From d6746ea8feb24ca5d07ddec0b331fe2a31a70ab8 Mon Sep 17 00:00:00 2001 From: sje Date: Fri, 16 Feb 2007 01:42:04 +0000 Subject: added folders support for private data storage path git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@121 4f64403b-2f21-0410-a795-97e2b3489a10 --- otr/dllmain.cpp | 70 +++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 45 deletions(-) (limited to 'otr/dllmain.cpp') 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 std::list 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; } -- cgit v1.2.3