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