source: protocols/oscar/info.c @ b7d3cc34

0.99
Last change on this file since b7d3cc34 was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 17.0 KB
Line 
1/*
2 * aim_info.c
3 *
4 * The functions here are responsible for requesting and parsing information-
5 * gathering SNACs.  Or something like that.
6 *
7 */
8
9#include <aim.h>
10#include "info.h"
11
12struct aim_priv_inforeq {
13        char sn[MAXSNLEN+1];
14        guint16 infotype;
15};
16
17int aim_getinfo(aim_session_t *sess, aim_conn_t *conn, const char *sn, guint16 infotype)
18{
19        struct aim_priv_inforeq privdata;
20        aim_frame_t *fr;
21        aim_snacid_t snacid;
22
23        if (!sess || !conn || !sn)
24                return -EINVAL;
25
26        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn))))
27                return -ENOMEM;
28
29        strncpy(privdata.sn, sn, sizeof(privdata.sn));
30        privdata.infotype = infotype;
31        snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq));
32       
33        aim_putsnac(&fr->data, 0x0002, 0x0005, 0x0000, snacid);
34        aimbs_put16(&fr->data, infotype);
35        aimbs_put8(&fr->data, strlen(sn));
36        aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
37
38        aim_tx_enqueue(sess, fr);
39
40        return 0;
41}
42
43const char *aim_userinfo_sn(aim_userinfo_t *ui)
44{
45
46        if (!ui)
47                return NULL;
48
49        return ui->sn;
50}
51
52guint16 aim_userinfo_flags(aim_userinfo_t *ui)
53{
54
55        if (!ui)
56                return 0;
57
58        return ui->flags;
59}
60
61guint16 aim_userinfo_idle(aim_userinfo_t *ui)
62{
63
64        if (!ui)
65                return 0;
66
67        return ui->idletime;
68}
69
70float aim_userinfo_warnlevel(aim_userinfo_t *ui)
71{
72
73        if (!ui)
74                return 0.00;
75
76        return (ui->warnlevel / 10);
77}
78
79time_t aim_userinfo_membersince(aim_userinfo_t *ui)
80{
81
82        if (!ui)
83                return 0;
84
85        return (time_t)ui->membersince;
86}
87
88time_t aim_userinfo_onlinesince(aim_userinfo_t *ui)
89{
90
91        if (!ui)
92                return 0;
93
94        return (time_t)ui->onlinesince;
95}
96
97guint32 aim_userinfo_sessionlen(aim_userinfo_t *ui)
98{
99
100        if (!ui)
101                return 0;
102
103        return ui->sessionlen;
104}
105
106int aim_userinfo_hascap(aim_userinfo_t *ui, guint32 cap)
107{
108
109        if (!ui || !(ui->present & AIM_USERINFO_PRESENT_CAPABILITIES))
110                return -1;
111
112        return !!(ui->capabilities & cap);
113}
114
115
116/*
117 * Capability blocks.
118 *
119 * These are CLSIDs. They should actually be of the form:
120 *
121 * {0x0946134b, 0x4c7f, 0x11d1,
122 *  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
123 *
124 * But, eh.
125 */
126static const struct {
127        guint32 flag;
128        guint8 data[16];
129} aim_caps[] = {
130
131        /*
132         * Chat is oddball.
133         */
134        {AIM_CAPS_CHAT,
135         {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1, 
136          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
137
138        /*
139         * These are mostly in order.
140         */
141        {AIM_CAPS_VOICE,
142         {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1, 
143          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
144
145        {AIM_CAPS_SENDFILE,
146         {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, 
147          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
148
149        /*
150         * Advertised by the EveryBuddy client.
151         */
152        {AIM_CAPS_ICQ,
153         {0x09, 0x46, 0x13, 0x44, 0x4c, 0x7f, 0x11, 0xd1, 
154          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
155
156        {AIM_CAPS_IMIMAGE,
157         {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1, 
158          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
159
160        {AIM_CAPS_BUDDYICON,
161         {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1, 
162          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
163
164        {AIM_CAPS_SAVESTOCKS,
165         {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
166          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
167
168        {AIM_CAPS_GETFILE,
169         {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
170          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
171
172    /*
173     * Client supports channel 2 extended, TLV(0x2711) based messages.
174     * Currently used only by ICQ clients. ICQ clients and clones use this GUID
175     * as message format sign. Trillian client use another GUID in channel 2
176     * messages to implement its own message format (trillian doesn't use
177     * TLV(x2711) in SecureIM channel 2 messages!).
178     */
179        {AIM_CAPS_ICQSERVERRELAY,
180         {0x09, 0x46, 0x13, 0x49, 0x4c, 0x7f, 0x11, 0xd1,
181          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
182
183        /*
184         * Indeed, there are two of these.  The former appears to be correct,
185         * but in some versions of winaim, the second one is set.  Either they
186         * forgot to fix endianness, or they made a typo. It really doesn't
187         * matter which.
188         */
189        {AIM_CAPS_GAMES,
190         {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
191          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
192        {AIM_CAPS_GAMES2,
193         {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
194          0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
195
196        {AIM_CAPS_SENDBUDDYLIST,
197         {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1,
198          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
199
200        {AIM_CAPS_UTF8,
201         {0x09, 0x46, 0x13, 0x4E, 0x4C, 0x7F, 0x11, 0xD1,
202          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
203
204        {AIM_CAPS_ICQRTF,
205         {0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34, 
206          0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}},
207
208        {AIM_CAPS_ICQUNKNOWN,
209         {0x2e, 0x7a, 0x64, 0x75, 0xfa, 0xdf, 0x4d, 0xc8,
210          0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}},
211
212        {AIM_CAPS_EMPTY,
213         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
215
216        {AIM_CAPS_TRILLIANCRYPT,
217         {0xf2, 0xe7, 0xc7, 0xf4, 0xfe, 0xad, 0x4d, 0xfb,
218          0xb2, 0x35, 0x36, 0x79, 0x8b, 0xdf, 0x00, 0x00}},
219
220        {AIM_CAPS_APINFO, 
221     {0xAA, 0x4A, 0x32, 0xB5, 0xF8, 0x84, 0x48, 0xc6,
222      0xA3, 0xD7, 0x8C, 0x50, 0x97, 0x19, 0xFD, 0x5B}},
223
224        {AIM_CAPS_INTEROP,
225         {0x09, 0x46, 0x13, 0x4d, 0x4c, 0x7f, 0x11, 0xd1,
226          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
227
228        {AIM_CAPS_ICHAT,
229         {0x09, 0x46, 0x00, 0x00, 0x4c, 0x7f, 0x11, 0xd1, 
230          0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
231
232        {AIM_CAPS_LAST}
233};
234
235/*
236 * This still takes a length parameter even with a bstream because capabilities
237 * are not naturally bounded.
238 *
239 */
240guint32 aim_getcap(aim_session_t *sess, aim_bstream_t *bs, int len)
241{
242        guint32 flags = 0;
243        int offset;
244
245        for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x10) {
246                guint8 *cap;
247                int i, identified;
248
249                cap = aimbs_getraw(bs, 0x10);
250
251                for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) {
252
253                        if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) {
254                                flags |= aim_caps[i].flag;
255                                identified++;
256                                break; /* should only match once... */
257
258                        }
259                }
260
261                if (!identified) {
262                        /*FIXME*/
263                        g_strdup_printf("unknown capability: {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
264                                        cap[0], cap[1], cap[2], cap[3],
265                                        cap[4], cap[5],
266                                        cap[6], cap[7],
267                                        cap[8], cap[9],
268                                        cap[10], cap[11], cap[12], cap[13],
269                                        cap[14], cap[15]);
270                       
271                }
272
273                g_free(cap);
274        }
275
276        return flags;
277}
278
279int aim_putcap(aim_bstream_t *bs, guint32 caps)
280{
281        int i;
282
283        if (!bs)
284                return -EINVAL;
285
286        for (i = 0; aim_bstream_empty(bs); i++) {
287
288                if (aim_caps[i].flag == AIM_CAPS_LAST)
289                        break;
290
291                if (caps & aim_caps[i].flag)
292                        aimbs_putraw(bs, aim_caps[i].data, 0x10);
293
294        }
295
296        return 0;
297}
298
299/*
300 * AIM is fairly regular about providing user info.  This is a generic
301 * routine to extract it in its standard form.
302 */
303int aim_extractuserinfo(aim_session_t *sess, aim_bstream_t *bs, aim_userinfo_t *outinfo)
304{
305        int curtlv, tlvcnt;
306        guint8 snlen;
307
308        if (!bs || !outinfo)
309                return -EINVAL;
310
311        /* Clear out old data first */
312        memset(outinfo, 0x00, sizeof(aim_userinfo_t));
313
314        /*
315         * Screen name.  Stored as an unterminated string prepended with a
316         * byte containing its length.
317         */
318        snlen = aimbs_get8(bs);
319        aimbs_getrawbuf(bs, (guint8 *)outinfo->sn, snlen);
320
321        /*
322         * Warning Level.  Stored as an unsigned short.
323         */
324        outinfo->warnlevel = aimbs_get16(bs);
325
326        /*
327         * TLV Count. Unsigned short representing the number of
328         * Type-Length-Value triples that follow.
329         */
330        tlvcnt = aimbs_get16(bs);
331
332        /*
333         * Parse out the Type-Length-Value triples as they're found.
334         */
335        for (curtlv = 0; curtlv < tlvcnt; curtlv++) {
336                int endpos;
337                guint16 type, length;
338
339                type = aimbs_get16(bs);
340                length = aimbs_get16(bs);
341
342                endpos = aim_bstream_curpos(bs) + length;
343
344                if (type == 0x0001) {
345                        /*
346                         * Type = 0x0001: User flags
347                         *
348                         * Specified as any of the following ORed together:
349                         *      0x0001  Trial (user less than 60days)
350                         *      0x0002  Unknown bit 2
351                         *      0x0004  AOL Main Service user
352                         *      0x0008  Unknown bit 4
353                         *      0x0010  Free (AIM) user
354                         *      0x0020  Away
355                         *      0x0400  ActiveBuddy
356                         *
357                         */
358                        outinfo->flags = aimbs_get16(bs);
359                        outinfo->present |= AIM_USERINFO_PRESENT_FLAGS;
360
361                } else if (type == 0x0002) {
362                        /*
363                         * Type = 0x0002: Member-Since date.
364                         *
365                         * The time/date that the user originally registered for
366                         * the service, stored in time_t format.
367                         */
368                        outinfo->membersince = aimbs_get32(bs);
369                        outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE;
370
371                } else if (type == 0x0003) {
372                        /*
373                         * Type = 0x0003: On-Since date.
374                         *
375                         * The time/date that the user started their current
376                         * session, stored in time_t format.
377                         */
378                        outinfo->onlinesince = aimbs_get32(bs);
379                        outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE;
380
381                } else if (type == 0x0004) {
382                        /*
383                         * Type = 0x0004: Idle time.
384                         *
385                         * Number of seconds since the user actively used the
386                         * service.
387                         *
388                         * Note that the client tells the server when to start
389                         * counting idle times, so this may or may not be
390                         * related to reality.
391                         */
392                        outinfo->idletime = aimbs_get16(bs);
393                        outinfo->present |= AIM_USERINFO_PRESENT_IDLE;
394
395                } else if (type == 0x0006) {
396                        /*
397                         * Type = 0x0006: ICQ Online Status
398                         *
399                         * ICQ's Away/DND/etc "enriched" status. Some decoding
400                         * of values done by Scott <darkagl@pcnet.com>
401                         */
402                        aimbs_get16(bs);
403                        outinfo->icqinfo.status = aimbs_get16(bs);
404                        outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS;
405
406                } else if (type == 0x000a) {
407                        /*
408                         * Type = 0x000a
409                         *
410                         * ICQ User IP Address.
411                         * Ahh, the joy of ICQ security.
412                         */
413                        outinfo->icqinfo.ipaddr = aimbs_get32(bs);
414                        outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR;
415
416                } else if (type == 0x000c) {
417                        /*
418                         * Type = 0x000c
419                         *
420                         * random crap containing the IP address,
421                         * apparently a port number, and some Other Stuff.
422                         *
423                         */
424                        aimbs_getrawbuf(bs, outinfo->icqinfo.crap, 0x25);
425                        outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA;
426
427                } else if (type == 0x000d) {
428                        /*
429                         * Type = 0x000d
430                         *
431                         * Capability information.
432                         *
433                         */
434                        outinfo->capabilities = aim_getcap(sess, bs, length);
435                        outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;
436
437                } else if (type == 0x000e) {
438                        /*
439                         * Type = 0x000e
440                         *
441                         * Unknown.  Always of zero length, and always only
442                         * on AOL users.
443                         *
444                         * Ignore.
445                         *
446                         */
447
448                } else if ((type == 0x000f) || (type == 0x0010)) {
449                        /*
450                         * Type = 0x000f: Session Length. (AIM)
451                         * Type = 0x0010: Session Length. (AOL)
452                         *
453                         * The duration, in seconds, of the user's current
454                         * session.
455                         *
456                         * Which TLV type this comes in depends on the
457                         * service the user is using (AIM or AOL).
458                         *
459                         */
460                        outinfo->sessionlen = aimbs_get32(bs);
461                        outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN;
462
463                } else {
464
465                        /*
466                         * Reaching here indicates that either AOL has
467                         * added yet another TLV for us to deal with,
468                         * or the parsing has gone Terribly Wrong.
469                         *
470                         * Either way, inform the owner and attempt
471                         * recovery.
472                         *
473                         */
474#ifdef DEBUG
475                        // do_error_dialog(sess->aux_data, G_STRLOC, "Unknown TLV encountered");
476#endif
477
478                }
479
480                /* Save ourselves. */
481                aim_bstream_setpos(bs, endpos);
482        }
483
484        return 0;
485}
486
487/*
488 * Inverse of aim_extractuserinfo()
489 */
490int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info)
491{
492        aim_tlvlist_t *tlvlist = NULL;
493
494        if (!bs || !info)
495                return -EINVAL;
496
497        aimbs_put8(bs, strlen(info->sn));
498        aimbs_putraw(bs, (guint8 *)info->sn, strlen(info->sn));
499
500        aimbs_put16(bs, info->warnlevel);
501
502
503        aim_addtlvtochain16(&tlvlist, 0x0001, info->flags);
504        aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
505        aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
506        aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
507
508#if ICQ_OSCAR_SUPPORT
509        if (atoi(info->sn) != 0) {
510                aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status);
511                aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
512        }
513#endif
514
515        aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities);
516
517        aim_addtlvtochain32(&tlvlist, (guint16)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen);
518
519        aimbs_put16(bs, aim_counttlvchain(&tlvlist));
520        aim_writetlvchain(bs, &tlvlist);
521        aim_freetlvchain(&tlvlist);
522
523        return 0;
524}
525
526int aim_sendbuddyoncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info)
527{
528        aim_frame_t *fr;
529        aim_snacid_t snacid;
530
531        if (!sess || !conn || !info)
532                return -EINVAL;
533
534        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
535                return -ENOMEM;
536
537        snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0);
538       
539        aim_putsnac(&fr->data, 0x0003, 0x000b, 0x0000, snacid);
540        aim_putuserinfo(&fr->data, info);
541
542        aim_tx_enqueue(sess, fr);
543
544        return 0;
545}
546
547int aim_sendbuddyoffgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn)
548{
549        aim_frame_t *fr;
550        aim_snacid_t snacid;
551
552        if (!sess || !conn || !sn)
553                return -EINVAL;
554
555        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
556                return -ENOMEM;
557
558        snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0);
559       
560        aim_putsnac(&fr->data, 0x0003, 0x000c, 0x0000, snacid);
561        aimbs_put8(&fr->data, strlen(sn));
562        aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
563
564        aim_tx_enqueue(sess, fr);
565
566        return 0;
567}
568
569/*
570 * Huh? What is this?
571 */
572int aim_0002_000b(aim_session_t *sess, aim_conn_t *conn, const char *sn)
573{
574        aim_frame_t *fr;
575        aim_snacid_t snacid;
576
577        if (!sess || !conn || !sn)
578                return -EINVAL;
579
580        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
581                return -ENOMEM;
582
583        snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0);
584       
585        aim_putsnac(&fr->data, 0x0002, 0x000b, 0x0000, snacid);
586        aimbs_put8(&fr->data, strlen(sn));
587        aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
588
589        aim_tx_enqueue(sess, fr);
590
591        return 0;
592}
593
594/*
595 * Normally contains:
596 *   t(0001)  - short containing max profile length (value = 1024)
597 *   t(0002)  - short - unknown (value = 16) [max MIME type length?]
598 *   t(0003)  - short - unknown (value = 10)
599 *   t(0004)  - short - unknown (value = 2048) [ICQ only?]
600 */
601static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
602{
603        aim_tlvlist_t *tlvlist;
604        aim_rxcallback_t userfunc;
605        int ret = 0;
606        guint16 maxsiglen = 0;
607
608        tlvlist = aim_readtlvchain(bs);
609
610        if (aim_gettlv(tlvlist, 0x0001, 1))
611                maxsiglen = aim_gettlv16(tlvlist, 0x0001, 1);
612
613        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
614                ret = userfunc(sess, rx, maxsiglen);
615
616        aim_freetlvchain(&tlvlist);
617
618        return ret;
619}
620
621static int userinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
622{
623        aim_userinfo_t userinfo;
624        char *text_encoding = NULL, *text = NULL;
625        guint16 text_length = 0;
626        aim_rxcallback_t userfunc;
627        aim_tlvlist_t *tlvlist;
628        aim_tlv_t *tlv;
629        aim_snac_t *origsnac = NULL;
630        struct aim_priv_inforeq *inforeq;
631        int ret = 0;
632
633        origsnac = aim_remsnac(sess, snac->id);
634
635        if (!origsnac || !origsnac->data) {
636                do_error_dialog(sess->aux_data, "major problem: no snac stored!", "Gaim");
637                return 0;
638        }
639
640        inforeq = (struct aim_priv_inforeq *)origsnac->data;
641
642        if ((inforeq->infotype != AIM_GETINFO_GENERALINFO) &&
643                        (inforeq->infotype != AIM_GETINFO_AWAYMESSAGE) &&
644                        (inforeq->infotype != AIM_GETINFO_CAPABILITIES)) {
645                do_error_dialog(sess->aux_data, "unknown infotype in request!", "Gaim");
646                return 0;
647        }
648
649        aim_extractuserinfo(sess, bs, &userinfo);
650
651        tlvlist = aim_readtlvchain(bs);
652
653        /*
654         * Depending on what informational text was requested, different
655         * TLVs will appear here.
656         *
657         * Profile will be 1 and 2, away message will be 3 and 4, caps
658         * will be 5.
659         */
660        if (inforeq->infotype == AIM_GETINFO_GENERALINFO) {
661                text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
662                if((tlv = aim_gettlv(tlvlist, 0x0002, 1))) {
663                        text = g_new0(char, tlv->length);
664                        memcpy(text, tlv->value, tlv->length);
665                        text_length = tlv->length;
666                }
667        } else if (inforeq->infotype == AIM_GETINFO_AWAYMESSAGE) {
668                text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
669                if((tlv = aim_gettlv(tlvlist, 0x0004, 1))) {
670                        text = g_new0(char, tlv->length);
671                        memcpy(text, tlv->value, tlv->length);
672                        text_length = tlv->length;
673                }
674        } else if (inforeq->infotype == AIM_GETINFO_CAPABILITIES) {
675                aim_tlv_t *ct;
676
677                if ((ct = aim_gettlv(tlvlist, 0x0005, 1))) {
678                        aim_bstream_t cbs;
679
680                        aim_bstream_init(&cbs, ct->value, ct->length);
681
682                        userinfo.capabilities = aim_getcap(sess, &cbs, ct->length);
683                        userinfo.present = AIM_USERINFO_PRESENT_CAPABILITIES;
684                }
685        }
686
687        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
688                ret = userfunc(sess, rx, &userinfo, inforeq->infotype, text_encoding, text, text_length);
689
690        g_free(text_encoding);
691        g_free(text);
692
693        aim_freetlvchain(&tlvlist);
694
695        if (origsnac)
696                g_free(origsnac->data);
697        g_free(origsnac);
698
699        return ret;
700}
701
702static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
703{
704
705        if (snac->subtype == 0x0003)
706                return rights(sess, mod, rx, snac, bs);
707        else if (snac->subtype == 0x0006)
708                return userinfo(sess, mod, rx, snac, bs);
709
710        return 0;
711}
712
713int locate_modfirst(aim_session_t *sess, aim_module_t *mod)
714{
715
716        mod->family = 0x0002;
717        mod->version = 0x0001;
718        mod->toolid = 0x0110;
719        mod->toolversion = 0x0629;
720        mod->flags = 0;
721        strncpy(mod->name, "locate", sizeof(mod->name));
722        mod->snachandler = snachandler;
723
724        return 0;
725}
Note: See TracBrowser for help on using the repository browser.