source: protocols/oscar/service.c @ 6f55bec

Last change on this file since 6f55bec was b041b52, checked in by Wilmer van der Gaast <wilmer@…>, at 2011-12-06T21:50:43Z

Merging compiler warning fixes from vmiklos.

This change also uncovered one bug in groupchat handling in OSCAR, which
I fixed during the merge.

  • Property mode set to 100644
File size: 25.4 KB
Line 
1/*
2 * Group 1.  This is a very special group.  All connections support
3 * this group, as it does some particularly good things (like rate limiting).
4 */
5
6#include <aim.h>
7
8#include "md5.h"
9
10/* Client Online (group 1, subtype 2) */
11int aim_clientready(aim_session_t *sess, aim_conn_t *conn)
12{
13        aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
14        struct snacgroup *sg;
15        aim_frame_t *fr;
16        aim_snacid_t snacid;
17
18        if (!ins)
19                return -EINVAL;
20
21        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
22                return -ENOMEM;
23
24        snacid = aim_cachesnac(sess, 0x0001, 0x0002, 0x0000, NULL, 0);
25        aim_putsnac(&fr->data, 0x0001, 0x0002, 0x0000, snacid);
26
27        /*
28         * Send only the tool versions that the server cares about (that it
29         * marked as supporting in the server ready SNAC). 
30         */
31        for (sg = ins->groups; sg; sg = sg->next) {
32                aim_module_t *mod;
33
34                if ((mod = aim__findmodulebygroup(sess, sg->group))) {
35                        aimbs_put16(&fr->data, mod->family);
36                        aimbs_put16(&fr->data, mod->version);
37                        aimbs_put16(&fr->data, mod->toolid);
38                        aimbs_put16(&fr->data, mod->toolversion);
39                } 
40        }
41
42        aim_tx_enqueue(sess, fr);
43
44        return 0;
45}
46
47/*
48 * Host Online (group 1, type 3)
49 *
50 * See comments in conn.c about how the group associations are supposed
51 * to work, and how they really work.
52 *
53 * This info probably doesn't even need to make it to the client.
54 *
55 * We don't actually call the client here.  This starts off the connection
56 * initialization routine required by all AIM connections.  The next time
57 * the client is called is the CONNINITDONE callback, which should be
58 * shortly after the rate information is acknowledged.
59 *
60 */
61static int hostonline(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
62{
63        guint16 *families;
64        int famcount;
65
66
67        if (!(families = g_malloc(aim_bstream_empty(bs))))
68                return 0;
69
70        for (famcount = 0; aim_bstream_empty(bs); famcount++) {
71                families[famcount] = aimbs_get16(bs);
72                aim_conn_addgroup(rx->conn, families[famcount]);
73        }
74
75        g_free(families);
76
77
78        /*
79         * Next step is in the Host Versions handler.
80         *
81         * Note that we must send this before we request rates, since
82         * the format of the rate information depends on the versions we
83         * give it.
84         *
85         */
86        aim_setversions(sess, rx->conn);
87
88        return 1; 
89}
90
91/* Service request (group 1, type 4) */
92int aim_reqservice(aim_session_t *sess, aim_conn_t *conn, guint16 serviceid)
93{
94        return aim_genericreq_s(sess, conn, 0x0001, 0x0004, &serviceid);
95}
96
97/* Redirect (group 1, type 5) */
98static int redirect(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
99{
100        struct aim_redirect_data redir;
101        aim_rxcallback_t userfunc;
102        aim_tlvlist_t *tlvlist;
103        aim_snac_t *origsnac = NULL;
104        int ret = 0;
105
106        memset(&redir, 0, sizeof(redir));
107
108        tlvlist = aim_readtlvchain(bs);
109
110        if (!aim_gettlv(tlvlist, 0x000d, 1) ||
111                        !aim_gettlv(tlvlist, 0x0005, 1) ||
112                        !aim_gettlv(tlvlist, 0x0006, 1)) {
113                aim_freetlvchain(&tlvlist);
114                return 0;
115        }
116
117        redir.group = aim_gettlv16(tlvlist, 0x000d, 1);
118        redir.ip = aim_gettlv_str(tlvlist, 0x0005, 1);
119        redir.cookie = (guint8 *)aim_gettlv_str(tlvlist, 0x0006, 1);
120
121        /* Fetch original SNAC so we can get csi if needed */
122        origsnac = aim_remsnac(sess, snac->id);
123
124        if ((redir.group == AIM_CONN_TYPE_CHAT) && origsnac) {
125                struct chatsnacinfo *csi = (struct chatsnacinfo *)origsnac->data;
126
127                redir.chat.exchange = csi->exchange;
128                redir.chat.room = csi->name;
129                redir.chat.instance = csi->instance;
130        }
131
132        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
133                ret = userfunc(sess, rx, &redir);
134
135        g_free((void *)redir.ip);
136        g_free((void *)redir.cookie);
137
138        if (origsnac)
139                g_free(origsnac->data);
140        g_free(origsnac);
141
142        aim_freetlvchain(&tlvlist);
143
144        return ret;
145}
146
147/* Request Rate Information. (group 1, type 6) */
148int aim_reqrates(aim_session_t *sess, aim_conn_t *conn)
149{
150        return aim_genericreq_n(sess, conn, 0x0001, 0x0006);
151}
152
153/*
154 * OSCAR defines several 'rate classes'.  Each class has seperate
155 * rate limiting properties (limit level, alert level, disconnect
156 * level, etc), and a set of SNAC family/type pairs associated with
157 * it.  The rate classes, their limiting properties, and the definitions
158 * of which SNACs are belong to which class, are defined in the
159 * Rate Response packet at login to each host. 
160 *
161 * Logically, all rate offenses within one class count against further
162 * offenses for other SNACs in the same class (ie, sending messages
163 * too fast will limit the number of user info requests you can send,
164 * since those two SNACs are in the same rate class).
165 *
166 * Since the rate classes are defined dynamically at login, the values
167 * below may change. But they seem to be fairly constant.
168 *
169 * Currently, BOS defines five rate classes, with the commonly used
170 * members as follows...
171 *
172 *  Rate class 0x0001:
173 *      - Everything thats not in any of the other classes
174 *
175 *  Rate class 0x0002:
176 *      - Buddy list add/remove
177 *      - Permit list add/remove
178 *      - Deny list add/remove
179 *
180 *  Rate class 0x0003:
181 *      - User information requests
182 *      - Outgoing ICBMs
183 *
184 *  Rate class 0x0004:
185 *      - A few unknowns: 2/9, 2/b, and f/2
186 *
187 *  Rate class 0x0005:
188 *      - Chat room create
189 *      - Outgoing chat ICBMs
190 *
191 * The only other thing of note is that class 5 (chat) has slightly looser
192 * limiting properties than class 3 (normal messages).  But thats just a
193 * small bit of trivia for you.
194 *
195 * The last thing that needs to be learned about the rate limiting
196 * system is how the actual numbers relate to the passing of time.  This
197 * seems to be a big mystery.
198 *
199 */
200
201static void rc_addclass(struct rateclass **head, struct rateclass *inrc)
202{
203        struct rateclass *rc, *rc2;
204
205        if (!(rc = g_malloc(sizeof(struct rateclass))))
206                return;
207
208        memcpy(rc, inrc, sizeof(struct rateclass));
209        rc->next = NULL;
210
211        for (rc2 = *head; rc2 && rc2->next; rc2 = rc2->next)
212                ;
213
214        if (!rc2)
215                *head = rc;
216        else
217                rc2->next = rc;
218
219        return;
220}
221
222static struct rateclass *rc_findclass(struct rateclass **head, guint16 id)
223{
224        struct rateclass *rc;
225
226        for (rc = *head; rc; rc = rc->next) {
227                if (rc->classid == id)
228                        return rc;
229        }
230
231        return NULL;
232}
233
234static void rc_addpair(struct rateclass *rc, guint16 group, guint16 type)
235{
236        struct snacpair *sp, *sp2;
237
238        if (!(sp = g_new0(struct snacpair, 1)))
239                return;
240
241        sp->group = group;
242        sp->subtype = type;
243        sp->next = NULL;
244
245        for (sp2 = rc->members; sp2 && sp2->next; sp2 = sp2->next)
246                ;
247
248        if (!sp2)
249                rc->members = sp;
250        else
251                sp2->next = sp;
252
253        return;
254}
255
256/* Rate Parameters (group 1, type 7) */
257static int rateresp(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
258{
259        aim_conn_inside_t *ins = (aim_conn_inside_t *)rx->conn->inside;
260        guint16 numclasses, i;
261        aim_rxcallback_t userfunc;
262
263
264        /*
265         * First are the parameters for each rate class.
266         */
267        numclasses = aimbs_get16(bs);
268        for (i = 0; i < numclasses; i++) {
269                struct rateclass rc;
270
271                memset(&rc, 0, sizeof(struct rateclass));
272
273                rc.classid = aimbs_get16(bs);
274                rc.windowsize = aimbs_get32(bs);
275                rc.clear = aimbs_get32(bs);
276                rc.alert = aimbs_get32(bs);
277                rc.limit = aimbs_get32(bs);
278                rc.disconnect = aimbs_get32(bs);
279                rc.current = aimbs_get32(bs);
280                rc.max = aimbs_get32(bs);
281
282                /*
283                 * The server will send an extra five bytes of parameters
284                 * depending on the version we advertised in 1/17.  If we
285                 * didn't send 1/17 (evil!), then this will crash and you
286                 * die, as it will default to the old version but we have
287                 * the new version hardcoded here.
288                 */
289                if (mod->version >= 3)
290                        aimbs_getrawbuf(bs, rc.unknown, sizeof(rc.unknown));
291
292                rc_addclass(&ins->rates, &rc);
293        }
294
295        /*
296         * Then the members of each class.
297         */
298        for (i = 0; i < numclasses; i++) {
299                guint16 classid, count;
300                struct rateclass *rc;
301                int j;
302
303                classid = aimbs_get16(bs);
304                count = aimbs_get16(bs);
305
306                rc = rc_findclass(&ins->rates, classid);
307
308                for (j = 0; j < count; j++) {
309                        guint16 group, subtype;
310
311                        group = aimbs_get16(bs);
312                        subtype = aimbs_get16(bs);
313
314                        if (rc)
315                                rc_addpair(rc, group, subtype);
316                }
317        }
318
319        /*
320         * We don't pass the rate information up to the client, as it really
321         * doesn't care.  The information is stored in the connection, however
322         * so that we can do more fun stuff later (not really).
323         */
324
325        /*
326         * Last step in the conn init procedure is to acknowledge that we
327         * agree to these draconian limitations.
328         */
329        aim_rates_addparam(sess, rx->conn);
330
331        /*
332         * Finally, tell the client it's ready to go...
333         */
334        if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE)))
335                userfunc(sess, rx);
336
337
338        return 1;
339}
340
341/* Add Rate Parameter (group 1, type 8) */
342int aim_rates_addparam(aim_session_t *sess, aim_conn_t *conn)
343{
344        aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
345        aim_frame_t *fr;       
346        aim_snacid_t snacid;
347        struct rateclass *rc;
348
349        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
350                return -ENOMEM; 
351
352        snacid = aim_cachesnac(sess, 0x0001, 0x0008, 0x0000, NULL, 0);
353        aim_putsnac(&fr->data, 0x0001, 0x0008, 0x0000, snacid);
354
355        for (rc = ins->rates; rc; rc = rc->next)
356                aimbs_put16(&fr->data, rc->classid);
357
358        aim_tx_enqueue(sess, fr);
359
360        return 0;
361}
362
363/* Delete Rate Parameter (group 1, type 9) */
364int aim_rates_delparam(aim_session_t *sess, aim_conn_t *conn)
365{
366        aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
367        aim_frame_t *fr;       
368        aim_snacid_t snacid;
369        struct rateclass *rc;
370
371        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
372                return -ENOMEM; 
373
374        snacid = aim_cachesnac(sess, 0x0001, 0x0009, 0x0000, NULL, 0);
375        aim_putsnac(&fr->data, 0x0001, 0x0009, 0x0000, snacid);
376
377        for (rc = ins->rates; rc; rc = rc->next)
378                aimbs_put16(&fr->data, rc->classid);
379
380        aim_tx_enqueue(sess, fr);
381
382        return 0;
383}
384
385/* Rate Change (group 1, type 0x0a) */
386static int ratechange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
387{
388        aim_rxcallback_t userfunc;
389        guint16 code, rateclass;
390        guint32 currentavg, maxavg, windowsize, clear, alert, limit, disconnect;
391
392        code = aimbs_get16(bs);
393        rateclass = aimbs_get16(bs);
394       
395        windowsize = aimbs_get32(bs);
396        clear = aimbs_get32(bs);
397        alert = aimbs_get32(bs);
398        limit = aimbs_get32(bs);
399        disconnect = aimbs_get32(bs);
400        currentavg = aimbs_get32(bs);
401        maxavg = aimbs_get32(bs);
402
403        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
404                return userfunc(sess, rx, code, rateclass, windowsize, clear, alert, limit, disconnect, currentavg, maxavg);
405
406        return 0;
407}
408
409/*
410 * How Migrations work. 
411 *
412 * The server sends a Server Pause message, which the client should respond to
413 * with a Server Pause Ack, which contains the families it needs on this
414 * connection. The server will send a Migration Notice with an IP address, and
415 * then disconnect. Next the client should open the connection and send the
416 * cookie.  Repeat the normal login process and pretend this never happened.
417 *
418 * The Server Pause contains no data.
419 *
420 */
421
422/* Service Pause (group 1, type 0x0b) */
423static int serverpause(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
424{
425        aim_rxcallback_t userfunc;
426
427        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
428                return userfunc(sess, rx);
429
430        return 0;
431}
432
433/*
434 * Service Pause Acknowledgement (group 1, type 0x0c)
435 *
436 * It is rather important that aim_sendpauseack() gets called for the exact
437 * same connection that the Server Pause callback was called for, since
438 * libfaim extracts the data for the SNAC from the connection structure.
439 *
440 * Of course, if you don't do that, more bad things happen than just what
441 * libfaim can cause.
442 *
443 */
444int aim_sendpauseack(aim_session_t *sess, aim_conn_t *conn)
445{
446        aim_frame_t *fr;
447        aim_snacid_t snacid;
448        aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
449        struct snacgroup *sg;
450
451        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1024)))
452                return -ENOMEM;
453
454        snacid = aim_cachesnac(sess, 0x0001, 0x000c, 0x0000, NULL, 0);
455        aim_putsnac(&fr->data, 0x0001, 0x000c, 0x0000, snacid);
456
457        /*
458         * This list should have all the groups that the original
459         * Host Online / Server Ready said this host supports.  And
460         * we want them all back after the migration.
461         */
462        for (sg = ins->groups; sg; sg = sg->next)
463                aimbs_put16(&fr->data, sg->group);
464
465        aim_tx_enqueue(sess, fr);
466
467        return 0;
468}
469
470/* Service Resume (group 1, type 0x0d) */
471static int serverresume(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
472{
473        aim_rxcallback_t userfunc;
474
475        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
476                return userfunc(sess, rx);
477
478        return 0;
479}
480
481/* Request self-info (group 1, type 0x0e) */
482int aim_reqpersonalinfo(aim_session_t *sess, aim_conn_t *conn)
483{
484        return aim_genericreq_n(sess, conn, 0x0001, 0x000e);
485}
486
487/* Self User Info (group 1, type 0x0f) */
488static int selfinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
489{
490        aim_rxcallback_t userfunc;
491        aim_userinfo_t userinfo;
492
493        aim_extractuserinfo(sess, bs, &userinfo);
494
495        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
496                return userfunc(sess, rx, &userinfo);
497
498        return 0;
499}
500
501/* Evil Notification (group 1, type 0x10) */
502static int evilnotify(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
503{
504        aim_rxcallback_t userfunc;
505        guint16 newevil;
506        aim_userinfo_t userinfo;
507
508        memset(&userinfo, 0, sizeof(aim_userinfo_t));
509       
510        newevil = aimbs_get16(bs);
511
512        if (aim_bstream_empty(bs))
513                aim_extractuserinfo(sess, bs, &userinfo);
514
515        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
516                return userfunc(sess, rx, newevil, &userinfo);
517
518        return 0;
519}
520
521/*
522 * Idle Notification (group 1, type 0x11)
523 *
524 * Should set your current idle time in seconds.  Note that this should
525 * never be called consecutively with a non-zero idle time.  That makes
526 * OSCAR do funny things.  Instead, just set it once you go idle, and then
527 * call it again with zero when you're back.
528 *
529 */
530int aim_bos_setidle(aim_session_t *sess, aim_conn_t *conn, guint32 idletime)
531{
532        return aim_genericreq_l(sess, conn, 0x0001, 0x0011, &idletime);
533}
534
535/*
536 * Service Migrate (group 1, type 0x12)
537 *
538 * This is the final SNAC sent on the original connection during a migration.
539 * It contains the IP and cookie used to connect to the new server, and
540 * optionally a list of the SNAC groups being migrated.
541 *
542 */
543static int migrate(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
544{
545        aim_rxcallback_t userfunc;
546        int ret = 0;
547        guint16 groupcount, i;
548        aim_tlvlist_t *tl;
549        char *ip = NULL;
550        aim_tlv_t *cktlv;
551
552        /*
553         * Apparently there's some fun stuff that can happen right here. The
554         * migration can actually be quite selective about what groups it
555         * moves to the new server.  When not all the groups for a connection
556         * are migrated, or they are all migrated but some groups are moved
557         * to a different server than others, it is called a bifurcated
558         * migration.
559         *
560         * Let's play dumb and not support that.
561         *
562         */
563        groupcount = aimbs_get16(bs);
564        for (i = 0; i < groupcount; i++) {
565                aimbs_get16(bs);
566
567                imcb_error(sess->aux_data, "bifurcated migration unsupported");
568        }
569
570        tl = aim_readtlvchain(bs);
571
572        if (aim_gettlv(tl, 0x0005, 1))
573                ip = aim_gettlv_str(tl, 0x0005, 1);
574
575        cktlv = aim_gettlv(tl, 0x0006, 1);
576
577        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
578                ret = userfunc(sess, rx, ip, cktlv ? cktlv->value : NULL);
579
580        aim_freetlvchain(&tl);
581        g_free(ip);
582
583        return ret;
584}
585
586/* Message of the Day (group 1, type 0x13) */
587static int motd(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
588{
589        aim_rxcallback_t userfunc;
590        char *msg = NULL;
591        int ret = 0;
592        aim_tlvlist_t *tlvlist;
593        guint16 id;
594
595        /*
596         * Code.
597         *
598         * Valid values:
599         *   1 Mandatory upgrade
600         *   2 Advisory upgrade
601         *   3 System bulletin
602         *   4 Nothing's wrong ("top o the world" -- normal)
603         *   5 Lets-break-something.
604         *
605         */
606        id = aimbs_get16(bs);
607
608        /*
609         * TLVs follow
610         */
611        tlvlist = aim_readtlvchain(bs);
612
613        msg = aim_gettlv_str(tlvlist, 0x000b, 1);
614
615        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
616                ret = userfunc(sess, rx, id, msg);
617
618        g_free(msg);
619
620        aim_freetlvchain(&tlvlist);
621
622        return ret;
623}
624
625/*
626 * Set privacy flags (group 1, type 0x14)
627 *
628 * Normally 0x03.
629 *
630 *  Bit 1:  Allows other AIM users to see how long you've been idle.
631 *  Bit 2:  Allows other AIM users to see how long you've been a member.
632 *
633 */
634int aim_bos_setprivacyflags(aim_session_t *sess, aim_conn_t *conn, guint32 flags)
635{
636        return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags);
637}
638
639/*
640 * No-op (group 1, type 0x16)
641 *
642 * WinAIM sends these every 4min or so to keep the connection alive.  Its not
643 * real necessary.
644 *
645 */
646int aim_nop(aim_session_t *sess, aim_conn_t *conn)
647{
648        return aim_genericreq_n(sess, conn, 0x0001, 0x0016);
649}
650
651/*
652 * Set client versions (group 1, subtype 0x17)
653 *
654 * If you've seen the clientonline/clientready SNAC you're probably
655 * wondering what the point of this one is.  And that point seems to be
656 * that the versions in the client online SNAC are sent too late for the
657 * server to be able to use them to change the protocol for the earlier
658 * login packets (client versions are sent right after Host Online is
659 * received, but client online versions aren't sent until quite a bit later).
660 * We can see them already making use of this by changing the format of
661 * the rate information based on what version of group 1 we advertise here.
662 *
663 */
664int aim_setversions(aim_session_t *sess, aim_conn_t *conn)
665{
666        aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
667        struct snacgroup *sg;
668        aim_frame_t *fr;
669        aim_snacid_t snacid;
670
671        if (!ins)
672                return -EINVAL;
673
674        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
675                return -ENOMEM;
676
677        snacid = aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0);
678        aim_putsnac(&fr->data, 0x0001, 0x0017, 0x0000, snacid);
679
680        /*
681         * Send only the versions that the server cares about (that it
682         * marked as supporting in the server ready SNAC). 
683         */
684        for (sg = ins->groups; sg; sg = sg->next) {
685                aim_module_t *mod;
686
687                if ((mod = aim__findmodulebygroup(sess, sg->group))) {
688                        aimbs_put16(&fr->data, mod->family);
689                        aimbs_put16(&fr->data, mod->version);
690                }
691        }
692
693        aim_tx_enqueue(sess, fr);
694
695        return 0;
696}
697
698/* Host versions (group 1, subtype 0x18) */
699static int hostversions(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
700{
701        guint8 *versions;
702
703        /* This is frivolous. (Thank you SmarterChild.) */
704        aim_bstream_empty(bs); /* == vercount * 4 */
705        versions = aimbs_getraw(bs, aim_bstream_empty(bs));
706        g_free(versions);
707
708        /*
709         * Now request rates.
710         */
711        aim_reqrates(sess, rx->conn);
712
713        return 1;
714}
715
716/*
717 * Subtype 0x001e - Extended Status
718 *
719 * Sets your ICQ status (available, away, do not disturb, etc.)
720 *
721 * These are the same TLVs seen in user info.  You can
722 * also set 0x0008 and 0x000c.
723 */
724int aim_setextstatus(aim_session_t *sess, aim_conn_t *conn, guint32 status)
725{
726        aim_frame_t *fr;
727        aim_snacid_t snacid;
728        aim_tlvlist_t *tl = NULL;
729        guint32 data;
730        struct im_connection *ic = sess ? sess->aux_data : NULL;
731
732        data = AIM_ICQ_STATE_HIDEIP | status; /* yay for error checking ;^) */
733       
734        if (ic && set_getbool(&ic->acc->set, "web_aware"))
735                data |= AIM_ICQ_STATE_WEBAWARE;
736
737        aim_addtlvtochain32(&tl, 0x0006, data); /* tlvlen */
738
739        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 8)))
740                return -ENOMEM;
741
742        snacid = aim_cachesnac(sess, 0x0001, 0x001e, 0x0000, NULL, 0);
743        aim_putsnac(&fr->data, 0x0001, 0x001e, 0x0000, snacid);
744       
745        aim_writetlvchain(&fr->data, &tl);
746        aim_freetlvchain(&tl);
747       
748        aim_tx_enqueue(sess, fr);
749
750        return 0;
751}
752
753/*
754 * Starting this past week (26 Mar 2001, say), AOL has started sending
755 * this nice little extra SNAC.  AFAIK, it has never been used until now.
756 *
757 * The request contains eight bytes.  The first four are an offset, the
758 * second four are a length.
759 *
760 * The offset is an offset into aim.exe when it is mapped during execution
761 * on Win32.  So far, AOL has only been requesting bytes in static regions
762 * of memory.  (I won't put it past them to start requesting data in
763 * less static regions -- regions that are initialized at run time, but still
764 * before the client recieves this request.)
765 *
766 * When the client recieves the request, it adds it to the current ds
767 * (0x00400000) and dereferences it, copying the data into a buffer which
768 * it then runs directly through the MD5 hasher.  The 16 byte output of
769 * the hash is then sent back to the server.
770 *
771 * If the client does not send any data back, or the data does not match
772 * the data that the specific client should have, the client will get the
773 * following message from "AOL Instant Messenger":
774 *    "You have been disconnected from the AOL Instant Message Service (SM)
775 *     for accessing the AOL network using unauthorized software.  You can
776 *     download a FREE, fully featured, and authorized client, here
777 *     http://www.aol.com/aim/download2.html"
778 * The connection is then closed, recieving disconnect code 1, URL
779 * http://www.aim.aol.com/errors/USER_LOGGED_OFF_NEW_LOGIN.html. 
780 *
781 * Note, however, that numerous inconsistencies can cause the above error,
782 * not just sending back a bad hash.  Do not immediatly suspect this code
783 * if you get disconnected.  AOL and the open/free software community have
784 * played this game for a couple years now, generating the above message
785 * on numerous ocassions.
786 *
787 * Anyway, neener.  We win again.
788 *
789 */
790/* Client verification (group 1, subtype 0x1f) */
791static int memrequest(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
792{
793        aim_rxcallback_t userfunc;
794        guint32 offset, len;
795        aim_tlvlist_t *list;
796        char *modname;
797
798        offset = aimbs_get32(bs);
799        len = aimbs_get32(bs);
800        list = aim_readtlvchain(bs);
801
802        modname = aim_gettlv_str(list, 0x0001, 1);
803
804        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
805                return userfunc(sess, rx, offset, len, modname);
806
807        g_free(modname);
808        aim_freetlvchain(&list);
809
810        return 0;
811}
812
813/* Client verification reply (group 1, subtype 0x20) */
814int aim_sendmemblock(aim_session_t *sess, aim_conn_t *conn, guint32 offset, guint32 len, const guint8 *buf, guint8 flag)
815{
816        aim_frame_t *fr;
817        aim_snacid_t snacid;
818
819        if (!sess || !conn)
820                return -EINVAL;
821
822        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16)))
823                return -ENOMEM;
824
825        snacid = aim_cachesnac(sess, 0x0001, 0x0020, 0x0000, NULL, 0);
826
827        aim_putsnac(&fr->data, 0x0001, 0x0020, 0x0000, snacid);
828        aimbs_put16(&fr->data, 0x0010); /* md5 is always 16 bytes */
829
830        if ((flag == AIM_SENDMEMBLOCK_FLAG_ISHASH) && buf && (len == 0x10)) { /* we're getting a hash */
831
832                aimbs_putraw(&fr->data, buf, 0x10); 
833
834        } else if (buf && (len > 0)) { /* use input buffer */
835                md5_state_t state;
836                md5_byte_t digest[0x10];
837
838                md5_init(&state);       
839                md5_append(&state, (const md5_byte_t *)buf, len);
840                md5_finish(&state, digest);
841
842                aimbs_putraw(&fr->data, (guint8 *)digest, 0x10);
843
844        } else if (len == 0) { /* no length, just hash NULL (buf is optional) */
845                md5_state_t state;
846                guint8 nil = '\0';
847                md5_byte_t digest[0x10];
848
849                /*
850                 * These MD5 routines are stupid in that you have to have
851                 * at least one append.  So thats why this doesn't look
852                 * real logical.
853                 */
854                md5_init(&state);
855                md5_append(&state, (const md5_byte_t *)&nil, 0);
856                md5_finish(&state, digest);
857
858                aimbs_putraw(&fr->data, (guint8 *)digest, 0x10);
859
860        } else {
861
862                /*
863                 * This data is correct for AIM 3.5.1670.
864                 *
865                 * Using these blocks is as close to "legal" as you can get
866                 * without using an AIM binary.
867                 *
868                 */
869                if ((offset == 0x03ffffff) && (len == 0x03ffffff)) {
870
871#if 1 /* with "AnrbnrAqhfzcd" */
872                        aimbs_put32(&fr->data, 0x44a95d26);
873                        aimbs_put32(&fr->data, 0xd2490423);
874                        aimbs_put32(&fr->data, 0x93b8821f);
875                        aimbs_put32(&fr->data, 0x51c54b01);
876#else /* no filename */
877                        aimbs_put32(&fr->data, 0x1df8cbae);
878                        aimbs_put32(&fr->data, 0x5523b839);
879                        aimbs_put32(&fr->data, 0xa0e10db3);
880                        aimbs_put32(&fr->data, 0xa46d3b39);
881#endif
882
883/* len can't be 0 here anyway...
884                } else if ((offset == 0x00001000) && (len == 0x00000000)) {
885
886                        aimbs_put32(&fr->data, 0xd41d8cd9);
887                        aimbs_put32(&fr->data, 0x8f00b204);
888                        aimbs_put32(&fr->data, 0xe9800998);
889                        aimbs_put32(&fr->data, 0xecf8427e);
890*/
891                } else
892                        imcb_error(sess->aux_data, "Warning: unknown hash request");
893
894        }
895
896        aim_tx_enqueue(sess, fr);
897
898        return 0;
899}
900
901static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
902{
903
904        if (snac->subtype == 0x0003)
905                return hostonline(sess, mod, rx, snac, bs);
906        else if (snac->subtype == 0x0005)
907                return redirect(sess, mod, rx, snac, bs);
908        else if (snac->subtype == 0x0007)
909                return rateresp(sess, mod, rx, snac, bs);
910        else if (snac->subtype == 0x000a)
911                return ratechange(sess, mod, rx, snac, bs);
912        else if (snac->subtype == 0x000b)
913                return serverpause(sess, mod, rx, snac, bs);
914        else if (snac->subtype == 0x000d)
915                return serverresume(sess, mod, rx, snac, bs);
916        else if (snac->subtype == 0x000f)
917                return selfinfo(sess, mod, rx, snac, bs);
918        else if (snac->subtype == 0x0010)
919                return evilnotify(sess, mod, rx, snac, bs);
920        else if (snac->subtype == 0x0012)
921                return migrate(sess, mod, rx, snac, bs);
922        else if (snac->subtype == 0x0013)
923                return motd(sess, mod, rx, snac, bs);
924        else if (snac->subtype == 0x0018)
925                return hostversions(sess, mod, rx, snac, bs);
926        else if (snac->subtype == 0x001f)
927                return memrequest(sess, mod, rx, snac, bs);
928
929        return 0;
930}
931
932int general_modfirst(aim_session_t *sess, aim_module_t *mod)
933{
934
935        mod->family = 0x0001;
936        mod->version = 0x0003;
937        mod->toolid = 0x0110;
938        mod->toolversion = 0x0629;
939        mod->flags = 0;
940        strncpy(mod->name, "general", sizeof(mod->name));
941        mod->snachandler = snachandler;
942
943        return 0;
944}
945
Note: See TracBrowser for help on using the repository browser.