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