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