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