]> andersk Git - libfaim.git/blame - src/buddylist.c
- Sat Mar 24 03:16:32 UTC 2001
[libfaim.git] / src / buddylist.c
CommitLineData
9de3ca7e 1
37ee990e 2#define FAIM_INTERNAL
dd60ff8b 3#include <aim.h>
9de3ca7e 4
9f1a4013 5/*
6 * Oncoming Buddy notifications contain a subset of the
7 * user information structure. Its close enough to run
8 * through aim_extractuserinfo() however.
9 *
10 */
11static int oncoming(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
12{
13 struct aim_userinfo_s userinfo;
14 rxcallback_t userfunc;
15
16 aim_extractuserinfo(sess, data, &userinfo);
17
18 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
19 return userfunc(sess, rx, &userinfo);
20
21 return 0;
22}
23
24/*
25 * Offgoing Buddy notifications contain no useful
26 * information other than the name it applies to.
27 *
28 */
29static int offgoing(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
30{
31 char sn[MAXSNLEN+1];
32 rxcallback_t userfunc;
33
34 strncpy(sn, (char *)data+1, (int)*data);
35
36 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
37 return userfunc(sess, rx, sn);
38
39 return 0;
40}
41
42static int rights(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
43{
44 rxcallback_t userfunc;
45 struct aim_tlvlist_t *tlvlist;
46 unsigned short maxbuddies = 0, maxwatchers = 0;
47 int ret = 0;
48
49 /*
50 * TLVs follow
51 */
52 if (!(tlvlist = aim_readtlvchain(data, datalen)))
53 return 0;
54
55 /*
56 * TLV type 0x0001: Maximum number of buddies.
57 */
58 if (aim_gettlv(tlvlist, 0x0001, 1))
59 maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1);
60
61 /*
62 * TLV type 0x0002: Maximum number of watchers.
63 *
64 * XXX: what the hell is a watcher?
65 *
66 */
67 if (aim_gettlv(tlvlist, 0x0002, 1))
68 maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1);
69
70 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
71 ret = userfunc(sess, rx, maxbuddies, maxwatchers);
72
73 aim_freetlvchain(&tlvlist);
74
75 return ret;
76}
77
78static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
79{
80
00ef5271 81 if (snac->subtype == 0x0003)
9f1a4013 82 return rights(sess, mod, rx, snac, data, datalen);
83 else if (snac->subtype == 0x000b)
84 return oncoming(sess, mod, rx, snac, data, datalen);
85 else if (snac->subtype == 0x000c)
86 return offgoing(sess, mod, rx, snac, data, datalen);
87
88 return 0;
89}
90
91faim_internal int buddylist_modfirst(struct aim_session_t *sess, aim_module_t *mod)
92{
93
94 mod->family = 0x0003;
95 mod->version = 0x0000;
96 mod->flags = 0;
97 strncpy(mod->name, "buddylist", sizeof(mod->name));
98 mod->snachandler = snachandler;
99
100 return 0;
101}
102
9de3ca7e 103/*
104 * aim_add_buddy()
105 *
106 * Adds a single buddy to your buddy list after login.
107 *
37ee990e 108 * XXX this should just be an extension of setbuddylist()
109 *
9de3ca7e 110 */
78b3fb13 111faim_export unsigned long aim_add_buddy(struct aim_session_t *sess,
112 struct aim_conn_t *conn,
113 char *sn )
9de3ca7e 114{
5b79dc93 115 struct command_tx_struct *newpacket;
116 int i;
9de3ca7e 117
5b79dc93 118 if(!sn)
119 return -1;
9de3ca7e 120
646c6b52 121 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
5b79dc93 122 return -1;
9de3ca7e 123
5b79dc93 124 newpacket->lock = 1;
9de3ca7e 125
5b79dc93 126 i = aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, sess->snac_nextid);
127 i += aimutil_put8(newpacket->data+i, strlen(sn));
128 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
9de3ca7e 129
5b79dc93 130 aim_tx_enqueue(sess, newpacket );
9de3ca7e 131
1ea867e3 132 aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
133
134 return sess->snac_nextid;
9de3ca7e 135}
136
37ee990e 137/*
138 * XXX generalise to support removing multiple buddies (basically, its
139 * the same as setbuddylist() but with a different snac subtype).
140 *
141 */
78b3fb13 142faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess,
143 struct aim_conn_t *conn,
144 char *sn )
9de3ca7e 145{
5b79dc93 146 struct command_tx_struct *newpacket;
147 int i;
9de3ca7e 148
5b79dc93 149 if(!sn)
150 return -1;
9de3ca7e 151
646c6b52 152 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
5b79dc93 153 return -1;
9de3ca7e 154
5b79dc93 155 newpacket->lock = 1;
9de3ca7e 156
5b79dc93 157 i = aim_putsnac(newpacket->data, 0x0003, 0x0005, 0x0000, sess->snac_nextid);
9de3ca7e 158
5b79dc93 159 i += aimutil_put8(newpacket->data+i, strlen(sn));
160 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
9de3ca7e 161
5b79dc93 162 aim_tx_enqueue(sess, newpacket);
9de3ca7e 163
1ea867e3 164 aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
9de3ca7e 165
1ea867e3 166 return sess->snac_nextid;
9de3ca7e 167}
168
This page took 0.113618 seconds and 5 git commands to generate.