Changeset 547c94c


Ignore:
Timestamp:
2010-03-12T22:32:55Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7053379
Parents:
8b6b740
Message:

Merging in some code from libyahoo2-trunk that deals better with (initial)
status updates and cleans up some stale stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/yahoo/libyahoo2.c

    r8b6b740 r547c94c  
    855855}
    856856
    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 
    906857static char * getcookie(char *rawcookie)
    907858{
     
    13601311}
    13611312
    1362 
    1363 static void yahoo_process_status(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1313static void yahoo_process_status(struct yahoo_input_data *yid,
     1314        struct yahoo_packet *pkt)
    13641315{
    13651316        YList *l;
    13661317        struct yahoo_data *yd = yid->yd;
    13671318
    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 */
     1319        struct user {
     1320                char *name;     /* 7      name */
     1321                int state;      /* 10     state */
     1322                int flags;      /* 13     flags, bit 0 = pager, bit 1 = chat, bit 2 = game */
     1323                int mobile;     /* 60     mobile */
     1324                char *msg;      /* 19     custom status message */
     1325                int away;       /* 47     away (or invisible) */
     1326                int buddy_session; /* 11  state */
     1327                int f17;        /* 17     in chat? then what about flags? */
     1328                int idle;       /* 137    seconds idle */
     1329                int f138;       /* 138    state */
     1330                char *f184;     /* 184    state */
     1331                int f192;       /* 192    state */
     1332                int f10001;     /* 10001  state */
     1333                int f10002;     /* 10002  state */
     1334                int f198;       /* 198    state */
     1335                char *f197;     /* 197    state */
     1336                char *f205;     /* 205    state */
     1337                int f213;       /* 213    state */
    13881338        } *u;
    13891339
    13901340        YList *users = 0;
    1391        
     1341
    13921342        if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
    1393                 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_DUPL, NULL);
    1394                 return;
    1395         }
     1343                YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id,
     1344                        YAHOO_LOGIN_DUPL, NULL);
     1345                return;
     1346        }
     1347
     1348        u = NULL;
    13961349
    13971350        for (l = pkt->hash; l; l = l->next) {
     
    13991352
    14001353                switch (pair->key) {
    1401                 case 0: /* we won't actually do anything with this */
     1354                case 300:       /* Begin buddy */
     1355                        if (!strcmp(pair->value, "315") && !u) {
     1356                                u = y_new0(struct user, 1);
     1357                        }
     1358                        break;
     1359                case 301:       /* End buddy */
     1360                        if (!strcmp(pair->value, "315") && u) {
     1361                                users = y_list_prepend(users, u);
     1362                                u = NULL;
     1363                        }
     1364                        break;
     1365                case 0: /* we won't actually do anything with this */
    14021366                        NOTICE(("key %d:%s", pair->key, pair->value));
    14031367                        break;
    1404                 case 1: /* we don't get the full buddy list here. */
     1368                case 1: /* we don't get the full buddy list here. */
    14051369                        if (!yd->logged_in) {
    1406                                 yd->logged_in = TRUE;
    1407                                 if(yd->current_status < 0)
     1370                                yd->logged_in = 1;
     1371                                if (yd->current_status < 0)
    14081372                                        yd->current_status = yd->initial_status;
    1409                                 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL);
     1373                                YAHOO_CALLBACK(ext_yahoo_login_response) (yd->
     1374                                        client_id, YAHOO_LOGIN_OK, NULL);
    14101375                        }
    14111376                        break;
    1412                 case 8: /* how many online buddies we have */
     1377                case 8: /* how many online buddies we have */
    14131378                        NOTICE(("key %d:%s", pair->key, pair->value));
    14141379                        break;
    1415                 case 7: /* the current buddy */
    1416                         u = y_new0(struct user, 1);
     1380                case 7: /* the current buddy */
     1381                        if (!u) {
     1382                                /* This will only happen in case of a single level message */
     1383                                u = y_new0(struct user, 1);
     1384                                users = y_list_prepend(users, u);
     1385                        }
    14171386                        u->name = pair->value;
    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 */
     1387                        break;
     1388                case 10:        /* state */
     1389                        u->state = strtol(pair->value, NULL, 10);
     1390                        break;
     1391                case 19:        /* custom status message */
     1392                        u->msg = pair->value;
     1393                        break;
     1394                case 47:        /* is it an away message or not. Not applicable for YMSG16 anymore */
     1395                        u->away = atoi(pair->value);
     1396                        break;
     1397                case 137:       /* seconds idle */
     1398                        u->idle = atoi(pair->value);
     1399                        break;
     1400                case 11:        /* this is the buddy's session id */
     1401                        u->buddy_session = atoi(pair->value);
     1402                        break;
     1403                case 17:        /* in chat? */
     1404                        u->f17 = atoi(pair->value);
     1405                        break;
     1406                case 13:        /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */
     1407                        u->flags = atoi(pair->value);
     1408                        break;
     1409                case 60:        /* SMS -> 1 MOBILE USER */
    14421410                        /* sometimes going offline makes this 2, but invisible never sends it */
    1443                         ((struct user*)users->data)->mobile = atoi(pair->value);
     1411                        u->mobile = atoi(pair->value);
    14441412                        break;
    14451413                case 138:
    1446                         ((struct user*)users->data)->f138 = atoi(pair->value);
     1414                        u->f138 = atoi(pair->value);
    14471415                        break;
    14481416                case 184:
    1449                         ((struct user*)users->data)->f184 = pair->value;
     1417                        u->f184 = pair->value;
    14501418                        break;
    14511419                case 192:
    1452                         ((struct user*)users->data)->f192 = atoi(pair->value);
     1420                        u->f192 = atoi(pair->value);
    14531421                        break;
    14541422                case 10001:
    1455                         ((struct user*)users->data)->f10001 = atoi(pair->value);
     1423                        u->f10001 = atoi(pair->value);
    14561424                        break;
    14571425                case 10002:
    1458                         ((struct user*)users->data)->f10002 = atoi(pair->value);
     1426                        u->f10002 = atoi(pair->value);
    14591427                        break;
    14601428                case 198:
    1461                         ((struct user*)users->data)->f198 = atoi(pair->value);
     1429                        u->f198 = atoi(pair->value);
    14621430                        break;
    14631431                case 197:
    1464                         ((struct user*)users->data)->f197 = pair->value;
     1432                        u->f197 = pair->value;
    14651433                        break;
    14661434                case 205:
    1467                         ((struct user*)users->data)->f205 = pair->value;
     1435                        u->f205 = pair->value;
    14681436                        break;
    14691437                case 213:
    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);
     1438                        u->f213 = atoi(pair->value);
     1439                        break;
     1440                case 16:        /* Custom error message */
     1441                        YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id,
     1442                                pair->value, 0, E_CUSTOM);
    14741443                        break;
    14751444                default:
    1476                         WARNING(("unknown status key %d:%s", pair->key, pair->value));
    1477                         break;
    1478                 }
    1479         }
    1480        
     1445                        WARNING(("unknown status key %d:%s", pair->key,
     1446                                        pair->value));
     1447                        break;
     1448                }
     1449        }
     1450
    14811451        while (users) {
    14821452                YList *t = users;
     
    14841454
    14851455                if (u->name != NULL) {
    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);
     1456                        if (pkt->service ==
     1457                                YAHOO_SERVICE_LOGOFF
     1458                                /*|| u->flags == 0 No flags for YMSG16 */ ) {
     1459                                YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->
     1460                                        client_id, u->name,
     1461                                        YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0);
    14881462                        } else {
    14891463                                /* Key 47 always seems to be 1 for YMSG16 */
    1490                                 if(!u->state)
     1464                                if (!u->state)
    14911465                                        u->away = 0;
    14921466                                else
    14931467                                        u->away = 1;
    14941468
    1495                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, u->state, u->msg, u->away, u->idle, u->mobile);
     1469                                YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->
     1470                                        client_id, u->name, u->state, u->msg,
     1471                                        u->away, u->idle, u->mobile);
    14961472                        }
    14971473                }
     
    15031479}
    15041480
    1505 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1481static void yahoo_process_buddy_list(struct yahoo_input_data *yid,
     1482        struct yahoo_packet *pkt)
    15061483{
    15071484        struct yahoo_data *yd = yid->yd;
     
    15151492                struct yahoo_pair *pair = l->data;
    15161493
    1517                 switch(pair->key) {
     1494                switch (pair->key) {
    15181495                case 300:
    15191496                case 301:
    15201497                case 302:
     1498                        break;  /* Separators. Our logic does not need them */
    15211499                case 303:
    1522                         if ( 315 == atoi(pair->value) )
     1500                        if (318 == atoi(pair->value))
    15231501                                last_packet = 1;
    15241502                        break;
    15251503                case 65:
    1526                         g_free(cur_group);
    15271504                        cur_group = strdup(pair->value);
    15281505                        break;
     
    15301507                        newbud = y_new0(struct yahoo_buddy, 1);
    15311508                        newbud->id = strdup(pair->value);
    1532                         if (cur_group) {
     1509                        if (cur_group)
    15331510                                newbud->group = strdup(cur_group);
    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                                 }
     1511                        else {
     1512                                struct yahoo_buddy *lastbud =
     1513                                        (struct yahoo_buddy *)y_list_nth(yd->
     1514                                        buddies,
     1515                                        y_list_length(yd->buddies) - 1)->data;
     1516                                newbud->group = strdup(lastbud->group);
    15451517                        }
    15461518
     
    15501522                }
    15511523        }
    1552        
    1553         g_free(cur_group);
    15541524
    15551525        /* we could be getting multiple packets here */
    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 */
     1526        if (pkt->hash && !last_packet)
     1527                return;
     1528
     1529        YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, yd->buddies);
     1530
     1531        /* Logged in */
    15621532        if (!yd->logged_in) {
    1563                 yd->logged_in = TRUE;
    1564                 if(yd->current_status < 0)
     1533                yd->logged_in = 1;
     1534                if (yd->current_status < 0)
    15651535                        yd->current_status = yd->initial_status;
    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)
     1536                YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id,
     1537                        YAHOO_LOGIN_OK, NULL);
     1538
     1539                /*
     1540                yahoo_set_away(yd->client_id, yd->initial_status, NULL,
     1541                        (yd->initial_status == YAHOO_STATUS_AVAILABLE) ? 0 : 1);
     1542
     1543                yahoo_get_yab(yd->client_id);
     1544                */
     1545        }
     1546
     1547}
     1548
     1549static void yahoo_process_list(struct yahoo_input_data *yid,
     1550        struct yahoo_packet *pkt)
    15711551{
    15721552        struct yahoo_data *yd = yid->yd;
    15731553        YList *l;
    15741554
    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 
     1555        /* we could be getting multiple packets here */
    15821556        for (l = pkt->hash; l; l = l->next) {
    15831557                struct yahoo_pair *pair = l->data;
    15841558
    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);
     1559                switch (pair->key) {
     1560                case 89:        /* identities */
     1561                        {
     1562                                char **identities =
     1563                                        y_strsplit(pair->value, ",", -1);
     1564                                int i;
     1565                                for (i = 0; identities[i]; i++)
     1566                                        yd->identities =
     1567                                                y_list_append(yd->identities,
     1568                                                strdup(identities[i]));
     1569                                y_strfreev(identities);
    15911570                        }
    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 */
    1601                         {
    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,
    1606                                                 strdup(identities[i]));
    1607                         y_strfreev(identities);
    1608                         }
    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') {
     1571                        YAHOO_CALLBACK(ext_yahoo_got_identities) (yd->client_id,
     1572                                yd->identities);
     1573                        break;
     1574                case 59:        /* cookies */
     1575                        if (pair->value[0] == 'Y') {
    16241576                                FREE(yd->cookie_y);
    16251577                                FREE(yd->login_cookie);
     
    16281580                                yd->login_cookie = getlcookie(yd->cookie_y);
    16291581
    1630                         } else if(pair->value[0]=='T') {
     1582                        } else if (pair->value[0] == 'T') {
    16311583                                FREE(yd->cookie_t);
    16321584                                yd->cookie_t = getcookie(pair->value);
    16331585
    1634                         } else if(pair->value[0]=='C') {
     1586                        } else if (pair->value[0] == 'C') {
    16351587                                FREE(yd->cookie_c);
    16361588                                yd->cookie_c = getcookie(pair->value);
    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         }
     1589                        }
     1590
     1591                        break;
     1592                case 3: /* my id */
     1593                case 90:        /* 1 */
     1594                case 100:       /* 0 */
     1595                case 101:       /* NULL */
     1596                case 102:       /* NULL */
     1597                case 93:        /* 86400/1440 */
     1598                        break;
     1599                }
     1600        }
     1601
     1602        if (yd->cookie_y && yd->cookie_t)       /* We don't get cookie_c anymore */
     1603                YAHOO_CALLBACK(ext_yahoo_got_cookies) (yd->client_id);
    16521604}
    16531605
Note: See TracChangeset for help on using the changeset viewer.