summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-08-10 03:56:41 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-08-10 03:56:41 +0300
commit36a60a8021dc0fa84ce13677f69e5a3f1428fe5b (patch)
tree4b90b38a42d2dc3c1c8ebf8f7f350fd3a8dd8404
parent329ad737e54ed5972a727105301877750011d9b3 (diff)
modified: commonheaders.h
new file: gpg_wrapper.cpp new file: gpg_wrapper.h modified: init.cpp modified: main.cpp new file: messages.cpp modified: new_gpg.vcproj modified: utilities.cpp modified: utilities.h
-rw-r--r--commonheaders.h1
-rw-r--r--gpg_wrapper.cpp99
-rw-r--r--gpg_wrapper.h18
-rw-r--r--init.cpp230
-rw-r--r--main.cpp31
-rw-r--r--messages.cpp17
-rw-r--r--new_gpg.vcproj20
-rw-r--r--utilities.cpp17
-rw-r--r--utilities.h2
9 files changed, 295 insertions, 140 deletions
diff --git a/commonheaders.h b/commonheaders.h
index 39e128f..9375e71 100644
--- a/commonheaders.h
+++ b/commonheaders.h
@@ -47,4 +47,5 @@ using std::wfstream;
#include "utilities.h"
#include "globals.h"
#include "main.h"
+#include "gpg_wrapper.h"
#endif
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp
new file mode 100644
index 0000000..e2cfad6
--- /dev/null
+++ b/gpg_wrapper.cpp
@@ -0,0 +1,99 @@
+// 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(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode)
+{
+ 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;
+
+ 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)
+ {
+ return pxCreatePipeFailed;
+ }
+
+ success=CreatePipe(&readstdout,&newstdout,&sattrs,0);
+ if (!success)
+ {
+ CloseHandle(newstdin);
+ CloseHandle(writestdin);
+ return pxCreatePipeFailed;
+ }
+
+ GetStartupInfo(&sinfo);
+ sinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
+ sinfo.wShowWindow=SW_HIDE;
+ sinfo.hStdOutput=newstdout;
+ sinfo.hStdError=newstdout;
+ sinfo.hStdInput=newstdin;
+
+ success = CreateProcess(NULL, acommandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
+
+ if (!success)
+ {
+ CloseHandle(newstdin);
+ CloseHandle(writestdin);
+ CloseHandle(newstdout);
+ CloseHandle(readstdout);
+ 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;
+ }
+
+ storeOutput(readstdout,aoutput);
+ WaitForSingleObject(pri.hProcess,INFINITE);
+
+ CloseHandle(pri.hThread);
+ CloseHandle(pri.hProcess);
+ CloseHandle(newstdin);
+ CloseHandle(newstdout);
+ CloseHandle(readstdout);
+ CloseHandle(writestdin);
+
+ return pxSuccess;
+}
diff --git a/gpg_wrapper.h b/gpg_wrapper.h
new file mode 100644
index 0000000..1139c51
--- /dev/null
+++ b/gpg_wrapper.h
@@ -0,0 +1,18 @@
+#ifndef GPG_WRAPPER_H
+#define GPG_WRAPPER_H
+typedef enum {
+ pxSuccess,
+ pxSuccessExitCodeInvalid,
+ pxCreatePipeFailed,
+ pxDuplicateHandleFailed,
+ pxCloseHandleFailed,
+ pxCreateProcessFailed,
+ pxThreadWaitFailed,
+ pxReadFileFailed,
+ pxBufferOverflow
+}
+pxResult;
+
+pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode);
+
+#endif \ No newline at end of file
diff --git a/init.cpp b/init.cpp
index a36db70..5b07200 100644
--- a/init.cpp
+++ b/init.cpp
@@ -1,116 +1,116 @@
-// 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"
-
-
-HINSTANCE hInst;
-HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL;
-PLUGINLINK *pluginLink;
-static int OnModulesLoaded(WPARAM wParam,LPARAM lParam);
-extern char *date();
-MM_INTERFACE mmi = {0};
-UTF8_INTERFACE utfi = {0};
-
-
-#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,1),
- "new GPG encryption support plugin",
- "sss",
- "sss123next@list.ru",
- "© 2010 sss",
- "http://sss.chaoslab.ru/tracker/mim_plugs/",
- 1, //unicode
- 0, //doesn't replace anything built-in
+// 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"
+
+
+HINSTANCE hInst;
+HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL;
+PLUGINLINK *pluginLink;
+static int OnModulesLoaded(WPARAM wParam,LPARAM lParam);
+extern char *date();
+MM_INTERFACE mmi = {0};
+UTF8_INTERFACE utfi = {0};
+
+
+#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,1),
+ "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, szModuleName" [");
- 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);
-
-extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
-{
- pluginLink=link;
- HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
- mir_getMMI(&mmi);
- mir_getUTFI(&utfi);
- CreateServiceFunction("/LoadPubKey",LoadKey);
- CreateServiceFunction("/ToggleEncryption",ToggleEncryption);
- 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);
- return 0;
-}
-
-
-static int OnModulesLoaded(WPARAM wParam,LPARAM lParam)
-{
- int GpgOptInit(WPARAM wParam,LPARAM lParam);
- int gpg_init();
- int OnPreBuildContactMenu(WPARAM w, LPARAM l);
- HookEvent(ME_OPT_INITIALISE, GpgOptInit);
- hOnPreBuildContactMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu);
- gpg_init();
- return 0;
-}
-
-
-extern "C" int __declspec(dllexport) Unload(void)
-{
- return 0;
-}
+};
+
+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, szModuleName" [");
+ 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);
+
+extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
+{
+ pluginLink=link;
+ HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+ mir_getMMI(&mmi);
+ mir_getUTFI(&utfi);
+ CreateServiceFunction("/LoadPubKey",LoadKey);
+ CreateServiceFunction("/ToggleEncryption",ToggleEncryption);
+ 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);
+ return 0;
+}
+
+
+static int OnModulesLoaded(WPARAM wParam,LPARAM lParam)
+{
+ void test();
+ int GpgOptInit(WPARAM wParam,LPARAM lParam);
+ int OnPreBuildContactMenu(WPARAM w, LPARAM l);
+ test();
+ HookEvent(ME_OPT_INITIALISE, GpgOptInit);
+ hOnPreBuildContactMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu);
+ return 0;
+}
+
+
+extern "C" int __declspec(dllexport) Unload(void)
+{
+ return 0;
+}
diff --git a/main.cpp b/main.cpp
index 180bbae..6ad5032 100644
--- a/main.cpp
+++ b/main.cpp
@@ -19,25 +19,14 @@
#include "commonheaders.h"
-int gpg_init()
+void test()
{
-/* setlocale (LC_ALL, "");
- gpgme_check_version (NULL);
- gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
-#ifdef LC_MESSAGES
- gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
-#endif
- gpgme_error_t err;
- gpgme_ctx_t ctx;
- err = gpgme_new(&ctx);
- TCHAR error[128];
- mir_sntprintf(error, 128, _T("%d"), error);
- MessageBox(0, error, _T("info"), MB_OK);
- gpgme_protocol_t proto = GPGME_PROTOCOL_OpenPGP;
- char *tmp = mir_t2a(UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T("")));
- char *tmp2 = mir_t2a(UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T("")));
- gpgme_ctx_set_engine_info(ctx, proto, tmp, tmp2);
- mir_free(tmp);
- mir_free(tmp2); */
- return 0;
-}
+ DWORD exitcode;
+ string output;
+ TCHAR *bin_path = UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T(""));
+ TCHAR bin[512];
+ _tcscpy(bin, bin_path);
+ _tcscat(bin, _T(" --help"));
+ pxResult pxresult=pxExecute(bin,"",&output,&exitcode);
+ MessageBoxA(0, output.c_str(), "", MB_OK);
+} \ No newline at end of file
diff --git a/messages.cpp b/messages.cpp
new file mode 100644
index 0000000..5e8b4de
--- /dev/null
+++ b/messages.cpp
@@ -0,0 +1,17 @@
+// 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"
diff --git a/new_gpg.vcproj b/new_gpg.vcproj
index b09872b..5964dba 100644
--- a/new_gpg.vcproj
+++ b/new_gpg.vcproj
@@ -178,10 +178,10 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="libgcrypt-11.lib libgpgme-11.lib libksba-8.lib"
+ AdditionalDependencies=""
LinkIncremental="2"
SuppressStartupBanner="true"
- AdditionalLibraryDirectories="X:\install\git\miranda\mim_plugs\lib"
+ AdditionalLibraryDirectories=""
GenerateDebugInformation="true"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
@@ -277,10 +277,10 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="libgcrypt-11.lib libgpgme-11.lib libksba-8.lib"
+ AdditionalDependencies=""
LinkIncremental="1"
SuppressStartupBanner="true"
- AdditionalLibraryDirectories="X:\install\git\miranda\mim_plugs\lib"
+ AdditionalLibraryDirectories=""
GenerateDebugInformation="false"
SubSystem="0"
OptimizeReferences="2"
@@ -616,6 +616,10 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
+ RelativePath=".\gpg_wrapper.cpp"
+ >
+ </File>
+ <File
RelativePath=".\init.cpp"
>
<FileConfiguration
@@ -641,6 +645,10 @@
</FileConfiguration>
</File>
<File
+ RelativePath=".\messages.cpp"
+ >
+ </File>
+ <File
RelativePath=".\options.cpp"
>
</File>
@@ -666,6 +674,10 @@
>
</File>
<File
+ RelativePath=".\gpg_wrapper.h"
+ >
+ </File>
+ <File
RelativePath=".\main.h"
>
</File>
diff --git a/utilities.cpp b/utilities.cpp
index 44121cd..f2d717d 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -200,3 +200,20 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM l)
CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi);
return 0;
}
+
+
+void storeOutput(HANDLE ahandle, string *output)
+{
+ BOOL success;
+ char readbuffer[10];
+ 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, 10);
+ } while (available>0);
+}
diff --git a/utilities.h b/utilities.h
index f8d4602..73a451f 100644
--- a/utilities.h
+++ b/utilities.h
@@ -21,4 +21,6 @@ void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szEx
TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file = false);
void GetFolderPath(TCHAR *WindowTittle, char *szSetting);
+void storeOutput(HANDLE ahandle, string *output);
+
#endif