From 1ea84dc56d95ceaf85c036127c5045eba0ad50ee Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 13 Aug 2015 17:08:34 +0000 Subject: massive name conflict resolution git-svn-id: http://svn.miranda-ng.org/main/trunk@14941 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/AimOscar/src/server.cpp | 1665 +++++++++++++++---------------------- 1 file changed, 689 insertions(+), 976 deletions(-) (limited to 'protocols/AimOscar/src/server.cpp') diff --git a/protocols/AimOscar/src/server.cpp b/protocols/AimOscar/src/server.cpp index 15d9e4babe..a69a768d25 100644 --- a/protocols/AimOscar/src/server.cpp +++ b/protocols/AimOscar/src/server.cpp @@ -16,13 +16,14 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" -void CAimProto::snac_md5_authkey(SNAC &snac,HANDLE hServerConn,unsigned short &seqno, const char* username, const char* password)//family 0x0017 +void CAimProto::snac_md5_authkey(SNAC &snac, HANDLE hServerConn, unsigned short &seqno, const char* username, const char* password)//family 0x0017 { if (snac.subcmp(0x0007))//md5 authkey string { - unsigned short length=snac.ushort(); + unsigned short length = snac.ushort(); char* authkey = snac.part(2, length); aim_auth_request(hServerConn, seqno, authkey, AIM_LANGUAGE, AIM_COUNTRY, username, password); mir_free(authkey); @@ -32,31 +33,27 @@ void CAimProto::snac_md5_authkey(SNAC &snac,HANDLE hServerConn,unsigned short &s int CAimProto::snac_authorization_reply(SNAC &snac)//family 0x0017 { int res = 0; - - if (snac.subcmp(0x0003)) - { + + if (snac.subcmp(0x0003)) { char* server = NULL; int address = 0; unsigned short port; unsigned char use_ssl = 0; - while (address < snac.len()) - { + while (address < snac.len()) { TLV tlv(snac.val(address)); if (tlv.cmp(0x0005)) server = tlv.dup(); - else if (tlv.cmp(0x0006)) - { - Netlib_CloseHandle(hServerConn); + else if (tlv.cmp(0x0006)) { + Netlib_CloseHandle(m_hServerConn); if (server == NULL) return 3; char* delim = strchr(server, ':'); port = delim ? (unsigned short)atoi(delim + 1) : get_default_port(); if (delim) *delim = 0; - hServerConn = aim_connect(server, port, use_ssl != 0, "bos.oscar.aol.com"); - if (hServerConn) - { + m_hServerConn = aim_connect(server, port, use_ssl != 0, "bos.oscar.aol.com"); + if (m_hServerConn) { mir_free(COOKIE); COOKIE_LENGTH = tlv.len(); COOKIE = tlv.dup(); @@ -67,138 +64,125 @@ int CAimProto::snac_authorization_reply(SNAC &snac)//family 0x0017 res = 3; break; } - else if (tlv.cmp(0x0008)) - { + else if (tlv.cmp(0x0008)) { login_error(tlv.ushort()); res = 2; break; } - else if (tlv.cmp(0x0011)) - { + else if (tlv.cmp(0x0011)) { char* email = tlv.dup(); setString(AIM_KEY_EM, email); mir_free(email); } - else if (tlv.cmp(0x008e)) - { + else if (tlv.cmp(0x008e)) { use_ssl = tlv.ubyte(); } address += tlv.len() + 4; } mir_free(server); - } + } return res; } -void CAimProto::snac_supported_families(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0001 +void CAimProto::snac_supported_families(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0001 { if (snac.subcmp(0x0003))//server supported service list { - aim_send_service_request(hServerConn,seqno); + aim_send_service_request(hServerConn, seqno); } } -void CAimProto::snac_supported_family_versions(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0001 +void CAimProto::snac_supported_family_versions(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0001 { if (snac.subcmp(0x0018))//service list okayed { - aim_request_rates(hServerConn,seqno);//request some rate crap + aim_request_rates(hServerConn, seqno);//request some rate crap } } -void CAimProto::snac_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_request_icbm(hServerConn,seqno); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_request_icbm(hServerConn, seqno); } } -void CAimProto::snac_mail_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_mail_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_request_mail(hServerConn,seqno); - aim_activate_mail(hServerConn,seqno); - aim_mail_ready(hServerConn,seqno); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_request_mail(hServerConn, seqno); + aim_activate_mail(hServerConn, seqno); + aim_mail_ready(hServerConn, seqno); } } -void CAimProto::snac_avatar_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_avatar_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_avatar_ready(hServerConn,seqno); - SetEvent(hAvatarEvent); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_avatar_ready(hServerConn, seqno); + SetEvent(m_hAvatarEvent); } } -void CAimProto::snac_chatnav_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_chatnav_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_chatnav_request_limits(hChatNavConn,chatnav_seqno); // Get the max number of rooms we're allowed in. + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_chatnav_request_limits(m_hChatNavConn, m_chatnav_seqno); // Get the max number of rooms we're allowed in. } } -void CAimProto::snac_chat_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_chat_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_chat_ready(hServerConn,seqno); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_chat_ready(hServerConn, seqno); } } -void CAimProto::snac_icbm_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0004 +void CAimProto::snac_icbm_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0004 { - if (snac.subcmp(0x0005)) - { - switch (m_iDesiredStatus) - { + if (snac.subcmp(0x0005)) { + switch (m_iDesiredStatus) { case ID_STATUS_ONLINE: broadcast_status(ID_STATUS_ONLINE); - aim_set_status(hServerConn,seqno,AIM_STATUS_ONLINE); + aim_set_status(hServerConn, seqno, AIM_STATUS_ONLINE); break; case ID_STATUS_INVISIBLE: broadcast_status(ID_STATUS_INVISIBLE); - aim_set_status(hServerConn,seqno,AIM_STATUS_INVISIBLE); + aim_set_status(hServerConn, seqno, AIM_STATUS_INVISIBLE); break; case ID_STATUS_OCCUPIED: broadcast_status(ID_STATUS_OCCUPIED); - aim_set_status(hServerConn,seqno,AIM_STATUS_BUSY|AIM_STATUS_AWAY); + aim_set_status(hServerConn, seqno, AIM_STATUS_BUSY | AIM_STATUS_AWAY); break; case ID_STATUS_AWAY: broadcast_status(ID_STATUS_AWAY); - aim_set_status(hServerConn,seqno,AIM_STATUS_AWAY); + aim_set_status(hServerConn, seqno, AIM_STATUS_AWAY); break; } char** msgptr = get_status_msg_loc(m_iDesiredStatus); - mir_free(last_status_msg); - last_status_msg = msgptr ? mir_strdup(*msgptr) : NULL; - aim_set_statusmsg(hServerConn, seqno, last_status_msg); + replaceStr(m_last_status_msg, msgptr ? *msgptr: NULL); + aim_set_statusmsg(hServerConn, seqno, m_last_status_msg); if (m_iDesiredStatus == ID_STATUS_AWAY) - aim_set_away(hServerConn, seqno, last_status_msg, true); + aim_set_away(hServerConn, seqno, m_last_status_msg, true); - if (getByte(AIM_KEY_II,0)) - { + if (getByte(AIM_KEY_II, 0)) { unsigned long time = getDword(AIM_KEY_IIT, 0); - aim_set_idle(hServerConn,seqno,time*60); - instantidle=1; + aim_set_idle(hServerConn, seqno, time * 60); + m_instantidle = 1; } - aim_request_list(hServerConn,seqno); + aim_request_list(hServerConn, seqno); } } void CAimProto::snac_self_info(SNAC &snac)//family 0x0001 { - if (snac.subcmp(0x000f)) - { + if (snac.subcmp(0x000f)) { int offset = snac.flags() & 0x8000 ? snac.ushort(0) + 2 : 0; unsigned char sn_len = snac.ubyte(offset++); @@ -208,14 +192,12 @@ void CAimProto::snac_self_info(SNAC &snac)//family 0x0001 int tlv_count = snac.ushort(offset); offset += 2; - for (int i = 0; i < tlv_count; i++) - { + for (int i = 0; i < tlv_count; i++) { TLV tlv(snac.val(offset)); offset += TLV_HEADER_SIZE + tlv.len(); - if (tlv.cmp(0x000a)) - { - detected_ip = tlv.ulong(); + if (tlv.cmp(0x000a)) { + m_detected_ip = tlv.ulong(); } } mir_free(sn); @@ -224,8 +206,7 @@ void CAimProto::snac_self_info(SNAC &snac)//family 0x0001 void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 { - if (snac.subcmp(0x000b)) - { + if (snac.subcmp(0x000b)) { char client[100] = ""; bool hiptop_user = false; bool bot_user = false; @@ -244,53 +225,48 @@ void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 int tlv_count = snac.ushort(offset); offset += 2; - for (int i = 0; i < tlv_count; i++) - { + for (int i = 0; i < tlv_count; i++) { TLV tlv(snac.val(offset)); offset += TLV_HEADER_SIZE; - if (tlv.cmp(0x0001))//user m_iStatus - { + if (tlv.cmp(0x0001)) { // user m_iStatus unsigned short status = tlv.ushort(); int unconfirmed = status & 0x0001; - int admin_aol = status & 0x0002; - int aol = status & 0x0004; + int admin_aol = status & 0x0002; + int aol = status & 0x0004; //int nonfree = status & 0x0008; //int aim = status & 0x0010; - int away = status & 0x0020; - int icq = status & 0x0040; - int wireless = status & 0x0080; - int bot = status & 0x0400; + int away = status & 0x0020; + int icq = status & 0x0040; + int wireless = status & 0x0080; + int bot = status & 0x0400; setString(hContact, AIM_KEY_NK, sn); if (icq) setString(hContact, "Transport", "ICQ"); else - delSetting(hContact, "Transport" ); + delSetting(hContact, "Transport"); if (admin_aol) setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_ADMIN); else if (aol) - setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_AOL); + setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_AOL); else if (icq) - setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_ICQ); + setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_ICQ); else if (unconfirmed) setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_UNCONFIRMED); else setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_CONFIRMED); - if (bot) - { - mir_strcpy(client,CLIENT_BOT); - bot_user=1; + if (bot) { + mir_strcpy(client, CLIENT_BOT); + bot_user = 1; } - if (wireless) - { - mir_strcpy(client,CLIENT_SMS); - wireless_user=1; + if (wireless) { + mir_strcpy(client, CLIENT_SMS); + wireless_user = 1; } - else if (away) - { - away_user=1; + else if (away) { + away_user = 1; } setDword(hContact, AIM_KEY_IT, 0);//erase idle time setDword(hContact, AIM_KEY_OT, 0);//erase online time @@ -299,241 +275,215 @@ void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 { status_type = tlv.ulong() & 0x00000FFF; } - else if (tlv.cmp(0x000d)) - { + else if (tlv.cmp(0x000d)) { caps_included = true; - for(int i = 0; i 2) - { - unsigned short len = tlv.ushort(i + 4); - if (len) - { + if ((flags & 4) && datalen > 2) { + unsigned short len = tlv.ushort(k + 4); + if (len) { msg_exist = true; - char* msg = tlv.part(i + 6, len); + char* msg = tlv.part(k + 6, len); char* msg_s = process_status_msg(msg, sn); db_set_utf(hContact, MOD_KEY_CL, OTH_KEY_SM, msg_s); @@ -546,32 +496,28 @@ void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 } break; } - i += 4 + datalen; + k += 4 + datalen; } if (!msg_exist) db_unset(hContact, MOD_KEY_CL, OTH_KEY_SM); } } - else if (tlv.cmp(0x0004))//idle tlv - { - if (hContact) - { + else if (tlv.cmp(0x0004)) { //idle tlv + if (hContact) { time_t current_time; time(¤t_time); setDword(hContact, AIM_KEY_IT, ((DWORD)current_time) - tlv.ushort() * 60); } } - else if (tlv.cmp(0x0003))//online time tlv - { + else if (tlv.cmp(0x0003)) { // online time tlv if (hContact) setDword(hContact, AIM_KEY_OT, tlv.ulong()); } - else if (tlv.cmp(0x0005))//member since - { - if (hContact) - setDword(hContact, AIM_KEY_MS, tlv.ulong()); - } + else if (tlv.cmp(0x0005)) { // member since + if (hContact) + setDword(hContact, AIM_KEY_MS, tlv.ulong()); + } offset += tlv.len(); } @@ -617,10 +563,10 @@ void CAimProto::snac_user_offline(SNAC &snac)//family 0x0003 { if (snac.subcmp(0x000c)) { unsigned char buddy_length = snac.ubyte(); - char* buddy=snac.part(1,buddy_length); - MCONTACT hContact=contact_from_sn(buddy, true); + char* buddy = snac.part(1, buddy_length); + MCONTACT hContact = contact_from_sn(buddy, true); if (hContact) - offline_contact(hContact,0); + offline_contact(hContact, 0); mir_free(buddy); } } @@ -633,12 +579,12 @@ void CAimProto::snac_error(SNAC &snac)//family 0x0003 or 0x0004 void CAimProto::process_ssi_list(SNAC &snac, int &offset) { unsigned short name_length = snac.ushort(offset); - char* name = snac.part(offset+2, name_length); - unsigned short group_id = snac.ushort(offset+ 2 +name_length); - unsigned short item_id = snac.ushort(offset+4+name_length); - unsigned short type = snac.ushort(offset+6+name_length); - unsigned short tlv_size = snac.ushort(offset+8+name_length); - const int tlv_base = offset + name_length + 10; + char* name = snac.part(offset + 2, name_length); + unsigned short group_id = snac.ushort(offset + 2 + name_length); + unsigned short item_id = snac.ushort(offset + 4 + name_length); + unsigned short type = snac.ushort(offset + 6 + name_length); + unsigned short tlv_size = snac.ushort(offset + 8 + name_length); + const int tlv_base = offset + name_length + 10; switch (type) { case 0x0000: //buddy record @@ -654,7 +600,7 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) } } if (i == 1 && getByte(AIM_KEY_MG, 1)) { - const char* group = group_list.find_name(group_id); + const char* group = m_group_list.find_name(group_id); if (group) { bool ok = false; DBVARIANT dbv; @@ -694,36 +640,36 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) if (!nickfound && getDword(AIM_KEY_LV, 0) >= 0x80500) db_unset(hContact, MOD_KEY_CL, "MyHandle"); } - } + } break; case 0x0001: //group record if (group_id) { - group_list.add(name, group_id); + m_group_list.add(name, group_id); if (getByte(AIM_KEY_MG, 1)) create_group(name); } break; case 0x0002: //permit record - allow_list.add(name, item_id); + m_allow_list.add(name, item_id); break; case 0x0003: //deny record - block_list.add(name, item_id); + m_block_list.add(name, item_id); break; case 0x0004: //privacy record if (group_id == 0) { - pd_info_id = item_id; + m_pd_info_id = item_id; for (int tlv_offset = 0; tlv_offset < tlv_size;) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00ca)) - pd_mode = tlv.ubyte(); + m_pd_mode = tlv.ubyte(); else if (tlv.cmp(0x00cc)) - pd_flags = tlv.ulong(); + m_pd_flags = tlv.ulong(); tlv_offset += TLV_HEADER_SIZE + tlv.len(); } @@ -732,24 +678,24 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) case 0x0005: //prefernces record if (group_id == 0) { - pref1_id = item_id; + m_pref1_id = item_id; for (int tlv_offset = 0; tlv_offset < tlv_size;) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00c9)) - pref1_flags = tlv.ulong(); + m_pref1_flags = tlv.ulong(); else if (tlv.cmp(0x00d6)) - pref1_set_flags = tlv.ulong(); + m_pref1_set_flags = tlv.ulong(); else if (tlv.cmp(0x00d7)) { - mir_free(pref2_flags); - pref2_flags = tlv.dup(); - pref2_len = tlv.len(); + mir_free(m_pref2_flags); + m_pref2_flags = tlv.dup(); + m_pref2_len = tlv.len(); } else if (tlv.cmp(0x00d8)) { - mir_free(pref2_set_flags); - pref2_set_flags = tlv.dup(); - pref2_set_len = tlv.len(); + mir_free(m_pref2_set_flags); + m_pref2_set_flags = tlv.dup(); + m_pref2_set_len = tlv.len(); } tlv_offset += TLV_HEADER_SIZE + tlv.len(); @@ -760,27 +706,27 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) case 0x0014: //avatar record if (!mir_strcmp(name, "1") || !mir_strcmp(name, "12")) { if (name_length == 1) - avatar_id_sm = item_id; + m_avatar_id_sm = item_id; else - avatar_id_lg = item_id; + m_avatar_id_lg = item_id; for (int tlv_offset = 0; tlv_offset < tlv_size;) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00d5) && tlv.len() > 2) { if (name_length == 1) { - mir_free(hash_sm); - hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + mir_free(m_hash_sm); + m_hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } else { - mir_free(hash_lg); - hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + mir_free(m_hash_lg); + m_hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } } tlv_offset += TLV_HEADER_SIZE + tlv.len(); } - if (list_received) + if (m_list_received) avatar_request_handler(NULL, NULL, 0); } break; @@ -813,26 +759,22 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) void CAimProto::modify_ssi_list(SNAC &snac, int &offset) { unsigned short name_length = snac.ushort(offset); - char* name = snac.part(offset+2, name_length); - unsigned short group_id = snac.ushort(offset+ 2 +name_length); - unsigned short item_id = snac.ushort(offset+4+name_length); - unsigned short type = snac.ushort(offset+6+name_length); - unsigned short tlv_size = snac.ushort(offset+8+name_length); - const int tlv_base = offset + name_length + 10; - - switch (type) - { + char* name = snac.part(offset + 2, name_length); + unsigned short group_id = snac.ushort(offset + 2 + name_length); + unsigned short item_id = snac.ushort(offset + 4 + name_length); + unsigned short type = snac.ushort(offset + 6 + name_length); + unsigned short tlv_size = snac.ushort(offset + 8 + name_length); + const int tlv_base = offset + name_length + 10; + + switch (type) { case 0x0000: //buddy record { MCONTACT hContact = contact_from_sn(name, true); - if (hContact) - { - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { + if (hContact) { + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { TLV tlv(snac.val(tlv_base + tlv_offset)); - if (tlv.cmp(0x0131) && tlv.len()) - { + if (tlv.cmp(0x0131) && tlv.len()) { char* nick = tlv.dup(); if (nick) db_set_utf(hContact, MOD_KEY_CL, "MyHandle", nick); @@ -848,18 +790,16 @@ void CAimProto::modify_ssi_list(SNAC &snac, int &offset) } case 0x0004: //privacy record - if (group_id == 0) - { - pd_info_id = item_id; + if (group_id == 0) { + m_pd_info_id = item_id; - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00ca)) - pd_mode = tlv.ubyte(); + m_pd_mode = tlv.ubyte(); else if (tlv.cmp(0x00cc)) - pd_flags = tlv.ulong(); + m_pd_flags = tlv.ulong(); tlv_offset += TLV_HEADER_SIZE + tlv.len(); } @@ -867,29 +807,25 @@ void CAimProto::modify_ssi_list(SNAC &snac, int &offset) break; case 0x0005: //prefernces record - if (group_id == 0) - { - pref1_id = item_id; + if (group_id == 0) { + m_pref1_id = item_id; - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00c9)) - pref1_flags = tlv.ulong(); + m_pref1_flags = tlv.ulong(); else if (tlv.cmp(0x00d6)) - pref1_set_flags = tlv.ulong(); - else if (tlv.cmp(0x00d7)) - { - mir_free(pref2_flags); - pref2_flags = tlv.dup(); - pref2_len = tlv.len(); + m_pref1_set_flags = tlv.ulong(); + else if (tlv.cmp(0x00d7)) { + mir_free(m_pref2_flags); + m_pref2_flags = tlv.dup(); + m_pref2_len = tlv.len(); } - else if (tlv.cmp(0x00d8)) - { - mir_free(pref2_set_flags); - pref2_set_flags = tlv.dup(); - pref2_set_len = tlv.len(); + else if (tlv.cmp(0x00d8)) { + mir_free(m_pref2_set_flags); + m_pref2_set_flags = tlv.dup(); + m_pref2_set_len = tlv.len(); } tlv_offset += TLV_HEADER_SIZE + tlv.len(); @@ -898,29 +834,24 @@ void CAimProto::modify_ssi_list(SNAC &snac, int &offset) break; case 0x0014: //avatar record - if (!mir_strcmp(name, "1") || !mir_strcmp(name, "12")) - { + if (!mir_strcmp(name, "1") || !mir_strcmp(name, "12")) { if (name_length == 1) - avatar_id_sm = item_id; + m_avatar_id_sm = item_id; else - avatar_id_lg = item_id; + m_avatar_id_lg = item_id; - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { - TLV tlv(snac.val( tlv_base + tlv_offset)); + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { + TLV tlv(snac.val(tlv_base + tlv_offset)); - if (tlv.cmp(0x00d5) && tlv.len() > 2) - { -// unsigned char type = tlv.ubyte(0); - if (name_length == 1) - { - mir_free(hash_sm); - hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + if (tlv.cmp(0x00d5) && tlv.len() > 2) { + // unsigned char type = tlv.ubyte(0); + if (name_length == 1) { + mir_free(m_hash_sm); + m_hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } - else - { - mir_free(hash_lg); - hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + else { + mir_free(m_hash_lg); + m_hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } } tlv_offset += TLV_HEADER_SIZE + tlv.len(); @@ -937,23 +868,21 @@ void CAimProto::delete_ssi_list(SNAC &snac, int &offset) { int i; - unsigned short name_length=snac.ushort(offset); - char* name=snac.part(offset+2,name_length); - unsigned short group_id=snac.ushort(offset+2+name_length); - unsigned short item_id=snac.ushort(offset+4+name_length); - unsigned short type=snac.ushort(offset+6+name_length); + unsigned short name_length = snac.ushort(offset); + char* name = snac.part(offset + 2, name_length); + unsigned short group_id = snac.ushort(offset + 2 + name_length); + unsigned short item_id = snac.ushort(offset + 4 + name_length); + unsigned short type = snac.ushort(offset + 6 + name_length); MCONTACT hContact = contact_from_sn(name); switch (type) { case 0x0000: //buddy record - for(i=1;;++i) - { + for (i = 1;; ++i) { unsigned short item_id_st = getBuddyId(hContact, i); if (item_id_st == 0) break; - if (item_id == item_id_st) - { + if (item_id == item_id_st) { deleteBuddyId(hContact, i); deleteGroupId(hContact, i); --i; @@ -964,60 +893,55 @@ void CAimProto::delete_ssi_list(SNAC &snac, int &offset) break; case 0x0001: //group record - group_list.remove_by_id(group_id); + m_group_list.remove_by_id(group_id); break; case 0x0014: //avatar record - if (mir_strcmp(name, "1")) - { - avatar_id_sm = 0; - mir_free(hash_sm); - hash_sm = NULL; + if (mir_strcmp(name, "1")) { + m_avatar_id_sm = 0; + mir_free(m_hash_sm); + m_hash_sm = NULL; } - else if (!mir_strcmp(name, "12")) - { - avatar_id_lg = 0; - mir_free(hash_lg); - hash_lg = NULL; + else if (!mir_strcmp(name, "12")) { + m_avatar_id_lg = 0; + mir_free(m_hash_lg); + m_hash_lg = NULL; } avatar_request_handler(NULL, NULL, 0); break; } - mir_free(name) ; + mir_free(name); } -void CAimProto::snac_contact_list(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0013 +void CAimProto::snac_contact_list(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0013 { - if (snac.subcmp(0x0006)) //contact list - { + if (snac.subcmp(0x0006)) { //contact list debugLogA("Contact List Received"); -// unsigned char ver = snac.ubyte(); + // unsigned char ver = snac.ubyte(); int num_obj = snac.ushort(1); - int offset=3; - for (int i=0; ihContact = hContact; msg_ack->id = *(int*)icbm_cookie & 0x7fffffff; @@ -1070,60 +988,56 @@ void CAimProto::snac_message_accepted(SNAC &snac)//family 0x004 mir_free(icbm_cookie); } } -void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0004 +void CAimProto::snac_received_message(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0004 { - if (snac.subcmp(0x0007)) - { - unsigned short channel = snac.ushort(8); + if (snac.subcmp(0x0007)) { + unsigned short channel = snac.ushort(8); unsigned char sn_length = snac.ubyte(10); - char* sn = snac.part(11,sn_length); + char *sn = snac.part(11, sn_length); MCONTACT hContact = contact_from_sn(sn, true, true), hMsgContact = NULL; - int offset=15+sn_length; + int offset = 15 + sn_length; - char* msg_buf=NULL; + char *msg_buf = NULL; unsigned long offline_timestamp = 0; bool is_offline = false; //file transfer stuff - char* icbm_cookie = NULL; - char* filename = NULL; - unsigned __int64 file_size=0; - bool auto_response=false; - bool force_proxy=false; - bool descr_included=false; - bool utf_fname=false; - bool unicode_descr=false; - short rdz_msg_type=-1; - unsigned short request_num=0; - unsigned long local_ip=0, verified_ip=0, proxy_ip=0; + char *icbm_cookie = NULL; + char *filename = NULL; + unsigned __int64 file_size = 0; + bool auto_response = false; + bool force_proxy = false; + bool descr_included = false; + bool utf_fname = false; + bool unicode_descr = false; + short rdz_msg_type = -1; + unsigned short request_num = 0; + unsigned long local_ip = 0, verified_ip = 0, proxy_ip = 0; unsigned short port = 0; unsigned short max_ver = 0; unsigned short num_files = 0; //end file transfer stuff - unsigned short tlv_head_num=snac.ushort(offset-2); - for (int i=0;i=snac.len()) break; + if (offset >= snac.len()) break; } - - while (offset < snac.len()) - { + + while (offset < snac.len()) { TLV tlv(snac.val(offset)); offset += TLV_HEADER_SIZE; - if (tlv.cmp(0x0004)&&!tlv.len())//auto response flag + if (tlv.cmp(0x0004) && !tlv.len())//auto response flag auto_response = 1; - if (tlv.cmp(0x0002)) //msg - { - unsigned short caps_length=tlv.ushort(2); - unsigned short msg_length=tlv.ushort(6+caps_length)-4; - unsigned short encoding=tlv.ushort(8+caps_length); - char* buf = tlv.part(12+caps_length,msg_length); + if (tlv.cmp(0x0002)) { // msg + unsigned short caps_length = tlv.ushort(2); + unsigned short msg_length = tlv.ushort(6 + caps_length) - 4; + unsigned short encoding = tlv.ushort(8 + caps_length); + char *buf = tlv.part(12 + caps_length, msg_length); if (hContact) { wchar_t* wbuf; hMsgContact = hContact; @@ -1156,39 +1070,39 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho if (channel == 2 && tlv.cmp(0x0005)) { //recv rendervous packet rdz_msg_type = snac.ushort(offset); - icbm_cookie = snac.part(offset+2,8); - if (cap_cmp(snac.val(offset+10), AIM_CAP_FILE_TRANSFER) == 0) { + icbm_cookie = snac.part(offset + 2, 8); + if (cap_cmp(snac.val(offset + 10), AIM_CAP_FILE_TRANSFER) == 0) { for (int i = 26; i < tlv.len(); ) { - TLV tlv(snac.val(offset+i)); - if (tlv.cmp(0x000A)) - request_num=tlv.ushort();//for file transfer - else if (tlv.cmp(0x0002))//proxy ip - proxy_ip = tlv.ulong(); - else if (tlv.cmp(0x0003))//client ip - local_ip = tlv.ulong(); - else if (tlv.cmp(0x0004))//verified ip - verified_ip = tlv.ulong(); - else if (tlv.cmp(0x0005)) - port=tlv.ushort(); - else if (tlv.cmp(0x0010)) - force_proxy=1; - else if (tlv.cmp(0x0012)) - max_ver = tlv.ushort(); - else if (tlv.cmp(0x2711)) { - num_files = tlv.ushort(2); - file_size = tlv.ulong(4); - filename = tlv.part(8, tlv.len()-8); + TLV tlv2(snac.val(offset + i)); + if (tlv2.cmp(0x000A)) + request_num = tlv2.ushort();//for file transfer + else if (tlv2.cmp(0x0002))//proxy ip + proxy_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0003))//client ip + local_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0004))//verified ip + verified_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0005)) + port = tlv2.ushort(); + else if (tlv2.cmp(0x0010)) + force_proxy = 1; + else if (tlv2.cmp(0x0012)) + max_ver = tlv2.ushort(); + else if (tlv2.cmp(0x2711)) { + num_files = tlv2.ushort(2); + file_size = tlv2.ulong(4); + filename = tlv2.part(8, tlv2.len() - 8); } - else if (tlv.cmp(0x2712)) { - char* enc = tlv.dup(); + else if (tlv2.cmp(0x2712)) { + char *enc = tlv2.dup(); utf_fname = mir_strcmp(enc, "utf-8") == 0; mir_free(enc); } - else if (tlv.cmp(0x2713)) { - file_size = tlv.u64(); + else if (tlv2.cmp(0x2713)) { + file_size = tlv2.u64(); } - else if (tlv.cmp(0x000c)) { - msg_buf = unicode_descr ? tlv.dupw() : tlv.dup(); + else if (tlv2.cmp(0x000c)) { + msg_buf = unicode_descr ? tlv2.dupw() : tlv2.dup(); html_decode(msg_buf); descr_included = true; if (strstr(msg_buf, "")) { @@ -1202,46 +1116,46 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho else descr_included = false; } } - else if (tlv.cmp(0x000d)) { - char* enc = tlv.dup(); + else if (tlv2.cmp(0x000d)) { + char* enc = tlv2.dup(); unicode_descr = mir_strcmp(enc, "unicode-2-0") == 0; mir_free(enc); } - i += TLV_HEADER_SIZE + tlv.len(); + i += TLV_HEADER_SIZE + tlv2.len(); } } - else if (cap_cmp(snac.val(offset+10), AIM_CAP_RTCAUDIO) == 0 || cap_cmp(snac.val(offset+10), AIM_CAP_RTCVIDEO) == 0) { + else if (cap_cmp(snac.val(offset + 10), AIM_CAP_RTCAUDIO) == 0 || cap_cmp(snac.val(offset + 10), AIM_CAP_RTCVIDEO) == 0) { for (int i = 26; i < tlv.len(); ) { - TLV tlv(snac.val(offset+i)); - if (tlv.cmp(0x000A)) - request_num=tlv.ushort();//for file transfer - else if (tlv.cmp(0x0002))//proxy ip - proxy_ip = tlv.ulong(); - else if (tlv.cmp(0x0003))//client ip - local_ip = tlv.ulong(); - else if (tlv.cmp(0x0004))//verified ip - verified_ip = tlv.ulong(); - else if (tlv.cmp(0x0005)) - port=tlv.ushort(); + TLV tlv2(snac.val(offset + i)); + if (tlv2.cmp(0x000A)) + request_num = tlv2.ushort();//for file transfer + else if (tlv2.cmp(0x0002))//proxy ip + proxy_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0003))//client ip + local_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0004))//verified ip + verified_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0005)) + port = tlv2.ushort(); } channel = 0; break; } - else if (cap_cmp(snac.val(offset+10), AIM_CAP_CHAT) == 0) { //it's a chat invite request - for(int i=26; i < tlv.len();) { - TLV tlv(snac.val(offset+i)); - if (tlv.cmp(0x000c)) //optional message - msg_buf = tlv.dup(); - else if (tlv.cmp(0x2711)) { //room information - int cookie_len=tlv.ubyte(2); - chatnav_param* par = - new chatnav_param(tlv.part(3,cookie_len), tlv.ushort(), tlv.ushort(3+cookie_len), - msg_buf, sn, icbm_cookie); + else if (cap_cmp(snac.val(offset + 10), AIM_CAP_CHAT) == 0) { //it's a chat invite request + for (int i = 26; i < tlv.len();) { + TLV tlv2(snac.val(offset + i)); + if (tlv2.cmp(0x000c)) //optional message + msg_buf = tlv2.dup(); + else if (tlv2.cmp(0x2711)) { //room information + int cookie_len = tlv2.ubyte(2); + chatnav_param* par = + new chatnav_param(tlv2.part(3, cookie_len), tlv2.ushort(), tlv2.ushort(3 + cookie_len), + msg_buf, sn, icbm_cookie); invite_chat_req_param* chat_rq = new invite_chat_req_param(par, this, msg_buf, sn, icbm_cookie); CallFunctionAsync(chat_request_cb, chat_rq); } - i+=TLV_HEADER_SIZE+tlv.len(); + i += TLV_HEADER_SIZE + tlv2.len(); } } else { @@ -1251,7 +1165,7 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho } if (channel == 6 && tlv.cmp(0x0005))//audio/video tunnel - msg_buf = tlv.dup(); + msg_buf = tlv.dup(); if (tlv.cmp(0x0006))//Offline message flag is_offline = true; @@ -1281,13 +1195,11 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho ProtoChainRecvMsg(hMsgContact, &pre); } - if (m_iStatus==ID_STATUS_AWAY && !auto_response && !getByte(AIM_KEY_DM,0)) - { + if (m_iStatus == ID_STATUS_AWAY && !auto_response && !getByte(AIM_KEY_DM, 0)) { unsigned long msg_time = getDword(hContact, AIM_KEY_LM, 0); unsigned long away_time = getDword(AIM_KEY_LA, 0); char** msgptr = get_status_msg_loc(m_iStatus); - if (away_time > msg_time && *msgptr) - { + if (away_time > msg_time && *msgptr) { char* s_msg = process_status_msg(*msgptr, sn); T2Utf away(TranslateT("[Auto-Response]:")); @@ -1310,10 +1222,8 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho setDword(hContact, AIM_KEY_LM, (DWORD)time(NULL)); } } - else if (channel == 2) // File Transfer - { - if (rdz_msg_type == 0 && request_num == 1) //buddy wants to send us a file - { + else if (channel == 2) { // File Transfer + if (rdz_msg_type == 0 && request_num == 1) { // buddy wants to send us a file debugLogA("Buddy Wants to Send us a file. Request 1"); debugLogA(force_proxy ? "Forcing a Proxy File transfer." : "Not forcing Proxy File transfer."); @@ -1329,11 +1239,11 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho ft->req_num = request_num; ft->file = mir_strdup(filename); - + ft->pfts.totalBytes = file_size; ft->pfts.totalFiles = num_files; - ft_list.insert(ft); + m_ft_list.insert(ft); if (!descr_included) msg_buf = NULL; @@ -1356,14 +1266,12 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho debugLogA("Verified IP: %s:%u", long_ip_to_char_ip(verified_ip, cip), port); debugLogA("Proxy IP: %s:%u", long_ip_to_char_ip(proxy_ip, cip), port); } - else if (rdz_msg_type == 0) - { + else if (rdz_msg_type == 0) { debugLogA("We are sending a file. Buddy wants us to connect to them. Request %d", request_num); debugLogA(force_proxy ? "Forcing a Proxy File transfer." : "Not forcing Proxy File transfer."); - file_transfer* ft = ft_list.find_by_cookie(icbm_cookie, hContact); - if (ft) - { + file_transfer* ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); + if (ft) { ft->hContact = hContact; ft->me_force_proxy |= (request_num > 2); @@ -1383,31 +1291,26 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho ForkThread(&CAimProto::accept_file_thread, ft); } - else - { + else { debugLogA("Unknown File transfer, thus denied."); aim_file_ad(hServerConn, seqno, sn, icbm_cookie, true, 0); } } - else if (rdz_msg_type == 1)//buddy cancelled or denied file transfer - { + else if (rdz_msg_type == 1) { // buddy cancelled or denied file transfer debugLogA("File transfer cancelled or denied."); - file_transfer* ft = ft_list.find_by_cookie(icbm_cookie, hContact); + file_transfer *ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_DENIED, ft, 0); - ft_list.remove_by_ft(ft); + m_ft_list.remove_by_ft(ft); } - else if (rdz_msg_type == 2)//buddy accepts our file transfer request - { + else if (rdz_msg_type == 2) { // buddy accepts our file transfer request debugLogA("File transfer accepted"); - file_transfer* ft = ft_list.find_by_cookie(icbm_cookie, hContact); - if (ft) - { - ft->accepted = true; + file_transfer *ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); + if (ft) { + ft->accepted = true; ft->max_ver = max_ver; } - else - aim_file_ad(hServerConn, seqno, sn, icbm_cookie, true, 0); + else aim_file_ad(hServerConn, seqno, sn, icbm_cookie, true, 0); } } else if (channel == 6) // Audio/Video call @@ -1425,15 +1328,12 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho void CAimProto::snac_file_decline(SNAC &snac)//family 0x0004 { - if (snac.subcmp(0x000b)) - { + if (snac.subcmp(0x000b)) { char *icbm_cookie = snac.part(0, 8); int channel = snac.ushort(8); - if (channel == 0x01) - { + if (channel == 0x01) { int sn_len = snac.ubyte(10); - char* sn = snac.part(11, sn_len); -// int reason = snac.ushort(11 + sn_len); + char *sn = snac.part(11, sn_len); MCONTACT hContact = contact_from_sn(sn); msg_ack_param *msg_ack = (msg_ack_param*)mir_alloc(sizeof(msg_ack_param)); @@ -1443,24 +1343,23 @@ void CAimProto::snac_file_decline(SNAC &snac)//family 0x0004 msg_ack->success = false; ForkThread(&CAimProto::msg_ack_success, msg_ack); } - if (channel == 0x02) - { + + if (channel == 0x02) { int sn_len = snac.ubyte(10); - char* sn = snac.part(11, sn_len); + char *sn = snac.part(11, sn_len); int reason = snac.ushort(11 + sn_len); - if (reason == 0x03) - { + if (reason == 0x03) { int error = snac.ushort(13 + sn_len); - if (error == 0x02) - { + if (error == 0x02) { debugLogA("File Transfer declied"); MCONTACT hContact = contact_from_sn(sn); - file_transfer *ft = ft_list.find_by_cookie(icbm_cookie, hContact); - if (ft) - { + file_transfer *ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); + if (ft) { ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_DENIED, ft, 0); - if (ft->hConn) Netlib_Shutdown(ft->hConn); - else ft_list.remove_by_ft(ft); + if (ft->hConn) + Netlib_Shutdown(ft->hConn); + else + m_ft_list.remove_by_ft(ft); } } } @@ -1471,8 +1370,7 @@ void CAimProto::snac_file_decline(SNAC &snac)//family 0x0004 } void CAimProto::snac_received_info(SNAC &snac)//family 0x0002 { - if (snac.subcmp(0x0006)) - { + if (snac.subcmp(0x0006)) { unsigned short offset = 0; int i = 0; bool away_message_received = false; @@ -1486,38 +1384,32 @@ void CAimProto::snac_received_info(SNAC &snac)//family 0x0002 unsigned short tlv_count = snac.ushort(3 + sn_length); offset = 5 + sn_length; MCONTACT hContact = contact_from_sn(sn, true, true); - - while (offset < snac.len()) - { + + while (offset < snac.len()) { TLV tlv(snac.val(offset)); - if (++i > tlv_count) - { - if (tlv.cmp(0x0001))//profile encoding - { - char* enc = tlv.dup(); + if (++i > tlv_count) { + if (tlv.cmp(0x0001)) { //profile encoding + char *enc = tlv.dup(); profile_unicode = strstr(enc, "unicode-2-0") != NULL; profile_utf = strstr(enc, "utf-8") != NULL; mir_free(enc); } - else if (tlv.cmp(0x0002))//profile message string - { - char* msg = profile_unicode ? tlv.dupw() : tlv.dup(); + else if (tlv.cmp(0x0002)) { //profile message string + char *msg = profile_unicode ? tlv.dupw() : tlv.dup(); profile_received = true; write_profile(sn, msg, profile_unicode | profile_utf); mir_free(msg); } - else if (tlv.cmp(0x0003))//away message encoding - { - char* enc = tlv.dup(); + else if (tlv.cmp(0x0003)) { //away message encoding + char *enc = tlv.dup(); away_message_unicode = strstr(enc, "unicode-2-0") != NULL; away_message_utf = strstr(enc, "utf-8") != NULL; mir_free(enc); } - else if (tlv.cmp(0x0004))//away message string - { - char* msg = away_message_unicode ? tlv.dupw() : tlv.dup(); + else if (tlv.cmp(0x0004)) { // away message string + char *msg = away_message_unicode ? tlv.dupw() : tlv.dup(); away_message_received = true; write_away_message(sn, msg, away_message_unicode | away_message_utf); @@ -1526,56 +1418,49 @@ void CAimProto::snac_received_info(SNAC &snac)//family 0x0002 } offset += TLV_HEADER_SIZE + tlv.len(); } - if (hContact) - { - if (getWord(hContact,AIM_KEY_ST,ID_STATUS_OFFLINE) == ID_STATUS_AWAY) - { - if (!away_message_received && request_away_message) - write_away_message(sn,Translate("No information has been provided by the server."),false); - request_away_message = 0; - } - if (!profile_received&&request_HTML_profile) - write_profile(sn,"No Profile",false); - request_HTML_profile=0; + if (hContact) { + if (getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_AWAY) { + if (!away_message_received && m_request_away_message) + write_away_message(sn, Translate("No information has been provided by the server."), false); + m_request_away_message = 0; + } + if (!profile_received && m_request_HTML_profile) + write_profile(sn, "No Profile", false); + m_request_HTML_profile = 0; } mir_free(sn); } } void CAimProto::snac_typing_notification(SNAC &snac)//family 0x004 { - if (snac.subcmp(0x0014)) - { - unsigned char sn_length=snac.ubyte(10); - char* sn=snac.part(11,sn_length); - MCONTACT hContact=contact_from_sn(sn); - if (hContact) - { - unsigned short type=snac.ushort(11+sn_length); - if (type==0x0000)//typing finished - CallService(MS_PROTO_CONTACTISTYPING,hContact,(WPARAM)PROTOTYPE_CONTACTTYPING_OFF); - else if (type==0x0001)//typed - CallService(MS_PROTO_CONTACTISTYPING,hContact,PROTOTYPE_CONTACTTYPING_INFINITE); - else if (type==0x0002)//typing - CallService(MS_PROTO_CONTACTISTYPING,hContact,(LPARAM)60); + if (snac.subcmp(0x0014)) { + unsigned char sn_length = snac.ubyte(10); + char *sn = snac.part(11, sn_length); + MCONTACT hContact = contact_from_sn(sn); + if (hContact) { + unsigned short type = snac.ushort(11 + sn_length); + if (type == 0x0000)//typing finished + CallService(MS_PROTO_CONTACTISTYPING, hContact, (WPARAM)PROTOTYPE_CONTACTTYPING_OFF); + else if (type == 0x0001)//typed + CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE); + else if (type == 0x0002)//typing + CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)60); } mir_free(sn); } } void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 { - if (snac.subcmp(0x000e)) - { + if (snac.subcmp(0x000e)) { unsigned short id = snac.id(); TLV tlv(snac.val(2)); unsigned short code = snac.ushort(6 + tlv.len()); -// ssi_queue.execute(this, code == 0); - switch (id) - { + + switch (id) { case 0x000a: - switch (code) - { + switch (code) { case 0x0000: -// ShowPopup(LPGEN("Successfully removed buddy from list."), ERROR_POPUP); + // ShowPopup(LPGEN("Successfully removed buddy from list."), ERROR_POPUP); break; case 0x0002: @@ -1591,10 +1476,9 @@ void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 break; case 0x0008: - switch (code) - { + switch (code) { case 0x0000: -// ShowPopup("Successfully added buddy to list.", ERROR_POPUP); + // ShowPopup("Successfully added buddy to list.", ERROR_POPUP); break; case 0x0003: @@ -1626,11 +1510,9 @@ void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 break; case 0x0009: - switch (code) - { + switch (code) { case 0x0000: case 0x000e: -// ShowPopup(LPGEN("Successfully modified group."), ERROR_POPUP); break; case 0x0002: @@ -1650,112 +1532,88 @@ void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 void CAimProto::snac_service_redirect(SNAC &snac)//family 0x0001 { - if (snac.subcmp(0x0005)) - { - char* server=NULL; - char* local_cookie=NULL; - char* host=NULL; - int local_cookie_length=0; - unsigned short family=0; - unsigned char use_ssl=0; - - int offset=2; // skip number of bytes in family version tlv - while (offset < snac.len()) - { + if (snac.subcmp(0x0005)) { + char* server = NULL; + char* local_cookie = NULL; + char* host = NULL; + int local_cookie_length = 0; + unsigned short family = 0; + unsigned char use_ssl = 0; + + int offset = 2; // skip number of bytes in family version tlv + while (offset < snac.len()) { TLV tlv(snac.val(offset)); - if (tlv.cmp(0x000d)) - { - family=tlv.ushort(); + if (tlv.cmp(0x000d)) { + family = tlv.ushort(); } - else if (tlv.cmp(0x0005)) - { - server=tlv.dup(); + else if (tlv.cmp(0x0005)) { + server = tlv.dup(); } - else if (tlv.cmp(0x0006)) - { - local_cookie=tlv.dup(); - local_cookie_length=tlv.len(); + else if (tlv.cmp(0x0006)) { + local_cookie = tlv.dup(); + local_cookie_length = tlv.len(); } - else if (tlv.cmp(0x008d)) - { - host=tlv.dup(); + else if (tlv.cmp(0x008d)) { + host = tlv.dup(); } - else if (tlv.cmp(0x008e)) - { - use_ssl=tlv.ubyte(); + else if (tlv.cmp(0x008e)) { + use_ssl = tlv.ubyte(); } - offset+=TLV_HEADER_SIZE+tlv.len(); + offset += TLV_HEADER_SIZE + tlv.len(); } - if (family == 0x0018) - { - hMailConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/, host); - if (hMailConn) - { + if (family == 0x0018) { + m_hMailConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/, host); + if (m_hMailConn) { debugLogA("Successfully Connected to the Mail Server."); - MAIL_COOKIE=local_cookie; - MAIL_COOKIE_LENGTH=local_cookie_length; - ForkThread( &CAimProto::aim_mail_negotiation, 0 ); + MAIL_COOKIE = local_cookie; + MAIL_COOKIE_LENGTH = local_cookie_length; + ForkThread(&CAimProto::aim_mail_negotiation, 0); } - else - debugLogA("Failed to connect to the Mail Server."); + else debugLogA("Failed to connect to the Mail Server."); } - else if (family == 0x0010) - { - hAvatarConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/); - if (hAvatarConn) - { + else if (family == 0x0010) { + m_hAvatarConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/); + if (m_hAvatarConn) { debugLogA("Successfully Connected to the Avatar Server."); AVATAR_COOKIE = local_cookie; AVATAR_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_avatar_negotiation, 0 ); + ForkThread(&CAimProto::aim_avatar_negotiation, 0); } - else - debugLogA("Failed to connect to the Avatar Server."); + else debugLogA("Failed to connect to the Avatar Server."); } - else if (family == 0x000D) - { - hChatNavConn = aim_connect(server, get_default_port(), use_ssl != 0, host); - if (hChatNavConn) - { + else if (family == 0x000D) { + m_hChatNavConn = aim_connect(server, get_default_port(), use_ssl != 0, host); + if (m_hChatNavConn) { debugLogA("Successfully Connected to the Chat Navigation Server."); CHATNAV_COOKIE = local_cookie; CHATNAV_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_chatnav_negotiation, 0 ); + ForkThread(&CAimProto::aim_chatnav_negotiation, 0); } - else - debugLogA("Failed to connect to the Chat Navigation Server."); - + else debugLogA("Failed to connect to the Chat Navigation Server."); } - else if (family == 0x000E) - { + else if (family == 0x000E) { chat_list_item* item = find_chat_by_cid(snac.idh()); - if (item) - { + if (item) { item->hconn = aim_connect(server, get_default_port(), use_ssl != 0, host); - if (item->hconn) - { + if (item->hconn) { debugLogA("Successfully Connected to the Chat Server."); chat_start(item->id, item->exchange); item->CHAT_COOKIE = local_cookie; item->CHAT_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_chat_negotiation, item ); + ForkThread(&CAimProto::aim_chat_negotiation, item); } - else - debugLogA("Failed to connect to the Chat Server."); + else debugLogA("Failed to connect to the Chat Server."); } } - else if (family == 0x0007) - { - hAdminConn = aim_connect(server, get_default_port(), false /*use_ssl != 0*/); - if (hAdminConn) - { + else if (family == 0x0007) { + m_hAdminConn = aim_connect(server, get_default_port(), false /*use_ssl != 0*/); + if (m_hAdminConn) { debugLogA("Successfully Connected to the Admin Server."); ADMIN_COOKIE = local_cookie; ADMIN_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_admin_negotiation, 0 ); + ForkThread(&CAimProto::aim_admin_negotiation, 0); } - else - debugLogA("Failed to connect to the Admin Server."); + else debugLogA("Failed to connect to the Admin Server."); } mir_free(server); mir_free(host); @@ -1764,8 +1622,7 @@ void CAimProto::snac_service_redirect(SNAC &snac)//family 0x0001 void CAimProto::snac_mail_response(SNAC &snac)//family 0x0018 { - if (snac.subcmp(0x0007)) - { + if (snac.subcmp(0x0007)) { char* sn = NULL; time_t time = 0; unsigned short num_msgs = 0; @@ -1776,45 +1633,36 @@ void CAimProto::snac_mail_response(SNAC &snac)//family 0x0018 int position = 26; int num_tlvs = snac.ushort(24); - for (int i = 0; i < num_tlvs; i++) - { + for (int i = 0; i < num_tlvs; i++) { TLV tlv(snac.val(position)); - if (tlv.cmp(0x0009)) - { + if (tlv.cmp(0x0009)) { sn = tlv.dup(); } - else if (tlv.cmp(0x001d)) - { + else if (tlv.cmp(0x001d)) { time = tlv.ulong(); } - else if (tlv.cmp(0x0080)) - { + else if (tlv.cmp(0x0080)) { num_msgs = tlv.ushort(); } - else if (tlv.cmp(0x0081)) - { + else if (tlv.cmp(0x0081)) { new_mail = tlv.ubyte(); } - else if (tlv.cmp(0x0084)) - { + else if (tlv.cmp(0x0084)) { flags = tlv.ushort(); } - else if (tlv.cmp(0x0007)) - { + else if (tlv.cmp(0x0007)) { url = tlv.dup(); } - else if (tlv.cmp(0x0082)) - { + else if (tlv.cmp(0x0082)) { address = tlv.dup(); } position += TLV_HEADER_SIZE + tlv.len(); } - if (new_mail && num_msgs) - { + if (new_mail && num_msgs) { TCHAR msg[1024]; int len = mir_sntprintf(msg, _countof(msg), _T("%S@%S (%d)\r\n%s "), sn, address, num_msgs, - TranslateT("You've got mail! Checked at")) ; + TranslateT("You've got mail! Checked at")); SYSTEMTIME stLocal; GetLocalTime(&stLocal); @@ -1827,22 +1675,22 @@ void CAimProto::snac_mail_response(SNAC &snac)//family 0x0018 mir_free(url); } } + void CAimProto::snac_retrieve_avatar(SNAC &snac)//family 0x0010 { - if (snac.subcmp(0x0007)) - { + if (snac.subcmp(0x0007)) { int sn_len = snac.ubyte(0); char* sn = snac.part(1, sn_len); int parse_off = sn_len + 4; parse_off += snac.ubyte(parse_off); - int hash_size=snac.ubyte(5+parse_off); - char* hash_string=bytes_to_string(snac.val(6+parse_off), hash_size); - parse_off += hash_size + 6; + int hash_size = snac.ubyte(5 + parse_off); + char* hash_string = bytes_to_string(snac.val(6 + parse_off), hash_size); + parse_off += hash_size + 6; - int icon_length=snac.ushort(parse_off); - char* icon_data=snac.val(parse_off+2); + int icon_length = snac.ushort(parse_off); + char* icon_data = snac.val(parse_off + 2); avatar_retrieval_handler(sn, hash_string, icon_data, icon_length); @@ -1852,12 +1700,10 @@ void CAimProto::snac_retrieve_avatar(SNAC &snac)//family 0x0010 } void CAimProto::snac_upload_reply_avatar(SNAC &snac)//family 0x0010 { - if (snac.subcmp(0x0003)) - { + if (snac.subcmp(0x0003)) { int code = snac.ubyte(0); - switch (code) - { - case 0: + switch (code) { + case 0: break; case 3: ShowPopup(LPGEN("Error uploading avatar. (Too small)"), ERROR_POPUP); @@ -1879,54 +1725,47 @@ void CAimProto::snac_upload_reply_avatar(SNAC &snac)//family 0x0010 } void CAimProto::snac_email_search_results(SNAC &snac)//family 0x000A { - if (snac.subcmp(0x0003)) // Found some buddies - { - PROTOSEARCHRESULT psr = {0}; + if (snac.subcmp(0x0003)) { // Found some buddies + PROTOSEARCHRESULT psr = { 0 }; psr.cbSize = sizeof(psr); - unsigned short offset=0; - while(offsetcid); + aim_chat_join_room(m_hServerConn, m_seqno, cookie, exchange, instance, item->cid); } mir_free(name); @@ -1992,148 +1808,89 @@ void CAimProto::snac_chatnav_info_response(SNAC &snac,HANDLE hServerConn,unsigne } } } -void CAimProto::snac_chat_joined_left_users(SNAC &snac,chat_list_item* item)//family 0x000E -{ // Handles both joining and leaving users. - if (snac.subcmp(0x0003) || snac.subcmp(0x0004)) - { +void CAimProto::snac_chat_joined_left_users(SNAC &snac, chat_list_item* item)//family 0x000E +{ + // Handles both joining and leaving users. + if (snac.subcmp(0x0003) || snac.subcmp(0x0004)) { int offset = 0; - while (offset < snac.len()) - { + while (offset < snac.len()) { int sn_len = snac.ubyte(offset); - char* sn = snac.part(offset+1, sn_len); // Most important part (screenname) + char* sn = snac.part(offset + 1, sn_len); // Most important part (screenname) chat_event(item->id, sn, snac.subcmp(0x0003) ? GC_EVENT_JOIN : GC_EVENT_PART); mir_free(sn); -// int warning = snac.ushort(offset+1+sn_len); - int num_tlv = snac.ushort(offset+3+sn_len); - offset += 5+sn_len; // We're looking at any remaining TLVs -/* - unsigned short user_class = 0; - unsigned long idle_time = 0; - unsigned long signon_time = 0; - unsigned long creation_time = 0; // Server uptime? -*/ - for (int i = 0; i < num_tlv; i++) // Loop through all the TLVs - { + int num_tlv = snac.ushort(offset + 3 + sn_len); + offset += 5 + sn_len; // We're looking at any remaining TLVs + + for (int i = 0; i < num_tlv; i++) { // Loop through all the TLVs TLV tlv(snac.val(offset)); -/* - if (tlv.cmp(0x0001)) - user_class = tlv.ushort(); - else if (tlv.cmp(0x0003)) - signon_time = tlv.ulong(); - else if (tlv.cmp(0x0005)) - creation_time = tlv.ulong(); - else if (tlv.cmp(0x000F)) - idle_time = tlv.ulong(); -*/ offset += TLV_HEADER_SIZE + tlv.len(); } } - } + } } -void CAimProto::snac_chat_received_message(SNAC &snac,chat_list_item* item)//family 0x000E +void CAimProto::snac_chat_received_message(SNAC &snac, chat_list_item* item)//family 0x000E { - if (snac.subcmp(0x0006)) - { + if (snac.subcmp(0x0006)) { TCHAR* message = NULL; char* sn = NULL; -// unsigned long cookie = snac.ulong(0); -// unsigned short channel = snac.ushort(8); + // unsigned long cookie = snac.ulong(0); + // unsigned short channel = snac.ushort(8); int tlv_offset = 10; - while (tlv_offset < snac.len()) - { + while (tlv_offset < snac.len()) { TLV tlv(snac.val(tlv_offset)); - if (tlv.cmp(0x0003)) // Sender information - { + if (tlv.cmp(0x0003)) { // Sender information int sn_len = tlv.ubyte(0); sn = tlv.part(1, sn_len); - /* - unsigned short warning = tlv.ushort(1+sn_len); - int num_tlv = tlv.ushort(3+sn_len); - - int offset = 19 + sn_len; - - unsigned short user_class = 0; - unsigned long idle_time = 0; - unsigned long signon_time = 0; - unsigned long creation_time = 0; //Server uptime? - - for (int i = 0; i < num_tlv; i++) // Loop through all the TLVs - { - TLV info_tlv(tlv.val() + offset); - - // TLV List - if (info_tlv.cmp(0x0001)) - user_class = info_tlv.ushort(); - else if (info_tlv.cmp(0x0003)) - signon_time = info_tlv.ulong(); - else if (info_tlv.cmp(0x0005)) - creation_time = info_tlv.ulong(); - else if (info_tlv.cmp(0x000F)) - idle_time = info_tlv.ulong(); - - offset += TLV_HEADER_SIZE + info_tlv.len(); - } - */ } - else if (tlv.cmp(0x0001)) // Public/Whisper flag + else if (tlv.cmp(0x0001)) // Public/Whisper flag { } - else if (tlv.cmp(0x0005)) // Message information - { + else if (tlv.cmp(0x0005)) { // Message information bool uni = false; bool utf = false; -// char* language = NULL; int offset = 0; - while (offset < tlv.len()) - { + while (offset < tlv.len()) { TLV msg_tlv(tlv.val() + offset); - + // TLV List - if (msg_tlv.cmp(0x0001)) - { - if (uni) - { + if (msg_tlv.cmp(0x0001)) { + if (uni) { char* msg = msg_tlv.dupw(); html_decode(msg); - message = mir_utf8decodeT(msg); + message = mir_utf8decodeT(msg); mir_free(msg); } - else if (utf) - { + else if (utf) { char* msg = msg_tlv.dup(); html_decode(msg); message = mir_utf8decodeT(msg); mir_free(msg); } - else - { + else { char* msg = msg_tlv.dup(); html_decode(msg); message = mir_a2t(msg); mir_free(msg); } } - else if (msg_tlv.cmp(0x0002)) - { + else if (msg_tlv.cmp(0x0002)) { char* enc = msg_tlv.dup(); uni = strstr(enc, "unicode-2-0") != NULL; utf = strstr(enc, "utf-8") != NULL; mir_free(enc); } -// else if (msg_tlv.cmp(0x0003)) -// language = msg_tlv.dup(); offset += TLV_HEADER_SIZE + msg_tlv.len(); } } - + tlv_offset += TLV_HEADER_SIZE + tlv.len(); } @@ -2144,76 +1901,63 @@ void CAimProto::snac_chat_received_message(SNAC &snac,chat_list_item* item)//fam } } -void CAimProto::snac_admin_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_admin_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_admin_ready(hServerConn,seqno); - SetEvent(hAdminEvent); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_admin_ready(hServerConn, seqno); + SetEvent(m_hAdminEvent); } } -void CAimProto::snac_admin_account_infomod(SNAC &snac)//family 0x0007 +void CAimProto::snac_admin_account_infomod(SNAC &snac) //family 0x0007 { - if (snac.subcmp(0x0003) || snac.subcmp(0x0005)) // Handles info response and modification response - { + if (snac.subcmp(0x0003) || snac.subcmp(0x0005)) { // Handles info response and modification response bool err = false; bool req_email = false; - unsigned short perms = 0; - unsigned short num_tlv = 0; - - perms = snac.ushort(); // Permissions - num_tlv = snac.ushort(2); // Number of TLVs - char* sn = NULL; // Screen Name - char* email = NULL; // Email address - //unsigned short status = 0; // Account status + WORD num_tlv = snac.ushort(2); // Number of TLVs + + char *sn = NULL; // Screen Name + char *email = NULL; // Email address unsigned short offset = 0; for (int i = 0; i < num_tlv; i++) // Loop through all the TLVs { - TLV tlv(snac.val(4+offset)); - + TLV tlv(snac.val(4 + offset)); + // TLV List if (tlv.cmp(0x0001)) sn = tlv.dup(); - if (tlv.cmp(0x0011)) - { + + if (tlv.cmp(0x0011)) { req_email = true; email = tlv.dup(); } - //if (tlv.cmp(0x0013)) - // status = tlv.ushort(); - if (tlv.cmp(0x0008)) // Handles any problems when requesting/changing information - { + + if (tlv.cmp(0x0008)) { // Handles any problems when requesting/changing information err = true; admin_error(tlv.ushort()); } - //if (tlv.cmp(0x0004)) - //error description offset += TLV_HEADER_SIZE + tlv.len(); } - if (snac.subcmp(0x0003) && !err) // Requested info - { + if (snac.subcmp(0x0003) && !err) { // Requested info // Display messages if (email) - setString(AIM_KEY_EM,email); // Save our email for future reference. + setString(AIM_KEY_EM, email); // Save our email for future reference. if (sn) - setString(AIM_KEY_SN,sn); // Update the database to reflect the formatted name. - ProtoBroadcastAck( NULL, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0 ); - + setString(AIM_KEY_SN, sn); // Update the database to reflect the formatted name. + ProtoBroadcastAck(NULL, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0); + } - else if (snac.subcmp(0x0005) && !err) // Changed info - { + else if (snac.subcmp(0x0005) && !err) { // Changed info // Display messages if (email && req_email) // We requested to change the email ShowPopup(LPGEN("A confirmation message has been sent to the new email address. Please follow its instructions."), 0); - else if (sn) - { - setString(AIM_KEY_SN,sn); // Update the database to reflect the formatted name. + else if (sn) { + setString(AIM_KEY_SN, sn); // Update the database to reflect the formatted name. //ShowPopup("Your Screen Name has been successfully formatted.", 0); } } @@ -2224,14 +1968,12 @@ void CAimProto::snac_admin_account_infomod(SNAC &snac)//family 0x0007 void CAimProto::snac_admin_account_confirm(SNAC &snac)//family 0x0007 { - if (snac.subcmp(0x0007)) - { + if (snac.subcmp(0x0007)) { unsigned short status = 0; status = snac.ushort(); - switch (status) - { + switch (status) { case 0: ShowPopup(LPGEN("A confirmation message has been sent to your email address. Please follow its instructions."), 0); break; @@ -2248,34 +1990,5 @@ void CAimProto::snac_admin_account_confirm(SNAC &snac)//family 0x0007 ShowPopup(LPGEN("Can't start the confirmation procedure."), 0); break; } - - //TLV tlv(snac.val(2)); - //if (tlv.cmp(0x0004)) - //error description } } - - -/*void CAimProto::snac_delete_contact(SNAC &snac, char* buf)//family 0x0013 -{ - if (snac.subcmp(0x000a)) - { - char sn[33]; - int sn_length=buf[SNAC_SIZE*2]; - MCONTACT hContact; - memset(sn, 0, sizeof(sn)); - memcpy(sn,&buf[SNAC_SIZE*2+1],sn_length); - hContact=find_contact(sn); - if (hContact) - { - unsigned short* type=(unsigned short*)&buf[SNAC_SIZE*2+1+sn_length]; - *type=htons(*type); - if (*type==0x0000)//typing finished - CallService(MS_PROTO_CONTACTISTYPING,hContact,(WPARAM)PROTOTYPE_CONTACTTYPING_OFF); - else if (*type==0x0001)//typed - CallService(MS_PROTO_CONTACTISTYPING,hContact,PROTOTYPE_CONTACTTYPING_INFINITE); - else if (*type==0x0002)//typing - CallService(MS_PROTO_CONTACTISTYPING,hContact,(LPARAM)60); - } - } -}*/ -- cgit v1.2.3