diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-29 03:32:07 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-29 03:32:07 +0300 |
commit | fbcc2024d5adcf4ed4aedc3ee86d7e1ce4e756d5 (patch) | |
tree | d0622283ef2a6ab5ca5444395952e39e6b65b739 | |
parent | 7ad02d9a9cd909ff8af474cdff82c2d70f7afd8f (diff) |
dos2unix
-rw-r--r-- | clist.cpp | 82 | ||||
-rw-r--r-- | gpg_wrapper.cpp | 314 | ||||
-rw-r--r-- | gpg_wrapper.h | 58 | ||||
-rw-r--r-- | icons.cpp | 172 | ||||
-rw-r--r-- | init.cpp | 484 | ||||
-rw-r--r-- | m_metacontacts.h | 332 | ||||
-rw-r--r-- | main.cpp | 2256 | ||||
-rw-r--r-- | metacontacts.cpp | 142 | ||||
-rw-r--r-- | resource.h | 148 | ||||
-rw-r--r-- | srmm.cpp | 150 | ||||
-rw-r--r-- | utilities.cpp | 620 |
11 files changed, 2379 insertions, 2379 deletions
@@ -1,41 +1,41 @@ -// Copyright © 2010 SecureIM developers (baloo and others), sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include "commonheaders.h"
-
-extern HANDLE g_hCLIcon;
-void RefreshContactListIcons(void);
-
-int onExtraImageListRebuilding(WPARAM, LPARAM)
-{
- if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_ADD_ICON) )
- RefreshContactListIcons();
- return 0;
-}
-
-
-int onExtraImageApplying(WPARAM wParam, LPARAM)
-{
- void setClistIcon(HANDLE);
- if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_SET_ICON))
- {
-// IconExtraColumn iec = {0}; //need to init this
- if( g_hCLIcon )
- setClistIcon((HANDLE)wParam);
-// ExtraIcon_SetIcon(g_hCLIcon, (HANDLE)wParam, iec.hImage);
- }
- return 0;
-}
+// Copyright © 2010 SecureIM developers (baloo and others), sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + +extern HANDLE g_hCLIcon; +void RefreshContactListIcons(void); + +int onExtraImageListRebuilding(WPARAM, LPARAM) +{ + if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_ADD_ICON) ) + RefreshContactListIcons(); + return 0; +} + + +int onExtraImageApplying(WPARAM wParam, LPARAM) +{ + void setClistIcon(HANDLE); + if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_SET_ICON)) + { +// IconExtraColumn iec = {0}; //need to init this + if( g_hCLIcon ) + setClistIcon((HANDLE)wParam); +// ExtraIcon_SetIcon(g_hCLIcon, (HANDLE)wParam, iec.hImage); + } + return 0; +} diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index 5bcf548..1a29440 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -1,161 +1,161 @@ -// Copyright © 2010 sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include "commonheaders.h"
-
-//thx gpg module from Harald Treder, Zakhar V. Bardymov
-
-
-pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result)
-{
- extern bool bDebugLog;
- extern fstream debuglog;
- BOOL success;
- STARTUPINFO sinfo = {0};
- SECURITY_ATTRIBUTES sattrs = {0};
- SECURITY_DESCRIPTOR sdesc = {0};
- PROCESS_INFORMATION pri = {0};
- HANDLE newstdin, newstdout, readstdout, writestdin;
- char *inputpos;
- unsigned long transfered;
- int size;
-
- TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T(""));
- {
- if(_waccess(bin_path, 0) == -1)
- if(errno == ENOENT)
- {
- mir_free(bin_path);
- *result = pxNotFound;
- return pxNotFound;
- }
- }
- wstring commandline;
-
- sattrs.nLength=sizeof(SECURITY_ATTRIBUTES);
- sattrs.bInheritHandle=TRUE;
- InitializeSecurityDescriptor(&sdesc,SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(&sdesc,TRUE,NULL,FALSE);
- sattrs.lpSecurityDescriptor=&sdesc;
-
- success=CreatePipe(&newstdin,&writestdin,&sattrs,0);
- if (!success)
- {
- *result = pxCreatePipeFailed;
- return pxCreatePipeFailed;
- }
-
- success=CreatePipe(&readstdout,&newstdout,&sattrs,0);
- if (!success)
- {
- CloseHandle(newstdin);
- CloseHandle(writestdin);
- *result = pxCreatePipeFailed;
- return pxCreatePipeFailed;
- }
-
- GetStartupInfo(&sinfo);
- sinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
- sinfo.wShowWindow=SW_HIDE;
- sinfo.hStdOutput=newstdout;
- sinfo.hStdError=newstdout;
- sinfo.hStdInput=newstdin;
-
- { //form initial command
- commandline += _T("\"");
- commandline += bin_path;
- commandline += _T("\" --homedir \"");
- TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- commandline += home_dir;
- commandline += _T("\" ");
- commandline += _T("--display-charset utf-8 ");
- commandline += *acommandline;
- mir_free(bin_path);
- mir_free(home_dir);
- }
-
- if(bDebugLog)
+// Copyright © 2010 sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + +//thx gpg module from Harald Treder, Zakhar V. Bardymov + + +pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result) +{ + extern bool bDebugLog; + extern fstream debuglog; + BOOL success; + STARTUPINFO sinfo = {0}; + SECURITY_ATTRIBUTES sattrs = {0}; + SECURITY_DESCRIPTOR sdesc = {0}; + PROCESS_INFORMATION pri = {0}; + HANDLE newstdin, newstdout, readstdout, writestdin; + char *inputpos; + unsigned long transfered; + int size; + + TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); + { + if(_waccess(bin_path, 0) == -1) + if(errno == ENOENT) + { + mir_free(bin_path); + *result = pxNotFound; + return pxNotFound; + } + } + wstring commandline; + + sattrs.nLength=sizeof(SECURITY_ATTRIBUTES); + sattrs.bInheritHandle=TRUE; + InitializeSecurityDescriptor(&sdesc,SECURITY_DESCRIPTOR_REVISION); + SetSecurityDescriptorDacl(&sdesc,TRUE,NULL,FALSE); + sattrs.lpSecurityDescriptor=&sdesc; + + success=CreatePipe(&newstdin,&writestdin,&sattrs,0); + if (!success) + { + *result = pxCreatePipeFailed; + return pxCreatePipeFailed; + } + + success=CreatePipe(&readstdout,&newstdout,&sattrs,0); + if (!success) + { + CloseHandle(newstdin); + CloseHandle(writestdin); + *result = pxCreatePipeFailed; + return pxCreatePipeFailed; + } + + GetStartupInfo(&sinfo); + sinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; + sinfo.wShowWindow=SW_HIDE; + sinfo.hStdOutput=newstdout; + sinfo.hStdError=newstdout; + sinfo.hStdInput=newstdin; + + { //form initial command + commandline += _T("\""); + commandline += bin_path; + commandline += _T("\" --homedir \""); + TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + commandline += home_dir; + commandline += _T("\" "); + commandline += _T("--display-charset utf-8 "); + commandline += *acommandline; + mir_free(bin_path); + mir_free(home_dir); + } + + if(bDebugLog) { char* tmp = mir_utf8encodeW(commandline.c_str()); - debuglog<<"in: "<<tmp<<"\n";
- mir_free(tmp);
- }
-
- TCHAR chNewEnv[128];
- LPTSTR lpszCurrentVariable;
- lpszCurrentVariable = (LPTSTR)chNewEnv;
- _tcscpy(lpszCurrentVariable, _T("LANGUAGE=0"));
-
-
- success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, (LPVOID)chNewEnv, NULL, &sinfo, &pri);
-
- if (!success)
- {
- CloseHandle(newstdin);
- CloseHandle(writestdin);
- CloseHandle(newstdout);
- CloseHandle(readstdout);
- *result = pxCreateProcessFailed;
- return pxCreateProcessFailed;
- }
-
- inputpos=ainput;
-
- while (TRUE)
- {
- success=GetExitCodeProcess(pri.hProcess,aexitcode);
- if (success && *aexitcode!=STILL_ACTIVE)
- break;
-
- storeOutput(readstdout,aoutput);
-
- if (*inputpos!='\0') size=1;
- else size=0;
-
- success=WriteFile(writestdin,inputpos,size,&transfered,NULL);
- inputpos+=transfered;
- Sleep(200);
- }
-
- storeOutput(readstdout,aoutput);
-
- if(bDebugLog)
+ debuglog<<"in: "<<tmp<<"\n"; + mir_free(tmp); + } + + TCHAR chNewEnv[128]; + LPTSTR lpszCurrentVariable; + lpszCurrentVariable = (LPTSTR)chNewEnv; + _tcscpy(lpszCurrentVariable, _T("LANGUAGE=0")); + + + success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, (LPVOID)chNewEnv, NULL, &sinfo, &pri); + + if (!success) + { + CloseHandle(newstdin); + CloseHandle(writestdin); + CloseHandle(newstdout); + CloseHandle(readstdout); + *result = pxCreateProcessFailed; + return pxCreateProcessFailed; + } + + inputpos=ainput; + + while (TRUE) + { + success=GetExitCodeProcess(pri.hProcess,aexitcode); + if (success && *aexitcode!=STILL_ACTIVE) + break; + + storeOutput(readstdout,aoutput); + + if (*inputpos!='\0') size=1; + else size=0; + + success=WriteFile(writestdin,inputpos,size,&transfered,NULL); + inputpos+=transfered; + Sleep(200); + } + + storeOutput(readstdout,aoutput); + + if(bDebugLog) + { + debuglog<<"out: "<<aoutput->c_str()<<"\n"; + } + + WaitForSingleObject(pri.hProcess,INFINITE); + + CloseHandle(pri.hThread); + CloseHandle(pri.hProcess); + CloseHandle(newstdin); + CloseHandle(newstdout); + CloseHandle(readstdout); + CloseHandle(writestdin); + + *result = pxSuccess; + return pxSuccess; +} + +void pxEexcute_thread(void *param) +{ + gpg_execution_params *params = (gpg_execution_params*)param; + pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result); + if(result == pxNotFound) { - debuglog<<"out: "<<aoutput->c_str()<<"\n";
- }
-
- WaitForSingleObject(pri.hProcess,INFINITE);
-
- CloseHandle(pri.hThread);
- CloseHandle(pri.hProcess);
- CloseHandle(newstdin);
- CloseHandle(newstdout);
- CloseHandle(readstdout);
- CloseHandle(writestdin);
-
- *result = pxSuccess;
- return pxSuccess;
-}
-
-void pxEexcute_thread(void *param)
-{
- gpg_execution_params *params = (gpg_execution_params*)param;
- pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result);
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- }
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + } }
\ No newline at end of file diff --git a/gpg_wrapper.h b/gpg_wrapper.h index 6b0baea..5d0ce2a 100644 --- a/gpg_wrapper.h +++ b/gpg_wrapper.h @@ -1,30 +1,30 @@ -#ifndef GPG_WRAPPER_H
-#define GPG_WRAPPER_H
-typedef enum {
- pxSuccess,
- pxSuccessExitCodeInvalid,
- pxCreatePipeFailed,
- pxDuplicateHandleFailed,
- pxCloseHandleFailed,
- pxCreateProcessFailed,
- pxThreadWaitFailed,
- pxReadFileFailed,
- pxBufferOverflow,
- pxNotFound
-}
-pxResult;
-
-pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result);
-
-struct gpg_execution_params
-{
- wstring *cmd;
- char *useless;
- string *out;
- LPDWORD code;
- pxResult *result;
-};
-
-void pxEexcute_thread(void *param);
-
+#ifndef GPG_WRAPPER_H +#define GPG_WRAPPER_H +typedef enum { + pxSuccess, + pxSuccessExitCodeInvalid, + pxCreatePipeFailed, + pxDuplicateHandleFailed, + pxCloseHandleFailed, + pxCreateProcessFailed, + pxThreadWaitFailed, + pxReadFileFailed, + pxBufferOverflow, + pxNotFound +} +pxResult; + +pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result); + +struct gpg_execution_params +{ + wstring *cmd; + char *useless; + string *out; + LPDWORD code; + pxResult *result; +}; + +void pxEexcute_thread(void *param); + #endif
\ No newline at end of file @@ -1,21 +1,21 @@ -// Copyright © 2010 SecureIM developers (baloo and others), sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include "commonheaders.h"
-
+// Copyright © 2010 SecureIM developers (baloo and others), sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + HANDLE IconLibDefine(TCHAR* desc, TCHAR* section, char* ident, HICON icon, char* def_file, int def_idx, int size) { SKINICONDESC sid = {0}; @@ -39,8 +39,8 @@ HANDLE IconLibDefine(TCHAR* desc, TCHAR* section, char* ident, HICON icon, char* return hIcon; } -
-
+ + void InitIconLib() { extern HINSTANCE hInst; @@ -75,69 +75,69 @@ HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook) { return HookEvent(ME_SKIN2_ICONSCHANGED, hook); } -
-
-void setClistIcon(HANDLE hContact)
-{
- bool enabled = isContactSecured(hContact);
- extern HANDLE g_hCLIcon;
- HANDLE hMC = metaGetContact(hContact);
- if(g_hCLIcon && enabled)
- { // обновить иконки в clist
- HICON icon = IconLibGetIcon("secured");
- IconExtraColumn iec = {0};
- iec.cbSize = sizeof(iec);
- iec.hImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)icon, (LPARAM)0);
- ExtraIcon_SetIcon(g_hCLIcon, hContact, iec.hImage);
- if(hMC)
- ExtraIcon_SetIcon(g_hCLIcon, hMC, iec.hImage);
- }
- else
- {
- ExtraIcon_SetIcon(g_hCLIcon, hContact, (HANDLE)0); // is it right ? hmm.., at least working....
- if(hMC)
- ExtraIcon_SetIcon(g_hCLIcon, hMC, (HANDLE)0);
- }
-}
-
-void setSrmmIcon(HANDLE hContact)
-{
- bool enabled = isContactSecured(hContact);
- HANDLE hMC = metaGetContact(hContact);
- if(ServiceExists(MS_MSG_MODIFYICON))
- { // обновить иконки в srmm
- StatusIconData sid = {0};
- sid.cbSize = sizeof(sid);
- sid.szModule = szGPGModuleName;
- sid.hIcon = IconLibGetIcon("secured");
- sid.dwId = 0x00000001;
- sid.flags = enabled?0:MBF_HIDDEN;
- CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
- if( hMC )
- CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid);
- ZeroMemory(&sid, sizeof(sid));
- sid.cbSize = sizeof(sid);
- sid.szModule = szGPGModuleName;
- sid.hIcon = IconLibGetIcon("unsecured");
- sid.dwId = 0x00000002;
- sid.flags = enabled?MBF_HIDDEN:0;
- CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
- if( hMC )
- CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid);
- }
-}
-
-
-void RefreshContactListIcons()
-{
- HANDLE hContact;
- extern HANDLE g_hCLIcon;
- CallService(MS_CLUI_LISTBEGINREBUILD,0,0);
- hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
- while (hContact)
- {
- setClistIcon(hContact);
- hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0);
- }
- CallService(MS_CLUI_LISTENDREBUILD,0,0);
-}
+ + +void setClistIcon(HANDLE hContact) +{ + bool enabled = isContactSecured(hContact); + extern HANDLE g_hCLIcon; + HANDLE hMC = metaGetContact(hContact); + if(g_hCLIcon && enabled) + { // обновить иконки в clist + HICON icon = IconLibGetIcon("secured"); + IconExtraColumn iec = {0}; + iec.cbSize = sizeof(iec); + iec.hImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)icon, (LPARAM)0); + ExtraIcon_SetIcon(g_hCLIcon, hContact, iec.hImage); + if(hMC) + ExtraIcon_SetIcon(g_hCLIcon, hMC, iec.hImage); + } + else + { + ExtraIcon_SetIcon(g_hCLIcon, hContact, (HANDLE)0); // is it right ? hmm.., at least working.... + if(hMC) + ExtraIcon_SetIcon(g_hCLIcon, hMC, (HANDLE)0); + } +} + +void setSrmmIcon(HANDLE hContact) +{ + bool enabled = isContactSecured(hContact); + HANDLE hMC = metaGetContact(hContact); + if(ServiceExists(MS_MSG_MODIFYICON)) + { // обновить иконки в srmm + StatusIconData sid = {0}; + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.hIcon = IconLibGetIcon("secured"); + sid.dwId = 0x00000001; + sid.flags = enabled?0:MBF_HIDDEN; + CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); + if( hMC ) + CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); + ZeroMemory(&sid, sizeof(sid)); + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.hIcon = IconLibGetIcon("unsecured"); + sid.dwId = 0x00000002; + sid.flags = enabled?MBF_HIDDEN:0; + CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); + if( hMC ) + CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); + } +} + + +void RefreshContactListIcons() +{ + HANDLE hContact; + extern HANDLE g_hCLIcon; + CallService(MS_CLUI_LISTBEGINREBUILD,0,0); + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + while (hContact) + { + setClistIcon(hContact); + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); + } + CallService(MS_CLUI_LISTENDREBUILD,0,0); +} @@ -1,242 +1,242 @@ -// Copyright © 2010 sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include "commonheaders.h"
-
-//global variables
-bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bIsMiranda09 = false, bMetaContacts = false;
-TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL;
-
-list <JabberAccount*> Accounts;
-
-HINSTANCE hInst;
-HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL;
-PLUGINLINK *pluginLink;
-IconExtraColumn g_IEC = {0};
-static int OnModulesLoaded(WPARAM wParam,LPARAM lParam);
-extern char *date();
-MM_INTERFACE mmi = {0};
-UTF8_INTERFACE utfi = {0};
-XML_API xi = {0};
-fstream debuglog;
-
-
-#define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } }
-
-PLUGININFOEX pluginInfo={
- sizeof(PLUGININFOEX),
- 0,
- PLUGIN_MAKE_VERSION(0,0,0,4),
- "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485",
- "sss",
- "sss123next@list.ru",
- "© 2010 sss",
- "http://sss.chaoslab.ru/tracker/mim_plugs/",
- 1, //unicode
- 0, //doesn't replace anything built-in
- MIID_GPG
-};
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
-{
- hInst=hinstDLL;
- return TRUE;
-}
-
-
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
-{
- static char plugname[52];
- strcpy(plugname, szGPGModuleName" [");
- strcat(plugname, date());
- strcat(plugname, " ");
- strcat(plugname, __TIME__);
- strcat(plugname, "]");
- pluginInfo.shortName = plugname;
- return &pluginInfo;
-}
-
-static const MUUID interfaces[] = {MIID_GPG, MIID_LAST};
-extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
-{
- return interfaces;
-}
-
-int LoadKey(WPARAM w, LPARAM l);
-int ToggleEncryption(WPARAM w, LPARAM l);
-int SendKey(WPARAM w, LPARAM l);
-
-void init_vars()
-{
- bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 0);
- inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("<GPGdec>"));
- inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("</GPGdec>"));
- outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>"));
- outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>"));
- bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0);
- bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", 1);
- if(bDebugLog)
- {
- TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\gpglog.txt"));
- debuglog.open(tmp, std::ios::app |std::ios::ate |std::ios::binary);
-// mir_free(tmp);
- }
-}
-
-extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
-{
- pluginLink=link;
- init_vars();
- HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
- mir_getMMI(&mmi);
- mir_getUTFI(&utfi);
- mir_getXI(&xi); //TODO: check if we have access to api
- CreateServiceFunction("/LoadPubKey",LoadKey);
- CreateServiceFunction("/ToggleEncryption",ToggleEncryption);
- CreateServiceFunction("/SendKey",SendKey);
- CLISTMENUITEM mi = {0};
- mi.cbSize=sizeof(mi);
- mi.position=-0x7FFFFFFF;
- mi.flags=0;
- mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
- mi.pszName="Load GPG public key";
- mi.pszService="/LoadPubKey";
- hLoadPubKey = (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="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;
-}
-
-int AddContact(WPARAM w, LPARAM l)
-{
- CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szGPGModuleName);
- return 0;
-}
-
-
-static int OnModulesLoaded(WPARAM wParam,LPARAM lParam)
-{
-
- int GpgOptInit(WPARAM wParam,LPARAM lParam);
- int OnPreBuildContactMenu(WPARAM w, LPARAM l);
- int RecvMsgSvc(WPARAM w, LPARAM l);
- int SendMsgSvc(WPARAM w, LPARAM l);
- int HookSendMsg(WPARAM w, LPARAM l);
-// int TestHook(WPARAM w, LPARAM l);
- int GetJabberInterface(WPARAM w, LPARAM l);
- int onWindowEvent(WPARAM wParam, LPARAM lParam);
- int onIconPressed(WPARAM wParam, LPARAM lParam);
- int onExtraImageListRebuilding(WPARAM, LPARAM);
- int onExtraImageApplying(WPARAM wParam, LPARAM);
- void InitIconLib();
-
- void InitCheck();
- void FirstRun();
- FirstRun();
- InitCheck();
- InitIconLib();
- if(ServiceExists(MS_MSG_ADDICON))
- {
- HICON IconLibGetIcon(const char* ident);
- StatusIconData sid = {0};
- sid.cbSize = sizeof(sid);
- sid.szModule = szGPGModuleName;
- sid.flags = MBF_HIDDEN;
- sid.dwId = 0x00000001;
- sid.hIcon = IconLibGetIcon("secured");
- sid.szTooltip = Translate("GPG Turn off encryption");
- CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid);
- ZeroMemory(&sid, sizeof(sid));
- sid.cbSize = sizeof(sid);
- sid.szModule = szGPGModuleName;
- sid.flags = MBF_HIDDEN;
- sid.dwId = 0x00000002;
- sid.hIcon = IconLibGetIcon("unsecured");
- sid.szTooltip = Translate("GPG Turn on encryption");
- CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid);
- }
-
-
- bIsMiranda09 = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0) >= 0x00090001?true:false;
- bMetaContacts = ServiceExists(MS_MC_GETMETACONTACT);
-
- if(bJabberAPI && bIsMiranda09)
- GetJabberInterface(0,0);
-
- HookEvent(ME_OPT_INITIALISE, GpgOptInit);
- HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg);
- if(bJabberAPI && bIsMiranda09)
- HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface);
-
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu);
-
- HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent);
- HookEvent(ME_MSG_ICONPRESSED, onIconPressed);
-
- if(ServiceExists(MS_EXTRAICON_REGISTER))
- g_hCLIcon = ExtraIcon_Register(szGPGModuleName, Translate("GPG encryption status"), "secured", (MIRANDAHOOK)onExtraImageListRebuilding, (MIRANDAHOOK)onExtraImageApplying);
-
-
-
- PROTOCOLDESCRIPTOR pd = {0};
- pd.cbSize=sizeof(PROTOCOLDESCRIPTOR);
- pd.szName=szGPGModuleName;
- pd.type=PROTOTYPE_ENCRYPTION;
- CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
-
- CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE,RecvMsgSvc);
- CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE,SendMsgSvc);
- CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE"W",RecvMsgSvc);
- CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE"W",SendMsgSvc);
-
- for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
- if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName))
- CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName);
-
- HookEvent(ME_DB_CONTACT_ADDED,AddContact);
-
-
-
- return 0;
-}
-
-
-extern "C" int __declspec(dllexport) Unload(void)
-{
- mir_free(inopentag);
- mir_free(inclosetag);
- mir_free(outopentag);
- mir_free(outclosetag);
- if(password)
- delete [] password;
- if(debuglog.is_open())
- debuglog.close();
- return 0;
-}
+// Copyright © 2010 sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + +//global variables +bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bIsMiranda09 = false, bMetaContacts = false; +TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL; + +list <JabberAccount*> Accounts; + +HINSTANCE hInst; +HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL; +PLUGINLINK *pluginLink; +IconExtraColumn g_IEC = {0}; +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); +extern char *date(); +MM_INTERFACE mmi = {0}; +UTF8_INTERFACE utfi = {0}; +XML_API xi = {0}; +fstream debuglog; + + +#define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } + +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + 0, + PLUGIN_MAKE_VERSION(0,0,0,4), + "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485", + "sss", + "sss123next@list.ru", + "© 2010 sss", + "http://sss.chaoslab.ru/tracker/mim_plugs/", + 1, //unicode + 0, //doesn't replace anything built-in + MIID_GPG +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + static char plugname[52]; + strcpy(plugname, szGPGModuleName" ["); + strcat(plugname, date()); + strcat(plugname, " "); + strcat(plugname, __TIME__); + strcat(plugname, "]"); + pluginInfo.shortName = plugname; + return &pluginInfo; +} + +static const MUUID interfaces[] = {MIID_GPG, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) +{ + return interfaces; +} + +int LoadKey(WPARAM w, LPARAM l); +int ToggleEncryption(WPARAM w, LPARAM l); +int SendKey(WPARAM w, LPARAM l); + +void init_vars() +{ + bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 0); + inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("<GPGdec>")); + inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("</GPGdec>")); + outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>")); + outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>")); + bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0); + bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", 1); + if(bDebugLog) + { + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\gpglog.txt")); + debuglog.open(tmp, std::ios::app |std::ios::ate |std::ios::binary); +// mir_free(tmp); + } +} + +extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) +{ + pluginLink=link; + init_vars(); + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + mir_getMMI(&mmi); + mir_getUTFI(&utfi); + mir_getXI(&xi); //TODO: check if we have access to api + CreateServiceFunction("/LoadPubKey",LoadKey); + CreateServiceFunction("/ToggleEncryption",ToggleEncryption); + CreateServiceFunction("/SendKey",SendKey); + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Load GPG public key"; + mi.pszService="/LoadPubKey"; + hLoadPubKey = (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="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; +} + +int AddContact(WPARAM w, LPARAM l) +{ + CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szGPGModuleName); + return 0; +} + + +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) +{ + + int GpgOptInit(WPARAM wParam,LPARAM lParam); + int OnPreBuildContactMenu(WPARAM w, LPARAM l); + int RecvMsgSvc(WPARAM w, LPARAM l); + int SendMsgSvc(WPARAM w, LPARAM l); + int HookSendMsg(WPARAM w, LPARAM l); +// int TestHook(WPARAM w, LPARAM l); + int GetJabberInterface(WPARAM w, LPARAM l); + int onWindowEvent(WPARAM wParam, LPARAM lParam); + int onIconPressed(WPARAM wParam, LPARAM lParam); + int onExtraImageListRebuilding(WPARAM, LPARAM); + int onExtraImageApplying(WPARAM wParam, LPARAM); + void InitIconLib(); + + void InitCheck(); + void FirstRun(); + FirstRun(); + InitCheck(); + InitIconLib(); + if(ServiceExists(MS_MSG_ADDICON)) + { + HICON IconLibGetIcon(const char* ident); + StatusIconData sid = {0}; + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000001; + sid.hIcon = IconLibGetIcon("secured"); + sid.szTooltip = Translate("GPG Turn off encryption"); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + ZeroMemory(&sid, sizeof(sid)); + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000002; + sid.hIcon = IconLibGetIcon("unsecured"); + sid.szTooltip = Translate("GPG Turn on encryption"); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + } + + + bIsMiranda09 = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0) >= 0x00090001?true:false; + bMetaContacts = ServiceExists(MS_MC_GETMETACONTACT); + + if(bJabberAPI && bIsMiranda09) + GetJabberInterface(0,0); + + HookEvent(ME_OPT_INITIALISE, GpgOptInit); + HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); + if(bJabberAPI && bIsMiranda09) + HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); + + HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent); + HookEvent(ME_MSG_ICONPRESSED, onIconPressed); + + if(ServiceExists(MS_EXTRAICON_REGISTER)) + g_hCLIcon = ExtraIcon_Register(szGPGModuleName, Translate("GPG encryption status"), "secured", (MIRANDAHOOK)onExtraImageListRebuilding, (MIRANDAHOOK)onExtraImageApplying); + + + + PROTOCOLDESCRIPTOR pd = {0}; + pd.cbSize=sizeof(PROTOCOLDESCRIPTOR); + pd.szName=szGPGModuleName; + pd.type=PROTOTYPE_ENCRYPTION; + CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); + + CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE,RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE,SendMsgSvc); + CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE"W",RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE"W",SendMsgSvc); + + for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName)) + CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName); + + HookEvent(ME_DB_CONTACT_ADDED,AddContact); + + + + return 0; +} + + +extern "C" int __declspec(dllexport) Unload(void) +{ + mir_free(inopentag); + mir_free(inclosetag); + mir_free(outopentag); + mir_free(outclosetag); + if(password) + delete [] password; + if(debuglog.is_open()) + debuglog.close(); + return 0; +} diff --git a/m_metacontacts.h b/m_metacontacts.h index 9f348bd..b4f63ea 100644 --- a/m_metacontacts.h +++ b/m_metacontacts.h @@ -1,166 +1,166 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-
-Copyright © 2004 Universite Louis PASTEUR, STRASBOURG.
-Copyright © 2004 Scott Ellis (www.scottellis.com.au mail@scottellis.com.au)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#ifndef M_METACONTACTS_H__
-#define M_METACONTACTS_H__ 1
-
-#ifndef MIID_METACONTACTS
-#define MIID_METACONTACTS {0xc0325019, 0xc1a7, 0x40f5, { 0x83, 0x65, 0x4f, 0x46, 0xbe, 0x21, 0x86, 0x3e}}
-#endif
-
-//get the handle for a contact's parent metacontact
-//wParam=(HANDLE)hSubContact
-//lParam=0
-//returns a handle to the parent metacontact, or null if this contact is not a subcontact
-#define MS_MC_GETMETACONTACT "MetaContacts/GetMeta"
-
-//gets the handle for the default contact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a handle to the default contact, or null on failure
-#define MS_MC_GETDEFAULTCONTACT "MetaContacts/GetDefault"
-
-//gets the contact number for the default contact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a DWORD contact number, or -1 on failure
-#define MS_MC_GETDEFAULTCONTACTNUM "MetaContacts/GetDefaultNum"
-
-//gets the handle for the 'most online' contact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a handle to the 'most online' contact
-#define MS_MC_GETMOSTONLINECONTACT "MetaContacts/GetMostOnline"
-
-//gets the number of subcontacts for a metacontact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a DWORD representing the number of subcontacts for the given metacontact
-#define MS_MC_GETNUMCONTACTS "MetaContacts/GetNumContacts"
-
-//gets the handle of a subcontact, using the subcontact's number
-//wParam=(HANDLE)hMetaContact
-//lParam=(DWORD)contact number
-//returns a handle to the specified subcontact
-#define MS_MC_GETSUBCONTACT "MetaContacts/GetSubContact"
-
-//sets the default contact, using the subcontact's contact number
-//wParam=(HANDLE)hMetaContact
-//lParam=(DWORD)contact number
-//returns 0 on success
-#define MS_MC_SETDEFAULTCONTACTNUM "MetaContacts/SetDefault"
-
-//sets the default contact, using the subcontact's handle
-//wParam=(HANDLE)hMetaContact
-//lParam=(HANDLE)hSubcontact
-//returns 0 on success
-#define MS_MC_SETDEFAULTCONTACT "MetaContacts/SetDefaultByHandle"
-
-//forces the metacontact to send using a specific subcontact, using the subcontact's contact number
-//wParam=(HANDLE)hMetaContact
-//lParam=(DWORD)contact number
-//returns 0 on success
-#define MS_MC_FORCESENDCONTACTNUM "MetaContacts/ForceSendContact"
-
-//forces the metacontact to send using a specific subcontact, using the subcontact's handle
-//wParam=(HANDLE)hMetaContact
-//lParam=(HANDLE)hSubcontact
-//returns 0 on success (will fail if 'force default' is in effect)
-#define MS_MC_FORCESENDCONTACT "MetaContacts/ForceSendContactByHandle"
-
-//'unforces' the metacontact to send using a specific subcontact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns 0 on success (will fail if 'force default' is in effect)
-#define MS_MC_UNFORCESENDCONTACT "MetaContacts/UnforceSendContact"
-
-//'forces' or 'unforces' (i.e. toggles) the metacontact to send using it's default contact
-// overrides (and clears) 'force send' above, and will even force use of offline contacts
-// will send ME_MC_FORCESEND or ME_MC_UNFORCESEND event
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns 1(true) or 0(false) representing new state of 'force default'
-#define MS_MC_FORCEDEFAULT "MetaContacts/ForceSendDefault"
-
-// method to get state of 'force' for a metacontact
-// wParam=(HANDLE)hMetaContact
-// lParam= (DWORD)&contact_number or NULL
-//
-// if lparam supplied, the contact_number of the contatct 'in force' will be copied to the address it points to,
-// or if none is in force, the value (DWORD)-1 will be copied
-// (v0.8.0.8+ returns 1 if 'force default' is true with *lParam == default contact number, else returns 0 with *lParam as above)
-#define MS_MC_GETFORCESTATE "MetaContacts/GetForceState"
-
-// fired when a metacontact's default contact changes (fired upon creation of metacontact also, when default is initially set)
-// wParam=(HANDLE)hMetaContact
-// lParam=(HANDLE)hDefaultContact
-#define ME_MC_DEFAULTTCHANGED "MetaContacts/DefaultChanged"
-
-// fired when a metacontact's subcontacts change (fired upon creation of metacontact, when contacts are added or removed, and when
-// contacts are reordered) - a signal to re-read metacontact data
-// wParam=(HANDLE)hMetaContact
-// lParam=0
-#define ME_MC_SUBCONTACTSCHANGED "MetaContacts/SubcontactsChanged"
-
-// fired when a metacontact is forced to send using a specific subcontact
-// wParam=(HANDLE)hMetaContact
-// lParam=(HANDLE)hForceContact
-#define ME_MC_FORCESEND "MetaContacts/ForceSend"
-
-// fired when a metacontact is 'unforced' to send using a specific subcontact
-// wParam=(HANDLE)hMetaContact
-// lParam=0
-#define ME_MC_UNFORCESEND "MetaContacts/UnforceSend"
-
-// method to get protocol name - used to be sure you're dealing with a "real" metacontacts plugin :)
-// wParam=lParam=0
-#define MS_MC_GETPROTOCOLNAME "MetaContacts/GetProtoName"
-
-
-// added 0.9.5.0 (22/3/05)
-// wParam=(HANDLE)hContact
-// lParam=0
-// convert a given contact into a metacontact
-#define MS_MC_CONVERTTOMETA "MetaContacts/ConvertToMetacontact"
-
-// added 0.9.5.0 (22/3/05)
-// wParam=(HANDLE)hContact
-// lParam=(HANDLE)hMeta
-// add an existing contact to a metacontact
-#define MS_MC_ADDTOMETA "MetaContacts/AddToMetacontact"
-
-// added 0.9.5.0 (22/3/05)
-// wParam=0
-// lParam=(HANDLE)hContact
-// remove a contact from a metacontact
-#define MS_MC_REMOVEFROMMETA "MetaContacts/RemoveFromMetacontact"
-
-
-// added 0.9.13.2 (6/10/05)
-// wParam=(BOOL)disable
-// lParam=0
-// enable/disable the 'hidden group hack' - for clists that support subcontact hiding using 'IsSubcontact' setting
-// should be called once in the clist 'onmodulesloaded' event handler (which, since it's loaded after the db, will be called
-// before the metacontact onmodulesloaded handler where the subcontact hiding is usually done)
-#define MS_MC_DISABLEHIDDENGROUP "MetaContacts/DisableHiddenGroup"
-
-#endif
+/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright © 2004 Universite Louis PASTEUR, STRASBOURG. +Copyright © 2004 Scott Ellis (www.scottellis.com.au mail@scottellis.com.au) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef M_METACONTACTS_H__ +#define M_METACONTACTS_H__ 1 + +#ifndef MIID_METACONTACTS +#define MIID_METACONTACTS {0xc0325019, 0xc1a7, 0x40f5, { 0x83, 0x65, 0x4f, 0x46, 0xbe, 0x21, 0x86, 0x3e}} +#endif + +//get the handle for a contact's parent metacontact +//wParam=(HANDLE)hSubContact +//lParam=0 +//returns a handle to the parent metacontact, or null if this contact is not a subcontact +#define MS_MC_GETMETACONTACT "MetaContacts/GetMeta" + +//gets the handle for the default contact +//wParam=(HANDLE)hMetaContact +//lParam=0 +//returns a handle to the default contact, or null on failure +#define MS_MC_GETDEFAULTCONTACT "MetaContacts/GetDefault" + +//gets the contact number for the default contact +//wParam=(HANDLE)hMetaContact +//lParam=0 +//returns a DWORD contact number, or -1 on failure +#define MS_MC_GETDEFAULTCONTACTNUM "MetaContacts/GetDefaultNum" + +//gets the handle for the 'most online' contact +//wParam=(HANDLE)hMetaContact +//lParam=0 +//returns a handle to the 'most online' contact +#define MS_MC_GETMOSTONLINECONTACT "MetaContacts/GetMostOnline" + +//gets the number of subcontacts for a metacontact +//wParam=(HANDLE)hMetaContact +//lParam=0 +//returns a DWORD representing the number of subcontacts for the given metacontact +#define MS_MC_GETNUMCONTACTS "MetaContacts/GetNumContacts" + +//gets the handle of a subcontact, using the subcontact's number +//wParam=(HANDLE)hMetaContact +//lParam=(DWORD)contact number +//returns a handle to the specified subcontact +#define MS_MC_GETSUBCONTACT "MetaContacts/GetSubContact" + +//sets the default contact, using the subcontact's contact number +//wParam=(HANDLE)hMetaContact +//lParam=(DWORD)contact number +//returns 0 on success +#define MS_MC_SETDEFAULTCONTACTNUM "MetaContacts/SetDefault" + +//sets the default contact, using the subcontact's handle +//wParam=(HANDLE)hMetaContact +//lParam=(HANDLE)hSubcontact +//returns 0 on success +#define MS_MC_SETDEFAULTCONTACT "MetaContacts/SetDefaultByHandle" + +//forces the metacontact to send using a specific subcontact, using the subcontact's contact number +//wParam=(HANDLE)hMetaContact +//lParam=(DWORD)contact number +//returns 0 on success +#define MS_MC_FORCESENDCONTACTNUM "MetaContacts/ForceSendContact" + +//forces the metacontact to send using a specific subcontact, using the subcontact's handle +//wParam=(HANDLE)hMetaContact +//lParam=(HANDLE)hSubcontact +//returns 0 on success (will fail if 'force default' is in effect) +#define MS_MC_FORCESENDCONTACT "MetaContacts/ForceSendContactByHandle" + +//'unforces' the metacontact to send using a specific subcontact +//wParam=(HANDLE)hMetaContact +//lParam=0 +//returns 0 on success (will fail if 'force default' is in effect) +#define MS_MC_UNFORCESENDCONTACT "MetaContacts/UnforceSendContact" + +//'forces' or 'unforces' (i.e. toggles) the metacontact to send using it's default contact +// overrides (and clears) 'force send' above, and will even force use of offline contacts +// will send ME_MC_FORCESEND or ME_MC_UNFORCESEND event +//wParam=(HANDLE)hMetaContact +//lParam=0 +//returns 1(true) or 0(false) representing new state of 'force default' +#define MS_MC_FORCEDEFAULT "MetaContacts/ForceSendDefault" + +// method to get state of 'force' for a metacontact +// wParam=(HANDLE)hMetaContact +// lParam= (DWORD)&contact_number or NULL +// +// if lparam supplied, the contact_number of the contatct 'in force' will be copied to the address it points to, +// or if none is in force, the value (DWORD)-1 will be copied +// (v0.8.0.8+ returns 1 if 'force default' is true with *lParam == default contact number, else returns 0 with *lParam as above) +#define MS_MC_GETFORCESTATE "MetaContacts/GetForceState" + +// fired when a metacontact's default contact changes (fired upon creation of metacontact also, when default is initially set) +// wParam=(HANDLE)hMetaContact +// lParam=(HANDLE)hDefaultContact +#define ME_MC_DEFAULTTCHANGED "MetaContacts/DefaultChanged" + +// fired when a metacontact's subcontacts change (fired upon creation of metacontact, when contacts are added or removed, and when +// contacts are reordered) - a signal to re-read metacontact data +// wParam=(HANDLE)hMetaContact +// lParam=0 +#define ME_MC_SUBCONTACTSCHANGED "MetaContacts/SubcontactsChanged" + +// fired when a metacontact is forced to send using a specific subcontact +// wParam=(HANDLE)hMetaContact +// lParam=(HANDLE)hForceContact +#define ME_MC_FORCESEND "MetaContacts/ForceSend" + +// fired when a metacontact is 'unforced' to send using a specific subcontact +// wParam=(HANDLE)hMetaContact +// lParam=0 +#define ME_MC_UNFORCESEND "MetaContacts/UnforceSend" + +// method to get protocol name - used to be sure you're dealing with a "real" metacontacts plugin :) +// wParam=lParam=0 +#define MS_MC_GETPROTOCOLNAME "MetaContacts/GetProtoName" + + +// added 0.9.5.0 (22/3/05) +// wParam=(HANDLE)hContact +// lParam=0 +// convert a given contact into a metacontact +#define MS_MC_CONVERTTOMETA "MetaContacts/ConvertToMetacontact" + +// added 0.9.5.0 (22/3/05) +// wParam=(HANDLE)hContact +// lParam=(HANDLE)hMeta +// add an existing contact to a metacontact +#define MS_MC_ADDTOMETA "MetaContacts/AddToMetacontact" + +// added 0.9.5.0 (22/3/05) +// wParam=0 +// lParam=(HANDLE)hContact +// remove a contact from a metacontact +#define MS_MC_REMOVEFROMMETA "MetaContacts/RemoveFromMetacontact" + + +// added 0.9.13.2 (6/10/05) +// wParam=(BOOL)disable +// lParam=0 +// enable/disable the 'hidden group hack' - for clists that support subcontact hiding using 'IsSubcontact' setting +// should be called once in the clist 'onmodulesloaded' event handler (which, since it's loaded after the db, will be called +// before the metacontact onmodulesloaded handler where the subcontact hiding is usually done) +#define MS_MC_DISABLEHIDDENGROUP "MetaContacts/DisableHiddenGroup" + +#endif @@ -1,948 +1,948 @@ -// Copyright © 2010 sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
-
-
-#include "commonheaders.h"
-
-
-HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL, hwndKeyGen = NULL, hwndSelectExistingKey = NULL;
-
-int itemnum = 0;
-
-HWND hwndList_g = NULL;
-
-static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
-{
- HWND hwndList=GetDlgItem(hwndDlg, IDC_KEY_LIST);
- hwndList_g = hwndList;
- LVCOLUMN col = {0};
- LVITEM item = {0};
- NMLISTVIEW * hdr = (NMLISTVIEW *) lParam;
- TCHAR fp[16] = {0};
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- col.pszText = _T("Key ID");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 50;
- ListView_InsertColumn(hwndList, 0, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Email");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 30;
- ListView_InsertColumn(hwndList, 1, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Name");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 250;
- ListView_InsertColumn(hwndList, 2, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Creation date");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 30;
- ListView_InsertColumn(hwndList, 3, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Key length");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 30;
- ListView_InsertColumn(hwndList, 4, &col);
- ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT);
- int i = 1, iRow = 0;
- {
- item.mask = LVIF_TEXT;
- item.iItem = i;
- item.iSubItem = 0;
- item.pszText = _T("");
- {//parse gpg output
- string out;
- DWORD code;
- pxResult result;
- wstring::size_type p = 0, p2 = 0, stop = 0;
- {
- gpg_execution_params params;
- wstring cmd = _T("--batch --list-secret-keys");
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
- }
- }
- while(p != string::npos)
- {
- if((p = out.find("sec ", p)) == string::npos)
- break;
- p += 5;
- if(p < stop)
- break;
- stop = p;
- p2 = out.find("/", p) - 1;
- TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- item.pszText = tmp;
- iRow = ListView_InsertItem(hwndList, &item);
- ListView_SetItemText(hwndList, iRow, 4, tmp);
- mir_free(tmp);
- p2+=2;
- p = out.find(" ", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList, iRow, 0, tmp);
- mir_free(tmp);
- p = out.find("uid ", p);
- p2 = out.find_first_not_of(" ", p+5);
- p = out.find("<", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList, iRow, 2, tmp);
- mir_free(tmp);
- p++;
- p2 = out.find(">", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- ListView_SetItemText(hwndList, iRow, 1, tmp);
- mir_free(tmp);
- p = out.find("ssb ", p2) + 6;
- p = out.find(" ", p) + 1;
- p2 = out.find("\n", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str());
- ListView_SetItemText(hwndList, iRow, 3, tmp);
- mir_free(tmp);
- 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);
- ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE);
- i++;
- }
- }
- }
-
- return TRUE;
- }
-
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDC_GENERATE_KEY:
- void ShowKeyGenDialog();
- ShowKeyGenDialog();
- break;
- case ID_OK:
- ListView_GetItemText(hwndList, itemnum, 0, fp, 16);
- {
- string out;
- DWORD code;
- wstring cmd = _T("--batch -a --export ");
- cmd += fp;
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
- }
- string::size_type s = 0;
- while((s = out.find("\r", s)) != string::npos)
- {
- out.erase(s, 1);
- }
- DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str());
- }
- DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp);
- TCHAR passwd[64];
- GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, passwd, 64);
- if(_tcslen(passwd) > 0)
- DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", passwd);
- else
- DBDeleteContactSetting(NULL, szGPGModuleName, "szKeyPassword");
- DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0);
- DestroyWindow(hwndDlg);
- break;
- case IDC_OTHER:
- {
- void ShowLoadPublicKeyDialog();
- extern map<int, HANDLE> user_data;
- extern int item_num;
- item_num = 0; //black magic here
- user_data[1] = 0;
- ShowLoadPublicKeyDialog();
- ListView_DeleteAllItems(hwndList);
- {
- int i = 1, iRow = 0;
- item.mask = LVIF_TEXT;
- item.iItem = i;
- item.iSubItem = 0;
- item.pszText = _T("");
- {//parse gpg output
- string out;
- DWORD code;
- wstring::size_type p = 0, p2 = 0, stop = 0;
- {
- wstring cmd = _T("--batch --list-secret-keys");
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
- }
- }
- while(p != string::npos)
- {
- if((p = out.find("sec ", p)) == string::npos)
- break;
- p += 5;
- if(p < stop)
- break;
- stop = p;
- p2 = out.find("/", p) - 1;
- TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- item.pszText = tmp;
- iRow = ListView_InsertItem(hwndList, &item);
- ListView_SetItemText(hwndList, iRow, 4, tmp);
- mir_free(tmp);
- p2+=2;
- p = out.find(" ", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList, iRow, 0, tmp);
- mir_free(tmp);
- p = out.find("uid ", p);
- p2 = out.find_first_not_of(" ", p+5);
- p = out.find("<", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList, iRow, 2, tmp);
- mir_free(tmp);
- p++;
- p2 = out.find(">", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- ListView_SetItemText(hwndList, iRow, 1, tmp);
- mir_free(tmp);
- p = out.find("ssb ", p2) + 6;
- p = out.find(" ", p) + 1;
- p2 = out.find("\n", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str());
- ListView_SetItemText(hwndList, iRow, 3, tmp);
- mir_free(tmp);
- 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);
- ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE);
- i++;
- }
- }
- }
- }
- break;
- case IDC_DELETE_KEY:
- ListView_GetItemText(hwndList, itemnum, 0, fp, 16);
- {
- string out;
- DWORD code;
- wstring cmd = _T("--batch --fingerprint ");
- cmd += fp;
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
- }
- string::size_type s = out.find("Key fingerprint = ");
- s += strlen("Key fingerprint = ");
- string::size_type s2 = out.find("\n", s);
- TCHAR *fp = NULL;
- {
- string tmp = out.substr(s, s2-s-1).c_str();
- string::size_type p = 0;
- while((p = tmp.find(" ", p)) != string::npos)
- {
- tmp.erase(p, 1);
- }
- fp = mir_a2t(tmp.c_str());
- }
- cmd.clear();
- out.clear();
- cmd += _T("--batch --delete-secret-and-public-key --fingerprint ");
- cmd += fp;
- mir_free(fp);
- gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
- }
- }
- DBDeleteContactSetting(NULL, szGPGModuleName, "GPGPubKey");
- DBDeleteContactSetting(NULL, szGPGModuleName, "KeyID");
- DBDeleteContactSetting(NULL, szGPGModuleName, "KeyComment");
- DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainName");
- DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainEmail");
- DBDeleteContactSetting(NULL, szGPGModuleName, "KeyType");
- ListView_DeleteItem(hwndList, itemnum);
- break;
- }
- break;
- }
-
- case WM_NOTIFY:
- {
- if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1))
- {
- if(hdr->hdr.code == LVN_ITEMCHANGED)
- {
- EnableWindow(GetDlgItem(hwndDlg, ID_OK), 1);
- itemnum = hdr->iItem;
- }
- }
- switch (((LPNMHDR)lParam)->code)
- {
- default:
- break;
-
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
- case WM_DESTROY:
- hwndFirstRun = NULL;
- break;
-
- }
-
- return FALSE;
-}
-
-void ShowFirstRunDialog();
-
-static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- TCHAR *tmp = NULL;
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T(""));
- SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp);
- mir_free(tmp);
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp);
- mir_free(tmp);
- return TRUE;
- }
-
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDC_SET_BIN_PATH:
- GetFilePath(_T("Choose gpg2.exe"), "szGpgBinPath", _T("*.exe"), _T("EXE Executables"));
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("gpg2.exe"));
- SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp);
- mir_free(tmp);
- break;
- case IDC_SET_HOME_DIR:
- GetFolderPath(_T("Set home diractory"), "szHomePath");
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp);
- mir_free(tmp);
- break;
- case ID_OK:
- {
- TCHAR tmp[512];
- GetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp, 512);
- DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp);
- GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512);
- while(tmp[_tcslen(tmp)-1] == '\\')
- tmp[_tcslen(tmp)-1] = '\0';
- DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp);
- DestroyWindow(hwndDlg);
- ShowFirstRunDialog();
- break;
- }
-
- default:
- break;
- }
-
- break;
- }
-
- case WM_NOTIFY:
- {
- switch (((LPNMHDR)lParam)->code)
- {
- default:
- break;
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
- case WM_DESTROY:
- hwndSetDirs = NULL;
- break;
-
- }
- return FALSE;
-}
-
-static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- extern HANDLE new_key_hcnt;
- void ImportKey();
- TCHAR *tmp = NULL;
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- TCHAR *tmp = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "GPGPubKey", _T(""));
- SetDlgItemText(hwndDlg, IDC_MESSAGE, (_tcslen(tmp) > 0)?_T("There is existing key for contact, would you like to replace with new key ?"):_T("New public key was received, do you want to import it?"));
- EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(new_key_hcnt, szGPGModuleName, "GPGEncryption", 0)?0:1);
- SetDlgItemText(hwndDlg, ID_IMPORT, (_tcslen(tmp) > 0)?_T("Replace"):_T("Accept"));
- mir_free(tmp);
- tmp = new TCHAR [256];
- _tcscpy(tmp, _T("Received key from "));
- _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)new_key_hcnt, (LPARAM)GCDNF_TCHAR));
- SetDlgItemText(hwndDlg, IDC_KEY_FROM, tmp);
- delete [] tmp;
- return TRUE;
- }
-
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case ID_IMPORT:
- ImportKey();
- DestroyWindow(hwndDlg);
- break;
- case IDC_IMPORT_AND_USE:
- ImportKey();
- DBWriteContactSettingByte(new_key_hcnt, szGPGModuleName, "GPGEncryption", 1);
- void setSrmmIcon(HANDLE hContact);
- void setClistIcon(HANDLE hContact);
- setSrmmIcon(new_key_hcnt);
- setClistIcon(new_key_hcnt);
- DestroyWindow(hwndDlg);
- break;
- case IDC_IGNORE_KEY:
- DestroyWindow(hwndDlg);
- break;
- default:
- break;
- }
-
- break;
- }
-
- case WM_NOTIFY:
- {
- switch (((LPNMHDR)lParam)->code)
- {
- default:
- break;
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
- case WM_DESTROY:
- hwndNewKey = NULL;
- break;
-
- }
- return FALSE;
-}
-static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("RSA"), 0);
- ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("DSA"), 1);
- SendDlgItemMessage(hwndDlg, IDC_KEY_TYPE, CB_SETCURSEL, (WPARAM)1, 0);
- SetDlgItemInt(hwndDlg, IDC_KEY_EXPIRE_DATE, 0, 0);
- SetDlgItemInt(hwndDlg, IDC_KEY_LENGTH, 2048, 0);
- return TRUE;
- }
-
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDCANCEL:
- DestroyWindow(hwndDlg);
- break;
- case IDOK:
- {
- wstring path;
- { //data sanity checks
- TCHAR *tmp = new TCHAR [5];
- GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5);
- if(_tcslen(tmp) < 3)
- {
- mir_free(tmp);
- MessageBox(0, _T("You must set encryption algorythm first"), _T("Error"), MB_OK);
- break;
- }
- mir_free(tmp);
- tmp = new TCHAR [5];
- GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5);
- int length = _ttoi(tmp);
- mir_free(tmp);
- if(length < 1024 || length > 4096)
- {
- MessageBox(0, _T("Key length must be of length from 1024 to 4096 bits"), _T("Error"), MB_OK);
- break;
- }
- tmp = new TCHAR [12];
- GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12);
- if(_tcslen(tmp) != 10 && tmp[0] != '0')
- {
- MessageBox(0, _T("Invalid date"), _T("Error"), MB_OK);
- delete [] tmp;
- break;
- }
- delete [] tmp;
- tmp = new TCHAR [128];
- GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128);
- if(_tcslen(tmp) < 5)
- {
- MessageBox(0, _T("Name must contain at least 5 characters"), _T("Error"), MB_OK);
- delete [] tmp;
- break;
- }
- delete [] tmp;
- tmp = new TCHAR [128];
- GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128);
- if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.'))))
- {
- MessageBox(0, _T("Invalid Email"), _T("Error"), MB_OK);
- delete [] tmp;
- break;
- }
- delete [] tmp;
- }
- { //generating key file
- TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- char *tmp2;// = mir_t2a(tmp);
- path = tmp;
- mir_free(tmp);
- // mir_free(tmp2);
- path.append(_T("\\new_key"));
- wfstream f(path.c_str(), std::ios::out);
- if(!f.is_open())
- {
- MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK);
- break;
- }
- f<<"Key-Type: ";
- tmp = new TCHAR [5];
- GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5);
- tmp2 = mir_t2a(tmp);
- char *subkeytype = new char [6];
- if(strstr(tmp2, "RSA"))
- strcpy(subkeytype, "RSA");
- else if(strstr(tmp2, "DSA")) //this is useless check for now, but it will be required if someone add another key types support
- strcpy(subkeytype, "ELG-E");
- delete [] tmp;
- f<<tmp2;
- mir_free(tmp2);
- f<<"\n";
- f<<"Key-Length: ";
- tmp = new TCHAR [5];
- GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5);
- int length = _ttoi(tmp);
- delete [] tmp;
- f<<length;
- f<<"\n";
- f<<"Subkey-Type: ";
- f<<subkeytype;
- delete [] subkeytype;
- f<<"\n";
- tmp = new TCHAR [64]; //i hope this is enough for password
- GetDlgItemText(hwndDlg, IDC_KEY_PASSWD, tmp, 64);
- if(_tcslen(tmp) > 0)
- {
- f<<"Passphrase: ";
- tmp2 = mir_utf8encodeW(tmp);
- f<<tmp2;
- f<<"\n";
- mir_free(tmp2);
- }
- delete [] tmp;
- f<<"Name-Real: ";
- tmp = new TCHAR [128];
- GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128);
- tmp2 = mir_utf8encodeW(tmp);
- f<<tmp2;
- mir_free(tmp2);
- delete [] tmp;
- f<<"\n";
- tmp = new TCHAR [512];
- GetDlgItemText(hwndDlg, IDC_KEY_COMMENT, tmp, 512);
- if(_tcslen(tmp) > 0)
- {
- tmp2 = mir_utf8encodeW(tmp);
- f<<"Name-Comment: ";
- f<<tmp2;
- f<<"\n";
- }
- mir_free(tmp2);
- delete [] tmp;
- f<<"Name-Email: ";
- tmp = new TCHAR [128];
- GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128);
- tmp2 = mir_utf8encodeW(tmp);
- f<<tmp2;
- mir_free(tmp2);
- delete [] tmp;
- f<<"\n";
- f<<"Expire-Date: ";
- tmp = new TCHAR [12];
- GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12);
- tmp2 = mir_utf8encodeW(tmp);
- f<<tmp2;
- mir_free(tmp2);
- delete [] tmp;
- f<<"\n";
- f.close();
- }
- { //gpg execution
- DWORD code;
- string out;
- wstring cmd;
- cmd += _T("--batch --yes --gen-key \"");
- cmd += path;
- cmd += _T("\"");
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 300000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
+// Copyright © 2010 sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + + +#include "commonheaders.h" + + +HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL, hwndKeyGen = NULL, hwndSelectExistingKey = NULL; + +int itemnum = 0; + +HWND hwndList_g = NULL; + +static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + HWND hwndList=GetDlgItem(hwndDlg, IDC_KEY_LIST); + hwndList_g = hwndList; + LVCOLUMN col = {0}; + LVITEM item = {0}; + NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; + TCHAR fp[16] = {0}; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + col.pszText = _T("Key ID"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 0, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Email"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 1, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Name"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 250; + ListView_InsertColumn(hwndList, 2, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Creation date"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 3, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Key length"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 4, &col); + ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT); + int i = 1, iRow = 0; + { + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + {//parse gpg output + string out; + DWORD code; + pxResult result; + wstring::size_type p = 0, p2 = 0, stop = 0; + { + gpg_execution_params params; + wstring cmd = _T("--batch --list-secret-keys"); + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + } + while(p != string::npos) + { + if((p = out.find("sec ", p)) == string::npos) + break; + p += 5; + if(p < stop) + break; + stop = p; + p2 = out.find("/", p) - 1; + TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + item.pszText = tmp; + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + p2+=2; + p = out.find(" ", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 0, tmp); + mir_free(tmp); + p = out.find("uid ", p); + p2 = out.find_first_not_of(" ", p+5); + p = out.find("<", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 2, tmp); + mir_free(tmp); + p++; + p2 = out.find(">", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str()); + ListView_SetItemText(hwndList, iRow, 3, tmp); + mir_free(tmp); + 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); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + i++; + } + } + } + + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_GENERATE_KEY: + void ShowKeyGenDialog(); + ShowKeyGenDialog(); + break; + case ID_OK: + ListView_GetItemText(hwndList, itemnum, 0, fp, 16); + { + string out; + DWORD code; + wstring cmd = _T("--batch -a --export "); + cmd += fp; + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + string::size_type s = 0; + while((s = out.find("\r", s)) != string::npos) + { + out.erase(s, 1); + } + DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str()); + } + DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp); + TCHAR passwd[64]; + GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, passwd, 64); + if(_tcslen(passwd) > 0) + DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", passwd); + else + DBDeleteContactSetting(NULL, szGPGModuleName, "szKeyPassword"); + DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0); + DestroyWindow(hwndDlg); + break; + case IDC_OTHER: + { + void ShowLoadPublicKeyDialog(); + extern map<int, HANDLE> user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = 0; + ShowLoadPublicKeyDialog(); + ListView_DeleteAllItems(hwndList); + { + int i = 1, iRow = 0; + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + {//parse gpg output + string out; + DWORD code; + wstring::size_type p = 0, p2 = 0, stop = 0; + { + wstring cmd = _T("--batch --list-secret-keys"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + } + while(p != string::npos) + { + if((p = out.find("sec ", p)) == string::npos) + break; + p += 5; + if(p < stop) + break; + stop = p; + p2 = out.find("/", p) - 1; + TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + item.pszText = tmp; + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + p2+=2; + p = out.find(" ", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 0, tmp); + mir_free(tmp); + p = out.find("uid ", p); + p2 = out.find_first_not_of(" ", p+5); + p = out.find("<", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 2, tmp); + mir_free(tmp); + p++; + p2 = out.find(">", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str()); + ListView_SetItemText(hwndList, iRow, 3, tmp); + mir_free(tmp); + 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); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + i++; + } + } + } + } + break; + case IDC_DELETE_KEY: + ListView_GetItemText(hwndList, itemnum, 0, fp, 16); + { + string out; + DWORD code; + wstring cmd = _T("--batch --fingerprint "); + cmd += fp; + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + string::size_type s = out.find("Key fingerprint = "); + s += strlen("Key fingerprint = "); + string::size_type s2 = out.find("\n", s); + TCHAR *fp = NULL; + { + string tmp = out.substr(s, s2-s-1).c_str(); + string::size_type p = 0; + while((p = tmp.find(" ", p)) != string::npos) + { + tmp.erase(p, 1); } - }
- DeleteFile(path.c_str());
- DestroyWindow(hwndDlg);
- {//parse gpg output
- LVITEM item = {0};
- int i = 1, iRow = 0;
- item.mask = LVIF_TEXT;
- item.iItem = i;
- item.iSubItem = 0;
- item.pszText = _T("");
- string out;
- DWORD code;
- string::size_type p = 0, p2 = 0, stop = 0;
- {
- wstring cmd = _T("--list-secret-keys");
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
+ fp = mir_a2t(tmp.c_str()); + } + cmd.clear(); + out.clear(); + cmd += _T("--batch --delete-secret-and-public-key --fingerprint "); + cmd += fp; + mir_free(fp); + gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + } + DBDeleteContactSetting(NULL, szGPGModuleName, "GPGPubKey"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyID"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyComment"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainName"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainEmail"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyType"); + ListView_DeleteItem(hwndList, itemnum); + break; + } + break; + } + + case WM_NOTIFY: + { + if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) + { + if(hdr->hdr.code == LVN_ITEMCHANGED) + { + EnableWindow(GetDlgItem(hwndDlg, ID_OK), 1); + itemnum = hdr->iItem; + } + } + switch (((LPNMHDR)lParam)->code) + { + default: + break; + + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndFirstRun = NULL; + break; + + } + + return FALSE; +} + +void ShowFirstRunDialog(); + +static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); + SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); + mir_free(tmp); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); + mir_free(tmp); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_SET_BIN_PATH: + GetFilePath(_T("Choose gpg2.exe"), "szGpgBinPath", _T("*.exe"), _T("EXE Executables")); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("gpg2.exe")); + SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); + mir_free(tmp); + break; + case IDC_SET_HOME_DIR: + GetFolderPath(_T("Set home diractory"), "szHomePath"); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); + mir_free(tmp); + break; + case ID_OK: + { + TCHAR tmp[512]; + GetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp, 512); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512); + while(tmp[_tcslen(tmp)-1] == '\\') + tmp[_tcslen(tmp)-1] = '\0'; + DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp); + DestroyWindow(hwndDlg); + ShowFirstRunDialog(); + break; + } + + default: + break; + } + + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + default: + break; + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndSetDirs = NULL; + break; + + } + return FALSE; +} + +static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + extern HANDLE new_key_hcnt; + void ImportKey(); + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + TCHAR *tmp = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "GPGPubKey", _T("")); + SetDlgItemText(hwndDlg, IDC_MESSAGE, (_tcslen(tmp) > 0)?_T("There is existing key for contact, would you like to replace with new key ?"):_T("New public key was received, do you want to import it?")); + EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(new_key_hcnt, szGPGModuleName, "GPGEncryption", 0)?0:1); + SetDlgItemText(hwndDlg, ID_IMPORT, (_tcslen(tmp) > 0)?_T("Replace"):_T("Accept")); + mir_free(tmp); + tmp = new TCHAR [256]; + _tcscpy(tmp, _T("Received key from ")); + _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)new_key_hcnt, (LPARAM)GCDNF_TCHAR)); + SetDlgItemText(hwndDlg, IDC_KEY_FROM, tmp); + delete [] tmp; + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case ID_IMPORT: + ImportKey(); + DestroyWindow(hwndDlg); + break; + case IDC_IMPORT_AND_USE: + ImportKey(); + DBWriteContactSettingByte(new_key_hcnt, szGPGModuleName, "GPGEncryption", 1); + void setSrmmIcon(HANDLE hContact); + void setClistIcon(HANDLE hContact); + setSrmmIcon(new_key_hcnt); + setClistIcon(new_key_hcnt); + DestroyWindow(hwndDlg); + break; + case IDC_IGNORE_KEY: + DestroyWindow(hwndDlg); + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + default: + break; + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndNewKey = NULL; + break; + + } + return FALSE; +} +static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("RSA"), 0); + ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("DSA"), 1); + SendDlgItemMessage(hwndDlg, IDC_KEY_TYPE, CB_SETCURSEL, (WPARAM)1, 0); + SetDlgItemInt(hwndDlg, IDC_KEY_EXPIRE_DATE, 0, 0); + SetDlgItemInt(hwndDlg, IDC_KEY_LENGTH, 2048, 0); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDCANCEL: + DestroyWindow(hwndDlg); + break; + case IDOK: + { + wstring path; + { //data sanity checks + TCHAR *tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); + if(_tcslen(tmp) < 3) + { + mir_free(tmp); + MessageBox(0, _T("You must set encryption algorythm first"), _T("Error"), MB_OK); + break; + } + mir_free(tmp); + tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5); + int length = _ttoi(tmp); + mir_free(tmp); + if(length < 1024 || length > 4096) + { + MessageBox(0, _T("Key length must be of length from 1024 to 4096 bits"), _T("Error"), MB_OK); + break; + } + tmp = new TCHAR [12]; + GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); + if(_tcslen(tmp) != 10 && tmp[0] != '0') + { + MessageBox(0, _T("Invalid date"), _T("Error"), MB_OK); + delete [] tmp; + break; + } + delete [] tmp; + tmp = new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); + if(_tcslen(tmp) < 5) + { + MessageBox(0, _T("Name must contain at least 5 characters"), _T("Error"), MB_OK); + delete [] tmp; + break; + } + delete [] tmp; + tmp = new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); + if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.')))) + { + MessageBox(0, _T("Invalid Email"), _T("Error"), MB_OK); + delete [] tmp; + break; + } + delete [] tmp; + } + { //generating key file + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + char *tmp2;// = mir_t2a(tmp); + path = tmp; + mir_free(tmp); + // mir_free(tmp2); + path.append(_T("\\new_key")); + wfstream f(path.c_str(), std::ios::out); + if(!f.is_open()) + { + MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK); + break; + } + f<<"Key-Type: "; + tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); + tmp2 = mir_t2a(tmp); + char *subkeytype = new char [6]; + if(strstr(tmp2, "RSA")) + strcpy(subkeytype, "RSA"); + else if(strstr(tmp2, "DSA")) //this is useless check for now, but it will be required if someone add another key types support + strcpy(subkeytype, "ELG-E"); + delete [] tmp; + f<<tmp2; + mir_free(tmp2); + f<<"\n"; + f<<"Key-Length: "; + tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5); + int length = _ttoi(tmp); + delete [] tmp; + f<<length; + f<<"\n"; + f<<"Subkey-Type: "; + f<<subkeytype; + delete [] subkeytype; + f<<"\n"; + tmp = new TCHAR [64]; //i hope this is enough for password + GetDlgItemText(hwndDlg, IDC_KEY_PASSWD, tmp, 64); + if(_tcslen(tmp) > 0) + { + f<<"Passphrase: "; + tmp2 = mir_utf8encodeW(tmp); + f<<tmp2; + f<<"\n"; + mir_free(tmp2); + } + delete [] tmp; + f<<"Name-Real: "; + tmp = new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); + tmp2 = mir_utf8encodeW(tmp); + f<<tmp2; + mir_free(tmp2); + delete [] tmp; + f<<"\n"; + tmp = new TCHAR [512]; + GetDlgItemText(hwndDlg, IDC_KEY_COMMENT, tmp, 512); + if(_tcslen(tmp) > 0) + { + tmp2 = mir_utf8encodeW(tmp); + f<<"Name-Comment: "; + f<<tmp2; + f<<"\n"; + } + mir_free(tmp2); + delete [] tmp; + f<<"Name-Email: "; + tmp = new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); + tmp2 = mir_utf8encodeW(tmp); + f<<tmp2; + mir_free(tmp2); + delete [] tmp; + f<<"\n"; + f<<"Expire-Date: "; + tmp = new TCHAR [12]; + GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); + tmp2 = mir_utf8encodeW(tmp); + f<<tmp2; + mir_free(tmp2); + delete [] tmp; + f<<"\n"; + f.close(); + } + { //gpg execution + DWORD code; + string out; + wstring cmd; + cmd += _T("--batch --yes --gen-key \""); + cmd += path; + cmd += _T("\""); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 300000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + } + DeleteFile(path.c_str()); + DestroyWindow(hwndDlg); + {//parse gpg output + LVITEM item = {0}; + int i = 1, iRow = 0; + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + string out; + DWORD code; + string::size_type p = 0, p2 = 0, stop = 0; + { + wstring cmd = _T("--list-secret-keys"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; } - }
- ListView_DeleteAllItems(hwndList_g);
- while(p != string::npos)
- {
- if((p = out.find("sec ", p)) == string::npos)
- break;
- p += 5;
- if(p < stop)
- break;
- stop = p;
- p2 = out.find("/", p) - 1;
- TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- item.pszText = tmp;
- iRow = ListView_InsertItem(hwndList_g, &item);
- ListView_SetItemText(hwndList_g, iRow, 4, tmp);
- mir_free(tmp);
- p2+=2;
- p = out.find(" ", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList_g, iRow, 0, tmp);
- mir_free(tmp);
- p = out.find("uid ", p);
- p2 = out.find_first_not_of(" ", p+5);
- p = out.find("<", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList_g, iRow, 2, tmp);
- mir_free(tmp);
- p++;
- p2 = out.find(">", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- ListView_SetItemText(hwndList_g, iRow, 1, tmp);
- mir_free(tmp);
- p = out.find("ssb ", p2) + 6;
- p = out.find(" ", p) + 1;
- p2 = out.find("\n", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str());
- ListView_SetItemText(hwndList_g, iRow, 3, tmp);
- mir_free(tmp);
- ListView_SetColumnWidth(hwndList_g, 0, LVSCW_AUTOSIZE);// not sure about this
- ListView_SetColumnWidth(hwndList_g, 1, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hwndList_g, 2, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hwndList_g, 3, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hwndList_g, 4, LVSCW_AUTOSIZE);
- i++;
- }
- }
- }
- break;
- default:
- break;
- }
-
- break;
- }
-
- case WM_NOTIFY:
- {
- switch (((LPNMHDR)lParam)->code)
- {
- default:
- break;
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
- case WM_DESTROY:
- hwndKeyGen = NULL;
- break;
-
- }
- return FALSE;
-}
-
-int itemnum2 = 0;
-
+ } + ListView_DeleteAllItems(hwndList_g); + while(p != string::npos) + { + if((p = out.find("sec ", p)) == string::npos) + break; + p += 5; + if(p < stop) + break; + stop = p; + p2 = out.find("/", p) - 1; + TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + item.pszText = tmp; + iRow = ListView_InsertItem(hwndList_g, &item); + ListView_SetItemText(hwndList_g, iRow, 4, tmp); + mir_free(tmp); + p2+=2; + p = out.find(" ", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList_g, iRow, 0, tmp); + mir_free(tmp); + p = out.find("uid ", p); + p2 = out.find_first_not_of(" ", p+5); + p = out.find("<", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList_g, iRow, 2, tmp); + mir_free(tmp); + p++; + p2 = out.find(">", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + ListView_SetItemText(hwndList_g, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str()); + ListView_SetItemText(hwndList_g, iRow, 3, tmp); + mir_free(tmp); + ListView_SetColumnWidth(hwndList_g, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList_g, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_g, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_g, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_g, 4, LVSCW_AUTOSIZE); + i++; + } + } + } + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + default: + break; + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndKeyGen = NULL; + break; + + } + return FALSE; +} + +int itemnum2 = 0; + static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { - HWND hwndList=GetDlgItem(hwndDlg, IDC_EXISTING_KEY_LIST);
- hwndList_g = hwndList;
- LVCOLUMN col = {0};
- LVITEM item = {0};
- NMLISTVIEW * hdr = (NMLISTVIEW *) lParam;
- TCHAR id[16] = {0};
+ HWND hwndList=GetDlgItem(hwndDlg, IDC_EXISTING_KEY_LIST); + hwndList_g = hwndList; + LVCOLUMN col = {0}; + LVITEM item = {0}; + NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; + TCHAR id[16] = {0}; switch (msg) { case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); - col.pszText = _T("Key ID");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 50;
- ListView_InsertColumn(hwndList, 0, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Email");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 30;
- ListView_InsertColumn(hwndList, 1, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Name");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 250;
- ListView_InsertColumn(hwndList, 2, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Creation date");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 30;
- ListView_InsertColumn(hwndList, 3, &col);
- ZeroMemory(&col,sizeof(col));
- col.pszText = _T("Key length");
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.fmt = LVCFMT_LEFT;
- col.cx = 30;
- ListView_InsertColumn(hwndList, 4, &col);
- ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT);
- int i = 1, iRow = 0;
- {
- item.mask = LVIF_TEXT;
- item.iItem = i;
- item.iSubItem = 0;
- item.pszText = _T("");
- {//parse gpg output
- string out;
- DWORD code;
- string::size_type p = 0, p2 = 0, stop = 0;
- {
- wstring cmd = _T("--batch --list-keys");
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
+ col.pszText = _T("Key ID"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 0, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Email"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 1, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Name"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 250; + ListView_InsertColumn(hwndList, 2, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Creation date"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 3, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Key length"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 4, &col); + ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT); + int i = 1, iRow = 0; + { + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + {//parse gpg output + string out; + DWORD code; + string::size_type p = 0, p2 = 0, stop = 0; + { + wstring cmd = _T("--batch --list-keys"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; } - }
- while(p != string::npos)
- {
- if((p = out.find("pub ", p)) == string::npos)
- break;
- p += 5;
- if(p < stop)
- break;
- stop = p;
- p2 = out.find("/", p) - 1;
- TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- item.pszText = tmp;
- iRow = ListView_InsertItem(hwndList, &item);
- ListView_SetItemText(hwndList, iRow, 4, tmp);
- mir_free(tmp);
- p2+=2;
- p = out.find(" ", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList, iRow, 0, tmp);
- mir_free(tmp);
- p = out.find("uid ", p);
- p2 = out.find_first_not_of(" ", p+5);
- p = out.find("<", p2);
- tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str());
- ListView_SetItemText(hwndList, iRow, 2, tmp);
- mir_free(tmp);
- p++;
- p2 = out.find(">", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str());
- ListView_SetItemText(hwndList, iRow, 1, tmp);
- mir_free(tmp);
- p = out.find("sub ", p2) + 6;
- p = out.find(" ", p) + 1;
- p2 = out.find("\n", p);
- tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str());
- ListView_SetItemText(hwndList, iRow, 3, tmp);
- mir_free(tmp);
- 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);
- ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE);
- i++;
- }
- }
- }
+ } + while(p != string::npos) + { + if((p = out.find("pub ", p)) == string::npos) + break; + p += 5; + if(p < stop) + break; + stop = p; + p2 = out.find("/", p) - 1; + TCHAR *tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + item.pszText = tmp; + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + p2+=2; + p = out.find(" ", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 0, tmp); + mir_free(tmp); + p = out.find("uid ", p); + p2 = out.find_first_not_of(" ", p+5); + p = out.find("<", p2); + tmp = mir_utf8decodeW(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 2, tmp); + mir_free(tmp); + p++; + p2 = out.find(">", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + p = out.find("sub ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_utf8decodeW(out.substr(p,p2-p-1).c_str()); + ListView_SetItemText(hwndList, iRow, 3, tmp); + mir_free(tmp); + 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); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + i++; + } + } + } return TRUE; } case WM_COMMAND: @@ -950,43 +950,43 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, switch (LOWORD(wParam)) { case IDOK: - {
- ListView_GetItemText(hwndList, itemnum2, 0, id, 16);
- extern HWND hPubKeyEdit;
- string out;
- DWORD code;
- wstring cmd = _T("--batch -a --export ");
+ { + ListView_GetItemText(hwndList, itemnum2, 0, id, 16); + extern HWND hPubKeyEdit; + string out; + DWORD code; + wstring cmd = _T("--batch -a --export "); cmd += id; - gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- break;
- }
- string::size_type s = 0;
- while((s = out.find("\r", s)) != string::npos)
- {
- out.erase(s, 1);
- }
- TCHAR *tmp = mir_a2t(out.c_str());
-// SetDlgItemText(hPubKeyEdit, IDC_PUBLIC_KEY_EDIT, tmp);
- SetWindowText(hPubKeyEdit, tmp);
- mir_free(tmp);
- }
- DestroyWindow(hwndDlg);
- break;
+ gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + string::size_type s = 0; + while((s = out.find("\r", s)) != string::npos) + { + out.erase(s, 1); + } + TCHAR *tmp = mir_a2t(out.c_str()); +// SetDlgItemText(hPubKeyEdit, IDC_PUBLIC_KEY_EDIT, tmp); + SetWindowText(hPubKeyEdit, tmp); + mir_free(tmp); + } + DestroyWindow(hwndDlg); + break; case IDCANCEL: DestroyWindow(hwndDlg); break; @@ -995,15 +995,15 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, } case WM_NOTIFY: - {
- if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1))
- {
- if(hdr->hdr.code == LVN_ITEMCHANGED)
- {
- EnableWindow(GetDlgItem(hwndDlg, IDOK), 1);
- itemnum2 = hdr->iItem;
- }
- }
+ { + if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) + { + if(hdr->hdr.code == LVN_ITEMCHANGED) + { + EnableWindow(GetDlgItem(hwndDlg, IDOK), 1); + itemnum2 = hdr->iItem; + } + } switch (((LPNMHDR)lParam)->code) { @@ -1026,45 +1026,45 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, return FALSE; } -
-
-extern HINSTANCE hInst;
-
-
-void ShowFirstRunDialog()
-{
- if (hwndFirstRun == NULL)
- {
- hwndFirstRun = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIRST_RUN), NULL, DlgProcFirstRun);
- }
- SetForegroundWindow(hwndFirstRun);
-}
-
-
-void ShowSetDirsDialog()
-{
- if (hwndSetDirs == NULL)
- {
- hwndSetDirs = CreateDialog(hInst, MAKEINTRESOURCE(IDD_BIN_PATH), NULL, DlgProcGpgBinOpts);
- }
- SetForegroundWindow(hwndSetDirs);
-}
-
-void ShowNewKeyDialog()
-{
- hwndNewKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_NEW_KEY), NULL, DlgProcNewKeyDialog);
- SetForegroundWindow(hwndNewKey);
-}
-
-void ShowKeyGenDialog()
-{
- if (hwndKeyGen == NULL)
- {
- hwndKeyGen = CreateDialog(hInst, MAKEINTRESOURCE(IDD_KEY_GEN), NULL, DlgProcKeyGenDialog);
- }
- SetForegroundWindow(hwndKeyGen);
-}
-
+ + +extern HINSTANCE hInst; + + +void ShowFirstRunDialog() +{ + if (hwndFirstRun == NULL) + { + hwndFirstRun = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIRST_RUN), NULL, DlgProcFirstRun); + } + SetForegroundWindow(hwndFirstRun); +} + + +void ShowSetDirsDialog() +{ + if (hwndSetDirs == NULL) + { + hwndSetDirs = CreateDialog(hInst, MAKEINTRESOURCE(IDD_BIN_PATH), NULL, DlgProcGpgBinOpts); + } + SetForegroundWindow(hwndSetDirs); +} + +void ShowNewKeyDialog() +{ + hwndNewKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_NEW_KEY), NULL, DlgProcNewKeyDialog); + SetForegroundWindow(hwndNewKey); +} + +void ShowKeyGenDialog() +{ + if (hwndKeyGen == NULL) + { + hwndKeyGen = CreateDialog(hInst, MAKEINTRESOURCE(IDD_KEY_GEN), NULL, DlgProcKeyGenDialog); + } + SetForegroundWindow(hwndKeyGen); +} + void ShowSelectExistingKeyDialog() { if (hwndSelectExistingKey == NULL) @@ -1073,117 +1073,117 @@ void ShowSelectExistingKeyDialog() } SetForegroundWindow(hwndSelectExistingKey); } -
-
-
-
-
-void FirstRun()
-{
- DWORD pid = 0;
- if(!DBGetContactSettingByte(NULL, szGPGModuleName, "FirstRun", 1))
- return;
- ShowSetDirsDialog();
-}
-
-void InitCheck()
-{
-}
-
-void ImportKey()
-{
- extern wstring new_key;
- extern HANDLE new_key_hcnt;
- DBWriteContactSettingTString(new_key_hcnt, szGPGModuleName, "GPGPubKey", new_key.c_str());
- { //gpg execute block
- wstring cmd;
- TCHAR tmp2[MAX_PATH] = {0};
- TCHAR *ptmp;
- string output;
- DWORD exitcode;
- {
- ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- _tcscpy(tmp2, ptmp);
- mir_free(ptmp);
- _tcscat(tmp2, _T("\\"));
- _tcscat(tmp2, _T("temporary_exported.asc"));
- wfstream f(tmp2, std::ios::out);
- ptmp = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "GPGPubKey", _T(""));
- wstring new_key = ptmp;
- mir_free(ptmp);
- f<<new_key.c_str();
- f.close();
- cmd += _T(" --batch ");
- cmd += _T(" --import \"");
- cmd += tmp2;
- cmd += _T("\"");
- }
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &output;
- params.code = &exitcode;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- return;
+ + + + + +void FirstRun() +{ + DWORD pid = 0; + if(!DBGetContactSettingByte(NULL, szGPGModuleName, "FirstRun", 1)) + return; + ShowSetDirsDialog(); +} + +void InitCheck() +{ +} + +void ImportKey() +{ + extern wstring new_key; + extern HANDLE new_key_hcnt; + DBWriteContactSettingTString(new_key_hcnt, szGPGModuleName, "GPGPubKey", new_key.c_str()); + { //gpg execute block + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + wfstream f(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "GPGPubKey", _T("")); + wstring new_key = ptmp; + mir_free(ptmp); + f<<new_key.c_str(); + f.close(); + cmd += _T(" --batch "); + cmd += _T(" --import \""); + cmd += tmp2; + cmd += _T("\""); } - DBDeleteContactSetting(new_key_hcnt, szGPGModuleName, "bAlwatsTrust");
- {
- char *tmp = NULL;
- string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
- string::size_type s2 = output.find(":", s);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str());
- s2+=2;
- s = output.find("\"", s2)-1;
- if(s != s2-1)
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str());
- s+=2;
- if((s2 = output.find("(", s)) == string::npos)
- s2 = output.find("<", s);
- tmp = new char [output.substr(s,s2-s-1).length()+1];
- strcpy(tmp, output.substr(s,s2-s-1).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainName", tmp);
- mir_free(tmp);
- if((s = output.find(")", s2)) == string::npos)
- s = output.find(">", s2);
- s2++;
- if(output[s] == ')')
- {
- tmp = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp, output.substr(s2,s-s2).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyComment", tmp);
- mir_free(tmp);
- s+=3;
- s2 = output.find(">", s);
- tmp = new char [output.substr(s,s2-s).length()+1];
- strcpy(tmp, output.substr(s,s2-s).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainEmail", tmp);
- mir_free(tmp);
- }
- else
- {
- tmp = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp, output.substr(s2,s-s2).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str());
- mir_free(tmp);
- }
+ gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &output; + params.code = &exitcode; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) + { + TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + return; + } + DBDeleteContactSetting(new_key_hcnt, szGPGModuleName, "bAlwatsTrust"); + { + char *tmp = NULL; + string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); + string::size_type s2 = output.find(":", s); + DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); + s2+=2; + s = output.find("\"", s2)-1; + if(s != s2-1) + DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str()); + s+=2; + if((s2 = output.find("(", s)) == string::npos) + s2 = output.find("<", s); + tmp = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainName", tmp); + mir_free(tmp); + if((s = output.find(")", s2)) == string::npos) + s = output.find(">", s2); + s2++; + if(output[s] == ')') + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyComment", tmp); + mir_free(tmp); + s+=3; + s2 = output.find(">", s); + tmp = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainEmail", tmp); + mir_free(tmp); + } + else + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp); + } } ptmp = mir_utf8decodeW(output.c_str()); MessageBox(0, ptmp, _T(""), MB_OK); - mir_free(ptmp);
- DeleteFile(tmp2);
- }
+ mir_free(ptmp); + DeleteFile(tmp2); + } }
\ No newline at end of file diff --git a/metacontacts.cpp b/metacontacts.cpp index 9ac3d63..6c49411 100644 --- a/metacontacts.cpp +++ b/metacontacts.cpp @@ -1,71 +1,71 @@ -// Copyright © 2010 SecureIM developers (baloo and others), sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include "commonheaders.h"
-
-extern bool bMetaContacts;
-
-BOOL isProtoMetaContacts(HANDLE hContact)
-{
- if(bMetaContacts) {
- LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if( proto && strcmp(proto,"MetaContacts")==0 ) {
- return true;
- }
- }
- return false;
-}
-
-
-BOOL metaIsDefaultSubContact(HANDLE hContact)
-{
-
- if(bMetaContacts)
- return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0),0)==hContact;
- return false;
-}
-
-
-HANDLE metaGetContact(HANDLE hContact)
-{
- if(bMetaContacts)
- return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0);
- return 0;
-}
-
-
-HANDLE metaGetMostOnline(HANDLE hContact)
-{
-
- if(bMetaContacts)
- return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0);
- return 0;
-}
-
-DWORD metaGetContactsNum(HANDLE hContact)
-{
- if(bMetaContacts)
- return CallService(MS_MC_GETNUMCONTACTS, (WPARAM)hContact, 0);
- return 0;
-}
-HANDLE metaGetSubcontact(HANDLE hContact, int num)
-{
- if(bMetaContacts)
- return (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, (LPARAM)num);
- return 0;
-}
-
-
+// Copyright © 2010 SecureIM developers (baloo and others), sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + +extern bool bMetaContacts; + +BOOL isProtoMetaContacts(HANDLE hContact) +{ + if(bMetaContacts) { + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if( proto && strcmp(proto,"MetaContacts")==0 ) { + return true; + } + } + return false; +} + + +BOOL metaIsDefaultSubContact(HANDLE hContact) +{ + + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0),0)==hContact; + return false; +} + + +HANDLE metaGetContact(HANDLE hContact) +{ + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); + return 0; +} + + +HANDLE metaGetMostOnline(HANDLE hContact) +{ + + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); + return 0; +} + +DWORD metaGetContactsNum(HANDLE hContact) +{ + if(bMetaContacts) + return CallService(MS_MC_GETNUMCONTACTS, (WPARAM)hContact, 0); + return 0; +} +HANDLE metaGetSubcontact(HANDLE hContact, int num) +{ + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, (LPARAM)num); + return 0; +} + + @@ -1,74 +1,74 @@ -//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by new_gpg.rc
-//
-#define IDD_LOAD_PUBLIC_KEY 102
-#define IDD_FIRST_RUN 103
-#define IDD_OPT_GPG 104
-#define IDD_OPT_GPG_BIN 105
-#define IDD_BIN_PATH 106
-#define IDD_OPT_GPG_MESSAGES 107
-#define IDD_NEW_KEY 108
-#define IDD_KEY_GEN 109
-#define IDD_LOAD_EXISTING_KEY 110
-#define IDD_KEY_PASSWD 111
-#define IDI_SECURED 112
-#define IDI_UNSECURED 113
-#define IDC_SET_BIN_PATH 1016
-#define IDC_SET_HOME_DIR 1017
-#define IDC_BIN_PATH 1018
-#define IDC_HOME_DIR 1019
-#define IDC_USERLIST 1020
-#define IDC_LOAD_KEY_BUTTON 1022
-#define ID_OK 1023
-#define ID_LOD_FROM_FILE 1024
-#define ID_LOAD_FROM_FILE 1024
-#define IDC_EDIT1 1025
-#define IDC_PUBLIC_KEY_EDIT 1025
-#define IDC_KEY_PASSWORD 1025
-#define IDC_IN_OPEN_TAG 1025
-#define IDC_KEY_PASSWD 1025
-#define IDC_PASSWORD 1025
-#define IDC_LOG_FILE_EDIT 1025
-#define IDC_BUTTON1 1026
-#define IDC_SAVE_KEY_BUTTON 1026
-#define IDC_GENERATE_KEY 1026
-#define IDC_IGNORE_KEY 1026
-#define IDC_SELECT_EXISTING 1026
-#define IDC_KEY_EMAIL 1026
-#define IDC_DELETE_KEY_BUTTON 1027
-#define IDC_IN_CLOSE_TAG 1027
-#define IDC_KEY_REAL_NAME 1027
-#define IDC_KEY_LIST 1028
-#define IDC_KEY_COMMENT 1028
-#define IDC_OUT_OPEN_TAG 1029
-#define IDC_APPEND_TAGS 1030
-#define IDC_OUT_CLOSE_TAG 1031
-#define IDC_SELECT_KEY 1033
-#define IDC_MESSAGE 1034
-#define ID_IMPORT 1035
-#define IDC_IMPORT_AND_USE 1036
-#define IDC_KEY_TYPE 1039
-#define IDC_KEY_LENGTH 1040
-#define IDC_KEY_EXPIRE_DATE 1043
-#define IDC_EXISTING_KEY_LIST 1045
-#define IDC_BUTTON2 1046
-#define IDC_OTHER 1046
-#define IDC_LOG_FILE_SET 1046
-#define IDC_SAVE_PASSWORD 1047
-#define IDC_DEBUG_LOG 1048
-#define IDC_JABBER_API 1049
-#define IDC_ENABLE_ENCRYPTION 1050
-#define IDC_KEY_FROM 1051
-#define IDC_DELETE_KEY 1052
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 114
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1053
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
+//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by new_gpg.rc +// +#define IDD_LOAD_PUBLIC_KEY 102 +#define IDD_FIRST_RUN 103 +#define IDD_OPT_GPG 104 +#define IDD_OPT_GPG_BIN 105 +#define IDD_BIN_PATH 106 +#define IDD_OPT_GPG_MESSAGES 107 +#define IDD_NEW_KEY 108 +#define IDD_KEY_GEN 109 +#define IDD_LOAD_EXISTING_KEY 110 +#define IDD_KEY_PASSWD 111 +#define IDI_SECURED 112 +#define IDI_UNSECURED 113 +#define IDC_SET_BIN_PATH 1016 +#define IDC_SET_HOME_DIR 1017 +#define IDC_BIN_PATH 1018 +#define IDC_HOME_DIR 1019 +#define IDC_USERLIST 1020 +#define IDC_LOAD_KEY_BUTTON 1022 +#define ID_OK 1023 +#define ID_LOD_FROM_FILE 1024 +#define ID_LOAD_FROM_FILE 1024 +#define IDC_EDIT1 1025 +#define IDC_PUBLIC_KEY_EDIT 1025 +#define IDC_KEY_PASSWORD 1025 +#define IDC_IN_OPEN_TAG 1025 +#define IDC_KEY_PASSWD 1025 +#define IDC_PASSWORD 1025 +#define IDC_LOG_FILE_EDIT 1025 +#define IDC_BUTTON1 1026 +#define IDC_SAVE_KEY_BUTTON 1026 +#define IDC_GENERATE_KEY 1026 +#define IDC_IGNORE_KEY 1026 +#define IDC_SELECT_EXISTING 1026 +#define IDC_KEY_EMAIL 1026 +#define IDC_DELETE_KEY_BUTTON 1027 +#define IDC_IN_CLOSE_TAG 1027 +#define IDC_KEY_REAL_NAME 1027 +#define IDC_KEY_LIST 1028 +#define IDC_KEY_COMMENT 1028 +#define IDC_OUT_OPEN_TAG 1029 +#define IDC_APPEND_TAGS 1030 +#define IDC_OUT_CLOSE_TAG 1031 +#define IDC_SELECT_KEY 1033 +#define IDC_MESSAGE 1034 +#define ID_IMPORT 1035 +#define IDC_IMPORT_AND_USE 1036 +#define IDC_KEY_TYPE 1039 +#define IDC_KEY_LENGTH 1040 +#define IDC_KEY_EXPIRE_DATE 1043 +#define IDC_EXISTING_KEY_LIST 1045 +#define IDC_BUTTON2 1046 +#define IDC_OTHER 1046 +#define IDC_LOG_FILE_SET 1046 +#define IDC_SAVE_PASSWORD 1047 +#define IDC_DEBUG_LOG 1048 +#define IDC_JABBER_API 1049 +#define IDC_ENABLE_ENCRYPTION 1050 +#define IDC_KEY_FROM 1051 +#define IDC_DELETE_KEY 1052 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 114 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1053 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif @@ -1,80 +1,80 @@ -// Copyright © 2010 SecureIM developers (baloo and others), sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
-
-#include "commonheaders.h"
-
-void ShowStatusIcon(HANDLE hContact);
-void setSrmmIcon(HANDLE hContact);
-
-int __cdecl onWindowEvent(WPARAM wParam, LPARAM lParam) {
-
- MessageWindowEventData *mwd = (MessageWindowEventData *)lParam;
- if(mwd->uType == MSG_WINDOW_EVT_OPEN || mwd->uType == MSG_WINDOW_EVT_OPENING)
- {
- setSrmmIcon(mwd->hContact);
- }
- return 0;
-}
-
-
-int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) {
- HANDLE hContact = (HANDLE)wParam;
- if( isProtoMetaContacts(hContact) )
- hContact = metaGetMostOnline(hContact); // возьмем тот, через который пойдет сообщение
-
- StatusIconClickData *sicd = (StatusIconClickData *)lParam;
- if(strcmp(sicd->szModule, szGPGModuleName) != 0)
+// Copyright © 2010 SecureIM developers (baloo and others), sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + +#include "commonheaders.h" + +void ShowStatusIcon(HANDLE hContact); +void setSrmmIcon(HANDLE hContact); + +int __cdecl onWindowEvent(WPARAM wParam, LPARAM lParam) { + + MessageWindowEventData *mwd = (MessageWindowEventData *)lParam; + if(mwd->uType == MSG_WINDOW_EVT_OPEN || mwd->uType == MSG_WINDOW_EVT_OPENING) + { + setSrmmIcon(mwd->hContact); + } + return 0; +} + + +int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam; + if( isProtoMetaContacts(hContact) ) + hContact = metaGetMostOnline(hContact); // возьмем тот, через который пойдет сообщение + + StatusIconClickData *sicd = (StatusIconClickData *)lParam; + if(strcmp(sicd->szModule, szGPGModuleName) != 0) return 0; // not our event - void setSrmmIcon(HANDLE);
- void setClistIcon(HANDLE);
- bool isContactHaveKey(HANDLE hContact);
+ void setSrmmIcon(HANDLE); + void setClistIcon(HANDLE); + bool isContactHaveKey(HANDLE hContact); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); if(enc) { - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- }
- else if(!enc)
- {
- if(!isContactHaveKey(hContact))
- {
- void ShowLoadPublicKeyDialog();
- extern map<int, HANDLE> user_data;
- extern int item_num;
- item_num = 0; //black magic here
- user_data[1] = hContact;
- ShowLoadPublicKeyDialog();
- }
- else
- {
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- return 0;
- }
- if(isContactHaveKey(hContact))
- {
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- }
- }
- return 0;
-}
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + else if(!enc) + { + if(!isContactHaveKey(hContact)) + { + void ShowLoadPublicKeyDialog(); + extern map<int, HANDLE> user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = hContact; + ShowLoadPublicKeyDialog(); + } + else + { + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + setSrmmIcon(hContact); + setClistIcon(hContact); + return 0; + } + if(isContactHaveKey(hContact)) + { + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + return 0; +} diff --git a/utilities.cpp b/utilities.cpp index 65b4b6f..03cb2c4 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1,216 +1,216 @@ -// Copyright © 2010 sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
-#include "commonheaders.h"
-
-
-TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef)
-{
- DBVARIANT dbv = {DBVT_DELETED};
- TCHAR* szRes;
- if (DBGetContactSettingTString(hContact, szModule, szSetting, &dbv))
- return _tcsdup(szDef);
- if(dbv.pszVal)
- szRes = _tcsdup(dbv.ptszVal);
- DBFreeVariant(&dbv);
- return szRes;
-}
-
-char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef)
-{
- DBVARIANT dbv = {DBVT_DELETED};
- char* szRes;
- if (DBGetContactSettingString(hContact, szModule, szSetting, &dbv))
- return _strdup(szDef);
- if(dbv.pszVal)
- szRes = _strdup(dbv.pszVal);
- DBFreeVariant(&dbv);
- return szRes;
-}
-
-
-char *date()
-{
- static char d[11];
- char *tmp = __DATE__, m[4], mn[3] = "01";
- m[0]=tmp[0];
- m[1]=tmp[1];
- m[2]=tmp[2];
- if(strstr(m,"Jan"))
- strcpy(mn,"01");
- else if(strstr(m,"Feb"))
- strcpy(mn,"02");
- else if(strstr(m,"Mar"))
- strcpy(mn,"03");
- else if(strstr(m,"Apr"))
- strcpy(mn,"04");
- else if(strstr(m,"May"))
- strcpy(mn,"05");
- else if(strstr(m,"Jun"))
- strcpy(mn,"06");
- else if(strstr(m,"Jul"))
- strcpy(mn,"07");
- else if(strstr(m,"Aug"))
- strcpy(mn,"08");
- else if(strstr(m,"Sep"))
- strcpy(mn,"09");
- else if(strstr(m,"Oct"))
- strcpy(mn,"10");
- else if(strstr(m,"Nov"))
- strcpy(mn,"11");
- else if(strstr(m,"Dec"))
- strcpy(mn,"12");
- d[0]=tmp[7];
- d[1]=tmp[8];
- d[2]=tmp[9];
- d[3]=tmp[10];
- d[4]='.';
- d[5]=mn[0];
- d[6]=mn[1];
- d[7]='.';
- if (tmp[4] == ' ')
- d[8] = '0';
- else
- d[8]=tmp[4];
- d[9]=tmp[5];
- return d;
-}
-
-void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc)
-{
- TCHAR str[MAX_PATH+2] = {0}, *tmp;
- OPENFILENAME ofn={0};
- TCHAR filter[512], *pfilter;
- ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName);
- ofn.Flags=OFN_EXPLORER;
- ofn.lpstrTitle=TranslateW(WindowTittle);
- _tcscpy(filter,TranslateW(szExtDesc));
- pfilter=filter+_tcslen(filter)+1;
- _tcscpy(pfilter, szExt);
- pfilter[_tcslen(pfilter)+1] = '\0';
- pfilter[_tcslen(pfilter)+2] = '\0';
- ofn.lpstrFilter=filter;
- tmp = UniGetContactSettingUtf(0, szGPGModuleName, szSetting, _T(""));
- _tcscpy(str, tmp);
- mir_free(tmp);
- if(_tcslen(str)< 2)
- str[0] = '\0';
- ofn.lpstrFile=str;
- ofn.nMaxFile=_MAX_PATH;
- ofn.nMaxFileTitle=MAX_PATH;
- if(!GetOpenFileName(&ofn))
- return;
- DBWriteContactSettingTString(0, szGPGModuleName, szSetting, str);
-}
-
-TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file)
-{
- TCHAR *str = new TCHAR [MAX_PATH+2];
- OPENFILENAME ofn={0};
- TCHAR filter[512], *pfilter;
- ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName);
- ofn.Flags=OFN_EXPLORER;
- ofn.lpstrTitle=TranslateW(WindowTittle);
- _tcscpy(filter,TranslateW(szExtDesc));
- pfilter=filter+_tcslen(filter)+1;
- _tcscpy(pfilter, szExt);
- pfilter[_tcslen(pfilter)+1] = '\0';
- pfilter[_tcslen(pfilter)+2] = '\0';
- ofn.lpstrFilter=filter;
- _tcscpy(str, _T(""));
- if(_tcslen(str)< 2)
- str[0] = '\0';
- ofn.lpstrFile=str;
- ofn.nMaxFile=_MAX_PATH;
- ofn.nMaxFileTitle=MAX_PATH;
- if(!save_file)
- {
- if(!GetOpenFileName(&ofn))
- {
- delete [] str;
- return NULL;
- }
- }
- else
- {
- if(!GetSaveFileName(&ofn))
- {
- delete [] str;
- return NULL;
- }
- }
- return str;
-}
-
-void GetFolderPath(TCHAR *WindowTittle, char *szSetting)
-{
- BROWSEINFO pbi = {0};
- pbi.lpszTitle = WindowTittle;
- pbi.ulFlags = BIF_EDITBOX|BIF_NEWDIALOGSTYLE|BIF_SHAREABLE;
- LPITEMIDLIST pidl = SHBrowseForFolder(&pbi);
- if (pidl != 0)
- {
- TCHAR path[MAX_PATH];
- if (SHGetPathFromIDList(pidl, path))
- {
- DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", path);
- }
- IMalloc * imalloc = 0;
- if (SUCCEEDED(SHGetMalloc(&imalloc)))
- {
- imalloc->Free(pidl);
- imalloc->Release();
- }
- }
-}
-
-int LoadKey(WPARAM w, LPARAM l)
-{
- void ShowLoadPublicKeyDialog();
- extern map<int, HANDLE> user_data;
- extern int item_num;
- item_num = 0; //black magic here
- user_data[1] = (HANDLE)w;
- ShowLoadPublicKeyDialog();
- return 0;
-}
-
-int SendKey(WPARAM w, LPARAM l)
-{
- HANDLE hContact = (HANDLE)w;
- if(isProtoMetaContacts(hContact))
- hContact = metaGetMostOnline(hContact);
- char *szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
- if(strlen(szMessage) > 1)
- {
- BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
- CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)szMessage);
- HistoryLog(hContact, "Public key sent", EVENTTYPE_MESSAGE, DBEF_SENT);
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc);
- }
- mir_free(szMessage);
- return 0;
-}
-
-extern HANDLE hLoadPublicKey, hToggleEncryption;
-
-int ToggleEncryption(WPARAM w, LPARAM l)
-{
+// Copyright © 2010 sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#include "commonheaders.h" + + +TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef) +{ + DBVARIANT dbv = {DBVT_DELETED}; + TCHAR* szRes; + if (DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) + return _tcsdup(szDef); + if(dbv.pszVal) + szRes = _tcsdup(dbv.ptszVal); + DBFreeVariant(&dbv); + return szRes; +} + +char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef) +{ + DBVARIANT dbv = {DBVT_DELETED}; + char* szRes; + if (DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) + return _strdup(szDef); + if(dbv.pszVal) + szRes = _strdup(dbv.pszVal); + DBFreeVariant(&dbv); + return szRes; +} + + +char *date() +{ + static char d[11]; + char *tmp = __DATE__, m[4], mn[3] = "01"; + m[0]=tmp[0]; + m[1]=tmp[1]; + m[2]=tmp[2]; + if(strstr(m,"Jan")) + strcpy(mn,"01"); + else if(strstr(m,"Feb")) + strcpy(mn,"02"); + else if(strstr(m,"Mar")) + strcpy(mn,"03"); + else if(strstr(m,"Apr")) + strcpy(mn,"04"); + else if(strstr(m,"May")) + strcpy(mn,"05"); + else if(strstr(m,"Jun")) + strcpy(mn,"06"); + else if(strstr(m,"Jul")) + strcpy(mn,"07"); + else if(strstr(m,"Aug")) + strcpy(mn,"08"); + else if(strstr(m,"Sep")) + strcpy(mn,"09"); + else if(strstr(m,"Oct")) + strcpy(mn,"10"); + else if(strstr(m,"Nov")) + strcpy(mn,"11"); + else if(strstr(m,"Dec")) + strcpy(mn,"12"); + d[0]=tmp[7]; + d[1]=tmp[8]; + d[2]=tmp[9]; + d[3]=tmp[10]; + d[4]='.'; + d[5]=mn[0]; + d[6]=mn[1]; + d[7]='.'; + if (tmp[4] == ' ') + d[8] = '0'; + else + d[8]=tmp[4]; + d[9]=tmp[5]; + return d; +} + +void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc) +{ + TCHAR str[MAX_PATH+2] = {0}, *tmp; + OPENFILENAME ofn={0}; + TCHAR filter[512], *pfilter; + ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName); + ofn.Flags=OFN_EXPLORER; + ofn.lpstrTitle=TranslateW(WindowTittle); + _tcscpy(filter,TranslateW(szExtDesc)); + pfilter=filter+_tcslen(filter)+1; + _tcscpy(pfilter, szExt); + pfilter[_tcslen(pfilter)+1] = '\0'; + pfilter[_tcslen(pfilter)+2] = '\0'; + ofn.lpstrFilter=filter; + tmp = UniGetContactSettingUtf(0, szGPGModuleName, szSetting, _T("")); + _tcscpy(str, tmp); + mir_free(tmp); + if(_tcslen(str)< 2) + str[0] = '\0'; + ofn.lpstrFile=str; + ofn.nMaxFile=_MAX_PATH; + ofn.nMaxFileTitle=MAX_PATH; + if(!GetOpenFileName(&ofn)) + return; + DBWriteContactSettingTString(0, szGPGModuleName, szSetting, str); +} + +TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file) +{ + TCHAR *str = new TCHAR [MAX_PATH+2]; + OPENFILENAME ofn={0}; + TCHAR filter[512], *pfilter; + ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName); + ofn.Flags=OFN_EXPLORER; + ofn.lpstrTitle=TranslateW(WindowTittle); + _tcscpy(filter,TranslateW(szExtDesc)); + pfilter=filter+_tcslen(filter)+1; + _tcscpy(pfilter, szExt); + pfilter[_tcslen(pfilter)+1] = '\0'; + pfilter[_tcslen(pfilter)+2] = '\0'; + ofn.lpstrFilter=filter; + _tcscpy(str, _T("")); + if(_tcslen(str)< 2) + str[0] = '\0'; + ofn.lpstrFile=str; + ofn.nMaxFile=_MAX_PATH; + ofn.nMaxFileTitle=MAX_PATH; + if(!save_file) + { + if(!GetOpenFileName(&ofn)) + { + delete [] str; + return NULL; + } + } + else + { + if(!GetSaveFileName(&ofn)) + { + delete [] str; + return NULL; + } + } + return str; +} + +void GetFolderPath(TCHAR *WindowTittle, char *szSetting) +{ + BROWSEINFO pbi = {0}; + pbi.lpszTitle = WindowTittle; + pbi.ulFlags = BIF_EDITBOX|BIF_NEWDIALOGSTYLE|BIF_SHAREABLE; + LPITEMIDLIST pidl = SHBrowseForFolder(&pbi); + if (pidl != 0) + { + TCHAR path[MAX_PATH]; + if (SHGetPathFromIDList(pidl, path)) + { + DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", path); + } + IMalloc * imalloc = 0; + if (SUCCEEDED(SHGetMalloc(&imalloc))) + { + imalloc->Free(pidl); + imalloc->Release(); + } + } +} + +int LoadKey(WPARAM w, LPARAM l) +{ + void ShowLoadPublicKeyDialog(); + extern map<int, HANDLE> user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = (HANDLE)w; + ShowLoadPublicKeyDialog(); + return 0; +} + +int SendKey(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + if(isProtoMetaContacts(hContact)) + hContact = metaGetMostOnline(hContact); + char *szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + if(strlen(szMessage) > 1) + { + BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)szMessage); + HistoryLog(hContact, "Public key sent", EVENTTYPE_MESSAGE, DBEF_SENT); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); + } + mir_free(szMessage); + return 0; +} + +extern HANDLE hLoadPublicKey, hToggleEncryption; + +int ToggleEncryption(WPARAM w, LPARAM l) +{ HANDLE hContact = (HANDLE)w; BYTE enc = 0; if(isProtoMetaContacts(hContact)) @@ -234,58 +234,58 @@ int ToggleEncryption(WPARAM w, LPARAM l) } else DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); - }
- void setSrmmIcon(HANDLE hContact);
- void setClistIcon(HANDLE hContact);
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- enc = enc?0:1;
- CLISTMENUITEM mi = {0};
- mi.cbSize=sizeof(mi);
- mi.flags = CMIM_NAME;
- enc?mi.pszName="Turn off GPG encryption":mi.pszName="Turn on GPG encryption";
- CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi);
- return 0;
-}
-
-int OnPreBuildContactMenu(WPARAM w, LPARAM l)
-{
- HANDLE hContact = (HANDLE)w;
- if(isProtoMetaContacts(hContact))
- hContact = metaGetMostOnline(hContact);
- CLISTMENUITEM mi = {0};
- mi.cbSize=sizeof(mi);
- mi.flags = CMIM_NAME;
- TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T(""));
- if(_tcslen(tmp) < 1)
- {
- DBDeleteContactSetting(hContact, szGPGModuleName, "GPGEncryption");
- mi.flags += CMIM_FLAGS | CMIF_GRAYED;
- }
- else
- mi.flags = CMIM_NAME | CMIM_FLAGS;
- mi.pszName = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?"Turn off GPG encryption":"Turn on GPG encryption";
- CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi);
- return 0;
-}
-
-
-void storeOutput(HANDLE ahandle, string *output)
-{
- BOOL success;
- char readbuffer[4096] = {0};
- unsigned long transfered, available;
-
- do {
- PeekNamedPipe(ahandle,NULL,0,NULL,&available,NULL);
- if (!available)
- continue;
- success=ReadFile(ahandle,readbuffer,sizeof(readbuffer),&transfered,NULL);
- if (success && transfered)
- output->append(readbuffer, 4096);
- } while (available>0);
-}
-
+ } + void setSrmmIcon(HANDLE hContact); + void setClistIcon(HANDLE hContact); + setSrmmIcon(hContact); + setClistIcon(hContact); + enc = enc?0:1; + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.flags = CMIM_NAME; + enc?mi.pszName="Turn off GPG encryption":mi.pszName="Turn on GPG encryption"; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi); + return 0; +} + +int OnPreBuildContactMenu(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + if(isProtoMetaContacts(hContact)) + hContact = metaGetMostOnline(hContact); + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.flags = CMIM_NAME; + TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + if(_tcslen(tmp) < 1) + { + DBDeleteContactSetting(hContact, szGPGModuleName, "GPGEncryption"); + mi.flags += CMIM_FLAGS | CMIF_GRAYED; + } + else + mi.flags = CMIM_NAME | CMIM_FLAGS; + mi.pszName = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?"Turn off GPG encryption":"Turn on GPG encryption"; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi); + return 0; +} + + +void storeOutput(HANDLE ahandle, string *output) +{ + BOOL success; + char readbuffer[4096] = {0}; + unsigned long transfered, available; + + do { + PeekNamedPipe(ahandle,NULL,0,NULL,&available,NULL); + if (!available) + continue; + success=ReadFile(ahandle,readbuffer,sizeof(readbuffer),&transfered,NULL); + if (success && transfered) + output->append(readbuffer, 4096); + } while (available>0); +} + void HistoryLog(HANDLE hContact, char *data, int event_type, int flags) { DBEVENTINFO Event = {0}; @@ -411,58 +411,58 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU extern TCHAR *password; string out; DWORD code; - wstring cmd;
- {
- TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
- if(_tcslen(tmp) > 0)
- {
- cmd += _T("--passphrase \"");
- cmd += tmp;
- cmd += _T("\" ");
- }
- else if(password)
- {
- cmd += _T("--passphrase \"");
- cmd += password;
- cmd += _T("\" ");
- }
- mir_free(tmp);
+ wstring cmd; + { + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); + if(_tcslen(tmp) > 0) + { + cmd += _T("--passphrase \""); + cmd += tmp; + cmd += _T("\" "); + } + else if(password) + { + cmd += _T("--passphrase \""); + cmd += password; + cmd += _T("\" "); + } + mir_free(tmp); } - cmd += _T("--default-key ");
- path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T(""));
- cmd += path_c;
- mir_free(path_c);
+ cmd += _T("--default-key "); + path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T("")); + cmd += path_c; + mir_free(path_c); cmd += _T(" --batch --yes -a -s \""); cmd += path_out; - cmd += _T("\" ");
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
+ cmd += _T("\" "); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); + if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- }
+ TerminateThread(gpg_thread, 0); + MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + } + if(result == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + } DeleteFile(path_out.c_str()); path_out += _T(".asc"); f.open(path_out.c_str(), std::ios::in); - wstring data;
- while(!f.eof() && f.is_open())
- {
- TCHAR tmp[128];
- f.getline(tmp, 128);
- data.append(tmp);
- data.append(_T("\n"));
- }
+ wstring data; + while(!f.eof() && f.is_open()) + { + TCHAR tmp[128]; + f.getline(tmp, 128); + data.append(tmp); + data.append(_T("\n")); + } DeleteFile(path_out.c_str()); if(data.find(_T("-----BEGIN PGP MESSAGE-----")) != wstring::npos && data.find(_T("-----END PGP MESSAGE-----")) != wstring::npos) { |