Changeset 5ebff60 for protocols/yahoo/libyahoo2.c
- Timestamp:
- 2015-02-20T22:50:54Z (10 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/yahoo/libyahoo2.c
raf359b4 r5ebff60 3 3 * 4 4 * Some code copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net> 5 * YMSG16 code copyright (C) 2009, 6 * 5 * YMSG16 code copyright (C) 2009, 6 * Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com> 7 7 * 8 8 * Yahoo Search copyright (C) 2003, Konstantin Klyagin <konst AT konst.org.ua> 9 9 * 10 10 * Much of this code was taken and adapted from the yahoo module for 11 * gaim released under the GNU GPL. This code is also released under the 11 * gaim released under the GNU GPL. This code is also released under the 12 12 * GNU GPL. 13 13 * … … 30 30 * 31 31 * YMSG16 authentication code based mostly on write-up at: 32 * 32 * http://www.carbonize.co.uk/ymsg16.html 33 33 * 34 34 * This program is free software; you can redistribute it and/or modify … … 60 60 # define strrchr rindex 61 61 # endif 62 char *strchr (), *strrchr();62 char *strchr(), *strrchr(); 63 63 # if !HAVE_MEMCPY 64 # define memcpy(d, s, n) bcopy 65 # define memmove(d, s, n) bcopy 64 # define memcpy(d, s, n) bcopy((s), (d), (n)) 65 # define memmove(d, s, n) bcopy((s), (d), (n)) 66 66 # endif 67 67 #endif … … 100 100 } 101 101 102 #define YAHOO_CALLBACK(x) 102 #define YAHOO_CALLBACK(x) yc->x 103 103 #else 104 #define YAHOO_CALLBACK(x) 104 #define YAHOO_CALLBACK(x) x 105 105 #endif 106 106 … … 113 113 char out[1024]; 114 114 va_list ap; 115 115 116 va_start(ap, fmt); 116 117 vsnprintf(out, sizeof(out), fmt, ap); 117 118 va_end(ap); 118 return YAHOO_CALLBACK (ext_yahoo_log) ("%s", out);119 return YAHOO_CALLBACK (ext_yahoo_log) ("%s", out); 119 120 } 120 121 … … 129 130 { 130 131 enum yahoo_log_level l = log_level; 132 131 133 log_level = level; 132 134 return l; … … 134 136 135 137 /* default values for servers */ 136 static char *default_pager_hosts[] = { 137 138 139 140 NULL};138 static char *default_pager_hosts[] = { "scs.msg.yahoo.com", 139 "scsa.msg.yahoo.com", 140 "scsb.msg.yahoo.com", 141 "scsc.msg.yahoo.com", 142 NULL }; 141 143 142 144 static int pager_port = 5050; … … 222 224 223 225 static void yahoo_process_filetransfer(struct yahoo_input_data *yid, 224 226 struct yahoo_packet *pkt); 225 227 static void yahoo_process_filetransferinfo(struct yahoo_input_data *yid, 226 228 struct yahoo_packet *pkt); 227 229 static void yahoo_process_filetransferaccept(struct yahoo_input_data *yid, 228 230 struct yahoo_packet *pkt); 229 231 230 232 static void yahoo_https_auth(struct yahoo_input_data *yid, const char *seed, const char *sn); … … 233 235 { 234 236 struct yahoo_server_settings *yss = 235 237 y_new0(struct yahoo_server_settings, 1); 236 238 237 239 /* Give preference to the default host list 238 * Make sure that only one of the two is set at any time 240 * Make sure that only one of the two is set at any time 239 241 */ 240 242 yss->pager_host = NULL; … … 263 265 while (1) { 264 266 key = va_arg(ap, char *); 265 if (key == NULL) 266 break; 267 if (key == NULL) { 268 break; 269 } 267 270 268 271 if (!strcmp(key, "pager_host")) { … … 306 309 } else { 307 310 WARNING(("Unknown key passed to yahoo_init, " 308 309 311 "perhaps you didn't terminate the list " 312 "with NULL")); 310 313 } 311 314 } … … 316 319 static void yahoo_free_server_settings(struct yahoo_server_settings *yss) 317 320 { 318 if (!yss) 319 return; 321 if (!yss) { 322 return; 323 } 320 324 321 325 free(yss->pager_host); … … 340 344 { 341 345 YList *l; 346 342 347 for (l = conns; l; l = y_list_next(l)) { 343 348 struct yahoo_data *yd = l->data; 344 if (yd->client_id == id) 349 if (yd->client_id == id) { 345 350 return yd; 351 } 346 352 } 347 353 return NULL; … … 357 363 static struct yahoo_input_data * find_input_by_id(int id) 358 364 { 359 360 361 362 363 364 365 365 YList *l; 366 for(l = inputs; l; l = y_list_next(l)) { 367 struct yahoo_input_data *yid = l->data; 368 if(yid->yd->client_id == id) 369 return yid; 370 } 371 return NULL; 366 372 } 367 373 */ … … 369 375 #if 0 370 376 static struct yahoo_input_data *find_input_by_id_and_webcam_user(int id, 371 377 const char *who) 372 378 { 373 379 YList *l; 380 374 381 LOG(("find_input_by_id_and_webcam_user")); 375 382 for (l = inputs; l; l = y_list_next(l)) { 376 383 struct yahoo_input_data *yid = l->data; 377 384 if (yid->type == YAHOO_CONNECTION_WEBCAM 378 379 380 381 || !(yid->wcm->user && !who)))385 && yid->yd->client_id == id && yid->wcm && ((who 386 && yid->wcm->user 387 && !strcmp(who, yid->wcm->user)) 388 || !(yid->wcm->user && !who))) { 382 389 return yid; 390 } 383 391 } 384 392 return NULL; … … 387 395 388 396 static struct yahoo_input_data *find_input_by_id_and_type(int id, 389 397 enum yahoo_connection_type type) 390 398 { 391 399 YList *l; 400 392 401 LOG(("find_input_by_id_and_type")); 393 402 for (l = inputs; l; l = y_list_next(l)) { 394 403 struct yahoo_input_data *yid = l->data; 395 if (yid->type == type && yid->yd->client_id == id) 404 if (yid->type == type && yid->yd->client_id == id) { 396 405 return yid; 406 } 397 407 } 398 408 return NULL; … … 402 412 { 403 413 YList *l; 414 404 415 LOG(("find_input_by_id_and_fd")); 405 416 for (l = inputs; l; l = y_list_next(l)) { 406 417 struct yahoo_input_data *yid = l->data; 407 if (yid->fd == fd && yid->yd->client_id == id) 418 if (yid->fd == fd && yid->yd->client_id == id) { 408 419 return yid; 420 } 409 421 } 410 422 return NULL; … … 415 427 int c = 0; 416 428 YList *l; 429 417 430 LOG(("counting %d", id)); 418 431 for (l = inputs; l; l = y_list_next(l)) { 419 432 struct yahoo_input_data *yid = l->data; 420 if (yid->yd->client_id == id) 433 if (yid->yd->client_id == id) { 421 434 c++; 435 } 422 436 } 423 437 LOG(("%d", c)); … … 432 446 for (l = list; l; l = l->next) { 433 447 struct yahoo_buddy *bud = l->data; 434 if (!bud) 448 if (!bud) { 435 449 continue; 450 } 436 451 437 452 FREE(bud->group); … … 503 518 504 519 static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, 505 520 enum ypacket_status status, int id) 506 521 { 507 522 struct yahoo_packet *pkt = y_new0(struct yahoo_packet, 1); … … 515 530 516 531 static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, 517 532 const char *value) 518 533 { 519 534 struct yahoo_pair *pair = y_new0(struct yahoo_pair, 1); 535 520 536 pair->key = key; 521 537 pair->value = strdup(value); … … 545 561 546 562 #define yahoo_put16(buf, data) ( \ 547 (*(buf) = (unsigned char)((data)>>8)&0xff), \548 (*((buf)+1) = (unsigned char)(data)&0xff), \549 550 #define yahoo_get16(buf) ((((*(buf)) &0xff)<<8) + ((*((buf)+1)) & 0xff))563 (*(buf) = (unsigned char) ((data) >> 8) & 0xff), \ 564 (*((buf) + 1) = (unsigned char) (data) & 0xff), \ 565 2) 566 #define yahoo_get16(buf) ((((*(buf)) & 0xff) << 8) + ((*((buf) + 1)) & 0xff)) 551 567 #define yahoo_put32(buf, data) ( \ 552 (*((buf)) = (unsigned char)((data)>>24)&0xff), \553 (*((buf)+1) = (unsigned char)((data)>>16)&0xff), \554 (*((buf)+2) = (unsigned char)((data)>>8)&0xff), \555 (*((buf)+3) = (unsigned char)(data)&0xff), \556 557 #define yahoo_get32(buf) ((((*(buf) )&0xff)<<24) + \558 (((*((buf)+1))&0xff)<<16) + \559 (((*((buf)+2))&0xff)<< 8) + \560 (((*((buf)+3))&0xff)))568 (*((buf)) = (unsigned char) ((data) >> 24) & 0xff), \ 569 (*((buf) + 1) = (unsigned char) ((data) >> 16) & 0xff), \ 570 (*((buf) + 2) = (unsigned char) ((data) >> 8) & 0xff), \ 571 (*((buf) + 3) = (unsigned char) (data) & 0xff), \ 572 4) 573 #define yahoo_get32(buf) ((((*(buf)) & 0xff) << 24) + \ 574 (((*((buf) + 1)) & 0xff) << 16) + \ 575 (((*((buf) + 2)) & 0xff) << 8) + \ 576 (((*((buf) + 3)) & 0xff))) 561 577 562 578 static void yahoo_packet_read(struct yahoo_packet *pkt, unsigned char *data, 563 579 int len) 564 580 { 565 581 int pos = 0; … … 575 591 x = 0; 576 592 while (pos + 1 < len) { 577 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) 593 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) { 578 594 break; 595 } 579 596 key[x++] = data[pos++]; 580 597 } … … 583 600 pair->key = strtol(key, NULL, 10); 584 601 free(key); 585 602 586 603 /* Libyahoo2 developer(s) don't seem to have the time to fix 587 604 this problem, so for now try to work around it: 588 605 589 606 Sometimes we receive an invalid packet with not any more 590 607 data at this point. I don't know how to handle this in a 591 608 clean way, but let's hope this is clean enough: */ 592 609 593 610 if (pos + 1 < len) { 594 accept = x; 611 accept = x; 595 612 /* if x is 0 there was no key, so don't accept it */ 596 if (accept) 613 if (accept) { 597 614 value = malloc(len - pos + 1); 615 } 598 616 x = 0; 599 617 while (pos + 1 < len) { 600 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) 618 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) { 601 619 break; 602 if (accept) 620 } 621 if (accept) { 603 622 value[x++] = data[pos++]; 623 } 604 624 } 605 if (accept) 625 if (accept) { 606 626 value[x] = 0; 627 } 607 628 pos += 2; 608 629 } else { 609 630 accept = 0; 610 631 } 611 632 612 633 if (accept) { 613 634 pair->value = strdup(value); … … 615 636 pkt->hash = y_list_append(pkt->hash, pair); 616 637 DEBUG_MSG(("Key: %d \tValue: %s", pair->key, 617 638 pair->value)); 618 639 } else { 619 640 FREE(pair); … … 631 652 unsigned char buf[100]; 632 653 633 snprintf((char *) buf, sizeof(buf), "%d", pair->key);634 strcpy((char *) data + pos, (char *)buf);635 pos += strlen((char *) buf);654 snprintf((char *) buf, sizeof(buf), "%d", pair->key); 655 strcpy((char *) data + pos, (char *) buf); 656 pos += strlen((char *) buf); 636 657 data[pos++] = 0xc0; 637 658 data[pos++] = 0x80; 638 659 639 strcpy((char *) data + pos, pair->value);660 strcpy((char *) data + pos, pair->value); 640 661 pos += strlen(pair->value); 641 662 data[pos++] = 0xc0; … … 660 681 int i; 661 682 for (i = 0; i < len; i++) { 662 if ((i % 8 == 0) && i) 663 YAHOO_CALLBACK(ext_yahoo_log) (" "); 664 if ((i % 16 == 0) && i) 665 YAHOO_CALLBACK(ext_yahoo_log) ("\n"); 666 YAHOO_CALLBACK(ext_yahoo_log) ("%02x ", data[i]); 667 } 668 YAHOO_CALLBACK(ext_yahoo_log) ("\n"); 683 if ((i % 8 == 0) && i) { 684 YAHOO_CALLBACK (ext_yahoo_log) (" "); 685 } 686 if ((i % 16 == 0) && i) { 687 YAHOO_CALLBACK (ext_yahoo_log) ("\n"); 688 } 689 YAHOO_CALLBACK (ext_yahoo_log) ("%02x ", data[i]); 690 } 691 YAHOO_CALLBACK (ext_yahoo_log) ("\n"); 669 692 for (i = 0; i < len; i++) { 670 if ((i % 8 == 0) && i) 671 YAHOO_CALLBACK(ext_yahoo_log) (" "); 672 if ((i % 16 == 0) && i) 673 YAHOO_CALLBACK(ext_yahoo_log) ("\n"); 674 if (isprint(data[i])) 675 YAHOO_CALLBACK(ext_yahoo_log) (" %c ", data[i]); 676 else 677 YAHOO_CALLBACK(ext_yahoo_log) (" . "); 678 } 679 YAHOO_CALLBACK(ext_yahoo_log) ("\n"); 693 if ((i % 8 == 0) && i) { 694 YAHOO_CALLBACK (ext_yahoo_log) (" "); 695 } 696 if ((i % 16 == 0) && i) { 697 YAHOO_CALLBACK (ext_yahoo_log) ("\n"); 698 } 699 if (isprint(data[i])) { 700 YAHOO_CALLBACK (ext_yahoo_log) (" %c ", data[i]); 701 } else { 702 YAHOO_CALLBACK (ext_yahoo_log) (" . "); 703 } 704 } 705 YAHOO_CALLBACK (ext_yahoo_log) ("\n"); 680 706 } 681 707 } … … 703 729 704 730 static void yahoo_add_to_send_queue(struct yahoo_input_data *yid, void *data, 705 731 int length) 706 732 { 707 733 struct data_queue *tx = y_new0(struct data_queue, 1); 734 708 735 tx->queue = y_new0(unsigned char, length); 709 736 tx->len = length; … … 712 739 yid->txqueues = y_list_append(yid->txqueues, tx); 713 740 714 if (!yid->write_tag) 741 if (!yid->write_tag) { 715 742 yid->write_tag = 716 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd-> 717 client_id, yid->fd, YAHOO_INPUT_WRITE, yid); 743 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd-> 744 client_id, yid->fd, YAHOO_INPUT_WRITE, yid); 745 } 718 746 } 719 747 720 748 static void yahoo_send_packet(struct yahoo_input_data *yid, 721 749 struct yahoo_packet *pkt, int extra_pad) 722 750 { 723 751 int pktlen = yahoo_packet_length(pkt); … … 726 754 int pos = 0; 727 755 728 if (yid->fd < 0) 729 return; 756 if (yid->fd < 0) { 757 return; 758 } 730 759 731 760 data = y_new0(unsigned char, len + 1); … … 733 762 memcpy(data + pos, "YMSG", 4); 734 763 pos += 4; 735 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); 736 pos += yahoo_put16(data + pos, 0x0000); 737 pos += yahoo_put16(data + pos, pktlen + extra_pad); 738 pos += yahoo_put16(data + pos, pkt->service); 739 pos += yahoo_put32(data + pos, pkt->status); 740 pos += yahoo_put32(data + pos, pkt->id); 764 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); /* version [latest 12 0x000c] */ 765 pos += yahoo_put16(data + pos, 0x0000); /* HIWORD pkt length??? */ 766 pos += yahoo_put16(data + pos, pktlen + extra_pad); /* LOWORD pkt length? */ 767 pos += yahoo_put16(data + pos, pkt->service); /* service */ 768 pos += yahoo_put32(data + pos, pkt->status); /* status [4bytes] */ 769 pos += yahoo_put32(data + pos, pkt->id); /* session [4bytes] */ 741 770 742 771 yahoo_packet_write(pkt, data + pos); … … 744 773 yahoo_packet_dump(data, len); 745 774 746 if (yid->type == YAHOO_CONNECTION_FT) 775 if (yid->type == YAHOO_CONNECTION_FT) { 747 776 yahoo_send_data(yid->fd, data, len); 748 else777 } else { 749 778 yahoo_add_to_send_queue(yid, data, len); 779 } 750 780 FREE(data); 751 781 } … … 770 800 int e; 771 801 772 if (fd == NULL) 802 if (fd == NULL) { 773 803 return -1; 804 } 774 805 775 806 yahoo_packet_dump(data, len); 776 807 777 808 do { 778 ret = YAHOO_CALLBACK (ext_yahoo_write) (fd, data, len);809 ret = YAHOO_CALLBACK (ext_yahoo_write) (fd, data, len); 779 810 } while (ret == -1 && errno == EINTR); 780 811 e = errno; … … 793 824 { 794 825 struct yahoo_data *yd = find_conn_by_id(id); 795 if (!yd) 796 return; 826 827 if (!yd) { 828 return; 829 } 797 830 798 831 del_from_list(yd); 799 832 800 833 yahoo_free_data(yd); 801 if (id == last_id) 834 if (id == last_id) { 802 835 last_id--; 836 } 803 837 } 804 838 … … 808 842 809 843 LOG(("yahoo_input_close(read)")); 810 YAHOO_CALLBACK (ext_yahoo_remove_handler) (yid->yd->client_id,811 844 YAHOO_CALLBACK (ext_yahoo_remove_handler) (yid->yd->client_id, 845 yid->read_tag); 812 846 LOG(("yahoo_input_close(write)")); 813 YAHOO_CALLBACK (ext_yahoo_remove_handler) (yid->yd->client_id,814 847 YAHOO_CALLBACK (ext_yahoo_remove_handler) (yid->yd->client_id, 848 yid->write_tag); 815 849 yid->read_tag = yid->write_tag = 0; 816 if (yid->fd) 817 YAHOO_CALLBACK(ext_yahoo_close) (yid->fd); 850 if (yid->fd) { 851 YAHOO_CALLBACK (ext_yahoo_close) (yid->fd); 852 } 818 853 yid->fd = 0; 819 854 FREE(yid->rxqueue); … … 823 858 } 824 859 yahoo_free_webcam(yid->wcm); 825 if (yid->wcd) 860 if (yid->wcd) { 826 861 FREE(yid->wcd); 862 } 827 863 if (yid->ys) { 828 864 FREE(yid->ys->lsearch_text); … … 846 882 char *cookieend; 847 883 848 if (strlen(rawcookie) < 2) 884 if (strlen(rawcookie) < 2) { 849 885 return NULL; 886 } 850 887 851 888 tmpcookie = strdup(rawcookie + 2); 852 889 cookieend = strchr(tmpcookie, ';'); 853 890 854 if (cookieend) 891 if (cookieend) { 855 892 *cookieend = '\0'; 893 } 856 894 857 895 cookie = strdup(tmpcookie); … … 872 910 tmp = strdup(tmpend + 2); 873 911 tmpend = strchr(tmp, '&'); 874 if (tmpend) 912 if (tmpend) { 875 913 *tmpend = '\0'; 914 } 876 915 login_cookie = strdup(tmp); 877 916 FREE(tmp); … … 882 921 883 922 static void yahoo_process_notify(struct yahoo_input_data *yid, 884 923 struct yahoo_packet *pkt) 885 924 { 886 925 struct yahoo_data *yd = yid->yd; … … 892 931 char *ind = NULL; 893 932 YList *l; 933 894 934 for (l = pkt->hash; l; l = l->next) { 895 935 struct yahoo_pair *pair = l->data; 896 if (pair->key == 4) 936 if (pair->key == 4) { 897 937 from = pair->value; 898 if (pair->key == 5) 938 } 939 if (pair->key == 5) { 899 940 to = pair->value; 900 if (pair->key == 49) 941 } 942 if (pair->key == 49) { 901 943 msg = pair->value; 902 if (pair->key == 13) 944 } 945 if (pair->key == 13) { 903 946 stat = atoi(pair->value); 904 if (pair->key == 14) 947 } 948 if (pair->key == 14) { 905 949 ind = pair->value; 906 if (pair->key == 16) { /* status == -1 */ 950 } 951 if (pair->key == 16) { /* status == -1 */ 907 952 NOTICE((pair->value)); 908 953 return; … … 911 956 } 912 957 913 if (!msg) 914 return; 915 916 if (!strncasecmp(msg, "TYPING", strlen("TYPING"))) 917 YAHOO_CALLBACK(ext_yahoo_typing_notify) (yd->client_id, to, 918 from, stat); 919 else if (!strncasecmp(msg, "GAME", strlen("GAME"))) 920 YAHOO_CALLBACK(ext_yahoo_game_notify) (yd->client_id, to, from, 921 stat, ind); 922 else if (!strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE"))) { 958 if (!msg) { 959 return; 960 } 961 962 if (!strncasecmp(msg, "TYPING", strlen("TYPING"))) { 963 YAHOO_CALLBACK (ext_yahoo_typing_notify) (yd->client_id, to, 964 from, stat); 965 } else if (!strncasecmp(msg, "GAME", strlen("GAME"))) { 966 YAHOO_CALLBACK (ext_yahoo_game_notify) (yd->client_id, to, from, 967 stat, ind); 968 } else if (!strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE"))) { 923 969 if (!strcmp(ind, " ")) { 924 YAHOO_CALLBACK (ext_yahoo_webcam_invite) (yd->client_id,925 970 YAHOO_CALLBACK (ext_yahoo_webcam_invite) (yd->client_id, 971 to, from); 926 972 } else { 927 973 accept = atoi(ind); 928 974 /* accept the invitation (-1 = deny 1 = accept) */ 929 if (accept < 0) 975 if (accept < 0) { 930 976 accept = 0; 931 YAHOO_CALLBACK(ext_yahoo_webcam_invite_reply) (yd-> 932 client_id, to, from, accept); 933 } 934 } else 977 } 978 YAHOO_CALLBACK (ext_yahoo_webcam_invite_reply) (yd-> 979 client_id, to, from, accept); 980 } 981 } else { 935 982 LOG(("Got unknown notification: %s", msg)); 983 } 936 984 } 937 985 938 986 static void yahoo_process_conference(struct yahoo_input_data *yid, 939 987 struct yahoo_packet *pkt) 940 988 { 941 989 struct yahoo_data *yd = yid->yd; … … 951 999 for (l = pkt->hash; l; l = l->next) { 952 1000 struct yahoo_pair *pair = l->data; 953 if (pair->key == 50) 1001 if (pair->key == 50) { 954 1002 host = pair->value; 955 956 if (pair->key == 52) { /* invite */ 1003 } 1004 1005 if (pair->key == 52) { /* invite */ 957 1006 members = y_list_append(members, strdup(pair->value)); 958 1007 } 959 if (pair->key == 53) 1008 if (pair->key == 53) { /* logon */ 960 1009 who = pair->value; 961 if (pair->key == 54) /* decline */ 1010 } 1011 if (pair->key == 54) { /* decline */ 962 1012 who = pair->value; 963 if (pair->key == 55) /* unavailable (status == 2) */ 1013 } 1014 if (pair->key == 55) { /* unavailable (status == 2) */ 964 1015 who = pair->value; 965 if (pair->key == 56) /* logoff */ 1016 } 1017 if (pair->key == 56) { /* logoff */ 966 1018 who = pair->value; 967 968 if (pair->key == 57) 1019 } 1020 1021 if (pair->key == 57) { 969 1022 room = pair->value; 970 971 if (pair->key == 58) /* join message */ 1023 } 1024 1025 if (pair->key == 58) { /* join message */ 972 1026 msg = pair->value; 973 if (pair->key == 14) /* decline/conf message */ 1027 } 1028 if (pair->key == 14) { /* decline/conf message */ 974 1029 msg = pair->value; 975 976 if (pair->key == 13) 1030 } 1031 1032 if (pair->key == 13) { 977 1033 ; 978 if (pair->key == 16) /* error */ 1034 } 1035 if (pair->key == 16) { /* error */ 979 1036 msg = pair->value; 980 981 if (pair->key == 1) /* my id */ 1037 } 1038 1039 if (pair->key == 1) { /* my id */ 982 1040 id = pair->value; 983 if (pair->key == 3) /* message sender */ 1041 } 1042 if (pair->key == 3) { /* message sender */ 984 1043 who = pair->value; 985 986 if (pair->key == 97) 1044 } 1045 1046 if (pair->key == 97) { 987 1047 utf8 = atoi(pair->value); 988 } 989 990 if (!room) 991 return; 1048 } 1049 } 1050 1051 if (!room) { 1052 return; 1053 } 992 1054 993 1055 if (host) { 994 1056 for (l = members; l; l = l->next) { 995 1057 char *w = l->data; 996 if (!strcmp(w, host)) 1058 if (!strcmp(w, host)) { 997 1059 break; 998 } 999 if (!l) 1060 } 1061 } 1062 if (!l) { 1000 1063 members = y_list_append(members, strdup(host)); 1064 } 1001 1065 } 1002 1066 /* invite, decline, join, left, message -> status == 1 */ … … 1004 1068 switch (pkt->service) { 1005 1069 case YAHOO_SERVICE_CONFINVITE: 1006 if (pkt->status == 2) ; 1007 else if (members) 1008 YAHOO_CALLBACK(ext_yahoo_got_conf_invite) (yd-> 1009 client_id, id, host, room, msg, members); 1010 else if (msg) 1011 YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, msg, 0, 1012 E_CONFNOTAVAIL); 1070 if (pkt->status == 2) { 1071 ; 1072 } else if (members) { 1073 YAHOO_CALLBACK (ext_yahoo_got_conf_invite) (yd-> 1074 client_id, id, host, room, msg, members); 1075 } else if (msg) { 1076 YAHOO_CALLBACK (ext_yahoo_error) (yd->client_id, msg, 0, 1077 E_CONFNOTAVAIL); 1078 } 1013 1079 break; 1014 1080 case YAHOO_SERVICE_CONFADDINVITE: 1015 if (pkt->status == 1) 1016 YAHOO_CALLBACK(ext_yahoo_got_conf_invite) (yd-> 1017 client_id, id, host, room, msg, members); 1081 if (pkt->status == 1) { 1082 YAHOO_CALLBACK (ext_yahoo_got_conf_invite) (yd-> 1083 client_id, id, host, room, msg, members); 1084 } 1018 1085 break; 1019 1086 case YAHOO_SERVICE_CONFDECLINE: 1020 if (who) 1021 YAHOO_CALLBACK(ext_yahoo_conf_userdecline) (yd-> 1022 client_id, id, who, room, msg); 1087 if (who) { 1088 YAHOO_CALLBACK (ext_yahoo_conf_userdecline) (yd-> 1089 client_id, id, who, room, msg); 1090 } 1023 1091 break; 1024 1092 case YAHOO_SERVICE_CONFLOGON: 1025 if (who) 1026 YAHOO_CALLBACK(ext_yahoo_conf_userjoin) (yd->client_id, 1027 id, who, room); 1093 if (who) { 1094 YAHOO_CALLBACK (ext_yahoo_conf_userjoin) (yd->client_id, 1095 id, who, room); 1096 } 1028 1097 break; 1029 1098 case YAHOO_SERVICE_CONFLOGOFF: 1030 if (who) 1031 YAHOO_CALLBACK(ext_yahoo_conf_userleave) (yd->client_id, 1032 id, who, room); 1099 if (who) { 1100 YAHOO_CALLBACK (ext_yahoo_conf_userleave) (yd->client_id, 1101 id, who, room); 1102 } 1033 1103 break; 1034 1104 case YAHOO_SERVICE_CONFMSG: 1035 if (who) 1036 YAHOO_CALLBACK(ext_yahoo_conf_message) (yd->client_id, 1037 id, who, room, msg, utf8); 1105 if (who) { 1106 YAHOO_CALLBACK (ext_yahoo_conf_message) (yd->client_id, 1107 id, who, room, msg, utf8); 1108 } 1038 1109 break; 1039 1110 } … … 1041 1112 1042 1113 static void yahoo_process_chat(struct yahoo_input_data *yid, 1043 1114 struct yahoo_packet *pkt) 1044 1115 { 1045 1116 char *msg = NULL; … … 1087 1158 if (pkt->service == YAHOO_SERVICE_CHATJOIN) { 1088 1159 currentmember = 1089 1160 y_new0(struct yahoo_chat_member, 1); 1090 1161 currentmember->id = strdup(pair->value); 1091 1162 members = y_list_append(members, currentmember); … … 1095 1166 if (pair->key == 110) { 1096 1167 /* age */ 1097 if (pkt->service == YAHOO_SERVICE_CHATJOIN) 1168 if (pkt->service == YAHOO_SERVICE_CHATJOIN) { 1098 1169 currentmember->age = atoi(pair->value); 1170 } 1099 1171 } 1100 1172 1101 1173 if (pair->key == 113) { 1102 1174 /* attribs */ 1103 if (pkt->service == YAHOO_SERVICE_CHATJOIN) 1175 if (pkt->service == YAHOO_SERVICE_CHATJOIN) { 1104 1176 currentmember->attribs = atoi(pair->value); 1177 } 1105 1178 } 1106 1179 1107 1180 if (pair->key == 141) { 1108 1181 /* alias */ 1109 if (pkt->service == YAHOO_SERVICE_CHATJOIN) 1182 if (pkt->service == YAHOO_SERVICE_CHATJOIN) { 1110 1183 currentmember->alias = strdup(pair->value); 1184 } 1111 1185 } 1112 1186 1113 1187 if (pair->key == 142) { 1114 1188 /* location */ 1115 if (pkt->service == YAHOO_SERVICE_CHATJOIN) 1189 if (pkt->service == YAHOO_SERVICE_CHATJOIN) { 1116 1190 currentmember->location = strdup(pair->value); 1191 } 1117 1192 } 1118 1193 … … 1139 1214 1140 1215 if (!room) { 1141 if (pkt->service == YAHOO_SERVICE_CHATLOGOUT) { 1142 YAHOO_CALLBACK (ext_yahoo_chat_yahoologout) (yid->yd->1143 1216 if (pkt->service == YAHOO_SERVICE_CHATLOGOUT) { /* yahoo originated chat logout */ 1217 YAHOO_CALLBACK (ext_yahoo_chat_yahoologout) (yid->yd-> 1218 client_id, id); 1144 1219 return; 1145 1220 } 1146 1221 if (pkt->service == YAHOO_SERVICE_COMMENT && chaterr) { 1147 YAHOO_CALLBACK (ext_yahoo_chat_yahooerror) (yid->yd->1148 1222 YAHOO_CALLBACK (ext_yahoo_chat_yahooerror) (yid->yd-> 1223 client_id, id); 1149 1224 return; 1150 1225 } … … 1160 1235 } 1161 1236 if (firstjoin && members) { 1162 YAHOO_CALLBACK (ext_yahoo_chat_join) (yid->yd->client_id,1163 1237 YAHOO_CALLBACK (ext_yahoo_chat_join) (yid->yd->client_id, 1238 id, room, topic, members, yid->fd); 1164 1239 } else if (who) { 1165 1240 if (y_list_length(members) != 1) { … … 1170 1245 YList *n = members->next; 1171 1246 currentmember = members->data; 1172 YAHOO_CALLBACK (ext_yahoo_chat_userjoin) (yid->1173 1247 YAHOO_CALLBACK (ext_yahoo_chat_userjoin) (yid-> 1248 yd->client_id, id, room, currentmember); 1174 1249 y_list_free_1(members); 1175 1250 members = n; … … 1179 1254 case YAHOO_SERVICE_CHATEXIT: 1180 1255 if (who) { 1181 YAHOO_CALLBACK (ext_yahoo_chat_userleave) (yid->yd->1182 1256 YAHOO_CALLBACK (ext_yahoo_chat_userleave) (yid->yd-> 1257 client_id, id, room, who); 1183 1258 } 1184 1259 break; 1185 1260 case YAHOO_SERVICE_COMMENT: 1186 1261 if (who) { 1187 YAHOO_CALLBACK (ext_yahoo_chat_message) (yid->yd->1188 1262 YAHOO_CALLBACK (ext_yahoo_chat_message) (yid->yd-> 1263 client_id, id, who, room, msg, msgtype, utf8); 1189 1264 } 1190 1265 break; … … 1193 1268 1194 1269 static void yahoo_process_message(struct yahoo_input_data *yid, 1195 1270 struct yahoo_packet *pkt) 1196 1271 { 1197 1272 struct yahoo_data *yd = yid->yd; … … 1213 1288 struct yahoo_pair *pair = l->data; 1214 1289 if (pair->key == 1 || pair->key == 4) { 1215 if (!message->from) 1290 if (!message->from) { 1216 1291 message->from = pair->value; 1217 } else if (pair->key == 5) 1292 } 1293 } else if (pair->key == 5) { 1218 1294 message->to = pair->value; 1219 else if (pair->key == 15)1295 } else if (pair->key == 15) { 1220 1296 message->tm = strtol(pair->value, NULL, 10); 1221 else if (pair->key == 97)1297 } else if (pair->key == 97) { 1222 1298 message->utf8 = atoi(pair->value); 1299 } 1223 1300 /* This comes when the official client sends us a message */ 1224 else if (pair->key == 429) 1301 else if (pair->key == 429) { 1225 1302 message->gunk = pair->value; 1303 } 1226 1304 /* user message *//* sys message */ 1227 else if (pair->key == 14 || pair->key == 16) 1305 else if (pair->key == 14 || pair->key == 16) { 1228 1306 message->msg = pair->value; 1229 else if (pair->key == 31) {1307 } else if (pair->key == 31) { 1230 1308 if (message->i_31) { 1231 1309 messages = y_list_append(messages, message); … … 1233 1311 } 1234 1312 message->i_31 = atoi(pair->value); 1235 } else if (pair->key == 32) 1313 } else if (pair->key == 32) { 1236 1314 message->i_32 = atoi(pair->value); 1237 else 1238 LOG(("yahoo_process_message: status: %d, key: %d, value: %s", pkt->status, pair->key, pair->value)); 1315 } else { 1316 LOG(("yahoo_process_message: status: %d, key: %d, value: %s", pkt->status, pair->key, 1317 pair->value)); 1318 } 1239 1319 } 1240 1320 … … 1244 1324 message = l->data; 1245 1325 if (pkt->service == YAHOO_SERVICE_SYSMESSAGE) { 1246 YAHOO_CALLBACK (ext_yahoo_system_message) (yd->client_id,1247 1326 YAHOO_CALLBACK (ext_yahoo_system_message) (yd->client_id, 1327 message->to, message->from, message->msg); 1248 1328 } else if (pkt->status <= 2 || pkt->status == 5) { 1249 1329 /* Confirm message receipt if we got the gunk */ 1250 if (message->gunk) {1330 if (message->gunk) { 1251 1331 struct yahoo_packet *outpkt; 1252 1332 1253 1333 outpkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE_CONFIRM, 1254 1334 YPACKET_STATUS_DEFAULT, 0); 1255 1335 yahoo_packet_hash(outpkt, 1, yd->user); 1256 1336 yahoo_packet_hash(outpkt, 5, message->from); … … 1260 1340 yahoo_packet_hash(outpkt, 450, "0"); 1261 1341 yahoo_send_packet(yid, outpkt, 0); 1262 1342 1263 1343 yahoo_packet_free(outpkt); 1264 1344 } 1265 1345 1266 if (!strcmp(message->msg, "<ding>")) 1267 YAHOO_CALLBACK(ext_yahoo_got_buzz) (yd->client_id, 1268 message->to, message->from, message->tm); 1269 else 1270 YAHOO_CALLBACK(ext_yahoo_got_im) (yd->client_id, 1271 message->to, message->from, message->msg, 1272 message->tm, pkt->status, message->utf8); 1346 if (!strcmp(message->msg, "<ding>")) { 1347 YAHOO_CALLBACK (ext_yahoo_got_buzz) (yd->client_id, 1348 message->to, message->from, message->tm); 1349 } else { 1350 YAHOO_CALLBACK (ext_yahoo_got_im) (yd->client_id, 1351 message->to, message->from, message->msg, 1352 message->tm, pkt->status, message->utf8); 1353 } 1273 1354 } else if (pkt->status == 0xffffffff) { 1274 YAHOO_CALLBACK (ext_yahoo_error) (yd->client_id,1275 1355 YAHOO_CALLBACK (ext_yahoo_error) (yd->client_id, 1356 message->msg, 0, E_SYSTEM); 1276 1357 } 1277 1358 FREE(message); … … 1286 1367 * 3 level: 1287 1368 * ======= 1288 * 1369 * 1289 1370 * 302 (318) - Beginning level 1 1290 * 1291 * 1292 * 1293 * 1294 * 1371 * 300 (318) - Begin level 2 1372 * 302 (319) - End level 2 header 1373 * 300 (319) - Begin level 3 1374 * 301 (319) - End level 3 1375 * 303 (319) - End level 2 1295 1376 * 303 (318) - End level 1 1296 1377 * … … 1299 1380 * 1300 1381 * 302 (315) - Beginning level 1 1301 * 1302 * 1382 * 300 (315) - Begin level 2 1383 * 301 (315) - End level 2 1303 1384 * 303 (315) - End level 1 1304 1385 * 1305 1386 */ 1306 1387 static void yahoo_process_status(struct yahoo_input_data *yid, 1307 1388 struct yahoo_packet *pkt) 1308 1389 { 1309 1390 YList *l; … … 1315 1396 1316 1397 if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) { 1317 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id,1318 1319 return; 1320 } 1321 1322 /* 1323 * Status updates may be spread accross multiple packets and not 1324 * even on buddy boundaries, so keeping some state is important. 1325 * So, continue where we left off, and only add a user entry to 1398 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 1399 YAHOO_LOGIN_DUPL, NULL); 1400 return; 1401 } 1402 1403 /* 1404 * Status updates may be spread accross multiple packets and not 1405 * even on buddy boundaries, so keeping some state is important. 1406 * So, continue where we left off, and only add a user entry to 1326 1407 * the list once it's complete (301-315 End buddy). 1327 1408 */ … … 1332 1413 1333 1414 switch (pair->key) { 1334 case 300: 1415 case 300: /* Begin buddy */ 1335 1416 if (!strcmp(pair->value, "315") && !u) { 1336 1417 u = yd->half_user = y_new0(struct yahoo_process_status_entry, 1); 1337 1418 } 1338 1419 break; 1339 case 301: 1420 case 301: /* End buddy */ 1340 1421 if (!strcmp(pair->value, "315") && u) { 1341 1422 /* Sometimes user info comes in an odd format with no 1342 1423 "begin buddy" but *with* an "end buddy". Don't add 1343 1424 it twice. */ 1344 if (!y_list_find(users, u)) 1425 if (!y_list_find(users, u)) { 1345 1426 users = y_list_prepend(users, u); 1427 } 1346 1428 u = yd->half_user = NULL; 1347 1429 } 1348 1430 break; 1349 case 0: 1431 case 0: /* we won't actually do anything with this */ 1350 1432 NOTICE(("key %d:%s", pair->key, pair->value)); 1351 1433 break; 1352 case 1: 1434 case 1: /* we don't get the full buddy list here. */ 1353 1435 if (!yd->logged_in) { 1354 1436 yd->logged_in = 1; 1355 if (yd->current_status < 0) 1437 if (yd->current_status < 0) { 1356 1438 yd->current_status = yd->initial_status; 1357 YAHOO_CALLBACK(ext_yahoo_login_response) (yd-> 1358 client_id, YAHOO_LOGIN_OK, NULL); 1439 } 1440 YAHOO_CALLBACK (ext_yahoo_login_response) (yd-> 1441 client_id, YAHOO_LOGIN_OK, NULL); 1359 1442 } 1360 1443 break; 1361 case 8: 1444 case 8: /* how many online buddies we have */ 1362 1445 NOTICE(("key %d:%s", pair->key, pair->value)); 1363 1446 break; 1364 case 7: 1447 case 7: /* the current buddy */ 1365 1448 if (!u) { 1366 1449 /* This will only happen in case of a single level message */ … … 1370 1453 u->name = pair->value; 1371 1454 break; 1372 case 10: 1455 case 10: /* state */ 1373 1456 u->state = strtol(pair->value, NULL, 10); 1374 1457 break; 1375 case 19: 1458 case 19: /* custom status message */ 1376 1459 u->msg = pair->value; 1377 1460 break; 1378 case 47: 1461 case 47: /* is it an away message or not. Not applicable for YMSG16 anymore */ 1379 1462 u->away = atoi(pair->value); 1380 1463 break; 1381 case 137: 1464 case 137: /* seconds idle */ 1382 1465 u->idle = atoi(pair->value); 1383 1466 break; 1384 case 11: 1467 case 11: /* this is the buddy's session id */ 1385 1468 u->buddy_session = atoi(pair->value); 1386 1469 break; 1387 case 17: 1470 case 17: /* in chat? */ 1388 1471 u->f17 = atoi(pair->value); 1389 1472 break; 1390 case 13: 1473 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */ 1391 1474 u->flags = atoi(pair->value); 1392 1475 break; 1393 case 60: 1476 case 60: /* SMS -> 1 MOBILE USER */ 1394 1477 /* sometimes going offline makes this 2, but invisible never sends it */ 1395 1478 u->mobile = atoi(pair->value); … … 1422 1505 u->f213 = atoi(pair->value); 1423 1506 break; 1424 case 16: 1425 YAHOO_CALLBACK (ext_yahoo_error) (yd->client_id,1426 1507 case 16: /* Custom error message */ 1508 YAHOO_CALLBACK (ext_yahoo_error) (yd->client_id, 1509 pair->value, 0, E_CUSTOM); 1427 1510 break; 1428 1511 default: 1429 1512 WARNING(("unknown status key %d:%s", pair->key, 1430 1513 pair->value)); 1431 1514 break; 1432 1515 } … … 1439 1522 if (u->name != NULL) { 1440 1523 if (pkt->service == 1441 1442 /*|| u->flags == 0 No flags for YMSG16 */) {1443 YAHOO_CALLBACK (ext_yahoo_status_changed) (yd->1444 1445 1524 YAHOO_SERVICE_LOGOFF 1525 /*|| u->flags == 0 No flags for YMSG16 */) { 1526 YAHOO_CALLBACK (ext_yahoo_status_changed) (yd-> 1527 client_id, u->name, 1528 YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0); 1446 1529 } else { 1447 1530 /* Key 47 always seems to be 1 for YMSG16 */ 1448 if (!u->state) 1531 if (!u->state) { 1449 1532 u->away = 0; 1450 else1533 } else { 1451 1534 u->away = 1; 1452 1453 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> 1454 client_id, u->name, u->state, u->msg, 1455 u->away, u->idle, u->mobile); 1535 } 1536 1537 YAHOO_CALLBACK (ext_yahoo_status_changed) (yd-> 1538 client_id, u->name, u->state, u->msg, 1539 u->away, u->idle, u->mobile); 1456 1540 } 1457 1541 } … … 1464 1548 1465 1549 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, 1466 1550 struct yahoo_packet *pkt) 1467 1551 { 1468 1552 struct yahoo_data *yd = yid->yd; … … 1480 1564 case 301: 1481 1565 case 302: 1482 break; 1566 break; /* Separators. Our logic does not need them */ 1483 1567 case 303: 1484 if (318 == atoi(pair->value)) 1568 if (318 == atoi(pair->value)) { 1485 1569 last_packet = 1; 1570 } 1486 1571 break; 1487 1572 case 65: … … 1491 1576 newbud = y_new0(struct yahoo_buddy, 1); 1492 1577 newbud->id = strdup(pair->value); 1493 if (cur_group) 1578 if (cur_group) { 1494 1579 newbud->group = strdup(cur_group); 1495 else if (yd->buddies) {1580 } else if (yd->buddies) { 1496 1581 struct yahoo_buddy *lastbud = 1497 (struct yahoo_buddy *)y_list_nth(yd->1498 1499 1582 (struct yahoo_buddy *) y_list_nth(yd-> 1583 buddies, 1584 y_list_length(yd->buddies) - 1)->data; 1500 1585 newbud->group = strdup(lastbud->group); 1501 } else 1586 } else { 1502 1587 newbud->group = strdup("Buddies"); 1588 } 1503 1589 1504 1590 yd->buddies = y_list_append(yd->buddies, newbud); … … 1509 1595 1510 1596 /* we could be getting multiple packets here */ 1511 if (pkt->hash && !last_packet) 1512 return; 1513 1514 YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, yd->buddies); 1597 if (pkt->hash && !last_packet) { 1598 return; 1599 } 1600 1601 YAHOO_CALLBACK (ext_yahoo_got_buddies) (yd->client_id, yd->buddies); 1515 1602 1516 1603 /* Logged in */ 1517 1604 if (!yd->logged_in) { 1518 1605 yd->logged_in = 1; 1519 if (yd->current_status < 0) 1606 if (yd->current_status < 0) { 1520 1607 yd->current_status = yd->initial_status; 1521 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 1522 YAHOO_LOGIN_OK, NULL); 1608 } 1609 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 1610 YAHOO_LOGIN_OK, NULL); 1523 1611 1524 1612 /* 1525 1613 yahoo_set_away(yd->client_id, yd->initial_status, NULL, 1526 1614 (yd->initial_status == YAHOO_STATUS_AVAILABLE) ? 0 : 1); 1527 1615 1528 1616 yahoo_get_yab(yd->client_id); … … 1533 1621 1534 1622 static void yahoo_process_list(struct yahoo_input_data *yid, 1535 1623 struct yahoo_packet *pkt) 1536 1624 { 1537 1625 struct yahoo_data *yd = yid->yd; … … 1543 1631 1544 1632 switch (pair->key) { 1545 case 89: /* identities */ 1546 { 1547 char **identities = 1548 y_strsplit(pair->value, ",", -1); 1549 int i; 1550 for (i = 0; identities[i]; i++) 1551 yd->identities = 1552 y_list_append(yd->identities, 1553 strdup(identities[i])); 1554 y_strfreev(identities); 1633 case 89: /* identities */ 1634 { 1635 char **identities = 1636 y_strsplit(pair->value, ",", -1); 1637 int i; 1638 for (i = 0; identities[i]; i++) { 1639 yd->identities = 1640 y_list_append(yd->identities, 1641 strdup(identities[i])); 1555 1642 } 1556 YAHOO_CALLBACK(ext_yahoo_got_identities) (yd->client_id, 1557 yd->identities); 1558 break; 1559 case 59: /* cookies */ 1643 y_strfreev(identities); 1644 } 1645 YAHOO_CALLBACK (ext_yahoo_got_identities) (yd->client_id, 1646 yd->identities); 1647 break; 1648 case 59: /* cookies */ 1560 1649 if (pair->value[0] == 'Y') { 1561 1650 FREE(yd->cookie_y); … … 1575 1664 1576 1665 break; 1577 case 3: /* my id */ 1578 case 90: /* 1 */ 1579 case 100: /* 0 */ 1580 case 101: /* NULL */ 1581 case 102: /* NULL */ 1582 case 93: /* 86400/1440 */ 1583 break; 1584 } 1585 } 1586 1587 if (yd->cookie_y && yd->cookie_t) /* We don't get cookie_c anymore */ 1588 YAHOO_CALLBACK(ext_yahoo_got_cookies) (yd->client_id); 1666 case 3: /* my id */ 1667 case 90: /* 1 */ 1668 case 100: /* 0 */ 1669 case 101: /* NULL */ 1670 case 102: /* NULL */ 1671 case 93: /* 86400/1440 */ 1672 break; 1673 } 1674 } 1675 1676 if (yd->cookie_y && yd->cookie_t) { /* We don't get cookie_c anymore */ 1677 YAHOO_CALLBACK (ext_yahoo_got_cookies) (yd->client_id); 1678 } 1589 1679 } 1590 1680 1591 1681 static void yahoo_process_verify(struct yahoo_input_data *yid, 1592 1682 struct yahoo_packet *pkt) 1593 1683 { 1594 1684 struct yahoo_data *yd = yid->yd; … … 1596 1686 if (pkt->status != 0x01) { 1597 1687 DEBUG_MSG(("expected status: 0x01, got: %d", pkt->status)); 1598 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id,1599 1688 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 1689 YAHOO_LOGIN_LOCK, ""); 1600 1690 return; 1601 1691 } 1602 1692 1603 1693 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YPACKET_STATUS_DEFAULT, 1604 1694 yd->session_id); 1605 1695 1606 1696 yahoo_packet_hash(pkt, 1, yd->user); … … 1612 1702 1613 1703 static void yahoo_process_picture_checksum(struct yahoo_input_data *yid, 1614 1704 struct yahoo_packet *pkt) 1615 1705 { 1616 1706 struct yahoo_data *yd = yid->yd; … … 1638 1728 } 1639 1729 1640 YAHOO_CALLBACK (ext_yahoo_got_buddyicon_checksum) (yd->client_id, to,1641 1730 YAHOO_CALLBACK (ext_yahoo_got_buddyicon_checksum) (yd->client_id, to, 1731 from, checksum); 1642 1732 } 1643 1733 1644 1734 static void yahoo_process_picture(struct yahoo_input_data *yid, 1645 1735 struct yahoo_packet *pkt) 1646 1736 { 1647 1737 struct yahoo_data *yd = yid->yd; … … 1658 1748 switch (pair->key) { 1659 1749 case 1: 1660 case 4: 1750 case 4: /* sender */ 1661 1751 from = pair->value; 1662 1752 break; 1663 case 5: 1753 case 5: /* we */ 1664 1754 to = pair->value; 1665 1755 break; 1666 case 13: 1756 case 13: /* request / sending */ 1667 1757 status = atoi(pair->value); 1668 1758 break; 1669 case 20: 1759 case 20: /* url */ 1670 1760 url = pair->value; 1671 1761 break; 1672 case 192: 1762 case 192: /*checksum */ 1673 1763 checksum = atoi(pair->value); 1674 1764 break; … … 1677 1767 1678 1768 switch (status) { 1679 case 1: 1680 YAHOO_CALLBACK (ext_yahoo_got_buddyicon_request) (yd->client_id,1681 1769 case 1: /* this is a request, ignore for now */ 1770 YAHOO_CALLBACK (ext_yahoo_got_buddyicon_request) (yd->client_id, 1771 to, from); 1682 1772 break; 1683 case 2: 1684 YAHOO_CALLBACK (ext_yahoo_got_buddyicon) (yd->client_id, to,1685 1773 case 2: /* this is cool - we get a picture :) */ 1774 YAHOO_CALLBACK (ext_yahoo_got_buddyicon) (yd->client_id, to, 1775 from, url, checksum); 1686 1776 break; 1687 1777 } … … 1689 1779 1690 1780 static void yahoo_process_picture_upload(struct yahoo_input_data *yid, 1691 1781 struct yahoo_packet *pkt) 1692 1782 { 1693 1783 struct yahoo_data *yd = yid->yd; … … 1695 1785 char *url = NULL; 1696 1786 1697 if (pkt->status != 1) 1698 return; /* something went wrong */ 1699 1787 if (pkt->status != 1) { 1788 return; /* something went wrong */ 1789 1790 } 1700 1791 for (l = pkt->hash; l; l = l->next) { 1701 1792 struct yahoo_pair *pair = l->data; 1702 1793 1703 1794 switch (pair->key) { 1704 case 5: 1705 break; 1706 case 20: 1795 case 5: /* we */ 1796 break; 1797 case 20: /* url */ 1707 1798 url = pair->value; 1708 1799 break; 1709 case 27: 1710 break; 1711 case 38: 1712 break; 1713 } 1714 } 1715 1716 YAHOO_CALLBACK (ext_yahoo_buddyicon_uploaded) (yd->client_id, url);1800 case 27: /* local filename */ 1801 break; 1802 case 38: /* time */ 1803 break; 1804 } 1805 } 1806 1807 YAHOO_CALLBACK (ext_yahoo_buddyicon_uploaded) (yd->client_id, url); 1717 1808 } 1718 1809 … … 1727 1818 1728 1819 struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); 1820 1729 1821 yid->yd = yd; 1730 1822 yid->type = YAHOO_CONNECTION_PAGER; … … 1739 1831 host = yss->pager_host; 1740 1832 1741 if (!host) 1833 if (!host) { 1742 1834 host = yss->pager_host_list[0]; 1743 1744 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, 1745 host, yss->pager_port, yahoo_connected, ccd, 0); 1835 } 1836 1837 tag = YAHOO_CALLBACK (ext_yahoo_connect_async) (yd->client_id, 1838 host, yss->pager_port, yahoo_connected, ccd, 0); 1746 1839 1747 1840 /* … … 1749 1842 * so ccd will have been freed 1750 1843 */ 1751 if (tag > 0) 1844 if (tag > 0) { 1752 1845 ccd->tag = tag; 1753 else if (tag < 0)1754 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id,1755 1756 }1757 1758 struct yahoo_https_auth_data 1759 {1846 } else if (tag < 0) { 1847 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 1848 YAHOO_LOGIN_SOCK, NULL); 1849 } 1850 } 1851 1852 struct yahoo_https_auth_data { 1760 1853 struct yahoo_input_data *yid; 1761 1854 char *token; … … 1774 1867 char *s, *end; 1775 1868 int len = strlen(key); 1776 1869 1777 1870 s = response; 1778 1871 do { 1779 1872 if (strncmp(s, key, len) == 0 && s[len] == '=') { 1780 1873 s += len + 1; 1781 if ((end = strchr(s, '\r'))) 1874 if ((end = strchr(s, '\r'))) { 1782 1875 return g_strndup(s, end - s); 1783 else1876 } else { 1784 1877 return g_strdup(s); 1785 } 1786 1787 if ((s = strchr(s, '\n'))) 1788 s ++; 1878 } 1879 } 1880 1881 if ((s = strchr(s, '\n'))) { 1882 s++; 1883 } 1789 1884 } while (s && *s); 1790 1885 1791 1886 return NULL; 1792 1887 } … … 1794 1889 static enum yahoo_status yahoo_https_status_parse(int code) 1795 1890 { 1796 switch (code) 1797 { 1798 case 1212: return (enum yahoo_status) YAHOO_LOGIN_PASSWD; 1799 case 1213: return (enum yahoo_status) YAHOO_LOGIN_LOCK; 1800 case 1235: return (enum yahoo_status) YAHOO_LOGIN_UNAME; 1801 default: return (enum yahoo_status) code; 1891 switch (code) { 1892 case 1212: return (enum yahoo_status) YAHOO_LOGIN_PASSWD; 1893 case 1213: return (enum yahoo_status) YAHOO_LOGIN_LOCK; 1894 case 1235: return (enum yahoo_status) YAHOO_LOGIN_UNAME; 1895 default: return (enum yahoo_status) code; 1802 1896 } 1803 1897 } … … 1806 1900 { 1807 1901 struct yahoo_https_auth_data *had = g_new0(struct yahoo_https_auth_data, 1); 1808 1902 1809 1903 had->yid = yid; 1810 1904 had->chal = g_strdup(seed); 1811 1905 1812 1906 yahoo_https_auth_token_init(had); 1813 1907 } … … 1819 1913 char *login, *passwd, *chal; 1820 1914 char *url; 1821 1915 1822 1916 login = g_strndup(yd->user, 3 * strlen(yd->user)); 1823 1917 http_encode(login); … … 1826 1920 chal = g_strndup(had->chal, 3 * strlen(had->chal)); 1827 1921 http_encode(chal); 1828 1922 1829 1923 url = g_strdup_printf("https://login.yahoo.com/config/pwtoken_get?src=ymsgr&ts=%d&login=%s&passwd=%s&chal=%s", 1830 1831 1924 (int) time(NULL), login, passwd, chal); 1925 1832 1926 http_dorequest_url(url, yahoo_https_auth_token_finish, had); 1833 1927 1834 1928 g_free(url); 1835 1929 g_free(chal); … … 1844 1938 struct yahoo_data *yd; 1845 1939 int st; 1846 1847 if (y_list_find(inputs, had->yid) == NULL) 1848 return; 1849 1940 1941 if (y_list_find(inputs, had->yid) == NULL) { 1942 return; 1943 } 1944 1850 1945 yid = had->yid; 1851 1946 yd = yid->yd; 1852 1947 1853 1948 if (req->status_code != 200) { 1854 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 2000 + req->status_code, NULL);1949 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 2000 + req->status_code, NULL); 1855 1950 goto fail; 1856 1951 } 1857 1952 1858 1953 if (sscanf(req->reply_body, "%d", &st) != 1 || st != 0) { 1859 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, yahoo_https_status_parse(st), NULL);1954 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, yahoo_https_status_parse(st), NULL); 1860 1955 goto fail; 1861 1956 } 1862 1957 1863 1958 if ((had->token = yahoo_ha_find_key(req->reply_body, "ymsgr")) == NULL) { 1864 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 3001, NULL);1959 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 3001, NULL); 1865 1960 goto fail; 1866 1961 } 1867 1962 1868 1963 yahoo_https_auth_init(had); 1869 1964 return; 1870 1965 1871 1966 fail: 1872 1967 g_free(had->token); … … 1878 1973 { 1879 1974 char *url; 1880 1975 1881 1976 url = g_strdup_printf("https://login.yahoo.com/config/pwtoken_login?src=ymsgr&ts=%d&token=%s", 1882 1977 (int) time(NULL), had->token); 1883 1978 1884 1979 http_dorequest_url(url, yahoo_https_auth_finish, had); 1885 1980 1886 1981 g_free(url); 1887 1982 } … … 1895 1990 char *crumb = NULL; 1896 1991 int st; 1897 1898 if (y_list_find(inputs, had->yid) == NULL) 1899 return; 1900 1992 1993 if (y_list_find(inputs, had->yid) == NULL) { 1994 return; 1995 } 1996 1901 1997 yid = had->yid; 1902 1998 yd = yid->yd; 1903 1999 1904 2000 md5_byte_t result[16]; 1905 2001 md5_state_t ctx; 1906 2002 1907 2003 unsigned char yhash[32]; 1908 2004 1909 2005 if (req->status_code != 200) { 1910 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 2000 + req->status_code, NULL);2006 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 2000 + req->status_code, NULL); 1911 2007 goto fail; 1912 2008 } 1913 2009 1914 2010 if (sscanf(req->reply_body, "%d", &st) != 1 || st != 0) { 1915 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, yahoo_https_status_parse(st), NULL);2011 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, yahoo_https_status_parse(st), NULL); 1916 2012 goto fail; 1917 2013 } 1918 2014 1919 2015 if ((yd->cookie_y = yahoo_ha_find_key(req->reply_body, "Y")) == NULL || 1920 2016 (yd->cookie_t = yahoo_ha_find_key(req->reply_body, "T")) == NULL || 1921 2017 (crumb = yahoo_ha_find_key(req->reply_body, "crumb")) == NULL) { 1922 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 3002, NULL);2018 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 3002, NULL); 1923 2019 goto fail; 1924 2020 } 1925 1926 md5_init(&ctx); 1927 md5_append(&ctx, (unsigned char *) crumb, 11);1928 md5_append(&ctx, (unsigned char *) had->chal, strlen(had->chal));2021 2022 md5_init(&ctx); 2023 md5_append(&ctx, (unsigned char *) crumb, 11); 2024 md5_append(&ctx, (unsigned char *) had->chal, strlen(had->chal)); 1929 2025 md5_finish(&ctx, result); 1930 2026 to_y64(yhash, result, 16); … … 1935 2031 yahoo_packet_hash(pack, 277, yd->cookie_y); 1936 2032 yahoo_packet_hash(pack, 278, yd->cookie_t); 1937 yahoo_packet_hash(pack, 307, (char *) yhash);2033 yahoo_packet_hash(pack, 307, (char *) yhash); 1938 2034 yahoo_packet_hash(pack, 244, "524223"); 1939 2035 yahoo_packet_hash(pack, 2, yd->user); … … 1941 2037 yahoo_packet_hash(pack, 98, "us"); 1942 2038 yahoo_packet_hash(pack, 135, "7.5.0.647"); 1943 2039 1944 2040 yahoo_send_packet(yid, pack, 0); 1945 2041 1946 2042 yahoo_packet_free(pack); 1947 2043 1948 2044 fail: 1949 2045 g_free(crumb); … … 1954 2050 1955 2051 static void yahoo_process_auth(struct yahoo_input_data *yid, 1956 2052 struct yahoo_packet *pkt) 1957 2053 { 1958 2054 char *seed = NULL; … … 1979 2075 } 1980 2076 1981 if (!seed) 1982 return; 1983 1984 if (m==2) 2077 if (!seed) { 2078 return; 2079 } 2080 2081 if (m == 2) { 1985 2082 yahoo_https_auth(yid, seed, sn); 1986 else {2083 } else { 1987 2084 /* call error */ 1988 2085 WARNING(("unknown auth type %d", m)); 1989 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id,1990 2086 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 2087 YAHOO_LOGIN_UNKNOWN, NULL); 1991 2088 } 1992 2089 } 1993 2090 1994 2091 static void yahoo_process_auth_resp(struct yahoo_input_data *yid, 1995 2092 struct yahoo_packet *pkt) 1996 2093 { 1997 2094 struct yahoo_data *yd = yid->yd; … … 2003 2100 for (l = pkt->hash; l; l = l->next) { 2004 2101 struct yahoo_pair *pair = l->data; 2005 if (pair->key == 0) 2102 if (pair->key == 0) { 2006 2103 ; /* login_id */ 2007 else if (pair->key == 1)2104 } else if (pair->key == 1) { 2008 2105 ; /* handle */ 2009 else if (pair->key == 20)2106 } else if (pair->key == 20) { 2010 2107 url = pair->value; 2011 else if (pair->key == 66)2108 } else if (pair->key == 66) { 2012 2109 login_status = atoi(pair->value); 2110 } 2013 2111 } 2014 2112 2015 2113 if (pkt->status == YPACKET_STATUS_DISCONNECTED) { 2016 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id,2017 2114 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 2115 login_status, url); 2018 2116 /* yahoo_logoff(yd->client_id); */ 2019 2117 } … … 2021 2119 2022 2120 static void yahoo_process_mail(struct yahoo_input_data *yid, 2023 2121 struct yahoo_packet *pkt) 2024 2122 { 2025 2123 struct yahoo_data *yd = yid->yd; … … 2032 2130 for (l = pkt->hash; l; l = l->next) { 2033 2131 struct yahoo_pair *pair = l->data; 2034 if (pair->key == 9) 2132 if (pair->key == 9) { 2035 2133 count = strtol(pair->value, NULL, 10); 2036 else if (pair->key == 43)2134 } else if (pair->key == 43) { 2037 2135 who = pair->value; 2038 else if (pair->key == 42)2136 } else if (pair->key == 42) { 2039 2137 email = pair->value; 2040 else if (pair->key == 18)2138 } else if (pair->key == 18) { 2041 2139 subj = pair->value; 2042 else2140 } else { 2043 2141 LOG(("key: %d => value: %s", pair->key, pair->value)); 2142 } 2044 2143 } 2045 2144 … … 2047 2146 char from[1024]; 2048 2147 snprintf(from, sizeof(from), "%s (%s)", who, email); 2049 YAHOO_CALLBACK(ext_yahoo_mail_notify) (yd->client_id, from, 2050 subj, count); 2051 } else if (count > 0) 2052 YAHOO_CALLBACK(ext_yahoo_mail_notify) (yd->client_id, NULL, 2053 NULL, count); 2148 YAHOO_CALLBACK (ext_yahoo_mail_notify) (yd->client_id, from, 2149 subj, count); 2150 } else if (count > 0) { 2151 YAHOO_CALLBACK (ext_yahoo_mail_notify) (yd->client_id, NULL, 2152 NULL, count); 2153 } 2054 2154 } 2055 2155 2056 2156 static void yahoo_process_new_contact(struct yahoo_input_data *yid, 2057 2157 struct yahoo_packet *pkt) 2058 2158 { 2059 2159 struct yahoo_data *yd = yid->yd; … … 2067 2167 for (l = pkt->hash; l; l = l->next) { 2068 2168 struct yahoo_pair *pair = l->data; 2069 if (pair->key == 4) 2169 if (pair->key == 4) { 2070 2170 who = pair->value; 2071 else if (pair->key == 5)2171 } else if (pair->key == 5) { 2072 2172 me = pair->value; 2073 else if (pair->key == 14)2173 } else if (pair->key == 14) { 2074 2174 msg = pair->value; 2075 else if (pair->key == 13)2175 } else if (pair->key == 13) { 2076 2176 online = strtol(pair->value, NULL, 10); 2077 } 2078 2079 if (who && online < 0) 2080 YAHOO_CALLBACK(ext_yahoo_contact_added) (yd->client_id, me, who, 2081 msg); 2082 else if (online == 2) 2083 YAHOO_CALLBACK(ext_yahoo_rejected) (yd->client_id, who, msg); 2177 } 2178 } 2179 2180 if (who && online < 0) { 2181 YAHOO_CALLBACK (ext_yahoo_contact_added) (yd->client_id, me, who, 2182 msg); 2183 } else if (online == 2) { 2184 YAHOO_CALLBACK (ext_yahoo_rejected) (yd->client_id, who, msg); 2185 } 2084 2186 } 2085 2187 2086 2188 /* UNUSED? */ 2087 2189 static void yahoo_process_contact(struct yahoo_input_data *yid, 2088 2190 struct yahoo_packet *pkt) 2089 2191 { 2090 2192 struct yahoo_data *yd = yid->yd; … … 2102 2204 for (l = pkt->hash; l; l = l->next) { 2103 2205 struct yahoo_pair *pair = l->data; 2104 if (pair->key == 1) 2206 if (pair->key == 1) { 2105 2207 id = pair->value; 2106 else if (pair->key == 3)2208 } else if (pair->key == 3) { 2107 2209 who = pair->value; 2108 else if (pair->key == 14)2210 } else if (pair->key == 14) { 2109 2211 msg = pair->value; 2110 else if (pair->key == 7)2212 } else if (pair->key == 7) { 2111 2213 name = pair->value; 2112 else if (pair->key == 10)2214 } else if (pair->key == 10) { 2113 2215 state = strtol(pair->value, NULL, 10); 2114 else if (pair->key == 15)2216 } else if (pair->key == 15) { 2115 2217 ; /* tm */ 2116 else if (pair->key == 13)2218 } else if (pair->key == 13) { 2117 2219 ; /* online */ 2118 else if (pair->key == 47)2220 } else if (pair->key == 47) { 2119 2221 away = strtol(pair->value, NULL, 10); 2120 else if (pair->key == 137)2222 } else if (pair->key == 137) { 2121 2223 idle = strtol(pair->value, NULL, 10); 2122 else if (pair->key == 60)2224 } else if (pair->key == 60) { 2123 2225 mobile = strtol(pair->value, NULL, 10); 2124 2125 } 2126 2127 if (id) 2128 YAHOO_CALLBACK(ext_yahoo_contact_added) (yd->client_id, id, who, 2129 msg); 2130 else if (name) 2131 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->client_id, name, 2132 state, msg, away, idle, mobile); 2133 else if (pkt->status == 0x07) 2134 YAHOO_CALLBACK(ext_yahoo_rejected) (yd->client_id, who, msg); 2226 } 2227 2228 } 2229 2230 if (id) { 2231 YAHOO_CALLBACK (ext_yahoo_contact_added) (yd->client_id, id, who, 2232 msg); 2233 } else if (name) { 2234 YAHOO_CALLBACK (ext_yahoo_status_changed) (yd->client_id, name, 2235 state, msg, away, idle, mobile); 2236 } else if (pkt->status == 0x07) { 2237 YAHOO_CALLBACK (ext_yahoo_rejected) (yd->client_id, who, msg); 2238 } 2135 2239 } 2136 2240 2137 2241 static void yahoo_process_buddyadd(struct yahoo_input_data *yid, 2138 2242 struct yahoo_packet *pkt) 2139 2243 { 2140 2244 struct yahoo_data *yd = yid->yd; … … 2146 2250 2147 2251 YList *l; 2252 2148 2253 for (l = pkt->hash; l; l = l->next) { 2149 2254 struct yahoo_pair *pair = l->data; 2150 if (pair->key == 1) 2255 if (pair->key == 1) { 2151 2256 ; /* Me... don't care */ 2152 if (pair->key == 7) 2257 } 2258 if (pair->key == 7) { 2153 2259 who = pair->value; 2154 if (pair->key == 65) 2260 } 2261 if (pair->key == 65) { 2155 2262 where = pair->value; 2156 if (pair->key == 66) 2263 } 2264 if (pair->key == 66) { 2157 2265 status = strtol(pair->value, NULL, 10); 2158 } 2159 2160 if (!who) 2161 return; 2162 if (!where) 2266 } 2267 } 2268 2269 if (!who) { 2270 return; 2271 } 2272 if (!where) { 2163 2273 where = "Unknown"; 2274 } 2164 2275 2165 2276 bud = y_new0(struct yahoo_buddy, 1); … … 2181 2292 accepted. Couldn't find any test account that doesn't require auth. 2182 2293 unfortunately (if there is even such a thing?) */ 2183 2184 /* A non-zero status (i've seen 2) seems to mean the buddy is already 2294 2295 /* A non-zero status (i've seen 2) seems to mean the buddy is already 2185 2296 * added and is online */ 2186 2297 if (status) { 2187 2298 LOG(("Setting online see packet for info")); 2188 2299 yahoo_dump_unhandled(pkt); 2189 YAHOO_CALLBACK (ext_yahoo_status_changed) (yd->client_id, who,2190 2300 YAHOO_CALLBACK (ext_yahoo_status_changed) (yd->client_id, who, 2301 YAHOO_STATUS_AVAILABLE, NULL, 0, 0, 0); 2191 2302 } 2192 2303 #endif … … 2194 2305 if (status == 0) { 2195 2306 YList *tmp = y_list_append(NULL, bud); 2196 YAHOO_CALLBACK (ext_yahoo_got_buddies) (yd->client_id, tmp);2307 YAHOO_CALLBACK (ext_yahoo_got_buddies) (yd->client_id, tmp); 2197 2308 y_list_free(tmp); 2198 2309 } … … 2200 2311 2201 2312 static void yahoo_process_buddydel(struct yahoo_input_data *yid, 2202 2313 struct yahoo_packet *pkt) 2203 2314 { 2204 2315 struct yahoo_data *yd = yid->yd; … … 2210 2321 2211 2322 YList *l; 2323 2212 2324 for (l = pkt->hash; l; l = l->next) { 2213 2325 struct yahoo_pair *pair = l->data; 2214 if (pair->key == 1) 2326 if (pair->key == 1) { 2215 2327 ; /* Me... don't care */ 2216 else if (pair->key == 7)2328 } else if (pair->key == 7) { 2217 2329 who = pair->value; 2218 else if (pair->key == 65)2330 } else if (pair->key == 65) { 2219 2331 where = pair->value; 2220 else if (pair->key == 66)2332 } else if (pair->key == 66) { 2221 2333 ; /* unk_66 */ 2222 else2334 } else { 2223 2335 DEBUG_MSG(("unknown key: %d = %s", pair->key, 2224 pair->value)); 2225 } 2226 2227 if (!who || !where) 2228 return; 2336 pair->value)); 2337 } 2338 } 2339 2340 if (!who || !where) { 2341 return; 2342 } 2229 2343 2230 2344 bud = y_new0(struct yahoo_buddy, 1); … … 2253 2367 2254 2368 static void yahoo_process_ignore(struct yahoo_input_data *yid, 2255 2369 struct yahoo_packet *pkt) 2256 2370 { 2257 2371 YList *l; 2372 2258 2373 for (l = pkt->hash; l; l = l->next) { 2259 2374 struct yahoo_pair *pair = l->data; 2260 if (pair->key == 0) 2375 if (pair->key == 0) { 2261 2376 ; /* who */ 2262 if (pair->key == 1) 2377 } 2378 if (pair->key == 1) { 2263 2379 ; /* Me... don't care */ 2264 if (pair->key == 13) /* 1 == ignore, 2 == unignore */ 2380 } 2381 if (pair->key == 13) { /* 1 == ignore, 2 == unignore */ 2265 2382 ; 2266 if (pair->key == 66) 2383 } 2384 if (pair->key == 66) { 2267 2385 ; /* status */ 2386 } 2268 2387 } 2269 2388 … … 2277 2396 2278 2397 /* if(status) 2279 2398 YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, who, 0, status); 2280 2399 */ 2281 2400 } 2282 2401 2283 2402 static void yahoo_process_voicechat(struct yahoo_input_data *yid, 2284 2403 struct yahoo_packet *pkt) 2285 2404 { 2286 2405 char *who = NULL; … … 2289 2408 2290 2409 YList *l; 2410 2291 2411 for (l = pkt->hash; l; l = l->next) { 2292 2412 struct yahoo_pair *pair = l->data; 2293 if (pair->key == 4) 2413 if (pair->key == 4) { 2294 2414 who = pair->value; 2295 if (pair->key == 5) 2415 } 2416 if (pair->key == 5) { 2296 2417 me = pair->value; 2297 if (pair->key == 13) 2418 } 2419 if (pair->key == 13) { 2298 2420 ; /* voice room */ 2299 if (pair->key == 57) 2421 } 2422 if (pair->key == 57) { 2300 2423 room = pair->value; 2424 } 2301 2425 } 2302 2426 2303 2427 NOTICE(("got voice chat invite from %s in %s to identity %s", who, room, 2304 2305 /* 2428 me)); 2429 /* 2306 2430 * send: s:0 1:me 5:who 57:room 13:1 2307 2431 * ???? s:4 5:who 10:99 19:-1615114531 … … 2315 2439 2316 2440 static void yahoo_process_ping(struct yahoo_input_data *yid, 2317 2441 struct yahoo_packet *pkt) 2318 2442 { 2319 2443 char *errormsg = NULL; 2320 2444 2321 2445 YList *l; 2446 2322 2447 for (l = pkt->hash; l; l = l->next) { 2323 2448 struct yahoo_pair *pair = l->data; 2324 if (pair->key == 16) 2449 if (pair->key == 16) { 2325 2450 errormsg = pair->value; 2451 } 2326 2452 } 2327 2453 2328 2454 NOTICE(("got ping packet")); 2329 YAHOO_CALLBACK (ext_yahoo_got_ping) (yid->yd->client_id, errormsg);2455 YAHOO_CALLBACK (ext_yahoo_got_ping) (yid->yd->client_id, errormsg); 2330 2456 } 2331 2457 2332 2458 static void yahoo_process_buddy_change_group(struct yahoo_input_data *yid, 2333 2459 struct yahoo_packet *pkt) 2334 2460 { 2335 2461 YList *l; … … 2341 2467 for (l = pkt->hash; l; l = l->next) { 2342 2468 struct yahoo_pair *pair = l->data; 2343 if (pair->key == 1) 2469 if (pair->key == 1) { 2344 2470 me = pair->value; 2345 if (pair->key == 7) 2471 } 2472 if (pair->key == 7) { 2346 2473 who = pair->value; 2347 if (pair->key == 224) 2474 } 2475 if (pair->key == 224) { 2348 2476 old_group = pair->value; 2349 if (pair->key == 264) 2477 } 2478 if (pair->key == 264) { 2350 2479 new_group = pair->value; 2351 } 2352 2353 YAHOO_CALLBACK(ext_yahoo_got_buddy_change_group) (yid->yd->client_id, 2354 me, who, old_group, new_group); 2480 } 2481 } 2482 2483 YAHOO_CALLBACK (ext_yahoo_got_buddy_change_group) (yid->yd->client_id, 2484 me, who, old_group, new_group); 2355 2485 } 2356 2486 … … 2376 2506 2377 2507 /* send initial packet */ 2378 if (who) 2508 if (who) { 2379 2509 data = strdup("<RVWCFG>"); 2380 else2510 } else { 2381 2511 data = strdup("<RUPCFG>"); 2512 } 2382 2513 yahoo_add_to_send_queue(yid, data, strlen(data)); 2383 2514 FREE(data); … … 2404 2535 2405 2536 yid->read_tag = 2406 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd,2407 2537 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd->client_id, fd, 2538 YAHOO_INPUT_READ, yid); 2408 2539 } 2409 2540 2410 2541 static void yahoo_webcam_get_server(struct yahoo_input_data *y, char *who, 2411 2542 char *key) 2412 2543 { 2413 2544 struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); … … 2421 2552 yid->wcm->key = strdup(key); 2422 2553 2423 YAHOO_CALLBACK (ext_yahoo_connect_async) (yid->yd->client_id,2424 2425 2554 YAHOO_CALLBACK (ext_yahoo_connect_async) (yid->yd->client_id, 2555 yss->webcam_host, yss->webcam_port, 2556 _yahoo_webcam_get_server_connected, yid, 0); 2426 2557 2427 2558 } … … 2429 2560 static YList *webcam_queue = NULL; 2430 2561 static void yahoo_process_webcam_key(struct yahoo_input_data *yid, 2431 2562 struct yahoo_packet *pkt) 2432 2563 { 2433 2564 char *key = NULL; … … 2435 2566 2436 2567 YList *l; 2568 2437 2569 yahoo_dump_unhandled(pkt); 2438 2570 for (l = pkt->hash; l; l = l->next) { 2439 2571 struct yahoo_pair *pair = l->data; 2440 if (pair->key == 5) 2572 if (pair->key == 5) { 2441 2573 ; /* me */ 2442 if (pair->key == 61) 2574 } 2575 if (pair->key == 61) { 2443 2576 key = pair->value; 2577 } 2444 2578 } 2445 2579 2446 2580 l = webcam_queue; 2447 if (!l) 2448 return; 2581 if (!l) { 2582 return; 2583 } 2449 2584 who = l->data; 2450 2585 webcam_queue = y_list_remove_link(webcam_queue, webcam_queue); … … 2455 2590 2456 2591 static void yahoo_packet_process(struct yahoo_input_data *yid, 2457 2592 struct yahoo_packet *pkt) 2458 2593 { 2459 2594 DEBUG_MSG(("yahoo_packet_process: 0x%02x", pkt->service)); … … 2577 2712 yahoo_process_picture_upload(yid, pkt); 2578 2713 break; 2579 case YAHOO_SERVICE_Y8_LIST: 2714 case YAHOO_SERVICE_Y8_LIST: /* Buddy List */ 2580 2715 yahoo_process_buddy_list(yid, pkt); 2581 2716 break; … … 2594 2729 int pktlen; 2595 2730 2596 if (!yd) 2731 if (!yd) { 2597 2732 return NULL; 2733 } 2598 2734 2599 2735 DEBUG_MSG(("rxlen is %d", yid->rxlen)); … … 2603 2739 } 2604 2740 2605 pos += 4; 2741 pos += 4; /* YMSG */ 2606 2742 pos += 2; 2607 2743 pos += 2; … … 2626 2762 pos += 4; 2627 2763 DEBUG_MSG(("Yahoo Service: 0x%02x Status: %d", pkt->service, 2628 2764 pkt->status)); 2629 2765 pkt->id = yahoo_get32(yid->rxqueue + pos); 2630 2766 pos += 4; … … 2638 2774 if (yid->rxlen > 0) { 2639 2775 unsigned char *tmp = y_memdup(yid->rxqueue + YAHOO_PACKET_HDRLEN 2640 2776 + pktlen, yid->rxlen); 2641 2777 FREE(yid->rxqueue); 2642 2778 yid->rxqueue = tmp; 2643 2779 DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, 2644 2780 yid->rxqueue)); 2645 2781 } else { 2646 2782 DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); … … 2655 2791 { 2656 2792 char *st, *en; 2657 char *data = (char *) d;2793 char *data = (char *) d; 2658 2794 struct yab *yab = NULL; 2659 2795 … … 2671 2807 } 2672 2808 2673 if (!en) 2809 if (!en) { 2674 2810 return NULL; 2811 } 2675 2812 2676 2813 st = strstr(en, "id=\""); … … 2755 2892 struct yahoo_data *yd = yid->yd; 2756 2893 2757 if (!yd) 2894 if (!yd) { 2758 2895 return NULL; 2896 } 2759 2897 2760 2898 do { 2761 2899 DEBUG_MSG(("rxlen is %d", yid->rxlen)); 2762 2900 2763 if (yid->rxlen <= strlen("<ct")) 2901 if (yid->rxlen <= strlen("<ct")) { 2764 2902 return NULL; 2903 } 2765 2904 2766 2905 /* start with <ct */ 2767 2906 while (pos < yid->rxlen - strlen("<ct") + 1 2768 && memcmp(yid->rxqueue + pos, "<ct", strlen("<ct")))2907 && memcmp(yid->rxqueue + pos, "<ct", strlen("<ct"))) { 2769 2908 pos++; 2770 2771 if (pos >= yid->rxlen - 1) 2909 } 2910 2911 if (pos >= yid->rxlen - 1) { 2772 2912 return NULL; 2913 } 2773 2914 2774 2915 end = pos + 2; 2775 2916 /* end with > */ 2776 2917 while (end < yid->rxlen - strlen(">") 2777 && memcmp(yid->rxqueue + end, ">", strlen(">")))2918 && memcmp(yid->rxqueue + end, ">", strlen(">"))) { 2778 2919 end++; 2779 2780 if (end >= yid->rxlen - 1) 2920 } 2921 2922 if (end >= yid->rxlen - 1) { 2781 2923 return NULL; 2924 } 2782 2925 2783 2926 yab = yahoo_yab_read(yid->rxqueue + pos, end + 2 - pos); … … 2785 2928 yid->rxlen -= end + 1; 2786 2929 DEBUG_MSG(("rxlen == %d, rxqueue == %p", yid->rxlen, 2787 2930 yid->rxqueue)); 2788 2931 if (yid->rxlen > 0) { 2789 2932 unsigned char *tmp = 2790 2933 y_memdup(yid->rxqueue + end + 1, yid->rxlen); 2791 2934 FREE(yid->rxqueue); 2792 2935 yid->rxqueue = tmp; 2793 2936 DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, 2794 2937 yid->rxqueue)); 2795 2938 } else { 2796 2939 DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); … … 2812 2955 struct yahoo_data *yd = yid->yd; 2813 2956 2814 if (!yid || !yd) 2957 if (!yid || !yd) { 2815 2958 return NULL; 2959 } 2816 2960 2817 2961 DEBUG_MSG(("rxlen is %d", yid->rxlen)); 2818 2962 2819 2963 len = yid->rxqueue[pos++]; 2820 if (yid->rxlen < len) 2964 if (yid->rxlen < len) { 2821 2965 return NULL; 2966 } 2822 2967 2823 2968 /* extract status (0 = ok, 6 = webcam not online) */ … … 2825 2970 2826 2971 if (status == 0) { 2827 pos += 2; 2972 pos += 2; /* skip next 2 bytes */ 2828 2973 server = y_memdup(yid->rxqueue + pos, 16); 2829 2974 pos += 16; 2830 2975 } else if (status == 6) { 2831 YAHOO_CALLBACK (ext_yahoo_webcam_closed)2832 2976 YAHOO_CALLBACK (ext_yahoo_webcam_closed) 2977 (yd->client_id, yid->wcm->user, 4); 2833 2978 } 2834 2979 … … 2842 2987 yid->rxqueue = tmp; 2843 2988 DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, 2844 2989 yid->rxqueue)); 2845 2990 } else { 2846 2991 DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); … … 2863 3008 struct yahoo_data *yd = yid->yd; 2864 3009 2865 if (!yd) 3010 if (!yd) { 2866 3011 return -1; 2867 2868 if (!yid->wcm || !yid->wcd || !yid->rxlen) 3012 } 3013 3014 if (!yid->wcm || !yid->wcd || !yid->rxlen) { 2869 3015 return -1; 3016 } 2870 3017 2871 3018 DEBUG_MSG(("rxlen is %d", yid->rxlen)); … … 2876 3023 yid->wcd->packet_type = 0; 2877 3024 2878 if (yid->rxlen < header_len) 3025 if (yid->rxlen < header_len) { 2879 3026 return 0; 3027 } 2880 3028 2881 3029 if (header_len >= 8) { … … 2899 3047 begin = pos; 2900 3048 pos += yid->wcd->to_read; 2901 if (pos > yid->rxlen) 3049 if (pos > yid->rxlen) { 2902 3050 pos = yid->rxlen; 3051 } 2903 3052 2904 3053 /* if it is not an image then make sure we have the whole packet */ … … 2913 3062 2914 3063 DEBUG_MSG(("packet type %.2X, data length %d", yid->wcd->packet_type, 2915 3064 yid->wcd->data_size)); 2916 3065 2917 3066 /* find out what kind of packet we got */ … … 2920 3069 /* user requests to view webcam (uploading) */ 2921 3070 if (yid->wcd->data_size && 2922 3071 yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) { 2923 3072 end = begin; 2924 while (end <= yid->rxlen && yid->rxqueue[end++] != 13) ; 3073 while (end <= yid->rxlen && yid->rxqueue[end++] != 13) { 3074 ; 3075 } 2925 3076 if (end > begin) { 2926 3077 who = y_memdup(yid->rxqueue + begin, 2927 3078 end - begin); 2928 3079 who[end - begin - 1] = 0; 2929 YAHOO_CALLBACK (ext_yahoo_webcam_viewer) (yd->2930 3080 YAHOO_CALLBACK (ext_yahoo_webcam_viewer) (yd-> 3081 client_id, who + 2, 2); 2931 3082 FREE(who); 2932 3083 } … … 2938 3089 /* 1 = accepted viewing permission */ 2939 3090 if (yid->wcd->timestamp == 0) { 2940 YAHOO_CALLBACK (ext_yahoo_webcam_closed) (yd->2941 3091 YAHOO_CALLBACK (ext_yahoo_webcam_closed) (yd-> 3092 client_id, yid->wcm->user, 3); 2942 3093 } 2943 3094 } 2944 3095 break; 2945 case 0x01: 3096 case 0x01: /* status packets?? */ 2946 3097 /* timestamp contains status info */ 2947 3098 /* 00 00 00 01 = we have data?? */ 2948 3099 break; 2949 case 0x02: 2950 YAHOO_CALLBACK (ext_yahoo_got_webcam_image) (yd->client_id,2951 2952 3100 case 0x02: /* image data */ 3101 YAHOO_CALLBACK (ext_yahoo_got_webcam_image) (yd->client_id, 3102 yid->wcm->user, yid->rxqueue + begin, 3103 yid->wcd->data_size, pos - begin, yid->wcd->timestamp); 2953 3104 break; 2954 case 0x05: 3105 case 0x05: /* response packets when uploading */ 2955 3106 if (!yid->wcd->data_size) { 2956 YAHOO_CALLBACK (ext_yahoo_webcam_data_request) (yd->2957 3107 YAHOO_CALLBACK (ext_yahoo_webcam_data_request) (yd-> 3108 client_id, yid->wcd->timestamp); 2958 3109 } 2959 3110 break; 2960 case 0x07: 3111 case 0x07: /* connection is closing */ 2961 3112 switch (reason) { 2962 case 0x01: 3113 case 0x01: /* user closed connection */ 2963 3114 closed = 1; 2964 3115 break; 2965 case 0x0F: 3116 case 0x0F: /* user cancelled permission */ 2966 3117 closed = 2; 2967 3118 break; 2968 3119 } 2969 YAHOO_CALLBACK (ext_yahoo_webcam_closed) (yd->client_id,2970 3120 YAHOO_CALLBACK (ext_yahoo_webcam_closed) (yd->client_id, 3121 yid->wcm->user, closed); 2971 3122 break; 2972 case 0x0C: 2973 case 0x0D: 3123 case 0x0C: /* user connected */ 3124 case 0x0D: /* user disconnected */ 2974 3125 if (yid->wcd->data_size) { 2975 3126 who = y_memdup(yid->rxqueue + begin, pos - begin + 1); 2976 3127 who[pos - begin] = 0; 2977 if (yid->wcd->packet_type == 0x0C) 3128 if (yid->wcd->packet_type == 0x0C) { 2978 3129 connect = 1; 2979 else3130 } else { 2980 3131 connect = 0; 2981 YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd->client_id, 2982 who, connect); 3132 } 3133 YAHOO_CALLBACK (ext_yahoo_webcam_viewer) (yd->client_id, 3134 who, connect); 2983 3135 FREE(who); 2984 3136 } 2985 3137 break; 2986 case 0x13: 3138 case 0x13: /* user data */ 2987 3139 /* i=user_ip (ip of the user we are viewing) */ 2988 3140 /* j=user_ext_ip (external ip of the user we */ 2989 3141 /* are viewing) */ 2990 3142 break; 2991 case 0x17: 3143 case 0x17: /* ?? */ 2992 3144 break; 2993 3145 } … … 3001 3153 yid->rxqueue = tmp; 3002 3154 DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, 3003 3155 yid->rxqueue)); 3004 3156 } else { 3005 3157 DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); … … 3008 3160 3009 3161 /* If we read a complete packet return success */ 3010 if (!yid->wcd->to_read) 3162 if (!yid->wcd->to_read) { 3011 3163 return 1; 3164 } 3012 3165 3013 3166 return 0; … … 3021 3174 3022 3175 LOG(("write callback: id=%d fd=%p data=%p", id, fd, data)); 3023 if (!yid || !yid->txqueues) 3176 if (!yid || !yid->txqueues) { 3024 3177 return -2; 3178 } 3025 3179 3026 3180 tx = yid->txqueues->data; … … 3028 3182 len = yahoo_send_data(fd, tx->queue, MIN(1024, tx->len)); 3029 3183 3030 if (len == -1 && errno == EAGAIN) 3184 if (len == -1 && errno == EAGAIN) { 3031 3185 return 1; 3186 } 3032 3187 3033 3188 if (len <= 0) { … … 3040 3195 free(tx); 3041 3196 yid->txqueues = 3042 3043 3197 y_list_remove_link(yid->txqueues, 3198 yid->txqueues); 3044 3199 y_list_free_1(l); 3045 3200 } 3046 3201 LOG(("yahoo_write_ready(%d, %p) len < 0", id, fd)); 3047 YAHOO_CALLBACK (ext_yahoo_remove_handler) (id, yid->write_tag);3202 YAHOO_CALLBACK (ext_yahoo_remove_handler) (id, yid->write_tag); 3048 3203 yid->write_tag = 0; 3049 3204 errno = e; … … 3062 3217 free(tx); 3063 3218 yid->txqueues = 3064 3219 y_list_remove_link(yid->txqueues, yid->txqueues); 3065 3220 y_list_free_1(l); 3066 3221 /* 3067 if(!yid->txqueues) 3222 if(!yid->txqueues) 3068 3223 LOG(("yahoo_write_ready(%d, %d) !yxqueues", id, fd)); 3069 3224 */ 3070 3225 if (!yid->txqueues) { 3071 3226 LOG(("yahoo_write_ready(%d, %p) !txqueues", id, fd)); 3072 YAHOO_CALLBACK (ext_yahoo_remove_handler) (id,3073 3227 YAHOO_CALLBACK (ext_yahoo_remove_handler) (id, 3228 yid->write_tag); 3074 3229 yid->write_tag = 0; 3075 3230 } … … 3080 3235 3081 3236 static void yahoo_process_pager_connection(struct yahoo_input_data *yid, 3082 3237 int over) 3083 3238 { 3084 3239 struct yahoo_packet *pkt; … … 3086 3241 int id = yd->client_id; 3087 3242 3088 if (over) 3089 return; 3243 if (over) { 3244 return; 3245 } 3090 3246 3091 3247 while (find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER) 3092 3248 && (pkt = yahoo_getdata(yid)) != NULL) { 3093 3249 3094 3250 yahoo_packet_process(yid, pkt); … … 3099 3255 3100 3256 static void yahoo_process_chatcat_connection(struct yahoo_input_data *yid, 3101 int over) 3102 { 3103 if (over) 3104 return; 3105 3106 if (strstr((char *)yid->rxqueue + (yid->rxlen - 20), "</content>")) { 3107 YAHOO_CALLBACK(ext_yahoo_chat_cat_xml) (yid->yd->client_id, 3108 (char *)yid->rxqueue); 3257 int over) 3258 { 3259 if (over) { 3260 return; 3261 } 3262 3263 if (strstr((char *) yid->rxqueue + (yid->rxlen - 20), "</content>")) { 3264 YAHOO_CALLBACK (ext_yahoo_chat_cat_xml) (yid->yd->client_id, 3265 (char *) yid->rxqueue); 3109 3266 } 3110 3267 } … … 3122 3279 LOG(("Got data for YAB")); 3123 3280 3124 if (over) 3125 return; 3281 if (over) { 3282 return; 3283 } 3126 3284 3127 3285 while (find_input_by_id_and_type(id, YAHOO_CONNECTION_YAB) 3128 3129 if (!yab->id) 3286 && (yab = yahoo_getyab(yid)) != NULL) { 3287 if (!yab->id) { 3130 3288 continue; 3289 } 3131 3290 3132 3291 changed = 1; … … 3141 3300 } else if (yab->fname && yab->lname) { 3142 3301 bud->real_name = y_new0(char, 3143 3144 3302 strlen(yab->fname) + 3303 strlen(yab->lname) + 2); 3145 3304 sprintf(bud->real_name, "%s %s", 3146 3305 yab->fname, yab->lname); 3147 3306 } else if (yab->fname) { 3148 3307 bud->real_name = strdup(yab->fname); 3149 3308 } 3150 break; 3309 break; /* for */ 3151 3310 } 3152 3311 } … … 3166 3325 } 3167 3326 3168 if (changed) 3169 YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, 3170 yd->buddies); 3327 if (changed) { 3328 YAHOO_CALLBACK (ext_yahoo_got_buddies) (yd->client_id, 3329 yd->buddies); 3330 } 3171 3331 } 3172 3332 #endif 3173 3333 3174 3334 static void yahoo_process_search_connection(struct yahoo_input_data *yid, 3175 3335 int over) 3176 3336 { 3177 3337 struct yahoo_found_contact *yct = NULL; 3178 char *p = (char *) yid->rxqueue, *np, *cp;3338 char *p = (char *) yid->rxqueue, *np, *cp; 3179 3339 int k, n; 3180 3340 int start = 0, found = 0, total = 0; 3181 3341 YList *contacts = NULL; 3182 3342 struct yahoo_input_data *pyid = 3183 find_input_by_id_and_type(yid->yd->client_id, 3184 YAHOO_CONNECTION_PAGER); 3185 3186 if (!over || !pyid) 3187 return; 3343 find_input_by_id_and_type(yid->yd->client_id, 3344 YAHOO_CONNECTION_PAGER); 3345 3346 if (!over || !pyid) { 3347 return; 3348 } 3188 3349 3189 3350 if (p && (p = strstr(p, "\r\n\r\n"))) { … … 3206 3367 } 3207 3368 3208 if (p) 3369 if (p) { 3209 3370 p++; 3371 } 3210 3372 3211 3373 k = 0; … … 3214 3376 np = strchr(p, 4); 3215 3377 3216 if (!np) 3378 if (!np) { 3217 3379 break; 3380 } 3218 3381 *np = 0; 3219 3382 p = np + 1; … … 3222 3385 case 1: 3223 3386 if (strlen(cp) > 2 3224 3387 && y_list_length(contacts) < total) { 3225 3388 yct = y_new0(struct yahoo_found_contact, 3226 3389 1); 3227 3390 contacts = y_list_append(contacts, yct); 3228 3391 yct->id = cp + 2; … … 3242 3405 case 5: 3243 3406 /* not worth the context switch for strcmp */ 3244 if (cp[0] != '\005' || cp[1] != '\000') 3407 if (cp[0] != '\005' || cp[1] != '\000') { 3245 3408 yct->location = cp; 3409 } 3246 3410 k = 0; 3247 3411 break; … … 3250 3414 } 3251 3415 3252 YAHOO_CALLBACK (ext_yahoo_got_search_result) (yid->yd->client_id, found,3253 3416 YAHOO_CALLBACK (ext_yahoo_got_search_result) (yid->yd->client_id, found, 3417 start, total, contacts); 3254 3418 3255 3419 while (contacts) { … … 3357 3521 3358 3522 yid->read_tag = 3359 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id,3360 3523 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd->client_id, 3524 yid->fd, YAHOO_INPUT_READ, yid); 3361 3525 } 3362 3526 … … 3366 3530 struct yahoo_input_data *yid; 3367 3531 3368 if (!wcm || !wcm->server || !wcm->key) 3369 return; 3532 if (!wcm || !wcm->server || !wcm->key) { 3533 return; 3534 } 3370 3535 3371 3536 yid = y_new0(struct yahoo_input_data, 1); … … 3380 3545 3381 3546 LOG(("Connecting to: %s:%d", wcm->server, wcm->port)); 3382 YAHOO_CALLBACK (ext_yahoo_connect_async) (y->yd->client_id, wcm->server,3383 3547 YAHOO_CALLBACK (ext_yahoo_connect_async) (y->yd->client_id, wcm->server, 3548 wcm->port, _yahoo_webcam_connected, yid, 0); 3384 3549 3385 3550 } 3386 3551 3387 3552 static void yahoo_process_webcam_master_connection(struct yahoo_input_data *yid, 3388 3553 int over) 3389 3554 { 3390 3555 char *server; 3391 3556 struct yahoo_server_settings *yss; 3392 3557 3393 if (over) 3394 return; 3558 if (over) { 3559 return; 3560 } 3395 3561 3396 3562 server = yahoo_getwebcam_master(yid); … … 3402 3568 yid->wcm->conn_type = yss->conn_type; 3403 3569 yid->wcm->my_ip = strdup(yss->local_host); 3404 if (yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) 3570 if (yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) { 3405 3571 yid->wcm->description = strdup(yss->webcam_description); 3572 } 3406 3573 yahoo_webcam_connect(yid); 3407 3574 FREE(server); … … 3410 3577 3411 3578 static void yahoo_process_webcam_connection(struct yahoo_input_data *yid, 3412 3579 int over) 3413 3580 { 3414 3581 int id = yid->yd->client_id; 3415 3582 void *fd = yid->fd; 3416 3583 3417 if (over) 3418 return; 3584 if (over) { 3585 return; 3586 } 3419 3587 3420 3588 /* as long as we still have packets available keep processing them */ 3421 3589 while (find_input_by_id_and_fd(id, fd) 3422 && yahoo_get_webcam_data(yid) == 1) ; 3423 } 3424 3425 static void (*yahoo_process_connection[]) (struct yahoo_input_data *, 3426 int over) = { 3427 yahoo_process_pager_connection, yahoo_process_ft_connection, 3428 NULL, /*yahoo_process_yab_connection, */ 3429 yahoo_process_webcam_master_connection, 3430 yahoo_process_webcam_connection, 3431 yahoo_process_chatcat_connection, 3432 yahoo_process_search_connection}; 3590 && yahoo_get_webcam_data(yid) == 1) { 3591 ; 3592 } 3593 } 3594 3595 static void(*yahoo_process_connection[]) (struct yahoo_input_data *, 3596 int over) = { 3597 yahoo_process_pager_connection, yahoo_process_ft_connection, 3598 NULL, /*yahoo_process_yab_connection, */ 3599 yahoo_process_webcam_master_connection, 3600 yahoo_process_webcam_connection, 3601 yahoo_process_chatcat_connection, 3602 yahoo_process_search_connection 3603 }; 3433 3604 3434 3605 int yahoo_read_ready(int id, void *fd, void *data) … … 3439 3610 3440 3611 LOG(("read callback: id=%d fd=%p data=%p", id, fd, data)); 3441 if (!yid) 3612 if (!yid) { 3442 3613 return -2; 3614 } 3443 3615 3444 3616 do { 3445 len = YAHOO_CALLBACK (ext_yahoo_read) (fd, buf, sizeof(buf));3617 len = YAHOO_CALLBACK (ext_yahoo_read) (fd, buf, sizeof(buf)); 3446 3618 } while (len == -1 && errno == EINTR); 3447 3619 3448 if (len == -1 && (errno == EAGAIN || errno == EINTR)) 3620 if (len == -1 && (errno == EAGAIN || errno == EINTR)) { /* we'll try again later */ 3449 3621 return 1; 3622 } 3450 3623 3451 3624 if (len <= 0) { … … 3454 3627 3455 3628 if (yid->type == YAHOO_CONNECTION_PAGER) { 3456 YAHOO_CALLBACK (ext_yahoo_login_response) (yid->yd->3457 3629 YAHOO_CALLBACK (ext_yahoo_login_response) (yid->yd-> 3630 client_id, YAHOO_LOGIN_SOCK, NULL); 3458 3631 } 3459 3632 … … 3462 3635 3463 3636 /* no need to return an error, because we've already fixed it */ 3464 if (len == 0) 3637 if (len == 0) { 3465 3638 return 1; 3639 } 3466 3640 3467 3641 errno = e; … … 3471 3645 3472 3646 yid->rxqueue = 3473 3647 y_renew(unsigned char, yid->rxqueue, len + yid->rxlen + 1); 3474 3648 memcpy(yid->rxqueue + yid->rxlen, buf, len); 3475 3649 yid->rxlen += len; … … 3488 3662 yd = y_new0(struct yahoo_data, 1); 3489 3663 3490 if (!yd) 3664 if (!yd) { 3491 3665 return 0; 3666 } 3492 3667 3493 3668 yd->user = strdup(username); … … 3526 3701 char *host = yss->pager_host; 3527 3702 3528 if (!host) 3703 if (!host) { 3529 3704 host = yss->pager_host_list[ccd->server_i]; 3705 } 3530 3706 3531 3707 yss->pager_port = fallback_ports[ccd->i++]; 3532 tag = YAHOO_CALLBACK (ext_yahoo_connect_async) (yd->3533 3534 3535 3536 if (tag > 0) 3708 tag = YAHOO_CALLBACK (ext_yahoo_connect_async) (yd-> 3709 client_id, host, yss->pager_port, 3710 yahoo_connected, ccd, 0); 3711 3712 if (tag > 0) { 3537 3713 ccd->tag = tag; 3714 } 3538 3715 } else if (yss->pager_host_list 3539 3716 && yss->pager_host_list[ccd->server_i]) { 3540 3717 3541 3718 /* Get back to the default port */ … … 3545 3722 3546 3723 ccd->i = 0; 3547 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, 3548 yss->pager_host_list[ccd->server_i], yss->pager_port, 3549 yahoo_connected, ccd, 0); 3724 tag = YAHOO_CALLBACK (ext_yahoo_connect_async) (yd->client_id, 3725 yss->pager_host_list[ccd->server_i], 3726 yss->pager_port, 3727 yahoo_connected, ccd, 0); 3550 3728 } else { 3551 3729 FREE(ccd); 3552 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id,3553 3730 YAHOO_CALLBACK (ext_yahoo_login_response) (yd->client_id, 3731 YAHOO_LOGIN_SOCK, NULL); 3554 3732 } 3555 3733 return; … … 3559 3737 3560 3738 /* fd == NULL && error == 0 means connect was cancelled */ 3561 if (!fd) 3562 return; 3739 if (!fd) { 3740 return; 3741 } 3563 3742 3564 3743 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YPACKET_STATUS_DEFAULT, 3565 3744 yd->session_id); 3566 3745 NOTICE(("Sending initial packet")); 3567 3746 … … 3576 3755 3577 3756 yid->read_tag = 3578 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id,3579 3757 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd->client_id, 3758 yid->fd, YAHOO_INPUT_READ, yid); 3580 3759 } 3581 3760 … … 3583 3762 { 3584 3763 struct yahoo_input_data *yid = 3585 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3586 if (!yid) 3764 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3765 3766 if (!yid) { 3587 3767 return 0; 3588 else3768 } else { 3589 3769 return yid->fd; 3770 } 3590 3771 } 3591 3772 … … 3598 3779 3599 3780 void yahoo_send_im(int id, const char *from, const char *who, const char *what, 3600 3781 int utf8, int picture) 3601 3782 { 3602 3783 struct yahoo_input_data *yid = 3603 3784 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3604 3785 struct yahoo_packet *pkt = NULL; 3605 3786 struct yahoo_data *yd; 3606 3787 char pic_str[10]; 3607 3788 3608 if (!yid) 3609 return; 3789 if (!yid) { 3790 return; 3791 } 3610 3792 3611 3793 yd = yid->yd; 3612 3794 3613 3795 pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, (enum ypacket_status) YAHOO_STATUS_OFFLINE, 3614 3796 yd->session_id); 3615 3797 3616 3798 snprintf(pic_str, sizeof(pic_str), "%d", picture); 3617 3799 3618 if (from && strcmp(from, yd->user)) 3800 if (from && strcmp(from, yd->user)) { 3619 3801 yahoo_packet_hash(pkt, 0, yd->user); 3802 } 3620 3803 yahoo_packet_hash(pkt, 1, from ? from : yd->user); 3621 3804 yahoo_packet_hash(pkt, 5, who); 3622 3805 yahoo_packet_hash(pkt, 14, what); 3623 3806 3624 if (utf8) 3807 if (utf8) { 3625 3808 yahoo_packet_hash(pkt, 97, "1"); 3626 3627 yahoo_packet_hash(pkt, 63, ";0"); /* imvironment name; or ;0 */ 3809 } 3810 3811 yahoo_packet_hash(pkt, 63, ";0"); /* imvironment name; or ;0 */ 3628 3812 yahoo_packet_hash(pkt, 64, "0"); 3629 3813 yahoo_packet_hash(pkt, 206, pic_str); … … 3637 3821 { 3638 3822 struct yahoo_input_data *yid = 3639 3823 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3640 3824 struct yahoo_data *yd; 3641 3825 struct yahoo_packet *pkt = NULL; 3642 if (!yid) 3643 return; 3826 3827 if (!yid) { 3828 return; 3829 } 3644 3830 3645 3831 yd = yid->yd; 3646 3832 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YPACKET_STATUS_NOTIFY, 3647 3833 yd->session_id); 3648 3834 3649 3835 yahoo_packet_hash(pkt, 5, who); … … 3661 3847 { 3662 3848 struct yahoo_input_data *yid = 3663 3849 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3664 3850 struct yahoo_data *yd; 3665 3851 struct yahoo_packet *pkt = NULL; … … 3667 3853 char s[4]; 3668 3854 3669 if (!yid) 3670 return; 3855 if (!yid) { 3856 return; 3857 } 3671 3858 3672 3859 yd = yid->yd; … … 3678 3865 if (yd->current_status == YAHOO_STATUS_INVISIBLE) { 3679 3866 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, 3680 3867 (enum ypacket_status) YAHOO_STATUS_AVAILABLE, 0); 3681 3868 yahoo_packet_hash(pkt, 13, "2"); 3682 3869 yahoo_send_packet(yid, pkt, 0); … … 3687 3874 3688 3875 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, 3689 3876 yd->current_status, yd->session_id); 3690 3877 snprintf(s, sizeof(s), "%d", yd->current_status); 3691 3878 yahoo_packet_hash(pkt, 10, s); 3692 3879 yahoo_packet_hash(pkt, 19, msg && state == YAHOO_STATUS_CUSTOM ? msg : ""); 3693 yahoo_packet_hash(pkt, 47, (away == 2) ? "2": (away) ?"1":"0");3880 yahoo_packet_hash(pkt, 47, (away == 2) ? "2" : (away) ? "1" : "0"); 3694 3881 yahoo_send_packet(yid, pkt, 0); 3695 3882 yahoo_packet_free(pkt); … … 3697 3884 if (old_status == YAHOO_STATUS_INVISIBLE) { 3698 3885 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, 3699 3886 (enum ypacket_status) YAHOO_STATUS_AVAILABLE, 0); 3700 3887 yahoo_packet_hash(pkt, 13, "1"); 3701 3888 yahoo_send_packet(yid, pkt, 0); … … 3707 3894 { 3708 3895 struct yahoo_input_data *yid = 3709 3896 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3710 3897 struct yahoo_data *yd; 3711 3898 struct yahoo_packet *pkt = NULL; 3712 3899 3713 if (!yid) 3714 return; 3900 if (!yid) { 3901 return; 3902 } 3715 3903 yd = yid->yd; 3716 3904 … … 3722 3910 connection reset will hopefully be clear enough. */ 3723 3911 pkt = yahoo_packet_new(YAHOO_SERVICE_LOGOFF, 3724 3912 YPACKET_STATUS_DEFAULT, yd->session_id); 3725 3913 yd->current_status = -1; 3726 3914 … … 3732 3920 3733 3921 /* do { 3734 3735 3922 yahoo_input_close(yid); 3923 } while((yid = find_input_by_id(id)));*/ 3736 3924 3737 3925 } … … 3741 3929 { 3742 3930 struct yahoo_input_data *yid = 3743 3931 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3744 3932 struct yahoo_data *yd; 3745 3933 struct yahoo_packet *pkt = NULL; 3746 3934 3747 if (!yid) 3748 return; 3935 if (!yid) { 3936 return; 3937 } 3749 3938 yd = yid->yd; 3750 3939 3751 3940 pkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YPACKET_STATUS_DEFAULT, 3752 3941 yd->session_id); 3753 3942 yahoo_packet_hash(pkt, 1, yd->user); 3754 3943 if (pkt) { … … 3762 3951 { 3763 3952 struct yahoo_input_data *yid = data; 3953 3764 3954 if (fd == NULL || error) { 3765 3955 inputs = y_list_remove(inputs, yid); … … 3770 3960 yid->fd = fd; 3771 3961 yid->read_tag = 3772 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd,3773 3962 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd->client_id, fd, 3963 YAHOO_INPUT_READ, yid); 3774 3964 } 3775 3965 … … 3783 3973 char buff[2048]; 3784 3974 3785 if (!yd) 3786 return; 3975 if (!yd) { 3976 return; 3977 } 3787 3978 3788 3979 yid = y_new0(struct yahoo_input_data, 1); … … 3793 3984 3794 3985 snprintf(url, 1024, 3795 3796 3986 "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us" 3987 "&diffs=1&t=0&tags=short&rt=0&prog-ver=8.1.0.249&useutf8=1&legenc=codepage-1252"); 3797 3988 3798 3989 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); … … 3801 3992 3802 3993 yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, 3803 3994 _yahoo_http_connected, yid); 3804 3995 } 3805 3996 … … 3821 4012 } 3822 4013 3823 YAHOO_CALLBACK (ext_yahoo_write) (fd, buff, strlen(buff));4014 YAHOO_CALLBACK (ext_yahoo_write) (fd, buff, strlen(buff)); 3824 4015 3825 4016 yid->fd = fd; 3826 4017 yid->read_tag = 3827 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd,3828 4018 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd->client_id, fd, 4019 YAHOO_INPUT_READ, yid); 3829 4020 3830 4021 FREE(buff); … … 3843 4034 int size = 0; 3844 4035 3845 if (!yd) 3846 return; 4036 if (!yd) { 4037 return; 4038 } 3847 4039 3848 4040 yid = y_new0(struct yahoo_input_data, 1); … … 3850 4042 yid->yd = yd; 3851 4043 3852 if (yab->yid)4044 if (yab->yid) { 3853 4045 size = snprintf(post, sizeof(post), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 3854 3855 3856 "</ab>", yd->user, 9, yab->yid,/* Don't know why */3857 yab->id, yab->nname?yab->nname:"");3858 else4046 "<ab k=\"%s\" cc=\"%d\">" 4047 "<ct id=\"%d\" e=\"1\" yi=\"%s\" nn=\"%s\" />" 4048 "</ab>", yd->user, 9, yab->yid, /* Don't know why */ 4049 yab->id, yab->nname ? yab->nname : ""); 4050 } else { 3859 4051 size = snprintf(post, sizeof(post), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 3860 "<ab k=\"%s\" cc=\"%d\">" 3861 "<ct a=\"1\" yi=\"%s\" nn=\"%s\" />" 3862 "</ab>", yd->user, 1, /* Don't know why */ 3863 yab->id, yab->nname?yab->nname:""); 4052 "<ab k=\"%s\" cc=\"%d\">" 4053 "<ct a=\"1\" yi=\"%s\" nn=\"%s\" />" 4054 "</ab>", yd->user, 1, /* Don't know why */ 4055 yab->id, yab->nname ? yab->nname : ""); 4056 } 3864 4057 3865 4058 yad->yid = yid; … … 3867 4060 3868 4061 strcpy(url, "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us" 3869 4062 "&sync=1&tags=short&noclear=1&useutf8=1&legenc=codepage-1252"); 3870 4063 3871 4064 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); … … 3874 4067 3875 4068 yahoo_http_post(yid->yd->client_id, url, buff, size, 3876 4069 _yahoo_http_post_connected, yad); 3877 4070 } 3878 4071 … … 3880 4073 { 3881 4074 struct yahoo_input_data *yid = 3882 4075 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3883 4076 struct yahoo_data *yd; 3884 4077 struct yahoo_packet *pkt = NULL; 3885 4078 3886 if (!yid) 3887 return; 4079 if (!yid) { 4080 return; 4081 } 3888 4082 yd = yid->yd; 3889 4083 3890 4084 pkt = yahoo_packet_new(active ? YAHOO_SERVICE_IDACT : 3891 4085 YAHOO_SERVICE_IDDEACT, YPACKET_STATUS_DEFAULT, yd->session_id); 3892 4086 yahoo_packet_hash(pkt, 3, identity); 3893 4087 if (pkt) { … … 3900 4094 { 3901 4095 struct yahoo_input_data *yid = 3902 4096 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3903 4097 struct yahoo_data *yd; 3904 4098 struct yahoo_packet *pkt = NULL; 3905 4099 3906 if (!yid) 3907 return; 4100 if (!yid) { 4101 return; 4102 } 3908 4103 yd = yid->yd; 3909 4104 3910 4105 pkt = yahoo_packet_new(YAHOO_SERVICE_USERSTAT, YPACKET_STATUS_DEFAULT, 3911 4106 yd->session_id); 3912 4107 if (pkt) { 3913 4108 yahoo_send_packet(yid, pkt, 0); … … 3920 4115 { 3921 4116 struct yahoo_input_data *yid = 3922 4117 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3923 4118 struct yahoo_data *yd; 3924 4119 struct yahoo_packet *pkt = NULL; 3925 if (!yid) 3926 return; 4120 4121 if (!yid) { 4122 return; 4123 } 3927 4124 yd = yid->yd; 3928 4125 3929 4126 pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YPACKET_STATUS_DEFAULT, 3930 4127 yd->session_id); 3931 4128 yahoo_send_packet(yid, pkt, 0); 3932 4129 yahoo_packet_free(pkt); … … 3937 4134 { 3938 4135 struct yahoo_input_data *yid = 3939 4136 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3940 4137 struct yahoo_data *yd; 3941 4138 struct yahoo_packet *pkt = NULL; 3942 4139 3943 if (!yid) 3944 return; 4140 if (!yid) { 4141 return; 4142 } 3945 4143 3946 4144 yd = yid->yd; 3947 4145 3948 4146 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YPACKET_STATUS_DEFAULT, 3949 4147 yd->session_id); 3950 4148 yahoo_send_packet(yid, pkt, 0); 3951 4149 yahoo_packet_free(pkt); … … 3954 4152 3955 4153 void yahoo_add_buddy(int id, const char *who, const char *group, 3956 4154 const char *msg) 3957 4155 { 3958 4156 struct yahoo_input_data *yid = 3959 4157 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3960 4158 struct yahoo_data *yd; 3961 4159 struct yahoo_packet *pkt; 3962 4160 3963 if (!yid) 3964 return; 4161 if (!yid) { 4162 return; 4163 } 3965 4164 yd = yid->yd; 3966 4165 3967 if (!yd->logged_in) 3968 return; 4166 if (!yd->logged_in) { 4167 return; 4168 } 3969 4169 3970 4170 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YPACKET_STATUS_DEFAULT, 3971 3972 if (msg != NULL) 4171 yd->session_id); 4172 if (msg != NULL) { /* add message/request "it's me add me" */ 3973 4173 yahoo_packet_hash(pkt, 14, msg); 3974 else4174 } else { 3975 4175 yahoo_packet_hash(pkt, 14, ""); 4176 } 3976 4177 yahoo_packet_hash(pkt, 65, group); 3977 4178 yahoo_packet_hash(pkt, 97, "1"); … … 3990 4191 { 3991 4192 struct yahoo_input_data *yid = 3992 4193 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3993 4194 struct yahoo_data *yd; 3994 4195 struct yahoo_packet *pkt = NULL; 3995 4196 3996 if (!yid) 3997 return; 4197 if (!yid) { 4198 return; 4199 } 3998 4200 yd = yid->yd; 3999 4201 4000 4202 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YPACKET_STATUS_DEFAULT, 4001 4203 yd->session_id); 4002 4204 4003 4205 yahoo_packet_hash(pkt, 1, yd->user); … … 4011 4213 { 4012 4214 struct yahoo_input_data *yid = 4013 4215 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4014 4216 struct yahoo_data *yd; 4015 4217 struct yahoo_packet *pkt; 4016 4218 4017 if (!yid) 4018 return; 4219 if (!yid) { 4220 return; 4221 } 4019 4222 yd = yid->yd; 4020 4223 4021 if (!yd->logged_in) 4022 return; 4224 if (!yd->logged_in) { 4225 return; 4226 } 4023 4227 4024 4228 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_AUTHORIZATION, 4025 4229 YPACKET_STATUS_DEFAULT, yd->session_id); 4026 4230 yahoo_packet_hash(pkt, 1, yd->user); 4027 4231 yahoo_packet_hash(pkt, 5, who); 4028 if (reject) 4232 if (reject) { 4029 4233 yahoo_packet_hash(pkt, 13, "2"); 4030 else {4234 } else { 4031 4235 yahoo_packet_hash(pkt, 241, "0"); 4032 4236 yahoo_packet_hash(pkt, 13, "1"); … … 4048 4252 { 4049 4253 struct yahoo_input_data *yid = 4050 4254 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4051 4255 struct yahoo_data *yd; 4052 4256 struct yahoo_packet *pkt; 4053 4257 4054 if (!yid) 4055 return; 4258 if (!yid) { 4259 return; 4260 } 4056 4261 yd = yid->yd; 4057 4262 4058 if (!yd->logged_in) 4059 return; 4263 if (!yd->logged_in) { 4264 return; 4265 } 4060 4266 4061 4267 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, 4062 4268 YPACKET_STATUS_DEFAULT, yd->session_id); 4063 4269 yahoo_packet_hash(pkt, 1, yd->user); 4064 4270 yahoo_packet_hash(pkt, 7, who); … … 4071 4277 { 4072 4278 struct yahoo_input_data *yid = 4073 4279 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4074 4280 struct yahoo_data *yd; 4075 4281 struct yahoo_packet *pkt; 4076 4282 4077 if (!yid) 4078 return; 4283 if (!yid) { 4284 return; 4285 } 4079 4286 yd = yid->yd; 4080 4287 4081 if (!yd->logged_in) 4082 return; 4288 if (!yd->logged_in) { 4289 return; 4290 } 4083 4291 4084 4292 pkt = yahoo_packet_new(YAHOO_SERVICE_STEALTH_PERM, 4085 4293 YPACKET_STATUS_DEFAULT, yd->session_id); 4086 4294 yahoo_packet_hash(pkt, 1, yd->user); 4087 4295 yahoo_packet_hash(pkt, 7, who); … … 4094 4302 4095 4303 void yahoo_change_buddy_group(int id, const char *who, const char *old_group, 4096 4304 const char *new_group) 4097 4305 { 4098 4306 struct yahoo_input_data *yid = 4099 4307 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4100 4308 struct yahoo_data *yd; 4101 4309 struct yahoo_packet *pkt = NULL; 4102 4310 4103 if (!yid) 4104 return; 4311 if (!yid) { 4312 return; 4313 } 4105 4314 yd = yid->yd; 4106 4315 4107 4316 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_CHANGE_GROUP, 4108 4317 YPACKET_STATUS_DEFAULT, yd->session_id); 4109 4318 yahoo_packet_hash(pkt, 1, yd->user); 4110 4319 yahoo_packet_hash(pkt, 302, "240"); … … 4124 4333 { 4125 4334 struct yahoo_input_data *yid = 4126 4335 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4127 4336 struct yahoo_data *yd; 4128 4337 struct yahoo_packet *pkt = NULL; 4129 4338 4130 if (!yid) 4131 return; 4339 if (!yid) { 4340 return; 4341 } 4132 4342 yd = yid->yd; 4133 4343 4134 4344 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, 4135 4345 YPACKET_STATUS_DEFAULT, yd->session_id); 4136 4346 yahoo_packet_hash(pkt, 1, yd->user); 4137 4347 yahoo_packet_hash(pkt, 65, old_group); … … 4143 4353 4144 4354 void yahoo_conference_addinvite(int id, const char *from, const char *who, 4145 4355 const char *room, const YList *members, const char *msg) 4146 4356 { 4147 4357 struct yahoo_input_data *yid = 4148 4358 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4149 4359 struct yahoo_data *yd; 4150 4360 struct yahoo_packet *pkt; 4151 4361 4152 if (!yid) 4153 return; 4362 if (!yid) { 4363 return; 4364 } 4154 4365 yd = yid->yd; 4155 4366 4156 4367 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, 4157 4368 YPACKET_STATUS_DEFAULT, yd->session_id); 4158 4369 4159 4370 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); … … 4163 4374 yahoo_packet_hash(pkt, 13, "0"); 4164 4375 for (; members; members = members->next) { 4165 yahoo_packet_hash(pkt, 52, (char *) members->data);4166 yahoo_packet_hash(pkt, 53, (char *) members->data);4376 yahoo_packet_hash(pkt, 52, (char *) members->data); 4377 yahoo_packet_hash(pkt, 53, (char *) members->data); 4167 4378 } 4168 4379 /* 52, 53 -> other members? */ … … 4175 4386 4176 4387 void yahoo_conference_invite(int id, const char *from, YList *who, 4177 4388 const char *room, const char *msg) 4178 4389 { 4179 4390 struct yahoo_input_data *yid = 4180 4391 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4181 4392 struct yahoo_data *yd; 4182 4393 struct yahoo_packet *pkt; 4183 4394 4184 if (!yid) 4185 return; 4395 if (!yid) { 4396 return; 4397 } 4186 4398 yd = yid->yd; 4187 4399 4188 4400 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFINVITE, YPACKET_STATUS_DEFAULT, 4189 4401 yd->session_id); 4190 4402 4191 4403 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4192 4404 yahoo_packet_hash(pkt, 50, yd->user); 4193 4405 for (; who; who = who->next) { 4194 yahoo_packet_hash(pkt, 52, (char *) who->data);4406 yahoo_packet_hash(pkt, 52, (char *) who->data); 4195 4407 } 4196 4408 yahoo_packet_hash(pkt, 57, room); … … 4204 4416 4205 4417 void yahoo_conference_logon(int id, const char *from, YList *who, 4206 4418 const char *room) 4207 4419 { 4208 4420 struct yahoo_input_data *yid = 4209 4421 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4210 4422 struct yahoo_data *yd; 4211 4423 struct yahoo_packet *pkt; 4212 4424 4213 if (!yid) 4214 return; 4425 if (!yid) { 4426 return; 4427 } 4215 4428 yd = yid->yd; 4216 4429 4217 4430 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YPACKET_STATUS_DEFAULT, 4218 4431 yd->session_id); 4219 4432 4220 4433 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4221 4434 yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); 4222 4435 yahoo_packet_hash(pkt, 57, room); 4223 for (; who; who = who->next) 4224 yahoo_packet_hash(pkt, 3, (char *)who->data); 4436 for (; who; who = who->next) { 4437 yahoo_packet_hash(pkt, 3, (char *) who->data); 4438 } 4225 4439 4226 4440 yahoo_send_packet(yid, pkt, 0); … … 4230 4444 4231 4445 void yahoo_conference_decline(int id, const char *from, YList *who, 4232 4446 const char *room, const char *msg) 4233 4447 { 4234 4448 struct yahoo_input_data *yid = 4235 4449 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4236 4450 struct yahoo_data *yd; 4237 4451 struct yahoo_packet *pkt; 4238 4452 4239 if (!yid) 4240 return; 4453 if (!yid) { 4454 return; 4455 } 4241 4456 yd = yid->yd; 4242 4457 4243 4458 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFDECLINE, 4244 4459 YPACKET_STATUS_DEFAULT, yd->session_id); 4245 4460 4246 4461 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4247 4462 yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); 4248 for (; who; who = who->next) 4249 yahoo_packet_hash(pkt, 3, (char *)who->data); 4463 for (; who; who = who->next) { 4464 yahoo_packet_hash(pkt, 3, (char *) who->data); 4465 } 4250 4466 yahoo_packet_hash(pkt, 57, room); 4251 4467 yahoo_packet_hash(pkt, 14, msg); … … 4257 4473 4258 4474 void yahoo_conference_logoff(int id, const char *from, YList *who, 4259 4475 const char *room) 4260 4476 { 4261 4477 struct yahoo_input_data *yid = 4262 4478 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4263 4479 struct yahoo_data *yd; 4264 4480 struct yahoo_packet *pkt; 4265 4481 4266 if (!yid) 4267 return; 4482 if (!yid) { 4483 return; 4484 } 4268 4485 yd = yid->yd; 4269 4486 4270 4487 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YPACKET_STATUS_DEFAULT, 4271 4488 yd->session_id); 4272 4489 4273 4490 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4274 4491 yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); 4275 for (; who; who = who->next) 4276 yahoo_packet_hash(pkt, 3, (char *)who->data); 4492 for (; who; who = who->next) { 4493 yahoo_packet_hash(pkt, 3, (char *) who->data); 4494 } 4277 4495 4278 4496 yahoo_packet_hash(pkt, 57, room); … … 4284 4502 4285 4503 void yahoo_conference_message(int id, const char *from, YList *who, 4286 4504 const char *room, const char *msg, int utf8) 4287 4505 { 4288 4506 struct yahoo_input_data *yid = 4289 4507 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4290 4508 struct yahoo_data *yd; 4291 4509 struct yahoo_packet *pkt; 4292 4510 4293 if (!yid) 4294 return; 4511 if (!yid) { 4512 return; 4513 } 4295 4514 yd = yid->yd; 4296 4515 4297 4516 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YPACKET_STATUS_DEFAULT, 4298 4517 yd->session_id); 4299 4518 4300 4519 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4301 4520 yahoo_packet_hash(pkt, 53, (from ? from : yd->user)); 4302 for (; who; who = who->next) 4303 yahoo_packet_hash(pkt, 53, (char *)who->data); 4521 for (; who; who = who->next) { 4522 yahoo_packet_hash(pkt, 53, (char *) who->data); 4523 } 4304 4524 4305 4525 yahoo_packet_hash(pkt, 57, room); 4306 4526 yahoo_packet_hash(pkt, 14, msg); 4307 4527 4308 if (utf8) 4528 if (utf8) { 4309 4529 yahoo_packet_hash(pkt, 97, "1"); 4530 } 4310 4531 4311 4532 yahoo_send_packet(yid, pkt, 0); … … 4322 4543 char buff[1024]; 4323 4544 4324 if (!yd) 4325 return; 4545 if (!yd) { 4546 return; 4547 } 4326 4548 4327 4549 yid = y_new0(struct yahoo_input_data, 1); … … 4331 4553 if (chatroomid == 0) { 4332 4554 snprintf(url, 1024, 4333 4555 "http://insider.msg.yahoo.com/ycontent/?chatcat=0"); 4334 4556 } else { 4335 4557 snprintf(url, 1024, 4336 4337 4558 "http://insider.msg.yahoo.com/ycontent/?chatroom_%d=0", 4559 chatroomid); 4338 4560 } 4339 4561 … … 4343 4565 4344 4566 yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, 4345 4567 _yahoo_http_connected, yid); 4346 4568 } 4347 4569 4348 4570 void yahoo_chat_logon(int id, const char *from, const char *room, 4349 4571 const char *roomid) 4350 4572 { 4351 4573 struct yahoo_input_data *yid = 4352 4574 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4353 4575 struct yahoo_data *yd; 4354 4576 struct yahoo_packet *pkt; 4355 4577 4356 if (!yid) 4357 return; 4578 if (!yid) { 4579 return; 4580 } 4358 4581 4359 4582 yd = yid->yd; 4360 4583 4361 4584 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YPACKET_STATUS_DEFAULT, 4362 4585 yd->session_id); 4363 4586 4364 4587 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); … … 4371 4594 4372 4595 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YPACKET_STATUS_DEFAULT, 4373 4596 yd->session_id); 4374 4597 4375 4598 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4376 4599 yahoo_packet_hash(pkt, 104, room); 4377 4600 yahoo_packet_hash(pkt, 129, roomid); 4378 yahoo_packet_hash(pkt, 62, "2"); 4601 yahoo_packet_hash(pkt, 62, "2"); /* ??? */ 4379 4602 4380 4603 yahoo_send_packet(yid, pkt, 0); … … 4384 4607 4385 4608 void yahoo_chat_message(int id, const char *from, const char *room, 4386 4609 const char *msg, const int msgtype, const int utf8) 4387 4610 { 4388 4611 struct yahoo_input_data *yid = 4389 4612 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4390 4613 struct yahoo_data *yd; 4391 4614 struct yahoo_packet *pkt; 4392 4615 char buf[2]; 4393 4616 4394 if (!yid) 4395 return; 4617 if (!yid) { 4618 return; 4619 } 4396 4620 4397 4621 yd = yid->yd; 4398 4622 4399 4623 pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YPACKET_STATUS_DEFAULT, 4400 4624 yd->session_id); 4401 4625 4402 4626 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); … … 4407 4631 yahoo_packet_hash(pkt, 124, buf); 4408 4632 4409 if (utf8) 4633 if (utf8) { 4410 4634 yahoo_packet_hash(pkt, 97, "1"); 4635 } 4411 4636 4412 4637 yahoo_send_packet(yid, pkt, 0); … … 4418 4643 { 4419 4644 struct yahoo_input_data *yid = 4420 4645 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4421 4646 struct yahoo_data *yd; 4422 4647 struct yahoo_packet *pkt; 4423 4648 4424 if (!yid) 4425 return; 4649 if (!yid) { 4650 return; 4651 } 4426 4652 4427 4653 yd = yid->yd; 4428 4654 4429 4655 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, YPACKET_STATUS_DEFAULT, 4430 4656 yd->session_id); 4431 4657 4432 4658 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); … … 4440 4666 { 4441 4667 struct yahoo_input_data *yid = 4442 4668 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4443 4669 struct yahoo_data *yd; 4444 4670 struct yahoo_packet *pkt; 4445 4671 4446 if (!yid) 4447 return; 4672 if (!yid) { 4673 return; 4674 } 4448 4675 4449 4676 yd = yid->yd; 4450 4677 4451 4678 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YPACKET_STATUS_DEFAULT, 4452 4679 0); 4453 4680 yahoo_packet_hash(pkt, 4, yd->user); 4454 4681 yahoo_packet_hash(pkt, 5, who); … … 4460 4687 4461 4688 void yahoo_send_picture_info(int id, const char *who, const char *url, 4462 4689 int checksum) 4463 4690 { 4464 4691 struct yahoo_input_data *yid = 4465 4692 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4466 4693 struct yahoo_data *yd; 4467 4694 struct yahoo_packet *pkt; 4468 4695 char checksum_str[10]; 4469 4696 4470 if (!yid) 4471 return; 4697 if (!yid) { 4698 return; 4699 } 4472 4700 4473 4701 yd = yid->yd; … … 4476 4704 4477 4705 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YPACKET_STATUS_DEFAULT, 4478 4706 0); 4479 4707 yahoo_packet_hash(pkt, 1, yd->user); 4480 4708 yahoo_packet_hash(pkt, 4, yd->user); … … 4491 4719 { 4492 4720 struct yahoo_input_data *yid = 4493 4721 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4494 4722 struct yahoo_data *yd; 4495 4723 struct yahoo_packet *pkt; 4496 4724 char type_str[10]; 4497 4725 4498 if (!yid) 4499 return; 4726 if (!yid) { 4727 return; 4728 } 4500 4729 4501 4730 yd = yid->yd; … … 4504 4733 4505 4734 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, 4506 4735 YPACKET_STATUS_DEFAULT, 0); 4507 4736 yahoo_packet_hash(pkt, 1, yd->user); 4508 4737 yahoo_packet_hash(pkt, 5, who); … … 4516 4745 { 4517 4746 struct yahoo_input_data *yid = 4518 4747 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4519 4748 struct yahoo_data *yd; 4520 4749 struct yahoo_packet *pkt; 4521 4750 char checksum_str[10]; 4522 4751 4523 if (!yid) 4524 return; 4752 if (!yid) { 4753 return; 4754 } 4525 4755 4526 4756 yd = yid->yd; … … 4529 4759 4530 4760 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, 4531 4761 YPACKET_STATUS_DEFAULT, 0); 4532 4762 yahoo_packet_hash(pkt, 1, yd->user); 4533 if (who != 0) 4763 if (who != 0) { 4534 4764 yahoo_packet_hash(pkt, 5, who); 4765 } 4535 4766 yahoo_packet_hash(pkt, 192, checksum_str); 4536 4767 yahoo_packet_hash(pkt, 212, "1"); … … 4543 4774 { 4544 4775 struct yahoo_input_data *yid = 4545 4546 4547 if (yid) 4776 find_input_by_id_and_webcam_user(id, who); 4777 4778 if (yid) { 4548 4779 yahoo_input_close(yid); 4780 } 4549 4781 } 4550 4782 … … 4552 4784 { 4553 4785 struct yahoo_input_data *yid = 4554 4786 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4555 4787 struct yahoo_data *yd; 4556 4788 struct yahoo_packet *pkt; 4557 4789 4558 if (!yid) 4559 return; 4560 4561 /* 4790 if (!yid) { 4791 return; 4792 } 4793 4794 /* 4562 4795 * add the user to the queue. this is a dirty hack, since 4563 4796 * the yahoo server doesn't tell us who's key it's returning, 4564 * we have to just hope that it sends back keys in the same 4797 * we have to just hope that it sends back keys in the same 4565 4798 * order that we request them. 4566 4799 * The queue is popped in yahoo_process_webcam_key … … 4571 4804 4572 4805 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBCAM, YPACKET_STATUS_DEFAULT, 4573 4806 yd->session_id); 4574 4807 4575 4808 yahoo_packet_hash(pkt, 1, yd->user); 4576 if (who != NULL) 4809 if (who != NULL) { 4577 4810 yahoo_packet_hash(pkt, 5, who); 4811 } 4578 4812 yahoo_send_packet(yid, pkt, 0); 4579 4813 … … 4582 4816 4583 4817 void yahoo_webcam_send_image(int id, unsigned char *image, unsigned int length, 4584 4818 unsigned int timestamp) 4585 4819 { 4586 4820 struct yahoo_input_data *yid = 4587 4821 find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); 4588 4822 unsigned char *packet; 4589 4823 unsigned char header_len = 13; 4590 4824 unsigned int pos = 0; 4591 4825 4592 if (!yid) 4593 return; 4826 if (!yid) { 4827 return; 4828 } 4594 4829 4595 4830 packet = y_new0(unsigned char, header_len); … … 4597 4832 packet[pos++] = header_len; 4598 4833 packet[pos++] = 0; 4599 packet[pos++] = 5; 4834 packet[pos++] = 5; /* version byte?? */ 4600 4835 packet[pos++] = 0; 4601 4836 pos += yahoo_put32(packet + pos, length); 4602 packet[pos++] = 2; 4837 packet[pos++] = 2; /* packet type, image */ 4603 4838 pos += yahoo_put32(packet + pos, timestamp); 4604 4839 yahoo_add_to_send_queue(yid, packet, header_len); 4605 4840 FREE(packet); 4606 4841 4607 if (length) 4842 if (length) { 4608 4843 yahoo_add_to_send_queue(yid, image, length); 4844 } 4609 4845 } 4610 4846 … … 4612 4848 { 4613 4849 struct yahoo_input_data *yid = 4614 4850 find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); 4615 4851 char *packet = NULL; 4616 4852 char *data = NULL; … … 4619 4855 unsigned int len = 0; 4620 4856 4621 if (!yid) 4622 return; 4857 if (!yid) { 4858 return; 4859 } 4623 4860 4624 4861 data = strdup("u="); 4625 data = y_string_append(data, (char *) who);4862 data = y_string_append(data, (char *) who); 4626 4863 data = y_string_append(data, "\r\n"); 4627 4864 len = strlen(data); … … 4630 4867 packet[pos++] = header_len; 4631 4868 packet[pos++] = 0; 4632 packet[pos++] = 5; 4869 packet[pos++] = 5; /* version byte?? */ 4633 4870 packet[pos++] = 0; 4634 4871 pos += yahoo_put32(packet + pos, len); 4635 packet[pos++] = 0; 4872 packet[pos++] = 0; /* packet type */ 4636 4873 pos += yahoo_put32(packet + pos, accept); 4637 4874 memcpy(packet + pos, data, len); … … 4644 4881 { 4645 4882 struct yahoo_input_data *yid = 4646 4883 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4647 4884 struct yahoo_packet *pkt; 4648 4885 4649 if (!yid) 4650 return; 4886 if (!yid) { 4887 return; 4888 } 4651 4889 4652 4890 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YPACKET_STATUS_NOTIFY, 4653 4891 yid->yd->session_id); 4654 4892 4655 4893 yahoo_packet_hash(pkt, 49, "WEBCAMINVITE"); … … 4664 4902 4665 4903 static void yahoo_search_internal(int id, int t, const char *text, int g, 4666 4904 int ar, int photo, int yahoo_only, int startpos, int total) 4667 4905 { 4668 4906 struct yahoo_data *yd = find_conn_by_id(id); … … 4672 4910 char *ctext, *p; 4673 4911 4674 if (!yd) 4675 return; 4912 if (!yd) { 4913 return; 4914 } 4676 4915 4677 4916 yid = y_new0(struct yahoo_input_data, 1); … … 4685 4924 4686 4925 snprintf(buff, sizeof(buff), "&.sq=%%20&.tt=%d&.ss=%d", total, 4687 4926 startpos); 4688 4927 4689 4928 ctext = strdup(text); 4690 while ((p = strchr(ctext, ' '))) 4929 while ((p = strchr(ctext, ' '))) { 4691 4930 *p = '+'; 4931 } 4692 4932 4693 4933 snprintf(url, 1024, 4694 4695 4696 4934 "http://members.yahoo.com/interests?.oc=m&.kw=%s&.sb=%d&.g=%d&.ar=0%s%s%s", 4935 ctext, t, g, photo ? "&.p=y" : "", yahoo_only ? "&.pg=y" : "", 4936 startpos ? buff : ""); 4697 4937 4698 4938 FREE(ctext); … … 4702 4942 inputs = y_list_prepend(inputs, yid); 4703 4943 yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, 4704 4944 _yahoo_http_connected, yid); 4705 4945 } 4706 4946 4707 4947 void yahoo_search(int id, enum yahoo_search_type t, const char *text, 4708 4709 4948 enum yahoo_search_gender g, enum yahoo_search_agerange ar, int photo, 4949 int yahoo_only) 4710 4950 { 4711 4951 struct yahoo_input_data *yid = 4712 4952 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4713 4953 struct yahoo_search_state *yss; 4714 4954 4715 if (!yid) 4716 return; 4717 4718 if (!yid->ys) 4955 if (!yid) { 4956 return; 4957 } 4958 4959 if (!yid->ys) { 4719 4960 yid->ys = y_new0(struct yahoo_search_state, 1); 4961 } 4720 4962 4721 4963 yss = yid->ys; … … 4735 4977 { 4736 4978 struct yahoo_input_data *yid = 4737 4979 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4738 4980 struct yahoo_search_state *yss; 4739 4981 4740 if (!yid || !yid->ys) 4741 return; 4982 if (!yid || !yid->ys) { 4983 return; 4984 } 4742 4985 4743 4986 yss = yid->ys; 4744 4987 4745 if (start == -1) 4988 if (start == -1) { 4746 4989 start = yss->lsearch_nstart + yss->lsearch_nfound; 4990 } 4747 4991 4748 4992 yahoo_search_internal(id, yss->lsearch_type, yss->lsearch_text, 4749 4750 4751 4993 yss->lsearch_gender, yss->lsearch_agerange, 4994 yss->lsearch_photo, yss->lsearch_yahoo_only, 4995 start, yss->lsearch_ntotal); 4752 4996 } 4753 4997 4754 4998 void yahoo_send_picture(int id, const char *name, unsigned long size, 4755 4999 yahoo_get_fd_callback callback, void *data) 4756 5000 { 4757 5001 /* Not Implemented */ … … 4796 5040 out[23] = '$'; 4797 5041 out[22] = '$'; 4798 5042 4799 5043 for (i = 0; i < 22; i++) { 4800 if (r == 0)5044 if (r == 0) { 4801 5045 r = rand(); 4802 4803 c = r%61; 4804 4805 if(c<26) 5046 } 5047 5048 c = r % 61; 5049 5050 if (c < 26) { 4806 5051 out[i] = c + 'a'; 4807 else if (c<52)5052 } else if (c < 52) { 4808 5053 out[i] = c - 26 + 'A'; 4809 else5054 } else { 4810 5055 out[i] = c - 52 + '0'; 5056 } 4811 5057 4812 5058 r /= 61; … … 4819 5065 static int _are_same_id(const void *sfd1, const void *id) 4820 5066 { 4821 return strcmp(((struct send_file_data *) sfd1)->id, (char *)id);5067 return strcmp(((struct send_file_data *) sfd1)->id, (char *) id); 4822 5068 } 4823 5069 4824 5070 static int _are_same_yid(const void *sfd1, const void *yid) 4825 5071 { 4826 if (((struct send_file_data *)sfd1)->yid == yid)5072 if (((struct send_file_data *) sfd1)->yid == yid) { 4827 5073 return 0; 4828 else5074 } else { 4829 5075 return 1; 5076 } 4830 5077 } 4831 5078 … … 4833 5080 { 4834 5081 YList *l = y_list_find_custom(active_file_transfers, id, 4835 _are_same_id); 4836 4837 if(l) 4838 return (struct send_file_data *)l->data; 4839 5082 _are_same_id); 5083 5084 if (l) { 5085 return (struct send_file_data *) l->data; 5086 } 5087 4840 5088 return NULL; 4841 5089 } … … 4844 5092 { 4845 5093 YList *l = y_list_find_custom(active_file_transfers, yid, 4846 _are_same_yid); 4847 4848 if(l) 4849 return (struct send_file_data *)l->data; 4850 5094 _are_same_yid); 5095 5096 if (l) { 5097 return (struct send_file_data *) l->data; 5098 } 5099 4851 5100 return NULL; 4852 5101 } … … 4859 5108 static void yahoo_remove_active_transfer(struct send_file_data *sfd) 4860 5109 { 4861 if (sfd == NULL) 4862 return; 4863 5110 if (sfd == NULL) { 5111 return; 5112 } 5113 4864 5114 active_file_transfers = y_list_remove(active_file_transfers, sfd); 4865 5115 free(sfd->id); … … 4885 5135 yid->fd = fd; 4886 5136 yid->read_tag = 4887 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd,4888 5137 YAHOO_CALLBACK (ext_yahoo_add_handler) (yid->yd->client_id, fd, 5138 YAHOO_INPUT_READ, yid); 4889 5139 } 4890 5140 4891 5141 static void yahoo_file_transfer_upload(struct yahoo_data *yd, 4892 5142 struct send_file_data *sfd) 4893 5143 { 4894 5144 char url[256]; … … 4909 5159 recv_enc = yahoo_urlencode(sfd->who); 4910 5160 4911 snprintf(url, sizeof(url), 4912 4913 5161 snprintf(url, sizeof(url), 5162 "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, 5163 token_enc, sender_enc, recv_enc); 4914 5164 4915 5165 snprintf(buff, sizeof(buff), "T=%s; Y=%s", yd->cookie_t, yd->cookie_y); 4916 5166 4917 5167 yahoo_http_post(yd->client_id, url, buff, sfd->size, 4918 5168 _yahoo_ft_upload_connected, sfd); 4919 5169 4920 5170 FREE(token_enc); … … 4924 5174 4925 5175 static void yahoo_init_ft_recv(struct yahoo_data *yd, 4926 5176 struct send_file_data *sfd) 4927 5177 { 4928 5178 char url[256]; … … 4943 5193 recv_enc = yahoo_urlencode(yd->user); 4944 5194 4945 snprintf(url, sizeof(url), 4946 4947 5195 snprintf(url, sizeof(url), 5196 "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, 5197 token_enc, sender_enc, recv_enc); 4948 5198 4949 5199 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); 4950 5200 4951 5201 yahoo_http_head(yid->yd->client_id, url, buff, 0, NULL, 4952 5202 _yahoo_http_connected, yid); 4953 5203 4954 5204 FREE(token_enc); … … 4958 5208 4959 5209 static void yahoo_file_transfer_accept(struct yahoo_input_data *yid, 4960 5210 struct send_file_data *sfd) 4961 5211 { 4962 5212 struct yahoo_packet *pkt; 4963 5213 4964 5214 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, 4965 5215 YPACKET_STATUS_DEFAULT, yid->yd->session_id); 4966 5216 4967 5217 yahoo_packet_hash(pkt, 1, yid->yd->user); … … 4980 5230 4981 5231 static void yahoo_process_filetransferaccept(struct yahoo_input_data *yid, 4982 5232 struct yahoo_packet *pkt) 4983 5233 { 4984 5234 YList *l; … … 5016 5266 5017 5267 yahoo_file_transfer_upload(yid->yd, sfd); 5018 } 5019 else { 5020 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5021 (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, 5022 sfd ? sfd->data : NULL); 5268 } else { 5269 YAHOO_CALLBACK (ext_yahoo_file_transfer_done) 5270 (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, 5271 sfd ? sfd->data : NULL); 5023 5272 5024 5273 yahoo_remove_active_transfer(sfd); … … 5027 5276 5028 5277 static void yahoo_process_filetransferinfo(struct yahoo_input_data *yid, 5029 5278 struct yahoo_packet *pkt) 5030 5279 { 5031 5280 YList *l; … … 5070 5319 5071 5320 yahoo_file_transfer_accept(yid, sfd); 5072 } 5073 else { 5074 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5075 (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, 5076 sfd ? sfd->data : NULL); 5321 } else { 5322 YAHOO_CALLBACK (ext_yahoo_file_transfer_done) 5323 (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, 5324 sfd ? sfd->data : NULL); 5077 5325 5078 5326 yahoo_remove_active_transfer(sfd); … … 5081 5329 5082 5330 static void yahoo_send_filetransferinfo(struct yahoo_data *yd, 5083 5331 struct send_file_data *sfd) 5084 5332 { 5085 5333 struct yahoo_input_data *yid; … … 5087 5335 5088 5336 yid = find_input_by_id_and_type(yd->client_id, YAHOO_CONNECTION_PAGER); 5089 sfd->ip_addr = YAHOO_CALLBACK (ext_yahoo_get_ip_addr)("relay.yahoo.com");5337 sfd->ip_addr = YAHOO_CALLBACK (ext_yahoo_get_ip_addr)("relay.yahoo.com"); 5090 5338 5091 5339 if (!sfd->ip_addr) { 5092 YAHOO_CALLBACK (ext_yahoo_file_transfer_done)5093 5340 YAHOO_CALLBACK (ext_yahoo_file_transfer_done) 5341 (yd->client_id, YAHOO_FILE_TRANSFER_RELAY, sfd->data); 5094 5342 5095 5343 yahoo_remove_active_transfer(sfd); … … 5099 5347 5100 5348 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFERINFO, 5101 5349 YPACKET_STATUS_DEFAULT, yd->session_id); 5102 5350 5103 5351 yahoo_packet_hash(pkt, 1, yd->user); … … 5114 5362 5115 5363 static void yahoo_process_filetransfer(struct yahoo_input_data *yid, 5116 5364 struct yahoo_packet *pkt) 5117 5365 { 5118 5366 YList *l; … … 5167 5415 /* Received a FT request from buddy */ 5168 5416 sfd = y_new0(struct send_file_data, 1); 5169 5417 5170 5418 sfd->client_id = yd->client_id; 5171 5419 sfd->id = strdup(id); … … 5173 5421 sfd->filename = strdup(filename); 5174 5422 sfd->size = size; 5175 5423 5176 5424 yahoo_add_active_transfer(sfd); 5177 5425 5178 YAHOO_CALLBACK(ext_yahoo_got_file) (yd->client_id, yd->user, 5179 who, msg, filename, size, sfd->id); 5180 } 5181 else { 5426 YAHOO_CALLBACK (ext_yahoo_got_file) (yd->client_id, yd->user, 5427 who, msg, filename, size, sfd->id); 5428 } else { 5182 5429 /* Response to our request */ 5183 5430 sfd = yahoo_get_active_transfer(id); … … 5185 5432 if (sfd && action == YAHOO_FILE_TRANSFER_ACCEPT) { 5186 5433 yahoo_send_filetransferinfo(yd, sfd); 5187 } 5188 else if (!sfd || action == YAHOO_FILE_TRANSFER_REJECT) { 5189 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5190 (yd->client_id, YAHOO_FILE_TRANSFER_REJECT, 5191 sfd ? sfd->data : NULL); 5434 } else if (!sfd || action == YAHOO_FILE_TRANSFER_REJECT) { 5435 YAHOO_CALLBACK (ext_yahoo_file_transfer_done) 5436 (yd->client_id, YAHOO_FILE_TRANSFER_REJECT,