13234
|
1 /*
|
|
2 * Gaim'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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 */
|
|
20
|
|
21 /*
|
|
22 * Family 0x0003 - 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 */
|
13239
|
36 faim_export int aim_buddylist_reqrights(OscarSession *sess, OscarConnection *conn)
|
13234
|
37 {
|
|
38 return aim_genericreq_n_snacid(sess, conn, 0x0003, 0x0002);
|
|
39 }
|
|
40
|
|
41 /*
|
|
42 * Subtype 0x0003 - Rights.
|
|
43 *
|
|
44 */
|
13239
|
45 static int rights(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
46 {
|
|
47 aim_rxcallback_t userfunc;
|
|
48 aim_tlvlist_t *tlvlist;
|
|
49 guint16 maxbuddies = 0, maxwatchers = 0;
|
|
50 int ret = 0;
|
|
51
|
|
52 /*
|
|
53 * TLVs follow
|
|
54 */
|
|
55 tlvlist = aim_tlvlist_read(bs);
|
|
56
|
|
57 /*
|
|
58 * TLV type 0x0001: Maximum number of buddies.
|
|
59 */
|
|
60 if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
|
|
61 maxbuddies = aim_tlv_get16(tlvlist, 0x0001, 1);
|
|
62
|
|
63 /*
|
|
64 * TLV type 0x0002: Maximum number of watchers.
|
|
65 *
|
|
66 * Watchers are other users who have you on their buddy
|
|
67 * list. (This is called the "reverse list" by a certain
|
|
68 * other IM protocol.)
|
|
69 *
|
|
70 */
|
|
71 if (aim_tlv_gettlv(tlvlist, 0x0002, 1))
|
|
72 maxwatchers = aim_tlv_get16(tlvlist, 0x0002, 1);
|
|
73
|
|
74 /*
|
|
75 * TLV type 0x0003: Unknown.
|
|
76 *
|
|
77 * ICQ only?
|
|
78 */
|
|
79
|
|
80 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
81 ret = userfunc(sess, rx, maxbuddies, maxwatchers);
|
|
82
|
|
83 aim_tlvlist_free(&tlvlist);
|
|
84
|
|
85 return ret;
|
|
86 }
|
|
87
|
|
88 /*
|
|
89 * Subtype 0x0004 - Add buddy to list.
|
|
90 *
|
|
91 * Adds a single buddy to your buddy list after login.
|
|
92 * XXX This should just be an extension of setbuddylist()
|
|
93 *
|
|
94 */
|
13239
|
95 faim_export int aim_buddylist_addbuddy(OscarSession *sess, OscarConnection *conn, const char *sn)
|
13234
|
96 {
|
13239
|
97 FlapFrame *fr;
|
13234
|
98 aim_snacid_t snacid;
|
|
99
|
|
100 if (!sn || !strlen(sn))
|
|
101 return -EINVAL;
|
|
102
|
13253
|
103 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
|
13234
|
104 return -ENOMEM;
|
|
105
|
|
106 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
|
|
107 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid);
|
|
108
|
|
109 aimbs_put8(&fr->data, strlen(sn));
|
|
110 aimbs_putstr(&fr->data, sn);
|
|
111
|
|
112 aim_tx_enqueue(sess, fr);
|
|
113
|
|
114 return 0;
|
|
115 }
|
|
116
|
|
117 /*
|
|
118 * Subtype 0x0004 - Add multiple buddies to your buddy list.
|
|
119 *
|
|
120 * This just builds the "set buddy list" command then queues it.
|
|
121 *
|
|
122 * buddy_list = "Screen Name One&ScreenNameTwo&";
|
|
123 *
|
|
124 * XXX Clean this up.
|
|
125 *
|
|
126 */
|
13239
|
127 faim_export int aim_buddylist_set(OscarSession *sess, OscarConnection *conn, const char *buddy_list)
|
13234
|
128 {
|
13239
|
129 FlapFrame *fr;
|
13234
|
130 aim_snacid_t snacid;
|
|
131 int len = 0;
|
|
132 char *localcpy = NULL;
|
|
133 char *tmpptr = NULL;
|
|
134
|
|
135 if (!buddy_list || !(localcpy = strdup(buddy_list)))
|
|
136 return -EINVAL;
|
|
137
|
|
138 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) {
|
|
139 gaim_debug_misc("oscar", "---adding: %s (%d)\n", tmpptr, strlen(tmpptr));
|
|
140 len += 1 + strlen(tmpptr);
|
|
141 tmpptr = strtok(NULL, "&");
|
|
142 }
|
|
143
|
13253
|
144 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+len)))
|
13234
|
145 return -ENOMEM;
|
|
146
|
|
147 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, NULL, 0);
|
|
148 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid);
|
|
149
|
|
150 strncpy(localcpy, buddy_list, strlen(buddy_list) + 1);
|
|
151
|
|
152 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) {
|
|
153
|
|
154 gaim_debug_misc("oscar", "---adding: %s (%d)\n", tmpptr, strlen(tmpptr));
|
|
155
|
|
156 aimbs_put8(&fr->data, strlen(tmpptr));
|
|
157 aimbs_putstr(&fr->data, tmpptr);
|
|
158 tmpptr = strtok(NULL, "&");
|
|
159 }
|
|
160
|
|
161 aim_tx_enqueue(sess, fr);
|
|
162
|
|
163 free(localcpy);
|
|
164
|
|
165 return 0;
|
|
166 }
|
|
167
|
|
168 /*
|
|
169 * Subtype 0x0005 - Remove buddy from list.
|
|
170 *
|
|
171 * XXX generalise to support removing multiple buddies (basically, its
|
|
172 * the same as setbuddylist() but with a different snac subtype).
|
|
173 *
|
|
174 */
|
13239
|
175 faim_export int aim_buddylist_removebuddy(OscarSession *sess, OscarConnection *conn, const char *sn)
|
13234
|
176 {
|
13239
|
177 FlapFrame *fr;
|
13234
|
178 aim_snacid_t snacid;
|
|
179
|
|
180 if (!sn || !strlen(sn))
|
|
181 return -EINVAL;
|
|
182
|
13253
|
183 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
|
13234
|
184 return -ENOMEM;
|
|
185
|
|
186 snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
|
|
187 aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid);
|
|
188
|
|
189 aimbs_put8(&fr->data, strlen(sn));
|
|
190 aimbs_putstr(&fr->data, sn);
|
|
191
|
|
192 aim_tx_enqueue(sess, fr);
|
|
193
|
|
194 return 0;
|
|
195 }
|
|
196
|
|
197 /*
|
|
198 * Subtype 0x000b
|
|
199 *
|
|
200 * XXX Why would we send this?
|
|
201 *
|
|
202 */
|
13239
|
203 faim_export int aim_buddylist_oncoming(OscarSession *sess, OscarConnection *conn, aim_userinfo_t *info)
|
13234
|
204 {
|
13239
|
205 FlapFrame *fr;
|
13234
|
206 aim_snacid_t snacid;
|
|
207
|
|
208 if (!sess || !conn || !info)
|
|
209 return -EINVAL;
|
|
210
|
13253
|
211 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
|
13234
|
212 return -ENOMEM;
|
|
213
|
|
214 snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0);
|
|
215
|
|
216 aim_putsnac(&fr->data, 0x0003, 0x000b, 0x0000, snacid);
|
|
217 aim_putuserinfo(&fr->data, info);
|
|
218
|
|
219 aim_tx_enqueue(sess, fr);
|
|
220
|
|
221 return 0;
|
|
222 }
|
|
223
|
|
224 /*
|
|
225 * Subtype 0x000c
|
|
226 *
|
|
227 * XXX Why would we send this?
|
|
228 *
|
|
229 */
|
13239
|
230 faim_export int aim_buddylist_offgoing(OscarSession *sess, OscarConnection *conn, const char *sn)
|
13234
|
231 {
|
13239
|
232 FlapFrame *fr;
|
13234
|
233 aim_snacid_t snacid;
|
|
234
|
|
235 if (!sess || !conn || !sn)
|
|
236 return -EINVAL;
|
|
237
|
13253
|
238 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
|
13234
|
239 return -ENOMEM;
|
|
240
|
|
241 snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0);
|
|
242
|
|
243 aim_putsnac(&fr->data, 0x0003, 0x000c, 0x0000, snacid);
|
|
244 aimbs_put8(&fr->data, strlen(sn));
|
|
245 aimbs_putstr(&fr->data, sn);
|
|
246
|
|
247 aim_tx_enqueue(sess, fr);
|
|
248
|
|
249 return 0;
|
|
250 }
|
|
251
|
|
252 /*
|
|
253 * Subtypes 0x000b and 0x000c - Change in buddy status
|
|
254 *
|
|
255 * Oncoming Buddy notifications contain a subset of the
|
|
256 * user information structure. It's close enough to run
|
|
257 * through aim_info_extract() however.
|
|
258 *
|
|
259 * Although the offgoing notification contains no information,
|
|
260 * it is still in a format parsable by aim_info_extract().
|
|
261 *
|
|
262 */
|
13239
|
263 static int buddychange(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
264 {
|
|
265 int ret = 0;
|
|
266 aim_userinfo_t userinfo;
|
|
267 aim_rxcallback_t userfunc;
|
|
268
|
|
269 aim_info_extract(sess, bs, &userinfo);
|
|
270
|
|
271 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
272 ret = userfunc(sess, rx, &userinfo);
|
|
273
|
|
274 if (snac->subtype == 0x000b)
|
|
275 aim_locate_requestuserinfo(sess, userinfo.sn);
|
|
276 aim_info_free(&userinfo);
|
|
277
|
|
278 return ret;
|
|
279 }
|
|
280
|
13239
|
281 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
282 {
|
|
283
|
|
284 if (snac->subtype == 0x0003)
|
|
285 return rights(sess, mod, rx, snac, bs);
|
|
286 else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c))
|
|
287 return buddychange(sess, mod, rx, snac, bs);
|
|
288
|
|
289 return 0;
|
|
290 }
|
|
291
|
13239
|
292 faim_internal int buddylist_modfirst(OscarSession *sess, aim_module_t *mod)
|
13234
|
293 {
|
|
294
|
|
295 mod->family = 0x0003;
|
|
296 mod->version = 0x0001;
|
|
297 mod->toolid = 0x0110;
|
|
298 mod->toolversion = 0x0629;
|
|
299 mod->flags = 0;
|
|
300 strncpy(mod->name, "buddy", sizeof(mod->name));
|
|
301 mod->snachandler = snachandler;
|
|
302
|
|
303 return 0;
|
|
304 }
|