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