1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
/********************************************************************\
* BitlBee -- An IRC to other IM-networks gateway *
* *
* Copyright 2002-2012 Wilmer van der Gaast and others *
\********************************************************************/
/*
* Various utility functions. Some are copied from Gaim to support the
* IM-modules, most are from BitlBee.
*
* Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
* (and possibly other members of the Gaim team)
* Copyright 2002-2012 Wilmer van der Gaast <wilmer@gaast.net>
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License with
the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
Fifth Floor, Boston, MA 02110-1301 USA
*/
#define BITLBEE_CORE
#include "nogaim.h"
#include "base64.h"
#include "md5.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <glib.h>
#include <time.h>
#ifdef HAVE_RESOLV_A
#include <arpa/nameser.h>
#include <resolv.h>
#endif
#include "md5.h"
#include "ssl_client.h"
void strip_linefeed(gchar *text)
{
int i, j;
gchar *text2 = g_malloc(strlen(text) + 1);
for (i = 0, j = 0; text[i]; i++) {
if (text[i] != '\r') {
text2[j++] = text[i];
}
}
text2[j] = '\0';
strcpy(text, text2);
g_free(text2);
}
time_t get_time(int year, int month, int day, int hour, int min, int sec)
{
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
tm.tm_year = year - 1900;
tm.tm_mon = month - 1;
tm.tm_mday = day;
tm.tm_hour = hour;
tm.tm_min = min;
tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
return mktime(&tm);
}
time_t mktime_utc(struct tm *tp)
{
struct tm utc;
time_t res, tres;
tp->tm_isdst = -1;
res = mktime(tp);
/* Problem is, mktime() just gave us the GMT timestamp for the
given local time... While the given time WAS NOT local. So
we should fix this now.
Now I could choose between messing with environment variables
(kludgy) or using timegm() (not portable)... Or doing the
following, which I actually prefer...
tzset() may also work but in other places I actually want to
use local time.
FFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUU!! */
gmtime_r(&res, &utc);
utc.tm_isdst = -1;
if (utc.tm_hour == tp->tm_hour && utc.tm_min == tp->tm_min) {
/* Sweet! We're in UTC right now... */
return res;
}
tres = mktime(&utc);
res += res - tres;
/* Yes, this is a hack. And it will go wrong around DST changes.
BUT this is more likely to be threadsafe than messing with
environment variables, and possibly more portable... */
return res;
}
typedef struct htmlentity {
char code[7];
char is[3];
} htmlentity_t;
static const htmlentity_t ent[] =
{
{ "lt", "<" },
{ "gt", ">" },
{ "amp", "&" },
{ "apos", "'" },
{ "quot", "\"" },
{ "aacute", "á" },
{ "eacute", "é" },
{ "iacute", "é" },
{ "oacute", "ó" },
{ "uacute", "ú" },
{ "agrave", "à" },
{ "egrave", "è" },
{ "igrave", "ì" },
{ "ograve", "ò" },
{ "ugrave", "ù" },
{ "acirc", "â" },
{ "ecirc", "ê" },
{ "icirc", "î" },
{ "ocirc", "ô" },
{ "ucirc", "û" },
{ "auml", "ä" },
{ "euml", "ë" },
{ "iuml", "ï" },
{ "ouml", "ö" },
{ "uuml", "ü" },
{ "nbsp", " " },
{ "", "" }
};
void strip_html(char *in)
{
char *start = in;
char out[strlen(in) + 1];
char *s = out, *cs;
int i, matched;
int taglen;
memset(out, 0, sizeof(out));
while (*in) {
if (*in == '<' && (g_ascii_isalpha(*(in + 1)) || *(in + 1) == '/')) {
/* If in points at a < and in+1 points at a letter or a slash, this is probably
a HTML-tag. Try to find a closing > and continue there. If the > can't be
found, assume that it wasn't a HTML-tag after all. */
cs = in;
while (*in && *in != '>') {
in++;
}
taglen = in - cs - 1; /* not <0 because the above loop runs at least once */
if (*in) {
if (g_strncasecmp(cs + 1, "b", taglen) == 0) {
*(s++) = '\x02';
} else if (g_strncasecmp(cs + 1, "/b", taglen) == 0) {
*(s++) = '\x02';
} else if (g_strncasecmp(cs + 1, "i", taglen) == 0) {
*(s++) = '\x1f';
} else if (g_strncasecmp(cs + 1, "/i", taglen) == 0) {
*(s++) = '\x1f';
} else if (g_strncasecmp(cs + 1, "br", taglen) == 0) {
*(s++) = '\n';
}
in++;
} else {
in = cs;
*(s++) = *(in++);
}
} else if (*in == '&') {
cs = ++in;
while (*in && g_ascii_isalpha(*in)) {
in++;
}
if (*in == ';') {
in++;
}
matched = 0;
for (i = 0; *ent[i].code; i++) {
if (g_strncasecmp(ent[i].code, cs, strlen(ent[i].code)) == 0) {
int j;
for (j = 0; ent[i].is[j]; j++) {
*(s++) = ent[i].is[j];
}
matched = 1;
break;
}
}
/* None of the entities were matched, so return the string */
if (!matched) {
in = cs - 1;
*(s++) = *(in++);
}
} else {
*(s++) = *(in++);
}
}
strcpy(start, out);
}
char *escape_html(const char *html)
{
const char *c = html;
GString *ret;
char *str;
if (html == NULL) {
return(NULL);
}
ret = g_string_new("");
while (*c) {
switch (*c) {
case '&':
ret = g_string_append(ret, "&");
break;
case '<':
ret = g_string_append(ret, "<");
break;
case '>':
ret = g_string_append(ret, ">");
break;
case '"':
ret = g_string_append(ret, """);
break;
default:
ret = g_string_append_c(ret, *c);
}
c++;
}
str = ret->str;
g_string_free(ret, FALSE);
return(str);
}
/* Decode%20a%20file%20name */
void http_decode(char *</*
* aim_im.c
*
* The routines for sending/receiving Instant Messages.
*
* Note the term ICBM (Inter-Client Basic Message) which blankets
* all types of genericly routed through-server messages. Within
* the ICBM types (family 4), a channel is defined. Each channel
* represents a different type of message. Channel 1 is used for
* what would commonly be called an "instant message". Channel 2
* is used for negotiating "rendezvous". These transactions end in
* something more complex happening, such as a chat invitation, or
* a file transfer.
*
* In addition to the channel, every ICBM contains a cookie. For
* standard IMs, these are only used for error messages. However,
* the more complex rendezvous messages make suitably more complex
* use of this field.
*
*/
#include <aim.h>
#include "im.h"
#include "info.h"
/*
* Takes a msghdr (and a length) and returns a client type
* code. Note that this is *only a guess* and has a low likelihood
* of actually being accurate.
*
* Its based on experimental data, with the help of Eric Warmenhoven
* who seems to have collected a wide variety of different AIM clients.
*
*
* Heres the current collection:
* 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414
* 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464,
* 4.3.2229, 4.4.2286
* 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here)
* 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any
* TOC client
*
* Note that in this function, only the feature bytes are tested, since
* the rest will always be the same.
*
*/
guint16 aim_fingerprintclient(guint8 *msghdr, int len)
{
static const struct {
guint16 clientid;
int len;
guint8 data[10];
} fingerprints[] = {
/* AOL Mobile Communicator, WinAIM 1.0.414 */
{ AIM_CLIENTTYPE_MC,
3, {0x01, 0x01, 0x01}},
/* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
{ AIM_CLIENTTYPE_WINAIM,
3, {0x01, 0x01, 0x02}},
/* WinAIM 4.1.2010, libfaim */
{ AIM_CLIENTTYPE_WINAIM41,
4, {0x01, 0x01, 0x01, 0x02}},
/* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
{ AIM_CLIENTTYPE_AOL_TOC,
1, {0x01}},
{ 0, 0}
};
int i;
if (!msghdr || (len <= 0))
return AIM_CLIENTTYPE_UNKNOWN;
for (i = 0; fingerprints[i].len; i++) {
if (fingerprints[i].len != len)
continue;
if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
return fingerprints[i].clientid;
}
return AIM_CLIENTTYPE_UNKNOWN;
}
/* This should be endian-safe now... but who knows... */
guint16 aim_iconsum(const guint8 *buf, int buflen)
{
guint32 sum;
int i;
for (i = 0, sum = 0; i + 1 < buflen; i += 2)
sum += (buf[i+1] << 8) + buf[i];
if (i < buflen)
sum += buf[i];
sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
return (guint16)sum;
}
/*
* Send an ICBM (instant message).
*
*
* Possible flags:
* AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
* AIM_IMFLAGS_ACK -- Requests that the server send an ack
* when the message is received (of type 0x0004/0x000c)
* AIM_IMFLAGS_OFFLINE--If destination is offline, store it until they are
* online (probably ICQ only).
* AIM_IMFLAGS_UNICODE--Instead of ASCII7, the passed message is
* made up of UNICODE duples. If you set
* this, you'd better be damn sure you know
* what you're doing.
* AIM_IMFLAGS_ISO_8859_1 -- The message contains the ASCII8 subset
* known as ISO-8859-1.
*
* Generally, you should use the lowest encoding possible to send
* your message. If you only use basic punctuation and the generic
* Latin alphabet, use ASCII7 (no flags). If you happen to use non-ASCII7
* characters, but they are all clearly defined in ISO-8859-1, then
* use that. Keep in mind that not all characters in the PC ASCII8
* character set are defined in the ISO standard. For those cases (most
* notably when the (r) symbol is used), you must use the full UNICODE
* encoding for your message. In UNICODE mode, _all_ characters must
* occupy 16bits, including ones that are not special. (Remember that
* the first 128 UNICODE symbols are equivelent to ASCII7, however they
* must be prefixed with a zero high order byte.)
*
* I strongly discourage the use of UNICODE mode, mainly because none
* of the clients I use can parse those messages (and besides that,
* wchars are difficult and non-portable to handle in most UNIX environments).
* If you really need to include special characters, use the HTML UNICODE
* entities. These are of the form ߪ where 2026 is the hex
* representation of the UNICODE index (in this case, UNICODE
* "Horizontal Ellipsis", or 133 in in ASCII8).
*
* Implementation note: Since this is one of the most-used functions
* in all of libfaim, it is written with performance in mind. As such,
* it is not as clear as it could be in respect to how this message is
* supposed to be layed out. Most obviously, tlvlists should be used
* instead of writing out the bytes manually.
*
* XXX more precise verification that we never send SNACs larger than 8192
* XXX check SNAC size for multipart
*
*/
int aim_send_im_ext(aim_session_t *sess, struct aim_sendimext_args *args)
{
static const guint8 deffeatures[] = {
0x01, 0x01, 0x01, 0x02
};
aim_conn_t *conn;
int i, msgtlvlen;
aim_frame_t *fr;
aim_snacid_t snacid;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)))
return -EINVAL;
if (!args)
return -EINVAL;
if (args->flags & AIM_IMFLAGS_MULTIPART) {
if (args->mpmsg->numparts <= 0)
return -EINVAL;
} else {
if (!args->msg || (args->msglen <= 0))
return -EINVAL;
if (args->msglen >= MAXMSGLEN)
return -E2BIG;
}
/* Painfully calculate the size of the message TLV */
msgtlvlen = 1 + 1; /* 0501 */
if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES)
msgtlvlen += 2 + args->featureslen;
else
msgtlvlen += 2 + sizeof(deffeatures);
if (args->flags & AIM_IMFLAGS_MULTIPART) {
aim_mpmsg_section_t *sec;
for (sec = args->mpmsg->parts; sec; sec = sec->next) {
msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
msgtlvlen += 4 /* charset */ + sec->datalen;
}
} else {
msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
msgtlvlen += 4 /* charset */ + args->msglen;
}
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, msgtlvlen+128)))
return -ENOMEM;
/* XXX should be optional */
snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
/*
* Generate a random message cookie
*
* We could cache these like we do SNAC IDs. (In fact, it
* might be a good idea.) In the message error functions,
* the 8byte message cookie is returned as well as the
* SNAC ID.
*
*/
for (i = 0; i < 8; i++)
aimbs_put8(&fr->data, (guint8) rand());
/*
* Channel ID
*/
aimbs_put16(&fr->data, 0x0001);
/*
* Destination SN (prepended with byte length)
*/
aimbs_put8(&fr->data, strlen(args->destsn));
aimbs_putraw(&fr->data, (guint8 *)args->destsn, strlen(args->destsn));
/*
* Message TLV (type 2).
*/
aimbs_put16(&fr->data, 0x0002);
aimbs_put16(&fr->data, msgtlvlen);
/*
* Features
*
*/
aimbs_put8(&fr->data, 0x05);
aimbs_put8(&fr->data, 0x01);
if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) {
aimbs_put16(&fr->data, args->featureslen);
aimbs_putraw(&fr->data, args->features, args->featureslen);
} else {
aimbs_put16(&fr->data, sizeof(deffeatures));
aimbs_putraw(&fr->data, deffeatures, sizeof(deffeatures));
}
if (args->flags & AIM_IMFLAGS_MULTIPART) {
aim_mpmsg_section_t *sec;
for (sec = args->mpmsg->parts; sec; sec = sec->next) {
aimbs_put16(&fr->data, 0x0101);
aimbs_put16(&fr->data, sec->datalen + 4);
aimbs_put16(&fr->data, sec->charset);
aimbs_put16(&fr->data, sec->charsubset);
aimbs_putraw(&fr->data, sec->data, sec->datalen);
}
} else {
aimbs_put16(&fr->data, 0x0101);
/*
* Message block length.
*/
aimbs_put16(&fr->data, args->msglen + 0x04);
/*
* Character set.
*/
if (args->flags & AIM_IMFLAGS_CUSTOMCHARSET) {
aimbs_put16(&fr->data, args->charset);
aimbs_put16(&fr->data, args->charsubset);
} else {
if (args->flags & AIM_IMFLAGS_UNICODE)
aimbs_put16(&fr->data, 0x0002);
else if (args->flags & AIM_IMFLAGS_ISO_8859_1)
aimbs_put16(&fr->data, 0x0003);
else
aimbs_put16(&fr->data, 0x0000);
aimbs_put16(&fr->data, 0x0000);
}
/*
* Message. Not terminated.
*/
aimbs_putraw(&fr->data, (guint8 *)args->msg, args->msglen);
}
/*
* Set the Request Acknowledge flag.
*/
if (args->flags & AIM_IMFLAGS_ACK) {
aimbs_put16(&fr->data, 0x0003);
aimbs_put16(&fr->data, 0x0000);
}
/*
* Set the Autoresponse flag.
*/
if (args->flags & AIM_IMFLAGS_AWAY) {
aimbs_put16(&fr->data, 0x0004);
aimbs_put16(&fr->data, 0x0000);
}
if (args->flags & AIM_IMFLAGS_OFFLINE) {
aimbs_put16(&fr->data, 0x0006);
aimbs_put16(&fr->data, 0x0000);
}
/*
* Set the I HAVE A REALLY PURTY ICON flag.
*/
if (args->flags & AIM_IMFLAGS_HASICON) {
aimbs_put16(&fr->data, 0x0008);
aimbs_put16(&fr->data, 0x000c);
aimbs_put32(&fr->data, args->iconlen);
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, args->iconsum);
aimbs_put32(&fr->data, args->iconstamp);
}
/*
* Set the Buddy Icon Requested flag.
*/
if (args->flags & AIM_IMFLAGS_BUDDYREQ) {
aimbs_put16(&fr->data, 0x0009);
aimbs_put16(&fr->data, 0x0000);
}
aim_tx_enqueue(sess, fr);
if (!(sess->flags & AIM_SESS_FLAGS_DONTTIMEOUTONICBM))
aim_cleansnacs(sess, 60); /* clean out SNACs over 60sec old */
return 0;
}
/*
* Simple wrapper for aim_send_im_ext()
*
* You cannot use aim_send_im if you need the HASICON flag. You must
* use aim_send_im_ext directly for that.
*
* aim_send_im also cannot be used if you require UNICODE messages, because
* that requires an explicit message length. Use aim_send_im_ext().
*
*/
int aim_send_im(aim_session_t *sess, const char *destsn, guint16 flags, const char *msg)
{
struct aim_sendimext_args args;
args.destsn = destsn;
args.flags = flags;
args.msg = msg;
args.msglen = strlen(msg);
/* Make these don't get set by accident -- they need aim_send_im_ext */
args.flags &= ~(AIM_IMFLAGS_CUSTOMFEATURES | AIM_IMFLAGS_HASICON | AIM_IMFLAGS_MULTIPART);
return aim_send_im_ext(sess, &args);
}
/*
* This is also performance sensitive. (If you can believe it...)
*
*/
int aim_send_icon(aim_session_t *sess, const char *sn, const guint8 *icon, int iconlen, time_t stamp, guint16 iconsum)
{
aim_conn_t *conn;
int i;
guint8 ck[8];
aim_frame_t *fr;
aim_snacid_t snacid;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)))
return -EINVAL;
if (!sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN))
return -EINVAL;
for (i = 0; i < 8; i++)
aimutil_put8(ck+i, (guint8) rand());
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
/*
* Cookie
*/
aimbs_putraw(&fr->data, ck, 8);
/*
* Channel (2)
*/
aimbs_put16(&fr->data, 0x0002);
/*
* Dest sn
*/
aimbs_put8(&fr->data, strlen(sn));
aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
/*
* TLV t(0005)
*
* Encompasses everything below.
*/
aimbs_put16(&fr->data, 0x0005);
aimbs_put16(&fr->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT));
aimbs_put16(&fr->data, 0x0000);
aimbs_putraw(&fr->data, ck, 8);
aim_putcap(&fr->data, AIM_CAPS_BUDDYICON);
/* TLV t(000a) */
aimbs_put16(&fr->data, 0x000a);
aimbs_put16(&fr->data, 0x0002);
aimbs_put16(&fr->data, 0x0001);
/* TLV t(000f) */
aimbs_put16(&fr->data, 0x000f);
aimbs_put16(&fr->data, 0x0000);
/* TLV t(2711) */
aimbs_put16(&fr->data, 0x2711);
aimbs_put16(&fr->data, 4+4+4+iconlen+strlen(AIM_ICONIDENT));
aimbs_put16(&fr->data, 0x0000);
aimbs_put16(&fr->data, iconsum);
aimbs_put32(&fr->data, iconlen);
aimbs_put32(&fr->data, stamp);
aimbs_putraw(&fr->data, icon, iconlen);
aimbs_putraw(&fr->data, (guint8 *)AIM_ICONIDENT, strlen(AIM_ICONIDENT));
/* TLV t(0003) */
aimbs_put16(&fr->data, 0x0003);
aimbs_put16(&fr->data, 0x0000);
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* This only works for ICQ 2001b (thats 2001 not 2000). Better, only
* send it to clients advertising the RTF capability. In fact, if you send
* it to a client that doesn't support that capability, the server will gladly
* bounce it back to you.
*
* You'd think this would be in icq.c, but, well, I'm trying to stick with
* the one-group-per-file scheme as much as possible. This could easily
* be an exception, since Rendezvous IMs are external of the Oscar core,
* and therefore are undefined. Really I just need to think of a good way to
* make an interface similar to what AOL actually uses. But I'm not using COM.
*
*/
int aim_send_rtfmsg(aim_session_t *sess, struct aim_sendrtfmsg_args *args)
{
const char rtfcap[] = {"{97B12751-243C-4334-AD22-D6ABF73F1492}"}; /* AIM_CAPS_ICQRTF capability in string form */
aim_conn_t *conn;
int i;
guint8 ck[8];
aim_frame_t *fr;
aim_snacid_t snacid;
int servdatalen;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)))
return -EINVAL;
if (!args || !args->destsn || !args->rtfmsg)
return -EINVAL;
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;
for (i = 0; i < 8; i++)
aimutil_put8(ck+i, (guint8) rand());
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+128+servdatalen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
/*
* Cookie
*/
aimbs_putraw(&fr->data, ck, 8);
/*
* Channel (2)
*/
aimbs_put16(&fr->data, 0x0002);
/*
* Dest sn
*/
aimbs_put8(&fr->data, strlen(args->destsn));
aimbs_putraw(&fr->data, (guint8 *)args->destsn, strlen(args->destsn));
/*
* TLV t(0005)
*
* Encompasses everything below.
*/
aimbs_put16(&fr->data, 0x0005);
aimbs_put16(&fr->data, 2+8+16 + 2+2+2 + 2+2 + 2+2+servdatalen);
aimbs_put16(&fr->data, 0x0000);
aimbs_putraw(&fr->data, ck, 8);
aim_putcap(&fr->data, AIM_CAPS_ICQSERVERRELAY);
/*
* t(000a) l(0002) v(0001)
*/
aimbs_put16(&fr->data, 0x000a);
aimbs_put16(&fr->data, 0x0002);
aimbs_put16(&fr->data, 0x0001);
/*
* t(000f) l(0000) v()
*/
aimbs_put16(&fr->data, 0x000f);
aimbs_put16(&
|