summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/src/svcs_menu.cpp
diff options
context:
space:
mode:
authorRené Schümann <white06tiger@gmail.com>2015-03-26 20:38:55 +0000
committerRené Schümann <white06tiger@gmail.com>2015-03-26 20:38:55 +0000
commit5f2e4efe46fefa7cd11f275896954c24be37b568 (patch)
tree00fb544f0a9a9e9a89dd1af28b97a6248edac9eb /plugins/MirOTR/src/svcs_menu.cpp
parent1f7e069bda342dff43e2224060f10fcb098ea62a (diff)
MirOTR: compatibility update to support/use libotr 4
+ added otrlextensions from Psi+ (thanks guys, better than our old modification to libotr) * basic instance tag support, though we don't offer user choice yet. + added ProtoGetNickname(), stolen from TabSRMM to get our own nickname of given protocol (utils.cpp) git-svn-id: http://svn.miranda-ng.org/main/trunk@12503 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR/src/svcs_menu.cpp')
-rw-r--r--plugins/MirOTR/src/svcs_menu.cpp378
1 files changed, 189 insertions, 189 deletions
diff --git a/plugins/MirOTR/src/svcs_menu.cpp b/plugins/MirOTR/src/svcs_menu.cpp
index 6699c00adc..4ed3f7a0d9 100644
--- a/plugins/MirOTR/src/svcs_menu.cpp
+++ b/plugins/MirOTR/src/svcs_menu.cpp
@@ -1,189 +1,189 @@
-#include "stdafx.h"
-
-static HGENMENU hStopItem, hStartItem;
-
-////////////////////////////////
-///////// Menu Services ////////
-///////////////////////////////
-int StartOTR(MCONTACT hContact) {
- const char *proto = GetContactProto(hContact);
- if (!proto) return 1; // error
- char *uname = contact_get_id(hContact);
- if (!uname) return 1; // error
- DWORD pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
- if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
-
- lib_cs_lock();
- char *msg = otrl_proto_default_query_msg(MODULENAME, pol);
- otr_gui_inject_message((void*)hContact, proto, proto, uname, msg ? msg : "?OTRv2?");
- lib_cs_unlock();
- otrl_message_free(msg);
- mir_free(uname);
- return 0;
-}
-
-INT_PTR SVC_StartOTR(WPARAM hContact, LPARAM lParam)
-{
- TCHAR buff[512];
-
- MCONTACT hSub = db_mc_getMostOnline(hContact);
- if(hSub != 0)
- hContact = hSub;
-
- if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0 ) {
- mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact));
- ShowError(buff);
- return 0;
- }
-
- mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_SESSION_REQUEST_OTR), contact_get_nameT(hContact));
- ShowMessage(hContact, buff);
-
- return StartOTR(hContact);
-}
-
-INT_PTR SVC_RefreshOTR(WPARAM hContact, LPARAM lParam)
-{
- TCHAR buff[512];
-
- MCONTACT hSub = db_mc_getMostOnline(hContact);
- if(hSub != 0)
- hContact = hSub;
-
- if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0 ) {
- mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact));
- ShowError(buff);
- return 0;
- }
-
- mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_SESSION_TRY_CONTINUE_OTR), contact_get_nameT(hContact));
- ShowMessage(hContact, buff);
-
- int res = StartOTR(hContact);
- if (res) return res;
-
- return 0;
-}
-
-int otr_disconnect_contact(MCONTACT hContact)
-{
- MCONTACT hSub = db_mc_getMostOnline(hContact);
- if (hSub != 0)
- hContact = hSub;
-
- const char *proto = GetContactProto(hContact);
- if (!proto) return 1; // error
- char *uname = contact_get_id(hContact);
- if (!uname) return 1; // error
-
- lib_cs_lock();
- otrl_message_disconnect(otr_user_state, &ops, (void*)hContact, proto, proto, uname);
- lib_cs_unlock();
- mir_free(uname);
- return 0;
-}
-
-INT_PTR SVC_StopOTR(WPARAM hContact, LPARAM lParam)
-{
- // prevent this filter from acting on injeceted messages for metas, when they are passed though the subcontact's proto send chain
- if (otr_disconnect_contact(hContact)) return 0;
-
- SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE);
-
- TCHAR buff[512];
- mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_SESSION_TERMINATED_OTR), contact_get_nameT(hContact));
- ShowMessage(hContact, buff);
- return 0;
-}
-
-INT_PTR SVC_VerifyOTR(WPARAM hContact, LPARAM lParam)
-{
- MCONTACT hSub = db_mc_getMostOnline(hContact);
- if(hSub != 0)
- hContact = hSub;
-
- ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
- if (!context)
- return 1;
-
- //VerifyContextDialog(context);
- SMPInitDialog(context);
- return 0;
-}
-
-INT_PTR SVC_ToggleHTMLOTR(WPARAM hContact, LPARAM lParam)
-{
- MCONTACT hSub = db_mc_getMostOnline(hContact);
- if (hSub != 0)
- hContact = hSub;
-
- if (db_get_b(hContact, MODULENAME, "HTMLConv", 0))
- db_set_b(hContact, MODULENAME, "HTMLConv", 0);
- else
- db_set_b(hContact, MODULENAME, "HTMLConv", 1);
-
- return 0;
-}
-
-void InitMenu()
-{
- CreateServiceFunction(MS_OTR_MENUSTART, SVC_StartOTR);
- CreateServiceFunction(MS_OTR_MENUSTOP, SVC_StopOTR);
- CreateServiceFunction(MS_OTR_MENUREFRESH, SVC_RefreshOTR);
- CreateServiceFunction(MS_OTR_MENUVERIFY, SVC_VerifyOTR);
- CreateServiceFunction(MS_OTR_MENUTOGGLEHTML, SVC_ToggleHTMLOTR);
-
- CLISTMENUITEM mi = { sizeof(mi) };
- mi.flags = CMIF_NOTOFFLINE | CMIF_TCHAR;
- mi.position = -400000;
-
- mi.ptszName = _T(LANG_STOP_OTR);
- mi.pszService = MS_OTR_MENUSTOP;
- mi.icolibItem = GetIconHandle(ICON_PRIVATE);
-
- hStopItem = Menu_AddContactMenuItem(&mi);
-
- mi.ptszName = _T(LANG_START_OTR);
- mi.pszService = MS_OTR_MENUSTART;
- mi.icolibItem = GetIconHandle(ICON_NOT_PRIVATE);
-
- hStartItem = Menu_AddContactMenuItem(&mi);
-
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SVC_PrebuildContactMenu);
-}
-
-int SVC_PrebuildContactMenu(WPARAM hContact, LPARAM lParam)
-{
- CLISTMENUITEM mi = { sizeof(mi) };
- mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIF_TCHAR;
-
- const char *proto = GetContactProto(hContact);
- DWORD pol = CONTACT_DEFAULT_POLICY;
-
- if (!proto || db_get_b(hContact, proto, "ChatRoom", 0) == 1) {
-hide_all:
- Menu_ShowItem(hStartItem, false);
- Menu_ShowItem(hStopItem, false);
- return 0;
- }
-
- if(proto && strcmp(proto, META_PROTO) == 0) {
- // make menu act as per most online subcontact
- hContact = db_mc_getMostOnline(hContact);
- if (!hContact)
- goto hide_all;
- proto = GetContactProto(hContact);
- }
-
- pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
- if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
-
- if(pol == OTRL_POLICY_NEVER || pol == OTRL_POLICY_ALWAYS)
- goto hide_all;
-
- ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
- TrustLevel encrypted = otr_context_get_trust(context);
- Menu_ShowItem(hStartItem, encrypted == TRUST_NOT_PRIVATE);
- Menu_ShowItem(hStopItem, encrypted != TRUST_NOT_PRIVATE);
- return 0;
-} \ No newline at end of file
+#include "stdafx.h"
+
+static HGENMENU hStopItem, hStartItem;
+
+////////////////////////////////
+///////// Menu Services ////////
+///////////////////////////////
+int StartOTR(MCONTACT hContact) {
+ const char *proto = GetContactProto(hContact);
+ if (!proto) return 1; // error
+ char *uname = contact_get_id(hContact);
+ if (!uname) return 1; // error
+ DWORD pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
+ if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
+
+ lib_cs_lock();
+ char *msg = otrl_proto_default_query_msg(MODULENAME, pol);
+ otr_gui_inject_message((void*)hContact, proto, proto, uname, msg ? msg : MIROTR_PROTO_HELLO);
+ free(msg);
+ lib_cs_unlock();
+ mir_free(uname);
+ return 0;
+}
+
+INT_PTR SVC_StartOTR(WPARAM hContact, LPARAM lParam)
+{
+ TCHAR buff[512];
+
+ MCONTACT hSub = db_mc_getMostOnline(hContact);
+ if(hSub != 0)
+ hContact = hSub;
+
+ if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0 ) {
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact));
+ ShowError(buff);
+ return 0;
+ }
+
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_SESSION_REQUEST_OTR), contact_get_nameT(hContact));
+ ShowMessage(hContact, buff);
+
+ return StartOTR(hContact);
+}
+
+INT_PTR SVC_RefreshOTR(WPARAM hContact, LPARAM lParam)
+{
+ TCHAR buff[512];
+
+ MCONTACT hSub = db_mc_getMostOnline(hContact);
+ if(hSub != 0)
+ hContact = hSub;
+
+ if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0 ) {
+ mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact));
+ ShowError(buff);
+ return 0;
+ }
+
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_SESSION_TRY_CONTINUE_OTR), contact_get_nameT(hContact));
+ ShowMessage(hContact, buff);
+
+ int res = StartOTR(hContact);
+ if (res) return res;
+
+ return 0;
+}
+
+int otr_disconnect_contact(MCONTACT hContact)
+{
+ MCONTACT hSub = db_mc_getMostOnline(hContact);
+ if (hSub != 0)
+ hContact = hSub;
+
+ const char *proto = GetContactProto(hContact);
+ if (!proto) return 1; // error
+ char *uname = contact_get_id(hContact);
+ if (!uname) return 1; // error
+
+ lib_cs_lock();
+ otrl_message_disconnect_all_instances(otr_user_state, &ops, (void*)hContact, proto, proto, uname);
+ lib_cs_unlock();
+ mir_free(uname);
+ return 0;
+}
+
+INT_PTR SVC_StopOTR(WPARAM hContact, LPARAM lParam)
+{
+ // prevent this filter from acting on injeceted messages for metas, when they are passed though the subcontact's proto send chain
+ if (otr_disconnect_contact(hContact)) return 0;
+
+ SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE);
+
+ TCHAR buff[512];
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT(LANG_SESSION_TERMINATED_OTR), contact_get_nameT(hContact));
+ ShowMessage(hContact, buff);
+ return 0;
+}
+
+INT_PTR SVC_VerifyOTR(WPARAM hContact, LPARAM lParam)
+{
+ MCONTACT hSub = db_mc_getMostOnline(hContact);
+ if(hSub != 0)
+ hContact = hSub;
+
+ ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
+ if (!context)
+ return 1;
+
+ //VerifyContextDialog(context);
+ SMPInitDialog(context);
+ return 0;
+}
+
+INT_PTR SVC_ToggleHTMLOTR(WPARAM hContact, LPARAM lParam)
+{
+ MCONTACT hSub = db_mc_getMostOnline(hContact);
+ if (hSub != 0)
+ hContact = hSub;
+
+ if (db_get_b(hContact, MODULENAME, "HTMLConv", 0))
+ db_set_b(hContact, MODULENAME, "HTMLConv", 0);
+ else
+ db_set_b(hContact, MODULENAME, "HTMLConv", 1);
+
+ return 0;
+}
+
+void InitMenu()
+{
+ CreateServiceFunction(MS_OTR_MENUSTART, SVC_StartOTR);
+ CreateServiceFunction(MS_OTR_MENUSTOP, SVC_StopOTR);
+ CreateServiceFunction(MS_OTR_MENUREFRESH, SVC_RefreshOTR);
+ CreateServiceFunction(MS_OTR_MENUVERIFY, SVC_VerifyOTR);
+ CreateServiceFunction(MS_OTR_MENUTOGGLEHTML, SVC_ToggleHTMLOTR);
+
+ CLISTMENUITEM mi = { sizeof(mi) };
+ mi.flags = CMIF_NOTOFFLINE | CMIF_TCHAR;
+ mi.position = -400000;
+
+ mi.ptszName = _T(LANG_STOP_OTR);
+ mi.pszService = MS_OTR_MENUSTOP;
+ mi.icolibItem = GetIconHandle(ICON_PRIVATE);
+
+ hStopItem = Menu_AddContactMenuItem(&mi);
+
+ mi.ptszName = _T(LANG_START_OTR);
+ mi.pszService = MS_OTR_MENUSTART;
+ mi.icolibItem = GetIconHandle(ICON_NOT_PRIVATE);
+
+ hStartItem = Menu_AddContactMenuItem(&mi);
+
+ HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SVC_PrebuildContactMenu);
+}
+
+int SVC_PrebuildContactMenu(WPARAM hContact, LPARAM lParam)
+{
+ CLISTMENUITEM mi = { sizeof(mi) };
+ mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIF_TCHAR;
+
+ const char *proto = GetContactProto(hContact);
+ DWORD pol = CONTACT_DEFAULT_POLICY;
+
+ if (!proto || db_get_b(hContact, proto, "ChatRoom", 0) == 1) {
+hide_all:
+ Menu_ShowItem(hStartItem, false);
+ Menu_ShowItem(hStopItem, false);
+ return 0;
+ }
+
+ if(proto && strcmp(proto, META_PROTO) == 0) {
+ // make menu act as per most online subcontact
+ hContact = db_mc_getMostOnline(hContact);
+ if (!hContact)
+ goto hide_all;
+ proto = GetContactProto(hContact);
+ }
+
+ pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
+ if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
+
+ if(pol == OTRL_POLICY_NEVER || pol == OTRL_POLICY_ALWAYS)
+ goto hide_all;
+
+ ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
+ TrustLevel encrypted = otr_context_get_trust(context);
+ Menu_ShowItem(hStartItem, encrypted == TRUST_NOT_PRIVATE);
+ Menu_ShowItem(hStopItem, encrypted != TRUST_NOT_PRIVATE);
+ return 0;
+}