Mercurial > pidgin.yaz
annotate libgaim/protocols/oscar/family_oservice.c @ 15107:f41cd6f78c60
[gaim-migrate @ 17892]
Use GHashTable and GQueue instead of GSList in a few places in
oscar. The speed improvements probably won't be noticeable.
4 files changed, 48 insertions(+), 106 deletions(-)
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 04 Dec 2006 11:14:11 +0000 |
parents | 525607f86cce |
children | fbfdbde296b0 |
rev | line source |
---|---|
14192 | 1 /* |
2 * Gaim's oscar protocol plugin | |
3 * This file is the legal property of its developers. | |
4 * Please see the AUTHORS file distributed alongside this file. | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
21 /* | |
22 * Family 0x0001 - This is a very special group. All connections support | |
23 * this group, as it does some particularly good things (like rate limiting). | |
24 */ | |
25 | |
26 #include "oscar.h" | |
27 | |
28 #include "cipher.h" | |
29 | |
30 /* Subtype 0x0002 - Client Online */ | |
31 void | |
32 aim_clientready(OscarData *od, FlapConnection *conn) | |
33 { | |
34 FlapFrame *frame; | |
35 aim_snacid_t snacid; | |
14348 | 36 GSList *cur; |
14192 | 37 |
38 frame = flap_frame_new(od, 0x02, 1152); | |
39 | |
40 snacid = aim_cachesnac(od, 0x0001, 0x0002, 0x0000, NULL, 0); | |
41 aim_putsnac(&frame->data, 0x0001, 0x0002, 0x0000, snacid); | |
42 | |
43 /* | |
44 * Send only the tool versions that the server cares about (that it | |
45 * marked as supporting in the server ready SNAC). | |
46 */ | |
47 for (cur = conn->groups; cur != NULL; cur = cur->next) | |
48 { | |
49 aim_module_t *mod; | |
50 | |
51 if ((mod = aim__findmodulebygroup(od, GPOINTER_TO_UINT(cur->data)))) | |
52 { | |
53 byte_stream_put16(&frame->data, mod->family); | |
54 byte_stream_put16(&frame->data, mod->version); | |
55 byte_stream_put16(&frame->data, mod->toolid); | |
56 byte_stream_put16(&frame->data, mod->toolversion); | |
57 } | |
58 } | |
59 | |
60 flap_connection_send(conn, frame); | |
61 } | |
62 | |
63 /* | |
64 * Subtype 0x0003 - Host Online | |
65 * | |
66 * See comments in conn.c about how the group associations are supposed | |
67 * to work, and how they really work. | |
68 * | |
69 * This info probably doesn't even need to make it to the client. | |
70 * | |
71 * We don't actually call the client here. This starts off the connection | |
72 * initialization routine required by all AIM connections. The next time | |
73 * the client is called is the CONNINITDONE callback, which should be | |
74 * shortly after the rate information is acknowledged. | |
75 * | |
76 */ | |
77 static int | |
78 hostonline(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
79 { | |
80 int group; | |
81 | |
82 while (byte_stream_empty(bs)) | |
83 { | |
84 group = byte_stream_get16(bs); | |
14348 | 85 conn->groups = g_slist_prepend(conn->groups, GUINT_TO_POINTER(group)); |
14192 | 86 } |
87 | |
88 /* | |
89 * Next step is in the Host Versions handler. | |
90 * | |
91 * Note that we must send this before we request rates, since | |
92 * the format of the rate information depends on the versions we | |
93 * give it. | |
94 * | |
95 */ | |
15086 | 96 aim_srv_setversions(od, conn); |
14192 | 97 |
98 return 1; | |
99 } | |
100 | |
101 /* Subtype 0x0004 - Service request */ | |
15086 | 102 void |
103 aim_srv_requestnew(OscarData *od, guint16 serviceid) | |
14192 | 104 { |
105 FlapConnection *conn; | |
106 | |
107 conn = flap_connection_findbygroup(od, SNAC_FAMILY_BOS); | |
108 | |
15086 | 109 aim_genericreq_s(od, conn, 0x0001, 0x0004, &serviceid); |
14192 | 110 } |
111 | |
112 /* | |
113 * Join a room of name roomname. This is the first step to joining an | |
114 * already created room. It's basically a Service Request for | |
115 * family 0x000e, with a little added on to specify the exchange and room | |
116 * name. | |
117 */ | |
118 int | |
119 aim_chat_join(OscarData *od, guint16 exchange, const char *roomname, guint16 instance) | |
120 { | |
121 FlapConnection *conn; | |
122 FlapFrame *frame; | |
123 aim_snacid_t snacid; | |
124 aim_tlvlist_t *tl = NULL; | |
125 struct chatsnacinfo csi; | |
126 | |
127 conn = flap_connection_findbygroup(od, SNAC_FAMILY_BOS); | |
128 if (!conn || !roomname || !strlen(roomname)) | |
129 return -EINVAL; | |
130 | |
131 frame = flap_frame_new(od, 0x02, 512); | |
132 | |
133 memset(&csi, 0, sizeof(csi)); | |
134 csi.exchange = exchange; | |
135 strncpy(csi.name, roomname, sizeof(csi.name)); | |
136 csi.instance = instance; | |
137 | |
138 snacid = aim_cachesnac(od, 0x0001, 0x0004, 0x0000, &csi, sizeof(csi)); | |
139 aim_putsnac(&frame->data, 0x0001, 0x0004, 0x0000, snacid); | |
140 | |
141 /* | |
142 * Requesting service chat (0x000e) | |
143 */ | |
144 byte_stream_put16(&frame->data, 0x000e); | |
145 | |
146 aim_tlvlist_add_chatroom(&tl, 0x0001, exchange, roomname, instance); | |
147 aim_tlvlist_write(&frame->data, &tl); | |
148 aim_tlvlist_free(&tl); | |
149 | |
150 flap_connection_send(conn, frame); | |
151 | |
152 return 0; | |
153 } | |
154 | |
155 /* Subtype 0x0005 - Redirect */ | |
156 static int | |
157 redirect(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
158 { | |
159 struct aim_redirect_data redir; | |
160 aim_rxcallback_t userfunc; | |
161 aim_tlvlist_t *tlvlist; | |
162 aim_snac_t *origsnac = NULL; | |
163 int ret = 0; | |
164 | |
165 memset(&redir, 0, sizeof(redir)); | |
166 | |
167 tlvlist = aim_tlvlist_read(bs); | |
168 | |
169 if (!aim_tlv_gettlv(tlvlist, 0x000d, 1) || | |
170 !aim_tlv_gettlv(tlvlist, 0x0005, 1) || | |
171 !aim_tlv_gettlv(tlvlist, 0x0006, 1)) { | |
172 aim_tlvlist_free(&tlvlist); | |
173 return 0; | |
174 } | |
175 | |
176 redir.group = aim_tlv_get16(tlvlist, 0x000d, 1); | |
177 redir.ip = aim_tlv_getstr(tlvlist, 0x0005, 1); | |
178 redir.cookielen = aim_tlv_gettlv(tlvlist, 0x0006, 1)->length; | |
179 redir.cookie = (guchar *)aim_tlv_getstr(tlvlist, 0x0006, 1); | |
180 | |
181 /* Fetch original SNAC so we can get csi if needed */ | |
182 origsnac = aim_remsnac(od, snac->id); | |
183 | |
184 if ((redir.group == SNAC_FAMILY_CHAT) && origsnac) { | |
185 struct chatsnacinfo *csi = (struct chatsnacinfo *)origsnac->data; | |
186 | |
187 redir.chat.exchange = csi->exchange; | |
188 redir.chat.room = csi->name; | |
189 redir.chat.instance = csi->instance; | |
190 } | |
191 | |
192 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
193 ret = userfunc(od, conn, frame, &redir); | |
194 | |
195 free((void *)redir.ip); | |
196 free((void *)redir.cookie); | |
197 | |
198 if (origsnac) | |
199 free(origsnac->data); | |
200 free(origsnac); | |
201 | |
202 aim_tlvlist_free(&tlvlist); | |
203 | |
204 return ret; | |
205 } | |
206 | |
207 /* Subtype 0x0006 - Request Rate Information. */ | |
208 void | |
15086 | 209 aim_srv_reqrates(OscarData *od, FlapConnection *conn) |
14192 | 210 { |
211 aim_genericreq_n_snacid(od, conn, 0x0001, 0x0006); | |
212 } | |
213 | |
214 /* | |
215 * OSCAR defines several 'rate classes'. Each class has separate | |
216 * rate limiting properties (limit level, alert level, disconnect | |
217 * level, etc), and a set of SNAC family/type pairs associated with | |
218 * it. The rate classes, their limiting properties, and the definitions | |
14646
e0a93e6fa98b
[gaim-migrate @ 17392]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14552
diff
changeset
|
219 * of which SNACs belong to which class are defined in the |
14192 | 220 * Rate Response packet at login to each host. |
221 * | |
222 * Logically, all rate offenses within one class count against further | |
223 * offenses for other SNACs in the same class (ie, sending messages | |
224 * too fast will limit the number of user info requests you can send, | |
225 * since those two SNACs are in the same rate class). | |
226 * | |
227 * Since the rate classes are defined dynamically at login, the values | |
228 * below may change. But they seem to be fairly constant. | |
229 * | |
230 * Currently, BOS defines five rate classes, with the commonly used | |
231 * members as follows... | |
232 * | |
233 * Rate class 0x0001: | |
234 * - Everything thats not in any of the other classes | |
235 * | |
236 * Rate class 0x0002: | |
237 * - Buddy list add/remove | |
238 * - Permit list add/remove | |
239 * - Deny list add/remove | |
240 * | |
241 * Rate class 0x0003: | |
242 * - User information requests | |
243 * - Outgoing ICBMs | |
244 * | |
245 * Rate class 0x0004: | |
246 * - A few unknowns: 2/9, 2/b, and f/2 | |
247 * | |
248 * Rate class 0x0005: | |
249 * - Chat room create | |
250 * - Outgoing chat ICBMs | |
251 * | |
252 * The only other thing of note is that class 5 (chat) has slightly looser | |
253 * limiting properties than class 3 (normal messages). But thats just a | |
254 * small bit of trivia for you. | |
255 * | |
256 * The last thing that needs to be learned about the rate limiting | |
257 * system is how the actual numbers relate to the passing of time. This | |
258 * seems to be a big mystery. | |
259 * | |
15086 | 260 * See joscar's javadoc for the RateClassInfo class for a great |
261 * explanation. You might be able to find it at | |
262 * http://dscoder.com/RateClassInfo.html | |
14192 | 263 */ |
264 | |
15087 | 265 static struct rateclass * |
266 rateclass_find(GSList *rateclasses, guint16 id) | |
14192 | 267 { |
15087 | 268 GSList *tmp; |
14192 | 269 |
15087 | 270 for (tmp = rateclasses; tmp != NULL; tmp = tmp->next) |
271 { | |
15091 | 272 struct rateclass *rateclass; |
15087 | 273 rateclass = tmp->data; |
274 if (rateclass->classid == id) | |
275 return rateclass; | |
14192 | 276 } |
277 | |
278 return NULL; | |
279 } | |
280 | |
281 /* Subtype 0x0007 - Rate Parameters */ | |
282 static int | |
283 rateresp(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
284 { | |
285 guint16 numclasses, i; | |
286 aim_rxcallback_t userfunc; | |
287 | |
288 /* | |
289 * First are the parameters for each rate class. | |
290 */ | |
291 numclasses = byte_stream_get16(bs); | |
15087 | 292 for (i = 0; i < numclasses; i++) |
293 { | |
294 struct rateclass *rateclass; | |
14192 | 295 |
15087 | 296 rateclass = g_new0(struct rateclass, 1); |
14192 | 297 |
15087 | 298 rateclass->classid = byte_stream_get16(bs); |
299 rateclass->windowsize = byte_stream_get32(bs); | |
300 rateclass->clear = byte_stream_get32(bs); | |
301 rateclass->alert = byte_stream_get32(bs); | |
302 rateclass->limit = byte_stream_get32(bs); | |
303 rateclass->disconnect = byte_stream_get32(bs); | |
304 rateclass->current = byte_stream_get32(bs); | |
305 rateclass->max = byte_stream_get32(bs); | |
14192 | 306 |
307 /* | |
308 * The server will send an extra five bytes of parameters | |
309 * depending on the version we advertised in 1/17. If we | |
310 * didn't send 1/17 (evil!), then this will crash and you | |
311 * die, as it will default to the old version but we have | |
312 * the new version hardcoded here. | |
313 */ | |
314 if (mod->version >= 3) | |
15087 | 315 byte_stream_getrawbuf(bs, rateclass->unknown, sizeof(rateclass->unknown)); |
14192 | 316 |
15107 | 317 rateclass->members = g_hash_table_new(g_direct_hash, g_direct_equal); |
15092 | 318 rateclass->last.tv_sec = 0; |
319 rateclass->last.tv_usec = 0; | |
15087 | 320 conn->rateclasses = g_slist_prepend(conn->rateclasses, rateclass); |
14192 | 321 } |
15087 | 322 conn->rateclasses = g_slist_reverse(conn->rateclasses); |
14192 | 323 |
324 /* | |
325 * Then the members of each class. | |
326 */ | |
15087 | 327 for (i = 0; i < numclasses; i++) |
328 { | |
14192 | 329 guint16 classid, count; |
15087 | 330 struct rateclass *rateclass; |
14192 | 331 int j; |
332 | |
333 classid = byte_stream_get16(bs); | |
334 count = byte_stream_get16(bs); | |
335 | |
15087 | 336 rateclass = rateclass_find(conn->rateclasses, classid); |
14192 | 337 |
15087 | 338 for (j = 0; j < count; j++) |
339 { | |
14192 | 340 guint16 group, subtype; |
341 | |
342 group = byte_stream_get16(bs); | |
343 subtype = byte_stream_get16(bs); | |
344 | |
15087 | 345 if (rateclass != NULL) |
15107 | 346 g_hash_table_insert(rateclass->members, |
347 GUINT_TO_POINTER((group << 16) + subtype), | |
348 GUINT_TO_POINTER(TRUE)); | |
14192 | 349 } |
350 } | |
351 | |
352 /* | |
353 * We don't pass the rate information up to the client, as it really | |
354 * doesn't care. The information is stored in the connection, however | |
15087 | 355 * so that we can do rate limiting management when sending SNACs. |
14192 | 356 */ |
357 | |
358 /* | |
359 * Last step in the conn init procedure is to acknowledge that we | |
360 * agree to these draconian limitations. | |
361 */ | |
15086 | 362 aim_srv_rates_addparam(od, conn); |
14192 | 363 |
364 /* | |
365 * Finally, tell the client it's ready to go... | |
366 */ | |
367 if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE))) | |
368 userfunc(od, conn, frame); | |
369 | |
370 return 1; | |
371 } | |
372 | |
373 /* Subtype 0x0008 - Add Rate Parameter */ | |
374 void | |
15086 | 375 aim_srv_rates_addparam(OscarData *od, FlapConnection *conn) |
14192 | 376 { |
377 FlapFrame *frame; | |
378 aim_snacid_t snacid; | |
15087 | 379 GSList *tmp; |
14192 | 380 |
381 frame = flap_frame_new(od, 0x02, 512); | |
382 | |
383 snacid = aim_cachesnac(od, 0x0001, 0x0008, 0x0000, NULL, 0); | |
384 aim_putsnac(&frame->data, 0x0001, 0x0008, 0x0000, snacid); | |
385 | |
15087 | 386 for (tmp = conn->rateclasses; tmp != NULL; tmp = tmp->next) |
387 { | |
388 struct rateclass *rateclass; | |
389 rateclass = tmp->data; | |
390 byte_stream_put16(&frame->data, rateclass->classid); | |
391 } | |
14192 | 392 |
393 flap_connection_send(conn, frame); | |
394 } | |
395 | |
396 /* Subtype 0x0009 - Delete Rate Parameter */ | |
397 void | |
15086 | 398 aim_srv_rates_delparam(OscarData *od, FlapConnection *conn) |
14192 | 399 { |
400 FlapFrame *frame; | |
401 aim_snacid_t snacid; | |
15087 | 402 GSList *tmp; |
14192 | 403 |
404 frame = flap_frame_new(od, 0x02, 512); | |
405 | |
406 snacid = aim_cachesnac(od, 0x0001, 0x0009, 0x0000, NULL, 0); | |
407 aim_putsnac(&frame->data, 0x0001, 0x0009, 0x0000, snacid); | |
408 | |
15087 | 409 for (tmp = conn->rateclasses; tmp != NULL; tmp = tmp->next) |
410 { | |
411 struct rateclass *rateclass; | |
412 rateclass = tmp->data; | |
413 byte_stream_put16(&frame->data, rateclass->classid); | |
414 } | |
14192 | 415 |
416 flap_connection_send(conn, frame); | |
417 } | |
418 | |
419 /* Subtype 0x000a - Rate Change */ | |
420 static int | |
421 ratechange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
422 { | |
423 int ret = 0; | |
424 aim_rxcallback_t userfunc; | |
15088 | 425 guint16 code, classid; |
426 struct rateclass *rateclass; | |
14192 | 427 |
428 code = byte_stream_get16(bs); | |
15088 | 429 classid = byte_stream_get16(bs); |
430 | |
431 rateclass = rateclass_find(conn->rateclasses, classid); | |
432 if (rateclass == NULL) | |
433 /* This should never really happen */ | |
434 return 0; | |
14192 | 435 |
15088 | 436 rateclass->windowsize = byte_stream_get32(bs); |
437 rateclass->clear = byte_stream_get32(bs); | |
438 rateclass->alert = byte_stream_get32(bs); | |
439 rateclass->limit = byte_stream_get32(bs); | |
440 rateclass->disconnect = byte_stream_get32(bs); | |
441 rateclass->current = byte_stream_get32(bs); | |
442 rateclass->max = byte_stream_get32(bs); | |
14192 | 443 |
444 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
15088 | 445 ret = userfunc(od, conn, frame, code, classid, rateclass->windowsize, rateclass->clear, rateclass->alert, rateclass->limit, rateclass->disconnect, rateclass->current, rateclass->max); |
14192 | 446 |
447 return ret; | |
448 } | |
449 | |
450 /* | |
451 * How Migrations work. | |
452 * | |
453 * The server sends a Server Pause message, which the client should respond to | |
454 * with a Server Pause Ack, which contains the families it needs on this | |
455 * connection. The server will send a Migration Notice with an IP address, and | |
456 * then disconnect. Next the client should open the connection and send the | |
457 * cookie. Repeat the normal login process and pretend this never happened. | |
458 * | |
459 * The Server Pause contains no data. | |
460 * | |
461 */ | |
462 | |
463 /* Subtype 0x000b - Service Pause */ | |
464 static int | |
465 serverpause(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
466 { | |
467 int ret = 0; | |
468 aim_rxcallback_t userfunc; | |
469 | |
470 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
471 ret = userfunc(od, conn, frame); | |
472 | |
473 return ret; | |
474 } | |
475 | |
476 /* | |
477 * Subtype 0x000c - Service Pause Acknowledgement | |
478 * | |
15086 | 479 * It is rather important that aim_srv_sendpauseack() gets called for the exact |
14192 | 480 * same connection that the Server Pause callback was called for, since |
481 * libfaim extracts the data for the SNAC from the connection structure. | |
482 * | |
483 * Of course, if you don't do that, more bad things happen than just what | |
484 * libfaim can cause. | |
485 * | |
486 */ | |
487 void | |
15086 | 488 aim_srv_sendpauseack(OscarData *od, FlapConnection *conn) |
14192 | 489 { |
490 FlapFrame *frame; | |
491 aim_snacid_t snacid; | |
14348 | 492 GSList *cur; |
14192 | 493 |
494 frame = flap_frame_new(od, 0x02, 1024); | |
495 | |
496 snacid = aim_cachesnac(od, 0x0001, 0x000c, 0x0000, NULL, 0); | |
497 aim_putsnac(&frame->data, 0x0001, 0x000c, 0x0000, snacid); | |
498 | |
499 /* | |
500 * This list should have all the groups that the original | |
501 * Host Online / Server Ready said this host supports. And | |
502 * we want them all back after the migration. | |
503 */ | |
504 for (cur = conn->groups; cur != NULL; cur = cur->next) | |
505 byte_stream_put16(&frame->data, GPOINTER_TO_UINT(cur->data)); | |
506 | |
507 flap_connection_send(conn, frame); | |
508 } | |
509 | |
510 /* Subtype 0x000d - Service Resume */ | |
511 static int | |
512 serverresume(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
513 { | |
514 int ret = 0; | |
515 aim_rxcallback_t userfunc; | |
516 | |
517 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
518 ret = userfunc(od, conn, frame); | |
519 | |
520 return ret; | |
521 } | |
522 | |
523 /* Subtype 0x000e - Request self-info */ | |
524 void | |
15086 | 525 aim_srv_reqpersonalinfo(OscarData *od, FlapConnection *conn) |
14192 | 526 { |
527 aim_genericreq_n_snacid(od, conn, 0x0001, 0x000e); | |
528 } | |
529 | |
530 /* Subtype 0x000f - Self User Info */ | |
531 static int | |
532 selfinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
533 { | |
534 int ret = 0; | |
535 aim_rxcallback_t userfunc; | |
536 aim_userinfo_t userinfo; | |
537 | |
538 aim_info_extract(od, bs, &userinfo); | |
539 | |
540 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
541 ret = userfunc(od, conn, frame, &userinfo); | |
542 | |
543 aim_info_free(&userinfo); | |
544 | |
545 return ret; | |
546 } | |
547 | |
548 /* Subtype 0x0010 - Evil Notification */ | |
549 static int | |
550 evilnotify(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
551 { | |
552 int ret = 0; | |
553 aim_rxcallback_t userfunc; | |
554 guint16 newevil; | |
555 aim_userinfo_t userinfo; | |
556 | |
557 memset(&userinfo, 0, sizeof(aim_userinfo_t)); | |
558 | |
559 newevil = byte_stream_get16(bs); | |
560 | |
561 if (byte_stream_empty(bs)) | |
562 aim_info_extract(od, bs, &userinfo); | |
563 | |
564 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
565 ret = userfunc(od, conn, frame, newevil, &userinfo); | |
566 | |
567 aim_info_free(&userinfo); | |
568 | |
569 return ret; | |
570 } | |
571 | |
572 /* | |
573 * Subtype 0x0011 - Idle Notification | |
574 * | |
575 * Should set your current idle time in seconds. Note that this should | |
576 * never be called consecutively with a non-zero idle time. That makes | |
577 * OSCAR do funny things. Instead, just set it once you go idle, and then | |
578 * call it again with zero when you're back. | |
579 * | |
580 */ | |
15086 | 581 void |
14192 | 582 aim_srv_setidle(OscarData *od, guint32 idletime) |
583 { | |
584 FlapConnection *conn; | |
585 | |
15086 | 586 conn = flap_connection_findbygroup(od, SNAC_FAMILY_BOS); |
587 aim_genericreq_l(od, conn, 0x0001, 0x0011, &idletime); | |
14192 | 588 } |
589 | |
590 /* | |
591 * Subtype 0x0012 - Service Migrate | |
592 * | |
593 * This is the final SNAC sent on the original connection during a migration. | |
594 * It contains the IP and cookie used to connect to the new server, and | |
595 * optionally a list of the SNAC groups being migrated. | |
596 * | |
597 */ | |
598 static int | |
599 migrate(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
600 { | |
601 aim_rxcallback_t userfunc; | |
602 int ret = 0; | |
603 guint16 groupcount, i; | |
604 aim_tlvlist_t *tl; | |
605 char *ip = NULL; | |
606 aim_tlv_t *cktlv; | |
607 | |
608 /* | |
609 * Apparently there's some fun stuff that can happen right here. The | |
610 * migration can actually be quite selective about what groups it | |
611 * moves to the new server. When not all the groups for a connection | |
612 * are migrated, or they are all migrated but some groups are moved | |
613 * to a different server than others, it is called a bifurcated | |
614 * migration. | |
615 * | |
616 * Let's play dumb and not support that. | |
617 * | |
618 */ | |
619 groupcount = byte_stream_get16(bs); | |
620 for (i = 0; i < groupcount; i++) { | |
621 guint16 group; | |
622 | |
623 group = byte_stream_get16(bs); | |
624 | |
625 gaim_debug_misc("oscar", "bifurcated migration unsupported -- group 0x%04x\n", group); | |
626 } | |
627 | |
628 tl = aim_tlvlist_read(bs); | |
629 | |
630 if (aim_tlv_gettlv(tl, 0x0005, 1)) | |
631 ip = aim_tlv_getstr(tl, 0x0005, 1); | |
632 | |
633 cktlv = aim_tlv_gettlv(tl, 0x0006, 1); | |
634 | |
635 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
636 ret = userfunc(od, conn, frame, ip, cktlv ? cktlv->value : NULL); | |
637 | |
638 aim_tlvlist_free(&tl); | |
639 free(ip); | |
640 | |
641 return ret; | |
642 } | |
643 | |
644 /* Subtype 0x0013 - Message of the Day */ | |
645 static int | |
646 motd(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
647 { | |
648 aim_rxcallback_t userfunc; | |
649 char *msg = NULL; | |
650 int ret = 0; | |
651 aim_tlvlist_t *tlvlist; | |
652 guint16 id; | |
653 | |
654 /* | |
655 * Code. | |
656 * | |
657 * Valid values: | |
658 * 1 Mandatory upgrade | |
659 * 2 Advisory upgrade | |
660 * 3 System bulletin | |
661 * 4 Nothing's wrong ("top o the world" -- normal) | |
662 * 5 Lets-break-something. | |
663 * | |
664 */ | |
665 id = byte_stream_get16(bs); | |
666 | |
667 /* | |
668 * TLVs follow | |
669 */ | |
670 tlvlist = aim_tlvlist_read(bs); | |
671 | |
672 msg = aim_tlv_getstr(tlvlist, 0x000b, 1); | |
673 | |
674 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
675 ret = userfunc(od, conn, frame, id, msg); | |
676 | |
677 free(msg); | |
678 | |
679 aim_tlvlist_free(&tlvlist); | |
680 | |
681 return ret; | |
682 } | |
683 | |
684 /* | |
685 * Subtype 0x0014 - Set privacy flags | |
686 * | |
687 * Normally 0x03. | |
688 * | |
689 * Bit 1: Allows other AIM users to see how long you've been idle. | |
690 * Bit 2: Allows other AIM users to see how long you've been a member. | |
691 * | |
692 */ | |
15086 | 693 void |
694 aim_srv_setprivacyflags(OscarData *od, FlapConnection *conn, guint32 flags) | |
14192 | 695 { |
15086 | 696 aim_genericreq_l(od, conn, 0x0001, 0x0014, &flags); |
14192 | 697 } |
698 | |
699 /* | |
700 * Subtype 0x0016 - No-op | |
701 * | |
702 * WinAIM sends these every 4min or so to keep the connection alive. Its not | |
703 * really necessary. | |
704 * | |
705 * Wha? No? Since when? I think WinAIM sends an empty channel 5 | |
706 * FLAP as a no-op... | |
707 */ | |
15086 | 708 void |
709 aim_srv_nop(OscarData *od, FlapConnection *conn) | |
14192 | 710 { |
15086 | 711 aim_genericreq_n(od, conn, 0x0001, 0x0016); |
14192 | 712 } |
713 | |
714 /* | |
715 * Subtype 0x0017 - Set client versions | |
716 * | |
717 * If you've seen the clientonline/clientready SNAC you're probably | |
718 * wondering what the point of this one is. And that point seems to be | |
719 * that the versions in the client online SNAC are sent too late for the | |
720 * server to be able to use them to change the protocol for the earlier | |
721 * login packets (client versions are sent right after Host Online is | |
722 * received, but client online versions aren't sent until quite a bit later). | |
723 * We can see them already making use of this by changing the format of | |
724 * the rate information based on what version of group 1 we advertise here. | |
725 * | |
726 */ | |
727 void | |
15086 | 728 aim_srv_setversions(OscarData *od, FlapConnection *conn) |
14192 | 729 { |
730 FlapFrame *frame; | |
731 aim_snacid_t snacid; | |
14348 | 732 GSList *cur; |
14192 | 733 |
734 frame = flap_frame_new(od, 0x02, 1152); | |
735 | |
736 snacid = aim_cachesnac(od, 0x0001, 0x0017, 0x0000, NULL, 0); | |
737 aim_putsnac(&frame->data, 0x0001, 0x0017, 0x0000, snacid); | |
738 | |
739 /* | |
740 * Send only the versions that the server cares about (that it | |
741 * marked as supporting in the server ready SNAC). | |
742 */ | |
743 for (cur = conn->groups; cur != NULL; cur = cur->next) | |
744 { | |
745 aim_module_t *mod; | |
746 | |
747 if ((mod = aim__findmodulebygroup(od, GPOINTER_TO_UINT(cur->data)))) | |
748 { | |
749 byte_stream_put16(&frame->data, mod->family); | |
750 byte_stream_put16(&frame->data, mod->version); | |
751 } | |
752 } | |
753 | |
754 flap_connection_send(conn, frame); | |
755 } | |
756 | |
757 /* Subtype 0x0018 - Host versions */ | |
758 static int | |
759 hostversions(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
760 { | |
761 int vercount; | |
762 guint8 *versions; | |
763 | |
764 /* This is frivolous. (Thank you SmarterChild.) */ | |
765 vercount = byte_stream_empty(bs)/4; | |
766 versions = byte_stream_getraw(bs, byte_stream_empty(bs)); | |
767 free(versions); | |
768 | |
769 /* | |
770 * Now request rates. | |
771 */ | |
15086 | 772 aim_srv_reqrates(od, conn); |
14192 | 773 |
774 return 1; | |
775 } | |
776 | |
777 /* | |
778 * Subtype 0x001e - Set various account settings (mostly ICQ related). | |
779 * | |
780 * These settings are transient, not server-stored (i.e. they only | |
781 * apply to this session, and must be re-set the next time you sign | |
782 * on). | |
783 * | |
784 * You can set your ICQ status (available, away, do not disturb, | |
785 * etc.), or whether your IP address should be hidden or not, or | |
786 * if your status is visible on ICQ web sites, and you can set | |
787 * your IP address info and what not. | |
788 * | |
789 * These are the same TLVs seen in user info. You can | |
790 * also set 0x0008 and 0x000c. | |
14552 | 791 * |
792 * TODO: Combine this with the function below. | |
14192 | 793 */ |
794 int | |
15086 | 795 aim_srv_setextstatus(OscarData *od, guint32 status) |
14192 | 796 { |
797 FlapConnection *conn; | |
798 FlapFrame *frame; | |
799 aim_snacid_t snacid; | |
800 aim_tlvlist_t *tl = NULL; | |
801 guint32 data; | |
802 | |
803 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM))) | |
804 return -EINVAL; | |
805 | |
806 data = AIM_ICQ_STATE_HIDEIP | AIM_ICQ_STATE_DIRECTREQUIREAUTH | status; | |
807 | |
808 frame = flap_frame_new(od, 0x02, 10 + 8); | |
809 | |
810 snacid = aim_cachesnac(od, 0x0001, 0x001e, 0x0000, NULL, 0); | |
811 aim_putsnac(&frame->data, 0x0001, 0x001e, 0x0000, snacid); | |
812 | |
813 aim_tlvlist_add_32(&tl, 0x0006, data); | |
814 #if 0 | |
815 aim_tlvlist_add_raw(&tl, 0x000c, 0x0025, chunk_of_x25_bytes_with_ip_address_etc); | |
816 aim_tlvlist_add_raw(&tl, 0x0011, 0x0005, unknown 0x01 61 10 f6 41); | |
817 aim_tlvlist_add_16(&tl, 0x0012, unknown 0x00 00); | |
818 #endif | |
819 aim_tlvlist_write(&frame->data, &tl); | |
820 aim_tlvlist_free(&tl); | |
821 | |
822 flap_connection_send(conn, frame); | |
823 | |
824 return 0; | |
825 } | |
826 | |
827 /* | |
828 * Subtype 0x001e - Extended Status. | |
829 * | |
830 * Sets your "available" message. This is currently only supported by iChat | |
831 * and Gaim. | |
832 * | |
833 * These are the same TLVs seen in user info. You can | |
834 * also set 0x0008 and 0x000c. | |
14552 | 835 * |
836 * TODO: Combine this with the above function. | |
14192 | 837 */ |
838 int | |
839 aim_srv_setstatusmsg(OscarData *od, const char *msg) | |
840 { | |
841 FlapConnection *conn; | |
842 FlapFrame *frame; | |
843 aim_snacid_t snacid; | |
14552 | 844 int msglen; |
14192 | 845 |
846 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004))) | |
847 return -EINVAL; | |
848 | |
14552 | 849 if (msg == NULL) |
850 msglen = 0; | |
851 else | |
852 msglen = strlen(msg); | |
14192 | 853 |
14552 | 854 frame = flap_frame_new(od, 0x02, 10 + 4 + msglen + 8); |
14192 | 855 |
14552 | 856 snacid = aim_cachesnac(od, 0x0001, 0x001e, 0x0000, NULL, 0); |
857 aim_putsnac(&frame->data, 0x0001, 0x001e, 0x0000, snacid); | |
858 | |
859 byte_stream_put16(&frame->data, 0x001d); /* userinfo TLV type */ | |
860 byte_stream_put16(&frame->data, msglen + 8); /* total length of userinfo TLV data */ | |
861 byte_stream_put16(&frame->data, 0x0002); | |
862 byte_stream_put8(&frame->data, 0x04); | |
863 byte_stream_put8(&frame->data, msglen+4); | |
864 byte_stream_put16(&frame->data, msglen); | |
865 if (msglen > 0) | |
14192 | 866 byte_stream_putstr(&frame->data, msg); |
14552 | 867 byte_stream_put16(&frame->data, 0x0000); |
14192 | 868 |
869 flap_connection_send(conn, frame); | |
870 | |
871 return 0; | |
872 } | |
873 | |
874 /* | |
875 * Starting this past week (26 Mar 2001, say), AOL has started sending | |
876 * this nice little extra SNAC. AFAIK, it has never been used until now. | |
877 * | |
878 * The request contains eight bytes. The first four are an offset, the | |
879 * second four are a length. | |
880 * | |
881 * The offset is an offset into aim.exe when it is mapped during execution | |
882 * on Win32. So far, AOL has only been requesting bytes in static regions | |
883 * of memory. (I won't put it past them to start requesting data in | |
884 * less static regions -- regions that are initialized at run time, but still | |
885 * before the client receives this request.) | |
886 * | |
887 * When the client receives the request, it adds it to the current ds | |
888 * (0x00400000) and dereferences it, copying the data into a buffer which | |
889 * it then runs directly through the MD5 hasher. The 16 byte output of | |
890 * the hash is then sent back to the server. | |
891 * | |
892 * If the client does not send any data back, or the data does not match | |
893 * the data that the specific client should have, the client will get the | |
894 * following message from "AOL Instant Messenger": | |
895 * "You have been disconnected from the AOL Instant Message Service (SM) | |
896 * for accessing the AOL network using unauthorized software. You can | |
897 * download a FREE, fully featured, and authorized client, here | |
898 * http://www.aol.com/aim/download2.html" | |
899 * The connection is then closed, receiving disconnect code 1, URL | |
900 * http://www.aim.aol.com/errors/USER_LOGGED_OFF_NEW_LOGIN.html. | |
901 * | |
902 * Note, however, that numerous inconsistencies can cause the above error, | |
903 * not just sending back a bad hash. Do not immediatly suspect this code | |
904 * if you get disconnected. AOL and the open/free software community have | |
905 * played this game for a couple years now, generating the above message | |
906 * on numerous ocassions. | |
907 * | |
908 * Anyway, neener. We win again. | |
909 * | |
910 */ | |
911 /* Subtype 0x001f - Client verification */ | |
912 static int | |
913 memrequest(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
914 { | |
915 int ret = 0; | |
916 aim_rxcallback_t userfunc; | |
917 guint32 offset, len; | |
918 aim_tlvlist_t *list; | |
919 char *modname; | |
920 | |
921 offset = byte_stream_get32(bs); | |
922 len = byte_stream_get32(bs); | |
923 list = aim_tlvlist_read(bs); | |
924 | |
925 modname = aim_tlv_getstr(list, 0x0001, 1); | |
926 | |
927 gaim_debug_info("oscar", "Got memory request for data at 0x%08lx (%d bytes) of requested %s\n", offset, len, modname ? modname : "aim.exe"); | |
928 | |
929 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
930 ret = userfunc(od, conn, frame, offset, len, modname); | |
931 | |
932 free(modname); | |
933 aim_tlvlist_free(&list); | |
934 | |
935 return ret; | |
936 } | |
937 | |
938 /* Subtype 0x0020 - Client verification reply */ | |
939 int | |
940 aim_sendmemblock(OscarData *od, FlapConnection *conn, guint32 offset, guint32 len, const guint8 *buf, guint8 flag) | |
941 { | |
942 FlapFrame *frame; | |
943 aim_snacid_t snacid; | |
944 | |
945 if (!od || !conn) | |
946 return -EINVAL; | |
947 | |
948 frame = flap_frame_new(od, 0x02, 10+2+16); | |
949 | |
950 snacid = aim_cachesnac(od, 0x0001, 0x0020, 0x0000, NULL, 0); | |
951 | |
952 aim_putsnac(&frame->data, 0x0001, 0x0020, 0x0000, snacid); | |
953 byte_stream_put16(&frame->data, 0x0010); /* md5 is always 16 bytes */ | |
954 | |
955 if ((flag == AIM_SENDMEMBLOCK_FLAG_ISHASH) && buf && (len == 0x10)) { /* we're getting a hash */ | |
956 | |
957 byte_stream_putraw(&frame->data, buf, 0x10); | |
958 | |
959 } else if (buf && (len > 0)) { /* use input buffer */ | |
960 GaimCipher *cipher; | |
961 GaimCipherContext *context; | |
962 guchar digest[16]; | |
963 | |
964 cipher = gaim_ciphers_find_cipher("md5"); | |
965 | |
966 context = gaim_cipher_context_new(cipher, NULL); | |
967 gaim_cipher_context_append(context, buf, len); | |
968 gaim_cipher_context_digest(context, 16, digest, NULL); | |
969 gaim_cipher_context_destroy(context); | |
970 | |
971 byte_stream_putraw(&frame->data, digest, 0x10); | |
972 | |
973 } else if (len == 0) { /* no length, just hash NULL (buf is optional) */ | |
974 GaimCipher *cipher; | |
975 GaimCipherContext *context; | |
976 guchar digest[16]; | |
977 guint8 nil = '\0'; | |
978 | |
979 /* | |
980 * I'm not sure if we really need the empty append with the | |
981 * new MD5 functions, so I'll leave it in, just in case. | |
982 */ | |
983 cipher = gaim_ciphers_find_cipher("md5"); | |
984 | |
985 context = gaim_cipher_context_new(cipher, NULL); | |
986 gaim_cipher_context_append(context, &nil, 0); | |
987 gaim_cipher_context_digest(context, 16, digest, NULL); | |
988 gaim_cipher_context_destroy(context); | |
989 | |
990 byte_stream_putraw(&frame->data, digest, 0x10); | |
991 | |
992 } else { | |
993 | |
994 /* | |
995 * This data is correct for AIM 3.5.1670. | |
996 * | |
997 * Using these blocks is as close to "legal" as you can get | |
998 * without using an AIM binary. | |
999 * | |
1000 */ | |
1001 if ((offset == 0x03ffffff) && (len == 0x03ffffff)) { | |
1002 | |
1003 #if 1 /* with "AnrbnrAqhfzcd" */ | |
1004 byte_stream_put32(&frame->data, 0x44a95d26); | |
1005 byte_stream_put32(&frame->data, 0xd2490423); | |
1006 byte_stream_put32(&frame->data, 0x93b8821f); | |
1007 byte_stream_put32(&frame->data, 0x51c54b01); | |
1008 #else /* no filename */ | |
1009 byte_stream_put32(&frame->data, 0x1df8cbae); | |
1010 byte_stream_put32(&frame->data, 0x5523b839); | |
1011 byte_stream_put32(&frame->data, 0xa0e10db3); | |
1012 byte_stream_put32(&frame->data, 0xa46d3b39); | |
1013 #endif | |
1014 | |
1015 } else | |
1016 gaim_debug_warning("oscar", "sendmemblock: unknown hash request\n"); | |
1017 | |
1018 } | |
1019 | |
1020 flap_connection_send(conn, frame); | |
1021 | |
1022 return 0; | |
1023 } | |
1024 | |
1025 /* | |
1026 * Subtype 0x0021 - Receive our extended status | |
1027 * | |
1028 * This is used for iChat's "available" messages, and maybe ICQ extended | |
1029 * status messages? It's also used to tell the client whether or not it | |
1030 * needs to upload an SSI buddy icon... who engineers this stuff, anyway? | |
1031 */ | |
1032 static int | |
1033 aim_parse_extstatus(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
1034 { | |
1035 int ret = 0; | |
1036 aim_rxcallback_t userfunc; | |
1037 guint16 type; | |
1038 guint8 flags, length; | |
1039 | |
1040 type = byte_stream_get16(bs); | |
1041 flags = byte_stream_get8(bs); | |
1042 length = byte_stream_get8(bs); | |
1043 | |
1044 /* | |
1045 * A flag of 0x01 could mean "this is the checksum we have for you" | |
1046 * A flag of 0x40 could mean "I don't have your icon, upload it" | |
1047 */ | |
1048 | |
1049 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) { | |
1050 switch (type) { | |
1051 case 0x0000: | |
1052 case 0x0001: { /* buddy icon checksum */ | |
1053 /* not sure what the difference between 1 and 0 is */ | |
1054 guint8 *md5 = byte_stream_getraw(bs, length); | |
1055 ret = userfunc(od, conn, frame, type, flags, length, md5); | |
1056 free(md5); | |
1057 } break; | |
1058 case 0x0002: { /* available message */ | |
1059 /* there is a second length that is just for the message */ | |
1060 char *msg = byte_stream_getstr(bs, byte_stream_get16(bs)); | |
1061 ret = userfunc(od, conn, frame, msg); | |
1062 free(msg); | |
1063 } break; | |
1064 } | |
1065 } | |
1066 | |
1067 return ret; | |
1068 } | |
1069 | |
1070 static int | |
1071 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
1072 { | |
1073 if (snac->subtype == 0x0003) | |
1074 return hostonline(od, conn, mod, frame, snac, bs); | |
1075 else if (snac->subtype == 0x0005) | |
1076 return redirect(od, conn, mod, frame, snac, bs); | |
1077 else if (snac->subtype == 0x0007) | |
1078 return rateresp(od, conn, mod, frame, snac, bs); | |
1079 else if (snac->subtype == 0x000a) | |
1080 return ratechange(od, conn, mod, frame, snac, bs); | |
1081 else if (snac->subtype == 0x000b) | |
1082 return serverpause(od, conn, mod, frame, snac, bs); | |
1083 else if (snac->subtype == 0x000d) | |
1084 return serverresume(od, conn, mod, frame, snac, bs); | |
1085 else if (snac->subtype == 0x000f) | |
1086 return selfinfo(od, conn, mod, frame, snac, bs); | |
1087 else if (snac->subtype == 0x0010) | |
1088 return evilnotify(od, conn, mod, frame, snac, bs); | |
1089 else if (snac->subtype == 0x0012) | |
1090 return migrate(od, conn, mod, frame, snac, bs); | |
1091 else if (snac->subtype == 0x0013) | |
1092 return motd(od, conn, mod, frame, snac, bs); | |
1093 else if (snac->subtype == 0x0018) | |
1094 return hostversions(od, conn, mod, frame, snac, bs); | |
1095 else if (snac->subtype == 0x001f) | |
1096 return memrequest(od, conn, mod, frame, snac, bs); | |
1097 else if (snac->subtype == 0x0021) | |
1098 return aim_parse_extstatus(od, conn, mod, frame, snac, bs); | |
1099 | |
1100 return 0; | |
1101 } | |
1102 | |
1103 int service_modfirst(OscarData *od, aim_module_t *mod) | |
1104 { | |
1105 mod->family = 0x0001; | |
1106 mod->version = 0x0003; | |
1107 mod->toolid = 0x0110; | |
1108 mod->toolversion = 0x0629; | |
1109 mod->flags = 0; | |
1110 strncpy(mod->name, "oservice", sizeof(mod->name)); | |
1111 mod->snachandler = snachandler; | |
1112 | |
1113 return 0; | |
1114 } |