Changeset 9034ba0
- Timestamp:
- 2010-07-24T10:57:08Z (14 years ago)
- Branches:
- master
- Children:
- 78e2eb7
- Parents:
- c36f73b
- Location:
- protocols/yahoo
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/yahoo/libyahoo2.c
rc36f73b r9034ba0 108 108 #endif 109 109 110 static int yahoo_send_data(int fd, void *data, int len); 110 static int yahoo_send_data(void *fd, void *data, int len); 111 static void _yahoo_http_connected(int id, void *fd, int error, void *data); 112 static void yahoo_connected(void *fd, int error, void *data); 111 113 112 114 int yahoo_log_message(char *fmt, ...) … … 140 142 141 143 /* default values for servers */ 142 static char pager_host[] = "scs.msg.yahoo.com"; 144 static char *default_pager_hosts[] = { "scs.msg.yahoo.com", 145 "scsa.msg.yahoo.com", 146 "scsb.msg.yahoo.com", 147 "scsc.msg.yahoo.com", 148 NULL}; 149 143 150 static int pager_port = 5050; 144 151 static int fallback_ports[] = { 23, 25, 80, 20, 119, 8001, 8002, 5050, 0 }; 152 145 153 static char filetransfer_host[] = "filetransfer.msg.yahoo.com"; 146 154 static int filetransfer_port = 80; … … 153 161 static char profile_url[] = "http://profiles.yahoo.com/"; 154 162 155 enum yahoo_service { /* these are easier to see in hex */ 156 YAHOO_SERVICE_LOGON = 1, 157 YAHOO_SERVICE_LOGOFF, 158 YAHOO_SERVICE_ISAWAY, 159 YAHOO_SERVICE_ISBACK, 160 YAHOO_SERVICE_IDLE, /* 5 (placemarker) */ 161 YAHOO_SERVICE_MESSAGE, 162 YAHOO_SERVICE_IDACT, 163 YAHOO_SERVICE_IDDEACT, 164 YAHOO_SERVICE_MAILSTAT, 165 YAHOO_SERVICE_USERSTAT, /* 0xa */ 166 YAHOO_SERVICE_NEWMAIL, 167 YAHOO_SERVICE_CHATINVITE, 168 YAHOO_SERVICE_CALENDAR, 169 YAHOO_SERVICE_NEWPERSONALMAIL, 170 YAHOO_SERVICE_NEWCONTACT, 171 YAHOO_SERVICE_ADDIDENT, /* 0x10 */ 172 YAHOO_SERVICE_ADDIGNORE, 173 YAHOO_SERVICE_PING, 174 YAHOO_SERVICE_GOTGROUPRENAME, /* < 1, 36(old), 37(new) */ 175 YAHOO_SERVICE_SYSMESSAGE = 0x14, 176 YAHOO_SERVICE_SKINNAME = 0x15, 177 YAHOO_SERVICE_PASSTHROUGH2 = 0x16, 178 YAHOO_SERVICE_CONFINVITE = 0x18, 179 YAHOO_SERVICE_CONFLOGON, 180 YAHOO_SERVICE_CONFDECLINE, 181 YAHOO_SERVICE_CONFLOGOFF, 182 YAHOO_SERVICE_CONFADDINVITE, 183 YAHOO_SERVICE_CONFMSG, 184 YAHOO_SERVICE_CHATLOGON, 185 YAHOO_SERVICE_CHATLOGOFF, 186 YAHOO_SERVICE_CHATMSG = 0x20, 187 YAHOO_SERVICE_GAMELOGON = 0x28, 188 YAHOO_SERVICE_GAMELOGOFF, 189 YAHOO_SERVICE_GAMEMSG = 0x2a, 190 YAHOO_SERVICE_FILETRANSFER = 0x46, 191 YAHOO_SERVICE_VOICECHAT = 0x4A, 192 YAHOO_SERVICE_NOTIFY, 193 YAHOO_SERVICE_VERIFY, 194 YAHOO_SERVICE_P2PFILEXFER, 195 YAHOO_SERVICE_PEERTOPEER = 0x4F, /* Checks if P2P possible */ 196 YAHOO_SERVICE_WEBCAM, 197 YAHOO_SERVICE_AUTHRESP = 0x54, 198 YAHOO_SERVICE_LIST, 199 YAHOO_SERVICE_AUTH = 0x57, 200 YAHOO_SERVICE_AUTHBUDDY = 0x6d, 201 YAHOO_SERVICE_ADDBUDDY = 0x83, 202 YAHOO_SERVICE_REMBUDDY, 203 YAHOO_SERVICE_IGNORECONTACT, /* > 1, 7, 13 < 1, 66, 13, 0*/ 204 YAHOO_SERVICE_REJECTCONTACT, 205 YAHOO_SERVICE_GROUPRENAME = 0x89, /* > 1, 65(new), 66(0), 67(old) */ 206 YAHOO_SERVICE_Y7_PING = 0x8A, /* 0 - id and that's it?? */ 207 YAHOO_SERVICE_CHATONLINE = 0x96, /* > 109(id), 1, 6(abcde) < 0,1*/ 208 YAHOO_SERVICE_CHATGOTO, 209 YAHOO_SERVICE_CHATJOIN, /* > 1 104-room 129-1600326591 62-2 */ 210 YAHOO_SERVICE_CHATLEAVE, 211 YAHOO_SERVICE_CHATEXIT = 0x9b, 212 YAHOO_SERVICE_CHATADDINVITE = 0x9d, 213 YAHOO_SERVICE_CHATLOGOUT = 0xa0, 214 YAHOO_SERVICE_CHATPING, 215 YAHOO_SERVICE_COMMENT = 0xa8, 216 YAHOO_SERVICE_STEALTH = 0xb9, 217 YAHOO_SERVICE_PICTURE_CHECKSUM = 0xbd, 218 YAHOO_SERVICE_PICTURE = 0xbe, 219 YAHOO_SERVICE_PICTURE_UPDATE = 0xc1, 220 YAHOO_SERVICE_PICTURE_UPLOAD = 0xc2, 221 YAHOO_SERVICE_Y6_VISIBILITY = 0xc5, 222 YAHOO_SERVICE_Y6_STATUS_UPDATE = 0xc6, 223 YAHOO_PHOTOSHARE_INIT = 0xd2, 224 YAHOO_SERVICE_CONTACT_YMSG13 = 0xd6, 225 YAHOO_PHOTOSHARE_PREV = 0xd7, 226 YAHOO_PHOTOSHARE_KEY = 0xd8, 227 YAHOO_PHOTOSHARE_TRANS = 0xda, 228 YAHOO_FILE_TRANSFER_INIT_YMSG13 = 0xdc, 229 YAHOO_FILE_TRANSFER_GET_YMSG13 = 0xdd, 230 YAHOO_FILE_TRANSFER_PUT_YMSG13 = 0xde, 231 YAHOO_SERVICE_YMSG15_STATUS = 0xf0, 232 YAHOO_SERVICE_YMSG15_BUDDY_LIST = 0xf1, 163 struct connect_callback_data { 164 struct yahoo_data *yd; 165 int tag; 166 int i; 167 int server_i; 233 168 }; 234 169 … … 268 203 struct yahoo_search_state *ys; 269 204 270 intfd;205 void *fd; 271 206 enum yahoo_connection_type type; 272 207 273 208 unsigned char *rxqueue; 274 209 int rxlen; … … 289 224 char *local_host; 290 225 int conn_type; 226 char **pager_host_list; 291 227 }; 292 228 229 static void yahoo_process_ft_connection(struct yahoo_input_data *yid, int over); 230 231 static void yahoo_process_filetransfer(struct yahoo_input_data *yid, 232 struct yahoo_packet *pkt); 233 static void yahoo_process_filetransferinfo(struct yahoo_input_data *yid, 234 struct yahoo_packet *pkt); 235 static void yahoo_process_filetransferaccept(struct yahoo_input_data *yid, 236 struct yahoo_packet *pkt); 237 238 static void yahoo_https_auth(struct yahoo_input_data *yid, const char *seed, const char *sn); 239 293 240 static void *_yahoo_default_server_settings() 294 241 { 295 struct yahoo_server_settings *yss = y_new0(struct yahoo_server_settings, 1); 296 297 yss->pager_host = strdup(pager_host); 242 struct yahoo_server_settings *yss = 243 y_new0(struct yahoo_server_settings, 1); 244 245 /* Give preference to the default host list 246 * Make sure that only one of the two is set at any time 247 */ 248 yss->pager_host = NULL; 249 yss->pager_host_list = default_pager_hosts; 250 298 251 yss->pager_port = pager_port; 299 252 yss->filetransfer_host = strdup(filetransfer_host); … … 314 267 char *svalue; 315 268 int nvalue; 269 char **pvalue; 316 270 317 271 while (1) { … … 324 278 free(yss->pager_host); 325 279 yss->pager_host = strdup(svalue); 280 yss->pager_host_list = NULL; 281 } else if (!strcmp(key, "pager_host_list")) { 282 pvalue = va_arg(ap, char **); 283 yss->pager_host_list = pvalue; 284 free(yss->pager_host); 285 yss->pager_host = NULL; 326 286 } else if (!strcmp(key, "pager_port")) { 327 287 nvalue = va_arg(ap, int); … … 384 344 conns = y_list_prepend(conns, yd); 385 345 } 346 386 347 static struct yahoo_data *find_conn_by_id(int id) 387 348 { … … 394 355 return NULL; 395 356 } 357 396 358 static void del_from_list(struct yahoo_data *yd) 397 359 { … … 400 362 401 363 /* call repeatedly to get the next one */ 402 static struct yahoo_input_data *find_input_by_id(int id) 364 /* 365 static struct yahoo_input_data * find_input_by_id(int id) 403 366 { 404 367 YList *l; … … 410 373 return NULL; 411 374 } 412 413 static struct yahoo_input_data *find_input_by_id_and_webcam_user(int id, const char *who) 375 */ 376 377 static struct yahoo_input_data *find_input_by_id_and_webcam_user(int id, 378 const char *who) 414 379 { 415 380 YList *l; … … 417 382 for (l = inputs; l; l = y_list_next(l)) { 418 383 struct yahoo_input_data *yid = l->data; 419 if (yid->type == YAHOO_CONNECTION_WEBCAM && yid->yd->client_id == id 420 && yid->wcm && 421 ((who && yid->wcm->user && !strcmp(who, yid->wcm->user)) || 422 !(yid->wcm->user && !who))) 384 if (yid->type == YAHOO_CONNECTION_WEBCAM 385 && yid->yd->client_id == id && yid->wcm && ((who 386 && yid->wcm->user 387 && !strcmp(who, yid->wcm->user)) 388 || !(yid->wcm->user && !who))) 423 389 return yid; 424 390 } … … 426 392 } 427 393 428 static struct yahoo_input_data *find_input_by_id_and_type(int id, enum yahoo_connection_type type) 394 static struct yahoo_input_data *find_input_by_id_and_type(int id, 395 enum yahoo_connection_type type) 429 396 { 430 397 YList *l; … … 438 405 } 439 406 440 static struct yahoo_input_data *find_input_by_id_and_fd(int id, intfd)407 static struct yahoo_input_data *find_input_by_id_and_fd(int id, void *fd) 441 408 { 442 409 YList *l; … … 463 430 return c; 464 431 } 465 466 432 467 433 extern char *yahoo_crypt(char *, char *); … … 528 494 FREE(yd->cookie_y); 529 495 FREE(yd->cookie_t); 496 FREE(yd->cookie_b); 530 497 FREE(yd->cookie_c); 531 498 FREE(yd->login_cookie); … … 543 510 #define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4) 544 511 545 static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, 546 enum yahoo_status status, int id)512 static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, 513 enum ypacket_status status, int id) 547 514 { 548 515 struct yahoo_packet *pkt = y_new0(struct yahoo_packet, 1); … … 555 522 } 556 523 557 static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, const char *value) 524 static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, 525 const char *value) 558 526 { 559 527 struct yahoo_pair *pair = y_new0(struct yahoo_pair, 1); … … 600 568 (((*((buf)+3))&0xff))) 601 569 602 static void yahoo_packet_read(struct yahoo_packet *pkt, unsigned char *data, int len) 570 static void yahoo_packet_read(struct yahoo_packet *pkt, unsigned char *data, 571 int len) 603 572 { 604 573 int pos = 0; … … 653 622 FREE(value); 654 623 pkt->hash = y_list_append(pkt->hash, pair); 655 DEBUG_MSG(("Key: %d \tValue: %s", pair->key, pair->value)); 624 DEBUG_MSG(("Key: %d \tValue: %s", pair->key, 625 pair->value)); 656 626 } else { 657 627 FREE(pair); … … 788 758 } 789 759 790 static int yahoo_send_data( intfd, void *data, int len)760 static int yahoo_send_data(void *fd, void *data, int len) 791 761 { 792 762 int ret; 793 763 int e; 794 764 795 if (fd < 0)765 if (fd == NULL) 796 766 return -1; 797 767 … … 799 769 800 770 do { 801 ret = write(fd, data, len);771 ret = YAHOO_CALLBACK(ext_yahoo_write) (fd, data, len); 802 772 } while (ret == -1 && errno == EINTR); 803 773 e = errno; … … 838 808 yid->read_tag = yid->write_tag = 0; 839 809 if (yid->fd) 840 close(yid->fd);810 YAHOO_CALLBACK(ext_yahoo_close) (yid->fd); 841 811 yid->fd = 0; 842 812 FREE(yid->rxqueue); … … 942 912 else if (!strncasecmp(msg, "GAME", strlen("GAME"))) 943 913 YAHOO_CALLBACK(ext_yahoo_game_notify) (yd->client_id, to, from, 944 stat );914 stat, ind); 945 915 else if (!strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE"))) { 946 916 if (!strcmp(ind, " ")) { … … 959 929 } 960 930 961 static void yahoo_process_filetransfer(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 962 { 963 struct yahoo_data *yd = yid->yd; 964 char *from = NULL; 965 char *to = NULL; 966 char *msg = NULL; 967 char *url = NULL; 968 long expires = 0; 969 970 char *service = NULL; 971 972 char *filename = NULL; 973 unsigned long filesize = 0L; 974 975 YList *l; 976 for (l = pkt->hash; l; l = l->next) { 977 struct yahoo_pair *pair = l->data; 978 if (pair->key == 4) 979 from = pair->value; 980 if (pair->key == 5) 981 to = pair->value; 982 if (pair->key == 14) 983 msg = pair->value; 984 if (pair->key == 20) 985 url = pair->value; 986 if (pair->key == 38) 987 expires = atol(pair->value); 988 989 if (pair->key == 27) 990 filename = pair->value; 991 if (pair->key == 28) 992 filesize = atol(pair->value); 993 994 if (pair->key == 49) 995 service = pair->value; 996 } 997 998 if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { 999 if (strcmp("FILEXFER", service) != 0) { 1000 WARNING(("unhandled service 0x%02x", pkt->service)); 1001 yahoo_dump_unhandled(pkt); 1002 return; 1003 } 1004 } 1005 1006 if (msg) { 1007 char *tmp; 1008 tmp = strchr(msg, '\006'); 1009 if (tmp) 1010 *tmp = '\0'; 1011 } 1012 if (url && from) 1013 YAHOO_CALLBACK(ext_yahoo_got_file) (yd->client_id, to, from, url, expires, msg, filename, filesize); 1014 1015 } 1016 1017 static void yahoo_process_conference(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 931 static void yahoo_process_conference(struct yahoo_input_data *yid, 932 struct yahoo_packet *pkt) 1018 933 { 1019 934 struct yahoo_data *yd = yid->yd; … … 1090 1005 break; 1091 1006 case YAHOO_SERVICE_CONFADDINVITE: 1092 if (pkt->status == 2) 1093 ; 1094 else 1095 YAHOO_CALLBACK(ext_yahoo_got_conf_invite) (yd->client_id, id, host, room, msg, members); 1007 if (pkt->status == 1) 1008 YAHOO_CALLBACK(ext_yahoo_got_conf_invite) (yd-> 1009 client_id, id, host, room, msg, members); 1096 1010 break; 1097 1011 case YAHOO_SERVICE_CONFDECLINE: … … 1134 1048 int chaterr = 0; 1135 1049 YList *l; 1136 1050 1137 1051 yahoo_dump_unhandled(pkt); 1138 1052 for (l = pkt->hash; l; l = l->next) { … … 1285 1199 char *msg; 1286 1200 int utf8; 1201 char *gunk; 1287 1202 } *message = y_new0(struct m, 1); 1288 1203 … … 1298 1213 else if (pair->key == 97) 1299 1214 message->utf8 = atoi(pair->value); 1300 /* user message */ /* sys message */ 1215 /* This comes when the official client sends us a message */ 1216 else if (pair->key == 429) 1217 message->gunk = pair->value; 1218 /* user message *//* sys message */ 1301 1219 else if (pair->key == 14 || pair->key == 16) 1302 1220 message->msg = pair->value; … … 1318 1236 message = l->data; 1319 1237 if (pkt->service == YAHOO_SERVICE_SYSMESSAGE) { 1320 YAHOO_CALLBACK(ext_yahoo_system_message) (yd->client_id, message->msg); 1238 YAHOO_CALLBACK(ext_yahoo_system_message) (yd->client_id, 1239 message->to, message->from, message->msg); 1321 1240 } else if (pkt->status <= 2 || pkt->status == 5) { 1322 YAHOO_CALLBACK(ext_yahoo_got_im) (yd->client_id, message->to, message->from, message->msg, message->tm, pkt->status, message->utf8); 1241 /* Confirm message receipt if we got the gunk */ 1242 if(message->gunk) { 1243 struct yahoo_packet *outpkt; 1244 1245 outpkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE_CONFIRM, 1246 YPACKET_STATUS_DEFAULT, 0); 1247 yahoo_packet_hash(outpkt, 1, yd->user); 1248 yahoo_packet_hash(outpkt, 5, message->from); 1249 yahoo_packet_hash(outpkt, 302, "430"); 1250 yahoo_packet_hash(outpkt, 430, message->gunk); 1251 yahoo_packet_hash(outpkt, 303, "430"); 1252 yahoo_packet_hash(outpkt, 450, "0"); 1253 yahoo_send_packet(yid, outpkt, 0); 1254 1255 yahoo_packet_free(outpkt); 1256 } 1257 1258 if (!strcmp(message->msg, "<ding>")) 1259 YAHOO_CALLBACK(ext_yahoo_got_buzz) (yd->client_id, 1260 message->to, message->from, message->tm); 1261 else 1262 YAHOO_CALLBACK(ext_yahoo_got_im) (yd->client_id, 1263 message->to, message->from, message->msg, 1264 message->tm, pkt->status, message->utf8); 1323 1265 } else if (pkt->status == 0xffffffff) { 1324 YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, message->msg, 0, E_SYSTEM); 1325 } 1326 free(message); 1266 YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, 1267 message->msg, 0, E_SYSTEM); 1268 } 1269 FREE(message); 1327 1270 } 1328 1271 … … 1330 1273 } 1331 1274 1275 /* 1276 * Here's what multi-level packets look like. Data in brackets is the value. 1277 * 1278 * 3 level: 1279 * ======= 1280 * 1281 * 302 (318) - Beginning level 1 1282 * 300 (318) - Begin level 2 1283 * 302 (319) - End level 2 header 1284 * 300 (319) - Begin level 3 1285 * 301 (319) - End level 3 1286 * 303 (319) - End level 2 1287 * 303 (318) - End level 1 1288 * 1289 * 2 level: 1290 * ======= 1291 * 1292 * 302 (315) - Beginning level 1 1293 * 300 (315) - Begin level 2 1294 * 301 (315) - End level 2 1295 * 303 (315) - End level 1 1296 * 1297 */ 1332 1298 static void yahoo_process_status(struct yahoo_input_data *yid, 1333 1299 struct yahoo_packet *pkt) … … 1721 1687 char *url = NULL; 1722 1688 1723 if ( pkt->status != 1)1689 if (pkt->status != 1) 1724 1690 return; /* something went wrong */ 1725 1726 for (l = pkt->hash; l; l = l->next) 1727 { 1691 1692 for (l = pkt->hash; l; l = l->next) { 1728 1693 struct yahoo_pair *pair = l->data; 1729 1694 1730 switch(pair->key) 1731 { 1732 case 5: /* we */ 1733 break; 1734 case 20: /* url */ 1735 url = pair->value; 1736 break; 1737 case 27: /* local filename */ 1738 break; 1739 case 38: /* time */ 1740 break; 1695 switch (pair->key) { 1696 case 5: /* we */ 1697 break; 1698 case 20: /* url */ 1699 url = pair->value; 1700 break; 1701 case 27: /* local filename */ 1702 break; 1703 case 38: /* time */ 1704 break; 1741 1705 } 1742 1706 } … … 1745 1709 } 1746 1710 1747 static void yahoo_process_auth_pre_0x0b(struct yahoo_input_data *yid, 1748 const char *seed, const char *sn) 1749 { 1750 struct yahoo_data *yd = yid->yd; 1751 1752 /* So, Yahoo has stopped supporting its older clients in India, and 1753 * undoubtedly will soon do so in the rest of the world. 1754 * 1755 * The new clients use this authentication method. I warn you in 1756 * advance, it's bizzare, convoluted, inordinately complicated. 1757 * It's also no more secure than crypt() was. The only purpose this 1758 * scheme could serve is to prevent third part clients from connecting 1759 * to their servers. 1760 * 1761 * Sorry, Yahoo. 1711 void yahoo_login(int id, int initial) 1712 { 1713 struct yahoo_data *yd = find_conn_by_id(id); 1714 struct connect_callback_data *ccd; 1715 struct yahoo_server_settings *yss; 1716 int tag; 1717 1718 char *host; 1719 1720 struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); 1721 yid->yd = yd; 1722 yid->type = YAHOO_CONNECTION_PAGER; 1723 inputs = y_list_prepend(inputs, yid); 1724 1725 yd->initial_status = initial; 1726 yss = yd->server_settings; 1727 1728 ccd = y_new0(struct connect_callback_data, 1); 1729 ccd->yd = yd; 1730 1731 host = yss->pager_host; 1732 1733 if (!host) 1734 host = yss->pager_host_list[0]; 1735 1736 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, 1737 host, yss->pager_port, yahoo_connected, ccd, 0); 1738 1739 /* 1740 * if tag <= 0, then callback has already been called 1741 * so ccd will have been freed 1762 1742 */ 1763 1764 struct yahoo_packet *pack; 1765 1766 md5_byte_t result[16]; 1767 md5_state_t ctx; 1768 char *crypt_result; 1769 unsigned char *password_hash = malloc(25); 1770 unsigned char *crypt_hash = malloc(25); 1771 unsigned char *hash_string_p = malloc(50 + strlen(sn)); 1772 unsigned char *hash_string_c = malloc(50 + strlen(sn)); 1773 1774 char checksum; 1775 1776 int sv; 1777 1778 unsigned char *result6 = malloc(25); 1779 unsigned char *result96 = malloc(25); 1780 1781 sv = seed[15]; 1782 sv = (sv % 8) % 5; 1783 1784 md5_init(&ctx); 1785 md5_append(&ctx, (md5_byte_t *)yd->password, strlen(yd->password)); 1786 md5_finish(&ctx, result); 1787 to_y64(password_hash, result, 16); 1788 1789 md5_init(&ctx); 1790 crypt_result = yahoo_crypt(yd->password, "$1$_2S43d5f$"); 1791 md5_append(&ctx, (md5_byte_t *)crypt_result, strlen(crypt_result)); 1792 md5_finish(&ctx, result); 1793 to_y64(crypt_hash, result, 16); 1794 free(crypt_result); 1795 1796 switch (sv) { 1797 case 0: 1798 checksum = seed[seed[7] % 16]; 1799 snprintf((char *)hash_string_p, strlen(sn) + 50, 1800 "%c%s%s%s", checksum, password_hash, yd->user, seed); 1801 snprintf((char *)hash_string_c, strlen(sn) + 50, 1802 "%c%s%s%s", checksum, crypt_hash, yd->user, seed); 1803 break; 1804 case 1: 1805 checksum = seed[seed[9] % 16]; 1806 snprintf((char *)hash_string_p, strlen(sn) + 50, 1807 "%c%s%s%s", checksum, yd->user, seed, password_hash); 1808 snprintf((char *)hash_string_c, strlen(sn) + 50, 1809 "%c%s%s%s", checksum, yd->user, seed, crypt_hash); 1810 break; 1811 case 2: 1812 checksum = seed[seed[15] % 16]; 1813 snprintf((char *)hash_string_p, strlen(sn) + 50, 1814 "%c%s%s%s", checksum, seed, password_hash, yd->user); 1815 snprintf((char *)hash_string_c, strlen(sn) + 50, 1816 "%c%s%s%s", checksum, seed, crypt_hash, yd->user); 1817 break; 1818 case 3: 1819 checksum = seed[seed[1] % 16]; 1820 snprintf((char *)hash_string_p, strlen(sn) + 50, 1821 "%c%s%s%s", checksum, yd->user, password_hash, seed); 1822 snprintf((char *)hash_string_c, strlen(sn) + 50, 1823 "%c%s%s%s", checksum, yd->user, crypt_hash, seed); 1824 break; 1825 case 4: 1826 checksum = seed[seed[3] % 16]; 1827 snprintf((char *)hash_string_p, strlen(sn) + 50, 1828 "%c%s%s%s", checksum, password_hash, seed, yd->user); 1829 snprintf((char *)hash_string_c, strlen(sn) + 50, 1830 "%c%s%s%s", checksum, crypt_hash, seed, yd->user); 1831 break; 1832 } 1833 1834 md5_init(&ctx); 1835 md5_append(&ctx, (md5_byte_t *)hash_string_p, strlen((char *)hash_string_p)); 1836 md5_finish(&ctx, result); 1837 to_y64(result6, result, 16); 1838 1839 md5_init(&ctx); 1840 md5_append(&ctx, (md5_byte_t *)hash_string_c, strlen((char *)hash_string_c)); 1841 md5_finish(&ctx, result); 1842 to_y64(result96, result, 16); 1843 1844 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->initial_status, yd->session_id); 1845 yahoo_packet_hash(pack, 0, yd->user); 1846 yahoo_packet_hash(pack, 6, (char *)result6); 1847 yahoo_packet_hash(pack, 96, (char *)result96); 1848 yahoo_packet_hash(pack, 1, yd->user); 1849 1850 yahoo_send_packet(yid, pack, 0); 1851 1852 FREE(result6); 1853 FREE(result96); 1854 FREE(password_hash); 1855 FREE(crypt_hash); 1856 FREE(hash_string_p); 1857 FREE(hash_string_c); 1858 1859 yahoo_packet_free(pack); 1860 1861 } 1862 1863 /* 1864 * New auth protocol cracked by Cerulean Studios and sent in to Gaim 1865 */ 1866 static void yahoo_process_auth_0x0b(struct yahoo_input_data *yid, const char *seed, const char *sn) 1867 { 1868 struct yahoo_packet *pack = NULL; 1869 struct yahoo_data *yd = yid->yd; 1870 1871 md5_byte_t result[16]; 1872 md5_state_t ctx; 1873 1874 sha1_state_t ctx1; 1875 sha1_state_t ctx2; 1876 1877 char *alphabet1 = "FBZDWAGHrJTLMNOPpRSKUVEXYChImkwQ"; 1878 char *alphabet2 = "F0E1D2C3B4A59687abcdefghijklmnop"; 1879 1880 char *challenge_lookup = "qzec2tb3um1olpar8whx4dfgijknsvy5"; 1881 char *operand_lookup = "+|&%/*^-"; 1882 char *delimit_lookup = ",;"; 1883 1884 unsigned char *password_hash = malloc(25); 1885 unsigned char *crypt_hash = malloc(25); 1886 char *crypt_result = NULL; 1887 unsigned char pass_hash_xor1[64]; 1888 unsigned char pass_hash_xor2[64]; 1889 unsigned char crypt_hash_xor1[64]; 1890 unsigned char crypt_hash_xor2[64]; 1891 unsigned char chal[7]; 1892 char resp_6[100]; 1893 char resp_96[100]; 1894 1895 unsigned char digest1[20]; 1896 unsigned char digest2[20]; 1897 unsigned char magic_key_char[4]; 1898 const unsigned char *magic_ptr; 1899 1900 unsigned int magic[64]; 1901 unsigned int magic_work = 0; 1902 1903 char comparison_src[20]; 1904 1905 int x, j, i; 1906 int cnt = 0; 1907 int magic_cnt = 0; 1908 int magic_len; 1909 int depth =0, table =0; 1910 1911 memset(&pass_hash_xor1, 0, 64); 1912 memset(&pass_hash_xor2, 0, 64); 1913 memset(&crypt_hash_xor1, 0, 64); 1914 memset(&crypt_hash_xor2, 0, 64); 1915 memset(&digest1, 0, 20); 1916 memset(&digest2, 0, 20); 1917 memset(&magic, 0, 64); 1918 memset(&resp_6, 0, 100); 1919 memset(&resp_96, 0, 100); 1920 memset(&magic_key_char, 0, 4); 1921 1922 /* 1923 * Magic: Phase 1. Generate what seems to be a 30 1924 * byte value (could change if base64 1925 * ends up differently? I don't remember and I'm 1926 * tired, so use a 64 byte buffer. 1927 */ 1928 1929 magic_ptr = (unsigned char *)seed; 1930 1931 while (*magic_ptr != 0) { 1932 char *loc; 1933 1934 /* Ignore parentheses. */ 1935 1936 if (*magic_ptr == '(' || *magic_ptr == ')') { 1937 magic_ptr++; 1938 continue; 1939 } 1940 1941 /* Characters and digits verify against 1942 the challenge lookup. 1943 */ 1944 1945 if (isalpha(*magic_ptr) || isdigit(*magic_ptr)) { 1946 loc = strchr(challenge_lookup, *magic_ptr); 1947 if (!loc) { 1948 /* This isn't good */ 1949 continue; 1950 } 1951 1952 /* Get offset into lookup table and lsh 3. */ 1953 1954 magic_work = loc - challenge_lookup; 1955 magic_work <<= 3; 1956 1957 magic_ptr++; 1958 continue; 1959 } else { 1960 unsigned int local_store; 1961 1962 loc = strchr(operand_lookup, *magic_ptr); 1963 if (!loc) { 1964 /* Also not good. */ 1965 continue; 1966 } 1967 1968 local_store = loc - operand_lookup; 1969 1970 /* Oops; how did this happen? */ 1971 if (magic_cnt >= 64) 1972 break; 1973 1974 magic[magic_cnt++] = magic_work | local_store; 1975 magic_ptr++; 1976 continue; 1977 } 1978 } 1979 1980 magic_len = magic_cnt; 1981 magic_cnt = 0; 1982 1983 /* Magic: Phase 2. Take generated magic value and 1984 * sprinkle fairy dust on the values. */ 1985 1986 for (magic_cnt = magic_len-2; magic_cnt >= 0; magic_cnt--) { 1987 unsigned char byte1; 1988 unsigned char byte2; 1989 1990 /* Bad. Abort. 1991 */ 1992 if (magic_cnt >= magic_len) { 1993 WARNING(("magic_cnt(%d) magic_len(%d)", magic_cnt, magic_len)) 1994 break; 1995 } 1996 1997 byte1 = magic[magic_cnt]; 1998 byte2 = magic[magic_cnt+1]; 1999 2000 byte1 *= 0xcd; 2001 byte1 ^= byte2; 2002 2003 magic[magic_cnt+1] = byte1; 2004 } 2005 2006 /* Magic: Phase 3. This computes 20 bytes. The first 4 bytes are used as our magic 2007 * key (and may be changed later); the next 16 bytes are an MD5 sum of the magic key 2008 * plus 3 bytes. The 3 bytes are found by looping, and they represent the offsets 2009 * into particular functions we'll later call to potentially alter the magic key. 2010 * 2011 * %-) 2012 */ 2013 2014 magic_cnt = 1; 2015 x = 0; 2016 2017 do { 2018 unsigned int bl = 0; 2019 unsigned int cl = magic[magic_cnt++]; 2020 2021 if (magic_cnt >= magic_len) 2022 break; 2023 2024 if (cl > 0x7F) { 2025 if (cl < 0xe0) 2026 bl = cl = (cl & 0x1f) << 6; 2027 else { 2028 bl = magic[magic_cnt++]; 2029 cl = (cl & 0x0f) << 6; 2030 bl = ((bl & 0x3f) + cl) << 6; 2031 } 2032 2033 cl = magic[magic_cnt++]; 2034 bl = (cl & 0x3f) + bl; 2035 } else 2036 bl = cl; 2037 2038 comparison_src[x++] = (bl & 0xff00) >> 8; 2039 comparison_src[x++] = bl & 0xff; 2040 } while (x < 20); 2041 2042 /* Dump magic key into a char for SHA1 action. */ 2043 2044 2045 for (x = 0; x < 4; x++) 2046 magic_key_char[x] = comparison_src[x]; 2047 2048 /* Compute values for recursive function table! */ 2049 memcpy( chal, magic_key_char, 4 ); 2050 x = 1; 2051 for ( i = 0; i < 0xFFFF && x; i++ ) 2052 { 2053 for ( j = 0; j < 5 && x; j++ ) 2054 { 2055 chal[4] = i; 2056 chal[5] = i >> 8; 2057 chal[6] = j; 2058 md5_init( &ctx ); 2059 md5_append( &ctx, chal, 7 ); 2060 md5_finish( &ctx, result ); 2061 if ( memcmp( comparison_src + 4, result, 16 ) == 0 ) 2062 { 2063 depth = i; 2064 table = j; 2065 x = 0; 2066 } 2067 } 2068 } 2069 2070 /* Transform magic_key_char using transform table */ 2071 x = magic_key_char[3] << 24 | magic_key_char[2] << 16 2072 | magic_key_char[1] << 8 | magic_key_char[0]; 2073 x = yahoo_xfrm( table, depth, x ); 2074 x = yahoo_xfrm( table, depth, x ); 2075 magic_key_char[0] = x & 0xFF; 2076 magic_key_char[1] = x >> 8 & 0xFF; 2077 magic_key_char[2] = x >> 16 & 0xFF; 2078 magic_key_char[3] = x >> 24 & 0xFF; 2079 2080 /* Get password and crypt hashes as per usual. */ 2081 md5_init(&ctx); 2082 md5_append(&ctx, (md5_byte_t *)yd->password, strlen(yd->password)); 2083 md5_finish(&ctx, result); 2084 to_y64(password_hash, result, 16); 2085 2086 md5_init(&ctx); 2087 crypt_result = yahoo_crypt(yd->password, "$1$_2S43d5f$"); 2088 md5_append(&ctx, (md5_byte_t *)crypt_result, strlen(crypt_result)); 2089 md5_finish(&ctx, result); 2090 to_y64(crypt_hash, result, 16); 2091 free(crypt_result); 2092 2093 /* Our first authentication response is based off 2094 * of the password hash. */ 2095 2096 for (x = 0; x < (int)strlen((char *)password_hash); x++) 2097 pass_hash_xor1[cnt++] = password_hash[x] ^ 0x36; 2098 2099 if (cnt < 64) 2100 memset(&(pass_hash_xor1[cnt]), 0x36, 64-cnt); 2101 2102 cnt = 0; 2103 2104 for (x = 0; x < (int)strlen((char *)password_hash); x++) 2105 pass_hash_xor2[cnt++] = password_hash[x] ^ 0x5c; 2106 2107 if (cnt < 64) 2108 memset(&(pass_hash_xor2[cnt]), 0x5c, 64-cnt); 2109 2110 sha1_init(&ctx1); 2111 sha1_init(&ctx2); 2112 2113 /* The first context gets the password hash XORed 2114 * with 0x36 plus a magic value 2115 * which we previously extrapolated from our 2116 * challenge. */ 2117 2118 sha1_append(&ctx1, pass_hash_xor1, 64); 2119 if (j >= 3 ) 2120 ctx1.Length_Low = 0x1ff; 2121 sha1_append(&ctx1, magic_key_char, 4); 2122 sha1_finish(&ctx1, digest1); 2123 2124 /* The second context gets the password hash XORed 2125 * with 0x5c plus the SHA-1 digest 2126 * of the first context. */ 2127 2128 sha1_append(&ctx2, pass_hash_xor2, 64); 2129 sha1_append(&ctx2, digest1, 20); 2130 sha1_finish(&ctx2, digest2); 2131 2132 /* Now that we have digest2, use it to fetch 2133 * characters from an alphabet to construct 2134 * our first authentication response. */ 2135 2136 for (x = 0; x < 20; x += 2) { 2137 unsigned int val = 0; 2138 unsigned int lookup = 0; 2139 char byte[6]; 2140 2141 memset(&byte, 0, 6); 2142 2143 /* First two bytes of digest stuffed 2144 * together. 2145 */ 2146 2147 val = digest2[x]; 2148 val <<= 8; 2149 val += digest2[x+1]; 2150 2151 lookup = (val >> 0x0b); 2152 lookup &= 0x1f; 2153 if (lookup >= strlen(alphabet1)) 2154 break; 2155 sprintf(byte, "%c", alphabet1[lookup]); 2156 strcat(resp_6, byte); 2157 strcat(resp_6, "="); 2158 2159 lookup = (val >> 0x06); 2160 lookup &= 0x1f; 2161 if (lookup >= strlen(alphabet2)) 2162 break; 2163 sprintf(byte, "%c", alphabet2[lookup]); 2164 strcat(resp_6, byte); 2165 2166 lookup = (val >> 0x01); 2167 lookup &= 0x1f; 2168 if (lookup >= strlen(alphabet2)) 2169 break; 2170 sprintf(byte, "%c", alphabet2[lookup]); 2171 strcat(resp_6, byte); 2172 2173 lookup = (val & 0x01); 2174 if (lookup >= strlen(delimit_lookup)) 2175 break; 2176 sprintf(byte, "%c", delimit_lookup[lookup]); 2177 strcat(resp_6, byte); 2178 } 2179 2180 /* Our second authentication response is based off 2181 * of the crypto hash. */ 2182 2183 cnt = 0; 2184 memset(&digest1, 0, 20); 2185 memset(&digest2, 0, 20); 2186 2187 for (x = 0; x < (int)strlen((char *)crypt_hash); x++) 2188 crypt_hash_xor1[cnt++] = crypt_hash[x] ^ 0x36; 2189 2190 if (cnt < 64) 2191 memset(&(crypt_hash_xor1[cnt]), 0x36, 64-cnt); 2192 2193 cnt = 0; 2194 2195 for (x = 0; x < (int)strlen((char *)crypt_hash); x++) 2196 crypt_hash_xor2[cnt++] = crypt_hash[x] ^ 0x5c; 2197 2198 if (cnt < 64) 2199 memset(&(crypt_hash_xor2[cnt]), 0x5c, 64-cnt); 2200 2201 sha1_init(&ctx1); 2202 sha1_init(&ctx2); 2203 2204 /* The first context gets the password hash XORed 2205 * with 0x36 plus a magic value 2206 * which we previously extrapolated from our 2207 * challenge. */ 2208 2209 sha1_append(&ctx1, crypt_hash_xor1, 64); 2210 if (j >= 3 ) 2211 ctx1.Length_Low = 0x1ff; 2212 sha1_append(&ctx1, magic_key_char, 4); 2213 sha1_finish(&ctx1, digest1); 2214 2215 /* The second context gets the password hash XORed 2216 * with 0x5c plus the SHA-1 digest 2217 * of the first context. */ 2218 2219 sha1_append(&ctx2, crypt_hash_xor2, 64); 2220 sha1_append(&ctx2, digest1, 20); 2221 sha1_finish(&ctx2, digest2); 2222 2223 /* Now that we have digest2, use it to fetch 2224 * characters from an alphabet to construct 2225 * our first authentication response. */ 2226 2227 for (x = 0; x < 20; x += 2) { 2228 unsigned int val = 0; 2229 unsigned int lookup = 0; 2230 2231 char byte[6]; 2232 2233 memset(&byte, 0, 6); 2234 2235 /* First two bytes of digest stuffed 2236 * together. */ 2237 2238 val = digest2[x]; 2239 val <<= 8; 2240 val += digest2[x+1]; 2241 2242 lookup = (val >> 0x0b); 2243 lookup &= 0x1f; 2244 if (lookup >= strlen(alphabet1)) 2245 break; 2246 sprintf(byte, "%c", alphabet1[lookup]); 2247 strcat(resp_96, byte); 2248 strcat(resp_96, "="); 2249 2250 lookup = (val >> 0x06); 2251 lookup &= 0x1f; 2252 if (lookup >= strlen(alphabet2)) 2253 break; 2254 sprintf(byte, "%c", alphabet2[lookup]); 2255 strcat(resp_96, byte); 2256 2257 lookup = (val >> 0x01); 2258 lookup &= 0x1f; 2259 if (lookup >= strlen(alphabet2)) 2260 break; 2261 sprintf(byte, "%c", alphabet2[lookup]); 2262 strcat(resp_96, byte); 2263 2264 lookup = (val & 0x01); 2265 if (lookup >= strlen(delimit_lookup)) 2266 break; 2267 sprintf(byte, "%c", delimit_lookup[lookup]); 2268 strcat(resp_96, byte); 2269 } 2270 2271 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->initial_status, yd->session_id); 2272 yahoo_packet_hash(pack, 0, sn); 2273 yahoo_packet_hash(pack, 6, resp_6); 2274 yahoo_packet_hash(pack, 96, resp_96); 2275 yahoo_packet_hash(pack, 1, sn); 2276 yahoo_send_packet(yid, pack, 0); 2277 yahoo_packet_free(pack); 2278 2279 free(password_hash); 2280 free(crypt_hash); 1743 if (tag > 0) 1744 ccd->tag = tag; 1745 else if (tag < 0) 1746 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 1747 YAHOO_LOGIN_SOCK, NULL); 2281 1748 } 2282 1749 … … 2328 1795 } 2329 1796 2330 static void yahoo_ process_auth_0x10(struct yahoo_input_data *yid, const char *seed, const char *sn)1797 static void yahoo_https_auth(struct yahoo_input_data *yid, const char *seed, const char *sn) 2331 1798 { 2332 1799 struct yahoo_https_auth_data *had = g_new0(struct yahoo_https_auth_data, 1); … … 2479 1946 } 2480 1947 2481 static void yahoo_process_auth(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1948 static void yahoo_process_auth(struct yahoo_input_data *yid, 1949 struct yahoo_packet *pkt) 2482 1950 { 2483 1951 char *seed = NULL; 2484 char *sn 1952 char *sn = NULL; 2485 1953 YList *l = pkt->hash; 2486 1954 int m = 0; 1955 struct yahoo_data *yd = yid->yd; 2487 1956 2488 1957 while (l) { 2489 1958 struct yahoo_pair *pair = l->data; 2490 if (pair->key == 94) 1959 1960 switch (pair->key) { 1961 case 94: 2491 1962 seed = pair->value; 2492 if (pair->key == 1) 1963 break; 1964 case 1: 2493 1965 sn = pair->value; 2494 if (pair->key == 13) 1966 break; 1967 case 13: 2495 1968 m = atoi(pair->value); 1969 break; 1970 } 2496 1971 l = l->next; 2497 1972 } 2498 1973 2499 if (!seed) 2500 return; 2501 2502 switch (m) { 2503 case 0: 2504 yahoo_process_auth_pre_0x0b(yid, seed, sn); 2505 break; 2506 case 1: 2507 yahoo_process_auth_0x0b(yid, seed, sn); 2508 break; 2509 case 2: 2510 yahoo_process_auth_0x10(yid, seed, sn); 2511 break; 2512 default: 2513 /* call error */ 2514 WARNING(("unknown auth type %d", m)); 2515 yahoo_process_auth_0x0b(yid, seed, sn); 2516 break; 2517 } 2518 } 2519 2520 static void yahoo_process_auth_resp(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1974 if (!seed) 1975 return; 1976 1977 if (m==2) 1978 yahoo_https_auth(yid, seed, sn); 1979 else { 1980 /* call error */ 1981 WARNING(("unknown auth type %d", m)); 1982 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 1983 YAHOO_LOGIN_UNKNOWN, NULL); 1984 } 1985 } 1986 1987 static void yahoo_process_auth_resp(struct yahoo_input_data *yid, 1988 struct yahoo_packet *pkt) 2521 1989 { 2522 1990 struct yahoo_data *yd = yid->yd; … … 2524 1992 char *handle; 2525 1993 char *url = NULL; 2526 int login_status = 0;1994 int login_status = -1; 2527 1995 2528 1996 YList *l; … … 2540 2008 } 2541 2009 2542 if (pkt->status == 0xffffffff) { 2543 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, login_status, url); 2544 /* yahoo_logoff(yd->client_id);*/ 2010 if (pkt->status == YPACKET_STATUS_DISCONNECTED) { 2011 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 2012 login_status, url); 2013 /* yahoo_logoff(yd->client_id); */ 2545 2014 } 2546 2015 } … … 2580 2049 } 2581 2050 2051 static void yahoo_process_new_contact(struct yahoo_input_data *yid, 2052 struct yahoo_packet *pkt) 2053 { 2054 struct yahoo_data *yd = yid->yd; 2055 char *me = NULL; 2056 char *who = NULL; 2057 char *msg = NULL; 2058 int online = -1; 2059 2060 YList *l; 2061 2062 for (l = pkt->hash; l; l = l->next) { 2063 struct yahoo_pair *pair = l->data; 2064 if (pair->key == 4) 2065 who = pair->value; 2066 else if (pair->key == 5) 2067 me = pair->value; 2068 else if (pair->key == 14) 2069 msg = pair->value; 2070 else if (pair->key == 13) 2071 online = strtol(pair->value, NULL, 10); 2072 } 2073 2074 if (who && online < 0) 2075 YAHOO_CALLBACK(ext_yahoo_contact_added) (yd->client_id, me, who, 2076 msg); 2077 else if (online == 2) 2078 YAHOO_CALLBACK(ext_yahoo_rejected) (yd->client_id, who, msg); 2079 } 2080 2081 /* UNUSED? */ 2582 2082 static void yahoo_process_contact(struct yahoo_input_data *yid, 2583 2083 struct yahoo_packet *pkt) … … 2661 2161 where = "Unknown"; 2662 2162 2663 /* status: 0 == Successful, 1 == Error (does not exist), 2 == Already in list */ 2664 if ( status == 0 ) { 2665 bud = y_new0(struct yahoo_buddy, 1); 2666 bud->id = strdup(who); 2667 bud->group = strdup(where); 2668 bud->real_name = NULL; 2669 2670 yd->buddies = y_list_append(yd->buddies, bud); 2671 2672 /* Possibly called already, but at least the call above doesn't 2673 seem to happen every time (not anytime I tried). */ 2674 YAHOO_CALLBACK(ext_yahoo_contact_added) (yd->client_id, me, who, NULL); 2675 } 2676 2677 /* YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->client_id, who, status, NULL, (status==YAHOO_STATUS_AVAILABLE?0:1)); */ 2678 } 2679 2680 static void yahoo_process_contact_ymsg13(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 2681 { 2682 char* who = NULL; 2683 char* me = NULL; 2684 char* msg = NULL; 2685 YList *l; 2686 for (l = pkt->hash; l; l = l->next) { 2687 struct yahoo_pair *pair = l->data; 2688 if (pair->key == 4) 2689 who = pair->value; 2690 else if (pair->key == 5) 2691 me = pair->value; 2692 else 2693 DEBUG_MSG(("unknown key: %d = %s", pair->key, pair->value)); 2694 } 2695 2696 if (pkt->status==3) 2697 YAHOO_CALLBACK(ext_yahoo_contact_auth_request) (yid->yd->client_id, me, who, msg); 2163 bud = y_new0(struct yahoo_buddy, 1); 2164 bud->id = strdup(who); 2165 bud->group = strdup(where); 2166 bud->real_name = NULL; 2167 2168 yd->buddies = y_list_append(yd->buddies, bud); 2169 2170 /* A non-zero status (i've seen 2) seems to mean the buddy is already 2171 * added and is online */ 2172 if (status) { 2173 LOG(("Setting online see packet for info")); 2174 yahoo_dump_unhandled(pkt); 2175 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->client_id, who, 2176 YAHOO_STATUS_AVAILABLE, NULL, 0, 0, 0); 2177 } 2698 2178 } 2699 2179 … … 2783 2263 2784 2264 /* if(status) 2785 YAHOO_CALLBACK(ext_yahoo_error) 2265 YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, who, 0, status); 2786 2266 */ 2787 2267 } … … 2837 2317 } 2838 2318 2839 static void _yahoo_webcam_get_server_connected(int fd, int error, void *d) 2319 static void yahoo_process_buddy_change_group(struct yahoo_input_data *yid, 2320 struct yahoo_packet *pkt) 2321 { 2322 YList *l; 2323 char *me = NULL; 2324 char *who = NULL; 2325 char *old_group = NULL; 2326 char *new_group = NULL; 2327 2328 for (l = pkt->hash; l; l = l->next) { 2329 struct yahoo_pair *pair = l->data; 2330 if (pair->key == 1) 2331 me = pair->value; 2332 if (pair->key == 7) 2333 who = pair->value; 2334 if (pair->key == 224) 2335 old_group = pair->value; 2336 if (pair->key == 264) 2337 new_group = pair->value; 2338 } 2339 2340 YAHOO_CALLBACK(ext_yahoo_got_buddy_change_group) (yid->yd->client_id, 2341 me, who, old_group, new_group); 2342 } 2343 2344 static void _yahoo_webcam_get_server_connected(void *fd, int error, void *d) 2840 2345 { 2841 2346 struct yahoo_input_data *yid = d; … … 2848 2353 unsigned int pos = 0; 2849 2354 2850 if (error || fd <= 0) {2355 if (error || !fd) { 2851 2356 FREE(who); 2852 2357 FREE(yid); … … 2905 2410 YAHOO_CALLBACK(ext_yahoo_connect_async) (yid->yd->client_id, 2906 2411 yss->webcam_host, yss->webcam_port, 2907 _yahoo_webcam_get_server_connected, yid );2412 _yahoo_webcam_get_server_connected, yid, 0); 2908 2413 2909 2414 } … … 2952 2457 case YAHOO_SERVICE_IDDEACT: 2953 2458 case YAHOO_SERVICE_Y6_STATUS_UPDATE: 2954 case YAHOO_SERVICE_Y MSG15_STATUS:2459 case YAHOO_SERVICE_Y8_STATUS: 2955 2460 yahoo_process_status(yid, pkt); 2956 2461 break; … … 2966 2471 yahoo_process_mail(yid, pkt); 2967 2472 break; 2968 case YAHOO_SERVICE_REJECTCONTACT: 2473 case YAHOO_SERVICE_Y7_AUTHORIZATION: 2474 yahoo_process_new_contact(yid, pkt); 2475 break; 2969 2476 case YAHOO_SERVICE_NEWCONTACT: 2970 2477 yahoo_process_contact(yid, pkt); … … 3001 2508 break; 3002 2509 case YAHOO_SERVICE_P2PFILEXFER: 3003 case YAHOO_SERVICE_ FILETRANSFER:2510 case YAHOO_SERVICE_Y7_FILETRANSFER: 3004 2511 yahoo_process_filetransfer(yid, pkt); 2512 break; 2513 case YAHOO_SERVICE_Y7_FILETRANSFERINFO: 2514 yahoo_process_filetransferinfo(yid, pkt); 2515 break; 2516 case YAHOO_SERVICE_Y7_FILETRANSFERACCEPT: 2517 yahoo_process_filetransferaccept(yid, pkt); 3005 2518 break; 3006 2519 case YAHOO_SERVICE_ADDBUDDY: 3007 2520 yahoo_process_buddyadd(yid, pkt); 3008 break;3009 case YAHOO_SERVICE_CONTACT_YMSG13:3010 yahoo_process_contact_ymsg13(yid,pkt);3011 2521 break; 3012 2522 case YAHOO_SERVICE_REMBUDDY: … … 3025 2535 yahoo_process_ping(yid, pkt); 3026 2536 break; 2537 case YAHOO_SERVICE_Y7_CHANGE_GROUP: 2538 yahoo_process_buddy_change_group(yid, pkt); 2539 break; 3027 2540 case YAHOO_SERVICE_IDLE: 3028 2541 case YAHOO_SERVICE_MAILSTAT: … … 3038 2551 case YAHOO_SERVICE_CHATLOGOFF: 3039 2552 case YAHOO_SERVICE_CHATMSG: 2553 case YAHOO_SERVICE_REJECTCONTACT: 3040 2554 case YAHOO_SERVICE_PEERTOPEER: 3041 2555 WARNING(("unhandled service 0x%02x", pkt->service)); … … 3050 2564 case YAHOO_SERVICE_PICTURE_UPLOAD: 3051 2565 yahoo_process_picture_upload(yid, pkt); 3052 break; 3053 case YAHOO_SERVICE_Y MSG15_BUDDY_LIST: /* Buddy List */2566 break; 2567 case YAHOO_SERVICE_Y8_LIST: /* Buddy List */ 3054 2568 yahoo_process_buddy_list(yid, pkt); 2569 break; 3055 2570 default: 3056 2571 WARNING(("unknown service 0x%02x", pkt->service)); … … 3387 2902 3388 2903 /* find out what kind of packet we got */ 3389 switch (yid->wcd->packet_type) 3390 { 3391 case 0x00: 3392 /* user requests to view webcam (uploading) */ 3393 if (yid->wcd->data_size && 3394 yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) { 3395 end = begin; 3396 while (end <= yid->rxlen && 3397 yid->rxqueue[end++] != 13); 3398 if (end > begin) 3399 { 3400 who = y_memdup(yid->rxqueue + begin, end - begin); 3401 who[end - begin - 1] = 0; 3402 YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd->client_id, who + 2, 2); 3403 FREE(who); 3404 } 3405 } 3406 3407 if (yid->wcm->direction == YAHOO_WEBCAM_DOWNLOAD) { 3408 /* timestamp/status field */ 3409 /* 0 = declined viewing permission */ 3410 /* 1 = accepted viewing permission */ 3411 if (yid->wcd->timestamp == 0) { 3412 YAHOO_CALLBACK(ext_yahoo_webcam_closed) (yd->client_id, yid->wcm->user, 3); 3413 } 3414 } 3415 break; 3416 case 0x01: /* status packets?? */ 3417 /* timestamp contains status info */ 3418 /* 00 00 00 01 = we have data?? */ 3419 break; 3420 case 0x02: /* image data */ 3421 YAHOO_CALLBACK(ext_yahoo_got_webcam_image) (yd->client_id, 3422 yid->wcm->user, yid->rxqueue + begin, 3423 yid->wcd->data_size, pos - begin, 3424 yid->wcd->timestamp); 3425 break; 3426 case 0x05: /* response packets when uploading */ 3427 if (!yid->wcd->data_size) { 3428 YAHOO_CALLBACK(ext_yahoo_webcam_data_request) (yd->client_id, yid->wcd->timestamp); 3429 } 3430 break; 3431 case 0x07: /* connection is closing */ 3432 switch(reason) 3433 { 3434 case 0x01: /* user closed connection */ 3435 closed = 1; 3436 break; 3437 case 0x0F: /* user cancelled permission */ 3438 closed = 2; 3439 break; 3440 } 3441 YAHOO_CALLBACK(ext_yahoo_webcam_closed) (yd->client_id, yid->wcm->user, closed); 3442 break; 3443 case 0x0C: /* user connected */ 3444 case 0x0D: /* user disconnected */ 3445 if (yid->wcd->data_size) { 3446 who = y_memdup(yid->rxqueue + begin, pos - begin + 1); 3447 who[pos - begin] = 0; 3448 if (yid->wcd->packet_type == 0x0C) 3449 connect = 1; 3450 else 3451 connect = 0; 3452 YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd->client_id, who, connect); 2904 switch (yid->wcd->packet_type) { 2905 case 0x00: 2906 /* user requests to view webcam (uploading) */ 2907 if (yid->wcd->data_size && 2908 yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) { 2909 end = begin; 2910 while (end <= yid->rxlen && yid->rxqueue[end++] != 13) ; 2911 if (end > begin) { 2912 who = y_memdup(yid->rxqueue + begin, 2913 end - begin); 2914 who[end - begin - 1] = 0; 2915 YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd-> 2916 client_id, who + 2, 2); 3453 2917 FREE(who); 3454 2918 } 3455 break; 3456 case 0x13: /* user data */ 3457 /* i = user_ip (ip of the user we are viewing) */ 3458 /* j = user_ext_ip (external ip of the user we */ 3459 /* are viewing) */ 3460 break; 3461 case 0x17: /* ?? */ 3462 break; 2919 } 2920 2921 if (yid->wcm->direction == YAHOO_WEBCAM_DOWNLOAD) { 2922 /* timestamp/status field */ 2923 /* 0 = declined viewing permission */ 2924 /* 1 = accepted viewing permission */ 2925 if (yid->wcd->timestamp == 0) { 2926 YAHOO_CALLBACK(ext_yahoo_webcam_closed) (yd-> 2927 client_id, yid->wcm->user, 3); 2928 } 2929 } 2930 break; 2931 case 0x01: /* status packets?? */ 2932 /* timestamp contains status info */ 2933 /* 00 00 00 01 = we have data?? */ 2934 break; 2935 case 0x02: /* image data */ 2936 YAHOO_CALLBACK(ext_yahoo_got_webcam_image) (yd->client_id, 2937 yid->wcm->user, yid->rxqueue + begin, 2938 yid->wcd->data_size, pos - begin, yid->wcd->timestamp); 2939 break; 2940 case 0x05: /* response packets when uploading */ 2941 if (!yid->wcd->data_size) { 2942 YAHOO_CALLBACK(ext_yahoo_webcam_data_request) (yd-> 2943 client_id, yid->wcd->timestamp); 2944 } 2945 break; 2946 case 0x07: /* connection is closing */ 2947 switch (reason) { 2948 case 0x01: /* user closed connection */ 2949 closed = 1; 2950 break; 2951 case 0x0F: /* user cancelled permission */ 2952 closed = 2; 2953 break; 2954 } 2955 YAHOO_CALLBACK(ext_yahoo_webcam_closed) (yd->client_id, 2956 yid->wcm->user, closed); 2957 break; 2958 case 0x0C: /* user connected */ 2959 case 0x0D: /* user disconnected */ 2960 if (yid->wcd->data_size) { 2961 who = y_memdup(yid->rxqueue + begin, pos - begin + 1); 2962 who[pos - begin] = 0; 2963 if (yid->wcd->packet_type == 0x0C) 2964 connect = 1; 2965 else 2966 connect = 0; 2967 YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd->client_id, 2968 who, connect); 2969 FREE(who); 2970 } 2971 break; 2972 case 0x13: /* user data */ 2973 /* i=user_ip (ip of the user we are viewing) */ 2974 /* j=user_ext_ip (external ip of the user we */ 2975 /* are viewing) */ 2976 break; 2977 case 0x17: /* ?? */ 2978 break; 3463 2979 } 3464 2980 yid->wcd->to_read -= pos - begin; … … 3466 2982 yid->rxlen -= pos; 3467 2983 DEBUG_MSG(("rxlen == %d, rxqueue == %p", yid->rxlen, yid->rxqueue)); 3468 if (yid->rxlen >0) {2984 if (yid->rxlen > 0) { 3469 2985 unsigned char *tmp = y_memdup(yid->rxqueue + pos, yid->rxlen); 3470 2986 FREE(yid->rxqueue); 3471 2987 yid->rxqueue = tmp; 3472 DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, yid->rxqueue)); 2988 DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, 2989 yid->rxqueue)); 3473 2990 } else { 3474 2991 DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); … … 3483 3000 } 3484 3001 3485 int yahoo_write_ready(int id, intfd, void *data)3002 int yahoo_write_ready(int id, void *fd, void *data) 3486 3003 { 3487 3004 struct yahoo_input_data *yid = data; … … 3489 3006 struct data_queue *tx; 3490 3007 3491 LOG(("write callback: id=%d fd=% ddata=%p", id, fd, data));3492 if (!yid || !yid->txqueues || !find_conn_by_id(id))3008 LOG(("write callback: id=%d fd=%p data=%p", id, fd, data)); 3009 if (!yid || !yid->txqueues) 3493 3010 return -2; 3494 3011 3495 3012 tx = yid->txqueues->data; 3496 3013 LOG(("writing %d bytes", tx->len)); … … 3508 3025 free(tx->queue); 3509 3026 free(tx); 3510 yid->txqueues = y_list_remove_link(yid->txqueues, yid->txqueues); 3027 yid->txqueues = 3028 y_list_remove_link(yid->txqueues, 3029 yid->txqueues); 3511 3030 y_list_free_1(l); 3512 3031 } 3513 LOG(("yahoo_write_ready(%d, % d) len < 0", id, fd));3032 LOG(("yahoo_write_ready(%d, %p) len < 0", id, fd)); 3514 3033 YAHOO_CALLBACK(ext_yahoo_remove_handler) (id, yid->write_tag); 3515 3034 yid->write_tag = 0; … … 3528 3047 free(tx->queue); 3529 3048 free(tx); 3530 yid->txqueues = y_list_remove_link(yid->txqueues, yid->txqueues); 3049 yid->txqueues = 3050 y_list_remove_link(yid->txqueues, yid->txqueues); 3531 3051 y_list_free_1(l); 3532 3052 /* 3533 if(!yid->txqueues)3534 3535 */3053 if(!yid->txqueues) 3054 LOG(("yahoo_write_ready(%d, %d) !yxqueues", id, fd)); 3055 */ 3536 3056 if (!yid->txqueues) { 3537 LOG(("yahoo_write_ready(%d, %d) !yxqueues", id, fd)); 3538 YAHOO_CALLBACK(ext_yahoo_remove_handler) (id, yid->write_tag); 3057 LOG(("yahoo_write_ready(%d, %p) !txqueues", id, fd)); 3058 YAHOO_CALLBACK(ext_yahoo_remove_handler) (id, 3059 yid->write_tag); 3539 3060 yid->write_tag = 0; 3540 3061 } … … 3544 3065 } 3545 3066 3546 static void yahoo_process_pager_connection(struct yahoo_input_data *yid, int over) 3067 static void yahoo_process_pager_connection(struct yahoo_input_data *yid, 3068 int over) 3547 3069 { 3548 3070 struct yahoo_packet *pkt; … … 3553 3075 return; 3554 3076 3555 while (find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER) 3556 3077 while (find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER) 3078 && (pkt = yahoo_getdata(yid)) != NULL) { 3557 3079 3558 3080 yahoo_packet_process(yid, pkt); … … 3562 3084 } 3563 3085 3564 static void yahoo_process_ft_connection(struct yahoo_input_data *yid, int over) 3565 { 3566 } 3567 3568 static void yahoo_process_chatcat_connection(struct yahoo_input_data *yid, int over) 3086 static void yahoo_process_chatcat_connection(struct yahoo_input_data *yid, 3087 int over) 3569 3088 { 3570 3089 if (over) 3571 3090 return; 3572 3091 3573 if (strstr((char*)yid->rxqueue+(yid->rxlen-20), "</content>")) { 3574 YAHOO_CALLBACK(ext_yahoo_chat_cat_xml) (yid->yd->client_id, (char*)yid->rxqueue); 3092 if (strstr((char *)yid->rxqueue + (yid->rxlen - 20), "</content>")) { 3093 YAHOO_CALLBACK(ext_yahoo_chat_cat_xml) (yid->yd->client_id, 3094 (char *)yid->rxqueue); 3575 3095 } 3576 3096 } … … 3583 3103 int changed = 0; 3584 3104 int id = yd->client_id; 3105 int yab_used = 0; 3106 3107 LOG(("Got data for YAB")); 3585 3108 3586 3109 if (over) 3587 3110 return; 3588 3111 3589 while (find_input_by_id_and_type(id, YAHOO_CONNECTION_YAB) 3590 3112 while (find_input_by_id_and_type(id, YAHOO_CONNECTION_YAB) 3113 && (yab = yahoo_getyab(yid)) != NULL) { 3591 3114 if (!yab->id) 3592 3115 continue; 3116 3593 3117 changed = 1; 3118 yab_used = 0; 3594 3119 for (buds = yd->buddies; buds; buds = buds->next) { 3595 3120 struct yahoo_buddy *bud = buds->data; 3596 3121 if (!strcmp(bud->id, yab->id)) { 3122 yab_used = 1; 3597 3123 bud->yab_entry = yab; 3598 3124 if (yab->nname) { 3599 3125 bud->real_name = strdup(yab->nname); 3600 3126 } else if (yab->fname && yab->lname) { 3601 bud->real_name = y_new0(char, 3602 strlen(yab->fname)+ 3603 strlen(yab->lname)+2 3604 ); 3127 bud->real_name = y_new0(char, 3128 strlen(yab->fname) + 3129 strlen(yab->lname) + 2); 3605 3130 sprintf(bud->real_name, "%s %s", 3606 3131 yab->fname, yab->lname); 3607 3132 } else if (yab->fname) { 3608 3133 bud->real_name = strdup(yab->fname); 3609 3134 } 3610 break; 3135 break; /* for */ 3611 3136 } 3612 3137 } 3138 3139 if (!yab_used) { 3140 FREE(yab->fname); 3141 FREE(yab->lname); 3142 FREE(yab->nname); 3143 FREE(yab->id); 3144 FREE(yab->email); 3145 FREE(yab->hphone); 3146 FREE(yab->wphone); 3147 FREE(yab->mphone); 3148 FREE(yab); 3149 } 3150 3613 3151 } 3614 3152 3615 3153 if (changed) 3616 YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, yd->buddies); 3617 } 3618 3619 static void yahoo_process_search_connection(struct yahoo_input_data *yid, int over) 3154 YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, 3155 yd->buddies); 3156 } 3157 3158 static void yahoo_process_search_connection(struct yahoo_input_data *yid, 3159 int over) 3620 3160 { 3621 3161 struct yahoo_found_contact *yct = NULL; 3622 3162 char *p = (char *)yid->rxqueue, *np, *cp; 3623 3163 int k, n; 3624 int start = 0, found =0, total=0;3164 int start = 0, found = 0, total = 0; 3625 3165 YList *contacts = NULL; 3626 struct yahoo_input_data *pyid = find_input_by_id_and_type(yid->yd->client_id, YAHOO_CONNECTION_PAGER); 3166 struct yahoo_input_data *pyid = 3167 find_input_by_id_and_type(yid->yd->client_id, 3168 YAHOO_CONNECTION_PAGER); 3627 3169 3628 3170 if (!over || !pyid) … … 3635 3177 p++; 3636 3178 n = atoi(p); 3637 switch(k) { 3638 case 0: found = pyid->ys->lsearch_nfound = n; break; 3639 case 2: start = pyid->ys->lsearch_nstart = n; break; 3640 case 3: total = pyid->ys->lsearch_ntotal = n; break; 3179 switch (k) { 3180 case 0: 3181 found = pyid->ys->lsearch_nfound = n; 3182 break; 3183 case 2: 3184 start = pyid->ys->lsearch_nstart = n; 3185 break; 3186 case 3: 3187 total = pyid->ys->lsearch_ntotal = n; 3188 break; 3641 3189 } 3642 3190 } … … 3653 3201 break; 3654 3202 *np = 0; 3655 p = np+1; 3656 3657 switch(k++) { 3658 case 1: 3659 if (strlen(cp) > 2 && y_list_length(contacts) < total) { 3660 yct = y_new0(struct yahoo_found_contact, 1); 3661 contacts = y_list_append(contacts, yct); 3662 yct->id = cp+2; 3663 } else { 3664 *p = 0; 3665 } 3666 break; 3667 case 2: 3668 yct->online = !strcmp(cp, "2") ? 1 : 0; 3669 break; 3670 case 3: 3671 yct->gender = cp; 3672 break; 3673 case 4: 3674 yct->age = atoi(cp); 3675 break; 3676 case 5: 3677 if (strcmp(cp, "5") != 0) 3678 yct->location = cp; 3679 k = 0; 3680 break; 3203 p = np + 1; 3204 3205 switch (k++) { 3206 case 1: 3207 if (strlen(cp) > 2 3208 && y_list_length(contacts) < total) { 3209 yct = y_new0(struct yahoo_found_contact, 3210 1); 3211 contacts = y_list_append(contacts, yct); 3212 yct->id = cp + 2; 3213 } else { 3214 *p = 0; 3215 } 3216 break; 3217 case 2: 3218 yct->online = !strcmp(cp, "2") ? 1 : 0; 3219 break; 3220 case 3: 3221 yct->gender = cp; 3222 break; 3223 case 4: 3224 yct->age = atoi(cp); 3225 break; 3226 case 5: 3227 /* not worth the context switch for strcmp */ 3228 if (cp[0] != '\005' || cp[1] != '\000') 3229 yct->location = cp; 3230 k = 0; 3231 break; 3681 3232 } 3682 3233 } 3683 3234 } 3684 3235 3685 YAHOO_CALLBACK(ext_yahoo_got_search_result) (yid->yd->client_id, found, start, total, contacts); 3236 YAHOO_CALLBACK(ext_yahoo_got_search_result) (yid->yd->client_id, found, 3237 start, total, contacts); 3686 3238 3687 3239 while (contacts) { … … 3693 3245 } 3694 3246 3695 static void _yahoo_webcam_connected( intfd, int error, void *d)3247 static void _yahoo_webcam_connected(void *fd, int error, void *d) 3696 3248 { 3697 3249 struct yahoo_input_data *yid = d; … … 3701 3253 char *data = NULL; 3702 3254 char *packet = NULL; 3703 unsigned char magic_nr[] = { 1, 0, 0, 0, 1};3255 unsigned char magic_nr[] = { 1, 0, 0, 0, 1 }; 3704 3256 unsigned header_len = 0; 3705 3257 unsigned int len = 0; 3706 3258 unsigned int pos = 0; 3707 3259 3708 if (error || fd <= 0) {3260 if (error || !fd) { 3709 3261 FREE(yid); 3710 3262 return; … … 3716 3268 LOG(("Connected")); 3717 3269 /* send initial packet */ 3718 switch (wcm->direction) 3719 { 3720 case YAHOO_WEBCAM_DOWNLOAD: 3721 data = strdup("<REQIMG>"); 3722 break; 3723 case YAHOO_WEBCAM_UPLOAD: 3724 data = strdup("<SNDIMG>"); 3725 break; 3726 default: 3727 return; 3270 switch (wcm->direction) { 3271 case YAHOO_WEBCAM_DOWNLOAD: 3272 data = strdup("<REQIMG>"); 3273 break; 3274 case YAHOO_WEBCAM_UPLOAD: 3275 data = strdup("<SNDIMG>"); 3276 break; 3277 default: 3278 return; 3728 3279 } 3729 3280 yahoo_add_to_send_queue(yid, data, strlen(data)); … … 3731 3282 3732 3283 /* send data */ 3733 switch (wcm->direction) 3734 { 3735 case YAHOO_WEBCAM_DOWNLOAD: 3736 header_len = 8; 3737 data = strdup("a=2\r\nc=us\r\ne=21\r\nu="); 3738 data = y_string_append(data, yd->user); 3739 data = y_string_append(data, "\r\nt="); 3740 data = y_string_append(data, wcm->key); 3741 data = y_string_append(data, "\r\ni="); 3742 data = y_string_append(data, wcm->my_ip); 3743 data = y_string_append(data, "\r\ng="); 3744 data = y_string_append(data, wcm->user); 3745 data = y_string_append(data, "\r\no=w-2-5-1\r\np="); 3746 snprintf(conn_type, sizeof(conn_type), "%d", wcm->conn_type); 3747 data = y_string_append(data, conn_type); 3748 data = y_string_append(data, "\r\n"); 3749 break; 3750 case YAHOO_WEBCAM_UPLOAD: 3751 header_len = 13; 3752 data = strdup("a=2\r\nc=us\r\nu="); 3753 data = y_string_append(data, yd->user); 3754 data = y_string_append(data, "\r\nt="); 3755 data = y_string_append(data, wcm->key); 3756 data = y_string_append(data, "\r\ni="); 3757 data = y_string_append(data, wcm->my_ip); 3758 data = y_string_append(data, "\r\no=w-2-5-1\r\np="); 3759 snprintf(conn_type, sizeof(conn_type), "%d", wcm->conn_type); 3760 data = y_string_append(data, conn_type); 3761 data = y_string_append(data, "\r\nb="); 3762 data = y_string_append(data, wcm->description); 3763 data = y_string_append(data, "\r\n"); 3764 break; 3284 switch (wcm->direction) { 3285 case YAHOO_WEBCAM_DOWNLOAD: 3286 header_len = 8; 3287 data = strdup("a=2\r\nc=us\r\ne=21\r\nu="); 3288 data = y_string_append(data, yd->user); 3289 data = y_string_append(data, "\r\nt="); 3290 data = y_string_append(data, wcm->key); 3291 data = y_string_append(data, "\r\ni="); 3292 data = y_string_append(data, wcm->my_ip); 3293 data = y_string_append(data, "\r\ng="); 3294 data = y_string_append(data, wcm->user); 3295 data = y_string_append(data, "\r\no=w-2-5-1\r\np="); 3296 snprintf(conn_type, sizeof(conn_type), "%d", wcm->conn_type); 3297 data = y_string_append(data, conn_type); 3298 data = y_string_append(data, "\r\n"); 3299 break; 3300 case YAHOO_WEBCAM_UPLOAD: 3301 header_len = 13; 3302 data = strdup("a=2\r\nc=us\r\nu="); 3303 data = y_string_append(data, yd->user); 3304 data = y_string_append(data, "\r\nt="); 3305 data = y_string_append(data, wcm->key); 3306 data = y_string_append(data, "\r\ni="); 3307 data = y_string_append(data, wcm->my_ip); 3308 data = y_string_append(data, "\r\no=w-2-5-1\r\np="); 3309 snprintf(conn_type, sizeof(conn_type), "%d", wcm->conn_type); 3310 data = y_string_append(data, conn_type); 3311 data = y_string_append(data, "\r\nb="); 3312 data = y_string_append(data, wcm->description); 3313 data = y_string_append(data, "\r\n"); 3314 break; 3765 3315 } 3766 3316 … … 3769 3319 packet[pos++] = header_len; 3770 3320 packet[pos++] = 0; 3771 switch (wcm->direction) 3772 { 3773 case YAHOO_WEBCAM_DOWNLOAD: 3774 packet[pos++] = 1; 3775 packet[pos++] = 0; 3776 break; 3777 case YAHOO_WEBCAM_UPLOAD: 3778 packet[pos++] = 5; 3779 packet[pos++] = 0; 3780 break; 3321 switch (wcm->direction) { 3322 case YAHOO_WEBCAM_DOWNLOAD: 3323 packet[pos++] = 1; 3324 packet[pos++] = 0; 3325 break; 3326 case YAHOO_WEBCAM_UPLOAD: 3327 packet[pos++] = 5; 3328 packet[pos++] = 0; 3329 break; 3781 3330 } 3782 3331 3783 3332 pos += yahoo_put32(packet + pos, len); 3784 if (wcm->direction == YAHOO_WEBCAM_UPLOAD) 3785 { 3333 if (wcm->direction == YAHOO_WEBCAM_UPLOAD) { 3786 3334 memcpy(packet + pos, magic_nr, sizeof(magic_nr)); 3787 3335 pos += sizeof(magic_nr); … … 3792 3340 FREE(data); 3793 3341 3794 yid->read_tag = YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, yid->fd, YAHOO_INPUT_READ, yid); 3342 yid->read_tag = 3343 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, 3344 yid->fd, YAHOO_INPUT_READ, yid); 3795 3345 } 3796 3346 … … 3817 3367 3818 3368 LOG(("Connecting to: %s:%d", wcm->server, wcm->port)); 3819 YAHOO_CALLBACK(ext_yahoo_connect_async) (y->yd->client_id, wcm->server, wcm->port, 3820 _yahoo_webcam_connected, yid); 3821 3822 } 3823 3824 static void yahoo_process_webcam_master_connection(struct yahoo_input_data *yid, int over) 3825 { 3826 char* server; 3369 YAHOO_CALLBACK(ext_yahoo_connect_async) (y->yd->client_id, wcm->server, 3370 wcm->port, _yahoo_webcam_connected, yid, 0); 3371 3372 } 3373 3374 static void yahoo_process_webcam_master_connection(struct yahoo_input_data *yid, 3375 int over) 3376 { 3377 char *server; 3827 3378 struct yahoo_server_settings *yss; 3828 3379 … … 3832 3383 server = yahoo_getwebcam_master(yid); 3833 3384 3834 if (server) 3835 { 3385 if (server) { 3836 3386 yss = yid->yd->server_settings; 3837 3387 yid->wcm->server = strdup(server); … … 3846 3396 } 3847 3397 3848 static void yahoo_process_webcam_connection(struct yahoo_input_data *yid, int over) 3398 static void yahoo_process_webcam_connection(struct yahoo_input_data *yid, 3399 int over) 3849 3400 { 3850 3401 int id = yid->yd->client_id; 3851 intfd = yid->fd;3402 void *fd = yid->fd; 3852 3403 3853 3404 if (over) … … 3855 3406 3856 3407 /* as long as we still have packets available keep processing them */ 3857 while (find_input_by_id_and_fd(id, fd) 3858 && yahoo_get_webcam_data(yid) == 1); 3859 } 3860 3861 static void (*yahoo_process_connection[])(struct yahoo_input_data *, int over) = { 3862 yahoo_process_pager_connection, 3863 yahoo_process_ft_connection, 3864 yahoo_process_yab_connection, 3865 yahoo_process_webcam_master_connection, 3866 yahoo_process_webcam_connection, 3867 yahoo_process_chatcat_connection, 3868 yahoo_process_search_connection, 3869 }; 3870 3871 int yahoo_read_ready(int id, int fd, void *data) 3408 while (find_input_by_id_and_fd(id, fd) 3409 && yahoo_get_webcam_data(yid) == 1) ; 3410 } 3411 3412 static void (*yahoo_process_connection[]) (struct yahoo_input_data *, 3413 int over) = { 3414 yahoo_process_pager_connection, yahoo_process_ft_connection, 3415 yahoo_process_yab_connection, 3416 yahoo_process_webcam_master_connection, 3417 yahoo_process_webcam_connection, 3418 yahoo_process_chatcat_connection, 3419 yahoo_process_search_connection}; 3420 3421 int yahoo_read_ready(int id, void *fd, void *data) 3872 3422 { 3873 3423 struct yahoo_input_data *yid = data; … … 3875 3425 int len; 3876 3426 3877 LOG(("read callback: id=%d fd=% ddata=%p", id, fd, data));3427 LOG(("read callback: id=%d fd=%p data=%p", id, fd, data)); 3878 3428 if (!yid) 3879 3429 return -2; 3880 3430 3881 3882 3431 do { 3883 len = read(fd, buf, sizeof(buf));3432 len = YAHOO_CALLBACK(ext_yahoo_read) (fd, buf, sizeof(buf)); 3884 3433 } while (len == -1 && errno == EINTR); 3885 3434 3886 if (len == -1 && (errno == EAGAIN ||errno == EINTR)) /* we'll try again later */3435 if (len == -1 && (errno == EAGAIN || errno == EINTR)) /* we'll try again later */ 3887 3436 return 1; 3888 3437 … … 3892 3441 3893 3442 if (yid->type == YAHOO_CONNECTION_PAGER) { 3894 YAHOO_CALLBACK(ext_yahoo_error) (yid->yd->client_id, "Connection closed by server", 1, E_CONNECTION); 3895 } 3896 3897 yahoo_process_connection[yid->type](yid, 1); 3443 YAHOO_CALLBACK(ext_yahoo_login_response) (yid->yd-> 3444 client_id, YAHOO_LOGIN_SOCK, NULL); 3445 } 3446 3447 yahoo_process_connection[yid->type] (yid, 1); 3898 3448 yahoo_input_close(yid); 3899 3449 … … 3907 3457 } 3908 3458 3909 yid->rxqueue = y_renew(unsigned char, yid->rxqueue, len + yid->rxlen); 3459 yid->rxqueue = 3460 y_renew(unsigned char, yid->rxqueue, len + yid->rxlen + 1); 3910 3461 memcpy(yid->rxqueue + yid->rxlen, buf, len); 3911 3462 yid->rxlen += len; 3912 3913 yahoo_process_connection[yid->type](yid, 0); 3463 yid->rxqueue[yid->rxlen] = 0; 3464 3465 yahoo_process_connection[yid->type] (yid, 0); 3914 3466 3915 3467 return len; … … 3948 3500 } 3949 3501 3950 struct connect_callback_data { 3951 struct yahoo_data *yd; 3952 int tag; 3953 int i; 3954 }; 3955 3956 static void yahoo_connected(int fd, int error, void *data) 3502 static void yahoo_connected(void *fd, int error, void *data) 3957 3503 { 3958 3504 struct connect_callback_data *ccd = data; … … 3963 3509 3964 3510 if (error) { 3511 int tag; 3965 3512 if (fallback_ports[ccd->i]) { 3966 int tag; 3513 char *host = yss->pager_host; 3514 3515 if (!host) 3516 host = yss->pager_host_list[ccd->server_i]; 3517 3967 3518 yss->pager_port = fallback_ports[ccd->i++]; 3968 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, yss->pager_host, 3969 yss->pager_port, yahoo_connected, ccd); 3519 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd-> 3520 client_id, host, yss->pager_port, 3521 yahoo_connected, ccd, 0); 3970 3522 3971 3523 if (tag > 0) 3972 3524 ccd->tag = tag; 3525 } else if (yss->pager_host_list 3526 && yss->pager_host_list[ccd->server_i]) { 3527 3528 /* Get back to the default port */ 3529 yss->pager_port = pager_port; 3530 ccd->server_i++; 3531 LOG(("Fallback: Connecting to %s:%d", yss->pager_host_list[ccd->server_i], yss->pager_port)); 3532 3533 ccd->i = 0; 3534 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, 3535 yss->pager_host_list[ccd->server_i], yss->pager_port, 3536 yahoo_connected, ccd, 0); 3973 3537 } else { 3974 3538 FREE(ccd); 3975 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, YAHOO_LOGIN_SOCK, NULL); 3539 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 3540 YAHOO_LOGIN_SOCK, NULL); 3976 3541 } 3977 3542 return; … … 3980 3545 FREE(ccd); 3981 3546 3982 /* fd < 0 && error == 0 means connect was cancelled */ 3983 if (fd < 0) 3984 return; 3985 3986 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, yd->session_id); 3547 /* fd == NULL && error == 0 means connect was cancelled */ 3548 if (!fd) 3549 return; 3550 3551 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YPACKET_STATUS_DEFAULT, 3552 yd->session_id); 3987 3553 NOTICE(("Sending initial packet")); 3988 3554 3989 3555 yahoo_packet_hash(pkt, 1, yd->user); 3990 3556 3991 yid = y_new0(struct yahoo_input_data, 1); 3992 yid->yd = yd; 3557 yid = find_input_by_id_and_type(yd->client_id, YAHOO_CONNECTION_PAGER); 3993 3558 yid->fd = fd; 3994 inputs = y_list_prepend(inputs, yid);3995 3559 3996 3560 yahoo_send_packet(yid, pkt, 0); … … 3998 3562 yahoo_packet_free(pkt); 3999 3563 4000 yid->read_tag = YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, yid->fd, YAHOO_INPUT_READ, yid); 4001 } 4002 4003 void yahoo_login(int id, int initial) 4004 { 4005 struct yahoo_data *yd = find_conn_by_id(id); 4006 struct connect_callback_data *ccd; 4007 struct yahoo_server_settings *yss; 4008 int tag; 4009 4010 if (!yd) 4011 return; 4012 4013 yss = yd->server_settings; 4014 4015 yd->initial_status = initial; 4016 4017 ccd = y_new0(struct connect_callback_data, 1); 4018 ccd->yd = yd; 4019 tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, yss->pager_host, yss->pager_port, 4020 yahoo_connected, ccd); 4021 4022 /* 4023 * if tag <= 0, then callback has already been called 4024 * so ccd will have been freed 4025 */ 4026 if (tag > 0) 4027 ccd->tag = tag; 4028 else if (tag < 0) 4029 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, YAHOO_LOGIN_SOCK, NULL); 4030 } 4031 4032 4033 int yahoo_get_fd(int id) 4034 { 4035 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3564 yid->read_tag = 3565 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, 3566 yid->fd, YAHOO_INPUT_READ, yid); 3567 } 3568 3569 void *yahoo_get_fd(int id) 3570 { 3571 struct yahoo_input_data *yid = 3572 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4036 3573 if (!yid) 4037 3574 return 0; … … 4040 3577 } 4041 3578 4042 void yahoo_send_im(int id, const char *from, const char *who, const char *what, int utf8, int picture) 4043 { 4044 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3579 void yahoo_send_buzz(int id, const char *from, const char *who) 3580 { 3581 yahoo_send_im(id, from, who, "<ding>", 1, 0); 3582 } 3583 3584 void yahoo_send_im(int id, const char *from, const char *who, const char *what, 3585 int utf8, int picture) 3586 { 3587 struct yahoo_input_data *yid = 3588 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4045 3589 struct yahoo_packet *pkt = NULL; 4046 3590 struct yahoo_data *yd; … … 4052 3596 yd = yid->yd; 4053 3597 4054 pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, yd->session_id); 3598 pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 3599 yd->session_id); 4055 3600 4056 3601 snprintf(pic_str, sizeof(pic_str), "%d", picture); 4057 3602 4058 3603 if (from && strcmp(from, yd->user)) 4059 3604 yahoo_packet_hash(pkt, 0, yd->user); 4060 yahoo_packet_hash(pkt, 1, from ?from:yd->user);3605 yahoo_packet_hash(pkt, 1, from ? from : yd->user); 4061 3606 yahoo_packet_hash(pkt, 5, who); 4062 3607 yahoo_packet_hash(pkt, 14, what); … … 4069 3614 yahoo_packet_hash(pkt, 206, pic_str); 4070 3615 4071 4072 3616 yahoo_send_packet(yid, pkt, 0); 4073 3617 … … 4077 3621 void yahoo_send_typing(int id, const char *from, const char *who, int typ) 4078 3622 { 4079 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3623 struct yahoo_input_data *yid = 3624 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4080 3625 struct yahoo_data *yd; 4081 3626 struct yahoo_packet *pkt = NULL; … … 4084 3629 4085 3630 yd = yid->yd; 4086 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_NOTIFY, yd->session_id); 3631 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YPACKET_STATUS_NOTIFY, 3632 yd->session_id); 4087 3633 4088 3634 yahoo_packet_hash(pkt, 5, who); 4089 yahoo_packet_hash(pkt, 1, from ?from:yd->user);3635 yahoo_packet_hash(pkt, 1, from ? from : yd->user); 4090 3636 yahoo_packet_hash(pkt, 14, " "); 4091 3637 yahoo_packet_hash(pkt, 13, typ ? "1" : "0"); … … 4099 3645 void yahoo_set_away(int id, enum yahoo_status state, const char *msg, int away) 4100 3646 { 4101 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3647 struct yahoo_input_data *yid = 3648 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4102 3649 struct yahoo_data *yd; 4103 3650 struct yahoo_packet *pkt = NULL; … … 4109 3656 4110 3657 yd = yid->yd; 3658 4111 3659 old_status = yd->current_status; 4112 3660 yd->current_status = state; … … 4114 3662 /* Thank you libpurple :) */ 4115 3663 if (yd->current_status == YAHOO_STATUS_INVISIBLE) { 4116 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBILITY, YAHOO_STATUS_AVAILABLE, 0); 3664 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, 3665 YAHOO_STATUS_AVAILABLE, 0); 4117 3666 yahoo_packet_hash(pkt, 13, "2"); 4118 3667 yahoo_send_packet(yid, pkt, 0); … … 4122 3671 } 4123 3672 4124 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, yd->current_status, yd->session_id); 3673 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, 3674 yd->current_status, yd->session_id); 4125 3675 snprintf(s, sizeof(s), "%d", yd->current_status); 4126 3676 yahoo_packet_hash(pkt, 10, s); … … 4131 3681 4132 3682 if (old_status == YAHOO_STATUS_INVISIBLE) { 4133 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBILITY, YAHOO_STATUS_AVAILABLE, 0); 3683 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, 3684 YAHOO_STATUS_AVAILABLE, 0); 4134 3685 yahoo_packet_hash(pkt, 13, "1"); 4135 3686 yahoo_send_packet(yid, pkt, 0); … … 4140 3691 void yahoo_logoff(int id) 4141 3692 { 4142 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3693 struct yahoo_input_data *yid = 3694 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4143 3695 struct yahoo_data *yd; 4144 3696 struct yahoo_packet *pkt = NULL; … … 4154 3706 get to do this so it'll just leak memory. And the TCP 4155 3707 connection reset will hopefully be clear enough. */ 4156 pkt = yahoo_packet_new(YAHOO_SERVICE_LOGOFF, YAHOO_STATUS_AVAILABLE, yd->session_id); 3708 pkt = yahoo_packet_new(YAHOO_SERVICE_LOGOFF, 3709 YPACKET_STATUS_DEFAULT, yd->session_id); 4157 3710 yd->current_status = -1; 4158 3711 … … 4163 3716 } 4164 3717 4165 do {3718 /* do { 4166 3719 yahoo_input_close(yid); 4167 } while ((yid = find_input_by_id(id))); 3720 } while((yid = find_input_by_id(id)));*/ 3721 4168 3722 } 4169 3723 4170 3724 void yahoo_get_list(int id) 4171 3725 { 4172 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3726 struct yahoo_input_data *yid = 3727 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4173 3728 struct yahoo_data *yd; 4174 3729 struct yahoo_packet *pkt = NULL; … … 4178 3733 yd = yid->yd; 4179 3734 4180 pkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_AVAILABLE, yd->session_id); 3735 pkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YPACKET_STATUS_DEFAULT, 3736 yd->session_id); 4181 3737 yahoo_packet_hash(pkt, 1, yd->user); 4182 3738 if (pkt) { … … 4186 3742 } 4187 3743 4188 static void _yahoo_http_connected(int id, intfd, int error, void *data)3744 static void _yahoo_http_connected(int id, void *fd, int error, void *data) 4189 3745 { 4190 3746 struct yahoo_input_data *yid = data; 4191 if (fd <= 0) {3747 if (fd == NULL || error) { 4192 3748 inputs = y_list_remove(inputs, yid); 4193 3749 FREE(yid); … … 4196 3752 4197 3753 yid->fd = fd; 4198 yid->read_tag = YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, YAHOO_INPUT_READ, yid); 4199 } 4200 3754 yid->read_tag = 3755 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, 3756 YAHOO_INPUT_READ, yid); 3757 } 3758 3759 /* FIXME Get address book from address.yahoo.com instead */ 4201 3760 void yahoo_get_yab(int id) 4202 3761 { 3762 struct yahoo_data *yd = find_conn_by_id(id); 3763 struct yahoo_input_data *yid; 3764 char url[1024]; 3765 char buff[2048]; 3766 3767 if (!yd) 3768 return; 3769 3770 yid = y_new0(struct yahoo_input_data, 1); 3771 yid->yd = yd; 3772 yid->type = YAHOO_CONNECTION_YAB; 3773 3774 LOG(("Sending request for Address Book")); 3775 3776 snprintf(url, 1024, 3777 "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us" 3778 "&diffs=1&t=0&tags=short&rt=0&prog-ver=8.1.0.249&useutf8=1&legenc=codepage-1252"); 3779 3780 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); 3781 3782 inputs = y_list_prepend(inputs, yid); 3783 3784 yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, 3785 _yahoo_http_connected, yid); 3786 } 3787 3788 struct yahoo_post_data { 3789 struct yahoo_input_data *yid; 3790 char *data; 3791 }; 3792 3793 static void _yahoo_http_post_connected(int id, void *fd, int error, void *data) 3794 { 3795 struct yahoo_post_data *yad = data; 3796 struct yahoo_input_data *yid = yad->yid; 3797 char *buff = yad->data; 3798 3799 if (!fd) { 3800 inputs = y_list_remove(inputs, yid); 3801 FREE(yid); 3802 return; 3803 } 3804 3805 YAHOO_CALLBACK(ext_yahoo_write) (fd, buff, strlen(buff)); 3806 3807 yid->fd = fd; 3808 yid->read_tag = 3809 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, 3810 YAHOO_INPUT_READ, yid); 3811 3812 FREE(buff); 3813 FREE(yad); 3814 } 3815 3816 /* FIXME This is also likely affected */ 3817 void yahoo_set_yab(int id, struct yab *yab) 3818 { 3819 struct yahoo_post_data *yad = y_new0(struct yahoo_post_data, 1); 4203 3820 struct yahoo_data *yd = find_conn_by_id(id); 4204 3821 struct yahoo_input_data *yid; 4205 3822 char url[1024]; 4206 3823 char buff[1024]; 4207 4208 if (!yd) 4209 return; 4210 4211 yid = y_new0(struct yahoo_input_data, 1); 4212 yid->yd = yd; 4213 yid->type = YAHOO_CONNECTION_YAB; 4214 4215 snprintf(url, 1024, "http://insider.msg.yahoo.com/ycontent/?ab2=0"); 4216 4217 snprintf(buff, sizeof(buff), "Y=%s; T=%s", 4218 yd->cookie_y, yd->cookie_t); 4219 4220 inputs = y_list_prepend(inputs, yid); 4221 4222 yahoo_http_get(yid->yd->client_id, url, buff, 4223 _yahoo_http_connected, yid); 4224 } 4225 4226 void yahoo_set_yab(int id, struct yab *yab) 4227 { 4228 struct yahoo_data *yd = find_conn_by_id(id); 4229 struct yahoo_input_data *yid; 4230 char url[1024]; 4231 char buff[1024]; 4232 char *temp; 4233 int size = sizeof(url)-1; 3824 char post[1024]; 3825 int size = 0; 4234 3826 4235 3827 if (!yd) … … 4240 3832 yid->yd = yd; 4241 3833 4242 strncpy(url, "http://insider.msg.yahoo.com/ycontent/?addab2=0", size); 4243 4244 if (yab->dbid) { 4245 /* change existing yab */ 4246 char tmp[32]; 4247 strncat(url, "&ee=1&ow=1&id=", size - strlen(url)); 4248 snprintf(tmp, sizeof(tmp), "%d", yab->dbid); 4249 strncat(url, tmp, size - strlen(url)); 4250 } 4251 4252 if (yab->fname) { 4253 strncat(url, "&fn=", size - strlen(url)); 4254 temp = yahoo_urlencode(yab->fname); 4255 strncat(url, temp, size - strlen(url)); 4256 free(temp); 4257 } 4258 if (yab->lname) { 4259 strncat(url, "&ln=", size - strlen(url)); 4260 temp = yahoo_urlencode(yab->lname); 4261 strncat(url, temp, size - strlen(url)); 4262 free(temp); 4263 } 4264 strncat(url, "&yid=", size - strlen(url)); 4265 temp = yahoo_urlencode(yab->id); 4266 strncat(url, temp, size - strlen(url)); 4267 free(temp); 4268 if (yab->nname) { 4269 strncat(url, "&nn=", size - strlen(url)); 4270 temp = yahoo_urlencode(yab->nname); 4271 strncat(url, temp, size - strlen(url)); 4272 free(temp); 4273 } 4274 if (yab->email) { 4275 strncat(url, "&e=", size - strlen(url)); 4276 temp = yahoo_urlencode(yab->email); 4277 strncat(url, temp, size - strlen(url)); 4278 free(temp); 4279 } 4280 if (yab->hphone) { 4281 strncat(url, "&hp=", size - strlen(url)); 4282 temp = yahoo_urlencode(yab->hphone); 4283 strncat(url, temp, size - strlen(url)); 4284 free(temp); 4285 } 4286 if (yab->wphone) { 4287 strncat(url, "&wp=", size - strlen(url)); 4288 temp = yahoo_urlencode(yab->wphone); 4289 strncat(url, temp, size - strlen(url)); 4290 free(temp); 4291 } 4292 if (yab->mphone) { 4293 strncat(url, "&mp=", size - strlen(url)); 4294 temp = yahoo_urlencode(yab->mphone); 4295 strncat(url, temp, size - strlen(url)); 4296 free(temp); 4297 } 4298 strncat(url, "&pp=0", size - strlen(url)); 4299 4300 snprintf(buff, sizeof(buff), "Y=%s; T=%s", 4301 yd->cookie_y, yd->cookie_t); 3834 if(yab->yid) 3835 size = snprintf(post, sizeof(post), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 3836 "<ab k=\"%s\" cc=\"%d\">" 3837 "<ct id=\"%d\" e=\"1\" yi=\"%s\" nn=\"%s\" />" 3838 "</ab>", yd->user, 9, yab->yid, /* Don't know why */ 3839 yab->id, yab->nname?yab->nname:""); 3840 else 3841 size = snprintf(post, sizeof(post), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 3842 "<ab k=\"%s\" cc=\"%d\">" 3843 "<ct a=\"1\" yi=\"%s\" nn=\"%s\" />" 3844 "</ab>", yd->user, 1, /* Don't know why */ 3845 yab->id, yab->nname?yab->nname:""); 3846 3847 yad->yid = yid; 3848 yad->data = strdup(post); 3849 3850 strcpy(url, "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us" 3851 "&sync=1&tags=short&noclear=1&useutf8=1&legenc=codepage-1252"); 3852 3853 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); 4302 3854 4303 3855 inputs = y_list_prepend(inputs, yid); 4304 3856 4305 yahoo_http_ get(yid->yd->client_id, url, buff,4306 _yahoo_http_connected, yid);3857 yahoo_http_post(yid->yd->client_id, url, buff, size, 3858 _yahoo_http_post_connected, yad); 4307 3859 } 4308 3860 4309 3861 void yahoo_set_identity_status(int id, const char *identity, int active) 4310 3862 { 4311 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3863 struct yahoo_input_data *yid = 3864 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4312 3865 struct yahoo_data *yd; 4313 3866 struct yahoo_packet *pkt = NULL; … … 4317 3870 yd = yid->yd; 4318 3871 4319 pkt = yahoo_packet_new(active ?YAHOO_SERVICE_IDACT:YAHOO_SERVICE_IDDEACT,4320 YAHOO_STATUS_AVAILABLE, yd->session_id);3872 pkt = yahoo_packet_new(active ? YAHOO_SERVICE_IDACT : 3873 YAHOO_SERVICE_IDDEACT, YPACKET_STATUS_DEFAULT, yd->session_id); 4321 3874 yahoo_packet_hash(pkt, 3, identity); 4322 3875 if (pkt) { … … 4328 3881 void yahoo_refresh(int id) 4329 3882 { 4330 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3883 struct yahoo_input_data *yid = 3884 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4331 3885 struct yahoo_data *yd; 4332 3886 struct yahoo_packet *pkt = NULL; … … 4336 3890 yd = yid->yd; 4337 3891 4338 pkt = yahoo_packet_new(YAHOO_SERVICE_USERSTAT, YAHOO_STATUS_AVAILABLE, yd->session_id); 3892 pkt = yahoo_packet_new(YAHOO_SERVICE_USERSTAT, YPACKET_STATUS_DEFAULT, 3893 yd->session_id); 4339 3894 if (pkt) { 4340 3895 yahoo_send_packet(yid, pkt, 0); … … 4345 3900 void yahoo_keepalive(int id) 4346 3901 { 4347 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3902 struct yahoo_input_data *yid = 3903 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4348 3904 struct yahoo_data *yd; 4349 3905 struct yahoo_packet *pkt = NULL; … … 4352 3908 yd = yid->yd; 4353 3909 4354 pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, yd->session_id); 3910 pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YPACKET_STATUS_DEFAULT, 3911 yd->session_id); 4355 3912 yahoo_send_packet(yid, pkt, 0); 4356 3913 yahoo_packet_free(pkt); 4357 3914 } 4358 3915 4359 void yahoo_chat_keepalive (int id) 4360 { 4361 struct yahoo_input_data *yid = find_input_by_id_and_type (id, YAHOO_CONNECTION_PAGER); 3916 void yahoo_chat_keepalive(int id) 3917 { 3918 struct yahoo_input_data *yid = 3919 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4362 3920 struct yahoo_data *yd; 4363 3921 struct yahoo_packet *pkt = NULL; 4364 3922 4365 3923 if (!yid) 4366 3924 return; 4367 3925 4368 3926 yd = yid->yd; 4369 3927 4370 pkt = yahoo_packet_new (YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, yd->session_id); 4371 yahoo_send_packet (yid, pkt, 0); 4372 yahoo_packet_free (pkt); 4373 } 4374 4375 void yahoo_add_buddy(int id, const char *who, const char *group, const char *msg) 4376 { 4377 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3928 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YPACKET_STATUS_DEFAULT, 3929 yd->session_id); 3930 yahoo_send_packet(yid, pkt, 0); 3931 yahoo_packet_free(pkt); 3932 } 3933 3934 void yahoo_add_buddy(int id, const char *who, const char *group, 3935 const char *msg) 3936 { 3937 struct yahoo_input_data *yid = 3938 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4378 3939 struct yahoo_data *yd; 4379 3940 struct yahoo_packet *pkt; … … 4386 3947 return; 4387 3948 4388 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YPACKET_STATUS_DEFAULT, yd->session_id);4389 4390 if (msg != NULL) 3949 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YPACKET_STATUS_DEFAULT, 3950 yd->session_id); 3951 if (msg != NULL) /* add message/request "it's me add me" */ 4391 3952 yahoo_packet_hash(pkt, 14, msg); 4392 3953 else 4393 yahoo_packet_hash(pkt,14,""); 4394 3954 yahoo_packet_hash(pkt, 14, ""); 4395 3955 yahoo_packet_hash(pkt, 65, group); 4396 3956 yahoo_packet_hash(pkt, 97, "1"); … … 4402 3962 yahoo_packet_hash(pkt, 301, "319"); 4403 3963 yahoo_packet_hash(pkt, 303, "319"); 4404 4405 4406 3964 yahoo_send_packet(yid, pkt, 0); 4407 3965 yahoo_packet_free(pkt); … … 4410 3968 void yahoo_remove_buddy(int id, const char *who, const char *group) 4411 3969 { 4412 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3970 struct yahoo_input_data *yid = 3971 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4413 3972 struct yahoo_data *yd; 4414 3973 struct yahoo_packet *pkt = NULL; … … 4418 3977 yd = yid->yd; 4419 3978 4420 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, yd->session_id); 3979 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YPACKET_STATUS_DEFAULT, 3980 yd->session_id); 4421 3981 4422 3982 yahoo_packet_hash(pkt, 1, yd->user); … … 4427 3987 } 4428 3988 4429 void yahoo_accept_buddy_ymsg13(int id,const char* me,const char* who){ 4430 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 3989 void yahoo_confirm_buddy(int id, const char *who, int reject, const char *msg) 3990 { 3991 struct yahoo_input_data *yid = 3992 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4431 3993 struct yahoo_data *yd; 3994 struct yahoo_packet *pkt; 4432 3995 4433 3996 if (!yid) … … 4435 3998 yd = yid->yd; 4436 3999 4437 struct yahoo_packet* pkt = NULL; 4438 pkt= yahoo_packet_new(YAHOO_SERVICE_CONTACT_YMSG13,YAHOO_STATUS_AVAILABLE,0); 4439 4440 yahoo_packet_hash(pkt,1,me ?: yd->user); 4441 yahoo_packet_hash(pkt,5,who); 4442 yahoo_packet_hash(pkt,13,"1"); 4443 yahoo_packet_hash(pkt,334,"0"); 4000 if (!yd->logged_in) 4001 return; 4002 4003 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_AUTHORIZATION, 4004 YPACKET_STATUS_DEFAULT, yd->session_id); 4005 yahoo_packet_hash(pkt, 1, yd->user); 4006 yahoo_packet_hash(pkt, 5, who); 4007 if (reject) 4008 yahoo_packet_hash(pkt, 13, "2"); 4009 else { 4010 yahoo_packet_hash(pkt, 241, "0"); 4011 yahoo_packet_hash(pkt, 13, "1"); 4012 } 4013 4014 yahoo_packet_hash(pkt, 334, "0"); 4015 4016 if (reject) { 4017 yahoo_packet_hash(pkt, 14, msg ? msg : ""); 4018 yahoo_packet_hash(pkt, 97, "1"); 4019 } 4020 4444 4021 yahoo_send_packet(yid, pkt, 0); 4445 4022 yahoo_packet_free(pkt); 4446 4023 } 4447 4024 4448 void yahoo_reject_buddy_ymsg13(int id,const char* me,const char* who,const char* msg){ 4449 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4025 void yahoo_ignore_buddy(int id, const char *who, int unignore) 4026 { 4027 struct yahoo_input_data *yid = 4028 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4450 4029 struct yahoo_data *yd; 4030 struct yahoo_packet *pkt; 4451 4031 4452 4032 if (!yid) … … 4454 4034 yd = yid->yd; 4455 4035 4456 struct yahoo_packet* pkt = NULL; 4457 pkt= yahoo_packet_new(YAHOO_SERVICE_CONTACT_YMSG13,YAHOO_STATUS_AVAILABLE,0); 4458 4459 yahoo_packet_hash(pkt,1,me ?: yd->user); 4460 yahoo_packet_hash(pkt,5,who); 4461 // yahoo_packet_hash(pkt,241,YAHOO_PROTO_VER); 4462 yahoo_packet_hash(pkt,13,"2"); 4463 yahoo_packet_hash(pkt,334,"0"); 4464 yahoo_packet_hash(pkt,97,"1"); 4465 yahoo_packet_hash(pkt,14,msg?:""); 4466 4036 if (!yd->logged_in) 4037 return; 4038 4039 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, 4040 YPACKET_STATUS_DEFAULT, yd->session_id); 4041 yahoo_packet_hash(pkt, 1, yd->user); 4042 yahoo_packet_hash(pkt, 7, who); 4043 yahoo_packet_hash(pkt, 13, unignore ? "2" : "1"); 4467 4044 yahoo_send_packet(yid, pkt, 0); 4468 4045 yahoo_packet_free(pkt); 4469 4470 } 4471 4472 void yahoo_reject_buddy(int id, const char *who, const char *msg) 4473 { 4474 struct yahoo_input_data *yid =find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);4046 } 4047 4048 void yahoo_stealth_buddy(int id, const char *who, int unstealth) 4049 { 4050 struct yahoo_input_data *yid = 4051 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4475 4052 struct yahoo_data *yd; 4476 4053 struct yahoo_packet *pkt; … … 4483 4060 return; 4484 4061 4485 pkt = yahoo_packet_new(YAHOO_SERVICE_REJECTCONTACT, YAHOO_STATUS_AVAILABLE, yd->session_id); 4062 pkt = yahoo_packet_new(YAHOO_SERVICE_STEALTH_PERM, 4063 YPACKET_STATUS_DEFAULT, yd->session_id); 4486 4064 yahoo_packet_hash(pkt, 1, yd->user); 4487 4065 yahoo_packet_hash(pkt, 7, who); 4488 yahoo_packet_hash(pkt, 14, msg); 4489 yahoo_send_packet(yid, pkt, 0); 4490 yahoo_packet_free(pkt); 4491 } 4492 4493 void yahoo_ignore_buddy(int id, const char *who, int unignore) 4494 { 4495 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4496 struct yahoo_data *yd; 4497 struct yahoo_packet *pkt; 4498 4499 if (!yid) 4500 return; 4501 yd = yid->yd; 4502 4503 if (!yd->logged_in) 4504 return; 4505 4506 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, yd->session_id); 4507 yahoo_packet_hash(pkt, 1, yd->user); 4508 yahoo_packet_hash(pkt, 7, who); 4509 yahoo_packet_hash(pkt, 13, unignore?"2":"1"); 4510 yahoo_send_packet(yid, pkt, 0); 4511 yahoo_packet_free(pkt); 4512 } 4513 4514 void yahoo_stealth_buddy(int id, const char *who, int unstealth) 4515 { 4516 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4517 struct yahoo_data *yd; 4518 struct yahoo_packet *pkt; 4519 4520 if (!yid) 4521 return; 4522 yd = yid->yd; 4523 4524 if (!yd->logged_in) 4525 return; 4526 4527 pkt = yahoo_packet_new(YAHOO_SERVICE_STEALTH, YAHOO_STATUS_AVAILABLE, yd->session_id); 4528 yahoo_packet_hash(pkt, 1, yd->user); 4529 yahoo_packet_hash(pkt, 7, who); 4530 yahoo_packet_hash(pkt, 31, unstealth?"2":"1"); 4066 yahoo_packet_hash(pkt, 31, unstealth ? "2" : "1"); 4531 4067 yahoo_packet_hash(pkt, 13, "2"); 4532 4068 yahoo_send_packet(yid, pkt, 0); … … 4534 4070 } 4535 4071 4536 void yahoo_change_buddy_group(int id, const char *who, const char *old_group, const char *new_group) 4537 { 4538 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4072 void yahoo_change_buddy_group(int id, const char *who, const char *old_group, 4073 const char *new_group) 4074 { 4075 struct yahoo_input_data *yid = 4076 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4539 4077 struct yahoo_data *yd; 4540 4078 struct yahoo_packet *pkt = NULL; … … 4544 4082 yd = yid->yd; 4545 4083 4546 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, yd->session_id); 4084 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_CHANGE_GROUP, 4085 YPACKET_STATUS_DEFAULT, yd->session_id); 4547 4086 yahoo_packet_hash(pkt, 1, yd->user); 4087 yahoo_packet_hash(pkt, 302, "240"); 4088 yahoo_packet_hash(pkt, 300, "240"); 4548 4089 yahoo_packet_hash(pkt, 7, who); 4549 yahoo_packet_hash(pkt, 65, new_group); 4550 yahoo_packet_hash(pkt, 14, " "); 4090 yahoo_packet_hash(pkt, 224, old_group); 4091 yahoo_packet_hash(pkt, 264, new_group); 4092 yahoo_packet_hash(pkt, 301, "240"); 4093 yahoo_packet_hash(pkt, 303, "240"); 4551 4094 4552 4095 yahoo_send_packet(yid, pkt, 0); 4553 4096 yahoo_packet_free(pkt); 4554 4555 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, yd->session_id);4556 yahoo_packet_hash(pkt, 1, yd->user);4557 yahoo_packet_hash(pkt, 7, who);4558 yahoo_packet_hash(pkt, 65, old_group);4559 yahoo_send_packet(yid, pkt, 0);4560 yahoo_packet_free(pkt);4561 4097 } 4562 4098 4563 4099 void yahoo_group_rename(int id, const char *old_group, const char *new_group) 4564 4100 { 4565 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4101 struct yahoo_input_data *yid = 4102 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4566 4103 struct yahoo_data *yd; 4567 4104 struct yahoo_packet *pkt = NULL; … … 4571 4108 yd = yid->yd; 4572 4109 4573 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, yd->session_id); 4110 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, 4111 YPACKET_STATUS_DEFAULT, yd->session_id); 4574 4112 yahoo_packet_hash(pkt, 1, yd->user); 4575 4113 yahoo_packet_hash(pkt, 65, old_group); … … 4580 4118 } 4581 4119 4582 void yahoo_conference_addinvite(int id, const char *from, const char *who, const char *room, const YList *members, const char *msg) 4583 { 4584 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4120 void yahoo_conference_addinvite(int id, const char *from, const char *who, 4121 const char *room, const YList *members, const char *msg) 4122 { 4123 struct yahoo_input_data *yid = 4124 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4585 4125 struct yahoo_data *yd; 4586 4126 struct yahoo_packet *pkt; 4587 4127 4588 4128 if (!yid) 4589 4129 return; 4590 4130 yd = yid->yd; 4591 4131 4592 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, yd->session_id); 4593 4594 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4132 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, 4133 YPACKET_STATUS_DEFAULT, yd->session_id); 4134 4135 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4595 4136 yahoo_packet_hash(pkt, 51, who); 4596 4137 yahoo_packet_hash(pkt, 57, room); … … 4608 4149 } 4609 4150 4610 void yahoo_conference_invite(int id, const char *from, YList *who, const char *room, const char *msg) 4611 { 4612 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4151 void yahoo_conference_invite(int id, const char *from, YList *who, 4152 const char *room, const char *msg) 4153 { 4154 struct yahoo_input_data *yid = 4155 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4613 4156 struct yahoo_data *yd; 4614 4157 struct yahoo_packet *pkt; 4615 4158 4616 4159 if (!yid) 4617 4160 return; 4618 4161 yd = yid->yd; 4619 4162 4620 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFINVITE, YAHOO_STATUS_AVAILABLE, yd->session_id); 4621 4622 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4163 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFINVITE, YPACKET_STATUS_DEFAULT, 4164 yd->session_id); 4165 4166 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4623 4167 yahoo_packet_hash(pkt, 50, yd->user); 4624 4168 for (; who; who = who->next) { … … 4634 4178 } 4635 4179 4636 void yahoo_conference_logon(int id, const char *from, YList *who, const char *room) 4637 { 4638 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4180 void yahoo_conference_logon(int id, const char *from, YList *who, 4181 const char *room) 4182 { 4183 struct yahoo_input_data *yid = 4184 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4639 4185 struct yahoo_data *yd; 4640 4186 struct yahoo_packet *pkt; 4641 4187 4642 4188 if (!yid) 4643 4189 return; 4644 4190 yd = yid->yd; 4645 4191 4646 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YAHOO_STATUS_AVAILABLE, yd->session_id); 4647 4648 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4649 for (; who; who = who->next) { 4192 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YPACKET_STATUS_DEFAULT, 4193 yd->session_id); 4194 4195 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4196 yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); 4197 yahoo_packet_hash(pkt, 57, room); 4198 for (; who; who = who->next) 4650 4199 yahoo_packet_hash(pkt, 3, (char *)who->data); 4651 }4652 yahoo_packet_hash(pkt, 57, room);4653 4200 4654 4201 yahoo_send_packet(yid, pkt, 0); … … 4657 4204 } 4658 4205 4659 void yahoo_conference_decline(int id, const char *from, YList *who, const char *room, const char *msg) 4660 { 4661 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4206 void yahoo_conference_decline(int id, const char *from, YList *who, 4207 const char *room, const char *msg) 4208 { 4209 struct yahoo_input_data *yid = 4210 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4662 4211 struct yahoo_data *yd; 4663 4212 struct yahoo_packet *pkt; 4664 4213 4665 4214 if (!yid) 4666 4215 return; 4667 4216 yd = yid->yd; 4668 4217 4669 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFDECLINE, YAHOO_STATUS_AVAILABLE, yd->session_id); 4670 4671 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4672 for (; who; who = who->next) { 4218 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFDECLINE, 4219 YPACKET_STATUS_DEFAULT, yd->session_id); 4220 4221 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4222 yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); 4223 for (; who; who = who->next) 4673 4224 yahoo_packet_hash(pkt, 3, (char *)who->data); 4674 }4675 4225 yahoo_packet_hash(pkt, 57, room); 4676 4226 yahoo_packet_hash(pkt, 14, msg); … … 4681 4231 } 4682 4232 4683 void yahoo_conference_logoff(int id, const char *from, YList *who, const char *room) 4684 { 4685 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4233 void yahoo_conference_logoff(int id, const char *from, YList *who, 4234 const char *room) 4235 { 4236 struct yahoo_input_data *yid = 4237 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4686 4238 struct yahoo_data *yd; 4687 4239 struct yahoo_packet *pkt; 4688 4240 4689 4241 if (!yid) 4690 4242 return; 4691 4243 yd = yid->yd; 4692 4244 4693 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YAHOO_STATUS_AVAILABLE, yd->session_id); 4694 4695 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4696 for (; who; who = who->next) { 4245 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YPACKET_STATUS_DEFAULT, 4246 yd->session_id); 4247 4248 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4249 yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); 4250 for (; who; who = who->next) 4697 4251 yahoo_packet_hash(pkt, 3, (char *)who->data); 4698 } 4252 4699 4253 yahoo_packet_hash(pkt, 57, room); 4700 4254 … … 4704 4258 } 4705 4259 4706 void yahoo_conference_message(int id, const char *from, YList *who, const char *room, const char *msg, int utf8) 4707 { 4708 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4260 void yahoo_conference_message(int id, const char *from, YList *who, 4261 const char *room, const char *msg, int utf8) 4262 { 4263 struct yahoo_input_data *yid = 4264 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4709 4265 struct yahoo_data *yd; 4710 4266 struct yahoo_packet *pkt; 4711 4267 4712 4268 if (!yid) 4713 4269 return; 4714 4270 yd = yid->yd; 4715 4271 4716 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, yd->session_id); 4717 4718 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4719 for (; who; who = who->next) { 4272 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YPACKET_STATUS_DEFAULT, 4273 yd->session_id); 4274 4275 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4276 yahoo_packet_hash(pkt, 53, (from ? from : yd->user)); 4277 for (; who; who = who->next) 4720 4278 yahoo_packet_hash(pkt, 53, (char *)who->data); 4721 } 4279 4722 4280 yahoo_packet_hash(pkt, 57, room); 4723 4281 yahoo_packet_hash(pkt, 14, msg); … … 4746 4304 4747 4305 if (chatroomid == 0) { 4748 snprintf(url, 1024, "http://insider.msg.yahoo.com/ycontent/?chatcat=0"); 4306 snprintf(url, 1024, 4307 "http://insider.msg.yahoo.com/ycontent/?chatcat=0"); 4749 4308 } else { 4750 snprintf(url, 1024, "http://insider.msg.yahoo.com/ycontent/?chatroom_%d=0",chatroomid); 4309 snprintf(url, 1024, 4310 "http://insider.msg.yahoo.com/ycontent/?chatroom_%d=0", 4311 chatroomid); 4751 4312 } 4752 4313 … … 4755 4316 inputs = y_list_prepend(inputs, yid); 4756 4317 4757 yahoo_http_get(yid->yd->client_id, url, buff, _yahoo_http_connected, yid); 4758 } 4759 4760 void yahoo_chat_logon(int id, const char *from, const char *room, const char *roomid) 4761 { 4762 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4318 yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, 4319 _yahoo_http_connected, yid); 4320 } 4321 4322 void yahoo_chat_logon(int id, const char *from, const char *room, 4323 const char *roomid) 4324 { 4325 struct yahoo_input_data *yid = 4326 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4763 4327 struct yahoo_data *yd; 4764 4328 struct yahoo_packet *pkt; 4765 4329 4766 4330 if (!yid) 4767 4331 return; … … 4769 4333 yd = yid->yd; 4770 4334 4771 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YAHOO_STATUS_AVAILABLE, yd->session_id); 4772 4773 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4335 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YPACKET_STATUS_DEFAULT, 4336 yd->session_id); 4337 4338 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4774 4339 yahoo_packet_hash(pkt, 109, yd->user); 4775 4340 yahoo_packet_hash(pkt, 6, "abcde"); … … 4779 4344 yahoo_packet_free(pkt); 4780 4345 4781 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, yd->session_id); 4782 4783 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4346 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YPACKET_STATUS_DEFAULT, 4347 yd->session_id); 4348 4349 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4784 4350 yahoo_packet_hash(pkt, 104, room); 4785 4351 yahoo_packet_hash(pkt, 129, roomid); 4786 yahoo_packet_hash(pkt, 62, "2"); 4352 yahoo_packet_hash(pkt, 62, "2"); /* ??? */ 4787 4353 4788 4354 yahoo_send_packet(yid, pkt, 0); … … 4791 4357 } 4792 4358 4793 4794 void yahoo_chat_message(int id, const char *from, const char *room, const char *msg, const int msgtype, const int utf8) 4795 { 4796 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4359 void yahoo_chat_message(int id, const char *from, const char *room, 4360 const char *msg, const int msgtype, const int utf8) 4361 { 4362 struct yahoo_input_data *yid = 4363 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4797 4364 struct yahoo_data *yd; 4798 4365 struct yahoo_packet *pkt; 4799 4366 char buf[2]; 4800 4367 4801 4368 if (!yid) 4802 4369 return; … … 4804 4371 yd = yid->yd; 4805 4372 4806 pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, yd->session_id); 4807 4808 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4373 pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YPACKET_STATUS_DEFAULT, 4374 yd->session_id); 4375 4376 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4809 4377 yahoo_packet_hash(pkt, 104, room); 4810 4378 yahoo_packet_hash(pkt, 117, msg); 4811 4379 4812 4380 snprintf(buf, sizeof(buf), "%d", msgtype); 4813 4381 yahoo_packet_hash(pkt, 124, buf); … … 4821 4389 } 4822 4390 4823 4824 4391 void yahoo_chat_logoff(int id, const char *from) 4825 4392 { 4826 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4393 struct yahoo_input_data *yid = 4394 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4827 4395 struct yahoo_data *yd; 4828 4396 struct yahoo_packet *pkt; 4829 4397 4830 4398 if (!yid) 4831 4399 return; … … 4833 4401 yd = yid->yd; 4834 4402 4835 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, YAHOO_STATUS_AVAILABLE, yd->session_id); 4836 4837 yahoo_packet_hash(pkt, 1, (from?from:yd->user)); 4403 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, YPACKET_STATUS_DEFAULT, 4404 yd->session_id); 4405 4406 yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); 4838 4407 4839 4408 yahoo_send_packet(yid, pkt, 0); … … 4844 4413 void yahoo_buddyicon_request(int id, const char *who) 4845 4414 { 4846 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4415 struct yahoo_input_data *yid = 4416 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4847 4417 struct yahoo_data *yd; 4848 4418 struct yahoo_packet *pkt; 4849 4419 4850 if ( !yid)4420 if (!yid) 4851 4421 return; 4852 4422 4853 4423 yd = yid->yd; 4854 4855 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); 4424 4425 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YPACKET_STATUS_DEFAULT, 4426 0); 4856 4427 yahoo_packet_hash(pkt, 4, yd->user); 4857 4428 yahoo_packet_hash(pkt, 5, who); … … 4862 4433 } 4863 4434 4864 void yahoo_send_picture_info(int id, const char *who, const char *url, int checksum) 4865 { 4866 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4435 void yahoo_send_picture_info(int id, const char *who, const char *url, 4436 int checksum) 4437 { 4438 struct yahoo_input_data *yid = 4439 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4867 4440 struct yahoo_data *yd; 4868 4441 struct yahoo_packet *pkt; 4869 4442 char checksum_str[10]; 4870 4443 4871 if ( !yid)4444 if (!yid) 4872 4445 return; 4873 4446 … … 4876 4449 snprintf(checksum_str, sizeof(checksum_str), "%d", checksum); 4877 4450 4878 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); 4451 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YPACKET_STATUS_DEFAULT, 4452 0); 4879 4453 yahoo_packet_hash(pkt, 1, yd->user); 4880 4454 yahoo_packet_hash(pkt, 4, yd->user); … … 4890 4464 void yahoo_send_picture_update(int id, const char *who, int type) 4891 4465 { 4892 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4466 struct yahoo_input_data *yid = 4467 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4893 4468 struct yahoo_data *yd; 4894 4469 struct yahoo_packet *pkt; 4895 4470 char type_str[10]; 4896 4471 4897 if ( !yid)4472 if (!yid) 4898 4473 return; 4899 4474 … … 4902 4477 snprintf(type_str, sizeof(type_str), "%d", type); 4903 4478 4904 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); 4479 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, 4480 YPACKET_STATUS_DEFAULT, 0); 4905 4481 yahoo_packet_hash(pkt, 1, yd->user); 4906 4482 yahoo_packet_hash(pkt, 5, who); … … 4913 4489 void yahoo_send_picture_checksum(int id, const char *who, int checksum) 4914 4490 { 4915 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4491 struct yahoo_input_data *yid = 4492 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4916 4493 struct yahoo_data *yd; 4917 4494 struct yahoo_packet *pkt; 4918 4495 char checksum_str[10]; 4919 4496 4920 if ( !yid)4497 if (!yid) 4921 4498 return; 4922 4499 4923 4500 yd = yid->yd; 4924 4501 4925 4502 snprintf(checksum_str, sizeof(checksum_str), "%d", checksum); 4926 4503 4927 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); 4504 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, 4505 YPACKET_STATUS_DEFAULT, 0); 4928 4506 yahoo_packet_hash(pkt, 1, yd->user); 4929 if ( who != 0)4507 if (who != 0) 4930 4508 yahoo_packet_hash(pkt, 5, who); 4931 4509 yahoo_packet_hash(pkt, 192, checksum_str); … … 4938 4516 void yahoo_webcam_close_feed(int id, const char *who) 4939 4517 { 4940 struct yahoo_input_data *yid = find_input_by_id_and_webcam_user(id, who); 4518 struct yahoo_input_data *yid = 4519 find_input_by_id_and_webcam_user(id, who); 4941 4520 4942 4521 if (yid) … … 4946 4525 void yahoo_webcam_get_feed(int id, const char *who) 4947 4526 { 4948 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4527 struct yahoo_input_data *yid = 4528 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4949 4529 struct yahoo_data *yd; 4950 4530 struct yahoo_packet *pkt; 4951 4531 4952 4532 if (!yid) 4953 4533 return; … … 4960 4540 * The queue is popped in yahoo_process_webcam_key 4961 4541 */ 4962 webcam_queue = y_list_append(webcam_queue, who ?strdup(who):NULL);4542 webcam_queue = y_list_append(webcam_queue, who ? strdup(who) : NULL); 4963 4543 4964 4544 yd = yid->yd; 4965 4545 4966 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBCAM, YAHOO_STATUS_AVAILABLE, yd->session_id); 4546 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBCAM, YPACKET_STATUS_DEFAULT, 4547 yd->session_id); 4967 4548 4968 4549 yahoo_packet_hash(pkt, 1, yd->user); … … 4974 4555 } 4975 4556 4976 void yahoo_webcam_send_image(int id, unsigned char *image, unsigned int length, unsigned int timestamp) 4977 { 4978 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); 4557 void yahoo_webcam_send_image(int id, unsigned char *image, unsigned int length, 4558 unsigned int timestamp) 4559 { 4560 struct yahoo_input_data *yid = 4561 find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); 4979 4562 unsigned char *packet; 4980 4563 unsigned char header_len = 13; … … 4988 4571 packet[pos++] = header_len; 4989 4572 packet[pos++] = 0; 4990 packet[pos++] = 5; 4573 packet[pos++] = 5; /* version byte?? */ 4991 4574 packet[pos++] = 0; 4992 4575 pos += yahoo_put32(packet + pos, length); 4993 packet[pos++] = 2; 4576 packet[pos++] = 2; /* packet type, image */ 4994 4577 pos += yahoo_put32(packet + pos, timestamp); 4995 4578 yahoo_add_to_send_queue(yid, packet, header_len); … … 5000 4583 } 5001 4584 5002 void yahoo_webcam_accept_viewer(int id, const char* who, int accept) 5003 { 5004 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); 4585 void yahoo_webcam_accept_viewer(int id, const char *who, int accept) 4586 { 4587 struct yahoo_input_data *yid = 4588 find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); 5005 4589 char *packet = NULL; 5006 4590 char *data = NULL; … … 5013 4597 5014 4598 data = strdup("u="); 5015 data = y_string_append(data, (char *)who);4599 data = y_string_append(data, (char *)who); 5016 4600 data = y_string_append(data, "\r\n"); 5017 4601 len = strlen(data); … … 5020 4604 packet[pos++] = header_len; 5021 4605 packet[pos++] = 0; 5022 packet[pos++] = 5; 4606 packet[pos++] = 5; /* version byte?? */ 5023 4607 packet[pos++] = 0; 5024 4608 pos += yahoo_put32(packet + pos, len); 5025 packet[pos++] = 0; 4609 packet[pos++] = 0; /* packet type */ 5026 4610 pos += yahoo_put32(packet + pos, accept); 5027 4611 memcpy(packet + pos, data, len); … … 5033 4617 void yahoo_webcam_invite(int id, const char *who) 5034 4618 { 5035 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4619 struct yahoo_input_data *yid = 4620 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 5036 4621 struct yahoo_packet *pkt; 5037 4622 5038 4623 if (!yid) 5039 4624 return; 5040 4625 5041 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_NOTIFY, yid->yd->session_id); 4626 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YPACKET_STATUS_NOTIFY, 4627 yid->yd->session_id); 5042 4628 5043 4629 yahoo_packet_hash(pkt, 49, "WEBCAMINVITE"); … … 5051 4637 } 5052 4638 5053 static void yahoo_search_internal(int id, int t, const char *text, int g, int ar, int photo, int yahoo_only, int startpos, int total) 4639 static void yahoo_search_internal(int id, int t, const char *text, int g, 4640 int ar, int photo, int yahoo_only, int startpos, int total) 5054 4641 { 5055 4642 struct yahoo_data *yd = find_conn_by_id(id); … … 5067 4654 5068 4655 /* 5069 age range 5070 .ar=1 - 13-18, 2 - 18-25, 3 - 25-35, 4 - 35-50, 5 - 50-70, 6 - 70+ 5071 */ 5072 5073 snprintf(buff, sizeof(buff), "&.sq=%%20&.tt=%d&.ss=%d", total, startpos); 4656 age range 4657 .ar=1 - 13-18, 2 - 18-25, 3 - 25-35, 4 - 35-50, 5 - 50-70, 6 - 70+ 4658 */ 4659 4660 snprintf(buff, sizeof(buff), "&.sq=%%20&.tt=%d&.ss=%d", total, 4661 startpos); 5074 4662 5075 4663 ctext = strdup(text); … … 5077 4665 *p = '+'; 5078 4666 5079 snprintf(url, 1024, "http://members.yahoo.com/interests?.oc=m&.kw=%s&.sb=%d&.g=%d&.ar=0%s%s%s", 5080 ctext, t, g, photo ? "&.p=y" : "", yahoo_only ? "&.pg=y" : "", 5081 startpos ? buff : ""); 4667 snprintf(url, 1024, 4668 "http://members.yahoo.com/interests?.oc=m&.kw=%s&.sb=%d&.g=%d&.ar=0%s%s%s", 4669 ctext, t, g, photo ? "&.p=y" : "", yahoo_only ? "&.pg=y" : "", 4670 startpos ? buff : ""); 5082 4671 5083 4672 FREE(ctext); … … 5086 4675 5087 4676 inputs = y_list_prepend(inputs, yid); 5088 yahoo_http_get(yid->yd->client_id, url, buff, _yahoo_http_connected, yid); 5089 } 5090 5091 void yahoo_search(int id, enum yahoo_search_type t, const char *text, enum yahoo_search_gender g, enum yahoo_search_agerange ar, 5092 int photo, int yahoo_only) 5093 { 5094 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4677 yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, 4678 _yahoo_http_connected, yid); 4679 } 4680 4681 void yahoo_search(int id, enum yahoo_search_type t, const char *text, 4682 enum yahoo_search_gender g, enum yahoo_search_agerange ar, int photo, 4683 int yahoo_only) 4684 { 4685 struct yahoo_input_data *yid = 4686 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 5095 4687 struct yahoo_search_state *yss; 5096 4688 … … 5116 4708 void yahoo_search_again(int id, int start) 5117 4709 { 5118 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 4710 struct yahoo_input_data *yid = 4711 find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 5119 4712 struct yahoo_search_state *yss; 5120 4713 … … 5127 4720 start = yss->lsearch_nstart + yss->lsearch_nfound; 5128 4721 5129 yahoo_search_internal(id, yss->lsearch_type, yss->lsearch_text, 5130 yss->lsearch_gender, yss->lsearch_agerange, 5131 yss->lsearch_photo, yss->lsearch_yahoo_only, 5132 start, yss->lsearch_ntotal); 5133 } 4722 yahoo_search_internal(id, yss->lsearch_type, yss->lsearch_text, 4723 yss->lsearch_gender, yss->lsearch_agerange, 4724 yss->lsearch_photo, yss->lsearch_yahoo_only, 4725 start, yss->lsearch_ntotal); 4726 } 4727 4728 void yahoo_send_picture(int id, const char *name, unsigned long size, 4729 yahoo_get_fd_callback callback, void *data) 4730 { 4731 /* Not Implemented */ 4732 } 4733 4734 /* File Transfer */ 4735 static YList *active_file_transfers = NULL; 4736 4737 enum { 4738 FT_STATE_HEAD = 1, 4739 FT_STATE_RECV, 4740 FT_STATE_RECV_START, 4741 FT_STATE_SEND 4742 }; 5134 4743 5135 4744 struct send_file_data { 5136 struct yahoo_packet *pkt; 4745 int client_id; 4746 char *id; 4747 char *who; 4748 char *filename; 4749 char *ip_addr; 4750 char *token; 4751 int size; 4752 4753 struct yahoo_input_data *yid; 4754 int state; 4755 5137 4756 yahoo_get_fd_callback callback; 5138 void * user_data;4757 void *data; 5139 4758 }; 5140 4759 5141 static void _yahoo_send_picture_connected(int id, int fd, int error, void *data) 5142 { 5143 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_FT); 4760 static char *yahoo_get_random(void) 4761 { 4762 int i = 0; 4763 int r = 0; 4764 int c = 0; 4765 char out[25]; 4766 4767 out[24] = '\0'; 4768 out[23] = '$'; 4769 out[22] = '$'; 4770 4771 for (i = 0; i < 22; i++) { 4772 if(r == 0) 4773 r = rand(); 4774 4775 c = r%61; 4776 4777 if(c<26) 4778 out[i] = c + 'a'; 4779 else if (c<52) 4780 out[i] = c - 26 + 'A'; 4781 else 4782 out[i] = c - 52 + '0'; 4783 4784 r /= 61; 4785 } 4786 4787 return strdup(out); 4788 } 4789 4790 static int _are_same_id(const void *sfd1, const void *id) 4791 { 4792 return strcmp(((struct send_file_data *)sfd1)->id, (char *)id); 4793 } 4794 4795 static int _are_same_yid(const void *sfd1, const void *yid) 4796 { 4797 if(((struct send_file_data *)sfd1)->yid == yid) 4798 return 0; 4799 else 4800 return 1; 4801 } 4802 4803 static struct send_file_data *yahoo_get_active_transfer(char *id) 4804 { 4805 YList *l = y_list_find_custom(active_file_transfers, id, 4806 _are_same_id); 4807 4808 if(l) 4809 return (struct send_file_data *)l->data; 4810 4811 return NULL; 4812 } 4813 4814 static struct send_file_data *yahoo_get_active_transfer_with_yid(void *yid) 4815 { 4816 YList *l = y_list_find_custom(active_file_transfers, yid, 4817 _are_same_yid); 4818 4819 if(l) 4820 return (struct send_file_data *)l->data; 4821 4822 return NULL; 4823 } 4824 4825 static void yahoo_add_active_transfer(struct send_file_data *sfd) 4826 { 4827 active_file_transfers = y_list_prepend(active_file_transfers, sfd); 4828 } 4829 4830 static void yahoo_remove_active_transfer(struct send_file_data *sfd) 4831 { 4832 active_file_transfers = y_list_remove(active_file_transfers, sfd); 4833 free(sfd->id); 4834 free(sfd->who); 4835 free(sfd->filename); 4836 free(sfd->ip_addr); 4837 FREE(sfd); 4838 } 4839 4840 static void _yahoo_ft_upload_connected(int id, void *fd, int error, void *data) 4841 { 5144 4842 struct send_file_data *sfd = data; 5145 struct yahoo_packet *pkt = sfd->pkt; 5146 unsigned char buff[1024]; 5147 5148 if (fd <= 0) { 5149 sfd->callback(id, fd, error, sfd->user_data); 5150 FREE(sfd); 5151 yahoo_packet_free(pkt); 4843 struct yahoo_input_data *yid = sfd->yid; 4844 4845 if (!fd) { 5152 4846 inputs = y_list_remove(inputs, yid); 5153 4847 FREE(yid); … … 5155 4849 } 5156 4850 4851 sfd->callback(id, fd, error, sfd->data); 4852 5157 4853 yid->fd = fd; 5158 yahoo_send_packet(yid, pkt, 8); 4854 yid->read_tag = 4855 YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, 4856 YAHOO_INPUT_READ, yid); 4857 } 4858 4859 static void yahoo_file_transfer_upload(struct yahoo_data *yd, 4860 struct send_file_data *sfd) 4861 { 4862 char url[256]; 4863 char buff[4096]; 4864 char *sender_enc = NULL, *recv_enc = NULL, *token_enc = NULL; 4865 4866 struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); 4867 4868 yid->yd = yd; 4869 yid->type = YAHOO_CONNECTION_FT; 4870 4871 inputs = y_list_prepend(inputs, yid); 4872 sfd->yid = yid; 4873 sfd->state = FT_STATE_SEND; 4874 4875 token_enc = yahoo_urlencode(sfd->token); 4876 sender_enc = yahoo_urlencode(yd->user); 4877 recv_enc = yahoo_urlencode(sfd->who); 4878 4879 snprintf(url, sizeof(url), 4880 "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, 4881 token_enc, sender_enc, recv_enc); 4882 4883 snprintf(buff, sizeof(buff), "T=%s; Y=%s", yd->cookie_t, yd->cookie_y); 4884 4885 yahoo_http_post(yd->client_id, url, buff, sfd->size, 4886 _yahoo_ft_upload_connected, sfd); 4887 4888 FREE(token_enc); 4889 FREE(sender_enc); 4890 FREE(recv_enc); 4891 } 4892 4893 static void yahoo_init_ft_recv(struct yahoo_data *yd, 4894 struct send_file_data *sfd) 4895 { 4896 char url[256]; 4897 char buff[1024]; 4898 char *sender_enc = NULL, *recv_enc = NULL, *token_enc = NULL; 4899 4900 struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); 4901 4902 yid->yd = yd; 4903 yid->type = YAHOO_CONNECTION_FT; 4904 4905 inputs = y_list_prepend(inputs, yid); 4906 sfd->yid = yid; 4907 sfd->state = FT_STATE_HEAD; 4908 4909 token_enc = yahoo_urlencode(sfd->token); 4910 sender_enc = yahoo_urlencode(sfd->who); 4911 recv_enc = yahoo_urlencode(yd->user); 4912 4913 snprintf(url, sizeof(url), 4914 "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, 4915 token_enc, sender_enc, recv_enc); 4916 4917 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); 4918 4919 yahoo_http_head(yid->yd->client_id, url, buff, 0, NULL, 4920 _yahoo_http_connected, yid); 4921 4922 FREE(token_enc); 4923 FREE(sender_enc); 4924 FREE(recv_enc); 4925 } 4926 4927 static void yahoo_file_transfer_accept(struct yahoo_input_data *yid, 4928 struct send_file_data *sfd) 4929 { 4930 struct yahoo_packet *pkt; 4931 4932 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, 4933 YPACKET_STATUS_DEFAULT, yid->yd->session_id); 4934 4935 yahoo_packet_hash(pkt, 1, yid->yd->user); 4936 yahoo_packet_hash(pkt, 5, sfd->who); 4937 yahoo_packet_hash(pkt, 265, sfd->id); 4938 yahoo_packet_hash(pkt, 27, sfd->filename); 4939 yahoo_packet_hash(pkt, 249, "3"); 4940 yahoo_packet_hash(pkt, 251, sfd->token); 4941 4942 yahoo_send_packet(yid, pkt, 0); 4943 5159 4944 yahoo_packet_free(pkt); 5160 4945 5161 snprintf((char *)buff, sizeof(buff), "29"); 5162 buff[2] = 0xc0; 5163 buff[3] = 0x80; 5164 5165 write(yid->fd, buff, 4); 5166 5167 /* YAHOO_CALLBACK(ext_yahoo_add_handler) (nyd->fd, YAHOO_INPUT_READ); */ 5168 5169 sfd->callback(id, fd, error, sfd->user_data); 5170 FREE(sfd); 5171 inputs = y_list_remove(inputs, yid); 5172 /* 5173 while (yahoo_tcp_readline(buff, sizeof(buff), nyd->fd) > 0) { 5174 if (!strcmp(buff, "")) 5175 break; 5176 } 5177 5178 */ 5179 yahoo_input_close(yid); 5180 } 5181 5182 void yahoo_send_picture(int id, const char *name, unsigned long size, 5183 yahoo_get_fd_callback callback, void *data) 5184 { 5185 struct yahoo_data *yd = find_conn_by_id(id); 4946 yahoo_init_ft_recv(yid->yd, sfd); 4947 } 4948 4949 static void yahoo_process_filetransferaccept(struct yahoo_input_data *yid, 4950 struct yahoo_packet *pkt) 4951 { 4952 YList *l; 4953 struct send_file_data *sfd; 4954 char *who = NULL; 4955 char *filename = NULL; 4956 char *id = NULL; 4957 char *token = NULL; 4958 4959 for (l = pkt->hash; l; l = l->next) { 4960 struct yahoo_pair *pair = l->data; 4961 switch (pair->key) { 4962 case 4: 4963 who = pair->value; 4964 break; 4965 case 5: 4966 /* Me... don't care */ 4967 break; 4968 case 249: 4969 break; 4970 case 265: 4971 id = pair->value; 4972 break; 4973 case 251: 4974 token = pair->value; 4975 break; 4976 case 27: 4977 filename = pair->value; 4978 break; 4979 } 4980 } 4981 4982 sfd = yahoo_get_active_transfer(id); 4983 4984 if (sfd) { 4985 sfd->token = strdup(token); 4986 4987 yahoo_file_transfer_upload(yid->yd, sfd); 4988 } 4989 else { 4990 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 4991 (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, 4992 sfd->data); 4993 4994 yahoo_remove_active_transfer(sfd); 4995 } 4996 } 4997 4998 static void yahoo_process_filetransferinfo(struct yahoo_input_data *yid, 4999 struct yahoo_packet *pkt) 5000 { 5001 YList *l; 5002 char *who = NULL; 5003 char *filename = NULL; 5004 char *id = NULL; 5005 char *token = NULL; 5006 char *ip_addr = NULL; 5007 5008 struct send_file_data *sfd; 5009 5010 for (l = pkt->hash; l; l = l->next) { 5011 struct yahoo_pair *pair = l->data; 5012 switch (pair->key) { 5013 case 1: 5014 case 4: 5015 who = pair->value; 5016 break; 5017 case 5: 5018 /* Me... don't care */ 5019 break; 5020 case 249: 5021 break; 5022 case 265: 5023 id = pair->value; 5024 break; 5025 case 250: 5026 ip_addr = pair->value; 5027 break; 5028 case 251: 5029 token = pair->value; 5030 break; 5031 case 27: 5032 filename = pair->value; 5033 break; 5034 } 5035 } 5036 5037 sfd = yahoo_get_active_transfer(id); 5038 5039 if (sfd) { 5040 sfd->token = strdup(token); 5041 sfd->ip_addr = strdup(ip_addr); 5042 5043 yahoo_file_transfer_accept(yid, sfd); 5044 } 5045 else { 5046 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5047 (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, 5048 sfd->data); 5049 5050 yahoo_remove_active_transfer(sfd); 5051 } 5052 } 5053 5054 static void yahoo_send_filetransferinfo(struct yahoo_data *yd, 5055 struct send_file_data *sfd) 5056 { 5186 5057 struct yahoo_input_data *yid; 5187 struct yahoo_server_settings *yss; 5058 struct yahoo_packet *pkt; 5059 5060 yid = find_input_by_id_and_type(yd->client_id, YAHOO_CONNECTION_PAGER); 5061 sfd->ip_addr = YAHOO_CALLBACK(ext_yahoo_get_ip_addr)("relay.yahoo.com"); 5062 5063 if (!sfd->ip_addr) { 5064 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5065 (yd->client_id, YAHOO_FILE_TRANSFER_RELAY, sfd->data); 5066 5067 yahoo_remove_active_transfer(sfd); 5068 5069 return; 5070 } 5071 5072 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFERINFO, 5073 YPACKET_STATUS_DEFAULT, yd->session_id); 5074 5075 yahoo_packet_hash(pkt, 1, yd->user); 5076 yahoo_packet_hash(pkt, 5, sfd->who); 5077 yahoo_packet_hash(pkt, 265, sfd->id); 5078 yahoo_packet_hash(pkt, 27, sfd->filename); 5079 yahoo_packet_hash(pkt, 249, "3"); 5080 yahoo_packet_hash(pkt, 250, sfd->ip_addr); 5081 5082 yahoo_send_packet(yid, pkt, 0); 5083 5084 yahoo_packet_free(pkt); 5085 } 5086 5087 static void yahoo_process_filetransfer(struct yahoo_input_data *yid, 5088 struct yahoo_packet *pkt) 5089 { 5090 YList *l; 5091 char *who = NULL; 5092 char *filename = NULL; 5093 char *msg = NULL; 5094 char *id = NULL; 5095 int action = 0; 5096 int size = 0; 5097 struct yahoo_data *yd = yid->yd; 5098 5099 struct send_file_data *sfd; 5100 5101 for (l = pkt->hash; l; l = l->next) { 5102 struct yahoo_pair *pair = l->data; 5103 switch (pair->key) { 5104 case 4: 5105 who = pair->value; 5106 break; 5107 case 5: 5108 /* Me... don't care */ 5109 break; 5110 case 222: 5111 action = atoi(pair->value); 5112 break; 5113 case 265: 5114 id = pair->value; 5115 break; 5116 case 266: /* Don't know */ 5117 break; 5118 case 302: /* Start Data? */ 5119 break; 5120 case 300: 5121 break; 5122 case 27: 5123 filename = pair->value; 5124 break; 5125 case 28: 5126 size = atoi(pair->value); 5127 break; 5128 case 14: 5129 msg = pair->value; 5130 case 301: /* End Data? */ 5131 break; 5132 case 303: 5133 break; 5134 5135 } 5136 } 5137 5138 if (action == YAHOO_FILE_TRANSFER_INIT) { 5139 /* Received a FT request from buddy */ 5140 sfd = y_new0(struct send_file_data, 1); 5141 5142 sfd->client_id = yd->client_id; 5143 sfd->id = strdup(id); 5144 sfd->who = strdup(who); 5145 sfd->filename = strdup(filename); 5146 sfd->size = size; 5147 5148 yahoo_add_active_transfer(sfd); 5149 5150 YAHOO_CALLBACK(ext_yahoo_got_file) (yd->client_id, yd->user, 5151 who, msg, filename, size, sfd->id); 5152 } 5153 else { 5154 /* Response to our request */ 5155 sfd = yahoo_get_active_transfer(id); 5156 5157 if (sfd && action == YAHOO_FILE_TRANSFER_ACCEPT) { 5158 yahoo_send_filetransferinfo(yd, sfd); 5159 } 5160 else if (!sfd || action == YAHOO_FILE_TRANSFER_REJECT) { 5161 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5162 (yd->client_id, YAHOO_FILE_TRANSFER_REJECT, 5163 sfd->data); 5164 5165 yahoo_remove_active_transfer(sfd); 5166 } 5167 } 5168 } 5169 5170 void yahoo_send_file(int id, const char *who, const char *msg, 5171 const char *name, unsigned long size, 5172 yahoo_get_fd_callback callback, void *data) 5173 { 5188 5174 struct yahoo_packet *pkt = NULL; 5189 5175 char size_str[10]; 5190 char expire_str[10]; 5191 long content_length = 0; 5192 unsigned char buff[1024]; 5193 char url[255]; 5176 struct yahoo_input_data *yid; 5177 struct yahoo_data *yd; 5194 5178 struct send_file_data *sfd; 5179 5180 yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); 5181 yd = find_conn_by_id(id); 5182 sfd = y_new0(struct send_file_data, 1); 5183 5184 sfd->client_id = id; 5185 sfd->id = yahoo_get_random(); 5186 sfd->who = strdup(who); 5187 sfd->filename = strdup(name); 5188 sfd->size = size; 5189 sfd->callback = callback; 5190 sfd->data = data; 5191 5192 yahoo_add_active_transfer(sfd); 5195 5193 5196 5194 if (!yd) 5197 5195 return; 5198 5196 5199 yss = yd->server_settings; 5200 5201 yid = y_new0(struct yahoo_input_data, 1); 5202 yid->yd = yd; 5203 yid->type = YAHOO_CONNECTION_FT; 5204 5205 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD, YAHOO_STATUS_AVAILABLE, yd->session_id); 5197 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFER, 5198 YPACKET_STATUS_DEFAULT, yd->session_id); 5206 5199 5207 5200 snprintf(size_str, sizeof(size_str), "%ld", size); 5208 snprintf(expire_str, sizeof(expire_str), "%ld", (long)604800); 5209 5210 yahoo_packet_hash(pkt, 0, yd->user); 5201 5211 5202 yahoo_packet_hash(pkt, 1, yd->user); 5212 yahoo_packet_hash(pkt, 14, ""); 5203 yahoo_packet_hash(pkt, 5, who); 5204 yahoo_packet_hash(pkt, 265, sfd->id); 5205 yahoo_packet_hash(pkt, 222, "1"); 5206 yahoo_packet_hash(pkt, 266, "1"); 5207 yahoo_packet_hash(pkt, 302, "268"); 5208 yahoo_packet_hash(pkt, 300, "268"); 5213 5209 yahoo_packet_hash(pkt, 27, name); 5214 5210 yahoo_packet_hash(pkt, 28, size_str); 5215 yahoo_packet_hash(pkt, 38, expire_str); 5211 yahoo_packet_hash(pkt, 301, "268"); 5212 yahoo_packet_hash(pkt, 303, "268"); 5213 5214 yahoo_send_packet(yid, pkt, 0); 5215 5216 yahoo_packet_free(pkt); 5217 } 5218 5219 void yahoo_send_file_transfer_response(int client_id, int response, char *id, void *data) 5220 { 5221 struct yahoo_packet *pkt = NULL; 5222 char resp[2]; 5223 struct yahoo_input_data *yid; 5216 5224 5217 5218 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); 5219 5220 snprintf(url, sizeof(url), "http://%s:%d/notifyft", 5221 yss->filetransfer_host, yss->filetransfer_port); 5222 snprintf((char *)buff, sizeof(buff), "Y=%s; T=%s", 5223 yd->cookie_y, yd->cookie_t); 5224 inputs = y_list_prepend(inputs, yid); 5225 5226 sfd = y_new0(struct send_file_data, 1); 5227 sfd->pkt = pkt; 5228 sfd->callback = callback; 5229 sfd->user_data = data; 5230 yahoo_http_post(yid->yd->client_id, url, (char *)buff, content_length+4+size, 5231 _yahoo_send_picture_connected, sfd); 5232 } 5233 5234 static void _yahoo_send_file_connected(int id, int fd, int error, void *data) 5235 { 5236 struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_FT); 5237 struct send_file_data *sfd = data; 5238 struct yahoo_packet *pkt = sfd->pkt; 5239 unsigned char buff[1024]; 5240 5241 if (fd <= 0) { 5242 sfd->callback(id, fd, error, sfd->user_data); 5243 FREE(sfd); 5244 yahoo_packet_free(pkt); 5245 inputs = y_list_remove(inputs, yid); 5246 FREE(yid); 5247 return; 5248 } 5249 5250 yid->fd = fd; 5251 yahoo_send_packet(yid, pkt, 8); 5225 struct send_file_data *sfd = yahoo_get_active_transfer(id); 5226 5227 sfd->data = data; 5228 5229 yid = find_input_by_id_and_type(client_id, YAHOO_CONNECTION_PAGER); 5230 5231 pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFER, 5232 YPACKET_STATUS_DEFAULT, yid->yd->session_id); 5233 5234 snprintf(resp, sizeof(resp), "%d", response); 5235 5236 yahoo_packet_hash(pkt, 1, yid->yd->user); 5237 yahoo_packet_hash(pkt, 5, sfd->who); 5238 yahoo_packet_hash(pkt, 265, sfd->id); 5239 yahoo_packet_hash(pkt, 222, resp); 5240 5241 yahoo_send_packet(yid, pkt, 0); 5242 5252 5243 yahoo_packet_free(pkt); 5253 5244 5254 snprintf((char *)buff, sizeof(buff), "29"); 5255 buff[2] = 0xc0; 5256 buff[3] = 0x80; 5245 if(response == YAHOO_FILE_TRANSFER_REJECT) 5246 yahoo_remove_active_transfer(sfd); 5247 } 5248 5249 static void yahoo_process_ft_connection(struct yahoo_input_data *yid, int over) 5250 { 5251 struct send_file_data *sfd; 5252 struct yahoo_data *yd = yid->yd; 5257 5253 5258 write(yid->fd, buff, 4); 5259 5260 /* YAHOO_CALLBACK(ext_yahoo_add_handler) (nyd->fd, YAHOO_INPUT_READ); */ 5261 5262 sfd->callback(id, fd, error, sfd->user_data); 5263 FREE(sfd); 5264 inputs = y_list_remove(inputs, yid); 5265 /* 5266 while (yahoo_tcp_readline(buff, sizeof(buff), nyd->fd) > 0) { 5267 if (!strcmp(buff, "")) 5268 break; 5269 } 5270 5271 */ 5272 yahoo_input_close(yid); 5273 } 5274 5275 void yahoo_send_file(int id, const char *who, const char *msg, 5276 const char *name, unsigned long size, 5277 yahoo_get_fd_callback callback, void *data) 5278 { 5279 struct yahoo_data *yd = find_conn_by_id(id); 5280 struct yahoo_input_data *yid; 5281 struct yahoo_server_settings *yss; 5282 struct yahoo_packet *pkt = NULL; 5283 char size_str[10]; 5284 long content_length = 0; 5285 unsigned char buff[1024]; 5286 char url[255]; 5287 struct send_file_data *sfd; 5288 5289 if (!yd) 5290 return; 5291 5292 yss = yd->server_settings; 5293 5294 yid = y_new0(struct yahoo_input_data, 1); 5295 yid->yd = yd; 5296 yid->type = YAHOO_CONNECTION_FT; 5297 5298 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, YAHOO_STATUS_AVAILABLE, yd->session_id); 5299 5300 snprintf(size_str, sizeof(size_str), "%ld", size); 5301 5302 yahoo_packet_hash(pkt, 0, yd->user); 5303 yahoo_packet_hash(pkt, 5, who); 5304 yahoo_packet_hash(pkt, 14, msg); 5305 yahoo_packet_hash(pkt, 27, name); 5306 yahoo_packet_hash(pkt, 28, size_str); 5307 5308 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); 5309 5310 snprintf(url, sizeof(url), "http://%s:%d/notifyft", 5311 yss->filetransfer_host, yss->filetransfer_port); 5312 snprintf((char *)buff, sizeof(buff), "Y=%s; T=%s", 5313 yd->cookie_y, yd->cookie_t); 5314 inputs = y_list_prepend(inputs, yid); 5315 5316 sfd = y_new0(struct send_file_data, 1); 5317 sfd->pkt = pkt; 5318 sfd->callback = callback; 5319 sfd->user_data = data; 5320 yahoo_http_post(yid->yd->client_id, url, (char *)buff, content_length+4+size, 5321 _yahoo_send_file_connected, sfd); 5322 } 5323 5254 sfd = yahoo_get_active_transfer_with_yid(yid); 5255 5256 if (!sfd) { 5257 LOG(("Something funny happened. yid %p has no sfd.\n", yid)); 5258 return; 5259 } 5260 5261 /* 5262 * We want to handle only the complete data with HEAD since we don't 5263 * want a situation where both the GET and HEAD are active. 5264 * With SEND, we really can't do much with partial response 5265 */ 5266 if ((sfd->state == FT_STATE_HEAD || sfd->state == FT_STATE_SEND) 5267 && !over) 5268 return; 5269 5270 if (sfd->state == FT_STATE_HEAD) { 5271 /* Do a GET */ 5272 char url[256]; 5273 char buff[1024]; 5274 char *sender_enc = NULL, *recv_enc = NULL, *token_enc = NULL; 5275 5276 struct yahoo_input_data *yid_ft = 5277 y_new0(struct yahoo_input_data, 1); 5278 5279 yid_ft->yd = yid->yd; 5280 yid_ft->type = YAHOO_CONNECTION_FT; 5281 5282 inputs = y_list_prepend(inputs, yid_ft); 5283 sfd->yid = yid_ft; 5284 sfd->state = FT_STATE_RECV; 5285 5286 token_enc = yahoo_urlencode(sfd->token); 5287 sender_enc = yahoo_urlencode(sfd->who); 5288 recv_enc = yahoo_urlencode(yd->user); 5289 5290 snprintf(url, sizeof(url), 5291 "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, 5292 token_enc, sender_enc, recv_enc); 5293 5294 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, 5295 yd->cookie_t); 5296 5297 5298 yahoo_http_get(yd->client_id, url, buff, 1, 1, 5299 _yahoo_http_connected, yid_ft); 5300 5301 FREE(token_enc); 5302 FREE(sender_enc); 5303 FREE(recv_enc); 5304 } 5305 else if (sfd->state == FT_STATE_RECV || 5306 sfd->state == FT_STATE_RECV_START) { 5307 5308 unsigned char *data_begin = NULL; 5309 5310 if (yid->rxlen == 0) 5311 yahoo_remove_active_transfer(sfd); 5312 5313 if (sfd->state != FT_STATE_RECV_START && 5314 (data_begin = 5315 (unsigned char *)strstr((char *)yid->rxqueue, 5316 "\r\n\r\n"))) { 5317 5318 sfd->state = FT_STATE_RECV_START; 5319 5320 yid->rxlen -= 4+(data_begin-yid->rxqueue)/sizeof(char); 5321 data_begin += 4; 5322 5323 if (yid->rxlen > 0) 5324 YAHOO_CALLBACK(ext_yahoo_got_ft_data) 5325 (yd->client_id, data_begin, 5326 yid->rxlen, sfd->data); 5327 } 5328 else if (sfd->state == FT_STATE_RECV_START) 5329 YAHOO_CALLBACK(ext_yahoo_got_ft_data) (yd->client_id, 5330 yid->rxqueue, yid->rxlen, sfd->data); 5331 5332 FREE(yid->rxqueue); 5333 yid->rxqueue = NULL; 5334 yid->rxlen = 0; 5335 } 5336 else if (sfd->state == FT_STATE_SEND) { 5337 /* Sent file completed */ 5338 int len = 0; 5339 char *off = strstr((char *)yid->rxqueue, "Content-Length: "); 5340 5341 if (off) { 5342 off += 16; 5343 len = atoi(off); 5344 } 5345 5346 if (len < sfd->size) 5347 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5348 (yd->client_id, 5349 YAHOO_FILE_TRANSFER_FAILED, sfd->data); 5350 else 5351 YAHOO_CALLBACK(ext_yahoo_file_transfer_done) 5352 (yd->client_id, 5353 YAHOO_FILE_TRANSFER_DONE, sfd->data); 5354 5355 yahoo_remove_active_transfer(sfd); 5356 } 5357 } 5358 5359 /* End File Transfer */ 5324 5360 5325 5361 enum yahoo_status yahoo_current_status(int id) … … 5362 5398 if (!strncasecmp(which, "y", 1)) 5363 5399 return yd->cookie_y; 5400 if (!strncasecmp(which, "b", 1)) 5401 return yd->cookie_b; 5364 5402 if (!strncasecmp(which, "t", 1)) 5365 5403 return yd->cookie_t; … … 5371 5409 } 5372 5410 5373 void yahoo_get_url_handle(int id, const char *url, 5374 yahoo_get_url_handle_callback callback, void *data) 5375 { 5376 struct yahoo_data *yd = find_conn_by_id(id); 5377 if (!yd) 5378 return; 5379 5380 yahoo_get_url_fd(id, url, yd, callback, data); 5381 } 5382 5383 const char *yahoo_get_profile_url( void ) 5411 const char *yahoo_get_profile_url(void) 5384 5412 { 5385 5413 return profile_url; 5386 5414 } 5387 -
protocols/yahoo/yahoo.c
rc36f73b r9034ba0 2 2 * libyahoo2 wrapper to BitlBee 3 3 * 4 * Mostly Copyright 2004 Wilmer van der Gaast <wilmer@gaast.net>4 * Mostly Copyright 2004-2010 Wilmer van der Gaast <wilmer@gaast.net> 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify … … 339 339 static void byahoo_auth_allow( struct im_connection *ic, const char *who ) 340 340 { 341 /* 341 342 struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; 342 343 343 344 yahoo_accept_buddy_ymsg13( yd->y2_id, NULL, who ); 345 */ 344 346 } 345 347 346 348 static void byahoo_auth_deny( struct im_connection *ic, const char *who ) 347 349 { 350 /* 348 351 struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; 349 352 350 353 yahoo_reject_buddy_ymsg13( yd->y2_id, NULL, who, NULL ); 354 */ 351 355 } 352 356 … … 421 425 } 422 426 423 d->callback( d->fd, 0, d->data );427 d->callback( NULL + d->fd, 0, d->data ); 424 428 g_free( d ); 425 429 } … … 441 445 return FALSE; 442 446 443 yahoo_read_ready( d->id, d->fd, d->data );447 yahoo_read_ready( d->id, NULL + d->fd, d->data ); 444 448 445 449 return TRUE; … … 458 462 struct byahoo_write_ready_data *d = data; 459 463 460 return yahoo_write_ready( d->id, d->fd, d->data );464 return yahoo_write_ready( d->id, NULL + d->fd, d->data ); 461 465 } 462 466 … … 606 610 flags = 0; 607 611 break; 608 case YAHOO_STATUS_NOTIFY:609 state_string = "Notify";610 break;611 612 } 612 613 … … 615 616 if( stat == YAHOO_STATUS_IDLE ) 616 617 imcb_buddy_times( ic, who, 0, idle ); 618 } 619 620 void ext_yahoo_got_buzz( int id, const char *me, const char *who, long tm ) 621 { 617 622 } 618 623 … … 630 635 } 631 636 632 void ext_yahoo_got_file( int id, 633 const char *ignored, 634 const char *who, const char *url, long expires, const char *msg, const char *fname, unsigned long fesize ) 637 void ext_yahoo_got_file( int id, const char *ignored, const char *who, const char *msg, 638 const char *fname, unsigned long fesize, char *trid ) 635 639 { 636 640 struct im_connection *ic = byahoo_get_ic_by_id( id ); 637 641 638 642 imcb_log( ic, "Got a file transfer (file = %s) from %s. Ignoring for now due to lack of support.", fname, who ); 643 } 644 645 void ext_yahoo_got_ft_data( int id, const unsigned char *in, int len, void *data ) 646 { 647 } 648 649 void ext_yahoo_file_transfer_done( int id, int result, void *data ) 650 { 639 651 } 640 652 … … 649 661 } 650 662 651 void ext_yahoo_system_message( int id, const char *m sg )663 void ext_yahoo_system_message( int id, const char *me, const char *who, const char *msg ) 652 664 { 653 665 struct im_connection *ic = byahoo_get_ic_by_id( id ); … … 671 683 672 684 /* TODO: Clear up the mess of inp and d structures */ 673 int ext_yahoo_add_handler( int id, int fd, yahoo_input_condition cond, void *data )685 int ext_yahoo_add_handler( int id, void *fd_, yahoo_input_condition cond, void *data ) 674 686 { 675 687 struct byahoo_input_data *inp = g_new0( struct byahoo_input_data, 1 ); 688 int fd = (int) fd_; 676 689 677 690 if( cond == YAHOO_INPUT_READ ) … … 700 713 { 701 714 g_free( inp ); 702 return ( -1 );715 return -1; 703 716 /* Panic... */ 704 717 } 705 718 706 719 byahoo_inputs = g_slist_append( byahoo_inputs, inp ); 707 return ( inp->h );720 return inp->h; 708 721 } 709 722 … … 729 742 } 730 743 731 int ext_yahoo_connect_async( int id, const char *host, int port, yahoo_connect_callback callback, void *data )744 int ext_yahoo_connect_async( int id, const char *host, int port, yahoo_connect_callback callback, void *data, int use_ssl ) 732 745 { 733 746 struct byahoo_connect_callback_data *d; … … 745 758 d->id = id; 746 759 747 return( fd ); 748 } 760 return fd; 761 } 762 763 char *ext_yahoo_get_ip_addr( const char *domain ) 764 { 765 return NULL; 766 } 767 768 int ext_yahoo_write( void *fd, char *buf, int len ) 769 { 770 return write( (int) fd, buf, len ); 771 } 772 773 int ext_yahoo_read( void *fd, char *buf, int len ) 774 { 775 return read( (int) fd, buf, len ); 776 } 777 778 void ext_yahoo_close( void *fd ) 779 { 780 close( (int) fd ); 781 } 782 783 void ext_yahoo_got_buddy_change_group( int id, const char *me, const char *who, 784 const char *old_group, const char *new_group ) 785 { 786 } 749 787 750 788 /* Because we don't want asynchronous connects in BitlBee, and because … … 752 790 int ext_yahoo_connect(const char *host, int port) 753 791 { 754 #if 0755 struct sockaddr_in serv_addr;756 static struct hostent *server;757 static char last_host[256];758 int servfd;759 char **p;760 761 if(last_host[0] || g_strcasecmp(last_host, host)!=0) {762 if(!(server = gethostbyname(host))) {763 return -1;764 }765 strncpy(last_host, host, 255);766 }767 768 if((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {769 return -1;770 }771 772 for (p = server->h_addr_list; *p; p++)773 {774 memset(&serv_addr, 0, sizeof(serv_addr));775 serv_addr.sin_family = AF_INET;776 memcpy(&serv_addr.sin_addr.s_addr, *p, server->h_length);777 serv_addr.sin_port = htons(port);778 779 if(connect(servfd, (struct sockaddr *) &serv_addr,780 sizeof(serv_addr)) == -1) {781 return -1;782 } else {783 return servfd;784 }785 }786 787 closesocket(servfd);788 #endif789 792 return -1; 790 793 } … … 898 901 } 899 902 900 void ext_yahoo_chat_join( int id, const char *who, const char *room, const char *topic, YList *members, intfd )903 void ext_yahoo_chat_join( int id, const char *who, const char *room, const char *topic, YList *members, void *fd ) 901 904 { 902 905 } … … 928 931 void ext_yahoo_contact_auth_request( int id, const char *myid, const char *who, const char *msg ) 929 932 { 930 struct im_connection *ic = byahoo_get_ic_by_id( id ); 931 932 imcb_ask_auth( ic, who, NULL ); 933 /* Apparently no longer implemented.. */ 933 934 } 934 935 … … 944 945 } 945 946 946 void ext_yahoo_game_notify( int id, const char *me, const char *who, int stat )947 void ext_yahoo_game_notify( int id, const char *me, const char *who, int stat, const char *msg ) 947 948 { 948 949 } -
protocols/yahoo/yahoo2.h
rc36f73b r9034ba0 51 51 #include "yahoo2_types.h" 52 52 53 /* returns the socket descriptor for a given pager connection. shouldn't be needed */54 intyahoo_get_fd(int id);53 /* returns the socket descriptor object for a given pager connection. shouldn't be needed */ 54 void *yahoo_get_fd(int id); 55 55 56 56 /* says how much logging to do */ 57 57 /* see yahoo2_types.h for the different values */ 58 intyahoo_set_log_level(enum yahoo_log_level level);59 enum yahoo_log_level yahoo_get_log_level( void);58 int yahoo_set_log_level(enum yahoo_log_level level); 59 enum yahoo_log_level yahoo_get_log_level(void); 60 60 61 61 /* these functions should be self explanatory */ … … 222 222 /* registered by ext_yahoo_add_handler */ 223 223 /* if these return negative values, errno may be set */ 224 int yahoo_read_ready(int id, intfd, void *data);225 int yahoo_write_ready(int id, intfd, void *data);224 int yahoo_read_ready(int id, void *fd, void *data); 225 int yahoo_write_ready(int id, void *fd, void *data); 226 226 227 227 /* utility functions. these do not hit the server */ … … 240 240 void yahoo_buddyicon_request(int id, const char *who); 241 241 242 void yahoo_accept_buddy_ymsg13(int,const char*, const char*);243 void yahoo_reject_buddy_ymsg13(int,const char*, const char*, const char*);244 245 242 #include "yahoo_httplib.h" 246 243 -
protocols/yahoo/yahoo2_callbacks.h
rc36f73b r9034ba0 55 55 * 56 56 * Params: 57 * fd - The file descriptor that has been connected, or -1 on error 57 * fd - The file descriptor object that has been connected, or NULL on 58 * error 58 59 * error - The value of errno set by the call to connect or 0 if no error 59 60 * Set both fd and error to 0 if the connect was cancelled by the … … 62 63 * function 63 64 */ 64 typedef void (*yahoo_connect_callback)(int fd, int error, void *callback_data); 65 65 typedef void (*yahoo_connect_callback) (void *fd, int error, 66 void *callback_data); 66 67 67 68 /* … … 262 263 * members - the initial members of the chatroom (null terminated YList 263 264 * of yahoo_chat_member's) Must be freed by the client 264 * fd - the socket where the connection is coming from (for tracking)265 * fd - the object where the connection is coming from (for tracking) 265 266 */ 266 267 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_join) (int id, const char *me, 267 const char *room, const char *topic, YList *members, intfd);268 const char *room, const char *topic, YList *members, void *fd); 268 269 269 270 /* … … 364 365 * me - the identity the file was sent to 365 366 * who - the user who sent the file 366 * url - the file url367 * expires - the expiry date of the file on the server (timestamp)368 367 * msg - the message 369 368 * fname- the file name if direct transfer 370 369 * fsize- the file size if direct transfer 371 */ 372 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_file)(int id, const char *me, const char *who, const char *url, long expires, const char *msg, const char *fname, unsigned long fesize); 373 374 375 /* 376 * Name: ext_yahoo_contact_auth_request 377 * Called when a contact wants to add you to his/her contact list 378 * Params: 379 * id - the id that identifies the server connection 380 * myid - the identity s/he added 381 * who - who did it 382 * msg - any message sent 383 */ 384 void YAHOO_CALLBACK_TYPE(ext_yahoo_contact_auth_request)(int id, const char *myid, const char *who, const char *msg); 385 370 * trid - transfer id. Unique for this transfer 371 * 372 * NOTE: Subsequent callbacks for file transfer do not send all of this 373 * information again since it is wasteful. Implementations are expected to 374 * save this information and supply it as callback data when the file or 375 * confirmation is sent 376 */ 377 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_file) (int id, const char *me, 378 const char *who, const char *msg, const char *fname, 379 unsigned long fesize, char *trid); 380 381 /* 382 * Name: ext_yahoo_got_ft_data 383 * Called multiple times when parts of the file are received 384 * Params: 385 * id - the id that identifies the server connection 386 * in - The data 387 * len - Length of the data 388 * data - callback data 389 */ 390 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ft_data) (int id, 391 const unsigned char *in, int len, void *data); 392 393 /* 394 * Name: ext_yahoo_file_transfer_done 395 * File transfer is done 396 * Params: 397 * id - the id that identifies the server connection 398 * result - To notify if it finished successfully or with a failure 399 * data - callback data 400 */ 401 void YAHOO_CALLBACK_TYPE(ext_yahoo_file_transfer_done) (int id, 402 int result, void *data); 386 403 387 404 /* … … 428 445 * who - the handle of the remote user 429 446 * stat - 1 if game, 0 if stopped gaming 430 */ 431 void YAHOO_CALLBACK_TYPE(ext_yahoo_game_notify)(int id, const char *me, const char *who, int stat); 432 447 * msg - game description and/or other text 448 */ 449 void YAHOO_CALLBACK_TYPE(ext_yahoo_game_notify) (int id, const char *me, 450 const char *who, int stat, const char *msg); 433 451 434 452 /* … … 449 467 * Params: 450 468 * id - the id that identifies the server connection 469 * me - the handle of the identity the notification is sent to 470 * who - the source of the system message (there are different types) 451 471 * msg - the message 452 472 */ 453 void YAHOO_CALLBACK_TYPE(ext_yahoo_system_message)(int id, const char *msg); 473 void YAHOO_CALLBACK_TYPE(ext_yahoo_system_message) (int id, 474 const char *me, const char *who, const char *msg); 454 475 455 476 /* … … 630 651 * Params: 631 652 * id - the id that identifies the server connection 632 * fd - the fd o n which to listen653 * fd - the fd object on which to listen 633 654 * cond - the condition on which to call the callback 634 655 * data - callback data to pass to yahoo_*_ready … … 636 657 * Returns: a tag to be used when removing the handler 637 658 */ 638 int YAHOO_CALLBACK_TYPE(ext_yahoo_add_handler) (int id, intfd,659 int YAHOO_CALLBACK_TYPE(ext_yahoo_add_handler) (int id, void *fd, 639 660 yahoo_input_condition cond, void *data); 640 661 … … 674 695 * callback - function to call when connect completes 675 696 * callback_data - data to pass to the callback function 676 * Returns: 677 * a unix file descriptor to the socket 697 * use_ssl - Whether we need an SSL connection 698 * Returns: 699 * a tag signifying the connection attempt 678 700 */ 679 701 int YAHOO_CALLBACK_TYPE(ext_yahoo_connect_async) (int id, 680 702 const char *host, int port, yahoo_connect_callback callback, 681 void *callback_data); 703 void *callback_data, int use_ssl); 704 705 /* 706 * Name: ext_yahoo_get_ip_addr 707 * get IP Address for a domain name 708 * Params: 709 * domain - Domain name 710 * Returns: 711 * Newly allocated string containing the IP Address in IPv4 notation 712 */ 713 char *YAHOO_CALLBACK_TYPE(ext_yahoo_get_ip_addr) (const char *domain); 714 715 /* 716 * Name: ext_yahoo_write 717 * Write data from the buffer into the socket for the specified connection 718 * Params: 719 * fd - the file descriptor object that identifies this connection 720 * buf - Buffer to write the data from 721 * len - Length of the data 722 * Returns: 723 * Number of bytes written or -1 for error 724 */ 725 int YAHOO_CALLBACK_TYPE(ext_yahoo_write) (void *fd, char *buf, int len); 726 727 /* 728 * Name: ext_yahoo_read 729 * Read data into a buffer from socket for the specified connection 730 * Params: 731 * fd - the file descriptor object that identifies this connection 732 * buf - Buffer to read the data into 733 * len - Max length to read 734 * Returns: 735 * Number of bytes read or -1 for error 736 */ 737 int YAHOO_CALLBACK_TYPE(ext_yahoo_read) (void *fd, char *buf, int len); 738 739 /* 740 * Name: ext_yahoo_close 741 * Close the file descriptor object and free its resources. Libyahoo2 will not 742 * use this object again. 743 * Params: 744 * fd - the file descriptor object that identifies this connection 745 * Returns: 746 * Nothing 747 */ 748 void YAHOO_CALLBACK_TYPE(ext_yahoo_close) (void *fd); 749 750 /* 751 * Name: ext_yahoo_got_buddy_change_group 752 * Acknowledgement of buddy changing group 753 * Params: 754 * id: client id 755 * me: The user 756 * who: Buddy name 757 * old_group: Old group name 758 * new_group: New group name 759 * Returns: 760 * Nothing 761 */ 762 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddy_change_group) (int id, 763 const char *me, const char *who, const char *old_group, 764 const char *new_group); 682 765 683 766 #ifdef USE_STRUCT_CALLBACKS … … 699 782 700 783 #endif 701 -
protocols/yahoo/yahoo2_types.h
rc36f73b r9034ba0 29 29 #endif 30 30 31 enum yahoo_status { 32 YAHOO_STATUS_DISCONNECTED = -1, 33 YAHOO_STATUS_AVAILABLE = 0, 34 YAHOO_STATUS_BRB, 35 YAHOO_STATUS_BUSY, 36 YAHOO_STATUS_NOTATHOME, 37 YAHOO_STATUS_NOTATDESK, 38 YAHOO_STATUS_NOTINOFFICE, 39 YAHOO_STATUS_ONPHONE, 40 YAHOO_STATUS_ONVACATION, 41 YAHOO_STATUS_OUTTOLUNCH, 42 YAHOO_STATUS_STEPPEDOUT, 43 YAHOO_STATUS_INVISIBLE = 12, 44 YAHOO_STATUS_CUSTOM = 99, 45 YAHOO_STATUS_IDLE = 999, 46 YAHOO_STATUS_WEBLOGIN = 0x5a55aa55, 47 YAHOO_STATUS_OFFLINE = 0x5a55aa56, /* don't ask */ 48 YAHOO_STATUS_NOTIFY = 0x16 /* TYPING */ 49 }; 50 #define YAHOO_STATUS_GAME 0x2 /* Games don't fit into the regular status model */ 51 52 enum yahoo_login_status { 53 YAHOO_LOGIN_OK = 0, 54 YAHOO_LOGIN_LOGOFF = 2, 55 YAHOO_LOGIN_UNAME = 3, 56 YAHOO_LOGIN_PASSWD = 13, 57 YAHOO_LOGIN_LOCK = 14, 58 YAHOO_LOGIN_DUPL = 99, 59 YAHOO_LOGIN_SOCK = -1, 60 }; 61 62 enum ypacket_status { 63 YPACKET_STATUS_DISCONNECTED = -1, 64 YPACKET_STATUS_DEFAULT = 0, 65 YPACKET_STATUS_SERVERACK = 1, 66 YPACKET_STATUS_GAME = 0x2, 67 YPACKET_STATUS_AWAY = 0x4, 68 YPACKET_STATUS_CONTINUED = 0x5, 69 YPACKET_STATUS_INVISIBLE = 12, 70 YPACKET_STATUS_NOTIFY = 0x16, /* TYPING */ 71 YPACKET_STATUS_WEBLOGIN = 0x5a55aa55, 72 YPACKET_STATUS_OFFLINE = 0x5a55aa56 73 }; 74 75 enum yahoo_error { 76 E_UNKNOWN = -1, 77 E_CONNECTION = -2, 78 E_SYSTEM = -3, 79 E_CUSTOM = 0, 80 81 /* responses from ignore buddy */ 82 E_IGNOREDUP = 2, 83 E_IGNORENONE = 3, 84 E_IGNORECONF = 12, 85 86 /* conference */ 87 E_CONFNOTAVAIL = 20 88 }; 89 90 enum yahoo_log_level { 91 YAHOO_LOG_NONE = 0, 92 YAHOO_LOG_FATAL, 93 YAHOO_LOG_ERR, 94 YAHOO_LOG_WARNING, 95 YAHOO_LOG_NOTICE, 96 YAHOO_LOG_INFO, 97 YAHOO_LOG_DEBUG 98 }; 31 enum yahoo_service { /* these are easier to see in hex */ 32 YAHOO_SERVICE_LOGON = 1, 33 YAHOO_SERVICE_LOGOFF, 34 YAHOO_SERVICE_ISAWAY, 35 YAHOO_SERVICE_ISBACK, 36 YAHOO_SERVICE_IDLE, /* 5 (placemarker) */ 37 YAHOO_SERVICE_MESSAGE, 38 YAHOO_SERVICE_IDACT, 39 YAHOO_SERVICE_IDDEACT, 40 YAHOO_SERVICE_MAILSTAT, 41 YAHOO_SERVICE_USERSTAT, /* 0xa */ 42 YAHOO_SERVICE_NEWMAIL, 43 YAHOO_SERVICE_CHATINVITE, 44 YAHOO_SERVICE_CALENDAR, 45 YAHOO_SERVICE_NEWPERSONALMAIL, 46 YAHOO_SERVICE_NEWCONTACT, 47 YAHOO_SERVICE_ADDIDENT, /* 0x10 */ 48 YAHOO_SERVICE_ADDIGNORE, 49 YAHOO_SERVICE_PING, 50 YAHOO_SERVICE_GOTGROUPRENAME, /* < 1, 36(old), 37(new) */ 51 YAHOO_SERVICE_SYSMESSAGE = 0x14, 52 YAHOO_SERVICE_SKINNAME = 0x15, 53 YAHOO_SERVICE_PASSTHROUGH2 = 0x16, 54 YAHOO_SERVICE_CONFINVITE = 0x18, 55 YAHOO_SERVICE_CONFLOGON, 56 YAHOO_SERVICE_CONFDECLINE, 57 YAHOO_SERVICE_CONFLOGOFF, 58 YAHOO_SERVICE_CONFADDINVITE, 59 YAHOO_SERVICE_CONFMSG, 60 YAHOO_SERVICE_CHATLOGON, 61 YAHOO_SERVICE_CHATLOGOFF, 62 YAHOO_SERVICE_CHATMSG = 0x20, 63 YAHOO_SERVICE_GAMELOGON = 0x28, 64 YAHOO_SERVICE_GAMELOGOFF, 65 YAHOO_SERVICE_GAMEMSG = 0x2a, 66 YAHOO_SERVICE_FILETRANSFER = 0x46, 67 YAHOO_SERVICE_VOICECHAT = 0x4A, 68 YAHOO_SERVICE_NOTIFY, 69 YAHOO_SERVICE_VERIFY, 70 YAHOO_SERVICE_P2PFILEXFER, 71 YAHOO_SERVICE_PEERTOPEER = 0x4F, /* Checks if P2P possible */ 72 YAHOO_SERVICE_WEBCAM, 73 YAHOO_SERVICE_AUTHRESP = 0x54, 74 YAHOO_SERVICE_LIST, 75 YAHOO_SERVICE_AUTH = 0x57, 76 YAHOO_SERVICE_AUTHBUDDY = 0x6d, 77 YAHOO_SERVICE_ADDBUDDY = 0x83, 78 YAHOO_SERVICE_REMBUDDY, 79 YAHOO_SERVICE_IGNORECONTACT, /* > 1, 7, 13 < 1, 66, 13, 0 */ 80 YAHOO_SERVICE_REJECTCONTACT, 81 YAHOO_SERVICE_GROUPRENAME = 0x89, /* > 1, 65(new), 66(0), 67(old) */ 82 YAHOO_SERVICE_Y7_PING = 0x8A, 83 YAHOO_SERVICE_CHATONLINE = 0x96, /* > 109(id), 1, 6(abcde) < 0,1 */ 84 YAHOO_SERVICE_CHATGOTO, 85 YAHOO_SERVICE_CHATJOIN, /* > 1 104-room 129-1600326591 62-2 */ 86 YAHOO_SERVICE_CHATLEAVE, 87 YAHOO_SERVICE_CHATEXIT = 0x9b, 88 YAHOO_SERVICE_CHATADDINVITE = 0x9d, 89 YAHOO_SERVICE_CHATLOGOUT = 0xa0, 90 YAHOO_SERVICE_CHATPING, 91 YAHOO_SERVICE_COMMENT = 0xa8, 92 YAHOO_SERVICE_GAME_INVITE = 0xb7, 93 YAHOO_SERVICE_STEALTH_PERM = 0xb9, 94 YAHOO_SERVICE_STEALTH_SESSION = 0xba, 95 YAHOO_SERVICE_AVATAR = 0xbc, 96 YAHOO_SERVICE_PICTURE_CHECKSUM = 0xbd, 97 YAHOO_SERVICE_PICTURE = 0xbe, 98 YAHOO_SERVICE_PICTURE_UPDATE = 0xc1, 99 YAHOO_SERVICE_PICTURE_UPLOAD = 0xc2, 100 YAHOO_SERVICE_YAB_UPDATE = 0xc4, 101 YAHOO_SERVICE_Y6_VISIBLE_TOGGLE = 0xc5, /* YMSG13, key 13: 2 = invisible, 1 = visible */ 102 YAHOO_SERVICE_Y6_STATUS_UPDATE = 0xc6, /* YMSG13 */ 103 YAHOO_SERVICE_PICTURE_STATUS = 0xc7, /* YMSG13, key 213: 0 = none, 1 = avatar, 2 = picture */ 104 YAHOO_SERVICE_VERIFY_ID_EXISTS = 0xc8, 105 YAHOO_SERVICE_AUDIBLE = 0xd0, 106 YAHOO_SERVICE_Y7_PHOTO_SHARING = 0xd2, 107 YAHOO_SERVICE_Y7_CONTACT_DETAILS = 0xd3, /* YMSG13 */ 108 YAHOO_SERVICE_Y7_CHAT_SESSION = 0xd4, 109 YAHOO_SERVICE_Y7_AUTHORIZATION = 0xd6, /* YMSG13 */ 110 YAHOO_SERVICE_Y7_FILETRANSFER = 0xdc, /* YMSG13 */ 111 YAHOO_SERVICE_Y7_FILETRANSFERINFO, /* YMSG13 */ 112 YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, /* YMSG13 */ 113 YAHOO_SERVICE_Y7_MINGLE = 0xe1, /* YMSG13 */ 114 YAHOO_SERVICE_Y7_CHANGE_GROUP = 0xe7, /* YMSG13 */ 115 YAHOO_SERVICE_MYSTERY = 0xef, /* Don't know what this is for */ 116 YAHOO_SERVICE_Y8_STATUS = 0xf0, /* YMSG15 */ 117 YAHOO_SERVICE_Y8_LIST = 0Xf1, /* YMSG15 */ 118 YAHOO_SERVICE_MESSAGE_CONFIRM = 0xfb, 119 YAHOO_SERVICE_WEBLOGIN = 0x0226, 120 YAHOO_SERVICE_SMS_MSG = 0x02ea 121 }; 122 123 enum yahoo_status { 124 YAHOO_STATUS_AVAILABLE = 0, 125 YAHOO_STATUS_BRB, 126 YAHOO_STATUS_BUSY, 127 YAHOO_STATUS_NOTATHOME, 128 YAHOO_STATUS_NOTATDESK, 129 YAHOO_STATUS_NOTINOFFICE, 130 YAHOO_STATUS_ONPHONE, 131 YAHOO_STATUS_ONVACATION, 132 YAHOO_STATUS_OUTTOLUNCH, 133 YAHOO_STATUS_STEPPEDOUT, 134 YAHOO_STATUS_INVISIBLE = 12, 135 YAHOO_STATUS_CUSTOM = 99, 136 YAHOO_STATUS_IDLE = 999, 137 YAHOO_STATUS_OFFLINE = 0x5a55aa56 /* don't ask */ 138 }; 139 140 enum ypacket_status { 141 YPACKET_STATUS_DISCONNECTED = -1, 142 YPACKET_STATUS_DEFAULT = 0, 143 YPACKET_STATUS_SERVERACK = 1, 144 YPACKET_STATUS_GAME = 0x2, 145 YPACKET_STATUS_AWAY = 0x4, 146 YPACKET_STATUS_CONTINUED = 0x5, 147 YPACKET_STATUS_INVISIBLE = 12, 148 YPACKET_STATUS_NOTIFY = 0x16, /* TYPING */ 149 YPACKET_STATUS_WEBLOGIN = 0x5a55aa55, 150 YPACKET_STATUS_OFFLINE = 0x5a55aa56 151 }; 152 153 #define YAHOO_STATUS_GAME 0x2 /* Games don't fit into the regular status model */ 154 155 enum yahoo_login_status { 156 YAHOO_LOGIN_OK = 0, 157 YAHOO_LOGIN_LOGOFF = 1, 158 YAHOO_LOGIN_UNAME = 3, 159 YAHOO_LOGIN_PASSWD = 13, 160 YAHOO_LOGIN_LOCK = 14, 161 YAHOO_LOGIN_DUPL = 99, 162 YAHOO_LOGIN_SOCK = -1, 163 YAHOO_LOGIN_UNKNOWN = 999 164 }; 165 166 enum yahoo_error { 167 E_UNKNOWN = -1, 168 E_CONNECTION = -2, 169 E_SYSTEM = -3, 170 E_CUSTOM = 0, 171 172 /* responses from ignore buddy */ 173 E_IGNOREDUP = 2, 174 E_IGNORENONE = 3, 175 E_IGNORECONF = 12, 176 177 /* conference */ 178 E_CONFNOTAVAIL = 20 179 }; 180 181 enum yahoo_log_level { 182 YAHOO_LOG_NONE = 0, 183 YAHOO_LOG_FATAL, 184 YAHOO_LOG_ERR, 185 YAHOO_LOG_WARNING, 186 YAHOO_LOG_NOTICE, 187 YAHOO_LOG_INFO, 188 YAHOO_LOG_DEBUG 189 }; 190 191 enum yahoo_file_transfer { 192 YAHOO_FILE_TRANSFER_INIT = 1, 193 YAHOO_FILE_TRANSFER_ACCEPT = 3, 194 YAHOO_FILE_TRANSFER_REJECT = 4, 195 YAHOO_FILE_TRANSFER_DONE = 5, 196 YAHOO_FILE_TRANSFER_RELAY, 197 YAHOO_FILE_TRANSFER_FAILED, 198 YAHOO_FILE_TRANSFER_UNKNOWN 199 }; 99 200 100 201 #define YAHOO_PROTO_VER 0x0010 … … 121 222 #define YAHOO_STYLE_URLOFF "\033[xlm" 122 223 123 enum yahoo_connection_type {124 YAHOO_CONNECTION_PAGER=0,125 YAHOO_CONNECTION_FT,126 YAHOO_CONNECTION_YAB,127 YAHOO_CONNECTION_WEBCAM_MASTER,128 YAHOO_CONNECTION_WEBCAM,129 YAHOO_CONNECTION_CHATCAT,130 YAHOO_CONNECTION_SEARCH,131 YAHOO_CONNECTION_AUTH,132 };133 134 enum yahoo_webcam_direction_type {135 YAHOO_WEBCAM_DOWNLOAD=0,136 137 };138 139 enum yahoo_stealth_visibility_type {140 YAHOO_STEALTH_DEFAULT = 0,141 142 143 };224 enum yahoo_connection_type { 225 YAHOO_CONNECTION_PAGER = 0, 226 YAHOO_CONNECTION_FT, 227 YAHOO_CONNECTION_YAB, 228 YAHOO_CONNECTION_WEBCAM_MASTER, 229 YAHOO_CONNECTION_WEBCAM, 230 YAHOO_CONNECTION_CHATCAT, 231 YAHOO_CONNECTION_SEARCH, 232 YAHOO_CONNECTION_AUTH 233 }; 234 235 enum yahoo_webcam_direction_type { 236 YAHOO_WEBCAM_DOWNLOAD = 0, 237 YAHOO_WEBCAM_UPLOAD 238 }; 239 240 enum yahoo_stealth_visibility_type { 241 YAHOO_STEALTH_DEFAULT = 0, 242 YAHOO_STEALTH_ONLINE, 243 YAHOO_STEALTH_PERM_OFFLINE 244 }; 144 245 145 246 /* chat member attribs */ 146 247 #define YAHOO_CHAT_MALE 0x8000 147 248 #define YAHOO_CHAT_FEMALE 0x10000 249 #define YAHOO_CHAT_FEMALE 0x10000 148 250 #define YAHOO_CHAT_DUNNO 0x400 149 251 #define YAHOO_CHAT_WEBCAM 0x10 150 252 151 enum yahoo_webcam_conn_type { Y_WCM_DIALUP, Y_WCM_DSL, Y_WCM_T1 }; 152 153 struct yahoo_webcam { 154 int direction; /* Uploading or downloading */ 155 int conn_type; /* 0=Dialup, 1=DSL/Cable, 2=T1/Lan */ 156 157 char *user; /* user we are viewing */ 158 char *server; /* webcam server to connect to */ 159 int port; /* webcam port to connect on */ 160 char *key; /* key to connect to the server with */ 161 char *description; /* webcam description */ 162 char *my_ip; /* own ip number */ 163 }; 164 165 struct yahoo_webcam_data { 166 unsigned int data_size; 167 unsigned int to_read; 168 unsigned int timestamp; 169 unsigned char packet_type; 170 }; 171 172 struct yahoo_data { 173 char *user; 174 char *password; 175 176 char *cookie_y; 177 char *cookie_t; 178 char *cookie_c; 179 char *login_cookie; 180 181 YList *buddies; 182 YList *ignore; 183 YList *identities; 184 char *login_id; 185 186 int current_status; 187 int initial_status; 188 int logged_in; 189 190 int session_id; 191 192 int client_id; 193 194 char *rawbuddylist; 195 char *ignorelist; 196 197 void *server_settings; 198 199 struct yahoo_process_status_entry *half_user; 200 }; 201 202 struct yab { 203 int yid; 204 char *id; 205 char *fname; 206 char *lname; 207 char *nname; 208 char *email; 209 char *hphone; 210 char *wphone; 211 char *mphone; 212 int dbid; 213 }; 214 215 struct yahoo_buddy { 216 char *group; 217 char *id; 218 char *real_name; 219 struct yab *yab_entry; 220 }; 221 222 enum yahoo_search_type { 223 YAHOO_SEARCH_KEYWORD = 0, 224 YAHOO_SEARCH_YID, 225 YAHOO_SEARCH_NAME 226 }; 227 228 enum yahoo_search_gender { 229 YAHOO_GENDER_NONE = 0, 230 YAHOO_GENDER_MALE, 231 YAHOO_GENDER_FEMALE 232 }; 233 234 enum yahoo_search_agerange { 235 YAHOO_AGERANGE_NONE = 0 236 }; 237 238 struct yahoo_found_contact { 239 char *id; 240 char *gender; 241 char *location; 242 int age; 243 int online; 244 }; 253 enum yahoo_webcam_conn_type { Y_WCM_DIALUP, Y_WCM_DSL, Y_WCM_T1 }; 254 255 struct yahoo_webcam { 256 int direction; /* Uploading or downloading */ 257 int conn_type; /* 0=Dialup, 1=DSL/Cable, 2=T1/Lan */ 258 259 char *user; /* user we are viewing */ 260 char *server; /* webcam server to connect to */ 261 int port; /* webcam port to connect on */ 262 char *key; /* key to connect to the server with */ 263 char *description; /* webcam description */ 264 char *my_ip; /* own ip number */ 265 }; 266 267 struct yahoo_webcam_data { 268 unsigned int data_size; 269 unsigned int to_read; 270 unsigned int timestamp; 271 unsigned char packet_type; 272 }; 273 274 struct yahoo_data { 275 char *user; 276 char *password; 277 278 char *cookie_y; 279 char *cookie_t; 280 char *cookie_c; 281 char *cookie_b; 282 char *login_cookie; 283 char *crumb; 284 char *seed; 285 286 YList *buddies; 287 YList *ignore; 288 YList *identities; 289 char *login_id; 290 291 int current_status; 292 int initial_status; 293 int logged_in; 294 295 int session_id; 296 297 int client_id; 298 299 char *rawbuddylist; 300 char *ignorelist; 301 302 void *server_settings; 303 304 struct yahoo_process_status_entry *half_user; 305 }; 306 307 struct yab { 308 int yid; 309 char *id; 310 char *fname; 311 char *lname; 312 char *nname; 313 char *email; 314 char *hphone; 315 char *wphone; 316 char *mphone; 317 int dbid; 318 }; 319 320 struct yahoo_buddy { 321 char *group; 322 char *id; 323 char *real_name; 324 struct yab *yab_entry; 325 }; 326 327 enum yahoo_search_type { 328 YAHOO_SEARCH_KEYWORD = 0, 329 YAHOO_SEARCH_YID, 330 YAHOO_SEARCH_NAME 331 }; 332 333 enum yahoo_search_gender { 334 YAHOO_GENDER_NONE = 0, 335 YAHOO_GENDER_MALE, 336 YAHOO_GENDER_FEMALE 337 }; 338 339 enum yahoo_search_agerange { 340 YAHOO_AGERANGE_NONE = 0 341 }; 342 343 struct yahoo_found_contact { 344 char *id; 345 char *gender; 346 char *location; 347 int age; 348 int online; 349 }; 245 350 246 351 /* 247 352 * Function pointer to be passed to http get/post and send file 248 353 */ 249 typedef void (*yahoo_get_fd_callback)(int id, int fd, int error, void *data); 354 typedef void (*yahoo_get_fd_callback) (int id, void *fd, int error, 355 void *data); 250 356 251 357 /* 252 358 * Function pointer to be passed to yahoo_get_url_handle 253 359 */ 254 typedef void (*yahoo_get_url_handle_callback)(int id, int fd, int error,255 const char *filename, unsigned long size, void *data);256 257 258 struct yahoo_chat_member {259 char *id;260 intage;261 intattribs;262 char *alias;263 char *location;264 };265 266 struct yahoo_process_status_entry { 267 char *name; /* 7 name */268 int state; /* 10 state */269 int flags; /* 13 flags, bit 0 = pager, bit 1 = chat, bit 2 = game */270 int mobile; /* 60 mobile */271 char *msg; /* 19 custom status message */272 int away; /* 47 away (or invisible) */273 int buddy_session; /* 11 state */274 int f17; /* 17 in chat? then what about flags? */275 int idle; /* 137 seconds idle */276 int f138; /* 138 state */277 char *f184; /* 184 state */278 int f192; /* 192 state */279 int f10001; /* 10001 state */280 int f10002; /* 10002 state */281 int f198; /* 198 state */282 char *f197; /* 197 state */283 char *f205; /* 205 state */284 int f213; /* 213 state */285 };360 typedef void (*yahoo_get_url_handle_callback) (int id, void *fd, 361 int error, const char *filename, unsigned long size, 362 void *data); 363 364 struct yahoo_chat_member { 365 char *id; 366 int age; 367 int attribs; 368 char *alias; 369 char *location; 370 }; 371 372 struct yahoo_process_status_entry { 373 char *name; /* 7 name */ 374 int state; /* 10 state */ 375 int flags; /* 13 flags, bit 0 = pager, bit 1 = chat, bit 2 = game */ 376 int mobile; /* 60 mobile */ 377 char *msg; /* 19 custom status message */ 378 int away; /* 47 away (or invisible) */ 379 int buddy_session; /* 11 state */ 380 int f17; /* 17 in chat? then what about flags? */ 381 int idle; /* 137 seconds idle */ 382 int f138; /* 138 state */ 383 char *f184; /* 184 state */ 384 int f192; /* 192 state */ 385 int f10001; /* 10001 state */ 386 int f10002; /* 10002 state */ 387 int f198; /* 198 state */ 388 char *f197; /* 197 state */ 389 char *f205; /* 205 state */ 390 int f213; /* 213 state */ 391 }; 286 392 287 393 #ifdef __cplusplus 288 394 } 289 395 #endif 290 291 396 #endif -
protocols/yahoo/yahoo_httplib.c
rc36f73b r9034ba0 30 30 # define strrchr rindex 31 31 # endif 32 char *strchr (), *strrchr();32 char *strchr(), *strrchr(); 33 33 # if !HAVE_MEMCPY 34 34 # define memcpy(d, s, n) bcopy ((s), (d), (n)) … … 36 36 # endif 37 37 #endif 38 39 38 40 39 #include <errno.h> … … 63 62 extern enum yahoo_log_level log_level; 64 63 65 int yahoo_tcp_readline(char *ptr, int maxlen, intfd)64 int yahoo_tcp_readline(char *ptr, int maxlen, void *fd) 66 65 { 67 66 int n, rc; … … 71 70 72 71 do { 73 rc = read(fd, &c, 1);74 } while (rc == -1 && (errno == EINTR || errno == EAGAIN));/* this is bad - it should be done asynchronously */72 rc = YAHOO_CALLBACK(ext_yahoo_read) (fd, &c, 1); 73 } while (rc == -1 && (errno == EINTR || errno == EAGAIN)); /* this is bad - it should be done asynchronously */ 75 74 76 75 if (rc == 1) { 77 if (c == '\r')/* get rid of \r */76 if (c == '\r') /* get rid of \r */ 78 77 continue; 79 78 *ptr = c; … … 83 82 } else if (rc == 0) { 84 83 if (n == 1) 85 return (0); 84 return (0); /* EOF, no data */ 86 85 else 87 break; 86 break; /* EOF, w/ data */ 88 87 } else { 89 88 return -1; … … 96 95 97 96 static int url_to_host_port_path(const char *url, 98 char *host, int *port, char *path)99 { 100 char *urlcopy =NULL;101 char *slash =NULL;102 char *colon =NULL;103 97 char *host, int *port, char *path, int *ssl) 98 { 99 char *urlcopy = NULL; 100 char *slash = NULL; 101 char *colon = NULL; 102 104 103 /* 105 104 * http://hostname … … 111 110 * http://hostname:port/path 112 111 * http://hostname:port/path:foo 112 * and https:// variants of the above 113 113 */ 114 114 115 if(strstr(url, "http://") == url) { 116 urlcopy = strdup(url+7); 115 if (strstr(url, "http://") == url) { 116 urlcopy = strdup(url + 7); 117 } else if (strstr(url, "https://") == url) { 118 urlcopy = strdup(url + 8); 119 *ssl = 1; 117 120 } else { 118 121 WARNING(("Weird url - unknown protocol: %s", url)); … … 123 126 colon = strchr(urlcopy, ':'); 124 127 125 if(!colon || (slash && slash < colon)) { 126 *port = 80; 128 if (!colon || (slash && slash < colon)) { 129 if (*ssl) 130 *port = 443; 131 else 132 *port = 80; 127 133 } else { 128 134 *colon = 0; 129 *port = atoi(colon +1);130 } 131 132 if (!slash) {135 *port = atoi(colon + 1); 136 } 137 138 if (!slash) { 133 139 strcpy(path, "/"); 134 140 } else { … … 138 144 139 145 strcpy(host, urlcopy); 140 146 141 147 FREE(urlcopy); 142 148 … … 146 152 static int isurlchar(unsigned char c) 147 153 { 148 return (isalnum(c) || '-' == c || '_' == c);154 return (isalnum(c)); 149 155 } 150 156 151 157 char *yahoo_urlencode(const char *instr) 152 158 { 153 int ipos =0, bpos=0;159 int ipos = 0, bpos = 0; 154 160 char *str = NULL; 155 161 int len = strlen(instr); 156 162 157 if (!(str = y_new(char, 3*len + 1)))158 return "";159 160 while (instr[ipos]) {161 while (isurlchar(instr[ipos]))163 if (!(str = y_new(char, 3 *len + 1))) 164 return ""; 165 166 while (instr[ipos]) { 167 while (isurlchar(instr[ipos])) 162 168 str[bpos++] = instr[ipos++]; 163 if (!instr[ipos])169 if (!instr[ipos]) 164 170 break; 165 166 snprintf(&str[bpos], 4, "%%% .2x", instr[ipos]);167 bpos +=3;171 172 snprintf(&str[bpos], 4, "%%%02x", instr[ipos] & 0xff); 173 bpos += 3; 168 174 ipos++; 169 175 } 170 str[bpos] ='\0';176 str[bpos] = '\0'; 171 177 172 178 /* free extra alloc'ed mem. */ 173 179 len = strlen(str); 174 str = y_renew(char, str, len +1);180 str = y_renew(char, str, len + 1); 175 181 176 182 return (str); … … 179 185 char *yahoo_urldecode(const char *instr) 180 186 { 181 int ipos =0, bpos=0;187 int ipos = 0, bpos = 0; 182 188 char *str = NULL; 183 char entity[3] ={0,0,0};189 char entity[3] = { 0, 0, 0 }; 184 190 unsigned dec; 185 191 int len = strlen(instr); 186 192 187 if (!(str = y_new(char, len+1)))188 return "";189 190 while (instr[ipos]) {191 while (instr[ipos] && instr[ipos]!='%')192 if (instr[ipos]=='+') {193 str[bpos++] =' ';193 if (!(str = y_new(char, len + 1))) 194 return ""; 195 196 while (instr[ipos]) { 197 while (instr[ipos] && instr[ipos] != '%') 198 if (instr[ipos] == '+') { 199 str[bpos++] = ' '; 194 200 ipos++; 195 201 } else 196 202 str[bpos++] = instr[ipos++]; 197 if (!instr[ipos])203 if (!instr[ipos]) 198 204 break; 199 200 if (instr[ipos+1] && instr[ipos+2]) {205 206 if (instr[ipos + 1] && instr[ipos + 2]) { 201 207 ipos++; 202 entity[0] =instr[ipos++];203 entity[1] =instr[ipos++];208 entity[0] = instr[ipos++]; 209 entity[1] = instr[ipos++]; 204 210 sscanf(entity, "%2x", &dec); 205 211 str[bpos++] = (char)dec; … … 208 214 } 209 215 } 210 str[bpos] ='\0';216 str[bpos] = '\0'; 211 217 212 218 /* free extra alloc'ed mem. */ 213 219 len = strlen(str); 214 str = y_renew(char, str, len +1);220 str = y_renew(char, str, len + 1); 215 221 216 222 return (str); … … 219 225 char *yahoo_xmldecode(const char *instr) 220 226 { 221 int ipos =0, bpos=0, epos=0;227 int ipos = 0, bpos = 0, epos = 0; 222 228 char *str = NULL; 223 char entity[4] ={0,0,0,0};224 char *entitymap[5][2] ={225 {"amp;", "&"},229 char entity[4] = { 0, 0, 0, 0 }; 230 char *entitymap[5][2] = { 231 {"amp;", "&"}, 226 232 {"quot;", "\""}, 227 {"lt;", "<"},228 {"gt;", "<"},233 {"lt;", "<"}, 234 {"gt;", "<"}, 229 235 {"nbsp;", " "} 230 236 }; … … 232 238 int len = strlen(instr); 233 239 234 if (!(str = y_new(char, len+1)))235 return "";236 237 while (instr[ipos]) {238 while (instr[ipos] && instr[ipos]!='&')239 if (instr[ipos]=='+') {240 str[bpos++] =' ';240 if (!(str = y_new(char, len + 1))) 241 return ""; 242 243 while (instr[ipos]) { 244 while (instr[ipos] && instr[ipos] != '&') 245 if (instr[ipos] == '+') { 246 str[bpos++] = ' '; 241 247 ipos++; 242 248 } else 243 249 str[bpos++] = instr[ipos++]; 244 if (!instr[ipos] || !instr[ipos+1])250 if (!instr[ipos] || !instr[ipos + 1]) 245 251 break; 246 252 ipos++; 247 253 248 if (instr[ipos] == '#') {254 if (instr[ipos] == '#') { 249 255 ipos++; 250 epos =0;251 while (instr[ipos] != ';')252 entity[epos++] =instr[ipos++];256 epos = 0; 257 while (instr[ipos] != ';') 258 entity[epos++] = instr[ipos++]; 253 259 sscanf(entity, "%u", &dec); 254 260 str[bpos++] = (char)dec; … … 256 262 } else { 257 263 int i; 258 for (i =0; i<5; i++)259 if (!strncmp(instr+ipos, entitymap[i][0],260 261 264 for (i = 0; i < 5; i++) 265 if (!strncmp(instr + ipos, entitymap[i][0], 266 strlen(entitymap[i][0]))) { 267 str[bpos++] = entitymap[i][1][0]; 262 268 ipos += strlen(entitymap[i][0]); 263 269 break; … … 265 271 } 266 272 } 267 str[bpos] ='\0';273 str[bpos] = '\0'; 268 274 269 275 /* free extra alloc'ed mem. */ 270 276 len = strlen(str); 271 str = y_renew(char, str, len +1);277 str = y_renew(char, str, len + 1); 272 278 273 279 return (str); 274 280 } 275 281 276 typedef void (*http_connected) (int id, intfd, int error);282 typedef void (*http_connected) (int id, void *fd, int error); 277 283 278 284 struct callback_data { … … 283 289 }; 284 290 285 static void connect_complete( intfd, int error, void *data)291 static void connect_complete(void *fd, int error, void *data) 286 292 { 287 293 struct callback_data *ccd = data; 288 if(error == 0 && fd > 0) 289 write(fd, ccd->request, strlen(ccd->request)); 290 FREE(ccd->request); 294 if (error == 0) 295 YAHOO_CALLBACK(ext_yahoo_write) (fd, ccd->request, 296 strlen(ccd->request)); 297 free(ccd->request); 291 298 ccd->callback(ccd->id, fd, error, ccd->user_data); 292 299 FREE(ccd); 293 300 } 294 301 295 static void yahoo_send_http_request(int id, char *host, int port, char *request, 296 yahoo_get_fd_callback callback, void *data)297 { 298 struct callback_data *ccd =y_new0(struct callback_data, 1);302 static void yahoo_send_http_request(int id, char *host, int port, char *request, 303 yahoo_get_fd_callback callback, void *data, int use_ssl) 304 { 305 struct callback_data *ccd = y_new0(struct callback_data, 1); 299 306 ccd->callback = callback; 300 307 ccd->id = id; 301 308 ccd->request = strdup(request); 302 309 ccd->user_data = data; 303 304 YAHOO_CALLBACK(ext_yahoo_connect_async)(id, host, port, connect_complete, ccd); 305 } 306 307 void yahoo_http_post(int id, const char *url, const char *cookies, long content_length, 308 yahoo_get_fd_callback callback, void *data) 310 311 YAHOO_CALLBACK(ext_yahoo_connect_async) (id, host, port, 312 connect_complete, ccd, use_ssl); 313 } 314 315 void yahoo_http_post(int id, const char *url, const char *cookies, 316 long content_length, yahoo_get_fd_callback callback, void *data) 309 317 { 310 318 char host[255]; … … 312 320 char path[255]; 313 321 char buff[1024]; 314 315 if(!url_to_host_port_path(url, host, &port, path)) 322 int ssl = 0; 323 324 if (!url_to_host_port_path(url, host, &port, path, &ssl)) 316 325 return; 317 326 318 snprintf(buff, sizeof(buff), 319 "POST %s HTTP/1.0\r\n" 320 "Content-length: %ld\r\n" 321 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n" 322 "Host: %s:%d\r\n" 323 "Cookie: %s\r\n" 324 "\r\n", 325 path, content_length, 326 host, port, 327 cookies); 328 329 yahoo_send_http_request(id, host, port, buff, callback, data); 330 } 331 332 void yahoo_http_get(int id, const char *url, const char *cookies, 333 yahoo_get_fd_callback callback, void *data) 327 /* thanks to kopete dumpcap */ 328 snprintf(buff, sizeof(buff), 329 "POST %s HTTP/1.1\r\n" 330 "Cookie: %s\r\n" 331 "User-Agent: Mozilla/5.0\r\n" 332 "Host: %s\r\n" 333 "Content-Length: %ld\r\n" 334 "Cache-Control: no-cache\r\n" 335 "\r\n", path, cookies, host, content_length); 336 337 yahoo_send_http_request(id, host, port, buff, callback, data, ssl); 338 } 339 340 void yahoo_http_get(int id, const char *url, const char *cookies, int http11, 341 int keepalive, yahoo_get_fd_callback callback, void *data) 334 342 { 335 343 char host[255]; 336 344 int port = 80; 337 345 char path[255]; 338 char buff[1024]; 339 340 if(!url_to_host_port_path(url, host, &port, path)) 346 char buff[2048]; 347 char cookiebuff[1024]; 348 int ssl = 0; 349 350 if (!url_to_host_port_path(url, host, &port, path, &ssl)) 341 351 return; 342 352 343 snprintf(buff, sizeof(buff),344 "GET %s HTTP/1.0\r\n"345 "Host: %s:%d\r\n"346 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n"347 "Cookie: %s\r\n"348 "\r\n",349 path, host, port, cookies); 350 351 yahoo_send_http_request(id, host, port, buff, callback, data);352 } 353 354 struct url_data { 355 yahoo_get_url_handle_callback callback;356 void *user_data;357 }; 358 359 static void yahoo_got_url_fd(int id, int fd, int error, void *data) 360 { 361 char *tmp=NULL; 362 char buff[1024];363 unsigned long filesize=0; 364 char *filename=NULL;365 int n;366 367 struct url_data *ud = data;368 369 i f(error || fd < 0) {370 ud->callback(id, fd, error, filename, filesize, ud->user_data); 371 FREE(ud);353 /* Allow cases when we don't need to send a cookie */ 354 if (cookies) 355 snprintf(cookiebuff, sizeof(cookiebuff), "Cookie: %s\r\n", 356 cookies); 357 else 358 cookiebuff[0] = '\0'; 359 360 snprintf(buff, sizeof(buff), 361 "GET %s HTTP/1.%s\r\n" 362 "%sHost: %s\r\n" 363 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n" 364 "Accept: */*\r\n" 365 "%s" "\r\n", path, http11?"1":"0", cookiebuff, host, 366 keepalive? "Connection: Keep-Alive\r\n":"Connection: close\r\n"); 367 368 yahoo_send_http_request(id, host, port, buff, callback, data, ssl); 369 } 370 371 void yahoo_http_head(int id, const char *url, const char *cookies, int len, 372 char *payload, yahoo_get_fd_callback callback, void *data) 373 { 374 char host[255]; 375 int port = 80; 376 char path[255]; 377 char buff[2048]; 378 char cookiebuff[1024]; 379 int ssl = 0; 380 381 if (!url_to_host_port_path(url, host, &port, path, &ssl)) 372 382 return; 373 } 374 375 while((n=yahoo_tcp_readline(buff, sizeof(buff), fd)) > 0) { 376 LOG(("Read:%s:\n", buff)); 377 if(!strcmp(buff, "")) 378 break; 379 380 if( !strncasecmp(buff, "Content-length:", 381 strlen("Content-length:")) ) { 382 tmp = strrchr(buff, ' '); 383 if(tmp) 384 filesize = atol(tmp); 385 } 386 387 if( !strncasecmp(buff, "Content-disposition:", 388 strlen("Content-disposition:")) ) { 389 tmp = strstr(buff, "name="); 390 if(tmp) { 391 tmp+=strlen("name="); 392 if(tmp[0] == '"') { 393 char *tmp2; 394 tmp++; 395 tmp2 = strchr(tmp, '"'); 396 if(tmp2) 397 *tmp2 = '\0'; 398 } else { 399 char *tmp2; 400 tmp2 = strchr(tmp, ';'); 401 if(!tmp2) 402 tmp2 = strchr(tmp, '\r'); 403 if(!tmp2) 404 tmp2 = strchr(tmp, '\n'); 405 if(tmp2) 406 *tmp2 = '\0'; 407 } 408 409 filename = strdup(tmp); 410 } 411 } 412 } 413 414 LOG(("n == %d\n", n)); 415 LOG(("Calling callback, filename:%s, size: %ld\n", filename, filesize)); 416 ud->callback(id, fd, error, filename, filesize, ud->user_data); 417 FREE(ud); 418 FREE(filename); 419 } 420 421 void yahoo_get_url_fd(int id, const char *url, const struct yahoo_data *yd, 422 yahoo_get_url_handle_callback callback, void *data) 423 { 424 char buff[1024]; 425 struct url_data *ud = y_new0(struct url_data, 1); 426 snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); 427 ud->callback = callback; 428 ud->user_data = data; 429 yahoo_http_get(id, url, buff, yahoo_got_url_fd, ud); 430 } 431 383 384 /* Allow cases when we don't need to send a cookie */ 385 if (cookies) 386 snprintf(cookiebuff, sizeof(cookiebuff), "Cookie: %s\r\n", 387 cookies); 388 else 389 cookiebuff[0] = '\0'; 390 391 snprintf(buff, sizeof(buff), 392 "HEAD %s HTTP/1.0\r\n" 393 "Accept: */*\r\n" 394 "Host: %s:%d\r\n" 395 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n" 396 "%s" 397 "Content-Length: %d\r\n" 398 "Cache-Control: no-cache\r\n" 399 "\r\n%s", path, host, port, cookiebuff, len, 400 payload?payload:""); 401 402 yahoo_send_http_request(id, host, port, buff, callback, data, ssl); 403 } 404 -
protocols/yahoo/yahoo_httplib.h
rc36f73b r9034ba0 29 29 #include "yahoo2_types.h" 30 30 31 char *yahoo_urlencode(const char *instr);32 char *yahoo_urldecode(const char *instr);33 char *yahoo_xmldecode(const char *instr);31 char *yahoo_urlencode(const char *instr); 32 char *yahoo_urldecode(const char *instr); 33 char *yahoo_xmldecode(const char *instr); 34 34 35 int yahoo_tcp_readline(char *ptr, int maxlen, int fd); 36 void yahoo_http_post(int id, const char *url, const char *cookies, long size, 37 yahoo_get_fd_callback callback, void *data); 38 void yahoo_http_get(int id, const char *url, const char *cookies, 39 yahoo_get_fd_callback callback, void *data); 40 void yahoo_get_url_fd(int id, const char *url, const struct yahoo_data *yd, 41 yahoo_get_url_handle_callback callback, void *data); 42 35 int yahoo_tcp_readline(char *ptr, int maxlen, void *fd); 36 void yahoo_http_post(int id, const char *url, const char *cookies, 37 long size, yahoo_get_fd_callback callback, void *data); 38 void yahoo_http_get(int id, const char *url, const char *cookies, 39 int http11, int keepalive, yahoo_get_fd_callback callback, 40 void *data); 41 void yahoo_http_head(int id, const char *url, const char *cookies, 42 int size, char *payload, yahoo_get_fd_callback callback, 43 void *data); 43 44 44 45 #ifdef __cplusplus 45 46 } 46 47 #endif 47 48 48 #endif -
protocols/yahoo/yahoo_list.h
rc36f73b r9034ba0 24 24 #define __YLIST_H__ 25 25 26 /* GLib has linked list already, so I don't see why libyahoo2 has to copy this... */26 /* BitlBee already uses GLib so use it. */ 27 27 28 28 typedef GList YList;
Note: See TracChangeset
for help on using the changeset viewer.