| 1 |
/* |
| 2 |
* Family 0x000d - Handle ChatNav. |
| 3 |
* |
| 4 |
* The ChatNav(igation) service does various things to keep chat |
| 5 |
* alive. It provides room information, room searching and creating, |
| 6 |
* as well as giving users the right ("permission") to use chat. |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
#define FAIM_INTERNAL |
| 11 |
#include <aim.h> |
| 12 |
|
| 13 |
/* |
| 14 |
* Subtype 0x0002 |
| 15 |
* |
| 16 |
* conn must be a chatnav connection! |
| 17 |
* |
| 18 |
*/ |
| 19 |
faim_export int aim_chatnav_reqrights(aim_session_t *sess, aim_conn_t *conn) |
| 20 |
{ |
| 21 |
return aim_genericreq_n_snacid(sess, conn, 0x000d, 0x0002); |
| 22 |
} |
| 23 |
|
| 24 |
/* |
| 25 |
* Subtype 0x0008 |
| 26 |
*/ |
| 27 |
faim_export int aim_chatnav_createroom(aim_session_t *sess, aim_conn_t *conn, const char *name, fu16_t exchange) |
| 28 |
{ |
| 29 |
static const char ck[] = {"create"}; |
| 30 |
static const char lang[] = {"en"}; |
| 31 |
static const char charset[] = {"us-ascii"}; |
| 32 |
aim_frame_t *fr; |
| 33 |
aim_snacid_t snacid; |
| 34 |
aim_tlvlist_t *tl = NULL; |
| 35 |
|
| 36 |
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) |
| 37 |
return -ENOMEM; |
| 38 |
|
| 39 |
snacid = aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); |
| 40 |
aim_putsnac(&fr->data, 0x000d, 0x0008, 0x0000, snacid); |
| 41 |
|
| 42 |
/* exchange */ |
| 43 |
aimbs_put16(&fr->data, exchange); |
| 44 |
|
| 45 |
/* |
| 46 |
* This looks to be a big hack. You'll note that this entire |
| 47 |
* SNAC is just a room info structure, but the hard room name, |
| 48 |
* here, is set to "create". |
| 49 |
* |
| 50 |
* Either this goes on the "list of questions concerning |
| 51 |
* why-the-hell-did-you-do-that", or this value is completly |
| 52 |
* ignored. Without experimental evidence, but a good knowledge of |
| 53 |
* AOL style, I'm going to guess that it is the latter, and that |
| 54 |
* the value of the room name in create requests is ignored. |
| 55 |
*/ |
| 56 |
aimbs_put8(&fr->data, strlen(ck)); |
| 57 |
aimbs_putraw(&fr->data, ck, strlen(ck)); |
| 58 |
|
| 59 |
/* |
| 60 |
* instance |
| 61 |
* |
| 62 |
* Setting this to 0xffff apparently assigns the last instance. |
| 63 |
* |
| 64 |
*/ |
| 65 |
aimbs_put16(&fr->data, 0xffff); |
| 66 |
|
| 67 |
/* detail level */ |
| 68 |
aimbs_put8(&fr->data, 0x01); |
| 69 |
|
| 70 |
aim_tlvlist_add_raw(&tl, 0x00d3, strlen(name), name); |
| 71 |
aim_tlvlist_add_raw(&tl, 0x00d6, strlen(charset), charset); |
| 72 |
aim_tlvlist_add_raw(&tl, 0x00d7, strlen(lang), lang); |
| 73 |
|
| 74 |
/* tlvcount */ |
| 75 |
aimbs_put16(&fr->data, aim_tlvlist_count(&tl)); |
| 76 |
aim_tlvlist_write(&fr->data, &tl); |
| 77 |
|
| 78 |
aim_tlvlist_free(&tl); |
| 79 |
|
| 80 |
aim_tx_enqueue(sess, fr); |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
static int parseinfo_perms(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs, aim_snac_t *snac2) |
| 86 |
{ |
| 87 |
aim_rxcallback_t userfunc; |
| 88 |
int ret = 0; |
| 89 |
struct aim_chat_exchangeinfo *exchanges = NULL; |
| 90 |
int curexchange; |
| 91 |
aim_tlv_t *exchangetlv; |
| 92 |
fu8_t maxrooms = 0; |
| 93 |
aim_tlvlist_t *tlvlist, *innerlist; |
| 94 |
|
| 95 |
tlvlist = aim_tlvlist_read(bs); |
| 96 |
|
| 97 |
/* |
| 98 |
* Type 0x0002: Maximum concurrent rooms. |
| 99 |
*/ |
| 100 |
if (aim_tlv_gettlv(tlvlist, 0x0002, 1)) |
| 101 |
maxrooms = aim_tlv_get8(tlvlist, 0x0002, 1); |
| 102 |
|
| 103 |
/* |
| 104 |
* Type 0x0003: Exchange information |
| 105 |
* |
| 106 |
* There can be any number of these, each one |
| 107 |
* representing another exchange. |
| 108 |
* |
| 109 |
*/ |
| 110 |
for (curexchange = 0; ((exchangetlv = aim_tlv_gettlv(tlvlist, 0x0003, curexchange+1))); ) { |
| 111 |
aim_bstream_t tbs; |
| 112 |
|
| 113 |
aim_bstream_init(&tbs, exchangetlv->value, exchangetlv->length); |
| 114 |
|
| 115 |
curexchange++; |
| 116 |
|
| 117 |
exchanges = realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo)); |
| 118 |
|
| 119 |
/* exchange number */ |
| 120 |
exchanges[curexchange-1].number = aimbs_get16(&tbs); |
| 121 |
innerlist = aim_tlvlist_read(&tbs); |
| 122 |
|
| 123 |
/* |
| 124 |
* Type 0x000a: Unknown. |
| 125 |
* |
| 126 |
* Usually three bytes: 0x0114 (exchange 1) or 0x010f (others). |
| 127 |
* |
| 128 |
*/ |
| 129 |
if (aim_tlv_gettlv(innerlist, 0x000a, 1)) |
| 130 |
; |
| 131 |
|
| 132 |
/* |
| 133 |
* Type 0x000d: Unknown. |
| 134 |
*/ |
| 135 |
if (aim_tlv_gettlv(innerlist, 0x000d, 1)) |
| 136 |
; |
| 137 |
|
| 138 |
/* |
| 139 |
* Type 0x0004: Unknown |
| 140 |
*/ |
| 141 |
if (aim_tlv_gettlv(innerlist, 0x0004, 1)) |
| 142 |
; |
| 143 |
|
| 144 |
/* |
| 145 |
* Type 0x0002: Unknown |
| 146 |
*/ |
| 147 |
if (aim_tlv_gettlv(innerlist, 0x0002, 1)) { |
| 148 |
fu16_t classperms; |
| 149 |
|
| 150 |
classperms = aim_tlv_get16(innerlist, 0x0002, 1); |
| 151 |
|
| 152 |
faimdprintf(sess, 1, "faim: class permissions %x\n", classperms); |
| 153 |
} |
| 154 |
|
| 155 |
/* |
| 156 |
* Type 0x00c9: Flags |
| 157 |
* |
| 158 |
* 1 Evilable |
| 159 |
* 2 Nav Only |
| 160 |
* 4 Instancing Allowed |
| 161 |
* 8 Occupant Peek Allowed |
| 162 |
* |
| 163 |
*/ |
| 164 |
if (aim_tlv_gettlv(innerlist, 0x00c9, 1)) |
| 165 |
exchanges[curexchange-1].flags = aim_tlv_get16(innerlist, 0x00c9, 1); |
| 166 |
|
| 167 |
/* |
| 168 |
* Type 0x00ca: Creation Date |
| 169 |
*/ |
| 170 |
if (aim_tlv_gettlv(innerlist, 0x00ca, 1)) |
| 171 |
; |
| 172 |
|
| 173 |
/* |
| 174 |
* Type 0x00d0: Mandatory Channels? |
| 175 |
*/ |
| 176 |
if (aim_tlv_gettlv(innerlist, 0x00d0, 1)) |
| 177 |
; |
| 178 |
|
| 179 |
/* |
| 180 |
* Type 0x00d1: Maximum Message length |
| 181 |
*/ |
| 182 |
if (aim_tlv_gettlv(innerlist, 0x00d1, 1)) |
| 183 |
; |
| 184 |
|
| 185 |
/* |
| 186 |
* Type 0x00d2: Maximum Occupancy? |
| 187 |
*/ |
| 188 |
if (aim_tlv_gettlv(innerlist, 0x00d2, 1)) |
| 189 |
; |
| 190 |
|
| 191 |
/* |
| 192 |
* Type 0x00d3: Exchange Description |
| 193 |
*/ |
| 194 |
if (aim_tlv_gettlv(innerlist, 0x00d3, 1)) |
| 195 |
exchanges[curexchange-1].name = aim_tlv_getstr(innerlist, 0x00d3, 1); |
| 196 |
else |
| 197 |
exchanges[curexchange-1].name = NULL; |
| 198 |
|
| 199 |
/* |
| 200 |
* Type 0x00d4: Exchange Description URL |
| 201 |
*/ |
| 202 |
if (aim_tlv_gettlv(innerlist, 0x00d4, 1)) |
| 203 |
; |
| 204 |
|
| 205 |
/* |
| 206 |
* Type 0x00d5: Creation Permissions |
| 207 |
* |
| 208 |
* 0 Creation not allowed |
| 209 |
* 1 Room creation allowed |
| 210 |
* 2 Exchange creation allowed |
| 211 |
* |
| 212 |
*/ |
| 213 |
if (aim_tlv_gettlv(innerlist, 0x00d5, 1)) { |
| 214 |
fu8_t createperms; |
| 215 |
|
| 216 |
createperms = aim_tlv_get8(innerlist, 0x00d5, 1); |
| 217 |
} |
| 218 |
|
| 219 |
/* |
| 220 |
* Type 0x00d6: Character Set (First Time) |
| 221 |
*/ |
| 222 |
if (aim_tlv_gettlv(innerlist, 0x00d6, 1)) |
| 223 |
exchanges[curexchange-1].charset1 = aim_tlv_getstr(innerlist, 0x00d6, 1); |
| 224 |
else |
| 225 |
exchanges[curexchange-1].charset1 = NULL; |
| 226 |
|
| 227 |
/* |
| 228 |
* Type 0x00d7: Language (First Time) |
| 229 |
*/ |
| 230 |
if (aim_tlv_gettlv(innerlist, 0x00d7, 1)) |
| 231 |
exchanges[curexchange-1].lang1 = aim_tlv_getstr(innerlist, 0x00d7, 1); |
| 232 |
else |
| 233 |
exchanges[curexchange-1].lang1 = NULL; |
| 234 |
|
| 235 |
/* |
| 236 |
* Type 0x00d8: Character Set (Second Time) |
| 237 |
*/ |
| 238 |
if (aim_tlv_gettlv(innerlist, 0x00d8, 1)) |
| 239 |
exchanges[curexchange-1].charset2 = aim_tlv_getstr(innerlist, 0x00d8, 1); |
| 240 |
else |
| 241 |
exchanges[curexchange-1].charset2 = NULL; |
| 242 |
|
| 243 |
/* |
| 244 |
* Type 0x00d9: Language (Second Time) |
| 245 |
*/ |
| 246 |
if (aim_tlv_gettlv(innerlist, 0x00d9, 1)) |
| 247 |
exchanges[curexchange-1].lang2 = aim_tlv_getstr(innerlist, 0x00d9, 1); |
| 248 |
else |
| 249 |
exchanges[curexchange-1].lang2 = NULL; |
| 250 |
|
| 251 |
/* |
| 252 |
* Type 0x00da: Unknown |
| 253 |
*/ |
| 254 |
if (aim_tlv_gettlv(innerlist, 0x00da, 1)) |
| 255 |
; |
| 256 |
|
| 257 |
aim_tlvlist_free(&innerlist); |
| 258 |
} |
| 259 |
|
| 260 |
/* |
| 261 |
* Call client. |
| 262 |
*/ |
| 263 |
if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
| 264 |
ret = userfunc(sess, rx, snac2->type, maxrooms, curexchange, exchanges); |
| 265 |
|
| 266 |
for (curexchange--; curexchange >= 0; curexchange--) { |
| 267 |
free(exchanges[curexchange].name); |
| 268 |
free(exchanges[curexchange].charset1); |
| 269 |
free(exchanges[curexchange].lang1); |
| 270 |
free(exchanges[curexchange].charset2); |
| 271 |
free(exchanges[curexchange].lang2); |
| 272 |
} |
| 273 |
free(exchanges); |
| 274 |
aim_tlvlist_free(&tlvlist); |
| 275 |
|
| 276 |
return ret; |
| 277 |
} |
| 278 |
|
| 279 |
static int parseinfo_create(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs, aim_snac_t *snac2) |
| 280 |
{ |
| 281 |
aim_rxcallback_t userfunc; |
| 282 |
aim_tlvlist_t *tlvlist, *innerlist; |
| 283 |
char *ck = NULL, *fqcn = NULL, *name = NULL; |
| 284 |
fu16_t exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0; |
| 285 |
fu32_t createtime = 0; |
| 286 |
fu8_t createperms = 0, detaillevel; |
| 287 |
int cklen; |
| 288 |
aim_tlv_t *bigblock; |
| 289 |
int ret = 0; |
| 290 |
aim_bstream_t bbbs; |
| 291 |
|
| 292 |
tlvlist = aim_tlvlist_read(bs); |
| 293 |
|
| 294 |
if (!(bigblock = aim_tlv_gettlv(tlvlist, 0x0004, 1))) { |
| 295 |
faimdprintf(sess, 0, "no bigblock in top tlv in create room response\n"); |
| 296 |
aim_tlvlist_free(&tlvlist); |
| 297 |
return 0; |
| 298 |
} |
| 299 |
|
| 300 |
aim_bstream_init(&bbbs, bigblock->value, bigblock->length); |
| 301 |
|
| 302 |
exchange = aimbs_get16(&bbbs); |
| 303 |
cklen = aimbs_get8(&bbbs); |
| 304 |
ck = aimbs_getstr(&bbbs, cklen); |
| 305 |
instance = aimbs_get16(&bbbs); |
| 306 |
detaillevel = aimbs_get8(&bbbs); |
| 307 |
|
| 308 |
if (detaillevel != 0x02) { |
| 309 |
faimdprintf(sess, 0, "unknown detaillevel in create room response (0x%02x)\n", detaillevel); |
| 310 |
aim_tlvlist_free(&tlvlist); |
| 311 |
free(ck); |
| 312 |
return 0; |
| 313 |
} |
| 314 |
|
| 315 |
unknown = aimbs_get16(&bbbs); |
| 316 |
|
| 317 |
innerlist = aim_tlvlist_read(&bbbs); |
| 318 |
|
| 319 |
if (aim_tlv_gettlv(innerlist, 0x006a, 1)) |
| 320 |
fqcn = aim_tlv_getstr(innerlist, 0x006a, 1); |
| 321 |
|
| 322 |
if (aim_tlv_gettlv(innerlist, 0x00c9, 1)) |
| 323 |
flags = aim_tlv_get16(innerlist, 0x00c9, 1); |
| 324 |
|
| 325 |
if (aim_tlv_gettlv(innerlist, 0x00ca, 1)) |
| 326 |
createtime = aim_tlv_get32(innerlist, 0x00ca, 1); |
| 327 |
|
| 328 |
if (aim_tlv_gettlv(innerlist, 0x00d1, 1)) |
| 329 |
maxmsglen = aim_tlv_get16(innerlist, 0x00d1, 1); |
| 330 |
|
| 331 |
if (aim_tlv_gettlv(innerlist, 0x00d2, 1)) |
| 332 |
maxoccupancy = aim_tlv_get16(innerlist, 0x00d2, 1); |
| 333 |
|
| 334 |
if (aim_tlv_gettlv(innerlist, 0x00d3, 1)) |
| 335 |
name = aim_tlv_getstr(innerlist, 0x00d3, 1); |
| 336 |
|
| 337 |
if (aim_tlv_gettlv(innerlist, 0x00d5, 1)) |
| 338 |
createperms = aim_tlv_get8(innerlist, 0x00d5, 1); |
| 339 |
|
| 340 |
if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
| 341 |
ret = userfunc(sess, rx, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); |
| 342 |
} |
| 343 |
|
| 344 |
free(ck); |
| 345 |
free(name); |
| 346 |
free(fqcn); |
| 347 |
aim_tlvlist_free(&innerlist); |
| 348 |
aim_tlvlist_free(&tlvlist); |
| 349 |
|
| 350 |
return ret; |
| 351 |
} |
| 352 |
|
| 353 |
/* |
| 354 |
* Subtype 0x0009 |
| 355 |
* |
| 356 |
* Since multiple things can trigger this callback, we must lookup the |
| 357 |
* snacid to determine the original snac subtype that was called. |
| 358 |
* |
| 359 |
* XXX This isn't really how this works. But this is: Every d/9 response |
| 360 |
* has a 16bit value at the beginning. That matches to: |
| 361 |
* Short Desc = 1 |
| 362 |
* Full Desc = 2 |
| 363 |
* Instance Info = 4 |
| 364 |
* Nav Short Desc = 8 |
| 365 |
* Nav Instance Info = 16 |
| 366 |
* And then everything is really asynchronous. There is no specific |
| 367 |
* attachment of a response to a create room request, for example. Creating |
| 368 |
* the room yields no different a response than requesting the room's info. |
| 369 |
* |
| 370 |
*/ |
| 371 |
static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
| 372 |
{ |
| 373 |
aim_snac_t *snac2; |
| 374 |
int ret = 0; |
| 375 |
|
| 376 |
if (!(snac2 = aim_remsnac(sess, snac->id))) { |
| 377 |
faimdprintf(sess, 0, "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snac->id); |
| 378 |
return 0; |
| 379 |
} |
| 380 |
|
| 381 |
if (snac2->family != 0x000d) { |
| 382 |
faimdprintf(sess, 0, "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac2->family); |
| 383 |
return 0; |
| 384 |
} |
| 385 |
|
| 386 |
/* |
| 387 |
* We now know what the original SNAC subtype was. |
| 388 |
*/ |
| 389 |
if (snac2->type == 0x0002) /* request chat rights */ |
| 390 |
ret = parseinfo_perms(sess, mod, rx, snac, bs, snac2); |
| 391 |
else if (snac2->type == 0x0003) /* request exchange info */ |
| 392 |
faimdprintf(sess, 0, "chatnav_parse_info: resposne to exchange info\n"); |
| 393 |
else if (snac2->type == 0x0004) /* request room info */ |
| 394 |
faimdprintf(sess, 0, "chatnav_parse_info: response to room info\n"); |
| 395 |
else if (snac2->type == 0x0005) /* request more room info */ |
| 396 |
faimdprintf(sess, 0, "chatnav_parse_info: response to more room info\n"); |
| 397 |
else if (snac2->type == 0x0006) /* request occupant list */ |
| 398 |
faimdprintf(sess, 0, "chatnav_parse_info: response to occupant info\n"); |
| 399 |
else if (snac2->type == 0x0007) /* search for a room */ |
| 400 |
faimdprintf(sess, 0, "chatnav_parse_info: search results\n"); |
| 401 |
else if (snac2->type == 0x0008) /* create room */ |
| 402 |
ret = parseinfo_create(sess, mod, rx, snac, bs, snac2); |
| 403 |
else |
| 404 |
faimdprintf(sess, 0, "chatnav_parse_info: unknown request subtype (%04x)\n", snac2->type); |
| 405 |
|
| 406 |
if (snac2) |
| 407 |
free(snac2->data); |
| 408 |
free(snac2); |
| 409 |
|
| 410 |
return ret; |
| 411 |
} |
| 412 |
|
| 413 |
static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
| 414 |
{ |
| 415 |
|
| 416 |
if (snac->subtype == 0x0009) |
| 417 |
return parseinfo(sess, mod, rx, snac, bs); |
| 418 |
|
| 419 |
return 0; |
| 420 |
} |
| 421 |
|
| 422 |
faim_internal int chatnav_modfirst(aim_session_t *sess, aim_module_t *mod) |
| 423 |
{ |
| 424 |
|
| 425 |
mod->family = 0x000d; |
| 426 |
mod->version = 0x0001; |
| 427 |
mod->toolid = 0x0010; |
| 428 |
mod->toolversion = 0x0629; |
| 429 |
mod->flags = 0; |
| 430 |
strncpy(mod->name, "chatnav", sizeof(mod->name)); |
| 431 |
mod->snachandler = snachandler; |
| 432 |
|
| 433 |
return 0; |
| 434 |
} |