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