Annotation of ChivanetAimPidgin/oscarprpl/src/c/family_buddy.c, revision 1.1.1.1

1.1       snw         1: /*
                      2:  * Purple's oscar protocol plugin
                      3:  * This file is the legal property of its developers.
                      4:  * Please see the AUTHORS file distributed alongside this file.
                      5:  *
                      6:  * This library is free software; you can redistribute it and/or
                      7:  * modify it under the terms of the GNU Lesser General Public
                      8:  * License as published by the Free Software Foundation; either
                      9:  * version 2 of the License, or (at your option) any later version.
                     10:  *
                     11:  * This library is distributed in the hope that it will be useful,
                     12:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     14:  * Lesser General Public License for more details.
                     15:  *
                     16:  * You should have received a copy of the GNU Lesser General Public
                     17:  * License along with this library; if not, write to the Free Software
                     18:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
                     19: */
                     20: 
                     21: /*
                     22:  * Family 0x0003 (SNAC_FAMILY_BUDDY) - Old-style Buddylist Management (non-SSI).
                     23:  *
                     24:  */
                     25: 
                     26: #include "oscar.h"
                     27: 
                     28: #include <string.h>
                     29: 
                     30: /*
                     31:  * Subtype 0x0002 - Request rights.
                     32:  *
                     33:  * Request Buddy List rights.
                     34:  *
                     35:  */
                     36: void
                     37: aim_buddylist_reqrights(OscarData *od, FlapConnection *conn)
                     38: {
                     39:        aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_BUDDY, SNAC_SUBTYPE_BUDDY_REQRIGHTS);
                     40: }
                     41: 
                     42: /*
                     43:  * Subtype 0x0003 - Rights.
                     44:  *
                     45:  */
                     46: static int
                     47: rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
                     48: {
                     49:        aim_rxcallback_t userfunc;
                     50:        GSList *tlvlist;
                     51:        guint16 maxbuddies = 0, maxwatchers = 0;
                     52:        int ret = 0;
                     53: 
                     54:        /*
                     55:         * TLVs follow
                     56:         */
                     57:        tlvlist = aim_tlvlist_read(bs);
                     58: 
                     59:        /*
                     60:         * TLV type 0x0001: Maximum number of buddies.
                     61:         */
                     62:        if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
                     63:                maxbuddies = aim_tlv_get16(tlvlist, 0x0001, 1);
                     64: 
                     65:        /*
                     66:         * TLV type 0x0002: Maximum number of watchers.
                     67:         *
                     68:         * Watchers are other users who have you on their buddy
                     69:         * list.  (This is called the "reverse list" by a certain
                     70:         * other IM protocol.)
                     71:         *
                     72:         */
                     73:        if (aim_tlv_gettlv(tlvlist, 0x0002, 1))
                     74:                maxwatchers = aim_tlv_get16(tlvlist, 0x0002, 1);
                     75: 
                     76:        /*
                     77:         * TLV type 0x0003: Unknown.
                     78:         *
                     79:         * ICQ only?
                     80:         */
                     81: 
                     82:        if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
                     83:                ret = userfunc(od, conn, frame, maxbuddies, maxwatchers);
                     84: 
                     85:        aim_tlvlist_free(tlvlist);
                     86: 
                     87:        return ret;
                     88: }
                     89: 
                     90: /*
                     91:  * Subtypes 0x000b (SNAC_SUBTYPE_BUDDY_ONCOMING) and 0x000c (SNAC_SUBTYPE_BUDDY_OFFGOING) - Change in buddy status
                     92:  *
                     93:  * Oncoming Buddy notifications contain a subset of the
                     94:  * user information structure.  It's close enough to run
                     95:  * through aim_info_extract() however.
                     96:  *
                     97:  * Although the offgoing notification contains no information,
                     98:  * it is still in a format parsable by aim_info_extract().
                     99:  *
                    100:  */
                    101: static int
                    102: buddychange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
                    103: {
                    104:        int ret = 0;
                    105:        aim_userinfo_t userinfo;
                    106:        aim_rxcallback_t userfunc;
                    107: 
                    108:        aim_info_extract(od, bs, &userinfo);
                    109: 
                    110:        if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
                    111:                ret = userfunc(od, conn, frame, &userinfo);
                    112: 
                    113:        if (snac->subtype == SNAC_SUBTYPE_BUDDY_ONCOMING &&
                    114:            userinfo.capabilities & OSCAR_CAPABILITY_XTRAZ) {
                    115:                PurpleAccount *account = purple_connection_get_account(od->gc);
                    116:                PurpleBuddy *buddy = purple_find_buddy(account, userinfo.bn);
                    117: 
                    118:                if (buddy) {
                    119:                        PurplePresence *presence = purple_buddy_get_presence(buddy);
                    120: 
                    121:                        if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_MOOD))
                    122:                                icq_im_xstatus_request(od, userinfo.bn);
                    123:                }
                    124:        }
                    125:        aim_info_free(&userinfo);
                    126: 
                    127:        return ret;
                    128: }
                    129: 
                    130: static int
                    131: snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
                    132: {
                    133:        if (snac->subtype == SNAC_SUBTYPE_BUDDY_RIGHTSINFO)
                    134:                return rights(od, conn, mod, frame, snac, bs);
                    135:        else if ((snac->subtype == SNAC_SUBTYPE_BUDDY_ONCOMING) || (snac->subtype == SNAC_SUBTYPE_BUDDY_OFFGOING))
                    136:                return buddychange(od, conn, mod, frame, snac, bs);
                    137: 
                    138:        return 0;
                    139: }
                    140: 
                    141: int
                    142: buddylist_modfirst(OscarData *od, aim_module_t *mod)
                    143: {
                    144:        mod->family = SNAC_FAMILY_BUDDY;
                    145:        mod->version = 0x0001;
                    146:        mod->toolid = 0x0110;
                    147:        mod->toolversion = 0x0629;
                    148:        mod->flags = 0;
                    149:        strncpy(mod->name, "buddy", sizeof(mod->name));
                    150:        mod->snachandler = snachandler;
                    151: 
                    152:        return 0;
                    153: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>