Mercurial > pidgin
annotate libgaim/protocols/oscar/family_oservice.c @ 15090:9cdc8bb39cf2
[gaim-migrate @ 17876]
First stab at attempting to keep track of our rate limiting average
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 02 Dec 2006 10:43:06 +0000 |
parents | 337dfc40a538 |
children | 525607f86cce |
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 */ | |
15085 | 96 aim_srv_setversions(od, conn); |
14192 | 97 |
98 return 1; | |
99 } | |
100 | |
101 /* Subtype 0x0004 - Service request */ | |
15085 | 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 | |
15085 | 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 | |
15085 | 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 * | |
15085 | 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 | |
15086 | 265 static struct rateclass * |
266 rateclass_find(GSList *rateclasses, guint16 id) | |
14192 | 267 { |
15086 | 268 GSList *tmp; |
14192 | 269 |
15086 | 270 for (tmp = rateclasses; tmp != NULL; tmp = tmp->next) |
271 { | |
15090 | 272 struct rateclass *rateclass; |
15086 | 273 rateclass = tmp->data; |
274 if (rateclass->classid == id) | |
275 return rateclass; | |
14192 | 276 } |
277 | |
278 return NULL; | |
279 } | |
280 | |
281 static void | |
15086 | 282 rateclass_addpair(struct rateclass *rateclass, guint16 group, guint16 type) |
14192 | 283 { |
15086 | 284 struct snacpair *snacpair; |
14192 | 285 |
15086 | 286 snacpair = g_new(struct snacpair, 1); |
287 snacpair->group = group; | |
288 snacpair->subtype = type; | |
14192 | 289 |
15086 | 290 rateclass->members = g_slist_prepend(rateclass->members, snacpair); |
14192 | 291 } |
292 | |
293 /* Subtype 0x0007 - Rate Parameters */ | |
294 static int | |
295 rateresp(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
296 { | |
297 guint16 numclasses, i; | |
298 aim_rxcallback_t userfunc; | |
299 | |
300 /* | |
301 * First are the parameters for each rate class. | |
302 */ | |
303 numclasses = byte_stream_get16(bs); | |
15086 | 304 for (i = 0; i < numclasses; i++) |
305 { | |
306 struct rateclass *rateclass; | |
14192 | 307 |
15086 | 308 rateclass = g_new0(struct rateclass, 1); |
14192 | 309 |
15086 | 310 rateclass->classid = byte_stream_get16(bs); |
311 rateclass->windowsize = byte_stream_get32(bs); | |
312 rateclass->clear = byte_stream_get32(bs); | |
313 rateclass->alert = byte_stream_get32(bs); | |
314 rateclass->limit = byte_stream_get32(bs); | |
315 rateclass->disconnect = byte_stream_get32(bs); | |
316 rateclass->current = byte_stream_get32(bs); | |
317 rateclass->max = byte_stream_get32(bs); | |
14192 | 318 |
319 /* | |
320 * The server will send an extra five bytes of parameters | |
321 * depending on the version we advertised in 1/17. If we | |
322 * didn't send 1/17 (evil!), then this will crash and you | |
323 * die, as it will default to the old version but we have | |
324 * the new version hardcoded here. | |
325 */ | |
326 if (mod->version >= 3) | |
15086 | 327 byte_stream_getrawbuf(bs, rateclass->unknown, sizeof(rateclass->unknown)); |
14192 | 328 |
15086 | 329 conn->rateclasses = g_slist_prepend(conn->rateclasses, rateclass); |
14192 | 330 } |
15086 | 331 conn->rateclasses = g_slist_reverse(conn->rateclasses); |
14192 | 332 |
333 /* | |
334 * Then the members of each class. | |
335 */ | |
15086 | 336 for (i = 0; i < numclasses; i++) |
337 { | |
14192 | 338 guint16 classid, count; |
15086 | 339 struct rateclass *rateclass; |
14192 | 340 int j; |
341 | |
342 classid = byte_stream_get16(bs); | |
343 count = byte_stream_get16(bs); | |
344 | |
15086 | 345 rateclass = rateclass_find(conn->rateclasses, classid); |
14192 | 346 |
15086 | 347 for (j = 0; j < count; j++) |
348 { | |
14192 | 349 guint16 group, subtype; |
350 | |
351 group = byte_stream_get16(bs); | |
352 subtype = byte_stream_get16(bs); | |
353 | |
15086 | 354 if (rateclass != NULL) |
355 rateclass_addpair(rateclass, group, subtype); | |
14192 | 356 } |
15086 | 357 rateclass->members = g_slist_reverse(rateclass->members); |
14192 | 358 } |
359 | |
360 /* | |
361 * We don't pass the rate information up to the client, as it really | |
362 * doesn't care. The information is stored in the connection, however | |
15086 | 363 * so that we can do rate limiting management when sending SNACs. |
14192 | 364 */ |
365 | |
366 /* | |
367 * Last step in the conn init procedure is to acknowledge that we | |
368 * agree to these draconian limitations. | |
369 */ | |
15085 | 370 aim_srv_rates_addparam(od, conn); |
14192 | 371 |
372 /* | |
373 * Finally, tell the client it's ready to go... | |
374 */ | |
375 if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE))) | |
376 userfunc(od, conn, frame); | |
377 | |
378 return 1; | |
379 } | |
380 | |
381 /* Subtype 0x0008 - Add Rate Parameter */ | |
382 void | |
15085 | 383 aim_srv_rates_addparam(OscarData *od, FlapConnection *conn) |
14192 | 384 { |
385 FlapFrame *frame; | |
386 aim_snacid_t snacid; | |
15086 | 387 GSList *tmp; |
14192 | 388 |
389 frame = flap_frame_new(od, 0x02, 512); | |
390 | |
391 snacid = aim_cachesnac(od, 0x0001, 0x0008, 0x0000, NULL, 0); | |
392 aim_putsnac(&frame->data, 0x0001, 0x0008, 0x0000, snacid); | |
393 | |
15086 | 394 for (tmp = conn->rateclasses; tmp != NULL; tmp = tmp->next) |
395 { | |
396 struct rateclass *rateclass; | |
397 rateclass = tmp->data; | |
398 byte_stream_put16(&frame->data, rateclass->classid); | |
399 } | |
14192 | 400 |
401 flap_connection_send(conn, frame); | |
402 } | |
403 | |
404 /* Subtype 0x0009 - Delete Rate Parameter */ | |
405 void | |
15085 | 406 aim_srv_rates_delparam(OscarData *od, FlapConnection *conn) |
14192 | 407 { |
408 FlapFrame *frame; | |
409 aim_snacid_t snacid; | |
15086 | 410 GSList *tmp; |
14192 | 411 |
412 frame = flap_frame_new(od, 0x02, 512); | |
413 | |
414 snacid = aim_cachesnac(od, 0x0001, 0x0009, 0x0000, NULL, 0); | |
415 aim_putsnac(&frame->data, 0x0001, 0x0009, 0x0000, snacid); | |
416 | |
15086 | 417 for (tmp = conn->rateclasses; tmp != NULL; tmp = tmp->next) |
418 { | |
419 struct rateclass *rateclass; | |
420 rateclass = tmp->data; | |
421 byte_stream_put16(&frame->data, rateclass->classid); | |
422 } | |
14192 | 423 |
424 flap_connection_send(conn, frame); | |
425 } | |
426 | |
427 /* Subtype 0x000a - Rate Change */ | |
428 static int | |
429 ratechange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
430 { | |
431 int ret = 0; | |
432 aim_rxcallback_t userfunc; | |
15087 | 433 guint16 code, classid; |
434 struct rateclass *rateclass; | |
14192 | 435 |
436 code = byte_stream_get16(bs); | |
15087 | 437 classid = byte_stream_get16(bs); |
438 | |
439 rateclass = rateclass_find(conn->rateclasses, classid); | |
440 if (rateclass == NULL) | |
441 /* This should never really happen */ | |
442 return 0; | |
14192 | 443 |
15087 | 444 rateclass->windowsize = byte_stream_get32(bs); |
445 rateclass->clear = byte_stream_get32(bs); | |
446 rateclass->alert = byte_stream_get32(bs); | |
447 rateclass->limit = byte_stream_get32(bs); | |
448 rateclass->disconnect = byte_stream_get32(bs); | |
449 rateclass->current = byte_stream_get32(bs); | |
450 rateclass->max = byte_stream_get32(bs); | |
14192 | 451 |
452 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
15087 | 453 ret = userfunc(od, conn, frame, code, classid, rateclass->windowsize, rateclass->clear, rateclass->alert, rateclass->limit, rateclass->disconnect, rateclass->current, rateclass->max); |
14192 | 454 |
455 return ret; | |
456 } | |
457 | |
458 /* | |
459 * How Migrations work. | |
460 * | |
461 * The server sends a Server Pause message, which the client should respond to | |
462 * with a Server Pause Ack, which contains the families it needs on this | |
463 * connection. The server will send a Migration Notice with an IP address, and | |
464 * then disconnect. Next the client should open the connection and send the | |
465 * cookie. Repeat the normal login process and pretend this never happened. | |
466 * | |
467 * The Server Pause contains no data. | |
468 * | |
469 */ | |
470 | |
471 /* Subtype 0x000b - Service Pause */ | |
472 static int | |
473 serverpause(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
474 { | |
475 int ret = 0; | |
476 aim_rxcallback_t userfunc; | |
477 | |
478 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
479 ret = userfunc(od, conn, frame); | |
480 | |
481 return ret; | |
482 } | |
483 | |
484 /* | |
485 * Subtype 0x000c - Service Pause Acknowledgement | |
486 * | |
15085 | 487 * It is rather important that aim_srv_sendpauseack() gets called for the exact |
14192 | 488 * same connection that the Server Pause callback was called for, since |
489 * libfaim extracts the data for the SNAC from the connection structure. | |
490 * | |
491 * Of course, if you don't do that, more bad things happen than just what | |
492 * libfaim can cause. | |
493 * | |
494 */ | |
495 void | |
15085 | 496 aim_srv_sendpauseack(OscarData *od, FlapConnection *conn) |
14192 | 497 { |
498 FlapFrame *frame; | |
499 aim_snacid_t snacid; | |
14348 | 500 GSList *cur; |
14192 | 501 |
502 frame = flap_frame_new(od, 0x02, 1024); | |
503 | |
504 snacid = aim_cachesnac(od, 0x0001, 0x000c, 0x0000, NULL, 0); | |
505 aim_putsnac(&frame->data, 0x0001, 0x000c, 0x0000, snacid); | |
506 | |
507 /* | |
508 * This list should have all the groups that the original | |
509 * Host Online / Server Ready said this host supports. And | |
510 * we want them all back after the migration. | |
511 */ | |
512 for (cur = conn->groups; cur != NULL; cur = cur->next) | |
513 byte_stream_put16(&frame->data, GPOINTER_TO_UINT(cur->data)); | |
514 | |
515 flap_connection_send(conn, frame); | |
516 } | |
517 | |
518 /* Subtype 0x000d - Service Resume */ | |
519 static int | |
520 serverresume(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
521 { | |
522 int ret = 0; | |
523 aim_rxcallback_t userfunc; | |
524 | |
525 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
526 ret = userfunc(od, conn, frame); | |
527 | |
528 return ret; | |
529 } | |
530 | |
531 /* Subtype 0x000e - Request self-info */ | |
532 void | |
15085 | 533 aim_srv_reqpersonalinfo(OscarData *od, FlapConnection *conn) |
14192 | 534 { |
535 aim_genericreq_n_snacid(od, conn, 0x0001, 0x000e); | |
536 } | |
537 | |
538 /* Subtype 0x000f - Self User Info */ | |
539 static int | |
540 selfinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
541 { | |
542 int ret = 0; | |
543 aim_rxcallback_t userfunc; | |
544 aim_userinfo_t userinfo; | |
545 | |
546 aim_info_extract(od, bs, &userinfo); | |
547 | |
548 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
549 ret = userfunc(od, conn, frame, &userinfo); | |
550 | |
551 aim_info_free(&userinfo); | |
552 | |
553 return ret; | |
554 } | |
555 | |
556 /* Subtype 0x0010 - Evil Notification */ | |
557 static int | |
558 evilnotify(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
559 { | |
560 int ret = 0; | |
561 aim_rxcallback_t userfunc; | |
562 guint16 newevil; | |
563 aim_userinfo_t userinfo; | |
564 | |
565 memset(&userinfo, 0, sizeof(aim_userinfo_t)); | |
566 | |
567 newevil = byte_stream_get16(bs); | |
568 | |
569 if (byte_stream_empty(bs)) | |
570 aim_info_extract(od, bs, &userinfo); | |
571 | |
572 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
573 ret = userfunc(od, conn, frame, newevil, &userinfo); | |
574 | |
575 aim_info_free(&userinfo); | |
576 | |
577 return ret; | |
578 } | |
579 | |
580 /* | |
581 * Subtype 0x0011 - Idle Notification | |
582 * | |
583 * Should set your current idle time in seconds. Note that this should | |
584 * never be called consecutively with a non-zero idle time. That makes | |
585 * OSCAR do funny things. Instead, just set it once you go idle, and then | |
586 * call it again with zero when you're back. | |
587 * | |
588 */ | |
15085 | 589 void |
14192 | 590 aim_srv_setidle(OscarData *od, guint32 idletime) |
591 { | |
592 FlapConnection *conn; | |
593 | |
15085 | 594 conn = flap_connection_findbygroup(od, SNAC_FAMILY_BOS); |
595 aim_genericreq_l(od, conn, 0x0001, 0x0011, &idletime); | |
14192 | 596 } |
597 | |
598 /* | |
599 * Subtype 0x0012 - Service Migrate | |
600 * | |
601 * This is the final SNAC sent on the original connection during a migration. | |
602 * It contains the IP and cookie used to connect to the new server, and | |
603 * optionally a list of the SNAC groups being migrated. | |
604 * | |
605 */ | |
606 static int | |
607 migrate(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
608 { | |
609 aim_rxcallback_t userfunc; | |
610 int ret = 0; | |
611 guint16 groupcount, i; | |
612 aim_tlvlist_t *tl; | |
613 char *ip = NULL; | |
614 aim_tlv_t *cktlv; | |
615 | |
616 /* | |
617 * Apparently there's some fun stuff that can happen right here. The | |
618 * migration can actually be quite selective about what groups it | |
619 * moves to the new server. When not all the groups for a connection | |
620 * are migrated, or they are all migrated but some groups are moved | |
621 * to a different server than others, it is called a bifurcated | |
622 * migration. | |
623 * | |
624 * Let's play dumb and not support that. | |
625 * | |
626 */ | |
627 groupcount = byte_stream_get16(bs); | |
628 for (i = 0; i < groupcount; i++) { | |
629 guint16 group; | |
630 | |
631 group = byte_stream_get16(bs); | |
632 | |
633 gaim_debug_misc("oscar", "bifurcated migration unsupported -- group 0x%04x\n", group); | |
634 } | |
635 | |
636 tl = aim_tlvlist_read(bs); | |
637 | |
638 if (aim_tlv_gettlv(tl, 0x0005, 1)) | |
639 ip = aim_tlv_getstr(tl, 0x0005, 1); | |
640 | |
641 cktlv = aim_tlv_gettlv(tl, 0x0006, 1); | |
642 | |
643 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
644 ret = userfunc(od, conn, frame, ip, cktlv ? cktlv->value : NULL); | |
645 | |
646 aim_tlvlist_free(&tl); | |
647 free(ip); | |
648 | |
649 return ret; | |
650 } | |
651 | |
652 /* Subtype 0x0013 - Message of the Day */ | |
653 static int | |
654 motd(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
655 { | |
656 aim_rxcallback_t userfunc; | |
657 char *msg = NULL; | |
658 int ret = 0; | |
659 aim_tlvlist_t *tlvlist; | |
660 guint16 id; | |
661 | |
662 /* | |
663 * Code. | |
664 * | |
665 * Valid values: | |
666 * 1 Mandatory upgrade | |
667 * 2 Advisory upgrade | |
668 * 3 System bulletin | |
669 * 4 Nothing's wrong ("top o the world" -- normal) | |
670 * 5 Lets-break-something. | |
671 * | |
672 */ | |
673 id = byte_stream_get16(bs); | |
674 | |
675 /* | |
676 * TLVs follow | |
677 */ | |
678 tlvlist = aim_tlvlist_read(bs); | |
679 | |
680 msg = aim_tlv_getstr(tlvlist, 0x000b, 1); | |
681 | |
682 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
683 ret = userfunc(od, conn, frame, id, msg); | |
684 | |
685 free(msg); | |
686 | |
687 aim_tlvlist_free(&tlvlist); | |
688 | |
689 return ret; | |
690 } | |
691 | |
692 /* | |
693 * Subtype 0x0014 - Set privacy flags | |
694 * | |
695 * Normally 0x03. | |
696 * | |
697 * Bit 1: Allows other AIM users to see how long you've been idle. | |
698 * Bit 2: Allows other AIM users to see how long you've been a member. | |
699 * | |
700 */ | |
15085 | 701 void |
702 aim_srv_setprivacyflags(OscarData *od, FlapConnection *conn, guint32 flags) | |
14192 | 703 { |
15085 | 704 aim_genericreq_l(od, conn, 0x0001, 0x0014, &flags); |
14192 | 705 } |
706 | |
707 /* | |
708 * Subtype 0x0016 - No-op | |
709 * | |
710 * WinAIM sends these every 4min or so to keep the connection alive. Its not | |
711 * really necessary. | |
712 * | |
713 * Wha? No? Since when? I think WinAIM sends an empty channel 5 | |
714 * FLAP as a no-op... | |
715 */ | |
15085 | 716 void |
717 aim_srv_nop(OscarData *od, FlapConnection *conn) | |
14192 | 718 { |
15085 | 719 aim_genericreq_n(od, conn, 0x0001, 0x0016); |
14192 | 720 } |
721 | |
722 /* | |
723 * Subtype 0x0017 - Set client versions | |
724 * | |
725 * If you've seen the clientonline/clientready SNAC you're probably | |
726 * wondering what the point of this one is. And that point seems to be | |
727 * that the versions in the client online SNAC are sent too late for the | |
728 * server to be able to use them to change the protocol for the earlier | |
729 * login packets (client versions are sent right after Host Online is | |
730 * received, but client online versions aren't sent until quite a bit later). | |
731 * We can see them already making use of this by changing the format of | |
732 * the rate information based on what version of group 1 we advertise here. | |
733 * | |
734 */ | |
735 void | |
15085 | 736 aim_srv_setversions(OscarData *od, FlapConnection *conn) |
14192 | 737 { |
738 FlapFrame *frame; | |
739 aim_snacid_t snacid; | |
14348 | 740 GSList *cur; |
14192 | 741 |
742 frame = flap_frame_new(od, 0x02, 1152); | |
743 | |
744 snacid = aim_cachesnac(od, 0x0001, 0x0017, 0x0000, NULL, 0); | |
745 aim_putsnac(&frame->data, 0x0001, 0x0017, 0x0000, snacid); | |
746 | |
747 /* | |
748 * Send only the versions that the server cares about (that it | |
749 * marked as supporting in the server ready SNAC). | |
750 */ | |
751 for (cur = conn->groups; cur != NULL; cur = cur->next) | |
752 { | |
753 aim_module_t *mod; | |
754 | |
755 if ((mod = aim__findmodulebygroup(od, GPOINTER_TO_UINT(cur->data)))) | |
756 { | |
757 byte_stream_put16(&frame->data, mod->family); | |
758 byte_stream_put16(&frame->data, mod->version); | |
759 } | |
760 } | |
761 | |
762 flap_connection_send(conn, frame); | |
763 } | |
764 | |
765 /* Subtype 0x0018 - Host versions */ | |
766 static int | |
767 hostversions(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
768 { | |
769 int vercount; | |
770 guint8 *versions; | |
771 | |
772 /* This is frivolous. (Thank you SmarterChild.) */ | |
773 vercount = byte_stream_empty(bs)/4; | |
774 versions = byte_stream_getraw(bs, byte_stream_empty(bs)); | |
775 free(versions); | |
776 | |
777 /* | |
778 * Now request rates. | |
779 */ | |
15085 | 780 aim_srv_reqrates(od, conn); |
14192 | 781 |
782 return 1; | |
783 } | |
784 | |
785 /* | |
786 * Subtype 0x001e - Set various account settings (mostly ICQ related). | |
787 * | |
788 * These settings are transient, not server-stored (i.e. they only | |
789 * apply to this session, and must be re-set the next time you sign | |
790 * on). | |
791 * | |
792 * You can set your ICQ status (available, away, do not disturb, | |
793 * etc.), or whether your IP address should be hidden or not, or | |
794 * if your status is visible on ICQ web sites, and you can set | |
795 * your IP address info and what not. | |
796 * | |
797 * These are the same TLVs seen in user info. You can | |
798 * also set 0x0008 and 0x000c. | |
14552 | 799 * |
800 * TODO: Combine this with the function below. | |
14192 | 801 */ |
802 int | |
15085 | 803 aim_srv_setextstatus(OscarData *od, guint32 status) |
14192 | 804 { |
805 FlapConnection *conn; | |
806 FlapFrame *frame; | |
807 aim_snacid_t snacid; | |
808 aim_tlvlist_t *tl = NULL; | |
809 guint32 data; | |
810 | |
811 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM))) | |
812 return -EINVAL; | |
813 | |
814 data = AIM_ICQ_STATE_HIDEIP | AIM_ICQ_STATE_DIRECTREQUIREAUTH | status; | |
815 | |
816 frame = flap_frame_new(od, 0x02, 10 + 8); | |
817 | |
818 snacid = aim_cachesnac(od, 0x0001, 0x001e, 0x0000, NULL, 0); | |
819 aim_putsnac(&frame->data, 0x0001, 0x001e, 0x0000, snacid); | |
820 | |
821 aim_tlvlist_add_32(&tl, 0x0006, data); | |
822 #if 0 | |
823 aim_tlvlist_add_raw(&tl, 0x000c, 0x0025, chunk_of_x25_bytes_with_ip_address_etc); | |
824 aim_tlvlist_add_raw(&tl, 0x0011, 0x0005, unknown 0x01 61 10 f6 41); | |
825 aim_tlvlist_add_16(&tl, 0x0012, unknown 0x00 00); | |
826 #endif | |
827 aim_tlvlist_write(&frame->data, &tl); | |
828 aim_tlvlist_free(&tl); | |
829 | |
830 flap_connection_send(conn, frame); | |
831 | |
832 return 0; | |
833 } | |
834 | |
835 /* | |
836 * Subtype 0x001e - Extended Status. | |
837 * | |
838 * Sets your "available" message. This is currently only supported by iChat | |
839 * and Gaim. | |
840 * | |
841 * These are the same TLVs seen in user info. You can | |
842 * also set 0x0008 and 0x000c. | |
14552 | 843 * |
844 * TODO: Combine this with the above function. | |
14192 | 845 */ |
846 int | |
847 aim_srv_setstatusmsg(OscarData *od, const char *msg) | |
848 { | |
849 FlapConnection *conn; | |
850 FlapFrame *frame; | |
851 aim_snacid_t snacid; | |
14552 | 852 int msglen; |
14192 | 853 |
854 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004))) | |
855 return -EINVAL; | |
856 | |
14552 | 857 if (msg == NULL) |
858 msglen = 0; | |
859 else | |
860 msglen = strlen(msg); | |
14192 | 861 |
14552 | 862 frame = flap_frame_new(od, 0x02, 10 + 4 + msglen + 8); |
14192 | 863 |
14552 | 864 snacid = aim_cachesnac(od, 0x0001, 0x001e, 0x0000, NULL, 0); |
865 aim_putsnac(&frame->data, 0x0001, 0x001e, 0x0000, snacid); | |
866 | |
867 byte_stream_put16(&frame->data, 0x001d); /* userinfo TLV type */ | |
868 byte_stream_put16(&frame->data, msglen + 8); /* total length of userinfo TLV data */ | |
869 byte_stream_put16(&frame->data, 0x0002); | |
870 byte_stream_put8(&frame->data, 0x04); | |
871 byte_stream_put8(&frame->data, msglen+4); | |
872 byte_stream_put16(&frame->data, msglen); | |
873 if (msglen > 0) | |
14192 | 874 byte_stream_putstr(&frame->data, msg); |
14552 | 875 byte_stream_put16(&frame->data, 0x0000); |
14192 | 876 |
877 flap_connection_send(conn, frame); | |
878 | |
879 return 0; | |
880 } | |
881 | |
882 /* | |
883 * Starting this past week (26 Mar 2001, say), AOL has started sending | |
884 * this nice little extra SNAC. AFAIK, it has never been used until now. | |
885 * | |
886 * The request contains eight bytes. The first four are an offset, the | |
887 * second four are a length. | |
888 * | |
889 * The offset is an offset into aim.exe when it is mapped during execution | |
890 * on Win32. So far, AOL has only been requesting bytes in static regions | |
891 * of memory. (I won't put it past them to start requesting data in | |
892 * less static regions -- regions that are initialized at run time, but still | |
893 * before the client receives this request.) | |
894 * | |
895 * When the client receives the request, it adds it to the current ds | |
896 * (0x00400000) and dereferences it, copying the data into a buffer which | |
897 * it then runs directly through the MD5 hasher. The 16 byte output of | |
898 * the hash is then sent back to the server. | |
899 * | |
900 * If the client does not send any data back, or the data does not match | |
901 * the data that the specific client should have, the client will get the | |
902 * following message from "AOL Instant Messenger": | |
903 * "You have been disconnected from the AOL Instant Message Service (SM) | |
904 * for accessing the AOL network using unauthorized software. You can | |
905 * download a FREE, fully featured, and authorized client, here | |
906 * http://www.aol.com/aim/download2.html" | |
907 * The connection is then closed, receiving disconnect code 1, URL | |
908 * http://www.aim.aol.com/errors/USER_LOGGED_OFF_NEW_LOGIN.html. | |
909 * | |
910 * Note, however, that numerous inconsistencies can cause the above error, | |
911 * not just sending back a bad hash. Do not immediatly suspect this code | |
912 * if you get disconnected. AOL and the open/free software community have | |
913 * played this game for a couple years now, generating the above message | |
914 * on numerous ocassions. | |
915 * | |
916 * Anyway, neener. We win again. | |
917 * | |
918 */ | |
919 /* Subtype 0x001f - Client verification */ | |
920 static int | |
921 memrequest(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
922 { | |
923 int ret = 0; | |
924 aim_rxcallback_t userfunc; | |
925 guint32 offset, len; | |
926 aim_tlvlist_t *list; | |
927 char *modname; | |
928 | |
929 offset = byte_stream_get32(bs); | |
930 len = byte_stream_get32(bs); | |
931 list = aim_tlvlist_read(bs); | |
932 | |
933 modname = aim_tlv_getstr(list, 0x0001, 1); | |
934 | |
935 gaim_debug_info("oscar", "Got memory request for data at 0x%08lx (%d bytes) of requested %s\n", offset, len, modname ? modname : "aim.exe"); | |
936 | |
937 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | |
938 ret = userfunc(od, conn, frame, offset, len, modname); | |
939 | |
940 free(modname); | |
941 aim_tlvlist_free(&list); | |
942 | |
943 return ret; | |
944 } | |
945 | |
946 /* Subtype 0x0020 - Client verification reply */ | |
947 int | |
948 aim_sendmemblock(OscarData *od, FlapConnection *conn, guint32 offset, guint32 len, const guint8 *buf, guint8 flag) | |
949 { | |
950 FlapFrame *frame; | |
951 aim_snacid_t snacid; | |
952 | |
953 if (!od || !conn) | |
954 return -EINVAL; | |
955 | |
956 frame = flap_frame_new(od, 0x02, 10+2+16); | |
957 | |
958 snacid = aim_cachesnac(od, 0x0001, 0x0020, 0x0000, NULL, 0); | |
959 | |
960 aim_putsnac(&frame->data, 0x0001, 0x0020, 0x0000, snacid); | |
961 byte_stream_put16(&frame->data, 0x0010); /* md5 is always 16 bytes */ | |
962 | |
963 if ((flag == AIM_SENDMEMBLOCK_FLAG_ISHASH) && buf && (len == 0x10)) { /* we're getting a hash */ | |
964 | |
965 byte_stream_putraw(&frame->data, buf, 0x10); | |
966 | |
967 } else if (buf && (len > 0)) { /* use input buffer */ | |
968 GaimCipher *cipher; | |
969 GaimCipherContext *context; | |
970 guchar digest[16]; | |
971 | |
972 cipher = gaim_ciphers_find_cipher("md5"); | |
973 | |
974 context = gaim_cipher_context_new(cipher, NULL); | |
975 gaim_cipher_context_append(context, buf, len); | |
976 gaim_cipher_context_digest(context, 16, digest, NULL); | |
977 gaim_cipher_context_destroy(context); | |
978 | |
979 byte_stream_putraw(&frame->data, digest, 0x10); | |
980 | |
981 } else if (len == 0) { /* no length, just hash NULL (buf is optional) */ | |
982 GaimCipher *cipher; | |
983 GaimCipherContext *context; | |
984 guchar digest[16]; | |
985 guint8 nil = '\0'; | |
986 | |
987 /* | |
988 * I'm not sure if we really need the empty append with the | |
989 * new MD5 functions, so I'll leave it in, just in case. | |
990 */ | |
991 cipher = gaim_ciphers_find_cipher("md5"); | |
992 | |
993 context = gaim_cipher_context_new(cipher, NULL); | |
994 gaim_cipher_context_append(context, &nil, 0); | |
995 gaim_cipher_context_digest(context, 16, digest, NULL); | |
996 gaim_cipher_context_destroy(context); | |
997 | |
998 byte_stream_putraw(&frame->data, digest, 0x10); | |
999 | |
1000 } else { | |
1001 | |
1002 /* | |
1003 * This data is correct for AIM 3.5.1670. | |
1004 * | |
1005 * Using these blocks is as close to "legal" as you can get | |
1006 * without using an AIM binary. | |
1007 * | |
1008 */ | |
1009 if ((offset == 0x03ffffff) && (len == 0x03ffffff)) { | |
1010 | |
1011 #if 1 /* with "AnrbnrAqhfzcd" */ | |
1012 byte_stream_put32(&frame->data, 0x44a95d26); | |
1013 byte_stream_put32(&frame->data, 0xd2490423); | |
1014 byte_stream_put32(&frame->data, 0x93b8821f); | |
1015 byte_stream_put32(&frame->data, 0x51c54b01); | |
1016 #else /* no filename */ | |
1017 byte_stream_put32(&frame->data, 0x1df8cbae); | |
1018 byte_stream_put32(&frame->data, 0x5523b839); | |
1019 byte_stream_put32(&frame->data, 0xa0e10db3); | |
1020 byte_stream_put32(&frame->data, 0xa46d3b39); | |
1021 #endif | |
1022 | |
1023 } else | |
1024 gaim_debug_warning("oscar", "sendmemblock: unknown hash request\n"); | |
1025 | |
1026 } | |
1027 | |
1028 flap_connection_send(conn, frame); | |
1029 | |
1030 return 0; | |
1031 } | |
1032 | |
1033 /* | |
1034 * Subtype 0x0021 - Receive our extended status | |
1035 * | |
1036 * This is used for iChat's "available" messages, and maybe ICQ extended | |
1037 * status messages? It's also used to tell the client whether or not it | |
1038 * needs to upload an SSI buddy icon... who engineers this stuff, anyway? | |
1039 */ | |
1040 static int | |
1041 aim_parse_extstatus(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
1042 { | |
1043 int ret = 0; | |
1044 aim_rxcallback_t userfunc; | |
1045 guint16 type; | |
1046 guint8 flags, length; | |
1047 | |
1048 type = byte_stream_get16(bs); | |
1049 flags = byte_stream_get8(bs); | |
1050 length = byte_stream_get8(bs); | |
1051 | |
1052 /* | |
1053 * A flag of 0x01 could mean "this is the checksum we have for you" | |
1054 * A flag of 0x40 could mean "I don't have your icon, upload it" | |
1055 */ | |
1056 | |
1057 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) { | |
1058 switch (type) { | |
1059 case 0x0000: | |
1060 case 0x0001: { /* buddy icon checksum */ | |
1061 /* not sure what the difference between 1 and 0 is */ | |
1062 guint8 *md5 = byte_stream_getraw(bs, length); | |
1063 ret = userfunc(od, conn, frame, type, flags, length, md5); | |
1064 free(md5); | |
1065 } break; | |
1066 case 0x0002: { /* available message */ | |
1067 /* there is a second length that is just for the message */ | |
1068 char *msg = byte_stream_getstr(bs, byte_stream_get16(bs)); | |
1069 ret = userfunc(od, conn, frame, msg); | |
1070 free(msg); | |
1071 } break; | |
1072 } | |
1073 } | |
1074 | |
1075 return ret; | |
1076 } | |
1077 | |
1078 static int | |
1079 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | |
1080 { | |
1081 if (snac->subtype == 0x0003) | |
1082 return hostonline(od, conn, mod, frame, snac, bs); | |
1083 else if (snac->subtype == 0x0005) | |
1084 return redirect(od, conn, mod, frame, snac, bs); | |
1085 else if (snac->subtype == 0x0007) | |
1086 return rateresp(od, conn, mod, frame, snac, bs); | |
1087 else if (snac->subtype == 0x000a) | |
1088 return ratechange(od, conn, mod, frame, snac, bs); | |
1089 else if (snac->subtype == 0x000b) | |
1090 return serverpause(od, conn, mod, frame, snac, bs); | |
1091 else if (snac->subtype == 0x000d) | |
1092 return serverresume(od, conn, mod, frame, snac, bs); | |
1093 else if (snac->subtype == 0x000f) | |
1094 return selfinfo(od, conn, mod, frame, snac, bs); | |
1095 else if (snac->subtype == 0x0010) | |
1096 return evilnotify(od, conn, mod, frame, snac, bs); | |
1097 else if (snac->subtype == 0x0012) | |
1098 return migrate(od, conn, mod, frame, snac, bs); | |
1099 else if (snac->subtype == 0x0013) | |
1100 return motd(od, conn, mod, frame, snac, bs); | |
1101 else if (snac->subtype == 0x0018) | |
1102 return hostversions(od, conn, mod, frame, snac, bs); | |
1103 else if (snac->subtype == 0x001f) | |
1104 return memrequest(od, conn, mod, frame, snac, bs); | |
1105 else if (snac->subtype == 0x0021) | |
1106 return aim_parse_extstatus(od, conn, mod, frame, snac, bs); | |
1107 | |
1108 return 0; | |
1109 } | |
1110 | |
1111 int service_modfirst(OscarData *od, aim_module_t *mod) | |
1112 { | |
1113 mod->family = 0x0001; | |
1114 mod->version = 0x0003; | |
1115 mod->toolid = 0x0110; | |
1116 mod->toolversion = 0x0629; | |
1117 mod->flags = 0; | |
1118 strncpy(mod->name, "oservice", sizeof(mod->name)); | |
1119 mod->snachandler = snachandler; | |
1120 | |
1121 return 0; | |
1122 } |