rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / libpurple / protocols / oscar / family_locate.c
blob7e9a93742e4a8a1397aaeb8f8bb092c3637082bf
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Family 0x0002 - Locate.
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.
29 #include "oscar.h"
31 /* Define to log unknown TLVs */
32 /* #define LOG_UNKNOWN_TLV */
35 * Capability blocks.
37 * These are CLSIDs. They should actually be of the form:
39 * {0x0946134b, 0x4c7f, 0x11d1,
40 * {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
42 * But, eh.
44 static const struct {
45 guint64 flag;
46 guint8 data[16];
47 } aim_caps[] = {
50 * These are in ascending numerical order.
53 /* Client understands short caps, a UUID of the form
54 * 0946XXYY-4C7F-11D1-8222-444553540000 where XXYY is the short cap. */
55 {OSCAR_CAPABILITY_SHORTCAPS,
56 {0x09, 0x46, 0x00, 0x00, 0x4c, 0x7f, 0x11, 0xd1,
57 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
59 {OSCAR_CAPABILITY_SECUREIM,
60 {0x09, 0x46, 0x00, 0x01, 0x4c, 0x7f, 0x11, 0xd1,
61 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
63 /* OSCAR_CAPABILITY_XHTML_IM */
64 {OSCAR_CAPABILITY_GENERICUNKNOWN,
65 {0x09, 0x46, 0x00, 0x02, 0x4c, 0x7f, 0x11, 0xd1,
66 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
68 {OSCAR_CAPABILITY_VIDEO,
69 {0x09, 0x46, 0x01, 0x00, 0x4c, 0x7f, 0x11, 0xd1,
70 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
72 /* "Live Video" (SIP/RTC Video) support in Windows AIM 5.5.3501 and newer */
73 {OSCAR_CAPABILITY_LIVEVIDEO,
74 {0x09, 0x46, 0x01, 0x01, 0x4c, 0x7f, 0x11, 0xd1,
75 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
77 /* "Camera" support in Windows AIM 5.5.3501 and newer */
78 {OSCAR_CAPABILITY_CAMERA,
79 {0x09, 0x46, 0x01, 0x02, 0x4c, 0x7f, 0x11, 0xd1,
80 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
82 /* "Microphone" support in Windows AIM 5.5.3501 and newer */
83 /* OSCAR_CAPABILITY_MICROPHONE */
84 {OSCAR_CAPABILITY_GENERICUNKNOWN,
85 {0x09, 0x46, 0x01, 0x03, 0x4c, 0x7f, 0x11, 0xd1,
86 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
88 /* Supports RTC Audio */
89 /* OSCAR_CAPABILITY_RTCAUDIO */
90 {OSCAR_CAPABILITY_GENERICUNKNOWN,
91 {0x09, 0x46, 0x01, 0x04, 0x4c, 0x7f, 0x11, 0xd1,
92 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
94 /* In iChatAV (version numbers...?) */
95 {OSCAR_CAPABILITY_ICHATAV,
96 {0x09, 0x46, 0x01, 0x05, 0x4c, 0x7f, 0x11, 0xd1,
97 0x82, 0x22, 0x44, 0x45, 0x45, 0x53, 0x54, 0x00}},
99 /* Supports "new status message features" (Who advertises this one?) */
100 /* OSCAR_CAPABILITY_HOST_STATUS_TEXT_AWARE */
101 {OSCAR_CAPABILITY_GENERICUNKNOWN,
102 {0x09, 0x46, 0x01, 0x0a, 0x4c, 0x7f, 0x11, 0xd1,
103 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
105 /* Supports "see as I type" (Who advertises this one?) */
106 /* OSCAR_CAPABILITY_SEE_AS_I_TYPE */
107 {OSCAR_CAPABILITY_GENERICUNKNOWN,
108 {0x09, 0x46, 0x01, 0x0b, 0x4c, 0x7f, 0x11, 0xd1,
109 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
111 /* Client only asserts caps for services in which it is participating */
112 /* OSCAR_CAPABILITY_SMARTCAPS */
113 {OSCAR_CAPABILITY_GENERICUNKNOWN,
114 {0x09, 0x46, 0x01, 0xff, 0x4c, 0x7f, 0x11, 0xd1,
115 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
117 {OSCAR_CAPABILITY_HIPTOP,
118 {0x09, 0x46, 0x13, 0x23, 0x4c, 0x7f, 0x11, 0xd1,
119 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
121 {OSCAR_CAPABILITY_TALK,
122 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
123 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
125 {OSCAR_CAPABILITY_SENDFILE,
126 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
127 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
129 {OSCAR_CAPABILITY_ICQ_DIRECT,
130 {0x09, 0x46, 0x13, 0x44, 0x4c, 0x7f, 0x11, 0xd1,
131 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
133 {OSCAR_CAPABILITY_DIRECTIM,
134 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
135 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
137 {OSCAR_CAPABILITY_BUDDYICON,
138 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
139 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
141 {OSCAR_CAPABILITY_ADDINS,
142 {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
143 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
145 {OSCAR_CAPABILITY_GETFILE,
146 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
147 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
149 {OSCAR_CAPABILITY_ICQSERVERRELAY,
150 {0x09, 0x46, 0x13, 0x49, 0x4c, 0x7f, 0x11, 0xd1,
151 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
154 * Indeed, there are two of these. The former appears to be correct,
155 * but in some versions of winaim, the second one is set. Either they
156 * forgot to fix endianness, or they made a typo. It really doesn't
157 * matter which.
159 {OSCAR_CAPABILITY_GAMES,
160 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
161 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
162 {OSCAR_CAPABILITY_GAMES2,
163 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
164 0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
166 /* New format of caps (xtraz icons) */
167 {OSCAR_CAPABILITY_NEWCAPS,
168 {0x09, 0x46, 0x00, 0x00, 0x4c, 0x7f, 0x11, 0xd1,
169 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
171 /* Support xtraz statuses */
172 {OSCAR_CAPABILITY_XTRAZ,
173 {0x1a, 0x09, 0x3c, 0x6c, 0xd7, 0xFD, 0x4e, 0xc5,
174 0x9d, 0x51, 0xa6, 0x47, 0x4e, 0x34, 0xf5, 0xa0}},
176 {OSCAR_CAPABILITY_SENDBUDDYLIST,
177 {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1,
178 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
181 * Setting this lets AIM users receive messages from ICQ users, and ICQ
182 * users receive messages from AIM users. It also lets ICQ users show
183 * up in buddy lists for AIM users, and AIM users show up in buddy lists
184 * for ICQ users. And ICQ privacy/invisibility acts like AIM privacy,
185 * in that if you add a user to your deny list, you will not be able to
186 * see them as online (previous you could still see them, but they
187 * couldn't see you.
189 {OSCAR_CAPABILITY_INTEROPERATE,
190 {0x09, 0x46, 0x13, 0x4d, 0x4c, 0x7f, 0x11, 0xd1,
191 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
193 {OSCAR_CAPABILITY_UNICODE,
194 {0x09, 0x46, 0x13, 0x4e, 0x4c, 0x7f, 0x11, 0xd1,
195 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
197 {OSCAR_CAPABILITY_GENERICUNKNOWN,
198 {0x09, 0x46, 0xf0, 0x03, 0x4c, 0x7f, 0x11, 0xd1,
199 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
201 {OSCAR_CAPABILITY_ICHAT_SCREENSHARE,
202 {0x09, 0x46, 0xf0, 0x04, 0x4c, 0x7f, 0x11, 0xd1,
203 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
205 {OSCAR_CAPABILITY_GENERICUNKNOWN,
206 {0x09, 0x46, 0xf0, 0x05, 0x4c, 0x7f, 0x11, 0xd1,
207 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
209 {OSCAR_CAPABILITY_UNICODEOLD,
210 {0x2e, 0x7a, 0x64, 0x75, 0xfa, 0xdf, 0x4d, 0xc8,
211 0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}},
213 {OSCAR_CAPABILITY_TYPING,
214 {0x56, 0x3f, 0xc8, 0x09, 0x0b, 0x6f, 0x41, 0xbd,
215 0x9f, 0x79, 0x42, 0x26, 0x09, 0xdf, 0xa2, 0xf3}},
218 * Chat is oddball.
220 {OSCAR_CAPABILITY_CHAT,
221 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
222 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
224 /* This is added by the servers and it only shows up for ourselves... */
225 {OSCAR_CAPABILITY_GENERICUNKNOWN,
226 {0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34,
227 0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x09}},
229 {OSCAR_CAPABILITY_ICQRTF,
230 {0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34,
231 0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}},
233 {OSCAR_CAPABILITY_APINFO,
234 {0xaa, 0x4a, 0x32, 0xb5, 0xf8, 0x84, 0x48, 0xc6,
235 0xa3, 0xd7, 0x8c, 0x50, 0x97, 0x19, 0xfd, 0x5b}},
237 {OSCAR_CAPABILITY_TRILLIANCRYPT,
238 {0xf2, 0xe7, 0xc7, 0xf4, 0xfe, 0xad, 0x4d, 0xfb,
239 0xb2, 0x35, 0x36, 0x79, 0x8b, 0xdf, 0x00, 0x00}},
241 {OSCAR_CAPABILITY_EMPTY,
242 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
245 {OSCAR_CAPABILITY_HTML_MSGS,
246 {0x01, 0x38, 0xca, 0x7b, 0x76, 0x9a, 0x49, 0x15,
247 0x88, 0xf2, 0x13, 0xfc, 0x00, 0x97, 0x9e, 0xa8}},
249 {OSCAR_CAPABILITY_LAST,
250 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
254 /* Keep this array synchronized with icq_purple_moods. */
255 static const struct {
256 const char *mood;
257 guint8 data[16];
258 } icq_custom_icons[] = {
260 {"thinking",
261 {0x3f, 0xb0, 0xbd, 0x36, 0xaf, 0x3b, 0x4a, 0x60,
262 0x9e, 0xef, 0xcf, 0x19, 0x0f, 0x6a, 0x5a, 0x7f}},
264 {"busy",
265 {0x48, 0x8e, 0x14, 0x89, 0x8a, 0xca, 0x4a, 0x08,
266 0x82, 0xaa, 0x77, 0xce, 0x7a, 0x16, 0x52, 0x08}},
268 {"shopping",
269 {0x63, 0x62, 0x73, 0x37, 0xa0, 0x3f, 0x49, 0xff,
270 0x80, 0xe5, 0xf7, 0x09, 0xcd, 0xe0, 0xa4, 0xee}},
272 /* This was in the original patch, but isn't what the official client
273 * (ICQ 6) sets when you choose its typewriter icon. */
274 {"typing",
275 {0x63, 0x4f, 0x6b, 0xd8 ,0xad, 0xd2, 0x4a, 0xa1,
276 0xaa, 0xb9, 0x11, 0x5b, 0xc2, 0x6d, 0x05, 0xa1}},
278 {"question",
279 {0x63, 0x14, 0x36, 0xff, 0x3f, 0x8a, 0x40, 0xd0,
280 0xa5, 0xcb, 0x7b, 0x66, 0xe0, 0x51, 0xb3, 0x64}},
282 {"angry",
283 {0x01, 0xd8, 0xd7, 0xee, 0xac, 0x3b, 0x49, 0x2a,
284 0xa5, 0x8d, 0xd3, 0xd8, 0x77, 0xe6, 0x6b, 0x92}},
286 {"plate",
287 {0xf8, 0xe8, 0xd7, 0xb2, 0x82, 0xc4, 0x41, 0x42,
288 0x90, 0xf8, 0x10, 0xc6, 0xce, 0x0a, 0x89, 0xa6}},
290 {"cinema",
291 {0x10, 0x7a, 0x9a, 0x18, 0x12, 0x32, 0x4d, 0xa4,
292 0xb6, 0xcd, 0x08, 0x79, 0xdb, 0x78, 0x0f, 0x09}},
294 {"sick",
295 {0x1f, 0x7a, 0x40, 0x71, 0xbf, 0x3b, 0x4e, 0x60,
296 0xbc, 0x32, 0x4c, 0x57, 0x87, 0xb0, 0x4c, 0xf1}},
298 {"typing",
299 {0x2c, 0xe0, 0xe4, 0xe5, 0x7c, 0x64, 0x43, 0x70,
300 0x9c, 0x3a, 0x7a, 0x1c, 0xe8, 0x78, 0xa7, 0xdc}},
302 {"suit",
303 {0xb7, 0x08, 0x67, 0xf5, 0x38, 0x25, 0x43, 0x27,
304 0xa1, 0xff, 0xcf, 0x4c, 0xc1, 0x93, 0x97, 0x97}},
306 {"bathing",
307 {0x5a, 0x58, 0x1e, 0xa1, 0xe5, 0x80, 0x43, 0x0c,
308 0xa0, 0x6f, 0x61, 0x22, 0x98, 0xb7, 0xe4, 0xc7}},
310 {"tv",
311 {0x80, 0x53, 0x7d, 0xe2, 0xa4, 0x67, 0x4a, 0x76,
312 0xb3, 0x54, 0x6d, 0xfd, 0x07, 0x5f, 0x5e, 0xc6}},
314 {"excited",
315 {0x6f, 0x49, 0x30, 0x98, 0x4f, 0x7c, 0x4a, 0xff,
316 0xa2, 0x76, 0x34, 0xa0, 0x3b, 0xce, 0xae, 0xa7}},
318 {"sleeping",
319 {0x78, 0x5e, 0x8c, 0x48, 0x40, 0xd3, 0x4c, 0x65,
320 0x88, 0x6f, 0x04, 0xcf, 0x3f, 0x3f, 0x43, 0xdf}},
322 {"hiptop",
323 {0x10, 0x11, 0x17, 0xc9, 0xa3, 0xb0, 0x40, 0xf9,
324 0x81, 0xac, 0x49, 0xe1, 0x59, 0xfb, 0xd5, 0xd4}},
326 {"in_love",
327 {0xdd, 0xcf, 0x0e, 0xa9, 0x71, 0x95, 0x40, 0x48,
328 0xa9, 0xc6, 0x41, 0x32, 0x06, 0xd6, 0xf2, 0x80}},
330 {"sleepy",
331 {0x83, 0xc9, 0xb7, 0x8e, 0x77, 0xe7, 0x43, 0x78,
332 0xb2, 0xc5, 0xfb, 0x6c, 0xfc, 0xc3, 0x5b, 0xec}},
334 {"meeting",
335 {0xf1, 0x8a, 0xb5, 0x2e, 0xdc, 0x57, 0x49, 0x1d,
336 0x99, 0xdc, 0x64, 0x44, 0x50, 0x24, 0x57, 0xaf}},
338 {"phone",
339 {0x12, 0x92, 0xe5, 0x50, 0x1b, 0x64, 0x4f, 0x66,
340 0xb2, 0x06, 0xb2, 0x9a, 0xf3, 0x78, 0xe4, 0x8d}},
342 {"surfing",
343 {0xa6, 0xed, 0x55, 0x7e, 0x6b, 0xf7, 0x44, 0xd4,
344 0xa5, 0xd4, 0xd2, 0xe7, 0xd9, 0x5c, 0xe8, 0x1f}},
346 {"mobile",
347 {0x16, 0x0c, 0x60, 0xbb, 0xdd, 0x44, 0x43, 0xf3,
348 0x91, 0x40, 0x05, 0x0f, 0x00, 0xe6, 0xc0, 0x09}},
350 {"search",
351 {0xd4, 0xe2, 0xb0, 0xba, 0x33, 0x4e, 0x4f, 0xa5,
352 0x98, 0xd0, 0x11, 0x7d, 0xbf, 0x4d, 0x3c, 0xc8}},
354 {"party",
355 {0xe6, 0x01, 0xe4, 0x1c, 0x33, 0x73, 0x4b, 0xd1,
356 0xbc, 0x06, 0x81, 0x1d, 0x6c, 0x32, 0x3d, 0x81}},
358 {"coffee",
359 {0x1b, 0x78, 0xae, 0x31, 0xfa, 0x0b, 0x4d, 0x38,
360 0x93, 0xd1, 0x99, 0x7e, 0xee, 0xaf, 0xb2, 0x18}},
362 {"console",
363 {0xd4, 0xa6, 0x11, 0xd0, 0x8f, 0x01, 0x4e, 0xc0,
364 0x92, 0x23, 0xc5, 0xb6, 0xbe, 0xc6, 0xcc, 0xf0}},
366 {"internet",
367 {0x12, 0xd0, 0x7e, 0x3e, 0xf8, 0x85, 0x48, 0x9e,
368 0x8e, 0x97, 0xa7, 0x2a, 0x65, 0x51, 0xe5, 0x8d}},
370 {"cigarette",
371 {0x64, 0x43, 0xc6, 0xaf, 0x22, 0x60, 0x45, 0x17,
372 0xb5, 0x8c, 0xd7, 0xdf, 0x8e, 0x29, 0x03, 0x52}},
374 {"writing",
375 {0x00, 0x72, 0xd9, 0x08, 0x4a, 0xd1, 0x43, 0xdd,
376 0x91, 0x99, 0x6f, 0x02, 0x69, 0x66, 0x02, 0x6f}},
378 {"beer",
379 {0x8c, 0x50, 0xdb, 0xae, 0x81, 0xed, 0x47, 0x86,
380 0xac, 0xca, 0x16, 0xcc, 0x32, 0x13, 0xc7, 0xb7}},
382 {"music",
383 {0x61, 0xbe, 0xe0, 0xdd, 0x8b, 0xdd, 0x47, 0x5d,
384 0x8d, 0xee, 0x5f, 0x4b, 0xaa, 0xcf, 0x19, 0xa7}},
386 {"studying",
387 {0x60, 0x9d, 0x52, 0xf8, 0xa2, 0x9a, 0x49, 0xa6,
388 0xb2, 0xa0, 0x25, 0x24, 0xc5, 0xe9, 0xd2, 0x60}},
390 {"working",
391 {0xba, 0x74, 0xdb, 0x3e, 0x9e, 0x24, 0x43, 0x4b,
392 0x87, 0xb6, 0x2f, 0x6b, 0x8d, 0xfe, 0xe5, 0x0f}},
394 {"restroom",
395 {0x16, 0xf5, 0xb7, 0x6f, 0xa9, 0xd2, 0x40, 0x35,
396 0x8c, 0xc5, 0xc0, 0x84, 0x70, 0x3c, 0x98, 0xfa}},
398 {NULL,
399 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
403 /* Keep this array synchronized with icq_custom_icons. */
404 static PurpleMood icq_purple_moods[] = {
405 {"thinking", N_("Thinking"), NULL},
406 {"busy", N_("Busy"), NULL},
407 {"shopping", N_("Shopping"), NULL},
408 /* This was in the original patch, but isn't what the official client
409 * (ICQ 6) sets when you choose its typewriter icon. */
410 {"typing", NULL, NULL},
411 {"question", N_("Questioning"), NULL},
412 {"angry", N_("Angry"), NULL},
413 {"plate", N_("Eating"), NULL},
414 {"cinema", N_("Watching a movie"), NULL},
415 {"sick", N_("Sick"), NULL},
416 {"typing", N_("Typing"), NULL},
417 {"suit", N_("At the office"), NULL},
418 {"bathing", N_("Taking a bath"), NULL},
419 {"tv", N_("Watching TV"), NULL},
420 {"excited", N_("Having fun"), NULL},
421 {"sleeping", N_("Sleeping"), NULL},
422 {"hiptop", N_("Using a PDA"), NULL},
423 {"in_love", N_("In love"), NULL},
424 /* Sleepy / Tired */
425 {"sleepy", N_("Sleepy"), NULL},
426 {"meeting", N_("Meeting friends"), NULL},
427 {"phone", N_("On the phone"), NULL},
428 {"surfing", N_("Surfing"), NULL},
429 /* "I am mobile." / "John is mobile." */
430 {"mobile", N_("Mobile"), NULL},
431 {"search", N_("Searching the web"), NULL},
432 {"party", N_("At a party"), NULL},
433 {"coffee", N_("Having Coffee"), NULL},
434 /* Playing video games */
435 {"console", N_("Gaming"), NULL},
436 {"internet", N_("Browsing the web"), NULL},
437 {"cigarette", N_("Smoking"), NULL},
438 {"writing", N_("Writing"), NULL},
439 /* Drinking [Alcohol] */
440 {"beer", N_("Drinking"), NULL},
441 {"music", N_("Listening to music"), NULL},
442 {"studying", N_("Studying"), NULL},
443 {"working", N_("Working"), NULL},
444 {"restroom", N_("In the restroom"), NULL},
445 /* Mark the last record. */
446 {NULL, NULL, NULL},
451 * Add the userinfo to our linked list. If we already have userinfo
452 * for this buddy, then just overwrite parts of the old data.
454 * @param userinfo Contains the new information for the buddy.
456 static void
457 aim_locate_adduserinfo(OscarData *od, aim_userinfo_t *userinfo)
459 aim_userinfo_t *cur;
461 cur = aim_locate_finduserinfo(od, userinfo->bn);
463 if (cur == NULL) {
464 cur = (aim_userinfo_t *)g_new0(aim_userinfo_t, 1);
465 cur->bn = g_strdup(userinfo->bn);
466 cur->next = od->locate.userinfo;
467 od->locate.userinfo = cur;
470 cur->warnlevel = userinfo->warnlevel;
471 cur->idletime = userinfo->idletime;
472 if (userinfo->flags != 0)
473 cur->flags = userinfo->flags;
474 if (userinfo->createtime != 0)
475 cur->createtime = userinfo->createtime;
476 if (userinfo->membersince != 0)
477 cur->membersince = userinfo->membersince;
478 if (userinfo->onlinesince != 0)
479 cur->onlinesince = userinfo->onlinesince;
480 if (userinfo->sessionlen != 0)
481 cur->sessionlen = userinfo->sessionlen;
482 if (userinfo->capabilities != 0)
483 cur->capabilities = userinfo->capabilities;
485 cur->present |= userinfo->present;
487 if (userinfo->iconcsumlen > 0) {
488 g_free(cur->iconcsum);
489 cur->iconcsum = (guint8 *)g_malloc(userinfo->iconcsumlen);
490 memcpy(cur->iconcsum, userinfo->iconcsum, userinfo->iconcsumlen);
491 cur->iconcsumlen = userinfo->iconcsumlen;
494 if (userinfo->info != NULL) {
495 g_free(cur->info);
496 g_free(cur->info_encoding);
497 if (userinfo->info_len > 0) {
498 cur->info = (char *)g_malloc(userinfo->info_len);
499 memcpy(cur->info, userinfo->info, userinfo->info_len);
500 } else
501 cur->info = NULL;
502 cur->info_encoding = g_strdup(userinfo->info_encoding);
503 cur->info_len = userinfo->info_len;
506 if (userinfo->status != NULL) {
507 g_free(cur->status);
508 g_free(cur->status_encoding);
509 if (userinfo->status_len > 0) {
510 cur->status = (char *)g_malloc(userinfo->status_len);
511 memcpy(cur->status, userinfo->status, userinfo->status_len);
512 } else
513 cur->status = NULL;
514 if (userinfo->status_encoding != NULL)
515 cur->status_encoding = g_strdup(userinfo->status_encoding);
516 else
517 cur->status_encoding = NULL;
518 cur->status_len = userinfo->status_len;
521 if (userinfo->itmsurl != NULL) {
522 g_free(cur->itmsurl);
523 g_free(cur->itmsurl_encoding);
524 if (userinfo->itmsurl_len > 0) {
525 cur->itmsurl = (char *)g_malloc(userinfo->itmsurl_len);
526 memcpy(cur->itmsurl, userinfo->itmsurl, userinfo->itmsurl_len);
527 } else
528 cur->itmsurl = NULL;
529 if (userinfo->itmsurl_encoding != NULL)
530 cur->itmsurl_encoding = g_strdup(userinfo->itmsurl_encoding);
531 else
532 cur->itmsurl_encoding = NULL;
533 cur->itmsurl_len = userinfo->itmsurl_len;
536 if (userinfo->away != NULL) {
537 g_free(cur->away);
538 g_free(cur->away_encoding);
539 if (userinfo->away_len > 0) {
540 cur->away = (char *)g_malloc(userinfo->away_len);
541 memcpy(cur->away, userinfo->away, userinfo->away_len);
542 } else
543 cur->away = NULL;
544 cur->away_encoding = g_strdup(userinfo->away_encoding);
545 cur->away_len = userinfo->away_len;
547 } else {
549 * We don't have an away message specified in this user_info
550 * block, so clear any cached away message now.
552 g_free(cur->away);
553 cur->away = NULL;
554 g_free(cur->away_encoding);
555 cur->away_encoding = NULL;
556 cur->away_len = 0;
560 aim_userinfo_t *aim_locate_finduserinfo(OscarData *od, const char *bn) {
561 aim_userinfo_t *cur = NULL;
563 if (bn == NULL)
564 return NULL;
566 cur = od->locate.userinfo;
568 while (cur != NULL) {
569 if (oscar_util_name_compare(cur->bn, bn) == 0)
570 return cur;
571 cur = cur->next;
574 return NULL;
577 guint64
578 aim_locate_getcaps(OscarData *od, ByteStream *bs, int len)
580 guint64 flags = 0;
581 int offset;
583 for (offset = 0; byte_stream_bytes_left(bs) && (offset < len); offset += 0x10) {
584 guint8 *cap;
585 int i, identified;
587 cap = byte_stream_getraw(bs, 0x10);
589 for (i = 0, identified = 0; !(aim_caps[i].flag & OSCAR_CAPABILITY_LAST); i++) {
590 if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) {
591 flags |= aim_caps[i].flag;
592 identified++;
593 break; /* should only match once... */
597 if (!identified)
598 purple_debug_misc("oscar", "unknown capability: {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
599 cap[0], cap[1], cap[2], cap[3],
600 cap[4], cap[5],
601 cap[6], cap[7],
602 cap[8], cap[9],
603 cap[10], cap[11], cap[12], cap[13],
604 cap[14], cap[15]);
605 g_free(cap);
608 return flags;
611 static const char *
612 aim_receive_custom_icon(OscarData *od, ByteStream *bs, int len)
614 int offset;
615 const char *result = NULL;
617 for (offset = 0; byte_stream_bytes_left(bs) && (offset < len); offset += 0x10) {
618 /* check wheather this capability is a custom user icon */
619 guint8 *cap;
620 int i;
622 cap = byte_stream_getraw(bs, 0x10);
624 for (i = 0; icq_custom_icons[i].mood; i++) {
625 if (memcmp(&icq_custom_icons[i].data, cap, 0x10) == 0) {
626 purple_debug_misc("oscar", "Custom status icon: %s\n", icq_purple_moods[i].description);
627 result = icq_custom_icons[i].mood;
628 break; /* should only match once... */
631 g_free(cap);
634 return result;
637 guint64
638 aim_locate_getcaps_short(OscarData *od, ByteStream *bs, int len)
640 guint64 flags = 0;
641 int offset;
643 for (offset = 0; byte_stream_bytes_left(bs) && (offset < len); offset += 0x02) {
644 guint8 *cap;
645 int i, identified;
647 cap = byte_stream_getraw(bs, 0x02);
649 for (i = 0, identified = 0; !(aim_caps[i].flag & OSCAR_CAPABILITY_LAST); i++) {
650 if (memcmp(&aim_caps[i].data[2], cap, 0x02) == 0) {
651 flags |= aim_caps[i].flag;
652 identified++;
653 break; /* should only match once... */
657 if (!identified)
658 purple_debug_misc("oscar", "unknown short capability: {%02x%02x}\n", cap[0], cap[1]);
660 g_free(cap);
663 return flags;
667 byte_stream_putcaps(ByteStream *bs, guint64 caps)
669 int i;
671 if (!bs)
672 return -EINVAL;
674 for (i = 0; byte_stream_bytes_left(bs); i++) {
675 if (aim_caps[i].flag == OSCAR_CAPABILITY_LAST)
676 break;
678 if (caps & aim_caps[i].flag)
679 byte_stream_putraw(bs, aim_caps[i].data, 0x10);
681 return 0;
684 #ifdef LOG_UNKNOWN_TLV
685 static void
686 dumptlv(OscarData *od, guint16 type, ByteStream *bs, guint8 len)
688 int i;
690 if (!od || !bs || !len)
691 return;
693 purple_debug_misc("oscar", "userinfo: type =0x%04x\n", type);
694 purple_debug_misc("oscar", "userinfo: length=0x%04x\n", len);
695 purple_debug_misc("oscar", "userinfo: value:\n");
697 for (i = 0; i < len; i++) {
698 if ((i % 8) == 0)
699 purple_debug_misc("oscar", "\nuserinfo: ");
700 purple_debug_misc("oscar", "0x%2x ", byte_stream_get8(bs));
703 purple_debug_misc("oscar", "\n");
705 return;
707 #endif
709 void
710 aim_info_free(aim_userinfo_t *info)
712 g_free(info->bn);
713 g_free(info->iconcsum);
714 g_free(info->info);
715 g_free(info->info_encoding);
716 g_free(info->status);
717 g_free(info->status_encoding);
718 g_free(info->itmsurl);
719 g_free(info->itmsurl_encoding);
720 g_free(info->away);
721 g_free(info->away_encoding);
724 static const struct {
725 char *icqmood;
726 const char *mood;
727 } icqmoods[] = {
728 {"icqmood0", "shopping"},
729 {"icqmood1", "bathing"},
730 {"icqmood2", "sleepy"},
731 {"icqmood3", "party"},
732 {"icqmood4", "beer"},
733 {"icqmood5", "thinking"},
734 {"icqmood6", "plate"},
735 {"icqmood7", "tv"},
736 {"icqmood8", "meeting"},
737 {"icqmood9", "coffee"},
738 {"icqmood10", "music"},
739 {"icqmood11", "suit"},
740 {"icqmood12", "cinema"},
741 {"icqmood13", "smile-big"},
742 {"icqmood14", "phone"},
743 {"icqmood15", "console"},
744 {"icqmood16", "studying"},
745 {"icqmood17", "sick"},
746 {"icqmood18", "sleeping"},
747 {"icqmood19", "surfing"},
748 {"icqmood20", "internet"},
749 {"icqmood21", "working"},
750 {"icqmood22", "typing"},
751 {"icqmood23", "angry"},
752 {NULL, 0}
757 * AIM is fairly regular about providing user info. This is a generic
758 * routine to extract it in its standard form.
761 aim_info_extract(OscarData *od, ByteStream *bs, aim_userinfo_t *outinfo)
763 int curtlv, tlvcnt;
764 guint8 bnlen;
766 if (!bs || !outinfo)
767 return -EINVAL;
769 /* Clear out old data first */
770 memset(outinfo, 0x00, sizeof(aim_userinfo_t));
773 * Username. Stored as an unterminated string prepended with a
774 * byte containing its length.
776 bnlen = byte_stream_get8(bs);
777 outinfo->bn = byte_stream_getstr(bs, bnlen);
780 * Warning Level. Stored as an unsigned short.
782 outinfo->warnlevel = byte_stream_get16(bs);
785 * TLV Count. Unsigned short representing the number of
786 * Type-Length-Value triples that follow.
788 tlvcnt = byte_stream_get16(bs);
791 * Parse out the Type-Length-Value triples as they're found.
793 for (curtlv = 0; curtlv < tlvcnt; curtlv++) {
794 guint16 type, length;
795 int endpos;
796 int curpos;
798 type = byte_stream_get16(bs);
799 length = byte_stream_get16(bs);
800 curpos = byte_stream_curpos(bs);
801 endpos = curpos + MIN(length, byte_stream_bytes_left(bs));
803 if (type == 0x0001) {
805 * User flags
807 * Specified as any of the following ORed together:
808 * 0x0001 Unconfirmed account
809 * 0x0002 Unknown bit 2
810 * 0x0004 AOL Main Service user
811 * 0x0008 Unknown bit 4
812 * 0x0010 Free (AIM) user
813 * 0x0020 Away
814 * 0x0040 ICQ user (AIM bit also set)
815 * 0x0080 Mobile device
816 * 0x0400 Bot (like ActiveBuddy)
818 outinfo->flags = byte_stream_get16(bs);
819 outinfo->present |= AIM_USERINFO_PRESENT_FLAGS;
821 } else if (type == 0x0002) {
823 * Account creation time
825 * The time/date that the user originally registered for
826 * the service, stored in time_t format.
828 * I'm not sure how this differs from type 5 ("member
829 * since").
831 * Note: This is the field formerly known as "member
832 * since". All these years and I finally found out
833 * that I got the name wrong.
835 outinfo->createtime = byte_stream_get32(bs);
836 outinfo->present |= AIM_USERINFO_PRESENT_CREATETIME;
838 } else if (type == 0x0003) {
840 * On-Since date
842 * The time/date that the user started their current
843 * session, stored in time_t format.
845 outinfo->onlinesince = byte_stream_get32(bs);
846 outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE;
848 } else if (type == 0x0004) {
850 * Idle time
852 * Number of minutes since the user actively used the
853 * service.
855 * Note that the client tells the server when to start
856 * counting idle times, so this may or may not be
857 * related to reality.
859 outinfo->idletime = byte_stream_get16(bs);
860 outinfo->present |= AIM_USERINFO_PRESENT_IDLE;
862 } else if (type == 0x0005) {
864 * Member since date
866 * The time/date that the user originally registered for
867 * the service, stored in time_t format.
869 * This is sometimes sent instead of type 2 ("account
870 * creation time"), particularly in the self-info.
871 * And particularly for ICQ?
873 outinfo->membersince = byte_stream_get32(bs);
874 outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE;
876 } else if (type == 0x0006) {
878 * ICQ Online Status
880 * ICQ's Away/DND/etc "enriched" status. Some decoding
881 * of values done by Scott <darkagl@pcnet.com>
883 byte_stream_get16(bs);
884 outinfo->icqinfo.status = byte_stream_get16(bs);
885 outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS;
887 } else if (type == 0x0008) {
889 * Client type, or some such.
892 } else if (type == 0x000a) {
894 * ICQ User IP Address
896 * Ahh, the joy of ICQ security.
898 outinfo->icqinfo.ipaddr = byte_stream_get32(bs);
899 outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR;
901 } else if (type == 0x000c) {
903 * Random crap containing the IP address,
904 * apparently a port number, and some Other Stuff.
906 * Format is:
907 * 4 bytes - Our IP address, 0xc0 a8 01 2b for 192.168.1.43
909 byte_stream_getrawbuf(bs, outinfo->icqinfo.crap, 0x25);
910 outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA;
912 } else if (type == 0x000d) {
913 PurpleAccount *account = purple_connection_get_account(od->gc);
914 const char *mood;
917 * OSCAR Capability information
919 outinfo->capabilities |= aim_locate_getcaps(od, bs, length);
920 outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;
921 byte_stream_setpos(bs, curpos);
923 mood = aim_receive_custom_icon(od, bs, length);
924 if (mood)
925 purple_protocol_got_user_status(account, outinfo->bn, "mood",
926 PURPLE_MOOD_NAME, mood,
927 NULL);
928 else
929 purple_protocol_got_user_status_deactive(account, outinfo->bn, "mood");
931 } else if (type == 0x000e) {
933 * AOL capability information
936 } else if ((type == 0x000f) || (type == 0x0010)) {
938 * Type = 0x000f: Session Length. (AIM)
939 * Type = 0x0010: Session Length. (AOL)
941 * The duration, in seconds, of the user's current
942 * session.
944 * Which TLV type this comes in depends on the
945 * service the user is using (AIM or AOL).
947 outinfo->sessionlen = byte_stream_get32(bs);
948 outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN;
950 } else if (type == 0x0014) {
952 * My instance number.
954 byte_stream_get8(bs);
956 } else if (type == 0x0019) {
958 * OSCAR short capability information. A shortened
959 * form of the normal capabilities.
961 outinfo->capabilities |= aim_locate_getcaps_short(od, bs, length);
962 outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;
964 } else if (type == 0x001a) {
966 * Type = 0x001a
968 * AOL short capability information. A shortened
969 * form of the normal capabilities.
972 } else if (type == 0x001b) {
974 * Encryption certification MD5 checksum.
977 } else if (type == 0x001d) {
979 * Buddy icon information and status/available messages.
981 * This almost seems like the AIM protocol guys gave
982 * the iChat guys a Type, and the iChat guys tried to
983 * cram as much cool shit into it as possible. Then
984 * the Windows AIM guys were like, "hey, that's
985 * pretty neat, let's copy those prawns."
987 * In that spirit, this can contain a custom message,
988 * kind of like an away message, but you're not away
989 * (it's called an "available" message). Or it can
990 * contain information about the buddy icon the user
991 * has stored on the server.
993 guint16 type2;
994 guint8 number2, length2;
995 int endpos2;
998 * Continue looping as long as we're able to read type2,
999 * number2, and length2.
1001 while (byte_stream_curpos(bs) + 4 <= endpos) {
1002 type2 = byte_stream_get16(bs);
1003 number2 = byte_stream_get8(bs);
1004 length2 = byte_stream_get8(bs);
1006 endpos2 = byte_stream_curpos(bs) + MIN(length2, byte_stream_bytes_left(bs));
1008 switch (type2) {
1009 case 0x0000: { /* This is an official buddy icon? */
1010 /* This is always 5 bytes of "0x02 01 d2 04 72"? */
1011 } break;
1013 case 0x0001: { /* A buddy icon checksum */
1014 if ((length2 > 0) && ((number2 == 0x00) || (number2 == 0x01))) {
1015 g_free(outinfo->iconcsum);
1016 outinfo->iconcsumtype = number2;
1017 outinfo->iconcsum = byte_stream_getraw(bs, length2);
1018 outinfo->iconcsumlen = length2;
1020 } break;
1022 case 0x0002: { /* A status/available message */
1023 g_free(outinfo->status);
1024 g_free(outinfo->status_encoding);
1025 if (length2 >= 4) {
1026 outinfo->status_len = byte_stream_get16(bs);
1027 outinfo->status = byte_stream_getstr(bs, outinfo->status_len);
1028 if (byte_stream_get16(bs) == 0x0001) { /* We have an encoding */
1029 byte_stream_get16(bs);
1030 outinfo->status_encoding = byte_stream_getstr(bs, byte_stream_get16(bs));
1031 } else {
1032 /* No explicit encoding, client should use UTF-8 */
1033 outinfo->status_encoding = NULL;
1035 } else {
1036 byte_stream_advance(bs, length2);
1037 outinfo->status_len = 0;
1038 outinfo->status = g_strdup("");
1039 outinfo->status_encoding = NULL;
1041 } break;
1043 case 0x0009: { /* An iTunes Music Store link */
1044 g_free(outinfo->itmsurl);
1045 g_free(outinfo->itmsurl_encoding);
1046 if (length2 >= 4) {
1047 outinfo->itmsurl_len = byte_stream_get16(bs);
1048 outinfo->itmsurl = byte_stream_getstr(bs, outinfo->itmsurl_len);
1049 if (byte_stream_get16(bs) == 0x0001) {
1050 /* We have an encoding */
1051 byte_stream_get16(bs);
1052 outinfo->itmsurl_encoding = byte_stream_getstr(bs, byte_stream_get16(bs));
1053 } else {
1054 /* No explicit encoding, client should use UTF-8 */
1055 outinfo->itmsurl_encoding = NULL;
1057 } else {
1058 byte_stream_advance(bs, length2);
1059 outinfo->itmsurl_len = 0;
1060 outinfo->itmsurl = g_strdup("");
1061 outinfo->itmsurl_encoding = NULL;
1063 } break;
1065 case 0x000e: { /* ICQ mood */
1066 PurpleAccount *account = purple_connection_get_account(od->gc);
1067 char *icqmood;
1068 gint32 i;
1069 const char *mood = NULL;
1071 icqmood = byte_stream_getstr(bs, length2);
1073 /* icqmood = "" means X-Status
1074 * with no mood icon. */
1075 if (*icqmood) {
1076 for (i = 0; icqmoods[i].icqmood; i++) {
1077 if (purple_strequal(icqmood, icqmoods[i].icqmood)) {
1078 mood = icqmoods[i].mood;
1079 break; /* should only match once... */
1083 if (!mood)
1084 purple_debug_warning("oscar", "Unknown icqmood: %s\n", icqmood);
1086 g_free(icqmood);
1088 if (mood)
1089 purple_protocol_got_user_status(account, outinfo->bn, "mood",
1090 PURPLE_MOOD_NAME, mood,
1091 NULL);
1092 else
1093 purple_protocol_got_user_status_deactive(account, outinfo->bn, "mood");
1094 } break;
1097 /* Save ourselves. */
1098 byte_stream_setpos(bs, endpos2);
1101 } else if (type == 0x001e) {
1103 * Always four bytes, but it doesn't look like an int.
1106 } else if (type == 0x001f) {
1108 * Upper bytes of user flags. Can be any size
1110 * Seen on a buddy using DeadAIM. Data was 4 bytes:
1111 * 0x00 00 00 10
1114 } else if (type == 0x0023) {
1116 * Last Buddy Feed update time, in seconds since the epoch.
1119 } else if (type == 0x0026) {
1121 * Time that the profile was set, in seconds since the epoch.
1124 } else if (type == 0x0027) {
1126 * Time that the away message was set, in seconds since the epoch.
1129 } else if (type == 0x002a) {
1131 * Country code based on GeoIP data.
1134 } else {
1137 * Reaching here indicates that either AOL has
1138 * added yet another TLV for us to deal with,
1139 * or the parsing has gone Terribly Wrong.
1141 * Either way, inform the owner and attempt
1142 * recovery.
1145 #ifdef LOG_UNKNOWN_TLV
1146 purple_debug_misc("oscar", "userinfo: **warning: unexpected TLV:\n");
1147 purple_debug_misc("oscar", "userinfo: bn =%s\n", outinfo->bn);
1148 dumptlv(od, type, bs, length);
1149 #endif
1152 /* Save ourselves. */
1153 byte_stream_setpos(bs, endpos);
1156 aim_locate_adduserinfo(od, outinfo);
1158 return 0;
1162 * Subtype 0x0001
1164 static int
1165 error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1167 aim_snac_t *snac2;
1168 guint16 reason;
1169 char *bn;
1171 snac2 = aim_remsnac(od, snac->id);
1172 if (!snac2) {
1173 purple_debug_misc("oscar", "locate error: received response from unknown request!\n");
1174 return 0;
1177 if ((snac2->family != SNAC_FAMILY_LOCATE) && (snac2->type != 0x0015)) {
1178 purple_debug_misc("oscar", "locate error: received response from invalid request! %d\n", snac2->family);
1179 g_free(snac2->data);
1180 g_free(snac2);
1181 return 0;
1184 bn = snac2->data;
1185 if (!bn) {
1186 purple_debug_misc("oscar", "locate error: received response from request without a buddy name!\n");
1187 g_free(snac2);
1188 return 0;
1191 reason = byte_stream_get16(bs);
1193 oscar_user_info_display_error(od, reason, bn);
1195 g_free(snac2->data);
1196 g_free(snac2);
1198 return 1;
1202 * Subtype 0x0002
1204 * Request Location services rights.
1208 aim_locate_reqrights(OscarData *od)
1210 FlapConnection *conn;
1212 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))
1213 return -EINVAL;
1215 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_LOCATE, SNAC_SUBTYPE_LOCATE_REQRIGHTS);
1217 return 0;
1221 * Subtype 0x0003
1223 * Normally contains:
1224 * t(0001) - short containing max profile length (value = 1024)
1225 * t(0002) - short - unknown (value = 16) [max MIME type length?]
1226 * t(0003) - short - unknown (value = 10)
1227 * t(0004) - short - unknown (value = 2048) [ICQ only?]
1229 static int
1230 rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1232 GSList *tlvlist;
1233 aim_rxcallback_t userfunc;
1234 int ret = 0;
1235 guint16 maxsiglen = 0;
1237 tlvlist = aim_tlvlist_read(bs);
1239 if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
1240 maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1);
1242 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1243 ret = userfunc(od, conn, frame, maxsiglen);
1245 aim_tlvlist_free(tlvlist);
1247 return ret;
1251 * Subtype 0x0004
1253 * Gives BOS your profile.
1255 * profile_encoding and awaymsg_encoding MUST be set if profile or
1256 * away are set, respectively, and their value may or may not be
1257 * restricted to a few choices. I am currently aware of:
1259 * us-ascii Just that
1260 * unicode-2-0 UTF-16BE
1262 * profile_len and awaymsg_len MUST be set similarly, and they MUST
1263 * be the length of their respective strings in bytes.
1265 * To get the previous behavior of awaymsg == "" un-setting the away
1266 * message, set awaymsg non-NULL and awaymsg_len to 0 (this is the
1267 * obvious equivalent).
1271 aim_locate_setprofile(OscarData *od,
1272 const char *profile_encoding, const gchar *profile, const int profile_len,
1273 const char *awaymsg_encoding, const gchar *awaymsg, const int awaymsg_len)
1275 FlapConnection *conn;
1276 ByteStream bs;
1277 aim_snacid_t snacid;
1278 GSList *tlvlist = NULL;
1279 char *encoding;
1280 static const char defencoding[] = {"text/aolrtf; charset=\"%s\""};
1282 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))
1283 return -EINVAL;
1285 if (!profile && !awaymsg)
1286 return -EINVAL;
1288 if ((profile && profile_encoding == NULL) || (awaymsg && awaymsg_len && awaymsg_encoding == NULL)) {
1289 return -EINVAL;
1292 /* Build the packet first to get real length */
1293 if (profile) {
1294 encoding = g_strdup_printf(defencoding, profile_encoding);
1295 aim_tlvlist_add_str(&tlvlist, 0x0001, encoding);
1296 aim_tlvlist_add_raw(&tlvlist, 0x0002, profile_len, (const guchar *)profile);
1297 g_free(encoding);
1301 * So here's how this works:
1302 * - You are away when you have a non-zero-length type 4 TLV stored.
1303 * - You become unaway when you clear the TLV with a zero-length
1304 * type 4 TLV.
1305 * - If you do not send the type 4 TLV, your status does not change
1306 * (that is, if you were away, you'll remain away).
1308 if (awaymsg) {
1309 if (awaymsg_len) {
1310 encoding = g_strdup_printf(defencoding, awaymsg_encoding);
1311 aim_tlvlist_add_str(&tlvlist, 0x0003, encoding);
1312 aim_tlvlist_add_raw(&tlvlist, 0x0004, awaymsg_len, (const guchar *)awaymsg);
1313 g_free(encoding);
1314 } else
1315 aim_tlvlist_add_noval(&tlvlist, 0x0004);
1318 byte_stream_new(&bs, aim_tlvlist_size(tlvlist));
1320 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0004, 0x0000, NULL, 0);
1322 aim_tlvlist_write(&bs, &tlvlist);
1323 aim_tlvlist_free(tlvlist);
1325 flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x0004, snacid, &bs);
1327 byte_stream_destroy(&bs);
1329 return 0;
1333 * Subtype 0x0004 - Set your client's capabilities.
1336 aim_locate_setcaps(OscarData *od, guint64 caps)
1338 FlapConnection *conn;
1339 PurpleAccount *account = purple_connection_get_account(od->gc);
1340 PurplePresence *presence = purple_account_get_presence(account);
1341 PurpleStatus *status = purple_presence_get_status(presence, "mood");
1342 const char *mood = purple_status_get_attr_string(status, PURPLE_MOOD_NAME);
1343 ByteStream bs;
1344 aim_snacid_t snacid;
1345 GSList *tlvlist = NULL;
1347 if (!(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))
1348 return -EINVAL;
1350 aim_tlvlist_add_caps(&tlvlist, 0x0005, caps, mood);
1352 byte_stream_new(&bs, aim_tlvlist_size(tlvlist));
1354 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0004, 0x0000, NULL, 0);
1356 aim_tlvlist_write(&bs, &tlvlist);
1357 aim_tlvlist_free(tlvlist);
1359 flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x0004, snacid, &bs);
1361 byte_stream_destroy(&bs);
1363 return 0;
1366 /* Subtype 0x0006 */
1367 static int
1368 userinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1370 int ret = 0;
1371 aim_userinfo_t *userinfo, *userinfo2;
1372 GSList *tlvlist;
1373 aim_tlv_t *tlv = NULL;
1375 userinfo = g_new0(aim_userinfo_t, 1);
1376 aim_info_extract(od, bs, userinfo);
1377 tlvlist = aim_tlvlist_read(bs);
1379 /* Profile will be 1 and 2 */
1380 userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1);
1381 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) {
1382 userinfo->info = (char *)g_malloc(tlv->length);
1383 memcpy(userinfo->info, tlv->value, tlv->length);
1384 userinfo->info_len = tlv->length;
1387 /* Away message will be 3 and 4 */
1388 userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1);
1389 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
1390 userinfo->away = (char *)g_malloc(tlv->length);
1391 memcpy(userinfo->away, tlv->value, tlv->length);
1392 userinfo->away_len = tlv->length;
1395 /* Caps will be 5 */
1396 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1))) {
1397 ByteStream cbs;
1398 PurpleAccount *account = purple_connection_get_account(od->gc);
1399 const char *mood;
1401 byte_stream_init(&cbs, tlv->value, tlv->length);
1402 userinfo->capabilities = aim_locate_getcaps(od, &cbs, tlv->length);
1403 byte_stream_rewind(&cbs);
1404 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES;
1406 mood = aim_receive_custom_icon(od, &cbs, tlv->length);
1407 if (mood)
1408 purple_protocol_got_user_status(account, userinfo->bn, "mood",
1409 PURPLE_MOOD_NAME, mood,
1410 NULL);
1411 else
1412 purple_protocol_got_user_status_deactive(account, userinfo->bn, "mood");
1414 aim_tlvlist_free(tlvlist);
1416 aim_locate_adduserinfo(od, userinfo);
1417 userinfo2 = aim_locate_finduserinfo(od, userinfo->bn);
1418 aim_info_free(userinfo);
1419 g_free(userinfo);
1421 /* Show the info to the user */
1422 oscar_user_info_display_aim(od, userinfo2);
1424 return ret;
1428 * Subtype 0x0015 - Request the info of a user using the short method. This is
1429 * what iChat uses. It normally is VERY leniently rate limited.
1431 * @param bn The buddy name whose info you wish to request.
1432 * @param flags The bitmask which specifies the type of info you wish to request.
1433 * 0x00000001 - Info/profile.
1434 * 0x00000002 - Away message.
1435 * 0x00000004 - Capabilities.
1436 * 0x00000008 - Certification.
1437 * @return Return 0 if no errors, otherwise return the error number.
1440 aim_locate_getinfoshort(OscarData *od, const char *bn, guint32 flags)
1442 FlapConnection *conn;
1443 ByteStream bs;
1444 aim_snacid_t snacid;
1446 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !bn)
1447 return -EINVAL;
1449 byte_stream_new(&bs, 4 + 1 + strlen(bn));
1450 byte_stream_put32(&bs, flags);
1451 byte_stream_put8(&bs, strlen(bn));
1452 byte_stream_putstr(&bs, bn);
1454 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0015, 0x0000, bn, strlen(bn)+1);
1455 flap_connection_send_snac_with_priority(od, conn, SNAC_FAMILY_LOCATE, 0x0015, snacid, &bs, FALSE);
1457 byte_stream_destroy(&bs);
1459 return 0;
1462 static int
1463 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1465 if (snac->subtype == 0x0001)
1466 return error(od, conn, mod, frame, snac, bs);
1467 else if (snac->subtype == 0x0003)
1468 return rights(od, conn, mod, frame, snac, bs);
1469 else if (snac->subtype == 0x0006)
1470 return userinfo(od, conn, mod, frame, snac, bs);
1472 return 0;
1475 static void
1476 locate_shutdown(OscarData *od, aim_module_t *mod)
1478 aim_userinfo_t *del;
1480 while (od->locate.userinfo) {
1481 del = od->locate.userinfo;
1482 od->locate.userinfo = od->locate.userinfo->next;
1483 aim_info_free(del);
1484 g_free(del);
1489 locate_modfirst(OscarData *od, aim_module_t *mod)
1491 mod->family = SNAC_FAMILY_LOCATE;
1492 mod->version = 0x0001;
1493 mod->toolid = 0x0110;
1494 mod->toolversion = 0x0629;
1495 mod->flags = 0;
1496 strncpy(mod->name, "locate", sizeof(mod->name));
1497 mod->snachandler = snachandler;
1498 mod->shutdown = locate_shutdown;
1500 return 0;
1503 const char*
1504 icq_get_custom_icon_description(const char *mood)
1506 int i;
1508 if (!(mood && *mood))
1509 return NULL;
1511 for (i = 0; icq_custom_icons[i].mood; i++) {
1512 /* We check that description is not NULL to exclude
1513 * duplicates, like the typing duplicate. */
1514 if (icq_purple_moods[i].description &&
1515 purple_strequal(mood, icq_custom_icons[i].mood)) {
1516 return icq_purple_moods[i].description;
1520 return NULL;
1523 guint8*
1524 icq_get_custom_icon_data(const char *mood)
1526 int i;
1528 if (!(mood && *mood))
1529 return NULL;
1531 for (i = 0; icq_custom_icons[i].mood; i++) {
1532 /* We check that description is not NULL to exclude
1533 * duplicates, like the typing duplicate. */
1534 if (icq_purple_moods[i].description &&
1535 purple_strequal(mood, icq_custom_icons[i].mood)) {
1536 return (guint8 *)icq_custom_icons[i].data;
1539 return NULL;
1542 PurpleMood*
1543 icq_get_purple_moods(PurpleAccount *account)
1545 return icq_purple_moods;