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