]> andersk Git - libfaim.git/blame - src/im.c
- Wed Aug 29 16:59:24 PDT 2001
[libfaim.git] / src / im.c
CommitLineData
9de3ca7e 1/*
2 * aim_im.c
3 *
4 * The routines for sending/receiving Instant Messages.
5 *
6ae3c48d 6 * Note the term ICBM (Inter-Client Basic Message) which blankets
7 * all types of genericly routed through-server messages. Within
8 * the ICBM types (family 4), a channel is defined. Each channel
9 * represents a different type of message. Channel 1 is used for
10 * what would commonly be called an "instant message". Channel 2
11 * is used for negotiating "rendezvous". These transactions end in
12 * something more complex happening, such as a chat invitation, or
13 * a file transfer.
14 *
15 * In addition to the channel, every ICBM contains a cookie. For
16 * standard IMs, these are only used for error messages. However,
17 * the more complex rendezvous messages make suitably more complex
18 * use of this field.
19 *
9de3ca7e 20 */
21
37ee990e 22#define FAIM_INTERNAL
dd60ff8b 23#include <aim.h>
9de3ca7e 24
9d83220c 25/*
26 * Takes a msghdr (and a length) and returns a client type
27 * code. Note that this is *only a guess* and has a low likelihood
28 * of actually being accurate.
29 *
30 * Its based on experimental data, with the help of Eric Warmenhoven
31 * who seems to have collected a wide variety of different AIM clients.
32 *
33 *
34 * Heres the current collection:
35 * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414
36 * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464,
37 * 4.3.2229, 4.4.2286
38 * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here)
39 * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any
40 * TOC client
41 */
42faim_export unsigned short aim_fingerprintclient(unsigned char *msghdr, int len)
43{
6ae3c48d 44 static const struct {
45 unsigned short clientid;
46 int len;
47 unsigned char data[10];
48 } fingerprints[] = {
49 /* AOL Mobile Communicator, WinAIM 1.0.414 */
50 { AIM_CLIENTTYPE_MC,
51 9, {0x05, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01}},
52
53 /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
54 { AIM_CLIENTTYPE_WINAIM,
55 9, {0x05, 0x01, 0x00, 0x03, 0x01, 0x01, 0x02, 0x01, 0x01}},
56
57 /* WinAIM 4.1.2010, libfaim */
58 { AIM_CLIENTTYPE_WINAIM41,
59 10, {0x05, 0x01, 0x00, 0x04, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01}},
60
61 /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
62 { AIM_CLIENTTYPE_AOL_TOC,
63 7, {0x05, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01}},
64
65 { 0, 0}
66 };
67 int i;
68
69 if (!msghdr || (len <= 0))
70 return AIM_CLIENTTYPE_UNKNOWN;
71
72 for (i = 0; fingerprints[i].len; i++) {
73 if (fingerprints[i].len != len)
74 continue;
75 if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
76 return fingerprints[i].clientid;
77 }
78
79 return AIM_CLIENTTYPE_UNKNOWN;
9d83220c 80}
81
50038c74 82/* This should be endian-safe now... but who knows... */
83faim_export unsigned short aim_iconsum(const unsigned char *buf, int buflen)
84{
6ae3c48d 85 unsigned long sum;
86 int i;
50038c74 87
6ae3c48d 88 for (i = 0, sum = 0; i < buflen; i += 2)
89 sum += (buf[i+1] << 8) + buf[i];
50038c74 90
6ae3c48d 91 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
50038c74 92
6ae3c48d 93 return sum & 0xffff;
50038c74 94}
95
9de3ca7e 96/*
97 * Send an ICBM (instant message).
98 *
99 *
100 * Possible flags:
101 * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
102 * AIM_IMFLAGS_ACK -- Requests that the server send an ack
103 * when the message is received (of type 0x0004/0x000c)
7b91722d 104 * AIM_IMFLAGS_UNICODE--Instead of ASCII7, the passed message is
105 * made up of UNICODE duples. If you set
106 * this, you'd better be damn sure you know
107 * what you're doing.
108 * AIM_IMFLAGS_ISO_8859_1 -- The message contains the ASCII8 subset
109 * known as ISO-8859-1.
110 *
111 * Generally, you should use the lowest encoding possible to send
112 * your message. If you only use basic punctuation and the generic
113 * Latin alphabet, use ASCII7 (no flags). If you happen to use non-ASCII7
114 * characters, but they are all clearly defined in ISO-8859-1, then
115 * use that. Keep in mind that not all characters in the PC ASCII8
116 * character set are defined in the ISO standard. For those cases (most
117 * notably when the (r) symbol is used), you must use the full UNICODE
118 * encoding for your message. In UNICODE mode, _all_ characters must
119 * occupy 16bits, including ones that are not special. (Remember that
120 * the first 128 UNICODE symbols are equivelent to ASCII7, however they
121 * must be prefixed with a zero high order byte.)
122 *
123 * I strongly discourage the use of UNICODE mode, mainly because none
124 * of the clients I use can parse those messages (and besides that,
125 * wchars are difficult and non-portable to handle in most UNIX environments).
126 * If you really need to include special characters, use the HTML UNICODE
127 * entities. These are of the form &#2026; where 2026 is the hex
128 * representation of the UNICODE index (in this case, UNICODE
129 * "Horizontal Ellipsis", or 133 in in ASCII8).
9de3ca7e 130 *
9de3ca7e 131 */
2d5fd943 132faim_export int aim_send_im_ext(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_sendimext_args *args)
a2244dd9 133{
2d5fd943 134 int curbyte,i;
135 struct command_tx_struct *newpacket;
136
137 if (!sess || !conn || !args)
138 return -EINVAL;
139
140 if (!args->msg || (args->msglen <= 0))
141 return -EINVAL;
142
143 if (args->msglen >= MAXMSGLEN)
144 return -E2BIG;
145
146 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, args->msglen+512)))
147 return -ENOMEM;
148
149 newpacket->lock = 1; /* lock struct */
150
151 curbyte = 0;
152 curbyte += aim_putsnac(newpacket->data+curbyte,
153 0x0004, 0x0006, 0x0000, sess->snac_nextid);
154
155 /*
156 * Generate a random message cookie
157 *
158 * We could cache these like we do SNAC IDs. (In fact, it
159 * might be a good idea.) In the message error functions,
160 * the 8byte message cookie is returned as well as the
161 * SNAC ID.
162 *
163 */
164 for (i = 0; i < 8; i++) {
165 curbyte += aimutil_put8(newpacket->data+curbyte,
166 (unsigned char) rand());
167 }
168
169 /*
170 * Channel ID
171 */
172 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
173
174 /*
175 * Destination SN (prepended with byte length)
176 */
177 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(args->destsn));
178 curbyte += aimutil_putstr(newpacket->data+curbyte,
179 args->destsn, strlen(args->destsn));
180
181 /*
182 * metaTLV start.
183 */
184 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
185 curbyte += aimutil_put16(newpacket->data+curbyte, args->msglen + 0x10);
186
187 /*
188 * Flag data / ICBM Parameters?
189 *
190 * I don't know what these are...
191 *
192 */
193 curbyte += aimutil_put8(newpacket->data+curbyte, 0x05);
194 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
195
196 /* number of bytes to follow */
197 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
198 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
199 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
200 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
201 curbyte += aimutil_put8(newpacket->data+curbyte, 0x02);
202
203 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0101);
204
205 /*
206 * Message block length.
207 */
208 curbyte += aimutil_put16(newpacket->data+curbyte, args->msglen + 0x04);
209
210 /*
211 * Character set.
212 */
213 if (args->flags & AIM_IMFLAGS_UNICODE)
214 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
215 else if (args->flags & AIM_IMFLAGS_ISO_8859_1)
216 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
217 else
218 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
219
220 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
221
222 /*
223 * Message. Not terminated.
224 */
225 curbyte += aimutil_putstr(newpacket->data+curbyte,
226 args->msg, args->msglen);
227
228 /*
229 * Set the Request Acknowledge flag.
230 */
231 if (args->flags & AIM_IMFLAGS_ACK) {
232 curbyte += aimutil_put16(newpacket->data+curbyte,0x0003);
233 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
234 }
49c8a2fa 235
2d5fd943 236 /*
237 * Set the Autoresponse flag.
238 */
239 if (args->flags & AIM_IMFLAGS_AWAY) {
240 curbyte += aimutil_put16(newpacket->data+curbyte,0x0004);
241 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
242 }
243
244 /*
245 * Set the Buddy Icon Requested flag.
246 */
247 if (args->flags & AIM_IMFLAGS_BUDDYREQ) {
248 curbyte += aimutil_put16(newpacket->data+curbyte,0x0009);
249 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
250 }
251
252 /*
253 * Set the I HAVE A REALLY PURTY ICON flag (with timestamp).
254 */
255 if (args->flags & AIM_IMFLAGS_HASICON) {
256 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0008);
257 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000c);
258 curbyte += aimutil_put32(newpacket->data+curbyte, args->iconlen);
259 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
260 curbyte += aimutil_put16(newpacket->data+curbyte, args->iconsum);
261 curbyte += aimutil_put32(newpacket->data+curbyte, args->iconstamp);
262 }
263
264 newpacket->commandlen = curbyte;
265 newpacket->lock = 0;
266
267 aim_tx_enqueue(sess, newpacket);
49c8a2fa 268
7b91722d 269#if 1 /* XXX do this with autoconf or something... */
2d5fd943 270 aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
271 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
7b91722d 272#endif
9de3ca7e 273
2d5fd943 274 return 0;
9de3ca7e 275}
276
7b91722d 277/*
278 * Simple wrapper for aim_send_im_ext()
279 *
280 * You cannot use aim_send_im if you need the HASICON flag. You must
281 * use aim_send_im_ext directly for that.
282 *
283 * aim_send_im also cannot be used if you require UNICODE messages, because
284 * that requires an explicit message length. Use aim_send_im_ext().
285 *
286 */
2d5fd943 287faim_export int aim_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, const char *destsn, unsigned short flags, const char *msg)
7b91722d 288{
2d5fd943 289 struct aim_sendimext_args args;
7b91722d 290
2d5fd943 291 args.destsn = destsn;
292 args.flags = flags;
293 args.msg = msg;
294 args.msglen = strlen(msg);
7b91722d 295
2d5fd943 296 return aim_send_im_ext(sess, conn, &args);
7b91722d 297}
298
50038c74 299faim_export int aim_send_icon(struct aim_session_t *sess, struct aim_conn_t *conn, const char *sn, const unsigned char *icon, int iconlen, time_t stamp, unsigned short iconsum)
7b91722d 300{
6ae3c48d 301 struct command_tx_struct *np;
302 int i, curbyte = 0;
303 unsigned char ck[8];
304
305 if (!sess || !conn || !sn || !icon ||
306 (iconlen <= 0) || (iconlen >= MAXICONLEN))
307 return -EINVAL;
308
309 if (conn->type != AIM_CONN_TYPE_BOS)
310 return -EINVAL;
311
312 for (i = 0, curbyte = 0; i < 8; i++)
313 curbyte += aimutil_put8(ck+curbyte, (u_char)rand());
314
315 if (!(np = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2)))
316 return -ENOMEM;
317
318 np->lock = 1;
319
320 curbyte = aim_putsnac(np->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
321
322 /*
323 * Cookie
324 */
325 memcpy(np->data+curbyte, ck, 8);
326 curbyte += 8;
327
328 /*
329 * Channel (2)
330 */
331 curbyte += aimutil_put16(np->data+curbyte, 0x0002);
332
333 /*
334 * Dest sn
335 */
336 curbyte += aimutil_put8(np->data+curbyte, strlen(sn));
337 curbyte += aimutil_putstr(np->data+curbyte, sn, strlen(sn));
338
339 /*
340 * TLV t(0005)
341 */
342 curbyte += aimutil_put16(np->data+curbyte, 0x0005);
343 curbyte += aimutil_put16(np->data+curbyte, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT));
344
345 curbyte += aimutil_put16(np->data+curbyte, 0x0000);
346
347 memcpy(np->data+curbyte, ck, 8);
348 curbyte += 8;
7b91722d 349
6ae3c48d 350 curbyte += aim_putcap(np->data+curbyte, 16, AIM_CAPS_BUDDYICON);
351
352 /* TLV t(000a) */
353 curbyte += aimutil_put16(np->data+curbyte, 0x000a);
354 curbyte += aimutil_put16(np->data+curbyte, 0x0002);
355 curbyte += aimutil_put16(np->data+curbyte, 0x0001);
356
357 /* TLV t(000f) */
358 curbyte += aimutil_put16(np->data+curbyte, 0x000f);
359 curbyte += aimutil_put16(np->data+curbyte, 0x0000);
360
361 /* TLV t(2711) */
362 curbyte += aimutil_put16(np->data+curbyte, 0x2711);
363 curbyte += aimutil_put16(np->data+curbyte, 4+4+4+iconlen+strlen(AIM_ICONIDENT));
364 curbyte += aimutil_put16(np->data+curbyte, 0x0000);
365 curbyte += aimutil_put16(np->data+curbyte, iconsum);
366 curbyte += aimutil_put32(np->data+curbyte, iconlen);
367 curbyte += aimutil_put32(np->data+curbyte, stamp);
368 memcpy(np->data+curbyte, icon, iconlen);
369 curbyte += iconlen;
370 memcpy(np->data+curbyte, AIM_ICONIDENT, strlen(AIM_ICONIDENT));
371 curbyte += strlen(AIM_ICONIDENT);
372
373 /* TLV t(0003) */
374 curbyte += aimutil_put16(np->data+curbyte, 0x0003);
375 curbyte += aimutil_put16(np->data+curbyte, 0x0000);
376
377 np->commandlen = curbyte;
378 np->lock = 0;
379 aim_tx_enqueue(sess, np);
380
381 return 0;
7b91722d 382}
383
00ef5271 384static int outgoingim(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
e5012450 385{
6ae3c48d 386 unsigned int i, ret = 0;
387 aim_rxcallback_t userfunc;
388 unsigned char cookie[8];
389 int channel;
390 struct aim_tlvlist_t *tlvlist;
391 char sn[MAXSNLEN];
392 unsigned short icbmflags = 0;
393 unsigned char flag1 = 0, flag2 = 0;
394 unsigned char *msgblock = NULL, *msg = NULL;
395
396 /* ICBM Cookie. */
397 for (i = 0; i < 8; i++)
398 cookie[i] = aimutil_get8(data+i);
399
400 /* Channel ID */
401 channel = aimutil_get16(data+i);
402 i += 2;
403
404 if (channel != 0x01) {
405 faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
406 return 1;
407 }
408
409 strncpy(sn, (char *) data+i+1, (int) *(data+i));
410 i += 1 + (int) *(data+i);
411
412 tlvlist = aim_readtlvchain(data+i, datalen-i);
413
414 if (aim_gettlv(tlvlist, 0x0003, 1))
415 icbmflags |= AIM_IMFLAGS_ACK;
416 if (aim_gettlv(tlvlist, 0x0004, 1))
417 icbmflags |= AIM_IMFLAGS_AWAY;
e5012450 418
6ae3c48d 419 if ((msgblock = (unsigned char *)aim_gettlv_str(tlvlist, 0x0002, 1))) {
420 int j = 0;
421
422 /* no, this really is correct. I'm not high or anything either. */
423 j += 2;
424 j += 2 + aimutil_get16(msgblock+j);
425 j += 2;
426
427 j += 2; /* final block length */
428
429 flag1 = aimutil_get16(msgblock);
430 j += 2;
431 flag2 = aimutil_get16(msgblock);
432 j += 2;
433
434 msg = msgblock+j;
435 }
436
437 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
438 ret = userfunc(sess, rx, channel, sn, msg, icbmflags, flag1, flag2);
439
440 free(msgblock);
441 aim_freetlvchain(&tlvlist);
442
443 return ret;
00ef5271 444}
445
6ae3c48d 446/*
447 * A multipart IM:
448 *
449 * 0004 0007 0000 8f08 d295
450 * 0031 6520 3b7b f9fd
451 * 0001
452 * 06 XXXX XXXX XXXX
453 * 0000
454 * 0004
455 * 0001 0002 0004
456 * 0010 0004 0000 01a3
457 * 0002 0004 3ab6 94fa
458 * 0003 0004 3b7b f85a
459 * 0002 003c
460 * 0501 0001 01
461 * 0101 000a 0000 0000 3c48 544d 4c3e ASCII part
462 * ISO-8859 part:
463 * 0101 0016 0003 0000 6c6b 7364 6a6b 6c6a 676c a56b 3b73 646a 6b6a
464 * 0101 000b 0000 0000 3c2f 4854 4d4c 3e another ASCII part
465 *
466 */
7b91722d 467static int incomingim_ch1(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned short channel, struct aim_userinfo_s *userinfo, unsigned char *data, int datalen, unsigned char *cookie)
00ef5271 468{
1dcd23dd 469 unsigned short type, length;
470 aim_rxcallback_t userfunc;
471 int i, ret = 0;
472 struct aim_incomingim_ch1_args args;
00ef5271 473
1dcd23dd 474 memset(&args, 0, sizeof(args));
00ef5271 475
1dcd23dd 476 /*
477 * This used to be done using tlvchains. For performance reasons,
478 * I've changed it to process the TLVs in-place. This avoids lots
479 * of per-IM memory allocations.
480 */
481 for (i = 0; i < datalen; ) {
482
483 type = aimutil_get16(data+i);
484 i += 2;
485
486 length = aimutil_get16(data+i);
487 i += 2;
488
489 if (type == 0x0002) { /* Message Block */
490 unsigned short wastebits;
491 unsigned char *msgblock;
492 int j = 0, y = 0, z = 0;
493
494 msgblock = data+i;
495
496 /*
497 * Extracting the message from the unknown cruft.
498 *
499 * This is a bit messy, and I'm not really qualified,
500 * even as the author, to comment on it. At least
501 * its not as bad as a while loop shooting into
502 * infinity.
503 *
504 * "Do you believe in magic?"
505 *
506 */
507
508 wastebits = aimutil_get8(msgblock+j++);
509 wastebits = aimutil_get8(msgblock+j++);
510
511 y = aimutil_get16(msgblock+j);
512 j += 2;
513 for (z = 0; z < y; z++)
514 wastebits = aimutil_get8(msgblock+j++);
515 wastebits = aimutil_get8(msgblock+j++);
516 wastebits = aimutil_get8(msgblock+j++);
517
518 args.finlen = j;
519 if (args.finlen > sizeof(args.fingerprint))
520 args.finlen = sizeof(args.fingerprint);
521 memcpy(args.fingerprint, msgblock, args.finlen);
522
523 /* Message string length, including flag words. */
524 args.msglen = aimutil_get16(msgblock+j);
525 j += 2;
526
527 /* Flag words. */
528 args.flag1 = aimutil_get16(msgblock+j);
529 if (args.flag1 == 0x0000)
530 ; /* ASCII */
531 else if (args.flag1 == 0x0002)
532 args.icbmflags |= AIM_IMFLAGS_UNICODE;
533 else if (args.flag1 == 0x0003)
534 args.icbmflags |= AIM_IMFLAGS_ISO_8859_1;
535 else if (args.flag1 == 0xffff)
536 ; /* no encoding (yeep!) */
537 j += 2;
538
539 args.flag2 = aimutil_get16(msgblock+j);
540 if (args.flag2 == 0x0000)
541 ; /* standard subencoding? */
542 else if (args.flag2 == 0x000b)
543 args.icbmflags |= AIM_IMFLAGS_SUBENC_MACINTOSH;
544 else if (args.flag2 == 0xffff)
545 ; /* no subencoding */
546 j += 2;
547
548 if ( ((args.flag1 != 0x0000) &&
549 (args.flag1 != 0x0002) &&
550 (args.flag1 != 0x0003) &&
551 (args.flag1 != 0xffff)) ||
552 ((args.flag2 != 0x0000) &&
553 (args.flag2 != 0x000b) &&
554 (args.flag2 != 0xffff))) {
555 faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", args.flag1, args.flag2);
556 }
557
558 /* Message string. */
559 args.msglen -= 4;
560 if (args.icbmflags & AIM_IMFLAGS_UNICODE) {
561 args.msg = malloc(args.msglen+2);
562 memcpy(args.msg, msgblock+j, args.msglen);
563 args.msg[args.msglen] = '\0'; /* wide NULL */
564 args.msg[args.msglen+1] = '\0';
565 } else {
566 args.msg = malloc(args.msglen+1);
567 memcpy(args.msg, msgblock+j, args.msglen);
568 args.msg[args.msglen] = '\0';
569 }
570
571 } else if (type == 0x0003) { /* Server Ack Requested */
572
573 args.icbmflags |= AIM_IMFLAGS_ACK;
574
575 } else if (type == 0x0004) { /* Message is Auto Response */
576
577 args.icbmflags |= AIM_IMFLAGS_AWAY;
578
579 } else if ((type == 0x0008) && (length == 0x000c)) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */
580
70b889c5 581 args.iconchecksum = aimutil_get32(data+i);
582 args.iconlength = aimutil_get32(data+i+4);
1dcd23dd 583 args.iconstamp = aimutil_get32(data+i+8);
584 args.icbmflags |= AIM_IMFLAGS_HASICON;
585
586 } else if (type == 0x0009) {
587
588 args.icbmflags |= AIM_IMFLAGS_BUDDYREQ;
589
590 } else if (type == 0x0017) {
591
592 args.extdatalen = length;
593 args.extdata = data+i;
594
595 } else {
6ae3c48d 596 faimdprintf(sess, 0, "incomingim_ch1: unknown TLV 0x%04x (len %d)\n", type, length);
1dcd23dd 597 }
598
599 i += length;
600 }
00ef5271 601
00ef5271 602
1dcd23dd 603 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
604 ret = userfunc(sess, rx, channel, userinfo, &args);
00ef5271 605
1dcd23dd 606 free(args.msg);
00ef5271 607
1dcd23dd 608 return ret;
00ef5271 609}
610
611static int incomingim_ch2(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned short channel, struct aim_userinfo_s *userinfo, struct aim_tlvlist_t *tlvlist, unsigned char *cookie)
612{
6ae3c48d 613 aim_rxcallback_t userfunc;
614 struct aim_tlv_t *block1;
615 struct aim_tlvlist_t *list2;
616 int ret = 0;
617 struct aim_incomingim_ch2_args args;
618
619 memset(&args, 0, sizeof(args));
620
621 /*
622 * There's another block of TLVs embedded in the type 5 here.
623 */
355229fe 624 if (!(block1 = aim_gettlv(tlvlist, 0x0005, 1)) || !block1->value) {
6ae3c48d 625 faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
626 return 0;
627 }
628
629 /*
630 * First two bytes represent the status of the connection.
631 *
632 * 0 is a request, 2 is an accept
633 */
634 args.status = aimutil_get16(block1->value+0);
635
636 /*
637 * Next comes the cookie. Should match the ICBM cookie.
638 */
639 if (memcmp(block1->value+2, cookie, 8) != 0)
640 faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
641
642 /*
643 * The next 16bytes are a capability block so we can
644 * identify what type of rendezvous this is.
645 *
646 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
647 * for pointing some of this out to me. In fact, a lot of
648 * the client-to-client info comes from the work of the GAIM
649 * developers. Thanks!
650 *
651 * Read off one capability string and we should have it ID'd.
652 *
653 */
654 if ((args.reqclass = aim_getcap(sess, block1->value+2+8, 0x10)) == 0x0000) {
655 faimdprintf(sess, 0, "rend: no ID block\n");
656 return 0;
657 }
658
659 /*
70b889c5 660 * What follows may be TLVs or nothing, depending on the
661 * purpose of the message.
662 *
663 * Ack packets for instance have nothing more to them.
664 */
6ae3c48d 665 list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
666
667 if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
668 struct aim_msgcookie_t *cook;
669 int type;
670
671 type = aim_msgcookie_gettype(args.reqclass); /* XXX: fix this shitty code */
672
673 if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
674 faimdprintf(sess, 0, "non-data rendezvous thats not in cache (type %d)\n", type);
675 aim_freetlvchain(&list2);
676 return 1;
677 }
678
679 if (cook->type == AIM_COOKIETYPE_OFTGET) {
680 struct aim_filetransfer_priv *ft;
681
682 if (cook->data) {
683 int errorcode = -1; /* XXX shouldnt this be 0? */
684
685 ft = (struct aim_filetransfer_priv *)cook->data;
686
687 if (args.status != 0x0002) {
688
689 if (aim_gettlv(list2, 0x000b, 1))
690 errorcode = aim_gettlv16(list2, 0x000b, 1);
691
692 /* XXX this should make it up to the client, you know.. */
693 if (errorcode)
694 faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
695 } /* args.status != 0x0002 */
696
697 } else {
698 faimdprintf(sess, 0, "no data attached to file transfer\n");
699 } /* !cook->data */
700
701 } else if (cook->type == AIM_CAPS_VOICE) {
702
703 faimdprintf(sess, 0, "voice request cancelled\n");
704
705 } else {
706
707 faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
708 }
709
710 aim_freetlvchain(&list2);
711
712 return 1;
00ef5271 713 }
6ae3c48d 714
715 /*
716 * The rest of the handling depends on what type it is.
717 */
718 if (args.reqclass & AIM_CAPS_BUDDYICON) {
719 struct aim_tlv_t *miscinfo;
720 int curpos = 0;
721
722 miscinfo = aim_gettlv(list2, 0x2711, 1);
723
70b889c5 724 args.info.icon.checksum = aimutil_get32(miscinfo->value+curpos);
6ae3c48d 725 curpos += 4;
726 args.info.icon.length = aimutil_get32(miscinfo->value+curpos);
727 curpos += 4;
728 args.info.icon.timestamp = aimutil_get32(miscinfo->value+curpos);
729 curpos += 4;
730 args.info.icon.icon = malloc(args.info.icon.length);
731 memcpy(args.info.icon.icon, miscinfo->value+curpos, args.info.icon.length);
732
733 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
734 ret = userfunc(sess, rx, channel, userinfo, &args);
735
736 free(args.info.icon.icon);
737
738 } else if (args.reqclass & AIM_CAPS_VOICE) {
739 struct aim_msgcookie_t *cachedcook;
740
741 faimdprintf(sess, 1, "rend: voice!\n");
742
743 if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t)))) {
744 aim_freetlvchain(&list2);
745 return 0;
746 }
747
748 memcpy(cachedcook->cookie, cookie, 8);
749 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
750 cachedcook->data = NULL;
751
752 if (aim_cachecookie(sess, cachedcook) == -1)
753 faimdprintf(sess, 0, "ERROR caching message cookie\n");
754
755 /* XXX: implement all this */
756
757 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
758 ret = userfunc(sess, rx, channel, userinfo, &args);
759
760 } else if (args.reqclass & AIM_CAPS_IMIMAGE) {
761 char ip[30];
762 struct aim_directim_priv *priv;
763
764 memset(ip, 0, sizeof(ip));
765
766 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
767 struct aim_tlv_t *iptlv, *porttlv;
768
769 iptlv = aim_gettlv(list2, 0x0003, 1);
770 porttlv = aim_gettlv(list2, 0x0005, 1);
771
772 snprintf(ip, 30, "%d.%d.%d.%d:%d",
773 aimutil_get8(iptlv->value+0),
774 aimutil_get8(iptlv->value+1),
775 aimutil_get8(iptlv->value+2),
776 aimutil_get8(iptlv->value+3),
777 4443 /*aimutil_get16(porttlv->value)*/);
778 }
779
780 faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n",
781 userinfo->sn, ip);
782
783 /*
784 * XXX: there are a couple of different request packets for
785 * different things
786 */
787
788 args.info.directim = priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); /* XXX error */
789 memcpy(priv->ip, ip, sizeof(priv->ip));
790 memcpy(priv->sn, userinfo->sn, sizeof(priv->sn));
791 memcpy(priv->cookie, cookie, sizeof(priv->cookie));
792
793 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
794 ret = userfunc(sess, rx, channel, userinfo, &args);
795
796 } else if (args.reqclass & AIM_CAPS_CHAT) {
797 struct aim_tlv_t *miscinfo;
798
799 miscinfo = aim_gettlv(list2, 0x2711, 1);
800 aim_chat_readroominfo(miscinfo->value, &args.info.chat.roominfo);
801
802 if (aim_gettlv(list2, 0x000c, 1))
803 args.info.chat.msg = aim_gettlv_str(list2, 0x000c, 1);
804
805 if (aim_gettlv(list2, 0x000d, 1))
806 args.info.chat.encoding = aim_gettlv_str(list2, 0x000d, 1);
807
808 if (aim_gettlv(list2, 0x000e, 1))
809 args.info.chat.lang = aim_gettlv_str(list2, 0x000e, 1);
810
811 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
812 ret = userfunc(sess, rx, channel, userinfo, &args);
813
814 free(args.info.chat.roominfo.name);
815 free(args.info.chat.msg);
816 free(args.info.chat.encoding);
817 free(args.info.chat.lang);
818
819 } else if (args.reqclass & AIM_CAPS_GETFILE) {
820 char ip[30];
821 struct aim_msgcookie_t *cachedcook;
822 struct aim_tlv_t *miscinfo;
823 struct aim_tlv_t *iptlv, *porttlv;
824
825 memset(ip, 0, 30);
826
827 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
828 aim_freetlvchain(&list2);
829 return 0;
830 }
831
832 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
833 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
834 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
835
836 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
837 aim_cookie_free(sess, cachedcook);
838 aim_freetlvchain(&list2);
839
840 return 0;
841 }
842
843 snprintf(ip, 30, "%d.%d.%d.%d:%d",
844 aimutil_get8(iptlv->value+0),
845 aimutil_get8(iptlv->value+1),
846 aimutil_get8(iptlv->value+2),
847 aimutil_get8(iptlv->value+3),
848 aimutil_get16(porttlv->value));
849
850 faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip);
851
852 args.info.getfile.ip = ip;
853 args.info.getfile.cookie = cookie;
854
855 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
856 ret = userfunc(sess, rx, channel, userinfo, &args);
857
858 } else if (args.reqclass & AIM_CAPS_SENDFILE) {
859#if 0
860 char ip[30];
861 struct aim_msgcookie_t *cachedcook;
862 struct aim_tlv_t *miscinfo;
863 struct aim_tlv_t *iptlv, *porttlv;
864
865 memset(ip, 0, 30);
866
867 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
868 aim_freetlvchain(&list2);
869 return 0;
870 }
871
872 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
873 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
874 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
875
876 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
877 aim_cookie_free(sess, cachedcook);
878 aim_freetlvchain(&list2);
879
880 return 0;
881 }
882
883 snprintf(ip, 30, "%d.%d.%d.%d:%d",
884 aimutil_get8(iptlv->value+0),
885 aimutil_get8(iptlv->value+1),
886 aimutil_get8(iptlv->value+2),
887 aimutil_get8(iptlv->value+3),
888 aimutil_get16(porttlv->value));
889
890 if (aim_gettlv(list2, 0x000c, 1))
891 desc = aim_gettlv_str(list2, 0x000c, 1);
892
893 faimdprintf(sess, 0, "rend: file transfer request from %s: %s (%s)\n",
894 userinfo->sn, desc, ip);
895
896 memcpy(cachedcook->cookie, cookie, 8);
897
898 ft = malloc(sizeof(struct aim_filetransfer_priv)); /* XXX */
899 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
900 strncpy(ft->ip, ip, sizeof(ft->ip));
901 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
902 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
903 cachedcook->data = ft;
904
905 if (aim_cachecookie(sess, cachedcook) == -1)
906 faimdprintf(sess, 0, "ERROR caching message cookie\n");
907
908 aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
909
910 if (desc)
911 free(desc);
912
913 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
914 ret = userfunc(sess, rx, channel, userinfo, &args);
00ef5271 915
916#endif
6ae3c48d 917 } else
918 faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", args.reqclass);
00ef5271 919
6ae3c48d 920 aim_freetlvchain(&list2);
00ef5271 921
6ae3c48d 922 return ret;
e5012450 923}
924
49c8a2fa 925/*
926 * It can easily be said that parsing ICBMs is THE single
927 * most difficult thing to do in the in AIM protocol. In
928 * fact, I think I just did say that.
929 *
930 * Below is the best damned solution I've come up with
931 * over the past sixteen months of battling with it. This
932 * can parse both away and normal messages from every client
933 * I have access to. Its not fast, its not clean. But it works.
934 *
49c8a2fa 935 */
00ef5271 936static int incomingim(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
9de3ca7e 937{
6ae3c48d 938 int i, ret = 0;
939 unsigned char cookie[8];
940 int channel;
941 struct aim_userinfo_s userinfo;
942
943 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
944
945 /*
946 * Read ICBM Cookie. And throw away.
947 */
948 for (i = 0; i < 8; i++)
949 cookie[i] = aimutil_get8(data+i);
950
951 /*
952 * Channel ID.
953 *
954 * Channel 0x0001 is the message channel. There are
955 * other channels for things called "rendevous"
956 * which represent chat and some of the other new
957 * features of AIM2/3/3.5.
958 *
959 * Channel 0x0002 is the Rendevous channel, which
960 * is where Chat Invitiations and various client-client
961 * connection negotiations come from.
962 *
963 */
964 channel = aimutil_get16(data+i);
965 i += 2;
966
967 /*
968 * Technically Channel 3 in chat could be done here too.
969 */
970 if ((channel != 0x01) && (channel != 0x02)) {
971 faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
972 return 1;
973 }
974
975 /*
976 * Extract the standard user info block.
977 *
978 * Note that although this contains TLVs that appear contiguous
979 * with the TLVs read below, they are two different pieces. The
980 * userinfo block contains the number of TLVs that contain user
981 * information, the rest are not even though there is no seperation.
982 * aim_extractuserinfo() returns the number of bytes used by the
983 * userinfo tlvs, so you can start reading the rest of them right
984 * afterward.
985 *
986 * That also means that TLV types can be duplicated between the
987 * userinfo block and the rest of the message, however there should
988 * never be two TLVs of the same type in one block.
989 *
990 */
991 i += aim_extractuserinfo(sess, data+i, &userinfo);
992
993 /*
994 * From here on, its depends on what channel we're on.
995 *
996 * Technically all channels have a TLV list have this, however,
997 * for the common channel 1 case, in-place parsing is used for
998 * performance reasons (less memory allocation).
999 */
1000 if (channel == 1) {
1001
1002 ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, data+i, datalen-i, cookie);
1003
1004 } else if (channel == 0x0002) {
1005 struct aim_tlvlist_t *tlvlist;
1006
1007 /*
1008 * Read block of TLVs (not including the userinfo data). All
1009 * further data is derived from what is parsed here.
1010 */
1011 tlvlist = aim_readtlvchain(data+i, datalen-i);
1012
1013 ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie);
1014
1015 /*
1016 * Free up the TLV chain.
1017 */
1018 aim_freetlvchain(&tlvlist);
1019 }
1020
1021 return ret;
49c8a2fa 1022}
1023
040457cc 1024/*
1025 * Possible codes:
1026 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
1027 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
1028 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
1029 *
1030 */
6ae3c48d 1031faim_export int aim_denytransfer(struct aim_session_t *sess,
1032 struct aim_conn_t *conn,
1033 const char *sender,
1034 const char *cookie,
1035 unsigned short code)
040457cc 1036{
6ae3c48d 1037 struct command_tx_struct *newpacket;
1038 int curbyte, i;
040457cc 1039
6ae3c48d 1040 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sender)+6)))
1041 return -ENOMEM;
040457cc 1042
6ae3c48d 1043 newpacket->lock = 1;
040457cc 1044
6ae3c48d 1045 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid++);
1046 for (i = 0; i < 8; i++)
1047 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
1048 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
1049 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
1050 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
1051 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
040457cc 1052
6ae3c48d 1053 newpacket->lock = 0;
1054 aim_tx_enqueue(sess, newpacket);
040457cc 1055
6ae3c48d 1056 return 0;
040457cc 1057}
1058
49c8a2fa 1059/*
355229fe 1060 * aim_reqicbmparaminfo()
49c8a2fa 1061 *
355229fe 1062 * Request ICBM parameter information.
49c8a2fa 1063 *
1064 */
355229fe 1065faim_export unsigned long aim_reqicbmparams(struct aim_session_t *sess, struct aim_conn_t *conn)
1066{
1067 return aim_genericreq_n(sess, conn, 0x0004, 0x0004);
1068}
1069
1070/*
1071 *
1072 */
1073faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_icbmparameters *params)
49c8a2fa 1074{
6ae3c48d 1075 struct command_tx_struct *newpacket;
1076 int curbyte;
49c8a2fa 1077
355229fe 1078 if (!sess || !conn || !params)
1079 return -EINVAL;
1080
6ae3c48d 1081 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+16)))
1082 return -ENOMEM;
5b79dc93 1083
6ae3c48d 1084 newpacket->lock = 1;
5b79dc93 1085
6ae3c48d 1086 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid++);
355229fe 1087
1088 /* This is read-only (in Parameter Reply). Must be set to zero here. */
1089 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
1090
1091 /* These are all read-write */
1092 curbyte += aimutil_put32(newpacket->data+curbyte, params->flags);
1093 curbyte += aimutil_put16(newpacket->data+curbyte, params->maxmsglen);
1094 curbyte += aimutil_put16(newpacket->data+curbyte, params->maxsenderwarn);
1095 curbyte += aimutil_put16(newpacket->data+curbyte, params->maxrecverwarn);
1096 curbyte += aimutil_put32(newpacket->data+curbyte, params->minmsginterval);
5b79dc93 1097
6ae3c48d 1098 newpacket->lock = 0;
1099 aim_tx_enqueue(sess, newpacket);
a25832e6 1100
6ae3c48d 1101 return 0;
a25832e6 1102}
1103
00ef5271 1104static int paraminfo(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
a25832e6 1105{
355229fe 1106 struct aim_icbmparameters params;
6ae3c48d 1107 aim_rxcallback_t userfunc;
1108 int i = 0;
a25832e6 1109
355229fe 1110 params.maxchan = aimutil_get16(data+i);
6ae3c48d 1111 i += 2;
a25832e6 1112
355229fe 1113 params.flags = aimutil_get32(data+i);
6ae3c48d 1114 i += 4;
96f8b1ed 1115
355229fe 1116 params.maxmsglen = aimutil_get16(data+i);
6ae3c48d 1117 i += 2;
a25832e6 1118
355229fe 1119 params.maxsenderwarn = aimutil_get16(data+i);
6ae3c48d 1120 i += 2;
49c8a2fa 1121
355229fe 1122 params.maxrecverwarn = aimutil_get16(data+i);
6ae3c48d 1123 i += 2;
e6b05d80 1124
355229fe 1125 params.minmsginterval = aimutil_get32(data+i);
6ae3c48d 1126 i += 4;
e6b05d80 1127
6ae3c48d 1128 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
355229fe 1129 return userfunc(sess, rx, &params);
00ef5271 1130
6ae3c48d 1131 return 0;
00ef5271 1132}
1133
1134static int missedcall(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
96f8b1ed 1135{
36a61e0d 1136 int i, ret = 0;
6ae3c48d 1137 aim_rxcallback_t userfunc;
1138 unsigned short channel, nummissed, reason;
1139 struct aim_userinfo_s userinfo;
36a61e0d 1140
1141 for (i = 0; i < datalen; ) {
96f8b1ed 1142
36a61e0d 1143 /* Channel ID. */
1144 channel = aimutil_get16(data+i);
1145 i += 2;
6ae3c48d 1146
36a61e0d 1147 /* Extract the standard user info block. */
1148 i += aim_extractuserinfo(sess, data+i, &userinfo);
6ae3c48d 1149
36a61e0d 1150 nummissed = aimutil_get16(data+i);
1151 i += 2;
6ae3c48d 1152
36a61e0d 1153 reason = aimutil_get16(data+i);
1154 i += 2;
6ae3c48d 1155
36a61e0d 1156 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1157 ret = userfunc(sess, rx, channel, &userinfo, nummissed, reason);
1158 }
6ae3c48d 1159
36a61e0d 1160 return ret;
00ef5271 1161}
1162
1163static int msgack(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
1164{
6ae3c48d 1165 aim_rxcallback_t userfunc;
1166 char sn[MAXSNLEN];
1167 unsigned char ck[8];
1168 unsigned short type;
1169 int i = 0;
1170 unsigned char snlen;
00ef5271 1171
6ae3c48d 1172 memcpy(ck, data, 8);
1173 i += 8;
00ef5271 1174
6ae3c48d 1175 type = aimutil_get16(data+i);
1176 i += 2;
00ef5271 1177
6ae3c48d 1178 snlen = aimutil_get8(data+i);
1179 i++;
00ef5271 1180
6ae3c48d 1181 memset(sn, 0, sizeof(sn));
1182 strncpy(sn, (char *)data+i, snlen);
00ef5271 1183
6ae3c48d 1184 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1185 return userfunc(sess, rx, type, sn);
00ef5271 1186
6ae3c48d 1187 return 0;
00ef5271 1188}
1189
1190static 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)
1191{
1192
6ae3c48d 1193 if (snac->subtype == 0x0005)
1194 return paraminfo(sess, mod, rx, snac, data, datalen);
1195 else if (snac->subtype == 0x0006)
1196 return outgoingim(sess, mod, rx, snac, data, datalen);
1197 else if (snac->subtype == 0x0007)
1198 return incomingim(sess, mod, rx, snac, data, datalen);
1199 else if (snac->subtype == 0x000a)
1200 return missedcall(sess, mod, rx, snac, data, datalen);
1201 else if (snac->subtype == 0x000c)
1202 return msgack(sess, mod, rx, snac, data, datalen);
1203
1204 return 0;
00ef5271 1205}
1206
1207faim_internal int msg_modfirst(struct aim_session_t *sess, aim_module_t *mod)
1208{
1209
6ae3c48d 1210 mod->family = 0x0004;
1211 mod->version = 0x0000;
1212 mod->flags = 0;
1213 strncpy(mod->name, "messaging", sizeof(mod->name));
1214 mod->snachandler = snachandler;
00ef5271 1215
6ae3c48d 1216 return 0;
96f8b1ed 1217}
This page took 2.544644 seconds and 5 git commands to generate.