source: protocols/oscar/service.c @ 727a68b

Last change on this file since 727a68b was e88fe7da, checked in by Veres Lajos <vlajos@…>, at 2015-08-07T21:53:25Z

typofix - https://github.com/vlajos/misspell_fixer

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