summaryrefslogtreecommitdiff
path: root/otr/options.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-02-16 01:42:04 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-02-16 01:42:04 +0000
commitd6746ea8feb24ca5d07ddec0b331fe2a31a70ab8 (patch)
tree487dd922e6b159892e4be885c871ffe9c047e4f7 /otr/options.cpp
parentfe7c82b6e3928b3424b4d4ed7b18046b8548795d (diff)
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
Diffstat (limited to 'otr/options.cpp')
-rw-r--r--otr/options.cpp69
1 files changed, 69 insertions, 0 deletions
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 <map>
typedef std::map<HANDLE, OtrlPolicy> 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) {