/* * In AIM 3.5 protocol, the first stage of login is to request login from the * Authorizer, passing it the screen name for verification. If the name is * invalid, a 0017/0003 is spit back, with the standard error contents. If * valid, a 0017/0007 comes back, which is the signal to send it the main * login command (0017/0002). * */ int aim_request_login(aim_session_t *sess, aim_conn_t *conn, const char *sn) { aim_frame_t *fr; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; if (!sess || !conn || !sn) return -EINVAL; if ((sn[0] >= '0') && (sn[0] <= '9')) return goddamnicq(sess, conn, sn); sess->flags |= AIM_SESS_FLAGS_SNACLOGIN; aim_sendflapver(sess, conn); if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(sn)))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x0017, 0x0006, 0x0000, snacid); aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *)sn); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw) { aim_frame_t *tx; aim_tlvlist_t *tl = NULL; aim_snacid_t snacid; if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + strlen(curpw) + 4 + strlen(newpw)))) { return -ENOMEM; } snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); /* new password TLV t(0002) */ aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), (guint8 *) newpw); /* current password TLV t(0012) */ aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), (guint8 *) curpw); aim_writetlvchain(&tx->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, tx); return 0; }
/* * In AIM 3.5 protocol, the first stage of login is to request login from the * Authorizer, passing it the screen name for verification. If the name is * invalid, a 0017/0003 is spit back, with the standard error contents. If * valid, a 0017/0007 comes back, which is the signal to send it the main * login command (0017/0002). * */ int aim_request_login(aim_session_t *sess, aim_conn_t *conn, const char *sn) { aim_frame_t *fr; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; struct im_connection *ic = sess->aux_data; if (!sess || !conn || !sn) { return -EINVAL; } if (g_ascii_isdigit(sn[0]) && set_getbool(&ic->acc->set, "old_icq_auth")) { return goddamnicq(sess, conn, sn); } sess->flags |= AIM_SESS_FLAGS_SNACLOGIN; aim_sendflapver(sess, conn); if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(sn)))) { return -ENOMEM; } snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x0017, 0x0006, 0x0000, snacid); aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * Inverse of aim_extractuserinfo() */ int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info) { aim_tlvlist_t *tlvlist = NULL; if (!bs || !info) return -EINVAL; aimbs_put8(bs, strlen(info->sn)); aimbs_putraw(bs, (guint8 *)info->sn, strlen(info->sn)); aimbs_put16(bs, info->warnlevel); aim_addtlvtochain16(&tlvlist, 0x0001, info->flags); aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince); aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince); aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime); #if ICQ_OSCAR_SUPPORT if (atoi(info->sn) != 0) { aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status); aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr); } #endif aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities); aim_addtlvtochain32(&tlvlist, (guint16)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); aimbs_put16(bs, aim_counttlvchain(&tlvlist)); aim_writetlvchain(bs, &tlvlist); aim_freetlvchain(&tlvlist); return 0; }
/* XXX pass these in better */ int aim_setuserinterests(aim_session_t *sess, aim_conn_t *conn, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, guint16 privacy) { aim_frame_t *fr; aim_tlvlist_t *tl = NULL; /* ?? privacy ?? */ aim_addtlvtochain16(&tl, 0x000a, privacy); if (interest1) aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest1), (guint8 *)interest1); if (interest2) aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest2), (guint8 *)interest2); if (interest3) aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest3), (guint8 *)interest3); if (interest4) aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest4), (guint8 *)interest4); if (interest5) aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest5), (guint8 *)interest5); if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl)))) return -ENOMEM; aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x0002, 0x000f, 0x0000, 0); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * Join a room of name roomname. This is the first step to joining an * already created room. It's basically a Service Request for * family 0x000e, with a little added on to specify the exchange and room * name. */ faim_export int aim_chat_join(aim_session_t *sess, aim_conn_t *conn, fu16_t exchange, const char *roomname, fu16_t instance) { aim_frame_t *fr; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; struct chatsnacinfo csi; if (!sess || !conn || !roomname || !strlen(roomname)) return -EINVAL; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512))) return -ENOMEM; memset(&csi, 0, sizeof(csi)); csi.exchange = exchange; strncpy(csi.name, roomname, sizeof(csi.name)); csi.instance = instance; snacid = aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, &csi, sizeof(csi)); aim_putsnac(&fr->data, 0x0001, 0x0004, 0x0000, snacid); /* * Requesting service chat (0x000e) */ aimbs_put16(&fr->data, 0x000e); aim_addtlvtochain_chatroom(&tl, 0x0001, exchange, roomname, instance); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * send_login(int socket, char *sn, char *password) * * This is the initial login request packet. * * NOTE!! If you want/need to make use of the aim_sendmemblock() function, * then the client information you send here must exactly match the * executable that you're pulling the data from. * * WinAIM 4.8.2540 * clientstring = "AOL Instant Messenger (SM), version 4.8.2540/WIN32" * clientid = 0x0109 * major = 0x0004 * minor = 0x0008 * point = 0x0000 * build = 0x09ec * t(0x0014) = 0x000000af * t(0x004a) = 0x01 * * WinAIM 4.3.2188: * clientstring = "AOL Instant Messenger (SM), version 4.3.2188/WIN32" * clientid = 0x0109 * major = 0x0400 * minor = 0x0003 * point = 0x0000 * build = 0x088c * unknown = 0x00000086 * lang = "en" * country = "us" * unknown4a = 0x01 * * Latest WinAIM that libfaim can emulate without server-side buddylists: * clientstring = "AOL Instant Messenger (SM), version 4.1.2010/WIN32" * clientid = 0x0004 * major = 0x0004 * minor = 0x0001 * point = 0x0000 * build = 0x07da * unknown= 0x0000004b * * WinAIM 3.5.1670: * clientstring = "AOL Instant Messenger (SM), version 3.5.1670/WIN32" * clientid = 0x0004 * major = 0x0003 * minor = 0x0005 * point = 0x0000 * build = 0x0686 * unknown =0x0000002a * * Java AIM 1.1.19: * clientstring = "AOL Instant Messenger (TM) version 1.1.19 for Java built 03/24/98, freeMem 215871 totalMem 1048567, i686, Linus, #2 SMP Sun Feb 11 03:41:17 UTC 2001 2.4.1-ac9, IBM Corporation, 1.1.8, 45.3, Tue Mar 27 12:09:17 PST 2001" * clientid = 0x0001 * major = 0x0001 * minor = 0x0001 * point = (not sent) * build = 0x0013 * unknown= (not sent) * * AIM for Linux 1.1.112: * clientstring = "AOL Instant Messenger (SM)" * clientid = 0x1d09 * major = 0x0001 * minor = 0x0001 * point = 0x0001 * build = 0x0070 * unknown= 0x0000008b * serverstore = 0x01 * */ int aim_send_login(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password, struct client_info_s *ci, const char *key) { aim_frame_t *fr; aim_tlvlist_t *tl = NULL; guint8 digest[16]; aim_snacid_t snacid; if (!ci || !sn || !password) return -EINVAL; /* * What the XORLOGIN flag _really_ means is that its an ICQ login, * which is really stupid and painful, so its not done here. * */ if (sess->flags & AIM_SESS_FLAGS_XORLOGIN) return goddamnicq2(sess, conn, sn, password); if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x0017, 0x0002, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x0017, 0x0002, 0x0000, snacid); aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *)sn); aim_encode_password_md5(password, key, digest); aim_addtlvtochain_raw(&tl, 0x0025, 16, digest); /* * Newer versions of winaim have an empty type x004c TLV here. */ if (ci->clientstring) aim_addtlvtochain_raw(&tl, 0x0003, strlen(ci->clientstring), (guint8 *)ci->clientstring); aim_addtlvtochain16(&tl, 0x0016, (guint16)ci->clientid); aim_addtlvtochain16(&tl, 0x0017, (guint16)ci->major); aim_addtlvtochain16(&tl, 0x0018, (guint16)ci->minor); aim_addtlvtochain16(&tl, 0x0019, (guint16)ci->point); aim_addtlvtochain16(&tl, 0x001a, (guint16)ci->build); aim_addtlvtochain_raw(&tl, 0x000e, strlen(ci->country), (guint8 *)ci->country); aim_addtlvtochain_raw(&tl, 0x000f, strlen(ci->lang), (guint8 *)ci->lang); /* * If set, old-fashioned buddy lists will not work. You will need * to use SSI. */ aim_addtlvtochain8(&tl, 0x004a, 0x01); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
faim_export int aim_chatnav_createroom(aim_session_t *sess, aim_conn_t *conn, const char *name, fu16_t exchange) { static const char ck[] = {"create"}; static const char lang[] = {"en"}; static const char charset[] = {"us-ascii"}; aim_frame_t *fr; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x000d, 0x0008, 0x0000, snacid); /* exchange */ aimbs_put16(&fr->data, exchange); /* * This looks to be a big hack. You'll note that this entire * SNAC is just a room info structure, but the hard room name, * here, is set to "create". * * Either this goes on the "list of questions concerning * why-the-hell-did-you-do-that", or this value is completly * ignored. Without experimental evidence, but a good knowledge of * AOL style, I'm going to guess that it is the latter, and that * the value of the room name in create requests is ignored. */ aimbs_put8(&fr->data, strlen(ck)); aimbs_putraw(&fr->data, ck, strlen(ck)); /* * instance * * Setting this to 0xffff apparently assigns the last instance. * */ aimbs_put16(&fr->data, 0xffff); /* detail level */ aimbs_put8(&fr->data, 0x01); aim_addtlvtochain_raw(&tl, 0x00d3, strlen(name), name); aim_addtlvtochain_raw(&tl, 0x00d6, strlen(charset), charset); aim_addtlvtochain_raw(&tl, 0x00d7, strlen(lang), lang); /* tlvcount */ aimbs_put16(&fr->data, aim_counttlvchain(&tl)); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * This just pushes the passed cookie onto the passed connection, without * the SNAC header or any of that. * * Very commonly used, as every connection except auth will require this to * be the first thing you send. * */ int aim_sendcookie(aim_session_t *sess, aim_conn_t *conn, const guint8 *chipsahoy) { aim_frame_t *fr; aim_tlvlist_t *tl = NULL; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4+2+2+AIM_COOKIELEN))) return -ENOMEM; aimbs_put32(&fr->data, 0x00000001); aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * aim_bos_setprofile(profile) * * Gives BOS your profile. * */ int aim_bos_setprofile(aim_session_t *sess, aim_conn_t *conn, const char *profile, const char *awaymsg, guint32 caps) { static const char defencoding[] = {"text/aolrtf; charset=\"utf-8\""}; aim_frame_t *fr; aim_tlvlist_t *tl = NULL; aim_snacid_t snacid; /* Build to packet first to get real length */ if (profile) { aim_addtlvtochain_raw(&tl, 0x0001, strlen(defencoding), (guint8 *)defencoding); aim_addtlvtochain_raw(&tl, 0x0002, strlen(profile), (guint8 *)profile); } /* * So here's how this works: * - You are away when you have a non-zero-length type 4 TLV stored. * - You become unaway when you clear the TLV with a zero-length * type 4 TLV. * - If you do not send the type 4 TLV, your status does not change * (that is, if you were away, you'll remain away). */ if (awaymsg) { if (strlen(awaymsg)) { aim_addtlvtochain_raw(&tl, 0x0003, strlen(defencoding), (guint8 *)defencoding); aim_addtlvtochain_raw(&tl, 0x0004, strlen(awaymsg), (guint8 *)awaymsg); } else aim_addtlvtochain_noval(&tl, 0x0004); } aim_addtlvtochain_caps(&tl, 0x0005, caps); if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_sizetlvchain(&tl)))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * Set directory profile data (not the same as aim_bos_setprofile!) * * privacy: 1 to allow searching, 0 to disallow. */ int aim_setdirectoryinfo(aim_session_t *sess, aim_conn_t *conn, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, guint16 privacy) { aim_frame_t *fr; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; aim_addtlvtochain16(&tl, 0x000a, privacy); if (first) aim_addtlvtochain_raw(&tl, 0x0001, strlen(first), (guint8 *)first); if (last) aim_addtlvtochain_raw(&tl, 0x0002, strlen(last), (guint8 *)last); if (middle) aim_addtlvtochain_raw(&tl, 0x0003, strlen(middle), (guint8 *)middle); if (maiden) aim_addtlvtochain_raw(&tl, 0x0004, strlen(maiden), (guint8 *)maiden); if (state) aim_addtlvtochain_raw(&tl, 0x0007, strlen(state), (guint8 *)state); if (city) aim_addtlvtochain_raw(&tl, 0x0008, strlen(city), (guint8 *)city); if (nickname) aim_addtlvtochain_raw(&tl, 0x000c, strlen(nickname), (guint8 *)nickname); if (zip) aim_addtlvtochain_raw(&tl, 0x000d, strlen(zip), (guint8 *)zip); if (street) aim_addtlvtochain_raw(&tl, 0x0021, strlen(street), (guint8 *)street); if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl)))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x0002, 0x0009, 0x0000, snacid); aim_writetlvchain(&fr->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
/* * Inverse of aim_extractuserinfo() */ faim_internal int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info) { aim_tlvlist_t *tlvlist = NULL; if (!bs || !info) return -EINVAL; aimbs_put8(bs, strlen(info->sn)); aimbs_putraw(bs, info->sn, strlen(info->sn)); aimbs_put16(bs, info->warnlevel); if (info->present & AIM_USERINFO_PRESENT_FLAGS) aim_addtlvtochain16(&tlvlist, 0x0001, info->flags); if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE) aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince); if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE) aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince); if (info->present & AIM_USERINFO_PRESENT_IDLE) aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime); #if ICQ_OSCAR_SUPPORT if (atoi(info->sn) != 0) { if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status); if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR) aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr); } #endif if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES) aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities); if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) aim_addtlvtochain32(&tlvlist, (fu16_t)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); aimbs_put16(bs, aim_counttlvchain(&tlvlist)); aim_writetlvchain(bs, &tlvlist); aim_freetlvchain(&tlvlist); return 0; }
/* * Part two of the ICQ hack. Note the ignoring of the key and clientinfo. */ static int goddamnicq2(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password) { static const char clientstr[] = { "ICQ Inc. - Product of ICQ (TM) 2001b.5.17.1.3642.85" }; static const char lang[] = { "en" }; static const char country[] = { "us" }; aim_frame_t *fr; aim_tlvlist_t *tl = NULL; guint8 *password_encoded; if (!(password_encoded = (guint8 *) g_malloc(strlen(password)))) { return -ENOMEM; } if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) { g_free(password_encoded); return -ENOMEM; } aim_encode_password(password, password_encoded); aimbs_put32(&fr->data, 0x00000001); aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn); aim_addtlvtochain_raw(&tl, 0x0002, strlen(password), password_encoded); aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientstr), (guint8 *) clientstr); aim_addtlvtochain16(&tl, 0x0016, 0x010a); /* cliend ID */ aim_addtlvtochain16(&tl, 0x0017, 0x0005); /* major version */ aim_addtlvtochain16(&tl, 0x0018, 0x0011); /* minor version */ aim_addtlvtochain16(&tl, 0x0019, 0x0001); /* point version */ aim_addtlvtochain16(&tl, 0x001a, 0x0e3a); /* build */ aim_addtlvtochain32(&tl, 0x0014, 0x00000055); /* distribution chan */ aim_addtlvtochain_raw(&tl, 0x000f, strlen(lang), (guint8 *) lang); aim_addtlvtochain_raw(&tl, 0x000e, strlen(country), (guint8 *) country); aim_writetlvchain(&fr->data, &tl); g_free(password_encoded); aim_freetlvchain(&tl); aim_tx_enqueue(sess, fr); return 0; }
int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail) { aim_frame_t *tx; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(newemail)))) { return -ENOMEM; } snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), (guint8 *) newemail); aim_writetlvchain(&tx->data, &tl); aim_freetlvchain(&tl); aim_tx_enqueue(sess, tx); return 0; }
/* * Note that the inner TLV chain will not be modifiable as a tlvchain once * it is written using this. Or rather, it can be, but updates won't be * made to this. * * XXX should probably support sublists for real. * * This is so neat. * */ faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl) { fu8_t *buf; int buflen; aim_bstream_t bs; buflen = aim_sizetlvchain(tl); if (buflen <= 0) return 0; if (!(buf = malloc(buflen))) return 0; aim_bstream_init(&bs, buf, buflen); aim_writetlvchain(&bs, tl); aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf); free(buf); return buflen; }
/* * Send a Chat Message. * * Possible flags: * AIM_CHATFLAGS_NOREFLECT -- Unset the flag that requests messages * should be sent to their sender. * AIM_CHATFLAGS_AWAY -- Mark the message as an autoresponse * (Note that WinAIM does not honor this, * and displays the message as normal.) * * XXX convert this to use tlvchains */ faim_export int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, fu16_t flags, const char *msg, int msglen) { int i; aim_frame_t *fr; aim_msgcookie_t *cookie; aim_snacid_t snacid; fu8_t ckstr[8]; aim_tlvlist_t *otl = NULL, *itl = NULL; if (!sess || !conn || !msg || (msglen <= 0)) return 0; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x000e, 0x0005, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x000e, 0x0005, 0x0000, snacid); /* * Generate a random message cookie. * * XXX mkcookie should generate the cookie and cache it in one * operation to preserve uniqueness. * */ for (i = 0; i < sizeof(ckstr); i++) aimutil_put8(ckstr+i, (fu8_t) rand()); cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL); cookie->data = NULL; /* XXX store something useful here */ aim_cachecookie(sess, cookie); for (i = 0; i < sizeof(ckstr); i++) aimbs_put8(&fr->data, ckstr[i]); /* * Channel ID. */ aimbs_put16(&fr->data, 0x0003); /* * Type 1: Flag meaning this message is destined to the room. */ aim_addtlvtochain_noval(&otl, 0x0001); /* * Type 6: Reflect */ if (!(flags & AIM_CHATFLAGS_NOREFLECT)) aim_addtlvtochain_noval(&otl, 0x0006); /* * Type 7: Autoresponse */ if (flags & AIM_CHATFLAGS_AWAY) aim_addtlvtochain_noval(&otl, 0x0007); /* * SubTLV: Type 1: Message */ aim_addtlvtochain_raw(&itl, 0x0001, strlen(msg), msg); /* * Type 5: Message block. Contains more TLVs. * * This could include other information... We just * put in a message TLV however. * */ aim_addtlvtochain_frozentlvlist(&otl, 0x0005, &itl); aim_writetlvchain(&fr->data, &otl); aim_freetlvchain(&itl); aim_freetlvchain(&otl); aim_tx_enqueue(sess, fr); return 0; }
/* * conn must be a BOS connection! */ faim_export int aim_chat_invite(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *msg, fu16_t exchange, const char *roomname, fu16_t instance) { int i; aim_frame_t *fr; aim_msgcookie_t *cookie; struct aim_invite_priv *priv; fu8_t ckstr[8]; aim_snacid_t snacid; aim_tlvlist_t *otl = NULL, *itl = NULL; fu8_t *hdr; int hdrlen; aim_bstream_t hdrbs; if (!sess || !conn || !sn || !msg || !roomname) return -EINVAL; if (conn->type != AIM_CONN_TYPE_BOS) return -EINVAL; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152+strlen(sn)+strlen(roomname)+strlen(msg)))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, sn, strlen(sn)+1); aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); /* * Cookie */ for (i = 0; i < sizeof(ckstr); i++) aimutil_put8(ckstr, (fu8_t) rand()); /* XXX should be uncached by an unwritten 'invite accept' handler */ if ((priv = malloc(sizeof(struct aim_invite_priv)))) { priv->sn = strdup(sn); priv->roomname = strdup(roomname); priv->exchange = exchange; priv->instance = instance; } if ((cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_INVITE, priv))) aim_cachecookie(sess, cookie); else free(priv); for (i = 0; i < sizeof(ckstr); i++) aimbs_put8(&fr->data, ckstr[i]); /* * Channel (2) */ aimbs_put16(&fr->data, 0x0002); /* * Dest sn */ aimbs_put8(&fr->data, strlen(sn)); aimbs_putraw(&fr->data, sn, strlen(sn)); /* * TLV t(0005) * * Everything else is inside this TLV. * * Sigh. AOL was rather inconsistent right here. So we have * to play some minor tricks. Right inside the type 5 is some * raw data, followed by a series of TLVs. * */ hdrlen = 2+8+16+6+4+4+strlen(msg)+4+2+1+strlen(roomname)+2; hdr = malloc(hdrlen); aim_bstream_init(&hdrbs, hdr, hdrlen); aimbs_put16(&hdrbs, 0x0000); /* Unknown! */ aimbs_putraw(&hdrbs, ckstr, sizeof(ckstr)); /* I think... */ aim_putcap(&hdrbs, AIM_CAPS_CHAT); aim_addtlvtochain16(&itl, 0x000a, 0x0001); aim_addtlvtochain_noval(&itl, 0x000f); aim_addtlvtochain_raw(&itl, 0x000c, strlen(msg), msg); aim_addtlvtochain_chatroom(&itl, 0x2711, exchange, roomname, instance); aim_writetlvchain(&hdrbs, &itl); aim_addtlvtochain_raw(&otl, 0x0005, aim_bstream_curpos(&hdrbs), hdr); aim_writetlvchain(&fr->data, &otl); free(hdr); aim_freetlvchain(&itl); aim_freetlvchain(&otl); aim_tx_enqueue(sess, fr); return 0; }