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