summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-08-28 10:19:59 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-08-28 10:19:59 +0300
commit3cbb1a2bf5892b58af4f344ee4648c8139a3ea8b (patch)
treed7407fa2b8e511f02fab1bcd89c8628f82106010
parent634d16d7a56e8ba72fda7b6f1896970b96b331ff (diff)
basic metacontacts support code
-rw-r--r--messages.cpp48
-rw-r--r--metacontacts.cpp12
-rw-r--r--new_gpg.rc4
3 files changed, 40 insertions, 24 deletions
diff --git a/messages.cpp b/messages.cpp
index 10be19f..ef4ddea 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -20,6 +20,9 @@
wstring new_key;
HANDLE new_key_hcnt = NULL;
+BOOL isProtoMetaContacts(HANDLE hContact);
+HANDLE getMostOnline(HANDLE hContact);
+
int RecvMsgSvc(WPARAM w, LPARAM l)
{
CCSDATA *ccs = (CCSDATA*)l;
@@ -32,6 +35,10 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
if (!msg)
return CallService(MS_PROTO_CHAINRECV, w, l);
BOOL unicode = (BOOL)(pre->flags&PREF_UNICODE);
+ HANDLE hContact = ccs->hContact;
+ if(isProtoMetaContacts(hContact))
+ hContact = getMostOnline(hContact);
+
{ //check for gpg related data
wchar_t *tmp = mir_utf8decodeW(msg);
@@ -72,7 +79,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----"));
}
new_key.append(str.substr(s1,s2-s1));
- new_key_hcnt = ccs->hContact;
+ new_key_hcnt = hContact;
ShowNewKeyDialog();
return CallService(MS_PROTO_CHAINRECV, w, l);
}
@@ -83,30 +90,30 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
void setSrmmIcon(HANDLE);
void setClistIcon(HANDLE);
bool isContactHaveKey(HANDLE hContact);
- if(!DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0))
+ if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
{
if(MessageBox(0, _T("We received encrypted message from contact with encryption turned off.\nDo you want turn on encryption for this contact ?"), _T("Warning"), MB_YESNO) == IDYES)
{
- if(!isContactHaveKey(ccs->hContact))
+ if(!isContactHaveKey(hContact))
{
void ShowLoadPublicKeyDialog();
extern map<int, HANDLE> user_data;
extern int item_num;
item_num = 0; //black magic here
- user_data[1] = ccs->hContact;
+ user_data[1] = hContact;
ShowLoadPublicKeyDialog();
}
else
{
- DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1);
- setSrmmIcon(ccs->hContact);
- setClistIcon(ccs->hContact);
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
+ setSrmmIcon(hContact);
+ setClistIcon(hContact);
}
- if(isContactHaveKey(ccs->hContact))
+ if(isContactHaveKey(hContact))
{
- DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1);
- setSrmmIcon(ccs->hContact);
- setClistIcon(ccs->hContact);
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
+ setSrmmIcon(hContact);
+ setClistIcon(hContact);
}
}
else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO)
@@ -286,7 +293,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
}
}
}
- if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0))
+ if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
{
wchar_t *tmp = mir_utf8decodeW(msg);
wstring str = tmp;
@@ -312,6 +319,9 @@ int SendMsgSvc(WPARAM w, LPARAM l)
if (!msg)
return CallService(MS_PROTO_CHAINSEND, w, l);
BOOL unicode = (BOOL)(ccs->wParam&PREF_UNICODE);
+ HANDLE hContact = ccs->hContact;
+ if(isProtoMetaContacts(hContact))
+ hContact = getMostOnline(hContact);
{ //encrypt data here
wchar_t *tmp = mir_utf8decodeW(msg);
@@ -323,16 +333,16 @@ int SendMsgSvc(WPARAM w, LPARAM l)
wstring cmd;
wstring path;
extern bool bJabberAPI, bIsMiranda09;
- char *tmp = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", "");
+ char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
if(strlen(tmp) < 2)
{
mir_free(tmp);
- HistoryLog(ccs->hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT);
+ HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT);
return CallService(MS_PROTO_CHAINSEND, w, l);
}
if(!bJabberAPI || !bIsMiranda09)
cmd += _T("--comment \"\" --no-version ");
- if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 0))
+ if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0))
cmd += _T("--trust-model always ");
cmd += _T("--batch --yes -e -a -r ");
TCHAR *tmp2 = mir_a2t(tmp);
@@ -381,7 +391,7 @@ int SendMsgSvc(WPARAM w, LPARAM l)
out.clear();
if(MessageBox(0, _T("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), _T("Warning"), MB_YESNO) == IDYES)
{
- DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 1);
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 1);
cmd.insert(0, _T("--trust-model always "));
gpg_execution_params params;
pxResult result;
@@ -423,14 +433,14 @@ int SendMsgSvc(WPARAM w, LPARAM l)
DeleteFile(path.c_str());
if(!str.length())
{
- HistoryLog(ccs->hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT);
+ HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT);
return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs);
}
mir_free((void**)ccs->lParam);
char *utf = mir_u2a(str.c_str());
ccs->lParam = (LPARAM)utf;
if(bAppendTags)
- DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "MsgsForTagging", DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "MsgsForTagging", 0) + 1);
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "MsgsForTagging", 0) + 1);
}
}
ccs->wParam&=~PREF_UNICODE;
@@ -440,6 +450,8 @@ int SendMsgSvc(WPARAM w, LPARAM l)
int HookSendMsg(WPARAM w, LPARAM l)
{
HANDLE hContact = (HANDLE)w;
+ if(isProtoMetaContacts(hContact))
+ hContact = getMostOnline(hContact);
if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
return 0;
diff --git a/metacontacts.cpp b/metacontacts.cpp
index 4540419..a830c52 100644
--- a/metacontacts.cpp
+++ b/metacontacts.cpp
@@ -18,7 +18,8 @@
extern bool bMetaContacts;
-BOOL isProtoMetaContacts(HANDLE hContact) {
+BOOL isProtoMetaContacts(HANDLE hContact)
+{
if(bMetaContacts) {
LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
if( proto && strcmp(proto,"MetaContacts")==0 ) {
@@ -32,7 +33,8 @@ BOOL isProtoMetaContacts(HANDLE hContact) {
}
-BOOL isDefaultSubContact(HANDLE hContact) {
+BOOL isDefaultSubContact(HANDLE hContact)
+{
if(bMetaContacts) {
return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0),0)==hContact;
@@ -41,7 +43,8 @@ BOOL isDefaultSubContact(HANDLE hContact) {
}
-HANDLE getMetaContact(HANDLE hContact) {
+HANDLE getMetaContact(HANDLE hContact)
+{
if(bMetaContacts) {
return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0);
@@ -50,7 +53,8 @@ HANDLE getMetaContact(HANDLE hContact) {
}
-HANDLE getMostOnline(HANDLE hContact) {
+HANDLE getMostOnline(HANDLE hContact)
+{
if(bMetaContacts) {
return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0);
diff --git a/new_gpg.rc b/new_gpg.rc
index 7f5117c..8bd1dff 100644
--- a/new_gpg.rc
+++ b/new_gpg.rc
@@ -256,8 +256,8 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
CONTROL "",IDC_USERLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,17,272,112
CTEXT "Userlist:",IDC_STATIC,25,7,201,8
- PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,54,14
- PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,65,135,50,14
+ PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,66,14
+ PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,78,135,70,14
PUSHBUTTON "Select own key",IDC_SELECT_KEY,222,193,57,14
CONTROL "Turn on debug log",IDC_DEBUG_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,159,89,10
EDITTEXT IDC_LOG_FILE_EDIT,11,157,98,14,ES_AUTOHSCROLL