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