diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-05-12 02:07:45 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-05-12 02:07:45 +0300 |
commit | 28fbb7c75a6f4a596c1af19755b05b835a6cc299 (patch) | |
tree | 2f52bfe5b0854c00bcab7eecc5d47291141629ae | |
parent | 6873a8a0889dcaf68c499f52f52fb0f9da4469e0 (diff) |
jabber: omemo: old code cleanup
respect omemo option (do not do unnecessary allocations/cleanup)
-rwxr-xr-x | protocols/JabberG/src/jabber_omemo.cpp | 95 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_proto.cpp | 5 |
2 files changed, 45 insertions, 55 deletions
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index d9856af306..fb5238b7db 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -399,55 +399,61 @@ namespace omemo { omemo_impl::omemo_impl(CJabberProto *p) : proto(p)
{
- if (!global_context)
- signal_context_create(&global_context, this);
- signal_mutex = new mir_cslockfull(_signal_cs);
- signal_mutex->unlock(); //fuck...
- provider = new signal_crypto_provider;
- provider->random_func = &random_func;
- provider->hmac_sha256_init_func = &hmac_sha256_init_func;
- provider->hmac_sha256_update_func = &hmac_sha256_update_func;
- provider->hmac_sha256_final_func = &hmac_sha256_final_func;
- provider->hmac_sha256_cleanup_func = &hmac_sha256_cleanup_func;
- provider->sha512_digest_init_func = &sha512_digest_init_func;
- provider->sha512_digest_update_func = &sha512_digest_update_func;
- provider->sha512_digest_final_func = &sha512_digest_final_func;
- provider->sha512_digest_cleanup_func = &sha512_digest_cleanup_func;
- provider->encrypt_func = &encrypt_func;
- provider->decrypt_func = &decrypt_func;
-
- if (signal_context_set_crypto_provider(global_context, provider))
+ if (proto->m_options.UseOMEMO)
{
- proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
- //TODO: handle error
- }
+ if (!global_context)
+ signal_context_create(&global_context, this);
+ signal_mutex = new mir_cslockfull(_signal_cs);
+ signal_mutex->unlock(); //fuck...
+ provider = new signal_crypto_provider;
+ provider->random_func = &random_func;
+ provider->hmac_sha256_init_func = &hmac_sha256_init_func;
+ provider->hmac_sha256_update_func = &hmac_sha256_update_func;
+ provider->hmac_sha256_final_func = &hmac_sha256_final_func;
+ provider->hmac_sha256_cleanup_func = &hmac_sha256_cleanup_func;
+ provider->sha512_digest_init_func = &sha512_digest_init_func;
+ provider->sha512_digest_update_func = &sha512_digest_update_func;
+ provider->sha512_digest_final_func = &sha512_digest_final_func;
+ provider->sha512_digest_cleanup_func = &sha512_digest_cleanup_func;
+ provider->encrypt_func = &encrypt_func;
+ provider->decrypt_func = &decrypt_func;
+
+ if (signal_context_set_crypto_provider(global_context, provider))
+ {
+ proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
+ //TODO: handle error
+ }
- if (signal_context_set_locking_functions(global_context, &lock, &unlock))
- {
- proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
- //TODO: handle error
+ if (signal_context_set_locking_functions(global_context, &lock, &unlock))
+ {
+ proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
+ //TODO: handle error
+ }
+ sessions_internal = new std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >;
}
- sessions_internal = new std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >;
}
omemo_impl::~omemo_impl()
{
- for (std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >::iterator i = ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->begin(),
- end = ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->end(); i != end; ++i)
+ if (proto->m_options.UseOMEMO)
{
- for (std::map<unsigned int, omemo_session_jabber_internal_ptrs>::iterator i2 = i->second.begin(), end2 = i->second.end(); i2 != end2; ++i2)
+ for (std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >::iterator i = ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->begin(),
+ end = ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->end(); i != end; ++i)
{
- if (i2->second.cipher)
- session_cipher_free(i2->second.cipher);
- if (i2->second.builder)
- session_builder_free(i2->second.builder);
- if (i2->second.store_context)
- signal_protocol_store_context_destroy(i2->second.store_context);
+ for (std::map<unsigned int, omemo_session_jabber_internal_ptrs>::iterator i2 = i->second.begin(), end2 = i->second.end(); i2 != end2; ++i2)
+ {
+ if (i2->second.cipher)
+ session_cipher_free(i2->second.cipher);
+ if (i2->second.builder)
+ session_builder_free(i2->second.builder);
+ if (i2->second.store_context)
+ signal_protocol_store_context_destroy(i2->second.store_context);
+ }
}
+ ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->clear();
+ delete (std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal;
+ delete signal_mutex;
+ delete provider;
}
- ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->clear();
- delete (std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal;
- delete signal_mutex;
- delete provider;
}
@@ -617,17 +623,6 @@ namespace omemo { }
- //session related libsignal api
- void clean_sessions()
- {
- /*
- as this is called for every jabber account it may cause problems
- if one of multiple jabber accounts is deleted in runtime,
- to avoid this kind of problems this map must be defained in CJabberProto,
- but as our silent rules agains stl and heavy constructions i will leave it here for now.
- */
- }
-
//signal_protocol_session_store callbacks follow
struct signal_store_backend_user_data
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index cd7692a02a..9d143d440c 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -157,9 +157,6 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) : m_tszSelectedLang = mir_wstrdup(L"en");
}
-namespace omemo {
- void clean_sessions();
-};
CJabberProto::~CJabberProto()
{
@@ -198,8 +195,6 @@ CJabberProto::~CJabberProto() mir_free(m_lstJabberFeatCapPairsDynamic[i]->szDescription);
delete m_lstJabberFeatCapPairsDynamic[i];
}
- if(m_options.UseOMEMO)
- omemo::clean_sessions();
}
////////////////////////////////////////////////////////////////////////////////////////
|