comparison libpurple/protocols/oscar/family_locate.c @ 15374:5fe8042783c1

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