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