diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-11 02:52:42 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-11 02:52:42 +0300 |
commit | ff34af8edad99fae99b59def8a3d5cce92085a9c (patch) | |
tree | 083fede580c7df94a0a588f5b325bf693bc427a6 | |
parent | 1de40ac790d3218cc10d37f95f9f1a8c573dbe77 (diff) |
modified: commonheaders.h
modified: gpg_wrapper.cpp
modified: gpg_wrapper.h
modified: init.cpp
modified: main.cpp
modified: messages.cpp
modified: options.cpp
modified: utilities.cpp
modified: utilities.h
-rw-r--r-- | commonheaders.h | 6 | ||||
-rw-r--r-- | gpg_wrapper.cpp | 27 | ||||
-rw-r--r-- | gpg_wrapper.h | 3 | ||||
-rw-r--r-- | init.cpp | 32 | ||||
-rw-r--r-- | main.cpp | 13 | ||||
-rw-r--r-- | messages.cpp | 29 | ||||
-rw-r--r-- | options.cpp | 76 | ||||
-rw-r--r-- | utilities.cpp | 17 | ||||
-rw-r--r-- | utilities.h | 1 |
9 files changed, 188 insertions, 16 deletions
diff --git a/commonheaders.h b/commonheaders.h index 9375e71..18d423c 100644 --- a/commonheaders.h +++ b/commonheaders.h @@ -18,6 +18,8 @@ #include <windows.h> #include <locale.h> #include <shlobj.h> +#include <io.h> +#include <errno.h> #include <iostream> #include <map> @@ -29,6 +31,7 @@ using std::string; using std::wstring; #include <fstream> using std::wfstream; +using std::fstream; #define MIRANDA_VER 0x0801 @@ -39,7 +42,8 @@ using std::wfstream; #include <m_clist.h> #include <m_icolib.h> #include <m_skin.h> -#include <m_protocols.h> +#include <m_protomod.h> +#include <m_protosvc.h> #include "resource.h" #include "gpgme.h" diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index e2cfad6..b9e9029 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -29,6 +29,18 @@ pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD a char *inputpos;
unsigned long transfered;
int size;
+
+ TCHAR *bin_path = UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T(""));
+ {
+ if(_waccess(bin_path, 0) == -1)
+ if(errno == ENOENT)
+ {
+ mir_free(bin_path);
+ return pxNotFound;
+ }
+ }
+ TCHAR *home_dir = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
+ TCHAR commandline[4096] = {0};
sattrs.nLength=sizeof(SECURITY_ATTRIBUTES);
sattrs.bInheritHandle=TRUE;
@@ -56,8 +68,21 @@ pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD a sinfo.hStdOutput=newstdout;
sinfo.hStdError=newstdout;
sinfo.hStdInput=newstdin;
+
+ { //form initial command
+ _tcscpy(commandline, _T("\""));
+ _tcscat(commandline, bin_path);
+ _tcscat(commandline, _T("\""));
+ _tcscat(commandline, _T(" --homedir"));
+ _tcscat(commandline, _T(" \""));
+ _tcscat(commandline, home_dir);
+ _tcscat(commandline, _T("\" "));
+ _tcscat(commandline, acommandline);
+ mir_free(bin_path);
+ mir_free(home_dir);
+ }
- success = CreateProcess(NULL, acommandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
+ success = CreateProcess(NULL, commandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
if (!success)
{
diff --git a/gpg_wrapper.h b/gpg_wrapper.h index 1139c51..99d9da8 100644 --- a/gpg_wrapper.h +++ b/gpg_wrapper.h @@ -9,7 +9,8 @@ typedef enum { pxCreateProcessFailed,
pxThreadWaitFailed,
pxReadFileFailed,
- pxBufferOverflow
+ pxBufferOverflow,
+ pxNotFound
}
pxResult;
@@ -97,15 +97,43 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) return 0;
}
+int AddContact(WPARAM w, LPARAM l)
+{
+ CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szModuleName);
+ return 0;
+}
+
static int OnModulesLoaded(WPARAM wParam,LPARAM lParam)
{
- void test();
+
int GpgOptInit(WPARAM wParam,LPARAM lParam);
int OnPreBuildContactMenu(WPARAM w, LPARAM l);
- test();
+ int RecvMsgSvc(WPARAM w, LPARAM l);
+ int SendMsgSvc(WPARAM w, LPARAM l);
+
HookEvent(ME_OPT_INITIALISE, GpgOptInit);
hOnPreBuildContactMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu);
+
+ PROTOCOLDESCRIPTOR pd = {0};
+ pd.cbSize=sizeof(PROTOCOLDESCRIPTOR);
+ pd.szName=szModuleName;
+ pd.type=PROTOTYPE_ENCRYPTION;
+ CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
+
+ CreateProtoServiceFunction(szModuleName,PSR_MESSAGE,RecvMsgSvc);
+ CreateProtoServiceFunction(szModuleName,PSS_MESSAGE,SendMsgSvc);
+ CreateProtoServiceFunction(szModuleName,PSR_MESSAGE"W",RecvMsgSvc);
+ CreateProtoServiceFunction(szModuleName,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)szModuleName))
+ CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szModuleName);
+
+ HookEvent(ME_DB_CONTACT_ADDED,AddContact);
+
+
+
return 0;
}
@@ -24,6 +24,14 @@ void test() DWORD exitcode;
string output;
TCHAR *bin_path = UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T(""));
+ {
+ if(_waccess(bin_path, 0) == -1)
+ if(errno == ENOENT)
+ {
+ mir_free(bin_path);
+ return;
+ }
+ }
TCHAR *home_dir = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
TCHAR bin[512];
_tcscpy(bin, bin_path);
@@ -35,5 +43,8 @@ void test() pxResult pxresult=pxExecute(bin,"",&output,&exitcode);
mir_free(bin_path);
mir_free(home_dir);
- MessageBoxA(0, output.c_str(), "", MB_OK);
+/* fstream f("c:\\str.txt", std::ios::out);
+ f<<output;
+ f.close();
+ MessageBoxA(0, output.c_str(), "", MB_OK); */
}
\ No newline at end of file diff --git a/messages.cpp b/messages.cpp index 5e8b4de..ab492d1 100644 --- a/messages.cpp +++ b/messages.cpp @@ -15,3 +15,32 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
+
+int RecvMsgSvc(WPARAM w, LPARAM l)
+{
+ CCSDATA *ccs = (CCSDATA*)l;
+ if (!ccs)
+ return CallService(MS_PROTO_CHAINRECV, w, l);
+ PROTORECVEVENT *pre = (PROTORECVEVENT*)(ccs->lParam);
+ if (!pre)
+ return CallService(MS_PROTO_CHAINRECV, w, l);
+ char *msg = pre->szMessage;
+ if (!msg)
+ return CallService(MS_PROTO_CHAINRECV, w, l);
+ bool unicode = (bool)(pre->flags&PREF_UNICODE);
+
+ return CallService(MS_PROTO_CHAINRECV, w, l);
+}
+
+int SendMsgSvc(WPARAM w, LPARAM l)
+{
+ CCSDATA *ccs = (CCSDATA*)l;
+ if (!ccs)
+ return CallService(MS_PROTO_CHAINSEND, w, l);
+ char *msg = (char*)(ccs->lParam);
+ if (!msg)
+ return CallService(MS_PROTO_CHAINSEND, w, l);
+ bool unicode = (bool)(ccs->wParam&PREF_UNICODE);
+
+ return CallService(MS_PROTO_CHAINSEND, w, l);
+}
\ No newline at end of file diff --git a/options.cpp b/options.cpp index b5c690d..e1ce214 100644 --- a/options.cpp +++ b/options.cpp @@ -126,7 +126,49 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA return TRUE;
case IDC_DELETE_KEY_BUTTON:
DBDeleteContactSetting(user_data[item_num+1], szModuleName, "GPGPubKey");
+ DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyFingerprint");
+ DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainName");
+ DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyType");
+ DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainEmail");
+ DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyComment");
ListView_SetItemText(hwndList, item_num, 2, _T("not set"));
+ { //gpg execute block
+ TCHAR cmd[40960] = {0};
+ TCHAR tmp2[MAX_PATH] = {0};
+ TCHAR *ptmp;
+ char *tmp;
+ bool keep = false;
+ tmp = GetContactSettingStringA(user_data[item_num+1], szModuleName, "KeyFingerprint", "");
+ for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
+ {
+ if(hContact != user_data[item_num+1])
+ {
+ char *tmp2 = GetContactSettingStringA(hContact, szModuleName, "KeyFingerprint", "");
+ if(!strcmp(tmp, tmp2))
+ {
+ mir_free(tmp2);
+ keep = true;
+ break;
+ }
+ mir_free(tmp2);
+ }
+ }
+ if(keep)
+ {
+ mir_free(tmp);
+ break;
+ }
+ string output;
+ DWORD exitcode;
+ _tcscat(cmd, _T(" --batch"));
+ _tcscat(cmd, _T(" --yes"));
+ _tcscat(cmd, _T(" --delete-key "));
+ ptmp = mir_a2t(tmp);
+ _tcscat(cmd, ptmp);
+ mir_free(ptmp);
+ pxResult pxresult=pxExecute(cmd,"",&output,&exitcode);
+ mir_free(tmp);
+ }
break;
default:
break;
@@ -301,16 +343,9 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP TCHAR *ptmp;
string output;
DWORD exitcode;
- ptmp = UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T(""));
- _tcscpy(cmd, ptmp);
- mir_free(ptmp);
- _tcscat(cmd, _T(" --homedir "));
- _tcscat(cmd, _T("\""));
- ptmp = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
- _tcscat(cmd, ptmp);
- _tcscat(cmd, _T("\""));
_tcscat(cmd, _T(" --import "));
{
+ ptmp = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
_tcscpy(tmp2, ptmp);
mir_free(ptmp);
_tcscat(tmp2, _T("\\"));
@@ -332,6 +367,31 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP }
pxResult pxresult=pxExecute(cmd,"",&output,&exitcode);
cp866_to_cp1251(&output);
+ {
+ string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
+ string::size_type s2 = output.find(":", s);
+ DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyFingerprint", output.substr(s,s2-s).c_str());
+ s2+=2;
+ s = output.find("\"", s2)-1;
+ if(s != s2-1)
+ DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyType", output.substr(s2,s-s2).c_str());
+ s+=2;
+ if((s2 = output.find("(", s)) == string::npos)
+ s2 = output.find("<", s);
+ DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str());
+ if((s = output.find(")", s2)) == string::npos)
+ s = output.find(">", s2);
+ s2++;
+ if(output[s] == ')')
+ {
+ DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyComment", output.substr(s2,s-s2).c_str());
+ s+=3;
+ s2 = output.find(">", s);
+ DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str());
+ }
+ else
+ DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str());
+ }
MessageBoxA(0, output.c_str(), "", MB_OK);
DeleteFile(tmp2);
}
diff --git a/utilities.cpp b/utilities.cpp index e0661a3..49e0c07 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -30,6 +30,19 @@ TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,c return szRes;
}
+char* __stdcall GetContactSettingStringA(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];
@@ -207,7 +220,7 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM l) void storeOutput(HANDLE ahandle, string *output)
{
BOOL success;
- char readbuffer[10];
+ char readbuffer[4096] = {0};
unsigned long transfered, available;
do {
@@ -216,7 +229,7 @@ void storeOutput(HANDLE ahandle, string *output) continue;
success=ReadFile(ahandle,readbuffer,sizeof(readbuffer),&transfered,NULL);
if (success && transfered)
- output->append(readbuffer, 10);
+ output->append(readbuffer, 4096);
} while (available>0);
}
diff --git a/utilities.h b/utilities.h index 423f87c..3f6cf4c 100644 --- a/utilities.h +++ b/utilities.h @@ -17,6 +17,7 @@ #ifndef UTILITIES_H #define UTILITIES_H TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef); +char* __stdcall GetContactSettingStringA(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef); void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc); TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file = false); void GetFolderPath(TCHAR *WindowTittle, char *szSetting); |