Mercurial > pidgin
annotate src/toc.c @ 198:73e9a0bfff62
[gaim-migrate @ 208]
Moved all the RVOUS stuff into rvous.c (mostly to reduce the size of dialogs.c).
Started trying to implement FILE_GET_UID, without much luck. I'm going to do
some dumps of the win client tomorrow to see if I can figure out what's going on
a little better.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 30 Apr 2000 10:39:35 +0000 |
parents | 24f0fef56a73 |
children | bc117fbcf527 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 | |
23 | |
24 #include <netdb.h> | |
25 #include <gtk/gtk.h> | |
26 #include <unistd.h> | |
27 #include <errno.h> | |
28 #include <netinet/in.h> | |
29 #include <arpa/inet.h> | |
30 #include <string.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <time.h> | |
34 #include <sys/socket.h> | |
35 #include "gaim.h" | |
36 #include "gnome_applet_mgr.h" | |
37 | |
38 | |
39 | |
40 /* descriptor for talking to TOC */ | |
41 static int toc_fd; | |
42 static int seqno; | |
43 static unsigned int peer_ver=0; | |
44 static int state; | |
45 static int inpa=-1; | |
46 #ifdef _WIN32 | |
47 static int win32_r; | |
48 #endif | |
49 | |
50 int toc_signon(char *username, char *password); | |
51 | |
52 | |
53 | |
54 int toc_login(char *username, char *password) | |
55 { | |
56 char *config; | |
57 struct in_addr *sin; | |
58 struct aim_user *u; | |
59 char buf[80]; | |
60 char buf2[2048]; | |
61 | |
62 g_snprintf(buf, sizeof(buf), "Looking up %s", aim_host); | |
63 set_login_progress(1, buf); | |
64 | |
65 sin = (struct in_addr *)get_address(aim_host); | |
66 if (!sin) { | |
67 | |
68 #ifdef USE_APPLET | |
69 setUserState(offline); | |
70 #endif /* USE_APPLET */ | |
71 set_state(STATE_OFFLINE); | |
72 g_snprintf(buf, sizeof(buf), "Unable to lookup %s", aim_host); | |
73 hide_login_progress(buf); | |
74 return -1; | |
75 } | |
76 | |
77 g_snprintf(toc_addy, sizeof(toc_addy), "%s", inet_ntoa(*sin)); | |
78 g_snprintf(buf, sizeof(buf), "Connecting to %s", inet_ntoa(*sin)); | |
79 | |
80 set_login_progress(2, buf); | |
81 | |
82 | |
83 | |
84 toc_fd = connect_address(sin->s_addr, aim_port); | |
85 | |
86 if (toc_fd < 0) { | |
87 #ifdef USE_APPLET | |
88 setUserState(offline); | |
89 #endif /* USE_APPLET */ | |
90 set_state(STATE_OFFLINE); | |
91 g_snprintf(buf, sizeof(buf), "Connect to %s failed", | |
92 inet_ntoa(*sin)); | |
93 hide_login_progress(buf); | |
94 return -1; | |
95 } | |
96 | |
97 g_free(sin); | |
98 | |
99 g_snprintf(buf, sizeof(buf), "Signon: %s",username); | |
100 | |
101 set_login_progress(3, buf); | |
102 | |
103 if (toc_signon(username, password) < 0) { | |
104 #ifdef USE_APPLET | |
105 setUserState(offline); | |
106 #endif /* USE_APPLET */ | |
107 set_state(STATE_OFFLINE); | |
108 hide_login_progress("Disconnected."); | |
109 return -1; | |
110 } | |
111 | |
112 g_snprintf(buf, sizeof(buf), "Waiting for reply..."); | |
113 set_login_progress(4, buf); | |
114 if (toc_wait_signon() < 0) { | |
115 #ifdef USE_APPLET | |
116 setUserState(offline); | |
117 #endif /* USE_APPLET */ | |
118 set_state(STATE_OFFLINE); | |
119 hide_login_progress("Authentication Failed"); | |
120 return -1; | |
121 } | |
122 | |
123 u = find_user(username); | |
124 | |
125 if (!u) { | |
126 u = g_new0(struct aim_user, 1); | |
127 g_snprintf(u->user_info, sizeof(u->user_info), DEFAULT_INFO); | |
128 aim_users = g_list_append(aim_users, u); | |
129 } | |
130 | |
131 current_user = u; | |
132 | |
133 g_snprintf(current_user->username, sizeof(current_user->username), "%s", username); | |
134 g_snprintf(current_user->password, sizeof(current_user->password), "%s", password); | |
135 | |
136 save_prefs(); | |
137 | |
138 g_snprintf(buf, sizeof(buf), "Retrieving config..."); | |
139 set_login_progress(5, buf); | |
140 if ((config=toc_wait_config()) == NULL) { | |
141 hide_login_progress("No Configuration"); | |
142 set_state(STATE_OFFLINE); | |
143 return -1; | |
144 | |
145 } | |
146 | |
147 | |
148 #ifdef USE_APPLET | |
107
55faf2e3a134
[gaim-migrate @ 117]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
149 make_buddy(); |
10 | 150 if (general_options & OPT_GEN_APP_BUDDY_SHOW) { |
50 | 151 gnome_buddy_show(); |
1 | 152 parse_toc_buddy_list(config); |
50 | 153 createOnlinePopup(); |
1 | 154 set_applet_draw_open(); |
155 } else { | |
156 gnome_buddy_hide(); | |
157 parse_toc_buddy_list(config); | |
158 set_applet_draw_closed(); | |
159 } | |
160 | |
161 | |
162 setUserState(online); | |
10 | 163 gtk_widget_hide(mainwindow); |
1 | 164 #else |
165 gtk_widget_hide(mainwindow); | |
166 show_buddy_list(); | |
167 parse_toc_buddy_list(config); | |
168 refresh_buddy_window(); | |
169 #endif | |
170 | |
171 | |
172 g_snprintf(buf2, sizeof(buf2), "toc_init_done"); | |
173 sflap_send(buf2, -1, TYPE_DATA); | |
174 | |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
175 g_snprintf(buf2, sizeof(buf2), "toc_set_caps %s %s", |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
176 FILE_SEND_UID, FILE_GET_UID); |
1 | 177 sflap_send(buf2, -1, TYPE_DATA); |
149 | 178 |
1 | 179 serv_finish_login(); |
180 return 0; | |
181 } | |
182 | |
183 void toc_close() | |
184 { | |
185 #ifdef USE_APPLET | |
186 setUserState(offline); | |
187 #endif /* USE_APPLET */ | |
188 seqno = 0; | |
189 state = STATE_OFFLINE; | |
190 if (inpa > 0) | |
191 gdk_input_remove(inpa); | |
192 close(toc_fd); | |
193 toc_fd=-1; | |
194 inpa=-1; | |
195 } | |
196 | |
197 unsigned char *roast_password(char *pass) | |
198 { | |
199 /* Trivial "encryption" */ | |
200 static char rp[256]; | |
201 static char *roast = ROAST; | |
202 int pos=2; | |
203 int x; | |
204 strcpy(rp, "0x"); | |
205 for (x=0;(x<150) && pass[x]; x++) | |
206 pos+=sprintf(&rp[pos],"%02x", pass[x] ^ roast[x % strlen(roast)]); | |
207 rp[pos]='\0'; | |
208 return rp; | |
209 } | |
210 | |
211 | |
212 char *print_header(void *hdr_v) | |
213 { | |
214 static char s[80]; | |
215 struct sflap_hdr *hdr = (struct sflap_hdr *)hdr_v; | |
216 g_snprintf(s,sizeof(s), "[ ast: %c, type: %d, seqno: %d, len: %d ]", | |
217 hdr->ast, hdr->type, ntohs(hdr->seqno), ntohs(hdr->len)); | |
218 return s; | |
219 } | |
220 | |
221 void print_buffer(char *buf, int len) | |
222 { | |
223 #if 0 | |
224 int x; | |
225 printf("[ "); | |
226 for (x=0;x<len;x++) | |
227 printf("%d ", buf[x]); | |
228 printf("]\n"); | |
229 printf("[ "); | |
230 for (x=0;x<len;x++) | |
231 printf("%c ", buf[x]); | |
232 printf("]\n"); | |
233 #endif | |
234 } | |
235 | |
236 int sflap_send(char *buf, int olen, int type) | |
237 { | |
238 int len; | |
239 int slen=0; | |
240 struct sflap_hdr hdr; | |
241 char obuf[MSG_LEN]; | |
242 | |
243 /* One _last_ 2048 check here! This shouldn't ever | |
244 * get hit though, hopefully. If it gets hit on an IM | |
245 * It'll lose the last " and the message won't go through, | |
246 * but this'll stop a segfault. */ | |
247 if (strlen(buf) > (MSG_LEN - sizeof(hdr))) { | |
248 buf[MSG_LEN - sizeof(hdr) - 3] = '"'; | |
249 buf[MSG_LEN - sizeof(hdr) - 2] = '\0'; | |
250 } | |
251 | |
252 sprintf(debug_buff,"%s [Len %d]\n", buf, strlen(buf)); | |
253 debug_print(debug_buff); | |
254 | |
255 | |
256 | |
257 if (olen < 0) | |
258 len = escape_message(buf); | |
259 else | |
260 len = olen; | |
261 hdr.ast = '*'; | |
262 hdr.type = type; | |
263 hdr.seqno = htons(seqno++ & 0xffff); | |
264 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); | |
265 | |
266 sprintf(debug_buff,"Escaped message is '%s'\n",buf); | |
267 debug_print(debug_buff); | |
268 | |
269 memcpy(obuf, &hdr, sizeof(hdr)); | |
270 slen += sizeof(hdr); | |
271 memcpy(&obuf[slen], buf, len); | |
272 slen += len; | |
273 if (type != TYPE_SIGNON) { | |
274 obuf[slen]='\0'; | |
275 slen += 1; | |
276 } | |
277 print_buffer(obuf, slen); | |
278 | |
279 return write(toc_fd, obuf, slen); | |
280 } | |
281 | |
282 | |
79 | 283 int wait_reply(char *buffer, size_t buflen) |
1 | 284 { |
79 | 285 size_t res=-1; |
286 int read_rv = -1; | |
1 | 287 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer; |
288 char *c; | |
289 | |
79 | 290 if(buflen < sizeof(struct sflap_hdr)) { |
291 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | |
292 return -1; | |
293 } | |
294 | |
295 while((read_rv = read(toc_fd, buffer, 1))) { | |
296 if (read_rv < 0 || read_rv > 1) | |
297 return -1; | |
1 | 298 if (buffer[0] == '*') |
299 break; | |
300 | |
301 } | |
302 | |
79 | 303 read_rv = read(toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1); |
1 | 304 |
79 | 305 if (read_rv < 0) |
306 return read_rv; | |
1 | 307 |
79 | 308 res = read_rv + 1; |
1 | 309 |
310 | |
311 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), ""); | |
312 debug_print(debug_buff); | |
313 | |
314 | |
79 | 315 if(buflen < sizeof(struct sflap_hdr) + ntohs(hdr->len) + 1) { |
316 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | |
317 return -1; | |
318 } | |
1 | 319 |
320 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) { | |
79 | 321 read_rv = read(toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res); |
322 if(read_rv < 0) return read_rv; | |
323 res += read_rv; | |
1 | 324 while(gtk_events_pending()) |
325 gtk_main_iteration(); | |
326 } | |
327 | |
328 if (res >= sizeof(struct sflap_hdr)) | |
329 buffer[res]='\0'; | |
330 else | |
331 return res - sizeof(struct sflap_hdr); | |
332 | |
333 switch(hdr->type) { | |
334 case TYPE_SIGNON: | |
335 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4); | |
336 peer_ver = ntohl(peer_ver); | |
337 seqno = ntohs(hdr->seqno); | |
338 state = STATE_SIGNON_REQUEST; | |
339 break; | |
340 case TYPE_DATA: | |
341 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:"))) | |
342 state = STATE_SIGNON_ACK; | |
343 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) { | |
344 state = STATE_CONFIG; | |
345 } else if (state != STATE_ONLINE && !strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) { | |
346 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":"); | |
347 show_error_dialog(c); | |
348 } | |
349 | |
350 sprintf(debug_buff, "Data: %s\n",buffer + sizeof(struct sflap_hdr)); | |
351 debug_print(debug_buff); | |
352 | |
353 break; | |
354 default: | |
355 sprintf(debug_buff, "Unknown/unimplemented packet type %d\n",hdr->type); | |
356 debug_print(debug_buff); | |
357 } | |
358 return res; | |
359 } | |
360 | |
361 | |
362 | |
363 void toc_callback( gpointer data, | |
364 gint source, | |
365 GdkInputCondition condition ) | |
366 { | |
367 char *buf; | |
368 char *c; | |
369 char *l; | |
370 | |
371 buf = g_malloc(BUF_LONG); | |
372 if (wait_reply(buf, BUF_LONG) < 0) { | |
373 signoff(); | |
374 hide_login_progress("Connection Closed"); | |
375 g_free(buf); | |
376 return; | |
377 } | |
378 | |
379 | |
380 c=strtok(buf+sizeof(struct sflap_hdr),":"); /* Ditch the first part */ | |
381 if (!strcasecmp(c,"UPDATE_BUDDY")) { | |
382 char *uc; | |
383 int logged, evil, idle, type = 0; | |
384 time_t signon; | |
385 time_t time_idle; | |
386 | |
387 c = strtok(NULL,":"); /* c is name */ | |
388 | |
389 l = strtok(NULL,":"); /* l is T/F logged status */ | |
390 | |
391 sscanf(strtok(NULL, ":"), "%d", &evil); | |
392 | |
393 sscanf(strtok(NULL, ":"), "%ld", &signon); | |
394 | |
395 sscanf(strtok(NULL, ":"), "%d", &idle); | |
396 | |
397 uc = strtok(NULL, ":"); | |
398 | |
399 | |
400 if (!strncasecmp(l,"T",1)) | |
401 logged = 1; | |
402 else | |
403 logged = 0; | |
404 | |
405 | |
406 if (uc[0] == 'A') | |
407 type |= UC_AOL; | |
408 | |
409 switch(uc[1]) { | |
410 case 'A': | |
411 type |= UC_ADMIN; | |
412 break; | |
413 case 'U': | |
414 type |= UC_UNCONFIRMED; | |
415 break; | |
416 case 'O': | |
417 type |= UC_NORMAL; | |
418 break; | |
419 default: | |
420 break; | |
421 } | |
422 | |
423 switch(uc[2]) { | |
424 case 'U': | |
425 type |= UC_UNAVAILABLE; | |
426 break; | |
427 default: | |
428 break; | |
429 } | |
430 | |
431 if (idle) { | |
432 time(&time_idle); | |
433 time_idle -= idle*60; | |
434 } else | |
435 time_idle = 0; | |
436 | |
437 serv_got_update(c, logged, evil, signon, time_idle, type); | |
438 | |
439 } else if (!strcasecmp(c, "ERROR")) { | |
440 c = strtok(NULL,":"); | |
441 show_error_dialog(c); | |
442 } else if (!strcasecmp(c, "NICK")) { | |
443 c = strtok(NULL,":"); | |
444 g_snprintf(current_user->username, sizeof(current_user->username), "%s", c); | |
445 } else if (!strcasecmp(c, "IM_IN")) { | |
446 char *away, *message; | |
447 int a = 0; | |
448 | |
449 c = strtok(NULL,":"); | |
450 away = strtok(NULL,":"); | |
451 | |
452 message = away; | |
453 | |
454 while(*message && (*message != ':')) | |
455 message++; | |
456 | |
457 message++; | |
458 | |
459 if (!strncasecmp(away, "T", 1)) | |
460 a = 1; | |
461 serv_got_im(c, message, a); | |
462 | |
463 } else if (!strcasecmp(c, "GOTO_URL")) { | |
464 char *name; | |
465 char *url; | |
466 | |
467 char tmp[256]; | |
468 | |
469 name = strtok(NULL, ":"); | |
470 url = strtok(NULL, ":"); | |
471 | |
472 | |
473 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url); | |
474 /* fprintf(stdout, "Name: %s\n%s\n", name, url); | |
475 printf("%s", grab_url(tmp));*/ | |
476 g_show_info(tmp); | |
477 } else if (!strcasecmp(c, "EVILED")) { | |
478 int lev; | |
479 char *name = NULL; | |
480 | |
481 sscanf(strtok(NULL, ":"), "%d", &lev); | |
482 name = strtok(NULL, ":"); | |
483 | |
484 sprintf(debug_buff,"%s | %d\n", name, lev); | |
485 debug_print(debug_buff); | |
486 | |
487 serv_got_eviled(name, lev); | |
488 | |
489 } else if (!strcasecmp(c, "CHAT_JOIN")) { | |
490 char *name; | |
491 int id; | |
492 | |
493 | |
494 sscanf(strtok(NULL, ":"), "%d", &id); | |
495 name = strtok(NULL, ":"); | |
496 serv_got_joined_chat(id, name); | |
497 | |
498 } else if (!strcasecmp(c, "DIR_STATUS")) { | |
149 | 499 } else if (!strcasecmp(c, "ADMIN_PASSWD_STATUS")) { |
500 do_error_dialog("Password Change Successeful", "Gaim - Password Change"); | |
1 | 501 } else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) { |
502 int id; | |
503 char *in; | |
504 char *buddy; | |
505 GList *bcs = buddy_chats; | |
506 struct buddy_chat *b = NULL; | |
507 | |
508 sscanf(strtok(NULL, ":"), "%d", &id); | |
509 | |
510 in = strtok(NULL, ":"); | |
511 | |
512 while(bcs) { | |
513 b = (struct buddy_chat *)bcs->data; | |
514 if (id == b->id) | |
515 break; | |
516 bcs = bcs->next; | |
517 b = NULL; | |
518 } | |
519 | |
44 | 520 if (!b) { |
45 | 521 g_free(buf); |
1 | 522 return; |
44 | 523 } |
1 | 524 |
525 | |
526 if (!strcasecmp(in, "T")) { | |
527 while((buddy = strtok(NULL, ":")) != NULL) { | |
528 add_chat_buddy(b, buddy); | |
529 } | |
530 } else { | |
531 while((buddy = strtok(NULL, ":")) != NULL) { | |
532 remove_chat_buddy(b, buddy); | |
533 } | |
534 } | |
535 | |
536 } else if (!strcasecmp(c, "CHAT_LEFT")) { | |
537 int id; | |
538 | |
539 | |
540 sscanf(strtok(NULL, ":"), "%d", &id); | |
541 | |
542 serv_got_chat_left(id); | |
543 | |
544 | |
545 } else if (!strcasecmp(c, "CHAT_IN")) { | |
546 | |
547 int id, w; | |
548 char *m; | |
549 char *who, *whisper; | |
550 | |
551 | |
552 sscanf(strtok(NULL, ":"), "%d", &id); | |
553 who = strtok(NULL, ":"); | |
554 whisper = strtok(NULL, ":"); | |
555 m = whisper; | |
556 while(*m && (*m != ':')) m++; | |
557 m++; | |
558 | |
559 if (!strcasecmp(whisper, "T")) | |
560 w = 1; | |
561 else | |
562 w = 0; | |
563 | |
564 serv_got_chat_in(id, who, w, m); | |
565 | |
566 | |
567 } else if (!strcasecmp(c, "CHAT_INVITE")) { | |
568 char *name; | |
569 char *who; | |
570 char *message; | |
571 int id; | |
572 | |
573 | |
574 name = strtok(NULL, ":"); | |
575 sscanf(strtok(NULL, ":"), "%d", &id); | |
576 who = strtok(NULL, ":"); | |
577 message = strtok(NULL, ":"); | |
578 | |
579 serv_got_chat_invite(name, id, who, message); | |
580 | |
581 | |
582 } else if (!strcasecmp(c, "RVOUS_PROPOSE")) { | |
583 char *user; | |
584 char *uuid; | |
585 char *cookie; | |
586 int seq; | |
587 char *rip, *pip, *vip; | |
588 int port; | |
589 int unk[4]; | |
590 char *messages[4]; | |
591 int subtype, files, totalsize; | |
194
d7690984c0f1
[gaim-migrate @ 204]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
149
diff
changeset
|
592 int temp; |
1 | 593 char *name; |
594 char *tmp; | |
595 int i; | |
596 struct file_transfer *ft; | |
597 | |
598 | |
599 user = strtok(NULL, ":"); | |
600 uuid = strtok(NULL, ":"); | |
601 cookie = strtok(NULL, ":"); | |
602 sscanf(strtok(NULL, ":"), "%d", &seq); | |
603 rip = strtok(NULL, ":"); | |
604 pip = strtok(NULL, ":"); | |
605 vip = strtok(NULL, ":"); | |
606 sscanf(strtok(NULL, ":"), "%d", &port); | |
607 for (i=0; i<4; i++) { | |
608 sscanf(strtok(NULL, ":"), "%d", &unk[i]); | |
609 if (unk[i] == 10001) | |
610 break; | |
611 messages[i] = frombase64(strtok(NULL, ":")); | |
612 } | |
613 | |
614 tmp = frombase64(strtok(NULL, ":")); | |
615 | |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
616 if (!strcmp(uuid, FILE_SEND_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
617 /* we're getting a file */ |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
618 subtype = tmp[1]; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
619 files = tmp[3]; /* These are fine */ |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
620 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
621 totalsize = 0; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
622 totalsize |= (tmp[4] << 24) & 0xff000000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
623 totalsize |= (tmp[5] << 16) & 0x00ff0000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
624 totalsize |= (tmp[6] << 8) & 0x0000ff00; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
625 totalsize |= (tmp[7] << 0) & 0x000000ff; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
626 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
627 name = tmp + 8; |
1 | 628 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
629 ft = g_new0(struct file_transfer, 1); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
630 |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
631 ft->cookie = g_strdup(cookie); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
632 ft->ip = g_strdup(pip); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
633 ft->port = port; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
634 if (i) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
635 ft->message = g_strdup(messages[0]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
636 else |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
637 ft->message = NULL; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
638 ft->filename = g_strdup(name); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
639 ft->user = g_strdup(user); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
640 ft->size = totalsize; |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
641 sprintf(ft->UID, "%s", FILE_SEND_UID); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
642 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
643 g_free(tmp); |
1 | 644 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
645 for (i--; i >= 0; i--) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
646 g_free(messages[i]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
647 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
648 accept_file_dialog(ft); |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
649 } else if (!strcmp(uuid, FILE_GET_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
650 /* we're sending a file */ |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
651 ft = g_new0(struct file_transfer, 1); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
652 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
653 ft->cookie = g_strdup(cookie); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
654 ft->ip = g_strdup(pip); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
655 ft->port = port; |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
656 if (i) |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
657 ft->message = g_strdup(messages[0]); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
658 else |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
659 ft->message = NULL; |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
660 ft->user = g_strdup(user); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
661 sprintf(ft->UID, "%s", FILE_GET_UID); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
662 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
663 g_free(tmp); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
664 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
665 for (i--; i >= 0; i--) |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
666 g_free(messages[i]); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
667 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
668 accept_file_dialog(ft); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
669 /* |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
670 } else if (!strcmp(uuid, VOICE_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
671 } else if (!strcmp(uuid, B_ICON_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
672 } else if (!strcmp(uuid, IMAGE_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
673 */ |
1 | 674 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
675 } else { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
676 sprintf(debug_buff,"don't know what to do with %s\n", |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
677 uuid); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
678 debug_print(debug_buff); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
679 } |
1 | 680 } else { |
681 sprintf(debug_buff,"don't know what to do with %s\n", c); | |
682 debug_print(debug_buff); | |
683 } | |
684 g_free(buf); | |
685 } | |
686 | |
687 | |
688 int toc_signon(char *username, char *password) | |
689 { | |
690 char buf[BUF_LONG]; | |
691 int res; | |
692 struct signon so; | |
693 | |
694 sprintf(debug_buff,"State = %d\n", state); | |
695 debug_print(debug_buff); | |
696 | |
697 if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0) | |
698 return res; | |
699 /* Wait for signon packet */ | |
700 | |
701 state = STATE_FLAPON; | |
702 | |
703 if ((res = wait_reply(buf, sizeof(buf)) < 0)) | |
704 return res; | |
705 | |
706 if (state != STATE_SIGNON_REQUEST) { | |
707 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state); | |
708 debug_print(debug_buff); | |
709 return -1; | |
710 } | |
711 | |
712 /* Compose a response */ | |
713 | |
714 g_snprintf(so.username, sizeof(so.username), "%s", username); | |
715 so.ver = ntohl(1); | |
716 so.tag = ntohs(1); | |
717 so.namelen = htons(strlen(so.username)); | |
718 | |
719 sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON); | |
720 | |
721 g_snprintf(buf, sizeof(buf), | |
722 "toc_signon %s %d %s %s %s \"%s\"", | |
723 login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION); | |
724 | |
725 sprintf(debug_buff,"Send: %s\n", buf); | |
726 debug_print(debug_buff); | |
727 | |
728 return sflap_send(buf, -1, TYPE_DATA); | |
729 } | |
730 | |
731 int toc_wait_signon() | |
732 { | |
733 /* Wait for the SIGNON to be approved */ | |
734 char buf[BUF_LEN]; | |
735 int res; | |
736 res = wait_reply(buf, sizeof(buf)); | |
737 if (res < 0) | |
738 return res; | |
739 if (state != STATE_SIGNON_ACK) { | |
740 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state); | |
741 debug_print(debug_buff); | |
742 return -1; | |
743 } | |
744 return 0; | |
745 } | |
746 | |
747 #ifdef _WIN32 | |
748 gint win32_read() | |
749 { | |
750 int ret; | |
751 struct fd_set fds; | |
752 struct timeval tv; | |
753 | |
754 FD_ZERO(&fds); | |
755 | |
756 tv.tv_sec = 0; | |
757 tv.tv_usec = 200; | |
758 | |
759 FD_SET(toc_fd, &fds); | |
760 | |
761 ret = select(toc_fd + 1, &fds, NULL, NULL, &tv); | |
762 | |
763 if (ret == 0) { | |
764 return TRUE; | |
765 } | |
766 | |
767 toc_callback(NULL, 0, (GdkInputCondition)0); | |
768 return TRUE; | |
769 } | |
770 #endif | |
771 | |
772 | |
773 char *toc_wait_config() | |
774 { | |
775 /* Waits for configuration packet, returning the contents of the packet */ | |
776 static char buf[BUF_LEN]; | |
777 int res; | |
778 res = wait_reply(buf, sizeof(buf)); | |
779 if (res < 0) | |
780 return NULL; | |
781 if (state != STATE_CONFIG) { | |
782 sprintf(debug_buff , "State should be %d, but is %d instead\n",STATE_CONFIG, state); | |
783 debug_print(debug_buff); | |
784 return NULL; | |
785 } | |
786 /* At this point, it's time to setup automatic handling of incoming packets */ | |
787 state = STATE_ONLINE; | |
788 #ifdef _WIN32 | |
789 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL); | |
790 #else | |
791 inpa = gdk_input_add(toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, NULL); | |
792 #endif | |
793 return buf; | |
794 } | |
795 | |
796 | |
797 void toc_build_config(char *s, int len) | |
798 { | |
799 GList *grp = groups; | |
800 GList *mem; | |
801 struct group *g; | |
802 struct buddy *b; | |
803 GList *plist = permit; | |
804 GList *dlist = deny; | |
805 | |
806 int pos=0; | |
807 | |
808 if (!permdeny) | |
809 permdeny = 1; | |
810 pos += g_snprintf(&s[pos], len - pos, "m %d\n", permdeny); | |
811 while(grp) { | |
812 g = (struct group *)grp->data; | |
813 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); | |
814 mem = g->members; | |
815 while(mem) { | |
816 b = (struct buddy *)mem->data; | |
817 pos += g_snprintf(&s[pos], len - pos, "b %s\n", b->name); | |
818 mem = mem->next; | |
819 } | |
820 grp = grp ->next; | |
821 } | |
822 while(plist) { | |
823 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
824 plist=plist->next; | |
825 | |
826 } | |
827 while(dlist) { | |
828 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
829 dlist=dlist->next; | |
830 } | |
831 } | |
832 | |
833 void parse_toc_buddy_list(char *config) | |
834 { | |
835 char *c; | |
836 char current[256]; | |
837 char *name; | |
838 GList *bud; | |
839 /* Clean out the permit/deny list!*/ | |
840 g_list_free(permit); | |
841 g_list_free(deny); | |
842 permit = NULL; | |
843 deny = NULL; | |
844 bud = NULL; | |
845 | |
846 | |
847 /* skip "CONFIG:" (if it exists)*/ | |
848 | |
849 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))? | |
850 strtok(config, "\n"): | |
851 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n"); | |
852 do { | |
853 if (c == NULL) | |
854 break; | |
855 if (*c == 'g') { | |
856 strncpy(current,c+2, sizeof(current)); | |
857 add_group(current); | |
858 } else if (*c == 'b') { | |
859 add_buddy(current, c+2); | |
860 bud = g_list_append(bud, c+2); | |
861 } else if (*c == 'p') { | |
862 name = g_malloc(strlen(c+2) + 2); | |
863 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
864 permit = g_list_append(permit, name); | |
865 } else if (*c == 'd') { | |
866 name = g_malloc(strlen(c+2) + 2); | |
867 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
868 deny = g_list_append(deny, name); | |
869 } else if (*c == 'm') { | |
870 sscanf(c + strlen(c) - 1, "%d", &permdeny); | |
871 if (permdeny == 0) | |
872 permdeny = 1; | |
873 } | |
874 }while((c=strtok(NULL,"\n"))); | |
875 #if 0 | |
876 fprintf(stdout, "Sending message '%s'\n",buf); | |
877 #endif | |
878 | |
879 serv_add_buddies(bud); | |
880 serv_set_permit_deny(); | |
881 } |