Changes in protocols/yahoo/libyahoo2.c [1be0d26:be915f5]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/yahoo/libyahoo2.c
r1be0d26 rbe915f5 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 users = y_list_prepend(users, u); 1347 u = yd->half_user = NULL; 1348 } 1349 break; 1350 case 0: /* we won't actually do anything with this */ 1412 case 8: /* how many online buddies we have */ 1351 1413 NOTICE(("key %d:%s", pair->key, pair->value)); 1352 1414 break; 1353 case 1: /* we don't get the full buddy list here. */ 1354 if (!yd->logged_in) { 1355 yd->logged_in = 1; 1356 if (yd->current_status < 0) 1357 yd->current_status = yd->initial_status; 1358 YAHOO_CALLBACK(ext_yahoo_login_response) (yd-> 1359 client_id, YAHOO_LOGIN_OK, NULL); 1360 } 1361 break; 1362 case 8: /* how many online buddies we have */ 1363 NOTICE(("key %d:%s", pair->key, pair->value)); 1364 break; 1365 case 7: /* the current buddy */ 1366 if (!u) { 1367 /* This will only happen in case of a single level message */ 1368 u = y_new0(struct yahoo_process_status_entry, 1); 1369 users = y_list_prepend(users, u); 1370 } 1415 case 7: /* the current buddy */ 1416 u = y_new0(struct user, 1); 1371 1417 u->name = pair->value; 1372 break; 1373 case 10: /* state */ 1374 u->state = strtol(pair->value, NULL, 10); 1375 break; 1376 case 19: /* custom status message */ 1377 u->msg = pair->value; 1378 break; 1379 case 47: /* is it an away message or not. Not applicable for YMSG16 anymore */ 1380 u->away = atoi(pair->value); 1381 break; 1382 case 137: /* seconds idle */ 1383 u->idle = atoi(pair->value); 1384 break; 1385 case 11: /* this is the buddy's session id */ 1386 u->buddy_session = atoi(pair->value); 1387 break; 1388 case 17: /* in chat? */ 1389 u->f17 = atoi(pair->value); 1390 break; 1391 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */ 1392 u->flags = atoi(pair->value); 1393 break; 1394 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 */ 1395 1442 /* sometimes going offline makes this 2, but invisible never sends it */ 1396 u->mobile = atoi(pair->value);1443 ((struct user*)users->data)->mobile = atoi(pair->value); 1397 1444 break; 1398 1445 case 138: 1399 u->f138 = atoi(pair->value);1446 ((struct user*)users->data)->f138 = atoi(pair->value); 1400 1447 break; 1401 1448 case 184: 1402 u->f184 = pair->value;1449 ((struct user*)users->data)->f184 = pair->value; 1403 1450 break; 1404 1451 case 192: 1405 u->f192 = atoi(pair->value);1452 ((struct user*)users->data)->f192 = atoi(pair->value); 1406 1453 break; 1407 1454 case 10001: 1408 u->f10001 = atoi(pair->value);1455 ((struct user*)users->data)->f10001 = atoi(pair->value); 1409 1456 break; 1410 1457 case 10002: 1411 u->f10002 = atoi(pair->value);1458 ((struct user*)users->data)->f10002 = atoi(pair->value); 1412 1459 break; 1413 1460 case 198: 1414 u->f198 = atoi(pair->value);1461 ((struct user*)users->data)->f198 = atoi(pair->value); 1415 1462 break; 1416 1463 case 197: 1417 u->f197 = pair->value;1464 ((struct user*)users->data)->f197 = pair->value; 1418 1465 break; 1419 1466 case 205: 1420 u->f205 = pair->value;1467 ((struct user*)users->data)->f205 = pair->value; 1421 1468 break; 1422 1469 case 213: 1423 u->f213 = atoi(pair->value); 1424 break; 1425 case 16: /* Custom error message */ 1426 YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, 1427 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); 1428 1474 break; 1429 1475 default: 1430 WARNING(("unknown status key %d:%s", pair->key, 1431 pair->value)); 1432 break; 1433 } 1434 } 1435 1476 WARNING(("unknown status key %d:%s", pair->key, pair->value)); 1477 break; 1478 } 1479 } 1480 1436 1481 while (users) { 1437 1482 YList *t = users; 1438 struct yahoo_process_status_entry*u = users->data;1483 struct user *u = users->data; 1439 1484 1440 1485 if (u->name != NULL) { 1441 if (pkt->service == 1442 YAHOO_SERVICE_LOGOFF 1443 /*|| u->flags == 0 No flags for YMSG16 */ ) { 1444 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> 1445 client_id, u->name, 1446 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); 1447 1488 } else { 1448 1489 /* Key 47 always seems to be 1 for YMSG16 */ 1449 if 1490 if(!u->state) 1450 1491 u->away = 0; 1451 1492 else 1452 1493 u->away = 1; 1453 1494 1454 YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> 1455 client_id, u->name, u->state, u->msg, 1456 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); 1457 1496 } 1458 1497 } … … 1464 1503 } 1465 1504 1466 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, 1467 struct yahoo_packet *pkt) 1505 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1468 1506 { 1469 1507 struct yahoo_data *yd = yid->yd; … … 1477 1515 struct yahoo_pair *pair = l->data; 1478 1516 1479 switch 1517 switch(pair->key) { 1480 1518 case 300: 1481 1519 case 301: 1482 1520 case 302: 1483 break; /* Separators. Our logic does not need them */1484 1521 case 303: 1485 if ( 318 == atoi(pair->value))1522 if ( 315 == atoi(pair->value) ) 1486 1523 last_packet = 1; 1487 1524 break; 1488 1525 case 65: 1526 g_free(cur_group); 1489 1527 cur_group = strdup(pair->value); 1490 1528 break; … … 1492 1530 newbud = y_new0(struct yahoo_buddy, 1); 1493 1531 newbud->id = strdup(pair->value); 1494 if (cur_group) 1532 if (cur_group) { 1495 1533 newbud->group = strdup(cur_group); 1496 else if (yd->buddies) { 1497 struct yahoo_buddy *lastbud = 1498 (struct yahoo_buddy *)y_list_nth(yd-> 1499 buddies, 1500 y_list_length(yd->buddies) - 1)->data; 1501 newbud->group = strdup(lastbud->group); 1502 } else 1503 newbud->group = strdup("Buddies"); 1534 } else { 1535 YList *last; 1536 struct yahoo_buddy *lastbud; 1537 1538 for (last = yd->buddies; last && last->next; last = last->next); 1539 if (last) { 1540 lastbud = last->data; 1541 newbud->group = strdup(lastbud->group); 1542 } else { 1543 newbud->group = strdup("Buddies"); 1544 } 1545 } 1504 1546 1505 1547 yd->buddies = y_list_append(yd->buddies, newbud); … … 1508 1550 } 1509 1551 } 1552 1553 g_free(cur_group); 1510 1554 1511 1555 /* we could be getting multiple packets here */ 1512 if ( pkt->hash && !last_packet)1513 return; 1514 1515 YAHOO_CALLBACK(ext_yahoo_got_buddies) 1516 1517 /* Logged in */1556 if (last_packet) 1557 return; 1558 1559 YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies); 1560 1561 /*** We login at the very end of the packet communication */ 1518 1562 if (!yd->logged_in) { 1519 yd->logged_in = 1;1520 if 1563 yd->logged_in = TRUE; 1564 if(yd->current_status < 0) 1521 1565 yd->current_status = yd->initial_status; 1522 YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 1523 YAHOO_LOGIN_OK, NULL); 1524 1525 /* 1526 yahoo_set_away(yd->client_id, yd->initial_status, NULL, 1527 (yd->initial_status == YAHOO_STATUS_AVAILABLE) ? 0 : 1); 1528 1529 yahoo_get_yab(yd->client_id); 1530 */ 1531 } 1532 1533 } 1534 1535 static void yahoo_process_list(struct yahoo_input_data *yid, 1536 struct yahoo_packet *pkt) 1566 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL); 1567 } 1568 } 1569 1570 static void yahoo_process_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt) 1537 1571 { 1538 1572 struct yahoo_data *yd = yid->yd; 1539 1573 YList *l; 1540 1574 1541 /* we could be getting multiple packets here */ 1575 if (!yd->logged_in) { 1576 yd->logged_in = TRUE; 1577 if(yd->current_status < 0) 1578 yd->current_status = yd->initial_status; 1579 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL); 1580 } 1581 1542 1582 for (l = pkt->hash; l; l = l->next) { 1543 1583 struct yahoo_pair *pair = l->data; 1544 1584 1545 switch (pair->key) { 1546 case 89: /* identities */ 1585 switch(pair->key) { 1586 case 87: /* buddies */ 1587 if(!yd->rawbuddylist) 1588 yd->rawbuddylist = strdup(pair->value); 1589 else { 1590 yd->rawbuddylist = y_string_append(yd->rawbuddylist, pair->value); 1591 } 1592 break; 1593 1594 case 88: /* ignore list */ 1595 if(!yd->ignorelist) 1596 yd->ignorelist = strdup("Ignore:"); 1597 yd->ignorelist = y_string_append(yd->ignorelist, pair->value); 1598 break; 1599 1600 case 89: /* identities */ 1547 1601 { 1548 char **identities = 1549 y_strsplit(pair->value, ",", -1); 1550 int i; 1551 for (i = 0; identities[i]; i++) 1552 yd->identities = 1553 y_list_append(yd->identities, 1602 char **identities = y_strsplit(pair->value, ",", -1); 1603 int i; 1604 for(i=0; identities[i]; i++) 1605 yd->identities = y_list_append(yd->identities, 1554 1606 strdup(identities[i])); 1555 1607 y_strfreev(identities); 1556 1608 } 1557 YAHOO_CALLBACK(ext_yahoo_got_identities) (yd->client_id, 1558 yd->identities); 1559 break; 1560 case 59: /* cookies */ 1561 if (pair->value[0] == 'Y') { 1609 YAHOO_CALLBACK(ext_yahoo_got_identities)(yd->client_id, yd->identities); 1610 break; 1611 case 59: /* cookies */ 1612 if(yd->ignorelist) { 1613 yd->ignore = bud_str2list(yd->ignorelist); 1614 FREE(yd->ignorelist); 1615 YAHOO_CALLBACK(ext_yahoo_got_ignore)(yd->client_id, yd->ignore); 1616 } 1617 if(yd->rawbuddylist) { 1618 yd->buddies = bud_str2list(yd->rawbuddylist); 1619 FREE(yd->rawbuddylist); 1620 YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies); 1621 } 1622 1623 if(pair->value[0]=='Y') { 1562 1624 FREE(yd->cookie_y); 1563 1625 FREE(yd->login_cookie); … … 1566 1628 yd->login_cookie = getlcookie(yd->cookie_y); 1567 1629 1568 } else if (pair->value[0] =='T') {1630 } else if(pair->value[0]=='T') { 1569 1631 FREE(yd->cookie_t); 1570 1632 yd->cookie_t = getcookie(pair->value); 1571 1633 1572 } else if (pair->value[0] =='C') {1634 } else if(pair->value[0]=='C') { 1573 1635 FREE(yd->cookie_c); 1574 1636 yd->cookie_c = getcookie(pair->value); 1575 } 1576 1577 break;1578 case 3: /* my id */1579 case 90: /* 1 */ 1580 case 100: /* 0 */1581 case 101: /* NULL*/1582 case 102: /* NULL*/1583 case 93: /* 86400/1440 */1584 break;1585 }1586 }1587 1588 if (yd->cookie_y && yd->cookie_t) /* We don't get cookie_c anymore */1589 YAHOO_CALLBACK(ext_yahoo_got_cookies) (yd->client_id);1637 } 1638 1639 if(yd->cookie_y && yd->cookie_t) 1640 YAHOO_CALLBACK(ext_yahoo_got_cookies)(yd->client_id); 1641 1642 break; 1643 case 3: /* my id */ 1644 case 90: /* 1 */ 1645 case 100: /* 0 */ 1646 case 101: /* NULL */ 1647 case 102: /* NULL */ 1648 case 93: /* 86400/1440 */ 1649 break; 1650 } 1651 } 1590 1652 } 1591 1653
Note: See TracChangeset
for help on using the changeset viewer.