Mercurial > pidgin
annotate src/toc.c @ 383:841b58aa069f
[gaim-migrate @ 393]
:-/
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 10 Jun 2000 07:35:19 +0000 |
parents | cf895313fc50 |
children | 0d4e80bdb96b |
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 | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
229
diff
changeset
|
41 #ifndef USE_OSCAR |
1 | 42 |
43 | |
44 /* descriptor for talking to TOC */ | |
45 static int toc_fd; | |
46 static int seqno; | |
47 static unsigned int peer_ver=0; | |
48 static int state; | |
49 static int inpa=-1; | |
50 #ifdef _WIN32 | |
51 static int win32_r; | |
52 #endif | |
53 | |
54 int toc_signon(char *username, char *password); | |
55 | |
56 | |
57 | |
58 int toc_login(char *username, char *password) | |
59 { | |
60 char *config; | |
61 struct in_addr *sin; | |
62 struct aim_user *u; | |
63 char buf[80]; | |
64 char buf2[2048]; | |
65 | |
66 g_snprintf(buf, sizeof(buf), "Looking up %s", aim_host); | |
67 set_login_progress(1, buf); | |
68 | |
69 sin = (struct in_addr *)get_address(aim_host); | |
70 if (!sin) { | |
71 | |
72 #ifdef USE_APPLET | |
73 setUserState(offline); | |
74 #endif /* USE_APPLET */ | |
75 set_state(STATE_OFFLINE); | |
76 g_snprintf(buf, sizeof(buf), "Unable to lookup %s", aim_host); | |
77 hide_login_progress(buf); | |
78 return -1; | |
79 } | |
80 | |
81 g_snprintf(toc_addy, sizeof(toc_addy), "%s", inet_ntoa(*sin)); | |
82 g_snprintf(buf, sizeof(buf), "Connecting to %s", inet_ntoa(*sin)); | |
83 | |
84 set_login_progress(2, buf); | |
85 | |
86 | |
87 | |
88 toc_fd = connect_address(sin->s_addr, aim_port); | |
89 | |
90 if (toc_fd < 0) { | |
91 #ifdef USE_APPLET | |
92 setUserState(offline); | |
93 #endif /* USE_APPLET */ | |
94 set_state(STATE_OFFLINE); | |
95 g_snprintf(buf, sizeof(buf), "Connect to %s failed", | |
96 inet_ntoa(*sin)); | |
97 hide_login_progress(buf); | |
98 return -1; | |
99 } | |
100 | |
101 g_free(sin); | |
102 | |
103 g_snprintf(buf, sizeof(buf), "Signon: %s",username); | |
104 | |
105 set_login_progress(3, buf); | |
106 | |
107 if (toc_signon(username, password) < 0) { | |
108 #ifdef USE_APPLET | |
109 setUserState(offline); | |
110 #endif /* USE_APPLET */ | |
111 set_state(STATE_OFFLINE); | |
112 hide_login_progress("Disconnected."); | |
113 return -1; | |
114 } | |
115 | |
116 g_snprintf(buf, sizeof(buf), "Waiting for reply..."); | |
117 set_login_progress(4, buf); | |
118 if (toc_wait_signon() < 0) { | |
119 #ifdef USE_APPLET | |
120 setUserState(offline); | |
121 #endif /* USE_APPLET */ | |
122 set_state(STATE_OFFLINE); | |
123 hide_login_progress("Authentication Failed"); | |
124 return -1; | |
125 } | |
126 | |
127 u = find_user(username); | |
128 | |
129 if (!u) { | |
130 u = g_new0(struct aim_user, 1); | |
131 g_snprintf(u->user_info, sizeof(u->user_info), DEFAULT_INFO); | |
132 aim_users = g_list_append(aim_users, u); | |
133 } | |
134 | |
135 current_user = u; | |
136 | |
137 g_snprintf(current_user->username, sizeof(current_user->username), "%s", username); | |
138 g_snprintf(current_user->password, sizeof(current_user->password), "%s", password); | |
139 | |
140 save_prefs(); | |
141 | |
142 g_snprintf(buf, sizeof(buf), "Retrieving config..."); | |
143 set_login_progress(5, buf); | |
300
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
144 config = toc_wait_config(); |
301
f905caee43ca
[gaim-migrate @ 311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
300
diff
changeset
|
145 state = STATE_ONLINE; |
1 | 146 |
147 #ifdef USE_APPLET | |
107
55faf2e3a134
[gaim-migrate @ 117]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
148 make_buddy(); |
10 | 149 if (general_options & OPT_GEN_APP_BUDDY_SHOW) { |
50 | 150 gnome_buddy_show(); |
300
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
151 if (config != NULL) |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
152 parse_toc_buddy_list(config, 0); |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
153 else |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
154 do_import(0, 0); |
50 | 155 createOnlinePopup(); |
1 | 156 set_applet_draw_open(); |
157 } else { | |
158 gnome_buddy_hide(); | |
300
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
159 if (config != NULL) |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
160 parse_toc_buddy_list(config, 0); |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
161 else |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
162 do_import(0, 0); |
1 | 163 set_applet_draw_closed(); |
164 } | |
165 | |
166 | |
167 setUserState(online); | |
10 | 168 gtk_widget_hide(mainwindow); |
1 | 169 #else |
170 gtk_widget_hide(mainwindow); | |
171 show_buddy_list(); | |
300
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
172 if (config != NULL) |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
173 parse_toc_buddy_list(config, 0); |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
174 else |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
175 do_import(0, 0); |
1 | 176 refresh_buddy_window(); |
177 #endif | |
178 | |
179 | |
180 g_snprintf(buf2, sizeof(buf2), "toc_init_done"); | |
181 sflap_send(buf2, -1, TYPE_DATA); | |
182 | |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
183 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
|
184 FILE_SEND_UID, FILE_GET_UID, B_ICON_UID, IMAGE_UID, |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
185 VOICE_UID); |
1 | 186 sflap_send(buf2, -1, TYPE_DATA); |
149 | 187 |
1 | 188 serv_finish_login(); |
189 return 0; | |
190 } | |
191 | |
192 void toc_close() | |
193 { | |
194 #ifdef USE_APPLET | |
195 setUserState(offline); | |
196 #endif /* USE_APPLET */ | |
197 seqno = 0; | |
198 state = STATE_OFFLINE; | |
199 if (inpa > 0) | |
200 gdk_input_remove(inpa); | |
201 close(toc_fd); | |
202 toc_fd=-1; | |
203 inpa=-1; | |
204 } | |
205 | |
206 unsigned char *roast_password(char *pass) | |
207 { | |
208 /* Trivial "encryption" */ | |
209 static char rp[256]; | |
210 static char *roast = ROAST; | |
211 int pos=2; | |
212 int x; | |
213 strcpy(rp, "0x"); | |
214 for (x=0;(x<150) && pass[x]; x++) | |
215 pos+=sprintf(&rp[pos],"%02x", pass[x] ^ roast[x % strlen(roast)]); | |
216 rp[pos]='\0'; | |
217 return rp; | |
218 } | |
219 | |
220 | |
221 char *print_header(void *hdr_v) | |
222 { | |
223 static char s[80]; | |
224 struct sflap_hdr *hdr = (struct sflap_hdr *)hdr_v; | |
225 g_snprintf(s,sizeof(s), "[ ast: %c, type: %d, seqno: %d, len: %d ]", | |
226 hdr->ast, hdr->type, ntohs(hdr->seqno), ntohs(hdr->len)); | |
227 return s; | |
228 } | |
229 | |
230 void print_buffer(char *buf, int len) | |
231 { | |
232 #if 0 | |
233 int x; | |
234 printf("[ "); | |
235 for (x=0;x<len;x++) | |
236 printf("%d ", buf[x]); | |
237 printf("]\n"); | |
238 printf("[ "); | |
239 for (x=0;x<len;x++) | |
240 printf("%c ", buf[x]); | |
241 printf("]\n"); | |
242 #endif | |
243 } | |
244 | |
245 int sflap_send(char *buf, int olen, int type) | |
246 { | |
247 int len; | |
248 int slen=0; | |
249 struct sflap_hdr hdr; | |
250 char obuf[MSG_LEN]; | |
251 | |
252 /* One _last_ 2048 check here! This shouldn't ever | |
253 * get hit though, hopefully. If it gets hit on an IM | |
254 * It'll lose the last " and the message won't go through, | |
255 * but this'll stop a segfault. */ | |
256 if (strlen(buf) > (MSG_LEN - sizeof(hdr))) { | |
257 buf[MSG_LEN - sizeof(hdr) - 3] = '"'; | |
258 buf[MSG_LEN - sizeof(hdr) - 2] = '\0'; | |
259 } | |
260 | |
261 sprintf(debug_buff,"%s [Len %d]\n", buf, strlen(buf)); | |
262 debug_print(debug_buff); | |
263 | |
264 | |
265 | |
266 if (olen < 0) | |
267 len = escape_message(buf); | |
268 else | |
269 len = olen; | |
270 hdr.ast = '*'; | |
271 hdr.type = type; | |
272 hdr.seqno = htons(seqno++ & 0xffff); | |
273 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); | |
274 | |
275 sprintf(debug_buff,"Escaped message is '%s'\n",buf); | |
276 debug_print(debug_buff); | |
277 | |
278 memcpy(obuf, &hdr, sizeof(hdr)); | |
279 slen += sizeof(hdr); | |
280 memcpy(&obuf[slen], buf, len); | |
281 slen += len; | |
282 if (type != TYPE_SIGNON) { | |
283 obuf[slen]='\0'; | |
284 slen += 1; | |
285 } | |
286 print_buffer(obuf, slen); | |
287 | |
288 return write(toc_fd, obuf, slen); | |
289 } | |
290 | |
291 | |
79 | 292 int wait_reply(char *buffer, size_t buflen) |
1 | 293 { |
79 | 294 size_t res=-1; |
295 int read_rv = -1; | |
1 | 296 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer; |
297 char *c; | |
298 | |
79 | 299 if(buflen < sizeof(struct sflap_hdr)) { |
300 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | |
301 return -1; | |
302 } | |
303 | |
304 while((read_rv = read(toc_fd, buffer, 1))) { | |
305 if (read_rv < 0 || read_rv > 1) | |
306 return -1; | |
1 | 307 if (buffer[0] == '*') |
308 break; | |
309 | |
310 } | |
311 | |
79 | 312 read_rv = read(toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1); |
1 | 313 |
79 | 314 if (read_rv < 0) |
315 return read_rv; | |
1 | 316 |
79 | 317 res = read_rv + 1; |
1 | 318 |
319 | |
320 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), ""); | |
321 debug_print(debug_buff); | |
322 | |
323 | |
79 | 324 if(buflen < sizeof(struct sflap_hdr) + ntohs(hdr->len) + 1) { |
325 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | |
326 return -1; | |
327 } | |
1 | 328 |
329 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) { | |
79 | 330 read_rv = read(toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res); |
331 if(read_rv < 0) return read_rv; | |
332 res += read_rv; | |
1 | 333 while(gtk_events_pending()) |
334 gtk_main_iteration(); | |
335 } | |
336 | |
337 if (res >= sizeof(struct sflap_hdr)) | |
338 buffer[res]='\0'; | |
339 else | |
340 return res - sizeof(struct sflap_hdr); | |
341 | |
342 switch(hdr->type) { | |
343 case TYPE_SIGNON: | |
344 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4); | |
345 peer_ver = ntohl(peer_ver); | |
346 seqno = ntohs(hdr->seqno); | |
347 state = STATE_SIGNON_REQUEST; | |
348 break; | |
349 case TYPE_DATA: | |
350 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:"))) | |
351 state = STATE_SIGNON_ACK; | |
352 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) { | |
353 state = STATE_CONFIG; | |
301
f905caee43ca
[gaim-migrate @ 311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
300
diff
changeset
|
354 } else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) { |
1 | 355 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":"); |
356 show_error_dialog(c); | |
357 } | |
358 | |
359 sprintf(debug_buff, "Data: %s\n",buffer + sizeof(struct sflap_hdr)); | |
360 debug_print(debug_buff); | |
361 | |
362 break; | |
363 default: | |
364 sprintf(debug_buff, "Unknown/unimplemented packet type %d\n",hdr->type); | |
365 debug_print(debug_buff); | |
366 } | |
367 return res; | |
368 } | |
369 | |
370 | |
371 | |
372 void toc_callback( gpointer data, | |
373 gint source, | |
374 GdkInputCondition condition ) | |
375 { | |
376 char *buf; | |
377 char *c; | |
378 char *l; | |
379 | |
380 buf = g_malloc(BUF_LONG); | |
381 if (wait_reply(buf, BUF_LONG) < 0) { | |
382 signoff(); | |
383 hide_login_progress("Connection Closed"); | |
384 g_free(buf); | |
385 return; | |
386 } | |
387 | |
388 | |
389 c=strtok(buf+sizeof(struct sflap_hdr),":"); /* Ditch the first part */ | |
390 if (!strcasecmp(c,"UPDATE_BUDDY")) { | |
391 char *uc; | |
392 int logged, evil, idle, type = 0; | |
393 time_t signon; | |
394 time_t time_idle; | |
395 | |
396 c = strtok(NULL,":"); /* c is name */ | |
397 | |
398 l = strtok(NULL,":"); /* l is T/F logged status */ | |
399 | |
400 sscanf(strtok(NULL, ":"), "%d", &evil); | |
401 | |
402 sscanf(strtok(NULL, ":"), "%ld", &signon); | |
403 | |
404 sscanf(strtok(NULL, ":"), "%d", &idle); | |
405 | |
406 uc = strtok(NULL, ":"); | |
407 | |
408 | |
409 if (!strncasecmp(l,"T",1)) | |
410 logged = 1; | |
411 else | |
412 logged = 0; | |
413 | |
414 | |
415 if (uc[0] == 'A') | |
416 type |= UC_AOL; | |
417 | |
418 switch(uc[1]) { | |
419 case 'A': | |
420 type |= UC_ADMIN; | |
421 break; | |
422 case 'U': | |
423 type |= UC_UNCONFIRMED; | |
424 break; | |
425 case 'O': | |
426 type |= UC_NORMAL; | |
427 break; | |
428 default: | |
429 break; | |
430 } | |
431 | |
432 switch(uc[2]) { | |
433 case 'U': | |
434 type |= UC_UNAVAILABLE; | |
435 break; | |
436 default: | |
437 break; | |
438 } | |
439 | |
440 if (idle) { | |
441 time(&time_idle); | |
442 time_idle -= idle*60; | |
443 } else | |
444 time_idle = 0; | |
445 | |
446 serv_got_update(c, logged, evil, signon, time_idle, type); | |
447 | |
300
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
448 } else if (!strcasecmp(c, "CONFIG")) { |
b32c83750104
[gaim-migrate @ 310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
296
diff
changeset
|
449 /* do we want to load the buddy list again here? */ |
318
35796808896a
[gaim-migrate @ 328]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
301
diff
changeset
|
450 c = strtok(NULL,":"); |
35796808896a
[gaim-migrate @ 328]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
301
diff
changeset
|
451 parse_toc_buddy_list(c, 0); |
1 | 452 } else if (!strcasecmp(c, "ERROR")) { |
301
f905caee43ca
[gaim-migrate @ 311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
300
diff
changeset
|
453 /* This should be handled by wait_reply |
1 | 454 c = strtok(NULL,":"); |
455 show_error_dialog(c); | |
301
f905caee43ca
[gaim-migrate @ 311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
300
diff
changeset
|
456 */ |
1 | 457 } else if (!strcasecmp(c, "NICK")) { |
458 c = strtok(NULL,":"); | |
459 g_snprintf(current_user->username, sizeof(current_user->username), "%s", c); | |
460 } else if (!strcasecmp(c, "IM_IN")) { | |
461 char *away, *message; | |
462 int a = 0; | |
463 | |
464 c = strtok(NULL,":"); | |
465 away = strtok(NULL,":"); | |
466 | |
467 message = away; | |
468 | |
469 while(*message && (*message != ':')) | |
470 message++; | |
471 | |
472 message++; | |
473 | |
474 if (!strncasecmp(away, "T", 1)) | |
475 a = 1; | |
476 serv_got_im(c, message, a); | |
477 | |
478 } else if (!strcasecmp(c, "GOTO_URL")) { | |
479 char *name; | |
480 char *url; | |
481 | |
482 char tmp[256]; | |
483 | |
484 name = strtok(NULL, ":"); | |
485 url = strtok(NULL, ":"); | |
486 | |
487 | |
488 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url); | |
489 /* fprintf(stdout, "Name: %s\n%s\n", name, url); | |
490 printf("%s", grab_url(tmp));*/ | |
491 g_show_info(tmp); | |
492 } else if (!strcasecmp(c, "EVILED")) { | |
493 int lev; | |
494 char *name = NULL; | |
495 | |
496 sscanf(strtok(NULL, ":"), "%d", &lev); | |
497 name = strtok(NULL, ":"); | |
498 | |
499 sprintf(debug_buff,"%s | %d\n", name, lev); | |
500 debug_print(debug_buff); | |
501 | |
502 serv_got_eviled(name, lev); | |
503 | |
504 } else if (!strcasecmp(c, "CHAT_JOIN")) { | |
505 char *name; | |
506 int id; | |
507 | |
508 | |
509 sscanf(strtok(NULL, ":"), "%d", &id); | |
510 name = strtok(NULL, ":"); | |
511 serv_got_joined_chat(id, name); | |
512 | |
513 } else if (!strcasecmp(c, "DIR_STATUS")) { | |
149 | 514 } else if (!strcasecmp(c, "ADMIN_PASSWD_STATUS")) { |
515 do_error_dialog("Password Change Successeful", "Gaim - Password Change"); | |
1 | 516 } else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) { |
517 int id; | |
518 char *in; | |
519 char *buddy; | |
520 GList *bcs = buddy_chats; | |
521 struct buddy_chat *b = NULL; | |
522 | |
523 sscanf(strtok(NULL, ":"), "%d", &id); | |
524 | |
525 in = strtok(NULL, ":"); | |
526 | |
527 while(bcs) { | |
528 b = (struct buddy_chat *)bcs->data; | |
529 if (id == b->id) | |
530 break; | |
531 bcs = bcs->next; | |
532 b = NULL; | |
533 } | |
534 | |
44 | 535 if (!b) { |
45 | 536 g_free(buf); |
1 | 537 return; |
44 | 538 } |
1 | 539 |
540 | |
541 if (!strcasecmp(in, "T")) { | |
542 while((buddy = strtok(NULL, ":")) != NULL) { | |
543 add_chat_buddy(b, buddy); | |
544 } | |
545 } else { | |
546 while((buddy = strtok(NULL, ":")) != NULL) { | |
547 remove_chat_buddy(b, buddy); | |
548 } | |
549 } | |
550 | |
551 } else if (!strcasecmp(c, "CHAT_LEFT")) { | |
552 int id; | |
553 | |
554 | |
555 sscanf(strtok(NULL, ":"), "%d", &id); | |
556 | |
557 serv_got_chat_left(id); | |
558 | |
559 | |
560 } else if (!strcasecmp(c, "CHAT_IN")) { | |
561 | |
562 int id, w; | |
563 char *m; | |
564 char *who, *whisper; | |
565 | |
566 | |
567 sscanf(strtok(NULL, ":"), "%d", &id); | |
568 who = strtok(NULL, ":"); | |
569 whisper = strtok(NULL, ":"); | |
570 m = whisper; | |
571 while(*m && (*m != ':')) m++; | |
572 m++; | |
573 | |
574 if (!strcasecmp(whisper, "T")) | |
575 w = 1; | |
576 else | |
577 w = 0; | |
578 | |
579 serv_got_chat_in(id, who, w, m); | |
580 | |
581 | |
582 } else if (!strcasecmp(c, "CHAT_INVITE")) { | |
583 char *name; | |
584 char *who; | |
585 char *message; | |
586 int id; | |
587 | |
588 | |
589 name = strtok(NULL, ":"); | |
590 sscanf(strtok(NULL, ":"), "%d", &id); | |
591 who = strtok(NULL, ":"); | |
592 message = strtok(NULL, ":"); | |
593 | |
594 serv_got_chat_invite(name, id, who, message); | |
595 | |
596 | |
597 } else if (!strcasecmp(c, "RVOUS_PROPOSE")) { | |
598 char *user; | |
599 char *uuid; | |
600 char *cookie; | |
601 int seq; | |
602 char *rip, *pip, *vip; | |
603 int port; | |
604 int unk[4]; | |
605 char *messages[4]; | |
606 int subtype, files, totalsize; | |
607 char *name; | |
608 char *tmp; | |
609 int i; | |
610 struct file_transfer *ft; | |
611 | |
612 | |
613 user = strtok(NULL, ":"); | |
614 uuid = strtok(NULL, ":"); | |
615 cookie = strtok(NULL, ":"); | |
616 sscanf(strtok(NULL, ":"), "%d", &seq); | |
617 rip = strtok(NULL, ":"); | |
618 pip = strtok(NULL, ":"); | |
619 vip = strtok(NULL, ":"); | |
620 sscanf(strtok(NULL, ":"), "%d", &port); | |
621 | |
197
24f0fef56a73
[gaim-migrate @ 207]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
196
diff
changeset
|
622 if (!strcmp(uuid, FILE_SEND_UID)) { |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
623 /* we're getting a file */ |
211
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
624 for (i=0; i<4; i++) { |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
625 sscanf(strtok(NULL, ":"), "%d", &unk[i]); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
626 if (unk[i] == 10001) |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
627 break; |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
628 messages[i] = frombase64(strtok(NULL, ":")); |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
629 } |
2042a38da38b
[gaim-migrate @ 221]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
630 tmp = frombase64(strtok(NULL, ":")); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
631 subtype = tmp[1]; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
632 files = tmp[3]; /* These are fine */ |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
633 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
634 totalsize = 0; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
635 totalsize |= (tmp[4] << 24) & 0xff000000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
636 totalsize |= (tmp[5] << 16) & 0x00ff0000; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
637 totalsize |= (tmp[6] << 8) & 0x0000ff00; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
638 totalsize |= (tmp[7] << 0) & 0x000000ff; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
639 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
640 name = tmp + 8; |
1 | 641 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
642 ft = g_new0(struct file_transfer, 1); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
643 |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
644 ft->cookie = g_strdup(cookie); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
645 ft->ip = g_strdup(pip); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
646 ft->port = port; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
647 if (i) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
648 ft->message = g_strdup(messages[0]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
649 else |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
650 ft->message = NULL; |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
651 ft->filename = g_strdup(name); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
652 ft->user = g_strdup(user); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
653 ft->size = totalsize; |
198
73e9a0bfff62
[gaim-migrate @ 208]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
197
diff
changeset
|
654 sprintf(ft->UID, "%s", FILE_SEND_UID); |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
655 |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
656 g_free(tmp); |
1 | 657 |
196
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
658 for (i--; i >= 0; i--) |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
659 g_free(messages[i]); |
3042e11c1902
[gaim-migrate @ 206]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
194
diff
changeset
|
660 |
217
fba779cc01f5
[gaim-migrate @ 227]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
216
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 | |
242
14fc16f579c8
[gaim-migrate @ 252]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
830 #endif /* USE_OSCAR */ |
1 | 831 |
832 void toc_build_config(char *s, int len) | |
833 { | |
834 GList *grp = groups; | |
835 GList *mem; | |
836 struct group *g; | |
837 struct buddy *b; | |
838 GList *plist = permit; | |
839 GList *dlist = deny; | |
840 | |
841 int pos=0; | |
842 | |
843 if (!permdeny) | |
844 permdeny = 1; | |
845 pos += g_snprintf(&s[pos], len - pos, "m %d\n", permdeny); | |
846 while(grp) { | |
847 g = (struct group *)grp->data; | |
848 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); | |
849 mem = g->members; | |
850 while(mem) { | |
851 b = (struct buddy *)mem->data; | |
852 pos += g_snprintf(&s[pos], len - pos, "b %s\n", b->name); | |
853 mem = mem->next; | |
854 } | |
855 grp = grp ->next; | |
856 } | |
857 while(plist) { | |
858 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
859 plist=plist->next; | |
860 | |
861 } | |
862 while(dlist) { | |
863 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
864 dlist=dlist->next; | |
865 } | |
866 } | |
867 | |
296
a88b889b692b
[gaim-migrate @ 306]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
285
diff
changeset
|
868 void parse_toc_buddy_list(char *config, int from_do_import) |
1 | 869 { |
870 char *c; | |
871 char current[256]; | |
872 char *name; | |
873 GList *bud; | |
228 | 874 int how_many = 0; |
875 | |
1 | 876 /* Clean out the permit/deny list!*/ |
877 g_list_free(permit); | |
878 g_list_free(deny); | |
879 permit = NULL; | |
880 deny = NULL; | |
881 bud = NULL; | |
882 | |
883 /* skip "CONFIG:" (if it exists)*/ | |
884 | |
332
b573f33c5e0e
[gaim-migrate @ 342]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
318
diff
changeset
|
885 if (config != NULL) { |
b573f33c5e0e
[gaim-migrate @ 342]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
318
diff
changeset
|
886 |
1 | 887 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))? |
888 strtok(config, "\n"): | |
889 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n"); | |
890 do { | |
891 if (c == NULL) | |
892 break; | |
893 if (*c == 'g') { | |
894 strncpy(current,c+2, sizeof(current)); | |
895 add_group(current); | |
228 | 896 how_many++; |
1 | 897 } else if (*c == 'b') { |
898 add_buddy(current, c+2); | |
228 | 899 how_many++; |
1 | 900 bud = g_list_append(bud, c+2); |
901 } else if (*c == 'p') { | |
902 name = g_malloc(strlen(c+2) + 2); | |
903 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
904 permit = g_list_append(permit, name); | |
905 } else if (*c == 'd') { | |
906 name = g_malloc(strlen(c+2) + 2); | |
907 g_snprintf(name, strlen(c+2) + 1, "%s", c+2); | |
908 deny = g_list_append(deny, name); | |
909 } else if (*c == 'm') { | |
910 sscanf(c + strlen(c) - 1, "%d", &permdeny); | |
911 if (permdeny == 0) | |
912 permdeny = 1; | |
913 } | |
914 }while((c=strtok(NULL,"\n"))); | |
915 #if 0 | |
916 fprintf(stdout, "Sending message '%s'\n",buf); | |
917 #endif | |
228 | 918 |
1 | 919 serv_add_buddies(bud); |
920 serv_set_permit_deny(); | |
333
af60432518a6
[gaim-migrate @ 343]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
332
diff
changeset
|
921 if (blist) { |
af60432518a6
[gaim-migrate @ 343]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
332
diff
changeset
|
922 build_edit_tree(); |
af60432518a6
[gaim-migrate @ 343]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
332
diff
changeset
|
923 build_permit_tree(); |
af60432518a6
[gaim-migrate @ 343]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
332
diff
changeset
|
924 } |
228 | 925 |
332
b573f33c5e0e
[gaim-migrate @ 342]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
318
diff
changeset
|
926 } |
b573f33c5e0e
[gaim-migrate @ 342]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
318
diff
changeset
|
927 |
228 | 928 /* perhaps the server dropped the buddy list, try importing from |
929 cache */ | |
930 | |
296
a88b889b692b
[gaim-migrate @ 306]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
285
diff
changeset
|
931 if ( how_many == 0 && !from_do_import ) { |
228 | 932 do_import( (GtkWidget *) NULL, 0 ); |
229 | 933 } else if ( bud_list_cache_exists() == FALSE ) { |
934 do_export( (GtkWidget *) NULL, 0 ); | |
228 | 935 } |
1 | 936 } |