Changes in protocols/yahoo/libyahoo2.c [9fca0657:99c8f13]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/yahoo/libyahoo2.c
r9fca0657 r99c8f13 855 855 } 856 856 857 static YList * bud_str2list(char *rawlist) 858 { 859 YList * l = NULL; 860 861 char **lines; 862 char **split; 863 char **buddies; 864 char **tmp, **bud; 865 866 lines = y_strsplit(rawlist, "\n", -1); 867 for (tmp = lines; *tmp; tmp++) { 868 struct yahoo_buddy *newbud; 869 870 split = y_strsplit(*tmp, ":", 2); 871 if (!split) 872 continue; 873 if (!split[0] || !split[1]) { 874 y_strfreev(split); 875 continue; 876 } 877 buddies = y_strsplit(split[1], ",", -1); 878 879 for (bud = buddies; bud && *bud; bud++) { 880 newbud = y_new0(struct yahoo_buddy, 1); 881 newbud->id = strdup(*bud); 882 newbud->group = strdup(split[0]); 883 884 if(y_list_find_custom(l, newbud, is_same_bud)) { 885 FREE(newbud->id); 886 FREE(newbud->group); 887 FREE(newbud); 888 continue; 889 } 890 891 newbud->real_name = NULL; 892 893 l = y_list_append(l, newbud); 894 895 NOTICE(("Added buddy %s to group %s", newbud->id, newbud->group)); 896 } 897 898 y_strfreev(buddies); 899 y_strfreev(split); 900 } 901 y_strfreev(lines); 902 903 return l; 904 } 905 857 906 static char * getcookie(char *rawcookie) 858 907 { … … 1311 1360 } 1312 1361 1313 static void yahoo_process_status(struct yahoo_input_data *yid, 1314 1362 1363 static void yahoo_process_status(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1315 1364 { 1316 1365 YList *l; 1317 1366 struct yahoo_data *yd = yid->yd; 1318 1367 1319 struct yahoo_process_status_entry *u; 1368 struct user 1369 { 1370 char *name; /* 7 name */ 1371 int state; /* 10 state */ 1372 int flags; /* 13 flags, bit 0 = pager, bit 1 = chat, bit 2 = game */ 1373 int mobile; /* 60 mobile */ 1374 char *msg; /* 19 custom status message */ 1375 int away; /* 47 away (or invisible)*/ 1376 int buddy_session; /* 11 state */ 1377 int f17; /* 17 in chat? then what about flags? */ 1378 int idle; /* 137 seconds idle */ 1379 int f138; /* 138 state */ 1380 char *f184; /* 184 state */ 1381 int f192; /* 192 state */ 1382 int f10001; /* 10001 state */ 1383 int f10002; /* 10002 state */ 1384 int f198; /* 198 state */ 1385 char *f197; /* 197 state */ 1386 char *f205; /* 205 state */ 1387 int f213; /* 213 state */ 1388 } *u; 1320 1389 1321 1390 YList *users = 0; 1322 1391 1323 1392 if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) { 1324 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 1325 YAHOO_LOGIN_DUPL, NULL); 1326 return; 1327 } 1328 1329 /* Status updates may be spread accross multiple packets and not 1330 even on buddy boundaries, so keeping some state is important. 1331 So, continue where we left off, and only add a user entry to 1332 the list once it's complete (301-315 End buddy). */ 1333 u = yd->half_user; 1393 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_DUPL, NULL); 1394 return; 1395 } 1334 1396 1335 1397 for (l = pkt->hash; l; l = l->next) { … … 1337 1399 1338 1400 switch (pair->key) { 1339 case 300: /* Begin buddy */ 1340 if (!strcmp(pair->value, "315") && !u) { 1341 u = yd->half_user = y_new0(struct yahoo_process_status_entry, 1); 1401 case 0: /* we won't actually do anything with this */ 1402 NOTICE(("key %d:%s", pair->key, pair->value)); 1403 break; 1404 case 1: /* we don't get the full buddy list here. */ 1405 if (!yd->logged_in) { 1406 yd->logged_in = TRUE; 1407 if(yd->current_status < 0) 1408 yd->current_status = yd->initial_status; 1409 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL); 1342 1410 } 1343 1411 break; 1344 case 301: /* End buddy */ 1345 if (!strcmp(pair->value, "315") && u) { 1346 /* Sometimes user info comes in an odd format with no 1347 "begin buddy" but *with* an "end buddy". Don't add 1348 it twice. */ 1349 if (!y_list_find(users, u)) 1350 users = y_list_prepend(users, u); 1351 u = yd->half_user = NULL; 1352 } 1353 break; 1354 case 0: /* we won't actually do anything with this */ 1412 case 8: /* how many online buddies we have */ 1355 1413 NOTICE(("key %d:%s", pair->key, pair->value)); 1356 1414 break; 1357 case 1: /* we don't get the full buddy list here. */ 1358 if (!yd->logged_in) { 1359 yd->logged_in = 1; 1360 if (yd->current_status < 0) 1361 yd->current_status = yd->initial_status; 1362 YAHOO_CALLBACK(ext_yahoo_login_response) (yd-> 1363 client_id, YAHOO_LOGIN_OK, NULL); 1364 } 1365 break; 1366 case 8: /* how many online buddies we have */ 1367 NOTICE(("key %d:%s", pair->key, pair->value)); 1368 break; 1369 case 7: /* the current buddy */ 1370 if (!u) { 1371 /* This will only happen in case of a single level message */ 1372 u = y_new0(struct yahoo_process_status_entry, 1); 1373 users = y_list_prepend(users, u); 1374 } 1415 case 7: /* the current buddy */ 1416 u = y_new0(struct user, 1); 1375 1417 u->name = pair->value; 1376 break; 1377 case 10: /* state */ 1378 u->state = strtol(pair->value, NULL, 10); 1379 break; 1380 case 19: /* custom status message */ 1381 u->msg = pair->value; 1382 break; 1383 case 47: /* is it an away message or not. Not applicable for YMSG16 anymore */ 1384 u->away = atoi(pair->value); 1385 break; 1386 case 137: /* seconds idle */ 1387 u->idle = atoi(pair->value); 1388 break; 1389 case 11: /* this is the buddy's session id */ 1390 u->buddy_session = atoi(pair->value); 1391 break; 1392 case 17: /* in chat? */ 1393 u->f17 = atoi(pair->value); 1394 break; 1395 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */ 1396 u->flags = atoi(pair->value); 1397 break; 1398 case 60: /* SMS -> 1 MOBILE USER */ 1418 users = y_list_prepend(users, u); 1419 break; 1420 case 10: /* state */ 1421 ((struct user*)users->data)->state = strtol(pair->value, NULL, 10); 1422 break; 1423 case 19: /* custom status message */ 1424 ((struct user*)users->data)->msg = pair->value; 1425 break; 1426 case 47: /* is it an away message or not */ 1427 ((struct user*)users->data)->away = atoi(pair->value); 1428 break; 1429 case 137: /* seconds idle */ 1430 ((struct user*)users->data)->idle = atoi(pair->value); 1431 break; 1432 case 11: /* this is the buddy's session id */ 1433 ((struct user*)users->data)->buddy_session = atoi(pair->value); 1434 break; 1435 case 17: /* in chat? */ 1436 ((struct user*)users->data)->f17 = atoi(pair->value); 1437 break; 1438 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */ 1439 ((struct user*)users->data)->flags = atoi(pair->value); 1440 break; 1441 case 60: /* SMS -> 1 MOBILE USER */ 1399 1442 /* sometimes going offline makes this 2, but invisible never sends it */ 1400 u->mobile = atoi(pair->value);1443 ((struct user*)users->data)->mobile = atoi(pair->value); 1401 1444 break; 1402 1445 case 138: 1403 u->f138 = atoi(pair->value);1446 ((struct user*)users->data)->f138 = atoi(pair->value); 1404 1447 break; 1405 1448 case 184: 1406 u->f184 = pair->value;1449 ((struct user*)users->data)->f184 = pair->value; 1407 1450 break; 1408 1451 case 192: 1409 u->f192 = atoi(pair->value);1452 ((struct user*)users->data)->f192 = atoi(pair->value); 1410 1453 break; 1411 1454 case 10001: 1412 u->f10001 = atoi(pair->value);1455 ((struct user*)users->data)->f10001 = atoi(pair->value); 1413 1456 break; 1414 1457 case 10002: 1415 u->f10002 = atoi(pair->value);1458 ((struct user*)users->data)->f10002 = atoi(pair->value); 1416 1459 break; 1417 1460 case 198: 1418 u->f198 = atoi(pair->value);1461 ((struct user*)users->data)->f198 = atoi(pair->value); 1419 1462 break; 1420 1463 case 197: 1421 u->f197 = pair->value;1464 ((struct user*)users->data)->f197 = pair->value; 1422 1465 break; 1423 1466 case 205: 1424 u->f205 = pair->value;1467 ((struct user*)users->data)->f205 = pair->value; 1425 1468 break; 1426 1469 case 213: 1427 u->f213 = atoi(pair->value); 1428 break; 1429 case 16: /* Custom error message */ 1430 YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, 1431 pair->value, 0, E_CUSTOM); 1470 ((struct user*)users->data)->f213 = atoi(pair->value); 1471 break; 1472 case 16: /* Custom error message */ 1473 YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, pair->value, 0, E_CUSTOM); 1432 1474 break; 1433 1475 default: 1434 WARNING(("unknown status key %d:%s", pair->key, 1435 pair->value)); 1436 break; 1437 } 1438 } 1439 1476 WARNING(("unknown status key %d:%s", pair->key, pair->value)); 1477 break; 1478 } 1479 } 1480 1440 1481 while (users) { 1441 1482 YList *t = users; 1442 struct yahoo_process_status_entry*u = users->data;1483 struct user *u = users->data; 1443 1484 1444 1485 if (u->name != NULL) { 1445 if (pkt->service == 1446 YAHOO_SERVICE_LOGOFF 1447 /*|| u->flags == 0 No flags for YMSG16 */ ) { 1448 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> 1449 client_id, u->name, 1450 YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0); 1486 if (pkt->service == YAHOO_SERVICE_LOGOFF) { /* || u->flags == 0) { Not in YMSG16 */ 1487 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0); 1451 1488 } else { 1452 1489 /* Key 47 always seems to be 1 for YMSG16 */ 1453 if 1490 if(!u->state) 1454 1491 u->away = 0; 1455 1492 else 1456 1493 u->away = 1; 1457 1494 1458 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> 1459 client_id, u->name, u->state, u->msg, 1460 u->away, u->idle, u->mobile); 1495 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, u->state, u->msg, u->away, u->idle, u->mobile); 1461 1496 } 1462 1497 } … … 1468 1503 } 1469 1504 1470 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, 1471 struct yahoo_packet *pkt) 1505 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1472 1506 { 1473 1507 struct yahoo_data *yd = yid->yd; … … 1481 1515 struct yahoo_pair *pair = l->data; 1482 1516 1483 switch 1517 switch(pair->key) { 1484 1518 case 300: 1485 1519 case 301: 1486 1520 case 302: 1487 break; /* Separators. Our logic does not need them */1488 1521 case 303: 1489 if ( 318 == atoi(pair->value))1522 if ( 315 == atoi(pair->value) ) 1490 1523 last_packet = 1; 1491 1524 break; 1492 1525 case 65: 1526 g_free(cur_group); 1493 1527 cur_group = strdup(pair->value); 1494 1528 break; … … 1496 1530 newbud = y_new0(struct yahoo_buddy, 1); 1497 1531 newbud->id = strdup(pair->value); 1498 if 1532 if(cur_group) 1499 1533 newbud->group = strdup(cur_group); 1500 else if (yd->buddies) { 1501 struct yahoo_buddy *lastbud = 1502 (struct yahoo_buddy *)y_list_nth(yd-> 1503 buddies, 1504 y_list_length(yd->buddies) - 1)->data; 1534 else { 1535 struct yahoo_buddy *lastbud = (struct yahoo_buddy *)y_list_nth( 1536 yd->buddies, y_list_length(yd->buddies)-1)->data; 1505 1537 newbud->group = strdup(lastbud->group); 1506 } else 1507 newbud->group = strdup("Buddies"); 1538 } 1508 1539 1509 1540 yd->buddies = y_list_append(yd->buddies, newbud); … … 1512 1543 } 1513 1544 } 1545 1546 g_free(cur_group); 1514 1547 1515 1548 /* we could be getting multiple packets here */ 1516 if ( pkt->hash && !last_packet)1517 return; 1518 1519 YAHOO_CALLBACK(ext_yahoo_got_buddies) 1520 1521 /* Logged in */1549 if (last_packet) 1550 return; 1551 1552 YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies); 1553 1554 /*** We login at the very end of the packet communication */ 1522 1555 if (!yd->logged_in) { 1523 yd->logged_in = 1;1524 if 1556 yd->logged_in = TRUE; 1557 if(yd->current_status < 0) 1525 1558 yd->current_status = yd->initial_status; 1526 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 1527 YAHOO_LOGIN_OK, NULL); 1528 1529 /* 1530 yahoo_set_away(yd->client_id, yd->initial_status, NULL, 1531 (yd->initial_status == YAHOO_STATUS_AVAILABLE) ? 0 : 1); 1532 1533 yahoo_get_yab(yd->client_id); 1534 */ 1535 } 1536 1537 } 1538 1539 static void yahoo_process_list(struct yahoo_input_data *yid, 1540 struct yahoo_packet *pkt) 1559 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL); 1560 } 1561 } 1562 1563 static void yahoo_process_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1541 1564 { 1542 1565 struct yahoo_data *yd = yid->yd; 1543 1566 YList *l; 1544 1567 1545 /* we could be getting multiple packets here */ 1568 if (!yd->logged_in) { 1569 yd->logged_in = TRUE; 1570 if(yd->current_status < 0) 1571 yd->current_status = yd->initial_status; 1572 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL); 1573 } 1574 1546 1575 for (l = pkt->hash; l; l = l->next) { 1547 1576 struct yahoo_pair *pair = l->data; 1548 1577 1549 switch (pair->key) { 1550 case 89: /* identities */ 1578 switch(pair->key) { 1579 case 87: /* buddies */ 1580 if(!yd->rawbuddylist) 1581 yd->rawbuddylist = strdup(pair->value); 1582 else { 1583 yd->rawbuddylist = y_string_append(yd->rawbuddylist, pair->value); 1584 } 1585 break; 1586 1587 case 88: /* ignore list */ 1588 if(!yd->ignorelist) 1589 yd->ignorelist = strdup("Ignore:"); 1590 yd->ignorelist = y_string_append(yd->ignorelist, pair->value); 1591 break; 1592 1593 case 89: /* identities */ 1551 1594 { 1552 char **identities = 1553 y_strsplit(pair->value, ",", -1); 1554 int i; 1555 for (i = 0; identities[i]; i++) 1556 yd->identities = 1557 y_list_append(yd->identities, 1595 char **identities = y_strsplit(pair->value, ",", -1); 1596 int i; 1597 for(i=0; identities[i]; i++) 1598 yd->identities = y_list_append(yd->identities, 1558 1599 strdup(identities[i])); 1559 1600 y_strfreev(identities); 1560 1601 } 1561 YAHOO_CALLBACK(ext_yahoo_got_identities) (yd->client_id, 1562 yd->identities); 1563 break; 1564 case 59: /* cookies */ 1565 if (pair->value[0] == 'Y') { 1602 YAHOO_CALLBACK(ext_yahoo_got_identities)(yd->client_id, yd->identities); 1603 break; 1604 case 59: /* cookies */ 1605 if(yd->ignorelist) { 1606 yd->ignore = bud_str2list(yd->ignorelist); 1607 FREE(yd->ignorelist); 1608 YAHOO_CALLBACK(ext_yahoo_got_ignore)(yd->client_id, yd->ignore); 1609 } 1610 if(yd->rawbuddylist) { 1611 yd->buddies = bud_str2list(yd->rawbuddylist); 1612 FREE(yd->rawbuddylist); 1613 YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies); 1614 } 1615 1616 if(pair->value[0]=='Y') { 1566 1617 FREE(yd->cookie_y); 1567 1618 FREE(yd->login_cookie); … … 1570 1621 yd->login_cookie = getlcookie(yd->cookie_y); 1571 1622 1572 } else if (pair->value[0] =='T') {1623 } else if(pair->value[0]=='T') { 1573 1624 FREE(yd->cookie_t); 1574 1625 yd->cookie_t = getcookie(pair->value); 1575 1626 1576 } else if (pair->value[0] =='C') {1627 } else if(pair->value[0]=='C') { 1577 1628 FREE(yd->cookie_c); 1578 1629 yd->cookie_c = getcookie(pair->value); 1579 } 1580 1581 break;1582 case 3: /* my id */1583 case 90: /* 1 */ 1584 case 100: /* 0 */1585 case 101: /* NULL*/1586 case 102: /* NULL*/1587 case 93: /* 86400/1440 */1588 break;1589 }1590 }1591 1592 if (yd->cookie_y && yd->cookie_t) /* We don't get cookie_c anymore */1593 YAHOO_CALLBACK(ext_yahoo_got_cookies) (yd->client_id);1630 } 1631 1632 if(yd->cookie_y && yd->cookie_t) 1633 YAHOO_CALLBACK(ext_yahoo_got_cookies)(yd->client_id); 1634 1635 break; 1636 case 3: /* my id */ 1637 case 90: /* 1 */ 1638 case 100: /* 0 */ 1639 case 101: /* NULL */ 1640 case 102: /* NULL */ 1641 case 93: /* 86400/1440 */ 1642 break; 1643 } 1644 } 1594 1645 } 1595 1646 … … 2342 2393 { 2343 2394 struct yahoo_https_auth_data *had = req->data; 2344 struct yahoo_input_data *yid ;2345 struct yahoo_data *yd ;2395 struct yahoo_input_data *yid = had->yid; 2396 struct yahoo_data *yd = yid->yd; 2346 2397 int st; 2347 2348 if (y_list_find(inputs, had->yid) == NULL)2349 return;2350 2351 yid = had->yid;2352 yd = yid->yd;2353 2398 2354 2399 if (req->status_code != 200) { … … 2391 2436 { 2392 2437 struct yahoo_https_auth_data *had = req->data; 2393 struct yahoo_input_data *yid ;2394 struct yahoo_data *yd ;2438 struct yahoo_input_data *yid = had->yid; 2439 struct yahoo_data *yd = yid->yd; 2395 2440 struct yahoo_packet *pack; 2396 char *crumb = NULL;2441 char *crumb; 2397 2442 int st; 2398 2399 if (y_list_find(inputs, had->yid) == NULL)2400 return;2401 2402 yid = had->yid;2403 yd = yid->yd;2404 2443 2405 2444 md5_byte_t result[16]; … … 4041 4080 4042 4081 yd = yid->yd; 4082 4043 4083 old_status = yd->current_status; 4044 yd->current_status = state; 4084 4085 if (msg && strncmp(msg,"Invisible",9)) { 4086 yd->current_status = YAHOO_STATUS_CUSTOM; 4087 } else { 4088 yd->current_status = state; 4089 } 4045 4090 4046 4091 /* Thank you libpurple :) */ … … 4057 4102 snprintf(s, sizeof(s), "%d", yd->current_status); 4058 4103 yahoo_packet_hash(pkt, 10, s); 4059 yahoo_packet_hash(pkt, 19, msg && state == YAHOO_STATUS_CUSTOM ? msg : ""); 4104 4105 if (yd->current_status == YAHOO_STATUS_CUSTOM) { 4106 yahoo_packet_hash(pkt, 19, msg); 4107 } else { 4108 yahoo_packet_hash(pkt, 19, ""); 4109 } 4110 4060 4111 yahoo_packet_hash(pkt, 47, (away == 2)? "2": (away) ?"1":"0"); 4112 4061 4113 yahoo_send_packet(yid, pkt, 0); 4062 4114 yahoo_packet_free(pkt);
Note: See TracChangeset
for help on using the changeset viewer.