summaryrefslogtreecommitdiff
path: root/plugins/New_GPG/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-03 16:30:25 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-03 16:30:25 +0300
commit9613f96e6a6f96ad02a0fc926054132811ae2bb1 (patch)
treef8fe94a3efe7598a2af926f264d354f7a08fb943 /plugins/New_GPG/src
parent2f880bda3aa2d8817ce43481df9d99b12ed82a58 (diff)
Accounts() : iterator for accounts
Diffstat (limited to 'plugins/New_GPG/src')
-rwxr-xr-xplugins/New_GPG/src/main.cpp36
-rwxr-xr-xplugins/New_GPG/src/ui.cpp56
-rwxr-xr-xplugins/New_GPG/src/utilities.cpp80
3 files changed, 76 insertions, 96 deletions
diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp
index 4f44a8f172..7b93bb6ea7 100755
--- a/plugins/New_GPG/src/main.cpp
+++ b/plugins/New_GPG/src/main.cpp
@@ -97,19 +97,17 @@ void InitCheck()
mir_free(home_dir);
tmp_dir += L"\\tmp";
_wmkdir(tmp_dir.c_str());
- int count = 0;
- PROTOACCOUNT **accounts;
- Proto_EnumAccounts(&count, &accounts);
+
string question;
char *keyid = nullptr;
- for (int i = 0; i < count; i++) {
- if (StriStr(accounts[i]->szModuleName, "metacontacts"))
+ for (auto &pa : Accounts()) {
+ if (StriStr(pa->szModuleName, "metacontacts"))
continue;
- if (StriStr(accounts[i]->szModuleName, "weather"))
+ if (StriStr(pa->szModuleName, "weather"))
continue;
- std::string acc = toUTF8(accounts[i]->tszAccountName);
+ std::string acc = toUTF8(pa->tszAccountName);
acc += "(";
- acc += accounts[i]->szModuleName;
+ acc += pa->szModuleName;
acc += ")";
acc += "_KeyID";
keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, acc.c_str(), "");
@@ -120,7 +118,7 @@ void InitCheck()
if ((p = out.find(keyid)) == string::npos) {
question += keyid;
question += Translate(" for account ");
- question += toUTF8(accounts[i]->tszAccountName);
+ 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)
{
@@ -161,7 +159,7 @@ void InitCheck()
if (expired) {
question += keyid;
question += Translate(" for account ");
- question += toUTF8(accounts[i]->tszAccountName);
+ 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)
{
@@ -252,32 +250,26 @@ void InitCheck()
mir_free(path);
}
if (globals.bAutoExchange) {
- int count = 0;
- PROTOACCOUNT **accounts;
- Proto_EnumAccounts(&count, &accounts);
ICQ_CUSTOMCAP cap;
cap.cbSize = sizeof(ICQ_CUSTOMCAP);
cap.hIcon = nullptr;
strncpy(cap.name, "GPG Key AutoExchange", MAX_CAPNAME);
strncpy(cap.caps, "GPGAutoExchange", sizeof(cap.caps));
- for (int i = 0; i < count; i++)
- if (ProtoServiceExists(accounts[i]->szProtoName, PS_ICQ_ADDCAPABILITY))
- CallProtoService(accounts[i]->szProtoName, PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap);
+ for (auto &pa : Accounts())
+ if (ProtoServiceExists(pa->szProtoName, PS_ICQ_ADDCAPABILITY))
+ CallProtoService(pa->szProtoName, PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap);
}
if (globals.bFileTransfers) {
- int count = 0;
- PROTOACCOUNT **accounts;
- Proto_EnumAccounts(&count, &accounts);
ICQ_CUSTOMCAP cap;
cap.cbSize = sizeof(ICQ_CUSTOMCAP);
cap.hIcon = nullptr;
strncpy(cap.name, "GPG Encrypted FileTransfers", MAX_CAPNAME);
strncpy(cap.caps, "GPGFileTransfer", sizeof(cap.caps));
- for (int i = 0; i < count; i++)
- if (ProtoServiceExists(accounts[i]->szProtoName, PS_ICQ_ADDCAPABILITY))
- CallProtoService(accounts[i]->szProtoName, PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap);
+ for (auto &pa : Accounts())
+ if (ProtoServiceExists(pa->szProtoName, PS_ICQ_ADDCAPABILITY))
+ CallProtoService(pa->szProtoName, PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap);
}
}
diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp
index 1a5ec6a5d0..d9677fd529 100755
--- a/plugins/New_GPG/src/ui.cpp
+++ b/plugins/New_GPG/src/ui.cpp
@@ -200,31 +200,28 @@ void CDlgFirstRun::OnInitDialog()
refresh_key_list();
- {
- combo_ACCOUNT.AddString(TranslateT("Default"));
- int count = 0;
- PROTOACCOUNT **accounts;
- Proto_EnumAccounts(&count, &accounts);
- for (int n = 0; n < count; n++) {
- if (StriStr(accounts[n]->szModuleName, "metacontacts"))
- continue;
- if (StriStr(accounts[n]->szModuleName, "weather"))
- continue;
- std::string acc = toUTF8(accounts[n]->tszAccountName);
- acc += "(";
- acc += accounts[n]->szModuleName;
- acc += ")";
- //acc += "_KeyID";
- combo_ACCOUNT.AddStringA(acc.c_str());
- }
- combo_ACCOUNT.SelectString(TranslateT("Default"));
- string keyinfo = Translate("key ID");
- keyinfo += ": ";
- char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", "");
- keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
- mir_free(keyid);
- lbl_KEY_ID.SetTextA(keyinfo.c_str());
+ combo_ACCOUNT.AddString(TranslateT("Default"));
+
+ for (auto &pa : Accounts()) {
+ if (StriStr(pa->szModuleName, "metacontacts"))
+ continue;
+ if (StriStr(pa->szModuleName, "weather"))
+ continue;
+ std::string acc = toUTF8(pa->tszAccountName);
+ acc += "(";
+ acc += pa->szModuleName;
+ acc += ")";
+ //acc += "_KeyID";
+ combo_ACCOUNT.AddStringA(acc.c_str());
}
+ combo_ACCOUNT.SelectString(TranslateT("Default"));
+ string keyinfo = Translate("key ID");
+ keyinfo += ": ";
+ char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", "");
+ keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
+ mir_free(keyid);
+ lbl_KEY_ID.SetTextA(keyinfo.c_str());
+
combo_ACCOUNT.OnChange = Callback(this, &CDlgFirstRun::onChange_ACCOUNT);
list_KEY_LIST.OnClick = Callback(this, &CDlgFirstRun::onChange_KEY_LIST);
}
@@ -706,21 +703,18 @@ void CDlgFirstRun::refresh_key_list()
list_KEY_LIST.SetItemText(row, 1, (wchar_t*)tmp.c_str());
// get accounts
- int count = 0;
- PROTOACCOUNT **accounts;
- Proto_EnumAccounts(&count, &accounts);
std::wstring accs;
- for (int n = 0; n < count; n++) {
- std::string setting = toUTF8(accounts[n]->tszAccountName);
+ for (auto &pa : Accounts()) {
+ std::string setting = toUTF8(pa->tszAccountName);
setting += "(";
- setting += accounts[n]->szModuleName;
+ setting += pa->szModuleName;
setting += ")";
setting += "_KeyID";
wchar_t *str = UniGetContactSettingUtf(NULL, szGPGModuleName, setting.c_str(), L"");
if (key_id == str) {
if (!accs.empty())
accs += L",";
- accs += accounts[n]->tszAccountName;
+ accs += pa->tszAccountName;
}
mir_free(str);
}
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp
index a38429091d..3781161311 100755
--- a/plugins/New_GPG/src/utilities.cpp
+++ b/plugins/New_GPG/src/utilities.cpp
@@ -595,26 +595,23 @@ int ComboBoxAddStringUtf(HWND hCombo, const wchar_t *szString, DWORD data)
int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, options later
{
void AddHandlers();
- int count = 0;
- PROTOACCOUNT **accounts;
- Proto_EnumAccounts(&count, &accounts);
+
list <JabberAccount*>::iterator p;
globals.Accounts.clear();
globals.Accounts.push_back(new JabberAccount);
p = globals.Accounts.begin();
(*p)->setAccountNumber(0);
- for (int i = 0; i < count; i++) //get only jabber accounts from all accounts
- {
- IJabberInterface *JIftmp = getJabberApi(accounts[i]->szModuleName);
+ for (auto &pa : Accounts()) {
+ IJabberInterface *JIftmp = getJabberApi(pa->szModuleName);
int a = 0;
if (JIftmp) {
(*p)->setJabberInterface(JIftmp);
- if (accounts[i]->tszAccountName) {
- wchar_t* tmp = mir_wstrdup(accounts[i]->tszAccountName);
+ if (pa->tszAccountName) {
+ wchar_t* tmp = mir_wstrdup(pa->tszAccountName);
(*p)->setAccountName(tmp);
}
else {
- wchar_t *tmp = mir_a2u(accounts[i]->szModuleName);
+ wchar_t *tmp = mir_a2u(pa->szModuleName);
(*p)->setAccountName(tmp);
}
(*p)->setAccountNumber(a);
@@ -1434,9 +1431,7 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
if (!file.is_open())
return 1; //TODO: handle error
- PROTOACCOUNT **accs;
- int acc_count = 0, processed_keys = 0, processed_private_keys = 0;
- Proto_EnumAccounts(&acc_count, &accs);
+ int processed_keys = 0, processed_private_keys = 0;
char line[256];
file.getline(line, 255);
@@ -1464,52 +1459,48 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
p2++;
key.erase(p1, p2 - p1);
std::string acc;
- for (int i = 0; i < acc_count; i++) {
+
+ for (auto &pa : Accounts()) {
if (acc.length())
break;
- const char *uid = Proto_GetUniqueId(accs[i]->szModuleName);
+ const char *uid = Proto_GetUniqueId(pa->szModuleName);
DBVARIANT dbv = { 0 };
- db_get(0, accs[i]->szModuleName, uid, &dbv);
+ db_get(0, pa->szModuleName, uid, &dbv);
std::string id;
switch (dbv.type) {
case DBVT_DELETED:
continue;
break;
+
case DBVT_BYTE:
- {
- char _id[64];
- mir_snprintf(_id, "%d", dbv.bVal);
- id += _id;
- if (id == login)
- acc = accs[i]->szModuleName;
- }
+ char _id[64];
+ mir_snprintf(_id, "%d", dbv.bVal);
+ id += _id;
+ if (id == login)
+ acc = pa->szModuleName;
break;
+
case DBVT_WORD:
- {
- char _id[64];
- mir_snprintf(_id, "%d", dbv.wVal);
- id += _id;
- if (id == login)
- acc = accs[i]->szModuleName;
- }
+ mir_snprintf(_id, "%d", dbv.wVal);
+ id += _id;
+ if (id == login)
+ acc = pa->szModuleName;
break;
+
case DBVT_DWORD:
- {
- char _id[64];
- mir_snprintf(_id, "%d", dbv.dVal);
- id += _id;
- if (id == login)
- acc = accs[i]->szModuleName;
- }
+ mir_snprintf(_id, "%d", dbv.dVal);
+ id += _id;
+ if (id == login)
+ acc = pa->szModuleName;
break;
+
case DBVT_ASCIIZ:
- {
- id += dbv.pszVal;
- db_free(&dbv);
- if (id == login)
- acc = accs[i]->szModuleName;
- }
+ id += dbv.pszVal;
+ db_free(&dbv);
+ if (id == login)
+ acc = pa->szModuleName;
break;
+
case DBVT_UTF8:
{
char *tmp = mir_utf8decodeA(dbv.pszVal);
@@ -1518,19 +1509,22 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM)
mir_free(tmp);
db_free(&dbv);
if (id == login)
- acc = accs[i]->szModuleName;
+ acc = pa->szModuleName;
}
break;
+
case DBVT_BLOB:
//TODO
db_free(&dbv);
break;
+
case DBVT_WCHAR:
//TODO
db_free(&dbv);
break;
}
}
+
if (acc.length()) {
const char *uid = Proto_GetUniqueId(acc.c_str());
for (auto &hContact : Contacts(acc.c_str())) {