comparison src/protocols/toc/toc.c @ 6484:5ced8e111473

[gaim-migrate @ 6998] Zephyr and toc were still using debug_printf(), but I taught them a thing or two. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 17 Aug 2003 17:55:46 +0000
parents 8f94cce8faa5
children 8af14f114730
comparison
equal deleted inserted replaced
6483:565339a6eb86 6484:5ced8e111473
174 174
175 g_snprintf(buf, sizeof buf, _("Looking up %s"), 175 g_snprintf(buf, sizeof buf, _("Looking up %s"),
176 gaim_account_get_string(account, "server", TOC_HOST)); 176 gaim_account_get_string(account, "server", TOC_HOST));
177 gaim_connection_update_progress(gc, buf, 1, TOC_CONNECT_STEPS); 177 gaim_connection_update_progress(gc, buf, 1, TOC_CONNECT_STEPS);
178 178
179 debug_printf("* Client connects to TOC\n"); 179 gaim_debug(GAIM_DEBUG_INFO, "toc", "Client connects to TOC\n");
180 if (gaim_proxy_connect(account, 180 if (gaim_proxy_connect(account,
181 gaim_account_get_string(account, "server", TOC_HOST), 181 gaim_account_get_string(account, "server", TOC_HOST),
182 gaim_account_get_int(account, "port", TOC_PORT), 182 gaim_account_get_int(account, "port", TOC_PORT),
183 toc_login_callback, gc) != 0 || !account->gc) { 183 toc_login_callback, gc) != 0 || !account->gc) {
184 g_snprintf(buf, sizeof(buf), _("Connect to %s failed"), 184 g_snprintf(buf, sizeof(buf), _("Connect to %s failed"),
218 if (getpeername(tdt->toc_fd, (struct sockaddr *)&name, &namelen) == 0) 218 if (getpeername(tdt->toc_fd, (struct sockaddr *)&name, &namelen) == 0)
219 strncpy(tdt->toc_ip, inet_ntoa(name.sin_addr), sizeof(tdt->toc_ip)); 219 strncpy(tdt->toc_ip, inet_ntoa(name.sin_addr), sizeof(tdt->toc_ip));
220 else 220 else
221 strncpy(tdt->toc_ip, gaim_account_get_string(gc->account, "server", TOC_HOST), sizeof(tdt->toc_ip)); 221 strncpy(tdt->toc_ip, gaim_account_get_string(gc->account, "server", TOC_HOST), sizeof(tdt->toc_ip));
222 222
223 debug_printf("* Client sends \"FLAPON\\r\\n\\r\\n\"\n"); 223 gaim_debug(GAIM_DEBUG_INFO, "toc",
224 "Client sends \"FLAPON\\r\\n\\r\\n\"\n");
224 if (toc_write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) { 225 if (toc_write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) {
225 gaim_connection_error(gc, _("Disconnected.")); 226 gaim_connection_error(gc, _("Disconnected."));
226 return; 227 return;
227 } 228 }
228 tdt->state = STATE_FLAPON; 229 tdt->state = STATE_FLAPON;
409 * get hit though, hopefully. If it gets hit on an IM 410 * get hit though, hopefully. If it gets hit on an IM
410 * It'll lose the last " and the message won't go through, 411 * It'll lose the last " and the message won't go through,
411 * but this'll stop a segfault. 412 * but this'll stop a segfault.
412 */ 413 */
413 if (len > MSG_LEN) { 414 if (len > MSG_LEN) {
414 debug_printf("message too long, truncating\n"); 415 gaim_debug(GAIM_DEBUG_WARNING, "toc", "message too long, truncating\n");
415 escaped[MSG_LEN - 1] = '\0'; 416 escaped[MSG_LEN - 1] = '\0';
416 len = MSG_LEN; 417 len = MSG_LEN;
417 } 418 }
418 419
419 if (olen < 0) 420 if (olen < 0)
420 debug_printf("TOC C: %s\n", escaped); 421 gaim_debug(GAIM_DEBUG_INFO, "toc", "C: %s\n", escaped);
421 422
422 hdr.ast = '*'; 423 hdr.ast = '*';
423 hdr.type = type; 424 hdr.type = type;
424 hdr.seqno = htons(tdt->seqno++ & 0xffff); 425 hdr.seqno = htons(tdt->seqno++ & 0xffff);
425 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); 426 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1));
448 struct toc_data *tdt = (struct toc_data *)gc->proto_data; 449 struct toc_data *tdt = (struct toc_data *)gc->proto_data;
449 struct sflap_hdr *hdr; 450 struct sflap_hdr *hdr;
450 int ret; 451 int ret;
451 452
452 if (toc_read(tdt->toc_fd, buffer, sizeof(struct sflap_hdr)) < 0) { 453 if (toc_read(tdt->toc_fd, buffer, sizeof(struct sflap_hdr)) < 0) {
453 debug_printf("error, couldn't read flap header\n"); 454 gaim_debug(GAIM_DEBUG_ERROR, "toc", "Couldn't read flap header\n");
454 return -1; 455 return -1;
455 } 456 }
456 457
457 hdr = (struct sflap_hdr *)buffer; 458 hdr = (struct sflap_hdr *)buffer;
458 459
459 if (buflen < ntohs(hdr->len)) { 460 if (buflen < ntohs(hdr->len)) {
460 /* fake like there's a read error */ 461 /* fake like there's a read error */
461 debug_printf("buffer too small (have %d, need %d)\n", buflen, ntohs(hdr->len)); 462 gaim_debug(GAIM_DEBUG_ERROR, "toc",
463 "buffer too small (have %d, need %d)\n",
464 buflen, ntohs(hdr->len));
462 return -1; 465 return -1;
463 } 466 }
464 467
465 if (ntohs(hdr->len) > 0) { 468 if (ntohs(hdr->len) > 0) {
466 int count = 0; 469 int count = 0;
606 } 609 }
607 610
608 if (tdt->state == STATE_FLAPON) { 611 if (tdt->state == STATE_FLAPON) {
609 hdr = (struct sflap_hdr *)buf; 612 hdr = (struct sflap_hdr *)buf;
610 if (hdr->type != TYPE_SIGNON) 613 if (hdr->type != TYPE_SIGNON)
611 debug_printf("problem, hdr->type != TYPE_SIGNON\n"); 614 gaim_debug(GAIM_DEBUG_ERROR, "toc", "hdr->type != TYPE_SIGNON\n");
612 else 615 else
613 debug_printf("* TOC sends Client FLAP SIGNON\n"); 616 gaim_debug(GAIM_DEBUG_INFO, "toc",
617 "TOC sends Client FLAP SIGNON\n");
614 tdt->seqno = ntohs(hdr->seqno); 618 tdt->seqno = ntohs(hdr->seqno);
615 tdt->state = STATE_SIGNON_REQUEST; 619 tdt->state = STATE_SIGNON_REQUEST;
616 620
617 debug_printf("* Client sends TOC FLAP SIGNON\n"); 621 gaim_debug(GAIM_DEBUG_INFO, "toc", "Client sends TOC FLAP SIGNON\n");
618 g_snprintf(so.username, sizeof(so.username), "%s", username); 622 g_snprintf(so.username, sizeof(so.username), "%s", username);
619 so.ver = htonl(1); 623 so.ver = htonl(1);
620 so.tag = htons(1); 624 so.tag = htons(1);
621 so.namelen = htons(strlen(so.username)); 625 so.namelen = htons(strlen(so.username));
622 if (sflap_send(gc, (char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON) < 0) { 626 if (sflap_send(gc, (char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON) < 0) {
623 gaim_connection_error(gc, _("Disconnected.")); 627 gaim_connection_error(gc, _("Disconnected."));
624 return; 628 return;
625 } 629 }
626 630
627 debug_printf("* Client sends TOC \"toc_signon\" message\n"); 631 gaim_debug(GAIM_DEBUG_INFO, "toc",
632 "Client sends TOC \"toc_signon\" message\n");
628 /* i hate icq. */ 633 /* i hate icq. */
629 if (username[0] >= '0' && username[0] <= '9') 634 if (username[0] >= '0' && username[0] <= '9')
630 password = g_strndup(gaim_account_get_password(gc->account), 8); 635 password = g_strndup(gaim_account_get_password(gc->account), 8);
631 else 636 else
632 password = g_strdup(gaim_account_get_password(gc->account)); 637 password = g_strdup(gaim_account_get_password(gc->account));
642 gaim_connection_update_progress(gc, _("Waiting for reply..."), 3, TOC_CONNECT_STEPS); 647 gaim_connection_update_progress(gc, _("Waiting for reply..."), 3, TOC_CONNECT_STEPS);
643 return; 648 return;
644 } 649 }
645 650
646 if (tdt->state == STATE_SIGNON_REQUEST) { 651 if (tdt->state == STATE_SIGNON_REQUEST) {
647 debug_printf("* TOC sends client SIGN_ON reply\n"); 652 gaim_debug(GAIM_DEBUG_INFO, "toc", "TOC sends client SIGN_ON reply\n");
648 if (g_ascii_strncasecmp(buf + sizeof(struct sflap_hdr), "SIGN_ON", strlen("SIGN_ON"))) { 653 if (g_ascii_strncasecmp(buf + sizeof(struct sflap_hdr), "SIGN_ON", strlen("SIGN_ON"))) {
649 debug_printf("Didn't get SIGN_ON! buf was: %s\n", 654 gaim_debug(GAIM_DEBUG_ERROR, "toc",
655 "Didn't get SIGN_ON! buf was: %s\n",
650 buf + sizeof(struct sflap_hdr)); 656 buf + sizeof(struct sflap_hdr));
651 if (!g_ascii_strncasecmp(buf + sizeof(struct sflap_hdr), "ERROR", 5)) { 657 if (!g_ascii_strncasecmp(buf + sizeof(struct sflap_hdr), "ERROR", 5)) {
652 strtok(buf + sizeof(struct sflap_hdr), ":"); 658 strtok(buf + sizeof(struct sflap_hdr), ":");
653 gaim_connection_error(gc, show_error_message()); 659 gaim_connection_error(gc, show_error_message());
654 } else 660 } else
655 gaim_connection_error(gc, _("Authentication Failed")); 661 gaim_connection_error(gc, _("Authentication Failed"));
656 return; 662 return;
657 } 663 }
658 /* we're supposed to check that it's really TOC v1 here but we know it is ;) */ 664 /* we're supposed to check that it's really TOC v1 here but we know it is ;) */
659 debug_printf("TOC version: %s\n", buf + sizeof(struct sflap_hdr) + 8); 665 gaim_debug(GAIM_DEBUG_INFO, "toc",
666 "TOC version: %s\n", buf + sizeof(struct sflap_hdr) + 8);
660 667
661 /* we used to check for the CONFIG here, but we'll wait until we've sent our 668 /* we used to check for the CONFIG here, but we'll wait until we've sent our
662 * version of the config and then the toc_init_done message. we'll come back to 669 * version of the config and then the toc_init_done message. we'll come back to
663 * the callback in a better state if we get CONFIG anyway */ 670 * the callback in a better state if we get CONFIG anyway */
664 671
666 673
667 gaim_connection_set_state(gc, GAIM_CONNECTED); 674 gaim_connection_set_state(gc, GAIM_CONNECTED);
668 serv_finish_login(gc); 675 serv_finish_login(gc);
669 676
670 /* Client sends TOC toc_init_done message */ 677 /* Client sends TOC toc_init_done message */
671 debug_printf("* Client sends TOC toc_init_done message\n"); 678 gaim_debug(GAIM_DEBUG_INFO, "toc",
679 "Client sends TOC toc_init_done message\n");
672 g_snprintf(snd, sizeof snd, "toc_init_done"); 680 g_snprintf(snd, sizeof snd, "toc_init_done");
673 sflap_send(gc, snd, -1, TYPE_DATA); 681 sflap_send(gc, snd, -1, TYPE_DATA);
674 682
675 /* 683 /*
676 g_snprintf(snd, sizeof snd, "toc_set_caps %s %s %s", 684 g_snprintf(snd, sizeof snd, "toc_set_caps %s %s %s",
680 sflap_send(gc, snd, -1, TYPE_DATA); 688 sflap_send(gc, snd, -1, TYPE_DATA);
681 689
682 return; 690 return;
683 } 691 }
684 692
685 debug_printf("TOC S: %s\n", buf + sizeof(struct sflap_hdr)); 693 gaim_debug(GAIM_DEBUG_INFO, "toc", "S: %s\n",
694 buf + sizeof(struct sflap_hdr));
686 695
687 c = strtok(buf + sizeof(struct sflap_hdr), ":"); /* Ditch the first part */ 696 c = strtok(buf + sizeof(struct sflap_hdr), ":"); /* Ditch the first part */
688 697
689 if (!g_ascii_strcasecmp(c, "SIGN_ON")) { 698 if (!g_ascii_strcasecmp(c, "SIGN_ON")) {
690 /* we should only get here after a PAUSE */ 699 /* we should only get here after a PAUSE */
691 if (tdt->state != STATE_PAUSE) 700 if (tdt->state != STATE_PAUSE)
692 debug_printf("got SIGN_ON but not PAUSE!\n"); 701 gaim_debug(GAIM_DEBUG_ERROR, "toc",
702 "got SIGN_ON but not PAUSE!\n");
693 else { 703 else {
694 tdt->state = STATE_ONLINE; 704 tdt->state = STATE_ONLINE;
695 g_snprintf(snd, sizeof snd, "toc_signon %s %d %s %s %s \"%s\"", 705 g_snprintf(snd, sizeof snd, "toc_signon %s %d %s %s %s \"%s\"",
696 AUTH_HOST, AUTH_PORT, 706 AUTH_HOST, AUTH_PORT,
697 normalize(gaim_account_get_username(gc->account)), 707 normalize(gaim_account_get_username(gc->account)),
971 981
972 g_free(tmp); 982 g_free(tmp);
973 for (i--; i >= 0; i--) 983 for (i--; i >= 0; i--)
974 g_free(messages[i]); 984 g_free(messages[i]);
975 985
976 debug_printf("English translation of RVOUS_PROPOSE: %s requests Send File (i.e." 986 gaim_debug(GAIM_DEBUG_MISC, "toc",
977 " send a file to you); %s:%d (verified_ip:port), %d files at" 987 "English translation of RVOUS_PROPOSE: %s requests "
978 " total size of %d bytes.\n", user, vip, port, files, totalsize); 988 "Send File (i.e. send a file to you); %s:%d "
989 "(verified_ip:port), %d files at total size of "
990 "%d bytes.\n", user, vip, port, files, totalsize);
979 accept_file_dialog(ft); 991 accept_file_dialog(ft);
980 } else if (!strcmp(uuid, FILE_GET_UID)) { 992 } else if (!strcmp(uuid, FILE_GET_UID)) {
981 /* they want us to send a file */ 993 /* they want us to send a file */
982 int unk[4], i; 994 int unk[4], i;
983 char *messages[4], *tmp; 995 char *messages[4], *tmp;
1025 break; 1037 break;
1026 frombase64(strtok(NULL, ":"), &messages[i], NULL); 1038 frombase64(strtok(NULL, ":"), &messages[i], NULL);
1027 } 1039 }
1028 frombase64(strtok(NULL, ":"), (char **)&icon, NULL); 1040 frombase64(strtok(NULL, ":"), (char **)&icon, NULL);
1029 1041
1030 debug_printf("received icon of length %d\n", icon->len); 1042 gaim_debug(GAIM_DEBUG_MISC, "toc",
1043 "received icon of length %d\n", icon->len);
1031 g_free(icon); 1044 g_free(icon);
1032 for (i--; i >= 0; i--) 1045 for (i--; i >= 0; i--)
1033 g_free(messages[i]); 1046 g_free(messages[i]);
1034 */ 1047 */
1035 } else if (!strcmp(uuid, IMAGE_UID)) { 1048 } else if (!strcmp(uuid, IMAGE_UID)) {
1036 /* aka Direct IM */ 1049 /* aka Direct IM */
1037 } else { 1050 } else {
1038 debug_printf("Don't know what to do with RVOUS UUID %s\n", uuid); 1051 gaim_debug(GAIM_DEBUG_ERROR, "toc",
1052 "Don't know what to do with RVOUS UUID %s\n", uuid);
1039 /* do we have to do anything here? i think it just times out */ 1053 /* do we have to do anything here? i think it just times out */
1040 } 1054 }
1041 } else { 1055 } else {
1042 debug_printf("don't know what to do with %s\n", c); 1056 gaim_debug(GAIM_DEBUG_ERROR, "toc",
1057 "don't know what to do with %s\n", c);
1043 } 1058 }
1044 } 1059 }
1045 1060
1046 static int toc_send_im(GaimConnection *gc, const char *name, const char *message, int len, int flags) 1061 static int toc_send_im(GaimConnection *gc, const char *name, const char *message, int len, int flags)
1047 { 1062 {
1101 const char *maiden, const char *city, const char *state, const char *country, const char *email) 1116 const char *maiden, const char *city, const char *state, const char *country, const char *email)
1102 { 1117 {
1103 char buf[BUF_LONG]; 1118 char buf[BUF_LONG];
1104 g_snprintf(buf, sizeof(buf) / 2, "toc_dir_search %s:%s:%s:%s:%s:%s:%s:%s", first, middle, 1119 g_snprintf(buf, sizeof(buf) / 2, "toc_dir_search %s:%s:%s:%s:%s:%s:%s:%s", first, middle,
1105 last, maiden, city, state, country, email); 1120 last, maiden, city, state, country, email);
1106 debug_printf("Searching for: %s,%s,%s,%s,%s,%s,%s\n", first, middle, last, maiden, 1121 gaim_debug(GAIM_DEBUG_INFO, "toc",
1122 "Searching for: %s,%s,%s,%s,%s,%s,%s\n",
1123 first, middle, last, maiden,
1107 city, state, country); 1124 city, state, country);
1108 sflap_send(g, buf, -1, TYPE_DATA); 1125 sflap_send(g, buf, -1, TYPE_DATA);
1109 } 1126 }
1110 1127
1111 static void toc_set_away(GaimConnection *g, const char *state, const char *message) 1128 static void toc_set_away(GaimConnection *g, const char *state, const char *message)
1552 gint inpa; 1569 gint inpa;
1553 }; 1570 };
1554 1571
1555 static void debug_header(struct file_transfer *ft) { 1572 static void debug_header(struct file_transfer *ft) {
1556 struct file_header *f = (struct file_header *)ft; 1573 struct file_header *f = (struct file_header *)ft;
1557 debug_printf("TOC FT HEADER:\n" 1574 gaim_debug(GAIM_DEBUG_MISC, "toc", "FT HEADER:\n"
1558 "\t%s %d 0x%04x\n" 1575 "\t%s %d 0x%04x\n"
1559 "\t%s %d %d\n" 1576 "\t%s %d %d\n"
1560 "\t%d %d %d %d %d %d\n" 1577 "\t%d %d %d %d %d %d\n"
1561 "\t%d %d %d %d %d %d %d %d\n" 1578 "\t%d %d %d %d %d %d %d %d\n"
1562 "\t%s\n" 1579 "\t%s\n"