source: protocols/oscar/service.c @ 8358691

Last change on this file since 8358691 was 43462708, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-01-06T12:37:55Z

More consistency in error/warning errors. Until now "WARNING:" was usually
in upper case while "Error:" wasn't .... that doesn't really make sense.

  • Property mode set to 100644
File size: 25.5 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                guint16 group;
566
567                group = aimbs_get16(bs);
568
569                imcb_error(sess->aux_data, "bifurcated migration unsupported");
570        }
571
572        tl = aim_readtlvchain(bs);
573
574        if (aim_gettlv(tl, 0x0005, 1))
575                ip = aim_gettlv_str(tl, 0x0005, 1);
576
577        cktlv = aim_gettlv(tl, 0x0006, 1);
578
579        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
580                ret = userfunc(sess, rx, ip, cktlv ? cktlv->value : NULL);
581
582        aim_freetlvchain(&tl);
583        g_free(ip);
584
585        return ret;
586}
587
588/* Message of the Day (group 1, type 0x13) */
589static int motd(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
590{
591        aim_rxcallback_t userfunc;
592        char *msg = NULL;
593        int ret = 0;
594        aim_tlvlist_t *tlvlist;
595        guint16 id;
596
597        /*
598         * Code.
599         *
600         * Valid values:
601         *   1 Mandatory upgrade
602         *   2 Advisory upgrade
603         *   3 System bulletin
604         *   4 Nothing's wrong ("top o the world" -- normal)
605         *   5 Lets-break-something.
606         *
607         */
608        id = aimbs_get16(bs);
609
610        /*
611         * TLVs follow
612         */
613        tlvlist = aim_readtlvchain(bs);
614
615        msg = aim_gettlv_str(tlvlist, 0x000b, 1);
616
617        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
618                ret = userfunc(sess, rx, id, msg);
619
620        g_free(msg);
621
622        aim_freetlvchain(&tlvlist);
623
624        return ret;
625}
626
627/*
628 * Set privacy flags (group 1, type 0x14)
629 *
630 * Normally 0x03.
631 *
632 *  Bit 1:  Allows other AIM users to see how long you've been idle.
633 *  Bit 2:  Allows other AIM users to see how long you've been a member.
634 *
635 */
636int aim_bos_setprivacyflags(aim_session_t *sess, aim_conn_t *conn, guint32 flags)
637{
638        return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags);
639}
640
641/*
642 * No-op (group 1, type 0x16)
643 *
644 * WinAIM sends these every 4min or so to keep the connection alive.  Its not
645 * real necessary.
646 *
647 */
648int aim_nop(aim_session_t *sess, aim_conn_t *conn)
649{
650        return aim_genericreq_n(sess, conn, 0x0001, 0x0016);
651}
652
653/*
654 * Set client versions (group 1, subtype 0x17)
655 *
656 * If you've seen the clientonline/clientready SNAC you're probably
657 * wondering what the point of this one is.  And that point seems to be
658 * that the versions in the client online SNAC are sent too late for the
659 * server to be able to use them to change the protocol for the earlier
660 * login packets (client versions are sent right after Host Online is
661 * received, but client online versions aren't sent until quite a bit later).
662 * We can see them already making use of this by changing the format of
663 * the rate information based on what version of group 1 we advertise here.
664 *
665 */
666int aim_setversions(aim_session_t *sess, aim_conn_t *conn)
667{
668        aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
669        struct snacgroup *sg;
670        aim_frame_t *fr;
671        aim_snacid_t snacid;
672
673        if (!ins)
674                return -EINVAL;
675
676        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
677                return -ENOMEM;
678
679        snacid = aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0);
680        aim_putsnac(&fr->data, 0x0001, 0x0017, 0x0000, snacid);
681
682        /*
683         * Send only the versions that the server cares about (that it
684         * marked as supporting in the server ready SNAC). 
685         */
686        for (sg = ins->groups; sg; sg = sg->next) {
687                aim_module_t *mod;
688
689                if ((mod = aim__findmodulebygroup(sess, sg->group))) {
690                        aimbs_put16(&fr->data, mod->family);
691                        aimbs_put16(&fr->data, mod->version);
692                }
693        }
694
695        aim_tx_enqueue(sess, fr);
696
697        return 0;
698}
699
700/* Host versions (group 1, subtype 0x18) */
701static int hostversions(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
702{
703        int vercount;
704        guint8 *versions;
705
706        /* This is frivolous. (Thank you SmarterChild.) */
707        vercount = aim_bstream_empty(bs)/4;
708        versions = aimbs_getraw(bs, aim_bstream_empty(bs));
709        g_free(versions);
710
711        /*
712         * Now request rates.
713         */
714        aim_reqrates(sess, rx->conn);
715
716        return 1;
717}
718
719/*
720 * Subtype 0x001e - Extended Status
721 *
722 * Sets your ICQ status (available, away, do not disturb, etc.)
723 *
724 * These are the same TLVs seen in user info.  You can
725 * also set 0x0008 and 0x000c.
726 */
727int aim_setextstatus(aim_session_t *sess, aim_conn_t *conn, guint32 status)
728{
729        aim_frame_t *fr;
730        aim_snacid_t snacid;
731        aim_tlvlist_t *tl = NULL;
732        guint32 data;
733        int tlvlen;
734        struct im_connection *ic = sess ? sess->aux_data : NULL;
735
736        data = AIM_ICQ_STATE_HIDEIP | status; /* yay for error checking ;^) */
737       
738        if (ic && set_getbool(&ic->acc->set, "web_aware"))
739                data |= AIM_ICQ_STATE_WEBAWARE;
740
741        tlvlen = aim_addtlvtochain32(&tl, 0x0006, data);
742
743        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 8)))
744                return -ENOMEM;
745
746        snacid = aim_cachesnac(sess, 0x0001, 0x001e, 0x0000, NULL, 0);
747        aim_putsnac(&fr->data, 0x0001, 0x001e, 0x0000, snacid);
748       
749        aim_writetlvchain(&fr->data, &tl);
750        aim_freetlvchain(&tl);
751       
752        aim_tx_enqueue(sess, fr);
753
754        return 0;
755}
756
757/*
758 * Starting this past week (26 Mar 2001, say), AOL has started sending
759 * this nice little extra SNAC.  AFAIK, it has never been used until now.
760 *
761 * The request contains eight bytes.  The first four are an offset, the
762 * second four are a length.
763 *
764 * The offset is an offset into aim.exe when it is mapped during execution
765 * on Win32.  So far, AOL has only been requesting bytes in static regions
766 * of memory.  (I won't put it past them to start requesting data in
767 * less static regions -- regions that are initialized at run time, but still
768 * before the client recieves this request.)
769 *
770 * When the client recieves the request, it adds it to the current ds
771 * (0x00400000) and dereferences it, copying the data into a buffer which
772 * it then runs directly through the MD5 hasher.  The 16 byte output of
773 * the hash is then sent back to the server.
774 *
775 * If the client does not send any data back, or the data does not match
776 * the data that the specific client should have, the client will get the
777 * following message from "AOL Instant Messenger":
778 *    "You have been disconnected from the AOL Instant Message Service (SM)
779 *     for accessing the AOL network using unauthorized software.  You can
780 *     download a FREE, fully featured, and authorized client, here
781 *     http://www.aol.com/aim/download2.html"
782 * The connection is then closed, recieving disconnect code 1, URL
783 * http://www.aim.aol.com/errors/USER_LOGGED_OFF_NEW_LOGIN.html. 
784 *
785 * Note, however, that numerous inconsistencies can cause the above error,
786 * not just sending back a bad hash.  Do not immediatly suspect this code
787 * if you get disconnected.  AOL and the open/free software community have
788 * played this game for a couple years now, generating the above message
789 * on numerous ocassions.
790 *
791 * Anyway, neener.  We win again.
792 *
793 */
794/* Client verification (group 1, subtype 0x1f) */
795static int memrequest(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
796{
797        aim_rxcallback_t userfunc;
798        guint32 offset, len;
799        aim_tlvlist_t *list;
800        char *modname;
801
802        offset = aimbs_get32(bs);
803        len = aimbs_get32(bs);
804        list = aim_readtlvchain(bs);
805
806        modname = aim_gettlv_str(list, 0x0001, 1);
807
808        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
809                return userfunc(sess, rx, offset, len, modname);
810
811        g_free(modname);
812        aim_freetlvchain(&list);
813
814        return 0;
815}
816
817/* Client verification reply (group 1, subtype 0x20) */
818int aim_sendmemblock(aim_session_t *sess, aim_conn_t *conn, guint32 offset, guint32 len, const guint8 *buf, guint8 flag)
819{
820        aim_frame_t *fr;
821        aim_snacid_t snacid;
822
823        if (!sess || !conn)
824                return -EINVAL;
825
826        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16)))
827                return -ENOMEM;
828
829        snacid = aim_cachesnac(sess, 0x0001, 0x0020, 0x0000, NULL, 0);
830
831        aim_putsnac(&fr->data, 0x0001, 0x0020, 0x0000, snacid);
832        aimbs_put16(&fr->data, 0x0010); /* md5 is always 16 bytes */
833
834        if ((flag == AIM_SENDMEMBLOCK_FLAG_ISHASH) && buf && (len == 0x10)) { /* we're getting a hash */
835
836                aimbs_putraw(&fr->data, buf, 0x10); 
837
838        } else if (buf && (len > 0)) { /* use input buffer */
839                md5_state_t state;
840                md5_byte_t digest[0x10];
841
842                md5_init(&state);       
843                md5_append(&state, (const md5_byte_t *)buf, len);
844                md5_finish(&state, digest);
845
846                aimbs_putraw(&fr->data, (guint8 *)digest, 0x10);
847
848        } else if (len == 0) { /* no length, just hash NULL (buf is optional) */
849                md5_state_t state;
850                guint8 nil = '\0';
851                md5_byte_t digest[0x10];
852
853                /*
854                 * These MD5 routines are stupid in that you have to have
855                 * at least one append.  So thats why this doesn't look
856                 * real logical.
857                 */
858                md5_init(&state);
859                md5_append(&state, (const md5_byte_t *)&nil, 0);
860                md5_finish(&state, digest);
861
862                aimbs_putraw(&fr->data, (guint8 *)digest, 0x10);
863
864        } else {
865
866                /*
867                 * This data is correct for AIM 3.5.1670.
868                 *
869                 * Using these blocks is as close to "legal" as you can get
870                 * without using an AIM binary.
871                 *
872                 */
873                if ((offset == 0x03ffffff) && (len == 0x03ffffff)) {
874
875#if 1 /* with "AnrbnrAqhfzcd" */
876                        aimbs_put32(&fr->data, 0x44a95d26);
877                        aimbs_put32(&fr->data, 0xd2490423);
878                        aimbs_put32(&fr->data, 0x93b8821f);
879                        aimbs_put32(&fr->data, 0x51c54b01);
880#else /* no filename */
881                        aimbs_put32(&fr->data, 0x1df8cbae);
882                        aimbs_put32(&fr->data, 0x5523b839);
883                        aimbs_put32(&fr->data, 0xa0e10db3);
884                        aimbs_put32(&fr->data, 0xa46d3b39);
885#endif
886
887/* len can't be 0 here anyway...
888                } else if ((offset == 0x00001000) && (len == 0x00000000)) {
889
890                        aimbs_put32(&fr->data, 0xd41d8cd9);
891                        aimbs_put32(&fr->data, 0x8f00b204);
892                        aimbs_put32(&fr->data, 0xe9800998);
893                        aimbs_put32(&fr->data, 0xecf8427e);
894*/
895                } else
896                        imcb_error(sess->aux_data, "Warning: unknown hash request");
897
898        }
899
900        aim_tx_enqueue(sess, fr);
901
902        return 0;
903}
904
905static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
906{
907
908        if (snac->subtype == 0x0003)
909                return hostonline(sess, mod, rx, snac, bs);
910        else if (snac->subtype == 0x0005)
911                return redirect(sess, mod, rx, snac, bs);
912        else if (snac->subtype == 0x0007)
913                return rateresp(sess, mod, rx, snac, bs);
914        else if (snac->subtype == 0x000a)
915                return ratechange(sess, mod, rx, snac, bs);
916        else if (snac->subtype == 0x000b)
917                return serverpause(sess, mod, rx, snac, bs);
918        else if (snac->subtype == 0x000d)
919                return serverresume(sess, mod, rx, snac, bs);
920        else if (snac->subtype == 0x000f)
921                return selfinfo(sess, mod, rx, snac, bs);
922        else if (snac->subtype == 0x0010)
923                return evilnotify(sess, mod, rx, snac, bs);
924        else if (snac->subtype == 0x0012)
925                return migrate(sess, mod, rx, snac, bs);
926        else if (snac->subtype == 0x0013)
927                return motd(sess, mod, rx, snac, bs);
928        else if (snac->subtype == 0x0018)
929                return hostversions(sess, mod, rx, snac, bs);
930        else if (snac->subtype == 0x001f)
931                return memrequest(sess, mod, rx, snac, bs);
932
933        return 0;
934}
935
936int general_modfirst(aim_session_t *sess, aim_module_t *mod)
937{
938
939        mod->family = 0x0001;
940        mod->version = 0x0003;
941        mod->toolid = 0x0110;
942        mod->toolversion = 0x0629;
943        mod->flags = 0;
944        strncpy(mod->name, "general", sizeof(mod->name));
945        mod->snachandler = snachandler;
946
947        return 0;
948}
949
Note: See TracBrowser for help on using the repository browser.