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