diff options
| author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-14 15:12:56 +0300 | 
|---|---|---|
| committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-14 15:12:56 +0300 | 
| commit | 86cafe5f5e47960cb8962fd555612aeb2d288285 (patch) | |
| tree | 43d96003c93b7f1d8f186d51f0276f9b7af46d68 | |
| parent | c7afab6ec1a5bde6295c96abac0710cfcb3c84cd (diff) | |
	modified:   main.cpp
	modified:   messages.cpp
	modified:   new_gpg.rc
	modified:   resource.h
| -rw-r--r-- | main.cpp | 130 | ||||
| -rw-r--r-- | messages.cpp | 52 | ||||
| -rw-r--r-- | new_gpg.rc | 34 | ||||
| -rw-r--r-- | resource.h | 11 | 
4 files changed, 181 insertions, 46 deletions
| @@ -30,7 +30,7 @@ void test()  }
 -HWND hwndFirstRun = NULL, hwndSetDirs = NULL;
 +HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL;
  int itemnum = 0;
 @@ -282,6 +282,64 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP    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, szModuleName, "GPGPubKey", _T(""));
 +		SetDlgItemText(hwndDlg, IDC_MESSAGE, (_tcslen(tmp) > 0)?_T("There is existing key for contact, do you want to replace with new key ?"):_T("New public key was received, do you want to import it?"));
 +		mir_free(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, szModuleName, "GPGEncryption", 1);
 +		  DestroyWindow(hwndDlg);
 +		  break;
 +	  case IDC_IGNORE_KEY:
 +		  DestroyWindow(hwndDlg);
 +		  break;
 +	  default:
 +		break;
 +      }
 +      
 +      break;
 +    }
 +    
 +  case WM_NOTIFY:
 +    {
 +      switch (((LPNMHDR)lParam)->code)
 +      {
 +      }
 +	}
 +    break;
 +  case WM_CLOSE:
 +	  DestroyWindow(hwndDlg);
 +	  break;
 +  case WM_DESTROY:
 +	  hwndFirstRun = NULL;
 +	  break;
 +
 +  }
 +  return FALSE;
 +}
 +
  extern HINSTANCE hInst;
 @@ -305,6 +363,13 @@ void ShowSetDirsDialog()  	SetForegroundWindow(hwndSetDirs);
  }
 +void ShowNewKeyDialog()
 +{
 +	hwndNewKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_NEW_KEY), NULL, DlgProcNewKeyDialog);
 +	SetForegroundWindow(hwndNewKey);
 +}
 +
 +
  void FirstRun()
  {
 @@ -313,3 +378,66 @@ void FirstRun()  		return;
  	ShowSetDirsDialog();
  }
 +
 +void ImportKey()
 +{
 +	extern wstring new_key;
 +	extern HANDLE new_key_hcnt;
 +	DBWriteContactSettingTString(new_key_hcnt, szModuleName, "GPGPubKey", new_key.c_str());
 +	{ //gpg execute block
 +		wstring cmd;
 +		TCHAR tmp2[MAX_PATH] = {0};
 +		TCHAR *ptmp;
 +		string output;
 +		DWORD exitcode;
 +		{
 +			ptmp = UniGetContactSettingUtf(NULL, szModuleName, "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, szModuleName, "GPGPubKey", _T(""));
 +			wstring new_key = ptmp;
 +			mir_free(ptmp);
 +			f<<new_key.c_str();
 +			f.close();
 +			cmd += _T(" --trust-model always ");
 +			cmd += _T(" --import \"");
 +			cmd += tmp2;
 +			cmd += _T("\"");
 +		}
 +		if(pxExecute(&cmd, "", &output, &exitcode) == pxNotFound)
 +		{
 +			MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);				  
 +		}
 +		cp866_to_cp1251(&output);
 +		{
 +			string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
 +			string::size_type s2 = output.find(":", s);
 +			DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyID", output.substr(s,s2-s).c_str());
 +			s2+=2;
 +			s = output.find("\"", s2)-1;
 +			if(s != s2-1)
 +				DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyType", output.substr(s2,s-s2).c_str());
 +			s+=2;
 +			if((s2 = output.find("(", s)) == string::npos)
 +				s2 = output.find("<", s);
 +			DBWriteContactSettingString(new_key_hcnt, 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(new_key_hcnt, szModuleName, "KeyComment", output.substr(s2,s-s2).c_str());
 +				s+=3;
 +				s2 = output.find(">", s);
 +				DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str());
 +			}
 +			else
 +				DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str());
 +		}
 +		MessageBoxA(0, output.c_str(), "", MB_OK);
 +		DeleteFile(tmp2);
 +	}
 +}
\ No newline at end of file diff --git a/messages.cpp b/messages.cpp index 5214429..960d063 100644 --- a/messages.cpp +++ b/messages.cpp @@ -16,6 +16,10 @@  #include "commonheaders.h"
 +
 +wstring new_key;
 +HANDLE new_key_hcnt = NULL;
 +
  int RecvMsgSvc(WPARAM w, LPARAM l)
  {
  	CCSDATA *ccs = (CCSDATA*)l;
 @@ -41,6 +45,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l)  		{  //this is public key
  			if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
  				;//
 +			void ShowNewKeyDialog();
 +/*			if(key_action == 3)
 +				return CallService(MS_PROTO_CHAINRECV, w, l);
 +			else if(key_action == 2)
 +				DBWriteContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 1); */
  			s1 = 0;
  			while((s1 = str.find(_T("\r"), s1)) != wstring::npos)
  			{
 @@ -49,39 +58,10 @@ int RecvMsgSvc(WPARAM w, LPARAM l)  			s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----"));
  			s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"));
  			s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
 -			DBWriteContactSettingTString(ccs->hContact, szModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str());
 -			{ //gpg execute block
 -				wstring cmd;
 -				TCHAR tmp2[MAX_PATH] = {0};
 -				TCHAR *ptmp;
 -				string output;
 -				DWORD exitcode;
 -				{
 -					ptmp = UniGetContactSettingUtf(NULL, szModuleName, "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(ccs->hContact, szModuleName, "GPGPubKey", _T(""));
 -					wstring str = ptmp;
 -					mir_free(ptmp);
 -					f<<str.c_str();
 -					f.close();
 -					cmd += _T(" --trust-model always ");
 -					cmd += _T(" --import \"");
 -					cmd += tmp2;
 -					cmd += _T("\"");
 -				}
 -				if(pxExecute(&cmd, "", &output, &exitcode) == pxNotFound)
 -				{
 -					MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);				  
 -					return CallService(MS_PROTO_CHAINRECV, w, l);
 -				}
 -				cp866_to_cp1251(&output);
 -				MessageBoxA(0, output.c_str(), "", MB_OK);
 -				DeleteFile(tmp2);
 -			}
 +			new_key.append(str.substr(s1,s2-s1));
 +			new_key_hcnt = ccs->hContact;
 +			ShowNewKeyDialog();
 +			return CallService(MS_PROTO_CHAINRECV, w, l);
  		}
  		s1 = str.find(_T("-----BEGIN PGP MESSAGE-----"));
  		s2 = str.find(_T("-----END PGP MESSAGE-----"));
 @@ -221,6 +201,7 @@ int SendMsgSvc(WPARAM w, LPARAM l)  				mir_free(tmp);
  				return CallService(MS_PROTO_CHAINSEND, w, l);
  			}
 +			cmd += _T("--comment \"\" --no-version ");
  			cmd += _T("--trust-model always ");
  			cmd += _T("--batch --yes -e -a -r ");
  			TCHAR *tmp2 = mir_a2t(tmp);
 @@ -272,12 +253,13 @@ int SendMsgSvc(WPARAM w, LPARAM l)  				return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs);
  			}
  			mir_free((void**)ccs->lParam);
 -			char *utf = mir_utf8encodeW(str.c_str());
 +			char *utf = mir_u2a(str.c_str());
  			ccs->lParam = (LPARAM)utf;
  			if(bAppendTags)
  				DBWriteContactSettingByte(ccs->hContact, szModuleName, "MsgsForTagging", DBGetContactSettingByte(ccs->hContact, szModuleName, "MsgsForTagging", 0) + 1);
  		}		
  	}
 +	ccs->wParam&=~PREF_UNICODE;
  	return CallService(MS_PROTO_CHAINSEND, w, l);
  }
 @@ -311,4 +293,4 @@ int HookSendMsg(WPARAM w, LPARAM l)  		}
  	}
  	return 0;
 -}
\ No newline at end of file +}
 @@ -75,18 +75,29 @@ BEGIN      RTEXT           "Key password:",IDC_STATIC,107,80,81,8
  END
 -IDD_BIN_PATH DIALOGEX 0, 0, 178, 89
 +IDD_BIN_PATH DIALOGEX 0, 0, 354, 89
  STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
  CAPTION "Set GPG bin path and keyring home dir."
  FONT 8, "MS Shell Dlg", 400, 0, 0x1
  BEGIN
      DEFPUSHBUTTON   "ОК",ID_OK,7,68,50,14
 -    PUSHBUTTON      "Browse",IDC_SET_BIN_PATH,116,18,38,14
 -    PUSHBUTTON      "Browse",IDC_SET_HOME_DIR,116,44,38,14
 -    EDITTEXT        IDC_BIN_PATH,7,17,95,14,ES_AUTOHSCROLL
 -    EDITTEXT        IDC_HOME_DIR,7,44,95,14,ES_AUTOHSCROLL
 +    PUSHBUTTON      "Browse",IDC_SET_BIN_PATH,293,18,38,14
 +    PUSHBUTTON      "Browse",IDC_SET_HOME_DIR,293,44,38,14
 +    EDITTEXT        IDC_BIN_PATH,7,17,277,14,ES_AUTOHSCROLL
 +    EDITTEXT        IDC_HOME_DIR,7,44,277,14,ES_AUTOHSCROLL
      LTEXT           "GnuPG2 binary:",IDC_STATIC,10,7,147,8
 -    LTEXT           "Home directory:",IDC_STATIC,9,34,144,8
 +    LTEXT           "Home directory:",IDC_STATIC,9,34,325,8
 +END
 +
 +IDD_NEW_KEY DIALOGEX 0, 0, 427, 68
 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 +CAPTION "New public key recieved"
 +FONT 8, "MS Shell Dlg", 400, 0, 0x1
 +BEGIN
 +    DEFPUSHBUTTON   "Import key",ID_IMPORT,9,47,46,14
 +    PUSHBUTTON      "Import key end turn on encryption",IDC_IMPORT_AND_USE,61,47,119,14
 +    PUSHBUTTON      "Ignore key",IDC_IGNORE_KEY,183,47,52,14
 +    CTEXT           "Статический",IDC_MESSAGE,19,25,392,8
  END
 @@ -117,10 +128,19 @@ BEGIN      IDD_BIN_PATH, DIALOG
      BEGIN
          LEFTMARGIN, 7
 -        RIGHTMARGIN, 171
 +        RIGHTMARGIN, 347
 +        VERTGUIDE, 284
          TOPMARGIN, 7
          BOTTOMMARGIN, 82
      END
 +
 +    IDD_NEW_KEY, DIALOG
 +    BEGIN
 +        LEFTMARGIN, 7
 +        RIGHTMARGIN, 420
 +        TOPMARGIN, 6
 +        BOTTOMMARGIN, 61
 +    END
  END
  #endif    // APSTUDIO_INVOKED
 @@ -8,6 +8,8 @@  #define IDD_OPT_GPG_BIN                 105
  #define IDD_BIN_PATH                    106
  #define IDD_OPT_GPG_MESSAGES            107
 +#define IDD_DIALOG1                     108
 +#define IDD_NEW_KEY                     108
  #define IDC_SET_BIN_PATH                1016
  #define IDC_SET_HOME_DIR                1017
  #define IDC_BIN_PATH                    1018
 @@ -24,22 +26,25 @@  #define IDC_BUTTON1                     1026
  #define IDC_SAVE_KEY_BUTTON             1026
  #define IDC_GENERATE_KEY                1026
 +#define IDC_IGNORE_KEY                  1026
  #define IDC_DELETE_KEY_BUTTON           1027
  #define IDC_IN_CLOSE_TAG                1027
  #define IDC_KEY_LIST                    1028
  #define IDC_OUT_OPEN_TAG                1029
  #define IDC_APPEND_TAGS                 1030
  #define IDC_OUT_CLOSE_TAG               1031
 -#define IDC_BUTTON2                     1033
  #define IDC_SELECT_KEY                  1033
 +#define IDC_MESSAGE                     1034
 +#define ID_IMPORT                       1035
 +#define IDC_IMPORT_AND_USE              1036
  // Next default values for new objects
  // 
  #ifdef APSTUDIO_INVOKED
  #ifndef APSTUDIO_READONLY_SYMBOLS
 -#define _APS_NEXT_RESOURCE_VALUE        107
 +#define _APS_NEXT_RESOURCE_VALUE        109
  #define _APS_NEXT_COMMAND_VALUE         40001
 -#define _APS_NEXT_CONTROL_VALUE         1034
 +#define _APS_NEXT_CONTROL_VALUE         1037
  #define _APS_NEXT_SYMED_VALUE           101
  #endif
  #endif
 | 
