diff options
-rw-r--r-- | plugins/SecureIM/src/crypt.h | 4 | ||||
-rw-r--r-- | plugins/SecureIM/src/crypt_lists.cpp | 43 | ||||
-rw-r--r-- | plugins/SecureIM/src/language.cpp | 26 | ||||
-rw-r--r-- | plugins/SecureIM/src/language.h | 20 | ||||
-rw-r--r-- | plugins/SecureIM/src/options.cpp | 1887 | ||||
-rw-r--r-- | plugins/SecureIM/src/options.h | 28 | ||||
-rw-r--r-- | plugins/SecureIM/src/svcs_rsa.cpp | 14 | ||||
-rw-r--r-- | plugins/SecureIM/src/version.h | 14 |
8 files changed, 921 insertions, 1115 deletions
diff --git a/plugins/SecureIM/src/crypt.h b/plugins/SecureIM/src/crypt.h index 79e2b677e6..a40d3c501c 100644 --- a/plugins/SecureIM/src/crypt.h +++ b/plugins/SecureIM/src/crypt.h @@ -98,9 +98,7 @@ pUinKey getUinKey(MCONTACT hContact); pUinKey getUinCtx(HANDLE);
void addMsg2Queue(pUinKey,WPARAM,LPSTR);
-void getContactName(MCONTACT hContact, LPSTR szName);
-void getContactNameA(MCONTACT hContact, LPSTR szName);
-void getContactUin(MCONTACT hContact, LPSTR szUIN);
+void getContactUin(MCONTACT hContact, LPWSTR szUIN);
void getContactUinA(MCONTACT hContact, LPSTR szUIN);
// crypt_check.cpp
diff --git a/plugins/SecureIM/src/crypt_lists.cpp b/plugins/SecureIM/src/crypt_lists.cpp index d94b25875b..621101ee50 100644 --- a/plugins/SecureIM/src/crypt_lists.cpp +++ b/plugins/SecureIM/src/crypt_lists.cpp @@ -184,18 +184,14 @@ void addMsg2Queue(pUinKey ptr, WPARAM wParam, LPSTR szMsg) ptrMessage->Message = mir_strdup(szMsg);
}
-void getContactNameA(MCONTACT hContact, LPSTR szName)
-{
- ptrA dn(mir_u2a(Clist_GetContactDisplayName(hContact)));
- mir_strcpy(szName, dn);
-}
-
-void getContactName(MCONTACT hContact, LPSTR szName)
+void getContactUinA(MCONTACT hContact, LPSTR szUIN)
{
- mir_wstrcpy((LPWSTR)szName, Clist_GetContactDisplayName(hContact));
+ wchar_t buf[NAMSIZE];
+ getContactUin(hContact, buf);
+ strncpy_s(szUIN, NAMSIZE, _T2A(buf), _TRUNCATE);
}
-void getContactUinA(MCONTACT hContact, LPSTR szUIN)
+void getContactUin(MCONTACT hContact, LPWSTR szUIN)
{
*szUIN = 0;
@@ -203,29 +199,10 @@ void getContactUinA(MCONTACT hContact, LPSTR szUIN) if (!ptr)
return;
- DBVARIANT dbv_uniqueid;
- LPCSTR uID = Proto_GetUniqueId(ptr->name);
- if (uID && db_get(hContact, ptr->name, uID, &dbv_uniqueid) == 0) {
- if (dbv_uniqueid.type == DBVT_WORD)
- sprintf(szUIN, "%u [%s]", dbv_uniqueid.wVal, ptr->name); //!!!!!!!!!!!
- else if (dbv_uniqueid.type == DBVT_DWORD)
- sprintf(szUIN, "%u [%s]", (UINT)dbv_uniqueid.dVal, ptr->name); //!!!!!!!!!!!
- else if (dbv_uniqueid.type == DBVT_BLOB)
- sprintf(szUIN, "%s [%s]", dbv_uniqueid.pbVal, ptr->name); //!!!!!!!!!!!
- else
- sprintf(szUIN, "%s [%s]", dbv_uniqueid.pszVal, ptr->name); //!!!!!!!!!!!
- }
- else mir_strcpy(szUIN, " == = unknown == =");
-
- db_free(&dbv_uniqueid);
-}
+ auto *pa = Proto_GetAccount(ptr->name);
+ if (pa == nullptr)
+ return;
-void getContactUin(MCONTACT hContact, LPSTR szUIN)
-{
- getContactUinA(hContact, szUIN);
- if (*szUIN) {
- LPWSTR tmp = mir_a2u(szUIN);
- mir_wstrcpy((LPWSTR)szUIN, tmp);
- mir_free(tmp);
- }
+ ptrW uid(Contact_GetInfo(CNF_UNIQUEID, hContact, pa->szModuleName));
+ mir_snwprintf(szUIN, NAMSIZE, L"%s [%s]", uid.get(), pa->tszAccountName);
}
diff --git a/plugins/SecureIM/src/language.cpp b/plugins/SecureIM/src/language.cpp index a6cf8f8961..fd89163b81 100644 --- a/plugins/SecureIM/src/language.cpp +++ b/plugins/SecureIM/src/language.cpp @@ -1,25 +1,7 @@ #include "commonheaders.h"
-//Popup Messages
-LPCSTR sim001 = LPGEN("SecureIM established...");
-LPCSTR sim002 = LPGEN("Key exchange failed...");
-LPCSTR sim003 = LPGEN("Key from disabled...");
-LPCSTR sim004 = LPGEN("Sent back message received...");
-LPCSTR sim005 = LPGEN("Sending back secure message...");
-LPCSTR sim006 = LPGEN("SecureIM disabled...");
-LPCSTR sim007 = LPGEN("Sending key...");
-LPCSTR sim008 = LPGEN("Key received...");
-LPCSTR sim009 = LPGEN("Sending message...");
-LPCSTR sim010 = LPGEN("Message received...");
-LPCSTR sim011 = LPGEN("Encrypting file:");
-LPCSTR sim012 = LPGEN("Decrypting file:");
-LPCSTR sim013 = LPGEN("Bad key received...");
-
//Error Messages
-LPCSTR sim101 = LPGEN("SecureIM: Error while decrypting the message.");
-LPCSTR sim102 = LPGEN("SecureIM: Error while decrypting the message, bad message length.");
-LPCSTR sim103 = LPGEN("SecureIM: Error while decrypting the message, bad message CRC.");
-LPCSTR sim104 = LPGEN("User has not answered to key exchange!\nYour messages are still in SecureIM queue, do you want to send them unencrypted now?");
+LPCSTR sim104 = LPGEN();
LPCSTR sim105 = LPGEN("SecureIM not enabled! You must enable SecureIM with this user...");
LPCSTR sim106 = LPGEN("Can't send encrypted message!\nUser is offline now and his secure key has been expired. Do you want to send your message?\nIt will be unencrypted!");
LPCSTR sim107 = LPGEN("SecureIM won't be loaded because cryptopp.dll is missing or wrong version!");
@@ -33,17 +15,14 @@ LPCSTR sim114 = LPGEN("Can't export RSA public key!"); LPCSTR sim115 = LPGEN("Can't import RSA public key!");
//Options
-LPCSTR sim201 = LPGEN("General");
-LPCSTR sim202 = LPGEN("Accounts");
+
LPCSTR sim203 = LPGEN("Nickname");
LPCSTR sim204 = LPGEN("User ID");
LPCSTR sim205 = LPGEN("Status");
LPCSTR sim206 = "PSK";
-LPCSTR sim210 = LPGEN("Name");
LPCSTR sim211 = LPGEN("Password is too short!");
LPCSTR sim212 = LPGEN("ON");
LPCSTR sim213 = LPGEN("Off");
-LPCSTR sim214 = "PGP";
LPCSTR sim215 = LPGEN("Key ID");
LPCSTR sim216 = LPGEN("Keyrings loaded.");
LPCSTR sim217 = LPGEN("Keyrings not loaded!");
@@ -55,7 +34,6 @@ LPCSTR sim222 = LPGEN("Private key loaded."); LPCSTR sim223 = LPGEN("Private key not loaded!");
LPCSTR sim224 = LPGEN("The new settings will become valid when you restart Miranda NG!");
LPCSTR sim225 = LPGEN("Keyrings disabled!");
-LPCSTR sim226 = "GPG";
LPCSTR sim227 = "CP";
LPCSTR sim228 = "ANSI";
LPCSTR sim229 = "UTF-8";
diff --git a/plugins/SecureIM/src/language.h b/plugins/SecureIM/src/language.h index 4c627efc2f..7e52510865 100644 --- a/plugins/SecureIM/src/language.h +++ b/plugins/SecureIM/src/language.h @@ -1,21 +1,6 @@ #ifndef __LANGUAGE_H__
#define __LANGUAGE_H__
-//Popup Messages
-extern LPCSTR sim001;
-extern LPCSTR sim002;
-extern LPCSTR sim003;
-extern LPCSTR sim004;
-extern LPCSTR sim005;
-extern LPCSTR sim006;
-extern LPCSTR sim007;
-extern LPCSTR sim008;
-extern LPCSTR sim009;
-extern LPCSTR sim010;
-extern LPCSTR sim011;
-extern LPCSTR sim012;
-extern LPCSTR sim013;
-
//Error Messages
extern LPCSTR sim101;
extern LPCSTR sim102;
@@ -34,17 +19,13 @@ extern LPCSTR sim114; extern LPCSTR sim115;
//Options
-extern LPCSTR sim201;
-extern LPCSTR sim202;
extern LPCSTR sim203;
extern LPCSTR sim204;
extern LPCSTR sim205;
extern LPCSTR sim206;
-extern LPCSTR sim210;
extern LPCSTR sim211;
extern LPCSTR sim212;
extern LPCSTR sim213;
-extern LPCSTR sim214;
extern LPCSTR sim215;
extern LPCSTR sim216;
extern LPCSTR sim217;
@@ -56,7 +37,6 @@ extern LPCSTR sim222; extern LPCSTR sim223;
extern LPCSTR sim224;
extern LPCSTR sim225;
-extern LPCSTR sim226;
extern LPCSTR sim227;
extern LPCSTR sim228;
extern LPCSTR sim229;
diff --git a/plugins/SecureIM/src/options.cpp b/plugins/SecureIM/src/options.cpp index c441eea3be..b5d9b4bd12 100644 --- a/plugins/SecureIM/src/options.cpp +++ b/plugins/SecureIM/src/options.cpp @@ -3,9 +3,9 @@ #define PSKSIZE (4096+1)
#define RSASIZE (4096+1)
-BOOL bChangeSortOrder = false;
+static BOOL bChangeSortOrder = false;
-BOOL hasKey(pUinKey ptr)
+static BOOL hasKey(pUinKey ptr)
{
BOOL ret = 0;
if (ptr->mode == MODE_NATIVE) {
@@ -23,7 +23,7 @@ BOOL hasKey(pUinKey ptr) return ret;
}
-void TC_InsertItem(HWND hwnd, WPARAM wparam, TCITEM *tci)
+static void TC_InsertItem(HWND hwnd, WPARAM wparam, TCITEM *tci)
{
LPWSTR tmp = mir_a2u(tci->pszText);
tci->pszText = (LPSTR)TranslateW(tmp);
@@ -39,35 +39,27 @@ static void LV_InsertColumn(HWND hwnd, WPARAM wparam, LVCOLUMN *lvc) mir_free(tmp);
}
-int LV_InsertItem(HWND hwnd, LVITEM *lvi)
+static int LV_InsertItem(HWND hwnd, LVITEMW *lvi)
{
return SNDMSG(hwnd, LVM_INSERTITEMW, 0, (LPARAM)lvi);
}
-int LV_InsertItemA(HWND hwnd, LVITEM *lvi)
+static void LV_SetItemText(HWND hwnd, WPARAM wparam, int subitem, LPWSTR text)
{
- lvi->pszText = (LPSTR)mir_a2u(lvi->pszText);
- int ret = LV_InsertItem(hwnd, lvi);
- mir_free(lvi->pszText);
- return ret;
-}
-
-void LV_SetItemText(HWND hwnd, WPARAM wparam, int subitem, LPSTR text)
-{
- LV_ITEM lvi; memset(&lvi, 0, sizeof(lvi));
+ LV_ITEMW lvi = {};
lvi.iSubItem = subitem;
lvi.pszText = text;
SNDMSG(hwnd, LVM_SETITEMTEXTW, wparam, (LPARAM)&lvi);
}
-void LV_SetItemTextA(HWND hwnd, WPARAM wparam, int subitem, LPSTR text)
+static void LV_SetItemTextA(HWND hwnd, WPARAM wparam, int subitem, LPCSTR text)
{
- text = (LPSTR)mir_a2u(text);
- LV_SetItemText(hwnd, wparam, subitem, text);
- mir_free(text);
+ wchar_t *p = mir_a2u(text);
+ LV_SetItemText(hwnd, wparam, subitem, p);
+ mir_free(p);
}
-void LV_GetItemTextA(HWND hwnd, WPARAM wparam, int iSubItem, LPSTR text, int cchTextMax)
+static void LV_GetItemTextA(HWND hwnd, WPARAM wparam, int iSubItem, LPSTR text, int cchTextMax)
{
LV_ITEM lvi; memset(&lvi, 0, sizeof(lvi));
lvi.iSubItem = iSubItem;
@@ -79,119 +71,561 @@ void LV_GetItemTextA(HWND hwnd, WPARAM wparam, int iSubItem, LPSTR text, int cch mir_free(lvi.pszText);
}
-/*
- * tabbed options dialog
- */
+static LPARAM getListViewParam(HWND hLV, UINT iItem)
+{
+ LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
+ lvi.iItem = iItem;
+ lvi.mask = LVIF_PARAM;
+ ListView_GetItem(hLV, &lvi);
+ return lvi.lParam;
+}
-INT_PTR CALLBACK OptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+static void setListViewIcon(HWND hLV, UINT iItem, pUinKey ptr)
{
- static int iInit = TRUE;
- TCITEM tci;
+ LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
+ lvi.iItem = iItem;
+ switch (ptr->tmode) {
+ case MODE_NATIVE:
+ case MODE_RSAAES:
+ lvi.iImage = ICO_ST_DIS + ptr->tstatus;
+ break;
+ case MODE_PGP:
+ lvi.iImage = ICO_OV_PGP;
+ break;
+ case MODE_GPG:
+ lvi.iImage = ICO_OV_GPG;
+ break;
+ }
+ lvi.mask = LVIF_IMAGE;
+ ListView_SetItem(hLV, &lvi);
+}
- switch (msg) {
- case WM_INITDIALOG:
- iInit = TRUE;
- tci.mask = TCIF_PARAM | TCIF_TEXT;
-
- tci.lParam = (LPARAM)CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TAB_GENERAL), hwnd, DlgProcOptionsGeneral);
- tci.pszText = (LPSTR)sim201;
- TC_InsertItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 0, &tci);
- EnableThemeDialogTexture((HWND)tci.lParam, ETDT_ENABLETAB);
-
- tci.lParam = (LPARAM)CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TAB_PROTO), hwnd, DlgProcOptionsProto);
- tci.pszText = (LPSTR)sim202;
- TC_InsertItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 2, &tci);
- EnableThemeDialogTexture((HWND)tci.lParam, ETDT_ENABLETAB);
- ShowWindow((HWND)tci.lParam, SW_HIDE);
-
- if (bPGP && bPGPloaded) {
- tci.lParam = (LPARAM)CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TAB_PGP), hwnd, DlgProcOptionsPGP);
- tci.pszText = (LPSTR)sim214;
- TC_InsertItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 3, &tci);
- EnableThemeDialogTexture((HWND)tci.lParam, ETDT_ENABLETAB);
- ShowWindow((HWND)tci.lParam, SW_HIDE);
- }
+static void setListViewMode(HWND hLV, UINT iItem, UINT iMode)
+{
+ char tmp[256];
+ strncpy(tmp, Translate(sim231[iMode]), sizeof(tmp) - 1);
+ LV_SetItemTextA(hLV, iItem, 2, tmp);
+}
+
+static void setListViewStatus(HWND hLV, UINT iItem, UINT iStatus)
+{
+ char tmp[128];
+ strncpy(tmp, Translate(sim232[iStatus]), sizeof(tmp) - 1);
+ LV_SetItemTextA(hLV, iItem, 3, tmp);
+}
+
+static UINT getListViewPSK(HWND hLV, UINT iItem)
+{
+ char str[128];
+ LV_GetItemTextA(hLV, iItem, 4, str, _countof(str));
+ return strncmp(str, Translate(sim206), sizeof(str)) == 0;
+}
+
+static void setListViewPSK(HWND hLV, UINT iItem, UINT iStatus)
+{
+ char str[128];
+ strncpy(str, (iStatus) ? Translate(sim206) : "-", sizeof(str) - 1);
+ LV_SetItemTextA(hLV, iItem, 4, str);
+}
+
+static UINT getListViewPUB(HWND hLV, UINT iItem)
+{
+ char str[128];
+ LV_GetItemTextA(hLV, iItem, 4, str, _countof(str));
+ return strncmp(str, Translate(sim233), sizeof(str)) == 0;
+}
- if (bGPG && bGPGloaded) {
- tci.lParam = (LPARAM)CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TAB_GPG), hwnd, DlgProcOptionsGPG);
- tci.pszText = (LPSTR)sim226;
- TC_InsertItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 4, &tci);
- EnableThemeDialogTexture((HWND)tci.lParam, ETDT_ENABLETAB);
- ShowWindow((HWND)tci.lParam, SW_HIDE);
+static void setListViewPUB(HWND hLV, UINT iItem, UINT iStatus)
+{
+ char str[128];
+ strncpy(str, (iStatus) ? Translate(sim233) : "-", sizeof(str) - 1);
+ LV_SetItemTextA(hLV, iItem, 4, str);
+
+ LPSTR sha = nullptr;
+ if (iStatus) {
+ DBVARIANT dbv;
+ dbv.type = DBVT_BLOB;
+ pUinKey ptr = (pUinKey)getListViewParam(hLV, iItem);
+ if (db_get(ptr->hContact, MODULENAME, "rsa_pub", &dbv) == 0) {
+ int len;
+ mir_exp->rsa_get_hash((PBYTE)dbv.pbVal, dbv.cpbVal, (PBYTE)str, &len);
+ sha = mir_strdup(to_hex((PBYTE)str, len));
+ db_free(&dbv);
}
+ }
+ if (sha) {
+ LV_SetItemTextA(hLV, iItem, 5, sha);
+ mir_free(sha);
+ }
+ else LV_SetItemTextA(hLV, iItem, 5, "");
+}
- // add more tabs here if needed
- // activate the final tab
- iInit = FALSE;
- return TRUE;
+static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+{
+ pUinKey p1 = pUinKey(lParam1), p2 = pUinKey(lParam2);
+ wchar_t t1[NAMSIZE], t2[NAMSIZE];
+ int s = 0, d = 0, m = 1;
+ DBVARIANT dbv1 = { 0 }, dbv2 = { 0 };
- case PSM_CHANGED: // used so tabs dont have to call SendMessage(GetParent(GetParent(hwnd)), PSM_CHANGED, 0, 0);
- if (!iInit)
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
+ if (lParamSort & 0x100) {
+ lParamSort &= 0xFF;
+ m = -1;
+ }
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case ID_UPDATE_CLIST:
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 0, &tci);
- SendMessage((HWND)tci.lParam, WM_COMMAND, ID_UPDATE_CLIST, 0);
- break;
+ switch (lParamSort) {
+ case 0x01:
+ case 0x11:
+ case 0x21:
+ return mir_wstrcmp(Clist_GetContactDisplayName(p1->hContact), Clist_GetContactDisplayName(p2->hContact)) * m;
- case ID_UPDATE_PLIST:
- if (!bPGP) break;
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 2, &tci);
- SendMessage((HWND)tci.lParam, WM_COMMAND, ID_UPDATE_CLIST, 0);
- break;
+ case 0x02:
+ case 0x12:
+ case 0x22:
+ getContactUin(p1->hContact, t1);
+ getContactUin(p2->hContact, t2);
+ return mir_wstrcmp(t1, t2) * m;
- case ID_UPDATE_GLIST:
- if (!bGPG) break;
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), 3, &tci);
- SendMessage((HWND)tci.lParam, WM_COMMAND, ID_UPDATE_GLIST, 0);
- break;
+ case 0x03:
+ s = p1->tmode;
+ d = p2->tmode;
+ return (s - d) * m;
+
+ case 0x13:
+ if (!db_get_s(p1->hContact, MODULENAME, "pgp_abbr", &dbv1)) {
+ if (!db_get_s(p2->hContact, MODULENAME, "pgp_abbr", &dbv2)) {
+ s = (dbv1.type == DBVT_ASCIIZ);
+ d = (dbv2.type == DBVT_ASCIIZ);
+ if (s && d) {
+ s = mir_strcmp(dbv1.pszVal, dbv2.pszVal);
+ d = 0;
+ }
+ db_free(&dbv1);
+ }
+ db_free(&dbv2);
+ return (s - d) * m;
}
- break;
+ else
+ return 0;
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- tci.mask = TCIF_PARAM;
- int cnt = TabCtrl_GetItemCount(GetDlgItem(hwnd, IDC_OPTIONSTAB));
- for (int i = 0; i < cnt; i++) {
- TabCtrl_GetItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), i, &tci);
- SendMessage((HWND)tci.lParam, WM_NOTIFY, 0, lParam);
+ case 0x23:
+ if (!db_get_s(p1->hContact, MODULENAME, "gpg", &dbv1)) {
+ s = (dbv1.type == DBVT_ASCIIZ);
+ if (!db_get_s(p2->hContact, MODULENAME, "gpg", &dbv2)) {
+ d = (dbv2.type == DBVT_ASCIIZ);
+ if (s && d) {
+ s = mir_strcmp(dbv1.pszVal, dbv2.pszVal);
+ d = 0;
}
+ db_free(&dbv1);
}
- break;
+ db_free(&dbv2);
+ return (s - d) * m;
+ }
+ else
+ return 0;
- case IDC_OPTIONSTAB:
- switch (((LPNMHDR)lParam)->code) {
- case TCN_SELCHANGING:
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), TabCtrl_GetCurSel(GetDlgItem(hwnd, IDC_OPTIONSTAB)), &tci);
- ShowWindow((HWND)tci.lParam, SW_HIDE);
- break;
+ case 0x04:
+ s = p1->tstatus;
+ d = p2->tstatus;
+ return (s - d) * m;
- case TCN_SELCHANGE:
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwnd, IDC_OPTIONSTAB), TabCtrl_GetCurSel(GetDlgItem(hwnd, IDC_OPTIONSTAB)), &tci);
- ShowWindow((HWND)tci.lParam, SW_SHOW);
- break;
+ case 0x05:
+ if (!db_get_s(p1->hContact, MODULENAME, "PSK", &dbv1)) {
+ s = (dbv1.type == DBVT_ASCIIZ);
+ if (!db_get_s(p2->hContact, MODULENAME, "PSK", &dbv2)) {
+ d = (dbv2.type == DBVT_ASCIIZ);
+ db_free(&dbv2);
}
+ db_free(&dbv1);
+ return (s - d) * m;
}
- break;
+ else
+ return 0;
}
+ return 0;
+}
- return FALSE;
+void ListView_Sort(HWND hLV, LPARAM lParamSort)
+{
+ // restore sort column
+ char t[32];
+ mir_snprintf(t, "os%02x", (UINT)lParamSort & 0xF0);
+ if ((lParamSort & 0x0F) == 0)
+ lParamSort = (int)g_plugin.getByte(t, lParamSort + 1);
+
+ g_plugin.setByte(t, (BYTE)lParamSort);
+
+ // restore sort order
+ mir_snprintf(t, "os%02x", (UINT)lParamSort);
+ int m = g_plugin.getByte(t, 0);
+ if (bChangeSortOrder) { m = !m; g_plugin.setByte(t, m); }
+
+ ListView_SortItems(hLV, &CompareFunc, lParamSort | (m << 8));
+}
+
+BOOL ShowSelectKeyDlg(HWND hParent, LPSTR KeyPath)
+{
+ OPENFILENAME ofn = { sizeof(ofn) };
+ ofn.hwndOwner = hParent;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON;
+
+ ofn.lpstrFile = KeyPath;
+ char temp[MAX_PATH];
+ mir_snprintf(temp, "%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c", Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0);
+ ofn.lpstrFilter = temp;
+ ofn.lpstrTitle = Translate("Open Key File");
+ if (!GetOpenFileName(&ofn)) return FALSE;
+
+ return TRUE;
+}
+
+LPCSTR priv_beg = "-----BEGIN PGP PRIVATE KEY BLOCK-----";
+LPCSTR priv_end = "-----END PGP PRIVATE KEY BLOCK-----";
+LPCSTR publ_beg = "-----BEGIN PGP PUBLIC KEY BLOCK-----";
+LPCSTR publ_end = "-----END PGP PUBLIC KEY BLOCK-----";
+
+LPSTR LoadKeys(LPCSTR file, BOOL priv)
+{
+ FILE *f = fopen(file, "r");
+ if (!f) return nullptr;
+
+ fseek(f, 0, SEEK_END);
+ int flen = ftell(f);
+ fseek(f, 0, SEEK_SET);
+
+ LPCSTR beg, end;
+ if (priv) {
+ beg = priv_beg;
+ end = priv_end;
+ }
+ else {
+ beg = publ_beg;
+ end = publ_end;
+ }
+
+ LPSTR keys = (LPSTR)mir_alloc(flen + 1);
+ int i = 0; BOOL b = false;
+ while (fgets(keys + i, 128, f)) {
+ if (!b && strncmp(keys + i, beg, mir_strlen(beg)) == 0)
+ b = true;
+ else if (b && strncmp(keys + i, end, mir_strlen(end)) == 0) {
+ i += (int)mir_strlen(keys + i);
+ b = false;
+ }
+ if (b)
+ i += (int)mir_strlen(keys + i);
+ }
+ *(keys + i) = '\0';
+ fclose(f);
+ return keys;
+}
+
+BOOL SaveExportRSAKeyDlg(HWND hParent, LPSTR key, BOOL priv)
+{
+ char szFile[MAX_PATH] = "rsa_pub.asc";
+ if (priv)
+ mir_strcpy(szFile, "rsa_priv.asc");
+
+ OPENFILENAME ofn = { sizeof(ofn) };
+ char temp[MAX_PATH];
+ mir_snprintf(temp, "%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c", Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0);
+ ofn.lpstrFilter = temp;
+ ofn.hwndOwner = hParent;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON;
+ ofn.lpstrFile = szFile;
+
+ ofn.lpstrTitle = (priv) ? Translate("Save Private Key File") : Translate("Save Public Key File");
+ if (!GetSaveFileName(&ofn))
+ return FALSE;
+
+ FILE *f = fopen(szFile, "wb");
+ if (!f)
+ return FALSE;
+ fwrite(key, mir_strlen(key), 1, f);
+ fclose(f);
+
+ return TRUE;
+}
+
+BOOL LoadImportRSAKeyDlg(HWND hParent, LPSTR key, BOOL priv)
+{
+ char szFile[MAX_PATH] = "rsa_pub.asc";
+ if (priv)
+ mir_strcpy(szFile, "rsa_priv.asc");
+
+ OPENFILENAME ofn = { 0 };
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = hParent;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.Flags = OFN_EXPLORER | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN;
+ ofn.lpstrFile = szFile;
+ char temp[MAX_PATH];
+ mir_snprintf(temp, "%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c", Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0);
+ ofn.lpstrFilter = temp;
+ ofn.lpstrTitle = (priv) ? Translate("Load Private Key File") : Translate("Load Public Key File");
+ if (!GetOpenFileName(&ofn))
+ return FALSE;
+
+ FILE *f = fopen(szFile, "rb");
+ if (!f)
+ return FALSE;
+
+ fseek(f, 0, SEEK_END);
+ int flen = ftell(f);
+ if (flen > RSASIZE) {
+ fclose(f);
+ return FALSE;
+ }
+ fseek(f, 0, SEEK_SET);
+
+ fread(key, flen, 1, f);
+ fclose(f);
+ return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////////////
+// first options tab
-INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
+static void ResetGeneralDlg(HWND hDlg)
+{
+ SetDlgItemText(hDlg, IDC_KET, "10");
+ SetDlgItemText(hDlg, IDC_OKT, "2");
+
+ CheckDlgButton(hDlg, IDC_SFT, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_SOM, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_ASI, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_MCD, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_SCM, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_DGP, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_AIP, BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_MCM, BST_UNCHECKED);
+
+ // rebuild list of contacts
+ HWND hLV = GetDlgItem(hDlg, IDC_STD_USERLIST);
+ ListView_DeleteAllItems(hLV);
+
+ LVITEMW lvi = {};
+ lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
+
+ for (auto &hContact : Contacts()) {
+ if (!isSecureProtocol(hContact) || isChatRoom(hContact))
+ continue;
+
+ pUinKey ptr = getUinKey(hContact);
+ if (!ptr)
+ continue;
+
+ ptr->tmode = MODE_NATIVE;
+ ptr->tstatus = STATUS_ENABLED;
+
+ lvi.iItem++;
+ lvi.iImage = ptr->tstatus;
+ lvi.lParam = (LPARAM)ptr;
+ lvi.pszText = Clist_GetContactDisplayName(hContact);
+ int itemNum = LV_InsertItem(hLV, &lvi);
+
+ wchar_t tmp[NAMSIZE];
+ getContactUin(hContact, tmp);
+ LV_SetItemText(hLV, itemNum, 1, tmp);
+
+ setListViewMode(hLV, itemNum, ptr->tmode);
+ setListViewStatus(hLV, itemNum, ptr->tstatus);
+ if (ptr->mode == MODE_NATIVE)
+ setListViewPSK(hLV, itemNum, 0);
+ else
+ setListViewPUB(hLV, itemNum, 0);
+ setListViewIcon(hLV, itemNum, ptr);
+ }
+}
+
+static void RefreshGeneralDlg(HWND hDlg, BOOL iInit)
+{
+ char timeout[10];
+
+ // Key Exchange Timeout
+ UINT data = g_plugin.getWord("ket", 10);
+ mir_itoa(data, timeout, 10);
+ SetDlgItemText(hDlg, IDC_KET, timeout);
+
+ // Offline Key Timeout
+ data = g_plugin.getWord("okt", 2);
+ mir_itoa(data, timeout, 10);
+ SetDlgItemText(hDlg, IDC_OKT, timeout);
+
+ GetFlags();
+
+ CheckDlgButton(hDlg, IDC_SFT, (bSFT) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_SOM, (bSOM) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_ASI, (bASI) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_MCD, (bMCD) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_SCM, (bSCM) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_DGP, (bDGP) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_AIP, (bAIP) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_NOL, (bNOL) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_AAK, (bAAK) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_MCM, (bMCM) ? BST_CHECKED : BST_UNCHECKED);
+
+ // Select {OFF,PGP,GPG}
+ CheckDlgButton(hDlg, IDC_PGP, bPGP ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hDlg, IDC_GPG, bGPG ? BST_CHECKED : BST_UNCHECKED);
+
+ // rebuild list of contacts
+ HWND hLV = GetDlgItem(hDlg, IDC_STD_USERLIST);
+ ListView_DeleteAllItems(hLV);
+
+ LVITEMW lvi; memset(&lvi, 0, sizeof(lvi));
+ lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
+
+ wchar_t tmp[NAMSIZE];
+
+ for (auto &hContact : Contacts()) {
+ if (!Proto_GetAccount(Proto_GetBaseAccountName(hContact)))
+ continue;
+
+ pUinKey ptr = getUinKey(hContact);
+ if (ptr && isSecureProtocol(hContact) && !isChatRoom(hContact)) {
+ if (iInit) {
+ ptr->tmode = ptr->mode;
+ ptr->tstatus = ptr->status;
+ }
+
+ lvi.iItem++;
+ lvi.iImage = ptr->tstatus;
+ lvi.lParam = (LPARAM)ptr;
+ lvi.pszText = Clist_GetContactDisplayName(hContact);
+ int itemNum = LV_InsertItem(hLV, &lvi);
+
+ getContactUin(hContact, tmp);
+ LV_SetItemText(hLV, itemNum, 1, tmp);
+
+ setListViewMode(hLV, itemNum, ptr->tmode);
+ setListViewStatus(hLV, itemNum, ptr->tstatus);
+ if (ptr->mode == MODE_NATIVE)
+ setListViewPSK(hLV, itemNum, hasKey(ptr));
+ else
+ setListViewPUB(hLV, itemNum, hasKey(ptr));
+ setListViewIcon(hLV, itemNum, ptr);
+ }
+ }
+ ListView_Sort(hLV, 0);
+}
+
+static INT_PTR CALLBACK DlgProcSetPSK(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static char *buffer;
+ switch (uMsg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hDlg);
+ SendDlgItemMessage(hDlg, IDC_EDIT1, EM_LIMITTEXT, PSKSIZE - 1, 0);
+ SetDlgItemTextW(hDlg, IDC_EDIT2, (LPWSTR)lParam);
+ buffer = (LPSTR)lParam;
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ if (GetDlgItemTextA(hDlg, IDC_EDIT1, buffer, PSKSIZE) < 8) {
+ msgbox1(hDlg, sim211, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
+ return TRUE;
+ }
+ EndDialog(hDlg, IDOK);
+ break;
+
+ case IDCANCEL:
+ EndDialog(hDlg, IDCANCEL);
+ break;
+ }
+ break;
+
+ default:
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void ApplyGeneralSettings(HWND hDlg)
+{
+ char timeout[5];
+ int tmp, i;
+
+ // Key Exchange Timeout
+ GetDlgItemText(hDlg, IDC_KET, timeout, 5);
+ tmp = atoi(timeout); if (tmp > 65535) tmp = 65535;
+ g_plugin.setWord("ket", tmp);
+ mir_exp->rsa_set_timeout(g_plugin.getWord("ket", 10));
+ mir_itoa(tmp, timeout, 10);
+ SetDlgItemText(hDlg, IDC_KET, timeout);
+
+ // Offline Key Timeout
+ GetDlgItemText(hDlg, IDC_OKT, timeout, 5);
+ tmp = atoi(timeout); if (tmp > 65535) tmp = 65535;
+ g_plugin.setWord("okt", tmp);
+ mir_itoa(tmp, timeout, 10);
+ SetDlgItemText(hDlg, IDC_OKT, timeout);
+
+ bSFT = (IsDlgButtonChecked(hDlg, IDC_SFT) == BST_CHECKED);
+ bSOM = (IsDlgButtonChecked(hDlg, IDC_SOM) == BST_CHECKED);
+ bASI = (IsDlgButtonChecked(hDlg, IDC_ASI) == BST_CHECKED);
+ bMCD = (IsDlgButtonChecked(hDlg, IDC_MCD) == BST_CHECKED);
+ bSCM = (IsDlgButtonChecked(hDlg, IDC_SCM) == BST_CHECKED);
+ bDGP = (IsDlgButtonChecked(hDlg, IDC_DGP) == BST_CHECKED);
+ bAIP = (IsDlgButtonChecked(hDlg, IDC_AIP) == BST_CHECKED);
+ bNOL = (IsDlgButtonChecked(hDlg, IDC_NOL) == BST_CHECKED);
+ bAAK = (IsDlgButtonChecked(hDlg, IDC_AAK) == BST_CHECKED);
+ bMCM = (IsDlgButtonChecked(hDlg, IDC_MCM) == BST_CHECKED);
+
+ SetFlags();
+
+ // PGP &| GPG flags
+ tmp = 0;
+ i = (IsDlgButtonChecked(hDlg, IDC_PGP) == BST_CHECKED);
+ if (i != bPGP) {
+ bPGP = i; tmp++;
+ g_plugin.setByte("pgp", bPGP);
+ }
+ i = (IsDlgButtonChecked(hDlg, IDC_GPG) == BST_CHECKED);
+ if (i != bGPG) {
+ bGPG = i; tmp++;
+ g_plugin.setByte("gpg", bGPG);
+ }
+ if (tmp)
+ msgbox1(hDlg, sim224, MODULENAME, MB_OK | MB_ICONINFORMATION);
+
+ HWND hLV = GetDlgItem(hDlg, IDC_STD_USERLIST);
+ i = ListView_GetNextItem(hLV, (UINT)-1, LVNI_ALL);
+ while (i != -1) {
+ pUinKey ptr = (pUinKey)getListViewParam(hLV, i);
+ if (!ptr) continue;
+ if (ptr->mode != ptr->tmode) {
+ ptr->mode = ptr->tmode;
+ db_set_b(ptr->hContact, MODULENAME, "mode", ptr->mode);
+ }
+ if (ptr->status != ptr->tstatus) {
+ ptr->status = ptr->tstatus;
+ if (ptr->status == STATUS_ENABLED) db_unset(ptr->hContact, MODULENAME, "StatusID");
+ else db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status);
+ }
+ if (ptr->mode == MODE_NATIVE) {
+ if (getListViewPSK(hLV, i)) {
+ LPSTR tmp = db_get_sa(ptr->hContact, MODULENAME, "tPSK");
+ db_set_s(ptr->hContact, MODULENAME, "PSK", tmp);
+ mir_free(tmp);
+ }
+ else db_unset(ptr->hContact, MODULENAME, "PSK");
+
+ db_unset(ptr->hContact, MODULENAME, "tPSK");
+ }
+ else if (ptr->mode == MODE_RSAAES) {
+ if (!getListViewPUB(hLV, i))
+ db_unset(ptr->hContact, MODULENAME, "rsa_pub");
+ }
+ i = ListView_GetNextItem(hLV, i, LVNI_ALL);
+ }
+}
+
+static INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
static int iInit = TRUE;
static HIMAGELIST hLarge, hSmall;
@@ -278,8 +712,8 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR idx = ListView_GetSelectionMark(hLV);
ptr = (pUinKey)getListViewParam(hLV, idx);
if (ptr) {
- LPSTR buffer = (LPSTR)alloca(PSKSIZE + 1);
- getContactName(ptr->hContact, buffer);
+ char *buffer = (LPSTR)alloca(PSKSIZE + 1);
+ strncpy_s(buffer, PSKSIZE, _T2A(Clist_GetContactDisplayName(ptr->hContact)), _TRUNCATE);
int res = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PSK), nullptr, DlgProcSetPSK, (LPARAM)buffer);
if (res == IDOK) {
setListViewPSK(hLV, idx, 1);
@@ -423,8 +857,12 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR }
break;
+ case LVN_COLUMNCLICK:
+ bChangeSortOrder = true;
+ ListView_Sort(hLV, LPNMLISTVIEW(lParam)->iSubItem + 0x01);
+ bChangeSortOrder = false;
+
case NM_RCLICK:
- {
LPNMLISTVIEW lpLV = (LPNMLISTVIEW)lParam;
ptr = (pUinKey)getListViewParam(hLV, lpLV->iItem);
if (ptr) {
@@ -466,13 +904,7 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_LEFTALIGN | TPM_TOPALIGN, p.x, p.y, 0, hDlg, nullptr);
DestroyMenu(hMenu);
}
- }
break;
-
- case LVN_COLUMNCLICK:
- bChangeSortOrder = true;
- ListView_Sort(hLV, LPNMLISTVIEW(lParam)->iSubItem + 0x01);
- bChangeSortOrder = false;
}
break;
}
@@ -481,7 +913,91 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR return FALSE;
}
-INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
+/////////////////////////////////////////////////////////////////////////////////////////
+// Accounts options tab
+
+static INT_PTR CALLBACK DlgProcSetPassphrase(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static LPSTR buffer;
+
+ switch (uMsg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hDlg);
+ SendDlgItemMessage(hDlg, IDC_PASSPHRASE, EM_LIMITTEXT, RSASIZE - 1, 0);
+ buffer = (LPSTR)lParam;
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ GetDlgItemTextA(hDlg, IDC_PASSPHRASE, buffer, RSASIZE);
+ EndDialog(hDlg, IDOK);
+ break;
+
+ case IDCANCEL:
+ EndDialog(hDlg, IDCANCEL);
+ break;
+ }
+ break;
+
+ default:
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void RefreshProtoDlg(HWND hDlg)
+{
+ HWND hLV = GetDlgItem(hDlg, IDC_PROTO);
+ ListView_DeleteAllItems(hLV);
+
+ LVITEMW lvi = { 0 };
+ lvi.mask = LVIF_TEXT | LVIF_PARAM;
+
+ for (int i = 0; i < arProto.getCount(); i++) {
+ auto *pa = Proto_GetAccount(arProto[i]->name);
+ if (pa == nullptr)
+ continue;
+
+ lvi.iItem = i + 1;
+ lvi.pszText = pa->tszAccountName;
+ lvi.lParam = (LPARAM)i;
+ int itemNum = LV_InsertItem(hLV, &lvi);
+ ListView_SetCheckState(hLV, itemNum, arProto[i]->inspecting);
+ }
+
+ SetDlgItemText(hDlg, IDC_SPLITON, "0");
+ SetDlgItemText(hDlg, IDC_SPLITOFF, "0");
+ EnableWindow(GetDlgItem(hDlg, IDC_SPLITON), false);
+ EnableWindow(GetDlgItem(hDlg, IDC_SPLITOFF), false);
+
+ BYTE sha[64]; int len; mir_exp->rsa_get_keyhash(CPP_MODE_RSA, nullptr, nullptr, (PBYTE)&sha, &len);
+ LPSTR txt = mir_strdup(to_hex(sha, len));
+ SetDlgItemText(hDlg, IDC_RSA_SHA, txt);
+ mir_free(txt);
+}
+
+static void ApplyProtoSettings(HWND hDlg)
+{
+ LPSTR szNames = (LPSTR)alloca(2048); *szNames = '\0';
+
+ HWND hLV = GetDlgItem(hDlg, IDC_PROTO);
+ int i = ListView_GetNextItem(hLV, (UINT)-1, LVNI_ALL);
+ while (i != -1) {
+ pSupPro p = arProto[getListViewProto(hLV, i)];
+ p->inspecting = ListView_GetCheckState(hLV, i);
+ char tmp[128];
+ mir_snprintf(tmp, "%s:%d:%d:%d;", p->name, p->inspecting, p->tsplit_on, p->tsplit_off);
+ mir_strcat(szNames, tmp);
+ p->split_on = p->tsplit_on;
+ p->split_off = p->tsplit_off;
+ i = ListView_GetNextItem(hLV, i, LVNI_ALL);
+ }
+
+ g_plugin.setString("protos", szNames);
+}
+
+static INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
static int iInit = TRUE;
char buf[32];
@@ -499,7 +1015,7 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_LEFT;
- lvc.pszText = (LPSTR)sim210;
+ lvc.pszText = LPGEN("Name");
lvc.cx = 150;
LV_InsertColumn(hLV, 0, &lvc);
@@ -523,42 +1039,42 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM return TRUE;
case IDC_RSA_EXP:
- {
- LPSTR pub = (LPSTR)alloca(RSASIZE);
- mir_exp->rsa_export_keypair(CPP_MODE_RSA, nullptr, pub, nullptr);
- if (!SaveExportRSAKeyDlg(hDlg, pub, 0))
- msgbox(hDlg, sim114, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
- }
+ {
+ LPSTR pub = (LPSTR)alloca(RSASIZE);
+ mir_exp->rsa_export_keypair(CPP_MODE_RSA, nullptr, pub, nullptr);
+ if (!SaveExportRSAKeyDlg(hDlg, pub, 0))
+ msgbox(hDlg, sim114, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
+ }
return TRUE;
case IDC_RSA_EXPPRIV:
- {
- LPSTR passphrase = (LPSTR)alloca(RSASIZE);
- int res = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSPHRASE), nullptr, DlgProcSetPassphrase, (LPARAM)passphrase);
- if (res == IDOK) {
- LPSTR priv = (LPSTR)alloca(RSASIZE);
- mir_exp->rsa_export_keypair(CPP_MODE_RSA, priv, nullptr, passphrase);
- if (!SaveExportRSAKeyDlg(hDlg, priv, 1))
- msgbox(hDlg, sim112, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
+ {
+ LPSTR passphrase = (LPSTR)alloca(RSASIZE);
+ int res = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSPHRASE), nullptr, DlgProcSetPassphrase, (LPARAM)passphrase);
+ if (res == IDOK) {
+ LPSTR priv = (LPSTR)alloca(RSASIZE);
+ mir_exp->rsa_export_keypair(CPP_MODE_RSA, priv, nullptr, passphrase);
+ if (!SaveExportRSAKeyDlg(hDlg, priv, 1))
+ msgbox(hDlg, sim112, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
+ }
}
- }
return TRUE;
case IDC_RSA_IMPPRIV:
- {
- LPSTR priv = (LPSTR)alloca(RSASIZE);
- if (!LoadImportRSAKeyDlg(hDlg, priv, 1))
- return TRUE;
+ {
+ LPSTR priv = (LPSTR)alloca(RSASIZE);
+ if (!LoadImportRSAKeyDlg(hDlg, priv, 1))
+ return TRUE;
- LPSTR passphrase = (LPSTR)alloca(RSASIZE);
- int res = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSPHRASE), nullptr, DlgProcSetPassphrase, (LPARAM)passphrase);
- if (res == IDOK) {
- if (!mir_exp->rsa_import_keypair(CPP_MODE_RSA, priv, passphrase))
- msgbox(hDlg, sim113, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
- else // обновить SHA-1 значение
- RefreshProtoDlg(hDlg);
+ LPSTR passphrase = (LPSTR)alloca(RSASIZE);
+ int res = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSPHRASE), nullptr, DlgProcSetPassphrase, (LPARAM)passphrase);
+ if (res == IDOK) {
+ if (!mir_exp->rsa_import_keypair(CPP_MODE_RSA, priv, passphrase))
+ msgbox(hDlg, sim113, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
+ else // обновить SHA-1 значение
+ RefreshProtoDlg(hDlg);
+ }
}
- }
return TRUE;
case IDC_SPLITON:
@@ -617,9 +1133,78 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM return FALSE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// PGP options
+
static BOOL bPGP9;
-INT_PTR CALLBACK DlgProcOptionsPGP(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
+static void RefreshPGPDlg(HWND hDlg, BOOL iInit)
+{
+ int ver = pgp_get_version();
+ bPGP9 = (ver >= 0x03050000);
+
+ EnableWindow(GetDlgItem(hDlg, IDC_SET_KEYRINGS), bUseKeyrings && !bPGP9);
+ EnableWindow(GetDlgItem(hDlg, IDC_LOAD_PRIVKEY), !bUseKeyrings);
+ SetDlgItemText(hDlg, IDC_PGP_PRIVKEY, bPGPprivkey ? Translate(sim222) : Translate(sim223));
+
+ if (bPGPloaded && ver) {
+ char pgpVerStr[64];
+ mir_snprintf(pgpVerStr, Translate(sim218), ver >> 24, (ver >> 16) & 255, (ver >> 8) & 255);
+ SetDlgItemText(hDlg, IDC_PGP_SDK, pgpVerStr);
+ }
+ else SetDlgItemText(hDlg, IDC_PGP_SDK, Translate(sim219));
+
+ SetDlgItemText(hDlg, IDC_KEYRING_STATUS, !bUseKeyrings ? Translate(sim225) : ((bPGP9) ? Translate(sim220) : (bPGPkeyrings ? Translate(sim216) : Translate(sim217))));
+
+ // Disable keyrings use
+ CheckDlgButton(hDlg, IDC_NO_KEYRINGS, (bUseKeyrings) ? BST_UNCHECKED : BST_CHECKED);
+
+ // rebuild list of contacts
+ HWND hLV = GetDlgItem(hDlg, IDC_PGP_USERLIST);
+ ListView_DeleteAllItems(hLV);
+
+ LVITEMW lvi; memset(&lvi, 0, sizeof(lvi));
+ lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
+
+ wchar_t tmp[NAMSIZE];
+
+ for (auto &hContact : Contacts()) {
+ pUinKey ptr = getUinKey(hContact);
+ if (ptr && ptr->mode == MODE_PGP && isSecureProtocol(hContact) && !isChatRoom(hContact)) {
+ LPSTR szKeyID = g_plugin.getStringA(hContact, "pgp_abbr");
+
+ lvi.iItem++;
+ lvi.iImage = (szKeyID != nullptr);
+ lvi.lParam = (LPARAM)ptr;
+ lvi.pszText = Clist_GetContactDisplayName(hContact);
+ int itemNum = LV_InsertItem(hLV, &lvi);
+
+ getContactUin(hContact, tmp);
+ LV_SetItemText(hLV, itemNum, 1, tmp);
+
+ LV_SetItemTextA(hLV, itemNum, 2, (szKeyID) ? szKeyID : Translate(sim221));
+ SAFE_FREE(szKeyID);
+ }
+ }
+ ListView_Sort(hLV, (LPARAM)0x10);
+}
+
+static void ApplyPGPSettings(HWND hDlg)
+{
+ bUseKeyrings = !(IsDlgButtonChecked(hDlg, IDC_NO_KEYRINGS) == BST_CHECKED);
+ g_plugin.setByte("ukr", bUseKeyrings);
+
+ char *priv = g_plugin.getStringA("tpgpPrivKey");
+ if (priv) {
+ bPGPprivkey = true;
+ pgp_set_priv_key(priv);
+ g_plugin.setString("pgpPrivKey", priv);
+ mir_free(priv);
+ g_plugin.delSetting("tpgpPrivKey");
+ }
+}
+
+static INT_PTR CALLBACK DlgProcOptionsPGP(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
static int iInit = TRUE;
static HIMAGELIST hLarge, hSmall;
@@ -673,41 +1258,41 @@ INT_PTR CALLBACK DlgProcOptionsPGP(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM l case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_SET_KEYRINGS:
- {
- char PubRingPath[MAX_PATH], SecRingPath[MAX_PATH];
- PubRingPath[0] = '\0'; SecRingPath[0] = '\0';
- bPGPkeyrings = pgp_open_keyrings(PubRingPath, SecRingPath);
- if (bPGPkeyrings && PubRingPath[0] && SecRingPath[0]) {
- g_plugin.setString("pgpPubRing", PubRingPath);
- g_plugin.setString("pgpSecRing", SecRingPath);
+ {
+ char PubRingPath[MAX_PATH], SecRingPath[MAX_PATH];
+ PubRingPath[0] = '\0'; SecRingPath[0] = '\0';
+ bPGPkeyrings = pgp_open_keyrings(PubRingPath, SecRingPath);
+ if (bPGPkeyrings && PubRingPath[0] && SecRingPath[0]) {
+ g_plugin.setString("pgpPubRing", PubRingPath);
+ g_plugin.setString("pgpSecRing", SecRingPath);
+ }
+ SetDlgItemText(hDlg, IDC_KEYRING_STATUS, bPGPkeyrings ? Translate(sim216) : Translate(sim217));
}
- SetDlgItemText(hDlg, IDC_KEYRING_STATUS, bPGPkeyrings ? Translate(sim216) : Translate(sim217));
- }
return FALSE;
case IDC_NO_KEYRINGS:
- {
- BOOL bNoKR = (IsDlgButtonChecked(hDlg, IDC_NO_KEYRINGS) == BST_CHECKED);
- EnableWindow(GetDlgItem(hDlg, IDC_SET_KEYRINGS), !bNoKR);
- EnableWindow(GetDlgItem(hDlg, IDC_LOAD_PRIVKEY), bNoKR);
- SetDlgItemText(hDlg, IDC_KEYRING_STATUS, bNoKR ? Translate(sim225) : ((bPGP9) ? Translate(sim220) : (bPGPkeyrings ? Translate(sim216) : Translate(sim217))));
- }
+ {
+ BOOL bNoKR = (IsDlgButtonChecked(hDlg, IDC_NO_KEYRINGS) == BST_CHECKED);
+ EnableWindow(GetDlgItem(hDlg, IDC_SET_KEYRINGS), !bNoKR);
+ EnableWindow(GetDlgItem(hDlg, IDC_LOAD_PRIVKEY), bNoKR);
+ SetDlgItemText(hDlg, IDC_KEYRING_STATUS, bNoKR ? Translate(sim225) : ((bPGP9) ? Translate(sim220) : (bPGPkeyrings ? Translate(sim216) : Translate(sim217))));
+ }
break;
case IDC_LOAD_PRIVKEY:
- {
- char KeyPath[MAX_PATH]; KeyPath[0] = '\0';
- if (ShowSelectKeyDlg(hDlg, KeyPath)) {
- char *priv = LoadKeys(KeyPath, true);
- if (priv) {
- g_plugin.setString("tpgpPrivKey", priv);
- mir_free(priv);
- }
- else {
- g_plugin.delSetting("tpgpPrivKey");
+ {
+ char KeyPath[MAX_PATH]; KeyPath[0] = '\0';
+ if (ShowSelectKeyDlg(hDlg, KeyPath)) {
+ char *priv = LoadKeys(KeyPath, true);
+ if (priv) {
+ g_plugin.setString("tpgpPrivKey", priv);
+ mir_free(priv);
+ }
+ else {
+ g_plugin.delSetting("tpgpPrivKey");
+ }
}
}
- }
break;
case ID_UPDATE_PLIST:
@@ -745,346 +1330,10 @@ INT_PTR CALLBACK DlgProcOptionsPGP(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM l return FALSE;
}
-INT_PTR CALLBACK DlgProcOptionsGPG(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
-{
- static int iInit = TRUE;
- static HIMAGELIST hLarge, hSmall;
- int i, idx; pUinKey ptr;
-
- HWND hLV = GetDlgItem(hDlg, IDC_GPG_USERLIST);
-
- switch (wMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hDlg);
-
- iInit = TRUE;
- ListView_SetExtendedListViewStyle(hLV, ListView_GetExtendedListViewStyle(hLV) | LVS_EX_FULLROWSELECT);
-
- hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), iBmpDepth, 1, 1);
- hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), iBmpDepth, 1, 1);
- for (i = ICO_ST_DIS; i <= ICO_ST_TRY; i++) {
- ImageList_AddIcon(hSmall, g_hICO[i]);
- ImageList_AddIcon(hLarge, g_hICO[i]);
- }
-
- ListView_SetImageList(hLV, hSmall, LVSIL_SMALL);
- ListView_SetImageList(hLV, hLarge, LVSIL_NORMAL);
- {
- static const char *szColHdr[] = { sim203, sim204, sim215, sim227, nullptr };
- static int iColWidth[] = { 140, 120, 120, 40 };
- LVCOLUMN lvc;
- lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
- lvc.fmt = LVCFMT_LEFT;
- for (i = 0; szColHdr[i]; i++) {
- lvc.iSubItem = i;
- lvc.pszText = (LPSTR)szColHdr[i];
- lvc.cx = iColWidth[i];
- LV_InsertColumn(hLV, i, &lvc);
- }
- }
-
- RefreshGPGDlg(hDlg, TRUE);
- iInit = FALSE;
- return TRUE;
-
- case WM_DESTROY:
- ImageList_Destroy(hSmall);
- ImageList_Destroy(hLarge);
- break;
-
- case WM_PAINT:
- if (!iInit)
- InvalidateRect(hDlg, nullptr, FALSE);
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_BROWSEEXECUTABLE_BTN:
- {
- char gpgexe[256];
- char filter[128];
- GetDlgItemText(hDlg, IDC_GPGEXECUTABLE_EDIT, gpgexe, _countof(gpgexe));
-
- // filter zusammensetzen
- mir_snprintf(filter, "%s (*.exe)%c*.exe%c%c", Translate("Executable Files"), 0, 0, 0);
-
- // OPENFILENAME initialisieren
- OPENFILENAME ofn = { sizeof(ofn) };
- ofn.hwndOwner = hDlg;
- ofn.lpstrFilter = filter;
- ofn.lpstrFile = gpgexe;
- ofn.nMaxFile = _countof(gpgexe);
- ofn.lpstrTitle = Translate("Select GnuPG Executable");
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
-
- if (GetOpenFileName(&ofn))
- SetDlgItemText(hDlg, IDC_GPGEXECUTABLE_EDIT, ofn.lpstrFile);
- }
- break;
-
- case ID_UPDATE_GLIST:
- iInit = TRUE;
- RefreshGPGDlg(hDlg, FALSE);
- iInit = FALSE;
- return TRUE;
- }
- if (!iInit)
- SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
- break;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
- iInit = TRUE;
- ApplyGPGSettings(hDlg);
- RefreshGPGDlg(hDlg, FALSE);
- iInit = FALSE;
- }
- break;
-
- case IDC_GPG_USERLIST:
- switch (((LPNMHDR)lParam)->code) {
- case NM_DBLCLK:
- if (LPNMLISTVIEW(lParam)->iSubItem == 3) {
- idx = LPNMLISTVIEW(lParam)->iItem;
- ptr = (pUinKey)getListViewParam(hLV, idx);
- if (!ptr) break;
- ptr->tgpgMode++; ptr->tgpgMode &= 1;
- LV_SetItemTextA(hLV, LPNMLISTVIEW(lParam)->iItem, LPNMLISTVIEW(lParam)->iSubItem, (ptr->tgpgMode) ? Translate(sim228) : Translate(sim229));
- SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
- }
- break;
-
- case LVN_COLUMNCLICK:
- bChangeSortOrder = true;
- ListView_Sort(hLV, LPNMLISTVIEW(lParam)->iSubItem + 0x21);
- bChangeSortOrder = false;
- }
- }
- break;
- }
- return FALSE;
-}
-
-INT_PTR CALLBACK DlgProcSetPSK(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- static char *buffer;
- switch (uMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hDlg);
- SendDlgItemMessage(hDlg, IDC_EDIT1, EM_LIMITTEXT, PSKSIZE - 1, 0);
- SetDlgItemTextW(hDlg, IDC_EDIT2, (LPWSTR)lParam);
- buffer = (LPSTR)lParam;
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- if (GetDlgItemTextA(hDlg, IDC_EDIT1, buffer, PSKSIZE) < 8) {
- msgbox1(hDlg, sim211, MODULENAME, MB_OK | MB_ICONEXCLAMATION);
- return TRUE;
- }
- EndDialog(hDlg, IDOK);
- break;
-
- case IDCANCEL:
- EndDialog(hDlg, IDCANCEL);
- break;
- }
- break;
-
- default:
- return FALSE;
- }
- return TRUE;
-}
-
-
-INT_PTR CALLBACK DlgProcSetPassphrase(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- static LPSTR buffer;
-
- switch (uMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hDlg);
- SendDlgItemMessage(hDlg, IDC_PASSPHRASE, EM_LIMITTEXT, RSASIZE - 1, 0);
- buffer = (LPSTR)lParam;
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- GetDlgItemTextA(hDlg, IDC_PASSPHRASE, buffer, RSASIZE);
- EndDialog(hDlg, IDOK);
- break;
-
- case IDCANCEL:
- EndDialog(hDlg, IDCANCEL);
- break;
- }
- break;
-
- default:
- return FALSE;
- }
- return TRUE;
-}
-
-///////////////////
-// R E F R E S H //
-///////////////////
-
-void RefreshGeneralDlg(HWND hDlg, BOOL iInit)
-{
- char timeout[10];
-
- // Key Exchange Timeout
- UINT data = g_plugin.getWord("ket", 10);
- mir_itoa(data, timeout, 10);
- SetDlgItemText(hDlg, IDC_KET, timeout);
-
- // Offline Key Timeout
- data = g_plugin.getWord("okt", 2);
- mir_itoa(data, timeout, 10);
- SetDlgItemText(hDlg, IDC_OKT, timeout);
-
- GetFlags();
-
- CheckDlgButton(hDlg, IDC_SFT, (bSFT) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_SOM, (bSOM) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_ASI, (bASI) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_MCD, (bMCD) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_SCM, (bSCM) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_DGP, (bDGP) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_AIP, (bAIP) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_NOL, (bNOL) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_AAK, (bAAK) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_MCM, (bMCM) ? BST_CHECKED : BST_UNCHECKED);
-
- // Select {OFF,PGP,GPG}
- CheckDlgButton(hDlg, IDC_PGP, bPGP ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_GPG, bGPG ? BST_CHECKED : BST_UNCHECKED);
-
- // rebuild list of contacts
- HWND hLV = GetDlgItem(hDlg, IDC_STD_USERLIST);
- ListView_DeleteAllItems(hLV);
-
- LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
- lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
-
- char tmp[NAMSIZE];
-
- for (auto &hContact : Contacts()) {
- pUinKey ptr = getUinKey(hContact);
- if (ptr && isSecureProtocol(hContact) && !isChatRoom(hContact)) {
- if (iInit) {
- ptr->tmode = ptr->mode;
- ptr->tstatus = ptr->status;
- }
-
- lvi.iItem++;
- lvi.iImage = ptr->tstatus;
- lvi.lParam = (LPARAM)ptr;
-
- getContactName(hContact, tmp);
- lvi.pszText = (LPSTR)&tmp;
- int itemNum = LV_InsertItem(hLV, &lvi);
-
- getContactUin(hContact, tmp);
- LV_SetItemText(hLV, itemNum, 1, tmp);
-
- setListViewMode(hLV, itemNum, ptr->tmode);
- setListViewStatus(hLV, itemNum, ptr->tstatus);
- if (ptr->mode == MODE_NATIVE) setListViewPSK(hLV, itemNum, hasKey(ptr));
- else setListViewPUB(hLV, itemNum, hasKey(ptr));
- setListViewIcon(hLV, itemNum, ptr);
- }
- }
- ListView_Sort(hLV, 0);
-}
-
-void RefreshProtoDlg(HWND hDlg)
-{
- HWND hLV = GetDlgItem(hDlg, IDC_PROTO);
- ListView_DeleteAllItems(hLV);
-
- LVITEM lvi = { 0 };
- lvi.mask = LVIF_TEXT | LVIF_PARAM;
-
- for (int i = 0; i < arProto.getCount(); i++) {
- lvi.iItem = i + 1;
- lvi.pszText = arProto[i]->name;
- lvi.lParam = (LPARAM)i;
- int itemNum = LV_InsertItemA(hLV, &lvi);
- ListView_SetCheckState(hLV, itemNum, arProto[i]->inspecting);
- }
-
- SetDlgItemText(hDlg, IDC_SPLITON, "0");
- SetDlgItemText(hDlg, IDC_SPLITOFF, "0");
- EnableWindow(GetDlgItem(hDlg, IDC_SPLITON), false);
- EnableWindow(GetDlgItem(hDlg, IDC_SPLITOFF), false);
-
- BYTE sha[64]; int len; mir_exp->rsa_get_keyhash(CPP_MODE_RSA, nullptr, nullptr, (PBYTE)&sha, &len);
- LPSTR txt = mir_strdup(to_hex(sha, len));
- SetDlgItemText(hDlg, IDC_RSA_SHA, txt);
- mir_free(txt);
-}
-
-void RefreshPGPDlg(HWND hDlg, BOOL iInit)
-{
- int ver = pgp_get_version();
- bPGP9 = (ver >= 0x03050000);
-
- EnableWindow(GetDlgItem(hDlg, IDC_SET_KEYRINGS), bUseKeyrings && !bPGP9);
- EnableWindow(GetDlgItem(hDlg, IDC_LOAD_PRIVKEY), !bUseKeyrings);
- SetDlgItemText(hDlg, IDC_PGP_PRIVKEY, bPGPprivkey ? Translate(sim222) : Translate(sim223));
-
- if (bPGPloaded && ver) {
- char pgpVerStr[64];
- mir_snprintf(pgpVerStr, Translate(sim218), ver >> 24, (ver >> 16) & 255, (ver >> 8) & 255);
- SetDlgItemText(hDlg, IDC_PGP_SDK, pgpVerStr);
- }
- else SetDlgItemText(hDlg, IDC_PGP_SDK, Translate(sim219));
-
- SetDlgItemText(hDlg, IDC_KEYRING_STATUS, !bUseKeyrings ? Translate(sim225) : ((bPGP9) ? Translate(sim220) : (bPGPkeyrings ? Translate(sim216) : Translate(sim217))));
-
- // Disable keyrings use
- CheckDlgButton(hDlg, IDC_NO_KEYRINGS, (bUseKeyrings) ? BST_UNCHECKED : BST_CHECKED);
-
- // rebuild list of contacts
- HWND hLV = GetDlgItem(hDlg, IDC_PGP_USERLIST);
- ListView_DeleteAllItems(hLV);
-
- LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
- lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
-
- char tmp[NAMSIZE];
-
- for (auto &hContact : Contacts()) {
- pUinKey ptr = getUinKey(hContact);
- if (ptr && ptr->mode == MODE_PGP && isSecureProtocol(hContact) && !isChatRoom(hContact)) {
- LPSTR szKeyID = g_plugin.getStringA(hContact, "pgp_abbr");
-
- lvi.iItem++;
- lvi.iImage = (szKeyID != nullptr);
- lvi.lParam = (LPARAM)ptr;
-
- getContactName(hContact, tmp);
- lvi.pszText = (LPSTR)&tmp;
- int itemNum = LV_InsertItem(hLV, &lvi);
-
- getContactUin(hContact, tmp);
- LV_SetItemText(hLV, itemNum, 1, tmp);
-
- LV_SetItemTextA(hLV, itemNum, 2, (szKeyID) ? szKeyID : Translate(sim221));
- SAFE_FREE(szKeyID);
- }
- }
- ListView_Sort(hLV, (LPARAM)0x10);
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// GPG options
-void RefreshGPGDlg(HWND hDlg, BOOL iInit)
+static void RefreshGPGDlg(HWND hDlg, BOOL iInit)
{
LPSTR path = g_plugin.getStringA("gpgExec");
if (path) {
@@ -1116,10 +1365,10 @@ void RefreshGPGDlg(HWND hDlg, BOOL iInit) HWND hLV = GetDlgItem(hDlg, IDC_GPG_USERLIST);
ListView_DeleteAllItems(hLV);
- LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
+ LVITEMW lvi; memset(&lvi, 0, sizeof(lvi));
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
- char tmp[NAMSIZE];
+ wchar_t tmp[NAMSIZE];
for (auto &hContact : Contacts()) {
pUinKey ptr = getUinKey(hContact);
@@ -1132,9 +1381,7 @@ void RefreshGPGDlg(HWND hDlg, BOOL iInit) lvi.iItem++;
lvi.iImage = (szKeyID != nullptr);
lvi.lParam = (LPARAM)ptr;
-
- getContactName(hContact, tmp);
- lvi.pszText = (LPSTR)&tmp;
+ lvi.pszText = Clist_GetContactDisplayName(hContact);
int itemNum = LV_InsertItem(hLV, &lvi);
getContactUin(hContact, tmp);
@@ -1148,182 +1395,7 @@ void RefreshGPGDlg(HWND hDlg, BOOL iInit) ListView_Sort(hLV, (LPARAM)0x20);
}
-///////////////
-// R E S E T //
-///////////////
-
-void ResetGeneralDlg(HWND hDlg)
-{
- SetDlgItemText(hDlg, IDC_KET, "10");
- SetDlgItemText(hDlg, IDC_OKT, "2");
-
- CheckDlgButton(hDlg, IDC_SFT, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_SOM, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_ASI, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_MCD, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_SCM, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_DGP, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_AIP, BST_UNCHECKED);
- CheckDlgButton(hDlg, IDC_MCM, BST_UNCHECKED);
-
- // rebuild list of contacts
- HWND hLV = GetDlgItem(hDlg, IDC_STD_USERLIST);
- ListView_DeleteAllItems(hLV);
-
- LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
- lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
-
- char tmp[NAMSIZE];
- for (auto &hContact : Contacts()) {
- if (!isSecureProtocol(hContact) || isChatRoom(hContact))
- continue;
-
- pUinKey ptr = getUinKey(hContact);
- if (!ptr) continue;
-
- ptr->tmode = MODE_NATIVE;
- ptr->tstatus = STATUS_ENABLED;
-
- lvi.iItem++;
- lvi.iImage = ptr->tstatus;
- lvi.lParam = (LPARAM)ptr;
-
- getContactName(hContact, tmp);
- lvi.pszText = (LPSTR)&tmp;
- int itemNum = LV_InsertItem(hLV, &lvi);
-
- getContactUin(hContact, tmp);
- LV_SetItemText(hLV, itemNum, 1, tmp);
-
- setListViewMode(hLV, itemNum, ptr->tmode);
- setListViewStatus(hLV, itemNum, ptr->tstatus);
- if (ptr->mode == MODE_NATIVE) setListViewPSK(hLV, itemNum, 0);
- else setListViewPUB(hLV, itemNum, 0);
- setListViewIcon(hLV, itemNum, ptr);
- }
-}
-
-///////////////
-// A P P L Y //
-///////////////
-
-void ApplyGeneralSettings(HWND hDlg)
-{
- char timeout[5];
- int tmp, i;
-
- // Key Exchange Timeout
- GetDlgItemText(hDlg, IDC_KET, timeout, 5);
- tmp = atoi(timeout); if (tmp > 65535) tmp = 65535;
- g_plugin.setWord("ket", tmp);
- mir_exp->rsa_set_timeout(g_plugin.getWord("ket", 10));
- mir_itoa(tmp, timeout, 10);
- SetDlgItemText(hDlg, IDC_KET, timeout);
-
- // Offline Key Timeout
- GetDlgItemText(hDlg, IDC_OKT, timeout, 5);
- tmp = atoi(timeout); if (tmp > 65535) tmp = 65535;
- g_plugin.setWord("okt", tmp);
- mir_itoa(tmp, timeout, 10);
- SetDlgItemText(hDlg, IDC_OKT, timeout);
-
- bSFT = (IsDlgButtonChecked(hDlg, IDC_SFT) == BST_CHECKED);
- bSOM = (IsDlgButtonChecked(hDlg, IDC_SOM) == BST_CHECKED);
- bASI = (IsDlgButtonChecked(hDlg, IDC_ASI) == BST_CHECKED);
- bMCD = (IsDlgButtonChecked(hDlg, IDC_MCD) == BST_CHECKED);
- bSCM = (IsDlgButtonChecked(hDlg, IDC_SCM) == BST_CHECKED);
- bDGP = (IsDlgButtonChecked(hDlg, IDC_DGP) == BST_CHECKED);
- bAIP = (IsDlgButtonChecked(hDlg, IDC_AIP) == BST_CHECKED);
- bNOL = (IsDlgButtonChecked(hDlg, IDC_NOL) == BST_CHECKED);
- bAAK = (IsDlgButtonChecked(hDlg, IDC_AAK) == BST_CHECKED);
- bMCM = (IsDlgButtonChecked(hDlg, IDC_MCM) == BST_CHECKED);
-
- SetFlags();
-
- // PGP &| GPG flags
- {
- tmp = 0;
- i = (IsDlgButtonChecked(hDlg, IDC_PGP) == BST_CHECKED);
- if (i != bPGP) {
- bPGP = i; tmp++;
- g_plugin.setByte("pgp", bPGP);
- }
- i = (IsDlgButtonChecked(hDlg, IDC_GPG) == BST_CHECKED);
- if (i != bGPG) {
- bGPG = i; tmp++;
- g_plugin.setByte("gpg", bGPG);
- }
- if (tmp) msgbox1(hDlg, sim224, MODULENAME, MB_OK | MB_ICONINFORMATION);
- }
-
- HWND hLV = GetDlgItem(hDlg, IDC_STD_USERLIST);
- i = ListView_GetNextItem(hLV, (UINT)-1, LVNI_ALL);
- while (i != -1) {
- pUinKey ptr = (pUinKey)getListViewParam(hLV, i);
- if (!ptr) continue;
- if (ptr->mode != ptr->tmode) {
- ptr->mode = ptr->tmode;
- db_set_b(ptr->hContact, MODULENAME, "mode", ptr->mode);
- }
- if (ptr->status != ptr->tstatus) {
- ptr->status = ptr->tstatus;
- if (ptr->status == STATUS_ENABLED) db_unset(ptr->hContact, MODULENAME, "StatusID");
- else db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status);
- }
- if (ptr->mode == MODE_NATIVE) {
- if (getListViewPSK(hLV, i)) {
- LPSTR tmp = db_get_sa(ptr->hContact, MODULENAME, "tPSK");
- db_set_s(ptr->hContact, MODULENAME, "PSK", tmp);
- mir_free(tmp);
- }
- else db_unset(ptr->hContact, MODULENAME, "PSK");
-
- db_unset(ptr->hContact, MODULENAME, "tPSK");
- }
- else if (ptr->mode == MODE_RSAAES) {
- if (!getListViewPUB(hLV, i))
- db_unset(ptr->hContact, MODULENAME, "rsa_pub");
- }
- i = ListView_GetNextItem(hLV, i, LVNI_ALL);
- }
-}
-
-void ApplyProtoSettings(HWND hDlg)
-{
- LPSTR szNames = (LPSTR)alloca(2048); *szNames = '\0';
-
- HWND hLV = GetDlgItem(hDlg, IDC_PROTO);
- int i = ListView_GetNextItem(hLV, (UINT)-1, LVNI_ALL);
- while (i != -1) {
- pSupPro p = arProto[getListViewProto(hLV, i)];
- p->inspecting = ListView_GetCheckState(hLV, i);
- char tmp[128];
- mir_snprintf(tmp, "%s:%d:%d:%d;", p->name, p->inspecting, p->tsplit_on, p->tsplit_off);
- mir_strcat(szNames, tmp);
- p->split_on = p->tsplit_on;
- p->split_off = p->tsplit_off;
- i = ListView_GetNextItem(hLV, i, LVNI_ALL);
- }
-
- g_plugin.setString("protos", szNames);
-}
-
-void ApplyPGPSettings(HWND hDlg)
-{
- bUseKeyrings = !(IsDlgButtonChecked(hDlg, IDC_NO_KEYRINGS) == BST_CHECKED);
- g_plugin.setByte("ukr", bUseKeyrings);
-
- char *priv = g_plugin.getStringA("tpgpPrivKey");
- if (priv) {
- bPGPprivkey = true;
- pgp_set_priv_key(priv);
- g_plugin.setString("pgpPrivKey", priv);
- mir_free(priv);
- g_plugin.delSetting("tpgpPrivKey");
- }
-}
-
-void ApplyGPGSettings(HWND hDlg)
+static void ApplyGPGSettings(HWND hDlg)
{
char tmp[256];
@@ -1364,339 +1436,164 @@ void ApplyGPGSettings(HWND hDlg) }
}
-///////////////
-// O T H E R //
-///////////////
-
-LPARAM getListViewParam(HWND hLV, UINT iItem)
-{
- LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
- lvi.iItem = iItem;
- lvi.mask = LVIF_PARAM;
- ListView_GetItem(hLV, &lvi);
- return lvi.lParam;
-}
-
-void setListViewIcon(HWND hLV, UINT iItem, pUinKey ptr)
-{
- LVITEM lvi; memset(&lvi, 0, sizeof(lvi));
- lvi.iItem = iItem;
- switch (ptr->tmode) {
- case MODE_NATIVE:
- case MODE_RSAAES:
- lvi.iImage = ICO_ST_DIS + ptr->tstatus;
- break;
- case MODE_PGP:
- lvi.iImage = ICO_OV_PGP;
- break;
- case MODE_GPG:
- lvi.iImage = ICO_OV_GPG;
- break;
- }
- lvi.mask = LVIF_IMAGE;
- ListView_SetItem(hLV, &lvi);
-}
-
-void setListViewMode(HWND hLV, UINT iItem, UINT iMode)
-{
- char tmp[256];
- strncpy(tmp, Translate(sim231[iMode]), sizeof(tmp)-1);
- LV_SetItemTextA(hLV, iItem, 2, tmp);
-}
-
-void setListViewStatus(HWND hLV, UINT iItem, UINT iStatus)
-{
- char tmp[128];
- strncpy(tmp, Translate(sim232[iStatus]), sizeof(tmp)-1);
- LV_SetItemTextA(hLV, iItem, 3, tmp);
-}
-
-UINT getListViewPSK(HWND hLV, UINT iItem)
+static INT_PTR CALLBACK DlgProcOptionsGPG(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
- char str[128];
- LV_GetItemTextA(hLV, iItem, 4, str, _countof(str));
- return strncmp(str, Translate(sim206), sizeof(str)) == 0;
-}
+ static int iInit = TRUE;
+ static HIMAGELIST hLarge, hSmall;
+ int i, idx; pUinKey ptr;
-void setListViewPSK(HWND hLV, UINT iItem, UINT iStatus)
-{
- char str[128];
- strncpy(str, (iStatus) ? Translate(sim206) : "-", sizeof(str)-1);
- LV_SetItemTextA(hLV, iItem, 4, str);
-}
+ HWND hLV = GetDlgItem(hDlg, IDC_GPG_USERLIST);
-UINT getListViewPUB(HWND hLV, UINT iItem)
-{
- char str[128];
- LV_GetItemTextA(hLV, iItem, 4, str, _countof(str));
- return strncmp(str, Translate(sim233), sizeof(str)) == 0;
-}
+ switch (wMsg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hDlg);
-void setListViewPUB(HWND hLV, UINT iItem, UINT iStatus)
-{
- char str[128];
- strncpy(str, (iStatus) ? Translate(sim233) : "-", sizeof(str)-1);
- LV_SetItemTextA(hLV, iItem, 4, str);
+ iInit = TRUE;
+ ListView_SetExtendedListViewStyle(hLV, ListView_GetExtendedListViewStyle(hLV) | LVS_EX_FULLROWSELECT);
- LPSTR sha = nullptr;
- if (iStatus) {
- DBVARIANT dbv;
- dbv.type = DBVT_BLOB;
- pUinKey ptr = (pUinKey)getListViewParam(hLV, iItem);
- if (db_get(ptr->hContact, MODULENAME, "rsa_pub", &dbv) == 0) {
- int len;
- mir_exp->rsa_get_hash((PBYTE)dbv.pbVal, dbv.cpbVal, (PBYTE)str, &len);
- sha = mir_strdup(to_hex((PBYTE)str, len));
- db_free(&dbv);
+ hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), iBmpDepth, 1, 1);
+ hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), iBmpDepth, 1, 1);
+ for (i = ICO_ST_DIS; i <= ICO_ST_TRY; i++) {
+ ImageList_AddIcon(hSmall, g_hICO[i]);
+ ImageList_AddIcon(hLarge, g_hICO[i]);
}
- }
- if (sha) {
- LV_SetItemTextA(hLV, iItem, 5, sha);
- mir_free(sha);
- }
- else LV_SetItemTextA(hLV, iItem, 5, "");
-}
-
-int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
-{
- pUinKey p1 = pUinKey(lParam1), p2 = pUinKey(lParam2);
- char t1[NAMSIZE], t2[NAMSIZE];
- int s=0, d=0, m = 1;
- DBVARIANT dbv1 = { 0 }, dbv2 = { 0 };
- if (lParamSort & 0x100) {
- lParamSort &= 0xFF;
- m = -1;
- }
+ ListView_SetImageList(hLV, hSmall, LVSIL_SMALL);
+ ListView_SetImageList(hLV, hLarge, LVSIL_NORMAL);
+ {
+ static const char *szColHdr[] = { sim203, sim204, sim215, sim227, nullptr };
+ static int iColWidth[] = { 140, 120, 120, 40 };
+ LVCOLUMN lvc;
+ lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+ lvc.fmt = LVCFMT_LEFT;
+ for (i = 0; szColHdr[i]; i++) {
+ lvc.iSubItem = i;
+ lvc.pszText = (LPSTR)szColHdr[i];
+ lvc.cx = iColWidth[i];
+ LV_InsertColumn(hLV, i, &lvc);
+ }
+ }
- switch (lParamSort) {
- case 0x01:
- case 0x11:
- case 0x21:
- getContactNameA(p1->hContact, t1);
- getContactNameA(p2->hContact, t2);
- return strncmp(t1, t2, NAMSIZE)*m;
+ RefreshGPGDlg(hDlg, TRUE);
+ iInit = FALSE;
+ return TRUE;
- case 0x02:
- case 0x12:
- case 0x22:
- getContactUinA(p1->hContact, t1);
- getContactUinA(p2->hContact, t2);
- return strncmp(t1, t2, NAMSIZE)*m;
+ case WM_DESTROY:
+ ImageList_Destroy(hSmall);
+ ImageList_Destroy(hLarge);
+ break;
- case 0x03:
- s = p1->tmode;
- d = p2->tmode;
- return (s - d)*m;
+ case WM_PAINT:
+ if (!iInit)
+ InvalidateRect(hDlg, nullptr, FALSE);
+ break;
- case 0x13:
- if(!db_get_s(p1->hContact, MODULENAME, "pgp_abbr", &dbv1)){
- if(!db_get_s(p2->hContact, MODULENAME, "pgp_abbr", &dbv2)) {
- s = (dbv1.type == DBVT_ASCIIZ);
- d = (dbv2.type == DBVT_ASCIIZ);
- if (s && d) {
- s = mir_strcmp(dbv1.pszVal, dbv2.pszVal);
- d = 0;
- }
- db_free(&dbv1);
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_BROWSEEXECUTABLE_BTN:
+ {
+ char gpgexe[256];
+ char filter[128];
+ GetDlgItemText(hDlg, IDC_GPGEXECUTABLE_EDIT, gpgexe, _countof(gpgexe));
+
+ // filter zusammensetzen
+ mir_snprintf(filter, "%s (*.exe)%c*.exe%c%c", Translate("Executable Files"), 0, 0, 0);
+
+ // OPENFILENAME initialisieren
+ OPENFILENAME ofn = { sizeof(ofn) };
+ ofn.hwndOwner = hDlg;
+ ofn.lpstrFilter = filter;
+ ofn.lpstrFile = gpgexe;
+ ofn.nMaxFile = _countof(gpgexe);
+ ofn.lpstrTitle = Translate("Select GnuPG Executable");
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
+
+ if (GetOpenFileName(&ofn))
+ SetDlgItemText(hDlg, IDC_GPGEXECUTABLE_EDIT, ofn.lpstrFile);
}
- db_free(&dbv2);
- return (s - d)*m;
- }
- else
- return 0;
+ break;
- case 0x23:
- if(!db_get_s(p1->hContact, MODULENAME, "gpg", &dbv1)) {
- s = (dbv1.type == DBVT_ASCIIZ);
- if(!db_get_s(p2->hContact, MODULENAME, "gpg", &dbv2)) {
- d = (dbv2.type == DBVT_ASCIIZ);
- if (s && d) {
- s = mir_strcmp(dbv1.pszVal, dbv2.pszVal);
- d = 0;
- }
- db_free(&dbv1);
- }
- db_free(&dbv2);
- return (s - d)*m;
+ case ID_UPDATE_GLIST:
+ iInit = TRUE;
+ RefreshGPGDlg(hDlg, FALSE);
+ iInit = FALSE;
+ return TRUE;
}
- else
- return 0;
-
- case 0x04:
- s = p1->tstatus;
- d = p2->tstatus;
- return (s - d)*m;
+ if (!iInit)
+ SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
+ break;
- case 0x05:
- if(!db_get_s(p1->hContact, MODULENAME, "PSK", &dbv1)) {
- s = (dbv1.type == DBVT_ASCIIZ);
- if (!db_get_s(p2->hContact, MODULENAME, "PSK", &dbv2)) {
- d = (dbv2.type == DBVT_ASCIIZ);
- db_free(&dbv2);
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
+ iInit = TRUE;
+ ApplyGPGSettings(hDlg);
+ RefreshGPGDlg(hDlg, FALSE);
+ iInit = FALSE;
}
- db_free(&dbv1);
- return (s - d)*m;
- }
- else
- return 0;
- }
- return 0;
-}
-
-void ListView_Sort(HWND hLV, LPARAM lParamSort)
-{
- // restore sort column
- char t[32];
- mir_snprintf(t, "os%02x", (UINT)lParamSort & 0xF0);
- if ((lParamSort & 0x0F) == 0)
- lParamSort = (int)g_plugin.getByte(t, lParamSort + 1);
-
- g_plugin.setByte(t, (BYTE)lParamSort);
-
- // restore sort order
- mir_snprintf(t, "os%02x", (UINT)lParamSort);
- int m = g_plugin.getByte(t, 0);
- if (bChangeSortOrder) { m = !m; g_plugin.setByte(t, m); }
-
- ListView_SortItems(hLV, &CompareFunc, lParamSort | (m << 8));
-}
-
-BOOL ShowSelectKeyDlg(HWND hParent, LPSTR KeyPath)
-{
- OPENFILENAME ofn = { sizeof(ofn) };
- ofn.hwndOwner = hParent;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON;
-
- ofn.lpstrFile = KeyPath;
- char temp[MAX_PATH];
- mir_snprintf(temp, "%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c", Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0);
- ofn.lpstrFilter = temp;
- ofn.lpstrTitle = Translate("Open Key File");
- if (!GetOpenFileName(&ofn)) return FALSE;
-
- return TRUE;
-}
-
-LPCSTR priv_beg = "-----BEGIN PGP PRIVATE KEY BLOCK-----";
-LPCSTR priv_end = "-----END PGP PRIVATE KEY BLOCK-----";
-LPCSTR publ_beg = "-----BEGIN PGP PUBLIC KEY BLOCK-----";
-LPCSTR publ_end = "-----END PGP PUBLIC KEY BLOCK-----";
-
-LPSTR LoadKeys(LPCSTR file, BOOL priv)
-{
- FILE *f = fopen(file, "r");
- if (!f) return nullptr;
-
- fseek(f, 0, SEEK_END);
- int flen = ftell(f);
- fseek(f, 0, SEEK_SET);
+ break;
- LPCSTR beg, end;
- if (priv) {
- beg = priv_beg;
- end = priv_end;
- }
- else {
- beg = publ_beg;
- end = publ_end;
- }
+ case IDC_GPG_USERLIST:
+ switch (((LPNMHDR)lParam)->code) {
+ case NM_DBLCLK:
+ if (LPNMLISTVIEW(lParam)->iSubItem == 3) {
+ idx = LPNMLISTVIEW(lParam)->iItem;
+ ptr = (pUinKey)getListViewParam(hLV, idx);
+ if (!ptr) break;
+ ptr->tgpgMode++; ptr->tgpgMode &= 1;
+ LV_SetItemTextA(hLV, LPNMLISTVIEW(lParam)->iItem, LPNMLISTVIEW(lParam)->iSubItem, (ptr->tgpgMode) ? Translate(sim228) : Translate(sim229));
+ SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
+ }
+ break;
- LPSTR keys = (LPSTR)mir_alloc(flen + 1);
- int i = 0; BOOL b = false;
- while (fgets(keys + i, 128, f)) {
- if (!b && strncmp(keys + i, beg, mir_strlen(beg)) == 0)
- b = true;
- else if (b && strncmp(keys + i, end, mir_strlen(end)) == 0) {
- i += (int)mir_strlen(keys + i);
- b = false;
+ case LVN_COLUMNCLICK:
+ bChangeSortOrder = true;
+ ListView_Sort(hLV, LPNMLISTVIEW(lParam)->iSubItem + 0x21);
+ bChangeSortOrder = false;
+ }
}
- if (b)
- i += (int)mir_strlen(keys + i);
+ break;
}
- *(keys + i) = '\0';
- fclose(f);
- return keys;
-}
-
-BOOL SaveExportRSAKeyDlg(HWND hParent, LPSTR key, BOOL priv)
-{
- char szFile[MAX_PATH] = "rsa_pub.asc";
- if (priv)
- mir_strcpy(szFile, "rsa_priv.asc");
-
- OPENFILENAME ofn = { sizeof(ofn) };
- char temp[MAX_PATH];
- mir_snprintf(temp, "%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c", Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0);
- ofn.lpstrFilter = temp;
- ofn.hwndOwner = hParent;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON;
- ofn.lpstrFile = szFile;
-
- ofn.lpstrTitle = (priv) ? Translate("Save Private Key File") : Translate("Save Public Key File");
- if (!GetSaveFileName(&ofn))
- return FALSE;
-
- FILE *f = fopen(szFile, "wb");
- if (!f)
- return FALSE;
- fwrite(key, mir_strlen(key), 1, f);
- fclose(f);
-
- return TRUE;
+ return FALSE;
}
-BOOL LoadImportRSAKeyDlg(HWND hParent, LPSTR key, BOOL priv)
-{
- char szFile[MAX_PATH] = "rsa_pub.asc";
- if (priv)
- mir_strcpy(szFile, "rsa_priv.asc");
-
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hParent;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_EXPLORER | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN;
- ofn.lpstrFile = szFile;
- char temp[MAX_PATH];
- mir_snprintf(temp, "%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c", Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0);
- ofn.lpstrFilter = temp;
- ofn.lpstrTitle = (priv) ? Translate("Load Private Key File") : Translate("Load Public Key File");
- if (!GetOpenFileName(&ofn))
- return FALSE;
-
- FILE *f = fopen(szFile, "rb");
- if (!f)
- return FALSE;
-
- fseek(f, 0, SEEK_END);
- int flen = ftell(f);
- if (flen > RSASIZE) {
- fclose(f);
- return FALSE;
- }
- fseek(f, 0, SEEK_SET);
-
- fread(key, flen, 1, f);
- fclose(f);
- return TRUE;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Module entry point
int onRegisterOptions(WPARAM wParam, LPARAM lParam)
{
OPTIONSDIALOGPAGE odp = {};
odp.szTitle.a = MODULENAME;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONSTAB);
+ odp.szGroup.a = LPGEN("Popups");
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_POPUP);
+ odp.pfnDlgProc = PopOptionsDlgProc;
+ g_plugin.addOptions(wParam, &odp);
+
odp.szGroup.a = LPGEN("Services");
- odp.pfnDlgProc = OptionsDlgProc;
+ odp.szTab.a = LPGEN("General");
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_TAB_GENERAL);
+ odp.pfnDlgProc = DlgProcOptionsGeneral;
g_plugin.addOptions(wParam, &odp);
- odp.pszTemplate = MAKEINTRESOURCE(IDD_POPUP);
- odp.szGroup.a = LPGEN("Popups");
- odp.pfnDlgProc = PopOptionsDlgProc;
+ odp.szTab.a = LPGEN("Accounts");
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_TAB_PROTO);
+ odp.pfnDlgProc = DlgProcOptionsProto;
g_plugin.addOptions(wParam, &odp);
+
+ if (bPGP && bPGPloaded) {
+ odp.szTab.a = "PGP";
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_TAB_PGP);
+ odp.pfnDlgProc = DlgProcOptionsPGP;
+ g_plugin.addOptions(wParam, &odp);
+ }
+
+ if (bGPG && bGPGloaded) {
+ odp.szTab.a = "GPG";
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_TAB_GPG);
+ odp.pfnDlgProc = DlgProcOptionsGPG;
+ g_plugin.addOptions(wParam, &odp);
+ }
return 0;
}
diff --git a/plugins/SecureIM/src/options.h b/plugins/SecureIM/src/options.h index b1f2b65b0e..0a673de432 100644 --- a/plugins/SecureIM/src/options.h +++ b/plugins/SecureIM/src/options.h @@ -1,37 +1,9 @@ #ifndef __OPTIONS_H__
#define __OPTIONS_H__
-INT_PTR CALLBACK OptionsDlgProc(HWND,UINT,WPARAM,LPARAM);
-INT_PTR CALLBACK DlgProcOptionsGeneral(HWND,UINT,WPARAM,LPARAM);
-INT_PTR CALLBACK DlgProcOptionsProto(HWND,UINT,WPARAM,LPARAM);
-INT_PTR CALLBACK DlgProcOptionsPGP(HWND,UINT,WPARAM,LPARAM);
-INT_PTR CALLBACK DlgProcOptionsGPG(HWND,UINT,WPARAM,LPARAM);
-INT_PTR CALLBACK DlgProcSetPSK(HWND,UINT,WPARAM,LPARAM);
-INT_PTR CALLBACK DlgProcSetPassphrase(HWND,UINT,WPARAM,LPARAM);
-void ApplyGeneralSettings(HWND);
-void ApplyProtoSettings(HWND);
-void ApplyPGPSettings(HWND);
-void ApplyGPGSettings(HWND);
-void RefreshGeneralDlg(HWND,BOOL);
-void RefreshProtoDlg(HWND);
-void RefreshPGPDlg(HWND,BOOL);
-void RefreshGPGDlg(HWND,BOOL);
-void ResetGeneralDlg(HWND);
-LPARAM getListViewParam(HWND,UINT);
-void setListViewIcon(HWND,UINT,pUinKey);
-void setListViewMode(HWND,UINT,UINT);
-void setListViewStatus(HWND,UINT,UINT);
-UINT getListViewPSK(HWND,UINT);
-void setListViewPSK(HWND,UINT,UINT);
-UINT getListViewPUB(HWND,UINT);
-void setListViewPUB(HWND,UINT,UINT);
int onRegisterOptions(WPARAM,LPARAM);
-int CALLBACK CompareFunc(LPARAM,LPARAM,LPARAM);
-void ListView_Sort(HWND,LPARAM);
BOOL ShowSelectKeyDlg(HWND,LPSTR);
LPSTR LoadKeys(LPCSTR,BOOL);
-BOOL SaveExportRSAKeyDlg(HWND,LPSTR,BOOL);
-BOOL LoadImportRSAKeyDlg(HWND,LPSTR,BOOL);
#define getListViewContact(h,i) (HANDLE)getListViewParam(h,i)
#define getListViewProto(h,i) (int)getListViewParam(h,i)
diff --git a/plugins/SecureIM/src/svcs_rsa.cpp b/plugins/SecureIM/src/svcs_rsa.cpp index 1663cc6aec..e4a0f226e8 100644 --- a/plugins/SecureIM/src/svcs_rsa.cpp +++ b/plugins/SecureIM/src/svcs_rsa.cpp @@ -32,7 +32,7 @@ int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int {
int v = 0, k = 0;
pUinKey ptr = getUinCtx(context); if (!ptr) return 0;
- LPSTR cnm = (LPSTR)mir_alloc(NAMSIZE); getContactNameA(ptr->hContact, cnm);
+ LPSTR cnm = (LPSTR)mir_alloc(NAMSIZE); strncpy_s(cnm, NAMSIZE, _T2A(Clist_GetContactDisplayName(ptr->hContact)), _TRUNCATE);
LPSTR uin = (LPSTR)mir_alloc(KEYSIZE); getContactUinA(ptr->hContact, uin);
LPSTR msg = (LPSTR)mir_alloc(MSGSIZE);
LPSTR sha = mir_strdup(to_hex(sig, sigLen));
@@ -50,8 +50,10 @@ int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int db_free(&dbv);
}
if (bAAK) {
- if (k) mir_snprintf(msg, MSGSIZE, Translate(sim523), cnm, uin, sha, sha_old);
- else mir_snprintf(msg, MSGSIZE, Translate(sim521), cnm, uin, sha);
+ if (k)
+ mir_snprintf(msg, MSGSIZE, Translate(sim523), cnm, uin, sha, sha_old);
+ else
+ mir_snprintf(msg, MSGSIZE, Translate(sim521), cnm, uin, sha);
showPopupKRmsg(ptr->hContact, msg);
HistoryLog(ptr->hContact, msg);
v = 1;
@@ -60,8 +62,10 @@ int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int #endif
}
else {
- if (k) mir_snprintf(msg, MSGSIZE, Translate(sim522), cnm, sha, sha_old);
- else mir_snprintf(msg, MSGSIZE, Translate(sim520), cnm, sha);
+ if (k)
+ mir_snprintf(msg, MSGSIZE, Translate(sim522), cnm, sha, sha_old);
+ else
+ mir_snprintf(msg, MSGSIZE, Translate(sim520), cnm, sha);
v = (msgbox(nullptr, msg, MODULENAME, MB_YESNO | MB_ICONQUESTION) == IDYES);
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("rsa_check_pub: manual accepted %d", v);
diff --git a/plugins/SecureIM/src/version.h b/plugins/SecureIM/src/version.h index 5911977447..e53f5f4590 100644 --- a/plugins/SecureIM/src/version.h +++ b/plugins/SecureIM/src/version.h @@ -1,13 +1,13 @@ -#define __MAJOR_VERSION 1
-#define __MINOR_VERSION 0
+#define __MAJOR_VERSION 1
+#define __MINOR_VERSION 0
#define __RELEASE_NUM 12
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>
#define __PLUGIN_NAME "SecureIM"
#define __FILENAME "SecureIM.dll"
-#define __DESCRIPTION "SecureIM plugin for Miranda NG."
-#define __AUTHOR "Johell, Ghost, Nightwish, __alex, Baloo"
-#define __AUTHORWEB "https://miranda-ng.org/p/SecureIM/"
-#define __COPYRIGHT "© 2003 Johell, 2005-09 Baloo"
+#define __DESCRIPTION "SecureIM plugin for Miranda NG."
+#define __AUTHOR "Johell, Ghost, Nightwish, __alex, Baloo"
+#define __AUTHORWEB "https://miranda-ng.org/p/SecureIM/"
+#define __COPYRIGHT "© 2003 Johell, 2005-09 Baloo"
|