source: protocols/oscar/chatnav.c @ d7edadf

Last change on this file since d7edadf was d18db32f, checked in by Miklos Vajna <vmiklos@…>, at 2011-12-06T00:53:26Z

oscar: unused-but-set-variables

  • Property mode set to 100644
File size: 10.5 KB
RevLine 
[b7d3cc34]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#include <aim.h>
11#include "chatnav.h"
12
13/*
14 * conn must be a chatnav connection!
15 */
16int aim_chatnav_reqrights(aim_session_t *sess, aim_conn_t *conn)
17{
18        return aim_genericreq_n_snacid(sess, conn, 0x000d, 0x0002);
19}
20
21int aim_chatnav_createroom(aim_session_t *sess, aim_conn_t *conn, const char *name, guint16 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, (guint8 *)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), (guint8 *)name);
65        aim_addtlvtochain_raw(&tl, 0x00d6, strlen(charset), (guint8 *)charset);
66        aim_addtlvtochain_raw(&tl, 0x00d7, strlen(lang), (guint8 *)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        guint8 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 = g_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                 */
[d18db32f]141                if (aim_gettlv(innerlist, 0x0002, 1))
142                        ;
[b7d3cc34]143
144                /*
145                 * Type 0x00c9: Flags
146                 *
147                 * 1 Evilable
148                 * 2 Nav Only
149                 * 4 Instancing Allowed
150                 * 8 Occupant Peek Allowed
151                 *
152                 */ 
153                if (aim_gettlv(innerlist, 0x00c9, 1))
154                        exchanges[curexchange-1].flags = aim_gettlv16(innerlist, 0x00c9, 1);
155                     
156                /*
157                 * Type 0x00ca: Creation Date
158                 */
159                if (aim_gettlv(innerlist, 0x00ca, 1))
160                        ;
161                     
162                /*
163                 * Type 0x00d0: Mandatory Channels?
164                 */
165                if (aim_gettlv(innerlist, 0x00d0, 1))
166                        ;
167
168                /*
169                 * Type 0x00d1: Maximum Message length
170                 */
171                if (aim_gettlv(innerlist, 0x00d1, 1))
172                        ;
173
174                /*
175                 * Type 0x00d2: Maximum Occupancy?
176                 */
177                if (aim_gettlv(innerlist, 0x00d2, 1))   
178                        ;
179
180                /*
181                 * Type 0x00d3: Exchange Description
182                 */
183                if (aim_gettlv(innerlist, 0x00d3, 1))   
184                        exchanges[curexchange-1].name = aim_gettlv_str(innerlist, 0x00d3, 1);
185                else
186                        exchanges[curexchange-1].name = NULL;
187
188                /*
189                 * Type 0x00d4: Exchange Description URL
190                 */
191                if (aim_gettlv(innerlist, 0x00d4, 1))   
192                        ;
193
194                /*
195                 * Type 0x00d5: Creation Permissions
196                 *
197                 * 0  Creation not allowed
198                 * 1  Room creation allowed
199                 * 2  Exchange creation allowed
200                 *
201                 */
[d18db32f]202                if (aim_gettlv(innerlist, 0x00d5, 1))
203                        ;
[b7d3cc34]204
205                /*
206                 * Type 0x00d6: Character Set (First Time)
207                 */           
208                if (aim_gettlv(innerlist, 0x00d6, 1))   
209                        exchanges[curexchange-1].charset1 = aim_gettlv_str(innerlist, 0x00d6, 1);
210                else
211                        exchanges[curexchange-1].charset1 = NULL;
212                     
213                /*
214                 * Type 0x00d7: Language (First Time)
215                 */           
216                if (aim_gettlv(innerlist, 0x00d7, 1))   
217                        exchanges[curexchange-1].lang1 = aim_gettlv_str(innerlist, 0x00d7, 1);
218                else
219                        exchanges[curexchange-1].lang1 = NULL;
220
221                /*
222                 * Type 0x00d8: Character Set (Second Time)
223                 */           
224                if (aim_gettlv(innerlist, 0x00d8, 1))   
225                        exchanges[curexchange-1].charset2 = aim_gettlv_str(innerlist, 0x00d8, 1);
226                else
227                        exchanges[curexchange-1].charset2 = NULL;
228
229                /*
230                 * Type 0x00d9: Language (Second Time)
231                 */           
232                if (aim_gettlv(innerlist, 0x00d9, 1))   
233                        exchanges[curexchange-1].lang2 = aim_gettlv_str(innerlist, 0x00d9, 1);
234                else
235                        exchanges[curexchange-1].lang2 = NULL;
236                     
237                /*
238                 * Type 0x00da: Unknown
239                 */
240                if (aim_gettlv(innerlist, 0x00da, 1))   
241                        ;
242
243                aim_freetlvchain(&innerlist);
244        }
245
246        /*
247         * Call client.
248         */
249        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
250                ret = userfunc(sess, rx, snac2->type, maxrooms, curexchange, exchanges);
251
252        for (curexchange--; curexchange >= 0; curexchange--) {
253                g_free(exchanges[curexchange].name);
254                g_free(exchanges[curexchange].charset1);
255                g_free(exchanges[curexchange].lang1);
256                g_free(exchanges[curexchange].charset2);
257                g_free(exchanges[curexchange].lang2);
258        }
259        g_free(exchanges);
260        aim_freetlvchain(&tlvlist);
261
262        return ret;
263}
264
265static 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)
266{
267        aim_rxcallback_t userfunc;
268        aim_tlvlist_t *tlvlist, *innerlist;
269        char *ck = NULL, *fqcn = NULL, *name = NULL;
270        guint16 exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0;
271        guint32 createtime = 0;
272        guint8 createperms = 0, detaillevel;
273        int cklen;
274        aim_tlv_t *bigblock;
275        int ret = 0;
276        aim_bstream_t bbbs;
277
278        tlvlist = aim_readtlvchain(bs);
279
280        if (!(bigblock = aim_gettlv(tlvlist, 0x0004, 1))) {
[84b045d]281                imcb_error(sess->aux_data, "no bigblock in top tlv in create room response");
[b7d3cc34]282       
283                aim_freetlvchain(&tlvlist);
284                return 0;
285        }
286
287        aim_bstream_init(&bbbs, bigblock->value, bigblock->length);
288
289        exchange = aimbs_get16(&bbbs);
290        cklen = aimbs_get8(&bbbs);
291        ck = aimbs_getstr(&bbbs, cklen);
292        instance = aimbs_get16(&bbbs);
293        detaillevel = aimbs_get8(&bbbs);
294
295        if (detaillevel != 0x02) {
[84b045d]296                imcb_error(sess->aux_data, "unknown detaillevel in create room response");
[b7d3cc34]297                aim_freetlvchain(&tlvlist);
298                g_free(ck);
299                return 0;
300        }
301
302        unknown = aimbs_get16(&bbbs);
303
304        innerlist = aim_readtlvchain(&bbbs);
305
306        if (aim_gettlv(innerlist, 0x006a, 1))
307                fqcn = aim_gettlv_str(innerlist, 0x006a, 1);
308
309        if (aim_gettlv(innerlist, 0x00c9, 1))
310                flags = aim_gettlv16(innerlist, 0x00c9, 1);
311
312        if (aim_gettlv(innerlist, 0x00ca, 1))
313                createtime = aim_gettlv32(innerlist, 0x00ca, 1);
314
315        if (aim_gettlv(innerlist, 0x00d1, 1))
316                maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1);
317
318        if (aim_gettlv(innerlist, 0x00d2, 1))
319                maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1);
320
321        if (aim_gettlv(innerlist, 0x00d3, 1))
322                name = aim_gettlv_str(innerlist, 0x00d3, 1);
323
324        if (aim_gettlv(innerlist, 0x00d5, 1))
325                createperms = aim_gettlv8(innerlist, 0x00d5, 1);
326
327        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
328                ret = userfunc(sess, rx, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
329        }
330
331        g_free(ck);
332        g_free(name);
333        g_free(fqcn);
334        aim_freetlvchain(&innerlist);
335        aim_freetlvchain(&tlvlist);
336
337        return ret;
338}
339
340/*
341 * Since multiple things can trigger this callback, we must lookup the
342 * snacid to determine the original snac subtype that was called.
343 *
344 * XXX This isn't really how this works.  But this is:  Every d/9 response
345 * has a 16bit value at the beginning. That matches to:
346 *    Short Desc = 1
347 *    Full Desc = 2
348 *    Instance Info = 4
349 *    Nav Short Desc = 8
350 *    Nav Instance Info = 16
351 * And then everything is really asynchronous.  There is no specific
352 * attachment of a response to a create room request, for example.  Creating
353 * the room yields no different a response than requesting the room's info.
354 *
355 */
356static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
357{
358        aim_snac_t *snac2;
359        int ret = 0;
360
361        if (!(snac2 = aim_remsnac(sess, snac->id))) {
[84b045d]362                imcb_error(sess->aux_data, "received response to unknown request!");
[b7d3cc34]363                return 0;
364        }
365
366        if (snac2->family != 0x000d) {
[7064d28]367                imcb_error(sess->aux_data, "received response that maps to corrupt request!");
[b7d3cc34]368                return 0;
369        }
370
371        /*
372         * We now know what the original SNAC subtype was.
373         */
374        if (snac2->type == 0x0002) /* request chat rights */
375                ret = parseinfo_perms(sess, mod, rx, snac, bs, snac2);
376        else if (snac2->type == 0x0003) {} /* request exchange info */
377        else if (snac2->type == 0x0004) {} /* request room info */
378        else if (snac2->type == 0x0005) {} /* request more room info */
379        else if (snac2->type == 0x0006) {} /* request occupant list */
380        else if (snac2->type == 0x0007) {} /* search for a room */
381        else if (snac2->type == 0x0008) /* create room */
382                ret = parseinfo_create(sess, mod, rx, snac, bs, snac2);
383        else
[84b045d]384                imcb_error(sess->aux_data, "unknown request subtype");
[b7d3cc34]385
386        if (snac2)
387                g_free(snac2->data);
388        g_free(snac2);
389
390        return ret;
391}
392
393static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
394{
395
396        if (snac->subtype == 0x0009)
397                return parseinfo(sess, mod, rx, snac, bs);
398
399        return 0;
400}
401
402int chatnav_modfirst(aim_session_t *sess, aim_module_t *mod)
403{
404
405        mod->family = 0x000d;
406        mod->version = 0x0003;
407        mod->toolid = 0x0010;
408        mod->toolversion = 0x0629;
409        mod->flags = 0;
410        strncpy(mod->name, "chatnav", sizeof(mod->name));
411        mod->snachandler = snachandler;
412
413        return 0;
414}
Note: See TracBrowser for help on using the repository browser.