/** * Create a rendezvous "init recv" packet and send it on its merry way. * This is the first packet sent to the proxy server by the second client * involved in this rendezvous proxy session. * * @param conn The peer connection. * @param pin The 2 byte PIN sent to us by the other user. This acts * as our passcode when establishing the proxy session. */ static void peer_proxy_send_join_existing_conn(PeerConnection *conn, guint16 pin) { ProxyFrame frame; PurpleAccount *account; const gchar *bn; guint8 bn_length; memset(&frame, 0, sizeof(ProxyFrame)); frame.type = PEER_PROXY_TYPE_JOIN; frame.flags = 0x0000; account = purple_connection_get_account(conn->od->gc); bn = purple_account_get_username(account); bn_length = strlen(bn); byte_stream_new(&frame.payload, 1 + bn_length + 2 + 8 + 20); byte_stream_put8(&frame.payload, bn_length); byte_stream_putraw(&frame.payload, (const guint8 *)bn, bn_length); byte_stream_put16(&frame.payload, pin); byte_stream_putraw(&frame.payload, conn->cookie, 8); byte_stream_put16(&frame.payload, 0x0001); /* Type */ byte_stream_put16(&frame.payload, 16); /* Length */ byte_stream_putcaps(&frame.payload, conn->type); /* Value */ peer_proxy_send(conn, &frame); }
static void peer_proxy_send(PeerConnection *conn, ProxyFrame *frame) { size_t length; ByteStream bs; purple_debug_info("oscar", "Outgoing peer proxy frame with " "type=0x%04hx, unknown=0x%08x, " "flags=0x%04hx, and payload length=%hd\n", frame->type, frame->unknown, frame->flags, frame->payload.len); length = 12 + frame->payload.len; byte_stream_new(&bs, length); byte_stream_put16(&bs, length - 2); byte_stream_put16(&bs, PEER_PROXY_PACKET_VERSION); byte_stream_put16(&bs, frame->type); byte_stream_put32(&bs, frame->unknown); byte_stream_put16(&bs, frame->flags); byte_stream_putraw(&bs, frame->payload.data, frame->payload.len); peer_connection_send(conn, &bs); byte_stream_destroy(&bs); }
static void sendframe_flap(FlapConnection *conn, FlapFrame *frame) { ByteStream bs; int payloadlen, bslen; payloadlen = byte_stream_curpos(&frame->data); byte_stream_new(&bs, 6 + payloadlen); /* FLAP header */ byte_stream_put8(&bs, 0x2a); byte_stream_put8(&bs, frame->channel); byte_stream_put16(&bs, frame->seqnum); byte_stream_put16(&bs, payloadlen); /* Payload */ byte_stream_rewind(&frame->data); byte_stream_putbs(&bs, &frame->data, payloadlen); bslen = byte_stream_curpos(&bs); byte_stream_rewind(&bs); flap_connection_send_byte_stream(&bs, conn, bslen); byte_stream_destroy(&bs); }
/* * Subtype 0x0008 */ int aim_chatnav_createroom(OscarData *od, FlapConnection *conn, const char *name, guint16 exchange) { static const char ck[] = {"create"}; static const char lang[] = {"en"}; static const char charset[] = {"us-ascii"}; ByteStream bs; aim_snacid_t snacid; GSList *tlvlist = NULL; byte_stream_new(&bs, 1142); snacid = aim_cachesnac(od, SNAC_FAMILY_CHATNAV, 0x0008, 0x0000, NULL, 0); /* exchange */ byte_stream_put16(&bs, 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 completely * 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. */ byte_stream_put8(&bs, strlen(ck)); byte_stream_putstr(&bs, ck); /* * instance * * Setting this to 0xffff apparently assigns the last instance. * */ byte_stream_put16(&bs, 0xffff); /* detail level */ byte_stream_put8(&bs, 0x01); aim_tlvlist_add_str(&tlvlist, 0x00d3, name); aim_tlvlist_add_str(&tlvlist, 0x00d6, charset); aim_tlvlist_add_str(&tlvlist, 0x00d7, lang); /* tlvcount */ byte_stream_put16(&bs, aim_tlvlist_count(tlvlist)); aim_tlvlist_write(&bs, &tlvlist); aim_tlvlist_free(tlvlist); flap_connection_send_snac(od, conn, SNAC_FAMILY_CHATNAV, 0x0008, snacid, &bs); byte_stream_destroy(&bs); return 0; }
/** * Subtype 0x000b * * Send SecurID response. */ int aim_auth_securid_send(OscarData *od, const char *securid) { FlapConnection *conn; FlapFrame *frame; aim_snacid_t snacid; int len; if (!od || !(conn = flap_connection_getbytype_all(od, SNAC_FAMILY_AUTH)) || !securid) return -EINVAL; len = strlen(securid); frame = flap_frame_new(od, 0x02, 10+2+len); snacid = aim_cachesnac(od, SNAC_FAMILY_AUTH, SNAC_SUBTYPE_AUTH_SECURID_RESPONSE, 0x0000, NULL, 0); aim_putsnac(&frame->data, SNAC_FAMILY_AUTH, SNAC_SUBTYPE_AUTH_SECURID_RESPONSE, 0x0000, 0); byte_stream_put16(&frame->data, len); byte_stream_putstr(&frame->data, securid); flap_connection_send(conn, frame); return 0; }
/* * Inverse of aim_info_extract() */ int aim_putuserinfo(ByteStream *bs, aim_userinfo_t *info) { GSList *tlvlist = NULL; if (!bs || !info) return -EINVAL; byte_stream_put8(bs, strlen(info->bn)); byte_stream_putstr(bs, info->bn); byte_stream_put16(bs, info->warnlevel); if (info->present & AIM_USERINFO_PRESENT_FLAGS) aim_tlvlist_add_16(&tlvlist, 0x0001, info->flags); if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE) aim_tlvlist_add_32(&tlvlist, 0x0002, info->membersince); if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE) aim_tlvlist_add_32(&tlvlist, 0x0003, info->onlinesince); if (info->present & AIM_USERINFO_PRESENT_IDLE) aim_tlvlist_add_16(&tlvlist, 0x0004, info->idletime); /* XXX - So, ICQ_OSCAR_SUPPORT is never defined anywhere... */ #ifdef ICQ_OSCAR_SUPPORT if (atoi(info->bn) != 0) { if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) aim_tlvlist_add_16(&tlvlist, 0x0006, info->icqinfo.status); if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR) aim_tlvlist_add_32(&tlvlist, 0x000a, info->icqinfo.ipaddr); } #endif if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES) aim_tlvlist_add_caps(&tlvlist, 0x000d, info->capabilities); if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) aim_tlvlist_add_32(&tlvlist, (guint16)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); byte_stream_put16(bs, aim_tlvlist_count(tlvlist)); aim_tlvlist_write(bs, &tlvlist); aim_tlvlist_free(tlvlist); return 0; }
/* * Subtype 0x0005 - Request info of another AIM user. * * @param sn The screenname whose info you wish to request. * @param infotype The type of info you wish to request. * 0x0001 - Info/profile * 0x0003 - Away message * 0x0004 - Capabilities */ int aim_locate_getinfo(OscarData *od, const char *sn, guint16 infotype) { FlapConnection *conn; FlapFrame *frame; aim_snacid_t snacid; if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn) return -EINVAL; frame = flap_frame_new(od, 0x02, 12+1+strlen(sn)); snacid = aim_cachesnac(od, 0x0002, 0x0005, 0x0000, NULL, 0); aim_putsnac(&frame->data, 0x0002, 0x0005, 0x0000, snacid); byte_stream_put16(&frame->data, infotype); byte_stream_put8(&frame->data, strlen(sn)); byte_stream_putstr(&frame->data, sn); flap_connection_send(conn, frame); return 0; }
/* * Subtype 0x0005 - Request info of another AIM user. * * @param bn The buddy name whose info you wish to request. * @param infotype The type of info you wish to request. * 0x0001 - Info/profile * 0x0003 - Away message * 0x0004 - Capabilities */ int aim_locate_getinfo(OscarData *od, const char *bn, guint16 infotype) { FlapConnection *conn; ByteStream bs; aim_snacid_t snacid; if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !bn) return -EINVAL; byte_stream_new(&bs, 2+1+strlen(bn)); snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0005, 0x0000, NULL, 0); byte_stream_put16(&bs, infotype); byte_stream_put8(&bs, strlen(bn)); byte_stream_putstr(&bs, bn); flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x0005, 0x0000, snacid, &bs); byte_stream_destroy(&bs); return 0; }
/** * Write the given OdcFrame to a ByteStream and send it out * on the established PeerConnection. */ static void peer_odc_send(PeerConnection *conn, OdcFrame *frame) { GaimAccount *account; const char *username; size_t length; ByteStream bs; gaim_debug_info("oscar", "Outgoing ODC frame to %s with " "type=0x%04x, flags=0x%04x, payload length=%u\n", conn->sn, frame->type, frame->flags, frame->payload.len); account = gaim_connection_get_account(conn->od->gc); username = gaim_account_get_username(account); memcpy(frame->sn, username, strlen(username)); memcpy(frame->cookie, conn->cookie, 8); length = 76; byte_stream_new(&bs, length + frame->payload.len); byte_stream_putraw(&bs, conn->magic, 4); byte_stream_put16(&bs, length); byte_stream_put16(&bs, frame->type); byte_stream_put16(&bs, frame->subtype); byte_stream_put16(&bs, 0x0000); byte_stream_putraw(&bs, frame->cookie, 8); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, 0x0000); byte_stream_put32(&bs, frame->payload.len); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, frame->encoding); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, frame->flags); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, 0x0000); byte_stream_putraw(&bs, frame->sn, 32); byte_stream_putraw(&bs, frame->payload.data, frame->payload.len); peer_connection_send(conn, &bs); g_free(bs.data); }
/* * Subtype 0x0005 - 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 */ int aim_chat_send_im(OscarData *od, FlapConnection *conn, guint16 flags, const gchar *msg, int msglen, const char *encoding, const char *language) { int i; ByteStream bs; IcbmCookie *cookie; aim_snacid_t snacid; guint8 ckstr[8]; GSList *tlvlist = NULL, *inner_tlvlist = NULL; if (!od || !conn || !msg || (msglen <= 0)) return 0; byte_stream_new(&bs, 1142); snacid = aim_cachesnac(od, SNAC_FAMILY_CHAT, 0x0005, 0x0000, NULL, 0); /* * Cookie * * XXX mkcookie should generate the cookie and cache it in one * operation to preserve uniqueness. */ for (i = 0; i < 8; i++) ckstr[i] = (guint8)rand(); cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL); cookie->data = NULL; /* XXX store something useful here */ aim_cachecookie(od, cookie); /* ICBM Header */ byte_stream_putraw(&bs, ckstr, 8); /* Cookie */ byte_stream_put16(&bs, 0x0003); /* Channel */ /* * Type 1: Flag meaning this message is destined to the room. */ aim_tlvlist_add_noval(&tlvlist, 0x0001); /* * Type 6: Reflect */ if (!(flags & AIM_CHATFLAGS_NOREFLECT)) aim_tlvlist_add_noval(&tlvlist, 0x0006); /* * Type 7: Autoresponse */ if (flags & AIM_CHATFLAGS_AWAY) aim_tlvlist_add_noval(&tlvlist, 0x0007); /* * SubTLV: Type 1: Message */ aim_tlvlist_add_raw(&inner_tlvlist, 0x0001, msglen, (guchar *)msg); /* * SubTLV: Type 2: Encoding */ if (encoding != NULL) aim_tlvlist_add_str(&inner_tlvlist, 0x0002, encoding); /* * SubTLV: Type 3: Language */ if (language != NULL) aim_tlvlist_add_str(&inner_tlvlist, 0x0003, language); /* * Type 5: Message block. Contains more TLVs. * * This could include other information... We just * put in a message TLV however. * */ aim_tlvlist_add_frozentlvlist(&tlvlist, 0x0005, &inner_tlvlist); aim_tlvlist_write(&bs, &tlvlist); aim_tlvlist_free(inner_tlvlist); aim_tlvlist_free(tlvlist); flap_connection_send_snac(od, conn, SNAC_FAMILY_CHAT, 0x0005, snacid, &bs); byte_stream_destroy(&bs); return 0; }