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