14192
|
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 */
|
|
38 void aim_chatnav_reqrights(OscarData *od, FlapConnection *conn)
|
|
39 {
|
|
40 aim_genericreq_n_snacid(od, conn, 0x000d, 0x0002);
|
|
41 }
|
|
42
|
|
43 /*
|
|
44 * Subtype 0x0008
|
|
45 */
|
|
46 int aim_chatnav_createroom(OscarData *od, FlapConnection *conn, const char *name, guint16 exchange)
|
|
47 {
|
|
48 static const char ck[] = {"create"};
|
|
49 static const char lang[] = {"en"};
|
|
50 static const char charset[] = {"us-ascii"};
|
|
51 FlapFrame *frame;
|
|
52 aim_snacid_t snacid;
|
|
53 aim_tlvlist_t *tl = NULL;
|
|
54
|
|
55 frame = flap_frame_new(od, 0x02, 1152);
|
|
56
|
|
57 snacid = aim_cachesnac(od, 0x000d, 0x0008, 0x0000, NULL, 0);
|
|
58 aim_putsnac(&frame->data, 0x000d, 0x0008, 0x0000, snacid);
|
|
59
|
|
60 /* exchange */
|
|
61 byte_stream_put16(&frame->data, exchange);
|
|
62
|
|
63 /*
|
|
64 * This looks to be a big hack. You'll note that this entire
|
|
65 * SNAC is just a room info structure, but the hard room name,
|
|
66 * here, is set to "create".
|
|
67 *
|
|
68 * Either this goes on the "list of questions concerning
|
|
69 * why-the-hell-did-you-do-that", or this value is completely
|
|
70 * ignored. Without experimental evidence, but a good knowledge of
|
|
71 * AOL style, I'm going to guess that it is the latter, and that
|
|
72 * the value of the room name in create requests is ignored.
|
|
73 */
|
|
74 byte_stream_put8(&frame->data, strlen(ck));
|
|
75 byte_stream_putstr(&frame->data, ck);
|
|
76
|
|
77 /*
|
|
78 * instance
|
|
79 *
|
|
80 * Setting this to 0xffff apparently assigns the last instance.
|
|
81 *
|
|
82 */
|
|
83 byte_stream_put16(&frame->data, 0xffff);
|
|
84
|
|
85 /* detail level */
|
|
86 byte_stream_put8(&frame->data, 0x01);
|
|
87
|
|
88 aim_tlvlist_add_str(&tl, 0x00d3, name);
|
|
89 aim_tlvlist_add_str(&tl, 0x00d6, charset);
|
|
90 aim_tlvlist_add_str(&tl, 0x00d7, lang);
|
|
91
|
|
92 /* tlvcount */
|
|
93 byte_stream_put16(&frame->data, aim_tlvlist_count(&tl));
|
|
94 aim_tlvlist_write(&frame->data, &tl);
|
|
95
|
|
96 aim_tlvlist_free(&tl);
|
|
97
|
|
98 flap_connection_send(conn, frame);
|
|
99
|
|
100 return 0;
|
|
101 }
|
|
102
|
|
103 static int
|
|
104 parseinfo_perms(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs, aim_snac_t *snac2)
|
|
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))); ) {
|
|
130 ByteStream tbs;
|
|
131
|
|
132 byte_stream_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 = byte_stream_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(od, snac->family, snac->subtype)))
|
|
300 ret = userfunc(od, conn, frame, 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
|
|
315 static int
|
|
316 parseinfo_create(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs, aim_snac_t *snac2)
|
|
317 {
|
|
318 aim_rxcallback_t userfunc;
|
|
319 aim_tlvlist_t *tlvlist, *innerlist;
|
|
320 char *ck = NULL, *fqcn = NULL, *name = NULL;
|
|
321 guint16 exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0;
|
|
322 guint32 createtime = 0;
|
|
323 guint8 createperms = 0, detaillevel;
|
|
324 int cklen;
|
|
325 aim_tlv_t *bigblock;
|
|
326 int ret = 0;
|
|
327 ByteStream bbbs;
|
|
328
|
|
329 tlvlist = aim_tlvlist_read(bs);
|
|
330
|
|
331 if (!(bigblock = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
|
|
332 gaim_debug_misc("oscar", "no bigblock in top tlv in create room response\n");
|
|
333 aim_tlvlist_free(&tlvlist);
|
|
334 return 0;
|
|
335 }
|
|
336
|
|
337 byte_stream_init(&bbbs, bigblock->value, bigblock->length);
|
|
338
|
|
339 exchange = byte_stream_get16(&bbbs);
|
|
340 cklen = byte_stream_get8(&bbbs);
|
|
341 ck = byte_stream_getstr(&bbbs, cklen);
|
|
342 instance = byte_stream_get16(&bbbs);
|
|
343 detaillevel = byte_stream_get8(&bbbs);
|
|
344
|
|
345 if (detaillevel != 0x02) {
|
|
346 gaim_debug_misc("oscar", "unknown detaillevel in create room response (0x%02x)\n", detaillevel);
|
|
347 aim_tlvlist_free(&tlvlist);
|
|
348 free(ck);
|
|
349 return 0;
|
|
350 }
|
|
351
|
|
352 unknown = byte_stream_get16(&bbbs);
|
|
353
|
|
354 innerlist = aim_tlvlist_read(&bbbs);
|
|
355
|
|
356 if (aim_tlv_gettlv(innerlist, 0x006a, 1))
|
|
357 fqcn = aim_tlv_getstr(innerlist, 0x006a, 1);
|
|
358
|
|
359 if (aim_tlv_gettlv(innerlist, 0x00c9, 1))
|
|
360 flags = aim_tlv_get16(innerlist, 0x00c9, 1);
|
|
361
|
|
362 if (aim_tlv_gettlv(innerlist, 0x00ca, 1))
|
|
363 createtime = aim_tlv_get32(innerlist, 0x00ca, 1);
|
|
364
|
|
365 if (aim_tlv_gettlv(innerlist, 0x00d1, 1))
|
|
366 maxmsglen = aim_tlv_get16(innerlist, 0x00d1, 1);
|
|
367
|
|
368 if (aim_tlv_gettlv(innerlist, 0x00d2, 1))
|
|
369 maxoccupancy = aim_tlv_get16(innerlist, 0x00d2, 1);
|
|
370
|
|
371 if (aim_tlv_gettlv(innerlist, 0x00d3, 1))
|
|
372 name = aim_tlv_getstr(innerlist, 0x00d3, 1);
|
|
373
|
|
374 if (aim_tlv_gettlv(innerlist, 0x00d5, 1))
|
|
375 createperms = aim_tlv_get8(innerlist, 0x00d5, 1);
|
|
376
|
|
377 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) {
|
|
378 ret = userfunc(od, conn, frame, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
|
|
379 }
|
|
380
|
|
381 free(ck);
|
|
382 free(name);
|
|
383 free(fqcn);
|
|
384 aim_tlvlist_free(&innerlist);
|
|
385 aim_tlvlist_free(&tlvlist);
|
|
386
|
|
387 return ret;
|
|
388 }
|
|
389
|
|
390 /*
|
|
391 * Subtype 0x0009
|
|
392 *
|
|
393 * Since multiple things can trigger this callback, we must lookup the
|
|
394 * snacid to determine the original snac subtype that was called.
|
|
395 *
|
|
396 * XXX This isn't really how this works. But this is: Every d/9 response
|
|
397 * has a 16bit value at the beginning. That matches to:
|
|
398 * Short Desc = 1
|
|
399 * Full Desc = 2
|
|
400 * Instance Info = 4
|
|
401 * Nav Short Desc = 8
|
|
402 * Nav Instance Info = 16
|
|
403 * And then everything is really asynchronous. There is no specific
|
|
404 * attachment of a response to a create room request, for example. Creating
|
|
405 * the room yields no different a response than requesting the room's info.
|
|
406 *
|
|
407 */
|
|
408 static int
|
|
409 parseinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
|
410 {
|
|
411 aim_snac_t *snac2;
|
|
412 int ret = 0;
|
|
413
|
|
414 if (!(snac2 = aim_remsnac(od, snac->id))) {
|
|
415 gaim_debug_misc("oscar", "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snac->id);
|
|
416 return 0;
|
|
417 }
|
|
418
|
|
419 if (snac2->family != 0x000d) {
|
|
420 gaim_debug_misc("oscar", "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac2->family);
|
|
421 return 0;
|
|
422 }
|
|
423
|
|
424 /*
|
|
425 * We now know what the original SNAC subtype was.
|
|
426 */
|
|
427 if (snac2->type == 0x0002) /* request chat rights */
|
|
428 ret = parseinfo_perms(od, conn, mod, frame, snac, bs, snac2);
|
|
429 else if (snac2->type == 0x0003) /* request exchange info */
|
|
430 gaim_debug_misc("oscar", "chatnav_parse_info: resposne to exchange info\n");
|
|
431 else if (snac2->type == 0x0004) /* request room info */
|
|
432 gaim_debug_misc("oscar", "chatnav_parse_info: response to room info\n");
|
|
433 else if (snac2->type == 0x0005) /* request more room info */
|
|
434 gaim_debug_misc("oscar", "chatnav_parse_info: response to more room info\n");
|
|
435 else if (snac2->type == 0x0006) /* request occupant list */
|
|
436 gaim_debug_misc("oscar", "chatnav_parse_info: response to occupant info\n");
|
|
437 else if (snac2->type == 0x0007) /* search for a room */
|
|
438 gaim_debug_misc("oscar", "chatnav_parse_info: search results\n");
|
|
439 else if (snac2->type == 0x0008) /* create room */
|
|
440 ret = parseinfo_create(od, conn, mod, frame, snac, bs, snac2);
|
|
441 else
|
|
442 gaim_debug_misc("oscar", "chatnav_parse_info: unknown request subtype (%04x)\n", snac2->type);
|
|
443
|
|
444 if (snac2)
|
|
445 free(snac2->data);
|
|
446 free(snac2);
|
|
447
|
|
448 return ret;
|
|
449 }
|
|
450
|
|
451 static int
|
|
452 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
|
453 {
|
|
454 if (snac->subtype == 0x0009)
|
|
455 return parseinfo(od, conn, mod, frame, snac, bs);
|
|
456
|
|
457 return 0;
|
|
458 }
|
|
459
|
|
460 int
|
|
461 chatnav_modfirst(OscarData *od, aim_module_t *mod)
|
|
462 {
|
|
463 mod->family = 0x000d;
|
|
464 mod->version = 0x0001;
|
|
465 mod->toolid = 0x0010;
|
|
466 mod->toolversion = 0x0629;
|
|
467 mod->flags = 0;
|
|
468 strncpy(mod->name, "chatnav", sizeof(mod->name));
|
|
469 mod->snachandler = snachandler;
|
|
470
|
|
471 return 0;
|
|
472 }
|