]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | /* |
2 | * aim_info.c | |
3 | * | |
4 | * The functions here are responsible for requesting and parsing information- | |
d410cf58 | 5 | * gathering SNACs. Or something like that. |
9de3ca7e | 6 | * |
7 | */ | |
8 | ||
37ee990e | 9 | #define FAIM_INTERNAL |
dd60ff8b | 10 | #include <aim.h> |
9de3ca7e | 11 | |
262272cc | 12 | struct aim_priv_inforeq { |
d410cf58 | 13 | char sn[MAXSNLEN+1]; |
14 | fu16_t infotype; | |
262272cc | 15 | }; |
16 | ||
d410cf58 | 17 | faim_export int aim_getinfo(aim_session_t *sess, aim_conn_t *conn, const char *sn, fu16_t infotype) |
9de3ca7e | 18 | { |
d410cf58 | 19 | struct aim_priv_inforeq privdata; |
20 | aim_frame_t *fr; | |
21 | aim_snacid_t snacid; | |
276495a3 | 22 | |
d410cf58 | 23 | if (!sess || !conn || !sn) |
24 | return -EINVAL; | |
00ef5271 | 25 | |
d410cf58 | 26 | if ((infotype != AIM_GETINFO_GENERALINFO) && (infotype != AIM_GETINFO_AWAYMESSAGE)) |
27 | return -EINVAL; | |
9de3ca7e | 28 | |
d410cf58 | 29 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn)))) |
30 | return -ENOMEM; | |
9de3ca7e | 31 | |
d410cf58 | 32 | strncpy(privdata.sn, sn, sizeof(privdata.sn)); |
33 | privdata.infotype = infotype; | |
34 | snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq)); | |
35 | ||
36 | aim_putsnac(&fr->data, 0x0002, 0x0005, 0x0000, snacid); | |
37 | aimbs_put16(&fr->data, infotype); | |
38 | aimbs_put8(&fr->data, strlen(sn)); | |
39 | aimbs_putraw(&fr->data, sn, strlen(sn)); | |
9de3ca7e | 40 | |
d410cf58 | 41 | aim_tx_enqueue(sess, fr); |
9de3ca7e | 42 | |
d410cf58 | 43 | return 0; |
96f8b1ed | 44 | } |
5b79dc93 | 45 | |
7b0bc7f2 | 46 | faim_export const char *aim_userinfo_sn(aim_userinfo_t *ui) |
47 | { | |
48 | ||
49 | if (!ui) | |
50 | return NULL; | |
51 | ||
52 | return ui->sn; | |
53 | } | |
54 | ||
55 | faim_export fu16_t aim_userinfo_flags(aim_userinfo_t *ui) | |
56 | { | |
57 | ||
58 | if (!ui) | |
59 | return 0; | |
60 | ||
61 | return ui->flags; | |
62 | } | |
63 | ||
64 | faim_export fu16_t aim_userinfo_idle(aim_userinfo_t *ui) | |
65 | { | |
66 | ||
67 | if (!ui) | |
68 | return 0; | |
69 | ||
70 | return ui->idletime; | |
71 | } | |
72 | ||
73 | faim_export float aim_userinfo_warnlevel(aim_userinfo_t *ui) | |
74 | { | |
75 | ||
76 | if (!ui) | |
77 | return 0.00; | |
78 | ||
79 | return (ui->warnlevel / 10); | |
80 | } | |
81 | ||
82 | faim_export time_t aim_userinfo_membersince(aim_userinfo_t *ui) | |
83 | { | |
84 | ||
85 | if (!ui) | |
86 | return 0; | |
87 | ||
88 | return (time_t)ui->membersince; | |
89 | } | |
90 | ||
91 | faim_export time_t aim_userinfo_onlinesince(aim_userinfo_t *ui) | |
92 | { | |
93 | ||
94 | if (!ui) | |
95 | return 0; | |
96 | ||
97 | return (time_t)ui->onlinesince; | |
98 | } | |
99 | ||
100 | faim_export fu32_t aim_userinfo_sessionlen(aim_userinfo_t *ui) | |
101 | { | |
102 | ||
103 | if (!ui) | |
104 | return 0; | |
105 | ||
106 | return ui->sessionlen; | |
107 | } | |
108 | ||
109 | faim_export int aim_userinfo_hascap(aim_userinfo_t *ui, fu16_t cap) | |
110 | { | |
111 | ||
112 | if (!ui || !ui->capspresent) | |
113 | return -1; | |
114 | ||
115 | return !!(ui->capabilities & cap); | |
116 | } | |
117 | ||
118 | ||
5b79dc93 | 119 | /* |
120 | * Capability blocks. | |
121 | */ | |
f7bb124a | 122 | static const struct { |
d410cf58 | 123 | unsigned short flag; |
124 | unsigned char data[16]; | |
f7bb124a | 125 | } aim_caps[] = { |
d410cf58 | 126 | |
127 | {AIM_CAPS_BUDDYICON, | |
128 | {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1, | |
129 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
130 | ||
131 | {AIM_CAPS_VOICE, | |
132 | {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1, | |
133 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
134 | ||
135 | {AIM_CAPS_IMIMAGE, | |
136 | {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1, | |
137 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
138 | ||
139 | {AIM_CAPS_CHAT, | |
140 | {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1, | |
141 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
142 | ||
143 | {AIM_CAPS_GETFILE, | |
144 | {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1, | |
145 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
146 | ||
147 | {AIM_CAPS_SENDFILE, | |
148 | {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, | |
149 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
150 | ||
151 | {AIM_CAPS_SAVESTOCKS, | |
152 | {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1, | |
153 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
154 | ||
155 | /* | |
156 | * Indeed, there are two of these. The former appears to be correct, | |
157 | * but in some versions of winaim, the second one is set. Either they | |
158 | * forgot to fix endianness, or they made a typo. It really doesn't | |
159 | * matter which. | |
160 | */ | |
161 | {AIM_CAPS_GAMES, | |
162 | {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1, | |
163 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
164 | {AIM_CAPS_GAMES2, | |
165 | {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1, | |
166 | 0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
167 | ||
168 | {AIM_CAPS_SENDBUDDYLIST, | |
169 | {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1, | |
170 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, | |
171 | ||
172 | {AIM_CAPS_LAST} | |
5b79dc93 | 173 | }; |
174 | ||
d410cf58 | 175 | /* |
176 | * This still takes a length parameter even with a bstream because capabilities | |
177 | * are not naturally bounded. | |
178 | * | |
179 | */ | |
180 | faim_internal fu16_t aim_getcap(aim_session_t *sess, aim_bstream_t *bs, int len) | |
b69540e3 | 181 | { |
d410cf58 | 182 | fu16_t flags = 0; |
183 | int offset; | |
184 | ||
185 | for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x10) { | |
186 | fu8_t *cap; | |
187 | int i, identified; | |
b69540e3 | 188 | |
d410cf58 | 189 | cap = aimbs_getraw(bs, 0x10); |
f7bb124a | 190 | |
d410cf58 | 191 | for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) { |
f7bb124a | 192 | |
d410cf58 | 193 | if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) { |
194 | flags |= aim_caps[i].flag; | |
195 | identified++; | |
196 | break; /* should only match once... */ | |
f7bb124a | 197 | |
d410cf58 | 198 | } |
199 | } | |
f7bb124a | 200 | |
d410cf58 | 201 | if (!identified) |
202 | faimdprintf(sess, 0, "unknown capability!\n"); | |
0589dc54 | 203 | |
d410cf58 | 204 | free(cap); |
205 | } | |
f7bb124a | 206 | |
d410cf58 | 207 | return flags; |
b69540e3 | 208 | } |
209 | ||
d410cf58 | 210 | faim_internal int aim_putcap(aim_bstream_t *bs, fu16_t caps) |
b69540e3 | 211 | { |
d410cf58 | 212 | int i; |
b69540e3 | 213 | |
d410cf58 | 214 | if (!bs) |
215 | return -EINVAL; | |
f7bb124a | 216 | |
d410cf58 | 217 | for (i = 0; aim_bstream_empty(bs); i++) { |
f7bb124a | 218 | |
d410cf58 | 219 | if (aim_caps[i].flag == AIM_CAPS_LAST) |
220 | break; | |
b69540e3 | 221 | |
d410cf58 | 222 | if (caps & aim_caps[i].flag) |
223 | aimbs_putraw(bs, aim_caps[i].data, 0x10); | |
b69540e3 | 224 | |
d410cf58 | 225 | } |
226 | ||
227 | return 0; | |
b69540e3 | 228 | } |
229 | ||
9de3ca7e | 230 | /* |
d410cf58 | 231 | * AIM is fairly regular about providing user info. This is a generic |
232 | * routine to extract it in its standard form. | |
9de3ca7e | 233 | */ |
7b0bc7f2 | 234 | faim_internal int aim_extractuserinfo(aim_session_t *sess, aim_bstream_t *bs, aim_userinfo_t *outinfo) |
9de3ca7e | 235 | { |
d410cf58 | 236 | int curtlv, tlvcnt; |
237 | fu8_t snlen; | |
238 | ||
239 | if (!bs || !outinfo) | |
240 | return -EINVAL; | |
241 | ||
242 | /* Clear out old data first */ | |
7b0bc7f2 | 243 | memset(outinfo, 0x00, sizeof(aim_userinfo_t)); |
d410cf58 | 244 | |
245 | /* | |
246 | * Screen name. Stored as an unterminated string prepended with a | |
247 | * byte containing its length. | |
248 | */ | |
249 | snlen = aimbs_get8(bs); | |
250 | aimbs_getrawbuf(bs, outinfo->sn, snlen); | |
251 | ||
252 | /* | |
253 | * Warning Level. Stored as an unsigned short. | |
254 | */ | |
255 | outinfo->warnlevel = aimbs_get16(bs); | |
256 | ||
257 | /* | |
258 | * TLV Count. Unsigned short representing the number of | |
259 | * Type-Length-Value triples that follow. | |
260 | */ | |
261 | tlvcnt = aimbs_get16(bs); | |
262 | ||
263 | /* | |
264 | * Parse out the Type-Length-Value triples as they're found. | |
265 | */ | |
266 | for (curtlv = 0; curtlv < tlvcnt; curtlv++) { | |
267 | int endpos; | |
268 | fu16_t type, length; | |
269 | ||
270 | type = aimbs_get16(bs); | |
271 | length = aimbs_get16(bs); | |
272 | ||
273 | endpos = aim_bstream_curpos(bs) + length; | |
274 | ||
275 | if (type == 0x0001) { | |
276 | /* | |
277 | * Type = 0x0001: User flags | |
278 | * | |
279 | * Specified as any of the following ORed together: | |
280 | * 0x0001 Trial (user less than 60days) | |
281 | * 0x0002 Unknown bit 2 | |
282 | * 0x0004 AOL Main Service user | |
283 | * 0x0008 Unknown bit 4 | |
284 | * 0x0010 Free (AIM) user | |
285 | * 0x0020 Away | |
25aaf30e | 286 | * 0x0400 ActiveBuddy |
d410cf58 | 287 | * |
288 | */ | |
289 | outinfo->flags = aimbs_get16(bs); | |
290 | ||
291 | } else if (type == 0x0002) { | |
292 | /* | |
293 | * Type = 0x0002: Member-Since date. | |
294 | * | |
295 | * The time/date that the user originally registered for | |
296 | * the service, stored in time_t format. | |
297 | */ | |
298 | outinfo->membersince = aimbs_get32(bs); | |
299 | ||
300 | } else if (type == 0x0003) { | |
301 | /* | |
302 | * Type = 0x0003: On-Since date. | |
303 | * | |
304 | * The time/date that the user started their current | |
305 | * session, stored in time_t format. | |
306 | */ | |
307 | outinfo->onlinesince = aimbs_get32(bs); | |
308 | ||
309 | } else if (type == 0x0004) { | |
310 | /* | |
311 | * Type = 0x0004: Idle time. | |
312 | * | |
313 | * Number of seconds since the user actively used the | |
314 | * service. | |
315 | * | |
316 | * Note that the client tells the server when to start | |
317 | * counting idle times, so this may or may not be | |
318 | * related to reality. | |
319 | */ | |
320 | outinfo->idletime = aimbs_get16(bs); | |
321 | ||
322 | } else if (type == 0x0006) { | |
323 | /* | |
324 | * Type = 0x0006: ICQ Online Status | |
325 | * | |
326 | * ICQ's Away/DND/etc "enriched" status. Some decoding | |
327 | * of values done by Scott <darkagl@pcnet.com> | |
328 | */ | |
329 | aimbs_get16(bs); | |
330 | outinfo->icqinfo.status = aimbs_get16(bs); | |
331 | ||
332 | } else if (type == 0x000a) { | |
333 | /* | |
334 | * Type = 0x000a | |
335 | * | |
336 | * ICQ User IP Address. | |
337 | * Ahh, the joy of ICQ security. | |
338 | */ | |
339 | outinfo->icqinfo.ipaddr = aimbs_get32(bs); | |
340 | ||
341 | } else if (type == 0x000c) { | |
342 | /* | |
343 | * Type = 0x000c | |
344 | * | |
345 | * random crap containing the IP address, | |
346 | * apparently a port number, and some Other Stuff. | |
347 | * | |
348 | */ | |
349 | aimbs_getrawbuf(bs, outinfo->icqinfo.crap, 0x25); | |
350 | ||
351 | } else if (type == 0x000d) { | |
352 | /* | |
353 | * Type = 0x000d | |
354 | * | |
355 | * Capability information. | |
356 | * | |
357 | */ | |
358 | outinfo->capabilities = aim_getcap(sess, bs, length); | |
7b0bc7f2 | 359 | outinfo->capspresent = 1; |
d410cf58 | 360 | |
361 | } else if (type == 0x000e) { | |
362 | /* | |
363 | * Type = 0x000e | |
364 | * | |
365 | * Unknown. Always of zero length, and always only | |
366 | * on AOL users. | |
367 | * | |
368 | * Ignore. | |
369 | * | |
370 | */ | |
371 | ||
372 | } else if ((type == 0x000f) || (type == 0x0010)) { | |
373 | /* | |
374 | * Type = 0x000f: Session Length. (AIM) | |
375 | * Type = 0x0010: Session Length. (AOL) | |
376 | * | |
377 | * The duration, in seconds, of the user's current | |
378 | * session. | |
379 | * | |
380 | * Which TLV type this comes in depends on the | |
381 | * service the user is using (AIM or AOL). | |
382 | * | |
383 | */ | |
384 | outinfo->sessionlen = aimbs_get32(bs); | |
385 | ||
386 | } else { | |
387 | ||
388 | /* | |
389 | * Reaching here indicates that either AOL has | |
390 | * added yet another TLV for us to deal with, | |
391 | * or the parsing has gone Terribly Wrong. | |
392 | * | |
393 | * Either way, inform the owner and attempt | |
394 | * recovery. | |
395 | * | |
396 | */ | |
397 | faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n"); | |
398 | faimdprintf(sess, 0, "userinfo: sn =%s\n", outinfo->sn); | |
399 | faimdprintf(sess, 0, "userinfo: type =0x%04x\n",type); | |
400 | faimdprintf(sess, 0, "userinfo: length=0x%04x\n", length); | |
401 | ||
402 | } | |
403 | ||
404 | /* Save ourselves. */ | |
405 | aim_bstream_setpos(bs, endpos); | |
406 | } | |
407 | ||
408 | return 0; | |
9de3ca7e | 409 | } |
410 | ||
50443ea0 | 411 | /* |
412 | * Inverse of aim_extractuserinfo() | |
413 | */ | |
7b0bc7f2 | 414 | faim_internal int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info) |
50443ea0 | 415 | { |
d410cf58 | 416 | aim_tlvlist_t *tlvlist = NULL; |
50443ea0 | 417 | |
d410cf58 | 418 | if (!bs || !info) |
419 | return -EINVAL; | |
50443ea0 | 420 | |
d410cf58 | 421 | aimbs_put8(bs, strlen(info->sn)); |
422 | aimbs_putraw(bs, info->sn, strlen(info->sn)); | |
50443ea0 | 423 | |
d410cf58 | 424 | aimbs_put16(bs, info->warnlevel); |
50443ea0 | 425 | |
9c38f1a7 | 426 | |
d410cf58 | 427 | aim_addtlvtochain16(&tlvlist, 0x0001, info->flags); |
428 | aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince); | |
429 | aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince); | |
430 | aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime); | |
3b101546 | 431 | |
432 | #if ICQ_OSCAR_SUPPORT | |
d410cf58 | 433 | if (atoi(info->sn) != 0) { |
434 | aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status); | |
435 | aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr); | |
436 | } | |
3b101546 | 437 | #endif |
438 | ||
d410cf58 | 439 | aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities); |
3b101546 | 440 | |
d410cf58 | 441 | aim_addtlvtochain32(&tlvlist, (fu16_t)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); |
3b101546 | 442 | |
d410cf58 | 443 | aimbs_put16(bs, aim_counttlvchain(&tlvlist)); |
444 | aim_writetlvchain(bs, &tlvlist); | |
445 | aim_freetlvchain(&tlvlist); | |
3b101546 | 446 | |
d410cf58 | 447 | return 0; |
50443ea0 | 448 | } |
449 | ||
7b0bc7f2 | 450 | faim_export int aim_sendbuddyoncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info) |
50443ea0 | 451 | { |
d410cf58 | 452 | aim_frame_t *fr; |
453 | aim_snacid_t snacid; | |
50443ea0 | 454 | |
d410cf58 | 455 | if (!sess || !conn || !info) |
456 | return -EINVAL; | |
50443ea0 | 457 | |
d410cf58 | 458 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) |
459 | return -ENOMEM; | |
50443ea0 | 460 | |
d410cf58 | 461 | snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0); |
462 | ||
463 | aim_putsnac(&fr->data, 0x0003, 0x000b, 0x0000, snacid); | |
464 | aim_putuserinfo(&fr->data, info); | |
50443ea0 | 465 | |
d410cf58 | 466 | aim_tx_enqueue(sess, fr); |
50443ea0 | 467 | |
d410cf58 | 468 | return 0; |
50443ea0 | 469 | } |
470 | ||
d410cf58 | 471 | faim_export int aim_sendbuddyoffgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
50443ea0 | 472 | { |
d410cf58 | 473 | aim_frame_t *fr; |
474 | aim_snacid_t snacid; | |
50443ea0 | 475 | |
d410cf58 | 476 | if (!sess || !conn || !sn) |
477 | return -EINVAL; | |
50443ea0 | 478 | |
d410cf58 | 479 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
480 | return -ENOMEM; | |
50443ea0 | 481 | |
d410cf58 | 482 | snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0); |
483 | ||
484 | aim_putsnac(&fr->data, 0x0003, 0x000c, 0x0000, snacid); | |
485 | aimbs_put8(&fr->data, strlen(sn)); | |
486 | aimbs_putraw(&fr->data, sn, strlen(sn)); | |
50443ea0 | 487 | |
d410cf58 | 488 | aim_tx_enqueue(sess, fr); |
50443ea0 | 489 | |
d410cf58 | 490 | return 0; |
50443ea0 | 491 | } |
262272cc | 492 | |
d410cf58 | 493 | /* |
494 | * Huh? What is this? | |
495 | */ | |
496 | faim_export int aim_0002_000b(aim_session_t *sess, aim_conn_t *conn, const char *sn) | |
e80a0fa9 | 497 | { |
d410cf58 | 498 | aim_frame_t *fr; |
499 | aim_snacid_t snacid; | |
e80a0fa9 | 500 | |
d410cf58 | 501 | if (!sess || !conn || !sn) |
502 | return -EINVAL; | |
e80a0fa9 | 503 | |
d410cf58 | 504 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
505 | return -ENOMEM; | |
e80a0fa9 | 506 | |
d410cf58 | 507 | snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0); |
508 | ||
509 | aim_putsnac(&fr->data, 0x0002, 0x000b, 0x0000, snacid); | |
510 | aimbs_put8(&fr->data, strlen(sn)); | |
511 | aimbs_putraw(&fr->data, sn, strlen(sn)); | |
e80a0fa9 | 512 | |
d410cf58 | 513 | aim_tx_enqueue(sess, fr); |
e80a0fa9 | 514 | |
d410cf58 | 515 | return 0; |
e80a0fa9 | 516 | } |
517 | ||
b39e0a91 | 518 | /* |
519 | * Normally contains: | |
520 | * t(0001) - short containing max profile length (value = 1024) | |
521 | * t(0002) - short - unknown (value = 16) [max MIME type length?] | |
25aaf30e | 522 | * t(0003) - short - unknown (value = 10) |
b39e0a91 | 523 | */ |
d410cf58 | 524 | static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
00ef5271 | 525 | { |
d410cf58 | 526 | aim_tlvlist_t *tlvlist; |
0867959e | 527 | aim_rxcallback_t userfunc; |
528 | int ret = 0; | |
d410cf58 | 529 | fu16_t maxsiglen = 0; |
b39e0a91 | 530 | |
d410cf58 | 531 | tlvlist = aim_readtlvchain(bs); |
00ef5271 | 532 | |
0867959e | 533 | if (aim_gettlv(tlvlist, 0x0001, 1)) |
534 | maxsiglen = aim_gettlv16(tlvlist, 0x0001, 1); | |
00ef5271 | 535 | |
0867959e | 536 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
537 | ret = userfunc(sess, rx, maxsiglen); | |
b39e0a91 | 538 | |
0867959e | 539 | aim_freetlvchain(&tlvlist); |
00ef5271 | 540 | |
0867959e | 541 | return ret; |
00ef5271 | 542 | } |
543 | ||
d410cf58 | 544 | static int userinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
00ef5271 | 545 | { |
7b0bc7f2 | 546 | aim_userinfo_t userinfo; |
d410cf58 | 547 | char *text_encoding = NULL, *text = NULL; |
548 | aim_rxcallback_t userfunc; | |
549 | aim_tlvlist_t *tlvlist; | |
550 | aim_snac_t *origsnac = NULL; | |
551 | struct aim_priv_inforeq *inforeq; | |
552 | int ret = 0; | |
553 | ||
554 | origsnac = aim_remsnac(sess, snac->id); | |
555 | ||
556 | if (!origsnac || !origsnac->data) { | |
557 | faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n"); | |
558 | return 0; | |
559 | } | |
560 | ||
561 | inforeq = (struct aim_priv_inforeq *)origsnac->data; | |
562 | ||
563 | if ((inforeq->infotype != AIM_GETINFO_GENERALINFO) && | |
564 | (inforeq->infotype != AIM_GETINFO_AWAYMESSAGE)) { | |
565 | faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype); | |
566 | return 0; | |
567 | } | |
568 | ||
569 | aim_extractuserinfo(sess, bs, &userinfo); | |
570 | ||
571 | tlvlist = aim_readtlvchain(bs); | |
572 | ||
573 | /* | |
574 | * Depending on what informational text was requested, different | |
575 | * TLVs will appear here. | |
576 | * | |
577 | * Profile will be 1 and 2, away message will be 3 and 4. | |
578 | */ | |
579 | if (aim_gettlv(tlvlist, 0x0001, 1)) { | |
580 | text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1); | |
581 | text = aim_gettlv_str(tlvlist, 0x0002, 1); | |
582 | } else if (aim_gettlv(tlvlist, 0x0003, 1)) { | |
583 | text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1); | |
584 | text = aim_gettlv_str(tlvlist, 0x0004, 1); | |
585 | } | |
586 | ||
587 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
588 | ret = userfunc(sess, rx, &userinfo, text_encoding, text, inforeq->infotype); | |
589 | ||
590 | free(text_encoding); | |
591 | free(text); | |
592 | ||
593 | aim_freetlvchain(&tlvlist); | |
594 | ||
595 | if (origsnac) | |
596 | free(origsnac->data); | |
597 | free(origsnac); | |
598 | ||
599 | return ret; | |
00ef5271 | 600 | } |
601 | ||
d410cf58 | 602 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
00ef5271 | 603 | { |
604 | ||
d410cf58 | 605 | if (snac->subtype == 0x0003) |
606 | return rights(sess, mod, rx, snac, bs); | |
607 | else if (snac->subtype == 0x0006) | |
608 | return userinfo(sess, mod, rx, snac, bs); | |
00ef5271 | 609 | |
d410cf58 | 610 | return 0; |
00ef5271 | 611 | } |
612 | ||
d410cf58 | 613 | faim_internal int locate_modfirst(aim_session_t *sess, aim_module_t *mod) |
00ef5271 | 614 | { |
615 | ||
d410cf58 | 616 | mod->family = 0x0002; |
617 | mod->version = 0x0000; | |
618 | mod->flags = 0; | |
619 | strncpy(mod->name, "locate", sizeof(mod->name)); | |
620 | mod->snachandler = snachandler; | |
00ef5271 | 621 | |
d410cf58 | 622 | return 0; |
00ef5271 | 623 | } |