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