int CAimProto::aim_ssi_update_preferences(HANDLE hServerConn, unsigned short &seqno) { unsigned short offset = 0; char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4 + 100]; unsigned short req = 0x09; if (m_pref1_id == 0) { m_pref1_id = get_random(); req = 0x08; } aim_writesnac(0x13, req, offset, buf, get_random()); // SSI Edit/Add aim_writeshort(0, offset, buf); // group name length aim_writeshort(0, offset, buf); // group id (root) aim_writeshort(m_pref1_id, offset, buf); // buddy id aim_writeshort(5, offset, buf); // buddy type: Presence unsigned short tlv_len = TLV_HEADER_SIZE * 2 + 8; if (m_pref2_len) tlv_len += TLV_HEADER_SIZE + m_pref2_len; if (m_pref2_set_len) tlv_len += TLV_HEADER_SIZE + m_pref2_set_len; aim_writeshort(tlv_len, offset, buf); // length of extra data aim_writetlvlong(0xc9, m_pref1_flags, offset, buf); // Update Buddy preferences 1 aim_writetlvlong(0xd6, m_pref1_set_flags, offset, buf); // Update Buddy preferences 1 if (m_pref2_len) aim_writetlv(0xd7, m_pref2_len, m_pref2_flags, offset, buf); // Update Buddy preferences 2 if (m_pref2_set_len) aim_writetlv(0xd8, m_pref2_set_len, m_pref2_set_flags, offset, buf); // Update Buddy preferences 2 return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); }
int CAimProto::aim_set_status(HANDLE hServerConn,unsigned short &seqno,unsigned long status_type) { unsigned short offset=0; char buf[SNAC_SIZE+TLV_HEADER_SIZE*2]; aim_writesnac(0x01,0x1E,offset,buf); aim_writetlvlong(0x06,status_type,offset,buf); return aim_sendflap(hServerConn,0x02,offset,buf,seqno); }
int CAimProto::aim_set_pd_info(HANDLE hServerConn, unsigned short &seqno) { unsigned short offset = 0; char buf[SNAC_SIZE + TLV_HEADER_SIZE * 3 + 20]; unsigned short req = 0x09; if (m_pd_info_id == 0) { m_pd_info_id = get_random(); req = 0x08; } aim_writesnac(0x13, req, offset, buf, get_random()); // SSI Edit/Add aim_writeshort(0, offset, buf); // name length aim_writeshort(0, offset, buf); // group id (root) aim_writeshort(m_pd_info_id, offset, buf); // buddy id aim_writeshort(0x4, offset, buf); // pd info id aim_writeshort(0x15, offset, buf); // size aim_writetlvchar(0xca, m_pd_mode, offset, buf); // pd mode aim_writetlvlong(0xcb, 0xffffffff, offset, buf); // pd mask aim_writetlvlong(0xcc, m_pd_flags, offset, buf); // pd flags return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); }
int CAimProto::aim_auth_request(HANDLE hServerConn, unsigned short &seqno, const char* key, const char* language, const char* country, const char* username, const char* password) { unsigned short offset = 0; BYTE pass_hash[16]; BYTE auth_hash[16]; mir_md5_state_t state; mir_md5_init(&state); mir_md5_append(&state, (const BYTE *)password, (int)mir_strlen(password)); mir_md5_finish(&state, pass_hash); mir_md5_init(&state); mir_md5_append(&state, (BYTE*)key, (int)mir_strlen(key)); mir_md5_append(&state, (BYTE*)pass_hash, MD5_HASH_LENGTH); mir_md5_append(&state, (BYTE*)AIM_MD5_STRING, sizeof(AIM_MD5_STRING) - 1); mir_md5_finish(&state, auth_hash); char client_id[64], mirver[64]; CallService(MS_SYSTEM_GETVERSIONTEXT, sizeof(mirver), (LPARAM)mirver); int client_id_len = mir_snprintf(client_id, "Miranda AIM, version %s", mirver); char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 14 + MD5_HASH_LENGTH + mir_strlen(username) + client_id_len + 30 + mir_strlen(language) + mir_strlen(country)); aim_writesnac(0x17, 0x02, offset, buf); aim_writetlv(0x01, (unsigned short)mir_strlen(username), username, offset, buf); aim_writetlv(0x25, MD5_HASH_LENGTH, (char*)auth_hash, offset, buf); aim_writetlv(0x4C, 0, 0, offset, buf);//signifies new password hash instead of old method aim_writetlv(0x03, (unsigned short)client_id_len, client_id, offset, buf); aim_writetlvshort(0x17, AIM_CLIENT_MAJOR_VERSION, offset, buf); aim_writetlvshort(0x18, AIM_CLIENT_MINOR_VERSION, offset, buf); aim_writetlvshort(0x19, AIM_CLIENT_LESSER_VERSION, offset, buf); aim_writetlvshort(0x1A, AIM_CLIENT_BUILD_NUMBER, offset, buf); aim_writetlvshort(0x16, AIM_CLIENT_ID_NUMBER, offset, buf); aim_writetlvlong(0x14, AIM_CLIENT_DISTRIBUTION_NUMBER, offset, buf); aim_writetlv(0x0F, (unsigned short)mir_strlen(language), language, offset, buf); aim_writetlv(0x0E, (unsigned short)mir_strlen(country), country, offset, buf); aim_writetlvchar(0x4A, getByte(AIM_KEY_FSC, 0) ? 3 : 1, offset, buf); // aim_writetlvchar(0x94,0,offset,buf); if (!getByte(AIM_KEY_DSSL, 0)) aim_writetlv(0x8c, 0, NULL, offset, buf); // Request SSL connection return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); }
// used when requesting a regular file transfer int CAimProto::aim_send_file(HANDLE hServerConn, unsigned short &seqno, unsigned long ip, unsigned short port, bool force_proxy, file_transfer *ft) { char msg_frag[2048]; unsigned short frag_offset = 0; aim_writeshort(0, frag_offset, msg_frag); // request type aim_writegeneric(8, ft->icbm_cookie, frag_offset, msg_frag); // icbm cookie aim_writegeneric(AIM_CAPS_LENGTH, AIM_CAP_FILE_TRANSFER, frag_offset, msg_frag); // uuid aim_writetlvshort(0x0a, ++ft->req_num, frag_offset, msg_frag); // request number aim_writetlvlong(0x02, ip, frag_offset, msg_frag); // ip aim_writetlvlong(0x16, ~ip, frag_offset, msg_frag); // ip check aim_writetlvshort(0x05, port, frag_offset, msg_frag); // port aim_writetlvshort(0x17, ~port, frag_offset, msg_frag); // port ip check if (force_proxy) aim_writetlv(0x10, 0, 0, frag_offset, msg_frag); // request proxy transfer else aim_writetlvlong(0x03, m_internal_ip, frag_offset, msg_frag); // ip if (ft->req_num == 1) { if (ft->message) { aimString dscr(ft->message); const char* charset = dscr.isUnicode() ? "unicode-2-0" : "us-ascii"; const unsigned short charset_len = (unsigned short)mir_strlen(charset); const char* desc_msg = dscr.getBuf(); const unsigned short desc_len = dscr.getSize(); aim_writetlv(0x0e, 2, "en", frag_offset, msg_frag); // language used by the data aim_writetlv(0x0d, charset_len, charset, frag_offset, msg_frag);// charset used by the data aim_writetlv(0x0c, desc_len, desc_msg, frag_offset, msg_frag); // invitaion text } aim_writetlv(0x0f, 0, 0, frag_offset, msg_frag); // request host check const char* fname = get_fname(ft->file); const unsigned short fnlen = (unsigned short)mir_strlen(fname); char* fblock = (char*)alloca(9 + fnlen); *(unsigned short*)&fblock[0] = _htons(ft->pfts.totalFiles > 1 ? 2 : 1); // single file transfer *(unsigned short*)&fblock[2] = _htons(ft->pfts.totalFiles); // number of files *(unsigned long*)&fblock[4] = _htonl(ft->pfts.totalBytes); // total bytes in files memcpy(&fblock[8], fname, fnlen + 1); const char* enc = is_utf(fname) ? "utf-8" : "us-ascii"; aim_writetlv(0x2711, 9 + fnlen, fblock, frag_offset, msg_frag); // extra data, file names, size aim_writetlv(0x2712, 8, enc, frag_offset, msg_frag); // character set used by data // aim_writetlvlong64(0x2713,ft->pfts.totalBytes,frag_offset,msg_frag); // file length debugLogA("Attempting to Send a file to a buddy."); } else { aim_writetlvshort(0x14, 0x0a, frag_offset, msg_frag); // Counter proposal reason } unsigned short offset = 0; unsigned short sn_length = (unsigned short)mir_strlen(ft->sn); char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 2 + 12 + frag_offset + sn_length); aim_writesnac(0x04, 0x06, offset, buf); // msg to host aim_writegeneric(8, ft->icbm_cookie, offset, buf); // icbm cookie aim_writeshort(2, offset, buf); // icbm channel aim_writechar((unsigned char)sn_length, offset, buf); // screen name length aim_writegeneric(sn_length, ft->sn, offset, buf); // screen name aim_writetlv(0x05, frag_offset, msg_frag, offset, buf); // icbm tags aim_writetlv(0x03, 0, 0, offset, buf); // request ack char cip[20]; long_ip_to_char_ip(ip, cip); debugLogA("IP for Buddy to connect to: %s:%u", cip, port); return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; }