]> andersk Git - libfaim.git/blame - src/login.c
- Tue Mar 27 19:15:10 PST 2001
[libfaim.git] / src / login.c
CommitLineData
9de3ca7e 1/*
2 * aim_login.c
3 *
4 * This contains all the functions needed to actually login.
5 *
6 */
7
37ee990e 8#define FAIM_INTERNAL
dd60ff8b 9#include <aim.h>
9de3ca7e 10
b5bc2a8c 11#include "md5.h"
12
5daacaa3 13static int aim_encode_password(const char *password, unsigned char *encoded);
9de3ca7e 14
78b3fb13 15faim_export int aim_sendconnack(struct aim_session_t *sess,
16 struct aim_conn_t *conn)
01b59e1e 17{
18 int curbyte=0;
19
5b79dc93 20 struct command_tx_struct *newpacket;
01b59e1e 21
646c6b52 22 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0001, 4)))
01b59e1e 23 return -1;
24
5b79dc93 25 newpacket->lock = 1;
01b59e1e 26
5b79dc93 27 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
28 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
01b59e1e 29
5b79dc93 30 newpacket->lock = 0;
31 return aim_tx_enqueue(sess, newpacket);
01b59e1e 32}
33
01b59e1e 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 */
78b3fb13 42faim_export int aim_request_login(struct aim_session_t *sess,
43 struct aim_conn_t *conn,
44 char *sn)
01b59e1e 45{
5daacaa3 46 int curbyte;
5b79dc93 47 struct command_tx_struct *newpacket;
01b59e1e 48
5daacaa3 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
22517493 96 sess->flags &= ~AIM_SESS_FLAGS_SNACLOGIN;
97
5daacaa3 98 return 0;
99 }
100
22517493 101 sess->flags |= AIM_SESS_FLAGS_SNACLOGIN;
5daacaa3 102
103 aim_sendconnack(sess, conn);
104
646c6b52 105 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+2+2+strlen(sn))))
5b79dc93 106 return -1;
01b59e1e 107
5b79dc93 108 newpacket->lock = 1;
01b59e1e 109
5daacaa3 110 curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0006, 0x0000, 0x00010000);
5b79dc93 111 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn);
01b59e1e 112
5daacaa3 113 newpacket->commandlen = curbyte;
5b79dc93 114 newpacket->lock = 0;
5daacaa3 115
5b79dc93 116 return aim_tx_enqueue(sess, newpacket);
01b59e1e 117}
01b59e1e 118
9de3ca7e 119/*
24286d93 120 * send_login(int socket, char *sn, char *password)
9de3ca7e 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 *
355982c5 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
154b4093 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 *
d32954e7 149 * Java AIM 1.1.19:
150 * clientstring = "AOL Instant Messenger (TM) version 1.1.19 for Java built 03/24/98, freeMem 215871 totalMem 1048567, i686, Linus, #2 SMP Sun Feb 11 03:41:17 UTC 2001 2.4.1-ac9, IBM Corporation, 1.1.8, 45.3, Tue Mar 27 12:09:17 PST 2001"
151 * major2 = 0x0001
152 * major = 0x0001
153 * minor = 0x0001
154 * minor2 = (not sent)
155 * build = 0x0013
156 * unknown= (not sent)
157 *
158 * AIM for Linux 1.1.112:
159 * clientstring = "AOL Instant Messenger (SM)"
160 * major2 = 0x1d09
161 * major = 0x0001
162 * minor = 0x0001
163 * minor2 = 0x0001
164 * build = 0x0070
165 * unknown= 0x0000008b
166 * serverstore = 0x01
167 *
9de3ca7e 168 */
78b3fb13 169faim_export int aim_send_login (struct aim_session_t *sess,
170 struct aim_conn_t *conn,
171 char *sn, char *password,
172 struct client_info_s *clientinfo,
173 char *key)
9de3ca7e 174{
9de3ca7e 175 int curbyte=0;
5b79dc93 176 struct command_tx_struct *newpacket;
9de3ca7e 177
01b59e1e 178 if (!clientinfo || !sn || !password)
179 return -1;
180
646c6b52 181 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
5b79dc93 182 return -1;
9de3ca7e 183
5b79dc93 184 newpacket->lock = 1;
01b59e1e 185
22517493 186 newpacket->hdr.oscar.type = (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)?0x02:0x01;
b5bc2a8c 187
22517493 188 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)
5daacaa3 189 curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0002, 0x0000, 0x00010000);
190 else {
191 curbyte = aimutil_put16(newpacket->data, 0x0000);
192 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
193 }
b5bc2a8c 194
5daacaa3 195 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn);
9de3ca7e 196
22517493 197 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
9f1a4013 198 unsigned char digest[16];
5daacaa3 199
200 aim_encode_password_md5(password, key, digest);
201 curbyte+= aim_puttlv_str(newpacket->data+curbyte, 0x0025, 16, (char *)digest);
202 } else {
203 char *password_encoded;
204
205 password_encoded = (char *) malloc(strlen(password));
206 aim_encode_password(password, password_encoded);
207 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0002, strlen(password), password_encoded);
208 free(password_encoded);
209 }
210
e80a0fa9 211 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0003, strlen(clientinfo->clientstring), clientinfo->clientstring);
13ebc4c4 212
22517493 213 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
154b4093 214
5daacaa3 215 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, (unsigned short)clientinfo->major2);
216 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, (unsigned short)clientinfo->major);
217 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, (unsigned short)clientinfo->minor);
218 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, (unsigned short)clientinfo->minor2);
219 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, (unsigned short)clientinfo->build);
b5bc2a8c 220
5daacaa3 221 } else {
355982c5 222 /* Use very specific version numbers, to further indicate the hack. */
5daacaa3 223 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, 0x010a);
224 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, 0x0004);
225 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, 0x003c);
226 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, 0x0001);
227 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, 0x0cce);
228 curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, 0x00000055);
229 }
9de3ca7e 230
e80a0fa9 231 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000e, strlen(clientinfo->country), clientinfo->country);
232 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000f, strlen(clientinfo->lang), clientinfo->lang);
13ebc4c4 233
e80a0fa9 234 if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
235 curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, clientinfo->unknown);
236 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0009, 0x0015);
237 }
238
13ebc4c4 239 newpacket->commandlen = curbyte;
9de3ca7e 240
5b79dc93 241 newpacket->lock = 0;
242 return aim_tx_enqueue(sess, newpacket);
9de3ca7e 243}
9de3ca7e 244
9f1a4013 245faim_export int aim_encode_password_md5(const char *password, const char *key, unsigned char *digest)
b5bc2a8c 246{
247 md5_state_t state;
248
249 md5_init(&state);
250 md5_append(&state, (const md5_byte_t *)key, strlen(key));
251 md5_append(&state, (const md5_byte_t *)password, strlen(password));
252 md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
253 md5_finish(&state, (md5_byte_t *)digest);
254
255 return 0;
256}
257
5daacaa3 258/**
259 * aim_encode_password - Encode a password using old XOR method
260 * @password: incoming password
261 * @encoded: buffer to put encoded password
9de3ca7e 262 *
263 * This takes a const pointer to a (null terminated) string
264 * containing the unencoded password. It also gets passed
265 * an already allocated buffer to store the encoded password.
266 * This buffer should be the exact length of the password without
5daacaa3 267 * the null. The encoded password buffer /is not %NULL terminated/.
9de3ca7e 268 *
269 * The encoding_table seems to be a fixed set of values. We'll
270 * hope it doesn't change over time!
271 *
5daacaa3 272 * This is only used for the XOR method, not the better MD5 method.
b5bc2a8c 273 *
9de3ca7e 274 */
b5bc2a8c 275static int aim_encode_password(const char *password, unsigned char *encoded)
9de3ca7e 276{
277 u_char encoding_table[] = {
b69540e3 278#if 0 /* old v1 table */
9de3ca7e 279 0xf3, 0xb3, 0x6c, 0x99,
280 0x95, 0x3f, 0xac, 0xb6,
281 0xc5, 0xfa, 0x6b, 0x63,
282 0x69, 0x6c, 0xc3, 0x9f
b69540e3 283#else /* v2.1 table, also works for ICQ */
5e02cf44 284 0xf3, 0x26, 0x81, 0xc4,
b69540e3 285 0x39, 0x86, 0xdb, 0x92,
286 0x71, 0xa3, 0xb9, 0xe6,
287 0x53, 0x7a, 0x95, 0x7c
288#endif
5e02cf44 289 };
290
291 int i;
b69540e3 292
5e02cf44 293 for (i = 0; i < strlen(password); i++)
294 encoded[i] = (password[i] ^ encoding_table[i]);
295
296 return 0;
297}
298
e6b05d80 299/*
300 * Generate an authorization response.
301 *
302 * You probably don't want this unless you're writing an AIM server.
303 *
304 */
78b3fb13 305faim_export unsigned long aim_sendauthresp(struct aim_session_t *sess,
306 struct aim_conn_t *conn,
355982c5 307 char *sn, int errorcode,
308 char *errorurl, char *bosip,
78b3fb13 309 char *cookie, char *email,
310 int regstatus)
e6b05d80 311{
5b79dc93 312 struct command_tx_struct *tx;
e6b05d80 313 struct aim_tlvlist_t *tlvlist = NULL;
314
646c6b52 315 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0004, 1152)))
5b79dc93 316 return -1;
e6b05d80 317
5b79dc93 318 tx->lock = 1;
e6b05d80 319
320 if (sn)
321 aim_addtlvtochain_str(&tlvlist, 0x0001, sn, strlen(sn));
322 else
355982c5 323 aim_addtlvtochain_str(&tlvlist, 0x0001, sess->sn, strlen(sess->sn));
e6b05d80 324
355982c5 325 if (errorcode) {
326 aim_addtlvtochain16(&tlvlist, 0x0008, errorcode);
327 aim_addtlvtochain_str(&tlvlist, 0x0004, errorurl, strlen(errorurl));
e6b05d80 328 } else {
329 aim_addtlvtochain_str(&tlvlist, 0x0005, bosip, strlen(bosip));
330 aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
331 aim_addtlvtochain_str(&tlvlist, 0x0011, email, strlen(email));
5ac21963 332 aim_addtlvtochain16(&tlvlist, 0x0013, (unsigned short)regstatus);
e6b05d80 333 }
334
5b79dc93 335 tx->commandlen = aim_writetlvchain(tx->data, tx->commandlen, &tlvlist);
336 tx->lock = 0;
355982c5 337
5b79dc93 338 return aim_tx_enqueue(sess, tx);
e6b05d80 339}
340
341/*
342 * Generate a random cookie. (Non-client use only)
343 */
78b3fb13 344faim_export int aim_gencookie(unsigned char *buf)
e6b05d80 345{
346 int i;
347
348 srand(time(NULL));
349
350 for (i=0; i < AIM_COOKIELEN; i++)
351 buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0));
352
353 return i;
354}
355
356/*
357 * Send Server Ready. (Non-client)
358 */
78b3fb13 359faim_export int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn)
e6b05d80 360{
5b79dc93 361 struct command_tx_struct *tx;
e6b05d80 362 int i = 0;
363
646c6b52 364 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+0x22)))
5b79dc93 365 return -1;
e6b05d80 366
5b79dc93 367 tx->lock = 1;
e6b05d80 368
67c0bb2f 369 i += aim_putsnac(tx->data, 0x0001, 0x0003, 0x0000, sess->snac_nextid++);
5b79dc93 370
371 i += aimutil_put16(tx->data+i, 0x0001);
372 i += aimutil_put16(tx->data+i, 0x0002);
373 i += aimutil_put16(tx->data+i, 0x0003);
374 i += aimutil_put16(tx->data+i, 0x0004);
375 i += aimutil_put16(tx->data+i, 0x0006);
376 i += aimutil_put16(tx->data+i, 0x0008);
377 i += aimutil_put16(tx->data+i, 0x0009);
378 i += aimutil_put16(tx->data+i, 0x000a);
379 i += aimutil_put16(tx->data+i, 0x000b);
380 i += aimutil_put16(tx->data+i, 0x000c);
67c0bb2f 381 i += aimutil_put16(tx->data+i, 0x0013);
382 i += aimutil_put16(tx->data+i, 0x0015);
5b79dc93 383
67c0bb2f 384 tx->commandlen = i;
5b79dc93 385 tx->lock = 0;
5b79dc93 386 return aim_tx_enqueue(sess, tx);
e6b05d80 387}
388
389
390/*
391 * Send service redirect. (Non-Client)
392 */
78b3fb13 393faim_export unsigned long aim_sendredirect(struct aim_session_t *sess,
394 struct aim_conn_t *conn,
395 unsigned short servid,
396 char *ip,
397 char *cookie)
e6b05d80 398{
5b79dc93 399 struct command_tx_struct *tx;
e6b05d80 400 struct aim_tlvlist_t *tlvlist = NULL;
401 int i = 0;
402
646c6b52 403 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
5b79dc93 404 return -1;
405
406 tx->lock = 1;
e6b05d80 407
13ebc4c4 408 i += aim_putsnac(tx->data+i, 0x0001, 0x0005, 0x0000, 0x00000000);
e6b05d80 409
410 aim_addtlvtochain16(&tlvlist, 0x000d, servid);
411 aim_addtlvtochain_str(&tlvlist, 0x0005, ip, strlen(ip));
412 aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
413
5b79dc93 414 tx->commandlen = aim_writetlvchain(tx->data+i, tx->commandlen-i, &tlvlist)+i;
e6b05d80 415 aim_freetlvchain(&tlvlist);
416
5b79dc93 417 tx->lock = 0;
418 return aim_tx_enqueue(sess, tx);
e6b05d80 419}
00ef5271 420
421
422static 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)
423{
424 rxcallback_t userfunc;
425 int ret = 0;
426 unsigned short *families;
427 int famcount, i;
428
429 famcount = datalen/2;
430
431 if (!(families = malloc(datalen)))
432 return 0;
433
434 for (i = 0; i < famcount; i++)
435 families[i] = aimutil_get16(data+(i*2));
436
437 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
438 ret = userfunc(sess, rx, famcount, families);
439
440 free(families);
441
442 return ret;
443}
444
445static 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)
446{
447 int serviceid;
448 unsigned char *cookie;
449 char *ip;
450 rxcallback_t userfunc;
451 struct aim_tlvlist_t *tlvlist;
452 char *chathack = NULL;
453 int chathackex = 0;
454 int ret = 0;
455
456 tlvlist = aim_readtlvchain(data, datalen);
457
458 if (!aim_gettlv(tlvlist, 0x000d, 1) ||
459 !aim_gettlv(tlvlist, 0x0005, 1) ||
460 !aim_gettlv(tlvlist, 0x0006, 1)) {
461 aim_freetlvchain(&tlvlist);
462 return 0;
463 }
464
465 serviceid = aim_gettlv16(tlvlist, 0x000d, 1);
466 ip = aim_gettlv_str(tlvlist, 0x0005, 1);
467 cookie = aim_gettlv_str(tlvlist, 0x0006, 1);
468
469 /*
470 * Chat hack.
471 *
472 */
473 if ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) {
474 chathack = sess->pendingjoin;
475 chathackex = sess->pendingjoinexchange;
476 sess->pendingjoin = NULL;
477 sess->pendingjoinexchange = 0;
478 }
479
480 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
481 ret = userfunc(sess, rx, serviceid, ip, cookie, chathack, chathackex);
482
483 free(ip);
484 free(cookie);
485 free(chathack);
486
487 aim_freetlvchain(&tlvlist);
488
489 return ret;
490}
491
492/*
493 * The Rate Limiting System, An Abridged Guide to Nonsense.
494 *
495 * OSCAR defines several 'rate classes'. Each class has seperate
496 * rate limiting properties (limit level, alert level, disconnect
497 * level, etc), and a set of SNAC family/type pairs associated with
498 * it. The rate classes, their limiting properties, and the definitions
499 * of which SNACs are belong to which class, are defined in the
500 * Rate Response packet at login to each host.
501 *
502 * Logically, all rate offenses within one class count against further
503 * offenses for other SNACs in the same class (ie, sending messages
504 * too fast will limit the number of user info requests you can send,
505 * since those two SNACs are in the same rate class).
506 *
507 * Since the rate classes are defined dynamically at login, the values
508 * below may change. But they seem to be fairly constant.
509 *
510 * Currently, BOS defines five rate classes, with the commonly used
511 * members as follows...
512 *
513 * Rate class 0x0001:
514 * - Everything thats not in any of the other classes
515 *
516 * Rate class 0x0002:
517 * - Buddy list add/remove
518 * - Permit list add/remove
519 * - Deny list add/remove
520 *
521 * Rate class 0x0003:
522 * - User information requests
523 * - Outgoing ICBMs
524 *
525 * Rate class 0x0004:
526 * - A few unknowns: 2/9, 2/b, and f/2
527 *
528 * Rate class 0x0005:
529 * - Chat room create
530 * - Outgoing chat ICBMs
531 *
532 * The only other thing of note is that class 5 (chat) has slightly looser
533 * limiting properties than class 3 (normal messages). But thats just a
534 * small bit of trivia for you.
535 *
536 * The last thing that needs to be learned about the rate limiting
537 * system is how the actual numbers relate to the passing of time. This
538 * seems to be a big mystery.
539 *
540 */
541
542/* XXX parse this */
543static 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)
544{
545 rxcallback_t userfunc;
546
547 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
548 return userfunc(sess, rx);
549
550 return 0;
551}
552
553static 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)
554{
555 rxcallback_t userfunc;
556 int i = 0, code;
557 unsigned long currentavg, maxavg;
558 unsigned long rateclass, windowsize, clear, alert, limit, disconnect;
559
560 code = aimutil_get16(data+i);
561 i += 2;
562
563 rateclass = aimutil_get16(data+i);
564 i += 2;
565
566 windowsize = aimutil_get32(data+i);
567 i += 4;
568 clear = aimutil_get32(data+i);
569 i += 4;
570 alert = aimutil_get32(data+i);
571 i += 4;
572 limit = aimutil_get32(data+i);
573 i += 4;
574 disconnect = aimutil_get32(data+i);
575 i += 4;
576 currentavg = aimutil_get32(data+i);
577 i += 4;
578 maxavg = aimutil_get32(data+i);
579 i += 4;
580
581 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
582 return userfunc(sess, rx, code, rateclass, windowsize, clear, alert, limit, disconnect, currentavg, maxavg);
583
584 return 0;
585}
586
587/* XXX parse this */
588static 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)
589{
590 rxcallback_t userfunc;
591
592 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
593 return userfunc(sess, rx);
594
595 return 0;
596}
597
598static 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)
599{
600 rxcallback_t userfunc = NULL;
601 int i = 0;
602 unsigned short newevil;
603 struct aim_userinfo_s userinfo;
604
605 newevil = aimutil_get16(data);
606 i += 2;
607
608 memset(&userinfo, 0, sizeof(struct aim_userinfo_s));
609
610 if (datalen-i)
611 i += aim_extractuserinfo(sess, data+i, &userinfo);
612
613 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
614 return userfunc(sess, rx, newevil, &userinfo);
615
616 return 0;
617}
618
619static 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)
620{
621 rxcallback_t userfunc;
622 char *msg = NULL;
623 int ret = 0;
624 struct aim_tlvlist_t *tlvlist;
625 unsigned short id;
626
627 /*
628 * Code.
629 *
630 * Valid values:
631 * 1 Mandatory upgrade
632 * 2 Advisory upgrade
633 * 3 System bulletin
634 * 4 Nothing's wrong ("top o the world" -- normal)
635 *
636 */
637 id = aimutil_get16(data);
638
639 /*
640 * TLVs follow
641 */
642 if ((tlvlist = aim_readtlvchain(data+2, datalen-2)))
643 msg = aim_gettlv_str(tlvlist, 0x000b, 1);
644
645 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
646 ret = userfunc(sess, rx, id, msg);
647
648 free(msg);
649
650 aim_freetlvchain(&tlvlist);
651
652 return ret;
653}
654
655static 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)
656{
657 rxcallback_t userfunc;
658 int vercount;
659
660 vercount = datalen/4;
661
662 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
663 return userfunc(sess, rx, vercount, data);
664
665 return 0;
666}
d32954e7 667/*
668 * Stay tuned. I have an explanation for here.
669 *
670 *
671 */
672static int memrequest(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
673{
674 return 1;
675}
00ef5271 676
677static 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)
678{
679
680 if (snac->subtype == 0x0003)
681 return hostonline(sess, mod, rx, snac, data, datalen);
682 else if (snac->subtype == 0x0005)
683 return redirect(sess, mod, rx, snac, data, datalen);
684 else if (snac->subtype == 0x0007)
685 return rateresp(sess, mod, rx, snac, data, datalen);
686 else if (snac->subtype == 0x000a)
687 return ratechange(sess, mod, rx, snac, data, datalen);
688 else if (snac->subtype == 0x000f)
689 return selfinfo(sess, mod, rx, snac, data, datalen);
690 else if (snac->subtype == 0x0010)
691 return evilnotify(sess, mod, rx, snac, data, datalen);
692 else if (snac->subtype == 0x0013)
693 return motd(sess, mod, rx, snac, data, datalen);
694 else if (snac->subtype == 0x0018)
695 return hostversions(sess, mod, rx, snac, data, datalen);
d32954e7 696 else if (snac->subtype == 0x001f)
697 return memrequest(sess, mod, rx, snac, data, datalen);
00ef5271 698
699 return 0;
700}
701
702faim_internal int general_modfirst(struct aim_session_t *sess, aim_module_t *mod)
703{
704
705 mod->family = 0x0001;
706 mod->version = 0x0000;
707 mod->flags = 0;
708 strncpy(mod->name, "general", sizeof(mod->name));
709 mod->snachandler = snachandler;
710
711 return 0;
712}
This page took 0.156288 seconds and 5 git commands to generate.