source: protocols/oscar/chat.c @ 0b9daac

Last change on this file since 0b9daac was 0b9daac, checked in by dequis <dx@…>, at 2015-02-20T23:16:08Z

Reorganize include files to avoid conflicts with other libs

  • Change all header includes to be relative to the project root
  • Remove -I${includedir} from bitlbee.pc Cflags
  • Install lib and protocols headers to their own directories. So now it is:

/usr/include/bitlbee/*.h
/usr/include/bitlbee/lib/*.h
/usr/include/bitlbee/protocols/*.h

This breaks backwards compatibility of third party plugins, but now
they don't have to do ambiguous includes like #include <proxy.h>

This also fixes trac ticket 1170 - conflicts when libproxy and liboauth
are installed at the same time bitlbee is built, which the macports
project ran into several times.

  • Property mode set to 100644
File size: 14.4 KB
RevLine 
[b7d3cc34]1/*
2 * aim_chat.c
3 *
4 * Routines for the Chat service.
5 *
6 */
7
[0b9daac]8#include "aim.h"
[b7d3cc34]9#include <glib.h>
10#include "info.h"
11
12/* Stored in the ->priv of chat connections */
13struct chatconnpriv {
14        guint16 exchange;
15        char *name;
16        guint16 instance;
17};
18
19void aim_conn_kill_chat(aim_session_t *sess, aim_conn_t *conn)
20{
[5ebff60]21        struct chatconnpriv *ccp = (struct chatconnpriv *) conn->priv;
[b7d3cc34]22
[5ebff60]23        if (ccp) {
[b7d3cc34]24                g_free(ccp->name);
[5ebff60]25        }
[b7d3cc34]26        g_free(ccp);
27
28        return;
29}
30
31/*
32 * Send a Chat Message.
33 *
34 * Possible flags:
35 *   AIM_CHATFLAGS_NOREFLECT   --  Unset the flag that requests messages
36 *                                 should be sent to their sender.
37 *   AIM_CHATFLAGS_AWAY        --  Mark the message as an autoresponse
38 *                                 (Note that WinAIM does not honor this,
39 *                                 and displays the message as normal.)
40 *
[5ebff60]41 * XXX convert this to use tlvchains
[b7d3cc34]42 */
43int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, guint16 flags, const char *msg, int msglen)
[5ebff60]44{
[b7d3cc34]45        int i;
46        aim_frame_t *fr;
47        aim_msgcookie_t *cookie;
48        aim_snacid_t snacid;
49        guint8 ckstr[8];
50        aim_tlvlist_t *otl = NULL, *itl = NULL;
51
[5ebff60]52        if (!sess || !conn || !msg || (msglen <= 0)) {
[b7d3cc34]53                return 0;
[5ebff60]54        }
[b7d3cc34]55
[5ebff60]56        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) {
[b7d3cc34]57                return -ENOMEM;
[5ebff60]58        }
[b7d3cc34]59
60        snacid = aim_cachesnac(sess, 0x000e, 0x0005, 0x0000, NULL, 0);
61        aim_putsnac(&fr->data, 0x000e, 0x0005, 0x0000, snacid);
62
63
[5ebff60]64        /*
[b7d3cc34]65         * Generate a random message cookie.
66         *
67         * XXX mkcookie should generate the cookie and cache it in one
68         * operation to preserve uniqueness.
69         *
70         */
[5ebff60]71        for (i = 0; i < sizeof(ckstr); i++) {
72                (void) aimutil_put8(ckstr + i, (guint8) rand());
73        }
74
[b7d3cc34]75
76        cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL);
77        cookie->data = NULL; /* XXX store something useful here */
78
79        aim_cachecookie(sess, cookie);
80
[5ebff60]81        for (i = 0; i < sizeof(ckstr); i++) {
[b7d3cc34]82                aimbs_put8(&fr->data, ckstr[i]);
[5ebff60]83        }
[b7d3cc34]84
85
86        /*
[5ebff60]87         * Channel ID.
[b7d3cc34]88         */
89        aimbs_put16(&fr->data, 0x0003);
90
91
92        /*
93         * Type 1: Flag meaning this message is destined to the room.
94         */
95        aim_addtlvtochain_noval(&otl, 0x0001);
96
97        /*
98         * Type 6: Reflect
99         */
[5ebff60]100        if (!(flags & AIM_CHATFLAGS_NOREFLECT)) {
[b7d3cc34]101                aim_addtlvtochain_noval(&otl, 0x0006);
[5ebff60]102        }
[b7d3cc34]103
104        /*
105         * Type 7: Autoresponse
106         */
[5ebff60]107        if (flags & AIM_CHATFLAGS_AWAY) {
[b7d3cc34]108                aim_addtlvtochain_noval(&otl, 0x0007);
[5ebff60]109        }
110
[73cf7fd]111        /* [WvG] This wasn't there originally, but we really should send
112                 the right charset flags, as we also do with normal
113                 messages. Hope this will work. :-) */
[936ded6]114        /*
[73cf7fd]115        if (flags & AIM_CHATFLAGS_UNICODE)
[5ebff60]116                aimbs_put16(&fr->data, 0x0002);
[73cf7fd]117        else if (flags & AIM_CHATFLAGS_ISO_8859_1)
[5ebff60]118                aimbs_put16(&fr->data, 0x0003);
[73cf7fd]119        else
[5ebff60]120                aimbs_put16(&fr->data, 0x0000);
121
[73cf7fd]122        aimbs_put16(&fr->data, 0x0000);
[936ded6]123        */
[5ebff60]124
[b7d3cc34]125        /*
126         * SubTLV: Type 1: Message
127         */
[5ebff60]128        aim_addtlvtochain_raw(&itl, 0x0001, strlen(msg), (guint8 *) msg);
[b7d3cc34]129
130        /*
131         * Type 5: Message block.  Contains more TLVs.
132         *
133         * This could include other information... We just
[5ebff60]134         * put in a message TLV however.
135         *
[b7d3cc34]136         */
137        aim_addtlvtochain_frozentlvlist(&otl, 0x0005, &itl);
138
139        aim_writetlvchain(&fr->data, &otl);
[5ebff60]140
[b7d3cc34]141        aim_freetlvchain(&itl);
142        aim_freetlvchain(&otl);
[5ebff60]143
[b7d3cc34]144        aim_tx_enqueue(sess, fr);
145
146        return 0;
147}
148
149/*
[5ebff60]150 * Join a room of name roomname.  This is the first step to joining an
151 * already created room.  It's basically a Service Request for
152 * family 0x000e, with a little added on to specify the exchange and room
[b7d3cc34]153 * name.
154 */
155int aim_chat_join(aim_session_t *sess, aim_conn_t *conn, guint16 exchange, const char *roomname, guint16 instance)
156{
157        aim_frame_t *fr;
158        aim_snacid_t snacid;
159        aim_tlvlist_t *tl = NULL;
160        struct chatsnacinfo csi;
[5ebff60]161
162        if (!sess || !conn || !roomname || !strlen(roomname)) {
[b7d3cc34]163                return -EINVAL;
[5ebff60]164        }
[b7d3cc34]165
[5ebff60]166        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512))) {
[b7d3cc34]167                return -ENOMEM;
[5ebff60]168        }
[b7d3cc34]169
170        memset(&csi, 0, sizeof(csi));
171        csi.exchange = exchange;
172        strncpy(csi.name, roomname, sizeof(csi.name));
173        csi.instance = instance;
174
175        snacid = aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, &csi, sizeof(csi));
176        aim_putsnac(&fr->data, 0x0001, 0x0004, 0x0000, snacid);
177
178        /*
179         * Requesting service chat (0x000e)
180         */
181        aimbs_put16(&fr->data, 0x000e);
182
183        aim_addtlvtochain_chatroom(&tl, 0x0001, exchange, roomname, instance);
184        aim_writetlvchain(&fr->data, &tl);
185        aim_freetlvchain(&tl);
186
187        aim_tx_enqueue(sess, fr);
188
[5ebff60]189        return 0;
[b7d3cc34]190}
191
192int aim_chat_readroominfo(aim_bstream_t *bs, struct aim_chat_roominfo *outinfo)
193{
194        int namelen;
195
[5ebff60]196        if (!bs || !outinfo) {
[b7d3cc34]197                return 0;
[5ebff60]198        }
[b7d3cc34]199
200        outinfo->exchange = aimbs_get16(bs);
201        namelen = aimbs_get8(bs);
202        outinfo->name = aimbs_getstr(bs, namelen);
203        outinfo->instance = aimbs_get16(bs);
204
205        return 0;
206}
207
208/*
209 * conn must be a BOS connection!
210 */
[5ebff60]211int aim_chat_invite(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *msg, guint16 exchange,
212                    const char *roomname, guint16 instance)
[b7d3cc34]213{
214        int i;
215        aim_frame_t *fr;
216        aim_msgcookie_t *cookie;
217        struct aim_invite_priv *priv;
218        guint8 ckstr[8];
219        aim_snacid_t snacid;
220        aim_tlvlist_t *otl = NULL, *itl = NULL;
221        guint8 *hdr;
222        int hdrlen;
223        aim_bstream_t hdrbs;
[5ebff60]224
225        if (!sess || !conn || !sn || !msg || !roomname) {
[b7d3cc34]226                return -EINVAL;
[5ebff60]227        }
[b7d3cc34]228
[5ebff60]229        if (conn->type != AIM_CONN_TYPE_BOS) {
[b7d3cc34]230                return -EINVAL;
[5ebff60]231        }
[b7d3cc34]232
[5ebff60]233        if (!(fr =
234                      aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152 + strlen(sn) + strlen(roomname) +
235                                 strlen(msg)))) {
[b7d3cc34]236                return -ENOMEM;
[5ebff60]237        }
[b7d3cc34]238
[5ebff60]239        snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, sn, strlen(sn) + 1);
[b7d3cc34]240        aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
241
242
243        /*
244         * Cookie
245         */
[5ebff60]246        for (i = 0; i < sizeof(ckstr); i++) {
[8519f45]247                (void) aimutil_put8(ckstr, (guint8) rand());
[5ebff60]248        }
[b7d3cc34]249
250        /* XXX should be uncached by an unwritten 'invite accept' handler */
251        if ((priv = g_malloc(sizeof(struct aim_invite_priv)))) {
252                priv->sn = g_strdup(sn);
253                priv->roomname = g_strdup(roomname);
254                priv->exchange = exchange;
255                priv->instance = instance;
256        }
257
[5ebff60]258        if ((cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_INVITE, priv))) {
[b7d3cc34]259                aim_cachecookie(sess, cookie);
[5ebff60]260        } else {
[b7d3cc34]261                g_free(priv);
[5ebff60]262        }
[b7d3cc34]263
[5ebff60]264        for (i = 0; i < sizeof(ckstr); i++) {
[b7d3cc34]265                aimbs_put8(&fr->data, ckstr[i]);
[5ebff60]266        }
[b7d3cc34]267
268
269        /*
270         * Channel (2)
271         */
272        aimbs_put16(&fr->data, 0x0002);
273
274        /*
275         * Dest sn
276         */
277        aimbs_put8(&fr->data, strlen(sn));
[5ebff60]278        aimbs_putraw(&fr->data, (guint8 *) sn, strlen(sn));
[b7d3cc34]279
280        /*
281         * TLV t(0005)
282         *
283         * Everything else is inside this TLV.
284         *
285         * Sigh.  AOL was rather inconsistent right here.  So we have
286         * to play some minor tricks.  Right inside the type 5 is some
[5ebff60]287         * raw data, followed by a series of TLVs.
[b7d3cc34]288         *
289         */
[5ebff60]290        hdrlen = 2 + 8 + 16 + 6 + 4 + 4 + strlen(msg) + 4 + 2 + 1 + strlen(roomname) + 2;
[b7d3cc34]291        hdr = g_malloc(hdrlen);
292        aim_bstream_init(&hdrbs, hdr, hdrlen);
[5ebff60]293
[b7d3cc34]294        aimbs_put16(&hdrbs, 0x0000); /* Unknown! */
295        aimbs_putraw(&hdrbs, ckstr, sizeof(ckstr)); /* I think... */
296        aim_putcap(&hdrbs, AIM_CAPS_CHAT);
297
298        aim_addtlvtochain16(&itl, 0x000a, 0x0001);
299        aim_addtlvtochain_noval(&itl, 0x000f);
[5ebff60]300        aim_addtlvtochain_raw(&itl, 0x000c, strlen(msg), (guint8 *) msg);
[b7d3cc34]301        aim_addtlvtochain_chatroom(&itl, 0x2711, exchange, roomname, instance);
302        aim_writetlvchain(&hdrbs, &itl);
[5ebff60]303
[b7d3cc34]304        aim_addtlvtochain_raw(&otl, 0x0005, aim_bstream_curpos(&hdrbs), hdr);
305
306        aim_writetlvchain(&fr->data, &otl);
307
308        g_free(hdr);
309        aim_freetlvchain(&itl);
310        aim_freetlvchain(&otl);
[5ebff60]311
[b7d3cc34]312        aim_tx_enqueue(sess, fr);
313
314        return 0;
315}
316
317/*
318 * General room information.  Lots of stuff.
319 *
320 * Values I know are in here but I havent attached
321 * them to any of the 'Unknown's:
322 *      - Language (English)
323 *
324 * SNAC 000e/0002
325 */
326static int infoupdate(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
327{
328        aim_userinfo_t *userinfo = NULL;
329        aim_rxcallback_t userfunc;
330        int ret = 0;
331        int usercount = 0;
332        guint8 detaillevel = 0;
333        char *roomname = NULL;
334        struct aim_chat_roominfo roominfo;
335        aim_tlvlist_t *tlvlist;
336        char *roomdesc = NULL;
337        guint16 flags = 0;
338        guint32 creationtime = 0;
339        guint16 maxmsglen = 0, maxvisiblemsglen = 0;
340        guint16 unknown_d2 = 0, unknown_d5 = 0;
341
342        aim_chat_readroominfo(bs, &roominfo);
343
344        detaillevel = aimbs_get8(bs);
345
346        if (detaillevel != 0x02) {
[84b045d]347                imcb_error(sess->aux_data, "Only detaillevel 0x2 is support at the moment");
[b7d3cc34]348                return 1;
349        }
350
[d18db32f]351        aimbs_get16(bs); /* tlv count */
[b7d3cc34]352
353        /*
354         * Everything else are TLVs.
[5ebff60]355         */
[b7d3cc34]356        tlvlist = aim_readtlvchain(bs);
357
358        /*
359         * TLV type 0x006a is the room name in Human Readable Form.
360         */
[5ebff60]361        if (aim_gettlv(tlvlist, 0x006a, 1)) {
[b7d3cc34]362                roomname = aim_gettlv_str(tlvlist, 0x006a, 1);
[5ebff60]363        }
[b7d3cc34]364
365        /*
366         * Type 0x006f: Number of occupants.
367         */
[5ebff60]368        if (aim_gettlv(tlvlist, 0x006f, 1)) {
[b7d3cc34]369                usercount = aim_gettlv16(tlvlist, 0x006f, 1);
[5ebff60]370        }
[b7d3cc34]371
372        /*
373         * Type 0x0073:  Occupant list.
374         */
[5ebff60]375        if (aim_gettlv(tlvlist, 0x0073, 1)) {
[b7d3cc34]376                int curoccupant = 0;
377                aim_tlv_t *tmptlv;
378                aim_bstream_t occbs;
379
380                tmptlv = aim_gettlv(tlvlist, 0x0073, 1);
381
382                /* Allocate enough userinfo structs for all occupants */
383                userinfo = g_new0(aim_userinfo_t, usercount);
384
385                aim_bstream_init(&occbs, tmptlv->value, tmptlv->length);
386
[5ebff60]387                while (curoccupant < usercount) {
[b7d3cc34]388                        aim_extractuserinfo(sess, &occbs, &userinfo[curoccupant++]);
[5ebff60]389                }
[b7d3cc34]390        }
391
[5ebff60]392        /*
[b7d3cc34]393         * Type 0x00c9: Flags. (AIM_CHATROOM_FLAG)
394         */
[5ebff60]395        if (aim_gettlv(tlvlist, 0x00c9, 1)) {
[b7d3cc34]396                flags = aim_gettlv16(tlvlist, 0x00c9, 1);
[5ebff60]397        }
[b7d3cc34]398
[5ebff60]399        /*
[b7d3cc34]400         * Type 0x00ca: Creation time (4 bytes)
401         */
[5ebff60]402        if (aim_gettlv(tlvlist, 0x00ca, 1)) {
[b7d3cc34]403                creationtime = aim_gettlv32(tlvlist, 0x00ca, 1);
[5ebff60]404        }
[b7d3cc34]405
[5ebff60]406        /*
[b7d3cc34]407         * Type 0x00d1: Maximum Message Length
408         */
[5ebff60]409        if (aim_gettlv(tlvlist, 0x00d1, 1)) {
[b7d3cc34]410                maxmsglen = aim_gettlv16(tlvlist, 0x00d1, 1);
[5ebff60]411        }
[b7d3cc34]412
[5ebff60]413        /*
[b7d3cc34]414         * Type 0x00d2: Unknown. (2 bytes)
415         */
[5ebff60]416        if (aim_gettlv(tlvlist, 0x00d2, 1)) {
[b7d3cc34]417                unknown_d2 = aim_gettlv16(tlvlist, 0x00d2, 1);
[5ebff60]418        }
[b7d3cc34]419
[5ebff60]420        /*
[b7d3cc34]421         * Type 0x00d3: Room Description
422         */
[5ebff60]423        if (aim_gettlv(tlvlist, 0x00d3, 1)) {
[b7d3cc34]424                roomdesc = aim_gettlv_str(tlvlist, 0x00d3, 1);
[5ebff60]425        }
[b7d3cc34]426
427        /*
428         * Type 0x000d4: Unknown (flag only)
429         */
[5ebff60]430        if (aim_gettlv(tlvlist, 0x000d4, 1)) {
[b7d3cc34]431                ;
[5ebff60]432        }
[b7d3cc34]433
[5ebff60]434        /*
[b7d3cc34]435         * Type 0x00d5: Unknown. (1 byte)
436         */
[5ebff60]437        if (aim_gettlv(tlvlist, 0x00d5, 1)) {
[b7d3cc34]438                unknown_d5 = aim_gettlv8(tlvlist, 0x00d5, 1);
[5ebff60]439        }
[b7d3cc34]440
441
442        /*
443         * Type 0x00d6: Encoding 1 ("us-ascii")
444         */
[5ebff60]445        if (aim_gettlv(tlvlist, 0x000d6, 1)) {
[b7d3cc34]446                ;
[5ebff60]447        }
448
[b7d3cc34]449        /*
450         * Type 0x00d7: Language 1 ("en")
451         */
[5ebff60]452        if (aim_gettlv(tlvlist, 0x000d7, 1)) {
[b7d3cc34]453                ;
[5ebff60]454        }
[b7d3cc34]455
456        /*
457         * Type 0x00d8: Encoding 2 ("us-ascii")
458         */
[5ebff60]459        if (aim_gettlv(tlvlist, 0x000d8, 1)) {
[b7d3cc34]460                ;
[5ebff60]461        }
462
[b7d3cc34]463        /*
464         * Type 0x00d9: Language 2 ("en")
465         */
[5ebff60]466        if (aim_gettlv(tlvlist, 0x000d9, 1)) {
[b7d3cc34]467                ;
[5ebff60]468        }
[b7d3cc34]469
470        /*
471         * Type 0x00da: Maximum visible message length
472         */
[5ebff60]473        if (aim_gettlv(tlvlist, 0x000da, 1)) {
[b7d3cc34]474                maxvisiblemsglen = aim_gettlv16(tlvlist, 0x00da, 1);
[5ebff60]475        }
[b7d3cc34]476
477        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
478                ret = userfunc(sess,
[5ebff60]479                               rx,
480                               &roominfo,
481                               roomname,
482                               usercount,
483                               userinfo,
484                               roomdesc,
485                               flags,
486                               creationtime,
487                               maxmsglen,
488                               unknown_d2,
489                               unknown_d5,
490                               maxvisiblemsglen);
[b7d3cc34]491        }
492
493        g_free(roominfo.name);
494        g_free(userinfo);
495        g_free(roomname);
496        g_free(roomdesc);
497        aim_freetlvchain(&tlvlist);
498
499        return ret;
500}
501
[5ebff60]502static int userlistchange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac,
503                          aim_bstream_t *bs)
[b7d3cc34]504{
505        aim_userinfo_t *userinfo = NULL;
506        aim_rxcallback_t userfunc;
507        int curcount = 0, ret = 0;
508
509        while (aim_bstream_empty(bs)) {
510                curcount++;
511                userinfo = g_realloc(userinfo, curcount * sizeof(aim_userinfo_t));
[5ebff60]512                aim_extractuserinfo(sess, bs, &userinfo[curcount - 1]);
[b7d3cc34]513        }
514
[5ebff60]515        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
[b7d3cc34]516                ret = userfunc(sess, rx, curcount, userinfo);
[5ebff60]517        }
[b7d3cc34]518
519        g_free(userinfo);
520
521        return ret;
522}
523
524/*
[5ebff60]525 * We could probably include this in the normal ICBM parsing
[b7d3cc34]526 * code as channel 0x0003, however, since only the start
527 * would be the same, we might as well do it here.
528 *
529 * General outline of this SNAC:
530 *   snac
531 *   cookie
532 *   channel id
533 *   tlvlist
534 *     unknown
535 *     source user info
536 *       name
537 *       evility
538 *       userinfo tlvs
539 *         online time
540 *         etc
541 *     message metatlv
542 *       message tlv
543 *         message string
544 *       possibly others
[5ebff60]545 *
[b7d3cc34]546 */
547static int incomingmsg(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
548{
549        aim_userinfo_t userinfo;
[5ebff60]550        aim_rxcallback_t userfunc;
[b7d3cc34]551        int ret = 0;
552        guint8 *cookie;
553        guint16 channel;
554        aim_tlvlist_t *otl;
555        char *msg = NULL;
556        aim_msgcookie_t *ck;
557
558        memset(&userinfo, 0, sizeof(aim_userinfo_t));
559
560        /*
561         * ICBM Cookie.  Uncache it.
562         */
563        cookie = aimbs_getraw(bs, 8);
564
565        if ((ck = aim_uncachecookie(sess, cookie, AIM_COOKIETYPE_CHAT))) {
566                g_free(ck->data);
567                g_free(ck);
568        }
569
570        /*
571         * Channel ID
572         *
573         * Channels 1 and 2 are implemented in the normal ICBM
574         * parser.
575         *
576         * We only do channel 3 here.
577         *
578         */
579        channel = aimbs_get16(bs);
580
581        if (channel != 0x0003) {
[84b045d]582                imcb_error(sess->aux_data, "unknown channel!");
[b7d3cc34]583                return 0;
584        }
585
586        /*
[5ebff60]587         * Start parsing TLVs right away.
[b7d3cc34]588         */
589        otl = aim_readtlvchain(bs);
590
591        /*
592         * Type 0x0003: Source User Information
593         */
594        if (aim_gettlv(otl, 0x0003, 1)) {
595                aim_tlv_t *userinfotlv;
596                aim_bstream_t tbs;
597
598                userinfotlv = aim_gettlv(otl, 0x0003, 1);
599
600                aim_bstream_init(&tbs, userinfotlv->value, userinfotlv->length);
601                aim_extractuserinfo(sess, &tbs, &userinfo);
602        }
603
604        /*
[5ebff60]605         * Type 0x0001: If present, it means it was a message to the
[b7d3cc34]606         * room (as opposed to a whisper).
607         */
[5ebff60]608        if (aim_gettlv(otl, 0x0001, 1)) {
[b7d3cc34]609                ;
[5ebff60]610        }
[b7d3cc34]611
612        /*
613         * Type 0x0005: Message Block.  Conains more TLVs.
614         */
615        if (aim_gettlv(otl, 0x0005, 1)) {
616                aim_tlvlist_t *itl;
617                aim_tlv_t *msgblock;
618                aim_bstream_t tbs;
619
620                msgblock = aim_gettlv(otl, 0x0005, 1);
621                aim_bstream_init(&tbs, msgblock->value, msgblock->length);
622                itl = aim_readtlvchain(&tbs);
623
[5ebff60]624                /*
[b7d3cc34]625                 * Type 0x0001: Message.
[5ebff60]626                 */
627                if (aim_gettlv(itl, 0x0001, 1)) {
[b7d3cc34]628                        msg = aim_gettlv_str(itl, 0x0001, 1);
[5ebff60]629                }
[b7d3cc34]630
[5ebff60]631                aim_freetlvchain(&itl);
[b7d3cc34]632        }
633
[5ebff60]634        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
[b7d3cc34]635                ret = userfunc(sess, rx, &userinfo, msg);
[5ebff60]636        }
[b7d3cc34]637
638        g_free(cookie);
639        g_free(msg);
640        aim_freetlvchain(&otl);
641
642        return ret;
643}
644
645static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
646{
647
[5ebff60]648        if (snac->subtype == 0x0002) {
[b7d3cc34]649                return infoupdate(sess, mod, rx, snac, bs);
[5ebff60]650        } else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004)) {
[b7d3cc34]651                return userlistchange(sess, mod, rx, snac, bs);
[5ebff60]652        } else if (snac->subtype == 0x0006) {
[b7d3cc34]653                return incomingmsg(sess, mod, rx, snac, bs);
[5ebff60]654        }
[b7d3cc34]655
656        return 0;
657}
658
659int chat_modfirst(aim_session_t *sess, aim_module_t *mod)
660{
661
662        mod->family = 0x000e;
663        mod->version = 0x0001;
664        mod->toolid = 0x0010;
665        mod->toolversion = 0x0629;
666        mod->flags = 0;
667        strncpy(mod->name, "chat", sizeof(mod->name));
668        mod->snachandler = snachandler;
669
670        return 0;
671}
Note: See TracBrowser for help on using the repository browser.