]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | /* |
2 | * aim_im.c | |
3 | * | |
4 | * The routines for sending/receiving Instant Messages. | |
5 | * | |
6ae3c48d | 6 | * Note the term ICBM (Inter-Client Basic Message) which blankets |
7 | * all types of genericly routed through-server messages. Within | |
8 | * the ICBM types (family 4), a channel is defined. Each channel | |
9 | * represents a different type of message. Channel 1 is used for | |
10 | * what would commonly be called an "instant message". Channel 2 | |
11 | * is used for negotiating "rendezvous". These transactions end in | |
12 | * something more complex happening, such as a chat invitation, or | |
13 | * a file transfer. | |
14 | * | |
15 | * In addition to the channel, every ICBM contains a cookie. For | |
16 | * standard IMs, these are only used for error messages. However, | |
17 | * the more complex rendezvous messages make suitably more complex | |
18 | * use of this field. | |
19 | * | |
9de3ca7e | 20 | */ |
21 | ||
37ee990e | 22 | #define FAIM_INTERNAL |
dd60ff8b | 23 | #include <aim.h> |
9de3ca7e | 24 | |
9d83220c | 25 | /* |
26 | * Takes a msghdr (and a length) and returns a client type | |
27 | * code. Note that this is *only a guess* and has a low likelihood | |
28 | * of actually being accurate. | |
29 | * | |
30 | * Its based on experimental data, with the help of Eric Warmenhoven | |
31 | * who seems to have collected a wide variety of different AIM clients. | |
32 | * | |
33 | * | |
34 | * Heres the current collection: | |
35 | * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414 | |
36 | * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464, | |
37 | * 4.3.2229, 4.4.2286 | |
38 | * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here) | |
39 | * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any | |
40 | * TOC client | |
d410cf58 | 41 | * |
42 | * Note that in this function, only the feature bytes are tested, since | |
43 | * the rest will always be the same. | |
44 | * | |
9d83220c | 45 | */ |
d410cf58 | 46 | faim_export fu16_t aim_fingerprintclient(fu8_t *msghdr, int len) |
9d83220c | 47 | { |
6ae3c48d | 48 | static const struct { |
d410cf58 | 49 | fu16_t clientid; |
6ae3c48d | 50 | int len; |
d410cf58 | 51 | fu8_t data[10]; |
6ae3c48d | 52 | } fingerprints[] = { |
53 | /* AOL Mobile Communicator, WinAIM 1.0.414 */ | |
54 | { AIM_CLIENTTYPE_MC, | |
d410cf58 | 55 | 3, {0x01, 0x01, 0x01}}, |
6ae3c48d | 56 | |
57 | /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */ | |
58 | { AIM_CLIENTTYPE_WINAIM, | |
d410cf58 | 59 | 3, {0x01, 0x01, 0x02}}, |
6ae3c48d | 60 | |
61 | /* WinAIM 4.1.2010, libfaim */ | |
62 | { AIM_CLIENTTYPE_WINAIM41, | |
d410cf58 | 63 | 4, {0x01, 0x01, 0x01, 0x02}}, |
6ae3c48d | 64 | |
65 | /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */ | |
66 | { AIM_CLIENTTYPE_AOL_TOC, | |
d410cf58 | 67 | 1, {0x01}}, |
6ae3c48d | 68 | |
69 | { 0, 0} | |
70 | }; | |
71 | int i; | |
72 | ||
73 | if (!msghdr || (len <= 0)) | |
74 | return AIM_CLIENTTYPE_UNKNOWN; | |
75 | ||
76 | for (i = 0; fingerprints[i].len; i++) { | |
77 | if (fingerprints[i].len != len) | |
78 | continue; | |
79 | if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0) | |
80 | return fingerprints[i].clientid; | |
81 | } | |
82 | ||
83 | return AIM_CLIENTTYPE_UNKNOWN; | |
9d83220c | 84 | } |
85 | ||
50038c74 | 86 | /* This should be endian-safe now... but who knows... */ |
e1b8c575 | 87 | faim_export fu32_t aim_iconsum(const fu8_t *buf, int buflen) |
50038c74 | 88 | { |
d410cf58 | 89 | fu32_t sum; |
6ae3c48d | 90 | int i; |
50038c74 | 91 | |
6ae3c48d | 92 | for (i = 0, sum = 0; i < buflen; i += 2) |
93 | sum += (buf[i+1] << 8) + buf[i]; | |
50038c74 | 94 | |
6ae3c48d | 95 | sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff); |
50038c74 | 96 | |
e1b8c575 | 97 | return sum; |
50038c74 | 98 | } |
99 | ||
9de3ca7e | 100 | /* |
101 | * Send an ICBM (instant message). | |
102 | * | |
103 | * | |
104 | * Possible flags: | |
105 | * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse | |
106 | * AIM_IMFLAGS_ACK -- Requests that the server send an ack | |
107 | * when the message is received (of type 0x0004/0x000c) | |
7b91722d | 108 | * AIM_IMFLAGS_UNICODE--Instead of ASCII7, the passed message is |
109 | * made up of UNICODE duples. If you set | |
110 | * this, you'd better be damn sure you know | |
111 | * what you're doing. | |
112 | * AIM_IMFLAGS_ISO_8859_1 -- The message contains the ASCII8 subset | |
113 | * known as ISO-8859-1. | |
114 | * | |
115 | * Generally, you should use the lowest encoding possible to send | |
116 | * your message. If you only use basic punctuation and the generic | |
117 | * Latin alphabet, use ASCII7 (no flags). If you happen to use non-ASCII7 | |
118 | * characters, but they are all clearly defined in ISO-8859-1, then | |
119 | * use that. Keep in mind that not all characters in the PC ASCII8 | |
120 | * character set are defined in the ISO standard. For those cases (most | |
121 | * notably when the (r) symbol is used), you must use the full UNICODE | |
122 | * encoding for your message. In UNICODE mode, _all_ characters must | |
123 | * occupy 16bits, including ones that are not special. (Remember that | |
124 | * the first 128 UNICODE symbols are equivelent to ASCII7, however they | |
125 | * must be prefixed with a zero high order byte.) | |
126 | * | |
127 | * I strongly discourage the use of UNICODE mode, mainly because none | |
128 | * of the clients I use can parse those messages (and besides that, | |
129 | * wchars are difficult and non-portable to handle in most UNIX environments). | |
130 | * If you really need to include special characters, use the HTML UNICODE | |
131 | * entities. These are of the form ߪ where 2026 is the hex | |
132 | * representation of the UNICODE index (in this case, UNICODE | |
133 | * "Horizontal Ellipsis", or 133 in in ASCII8). | |
9de3ca7e | 134 | * |
d410cf58 | 135 | * Implementation note: Since this is one of the most-used functions |
136 | * in all of libfaim, it is written with performance in mind. As such, | |
137 | * it is not as clear as it could be in respect to how this message is | |
138 | * supposed to be layed out. Most obviously, tlvlists should be used | |
139 | * instead of writing out the bytes manually. | |
140 | * | |
603fdcaa | 141 | * XXX more precise verification that we never send SNACs larger than 8192 |
142 | * XXX check SNAC size for multipart | |
d410cf58 | 143 | * |
9de3ca7e | 144 | */ |
d410cf58 | 145 | faim_export int aim_send_im_ext(aim_session_t *sess, aim_conn_t *conn, struct aim_sendimext_args *args) |
a2244dd9 | 146 | { |
84e0ca17 | 147 | static const fu8_t deffeatures[] = { |
148 | 0x01, 0x01, 0x01, 0x02, 0x42, | |
149 | }; | |
150 | int i, msgtlvlen; | |
d410cf58 | 151 | aim_frame_t *fr; |
152 | aim_snacid_t snacid; | |
2d5fd943 | 153 | |
154 | if (!sess || !conn || !args) | |
d410cf58 | 155 | return -EINVAL; |
2d5fd943 | 156 | |
603fdcaa | 157 | if (args->flags & AIM_IMFLAGS_MULTIPART) { |
158 | if (args->mpmsg->numparts <= 0) | |
159 | return -EINVAL; | |
160 | } else { | |
161 | if (!args->msg || (args->msglen <= 0)) | |
162 | return -EINVAL; | |
163 | ||
164 | if (args->msglen >= MAXMSGLEN) | |
165 | return -E2BIG; | |
166 | } | |
2d5fd943 | 167 | |
603fdcaa | 168 | /* Painfully calculate the size of the message TLV */ |
169 | msgtlvlen = 1 + 1; /* 0501 */ | |
2d5fd943 | 170 | |
84e0ca17 | 171 | if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) |
603fdcaa | 172 | msgtlvlen += 2 + args->featureslen; |
84e0ca17 | 173 | else |
603fdcaa | 174 | msgtlvlen += 2 + sizeof(deffeatures); |
175 | ||
176 | if (args->flags & AIM_IMFLAGS_MULTIPART) { | |
177 | aim_mpmsg_section_t *sec; | |
178 | ||
179 | for (sec = args->mpmsg->parts; sec; sec = sec->next) { | |
180 | msgtlvlen += 2 /* 0101 */ + 2 /* block len */; | |
181 | msgtlvlen += 4 /* charset */ + sec->datalen; | |
182 | } | |
183 | ||
184 | } else { | |
185 | msgtlvlen += 2 /* 0101 */ + 2 /* block len */; | |
186 | msgtlvlen += 4 /* charset */ + args->msglen; | |
187 | } | |
188 | ||
189 | ||
190 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, msgtlvlen+128))) | |
2d5fd943 | 191 | return -ENOMEM; |
192 | ||
d410cf58 | 193 | /* XXX should be optional */ |
194 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1); | |
195 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); | |
2d5fd943 | 196 | |
197 | /* | |
198 | * Generate a random message cookie | |
199 | * | |
200 | * We could cache these like we do SNAC IDs. (In fact, it | |
201 | * might be a good idea.) In the message error functions, | |
202 | * the 8byte message cookie is returned as well as the | |
203 | * SNAC ID. | |
204 | * | |
205 | */ | |
d410cf58 | 206 | for (i = 0; i < 8; i++) |
207 | aimbs_put8(&fr->data, (fu8_t) rand()); | |
2d5fd943 | 208 | |
209 | /* | |
210 | * Channel ID | |
211 | */ | |
d410cf58 | 212 | aimbs_put16(&fr->data, 0x0001); |
2d5fd943 | 213 | |
214 | /* | |
215 | * Destination SN (prepended with byte length) | |
216 | */ | |
d410cf58 | 217 | aimbs_put8(&fr->data, strlen(args->destsn)); |
218 | aimbs_putraw(&fr->data, args->destsn, strlen(args->destsn)); | |
2d5fd943 | 219 | |
220 | /* | |
221 | * metaTLV start. | |
222 | */ | |
d410cf58 | 223 | aimbs_put16(&fr->data, 0x0002); |
84e0ca17 | 224 | aimbs_put16(&fr->data, msgtlvlen); |
2d5fd943 | 225 | |
226 | /* | |
84e0ca17 | 227 | * Features |
2d5fd943 | 228 | * |
229 | */ | |
d410cf58 | 230 | aimbs_put8(&fr->data, 0x05); |
231 | aimbs_put8(&fr->data, 0x01); | |
2d5fd943 | 232 | |
84e0ca17 | 233 | if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) { |
234 | aimbs_put16(&fr->data, args->featureslen); | |
235 | aimbs_putraw(&fr->data, args->features, args->featureslen); | |
236 | } else { | |
237 | aimbs_put16(&fr->data, sizeof(deffeatures)); | |
238 | aimbs_putraw(&fr->data, deffeatures, sizeof(deffeatures)); | |
239 | } | |
2d5fd943 | 240 | |
603fdcaa | 241 | if (args->flags & AIM_IMFLAGS_MULTIPART) { |
242 | aim_mpmsg_section_t *sec; | |
2d5fd943 | 243 | |
603fdcaa | 244 | for (sec = args->mpmsg->parts; sec; sec = sec->next) { |
245 | aimbs_put16(&fr->data, 0x0101); | |
246 | aimbs_put16(&fr->data, sec->datalen + 4); | |
247 | aimbs_put16(&fr->data, sec->charset); | |
248 | aimbs_put16(&fr->data, sec->charsubset); | |
249 | aimbs_putraw(&fr->data, sec->data, sec->datalen); | |
250 | } | |
2d5fd943 | 251 | |
603fdcaa | 252 | } else { |
2d5fd943 | 253 | |
603fdcaa | 254 | aimbs_put16(&fr->data, 0x0101); |
2d5fd943 | 255 | |
603fdcaa | 256 | /* |
257 | * Message block length. | |
258 | */ | |
259 | aimbs_put16(&fr->data, args->msglen + 0x04); | |
260 | ||
261 | /* | |
262 | * Character set. | |
263 | */ | |
264 | if (args->flags & AIM_IMFLAGS_CUSTOMCHARSET) { | |
265 | ||
266 | aimbs_put16(&fr->data, args->charset); | |
267 | aimbs_put16(&fr->data, args->charsubset); | |
268 | ||
269 | } else { | |
270 | if (args->flags & AIM_IMFLAGS_UNICODE) | |
271 | aimbs_put16(&fr->data, 0x0002); | |
272 | else if (args->flags & AIM_IMFLAGS_ISO_8859_1) | |
273 | aimbs_put16(&fr->data, 0x0003); | |
274 | else | |
275 | aimbs_put16(&fr->data, 0x0000); | |
276 | ||
277 | aimbs_put16(&fr->data, 0x0000); | |
278 | } | |
279 | ||
280 | /* | |
281 | * Message. Not terminated. | |
282 | */ | |
283 | aimbs_putraw(&fr->data, args->msg, args->msglen); | |
284 | } | |
2d5fd943 | 285 | |
286 | /* | |
287 | * Set the Request Acknowledge flag. | |
288 | */ | |
289 | if (args->flags & AIM_IMFLAGS_ACK) { | |
d410cf58 | 290 | aimbs_put16(&fr->data, 0x0003); |
291 | aimbs_put16(&fr->data, 0x0000); | |
2d5fd943 | 292 | } |
d410cf58 | 293 | |
2d5fd943 | 294 | /* |
295 | * Set the Autoresponse flag. | |
296 | */ | |
297 | if (args->flags & AIM_IMFLAGS_AWAY) { | |
d410cf58 | 298 | aimbs_put16(&fr->data, 0x0004); |
299 | aimbs_put16(&fr->data, 0x0000); | |
2d5fd943 | 300 | } |
301 | ||
302 | /* | |
303 | * Set the Buddy Icon Requested flag. | |
304 | */ | |
305 | if (args->flags & AIM_IMFLAGS_BUDDYREQ) { | |
d410cf58 | 306 | aimbs_put16(&fr->data, 0x0009); |
307 | aimbs_put16(&fr->data, 0x0000); | |
2d5fd943 | 308 | } |
309 | ||
310 | /* | |
d410cf58 | 311 | * Set the I HAVE A REALLY PURTY ICON flag. |
2d5fd943 | 312 | */ |
313 | if (args->flags & AIM_IMFLAGS_HASICON) { | |
e1b8c575 | 314 | aimbs_put16(&fr->data, 0x0008); |
d410cf58 | 315 | aimbs_put16(&fr->data, 0x000c); |
316 | aimbs_put32(&fr->data, args->iconlen); | |
e1b8c575 | 317 | aimbs_put32(&fr->data, args->iconsum); |
d410cf58 | 318 | aimbs_put32(&fr->data, args->iconstamp); |
2d5fd943 | 319 | } |
320 | ||
d410cf58 | 321 | aim_tx_enqueue(sess, fr); |
49c8a2fa | 322 | |
7b91722d | 323 | #if 1 /* XXX do this with autoconf or something... */ |
2d5fd943 | 324 | aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ |
7b91722d | 325 | #endif |
9de3ca7e | 326 | |
2d5fd943 | 327 | return 0; |
9de3ca7e | 328 | } |
329 | ||
7b91722d | 330 | /* |
331 | * Simple wrapper for aim_send_im_ext() | |
332 | * | |
333 | * You cannot use aim_send_im if you need the HASICON flag. You must | |
334 | * use aim_send_im_ext directly for that. | |
335 | * | |
336 | * aim_send_im also cannot be used if you require UNICODE messages, because | |
337 | * that requires an explicit message length. Use aim_send_im_ext(). | |
338 | * | |
339 | */ | |
d410cf58 | 340 | faim_export int aim_send_im(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu16_t flags, const char *msg) |
7b91722d | 341 | { |
2d5fd943 | 342 | struct aim_sendimext_args args; |
7b91722d | 343 | |
2d5fd943 | 344 | args.destsn = destsn; |
345 | args.flags = flags; | |
346 | args.msg = msg; | |
347 | args.msglen = strlen(msg); | |
7b91722d | 348 | |
84e0ca17 | 349 | /* Make these don't get set by accident -- they need aim_send_im_ext */ |
603fdcaa | 350 | args.flags &= ~(AIM_IMFLAGS_CUSTOMFEATURES | AIM_IMFLAGS_HASICON | AIM_IMFLAGS_MULTIPART); |
84e0ca17 | 351 | |
2d5fd943 | 352 | return aim_send_im_ext(sess, conn, &args); |
7b91722d | 353 | } |
354 | ||
d410cf58 | 355 | /* |
603fdcaa | 356 | * This is also performance sensitive. (If you can believe it...) |
d410cf58 | 357 | * |
358 | */ | |
e1b8c575 | 359 | faim_export int aim_send_icon(aim_session_t *sess, aim_conn_t *conn, const char *sn, const fu8_t *icon, int iconlen, time_t stamp, fu32_t iconsum) |
7b91722d | 360 | { |
d410cf58 | 361 | int i; |
362 | fu8_t ck[8]; | |
363 | aim_frame_t *fr; | |
364 | aim_snacid_t snacid; | |
6ae3c48d | 365 | |
d410cf58 | 366 | if (!sess || !conn || !sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN)) |
367 | return -EINVAL; | |
6ae3c48d | 368 | |
369 | if (conn->type != AIM_CONN_TYPE_BOS) | |
370 | return -EINVAL; | |
371 | ||
d410cf58 | 372 | for (i = 0; i < 8; i++) |
373 | aimutil_put8(ck+i, (fu8_t) rand()); | |
6ae3c48d | 374 | |
d410cf58 | 375 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2))) |
6ae3c48d | 376 | return -ENOMEM; |
377 | ||
d410cf58 | 378 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
379 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); | |
6ae3c48d | 380 | |
381 | /* | |
382 | * Cookie | |
383 | */ | |
d410cf58 | 384 | aimbs_putraw(&fr->data, ck, 8); |
6ae3c48d | 385 | |
386 | /* | |
387 | * Channel (2) | |
388 | */ | |
d410cf58 | 389 | aimbs_put16(&fr->data, 0x0002); |
6ae3c48d | 390 | |
391 | /* | |
392 | * Dest sn | |
393 | */ | |
d410cf58 | 394 | aimbs_put8(&fr->data, strlen(sn)); |
395 | aimbs_putraw(&fr->data, sn, strlen(sn)); | |
6ae3c48d | 396 | |
397 | /* | |
398 | * TLV t(0005) | |
d410cf58 | 399 | * |
400 | * Encompasses everything below. | |
6ae3c48d | 401 | */ |
d410cf58 | 402 | aimbs_put16(&fr->data, 0x0005); |
403 | aimbs_put16(&fr->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT)); | |
6ae3c48d | 404 | |
d410cf58 | 405 | aimbs_put16(&fr->data, 0x0000); |
406 | aimbs_putraw(&fr->data, ck, 8); | |
407 | aim_putcap(&fr->data, AIM_CAPS_BUDDYICON); | |
6ae3c48d | 408 | |
409 | /* TLV t(000a) */ | |
d410cf58 | 410 | aimbs_put16(&fr->data, 0x000a); |
411 | aimbs_put16(&fr->data, 0x0002); | |
412 | aimbs_put16(&fr->data, 0x0001); | |
6ae3c48d | 413 | |
414 | /* TLV t(000f) */ | |
d410cf58 | 415 | aimbs_put16(&fr->data, 0x000f); |
416 | aimbs_put16(&fr->data, 0x0000); | |
6ae3c48d | 417 | |
418 | /* TLV t(2711) */ | |
d410cf58 | 419 | aimbs_put16(&fr->data, 0x2711); |
420 | aimbs_put16(&fr->data, 4+4+4+iconlen+strlen(AIM_ICONIDENT)); | |
e1b8c575 | 421 | aimbs_put32(&fr->data, iconsum); |
d410cf58 | 422 | aimbs_put32(&fr->data, iconlen); |
423 | aimbs_put32(&fr->data, stamp); | |
424 | aimbs_putraw(&fr->data, icon, iconlen); | |
425 | aimbs_putraw(&fr->data, AIM_ICONIDENT, strlen(AIM_ICONIDENT)); | |
6ae3c48d | 426 | |
427 | /* TLV t(0003) */ | |
d410cf58 | 428 | aimbs_put16(&fr->data, 0x0003); |
429 | aimbs_put16(&fr->data, 0x0000); | |
6ae3c48d | 430 | |
d410cf58 | 431 | aim_tx_enqueue(sess, fr); |
6ae3c48d | 432 | |
433 | return 0; | |
7b91722d | 434 | } |
435 | ||
d410cf58 | 436 | static int outgoingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
e5012450 | 437 | { |
d410cf58 | 438 | int i, ret = 0; |
6ae3c48d | 439 | aim_rxcallback_t userfunc; |
d410cf58 | 440 | fu8_t cookie[8]; |
441 | fu16_t channel; | |
442 | aim_tlvlist_t *tlvlist; | |
443 | char *sn; | |
444 | int snlen; | |
445 | fu16_t icbmflags = 0; | |
446 | fu8_t flag1 = 0, flag2 = 0; | |
447 | fu8_t *msg = NULL; | |
448 | aim_tlv_t *msgblock; | |
6ae3c48d | 449 | |
450 | /* ICBM Cookie. */ | |
451 | for (i = 0; i < 8; i++) | |
d410cf58 | 452 | cookie[i] = aimbs_get8(bs); |
6ae3c48d | 453 | |
454 | /* Channel ID */ | |
d410cf58 | 455 | channel = aimbs_get16(bs); |
6ae3c48d | 456 | |
457 | if (channel != 0x01) { | |
458 | faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel); | |
d410cf58 | 459 | return 0; |
6ae3c48d | 460 | } |
461 | ||
d410cf58 | 462 | snlen = aimbs_get8(bs); |
463 | sn = aimbs_getstr(bs, snlen); | |
6ae3c48d | 464 | |
d410cf58 | 465 | tlvlist = aim_readtlvchain(bs); |
6ae3c48d | 466 | |
467 | if (aim_gettlv(tlvlist, 0x0003, 1)) | |
468 | icbmflags |= AIM_IMFLAGS_ACK; | |
469 | if (aim_gettlv(tlvlist, 0x0004, 1)) | |
470 | icbmflags |= AIM_IMFLAGS_AWAY; | |
e5012450 | 471 | |
d410cf58 | 472 | if ((msgblock = aim_gettlv(tlvlist, 0x0002, 1))) { |
473 | aim_bstream_t mbs; | |
474 | int featurelen, msglen; | |
475 | ||
476 | aim_bstream_init(&mbs, msgblock->value, msgblock->length); | |
6ae3c48d | 477 | |
d410cf58 | 478 | aimbs_get8(&mbs); |
479 | aimbs_get8(&mbs); | |
480 | for (featurelen = aimbs_get16(&mbs); featurelen; featurelen--) | |
481 | aimbs_get8(&mbs); | |
482 | aimbs_get8(&mbs); | |
483 | aimbs_get8(&mbs); | |
6ae3c48d | 484 | |
d410cf58 | 485 | msglen = aimbs_get16(&mbs) - 4; /* final block length */ |
6ae3c48d | 486 | |
d410cf58 | 487 | flag1 = aimbs_get16(&mbs); |
488 | flag2 = aimbs_get16(&mbs); | |
6ae3c48d | 489 | |
d410cf58 | 490 | msg = aimbs_getstr(&mbs, msglen); |
6ae3c48d | 491 | } |
492 | ||
493 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
494 | ret = userfunc(sess, rx, channel, sn, msg, icbmflags, flag1, flag2); | |
495 | ||
d410cf58 | 496 | free(sn); |
6ae3c48d | 497 | aim_freetlvchain(&tlvlist); |
498 | ||
499 | return ret; | |
00ef5271 | 500 | } |
501 | ||
603fdcaa | 502 | /* |
503 | * Ahh, the joys of nearly ridiculous over-engineering. | |
504 | * | |
505 | * Not only do AIM ICBM's support multiple channels. Not only do they | |
506 | * support multiple character sets. But they support multiple character | |
507 | * sets / encodings within the same ICBM. | |
508 | * | |
509 | * These multipart messages allow for complex space savings techniques, which | |
510 | * seem utterly unnecessary by today's standards. In fact, there is only | |
511 | * one client still in popular use that still uses this method: AOL for the | |
512 | * Macintosh, Version 5.0. Obscure, yes, I know. | |
513 | * | |
514 | * In modern (non-"legacy") clients, if the user tries to send a character | |
515 | * that is not ISO-8859-1 or ASCII, the client will send the entire message | |
516 | * as UNICODE, meaning that every character in the message will occupy the | |
517 | * full 16 bit UNICODE field, even if the high order byte would be zero. | |
518 | * Multipart messages prevent this wasted space by allowing the client to | |
519 | * only send the characters in UNICODE that need to be sent that way, and | |
520 | * the rest of the message can be sent in whatever the native character | |
521 | * set is (probably ASCII). | |
522 | * | |
523 | * An important note is that sections will be displayed in the order that | |
524 | * they appear in the ICBM. There is no facility for merging or rearranging | |
525 | * sections at run time. So if you have, say, ASCII then UNICODE then ASCII, | |
526 | * you must supply two ASCII sections with a UNICODE in the middle, and incur | |
527 | * the associated overhead. | |
528 | * | |
529 | * Normally I would have laughed and given a firm 'no' to supporting this | |
530 | * seldom-used feature, but something is attracting me to it. In the future, | |
531 | * it may be possible to abuse this to send mixed-media messages to other | |
532 | * open source clients (like encryption or something) -- see faimtest for | |
533 | * examples of how to do this. | |
534 | * | |
535 | * I would definitly recommend avoiding this feature unless you really | |
536 | * know what you are doing, and/or you have something neat to do with it. | |
537 | * | |
538 | */ | |
539 | faim_export int aim_mpmsg_init(aim_session_t *sess, aim_mpmsg_t *mpm) | |
540 | { | |
541 | ||
542 | memset(mpm, 0, sizeof(aim_mpmsg_t)); | |
543 | ||
544 | return 0; | |
545 | } | |
546 | ||
547 | static int mpmsg_addsection(aim_session_t *sess, aim_mpmsg_t *mpm, fu16_t charset, fu16_t charsubset, fu8_t *data, fu16_t datalen) | |
548 | { | |
549 | aim_mpmsg_section_t *sec; | |
550 | ||
551 | if (!(sec = malloc(sizeof(aim_mpmsg_section_t)))) | |
552 | return -1; | |
553 | ||
554 | sec->charset = charset; | |
555 | sec->charsubset = charsubset; | |
556 | sec->data = data; | |
557 | sec->datalen = datalen; | |
558 | sec->next = NULL; | |
559 | ||
560 | if (!mpm->parts) | |
561 | mpm->parts = sec; | |
562 | else { | |
563 | aim_mpmsg_section_t *cur; | |
564 | ||
565 | for (cur = mpm->parts; cur->next; cur = cur->next) | |
566 | ; | |
567 | cur->next = sec; | |
568 | } | |
569 | ||
570 | mpm->numparts++; | |
571 | ||
572 | return 0; | |
573 | } | |
574 | ||
575 | faim_export int aim_mpmsg_addraw(aim_session_t *sess, aim_mpmsg_t *mpm, fu16_t charset, fu16_t charsubset, const fu8_t *data, fu16_t datalen) | |
576 | { | |
577 | fu8_t *dup; | |
578 | ||
579 | if (!(dup = malloc(datalen))) | |
580 | return -1; | |
581 | memcpy(dup, data, datalen); | |
582 | ||
583 | if (mpmsg_addsection(sess, mpm, charset, charsubset, dup, datalen) == -1) { | |
584 | free(dup); | |
585 | return -1; | |
586 | } | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
591 | /* XXX should provide a way of saying ISO-8859-1 specifically */ | |
592 | faim_export int aim_mpmsg_addascii(aim_session_t *sess, aim_mpmsg_t *mpm, const char *ascii) | |
593 | { | |
594 | fu8_t *dup; | |
595 | ||
596 | if (!(dup = strdup(ascii))) | |
597 | return -1; | |
598 | ||
599 | if (mpmsg_addsection(sess, mpm, 0x0000, 0x0000, dup, strlen(ascii)) == -1) { | |
600 | free(dup); | |
601 | return -1; | |
602 | } | |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
607 | faim_export int aim_mpmsg_addunicode(aim_session_t *sess, aim_mpmsg_t *mpm, const fu16_t *unicode, fu16_t unicodelen) | |
608 | { | |
609 | fu8_t *buf; | |
610 | aim_bstream_t bs; | |
611 | int i; | |
612 | ||
613 | if (!(buf = malloc(unicodelen * 2))) | |
614 | return -1; | |
615 | ||
616 | aim_bstream_init(&bs, buf, unicodelen * 2); | |
617 | ||
618 | /* We assume unicode is in /host/ byte order -- convert to network */ | |
619 | for (i = 0; i < unicodelen; i++) | |
620 | aimbs_put16(&bs, unicode[i]); | |
621 | ||
622 | if (mpmsg_addsection(sess, mpm, 0x0002, 0x0000, buf, aim_bstream_curpos(&bs)) == -1) { | |
623 | free(buf); | |
624 | return -1; | |
625 | } | |
626 | ||
627 | return 0; | |
628 | } | |
629 | ||
630 | faim_export void aim_mpmsg_free(aim_session_t *sess, aim_mpmsg_t *mpm) | |
631 | { | |
632 | aim_mpmsg_section_t *cur; | |
633 | ||
634 | for (cur = mpm->parts; cur; ) { | |
635 | aim_mpmsg_section_t *tmp; | |
636 | ||
637 | tmp = cur->next; | |
638 | free(cur->data); | |
639 | free(cur); | |
640 | cur = tmp; | |
641 | } | |
642 | ||
643 | mpm->numparts = 0; | |
644 | mpm->parts = NULL; | |
645 | ||
646 | return; | |
647 | } | |
648 | ||
649 | /* | |
650 | * Start by building the multipart structures, then pick the first | |
651 | * human-readable section and stuff it into args->msg so no one gets | |
652 | * suspicious. | |
653 | * | |
654 | */ | |
655 | static int incomingim_ch1_parsemsgs(aim_session_t *sess, fu8_t *data, int len, struct aim_incomingim_ch1_args *args) | |
656 | { | |
657 | static const fu16_t charsetpri[] = { | |
658 | 0x0000, /* ASCII first */ | |
659 | 0x0003, /* then ISO-8859-1 */ | |
660 | 0x0002, /* UNICODE as last resort */ | |
661 | }; | |
662 | static const int charsetpricount = 3; | |
663 | int i; | |
664 | aim_bstream_t mbs; | |
665 | aim_mpmsg_section_t *sec; | |
666 | ||
667 | aim_bstream_init(&mbs, data, len); | |
668 | ||
669 | while (aim_bstream_empty(&mbs)) { | |
670 | fu16_t msglen, flag1, flag2; | |
671 | fu8_t *msgbuf; | |
672 | ||
673 | aimbs_get8(&mbs); /* 01 */ | |
674 | aimbs_get8(&mbs); /* 01 */ | |
675 | ||
676 | /* Message string length, including character set info. */ | |
677 | msglen = aimbs_get16(&mbs); | |
678 | ||
679 | /* Character set info */ | |
680 | flag1 = aimbs_get16(&mbs); | |
681 | flag2 = aimbs_get16(&mbs); | |
682 | ||
683 | /* Message. */ | |
684 | msglen -= 4; | |
685 | ||
686 | /* | |
687 | * For now, we don't care what the encoding is. Just copy | |
688 | * it into a multipart struct and deal with it later. However, | |
689 | * always pad the ending with a NULL. This makes it easier | |
690 | * to treat ASCII sections as strings. It won't matter for | |
691 | * UNICODE or binary data, as you should never read past | |
692 | * the specified data length, which will not include the pad. | |
693 | * | |
694 | * XXX There's an API bug here. For sending, the UNICODE is | |
695 | * given in host byte order (aim_mpmsg_addunicode), but here | |
696 | * the received messages are given in network byte order. | |
697 | * | |
698 | */ | |
699 | msgbuf = aimbs_getstr(&mbs, msglen); | |
700 | mpmsg_addsection(sess, &args->mpmsg, flag1, flag2, msgbuf, msglen); | |
701 | ||
702 | } /* while */ | |
703 | ||
704 | args->icbmflags |= AIM_IMFLAGS_MULTIPART; /* always set */ | |
705 | ||
706 | /* | |
707 | * Clients that support multiparts should never use args->msg, as it | |
708 | * will point to an arbitrary section. | |
709 | * | |
710 | * Here, we attempt to provide clients that do not support multipart | |
711 | * messages with something to look at -- hopefully a human-readable | |
712 | * string. But, failing that, a UNICODE message, or nothing at all. | |
713 | * | |
714 | * Which means that even if args->msg is NULL, it does not mean the | |
715 | * message was blank. | |
716 | * | |
717 | */ | |
718 | for (i = 0; i < charsetpricount; i++) { | |
719 | for (sec = args->mpmsg.parts; sec; sec = sec->next) { | |
720 | ||
721 | if (sec->charset != charsetpri[i]) | |
722 | continue; | |
723 | ||
724 | /* Great. We found one. Fill it in. */ | |
725 | args->charset = sec->charset; | |
726 | args->charsubset = sec->charsubset; | |
727 | args->icbmflags |= AIM_IMFLAGS_CUSTOMCHARSET; | |
728 | ||
729 | /* Set up the simple flags */ | |
730 | if (args->charset == 0x0000) | |
731 | ; /* ASCII */ | |
732 | else if (args->charset == 0x0002) | |
733 | args->icbmflags |= AIM_IMFLAGS_UNICODE; | |
734 | else if (args->charset == 0x0003) | |
735 | args->icbmflags |= AIM_IMFLAGS_ISO_8859_1; | |
736 | else if (args->charset == 0xffff) | |
737 | ; /* no encoding (yeep!) */ | |
738 | ||
739 | if (args->charsubset == 0x0000) | |
740 | ; /* standard subencoding? */ | |
741 | else if (args->charsubset == 0x000b) | |
742 | args->icbmflags |= AIM_IMFLAGS_SUBENC_MACINTOSH; | |
743 | else if (args->charsubset == 0xffff) | |
744 | ; /* no subencoding */ | |
745 | #if 0 | |
746 | /* XXX this isn't really necesary... */ | |
747 | if ( ((args.flag1 != 0x0000) && | |
748 | (args.flag1 != 0x0002) && | |
749 | (args.flag1 != 0x0003) && | |
750 | (args.flag1 != 0xffff)) || | |
751 | ((args.flag2 != 0x0000) && | |
752 | (args.flag2 != 0x000b) && | |
753 | (args.flag2 != 0xffff))) { | |
754 | faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", args.flag1, args.flag2); | |
755 | } | |
756 | #endif | |
757 | ||
758 | args->msg = sec->data; | |
759 | args->msglen = sec->datalen; | |
760 | ||
761 | return 0; | |
762 | } | |
763 | } | |
764 | ||
765 | /* No human-readable sections found. Oh well. */ | |
766 | args->charset = args->charsubset = 0xffff; | |
767 | args->msg = NULL; | |
768 | args->msglen = 0; | |
769 | ||
770 | return 0; | |
771 | } | |
772 | ||
6ae3c48d | 773 | /* |
d410cf58 | 774 | * |
775 | * This should use tlvlists, but doesn't for performance reasons. | |
776 | * | |
777 | * XXX support multipart IMs: | |
6ae3c48d | 778 | * |
779 | * 0004 0007 0000 8f08 d295 | |
780 | * 0031 6520 3b7b f9fd | |
781 | * 0001 | |
782 | * 06 XXXX XXXX XXXX | |
783 | * 0000 | |
784 | * 0004 | |
785 | * 0001 0002 0004 | |
786 | * 0010 0004 0000 01a3 | |
787 | * 0002 0004 3ab6 94fa | |
788 | * 0003 0004 3b7b f85a | |
789 | * 0002 003c | |
790 | * 0501 0001 01 | |
791 | * 0101 000a 0000 0000 3c48 544d 4c3e ASCII part | |
792 | * ISO-8859 part: | |
793 | * 0101 0016 0003 0000 6c6b 7364 6a6b 6c6a 676c a56b 3b73 646a 6b6a | |
794 | * 0101 000b 0000 0000 3c2f 4854 4d4c 3e another ASCII part | |
795 | * | |
796 | */ | |
d410cf58 | 797 | static int incomingim_ch1(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, fu16_t channel, struct aim_userinfo_s *userinfo, aim_bstream_t *bs, fu8_t *cookie) |
00ef5271 | 798 | { |
d410cf58 | 799 | fu16_t type, length; |
1dcd23dd | 800 | aim_rxcallback_t userfunc; |
d410cf58 | 801 | int ret = 0; |
1dcd23dd | 802 | struct aim_incomingim_ch1_args args; |
d410cf58 | 803 | int endpos; |
00ef5271 | 804 | |
1dcd23dd | 805 | memset(&args, 0, sizeof(args)); |
00ef5271 | 806 | |
603fdcaa | 807 | aim_mpmsg_init(sess, &args.mpmsg); |
808 | ||
1dcd23dd | 809 | /* |
810 | * This used to be done using tlvchains. For performance reasons, | |
811 | * I've changed it to process the TLVs in-place. This avoids lots | |
812 | * of per-IM memory allocations. | |
813 | */ | |
d410cf58 | 814 | while (aim_bstream_empty(bs)) { |
815 | ||
816 | type = aimbs_get16(bs); | |
817 | length = aimbs_get16(bs); | |
1dcd23dd | 818 | |
d410cf58 | 819 | endpos = aim_bstream_curpos(bs) + length; |
1dcd23dd | 820 | |
821 | if (type == 0x0002) { /* Message Block */ | |
1dcd23dd | 822 | |
1dcd23dd | 823 | /* |
d410cf58 | 824 | * This TLV consists of the following: |
825 | * - 0501 -- Unknown | |
826 | * - Features: Don't know how to interpret these | |
827 | * - 0101 -- Unknown | |
828 | * - Message | |
1dcd23dd | 829 | * |
830 | */ | |
831 | ||
d410cf58 | 832 | aimbs_get8(bs); /* 05 */ |
833 | aimbs_get8(bs); /* 01 */ | |
84e0ca17 | 834 | |
835 | args.featureslen = aimbs_get16(bs); | |
836 | /* XXX XXX this is all evil! */ | |
837 | args.features = bs->data + bs->offset; | |
838 | aim_bstream_advance(bs, args.featureslen); | |
839 | args.icbmflags |= AIM_IMFLAGS_CUSTOMFEATURES; | |
840 | ||
603fdcaa | 841 | /* |
842 | * The rest of the TLV contains one or more message | |
843 | * blocks... | |
844 | */ | |
845 | incomingim_ch1_parsemsgs(sess, bs->data + bs->offset /* XXX evil!!! */, length - 2 - 2 - args.featureslen, &args); | |
1dcd23dd | 846 | |
847 | } else if (type == 0x0003) { /* Server Ack Requested */ | |
848 | ||
849 | args.icbmflags |= AIM_IMFLAGS_ACK; | |
850 | ||
851 | } else if (type == 0x0004) { /* Message is Auto Response */ | |
852 | ||
853 | args.icbmflags |= AIM_IMFLAGS_AWAY; | |
854 | ||
d410cf58 | 855 | } else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */ |
1dcd23dd | 856 | |
84e0ca17 | 857 | args.iconsum = aimbs_get32(bs); |
858 | args.iconlen = aimbs_get32(bs); | |
d410cf58 | 859 | args.iconstamp = aimbs_get32(bs); |
1dcd23dd | 860 | args.icbmflags |= AIM_IMFLAGS_HASICON; |
861 | ||
862 | } else if (type == 0x0009) { | |
863 | ||
864 | args.icbmflags |= AIM_IMFLAGS_BUDDYREQ; | |
865 | ||
866 | } else if (type == 0x0017) { | |
867 | ||
868 | args.extdatalen = length; | |
d410cf58 | 869 | args.extdata = aimbs_getraw(bs, args.extdatalen); |
1dcd23dd | 870 | |
871 | } else { | |
6ae3c48d | 872 | faimdprintf(sess, 0, "incomingim_ch1: unknown TLV 0x%04x (len %d)\n", type, length); |
1dcd23dd | 873 | } |
874 | ||
d410cf58 | 875 | /* |
876 | * This is here to protect ourselves from ourselves. That | |
877 | * is, if something above doesn't completly parse its value | |
878 | * section, or, worse, overparses it, this will set the | |
879 | * stream where it needs to be in order to land on the next | |
880 | * TLV when the loop continues. | |
881 | * | |
882 | */ | |
883 | aim_bstream_setpos(bs, endpos); | |
1dcd23dd | 884 | } |
00ef5271 | 885 | |
00ef5271 | 886 | |
1dcd23dd | 887 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
888 | ret = userfunc(sess, rx, channel, userinfo, &args); | |
00ef5271 | 889 | |
603fdcaa | 890 | aim_mpmsg_free(sess, &args.mpmsg); |
d410cf58 | 891 | free(args.extdata); |
00ef5271 | 892 | |
1dcd23dd | 893 | return ret; |
00ef5271 | 894 | } |
895 | ||
8722e782 | 896 | static int incomingim_ch2_buddylist(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) |
897 | { | |
898 | aim_rxcallback_t userfunc; | |
899 | int ret = 0; | |
900 | aim_tlv_t *tse; | |
901 | aim_bstream_t tbs; | |
902 | ||
903 | if (args->status != 0x0000) | |
904 | return 1; /* ignore it -- not sure what it means */ | |
905 | ||
906 | tse = aim_gettlv(list2, 0x2711, 1); | |
907 | aim_bstream_init(&tbs, tse->value, tse->length); | |
908 | ||
909 | /* | |
910 | * This goes like this... | |
911 | * | |
912 | * group name length | |
913 | * group name | |
914 | * num of buddies in group | |
915 | * buddy name length | |
916 | * buddy name | |
917 | * buddy name length | |
918 | * buddy name | |
919 | * ... | |
920 | * group name length | |
921 | * group name | |
922 | * num of buddies in group | |
923 | * buddy name length | |
924 | * buddy name | |
925 | * ... | |
926 | * ... | |
927 | */ | |
928 | while (aim_bstream_empty(&tbs)) { | |
929 | fu16_t gnlen, numb; | |
930 | int i; | |
931 | char *gn; | |
932 | ||
933 | gnlen = aimbs_get16(&tbs); | |
934 | gn = aimbs_getstr(&tbs, gnlen); | |
935 | numb = aimbs_get16(&tbs); | |
936 | ||
937 | for (i = 0; i < numb; i++) { | |
938 | fu16_t bnlen; | |
939 | char *bn; | |
940 | ||
941 | bnlen = aimbs_get16(&tbs); | |
942 | bn = aimbs_getstr(&tbs, bnlen); | |
943 | ||
944 | faimdprintf(sess, 0, "got a buddy list from %s: group %s, buddy %s\n", userinfo->sn, gn, bn); | |
945 | ||
946 | free(bn); | |
947 | } | |
948 | ||
949 | free(gn); | |
950 | } | |
951 | ||
952 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
953 | ret = userfunc(sess, rx, 0x0002, userinfo, args); | |
954 | ||
955 | return ret; | |
956 | } | |
957 | ||
c5f5b7f1 | 958 | static int incomingim_ch2_buddyicon(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) |
959 | { | |
960 | aim_rxcallback_t userfunc; | |
961 | int ret = 0; | |
962 | aim_tlv_t *miscinfo; | |
963 | aim_bstream_t tbs; | |
964 | ||
965 | miscinfo = aim_gettlv(list2, 0x2711, 1); | |
966 | aim_bstream_init(&tbs, miscinfo->value, miscinfo->length); | |
967 | ||
968 | args->info.icon.checksum = aimbs_get32(&tbs); | |
969 | args->info.icon.length = aimbs_get32(&tbs); | |
970 | args->info.icon.timestamp = aimbs_get32(&tbs); | |
971 | args->info.icon.icon = aimbs_getraw(&tbs, args->info.icon.length); | |
972 | ||
973 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
974 | ret = userfunc(sess, rx, 0x0002, userinfo, args); | |
975 | ||
976 | free(args->info.icon.icon); | |
977 | ||
978 | return ret; | |
979 | } | |
980 | ||
8722e782 | 981 | static int incomingim_ch2_voice(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) |
982 | { | |
983 | aim_msgcookie_t *cachedcook; | |
984 | int ret = 0; | |
985 | aim_rxcallback_t userfunc; | |
986 | ||
987 | faimdprintf(sess, 1, "rend: voice!\n"); | |
988 | ||
989 | if (!(cachedcook = (aim_msgcookie_t*)calloc(1, sizeof(aim_msgcookie_t)))) | |
990 | return 0; | |
991 | ||
992 | memcpy(cachedcook->cookie, args->cookie, 8); | |
993 | cachedcook->type = AIM_COOKIETYPE_OFTVOICE; | |
994 | cachedcook->data = NULL; | |
995 | ||
996 | if (aim_cachecookie(sess, cachedcook) == -1) | |
997 | faimdprintf(sess, 0, "ERROR caching message cookie\n"); | |
998 | ||
999 | /* XXX: implement all this */ | |
1000 | ||
1001 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
5588b2ee | 1002 | ret = userfunc(sess, rx, 0x0002, userinfo, args); |
8722e782 | 1003 | |
1004 | return ret; | |
1005 | } | |
1006 | ||
1007 | static int incomingim_ch2_chat(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) | |
1008 | { | |
1009 | aim_tlv_t *miscinfo; | |
1010 | aim_bstream_t tbs; | |
1011 | aim_rxcallback_t userfunc; | |
1012 | int ret = 0; | |
1013 | ||
1014 | miscinfo = aim_gettlv(list2, 0x2711, 1); | |
1015 | aim_bstream_init(&tbs, miscinfo->value, miscinfo->length); | |
1016 | ||
1017 | aim_chat_readroominfo(&tbs, &args->info.chat.roominfo); | |
1018 | ||
1019 | if (aim_gettlv(list2, 0x000c, 1)) | |
1020 | args->info.chat.msg = aim_gettlv_str(list2, 0x000c, 1); | |
1021 | ||
1022 | if (aim_gettlv(list2, 0x000d, 1)) | |
1023 | args->info.chat.encoding = aim_gettlv_str(list2, 0x000d, 1); | |
1024 | ||
1025 | if (aim_gettlv(list2, 0x000e, 1)) | |
1026 | args->info.chat.lang = aim_gettlv_str(list2, 0x000e, 1); | |
1027 | ||
1028 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
5588b2ee | 1029 | ret = userfunc(sess, rx, 0x0002, userinfo, args); |
8722e782 | 1030 | |
1031 | /* XXX free_roominfo */ | |
1032 | free(args->info.chat.roominfo.name); | |
1033 | free(args->info.chat.msg); | |
1034 | free(args->info.chat.encoding); | |
1035 | free(args->info.chat.lang); | |
1036 | ||
1037 | return ret; | |
1038 | } | |
1039 | ||
1040 | static int incomingim_ch2_getfile(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) | |
1041 | { | |
1042 | char ip[30]; | |
1043 | aim_msgcookie_t *cachedcook; | |
1044 | aim_tlv_t *miscinfo; | |
1045 | aim_tlv_t *iptlv, *porttlv; | |
1046 | int ret = 0; | |
1047 | aim_rxcallback_t userfunc; | |
1048 | ||
1049 | memset(ip, 0, 30); | |
1050 | ||
1051 | if (!(cachedcook = calloc(1, sizeof(aim_msgcookie_t)))) { | |
1052 | aim_freetlvchain(&list2); | |
1053 | return 0; | |
1054 | } | |
1055 | ||
1056 | if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) || | |
1057 | !(iptlv = aim_gettlv(list2, 0x0003, 1)) || | |
1058 | !(porttlv = aim_gettlv(list2, 0x0005, 1))) { | |
1059 | ||
1060 | faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn); | |
1061 | aim_cookie_free(sess, cachedcook); | |
1062 | aim_freetlvchain(&list2); | |
1063 | ||
1064 | return 0; | |
1065 | } | |
1066 | ||
1067 | snprintf(ip, 30, "%d.%d.%d.%d:%d", | |
1068 | aimutil_get8(iptlv->value+0), | |
1069 | aimutil_get8(iptlv->value+1), | |
1070 | aimutil_get8(iptlv->value+2), | |
1071 | aimutil_get8(iptlv->value+3), | |
1072 | aimutil_get16(porttlv->value)); | |
1073 | ||
1074 | faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip); | |
1075 | ||
1076 | args->info.getfile.ip = ip; | |
1077 | memcpy(args->info.getfile.cookie, args->cookie, 8); | |
1078 | ||
1079 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
5588b2ee | 1080 | ret = userfunc(sess, rx, 0x0002, userinfo, args); |
8722e782 | 1081 | |
1082 | return ret; | |
1083 | } | |
1084 | ||
1085 | static int incomingim_ch2_sendfile(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) | |
1086 | { | |
1087 | #if 0 | |
1088 | char ip[30]; | |
1089 | aim_msgcookie_t *cachedcook; | |
1090 | aim_tlv_t *miscinfo; | |
1091 | aim_tlv_t *iptlv, *porttlv; | |
1092 | int ret =0; | |
1093 | aim_rxcallback_t userfunc; | |
1094 | char *desc = NULL; | |
1095 | ||
1096 | memset(ip, 0, 30); | |
1097 | ||
1098 | if (!(cachedcook = calloc(1, sizeof(aim_msgcookie_t)))) | |
1099 | return 0; | |
1100 | ||
1101 | if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) || | |
1102 | !(iptlv = aim_gettlv(list2, 0x0003, 1)) || | |
1103 | !(porttlv = aim_gettlv(list2, 0x0005, 1))) { | |
1104 | ||
1105 | faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn); | |
1106 | aim_cookie_free(sess, cachedcook); | |
1107 | ||
1108 | return 0; | |
1109 | } | |
1110 | ||
1111 | snprintf(ip, 30, "%d.%d.%d.%d:%d", | |
1112 | aimutil_get8(iptlv->value+0), | |
1113 | aimutil_get8(iptlv->value+1), | |
1114 | aimutil_get8(iptlv->value+2), | |
1115 | aimutil_get8(iptlv->value+3), | |
1116 | aimutil_get16(porttlv->value)); | |
1117 | ||
1118 | if (aim_gettlv(list2, 0x000c, 1)) | |
1119 | desc = aim_gettlv_str(list2, 0x000c, 1); | |
1120 | ||
1121 | faimdprintf(sess, 0, "rend: file transfer request from %s: %s (%s)\n", | |
1122 | userinfo->sn, desc, ip); | |
1123 | ||
1124 | memcpy(cachedcook->cookie, args->cookie, 8); | |
1125 | ||
1126 | ft = malloc(sizeof(struct aim_filetransfer_priv)); /* XXX */ | |
1127 | strncpy(ft->sn, userinfo.sn, sizeof(ft->sn)); | |
1128 | strncpy(ft->ip, ip, sizeof(ft->ip)); | |
1129 | strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name)); | |
1130 | cachedcook->type = AIM_COOKIETYPE_OFTSEND; | |
1131 | cachedcook->data = ft; | |
1132 | ||
1133 | if (aim_cachecookie(sess, cachedcook) == -1) | |
1134 | faimdprintf(sess, 0, "ERROR caching message cookie\n"); | |
1135 | ||
1136 | aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE); | |
1137 | ||
1138 | if (desc) | |
1139 | free(desc); | |
1140 | ||
1141 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
1142 | ret = userfunc(sess, rx, 0x0002, userinfo, &args); | |
1143 | #endif | |
1144 | return 0; | |
1145 | } | |
1146 | ||
c5f5b7f1 | 1147 | static int incomingim_ch2_imimage(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2) |
1148 | { | |
1149 | aim_rxcallback_t userfunc; | |
1150 | int ret = 0; | |
1151 | ||
1152 | /* Primary IP address */ | |
1153 | if (aim_gettlv(list2, 0x0003, 1)) { | |
1154 | aim_tlv_t *tlv; | |
1155 | ||
1156 | tlv = aim_gettlv(list2, 0x0003, 1); | |
1157 | ||
1158 | snprintf(args->info.imimage.ip, sizeof(args->info.imimage.ip), | |
1159 | "%d.%d.%d.%d:4443", | |
1160 | tlv->value[0], | |
1161 | tlv->value[1], | |
1162 | tlv->value[2], | |
1163 | tlv->value[3]); | |
1164 | } | |
1165 | ||
1166 | /* | |
1167 | * Alternate IP address | |
1168 | * | |
1169 | * Sort of. The peer doesn't send this -- the OSCAR | |
1170 | * server does. So it will be the IP address that the | |
1171 | * peer is directly connected to the internet with, which | |
1172 | * may not be the same as the IP above. If these two | |
1173 | * values differ, it's rather unlikely that this | |
1174 | * rendezvous is going to happen... | |
1175 | * | |
1176 | */ | |
1177 | if (aim_gettlv(list2, 0x0004, 1)) | |
1178 | ; | |
1179 | ||
1180 | /* Port number (not correct -- ignore) */ | |
1181 | if (aim_gettlv(list2, 0x0005, 1)) | |
1182 | ; | |
1183 | ||
1184 | /* Unknown -- two bytes = 0x0001 */ | |
1185 | if (aim_gettlv(list2, 0x000a, 1)) | |
1186 | ; | |
1187 | ||
1188 | /* Unknown -- no value */ | |
1189 | if (aim_gettlv(list2, 0x000f, 1)) | |
1190 | ; | |
1191 | ||
1192 | faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n", userinfo->sn, args->info.imimage.ip); | |
1193 | ||
1194 | /* | |
1195 | * XXX: there are a couple of different request packets for | |
1196 | * different things | |
1197 | */ | |
1198 | ||
1199 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
1200 | ret = userfunc(sess, rx, 0x0002, userinfo, args); | |
1201 | ||
1202 | return ret; | |
1203 | } | |
1204 | ||
d410cf58 | 1205 | /* XXX Ugh. I think its obvious. */ |
1206 | static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, fu16_t channel, struct aim_userinfo_s *userinfo, aim_tlvlist_t *tlvlist, fu8_t *cookie) | |
00ef5271 | 1207 | { |
d410cf58 | 1208 | aim_tlv_t *block1; |
1209 | aim_tlvlist_t *list2; | |
6ae3c48d | 1210 | int ret = 0; |
1211 | struct aim_incomingim_ch2_args args; | |
d410cf58 | 1212 | aim_bstream_t bbs; |
1213 | fu8_t *cookie2; | |
6ae3c48d | 1214 | |
1215 | memset(&args, 0, sizeof(args)); | |
1216 | ||
1217 | /* | |
1218 | * There's another block of TLVs embedded in the type 5 here. | |
1219 | */ | |
355229fe | 1220 | if (!(block1 = aim_gettlv(tlvlist, 0x0005, 1)) || !block1->value) { |
6ae3c48d | 1221 | faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n"); |
1222 | return 0; | |
1223 | } | |
1224 | ||
d410cf58 | 1225 | aim_bstream_init(&bbs, block1->value, block1->length); |
1226 | ||
6ae3c48d | 1227 | /* |
1228 | * First two bytes represent the status of the connection. | |
1229 | * | |
1230 | * 0 is a request, 2 is an accept | |
1231 | */ | |
d410cf58 | 1232 | args.status = aimbs_get16(&bbs); |
6ae3c48d | 1233 | |
1234 | /* | |
1235 | * Next comes the cookie. Should match the ICBM cookie. | |
1236 | */ | |
d410cf58 | 1237 | cookie2 = aimbs_getraw(&bbs, 8); |
1238 | if (memcmp(cookie, cookie2, 8) != 0) | |
6ae3c48d | 1239 | faimdprintf(sess, 0, "rend: warning cookies don't match!\n"); |
c5f5b7f1 | 1240 | memcpy(args.cookie, cookie2, 8); |
d410cf58 | 1241 | free(cookie2); |
6ae3c48d | 1242 | |
1243 | /* | |
1244 | * The next 16bytes are a capability block so we can | |
1245 | * identify what type of rendezvous this is. | |
1246 | * | |
1247 | * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM) | |
1248 | * for pointing some of this out to me. In fact, a lot of | |
1249 | * the client-to-client info comes from the work of the GAIM | |
1250 | * developers. Thanks! | |
1251 | * | |
1252 | * Read off one capability string and we should have it ID'd. | |
1253 | * | |
1254 | */ | |
d410cf58 | 1255 | if ((args.reqclass = aim_getcap(sess, &bbs, 0x10)) == 0x0000) { |
6ae3c48d | 1256 | faimdprintf(sess, 0, "rend: no ID block\n"); |
1257 | return 0; | |
1258 | } | |
1259 | ||
1260 | /* | |
70b889c5 | 1261 | * What follows may be TLVs or nothing, depending on the |
1262 | * purpose of the message. | |
1263 | * | |
1264 | * Ack packets for instance have nothing more to them. | |
1265 | */ | |
d410cf58 | 1266 | list2 = aim_readtlvchain(&bbs); |
6ae3c48d | 1267 | |
c5f5b7f1 | 1268 | #if 0 /* this should be in the per-type blocks */ |
6ae3c48d | 1269 | if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) { |
d410cf58 | 1270 | aim_msgcookie_t *cook; |
6ae3c48d | 1271 | int type; |
1272 | ||
1273 | type = aim_msgcookie_gettype(args.reqclass); /* XXX: fix this shitty code */ | |
1274 | ||
1275 | if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) { | |
1276 | faimdprintf(sess, 0, "non-data rendezvous thats not in cache (type %d)\n", type); | |
d410cf58 | 1277 | aim_freetlvchain(&list2); |
1278 | return 1; | |
6ae3c48d | 1279 | } |
1280 | ||
1281 | if (cook->type == AIM_COOKIETYPE_OFTGET) { | |
1282 | struct aim_filetransfer_priv *ft; | |
1283 | ||
1284 | if (cook->data) { | |
1285 | int errorcode = -1; /* XXX shouldnt this be 0? */ | |
1286 | ||
1287 | ft = (struct aim_filetransfer_priv *)cook->data; | |
1288 | ||
1289 | if (args.status != 0x0002) { | |
1290 | ||
d410cf58 | 1291 | if (aim_gettlv(list2, 0x000b, 1)) |
1292 | errorcode = aim_gettlv16(list2, 0x000b, 1); | |
6ae3c48d | 1293 | |
d410cf58 | 1294 | /* XXX this should make it up to the client, you know.. */ |
1295 | if (errorcode) | |
1296 | faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode); | |
6ae3c48d | 1297 | } /* args.status != 0x0002 */ |
d410cf58 | 1298 | |
6ae3c48d | 1299 | } else { |
1300 | faimdprintf(sess, 0, "no data attached to file transfer\n"); | |
1301 | } /* !cook->data */ | |
1302 | ||
1303 | } else if (cook->type == AIM_CAPS_VOICE) { | |
1304 | ||
1305 | faimdprintf(sess, 0, "voice request cancelled\n"); | |
1306 | ||
1307 | } else { | |
1308 | ||
1309 | faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type); | |
1310 | } | |
1311 | ||
1312 | aim_freetlvchain(&list2); | |
1313 | ||
1314 | return 1; | |
00ef5271 | 1315 | } |
c5f5b7f1 | 1316 | #endif |
6ae3c48d | 1317 | |
1318 | /* | |
1319 | * The rest of the handling depends on what type it is. | |
1320 | */ | |
8722e782 | 1321 | if (args.reqclass & AIM_CAPS_BUDDYICON) |
c5f5b7f1 | 1322 | ret = incomingim_ch2_buddyicon(sess, mod, rx, snac, userinfo, &args, list2); |
8722e782 | 1323 | else if (args.reqclass & AIM_CAPS_SENDBUDDYLIST) |
1324 | ret = incomingim_ch2_buddylist(sess, mod, rx, snac, userinfo, &args, list2); | |
1325 | else if (args.reqclass & AIM_CAPS_VOICE) | |
1326 | ret = incomingim_ch2_voice(sess, mod, rx, snac, userinfo, &args, list2); | |
1327 | else if (args.reqclass & AIM_CAPS_IMIMAGE) | |
c5f5b7f1 | 1328 | ret = incomingim_ch2_imimage(sess, mod, rx, snac, userinfo, &args, list2); |
8722e782 | 1329 | else if (args.reqclass & AIM_CAPS_CHAT) |
1330 | ret = incomingim_ch2_chat(sess, mod, rx, snac, userinfo, &args, list2); | |
1331 | else if (args.reqclass & AIM_CAPS_GETFILE) | |
1332 | ret = incomingim_ch2_getfile(sess, mod, rx, snac, userinfo, &args, list2); | |
1333 | else if (args.reqclass & AIM_CAPS_SENDFILE) | |
1334 | ret = incomingim_ch2_sendfile(sess, mod, rx, snac, userinfo, &args, list2); | |
1335 | else | |
6ae3c48d | 1336 | faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", args.reqclass); |
00ef5271 | 1337 | |
6ae3c48d | 1338 | aim_freetlvchain(&list2); |
00ef5271 | 1339 | |
6ae3c48d | 1340 | return ret; |
e5012450 | 1341 | } |
1342 | ||
49c8a2fa | 1343 | /* |
1344 | * It can easily be said that parsing ICBMs is THE single | |
1345 | * most difficult thing to do in the in AIM protocol. In | |
1346 | * fact, I think I just did say that. | |
1347 | * | |
1348 | * Below is the best damned solution I've come up with | |
1349 | * over the past sixteen months of battling with it. This | |
1350 | * can parse both away and normal messages from every client | |
1351 | * I have access to. Its not fast, its not clean. But it works. | |
1352 | * | |
49c8a2fa | 1353 | */ |
d410cf58 | 1354 | static int incomingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
9de3ca7e | 1355 | { |
6ae3c48d | 1356 | int i, ret = 0; |
d410cf58 | 1357 | fu8_t cookie[8]; |
1358 | fu16_t channel; | |
6ae3c48d | 1359 | struct aim_userinfo_s userinfo; |
1360 | ||
1361 | memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s)); | |
1362 | ||
1363 | /* | |
1364 | * Read ICBM Cookie. And throw away. | |
1365 | */ | |
1366 | for (i = 0; i < 8; i++) | |
d410cf58 | 1367 | cookie[i] = aimbs_get8(bs); |
6ae3c48d | 1368 | |
1369 | /* | |
1370 | * Channel ID. | |
1371 | * | |
1372 | * Channel 0x0001 is the message channel. There are | |
1373 | * other channels for things called "rendevous" | |
1374 | * which represent chat and some of the other new | |
1375 | * features of AIM2/3/3.5. | |
1376 | * | |
1377 | * Channel 0x0002 is the Rendevous channel, which | |
1378 | * is where Chat Invitiations and various client-client | |
1379 | * connection negotiations come from. | |
1380 | * | |
1381 | */ | |
d410cf58 | 1382 | channel = aimbs_get16(bs); |
6ae3c48d | 1383 | |
1384 | /* | |
1385 | * Technically Channel 3 in chat could be done here too. | |
1386 | */ | |
1387 | if ((channel != 0x01) && (channel != 0x02)) { | |
1388 | faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel); | |
d410cf58 | 1389 | return 0; |
6ae3c48d | 1390 | } |
1391 | ||
1392 | /* | |
1393 | * Extract the standard user info block. | |
1394 | * | |
1395 | * Note that although this contains TLVs that appear contiguous | |
1396 | * with the TLVs read below, they are two different pieces. The | |
1397 | * userinfo block contains the number of TLVs that contain user | |
1398 | * information, the rest are not even though there is no seperation. | |
1399 | * aim_extractuserinfo() returns the number of bytes used by the | |
1400 | * userinfo tlvs, so you can start reading the rest of them right | |
1401 | * afterward. | |
1402 | * | |
1403 | * That also means that TLV types can be duplicated between the | |
1404 | * userinfo block and the rest of the message, however there should | |
1405 | * never be two TLVs of the same type in one block. | |
1406 | * | |
1407 | */ | |
d410cf58 | 1408 | aim_extractuserinfo(sess, bs, &userinfo); |
6ae3c48d | 1409 | |
1410 | /* | |
1411 | * From here on, its depends on what channel we're on. | |
1412 | * | |
1413 | * Technically all channels have a TLV list have this, however, | |
1414 | * for the common channel 1 case, in-place parsing is used for | |
1415 | * performance reasons (less memory allocation). | |
1416 | */ | |
1417 | if (channel == 1) { | |
1418 | ||
d410cf58 | 1419 | ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, bs, cookie); |
6ae3c48d | 1420 | |
1421 | } else if (channel == 0x0002) { | |
d410cf58 | 1422 | aim_tlvlist_t *tlvlist; |
6ae3c48d | 1423 | |
1424 | /* | |
1425 | * Read block of TLVs (not including the userinfo data). All | |
1426 | * further data is derived from what is parsed here. | |
1427 | */ | |
d410cf58 | 1428 | tlvlist = aim_readtlvchain(bs); |
6ae3c48d | 1429 | |
1430 | ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie); | |
1431 | ||
1432 | /* | |
1433 | * Free up the TLV chain. | |
1434 | */ | |
1435 | aim_freetlvchain(&tlvlist); | |
1436 | } | |
1437 | ||
1438 | return ret; | |
49c8a2fa | 1439 | } |
1440 | ||
040457cc | 1441 | /* |
1442 | * Possible codes: | |
1443 | * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support" | |
1444 | * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer" | |
1445 | * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers" | |
1446 | * | |
1447 | */ | |
d410cf58 | 1448 | faim_export int aim_denytransfer(aim_session_t *sess, aim_conn_t *conn, const char *sender, const char *cookie, fu16_t code) |
040457cc | 1449 | { |
d410cf58 | 1450 | aim_frame_t *fr; |
1451 | aim_snacid_t snacid; | |
1452 | aim_tlvlist_t *tl = NULL; | |
1453 | ||
1454 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6))) | |
6ae3c48d | 1455 | return -ENOMEM; |
040457cc | 1456 | |
d410cf58 | 1457 | snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0); |
1458 | aim_putsnac(&fr->data, 0x0004, 0x000b, 0x0000, snacid); | |
1459 | ||
1460 | aimbs_putraw(&fr->data, cookie, 8); | |
040457cc | 1461 | |
d410cf58 | 1462 | aimbs_put16(&fr->data, 0x0002); /* channel */ |
1463 | aimbs_put8(&fr->data, strlen(sender)); | |
1464 | aimbs_putraw(&fr->data, sender, strlen(sender)); | |
040457cc | 1465 | |
d410cf58 | 1466 | aim_addtlvtochain16(&tl, 0x0003, code); |
1467 | aim_writetlvchain(&fr->data, &tl); | |
1468 | aim_freetlvchain(&tl); | |
1469 | ||
1470 | aim_tx_enqueue(sess, fr); | |
040457cc | 1471 | |
6ae3c48d | 1472 | return 0; |
040457cc | 1473 | } |
1474 | ||
49c8a2fa | 1475 | /* |
355229fe | 1476 | * aim_reqicbmparaminfo() |
49c8a2fa | 1477 | * |
355229fe | 1478 | * Request ICBM parameter information. |
49c8a2fa | 1479 | * |
1480 | */ | |
d410cf58 | 1481 | faim_export int aim_reqicbmparams(aim_session_t *sess, aim_conn_t *conn) |
355229fe | 1482 | { |
1483 | return aim_genericreq_n(sess, conn, 0x0004, 0x0004); | |
1484 | } | |
1485 | ||
1486 | /* | |
1487 | * | |
d410cf58 | 1488 | * I definitly recommend sending this. If you don't, you'll be stuck |
1489 | * with the rather unreasonable defaults. You don't want those. Send this. | |
1490 | * | |
355229fe | 1491 | */ |
d410cf58 | 1492 | faim_export int aim_seticbmparam(aim_session_t *sess, aim_conn_t *conn, struct aim_icbmparameters *params) |
49c8a2fa | 1493 | { |
d410cf58 | 1494 | aim_frame_t *fr; |
1495 | aim_snacid_t snacid; | |
49c8a2fa | 1496 | |
355229fe | 1497 | if (!sess || !conn || !params) |
1498 | return -EINVAL; | |
1499 | ||
d410cf58 | 1500 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+16))) |
6ae3c48d | 1501 | return -ENOMEM; |
5b79dc93 | 1502 | |
d410cf58 | 1503 | snacid = aim_cachesnac(sess, 0x0004, 0x0002, 0x0000, NULL, 0); |
1504 | aim_putsnac(&fr->data, 0x0004, 0x0002, 0x0000, snacid); | |
5b79dc93 | 1505 | |
d410cf58 | 1506 | /* This is read-only (see Parameter Reply). Must be set to zero here. */ |
1507 | aimbs_put16(&fr->data, 0x0000); | |
355229fe | 1508 | |
1509 | /* These are all read-write */ | |
d410cf58 | 1510 | aimbs_put32(&fr->data, params->flags); |
1511 | aimbs_put16(&fr->data, params->maxmsglen); | |
1512 | aimbs_put16(&fr->data, params->maxsenderwarn); | |
1513 | aimbs_put16(&fr->data, params->maxrecverwarn); | |
1514 | aimbs_put32(&fr->data, params->minmsginterval); | |
5b79dc93 | 1515 | |
d410cf58 | 1516 | aim_tx_enqueue(sess, fr); |
a25832e6 | 1517 | |
6ae3c48d | 1518 | return 0; |
a25832e6 | 1519 | } |
1520 | ||
d410cf58 | 1521 | static int paraminfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
a25832e6 | 1522 | { |
355229fe | 1523 | struct aim_icbmparameters params; |
6ae3c48d | 1524 | aim_rxcallback_t userfunc; |
e6b05d80 | 1525 | |
d410cf58 | 1526 | params.maxchan = aimbs_get16(bs); |
1527 | params.flags = aimbs_get32(bs); | |
1528 | params.maxmsglen = aimbs_get16(bs); | |
1529 | params.maxsenderwarn = aimbs_get16(bs); | |
1530 | params.maxrecverwarn = aimbs_get16(bs); | |
1531 | params.minmsginterval = aimbs_get32(bs); | |
1532 | ||
6ae3c48d | 1533 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
355229fe | 1534 | return userfunc(sess, rx, ¶ms); |
00ef5271 | 1535 | |
6ae3c48d | 1536 | return 0; |
00ef5271 | 1537 | } |
1538 | ||
d410cf58 | 1539 | static int missedcall(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
96f8b1ed | 1540 | { |
d410cf58 | 1541 | int ret = 0; |
6ae3c48d | 1542 | aim_rxcallback_t userfunc; |
d410cf58 | 1543 | fu16_t channel, nummissed, reason; |
6ae3c48d | 1544 | struct aim_userinfo_s userinfo; |
6ae3c48d | 1545 | |
d410cf58 | 1546 | while (aim_bstream_empty(bs)) { |
6ae3c48d | 1547 | |
d410cf58 | 1548 | channel = aimbs_get16(bs); |
1549 | aim_extractuserinfo(sess, bs, &userinfo); | |
1550 | nummissed = aimbs_get16(bs); | |
1551 | reason = aimbs_get16(bs); | |
6ae3c48d | 1552 | |
36a61e0d | 1553 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
1554 | ret = userfunc(sess, rx, channel, &userinfo, nummissed, reason); | |
1555 | } | |
6ae3c48d | 1556 | |
36a61e0d | 1557 | return ret; |
00ef5271 | 1558 | } |
1559 | ||
d410cf58 | 1560 | static int clienterr(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
00ef5271 | 1561 | { |
d410cf58 | 1562 | int ret = 0; |
6ae3c48d | 1563 | aim_rxcallback_t userfunc; |
d410cf58 | 1564 | fu16_t channel, reason; |
1565 | char *sn; | |
1566 | fu8_t *ck, snlen; | |
00ef5271 | 1567 | |
d410cf58 | 1568 | ck = aimbs_getraw(bs, 8); |
1569 | channel = aimbs_get16(bs); | |
1570 | snlen = aimbs_get8(bs); | |
1571 | sn = aimbs_getstr(bs, snlen); | |
1572 | reason = aimbs_get16(bs); | |
00ef5271 | 1573 | |
d410cf58 | 1574 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
1575 | ret = userfunc(sess, rx, channel, sn, reason); | |
00ef5271 | 1576 | |
d410cf58 | 1577 | return ret; |
1578 | } | |
00ef5271 | 1579 | |
d410cf58 | 1580 | static int msgack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
1581 | { | |
1582 | aim_rxcallback_t userfunc; | |
1583 | fu16_t type; | |
1584 | fu8_t snlen, *ck; | |
1585 | char *sn; | |
1586 | ||
1587 | ck = aimbs_getraw(bs, 8); | |
1588 | type = aimbs_get16(bs); | |
1589 | snlen = aimbs_get8(bs); | |
1590 | sn = aimbs_getstr(bs, snlen); | |
00ef5271 | 1591 | |
6ae3c48d | 1592 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
1593 | return userfunc(sess, rx, type, sn); | |
00ef5271 | 1594 | |
d410cf58 | 1595 | free(sn); |
1596 | free(ck); | |
1597 | ||
6ae3c48d | 1598 | return 0; |
00ef5271 | 1599 | } |
1600 | ||
d410cf58 | 1601 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
00ef5271 | 1602 | { |
1603 | ||
6ae3c48d | 1604 | if (snac->subtype == 0x0005) |
d410cf58 | 1605 | return paraminfo(sess, mod, rx, snac, bs); |
6ae3c48d | 1606 | else if (snac->subtype == 0x0006) |
d410cf58 | 1607 | return outgoingim(sess, mod, rx, snac, bs); |
6ae3c48d | 1608 | else if (snac->subtype == 0x0007) |
d410cf58 | 1609 | return incomingim(sess, mod, rx, snac, bs); |
6ae3c48d | 1610 | else if (snac->subtype == 0x000a) |
d410cf58 | 1611 | return missedcall(sess, mod, rx, snac, bs); |
1612 | else if (snac->subtype == 0x000b) | |
1613 | return clienterr(sess, mod, rx, snac, bs); | |
6ae3c48d | 1614 | else if (snac->subtype == 0x000c) |
d410cf58 | 1615 | return msgack(sess, mod, rx, snac, bs); |
6ae3c48d | 1616 | |
1617 | return 0; | |
00ef5271 | 1618 | } |
1619 | ||
d410cf58 | 1620 | faim_internal int msg_modfirst(aim_session_t *sess, aim_module_t *mod) |
00ef5271 | 1621 | { |
1622 | ||
6ae3c48d | 1623 | mod->family = 0x0004; |
1624 | mod->version = 0x0000; | |
1625 | mod->flags = 0; | |
1626 | strncpy(mod->name, "messaging", sizeof(mod->name)); | |
1627 | mod->snachandler = snachandler; | |
00ef5271 | 1628 | |
6ae3c48d | 1629 | return 0; |
96f8b1ed | 1630 | } |