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
|
|
286 int wait_reply(char *buffer, int buflen)
|
|
287 {
|
|
288 int res=6;
|
|
289 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer;
|
|
290 char *c;
|
|
291
|
|
292 while((res = read(toc_fd, buffer, 1))) {
|
|
293 if (res < 0)
|
|
294 return res;
|
|
295 if (buffer[0] == '*')
|
|
296 break;
|
|
297
|
|
298 }
|
|
299
|
|
300 res = read(toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1);
|
|
301
|
|
302 if (res < 0)
|
|
303 return res;
|
|
304
|
|
305 res += 1;
|
|
306
|
|
307
|
|
308 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), "");
|
|
309 debug_print(debug_buff);
|
|
310
|
|
311
|
|
312
|
|
313 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) {
|
|
314 res += read(toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res);
|
|
315 while(gtk_events_pending())
|
|
316 gtk_main_iteration();
|
|
317 }
|
|
318
|
|
319 if (res >= sizeof(struct sflap_hdr))
|
|
320 buffer[res]='\0';
|
|
321 else
|
|
322 return res - sizeof(struct sflap_hdr);
|
|
323
|
|
324 switch(hdr->type) {
|
|
325 case TYPE_SIGNON:
|
|
326 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4);
|
|
327 peer_ver = ntohl(peer_ver);
|
|
328 seqno = ntohs(hdr->seqno);
|
|
329 state = STATE_SIGNON_REQUEST;
|
|
330 break;
|
|
331 case TYPE_DATA:
|
|
332 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:")))
|
|
333 state = STATE_SIGNON_ACK;
|
|
334 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) {
|
|
335 state = STATE_CONFIG;
|
|
336 } else if (state != STATE_ONLINE && !strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) {
|
|
337 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":");
|
|
338 show_error_dialog(c);
|
|
339 }
|
|
340
|
|
341 sprintf(debug_buff, "Data: %s\n",buffer + sizeof(struct sflap_hdr));
|
|
342 debug_print(debug_buff);
|
|
343
|
|
344 break;
|
|
345 default:
|
|
346 sprintf(debug_buff, "Unknown/unimplemented packet type %d\n",hdr->type);
|
|
347 debug_print(debug_buff);
|
|
348 }
|
|
349 return res;
|
|
350 }
|
|
351
|
|
352
|
|
353
|
|
354 void toc_callback( gpointer data,
|
|
355 gint source,
|
|
356 GdkInputCondition condition )
|
|
357 {
|
|
358 char *buf;
|
|
359 char *c;
|
|
360 char *l;
|
|
361
|
|
362 buf = g_malloc(BUF_LONG);
|
|
363 if (wait_reply(buf, BUF_LONG) < 0) {
|
|
364 signoff();
|
|
365 hide_login_progress("Connection Closed");
|
|
366 g_free(buf);
|
|
367 return;
|
|
368 }
|
|
369
|
|
370
|
|
371 c=strtok(buf+sizeof(struct sflap_hdr),":"); /* Ditch the first part */
|
|
372 if (!strcasecmp(c,"UPDATE_BUDDY")) {
|
|
373 char *uc;
|
|
374 int logged, evil, idle, type = 0;
|
|
375 time_t signon;
|
|
376 time_t time_idle;
|
|
377
|
|
378 c = strtok(NULL,":"); /* c is name */
|
|
379
|
|
380 l = strtok(NULL,":"); /* l is T/F logged status */
|
|
381
|
|
382 sscanf(strtok(NULL, ":"), "%d", &evil);
|
|
383
|
|
384 sscanf(strtok(NULL, ":"), "%ld", &signon);
|
|
385
|
|
386 sscanf(strtok(NULL, ":"), "%d", &idle);
|
|
387
|
|
388 uc = strtok(NULL, ":");
|
|
389
|
|
390
|
|
391 if (!strncasecmp(l,"T",1))
|
|
392 logged = 1;
|
|
393 else
|
|
394 logged = 0;
|
|
395
|
|
396
|
|
397 if (uc[0] == 'A')
|
|
398 type |= UC_AOL;
|
|
399
|
|
400 switch(uc[1]) {
|
|
401 case 'A':
|
|
402 type |= UC_ADMIN;
|
|
403 break;
|
|
404 case 'U':
|
|
405 type |= UC_UNCONFIRMED;
|
|
406 break;
|
|
407 case 'O':
|
|
408 type |= UC_NORMAL;
|
|
409 break;
|
|
410 default:
|
|
411 break;
|
|
412 }
|
|
413
|
|
414 switch(uc[2]) {
|
|
415 case 'U':
|
|
416 type |= UC_UNAVAILABLE;
|
|
417 break;
|
|
418 default:
|
|
419 break;
|
|
420 }
|
|
421
|
|
422 if (idle) {
|
|
423 time(&time_idle);
|
|
424 time_idle -= idle*60;
|
|
425 } else
|
|
426 time_idle = 0;
|
|
427
|
|
428 serv_got_update(c, logged, evil, signon, time_idle, type);
|
|
429
|
|
430 } else if (!strcasecmp(c, "ERROR")) {
|
|
431 c = strtok(NULL,":");
|
|
432 show_error_dialog(c);
|
|
433 } else if (!strcasecmp(c, "NICK")) {
|
|
434 c = strtok(NULL,":");
|
|
435 g_snprintf(current_user->username, sizeof(current_user->username), "%s", c);
|
|
436 } else if (!strcasecmp(c, "IM_IN")) {
|
|
437 char *away, *message;
|
|
438 int a = 0;
|
|
439
|
|
440 c = strtok(NULL,":");
|
|
441 away = strtok(NULL,":");
|
|
442
|
|
443 message = away;
|
|
444
|
|
445 while(*message && (*message != ':'))
|
|
446 message++;
|
|
447
|
|
448 message++;
|
|
449
|
|
450 if (!strncasecmp(away, "T", 1))
|
|
451 a = 1;
|
|
452 serv_got_im(c, message, a);
|
|
453
|
|
454 } else if (!strcasecmp(c, "GOTO_URL")) {
|
|
455 char *name;
|
|
456 char *url;
|
|
457
|
|
458 char tmp[256];
|
|
459
|
|
460 name = strtok(NULL, ":");
|
|
461 url = strtok(NULL, ":");
|
|
462
|
|
463
|
|
464 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url);
|
|
465 /* fprintf(stdout, "Name: %s\n%s\n", name, url);
|
|
466 printf("%s", grab_url(tmp));*/
|
|
467 g_show_info(tmp);
|
|
468 } else if (!strcasecmp(c, "EVILED")) {
|
|
469 int lev;
|
|
470 char *name = NULL;
|
|
471
|
|
472 sscanf(strtok(NULL, ":"), "%d", &lev);
|
|
473 name = strtok(NULL, ":");
|
|
474
|
|
475 sprintf(debug_buff,"%s | %d\n", name, lev);
|
|
476 debug_print(debug_buff);
|
|
477
|
|
478 serv_got_eviled(name, lev);
|
|
479
|
|
480 } else if (!strcasecmp(c, "CHAT_JOIN")) {
|
|
481 char *name;
|
|
482 int id;
|
|
483
|
|
484
|
|
485 sscanf(strtok(NULL, ":"), "%d", &id);
|
|
486 name = strtok(NULL, ":");
|
|
487 serv_got_joined_chat(id, name);
|
|
488
|
|
489 } else if (!strcasecmp(c, "DIR_STATUS")) {
|
|
490 } else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) {
|
|
491 int id;
|
|
492 char *in;
|
|
493 char *buddy;
|
|
494 GList *bcs = buddy_chats;
|
|
495 struct buddy_chat *b = NULL;
|
|
496
|
|
497 sscanf(strtok(NULL, ":"), "%d", &id);
|
|
498
|
|
499 in = strtok(NULL, ":");
|
|
500
|
|
501 while(bcs) {
|
|
502 b = (struct buddy_chat *)bcs->data;
|
|
503 if (id == b->id)
|
|
504 break;
|
|
505 bcs = bcs->next;
|
|
506 b = NULL;
|
|
507 }
|
|
508
|
44
|
509 if (!b) {
|
45
|
510 g_free(buf);
|
1
|
511 return;
|
44
|
512 }
|
1
|
513
|
|
514
|
|
515 if (!strcasecmp(in, "T")) {
|
|
516 while((buddy = strtok(NULL, ":")) != NULL) {
|
|
517 add_chat_buddy(b, buddy);
|
|
518 }
|
|
519 } else {
|
|
520 while((buddy = strtok(NULL, ":")) != NULL) {
|
|
521 remove_chat_buddy(b, buddy);
|
|
522 }
|
|
523 }
|
|
524
|
|
525 } else if (!strcasecmp(c, "CHAT_LEFT")) {
|
|
526 int id;
|
|
527
|
|
528
|
|
529 sscanf(strtok(NULL, ":"), "%d", &id);
|
|
530
|
|
531 serv_got_chat_left(id);
|
|
532
|
|
533
|
|
534 } else if (!strcasecmp(c, "CHAT_IN")) {
|
|
535
|
|
536 int id, w;
|
|
537 char *m;
|
|
538 char *who, *whisper;
|
|
539
|
|
540
|
|
541 sscanf(strtok(NULL, ":"), "%d", &id);
|
|
542 who = strtok(NULL, ":");
|
|
543 whisper = strtok(NULL, ":");
|
|
544 m = whisper;
|
|
545 while(*m && (*m != ':')) m++;
|
|
546 m++;
|
|
547
|
|
548 if (!strcasecmp(whisper, "T"))
|
|
549 w = 1;
|
|
550 else
|
|
551 w = 0;
|
|
552
|
|
553 serv_got_chat_in(id, who, w, m);
|
|
554
|
|
555
|
|
556 } else if (!strcasecmp(c, "CHAT_INVITE")) {
|
|
557 char *name;
|
|
558 char *who;
|
|
559 char *message;
|
|
560 int id;
|
|
561
|
|
562
|
|
563 name = strtok(NULL, ":");
|
|
564 sscanf(strtok(NULL, ":"), "%d", &id);
|
|
565 who = strtok(NULL, ":");
|
|
566 message = strtok(NULL, ":");
|
|
567
|
|
568 serv_got_chat_invite(name, id, who, message);
|
|
569
|
|
570
|
|
571 #if 0
|
|
572 } else if (!strcasecmp(c, "RVOUS_PROPOSE")) {
|
|
573 /* File trans. Yummy. */
|
|
574 char *user;
|
|
575 char *uuid;
|
|
576 char *cookie;
|
|
577 int seq;
|
|
578 char *rip, *pip, *vip;
|
|
579 int port;
|
|
580 int unk[4];
|
|
581 char *messages[4];
|
|
582 int subtype, files, totalsize;
|
|
583 char *name;
|
|
584 char *tmp;
|
|
585 int i;
|
|
586 struct file_transfer *ft;
|
|
587
|
|
588
|
|
589 user = strtok(NULL, ":");
|
|
590 uuid = strtok(NULL, ":");
|
|
591 cookie = strtok(NULL, ":");
|
|
592 sscanf(strtok(NULL, ":"), "%d", &seq);
|
|
593 rip = strtok(NULL, ":");
|
|
594 pip = strtok(NULL, ":");
|
|
595 vip = strtok(NULL, ":");
|
|
596 sscanf(strtok(NULL, ":"), "%d", &port);
|
|
597 for (i=0; i<4; i++) {
|
|
598 sscanf(strtok(NULL, ":"), "%d", &unk[i]);
|
|
599 if (unk[i] == 10001)
|
|
600 break;
|
|
601 messages[i] = frombase64(strtok(NULL, ":"));
|
|
602 }
|
|
603
|
|
604 tmp = frombase64(strtok(NULL, ":"));
|
|
605
|
|
606 subtype = tmp[1];
|
|
607 files = tmp[3]; /* These are fine */
|
|
608
|
|
609 totalsize = (tmp[4] << 24 & 0xff) |
|
|
610 (tmp[5] << 16 & 0xff) |
|
|
611 (tmp[6] << 8 & 0xff) |
|
|
612 (tmp[7] & 0xff);
|
|
613
|
|
614 name = tmp + 8;
|
|
615
|
|
616 ft = g_new0(struct file_transfer, 1);
|
|
617
|
|
618 ft->cookie = g_strdup(cookie);
|
|
619 ft->ip = g_strdup(pip);
|
|
620 ft->port = port;
|
|
621 if (i)
|
|
622 ft->message = g_strdup(messages[0]);
|
|
623 else
|
|
624 ft->message = NULL;
|
|
625 ft->filename = g_strdup(name);
|
|
626 ft->user = g_strdup(user);
|
|
627 ft->size = totalsize;
|
|
628
|
|
629 g_free(tmp);
|
|
630
|
|
631 for (i--; i >= 0; i--)
|
|
632 g_free(messages[i]);
|
|
633
|
|
634 accept_file_dialog(ft);
|
|
635 #endif
|
|
636 } else {
|
|
637 sprintf(debug_buff,"don't know what to do with %s\n", c);
|
|
638 debug_print(debug_buff);
|
|
639 }
|
|
640 g_free(buf);
|
|
641 }
|
|
642
|
|
643
|
|
644 int toc_signon(char *username, char *password)
|
|
645 {
|
|
646 char buf[BUF_LONG];
|
|
647 int res;
|
|
648 struct signon so;
|
|
649
|
|
650 sprintf(debug_buff,"State = %d\n", state);
|
|
651 debug_print(debug_buff);
|
|
652
|
|
653 if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0)
|
|
654 return res;
|
|
655 /* Wait for signon packet */
|
|
656
|
|
657 state = STATE_FLAPON;
|
|
658
|
|
659 if ((res = wait_reply(buf, sizeof(buf)) < 0))
|
|
660 return res;
|
|
661
|
|
662 if (state != STATE_SIGNON_REQUEST) {
|
|
663 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state);
|
|
664 debug_print(debug_buff);
|
|
665 return -1;
|
|
666 }
|
|
667
|
|
668 /* Compose a response */
|
|
669
|
|
670 g_snprintf(so.username, sizeof(so.username), "%s", username);
|
|
671 so.ver = ntohl(1);
|
|
672 so.tag = ntohs(1);
|
|
673 so.namelen = htons(strlen(so.username));
|
|
674
|
|
675 sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON);
|
|
676
|
|
677 g_snprintf(buf, sizeof(buf),
|
|
678 "toc_signon %s %d %s %s %s \"%s\"",
|
|
679 login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION);
|
|
680
|
|
681 sprintf(debug_buff,"Send: %s\n", buf);
|
|
682 debug_print(debug_buff);
|
|
683
|
|
684 return sflap_send(buf, -1, TYPE_DATA);
|
|
685 }
|
|
686
|
|
687 int toc_wait_signon()
|
|
688 {
|
|
689 /* Wait for the SIGNON to be approved */
|
|
690 char buf[BUF_LEN];
|
|
691 int res;
|
|
692 res = wait_reply(buf, sizeof(buf));
|
|
693 if (res < 0)
|
|
694 return res;
|
|
695 if (state != STATE_SIGNON_ACK) {
|
|
696 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state);
|
|
697 debug_print(debug_buff);
|
|
698 return -1;
|
|
699 }
|
|
700 return 0;
|
|
701 }
|
|
702
|
|
703 #ifdef _WIN32
|
|
704 gint win32_read()
|
|
705 {
|
|
706 int ret;
|
|
707 struct fd_set fds;
|
|
708 struct timeval tv;
|
|
709
|
|
710 FD_ZERO(&fds);
|
|
711
|
|
712 tv.tv_sec = 0;
|
|
713 tv.tv_usec = 200;
|
|
714
|
|
715 FD_SET(toc_fd, &fds);
|
|
716
|
|
717 ret = select(toc_fd + 1, &fds, NULL, NULL, &tv);
|
|
718
|
|
719 if (ret == 0) {
|
|
720 return TRUE;
|
|
721 }
|
|
722
|
|
723 toc_callback(NULL, 0, (GdkInputCondition)0);
|
|
724 return TRUE;
|
|
725 }
|
|
726 #endif
|
|
727
|
|
728
|
|
729 char *toc_wait_config()
|
|
730 {
|
|
731 /* Waits for configuration packet, returning the contents of the packet */
|
|
732 static char buf[BUF_LEN];
|
|
733 int res;
|
|
734 res = wait_reply(buf, sizeof(buf));
|
|
735 if (res < 0)
|
|
736 return NULL;
|
|
737 if (state != STATE_CONFIG) {
|
|
738 sprintf(debug_buff , "State should be %d, but is %d instead\n",STATE_CONFIG, state);
|
|
739 debug_print(debug_buff);
|
|
740 return NULL;
|
|
741 }
|
|
742 /* At this point, it's time to setup automatic handling of incoming packets */
|
|
743 state = STATE_ONLINE;
|
|
744 #ifdef _WIN32
|
|
745 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL);
|
|
746 #else
|
|
747 inpa = gdk_input_add(toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, NULL);
|
|
748 #endif
|
|
749 return buf;
|
|
750 }
|
|
751
|
|
752
|
|
753 void toc_build_config(char *s, int len)
|
|
754 {
|
|
755 GList *grp = groups;
|
|
756 GList *mem;
|
|
757 struct group *g;
|
|
758 struct buddy *b;
|
|
759 GList *plist = permit;
|
|
760 GList *dlist = deny;
|
|
761
|
|
762 int pos=0;
|
|
763
|
|
764 if (!permdeny)
|
|
765 permdeny = 1;
|
|
766 pos += g_snprintf(&s[pos], len - pos, "m %d\n", permdeny);
|
|
767 while(grp) {
|
|
768 g = (struct group *)grp->data;
|
|
769 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name);
|
|
770 mem = g->members;
|
|
771 while(mem) {
|
|
772 b = (struct buddy *)mem->data;
|
|
773 pos += g_snprintf(&s[pos], len - pos, "b %s\n", b->name);
|
|
774 mem = mem->next;
|
|
775 }
|
|
776 grp = grp ->next;
|
|
777 }
|
|
778 while(plist) {
|
|
779 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data);
|
|
780 plist=plist->next;
|
|
781
|
|
782 }
|
|
783 while(dlist) {
|
|
784 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data);
|
|
785 dlist=dlist->next;
|
|
786 }
|
|
787 }
|
|
788
|
|
789 void parse_toc_buddy_list(char *config)
|
|
790 {
|
|
791 char *c;
|
|
792 char current[256];
|
|
793 char *name;
|
|
794 GList *bud;
|
|
795 /* Clean out the permit/deny list!*/
|
|
796 g_list_free(permit);
|
|
797 g_list_free(deny);
|
|
798 permit = NULL;
|
|
799 deny = NULL;
|
|
800 bud = NULL;
|
|
801
|
|
802
|
|
803 /* skip "CONFIG:" (if it exists)*/
|
|
804
|
|
805 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))?
|
|
806 strtok(config, "\n"):
|
|
807 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n");
|
|
808 do {
|
|
809 if (c == NULL)
|
|
810 break;
|
|
811 if (*c == 'g') {
|
|
812 strncpy(current,c+2, sizeof(current));
|
|
813 add_group(current);
|
|
814 } else if (*c == 'b') {
|
|
815 add_buddy(current, c+2);
|
|
816 bud = g_list_append(bud, c+2);
|
|
817 } else if (*c == 'p') {
|
|
818 name = g_malloc(strlen(c+2) + 2);
|
|
819 g_snprintf(name, strlen(c+2) + 1, "%s", c+2);
|
|
820 permit = g_list_append(permit, name);
|
|
821 } else if (*c == 'd') {
|
|
822 name = g_malloc(strlen(c+2) + 2);
|
|
823 g_snprintf(name, strlen(c+2) + 1, "%s", c+2);
|
|
824 deny = g_list_append(deny, name);
|
|
825 } else if (*c == 'm') {
|
|
826 sscanf(c + strlen(c) - 1, "%d", &permdeny);
|
|
827 if (permdeny == 0)
|
|
828 permdeny = 1;
|
|
829 }
|
|
830 }while((c=strtok(NULL,"\n")));
|
|
831 #if 0
|
|
832 fprintf(stdout, "Sending message '%s'\n",buf);
|
|
833 #endif
|
|
834
|
|
835 serv_add_buddies(bud);
|
|
836 serv_set_permit_deny();
|
|
837 }
|