summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2015-04-30 08:05:40 +0000
committerKirill Volinsky <mataes2007@gmail.com>2015-04-30 08:05:40 +0000
commit34d561d1468bfd0a380d755d6c991ec1b7ed79cf (patch)
tree61a6267280dd6808cf5310a8981cce4a530f2674 /plugins/MirOTR/src
parent944482ac36d1f1d6e14cf791130bea5c7c9de01b (diff)
minus critical section
git-svn-id: http://svn.miranda-ng.org/main/trunk@13283 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR/src')
-rw-r--r--plugins/MirOTR/src/dbfilter.cpp12
-rw-r--r--plugins/MirOTR/src/dialogs.cpp6
-rw-r--r--plugins/MirOTR/src/dllmain.cpp6
-rw-r--r--plugins/MirOTR/src/options.cpp1
-rw-r--r--plugins/MirOTR/src/otr.cpp2
-rw-r--r--plugins/MirOTR/src/svcs_menu.cpp2
-rw-r--r--plugins/MirOTR/src/svcs_proto.cpp1
-rw-r--r--plugins/MirOTR/src/utils.cpp20
-rw-r--r--plugins/MirOTR/src/utils.h4
9 files changed, 5 insertions, 49 deletions
diff --git a/plugins/MirOTR/src/dbfilter.cpp b/plugins/MirOTR/src/dbfilter.cpp
index 339592c832..0ae91eeb37 100644
--- a/plugins/MirOTR/src/dbfilter.cpp
+++ b/plugins/MirOTR/src/dbfilter.cpp
@@ -1,7 +1,7 @@
#include "stdafx.h"
static HANDLE hDBEventPreAdd, hDBEventAdded, hContactSettingChanged;
-static CRITICAL_SECTION RemoveChainCS={0}, *lpRemoveChainCS = &RemoveChainCS;
+static mir_cs RemoveChainCS, *lpRemoveChainCS = &RemoveChainCS;
static UINT_PTR timerId = 0;
struct DeleteEventNode {
@@ -18,7 +18,7 @@ static DeleteEventHead DeleteEvents = {0,0};
VOID CALLBACK DeleteTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
if (!DeleteEvents.first) return;
- EnterCriticalSection(lpRemoveChainCS);
+ mir_cslock lck(*lpRemoveChainCS);
DeleteEventNode *prev =0, *current, *next;
DBEVENTINFO info = { sizeof(info) };
next = DeleteEvents.first;
@@ -38,7 +38,6 @@ VOID CALLBACK DeleteTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTi
}
}
if (!DeleteEvents.first) DeleteEvents.last = 0;
- LeaveCriticalSection(lpRemoveChainCS);
}
@@ -211,13 +210,12 @@ int OnDatabaseEventPreAdd(WPARAM hContact, LPARAM lParam)
node->hDbEvent = lParam;
node->timestamp = time(0);
node->next = 0;
- EnterCriticalSection(lpRemoveChainCS);
+ mir_cslock lck(*lpRemoveChainCS);
if (DeleteEvents.last)
DeleteEvents.last->next = node;
else
DeleteEvents.first = node;
DeleteEvents.last = node;
- LeaveCriticalSection(lpRemoveChainCS);
}
}
}
@@ -260,7 +258,6 @@ int WindowEvent(WPARAM wParam, LPARAM lParam) {
lib_cs_lock();
ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
- lib_cs_unlock();
SetEncryptionStatus(hContact, otr_context_get_trust(context));
@@ -292,7 +289,6 @@ int StatusModeChange(WPARAM wParam, LPARAM lParam) {
}
context = context->next;
}
- lib_cs_unlock();
return 0;
}
@@ -332,7 +328,6 @@ int OnContactSettingChanged(WPARAM hContact, LPARAM lParam)
}
void InitDBFilter() {
- InitializeCriticalSectionAndSpinCount(lpRemoveChainCS, 500);
hDBEventPreAdd = HookEvent(ME_DB_EVENT_FILTER_ADD, OnDatabaseEventPreAdd);
hDBEventAdded = HookEvent(ME_DB_EVENT_ADDED, OnDatabaseEventAdded);
hContactSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnContactSettingChanged);
@@ -347,5 +342,4 @@ void DeinitDBFilter() {
hContactSettingChanged=0;
if (timerId) KillTimer(0, timerId);
DeleteTimerProc(0,0,0,0);
- DeleteCriticalSection(lpRemoveChainCS);
}
diff --git a/plugins/MirOTR/src/dialogs.cpp b/plugins/MirOTR/src/dialogs.cpp
index c43a2b1d55..c4ad4b9f63 100644
--- a/plugins/MirOTR/src/dialogs.cpp
+++ b/plugins/MirOTR/src/dialogs.cpp
@@ -542,12 +542,10 @@ INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
unsigned char hash[20];
lib_cs_lock();
if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) {
- lib_cs_unlock();
DestroyWindow(hwndDlg);
return FALSE;
}
otrl_privkey_hash_to_humanT(buff, hash);
- lib_cs_unlock();
SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff);
SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0);
SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY));
@@ -688,12 +686,10 @@ INT_PTR CALLBACK DlgBoxProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam,
unsigned char hash[20];
lib_cs_lock();
if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) {
- lib_cs_unlock();
EndDialog(hwndDlg, IDCANCEL);
return FALSE;
}
otrl_privkey_hash_to_humanT(buff, hash);
- lib_cs_unlock();
SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff);
SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0);
SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY));
@@ -746,7 +742,6 @@ unsigned int CALLBACK verify_context_thread(void *param)
lib_cs_lock();
otrl_context_set_trust(context->active_fingerprint, "verified");
otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename));
- lib_cs_unlock();
mir_sntprintf(msg, SIZEOF(msg), TranslateT(LANG_FINGERPRINT_VERIFIED), contact_get_nameT(hContact));
ShowMessage(hContact, msg);
SetEncryptionStatus(hContact, otr_context_get_trust(context));
@@ -755,7 +750,6 @@ unsigned int CALLBACK verify_context_thread(void *param)
lib_cs_lock();
otrl_context_set_trust(context->active_fingerprint, NULL);
otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename));
- lib_cs_unlock();
mir_sntprintf(msg, SIZEOF(msg), TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT(hContact));
ShowMessage(hContact, msg);
SetEncryptionStatus(hContact, otr_context_get_trust(context));
diff --git a/plugins/MirOTR/src/dllmain.cpp b/plugins/MirOTR/src/dllmain.cpp
index 643ffea251..2b3bd3d31a 100644
--- a/plugins/MirOTR/src/dllmain.cpp
+++ b/plugins/MirOTR/src/dllmain.cpp
@@ -33,11 +33,8 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda
int ModulesLoaded(WPARAM wParam, LPARAM lParam)
{
- InitUtils();
-
lib_cs_lock();
otr_user_state = otrl_userstate_create();
- lib_cs_unlock();
// this calls ReadPrivkeyFiles (above) to set filename values (also called on ME_FOLDERS_PATH_CHANGED)
InitOptions();
@@ -112,9 +109,6 @@ extern "C" __declspec(dllexport) int Unload(void)
lib_cs_lock();
otrl_userstate_free(otr_user_state);
- lib_cs_unlock();
-
- DeinitUtils();
return 0;
}
diff --git a/plugins/MirOTR/src/options.cpp b/plugins/MirOTR/src/options.cpp
index 07dadafd6b..6345502f7c 100644
--- a/plugins/MirOTR/src/options.cpp
+++ b/plugins/MirOTR/src/options.cpp
@@ -133,7 +133,6 @@ void ReadPrivkeyFiles()
otrl_privkey_read(otr_user_state, _T2A(g_private_key_filename));
otrl_privkey_read_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename), set_context_contact, 0);
otrl_instag_read(otr_user_state, _T2A(g_instag_filename));
- lib_cs_unlock();
}
static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
diff --git a/plugins/MirOTR/src/otr.cpp b/plugins/MirOTR/src/otr.cpp
index d4f560573a..908decc3c1 100644
--- a/plugins/MirOTR/src/otr.cpp
+++ b/plugins/MirOTR/src/otr.cpp
@@ -39,9 +39,7 @@ static unsigned int CALLBACK generate_key_thread(void* param)
{
Thread_Push(0);
GenKeyData *data = (GenKeyData *)param;
- //lib_cs_lock();
otrl_privkey_generate(otr_user_state, _T2A(g_private_key_filename), data->proto, data->proto);
- //lib_cs_unlock();
PostMessage(data->dialog, WMU_ENDDIALOG, 0, 0);
mir_free(data);
Thread_Pop();
diff --git a/plugins/MirOTR/src/svcs_menu.cpp b/plugins/MirOTR/src/svcs_menu.cpp
index 5467416408..ff963c9dd1 100644
--- a/plugins/MirOTR/src/svcs_menu.cpp
+++ b/plugins/MirOTR/src/svcs_menu.cpp
@@ -44,7 +44,6 @@ int StartOTR(MCONTACT hContact) {
mir_free(msg_utf8);
}
#endif
- lib_cs_unlock();
mir_free(uname);
return 0;
}
@@ -105,7 +104,6 @@ int otr_disconnect_contact(MCONTACT hContact)
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;
}
diff --git a/plugins/MirOTR/src/svcs_proto.cpp b/plugins/MirOTR/src/svcs_proto.cpp
index 90f4373128..1d89651585 100644
--- a/plugins/MirOTR/src/svcs_proto.cpp
+++ b/plugins/MirOTR/src/svcs_proto.cpp
@@ -137,7 +137,6 @@ INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam)
int ignore_msg = otrl_message_receiving(otr_user_state, &ops, (void*)ccs->hContact,
proto, proto, uname, oldmessage_utf,
&newmessage, &tlvs, &context, add_appdata, (void*)ccs->hContact);
- lib_cs_unlock();
mir_free(uname);
if ( !(pre->flags & PREF_UTF))
diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp
index 2b84202d52..2cb11f610f 100644
--- a/plugins/MirOTR/src/utils.cpp
+++ b/plugins/MirOTR/src/utils.cpp
@@ -1,25 +1,10 @@
#include "stdafx.h"
-CRITICAL_SECTION lib_cs;
-
-void InitUtils()
-{
- InitializeCriticalSection(&lib_cs);
-}
-
-void DeinitUtils()
-{
- DeleteCriticalSection(&lib_cs);
-}
+mir_cs lib_cs;
void lib_cs_lock()
{
- EnterCriticalSection(&lib_cs);
-}
-
-void lib_cs_unlock()
-{
- LeaveCriticalSection(&lib_cs);
+ mir_cslock lck(lib_cs);
}
MCONTACT find_contact(const char* userid, const char* protocol)
@@ -76,7 +61,6 @@ void VerifyFingerprint(ConnContext *context, bool verify) {
lib_cs_lock();
otrl_context_set_trust(context->active_fingerprint, (verify)?"verified":NULL);
otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename));
- lib_cs_unlock();
VerifyFingerprintMessage(context, verify);
}
diff --git a/plugins/MirOTR/src/utils.h b/plugins/MirOTR/src/utils.h
index 1b34c34eb5..633b5a0647 100644
--- a/plugins/MirOTR/src/utils.h
+++ b/plugins/MirOTR/src/utils.h
@@ -5,7 +5,6 @@
void lib_cs_lock();
-void lib_cs_unlock();
MCONTACT find_contact(const char* userid, const char* protocol);
ConnContext * otrl_context_find_miranda(OtrlUserState us, MCONTACT hContact);
@@ -41,9 +40,6 @@ void ShowMessageInlineUtf(const MCONTACT hContact, const char *msg);
void ShowMessage(const MCONTACT hContact, const TCHAR *msg);
void ShowMessageUtf(const MCONTACT hContact, const char *msg);
-void InitUtils();
-void DeinitUtils();
-
const TCHAR *policy_to_string(OtrlPolicy policy);
OtrlPolicy policy_from_string(const TCHAR *polstring);