13234
|
1 /*
|
|
2 * Gaim's oscar protocol plugin
|
|
3 * This file is the legal property of its developers.
|
|
4 * Please see the AUTHORS file distributed alongside this file.
|
|
5 *
|
|
6 * This library is free software; you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU Lesser General Public
|
|
8 * License as published by the Free Software Foundation; either
|
|
9 * version 2 of the License, or (at your option) any later version.
|
|
10 *
|
|
11 * This library is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * Lesser General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU Lesser General Public
|
|
17 * License along with this library; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 */
|
|
20
|
|
21 /*
|
|
22 * Family 0x0004 - Routines for sending/receiving Instant Messages.
|
|
23 *
|
|
24 * Note the term ICBM (Inter-Client Basic Message) which blankets
|
|
25 * all types of generically routed through-server messages. Within
|
|
26 * the ICBM types (family 4), a channel is defined. Each channel
|
|
27 * represents a different type of message. Channel 1 is used for
|
|
28 * what would commonly be called an "instant message". Channel 2
|
|
29 * is used for negotiating "rendezvous". These transactions end in
|
|
30 * something more complex happening, such as a chat invitation, or
|
|
31 * a file transfer. Channel 3 is used for chat messages (not in
|
|
32 * the same family as these channels). Channel 4 is used for
|
|
33 * various ICQ messages. Examples are normal messages, URLs, and
|
|
34 * old-style authorization.
|
|
35 *
|
|
36 * In addition to the channel, every ICBM contains a cookie. For
|
|
37 * standard IMs, these are only used for error messages. However,
|
|
38 * the more complex rendezvous messages make suitably more complex
|
|
39 * use of this field.
|
|
40 *
|
|
41 * TODO: Split this up into an im.c file an an icbm.c file. It
|
|
42 * will be beautiful, you'll see.
|
|
43 *
|
13592
|
44 * Make sure flap_connection_findbygroup is used by all functions.
|
13234
|
45 */
|
|
46
|
|
47 #include "oscar.h"
|
|
48 #include "peer.h"
|
|
49
|
|
50 #ifdef _WIN32
|
|
51 #include "win32dep.h"
|
|
52 #endif
|
|
53
|
|
54 /**
|
|
55 * Add a standard ICBM header to the given bstream with the given
|
|
56 * information.
|
|
57 *
|
|
58 * @param bs The bstream to write the ICBM header to.
|
|
59 * @param c c is for cookie, and cookie is for me.
|
|
60 * @param channel The ICBM channel (1 through 4).
|
|
61 * @param sn Null-terminated scrizeen nizame.
|
|
62 * @return The number of bytes written. It's really not useful.
|
|
63 */
|
13239
|
64 static int aim_im_puticbm(ByteStream *bs, const guchar *c, guint16 channel, const char *sn)
|
13234
|
65 {
|
13592
|
66 byte_stream_putraw(bs, c, 8);
|
|
67 byte_stream_put16(bs, channel);
|
|
68 byte_stream_put8(bs, strlen(sn));
|
|
69 byte_stream_putstr(bs, sn);
|
13234
|
70 return 8+2+1+strlen(sn);
|
|
71 }
|
|
72
|
13592
|
73 /**
|
13234
|
74 * Generates a random ICBM cookie in a character array of length 8
|
|
75 * and copies it into the variable passed as cookie
|
13592
|
76 * TODO: Maybe we should stop limiting our characters to the visible range?
|
13234
|
77 */
|
13592
|
78 void aim_icbm_makecookie(guchar *cookie)
|
13234
|
79 {
|
|
80 int i;
|
|
81
|
|
82 /* Should be like "21CBF95" and null terminated */
|
|
83 for (i = 0; i < 7; i++)
|
|
84 cookie[i] = 0x30 + ((guchar)rand() % 10);
|
|
85 cookie[7] = '\0';
|
|
86 }
|
|
87
|
|
88 /*
|
|
89 * Takes a msghdr (and a length) and returns a client type
|
|
90 * code. Note that this is *only a guess* and has a low likelihood
|
|
91 * of actually being accurate.
|
|
92 *
|
|
93 * Its based on experimental data, with the help of Eric Warmenhoven
|
|
94 * who seems to have collected a wide variety of different AIM clients.
|
|
95 *
|
|
96 *
|
|
97 * Heres the current collection:
|
|
98 * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414
|
|
99 * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464,
|
|
100 * 4.3.2229, 4.4.2286
|
|
101 * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here)
|
|
102 * 0501 0003 0101 02 WinAIM 5
|
|
103 * 0501 0001 01 iChat x.x, mobile buddies
|
|
104 * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any TOC client
|
|
105 * 0501 0002 0106 WinICQ 5.45.1.3777.85
|
|
106 *
|
|
107 * Note that in this function, only the feature bytes are tested, since
|
|
108 * the rest will always be the same.
|
|
109 *
|
|
110 */
|
13592
|
111 guint16 aim_im_fingerprint(const guint8 *msghdr, int len)
|
13234
|
112 {
|
|
113 static const struct {
|
|
114 guint16 clientid;
|
|
115 int len;
|
|
116 guint8 data[10];
|
|
117 } fingerprints[] = {
|
|
118 /* AOL Mobile Communicator, WinAIM 1.0.414 */
|
|
119 { AIM_CLIENTTYPE_MC,
|
|
120 3, {0x01, 0x01, 0x01}},
|
|
121
|
|
122 /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
|
|
123 { AIM_CLIENTTYPE_WINAIM,
|
|
124 3, {0x01, 0x01, 0x02}},
|
|
125
|
|
126 /* WinAIM 4.1.2010, libfaim */
|
|
127 { AIM_CLIENTTYPE_WINAIM41,
|
|
128 4, {0x01, 0x01, 0x01, 0x02}},
|
|
129
|
|
130 /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
|
|
131 { AIM_CLIENTTYPE_AOL_TOC,
|
|
132 1, {0x01}},
|
|
133
|
|
134 { 0, 0, {0x00}}
|
|
135 };
|
|
136 int i;
|
|
137
|
|
138 if (!msghdr || (len <= 0))
|
|
139 return AIM_CLIENTTYPE_UNKNOWN;
|
|
140
|
|
141 for (i = 0; fingerprints[i].len; i++) {
|
|
142 if (fingerprints[i].len != len)
|
|
143 continue;
|
|
144 if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
|
|
145 return fingerprints[i].clientid;
|
|
146 }
|
|
147
|
|
148 return AIM_CLIENTTYPE_UNKNOWN;
|
|
149 }
|
|
150
|
|
151 /**
|
|
152 * Subtype 0x0002 - Set ICBM parameters.
|
|
153 *
|
|
154 * I definitely recommend sending this. If you don't, you'll be stuck
|
|
155 * with the rather unreasonable defaults.
|
|
156 *
|
|
157 */
|
13592
|
158 int aim_im_setparams(OscarData *od, struct aim_icbmparameters *params)
|
13234
|
159 {
|
13592
|
160 FlapConnection *conn;
|
|
161 FlapFrame *frame;
|
13234
|
162 aim_snacid_t snacid;
|
|
163
|
13592
|
164 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
165 return -EINVAL;
|
|
166
|
|
167 if (!params)
|
|
168 return -EINVAL;
|
|
169
|
13592
|
170 frame = flap_frame_new(od, 0x02, 10+16);
|
|
171
|
|
172 snacid = aim_cachesnac(od, 0x0004, 0x0002, 0x0000, NULL, 0);
|
|
173 aim_putsnac(&frame->data, 0x0004, 0x0002, 0x0000, snacid);
|
13234
|
174
|
|
175 /* This is read-only (see Parameter Reply). Must be set to zero here. */
|
13592
|
176 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
177
|
|
178 /* These are all read-write */
|
13592
|
179 byte_stream_put32(&frame->data, params->flags);
|
|
180 byte_stream_put16(&frame->data, params->maxmsglen);
|
|
181 byte_stream_put16(&frame->data, params->maxsenderwarn);
|
|
182 byte_stream_put16(&frame->data, params->maxrecverwarn);
|
|
183 byte_stream_put32(&frame->data, params->minmsginterval);
|
|
184
|
|
185 flap_connection_send(conn, frame);
|
13234
|
186
|
|
187 return 0;
|
|
188 }
|
|
189
|
|
190 /**
|
|
191 * Subtype 0x0004 - Request ICBM parameter information.
|
|
192 *
|
|
193 */
|
13592
|
194 int aim_im_reqparams(OscarData *od)
|
13234
|
195 {
|
13592
|
196 FlapConnection *conn;
|
|
197
|
|
198 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
199 return -EINVAL;
|
|
200
|
13592
|
201 return aim_genericreq_n_snacid(od, conn, 0x0004, 0x0004);
|
13234
|
202 }
|
|
203
|
|
204 /**
|
|
205 * Subtype 0x0005 - Receive parameter information.
|
|
206 *
|
|
207 */
|
13592
|
208 static int aim_im_paraminfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
209 {
|
|
210 aim_rxcallback_t userfunc;
|
|
211 struct aim_icbmparameters params;
|
|
212
|
13592
|
213 params.maxchan = byte_stream_get16(bs);
|
|
214 params.flags = byte_stream_get32(bs);
|
|
215 params.maxmsglen = byte_stream_get16(bs);
|
|
216 params.maxsenderwarn = byte_stream_get16(bs);
|
|
217 params.maxrecverwarn = byte_stream_get16(bs);
|
|
218 params.minmsginterval = byte_stream_get32(bs);
|
|
219
|
|
220 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
221 return userfunc(od, conn, frame, ¶ms);
|
13234
|
222
|
|
223 return 0;
|
|
224 }
|
|
225
|
|
226 /**
|
|
227 * Subtype 0x0006 - Send an ICBM (instant message).
|
|
228 *
|
|
229 *
|
|
230 * Possible flags:
|
|
231 * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
|
|
232 * AIM_IMFLAGS_ACK -- Requests that the server send an ack
|
|
233 * when the message is received (of type 0x0004/0x000c)
|
|
234 * AIM_IMFLAGS_OFFLINE--If destination is offline, store it until they are
|
|
235 * online (probably ICQ only).
|
|
236 *
|
|
237 * Generally, you should use the lowest encoding possible to send
|
|
238 * your message. If you only use basic punctuation and the generic
|
|
239 * Latin alphabet, use ASCII7 (no flags). If you happen to use non-ASCII7
|
|
240 * characters, but they are all clearly defined in ISO-8859-1, then
|
|
241 * use that. Keep in mind that not all characters in the PC ASCII8
|
|
242 * character set are defined in the ISO standard. For those cases (most
|
|
243 * notably when the (r) symbol is used), you must use the full UNICODE
|
|
244 * encoding for your message. In UNICODE mode, _all_ characters must
|
|
245 * occupy 16bits, including ones that are not special. (Remember that
|
|
246 * the first 128 UNICODE symbols are equivalent to ASCII7, however they
|
|
247 * must be prefixed with a zero high order byte.)
|
|
248 *
|
|
249 * I strongly discourage the use of UNICODE mode, mainly because none
|
|
250 * of the clients I use can parse those messages (and besides that,
|
|
251 * wchars are difficult and non-portable to handle in most UNIX environments).
|
|
252 * If you really need to include special characters, use the HTML UNICODE
|
|
253 * entities. These are of the form ߪ where 2026 is the hex
|
|
254 * representation of the UNICODE index (in this case, UNICODE
|
|
255 * "Horizontal Ellipsis", or 133 in in ASCII8).
|
|
256 *
|
|
257 * Implementation note: Since this is one of the most-used functions
|
|
258 * in all of libfaim, it is written with performance in mind. As such,
|
|
259 * it is not as clear as it could be in respect to how this message is
|
|
260 * supposed to be layed out. Most obviously, tlvlists should be used
|
|
261 * instead of writing out the bytes manually.
|
|
262 *
|
|
263 * XXX - more precise verification that we never send SNACs larger than 8192
|
|
264 * XXX - check SNAC size for multipart
|
|
265 *
|
|
266 */
|
13592
|
267 int aim_im_sendch1_ext(OscarData *od, struct aim_sendimext_args *args)
|
13234
|
268 {
|
13592
|
269 FlapConnection *conn;
|
|
270 FlapFrame *frame;
|
13234
|
271 aim_snacid_t snacid;
|
|
272 guchar cookie[8];
|
|
273 int msgtlvlen;
|
|
274 static const guint8 deffeatures[] = { 0x01, 0x01, 0x01, 0x02 };
|
|
275
|
13592
|
276 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
277 return -EINVAL;
|
|
278
|
|
279 if (!args)
|
|
280 return -EINVAL;
|
|
281
|
|
282 if (args->flags & AIM_IMFLAGS_MULTIPART) {
|
|
283 if (args->mpmsg->numparts == 0)
|
|
284 return -EINVAL;
|
|
285 } else {
|
|
286 if (!args->msg || (args->msglen <= 0))
|
|
287 return -EINVAL;
|
|
288
|
|
289 if (args->msglen >= MAXMSGLEN)
|
|
290 return -E2BIG;
|
|
291 }
|
|
292
|
|
293 /* Painfully calculate the size of the message TLV */
|
|
294 msgtlvlen = 1 + 1; /* 0501 */
|
|
295
|
|
296 if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES)
|
|
297 msgtlvlen += 2 + args->featureslen;
|
|
298 else
|
|
299 msgtlvlen += 2 + sizeof(deffeatures);
|
|
300
|
|
301 if (args->flags & AIM_IMFLAGS_MULTIPART) {
|
|
302 aim_mpmsg_section_t *sec;
|
|
303
|
|
304 for (sec = args->mpmsg->parts; sec; sec = sec->next) {
|
|
305 msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
|
|
306 msgtlvlen += 4 /* charset */ + sec->datalen;
|
|
307 }
|
|
308
|
|
309 } else {
|
|
310 msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
|
|
311 msgtlvlen += 4 /* charset */ + args->msglen;
|
|
312 }
|
|
313
|
13592
|
314 frame = flap_frame_new(od, 0x02, msgtlvlen+128);
|
13234
|
315
|
|
316 /* XXX - should be optional */
|
13592
|
317 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
|
|
318 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
319
|
|
320 /* Generate an ICBM cookie */
|
|
321 aim_icbm_makecookie(cookie);
|
|
322
|
|
323 /* ICBM header */
|
13592
|
324 aim_im_puticbm(&frame->data, cookie, 0x0001, args->destsn);
|
13234
|
325
|
|
326 /* Message TLV (type 0x0002) */
|
13592
|
327 byte_stream_put16(&frame->data, 0x0002);
|
|
328 byte_stream_put16(&frame->data, msgtlvlen);
|
13234
|
329
|
|
330 /* Features TLV (type 0x0501) */
|
13592
|
331 byte_stream_put16(&frame->data, 0x0501);
|
13234
|
332 if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) {
|
13592
|
333 byte_stream_put16(&frame->data, args->featureslen);
|
|
334 byte_stream_putraw(&frame->data, args->features, args->featureslen);
|
13234
|
335 } else {
|
13592
|
336 byte_stream_put16(&frame->data, sizeof(deffeatures));
|
|
337 byte_stream_putraw(&frame->data, deffeatures, sizeof(deffeatures));
|
13234
|
338 }
|
|
339
|
|
340 if (args->flags & AIM_IMFLAGS_MULTIPART) {
|
|
341 aim_mpmsg_section_t *sec;
|
|
342
|
|
343 /* Insert each message part in a TLV (type 0x0101) */
|
|
344 for (sec = args->mpmsg->parts; sec; sec = sec->next) {
|
13592
|
345 byte_stream_put16(&frame->data, 0x0101);
|
|
346 byte_stream_put16(&frame->data, sec->datalen + 4);
|
|
347 byte_stream_put16(&frame->data, sec->charset);
|
|
348 byte_stream_put16(&frame->data, sec->charsubset);
|
|
349 byte_stream_putraw(&frame->data, (guchar *)sec->data, sec->datalen);
|
13234
|
350 }
|
|
351
|
|
352 } else {
|
|
353
|
|
354 /* Insert message text in a TLV (type 0x0101) */
|
13592
|
355 byte_stream_put16(&frame->data, 0x0101);
|
13234
|
356
|
|
357 /* Message block length */
|
13592
|
358 byte_stream_put16(&frame->data, args->msglen + 0x04);
|
13234
|
359
|
|
360 /* Character set */
|
13592
|
361 byte_stream_put16(&frame->data, args->charset);
|
|
362 byte_stream_put16(&frame->data, args->charsubset);
|
13234
|
363
|
|
364 /* Message. Not terminated */
|
13592
|
365 byte_stream_putraw(&frame->data, (guchar *)args->msg, args->msglen);
|
13234
|
366 }
|
|
367
|
|
368 /* Set the Autoresponse flag */
|
|
369 if (args->flags & AIM_IMFLAGS_AWAY) {
|
13592
|
370 byte_stream_put16(&frame->data, 0x0004);
|
|
371 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
372 } else if (args->flags & AIM_IMFLAGS_ACK) {
|
|
373 /* Set the Request Acknowledge flag */
|
13592
|
374 byte_stream_put16(&frame->data, 0x0003);
|
|
375 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
376 }
|
|
377
|
|
378 if (args->flags & AIM_IMFLAGS_OFFLINE) {
|
13592
|
379 byte_stream_put16(&frame->data, 0x0006);
|
|
380 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
381 }
|
|
382
|
|
383 /*
|
|
384 * Set the I HAVE A REALLY PURTY ICON flag.
|
|
385 * XXX - This should really only be sent on initial
|
|
386 * IMs and when you change your icon.
|
|
387 */
|
|
388 if (args->flags & AIM_IMFLAGS_HASICON) {
|
13592
|
389 byte_stream_put16(&frame->data, 0x0008);
|
|
390 byte_stream_put16(&frame->data, 0x000c);
|
|
391 byte_stream_put32(&frame->data, args->iconlen);
|
|
392 byte_stream_put16(&frame->data, 0x0001);
|
|
393 byte_stream_put16(&frame->data, args->iconsum);
|
|
394 byte_stream_put32(&frame->data, args->iconstamp);
|
13234
|
395 }
|
|
396
|
|
397 /*
|
|
398 * Set the Buddy Icon Requested flag.
|
|
399 * XXX - Every time? Surely not...
|
|
400 */
|
|
401 if (args->flags & AIM_IMFLAGS_BUDDYREQ) {
|
13592
|
402 byte_stream_put16(&frame->data, 0x0009);
|
|
403 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
404 }
|
|
405
|
13592
|
406 flap_connection_send(conn, frame);
|
13234
|
407
|
|
408 /* clean out SNACs over 60sec old */
|
13592
|
409 aim_cleansnacs(od, 60);
|
13234
|
410
|
|
411 return 0;
|
|
412 }
|
|
413
|
|
414 /*
|
|
415 * Simple wrapper for aim_im_sendch1_ext()
|
|
416 *
|
|
417 * You cannot use aim_send_im if you need the HASICON flag. You must
|
|
418 * use aim_im_sendch1_ext directly for that.
|
|
419 *
|
|
420 * aim_send_im also cannot be used if you require UNICODE messages, because
|
|
421 * that requires an explicit message length. Use aim_im_sendch1_ext().
|
|
422 *
|
|
423 */
|
13592
|
424 int aim_im_sendch1(OscarData *od, const char *sn, guint16 flags, const char *msg)
|
13234
|
425 {
|
|
426 struct aim_sendimext_args args;
|
|
427
|
|
428 args.destsn = sn;
|
|
429 args.flags = flags;
|
|
430 args.msg = msg;
|
|
431 args.msglen = strlen(msg);
|
|
432 args.charset = 0x0000;
|
|
433 args.charsubset = 0x0000;
|
|
434
|
|
435 /* Make these don't get set by accident -- they need aim_im_sendch1_ext */
|
|
436 args.flags &= ~(AIM_IMFLAGS_CUSTOMFEATURES | AIM_IMFLAGS_HASICON | AIM_IMFLAGS_MULTIPART);
|
|
437
|
13592
|
438 return aim_im_sendch1_ext(od, &args);
|
13234
|
439 }
|
|
440
|
|
441 /*
|
|
442 * Subtype 0x0006 - Send a chat invitation.
|
|
443 */
|
13592
|
444 int aim_im_sendch2_chatinvite(OscarData *od, const char *sn, const char *msg, guint16 exchange, const char *roomname, guint16 instance)
|
13234
|
445 {
|
13592
|
446 FlapConnection *conn;
|
|
447 FlapFrame *frame;
|
13234
|
448 aim_snacid_t snacid;
|
13239
|
449 IcbmCookie *msgcookie;
|
13234
|
450 struct aim_invite_priv *priv;
|
|
451 guchar cookie[8];
|
|
452 aim_tlvlist_t *otl = NULL, *itl = NULL;
|
|
453 guint8 *hdr;
|
|
454 int hdrlen;
|
13239
|
455 ByteStream hdrbs;
|
13234
|
456
|
13592
|
457 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
458 return -EINVAL;
|
|
459
|
|
460 if (!sn || !msg || !roomname)
|
|
461 return -EINVAL;
|
|
462
|
|
463 aim_icbm_makecookie(cookie);
|
|
464
|
13592
|
465 frame = flap_frame_new(od, 0x02, 1152+strlen(sn)+strlen(roomname)+strlen(msg));
|
|
466
|
|
467 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, sn, strlen(sn)+1);
|
|
468 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
469
|
|
470 /* XXX should be uncached by an unwritten 'invite accept' handler */
|
13592
|
471 priv = malloc(sizeof(struct aim_invite_priv));
|
|
472 priv->sn = strdup(sn);
|
|
473 priv->roomname = strdup(roomname);
|
|
474 priv->exchange = exchange;
|
|
475 priv->instance = instance;
|
13234
|
476
|
|
477 if ((msgcookie = aim_mkcookie(cookie, AIM_COOKIETYPE_INVITE, priv)))
|
13592
|
478 aim_cachecookie(od, msgcookie);
|
13234
|
479 else
|
|
480 free(priv);
|
|
481
|
|
482 /* ICBM Header */
|
13592
|
483 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
13234
|
484
|
|
485 /*
|
|
486 * TLV t(0005)
|
|
487 *
|
|
488 * Everything else is inside this TLV.
|
|
489 *
|
|
490 * Sigh. AOL was rather inconsistent right here. So we have
|
|
491 * to play some minor tricks. Right inside the type 5 is some
|
|
492 * raw data, followed by a series of TLVs.
|
|
493 *
|
|
494 */
|
|
495 hdrlen = 2+8+16+6+4+4+strlen(msg)+4+2+1+strlen(roomname)+2;
|
|
496 hdr = malloc(hdrlen);
|
13592
|
497 byte_stream_init(&hdrbs, hdr, hdrlen);
|
|
498
|
|
499 byte_stream_put16(&hdrbs, 0x0000); /* Unknown! */
|
|
500 byte_stream_putraw(&hdrbs, cookie, sizeof(cookie)); /* I think... */
|
|
501 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_CHAT);
|
13234
|
502
|
|
503 aim_tlvlist_add_16(&itl, 0x000a, 0x0001);
|
|
504 aim_tlvlist_add_noval(&itl, 0x000f);
|
|
505 aim_tlvlist_add_str(&itl, 0x000c, msg);
|
|
506 aim_tlvlist_add_chatroom(&itl, 0x2711, exchange, roomname, instance);
|
|
507 aim_tlvlist_write(&hdrbs, &itl);
|
|
508
|
13592
|
509 aim_tlvlist_add_raw(&otl, 0x0005, byte_stream_curpos(&hdrbs), hdr);
|
|
510
|
|
511 aim_tlvlist_write(&frame->data, &otl);
|
13234
|
512
|
|
513 free(hdr);
|
|
514 aim_tlvlist_free(&itl);
|
|
515 aim_tlvlist_free(&otl);
|
|
516
|
13592
|
517 flap_connection_send(conn, frame);
|
13234
|
518
|
|
519 return 0;
|
|
520 }
|
|
521
|
|
522 /**
|
|
523 * Subtype 0x0006 - Send your icon to a given user.
|
|
524 *
|
|
525 * This is also performance sensitive. (If you can believe it...)
|
|
526 *
|
|
527 */
|
13592
|
528 int aim_im_sendch2_icon(OscarData *od, const char *sn, const guint8 *icon, int iconlen, time_t stamp, guint16 iconsum)
|
13234
|
529 {
|
13592
|
530 FlapConnection *conn;
|
|
531 FlapFrame *frame;
|
13234
|
532 aim_snacid_t snacid;
|
|
533 guchar cookie[8];
|
|
534
|
13592
|
535 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
536 return -EINVAL;
|
|
537
|
|
538 if (!sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN))
|
|
539 return -EINVAL;
|
|
540
|
|
541 aim_icbm_makecookie(cookie);
|
|
542
|
13592
|
543 frame = flap_frame_new(od, 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);
|
|
544
|
|
545 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
546 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
547
|
|
548 /* ICBM header */
|
13592
|
549 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
13234
|
550
|
|
551 /*
|
|
552 * TLV t(0005)
|
|
553 *
|
|
554 * Encompasses everything below.
|
|
555 */
|
13592
|
556 byte_stream_put16(&frame->data, 0x0005);
|
|
557 byte_stream_put16(&frame->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT));
|
|
558
|
|
559 byte_stream_put16(&frame->data, 0x0000);
|
|
560 byte_stream_putraw(&frame->data, cookie, 8);
|
|
561 byte_stream_putcaps(&frame->data, OSCAR_CAPABILITY_BUDDYICON);
|
13234
|
562
|
|
563 /* TLV t(000a) */
|
13592
|
564 byte_stream_put16(&frame->data, 0x000a);
|
|
565 byte_stream_put16(&frame->data, 0x0002);
|
|
566 byte_stream_put16(&frame->data, 0x0001);
|
13234
|
567
|
|
568 /* TLV t(000f) */
|
13592
|
569 byte_stream_put16(&frame->data, 0x000f);
|
|
570 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
571
|
|
572 /* TLV t(2711) */
|
13592
|
573 byte_stream_put16(&frame->data, 0x2711);
|
|
574 byte_stream_put16(&frame->data, 4+4+4+iconlen+strlen(AIM_ICONIDENT));
|
|
575 byte_stream_put16(&frame->data, 0x0000);
|
|
576 byte_stream_put16(&frame->data, iconsum);
|
|
577 byte_stream_put32(&frame->data, iconlen);
|
|
578 byte_stream_put32(&frame->data, stamp);
|
|
579 byte_stream_putraw(&frame->data, icon, iconlen);
|
|
580 byte_stream_putstr(&frame->data, AIM_ICONIDENT);
|
13234
|
581
|
|
582 /* TLV t(0003) */
|
13592
|
583 byte_stream_put16(&frame->data, 0x0003);
|
|
584 byte_stream_put16(&frame->data, 0x0000);
|
|
585
|
|
586 flap_connection_send(conn, frame);
|
13234
|
587
|
|
588 return 0;
|
|
589 }
|
|
590
|
|
591 /*
|
|
592 * Subtype 0x0006 - Send a rich text message.
|
|
593 *
|
|
594 * This only works for ICQ 2001b (thats 2001 not 2000). Better, only
|
|
595 * send it to clients advertising the RTF capability. In fact, if you send
|
|
596 * it to a client that doesn't support that capability, the server will gladly
|
|
597 * bounce it back to you.
|
|
598 *
|
|
599 * You'd think this would be in icq.c, but, well, I'm trying to stick with
|
|
600 * the one-group-per-file scheme as much as possible. This could easily
|
|
601 * be an exception, since Rendezvous IMs are external of the Oscar core,
|
|
602 * and therefore are undefined. Really I just need to think of a good way to
|
|
603 * make an interface similar to what AOL actually uses. But I'm not using COM.
|
|
604 *
|
|
605 */
|
13592
|
606 int aim_im_sendch2_rtfmsg(OscarData *od, struct aim_sendrtfmsg_args *args)
|
13234
|
607 {
|
13592
|
608 FlapConnection *conn;
|
|
609 FlapFrame *frame;
|
13234
|
610 aim_snacid_t snacid;
|
|
611 guchar cookie[8];
|
13592
|
612 const char rtfcap[] = {"{97B12751-243C-4334-AD22-D6ABF73F1492}"}; /* OSCAR_CAPABILITY_ICQRTF capability in string form */
|
13234
|
613 int servdatalen;
|
|
614
|
13592
|
615 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
616 return -EINVAL;
|
|
617
|
|
618 if (!args || !args->destsn || !args->rtfmsg)
|
|
619 return -EINVAL;
|
|
620
|
|
621 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;
|
|
622
|
|
623 aim_icbm_makecookie(cookie);
|
|
624
|
13592
|
625 frame = flap_frame_new(od, 0x02, 10+128+servdatalen);
|
|
626
|
|
627 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
628 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
629
|
|
630 /* ICBM header */
|
13592
|
631 aim_im_puticbm(&frame->data, cookie, 0x0002, args->destsn);
|
13234
|
632
|
|
633 /* TLV t(0005) - Encompasses everything below. */
|
13592
|
634 byte_stream_put16(&frame->data, 0x0005);
|
|
635 byte_stream_put16(&frame->data, 2+8+16 + 2+2+2 + 2+2 + 2+2+servdatalen);
|
|
636
|
|
637 byte_stream_put16(&frame->data, 0x0000);
|
|
638 byte_stream_putraw(&frame->data, cookie, 8);
|
|
639 byte_stream_putcaps(&frame->data, OSCAR_CAPABILITY_ICQSERVERRELAY);
|
13234
|
640
|
|
641 /* t(000a) l(0002) v(0001) */
|
13592
|
642 byte_stream_put16(&frame->data, 0x000a);
|
|
643 byte_stream_put16(&frame->data, 0x0002);
|
|
644 byte_stream_put16(&frame->data, 0x0001);
|
13234
|
645
|
|
646 /* t(000f) l(0000) v() */
|
13592
|
647 byte_stream_put16(&frame->data, 0x000f);
|
|
648 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
649
|
|
650 /* Service Data TLV */
|
13592
|
651 byte_stream_put16(&frame->data, 0x2711);
|
|
652 byte_stream_put16(&frame->data, servdatalen);
|
|
653
|
|
654 byte_stream_putle16(&frame->data, 11 + 16 /* 11 + (sizeof CLSID) */);
|
|
655 byte_stream_putle16(&frame->data, 9);
|
|
656 byte_stream_putcaps(&frame->data, OSCAR_CAPABILITY_EMPTY);
|
|
657 byte_stream_putle16(&frame->data, 0);
|
|
658 byte_stream_putle32(&frame->data, 0);
|
|
659 byte_stream_putle8(&frame->data, 0);
|
|
660 byte_stream_putle16(&frame->data, 0x03ea); /* trid1 */
|
|
661
|
|
662 byte_stream_putle16(&frame->data, 14);
|
|
663 byte_stream_putle16(&frame->data, 0x03eb); /* trid2 */
|
|
664 byte_stream_putle32(&frame->data, 0);
|
|
665 byte_stream_putle32(&frame->data, 0);
|
|
666 byte_stream_putle32(&frame->data, 0);
|
|
667
|
|
668 byte_stream_putle16(&frame->data, 0x0001);
|
|
669 byte_stream_putle32(&frame->data, 0);
|
|
670 byte_stream_putle16(&frame->data, strlen(args->rtfmsg)+1);
|
|
671 byte_stream_putraw(&frame->data, (const guint8 *)args->rtfmsg, strlen(args->rtfmsg)+1);
|
|
672
|
|
673 byte_stream_putle32(&frame->data, args->fgcolor);
|
|
674 byte_stream_putle32(&frame->data, args->bgcolor);
|
|
675 byte_stream_putle32(&frame->data, strlen(rtfcap)+1);
|
|
676 byte_stream_putraw(&frame->data, (const guint8 *)rtfcap, strlen(rtfcap)+1);
|
|
677
|
|
678 flap_connection_send(conn, frame);
|
13234
|
679
|
|
680 return 0;
|
|
681 }
|
|
682
|
|
683 /**
|
13592
|
684 * Cancel a rendezvous invitation. It could be an invitation to
|
|
685 * establish a direct connection, or a file-send, or a chat invite.
|
13234
|
686 */
|
13592
|
687 void
|
|
688 aim_im_sendch2_cancel(PeerConnection *peer_conn)
|
13234
|
689 {
|
13592
|
690 OscarData *od;
|
|
691 FlapConnection *conn;
|
|
692 FlapFrame *frame;
|
13234
|
693 aim_snacid_t snacid;
|
13592
|
694 aim_tlvlist_t *tl = NULL, *itl = NULL;
|
|
695 int hdrlen;
|
|
696 guint8 *hdr;
|
|
697 ByteStream hdrbs;
|
|
698
|
|
699 od = peer_conn->od;
|
|
700 conn = flap_connection_findbygroup(od, 0x0004);
|
|
701 if (conn == NULL)
|
|
702 return;
|
|
703
|
|
704 frame = flap_frame_new(od, 0x02, 128+strlen(peer_conn->sn));
|
|
705
|
|
706 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
707 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
|
708
|
|
709 /* ICBM header */
|
|
710 aim_im_puticbm(&frame->data, peer_conn->cookie, 0x0002, peer_conn->sn);
|
|
711
|
|
712 aim_tlvlist_add_noval(&tl, 0x0003);
|
|
713
|
|
714 hdrlen = 64;
|
|
715 hdr = malloc(hdrlen);
|
|
716 byte_stream_init(&hdrbs, hdr, hdrlen);
|
|
717
|
|
718 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_CANCEL);
|
|
719 byte_stream_putraw(&hdrbs, peer_conn->cookie, 8);
|
|
720 byte_stream_putcaps(&hdrbs, peer_conn->type);
|
|
721
|
|
722 /* This TLV means "cancel!" */
|
|
723 aim_tlvlist_add_16(&itl, 0x000b, 0x0001);
|
|
724 aim_tlvlist_write(&hdrbs, &itl);
|
|
725
|
|
726 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr);
|
|
727
|
|
728 aim_tlvlist_write(&frame->data, &tl);
|
|
729
|
|
730 free(hdr);
|
|
731 aim_tlvlist_free(&itl);
|
|
732 aim_tlvlist_free(&tl);
|
|
733
|
|
734 flap_connection_send(conn, frame);
|
|
735 }
|
|
736
|
|
737 /**
|
|
738 * Subtype 0x0006 - Send an "I accept and I've connected to
|
|
739 * you" message.
|
|
740 */
|
|
741 void
|
|
742 aim_im_sendch2_connected(PeerConnection *peer_conn)
|
|
743 {
|
|
744 OscarData *od;
|
|
745 FlapConnection *conn;
|
|
746 FlapFrame *frame;
|
|
747 aim_snacid_t snacid;
|
|
748
|
|
749 od = peer_conn->od;
|
|
750 conn = flap_connection_findbygroup(od, 0x0004);
|
|
751 if (conn == NULL)
|
|
752 return;
|
|
753
|
|
754 frame = flap_frame_new(od, 0x02, 10 + 11+strlen(peer_conn->sn) + 4+2+8+16);
|
|
755
|
|
756 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
757 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
|
758
|
|
759 /* ICBM header */
|
|
760 aim_im_puticbm(&frame->data, peer_conn->cookie, 0x0002, peer_conn->sn);
|
|
761
|
|
762 byte_stream_put16(&frame->data, 0x0005);
|
|
763 byte_stream_put16(&frame->data, 0x001a);
|
|
764 byte_stream_put16(&frame->data, AIM_RENDEZVOUS_CONNECTED);
|
|
765 byte_stream_putraw(&frame->data, peer_conn->cookie, 8);
|
|
766 byte_stream_putcaps(&frame->data, peer_conn->type);
|
|
767
|
|
768 flap_connection_send(conn, frame);
|
|
769 }
|
|
770
|
|
771 /**
|
|
772 * Subtype 0x0006 - Send a direct connect rendezvous ICBM. This
|
|
773 * could have a number of meanings, depending on the content:
|
|
774 * "I want you to connect to me"
|
|
775 * "I want to connect to you"
|
|
776 * "I want to connect through a proxy server"
|
|
777 */
|
|
778 void
|
|
779 aim_im_sendch2_odc_requestdirect(OscarData *od, guchar *cookie, const char *sn, const guint8 *ip, guint16 port, guint16 requestnumber)
|
|
780 {
|
|
781 FlapConnection *conn;
|
|
782 FlapFrame *frame;
|
|
783 aim_snacid_t snacid;
|
13234
|
784 aim_tlvlist_t *tl = NULL, *itl = NULL;
|
|
785 int hdrlen;
|
|
786 guint8 *hdr;
|
13239
|
787 ByteStream hdrbs;
|
13234
|
788
|
13592
|
789 conn = flap_connection_findbygroup(od, 0x0004);
|
|
790 if (conn == NULL)
|
|
791 return;
|
|
792
|
|
793 frame = flap_frame_new(od, 0x02, 256+strlen(sn));
|
|
794
|
|
795 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
796 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
797
|
|
798 /* ICBM header */
|
13592
|
799 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
13234
|
800
|
|
801 aim_tlvlist_add_noval(&tl, 0x0003);
|
|
802
|
13592
|
803 hdrlen = 128;
|
13234
|
804 hdr = malloc(hdrlen);
|
13592
|
805 byte_stream_init(&hdrbs, hdr, hdrlen);
|
|
806
|
|
807 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
|
|
808 byte_stream_putraw(&hdrbs, cookie, 8);
|
|
809 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_DIRECTIM);
|
|
810
|
|
811 aim_tlvlist_add_raw(&itl, 0x0002, 4, ip);
|
13234
|
812 aim_tlvlist_add_raw(&itl, 0x0003, 4, ip);
|
|
813 aim_tlvlist_add_16(&itl, 0x0005, port);
|
13592
|
814 aim_tlvlist_add_16(&itl, 0x000a, requestnumber);
|
13234
|
815 aim_tlvlist_add_noval(&itl, 0x000f);
|
|
816 aim_tlvlist_write(&hdrbs, &itl);
|
|
817
|
13592
|
818 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr);
|
|
819
|
|
820 aim_tlvlist_write(&frame->data, &tl);
|
13234
|
821
|
|
822 free(hdr);
|
|
823 aim_tlvlist_free(&itl);
|
|
824 aim_tlvlist_free(&tl);
|
|
825
|
13592
|
826 flap_connection_send(conn, frame);
|
|
827 }
|
|
828
|
|
829 /**
|
|
830 * Subtype 0x0006 - Send a direct connect rendezvous ICBM asking the
|
|
831 * remote user to connect to us via a proxy server.
|
|
832 */
|
|
833 void
|
|
834 aim_im_sendch2_odc_requestproxy(OscarData *od, guchar *cookie, const char *sn, const guint8 *ip, guint16 pin, guint16 requestnumber)
|
|
835 {
|
|
836 FlapConnection *conn;
|
|
837 FlapFrame *frame;
|
|
838 aim_snacid_t snacid;
|
|
839 aim_tlvlist_t *tl = NULL, *itl = NULL;
|
|
840 int hdrlen;
|
|
841 guint8 *hdr;
|
|
842 ByteStream hdrbs;
|
|
843 guint8 ip_comp[4];
|
|
844
|
|
845 conn = flap_connection_findbygroup(od, 0x0004);
|
|
846 if (conn == NULL)
|
|
847 return;
|
|
848
|
|
849 frame = flap_frame_new(od, 0x02, 256+strlen(sn));
|
|
850
|
|
851 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
852 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
|
853
|
|
854 /* ICBM header */
|
|
855 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
|
856
|
|
857 aim_tlvlist_add_noval(&tl, 0x0003);
|
|
858
|
|
859 hdrlen = 128;
|
|
860 hdr = malloc(hdrlen);
|
|
861 byte_stream_init(&hdrbs, hdr, hdrlen);
|
|
862
|
|
863 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
|
|
864 byte_stream_putraw(&hdrbs, cookie, 8);
|
|
865 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_DIRECTIM);
|
|
866
|
|
867 aim_tlvlist_add_raw(&itl, 0x0002, 4, ip);
|
|
868 aim_tlvlist_add_raw(&itl, 0x0003, 4, ip);
|
|
869 aim_tlvlist_add_16(&itl, 0x0005, pin);
|
|
870 aim_tlvlist_add_16(&itl, 0x000a, requestnumber);
|
|
871 aim_tlvlist_add_noval(&itl, 0x000f);
|
|
872 aim_tlvlist_add_noval(&itl, 0x0010);
|
|
873
|
|
874 /* Send the bitwise complement of the port and ip. As a check? */
|
|
875 ip_comp[0] = ~ip[0];
|
|
876 ip_comp[1] = ~ip[1];
|
|
877 ip_comp[2] = ~ip[2];
|
|
878 ip_comp[3] = ~ip[3];
|
|
879 aim_tlvlist_add_raw(&itl, 0x0016, 4, ip_comp);
|
|
880 aim_tlvlist_add_16(&itl, 0x0017, ~pin);
|
|
881
|
|
882 aim_tlvlist_write(&hdrbs, &itl);
|
|
883
|
|
884 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr);
|
|
885
|
|
886 aim_tlvlist_write(&frame->data, &tl);
|
|
887
|
|
888 free(hdr);
|
|
889 aim_tlvlist_free(&itl);
|
|
890 aim_tlvlist_free(&tl);
|
|
891
|
|
892 flap_connection_send(conn, frame);
|
13234
|
893 }
|
|
894
|
|
895 /**
|
|
896 * Subtype 0x0006 - Send an "I want to send you this file" message
|
|
897 *
|
|
898 */
|
13592
|
899 void
|
|
900 aim_im_sendch2_sendfile_requestdirect(OscarData *od, guchar *cookie, const char *sn, const guint8 *ip, guint16 port, guint16 requestnumber, const gchar *filename, guint32 size, guint16 numfiles)
|
13234
|
901 {
|
13592
|
902 FlapConnection *conn;
|
|
903 FlapFrame *frame;
|
13234
|
904 aim_snacid_t snacid;
|
13592
|
905 aim_tlvlist_t *tl = NULL, *itl = NULL;
|
|
906 int hdrlen, buflen;
|
|
907 guint8 *hdr;
|
|
908 ByteStream hdrbs;
|
|
909
|
|
910 conn = flap_connection_findbygroup(od, 0x0004);
|
|
911 if (conn == NULL)
|
|
912 return;
|
|
913
|
|
914 frame = flap_frame_new(od, 0x02, 1024);
|
|
915
|
|
916 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
917 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
918
|
|
919 /* ICBM header */
|
13592
|
920 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
|
921
|
|
922 aim_tlvlist_add_noval(&tl, 0x0003);
|
|
923
|
|
924 hdrlen = 512;
|
|
925 hdr = malloc(hdrlen);
|
|
926 byte_stream_init(&hdrbs, hdr, hdrlen);
|
|
927
|
|
928 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
|
|
929 byte_stream_putraw(&hdrbs, cookie, 8);
|
|
930 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_SENDFILE);
|
|
931
|
|
932 aim_tlvlist_add_raw(&itl, 0x0002, 4, ip);
|
|
933 aim_tlvlist_add_raw(&itl, 0x0003, 4, ip);
|
|
934 aim_tlvlist_add_16(&itl, 0x0005, port);
|
|
935 aim_tlvlist_add_16(&itl, 0x000a, requestnumber);
|
|
936 aim_tlvlist_add_noval(&itl, 0x000f);
|
|
937 /* TODO: Send 0x0016 and 0x0017 */
|
|
938
|
|
939 #if 0
|
|
940 /* TODO: If the following is ever enabled, ensure that it is
|
|
941 * not sent with a receive redirect or stage 3 proxy
|
|
942 * redirect for a file receive (same conditions for
|
|
943 * sending 0x000f above)
|
|
944 */
|
|
945 aim_tlvlist_add_raw(&itl, 0x000e, 2, "en");
|
|
946 aim_tlvlist_add_raw(&itl, 0x000d, 8, "us-ascii");
|
|
947 aim_tlvlist_add_raw(&itl, 0x000c, 24, "Please accept this file.");
|
|
948 #endif
|
|
949
|
|
950 if (filename != NULL)
|
|
951 {
|
|
952 ByteStream bs;
|
|
953
|
|
954 /* Begin TLV t(2711) */
|
|
955 buflen = 2+2+4+strlen(filename)+1;
|
|
956 byte_stream_init(&bs, malloc(buflen), buflen);
|
|
957 byte_stream_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001);
|
|
958 byte_stream_put16(&bs, numfiles);
|
|
959 byte_stream_put32(&bs, size);
|
|
960
|
|
961 /* Filename - NULL terminated, for some odd reason */
|
|
962 byte_stream_putstr(&bs, filename);
|
|
963 byte_stream_put8(&bs, 0x00);
|
|
964
|
|
965 aim_tlvlist_add_raw(&itl, 0x2711, bs.len, bs.data);
|
|
966 free(bs.data);
|
|
967 /* End TLV t(2711) */
|
|
968 }
|
|
969
|
|
970 aim_tlvlist_write(&hdrbs, &itl);
|
|
971 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr);
|
|
972
|
|
973 aim_tlvlist_write(&frame->data, &tl);
|
|
974
|
|
975 free(hdr);
|
|
976 aim_tlvlist_free(&itl);
|
13234
|
977 aim_tlvlist_free(&tl);
|
|
978
|
13592
|
979 flap_connection_send(conn, frame);
|
13234
|
980 }
|
|
981
|
|
982 /**
|
13592
|
983 * Subtype 0x0006 - Send a sendfile connect rendezvous ICBM asking the
|
|
984 * remote user to connect to us via a proxy server.
|
13234
|
985 */
|
13592
|
986 void
|
|
987 aim_im_sendch2_sendfile_requestproxy(OscarData *od, guchar *cookie, const char *sn, const guint8 *ip, guint16 pin, guint16 requestnumber, const gchar *filename, guint32 size, guint16 numfiles)
|
13234
|
988 {
|
13592
|
989 FlapConnection *conn;
|
|
990 FlapFrame *frame;
|
13234
|
991 aim_snacid_t snacid;
|
13592
|
992 aim_tlvlist_t *tl = NULL, *itl = NULL;
|
|
993 int hdrlen, buflen;
|
|
994 guint8 *hdr;
|
|
995 ByteStream hdrbs;
|
|
996 guint8 ip_comp[4];
|
|
997
|
|
998 conn = flap_connection_findbygroup(od, 0x0004);
|
|
999 if (conn == NULL)
|
|
1000 return;
|
|
1001
|
|
1002 frame = flap_frame_new(od, 0x02, 1024);
|
|
1003
|
|
1004 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
1005 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
1006
|
|
1007 /* ICBM header */
|
13592
|
1008 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
|
1009
|
|
1010 aim_tlvlist_add_noval(&tl, 0x0003);
|
|
1011
|
|
1012 hdrlen = 512;
|
|
1013 hdr = malloc(hdrlen);
|
|
1014 byte_stream_init(&hdrbs, hdr, hdrlen);
|
|
1015
|
|
1016 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
|
|
1017 byte_stream_putraw(&hdrbs, cookie, 8);
|
|
1018 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_SENDFILE);
|
|
1019
|
|
1020 aim_tlvlist_add_raw(&itl, 0x0002, 4, ip);
|
|
1021 aim_tlvlist_add_raw(&itl, 0x0003, 4, ip);
|
|
1022 aim_tlvlist_add_16(&itl, 0x0005, pin);
|
|
1023 aim_tlvlist_add_16(&itl, 0x000a, requestnumber);
|
|
1024 aim_tlvlist_add_noval(&itl, 0x000f);
|
|
1025 aim_tlvlist_add_noval(&itl, 0x0010);
|
|
1026
|
|
1027 /* Send the bitwise complement of the port and ip. As a check? */
|
|
1028 ip_comp[0] = ~ip[0];
|
|
1029 ip_comp[1] = ~ip[1];
|
|
1030 ip_comp[2] = ~ip[2];
|
|
1031 ip_comp[3] = ~ip[3];
|
|
1032 aim_tlvlist_add_raw(&itl, 0x0016, 4, ip_comp);
|
|
1033 aim_tlvlist_add_16(&itl, 0x0017, ~pin);
|
|
1034
|
|
1035 #if 0
|
|
1036 /* TODO: If the following is ever enabled, ensure that it is
|
|
1037 * not sent with a receive redirect or stage 3 proxy
|
|
1038 * redirect for a file receive (same conditions for
|
|
1039 * sending 0x000f above)
|
|
1040 */
|
|
1041 aim_tlvlist_add_raw(&itl, 0x000e, 2, "en");
|
|
1042 aim_tlvlist_add_raw(&itl, 0x000d, 8, "us-ascii");
|
|
1043 aim_tlvlist_add_raw(&itl, 0x000c, 24, "Please accept this file.");
|
|
1044 #endif
|
|
1045
|
|
1046 if (filename != NULL)
|
|
1047 {
|
|
1048 ByteStream bs;
|
|
1049
|
|
1050 /* Begin TLV t(2711) */
|
|
1051 buflen = 2+2+4+strlen(filename)+1;
|
|
1052 byte_stream_init(&bs, malloc(buflen), buflen);
|
|
1053 byte_stream_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001);
|
|
1054 byte_stream_put16(&bs, numfiles);
|
|
1055 byte_stream_put32(&bs, size);
|
|
1056
|
|
1057 /* Filename - NULL terminated, for some odd reason */
|
|
1058 byte_stream_putstr(&bs, filename);
|
|
1059 byte_stream_put8(&bs, 0x00);
|
|
1060
|
|
1061 aim_tlvlist_add_raw(&itl, 0x2711, bs.len, bs.data);
|
|
1062 free(bs.data);
|
|
1063 /* End TLV t(2711) */
|
|
1064 }
|
|
1065
|
|
1066 aim_tlvlist_write(&hdrbs, &itl);
|
|
1067
|
|
1068 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr);
|
|
1069
|
|
1070 aim_tlvlist_write(&frame->data, &tl);
|
|
1071
|
|
1072 free(hdr);
|
|
1073 aim_tlvlist_free(&itl);
|
|
1074 aim_tlvlist_free(&tl);
|
|
1075
|
|
1076 flap_connection_send(conn, frame);
|
13234
|
1077 }
|
|
1078
|
|
1079 /**
|
|
1080 * Subtype 0x0006 - Request the status message of the given ICQ user.
|
|
1081 *
|
13592
|
1082 * @param od The oscar session.
|
13234
|
1083 * @param sn The UIN of the user of whom you wish to request info.
|
|
1084 * @param type The type of info you wish to request. This should be the current
|
|
1085 * state of the user, as one of the AIM_ICQ_STATE_* defines.
|
|
1086 * @return Return 0 if no errors, otherwise return the error number.
|
|
1087 */
|
13592
|
1088 int aim_im_sendch2_geticqaway(OscarData *od, const char *sn, int type)
|
13234
|
1089 {
|
13592
|
1090 FlapConnection *conn;
|
|
1091 FlapFrame *frame;
|
13234
|
1092 aim_snacid_t snacid;
|
|
1093 guchar cookie[8];
|
|
1094
|
13592
|
1095 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)) || !sn)
|
13234
|
1096 return -EINVAL;
|
|
1097
|
|
1098 aim_icbm_makecookie(cookie);
|
|
1099
|
13592
|
1100 frame = flap_frame_new(od, 0x02, 10+8+2+1+strlen(sn) + 4+0x5e + 4);
|
|
1101
|
|
1102 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
1103 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
1104
|
|
1105 /* ICBM header */
|
13592
|
1106 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
|
13234
|
1107
|
|
1108 /* TLV t(0005) - Encompasses almost everything below. */
|
13592
|
1109 byte_stream_put16(&frame->data, 0x0005); /* T */
|
|
1110 byte_stream_put16(&frame->data, 0x005e); /* L */
|
13234
|
1111 { /* V */
|
13592
|
1112 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
1113
|
|
1114 /* Cookie */
|
13592
|
1115 byte_stream_putraw(&frame->data, cookie, 8);
|
13234
|
1116
|
|
1117 /* Put the 16 byte server relay capability */
|
13592
|
1118 byte_stream_putcaps(&frame->data, OSCAR_CAPABILITY_ICQSERVERRELAY);
|
13234
|
1119
|
|
1120 /* TLV t(000a) */
|
13592
|
1121 byte_stream_put16(&frame->data, 0x000a);
|
|
1122 byte_stream_put16(&frame->data, 0x0002);
|
|
1123 byte_stream_put16(&frame->data, 0x0001);
|
13234
|
1124
|
|
1125 /* TLV t(000f) */
|
13592
|
1126 byte_stream_put16(&frame->data, 0x000f);
|
|
1127 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
1128
|
|
1129 /* TLV t(2711) */
|
13592
|
1130 byte_stream_put16(&frame->data, 0x2711);
|
|
1131 byte_stream_put16(&frame->data, 0x0036);
|
13234
|
1132 { /* V */
|
13592
|
1133 byte_stream_putle16(&frame->data, 0x001b); /* L */
|
|
1134 byte_stream_putle16(&frame->data, 0x0009); /* Protocol version */
|
|
1135 byte_stream_putcaps(&frame->data, OSCAR_CAPABILITY_EMPTY);
|
|
1136 byte_stream_putle16(&frame->data, 0x0000); /* Unknown */
|
|
1137 byte_stream_putle16(&frame->data, 0x0001); /* Client features? */
|
|
1138 byte_stream_putle16(&frame->data, 0x0000); /* Unknown */
|
|
1139 byte_stream_putle8(&frame->data, 0x00); /* Unkizown */
|
|
1140 byte_stream_putle16(&frame->data, 0xffff); /* Sequence number? XXX - This should decrement by 1 with each request */
|
|
1141
|
|
1142 byte_stream_putle16(&frame->data, 0x000e); /* L */
|
|
1143 byte_stream_putle16(&frame->data, 0xffff); /* Sequence number? XXX - This should decrement by 1 with each request */
|
|
1144 byte_stream_putle32(&frame->data, 0x00000000); /* Unknown */
|
|
1145 byte_stream_putle32(&frame->data, 0x00000000); /* Unknown */
|
|
1146 byte_stream_putle32(&frame->data, 0x00000000); /* Unknown */
|
13234
|
1147
|
|
1148 /* The type of status message being requested */
|
|
1149 if (type & AIM_ICQ_STATE_CHAT)
|
13592
|
1150 byte_stream_putle16(&frame->data, 0x03ec);
|
13234
|
1151 else if(type & AIM_ICQ_STATE_DND)
|
13592
|
1152 byte_stream_putle16(&frame->data, 0x03eb);
|
13234
|
1153 else if(type & AIM_ICQ_STATE_OUT)
|
13592
|
1154 byte_stream_putle16(&frame->data, 0x03ea);
|
13234
|
1155 else if(type & AIM_ICQ_STATE_BUSY)
|
13592
|
1156 byte_stream_putle16(&frame->data, 0x03e9);
|
13234
|
1157 else if(type & AIM_ICQ_STATE_AWAY)
|
13592
|
1158 byte_stream_putle16(&frame->data, 0x03e8);
|
|
1159
|
|
1160 byte_stream_putle16(&frame->data, 0x0001); /* Status? */
|
|
1161 byte_stream_putle16(&frame->data, 0x0001); /* Priority of this message? */
|
|
1162 byte_stream_putle16(&frame->data, 0x0001); /* L */
|
|
1163 byte_stream_putle8(&frame->data, 0x00); /* String of length L */
|
13234
|
1164 } /* End TLV t(2711) */
|
|
1165 } /* End TLV t(0005) */
|
|
1166
|
|
1167 /* TLV t(0003) */
|
13592
|
1168 byte_stream_put16(&frame->data, 0x0003);
|
|
1169 byte_stream_put16(&frame->data, 0x0000);
|
|
1170
|
|
1171 flap_connection_send(conn, frame);
|
13234
|
1172
|
|
1173 return 0;
|
|
1174 }
|
|
1175
|
|
1176 /**
|
|
1177 * Subtype 0x0006 - Send an ICQ-esque ICBM.
|
|
1178 *
|
|
1179 * This can be used to send an ICQ authorization reply (deny or grant). It is the "old way."
|
|
1180 * The new way is to use SSI. I like the new way a lot better. This seems like such a hack,
|
|
1181 * mostly because it's in network byte order. Figuring this stuff out sometimes takes a while,
|
|
1182 * but thats ok, because it gives me time to try to figure out what kind of drugs the AOL people
|
|
1183 * were taking when they merged the two protocols.
|
|
1184 *
|
|
1185 * @param sn The destination screen name.
|
|
1186 * @param type The type of message. 0x0007 for authorization denied. 0x0008 for authorization granted.
|
|
1187 * @param message The message you want to send, it should be null terminated.
|
|
1188 * @return Return 0 if no errors, otherwise return the error number.
|
|
1189 */
|
13592
|
1190 int aim_im_sendch4(OscarData *od, const char *sn, guint16 type, const char *message)
|
13234
|
1191 {
|
13592
|
1192 FlapConnection *conn;
|
|
1193 FlapFrame *frame;
|
13234
|
1194 aim_snacid_t snacid;
|
|
1195 guchar cookie[8];
|
|
1196
|
13592
|
1197 if (!od || !(conn = flap_connection_findbygroup(od, 0x0002)))
|
13234
|
1198 return -EINVAL;
|
|
1199
|
|
1200 if (!sn || !type || !message)
|
|
1201 return -EINVAL;
|
|
1202
|
13592
|
1203 frame = flap_frame_new(od, 0x02, 10+8+3+strlen(sn)+12+strlen(message)+1+4);
|
|
1204
|
|
1205 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, NULL, 0);
|
|
1206 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
|
13234
|
1207
|
|
1208 aim_icbm_makecookie(cookie);
|
|
1209
|
|
1210 /* ICBM header */
|
13592
|
1211 aim_im_puticbm(&frame->data, cookie, 0x0004, sn);
|
13234
|
1212
|
|
1213 /*
|
|
1214 * TLV t(0005)
|
|
1215 *
|
|
1216 * ICQ data (the UIN and the message).
|
|
1217 */
|
13592
|
1218 byte_stream_put16(&frame->data, 0x0005);
|
|
1219 byte_stream_put16(&frame->data, 4 + 2+2+strlen(message)+1);
|
13234
|
1220
|
|
1221 /*
|
|
1222 * Your UIN
|
|
1223 */
|
13592
|
1224 byte_stream_putle32(&frame->data, atoi(od->sn));
|
13234
|
1225
|
|
1226 /*
|
|
1227 * TLV t(type) l(strlen(message)+1) v(message+NULL)
|
|
1228 */
|
13592
|
1229 byte_stream_putle16(&frame->data, type);
|
|
1230 byte_stream_putle16(&frame->data, strlen(message)+1);
|
|
1231 byte_stream_putraw(&frame->data, (const guint8 *)message, strlen(message)+1);
|
13234
|
1232
|
|
1233 /*
|
|
1234 * TLV t(0006) l(0000) v()
|
|
1235 */
|
13592
|
1236 byte_stream_put16(&frame->data, 0x0006);
|
|
1237 byte_stream_put16(&frame->data, 0x0000);
|
|
1238
|
|
1239 flap_connection_send(conn, frame);
|
13234
|
1240
|
|
1241 return 0;
|
|
1242 }
|
|
1243
|
|
1244 /*
|
|
1245 * XXX - I don't see when this would ever get called...
|
|
1246 */
|
13592
|
1247 static int outgoingim(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
1248 {
|
|
1249 int ret = 0;
|
|
1250 aim_rxcallback_t userfunc;
|
|
1251 guchar cookie[8];
|
|
1252 guint16 channel;
|
|
1253 aim_tlvlist_t *tlvlist;
|
|
1254 char *sn;
|
|
1255 int snlen;
|
|
1256 guint16 icbmflags = 0;
|
|
1257 guint8 flag1 = 0, flag2 = 0;
|
|
1258 gchar *msg = NULL;
|
|
1259 aim_tlv_t *msgblock;
|
|
1260
|
|
1261 /* ICBM Cookie. */
|
|
1262 aim_icbm_makecookie(cookie);
|
|
1263
|
|
1264 /* Channel ID */
|
13592
|
1265 channel = byte_stream_get16(bs);
|
13234
|
1266
|
|
1267 if (channel != 0x01) {
|
|
1268 gaim_debug_misc("oscar", "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
|
|
1269 return 0;
|
|
1270 }
|
|
1271
|
13592
|
1272 snlen = byte_stream_get8(bs);
|
|
1273 sn = byte_stream_getstr(bs, snlen);
|
13234
|
1274
|
|
1275 tlvlist = aim_tlvlist_read(bs);
|
|
1276
|
|
1277 if (aim_tlv_gettlv(tlvlist, 0x0003, 1))
|
|
1278 icbmflags |= AIM_IMFLAGS_ACK;
|
|
1279 if (aim_tlv_gettlv(tlvlist, 0x0004, 1))
|
|
1280 icbmflags |= AIM_IMFLAGS_AWAY;
|
|
1281
|
|
1282 if ((msgblock = aim_tlv_gettlv(tlvlist, 0x0002, 1))) {
|
13239
|
1283 ByteStream mbs;
|
13234
|
1284 int featurelen, msglen;
|
|
1285
|
13592
|
1286 byte_stream_init(&mbs, msgblock->value, msgblock->length);
|
|
1287
|
|
1288 byte_stream_get8(&mbs);
|
|
1289 byte_stream_get8(&mbs);
|
|
1290 for (featurelen = byte_stream_get16(&mbs); featurelen; featurelen--)
|
|
1291 byte_stream_get8(&mbs);
|
|
1292 byte_stream_get8(&mbs);
|
|
1293 byte_stream_get8(&mbs);
|
|
1294
|
|
1295 msglen = byte_stream_get16(&mbs) - 4; /* final block length */
|
|
1296
|
|
1297 flag1 = byte_stream_get16(&mbs);
|
|
1298 flag2 = byte_stream_get16(&mbs);
|
|
1299
|
|
1300 msg = byte_stream_getstr(&mbs, msglen);
|
13234
|
1301 }
|
|
1302
|
13592
|
1303 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
1304 ret = userfunc(od, conn, frame, channel, sn, msg, icbmflags, flag1, flag2);
|
13234
|
1305
|
|
1306 free(sn);
|
|
1307 aim_tlvlist_free(&tlvlist);
|
|
1308
|
|
1309 return ret;
|
|
1310 }
|
|
1311
|
|
1312 /*
|
|
1313 * Ahh, the joys of nearly ridiculous over-engineering.
|
|
1314 *
|
|
1315 * Not only do AIM ICBM's support multiple channels. Not only do they
|
|
1316 * support multiple character sets. But they support multiple character
|
|
1317 * sets / encodings within the same ICBM.
|
|
1318 *
|
|
1319 * These multipart messages allow for complex space savings techniques, which
|
|
1320 * seem utterly unnecessary by today's standards. In fact, there is only
|
|
1321 * one client still in popular use that still uses this method: AOL for the
|
|
1322 * Macintosh, Version 5.0. Obscure, yes, I know.
|
|
1323 *
|
|
1324 * In modern (non-"legacy") clients, if the user tries to send a character
|
|
1325 * that is not ISO-8859-1 or ASCII, the client will send the entire message
|
|
1326 * as UNICODE, meaning that every character in the message will occupy the
|
|
1327 * full 16 bit UNICODE field, even if the high order byte would be zero.
|
|
1328 * Multipart messages prevent this wasted space by allowing the client to
|
|
1329 * only send the characters in UNICODE that need to be sent that way, and
|
|
1330 * the rest of the message can be sent in whatever the native character
|
|
1331 * set is (probably ASCII).
|
|
1332 *
|
|
1333 * An important note is that sections will be displayed in the order that
|
|
1334 * they appear in the ICBM. There is no facility for merging or rearranging
|
|
1335 * sections at run time. So if you have, say, ASCII then UNICODE then ASCII,
|
|
1336 * you must supply two ASCII sections with a UNICODE in the middle, and incur
|
|
1337 * the associated overhead.
|
|
1338 *
|
|
1339 * Normally I would have laughed and given a firm 'no' to supporting this
|
|
1340 * seldom-used feature, but something is attracting me to it. In the future,
|
|
1341 * it may be possible to abuse this to send mixed-media messages to other
|
|
1342 * open source clients (like encryption or something) -- see faimtest for
|
|
1343 * examples of how to do this.
|
|
1344 *
|
|
1345 * I would definitely recommend avoiding this feature unless you really
|
|
1346 * know what you are doing, and/or you have something neat to do with it.
|
|
1347 *
|
|
1348 */
|
13592
|
1349 int aim_mpmsg_init(OscarData *od, aim_mpmsg_t *mpm)
|
13234
|
1350 {
|
|
1351
|
|
1352 memset(mpm, 0, sizeof(aim_mpmsg_t));
|
|
1353
|
|
1354 return 0;
|
|
1355 }
|
|
1356
|
13592
|
1357 static int mpmsg_addsection(OscarData *od, aim_mpmsg_t *mpm, guint16 charset, guint16 charsubset, gchar *data, guint16 datalen)
|
13234
|
1358 {
|
|
1359 aim_mpmsg_section_t *sec;
|
|
1360
|
13592
|
1361 sec = malloc(sizeof(aim_mpmsg_section_t));
|
13234
|
1362
|
|
1363 sec->charset = charset;
|
|
1364 sec->charsubset = charsubset;
|
|
1365 sec->data = data;
|
|
1366 sec->datalen = datalen;
|
|
1367 sec->next = NULL;
|
|
1368
|
|
1369 if (!mpm->parts)
|
|
1370 mpm->parts = sec;
|
|
1371 else {
|
|
1372 aim_mpmsg_section_t *cur;
|
|
1373
|
|
1374 for (cur = mpm->parts; cur->next; cur = cur->next)
|
|
1375 ;
|
|
1376 cur->next = sec;
|
|
1377 }
|
|
1378
|
|
1379 mpm->numparts++;
|
|
1380
|
|
1381 return 0;
|
|
1382 }
|
|
1383
|
13592
|
1384 int aim_mpmsg_addraw(OscarData *od, aim_mpmsg_t *mpm, guint16 charset, guint16 charsubset, const gchar *data, guint16 datalen)
|
13234
|
1385 {
|
|
1386 gchar *dup;
|
|
1387
|
13592
|
1388 dup = malloc(datalen);
|
13234
|
1389 memcpy(dup, data, datalen);
|
|
1390
|
13592
|
1391 if (mpmsg_addsection(od, mpm, charset, charsubset, dup, datalen) == -1) {
|
13234
|
1392 free(dup);
|
|
1393 return -1;
|
|
1394 }
|
|
1395
|
|
1396 return 0;
|
|
1397 }
|
|
1398
|
|
1399 /* XXX - should provide a way of saying ISO-8859-1 specifically */
|
13592
|
1400 int aim_mpmsg_addascii(OscarData *od, aim_mpmsg_t *mpm, const char *ascii)
|
13234
|
1401 {
|
|
1402 gchar *dup;
|
|
1403
|
|
1404 if (!(dup = strdup(ascii)))
|
|
1405 return -1;
|
|
1406
|
13592
|
1407 if (mpmsg_addsection(od, mpm, 0x0000, 0x0000, dup, strlen(ascii)) == -1) {
|
13234
|
1408 free(dup);
|
|
1409 return -1;
|
|
1410 }
|
|
1411
|
|
1412 return 0;
|
|
1413 }
|
|
1414
|
13592
|
1415 int aim_mpmsg_addunicode(OscarData *od, aim_mpmsg_t *mpm, const guint16 *unicode, guint16 unicodelen)
|
13234
|
1416 {
|
|
1417 gchar *buf;
|
13239
|
1418 ByteStream bs;
|
13234
|
1419 int i;
|
|
1420
|
13592
|
1421 buf = malloc(unicodelen * 2);
|
|
1422
|
|
1423 byte_stream_init(&bs, (guchar *)buf, unicodelen * 2);
|
13234
|
1424
|
|
1425 /* We assume unicode is in /host/ byte order -- convert to network */
|
|
1426 for (i = 0; i < unicodelen; i++)
|
13592
|
1427 byte_stream_put16(&bs, unicode[i]);
|
|
1428
|
|
1429 if (mpmsg_addsection(od, mpm, 0x0002, 0x0000, buf, byte_stream_curpos(&bs)) == -1) {
|
13234
|
1430 free(buf);
|
|
1431 return -1;
|
|
1432 }
|
|
1433
|
|
1434 return 0;
|
|
1435 }
|
|
1436
|
13592
|
1437 void aim_mpmsg_free(OscarData *od, aim_mpmsg_t *mpm)
|
13234
|
1438 {
|
|
1439 aim_mpmsg_section_t *cur;
|
|
1440
|
|
1441 for (cur = mpm->parts; cur; ) {
|
|
1442 aim_mpmsg_section_t *tmp;
|
|
1443
|
|
1444 tmp = cur->next;
|
|
1445 free(cur->data);
|
|
1446 free(cur);
|
|
1447 cur = tmp;
|
|
1448 }
|
|
1449
|
|
1450 mpm->numparts = 0;
|
|
1451 mpm->parts = NULL;
|
|
1452
|
|
1453 return;
|
|
1454 }
|
|
1455
|
|
1456 /*
|
|
1457 * Start by building the multipart structures, then pick the first
|
|
1458 * human-readable section and stuff it into args->msg so no one gets
|
|
1459 * suspicious.
|
|
1460 */
|
13592
|
1461 static int incomingim_ch1_parsemsgs(OscarData *od, aim_userinfo_t *userinfo, guint8 *data, int len, struct aim_incomingim_ch1_args *args)
|
13234
|
1462 {
|
|
1463 /* Should this be ASCII -> UNICODE -> Custom */
|
|
1464 static const guint16 charsetpri[] = {
|
|
1465 AIM_CHARSET_ASCII, /* ASCII first */
|
|
1466 AIM_CHARSET_CUSTOM, /* then ISO-8859-1 */
|
|
1467 AIM_CHARSET_UNICODE, /* UNICODE as last resort */
|
|
1468 };
|
|
1469 static const int charsetpricount = 3;
|
|
1470 int i;
|
13239
|
1471 ByteStream mbs;
|
13234
|
1472 aim_mpmsg_section_t *sec;
|
|
1473
|
13592
|
1474 byte_stream_init(&mbs, data, len);
|
|
1475
|
|
1476 while (byte_stream_empty(&mbs)) {
|
13234
|
1477 guint16 msglen, flag1, flag2;
|
|
1478 gchar *msgbuf;
|
|
1479
|
13592
|
1480 byte_stream_get8(&mbs); /* 01 */
|
|
1481 byte_stream_get8(&mbs); /* 01 */
|
13234
|
1482
|
|
1483 /* Message string length, including character set info. */
|
13592
|
1484 msglen = byte_stream_get16(&mbs);
|
|
1485 if (msglen > byte_stream_empty(&mbs))
|
13234
|
1486 {
|
|
1487 gaim_debug_misc("oscar", "Received an IM containing an invalid message part from %s. They are probably trying to do something malicious.", userinfo->sn);
|
|
1488 break;
|
|
1489 }
|
|
1490
|
|
1491 /* Character set info */
|
13592
|
1492 flag1 = byte_stream_get16(&mbs);
|
|
1493 flag2 = byte_stream_get16(&mbs);
|
13234
|
1494
|
|
1495 /* Message. */
|
|
1496 msglen -= 4;
|
|
1497
|
|
1498 /*
|
|
1499 * For now, we don't care what the encoding is. Just copy
|
|
1500 * it into a multipart struct and deal with it later. However,
|
|
1501 * always pad the ending with a NULL. This makes it easier
|
|
1502 * to treat ASCII sections as strings. It won't matter for
|
|
1503 * UNICODE or binary data, as you should never read past
|
|
1504 * the specified data length, which will not include the pad.
|
|
1505 *
|
|
1506 * XXX - There's an API bug here. For sending, the UNICODE is
|
|
1507 * given in host byte order (aim_mpmsg_addunicode), but here
|
|
1508 * the received messages are given in network byte order.
|
|
1509 *
|
|
1510 */
|
13592
|
1511 msgbuf = (gchar *)byte_stream_getraw(&mbs, msglen);
|
|
1512 mpmsg_addsection(od, &args->mpmsg, flag1, flag2, msgbuf, msglen);
|
13234
|
1513
|
|
1514 } /* while */
|
|
1515
|
|
1516 args->icbmflags |= AIM_IMFLAGS_MULTIPART; /* always set */
|
|
1517
|
|
1518 /*
|
|
1519 * Clients that support multiparts should never use args->msg, as it
|
|
1520 * will point to an arbitrary section.
|
|
1521 *
|
|
1522 * Here, we attempt to provide clients that do not support multipart
|
|
1523 * messages with something to look at -- hopefully a human-readable
|
|
1524 * string. But, failing that, a UNICODE message, or nothing at all.
|
|
1525 *
|
|
1526 * Which means that even if args->msg is NULL, it does not mean the
|
|
1527 * message was blank.
|
|
1528 *
|
|
1529 */
|
|
1530 for (i = 0; i < charsetpricount; i++) {
|
|
1531 for (sec = args->mpmsg.parts; sec; sec = sec->next) {
|
|
1532
|
|
1533 if (sec->charset != charsetpri[i])
|
|
1534 continue;
|
|
1535
|
|
1536 /* Great. We found one. Fill it in. */
|
|
1537 args->charset = sec->charset;
|
|
1538 args->charsubset = sec->charsubset;
|
|
1539
|
|
1540 /* Set up the simple flags */
|
|
1541 switch (args->charsubset)
|
|
1542 {
|
|
1543 case 0x0000:
|
|
1544 /* standard subencoding? */
|
|
1545 break;
|
|
1546 case 0x000b:
|
|
1547 args->icbmflags |= AIM_IMFLAGS_SUBENC_MACINTOSH;
|
|
1548 break;
|
|
1549 case 0xffff:
|
|
1550 /* no subencoding */
|
|
1551 break;
|
|
1552 default:
|
|
1553 break;
|
|
1554 }
|
|
1555
|
|
1556 args->msg = sec->data;
|
|
1557 args->msglen = sec->datalen;
|
|
1558
|
|
1559 return 0;
|
|
1560 }
|
|
1561 }
|
|
1562
|
|
1563 /* No human-readable sections found. Oh well. */
|
|
1564 args->charset = args->charsubset = 0xffff;
|
|
1565 args->msg = NULL;
|
|
1566 args->msglen = 0;
|
|
1567
|
|
1568 return 0;
|
|
1569 }
|
|
1570
|
13592
|
1571 static int incomingim_ch1(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, guint16 channel, aim_userinfo_t *userinfo, ByteStream *bs, guint8 *cookie)
|
13234
|
1572 {
|
|
1573 guint16 type, length;
|
|
1574 aim_rxcallback_t userfunc;
|
|
1575 int ret = 0;
|
|
1576 struct aim_incomingim_ch1_args args;
|
|
1577 unsigned int endpos;
|
|
1578
|
|
1579 memset(&args, 0, sizeof(args));
|
|
1580
|
13592
|
1581 aim_mpmsg_init(od, &args.mpmsg);
|
13234
|
1582
|
|
1583 /*
|
|
1584 * This used to be done using tlvchains. For performance reasons,
|
|
1585 * I've changed it to process the TLVs in-place. This avoids lots
|
|
1586 * of per-IM memory allocations.
|
|
1587 */
|
13592
|
1588 while (byte_stream_empty(bs))
|
13234
|
1589 {
|
13592
|
1590 type = byte_stream_get16(bs);
|
|
1591 length = byte_stream_get16(bs);
|
|
1592
|
|
1593 if (length > byte_stream_empty(bs))
|
13234
|
1594 {
|
|
1595 gaim_debug_misc("oscar", "Received an IM containing an invalid message part from %s. They are probably trying to do something malicious.\n", userinfo->sn);
|
|
1596 break;
|
|
1597 }
|
|
1598
|
13592
|
1599 endpos = byte_stream_curpos(bs) + length;
|
13234
|
1600
|
|
1601 if (type == 0x0002) { /* Message Block */
|
|
1602
|
|
1603 /*
|
|
1604 * This TLV consists of the following:
|
|
1605 * - 0501 -- Unknown
|
|
1606 * - Features: Don't know how to interpret these
|
|
1607 * - 0101 -- Unknown
|
|
1608 * - Message
|
|
1609 *
|
|
1610 */
|
|
1611
|
13592
|
1612 byte_stream_get8(bs); /* 05 */
|
|
1613 byte_stream_get8(bs); /* 01 */
|
|
1614
|
|
1615 args.featureslen = byte_stream_get16(bs);
|
|
1616 if (args.featureslen > byte_stream_empty(bs))
|
13234
|
1617 {
|
|
1618 gaim_debug_misc("oscar", "Received an IM containing an invalid message part from %s. They are probably trying to do something malicious.\n", userinfo->sn);
|
|
1619 break;
|
|
1620 }
|
|
1621 if (args.featureslen == 0)
|
|
1622 {
|
|
1623 args.features = NULL;
|
|
1624 }
|
|
1625 else
|
|
1626 {
|
13592
|
1627 args.features = byte_stream_getraw(bs, args.featureslen);
|
13234
|
1628 args.icbmflags |= AIM_IMFLAGS_CUSTOMFEATURES;
|
|
1629 }
|
|
1630
|
|
1631 /*
|
|
1632 * The rest of the TLV contains one or more message
|
|
1633 * blocks...
|
|
1634 */
|
13592
|
1635 incomingim_ch1_parsemsgs(od, userinfo, bs->data + bs->offset /* XXX evil!!! */, length - 2 - 2 - args.featureslen, &args);
|
13234
|
1636
|
|
1637 } else if (type == 0x0003) { /* Server Ack Requested */
|
|
1638
|
|
1639 args.icbmflags |= AIM_IMFLAGS_ACK;
|
|
1640
|
|
1641 } else if (type == 0x0004) { /* Message is Auto Response */
|
|
1642
|
|
1643 args.icbmflags |= AIM_IMFLAGS_AWAY;
|
|
1644
|
|
1645 } else if (type == 0x0006) { /* Message was received offline. */
|
|
1646
|
|
1647 /* XXX - not sure if this actually gets sent. */
|
|
1648 args.icbmflags |= AIM_IMFLAGS_OFFLINE;
|
|
1649
|
|
1650 } else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */
|
|
1651
|
13592
|
1652 args.iconlen = byte_stream_get32(bs);
|
|
1653 byte_stream_get16(bs); /* 0x0001 */
|
|
1654 args.iconsum = byte_stream_get16(bs);
|
|
1655 args.iconstamp = byte_stream_get32(bs);
|
13234
|
1656
|
|
1657 /*
|
|
1658 * This looks to be a client bug. MacAIM 4.3 will
|
|
1659 * send this tag, but with all zero values, in the
|
|
1660 * first message of a conversation. This makes no
|
|
1661 * sense whatsoever, so I'm going to say its a bug.
|
|
1662 *
|
|
1663 * You really shouldn't advertise a zero-length icon
|
|
1664 * anyway.
|
|
1665 *
|
|
1666 */
|
|
1667 if (args.iconlen)
|
|
1668 args.icbmflags |= AIM_IMFLAGS_HASICON;
|
|
1669
|
|
1670 } else if (type == 0x0009) {
|
|
1671
|
|
1672 args.icbmflags |= AIM_IMFLAGS_BUDDYREQ;
|
|
1673
|
|
1674 } else if (type == 0x000b) { /* Non-direct connect typing notification */
|
|
1675
|
|
1676 args.icbmflags |= AIM_IMFLAGS_TYPINGNOT;
|
|
1677
|
|
1678 } else if (type == 0x0017) {
|
|
1679
|
|
1680 free(args.extdata);
|
|
1681 args.extdatalen = length;
|
13592
|
1682 if (args.extdatalen > byte_stream_empty(bs))
|
13234
|
1683 {
|
|
1684 gaim_debug_misc("oscar", "Received an IM containing an invalid message part from %s. They are probably trying to do something malicious.\n", userinfo->sn);
|
|
1685 break;
|
|
1686 }
|
|
1687 if (args.extdatalen == 0)
|
|
1688 args.extdata = NULL;
|
|
1689 else
|
13592
|
1690 args.extdata = byte_stream_getraw(bs, args.extdatalen);
|
13234
|
1691
|
|
1692 } else {
|
|
1693 gaim_debug_misc("oscar", "incomingim_ch1: unknown TLV 0x%04x (len %d)\n", type, length);
|
|
1694 }
|
|
1695
|
|
1696 /*
|
|
1697 * This is here to protect ourselves from ourselves. That
|
|
1698 * is, if something above doesn't completely parse its value
|
|
1699 * section, or, worse, overparses it, this will set the
|
|
1700 * stream where it needs to be in order to land on the next
|
|
1701 * TLV when the loop continues.
|
|
1702 *
|
|
1703 */
|
13592
|
1704 byte_stream_setpos(bs, endpos);
|
13234
|
1705 }
|
|
1706
|
|
1707
|
13592
|
1708 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
1709 ret = userfunc(od, conn, frame, channel, userinfo, &args);
|
|
1710
|
|
1711 aim_mpmsg_free(od, &args.mpmsg);
|
13234
|
1712 free(args.features);
|
|
1713 free(args.extdata);
|
|
1714
|
|
1715 return ret;
|
|
1716 }
|
|
1717
|
13592
|
1718 static void incomingim_ch2_buddylist(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, aim_userinfo_t *userinfo, IcbmArgsCh2 *args, ByteStream *servdata)
|
13234
|
1719 {
|
|
1720
|
|
1721 /*
|
|
1722 * This goes like this...
|
|
1723 *
|
|
1724 * group name length
|
|
1725 * group name
|
|
1726 * num of buddies in group
|
|
1727 * buddy name length
|
|
1728 * buddy name
|
|
1729 * buddy name length
|
|
1730 * buddy name
|
|
1731 * ...
|
|
1732 * group name length
|
|
1733 * group name
|
|
1734 * num of buddies in group
|
|
1735 * buddy name length
|
|
1736 * buddy name
|
|
1737 * ...
|
|
1738 * ...
|
|
1739 */
|
13592
|
1740 while (servdata && byte_stream_empty(servdata)) {
|
13234
|
1741 guint16 gnlen, numb;
|
|
1742 int i;
|
|
1743 char *gn;
|
|
1744
|
13592
|
1745 gnlen = byte_stream_get16(servdata);
|
|
1746 gn = byte_stream_getstr(servdata, gnlen);
|
|
1747 numb = byte_stream_get16(servdata);
|
13234
|
1748
|
|
1749 for (i = 0; i < numb; i++) {
|
|
1750 guint16 bnlen;
|
|
1751 char *bn;
|
|
1752
|
13592
|
1753 bnlen = byte_stream_get16(servdata);
|
|
1754 bn = byte_stream_getstr(servdata, bnlen);
|
13234
|
1755
|
|
1756 gaim_debug_misc("oscar", "got a buddy list from %s: group %s, buddy %s\n", userinfo->sn, gn, bn);
|
|
1757
|
|
1758 free(bn);
|
|
1759 }
|
|
1760
|
|
1761 free(gn);
|
|
1762 }
|
|
1763
|
|
1764 return;
|
|
1765 }
|
|
1766
|
13592
|
1767 static void incomingim_ch2_buddyicon_free(OscarData *od, IcbmArgsCh2 *args)
|
13234
|
1768 {
|
|
1769
|
|
1770 free(args->info.icon.icon);
|
|
1771
|
|
1772 return;
|
|
1773 }
|
|
1774
|
13592
|
1775 static void incomingim_ch2_buddyicon(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, aim_userinfo_t *userinfo, IcbmArgsCh2 *args, ByteStream *servdata)
|
13234
|
1776 {
|
|
1777
|
|
1778 if (servdata) {
|
13592
|
1779 args->info.icon.checksum = byte_stream_get32(servdata);
|
|
1780 args->info.icon.length = byte_stream_get32(servdata);
|
|
1781 args->info.icon.timestamp = byte_stream_get32(servdata);
|
|
1782 args->info.icon.icon = byte_stream_getraw(servdata, args->info.icon.length);
|
13234
|
1783 }
|
|
1784
|
|
1785 args->destructor = (void *)incomingim_ch2_buddyicon_free;
|
|
1786
|
|
1787 return;
|
|
1788 }
|
|
1789
|
13592
|
1790 static void incomingim_ch2_chat_free(OscarData *od, IcbmArgsCh2 *args)
|
13234
|
1791 {
|
|
1792
|
|
1793 /* XXX - aim_chat_roominfo_free() */
|
|
1794 free(args->info.chat.roominfo.name);
|
|
1795
|
|
1796 return;
|
|
1797 }
|
|
1798
|
13592
|
1799 static void incomingim_ch2_chat(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, aim_userinfo_t *userinfo, IcbmArgsCh2 *args, ByteStream *servdata)
|
13234
|
1800 {
|
|
1801
|
|
1802 /*
|
|
1803 * Chat room info.
|
|
1804 */
|
|
1805 if (servdata)
|
|
1806 aim_chat_readroominfo(servdata, &args->info.chat.roominfo);
|
|
1807
|
|
1808 args->destructor = (void *)incomingim_ch2_chat_free;
|
|
1809
|
|
1810 return;
|
|
1811 }
|
|
1812
|
13592
|
1813 static void incomingim_ch2_icqserverrelay_free(OscarData *od, IcbmArgsCh2 *args)
|
13234
|
1814 {
|
|
1815
|
|
1816 free((char *)args->info.rtfmsg.rtfmsg);
|
|
1817
|
|
1818 return;
|
|
1819 }
|
|
1820
|
|
1821 /*
|
13592
|
1822 * The relationship between OSCAR_CAPABILITY_ICQSERVERRELAY and OSCAR_CAPABILITY_ICQRTF is
|
13234
|
1823 * kind of odd. This sends the client ICQRTF since that is all that I've seen
|
|
1824 * SERVERRELAY used for.
|
|
1825 *
|
|
1826 * Note that this is all little-endian. Cringe.
|
|
1827 *
|
|
1828 */
|
13592
|
1829 static void incomingim_ch2_icqserverrelay(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, aim_userinfo_t *userinfo, IcbmArgsCh2 *args, ByteStream *servdata)
|
13234
|
1830 {
|
|
1831 guint16 hdrlen, anslen, msglen;
|
|
1832
|
13592
|
1833 hdrlen = byte_stream_getle16(servdata);
|
|
1834 byte_stream_advance(servdata, hdrlen);
|
|
1835
|
|
1836 hdrlen = byte_stream_getle16(servdata);
|
|
1837 byte_stream_advance(servdata, hdrlen);
|
|
1838
|
|
1839 args->info.rtfmsg.msgtype = byte_stream_getle16(servdata);
|
|
1840
|
|
1841 anslen = byte_stream_getle32(servdata);
|
|
1842 byte_stream_advance(servdata, anslen);
|
|
1843
|
|
1844 msglen = byte_stream_getle16(servdata);
|
|
1845 args->info.rtfmsg.rtfmsg = byte_stream_getstr(servdata, msglen);
|
|
1846
|
|
1847 args->info.rtfmsg.fgcolor = byte_stream_getle32(servdata);
|
|
1848 args->info.rtfmsg.bgcolor = byte_stream_getle32(servdata);
|
|
1849
|
|
1850 hdrlen = byte_stream_getle32(servdata);
|
|
1851 byte_stream_advance(servdata, hdrlen);
|
13234
|
1852
|
|
1853 args->destructor = (void *)incomingim_ch2_icqserverrelay_free;
|
|
1854
|
|
1855 return;
|
|
1856 }
|
|
1857
|
13592
|
1858 static void incomingim_ch2_sendfile_free(OscarData *od, IcbmArgsCh2 *args)
|
13234
|
1859 {
|
|
1860 free(args->info.sendfile.filename);
|
|
1861 }
|
|
1862
|
13592
|
1863 static void incomingim_ch2_sendfile(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, aim_userinfo_t *userinfo, IcbmArgsCh2 *args, ByteStream *servdata)
|
13234
|
1864 {
|
|
1865
|
|
1866 args->destructor = (void *)incomingim_ch2_sendfile_free;
|
|
1867
|
|
1868 /* Maybe there is a better way to tell what kind of sendfile
|
|
1869 * this is? Maybe TLV t(000a)? */
|
|
1870 if (servdata) { /* Someone is sending us a file */
|
|
1871 int flen;
|
|
1872
|
|
1873 /* subtype is one of AIM_OFT_SUBTYPE_* */
|
13592
|
1874 args->info.sendfile.subtype = byte_stream_get16(servdata);
|
|
1875 args->info.sendfile.totfiles = byte_stream_get16(servdata);
|
|
1876 args->info.sendfile.totsize = byte_stream_get32(servdata);
|
13234
|
1877
|
|
1878 /*
|
|
1879 * I hope to God I'm right when I guess that there is a
|
|
1880 * 32 char max filename length for single files. I think
|
|
1881 * OFT tends to do that. Gotta love inconsistency. I saw
|
|
1882 * a 26 byte filename?
|
|
1883 */
|
13592
|
1884 /* AAA - create an byte_stream_getnullstr function (don't anymore)(maybe) */
|
13234
|
1885 /* Use an inelegant way of getting the null-terminated filename,
|
|
1886 * since there's no easy bstream routine. */
|
13592
|
1887 for (flen = 0; byte_stream_get8(servdata); flen++);
|
|
1888 byte_stream_advance(servdata, -flen -1);
|
|
1889 args->info.sendfile.filename = byte_stream_getstr(servdata, flen);
|
13234
|
1890
|
|
1891 /* There is sometimes more after the null-terminated filename,
|
|
1892 * but I'm unsure of its format. */
|
|
1893 /* I don't believe him. */
|
|
1894 /* There is sometimes a null byte inside a unicode filename,
|
|
1895 * but as far as I can tell the filename is the last
|
|
1896 * piece of data that will be in this message. --Jonathan */
|
|
1897 }
|
|
1898
|
|
1899 return;
|
|
1900 }
|
|
1901
|
13592
|
1902 typedef void (*ch2_args_destructor_t)(OscarData *od, IcbmArgsCh2 *args);
|
|
1903
|
|
1904 static int incomingim_ch2(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, guint16 channel, aim_userinfo_t *userinfo, aim_tlvlist_t *tlvlist, guint8 *cookie)
|
13234
|
1905 {
|
|
1906 aim_rxcallback_t userfunc;
|
|
1907 aim_tlv_t *block1, *servdatatlv;
|
|
1908 aim_tlvlist_t *list2;
|
13592
|
1909 IcbmArgsCh2 args;
|
13239
|
1910 ByteStream bbs, sdbs, *sdbsptr = NULL;
|
13234
|
1911 guint8 *cookie2;
|
|
1912 int ret = 0;
|
|
1913
|
|
1914 char proxyip[30] = {""};
|
|
1915 char clientip[30] = {""};
|
|
1916 char verifiedip[30] = {""};
|
|
1917
|
|
1918 memset(&args, 0, sizeof(args));
|
|
1919
|
|
1920 /*
|
|
1921 * There's another block of TLVs embedded in the type 5 here.
|
|
1922 */
|
|
1923 block1 = aim_tlv_gettlv(tlvlist, 0x0005, 1);
|
13592
|
1924 byte_stream_init(&bbs, block1->value, block1->length);
|
13234
|
1925
|
|
1926 /*
|
|
1927 * First two bytes represent the status of the connection.
|
13592
|
1928 * One of the AIM_RENDEZVOUS_ defines.
|
13234
|
1929 *
|
|
1930 * 0 is a request, 1 is a cancel, 2 is an accept
|
|
1931 */
|
13592
|
1932 args.status = byte_stream_get16(&bbs);
|
13234
|
1933
|
|
1934 /*
|
|
1935 * Next comes the cookie. Should match the ICBM cookie.
|
|
1936 */
|
13592
|
1937 cookie2 = byte_stream_getraw(&bbs, 8);
|
13234
|
1938 if (memcmp(cookie, cookie2, 8) != 0)
|
|
1939 gaim_debug_misc("oscar", "rend: warning cookies don't match!\n");
|
|
1940 memcpy(args.cookie, cookie2, 8);
|
|
1941 free(cookie2);
|
|
1942
|
|
1943 /*
|
|
1944 * The next 16bytes are a capability block so we can
|
|
1945 * identify what type of rendezvous this is.
|
|
1946 */
|
13592
|
1947 args.type = aim_locate_getcaps(od, &bbs, 0x10);
|
13234
|
1948
|
|
1949 /*
|
|
1950 * What follows may be TLVs or nothing, depending on the
|
|
1951 * purpose of the message.
|
|
1952 *
|
|
1953 * Ack packets for instance have nothing more to them.
|
|
1954 */
|
|
1955 list2 = aim_tlvlist_read(&bbs);
|
|
1956
|
|
1957 /*
|
|
1958 * IP address to proxy the file transfer through.
|
|
1959 *
|
13592
|
1960 * TODO: I don't like this. Maybe just read in an int? Or inet_ntoa...
|
13234
|
1961 */
|
|
1962 if (aim_tlv_gettlv(list2, 0x0002, 1)) {
|
|
1963 aim_tlv_t *iptlv;
|
|
1964
|
|
1965 iptlv = aim_tlv_gettlv(list2, 0x0002, 1);
|
|
1966 if (iptlv->length == 4)
|
|
1967 snprintf(proxyip, sizeof(proxyip), "%hhu.%hhu.%hhu.%hhu",
|
|
1968 iptlv->value[0], iptlv->value[1],
|
|
1969 iptlv->value[2], iptlv->value[3]);
|
|
1970 }
|
|
1971
|
|
1972 /*
|
|
1973 * IP address from the perspective of the client.
|
|
1974 */
|
|
1975 if (aim_tlv_gettlv(list2, 0x0003, 1)) {
|
|
1976 aim_tlv_t *iptlv;
|
|
1977
|
|
1978 iptlv = aim_tlv_gettlv(list2, 0x0003, 1);
|
|
1979 if (iptlv->length == 4)
|
|
1980 snprintf(clientip, sizeof(clientip), "%hhu.%hhu.%hhu.%hhu",
|
|
1981 iptlv->value[0], iptlv->value[1],
|
|
1982 iptlv->value[2], iptlv->value[3]);
|
|
1983 }
|
|
1984
|
|
1985 /*
|
|
1986 * Verified IP address (from the perspective of Oscar).
|
|
1987 *
|
|
1988 * This is added by the server.
|
|
1989 */
|
|
1990 if (aim_tlv_gettlv(list2, 0x0004, 1)) {
|
|
1991 aim_tlv_t *iptlv;
|
|
1992
|
|
1993 iptlv = aim_tlv_gettlv(list2, 0x0004, 1);
|
|
1994 if (iptlv->length == 4)
|
|
1995 snprintf(verifiedip, sizeof(verifiedip), "%hhu.%hhu.%hhu.%hhu",
|
|
1996 iptlv->value[0], iptlv->value[1],
|
|
1997 iptlv->value[2], iptlv->value[3]);
|
|
1998 }
|
|
1999
|
|
2000 /*
|
|
2001 * Port number for something.
|
|
2002 */
|
|
2003 if (aim_tlv_gettlv(list2, 0x0005, 1))
|
|
2004 args.port = aim_tlv_get16(list2, 0x0005, 1);
|
|
2005
|
|
2006 /*
|
13592
|
2007 * File transfer "request number":
|
|
2008 * 0x0001 - Initial file transfer request for no proxy or stage 1 proxy
|
|
2009 * 0x0002 - "Reply request" for a stage 2 proxy (receiver wants to use proxy)
|
|
2010 * 0x0003 - A third request has been sent; applies only to stage 3 proxied transfers
|
13234
|
2011 */
|
|
2012 if (aim_tlv_gettlv(list2, 0x000a, 1))
|
13592
|
2013 args.requestnumber = aim_tlv_get16(list2, 0x000a, 1);
|
13234
|
2014
|
|
2015 /*
|
13592
|
2016 * Terminate connection/error code. 0x0001 means the other user
|
|
2017 * canceled the connection.
|
13234
|
2018 */
|
|
2019 if (aim_tlv_gettlv(list2, 0x000b, 1))
|
|
2020 args.errorcode = aim_tlv_get16(list2, 0x000b, 1);
|
|
2021
|
|
2022 /*
|
|
2023 * Invitation message / chat description.
|
|
2024 */
|
|
2025 if (aim_tlv_gettlv(list2, 0x000c, 1)) {
|
|
2026 args.msg = aim_tlv_getstr(list2, 0x000c, 1);
|
|
2027 args.msglen = aim_tlv_getlength(list2, 0x000c, 1);
|
|
2028 }
|
|
2029
|
|
2030 /*
|
|
2031 * Character set.
|
|
2032 */
|
|
2033 if (aim_tlv_gettlv(list2, 0x000d, 1))
|
|
2034 args.encoding = aim_tlv_getstr(list2, 0x000d, 1);
|
|
2035
|
|
2036 /*
|
|
2037 * Language.
|
|
2038 */
|
|
2039 if (aim_tlv_gettlv(list2, 0x000e, 1))
|
|
2040 args.language = aim_tlv_getstr(list2, 0x000e, 1);
|
|
2041
|
|
2042 #if 0
|
|
2043 /*
|
|
2044 * Unknown -- no value
|
|
2045 *
|
|
2046 * Maybe means we should connect directly to transfer the file?
|
|
2047 * Also used in ICQ Lite Beta 4.0 URLs. Also empty.
|
|
2048 */
|
|
2049 /* I don't think this indicates a direct transfer; this flag is
|
|
2050 * also present in a stage 1 proxied file send request -- Jonathan */
|
|
2051 if (aim_tlv_gettlv(list2, 0x000f, 1)) {
|
|
2052 /* Unhandled */
|
|
2053 }
|
|
2054 #endif
|
|
2055
|
|
2056 /*
|
|
2057 * Flag meaning we should proxy the file transfer through an AIM server
|
|
2058 */
|
|
2059 if (aim_tlv_gettlv(list2, 0x0010, 1))
|
13592
|
2060 args.use_proxy = TRUE;
|
13234
|
2061
|
|
2062 if (strlen(proxyip))
|
|
2063 args.proxyip = (char *)proxyip;
|
|
2064 if (strlen(clientip))
|
|
2065 args.clientip = (char *)clientip;
|
|
2066 if (strlen(verifiedip))
|
|
2067 args.verifiedip = (char *)verifiedip;
|
|
2068
|
|
2069 /*
|
|
2070 * This must be present in PROPOSALs, but will probably not
|
|
2071 * exist in CANCELs and ACCEPTs. Also exists in ICQ Lite
|
13592
|
2072 * Beta 4.0 URLs (OSCAR_CAPABILITY_ICQSERVERRELAY).
|
13234
|
2073 *
|
|
2074 * Service Data blocks are module-specific in format.
|
|
2075 */
|
|
2076 if ((servdatatlv = aim_tlv_gettlv(list2, 0x2711 /* 10001 */, 1))) {
|
|
2077
|
13592
|
2078 byte_stream_init(&sdbs, servdatatlv->value, servdatatlv->length);
|
13234
|
2079 sdbsptr = &sdbs;
|
|
2080 }
|
|
2081
|
|
2082 /*
|
|
2083 * The rest of the handling depends on what type it is.
|
|
2084 *
|
|
2085 * Not all of them have special handling (yet).
|
|
2086 */
|
13592
|
2087 if (args.type & OSCAR_CAPABILITY_BUDDYICON)
|
|
2088 incomingim_ch2_buddyicon(od, conn, mod, frame, snac, userinfo, &args, sdbsptr);
|
|
2089 else if (args.type & OSCAR_CAPABILITY_SENDBUDDYLIST)
|
|
2090 incomingim_ch2_buddylist(od, conn, mod, frame, snac, userinfo, &args, sdbsptr);
|
|
2091 else if (args.type & OSCAR_CAPABILITY_CHAT)
|
|
2092 incomingim_ch2_chat(od, conn, mod, frame, snac, userinfo, &args, sdbsptr);
|
|
2093 else if (args.type & OSCAR_CAPABILITY_ICQSERVERRELAY)
|
|
2094 incomingim_ch2_icqserverrelay(od, conn, mod, frame, snac, userinfo, &args, sdbsptr);
|
|
2095 else if (args.type & OSCAR_CAPABILITY_SENDFILE)
|
|
2096 incomingim_ch2_sendfile(od, conn, mod, frame, snac, userinfo, &args, sdbsptr);
|
|
2097
|
|
2098 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2099 ret = userfunc(od, conn, frame, channel, userinfo, &args);
|
13234
|
2100
|
|
2101
|
|
2102 if (args.destructor)
|
13592
|
2103 ((ch2_args_destructor_t)args.destructor)(od, &args);
|
13234
|
2104
|
|
2105 free((char *)args.msg);
|
|
2106 free((char *)args.encoding);
|
|
2107 free((char *)args.language);
|
|
2108
|
|
2109 aim_tlvlist_free(&list2);
|
|
2110
|
|
2111 return ret;
|
|
2112 }
|
|
2113
|
13592
|
2114 static int incomingim_ch4(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, guint16 channel, aim_userinfo_t *userinfo, aim_tlvlist_t *tlvlist, guint8 *cookie)
|
13234
|
2115 {
|
13239
|
2116 ByteStream meat;
|
13234
|
2117 aim_rxcallback_t userfunc;
|
|
2118 aim_tlv_t *block;
|
|
2119 struct aim_incomingim_ch4_args args;
|
|
2120 int ret = 0;
|
|
2121
|
|
2122 /*
|
|
2123 * Make a bstream for the meaty part. Yum. Meat.
|
|
2124 */
|
|
2125 if (!(block = aim_tlv_gettlv(tlvlist, 0x0005, 1)))
|
|
2126 return -1;
|
13592
|
2127 byte_stream_init(&meat, block->value, block->length);
|
|
2128
|
|
2129 args.uin = byte_stream_getle32(&meat);
|
|
2130 args.type = byte_stream_getle8(&meat);
|
|
2131 args.flags = byte_stream_getle8(&meat);
|
|
2132 args.msglen = byte_stream_getle16(&meat);
|
|
2133 args.msg = (gchar *)byte_stream_getraw(&meat, args.msglen);
|
|
2134
|
|
2135 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2136 ret = userfunc(od, conn, frame, channel, userinfo, &args);
|
13234
|
2137
|
|
2138 free(args.msg);
|
|
2139
|
|
2140 return ret;
|
|
2141 }
|
|
2142
|
|
2143 /*
|
|
2144 * Subtype 0x0007
|
|
2145 *
|
|
2146 * It can easily be said that parsing ICBMs is THE single
|
|
2147 * most difficult thing to do in the in AIM protocol. In
|
|
2148 * fact, I think I just did say that.
|
|
2149 *
|
|
2150 * Below is the best damned solution I've come up with
|
|
2151 * over the past sixteen months of battling with it. This
|
|
2152 * can parse both away and normal messages from every client
|
|
2153 * I have access to. Its not fast, its not clean. But it works.
|
|
2154 *
|
|
2155 */
|
13592
|
2156 static int incomingim(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
2157 {
|
|
2158 int ret = 0;
|
|
2159 guchar *cookie;
|
|
2160 guint16 channel;
|
|
2161 aim_userinfo_t userinfo;
|
|
2162
|
|
2163 memset(&userinfo, 0x00, sizeof(aim_userinfo_t));
|
|
2164
|
|
2165 /*
|
|
2166 * Read ICBM Cookie.
|
|
2167 */
|
13592
|
2168 cookie = byte_stream_getraw(bs, 8);
|
13234
|
2169
|
|
2170 /*
|
|
2171 * Channel ID.
|
|
2172 *
|
|
2173 * Channel 0x0001 is the message channel. It is
|
|
2174 * used to send basic ICBMs.
|
|
2175 *
|
|
2176 * Channel 0x0002 is the Rendezvous channel, which
|
|
2177 * is where Chat Invitiations and various client-client
|
|
2178 * connection negotiations come from.
|
|
2179 *
|
|
2180 * Channel 0x0003 is used for chat messages.
|
|
2181 *
|
|
2182 * Channel 0x0004 is used for ICQ authorization, or
|
|
2183 * possibly any system notice.
|
|
2184 *
|
|
2185 */
|
13592
|
2186 channel = byte_stream_get16(bs);
|
13234
|
2187
|
|
2188 /*
|
|
2189 * Extract the standard user info block.
|
|
2190 *
|
|
2191 * Note that although this contains TLVs that appear contiguous
|
|
2192 * with the TLVs read below, they are two different pieces. The
|
|
2193 * userinfo block contains the number of TLVs that contain user
|
|
2194 * information, the rest are not even though there is no separation.
|
|
2195 * You can start reading the message TLVs after aim_info_extract()
|
|
2196 * parses out the standard userinfo block.
|
|
2197 *
|
|
2198 * That also means that TLV types can be duplicated between the
|
|
2199 * userinfo block and the rest of the message, however there should
|
|
2200 * never be two TLVs of the same type in one block.
|
|
2201 *
|
|
2202 */
|
13592
|
2203 aim_info_extract(od, bs, &userinfo);
|
13234
|
2204
|
|
2205 /*
|
|
2206 * From here on, its depends on what channel we're on.
|
|
2207 *
|
|
2208 * Technically all channels have a TLV list have this, however,
|
|
2209 * for the common channel 1 case, in-place parsing is used for
|
|
2210 * performance reasons (less memory allocation).
|
|
2211 */
|
|
2212 if (channel == 1) {
|
|
2213
|
13592
|
2214 ret = incomingim_ch1(od, conn, mod, frame, snac, channel, &userinfo, bs, cookie);
|
13234
|
2215
|
|
2216 } else if (channel == 2) {
|
|
2217 aim_tlvlist_t *tlvlist;
|
|
2218
|
|
2219 /*
|
|
2220 * Read block of TLVs (not including the userinfo data). All
|
|
2221 * further data is derived from what is parsed here.
|
|
2222 */
|
|
2223 tlvlist = aim_tlvlist_read(bs);
|
|
2224
|
13592
|
2225 ret = incomingim_ch2(od, conn, mod, frame, snac, channel, &userinfo, tlvlist, cookie);
|
13234
|
2226
|
|
2227 aim_tlvlist_free(&tlvlist);
|
|
2228
|
|
2229 } else if (channel == 4) {
|
|
2230 aim_tlvlist_t *tlvlist;
|
|
2231
|
|
2232 tlvlist = aim_tlvlist_read(bs);
|
13592
|
2233 ret = incomingim_ch4(od, conn, mod, frame, snac, channel, &userinfo, tlvlist, cookie);
|
13234
|
2234 aim_tlvlist_free(&tlvlist);
|
|
2235
|
|
2236 } else {
|
|
2237 gaim_debug_misc("oscar", "icbm: ICBM received on an unsupported channel. Ignoring. (chan = %04x)\n", channel);
|
|
2238 }
|
|
2239
|
|
2240 aim_info_free(&userinfo);
|
|
2241 free(cookie);
|
|
2242
|
|
2243 return ret;
|
|
2244 }
|
|
2245
|
|
2246 /*
|
|
2247 * Subtype 0x0008 - Send a warning to sn.
|
|
2248 *
|
|
2249 * Flags:
|
|
2250 * AIM_WARN_ANON Send as an anonymous (doesn't count as much)
|
|
2251 *
|
|
2252 * returns -1 on error (couldn't alloc packet), 0 on success.
|
|
2253 *
|
|
2254 */
|
13592
|
2255 int aim_im_warn(OscarData *od, FlapConnection *conn, const char *sn, guint32 flags)
|
13234
|
2256 {
|
13592
|
2257 FlapFrame *frame;
|
13234
|
2258 aim_snacid_t snacid;
|
|
2259
|
13592
|
2260 if (!od || !conn || !sn)
|
13234
|
2261 return -EINVAL;
|
|
2262
|
13592
|
2263 frame = flap_frame_new(od, 0x02, strlen(sn)+13);
|
|
2264
|
|
2265 snacid = aim_cachesnac(od, 0x0004, 0x0008, 0x0000, sn, strlen(sn)+1);
|
|
2266 aim_putsnac(&frame->data, 0x0004, 0x0008, 0x0000, snacid);
|
|
2267
|
|
2268 byte_stream_put16(&frame->data, (flags & AIM_WARN_ANON) ? 0x0001 : 0x0000);
|
|
2269 byte_stream_put8(&frame->data, strlen(sn));
|
|
2270 byte_stream_putstr(&frame->data, sn);
|
|
2271
|
|
2272 flap_connection_send(conn, frame);
|
13234
|
2273
|
|
2274 return 0;
|
|
2275 }
|
|
2276
|
|
2277 /* Subtype 0x000a */
|
13592
|
2278 static int missedcall(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
2279 {
|
|
2280 int ret = 0;
|
|
2281 aim_rxcallback_t userfunc;
|
|
2282 guint16 channel, nummissed, reason;
|
|
2283 aim_userinfo_t userinfo;
|
|
2284
|
13592
|
2285 while (byte_stream_empty(bs)) {
|
|
2286
|
|
2287 channel = byte_stream_get16(bs);
|
|
2288 aim_info_extract(od, bs, &userinfo);
|
|
2289 nummissed = byte_stream_get16(bs);
|
|
2290 reason = byte_stream_get16(bs);
|
|
2291
|
|
2292 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2293 ret = userfunc(od, conn, frame, channel, &userinfo, nummissed, reason);
|
13234
|
2294
|
|
2295 aim_info_free(&userinfo);
|
|
2296 }
|
|
2297
|
|
2298 return ret;
|
|
2299 }
|
|
2300
|
|
2301 /*
|
|
2302 * Subtype 0x000b
|
|
2303 *
|
|
2304 * Possible codes:
|
|
2305 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
|
|
2306 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
|
|
2307 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
|
|
2308 *
|
|
2309 */
|
13592
|
2310 int aim_im_denytransfer(OscarData *od, const char *sn, const guchar *cookie, guint16 code)
|
13234
|
2311 {
|
13592
|
2312 FlapConnection *conn;
|
|
2313 FlapFrame *frame;
|
13234
|
2314 aim_snacid_t snacid;
|
|
2315 aim_tlvlist_t *tl = NULL;
|
|
2316
|
13592
|
2317 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
|
13234
|
2318 return -EINVAL;
|
|
2319
|
13592
|
2320 frame = flap_frame_new(od, 0x02, 10+8+2+1+strlen(sn)+6);
|
|
2321
|
|
2322 snacid = aim_cachesnac(od, 0x0004, 0x000b, 0x0000, NULL, 0);
|
|
2323 aim_putsnac(&frame->data, 0x0004, 0x000b, 0x0000, snacid);
|
|
2324
|
|
2325 byte_stream_putraw(&frame->data, cookie, 8);
|
|
2326
|
|
2327 byte_stream_put16(&frame->data, 0x0002); /* channel */
|
|
2328 byte_stream_put8(&frame->data, strlen(sn));
|
|
2329 byte_stream_putstr(&frame->data, sn);
|
13234
|
2330
|
|
2331 aim_tlvlist_add_16(&tl, 0x0003, code);
|
13592
|
2332 aim_tlvlist_write(&frame->data, &tl);
|
13234
|
2333 aim_tlvlist_free(&tl);
|
|
2334
|
13592
|
2335 flap_connection_send(conn, frame);
|
13234
|
2336
|
|
2337 return 0;
|
|
2338 }
|
|
2339
|
|
2340 /*
|
13592
|
2341 * Subtype 0x000b - Receive the response from an ICQ status message
|
|
2342 * request (in which case this contains the ICQ status message) or
|
|
2343 * a file transfer or direct IM request was declined.
|
13234
|
2344 */
|
13592
|
2345 static int clientautoresp(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
2346 {
|
|
2347 int ret = 0;
|
|
2348 aim_rxcallback_t userfunc;
|
|
2349 guint16 channel, reason;
|
|
2350 char *sn;
|
|
2351 guchar *cookie;
|
|
2352 guint8 snlen;
|
|
2353
|
13592
|
2354 cookie = byte_stream_getraw(bs, 8);
|
|
2355 channel = byte_stream_get16(bs);
|
|
2356 snlen = byte_stream_get8(bs);
|
|
2357 sn = byte_stream_getstr(bs, snlen);
|
|
2358 reason = byte_stream_get16(bs);
|
13234
|
2359
|
|
2360 if (channel == 0x0002) { /* File transfer declined */
|
13592
|
2361 byte_stream_get16(bs); /* Unknown */
|
|
2362 byte_stream_get16(bs); /* Unknown */
|
|
2363 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2364 ret = userfunc(od, conn, frame, channel, sn, reason, cookie);
|
13234
|
2365 } else if (channel == 0x0004) { /* ICQ message */
|
|
2366 switch (reason) {
|
|
2367 case 0x0003: { /* ICQ status message. Maybe other stuff too, you never know with these people. */
|
|
2368 guint8 statusmsgtype, *msg;
|
|
2369 guint16 len;
|
|
2370 guint32 state;
|
|
2371
|
13592
|
2372 len = byte_stream_getle16(bs); /* Should be 0x001b */
|
|
2373 byte_stream_advance(bs, len); /* Unknown */
|
|
2374
|
|
2375 len = byte_stream_getle16(bs); /* Should be 0x000e */
|
|
2376 byte_stream_advance(bs, len); /* Unknown */
|
|
2377
|
|
2378 statusmsgtype = byte_stream_getle8(bs);
|
13234
|
2379 switch (statusmsgtype) {
|
|
2380 case 0xe8:
|
|
2381 state = AIM_ICQ_STATE_AWAY;
|
|
2382 break;
|
|
2383 case 0xe9:
|
|
2384 state = AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_BUSY;
|
|
2385 break;
|
|
2386 case 0xea:
|
|
2387 state = AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_OUT;
|
|
2388 break;
|
|
2389 case 0xeb:
|
|
2390 state = AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_DND | AIM_ICQ_STATE_BUSY;
|
|
2391 break;
|
|
2392 case 0xec:
|
|
2393 state = AIM_ICQ_STATE_CHAT;
|
|
2394 break;
|
|
2395 default:
|
|
2396 state = 0;
|
|
2397 break;
|
|
2398 }
|
|
2399
|
13592
|
2400 byte_stream_getle8(bs); /* Unknown - 0x03 Maybe this means this is an auto-reply */
|
|
2401 byte_stream_getle16(bs); /* Unknown - 0x0000 */
|
|
2402 byte_stream_getle16(bs); /* Unknown - 0x0000 */
|
|
2403
|
|
2404 len = byte_stream_getle16(bs);
|
|
2405 msg = byte_stream_getraw(bs, len);
|
|
2406
|
|
2407 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2408 ret = userfunc(od, conn, frame, channel, sn, reason, state, msg);
|
13234
|
2409
|
|
2410 free(msg);
|
|
2411 } break;
|
|
2412
|
|
2413 default: {
|
13592
|
2414 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2415 ret = userfunc(od, conn, frame, channel, sn, reason);
|
13234
|
2416 } break;
|
|
2417 } /* end switch */
|
|
2418 }
|
|
2419
|
|
2420 free(cookie);
|
|
2421 free(sn);
|
|
2422
|
|
2423 return ret;
|
|
2424 }
|
|
2425
|
|
2426 /*
|
|
2427 * Subtype 0x000c - Receive an ack after sending an ICBM.
|
|
2428 *
|
|
2429 * You have to have send the message with the AIM_IMFLAGS_ACK flag set
|
|
2430 * (TLV t(0003)). The ack contains the ICBM header of the message you
|
|
2431 * sent.
|
|
2432 *
|
|
2433 */
|
13592
|
2434 static int msgack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
2435 {
|
|
2436 aim_rxcallback_t userfunc;
|
|
2437 guint16 ch;
|
|
2438 guchar *cookie;
|
|
2439 char *sn;
|
|
2440 int ret = 0;
|
|
2441
|
13592
|
2442 cookie = byte_stream_getraw(bs, 8);
|
|
2443 ch = byte_stream_get16(bs);
|
|
2444 sn = byte_stream_getstr(bs, byte_stream_get8(bs));
|
|
2445
|
|
2446 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2447 ret = userfunc(od, conn, frame, ch, sn);
|
13234
|
2448
|
|
2449 free(sn);
|
|
2450 free(cookie);
|
|
2451
|
|
2452 return ret;
|
|
2453 }
|
|
2454
|
|
2455 /*
|
|
2456 * Subtype 0x0014 - Send a mini typing notification (mtn) packet.
|
|
2457 *
|
|
2458 * This is supported by winaim5 and newer, MacAIM bleh and newer, iChat bleh and newer,
|
|
2459 * and Gaim 0.60 and newer.
|
|
2460 *
|
|
2461 */
|
13592
|
2462 int aim_im_sendmtn(OscarData *od, guint16 type1, const char *sn, guint16 type2)
|
13234
|
2463 {
|
13592
|
2464 FlapConnection *conn;
|
|
2465 FlapFrame *frame;
|
13234
|
2466 aim_snacid_t snacid;
|
|
2467
|
13592
|
2468 if (!od || !(conn = flap_connection_findbygroup(od, 0x0002)))
|
13234
|
2469 return -EINVAL;
|
|
2470
|
|
2471 if (!sn)
|
|
2472 return -EINVAL;
|
|
2473
|
13592
|
2474 frame = flap_frame_new(od, 0x02, 10+11+strlen(sn)+2);
|
|
2475
|
|
2476 snacid = aim_cachesnac(od, 0x0004, 0x0014, 0x0000, NULL, 0);
|
|
2477 aim_putsnac(&frame->data, 0x0004, 0x0014, 0x0000, snacid);
|
13234
|
2478
|
|
2479 /*
|
|
2480 * 8 days of light
|
|
2481 * Er, that is to say, 8 bytes of 0's
|
|
2482 */
|
13592
|
2483 byte_stream_put16(&frame->data, 0x0000);
|
|
2484 byte_stream_put16(&frame->data, 0x0000);
|
|
2485 byte_stream_put16(&frame->data, 0x0000);
|
|
2486 byte_stream_put16(&frame->data, 0x0000);
|
13234
|
2487
|
|
2488 /*
|
|
2489 * Type 1 (should be 0x0001 for mtn)
|
|
2490 */
|
13592
|
2491 byte_stream_put16(&frame->data, type1);
|
13234
|
2492
|
|
2493 /*
|
|
2494 * Dest sn
|
|
2495 */
|
13592
|
2496 byte_stream_put8(&frame->data, strlen(sn));
|
|
2497 byte_stream_putstr(&frame->data, sn);
|
13234
|
2498
|
|
2499 /*
|
|
2500 * Type 2 (should be 0x0000, 0x0001, or 0x0002 for mtn)
|
|
2501 */
|
13592
|
2502 byte_stream_put16(&frame->data, type2);
|
|
2503
|
|
2504 flap_connection_send(conn, frame);
|
13234
|
2505
|
|
2506 return 0;
|
|
2507 }
|
|
2508
|
|
2509 /*
|
|
2510 * Subtype 0x0014 - Receive a mini typing notification (mtn) packet.
|
|
2511 *
|
|
2512 * This is supported by winaim5 and newer, MacAIM bleh and newer, iChat bleh and newer,
|
|
2513 * and Gaim 0.60 and newer.
|
|
2514 *
|
|
2515 */
|
13592
|
2516 static int mtn_receive(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
2517 {
|
|
2518 int ret = 0;
|
|
2519 aim_rxcallback_t userfunc;
|
|
2520 char *sn;
|
|
2521 guint8 snlen;
|
|
2522 guint16 type1, type2;
|
|
2523
|
13592
|
2524 byte_stream_advance(bs, 8); /* Unknown - All 0's */
|
|
2525 type1 = byte_stream_get16(bs);
|
|
2526 snlen = byte_stream_get8(bs);
|
|
2527 sn = byte_stream_getstr(bs, snlen);
|
|
2528 type2 = byte_stream_get16(bs);
|
|
2529
|
|
2530 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
2531 ret = userfunc(od, conn, frame, type1, sn, type2);
|
13234
|
2532
|
|
2533 free(sn);
|
|
2534
|
|
2535 return ret;
|
|
2536 }
|
|
2537
|
13592
|
2538 static int
|
|
2539 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
2540 {
|
|
2541 if (snac->subtype == 0x0005)
|
13592
|
2542 return aim_im_paraminfo(od, conn, mod, frame, snac, bs);
|
13234
|
2543 else if (snac->subtype == 0x0006)
|
13592
|
2544 return outgoingim(od, conn, mod, frame, snac, bs);
|
13234
|
2545 else if (snac->subtype == 0x0007)
|
13592
|
2546 return incomingim(od, conn, mod, frame, snac, bs);
|
13234
|
2547 else if (snac->subtype == 0x000a)
|
13592
|
2548 return missedcall(od, conn, mod, frame, snac, bs);
|
13234
|
2549 else if (snac->subtype == 0x000b)
|
13592
|
2550 return clientautoresp(od, conn, mod, frame, snac, bs);
|
13234
|
2551 else if (snac->subtype == 0x000c)
|
13592
|
2552 return msgack(od, conn, mod, frame, snac, bs);
|
13234
|
2553 else if (snac->subtype == 0x0014)
|
13592
|
2554 return mtn_receive(od, conn, mod, frame, snac, bs);
|
13234
|
2555
|
|
2556 return 0;
|
|
2557 }
|
|
2558
|
13592
|
2559 int
|
|
2560 msg_modfirst(OscarData *od, aim_module_t *mod)
|
13234
|
2561 {
|
|
2562 mod->family = 0x0004;
|
|
2563 mod->version = 0x0001;
|
|
2564 mod->toolid = 0x0110;
|
|
2565 mod->toolversion = 0x0629;
|
|
2566 mod->flags = 0;
|
|
2567 strncpy(mod->name, "messaging", sizeof(mod->name));
|
|
2568 mod->snachandler = snachandler;
|
|
2569
|
|
2570 return 0;
|
|
2571 }
|