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