rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / libpurple / protocols / oscar / family_buddy.c
blob3d38323032e34f714d051fc5d44884b6d14ae9bc
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.
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.
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.
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
22 * Family 0x0003 (SNAC_FAMILY_BUDDY) - Old-style Buddylist Management (non-SSI).
26 #include "oscar.h"
28 #include <string.h>
31 * Subtype 0x0002 - Request rights.
33 * Request Buddy List rights.
36 void
37 aim_buddylist_reqrights(OscarData *od, FlapConnection *conn)
39 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_BUDDY, SNAC_SUBTYPE_BUDDY_REQRIGHTS);
43 * Subtype 0x0003 - Rights.
46 static int
47 rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
49 aim_rxcallback_t userfunc;
50 GSList *tlvlist;
51 guint16 maxbuddies = 0, maxwatchers = 0;
52 int ret = 0;
55 * TLVs follow
57 tlvlist = aim_tlvlist_read(bs);
60 * TLV type 0x0001: Maximum number of buddies.
62 if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
63 maxbuddies = aim_tlv_get16(tlvlist, 0x0001, 1);
66 * TLV type 0x0002: Maximum number of watchers.
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.)
73 if (aim_tlv_gettlv(tlvlist, 0x0002, 1))
74 maxwatchers = aim_tlv_get16(tlvlist, 0x0002, 1);
77 * TLV type 0x0003: Unknown.
79 * ICQ only?
82 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
83 ret = userfunc(od, conn, frame, maxbuddies, maxwatchers);
85 aim_tlvlist_free(tlvlist);
87 return ret;
91 * Subtypes 0x000b (SNAC_SUBTYPE_BUDDY_ONCOMING) and 0x000c (SNAC_SUBTYPE_BUDDY_OFFGOING) - Change in buddy status
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.
97 * Although the offgoing notification contains no information,
98 * it is still in a format parsable by aim_info_extract().
101 static int
102 buddychange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
104 int ret = 0;
105 aim_userinfo_t userinfo;
106 aim_rxcallback_t userfunc;
108 aim_info_extract(od, bs, &userinfo);
110 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
111 ret = userfunc(od, conn, frame, &userinfo);
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_blist_find_buddy(account, userinfo.bn);
118 if (buddy) {
119 PurplePresence *presence = purple_buddy_get_presence(buddy);
121 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_MOOD))
122 icq_im_xstatus_request(od, userinfo.bn);
125 aim_info_free(&userinfo);
127 return ret;
130 static int
131 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
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);
138 return 0;
142 buddylist_modfirst(OscarData *od, aim_module_t *mod)
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;
152 return 0;