7011
|
1 /*
|
|
2 * Family 0x0002 - Locate.
|
|
3 *
|
|
4 * The functions here are responsible for requesting and parsing information-
|
|
5 * gathering SNACs. Or something like that. This family contains the SNACs
|
|
6 * for getting and setting info, away messages, directory profile thingy, etc.
|
|
7 */
|
|
8
|
|
9 #define FAIM_INTERNAL
|
|
10 #include <aim.h>
|
|
11 #ifdef _WIN32
|
|
12 #include "win32dep.h"
|
|
13 #endif
|
|
14
|
|
15 /*
|
|
16 * Capability blocks.
|
|
17 *
|
|
18 * These are CLSIDs. They should actually be of the form:
|
|
19 *
|
|
20 * {0x0946134b, 0x4c7f, 0x11d1,
|
|
21 * {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
|
|
22 *
|
|
23 * But, eh.
|
|
24 */
|
|
25 static const struct {
|
|
26 fu32_t flag;
|
|
27 fu8_t data[16];
|
|
28 } aim_caps[] = {
|
|
29
|
|
30 /*
|
|
31 * These are in ascending numerical order.
|
|
32 */
|
7253
|
33
|
|
34 /*
|
|
35 * Perhaps better called AIM_CAPS_SHORTCAPS
|
|
36 */
|
7011
|
37 {AIM_CAPS_ICHAT,
|
|
38 {0x09, 0x46, 0x00, 0x00, 0x4c, 0x7f, 0x11, 0xd1,
|
|
39 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
40
|
|
41 {AIM_CAPS_SECUREIM,
|
|
42 {0x09, 0x46, 0x00, 0x01, 0x4c, 0x7f, 0x11, 0xd1,
|
|
43 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
44
|
7025
|
45 /*
|
|
46 * Not really sure about this one. In an email from
|
|
47 * 26 Sep 2003, Matthew Sachs suggested that, "this
|
|
48 * is probably the capability for the SMS features."
|
|
49 */
|
|
50 {AIM_CAPS_SMS,
|
|
51 {0x09, 0x46, 0x01, 0xff, 0x4c, 0x7f, 0x11, 0xd1,
|
|
52 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
53
|
7091
|
54 {AIM_CAPS_GENERICUNKNOWN,
|
7025
|
55 {0x09, 0x46, 0xf0, 0x03, 0x4c, 0x7f, 0x11, 0xd1,
|
|
56 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
57
|
7091
|
58 {AIM_CAPS_GENERICUNKNOWN,
|
7025
|
59 {0x09, 0x46, 0xf0, 0x04, 0x4c, 0x7f, 0x11, 0xd1,
|
|
60 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
61
|
7091
|
62 {AIM_CAPS_GENERICUNKNOWN,
|
7025
|
63 {0x09, 0x46, 0xf0, 0x05, 0x4c, 0x7f, 0x11, 0xd1,
|
|
64 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
65
|
7011
|
66 {AIM_CAPS_HIPTOP,
|
|
67 {0x09, 0x46, 0x13, 0x23, 0x4c, 0x7f, 0x11, 0xd1,
|
|
68 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
69
|
|
70 {AIM_CAPS_VOICE,
|
|
71 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
|
|
72 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
73
|
|
74 {AIM_CAPS_SENDFILE,
|
|
75 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
|
|
76 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
77
|
7141
|
78 {AIM_CAPS_ICQ_DIRECT,
|
7011
|
79 {0x09, 0x46, 0x13, 0x44, 0x4c, 0x7f, 0x11, 0xd1,
|
|
80 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
81
|
|
82 {AIM_CAPS_DIRECTIM,
|
|
83 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
|
|
84 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
85
|
|
86 {AIM_CAPS_BUDDYICON,
|
|
87 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
|
|
88 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
89
|
|
90 /*
|
|
91 * Windows AIM calls this "Add-ins," which is probably more accurate
|
|
92 */
|
|
93 {AIM_CAPS_SAVESTOCKS,
|
|
94 {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
|
|
95 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
96
|
|
97 {AIM_CAPS_GETFILE,
|
|
98 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
|
|
99 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
100
|
|
101 {AIM_CAPS_ICQSERVERRELAY,
|
|
102 {0x09, 0x46, 0x13, 0x49, 0x4c, 0x7f, 0x11, 0xd1,
|
|
103 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
104
|
|
105 /*
|
|
106 * Indeed, there are two of these. The former appears to be correct,
|
|
107 * but in some versions of winaim, the second one is set. Either they
|
|
108 * forgot to fix endianness, or they made a typo. It really doesn't
|
|
109 * matter which.
|
|
110 */
|
|
111 {AIM_CAPS_GAMES,
|
|
112 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
|
|
113 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
114 {AIM_CAPS_GAMES2,
|
|
115 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
|
|
116 0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
117
|
|
118 {AIM_CAPS_SENDBUDDYLIST,
|
|
119 {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1,
|
|
120 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
121
|
|
122 /*
|
|
123 * Setting this lets AIM users receive messages from ICQ users, and ICQ
|
|
124 * users receive messages from AIM users. It also lets ICQ users show
|
|
125 * up in buddy lists for AIM users, and AIM users show up in buddy lists
|
|
126 * for ICQ users. And ICQ privacy/invisibility acts like AIM privacy,
|
|
127 * in that if you add a user to your deny list, you will not be able to
|
|
128 * see them as online (previous you could still see them, but they
|
|
129 * couldn't see you.
|
|
130 */
|
|
131 {AIM_CAPS_INTEROPERATE,
|
|
132 {0x09, 0x46, 0x13, 0x4d, 0x4c, 0x7f, 0x11, 0xd1,
|
|
133 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
134
|
|
135 {AIM_CAPS_ICQUTF8,
|
|
136 {0x09, 0x46, 0x13, 0x4e, 0x4c, 0x7f, 0x11, 0xd1,
|
|
137 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
138
|
|
139 {AIM_CAPS_ICQUTF8OLD,
|
|
140 {0x2e, 0x7a, 0x64, 0x75, 0xfa, 0xdf, 0x4d, 0xc8,
|
|
141 0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}},
|
|
142
|
|
143 /*
|
|
144 * Chat is oddball.
|
|
145 */
|
|
146 {AIM_CAPS_CHAT,
|
|
147 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
|
|
148 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
|
|
149
|
|
150 /*
|
|
151 {AIM_CAPS_ICQ2GO,
|
|
152 {0x56, 0x3f, 0xc8, 0x09, 0x0b, 0x6f, 0x41, 0xbd,
|
|
153 0x9f, 0x79, 0x42, 0x26, 0x09, 0xdf, 0xa2, 0xf3}},
|
|
154 */
|
|
155
|
|
156 {AIM_CAPS_ICQRTF,
|
|
157 {0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34,
|
|
158 0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}},
|
|
159
|
7091
|
160 /* This is added by the servers and it only shows up for ourselves... */
|
|
161 {AIM_CAPS_GENERICUNKNOWN,
|
7011
|
162 {0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34,
|
7091
|
163 0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x09}},
|
7011
|
164
|
|
165 {AIM_CAPS_APINFO,
|
|
166 {0xaa, 0x4a, 0x32, 0xb5, 0xf8, 0x84, 0x48, 0xc6,
|
|
167 0xa3, 0xd7, 0x8c, 0x50, 0x97, 0x19, 0xfd, 0x5b}},
|
|
168
|
|
169 {AIM_CAPS_TRILLIANCRYPT,
|
|
170 {0xf2, 0xe7, 0xc7, 0xf4, 0xfe, 0xad, 0x4d, 0xfb,
|
|
171 0xb2, 0x35, 0x36, 0x79, 0x8b, 0xdf, 0x00, 0x00}},
|
|
172
|
|
173 {AIM_CAPS_EMPTY,
|
|
174 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
|
|
176
|
|
177 {AIM_CAPS_LAST}
|
|
178 };
|
|
179
|
|
180 /*
|
|
181 * Add the userinfo to our linked list. If we already have userinfo
|
|
182 * for this buddy, then just overwrite parts of the old data.
|
|
183 * @param userinfo Contains the new information for the buddy.
|
|
184 */
|
7045
|
185 static void aim_locate_adduserinfo(aim_session_t *sess, aim_userinfo_t *userinfo) {
|
7011
|
186 aim_userinfo_t *cur;
|
|
187
|
7045
|
188 cur = aim_locate_finduserinfo(sess, userinfo->sn);
|
7011
|
189
|
|
190 if (cur == NULL) {
|
|
191 cur = (aim_userinfo_t *)calloc(1, sizeof(aim_userinfo_t));
|
|
192 cur->sn = strdup(userinfo->sn);
|
7045
|
193 cur->next = sess->locate.userinfo;
|
|
194 sess->locate.userinfo = cur;
|
7011
|
195 }
|
|
196
|
|
197 cur->warnlevel = userinfo->warnlevel;
|
|
198 cur->idletime = userinfo->idletime;
|
|
199 if (userinfo->flags != 0)
|
|
200 cur->flags = userinfo->flags;
|
|
201 if (userinfo->createtime != 0)
|
|
202 cur->createtime = userinfo->createtime;
|
|
203 if (userinfo->membersince != 0)
|
|
204 cur->membersince = userinfo->membersince;
|
|
205 if (userinfo->onlinesince != 0)
|
|
206 cur->onlinesince = userinfo->onlinesince;
|
|
207 if (userinfo->sessionlen != 0)
|
|
208 cur->sessionlen = userinfo->sessionlen;
|
|
209 if (userinfo->capabilities != 0)
|
|
210 cur->capabilities = userinfo->capabilities;
|
|
211 cur->present |= userinfo->present;
|
|
212
|
7046
|
213 if (userinfo->iconcsumlen > 0) {
|
|
214 free(cur->iconcsum);
|
|
215 cur->iconcsum = (fu8_t *)malloc(userinfo->iconcsumlen);
|
|
216 memcpy(cur->iconcsum, userinfo->iconcsum, userinfo->iconcsumlen);
|
|
217 cur->iconcsumlen = userinfo->iconcsumlen;
|
7011
|
218 }
|
|
219
|
|
220 if ((userinfo->info != NULL) && (userinfo->info_len > 0)) {
|
|
221 free(cur->info);
|
|
222 free(cur->info_encoding);
|
|
223 cur->info = (char *)malloc(userinfo->info_len);
|
|
224 memcpy(cur->info, userinfo->info, userinfo->info_len);
|
7235
|
225 cur->info_encoding = strdup(userinfo->info_encoding);
|
7011
|
226 cur->info_len = userinfo->info_len;
|
|
227 }
|
7046
|
228
|
|
229 if ((userinfo->away != NULL) && (userinfo->away_len > 0)) {
|
|
230 free(cur->away);
|
|
231 free(cur->away_encoding);
|
|
232 cur->away = (char *)malloc(userinfo->away_len);
|
|
233 memcpy(cur->away, userinfo->away, userinfo->away_len);
|
7235
|
234 cur->away_encoding = strdup(userinfo->away_encoding);
|
7046
|
235 cur->away_len = userinfo->away_len;
|
|
236 }
|
7011
|
237 }
|
|
238
|
|
239 static void aim_locate_dorequest(aim_session_t *sess) {
|
7045
|
240 struct userinfo_node *cur = sess->locate.request_queue;
|
7011
|
241
|
|
242 if (cur == NULL)
|
|
243 return;
|
|
244
|
7045
|
245 if (sess->locate.waiting_for_response == TRUE)
|
7011
|
246 return;
|
|
247
|
7045
|
248 sess->locate.waiting_for_response = TRUE;
|
7166
|
249 aim_locate_getinfoshort(sess, cur->sn, 0x00000003);
|
7011
|
250 }
|
|
251
|
7259
|
252 /*
|
|
253 * Remove this screen name from our queue. If this info was resquested
|
|
254 * by our info request queue, then pop off the next element of the queue.
|
|
255 *
|
|
256 * @param sess The aim session.
|
|
257 * @param sn Screen name of the info we just received.
|
|
258 * @return True if the request was explicit (client requested the info),
|
|
259 * false if the request was implicit (libfaim request the info).
|
|
260 */
|
|
261 static int aim_locate_gotuserinfo(aim_session_t *sess, const char *sn) {
|
|
262 struct userinfo_node *cur, *del;
|
|
263 int was_explicit = TRUE;
|
|
264
|
|
265 while ((sess->locate.request_queue != NULL) && (aim_sncmp(sn, sess->locate.request_queue->sn) == 0)) {
|
|
266 del = sess->locate.request_queue;
|
|
267 sess->locate.request_queue = del->next;
|
|
268 was_explicit = FALSE;
|
|
269 free(del->sn);
|
|
270 free(del);
|
|
271 }
|
|
272
|
|
273 cur = sess->locate.request_queue;
|
|
274 while ((cur != NULL) && (cur->next != NULL)) {
|
|
275 if (aim_sncmp(sn, cur->next->sn) == 0) {
|
|
276 del = cur->next;
|
|
277 cur->next = del->next;
|
|
278 was_explicit = FALSE;
|
|
279 free(del->sn);
|
|
280 free(del);
|
|
281 } else
|
|
282 cur = cur->next;
|
|
283 }
|
|
284
|
|
285 if (!was_explicit) {
|
|
286 sess->locate.waiting_for_response = FALSE;
|
|
287 aim_locate_dorequest(sess);
|
|
288 }
|
|
289
|
|
290 return was_explicit;
|
|
291 }
|
|
292
|
7011
|
293 faim_internal void aim_locate_requestuserinfo(aim_session_t *sess, const char *sn) {
|
7045
|
294 struct userinfo_node *cur;
|
7011
|
295
|
7266
|
296 /* Make sure we aren't already requesting info for this buddy */
|
|
297 cur = sess->locate.request_queue;
|
|
298 while (cur != NULL) {
|
|
299 if (aim_sncmp(sn, cur->sn) == 0)
|
|
300 return;
|
|
301 cur = cur->next;
|
|
302 }
|
|
303
|
|
304 /* Add a new node to our request queue */
|
7045
|
305 cur = (struct userinfo_node *)malloc(sizeof(struct userinfo_node));
|
7011
|
306 cur->sn = strdup(sn);
|
7045
|
307 cur->next = sess->locate.request_queue;
|
|
308 sess->locate.request_queue = cur;
|
7011
|
309
|
7266
|
310 /* Actually request some info up in this piece */
|
7011
|
311 aim_locate_dorequest(sess);
|
|
312 }
|
|
313
|
7045
|
314 faim_export aim_userinfo_t *aim_locate_finduserinfo(aim_session_t *sess, const char *sn) {
|
|
315 aim_userinfo_t *cur = sess->locate.userinfo;
|
7011
|
316
|
|
317 while (cur != NULL) {
|
|
318 if (aim_sncmp(cur->sn, sn) == 0)
|
|
319 return cur;
|
|
320 cur = cur->next;
|
|
321 }
|
|
322
|
|
323 return NULL;
|
|
324 }
|
|
325
|
|
326 /*
|
|
327 * This still takes a length parameter even with a bstream because capabilities
|
|
328 * are not naturally bounded.
|
|
329 */
|
|
330 faim_internal fu32_t aim_getcap(aim_session_t *sess, aim_bstream_t *bs, int len)
|
|
331 {
|
|
332 fu32_t flags = 0;
|
|
333 int offset;
|
|
334
|
|
335 for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x10) {
|
|
336 fu8_t *cap;
|
|
337 int i, identified;
|
|
338
|
|
339 cap = aimbs_getraw(bs, 0x10);
|
|
340
|
|
341 for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) {
|
|
342
|
|
343 if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) {
|
|
344 flags |= aim_caps[i].flag;
|
|
345 identified++;
|
|
346 break; /* should only match once... */
|
|
347
|
|
348 }
|
|
349 }
|
|
350
|
|
351 if (!identified) {
|
|
352 faimdprintf(sess, 0, "unknown capability: {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
|
|
353 cap[0], cap[1], cap[2], cap[3],
|
|
354 cap[4], cap[5],
|
|
355 cap[6], cap[7],
|
|
356 cap[8], cap[9],
|
|
357 cap[10], cap[11], cap[12], cap[13],
|
|
358 cap[14], cap[15]);
|
|
359 }
|
|
360
|
|
361 free(cap);
|
|
362 }
|
|
363
|
|
364 return flags;
|
|
365 }
|
|
366
|
|
367 faim_internal int aim_putcap(aim_bstream_t *bs, fu32_t caps)
|
|
368 {
|
|
369 int i;
|
|
370
|
|
371 if (!bs)
|
|
372 return -EINVAL;
|
|
373
|
|
374 for (i = 0; aim_bstream_empty(bs); i++) {
|
|
375
|
|
376 if (aim_caps[i].flag == AIM_CAPS_LAST)
|
|
377 break;
|
|
378
|
|
379 if (caps & aim_caps[i].flag)
|
|
380 aimbs_putraw(bs, aim_caps[i].data, 0x10);
|
|
381
|
|
382 }
|
|
383
|
|
384 return 0;
|
|
385 }
|
|
386
|
|
387 static void dumptlv(aim_session_t *sess, fu16_t type, aim_bstream_t *bs, fu8_t len)
|
|
388 {
|
|
389 int i;
|
|
390
|
|
391 if (!sess || !bs || !len)
|
|
392 return;
|
|
393
|
|
394 faimdprintf(sess, 0, "userinfo: type =0x%04x\n", type);
|
|
395 faimdprintf(sess, 0, "userinfo: length=0x%04x\n", len);
|
|
396 faimdprintf(sess, 0, "userinfo: value:\n");
|
|
397
|
|
398 for (i = 0; i < len; i++) {
|
|
399 if ((i % 8) == 0)
|
|
400 faimdprintf(sess, 0, "\nuserinfo: ");
|
|
401 faimdprintf(sess, 0, "0x%2x ", aimbs_get8(bs));
|
|
402 }
|
|
403
|
|
404 faimdprintf(sess, 0, "\n");
|
|
405
|
|
406 return;
|
|
407 }
|
|
408
|
|
409 faim_internal void aim_info_free(aim_userinfo_t *info)
|
|
410 {
|
|
411 free(info->sn);
|
|
412 free(info->iconcsum);
|
|
413 free(info->info);
|
|
414 free(info->info_encoding);
|
|
415 free(info->avail);
|
|
416 free(info->avail_encoding);
|
|
417 free(info->away);
|
|
418 free(info->away_encoding);
|
|
419 }
|
|
420
|
|
421 /*
|
|
422 * AIM is fairly regular about providing user info. This is a generic
|
|
423 * routine to extract it in its standard form.
|
|
424 */
|
|
425 faim_internal int aim_info_extract(aim_session_t *sess, aim_bstream_t *bs, aim_userinfo_t *outinfo)
|
|
426 {
|
|
427 int curtlv, tlvcnt;
|
|
428 fu8_t snlen;
|
|
429
|
|
430 if (!bs || !outinfo)
|
|
431 return -EINVAL;
|
|
432
|
|
433 /* Clear out old data first */
|
|
434 memset(outinfo, 0x00, sizeof(aim_userinfo_t));
|
|
435
|
|
436 /*
|
|
437 * Screen name. Stored as an unterminated string prepended with a
|
|
438 * byte containing its length.
|
|
439 */
|
|
440 snlen = aimbs_get8(bs);
|
|
441 outinfo->sn = aimbs_getstr(bs, snlen);
|
|
442
|
|
443 /*
|
|
444 * Warning Level. Stored as an unsigned short.
|
|
445 */
|
|
446 outinfo->warnlevel = aimbs_get16(bs);
|
|
447
|
|
448 /*
|
|
449 * TLV Count. Unsigned short representing the number of
|
|
450 * Type-Length-Value triples that follow.
|
|
451 */
|
|
452 tlvcnt = aimbs_get16(bs);
|
|
453
|
|
454 /*
|
|
455 * Parse out the Type-Length-Value triples as they're found.
|
|
456 */
|
|
457 for (curtlv = 0; curtlv < tlvcnt; curtlv++) {
|
|
458 int endpos;
|
|
459 fu16_t type, length;
|
|
460
|
|
461 type = aimbs_get16(bs);
|
|
462 length = aimbs_get16(bs);
|
|
463
|
|
464 endpos = aim_bstream_curpos(bs) + length;
|
|
465
|
|
466 if (type == 0x0001) {
|
|
467 /*
|
|
468 * Type = 0x0001: User flags
|
|
469 *
|
|
470 * Specified as any of the following ORed together:
|
|
471 * 0x0001 Trial (user less than 60days)
|
|
472 * 0x0002 Unknown bit 2
|
|
473 * 0x0004 AOL Main Service user
|
|
474 * 0x0008 Unknown bit 4
|
|
475 * 0x0010 Free (AIM) user
|
|
476 * 0x0020 Away
|
|
477 * 0x0400 ActiveBuddy
|
|
478 *
|
|
479 */
|
|
480 outinfo->flags = aimbs_get16(bs);
|
|
481 outinfo->present |= AIM_USERINFO_PRESENT_FLAGS;
|
|
482
|
|
483 } else if (type == 0x0002) {
|
|
484 /*
|
|
485 * Type = 0x0002: Account creation time.
|
|
486 *
|
|
487 * The time/date that the user originally registered for
|
|
488 * the service, stored in time_t format.
|
|
489 *
|
|
490 * I'm not sure how this differs from type 5 ("member
|
|
491 * since").
|
|
492 *
|
|
493 * Note: This is the field formerly known as "member
|
|
494 * since". All these years and I finally found out
|
|
495 * that I got the name wrong.
|
|
496 */
|
|
497 outinfo->createtime = aimbs_get32(bs);
|
|
498 outinfo->present |= AIM_USERINFO_PRESENT_CREATETIME;
|
|
499
|
|
500 } else if (type == 0x0003) {
|
|
501 /*
|
|
502 * Type = 0x0003: On-Since date.
|
|
503 *
|
|
504 * The time/date that the user started their current
|
|
505 * session, stored in time_t format.
|
|
506 */
|
|
507 outinfo->onlinesince = aimbs_get32(bs);
|
|
508 outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE;
|
|
509
|
|
510 } else if (type == 0x0004) {
|
|
511 /*
|
|
512 * Type = 0x0004: Idle time.
|
|
513 *
|
|
514 * Number of minutes since the user actively used the
|
|
515 * service.
|
|
516 *
|
|
517 * Note that the client tells the server when to start
|
|
518 * counting idle times, so this may or may not be
|
|
519 * related to reality.
|
|
520 */
|
|
521 outinfo->idletime = aimbs_get16(bs);
|
|
522 outinfo->present |= AIM_USERINFO_PRESENT_IDLE;
|
|
523
|
|
524 } else if (type == 0x0005) {
|
|
525 /*
|
|
526 * Type = 0x0005: Member since date.
|
|
527 *
|
|
528 * The time/date that the user originally registered for
|
|
529 * the service, stored in time_t format.
|
|
530 *
|
|
531 * This is sometimes sent instead of type 2 ("account
|
|
532 * creation time"), particularly in the self-info.
|
|
533 * And particularly for ICQ?
|
|
534 */
|
|
535 outinfo->membersince = aimbs_get32(bs);
|
|
536 outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE;
|
|
537
|
|
538 } else if (type == 0x0006) {
|
|
539 /*
|
|
540 * Type = 0x0006: ICQ Online Status
|
|
541 *
|
|
542 * ICQ's Away/DND/etc "enriched" status. Some decoding
|
|
543 * of values done by Scott <darkagl@pcnet.com>
|
|
544 */
|
|
545 aimbs_get16(bs);
|
|
546 outinfo->icqinfo.status = aimbs_get16(bs);
|
|
547 outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS;
|
|
548
|
7141
|
549 } else if (type == 0x0008) {
|
|
550 /*
|
|
551 * Type = 0x0008
|
|
552 *
|
|
553 * Client type, or some such.
|
|
554 */
|
|
555
|
7011
|
556 } else if (type == 0x000a) {
|
|
557 /*
|
|
558 * Type = 0x000a
|
|
559 *
|
|
560 * ICQ User IP Address.
|
|
561 * Ahh, the joy of ICQ security.
|
|
562 */
|
|
563 outinfo->icqinfo.ipaddr = aimbs_get32(bs);
|
|
564 outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR;
|
|
565
|
|
566 } else if (type == 0x000c) {
|
|
567 /*
|
|
568 * Type = 0x000c
|
|
569 *
|
|
570 * random crap containing the IP address,
|
|
571 * apparently a port number, and some Other Stuff.
|
|
572 *
|
|
573 * Format is:
|
|
574 * 4 bytes - Our IP address, 0xc0 a8 01 2b for 192.168.1.43
|
|
575 *
|
|
576 *
|
|
577 */
|
|
578 aimbs_getrawbuf(bs, outinfo->icqinfo.crap, 0x25);
|
|
579 outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA;
|
|
580
|
|
581 } else if (type == 0x000d) {
|
|
582 /*
|
|
583 * Type = 0x000d
|
|
584 *
|
7141
|
585 * OSCAR Capability information.
|
7011
|
586 *
|
|
587 */
|
|
588 outinfo->capabilities = aim_getcap(sess, bs, length);
|
|
589 outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;
|
|
590
|
|
591 } else if (type == 0x000e) {
|
|
592 /*
|
|
593 * Type = 0x000e
|
|
594 *
|
7141
|
595 * AOL capability information.
|
7011
|
596 *
|
|
597 */
|
|
598
|
|
599 } else if ((type == 0x000f) || (type == 0x0010)) {
|
|
600 /*
|
|
601 * Type = 0x000f: Session Length. (AIM)
|
|
602 * Type = 0x0010: Session Length. (AOL)
|
|
603 *
|
|
604 * The duration, in seconds, of the user's current
|
|
605 * session.
|
|
606 *
|
|
607 * Which TLV type this comes in depends on the
|
|
608 * service the user is using (AIM or AOL).
|
|
609 *
|
|
610 */
|
|
611 outinfo->sessionlen = aimbs_get32(bs);
|
|
612 outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN;
|
|
613
|
|
614 } else if (type == 0x0019) {
|
7141
|
615 /*
|
|
616 * Type = 0x0019
|
|
617 *
|
|
618 * OSCAR short capability information. A shortened
|
|
619 * form of the normal capabilities.
|
|
620 */
|
7011
|
621
|
|
622 } else if (type == 0x001b) {
|
7141
|
623 /*
|
|
624 * Type = 0x001a
|
|
625 *
|
|
626 * AOL short capability information. A shortened
|
|
627 * form of the normal capabilities.
|
|
628 */
|
|
629
|
|
630 } else if (type == 0x001b) {
|
|
631 /*
|
|
632 * Type = 0x0019
|
|
633 *
|
|
634 * Encryption certification MD5 checksum.
|
|
635 */
|
7011
|
636
|
|
637 } else if (type == 0x001d) {
|
|
638 /*
|
|
639 * Type = 0x001d
|
|
640 *
|
|
641 * Buddy icon information and available messages.
|
|
642 *
|
|
643 * This almost seems like the AIM protocol guys gave
|
|
644 * the iChat guys a Type, and the iChat guys tried to
|
|
645 * cram as much cool shit into it as possible. Then
|
|
646 * the Windows AIM guys were like, "hey, that's
|
|
647 * pretty neat, let's copy those prawns."
|
|
648 *
|
|
649 * In that spirit, this can contain a custom message,
|
|
650 * kind of like an away message, but you're not away
|
|
651 * (it's called an "available" message). Or it can
|
|
652 * contain information about the buddy icon the user
|
|
653 * has stored on the server.
|
|
654 */
|
|
655 int type2, number, length2;
|
|
656
|
|
657 while (aim_bstream_curpos(bs) < endpos) {
|
|
658 type2 = aimbs_get16(bs);
|
|
659 number = aimbs_get8(bs);
|
|
660 length2 = aimbs_get8(bs);
|
|
661
|
|
662 switch (type2) {
|
|
663 case 0x0000: { /* This is an official buddy icon? */
|
|
664 /* This is always 5 bytes of "0x02 01 d2 04 72"? */
|
|
665 aim_bstream_advance(bs, length2);
|
|
666 } break;
|
|
667
|
|
668 case 0x0001: { /* A buddy icon checksum */
|
|
669 if ((length2 > 0) && (number == 0x01)) {
|
|
670 free(outinfo->iconcsum);
|
|
671 outinfo->iconcsum = aimbs_getraw(bs, length2);
|
|
672 outinfo->iconcsumlen = length2;
|
|
673 } else
|
|
674 aim_bstream_advance(bs, length2);
|
|
675 } break;
|
|
676
|
|
677 case 0x0002: { /* An available message */
|
|
678 if (length2 > 4) {
|
|
679 free(outinfo->avail);
|
|
680 outinfo->avail_len = aimbs_get16(bs);
|
|
681 outinfo->avail = aimbs_getstr(bs, outinfo->avail_len);
|
|
682 if (aimbs_get16(bs) == 0x0001) { /* We have an encoding */
|
|
683 aimbs_get16(bs);
|
|
684 outinfo->avail_encoding = aimbs_getstr(bs, aimbs_get16(bs));
|
|
685 } else {
|
|
686 /* No explicit encoding, client should use UTF-8 */
|
|
687 outinfo->avail_encoding = NULL;
|
|
688 }
|
|
689 } else
|
|
690 aim_bstream_advance(bs, length2);
|
|
691 } break;
|
|
692
|
|
693 default: {
|
|
694 aim_bstream_advance(bs, length2);
|
|
695 } break;
|
|
696 }
|
|
697 }
|
|
698
|
|
699 } else if (type == 0x001e) {
|
|
700 /*
|
|
701 * Type 30: Unknown.
|
|
702 *
|
|
703 * Always four bytes, but it doesn't look like an int.
|
|
704 */
|
7025
|
705
|
|
706 } else if (type == 0x001f) {
|
|
707 /*
|
|
708 * Type 31: Unknown.
|
|
709 *
|
|
710 * Seen on a buddy using DeadAIM. Data was 4 bytes:
|
|
711 * 0x00 00 00 10
|
|
712 */
|
|
713
|
7011
|
714 } else {
|
|
715
|
|
716 /*
|
|
717 * Reaching here indicates that either AOL has
|
|
718 * added yet another TLV for us to deal with,
|
|
719 * or the parsing has gone Terribly Wrong.
|
|
720 *
|
|
721 * Either way, inform the owner and attempt
|
|
722 * recovery.
|
|
723 *
|
|
724 */
|
|
725 faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n");
|
|
726 faimdprintf(sess, 0, "userinfo: sn =%s\n", outinfo->sn);
|
|
727 dumptlv(sess, type, bs, length);
|
|
728 }
|
|
729
|
|
730 /* Save ourselves. */
|
|
731 aim_bstream_setpos(bs, endpos);
|
|
732 }
|
|
733
|
7045
|
734 aim_locate_adduserinfo(sess, outinfo);
|
7011
|
735
|
|
736 return 0;
|
|
737 }
|
|
738
|
|
739 /*
|
|
740 * Inverse of aim_info_extract()
|
|
741 */
|
|
742 faim_internal int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info)
|
|
743 {
|
|
744 aim_tlvlist_t *tlvlist = NULL;
|
|
745
|
|
746 if (!bs || !info)
|
|
747 return -EINVAL;
|
|
748
|
|
749 aimbs_put8(bs, strlen(info->sn));
|
|
750 aimbs_putraw(bs, info->sn, strlen(info->sn));
|
|
751
|
|
752 aimbs_put16(bs, info->warnlevel);
|
|
753
|
|
754 if (info->present & AIM_USERINFO_PRESENT_FLAGS)
|
7167
|
755 aim_tlvlist_add_16(&tlvlist, 0x0001, info->flags);
|
7011
|
756 if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE)
|
7167
|
757 aim_tlvlist_add_32(&tlvlist, 0x0002, info->membersince);
|
7011
|
758 if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE)
|
7167
|
759 aim_tlvlist_add_32(&tlvlist, 0x0003, info->onlinesince);
|
7011
|
760 if (info->present & AIM_USERINFO_PRESENT_IDLE)
|
7167
|
761 aim_tlvlist_add_16(&tlvlist, 0x0004, info->idletime);
|
7011
|
762
|
|
763 /* XXX - So, ICQ_OSCAR_SUPPORT is never defined anywhere... */
|
|
764 #if ICQ_OSCAR_SUPPORT
|
|
765 if (atoi(info->sn) != 0) {
|
|
766 if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS)
|
7167
|
767 aim_tlvlist_add_16(&tlvlist, 0x0006, info->icqinfo.status);
|
7011
|
768 if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR)
|
7167
|
769 aim_tlvlist_add_32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
|
7011
|
770 }
|
|
771 #endif
|
|
772
|
|
773 if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES)
|
7167
|
774 aim_tlvlist_add_caps(&tlvlist, 0x000d, info->capabilities);
|
7011
|
775
|
|
776 if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN)
|
7167
|
777 aim_tlvlist_add_32(&tlvlist, (fu16_t)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen);
|
7011
|
778
|
7167
|
779 aimbs_put16(bs, aim_tlvlist_count(&tlvlist));
|
|
780 aim_tlvlist_write(bs, &tlvlist);
|
|
781 aim_tlvlist_free(&tlvlist);
|
7011
|
782
|
|
783 return 0;
|
|
784 }
|
|
785
|
|
786 /*
|
7259
|
787 * Subtype 0x0001
|
|
788 */
|
|
789 static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
790 {
|
|
791 int ret = 0;
|
|
792 aim_rxcallback_t userfunc;
|
|
793 aim_snac_t *snac2;
|
|
794 fu16_t reason;
|
|
795 char *sn;
|
|
796 int was_explicit;
|
|
797
|
|
798 if (!(snac2 = aim_remsnac(sess, snac->id))) {
|
|
799 faimdprintf(sess, 0, "faim: locate.c, error(): received response from unknown request!\n");
|
|
800 return 0;
|
|
801 }
|
|
802
|
|
803 if ((snac2->family != 0x0002) && (snac2->type != 0x0015)) {
|
|
804 faimdprintf(sess, 0, "faim: locate.c, error(): received response from invalid request! %d\n", snac2->family);
|
|
805 return 0;
|
|
806 }
|
|
807
|
|
808 if (!(sn = snac2->data)) {
|
|
809 faimdprintf(sess, 0, "faim: locate.c, error(): received response from request without a screen name!\n");
|
|
810 return 0;
|
|
811 }
|
|
812
|
|
813 reason = aimbs_get16(bs);
|
|
814
|
|
815 /*
|
|
816 * Remove this screen name from our queue. If the client requested
|
|
817 * this buddy's info explicitly, then notify them that we do not have
|
|
818 * info for this buddy.
|
|
819 */
|
|
820 was_explicit = aim_locate_gotuserinfo(sess, sn);
|
|
821 if (was_explicit == TRUE)
|
|
822 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
823 ret = userfunc(sess, rx, reason, sn);
|
|
824
|
|
825 if (snac2)
|
|
826 free(snac2->data);
|
|
827 free(snac2);
|
|
828
|
|
829 return ret;
|
|
830 }
|
|
831
|
|
832 /*
|
7011
|
833 * Subtype 0x0002
|
|
834 *
|
|
835 * Request Location services rights.
|
|
836 *
|
|
837 */
|
|
838 faim_export int aim_locate_reqrights(aim_session_t *sess)
|
|
839 {
|
|
840 aim_conn_t *conn;
|
|
841
|
|
842 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
|
|
843 return -EINVAL;
|
|
844
|
|
845 return aim_genericreq_n(sess, conn, AIM_CB_FAM_LOC, AIM_CB_LOC_REQRIGHTS);
|
|
846 }
|
|
847
|
|
848 /*
|
|
849 * Subtype 0x0003
|
|
850 *
|
|
851 * Normally contains:
|
|
852 * t(0001) - short containing max profile length (value = 1024)
|
|
853 * t(0002) - short - unknown (value = 16) [max MIME type length?]
|
|
854 * t(0003) - short - unknown (value = 10)
|
|
855 * t(0004) - short - unknown (value = 2048) [ICQ only?]
|
|
856 */
|
|
857 static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
858 {
|
|
859 aim_tlvlist_t *tlvlist;
|
|
860 aim_rxcallback_t userfunc;
|
|
861 int ret = 0;
|
|
862 fu16_t maxsiglen = 0;
|
|
863
|
7167
|
864 tlvlist = aim_tlvlist_read(bs);
|
7011
|
865
|
7167
|
866 if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
|
|
867 maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1);
|
7011
|
868
|
|
869 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
870 ret = userfunc(sess, rx, maxsiglen);
|
|
871
|
7167
|
872 aim_tlvlist_free(&tlvlist);
|
7011
|
873
|
|
874 return ret;
|
|
875 }
|
|
876
|
|
877 /*
|
|
878 * Subtype 0x0004
|
|
879 *
|
|
880 * Gives BOS your profile.
|
|
881 *
|
|
882 * profile_encoding and awaymsg_encoding MUST be set if profile or
|
|
883 * away are set, respectively, and their value may or may not be
|
|
884 * restricted to a few choices. I am currently aware of:
|
|
885 *
|
|
886 * us-ascii Just that
|
|
887 * unicode-2-0 UCS2-BE
|
|
888 *
|
|
889 * profile_len and awaymsg_len MUST be set similarly, and they MUST
|
|
890 * be the length of their respective strings in bytes.
|
|
891 *
|
|
892 * To get the previous behavior of awaymsg == "" un-setting the away
|
|
893 * message, set awaymsg non-NULL and awaymsg_len to 0 (this is the
|
|
894 * obvious equivalent).
|
|
895 *
|
|
896 */
|
|
897 faim_export int aim_locate_setprofile(aim_session_t *sess,
|
|
898 const char *profile_encoding, const char *profile, const int profile_len,
|
|
899 const char *awaymsg_encoding, const char *awaymsg, const int awaymsg_len,
|
|
900 fu32_t caps)
|
|
901 {
|
|
902 aim_conn_t *conn;
|
|
903 aim_frame_t *fr;
|
|
904 aim_snacid_t snacid;
|
|
905 aim_tlvlist_t *tl = NULL;
|
|
906 char *encoding;
|
|
907 static const char defencoding[] = {"text/aolrtf; charset=\"%s\""};
|
|
908
|
|
909 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
|
|
910 return -EINVAL;
|
|
911
|
|
912 if ((profile && profile_encoding == NULL) || (awaymsg && awaymsg_len && awaymsg_encoding == NULL)) {
|
|
913 return -EINVAL;
|
|
914 }
|
|
915
|
|
916 /* Build the packet first to get real length */
|
|
917 if (profile) {
|
|
918 /* no + 1 here because of %s */
|
|
919 encoding = malloc(strlen(defencoding) + strlen(profile_encoding));
|
|
920 if (encoding == NULL) {
|
|
921 return -ENOMEM;
|
|
922 }
|
|
923 snprintf(encoding, strlen(defencoding) + strlen(profile_encoding), defencoding, profile_encoding);
|
7167
|
924 aim_tlvlist_add_raw(&tl, 0x0001, strlen(encoding), encoding);
|
|
925 aim_tlvlist_add_raw(&tl, 0x0002, profile_len, profile);
|
7011
|
926 free(encoding);
|
|
927 }
|
|
928
|
|
929 /*
|
|
930 * So here's how this works:
|
|
931 * - You are away when you have a non-zero-length type 4 TLV stored.
|
|
932 * - You become unaway when you clear the TLV with a zero-length
|
|
933 * type 4 TLV.
|
|
934 * - If you do not send the type 4 TLV, your status does not change
|
|
935 * (that is, if you were away, you'll remain away).
|
|
936 */
|
|
937 if (awaymsg) {
|
|
938 if (awaymsg_len) {
|
|
939 encoding = malloc(strlen(defencoding) + strlen(awaymsg_encoding));
|
|
940 if (encoding == NULL) {
|
|
941 return -ENOMEM;
|
|
942 }
|
|
943 snprintf(encoding, strlen(defencoding) + strlen(awaymsg_encoding), defencoding, awaymsg_encoding);
|
7167
|
944 aim_tlvlist_add_raw(&tl, 0x0003, strlen(encoding), encoding);
|
|
945 aim_tlvlist_add_raw(&tl, 0x0004, awaymsg_len, awaymsg);
|
7011
|
946 free(encoding);
|
|
947 } else
|
7167
|
948 aim_tlvlist_add_noval(&tl, 0x0004);
|
7011
|
949 }
|
|
950
|
7167
|
951 aim_tlvlist_add_caps(&tl, 0x0005, caps);
|
7011
|
952
|
7167
|
953 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
|
7011
|
954 return -ENOMEM;
|
|
955
|
|
956 snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
|
|
957 aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid);
|
|
958
|
7167
|
959 aim_tlvlist_write(&fr->data, &tl);
|
|
960 aim_tlvlist_free(&tl);
|
7011
|
961
|
|
962 aim_tx_enqueue(sess, fr);
|
|
963
|
|
964 return 0;
|
|
965 }
|
|
966
|
|
967 /*
|
|
968 * Subtype 0x0005 - Request info of another AIM user.
|
|
969 *
|
|
970 * @param sn The screenname whose info you wish to request.
|
|
971 * @param infotype The type of info you wish to request.
|
|
972 * 0x0001 - Info/profile
|
|
973 * 0x0003 - Away message
|
|
974 * 0x0004 - Capabilities
|
|
975 */
|
|
976 faim_export int aim_locate_getinfo(aim_session_t *sess, const char *sn, fu16_t infotype)
|
|
977 {
|
|
978 aim_conn_t *conn;
|
|
979 aim_frame_t *fr;
|
|
980 aim_snacid_t snacid;
|
|
981
|
|
982 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn)
|
|
983 return -EINVAL;
|
|
984
|
|
985 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn))))
|
|
986 return -ENOMEM;
|
|
987
|
|
988 snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, NULL, 0);
|
|
989
|
|
990 aim_putsnac(&fr->data, 0x0002, 0x0005, 0x0000, snacid);
|
|
991 aimbs_put16(&fr->data, infotype);
|
|
992 aimbs_put8(&fr->data, strlen(sn));
|
|
993 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
994
|
|
995 aim_tx_enqueue(sess, fr);
|
|
996
|
|
997 return 0;
|
|
998 }
|
|
999
|
|
1000 /* Subtype 0x0006 */
|
|
1001 static int userinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1002 {
|
|
1003 int ret = 0;
|
|
1004 aim_rxcallback_t userfunc;
|
|
1005 aim_userinfo_t *userinfo, *userinfo2;
|
|
1006 aim_tlvlist_t *tlvlist;
|
|
1007 aim_tlv_t *tlv = NULL;
|
|
1008 int was_explicit;
|
|
1009
|
|
1010 userinfo = (aim_userinfo_t *)malloc(sizeof(aim_userinfo_t));
|
|
1011 aim_info_extract(sess, bs, userinfo);
|
7167
|
1012 tlvlist = aim_tlvlist_read(bs);
|
7011
|
1013
|
|
1014 /* Profile will be 1 and 2 */
|
7167
|
1015 userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1);
|
|
1016 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) {
|
7011
|
1017 userinfo->info = (char *)malloc(tlv->length);
|
|
1018 memcpy(userinfo->info, tlv->value, tlv->length);
|
|
1019 userinfo->info_len = tlv->length;
|
|
1020 }
|
|
1021
|
|
1022 /* Away message will be 3 and 4 */
|
7167
|
1023 userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1);
|
|
1024 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
|
7011
|
1025 userinfo->away = (char *)malloc(tlv->length);
|
|
1026 memcpy(userinfo->away, tlv->value, tlv->length);
|
|
1027 userinfo->away_len = tlv->length;
|
|
1028 }
|
|
1029
|
|
1030 /* Caps will be 5 */
|
7167
|
1031 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1))) {
|
7011
|
1032 aim_bstream_t cbs;
|
|
1033 aim_bstream_init(&cbs, tlv->value, tlv->length);
|
|
1034 userinfo->capabilities = aim_getcap(sess, &cbs, tlv->length);
|
|
1035 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES;
|
|
1036 }
|
7167
|
1037 aim_tlvlist_free(&tlvlist);
|
7011
|
1038
|
7045
|
1039 aim_locate_adduserinfo(sess, userinfo);
|
|
1040 userinfo2 = aim_locate_finduserinfo(sess, userinfo->sn);
|
7011
|
1041 aim_info_free(userinfo);
|
|
1042 free(userinfo);
|
|
1043
|
|
1044 /*
|
|
1045 * Remove this screen name from our queue. If the client requested
|
|
1046 * this buddy's info explicitly, then notify them that we have info
|
|
1047 * for this buddy.
|
|
1048 */
|
7259
|
1049 was_explicit = aim_locate_gotuserinfo(sess, userinfo2->sn);
|
|
1050 if (was_explicit == TRUE)
|
7011
|
1051 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1052 ret = userfunc(sess, rx, userinfo2);
|
|
1053
|
|
1054 return ret;
|
|
1055 }
|
|
1056
|
|
1057 /*
|
|
1058 * Subtype 0x0009 - Set directory profile data.
|
|
1059 *
|
|
1060 * This is not the same as aim_location_setprofile!
|
|
1061 * privacy: 1 to allow searching, 0 to disallow.
|
|
1062 *
|
|
1063 */
|
|
1064 faim_export int aim_locate_setdirinfo(aim_session_t *sess, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, fu16_t privacy)
|
|
1065 {
|
|
1066 aim_conn_t *conn;
|
|
1067 aim_frame_t *fr;
|
|
1068 aim_snacid_t snacid;
|
|
1069 aim_tlvlist_t *tl = NULL;
|
|
1070
|
|
1071 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
|
|
1072 return -EINVAL;
|
|
1073
|
7167
|
1074 aim_tlvlist_add_16(&tl, 0x000a, privacy);
|
7011
|
1075
|
|
1076 if (first)
|
7167
|
1077 aim_tlvlist_add_raw(&tl, 0x0001, strlen(first), first);
|
7011
|
1078 if (last)
|
7167
|
1079 aim_tlvlist_add_raw(&tl, 0x0002, strlen(last), last);
|
7011
|
1080 if (middle)
|
7167
|
1081 aim_tlvlist_add_raw(&tl, 0x0003, strlen(middle), middle);
|
7011
|
1082 if (maiden)
|
7167
|
1083 aim_tlvlist_add_raw(&tl, 0x0004, strlen(maiden), maiden);
|
7011
|
1084
|
|
1085 if (state)
|
7167
|
1086 aim_tlvlist_add_raw(&tl, 0x0007, strlen(state), state);
|
7011
|
1087 if (city)
|
7167
|
1088 aim_tlvlist_add_raw(&tl, 0x0008, strlen(city), city);
|
7011
|
1089
|
|
1090 if (nickname)
|
7167
|
1091 aim_tlvlist_add_raw(&tl, 0x000c, strlen(nickname), nickname);
|
7011
|
1092 if (zip)
|
7167
|
1093 aim_tlvlist_add_raw(&tl, 0x000d, strlen(zip), zip);
|
7011
|
1094
|
|
1095 if (street)
|
7167
|
1096 aim_tlvlist_add_raw(&tl, 0x0021, strlen(street), street);
|
7011
|
1097
|
7167
|
1098 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
|
7011
|
1099 return -ENOMEM;
|
|
1100
|
|
1101 snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0);
|
|
1102
|
|
1103 aim_putsnac(&fr->data, 0x0002, 0x0009, 0x0000, snacid);
|
7167
|
1104 aim_tlvlist_write(&fr->data, &tl);
|
|
1105 aim_tlvlist_free(&tl);
|
7011
|
1106
|
|
1107 aim_tx_enqueue(sess, fr);
|
|
1108
|
|
1109 return 0;
|
|
1110 }
|
|
1111
|
|
1112 /*
|
|
1113 * Subtype 0x000b - Huh? What is this?
|
|
1114 */
|
|
1115 faim_export int aim_locate_000b(aim_session_t *sess, const char *sn)
|
|
1116 {
|
|
1117 aim_conn_t *conn;
|
|
1118 aim_frame_t *fr;
|
|
1119 aim_snacid_t snacid;
|
|
1120
|
|
1121 return -EINVAL;
|
|
1122
|
|
1123 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn)
|
|
1124 return -EINVAL;
|
|
1125
|
|
1126 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
|
|
1127 return -ENOMEM;
|
|
1128
|
|
1129 snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0);
|
|
1130
|
|
1131 aim_putsnac(&fr->data, 0x0002, 0x000b, 0x0000, snacid);
|
|
1132 aimbs_put8(&fr->data, strlen(sn));
|
|
1133 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1134
|
|
1135 aim_tx_enqueue(sess, fr);
|
|
1136
|
|
1137 return 0;
|
|
1138 }
|
|
1139
|
|
1140 /*
|
|
1141 * Subtype 0x000f
|
|
1142 *
|
|
1143 * XXX pass these in better
|
|
1144 *
|
|
1145 */
|
|
1146 faim_export int aim_locate_setinterests(aim_session_t *sess, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, fu16_t privacy)
|
|
1147 {
|
|
1148 aim_conn_t *conn;
|
|
1149 aim_frame_t *fr;
|
|
1150 aim_snacid_t snacid;
|
|
1151 aim_tlvlist_t *tl = NULL;
|
|
1152
|
|
1153 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
|
|
1154 return -EINVAL;
|
|
1155
|
|
1156 /* ?? privacy ?? */
|
7167
|
1157 aim_tlvlist_add_16(&tl, 0x000a, privacy);
|
7011
|
1158
|
|
1159 if (interest1)
|
7167
|
1160 aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest1), interest1);
|
7011
|
1161 if (interest2)
|
7167
|
1162 aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest2), interest2);
|
7011
|
1163 if (interest3)
|
7167
|
1164 aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest3), interest3);
|
7011
|
1165 if (interest4)
|
7167
|
1166 aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest4), interest4);
|
7011
|
1167 if (interest5)
|
7167
|
1168 aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest5), interest5);
|
7011
|
1169
|
7167
|
1170 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
|
7011
|
1171 return -ENOMEM;
|
|
1172
|
|
1173 snacid = aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0);
|
|
1174
|
|
1175 aim_putsnac(&fr->data, 0x0002, 0x000f, 0x0000, 0);
|
7167
|
1176 aim_tlvlist_write(&fr->data, &tl);
|
|
1177 aim_tlvlist_free(&tl);
|
7011
|
1178
|
|
1179 aim_tx_enqueue(sess, fr);
|
|
1180
|
|
1181 return 0;
|
|
1182 }
|
|
1183
|
|
1184 /*
|
|
1185 * Subtype 0x0015 - Request the info a user using the short method. This is
|
|
1186 * what iChat uses. It normally is VERY leniently rate limited.
|
|
1187 *
|
|
1188 * @param sn The screen name whose info you wish to request.
|
|
1189 * @param flags The bitmask which specifies the type of info you wish to request.
|
|
1190 * 0x00000001 - Info/profile.
|
|
1191 * 0x00000002 - Away message.
|
|
1192 * 0x00000004 - Capabilities.
|
|
1193 * 0x00000008 - Certification.
|
|
1194 * @return Return 0 if no errors, otherwise return the error number.
|
|
1195 */
|
|
1196 faim_export int aim_locate_getinfoshort(aim_session_t *sess, const char *sn, fu32_t flags)
|
|
1197 {
|
|
1198 aim_conn_t *conn;
|
|
1199 aim_frame_t *fr;
|
|
1200 aim_snacid_t snacid;
|
|
1201
|
|
1202 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn)
|
|
1203 return -EINVAL;
|
|
1204
|
|
1205 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+1+strlen(sn))))
|
|
1206 return -ENOMEM;
|
|
1207
|
7259
|
1208 snacid = aim_cachesnac(sess, 0x0002, 0x0015, 0x0000, sn, strlen(sn)+1);
|
7011
|
1209
|
7259
|
1210 aim_putsnac(&fr->data, 0x0002, 0x0015, 0x0000, snacid);
|
7011
|
1211 aimbs_put32(&fr->data, flags);
|
|
1212 aimbs_put8(&fr->data, strlen(sn));
|
|
1213 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1214
|
|
1215 aim_tx_enqueue(sess, fr);
|
|
1216
|
|
1217 return 0;
|
|
1218 }
|
|
1219
|
|
1220 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1221 {
|
|
1222
|
7259
|
1223 if (snac->subtype == 0x0001)
|
|
1224 return error(sess, mod, rx, snac, bs);
|
|
1225 else if (snac->subtype == 0x0003)
|
7011
|
1226 return rights(sess, mod, rx, snac, bs);
|
|
1227 else if (snac->subtype == 0x0006)
|
|
1228 return userinfo(sess, mod, rx, snac, bs);
|
|
1229
|
|
1230 return 0;
|
|
1231 }
|
|
1232
|
|
1233 static void locate_shutdown(aim_session_t *sess, aim_module_t *mod)
|
|
1234 {
|
|
1235 aim_userinfo_t *del;
|
|
1236
|
7045
|
1237 while (sess->locate.userinfo) {
|
|
1238 del = sess->locate.userinfo;
|
|
1239 sess->locate.userinfo = sess->locate.userinfo->next;
|
7046
|
1240 aim_info_free(del);
|
7011
|
1241 free(del);
|
|
1242 }
|
|
1243 }
|
|
1244
|
|
1245 faim_internal int locate_modfirst(aim_session_t *sess, aim_module_t *mod)
|
|
1246 {
|
|
1247
|
|
1248 mod->family = AIM_CB_FAM_LOC;
|
|
1249 mod->version = 0x0001;
|
|
1250 mod->toolid = 0x0110;
|
|
1251 mod->toolversion = 0x0629;
|
|
1252 mod->flags = 0;
|
|
1253 strncpy(mod->name, "locate", sizeof(mod->name));
|
|
1254 mod->snachandler = snachandler;
|
|
1255 mod->shutdown = locate_shutdown;
|
|
1256
|
|
1257 return 0;
|
|
1258 }
|