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