summaryrefslogtreecommitdiff
path: root/messages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'messages.cpp')
-rw-r--r--messages.cpp104
1 files changed, 83 insertions, 21 deletions
diff --git a/messages.cpp b/messages.cpp
index ed2108f..6513867 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -22,7 +22,6 @@ HANDLE new_key_hcnt = NULL;
boost::mutex new_key_hcnt_mutex;
bool _terminate = false;
-BOOL isProtoMetaContacts(HANDLE hContact);
int RecvMsgSvc(WPARAM w, LPARAM l)
{
@@ -36,8 +35,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
if (!msg)
return CallService(MS_PROTO_CHAINRECV, w, l);
HANDLE hContact = ccs->hContact;
- if(isProtoMetaContacts(hContact))
- hContact = metaGetMostOnline(hContact);
+// if(isProtoMetaContacts(hContact))
+// hContact = metaGetMostOnline(hContact);
{ //check for gpg related data
@@ -92,7 +91,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
void setSrmmIcon(HANDLE);
void setClistIcon(HANDLE);
bool isContactHaveKey(HANDLE hContact);
- if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
+ if(!DBGetContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 0))
{
debuglog<<"info: "<<"received message from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" whith tyrned off encryption\n";
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)
@@ -108,13 +107,13 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
}
else
{
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
+ DBWriteContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
}
if(isContactHaveKey(hContact))
{
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
+ DBWriteContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
}
@@ -144,7 +143,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
wstring cmd;
cmd += _T("--batch ");
{
- char *inkeyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "InKeyID", "");
+ char *inkeyid = UniGetContactSettingUtf(metaGetCurrent(hContact), szGPGModuleName, "InKeyID", "");
TCHAR *pass = NULL;
if(strlen(inkeyid) > 0)
{
@@ -221,7 +220,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
s = out.find(" ID ", s);
s += strlen(" ID ");
string::size_type s2 = out.find(",",s);
- DBWriteContactSettingString(hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
+ DBWriteContactSettingString(metaGetCurrent(hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
}
void ShowLoadKeyPasswordWindow();
new_key_hcnt_mutex.lock();
@@ -341,14 +340,27 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
str.append(inclosetag);
}
pre->szMessage = mir_utf8encodeW(str.c_str());
+ if(metaIsSubcontact(hContact))
+ {
+ char *msg = mir_utf8encodeW(str.c_str());
+ HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF);
+ mir_free(msg);
+ return 1;
+ }
return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs);
}
}
}
}
}
- if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
+ if(DBGetContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 0))
{
+ if(metaIsSubcontact(hContact))
+ {
+ HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF);
+ mir_free(msg);
+ return 1;
+ }
wchar_t *tmp = mir_utf8decodeW(msg);
wstring str = tmp;
mir_free(tmp);
@@ -358,7 +370,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
}
return CallService(MS_PROTO_CHAINRECV, w, l);
}
-
+list<string*> msgs_to_ignore;
int SendMsgSvc(WPARAM w, LPARAM l)
{
CCSDATA *ccs = (CCSDATA*)l;
@@ -368,11 +380,14 @@ int SendMsgSvc(WPARAM w, LPARAM l)
char *msg = (char*)(ccs->lParam);
if (!msg)
return CallService(MS_PROTO_CHAINSEND, w, l);
+ if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) //metecontacts .... %)
+ return CallService(MS_PROTO_CHAINSEND, w, l);
HANDLE hContact = ccs->hContact;
- if(isProtoMetaContacts(hContact))
- hContact = metaGetMostOnline(hContact);
+ if(metaIsProtoMetaContacts(hContact))
+ return CallService(MS_PROTO_CHAINSEND, w, l);
+// hContact = metaGetCurrent(hContact);
if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
- return CallService(MS_PROTO_CHAINSEND, w, l);
+ return CallService(MS_PROTO_CHAINSEND, w, l);
{ //encrypt data here
@@ -386,13 +401,13 @@ int SendMsgSvc(WPARAM w, LPARAM l)
wstring path;
extern bool bJabberAPI, bIsMiranda09;
char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
- if(strlen(tmp) < 2)
+ if(!tmp[0])
{
mir_free(tmp);
HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT);
return CallService(MS_PROTO_CHAINSEND, w, l);
}
- if(!bJabberAPI || !bIsMiranda09)
+ if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself
cmd += _T("--comment \"\" --no-version ");
if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0))
cmd += _T("--trust-model always ");
@@ -466,6 +481,12 @@ int SendMsgSvc(WPARAM w, LPARAM l)
else
return 0;
}
+ if(out.find("usage: ") != string::npos)
+ {
+ MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encrypting."), _T("Warning"), MB_OK);
+ DeleteFile(path.c_str());
+ return CallService(MS_PROTO_CHAINSEND, w, l);
+ }
DeleteFile(path.c_str());
path.append(_T(".asc"));
wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
@@ -488,9 +509,31 @@ int SendMsgSvc(WPARAM w, LPARAM l)
debuglog<<"info: Failed to encrypt message with GPG";
return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs);
}
+ if(metaIsSubcontact(hContact))
+ { //dirty hack to avoid metacontacts problem ..., this also broke filters chain
+ int returnNoError(HANDLE hContact);
+ string str_event = (char*)ccs->lParam;
+ msgs_to_ignore.push_back(new string(str_event));
+ if(bAppendTags)
+ {
+ char *opentag = mir_utf8encodeW(outopentag);
+ str_event.insert(0, opentag);
+ mir_free(opentag);
+ char *closetag = mir_utf8encodeW(outclosetag);
+ str_event.append(closetag);
+ mir_free(closetag);
+ }
+ HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF);
+ HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF);
+ DBWriteContactSettingByte(metaGetContact(hContact), szGPGModuleName, "MsgsForTagging", DBGetContactSettingByte(metaGetContact(hContact), szGPGModuleName, "MsgsForTagging", 0) + 1);
+ char *data = mir_utf8encodeW(str.c_str());
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)data);
+ mir_free(data);
+ return returnNoError(hContact);
+ }
ccs->lParam = (LPARAM)mir_utf8encodeW(str.c_str());
if(bAppendTags)
- DBWriteContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "MsgsForTagging", 0) + 1);
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", DBGetContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", 0) + 1);
}
}
return CallService(MS_PROTO_CHAINSEND, w, l);
@@ -498,20 +541,39 @@ int SendMsgSvc(WPARAM w, LPARAM l)
int HookSendMsg(WPARAM w, LPARAM l)
{
+ if(!l)
+ return 0;
+ DBEVENTINFO * dbei = (DBEVENTINFO*)l;
+ if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT))
+ {
+ if(strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----")) //grrrr!
+ return 1;
+ if(!msgs_to_ignore.empty())
+ {
+ for(list<string*>::iterator p = msgs_to_ignore.begin(); p != msgs_to_ignore.end(); p++)
+ {
+ if(!strcmp((*p)->c_str(), (char*)dbei->pBlob))
+ {
+ delete *p;
+ msgs_to_ignore.remove(*p);
+ return 1;
+ }
+ }
+ }
+ }
HANDLE hContact = (HANDLE)w;
- if(isProtoMetaContacts(hContact))
- hContact = metaGetMostOnline(hContact);
+
+
+ if(metaIsProtoMetaContacts(hContact))
+ hContact = metaGetCurrent(hContact);
if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0))
return 0;
if(bAppendTags)
{
- if(!l)
- return 0;
BYTE Msgs = DBGetContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", 0);
if(!Msgs)
return 0;
- DBEVENTINFO * dbei = (DBEVENTINFO*)l;
if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT))
{
char *msg = (char*)dbei->pBlob;