1 | /* |
---|
2 | * aim_im.c |
---|
3 | * |
---|
4 | * The routines for sending/receiving Instant Messages. |
---|
5 | * |
---|
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 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include <aim.h> |
---|
23 | #include "im.h" |
---|
24 | #include "info.h" |
---|
25 | |
---|
26 | /* |
---|
27 | * Takes a msghdr (and a length) and returns a client type |
---|
28 | * code. Note that this is *only a guess* and has a low likelihood |
---|
29 | * of actually being accurate. |
---|
30 | * |
---|
31 | * Its based on experimental data, with the help of Eric Warmenhoven |
---|
32 | * who seems to have collected a wide variety of different AIM clients. |
---|
33 | * |
---|
34 | * |
---|
35 | * Heres the current collection: |
---|
36 | * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414 |
---|
37 | * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464, |
---|
38 | * 4.3.2229, 4.4.2286 |
---|
39 | * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here) |
---|
40 | * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any |
---|
41 | * TOC client |
---|
42 | * |
---|
43 | * Note that in this function, only the feature bytes are tested, since |
---|
44 | * the rest will always be the same. |
---|
45 | * |
---|
46 | */ |
---|
47 | guint16 aim_fingerprintclient(guint8 *msghdr, int len) |
---|
48 | { |
---|
49 | static const struct { |
---|
50 | guint16 clientid; |
---|
51 | int len; |
---|
52 | guint8 data[10]; |
---|
53 | } fingerprints[] = { |
---|
54 | /* AOL Mobile Communicator, WinAIM 1.0.414 */ |
---|
55 | { AIM_CLIENTTYPE_MC, |
---|
56 | 3, {0x01, 0x01, 0x01}}, |
---|
57 | |
---|
58 | /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */ |
---|
59 | { AIM_CLIENTTYPE_WINAIM, |
---|
60 | 3, {0x01, 0x01, 0x02}}, |
---|
61 | |
---|
62 | /* WinAIM 4.1.2010, libfaim */ |
---|
63 | { AIM_CLIENTTYPE_WINAIM41, |
---|
64 | 4, {0x01, 0x01, 0x01, 0x02}}, |
---|
65 | |
---|
66 | /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */ |
---|
67 | { AIM_CLIENTTYPE_AOL_TOC, |
---|
68 | 1, {0x01}}, |
---|
69 | |
---|
70 | { 0, 0} |
---|
71 | }; |
---|
72 | int i; |
---|
73 | |
---|
74 | if (!msghdr || (len <= 0)) |
---|
75 | return AIM_CLIENTTYPE_UNKNOWN; |
---|
76 | |
---|
77 | for (i = 0; fingerprints[i].len; i++) { |
---|
78 | if (fingerprints[i].len != len) |
---|
79 | continue; |
---|
80 | if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0) |
---|
81 | return fingerprints[i].clientid; |
---|
82 | } |
---|
83 | |
---|
84 | return AIM_CLIENTTYPE_UNKNOWN; |
---|
85 | } |
---|
86 | |
---|
87 | /* This should be endian-safe now... but who knows... */ |
---|
88 | guint16 aim_iconsum(const guint8 *buf, int buflen) |
---|
89 | { |
---|
90 | guint32 sum; |
---|
91 | int i; |
---|
92 | |
---|
93 | for (i = 0, sum = 0; i + 1 < buflen; i += 2) |
---|
94 | sum += (buf[i+1] << 8) + buf[i]; |
---|
95 | if (i < buflen) |
---|
96 | sum += buf[i]; |
---|
97 | |
---|
98 | sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff); |
---|
99 | |
---|
100 | return (guint16)sum; |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | * Send an ICBM (instant message). |
---|
105 | * |
---|
106 | * |
---|
107 | * Possible flags: |
---|
108 | * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse |
---|
109 | * AIM_IMFLAGS_ACK -- Requests that the server send an ack |
---|
110 | * when the message is received (of type 0x0004/0x000c) |
---|
111 | * AIM_IMFLAGS_OFFLINE--If destination is offline, store it until they are |
---|
112 | * online (probably ICQ only). |
---|
113 | * AIM_IMFLAGS_UNICODE--Instead of ASCII7, the passed message is |
---|
114 | * made up of UNICODE duples. If you set |
---|
115 | * this, you'd better be damn sure you know |
---|
116 | * what you're doing. |
---|
117 | * AIM_IMFLAGS_ISO_8859_1 -- The message contains the ASCII8 subset |
---|
118 | * known as ISO-8859-1. |
---|
119 | * |
---|
120 | * Generally, you should use the lowest encoding possible to send |
---|
121 | * your message. If you only use basic punctuation and the generic |
---|
122 | * Latin alphabet, use ASCII7 (no flags). If you happen to use non-ASCII7 |
---|
123 | * characters, but they are all clearly defined in ISO-8859-1, then |
---|
124 | * use that. Keep in mind that not all characters in the PC ASCII8 |
---|
125 | * character set are defined in the ISO standard. For those cases (most |
---|
126 | * notably when the (r) symbol is used), you must use the full UNICODE |
---|
127 | * encoding for your message. In UNICODE mode, _all_ characters must |
---|
128 | * occupy 16bits, including ones that are not special. (Remember that |
---|
129 | * the first 128 UNICODE symbols are equivelent to ASCII7, however they |
---|
130 | * must be prefixed with a zero high order byte.) |
---|
131 | * |
---|
132 | * I strongly discourage the use of UNICODE mode, mainly because none |
---|
133 | * of the clients I use can parse those messages (and besides that, |
---|
134 | * wchars are difficult and non-portable to handle in most UNIX environments). |
---|
135 | * If you really need to include special characters, use the HTML UNICODE |
---|
136 | * entities. These are of the form ߪ where 2026 is the hex |
---|
137 | * representation of the UNICODE index (in this case, UNICODE |
---|
138 | * "Horizontal Ellipsis", or 133 in in ASCII8). |
---|
139 | * |
---|
140 | * Implementation note: Since this is one of the most-used functions |
---|
141 | * in all of libfaim, it is written with performance in mind. As such, |
---|
142 | * it is not as clear as it could be in respect to how this message is |
---|
143 | * supposed to be layed out. Most obviously, tlvlists should be used |
---|
144 | * instead of writing out the bytes manually. |
---|
145 | * |
---|
146 | * XXX more precise verification that we never send SNACs larger than 8192 |
---|
147 | * XXX check SNAC size for multipart |
---|
148 | * |
---|
149 | */ |
---|
150 | int aim_send_im_ext(aim_session_t *sess, struct aim_sendimext_args *args) |
---|
151 | { |
---|
152 | static const guint8 deffeatures[] = { |
---|
153 | 0x01, 0x01, 0x01, 0x02 |
---|
154 | }; |
---|
155 | aim_conn_t *conn; |
---|
156 | int i, msgtlvlen; |
---|
157 | aim_frame_t *fr; |
---|
158 | aim_snacid_t snacid; |
---|
159 | |
---|
160 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
161 | return -EINVAL; |
---|
162 | |
---|
163 | if (!args) |
---|
164 | return -EINVAL; |
---|
165 | |
---|
166 | if (args->flags & AIM_IMFLAGS_MULTIPART) { |
---|
167 | if (args->mpmsg->numparts <= 0) |
---|
168 | return -EINVAL; |
---|
169 | } else { |
---|
170 | if (!args->msg || (args->msglen <= 0)) |
---|
171 | return -EINVAL; |
---|
172 | |
---|
173 | if (args->msglen >= MAXMSGLEN) |
---|
174 | return -E2BIG; |
---|
175 | } |
---|
176 | |
---|
177 | /* Painfully calculate the size of the message TLV */ |
---|
178 | msgtlvlen = 1 + 1; /* 0501 */ |
---|
179 | |
---|
180 | if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) |
---|
181 | msgtlvlen += 2 + args->featureslen; |
---|
182 | else |
---|
183 | msgtlvlen += 2 + sizeof(deffeatures); |
---|
184 | |
---|
185 | if (args->flags & AIM_IMFLAGS_MULTIPART) { |
---|
186 | aim_mpmsg_section_t *sec; |
---|
187 | |
---|
188 | for (sec = args->mpmsg->parts; sec; sec = sec->next) { |
---|
189 | msgtlvlen += 2 /* 0101 */ + 2 /* block len */; |
---|
190 | msgtlvlen += 4 /* charset */ + sec->datalen; |
---|
191 | } |
---|
192 | |
---|
193 | } else { |
---|
194 | msgtlvlen += 2 /* 0101 */ + 2 /* block len */; |
---|
195 | msgtlvlen += 4 /* charset */ + args->msglen; |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, msgtlvlen+128))) |
---|
200 | return -ENOMEM; |
---|
201 | |
---|
202 | /* XXX should be optional */ |
---|
203 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1); |
---|
204 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
---|
205 | |
---|
206 | /* |
---|
207 | * Generate a random message cookie |
---|
208 | * |
---|
209 | * We could cache these like we do SNAC IDs. (In fact, it |
---|
210 | * might be a good idea.) In the message error functions, |
---|
211 | * the 8byte message cookie is returned as well as the |
---|
212 | * SNAC ID. |
---|
213 | * |
---|
214 | */ |
---|
215 | for (i = 0; i < 8; i++) |
---|
216 | aimbs_put8(&fr->data, (guint8) rand()); |
---|
217 | |
---|
218 | /* |
---|
219 | * Channel ID |
---|
220 | */ |
---|
221 | aimbs_put16(&fr->data, 0x0001); |
---|
222 | |
---|
223 | /* |
---|
224 | * Destination SN (prepended with byte length) |
---|
225 | */ |
---|
226 | aimbs_put8(&fr->data, strlen(args->destsn)); |
---|
227 | aimbs_putraw(&fr->data, (guint8 *)args->destsn, strlen(args->destsn)); |
---|
228 | |
---|
229 | /* |
---|
230 | * Message TLV (type 2). |
---|
231 | */ |
---|
232 | aimbs_put16(&fr->data, 0x0002); |
---|
233 | aimbs_put16(&fr->data, msgtlvlen); |
---|
234 | |
---|
235 | /* |
---|
236 | * Features |
---|
237 | * |
---|
238 | */ |
---|
239 | aimbs_put8(&fr->data, 0x05); |
---|
240 | aimbs_put8(&fr->data, 0x01); |
---|
241 | |
---|
242 | if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) { |
---|
243 | aimbs_put16(&fr->data, args->featureslen); |
---|
244 | aimbs_putraw(&fr->data, args->features, args->featureslen); |
---|
245 | } else { |
---|
246 | aimbs_put16(&fr->data, sizeof(deffeatures)); |
---|
247 | aimbs_putraw(&fr->data, deffeatures, sizeof(deffeatures)); |
---|
248 | } |
---|
249 | |
---|
250 | if (args->flags & AIM_IMFLAGS_MULTIPART) { |
---|
251 | aim_mpmsg_section_t *sec; |
---|
252 | |
---|
253 | for (sec = args->mpmsg->parts; sec; sec = sec->next) { |
---|
254 | aimbs_put16(&fr->data, 0x0101); |
---|
255 | aimbs_put16(&fr->data, sec->datalen + 4); |
---|
256 | aimbs_put16(&fr->data, sec->charset); |
---|
257 | aimbs_put16(&fr->data, sec->charsubset); |
---|
258 | aimbs_putraw(&fr->data, sec->data, sec->datalen); |
---|
259 | } |
---|
260 | |
---|
261 | } else { |
---|
262 | |
---|
263 | aimbs_put16(&fr->data, 0x0101); |
---|
264 | |
---|
265 | /* |
---|
266 | * Message block length. |
---|
267 | */ |
---|
268 | aimbs_put16(&fr->data, args->msglen + 0x04); |
---|
269 | |
---|
270 | /* |
---|
271 | * Character set. |
---|
272 | */ |
---|
273 | if (args->flags & AIM_IMFLAGS_CUSTOMCHARSET) { |
---|
274 | |
---|
275 | aimbs_put16(&fr->data, args->charset); |
---|
276 | aimbs_put16(&fr->data, args->charsubset); |
---|
277 | |
---|
278 | } else { |
---|
279 | if (args->flags & AIM_IMFLAGS_UNICODE) |
---|
280 | aimbs_put16(&fr->data, 0x0002); |
---|
281 | else if (args->flags & AIM_IMFLAGS_ISO_8859_1) |
---|
282 | aimbs_put16(&fr->data, 0x0003); |
---|
283 | else |
---|
284 | aimbs_put16(&fr->data, 0x0000); |
---|
285 | |
---|
286 | aimbs_put16(&fr->data, 0x0000); |
---|
287 | } |
---|
288 | |
---|
289 | /* |
---|
290 | * Message. Not terminated. |
---|
291 | */ |
---|
292 | aimbs_putraw(&fr->data, (guint8 *)args->msg, args->msglen); |
---|
293 | } |
---|
294 | |
---|
295 | /* |
---|
296 | * Set the Request Acknowledge flag. |
---|
297 | */ |
---|
298 | if (args->flags & AIM_IMFLAGS_ACK) { |
---|
299 | aimbs_put16(&fr->data, 0x0003); |
---|
300 | aimbs_put16(&fr->data, 0x0000); |
---|
301 | } |
---|
302 | |
---|
303 | /* |
---|
304 | * Set the Autoresponse flag. |
---|
305 | */ |
---|
306 | if (args->flags & AIM_IMFLAGS_AWAY) { |
---|
307 | aimbs_put16(&fr->data, 0x0004); |
---|
308 | aimbs_put16(&fr->data, 0x0000); |
---|
309 | } |
---|
310 | |
---|
311 | if (args->flags & AIM_IMFLAGS_OFFLINE) { |
---|
312 | aimbs_put16(&fr->data, 0x0006); |
---|
313 | aimbs_put16(&fr->data, 0x0000); |
---|
314 | } |
---|
315 | |
---|
316 | /* |
---|
317 | * Set the I HAVE A REALLY PURTY ICON flag. |
---|
318 | */ |
---|
319 | if (args->flags & AIM_IMFLAGS_HASICON) { |
---|
320 | aimbs_put16(&fr->data, 0x0008); |
---|
321 | aimbs_put16(&fr->data, 0x000c); |
---|
322 | aimbs_put32(&fr->data, args->iconlen); |
---|
323 | aimbs_put16(&fr->data, 0x0001); |
---|
324 | aimbs_put16(&fr->data, args->iconsum); |
---|
325 | aimbs_put32(&fr->data, args->iconstamp); |
---|
326 | } |
---|
327 | |
---|
328 | /* |
---|
329 | * Set the Buddy Icon Requested flag. |
---|
330 | */ |
---|
331 | if (args->flags & AIM_IMFLAGS_BUDDYREQ) { |
---|
332 | aimbs_put16(&fr->data, 0x0009); |
---|
333 | aimbs_put16(&fr->data, 0x0000); |
---|
334 | } |
---|
335 | |
---|
336 | aim_tx_enqueue(sess, fr); |
---|
337 | |
---|
338 | if (!(sess->flags & AIM_SESS_FLAGS_DONTTIMEOUTONICBM)) |
---|
339 | aim_cleansnacs(sess, 60); /* clean out SNACs over 60sec old */ |
---|
340 | |
---|
341 | return 0; |
---|
342 | } |
---|
343 | |
---|
344 | /* |
---|
345 | * Simple wrapper for aim_send_im_ext() |
---|
346 | * |
---|
347 | * You cannot use aim_send_im if you need the HASICON flag. You must |
---|
348 | * use aim_send_im_ext directly for that. |
---|
349 | * |
---|
350 | * aim_send_im also cannot be used if you require UNICODE messages, because |
---|
351 | * that requires an explicit message length. Use aim_send_im_ext(). |
---|
352 | * |
---|
353 | */ |
---|
354 | int aim_send_im(aim_session_t *sess, const char *destsn, guint16 flags, const char *msg) |
---|
355 | { |
---|
356 | struct aim_sendimext_args args; |
---|
357 | |
---|
358 | args.destsn = destsn; |
---|
359 | args.flags = flags; |
---|
360 | args.msg = msg; |
---|
361 | args.msglen = strlen(msg); |
---|
362 | |
---|
363 | /* Make these don't get set by accident -- they need aim_send_im_ext */ |
---|
364 | args.flags &= ~(AIM_IMFLAGS_CUSTOMFEATURES | AIM_IMFLAGS_HASICON | AIM_IMFLAGS_MULTIPART); |
---|
365 | |
---|
366 | return aim_send_im_ext(sess, &args); |
---|
367 | } |
---|
368 | |
---|
369 | /* |
---|
370 | * This is also performance sensitive. (If you can believe it...) |
---|
371 | * |
---|
372 | */ |
---|
373 | int aim_send_icon(aim_session_t *sess, const char *sn, const guint8 *icon, int iconlen, time_t stamp, guint16 iconsum) |
---|
374 | { |
---|
375 | aim_conn_t *conn; |
---|
376 | int i; |
---|
377 | guint8 ck[8]; |
---|
378 | aim_frame_t *fr; |
---|
379 | aim_snacid_t snacid; |
---|
380 | |
---|
381 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
382 | return -EINVAL; |
---|
383 | |
---|
384 | if (!sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN)) |
---|
385 | return -EINVAL; |
---|
386 | |
---|
387 | for (i = 0; i < 8; i++) |
---|
388 | aimutil_put8(ck+i, (guint8) rand()); |
---|
389 | |
---|
390 | 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))) |
---|
391 | return -ENOMEM; |
---|
392 | |
---|
393 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
---|
394 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
---|
395 | |
---|
396 | /* |
---|
397 | * Cookie |
---|
398 | */ |
---|
399 | aimbs_putraw(&fr->data, ck, 8); |
---|
400 | |
---|
401 | /* |
---|
402 | * Channel (2) |
---|
403 | */ |
---|
404 | aimbs_put16(&fr->data, 0x0002); |
---|
405 | |
---|
406 | /* |
---|
407 | * Dest sn |
---|
408 | */ |
---|
409 | aimbs_put8(&fr->data, strlen(sn)); |
---|
410 | aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn)); |
---|
411 | |
---|
412 | /* |
---|
413 | * TLV t(0005) |
---|
414 | * |
---|
415 | * Encompasses everything below. |
---|
416 | */ |
---|
417 | aimbs_put16(&fr->data, 0x0005); |
---|
418 | aimbs_put16(&fr->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT)); |
---|
419 | |
---|
420 | aimbs_put16(&fr->data, 0x0000); |
---|
421 | aimbs_putraw(&fr->data, ck, 8); |
---|
422 | aim_putcap(&fr->data, AIM_CAPS_BUDDYICON); |
---|
423 | |
---|
424 | /* TLV t(000a) */ |
---|
425 | aimbs_put16(&fr->data, 0x000a); |
---|
426 | aimbs_put16(&fr->data, 0x0002); |
---|
427 | aimbs_put16(&fr->data, 0x0001); |
---|
428 | |
---|
429 | /* TLV t(000f) */ |
---|
430 | aimbs_put16(&fr->data, 0x000f); |
---|
431 | aimbs_put16(&fr->data, 0x0000); |
---|
432 | |
---|
433 | /* TLV t(2711) */ |
---|
434 | aimbs_put16(&fr->data, 0x2711); |
---|
435 | aimbs_put16(&fr->data, 4+4+4+iconlen+strlen(AIM_ICONIDENT)); |
---|
436 | aimbs_put16(&fr->data, 0x0000); |
---|
437 | aimbs_put16(&fr->data, iconsum); |
---|
438 | aimbs_put32(&fr->data, iconlen); |
---|
439 | aimbs_put32(&fr->data, stamp); |
---|
440 | aimbs_putraw(&fr->data, icon, iconlen); |
---|
441 | aimbs_putraw(&fr->data, (guint8 *)AIM_ICONIDENT, strlen(AIM_ICONIDENT)); |
---|
442 | |
---|
443 | /* TLV t(0003) */ |
---|
444 | aimbs_put16(&fr->data, 0x0003); |
---|
445 | aimbs_put16(&fr->data, 0x0000); |
---|
446 | |
---|
447 | aim_tx_enqueue(sess, fr); |
---|
448 | |
---|
449 | return 0; |
---|
450 | } |
---|
451 | |
---|
452 | /* |
---|
453 | * This only works for ICQ 2001b (thats 2001 not 2000). Better, only |
---|
454 | * send it to clients advertising the RTF capability. In fact, if you send |
---|
455 | * it to a client that doesn't support that capability, the server will gladly |
---|
456 | * bounce it back to you. |
---|
457 | * |
---|
458 | * You'd think this would be in icq.c, but, well, I'm trying to stick with |
---|
459 | * the one-group-per-file scheme as much as possible. This could easily |
---|
460 | * be an exception, since Rendezvous IMs are external of the Oscar core, |
---|
461 | * and therefore are undefined. Really I just need to think of a good way to |
---|
462 | * make an interface similar to what AOL actually uses. But I'm not using COM. |
---|
463 | * |
---|
464 | */ |
---|
465 | int aim_send_rtfmsg(aim_session_t *sess, struct aim_sendrtfmsg_args *args) |
---|
466 | { |
---|
467 | const char rtfcap[] = {"{97B12751-243C-4334-AD22-D6ABF73F1492}"}; /* AIM_CAPS_ICQRTF capability in string form */ |
---|
468 | aim_conn_t *conn; |
---|
469 | int i; |
---|
470 | guint8 ck[8]; |
---|
471 | aim_frame_t *fr; |
---|
472 | aim_snacid_t snacid; |
---|
473 | int servdatalen; |
---|
474 | |
---|
475 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
476 | return -EINVAL; |
---|
477 | |
---|
478 | if (!args || !args->destsn || !args->rtfmsg) |
---|
479 | return -EINVAL; |
---|
480 | |
---|
481 | servdatalen = 2+2+16+2+4+1+2 + 2+2+4+4+4 + 2+4+2+strlen(args->rtfmsg)+1 + 4+4+4+strlen(rtfcap)+1; |
---|
482 | |
---|
483 | for (i = 0; i < 8; i++) |
---|
484 | aimutil_put8(ck+i, (guint8) rand()); |
---|
485 | |
---|
486 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+128+servdatalen))) |
---|
487 | return -ENOMEM; |
---|
488 | |
---|
489 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
---|
490 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
---|
491 | |
---|
492 | /* |
---|
493 | * Cookie |
---|
494 | */ |
---|
495 | aimbs_putraw(&fr->data, ck, 8); |
---|
496 | |
---|
497 | /* |
---|
498 | * Channel (2) |
---|
499 | */ |
---|
500 | aimbs_put16(&fr->data, 0x0002); |
---|
501 | |
---|
502 | /* |
---|
503 | * Dest sn |
---|
504 | */ |
---|
505 | aimbs_put8(&fr->data, strlen(args->destsn)); |
---|
506 | aimbs_putraw(&fr->data, (guint8 *)args->destsn, strlen(args->destsn)); |
---|
507 | |
---|
508 | /* |
---|
509 | * TLV t(0005) |
---|
510 | * |
---|
511 | * Encompasses everything below. |
---|
512 | */ |
---|
513 | aimbs_put16(&fr->data, 0x0005); |
---|
514 | aimbs_put16(&fr->data, 2+8+16 + 2+2+2 + 2+2 + 2+2+servdatalen); |
---|
515 | |
---|
516 | aimbs_put16(&fr->data, 0x0000); |
---|
517 | aimbs_putraw(&fr->data, ck, 8); |
---|
518 | aim_putcap(&fr->data, AIM_CAPS_ICQSERVERRELAY); |
---|
519 | |
---|
520 | /* |
---|
521 | * t(000a) l(0002) v(0001) |
---|
522 | */ |
---|
523 | aimbs_put16(&fr->data, 0x000a); |
---|
524 | aimbs_put16(&fr->data, 0x0002); |
---|
525 | aimbs_put16(&fr->data, 0x0001); |
---|
526 | |
---|
527 | /* |
---|
528 | * t(000f) l(0000) v() |
---|
529 | */ |
---|
530 | aimbs_put16(&fr->data, 0x000f); |
---|
531 | aimbs_put16(&fr->data, 0x0000); |
---|
532 | |
---|
533 | /* |
---|
534 | * Service Data TLV |
---|
535 | */ |
---|
536 | aimbs_put16(&fr->data, 0x2711); |
---|
537 | aimbs_put16(&fr->data, servdatalen); |
---|
538 | |
---|
539 | aimbs_putle16(&fr->data, 11 + 16 /* 11 + (sizeof CLSID) */); |
---|
540 | aimbs_putle16(&fr->data, 9); |
---|
541 | aim_putcap(&fr->data, AIM_CAPS_EMPTY); |
---|
542 | aimbs_putle16(&fr->data, 0); |
---|
543 | aimbs_putle32(&fr->data, 0); |
---|
544 | aimbs_putle8(&fr->data, 0); |
---|
545 | aimbs_putle16(&fr->data, 0x03ea); /* trid1 */ |
---|
546 | |
---|
547 | aimbs_putle16(&fr->data, 14); |
---|
548 | aimbs_putle16(&fr->data, 0x03eb); /* trid2 */ |
---|
549 | aimbs_putle32(&fr->data, 0); |
---|
550 | aimbs_putle32(&fr->data, 0); |
---|
551 | aimbs_putle32(&fr->data, 0); |
---|
552 | |
---|
553 | aimbs_putle16(&fr->data, 0x0001); |
---|
554 | aimbs_putle32(&fr->data, 0); |
---|
555 | aimbs_putle16(&fr->data, strlen(args->rtfmsg)+1); |
---|
556 | aimbs_putraw(&fr->data, (guint8 *)args->rtfmsg, strlen(args->rtfmsg)+1); |
---|
557 | |
---|
558 | aimbs_putle32(&fr->data, args->fgcolor); |
---|
559 | aimbs_putle32(&fr->data, args->bgcolor); |
---|
560 | aimbs_putle32(&fr->data, strlen(rtfcap)+1); |
---|
561 | aimbs_putraw(&fr->data, (guint8 *)rtfcap, strlen(rtfcap)+1); |
---|
562 | |
---|
563 | aim_tx_enqueue(sess, fr); |
---|
564 | |
---|
565 | return 0; |
---|
566 | } |
---|
567 | |
---|
568 | int aim_request_directim(aim_session_t *sess, const char *destsn, guint8 *ip, guint16 port, guint8 *ckret) |
---|
569 | { |
---|
570 | aim_conn_t *conn; |
---|
571 | guint8 ck[8]; |
---|
572 | aim_frame_t *fr; |
---|
573 | aim_snacid_t snacid; |
---|
574 | aim_tlvlist_t *tl = NULL, *itl = NULL; |
---|
575 | int hdrlen, i; |
---|
576 | guint8 *hdr; |
---|
577 | aim_bstream_t hdrbs; |
---|
578 | |
---|
579 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
580 | return -EINVAL; |
---|
581 | |
---|
582 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(destsn)))) |
---|
583 | return -ENOMEM; |
---|
584 | |
---|
585 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
---|
586 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
---|
587 | |
---|
588 | /* |
---|
589 | * Generate a random message cookie |
---|
590 | * |
---|
591 | * This cookie needs to be alphanumeric and NULL-terminated to be |
---|
592 | * TOC-compatible. |
---|
593 | * |
---|
594 | * XXX have I mentioned these should be generated in msgcookie.c? |
---|
595 | * |
---|
596 | */ |
---|
597 | for (i = 0; i < 7; i++) |
---|
598 | ck[i] = 0x30 + ((guint8) rand() % 10); |
---|
599 | ck[7] = '\0'; |
---|
600 | |
---|
601 | if (ckret) |
---|
602 | memcpy(ckret, ck, 8); |
---|
603 | |
---|
604 | /* Cookie */ |
---|
605 | aimbs_putraw(&fr->data, ck, 8); |
---|
606 | |
---|
607 | /* Channel */ |
---|
608 | aimbs_put16(&fr->data, 0x0002); |
---|
609 | |
---|
610 | /* Destination SN */ |
---|
611 | aimbs_put8(&fr->data, strlen(destsn)); |
---|
612 | aimbs_putraw(&fr->data, (guint8 *)destsn, strlen(destsn)); |
---|
613 | |
---|
614 | aim_addtlvtochain_noval(&tl, 0x0003); |
---|
615 | |
---|
616 | hdrlen = 2+8+16+6+8+6+4; |
---|
617 | hdr = g_malloc(hdrlen); |
---|
618 | aim_bstream_init(&hdrbs, hdr, hdrlen); |
---|
619 | |
---|
620 | aimbs_put16(&hdrbs, 0x0000); |
---|
621 | aimbs_putraw(&hdrbs, ck, 8); |
---|
622 | aim_putcap(&hdrbs, AIM_CAPS_IMIMAGE); |
---|
623 | |
---|
624 | aim_addtlvtochain16(&itl, 0x000a, 0x0001); |
---|
625 | aim_addtlvtochain_raw(&itl, 0x0003, 4, ip); |
---|
626 | aim_addtlvtochain16(&itl, 0x0005, port); |
---|
627 | aim_addtlvtochain_noval(&itl, 0x000f); |
---|
628 | |
---|
629 | aim_writetlvchain(&hdrbs, &itl); |
---|
630 | |
---|
631 | aim_addtlvtochain_raw(&tl, 0x0005, aim_bstream_curpos(&hdrbs), hdr); |
---|
632 | |
---|
633 | aim_writetlvchain(&fr->data, &tl); |
---|
634 | |
---|
635 | g_free(hdr); |
---|
636 | aim_freetlvchain(&itl); |
---|
637 | aim_freetlvchain(&tl); |
---|
638 | |
---|
639 | aim_tx_enqueue(sess, fr); |
---|
640 | |
---|
641 | return 0; |
---|
642 | } |
---|
643 | |
---|
644 | int aim_request_sendfile(aim_session_t *sess, const char *sn, const char *filename, guint16 numfiles, guint32 totsize, guint8 *ip, guint16 port, guint8 *ckret) |
---|
645 | { |
---|
646 | aim_conn_t *conn; |
---|
647 | int i; |
---|
648 | guint8 ck[8]; |
---|
649 | aim_frame_t *fr; |
---|
650 | aim_snacid_t snacid; |
---|
651 | |
---|
652 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
653 | return -EINVAL; |
---|
654 | |
---|
655 | if (!sn || !filename) |
---|
656 | return -EINVAL; |
---|
657 | |
---|
658 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+6+8+6+4+2+2+2+2+4+strlen(filename)+4))) |
---|
659 | return -ENOMEM; |
---|
660 | |
---|
661 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
---|
662 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
---|
663 | |
---|
664 | for (i = 0; i < 7; i++) |
---|
665 | aimutil_put8(ck+i, 0x30 + ((guint8) rand() % 10)); |
---|
666 | ck[7] = '\0'; |
---|
667 | |
---|
668 | if (ckret) |
---|
669 | memcpy(ckret, ck, 8); |
---|
670 | |
---|
671 | /* |
---|
672 | * Cookie |
---|
673 | */ |
---|
674 | aimbs_putraw(&fr->data, ck, 8); |
---|
675 | |
---|
676 | /* |
---|
677 | * Channel (2) |
---|
678 | */ |
---|
679 | aimbs_put16(&fr->data, 0x0002); |
---|
680 | |
---|
681 | /* |
---|
682 | * Dest sn |
---|
683 | */ |
---|
684 | aimbs_put8(&fr->data, strlen(sn)); |
---|
685 | aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn)); |
---|
686 | |
---|
687 | /* |
---|
688 | * TLV t(0005) |
---|
689 | * |
---|
690 | * Encompasses everything below. Gee. |
---|
691 | */ |
---|
692 | aimbs_put16(&fr->data, 0x0005); |
---|
693 | aimbs_put16(&fr->data, 2+8+16+6+8+6+4+2+2+2+2+4+strlen(filename)+4); |
---|
694 | |
---|
695 | aimbs_put16(&fr->data, 0x0000); |
---|
696 | aimbs_putraw(&fr->data, ck, 8); |
---|
697 | aim_putcap(&fr->data, AIM_CAPS_SENDFILE); |
---|
698 | |
---|
699 | /* TLV t(000a) */ |
---|
700 | aimbs_put16(&fr->data, 0x000a); |
---|
701 | aimbs_put16(&fr->data, 0x0002); |
---|
702 | aimbs_put16(&fr->data, 0x0001); |
---|
703 | |
---|
704 | /* TLV t(0003) (IP) */ |
---|
705 | aimbs_put16(&fr->data, 0x0003); |
---|
706 | aimbs_put16(&fr->data, 0x0004); |
---|
707 | aimbs_putraw(&fr->data, ip, 4); |
---|
708 | |
---|
709 | /* TLV t(0005) (port) */ |
---|
710 | aimbs_put16(&fr->data, 0x0005); |
---|
711 | aimbs_put16(&fr->data, 0x0002); |
---|
712 | aimbs_put16(&fr->data, port); |
---|
713 | |
---|
714 | /* TLV t(000f) */ |
---|
715 | aimbs_put16(&fr->data, 0x000f); |
---|
716 | aimbs_put16(&fr->data, 0x0000); |
---|
717 | |
---|
718 | /* TLV t(2711) */ |
---|
719 | aimbs_put16(&fr->data, 0x2711); |
---|
720 | aimbs_put16(&fr->data, 2+2+4+strlen(filename)+4); |
---|
721 | |
---|
722 | /* ? */ |
---|
723 | aimbs_put16(&fr->data, 0x0001); |
---|
724 | aimbs_put16(&fr->data, numfiles); |
---|
725 | aimbs_put32(&fr->data, totsize); |
---|
726 | aimbs_putraw(&fr->data, (guint8 *)filename, strlen(filename)); |
---|
727 | |
---|
728 | /* ? */ |
---|
729 | aimbs_put32(&fr->data, 0x00000000); |
---|
730 | |
---|
731 | aim_tx_enqueue(sess, fr); |
---|
732 | |
---|
733 | return 0; |
---|
734 | } |
---|
735 | |
---|
736 | /** |
---|
737 | * Request the status message of the given ICQ user. |
---|
738 | * |
---|
739 | * @param sess The oscar session. |
---|
740 | * @param sn The UIN of the user of whom you wish to request info. |
---|
741 | * @param type The type of info you wish to request. This should be the current |
---|
742 | * state of the user, as one of the AIM_ICQ_STATE_* defines. |
---|
743 | * @return Return 0 if no errors, otherwise return the error number. |
---|
744 | */ |
---|
745 | int aim_send_im_ch2_geticqmessage(aim_session_t *sess, const char *sn, int type) |
---|
746 | { |
---|
747 | aim_conn_t *conn; |
---|
748 | int i; |
---|
749 | guint8 ck[8]; |
---|
750 | aim_frame_t *fr; |
---|
751 | aim_snacid_t snacid; |
---|
752 | |
---|
753 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !sn) |
---|
754 | return -EINVAL; |
---|
755 | |
---|
756 | for (i = 0; i < 8; i++) |
---|
757 | aimutil_put8(ck+i, (guint8) rand()); |
---|
758 | |
---|
759 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn) + 4+0x5e + 4))) |
---|
760 | return -ENOMEM; |
---|
761 | |
---|
762 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
---|
763 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
---|
764 | |
---|
765 | /* Cookie */ |
---|
766 | aimbs_putraw(&fr->data, ck, 8); |
---|
767 | |
---|
768 | /* Channel (2) */ |
---|
769 | aimbs_put16(&fr->data, 0x0002); |
---|
770 | |
---|
771 | /* Dest sn */ |
---|
772 | aimbs_put8(&fr->data, strlen(sn)); |
---|
773 | aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn)); |
---|
774 | |
---|
775 | /* TLV t(0005) - Encompasses almost everything below. */ |
---|
776 | aimbs_put16(&fr->data, 0x0005); /* T */ |
---|
777 | aimbs_put16(&fr->data, 0x005e); /* L */ |
---|
778 | { /* V */ |
---|
779 | aimbs_put16(&fr->data, 0x0000); |
---|
780 | |
---|
781 | /* Cookie */ |
---|
782 | aimbs_putraw(&fr->data, ck, 8); |
---|
783 | |
---|
784 | /* Put the 16 byte server relay capability */ |
---|
785 | aim_putcap(&fr->data, AIM_CAPS_ICQSERVERRELAY); |
---|
786 | |
---|
787 | /* TLV t(000a) */ |
---|
788 | aimbs_put16(&fr->data, 0x000a); |
---|
789 | aimbs_put16(&fr->data, 0x0002); |
---|
790 | aimbs_put16(&fr->data, 0x0001); |
---|
791 | |
---|
792 | /* TLV t(000f) */ |
---|
793 | aimbs_put16(&fr->data, 0x000f); |
---|
794 | aimbs_put16(&fr->data, 0x0000); |
---|
795 | |
---|
796 | /* TLV t(2711) */ |
---|
797 | aimbs_put16(&fr->data, 0x2711); |
---|
798 | aimbs_put16(&fr->data, 0x0036); |
---|
799 | { /* V */ |
---|
800 | aimbs_putle16(&fr->data, 0x001b); /* L */ |
---|
801 | aimbs_putle16(&fr->data, 0x0008); /* AAA - Protocol version */ |
---|
802 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
803 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
804 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
805 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
806 | aimbs_putle16(&fr->data, 0x0000); /* Unknown */ |
---|
807 | aimbs_putle16(&fr->data, 0x0003); /* Client features? */ |
---|
808 | aimbs_putle16(&fr->data, 0x0000); /* Unknown */ |
---|
809 | aimbs_putle8(&fr->data, 0x00); /* Unkizown */ |
---|
810 | aimbs_putle16(&fr->data, 0xffff); /* Sequence number? XXX - This should decrement by 1 with each request */ |
---|
811 | |
---|
812 | aimbs_putle16(&fr->data, 0x000e); /* L */ |
---|
813 | aimbs_putle16(&fr->data, 0xffff); /* Sequence number? XXX - This should decrement by 1 with each request */ |
---|
814 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
815 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
816 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
817 | |
---|
818 | /* The type of status message being requested */ |
---|
819 | if (type & AIM_ICQ_STATE_CHAT) |
---|
820 | aimbs_putle16(&fr->data, 0x03ec); |
---|
821 | else if(type & AIM_ICQ_STATE_DND) |
---|
822 | aimbs_putle16(&fr->data, 0x03eb); |
---|
823 | else if(type & AIM_ICQ_STATE_OUT) |
---|
824 | aimbs_putle16(&fr->data, 0x03ea); |
---|
825 | else if(type & AIM_ICQ_STATE_BUSY) |
---|
826 | aimbs_putle16(&fr->data, 0x03e9); |
---|
827 | else if(type & AIM_ICQ_STATE_AWAY) |
---|
828 | aimbs_putle16(&fr->data, 0x03e8); |
---|
829 | |
---|
830 | aimbs_putle16(&fr->data, 0x0000); /* Status? */ |
---|
831 | aimbs_putle16(&fr->data, 0x0001); /* Priority of this message? */ |
---|
832 | aimbs_putle16(&fr->data, 0x0001); /* L? */ |
---|
833 | aimbs_putle8(&fr->data, 0x00); /* Null termination? */ |
---|
834 | } /* End TLV t(2711) */ |
---|
835 | } /* End TLV t(0005) */ |
---|
836 | |
---|
837 | /* TLV t(0003) */ |
---|
838 | aimbs_put16(&fr->data, 0x0003); |
---|
839 | aimbs_put16(&fr->data, 0x0000); |
---|
840 | |
---|
841 | aim_tx_enqueue(sess, fr); |
---|
842 | |
---|
843 | return 0; |
---|
844 | } |
---|
845 | |
---|
846 | /** |
---|
847 | * answers status message requests |
---|
848 | * @param sess the oscar session |
---|
849 | * @param sender the guy whos asking |
---|
850 | * @param cookie message id which we are answering for |
---|
851 | * @param message away message |
---|
852 | * @param state our current away state the way icq requests it (0xE8 for away, 0xE9 occupied, ...) |
---|
853 | * @return 0 if no error |
---|
854 | */ |
---|
855 | int aim_send_im_ch2_statusmessage(aim_session_t *sess, const char *sender, const guint8 *cookie, |
---|
856 | const char *message, const guint8 state, const guint16 dc) |
---|
857 | { |
---|
858 | aim_conn_t *conn; |
---|
859 | aim_frame_t *fr; |
---|
860 | aim_snacid_t snacid; |
---|
861 | |
---|
862 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
863 | return -EINVAL; |
---|
864 | |
---|
865 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, |
---|
866 | 10+8+2+1+strlen(sender)+2+0x1d+0x10+9+strlen(message)+1))) |
---|
867 | return -ENOMEM; |
---|
868 | |
---|
869 | snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0); |
---|
870 | aim_putsnac(&fr->data, 0x0004, 0x000b, 0x0000, snacid); |
---|
871 | |
---|
872 | aimbs_putraw(&fr->data, cookie, 8); |
---|
873 | |
---|
874 | aimbs_put16(&fr->data, 0x0002); /* channel */ |
---|
875 | aimbs_put8(&fr->data, strlen(sender)); |
---|
876 | aimbs_putraw(&fr->data, (guint8 *)sender, strlen(sender)); |
---|
877 | |
---|
878 | aimbs_put16(&fr->data, 0x0003); /* reason: channel specific */ |
---|
879 | |
---|
880 | aimbs_putle16(&fr->data, 0x001b); /* length of data SEQ1 */ |
---|
881 | aimbs_putle16(&fr->data, 0x0008); /* protocol version */ |
---|
882 | |
---|
883 | aimbs_putle32(&fr->data, 0x0000); /* no plugin -> 16 times 0x00 */ |
---|
884 | aimbs_putle32(&fr->data, 0x0000); |
---|
885 | aimbs_putle32(&fr->data, 0x0000); |
---|
886 | aimbs_putle32(&fr->data, 0x0000); |
---|
887 | |
---|
888 | aimbs_putle16(&fr->data, 0x0000); /* unknown */ |
---|
889 | aimbs_putle32(&fr->data, 0x0003); /* client features */ |
---|
890 | aimbs_putle8(&fr->data, 0x00); /* unknown */ |
---|
891 | aimbs_putle16(&fr->data, dc); /* Sequence number? XXX - This should decrement by 1 with each request */ |
---|
892 | /* end of SEQ1 */ |
---|
893 | |
---|
894 | aimbs_putle16(&fr->data, 0x000e); /* Length of SEQ2 */ |
---|
895 | aimbs_putle16(&fr->data, dc); /* Sequence number? same as above |
---|
896 | * XXX - This should decrement by 1 with each request */ |
---|
897 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
898 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
899 | aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ |
---|
900 | /* end of SEQ2 */ |
---|
901 | |
---|
902 | /* now for the real fun */ |
---|
903 | aimbs_putle8(&fr->data, state); /* away state */ |
---|
904 | aimbs_putle8(&fr->data, 0x03); /* msg-flag: 03 for states */ |
---|
905 | aimbs_putle16(&fr->data, 0x0000); /* status code ? */ |
---|
906 | aimbs_putle16(&fr->data, 0x0000); /* priority code */ |
---|
907 | aimbs_putle16(&fr->data, strlen(message) + 1); /* message length + termination */ |
---|
908 | aimbs_putraw(&fr->data, (guint8 *) message, strlen(message) + 1); /* null terminated string */ |
---|
909 | |
---|
910 | aim_tx_enqueue(sess, fr); |
---|
911 | |
---|
912 | |
---|
913 | return 0; |
---|
914 | } |
---|
915 | |
---|
916 | |
---|
917 | static int outgoingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
918 | { |
---|
919 | int i, ret = 0; |
---|
920 | aim_rxcallback_t userfunc; |
---|
921 | guint8 cookie[8]; |
---|
922 | guint16 channel; |
---|
923 | aim_tlvlist_t *tlvlist; |
---|
924 | char *sn; |
---|
925 | int snlen; |
---|
926 | guint16 icbmflags = 0; |
---|
927 | guint8 flag1 = 0, flag2 = 0; |
---|
928 | char *msg = NULL; |
---|
929 | aim_tlv_t *msgblock; |
---|
930 | |
---|
931 | /* ICBM Cookie. */ |
---|
932 | for (i = 0; i < 8; i++) |
---|
933 | cookie[i] = aimbs_get8(bs); |
---|
934 | |
---|
935 | /* Channel ID */ |
---|
936 | channel = aimbs_get16(bs); |
---|
937 | |
---|
938 | if (channel != 0x01) { |
---|
939 | imcb_error(sess->aux_data, "icbm: ICBM recieved on unsupported channel. Ignoring."); |
---|
940 | return 0; |
---|
941 | } |
---|
942 | |
---|
943 | snlen = aimbs_get8(bs); |
---|
944 | sn = aimbs_getstr(bs, snlen); |
---|
945 | |
---|
946 | tlvlist = aim_readtlvchain(bs); |
---|
947 | |
---|
948 | if (aim_gettlv(tlvlist, 0x0003, 1)) |
---|
949 | icbmflags |= AIM_IMFLAGS_ACK; |
---|
950 | if (aim_gettlv(tlvlist, 0x0004, 1)) |
---|
951 | icbmflags |= AIM_IMFLAGS_AWAY; |
---|
952 | |
---|
953 | if ((msgblock = aim_gettlv(tlvlist, 0x0002, 1))) { |
---|
954 | aim_bstream_t mbs; |
---|
955 | int featurelen, msglen; |
---|
956 | |
---|
957 | aim_bstream_init(&mbs, msgblock->value, msgblock->length); |
---|
958 | |
---|
959 | aimbs_get8(&mbs); |
---|
960 | aimbs_get8(&mbs); |
---|
961 | for (featurelen = aimbs_get16(&mbs); featurelen; featurelen--) |
---|
962 | aimbs_get8(&mbs); |
---|
963 | aimbs_get8(&mbs); |
---|
964 | aimbs_get8(&mbs); |
---|
965 | |
---|
966 | msglen = aimbs_get16(&mbs) - 4; /* final block length */ |
---|
967 | |
---|
968 | flag1 = aimbs_get16(&mbs); |
---|
969 | flag2 = aimbs_get16(&mbs); |
---|
970 | |
---|
971 | msg = aimbs_getstr(&mbs, msglen); |
---|
972 | } |
---|
973 | |
---|
974 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
975 | ret = userfunc(sess, rx, channel, sn, msg, icbmflags, flag1, flag2); |
---|
976 | |
---|
977 | g_free(sn); |
---|
978 | aim_freetlvchain(&tlvlist); |
---|
979 | |
---|
980 | return ret; |
---|
981 | } |
---|
982 | |
---|
983 | /* |
---|
984 | * Ahh, the joys of nearly ridiculous over-engineering. |
---|
985 | * |
---|
986 | * Not only do AIM ICBM's support multiple channels. Not only do they |
---|
987 | * support multiple character sets. But they support multiple character |
---|
988 | * sets / encodings within the same ICBM. |
---|
989 | * |
---|
990 | * These multipart messages allow for complex space savings techniques, which |
---|
991 | * seem utterly unnecessary by today's standards. In fact, there is only |
---|
992 | * one client still in popular use that still uses this method: AOL for the |
---|
993 | * Macintosh, Version 5.0. Obscure, yes, I know. |
---|
994 | * |
---|
995 | * In modern (non-"legacy") clients, if the user tries to send a character |
---|
996 | * that is not ISO-8859-1 or ASCII, the client will send the entire message |
---|
997 | * as UNICODE, meaning that every character in the message will occupy the |
---|
998 | * full 16 bit UNICODE field, even if the high order byte would be zero. |
---|
999 | * Multipart messages prevent this wasted space by allowing the client to |
---|
1000 | * only send the characters in UNICODE that need to be sent that way, and |
---|
1001 | * the rest of the message can be sent in whatever the native character |
---|
1002 | * set is (probably ASCII). |
---|
1003 | * |
---|
1004 | * An important note is that sections will be displayed in the order that |
---|
1005 | * they appear in the ICBM. There is no facility for merging or rearranging |
---|
1006 | * sections at run time. So if you have, say, ASCII then UNICODE then ASCII, |
---|
1007 | * you must supply two ASCII sections with a UNICODE in the middle, and incur |
---|
1008 | * the associated overhead. |
---|
1009 | * |
---|
1010 | * Normally I would have laughed and given a firm 'no' to supporting this |
---|
1011 | * seldom-used feature, but something is attracting me to it. In the future, |
---|
1012 | * it may be possible to abuse this to send mixed-media messages to other |
---|
1013 | * open source clients (like encryption or something) -- see faimtest for |
---|
1014 | * examples of how to do this. |
---|
1015 | * |
---|
1016 | * I would definitly recommend avoiding this feature unless you really |
---|
1017 | * know what you are doing, and/or you have something neat to do with it. |
---|
1018 | * |
---|
1019 | */ |
---|
1020 | int aim_mpmsg_init(aim_session_t *sess, aim_mpmsg_t *mpm) |
---|
1021 | { |
---|
1022 | |
---|
1023 | memset(mpm, 0, sizeof(aim_mpmsg_t)); |
---|
1024 | |
---|
1025 | return 0; |
---|
1026 | } |
---|
1027 | |
---|
1028 | static int mpmsg_addsection(aim_session_t *sess, aim_mpmsg_t *mpm, guint16 charset, guint16 charsubset, guint8 *data, guint16 datalen) |
---|
1029 | { |
---|
1030 | aim_mpmsg_section_t *sec; |
---|
1031 | |
---|
1032 | if (!(sec = g_new0(aim_mpmsg_section_t,1))) |
---|
1033 | return -1; |
---|
1034 | |
---|
1035 | sec->charset = charset; |
---|
1036 | sec->charsubset = charsubset; |
---|
1037 | sec->data = data; |
---|
1038 | sec->datalen = datalen; |
---|
1039 | sec->next = NULL; |
---|
1040 | |
---|
1041 | if (!mpm->parts) |
---|
1042 | mpm->parts = sec; |
---|
1043 | else { |
---|
1044 | aim_mpmsg_section_t *cur; |
---|
1045 | |
---|
1046 | for (cur = mpm->parts; cur->next; cur = cur->next) |
---|
1047 | ; |
---|
1048 | cur->next = sec; |
---|
1049 | } |
---|
1050 | |
---|
1051 | mpm->numparts++; |
---|
1052 | |
---|
1053 | return 0; |
---|
1054 | } |
---|
1055 | |
---|
1056 | int aim_mpmsg_addraw(aim_session_t *sess, aim_mpmsg_t *mpm, guint16 charset, guint16 charsubset, const guint8 *data, guint16 datalen) |
---|
1057 | { |
---|
1058 | guint8 *dup; |
---|
1059 | |
---|
1060 | if (!(dup = g_malloc(datalen))) |
---|
1061 | return -1; |
---|
1062 | memcpy(dup, data, datalen); |
---|
1063 | |
---|
1064 | if (mpmsg_addsection(sess, mpm, charset, charsubset, dup, datalen) == -1) { |
---|
1065 | g_free(dup); |
---|
1066 | return -1; |
---|
1067 | } |
---|
1068 | |
---|
1069 | return 0; |
---|
1070 | } |
---|
1071 | |
---|
1072 | /* XXX should provide a way of saying ISO-8859-1 specifically */ |
---|
1073 | int aim_mpmsg_addascii(aim_session_t *sess, aim_mpmsg_t *mpm, const char *ascii) |
---|
1074 | { |
---|
1075 | char *dup; |
---|
1076 | |
---|
1077 | if (!(dup = g_strdup(ascii))) |
---|
1078 | return -1; |
---|
1079 | |
---|
1080 | if (mpmsg_addsection(sess, mpm, 0x0000, 0x0000, (guint8 *)dup, (guint16) strlen(ascii)) == -1) { |
---|
1081 | g_free(dup); |
---|
1082 | return -1; |
---|
1083 | } |
---|
1084 | |
---|
1085 | return 0; |
---|
1086 | } |
---|
1087 | |
---|
1088 | int aim_mpmsg_addunicode(aim_session_t *sess, aim_mpmsg_t *mpm, const guint16 *unicode, guint16 unicodelen) |
---|
1089 | { |
---|
1090 | guint8 *buf; |
---|
1091 | aim_bstream_t bs; |
---|
1092 | int i; |
---|
1093 | |
---|
1094 | if (!(buf = g_malloc(unicodelen * 2))) |
---|
1095 | return -1; |
---|
1096 | |
---|
1097 | aim_bstream_init(&bs, buf, unicodelen * 2); |
---|
1098 | |
---|
1099 | /* We assume unicode is in /host/ byte order -- convert to network */ |
---|
1100 | for (i = 0; i < unicodelen; i++) |
---|
1101 | aimbs_put16(&bs, unicode[i]); |
---|
1102 | |
---|
1103 | if (mpmsg_addsection(sess, mpm, 0x0002, 0x0000, buf, aim_bstream_curpos(&bs)) == -1) { |
---|
1104 | g_free(buf); |
---|
1105 | return -1; |
---|
1106 | } |
---|
1107 | |
---|
1108 | return 0; |
---|
1109 | } |
---|
1110 | |
---|
1111 | void aim_mpmsg_free(aim_session_t *sess, aim_mpmsg_t *mpm) |
---|
1112 | { |
---|
1113 | aim_mpmsg_section_t *cur; |
---|
1114 | |
---|
1115 | for (cur = mpm->parts; cur; ) { |
---|
1116 | aim_mpmsg_section_t *tmp; |
---|
1117 | |
---|
1118 | tmp = cur->next; |
---|
1119 | g_free(cur->data); |
---|
1120 | g_free(cur); |
---|
1121 | cur = tmp; |
---|
1122 | } |
---|
1123 | |
---|
1124 | mpm->numparts = 0; |
---|
1125 | mpm->parts = NULL; |
---|
1126 | |
---|
1127 | return; |
---|
1128 | } |
---|
1129 | |
---|
1130 | /* |
---|
1131 | * Start by building the multipart structures, then pick the first |
---|
1132 | * human-readable section and stuff it into args->msg so no one gets |
---|
1133 | * suspicious. |
---|
1134 | * |
---|
1135 | */ |
---|
1136 | static int incomingim_ch1_parsemsgs(aim_session_t *sess, guint8 *data, int len, struct aim_incomingim_ch1_args *args) |
---|
1137 | { |
---|
1138 | static const guint16 charsetpri[] = { |
---|
1139 | 0x0000, /* ASCII first */ |
---|
1140 | 0x0003, /* then ISO-8859-1 */ |
---|
1141 | 0x0002, /* UNICODE as last resort */ |
---|
1142 | }; |
---|
1143 | static const int charsetpricount = 3; |
---|
1144 | int i; |
---|
1145 | aim_bstream_t mbs; |
---|
1146 | aim_mpmsg_section_t *sec; |
---|
1147 | |
---|
1148 | aim_bstream_init(&mbs, data, len); |
---|
1149 | |
---|
1150 | while (aim_bstream_empty(&mbs)) { |
---|
1151 | guint16 msglen, flag1, flag2; |
---|
1152 | char *msgbuf; |
---|
1153 | |
---|
1154 | aimbs_get8(&mbs); /* 01 */ |
---|
1155 | aimbs_get8(&mbs); /* 01 */ |
---|
1156 | |
---|
1157 | /* Message string length, including character set info. */ |
---|
1158 | msglen = aimbs_get16(&mbs); |
---|
1159 | |
---|
1160 | /* Character set info */ |
---|
1161 | flag1 = aimbs_get16(&mbs); |
---|
1162 | flag2 = aimbs_get16(&mbs); |
---|
1163 | |
---|
1164 | /* Message. */ |
---|
1165 | msglen -= 4; |
---|
1166 | |
---|
1167 | /* |
---|
1168 | * For now, we don't care what the encoding is. Just copy |
---|
1169 | * it into a multipart struct and deal with it later. However, |
---|
1170 | * always pad the ending with a NULL. This makes it easier |
---|
1171 | * to treat ASCII sections as strings. It won't matter for |
---|
1172 | * UNICODE or binary data, as you should never read past |
---|
1173 | * the specified data length, which will not include the pad. |
---|
1174 | * |
---|
1175 | * XXX There's an API bug here. For sending, the UNICODE is |
---|
1176 | * given in host byte order (aim_mpmsg_addunicode), but here |
---|
1177 | * the received messages are given in network byte order. |
---|
1178 | * |
---|
1179 | */ |
---|
1180 | msgbuf = aimbs_getstr(&mbs, msglen); |
---|
1181 | mpmsg_addsection(sess, &args->mpmsg, flag1, flag2, (guint8 *)msgbuf, (guint16) msglen); |
---|
1182 | |
---|
1183 | } /* while */ |
---|
1184 | |
---|
1185 | args->icbmflags |= AIM_IMFLAGS_MULTIPART; /* always set */ |
---|
1186 | |
---|
1187 | /* |
---|
1188 | * Clients that support multiparts should never use args->msg, as it |
---|
1189 | * will point to an arbitrary section. |
---|
1190 | * |
---|
1191 | * Here, we attempt to provide clients that do not support multipart |
---|
1192 | * messages with something to look at -- hopefully a human-readable |
---|
1193 | * string. But, failing that, a UNICODE message, or nothing at all. |
---|
1194 | * |
---|
1195 | * Which means that even if args->msg is NULL, it does not mean the |
---|
1196 | * message was blank. |
---|
1197 | * |
---|
1198 | */ |
---|
1199 | for (i = 0; i < charsetpricount; i++) { |
---|
1200 | for (sec = args->mpmsg.parts; sec; sec = sec->next) { |
---|
1201 | |
---|
1202 | if (sec->charset != charsetpri[i]) |
---|
1203 | continue; |
---|
1204 | |
---|
1205 | /* Great. We found one. Fill it in. */ |
---|
1206 | args->charset = sec->charset; |
---|
1207 | args->charsubset = sec->charsubset; |
---|
1208 | args->icbmflags |= AIM_IMFLAGS_CUSTOMCHARSET; |
---|
1209 | |
---|
1210 | /* Set up the simple flags */ |
---|
1211 | if (args->charset == 0x0000) |
---|
1212 | ; /* ASCII */ |
---|
1213 | else if (args->charset == 0x0002) |
---|
1214 | args->icbmflags |= AIM_IMFLAGS_UNICODE; |
---|
1215 | else if (args->charset == 0x0003) |
---|
1216 | args->icbmflags |= AIM_IMFLAGS_ISO_8859_1; |
---|
1217 | else if (args->charset == 0xffff) |
---|
1218 | ; /* no encoding (yeep!) */ |
---|
1219 | |
---|
1220 | if (args->charsubset == 0x0000) |
---|
1221 | ; /* standard subencoding? */ |
---|
1222 | else if (args->charsubset == 0x000b) |
---|
1223 | args->icbmflags |= AIM_IMFLAGS_SUBENC_MACINTOSH; |
---|
1224 | else if (args->charsubset == 0xffff) |
---|
1225 | ; /* no subencoding */ |
---|
1226 | #if 0 |
---|
1227 | /* XXX this isn't really necesary... */ |
---|
1228 | if ( ((args.flag1 != 0x0000) && |
---|
1229 | (args.flag1 != 0x0002) && |
---|
1230 | (args.flag1 != 0x0003) && |
---|
1231 | (args.flag1 != 0xffff)) || |
---|
1232 | ((args.flag2 != 0x0000) && |
---|
1233 | (args.flag2 != 0x000b) && |
---|
1234 | (args.flag2 != 0xffff))) { |
---|
1235 | faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", args.flag1, args.flag2); |
---|
1236 | } |
---|
1237 | #endif |
---|
1238 | |
---|
1239 | args->msg = (char *)sec->data; |
---|
1240 | args->msglen = sec->datalen; |
---|
1241 | |
---|
1242 | return 0; |
---|
1243 | } |
---|
1244 | } |
---|
1245 | |
---|
1246 | /* No human-readable sections found. Oh well. */ |
---|
1247 | args->charset = args->charsubset = 0xffff; |
---|
1248 | args->msg = NULL; |
---|
1249 | args->msglen = 0; |
---|
1250 | |
---|
1251 | return 0; |
---|
1252 | } |
---|
1253 | |
---|
1254 | static int incomingim_ch1(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, guint16 channel, aim_userinfo_t *userinfo, aim_bstream_t *bs, guint8 *cookie) |
---|
1255 | { |
---|
1256 | guint16 type, length; |
---|
1257 | aim_rxcallback_t userfunc; |
---|
1258 | int ret = 0; |
---|
1259 | struct aim_incomingim_ch1_args args; |
---|
1260 | int endpos; |
---|
1261 | |
---|
1262 | memset(&args, 0, sizeof(args)); |
---|
1263 | |
---|
1264 | aim_mpmsg_init(sess, &args.mpmsg); |
---|
1265 | |
---|
1266 | /* |
---|
1267 | * This used to be done using tlvchains. For performance reasons, |
---|
1268 | * I've changed it to process the TLVs in-place. This avoids lots |
---|
1269 | * of per-IM memory allocations. |
---|
1270 | */ |
---|
1271 | while (aim_bstream_empty(bs)) { |
---|
1272 | |
---|
1273 | type = aimbs_get16(bs); |
---|
1274 | length = aimbs_get16(bs); |
---|
1275 | |
---|
1276 | endpos = aim_bstream_curpos(bs) + length; |
---|
1277 | |
---|
1278 | if (type == 0x0002) { /* Message Block */ |
---|
1279 | |
---|
1280 | /* |
---|
1281 | * This TLV consists of the following: |
---|
1282 | * - 0501 -- Unknown |
---|
1283 | * - Features: Don't know how to interpret these |
---|
1284 | * - 0101 -- Unknown |
---|
1285 | * - Message |
---|
1286 | * |
---|
1287 | */ |
---|
1288 | |
---|
1289 | aimbs_get8(bs); /* 05 */ |
---|
1290 | aimbs_get8(bs); /* 01 */ |
---|
1291 | |
---|
1292 | args.featureslen = aimbs_get16(bs); |
---|
1293 | /* XXX XXX this is all evil! */ |
---|
1294 | args.features = bs->data + bs->offset; |
---|
1295 | aim_bstream_advance(bs, args.featureslen); |
---|
1296 | args.icbmflags |= AIM_IMFLAGS_CUSTOMFEATURES; |
---|
1297 | |
---|
1298 | /* |
---|
1299 | * The rest of the TLV contains one or more message |
---|
1300 | * blocks... |
---|
1301 | */ |
---|
1302 | incomingim_ch1_parsemsgs(sess, bs->data + bs->offset /* XXX evil!!! */, length - 2 - 2 - args.featureslen, &args); |
---|
1303 | |
---|
1304 | } else if (type == 0x0003) { /* Server Ack Requested */ |
---|
1305 | |
---|
1306 | args.icbmflags |= AIM_IMFLAGS_ACK; |
---|
1307 | |
---|
1308 | } else if (type == 0x0004) { /* Message is Auto Response */ |
---|
1309 | |
---|
1310 | args.icbmflags |= AIM_IMFLAGS_AWAY; |
---|
1311 | |
---|
1312 | } else if (type == 0x0006) { /* Message was received offline. */ |
---|
1313 | |
---|
1314 | /* XXX not sure if this actually gets sent. */ |
---|
1315 | args.icbmflags |= AIM_IMFLAGS_OFFLINE; |
---|
1316 | |
---|
1317 | } else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */ |
---|
1318 | |
---|
1319 | args.iconlen = aimbs_get32(bs); |
---|
1320 | aimbs_get16(bs); /* 0x0001 */ |
---|
1321 | args.iconsum = aimbs_get16(bs); |
---|
1322 | args.iconstamp = aimbs_get32(bs); |
---|
1323 | |
---|
1324 | /* |
---|
1325 | * This looks to be a client bug. MacAIM 4.3 will |
---|
1326 | * send this tag, but with all zero values, in the |
---|
1327 | * first message of a conversation. This makes no |
---|
1328 | * sense whatsoever, so I'm going to say its a bug. |
---|
1329 | * |
---|
1330 | * You really shouldn't advertise a zero-length icon |
---|
1331 | * anyway. |
---|
1332 | * |
---|
1333 | */ |
---|
1334 | if (args.iconlen) |
---|
1335 | args.icbmflags |= AIM_IMFLAGS_HASICON; |
---|
1336 | |
---|
1337 | } else if (type == 0x0009) { |
---|
1338 | |
---|
1339 | args.icbmflags |= AIM_IMFLAGS_BUDDYREQ; |
---|
1340 | |
---|
1341 | } else if (type == 0x0017) { |
---|
1342 | |
---|
1343 | args.extdatalen = length; |
---|
1344 | args.extdata = aimbs_getraw(bs, args.extdatalen); |
---|
1345 | |
---|
1346 | } else { |
---|
1347 | // imcb_error(sess->aux_data, "Unknown TLV encountered"); |
---|
1348 | } |
---|
1349 | |
---|
1350 | /* |
---|
1351 | * This is here to protect ourselves from ourselves. That |
---|
1352 | * is, if something above doesn't completly parse its value |
---|
1353 | * section, or, worse, overparses it, this will set the |
---|
1354 | * stream where it needs to be in order to land on the next |
---|
1355 | * TLV when the loop continues. |
---|
1356 | * |
---|
1357 | */ |
---|
1358 | aim_bstream_setpos(bs, endpos); |
---|
1359 | } |
---|
1360 | |
---|
1361 | |
---|
1362 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1363 | ret = userfunc(sess, rx, channel, userinfo, &args); |
---|
1364 | |
---|
1365 | aim_mpmsg_free(sess, &args.mpmsg); |
---|
1366 | g_free(args.extdata); |
---|
1367 | |
---|
1368 | return ret; |
---|
1369 | } |
---|
1370 | |
---|
1371 | |
---|
1372 | static void incomingim_ch2_chat_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args) |
---|
1373 | { |
---|
1374 | |
---|
1375 | /* XXX aim_chat_roominfo_free() */ |
---|
1376 | g_free(args->info.chat.roominfo.name); |
---|
1377 | |
---|
1378 | return; |
---|
1379 | } |
---|
1380 | |
---|
1381 | static void incomingim_ch2_chat(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args, aim_bstream_t *servdata) |
---|
1382 | { |
---|
1383 | |
---|
1384 | /* |
---|
1385 | * Chat room info. |
---|
1386 | */ |
---|
1387 | if (servdata) |
---|
1388 | aim_chat_readroominfo(servdata, &args->info.chat.roominfo); |
---|
1389 | |
---|
1390 | args->destructor = (void *)incomingim_ch2_chat_free; |
---|
1391 | |
---|
1392 | return; |
---|
1393 | } |
---|
1394 | |
---|
1395 | static void incomingim_ch2_icqserverrelay_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args) |
---|
1396 | { |
---|
1397 | |
---|
1398 | g_free((char *)args->info.rtfmsg.rtfmsg); |
---|
1399 | |
---|
1400 | return; |
---|
1401 | } |
---|
1402 | |
---|
1403 | /* |
---|
1404 | * The relationship between AIM_CAPS_ICQSERVERRELAY and AIM_CAPS_ICQRTF is |
---|
1405 | * kind of odd. This sends the client ICQRTF since that is all that I've seen |
---|
1406 | * SERVERRELAY used for. |
---|
1407 | * |
---|
1408 | * Note that this is all little-endian. Cringe. |
---|
1409 | * |
---|
1410 | * This cap is used for auto status message replies, too [ft] |
---|
1411 | * |
---|
1412 | */ |
---|
1413 | static void incomingim_ch2_icqserverrelay(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args, aim_bstream_t *servdata) |
---|
1414 | { |
---|
1415 | guint16 hdrlen, msglen, dc; |
---|
1416 | guint8 msgtype, msgflags; |
---|
1417 | guint8 *plugin; |
---|
1418 | int i = 0, tmp = 0; |
---|
1419 | struct im_connection *ic = sess->aux_data; |
---|
1420 | |
---|
1421 | /* at the moment we just can deal with requests, not with cancel or accept */ |
---|
1422 | if (args->status != 0) return; |
---|
1423 | |
---|
1424 | hdrlen = aimbs_getle16(servdata); |
---|
1425 | |
---|
1426 | aim_bstream_advance(servdata, 0x02); /* protocol version */ |
---|
1427 | plugin = aimbs_getraw(servdata, 0x10); /* following data is a message or |
---|
1428 | something plugin specific */ |
---|
1429 | /* as there is no plugin handling, just skip the rest */ |
---|
1430 | aim_bstream_advance(servdata, hdrlen - 0x12); |
---|
1431 | |
---|
1432 | hdrlen = aimbs_getle16(servdata); |
---|
1433 | dc = aimbs_getle16(servdata); /* save the sequence number */ |
---|
1434 | aim_bstream_advance(servdata, hdrlen - 0x02); |
---|
1435 | |
---|
1436 | /* TODO is it a message or something for a plugin? */ |
---|
1437 | for (i = 0; i < 0x10; i++) { |
---|
1438 | tmp |= plugin[i]; |
---|
1439 | } |
---|
1440 | |
---|
1441 | if (!tmp) { /* message follows */ |
---|
1442 | |
---|
1443 | msgtype = aimbs_getle8(servdata); |
---|
1444 | msgflags = aimbs_getle8(servdata); |
---|
1445 | |
---|
1446 | aim_bstream_advance(servdata, 0x04); /* status code and priority code */ |
---|
1447 | |
---|
1448 | msglen = aimbs_getle16(servdata); /* message string length */ |
---|
1449 | args->info.rtfmsg.rtfmsg = aimbs_getstr(servdata, msglen); |
---|
1450 | |
---|
1451 | switch(msgtype) { |
---|
1452 | case AIM_MTYPE_PLAIN: |
---|
1453 | |
---|
1454 | args->info.rtfmsg.fgcolor = aimbs_getle32(servdata); |
---|
1455 | args->info.rtfmsg.bgcolor = aimbs_getle32(servdata); |
---|
1456 | |
---|
1457 | hdrlen = aimbs_getle32(servdata); |
---|
1458 | aim_bstream_advance(servdata, hdrlen); |
---|
1459 | |
---|
1460 | /* XXX This is such a hack. */ |
---|
1461 | args->reqclass = AIM_CAPS_ICQRTF; |
---|
1462 | break; |
---|
1463 | |
---|
1464 | case AIM_MTYPE_AUTOAWAY: |
---|
1465 | case AIM_MTYPE_AUTOBUSY: |
---|
1466 | case AIM_MTYPE_AUTONA: |
---|
1467 | case AIM_MTYPE_AUTODND: |
---|
1468 | case AIM_MTYPE_AUTOFFC: |
---|
1469 | case 0x9c: /* ICQ 5 seems to send this */ |
---|
1470 | aim_send_im_ch2_statusmessage(sess, userinfo->sn, args->cookie, |
---|
1471 | ic->away ? ic->away : "", sess->aim_icq_state, dc); |
---|
1472 | break; |
---|
1473 | |
---|
1474 | } |
---|
1475 | } /* message or plugin specific */ |
---|
1476 | |
---|
1477 | g_free(plugin); |
---|
1478 | args->destructor = (void *)incomingim_ch2_icqserverrelay_free; |
---|
1479 | |
---|
1480 | return; |
---|
1481 | } |
---|
1482 | |
---|
1483 | typedef void (*ch2_args_destructor_t)(aim_session_t *sess, struct aim_incomingim_ch2_args *args); |
---|
1484 | |
---|
1485 | static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, guint16 channel, aim_userinfo_t *userinfo, aim_tlvlist_t *tlvlist, guint8 *cookie) |
---|
1486 | { |
---|
1487 | aim_rxcallback_t userfunc; |
---|
1488 | aim_tlv_t *block1, *servdatatlv; |
---|
1489 | aim_tlvlist_t *list2; |
---|
1490 | struct aim_incomingim_ch2_args args; |
---|
1491 | aim_bstream_t bbs, sdbs, *sdbsptr = NULL; |
---|
1492 | guint8 *cookie2; |
---|
1493 | int ret = 0; |
---|
1494 | |
---|
1495 | char clientip1[30] = {""}; |
---|
1496 | char clientip2[30] = {""}; |
---|
1497 | char verifiedip[30] = {""}; |
---|
1498 | |
---|
1499 | memset(&args, 0, sizeof(args)); |
---|
1500 | |
---|
1501 | /* |
---|
1502 | * There's another block of TLVs embedded in the type 5 here. |
---|
1503 | */ |
---|
1504 | block1 = aim_gettlv(tlvlist, 0x0005, 1); |
---|
1505 | aim_bstream_init(&bbs, block1->value, block1->length); |
---|
1506 | |
---|
1507 | /* |
---|
1508 | * First two bytes represent the status of the connection. |
---|
1509 | * |
---|
1510 | * 0 is a request, 1 is a deny (?), 2 is an accept |
---|
1511 | */ |
---|
1512 | args.status = aimbs_get16(&bbs); |
---|
1513 | |
---|
1514 | /* |
---|
1515 | * Next comes the cookie. Should match the ICBM cookie. |
---|
1516 | */ |
---|
1517 | cookie2 = aimbs_getraw(&bbs, 8); |
---|
1518 | if (memcmp(cookie, cookie2, 8) != 0) |
---|
1519 | imcb_error(sess->aux_data, "rend: warning cookies don't match!"); |
---|
1520 | memcpy(args.cookie, cookie2, 8); |
---|
1521 | g_free(cookie2); |
---|
1522 | |
---|
1523 | /* |
---|
1524 | * The next 16bytes are a capability block so we can |
---|
1525 | * identify what type of rendezvous this is. |
---|
1526 | */ |
---|
1527 | args.reqclass = aim_getcap(sess, &bbs, 0x10); |
---|
1528 | |
---|
1529 | /* |
---|
1530 | * What follows may be TLVs or nothing, depending on the |
---|
1531 | * purpose of the message. |
---|
1532 | * |
---|
1533 | * Ack packets for instance have nothing more to them. |
---|
1534 | */ |
---|
1535 | list2 = aim_readtlvchain(&bbs); |
---|
1536 | |
---|
1537 | /* |
---|
1538 | * IP address from the perspective of the client. |
---|
1539 | */ |
---|
1540 | if (aim_gettlv(list2, 0x0002, 1)) { |
---|
1541 | aim_tlv_t *iptlv; |
---|
1542 | |
---|
1543 | iptlv = aim_gettlv(list2, 0x0002, 1); |
---|
1544 | |
---|
1545 | g_snprintf(clientip1, sizeof(clientip1), "%d.%d.%d.%d", |
---|
1546 | aimutil_get8(iptlv->value+0), |
---|
1547 | aimutil_get8(iptlv->value+1), |
---|
1548 | aimutil_get8(iptlv->value+2), |
---|
1549 | aimutil_get8(iptlv->value+3)); |
---|
1550 | } |
---|
1551 | |
---|
1552 | /* |
---|
1553 | * Secondary IP address from the perspective of the client. |
---|
1554 | */ |
---|
1555 | if (aim_gettlv(list2, 0x0003, 1)) { |
---|
1556 | aim_tlv_t *iptlv; |
---|
1557 | |
---|
1558 | iptlv = aim_gettlv(list2, 0x0003, 1); |
---|
1559 | |
---|
1560 | g_snprintf(clientip2, sizeof(clientip2), "%d.%d.%d.%d", |
---|
1561 | aimutil_get8(iptlv->value+0), |
---|
1562 | aimutil_get8(iptlv->value+1), |
---|
1563 | aimutil_get8(iptlv->value+2), |
---|
1564 | aimutil_get8(iptlv->value+3)); |
---|
1565 | } |
---|
1566 | |
---|
1567 | /* |
---|
1568 | * Verified IP address (from the perspective of Oscar). |
---|
1569 | * |
---|
1570 | * This is added by the server. |
---|
1571 | */ |
---|
1572 | if (aim_gettlv(list2, 0x0004, 1)) { |
---|
1573 | aim_tlv_t *iptlv; |
---|
1574 | |
---|
1575 | iptlv = aim_gettlv(list2, 0x0004, 1); |
---|
1576 | |
---|
1577 | g_snprintf(verifiedip, sizeof(verifiedip), "%d.%d.%d.%d", |
---|
1578 | aimutil_get8(iptlv->value+0), |
---|
1579 | aimutil_get8(iptlv->value+1), |
---|
1580 | aimutil_get8(iptlv->value+2), |
---|
1581 | aimutil_get8(iptlv->value+3)); |
---|
1582 | } |
---|
1583 | |
---|
1584 | /* |
---|
1585 | * Port number for something. |
---|
1586 | */ |
---|
1587 | if (aim_gettlv(list2, 0x0005, 1)) |
---|
1588 | args.port = aim_gettlv16(list2, 0x0005, 1); |
---|
1589 | |
---|
1590 | /* |
---|
1591 | * Error code. |
---|
1592 | */ |
---|
1593 | if (aim_gettlv(list2, 0x000b, 1)) |
---|
1594 | args.errorcode = aim_gettlv16(list2, 0x000b, 1); |
---|
1595 | |
---|
1596 | /* |
---|
1597 | * Invitation message / chat description. |
---|
1598 | */ |
---|
1599 | if (aim_gettlv(list2, 0x000c, 1)) |
---|
1600 | args.msg = aim_gettlv_str(list2, 0x000c, 1); |
---|
1601 | |
---|
1602 | /* |
---|
1603 | * Character set. |
---|
1604 | */ |
---|
1605 | if (aim_gettlv(list2, 0x000d, 1)) |
---|
1606 | args.encoding = aim_gettlv_str(list2, 0x000d, 1); |
---|
1607 | |
---|
1608 | /* |
---|
1609 | * Language. |
---|
1610 | */ |
---|
1611 | if (aim_gettlv(list2, 0x000e, 1)) |
---|
1612 | args.language = aim_gettlv_str(list2, 0x000e, 1); |
---|
1613 | |
---|
1614 | /* Unknown -- two bytes = 0x0001 */ |
---|
1615 | if (aim_gettlv(list2, 0x000a, 1)) |
---|
1616 | ; |
---|
1617 | |
---|
1618 | /* Unknown -- no value */ |
---|
1619 | if (aim_gettlv(list2, 0x000f, 1)) |
---|
1620 | ; |
---|
1621 | |
---|
1622 | if (strlen(clientip1)) |
---|
1623 | args.clientip = (char *)clientip1; |
---|
1624 | if (strlen(clientip2)) |
---|
1625 | args.clientip2 = (char *)clientip2; |
---|
1626 | if (strlen(verifiedip)) |
---|
1627 | args.verifiedip = (char *)verifiedip; |
---|
1628 | |
---|
1629 | /* |
---|
1630 | * This is must be present in PROPOSALs, but will probably not |
---|
1631 | * exist in CANCELs and ACCEPTs. |
---|
1632 | * |
---|
1633 | * Service Data blocks are module-specific in format. |
---|
1634 | */ |
---|
1635 | if ((servdatatlv = aim_gettlv(list2, 0x2711 /* 10001 */, 1))) { |
---|
1636 | |
---|
1637 | aim_bstream_init(&sdbs, servdatatlv->value, servdatatlv->length); |
---|
1638 | sdbsptr = &sdbs; |
---|
1639 | } |
---|
1640 | |
---|
1641 | if (args.reqclass & AIM_CAPS_ICQSERVERRELAY) |
---|
1642 | incomingim_ch2_icqserverrelay(sess, mod, rx, snac, userinfo, &args, sdbsptr); |
---|
1643 | else if (args.reqclass & AIM_CAPS_CHAT) |
---|
1644 | incomingim_ch2_chat(sess, mod, rx, snac, userinfo, &args, sdbsptr); |
---|
1645 | |
---|
1646 | |
---|
1647 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1648 | ret = userfunc(sess, rx, channel, userinfo, &args); |
---|
1649 | |
---|
1650 | |
---|
1651 | if (args.destructor) |
---|
1652 | ((ch2_args_destructor_t)args.destructor)(sess, &args); |
---|
1653 | |
---|
1654 | g_free((char *)args.msg); |
---|
1655 | g_free((char *)args.encoding); |
---|
1656 | g_free((char *)args.language); |
---|
1657 | |
---|
1658 | aim_freetlvchain(&list2); |
---|
1659 | |
---|
1660 | return ret; |
---|
1661 | } |
---|
1662 | |
---|
1663 | static int incomingim_ch4(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, guint16 channel, aim_userinfo_t *userinfo, aim_tlvlist_t *tlvlist, guint8 *cookie) |
---|
1664 | { |
---|
1665 | aim_bstream_t meat; |
---|
1666 | aim_rxcallback_t userfunc; |
---|
1667 | aim_tlv_t *block; |
---|
1668 | struct aim_incomingim_ch4_args args; |
---|
1669 | int ret = 0; |
---|
1670 | |
---|
1671 | /* |
---|
1672 | * Make a bstream for the meaty part. Yum. Meat. |
---|
1673 | */ |
---|
1674 | if (!(block = aim_gettlv(tlvlist, 0x0005, 1))) |
---|
1675 | return -1; |
---|
1676 | aim_bstream_init(&meat, block->value, block->length); |
---|
1677 | |
---|
1678 | args.uin = aimbs_getle32(&meat); |
---|
1679 | args.type = aimbs_getle16(&meat); |
---|
1680 | args.msg = (char *)aimbs_getraw(&meat, aimbs_getle16(&meat)); |
---|
1681 | |
---|
1682 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1683 | ret = userfunc(sess, rx, channel, userinfo, &args); |
---|
1684 | |
---|
1685 | g_free(args.msg); |
---|
1686 | |
---|
1687 | return ret; |
---|
1688 | } |
---|
1689 | |
---|
1690 | /* |
---|
1691 | * It can easily be said that parsing ICBMs is THE single |
---|
1692 | * most difficult thing to do in the in AIM protocol. In |
---|
1693 | * fact, I think I just did say that. |
---|
1694 | * |
---|
1695 | * Below is the best damned solution I've come up with |
---|
1696 | * over the past sixteen months of battling with it. This |
---|
1697 | * can parse both away and normal messages from every client |
---|
1698 | * I have access to. Its not fast, its not clean. But it works. |
---|
1699 | * |
---|
1700 | */ |
---|
1701 | static int incomingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
1702 | { |
---|
1703 | int i, ret = 0; |
---|
1704 | guint8 cookie[8]; |
---|
1705 | guint16 channel; |
---|
1706 | aim_userinfo_t userinfo; |
---|
1707 | |
---|
1708 | memset(&userinfo, 0x00, sizeof(aim_userinfo_t)); |
---|
1709 | |
---|
1710 | /* |
---|
1711 | * Read ICBM Cookie. And throw away. |
---|
1712 | */ |
---|
1713 | for (i = 0; i < 8; i++) |
---|
1714 | cookie[i] = aimbs_get8(bs); |
---|
1715 | |
---|
1716 | /* |
---|
1717 | * Channel ID. |
---|
1718 | * |
---|
1719 | * Channel 0x0001 is the message channel. There are |
---|
1720 | * other channels for things called "rendevous" |
---|
1721 | * which represent chat and some of the other new |
---|
1722 | * features of AIM2/3/3.5. |
---|
1723 | * |
---|
1724 | * Channel 0x0002 is the Rendevous channel, which |
---|
1725 | * is where Chat Invitiations and various client-client |
---|
1726 | * connection negotiations come from. |
---|
1727 | * |
---|
1728 | * Channel 0x0004 is used for ICQ authorization, or |
---|
1729 | * possibly any system notice. |
---|
1730 | * |
---|
1731 | */ |
---|
1732 | channel = aimbs_get16(bs); |
---|
1733 | |
---|
1734 | /* |
---|
1735 | * Extract the standard user info block. |
---|
1736 | * |
---|
1737 | * Note that although this contains TLVs that appear contiguous |
---|
1738 | * with the TLVs read below, they are two different pieces. The |
---|
1739 | * userinfo block contains the number of TLVs that contain user |
---|
1740 | * information, the rest are not even though there is no seperation. |
---|
1741 | * aim_extractuserinfo() returns the number of bytes used by the |
---|
1742 | * userinfo tlvs, so you can start reading the rest of them right |
---|
1743 | * afterward. |
---|
1744 | * |
---|
1745 | * That also means that TLV types can be duplicated between the |
---|
1746 | * userinfo block and the rest of the message, however there should |
---|
1747 | * never be two TLVs of the same type in one block. |
---|
1748 | * |
---|
1749 | */ |
---|
1750 | aim_extractuserinfo(sess, bs, &userinfo); |
---|
1751 | |
---|
1752 | /* |
---|
1753 | * From here on, its depends on what channel we're on. |
---|
1754 | * |
---|
1755 | * Technically all channels have a TLV list have this, however, |
---|
1756 | * for the common channel 1 case, in-place parsing is used for |
---|
1757 | * performance reasons (less memory allocation). |
---|
1758 | */ |
---|
1759 | if (channel == 1) { |
---|
1760 | |
---|
1761 | ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, bs, cookie); |
---|
1762 | |
---|
1763 | } else if (channel == 2) { |
---|
1764 | aim_tlvlist_t *tlvlist; |
---|
1765 | |
---|
1766 | /* |
---|
1767 | * Read block of TLVs (not including the userinfo data). All |
---|
1768 | * further data is derived from what is parsed here. |
---|
1769 | */ |
---|
1770 | tlvlist = aim_readtlvchain(bs); |
---|
1771 | |
---|
1772 | ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie); |
---|
1773 | |
---|
1774 | aim_freetlvchain(&tlvlist); |
---|
1775 | |
---|
1776 | } else if (channel == 4) { |
---|
1777 | aim_tlvlist_t *tlvlist; |
---|
1778 | |
---|
1779 | tlvlist = aim_readtlvchain(bs); |
---|
1780 | ret = incomingim_ch4(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie); |
---|
1781 | aim_freetlvchain(&tlvlist); |
---|
1782 | |
---|
1783 | } else { |
---|
1784 | |
---|
1785 | imcb_error(sess->aux_data, "ICBM received on an unsupported channel. Ignoring."); |
---|
1786 | |
---|
1787 | return 0; |
---|
1788 | } |
---|
1789 | |
---|
1790 | return ret; |
---|
1791 | } |
---|
1792 | |
---|
1793 | /* |
---|
1794 | * Possible codes: |
---|
1795 | * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support" |
---|
1796 | * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer" |
---|
1797 | * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers" |
---|
1798 | * |
---|
1799 | */ |
---|
1800 | int aim_denytransfer(aim_session_t *sess, const char *sender, const guint8 *cookie, guint16 code) |
---|
1801 | { |
---|
1802 | aim_conn_t *conn; |
---|
1803 | aim_frame_t *fr; |
---|
1804 | aim_snacid_t snacid; |
---|
1805 | aim_tlvlist_t *tl = NULL; |
---|
1806 | |
---|
1807 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
1808 | return -EINVAL; |
---|
1809 | |
---|
1810 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6))) |
---|
1811 | return -ENOMEM; |
---|
1812 | |
---|
1813 | snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0); |
---|
1814 | aim_putsnac(&fr->data, 0x0004, 0x000b, 0x0000, snacid); |
---|
1815 | |
---|
1816 | aimbs_putraw(&fr->data, cookie, 8); |
---|
1817 | |
---|
1818 | aimbs_put16(&fr->data, 0x0002); /* channel */ |
---|
1819 | aimbs_put8(&fr->data, strlen(sender)); |
---|
1820 | aimbs_putraw(&fr->data, (guint8 *)sender, strlen(sender)); |
---|
1821 | |
---|
1822 | aim_addtlvtochain16(&tl, 0x0003, code); |
---|
1823 | aim_writetlvchain(&fr->data, &tl); |
---|
1824 | aim_freetlvchain(&tl); |
---|
1825 | |
---|
1826 | aim_tx_enqueue(sess, fr); |
---|
1827 | |
---|
1828 | return 0; |
---|
1829 | } |
---|
1830 | |
---|
1831 | /* |
---|
1832 | * aim_reqicbmparaminfo() |
---|
1833 | * |
---|
1834 | * Request ICBM parameter information. |
---|
1835 | * |
---|
1836 | */ |
---|
1837 | int aim_reqicbmparams(aim_session_t *sess) |
---|
1838 | { |
---|
1839 | aim_conn_t *conn; |
---|
1840 | |
---|
1841 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
1842 | return -EINVAL; |
---|
1843 | |
---|
1844 | return aim_genericreq_n(sess, conn, 0x0004, 0x0004); |
---|
1845 | } |
---|
1846 | |
---|
1847 | /* |
---|
1848 | * |
---|
1849 | * I definitly recommend sending this. If you don't, you'll be stuck |
---|
1850 | * with the rather unreasonable defaults. You don't want those. Send this. |
---|
1851 | * |
---|
1852 | */ |
---|
1853 | int aim_seticbmparam(aim_session_t *sess, struct aim_icbmparameters *params) |
---|
1854 | { |
---|
1855 | aim_conn_t *conn; |
---|
1856 | aim_frame_t *fr; |
---|
1857 | aim_snacid_t snacid; |
---|
1858 | |
---|
1859 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) |
---|
1860 | return -EINVAL; |
---|
1861 | |
---|
1862 | if (!params) |
---|
1863 | return -EINVAL; |
---|
1864 | |
---|
1865 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+16))) |
---|
1866 | return -ENOMEM; |
---|
1867 | |
---|
1868 | snacid = aim_cachesnac(sess, 0x0004, 0x0002, 0x0000, NULL, 0); |
---|
1869 | aim_putsnac(&fr->data, 0x0004, 0x0002, 0x0000, snacid); |
---|
1870 | |
---|
1871 | /* This is read-only (see Parameter Reply). Must be set to zero here. */ |
---|
1872 | aimbs_put16(&fr->data, 0x0000); |
---|
1873 | |
---|
1874 | /* These are all read-write */ |
---|
1875 | aimbs_put32(&fr->data, params->flags); |
---|
1876 | aimbs_put16(&fr->data, params->maxmsglen); |
---|
1877 | aimbs_put16(&fr->data, params->maxsenderwarn); |
---|
1878 | aimbs_put16(&fr->data, params->maxrecverwarn); |
---|
1879 | aimbs_put32(&fr->data, params->minmsginterval); |
---|
1880 | |
---|
1881 | aim_tx_enqueue(sess, fr); |
---|
1882 | |
---|
1883 | return 0; |
---|
1884 | } |
---|
1885 | |
---|
1886 | static int paraminfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
1887 | { |
---|
1888 | struct aim_icbmparameters params; |
---|
1889 | aim_rxcallback_t userfunc; |
---|
1890 | |
---|
1891 | params.maxchan = aimbs_get16(bs); |
---|
1892 | params.flags = aimbs_get32(bs); |
---|
1893 | params.maxmsglen = aimbs_get16(bs); |
---|
1894 | params.maxsenderwarn = aimbs_get16(bs); |
---|
1895 | params.maxrecverwarn = aimbs_get16(bs); |
---|
1896 | params.minmsginterval = aimbs_get32(bs); |
---|
1897 | |
---|
1898 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1899 | return userfunc(sess, rx, ¶ms); |
---|
1900 | |
---|
1901 | return 0; |
---|
1902 | } |
---|
1903 | |
---|
1904 | static int missedcall(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
1905 | { |
---|
1906 | int ret = 0; |
---|
1907 | aim_rxcallback_t userfunc; |
---|
1908 | guint16 channel, nummissed, reason; |
---|
1909 | aim_userinfo_t userinfo; |
---|
1910 | |
---|
1911 | while (aim_bstream_empty(bs)) { |
---|
1912 | |
---|
1913 | channel = aimbs_get16(bs); |
---|
1914 | aim_extractuserinfo(sess, bs, &userinfo); |
---|
1915 | nummissed = aimbs_get16(bs); |
---|
1916 | reason = aimbs_get16(bs); |
---|
1917 | |
---|
1918 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1919 | ret = userfunc(sess, rx, channel, &userinfo, nummissed, reason); |
---|
1920 | } |
---|
1921 | |
---|
1922 | return ret; |
---|
1923 | } |
---|
1924 | |
---|
1925 | /* |
---|
1926 | * Receive the response from an ICQ status message request. This contains the |
---|
1927 | * ICQ status message. Go figure. |
---|
1928 | */ |
---|
1929 | static int clientautoresp(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
1930 | { |
---|
1931 | int ret = 0; |
---|
1932 | aim_rxcallback_t userfunc; |
---|
1933 | guint16 channel, reason; |
---|
1934 | char *sn; |
---|
1935 | guint8 *ck, snlen; |
---|
1936 | |
---|
1937 | ck = aimbs_getraw(bs, 8); |
---|
1938 | channel = aimbs_get16(bs); |
---|
1939 | snlen = aimbs_get8(bs); |
---|
1940 | sn = aimbs_getstr(bs, snlen); |
---|
1941 | reason = aimbs_get16(bs); |
---|
1942 | |
---|
1943 | switch (reason) { |
---|
1944 | case 0x0003: { /* ICQ status message. Maybe other stuff too, you never know with these people. */ |
---|
1945 | guint8 statusmsgtype, *msg; |
---|
1946 | guint16 len; |
---|
1947 | guint32 state; |
---|
1948 | |
---|
1949 | len = aimbs_getle16(bs); /* Should be 0x001b */ |
---|
1950 | aim_bstream_advance(bs, len); /* Unknown */ |
---|
1951 | |
---|
1952 | len = aimbs_getle16(bs); /* Should be 0x000e */ |
---|
1953 | aim_bstream_advance(bs, len); /* Unknown */ |
---|
1954 | |
---|
1955 | statusmsgtype = aimbs_getle8(bs); |
---|
1956 | switch (statusmsgtype) { |
---|
1957 | case 0xe8: |
---|
1958 | state = AIM_ICQ_STATE_AWAY; |
---|
1959 | break; |
---|
1960 | case 0xe9: |
---|
1961 | state = AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_BUSY; |
---|
1962 | break; |
---|
1963 | case 0xea: |
---|
1964 | state = AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_OUT; |
---|
1965 | break; |
---|
1966 | case 0xeb: |
---|
1967 | state = AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_DND | AIM_ICQ_STATE_BUSY; |
---|
1968 | break; |
---|
1969 | case 0xec: |
---|
1970 | state = AIM_ICQ_STATE_CHAT; |
---|
1971 | break; |
---|
1972 | default: |
---|
1973 | state = 0; |
---|
1974 | break; |
---|
1975 | } |
---|
1976 | |
---|
1977 | aimbs_getle8(bs); /* Unknown - 0x03 Maybe this means this is an auto-reply */ |
---|
1978 | aimbs_getle16(bs); /* Unknown - 0x0000 */ |
---|
1979 | aimbs_getle16(bs); /* Unknown - 0x0000 */ |
---|
1980 | |
---|
1981 | len = aimbs_getle16(bs); |
---|
1982 | msg = aimbs_getraw(bs, len); |
---|
1983 | |
---|
1984 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1985 | ret = userfunc(sess, rx, channel, sn, reason, state, msg); |
---|
1986 | |
---|
1987 | g_free(msg); |
---|
1988 | } break; |
---|
1989 | |
---|
1990 | default: { |
---|
1991 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
1992 | ret = userfunc(sess, rx, channel, sn, reason); |
---|
1993 | } break; |
---|
1994 | } /* end switch */ |
---|
1995 | |
---|
1996 | g_free(ck); |
---|
1997 | g_free(sn); |
---|
1998 | |
---|
1999 | return ret; |
---|
2000 | } |
---|
2001 | |
---|
2002 | static int msgack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
2003 | { |
---|
2004 | aim_rxcallback_t userfunc; |
---|
2005 | guint16 type; |
---|
2006 | guint8 snlen, *ck; |
---|
2007 | char *sn; |
---|
2008 | int ret = 0; |
---|
2009 | |
---|
2010 | ck = aimbs_getraw(bs, 8); |
---|
2011 | type = aimbs_get16(bs); |
---|
2012 | snlen = aimbs_get8(bs); |
---|
2013 | sn = aimbs_getstr(bs, snlen); |
---|
2014 | |
---|
2015 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
2016 | ret = userfunc(sess, rx, type, sn); |
---|
2017 | |
---|
2018 | g_free(sn); |
---|
2019 | g_free(ck); |
---|
2020 | |
---|
2021 | return ret; |
---|
2022 | } |
---|
2023 | |
---|
2024 | /* |
---|
2025 | * Subtype 0x0014 - Send a mini typing notification (mtn) packet. |
---|
2026 | * |
---|
2027 | * This is supported by winaim5 and newer, MacAIM bleh and newer, iChat bleh and newer, |
---|
2028 | * and Gaim 0.60 and newer. |
---|
2029 | * |
---|
2030 | */ |
---|
2031 | int aim_im_sendmtn(aim_session_t *sess, guint16 type1, const char *sn, guint16 type2) |
---|
2032 | { |
---|
2033 | aim_conn_t *conn; |
---|
2034 | aim_frame_t *fr; |
---|
2035 | aim_snacid_t snacid; |
---|
2036 | |
---|
2037 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0002))) |
---|
2038 | return -EINVAL; |
---|
2039 | |
---|
2040 | if (!sn) |
---|
2041 | return -EINVAL; |
---|
2042 | |
---|
2043 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+11+strlen(sn)+2))) |
---|
2044 | return -ENOMEM; |
---|
2045 | |
---|
2046 | snacid = aim_cachesnac(sess, 0x0004, 0x0014, 0x0000, NULL, 0); |
---|
2047 | aim_putsnac(&fr->data, 0x0004, 0x0014, 0x0000, snacid); |
---|
2048 | |
---|
2049 | /* |
---|
2050 | * 8 days of light |
---|
2051 | * Er, that is to say, 8 bytes of 0's |
---|
2052 | */ |
---|
2053 | aimbs_put16(&fr->data, 0x0000); |
---|
2054 | aimbs_put16(&fr->data, 0x0000); |
---|
2055 | aimbs_put16(&fr->data, 0x0000); |
---|
2056 | aimbs_put16(&fr->data, 0x0000); |
---|
2057 | |
---|
2058 | /* |
---|
2059 | * Type 1 (should be 0x0001 for mtn) |
---|
2060 | */ |
---|
2061 | aimbs_put16(&fr->data, type1); |
---|
2062 | |
---|
2063 | /* |
---|
2064 | * Dest sn |
---|
2065 | */ |
---|
2066 | aimbs_put8(&fr->data, strlen(sn)); |
---|
2067 | aimbs_putraw(&fr->data, (const guint8*)sn, strlen(sn)); |
---|
2068 | |
---|
2069 | /* |
---|
2070 | * Type 2 (should be 0x0000, 0x0001, or 0x0002 for mtn) |
---|
2071 | */ |
---|
2072 | aimbs_put16(&fr->data, type2); |
---|
2073 | |
---|
2074 | aim_tx_enqueue(sess, fr); |
---|
2075 | |
---|
2076 | return 0; |
---|
2077 | } |
---|
2078 | |
---|
2079 | /* |
---|
2080 | * Subtype 0x0014 - Receive a mini typing notification (mtn) packet. |
---|
2081 | * |
---|
2082 | * This is supported by winaim5 and newer, MacAIM bleh and newer, iChat bleh and newer, |
---|
2083 | * and Gaim 0.60 and newer. |
---|
2084 | * |
---|
2085 | */ |
---|
2086 | static int mtn_receive(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
2087 | { |
---|
2088 | int ret = 0; |
---|
2089 | aim_rxcallback_t userfunc; |
---|
2090 | char *sn; |
---|
2091 | guint8 snlen; |
---|
2092 | guint16 type1, type2; |
---|
2093 | |
---|
2094 | aim_bstream_advance(bs, 8); /* Unknown - All 0's */ |
---|
2095 | type1 = aimbs_get16(bs); |
---|
2096 | snlen = aimbs_get8(bs); |
---|
2097 | sn = aimbs_getstr(bs, snlen); |
---|
2098 | type2 = aimbs_get16(bs); |
---|
2099 | |
---|
2100 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
2101 | ret = userfunc(sess, rx, type1, sn, type2); |
---|
2102 | |
---|
2103 | g_free(sn); |
---|
2104 | |
---|
2105 | return ret; |
---|
2106 | } |
---|
2107 | |
---|
2108 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
2109 | { |
---|
2110 | |
---|
2111 | if (snac->subtype == 0x0005) |
---|
2112 | return paraminfo(sess, mod, rx, snac, bs); |
---|
2113 | else if (snac->subtype == 0x0006) |
---|
2114 | return outgoingim(sess, mod, rx, snac, bs); |
---|
2115 | else if (snac->subtype == 0x0007) |
---|
2116 | return incomingim(sess, mod, rx, snac, bs); |
---|
2117 | else if (snac->subtype == 0x000a) |
---|
2118 | return missedcall(sess, mod, rx, snac, bs); |
---|
2119 | else if (snac->subtype == 0x000b) |
---|
2120 | return clientautoresp(sess, mod, rx, snac, bs); |
---|
2121 | else if (snac->subtype == 0x000c) |
---|
2122 | return msgack(sess, mod, rx, snac, bs); |
---|
2123 | else if (snac->subtype == 0x0014) |
---|
2124 | return mtn_receive(sess, mod, rx, snac, bs); |
---|
2125 | |
---|
2126 | return 0; |
---|
2127 | } |
---|
2128 | |
---|
2129 | int msg_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
2130 | { |
---|
2131 | |
---|
2132 | mod->family = 0x0004; |
---|
2133 | mod->version = 0x0001; |
---|
2134 | mod->toolid = 0x0110; |
---|
2135 | mod->toolversion = 0x0629; |
---|
2136 | mod->flags = 0; |
---|
2137 | strncpy(mod->name, "messaging", sizeof(mod->name)); |
---|
2138 | mod->snachandler = snachandler; |
---|
2139 | |
---|
2140 | return 0; |
---|
2141 | } |
---|