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