summaryrefslogtreecommitdiff
path: root/otr/dllmain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'otr/dllmain.cpp')
-rw-r--r--otr/dllmain.cpp70
1 files changed, 25 insertions, 45 deletions
diff --git a/otr/dllmain.cpp b/otr/dllmain.cpp
index 522a3bc..9fed847 100644
--- a/otr/dllmain.cpp
+++ b/otr/dllmain.cpp
@@ -26,6 +26,11 @@ int code_page = CP_ACP;
#include <list>
std::list<void *> alloc_list;
+char fingerprint_store_filename[MAX_PATH];
+char private_key_filename[MAX_PATH];
+
+OtrlUserState otr_user_state = 0;
+
// plugin stuff
PLUGININFO pluginInfo={
sizeof(PLUGININFO),
@@ -140,10 +145,6 @@ void lib_cs_unlock() {
LeaveCriticalSection(&lib_cs);
}
-char fingerprint_store_filename[MAX_PATH];
-char private_key_filename[MAX_PATH];
-
-OtrlUserState otr_user_state = 0;
/* Return the OTR policy for the given context. */
extern "C" OtrlPolicy otr_gui_policy(void *opdata, ConnContext *context) {
@@ -1024,6 +1025,13 @@ int IconPressed(WPARAM wParam, LPARAM lParam) {
return 0;
}
+void ReadPrivkeyFiles() {
+ lib_cs_lock();
+ otrl_privkey_read(otr_user_state, private_key_filename);
+ otrl_privkey_read_fingerprints(otr_user_state, fingerprint_store_filename, 0, 0);
+ lib_cs_unlock();
+}
+
int ModulesLoaded(WPARAM wParam, LPARAM lParam) {
if(ServiceExists(MS_UPDATE_REGISTER)) {
// register with updater
@@ -1079,7 +1087,20 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) {
hEventIconPressed = HookEvent(ME_MSG_ICONPRESSED, IconPressed);
}
+ //////////////
+ /////// init OTR
+ OTRL_INIT;
+ 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)
+ LoadOptions();
+ HookEvent(ME_OPT_INITIALISE, OptInit);
+
+ // hook setting changed to monitor status
+ HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged);
+
return 0;
}
@@ -1108,40 +1129,6 @@ extern "C" DLLIMPORT int Load(PLUGINLINK *link) {
if(ServiceExists(MS_DB_SETSETTINGRESIDENT)) { // 0.6+
CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)(MODULE "/Encrypted"));
}
- //////////////
- /// create secure data filenames, prefixed with profile name (minus extention) and an underscore
- char mod_fname[MAX_PATH];
- if(CallService(MS_DB_GETPROFILEPATH, (WPARAM)MAX_PATH, (LPARAM)mod_fname)) {
- GetModuleFileName(0, mod_fname, MAX_PATH);
- char *p = strrchr(mod_fname, '\\');
- if(p) *p = 0;
- }
-
- strcat(mod_fname, "\\OTR_data");
- CreatePath(mod_fname);
- strcat(mod_fname, "\\");
-
- strcpy(fingerprint_store_filename, mod_fname);
- strcpy(private_key_filename, mod_fname);
-
- char mod_prefix[128];
- CallService(MS_DB_GETPROFILENAME, 128, (LPARAM)mod_prefix);
- char *p = strrchr(mod_prefix, '.'); // cut off extention if present
- if(p) *p = 0;
-
- strcat(fingerprint_store_filename, mod_prefix);
- strcat(private_key_filename, mod_prefix);
- strcat(fingerprint_store_filename, "_");
- strcat(private_key_filename, "_");
-
- strcat(fingerprint_store_filename, FINGERPRINT_STORE_FILENAME);
- strcat(private_key_filename, PRIVATE_KEY_FILENAME);
- //////////////
- /////// init OTR // no need to lock critical section here - only one thread
- OTRL_INIT;
- otr_user_state = otrl_userstate_create();
- otrl_privkey_read(otr_user_state, private_key_filename);
- otrl_privkey_read_fingerprints(otr_user_state, fingerprint_store_filename, 0, 0);
/////////////
////// init plugin
@@ -1167,19 +1154,12 @@ extern "C" DLLIMPORT int Load(PLUGINLINK *link) {
CreateServiceFunction(MS_OTR_MENUSTART, StartOTR);
CreateServiceFunction(MS_OTR_MENUSTOP, StopOTR);
- // init options
- LoadOptions();
- HookEvent(ME_OPT_INITIALISE, OptInit);
-
if(ServiceExists(MS_LANGPACK_GETCODEPAGE))
code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
// hook modules loaded for updater support
HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
- // hook setting changed to monitor status
- HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged);
-
return 0;
}