]> andersk Git - libfaim.git/blame - src/im.c
- Mon Mar 5 01:19:48 UTC 2001
[libfaim.git] / src / im.c
CommitLineData
9de3ca7e 1/*
2 * aim_im.c
3 *
4 * The routines for sending/receiving Instant Messages.
5 *
6 */
7
37ee990e 8#define FAIM_INTERNAL
dd60ff8b 9#include <aim.h>
9de3ca7e 10
9d83220c 11/*
12 * Takes a msghdr (and a length) and returns a client type
13 * code. Note that this is *only a guess* and has a low likelihood
14 * of actually being accurate.
15 *
16 * Its based on experimental data, with the help of Eric Warmenhoven
17 * who seems to have collected a wide variety of different AIM clients.
18 *
19 *
20 * Heres the current collection:
21 * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414
22 * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464,
23 * 4.3.2229, 4.4.2286
24 * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here)
25 * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any
26 * TOC client
27 */
28faim_export unsigned short aim_fingerprintclient(unsigned char *msghdr, int len)
29{
30 static const struct {
31 unsigned short clientid;
32 int len;
33 unsigned char data[10];
34 } fingerprints[] = {
35 /* AOL Mobile Communicator, WinAIM 1.0.414 */
36 { AIM_CLIENTTYPE_MC,
37 9, {0x05, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01}},
38
39 /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
40 { AIM_CLIENTTYPE_WINAIM,
41 9, {0x05, 0x01, 0x00, 0x03, 0x01, 0x01, 0x02, 0x01, 0x01}},
42
43 /* WinAIM 4.1.2010, libfaim */
44 { AIM_CLIENTTYPE_WINAIM41,
45 10, {0x05, 0x01, 0x00, 0x04, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01}},
46
47 /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
48 { AIM_CLIENTTYPE_AOL_TOC,
49 7, {0x05, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01}},
50
51 { 0, 0}
52 };
53 int i;
54
55 if (!msghdr || (len <= 0))
56 return 0;
57
58 for (i = 0; fingerprints[i].len; i++) {
59 if (fingerprints[i].len != len)
60 continue;
61 if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
62 return fingerprints[i].clientid;
63 }
64
65 return AIM_CLIENTTYPE_UNKNOWN;
66}
67
9de3ca7e 68/*
69 * Send an ICBM (instant message).
70 *
71 *
72 * Possible flags:
73 * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
74 * AIM_IMFLAGS_ACK -- Requests that the server send an ack
75 * when the message is received (of type 0x0004/0x000c)
76 *
9de3ca7e 77 */
78b3fb13 78faim_export unsigned long aim_send_im(struct aim_session_t *sess,
79 struct aim_conn_t *conn,
80 char *destsn, u_int flags, char *msg)
9de3ca7e 81{
82
49c8a2fa 83 int curbyte,i;
5b79dc93 84 struct command_tx_struct *newpacket;
9de3ca7e 85
91931247 86 if (strlen(msg) >= MAXMSGLEN)
87 return -1;
88
646c6b52 89 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, strlen(msg)+256)))
5b79dc93 90 return -1;
9de3ca7e 91
5b79dc93 92 newpacket->lock = 1; /* lock struct */
9de3ca7e 93
94 curbyte = 0;
5b79dc93 95 curbyte += aim_putsnac(newpacket->data+curbyte,
a25832e6 96 0x0004, 0x0006, 0x0000, sess->snac_nextid);
9de3ca7e 97
49c8a2fa 98 /*
99 * Generate a random message cookie
a25832e6 100 *
101 * We could cache these like we do SNAC IDs. (In fact, it
102 * might be a good idea.) In the message error functions,
103 * the 8byte message cookie is returned as well as the
104 * SNAC ID.
105 *
49c8a2fa 106 */
107 for (i=0;i<8;i++)
5ac21963 108 curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) rand());
9de3ca7e 109
49c8a2fa 110 /*
111 * Channel ID
112 */
5b79dc93 113 curbyte += aimutil_put16(newpacket->data+curbyte,0x0001);
9de3ca7e 114
49c8a2fa 115 /*
116 * Destination SN (prepended with byte length)
117 */
5b79dc93 118 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
119 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
9de3ca7e 120
49c8a2fa 121 /*
122 * metaTLV start.
123 */
5b79dc93 124 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
e5012450 125 curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x10);
9de3ca7e 126
49c8a2fa 127 /*
e5012450 128 * Flag data / ICBM Parameters?
9d83220c 129 *
130 * I don't know what these are...
131 *
49c8a2fa 132 */
e5012450 133 curbyte += aimutil_put8(newpacket->data+curbyte, 0x05);
134 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
135
136 /* number of bytes to follow */
137 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
138 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
139 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
140 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
141 curbyte += aimutil_put8(newpacket->data+curbyte, 0x02);
142
5b79dc93 143 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0101);
9de3ca7e 144
49c8a2fa 145 /*
146 * Message block length.
147 */
5b79dc93 148 curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x04);
9de3ca7e 149
49c8a2fa 150 /*
151 * Character set data?
152 */
5b79dc93 153 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
154 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
9de3ca7e 155
49c8a2fa 156 /*
157 * Message. Not terminated.
158 */
5b79dc93 159 curbyte += aimutil_putstr(newpacket->data+curbyte,msg, strlen(msg));
9de3ca7e 160
49c8a2fa 161 /*
162 * Set the Request Acknowledge flag.
163 */
5b79dc93 164 if (flags & AIM_IMFLAGS_ACK) {
165 curbyte += aimutil_put16(newpacket->data+curbyte,0x0003);
166 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
167 }
49c8a2fa 168
169 /*
170 * Set the Autoresponse flag.
171 */
5b79dc93 172 if (flags & AIM_IMFLAGS_AWAY) {
173 curbyte += aimutil_put16(newpacket->data+curbyte,0x0004);
174 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
175 }
49c8a2fa 176
5b79dc93 177 newpacket->commandlen = curbyte;
178 newpacket->lock = 0;
9de3ca7e 179
5b79dc93 180 aim_tx_enqueue(sess, newpacket);
49c8a2fa 181
1ea867e3 182 aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, destsn, strlen(destsn)+1);
183 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
9de3ca7e 184
1ea867e3 185 return sess->snac_nextid;
9de3ca7e 186}
187
78b3fb13 188faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
189 struct command_rx_struct *command)
e5012450 190{
191 unsigned int i = 0, z;
192 rxcallback_t userfunc = NULL;
193 unsigned char cookie[8];
194 int channel;
195 struct aim_tlvlist_t *tlvlist;
196 char sn[MAXSNLEN];
197 unsigned short icbmflags = 0;
198 unsigned char flag1 = 0, flag2 = 0;
199 unsigned char *msgblock = NULL, *msg = NULL;
200
201 i = 10;
202
203 /* ICBM Cookie. */
204 for (z=0; z<8; z++,i++)
205 cookie[z] = command->data[i];
206
207 /* Channel ID */
208 channel = aimutil_get16(command->data+i);
209 i += 2;
210
211 if (channel != 0x01) {
646c6b52 212 faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
e5012450 213 return 1;
214 }
215
78b3fb13 216 strncpy(sn, (char *) command->data+i+1, (int) *(command->data+i));
e5012450 217 i += 1 + (int) *(command->data+i);
218
219 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
220
221 if (aim_gettlv(tlvlist, 0x0003, 1))
222 icbmflags |= AIM_IMFLAGS_ACK;
223 if (aim_gettlv(tlvlist, 0x0004, 1))
224 icbmflags |= AIM_IMFLAGS_AWAY;
225
226 if (aim_gettlv(tlvlist, 0x0002, 1)) {
227 int j = 0;
228
78b3fb13 229 msgblock = (unsigned char *)aim_gettlv_str(tlvlist, 0x0002, 1);
e5012450 230
231 /* no, this really is correct. I'm not high or anything either. */
232 j += 2;
233 j += 2 + aimutil_get16(msgblock+j);
234 j += 2;
235
236 j += 2; /* final block length */
237
238 flag1 = aimutil_get16(msgblock);
239 j += 2;
240 flag2 = aimutil_get16(msgblock);
241 j += 2;
242
243 msg = msgblock+j;
244 }
245
646c6b52 246 if ((userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0006)) || (i = 0))
e5012450 247 i = userfunc(sess, command, channel, sn, msg, icbmflags, flag1, flag2);
248
249 if (msgblock)
250 free(msgblock);
251 aim_freetlvchain(&tlvlist);
252
253 return 0;
254}
255
49c8a2fa 256/*
257 * It can easily be said that parsing ICBMs is THE single
258 * most difficult thing to do in the in AIM protocol. In
259 * fact, I think I just did say that.
260 *
261 * Below is the best damned solution I've come up with
262 * over the past sixteen months of battling with it. This
263 * can parse both away and normal messages from every client
264 * I have access to. Its not fast, its not clean. But it works.
265 *
266 * We should also support at least minimal parsing of
267 * Channel 2, so that we can at least know the name of the
268 * room we're invited to, but obviously can't attend...
269 *
270 */
78b3fb13 271faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
272 struct command_rx_struct *command)
9de3ca7e 273{
26af6789 274 u_int i = 0,z;
9de3ca7e 275 rxcallback_t userfunc = NULL;
49c8a2fa 276 u_char cookie[8];
277 int channel;
278 struct aim_tlvlist_t *tlvlist;
26af6789 279 struct aim_userinfo_s userinfo;
49c8a2fa 280
95d7332a 281 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
282
49c8a2fa 283 i = 10; /* Skip SNAC header */
284
9de3ca7e 285 /*
49c8a2fa 286 * Read ICBM Cookie. And throw away.
9de3ca7e 287 */
49c8a2fa 288 for (z=0; z<8; z++,i++)
289 cookie[z] = command->data[i];
9de3ca7e 290
49c8a2fa 291 /*
292 * Channel ID.
293 *
294 * Channel 0x0001 is the message channel. There are
295 * other channels for things called "rendevous"
296 * which represent chat and some of the other new
26af6789 297 * features of AIM2/3/3.5.
298 *
299 * Channel 0x0002 is the Rendevous channel, which
50443ea0 300 * is where Chat Invitiations and various client-client
301 * connection negotiations come from.
26af6789 302 *
49c8a2fa 303 */
304 channel = aimutil_get16(command->data+i);
9de3ca7e 305 i += 2;
26af6789 306
307 /*
308 *
309 */
646c6b52 310 if ((channel != 0x01) && (channel != 0x02)) {
311 faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
312 return 1;
313 }
9de3ca7e 314
49c8a2fa 315 /*
68ac63c2 316 * Extract the standard user info block.
317 *
318 * Note that although this contains TLVs that appear contiguous
319 * with the TLVs read below, they are two different pieces. The
320 * userinfo block contains the number of TLVs that contain user
321 * information, the rest are not even though there is no seperation.
322 * aim_extractuserinfo() returns the number of bytes used by the
323 * userinfo tlvs, so you can start reading the rest of them right
324 * afterward.
325 *
326 * That also means that TLV types can be duplicated between the
327 * userinfo block and the rest of the message, however there should
328 * never be two TLVs of the same type in one block.
329 *
26af6789 330 */
646c6b52 331 i += aim_extractuserinfo(sess, command->data+i, &userinfo);
26af6789 332
49c8a2fa 333 /*
68ac63c2 334 * Read block of TLVs (not including the userinfo data). All
335 * further data is derived from what is parsed here.
49c8a2fa 336 */
337 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
9de3ca7e 338
49c8a2fa 339 /*
26af6789 340 * From here on, its depends on what channel we're on.
49c8a2fa 341 */
26af6789 342 if (channel == 1)
49c8a2fa 343 {
26af6789 344 u_int j = 0, y = 0, z = 0;
345 char *msg = NULL;
346 u_int icbmflags = 0;
7392c79f 347 struct aim_tlv_t *msgblocktlv;
26af6789 348 u_char *msgblock;
349 u_short flag1,flag2;
9d83220c 350 int finlen = 0;
351 unsigned char fingerprint[10];
352 u_short wastebits;
95d7332a 353
26af6789 354 /*
355 * Check Autoresponse status. If it is an autoresponse,
68ac63c2 356 * it will contain a type 0x0004 TLV, with zero length.
26af6789 357 */
68ac63c2 358 if (aim_gettlv(tlvlist, 0x0004, 1))
26af6789 359 icbmflags |= AIM_IMFLAGS_AWAY;
360
361 /*
362 * Check Ack Request status.
363 */
68ac63c2 364 if (aim_gettlv(tlvlist, 0x0003, 1))
26af6789 365 icbmflags |= AIM_IMFLAGS_ACK;
366
26af6789 367 /*
368 * Message block.
26af6789 369 */
370 msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
68ac63c2 371 if (!msgblocktlv || !msgblocktlv->value) {
646c6b52 372 faimdprintf(sess, 0, "icbm: major error! no message block TLV found!\n");
68ac63c2 373 aim_freetlvchain(&tlvlist);
374 return 1;
375 }
26af6789 376
377 /*
378 * Extracting the message from the unknown cruft.
379 *
380 * This is a bit messy, and I'm not really qualified,
381 * even as the author, to comment on it. At least
382 * its not as bad as a while loop shooting into infinity.
383 *
384 * "Do you believe in magic?"
385 *
386 */
387 msgblock = msgblocktlv->value;
388 j = 0;
389
390 wastebits = aimutil_get8(msgblock+j++);
391 wastebits = aimutil_get8(msgblock+j++);
392
393 y = aimutil_get16(msgblock+j);
394 j += 2;
395 for (z = 0; z < y; z++)
396 wastebits = aimutil_get8(msgblock+j++);
397 wastebits = aimutil_get8(msgblock+j++);
398 wastebits = aimutil_get8(msgblock+j++);
9d83220c 399
400 finlen = j;
401 if (finlen > sizeof(fingerprint))
402 finlen = sizeof(fingerprint);
403 memcpy(fingerprint, msgblocktlv->value, finlen);
404
26af6789 405 /*
406 * Message string length, including flag words.
407 */
408 i = aimutil_get16(msgblock+j);
409 j += 2;
410
411 /*
412 * Flag words.
413 *
414 * Its rumored that these can kick in some funky
415 * 16bit-wide char stuff that used to really kill
416 * libfaim. Hopefully the latter is no longer true.
417 *
418 * Though someone should investiagte the former.
419 *
420 */
421 flag1 = aimutil_get16(msgblock+j);
422 j += 2;
423 flag2 = aimutil_get16(msgblock+j);
424 j += 2;
425
426 if (flag1 || flag2)
646c6b52 427 faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
26af6789 428
429 /*
430 * Message string.
431 */
432 i -= 4;
433 msg = (char *)malloc(i+1);
434 memcpy(msg, msgblock+j, i);
435 msg[i] = '\0';
436
437 /*
438 * Call client.
439 */
646c6b52 440 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
26af6789 441 if (userfunc)
9d83220c 442 i = userfunc(sess, command, channel, &userinfo, msg, icbmflags, flag1, flag2, finlen, fingerprint);
26af6789 443 else
444 i = 0;
445
446 free(msg);
49c8a2fa 447 }
26af6789 448 else if (channel == 0x0002)
0c20631f 449 {
26af6789 450 struct aim_tlv_t *block1;
451 struct aim_tlvlist_t *list2;
040457cc 452 unsigned short reqclass = 0;
b69540e3 453 unsigned short status = 0;
26af6789 454
26af6789 455 /*
456 * There's another block of TLVs embedded in the type 5 here.
457 */
458 block1 = aim_gettlv(tlvlist, 0x0005, 1);
040457cc 459 if (!block1) {
646c6b52 460 faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
040457cc 461 aim_freetlvchain(&tlvlist);
26af6789 462 return 1; /* major problem */
040457cc 463 }
26af6789 464
b69540e3 465 /*
466 * First two bytes represent the status of the connection.
467 *
468 * 0 is a request, 2 is an accept
469 */
470 status = aimutil_get16(block1->value+0);
471
472 /*
473 * Next comes the cookie. Should match the ICBM cookie.
474 */
475 if (memcmp(block1->value+2, cookie, 8) != 0)
646c6b52 476 faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
26af6789 477
0c20631f 478 /*
b69540e3 479 * The next 16bytes are a capability block so we can
480 * identify what type of rendezvous this is.
0c20631f 481 *
b69540e3 482 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
483 * for pointing some of this out to me. In fact, a lot of
484 * the client-to-client info comes from the work of the GAIM
485 * developers. Thanks!
486 *
487 * Read off one capability string and we should have it ID'd.
488 *
0c20631f 489 */
646c6b52 490 reqclass = aim_getcap(sess, block1->value+2+8, 0x10);
b69540e3 491 if (reqclass == 0x0000) {
646c6b52 492 faimdprintf(sess, 0, "rend: no ID block\n");
040457cc 493 aim_freetlvchain(&tlvlist);
494 return 1;
495 }
496
b69540e3 497 /*
498 * What follows may be TLVs or nothing, depending on the
499 * purpose of the message.
500 *
501 * Ack packets for instance have nothing more to them.
502 */
503 list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
504
505 if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
040457cc 506 struct aim_msgcookie_t *cook;
7392c79f 507 int type;
508
509 type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
040457cc 510
646c6b52 511 if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
512 faimdprintf(sess, 0, "non-data rendezvous thats not in cache %d/%s!\n", type, cookie);
513 aim_freetlvchain(&list2);
514 aim_freetlvchain(&tlvlist);
515 return 1;
26af6789 516 }
517
37ee990e 518 if (cook->type == AIM_COOKIETYPE_OFTGET) {
7392c79f 519 struct aim_filetransfer_priv *ft;
26af6789 520
040457cc 521 if (cook->data) {
1ea867e3 522 int errorcode = -1; /* XXX shouldnt this be 0? */
040457cc 523
7392c79f 524 ft = (struct aim_filetransfer_priv *)cook->data;
040457cc 525
37ee990e 526 if(status != 0x0002) {
527 if (aim_gettlv(list2, 0x000b, 1))
528 errorcode = aim_gettlv16(list2, 0x000b, 1);
529
530 if (errorcode)
646c6b52 531 faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
b69540e3 532 }
040457cc 533 } else {
646c6b52 534 faimdprintf(sess, 0, "no data attached to file transfer\n");
040457cc 535 }
b69540e3 536 } else if (cook->type == AIM_CAPS_VOICE) {
646c6b52 537 faimdprintf(sess, 0, "voice request cancelled\n");
040457cc 538 } else {
646c6b52 539 faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
040457cc 540 }
37ee990e 541
b69540e3 542 if (list2)
543 aim_freetlvchain(&list2);
544 aim_freetlvchain(&tlvlist);
040457cc 545 return 1;
546 }
547
040457cc 548 /*
b69540e3 549 * The rest of the handling depends on what type it is.
040457cc 550 */
b69540e3 551 if (reqclass & AIM_CAPS_BUDDYICON) {
f21cc652 552
553 /*
554 * Call client.
555 */
871e2fd0 556#if 0
646c6b52 557 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
f21cc652 558 if (userfunc || (i = 0))
559 i = userfunc(sess,
560 command,
561 channel,
562 reqclass,
871e2fd0 563 &userinfo,
564 ip,
565 cookie);
566#endif
f21cc652 567
b69540e3 568 } else if (reqclass & AIM_CAPS_VOICE) {
7392c79f 569 struct aim_msgcookie_t *cachedcook;
b69540e3 570
646c6b52 571 faimdprintf(sess, 0, "rend: voice!\n");
b69540e3 572
7392c79f 573 if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t))))
574 return 1;
575
576 memcpy(cachedcook->cookie, cookie, 8);
577 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
578 cachedcook->data = NULL;
579
646c6b52 580 if (aim_cachecookie(sess, cachedcook) == -1)
581 faimdprintf(sess, 0, "ERROR caching message cookie\n");
040457cc 582
583 /* XXX: implement all this */
584
585 /*
586 * Call client.
587 */
646c6b52 588 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
040457cc 589 if (userfunc || (i = 0)) {
7392c79f 590 i = userfunc(sess, command, channel, reqclass, &userinfo);
040457cc 591 }
7392c79f 592 } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) {
040457cc 593 char ip[30];
7392c79f 594 struct aim_directim_priv *priv;
040457cc 595
871e2fd0 596 memset(ip, 0, 30);
040457cc 597
7392c79f 598 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
040457cc 599 struct aim_tlv_t *iptlv, *porttlv;
0c20631f 600
040457cc 601 iptlv = aim_gettlv(list2, 0x0003, 1);
602 porttlv = aim_gettlv(list2, 0x0005, 1);
603
871e2fd0 604 snprintf(ip, 30, "%d.%d.%d.%d:%d",
040457cc 605 aimutil_get8(iptlv->value+0),
606 aimutil_get8(iptlv->value+1),
607 aimutil_get8(iptlv->value+2),
608 aimutil_get8(iptlv->value+3),
b69540e3 609 4443 /*aimutil_get16(porttlv->value)*/);
040457cc 610 }
611
646c6b52 612 faimdprintf(sess, 0, "rend: directIM request from %s (%s)\n",
613 userinfo.sn, ip);
b69540e3 614
7392c79f 615 /* XXX: there are a couple of different request packets for
616 * different things */
040457cc 617
7392c79f 618 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
619 memcpy(priv->ip, ip, sizeof(priv->ip));
620 memcpy(priv->sn, userinfo.sn, sizeof(priv->sn));
621 memcpy(priv->cookie, cookie, sizeof(priv->cookie));
040457cc 622
f21cc652 623 /*
624 * Call client.
625 */
646c6b52 626 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
f21cc652 627 if (userfunc || (i = 0))
628 i = userfunc(sess,
629 command,
630 channel,
631 reqclass,
7392c79f 632 &userinfo, priv);
b69540e3 633
634 } else if (reqclass & AIM_CAPS_CHAT) {
635 struct aim_tlv_t *miscinfo;
040457cc 636 struct aim_chat_roominfo roominfo;
637 char *msg=NULL,*encoding=NULL,*lang=NULL;
638
b69540e3 639 miscinfo = aim_gettlv(list2, 0x2711, 1);
040457cc 640 aim_chat_readroominfo(miscinfo->value, &roominfo);
641
642 if (aim_gettlv(list2, 0x000c, 1))
643 msg = aim_gettlv_str(list2, 0x000c, 1);
0c20631f 644
040457cc 645 if (aim_gettlv(list2, 0x000d, 1))
646 encoding = aim_gettlv_str(list2, 0x000d, 1);
0c20631f 647
040457cc 648 if (aim_gettlv(list2, 0x000e, 1))
649 lang = aim_gettlv_str(list2, 0x000e, 1);
26af6789 650
040457cc 651 /*
652 * Call client.
653 */
646c6b52 654 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
040457cc 655 if (userfunc || (i = 0))
656 i = userfunc(sess,
657 command,
658 channel,
f21cc652 659 reqclass,
040457cc 660 &userinfo,
661 &roominfo,
662 msg,
663 encoding?encoding+1:NULL,
664 lang?lang+1:NULL);
0c20631f 665 free(roominfo.name);
666 free(msg);
667 free(encoding);
668 free(lang);
b69540e3 669 } else if (reqclass & AIM_CAPS_GETFILE) {
7392c79f 670 char ip[30];
7392c79f 671 struct aim_msgcookie_t *cachedcook;
7392c79f 672 struct aim_tlv_t *miscinfo;
7392c79f 673
674 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t))))
675 return 0;
676
871e2fd0 677 memset(ip, 0, 30);
f21cc652 678
7392c79f 679 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
646c6b52 680 aim_cookie_free(sess, cachedcook);
7392c79f 681 return 0;
682 }
683
684 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
685 struct aim_tlv_t *iptlv, *porttlv;
686
687 if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
646c6b52 688 aim_cookie_free(sess, cachedcook);
7392c79f 689 return 0;
690 }
691
871e2fd0 692 snprintf(ip, 30, "%d.%d.%d.%d:%d",
7392c79f 693 aimutil_get8(iptlv->value+0),
694 aimutil_get8(iptlv->value+1),
695 aimutil_get8(iptlv->value+2),
696 aimutil_get8(iptlv->value+3),
697 aimutil_get16(porttlv->value));
698 }
699
646c6b52 700 faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo.sn, ip);
7392c79f 701
f21cc652 702 /*
703 * Call client.
704 */
646c6b52 705 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
f21cc652 706 if (userfunc || (i = 0))
707 i = userfunc(sess,
708 command,
709 channel,
710 reqclass,
871e2fd0 711 &userinfo,
712 ip,
713 cookie);
f21cc652 714
b69540e3 715 } else if (reqclass & AIM_CAPS_SENDFILE) {
f21cc652 716#if 0
7392c79f 717 char ip[30];
718 char *desc = NULL;
719 struct aim_msgcookie_t *cachedcook;
720 struct aim_filetransfer_priv *ft;
721 struct aim_tlv_t *miscinfo;
b69540e3 722
723 memset(ip, 0, sizeof(ip));
724
7392c79f 725 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)))
726 return 0;
b69540e3 727
728 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
729 struct aim_tlv_t *iptlv, *porttlv;
730
731 iptlv = aim_gettlv(list2, 0x0003, 1);
732 porttlv = aim_gettlv(list2, 0x0005, 1);
733
734 snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d",
735 aimutil_get8(iptlv->value+0),
736 aimutil_get8(iptlv->value+1),
737 aimutil_get8(iptlv->value+2),
738 aimutil_get8(iptlv->value+3),
739 aimutil_get16(porttlv->value));
740 }
741
742 if (aim_gettlv(list2, 0x000c, 1)) {
743 desc = aim_gettlv_str(list2, 0x000c, 1);
744 }
745
646c6b52 746 faimdprintf(sess, 0, "rend: file transfer request from %s for %s: %s (%s)\n",
747 userinfo.sn,
748 miscinfo->value+8,
749 desc,
750 ip);
b69540e3 751
7392c79f 752 memcpy(cachedcook->cookie, cookie, 8);
b69540e3 753
7392c79f 754 ft = malloc(sizeof(struct aim_filetransfer_priv));
755 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
b69540e3 756 strncpy(ft->ip, ip, sizeof(ft->ip));
7392c79f 757 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
758 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
759 cachedcook->data = ft;
b69540e3 760
646c6b52 761 if (aim_cachecookie(sess, cachedcook) == -1)
762 faimdprintf(sess, 0, "ERROR caching message cookie\n");
b69540e3 763
764
7392c79f 765 aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
766
767 if (desc)
768 free(desc);
f21cc652 769#endif
7392c79f 770 /*
771 * Call client.
772 */
646c6b52 773 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
7392c79f 774 if (userfunc || (i = 0))
775 i = userfunc(sess,
776 command,
777 channel,
778 reqclass,
779 &userinfo);
646c6b52 780 } else
781 faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", reqclass);
040457cc 782
26af6789 783 aim_freetlvchain(&list2);
784 }
9de3ca7e 785
49c8a2fa 786 /*
787 * Free up the TLV chain.
788 */
789 aim_freetlvchain(&tlvlist);
26af6789 790
49c8a2fa 791
26af6789 792 return i;
49c8a2fa 793}
794
040457cc 795/*
796 * Possible codes:
797 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
798 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
799 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
800 *
801 */
78b3fb13 802faim_export unsigned long aim_denytransfer(struct aim_session_t *sess,
803 struct aim_conn_t *conn,
804 char *sender,
805 char *cookie,
806 unsigned short code)
040457cc 807{
808 struct command_tx_struct *newpacket;
809 int curbyte, i;
810
646c6b52 811 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sender)+6)))
040457cc 812 return -1;
813
814 newpacket->lock = 1;
815
816 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid);
817 for (i = 0; i < 8; i++)
818 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
819 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
820 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
821 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
822 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
823
824 newpacket->lock = 0;
825 aim_tx_enqueue(sess, newpacket);
826
827 return (sess->snac_nextid++);
828}
829
49c8a2fa 830/*
831 * Not real sure what this does, nor does anyone I've talk to.
832 *
833 * Didn't use to send it. But now I think it might be a good
834 * idea.
835 *
836 */
78b3fb13 837faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess,
838 struct aim_conn_t *conn)
49c8a2fa 839{
5b79dc93 840 struct command_tx_struct *newpacket;
49c8a2fa 841 int curbyte;
842
646c6b52 843 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+16)))
5b79dc93 844 return -1;
845
846 newpacket->lock = 1;
847
848 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
849 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
850 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00000003);
851 curbyte += aimutil_put8(newpacket->data+curbyte, 0x1f);
852 curbyte += aimutil_put8(newpacket->data+curbyte, 0x40);
853 curbyte += aimutil_put8(newpacket->data+curbyte, 0x03);
854 curbyte += aimutil_put8(newpacket->data+curbyte, 0xe7);
855 curbyte += aimutil_put8(newpacket->data+curbyte, 0x03);
856 curbyte += aimutil_put8(newpacket->data+curbyte, 0xe7);
857 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
858 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
859
860 newpacket->lock = 0;
861 aim_tx_enqueue(sess, newpacket);
a25832e6 862
863 return (sess->snac_nextid++);
864}
865
78b3fb13 866faim_internal int aim_parse_msgerror_middle(struct aim_session_t *sess,
867 struct command_rx_struct *command)
a25832e6 868{
869 u_long snacid = 0x000000000;
870 struct aim_snac_t *snac = NULL;
871 int ret = 0;
872 rxcallback_t userfunc = NULL;
96f8b1ed 873 char *dest;
874 unsigned short reason = 0;
a25832e6 875
876 /*
877 * Get SNAC from packet and look it up
878 * the list of unrepliedto/outstanding
879 * SNACs.
880 *
881 * After its looked up, the SN that the
882 * message should've gone to will be
883 * in the ->data element of the snac struct.
884 *
885 */
886 snacid = aimutil_get32(command->data+6);
887 snac = aim_remsnac(sess, snacid);
888
46b6130d 889 if (!snac) {
646c6b52 890 faimdprintf(sess, 0, "msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
96f8b1ed 891 dest = NULL;
892 } else
893 dest = snac->data;
894
895 reason = aimutil_get16(command->data+10);
a25832e6 896
897 /*
898 * Call client.
899 */
646c6b52 900 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0001);
a25832e6 901 if (userfunc)
96f8b1ed 902 ret = userfunc(sess, command, dest, reason);
a25832e6 903 else
904 ret = 0;
905
46b6130d 906 if (snac) {
907 free(snac->data);
908 free(snac);
909 }
49c8a2fa 910
a25832e6 911 return ret;
9de3ca7e 912}
e6b05d80 913
914
78b3fb13 915faim_internal int aim_parse_missedcall(struct aim_session_t *sess,
916 struct command_rx_struct *command)
96f8b1ed 917{
918 int i, ret = 1;
919 rxcallback_t userfunc = NULL;
920 unsigned short channel, nummissed, reason;
921 struct aim_userinfo_s userinfo;
922
923 i = 10; /* Skip SNAC header */
924
925
926 /*
927 * XXX: supposedly, this entire packet can repeat as many times
928 * as necessary. Should implement that.
929 */
930
931 /*
932 * Channel ID.
933 */
934 channel = aimutil_get16(command->data+i);
935 i += 2;
936
937 /*
938 * Extract the standard user info block.
939 */
646c6b52 940 i += aim_extractuserinfo(sess, command->data+i, &userinfo);
96f8b1ed 941
942 nummissed = aimutil_get16(command->data+i);
943 i += 2;
944
945 reason = aimutil_get16(command->data+i);
946 i += 2;
947
948 /*
949 * Call client.
950 */
646c6b52 951 userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x000a);
96f8b1ed 952 if (userfunc)
953 ret = userfunc(sess, command, channel, &userinfo, nummissed, reason);
954 else
955 ret = 0;
956
957 return ret;
958}
This page took 2.654521 seconds and 5 git commands to generate.