]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * aim_im.c | |
3 | * | |
4 | * The routines for sending/receiving Instant Messages. | |
5 | * | |
6 | */ | |
7 | ||
8 | #define FAIM_INTERNAL | |
9 | #include <aim.h> | |
10 | ||
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 | */ | |
28 | faim_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 | ||
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 | * | |
77 | */ | |
78 | faim_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) | |
81 | { | |
82 | ||
83 | int curbyte,i; | |
84 | struct command_tx_struct *newpacket; | |
85 | ||
86 | if (strlen(msg) >= MAXMSGLEN) | |
87 | return -1; | |
88 | ||
89 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, strlen(msg)+256))) | |
90 | return -1; | |
91 | ||
92 | newpacket->lock = 1; /* lock struct */ | |
93 | ||
94 | curbyte = 0; | |
95 | curbyte += aim_putsnac(newpacket->data+curbyte, | |
96 | 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
97 | ||
98 | /* | |
99 | * Generate a random message cookie | |
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 | * | |
106 | */ | |
107 | for (i=0;i<8;i++) | |
108 | curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) rand()); | |
109 | ||
110 | /* | |
111 | * Channel ID | |
112 | */ | |
113 | curbyte += aimutil_put16(newpacket->data+curbyte,0x0001); | |
114 | ||
115 | /* | |
116 | * Destination SN (prepended with byte length) | |
117 | */ | |
118 | curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn)); | |
119 | curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
120 | ||
121 | /* | |
122 | * metaTLV start. | |
123 | */ | |
124 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
125 | curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x10); | |
126 | ||
127 | /* | |
128 | * Flag data / ICBM Parameters? | |
129 | * | |
130 | * I don't know what these are... | |
131 | * | |
132 | */ | |
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 | ||
143 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0101); | |
144 | ||
145 | /* | |
146 | * Message block length. | |
147 | */ | |
148 | curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x04); | |
149 | ||
150 | /* | |
151 | * Character set data? | |
152 | */ | |
153 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
154 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
155 | ||
156 | /* | |
157 | * Message. Not terminated. | |
158 | */ | |
159 | curbyte += aimutil_putstr(newpacket->data+curbyte,msg, strlen(msg)); | |
160 | ||
161 | /* | |
162 | * Set the Request Acknowledge flag. | |
163 | */ | |
164 | if (flags & AIM_IMFLAGS_ACK) { | |
165 | curbyte += aimutil_put16(newpacket->data+curbyte,0x0003); | |
166 | curbyte += aimutil_put16(newpacket->data+curbyte,0x0000); | |
167 | } | |
168 | ||
169 | /* | |
170 | * Set the Autoresponse flag. | |
171 | */ | |
172 | if (flags & AIM_IMFLAGS_AWAY) { | |
173 | curbyte += aimutil_put16(newpacket->data+curbyte,0x0004); | |
174 | curbyte += aimutil_put16(newpacket->data+curbyte,0x0000); | |
175 | } | |
176 | ||
177 | newpacket->commandlen = curbyte; | |
178 | newpacket->lock = 0; | |
179 | ||
180 | aim_tx_enqueue(sess, newpacket); | |
181 | ||
182 | aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, destsn, strlen(destsn)+1); | |
183 | aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ | |
184 | ||
185 | return sess->snac_nextid; | |
186 | } | |
187 | ||
188 | faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess, | |
189 | struct command_rx_struct *command) | |
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) { | |
212 | faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel); | |
213 | return 1; | |
214 | } | |
215 | ||
216 | strncpy(sn, (char *) command->data+i+1, (int) *(command->data+i)); | |
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 | ||
229 | msgblock = (unsigned char *)aim_gettlv_str(tlvlist, 0x0002, 1); | |
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 | ||
246 | if ((userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0006)) || (i = 0)) | |
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 | ||
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 | */ | |
271 | faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess, | |
272 | struct command_rx_struct *command) | |
273 | { | |
274 | u_int i = 0,z; | |
275 | rxcallback_t userfunc = NULL; | |
276 | u_char cookie[8]; | |
277 | int channel; | |
278 | struct aim_tlvlist_t *tlvlist; | |
279 | struct aim_userinfo_s userinfo; | |
280 | ||
281 | memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s)); | |
282 | ||
283 | i = 10; /* Skip SNAC header */ | |
284 | ||
285 | /* | |
286 | * Read ICBM Cookie. And throw away. | |
287 | */ | |
288 | for (z=0; z<8; z++,i++) | |
289 | cookie[z] = command->data[i]; | |
290 | ||
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 | |
297 | * features of AIM2/3/3.5. | |
298 | * | |
299 | * Channel 0x0002 is the Rendevous channel, which | |
300 | * is where Chat Invitiations and various client-client | |
301 | * connection negotiations come from. | |
302 | * | |
303 | */ | |
304 | channel = aimutil_get16(command->data+i); | |
305 | i += 2; | |
306 | ||
307 | /* | |
308 | * | |
309 | */ | |
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 | } | |
314 | ||
315 | /* | |
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 | * | |
330 | */ | |
331 | i += aim_extractuserinfo(sess, command->data+i, &userinfo); | |
332 | ||
333 | /* | |
334 | * Read block of TLVs (not including the userinfo data). All | |
335 | * further data is derived from what is parsed here. | |
336 | */ | |
337 | tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i); | |
338 | ||
339 | /* | |
340 | * From here on, its depends on what channel we're on. | |
341 | */ | |
342 | if (channel == 1) | |
343 | { | |
344 | u_int j = 0, y = 0, z = 0; | |
345 | char *msg = NULL; | |
346 | u_int icbmflags = 0; | |
347 | struct aim_tlv_t *msgblocktlv; | |
348 | u_char *msgblock; | |
349 | u_short flag1,flag2; | |
350 | int finlen = 0; | |
351 | unsigned char fingerprint[10]; | |
352 | u_short wastebits; | |
353 | ||
354 | /* | |
355 | * Check Autoresponse status. If it is an autoresponse, | |
356 | * it will contain a type 0x0004 TLV, with zero length. | |
357 | */ | |
358 | if (aim_gettlv(tlvlist, 0x0004, 1)) | |
359 | icbmflags |= AIM_IMFLAGS_AWAY; | |
360 | ||
361 | /* | |
362 | * Check Ack Request status. | |
363 | */ | |
364 | if (aim_gettlv(tlvlist, 0x0003, 1)) | |
365 | icbmflags |= AIM_IMFLAGS_ACK; | |
366 | ||
367 | /* | |
368 | * Message block. | |
369 | */ | |
370 | msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1); | |
371 | if (!msgblocktlv || !msgblocktlv->value) { | |
372 | faimdprintf(sess, 0, "icbm: major error! no message block TLV found!\n"); | |
373 | aim_freetlvchain(&tlvlist); | |
374 | return 1; | |
375 | } | |
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++); | |
399 | ||
400 | finlen = j; | |
401 | if (finlen > sizeof(fingerprint)) | |
402 | finlen = sizeof(fingerprint); | |
403 | memcpy(fingerprint, msgblocktlv->value, finlen); | |
404 | ||
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) | |
427 | faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2); | |
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 | */ | |
440 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
441 | if (userfunc) | |
442 | i = userfunc(sess, command, channel, &userinfo, msg, icbmflags, flag1, flag2, finlen, fingerprint); | |
443 | else | |
444 | i = 0; | |
445 | ||
446 | free(msg); | |
447 | } | |
448 | else if (channel == 0x0002) | |
449 | { | |
450 | struct aim_tlv_t *block1; | |
451 | struct aim_tlvlist_t *list2; | |
452 | unsigned short reqclass = 0; | |
453 | unsigned short status = 0; | |
454 | ||
455 | /* | |
456 | * There's another block of TLVs embedded in the type 5 here. | |
457 | */ | |
458 | block1 = aim_gettlv(tlvlist, 0x0005, 1); | |
459 | if (!block1) { | |
460 | faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n"); | |
461 | aim_freetlvchain(&tlvlist); | |
462 | return 1; /* major problem */ | |
463 | } | |
464 | ||
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) | |
476 | faimdprintf(sess, 0, "rend: warning cookies don't match!\n"); | |
477 | ||
478 | /* | |
479 | * The next 16bytes are a capability block so we can | |
480 | * identify what type of rendezvous this is. | |
481 | * | |
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 | * | |
489 | */ | |
490 | reqclass = aim_getcap(sess, block1->value+2+8, 0x10); | |
491 | if (reqclass == 0x0000) { | |
492 | faimdprintf(sess, 0, "rend: no ID block\n"); | |
493 | aim_freetlvchain(&tlvlist); | |
494 | return 1; | |
495 | } | |
496 | ||
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)))) { | |
506 | struct aim_msgcookie_t *cook; | |
507 | int type; | |
508 | ||
509 | type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */ | |
510 | ||
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; | |
516 | } | |
517 | ||
518 | if (cook->type == AIM_COOKIETYPE_OFTGET) { | |
519 | struct aim_filetransfer_priv *ft; | |
520 | ||
521 | if (cook->data) { | |
522 | int errorcode = -1; /* XXX shouldnt this be 0? */ | |
523 | ||
524 | ft = (struct aim_filetransfer_priv *)cook->data; | |
525 | ||
526 | if(status != 0x0002) { | |
527 | if (aim_gettlv(list2, 0x000b, 1)) | |
528 | errorcode = aim_gettlv16(list2, 0x000b, 1); | |
529 | ||
530 | if (errorcode) | |
531 | faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode); | |
532 | } | |
533 | } else { | |
534 | faimdprintf(sess, 0, "no data attached to file transfer\n"); | |
535 | } | |
536 | } else if (cook->type == AIM_CAPS_VOICE) { | |
537 | faimdprintf(sess, 0, "voice request cancelled\n"); | |
538 | } else { | |
539 | faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type); | |
540 | } | |
541 | ||
542 | if (list2) | |
543 | aim_freetlvchain(&list2); | |
544 | aim_freetlvchain(&tlvlist); | |
545 | return 1; | |
546 | } | |
547 | ||
548 | /* | |
549 | * The rest of the handling depends on what type it is. | |
550 | */ | |
551 | if (reqclass & AIM_CAPS_BUDDYICON) { | |
552 | ||
553 | /* | |
554 | * Call client. | |
555 | */ | |
556 | #if 0 | |
557 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
558 | if (userfunc || (i = 0)) | |
559 | i = userfunc(sess, | |
560 | command, | |
561 | channel, | |
562 | reqclass, | |
563 | &userinfo, | |
564 | ip, | |
565 | cookie); | |
566 | #endif | |
567 | ||
568 | } else if (reqclass & AIM_CAPS_VOICE) { | |
569 | struct aim_msgcookie_t *cachedcook; | |
570 | ||
571 | faimdprintf(sess, 0, "rend: voice!\n"); | |
572 | ||
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 | ||
580 | if (aim_cachecookie(sess, cachedcook) == -1) | |
581 | faimdprintf(sess, 0, "ERROR caching message cookie\n"); | |
582 | ||
583 | /* XXX: implement all this */ | |
584 | ||
585 | /* | |
586 | * Call client. | |
587 | */ | |
588 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
589 | if (userfunc || (i = 0)) { | |
590 | i = userfunc(sess, command, channel, reqclass, &userinfo); | |
591 | } | |
592 | } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) { | |
593 | char ip[30]; | |
594 | struct aim_directim_priv *priv; | |
595 | ||
596 | memset(ip, 0, 30); | |
597 | ||
598 | if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) { | |
599 | struct aim_tlv_t *iptlv, *porttlv; | |
600 | ||
601 | iptlv = aim_gettlv(list2, 0x0003, 1); | |
602 | porttlv = aim_gettlv(list2, 0x0005, 1); | |
603 | ||
604 | snprintf(ip, 30, "%d.%d.%d.%d:%d", | |
605 | aimutil_get8(iptlv->value+0), | |
606 | aimutil_get8(iptlv->value+1), | |
607 | aimutil_get8(iptlv->value+2), | |
608 | aimutil_get8(iptlv->value+3), | |
609 | 4443 /*aimutil_get16(porttlv->value)*/); | |
610 | } | |
611 | ||
612 | faimdprintf(sess, 0, "rend: directIM request from %s (%s)\n", | |
613 | userinfo.sn, ip); | |
614 | ||
615 | /* XXX: there are a couple of different request packets for | |
616 | * different things */ | |
617 | ||
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)); | |
622 | ||
623 | /* | |
624 | * Call client. | |
625 | */ | |
626 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
627 | if (userfunc || (i = 0)) | |
628 | i = userfunc(sess, | |
629 | command, | |
630 | channel, | |
631 | reqclass, | |
632 | &userinfo, priv); | |
633 | ||
634 | } else if (reqclass & AIM_CAPS_CHAT) { | |
635 | struct aim_tlv_t *miscinfo; | |
636 | struct aim_chat_roominfo roominfo; | |
637 | char *msg=NULL,*encoding=NULL,*lang=NULL; | |
638 | ||
639 | miscinfo = aim_gettlv(list2, 0x2711, 1); | |
640 | aim_chat_readroominfo(miscinfo->value, &roominfo); | |
641 | ||
642 | if (aim_gettlv(list2, 0x000c, 1)) | |
643 | msg = aim_gettlv_str(list2, 0x000c, 1); | |
644 | ||
645 | if (aim_gettlv(list2, 0x000d, 1)) | |
646 | encoding = aim_gettlv_str(list2, 0x000d, 1); | |
647 | ||
648 | if (aim_gettlv(list2, 0x000e, 1)) | |
649 | lang = aim_gettlv_str(list2, 0x000e, 1); | |
650 | ||
651 | /* | |
652 | * Call client. | |
653 | */ | |
654 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
655 | if (userfunc || (i = 0)) | |
656 | i = userfunc(sess, | |
657 | command, | |
658 | channel, | |
659 | reqclass, | |
660 | &userinfo, | |
661 | &roominfo, | |
662 | msg, | |
663 | encoding?encoding+1:NULL, | |
664 | lang?lang+1:NULL); | |
665 | free(roominfo.name); | |
666 | free(msg); | |
667 | free(encoding); | |
668 | free(lang); | |
669 | } else if (reqclass & AIM_CAPS_GETFILE) { | |
670 | char ip[30]; | |
671 | struct aim_msgcookie_t *cachedcook; | |
672 | struct aim_tlv_t *miscinfo; | |
673 | ||
674 | if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) | |
675 | return 0; | |
676 | ||
677 | memset(ip, 0, 30); | |
678 | ||
679 | if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) { | |
680 | aim_cookie_free(sess, cachedcook); | |
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))) { | |
688 | aim_cookie_free(sess, cachedcook); | |
689 | return 0; | |
690 | } | |
691 | ||
692 | snprintf(ip, 30, "%d.%d.%d.%d:%d", | |
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 | ||
700 | faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo.sn, ip); | |
701 | ||
702 | /* | |
703 | * Call client. | |
704 | */ | |
705 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
706 | if (userfunc || (i = 0)) | |
707 | i = userfunc(sess, | |
708 | command, | |
709 | channel, | |
710 | reqclass, | |
711 | &userinfo, | |
712 | ip, | |
713 | cookie); | |
714 | ||
715 | } else if (reqclass & AIM_CAPS_SENDFILE) { | |
716 | #if 0 | |
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; | |
722 | ||
723 | memset(ip, 0, sizeof(ip)); | |
724 | ||
725 | if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) | |
726 | return 0; | |
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 | ||
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); | |
751 | ||
752 | memcpy(cachedcook->cookie, cookie, 8); | |
753 | ||
754 | ft = malloc(sizeof(struct aim_filetransfer_priv)); | |
755 | strncpy(ft->sn, userinfo.sn, sizeof(ft->sn)); | |
756 | strncpy(ft->ip, ip, sizeof(ft->ip)); | |
757 | strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name)); | |
758 | cachedcook->type = AIM_COOKIETYPE_OFTSEND; | |
759 | cachedcook->data = ft; | |
760 | ||
761 | if (aim_cachecookie(sess, cachedcook) == -1) | |
762 | faimdprintf(sess, 0, "ERROR caching message cookie\n"); | |
763 | ||
764 | ||
765 | aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE); | |
766 | ||
767 | if (desc) | |
768 | free(desc); | |
769 | #endif | |
770 | /* | |
771 | * Call client. | |
772 | */ | |
773 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007); | |
774 | if (userfunc || (i = 0)) | |
775 | i = userfunc(sess, | |
776 | command, | |
777 | channel, | |
778 | reqclass, | |
779 | &userinfo); | |
780 | } else | |
781 | faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", reqclass); | |
782 | ||
783 | aim_freetlvchain(&list2); | |
784 | } | |
785 | ||
786 | /* | |
787 | * Free up the TLV chain. | |
788 | */ | |
789 | aim_freetlvchain(&tlvlist); | |
790 | ||
791 | ||
792 | return i; | |
793 | } | |
794 | ||
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 | */ | |
802 | faim_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) | |
807 | { | |
808 | struct command_tx_struct *newpacket; | |
809 | int curbyte, i; | |
810 | ||
811 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sender)+6))) | |
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 | ||
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 | */ | |
837 | faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess, | |
838 | struct aim_conn_t *conn) | |
839 | { | |
840 | struct command_tx_struct *newpacket; | |
841 | int curbyte; | |
842 | ||
843 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+16))) | |
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); | |
862 | ||
863 | return (sess->snac_nextid++); | |
864 | } | |
865 | ||
866 | faim_internal int aim_parse_msgerror_middle(struct aim_session_t *sess, | |
867 | struct command_rx_struct *command) | |
868 | { | |
869 | u_long snacid = 0x000000000; | |
870 | struct aim_snac_t *snac = NULL; | |
871 | int ret = 0; | |
872 | rxcallback_t userfunc = NULL; | |
873 | char *dest; | |
874 | unsigned short reason = 0; | |
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 | ||
889 | if (!snac) { | |
890 | faimdprintf(sess, 0, "msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid); | |
891 | dest = NULL; | |
892 | } else | |
893 | dest = snac->data; | |
894 | ||
895 | reason = aimutil_get16(command->data+10); | |
896 | ||
897 | /* | |
898 | * Call client. | |
899 | */ | |
900 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0001); | |
901 | if (userfunc) | |
902 | ret = userfunc(sess, command, dest, reason); | |
903 | else | |
904 | ret = 0; | |
905 | ||
906 | if (snac) { | |
907 | free(snac->data); | |
908 | free(snac); | |
909 | } | |
910 | ||
911 | return ret; | |
912 | } | |
913 | ||
914 | ||
915 | faim_internal int aim_parse_missedcall(struct aim_session_t *sess, | |
916 | struct command_rx_struct *command) | |
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 | */ | |
940 | i += aim_extractuserinfo(sess, command->data+i, &userinfo); | |
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 | */ | |
951 | userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x000a); | |
952 | if (userfunc) | |
953 | ret = userfunc(sess, command, channel, &userinfo, nummissed, reason); | |
954 | else | |
955 | ret = 0; | |
956 | ||
957 | return ret; | |
958 | } |