Mercurial > pidgin
annotate src/toc.c @ 210:ec0686b3b03f
[gaim-migrate @ 220]
Mostly small changes trying to get -Wall not to give any messages.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 01 May 2000 19:39:00 +0000 |
parents | 522e885485f0 |
children | 2042a38da38b |
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; | |
592 char *name; | |
593 char *tmp; | |
594 int i; | |
595 struct file_transfer *ft; | |
596 | |
597 | |
598 user = strtok(NULL, ":"); | |
599 uuid = strtok(NULL, ":"); | |
600 cookie = strtok(NULL, ":"); | |
601 sscanf(strtok(NULL, ":"), "%d", &seq); | |
602 rip = strtok(NULL, ":"); | |
603 pip = strtok(NULL, ":"); | |
604 vip = strtok(NULL, ":"); | |
605 sscanf(strtok(NULL, ":"), "%d", &port); | |
606 for (i=0; i<4; i++) { | |
607 sscanf(strtok(NULL, ":"), "%d", &unk[i]); | |
608 if (unk[i] == 10001) | |
609 break; | |
610 messages[i] = frombase64(strtok(NULL, ":")); | |
611 } | |
612 | |
613 tmp = frombase64(strtok(NULL, ":")); | |
208
522e885485f0
[gaim-migrate @ 218]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
614 sprintf(debug_buff, "%d %d %d %d %d %d %d %d %s\n", tmp[0], |
522e885485f0
[gaim-migrate @ 218]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
615 tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], |
522e885485f0
[gaim-migrate @ 218]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
616 tmp[7], tmp + 8); |
522e885485f0
[gaim-migrate @ 218]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
617 debug_print(debug_buff); |
1 | 618 |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
619 if (!strcmp(uuid, FILE_SEND_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
620 /* we're getting a file */ |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
621 subtype = tmp[1]; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
622 files = tmp[3]; /* These are fine */ |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
623 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
624 totalsize = 0; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
625 totalsize |= (tmp[4] << 24) & 0xff000000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
626 totalsize |= (tmp[5] << 16) & 0x00ff0000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
627 totalsize |= (tmp[6] << 8) & 0x0000ff00; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
628 totalsize |= (tmp[7] << 0) & 0x000000ff; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
629 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
630 name = tmp + 8; |
1 | 631 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
632 ft = g_new0(struct file_transfer, 1); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
633 |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
634 ft->cookie = g_strdup(cookie); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
635 ft->ip = g_strdup(pip); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
636 ft->port = port; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
637 if (i) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
638 ft->message = g_strdup(messages[0]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
639 else |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
640 ft->message = NULL; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
641 ft->filename = g_strdup(name); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
642 ft->user = g_strdup(user); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
643 ft->size = totalsize; |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
644 sprintf(ft->UID, "%s", FILE_SEND_UID); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
645 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
646 g_free(tmp); |
1 | 647 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
648 for (i--; i >= 0; i--) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
649 g_free(messages[i]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
650 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
651 accept_file_dialog(ft); |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
652 } else if (!strcmp(uuid, FILE_GET_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
653 /* we're sending a file */ |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
654 ft = g_new0(struct file_transfer, 1); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
655 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
656 ft->cookie = g_strdup(cookie); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
657 ft->ip = g_strdup(pip); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
658 ft->port = port; |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
659 if (i) |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
660 ft->message = g_strdup(messages[0]); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
661 else |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
662 ft->message = NULL; |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
663 ft->user = g_strdup(user); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
664 sprintf(ft->UID, "%s", FILE_GET_UID); |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
665 |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
666 g_free(tmp); |
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 for (i--; i >= 0; i--) |
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
669 g_free(messages[i]); |
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 accept_file_dialog(ft); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
672 /* |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
673 } else if (!strcmp(uuid, VOICE_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
674 } else if (!strcmp(uuid, B_ICON_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
675 } else if (!strcmp(uuid, IMAGE_UID)) { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
676 */ |
1 | 677 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
678 } else { |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
679 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
|
680 uuid); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
681 debug_print(debug_buff); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
682 } |
1 | 683 } else { |
684 sprintf(debug_buff,"don't know what to do with %s\n", c); | |
685 debug_print(debug_buff); | |
686 } | |
687 g_free(buf); | |
688 } | |
689 | |
690 | |
691 int toc_signon(char *username, char *password) | |
692 { | |
693 char buf[BUF_LONG]; | |
694 int res; | |
695 struct signon so; | |
696 | |
697 sprintf(debug_buff,"State = %d\n", state); | |
698 debug_print(debug_buff); | |
699 | |
700 if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0) | |
701 return res; | |
702 /* Wait for signon packet */ | |
703 | |
704 state = STATE_FLAPON; | |
705 | |
706 if ((res = wait_reply(buf, sizeof(buf)) < 0)) | |
707 return res; | |
708 | |
709 if (state != STATE_SIGNON_REQUEST) { | |
710 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state); | |
711 debug_print(debug_buff); | |
712 return -1; | |
713 } | |
714 | |
715 /* Compose a response */ | |
716 | |
717 g_snprintf(so.username, sizeof(so.username), "%s", username); | |
718 so.ver = ntohl(1); | |
719 so.tag = ntohs(1); | |
720 so.namelen = htons(strlen(so.username)); | |
721 | |
722 sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON); | |
723 | |
724 g_snprintf(buf, sizeof(buf), | |
725 "toc_signon %s %d %s %s %s \"%s\"", | |
726 login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION); | |
727 | |
728 sprintf(debug_buff,"Send: %s\n", buf); | |
729 debug_print(debug_buff); | |
730 | |
731 return sflap_send(buf, -1, TYPE_DATA); | |
732 } | |
733 | |
734 int toc_wait_signon() | |
735 { | |
736 /* Wait for the SIGNON to be approved */ | |
737 char buf[BUF_LEN]; | |
738 int res; | |
739 res = wait_reply(buf, sizeof(buf)); | |
740 if (res < 0) | |
741 return res; | |
742 if (state != STATE_SIGNON_ACK) { | |
743 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state); | |
744 debug_print(debug_buff); | |
745 return -1; | |
746 } | |
747 return 0; | |
748 } | |
749 | |
750 #ifdef _WIN32 | |
751 gint win32_read() | |
752 { | |
753 int ret; | |
754 struct fd_set fds; | |
755 struct timeval tv; | |
756 | |
757 FD_ZERO(&fds); | |
758 | |
759 tv.tv_sec = 0; | |
760 tv.tv_usec = 200; | |
761 | |
762 FD_SET(toc_fd, &fds); | |
763 | |
764 ret = select(toc_fd + 1, &fds, NULL, NULL, &tv); | |
765 | |
766 if (ret == 0) { | |
767 return TRUE; | |
768 } | |
769 | |
770 toc_callback(NULL, 0, (GdkInputCondition)0); | |
771 return TRUE; | |
772 } | |
773 #endif | |
774 | |
775 | |
776 char *toc_wait_config() | |
777 { | |
778 /* Waits for configuration packet, returning the contents of the packet */ | |
779 static char buf[BUF_LEN]; | |
780 int res; | |
781 res = wait_reply(buf, sizeof(buf)); | |
782 if (res < 0) | |
783 return NULL; | |
784 if (state != STATE_CONFIG) { | |
785 sprintf(debug_buff , "State should be %d, but is %d instead\n",STATE_CONFIG, state); | |
786 debug_print(debug_buff); | |
787 return NULL; | |
788 } | |
789 /* At this point, it's time to setup automatic handling of incoming packets */ | |
790 state = STATE_ONLINE; | |
791 #ifdef _WIN32 | |
792 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL); | |
793 #else | |
794 inpa = gdk_input_add(toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, NULL); | |
795 #endif | |
796 return buf; | |
797 } | |
798 | |
799 | |
800 void toc_build_config(char *s, int len) | |
801 { | |
802 GList *grp = groups; | |
803 GList *mem; | |
804 struct group *g; | |
805 struct buddy *b; | |
806 GList *plist = permit; | |
807 GList *dlist = deny; | |
808 | |
809 int pos=0; | |
810 | |
811 if (!permdeny) | |
812 permdeny = 1; | |
813 pos += g_snprintf(&s[pos], len - pos, "m %d\n", permdeny); | |
814 while(grp) { | |
815 g = (struct group *)grp->data; | |
816 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); | |
817 mem = g->members; | |
818 while(mem) { | |
819 b = (struct buddy *)mem->data; | |
820 pos += g_snprintf(&s[pos], len - pos, "b %s\n", b->name); | |
821 mem = mem->next; | |
822 } | |
823 grp = grp ->next; | |
824 } | |
825 while(plist) { | |
826 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
827 plist=plist->next; | |
828 | |
829 } | |
830 while(dlist) { | |
831 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
832 dlist=dlist->next; | |
833 } | |
834 } | |
835 | |
836 void parse_toc_buddy_list(char *config) | |
837 { | |
838 char *c; | |
839 char current[256]; | |
840 char *name; | |
841 GList *bud; | |
842 /* Clean out the permit/deny list!*/ | |
843 g_list_free(permit); | |
844 g_list_free(deny); | |
845 permit = NULL; | |
846 deny = NULL; | |
847 bud = NULL; | |
848 | |
849 | |
850 /* skip "CONFIG:" (if it exists)*/ | |
851 | |
852 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))? | |
853 strtok(config, "\n"): | |
854 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n"); | |
855 do { | |
856 if (c == NULL) | |
857 break; | |
858 if (*c == 'g') { | |
859 strncpy(current,c+2, sizeof(current)); | |
860 add_group(current); | |
861 } else if (*c == 'b') { | |
862 add_buddy(current, c+2); | |
863 bud = g_list_append(bud, c+2); | |
864 } else if (*c == 'p') { | |
865 name = g_malloc(strlen(c+2) + 2); | |
866 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
867 permit = g_list_append(permit, name); | |
868 } else if (*c == 'd') { | |
869 name = g_malloc(strlen(c+2) + 2); | |
870 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
871 deny = g_list_append(deny, name); | |
872 } else if (*c == 'm') { | |
873 sscanf(c + strlen(c) - 1, "%d", &permdeny); | |
874 if (permdeny == 0) | |
875 permdeny = 1; | |
876 } | |
877 }while((c=strtok(NULL,"\n"))); | |
878 #if 0 | |
879 fprintf(stdout, "Sending message '%s'\n",buf); | |
880 #endif | |
881 | |
882 serv_add_buddies(bud); | |
883 serv_set_permit_deny(); | |
884 } |