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