Mercurial > pidgin
annotate src/protocols/oscar/locate.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 23 Dec 2005 19:26:04 +0000 |
parents | e856f985a0b9 |
children | 46ba853a76b5 |
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 |
7301 | 258 if (userinfo->away != NULL) { |
7046 | 259 free(cur->away); |
260 free(cur->away_encoding); | |
8393 | 261 if (userinfo->away_len > 0) { |
262 cur->away = (char *)malloc(userinfo->away_len); | |
263 memcpy(cur->away, userinfo->away, userinfo->away_len); | |
8394 | 264 } else |
265 cur->away = NULL; | |
7235 | 266 cur->away_encoding = strdup(userinfo->away_encoding); |
7046 | 267 cur->away_len = userinfo->away_len; |
268 } | |
10436 | 269 |
270 /* | |
271 * This callback can be used by a client if they want to know whenever | |
272 * info for a buddy is updated. For example, if a client shows away | |
273 * messages in its buddy list, then it would need to know if a user's | |
274 * away message changes. | |
275 */ | |
276 conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC); | |
277 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_LOC, AIM_CB_LOC_GOTINFOBLOCK))) | |
278 userfunc(sess, NULL, cur); | |
7011 | 279 } |
280 | |
8341 | 281 faim_export void aim_locate_dorequest(aim_session_t *sess) { |
7466 | 282 struct userinfo_node *cur = sess->locate.torequest; |
7011 | 283 |
284 if (cur == NULL) | |
285 return; | |
286 | |
7045 | 287 if (sess->locate.waiting_for_response == TRUE) |
7011 | 288 return; |
289 | |
7045 | 290 sess->locate.waiting_for_response = TRUE; |
7166 | 291 aim_locate_getinfoshort(sess, cur->sn, 0x00000003); |
7466 | 292 |
293 /* Move this node to the "requested" queue */ | |
294 sess->locate.torequest = cur->next; | |
295 cur->next = sess->locate.requested; | |
296 sess->locate.requested = cur; | |
7011 | 297 } |
298 | |
7447 | 299 /** |
11255 | 300 * Remove this screen name from our queue. If this info was requested |
7447 | 301 * by our info request queue, then pop the next element off of the queue. |
7259 | 302 * |
303 * @param sess The aim session. | |
304 * @param sn Screen name of the info we just received. | |
11255 | 305 * @return True if the request was explicit (client requested the info), |
7259 | 306 * false if the request was implicit (libfaim request the info). |
307 */ | |
308 static int aim_locate_gotuserinfo(aim_session_t *sess, const char *sn) { | |
309 struct userinfo_node *cur, *del; | |
310 int was_explicit = TRUE; | |
311 | |
7466 | 312 while ((sess->locate.requested != NULL) && (aim_sncmp(sn, sess->locate.requested->sn) == 0)) { |
313 del = sess->locate.requested; | |
314 sess->locate.requested = del->next; | |
7259 | 315 was_explicit = FALSE; |
316 free(del->sn); | |
317 free(del); | |
318 } | |
319 | |
7466 | 320 cur = sess->locate.requested; |
7259 | 321 while ((cur != NULL) && (cur->next != NULL)) { |
322 if (aim_sncmp(sn, cur->next->sn) == 0) { | |
323 del = cur->next; | |
324 cur->next = del->next; | |
325 was_explicit = FALSE; | |
326 free(del->sn); | |
327 free(del); | |
328 } else | |
329 cur = cur->next; | |
330 } | |
331 | |
332 if (!was_explicit) { | |
8341 | 333 aim_conn_t *conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC); |
334 aim_rxcallback_t userfunc; | |
335 | |
7259 | 336 sess->locate.waiting_for_response = FALSE; |
8341 | 337 |
338 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_LOC, AIM_CB_LOC_REQUESTINFOTIMEOUT))) | |
339 userfunc(sess, NULL); | |
8342 | 340 else |
341 aim_locate_dorequest(sess); | |
7259 | 342 } |
343 | |
344 return was_explicit; | |
345 } | |
346 | |
7011 | 347 faim_internal void aim_locate_requestuserinfo(aim_session_t *sess, const char *sn) { |
7045 | 348 struct userinfo_node *cur; |
7011 | 349 |
7266 | 350 /* Make sure we aren't already requesting info for this buddy */ |
7466 | 351 cur = sess->locate.torequest; |
7266 | 352 while (cur != NULL) { |
353 if (aim_sncmp(sn, cur->sn) == 0) | |
354 return; | |
355 cur = cur->next; | |
356 } | |
357 | |
358 /* Add a new node to our request queue */ | |
7045 | 359 cur = (struct userinfo_node *)malloc(sizeof(struct userinfo_node)); |
7011 | 360 cur->sn = strdup(sn); |
7466 | 361 cur->next = sess->locate.torequest; |
362 sess->locate.torequest = cur; | |
7011 | 363 |
7266 | 364 /* Actually request some info up in this piece */ |
7011 | 365 aim_locate_dorequest(sess); |
366 } | |
367 | |
7045 | 368 faim_export aim_userinfo_t *aim_locate_finduserinfo(aim_session_t *sess, const char *sn) { |
10116 | 369 aim_userinfo_t *cur = NULL; |
370 | |
371 if (sn == NULL) | |
372 return NULL; | |
373 | |
374 cur = sess->locate.userinfo; | |
7011 | 375 |
376 while (cur != NULL) { | |
377 if (aim_sncmp(cur->sn, sn) == 0) | |
378 return cur; | |
379 cur = cur->next; | |
380 } | |
381 | |
382 return NULL; | |
383 } | |
384 | |
7334 | 385 faim_internal fu32_t aim_locate_getcaps(aim_session_t *sess, aim_bstream_t *bs, int len) |
7011 | 386 { |
387 fu32_t flags = 0; | |
388 int offset; | |
389 | |
390 for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x10) { | |
391 fu8_t *cap; | |
392 int i, identified; | |
393 | |
394 cap = aimbs_getraw(bs, 0x10); | |
395 | |
396 for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) { | |
397 if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) { | |
398 flags |= aim_caps[i].flag; | |
399 identified++; | |
400 break; /* should only match once... */ | |
401 } | |
402 } | |
403 | |
7334 | 404 if (!identified) |
11253 | 405 gaim_debug_misc("oscar", "unknown capability: {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", |
7011 | 406 cap[0], cap[1], cap[2], cap[3], |
407 cap[4], cap[5], | |
408 cap[6], cap[7], | |
409 cap[8], cap[9], | |
410 cap[10], cap[11], cap[12], cap[13], | |
411 cap[14], cap[15]); | |
7334 | 412 |
413 free(cap); | |
414 } | |
415 | |
416 return flags; | |
417 } | |
418 | |
419 faim_internal fu32_t aim_locate_getcaps_short(aim_session_t *sess, aim_bstream_t *bs, int len) | |
420 { | |
421 fu32_t flags = 0; | |
422 int offset; | |
423 | |
424 for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x02) { | |
425 fu8_t *cap; | |
426 int i, identified; | |
427 | |
428 cap = aimbs_getraw(bs, 0x02); | |
429 | |
430 for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) { | |
431 if (memcmp(&aim_caps[i].data[2], cap, 0x02) == 0) { | |
432 flags |= aim_caps[i].flag; | |
433 identified++; | |
434 break; /* should only match once... */ | |
435 } | |
7011 | 436 } |
437 | |
7334 | 438 if (!identified) |
11253 | 439 gaim_debug_misc("oscar", "unknown short capability: {%02x%02x}\n", cap[0], cap[1]); |
7334 | 440 |
7011 | 441 free(cap); |
442 } | |
443 | |
444 return flags; | |
445 } | |
446 | |
11285 | 447 faim_internal int aimbs_putcaps(aim_bstream_t *bs, fu32_t caps) |
7011 | 448 { |
449 int i; | |
450 | |
451 if (!bs) | |
452 return -EINVAL; | |
453 | |
454 for (i = 0; aim_bstream_empty(bs); i++) { | |
455 | |
456 if (aim_caps[i].flag == AIM_CAPS_LAST) | |
457 break; | |
458 | |
459 if (caps & aim_caps[i].flag) | |
460 aimbs_putraw(bs, aim_caps[i].data, 0x10); | |
461 | |
462 } | |
463 | |
464 return 0; | |
465 } | |
466 | |
467 static void dumptlv(aim_session_t *sess, fu16_t type, aim_bstream_t *bs, fu8_t len) | |
468 { | |
469 int i; | |
470 | |
471 if (!sess || !bs || !len) | |
472 return; | |
473 | |
11253 | 474 gaim_debug_misc("oscar", "userinfo: type =0x%04x\n", type); |
475 gaim_debug_misc("oscar", "userinfo: length=0x%04x\n", len); | |
476 gaim_debug_misc("oscar", "userinfo: value:\n"); | |
7011 | 477 |
478 for (i = 0; i < len; i++) { | |
479 if ((i % 8) == 0) | |
11253 | 480 gaim_debug_misc("oscar", "\nuserinfo: "); |
481 gaim_debug_misc("oscar", "0x%2x ", aimbs_get8(bs)); | |
7011 | 482 } |
483 | |
11253 | 484 gaim_debug_misc("oscar", "\n"); |
7011 | 485 |
486 return; | |
487 } | |
488 | |
489 faim_internal void aim_info_free(aim_userinfo_t *info) | |
490 { | |
491 free(info->sn); | |
492 free(info->iconcsum); | |
493 free(info->info); | |
494 free(info->info_encoding); | |
12349 | 495 free(info->status); |
496 free(info->status_encoding); | |
7011 | 497 free(info->away); |
498 free(info->away_encoding); | |
499 } | |
500 | |
501 /* | |
11255 | 502 * AIM is fairly regular about providing user info. This is a generic |
7011 | 503 * routine to extract it in its standard form. |
504 */ | |
505 faim_internal int aim_info_extract(aim_session_t *sess, aim_bstream_t *bs, aim_userinfo_t *outinfo) | |
506 { | |
507 int curtlv, tlvcnt; | |
508 fu8_t snlen; | |
509 | |
510 if (!bs || !outinfo) | |
511 return -EINVAL; | |
512 | |
513 /* Clear out old data first */ | |
514 memset(outinfo, 0x00, sizeof(aim_userinfo_t)); | |
515 | |
516 /* | |
11255 | 517 * Screen name. Stored as an unterminated string prepended with a |
7011 | 518 * byte containing its length. |
519 */ | |
520 snlen = aimbs_get8(bs); | |
521 outinfo->sn = aimbs_getstr(bs, snlen); | |
522 | |
523 /* | |
524 * Warning Level. Stored as an unsigned short. | |
525 */ | |
526 outinfo->warnlevel = aimbs_get16(bs); | |
527 | |
528 /* | |
11255 | 529 * TLV Count. Unsigned short representing the number of |
7011 | 530 * Type-Length-Value triples that follow. |
531 */ | |
532 tlvcnt = aimbs_get16(bs); | |
533 | |
11255 | 534 /* |
7011 | 535 * Parse out the Type-Length-Value triples as they're found. |
536 */ | |
537 for (curtlv = 0; curtlv < tlvcnt; curtlv++) { | |
538 int endpos; | |
539 fu16_t type, length; | |
540 | |
541 type = aimbs_get16(bs); | |
542 length = aimbs_get16(bs); | |
543 | |
544 endpos = aim_bstream_curpos(bs) + length; | |
545 | |
546 if (type == 0x0001) { | |
547 /* | |
548 * Type = 0x0001: User flags | |
549 * | |
550 * Specified as any of the following ORed together: | |
551 * 0x0001 Trial (user less than 60days) | |
552 * 0x0002 Unknown bit 2 | |
553 * 0x0004 AOL Main Service user | |
554 * 0x0008 Unknown bit 4 | |
555 * 0x0010 Free (AIM) user | |
556 * 0x0020 Away | |
557 * 0x0400 ActiveBuddy | |
558 * | |
559 */ | |
560 outinfo->flags = aimbs_get16(bs); | |
561 outinfo->present |= AIM_USERINFO_PRESENT_FLAGS; | |
562 | |
563 } else if (type == 0x0002) { | |
564 /* | |
565 * Type = 0x0002: Account creation time. | |
566 * | |
567 * The time/date that the user originally registered for | |
568 * the service, stored in time_t format. | |
569 * | |
570 * I'm not sure how this differs from type 5 ("member | |
571 * since"). | |
572 * | |
573 * Note: This is the field formerly known as "member | |
574 * since". All these years and I finally found out | |
575 * that I got the name wrong. | |
576 */ | |
577 outinfo->createtime = aimbs_get32(bs); | |
578 outinfo->present |= AIM_USERINFO_PRESENT_CREATETIME; | |
579 | |
580 } else if (type == 0x0003) { | |
581 /* | |
582 * Type = 0x0003: On-Since date. | |
583 * | |
584 * The time/date that the user started their current | |
585 * session, stored in time_t format. | |
586 */ | |
587 outinfo->onlinesince = aimbs_get32(bs); | |
588 outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE; | |
589 | |
590 } else if (type == 0x0004) { | |
591 /* | |
592 * Type = 0x0004: Idle time. | |
593 * | |
594 * Number of minutes since the user actively used the | |
595 * service. | |
596 * | |
597 * Note that the client tells the server when to start | |
598 * counting idle times, so this may or may not be | |
599 * related to reality. | |
600 */ | |
601 outinfo->idletime = aimbs_get16(bs); | |
602 outinfo->present |= AIM_USERINFO_PRESENT_IDLE; | |
603 | |
604 } else if (type == 0x0005) { | |
605 /* | |
606 * Type = 0x0005: Member since date. | |
607 * | |
608 * The time/date that the user originally registered for | |
609 * the service, stored in time_t format. | |
610 * | |
611 * This is sometimes sent instead of type 2 ("account | |
612 * creation time"), particularly in the self-info. | |
613 * And particularly for ICQ? | |
614 */ | |
615 outinfo->membersince = aimbs_get32(bs); | |
616 outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE; | |
617 | |
618 } else if (type == 0x0006) { | |
619 /* | |
620 * Type = 0x0006: ICQ Online Status | |
621 * | |
622 * ICQ's Away/DND/etc "enriched" status. Some decoding | |
623 * of values done by Scott <darkagl@pcnet.com> | |
624 */ | |
625 aimbs_get16(bs); | |
626 outinfo->icqinfo.status = aimbs_get16(bs); | |
627 outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS; | |
628 | |
7141 | 629 } else if (type == 0x0008) { |
630 /* | |
631 * Type = 0x0008 | |
632 * | |
633 * Client type, or some such. | |
634 */ | |
635 | |
7011 | 636 } else if (type == 0x000a) { |
637 /* | |
638 * Type = 0x000a | |
639 * | |
640 * ICQ User IP Address. | |
641 * Ahh, the joy of ICQ security. | |
642 */ | |
643 outinfo->icqinfo.ipaddr = aimbs_get32(bs); | |
644 outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR; | |
645 | |
646 } else if (type == 0x000c) { | |
647 /* | |
648 * Type = 0x000c | |
649 * | |
650 * random crap containing the IP address, | |
651 * apparently a port number, and some Other Stuff. | |
652 * | |
653 * Format is: | |
654 * 4 bytes - Our IP address, 0xc0 a8 01 2b for 192.168.1.43 | |
655 * | |
656 * | |
657 */ | |
658 aimbs_getrawbuf(bs, outinfo->icqinfo.crap, 0x25); | |
659 outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA; | |
660 | |
661 } else if (type == 0x000d) { | |
662 /* | |
663 * Type = 0x000d | |
664 * | |
7141 | 665 * OSCAR Capability information. |
7011 | 666 * |
667 */ | |
7334 | 668 outinfo->capabilities |= aim_locate_getcaps(sess, bs, length); |
7011 | 669 outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES; |
670 | |
671 } else if (type == 0x000e) { | |
672 /* | |
673 * Type = 0x000e | |
674 * | |
7141 | 675 * AOL capability information. |
7011 | 676 * |
677 */ | |
678 | |
679 } else if ((type == 0x000f) || (type == 0x0010)) { | |
680 /* | |
681 * Type = 0x000f: Session Length. (AIM) | |
682 * Type = 0x0010: Session Length. (AOL) | |
683 * | |
684 * The duration, in seconds, of the user's current | |
685 * session. | |
686 * | |
687 * Which TLV type this comes in depends on the | |
688 * service the user is using (AIM or AOL). | |
689 * | |
690 */ | |
691 outinfo->sessionlen = aimbs_get32(bs); | |
692 outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN; | |
693 | |
694 } else if (type == 0x0019) { | |
7141 | 695 /* |
696 * Type = 0x0019 | |
697 * | |
698 * OSCAR short capability information. A shortened | |
699 * form of the normal capabilities. | |
700 */ | |
7334 | 701 outinfo->capabilities |= aim_locate_getcaps_short(sess, bs, length); |
702 outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES; | |
7011 | 703 |
704 } else if (type == 0x001b) { | |
7141 | 705 /* |
706 * Type = 0x001a | |
707 * | |
708 * AOL short capability information. A shortened | |
709 * form of the normal capabilities. | |
710 */ | |
711 | |
712 } else if (type == 0x001b) { | |
713 /* | |
714 * Type = 0x0019 | |
715 * | |
716 * Encryption certification MD5 checksum. | |
717 */ | |
7011 | 718 |
719 } else if (type == 0x001d) { | |
720 /* | |
721 * Type = 0x001d | |
722 * | |
12349 | 723 * Buddy icon information and status/available messages. |
7011 | 724 * |
12349 | 725 * This almost seems like the AIM protocol guys gave |
726 * the iChat guys a Type, and the iChat guys tried to | |
727 * cram as much cool shit into it as possible. Then | |
728 * the Windows AIM guys were like, "hey, that's | |
7011 | 729 * pretty neat, let's copy those prawns." |
730 * | |
12349 | 731 * In that spirit, this can contain a custom message, |
732 * kind of like an away message, but you're not away | |
733 * (it's called an "available" message). Or it can | |
734 * contain information about the buddy icon the user | |
7011 | 735 * has stored on the server. |
736 */ | |
737 int type2, number, length2; | |
738 | |
739 while (aim_bstream_curpos(bs) < endpos) { | |
740 type2 = aimbs_get16(bs); | |
741 number = aimbs_get8(bs); | |
742 length2 = aimbs_get8(bs); | |
743 | |
744 switch (type2) { | |
745 case 0x0000: { /* This is an official buddy icon? */ | |
746 /* This is always 5 bytes of "0x02 01 d2 04 72"? */ | |
747 aim_bstream_advance(bs, length2); | |
748 } break; | |
749 | |
750 case 0x0001: { /* A buddy icon checksum */ | |
11024 | 751 if ((length2 > 0) && ((number == 0x00) || (number == 0x01))) { |
7011 | 752 free(outinfo->iconcsum); |
11024 | 753 outinfo->iconcsumtype = number; |
7011 | 754 outinfo->iconcsum = aimbs_getraw(bs, length2); |
755 outinfo->iconcsumlen = length2; | |
756 } else | |
757 aim_bstream_advance(bs, length2); | |
758 } break; | |
759 | |
12349 | 760 case 0x0002: { /* An status/available message */ |
761 free(outinfo->status); | |
762 free(outinfo->status_encoding); | |
10563 | 763 if (length2 >= 4) { |
12349 | 764 outinfo->status_len = aimbs_get16(bs); |
765 outinfo->status = aimbs_getstr(bs, outinfo->status_len); | |
7011 | 766 if (aimbs_get16(bs) == 0x0001) { /* We have an encoding */ |
767 aimbs_get16(bs); | |
12349 | 768 outinfo->status_encoding = aimbs_getstr(bs, aimbs_get16(bs)); |
7011 | 769 } else { |
770 /* No explicit encoding, client should use UTF-8 */ | |
12349 | 771 outinfo->status_encoding = NULL; |
7011 | 772 } |
12307 | 773 } else { |
7011 | 774 aim_bstream_advance(bs, length2); |
12349 | 775 outinfo->status_len = 0; |
776 outinfo->status = g_strdup(""); | |
777 outinfo->status_encoding = NULL; | |
12307 | 778 } |
7011 | 779 } break; |
780 | |
781 default: { | |
782 aim_bstream_advance(bs, length2); | |
783 } break; | |
784 } | |
785 } | |
786 | |
787 } else if (type == 0x001e) { | |
788 /* | |
789 * Type 30: Unknown. | |
790 * | |
791 * Always four bytes, but it doesn't look like an int. | |
792 */ | |
7025 | 793 |
794 } else if (type == 0x001f) { | |
795 /* | |
796 * Type 31: Unknown. | |
797 * | |
798 * Seen on a buddy using DeadAIM. Data was 4 bytes: | |
799 * 0x00 00 00 10 | |
800 */ | |
801 | |
7011 | 802 } else { |
803 | |
804 /* | |
805 * Reaching here indicates that either AOL has | |
806 * added yet another TLV for us to deal with, | |
807 * or the parsing has gone Terribly Wrong. | |
808 * | |
809 * Either way, inform the owner and attempt | |
810 * recovery. | |
811 * | |
812 */ | |
11253 | 813 gaim_debug_misc("oscar", "userinfo: **warning: unexpected TLV:\n"); |
814 gaim_debug_misc("oscar", "userinfo: sn =%s\n", outinfo->sn); | |
7011 | 815 dumptlv(sess, type, bs, length); |
816 } | |
817 | |
818 /* Save ourselves. */ | |
819 aim_bstream_setpos(bs, endpos); | |
820 } | |
821 | |
7045 | 822 aim_locate_adduserinfo(sess, outinfo); |
7011 | 823 |
824 return 0; | |
825 } | |
826 | |
827 /* | |
828 * Inverse of aim_info_extract() | |
829 */ | |
830 faim_internal int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info) | |
831 { | |
832 aim_tlvlist_t *tlvlist = NULL; | |
833 | |
834 if (!bs || !info) | |
835 return -EINVAL; | |
836 | |
837 aimbs_put8(bs, strlen(info->sn)); | |
10990 | 838 aimbs_putstr(bs, info->sn); |
7011 | 839 |
840 aimbs_put16(bs, info->warnlevel); | |
841 | |
842 if (info->present & AIM_USERINFO_PRESENT_FLAGS) | |
7167 | 843 aim_tlvlist_add_16(&tlvlist, 0x0001, info->flags); |
7011 | 844 if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE) |
7167 | 845 aim_tlvlist_add_32(&tlvlist, 0x0002, info->membersince); |
7011 | 846 if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE) |
7167 | 847 aim_tlvlist_add_32(&tlvlist, 0x0003, info->onlinesince); |
7011 | 848 if (info->present & AIM_USERINFO_PRESENT_IDLE) |
7167 | 849 aim_tlvlist_add_16(&tlvlist, 0x0004, info->idletime); |
7011 | 850 |
851 /* XXX - So, ICQ_OSCAR_SUPPORT is never defined anywhere... */ | |
12407
b33b4e326c90
[gaim-migrate @ 14714]
Richard Laager <rlaager@wiktel.com>
parents:
12349
diff
changeset
|
852 #ifdef ICQ_OSCAR_SUPPORT |
7011 | 853 if (atoi(info->sn) != 0) { |
854 if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) | |
7167 | 855 aim_tlvlist_add_16(&tlvlist, 0x0006, info->icqinfo.status); |
7011 | 856 if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR) |
7167 | 857 aim_tlvlist_add_32(&tlvlist, 0x000a, info->icqinfo.ipaddr); |
7011 | 858 } |
859 #endif | |
860 | |
861 if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES) | |
7167 | 862 aim_tlvlist_add_caps(&tlvlist, 0x000d, info->capabilities); |
10436 | 863 |
7011 | 864 if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) |
7167 | 865 aim_tlvlist_add_32(&tlvlist, (fu16_t)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); |
7011 | 866 |
7167 | 867 aimbs_put16(bs, aim_tlvlist_count(&tlvlist)); |
868 aim_tlvlist_write(bs, &tlvlist); | |
869 aim_tlvlist_free(&tlvlist); | |
7011 | 870 |
871 return 0; | |
872 } | |
873 | |
874 /* | |
7259 | 875 * Subtype 0x0001 |
876 */ | |
877 static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
878 { | |
879 int ret = 0; | |
880 aim_rxcallback_t userfunc; | |
881 aim_snac_t *snac2; | |
882 fu16_t reason; | |
883 char *sn; | |
884 int was_explicit; | |
885 | |
886 if (!(snac2 = aim_remsnac(sess, snac->id))) { | |
11253 | 887 gaim_debug_misc("oscar", "faim: locate.c, error(): received response from unknown request!\n"); |
7259 | 888 return 0; |
889 } | |
890 | |
891 if ((snac2->family != 0x0002) && (snac2->type != 0x0015)) { | |
11253 | 892 gaim_debug_misc("oscar", "faim: locate.c, error(): received response from invalid request! %d\n", snac2->family); |
7259 | 893 return 0; |
894 } | |
895 | |
896 if (!(sn = snac2->data)) { | |
11253 | 897 gaim_debug_misc("oscar", "faim: locate.c, error(): received response from request without a screen name!\n"); |
7259 | 898 return 0; |
899 } | |
900 | |
901 reason = aimbs_get16(bs); | |
902 | |
903 /* | |
904 * Remove this screen name from our queue. If the client requested | |
905 * this buddy's info explicitly, then notify them that we do not have | |
906 * info for this buddy. | |
907 */ | |
908 was_explicit = aim_locate_gotuserinfo(sess, sn); | |
909 if (was_explicit == TRUE) | |
910 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
911 ret = userfunc(sess, rx, reason, sn); | |
912 | |
913 if (snac2) | |
914 free(snac2->data); | |
915 free(snac2); | |
916 | |
917 return ret; | |
918 } | |
919 | |
920 /* | |
7011 | 921 * Subtype 0x0002 |
922 * | |
923 * Request Location services rights. | |
924 * | |
925 */ | |
926 faim_export int aim_locate_reqrights(aim_session_t *sess) | |
927 { | |
928 aim_conn_t *conn; | |
929 | |
930 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC))) | |
931 return -EINVAL; | |
932 | |
7282 | 933 return aim_genericreq_n_snacid(sess, conn, AIM_CB_FAM_LOC, AIM_CB_LOC_REQRIGHTS); |
7011 | 934 } |
935 | |
936 /* | |
937 * Subtype 0x0003 | |
938 * | |
939 * Normally contains: | |
940 * t(0001) - short containing max profile length (value = 1024) | |
941 * t(0002) - short - unknown (value = 16) [max MIME type length?] | |
942 * t(0003) - short - unknown (value = 10) | |
943 * t(0004) - short - unknown (value = 2048) [ICQ only?] | |
944 */ | |
945 static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
946 { | |
947 aim_tlvlist_t *tlvlist; | |
948 aim_rxcallback_t userfunc; | |
949 int ret = 0; | |
950 fu16_t maxsiglen = 0; | |
951 | |
7167 | 952 tlvlist = aim_tlvlist_read(bs); |
7011 | 953 |
7167 | 954 if (aim_tlv_gettlv(tlvlist, 0x0001, 1)) |
955 maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1); | |
7011 | 956 |
957 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
958 ret = userfunc(sess, rx, maxsiglen); | |
959 | |
7167 | 960 aim_tlvlist_free(&tlvlist); |
7011 | 961 |
962 return ret; | |
963 } | |
964 | |
965 /* | |
966 * Subtype 0x0004 | |
967 * | |
968 * Gives BOS your profile. | |
969 * | |
970 * profile_encoding and awaymsg_encoding MUST be set if profile or | |
971 * away are set, respectively, and their value may or may not be | |
972 * restricted to a few choices. I am currently aware of: | |
11159 | 973 * |
7011 | 974 * us-ascii Just that |
975 * unicode-2-0 UCS2-BE | |
11159 | 976 * |
7011 | 977 * profile_len and awaymsg_len MUST be set similarly, and they MUST |
978 * be the length of their respective strings in bytes. | |
979 * | |
980 * To get the previous behavior of awaymsg == "" un-setting the away | |
981 * message, set awaymsg non-NULL and awaymsg_len to 0 (this is the | |
982 * obvious equivalent). | |
11159 | 983 * |
7011 | 984 */ |
985 faim_export int aim_locate_setprofile(aim_session_t *sess, | |
11159 | 986 const char *profile_encoding, const gchar *profile, const int profile_len, |
987 const char *awaymsg_encoding, const gchar *awaymsg, const int awaymsg_len) | |
7011 | 988 { |
989 aim_conn_t *conn; | |
990 aim_frame_t *fr; | |
991 aim_snacid_t snacid; | |
992 aim_tlvlist_t *tl = NULL; | |
993 char *encoding; | |
994 static const char defencoding[] = {"text/aolrtf; charset=\"%s\""}; | |
995 | |
996 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC))) | |
997 return -EINVAL; | |
998 | |
7510 | 999 if (!profile && !awaymsg) |
1000 return -EINVAL; | |
1001 | |
7011 | 1002 if ((profile && profile_encoding == NULL) || (awaymsg && awaymsg_len && awaymsg_encoding == NULL)) { |
1003 return -EINVAL; | |
1004 } | |
1005 | |
1006 /* Build the packet first to get real length */ | |
1007 if (profile) { | |
1008 /* no + 1 here because of %s */ | |
1009 encoding = malloc(strlen(defencoding) + strlen(profile_encoding)); | |
1010 if (encoding == NULL) { | |
1011 return -ENOMEM; | |
1012 } | |
1013 snprintf(encoding, strlen(defencoding) + strlen(profile_encoding), defencoding, profile_encoding); | |
10991 | 1014 aim_tlvlist_add_str(&tl, 0x0001, encoding); |
11159 | 1015 aim_tlvlist_add_raw(&tl, 0x0002, profile_len, (const guchar *)profile); |
7011 | 1016 free(encoding); |
1017 } | |
1018 | |
1019 /* | |
1020 * So here's how this works: | |
1021 * - You are away when you have a non-zero-length type 4 TLV stored. | |
1022 * - You become unaway when you clear the TLV with a zero-length | |
1023 * type 4 TLV. | |
1024 * - If you do not send the type 4 TLV, your status does not change | |
1025 * (that is, if you were away, you'll remain away). | |
1026 */ | |
1027 if (awaymsg) { | |
1028 if (awaymsg_len) { | |
1029 encoding = malloc(strlen(defencoding) + strlen(awaymsg_encoding)); | |
1030 if (encoding == NULL) { | |
1031 return -ENOMEM; | |
1032 } | |
1033 snprintf(encoding, strlen(defencoding) + strlen(awaymsg_encoding), defencoding, awaymsg_encoding); | |
10991 | 1034 aim_tlvlist_add_str(&tl, 0x0003, encoding); |
11159 | 1035 aim_tlvlist_add_raw(&tl, 0x0004, awaymsg_len, (const guchar *)awaymsg); |
7011 | 1036 free(encoding); |
1037 } else | |
7167 | 1038 aim_tlvlist_add_noval(&tl, 0x0004); |
7011 | 1039 } |
1040 | |
7334 | 1041 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl)))) |
1042 return -ENOMEM; | |
1043 | |
1044 snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0); | |
1045 aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid); | |
1046 | |
1047 aim_tlvlist_write(&fr->data, &tl); | |
1048 aim_tlvlist_free(&tl); | |
1049 | |
1050 aim_tx_enqueue(sess, fr); | |
1051 | |
1052 return 0; | |
1053 } | |
1054 | |
1055 /* | |
1056 * Subtype 0x0004 - Set your client's capabilities. | |
1057 */ | |
1058 faim_export int aim_locate_setcaps(aim_session_t *sess, fu32_t caps) | |
1059 { | |
1060 aim_conn_t *conn; | |
1061 aim_frame_t *fr; | |
1062 aim_snacid_t snacid; | |
1063 aim_tlvlist_t *tl = NULL; | |
1064 | |
1065 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC))) | |
1066 return -EINVAL; | |
1067 | |
1068 aim_tlvlist_add_caps(&tl, 0x0005, caps); | |
7011 | 1069 |
7167 | 1070 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl)))) |
7011 | 1071 return -ENOMEM; |
1072 | |
1073 snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0); | |
1074 aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid); | |
1075 | |
7167 | 1076 aim_tlvlist_write(&fr->data, &tl); |
1077 aim_tlvlist_free(&tl); | |
7011 | 1078 |
1079 aim_tx_enqueue(sess, fr); | |
1080 | |
1081 return 0; | |
1082 } | |
1083 | |
1084 /* | |
1085 * Subtype 0x0005 - Request info of another AIM user. | |
1086 * | |
1087 * @param sn The screenname whose info you wish to request. | |
1088 * @param infotype The type of info you wish to request. | |
1089 * 0x0001 - Info/profile | |
1090 * 0x0003 - Away message | |
1091 * 0x0004 - Capabilities | |
1092 */ | |
1093 faim_export int aim_locate_getinfo(aim_session_t *sess, const char *sn, fu16_t infotype) | |
1094 { | |
1095 aim_conn_t *conn; | |
1096 aim_frame_t *fr; | |
1097 aim_snacid_t snacid; | |
1098 | |
1099 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn) | |
1100 return -EINVAL; | |
1101 | |
1102 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn)))) | |
1103 return -ENOMEM; | |
1104 | |
1105 snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, NULL, 0); | |
10436 | 1106 |
7011 | 1107 aim_putsnac(&fr->data, 0x0002, 0x0005, 0x0000, snacid); |
1108 aimbs_put16(&fr->data, infotype); | |
1109 aimbs_put8(&fr->data, strlen(sn)); | |
10998 | 1110 aimbs_putstr(&fr->data, sn); |
7011 | 1111 |
1112 aim_tx_enqueue(sess, fr); | |
1113 | |
1114 return 0; | |
1115 } | |
1116 | |
1117 /* Subtype 0x0006 */ | |
1118 static int userinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
1119 { | |
1120 int ret = 0; | |
1121 aim_rxcallback_t userfunc; | |
1122 aim_userinfo_t *userinfo, *userinfo2; | |
1123 aim_tlvlist_t *tlvlist; | |
1124 aim_tlv_t *tlv = NULL; | |
1125 int was_explicit; | |
1126 | |
1127 userinfo = (aim_userinfo_t *)malloc(sizeof(aim_userinfo_t)); | |
1128 aim_info_extract(sess, bs, userinfo); | |
7167 | 1129 tlvlist = aim_tlvlist_read(bs); |
7011 | 1130 |
1131 /* Profile will be 1 and 2 */ | |
7167 | 1132 userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1); |
1133 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) { | |
7011 | 1134 userinfo->info = (char *)malloc(tlv->length); |
1135 memcpy(userinfo->info, tlv->value, tlv->length); | |
1136 userinfo->info_len = tlv->length; | |
1137 } | |
1138 | |
1139 /* Away message will be 3 and 4 */ | |
7167 | 1140 userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1); |
1141 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) { | |
7011 | 1142 userinfo->away = (char *)malloc(tlv->length); |
1143 memcpy(userinfo->away, tlv->value, tlv->length); | |
1144 userinfo->away_len = tlv->length; | |
1145 } | |
1146 | |
1147 /* Caps will be 5 */ | |
7167 | 1148 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1))) { |
7011 | 1149 aim_bstream_t cbs; |
1150 aim_bstream_init(&cbs, tlv->value, tlv->length); | |
7334 | 1151 userinfo->capabilities = aim_locate_getcaps(sess, &cbs, tlv->length); |
7011 | 1152 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES; |
1153 } | |
7167 | 1154 aim_tlvlist_free(&tlvlist); |
7011 | 1155 |
7045 | 1156 aim_locate_adduserinfo(sess, userinfo); |
1157 userinfo2 = aim_locate_finduserinfo(sess, userinfo->sn); | |
7011 | 1158 aim_info_free(userinfo); |
1159 free(userinfo); | |
1160 | |
1161 /* | |
11255 | 1162 * Remove this screen name from our queue. If the client requested |
1163 * this buddy's info explicitly, then notify them that we have info | |
7011 | 1164 * for this buddy. |
1165 */ | |
7259 | 1166 was_explicit = aim_locate_gotuserinfo(sess, userinfo2->sn); |
1167 if (was_explicit == TRUE) | |
7011 | 1168 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
1169 ret = userfunc(sess, rx, userinfo2); | |
1170 | |
1171 return ret; | |
1172 } | |
1173 | |
11255 | 1174 /* |
7011 | 1175 * Subtype 0x0009 - Set directory profile data. |
1176 * | |
1177 * This is not the same as aim_location_setprofile! | |
1178 * privacy: 1 to allow searching, 0 to disallow. | |
1179 * | |
1180 */ | |
11255 | 1181 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 | 1182 { |
1183 aim_conn_t *conn; | |
1184 aim_frame_t *fr; | |
1185 aim_snacid_t snacid; | |
1186 aim_tlvlist_t *tl = NULL; | |
1187 | |
1188 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC))) | |
1189 return -EINVAL; | |
1190 | |
7167 | 1191 aim_tlvlist_add_16(&tl, 0x000a, privacy); |
7011 | 1192 |
1193 if (first) | |
10991 | 1194 aim_tlvlist_add_str(&tl, 0x0001, first); |
7011 | 1195 if (last) |
10991 | 1196 aim_tlvlist_add_str(&tl, 0x0002, last); |
7011 | 1197 if (middle) |
10991 | 1198 aim_tlvlist_add_str(&tl, 0x0003, middle); |
7011 | 1199 if (maiden) |
10991 | 1200 aim_tlvlist_add_str(&tl, 0x0004, maiden); |
7011 | 1201 |
1202 if (state) | |
10991 | 1203 aim_tlvlist_add_str(&tl, 0x0007, state); |
7011 | 1204 if (city) |
10991 | 1205 aim_tlvlist_add_str(&tl, 0x0008, city); |
7011 | 1206 |
1207 if (nickname) | |
10991 | 1208 aim_tlvlist_add_str(&tl, 0x000c, nickname); |
7011 | 1209 if (zip) |
10991 | 1210 aim_tlvlist_add_str(&tl, 0x000d, zip); |
7011 | 1211 |
1212 if (street) | |
10991 | 1213 aim_tlvlist_add_str(&tl, 0x0021, street); |
7011 | 1214 |
7167 | 1215 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl)))) |
7011 | 1216 return -ENOMEM; |
1217 | |
1218 snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0); | |
1219 | |
1220 aim_putsnac(&fr->data, 0x0002, 0x0009, 0x0000, snacid); | |
7167 | 1221 aim_tlvlist_write(&fr->data, &tl); |
1222 aim_tlvlist_free(&tl); | |
7011 | 1223 |
1224 aim_tx_enqueue(sess, fr); | |
1225 | |
1226 return 0; | |
1227 } | |
1228 | |
1229 /* | |
1230 * Subtype 0x000b - Huh? What is this? | |
1231 */ | |
1232 faim_export int aim_locate_000b(aim_session_t *sess, const char *sn) | |
1233 { | |
1234 aim_conn_t *conn; | |
1235 aim_frame_t *fr; | |
1236 aim_snacid_t snacid; | |
1237 | |
1238 return -EINVAL; | |
1239 | |
1240 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn) | |
1241 return -EINVAL; | |
1242 | |
1243 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) | |
1244 return -ENOMEM; | |
1245 | |
1246 snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0); | |
11255 | 1247 |
7011 | 1248 aim_putsnac(&fr->data, 0x0002, 0x000b, 0x0000, snacid); |
1249 aimbs_put8(&fr->data, strlen(sn)); | |
10990 | 1250 aimbs_putstr(&fr->data, sn); |
7011 | 1251 |
1252 aim_tx_enqueue(sess, fr); | |
1253 | |
1254 return 0; | |
1255 } | |
1256 | |
1257 /* | |
1258 * Subtype 0x000f | |
11255 | 1259 * |
7011 | 1260 * XXX pass these in better |
1261 * | |
1262 */ | |
1263 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) | |
1264 { | |
1265 aim_conn_t *conn; | |
1266 aim_frame_t *fr; | |
1267 aim_snacid_t snacid; | |
1268 aim_tlvlist_t *tl = NULL; | |
1269 | |
1270 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC))) | |
1271 return -EINVAL; | |
1272 | |
1273 /* ?? privacy ?? */ | |
7167 | 1274 aim_tlvlist_add_16(&tl, 0x000a, privacy); |
7011 | 1275 |
1276 if (interest1) | |
10991 | 1277 aim_tlvlist_add_str(&tl, 0x0000b, interest1); |
7011 | 1278 if (interest2) |
10991 | 1279 aim_tlvlist_add_str(&tl, 0x0000b, interest2); |
7011 | 1280 if (interest3) |
10991 | 1281 aim_tlvlist_add_str(&tl, 0x0000b, interest3); |
7011 | 1282 if (interest4) |
10991 | 1283 aim_tlvlist_add_str(&tl, 0x0000b, interest4); |
7011 | 1284 if (interest5) |
10991 | 1285 aim_tlvlist_add_str(&tl, 0x0000b, interest5); |
7011 | 1286 |
7167 | 1287 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl)))) |
7011 | 1288 return -ENOMEM; |
1289 | |
1290 snacid = aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0); | |
1291 | |
1292 aim_putsnac(&fr->data, 0x0002, 0x000f, 0x0000, 0); | |
7167 | 1293 aim_tlvlist_write(&fr->data, &tl); |
1294 aim_tlvlist_free(&tl); | |
7011 | 1295 |
1296 aim_tx_enqueue(sess, fr); | |
1297 | |
1298 return 0; | |
1299 } | |
1300 | |
1301 /* | |
11255 | 1302 * Subtype 0x0015 - Request the info a user using the short method. This is |
7011 | 1303 * what iChat uses. It normally is VERY leniently rate limited. |
1304 * | |
1305 * @param sn The screen name whose info you wish to request. | |
1306 * @param flags The bitmask which specifies the type of info you wish to request. | |
1307 * 0x00000001 - Info/profile. | |
1308 * 0x00000002 - Away message. | |
1309 * 0x00000004 - Capabilities. | |
1310 * 0x00000008 - Certification. | |
1311 * @return Return 0 if no errors, otherwise return the error number. | |
1312 */ | |
1313 faim_export int aim_locate_getinfoshort(aim_session_t *sess, const char *sn, fu32_t flags) | |
1314 { | |
1315 aim_conn_t *conn; | |
1316 aim_frame_t *fr; | |
1317 aim_snacid_t snacid; | |
1318 | |
1319 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn) | |
1320 return -EINVAL; | |
1321 | |
1322 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+1+strlen(sn)))) | |
1323 return -ENOMEM; | |
1324 | |
7259 | 1325 snacid = aim_cachesnac(sess, 0x0002, 0x0015, 0x0000, sn, strlen(sn)+1); |
7011 | 1326 |
7259 | 1327 aim_putsnac(&fr->data, 0x0002, 0x0015, 0x0000, snacid); |
7011 | 1328 aimbs_put32(&fr->data, flags); |
1329 aimbs_put8(&fr->data, strlen(sn)); | |
10990 | 1330 aimbs_putstr(&fr->data, sn); |
7011 | 1331 |
1332 aim_tx_enqueue(sess, fr); | |
1333 | |
1334 return 0; | |
1335 } | |
1336 | |
1337 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
1338 { | |
1339 | |
7259 | 1340 if (snac->subtype == 0x0001) |
1341 return error(sess, mod, rx, snac, bs); | |
1342 else if (snac->subtype == 0x0003) | |
7011 | 1343 return rights(sess, mod, rx, snac, bs); |
1344 else if (snac->subtype == 0x0006) | |
1345 return userinfo(sess, mod, rx, snac, bs); | |
1346 | |
1347 return 0; | |
1348 } | |
1349 | |
1350 static void locate_shutdown(aim_session_t *sess, aim_module_t *mod) | |
1351 { | |
1352 aim_userinfo_t *del; | |
1353 | |
7045 | 1354 while (sess->locate.userinfo) { |
1355 del = sess->locate.userinfo; | |
1356 sess->locate.userinfo = sess->locate.userinfo->next; | |
7046 | 1357 aim_info_free(del); |
7011 | 1358 free(del); |
1359 } | |
1360 } | |
1361 | |
1362 faim_internal int locate_modfirst(aim_session_t *sess, aim_module_t *mod) | |
1363 { | |
1364 | |
1365 mod->family = AIM_CB_FAM_LOC; | |
1366 mod->version = 0x0001; | |
1367 mod->toolid = 0x0110; | |
1368 mod->toolversion = 0x0629; | |
1369 mod->flags = 0; | |
1370 strncpy(mod->name, "locate", sizeof(mod->name)); | |
1371 mod->snachandler = snachandler; | |
1372 mod->shutdown = locate_shutdown; | |
1373 | |
1374 return 0; | |
1375 } |