Ignore:
Timestamp:
2007-04-16T04:31:52Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
b3cae44
Parents:
6bbb939
Message:

Updating the Yahoo! module. This seems to fix handling of incoming away
states/messages, should fix some issues with group chats, and unfortunately
also adds some crap which I don't want to clean up for now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/yahoo/libyahoo2.c

    r6bbb939 rcfc8d58  
    104104#define YAHOO_CALLBACK(x)       x
    105105#endif
     106
     107static int yahoo_send_data(int fd, void *data, int len);
    106108
    107109int yahoo_log_message(char * fmt, ...)
     
    204206        YAHOO_SERVICE_CHATLOGOUT = 0xa0,
    205207        YAHOO_SERVICE_CHATPING,
    206         YAHOO_SERVICE_COMMENT = 0xa8
     208        YAHOO_SERVICE_COMMENT = 0xa8,
     209        YAHOO_SERVICE_STEALTH = 0xb9,
     210        YAHOO_SERVICE_PICTURE_CHECKSUM = 0xbd,
     211        YAHOO_SERVICE_PICTURE = 0xbe,
     212        YAHOO_SERVICE_PICTURE_UPDATE = 0xc1,
     213        YAHOO_SERVICE_PICTURE_UPLOAD = 0xc2
    207214};
    208215
     
    741748        yahoo_packet_dump(data, len);
    742749       
     750        if( yid->type == YAHOO_CONNECTION_FT )
     751                yahoo_send_data(yid->fd, data, len);
     752        else
    743753        yahoo_add_to_send_queue(yid, data, len);
    744754        FREE(data);
     
    926936        char *msg = NULL;
    927937        char *from = NULL;
     938        char *to = NULL;
    928939        int stat = 0;
    929940        int accept = 0;
     
    934945                if (pair->key == 4)
    935946                        from = pair->value;
     947                if (pair->key == 5)
     948                        to = pair->value;
    936949                if (pair->key == 49)
    937950                        msg = pair->value;
     
    951964       
    952965        if (!strncasecmp(msg, "TYPING", strlen("TYPING")))
    953                 YAHOO_CALLBACK(ext_yahoo_typing_notify)(yd->client_id, from, stat);
     966                YAHOO_CALLBACK(ext_yahoo_typing_notify)(yd->client_id, to, from, stat);
    954967        else if (!strncasecmp(msg, "GAME", strlen("GAME")))
    955                 YAHOO_CALLBACK(ext_yahoo_game_notify)(yd->client_id, from, stat);
     968                YAHOO_CALLBACK(ext_yahoo_game_notify)(yd->client_id, to, from, stat);
    956969        else if (!strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE")))
    957970        {
    958971                if (!strcmp(ind, " ")) {
    959                         YAHOO_CALLBACK(ext_yahoo_webcam_invite)(yd->client_id, from);
     972                        YAHOO_CALLBACK(ext_yahoo_webcam_invite)(yd->client_id, to, from);
    960973                } else {
    961974                        accept = atoi(ind);
     
    963976                        if (accept < 0)
    964977                                accept = 0;
    965                         YAHOO_CALLBACK(ext_yahoo_webcam_invite_reply)(yd->client_id, from, accept);
     978                        YAHOO_CALLBACK(ext_yahoo_webcam_invite_reply)(yd->client_id, to, from, accept);
    966979                }
    967980        }
     
    10221035        }
    10231036        if(url && from)
    1024                 YAHOO_CALLBACK(ext_yahoo_got_file)(yd->client_id, from, url, expires, msg, filename, filesize);
     1037                YAHOO_CALLBACK(ext_yahoo_got_file)(yd->client_id, to, from, url, expires, msg, filename, filesize);
    10251038
    10261039}
     
    10961109                        ;
    10971110                else if(members)
    1098                         YAHOO_CALLBACK(ext_yahoo_got_conf_invite)(yd->client_id, host, room, msg, members);
     1111                        YAHOO_CALLBACK(ext_yahoo_got_conf_invite)(yd->client_id, id, host, room, msg, members);
    10991112                else if(msg)
    1100                         YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, msg, 0);
     1113                        YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, msg, 0, E_CONFNOTAVAIL);
    11011114                break;
    11021115        case YAHOO_SERVICE_CONFADDINVITE:
     
    11041117                        ;
    11051118                else
    1106                         YAHOO_CALLBACK(ext_yahoo_got_conf_invite)(yd->client_id, host, room, msg, members);
     1119                        YAHOO_CALLBACK(ext_yahoo_got_conf_invite)(yd->client_id, id, host, room, msg, members);
    11071120                break;
    11081121        case YAHOO_SERVICE_CONFDECLINE:
    11091122                if(who)
    1110                         YAHOO_CALLBACK(ext_yahoo_conf_userdecline)(yd->client_id, who, room, msg);
     1123                        YAHOO_CALLBACK(ext_yahoo_conf_userdecline)(yd->client_id, id, who, room, msg);
    11111124                break;
    11121125        case YAHOO_SERVICE_CONFLOGON:
    11131126                if(who)
    1114                         YAHOO_CALLBACK(ext_yahoo_conf_userjoin)(yd->client_id, who, room);
     1127                        YAHOO_CALLBACK(ext_yahoo_conf_userjoin)(yd->client_id, id, who, room);
    11151128                break;
    11161129        case YAHOO_SERVICE_CONFLOGOFF:
    11171130                if(who)
    1118                         YAHOO_CALLBACK(ext_yahoo_conf_userleave)(yd->client_id, who, room);
     1131                        YAHOO_CALLBACK(ext_yahoo_conf_userleave)(yd->client_id, id, who, room);
    11191132                break;
    11201133        case YAHOO_SERVICE_CONFMSG:
    11211134                if(who)
    1122                         YAHOO_CALLBACK(ext_yahoo_conf_message)(yd->client_id, who, room, msg, utf8);
     1135                        YAHOO_CALLBACK(ext_yahoo_conf_message)(yd->client_id, id, who, room, msg, utf8);
    11231136                break;
    11241137        }
     
    11281141{
    11291142        char *msg = NULL;
     1143        char *id = NULL;
    11301144        char *who = NULL;
    11311145        char *room = NULL;
     
    11441158                struct yahoo_pair *pair = l->data;
    11451159
     1160                if (pair->key == 1) {
     1161                        /* My identity */
     1162                        id = pair->value;
     1163                }
     1164
    11461165                if (pair->key == 104) {
    11471166                        /* Room name */
     
    12181237        if(!room) {
    12191238                if (pkt->service == YAHOO_SERVICE_CHATLOGOUT) { /* yahoo originated chat logout */
    1220                         YAHOO_CALLBACK(ext_yahoo_chat_yahoologout)(yid->yd->client_id);
     1239                        YAHOO_CALLBACK(ext_yahoo_chat_yahoologout)(yid->yd->client_id, id);
    12211240                        return ;
    12221241                }
    12231242                if (pkt->service == YAHOO_SERVICE_COMMENT && chaterr)  {
    1224                         YAHOO_CALLBACK(ext_yahoo_chat_yahooerror)(yid->yd->client_id);
    1225                         return ;
     1243                        YAHOO_CALLBACK(ext_yahoo_chat_yahooerror)(yid->yd->client_id, id);
     1244                        return;
    12261245                }
    12271246
     
    12361255                }
    12371256                if(firstjoin && members) {
    1238                         YAHOO_CALLBACK(ext_yahoo_chat_join)(yid->yd->client_id, room, topic, members, yid->fd);
     1257                        YAHOO_CALLBACK(ext_yahoo_chat_join)(yid->yd->client_id, id, room, topic, members, yid->fd);
    12391258                } else if(who) {
    12401259                        if(y_list_length(members) != 1) {
     
    12451264                                YList *n = members->next;
    12461265                                currentmember = members->data;
    1247                                 YAHOO_CALLBACK(ext_yahoo_chat_userjoin)(yid->yd->client_id, room, currentmember);
     1266                                YAHOO_CALLBACK(ext_yahoo_chat_userjoin)(yid->yd->client_id, id, room, currentmember);
    12481267                                y_list_free_1(members);
    12491268                                members=n;
     
    12531272        case YAHOO_SERVICE_CHATEXIT:
    12541273                if(who) {
    1255                         YAHOO_CALLBACK(ext_yahoo_chat_userleave)(yid->yd->client_id, room, who);
     1274                        YAHOO_CALLBACK(ext_yahoo_chat_userleave)(yid->yd->client_id, id, room, who);
    12561275                }
    12571276                break;
    12581277        case YAHOO_SERVICE_COMMENT:
    12591278                if(who) {
    1260                         YAHOO_CALLBACK(ext_yahoo_chat_message)(yid->yd->client_id, who, room, msg, msgtype, utf8);
     1279                        YAHOO_CALLBACK(ext_yahoo_chat_message)(yid->yd->client_id, id, who, room, msg, msgtype, utf8);
    12611280                }
    12621281                break;
     
    13171336                        YAHOO_CALLBACK(ext_yahoo_system_message)(yd->client_id, message->msg);
    13181337                } else if (pkt->status <= 2 || pkt->status == 5) {
    1319                         YAHOO_CALLBACK(ext_yahoo_got_im)(yd->client_id, message->from, message->msg, message->tm, pkt->status, message->utf8);
     1338                        YAHOO_CALLBACK(ext_yahoo_got_im)(yd->client_id, message->to, message->from, message->msg, message->tm, pkt->status, message->utf8);
    13201339                } else if (pkt->status == 0xffffffff) {
    1321                         YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, message->msg, 0);
     1340                        YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, message->msg, 0, E_SYSTEM);
    13221341                }
    13231342                free(message);
     
    13321351        YList *l;
    13331352        struct yahoo_data *yd = yid->yd;
    1334         char *name = NULL;
    1335         int state = 0;
    1336         int away = 0;
    1337         int idle = 0;
    1338         char *msg = NULL;
     1353
     1354        struct user
     1355        {
     1356                char *name;     /* 7    name */
     1357                int   state;    /* 10   state */
     1358                int   flags;    /* 13   flags, bit 0 = pager, bit 1 = chat, bit 2 = game */
     1359                int   mobile;   /* 60   mobile */
     1360                char *msg;      /* 19   custom status message */
     1361                int   away;     /* 47   away (or invisible)*/
     1362                int   buddy_session;    /* 11   state */
     1363                int   f17;      /* 17   in chat? then what about flags? */
     1364                int   idle;     /* 137  seconds idle */
     1365                int   f138;     /* 138  state */
     1366                char *f184;     /* 184  state */
     1367                int   f192;     /* 192  state */
     1368                int   f10001;   /* 10001        state */
     1369                int   f10002;   /* 10002        state */
     1370                int   f198;     /* 198  state */
     1371                char *f197;     /* 197  state */
     1372                char *f205;     /* 205  state */
     1373                int   f213;     /* 213  state */
     1374        } *u;
     1375
     1376        YList *users = 0;
    13391377       
    1340         if(pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
     1378        if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
    13411379                YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_DUPL, NULL);
    13421380                return;
     
    13621400                        break;
    13631401                case 7: /* the current buddy */
    1364                         name = pair->value;
     1402                        u = y_new0(struct user, 1);
     1403                        u->name = pair->value;
     1404                        users = y_list_prepend(users, u);
    13651405                        break;
    13661406                case 10: /* state */
    1367                         state = strtol(pair->value, NULL, 10);
     1407                        ((struct user*)users->data)->state = strtol(pair->value, NULL, 10);
    13681408                        break;
    13691409                case 19: /* custom status message */
    1370                         msg = pair->value;
     1410                        ((struct user*)users->data)->msg = pair->value;
    13711411                        break;
    13721412                case 47: /* is it an away message or not */
    1373                         away = atoi(pair->value);
     1413                        ((struct user*)users->data)->away = atoi(pair->value);
    13741414                        break;
    13751415                case 137: /* seconds idle */
    1376                         idle = atoi(pair->value);
    1377                         break;
    1378                 case 11: /* what is this? */
    1379                         NOTICE(("key %d:%s", pair->key, pair->value));
     1416                        ((struct user*)users->data)->idle = atoi(pair->value);
     1417                        break;
     1418                case 11: /* this is the buddy's session id */
     1419                        ((struct user*)users->data)->buddy_session = atoi(pair->value);
    13801420                        break;
    13811421                case 17: /* in chat? */
    1382                         break;
    1383                 case 13: /* in pager? */
    1384                         if (pkt->service == YAHOO_SERVICE_LOGOFF || strtol(pair->value, NULL, 10) == 0) {
    1385                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, name, YAHOO_STATUS_OFFLINE, NULL, 1);
    1386                                 break;
    1387                         }
    1388                         if (state == YAHOO_STATUS_AVAILABLE) {
    1389                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, name, state, NULL, 0);
    1390                         } else if (state == YAHOO_STATUS_CUSTOM) {
    1391                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, name, state, msg, away);
    1392                         } else {
    1393                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, name, state, NULL, idle);
    1394                         }
    1395 
    1396                         break;
    1397                 case 60:
     1422                        ((struct user*)users->data)->f17 = atoi(pair->value);
     1423                        break;
     1424                case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */
     1425                        ((struct user*)users->data)->flags = atoi(pair->value);
     1426                        break;
     1427                case 60: /* SMS -> 1 MOBILE USER */
    13981428                        /* sometimes going offline makes this 2, but invisible never sends it */
    1399                         NOTICE(("key %d:%s", pair->key, pair->value));
    1400                          break;
     1429                        ((struct user*)users->data)->mobile = atoi(pair->value);
     1430                        break;
     1431                case 138:
     1432                        ((struct user*)users->data)->f138 = atoi(pair->value);
     1433                        break;
     1434                case 184:
     1435                        ((struct user*)users->data)->f184 = pair->value;
     1436                        break;
     1437                case 192:
     1438                        ((struct user*)users->data)->f192 = atoi(pair->value);
     1439                        break;
     1440                case 10001:
     1441                        ((struct user*)users->data)->f10001 = atoi(pair->value);
     1442                        break;
     1443                case 10002:
     1444                        ((struct user*)users->data)->f10002 = atoi(pair->value);
     1445                        break;
     1446                case 198:
     1447                        ((struct user*)users->data)->f198 = atoi(pair->value);
     1448                        break;
     1449                case 197:
     1450                        ((struct user*)users->data)->f197 = pair->value;
     1451                        break;
     1452                case 205:
     1453                        ((struct user*)users->data)->f205 = pair->value;
     1454                        break;
     1455                case 213:
     1456                        ((struct user*)users->data)->f213 = atoi(pair->value);
     1457                        break;
    14011458                case 16: /* Custom error message */
    1402                         YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, pair->value, 0);
     1459                        YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, pair->value, 0, E_CUSTOM);
    14031460                        break;
    14041461                default:
     
    14061463                        break;
    14071464                }
     1465        }
     1466       
     1467        while (users) {
     1468                YList *t = users;
     1469                struct user *u = users->data;
     1470
     1471                if (u->name != NULL) {
     1472                        if (pkt->service == YAHOO_SERVICE_LOGOFF || u->flags == 0) {
     1473                                YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0);
     1474                        } else {
     1475                                YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, u->state, u->msg, u->away, u->idle, u->mobile);
     1476                        }
     1477                }
     1478
     1479                users = y_list_remove_link(users, users);
     1480                y_list_free_1(t);
     1481                FREE(u);
    14081482        }
    14091483}
     
    15101584        yahoo_packet_free(pkt);
    15111585
     1586}
     1587
     1588static void yahoo_process_picture_checksum( struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1589{
     1590        struct yahoo_data *yd = yid->yd;
     1591        char *from = NULL;
     1592        char *to = NULL;
     1593        int checksum = 0;
     1594        YList *l;
     1595
     1596        for(l = pkt->hash; l; l = l->next)
     1597        {
     1598                struct yahoo_pair *pair = l->data;
     1599
     1600                switch(pair->key)
     1601                {
     1602                        case 1:
     1603                        case 4:
     1604                                from = pair->value;
     1605                        case 5:
     1606                                to = pair->value;
     1607                                break;
     1608                        case 212:
     1609                                break;
     1610                        case 192:
     1611                                checksum = atoi( pair->value );
     1612                                break;
     1613                }
     1614        }
     1615
     1616        YAHOO_CALLBACK(ext_yahoo_got_buddyicon_checksum)(yd->client_id,to,from,checksum);
     1617}
     1618
     1619static void yahoo_process_picture(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1620{
     1621        struct yahoo_data *yd = yid->yd;
     1622        char *url = NULL;
     1623        char *from = NULL;
     1624        char *to = NULL;
     1625        int status = 0;
     1626        int checksum = 0;
     1627        YList *l;
     1628       
     1629        for(l = pkt->hash; l; l = l->next)
     1630        {
     1631                struct yahoo_pair *pair = l->data;
     1632
     1633                switch(pair->key)
     1634                {
     1635                case 1:
     1636                case 4:         /* sender */
     1637                        from = pair->value;
     1638                        break;
     1639                case 5:         /* we */
     1640                        to = pair->value;
     1641                        break;
     1642                case 13:                /* request / sending */
     1643                        status = atoi( pair->value );
     1644                        break;
     1645                case 20:                /* url */
     1646                        url = pair->value;
     1647                        break;
     1648                case 192:       /*checksum */
     1649                        checksum = atoi( pair->value );
     1650                        break;
     1651                }
     1652        }
     1653
     1654        switch( status )
     1655        {
     1656                case 1: /* this is a request, ignore for now */
     1657                        YAHOO_CALLBACK(ext_yahoo_got_buddyicon_request)(yd->client_id, to, from);
     1658                        break;
     1659                case 2: /* this is cool - we get a picture :) */
     1660                        YAHOO_CALLBACK(ext_yahoo_got_buddyicon)(yd->client_id,to, from, url, checksum);
     1661                        break;
     1662        }
     1663}
     1664
     1665static void yahoo_process_picture_upload(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1666{
     1667        struct yahoo_data *yd = yid->yd;
     1668        YList *l;
     1669        char *url = NULL;
     1670
     1671        if ( pkt->status != 1 )
     1672                return;         /* something went wrong */
     1673       
     1674        for(l = pkt->hash; l; l = l->next)
     1675        {
     1676                struct yahoo_pair *pair = l->data;
     1677
     1678                switch(pair->key)
     1679                {
     1680                        case 5:         /* we */
     1681                                break;
     1682                        case 20:                /* url */
     1683                                url = pair->value;
     1684                                break;
     1685                        case 27:                /* local filename */
     1686                                break;
     1687                        case 38:                /* time */
     1688                                break;
     1689                }
     1690        }
     1691
     1692        YAHOO_CALLBACK(ext_yahoo_buddyicon_uploaded)(yd->client_id, url);
    15121693}
    15131694
     
    21542335        int online = FALSE;
    21552336        int away = 0;
     2337        int idle = 0;
     2338        int mobile = 0;
    21562339
    21572340        YList *l;
     
    21752358                else if (pair->key == 47)
    21762359                        away = strtol(pair->value, NULL, 10);
     2360                else if (pair->key == 137)
     2361                        idle = strtol(pair->value, NULL, 10);
     2362                else if (pair->key == 60)
     2363                        mobile = strtol(pair->value, NULL, 10);
     2364               
    21772365        }
    21782366
     
    21802368                YAHOO_CALLBACK(ext_yahoo_contact_added)(yd->client_id, id, who, msg);
    21812369        else if (name)
    2182                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, name, state, msg, away);
     2370                YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, name, state, msg, away, idle, mobile);
    21832371        else if(pkt->status == 0x07)
    21842372                YAHOO_CALLBACK(ext_yahoo_rejected)(yd->client_id, who, msg);
     
    23082496
    23092497/*      if(status)
    2310                 YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, status, who, 0);
     2498                YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, who, 0, status);
    23112499*/     
    23122500}
     
    23322520        }
    23332521
    2334         NOTICE(("got voice chat invite from %s in %s", who, room));
     2522        NOTICE(("got voice chat invite from %s in %s to identity %s", who, room, me));
    23352523        /*
    23362524         * send: s:0 1:me 5:who 57:room 13:1
     
    23422530         * rejr: s:4 5:who 10:99 19:-1617114599
    23432531         */
     2532}
     2533
     2534static void yahoo_process_ping(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     2535{
     2536        char *errormsg = NULL;
     2537       
     2538        YList *l;
     2539        for (l = pkt->hash; l; l = l->next) {
     2540                struct yahoo_pair *pair = l->data;
     2541                if (pair->key == 16)
     2542                        errormsg = pair->value;
     2543        }
     2544       
     2545        NOTICE(("got ping packet"));
     2546        YAHOO_CALLBACK(ext_yahoo_got_ping)(yid->yd->client_id, errormsg);
    23442547}
    23452548
     
    25192722                yahoo_process_webcam_key(yid, pkt);
    25202723                break;
     2724        case YAHOO_SERVICE_PING:
     2725                yahoo_process_ping(yid, pkt);
     2726                break;
    25212727        case YAHOO_SERVICE_IDLE:
    25222728        case YAHOO_SERVICE_MAILSTAT:
     
    25262732        case YAHOO_SERVICE_ADDIDENT:
    25272733        case YAHOO_SERVICE_ADDIGNORE:
    2528         case YAHOO_SERVICE_PING:
    25292734        case YAHOO_SERVICE_GOTGROUPRENAME:
    25302735        case YAHOO_SERVICE_GROUPRENAME:
     
    25382743                yahoo_dump_unhandled(pkt);
    25392744                break;
     2745        case YAHOO_SERVICE_PICTURE:
     2746                yahoo_process_picture(yid, pkt);
     2747                break;
     2748        case YAHOO_SERVICE_PICTURE_CHECKSUM:
     2749                yahoo_process_picture_checksum(yid, pkt);
     2750                break;
     2751        case YAHOO_SERVICE_PICTURE_UPLOAD:
     2752                yahoo_process_picture_upload(yid, pkt);
     2753                break; 
    25402754        default:
    25412755                WARNING(("unknown service 0x%02x", pkt->service));
     
    33473561
    33483562                if(yid->type == YAHOO_CONNECTION_PAGER) {
    3349                         YAHOO_CALLBACK(ext_yahoo_login_response)(yid->yd->client_id, YAHOO_LOGIN_SOCK, NULL);
     3563                        YAHOO_CALLBACK(ext_yahoo_error)(yid->yd->client_id, "Connection closed by server", 1, E_CONNECTION);
    33503564                }
    33513565
     
    34953709}
    34963710
    3497 void yahoo_send_im(int id, const char *from, const char *who, const char *what, int utf8)
     3711void yahoo_send_im(int id, const char *from, const char *who, const char *what, int utf8, int picture)
    34983712{
    34993713        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
    35003714        struct yahoo_packet *pkt = NULL;
    35013715        struct yahoo_data *yd;
     3716        char pic_str[10];
    35023717
    35033718        if(!yid)
     
    35083723        pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, yd->session_id);
    35093724
     3725        snprintf(pic_str, sizeof(pic_str), "%d", picture);
     3726       
    35103727        if(from && strcmp(from, yd->user))
    35113728                yahoo_packet_hash(pkt, 0, yd->user);
     
    35193736        yahoo_packet_hash(pkt, 63, ";0");       /* imvironment name; or ;0 */
    35203737        yahoo_packet_hash(pkt, 64, "0");
     3738        yahoo_packet_hash(pkt, 206, pic_str);
    35213739
    35223740
     
    35713789        else
    35723790                service = YAHOO_SERVICE_ISAWAY;
    3573         pkt = yahoo_packet_new(service, yd->current_status, yd->session_id);
    3574         snprintf(s, sizeof(s), "%d", yd->current_status);
    3575         yahoo_packet_hash(pkt, 10, s);
    3576         if (yd->current_status == YAHOO_STATUS_CUSTOM) {
    3577                 yahoo_packet_hash(pkt, 19, msg);
    3578                 yahoo_packet_hash(pkt, 47, away?"1":"0");
     3791         
     3792        if ((away == 2) && (yd->current_status == YAHOO_STATUS_AVAILABLE)) {
     3793                pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_BRB, yd->session_id);
     3794                yahoo_packet_hash(pkt, 10, "999");
     3795                yahoo_packet_hash(pkt, 47, "2");
     3796        }else {
     3797                pkt = yahoo_packet_new(service, YAHOO_STATUS_AVAILABLE, yd->session_id);
     3798                snprintf(s, sizeof(s), "%d", yd->current_status);
     3799                yahoo_packet_hash(pkt, 10, s);
     3800                if (yd->current_status == YAHOO_STATUS_CUSTOM) {
     3801                        yahoo_packet_hash(pkt, 19, msg);
     3802                        yahoo_packet_hash(pkt, 47, (away == 2)? "2": (away) ?"1":"0");
     3803                } else {
     3804                        yahoo_packet_hash(pkt, 47, (away == 2)? "2": (away) ?"1":"0");
     3805                }
     3806               
     3807               
     3808               
    35793809        }
    35803810
     
    38174047}
    38184048
    3819 void yahoo_add_buddy(int id, const char *who, const char *group)
     4049void yahoo_add_buddy(int id, const char *who, const char *group, const char *msg)
    38204050{
    38214051        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
     
    38344064        yahoo_packet_hash(pkt, 7, who);
    38354065        yahoo_packet_hash(pkt, 65, group);
     4066        if (msg != NULL) /* add message/request "it's me add me" */
     4067                yahoo_packet_hash(pkt, 14, msg);
    38364068        yahoo_send_packet(yid, pkt, 0);
    38374069        yahoo_packet_free(pkt);
     
    38954127        yahoo_packet_hash(pkt, 7, who);
    38964128        yahoo_packet_hash(pkt, 13, unignore?"2":"1");
     4129        yahoo_send_packet(yid, pkt, 0);
     4130        yahoo_packet_free(pkt);
     4131}
     4132
     4133void yahoo_stealth_buddy(int id, const char *who, int unstealth)
     4134{
     4135        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
     4136        struct yahoo_data *yd;
     4137        struct yahoo_packet *pkt;
     4138
     4139        if(!yid)
     4140                return;
     4141        yd = yid->yd;
     4142
     4143        if (!yd->logged_in)
     4144                return;
     4145
     4146        pkt = yahoo_packet_new(YAHOO_SERVICE_STEALTH, YAHOO_STATUS_AVAILABLE, yd->session_id);
     4147        yahoo_packet_hash(pkt, 1, yd->user);
     4148        yahoo_packet_hash(pkt, 7, who);
     4149        yahoo_packet_hash(pkt, 31, unstealth?"2":"1");
     4150        yahoo_packet_hash(pkt, 13, "2");
    38974151        yahoo_send_packet(yid, pkt, 0);
    38984152        yahoo_packet_free(pkt);
     
    42024456        yahoo_packet_hash(pkt, 1, (from?from:yd->user));
    42034457
     4458        yahoo_send_packet(yid, pkt, 0);
     4459
     4460        yahoo_packet_free(pkt);
     4461}
     4462
     4463void yahoo_buddyicon_request(int id, const char *who)
     4464{
     4465        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
     4466        struct yahoo_data *yd;
     4467        struct yahoo_packet *pkt;
     4468
     4469        if( !yid )
     4470                return;
     4471
     4472        yd = yid->yd;
     4473       
     4474        pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
     4475        yahoo_packet_hash(pkt, 4, yd->user);
     4476        yahoo_packet_hash(pkt, 5, who);
     4477        yahoo_packet_hash(pkt, 13, "1");
     4478        yahoo_send_packet(yid, pkt, 0);
     4479
     4480        yahoo_packet_free(pkt);
     4481}
     4482
     4483void yahoo_send_picture_info(int id, const char *who, const char *url, int checksum)
     4484{
     4485        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
     4486        struct yahoo_data *yd;
     4487        struct yahoo_packet *pkt;
     4488        char checksum_str[10];
     4489
     4490        if( !yid )
     4491                return;
     4492
     4493        yd = yid->yd;
     4494
     4495        snprintf(checksum_str, sizeof(checksum_str), "%d", checksum);
     4496
     4497        pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
     4498        yahoo_packet_hash(pkt, 1, yd->user);
     4499        yahoo_packet_hash(pkt, 4, yd->user);
     4500        yahoo_packet_hash(pkt, 5, who);
     4501        yahoo_packet_hash(pkt, 13, "2");
     4502        yahoo_packet_hash(pkt, 20, url);
     4503        yahoo_packet_hash(pkt, 192, checksum_str);
     4504        yahoo_send_packet(yid, pkt, 0);
     4505
     4506        yahoo_packet_free(pkt);
     4507}
     4508
     4509void yahoo_send_picture_update(int id, const char *who, int type)
     4510{
     4511        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
     4512        struct yahoo_data *yd;
     4513        struct yahoo_packet *pkt;
     4514        char type_str[10];
     4515
     4516        if( !yid )
     4517                return;
     4518
     4519        yd = yid->yd;
     4520
     4521        snprintf(type_str, sizeof(type_str), "%d", type);
     4522
     4523        pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
     4524        yahoo_packet_hash(pkt, 1, yd->user);
     4525        yahoo_packet_hash(pkt, 5, who);
     4526        yahoo_packet_hash(pkt, 206, type_str);
     4527        yahoo_send_packet(yid, pkt, 0);
     4528
     4529        yahoo_packet_free(pkt);
     4530}
     4531
     4532void yahoo_send_picture_checksum(int id, const char *who, int checksum)
     4533{
     4534        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER);
     4535        struct yahoo_data *yd;
     4536        struct yahoo_packet *pkt;
     4537        char checksum_str[10];
     4538
     4539        if( !yid )
     4540                return;
     4541
     4542        yd = yid->yd;
     4543       
     4544        snprintf(checksum_str, sizeof(checksum_str), "%d", checksum);
     4545
     4546        pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0);
     4547        yahoo_packet_hash(pkt, 1, yd->user);
     4548        if( who != 0 )
     4549                yahoo_packet_hash(pkt, 5, who);
     4550        yahoo_packet_hash(pkt, 192, checksum_str);
     4551        yahoo_packet_hash(pkt, 212, "1");
    42044552        yahoo_send_packet(yid, pkt, 0);
    42054553
     
    44104758};
    44114759
     4760static void _yahoo_send_picture_connected(int id, int fd, int error, void *data)
     4761{
     4762        struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_FT);
     4763        struct send_file_data *sfd = data;
     4764        struct yahoo_packet *pkt = sfd->pkt;
     4765        unsigned char buff[1024];
     4766
     4767        if(fd <= 0) {
     4768                sfd->callback(id, fd, error, sfd->user_data);
     4769                FREE(sfd);
     4770                yahoo_packet_free(pkt);
     4771                inputs = y_list_remove(inputs, yid);
     4772                FREE(yid);
     4773                return;
     4774        }
     4775
     4776        yid->fd = fd;
     4777        yahoo_send_packet(yid, pkt, 8);
     4778        yahoo_packet_free(pkt);
     4779
     4780        snprintf((char *)buff, sizeof(buff), "29");
     4781        buff[2] = 0xc0;
     4782        buff[3] = 0x80;
     4783       
     4784        write(yid->fd, buff, 4);
     4785
     4786        /*      YAHOO_CALLBACK(ext_yahoo_add_handler)(nyd->fd, YAHOO_INPUT_READ); */
     4787
     4788        sfd->callback(id, fd, error, sfd->user_data);
     4789        FREE(sfd);
     4790        inputs = y_list_remove(inputs, yid);
     4791        /*
     4792        while(yahoo_tcp_readline(buff, sizeof(buff), nyd->fd) > 0) {
     4793        if(!strcmp(buff, ""))
     4794        break;
     4795}
     4796
     4797        */
     4798        yahoo_input_close(yid);
     4799}
     4800
     4801void yahoo_send_picture(int id, const char *name, unsigned long size,
     4802                                                        yahoo_get_fd_callback callback, void *data)
     4803{
     4804        struct yahoo_data *yd = find_conn_by_id(id);
     4805        struct yahoo_input_data *yid;
     4806        struct yahoo_server_settings *yss;
     4807        struct yahoo_packet *pkt = NULL;
     4808        char size_str[10];
     4809        char expire_str[10];
     4810        long content_length=0;
     4811        unsigned char buff[1024];
     4812        char url[255];
     4813        struct send_file_data *sfd;
     4814
     4815        if(!yd)
     4816                return;
     4817
     4818        yss = yd->server_settings;
     4819
     4820        yid = y_new0(struct yahoo_input_data, 1);
     4821        yid->yd = yd;
     4822        yid->type = YAHOO_CONNECTION_FT;
     4823
     4824        pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD, YAHOO_STATUS_AVAILABLE, yd->session_id);
     4825
     4826        snprintf(size_str, sizeof(size_str), "%ld", size);
     4827        snprintf(expire_str, sizeof(expire_str), "%ld", (long)604800);
     4828
     4829        yahoo_packet_hash(pkt, 0, yd->user);
     4830        yahoo_packet_hash(pkt, 1, yd->user);
     4831        yahoo_packet_hash(pkt, 14, "");
     4832        yahoo_packet_hash(pkt, 27, name);
     4833        yahoo_packet_hash(pkt, 28, size_str);
     4834        yahoo_packet_hash(pkt, 38, expire_str);
     4835       
     4836
     4837        content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt);
     4838
     4839        snprintf(url, sizeof(url), "http://%s:%d/notifyft",
     4840                                yss->filetransfer_host, yss->filetransfer_port);
     4841        snprintf((char *)buff, sizeof(buff), "Y=%s; T=%s",
     4842                                 yd->cookie_y, yd->cookie_t);
     4843        inputs = y_list_prepend(inputs, yid);
     4844
     4845        sfd = y_new0(struct send_file_data, 1);
     4846        sfd->pkt = pkt;
     4847        sfd->callback = callback;
     4848        sfd->user_data = data;
     4849        yahoo_http_post(yid->yd->client_id, url, (char *)buff, content_length+4+size,
     4850                                                _yahoo_send_picture_connected, sfd);
     4851}
     4852
    44124853static void _yahoo_send_file_connected(int id, int fd, int error, void *data)
    44134854{
Note: See TracChangeset for help on using the changeset viewer.