Mercurial > pidgin
annotate src/toc.c @ 211:2042a38da38b
[gaim-migrate @ 221]
Changed plugins/Makefile.am so that 'make clean' removes built plugins.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 03 May 2000 00:34:30 +0000 |
parents | 522e885485f0 |
children | 89c9334d3484 |
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 | |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
175 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
|
176 FILE_SEND_UID, FILE_GET_UID, B_ICON_UID, IMAGE_UID, |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
177 VOICE_UID); |
1 | 178 sflap_send(buf2, -1, TYPE_DATA); |
149 | 179 |
1 | 180 serv_finish_login(); |
181 return 0; | |
182 } | |
183 | |
184 void toc_close() | |
185 { | |
186 #ifdef USE_APPLET | |
187 setUserState(offline); | |
188 #endif /* USE_APPLET */ | |
189 seqno = 0; | |
190 state = STATE_OFFLINE; | |
191 if (inpa > 0) | |
192 gdk_input_remove(inpa); | |
193 close(toc_fd); | |
194 toc_fd=-1; | |
195 inpa=-1; | |
196 } | |
197 | |
198 unsigned char *roast_password(char *pass) | |
199 { | |
200 /* Trivial "encryption" */ | |
201 static char rp[256]; | |
202 static char *roast = ROAST; | |
203 int pos=2; | |
204 int x; | |
205 strcpy(rp, "0x"); | |
206 for (x=0;(x<150) && pass[x]; x++) | |
207 pos+=sprintf(&rp[pos],"%02x", pass[x] ^ roast[x % strlen(roast)]); | |
208 rp[pos]='\0'; | |
209 return rp; | |
210 } | |
211 | |
212 | |
213 char *print_header(void *hdr_v) | |
214 { | |
215 static char s[80]; | |
216 struct sflap_hdr *hdr = (struct sflap_hdr *)hdr_v; | |
217 g_snprintf(s,sizeof(s), "[ ast: %c, type: %d, seqno: %d, len: %d ]", | |
218 hdr->ast, hdr->type, ntohs(hdr->seqno), ntohs(hdr->len)); | |
219 return s; | |
220 } | |
221 | |
222 void print_buffer(char *buf, int len) | |
223 { | |
224 #if 0 | |
225 int x; | |
226 printf("[ "); | |
227 for (x=0;x<len;x++) | |
228 printf("%d ", buf[x]); | |
229 printf("]\n"); | |
230 printf("[ "); | |
231 for (x=0;x<len;x++) | |
232 printf("%c ", buf[x]); | |
233 printf("]\n"); | |
234 #endif | |
235 } | |
236 | |
237 int sflap_send(char *buf, int olen, int type) | |
238 { | |
239 int len; | |
240 int slen=0; | |
241 struct sflap_hdr hdr; | |
242 char obuf[MSG_LEN]; | |
243 | |
244 /* One _last_ 2048 check here! This shouldn't ever | |
245 * get hit though, hopefully. If it gets hit on an IM | |
246 * It'll lose the last " and the message won't go through, | |
247 * but this'll stop a segfault. */ | |
248 if (strlen(buf) > (MSG_LEN - sizeof(hdr))) { | |
249 buf[MSG_LEN - sizeof(hdr) - 3] = '"'; | |
250 buf[MSG_LEN - sizeof(hdr) - 2] = '\0'; | |
251 } | |
252 | |
253 sprintf(debug_buff,"%s [Len %d]\n", buf, strlen(buf)); | |
254 debug_print(debug_buff); | |
255 | |
256 | |
257 | |
258 if (olen < 0) | |
259 len = escape_message(buf); | |
260 else | |
261 len = olen; | |
262 hdr.ast = '*'; | |
263 hdr.type = type; | |
264 hdr.seqno = htons(seqno++ & 0xffff); | |
265 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); | |
266 | |
267 sprintf(debug_buff,"Escaped message is '%s'\n",buf); | |
268 debug_print(debug_buff); | |
269 | |
270 memcpy(obuf, &hdr, sizeof(hdr)); | |
271 slen += sizeof(hdr); | |
272 memcpy(&obuf[slen], buf, len); | |
273 slen += len; | |
274 if (type != TYPE_SIGNON) { | |
275 obuf[slen]='\0'; | |
276 slen += 1; | |
277 } | |
278 print_buffer(obuf, slen); | |
279 | |
280 return write(toc_fd, obuf, slen); | |
281 } | |
282 | |
283 | |
79 | 284 int wait_reply(char *buffer, size_t buflen) |
1 | 285 { |
79 | 286 size_t res=-1; |
287 int read_rv = -1; | |
1 | 288 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer; |
289 char *c; | |
290 | |
79 | 291 if(buflen < sizeof(struct sflap_hdr)) { |
292 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | |
293 return -1; | |
294 } | |
295 | |
296 while((read_rv = read(toc_fd, buffer, 1))) { | |
297 if (read_rv < 0 || read_rv > 1) | |
298 return -1; | |
1 | 299 if (buffer[0] == '*') |
300 break; | |
301 | |
302 } | |
303 | |
79 | 304 read_rv = read(toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1); |
1 | 305 |
79 | 306 if (read_rv < 0) |
307 return read_rv; | |
1 | 308 |
79 | 309 res = read_rv + 1; |
1 | 310 |
311 | |
312 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), ""); | |
313 debug_print(debug_buff); | |
314 | |
315 | |
79 | 316 if(buflen < sizeof(struct sflap_hdr) + ntohs(hdr->len) + 1) { |
317 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | |
318 return -1; | |
319 } | |
1 | 320 |
321 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) { | |
79 | 322 read_rv = read(toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res); |
323 if(read_rv < 0) return read_rv; | |
324 res += read_rv; | |
1 | 325 while(gtk_events_pending()) |
326 gtk_main_iteration(); | |
327 } | |
328 | |
329 if (res >= sizeof(struct sflap_hdr)) | |
330 buffer[res]='\0'; | |
331 else | |
332 return res - sizeof(struct sflap_hdr); | |
333 | |
334 switch(hdr->type) { | |
335 case TYPE_SIGNON: | |
336 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4); | |
337 peer_ver = ntohl(peer_ver); | |
338 seqno = ntohs(hdr->seqno); | |
339 state = STATE_SIGNON_REQUEST; | |
340 break; | |
341 case TYPE_DATA: | |
342 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:"))) | |
343 state = STATE_SIGNON_ACK; | |
344 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) { | |
345 state = STATE_CONFIG; | |
346 } else if (state != STATE_ONLINE && !strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) { | |
347 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":"); | |
348 show_error_dialog(c); | |
349 } | |
350 | |
351 sprintf(debug_buff, "Data: %s\n",buffer + sizeof(struct sflap_hdr)); | |
352 debug_print(debug_buff); | |
353 | |
354 break; | |
355 default: | |
356 sprintf(debug_buff, "Unknown/unimplemented packet type %d\n",hdr->type); | |
357 debug_print(debug_buff); | |
358 } | |
359 return res; | |
360 } | |
361 | |
362 | |
363 | |
364 void toc_callback( gpointer data, | |
365 gint source, | |
366 GdkInputCondition condition ) | |
367 { | |
368 char *buf; | |
369 char *c; | |
370 char *l; | |
371 | |
372 buf = g_malloc(BUF_LONG); | |
373 if (wait_reply(buf, BUF_LONG) < 0) { | |
374 signoff(); | |
375 hide_login_progress("Connection Closed"); | |
376 g_free(buf); | |
377 return; | |
378 } | |
379 | |
380 | |
381 c=strtok(buf+sizeof(struct sflap_hdr),":"); /* Ditch the first part */ | |
382 if (!strcasecmp(c,"UPDATE_BUDDY")) { | |
383 char *uc; | |
384 int logged, evil, idle, type = 0; | |
385 time_t signon; | |
386 time_t time_idle; | |
387 | |
388 c = strtok(NULL,":"); /* c is name */ | |
389 | |
390 l = strtok(NULL,":"); /* l is T/F logged status */ | |
391 | |
392 sscanf(strtok(NULL, ":"), "%d", &evil); | |
393 | |
394 sscanf(strtok(NULL, ":"), "%ld", &signon); | |
395 | |
396 sscanf(strtok(NULL, ":"), "%d", &idle); | |
397 | |
398 uc = strtok(NULL, ":"); | |
399 | |
400 | |
401 if (!strncasecmp(l,"T",1)) | |
402 logged = 1; | |
403 else | |
404 logged = 0; | |
405 | |
406 | |
407 if (uc[0] == 'A') | |
408 type |= UC_AOL; | |
409 | |
410 switch(uc[1]) { | |
411 case 'A': | |
412 type |= UC_ADMIN; | |
413 break; | |
414 case 'U': | |
415 type |= UC_UNCONFIRMED; | |
416 break; | |
417 case 'O': | |
418 type |= UC_NORMAL; | |
419 break; | |
420 default: | |
421 break; | |
422 } | |
423 | |
424 switch(uc[2]) { | |
425 case 'U': | |
426 type |= UC_UNAVAILABLE; | |
427 break; | |
428 default: | |
429 break; | |
430 } | |
431 | |
432 if (idle) { | |
433 time(&time_idle); | |
434 time_idle -= idle*60; | |
435 } else | |
436 time_idle = 0; | |
437 | |
438 serv_got_update(c, logged, evil, signon, time_idle, type); | |
439 | |
440 } else if (!strcasecmp(c, "ERROR")) { | |
441 c = strtok(NULL,":"); | |
442 show_error_dialog(c); | |
443 } else if (!strcasecmp(c, "NICK")) { | |
444 c = strtok(NULL,":"); | |
445 g_snprintf(current_user->username, sizeof(current_user->username), "%s", c); | |
446 } else if (!strcasecmp(c, "IM_IN")) { | |
447 char *away, *message; | |
448 int a = 0; | |
449 | |
450 c = strtok(NULL,":"); | |
451 away = strtok(NULL,":"); | |
452 | |
453 message = away; | |
454 | |
455 while(*message && (*message != ':')) | |
456 message++; | |
457 | |
458 message++; | |
459 | |
460 if (!strncasecmp(away, "T", 1)) | |
461 a = 1; | |
462 serv_got_im(c, message, a); | |
463 | |
464 } else if (!strcasecmp(c, "GOTO_URL")) { | |
465 char *name; | |
466 char *url; | |
467 | |
468 char tmp[256]; | |
469 | |
470 name = strtok(NULL, ":"); | |
471 url = strtok(NULL, ":"); | |
472 | |
473 | |
474 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url); | |
475 /* fprintf(stdout, "Name: %s\n%s\n", name, url); | |
476 printf("%s", grab_url(tmp));*/ | |
477 g_show_info(tmp); | |
478 } else if (!strcasecmp(c, "EVILED")) { | |
479 int lev; | |
480 char *name = NULL; | |
481 | |
482 sscanf(strtok(NULL, ":"), "%d", &lev); | |
483 name = strtok(NULL, ":"); | |
484 | |
485 sprintf(debug_buff,"%s | %d\n", name, lev); | |
486 debug_print(debug_buff); | |
487 | |
488 serv_got_eviled(name, lev); | |
489 | |
490 } else if (!strcasecmp(c, "CHAT_JOIN")) { | |
491 char *name; | |
492 int id; | |
493 | |
494 | |
495 sscanf(strtok(NULL, ":"), "%d", &id); | |
496 name = strtok(NULL, ":"); | |
497 serv_got_joined_chat(id, name); | |
498 | |
499 } else if (!strcasecmp(c, "DIR_STATUS")) { | |
149 | 500 } else if (!strcasecmp(c, "ADMIN_PASSWD_STATUS")) { |
501 do_error_dialog("Password Change Successeful", "Gaim - Password Change"); | |
1 | 502 } else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) { |
503 int id; | |
504 char *in; | |
505 char *buddy; | |
506 GList *bcs = buddy_chats; | |
507 struct buddy_chat *b = NULL; | |
508 | |
509 sscanf(strtok(NULL, ":"), "%d", &id); | |
510 | |
511 in = strtok(NULL, ":"); | |
512 | |
513 while(bcs) { | |
514 b = (struct buddy_chat *)bcs->data; | |
515 if (id == b->id) | |
516 break; | |
517 bcs = bcs->next; | |
518 b = NULL; | |
519 } | |
520 | |
44 | 521 if (!b) { |
45 | 522 g_free(buf); |
1 | 523 return; |
44 | 524 } |
1 | 525 |
526 | |
527 if (!strcasecmp(in, "T")) { | |
528 while((buddy = strtok(NULL, ":")) != NULL) { | |
529 add_chat_buddy(b, buddy); | |
530 } | |
531 } else { | |
532 while((buddy = strtok(NULL, ":")) != NULL) { | |
533 remove_chat_buddy(b, buddy); | |
534 } | |
535 } | |
536 | |
537 } else if (!strcasecmp(c, "CHAT_LEFT")) { | |
538 int id; | |
539 | |
540 | |
541 sscanf(strtok(NULL, ":"), "%d", &id); | |
542 | |
543 serv_got_chat_left(id); | |
544 | |
545 | |
546 } else if (!strcasecmp(c, "CHAT_IN")) { | |
547 | |
548 int id, w; | |
549 char *m; | |
550 char *who, *whisper; | |
551 | |
552 | |
553 sscanf(strtok(NULL, ":"), "%d", &id); | |
554 who = strtok(NULL, ":"); | |
555 whisper = strtok(NULL, ":"); | |
556 m = whisper; | |
557 while(*m && (*m != ':')) m++; | |
558 m++; | |
559 | |
560 if (!strcasecmp(whisper, "T")) | |
561 w = 1; | |
562 else | |
563 w = 0; | |
564 | |
565 serv_got_chat_in(id, who, w, m); | |
566 | |
567 | |
568 } else if (!strcasecmp(c, "CHAT_INVITE")) { | |
569 char *name; | |
570 char *who; | |
571 char *message; | |
572 int id; | |
573 | |
574 | |
575 name = strtok(NULL, ":"); | |
576 sscanf(strtok(NULL, ":"), "%d", &id); | |
577 who = strtok(NULL, ":"); | |
578 message = strtok(NULL, ":"); | |
579 | |
580 serv_got_chat_invite(name, id, who, message); | |
581 | |
582 | |
583 } else if (!strcasecmp(c, "RVOUS_PROPOSE")) { | |
584 char *user; | |
585 char *uuid; | |
586 char *cookie; | |
587 int seq; | |
588 char *rip, *pip, *vip; | |
589 int port; | |
590 int unk[4]; | |
591 char *messages[4]; | |
592 int subtype, files, totalsize; | |
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 | |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
608 if (!strcmp(uuid, FILE_SEND_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
609 /* we're getting a file */ |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
610 for (i=0; i<4; i++) { |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
611 sscanf(strtok(NULL, ":"), "%d", &unk[i]); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
612 if (unk[i] == 10001) |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
613 break; |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
614 messages[i] = frombase64(strtok(NULL, ":")); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
615 } |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
616 tmp = frombase64(strtok(NULL, ":")); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
617 subtype = tmp[1]; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
618 files = tmp[3]; /* These are fine */ |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
619 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
620 totalsize = 0; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
621 totalsize |= (tmp[4] << 24) & 0xff000000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
622 totalsize |= (tmp[5] << 16) & 0x00ff0000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
623 totalsize |= (tmp[6] << 8) & 0x0000ff00; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
624 totalsize |= (tmp[7] << 0) & 0x000000ff; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
625 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
626 name = tmp + 8; |
1 | 627 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
628 ft = g_new0(struct file_transfer, 1); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
629 |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
630 ft->cookie = g_strdup(cookie); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
631 ft->ip = g_strdup(pip); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
632 ft->port = port; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
633 if (i) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
634 ft->message = g_strdup(messages[0]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
635 else |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
636 ft->message = NULL; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
637 ft->filename = g_strdup(name); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
638 ft->user = g_strdup(user); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
639 ft->size = totalsize; |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
640 sprintf(ft->UID, "%s", FILE_SEND_UID); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
641 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
642 g_free(tmp); |
1 | 643 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
644 for (i--; i >= 0; i--) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
645 g_free(messages[i]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
646 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
647 accept_file_dialog(ft); |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
648 } else if (!strcmp(uuid, FILE_GET_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
649 /* we're sending a file */ |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
650 for (i=0; i<4; i++) { |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
651 sscanf(strtok(NULL, ":"), "%d", &unk[i]); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
652 if (unk[i] == 10001) |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
653 break; |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
654 messages[i] = frombase64(strtok(NULL, ":")); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
655 } |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
656 tmp = frombase64(strtok(NULL, ":")); |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
657 ft = g_new0(struct file_transfer, 1); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
658 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
659 ft->cookie = g_strdup(cookie); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
660 ft->ip = g_strdup(pip); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
661 ft->port = port; |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
662 if (i) |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
663 ft->message = g_strdup(messages[0]); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
664 else |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
665 ft->message = NULL; |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
666 ft->user = g_strdup(user); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
667 sprintf(ft->UID, "%s", FILE_GET_UID); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
668 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
669 g_free(tmp); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
670 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
671 for (i--; i >= 0; i--) |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
672 g_free(messages[i]); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
673 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
674 accept_file_dialog(ft); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
675 /* |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
676 } else if (!strcmp(uuid, VOICE_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
677 } else if (!strcmp(uuid, B_ICON_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
678 } else if (!strcmp(uuid, IMAGE_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
679 */ |
1 | 680 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
681 } else { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
682 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
|
683 uuid); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
684 debug_print(debug_buff); |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
685 tmp = g_malloc(BUF_LEN); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
686 name = frombase64(cookie); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
687 snprintf(tmp, BUF_LEN, "toc_rvous_cancel %s %s %s", |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
688 user, name, uuid); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
689 sflap_send(tmp, strlen(tmp), TYPE_DATA); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
690 free(name); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
691 free(tmp); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
692 } |
1 | 693 } else { |
694 sprintf(debug_buff,"don't know what to do with %s\n", c); | |
695 debug_print(debug_buff); | |
696 } | |
697 g_free(buf); | |
698 } | |
699 | |
700 | |
701 int toc_signon(char *username, char *password) | |
702 { | |
703 char buf[BUF_LONG]; | |
704 int res; | |
705 struct signon so; | |
706 | |
707 sprintf(debug_buff,"State = %d\n", state); | |
708 debug_print(debug_buff); | |
709 | |
710 if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0) | |
711 return res; | |
712 /* Wait for signon packet */ | |
713 | |
714 state = STATE_FLAPON; | |
715 | |
716 if ((res = wait_reply(buf, sizeof(buf)) < 0)) | |
717 return res; | |
718 | |
719 if (state != STATE_SIGNON_REQUEST) { | |
720 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state); | |
721 debug_print(debug_buff); | |
722 return -1; | |
723 } | |
724 | |
725 /* Compose a response */ | |
726 | |
727 g_snprintf(so.username, sizeof(so.username), "%s", username); | |
728 so.ver = ntohl(1); | |
729 so.tag = ntohs(1); | |
730 so.namelen = htons(strlen(so.username)); | |
731 | |
732 sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON); | |
733 | |
734 g_snprintf(buf, sizeof(buf), | |
735 "toc_signon %s %d %s %s %s \"%s\"", | |
736 login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION); | |
737 | |
738 sprintf(debug_buff,"Send: %s\n", buf); | |
739 debug_print(debug_buff); | |
740 | |
741 return sflap_send(buf, -1, TYPE_DATA); | |
742 } | |
743 | |
744 int toc_wait_signon() | |
745 { | |
746 /* Wait for the SIGNON to be approved */ | |
747 char buf[BUF_LEN]; | |
748 int res; | |
749 res = wait_reply(buf, sizeof(buf)); | |
750 if (res < 0) | |
751 return res; | |
752 if (state != STATE_SIGNON_ACK) { | |
753 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state); | |
754 debug_print(debug_buff); | |
755 return -1; | |
756 } | |
757 return 0; | |
758 } | |
759 | |
760 #ifdef _WIN32 | |
761 gint win32_read() | |
762 { | |
763 int ret; | |
764 struct fd_set fds; | |
765 struct timeval tv; | |
766 | |
767 FD_ZERO(&fds); | |
768 | |
769 tv.tv_sec = 0; | |
770 tv.tv_usec = 200; | |
771 | |
772 FD_SET(toc_fd, &fds); | |
773 | |
774 ret = select(toc_fd + 1, &fds, NULL, NULL, &tv); | |
775 | |
776 if (ret == 0) { | |
777 return TRUE; | |
778 } | |
779 | |
780 toc_callback(NULL, 0, (GdkInputCondition)0); | |
781 return TRUE; | |
782 } | |
783 #endif | |
784 | |
785 | |
786 char *toc_wait_config() | |
787 { | |
788 /* Waits for configuration packet, returning the contents of the packet */ | |
789 static char buf[BUF_LEN]; | |
790 int res; | |
791 res = wait_reply(buf, sizeof(buf)); | |
792 if (res < 0) | |
793 return NULL; | |
794 if (state != STATE_CONFIG) { | |
795 sprintf(debug_buff , "State should be %d, but is %d instead\n",STATE_CONFIG, state); | |
796 debug_print(debug_buff); | |
797 return NULL; | |
798 } | |
799 /* At this point, it's time to setup automatic handling of incoming packets */ | |
800 state = STATE_ONLINE; | |
801 #ifdef _WIN32 | |
802 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL); | |
803 #else | |
804 inpa = gdk_input_add(toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, NULL); | |
805 #endif | |
806 return buf; | |
807 } | |
808 | |
809 | |
810 void toc_build_config(char *s, int len) | |
811 { | |
812 GList *grp = groups; | |
813 GList *mem; | |
814 struct group *g; | |
815 struct buddy *b; | |
816 GList *plist = permit; | |
817 GList *dlist = deny; | |
818 | |
819 int pos=0; | |
820 | |
821 if (!permdeny) | |
822 permdeny = 1; | |
823 pos += g_snprintf(&s[pos], len - pos, "m %d\n", permdeny); | |
824 while(grp) { | |
825 g = (struct group *)grp->data; | |
826 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); | |
827 mem = g->members; | |
828 while(mem) { | |
829 b = (struct buddy *)mem->data; | |
830 pos += g_snprintf(&s[pos], len - pos, "b %s\n", b->name); | |
831 mem = mem->next; | |
832 } | |
833 grp = grp ->next; | |
834 } | |
835 while(plist) { | |
836 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
837 plist=plist->next; | |
838 | |
839 } | |
840 while(dlist) { | |
841 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
842 dlist=dlist->next; | |
843 } | |
844 } | |
845 | |
846 void parse_toc_buddy_list(char *config) | |
847 { | |
848 char *c; | |
849 char current[256]; | |
850 char *name; | |
851 GList *bud; | |
852 /* Clean out the permit/deny list!*/ | |
853 g_list_free(permit); | |
854 g_list_free(deny); | |
855 permit = NULL; | |
856 deny = NULL; | |
857 bud = NULL; | |
858 | |
859 | |
860 /* skip "CONFIG:" (if it exists)*/ | |
861 | |
862 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))? | |
863 strtok(config, "\n"): | |
864 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n"); | |
865 do { | |
866 if (c == NULL) | |
867 break; | |
868 if (*c == 'g') { | |
869 strncpy(current,c+2, sizeof(current)); | |
870 add_group(current); | |
871 } else if (*c == 'b') { | |
872 add_buddy(current, c+2); | |
873 bud = g_list_append(bud, c+2); | |
874 } else if (*c == 'p') { | |
875 name = g_malloc(strlen(c+2) + 2); | |
876 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
877 permit = g_list_append(permit, name); | |
878 } else if (*c == 'd') { | |
879 name = g_malloc(strlen(c+2) + 2); | |
880 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
881 deny = g_list_append(deny, name); | |
882 } else if (*c == 'm') { | |
883 sscanf(c + strlen(c) - 1, "%d", &permdeny); | |
884 if (permdeny == 0) | |
885 permdeny = 1; | |
886 } | |
887 }while((c=strtok(NULL,"\n"))); | |
888 #if 0 | |
889 fprintf(stdout, "Sending message '%s'\n",buf); | |
890 #endif | |
891 | |
892 serv_add_buddies(bud); | |
893 serv_set_permit_deny(); | |
894 } |