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/common.h | 8 ++++++- otr/dllmain.cpp | 70 ++++++++++++++++++++----------------------------------- otr/options.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ otr/otr.mdsp | 16 +++++++++---- otr/otr_private.h | 4 ++-- otr/utils.cpp | 4 ++-- 6 files changed, 116 insertions(+), 55 deletions(-) diff --git a/otr/common.h b/otr/common.h index 062ae78..e4c7741 100644 --- a/otr/common.h +++ b/otr/common.h @@ -37,7 +37,8 @@ #include #include -#include "IcoLib.h" +#include +#include #define MODULE "OTR" @@ -61,6 +62,10 @@ extern DWORD mainThreadId; extern OtrlUserState otr_user_state; extern char private_key_filename[MAX_PATH]; +extern char fingerprint_store_filename[MAX_PATH]; + +// read the files named above +void ReadPrivkeyFiles(); #define MS_OTR_MENUSTART "OTR/Start" #define MS_OTR_MENUSTOP "OTR/Stop" @@ -68,4 +73,5 @@ extern char private_key_filename[MAX_PATH]; #define INLINE_PREFIX "[OTR Message] " #define INLINE_PREFIX_LEN 14 + #endif 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; } diff --git a/otr/options.cpp b/otr/options.cpp index 4e81895..d94afa0 100644 --- a/otr/options.cpp +++ b/otr/options.cpp @@ -1,5 +1,6 @@ #include "common.h" #include "options.h" +#include "utils.h" Options options; @@ -9,6 +10,72 @@ Options options; #include typedef std::map ContactPolicyMap; +void SetFilenames(const char *path) { + strcpy(fingerprint_store_filename, path); + strcpy(private_key_filename, path); + strcat(fingerprint_store_filename, "\\"); + strcat(private_key_filename, "\\"); + + 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); +} + +int FoldersChanged(WPARAM wParam, LPARAM lParam) { + char path[MAX_PATH]; + + FOLDERSGETDATA fgd = {0}; + fgd.cbSize = sizeof(FOLDERSGETDATA); + fgd.nMaxPathSize = sizeof(path); + fgd.szPath = path; + + CallService(MS_FOLDERS_GET_PATH, 0, (LPARAM)&fgd); + + SetFilenames(path); + ReadPrivkeyFiles(); + return 0; +} + +void LoadFilenames() { + char path[MAX_PATH]; + if(ServiceExists(MS_FOLDERS_REGISTER_PATH)) { + FOLDERSDATA fd = {0}; + fd.cbSize = sizeof(FOLDERSDATA); + strncpy(fd.szSection, "OTR",FOLDERS_NAME_MAX_SIZE); + strncpy(fd.szName, "Private Data", FOLDERS_NAME_MAX_SIZE); + fd.szFormat = PROFILE_PATH "\\OTR_data"; + + CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM)&fd); + HookEvent(ME_FOLDERS_PATH_CHANGED, FoldersChanged); + + // get the path - above are only defaults - there may be a different value in the db + FoldersChanged(0, 0); + } else { + ////////////// + /// create secure data filenames, prefixed with profile name (minus extention) and an underscore + if(CallService(MS_DB_GETPROFILEPATH, (WPARAM)MAX_PATH, (LPARAM)path)) { + GetModuleFileName(0, path, MAX_PATH); + char *p = strrchr(path, '\\'); + if(p) *p = 0; + } + + strcat(path, "\\OTR_data"); + CreatePath(path); + + SetFilenames(path); + ReadPrivkeyFiles(); + } +} + void LoadOptions() { options.default_policy = DBGetContactSettingWord(0, MODULE, "DefaultPolicy", OTRL_POLICY_OPPORTUNISTIC); // deal with changed flags in proto.h and new interpretation of 'manual' mode (see common.h) @@ -40,6 +107,8 @@ void LoadOptions() { strcpy(options.prefix, "OTR: "); options.delete_history = (DBGetContactSettingByte(0, MODULE, "DeleteHistory", 1) == 1); + + LoadFilenames(); } void SaveOptions(ContactPolicyMap *contact_policies) { diff --git a/otr/otr.mdsp b/otr/otr.mdsp index b78c0e0..6910283 100644 --- a/otr/otr.mdsp +++ b/otr/otr.mdsp @@ -99,9 +99,15 @@ extraResourceOptions= 2=resource.rc [Other] [History] -dllmain.cpp,38218 -libotr\libotr\src\context.h,0 -options.h,0 -..\..\include\m_message.h,1554 -common.h,795 otr_private.h,171 +common.h,1620 +..\..\include\m_message.h,1554 +options.h,389 +libotr\libotr\src\context.h,0 +dll.h,0 +options.cpp,1190 +utils.cpp,19 +utils.h,0 +..\..\include\m_icolib.h,0 +..\..\include\m_folders.h,5834 +dllmain.cpp,38623 diff --git a/otr/otr_private.h b/otr/otr_private.h index 1810cf0..bd4895d 100644 --- a/otr/otr_private.h +++ b/otr/otr_private.h @@ -4,8 +4,8 @@ /* VERSION DEFINITIONS */ #define VER_MAJOR 0 #define VER_MINOR 4 -#define VER_RELEASE 3 -#define VER_BUILD 1 +#define VER_RELEASE 4 +#define VER_BUILD 0 #define __STRINGIZE(x) #x #define VER_STRING __STRINGIZE( VER_MAJOR.VER_MINOR.VER_RELEASE.VER_BUILD ) diff --git a/otr/utils.cpp b/otr/utils.cpp index 2950504..cd5febf 100644 --- a/otr/utils.cpp +++ b/otr/utils.cpp @@ -233,9 +233,9 @@ int ReloadIcons(WPARAM wParam, LPARAM lParam) { void InitUtils() { if(ServiceExists(MS_SKIN2_ADDICON)) { - SKINICONDESC2 sid; + SKINICONDESC sid; - sid.cbSize = sizeof(SKINICONDESC2); + sid.cbSize = sizeof(SKINICONDESC); sid.pszSection = "OTR"; sid.hDefaultIcon = 0; -- cgit v1.2.3