1535
|
1 /*
|
|
2 * aim_login.c
|
|
3 *
|
|
4 * This contains all the functions needed to actually login.
|
|
5 *
|
|
6 */
|
|
7
|
|
8 #define FAIM_INTERNAL
|
|
9 #include <aim.h>
|
|
10
|
|
11 #include "md5.h"
|
|
12
|
|
13 static int aim_encode_password(const char *password, unsigned char *encoded);
|
|
14
|
|
15 faim_export int aim_sendconnack(struct aim_session_t *sess,
|
|
16 struct aim_conn_t *conn)
|
|
17 {
|
|
18 int curbyte=0;
|
|
19
|
|
20 struct command_tx_struct *newpacket;
|
|
21
|
|
22 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0001, 4)))
|
|
23 return -1;
|
|
24
|
|
25 newpacket->lock = 1;
|
|
26
|
|
27 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
|
|
28 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
|
|
29
|
|
30 newpacket->lock = 0;
|
|
31 return aim_tx_enqueue(sess, newpacket);
|
|
32 }
|
|
33
|
|
34 /*
|
|
35 * In AIM 3.5 protocol, the first stage of login is to request
|
|
36 * login from the Authorizer, passing it the screen name
|
|
37 * for verification. If the name is invalid, a 0017/0003
|
|
38 * is spit back, with the standard error contents. If valid,
|
|
39 * a 0017/0007 comes back, which is the signal to send
|
|
40 * it the main login command (0017/0002).
|
|
41 */
|
|
42 faim_export int aim_request_login(struct aim_session_t *sess,
|
|
43 struct aim_conn_t *conn,
|
|
44 char *sn)
|
|
45 {
|
|
46 int curbyte;
|
|
47 struct command_tx_struct *newpacket;
|
|
48
|
|
49 if (!sess || !conn || !sn)
|
|
50 return -1;
|
|
51
|
|
52 /*
|
|
53 * For ICQ, we enable the ancient horrible login and stuff
|
|
54 * a key packet into the queue to make it look like we got
|
|
55 * a reply back. This is so the client doesn't know we're
|
|
56 * really not doing MD5 login.
|
|
57 *
|
|
58 * This may sound stupid, but I'm not in the best of moods and
|
|
59 * I don't plan to keep support for this crap around much longer.
|
|
60 * Its all AOL's fault anyway, really. I hate AOL. Really. They
|
|
61 * always seem to be able to piss me off by doing the dumbest little
|
|
62 * things. Like disabling MD5 logins for ICQ UINs, or adding purposefully
|
|
63 * wrong TLV lengths, or adding superfluous information to host strings,
|
|
64 * or... I'll stop.
|
|
65 *
|
|
66 */
|
|
67 if ((sn[0] >= '0') && (sn[0] <= '9')) {
|
|
68 struct command_rx_struct *newrx;
|
|
69 int i;
|
|
70
|
|
71 if (!(newrx = (struct command_rx_struct *)malloc(sizeof(struct command_rx_struct))))
|
|
72 return -1;
|
|
73 memset(newrx, 0x00, sizeof(struct command_rx_struct));
|
|
74 newrx->lock = 1;
|
|
75 newrx->hdrtype = AIM_FRAMETYPE_OSCAR;
|
|
76 newrx->hdr.oscar.type = 0x02;
|
|
77 newrx->hdr.oscar.seqnum = 0;
|
|
78 newrx->commandlen = 10+2+1;
|
|
79 newrx->nofree = 0;
|
|
80 if (!(newrx->data = malloc(newrx->commandlen))) {
|
|
81 free(newrx);
|
|
82 return -1;
|
|
83 }
|
|
84
|
|
85 i = aim_putsnac(newrx->data, 0x0017, 0x0007, 0x0000, 0x0000);
|
|
86 i += aimutil_put16(newrx->data+i, 0x01);
|
|
87 i += aimutil_putstr(newrx->data+i, "0", 1);
|
|
88
|
|
89 newrx->conn = conn;
|
|
90
|
|
91 newrx->next = sess->queue_incoming;
|
|
92 sess->queue_incoming = newrx;
|
|
93
|
|
94 newrx->lock = 0;
|
|
95
|
|
96 sess->flags &= ~AIM_SESS_FLAGS_SNACLOGIN;
|
|
97
|
|
98 return 0;
|
|
99 }
|
|
100
|
|
101 sess->flags |= AIM_SESS_FLAGS_SNACLOGIN;
|
|
102
|
|
103 aim_sendconnack(sess, conn);
|
|
104
|
|
105 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+2+2+strlen(sn))))
|
|
106 return -1;
|
|
107
|
|
108 newpacket->lock = 1;
|
|
109
|
|
110 curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0006, 0x0000, 0x00010000);
|
|
111 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn);
|
|
112
|
|
113 newpacket->commandlen = curbyte;
|
|
114 newpacket->lock = 0;
|
|
115
|
|
116 return aim_tx_enqueue(sess, newpacket);
|
|
117 }
|
|
118
|
|
119 /*
|
|
120 * send_login(int socket, char *sn, char *password)
|
|
121 *
|
|
122 * This is the initial login request packet.
|
|
123 *
|
|
124 * The password is encoded before transmition, as per
|
|
125 * encode_password(). See that function for their
|
|
126 * stupid method of doing it.
|
|
127 *
|
|
128 * Latest WinAIM:
|
|
129 * clientstring = "AOL Instant Messenger (SM), version 4.3.2188/WIN32"
|
|
130 * major2 = 0x0109
|
|
131 * major = 0x0400
|
|
132 * minor = 0x0003
|
|
133 * minor2 = 0x0000
|
|
134 * build = 0x088c
|
|
135 * unknown = 0x00000086
|
|
136 * lang = "en"
|
|
137 * country = "us"
|
|
138 * unknown4a = 0x01
|
1649
|
139 *
|
|
140 * Latest WinAIM that libfaim can emulate without server-side buddylists:
|
|
141 * clientstring = "AOL Instant Messenger (SM), version 3.5.1670/WIN32"
|
|
142 * major2 = 0x0004
|
|
143 * major = 0x0003
|
|
144 * minor = 0x0005
|
|
145 * minor2 = 0x0000
|
|
146 * build = 0x0686
|
|
147 * unknown =0x0000002a
|
|
148 *
|
1535
|
149 */
|
|
150 faim_export int aim_send_login (struct aim_session_t *sess,
|
|
151 struct aim_conn_t *conn,
|
|
152 char *sn, char *password,
|
|
153 struct client_info_s *clientinfo,
|
|
154 char *key)
|
|
155 {
|
|
156 int curbyte=0;
|
|
157 struct command_tx_struct *newpacket;
|
|
158
|
|
159 if (!clientinfo || !sn || !password)
|
|
160 return -1;
|
|
161
|
|
162 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
|
|
163 return -1;
|
|
164
|
|
165 newpacket->lock = 1;
|
|
166
|
|
167 newpacket->hdr.oscar.type = (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)?0x02:0x01;
|
|
168
|
|
169 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)
|
|
170 curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0002, 0x0000, 0x00010000);
|
|
171 else {
|
|
172 curbyte = aimutil_put16(newpacket->data, 0x0000);
|
|
173 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
|
|
174 }
|
|
175
|
|
176 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn);
|
|
177
|
|
178 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
|
1649
|
179 unsigned char digest[16];
|
1535
|
180
|
|
181 aim_encode_password_md5(password, key, digest);
|
|
182 curbyte+= aim_puttlv_str(newpacket->data+curbyte, 0x0025, 16, (char *)digest);
|
|
183 } else {
|
|
184 char *password_encoded;
|
|
185
|
|
186 password_encoded = (char *) malloc(strlen(password));
|
|
187 aim_encode_password(password, password_encoded);
|
|
188 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0002, strlen(password), password_encoded);
|
|
189 free(password_encoded);
|
|
190 }
|
|
191
|
1649
|
192 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0003, strlen(clientinfo->clientstring), clientinfo->clientstring);
|
1535
|
193
|
|
194 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
|
1649
|
195
|
1535
|
196 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, (unsigned short)clientinfo->major2);
|
|
197 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, (unsigned short)clientinfo->major);
|
|
198 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, (unsigned short)clientinfo->minor);
|
|
199 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, (unsigned short)clientinfo->minor2);
|
|
200 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, (unsigned short)clientinfo->build);
|
|
201
|
|
202 } else {
|
|
203 /* Use very specific version numbers, to further indicate the hack. */
|
|
204 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, 0x010a);
|
|
205 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, 0x0004);
|
|
206 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, 0x003c);
|
|
207 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, 0x0001);
|
|
208 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, 0x0cce);
|
|
209 curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, 0x00000055);
|
|
210 }
|
|
211
|
1649
|
212 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000e, strlen(clientinfo->country), clientinfo->country);
|
|
213 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000f, strlen(clientinfo->lang), clientinfo->lang);
|
|
214
|
|
215 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
|
|
216 curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, clientinfo->unknown);
|
|
217 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0009, 0x0015);
|
|
218 }
|
1535
|
219
|
|
220 newpacket->commandlen = curbyte;
|
|
221
|
|
222 newpacket->lock = 0;
|
|
223 return aim_tx_enqueue(sess, newpacket);
|
|
224 }
|
|
225
|
1649
|
226 faim_export int aim_encode_password_md5(const char *password, const char *key, unsigned char *digest)
|
1535
|
227 {
|
|
228 md5_state_t state;
|
|
229
|
|
230 md5_init(&state);
|
|
231 md5_append(&state, (const md5_byte_t *)key, strlen(key));
|
|
232 md5_append(&state, (const md5_byte_t *)password, strlen(password));
|
|
233 md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
|
|
234 md5_finish(&state, (md5_byte_t *)digest);
|
|
235
|
|
236 return 0;
|
|
237 }
|
|
238
|
|
239 /**
|
|
240 * aim_encode_password - Encode a password using old XOR method
|
|
241 * @password: incoming password
|
|
242 * @encoded: buffer to put encoded password
|
|
243 *
|
|
244 * This takes a const pointer to a (null terminated) string
|
|
245 * containing the unencoded password. It also gets passed
|
|
246 * an already allocated buffer to store the encoded password.
|
|
247 * This buffer should be the exact length of the password without
|
|
248 * the null. The encoded password buffer /is not %NULL terminated/.
|
|
249 *
|
|
250 * The encoding_table seems to be a fixed set of values. We'll
|
|
251 * hope it doesn't change over time!
|
|
252 *
|
|
253 * This is only used for the XOR method, not the better MD5 method.
|
|
254 *
|
|
255 */
|
|
256 static int aim_encode_password(const char *password, unsigned char *encoded)
|
|
257 {
|
|
258 u_char encoding_table[] = {
|
|
259 #if 0 /* old v1 table */
|
|
260 0xf3, 0xb3, 0x6c, 0x99,
|
|
261 0x95, 0x3f, 0xac, 0xb6,
|
|
262 0xc5, 0xfa, 0x6b, 0x63,
|
|
263 0x69, 0x6c, 0xc3, 0x9f
|
|
264 #else /* v2.1 table, also works for ICQ */
|
|
265 0xf3, 0x26, 0x81, 0xc4,
|
|
266 0x39, 0x86, 0xdb, 0x92,
|
|
267 0x71, 0xa3, 0xb9, 0xe6,
|
|
268 0x53, 0x7a, 0x95, 0x7c
|
|
269 #endif
|
|
270 };
|
|
271
|
|
272 int i;
|
|
273
|
|
274 for (i = 0; i < strlen(password); i++)
|
|
275 encoded[i] = (password[i] ^ encoding_table[i]);
|
|
276
|
|
277 return 0;
|
|
278 }
|
|
279
|
|
280 /*
|
|
281 * Generate an authorization response.
|
|
282 *
|
|
283 * You probably don't want this unless you're writing an AIM server.
|
|
284 *
|
|
285 */
|
|
286 faim_export unsigned long aim_sendauthresp(struct aim_session_t *sess,
|
|
287 struct aim_conn_t *conn,
|
|
288 char *sn, int errorcode,
|
|
289 char *errorurl, char *bosip,
|
|
290 char *cookie, char *email,
|
|
291 int regstatus)
|
|
292 {
|
|
293 struct command_tx_struct *tx;
|
|
294 struct aim_tlvlist_t *tlvlist = NULL;
|
|
295
|
|
296 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0004, 1152)))
|
|
297 return -1;
|
|
298
|
|
299 tx->lock = 1;
|
|
300
|
|
301 if (sn)
|
|
302 aim_addtlvtochain_str(&tlvlist, 0x0001, sn, strlen(sn));
|
|
303 else
|
|
304 aim_addtlvtochain_str(&tlvlist, 0x0001, sess->sn, strlen(sess->sn));
|
|
305
|
|
306 if (errorcode) {
|
|
307 aim_addtlvtochain16(&tlvlist, 0x0008, errorcode);
|
|
308 aim_addtlvtochain_str(&tlvlist, 0x0004, errorurl, strlen(errorurl));
|
|
309 } else {
|
|
310 aim_addtlvtochain_str(&tlvlist, 0x0005, bosip, strlen(bosip));
|
|
311 aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
|
|
312 aim_addtlvtochain_str(&tlvlist, 0x0011, email, strlen(email));
|
|
313 aim_addtlvtochain16(&tlvlist, 0x0013, (unsigned short)regstatus);
|
|
314 }
|
|
315
|
|
316 tx->commandlen = aim_writetlvchain(tx->data, tx->commandlen, &tlvlist);
|
|
317 tx->lock = 0;
|
|
318
|
|
319 return aim_tx_enqueue(sess, tx);
|
|
320 }
|
|
321
|
|
322 /*
|
|
323 * Generate a random cookie. (Non-client use only)
|
|
324 */
|
|
325 faim_export int aim_gencookie(unsigned char *buf)
|
|
326 {
|
|
327 int i;
|
|
328
|
|
329 srand(time(NULL));
|
|
330
|
|
331 for (i=0; i < AIM_COOKIELEN; i++)
|
|
332 buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0));
|
|
333
|
|
334 return i;
|
|
335 }
|
|
336
|
|
337 /*
|
|
338 * Send Server Ready. (Non-client)
|
|
339 */
|
|
340 faim_export int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn)
|
|
341 {
|
|
342 struct command_tx_struct *tx;
|
|
343 int i = 0;
|
|
344
|
|
345 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+0x22)))
|
|
346 return -1;
|
|
347
|
|
348 tx->lock = 1;
|
|
349
|
|
350 i += aim_putsnac(tx->data, 0x0001, 0x0003, 0x0000, sess->snac_nextid++);
|
|
351
|
|
352 i += aimutil_put16(tx->data+i, 0x0001);
|
|
353 i += aimutil_put16(tx->data+i, 0x0002);
|
|
354 i += aimutil_put16(tx->data+i, 0x0003);
|
|
355 i += aimutil_put16(tx->data+i, 0x0004);
|
|
356 i += aimutil_put16(tx->data+i, 0x0006);
|
|
357 i += aimutil_put16(tx->data+i, 0x0008);
|
|
358 i += aimutil_put16(tx->data+i, 0x0009);
|
|
359 i += aimutil_put16(tx->data+i, 0x000a);
|
|
360 i += aimutil_put16(tx->data+i, 0x000b);
|
|
361 i += aimutil_put16(tx->data+i, 0x000c);
|
|
362 i += aimutil_put16(tx->data+i, 0x0013);
|
|
363 i += aimutil_put16(tx->data+i, 0x0015);
|
|
364
|
|
365 tx->commandlen = i;
|
|
366 tx->lock = 0;
|
|
367 return aim_tx_enqueue(sess, tx);
|
|
368 }
|
|
369
|
|
370
|
|
371 /*
|
|
372 * Send service redirect. (Non-Client)
|
|
373 */
|
|
374 faim_export unsigned long aim_sendredirect(struct aim_session_t *sess,
|
|
375 struct aim_conn_t *conn,
|
|
376 unsigned short servid,
|
|
377 char *ip,
|
|
378 char *cookie)
|
|
379 {
|
|
380 struct command_tx_struct *tx;
|
|
381 struct aim_tlvlist_t *tlvlist = NULL;
|
|
382 int i = 0;
|
|
383
|
|
384 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
|
|
385 return -1;
|
|
386
|
|
387 tx->lock = 1;
|
|
388
|
|
389 i += aim_putsnac(tx->data+i, 0x0001, 0x0005, 0x0000, 0x00000000);
|
|
390
|
|
391 aim_addtlvtochain16(&tlvlist, 0x000d, servid);
|
|
392 aim_addtlvtochain_str(&tlvlist, 0x0005, ip, strlen(ip));
|
|
393 aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
|
|
394
|
|
395 tx->commandlen = aim_writetlvchain(tx->data+i, tx->commandlen-i, &tlvlist)+i;
|
|
396 aim_freetlvchain(&tlvlist);
|
|
397
|
|
398 tx->lock = 0;
|
|
399 return aim_tx_enqueue(sess, tx);
|
|
400 }
|
1649
|
401
|
|
402
|
|
403 static int hostonline(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
404 {
|
|
405 rxcallback_t userfunc;
|
|
406 int ret = 0;
|
|
407 unsigned short *families;
|
|
408 int famcount, i;
|
|
409
|
|
410 famcount = datalen/2;
|
|
411
|
|
412 if (!(families = malloc(datalen)))
|
|
413 return 0;
|
|
414
|
|
415 for (i = 0; i < famcount; i++)
|
|
416 families[i] = aimutil_get16(data+(i*2));
|
|
417
|
|
418 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
419 ret = userfunc(sess, rx, famcount, families);
|
|
420
|
|
421 free(families);
|
|
422
|
|
423 return ret;
|
|
424 }
|
|
425
|
|
426 static int redirect(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
427 {
|
|
428 int serviceid;
|
|
429 unsigned char *cookie;
|
|
430 char *ip;
|
|
431 rxcallback_t userfunc;
|
|
432 struct aim_tlvlist_t *tlvlist;
|
|
433 char *chathack = NULL;
|
|
434 int chathackex = 0;
|
|
435 int ret = 0;
|
|
436
|
|
437 tlvlist = aim_readtlvchain(data, datalen);
|
|
438
|
|
439 if (!aim_gettlv(tlvlist, 0x000d, 1) ||
|
|
440 !aim_gettlv(tlvlist, 0x0005, 1) ||
|
|
441 !aim_gettlv(tlvlist, 0x0006, 1)) {
|
|
442 aim_freetlvchain(&tlvlist);
|
|
443 return 0;
|
|
444 }
|
|
445
|
|
446 serviceid = aim_gettlv16(tlvlist, 0x000d, 1);
|
|
447 ip = aim_gettlv_str(tlvlist, 0x0005, 1);
|
|
448 cookie = aim_gettlv_str(tlvlist, 0x0006, 1);
|
|
449
|
|
450 /*
|
|
451 * Chat hack.
|
|
452 *
|
|
453 */
|
|
454 if ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) {
|
|
455 chathack = sess->pendingjoin;
|
|
456 chathackex = sess->pendingjoinexchange;
|
|
457 sess->pendingjoin = NULL;
|
|
458 sess->pendingjoinexchange = 0;
|
|
459 }
|
|
460
|
|
461 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
462 ret = userfunc(sess, rx, serviceid, ip, cookie, chathack, chathackex);
|
|
463
|
|
464 free(ip);
|
|
465 free(cookie);
|
|
466 free(chathack);
|
|
467
|
|
468 aim_freetlvchain(&tlvlist);
|
|
469
|
|
470 return ret;
|
|
471 }
|
|
472
|
|
473 /*
|
|
474 * The Rate Limiting System, An Abridged Guide to Nonsense.
|
|
475 *
|
|
476 * OSCAR defines several 'rate classes'. Each class has seperate
|
|
477 * rate limiting properties (limit level, alert level, disconnect
|
|
478 * level, etc), and a set of SNAC family/type pairs associated with
|
|
479 * it. The rate classes, their limiting properties, and the definitions
|
|
480 * of which SNACs are belong to which class, are defined in the
|
|
481 * Rate Response packet at login to each host.
|
|
482 *
|
|
483 * Logically, all rate offenses within one class count against further
|
|
484 * offenses for other SNACs in the same class (ie, sending messages
|
|
485 * too fast will limit the number of user info requests you can send,
|
|
486 * since those two SNACs are in the same rate class).
|
|
487 *
|
|
488 * Since the rate classes are defined dynamically at login, the values
|
|
489 * below may change. But they seem to be fairly constant.
|
|
490 *
|
|
491 * Currently, BOS defines five rate classes, with the commonly used
|
|
492 * members as follows...
|
|
493 *
|
|
494 * Rate class 0x0001:
|
|
495 * - Everything thats not in any of the other classes
|
|
496 *
|
|
497 * Rate class 0x0002:
|
|
498 * - Buddy list add/remove
|
|
499 * - Permit list add/remove
|
|
500 * - Deny list add/remove
|
|
501 *
|
|
502 * Rate class 0x0003:
|
|
503 * - User information requests
|
|
504 * - Outgoing ICBMs
|
|
505 *
|
|
506 * Rate class 0x0004:
|
|
507 * - A few unknowns: 2/9, 2/b, and f/2
|
|
508 *
|
|
509 * Rate class 0x0005:
|
|
510 * - Chat room create
|
|
511 * - Outgoing chat ICBMs
|
|
512 *
|
|
513 * The only other thing of note is that class 5 (chat) has slightly looser
|
|
514 * limiting properties than class 3 (normal messages). But thats just a
|
|
515 * small bit of trivia for you.
|
|
516 *
|
|
517 * The last thing that needs to be learned about the rate limiting
|
|
518 * system is how the actual numbers relate to the passing of time. This
|
|
519 * seems to be a big mystery.
|
|
520 *
|
|
521 */
|
|
522
|
|
523 /* XXX parse this */
|
|
524 static int rateresp(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
525 {
|
|
526 rxcallback_t userfunc;
|
|
527
|
|
528 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
529 return userfunc(sess, rx);
|
|
530
|
|
531 return 0;
|
|
532 }
|
|
533
|
|
534 static int ratechange(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
535 {
|
|
536 rxcallback_t userfunc;
|
|
537 int i = 0, code;
|
|
538 unsigned long currentavg, maxavg;
|
|
539 unsigned long rateclass, windowsize, clear, alert, limit, disconnect;
|
|
540
|
|
541 code = aimutil_get16(data+i);
|
|
542 i += 2;
|
|
543
|
|
544 rateclass = aimutil_get16(data+i);
|
|
545 i += 2;
|
|
546
|
|
547 windowsize = aimutil_get32(data+i);
|
|
548 i += 4;
|
|
549 clear = aimutil_get32(data+i);
|
|
550 i += 4;
|
|
551 alert = aimutil_get32(data+i);
|
|
552 i += 4;
|
|
553 limit = aimutil_get32(data+i);
|
|
554 i += 4;
|
|
555 disconnect = aimutil_get32(data+i);
|
|
556 i += 4;
|
|
557 currentavg = aimutil_get32(data+i);
|
|
558 i += 4;
|
|
559 maxavg = aimutil_get32(data+i);
|
|
560 i += 4;
|
|
561
|
|
562 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
563 return userfunc(sess, rx, code, rateclass, windowsize, clear, alert, limit, disconnect, currentavg, maxavg);
|
|
564
|
|
565 return 0;
|
|
566 }
|
|
567
|
|
568 /* XXX parse this */
|
|
569 static int selfinfo(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
570 {
|
|
571 rxcallback_t userfunc;
|
|
572
|
|
573 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
574 return userfunc(sess, rx);
|
|
575
|
|
576 return 0;
|
|
577 }
|
|
578
|
|
579 static int evilnotify(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
580 {
|
|
581 rxcallback_t userfunc = NULL;
|
|
582 int i = 0;
|
|
583 unsigned short newevil;
|
|
584 struct aim_userinfo_s userinfo;
|
|
585
|
|
586 newevil = aimutil_get16(data);
|
|
587 i += 2;
|
|
588
|
|
589 memset(&userinfo, 0, sizeof(struct aim_userinfo_s));
|
|
590
|
|
591 if (datalen-i)
|
|
592 i += aim_extractuserinfo(sess, data+i, &userinfo);
|
|
593
|
|
594 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
595 return userfunc(sess, rx, newevil, &userinfo);
|
|
596
|
|
597 return 0;
|
|
598 }
|
|
599
|
|
600 static int motd(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
601 {
|
|
602 rxcallback_t userfunc;
|
|
603 char *msg = NULL;
|
|
604 int ret = 0;
|
|
605 struct aim_tlvlist_t *tlvlist;
|
|
606 unsigned short id;
|
|
607
|
|
608 /*
|
|
609 * Code.
|
|
610 *
|
|
611 * Valid values:
|
|
612 * 1 Mandatory upgrade
|
|
613 * 2 Advisory upgrade
|
|
614 * 3 System bulletin
|
|
615 * 4 Nothing's wrong ("top o the world" -- normal)
|
|
616 *
|
|
617 */
|
|
618 id = aimutil_get16(data);
|
|
619
|
|
620 /*
|
|
621 * TLVs follow
|
|
622 */
|
|
623 if ((tlvlist = aim_readtlvchain(data+2, datalen-2)))
|
|
624 msg = aim_gettlv_str(tlvlist, 0x000b, 1);
|
|
625
|
|
626 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
627 ret = userfunc(sess, rx, id, msg);
|
|
628
|
|
629 free(msg);
|
|
630
|
|
631 aim_freetlvchain(&tlvlist);
|
|
632
|
|
633 return ret;
|
|
634 }
|
|
635
|
|
636 static int hostversions(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
637 {
|
|
638 rxcallback_t userfunc;
|
|
639 int vercount;
|
|
640
|
|
641 vercount = datalen/4;
|
|
642
|
|
643 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
644 return userfunc(sess, rx, vercount, data);
|
|
645
|
|
646 return 0;
|
|
647 }
|
|
648
|
|
649 static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
|
|
650 {
|
|
651
|
|
652 if (snac->subtype == 0x0003)
|
|
653 return hostonline(sess, mod, rx, snac, data, datalen);
|
|
654 else if (snac->subtype == 0x0005)
|
|
655 return redirect(sess, mod, rx, snac, data, datalen);
|
|
656 else if (snac->subtype == 0x0007)
|
|
657 return rateresp(sess, mod, rx, snac, data, datalen);
|
|
658 else if (snac->subtype == 0x000a)
|
|
659 return ratechange(sess, mod, rx, snac, data, datalen);
|
|
660 else if (snac->subtype == 0x000f)
|
|
661 return selfinfo(sess, mod, rx, snac, data, datalen);
|
|
662 else if (snac->subtype == 0x0010)
|
|
663 return evilnotify(sess, mod, rx, snac, data, datalen);
|
|
664 else if (snac->subtype == 0x0013)
|
|
665 return motd(sess, mod, rx, snac, data, datalen);
|
|
666 else if (snac->subtype == 0x0018)
|
|
667 return hostversions(sess, mod, rx, snac, data, datalen);
|
|
668
|
|
669 return 0;
|
|
670 }
|
|
671
|
|
672 faim_internal int general_modfirst(struct aim_session_t *sess, aim_module_t *mod)
|
|
673 {
|
|
674
|
|
675 mod->family = 0x0001;
|
|
676 mod->version = 0x0000;
|
|
677 mod->flags = 0;
|
|
678 strncpy(mod->name, "general", sizeof(mod->name));
|
|
679 mod->snachandler = snachandler;
|
|
680
|
|
681 return 0;
|
|
682 }
|