Sat, 11 Feb 2006 21:45:18 +0000
[gaim-migrate @ 15600]
Massive oscar shuffling. No change in functionality.
I renamed each of the files that contains stuff for a SNAC family.
I started splitting the file transfer/direct connect stuff into
peer.c and peer.h. I stopped using fu8_t, fu16_t and fu32_t and
switched to guint8, guint16 and guint32 instead. I changed the
SNAC family and subtype defines so they are more meaningful.
Added LGPL copyright header to each file. Added myself to the
AUTHORS file.
| 13235 | 1 | /* |
| 2 | * Gaim's oscar protocol plugin | |
| 3 | * This file is the legal property of its developers. | |
| 4 | * Please see the AUTHORS file distributed alongside this file. | |
| 5 | * | |
| 6 | * This library is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU Lesser General Public | |
| 8 | * License as published by the Free Software Foundation; either | |
| 9 | * version 2 of the License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This library is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * Lesser General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU Lesser General Public | |
| 17 | * License along with this library; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
| 21 | /* | |
| 22 | * Family 0x000e - Routines for the Chat service. | |
| 23 | * | |
| 24 | */ | |
| 25 | ||
| 26 | #include "oscar.h" | |
| 27 | ||
| 28 | #include <string.h> | |
| 29 | ||
| 30 | /* Stored in the ->internal of chat connections */ | |
| 31 | struct chatconnpriv { | |
| 32 | guint16 exchange; | |
| 33 | char *name; | |
| 34 | guint16 instance; | |
| 35 | }; | |
| 36 | ||
| 37 | faim_internal void aim_conn_kill_chat(aim_session_t *sess, aim_conn_t *conn) | |
| 38 | { | |
| 39 | struct chatconnpriv *ccp = (struct chatconnpriv *)conn->internal; | |
| 40 | ||
| 41 | if (ccp) | |
| 42 | free(ccp->name); | |
| 43 | free(ccp); | |
| 44 | ||
| 45 | return; | |
| 46 | } | |
| 47 | ||
| 48 | faim_export char *aim_chat_getname(aim_conn_t *conn) | |
| 49 | { | |
| 50 | struct chatconnpriv *ccp; | |
| 51 | ||
| 52 | if (!conn) | |
| 53 | return NULL; | |
| 54 | ||
| 55 | if (conn->type != AIM_CONN_TYPE_CHAT) | |
| 56 | return NULL; | |
| 57 | ||
| 58 | ccp = (struct chatconnpriv *)conn->internal; | |
| 59 | ||
| 60 | return ccp->name; | |
| 61 | } | |
| 62 | ||
| 63 | /* XXX get this into conn.c -- evil!! */ | |
| 64 | faim_export aim_conn_t *aim_chat_getconn(aim_session_t *sess, const char *name) | |
| 65 | { | |
| 66 | aim_conn_t *cur; | |
| 67 | ||
| 68 | for (cur = sess->connlist; cur; cur = cur->next) { | |
| 69 | struct chatconnpriv *ccp = (struct chatconnpriv *)cur->internal; | |
| 70 | ||
| 71 | if (cur->type != AIM_CONN_TYPE_CHAT) | |
| 72 | continue; | |
| 73 | if (!cur->internal) { | |
| 74 | gaim_debug_misc("oscar", "faim: chat: chat connection with no name! (fd = %d)\n", cur->fd); | |
| 75 | continue; | |
| 76 | } | |
| 77 | ||
| 78 | if (strcmp(ccp->name, name) == 0) | |
| 79 | break; | |
| 80 | } | |
| 81 | ||
| 82 | return cur; | |
| 83 | } | |
| 84 | ||
| 85 | faim_export int aim_chat_attachname(aim_conn_t *conn, guint16 exchange, const char *roomname, guint16 instance) | |
| 86 | { | |
| 87 | struct chatconnpriv *ccp; | |
| 88 | ||
| 89 | if (!conn || !roomname) | |
| 90 | return -EINVAL; | |
| 91 | ||
| 92 | if (conn->internal) | |
| 93 | free(conn->internal); | |
| 94 | ||
| 95 | if (!(ccp = malloc(sizeof(struct chatconnpriv)))) | |
| 96 | return -ENOMEM; | |
| 97 | ||
| 98 | ccp->exchange = exchange; | |
| 99 | ccp->name = strdup(roomname); | |
| 100 | ccp->instance = instance; | |
| 101 | ||
| 102 | conn->internal = (void *)ccp; | |
| 103 | ||
| 104 | return 0; | |
| 105 | } | |
| 106 | ||
| 107 | faim_internal int aim_chat_readroominfo(aim_bstream_t *bs, struct aim_chat_roominfo *outinfo) | |
| 108 | { | |
| 109 | int namelen; | |
| 110 | ||
| 111 | if (!bs || !outinfo) | |
| 112 | return 0; | |
| 113 | ||
| 114 | outinfo->exchange = aimbs_get16(bs); | |
| 115 | namelen = aimbs_get8(bs); | |
| 116 | outinfo->name = aimbs_getstr(bs, namelen); | |
| 117 | outinfo->instance = aimbs_get16(bs); | |
| 118 | ||
| 119 | return 0; | |
| 120 | } | |
| 121 | ||
| 122 | faim_export int aim_chat_leaveroom(aim_session_t *sess, const char *name) | |
| 123 | { | |
| 124 | aim_conn_t *conn; | |
| 125 | ||
| 126 | if (!(conn = aim_chat_getconn(sess, name))) | |
| 127 | return -ENOENT; | |
| 128 | ||
| 129 | aim_conn_close(conn); | |
| 130 | ||
| 131 | return 0; | |
| 132 | } | |
| 133 | ||
| 134 | /* | |
| 135 | * Subtype 0x0002 - General room information. Lots of stuff. | |
| 136 | * | |
| 137 | * Values I know are in here but I haven't attached | |
| 138 | * them to any of the 'Unknown's: | |
| 139 | * - Language (English) | |
| 140 | * | |
| 141 | */ | |
| 142 | static int infoupdate(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 143 | { | |
| 144 | aim_userinfo_t *userinfo = NULL; | |
| 145 | aim_rxcallback_t userfunc; | |
| 146 | int ret = 0; | |
| 147 | int usercount = 0; | |
| 148 | guint8 detaillevel = 0; | |
| 149 | char *roomname = NULL; | |
| 150 | struct aim_chat_roominfo roominfo; | |
| 151 | guint16 tlvcount = 0; | |
| 152 | aim_tlvlist_t *tlvlist; | |
| 153 | char *roomdesc = NULL; | |
| 154 | guint16 flags = 0; | |
| 155 | guint32 creationtime = 0; | |
| 156 | guint16 maxmsglen = 0, maxvisiblemsglen = 0; | |
| 157 | guint16 unknown_d2 = 0, unknown_d5 = 0; | |
| 158 | ||
| 159 | aim_chat_readroominfo(bs, &roominfo); | |
| 160 | ||
| 161 | detaillevel = aimbs_get8(bs); | |
| 162 | ||
| 163 | if (detaillevel != 0x02) { | |
| 164 | gaim_debug_misc("oscar", "faim: chat_roomupdateinfo: detail level %d not supported\n", detaillevel); | |
| 165 | return 1; | |
| 166 | } | |
| 167 | ||
| 168 | tlvcount = aimbs_get16(bs); | |
| 169 | ||
| 170 | /* | |
| 171 | * Everything else are TLVs. | |
| 172 | */ | |
| 173 | tlvlist = aim_tlvlist_read(bs); | |
| 174 | ||
| 175 | /* | |
| 176 | * TLV type 0x006a is the room name in Human Readable Form. | |
| 177 | */ | |
| 178 | if (aim_tlv_gettlv(tlvlist, 0x006a, 1)) | |
| 179 | roomname = aim_tlv_getstr(tlvlist, 0x006a, 1); | |
| 180 | ||
| 181 | /* | |
| 182 | * Type 0x006f: Number of occupants. | |
| 183 | */ | |
| 184 | if (aim_tlv_gettlv(tlvlist, 0x006f, 1)) | |
| 185 | usercount = aim_tlv_get16(tlvlist, 0x006f, 1); | |
| 186 | ||
| 187 | /* | |
| 188 | * Type 0x0073: Occupant list. | |
| 189 | */ | |
| 190 | if (aim_tlv_gettlv(tlvlist, 0x0073, 1)) { | |
| 191 | int curoccupant = 0; | |
| 192 | aim_tlv_t *tmptlv; | |
| 193 | aim_bstream_t occbs; | |
| 194 | ||
| 195 | tmptlv = aim_tlv_gettlv(tlvlist, 0x0073, 1); | |
| 196 | ||
| 197 | /* Allocate enough userinfo structs for all occupants */ | |
| 198 | userinfo = calloc(usercount, sizeof(aim_userinfo_t)); | |
| 199 | ||
| 200 | aim_bstream_init(&occbs, tmptlv->value, tmptlv->length); | |
| 201 | ||
| 202 | while (curoccupant < usercount) | |
| 203 | aim_info_extract(sess, &occbs, &userinfo[curoccupant++]); | |
| 204 | } | |
| 205 | ||
| 206 | /* | |
| 207 | * Type 0x00c9: Flags. (AIM_CHATROOM_FLAG) | |
| 208 | */ | |
| 209 | if (aim_tlv_gettlv(tlvlist, 0x00c9, 1)) | |
| 210 | flags = aim_tlv_get16(tlvlist, 0x00c9, 1); | |
| 211 | ||
| 212 | /* | |
| 213 | * Type 0x00ca: Creation time (4 bytes) | |
| 214 | */ | |
| 215 | if (aim_tlv_gettlv(tlvlist, 0x00ca, 1)) | |
| 216 | creationtime = aim_tlv_get32(tlvlist, 0x00ca, 1); | |
| 217 | ||
| 218 | /* | |
| 219 | * Type 0x00d1: Maximum Message Length | |
| 220 | */ | |
| 221 | if (aim_tlv_gettlv(tlvlist, 0x00d1, 1)) | |
| 222 | maxmsglen = aim_tlv_get16(tlvlist, 0x00d1, 1); | |
| 223 | ||
| 224 | /* | |
| 225 | * Type 0x00d2: Unknown. (2 bytes) | |
| 226 | */ | |
| 227 | if (aim_tlv_gettlv(tlvlist, 0x00d2, 1)) | |
| 228 | unknown_d2 = aim_tlv_get16(tlvlist, 0x00d2, 1); | |
| 229 | ||
| 230 | /* | |
| 231 | * Type 0x00d3: Room Description | |
| 232 | */ | |
| 233 | if (aim_tlv_gettlv(tlvlist, 0x00d3, 1)) | |
| 234 | roomdesc = aim_tlv_getstr(tlvlist, 0x00d3, 1); | |
| 235 | ||
| 236 | #if 0 | |
| 237 | /* | |
| 238 | * Type 0x000d4: Unknown (flag only) | |
| 239 | */ | |
| 240 | if (aim_tlv_gettlv(tlvlist, 0x000d4, 1)) { | |
| 241 | /* Unhandled */ | |
| 242 | } | |
| 243 | #endif | |
| 244 | ||
| 245 | /* | |
| 246 | * Type 0x00d5: Unknown. (1 byte) | |
| 247 | */ | |
| 248 | if (aim_tlv_gettlv(tlvlist, 0x00d5, 1)) | |
| 249 | unknown_d5 = aim_tlv_get8(tlvlist, 0x00d5, 1); | |
| 250 | ||
| 251 | #if 0 | |
| 252 | /* | |
| 253 | * Type 0x00d6: Encoding 1 ("us-ascii") | |
| 254 | */ | |
| 255 | if (aim_tlv_gettlv(tlvlist, 0x000d6, 1)) { | |
| 256 | /* Unhandled */ | |
| 257 | } | |
| 258 | ||
| 259 | /* | |
| 260 | * Type 0x00d7: Language 1 ("en") | |
| 261 | */ | |
| 262 | if (aim_tlv_gettlv(tlvlist, 0x000d7, 1)) { | |
| 263 | /* Unhandled */ | |
| 264 | } | |
| 265 | ||
| 266 | /* | |
| 267 | * Type 0x00d8: Encoding 2 ("us-ascii") | |
| 268 | */ | |
| 269 | if (aim_tlv_gettlv(tlvlist, 0x000d8, 1)) { | |
| 270 | /* Unhandled */ | |
| 271 | } | |
| 272 | ||
| 273 | /* | |
| 274 | * Type 0x00d9: Language 2 ("en") | |
| 275 | */ | |
| 276 | if (aim_tlv_gettlv(tlvlist, 0x000d9, 1)) { | |
| 277 | /* Unhandled */ | |
| 278 | } | |
| 279 | #endif | |
| 280 | ||
| 281 | /* | |
| 282 | * Type 0x00da: Maximum visible message length | |
| 283 | */ | |
| 284 | if (aim_tlv_gettlv(tlvlist, 0x000da, 1)) | |
| 285 | maxvisiblemsglen = aim_tlv_get16(tlvlist, 0x00da, 1); | |
| 286 | ||
| 287 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { | |
| 288 | ret = userfunc(sess, | |
| 289 | rx, | |
| 290 | &roominfo, | |
| 291 | roomname, | |
| 292 | usercount, | |
| 293 | userinfo, | |
| 294 | roomdesc, | |
| 295 | flags, | |
| 296 | creationtime, | |
| 297 | maxmsglen, | |
| 298 | unknown_d2, | |
| 299 | unknown_d5, | |
| 300 | maxvisiblemsglen); | |
| 301 | } | |
| 302 | ||
| 303 | free(roominfo.name); | |
| 304 | ||
| 305 | while (usercount > 0) | |
| 306 | aim_info_free(&userinfo[--usercount]); | |
| 307 | ||
| 308 | free(userinfo); | |
| 309 | free(roomname); | |
| 310 | free(roomdesc); | |
| 311 | aim_tlvlist_free(&tlvlist); | |
| 312 | ||
| 313 | return ret; | |
| 314 | } | |
| 315 | ||
| 316 | /* Subtypes 0x0003 and 0x0004 */ | |
| 317 | static int userlistchange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 318 | { | |
| 319 | aim_userinfo_t *userinfo = NULL; | |
| 320 | aim_rxcallback_t userfunc; | |
| 321 | int curcount = 0, ret = 0; | |
| 322 | ||
| 323 | while (aim_bstream_empty(bs)) { | |
| 324 | curcount++; | |
| 325 | userinfo = realloc(userinfo, curcount * sizeof(aim_userinfo_t)); | |
| 326 | aim_info_extract(sess, bs, &userinfo[curcount-1]); | |
| 327 | } | |
| 328 | ||
| 329 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 330 | ret = userfunc(sess, rx, curcount, userinfo); | |
| 331 | ||
| 332 | aim_info_free(userinfo); | |
| 333 | free(userinfo); | |
| 334 | ||
| 335 | return ret; | |
| 336 | } | |
| 337 | ||
| 338 | /* | |
| 339 | * Subtype 0x0005 - Send a Chat Message. | |
| 340 | * | |
| 341 | * Possible flags: | |
| 342 | * AIM_CHATFLAGS_NOREFLECT -- Unset the flag that requests messages | |
| 343 | * should be sent to their sender. | |
| 344 | * AIM_CHATFLAGS_AWAY -- Mark the message as an autoresponse | |
| 345 | * (Note that WinAIM does not honor this, | |
| 346 | * and displays the message as normal.) | |
| 347 | * | |
| 348 | * XXX convert this to use tlvchains | |
| 349 | */ | |
| 350 | faim_export int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, guint16 flags, const gchar *msg, int msglen, const char *encoding, const char *language) | |
| 351 | { | |
| 352 | int i; | |
| 353 | aim_frame_t *fr; | |
| 354 | aim_msgcookie_t *cookie; | |
| 355 | aim_snacid_t snacid; | |
| 356 | guint8 ckstr[8]; | |
| 357 | aim_tlvlist_t *otl = NULL, *itl = NULL; | |
| 358 | ||
| 359 | if (!sess || !conn || !msg || (msglen <= 0)) | |
| 360 | return 0; | |
| 361 | ||
| 362 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) | |
| 363 | return -ENOMEM; | |
| 364 | ||
| 365 | snacid = aim_cachesnac(sess, 0x000e, 0x0005, 0x0000, NULL, 0); | |
| 366 | aim_putsnac(&fr->data, 0x000e, 0x0005, 0x0000, snacid); | |
| 367 | ||
| 368 | /* | |
| 369 | * Cookie | |
| 370 | * | |
| 371 | * XXX mkcookie should generate the cookie and cache it in one | |
| 372 | * operation to preserve uniqueness. | |
| 373 | */ | |
| 374 | for (i = 0; i < 8; i++) | |
| 375 | ckstr[i] = (guint8)rand(); | |
| 376 | ||
| 377 | cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL); | |
| 378 | cookie->data = NULL; /* XXX store something useful here */ | |
| 379 | ||
| 380 | aim_cachecookie(sess, cookie); | |
| 381 | ||
| 382 | /* ICBM Header */ | |
| 383 | aimbs_putraw(&fr->data, ckstr, 8); /* Cookie */ | |
| 384 | aimbs_put16(&fr->data, 0x0003); /* Channel */ | |
| 385 | ||
| 386 | /* | |
| 387 | * Type 1: Flag meaning this message is destined to the room. | |
| 388 | */ | |
| 389 | aim_tlvlist_add_noval(&otl, 0x0001); | |
| 390 | ||
| 391 | /* | |
| 392 | * Type 6: Reflect | |
| 393 | */ | |
| 394 | if (!(flags & AIM_CHATFLAGS_NOREFLECT)) | |
| 395 | aim_tlvlist_add_noval(&otl, 0x0006); | |
| 396 | ||
| 397 | /* | |
| 398 | * Type 7: Autoresponse | |
| 399 | */ | |
| 400 | if (flags & AIM_CHATFLAGS_AWAY) | |
| 401 | aim_tlvlist_add_noval(&otl, 0x0007); | |
| 402 | ||
| 403 | /* | |
| 404 | * SubTLV: Type 1: Message | |
| 405 | */ | |
| 406 | aim_tlvlist_add_raw(&itl, 0x0001, msglen, (guchar *)msg); | |
| 407 | ||
| 408 | /* | |
| 409 | * SubTLV: Type 2: Encoding | |
| 410 | */ | |
| 411 | if (encoding != NULL) | |
| 412 | aim_tlvlist_add_str(&itl, 0x0002, encoding); | |
| 413 | ||
| 414 | /* | |
| 415 | * SubTLV: Type 3: Language | |
| 416 | */ | |
| 417 | if (language != NULL) | |
| 418 | aim_tlvlist_add_str(&itl, 0x0003, language); | |
| 419 | ||
| 420 | /* | |
| 421 | * Type 5: Message block. Contains more TLVs. | |
| 422 | * | |
| 423 | * This could include other information... We just | |
| 424 | * put in a message TLV however. | |
| 425 | * | |
| 426 | */ | |
| 427 | aim_tlvlist_add_frozentlvlist(&otl, 0x0005, &itl); | |
| 428 | ||
| 429 | aim_tlvlist_write(&fr->data, &otl); | |
| 430 | ||
| 431 | aim_tlvlist_free(&itl); | |
| 432 | aim_tlvlist_free(&otl); | |
| 433 | ||
| 434 | aim_tx_enqueue(sess, fr); | |
| 435 | ||
| 436 | return 0; | |
| 437 | } | |
| 438 | ||
| 439 | /* | |
| 440 | * Subtype 0x0006 | |
| 441 | * | |
| 442 | * We could probably include this in the normal ICBM parsing | |
| 443 | * code as channel 0x0003, however, since only the start | |
| 444 | * would be the same, we might as well do it here. | |
| 445 | * | |
| 446 | * General outline of this SNAC: | |
| 447 | * snac | |
| 448 | * cookie | |
| 449 | * channel id | |
| 450 | * tlvlist | |
| 451 | * unknown | |
| 452 | * source user info | |
| 453 | * name | |
| 454 | * evility | |
| 455 | * userinfo tlvs | |
| 456 | * online time | |
| 457 | * etc | |
| 458 | * message metatlv | |
| 459 | * message tlv | |
| 460 | * message string | |
| 461 | * possibly others | |
| 462 | * | |
| 463 | */ | |
| 464 | static int incomingim_ch3(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 465 | { | |
| 466 | int ret = 0, i; | |
| 467 | aim_rxcallback_t userfunc; | |
| 468 | aim_userinfo_t userinfo; | |
| 469 | guint8 cookie[8]; | |
| 470 | guint16 channel; | |
| 471 | aim_tlvlist_t *otl; | |
| 472 | char *msg = NULL; | |
| 473 | int len = 0; | |
| 474 | char *encoding = NULL, *language = NULL; | |
| 475 | aim_msgcookie_t *ck; | |
| 476 | ||
| 477 | memset(&userinfo, 0, sizeof(aim_userinfo_t)); | |
| 478 | ||
| 479 | /* | |
| 480 | * Read ICBM Cookie. | |
| 481 | */ | |
| 482 | for (i = 0; i < 8; i++) | |
| 483 | cookie[i] = aimbs_get8(bs); | |
| 484 | ||
| 485 | if ((ck = aim_uncachecookie(sess, cookie, AIM_COOKIETYPE_CHAT))) { | |
| 486 | free(ck->data); | |
| 487 | free(ck); | |
| 488 | } | |
| 489 | ||
| 490 | /* | |
| 491 | * Channel ID | |
| 492 | * | |
| 493 | * Channel 0x0003 is used for chat messages. | |
| 494 | * | |
| 495 | */ | |
| 496 | channel = aimbs_get16(bs); | |
| 497 | ||
| 498 | if (channel != 0x0003) { | |
| 499 | gaim_debug_misc("oscar", "faim: chat_incoming: unknown channel! (0x%04x)\n", channel); | |
| 500 | return 0; | |
| 501 | } | |
| 502 | ||
| 503 | /* | |
| 504 | * Start parsing TLVs right away. | |
| 505 | */ | |
| 506 | otl = aim_tlvlist_read(bs); | |
| 507 | ||
| 508 | /* | |
| 509 | * Type 0x0003: Source User Information | |
| 510 | */ | |
| 511 | if (aim_tlv_gettlv(otl, 0x0003, 1)) { | |
| 512 | aim_tlv_t *userinfotlv; | |
| 513 | aim_bstream_t tbs; | |
| 514 | ||
| 515 | userinfotlv = aim_tlv_gettlv(otl, 0x0003, 1); | |
| 516 | ||
| 517 | aim_bstream_init(&tbs, userinfotlv->value, userinfotlv->length); | |
| 518 | aim_info_extract(sess, &tbs, &userinfo); | |
| 519 | } | |
| 520 | ||
| 521 | #if 0 | |
| 522 | /* | |
| 523 | * Type 0x0001: If present, it means it was a message to the | |
| 524 | * room (as opposed to a whisper). | |
| 525 | */ | |
| 526 | if (aim_tlv_gettlv(otl, 0x0001, 1)) { | |
| 527 | /* Unhandled */ | |
| 528 | } | |
| 529 | #endif | |
| 530 | ||
| 531 | /* | |
| 532 | * Type 0x0005: Message Block. Conains more TLVs. | |
| 533 | */ | |
| 534 | if (aim_tlv_gettlv(otl, 0x0005, 1)) { | |
| 535 | aim_tlvlist_t *itl; | |
| 536 | aim_tlv_t *msgblock; | |
| 537 | aim_bstream_t tbs; | |
| 538 | ||
| 539 | msgblock = aim_tlv_gettlv(otl, 0x0005, 1); | |
| 540 | aim_bstream_init(&tbs, msgblock->value, msgblock->length); | |
| 541 | itl = aim_tlvlist_read(&tbs); | |
| 542 | ||
| 543 | /* | |
| 544 | * Type 0x0001: Message. | |
| 545 | */ | |
| 546 | if (aim_tlv_gettlv(itl, 0x0001, 1)) { | |
| 547 | msg = aim_tlv_getstr(itl, 0x0001, 1); | |
| 548 | len = aim_tlv_gettlv(itl, 0x0001, 1)->length; | |
| 549 | } | |
| 550 | ||
| 551 | /* | |
| 552 | * Type 0x0002: Encoding. | |
| 553 | */ | |
| 554 | if (aim_tlv_gettlv(itl, 0x0002, 1)) | |
| 555 | encoding = aim_tlv_getstr(itl, 0x0002, 1); | |
| 556 | ||
| 557 | /* | |
| 558 | * Type 0x0003: Language. | |
| 559 | */ | |
| 560 | if (aim_tlv_gettlv(itl, 0x0003, 1)) | |
| 561 | language = aim_tlv_getstr(itl, 0x0003, 1); | |
| 562 | ||
| 563 | aim_tlvlist_free(&itl); | |
| 564 | } | |
| 565 | ||
| 566 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
| 567 | ret = userfunc(sess, rx, &userinfo, len, msg, encoding, language); | |
| 568 | ||
| 569 | aim_info_free(&userinfo); | |
| 570 | free(msg); | |
| 571 | aim_tlvlist_free(&otl); | |
| 572 | ||
| 573 | return ret; | |
| 574 | } | |
| 575 | ||
| 576 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 577 | { | |
| 578 | ||
| 579 | if (snac->subtype == 0x0002) | |
| 580 | return infoupdate(sess, mod, rx, snac, bs); | |
| 581 | else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004)) | |
| 582 | return userlistchange(sess, mod, rx, snac, bs); | |
| 583 | else if (snac->subtype == 0x0006) | |
| 584 | return incomingim_ch3(sess, mod, rx, snac, bs); | |
| 585 | ||
| 586 | return 0; | |
| 587 | } | |
| 588 | ||
| 589 | faim_internal int chat_modfirst(aim_session_t *sess, aim_module_t *mod) | |
| 590 | { | |
| 591 | ||
| 592 | mod->family = 0x000e; | |
| 593 | mod->version = 0x0001; | |
| 594 | mod->toolid = 0x0010; | |
| 595 | mod->toolversion = 0x0629; | |
| 596 | mod->flags = 0; | |
| 597 | strncpy(mod->name, "chat", sizeof(mod->name)); | |
| 598 | mod->snachandler = snachandler; | |
| 599 | ||
| 600 | return 0; | |
| 601 | } |