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