source: libfaim/chatnav.c @ fd93b41

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