]> andersk Git - libfaim.git/blame - src/im.c
- Sat Aug 25 19:19:16 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
581 args.iconstamp = aimutil_get32(data+i+8);
582 args.icbmflags |= AIM_IMFLAGS_HASICON;
583
584 } else if (type == 0x0009) {
585
586 args.icbmflags |= AIM_IMFLAGS_BUDDYREQ;
587
588 } else if (type == 0x0017) {
589
590 args.extdatalen = length;
591 args.extdata = data+i;
592
593 } else {
6ae3c48d 594 faimdprintf(sess, 0, "incomingim_ch1: unknown TLV 0x%04x (len %d)\n", type, length);
1dcd23dd 595 }
596
597 i += length;
598 }
00ef5271 599
00ef5271 600
1dcd23dd 601 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
602 ret = userfunc(sess, rx, channel, userinfo, &args);
00ef5271 603
1dcd23dd 604 free(args.msg);
00ef5271 605
1dcd23dd 606 return ret;
00ef5271 607}
608
609static 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)
610{
6ae3c48d 611 aim_rxcallback_t userfunc;
612 struct aim_tlv_t *block1;
613 struct aim_tlvlist_t *list2;
614 int ret = 0;
615 struct aim_incomingim_ch2_args args;
616
617 memset(&args, 0, sizeof(args));
618
619 /*
620 * There's another block of TLVs embedded in the type 5 here.
621 */
355229fe 622 if (!(block1 = aim_gettlv(tlvlist, 0x0005, 1)) || !block1->value) {
6ae3c48d 623 faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
624 return 0;
625 }
626
627 /*
628 * First two bytes represent the status of the connection.
629 *
630 * 0 is a request, 2 is an accept
631 */
632 args.status = aimutil_get16(block1->value+0);
633
634 /*
635 * Next comes the cookie. Should match the ICBM cookie.
636 */
637 if (memcmp(block1->value+2, cookie, 8) != 0)
638 faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
639
640 /*
641 * The next 16bytes are a capability block so we can
642 * identify what type of rendezvous this is.
643 *
644 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
645 * for pointing some of this out to me. In fact, a lot of
646 * the client-to-client info comes from the work of the GAIM
647 * developers. Thanks!
648 *
649 * Read off one capability string and we should have it ID'd.
650 *
651 */
652 if ((args.reqclass = aim_getcap(sess, block1->value+2+8, 0x10)) == 0x0000) {
653 faimdprintf(sess, 0, "rend: no ID block\n");
654 return 0;
655 }
656
657 /*
658 * What follows may be TLVs or nothing, depending on the
659 * purpose of the message.
660 *
661 * Ack packets for instance have nothing more to them.
662 */
663 list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
664
665 if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
666 struct aim_msgcookie_t *cook;
667 int type;
668
669 type = aim_msgcookie_gettype(args.reqclass); /* XXX: fix this shitty code */
670
671 if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
672 faimdprintf(sess, 0, "non-data rendezvous thats not in cache (type %d)\n", type);
673 aim_freetlvchain(&list2);
674 return 1;
675 }
676
677 if (cook->type == AIM_COOKIETYPE_OFTGET) {
678 struct aim_filetransfer_priv *ft;
679
680 if (cook->data) {
681 int errorcode = -1; /* XXX shouldnt this be 0? */
682
683 ft = (struct aim_filetransfer_priv *)cook->data;
684
685 if (args.status != 0x0002) {
686
687 if (aim_gettlv(list2, 0x000b, 1))
688 errorcode = aim_gettlv16(list2, 0x000b, 1);
689
690 /* XXX this should make it up to the client, you know.. */
691 if (errorcode)
692 faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
693 } /* args.status != 0x0002 */
694
695 } else {
696 faimdprintf(sess, 0, "no data attached to file transfer\n");
697 } /* !cook->data */
698
699 } else if (cook->type == AIM_CAPS_VOICE) {
700
701 faimdprintf(sess, 0, "voice request cancelled\n");
702
703 } else {
704
705 faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
706 }
707
708 aim_freetlvchain(&list2);
709
710 return 1;
00ef5271 711 }
6ae3c48d 712
713 /*
714 * The rest of the handling depends on what type it is.
715 */
716 if (args.reqclass & AIM_CAPS_BUDDYICON) {
717 struct aim_tlv_t *miscinfo;
718 int curpos = 0;
719
720 miscinfo = aim_gettlv(list2, 0x2711, 1);
721
722 /* aimutil_get32(miscinfo->value+curpos); i don't know what this is */
723 curpos += 4;
724 args.info.icon.length = aimutil_get32(miscinfo->value+curpos);
725 curpos += 4;
726 args.info.icon.timestamp = aimutil_get32(miscinfo->value+curpos);
727 curpos += 4;
728 args.info.icon.icon = malloc(args.info.icon.length);
729 memcpy(args.info.icon.icon, miscinfo->value+curpos, args.info.icon.length);
730
731 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
732 ret = userfunc(sess, rx, channel, userinfo, &args);
733
734 free(args.info.icon.icon);
735
736 } else if (args.reqclass & AIM_CAPS_VOICE) {
737 struct aim_msgcookie_t *cachedcook;
738
739 faimdprintf(sess, 1, "rend: voice!\n");
740
741 if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t)))) {
742 aim_freetlvchain(&list2);
743 return 0;
744 }
745
746 memcpy(cachedcook->cookie, cookie, 8);
747 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
748 cachedcook->data = NULL;
749
750 if (aim_cachecookie(sess, cachedcook) == -1)
751 faimdprintf(sess, 0, "ERROR caching message cookie\n");
752
753 /* XXX: implement all this */
754
755 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
756 ret = userfunc(sess, rx, channel, userinfo, &args);
757
758 } else if (args.reqclass & AIM_CAPS_IMIMAGE) {
759 char ip[30];
760 struct aim_directim_priv *priv;
761
762 memset(ip, 0, sizeof(ip));
763
764 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
765 struct aim_tlv_t *iptlv, *porttlv;
766
767 iptlv = aim_gettlv(list2, 0x0003, 1);
768 porttlv = aim_gettlv(list2, 0x0005, 1);
769
770 snprintf(ip, 30, "%d.%d.%d.%d:%d",
771 aimutil_get8(iptlv->value+0),
772 aimutil_get8(iptlv->value+1),
773 aimutil_get8(iptlv->value+2),
774 aimutil_get8(iptlv->value+3),
775 4443 /*aimutil_get16(porttlv->value)*/);
776 }
777
778 faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n",
779 userinfo->sn, ip);
780
781 /*
782 * XXX: there are a couple of different request packets for
783 * different things
784 */
785
786 args.info.directim = priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); /* XXX error */
787 memcpy(priv->ip, ip, sizeof(priv->ip));
788 memcpy(priv->sn, userinfo->sn, sizeof(priv->sn));
789 memcpy(priv->cookie, cookie, sizeof(priv->cookie));
790
791 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
792 ret = userfunc(sess, rx, channel, userinfo, &args);
793
794 } else if (args.reqclass & AIM_CAPS_CHAT) {
795 struct aim_tlv_t *miscinfo;
796
797 miscinfo = aim_gettlv(list2, 0x2711, 1);
798 aim_chat_readroominfo(miscinfo->value, &args.info.chat.roominfo);
799
800 if (aim_gettlv(list2, 0x000c, 1))
801 args.info.chat.msg = aim_gettlv_str(list2, 0x000c, 1);
802
803 if (aim_gettlv(list2, 0x000d, 1))
804 args.info.chat.encoding = aim_gettlv_str(list2, 0x000d, 1);
805
806 if (aim_gettlv(list2, 0x000e, 1))
807 args.info.chat.lang = aim_gettlv_str(list2, 0x000e, 1);
808
809 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
810 ret = userfunc(sess, rx, channel, userinfo, &args);
811
812 free(args.info.chat.roominfo.name);
813 free(args.info.chat.msg);
814 free(args.info.chat.encoding);
815 free(args.info.chat.lang);
816
817 } else if (args.reqclass & AIM_CAPS_GETFILE) {
818 char ip[30];
819 struct aim_msgcookie_t *cachedcook;
820 struct aim_tlv_t *miscinfo;
821 struct aim_tlv_t *iptlv, *porttlv;
822
823 memset(ip, 0, 30);
824
825 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
826 aim_freetlvchain(&list2);
827 return 0;
828 }
829
830 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
831 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
832 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
833
834 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
835 aim_cookie_free(sess, cachedcook);
836 aim_freetlvchain(&list2);
837
838 return 0;
839 }
840
841 snprintf(ip, 30, "%d.%d.%d.%d:%d",
842 aimutil_get8(iptlv->value+0),
843 aimutil_get8(iptlv->value+1),
844 aimutil_get8(iptlv->value+2),
845 aimutil_get8(iptlv->value+3),
846 aimutil_get16(porttlv->value));
847
848 faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip);
849
850 args.info.getfile.ip = ip;
851 args.info.getfile.cookie = cookie;
852
853 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
854 ret = userfunc(sess, rx, channel, userinfo, &args);
855
856 } else if (args.reqclass & AIM_CAPS_SENDFILE) {
857#if 0
858 char ip[30];
859 struct aim_msgcookie_t *cachedcook;
860 struct aim_tlv_t *miscinfo;
861 struct aim_tlv_t *iptlv, *porttlv;
862
863 memset(ip, 0, 30);
864
865 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
866 aim_freetlvchain(&list2);
867 return 0;
868 }
869
870 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
871 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
872 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
873
874 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
875 aim_cookie_free(sess, cachedcook);
876 aim_freetlvchain(&list2);
877
878 return 0;
879 }
880
881 snprintf(ip, 30, "%d.%d.%d.%d:%d",
882 aimutil_get8(iptlv->value+0),
883 aimutil_get8(iptlv->value+1),
884 aimutil_get8(iptlv->value+2),
885 aimutil_get8(iptlv->value+3),
886 aimutil_get16(porttlv->value));
887
888 if (aim_gettlv(list2, 0x000c, 1))
889 desc = aim_gettlv_str(list2, 0x000c, 1);
890
891 faimdprintf(sess, 0, "rend: file transfer request from %s: %s (%s)\n",
892 userinfo->sn, desc, ip);
893
894 memcpy(cachedcook->cookie, cookie, 8);
895
896 ft = malloc(sizeof(struct aim_filetransfer_priv)); /* XXX */
897 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
898 strncpy(ft->ip, ip, sizeof(ft->ip));
899 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
900 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
901 cachedcook->data = ft;
902
903 if (aim_cachecookie(sess, cachedcook) == -1)
904 faimdprintf(sess, 0, "ERROR caching message cookie\n");
905
906 aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
907
908 if (desc)
909 free(desc);
910
911 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
912 ret = userfunc(sess, rx, channel, userinfo, &args);
00ef5271 913
914#endif
6ae3c48d 915 } else
916 faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", args.reqclass);
00ef5271 917
6ae3c48d 918 aim_freetlvchain(&list2);
00ef5271 919
6ae3c48d 920 return ret;
e5012450 921}
922
49c8a2fa 923/*
924 * It can easily be said that parsing ICBMs is THE single
925 * most difficult thing to do in the in AIM protocol. In
926 * fact, I think I just did say that.
927 *
928 * Below is the best damned solution I've come up with
929 * over the past sixteen months of battling with it. This
930 * can parse both away and normal messages from every client
931 * I have access to. Its not fast, its not clean. But it works.
932 *
49c8a2fa 933 */
00ef5271 934static 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 935{
6ae3c48d 936 int i, ret = 0;
937 unsigned char cookie[8];
938 int channel;
939 struct aim_userinfo_s userinfo;
940
941 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
942
943 /*
944 * Read ICBM Cookie. And throw away.
945 */
946 for (i = 0; i < 8; i++)
947 cookie[i] = aimutil_get8(data+i);
948
949 /*
950 * Channel ID.
951 *
952 * Channel 0x0001 is the message channel. There are
953 * other channels for things called "rendevous"
954 * which represent chat and some of the other new
955 * features of AIM2/3/3.5.
956 *
957 * Channel 0x0002 is the Rendevous channel, which
958 * is where Chat Invitiations and various client-client
959 * connection negotiations come from.
960 *
961 */
962 channel = aimutil_get16(data+i);
963 i += 2;
964
965 /*
966 * Technically Channel 3 in chat could be done here too.
967 */
968 if ((channel != 0x01) && (channel != 0x02)) {
969 faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
970 return 1;
971 }
972
973 /*
974 * Extract the standard user info block.
975 *
976 * Note that although this contains TLVs that appear contiguous
977 * with the TLVs read below, they are two different pieces. The
978 * userinfo block contains the number of TLVs that contain user
979 * information, the rest are not even though there is no seperation.
980 * aim_extractuserinfo() returns the number of bytes used by the
981 * userinfo tlvs, so you can start reading the rest of them right
982 * afterward.
983 *
984 * That also means that TLV types can be duplicated between the
985 * userinfo block and the rest of the message, however there should
986 * never be two TLVs of the same type in one block.
987 *
988 */
989 i += aim_extractuserinfo(sess, data+i, &userinfo);
990
991 /*
992 * From here on, its depends on what channel we're on.
993 *
994 * Technically all channels have a TLV list have this, however,
995 * for the common channel 1 case, in-place parsing is used for
996 * performance reasons (less memory allocation).
997 */
998 if (channel == 1) {
999
1000 ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, data+i, datalen-i, cookie);
1001
1002 } else if (channel == 0x0002) {
1003 struct aim_tlvlist_t *tlvlist;
1004
1005 /*
1006 * Read block of TLVs (not including the userinfo data). All
1007 * further data is derived from what is parsed here.
1008 */
1009 tlvlist = aim_readtlvchain(data+i, datalen-i);
1010
1011 ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie);
1012
1013 /*
1014 * Free up the TLV chain.
1015 */
1016 aim_freetlvchain(&tlvlist);
1017 }
1018
1019 return ret;
49c8a2fa 1020}
1021
040457cc 1022/*
1023 * Possible codes:
1024 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
1025 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
1026 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
1027 *
1028 */
6ae3c48d 1029faim_export int aim_denytransfer(struct aim_session_t *sess,
1030 struct aim_conn_t *conn,
1031 const char *sender,
1032 const char *cookie,
1033 unsigned short code)
040457cc 1034{
6ae3c48d 1035 struct command_tx_struct *newpacket;
1036 int curbyte, i;
040457cc 1037
6ae3c48d 1038 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sender)+6)))
1039 return -ENOMEM;
040457cc 1040
6ae3c48d 1041 newpacket->lock = 1;
040457cc 1042
6ae3c48d 1043 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid++);
1044 for (i = 0; i < 8; i++)
1045 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
1046 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
1047 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
1048 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
1049 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
040457cc 1050
6ae3c48d 1051 newpacket->lock = 0;
1052 aim_tx_enqueue(sess, newpacket);
040457cc 1053
6ae3c48d 1054 return 0;
040457cc 1055}
1056
49c8a2fa 1057/*
355229fe 1058 * aim_reqicbmparaminfo()
49c8a2fa 1059 *
355229fe 1060 * Request ICBM parameter information.
49c8a2fa 1061 *
1062 */
355229fe 1063faim_export unsigned long aim_reqicbmparams(struct aim_session_t *sess, struct aim_conn_t *conn)
1064{
1065 return aim_genericreq_n(sess, conn, 0x0004, 0x0004);
1066}
1067
1068/*
1069 *
1070 */
1071faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_icbmparameters *params)
49c8a2fa 1072{
6ae3c48d 1073 struct command_tx_struct *newpacket;
1074 int curbyte;
49c8a2fa 1075
355229fe 1076 if (!sess || !conn || !params)
1077 return -EINVAL;
1078
6ae3c48d 1079 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+16)))
1080 return -ENOMEM;
5b79dc93 1081
6ae3c48d 1082 newpacket->lock = 1;
5b79dc93 1083
6ae3c48d 1084 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid++);
355229fe 1085
1086 /* This is read-only (in Parameter Reply). Must be set to zero here. */
1087 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
1088
1089 /* These are all read-write */
1090 curbyte += aimutil_put32(newpacket->data+curbyte, params->flags);
1091 curbyte += aimutil_put16(newpacket->data+curbyte, params->maxmsglen);
1092 curbyte += aimutil_put16(newpacket->data+curbyte, params->maxsenderwarn);
1093 curbyte += aimutil_put16(newpacket->data+curbyte, params->maxrecverwarn);
1094 curbyte += aimutil_put32(newpacket->data+curbyte, params->minmsginterval);
5b79dc93 1095
6ae3c48d 1096 newpacket->lock = 0;
1097 aim_tx_enqueue(sess, newpacket);
a25832e6 1098
6ae3c48d 1099 return 0;
a25832e6 1100}
1101
00ef5271 1102static 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 1103{
355229fe 1104 struct aim_icbmparameters params;
6ae3c48d 1105 aim_rxcallback_t userfunc;
1106 int i = 0;
a25832e6 1107
355229fe 1108 params.maxchan = aimutil_get16(data+i);
6ae3c48d 1109 i += 2;
a25832e6 1110
355229fe 1111 params.flags = aimutil_get32(data+i);
6ae3c48d 1112 i += 4;
96f8b1ed 1113
355229fe 1114 params.maxmsglen = aimutil_get16(data+i);
6ae3c48d 1115 i += 2;
a25832e6 1116
355229fe 1117 params.maxsenderwarn = aimutil_get16(data+i);
6ae3c48d 1118 i += 2;
49c8a2fa 1119
355229fe 1120 params.maxrecverwarn = aimutil_get16(data+i);
6ae3c48d 1121 i += 2;
e6b05d80 1122
355229fe 1123 params.minmsginterval = aimutil_get32(data+i);
6ae3c48d 1124 i += 4;
e6b05d80 1125
6ae3c48d 1126 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
355229fe 1127 return userfunc(sess, rx, &params);
00ef5271 1128
6ae3c48d 1129 return 0;
00ef5271 1130}
1131
1132static 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 1133{
36a61e0d 1134 int i, ret = 0;
6ae3c48d 1135 aim_rxcallback_t userfunc;
1136 unsigned short channel, nummissed, reason;
1137 struct aim_userinfo_s userinfo;
36a61e0d 1138
1139 for (i = 0; i < datalen; ) {
96f8b1ed 1140
36a61e0d 1141 /* Channel ID. */
1142 channel = aimutil_get16(data+i);
1143 i += 2;
6ae3c48d 1144
36a61e0d 1145 /* Extract the standard user info block. */
1146 i += aim_extractuserinfo(sess, data+i, &userinfo);
6ae3c48d 1147
36a61e0d 1148 nummissed = aimutil_get16(data+i);
1149 i += 2;
6ae3c48d 1150
36a61e0d 1151 reason = aimutil_get16(data+i);
1152 i += 2;
6ae3c48d 1153
36a61e0d 1154 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1155 ret = userfunc(sess, rx, channel, &userinfo, nummissed, reason);
1156 }
6ae3c48d 1157
36a61e0d 1158 return ret;
00ef5271 1159}
1160
1161static 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)
1162{
6ae3c48d 1163 aim_rxcallback_t userfunc;
1164 char sn[MAXSNLEN];
1165 unsigned char ck[8];
1166 unsigned short type;
1167 int i = 0;
1168 unsigned char snlen;
00ef5271 1169
6ae3c48d 1170 memcpy(ck, data, 8);
1171 i += 8;
00ef5271 1172
6ae3c48d 1173 type = aimutil_get16(data+i);
1174 i += 2;
00ef5271 1175
6ae3c48d 1176 snlen = aimutil_get8(data+i);
1177 i++;
00ef5271 1178
6ae3c48d 1179 memset(sn, 0, sizeof(sn));
1180 strncpy(sn, (char *)data+i, snlen);
00ef5271 1181
6ae3c48d 1182 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1183 return userfunc(sess, rx, type, sn);
00ef5271 1184
6ae3c48d 1185 return 0;
00ef5271 1186}
1187
1188static 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)
1189{
1190
6ae3c48d 1191 if (snac->subtype == 0x0005)
1192 return paraminfo(sess, mod, rx, snac, data, datalen);
1193 else if (snac->subtype == 0x0006)
1194 return outgoingim(sess, mod, rx, snac, data, datalen);
1195 else if (snac->subtype == 0x0007)
1196 return incomingim(sess, mod, rx, snac, data, datalen);
1197 else if (snac->subtype == 0x000a)
1198 return missedcall(sess, mod, rx, snac, data, datalen);
1199 else if (snac->subtype == 0x000c)
1200 return msgack(sess, mod, rx, snac, data, datalen);
1201
1202 return 0;
00ef5271 1203}
1204
1205faim_internal int msg_modfirst(struct aim_session_t *sess, aim_module_t *mod)
1206{
1207
6ae3c48d 1208 mod->family = 0x0004;
1209 mod->version = 0x0000;
1210 mod->flags = 0;
1211 strncpy(mod->name, "messaging", sizeof(mod->name));
1212 mod->snachandler = snachandler;
00ef5271 1213
6ae3c48d 1214 return 0;
96f8b1ed 1215}
This page took 0.241525 seconds and 5 git commands to generate.