summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-09-16 06:07:04 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-09-16 06:07:04 +0300
commit47318893c6ac81644b8c81bc6f58610cd624568d (patch)
treefd214d63a797392b3a7ba3aa80ef5cb9b795fcbc
parent73815a8f028cee1caf3e7ce597fbb409cc0c5396 (diff)
added autoassigning existing key for contact with gpg sign in prescense, import from keyserver later
-rw-r--r--messages.cpp2
-rw-r--r--options.cpp53
-rw-r--r--utilities.cpp20
3 files changed, 73 insertions, 2 deletions
diff --git a/messages.cpp b/messages.cpp
index 9dfe9d7..a97e433 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -42,6 +42,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
{ //check for gpg related data
wchar_t *tmp = mir_utf8decodeW(msg);
+ if(!tmp)
+ tmp = mir_a2t(msg);
wstring str = tmp;
mir_free(tmp);
wstring::size_type s1 = wstring::npos, s2 = wstring::npos;
diff --git a/options.cpp b/options.cpp
index 5dafb05..4f73d32 100644
--- a/options.cpp
+++ b/options.cpp
@@ -624,6 +624,59 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
}
}
}
+ char *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID_Prescense", "");
+ if(strlen(tmp) > 0)
+ {
+ char *tmp2 = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", "");
+ if(strlen(tmp2) == 0)
+ {
+ string out;
+ DWORD code;
+ wstring cmd = _T(" --export -a ");
+ TCHAR *tmp3 = mir_a2t(tmp);
+ cmd += tmp3;
+ mir_free(tmp3);
+ 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*)&params);
+ 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);
+ }
+ if((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos))
+ {
+ string::size_type p = 0, stop = 0;
+ for(;;)
+ {
+ if((p = out.find("\n", p+2)) != string::npos)
+ {
+ if(p > stop)
+ {
+ stop = p;
+ out.insert(p, "\r");
+ }
+ else
+ break;
+ }
+ }
+ TCHAR *tmp = mir_a2t(out.c_str());
+ str.clear();
+ str.append(tmp);
+ }
+ }
+ mir_free(tmp2);
+ }
+ mir_free(tmp);
SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T(""));
}
hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT);
diff --git a/utilities.cpp b/utilities.cpp
index 9cba16a..dbff3b0 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -614,8 +614,24 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
if(out.find("key ID ") != string::npos)
{
//need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ?
- string::size_type p = out.find("key ID ") + strlen("key ID ");
- string::size_type p2 = out.find("\n", p);
+ string::size_type p1 = out.find("key ID ") + strlen("key ID ");
+ string::size_type p2 = out.find("\n", p1);
+ if(p1 != string::npos && p2 != string::npos)
+ {
+ HANDLE hContact = NULL;
+ {
+ extern list <JabberAccount*> Accounts;
+ list <JabberAccount*>::iterator p = Accounts.begin();
+ for(unsigned int i = 0; i < Accounts.size(); i++, p++)
+ {
+ if(!(*p))
+ break;
+ hContact = (*p)->getJabberInterface()->Sys()->ContactFromJID(xi.getAttrValue(node, _T("from")));
+ if(hContact)
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID_Prescense", out.substr(p1, p2-p1-1).c_str());
+ }
+ }
+ }
}
}
return FALSE;