summaryrefslogtreecommitdiff
path: root/plugins/New_GPG
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-03-15 19:02:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-03-15 19:02:06 +0300
commit265cf5b83f7baca19925ed3b33cd62e6815f29db (patch)
tree8a7f5555823579442f63fc44b711cd84066404df /plugins/New_GPG
parentec60bf5b0f03bfb4c310957e5eec9c17193c6c15 (diff)
NewGPG: massive code cleaning
Diffstat (limited to 'plugins/New_GPG')
-rwxr-xr-xplugins/New_GPG/src/globals.h2
-rwxr-xr-xplugins/New_GPG/src/gpg_wrapper.cpp48
-rwxr-xr-xplugins/New_GPG/src/init.cpp32
-rwxr-xr-xplugins/New_GPG/src/log.cpp22
-rw-r--r--plugins/New_GPG/src/log.h9
-rwxr-xr-xplugins/New_GPG/src/main.cpp153
-rwxr-xr-xplugins/New_GPG/src/messages.cpp313
-rwxr-xr-xplugins/New_GPG/src/options.cpp285
-rwxr-xr-xplugins/New_GPG/src/srmm.cpp11
-rwxr-xr-xplugins/New_GPG/src/ui.cpp119
-rwxr-xr-xplugins/New_GPG/src/utilities.cpp365
-rwxr-xr-xplugins/New_GPG/src/version.h2
12 files changed, 578 insertions, 783 deletions
diff --git a/plugins/New_GPG/src/globals.h b/plugins/New_GPG/src/globals.h
index 5c5fd0dc28..1b8687c4d0 100755
--- a/plugins/New_GPG/src/globals.h
+++ b/plugins/New_GPG/src/globals.h
@@ -20,7 +20,7 @@
struct globals_s
{
bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bFileTransfers = false, bSameAction = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false, bDecryptFiles = false;;
- wchar_t *inopentag = nullptr, *inclosetag = nullptr, *outopentag = nullptr, *outclosetag = nullptr, *password = nullptr;
+ CMStringW wszInopentag, wszInclosetag, wszOutopentag, wszOutclosetag, wszPassword;
wchar_t key_id_global[17] = { 0 };
list <JabberAccount*> Accounts;
HFONT bold_font = nullptr;
diff --git a/plugins/New_GPG/src/gpg_wrapper.cpp b/plugins/New_GPG/src/gpg_wrapper.cpp
index aa618f9064..bac0dabaf3 100755
--- a/plugins/New_GPG/src/gpg_wrapper.cpp
+++ b/plugins/New_GPG/src/gpg_wrapper.cpp
@@ -21,15 +21,12 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae
if (!globals.gpg_valid)
return pxNotConfigured;
- wchar_t *bin_path = db_get_wsa(0, MODULENAME, "szGpgBinPath", L"");
- {
- if (!boost::filesystem::exists(bin_path)) {
- mir_free(bin_path);
- if (globals.bDebugLog)
- globals.debuglog << std::string(time_str() + ": GPG executable not found");
- *result = pxNotFound;
- return pxNotFound;
- }
+ CMStringW bin_path(g_plugin.getMStringW("szGpgBinPath"));
+ if (!boost::filesystem::exists(bin_path.c_str())) {
+ if (globals.bDebugLog)
+ globals.debuglog << std::string(time_str() + ": GPG executable not found");
+ *result = pxNotFound;
+ return pxNotFound;
}
using namespace boost::process;
@@ -41,14 +38,14 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae
env.push_back(L"LANGUAGE=en@quot");
env.push_back(L"LC_ALL=English");
env.push_back(L"LANG=C");
- argv.push_back(bin_path);
- wchar_t *home_dir = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- if (mir_wstrlen(home_dir)) //this check are required for first run gpg binary validation
- {
+ argv.push_back(bin_path.c_str());
+
+ CMStringW home_dir(g_plugin.getMStringW("szHomePath"));
+ if (!home_dir.IsEmpty()) { // this check are required for first run gpg binary validation
argv.push_back(L"--homedir");
- argv.push_back(home_dir);
+ argv.push_back(home_dir.c_str());
}
- mir_free(home_dir);
+
argv.push_back(L"--display-charset");
argv.push_back(L"utf-8");
argv.push_back(L"-z9");
@@ -156,15 +153,12 @@ pxResult pxExecute_passwd_change(std::vector<std::wstring> &aargv, pxResult *res
if (!globals.gpg_valid)
return pxNotConfigured;
- wchar_t *bin_path = db_get_wsa(0, MODULENAME, "szGpgBinPath", L"");
- {
- if (!boost::filesystem::exists(bin_path)) {
- mir_free(bin_path);
- if (globals.bDebugLog)
- globals.debuglog << std::string(time_str() + ": GPG executable not found");
- *result = pxNotFound;
- return pxNotFound;
- }
+ CMStringW bin_path(g_plugin.getMStringW("szGpgBinPath"));
+ if (!boost::filesystem::exists(bin_path.c_str())) {
+ if (globals.bDebugLog)
+ globals.debuglog << std::string(time_str() + ": GPG executable not found");
+ *result = pxNotFound;
+ return pxNotFound;
}
using namespace boost::process;
@@ -175,11 +169,9 @@ pxResult pxExecute_passwd_change(std::vector<std::wstring> &aargv, pxResult *res
std::vector<std::wstring> env;
env.push_back(L"LANGUAGE=en@quot");
env.push_back(L"LC_ALL=English");
- argv.push_back(bin_path);
+ argv.push_back(bin_path.c_str());
argv.push_back(L"--homedir");
- wchar_t *home_dir = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- argv.push_back(home_dir);
- mir_free(home_dir);
+ argv.push_back(g_plugin.getMStringW("szHomePath").c_str());
argv.push_back(L"--display-charset");
argv.push_back(L"utf-8");
argv.push_back(L"-z9");
diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp
index e9e536736b..eedda9a3c1 100755
--- a/plugins/New_GPG/src/init.cpp
+++ b/plugins/New_GPG/src/init.cpp
@@ -70,20 +70,20 @@ void InitIconLib();
void init_vars()
{
- globals.bAppendTags = g_plugin.getByte("bAppendTags", 0) != 0;
- globals.bStripTags = g_plugin.getByte("bStripTags", 0) != 0;
- globals.inopentag = db_get_wsa(0, MODULENAME, "szInOpenTag", L"<GPGdec>");
- globals.inclosetag = db_get_wsa(0, MODULENAME, "szInCloseTag", L"</GPGdec>");
- globals.outopentag = db_get_wsa(0, MODULENAME, "szOutOpenTag", L"<GPGenc>");
- globals.outclosetag = db_get_wsa(0, MODULENAME, "szOutCloseTag", L"</GPGenc>");
- globals.bDebugLog = g_plugin.getByte("bDebugLog", 0) != 0;
- globals.bAutoExchange = g_plugin.getByte("bAutoExchange", 0) != 0;
- globals.bSameAction = g_plugin.getByte("bSameAction", 0) != 0;
- globals.password = db_get_wsa(0, MODULENAME, "szKeyPassword", L"");
+ globals.bAppendTags = g_plugin.getBool("bAppendTags", 0);
+ globals.bStripTags = g_plugin.getBool("bStripTags", 0);
+ globals.wszInopentag = g_plugin.getMStringW("szInOpenTag", L"<GPGdec>");
+ globals.wszInclosetag = g_plugin.getMStringW("szInCloseTag", L"</GPGdec>");
+ globals.wszOutopentag = g_plugin.getMStringW("szOutOpenTag", L"<GPGenc>");
+ globals.wszOutclosetag = g_plugin.getMStringW("szOutCloseTag", L"</GPGenc>");
+ globals.bDebugLog = g_plugin.getBool("bDebugLog", 0);
+ globals.bAutoExchange = g_plugin.getBool("bAutoExchange", 0);
+ globals.bSameAction = g_plugin.getBool("bSameAction", 0);
+ globals.wszPassword = g_plugin.getMStringW("szKeyPassword");
globals.debuglog.init();
- globals.bJabberAPI = g_plugin.getByte("bJabberAPI", true) != 0;
- globals.bPresenceSigning = g_plugin.getByte("bPresenceSigning", 0) != 0;
- globals.bFileTransfers = g_plugin.getByte("bFileTransfers", 0) != 0;
+ globals.bJabberAPI = g_plugin.getBool("bJabberAPI", true);
+ globals.bPresenceSigning = g_plugin.getBool("bPresenceSigning", 0);
+ globals.bFileTransfers = g_plugin.getBool("bFileTransfers", 0);
globals.firstrun_rect.left = g_plugin.getDword("FirstrunWindowX", 0);
globals.firstrun_rect.top = g_plugin.getDword("FirstrunWindowY", 0);
globals.key_password_rect.left = g_plugin.getDword("PasswordWindowX", 0);
@@ -206,12 +206,6 @@ int CMPlugin::Unload()
if (!p.empty())
boost::filesystem::remove(p);
- mir_free(globals.inopentag);
- mir_free(globals.inclosetag);
- mir_free(globals.outopentag);
- mir_free(globals.outclosetag);
- if (globals.password)
- mir_free(globals.password);
clean_temp_dir();
return 0;
}
diff --git a/plugins/New_GPG/src/log.cpp b/plugins/New_GPG/src/log.cpp
index cf84dda141..24f6af9c1a 100755
--- a/plugins/New_GPG/src/log.cpp
+++ b/plugins/New_GPG/src/log.cpp
@@ -22,8 +22,8 @@ logtofile& logtofile::operator<<(wchar_t *buf)
init();
mir_cslock l(csLock);
- log.open(toUTF8(path).c_str(), std::ios::app | std::ios::ate);
- log << toUTF8(buf);
+ log.open(path, std::ios::app | std::ios::ate);
+ log << buf;
log << "\n";
log.close();
return *this;
@@ -35,7 +35,7 @@ logtofile& logtofile::operator<<(char *buf)
init();
mir_cslock l(csLock);
- log.open(toUTF8(path).c_str(), std::ios::app | std::ios::ate);
+ log.open(path, std::ios::app | std::ios::ate);
log << buf;
log << "\n";
log.close();
@@ -49,7 +49,7 @@ logtofile& logtofile::operator<<(string buf)
mir_cslock l(csLock);
char *tmp = mir_utf8encode(buf.c_str());
- log.open(toUTF8(path).c_str(), std::ios::app | std::ios::ate);
+ log.open(path, std::ios::app | std::ios::ate);
log << tmp;
log << "\n";
log.close();
@@ -63,8 +63,8 @@ logtofile& logtofile::operator<<(wstring buf)
init();
mir_cslock l(csLock);
- log.open(toUTF8(path).c_str(), std::ios::app | std::ios::ate);
- log << toUTF8(buf);
+ log.open(path, std::ios::app | std::ios::ate);
+ log << buf;
log << "\n";
log.close();
return *this;
@@ -72,20 +72,16 @@ logtofile& logtofile::operator<<(wstring buf)
void logtofile::init()
{
- if (globals.bDebugLog) {
- if (path)
- mir_free(path);
- path = db_get_wsa(0, MODULENAME, "szLogFilePath", L"C:\\GPGdebug.log");
- }
+ if (globals.bDebugLog)
+ path = g_plugin.getMStringW("szLogFilePath", L"C:\\GPGdebug.log");
+
_bDebugLog = globals.bDebugLog;
}
logtofile::logtofile()
{
- path = nullptr;
}
logtofile::~logtofile()
{
- mir_free(path);
}
diff --git a/plugins/New_GPG/src/log.h b/plugins/New_GPG/src/log.h
index 0b7315cc7f..86da7b3376 100644
--- a/plugins/New_GPG/src/log.h
+++ b/plugins/New_GPG/src/log.h
@@ -26,11 +26,12 @@ public:
void init();
~logtofile();
logtofile();
+
private:
- fstream log;
- wchar_t *path;
- bool _bDebugLog;
- mir_cs csLock;
+ wfstream log;
+ CMStringW path;
+ bool _bDebugLog;
+ mir_cs csLock;
};
#endif
diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp
index f1dc0cb427..bb0af2af05 100755
--- a/plugins/New_GPG/src/main.cpp
+++ b/plugins/New_GPG/src/main.cpp
@@ -28,17 +28,16 @@ void FirstRun()
void InitCheck()
{
+ // parse gpg output
{
- // parse gpg output
- wchar_t *current_home = db_get_wsa(0, MODULENAME, "szHomePath", L"");
+ ptrW current_home(g_plugin.getWStringA("szHomePath", L""));
g_plugin.setWString("szHomePath", L""); //we do not need home for gpg binary validation
globals.gpg_valid = isGPGValid();
g_plugin.setWString("szHomePath", current_home); //return current home dir back
- mir_free(current_home);
+ }
+ {
bool home_dir_access = false, temp_access = false;
- wchar_t *home_dir = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- std::wstring test_path = home_dir;
- mir_free(home_dir);
+ std::wstring test_path(ptrW(g_plugin.getWStringA("szHomePath", L"")));
test_path += L"/";
test_path += toUTF16(get_random(13));
wfstream test_file;
@@ -50,8 +49,8 @@ void InitCheck()
test_file.close();
boost::filesystem::remove(test_path);
}
- home_dir = _tgetenv(L"TEMP");
- test_path = home_dir;
+
+ test_path = _wgetenv(L"TEMP");
test_path += L"/";
test_path += toUTF16(get_random(13));
test_file.open(test_path, std::ios::trunc | std::ios::out);
@@ -91,14 +90,10 @@ void InitCheck()
if (result == pxNotFound)
return;
}
- home_dir = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- wstring tmp_dir = home_dir;
- mir_free(home_dir);
- tmp_dir += L"\\tmp";
- _wmkdir(tmp_dir.c_str());
- string question;
- char *keyid = nullptr;
+ _wmkdir(g_plugin.getMStringW("szHomePath") + L"\\tmp");
+
+ CMStringW wszQuestion;
for (auto &pa : Accounts()) {
if (StriStr(pa->szModuleName, "metacontacts"))
continue;
@@ -109,17 +104,16 @@ void InitCheck()
acc += pa->szModuleName;
acc += ")";
acc += "_KeyID";
- keyid = db_get_sa(0, MODULENAME, acc.c_str(), "");
- if (keyid[0]) {
- question = Translate("Your secret key with ID: ");
- mir_free(keyid);
- keyid = db_get_sa(0, MODULENAME, "KeyID", "");
+ CMStringA keyid = g_plugin.getMStringA(acc.c_str());
+ if (!keyid.IsEmpty()) {
+ wszQuestion = TranslateT("Your secret key with ID: ");
+ keyid = g_plugin.getMStringA("KeyID");
if ((p = out.find(keyid)) == string::npos) {
- question += keyid;
- question += Translate(" for account ");
- question += toUTF8(pa->tszAccountName);
- question += Translate(" deleted from GPG secret keyring.\nDo you want to set another key?");
- if (MessageBoxA(nullptr, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) {
+ wszQuestion += keyid;
+ wszQuestion += TranslateT(" for account ");
+ wszQuestion += pa->tszAccountName;
+ wszQuestion += TranslateT(" deleted from GPG secret keyring.\nDo you want to set another key?");
+ if (MessageBoxW(nullptr, wszQuestion, TranslateT("Own secret key warning"), MB_YESNO) == IDYES) {
CDlgFirstRun *d = new CDlgFirstRun;
d->DoModal();
}
@@ -155,11 +149,11 @@ void InitCheck()
}
}
if (expired) {
- question += keyid;
- question += Translate(" for account ");
- question += toUTF8(pa->tszAccountName);
- question += Translate(" expired and will not work.\nDo you want to set another key?");
- if (MessageBoxA(nullptr, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) {
+ wszQuestion += keyid;
+ wszQuestion += TranslateT(" for account ");
+ wszQuestion += pa->tszAccountName;
+ wszQuestion += TranslateT(" expired and will not work.\nDo you want to set another key?");
+ if (MessageBoxW(nullptr, wszQuestion.c_str(), TranslateT("Own secret key warning"), MB_YESNO) == IDYES) {
CDlgFirstRun *d = new CDlgFirstRun;
d->DoModal();
}
@@ -167,25 +161,22 @@ void InitCheck()
mir_free(expire_date);
}
}
- if (keyid) {
- mir_free(keyid);
- keyid = nullptr;
- }
}
- question = Translate("Your secret key with ID: ");
- keyid = db_get_sa(0, MODULENAME, "KeyID", "");
- char *key = db_get_sa(0, MODULENAME, "GPGPubKey", "");
- if (!g_plugin.getByte("FirstRun", 1) && (!keyid[0] || !key[0])) {
- question = Translate("You didn't set a private key.\nWould you like to set it now?");
- if (MessageBoxA(nullptr, question.c_str(), Translate("Own private key warning"), MB_YESNO) == IDYES) {
+
+ wszQuestion = TranslateT("Your secret key with ID: ");
+ CMStringA keyid(g_plugin.getMStringA("KeyID"));
+ CMStringA key(g_plugin.getMStringA("GPGPubKey"));
+ if (!g_plugin.getByte("FirstRun", 1) && (keyid.IsEmpty() || key.IsEmpty())) {
+ wszQuestion = TranslateT("You didn't set a private key.\nWould you like to set it now?");
+ if (MessageBoxW(nullptr, wszQuestion, TranslateT("Own private key warning"), MB_YESNO) == IDYES) {
CDlgFirstRun *d = new CDlgFirstRun;
d->DoModal();
}
}
if ((p = out.find(keyid)) == string::npos) {
- question += keyid;
- question += Translate(" deleted from GPG secret keyring.\nDo you want to set another key?");
- if (MessageBoxA(nullptr, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) {
+ wszQuestion += keyid;
+ wszQuestion += TranslateT(" deleted from GPG secret keyring.\nDo you want to set another key?");
+ if (MessageBoxW(nullptr, wszQuestion, TranslateT("Own secret key warning"), MB_YESNO) == IDYES) {
CDlgFirstRun *d = new CDlgFirstRun;
d->DoModal();
}
@@ -221,9 +212,9 @@ void InitCheck()
}
}
if (expired) {
- question += keyid;
- question += Translate(" expired and will not work.\nDo you want to set another key?");
- if (MessageBoxA(nullptr, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) {
+ wszQuestion += keyid;
+ wszQuestion += TranslateT(" expired and will not work.\nDo you want to set another key?");
+ if (MessageBoxW(nullptr, wszQuestion, TranslateT("Own secret key warning"), MB_YESNO) == IDYES) {
CDlgFirstRun *d = new CDlgFirstRun;
d->DoModal();
}
@@ -231,17 +222,14 @@ void InitCheck()
mir_free(expire_date);
}
// TODO: check for expired key
- mir_free(keyid);
- mir_free(key);
}
{
- wchar_t *path = db_get_wsa(0, MODULENAME, "szHomePath", L"");
+ CMStringW path(g_plugin.getMStringW("szHomePath"));
DWORD dwFileAttr = GetFileAttributes(path);
if (dwFileAttr != INVALID_FILE_ATTRIBUTES) {
dwFileAttr &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(path, dwFileAttr);
}
- mir_free(path);
}
}
@@ -257,35 +245,32 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
for (int i = 0; i < count; i++) {
MCONTACT hcnt = db_mc_getSub(hContact, i);
if (hcnt)
- db_set_ws(hcnt, MODULENAME, "GPGPubKey", new_key.c_str());
+ g_plugin.setWString(hcnt, "GPGPubKey", new_key.c_str());
}
}
- else db_set_ws(metaGetMostOnline(hContact), MODULENAME, "GPGPubKey", new_key.c_str());
+ else g_plugin.setWString(metaGetMostOnline(hContact), "GPGPubKey", new_key.c_str());
}
else g_plugin.setWString(hContact, "GPGPubKey", new_key.c_str());
// gpg execute block
- std::vector<wstring> cmd;
- wchar_t tmp2[MAX_PATH] = { 0 };
- {
- wcsncpy(tmp2, ptrW(db_get_wsa(0, MODULENAME, "szHomePath", L"")), MAX_PATH - 1);
- mir_wstrncat(tmp2, L"\\", _countof(tmp2) - mir_wstrlen(tmp2));
- mir_wstrncat(tmp2, L"temporary_exported.asc", _countof(tmp2) - mir_wstrlen(tmp2));
- boost::filesystem::remove(tmp2);
+ CMStringW tmp2 = g_plugin.getMStringW("szHomePath");
+ tmp2 += L"\\temporary_exported.asc";
+ boost::filesystem::remove(tmp2.c_str());
- ptrW ptmp;
- if (db_mc_isMeta(hContact))
- ptmp = db_get_wsa(metaGetMostOnline(hContact), MODULENAME, "GPGPubKey", L"");
- else
- ptmp = db_get_wsa(hContact, MODULENAME, "GPGPubKey", L"");
+ CMStringW ptmp;
+ if (db_mc_isMeta(hContact))
+ ptmp = g_plugin.getMStringW(metaGetMostOnline(hContact), "GPGPubKey");
+ else
+ ptmp = g_plugin.getMStringW(hContact, "GPGPubKey");
- wfstream f(tmp2, std::ios::out);
- f << ptmp.get();
- f.close();
- cmd.push_back(L"--batch");
- cmd.push_back(L"--import");
- cmd.push_back(tmp2);
- }
+ wfstream f(tmp2, std::ios::out);
+ f << ptmp.c_str();
+ f.close();
+
+ std::vector<wstring> cmd;
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--import");
+ cmd.push_back(tmp2.c_str());
gpg_execution_params params(cmd);
string output;
@@ -308,7 +293,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
char *tmp = nullptr;
string::size_type s = output.find("gpg: key ") + mir_strlen("gpg: key ");
string::size_type s2 = output.find(":", s);
- db_set_s(hcnt, MODULENAME, "KeyID", output.substr(s, s2 - s).c_str());
+ g_plugin.setString(hcnt, "KeyID", output.substr(s, s2 - s).c_str());
s = output.find("“", s2);
if (s == string::npos) {
s = output.find("\"", s2);
@@ -329,7 +314,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)*(output.substr(s, s2 - s - (uncommon ? 1 : 0)).length() + 1));
mir_strcpy(tmp, output.substr(s, s2 - s - (uncommon ? 1 : 0)).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(hcnt, MODULENAME, "KeyMainName", tmp);
+ g_plugin.setString(hcnt, "KeyMainName", tmp);
mir_free(tmp);
}
@@ -343,7 +328,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)* (output.substr(s2, s - s2).length() + 1));
mir_strcpy(tmp, output.substr(s2, s - s2).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(hcnt, MODULENAME, "KeyComment", tmp);
+ g_plugin.setString(hcnt, "KeyComment", tmp);
mir_free(tmp);
s += 3;
s2 = output.find(">", s);
@@ -351,7 +336,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)*(output.substr(s, s2 - s).length() + 1));
mir_strcpy(tmp, output.substr(s, s2 - s).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(hcnt, MODULENAME, "KeyMainEmail", tmp);
+ g_plugin.setString(hcnt, "KeyMainEmail", tmp);
mir_free(tmp);
}
}
@@ -359,11 +344,11 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)* (output.substr(s2, s - s2).length() + 1));
mir_strcpy(tmp, output.substr(s2, s - s2).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(hcnt, MODULENAME, "KeyMainEmail", output.substr(s2, s - s2).c_str());
+ g_plugin.setString(hcnt, "KeyMainEmail", output.substr(s2, s - s2).c_str());
mir_free(tmp);
}
}
- db_unset(hcnt, MODULENAME, "bAlwatsTrust");
+ g_plugin.delSetting(hcnt, "bAlwatsTrust");
}
}
}
@@ -371,7 +356,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
char *tmp = nullptr;
string::size_type s = output.find("gpg: key ") + mir_strlen("gpg: key ");
string::size_type s2 = output.find(":", s);
- db_set_s(metaGetMostOnline(hContact), MODULENAME, "KeyID", output.substr(s, s2 - s).c_str());
+ g_plugin.setString(metaGetMostOnline(hContact), "KeyID", output.substr(s, s2 - s).c_str());
s = output.find("“", s2);
if (s == string::npos) {
s = output.find("\"", s2);
@@ -392,7 +377,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)*(output.substr(s, s2 - s - (uncommon ? 1 : 0)).length() + 1));
mir_strcpy(tmp, output.substr(s, s2 - s - (uncommon ? 1 : 0)).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(metaGetMostOnline(hContact), MODULENAME, "KeyMainName", tmp);
+ g_plugin.setString(metaGetMostOnline(hContact), "KeyMainName", tmp);
mir_free(tmp);
}
if ((s = output.find(")", s2)) == string::npos)
@@ -405,7 +390,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)* (output.substr(s2, s - s2).length() + 1));
mir_strcpy(tmp, output.substr(s2, s - s2).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(metaGetMostOnline(hContact), MODULENAME, "KeyComment", tmp);
+ g_plugin.setString(metaGetMostOnline(hContact), "KeyComment", tmp);
mir_free(tmp);
s += 3;
s2 = output.find(">", s);
@@ -413,7 +398,7 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)*(output.substr(s, s2 - s).length() + 1));
mir_strcpy(tmp, output.substr(s, s2 - s).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(metaGetMostOnline(hContact), MODULENAME, "KeyMainEmail", tmp);
+ g_plugin.setString(metaGetMostOnline(hContact), "KeyMainEmail", tmp);
mir_free(tmp);
}
}
@@ -421,11 +406,11 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
tmp = (char*)mir_alloc(sizeof(char)* (output.substr(s2, s - s2).length() + 1));
mir_strcpy(tmp, output.substr(s2, s - s2).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(metaGetMostOnline(hContact), MODULENAME, "KeyMainEmail", output.substr(s2, s - s2).c_str());
+ g_plugin.setString(metaGetMostOnline(hContact), "KeyMainEmail", output.substr(s2, s - s2).c_str());
mir_free(tmp);
}
}
- db_unset(metaGetMostOnline(hContact), MODULENAME, "bAlwatsTrust");
+ g_plugin.delSetting(metaGetMostOnline(hContact), "bAlwatsTrust");
}
}
else {
@@ -490,5 +475,5 @@ void ImportKey(MCONTACT hContact, std::wstring new_key)
}
MessageBox(nullptr, toUTF16(output).c_str(), L"", MB_OK);
- boost::filesystem::remove(tmp2);
+ boost::filesystem::remove(tmp2.c_str());
}
diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp
index a176b175d6..40cd491462 100755
--- a/plugins/New_GPG/src/messages.cpp
+++ b/plugins/New_GPG/src/messages.cpp
@@ -55,12 +55,12 @@ static void RecvMsgSvc_func(RecvParams *param)
ShowLoadPublicKeyDialog(true);
}
else {
- db_set_b(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, MODULENAME, "GPGEncryption", 1);
+ g_plugin.setByte(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
}
if (isContactHaveKey(hContact)) {
- db_set_b(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, MODULENAME, "GPGEncryption", 1);
+ g_plugin.setByte(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
}
@@ -76,7 +76,7 @@ static void RecvMsgSvc_func(RecvParams *param)
boost::algorithm::erase_all(param->str, "\r");
s2 += mir_wstrlen(L"-----END PGP MESSAGE-----");
- ptrW ptszHomePath(db_get_wsa(0, MODULENAME, "szHomePath", L""));
+ ptrW ptszHomePath(g_plugin.getWStringA("szHomePath", L""));
wstring encfile = toUTF16(get_random(10));
wstring decfile = toUTF16(get_random(10));
{
@@ -114,35 +114,33 @@ static void RecvMsgSvc_func(RecvParams *param)
std::vector<wstring> cmd;
cmd.push_back(L"--batch");
{
- char *inkeyid = db_get_sa(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, MODULENAME, "InKeyID", "");
- wchar_t *pass = nullptr;
- if (inkeyid[0]) {
+ CMStringA inkeyid = g_plugin.getMStringA(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, "InKeyID");
+ CMStringW pass;
+ if (!inkeyid.IsEmpty()) {
string dbsetting = "szKey_";
dbsetting += inkeyid;
dbsetting += "_Password";
- pass = db_get_wsa(0, MODULENAME, dbsetting.c_str(), L"");
- if (pass[0] && globals.bDebugLog)
- globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid + ", trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password");
+ pass = g_plugin.getMStringW(dbsetting.c_str());
+ if (!pass.IsEmpty() && globals.bDebugLog)
+ globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid.c_str() + ", trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password");
}
else {
- pass = db_get_wsa(0, MODULENAME, "szKeyPassword", L"");
- if (pass[0] && globals.bDebugLog)
+ pass = g_plugin.getMStringW("szKeyPassword");
+ if (!pass.IsEmpty() && globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password");
}
- if (pass && pass[0]) {
+ if (!pass.IsEmpty()) {
cmd.push_back(L"--passphrase");
- cmd.push_back(pass);
+ cmd.push_back(pass.c_str());
}
- else if (globals.password && globals.password[0]) {
+ else if (!globals.wszPassword.IsEmpty()) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password");
cmd.push_back(L"--passphrase");
- cmd.push_back(globals.password);
+ cmd.push_back(globals.wszPassword.c_str());
}
else if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with out password");
- mir_free(pass);
- mir_free(inkeyid);
}
if (!globals.bDebugLog) {
@@ -203,18 +201,18 @@ static void RecvMsgSvc_func(RecvParams *param)
string::size_type s = out.find(" encrypted with ");
s = out.find(" ID ", s);
s += mir_strlen(" ID ");
- db_set_s(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, MODULENAME, "InKeyID", out.substr(s, out.find(",", s) - s).c_str());
+ g_plugin.setString(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, "InKeyID", out.substr(s, out.find(",", s) - s).c_str());
}
CDlgKeyPasswordMsgBox *d = new CDlgKeyPasswordMsgBox(hContact);
d->DoModal();
std::vector<wstring> cmd2 = cmd;
- if (globals.password) {
+ if (!globals.wszPassword.IsEmpty()) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)));
std::vector<wstring> tmp3;
tmp3.push_back(L"--passphrase");
- tmp3.push_back(globals.password);
+ tmp3.push_back(globals.wszPassword.c_str());
cmd2.insert(cmd2.begin(), tmp3.begin(), tmp3.end());
}
out.clear();
@@ -340,8 +338,8 @@ static void RecvMsgSvc_func(RecvParams *param)
fix_line_term(param->str);
if (globals.bAppendTags) {
- param->str.insert(0, globals.inopentag);
- param->str.append(globals.inclosetag);
+ param->str.insert(0, globals.wszInopentag);
+ param->str.append(globals.wszInclosetag);
}
char *tmp = mir_strdup(toUTF8(param->str).c_str());
@@ -352,7 +350,7 @@ static void RecvMsgSvc_func(RecvParams *param)
}
}
}
- if (db_get_b(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, MODULENAME, "GPGEncryption", 0)) {
+ if (g_plugin.getByte(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, "GPGEncryption")) {
HistoryLog(hContact, db_event(param->msg, param->timestamp, 0, dbflags | DBEF_READ));
delete param;
return;
@@ -394,50 +392,45 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l)
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info(autoexchange): found pubkey block:" + toUTF8(Clist_GetContactDisplayName(ccs->hContact)));
s2 += mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----");
- db_set_ws(ccs->hContact, MODULENAME, "GPGPubKey", str.substr(s1, s2 - s1).c_str());
- { //gpg execute block
+ g_plugin.setWString(ccs->hContact, "GPGPubKey", str.substr(s1, s2 - s1).c_str());
+ {
+ // gpg execute block
std::vector<wstring> cmd;
- wchar_t tmp2[MAX_PATH] = { 0 };
string output;
DWORD exitcode;
+
+ CMStringW tmp2(g_plugin.getMStringW("szHomePath"));
+ tmp2 += L"\\";
+ tmp2 += get_random(5).c_str();
+ tmp2 += L".asc";
+
+ if (!globals.bDebugLog) {
+ boost::system::error_code e;
+ boost::filesystem::remove(tmp2.c_str(), e);
+ }
+ wfstream f(tmp2, std::ios::out);
{
- ptrW ptmp(db_get_wsa(0, MODULENAME, "szHomePath", L""));
- mir_wstrcpy(tmp2, ptmp);
- mir_free(ptmp);
- mir_wstrcat(tmp2, L"\\");
- wchar_t *tmp3 = mir_a2u(get_random(5).c_str());
- mir_wstrcat(tmp2, tmp3);
- mir_wstrcat(tmp2, L".asc");
- mir_free(tmp3);
- //mir_wstrcat(tmp2, L"temporary_exported.asc");
- if (!globals.bDebugLog) {
- boost::system::error_code e;
- boost::filesystem::remove(tmp2, e);
- }
- wfstream f(tmp2, std::ios::out);
- {
- const int timeout = 5000, step = 100;
- int count = 0;
- while (!f.is_open()) {
- ::Sleep(step);
- count += step;
- if (count >= timeout) {
- db_set_b(ccs->hContact, MODULENAME, "GPGEncryption", 0);
- setSrmmIcon(ccs->hContact);
- setClistIcon(ccs->hContact);
- globals.debuglog << std::string(time_str() + "info: failed to create temporary file for decryption, disabling gpg for contact to avoid deadlock");
- return 1;
- }
- f.open(tmp2, std::ios::out);
+ const int timeout = 5000, step = 100;
+ int count = 0;
+ while (!f.is_open()) {
+ ::Sleep(step);
+ count += step;
+ if (count >= timeout) {
+ g_plugin.setByte(ccs->hContact, "GPGEncryption", 0);
+ setSrmmIcon(ccs->hContact);
+ setClistIcon(ccs->hContact);
+ globals.debuglog << std::string(time_str() + "info: failed to create temporary file for decryption, disabling gpg for contact to avoid deadlock");
+ return 1;
}
+ f.open(tmp2, std::ios::out);
}
- ptmp = db_get_wsa(ccs->hContact, MODULENAME, "GPGPubKey", L"");
- f << (wchar_t*)ptmp;
- f.close();
- cmd.push_back(L"--batch");
- cmd.push_back(L"--import");
- cmd.push_back(tmp2);
}
+ f << g_plugin.getMStringW(ccs->hContact, "GPGPubKey").c_str();
+ f.close();
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--import");
+ cmd.push_back(tmp2.c_str());
+
gpg_execution_params params(cmd);
pxResult result;
params.out = &output;
@@ -447,73 +440,67 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l)
return 1;
if (!globals.bDebugLog) {
boost::system::error_code e;
- boost::filesystem::remove(tmp2, e);
+ boost::filesystem::remove(tmp2.c_str(), e);
}
if (result == pxNotFound)
return 1;
- /* if (result == pxSuccessExitCodeInvalid) //sometime we have invalid return code after succesful decryption, this should be non-fatal at least
- {
- HistoryLog(ccs->hContact, db_event(Translate("failed to decrypt message, GPG returned error, turn on debug log for more details")));
- return 1;
- } */
- {
- char *tmp = nullptr;
- s1 = output.find("gpg: key ") + mir_strlen("gpg: key ");
- s2 = output.find(":", s1);
- db_set_s(ccs->hContact, MODULENAME, "KeyID", output.substr(s1, s2 - s1).c_str());
- s2 += 2;
- s1 = output.find("“", s2);
- if (s1 == string::npos) {
- s1 = output.find("\"", s2);
- s1 += 1;
- }
- else s1 += 3;
-
- if ((s2 = output.find("(", s1)) == string::npos)
- s2 = output.find("<", s1);
- else if (s2 > output.find("<", s1))
- s2 = output.find("<", s1);
- tmp = (char*)mir_alloc(output.substr(s1, s2 - s1 - 1).length() + 1);
- mir_strcpy(tmp, output.substr(s1, s2 - s1 - 1).c_str());
+
+ s1 = output.find("gpg: key ") + mir_strlen("gpg: key ");
+ s2 = output.find(":", s1);
+ g_plugin.setString(ccs->hContact, "KeyID", output.substr(s1, s2 - s1).c_str());
+ s2 += 2;
+ s1 = output.find("“", s2);
+ if (s1 == string::npos) {
+ s1 = output.find("\"", s2);
+ s1 += 1;
+ }
+ else s1 += 3;
+
+ if ((s2 = output.find("(", s1)) == string::npos)
+ s2 = output.find("<", s1);
+ else if (s2 > output.find("<", s1))
+ s2 = output.find("<", s1);
+
+ char *tmp = (char*)mir_alloc(output.substr(s1, s2 - s1 - 1).length() + 1);
+ mir_strcpy(tmp, output.substr(s1, s2 - s1 - 1).c_str());
+ mir_utf8decode(tmp, nullptr);
+ g_plugin.setString(ccs->hContact, "KeyMainName", tmp);
+ mir_free(tmp);
+ if ((s1 = output.find(")", s2)) == string::npos)
+ s1 = output.find(">", s2);
+ else if (s1 > output.find(">", s2))
+ s1 = output.find(">", s2);
+ s2++;
+ if (output[s1] == ')') {
+ tmp = (char*)mir_alloc(output.substr(s2, s1 - s2).length() + 1);
+ mir_strcpy(tmp, output.substr(s2, s1 - s2).c_str());
mir_utf8decode(tmp, nullptr);
- db_set_s(ccs->hContact, MODULENAME, "KeyMainName", tmp);
+ g_plugin.setString(ccs->hContact, "KeyComment", tmp);
+ mir_free(tmp);
+ s1 += 3;
+ s2 = output.find(">", s1);
+ tmp = (char*)mir_alloc(output.substr(s1, s2 - s1).length() + 1);
+ mir_strcpy(tmp, output.substr(s1, s2 - s1).c_str());
+ mir_utf8decode(tmp, nullptr);
+ g_plugin.setString(ccs->hContact, "KeyMainEmail", tmp);
+ mir_free(tmp);
+ }
+ else {
+ tmp = (char*)mir_alloc(output.substr(s2, s1 - s2).length() + 1);
+ mir_strcpy(tmp, output.substr(s2, s1 - s2).c_str());
+ mir_utf8decode(tmp, nullptr);
+ g_plugin.setString(ccs->hContact, "KeyMainEmail", output.substr(s2, s1 - s2).c_str());
mir_free(tmp);
- if ((s1 = output.find(")", s2)) == string::npos)
- s1 = output.find(">", s2);
- else if (s1 > output.find(">", s2))
- s1 = output.find(">", s2);
- s2++;
- if (output[s1] == ')') {
- tmp = (char*)mir_alloc(output.substr(s2, s1 - s2).length() + 1);
- mir_strcpy(tmp, output.substr(s2, s1 - s2).c_str());
- mir_utf8decode(tmp, nullptr);
- db_set_s(ccs->hContact, MODULENAME, "KeyComment", tmp);
- mir_free(tmp);
- s1 += 3;
- s2 = output.find(">", s1);
- tmp = (char*)mir_alloc(output.substr(s1, s2 - s1).length() + 1);
- mir_strcpy(tmp, output.substr(s1, s2 - s1).c_str());
- mir_utf8decode(tmp, nullptr);
- db_set_s(ccs->hContact, MODULENAME, "KeyMainEmail", tmp);
- mir_free(tmp);
- }
- else {
- tmp = (char*)mir_alloc(output.substr(s2, s1 - s2).length() + 1);
- mir_strcpy(tmp, output.substr(s2, s1 - s2).c_str());
- mir_utf8decode(tmp, nullptr);
- db_set_s(ccs->hContact, MODULENAME, "KeyMainEmail", output.substr(s2, s1 - s2).c_str());
- mir_free(tmp);
- }
- db_set_b(ccs->hContact, MODULENAME, "GPGEncryption", 1);
- db_set_b(ccs->hContact, MODULENAME, "bAlwatsTrust", 1);
- setSrmmIcon(ccs->hContact);
- setClistIcon(ccs->hContact);
- if (db_mc_isSub(ccs->hContact)) {
- setSrmmIcon(db_mc_getMeta(ccs->hContact));
- setClistIcon(db_mc_getMeta(ccs->hContact));
- }
- HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature");
}
+ g_plugin.setByte(ccs->hContact, "GPGEncryption", 1);
+ g_plugin.setByte(ccs->hContact, "bAlwatsTrust", 1);
+ setSrmmIcon(ccs->hContact);
+ setClistIcon(ccs->hContact);
+ if (db_mc_isSub(ccs->hContact)) {
+ setSrmmIcon(db_mc_getMeta(ccs->hContact));
+ setClistIcon(db_mc_getMeta(ccs->hContact));
+ }
+ HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature");
}
return 1;
}
@@ -541,17 +528,17 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l)
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info(autoexchange): received key request from: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)));
- ptrA tmp(db_get_sa(0, MODULENAME, "GPGPubKey", ""));
- if (tmp[0]) {
- int enc_state = db_get_b(ccs->hContact, MODULENAME, "GPGEncryption", 0);
+ CMStringA tmp(g_plugin.getMStringA("GPGPubKey"));
+ if (!tmp.IsEmpty()) {
+ int enc_state = g_plugin.getByte(ccs->hContact, "GPGEncryption");
if (enc_state)
- db_set_b(ccs->hContact, MODULENAME, "GPGEncryption", 0);
+ g_plugin.setByte(ccs->hContact, "GPGEncryption", 0);
string str1 = "-----PGP KEY RESPONSE-----";
str1.append(tmp);
ProtoChainSend(ccs->hContact, PSS_MESSAGE, 0, (LPARAM)str1.c_str());
if (enc_state)
- db_set_b(ccs->hContact, MODULENAME, "GPGEncryption", 1);
+ g_plugin.setByte(ccs->hContact, "GPGEncryption", 1);
}
return 0;
}
@@ -598,45 +585,41 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags)
str.replace(i, 2, L"\n"); */
string out;
DWORD code;
- wstring file = toUTF16(get_random(10)), path;
+ wstring file = toUTF16(get_random(10));
std::vector<std::wstring> cmd;
{
wchar_t *tmp2;
- {
- char *tmp = db_get_sa(hContact, MODULENAME, "KeyID", "");
- if (!tmp[0]) {
- mir_free(tmp);
- HistoryLog(hContact, db_event("Failed to encrypt message with GPG (not found key for encryption in db)", 0, 0, DBEF_SENT));
- ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg);
- return;
- }
- if (!globals.bJabberAPI) //force jabber to handle encrypted message by itself
- {
- cmd.push_back(L"--comment");
- cmd.push_back(L"\"\"");
- cmd.push_back(L"--no-version");
- }
- if (g_plugin.getByte(hContact, "bAlwaysTrust", 0)) {
- cmd.push_back(L"--trust-model");
- cmd.push_back(L"always");
- }
- cmd.push_back(L"--batch");
- cmd.push_back(L"--yes");
- cmd.push_back(L"-eatr");
- tmp2 = mir_a2u(tmp);
- mir_free(tmp);
+
+ CMStringA tmp(g_plugin.getMStringA(hContact, "KeyID"));
+ if (tmp.IsEmpty()) {
+ HistoryLog(hContact, db_event("Failed to encrypt message with GPG (not found key for encryption in db)", 0, 0, DBEF_SENT));
+ ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg);
+ return;
+ }
+
+ if (!globals.bJabberAPI) { //force jabber to handle encrypted message by itself
+ cmd.push_back(L"--comment");
+ cmd.push_back(L"\"\"");
+ cmd.push_back(L"--no-version");
+ }
+ if (g_plugin.getByte(hContact, "bAlwaysTrust", 0)) {
+ cmd.push_back(L"--trust-model");
+ cmd.push_back(L"always");
}
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--yes");
+ cmd.push_back(L"-eatr");
+ tmp2 = mir_a2u(tmp);
+
cmd.push_back(tmp2);
mir_free(tmp2);
}
- {
- wchar_t *tmp2 = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- path = tmp2;
- cmd.push_back(std::wstring(tmp2) + L"\\tmp\\" + file);
- mir_free(tmp2);
- }
+
+ CMStringW path(g_plugin.getMStringW("szHomePath"));
path += L"\\tmp\\";
- path += file;
+ path += file.c_str();
+ cmd.push_back(path.c_str());
+
const int timeout = 5000, step = 100;
int count = 0;
{
@@ -708,17 +691,17 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags)
ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg);
if (!globals.bDebugLog) {
boost::system::error_code e;
- boost::filesystem::remove(path, e);
+ boost::filesystem::remove(path.c_str(), e);
}
return;
}
if (!globals.bDebugLog) {
boost::system::error_code e;
- boost::filesystem::remove(path, e);
+ boost::filesystem::remove(path.c_str(), e);
}
- path.append(L".asc");
+ path += L".asc";
wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
count = 0;
while (!f.is_open()) {
@@ -746,7 +729,7 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags)
f.close();
if (!globals.bDebugLog) {
boost::system::error_code e;
- boost::filesystem::remove(path, e);
+ boost::filesystem::remove(path.c_str(), e);
}
}
@@ -760,8 +743,8 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags)
string str_event = msg;
if (globals.bAppendTags) {
- str_event.insert(0, toUTF8(globals.outopentag));
- str_event.append(toUTF8(globals.outclosetag));
+ str_event.insert(0, toUTF8(globals.wszOutopentag.c_str()));
+ str_event.append(toUTF8(globals.wszOutclosetag.c_str()));
}
if (globals.bDebugLog)
@@ -881,8 +864,8 @@ int HookSendMsg(WPARAM w, LPARAM l)
if (globals.bAppendTags) {
string str_event = (char*)dbei->pBlob;
//mir_free(dbei->pBlob);
- str_event.insert(0, toUTF8(globals.outopentag));
- str_event.append(toUTF8(globals.outclosetag));
+ str_event.insert(0, toUTF8(globals.wszOutopentag.c_str()));
+ str_event.append(toUTF8(globals.wszOutclosetag.c_str()));
dbei->pBlob = (PBYTE)mir_strdup(str_event.c_str());
dbei->cbBlob = (DWORD)str_event.length() + 1;
}
diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp
index 4e3814f502..6728343fe5 100755
--- a/plugins/New_GPG/src/options.cpp
+++ b/plugins/New_GPG/src/options.cpp
@@ -64,34 +64,16 @@ public:
int row = list_USERLIST.AddItem(L"", 0);
list_USERLIST.SetItemText(row, 0, name);
- wchar_t *tmp = mir_a2u(Proto_GetBaseAccountName(hContact));
- list_USERLIST.SetItemText(row, 4, tmp);
- mir_free(tmp);
+ list_USERLIST.SetItemText(row, 4, _A2T(Proto_GetBaseAccountName(hContact)));
- char *tmp2 = db_get_sa(hContact, MODULENAME, "KeyID", "");
- tmp = mir_a2u(tmp2);
- mir_free(tmp2);
- list_USERLIST.SetItemText(row, 1, (mir_wstrlen(tmp) > 1) ? tmp : L"not set");
- mir_free(tmp);
+ CMStringW tmp = g_plugin.getMStringW(hContact, "KeyID", L"not set");
+ list_USERLIST.SetItemText(row, 1, tmp);
- tmp2 = db_get_sa(hContact, MODULENAME, "KeyMainName", "");
- if (!toUTF16(tmp2).empty())
- tmp = mir_wstrdup(toUTF16(tmp2).c_str());
- else
- tmp = db_get_wsa(hContact, MODULENAME, "KeyMainName", L"");
- mir_free(tmp2);
- list_USERLIST.SetItemText(row, 2, (mir_wstrlen(tmp) > 1) ? tmp : L"not set");
- mir_free(tmp);
-
- tmp2 = db_get_sa(hContact, MODULENAME, "KeyMainEmail", "");
- if (!toUTF16(tmp2).empty())
- tmp = mir_wstrdup(toUTF16(tmp2).c_str());
- else
- tmp = db_get_wsa(hContact, MODULENAME, "KeyMainEmail", L"");
- mir_free(tmp2);
- list_USERLIST.SetItemText(row, 3, (mir_wstrlen(tmp) > 1) ? tmp : L"not set");
- mir_free(tmp);
+ tmp = g_plugin.getMStringW(hContact, "KeyMainName", L"not set");
+ list_USERLIST.SetItemText(row, 2, tmp);
+ tmp = g_plugin.getMStringW(hContact, "KeyMainEmail", L"not set");
+ list_USERLIST.SetItemText(row, 3, tmp);
if (g_plugin.getByte(hContact, "GPGEncryption", 0))
list_USERLIST.SetCheckState(row, 1);
@@ -104,20 +86,19 @@ public:
i++;
}
}
- edit_LOG_FILE_EDIT.SetText(ptrW(db_get_wsa(0, MODULENAME, "szLogFilePath", L"")));
+ edit_LOG_FILE_EDIT.SetText(ptrW(g_plugin.getWStringA("szLogFilePath", L"")));
check_DEBUG_LOG.SetState(g_plugin.getByte("bDebugLog", 0));
check_JABBER_API.Enable();
check_AUTO_EXCHANGE.Enable(globals.bJabberAPI);
- {
- string keyinfo = Translate("Default private key ID");
- keyinfo += ": ";
- char *keyid = db_get_sa(0, MODULENAME, "KeyID", "");
- keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
- mir_free(keyid);
- lbl_CURRENT_KEY.SetTextA(keyinfo.c_str());
- }
+ CMStringW keyinfo = TranslateT("Default private key ID");
+ keyinfo += L": ";
+
+ ptrW keyid(g_plugin.getWStringA("KeyID"));
+ keyinfo += (mir_wstrlen(keyid) > 0) ? keyid : TranslateT("not set");
+ lbl_CURRENT_KEY.SetText(keyinfo);
+
check_JABBER_API.SetState(g_plugin.getByte("bJabberAPI", 1));
check_FILE_TRANSFERS.SetState(g_plugin.getByte("bFileTransfers", 0));
check_AUTO_EXCHANGE.SetState(g_plugin.getByte("bAutoExchange", 0));
@@ -156,7 +137,6 @@ public:
void setSrmmIcon(MCONTACT hContact);
{ //gpg execute block
wchar_t *ptmp;
- char *tmp;
bool keep = false;
bool ismetacontact = false;
MCONTACT meta = NULL;
@@ -170,18 +150,18 @@ public:
hContact = metaGetMostOnline(meta);
ismetacontact = true;
}
- tmp = db_get_sa(hContact, MODULENAME, "KeyID", "");
+
+ CMStringA tmp(g_plugin.getMStringA(hContact, "KeyID"));
for (auto &hcnttmp : Contacts()) {
if (hcnttmp != hContact) {
- char *tmp2 = db_get_sa(hcnttmp, MODULENAME, "KeyID", "");
+ ptrA tmp2(g_plugin.getStringA(hcnttmp, "KeyID"));
if (!mir_strcmp(tmp, tmp2)) {
- mir_free(tmp2);
keep = true;
break;
}
- mir_free(tmp2);
}
}
+
if (!keep)
if (MessageBox(nullptr, TranslateT("This key is not used by any contact. Do you want to remove it from public keyring?"), TranslateT("Key info"), MB_YESNO) == IDYES) {
std::vector<wstring> cmd;
@@ -198,20 +178,18 @@ public:
params.out = &output;
params.code = &exitcode;
params.result = &result;
- if (!gpg_launcher(params)) {
- mir_free(tmp);
+ if (!gpg_launcher(params))
return;
- }
- if (result == pxNotFound) {
- mir_free(tmp);
+
+ if (result == pxNotFound)
return;
- }
+
if (output.find("--delete-secret-keys") != string::npos)
MessageBox(nullptr, TranslateT("we have secret key for this public key, do not removing from GPG keyring"), TranslateT("info"), MB_OK);
else
MessageBox(nullptr, TranslateT("Key removed from GPG keyring"), TranslateT("info"), MB_OK);
}
- mir_free(tmp);
+
if (ismetacontact) {
if (MessageBox(nullptr, TranslateT("Do you want to remove key from entire metacontact (all subcontacts)?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) {
MCONTACT hcnt = NULL;
@@ -219,12 +197,12 @@ public:
for (int i = 0; i < count; i++) {
hcnt = db_mc_getSub(meta, i);
if (hcnt) {
- db_unset(hcnt, MODULENAME, "KeyID");
- db_unset(hcnt, MODULENAME, "GPGPubKey");
- db_unset(hcnt, MODULENAME, "KeyMainName");
- db_unset(hcnt, MODULENAME, "KeyType");
- db_unset(hcnt, MODULENAME, "KeyMainEmail");
- db_unset(hcnt, MODULENAME, "KeyComment");
+ g_plugin.delSetting(hcnt, "KeyID");
+ g_plugin.delSetting(hcnt, "GPGPubKey");
+ g_plugin.delSetting(hcnt, "KeyMainName");
+ g_plugin.delSetting(hcnt, "KeyType");
+ g_plugin.delSetting(hcnt, "KeyMainEmail");
+ g_plugin.delSetting(hcnt, "KeyComment");
setClistIcon(hcnt);
setSrmmIcon(hcnt);
}
@@ -242,12 +220,12 @@ public:
}
}
else {
- db_unset(globals.user_data[item_num + 1], MODULENAME, "KeyID");
- db_unset(globals.user_data[item_num + 1], MODULENAME, "GPGPubKey");
- db_unset(globals.user_data[item_num + 1], MODULENAME, "KeyMainName");
- db_unset(globals.user_data[item_num + 1], MODULENAME, "KeyType");
- db_unset(globals.user_data[item_num + 1], MODULENAME, "KeyMainEmail");
- db_unset(globals.user_data[item_num + 1], MODULENAME, "KeyComment");
+ g_plugin.delSetting(globals.user_data[item_num + 1], "KeyID");
+ g_plugin.delSetting(globals.user_data[item_num + 1], "GPGPubKey");
+ g_plugin.delSetting(globals.user_data[item_num + 1], "KeyMainName");
+ g_plugin.delSetting(globals.user_data[item_num + 1], "KeyType");
+ g_plugin.delSetting(globals.user_data[item_num + 1], "KeyMainEmail");
+ g_plugin.delSetting(globals.user_data[item_num + 1], "KeyComment");
setClistIcon(globals.user_data[item_num + 1]);
setSrmmIcon(globals.user_data[item_num + 1]);
}
@@ -267,10 +245,8 @@ public:
{
wchar_t *tmp = GetFilePath(TranslateT("Export public key"), L"*", TranslateT(".asc pubkey file"), true);
if (tmp) {
- wstring str(ptrW(db_get_wsa(globals.user_data[item_num + 1], MODULENAME, "GPGPubKey", L"")));
- wstring::size_type s = 0;
- while ((s = str.find(L"\r", s)) != wstring::npos)
- str.erase(s, 1);
+ CMStringW str(g_plugin.getMStringW(globals.user_data[item_num + 1], "GPGPubKey"));
+ str.Replace(L"\r", L"");
wfstream f(tmp, std::ios::out);
delete[] tmp;
@@ -282,16 +258,16 @@ public:
void onClick_COPY_KEY(CCtrlButton*)
{
if (OpenClipboard(m_hwnd)) {
- char *szKey = db_get_sa(0, MODULENAME, "GPGPubKey", "");
- std::string str = szKey;
- mir_free(szKey);
- boost::algorithm::replace_all(str, "\n", "\r\n");
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.size() + 1);
+ CMStringA str(g_plugin.getMStringA("GPGPubKey"));
+ str.Replace("\n", "\r\n");
+
+ HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.GetLength() + 1);
if (!hMem) {
MessageBox(nullptr, TranslateT("Failed to allocate memory"), TranslateT("Error"), MB_OK);
return;
}
- szKey = (char*)GlobalLock(hMem);
+
+ char *szKey = (char*)GlobalLock(hMem);
if (!szKey) {
wchar_t msg[64];
mir_snwprintf(msg, TranslateT("Failed to lock memory with error %d"), GetLastError());
@@ -299,9 +275,9 @@ public:
GlobalFree(hMem);
}
else {
- memcpy(szKey, str.c_str(), str.size());
- szKey[str.size()] = '\0';
- str.clear();
+ memcpy(szKey, str.c_str(), str.GetLength());
+ szKey[str.GetLength()] = '\0';
+
EmptyClipboard();
GlobalUnlock(hMem);
if (!SetClipboardData(CF_OEMTEXT, hMem)) {
@@ -343,9 +319,9 @@ public:
void setSrmmIcon(MCONTACT hContact);
item_num = hdr->iItem;
if (list_USERLIST.GetCheckState(hdr->iItem))
- db_set_b(globals.user_data[item_num + 1], MODULENAME, "GPGEncryption", 1);
+ g_plugin.setByte(globals.user_data[item_num + 1], "GPGEncryption", 1);
else
- db_set_b(globals.user_data[item_num + 1], MODULENAME, "GPGEncryption", 0);
+ g_plugin.setByte(globals.user_data[item_num + 1], "GPGEncryption", 0);
setClistIcon(globals.user_data[item_num + 1]);
setSrmmIcon(globals.user_data[item_num + 1]);
}
@@ -384,8 +360,8 @@ public:
bool OnInitDialog() override
{
- edit_BIN_PATH.SetText(ptrW(db_get_wsa(0, MODULENAME, "szGpgBinPath", L"gpg.exe")));
- edit_HOME_DIR.SetText(ptrW(db_get_wsa(0, MODULENAME, "szHomePath", L"gpg")));
+ edit_BIN_PATH.SetText(g_plugin.getMStringW("szGpgBinPath", L"gpg.exe"));
+ edit_HOME_DIR.SetText(g_plugin.getMStringW("szHomePath", L"gpg"));
return true;
}
@@ -403,7 +379,7 @@ public:
void onClick_SET_BIN_PATH(CCtrlButton*)
{
GetFilePath(TranslateT("Choose gpg.exe"), "szGpgBinPath", L"*.exe", TranslateT("EXE Executables"));
- CMStringW tmp(ptrW(db_get_wsa(0, MODULENAME, "szGpgBinPath", L"gpg.exe")));
+ CMStringW tmp(g_plugin.getMStringW("szGpgBinPath", L"gpg.exe"));
edit_BIN_PATH.SetText(tmp);
bool gpg_exists = false;
{
@@ -411,7 +387,7 @@ public:
gpg_exists = true;
if (gpg_exists) {
bool bad_version = false;
- wchar_t *tmp_path = db_get_wsa(0, MODULENAME, "szGpgBinPath", L"");
+ CMStringW tmp_path = g_plugin.getMStringW("szGpgBinPath", L"");
g_plugin.setWString("szGpgBinPath", tmp);
string out;
DWORD code;
@@ -427,7 +403,7 @@ public:
gpg_launcher(params);
globals.gpg_valid = old_gpg_state;
g_plugin.setWString("szGpgBinPath", tmp_path);
- mir_free(tmp_path);
+
string::size_type p1 = out.find("(GnuPG) ");
if (p1 != string::npos) {
p1 += mir_strlen("(GnuPG) ");
@@ -438,8 +414,6 @@ public:
bad_version = false;
MessageBox(nullptr, TranslateT("This is not GnuPG binary!\nIt is recommended that you use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK);
}
- /* if(bad_version) //looks like working fine with gpg2
- MessageBox(0, TranslateT("Unsupported GnuPG version found, use at you own risk!\nIt is recommended that you use GnuPG v1.x.x with this plugin."), L"Warning", MB_OK); */
}
}
wchar_t mir_path[MAX_PATH];
@@ -453,7 +427,7 @@ public:
void onClick_SET_HOME_DIR(CCtrlButton*)
{
GetFolderPath(TranslateT("Set home directory"));
- CMStringW tmp(ptrW(db_get_wsa(0, MODULENAME, "szHomePath", L"")));
+ CMStringW tmp(g_plugin.getMStringW("szHomePath", L""));
edit_HOME_DIR.SetText(tmp);
wchar_t mir_path[MAX_PATH];
PathToAbsoluteW(L"\\", mir_path);
@@ -479,10 +453,10 @@ public:
{
check_APPEND_TAGS.SetState(g_plugin.getByte("bAppendTags", 0));
check_STRIP_TAGS.SetState(g_plugin.getByte("bStripTags", 0));
- edit_IN_OPEN_TAG.SetText(ptrW(db_get_wsa(0, MODULENAME, "szInOpenTag", L"<GPGdec>")));
- edit_IN_CLOSE_TAG.SetText(ptrW(db_get_wsa(0, MODULENAME, "szInCloseTag", L"</GPGdec>")));
- edit_OUT_OPEN_TAG.SetText(ptrW(db_get_wsa(0, MODULENAME, "szOutOpenTag", L"<GPGenc>")));
- edit_OUT_CLOSE_TAG.SetText(ptrW(db_get_wsa(0, MODULENAME, "szOutCloseTag", L"</GPGenc>")));
+ edit_IN_OPEN_TAG.SetText(g_plugin.getMStringW("szInOpenTag", L"<GPGdec>"));
+ edit_IN_CLOSE_TAG.SetText(g_plugin.getMStringW("szInCloseTag", L"</GPGdec>"));
+ edit_OUT_OPEN_TAG.SetText(g_plugin.getMStringW("szOutOpenTag", L"<GPGenc>"));
+ edit_OUT_CLOSE_TAG.SetText(g_plugin.getMStringW("szOutCloseTag", L"</GPGenc>"));
return true;
}
@@ -491,22 +465,21 @@ public:
g_plugin.setByte("bAppendTags", globals.bAppendTags = check_APPEND_TAGS.GetState());
g_plugin.setByte("bStripTags", globals.bStripTags = check_STRIP_TAGS.GetState());
{
- wchar_t *tmp = mir_wstrdup(edit_IN_OPEN_TAG.GetText());
+ ptrW tmp(edit_IN_OPEN_TAG.GetText());
g_plugin.setWString("szInOpenTag", tmp);
- mir_free(globals.inopentag);
- globals.inopentag = tmp;
- tmp = mir_wstrdup(edit_IN_CLOSE_TAG.GetText());
+ globals.wszInopentag = tmp;
+
+ tmp = edit_IN_CLOSE_TAG.GetText();
g_plugin.setWString("szInCloseTag", tmp);
- mir_free(globals.inclosetag);
- globals.inclosetag = tmp;
+ globals.wszInclosetag = tmp;
+
tmp = mir_wstrdup(edit_OUT_OPEN_TAG.GetText());
g_plugin.setWString("szOutOpenTag", tmp);
- mir_free(globals.outopentag);
- globals.outopentag = tmp;
+ globals.wszOutopentag = tmp;
+
tmp = mir_wstrdup(edit_OUT_CLOSE_TAG.GetText());
g_plugin.setWString("szOutCloseTag", tmp);
- mir_free(globals.outclosetag);
- globals.outclosetag = tmp;
+ globals.wszOutclosetag = tmp;
}
return true;
}
@@ -609,9 +582,7 @@ public:
chk_ENABLE_ENCRYPTION.SetState(1);
}
if (hcnt) {
- wchar_t *tmp = db_get_wsa(hcnt, MODULENAME, "GPGPubKey", L"");
- wstring str = tmp;
- mir_free(tmp); tmp = nullptr;
+ wstring str = ptrW(g_plugin.getWStringA(hcnt, "GPGPubKey", L""));
if (!str.empty()) {
wstring::size_type p = 0, stop = 0;
for (;;) {
@@ -624,10 +595,9 @@ public:
}
}
}
- // char *tmp = db_get_wsa(hcnt, MODULENAME, "KeyID_Prescense", "");
+
if (!globals.hcontact_data[hcnt].key_in_prescense.empty()) {
- char *tmp2 = db_get_sa(hcnt, MODULENAME, "KeyID", "");
- if (!tmp2[0]) {
+ if (g_plugin.getMStringA(hcnt, "KeyID").IsEmpty()) {
string out;
DWORD code;
std::vector<wstring> cmd;
@@ -662,10 +632,8 @@ public:
btn_IMPORT.Enable();
}
}
- mir_free(tmp2);
}
- if (tmp)
- mir_free(tmp);
+
edit_PUBLIC_KEY_EDIT.SetText(!str.empty() ? str.c_str() : L"");
}
edit_p_PubKeyEdit = &edit_PUBLIC_KEY_EDIT;
@@ -723,10 +691,10 @@ public:
for (int i = 0; i < count; i++) {
MCONTACT hcnt = db_mc_getSub(hContact, i);
if (hcnt)
- db_set_ws(hcnt, MODULENAME, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
+ g_plugin.setWString(hcnt, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
}
}
- else db_set_ws(metaGetMostOnline(hContact), MODULENAME, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
+ else g_plugin.setWString(metaGetMostOnline(hContact), "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
}
else g_plugin.setWString(hContact, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
}
@@ -734,31 +702,24 @@ public:
mir_wstrcpy(tmp, key_buf.substr(ws1, ws2 - ws1).c_str());
{ //gpg execute block
std::vector<wstring> cmd;
- wchar_t tmp2[MAX_PATH] = { 0 };
- wchar_t *ptmp;
+ CMStringW tmp2;
string output;
DWORD exitcode;
{
MCONTACT hcnt = db_mc_tryMeta(hContact);
- ptmp = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- wcsncpy(tmp2, ptmp, MAX_PATH - 1);
- mir_free(ptmp);
- mir_wstrncat(tmp2, L"\\", _countof(tmp2) - mir_wstrlen(tmp2));
- mir_wstrncat(tmp2, L"temporary_exported.asc", _countof(tmp2) - mir_wstrlen(tmp2));
- boost::filesystem::remove(tmp2);
+ tmp2 = g_plugin.getMStringW("szHomePath");
+ tmp2 += L"\\temporary_exported.asc";
+ boost::filesystem::remove(tmp2.c_str());
+
wfstream f(tmp2, std::ios::out);
- ptmp = db_get_wsa(hcnt, MODULENAME, "GPGPubKey", L"");
- wstring str = ptmp;
- mir_free(ptmp);
- wstring::size_type s = 0;
- while ((s = str.find(L"\r", s)) != wstring::npos) {
- str.erase(s, 1);
- }
+ CMStringW str = g_plugin.getMStringW(hcnt, "GPGPubKey");
+ str.Replace(L"\r", L"");
f << str.c_str();
f.close();
+
cmd.push_back(L"--batch");
cmd.push_back(L"--import");
- cmd.push_back(tmp2);
+ cmd.push_back(tmp2.c_str());
}
gpg_execution_params params(cmd);
pxResult result;
@@ -778,17 +739,17 @@ public:
for (int i = 0; i < count; i++) {
MCONTACT hcnt = db_mc_getSub(hContact, i);
if (hcnt)
- db_unset(hcnt, MODULENAME, "bAlwatsTrust");
+ g_plugin.delSetting(hcnt, "bAlwatsTrust");
}
}
- else db_unset(metaGetMostOnline(hContact), MODULENAME, "bAlwatsTrust");
+ else g_plugin.delSetting(metaGetMostOnline(hContact), "bAlwatsTrust");
}
else g_plugin.delSetting(hContact, "bAlwatsTrust");
}
{
if (output.find("already in secret keyring") != string::npos) {
MessageBox(nullptr, TranslateT("Key already in secret keyring."), TranslateT("Info"), MB_OK);
- boost::filesystem::remove(tmp2);
+ boost::filesystem::remove(tmp2.c_str());
return;
}
string::size_type s = output.find("gpg: key ") + mir_strlen("gpg: key ");
@@ -804,14 +765,12 @@ public:
for (int i = 0; i < count; i++) {
MCONTACT hcnt = db_mc_getSub(hContact, i);
if (hcnt)
- db_set_s(hcnt, MODULENAME, "KeyID", tmp3);
+ g_plugin.setString(hcnt, "KeyID", tmp3);
}
}
- else
- db_set_s(metaGetMostOnline(hContact), MODULENAME, "KeyID", tmp3);
+ else g_plugin.setString(metaGetMostOnline(hContact), "KeyID", tmp3);
}
- else
- g_plugin.setString(hContact, "KeyID", tmp3);
+ else g_plugin.setString(hContact, "KeyID", tmp3);
}
mir_free(tmp3);
}
@@ -945,36 +904,31 @@ public:
}
}
if (!hContact) {
- wchar_t *fp = db_get_wsa(hContact, MODULENAME, "KeyID", L"");
- {
- string out;
- DWORD code;
- std::vector<wstring> cmds;
- cmds.push_back(L"--batch");
- cmds.push_back(L"-a");
- cmds.push_back(L"--export");
- cmds.push_back(fp);
- mir_free(fp);
- gpg_execution_params params2(cmds);
- pxResult result2;
- params2.out = &out;
- params2.code = &code;
- params2.result = &result2;
- if (!gpg_launcher(params2))
- return;
- if (result2 == pxNotFound)
- return;
- string::size_type s = 0;
- while ((s = out.find("\r", s)) != string::npos) {
- out.erase(s, 1);
- }
- g_plugin.setString(hContact, "GPGPubKey", out.c_str());
+ string out;
+ DWORD code;
+ std::vector<wstring> cmds;
+ cmds.push_back(L"--batch");
+ cmds.push_back(L"-a");
+ cmds.push_back(L"--export");
+ cmds.push_back(g_plugin.getMStringW(hContact, "KeyID").c_str());
+
+ gpg_execution_params params2(cmds);
+ pxResult result2;
+ params2.out = &out;
+ params2.code = &code;
+ params2.result = &result2;
+ if (!gpg_launcher(params2))
+ return;
+ if (result2 == pxNotFound)
+ return;
+ string::size_type s = 0;
+ while ((s = out.find("\r", s)) != string::npos) {
+ out.erase(s, 1);
}
+ g_plugin.setString(hContact, "GPGPubKey", out.c_str());
}
- tmp = mir_wstrdup(toUTF16(output).c_str());
- MessageBox(nullptr, tmp, L"", MB_OK);
- mir_free(tmp);
- boost::filesystem::remove(tmp2);
+ MessageBoxA(nullptr, output.c_str(), "", MB_OK);
+ boost::filesystem::remove(tmp2.c_str());
}
key_buf.clear();
if (chk_ENABLE_ENCRYPTION.GetState()) {
@@ -985,24 +939,15 @@ public:
for (int i = 0; i < count; i++) {
MCONTACT hcnt = db_mc_getSub(hContact, i);
if (hcnt) {
- if (!isContactSecured(hcnt))
- db_set_b(hcnt, MODULENAME, "GPGEncryption", 1);
- else
- db_set_b(hcnt, MODULENAME, "GPGEncryption", 0);
+ g_plugin.setByte(hcnt, "GPGEncryption", !isContactSecured(hcnt));
setSrmmIcon(hContact);
setClistIcon(hContact);
}
}
}
- else if (!isContactSecured(hContact))
- db_set_b(metaGetMostOnline(hContact), MODULENAME, "GPGEncryption", 1);
- else
- db_set_b(metaGetMostOnline(hContact), MODULENAME, "GPGEncryption", 0);
+ else g_plugin.setByte(metaGetMostOnline(hContact), "GPGEncryption", !isContactSecured(hContact));
}
- else if (!isContactSecured(hContact))
- g_plugin.setByte(hContact, "GPGEncryption", 1);
- else
- g_plugin.setByte(hContact, "GPGEncryption", 0);
+ else g_plugin.setByte(hContact, "GPGEncryption", !isContactSecured(hContact));
}
}
this->Close();
diff --git a/plugins/New_GPG/src/srmm.cpp b/plugins/New_GPG/src/srmm.cpp
index 1268a85a19..e44c69ec31 100755
--- a/plugins/New_GPG/src/srmm.cpp
+++ b/plugins/New_GPG/src/srmm.cpp
@@ -41,10 +41,11 @@ int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam)
if (mir_strcmp(sicd->szModule, MODULENAME))
return 0; // not our event
- BYTE enc = g_plugin.getByte(hContact, "GPGEncryption", 0);
+ int enc = g_plugin.getByte(hContact, "GPGEncryption", 0);
if (enc) {
g_plugin.setByte(hContact, "GPGEncryption", 0);
- hMeta ? db_set_b(hMeta, MODULENAME, "GPGEncryption", 0) : 0;
+ if (hMeta)
+ g_plugin.setByte(hMeta, "GPGEncryption", 0);
setSrmmIcon(hContact);
setClistIcon(hContact);
}
@@ -57,14 +58,16 @@ int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam)
}
else {
g_plugin.setByte(hContact, "GPGEncryption", 1);
- hMeta ? db_set_b(hMeta, MODULENAME, "GPGEncryption", 1) : 0;
+ if (hMeta)
+ g_plugin.setByte(hMeta, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
return 0;
}
if (isContactHaveKey(hContact)) {
g_plugin.setByte(hContact, "GPGEncryption", 1);
- hMeta ? db_set_b(hMeta, MODULENAME, "GPGEncryption", 1) : 0;
+ if (hMeta)
+ g_plugin.setByte(hMeta, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
}
diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp
index 37ee942976..1be6744636 100755
--- a/plugins/New_GPG/src/ui.cpp
+++ b/plugins/New_GPG/src/ui.cpp
@@ -99,25 +99,23 @@ bool CDlgChangePasswdMsgBox::OnApply()
MessageBox(m_hwnd, TranslateT("New passwords do not match"), TranslateT("Error"), MB_OK);
return false;
}
+
std::string old_pass, new_pass;
- // wchar_t buf[256] = { 0 };
- new_pass = toUTF8(edit_NEW_PASSWD1.GetText());
- old_pass = toUTF8(edit_OLD_PASSWD.GetText());
+ new_pass = toUTF8(ptrW(edit_NEW_PASSWD1.GetText()).get());
+ old_pass = toUTF8(ptrW(edit_OLD_PASSWD.GetText()).get());
+
bool old_pass_match = false;
- wchar_t *pass = db_get_wsa(0, MODULENAME, "szKeyPassword", L"");
- if (!mir_wstrcmp(pass, edit_OLD_PASSWD.GetText()))
+ if (!mir_strcmp(ptrA(g_plugin.getUStringA("szKeyPassword")), old_pass.c_str()))
old_pass_match = true;
- mir_free(pass);
if (!old_pass_match) {
if (globals.key_id_global[0]) {
string dbsetting = "szKey_";
dbsetting += toUTF8(globals.key_id_global);
dbsetting += "_Password";
- pass = db_get_wsa(0, MODULENAME, dbsetting.c_str(), L"");
- if (!mir_wstrcmp(pass, edit_OLD_PASSWD.GetText()))
+ ptrA pass(g_plugin.getUStringA(dbsetting.c_str()));
+ if (!mir_strcmp(pass, old_pass.c_str()))
old_pass_match = true;
- mir_free(pass);
}
}
@@ -213,12 +211,11 @@ bool CDlgFirstRun::OnInitDialog()
combo_ACCOUNT.AddString(wszAcc);
}
combo_ACCOUNT.SelectString(TranslateT("Default"));
- string keyinfo = Translate("key ID");
- keyinfo += ": ";
- char *keyid = db_get_sa(0, MODULENAME, "KeyID", "");
- keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
- mir_free(keyid);
- lbl_KEY_ID.SetTextA(keyinfo.c_str());
+
+ CMStringW keyinfo = TranslateT("key ID");
+ keyinfo += L": ";
+ keyinfo += g_plugin.getMStringW("KeyID", TranslateT("not set"));
+ lbl_KEY_ID.SetText(keyinfo);
combo_ACCOUNT.OnChange = Callback(this, &CDlgFirstRun::onChange_ACCOUNT);
list_KEY_LIST.OnClick = Callback(this, &CDlgFirstRun::onChange_KEY_LIST);
@@ -550,27 +547,19 @@ void CDlgFirstRun::onClick_OK(CCtrlButton*)
void CDlgFirstRun::onChange_ACCOUNT(CCtrlCombo*)
{
- char *buf = mir_strdup(combo_ACCOUNT.GetTextA());
+ CMStringW keyinfo = TranslateT("key ID");
+ keyinfo += ": ";
+
+ ptrA buf(combo_ACCOUNT.GetTextA());
if (!mir_strcmp(buf, Translate("Default"))) {
- string keyinfo = Translate("key ID");
- keyinfo += ": ";
- char *keyid = db_get_sa(0, MODULENAME, "KeyID", "");
- keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
- mir_free(keyid);
- lbl_KEY_ID.SetTextA(keyinfo.c_str());
+ keyinfo += g_plugin.getMStringW("KeyID", TranslateT("not set"));
}
else {
- string keyinfo = Translate("key ID");
- keyinfo += ": ";
std::string acc_str = buf;
acc_str += "_KeyID";
- char *keyid = db_get_sa(0, MODULENAME, acc_str.c_str(), "");
- keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
- mir_free(keyid);
- lbl_KEY_ID.SetTextA(keyinfo.c_str());
+ keyinfo += g_plugin.getMStringW(acc_str.c_str(), TranslateT("not set"));
}
- if (buf)
- mir_free(buf);
+ lbl_KEY_ID.SetText(keyinfo);
}
void CDlgFirstRun::onChange_KEY_LIST(CCtrlListView::TEventInfo *ev) //TODO: check if this work
@@ -715,15 +704,15 @@ void CDlgFirstRun::refresh_key_list()
setting += pa->szModuleName;
setting += ")";
setting += "_KeyID";
- wchar_t *str = db_get_wsa(0, MODULENAME, setting.c_str(), L"");
- if (key_id == str) {
+ ptrW str(g_plugin.getWStringA(setting.c_str(), L""));
+ if (key_id == str.get()) {
if (!accs.empty())
accs += L",";
accs += pa->tszAccountName;
}
mir_free(str);
}
- list_KEY_LIST.SetItemText(row, 6, (wchar_t*)accs.c_str());
+ list_KEY_LIST.SetItemText(row, 6, accs.c_str());
}
i++;
list_KEY_LIST.SetColumnWidth(0, LVSCW_AUTOSIZE);
@@ -783,10 +772,10 @@ bool CDlgGpgBinOpts::OnInitDialog()
{
ptrW tmp;
if (!gpg_exists) {
- tmp = db_get_wsa(0, MODULENAME, "szGpgBinPath", (SHGetValueW(HKEY_CURRENT_USER, L"Software\\GNU\\GnuPG", L"gpgProgram", 0, (void*)path.c_str(), &len) == ERROR_SUCCESS) ? path.c_str() : L"");
+ tmp = g_plugin.getWStringA("szGpgBinPath", (SHGetValueW(HKEY_CURRENT_USER, L"Software\\GNU\\GnuPG", L"gpgProgram", 0, (void*)path.c_str(), &len) == ERROR_SUCCESS) ? path.c_str() : L"");
if (tmp[0])
if (!boost::filesystem::exists((wchar_t*)tmp))
- MessageBox(nullptr, TranslateT("Wrong GPG binary location found in system.\nPlease choose another location"), TranslateT("Warning"), MB_OK);
+ MessageBoxW(nullptr, TranslateT("Wrong GPG binary location found in system.\nPlease choose another location"), TranslateT("Warning"), MB_OK);
}
else tmp = mir_wstrdup(path.c_str());
@@ -822,19 +811,19 @@ bool CDlgGpgBinOpts::OnInitDialog()
}
}
{
- ptrW tmp(db_get_wsa(0, MODULENAME, "szHomePath", L""));
- if (!tmp[0]) {
+ CMStringW tmp(g_plugin.getMStringW("szHomePath"));
+ if (tmp.IsEmpty()) {
wchar_t mir_path[MAX_PATH];
PathToAbsoluteW(L"\\", mir_path);
mir_wstrcat(mir_path, L"\\gpg");
if (_waccess(mir_path, 0) != -1) {
- tmp = mir_wstrdup(mir_path);
- MessageBox(nullptr, TranslateT("\"GPG\" directory found in Miranda root.\nAssuming it's GPG home directory.\nGPG home directory set."), TranslateT("Info"), MB_OK);
+ tmp = mir_path;
+ MessageBoxW(nullptr, TranslateT("\"GPG\" directory found in Miranda root.\nAssuming it's GPG home directory.\nGPG home directory set."), TranslateT("Info"), MB_OK);
}
else {
wstring path_ = _wgetenv(L"APPDATA");
path_ += L"\\GnuPG";
- tmp = mir_wstrdup(path_.c_str());
+ tmp = path_.c_str();
}
}
edit_HOME_DIR.SetText(!gpg_exists ? tmp : L"gpg");
@@ -849,8 +838,9 @@ bool CDlgGpgBinOpts::OnInitDialog()
void CDlgGpgBinOpts::onClick_SET_BIN_PATH(CCtrlButton*)
{
GetFilePath(L"Choose gpg.exe", "szGpgBinPath", L"*.exe", L"EXE Executables");
- CMStringW tmp(ptrW(db_get_wsa(0, MODULENAME, "szGpgBinPath", L"gpg.exe")));
+ CMStringW tmp(g_plugin.getMStringW("szGpgBinPath", L"gpg.exe"));
edit_BIN_PATH.SetText(tmp);
+
wchar_t mir_path[MAX_PATH];
PathToAbsoluteW(L"\\", mir_path);
if (tmp.Find(mir_path, 0) == 0) {
@@ -862,8 +852,9 @@ void CDlgGpgBinOpts::onClick_SET_BIN_PATH(CCtrlButton*)
void CDlgGpgBinOpts::onClick_SET_HOME_DIR(CCtrlButton*)
{
GetFolderPath(L"Set home directory");
- CMStringW tmp(ptrW(db_get_wsa(0, MODULENAME, "szHomePath", L"")));
+ CMStringW tmp(g_plugin.getMStringW("szHomePath"));
edit_HOME_DIR.SetText(tmp);
+
wchar_t mir_path[MAX_PATH];
PathToAbsoluteW(L"\\", mir_path);
PathToAbsoluteW(L"\\", mir_path);
@@ -925,17 +916,14 @@ CDlgNewKey::CDlgNewKey(MCONTACT _hContact, wstring _new_key) :
bool CDlgNewKey::OnInitDialog()
{
- //new_key_hcnt_mutex.unlock();
SetWindowPos(m_hwnd, nullptr, globals.new_key_rect.left, globals.new_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
- wchar_t *tmp = db_get_wsa(hContact, MODULENAME, "GPGPubKey", L"");
- lbl_MESSAGE.SetText(tmp[0] ? TranslateT("There is existing key for contact, would you like to replace it with new key?") : TranslateT("New public key was received, do you want to import it?"));
+ CMStringW tmp = g_plugin.getMStringW(hContact, "GPGPubKey");
+ lbl_MESSAGE.SetText(!tmp.IsEmpty() ? TranslateT("There is existing key for contact, would you like to replace it with new key?") : TranslateT("New public key was received, do you want to import it?"));
btn_IMPORT_AND_USE.Enable(g_plugin.getByte(hContact, "GPGEncryption", 0));
- btn_IMPORT.SetText(tmp[0] ? TranslateT("Replace") : TranslateT("Accept"));
- mir_free(tmp);
- tmp = new wchar_t[256];
- mir_snwprintf(tmp, 255 * sizeof(wchar_t), TranslateT("Received key from %s"), Clist_GetContactDisplayName(hContact));
+ btn_IMPORT.SetText(!tmp.IsEmpty() ? TranslateT("Replace") : TranslateT("Accept"));
+
+ tmp.Format(TranslateT("Received key from %s"), Clist_GetContactDisplayName(hContact));
lbl_KEY_FROM.SetText(tmp);
- mir_free(tmp);
return true;
}
@@ -1034,9 +1022,8 @@ bool CDlgKeyGen::OnApply()
}
// generating key file
- wstring path = ptrW(db_get_wsa(0, MODULENAME, "szHomePath", L""));
-
- path.append(L"\\new_key");
+ CMStringW path = g_plugin.getMStringW("szHomePath");
+ path += L"\\new_key";
wfstream f(path.c_str(), std::ios::out);
if (!f.is_open()) {
MessageBox(nullptr, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK);
@@ -1091,7 +1078,7 @@ bool CDlgKeyGen::OnApply()
cmd.push_back(L"--batch");
cmd.push_back(L"--yes");
cmd.push_back(L"--gen-key");
- cmd.push_back(path);
+ cmd.push_back(path.c_str());
gpg_execution_params params(cmd);
pxResult result;
params.out = &out;
@@ -1111,7 +1098,7 @@ bool CDlgKeyGen::OnApply()
if (result == pxNotFound)
return false;
- boost::filesystem::remove(path);
+ boost::filesystem::remove(path.c_str());
return true;
}
@@ -1355,14 +1342,12 @@ CDlgKeyPasswordMsgBox::CDlgKeyPasswordMsgBox(MCONTACT _hContact) :
bool CDlgKeyPasswordMsgBox::OnInitDialog()
{
- inkeyid = db_get_sa(hContact, MODULENAME, "InKeyID", "");
-
SetWindowPos(m_hwnd, nullptr, globals.key_password_rect.left, globals.key_password_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
- string questionstr = "Please enter password for key with ID: ";
- questionstr += inkeyid;
- mir_free(inkeyid);
- lbl_KEYID.SetTextA(questionstr.c_str());
+ CMStringW questionstr = TranslateT("Please enter password for key with ID: ");
+ questionstr += g_plugin.getMStringW(hContact, "InKeyID");
+ lbl_KEYID.SetText(questionstr.c_str());
+
chk_DEFAULT_PASSWORD.Disable();
return true;
}
@@ -1377,23 +1362,19 @@ void CDlgKeyPasswordMsgBox::OnDestroy()
void CDlgKeyPasswordMsgBox::onClick_OK(CCtrlButton*)
{
- wchar_t *tmp = mir_wstrdup(edit_KEY_PASSWORD.GetText());
+ ptrW tmp(edit_KEY_PASSWORD.GetText());
if (tmp && tmp[0]) {
if (chk_SAVE_PASSWORD.GetState()) {
- inkeyid = db_get_sa(hContact, MODULENAME, "InKeyID", "");
+ inkeyid = g_plugin.getStringA(hContact, "InKeyID", "");
if (inkeyid && inkeyid[0] && !chk_DEFAULT_PASSWORD.GetState()) {
string dbsetting = "szKey_";
dbsetting += inkeyid;
dbsetting += "_Password";
g_plugin.setWString(dbsetting.c_str(), tmp);
}
- else
- g_plugin.setWString("szKeyPassword", tmp);
+ else g_plugin.setWString("szKeyPassword", tmp);
}
- if (globals.password)
- mir_free(globals.password);
- globals.password = (wchar_t*)mir_alloc(sizeof(wchar_t)*(mir_wstrlen(tmp) + 1));
- mir_wstrcpy(globals.password, tmp);
+ globals.wszPassword = tmp;
}
mir_free(inkeyid);
DestroyWindow(m_hwnd);
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp
index b9e0c1bff7..fcb74bc96d 100755
--- a/plugins/New_GPG/src/utilities.cpp
+++ b/plugins/New_GPG/src/utilities.cpp
@@ -23,7 +23,7 @@ void ShowLoadPublicKeyDialog(bool = false);
void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t *szExtDesc)
{
- wchar_t str[MAX_PATH + 2] = { 0 }, *tmp;
+ wchar_t str[MAX_PATH + 2] = {};
OPENFILENAME ofn = { 0 };
wchar_t filter[512], *pfilter;
ofn.lStructSize = CDSIZEOF_STRUCT(OPENFILENAME, lpTemplateName);
@@ -35,9 +35,7 @@ void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t
pfilter[mir_wstrlen(pfilter) + 1] = '\0';
pfilter[mir_wstrlen(pfilter) + 2] = '\0';
ofn.lpstrFilter = filter;
- tmp = db_get_wsa(0, MODULENAME, szSetting, L"");
- wcsncpy(str, tmp, _countof(str) - 1);
- mir_free(tmp);
+ wcsncpy(str, g_plugin.getMStringW(szSetting), _countof(str) - 1);
if (mir_wstrlen(str) < 2)
str[0] = '\0';
ofn.lpstrFile = str;
@@ -112,7 +110,7 @@ INT_PTR LoadKey(WPARAM w, LPARAM)
INT_PTR SendKey(WPARAM w, LPARAM)
{
MCONTACT hContact = db_mc_tryMeta(w);
- char *szMessage;
+ CMStringA szMessage;
std::string key_id_str;
{
LPSTR proto = Proto_GetBaseAccountName(hContact);
@@ -127,31 +125,24 @@ INT_PTR SendKey(WPARAM w, LPARAM)
key_id_str += "_KeyID";
acc_str += "_GPGPubKey";
}
- szMessage = db_get_sa(0, MODULENAME, acc_str.empty() ? "GPGPubKey" : acc_str.c_str(), "");
- if (!szMessage[0]) {
- mir_free(szMessage);
- szMessage = db_get_sa(0, MODULENAME, "GPGPubKey", ""); //try to get default key as fallback in any way
- }
+ szMessage = g_plugin.getMStringA(acc_str.empty() ? "GPGPubKey" : acc_str.c_str());
+ if (szMessage.IsEmpty())
+ szMessage = g_plugin.getMStringA("GPGPubKey"); //try to get default key as fallback in any way
}
- if (szMessage[0]) {
+ if (!szMessage.IsEmpty()) {
BYTE enc = g_plugin.getByte(hContact, "GPGEncryption", 0);
g_plugin.setByte(hContact, "GPGEncryption", 0);
- ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)szMessage);
+ ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)szMessage.c_str());
std::string msg = "Public key ";
- char *keyid = db_get_sa(0, MODULENAME, key_id_str.c_str(), "");
- if (!keyid[0]) {
- mir_free(keyid);
- keyid = db_get_sa(0, MODULENAME, "KeyID", "");
- }
+ CMStringA keyid = g_plugin.getMStringA(key_id_str.c_str());
+ if (keyid.IsEmpty())
+ keyid = g_plugin.getMStringA("KeyID");
msg += keyid;
- mir_free(keyid);
msg += " sent";
- mir_free(szMessage);
- szMessage = mir_strdup(msg.c_str());
- HistoryLog(hContact, db_event(szMessage, 0, 0, DBEF_SENT));
+
+ HistoryLog(hContact, db_event((char*)msg.c_str(), 0, 0, DBEF_SENT));
g_plugin.setByte(hContact, "GPGEncryption", enc);
}
- else mir_free(szMessage);
return 0;
}
@@ -161,13 +152,13 @@ INT_PTR ToggleEncryption(WPARAM w, LPARAM)
MCONTACT hContact = (MCONTACT)w;
BYTE enc;
if (db_mc_isMeta(hContact)) {
- enc = db_get_b(metaGetMostOnline(hContact), MODULENAME, "GPGEncryption", 0);
+ enc = g_plugin.getByte(metaGetMostOnline(hContact), "GPGEncryption");
if (MessageBox(nullptr, TranslateT("Do you want to toggle encryption for all subcontacts?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) {
int count = db_mc_getSubCount(hContact);
for (int i = 0; i < count; i++) {
MCONTACT hcnt = db_mc_getSub(hContact, i);
if (hcnt)
- db_set_b(hcnt, MODULENAME, "GPGEncryption", enc ? 0 : 1);
+ g_plugin.getByte(hcnt, "GPGEncryption", enc ? 0 : 1);
}
g_plugin.setByte(hContact, "GPGEncryption", enc ? 0 : 1);
}
@@ -200,20 +191,19 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM)
setting += ")";
setting += "_KeyID";
}
- char *keyid = db_get_sa(0, MODULENAME, setting.c_str(), "");
- if (!keyid[0]) {
- mir_free(keyid);
- keyid = db_get_sa(0, MODULENAME, "KeyID", "");
- }
+
+ CMStringA keyid = g_plugin.getMStringA(setting.c_str());
+ if (keyid.IsEmpty())
+ keyid = g_plugin.getMStringA("KeyID");
+
wchar_t buf[128] = { 0 };
- mir_snwprintf(buf, L"%s: %s", TranslateT("Send public key"), toUTF16(keyid).c_str());
- mir_free(keyid);
+ mir_snwprintf(buf, L"%s: %S", TranslateT("Send public key"), keyid.c_str());
Menu_ModifyItem(globals.hSendKey, buf);
}
int flags;
- wchar_t *tmp = db_get_wsa(hContact, MODULENAME, "GPGPubKey", L"");
- if (!tmp[0]) {
+ CMStringA tmp = g_plugin.getMStringW(hContact, "GPGPubKey");
+ if (tmp.IsEmpty()) {
g_plugin.delSetting(hContact, "GPGEncryption");
flags = CMIF_GRAYED;
}
@@ -222,7 +212,6 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM)
Menu_ModifyItem(globals.hToggleEncryption,
g_plugin.getByte(hContact, "GPGEncryption", 0) ? L"Turn off GPG encryption" : L"Turn on GPG encryption",
INVALID_HANDLE_VALUE, flags);
- mir_free(tmp);
return 0;
}
@@ -283,36 +272,35 @@ int onProtoAck(WPARAM, LPARAM l)
}
cmd.push_back(file);
boost::filesystem::remove(file);
- { // password
- wchar_t *pass = nullptr;
- char *keyid = db_get_sa(ack->hContact, MODULENAME, "KeyID", "");
- if (mir_strlen(keyid) > 0) {
+ {
+ // password
+ CMStringW pass;
+ CMStringA keyid = g_plugin.getMStringA(ack->hContact, "KeyID");
+ if (!keyid.IsEmpty()) {
string dbsetting = "szKey_";
dbsetting += keyid;
dbsetting += "_Password";
- pass = db_get_wsa(0, MODULENAME, dbsetting.c_str(), L"");
- if (mir_wstrlen(pass) > 0 && globals.bDebugLog)
- globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + keyid + ", trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->hContact)) + " with password");
+ pass = g_plugin.getMStringW(dbsetting.c_str());
+ if (!pass.IsEmpty() && globals.bDebugLog)
+ globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + keyid.c_str() + ", trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->hContact)) + " with password");
}
else {
- pass = db_get_wsa(0, MODULENAME, "szKeyPassword", L"");
- if (mir_wstrlen(pass) > 0 && globals.bDebugLog)
+ pass = g_plugin.getMStringW("szKeyPassword");
+ if (!pass.IsEmpty() && globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->hContact)) + " with password");
}
- if (mir_wstrlen(pass) > 0) {
+ if (!pass.IsEmpty()) {
cmd.push_back(L"--passphrase");
- cmd.push_back(pass);
+ cmd.push_back(pass.c_str());
}
- else if (globals.password) {
+ else if (!globals.wszPassword.IsEmpty()) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->hContact)) + " with password");
cmd.push_back(L"--passphrase");
- cmd.push_back(globals.password);
+ cmd.push_back(globals.wszPassword.c_str());
}
else if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->hContact)) + " with out password");
- mir_free(pass);
- mir_free(keyid);
}
cmd.push_back(L"-d");
cmd.push_back(filename);
@@ -333,19 +321,19 @@ int onProtoAck(WPARAM, LPARAM l)
s += mir_strlen(" ID ");
string::size_type s2 = out.find(",", s);
if (db_mc_isMeta(ack->hContact))
- db_set_s(metaGetMostOnline(ack->hContact), MODULENAME, "InKeyID", out.substr(s, s2 - s).c_str());
+ g_plugin.setString(metaGetMostOnline(ack->hContact), "InKeyID", out.substr(s, s2 - s).c_str());
else
- db_set_s(ack->hContact, MODULENAME, "InKeyID", out.substr(s, s2 - s).c_str());
+ g_plugin.setString(ack->hContact, "InKeyID", out.substr(s, s2 - s).c_str());
}
CDlgKeyPasswordMsgBox *d = new CDlgKeyPasswordMsgBox(ack->hContact);
d->DoModal();
std::vector<wstring> cmd2 = cmd;
- if (globals.password) {
+ if (!globals.wszPassword.IsEmpty()) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->hContact)));
std::vector<wstring> tmp;
tmp.push_back(L"--passphrase");
- tmp.push_back(globals.password);
+ tmp.push_back(globals.wszPassword.c_str());
cmd2.insert(cmd2.begin(), tmp.begin(), tmp.end());
}
out.clear();
@@ -395,8 +383,8 @@ std::wstring encrypt_file(MCONTACT hContact, wchar_t *filename)
cmd.push_back(L"--batch");
cmd.push_back(L"--tes");
cmd.push_back(L"-r");
- char *keyid = db_get_sa(hcnt, MODULENAME, "KeyID", "");
- wchar_t *szKeyid = mir_a2u(keyid);
+
+ CMStringW keyid = g_plugin.getMStringW(hcnt, "KeyID");
wchar_t *name = wcsrchr(filename, '\\');
if (!name)
name = filename;
@@ -404,13 +392,13 @@ std::wstring encrypt_file(MCONTACT hContact, wchar_t *filename)
name++;
wchar_t *file_out = new wchar_t[mir_wstrlen(name) + mir_wstrlen(L".gpg") + 1];
mir_snwprintf(file_out, mir_wstrlen(name) + mir_wstrlen(L".gpg") + 1, L"%s.gpg", name);
- cmd.push_back(szKeyid);
- if (db_get_b(hcnt, MODULENAME, "bAlwaysTrust", 0)) {
+ cmd.push_back(keyid.c_str());
+
+ if (g_plugin.getByte(hcnt, "bAlwaysTrust")) {
cmd.push_back(L"--trust-model");
cmd.push_back(L"always");
}
- mir_free(szKeyid);
- mir_free(keyid);
+
cmd.push_back(L"-o");
wchar_t *temp = _tgetenv(L"TEMP");
cmd.push_back(wstring(temp) + L"\\" + file_out);
@@ -430,7 +418,7 @@ std::wstring encrypt_file(MCONTACT hContact, wchar_t *filename)
if (out.find("There is no assurance this key belongs to the named user") != string::npos) {
out.clear();
if (MessageBox(nullptr, TranslateT("We're trying to encrypt with untrusted key. Do you want to trust this key permanently?"), TranslateT("Warning"), MB_YESNO) == IDYES) {
- db_set_b(hcnt, MODULENAME, "bAlwaysTrust", 1);
+ g_plugin.setByte(hcnt, "bAlwaysTrust", 1);
std::vector<std::wstring> tmp;
tmp.push_back(L"--trust-model");
tmp.push_back(L"always");
@@ -631,10 +619,8 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
}
if (globals.bPresenceSigning && nodename && strstr(nodename, "status")) {
- char *path_c = db_get_utfa(0, MODULENAME, "szHomePath", "");
- string path_out = path_c;
+ string path_out = ptrA(g_plugin.getUStringA("szHomePath", ""));
string file = get_random(10);
- mir_free(path_c);
path_out += "\\tmp\\";
path_out += file;
boost::filesystem::remove(path_out);
@@ -651,50 +637,44 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
DWORD code;
std::vector<wstring> cmd;
{
- char* inkeyid = nullptr;
-
char setting[64];
mir_snprintf(setting, sizeof(setting) - 1, "%s_KeyID", ji->GetModuleName());
- inkeyid = db_get_sa(0, MODULENAME, setting, "");
- if (!inkeyid[0]) {
- mir_free(inkeyid);
- inkeyid = db_get_sa(0, MODULENAME, "KeyID", "");
- }
+ CMStringA inkeyid = g_plugin.getMStringA(setting);
+ if (inkeyid.IsEmpty())
+ inkeyid = g_plugin.getMStringA("KeyID");
- ptrW pass;
- if (inkeyid[0]) {
+ CMStringW pass;
+ if (!inkeyid.IsEmpty()) {
string dbsetting = "szKey_";
dbsetting += inkeyid;
dbsetting += "_Password";
- pass = db_get_wsa(0, MODULENAME, dbsetting.c_str(), L"");
- if (pass[0] && globals.bDebugLog)
- globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid + ", trying to encrypt message from self with password");
+ pass = g_plugin.getMStringW(dbsetting.c_str());
+ if (!pass.IsEmpty() && globals.bDebugLog)
+ globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid.c_str() + ", trying to encrypt message from self with password");
}
- if (inkeyid && inkeyid[0])
- mir_free(inkeyid);
else {
- pass = db_get_wsa(0, MODULENAME, "szKeyPassword", L"");
- if (pass[0] && globals.bDebugLog)
+ pass = g_plugin.getMStringW("szKeyPassword");
+ if (!pass.IsEmpty() && globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to encrypt message from self with password");
}
if (pass[0]) {
cmd.push_back(L"--passphrase");
- cmd.push_back(pass.get());
+ cmd.push_back(pass.c_str());
}
- else if (globals.password && globals.password[0]) {
+ else if (!globals.wszPassword.IsEmpty()) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to encrypt message from self with password");
cmd.push_back(L"--passphrase");
- cmd.push_back(globals.password);
+ cmd.push_back(globals.wszPassword.c_str());
}
else if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to encrypt message from self with out password");
}
cmd.push_back(L"--local-user");
- cmd.push_back(ptrW(db_get_wsa(0, MODULENAME, "KeyID", L"")).get());
+ cmd.push_back(g_plugin.getMStringW("KeyID").c_str());
cmd.push_back(L"--default-key");
- cmd.push_back(ptrW(db_get_wsa(0, MODULENAME, "KeyID", L"")).get());
+ cmd.push_back(g_plugin.getMStringW("KeyID").c_str());
cmd.push_back(L"--batch");
cmd.push_back(L"--yes");
cmd.push_back(L"-abs");
@@ -794,18 +774,17 @@ static JABBER_HANDLER_FUNC PresenceHandler(IJabberInterface*, TiXmlElement* node
wstring file = toUTF16(get_random(10)), status_file = toUTF16(get_random(10));
sign += data;
sign += "\n-----END PGP SIGNATURE-----\n";
- wchar_t *path_c = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- wstring path_out = path_c, status_file_out = path_c;
- mir_free(path_c);
+
+ CMStringW path_out = g_plugin.getMStringW("szHomePath"), status_file_out = path_out;
path_out += L"\\tmp\\";
- path_out += file;
+ path_out += file.c_str();
path_out += L".sig";
status_file_out += L"\\tmp\\";
- status_file_out += status_file;
+ status_file_out += status_file.c_str();
status_file_out += L".status";
- boost::filesystem::remove(path_out);
- boost::filesystem::remove(status_file_out);
+ boost::filesystem::remove(path_out.c_str());
+ boost::filesystem::remove(status_file_out.c_str());
wfstream f(path_out.c_str(), std::ios::out);
while (!f.is_open())
f.open(path_out.c_str(), std::ios::out);
@@ -816,7 +795,7 @@ static JABBER_HANDLER_FUNC PresenceHandler(IJabberInterface*, TiXmlElement* node
f.open(status_file_out.c_str(), std::ios::out);
f << status_str.c_str();
f.close();
- if (!boost::filesystem::exists(path_out)) {
+ if (!boost::filesystem::exists(path_out.c_str())) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": info: Failed to write sign in file");
return FALSE;
@@ -827,8 +806,8 @@ static JABBER_HANDLER_FUNC PresenceHandler(IJabberInterface*, TiXmlElement* node
std::vector<wstring> cmd;
cmd.push_back(L"--verify");
cmd.push_back(L"-a");
- cmd.push_back(path_out);
- cmd.push_back(status_file_out);
+ cmd.push_back(path_out.c_str());
+ cmd.push_back(status_file_out.c_str());
gpg_execution_params params(cmd);
pxResult result;
params.out = &out;
@@ -840,8 +819,8 @@ static JABBER_HANDLER_FUNC PresenceHandler(IJabberInterface*, TiXmlElement* node
if (result == pxNotFound) {
return FALSE;
}
- boost::filesystem::remove(path_out);
- boost::filesystem::remove(status_file_out);
+ boost::filesystem::remove(path_out.c_str());
+ boost::filesystem::remove(status_file_out.c_str());
if (out.find("key ID ") != string::npos) {
//need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ?
string::size_type p1 = out.find("key ID ") + mir_strlen("key ID ");
@@ -898,14 +877,12 @@ bool isContactSecured(MCONTACT hContact)
return false;
}
if (!db_mc_isMeta(hContact)) {
- wchar_t *key = db_get_wsa(hContact, MODULENAME, "GPGPubKey", L"");
- if (!key[0]) {
- mir_free(key);
+ CMStringW key = g_plugin.getMStringW(hContact, "GPGPubKey");
+ if (key.IsEmpty()) {
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": encryption is turned off for " + toUTF8(Clist_GetContactDisplayName(hContact)));
return false;
}
- mir_free(key);
}
if (globals.bDebugLog)
globals.debuglog << std::string(time_str() + ": encryption is turned on for " + toUTF8(Clist_GetContactDisplayName(hContact)));
@@ -914,66 +891,46 @@ bool isContactSecured(MCONTACT hContact)
bool isContactHaveKey(MCONTACT hContact)
{
- wchar_t *key = db_get_wsa(hContact, MODULENAME, "GPGPubKey", L"");
- if (mir_wstrlen(key) > 0) {
- mir_free(key);
- return true;
- }
- mir_free(key);
- return false;
+ ptrW key(g_plugin.getWStringA(hContact, "GPGPubKey"));
+ return (mir_wstrlen(key) > 0);
}
bool isGPGKeyExist()
{
- wchar_t *id = db_get_wsa(0, MODULENAME, "KeyID", L"");
- char *key = db_get_sa(0, MODULENAME, "GPGPubKey", "");
- if (id[0] && key[0]) {
- mir_free(id);
- mir_free(key);
- return true;
- }
- mir_free(id);
- mir_free(key);
- return false;
+ CMStringW id(g_plugin.getMStringW("KeyID", L""));
+ CMStringA key(g_plugin.getMStringA("GPGPubKey", ""));
+ return (!id.IsEmpty() && !key.IsEmpty());
}
+
bool isGPGValid()
{
- wchar_t *tmp = nullptr;
+ ptrW tmp;
bool gpg_exists = false, is_valid = true;
- tmp = db_get_wsa(0, MODULENAME, "szGpgBinPath", L"");
- boost::filesystem::path p(tmp);
+ boost::filesystem::path p(g_plugin.getMStringW("szGpgBinPath").c_str());
if (boost::filesystem::exists(p) && boost::filesystem::is_regular_file(p))
gpg_exists = true;
else {
- mir_free(tmp);
- tmp = nullptr;
- wchar_t *path = (wchar_t*)mir_alloc(sizeof(wchar_t)*MAX_PATH);
- wchar_t *mir_path = (wchar_t*)mir_alloc(MAX_PATH * sizeof(wchar_t));
+ wchar_t path[MAX_PATH], mir_path[MAX_PATH];
PathToAbsoluteW(L"\\", mir_path);
SetCurrentDirectoryW(mir_path);
- tmp = mir_wstrdup(mir_path);
- mir_free(mir_path);
+
//mir_realloc(path, (mir_wstrlen(path)+64)*sizeof(wchar_t));
- wchar_t *gpg_path = (wchar_t*)mir_alloc(sizeof(wchar_t)*MAX_PATH);
- mir_wstrcpy(gpg_path, tmp);
+ wchar_t gpg_path[MAX_PATH];
+ mir_wstrcpy(gpg_path, mir_path);
mir_wstrcat(gpg_path, L"\\GnuPG\\gpg.exe");
- mir_free(tmp);
- tmp = nullptr;
+
p = boost::filesystem::path(gpg_path);
if (boost::filesystem::exists(p) && boost::filesystem::is_regular_file(p)) {
gpg_exists = true;
mir_wstrcpy(path, L"GnuPG\\gpg.exe");
}
- mir_free(gpg_path);
tmp = mir_wstrdup(path);
- mir_free(path);
}
if (gpg_exists) {
g_plugin.setWString("szGpgBinPath", tmp);
- mir_free(tmp);
- tmp = nullptr;
+
string out;
DWORD code;
std::vector<wstring> cmd;
@@ -991,18 +948,7 @@ bool isGPGValid()
if (p1 == string::npos)
is_valid = false;
}
- if (tmp) {
- mir_free(tmp);
- tmp = nullptr;
- }
- /* if(!gpg_exists)
- {
- wstring path_ = _wgetenv(L"APPDATA");
- path_ += L"\\GnuPG";
- tmp = db_get_wsa(0, MODULENAME, "szHomePath", (wchar_t*)path_.c_str());
- }
- if(tmp)
- mir_free(tmp); */
+
return is_valid && gpg_exists;
}
@@ -1134,7 +1080,6 @@ void send_encrypted_msgs_thread(void *param)
{
MCONTACT hContact = (MCONTACT)(DWORD_PTR)param;
while (true) {
- //char *key = db_get_wsa(hContact, MODULENAME, "GPGPubKey", "");
while (!isContactSecured(hContact))
Sleep(1000);
@@ -1199,16 +1144,7 @@ void ExportGpGKeysFunc(int type)
return; //TODO: handle error
if (!type || type == 2) {
for (auto &hContact : Contacts()) {
- char *k = db_get_sa(hContact, MODULENAME, "GPGPubKey", "");
- std::string key;
- if (!k[0]) {
- mir_free(k);
- continue;
- }
- else {
- key = k;
- mir_free(k);
- }
+ CMStringA key = g_plugin.getMStringA(hContact, "GPGPubKey");
const char *proto = Proto_GetBaseAccountName(hContact);
std::string id = "Comment: login ";
@@ -1315,18 +1251,19 @@ void ExportGpGKeysFunc(int type)
db_free(&dbv);
break;
}
- std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----");
- if (p1 == std::string::npos)
+ int p1 = key.Find("-----BEGIN PGP PUBLIC KEY BLOCK-----");
+ if (p1 == -1)
continue;
p1 += mir_strlen("-----BEGIN PGP PUBLIC KEY BLOCK-----");
p1++;
id += '\n';
- key.insert(p1, id);
+ key.Insert(p1, id.c_str());
file << key;
file << std::endl;
exported_keys++;
}
}
+
if (type == 1 || type == 2) {
string out;
DWORD code;
@@ -1546,25 +1483,21 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
break;
}
if (found) {
- wstring path;
+ CMStringW path = g_plugin.getMStringW("szHomePath");
std::vector<std::wstring> cmd;
- wchar_t *ptmp;
string output;
DWORD exitcode;
{
- ptmp = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- path = ptmp;
- mir_free(ptmp);
wstring rand = toUTF16(get_random(10));
path += L"\\";
- path += rand;
- boost::filesystem::remove(path);
+ path += rand.c_str();
+ boost::filesystem::remove(path.c_str());
wfstream f(path, std::ios::out);
f << toUTF16(key).c_str();
f.close();
cmd.push_back(L"--batch");
cmd.push_back(L"--import");
- cmd.push_back(path);
+ cmd.push_back(path.c_str());
}
gpg_execution_params params(cmd);
pxResult result;
@@ -1580,7 +1513,7 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
{
if (output.find("already in secret keyring") != string::npos) {
MessageBox(nullptr, TranslateT("Key already in secret keyring."), TranslateT("Info"), MB_OK);
- boost::filesystem::remove(path);
+ boost::filesystem::remove(path.c_str());
break;
}
char *tmp2;
@@ -1643,7 +1576,7 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
g_plugin.setByte(hContact, "GPGEncryption", 1);
g_plugin.setWString(hContact, "GPGPubKey", toUTF16(key).c_str());
}
- boost::filesystem::remove(path);
+ boost::filesystem::remove(path.c_str());
break;
}
}
@@ -1652,25 +1585,21 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
}
else if (strstr(line, "-----END PGP PRIVATE KEY BLOCK-----")) {
std::vector<wstring> cmd;
- wchar_t tmp2[MAX_PATH] = { 0 };
- wchar_t *ptmp;
string output;
DWORD exitcode;
- {
- ptmp = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- wcsncpy(tmp2, ptmp, MAX_PATH - 1);
- mir_free(ptmp);
- mir_wstrncat(tmp2, L"\\", _countof(tmp2) - mir_wstrlen(tmp2));
- mir_wstrncat(tmp2, L"temporary_exported.asc", _countof(tmp2) - mir_wstrlen(tmp2));
- boost::filesystem::remove(tmp2);
- wfstream f(tmp2, std::ios::out);
- f << toUTF16(key).c_str();
- f.close();
- cmd.push_back(L"--batch");
- cmd.push_back(L"--import");
- cmd.push_back(tmp2);
- }
+
+ CMStringW tmp2 = g_plugin.getMStringW("szHomePath");
+ tmp2 += L"\\temporary_exported.asc";
+ boost::filesystem::remove(tmp2.c_str());
+
+ wfstream f(tmp2, std::ios::out);
+ f << toUTF16(key).c_str();
+ f.close();
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--import");
+ cmd.push_back(tmp2.c_str());
gpg_execution_params params(cmd);
+
pxResult result;
params.out = &output;
params.code = &exitcode;
@@ -1729,33 +1658,25 @@ void strip_tags(std::wstring &str)
{
if (str.empty())
return;
- boost::algorithm::erase_all(str, globals.inopentag);
- boost::algorithm::erase_all(str, globals.inclosetag);
- boost::algorithm::erase_all(str, globals.outopentag);
- boost::algorithm::erase_all(str, globals.outclosetag);
+ boost::algorithm::erase_all(str, globals.wszInopentag.c_str());
+ boost::algorithm::erase_all(str, globals.wszInclosetag.c_str());
+ boost::algorithm::erase_all(str, globals.wszOutopentag.c_str());
+ boost::algorithm::erase_all(str, globals.wszOutclosetag.c_str());
}
-
-
void ShowEncryptedFileMsgBox()
{
CDlgEncryptedFileMsgBox *d = new CDlgEncryptedFileMsgBox;
d->DoModal();
}
-
-
-
void ShowExportKeysDlg()
{
CDlgExportKeysMsgBox *d = new CDlgExportKeysMsgBox;
d->Show();
}
-
-
-
void ShowChangePasswdDlg()
{
CDlgChangePasswdMsgBox *d = new CDlgChangePasswdMsgBox;
@@ -1765,17 +1686,15 @@ void ShowChangePasswdDlg()
void clean_temp_dir()
{
using namespace boost::filesystem;
- char *mir_path = new char[MAX_PATH];
- PathToAbsolute("\\", mir_path);
- wstring path = toUTF16(mir_path);
- SetCurrentDirectoryA(mir_path);
- delete[] mir_path;
- wchar_t *tmp = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- path += tmp;
- mir_free(tmp);
- path += L"\\tmp";
- if (exists(path) && is_directory(path)) {
- boost::filesystem::path p(path);
+ wchar_t mir_path[MAX_PATH];
+ PathToAbsoluteW(L"\\", mir_path);
+ SetCurrentDirectoryW(mir_path);
+
+ CMStringW tmp = mir_path;
+ tmp += g_plugin.getMStringW("szHomePath");
+ tmp += L"\\tmp";
+ if (exists(tmp.c_str()) && is_directory(tmp.c_str())) {
+ boost::filesystem::path p(tmp);
for (directory_iterator i = directory_iterator(p), end = directory_iterator(); i != end; ++i) {
if (boost::filesystem::is_regular_file(i->path())) {
if ((i->path().filename().generic_string().length() == 10 && (i->path().filename().generic_string().find(".") == std::string::npos)) ||
@@ -1841,13 +1760,12 @@ bool gpg_validate_paths(wchar_t *gpg_bin_path, wchar_t *gpg_home_path)
return false;
}
{
- wchar_t *path = db_get_wsa(0, MODULENAME, "szHomePath", L"");
+ CMStringW path = g_plugin.getMStringW("szHomePath");
DWORD dwFileAttr = GetFileAttributes(path);
if (dwFileAttr != INVALID_FILE_ATTRIBUTES) {
dwFileAttr &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(path, dwFileAttr);
}
- mir_free(path);
}
return true;
}
@@ -1863,18 +1781,15 @@ bool gpg_use_new_random_key(char *account_name, wchar_t *gpg_bin_path, wchar_t *
if (gpg_bin_path && gpg_home_dir)
gpg_save_paths(gpg_bin_path, gpg_home_dir);
- wstring path;
+ CMStringW path;
{
// generating key file
- wchar_t *tmp = nullptr;
if (gpg_home_dir)
- tmp = gpg_home_dir;
+ path = gpg_home_dir;
else
- tmp = db_get_wsa(0, MODULENAME, "szHomePath", L"");
- path = tmp;
- if (!gpg_home_dir)
- mir_free(tmp);
- path.append(L"\\new_key");
+ path = g_plugin.getMStringW("szHomePath");
+
+ path += L"\\new_key";
wfstream f(path.c_str(), std::ios::out);
if (!f.is_open()) {
MessageBox(nullptr, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK);
@@ -1905,7 +1820,7 @@ bool gpg_use_new_random_key(char *account_name, wchar_t *gpg_bin_path, wchar_t *
cmd.push_back(L"--batch");
cmd.push_back(L"--yes");
cmd.push_back(L"--gen-key");
- cmd.push_back(path);
+ cmd.push_back(path.c_str());
gpg_execution_params params(cmd);
pxResult result;
params.out = &out;
@@ -1916,22 +1831,22 @@ bool gpg_use_new_random_key(char *account_name, wchar_t *gpg_bin_path, wchar_t *
if (result == pxNotFound)
return false;
- boost::filesystem::remove(path);
+ boost::filesystem::remove(path.c_str());
string::size_type p1 = 0;
if ((p1 = out.find("key ")) != string::npos)
- path = toUTF16(out.substr(p1 + 4, 8));
+ path = toUTF16(out.substr(p1 + 4, 8)).c_str();
else
- path.clear();
+ path.Empty();
}
- if (!path.empty()) {
+ if (!path.IsEmpty()) {
string out;
DWORD code;
std::vector<wstring> cmd;
cmd.push_back(L"--batch");
cmd.push_back(L"-a");
cmd.push_back(L"--export");
- cmd.push_back(path);
+ cmd.push_back(path.c_str());
gpg_execution_params params(cmd);
pxResult result;
params.out = &out;
diff --git a/plugins/New_GPG/src/version.h b/plugins/New_GPG/src/version.h
index 548a219f78..23bef7f8e7 100755
--- a/plugins/New_GPG/src/version.h
+++ b/plugins/New_GPG/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>