From c91f19085e70f9e7fb2e8a445c87043f860f1f02 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 28 Feb 2017 16:10:20 +0300 Subject: jabber: fix caps ui bug introduced in early omemo implementation stage omemo: basic device list event handler, added +notify cap to permanent caps, currenlty jabber have problems with dynamic caps... --- protocols/JabberG/src/jabber_caps.h | 3 +- protocols/JabberG/src/jabber_iqid.cpp | 0 protocols/JabberG/src/jabber_omemo.cpp | 80 +++++++++++++++++++++++++++------- protocols/JabberG/src/jabber_proto.cpp | 15 ------- protocols/JabberG/src/jabber_proto.h | 1 + protocols/JabberG/src/jabber_util.cpp | 0 6 files changed, 68 insertions(+), 31 deletions(-) mode change 100644 => 100755 protocols/JabberG/src/jabber_iqid.cpp mode change 100644 => 100755 protocols/JabberG/src/jabber_util.cpp (limited to 'protocols') diff --git a/protocols/JabberG/src/jabber_caps.h b/protocols/JabberG/src/jabber_caps.h index 1afece97bb..4e69e7c1bf 100755 --- a/protocols/JabberG/src/jabber_caps.h +++ b/protocols/JabberG/src/jabber_caps.h @@ -167,7 +167,8 @@ typedef unsigned __int64 JabberCapsBits; JABBER_CAPS_ROSTER_EXCHANGE | JABBER_CAPS_DIRECT_MUC_INVITE) #define JABBER_CAPS_MIRANDA_ALL (JABBER_CAPS_MIRANDA_PARTIAL | JABBER_CAPS_COMMANDS | \ - JABBER_CAPS_USER_MOOD_NOTIFY | JABBER_CAPS_USER_TUNE_NOTIFY | JABBER_CAPS_USER_ACTIVITY_NOTIFY | JABBER_CAPS_PLATFORMX86 | JABBER_CAPS_PLATFORMX64) + JABBER_CAPS_USER_MOOD_NOTIFY | JABBER_CAPS_USER_TUNE_NOTIFY | JABBER_CAPS_USER_ACTIVITY_NOTIFY | JABBER_CAPS_OMEMO_NOTIFY \ + | JABBER_CAPS_PLATFORMX86 | JABBER_CAPS_PLATFORMX64) #define JABBER_EXT_SECUREIM L"secureim" diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp old mode 100644 new mode 100755 diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 47e70401b9..354648c1b8 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -420,19 +420,12 @@ namespace omemo { int id = proto->getDword("OmemoDeviceId", 0); if (id == 0) return true; - DBVARIANT dbv = { 0 }; - proto->getString("OmemoDevicePublicKey", &dbv); - if (!dbv.pszVal[0]) - { - //does it need to free something in DBVARIANT? + ptrA buf(proto->getStringA("OmemoDevicePublicKey")); + if (!buf[0]) return true; - } - proto->getString("OmemoDevicePrivateKey", &dbv); - if (!dbv.pszVal[0]) - { - //does it need to free something in DBVARIANT? + buf = ptrA(proto->getStringA("OmemoDevicePrivateKey")); + if (!buf[0]) return true; - } return false; } @@ -458,6 +451,8 @@ namespace omemo { SIGNAL_UNREF(new_dev->device_key); + //TODO: publish device info to pubsub + } }; @@ -466,7 +461,7 @@ void CJabberProto::OmemoInitDevice() { if (omemo::IsFirstRun(this)) omemo::RefreshDevice(this); - + OmemoAnnounceDevice(); } @@ -475,7 +470,62 @@ void CJabberProto::OmemoHandleMessage(HXML /*node*/) //TODO: handle "encrypted" node here } -void CJabberProto::OmemoHandleDeviceList(HXML /*node*/) +void CJabberProto::OmemoHandleDeviceList(HXML node) { - //TODO: handle omemo device list event node here -} \ No newline at end of file + if (!node) + return; + HXML message = xmlGetParent(node); + message = xmlGetParent(node); + LPCTSTR jid = XmlGetAttrValue(message, L"from"); + MCONTACT hContact = HContactFromJID(jid); + node = XmlGetChild(node, "item"); //get node + if (!node) + return; + node = XmlGetChildByTag(node, L"list", L"xmlns", JABBER_FEAT_OMEMO); // + if (!node) + return; + bool own_jid = false; //TODO: detect own jid (not work dues to jabber_thread.cpp:947+) + DWORD current_id; + LPCTSTR current_id_str; + if (own_jid) + { + //check if our device exist + bool own_device_listed = false; + DWORD own_id = getDword("OmemoDeviceId", 0); + if (own_id = 0) + OmemoInitDevice(); + + for (HXML list_item = xmlGetFirstChild(node); list_item; xmlGetNextNode(list_item)) + { + current_id_str = xmlGetAttrValue(list_item, L"id"); + current_id = _wtoi(current_id_str); + if (current_id == own_id) + own_device_listed = true; + } + if (!own_device_listed) + OmemoAnnounceDevice(); + } + else + { + //store device id's + int i = 0; + char setting_name[64]; + for (HXML list_item = xmlGetFirstChild(node); list_item; xmlGetNextNode(list_item), i++) + { + current_id_str = xmlGetAttrValue(list_item, L"id"); + current_id = _wtoi(current_id_str); + mir_snprintf(setting_name, "OmemoDeviceId%d", i); + setDword(setting_name, current_id); + } + } +} + +void CJabberProto::OmemoAnnounceDevice() +{ + //TODO: get device list + //TODO: check for own device id + //TODO: add own device id + //TODO: send device list back + +} + diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 8c220e2a63..19813ac138 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -138,22 +138,7 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) : m_pepServices.insert(new CPepActivity(this)); if (m_options.UseOMEMO) - { - JabberCapsBits jcb = 0; - // set all bits occupied by g_JabberFeatCapPairs - for (int i = 0; g_JabberFeatCapPairs[i].szFeature; i++) - jcb |= g_JabberFeatCapPairs[i].jcbCap; - - // set all bits already occupied by external plugins - for (int i = 0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++) - jcb |= m_lstJabberFeatCapPairsDynamic[i]->jcbCap; - - jcb |= JABBER_CAPS_OMEMO_NOTIFY; - - m_clientCapsManager.SetClientCaps(JABBER_CAPS_MIRANDA_NODE, szCoreVersion, jcb); - OmemoInitDevice(); - } db_set_resident(m_szModuleName, DBSETTING_XSTATUSID); db_set_resident(m_szModuleName, DBSETTING_XSTATUSNAME); diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 48c7778461..ed63eff36c 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -340,6 +340,7 @@ struct CJabberProto : public PROTO, public IJabberInterface void OmemoHandleMessage(HXML node); void OmemoHandleDeviceList(HXML node); void OmemoInitDevice(); + void OmemoAnnounceDevice(); //---- jabber_console.cpp ------------------------------------------------------------ diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp old mode 100644 new mode 100755 -- cgit v1.2.3