source: protocols/oscar/buddylist.c @ b7d3cc34

0.99
Last change on this file since b7d3cc34 was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include <aim.h>
2#include "buddylist.h"
3
4/*
5 * Oncoming Buddy notifications contain a subset of the
6 * user information structure.  Its close enough to run
7 * through aim_extractuserinfo() however.
8 *
9 * Although the offgoing notification contains no information,
10 * it is still in a format parsable by extractuserinfo.
11 *
12 */
13static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
14{
15        aim_userinfo_t userinfo;
16        aim_rxcallback_t userfunc;
17
18        aim_extractuserinfo(sess, bs, &userinfo);
19
20        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
21                return userfunc(sess, rx, &userinfo);
22
23        return 0;
24}
25
26static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
27{
28        aim_rxcallback_t userfunc;
29        aim_tlvlist_t *tlvlist;
30        guint16 maxbuddies = 0, maxwatchers = 0;
31        int ret = 0;
32
33        /*
34         * TLVs follow
35         */
36        tlvlist = aim_readtlvchain(bs);
37
38        /*
39         * TLV type 0x0001: Maximum number of buddies.
40         */
41        if (aim_gettlv(tlvlist, 0x0001, 1))
42                maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1);
43
44        /*
45         * TLV type 0x0002: Maximum number of watchers.
46         *
47         * Watchers are other users who have you on their buddy
48         * list.  (This is called the "reverse list" by a certain
49         * other IM protocol.)
50         *
51         */
52        if (aim_gettlv(tlvlist, 0x0002, 1))
53                maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1);
54
55        /*
56         * TLV type 0x0003: Unknown.
57         *
58         * ICQ only?
59         */
60
61        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
62                ret = userfunc(sess, rx, maxbuddies, maxwatchers);
63
64        aim_freetlvchain(&tlvlist);
65
66        return ret; 
67}
68
69static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
70{
71
72        if (snac->subtype == 0x0003)
73                return rights(sess, mod, rx, snac, bs);
74        else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c))
75                return buddychange(sess, mod, rx, snac, bs);
76
77        return 0;
78}
79
80int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod)
81{
82
83        mod->family = 0x0003;
84        mod->version = 0x0001;
85        mod->toolid = 0x0110;
86        mod->toolversion = 0x0629;
87        mod->flags = 0;
88        strncpy(mod->name, "buddylist", sizeof(mod->name));
89        mod->snachandler = snachandler;
90
91        return 0;
92}
93
94/*
95 * aim_add_buddy()
96 *
97 * Adds a single buddy to your buddy list after login.
98 *
99 * XXX this should just be an extension of setbuddylist()
100 *
101 */
102int aim_add_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn)
103{
104        aim_frame_t *fr;
105        aim_snacid_t snacid;
106
107        if (!sn || !strlen(sn))
108                return -EINVAL;
109
110        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
111                return -ENOMEM;
112
113        snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
114        aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid);
115
116        aimbs_put8(&fr->data, strlen(sn));
117        aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
118
119        aim_tx_enqueue(sess, fr);
120
121        return 0;
122}
123
124/*
125 * XXX generalise to support removing multiple buddies (basically, its
126 * the same as setbuddylist() but with a different snac subtype).
127 *
128 */
129int aim_remove_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn)
130{
131        aim_frame_t *fr;
132        aim_snacid_t snacid;
133
134        if (!sn || !strlen(sn))
135                return -EINVAL;
136
137        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
138                return -ENOMEM;
139
140        snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
141        aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid);
142
143        aimbs_put8(&fr->data, strlen(sn));
144        aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
145
146        aim_tx_enqueue(sess, fr);
147
148        return 0;
149}
150
Note: See TracBrowser for help on using the repository browser.