Mercurial > pidgin
annotate src/protocols/oscar/service.c @ 2734:9fc65bb80596
[gaim-migrate @ 2747]
it's 6am
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Sat, 17 Nov 2001 13:57:30 +0000 |
| parents | 441b84ab7f4e |
| children | 9467e4ee81be |
| rev | line source |
|---|---|
| 2703 | 1 /* |
| 2 * Group 1. This is a very special group. All connections support | |
| 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 | |
| 12 /* Client Online (group 1, subtype 2) */ | |
| 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 /* | |
| 51 * Host Online (group 1, type 3) | |
| 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 | |
| 94 /* Service request (group 1, type 4) */ | |
| 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 | |
| 100 /* Redirect (group 1, type 5) */ | |
| 101 static int redirect(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 102 { | |
| 103 int serviceid; | |
| 104 fu8_t *cookie; | |
| 105 char *ip; | |
| 106 aim_rxcallback_t userfunc; | |
| 107 aim_tlvlist_t *tlvlist; | |
| 108 char *chathack = NULL; | |
| 109 int chathackex = 0; | |
| 110 int ret = 0; | |
| 111 | |
| 112 tlvlist = aim_readtlvchain(bs); | |
| 113 | |
| 114 if (!aim_gettlv(tlvlist, 0x000d, 1) || | |
| 115 !aim_gettlv(tlvlist, 0x0005, 1) || | |
| 116 !aim_gettlv(tlvlist, 0x0006, 1)) { | |
| 117 aim_freetlvchain(&tlvlist); | |
| 118 return 0; | |
| 119 } | |
| 120 | |
| 121 serviceid = aim_gettlv16(tlvlist, 0x000d, 1); | |
| 122 ip = aim_gettlv_str(tlvlist, 0x0005, 1); | |
| 123 cookie = aim_gettlv_str(tlvlist, 0x0006, 1); | |
| 124 | |
| 125 /* | |
| 126 * Chat hack. | |
| 127 */ | |
| 128 if ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) { | |
| 129 chathack = sess->pendingjoin; | |
| 130 chathackex = sess->pendingjoinexchange; | |
| 131 sess->pendingjoin = NULL; | |
| 132 sess->pendingjoinexchange = 0; | |
| 133 } | |
| 134 | |
| 135 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 136 ret = userfunc(sess, rx, serviceid, ip, cookie, chathack, chathackex); | |
| 137 | |
| 138 free(ip); | |
| 139 free(cookie); | |
| 140 free(chathack); | |
| 141 | |
| 142 aim_freetlvchain(&tlvlist); | |
| 143 | |
| 144 return ret; | |
| 145 } | |
| 146 | |
| 147 /* Request Rate Information. (group 1, type 6) */ | |
| 148 faim_internal int aim_reqrates(aim_session_t *sess, aim_conn_t *conn) | |
| 149 { | |
| 150 return aim_genericreq_n(sess, conn, 0x0001, 0x0006); | |
| 151 } | |
| 152 | |
| 153 /* | |
| 154 * OSCAR defines several 'rate classes'. Each class has seperate | |
| 155 * rate limiting properties (limit level, alert level, disconnect | |
| 156 * level, etc), and a set of SNAC family/type pairs associated with | |
| 157 * it. The rate classes, their limiting properties, and the definitions | |
| 158 * of which SNACs are belong to which class, are defined in the | |
| 159 * Rate Response packet at login to each host. | |
| 160 * | |
| 161 * Logically, all rate offenses within one class count against further | |
| 162 * offenses for other SNACs in the same class (ie, sending messages | |
| 163 * too fast will limit the number of user info requests you can send, | |
| 164 * since those two SNACs are in the same rate class). | |
| 165 * | |
| 166 * Since the rate classes are defined dynamically at login, the values | |
| 167 * below may change. But they seem to be fairly constant. | |
| 168 * | |
| 169 * Currently, BOS defines five rate classes, with the commonly used | |
| 170 * members as follows... | |
| 171 * | |
| 172 * Rate class 0x0001: | |
| 173 * - Everything thats not in any of the other classes | |
| 174 * | |
| 175 * Rate class 0x0002: | |
| 176 * - Buddy list add/remove | |
| 177 * - Permit list add/remove | |
| 178 * - Deny list add/remove | |
| 179 * | |
| 180 * Rate class 0x0003: | |
| 181 * - User information requests | |
| 182 * - Outgoing ICBMs | |
| 183 * | |
| 184 * Rate class 0x0004: | |
| 185 * - A few unknowns: 2/9, 2/b, and f/2 | |
| 186 * | |
| 187 * Rate class 0x0005: | |
| 188 * - Chat room create | |
| 189 * - Outgoing chat ICBMs | |
| 190 * | |
| 191 * The only other thing of note is that class 5 (chat) has slightly looser | |
| 192 * limiting properties than class 3 (normal messages). But thats just a | |
| 193 * small bit of trivia for you. | |
| 194 * | |
| 195 * The last thing that needs to be learned about the rate limiting | |
| 196 * system is how the actual numbers relate to the passing of time. This | |
| 197 * seems to be a big mystery. | |
| 198 * | |
| 199 */ | |
| 200 | |
| 201 static void rc_addclass(struct rateclass **head, struct rateclass *inrc) | |
| 202 { | |
| 203 struct rateclass *rc, *rc2; | |
| 204 | |
| 205 if (!(rc = malloc(sizeof(struct rateclass)))) | |
| 206 return; | |
| 207 | |
| 208 memcpy(rc, inrc, sizeof(struct rateclass)); | |
| 209 rc->next = NULL; | |
| 210 | |
| 211 for (rc2 = *head; rc2 && rc2->next; rc2 = rc2->next) | |
| 212 ; | |
| 213 | |
| 214 if (!rc2) | |
| 215 *head = rc; | |
| 216 else | |
| 217 rc2->next = rc; | |
| 218 | |
| 219 return; | |
| 220 } | |
| 221 | |
| 222 static struct rateclass *rc_findclass(struct rateclass **head, fu16_t id) | |
| 223 { | |
| 224 struct rateclass *rc; | |
| 225 | |
| 226 for (rc = *head; rc; rc = rc->next) { | |
| 227 if (rc->classid == id) | |
| 228 return rc; | |
| 229 } | |
| 230 | |
| 231 return NULL; | |
| 232 } | |
| 233 | |
| 234 static void rc_addpair(struct rateclass *rc, fu16_t group, fu16_t type) | |
| 235 { | |
| 236 struct snacpair *sp, *sp2; | |
| 237 | |
| 238 if (!(sp = malloc(sizeof(struct snacpair)))) | |
| 239 return; | |
| 240 memset(sp, 0, sizeof(struct snacpair)); | |
| 241 | |
| 242 sp->group = group; | |
| 243 sp->subtype = type; | |
| 244 sp->next = NULL; | |
| 245 | |
| 246 for (sp2 = rc->members; sp2 && sp2->next; sp2 = sp2->next) | |
| 247 ; | |
| 248 | |
| 249 if (!sp2) | |
| 250 rc->members = sp; | |
| 251 else | |
| 252 sp2->next = sp; | |
| 253 | |
| 254 return; | |
| 255 } | |
| 256 | |
| 257 /* Rate Parameters (group 1, type 7) */ | |
| 258 static int rateresp(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 259 { | |
| 260 aim_conn_inside_t *ins = (aim_conn_inside_t *)rx->conn->inside; | |
| 261 fu16_t numclasses, i; | |
| 262 aim_rxcallback_t userfunc; | |
| 263 | |
| 264 | |
| 265 /* | |
| 266 * First are the parameters for each rate class. | |
| 267 */ | |
| 268 numclasses = aimbs_get16(bs); | |
| 269 for (i = 0; i < numclasses; i++) { | |
| 270 struct rateclass rc; | |
| 271 | |
| 272 memset(&rc, 0, sizeof(struct rateclass)); | |
| 273 | |
| 274 rc.classid = aimbs_get16(bs); | |
| 275 rc.windowsize = aimbs_get32(bs); | |
| 276 rc.clear = aimbs_get32(bs); | |
| 277 rc.alert = aimbs_get32(bs); | |
| 278 rc.limit = aimbs_get32(bs); | |
| 279 rc.disconnect = aimbs_get32(bs); | |
| 280 rc.current = aimbs_get32(bs); | |
| 281 rc.max = aimbs_get32(bs); | |
| 282 | |
| 283 /* | |
| 284 * The server will send an extra five bytes of parameters | |
| 285 * depending on the version we advertised in 1/17. If we | |
| 286 * didn't send 1/17 (evil!), then this will crash and you | |
| 287 * die, as it will default to the old version but we have | |
| 288 * the new version hardcoded here. | |
| 289 */ | |
| 290 if (mod->version >= 3) | |
| 291 aimbs_getrawbuf(bs, rc.unknown, sizeof(rc.unknown)); | |
| 292 | |
|
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
293 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
|
294 |
| 2703 | 295 rc_addclass(&ins->rates, &rc); |
| 296 } | |
| 297 | |
| 298 /* | |
| 299 * Then the members of each class. | |
| 300 */ | |
| 301 for (i = 0; i < numclasses; i++) { | |
| 302 fu16_t classid, count; | |
| 303 struct rateclass *rc; | |
| 304 int j; | |
| 305 | |
| 306 classid = aimbs_get16(bs); | |
| 307 count = aimbs_get16(bs); | |
| 308 | |
| 309 rc = rc_findclass(&ins->rates, classid); | |
| 310 | |
| 311 for (j = 0; j < count; j++) { | |
| 312 fu16_t group, subtype; | |
| 313 | |
| 314 group = aimbs_get16(bs); | |
| 315 subtype = aimbs_get16(bs); | |
| 316 | |
| 317 if (rc) | |
| 318 rc_addpair(rc, group, subtype); | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 /* | |
| 323 * We don't pass the rate information up to the client, as it really | |
| 324 * doesn't care. The information is stored in the connection, however | |
| 325 * so that we can do more fun stuff later (not really). | |
| 326 */ | |
| 327 | |
| 328 /* | |
| 329 * Last step in the conn init procedure is to acknowledge that we | |
| 330 * agree to these draconian limitations. | |
| 331 */ | |
| 332 aim_rates_addparam(sess, rx->conn); | |
| 333 | |
| 334 /* | |
| 335 * Finally, tell the client it's ready to go... | |
| 336 */ | |
| 337 if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE))) | |
| 338 userfunc(sess, rx); | |
| 339 | |
| 340 | |
| 341 return 1; | |
| 342 } | |
| 343 | |
| 344 /* Add Rate Parameter (group 1, type 8) */ | |
| 345 faim_internal int aim_rates_addparam(aim_session_t *sess, aim_conn_t *conn) | |
| 346 { | |
| 347 aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside; | |
| 348 aim_frame_t *fr; | |
| 349 aim_snacid_t snacid; | |
| 350 struct rateclass *rc; | |
| 351 | |
| 352 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512))) | |
| 353 return -ENOMEM; | |
| 354 | |
| 355 snacid = aim_cachesnac(sess, 0x0001, 0x0008, 0x0000, NULL, 0); | |
| 356 aim_putsnac(&fr->data, 0x0001, 0x0008, 0x0000, snacid); | |
| 357 | |
| 358 for (rc = ins->rates; rc; rc = rc->next) | |
| 359 aimbs_put16(&fr->data, rc->classid); | |
| 360 | |
| 361 aim_tx_enqueue(sess, fr); | |
| 362 | |
| 363 return 0; | |
| 364 } | |
| 365 | |
| 366 /* Delete Rate Parameter (group 1, type 9) */ | |
| 367 faim_internal int aim_rates_delparam(aim_session_t *sess, aim_conn_t *conn) | |
| 368 { | |
| 369 aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside; | |
| 370 aim_frame_t *fr; | |
| 371 aim_snacid_t snacid; | |
| 372 struct rateclass *rc; | |
| 373 | |
| 374 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512))) | |
| 375 return -ENOMEM; | |
| 376 | |
| 377 snacid = aim_cachesnac(sess, 0x0001, 0x0009, 0x0000, NULL, 0); | |
| 378 aim_putsnac(&fr->data, 0x0001, 0x0009, 0x0000, snacid); | |
| 379 | |
| 380 for (rc = ins->rates; rc; rc = rc->next) | |
| 381 aimbs_put16(&fr->data, rc->classid); | |
| 382 | |
| 383 aim_tx_enqueue(sess, fr); | |
| 384 | |
| 385 return 0; | |
| 386 } | |
| 387 | |
| 388 /* Rate Change (group 1, type 0x0a) */ | |
| 389 static int ratechange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 390 { | |
| 391 aim_rxcallback_t userfunc; | |
| 392 fu16_t code, rateclass; | |
| 393 fu32_t currentavg, maxavg, windowsize, clear, alert, limit, disconnect; | |
| 394 | |
| 395 code = aimbs_get16(bs); | |
| 396 rateclass = aimbs_get16(bs); | |
| 397 | |
| 398 windowsize = aimbs_get32(bs); | |
| 399 clear = aimbs_get32(bs); | |
| 400 alert = aimbs_get32(bs); | |
| 401 limit = aimbs_get32(bs); | |
| 402 disconnect = aimbs_get32(bs); | |
| 403 currentavg = aimbs_get32(bs); | |
| 404 maxavg = aimbs_get32(bs); | |
| 405 | |
| 406 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 407 return userfunc(sess, rx, code, rateclass, windowsize, clear, alert, limit, disconnect, currentavg, maxavg); | |
| 408 | |
| 409 return 0; | |
| 410 } | |
| 411 | |
| 412 /* | |
| 413 * How Migrations work. | |
| 414 * | |
| 415 * The server sends a Server Pause message, which the client should respond to | |
| 416 * with a Server Pause Ack, which contains the families it needs on this | |
| 417 * connection. The server will send a Migration Notice with an IP address, and | |
| 418 * then disconnect. Next the client should open the connection and send the | |
| 419 * cookie. Repeat the normal login process and pretend this never happened. | |
| 420 * | |
| 421 * The Server Pause contains no data. | |
| 422 * | |
| 423 */ | |
| 424 | |
| 425 /* Service Pause (group 1, type 0x0b) */ | |
| 426 static int serverpause(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 427 { | |
| 428 aim_rxcallback_t userfunc; | |
| 429 | |
| 430 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 431 return userfunc(sess, rx); | |
| 432 | |
| 433 return 0; | |
| 434 } | |
| 435 | |
| 436 /* | |
| 437 * Service Pause Acknowledgement (group 1, type 0x0c) | |
| 438 * | |
| 439 * It is rather important that aim_sendpauseack() gets called for the exact | |
| 440 * same connection that the Server Pause callback was called for, since | |
| 441 * libfaim extracts the data for the SNAC from the connection structure. | |
| 442 * | |
| 443 * Of course, if you don't do that, more bad things happen than just what | |
| 444 * libfaim can cause. | |
| 445 * | |
| 446 */ | |
| 447 faim_export int aim_sendpauseack(aim_session_t *sess, aim_conn_t *conn) | |
| 448 { | |
| 449 aim_frame_t *fr; | |
| 450 aim_snacid_t snacid; | |
| 451 aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside; | |
| 452 struct snacgroup *sg; | |
| 453 | |
| 454 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1024))) | |
| 455 return -ENOMEM; | |
| 456 | |
| 457 snacid = aim_cachesnac(sess, 0x0001, 0x000c, 0x0000, NULL, 0); | |
| 458 aim_putsnac(&fr->data, 0x0001, 0x000c, 0x0000, snacid); | |
| 459 | |
| 460 /* | |
| 461 * This list should have all the groups that the original | |
| 462 * Host Online / Server Ready said this host supports. And | |
| 463 * we want them all back after the migration. | |
| 464 */ | |
| 465 for (sg = ins->groups; sg; sg = sg->next) | |
| 466 aimbs_put16(&fr->data, sg->group); | |
| 467 | |
| 468 aim_tx_enqueue(sess, fr); | |
| 469 | |
| 470 return 0; | |
| 471 } | |
| 472 | |
| 473 /* Service Resume (group 1, type 0x0d) */ | |
| 474 static int serverresume(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 475 { | |
| 476 aim_rxcallback_t userfunc; | |
| 477 | |
| 478 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 479 return userfunc(sess, rx); | |
| 480 | |
| 481 return 0; | |
| 482 } | |
| 483 | |
| 484 /* Request self-info (group 1, type 0x0e) */ | |
| 485 faim_export int aim_reqpersonalinfo(aim_session_t *sess, aim_conn_t *conn) | |
| 486 { | |
| 487 return aim_genericreq_n(sess, conn, 0x0001, 0x000e); | |
| 488 } | |
| 489 | |
| 490 /* Self User Info (group 1, type 0x0f) */ | |
| 491 static int selfinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 492 { | |
| 493 aim_rxcallback_t userfunc; | |
| 494 aim_userinfo_t userinfo; | |
| 495 | |
| 496 aim_extractuserinfo(sess, bs, &userinfo); | |
| 497 | |
| 498 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 499 return userfunc(sess, rx, &userinfo); | |
| 500 | |
| 501 return 0; | |
| 502 } | |
| 503 | |
| 504 /* Evil Notification (group 1, type 0x10) */ | |
| 505 static int evilnotify(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 506 { | |
| 507 aim_rxcallback_t userfunc; | |
| 508 fu16_t newevil; | |
| 509 aim_userinfo_t userinfo; | |
| 510 | |
| 511 memset(&userinfo, 0, sizeof(aim_userinfo_t)); | |
| 512 | |
| 513 newevil = aimbs_get16(bs); | |
| 514 | |
| 515 if (aim_bstream_empty(bs)) | |
| 516 aim_extractuserinfo(sess, bs, &userinfo); | |
| 517 | |
| 518 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 519 return userfunc(sess, rx, newevil, &userinfo); | |
| 520 | |
| 521 return 0; | |
| 522 } | |
| 523 | |
| 524 /* | |
| 525 * Idle Notification (group 1, type 0x11) | |
| 526 * | |
| 527 * Should set your current idle time in seconds. Note that this should | |
| 528 * never be called consecutively with a non-zero idle time. That makes | |
| 529 * OSCAR do funny things. Instead, just set it once you go idle, and then | |
| 530 * call it again with zero when you're back. | |
| 531 * | |
| 532 */ | |
| 533 faim_export int aim_bos_setidle(aim_session_t *sess, aim_conn_t *conn, fu32_t idletime) | |
| 534 { | |
| 535 return aim_genericreq_l(sess, conn, 0x0001, 0x0011, &idletime); | |
| 536 } | |
| 537 | |
| 538 /* | |
| 539 * Service Migrate (group 1, type 0x12) | |
| 540 * | |
| 541 * This is the final SNAC sent on the original connection during a migration. | |
| 542 * It contains the IP and cookie used to connect to the new server, and | |
| 543 * optionally a list of the SNAC groups being migrated. | |
| 544 * | |
| 545 */ | |
| 546 static int migrate(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 547 { | |
| 548 aim_rxcallback_t userfunc; | |
| 549 int ret = 0; | |
| 550 fu16_t groupcount, i; | |
| 551 aim_tlvlist_t *tl; | |
| 552 char *ip = NULL; | |
| 553 aim_tlv_t *cktlv; | |
| 554 | |
| 555 /* | |
| 556 * Apparently there's some fun stuff that can happen right here. The | |
| 557 * migration can actually be quite selective about what groups it | |
| 558 * moves to the new server. When not all the groups for a connection | |
| 559 * are migrated, or they are all migrated but some groups are moved | |
| 560 * to a different server than others, it is called a bifurcated | |
| 561 * migration. | |
| 562 * | |
| 563 * Let's play dumb and not support that. | |
| 564 * | |
| 565 */ | |
| 566 groupcount = aimbs_get16(bs); | |
| 567 for (i = 0; i < groupcount; i++) { | |
| 568 fu16_t group; | |
| 569 | |
| 570 group = aimbs_get16(bs); | |
| 571 | |
| 572 faimdprintf(sess, 0, "bifurcated migration unsupported -- group 0x%04x\n", group); | |
| 573 } | |
| 574 | |
| 575 tl = aim_readtlvchain(bs); | |
| 576 | |
| 577 if (aim_gettlv(tl, 0x0005, 1)) | |
| 578 ip = aim_gettlv_str(tl, 0x0005, 1); | |
| 579 | |
| 580 cktlv = aim_gettlv(tl, 0x0006, 1); | |
| 581 | |
| 582 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 583 ret = userfunc(sess, rx, ip, cktlv ? cktlv->value : NULL); | |
| 584 | |
| 585 aim_freetlvchain(&tl); | |
| 586 free(ip); | |
| 587 | |
| 588 return ret; | |
| 589 } | |
| 590 | |
| 591 /* Message of the Day (group 1, type 0x13) */ | |
| 592 static int motd(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 593 { | |
| 594 aim_rxcallback_t userfunc; | |
| 595 char *msg = NULL; | |
| 596 int ret = 0; | |
| 597 aim_tlvlist_t *tlvlist; | |
| 598 fu16_t id; | |
| 599 | |
| 600 /* | |
| 601 * Code. | |
| 602 * | |
| 603 * Valid values: | |
| 604 * 1 Mandatory upgrade | |
| 605 * 2 Advisory upgrade | |
| 606 * 3 System bulletin | |
| 607 * 4 Nothing's wrong ("top o the world" -- normal) | |
| 608 * 5 Lets-break-something. | |
| 609 * | |
| 610 */ | |
| 611 id = aimbs_get16(bs); | |
| 612 | |
| 613 /* | |
| 614 * TLVs follow | |
| 615 */ | |
| 616 tlvlist = aim_readtlvchain(bs); | |
| 617 | |
| 618 msg = aim_gettlv_str(tlvlist, 0x000b, 1); | |
| 619 | |
| 620 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 621 ret = userfunc(sess, rx, id, msg); | |
| 622 | |
| 623 free(msg); | |
| 624 | |
| 625 aim_freetlvchain(&tlvlist); | |
| 626 | |
| 627 return ret; | |
| 628 } | |
| 629 | |
| 630 /* | |
| 631 * Set privacy flags (group 1, type 0x14) | |
| 632 * | |
| 633 * Normally 0x03. | |
| 634 * | |
| 635 * Bit 1: Allows other AIM users to see how long you've been idle. | |
| 636 * Bit 2: Allows other AIM users to see how long you've been a member. | |
| 637 * | |
| 638 */ | |
| 639 faim_export int aim_bos_setprivacyflags(aim_session_t *sess, aim_conn_t *conn, fu32_t flags) | |
| 640 { | |
| 641 return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags); | |
| 642 } | |
| 643 | |
| 644 /* | |
| 645 * No-op (group 1, type 0x16) | |
| 646 * | |
| 647 * WinAIM sends these every 4min or so to keep the connection alive. Its not | |
| 648 * real necessary. | |
| 649 * | |
| 650 */ | |
| 651 faim_export int aim_nop(aim_session_t *sess, aim_conn_t *conn) | |
| 652 { | |
| 653 return aim_genericreq_n(sess, conn, 0x0001, 0x0016); | |
| 654 } | |
| 655 | |
| 656 /* | |
| 657 * Set client versions (group 1, subtype 0x17) | |
| 658 * | |
| 659 * If you've seen the clientonline/clientready SNAC you're probably | |
| 660 * wondering what the point of this one is. And that point seems to be | |
| 661 * that the versions in the client online SNAC are sent too late for the | |
| 662 * server to be able to use them to change the protocol for the earlier | |
| 663 * login packets (client versions are sent right after Host Online is | |
| 664 * received, but client online versions aren't sent until quite a bit later). | |
| 665 * We can see them already making use of this by changing the format of | |
| 666 * the rate information based on what version of group 1 we advertise here. | |
| 667 * | |
| 668 */ | |
| 669 faim_internal int aim_setversions(aim_session_t *sess, aim_conn_t *conn) | |
| 670 { | |
| 671 aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside; | |
| 672 struct snacgroup *sg; | |
| 673 aim_frame_t *fr; | |
| 674 aim_snacid_t snacid; | |
| 675 | |
| 676 if (!ins) | |
| 677 return -EINVAL; | |
| 678 | |
| 679 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) | |
| 680 return -ENOMEM; | |
| 681 | |
| 682 snacid = aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0); | |
| 683 aim_putsnac(&fr->data, 0x0001, 0x0017, 0x0000, snacid); | |
| 684 | |
| 685 /* | |
| 686 * Send only the versions that the server cares about (that it | |
| 687 * marked as supporting in the server ready SNAC). | |
| 688 */ | |
| 689 for (sg = ins->groups; sg; sg = sg->next) { | |
| 690 aim_module_t *mod; | |
| 691 | |
| 692 if ((mod = aim__findmodulebygroup(sess, sg->group))) { | |
| 693 aimbs_put16(&fr->data, mod->family); | |
| 694 aimbs_put16(&fr->data, mod->version); | |
| 695 } else | |
| 696 faimdprintf(sess, 1, "aim_setversions: server supports group 0x%04x but we don't!\n", sg->group); | |
| 697 } | |
| 698 | |
| 699 aim_tx_enqueue(sess, fr); | |
| 700 | |
| 701 return 0; | |
| 702 } | |
| 703 | |
| 704 /* Host versions (group 1, subtype 0x18) */ | |
| 705 static int hostversions(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 706 { | |
| 707 int vercount; | |
| 708 fu8_t *versions; | |
| 709 | |
| 710 /* This is frivolous. (Thank you SmarterChild.) */ | |
| 711 vercount = aim_bstream_empty(bs)/4; | |
| 712 versions = aimbs_getraw(bs, aim_bstream_empty(bs)); | |
| 713 free(versions); | |
| 714 | |
| 715 /* | |
| 716 * Now request rates. | |
| 717 */ | |
| 718 aim_reqrates(sess, rx->conn); | |
| 719 | |
| 720 return 1; | |
| 721 } | |
| 722 | |
| 723 /* | |
| 724 * Set Extended Status (group 1, type 0x1e) | |
| 725 * | |
| 726 * Currently only works if using ICQ. | |
| 727 * | |
| 728 */ | |
| 729 faim_export int aim_setextstatus(aim_session_t *sess, aim_conn_t *conn, fu16_t status) | |
| 730 { | |
| 731 aim_frame_t *fr; | |
| 732 aim_snacid_t snacid; | |
| 733 aim_tlvlist_t *tl = NULL; | |
| 734 fu32_t data; | |
| 735 | |
| 736 data = 0x00030000 | status; /* yay for error checking ;^) */ | |
| 737 | |
| 738 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 8))) | |
| 739 return -ENOMEM; | |
| 740 | |
| 741 snacid = aim_cachesnac(sess, 0x0001, 0x001e, 0x0000, NULL, 0); | |
| 742 aim_putsnac(&fr->data, 0x0001, 0x001e, 0x0000, snacid); | |
| 743 | |
| 744 aim_addtlvtochain32(&tl, 0x0006, data); | |
| 745 aim_writetlvchain(&fr->data, &tl); | |
| 746 aim_freetlvchain(&tl); | |
| 747 | |
| 748 aim_tx_enqueue(sess, fr); | |
| 749 | |
| 750 return 0; | |
| 751 } | |
| 752 | |
| 753 /* | |
| 754 * Starting this past week (26 Mar 2001, say), AOL has started sending | |
| 755 * this nice little extra SNAC. AFAIK, it has never been used until now. | |
| 756 * | |
| 757 * The request contains eight bytes. The first four are an offset, the | |
| 758 * second four are a length. | |
| 759 * | |
| 760 * The offset is an offset into aim.exe when it is mapped during execution | |
| 761 * on Win32. So far, AOL has only been requesting bytes in static regions | |
| 762 * of memory. (I won't put it past them to start requesting data in | |
| 763 * less static regions -- regions that are initialized at run time, but still | |
| 764 * before the client recieves this request.) | |
| 765 * | |
| 766 * When the client recieves the request, it adds it to the current ds | |
| 767 * (0x00400000) and dereferences it, copying the data into a buffer which | |
| 768 * it then runs directly through the MD5 hasher. The 16 byte output of | |
| 769 * the hash is then sent back to the server. | |
| 770 * | |
| 771 * If the client does not send any data back, or the data does not match | |
| 772 * the data that the specific client should have, the client will get the | |
| 773 * following message from "AOL Instant Messenger": | |
| 774 * "You have been disconnected from the AOL Instant Message Service (SM) | |
| 775 * for accessing the AOL network using unauthorized software. You can | |
| 776 * download a FREE, fully featured, and authorized client, here | |
| 777 * http://www.aol.com/aim/download2.html" | |
| 778 * The connection is then closed, recieving disconnect code 1, URL | |
| 779 * http://www.aim.aol.com/errors/USER_LOGGED_OFF_NEW_LOGIN.html. | |
| 780 * | |
| 781 * Note, however, that numerous inconsistencies can cause the above error, | |
| 782 * not just sending back a bad hash. Do not immediatly suspect this code | |
| 783 * if you get disconnected. AOL and the open/free software community have | |
| 784 * played this game for a couple years now, generating the above message | |
| 785 * on numerous ocassions. | |
| 786 * | |
| 787 * Anyway, neener. We win again. | |
| 788 * | |
| 789 */ | |
| 790 /* Client verification (group 1, subtype 0x1f) */ | |
| 791 static int memrequest(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 792 { | |
| 793 aim_rxcallback_t userfunc; | |
| 794 fu32_t offset, len; | |
| 795 aim_tlvlist_t *list; | |
| 796 char *modname; | |
| 797 | |
| 798 offset = aimbs_get32(bs); | |
| 799 len = aimbs_get32(bs); | |
| 800 list = aim_readtlvchain(bs); | |
| 801 | |
| 802 modname = aim_gettlv_str(list, 0x0001, 1); | |
| 803 | |
| 804 faimdprintf(sess, 1, "data at 0x%08lx (%d bytes) of requested\n", offset, len, modname ? modname : "aim.exe"); | |
| 805 | |
| 806 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 807 return userfunc(sess, rx, offset, len, modname); | |
| 808 | |
| 809 free(modname); | |
| 810 aim_freetlvchain(&list); | |
| 811 | |
| 812 return 0; | |
| 813 } | |
| 814 | |
| 815 #if 0 | |
| 816 static void dumpbox(aim_session_t *sess, unsigned char *buf, int len) | |
| 817 { | |
| 818 int i; | |
| 819 | |
| 820 if (!sess || !buf || !len) | |
| 821 return; | |
| 822 | |
| 823 faimdprintf(sess, 1, "\nDump of %d bytes at %p:", len, buf); | |
| 824 | |
| 825 for (i = 0; i < len; i++) { | |
| 826 if ((i % 8) == 0) | |
| 827 faimdprintf(sess, 1, "\n\t"); | |
| 828 | |
| 829 faimdprintf(sess, 1, "0x%2x ", buf[i]); | |
| 830 } | |
| 831 | |
| 832 faimdprintf(sess, 1, "\n\n"); | |
| 833 | |
| 834 return; | |
| 835 } | |
| 836 #endif | |
| 837 | |
| 838 /* Client verification reply (group 1, subtype 0x20) */ | |
| 839 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) | |
| 840 { | |
| 841 aim_frame_t *fr; | |
| 842 aim_snacid_t snacid; | |
| 843 | |
| 844 if (!sess || !conn) | |
| 845 return -EINVAL; | |
| 846 | |
| 847 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16))) | |
| 848 return -ENOMEM; | |
| 849 | |
| 850 snacid = aim_cachesnac(sess, 0x0001, 0x0020, 0x0000, NULL, 0); | |
| 851 | |
| 852 aim_putsnac(&fr->data, 0x0001, 0x0020, 0x0000, snacid); | |
| 853 aimbs_put16(&fr->data, 0x0010); /* md5 is always 16 bytes */ | |
| 854 | |
| 855 if ((flag == AIM_SENDMEMBLOCK_FLAG_ISHASH) && buf && (len == 0x10)) { /* we're getting a hash */ | |
| 856 | |
| 857 aimbs_putraw(&fr->data, buf, 0x10); | |
| 858 | |
| 859 } else if (buf && (len > 0)) { /* use input buffer */ | |
| 860 md5_state_t state; | |
| 861 md5_byte_t digest[0x10]; | |
| 862 | |
| 863 md5_init(&state); | |
| 864 md5_append(&state, (const md5_byte_t *)buf, len); | |
| 865 md5_finish(&state, digest); | |
| 866 | |
| 867 aimbs_putraw(&fr->data, (fu8_t *)digest, 0x10); | |
| 868 | |
| 869 } else if (len == 0) { /* no length, just hash NULL (buf is optional) */ | |
| 870 md5_state_t state; | |
| 871 fu8_t nil = '\0'; | |
| 872 md5_byte_t digest[0x10]; | |
| 873 | |
| 874 /* | |
| 875 * These MD5 routines are stupid in that you have to have | |
| 876 * at least one append. So thats why this doesn't look | |
| 877 * real logical. | |
| 878 */ | |
| 879 md5_init(&state); | |
| 880 md5_append(&state, (const md5_byte_t *)&nil, 0); | |
| 881 md5_finish(&state, digest); | |
| 882 | |
| 883 aimbs_putraw(&fr->data, (fu8_t *)digest, 0x10); | |
| 884 | |
| 885 } else { | |
| 886 | |
| 887 /* | |
| 888 * This data is correct for AIM 3.5.1670. | |
| 889 * | |
| 890 * Using these blocks is as close to "legal" as you can get | |
| 891 * without using an AIM binary. | |
| 892 * | |
| 893 */ | |
| 894 if ((offset == 0x03ffffff) && (len == 0x03ffffff)) { | |
| 895 | |
| 896 #if 1 /* with "AnrbnrAqhfzcd" */ | |
| 897 aimbs_put32(&fr->data, 0x44a95d26); | |
| 898 aimbs_put32(&fr->data, 0xd2490423); | |
| 899 aimbs_put32(&fr->data, 0x93b8821f); | |
| 900 aimbs_put32(&fr->data, 0x51c54b01); | |
| 901 #else /* no filename */ | |
| 902 aimbs_put32(&fr->data, 0x1df8cbae); | |
| 903 aimbs_put32(&fr->data, 0x5523b839); | |
| 904 aimbs_put32(&fr->data, 0xa0e10db3); | |
| 905 aimbs_put32(&fr->data, 0xa46d3b39); | |
| 906 #endif | |
| 907 | |
| 908 } else if ((offset == 0x00001000) && (len == 0x00000000)) { | |
| 909 | |
| 910 aimbs_put32(&fr->data, 0xd41d8cd9); | |
| 911 aimbs_put32(&fr->data, 0x8f00b204); | |
| 912 aimbs_put32(&fr->data, 0xe9800998); | |
| 913 aimbs_put32(&fr->data, 0xecf8427e); | |
| 914 | |
| 915 } else | |
| 916 faimdprintf(sess, 0, "sendmemblock: WARNING: unknown hash request\n"); | |
| 917 | |
| 918 } | |
| 919 | |
| 920 aim_tx_enqueue(sess, fr); | |
| 921 | |
| 922 return 0; | |
| 923 } | |
| 924 | |
| 925 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 926 { | |
| 927 | |
| 928 if (snac->subtype == 0x0003) | |
| 929 return hostonline(sess, mod, rx, snac, bs); | |
| 930 else if (snac->subtype == 0x0005) | |
| 931 return redirect(sess, mod, rx, snac, bs); | |
| 932 else if (snac->subtype == 0x0007) | |
| 933 return rateresp(sess, mod, rx, snac, bs); | |
| 934 else if (snac->subtype == 0x000a) | |
| 935 return ratechange(sess, mod, rx, snac, bs); | |
| 936 else if (snac->subtype == 0x000b) | |
| 937 return serverpause(sess, mod, rx, snac, bs); | |
| 938 else if (snac->subtype == 0x000d) | |
| 939 return serverresume(sess, mod, rx, snac, bs); | |
| 940 else if (snac->subtype == 0x000f) | |
| 941 return selfinfo(sess, mod, rx, snac, bs); | |
| 942 else if (snac->subtype == 0x0010) | |
| 943 return evilnotify(sess, mod, rx, snac, bs); | |
| 944 else if (snac->subtype == 0x0012) | |
| 945 return migrate(sess, mod, rx, snac, bs); | |
| 946 else if (snac->subtype == 0x0013) | |
| 947 return motd(sess, mod, rx, snac, bs); | |
| 948 else if (snac->subtype == 0x0018) | |
| 949 return hostversions(sess, mod, rx, snac, bs); | |
| 950 else if (snac->subtype == 0x001f) | |
| 951 return memrequest(sess, mod, rx, snac, bs); | |
| 952 | |
| 953 return 0; | |
| 954 } | |
| 955 | |
| 956 faim_internal int general_modfirst(aim_session_t *sess, aim_module_t *mod) | |
| 957 { | |
| 958 | |
| 959 mod->family = 0x0001; | |
| 960 mod->version = 0x0003; | |
| 961 mod->toolid = 0x0110; | |
| 962 mod->toolversion = 0x047b; | |
| 963 mod->flags = 0; | |
| 964 strncpy(mod->name, "general", sizeof(mod->name)); | |
| 965 mod->snachandler = snachandler; | |
| 966 | |
| 967 return 0; | |
| 968 } | |
| 969 |
