summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_omemo.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2017-02-28 16:10:20 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2017-02-28 16:13:54 +0300
commitc91f19085e70f9e7fb2e8a445c87043f860f1f02 (patch)
tree814034e1df805ecb256be34d12ccfcc5c3235b8a /protocols/JabberG/src/jabber_omemo.cpp
parent8736afe83f8c5aadf130542b2bbf14b2bcf57105 (diff)
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...
Diffstat (limited to 'protocols/JabberG/src/jabber_omemo.cpp')
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.cpp80
1 files changed, 65 insertions, 15 deletions
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 <item> node
+ if (!node)
+ return;
+ node = XmlGetChildByTag(node, L"list", L"xmlns", JABBER_FEAT_OMEMO); //<list xmlns = 'urn:xmpp:omemo:0'>
+ 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
+
+}
+