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