summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/svcs_proto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SecureIM/src/svcs_proto.cpp')
-rw-r--r--plugins/SecureIM/src/svcs_proto.cpp635
1 files changed, 259 insertions, 376 deletions
diff --git a/plugins/SecureIM/src/svcs_proto.cpp b/plugins/SecureIM/src/svcs_proto.cpp
index bae34792a8..79096d8a3f 100644
--- a/plugins/SecureIM/src/svcs_proto.cpp
+++ b/plugins/SecureIM/src/svcs_proto.cpp
@@ -1,62 +1,62 @@
#include "commonheaders.h"
-
// return SignID
-int getSecureSig(LPCSTR szMsg, LPSTR *szPlainMsg=NULL) {
- if (szPlainMsg) *szPlainMsg=(LPSTR)szMsg;
- for (int i=0;signs[i].len;i++) {
- if (memcmp(szMsg,signs[i].sig,signs[i].len)==0) {
-/* for (int i=strlen(szMsg)-1;i;i--) {
- if ( szMsg[i] == '\x0D' || szMsg[i] == '\x0A' )
- ((LPSTR)szMsg)[i] = '\0';
- else
- break;
- }*/
+int getSecureSig(LPCSTR szMsg, LPSTR *szPlainMsg=NULL)
+{
+ if (szPlainMsg) *szPlainMsg = (LPSTR)szMsg;
+ for (int i=0; signs[i].len; i++) {
+ if (memcmp(szMsg,signs[i].sig,signs[i].len) == 0) {
if (szPlainMsg) *szPlainMsg = (LPSTR)(szMsg+signs[i].len);
- if (signs[i].key==SiG_GAME && !bDGP)
+ if (signs[i].key == SiG_GAME && !bDGP)
return SiG_NONE;
+
return signs[i].key;
}
}
return SiG_NONE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
-int returnNoError(HANDLE hContact) {
- HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
- unsigned int tID;
- CloseHandle( (HANDLE) _beginthreadex(NULL, 0, sttFakeAck, new TFakeAckParams(hEvent,hContact,777,0), 0, &tID));
- SetEvent( hEvent );
- return 777;
+static void sttFakeAck(LPVOID param)
+{
+ TFakeAckParams *tParam = (TFakeAckParams*)param;
+
+ Sleep(100);
+ if (tParam->msg == NULL )
+ SendBroadcast(tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)tParam->id, 0);
+ else
+ SendBroadcast(tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)tParam->id, LPARAM(tParam->msg));
+
+ delete tParam;
}
+int returnNoError(HANDLE hContact)
+{
+ mir_forkthread(sttFakeAck, new TFakeAckParams(hContact, 777, 0));
+ return 777;
+}
-int returnError(HANDLE hContact, LPCSTR err) {
- HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
- unsigned int tID;
- CloseHandle( (HANDLE) _beginthreadex(NULL, 0, sttFakeAck, new TFakeAckParams(hEvent,hContact,666,err), 0, &tID));
- SetEvent( hEvent );
+int returnError(HANDLE hContact, LPCSTR err)
+{
+ mir_forkthread(sttFakeAck, new TFakeAckParams(hContact, 666, err));
return 666;
}
-
LPSTR szUnrtfMsg = NULL;
-
// RecvMsg handler
-INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
-
+INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam)
+{
CCSDATA *pccsd = (CCSDATA *)lParam;
PROTORECVEVENT *ppre = (PROTORECVEVENT *)pccsd->lParam;
pUinKey ptr = getUinKey(pccsd->hContact);
LPSTR szEncMsg = ppre->szMessage, szPlainMsg = NULL;
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onRecvMsg: %s", szEncMsg);
-#endif
// cut rtf tags
- if ( pRtfconvString && memcmp(szEncMsg,"{\\rtf1",6)==0 ) {
+ if (pRtfconvString && memcmp(szEncMsg,"{\\rtf1",6) == 0) {
SAFE_FREE(szUnrtfMsg);
int len = (int)strlen(szEncMsg)+1;
LPWSTR szTemp = (LPWSTR)mir_alloc(len*sizeof(WCHAR));
@@ -66,7 +66,7 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
rtfconvA(szEncMsg,szTemp);
len = (int)wcslen(szTemp)-1;
while(len) {
- if ( szTemp[len] == 0x0D || szTemp[len] == 0x0A )
+ if (szTemp[len] == 0x0D || szTemp[len] == 0x0A )
szTemp[len] = 0;
else
break;
@@ -82,48 +82,33 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
}
int ssig = getSecureSig(ppre->szMessage,&szEncMsg);
- BOOL bSecured = isContactSecured(pccsd->hContact)&SECURED;
- BOOL bPGP = isContactPGP(pccsd->hContact);
- BOOL bGPG = isContactGPG(pccsd->hContact);
-
-// HANDLE hMetaContact = getMetaContact(pccsd->hContact);
-// if ( hMetaContact ) {
-// ptr = getUinKey(hMetaContact);
-// }
+ bool bSecured = (isContactSecured(pccsd->hContact)&SECURED) != 0;
+ bool bPGP = isContactPGP(pccsd->hContact);
+ bool bGPG = isContactGPG(pccsd->hContact);
// pass any unchanged message
- if ( !ptr ||
- ssig==SiG_GAME ||
- !isSecureProtocol(pccsd->hContact) ||
- (isProtoMetaContacts(pccsd->hContact) && (pccsd->wParam & PREF_SIMNOMETA)) ||
- isChatRoom(pccsd->hContact) ||
- (ssig==SiG_NONE && !ptr->msgSplitted && !bSecured && !bPGP && !bGPG)
- ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (!ptr || ssig == SiG_GAME || !isSecureProtocol(pccsd->hContact) ||
+ (isProtoMetaContacts(pccsd->hContact) && (pccsd->wParam & PREF_SIMNOMETA)) || isChatRoom(pccsd->hContact) ||
+ (ssig == SiG_NONE && !ptr->msgSplitted && !bSecured && !bPGP && !bGPG)) {
Sent_NetLog("onRecvMsg: pass unhandled");
-#endif
return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
}
// drop message: fake, unsigned or from invisible contacts
- if ( isContactInvisible(pccsd->hContact) || ssig==SiG_FAKE ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (isContactInvisible(pccsd->hContact) || ssig == SiG_FAKE) {
Sent_NetLog("onRecvMsg: drop unhandled (contact invisible or hidden)");
-#endif
return 1;
}
// receive non-secure message in secure mode
- if ( ssig==SiG_NONE && !ptr->msgSplitted ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ssig == SiG_NONE && !ptr->msgSplitted) {
Sent_NetLog("onRecvMsg: non-secure message");
-#endif
- if (ppre->flags & PREF_UNICODE) {
+
+ if (ppre->flags & PREF_UNICODE)
szPlainMsg = m_awstrcat(Translate(sim402),szEncMsg);
- }
- else {
+ else
szPlainMsg = m_aastrcat(Translate(sim402),szEncMsg);
- }
+
ppre->szMessage = szPlainMsg;
pccsd->wParam |= PREF_SIMNOMETA;
int ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
@@ -132,33 +117,31 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
}
// received non-pgp secure message from disabled contact
- if ( ssig!=SiG_PGPM && !bPGP && !bGPG && ptr->status==STATUS_DISABLED ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
- Sent_NetLog("onRecvMsg: message from disabled");
-#endif
- if ( ptr->mode==MODE_NATIVE ) {
- // tell to the other side that we have the plugin disabled with him
- pccsd->wParam |= PREF_METANODB;
- pccsd->lParam = (LPARAM) SIG_DISA;
- pccsd->szProtoService = PSS_MESSAGE;
- CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+ if (ssig != SiG_PGPM && !bPGP && !bGPG && ptr->status == STATUS_DISABLED) {
+ Sent_NetLog("onRecvMsg: message from disabled");
- showPopUp(sim003,pccsd->hContact,g_hPOP[POP_PU_DIS],0);
- }
- else {
- createRSAcntx(ptr);
- exp->rsa_disabled(ptr->cntx);
- deleteRSAcntx(ptr);
- }
- SAFE_FREE(ptr->msgSplitted);
- return 1;
+ if (ptr->mode == MODE_NATIVE) {
+ // tell to the other side that we have the plugin disabled with him
+ pccsd->wParam |= PREF_METANODB;
+ pccsd->lParam = (LPARAM) SIG_DISA;
+ pccsd->szProtoService = PSS_MESSAGE;
+ CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+
+ showPopUp(sim003,pccsd->hContact,g_hPOP[POP_PU_DIS],0);
+ }
+ else {
+ createRSAcntx(ptr);
+ exp->rsa_disabled(ptr->cntx);
+ deleteRSAcntx(ptr);
+ }
+ SAFE_FREE(ptr->msgSplitted);
+ return 1;
}
// combine message splitted by protocol (no tags)
- if ( ssig==SiG_NONE && ptr->msgSplitted ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ssig == SiG_NONE && ptr->msgSplitted) {
Sent_NetLog("onRecvMsg: combine untagged splitted message");
-#endif
+
LPSTR tmp = (LPSTR) mir_alloc(strlen(ptr->msgSplitted)+strlen(szEncMsg)+1);
strcpy(tmp,ptr->msgSplitted);
strcat(tmp,szEncMsg);
@@ -166,28 +149,22 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
ptr->msgSplitted = szEncMsg = ppre->szMessage = tmp;
ssig = getSecureSig(tmp,&szEncMsg);
}
- else {
- SAFE_FREE(ptr->msgSplitted);
- }
+ else SAFE_FREE(ptr->msgSplitted);
// combine message splitted by secureim (with tags)
- if ( ssig==SiG_SECP || ssig==SiG_PART ) {
+ if (ssig == SiG_SECP || ssig == SiG_PART) {
LPSTR msg = combineMessage(ptr,szEncMsg);
- if ( !msg ) return 1;
+ if (!msg ) return 1;
szEncMsg = ppre->szMessage = msg;
ssig = getSecureSig(msg,&szEncMsg);
}
// decrypt PGP/GPG message
- if ( ssig==SiG_PGPM &&
- ((bPGPloaded && (bPGPkeyrings || bPGPprivkey))||
- (bGPGloaded && bGPGkeyrings))
- ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ssig == SiG_PGPM && ((bPGPloaded && (bPGPkeyrings || bPGPprivkey)) || (bGPGloaded && bGPGkeyrings))) {
Sent_NetLog("onRecvMsg: PGP/GPG message");
-#endif
+
szEncMsg = ppre->szMessage;
- if ( !ptr->cntx ) {
+ if (!ptr->cntx) {
ptr->cntx = cpp_create_context(((bGPGloaded && bGPGkeyrings)?CPP_MODE_GPG:CPP_MODE_PGP) | ((db_get_b(pccsd->hContact,MODULENAME,"gpgANSI",0))?CPP_MODE_GPG_ANSI:0));
ptr->keyLoaded = 0;
}
@@ -201,9 +178,9 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
if (!ptr->keyLoaded && bPGPloaded) ptr->keyLoaded = LoadKeyPGP(ptr);
if (!ptr->keyLoaded && bGPGloaded) ptr->keyLoaded = LoadKeyGPG(ptr);
- if (ptr->keyLoaded==1) szOldMsg = pgp_decode(ptr->cntx, szEncMsg);
+ if (ptr->keyLoaded == 1) szOldMsg = pgp_decode(ptr->cntx, szEncMsg);
else
- if (ptr->keyLoaded==2) szOldMsg = gpg_decode(ptr->cntx, szEncMsg);
+ if (ptr->keyLoaded == 2) szOldMsg = gpg_decode(ptr->cntx, szEncMsg);
if (!szOldMsg) { // error while decrypting message, send error
SAFE_FREE(ptr->msgSplitted);
@@ -215,7 +192,7 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
// receive encrypted message in non-encrypted mode
if (!isContactPGP(pccsd->hContact) && !isContactGPG(pccsd->hContact)) {
- szNewMsg = m_ustrcat(TranslateU(sim403),szOldMsg);
+ szNewMsg = m_ustrcat(Translate(sim403), szOldMsg);
szOldMsg = szNewMsg;
}
szNewMsg = utf8_to_miranda(szOldMsg,ppre->flags); pccsd->wParam = ppre->flags;
@@ -230,30 +207,27 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
return ret;
}
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onRecvMsg: switch(ssig)=%d",ssig);
-#endif
- switch(ssig) {
+ switch(ssig) {
case SiG_PGPM:
return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
case SiG_SECU: { // new secured msg, pass to rsa_recv
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onRecvMsg: RSA/AES message");
-#endif
- if ( ptr->mode==MODE_NATIVE ) {
+
+ if (ptr->mode == MODE_NATIVE) {
ptr->mode = MODE_RSAAES;
deleteRSAcntx(ptr);
db_set_b(ptr->hContact, MODULENAME, "mode", ptr->mode);
}
createRSAcntx(ptr);
loadRSAkey(ptr);
- if ( exp->rsa_get_state(ptr->cntx)==0 )
+ if (exp->rsa_get_state(ptr->cntx) == 0 )
showPopUpKR(ptr->hContact);
LPSTR szOldMsg = exp->rsa_recv(ptr->cntx,szEncMsg);
- if ( !szOldMsg ) return 1; // don't display it ...
+ if (!szOldMsg ) return 1; // don't display it ...
LPSTR szNewMsg = utf8_to_miranda(szOldMsg,ppre->flags); pccsd->wParam = ppre->flags;
ppre->szMessage = szNewMsg;
@@ -267,11 +241,10 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
return ret;
} break;
- case SiG_ENON: { // online message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_ENON: // online message
Sent_NetLog("onRecvMsg: Native SiG_ENON message");
-#endif
- if ( cpp_keyx(ptr->cntx)) {
+
+ if (cpp_keyx(ptr->cntx)) {
// decrypting message
szPlainMsg = decodeMsg(ptr,lParam,szEncMsg);
if (!ptr->decoded) {
@@ -280,21 +253,19 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
ptr->msgSplitted=mir_strdup(szEncMsg);
return 1; // don't display it ...
}
-// showPopUpRM(ptr->hContact);
}
else {
// reinit key exchange user has send an encrypted message and i have no key
cpp_reset_context(ptr->cntx);
- LPSTR reSend = (LPSTR) mir_alloc(strlen(szEncMsg)+LEN_RSND);
+ mir_ptr<char> reSend((LPSTR)mir_alloc(strlen(szEncMsg)+LEN_RSND));
strcpy(reSend,SIG_RSND); // copy resend sig
strcat(reSend,szEncMsg); // add mess
- pccsd->wParam |= PREF_METANODB;
+ pccsd->wParam |= PREF_METANODB;
pccsd->lParam = (LPARAM) reSend; // reSend Message to reemit
pccsd->szProtoService = PSS_MESSAGE;
CallService(MS_PROTO_CHAINSEND, wParam, lParam); // send back cipher message
- mir_free(reSend);
LPSTR keyToSend = InitKeyA(ptr,0); // calculate public and private key
@@ -304,46 +275,38 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
showPopUp(sim005,NULL,g_hPOP[POP_PU_DIS],0);
showPopUpKS(ptr->hContact);
-
return 1;
}
- } break;
+ break;
- case SiG_ENOF: { // offline message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_ENOF: // offline message
Sent_NetLog("onRecvMsg: Native SiG_ENOF message");
-#endif
+
// if offline key is set and we have not an offline message unset key
if (ptr->offlineKey && cpp_keyx(ptr->cntx)) {
cpp_reset_context(ptr->cntx);
ptr->offlineKey = false;
}
+
// decrypting message with last offline key
DBVARIANT dbv;
dbv.type = DBVT_BLOB;
+ if (DBGetContactSetting(ptr->hContact, MODULENAME, "offlineKey", &dbv))
+ return CallService(MS_PROTO_CHAINRECV, wParam, lParam); // exit and show messsage
- if ( DBGetContactSetting(ptr->hContact,MODULENAME,"offlineKey",&dbv) == 0 ) {
- // if valid key is succefully retrieved
- ptr->offlineKey = true;
- InitKeyX(ptr,dbv.pbVal);
- db_free(&dbv);
+ // if valid key is succefully retrieved
+ ptr->offlineKey = true;
+ InitKeyX(ptr,dbv.pbVal);
+ db_free(&dbv);
- // decrypting message
- szPlainMsg = decodeMsg(ptr,lParam,szEncMsg);
-
-// showPopUpRM(ptr->hContact);
- ShowStatusIconNotify(ptr->hContact);
- }
- else {
- // exit and show messsage
- return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
- }
- } break;
+ // decrypting message
+ szPlainMsg = decodeMsg(ptr,lParam,szEncMsg);
+ ShowStatusIconNotify(ptr->hContact);
+ break;
- case SiG_RSND: { // resend message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_RSND: // resend message
Sent_NetLog("onRecvMsg: Native SiG_RSND message");
-#endif
+
if (cpp_keyx(ptr->cntx)) {
// decrypt sended back message and save message for future sending with a new secret key
szPlainMsg = decodeMsg(ptr,(LPARAM)pccsd,szEncMsg);
@@ -354,16 +317,11 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
showPopUp(sim004,NULL,g_hPOP[POP_PU_DIS],0);
}
return 1; // don't display it ...
- } break;
- case SiG_DISA: { // disabled message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_DISA: // disabled message
Sent_NetLog("onRecvMsg: Native SiG_DISA message");
-#endif
-// ptr->status=ptr->tstatus=STATUS_DISABLED;
-// db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status);
- }
- case SiG_DEIN: { // deinit message
+
+ case SiG_DEIN: // deinit message
// other user has disabled SecureIM with you
cpp_delete_context(ptr->cntx); ptr->cntx=0;
@@ -372,42 +330,34 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
waitForExchange(ptr,3); // дослать нешифрованно
return 1;
- } break;
- case SiG_KEYR: // key3 message
- case SiG_KEYA: // keyA message
- case SiG_KEYB: { // keyB message
- if ( ptr->mode==MODE_RSAAES ) {
+ case SiG_KEYR: // key3 message
+ case SiG_KEYA: // keyA message
+ case SiG_KEYB: // keyB message
+ if (ptr->mode == MODE_RSAAES) {
ptr->mode = MODE_NATIVE;
cpp_delete_context(ptr->cntx);
ptr->cntx = 0;
ptr->keyLoaded = 0;
db_set_b(ptr->hContact, MODULENAME, "mode", ptr->mode);
}
+
switch(ssig) {
- case SiG_KEYR: { // key3 message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_KEYR: // key3 message
Sent_NetLog("onRecvMsg: SiG_KEYR received");
-#endif
+
// receive KeyB from user;
showPopUpKR(ptr->hContact);
- if ( ptr->cntx && cpp_keyb(ptr->cntx)) {
+ if (ptr->cntx && cpp_keyb(ptr->cntx)) {
// reinit key exchange if an old key from user is found
cpp_reset_context(ptr->cntx);
}
- if ( InitKeyB(ptr,szEncMsg)!=CPP_ERROR_NONE ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (InitKeyB(ptr,szEncMsg) != CPP_ERROR_NONE) {
Sent_NetLog("onRecvMsg: SiG_KEYR InitKeyB error");
-#endif
+
// tell to the other side that we have the plugin disabled with him
-/*
- pccsd->wParam |= PREF_METANODB;
- pccsd->lParam = (LPARAM) SIG_DISA;
- pccsd->szProtoService = PSS_MESSAGE;
- CallService(MS_PROTO_CHAINSEND, wParam, lParam);
-*/
showPopUp(sim013,ptr->hContact,g_hPOP[POP_PU_DIS],0);
ShowStatusIconNotify(ptr->hContact);
@@ -416,7 +366,7 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
}
// other side support RSA mode ?
- if ( ptr->features & CPP_FEATURES_RSA ) {
+ if (ptr->features & CPP_FEATURES_RSA) {
// switch to RSAAES mode
ptr->mode = MODE_RSAAES;
db_set_b(ptr->hContact, MODULENAME, "mode", ptr->mode);
@@ -431,14 +381,13 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
}
// other side support new key format ?
- if ( ptr->features & CPP_FEATURES_NEWPG ) {
+ if (ptr->features & CPP_FEATURES_NEWPG) {
cpp_reset_context(ptr->cntx);
LPSTR keyToSend = InitKeyA(ptr,CPP_FEATURES_NEWPG|KEY_A_SIG); // calculate NEW public and private key
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onRecvMsg: Sending KEYA %s", keyToSend);
-#endif
- pccsd->wParam |= PREF_METANODB;
+
+ pccsd->wParam |= PREF_METANODB;
pccsd->lParam = (LPARAM)keyToSend;
pccsd->szProtoService = PSS_MESSAGE;
CallService(MS_PROTO_CHAINSEND, wParam, lParam);
@@ -450,12 +399,11 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
}
// auto send my public key to keyB user if not done before
- if ( !cpp_keya(ptr->cntx)) {
+ if (!cpp_keya(ptr->cntx)) {
LPSTR keyToSend = InitKeyA(ptr,0); // calculate public and private key
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onRecvMsg: Sending KEYA %s", keyToSend);
-#endif
- pccsd->wParam |= PREF_METANODB;
+
+ pccsd->wParam |= PREF_METANODB;
pccsd->lParam = (LPARAM)keyToSend;
pccsd->szProtoService = PSS_MESSAGE;
CallService(MS_PROTO_CHAINSEND, wParam, lParam);
@@ -463,64 +411,47 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
showPopUpKS(ptr->hContact);
}
- } break;
+ break;
- case SiG_KEYA: { // keyA message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_KEYA: // keyA message
Sent_NetLog("onRecvMsg: SiG_KEYA received");
-#endif
+
// receive KeyA from user;
showPopUpKR(ptr->hContact);
cpp_reset_context(ptr->cntx);
- if (InitKeyB(ptr,szEncMsg)!=CPP_ERROR_NONE) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (InitKeyB(ptr,szEncMsg) != CPP_ERROR_NONE) {
Sent_NetLog("onRecvMsg: SiG_KEYA InitKeyB error");
-#endif
+
// tell to the other side that we have the plugin disabled with him
-/*
- pccsd->wParam |= PREF_METANODB;
- pccsd->lParam = (LPARAM) SIG_DISA;
- pccsd->szProtoService = PSS_MESSAGE;
- CallService(MS_PROTO_CHAINSEND, wParam, lParam);
-*/
showPopUp(sim013,ptr->hContact,g_hPOP[POP_PU_DIS],0);
ShowStatusIconNotify(ptr->hContact);
waitForExchange(ptr,3); // дослать нешифрованно
return 1;
}
+ else {
+ mir_ptr<char> keyToSend( InitKeyA(ptr, CPP_FEATURES_NEWPG | KEY_B_SIG)); // calculate NEW public and private key
+ Sent_NetLog("onRecvMsg: Sending KEYB %s", keyToSend);
- LPSTR keyToSend = InitKeyA(ptr,CPP_FEATURES_NEWPG|KEY_B_SIG); // calculate NEW public and private key
-#if defined(_DEBUG) || defined(NETLIB_LOG)
- Sent_NetLog("onRecvMsg: Sending KEYB %s", keyToSend);
-#endif
- pccsd->wParam |= PREF_METANODB;
- pccsd->lParam = (LPARAM)keyToSend;
- pccsd->szProtoService = PSS_MESSAGE;
- CallService(MS_PROTO_CHAINSEND, wParam, lParam);
- mir_free(keyToSend);
- } break;
+ pccsd->wParam |= PREF_METANODB;
+ pccsd->lParam = (LPARAM)keyToSend;
+ pccsd->szProtoService = PSS_MESSAGE;
+ CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+ }
+ break;
- case SiG_KEYB: { // keyB message
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ case SiG_KEYB: // keyB message
Sent_NetLog("onRecvMsg: SiG_KEYB received");
-#endif
+
// receive KeyB from user;
showPopUpKR(ptr->hContact);
// clear all and send DISA if received KeyB, and not exist KeyA or error on InitKeyB
- if (!cpp_keya(ptr->cntx) || InitKeyB(ptr,szEncMsg)!=CPP_ERROR_NONE) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (!cpp_keya(ptr->cntx) || InitKeyB(ptr,szEncMsg) != CPP_ERROR_NONE) {
Sent_NetLog("onRecvMsg: SiG_KEYB InitKeyB error");
-#endif
+
// tell to the other side that we have the plugin disabled with him
-/*
- pccsd->wParam |= PREF_METANODB;
- pccsd->lParam = (LPARAM) SIG_DISA;
- pccsd->szProtoService = PSS_MESSAGE;
- CallService(MS_PROTO_CHAINSEND, wParam, lParam);
-*/
showPopUp(sim013,ptr->hContact,g_hPOP[POP_PU_DIS],0);
ShowStatusIconNotify(ptr->hContact);
@@ -528,128 +459,103 @@ INT_PTR __cdecl onRecvMsg(WPARAM wParam, LPARAM lParam) {
waitForExchange(ptr,3); // дослать нешифрованно
return 1;
}
- } break;
-
- } // switch
+ break;
+ }
/* common part (CalcKeyX & SendQueue) */
// calculate KeyX
- if ( cpp_keya(ptr->cntx) && cpp_keyb(ptr->cntx) && !cpp_keyx(ptr->cntx))
+ if (cpp_keya(ptr->cntx) && cpp_keyb(ptr->cntx) && !cpp_keyx(ptr->cntx))
CalculateKeyX(ptr,ptr->hContact);
ShowStatusIconNotify(ptr->hContact);
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onRecvMsg: Session established");
-#endif
waitForExchange(ptr,2); // дошлем через шифрованное соединение
return 1;
- /* common part (CalcKeyX & SendQueue) */
- } break;
-
- } //switch
+ }
// receive message
- if ( cpp_keyx(ptr->cntx) && (ssig==SiG_ENON||ssig==SiG_ENOF)) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (cpp_keyx(ptr->cntx) && (ssig == SiG_ENON||ssig == SiG_ENOF)) {
Sent_NetLog("onRecvMsg: message received");
-#endif
showPopUpRM(ptr->hContact);
}
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+
Sent_NetLog("onRecvMsg: exit");
-#endif
+
pccsd->wParam |= PREF_SIMNOMETA;
int ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
SAFE_FREE(szPlainMsg);
return ret;
}
-
// SendMsgW handler
-INT_PTR __cdecl onSendMsgW(WPARAM wParam, LPARAM lParam) {
+INT_PTR __cdecl onSendMsgW(WPARAM wParam, LPARAM lParam)
+{
if (!lParam) return 0;
- CCSDATA *ccs = (CCSDATA *) lParam;
- if ( !(ccs->wParam & PREF_UTF))
+ CCSDATA *ccs = (CCSDATA*)lParam;
+ if (!(ccs->wParam & PREF_UTF))
ccs->wParam |= PREF_UNICODE;
return onSendMsg(wParam, lParam);
}
-
// SendMsg handler
-INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
-
+INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam)
+{
CCSDATA *pccsd = (CCSDATA *)lParam;
pUinKey ptr = getUinKey(pccsd->hContact);
int ssig = getSecureSig((LPCSTR)pccsd->lParam);
int stat = getContactStatus(pccsd->hContact);
- // HANDLE hMetaContact = getMetaContact(pccsd->hContact);
- // if ( hMetaContact ) {
- // ptr = getUinKey(hMetaContact);
- // }
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onSend: %s",(LPSTR)pccsd->lParam);
-#endif
+
// pass unhandled messages
- if ( !ptr ||
- ssig==SiG_GAME || ssig==SiG_PGPM || ssig==SiG_SECU || ssig==SiG_SECP ||
- isChatRoom(pccsd->hContact) ||
- /* (ssig!=SiG_NONE && hMetaContact && (pccsd->wParam & PREF_METANODB)) || */
- stat==-1 ||
- (ssig==SiG_NONE && ptr->sendQueue) ||
- (ssig==SiG_NONE && ptr->status==STATUS_DISABLED) // Disabled - pass unhandled
- ) {
- return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
-#if defined(_DEBUG) || defined(NETLIB_LOG)
- Sent_NetLog("onSendMsg: pass unhandled");
-#endif
+ if (!ptr || ssig == SiG_GAME || ssig == SiG_PGPM || ssig == SiG_SECU || ssig == SiG_SECP ||
+ isChatRoom(pccsd->hContact) || stat == -1 ||
+ (ssig == SiG_NONE && ptr->sendQueue) || (ssig == SiG_NONE && ptr->status == STATUS_DISABLED)) {
+ return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+
+ Sent_NetLog("onSendMsg: pass unhandled");
}
//
// PGP/GPG mode
//
- if ( ptr->mode==MODE_PGP || ptr->mode==MODE_GPG ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ptr->mode == MODE_PGP || ptr->mode == MODE_GPG) {
Sent_NetLog("onSendMsg: PGP|GPG mode");
-#endif
+
// если можно зашифровать - шифруем
- if ( isContactPGP(ptr->hContact) || isContactGPG(ptr->hContact)) {
- if ( !ptr->cntx ) {
+ if (isContactPGP(ptr->hContact) || isContactGPG(ptr->hContact)) {
+ if (!ptr->cntx) {
ptr->cntx = cpp_create_context((isContactGPG(ptr->hContact)?CPP_MODE_GPG:CPP_MODE_PGP) | ((db_get_b(ptr->hContact,MODULENAME,"gpgANSI",0))?CPP_MODE_GPG_ANSI:0));
ptr->keyLoaded = 0;
}
- if ( !ptr->keyLoaded && bPGPloaded ) ptr->keyLoaded = LoadKeyPGP(ptr);
- if ( !ptr->keyLoaded && bGPGloaded ) ptr->keyLoaded = LoadKeyGPG(ptr);
- if ( !ptr->keyLoaded ) return returnError(pccsd->hContact,Translate(sim108));
+ if (!ptr->keyLoaded && bPGPloaded ) ptr->keyLoaded = LoadKeyPGP(ptr);
+ if (!ptr->keyLoaded && bGPGloaded ) ptr->keyLoaded = LoadKeyGPG(ptr);
+ if (!ptr->keyLoaded ) return returnError(pccsd->hContact,Translate(sim108));
LPSTR szNewMsg = NULL;
LPSTR szUtfMsg = miranda_to_utf8((LPCSTR)pccsd->lParam,pccsd->wParam);
- if ( ptr->keyLoaded == 1 ) { // PGP
+ if (ptr->keyLoaded == 1) // PGP
szNewMsg = pgp_encode(ptr->cntx,szUtfMsg);
- }
- else
- if ( ptr->keyLoaded == 2 ) { // GPG
- szNewMsg = gpg_encode(ptr->cntx,szUtfMsg);
- }
- mir_free(szUtfMsg);
- if ( !szNewMsg ) {
- return returnError(pccsd->hContact,Translate(sim109));
- }
+ else if (ptr->keyLoaded == 2) // GPG
+ szNewMsg = gpg_encode(ptr->cntx,szUtfMsg);
- // отправляем зашифрованное сообщение
- splitMessageSend(ptr,szNewMsg);
+ mir_free(szUtfMsg);
+ if (!szNewMsg)
+ return returnError(pccsd->hContact,Translate(sim109));
- showPopUpSM(ptr->hContact);
+ // отправляем зашифрованное сообщение
+ splitMessageSend(ptr,szNewMsg);
- return returnNoError(pccsd->hContact);
- }
- else {
- // отправляем незашифрованное
- return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+ showPopUpSM(ptr->hContact);
+
+ return returnNoError(pccsd->hContact);
}
+
+ // отправляем незашифрованное
+ return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
// get contact SecureIM status
@@ -658,30 +564,26 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
//
// RSA/AES mode
//
- if ( ptr->mode==MODE_RSAAES ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ptr->mode == MODE_RSAAES) {
Sent_NetLog("onSendMsg: RSA/AES mode");
-#endif
+
// contact is offline
- if ( stat==ID_STATUS_OFFLINE ) {
- if ( ptr->cntx ) {
- if ( exp->rsa_get_state(ptr->cntx)!=0 ) {
+ if (stat == ID_STATUS_OFFLINE) {
+ if (ptr->cntx) {
+ if (exp->rsa_get_state(ptr->cntx) != 0)
resetRSAcntx(ptr);
- }
- }
- else {
- createRSAcntx(ptr);
}
- if ( !bSOM || (!isClientMiranda(ptr,1) && !isSecureIM(ptr,1)) || !loadRSAkey(ptr)) {
- if ( ssig==SiG_NONE ) {
+ else createRSAcntx(ptr);
+
+ if (!bSOM || (!isClientMiranda(ptr,1) && !isSecureIM(ptr,1)) || !loadRSAkey(ptr)) {
+ if (ssig == SiG_NONE)
// просто шлем незашифрованное в оффлайн
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
- }
- else {
- // ничего не шлем дальше - это служебное сообщение
- return returnNoError(pccsd->hContact);
- }
+
+ // ничего не шлем дальше - это служебное сообщение
+ return returnNoError(pccsd->hContact);
}
+
// шлем шифрованное в оффлайн
LPSTR szUtfMsg = miranda_to_utf8((LPCSTR)pccsd->lParam,pccsd->wParam);
exp->rsa_send(ptr->cntx,szUtfMsg);
@@ -689,38 +591,42 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
showPopUpSM(ptr->hContact);
return returnNoError(pccsd->hContact);
}
+
// SecureIM connection with this contact is disabled
- if ( stid==STATUS_DISABLED ) {
- if ( ptr->cntx ) {
+ if (stid == STATUS_DISABLED) {
+ if (ptr->cntx) {
exp->rsa_disabled(ptr->cntx);
deleteRSAcntx(ptr);
}
- if ( ssig==SiG_NONE ) {
- // просто шлем незашифрованное
+
+ if (ssig == SiG_NONE) // просто шлем незашифрованное
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
- }
+
// ничего не шлем дальше - это служебное сообщение
return returnNoError(pccsd->hContact);
}
+
// разорвать соединение
- if ( ssig==SiG_DEIN ) {
- if ( ptr->cntx ) {
+ if (ssig == SiG_DEIN) {
+ if (ptr->cntx) {
exp->rsa_disconnect(ptr->cntx);
deleteRSAcntx(ptr);
}
+ ShowStatusIconNotify(ptr->hContact);
waitForExchange(ptr,3); // дошлем нешифрованно
return returnNoError(pccsd->hContact);
}
+
// соединение установлено
- if ( ptr->cntx && exp->rsa_get_state(ptr->cntx)==7 ) {
- LPSTR szUtfMsg = miranda_to_utf8((LPCSTR)pccsd->lParam,pccsd->wParam);
- exp->rsa_send(ptr->cntx,szUtfMsg);
- mir_free(szUtfMsg);
+ if (ptr->cntx && exp->rsa_get_state(ptr->cntx) == 7) {
+ exp->rsa_send(ptr->cntx, mir_ptr<char>(miranda_to_utf8((LPCSTR)pccsd->lParam,pccsd->wParam)));
+ ShowStatusIconNotify(ptr->hContact);
showPopUpSM(ptr->hContact);
return returnNoError(pccsd->hContact);
}
+
// просто сообщение (без тэгов, нет контекста и работают AIP & NOL)
- if ( ssig==SiG_NONE && isSecureIM(ptr->hContact)) {
+ if (ssig == SiG_NONE && isSecureIM(ptr->hContact)) {
// добавим его в очередь
addMsg2Queue(ptr, pccsd->wParam, (LPSTR)pccsd->lParam);
// запускаем процесс установки соединения
@@ -728,8 +634,9 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
// запускаем трэд ожидания и досылки
waitForExchange(ptr);
}
+
// установить соединение
- if ( ssig==SiG_INIT ) {
+ if (ssig == SiG_INIT) {
createRSAcntx(ptr);
loadRSAkey(ptr);
exp->rsa_connect(ptr->cntx);
@@ -737,6 +644,7 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
ShowStatusIconNotify(pccsd->hContact);
return returnNoError(pccsd->hContact);
}
+
// просто шлем незашифрованное (не знаю даже когда такое случится)
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
@@ -744,21 +652,17 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
//
// Native mode
//
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onSendMsg: Native mode");
-#endif
// SecureIM connection with this contact is disabled
- if ( stid==STATUS_DISABLED ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (stid == STATUS_DISABLED) {
Sent_NetLog("onSendMsg: message for Disabled");
-#endif
+
// if user try initialize connection
- if ( ssig==SiG_INIT ) {
- // secure IM is disabled ...
+ if (ssig == SiG_INIT) // secure IM is disabled ...
return returnError(pccsd->hContact,Translate(sim105));
- }
- if (ptr->cntx) { // if exist secure context
+
+ if (ptr->cntx) { // if secure context exists
cpp_delete_context(ptr->cntx); ptr->cntx=0;
CCSDATA ccsd;
@@ -777,16 +681,13 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
// contact is offline
if (stat == ID_STATUS_OFFLINE) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onSendMsg: message for offline");
-#endif
- if ( ssig==SiG_INIT && cpp_keyx(ptr->cntx)) {
- // reinit key exchange
+
+ if (ssig == SiG_INIT && cpp_keyx(ptr->cntx)) // reinit key exchange
cpp_reset_context(ptr->cntx);
- }
- if ( !bSOM ) {
- if ( ssig!=SiG_NONE )
+ if (!bSOM) {
+ if (ssig != SiG_NONE )
return returnNoError(pccsd->hContact);
// exit and send unencrypted message
@@ -797,43 +698,36 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
if (stid == STATUS_ALWAYSTRY && isMiranda) { // always try && Miranda
// set key for offline user
DBVARIANT dbv; dbv.type = DBVT_BLOB;
- if ( db_get_dw(ptr->hContact, MODULENAME, "offlineKeyTimeout", 0) > gettime() &&
- DBGetContactSetting(ptr->hContact, MODULENAME, "offlineKey", &dbv) == 0
- ) {
- // if valid key is succefully retrieved
- ptr->offlineKey = true;
- InitKeyX(ptr,dbv.pbVal);
- db_free(&dbv);
+ if (db_get_dw(ptr->hContact, MODULENAME, "offlineKeyTimeout", 0) > gettime() &&
+ DBGetContactSetting(ptr->hContact, MODULENAME, "offlineKey", &dbv) == 0) {
+ // if valid key is succefully retrieved
+ ptr->offlineKey = true;
+ InitKeyX(ptr,dbv.pbVal);
+ db_free(&dbv);
}
else {
db_unset(ptr->hContact,MODULENAME,"offlineKey");
db_unset(ptr->hContact,MODULENAME,"offlineKeyTimeout");
- if (msgbox1(0,sim106,MODULENAME,MB_YESNO|MB_ICONQUESTION)==IDNO) {
+ if (msgbox1(0,sim106,MODULENAME,MB_YESNO|MB_ICONQUESTION) == IDNO)
return returnNoError(pccsd->hContact);
- }
+
// exit and send unencrypted message
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
}
else {
- /* if (stid==STATUS_ALWAYSTRY && !isMiranda || stid!=STATUS_ALWAYSTRY && isMiranda) {
- int res=msgbox1(0,"User is offline now, Do you want to send your message ?\nIt will be unencrypted !","Can't Send Encrypted Message !",MB_YESNO);
- if (res==IDNO) return 1;
- }*/
- if ( ssig!=SiG_NONE ) {
+ if (ssig != SiG_NONE)
return returnNoError(pccsd->hContact);
- }
+
// exit and send unencrypted message
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
-
}
else {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onSendMsg: message for online");
-#endif
+
// contact is online and we use an offline key -> reset offline key
- if ( ptr->offlineKey ) {
+ if (ptr->offlineKey) {
cpp_reset_context(ptr->cntx);
ptr->offlineKey = false;
ShowStatusIconNotify(ptr->hContact);
@@ -841,18 +735,15 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
}
// if init is called from contact menu list reinit secure im connection
- if ( ssig==SiG_INIT ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ssig == SiG_INIT) {
Sent_NetLog("onSendMsg: SiG_INIT");
-#endif
cpp_reset_context(ptr->cntx);
}
// if deinit is called from contact menu list deinit secure im connection
- if ( ssig==SiG_DEIN ) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (ssig == SiG_DEIN) {
Sent_NetLog("onSendMsg: SiG_DEIN");
-#endif
+
// disable SecureIM only if it was enabled
if (ptr->cntx) {
cpp_delete_context(ptr->cntx); ptr->cntx=0;
@@ -866,21 +757,17 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
return returnNoError(pccsd->hContact);
}
- if ( cpp_keya(ptr->cntx) && cpp_keyb(ptr->cntx) && !cpp_keyx(ptr->cntx))
+ if (cpp_keya(ptr->cntx) && cpp_keyb(ptr->cntx) && !cpp_keyx(ptr->cntx))
CalculateKeyX(ptr,ptr->hContact);
ShowStatusIconNotify(pccsd->hContact);
// if cryptokey exist
- if ( cpp_keyx(ptr->cntx)) {
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ if (cpp_keyx(ptr->cntx)) {
Sent_NetLog("onSendMsg: cryptokey exist");
-#endif
- LPSTR szNewMsg = encodeMsg(ptr,(LPARAM)pccsd);
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+ LPSTR szNewMsg = encodeMsg(ptr,(LPARAM)pccsd);
Sent_NetLog("onSend: encrypted msg '%s'",szNewMsg);
-#endif
pccsd->wParam |= PREF_METANODB;
pccsd->lParam = (LPARAM) szNewMsg;
@@ -888,26 +775,22 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
int ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
mir_free(szNewMsg);
-
showPopUpSM(ptr->hContact);
-
return ret;
}
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("onSendMsg: cryptokey not exist, try establishe connection");
-#endif
+
// send KeyA if init || always_try || waitkey || always_if_possible
- if ( ssig==SiG_INIT || (stid==STATUS_ALWAYSTRY && isClientMiranda(ptr->hContact)) || isSecureIM(ptr->hContact) || ptr->waitForExchange ) {
- if (ssig==SiG_NONE)
+ if (ssig == SiG_INIT || (stid == STATUS_ALWAYSTRY && isClientMiranda(ptr->hContact)) || isSecureIM(ptr->hContact) || ptr->waitForExchange) {
+ if (ssig == SiG_NONE)
addMsg2Queue(ptr, pccsd->wParam, (LPSTR)pccsd->lParam);
- if ( !ptr->waitForExchange ) {
+ if (!ptr->waitForExchange) {
// init || always_try || always_if_possible
LPSTR keyToSend = InitKeyA(ptr,0); // calculate public and private key & fill KeyA
-#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("Sending KEY3: %s", keyToSend);
-#endif
+
pccsd->wParam &= ~PREF_UNICODE;
pccsd->wParam |= PREF_METANODB;
pccsd->lParam = (LPARAM) keyToSend;
@@ -922,9 +805,8 @@ INT_PTR __cdecl onSendMsg(WPARAM wParam, LPARAM lParam) {
}
return returnNoError(pccsd->hContact);
}
-#if defined(_DEBUG) || defined(NETLIB_LOG)
+
Sent_NetLog("onSendMsg: pass unchanged to chain");
-#endif
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
@@ -935,18 +817,19 @@ INT_PTR __cdecl onSendFile(WPARAM wParam, LPARAM lParam)
CCSDATA *pccsd=(CCSDATA*)lParam;
pUinKey ptr = getUinKey(pccsd->hContact);
- if (!ptr || !bSFT) return CallService(PSS_FILE, wParam, lParam);
+ if (!ptr || !bSFT)
+ return CallService(PSS_FILE, wParam, lParam);
if (isContactSecured(pccsd->hContact)&SECURED) {
char **file=(char **)pccsd->lParam;
- if (file_idx==100) file_idx=0;
+ if (file_idx == 100) file_idx=0;
int i;
for (i=0;file[i];i++) {
if (strstr(file[i],".AESHELL")) continue;
char *name = strrchr(file[i],'\\');
- if ( !name ) name = file[i];
+ if (!name ) name = file[i];
else name++;
char *file_out = (char*) mir_alloc(TEMP_SIZE+strlen(name)+20);
@@ -964,7 +847,7 @@ INT_PTR __cdecl onSendFile(WPARAM wParam, LPARAM lParam)
mir_free(file[i]);
file[i]=file_out;
}
- if ( ptr->fileSend ) { // очистим сохраненный список
+ if (ptr->fileSend) { // очистим сохраненный список
for (int j=0; ptr->fileSend[j]; j++)
mir_free(ptr->fileSend[j]);
@@ -984,7 +867,7 @@ INT_PTR __cdecl onSendFile(WPARAM wParam, LPARAM lParam)
int __cdecl onProtoAck(WPARAM wParam,LPARAM lParam)
{
ACKDATA *ack=(ACKDATA*)lParam;
- if (ack->type!=ACKTYPE_FILE) return 0; //quit if not file transfer event
+ if (ack->type != ACKTYPE_FILE) return 0; //quit if not file transfer event
PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->lParam;
pUinKey ptr = getUinKey(ack->hContact);
@@ -1007,18 +890,18 @@ int __cdecl onProtoAck(WPARAM wParam,LPARAM lParam)
case ACKRESULT_DENIED:
case ACKRESULT_FAILED:
- if ( ptr->lastFileRecv ) {
+ if (ptr->lastFileRecv) {
if (strstr(ptr->lastFileRecv,".AESHELL")) mir_unlink(ptr->lastFileRecv);
SAFE_FREE(ptr->lastFileRecv);
}
- if ( ptr->lastFileSend ) {
+ if (ptr->lastFileSend) {
if (strstr(ptr->lastFileSend,".AESHELL")) mir_unlink(ptr->lastFileSend);
SAFE_FREE(ptr->lastFileSend);
}
- if ( ptr->fileSend ) {
+ if (ptr->fileSend) {
char **file=ptr->fileSend;
for (int j=0;file[j];j++) {
- if ( strstr(file[j],".AESHELL")) mir_unlink(file[j]);
+ if (strstr(file[j],".AESHELL")) mir_unlink(file[j]);
mir_free(file[j]);
}
SAFE_FREE(ptr->fileSend);
@@ -1027,14 +910,14 @@ int __cdecl onProtoAck(WPARAM wParam,LPARAM lParam)
case ACKRESULT_NEXTFILE:
case ACKRESULT_SUCCESS:
- if ( ptr->finFileRecv && ptr->lastFileRecv ) {
- if ( strstr(ptr->lastFileRecv,".AESHELL")) {
+ if (ptr->finFileRecv && ptr->lastFileRecv) {
+ if (strstr(ptr->lastFileRecv,".AESHELL")) {
char buf[MAX_PATH];
LPSTR file_out=mir_strdup(ptr->lastFileRecv);
LPSTR pos=strrchr(file_out,'.'); //find last .
if (pos) *pos='\0'; //remove AESHELL from name
- if ( isFileExist(file_out)) {
+ if (isFileExist(file_out)) {
buf[0]='\0';
LPSTR p=strrchr(file_out,'.');
LPSTR x=strrchr(file_out,'\\');
@@ -1044,14 +927,14 @@ int __cdecl onProtoAck(WPARAM wParam,LPARAM lParam)
}
for (int i=1;i<10000;i++) {
sprintf(pos," (%d)%s",i,buf);
- if ( !isFileExist(file_out)) break;
+ if (!isFileExist(file_out)) break;
}
}
sprintf(buf,"%s\n%s",Translate(sim012),file_out);
showPopUp(buf,NULL,g_hPOP[POP_PU_MSR],2);
- if ( ptr->mode == MODE_RSAAES )
+ if (ptr->mode == MODE_RSAAES )
exp->rsa_decrypt_file(ptr->cntx,ptr->lastFileRecv,file_out);
else
cpp_decrypt_file(ptr->cntx,ptr->lastFileRecv,file_out);
@@ -1062,8 +945,8 @@ int __cdecl onProtoAck(WPARAM wParam,LPARAM lParam)
SAFE_FREE(ptr->lastFileRecv);
ptr->finFileRecv = false;
}
- if ( ptr->finFileSend && ptr->lastFileSend ) {
- if ( strstr(ptr->lastFileSend,".AESHELL")) mir_unlink(ptr->lastFileSend);
+ if (ptr->finFileSend && ptr->lastFileSend) {
+ if (strstr(ptr->lastFileSend,".AESHELL")) mir_unlink(ptr->lastFileSend);
SAFE_FREE(ptr->lastFileSend);
ptr->finFileSend = false;
}