4 * Deals with the authorizer.
11 /* this just pushes the passed cookie onto the passed connection -- NO SNAC! */
12 faim_export int aim_auth_sendcookie(aim_session_t *sess, aim_conn_t *conn, const fu8_t *chipsahoy)
15 aim_tlvlist_t *tl = NULL;
17 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4+2+2+AIM_COOKIELEN)))
20 aimbs_put32(&fr->data, 0x00000001);
21 aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy);
22 aim_writetlvchain(&fr->data, &tl);
23 aim_freetlvchain(&tl);
25 aim_tx_enqueue(sess, fr);
31 * This is sent back as a general response to the login command.
32 * It can be either an error or a success, depending on the
33 * precense of certain TLVs.
35 * The client should check the value passed as errorcode. If
36 * its nonzero, there was an error.
39 static int parse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
41 aim_tlvlist_t *tlvlist;
43 aim_rxcallback_t userfunc;
44 char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL;
45 unsigned char *cookie = NULL;
46 int errorcode = 0, regstatus = 0;
47 int latestbuild = 0, latestbetabuild = 0;
48 char *latestrelease = NULL, *latestbeta = NULL;
49 char *latestreleaseurl = NULL, *latestbetaurl = NULL;
50 char *latestreleaseinfo = NULL, *latestbetainfo = NULL;
53 * Read block of TLVs. All further data is derived
54 * from what is parsed here.
56 tlvlist = aim_readtlvchain(bs);
59 * No matter what, we should have a screen name.
61 memset(sess->sn, 0, sizeof(sess->sn));
62 if (aim_gettlv(tlvlist, 0x0001, 1)) {
63 sn = aim_gettlv_str(tlvlist, 0x0001, 1);
64 strncpy(sess->sn, sn, sizeof(sess->sn));
68 * Check for an error code. If so, we should also
71 if (aim_gettlv(tlvlist, 0x0008, 1))
72 errorcode = aim_gettlv16(tlvlist, 0x0008, 1);
73 if (aim_gettlv(tlvlist, 0x0004, 1))
74 errurl = aim_gettlv_str(tlvlist, 0x0004, 1);
79 if (aim_gettlv(tlvlist, 0x0005, 1))
80 bosip = aim_gettlv_str(tlvlist, 0x0005, 1);
83 * Authorization cookie.
85 if (aim_gettlv(tlvlist, 0x0006, 1)) {
88 tmptlv = aim_gettlv(tlvlist, 0x0006, 1);
90 if ((cookie = malloc(tmptlv->length)))
91 memcpy(cookie, tmptlv->value, tmptlv->length);
95 * The email address attached to this account
96 * Not available for ICQ logins.
98 if (aim_gettlv(tlvlist, 0x0011, 1))
99 email = aim_gettlv_str(tlvlist, 0x0011, 1);
102 * The registration status. (Not real sure what it means.)
103 * Not available for ICQ logins.
106 * 2 = Limited disclosure
107 * 3 = Full disclosure
109 * This has to do with whether your email address is available
110 * to other users or not. AFAIK, this feature is no longer used.
113 if (aim_gettlv(tlvlist, 0x0013, 1))
114 regstatus = aim_gettlv16(tlvlist, 0x0013, 1);
116 if (aim_gettlv(tlvlist, 0x0040, 1))
117 latestbetabuild = aim_gettlv32(tlvlist, 0x0040, 1);
118 if (aim_gettlv(tlvlist, 0x0041, 1))
119 latestbetaurl = aim_gettlv_str(tlvlist, 0x0041, 1);
120 if (aim_gettlv(tlvlist, 0x0042, 1))
121 latestbetainfo = aim_gettlv_str(tlvlist, 0x0042, 1);
122 if (aim_gettlv(tlvlist, 0x0043, 1))
123 latestbeta = aim_gettlv_str(tlvlist, 0x0043, 1);
124 if (aim_gettlv(tlvlist, 0x0048, 1))
125 ; /* no idea what this is */
127 if (aim_gettlv(tlvlist, 0x0044, 1))
128 latestbuild = aim_gettlv32(tlvlist, 0x0044, 1);
129 if (aim_gettlv(tlvlist, 0x0045, 1))
130 latestreleaseurl = aim_gettlv_str(tlvlist, 0x0045, 1);
131 if (aim_gettlv(tlvlist, 0x0046, 1))
132 latestreleaseinfo = aim_gettlv_str(tlvlist, 0x0046, 1);
133 if (aim_gettlv(tlvlist, 0x0047, 1))
134 latestrelease = aim_gettlv_str(tlvlist, 0x0047, 1);
135 if (aim_gettlv(tlvlist, 0x0049, 1))
136 ; /* no idea what this is */
139 if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003))) {
140 /* XXX return as a struct? */
141 ret = userfunc(sess, rx, sn, errorcode, errurl, regstatus, email, bosip, cookie, latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo, latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
150 free(latestreleaseurl);
153 free(latestreleaseinfo);
154 free(latestbetainfo);
156 aim_freetlvchain(&tlvlist);
162 * Middle handler for 0017/0007 SNACs. Contains the auth key prefixed
163 * by only its length in a two byte word.
165 * Calls the client, which should then use the value to call aim_send_login.
168 static int keyparse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
171 aim_rxcallback_t userfunc;
174 keylen = aimbs_get16(bs);
175 keystr = aimbs_getstr(bs, keylen);
177 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
178 ret = userfunc(sess, rx, keystr);
185 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
188 if (snac->subtype == 0x0003)
189 return parse(sess, mod, rx, snac, bs);
190 else if (snac->subtype == 0x0007)
191 return keyparse(sess, mod, rx, snac, bs);
196 faim_internal int auth_modfirst(aim_session_t *sess, aim_module_t *mod)
199 mod->family = 0x0017;
200 mod->version = 0x0000;
202 strncpy(mod->name, "auth", sizeof(mod->name));
203 mod->snachandler = snachandler;