From 41539458d2d114cb714b72315c482e33340a9ee3 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 11 Aug 2010 05:22:07 +0300 Subject: modified: init.cpp modified: main.cpp modified: messages.cpp modified: new_gpg.rc modified: options.cpp modified: resource.h modified: utilities.cpp --- init.cpp | 21 +++++++++++-- main.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++--------------- messages.cpp | 11 +++++++ new_gpg.rc | 16 ++++++++++ options.cpp | 66 +++++++++++++++++++++++---------------- resource.h | 5 +-- utilities.cpp | 7 +++++ 7 files changed, 169 insertions(+), 56 deletions(-) diff --git a/init.cpp b/init.cpp index 5bc53ff..801b1c7 100644 --- a/init.cpp +++ b/init.cpp @@ -18,7 +18,7 @@ HINSTANCE hInst; -HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL; +HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL; PLUGINLINK *pluginLink; static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); extern char *date(); @@ -69,6 +69,7 @@ extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) int LoadKey(WPARAM w, LPARAM l); int ToggleEncryption(WPARAM w, LPARAM l); +int SendKey(WPARAM w, LPARAM l); extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) { @@ -77,7 +78,8 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) mir_getMMI(&mmi); mir_getUTFI(&utfi); CreateServiceFunction("/LoadPubKey",LoadKey); - CreateServiceFunction("/ToggleEncryption",ToggleEncryption); + CreateServiceFunction("/ToggleEncryption",ToggleEncryption); + CreateServiceFunction("/SendKey",SendKey); CLISTMENUITEM mi = {0}; mi.cbSize=sizeof(mi); mi.position=-0x7FFFFFFF; @@ -94,6 +96,14 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) mi.pszName="Toggle GPG encryption"; mi.pszService="/ToggleEncryption"; hToggleEncryption = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFe; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Send public key"; + mi.pszService="/SendKey"; + hSendKey = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); return 0; } @@ -112,6 +122,13 @@ static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) int RecvMsgSvc(WPARAM w, LPARAM l); int SendMsgSvc(WPARAM w, LPARAM l); + void test(); + + void FirstRun(); + FirstRun(); + + test(); + HookEvent(ME_OPT_INITIALISE, GpgOptInit); hOnPreBuildContactMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); diff --git a/main.cpp b/main.cpp index b93f9f5..7adec85 100644 --- a/main.cpp +++ b/main.cpp @@ -21,30 +21,79 @@ void test() { - DWORD exitcode; - string output; - TCHAR *bin_path = UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T("")); + string out; + DWORD code; + TCHAR cmd[512]; + _tcscpy(cmd, _T("--list-secret-keys")); + pxExecute(cmd, "", &out, &code); + MessageBoxA(0, out.c_str(), "test", MB_OK); +} + + +HWND hwndFirstRun = NULL; + +static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case ID_OK: + DestroyWindow(hwndDlg); + break; + } + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + return TRUE; + } + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndFirstRun = NULL; + break; + + } + + return FALSE; +} + +extern HINSTANCE hInst; + +void ShowFirstRunDialog() +{ + if (hwndFirstRun == NULL) { - if(_waccess(bin_path, 0) == -1) - if(errno == ENOENT) - { - mir_free(bin_path); - return; - } + hwndFirstRun = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIRST_RUN), NULL, DlgProcFirstRun); } - TCHAR *home_dir = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T("")); - TCHAR bin[512]; - _tcscpy(bin, bin_path); - _tcscat(bin, _T(" --homedir ")); - _tcscat(bin, _T("\"")); - _tcscat(bin, home_dir); - _tcscat(bin, _T("\"")); - _tcscat(bin, _T(" --help")); - pxResult pxresult=pxExecute(bin,"",&output,&exitcode); - mir_free(bin_path); - mir_free(home_dir); -/* fstream f("c:\\str.txt", std::ios::out); - f<flags&PREF_UNICODE); + { //check for public key + string str = msg; + string::size_type s1, s2; + if(((s2 = str.find("-----END PGP PUBLIC KEY BLOCK-----")) != string::npos) && ((s1 = str.find("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != string::npos)) + { //this is public key + } + else if(((s2 = str.find("-/ENCRYPTED-")) != string::npos) && ((s1 = str.find("-ENCRYPTED-")) != string::npos)) + { //this is encrypted data block + } + } + return CallService(MS_PROTO_CHAINRECV, w, l); } diff --git a/new_gpg.rc b/new_gpg.rc index d60bec2..6b5dce6 100644 --- a/new_gpg.rc +++ b/new_gpg.rc @@ -62,6 +62,14 @@ BEGIN EDITTEXT IDC_PUBLIC_KEY_EDIT,7,7,255,51,ES_MULTILINE | ES_AUTOHSCROLL | WS_VSCROLL,WS_EX_STATICEDGE END +IDD_FIRST_RUN DIALOGEX 0, 0, 439, 196 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "new GPG Plugin First Run" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "خت",ID_OK,15,175,50,14 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -78,6 +86,14 @@ BEGIN TOPMARGIN, 7 BOTTOMMARGIN, 77 END + + IDD_FIRST_RUN, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 432 + TOPMARGIN, 7 + BOTTOMMARGIN, 189 + END END #endif // APSTUDIO_INVOKED diff --git a/options.cpp b/options.cpp index e1ce214..2afed94 100644 --- a/options.cpp +++ b/options.cpp @@ -62,9 +62,10 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA { HWND hwndList=GetDlgItem(hwndDlg, IDC_USERLIST); hwndList_p = hwndList; - LVCOLUMN col; - LVITEM item; - TCHAR *tmp; + LVCOLUMN col = {0}; + LVITEM item = {0}; + TCHAR *tmp = NULL; + char *tmp2 = NULL; NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; switch (msg) { @@ -77,7 +78,7 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA col.cx = 100; ListView_InsertColumn(hwndList, 0, &col); ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Protocol"); + col.pszText = _T("Fingerprint"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 30; @@ -88,6 +89,12 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA col.fmt = LVCFMT_LEFT; col.cx = 250; ListView_InsertColumn(hwndList, 2, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Protocol"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 3, &col); ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); int i = 1, iRow = 0; for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) @@ -100,10 +107,15 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA iRow = ListView_InsertItem(hwndList, &item); ListView_SetItemText(hwndList, iRow, 0, name); TCHAR *tmp = mir_a2t((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); - ListView_SetItemText(hwndList, iRow, 1, tmp); + ListView_SetItemText(hwndList, iRow, 3, tmp); mir_free(tmp); tmp = UniGetContactSettingUtf(hContact, szModuleName, "GPGPubKey", _T("not set")); ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + tmp2 = GetContactSettingStringA(hContact, szModuleName, "KeyFingerprint", ""); + tmp = mir_a2t(tmp2); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 1, (_tcslen(tmp) > 1)?tmp:_T("not set")); if(DBGetContactSettingByte(hContact, szModuleName, "GPGEncryption", 0)) ListView_SetItemState(hwndList, iRow, 0x2000, 0xF000); user_data[i] = hContact; @@ -113,6 +125,7 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); return TRUE; } @@ -125,13 +138,6 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA ShowLoadPublicKeyDialog(); return TRUE; case IDC_DELETE_KEY_BUTTON: - DBDeleteContactSetting(user_data[item_num+1], szModuleName, "GPGPubKey"); - DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyFingerprint"); - DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainName"); - DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyType"); - DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainEmail"); - DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyComment"); - ListView_SetItemText(hwndList, item_num, 2, _T("not set")); { //gpg execute block TCHAR cmd[40960] = {0}; TCHAR tmp2[MAX_PATH] = {0}; @@ -153,22 +159,29 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA mir_free(tmp2); } } - if(keep) + if(!keep) { - mir_free(tmp); - break; + string output; + DWORD exitcode; + _tcscat(cmd, _T(" --batch")); + _tcscat(cmd, _T(" --yes")); + _tcscat(cmd, _T(" --delete-key ")); + ptmp = mir_a2t(tmp); + _tcscat(cmd, ptmp); + mir_free(ptmp); + pxExecute(cmd, "", &output,&exitcode); + MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK); } - string output; - DWORD exitcode; - _tcscat(cmd, _T(" --batch")); - _tcscat(cmd, _T(" --yes")); - _tcscat(cmd, _T(" --delete-key ")); - ptmp = mir_a2t(tmp); - _tcscat(cmd, ptmp); - mir_free(ptmp); - pxResult pxresult=pxExecute(cmd,"",&output,&exitcode); mir_free(tmp); } + DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyFingerprint"); + DBDeleteContactSetting(user_data[item_num+1], szModuleName, "GPGPubKey"); + DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainName"); + DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyType"); + DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainEmail"); + DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyComment"); + ListView_SetItemText(hwndList, item_num, 2, _T("not set")); + ListView_SetItemText(hwndList, item_num, 1, _T("not set")); break; default: break; @@ -338,7 +351,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); ListView_SetItemText(hwndList_p, item_num, 2, tmp); { //gpg execute block - TCHAR cmd[40960] = {0}; + TCHAR cmd[4096] = {0}; TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; string output; @@ -365,7 +378,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP _tcscat(cmd, tmp2); _tcscat(cmd, _T("\"")); } - pxResult pxresult=pxExecute(cmd,"",&output,&exitcode); + pxExecute(cmd, "", &output, &exitcode); cp866_to_cp1251(&output); { string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); @@ -431,7 +444,6 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP key_buf.clear(); break; } - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } diff --git a/resource.h b/resource.h index 569256d..c5d1d12 100644 --- a/resource.h +++ b/resource.h @@ -3,6 +3,8 @@ // Used by new_gpg.rc // #define IDD_LOAD_PUBLIC_KEY 102 +#define IDD_DIALOG1 103 +#define IDD_FIRST_RUN 103 #define IDD_OPT_GPG 104 #define IDD_OPT_GPG_BIN 105 #define IDC_SET_BIN_PATH 1016 @@ -18,14 +20,13 @@ #define IDC_PUBLIC_KEY_EDIT 1025 #define IDC_BUTTON1 1026 #define IDC_SAVE_KEY_BUTTON 1026 -#define IDC_BUTTON2 1027 #define IDC_DELETE_KEY_BUTTON 1027 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 103 +#define _APS_NEXT_RESOURCE_VALUE 104 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1028 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/utilities.cpp b/utilities.cpp index 49e0c07..e4a63c9 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -189,6 +189,13 @@ int LoadKey(WPARAM w, LPARAM l) return 0; } +int SendKey(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + //CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)szMessage); + return 0; +} + extern HANDLE hLoadPublicKey, hToggleEncryption; int ToggleEncryption(WPARAM w, LPARAM l) -- cgit v1.2.3