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
|
10
|
149 if (general_options & OPT_GEN_APP_BUDDY_SHOW) {
|
50
|
150 make_buddy();
|
|
151 gnome_buddy_show();
|
1
|
152 parse_toc_buddy_list(config);
|
50
|
153 createOnlinePopup();
|
1
|
154 set_applet_draw_open();
|
|
155 } else {
|
|
156 make_buddy();
|
|
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
|
|
176 #if 0
|
|
177 g_snprintf(buf2, sizeof(buf2), "toc_set_caps %s",
|
|
178 FILETRANS_UID);
|
|
179 sflap_send(buf2, -1, TYPE_DATA);
|
|
180 #endif
|
|
181
|
|
182 serv_finish_login();
|
|
183 return 0;
|
|
184 }
|
|
185
|
|
186 void toc_close()
|
|
187 {
|
|
188 #ifdef USE_APPLET
|
|
189 setUserState(offline);
|
|
190 #endif /* USE_APPLET */
|
|
191 seqno = 0;
|
|
192 state = STATE_OFFLINE;
|
|
193 if (inpa > 0)
|
|
194 gdk_input_remove(inpa);
|
|
195 close(toc_fd);
|
|
196 toc_fd=-1;
|
|
197 inpa=-1;
|
|
198 }
|
|
199
|
|
200 unsigned char *roast_password(char *pass)
|
|
201 {
|
|
202 /* Trivial "encryption" */
|
|
203 static char rp[256];
|
|
204 static char *roast = ROAST;
|
|
205 int pos=2;
|
|
206 int x;
|
|
207 strcpy(rp, "0x");
|
|
208 for (x=0;(x<150) && pass[x]; x++)
|
|
209 pos+=sprintf(&rp[pos],"%02x", pass[x] ^ roast[x % strlen(roast)]);
|
|
210 rp[pos]='\0';
|
|
211 return rp;
|
|
212 }
|
|
213
|
|
214
|
|
215 char *print_header(void *hdr_v)
|
|
216 {
|
|
217 static char s[80];
|
|
218 struct sflap_hdr *hdr = (struct sflap_hdr *)hdr_v;
|
|
219 g_snprintf(s,sizeof(s), "[ ast: %c, type: %d, seqno: %d, len: %d ]",
|
|
220 hdr->ast, hdr->type, ntohs(hdr->seqno), ntohs(hdr->len));
|
|
221 return s;
|
|
222 }
|
|
223
|
|
224 void print_buffer(char *buf, int len)
|
|
225 {
|
|
226 #if 0
|
|
227 int x;
|
|
228 printf("[ ");
|
|
229 for (x=0;x<len;x++)
|
|
230 printf("%d ", buf[x]);
|
|
231 printf("]\n");
|
|
232 printf("[ ");
|
|
233 for (x=0;x<len;x++)
|
|
234 printf("%c ", buf[x]);
|
|
235 printf("]\n");
|
|
236 #endif
|
|
237 }
|
|
238
|
|
239 int sflap_send(char *buf, int olen, int type)
|
|
240 {
|
|
241 int len;
|
|
242 int slen=0;
|
|
243 struct sflap_hdr hdr;
|
|
244 char obuf[MSG_LEN];
|
|
245
|
|
246 /* One _last_ 2048 check here! This shouldn't ever
|
|
247 * get hit though, hopefully. If it gets hit on an IM
|
|
248 * It'll lose the last " and the message won't go through,
|
|
249 * but this'll stop a segfault. */
|
|
250 if (strlen(buf) > (MSG_LEN - sizeof(hdr))) {
|
|
251 buf[MSG_LEN - sizeof(hdr) - 3] = '"';
|
|
252 buf[MSG_LEN - sizeof(hdr) - 2] = '\0';
|
|
253 }
|
|
254
|
|
255 sprintf(debug_buff,"%s [Len %d]\n", buf, strlen(buf));
|
|
256 debug_print(debug_buff);
|
|
257
|
|
258
|
|
259
|
|
260 if (olen < 0)
|
|
261 len = escape_message(buf);
|
|
262 else
|
|
263 len = olen;
|
|
264 hdr.ast = '*';
|
|
265 hdr.type = type;
|
|
266 hdr.seqno = htons(seqno++ & 0xffff);
|
|
267 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1));
|
|
268
|
|
269 sprintf(debug_buff,"Escaped message is '%s'\n",buf);
|
|
270 debug_print(debug_buff);
|
|
271
|
|
272 memcpy(obuf, &hdr, sizeof(hdr));
|
|
273 slen += sizeof(hdr);
|
|
274 memcpy(&obuf[slen], buf, len);
|
|
275 slen += len;
|
|
276 if (type != TYPE_SIGNON) {
|
|
277 obuf[slen]='\0';
|
|
278 slen += 1;
|
|
279 }
|
|
280 print_buffer(obuf, slen);
|
|
281
|
|
282 return write(toc_fd, obuf, slen);
|
|
283 }
|
|
284
|
|
285
|
79
|
286 int wait_reply(char *buffer, size_t buflen)
|
1
|
287 {
|
79
|
288 size_t res=-1;
|
|
289 int read_rv = -1;
|
1
|
290 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer;
|
|
291 char *c;
|
|
292
|
79
|
293 if(buflen < sizeof(struct sflap_hdr)) {
|
|
294 do_error_dialog("Buffer too small", "Gaim - Error (internal)");
|
|
295 return -1;
|
|
296 }
|
|
297
|
|
298 while((read_rv = read(toc_fd, buffer, 1))) {
|
|
299 if (read_rv < 0 || read_rv > 1)
|
|
300 return -1;
|
1
|
301 if (buffer[0] == '*')
|
|
302 break;
|
|
303
|
|
304 }
|
|
305
|
79
|
306 read_rv = read(toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1);
|
1
|
307
|
79
|
308 if (read_rv < 0)
|
|
309 return read_rv;
|
1
|
310
|
79
|
311 res = read_rv + 1;
|
1
|
312
|
|
313
|
|
314 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), "");
|
|
315 debug_print(debug_buff);
|
|
316
|
|
317
|
79
|
318 if(buflen < sizeof(struct sflap_hdr) + ntohs(hdr->len) + 1) {
|
|
319 do_error_dialog("Buffer too small", "Gaim - Error (internal)");
|
|
320 return -1;
|
|
321 }
|
1
|
322
|
|
323 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) {
|
79
|
324 read_rv = read(toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res);
|
|
325 if(read_rv < 0) return read_rv;
|
|
326 res += read_rv;
|
1
|
327 while(gtk_events_pending())
|
|
328 gtk_main_iteration();
|
|
329 }
|
|
330
|
|
331 if (res >= sizeof(struct sflap_hdr))
|
|
332 buffer[res]='\0';
|
|
333 else
|
|
334 return res - sizeof(struct sflap_hdr);
|
|
335
|
|
336 switch(hdr->type) {
|
|
337 case TYPE_SIGNON:
|
|
338 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4);
|
|
339 peer_ver = ntohl(peer_ver);
|
|
340 seqno = ntohs(hdr->seqno);
|
|
341 state = STATE_SIGNON_REQUEST;
|
|
342 break;
|
|
343 case TYPE_DATA:
|
|
344 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:")))
|
|
345 state = STATE_SIGNON_ACK;
|
|
346 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) {
|
|
347 state = STATE_CONFIG;
|
|
348 } else if (state != STATE_ONLINE && !strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) {
|
|
349 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":");
|
|
350 show_error_dialog(c);
|
|
351 }
|
|
352
|
|
353 sprintf(debug_buff, "Data: %s\n",buffer + sizeof(struct sflap_hdr));
|
|
354 debug_print(debug_buff);
|
|
355
|
|
356 break;
|
|
357 default:
|
|
358 sprintf(debug_buff, "Unknown/unimplemented packet type %d\n",hdr->type);
|
|
359 debug_print(debug_buff);
|
|
360 }
|
|
361 return res;
|
|
362 }
|
|
363
|
|
364
|
|
365
|
|
366 void toc_callback( gpointer data,
|
|
367 gint source,
|
|
368 GdkInputCondition condition )
|
|
369 {
|
|
370 char *buf;
|
|
371 char *c;
|
|
372 char *l;
|
|
373
|
|
374 buf = g_malloc(BUF_LONG);
|
|
375 if (wait_reply(buf, BUF_LONG) < 0) {
|
|
376 signoff();
|
|
377 hide_login_progress("Connection Closed");
|
|
378 g_free(buf);
|
|
379 return;
|
|
380 }
|
|
381
|
|
382
|
|
383 c=strtok(buf+sizeof(struct sflap_hdr),":"); /* Ditch the first part */
|
|
384 if (!strcasecmp(c,"UPDATE_BUDDY")) {
|
|
385 char *uc;
|
|
386 int logged, evil, idle, type = 0;
|
|
387 time_t signon;
|
|
388 time_t time_idle;
|
|
389
|
|
390 c = strtok(NULL,":"); /* c is name */
|
|
391
|
|
392 l = strtok(NULL,":"); /* l is T/F logged status */
|
|
393
|
|
394 sscanf(strtok(NULL, ":"), "%d", &evil);
|
|
395
|
|
396 sscanf(strtok(NULL, ":"), "%ld", &signon);
|
|
397
|
|
398 sscanf(strtok(NULL, ":"), "%d", &idle);
|
|
399
|
|
400 uc = strtok(NULL, ":");
|
|
401
|
|
402
|
|
403 if (!strncasecmp(l,"T",1))
|
|
404 logged = 1;
|
|
405 else
|
|
406 logged = 0;
|
|
407
|
|
408
|
|
409 if (uc[0] == 'A')
|
|
410 type |= UC_AOL;
|
|
411
|
|
412 switch(uc[1]) {
|
|
413 case 'A':
|
|
414 type |= UC_ADMIN;
|
|
415 break;
|
|
416 case 'U':
|
|
417 type |= UC_UNCONFIRMED;
|
|
418 break;
|
|
419 case 'O':
|
|
420 type |= UC_NORMAL;
|
|
421 break;
|
|
422 default:
|
|
423 break;
|
|
424 }
|
|
425
|
|
426 switch(uc[2]) {
|
|
427 case 'U':
|
|
428 type |= UC_UNAVAILABLE;
|
|
429 break;
|
|
430 default:
|
|
431 break;
|
|
432 }
|
|
433
|
|
434 if (idle) {
|
|
435 time(&time_idle);
|
|
436 time_idle -= idle*60;
|
|
437 } else
|
|
438 time_idle = 0;
|
|
439
|
|
440 serv_got_update(c, logged, evil, signon, time_idle, type);
|
|
441
|
|
442 } else if (!strcasecmp(c, "ERROR")) {
|
|
443 c = strtok(NULL,":");
|
|
444 show_error_dialog(c);
|
|
445 } else if (!strcasecmp(c, "NICK")) {
|
|
446 c = strtok(NULL,":");
|
|
447 g_snprintf(current_user->username, sizeof(current_user->username), "%s", c);
|
|
448 } else if (!strcasecmp(c, "IM_IN")) {
|
|
449 char *away, *message;
|
|
450 int a = 0;
|
|
451
|
|
452 c = strtok(NULL,":");
|
|
453 away = strtok(NULL,":");
|
|
454
|
|
455 message = away;
|
|
456
|
|
457 while(*message && (*message != ':'))
|
|
458 message++;
|
|
459
|
|
460 message++;
|
|
461
|
|
462 if (!strncasecmp(away, "T", 1))
|
|
463 a = 1;
|
|
464 serv_got_im(c, message, a);
|
|
465
|
|
466 } else if (!strcasecmp(c, "GOTO_URL")) {
|
|
467 char *name;
|
|
468 char *url;
|
|
469
|
|
470 char tmp[256];
|
|
471
|
|
472 name = strtok(NULL, ":");
|
|
473 url = strtok(NULL, ":");
|
|
474
|
|
475
|
|
476 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url);
|
|
477 /* fprintf(stdout, "Name: %s\n%s\n", name, url);
|
|
478 printf("%s", grab_url(tmp));*/
|
|
479 g_show_info(tmp);
|
|
480 } else if (!strcasecmp(c, "EVILED")) {
|
|
481 int lev;
|
|
482 char *name = NULL;
|
|
483
|
|
484 sscanf(strtok(NULL, ":"), "%d", &lev);
|
|
485 name = strtok(NULL, ":");
|
|
486
|
|
487 sprintf(debug_buff,"%s | %d\n", name, lev);
|
|
488 debug_print(debug_buff);
|
|
489
|
|
490 serv_got_eviled(name, lev);
|
|
491
|
|
492 } else if (!strcasecmp(c, "CHAT_JOIN")) {
|
|
493 char *name;
|
|
494 int id;
|
|
495
|
|
496
|
|
497 sscanf(strtok(NULL, ":"), "%d", &id);
|
|
498 name = strtok(NULL, ":");
|
|
499 serv_got_joined_chat(id, name);
|
|
500
|
|
501 } else if (!strcasecmp(c, "DIR_STATUS")) {
|
|
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 #if 0
|
|
584 } else if (!strcasecmp(c, "RVOUS_PROPOSE")) {
|
|
585 /* File trans. Yummy. */
|
|
586 char *user;
|
|
587 char *uuid;
|
|
588 char *cookie;
|
|
589 int seq;
|
|
590 char *rip, *pip, *vip;
|
|
591 int port;
|
|
592 int unk[4];
|
|
593 char *messages[4];
|
|
594 int subtype, files, totalsize;
|
|
595 char *name;
|
|
596 char *tmp;
|
|
597 int i;
|
|
598 struct file_transfer *ft;
|
|
599
|
|
600
|
|
601 user = strtok(NULL, ":");
|
|
602 uuid = strtok(NULL, ":");
|
|
603 cookie = strtok(NULL, ":");
|
|
604 sscanf(strtok(NULL, ":"), "%d", &seq);
|
|
605 rip = strtok(NULL, ":");
|
|
606 pip = strtok(NULL, ":");
|
|
607 vip = strtok(NULL, ":");
|
|
608 sscanf(strtok(NULL, ":"), "%d", &port);
|
|
609 for (i=0; i<4; i++) {
|
|
610 sscanf(strtok(NULL, ":"), "%d", &unk[i]);
|
|
611 if (unk[i] == 10001)
|
|
612 break;
|
|
613 messages[i] = frombase64(strtok(NULL, ":"));
|
|
614 }
|
|
615
|
|
616 tmp = frombase64(strtok(NULL, ":"));
|
|
617
|
|
618 subtype = tmp[1];
|
|
619 files = tmp[3]; /* These are fine */
|
|
620
|
|
621 totalsize = (tmp[4] << 24 & 0xff) |
|
|
622 (tmp[5] << 16 & 0xff) |
|
|
623 (tmp[6] << 8 & 0xff) |
|
|
624 (tmp[7] & 0xff);
|
|
625
|
|
626 name = tmp + 8;
|
|
627
|
|
628 ft = g_new0(struct file_transfer, 1);
|
|
629
|
|
630 ft->cookie = g_strdup(cookie);
|
|
631 ft->ip = g_strdup(pip);
|
|
632 ft->port = port;
|
|
633 if (i)
|
|
634 ft->message = g_strdup(messages[0]);
|
|
635 else
|
|
636 ft->message = NULL;
|
|
637 ft->filename = g_strdup(name);
|
|
638 ft->user = g_strdup(user);
|
|
639 ft->size = totalsize;
|
|
640
|
|
641 g_free(tmp);
|
|
642
|
|
643 for (i--; i >= 0; i--)
|
|
644 g_free(messages[i]);
|
|
645
|
|
646 accept_file_dialog(ft);
|
|
647 #endif
|
|
648 } else {
|
|
649 sprintf(debug_buff,"don't know what to do with %s\n", c);
|
|
650 debug_print(debug_buff);
|
|
651 }
|
|
652 g_free(buf);
|
|
653 }
|
|
654
|
|
655
|
|
656 int toc_signon(char *username, char *password)
|
|
657 {
|
|
658 char buf[BUF_LONG];
|
|
659 int res;
|
|
660 struct signon so;
|
|
661
|
|
662 sprintf(debug_buff,"State = %d\n", state);
|
|
663 debug_print(debug_buff);
|
|
664
|
|
665 if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0)
|
|
666 return res;
|
|
667 /* Wait for signon packet */
|
|
668
|
|
669 state = STATE_FLAPON;
|
|
670
|
|
671 if ((res = wait_reply(buf, sizeof(buf)) < 0))
|
|
672 return res;
|
|
673
|
|
674 if (state != STATE_SIGNON_REQUEST) {
|
|
675 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state);
|
|
676 debug_print(debug_buff);
|
|
677 return -1;
|
|
678 }
|
|
679
|
|
680 /* Compose a response */
|
|
681
|
|
682 g_snprintf(so.username, sizeof(so.username), "%s", username);
|
|
683 so.ver = ntohl(1);
|
|
684 so.tag = ntohs(1);
|
|
685 so.namelen = htons(strlen(so.username));
|
|
686
|
|
687 sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON);
|
|
688
|
|
689 g_snprintf(buf, sizeof(buf),
|
|
690 "toc_signon %s %d %s %s %s \"%s\"",
|
|
691 login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION);
|
|
692
|
|
693 sprintf(debug_buff,"Send: %s\n", buf);
|
|
694 debug_print(debug_buff);
|
|
695
|
|
696 return sflap_send(buf, -1, TYPE_DATA);
|
|
697 }
|
|
698
|
|
699 int toc_wait_signon()
|
|
700 {
|
|
701 /* Wait for the SIGNON to be approved */
|
|
702 char buf[BUF_LEN];
|
|
703 int res;
|
|
704 res = wait_reply(buf, sizeof(buf));
|
|
705 if (res < 0)
|
|
706 return res;
|
|
707 if (state != STATE_SIGNON_ACK) {
|
|
708 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state);
|
|
709 debug_print(debug_buff);
|
|
710 return -1;
|
|
711 }
|
|
712 return 0;
|
|
713 }
|
|
714
|
|
715 #ifdef _WIN32
|
|
716 gint win32_read()
|
|
717 {
|
|
718 int ret;
|
|
719 struct fd_set fds;
|
|
720 struct timeval tv;
|
|
721
|
|
722 FD_ZERO(&fds);
|
|
723
|
|
724 tv.tv_sec = 0;
|
|
725 tv.tv_usec = 200;
|
|
726
|
|
727 FD_SET(toc_fd, &fds);
|
|
728
|
|
729 ret = select(toc_fd + 1, &fds, NULL, NULL, &tv);
|
|
730
|
|
731 if (ret == 0) {
|
|
732 return TRUE;
|
|
733 }
|
|
734
|
|
735 toc_callback(NULL, 0, (GdkInputCondition)0);
|
|
736 return TRUE;
|
|
737 }
|
|
738 #endif
|
|
739
|
|
740
|
|
741 char *toc_wait_config()
|
|
742 {
|
|
743 /* Waits for configuration packet, returning the contents of the packet */
|
|
744 static char buf[BUF_LEN];
|
|
745 int res;
|
|
746 res = wait_reply(buf, sizeof(buf));
|
|
747 if (res < 0)
|
|
748 return NULL;
|
|
749 if (state != STATE_CONFIG) {
|
|
750 sprintf(debug_buff , "State should be %d, but is %d instead\n",STATE_CONFIG, state);
|
|
751 debug_print(debug_buff);
|
|
752 return NULL;
|
|
753 }
|
|
754 /* At this point, it's time to setup automatic handling of incoming packets */
|
|
755 state = STATE_ONLINE;
|
|
756 #ifdef _WIN32
|
|
757 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL);
|
|
758 #else
|
|
759 inpa = gdk_input_add(toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, NULL);
|
|
760 #endif
|
|
761 return buf;
|
|
762 }
|
|
763
|
|
764
|
|
765 void toc_build_config(char *s, int len)
|
|
766 {
|
|
767 GList *grp = groups;
|
|
768 GList *mem;
|
|
769 struct group *g;
|
|
770 struct buddy *b;
|
|
771 GList *plist = permit;
|
|
772 GList *dlist = deny;
|
|
773
|
|
774 int pos=0;
|
|
775
|
|
776 if (!permdeny)
|
|
777 permdeny = 1;
|
|
778 pos += g_snprintf(&s[pos], len - pos, "m %d\n", permdeny);
|
|
779 while(grp) {
|
|
780 g = (struct group *)grp->data;
|
|
781 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name);
|
|
782 mem = g->members;
|
|
783 while(mem) {
|
|
784 b = (struct buddy *)mem->data;
|
|
785 pos += g_snprintf(&s[pos], len - pos, "b %s\n", b->name);
|
|
786 mem = mem->next;
|
|
787 }
|
|
788 grp = grp ->next;
|
|
789 }
|
|
790 while(plist) {
|
|
791 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data);
|
|
792 plist=plist->next;
|
|
793
|
|
794 }
|
|
795 while(dlist) {
|
|
796 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data);
|
|
797 dlist=dlist->next;
|
|
798 }
|
|
799 }
|
|
800
|
|
801 void parse_toc_buddy_list(char *config)
|
|
802 {
|
|
803 char *c;
|
|
804 char current[256];
|
|
805 char *name;
|
|
806 GList *bud;
|
|
807 /* Clean out the permit/deny list!*/
|
|
808 g_list_free(permit);
|
|
809 g_list_free(deny);
|
|
810 permit = NULL;
|
|
811 deny = NULL;
|
|
812 bud = NULL;
|
|
813
|
|
814
|
|
815 /* skip "CONFIG:" (if it exists)*/
|
|
816
|
|
817 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))?
|
|
818 strtok(config, "\n"):
|
|
819 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n");
|
|
820 do {
|
|
821 if (c == NULL)
|
|
822 break;
|
|
823 if (*c == 'g') {
|
|
824 strncpy(current,c+2, sizeof(current));
|
|
825 add_group(current);
|
|
826 } else if (*c == 'b') {
|
|
827 add_buddy(current, c+2);
|
|
828 bud = g_list_append(bud, c+2);
|
|
829 } else if (*c == 'p') {
|
|
830 name = g_malloc(strlen(c+2) + 2);
|
|
831 g_snprintf(name, strlen(c+2) + 1, "%s", c+2);
|
|
832 permit = g_list_append(permit, name);
|
|
833 } else if (*c == 'd') {
|
|
834 name = g_malloc(strlen(c+2) + 2);
|
|
835 g_snprintf(name, strlen(c+2) + 1, "%s", c+2);
|
|
836 deny = g_list_append(deny, name);
|
|
837 } else if (*c == 'm') {
|
|
838 sscanf(c + strlen(c) - 1, "%d", &permdeny);
|
|
839 if (permdeny == 0)
|
|
840 permdeny = 1;
|
|
841 }
|
|
842 }while((c=strtok(NULL,"\n")));
|
|
843 #if 0
|
|
844 fprintf(stdout, "Sending message '%s'\n",buf);
|
|
845 #endif
|
|
846
|
|
847 serv_add_buddies(bud);
|
|
848 serv_set_permit_deny();
|
|
849 }
|