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