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 0x000d - Handle ChatNav.
|
|
23 *
|
|
24 * The ChatNav(igation) service does various things to keep chat
|
|
25 * alive. It provides room information, room searching and creating,
|
|
26 * as well as giving users the right ("permission") to use chat.
|
|
27 *
|
|
28 */
|
|
29
|
|
30 #include "oscar.h"
|
|
31
|
|
32 /*
|
|
33 * Subtype 0x0002
|
|
34 *
|
|
35 * conn must be a chatnav connection!
|
|
36 *
|
|
37 */
|
13239
|
38 faim_export int aim_chatnav_reqrights(OscarSession *sess, OscarConnection *conn)
|
13234
|
39 {
|
|
40 return aim_genericreq_n_snacid(sess, conn, 0x000d, 0x0002);
|
|
41 }
|
|
42
|
|
43 /*
|
|
44 * Subtype 0x0008
|
|
45 */
|
13239
|
46 faim_export int aim_chatnav_createroom(OscarSession *sess, OscarConnection *conn, const char *name, guint16 exchange)
|
13234
|
47 {
|
|
48 static const char ck[] = {"create"};
|
|
49 static const char lang[] = {"en"};
|
|
50 static const char charset[] = {"us-ascii"};
|
13239
|
51 FlapFrame *fr;
|
13234
|
52 aim_snacid_t snacid;
|
|
53 aim_tlvlist_t *tl = NULL;
|
|
54
|
|
55 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
|
|
56 return -ENOMEM;
|
|
57
|
|
58 snacid = aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0);
|
|
59 aim_putsnac(&fr->data, 0x000d, 0x0008, 0x0000, snacid);
|
|
60
|
|
61 /* exchange */
|
|
62 aimbs_put16(&fr->data, exchange);
|
|
63
|
|
64 /*
|
|
65 * This looks to be a big hack. You'll note that this entire
|
|
66 * SNAC is just a room info structure, but the hard room name,
|
|
67 * here, is set to "create".
|
|
68 *
|
|
69 * Either this goes on the "list of questions concerning
|
|
70 * why-the-hell-did-you-do-that", or this value is completely
|
|
71 * ignored. Without experimental evidence, but a good knowledge of
|
|
72 * AOL style, I'm going to guess that it is the latter, and that
|
|
73 * the value of the room name in create requests is ignored.
|
|
74 */
|
|
75 aimbs_put8(&fr->data, strlen(ck));
|
|
76 aimbs_putstr(&fr->data, ck);
|
|
77
|
|
78 /*
|
|
79 * instance
|
|
80 *
|
|
81 * Setting this to 0xffff apparently assigns the last instance.
|
|
82 *
|
|
83 */
|
|
84 aimbs_put16(&fr->data, 0xffff);
|
|
85
|
|
86 /* detail level */
|
|
87 aimbs_put8(&fr->data, 0x01);
|
|
88
|
|
89 aim_tlvlist_add_str(&tl, 0x00d3, name);
|
|
90 aim_tlvlist_add_str(&tl, 0x00d6, charset);
|
|
91 aim_tlvlist_add_str(&tl, 0x00d7, lang);
|
|
92
|
|
93 /* tlvcount */
|
|
94 aimbs_put16(&fr->data, aim_tlvlist_count(&tl));
|
|
95 aim_tlvlist_write(&fr->data, &tl);
|
|
96
|
|
97 aim_tlvlist_free(&tl);
|
|
98
|
|
99 aim_tx_enqueue(sess, fr);
|
|
100
|
|
101 return 0;
|
|
102 }
|
|
103
|
13239
|
104 static int parseinfo_perms(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs, aim_snac_t *snac2)
|
13234
|
105 {
|
|
106 aim_rxcallback_t userfunc;
|
|
107 int ret = 0;
|
|
108 struct aim_chat_exchangeinfo *exchanges = NULL;
|
|
109 int curexchange;
|
|
110 aim_tlv_t *exchangetlv;
|
|
111 guint8 maxrooms = 0;
|
|
112 aim_tlvlist_t *tlvlist, *innerlist;
|
|
113
|
|
114 tlvlist = aim_tlvlist_read(bs);
|
|
115
|
|
116 /*
|
|
117 * Type 0x0002: Maximum concurrent rooms.
|
|
118 */
|
|
119 if (aim_tlv_gettlv(tlvlist, 0x0002, 1))
|
|
120 maxrooms = aim_tlv_get8(tlvlist, 0x0002, 1);
|
|
121
|
|
122 /*
|
|
123 * Type 0x0003: Exchange information
|
|
124 *
|
|
125 * There can be any number of these, each one
|
|
126 * representing another exchange.
|
|
127 *
|
|
128 */
|
|
129 for (curexchange = 0; ((exchangetlv = aim_tlv_gettlv(tlvlist, 0x0003, curexchange+1))); ) {
|
13239
|
130 ByteStream tbs;
|
13234
|
131
|
|
132 aim_bstream_init(&tbs, exchangetlv->value, exchangetlv->length);
|
|
133
|
|
134 curexchange++;
|
|
135
|
|
136 exchanges = realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo));
|
|
137
|
|
138 /* exchange number */
|
|
139 exchanges[curexchange-1].number = aimbs_get16(&tbs);
|
|
140 innerlist = aim_tlvlist_read(&tbs);
|
|
141
|
|
142 #if 0
|
|
143 /*
|
|
144 * Type 0x000a: Unknown.
|
|
145 *
|
|
146 * Usually three bytes: 0x0114 (exchange 1) or 0x010f (others).
|
|
147 *
|
|
148 */
|
|
149 if (aim_tlv_gettlv(innerlist, 0x000a, 1)) {
|
|
150 /* Unhandled */
|
|
151 }
|
|
152
|
|
153 /*
|
|
154 * Type 0x000d: Unknown.
|
|
155 */
|
|
156 if (aim_tlv_gettlv(innerlist, 0x000d, 1)) {
|
|
157 /* Unhandled */
|
|
158 }
|
|
159
|
|
160 /*
|
|
161 * Type 0x0004: Unknown
|
|
162 */
|
|
163 if (aim_tlv_gettlv(innerlist, 0x0004, 1)) {
|
|
164 /* Unhandled */
|
|
165 }
|
|
166 #endif
|
|
167
|
|
168 /*
|
|
169 * Type 0x0002: Unknown
|
|
170 */
|
|
171 if (aim_tlv_gettlv(innerlist, 0x0002, 1)) {
|
|
172 guint16 classperms;
|
|
173
|
|
174 classperms = aim_tlv_get16(innerlist, 0x0002, 1);
|
|
175
|
|
176 gaim_debug_misc("oscar", "faim: class permissions %x\n", classperms);
|
|
177 }
|
|
178
|
|
179 /*
|
|
180 * Type 0x00c9: Flags
|
|
181 *
|
|
182 * 1 Evilable
|
|
183 * 2 Nav Only
|
|
184 * 4 Instancing Allowed
|
|
185 * 8 Occupant Peek Allowed
|
|
186 *
|
|
187 */
|
|
188 if (aim_tlv_gettlv(innerlist, 0x00c9, 1))
|
|
189 exchanges[curexchange-1].flags = aim_tlv_get16(innerlist, 0x00c9, 1);
|
|
190
|
|
191 #if 0
|
|
192 /*
|
|
193 * Type 0x00ca: Creation Date
|
|
194 */
|
|
195 if (aim_tlv_gettlv(innerlist, 0x00ca, 1)) {
|
|
196 /* Unhandled */
|
|
197 }
|
|
198
|
|
199 /*
|
|
200 * Type 0x00d0: Mandatory Channels?
|
|
201 */
|
|
202 if (aim_tlv_gettlv(innerlist, 0x00d0, 1)) {
|
|
203 /* Unhandled */
|
|
204 }
|
|
205
|
|
206 /*
|
|
207 * Type 0x00d1: Maximum Message length
|
|
208 */
|
|
209 if (aim_tlv_gettlv(innerlist, 0x00d1, 1)) {
|
|
210 /* Unhandled */
|
|
211 }
|
|
212
|
|
213 /*
|
|
214 * Type 0x00d2: Maximum Occupancy?
|
|
215 */
|
|
216 if (aim_tlv_gettlv(innerlist, 0x00d2, 1)) {
|
|
217 /* Unhandled */
|
|
218 }
|
|
219 #endif
|
|
220
|
|
221 /*
|
|
222 * Type 0x00d3: Exchange Description
|
|
223 */
|
|
224 if (aim_tlv_gettlv(innerlist, 0x00d3, 1))
|
|
225 exchanges[curexchange-1].name = aim_tlv_getstr(innerlist, 0x00d3, 1);
|
|
226 else
|
|
227 exchanges[curexchange-1].name = NULL;
|
|
228
|
|
229 #if 0
|
|
230 /*
|
|
231 * Type 0x00d4: Exchange Description URL
|
|
232 */
|
|
233 if (aim_tlv_gettlv(innerlist, 0x00d4, 1)) {
|
|
234 /* Unhandled */
|
|
235 }
|
|
236 #endif
|
|
237
|
|
238 /*
|
|
239 * Type 0x00d5: Creation Permissions
|
|
240 *
|
|
241 * 0 Creation not allowed
|
|
242 * 1 Room creation allowed
|
|
243 * 2 Exchange creation allowed
|
|
244 *
|
|
245 */
|
|
246 if (aim_tlv_gettlv(innerlist, 0x00d5, 1)) {
|
|
247 guint8 createperms;
|
|
248
|
|
249 createperms = aim_tlv_get8(innerlist, 0x00d5, 1);
|
|
250 }
|
|
251
|
|
252 /*
|
|
253 * Type 0x00d6: Character Set (First Time)
|
|
254 */
|
|
255 if (aim_tlv_gettlv(innerlist, 0x00d6, 1))
|
|
256 exchanges[curexchange-1].charset1 = aim_tlv_getstr(innerlist, 0x00d6, 1);
|
|
257 else
|
|
258 exchanges[curexchange-1].charset1 = NULL;
|
|
259
|
|
260 /*
|
|
261 * Type 0x00d7: Language (First Time)
|
|
262 */
|
|
263 if (aim_tlv_gettlv(innerlist, 0x00d7, 1))
|
|
264 exchanges[curexchange-1].lang1 = aim_tlv_getstr(innerlist, 0x00d7, 1);
|
|
265 else
|
|
266 exchanges[curexchange-1].lang1 = NULL;
|
|
267
|
|
268 /*
|
|
269 * Type 0x00d8: Character Set (Second Time)
|
|
270 */
|
|
271 if (aim_tlv_gettlv(innerlist, 0x00d8, 1))
|
|
272 exchanges[curexchange-1].charset2 = aim_tlv_getstr(innerlist, 0x00d8, 1);
|
|
273 else
|
|
274 exchanges[curexchange-1].charset2 = NULL;
|
|
275
|
|
276 /*
|
|
277 * Type 0x00d9: Language (Second Time)
|
|
278 */
|
|
279 if (aim_tlv_gettlv(innerlist, 0x00d9, 1))
|
|
280 exchanges[curexchange-1].lang2 = aim_tlv_getstr(innerlist, 0x00d9, 1);
|
|
281 else
|
|
282 exchanges[curexchange-1].lang2 = NULL;
|
|
283
|
|
284 #if 0
|
|
285 /*
|
|
286 * Type 0x00da: Unknown
|
|
287 */
|
|
288 if (aim_tlv_gettlv(innerlist, 0x00da, 1)) {
|
|
289 /* Unhandled */
|
|
290 }
|
|
291 #endif
|
|
292
|
|
293 aim_tlvlist_free(&innerlist);
|
|
294 }
|
|
295
|
|
296 /*
|
|
297 * Call client.
|
|
298 */
|
|
299 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
300 ret = userfunc(sess, rx, snac2->type, maxrooms, curexchange, exchanges);
|
|
301
|
|
302 for (curexchange--; curexchange >= 0; curexchange--) {
|
|
303 free(exchanges[curexchange].name);
|
|
304 free(exchanges[curexchange].charset1);
|
|
305 free(exchanges[curexchange].lang1);
|
|
306 free(exchanges[curexchange].charset2);
|
|
307 free(exchanges[curexchange].lang2);
|
|
308 }
|
|
309 free(exchanges);
|
|
310 aim_tlvlist_free(&tlvlist);
|
|
311
|
|
312 return ret;
|
|
313 }
|
|
314
|
13239
|
315 static int parseinfo_create(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs, aim_snac_t *snac2)
|
13234
|
316 {
|
|
317 aim_rxcallback_t userfunc;
|
|
318 aim_tlvlist_t *tlvlist, *innerlist;
|
|
319 char *ck = NULL, *fqcn = NULL, *name = NULL;
|
|
320 guint16 exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0;
|
|
321 guint32 createtime = 0;
|
|
322 guint8 createperms = 0, detaillevel;
|
|
323 int cklen;
|
|
324 aim_tlv_t *bigblock;
|
|
325 int ret = 0;
|
13239
|
326 ByteStream bbbs;
|
13234
|
327
|
|
328 tlvlist = aim_tlvlist_read(bs);
|
|
329
|
|
330 if (!(bigblock = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
|
|
331 gaim_debug_misc("oscar", "no bigblock in top tlv in create room response\n");
|
|
332 aim_tlvlist_free(&tlvlist);
|
|
333 return 0;
|
|
334 }
|
|
335
|
|
336 aim_bstream_init(&bbbs, bigblock->value, bigblock->length);
|
|
337
|
|
338 exchange = aimbs_get16(&bbbs);
|
|
339 cklen = aimbs_get8(&bbbs);
|
|
340 ck = aimbs_getstr(&bbbs, cklen);
|
|
341 instance = aimbs_get16(&bbbs);
|
|
342 detaillevel = aimbs_get8(&bbbs);
|
|
343
|
|
344 if (detaillevel != 0x02) {
|
|
345 gaim_debug_misc("oscar", "unknown detaillevel in create room response (0x%02x)\n", detaillevel);
|
|
346 aim_tlvlist_free(&tlvlist);
|
|
347 free(ck);
|
|
348 return 0;
|
|
349 }
|
|
350
|
|
351 unknown = aimbs_get16(&bbbs);
|
|
352
|
|
353 innerlist = aim_tlvlist_read(&bbbs);
|
|
354
|
|
355 if (aim_tlv_gettlv(innerlist, 0x006a, 1))
|
|
356 fqcn = aim_tlv_getstr(innerlist, 0x006a, 1);
|
|
357
|
|
358 if (aim_tlv_gettlv(innerlist, 0x00c9, 1))
|
|
359 flags = aim_tlv_get16(innerlist, 0x00c9, 1);
|
|
360
|
|
361 if (aim_tlv_gettlv(innerlist, 0x00ca, 1))
|
|
362 createtime = aim_tlv_get32(innerlist, 0x00ca, 1);
|
|
363
|
|
364 if (aim_tlv_gettlv(innerlist, 0x00d1, 1))
|
|
365 maxmsglen = aim_tlv_get16(innerlist, 0x00d1, 1);
|
|
366
|
|
367 if (aim_tlv_gettlv(innerlist, 0x00d2, 1))
|
|
368 maxoccupancy = aim_tlv_get16(innerlist, 0x00d2, 1);
|
|
369
|
|
370 if (aim_tlv_gettlv(innerlist, 0x00d3, 1))
|
|
371 name = aim_tlv_getstr(innerlist, 0x00d3, 1);
|
|
372
|
|
373 if (aim_tlv_gettlv(innerlist, 0x00d5, 1))
|
|
374 createperms = aim_tlv_get8(innerlist, 0x00d5, 1);
|
|
375
|
|
376 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
|
|
377 ret = userfunc(sess, rx, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
|
|
378 }
|
|
379
|
|
380 free(ck);
|
|
381 free(name);
|
|
382 free(fqcn);
|
|
383 aim_tlvlist_free(&innerlist);
|
|
384 aim_tlvlist_free(&tlvlist);
|
|
385
|
|
386 return ret;
|
|
387 }
|
|
388
|
|
389 /*
|
|
390 * Subtype 0x0009
|
|
391 *
|
|
392 * Since multiple things can trigger this callback, we must lookup the
|
|
393 * snacid to determine the original snac subtype that was called.
|
|
394 *
|
|
395 * XXX This isn't really how this works. But this is: Every d/9 response
|
|
396 * has a 16bit value at the beginning. That matches to:
|
|
397 * Short Desc = 1
|
|
398 * Full Desc = 2
|
|
399 * Instance Info = 4
|
|
400 * Nav Short Desc = 8
|
|
401 * Nav Instance Info = 16
|
|
402 * And then everything is really asynchronous. There is no specific
|
|
403 * attachment of a response to a create room request, for example. Creating
|
|
404 * the room yields no different a response than requesting the room's info.
|
|
405 *
|
|
406 */
|
13239
|
407 static int parseinfo(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
408 {
|
|
409 aim_snac_t *snac2;
|
|
410 int ret = 0;
|
|
411
|
|
412 if (!(snac2 = aim_remsnac(sess, snac->id))) {
|
|
413 gaim_debug_misc("oscar", "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snac->id);
|
|
414 return 0;
|
|
415 }
|
|
416
|
|
417 if (snac2->family != 0x000d) {
|
|
418 gaim_debug_misc("oscar", "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac2->family);
|
|
419 return 0;
|
|
420 }
|
|
421
|
|
422 /*
|
|
423 * We now know what the original SNAC subtype was.
|
|
424 */
|
|
425 if (snac2->type == 0x0002) /* request chat rights */
|
|
426 ret = parseinfo_perms(sess, mod, rx, snac, bs, snac2);
|
|
427 else if (snac2->type == 0x0003) /* request exchange info */
|
|
428 gaim_debug_misc("oscar", "chatnav_parse_info: resposne to exchange info\n");
|
|
429 else if (snac2->type == 0x0004) /* request room info */
|
|
430 gaim_debug_misc("oscar", "chatnav_parse_info: response to room info\n");
|
|
431 else if (snac2->type == 0x0005) /* request more room info */
|
|
432 gaim_debug_misc("oscar", "chatnav_parse_info: response to more room info\n");
|
|
433 else if (snac2->type == 0x0006) /* request occupant list */
|
|
434 gaim_debug_misc("oscar", "chatnav_parse_info: response to occupant info\n");
|
|
435 else if (snac2->type == 0x0007) /* search for a room */
|
|
436 gaim_debug_misc("oscar", "chatnav_parse_info: search results\n");
|
|
437 else if (snac2->type == 0x0008) /* create room */
|
|
438 ret = parseinfo_create(sess, mod, rx, snac, bs, snac2);
|
|
439 else
|
|
440 gaim_debug_misc("oscar", "chatnav_parse_info: unknown request subtype (%04x)\n", snac2->type);
|
|
441
|
|
442 if (snac2)
|
|
443 free(snac2->data);
|
|
444 free(snac2);
|
|
445
|
|
446 return ret;
|
|
447 }
|
|
448
|
13239
|
449 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
450 {
|
|
451
|
|
452 if (snac->subtype == 0x0009)
|
|
453 return parseinfo(sess, mod, rx, snac, bs);
|
|
454
|
|
455 return 0;
|
|
456 }
|
|
457
|
13239
|
458 faim_internal int chatnav_modfirst(OscarSession *sess, aim_module_t *mod)
|
13234
|
459 {
|
|
460
|
|
461 mod->family = 0x000d;
|
|
462 mod->version = 0x0001;
|
|
463 mod->toolid = 0x0010;
|
|
464 mod->toolversion = 0x0629;
|
|
465 mod->flags = 0;
|
|
466 strncpy(mod->name, "chatnav", sizeof(mod->name));
|
|
467 mod->snachandler = snachandler;
|
|
468
|
|
469 return 0;
|
|
470 }
|