From 754c5e27f878dc4a46131593e00e78e054faa995 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 1 Apr 2013 19:37:35 +0000 Subject: SecureIM: - thread cleaning; - fix SRMM status icon; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@4278 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SecureIM/src/commonheaders.cpp | 32 +- plugins/SecureIM/src/commonheaders.h | 20 +- plugins/SecureIM/src/crypt.h | 31 +- plugins/SecureIM/src/crypt_check.cpp | 8 +- plugins/SecureIM/src/crypt_dll.cpp | 28 +- plugins/SecureIM/src/crypt_icons.cpp | 8 +- plugins/SecureIM/src/crypt_lists.cpp | 19 +- plugins/SecureIM/src/crypt_metacontacts.cpp | 2 +- plugins/SecureIM/src/crypt_misc.cpp | 140 +++--- plugins/SecureIM/src/gettime.cpp | 19 +- plugins/SecureIM/src/images.cpp | 14 +- plugins/SecureIM/src/loadicons.cpp | 2 +- plugins/SecureIM/src/loadlib.cpp | 4 +- plugins/SecureIM/src/main.cpp | 193 ++++----- plugins/SecureIM/src/mmi.cpp | 6 +- plugins/SecureIM/src/options.cpp | 186 ++++---- plugins/SecureIM/src/popupOptions.cpp | 12 +- plugins/SecureIM/src/rtfconv.cpp | 8 +- plugins/SecureIM/src/rtfconv.h | 5 +- plugins/SecureIM/src/splitmsg.cpp | 50 +-- plugins/SecureIM/src/svcs_clist.cpp | 53 ++- plugins/SecureIM/src/svcs_menu.cpp | 6 +- plugins/SecureIM/src/svcs_proto.cpp | 635 ++++++++++++---------------- plugins/SecureIM/src/svcs_rsa.cpp | 133 +++--- plugins/SecureIM/src/svcs_rsa.h | 2 +- plugins/SecureIM/src/svcs_srmm.cpp | 6 +- 26 files changed, 682 insertions(+), 940 deletions(-) diff --git a/plugins/SecureIM/src/commonheaders.cpp b/plugins/SecureIM/src/commonheaders.cpp index ed88af67f9..f23ef86633 100644 --- a/plugins/SecureIM/src/commonheaders.cpp +++ b/plugins/SecureIM/src/commonheaders.cpp @@ -86,34 +86,7 @@ void SetFlags() db_set_b(0, MODULENAME, "mcm", bMCM); } -struct A2U { - LPSTR a; - LPSTR u; -}; -typedef A2U* pA2U; - -pA2U pa2u; -int ca2u=0; - -LPSTR TranslateU( LPCSTR lpText ) -{ - int i; - for (i=0;iutf8encode(lpwTran)); - return pa2u[i].u; -} - -int msgbox( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) +int msgbox(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) { LPWSTR lpwText = mir_a2u(lpText); LPWSTR lpwCaption = mir_a2u(lpCaption); @@ -139,7 +112,6 @@ void CopyToClipboard(HWND hwnd,LPSTR msg) CloseClipboard(); } -#if defined(_DEBUG) || defined(NETLIB_LOG) HANDLE hNetlibUser; void InitNetlib() @@ -168,7 +140,5 @@ int Sent_NetLog(const char *fmt,...) va_end(va); return CallService(MS_NETLIB_LOG,(WPARAM)hNetlibUser,(LPARAM)szText); } -#endif - // EOF diff --git a/plugins/SecureIM/src/commonheaders.h b/plugins/SecureIM/src/commonheaders.h index 8ab8fbcb30..9a5091183b 100644 --- a/plugins/SecureIM/src/commonheaders.h +++ b/plugins/SecureIM/src/commonheaders.h @@ -100,30 +100,20 @@ int onModulesLoaded(WPARAM, LPARAM); int onSystemOKToExit(WPARAM, LPARAM); int ModuleLoad(WPARAM wParam, LPARAM lParam); +int SendBroadcast(HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam); + LPSTR myDBGetStringDecode(HANDLE,const char *,const char *); int myDBWriteStringEncode(HANDLE,const char *,const char *,const char *); -#if defined(_DEBUG) || defined(NETLIB_LOG) extern HANDLE hNetlibUser; void InitNetlib(); void DeinitNetlib(); int Sent_NetLog(const char *,...); -#endif -/* -int DBWriteString(HANDLE,const char *,const char *,const char *); -int DBGetByte(HANDLE,const char *,const char *,int); -int DBWriteByte(HANDLE,const char *,const char *,BYTE); -int DBGetWord(HANDLE,const char *,const char *,int); -int DBWriteWord(HANDLE,const char *,const char *,WORD); -*/ + void GetFlags(); void SetFlags(); -/* -LPSTR u2a( LPCWSTR src ); -LPWSTR a2u( LPCSTR src ); -*/ -LPSTR TranslateU( LPCSTR lpText ); -int msgbox( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType ); + +int msgbox(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); void CopyToClipboard(HWND hwnd,LPSTR msg); #define msgbox0(a,b,c,d) msgbox(a,b,c,d) #define msgbox1(a,b,c,d) msgbox(a,b,c,d) diff --git a/plugins/SecureIM/src/crypt.h b/plugins/SecureIM/src/crypt.h index 1b6680584c..c3f79bcd6b 100644 --- a/plugins/SecureIM/src/crypt.h +++ b/plugins/SecureIM/src/crypt.h @@ -68,28 +68,17 @@ struct UinKey }; typedef UinKey* pUinKey; -struct TFakeAckParams { - inline TFakeAckParams( HANDLE p1, HANDLE p2, LONG p3, LPCSTR p4 ) : - hEvent( p1 ), - hContact( p2 ), - id( p3 ), - msg( p4 ) - {} - - HANDLE hEvent; - HANDLE hContact; - LONG id; - LPCSTR msg; -}; - -struct TWaitForExchange { - inline TWaitForExchange( HANDLE p1, HANDLE p2 ) : - hEvent( p1 ), - hContact( p2 ) +struct TFakeAckParams +{ + __forceinline TFakeAckParams(HANDLE p1, LONG p2, LPCSTR p3) : + hContact(p1), + id(p2), + msg(p3) {} - HANDLE hEvent; - HANDLE hContact; + HANDLE hContact; + LONG id; + LPCSTR msg; }; extern char szUIN[NAMSIZE]; @@ -172,8 +161,6 @@ BOOL LoadKeyPGP(pUinKey); BOOL LoadKeyGPG(pUinKey); // crypt_misc.cpp -unsigned __stdcall sttFakeAck(LPVOID); -unsigned __stdcall sttWaitForExchange(LPVOID); void waitForExchange(pUinKey ptr, int flag = 1); #endif diff --git a/plugins/SecureIM/src/crypt_check.cpp b/plugins/SecureIM/src/crypt_check.cpp index 1f9bd04249..9369a1ba64 100644 --- a/plugins/SecureIM/src/crypt_check.cpp +++ b/plugins/SecureIM/src/crypt_check.cpp @@ -23,7 +23,7 @@ BYTE isContactSecured(HANDLE hContact) // нужна проверка на Offline и в этом случае другие статусы if (!arClist.getCount()) return 0; - if ( isProtoMetaContacts(hContact)) + if (isProtoMetaContacts(hContact)) hContact = getMostOnline(hContact); // возьмем тот, через который пойдет сообщение pUinKey p = findUinKey(hContact); @@ -70,7 +70,7 @@ bool isClientMiranda(pUinKey ptr, BOOL emptyMirverAsMiranda) bool isMiranda = true; LPSTR mirver = db_get_sa(ptr->hContact,ptr->proto->name,"MirVer"); if (mirver) { - isMiranda = (emptyMirverAsMiranda && !*mirver) || (strstr(mirver,"Miranda")!=NULL); + isMiranda = (emptyMirverAsMiranda && !*mirver) || (strstr(mirver,"Miranda") != NULL); mir_free(mirver); } return isMiranda; @@ -185,7 +185,7 @@ bool isChatRoom(HANDLE hContact) bool isFileExist(LPCSTR filename) { - return (GetFileAttributes(filename)!=(UINT)-1); + return (GetFileAttributes(filename) != (UINT)-1); } bool isSecureIM(pUinKey ptr, BOOL emptyMirverAsSecureIM) @@ -199,7 +199,7 @@ bool isSecureIM(pUinKey ptr, BOOL emptyMirverAsSecureIM) bool isSecureIM = false; LPSTR mirver = db_get_sa(ptr->hContact,ptr->proto->name,"MirVer"); if (mirver) { - isSecureIM = (emptyMirverAsSecureIM && !*mirver) || (strstr(mirver,"SecureIM")!=NULL) || (strstr(mirver,"secureim")!=NULL); + isSecureIM = (emptyMirverAsSecureIM && !*mirver) || (strstr(mirver,"SecureIM") != NULL) || (strstr(mirver,"secureim") != NULL); mir_free(mirver); } return isSecureIM; diff --git a/plugins/SecureIM/src/crypt_dll.cpp b/plugins/SecureIM/src/crypt_dll.cpp index 5bd50c4ca3..023de0ba68 100644 --- a/plugins/SecureIM/src/crypt_dll.cpp +++ b/plugins/SecureIM/src/crypt_dll.cpp @@ -2,11 +2,11 @@ // generate KeyA pair and return public key -LPSTR InitKeyA(pUinKey ptr,int features) { -#if defined(_DEBUG) || defined(NETLIB_LOG) +LPSTR InitKeyA(pUinKey ptr,int features) +{ Sent_NetLog("InitKeyA: %04x", features); -#endif - if ( !ptr->cntx ) + + if (!ptr->cntx ) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); char *tmp = db_get_sa(ptr->hContact,MODULENAME,"PSK"); @@ -42,10 +42,10 @@ LPSTR InitKeyA(pUinKey ptr,int features) { } // store KeyB into context -int InitKeyB(pUinKey ptr,LPCSTR key) { -#if defined(_DEBUG) || defined(NETLIB_LOG) +int InitKeyB(pUinKey ptr,LPCSTR key) +{ Sent_NetLog("InitKeyB: %s", key); -#endif + if (!ptr->cntx) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); @@ -78,7 +78,7 @@ void InitKeyX(pUinKey ptr,BYTE *key) { BOOL CalculateKeyX(pUinKey ptr,HANDLE hContact) { int agr = cpp_calc_keyx(ptr->cntx); - if ( agr ) { + if (agr) { // do this only if key exchanged is ok // we use a 192bit key int keysize = cpp_size_keyx(); @@ -110,7 +110,7 @@ BOOL CalculateKeyX(pUinKey ptr,HANDLE hContact) { // agree value problem showPopUp(sim002,hContact,g_hPOP[POP_PU_DIS],0); } - return agr!=0; + return agr != 0; } @@ -137,10 +137,10 @@ LPSTR encodeMsg(pUinKey ptr, LPARAM lParam) { LPSTR szNewMsg = NULL; LPSTR szOldMsg = (LPSTR) pccsd->lParam; - if ( pccsd->wParam & PREF_UTF ) + if (pccsd->wParam & PREF_UTF ) szNewMsg = encrypt(ptr,cpp_encodeU(ptr->cntx,szOldMsg)); else - if ( pccsd->wParam & PREF_UNICODE ) + if (pccsd->wParam & PREF_UNICODE ) szNewMsg = encrypt(ptr,cpp_encodeW(ptr->cntx,(LPWSTR)(szOldMsg+strlen(szOldMsg)+1))); else szNewMsg = encrypt(ptr,cpp_encodeA(ptr->cntx,szOldMsg)); @@ -181,7 +181,7 @@ LPSTR decodeMsg(pUinKey ptr, LPARAM lParam, LPSTR szEncMsg) { } else { ptr->decoded=true; - if ( ppre->flags & PREF_UTF ) { // Ґб«Ё Їа®в®Є®« Ї®¤¤Ґа¦Ёў Ґв utf8 - в®Ј¤  ®вЇа ў«пҐ¬ ў utf8 + if (ppre->flags & PREF_UTF) { // Ґб«Ё Їа®в®Є®« Ї®¤¤Ґа¦Ёў Ґв utf8 - в®Ј¤  ®вЇа ў«пҐ¬ ў utf8 int olen = (int)strlen(szOldMsg)+1; szNewMsg = (LPSTR) mir_alloc(olen); memcpy(szNewMsg,szOldMsg,olen); @@ -205,7 +205,7 @@ BOOL LoadKeyPGP(pUinKey ptr) if (mode == 0) { DBVARIANT dbv; DBGetContactSetting(ptr->hContact,MODULENAME,"pgp",&dbv); - BOOL r=(dbv.type==DBVT_BLOB); + BOOL r=(dbv.type == DBVT_BLOB); if (r) pgp_set_keyid(ptr->cntx,(PVOID)dbv.pbVal); db_free(&dbv); return r; @@ -224,7 +224,7 @@ BOOL LoadKeyPGP(pUinKey ptr) BOOL LoadKeyGPG(pUinKey ptr) { LPSTR key = db_get_sa(ptr->hContact,MODULENAME,"gpg"); - if ( key ) { + if (key) { gpg_set_keyid(ptr->cntx,key); mir_free(key); return 2; diff --git a/plugins/SecureIM/src/crypt_icons.cpp b/plugins/SecureIM/src/crypt_icons.cpp index 6bcfcde382..d5eacbd51b 100644 --- a/plugins/SecureIM/src/crypt_icons.cpp +++ b/plugins/SecureIM/src/crypt_icons.cpp @@ -75,7 +75,7 @@ void ShowStatusIcon(HANDLE hContact, int mode) ExtraIcon_Clear(g_hCLIcon, hMC); } - if ( ServiceExists(MS_MSG_MODIFYICON)) { // обновить иконки в srmm + if (ServiceExists(MS_MSG_MODIFYICON)) { // обновить иконки в srmm StatusIconData sid = {sizeof(sid) }; sid.szModule = (char*)MODULENAME; for (int i = MODE_NATIVE; i < MODE_CNT; i++) { @@ -84,7 +84,7 @@ void ShowStatusIcon(HANDLE hContact, int mode) if (mode == -1 || (mode & 0x0f) != i || isChatRoom(hContact)) sid.flags |= MBF_HIDDEN; // отключаем все ненужные иконки CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); - if ( hMC ) + if (hMC ) CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); } } @@ -98,7 +98,7 @@ void ShowStatusIcon(HANDLE hContact) void ShowStatusIconNotify(HANDLE hContact) { BYTE mode = isContactSecured(hContact); - NotifyEventHooks(g_hEvent[(mode&SECURED)!=0], (WPARAM)hContact, 0); + NotifyEventHooks(g_hEvent[(mode&SECURED) != 0], (WPARAM)hContact, 0); ShowStatusIcon(hContact,mode); } @@ -109,7 +109,7 @@ void RefreshContactListIcons(void) HANDLE hContact = db_find_first(); while (hContact) { // и снова зажигаем иконку - if ( isSecureProtocol(hContact)) + if (isSecureProtocol(hContact)) ShowStatusIcon(hContact); hContact = db_find_next(hContact); } diff --git a/plugins/SecureIM/src/crypt_lists.cpp b/plugins/SecureIM/src/crypt_lists.cpp index 30f6c432d8..5c89f4d2e9 100644 --- a/plugins/SecureIM/src/crypt_lists.cpp +++ b/plugins/SecureIM/src/crypt_lists.cpp @@ -65,7 +65,7 @@ void freeSupportedProtocols() pSupPro getSupPro(HANDLE hContact) { for (int j=0; j < arProto.getCount(); j++) - if ( CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)arProto[j]->name)) + if (CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)arProto[j]->name)) return arProto[j]; return NULL; @@ -86,7 +86,7 @@ pUinKey addContact(HANDLE hContact) p->proto = proto; p->mode = db_get_b(hContact, MODULENAME, "mode", 99); if (p->mode == 99) { - if ( isContactPGP(hContact)) + if (isContactPGP(hContact)) p->mode = MODE_PGP; else p->mode = isContactGPG(hContact) ? MODE_GPG : MODE_RSAAES; @@ -162,16 +162,15 @@ pUinKey getUinCtx(HANDLE cntx) } // add message to user queue for send later -void addMsg2Queue(pUinKey ptr,WPARAM wParam,LPSTR szMsg) { - -#if defined(_DEBUG) || defined(NETLIB_LOG) +void addMsg2Queue(pUinKey ptr,WPARAM wParam,LPSTR szMsg) +{ Sent_NetLog("addMsg2Queue: msg: -----\n%s\n-----\n",szMsg); -#endif + pWM ptrMessage; EnterCriticalSection(&localQueueMutex); - if (ptr->msgQueue==NULL){ + if (ptr->msgQueue == NULL){ // create new ptr->msgQueue = (pWM) mir_alloc(sizeof(struct waitingMessage)); ptrMessage = ptr->msgQueue; @@ -221,8 +220,8 @@ void getContactUinA(HANDLE hContact, LPSTR szUIN) DBVARIANT dbv_uniqueid; LPSTR uID = (LPSTR) CallProtoService(ptr->name, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); - if ( uID==(LPSTR)CALLSERVICE_NOTFOUND ) uID = 0; // Billy_Bons - if ( uID && DBGetContactSetting(hContact, ptr->name, uID, &dbv_uniqueid)==0 ) { + if (uID == (LPSTR)CALLSERVICE_NOTFOUND ) uID = 0; // Billy_Bons + if (uID && DBGetContactSetting(hContact, ptr->name, uID, &dbv_uniqueid) == 0) { if (dbv_uniqueid.type == DBVT_WORD) sprintf(szUIN, "%u [%s]", dbv_uniqueid.wVal, ptr->name); else if (dbv_uniqueid.type == DBVT_DWORD) @@ -232,7 +231,7 @@ void getContactUinA(HANDLE hContact, LPSTR szUIN) else sprintf(szUIN, "%s [%s]", dbv_uniqueid.pszVal, ptr->name); } - else strcpy(szUIN, "=== unknown ==="); + else strcpy(szUIN, " == = unknown == ="); db_free(&dbv_uniqueid); } diff --git a/plugins/SecureIM/src/crypt_metacontacts.cpp b/plugins/SecureIM/src/crypt_metacontacts.cpp index 87e948716a..39bebd23c2 100644 --- a/plugins/SecureIM/src/crypt_metacontacts.cpp +++ b/plugins/SecureIM/src/crypt_metacontacts.cpp @@ -4,7 +4,7 @@ BOOL isProtoMetaContacts(HANDLE hContact) { if (bMetaContacts) { LPSTR proto = GetContactProto(hContact); - if ( proto && !strcmp(proto,"MetaContacts")) + if (proto && !strcmp(proto,"MetaContacts")) return true; } return false; diff --git a/plugins/SecureIM/src/crypt_misc.cpp b/plugins/SecureIM/src/crypt_misc.cpp index 3675a4198e..1732c54ccc 100644 --- a/plugins/SecureIM/src/crypt_misc.cpp +++ b/plugins/SecureIM/src/crypt_misc.cpp @@ -1,89 +1,62 @@ #include "commonheaders.h" - -int SendBroadcast( HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam ) { - ACKDATA ack; - memset(&ack,0,sizeof(ack)); - ack.cbSize = sizeof( ACKDATA ); - ack.szModule = GetContactProto(hContact); +int SendBroadcast(HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam) +{ + ACKDATA ack = { sizeof(ack) }; + ack.szModule = GetContactProto(hContact); ack.hContact = hContact; ack.type = type; ack.result = result; ack.hProcess = hProcess; ack.lParam = lParam; - return CallService( MS_PROTO_BROADCASTACK, 0, ( LPARAM )&ack ); -} - - -unsigned __stdcall sttFakeAck( LPVOID param ) { - - TFakeAckParams* tParam = ( TFakeAckParams* )param; - WaitForSingleObject( tParam->hEvent, INFINITE ); - - 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 )); - - CloseHandle( tParam->hEvent ); - delete tParam; - - return 0; + return CallService(MS_PROTO_BROADCASTACK, 0, (LPARAM)&ack); } +static void sttWaitForExchange(LPVOID param) +{ + HANDLE hContact = (HANDLE)param; + pUinKey ptr = getUinKey(hContact); + if (!ptr) + return; -unsigned __stdcall sttWaitForExchange( LPVOID param ) { - - TWaitForExchange* tParam = ( TWaitForExchange* )param; - WaitForSingleObject( tParam->hEvent, INFINITE ); - - pUinKey ptr = getUinKey(tParam->hContact); - delete tParam; - - if ( !ptr ) return 0; - - for (int i=0;iwaitForExchange != 1 ) break; - } // for + for (int i=0; i < db_get_w(0, MODULENAME, "ket", 10)*10; i++) { + Sleep(100); + if (ptr->waitForExchange != 1) + break; + } -#if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("sttWaitForExchange: %d",ptr->waitForExchange); -#endif - // if keyexchange failed or timeout - if ( ptr->waitForExchange==1 || ptr->waitForExchange==3 ) { // Їа®вге«® - ®вЇа ў«пҐ¬ ­Ґ§ иЁда®ў ­­®, Ґб«Ё ­ ¤® - if ( ptr->msgQueue && msgbox1(0,sim104,MODULENAME,MB_YESNO|MB_ICONQUESTION)==IDYES ) { - EnterCriticalSection(&localQueueMutex); - ptr->sendQueue = true; - pWM ptrMessage = ptr->msgQueue; - while( ptrMessage ) { -#if defined(_DEBUG) || defined(NETLIB_LOG) + + // if keyexchange failed or timeout + if (ptr->waitForExchange == 1 || ptr->waitForExchange == 3) { // протухло - отправляем незашифрованно, если надо + if (ptr->msgQueue && msgbox1(0,sim104,MODULENAME,MB_YESNO|MB_ICONQUESTION) == IDYES) { + EnterCriticalSection(&localQueueMutex); + ptr->sendQueue = true; + pWM ptrMessage = ptr->msgQueue; + while(ptrMessage) { Sent_NetLog("Sent (unencrypted) message from queue: %s",ptrMessage->Message); -#endif - // send unencrypted messages - CallContactService(ptr->hContact,PSS_MESSAGE,(WPARAM)ptrMessage->wParam|PREF_METANODB,(LPARAM)ptrMessage->Message); - mir_free(ptrMessage->Message); - pWM tmp = ptrMessage; - ptrMessage = ptrMessage->nextMessage; - mir_free(tmp); - } - ptr->msgQueue = NULL; - ptr->sendQueue = false; - LeaveCriticalSection(&localQueueMutex); - } + + // send unencrypted messages + CallContactService(ptr->hContact,PSS_MESSAGE,(WPARAM)ptrMessage->wParam|PREF_METANODB,(LPARAM)ptrMessage->Message); + mir_free(ptrMessage->Message); + pWM tmp = ptrMessage; + ptrMessage = ptrMessage->nextMessage; + mir_free(tmp); + } + ptr->msgQueue = NULL; + ptr->sendQueue = false; + LeaveCriticalSection(&localQueueMutex); + } ptr->waitForExchange = 0; - ShowStatusIconNotify(ptr->hContact); - } - else - if ( ptr->waitForExchange==2 ) { // ¤®б« вм ®зҐаҐ¤м зҐаҐ§ гбв ­®ў«Ґ­­®Ґ ᮥ¤Ё­Ґ­ЁҐ + ShowStatusIconNotify(ptr->hContact); + } + else if (ptr->waitForExchange == 2) { // дослать очередь через установленное соединение EnterCriticalSection(&localQueueMutex); // we need to resend last send back message with new crypto Key pWM ptrMessage = ptr->msgQueue; while (ptrMessage) { -#if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("Sent (encrypted) message from queue: %s",ptrMessage->Message); -#endif + // send unencrypted messages CallContactService(ptr->hContact,PSS_MESSAGE,(WPARAM)ptrMessage->wParam|PREF_METANODB,(LPARAM)ptrMessage->Message); mir_free(ptrMessage->Message); @@ -94,9 +67,8 @@ unsigned __stdcall sttWaitForExchange( LPVOID param ) { ptr->msgQueue = NULL; ptr->waitForExchange = 0; LeaveCriticalSection(&localQueueMutex); - } - else - if ( ptr->waitForExchange==0 ) { // ®зЁбвЁвм ®зҐаҐ¤м + } + else if (ptr->waitForExchange == 0) { // очистить очередь EnterCriticalSection(&localQueueMutex); // we need to resend last send back message with new crypto Key pWM ptrMessage = ptr->msgQueue; @@ -108,29 +80,25 @@ unsigned __stdcall sttWaitForExchange( LPVOID param ) { } ptr->msgQueue = NULL; LeaveCriticalSection(&localQueueMutex); - } - return 0; + } } - // set wait flag and run thread -void waitForExchange(pUinKey ptr, int flag) { - switch( flag ) { - case 0: // бЎа®бЁвм - case 2: // ¤®б« вм иЁда®ў ­® - case 3: // ¤®б« вм ­ҐиЁда®ў ­® - if ( ptr->waitForExchange ) +void waitForExchange(pUinKey ptr, int flag) +{ + switch(flag) { + case 0: // reset + case 2: // send secure + case 3: // send unsecure + if (ptr->waitForExchange) ptr->waitForExchange = flag; break; - case 1: // § ЇгбвЁвм - if ( ptr->waitForExchange ) + case 1: // launch + if (ptr->waitForExchange) break; + ptr->waitForExchange = 1; - // § ЇгбЄ Ґ¬ ван¤ - HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); - unsigned int tID; - CloseHandle( (HANDLE) _beginthreadex(NULL, 0, sttWaitForExchange, new TWaitForExchange(hEvent,ptr->hContact), 0, &tID)); - SetEvent( hEvent ); + mir_forkthread(sttWaitForExchange, ptr->hContact); break; } } diff --git a/plugins/SecureIM/src/gettime.cpp b/plugins/SecureIM/src/gettime.cpp index 529a8e0c8e..f38fe2e672 100644 --- a/plugins/SecureIM/src/gettime.cpp +++ b/plugins/SecureIM/src/gettime.cpp @@ -11,19 +11,20 @@ const static ULONGLONG ix_epoch = 116444736000000000; const static ULONGLONG ix_epoch = 116444736000000000LL; #endif -DWORD gettime(void) { +DWORD gettime(void) +{ - ULONGLONG diff_100_nsec; - union { - FILETIME f; - ULARGE_INTEGER u; - } now; + ULONGLONG diff_100_nsec; + union { + FILETIME f; + ULARGE_INTEGER u; + } now; - GetSystemTimeAsFileTime( &now.f ); + GetSystemTimeAsFileTime(&now.f); - diff_100_nsec = now.u.QuadPart - ix_epoch; + diff_100_nsec = now.u.QuadPart - ix_epoch; - return (DWORD)( diff_100_nsec / div_100_nsec ); + return (DWORD)(diff_100_nsec / div_100_nsec); } // EOF diff --git a/plugins/SecureIM/src/images.cpp b/plugins/SecureIM/src/images.cpp index eb4c87dea1..abecbb5ab8 100644 --- a/plugins/SecureIM/src/images.cpp +++ b/plugins/SecureIM/src/images.cpp @@ -214,7 +214,7 @@ BOOL MakeBitmap32(HBITMAP *hBitmap) } -#define GET_PIXEL(__P__, __X__, __Y__) ( __P__ + width * 4 * (__Y__) + 4 * (__X__)) +#define GET_PIXEL(__P__, __X__, __Y__)(__P__ + width * 4 * (__Y__) + 4 * (__X__)) BOOL MakeGrayscale(HBITMAP *hBitmap) { @@ -250,7 +250,7 @@ BOOL MakeGrayscale(HBITMAP *hBitmap) for (x = 0 ; x < width ; x++) { p1 = GET_PIXEL(p, x, y); - p1[0] = p1[1] = p1[2] = ( p1[0] + p1[1] + p1[2] ) / 3; + p1[0] = p1[1] = p1[2] = (p1[0] + p1[1] + p1[2]) / 3; } } @@ -268,10 +268,10 @@ HICON MakeHalfAlphaIcon(HICON SourceIcon) HICON TargetIcon, TempIcon; TempIcon = CopyIcon(SourceIcon); - if ( !GetIconInfo(TempIcon, &TargetIconInfo)) + if (!GetIconInfo(TempIcon, &TargetIconInfo)) return NULL; - if ( !GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo)) + if (!GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo)) return NULL; MakeBitmap32(&TargetIconInfo.hbmColor); @@ -292,7 +292,7 @@ HICON MakeGrayscaleIcon(HICON SourceIcon) HICON TargetIcon, TempIcon; TempIcon = CopyIcon(SourceIcon); - if (! GetIconInfo(TempIcon, &TargetIconInfo) || GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo)==0) return NULL; + if (! GetIconInfo(TempIcon, &TargetIconInfo) || GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo) == 0) return NULL; MakeGrayscale(&TargetIconInfo.hbmColor); @@ -313,14 +313,14 @@ HICON BindOverlayIcon(HICON SourceIcon,HICON OverlayIcon) BLENDFUNCTION bf = {0,0,255,1}; TempIcon = CopyIcon(SourceIcon); - if ( !GetIconInfo( TempIcon, &TargetIconInfo )) + if (!GetIconInfo(TempIcon, &TargetIconInfo)) return NULL; MakeBitmap32(&TargetIconInfo.hbmColor); CorrectBitmap32Alpha(TargetIconInfo.hbmColor, FALSE); GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo); - if ( !GetIconInfo(OverlayIcon, &OverlayIconInfo) || !GetObject(OverlayIconInfo.hbmColor, sizeof(BITMAP), &OverlayBitmapInfo)) + if (!GetIconInfo(OverlayIcon, &OverlayIconInfo) || !GetObject(OverlayIconInfo.hbmColor, sizeof(BITMAP), &OverlayBitmapInfo)) return NULL; TargetDC = CreateCompatibleDC(NULL); diff --git a/plugins/SecureIM/src/loadicons.cpp b/plugins/SecureIM/src/loadicons.cpp index 473bc7108a..dc550f3ca2 100644 --- a/plugins/SecureIM/src/loadicons.cpp +++ b/plugins/SecureIM/src/loadicons.cpp @@ -75,7 +75,7 @@ void InitIcons(void) { HINSTANCE hNewIconInst = NULL; - if ( g_hFolders ) { + if (g_hFolders) { TCHAR pathname[MAX_PATH]; FoldersGetCustomPathExT(g_hFolders, pathname, MAX_PATH, "icons\\"); if (hNewIconInst == NULL) diff --git a/plugins/SecureIM/src/loadlib.cpp b/plugins/SecureIM/src/loadlib.cpp index ac0d2f9272..ac75e5c172 100644 --- a/plugins/SecureIM/src/loadlib.cpp +++ b/plugins/SecureIM/src/loadlib.cpp @@ -5,9 +5,9 @@ CRYPTOPP_INFO cpp; BOOL loadlib(void) { HMODULE h = LoadLibraryA("plugins/cryptopp.dll"); - if ( h == NULL ) { + if (h == NULL) { h = LoadLibraryA("cryptopp.dll"); - if ( h == NULL ) return 0; + if (h == NULL ) return 0; } cpp.cc = (_cpp_create_context) GetProcAddress(h, "cpp_create_context"); diff --git a/plugins/SecureIM/src/main.cpp b/plugins/SecureIM/src/main.cpp index 4876f94887..504e2e1e5e 100644 --- a/plugins/SecureIM/src/main.cpp +++ b/plugins/SecureIM/src/main.cpp @@ -2,7 +2,8 @@ int hLangpack = 0; -BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID) { +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID) +{ g_hInst = hInst; if (dwReason == DLL_PROCESS_ATTACH) { INITCOMMONCONTROLSEX icce = { sizeof(icce), ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES }; @@ -52,7 +53,7 @@ extern "C" __declspec(dllexport) int __cdecl Load(void) GetTempPath(sizeof(temp),temp); GetLongPathName(temp,TEMP,sizeof(TEMP)); TEMP_SIZE = (int)strlen(TEMP); - if (TEMP[TEMP_SIZE-1]=='\\') { + if (TEMP[TEMP_SIZE-1] == '\\') { TEMP_SIZE--; TEMP[TEMP_SIZE]='\0'; } @@ -60,15 +61,15 @@ extern "C" __declspec(dllexport) int __cdecl Load(void) // check for support TrueColor Icons BOOL bIsComCtl6 = FALSE; HMODULE hComCtlDll = LoadLibrary(_T("comctl32.dll")); - if ( hComCtlDll ) { + if (hComCtlDll) { typedef HRESULT (CALLBACK *PFNDLLGETVERSION)(DLLVERSIONINFO*); PFNDLLGETVERSION pfnDllGetVersion = (PFNDLLGETVERSION) GetProcAddress(hComCtlDll,"DllGetVersion"); - if ( pfnDllGetVersion ) { + if (pfnDllGetVersion) { DLLVERSIONINFO dvi; memset(&dvi,0,sizeof(dvi)); dvi.cbSize = sizeof(dvi); - HRESULT hRes = (*pfnDllGetVersion)( &dvi ); - if ( SUCCEEDED(hRes) && dvi.dwMajorVersion >= 6 ) { + HRESULT hRes = (*pfnDllGetVersion)(&dvi); + if (SUCCEEDED(hRes) && dvi.dwMajorVersion >= 6) { bIsComCtl6 = TRUE; } } @@ -80,7 +81,7 @@ extern "C" __declspec(dllexport) int __cdecl Load(void) iCoreVersion = CallService(MS_SYSTEM_GETVERSION,0,0); // load crypo++ dll - if ( !loadlib()) { + if (!loadlib()) { msgbox1(0,sim107,MODULENAME,MB_OK|MB_ICONSTOP); return 1; } @@ -134,10 +135,7 @@ int ModuleLoad(WPARAM wParam, LPARAM lParam) int onModulesLoaded(WPARAM wParam, LPARAM lParam) { -#if defined(_DEBUG) || defined(NETLIB_LOG) InitNetlib(); - Sent_NetLog("onModuleLoaded begin"); -#endif g_hFolders = FoldersRegisterCustomPathT(LPGEN("SecureIM"), LPGEN("Icons"), _T(MIRANDA_PATH"\\icons")); @@ -145,21 +143,19 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) GetFlags(); ModuleLoad(0, 0); -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("rsa_init"); -#endif // RSA/AES + Sent_NetLog("rsa_init"); rsa_init(&exp, &imp); DBVARIANT dbv; dbv.type = DBVT_BLOB; - if ( DBGetContactSetting(0,MODULENAME,"rsa_priv",&dbv) == 0 ) { + if (DBGetContactSetting(0,MODULENAME,"rsa_priv",&dbv) == 0) { exp->rsa_set_keypair(CPP_MODE_RSA_4096,dbv.pbVal,dbv.cpbVal); db_free(&dbv); rsa_4096=1; } - else if ( DBGetContactSetting(0,MODULENAME,"rsa_priv_4096",&dbv) == 0 ) { + else if (DBGetContactSetting(0,MODULENAME,"rsa_priv_4096",&dbv) == 0) { exp->rsa_set_keypair(CPP_MODE_RSA_4096|CPP_MODE_RSA_BER,dbv.pbVal,dbv.cpbVal); db_free(&dbv); @@ -187,63 +183,57 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) rsa_4096 = 1; } - if ( !rsa_4096 ) { - unsigned int tID; - CloseHandle( (HANDLE) _beginthreadex(NULL, 0, sttGenerateRSA, NULL, 0, &tID)); - } + if (!rsa_4096) + mir_forkthread(sttGenerateRSA, NULL); exp->rsa_set_timeout( db_get_w(0,MODULENAME,"ket",10)); -#if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("pgp_init"); -#endif + bPGP = db_get_b(0, MODULENAME, "pgp", 0); if (bPGP) { //PGP - bPGPloaded = pgp_init(); - bUseKeyrings = db_get_b(0,MODULENAME,"ukr",1); - LPSTR priv = myDBGetStringDecode(0,MODULENAME,"pgpPrivKey"); - if (priv) { - bPGPprivkey = true; - if (bPGPloaded) - pgp_set_priv_key(priv); - mir_free(priv); - }// if (priv) - if (bPGPloaded && bUseKeyrings) { - char PubRingPath[MAX_PATH], SecRingPath[MAX_PATH]; - PubRingPath[0]='\0'; SecRingPath[0]='\0'; - if (pgp_get_version()<0x02000000) { // 6xx - bPGPkeyrings = pgp_open_keyrings(PubRingPath,SecRingPath); - } - else { - LPSTR tmp; - tmp = db_get_sa(0,MODULENAME,"pgpPubRing"); - if (tmp) { - strncpy(PubRingPath,tmp,sizeof(PubRingPath)); - mir_free(tmp); - } - tmp = db_get_sa(0,MODULENAME,"pgpSecRing"); - if (tmp) { - strncpy(SecRingPath,tmp,sizeof(SecRingPath)); - mir_free(tmp); - } - if (PubRingPath[0] && SecRingPath[0]) { - bPGPkeyrings = pgp_open_keyrings(PubRingPath,SecRingPath); - if (bPGPkeyrings) { - db_set_s(0,MODULENAME,"pgpPubRing",PubRingPath); - db_set_s(0,MODULENAME,"pgpSecRing",SecRingPath); - } - else { - db_unset(0, MODULENAME, "pgpPubRing"); - db_unset(0, MODULENAME, "pgpSecRing"); - } - } - } - }// if (bPGPloaded && bUseKeyrings) - }// if (bPGP) - -#if defined(_DEBUG) || defined(NETLIB_LOG) + bPGPloaded = pgp_init(); + bUseKeyrings = db_get_b(0,MODULENAME,"ukr",1); + LPSTR priv = myDBGetStringDecode(0,MODULENAME,"pgpPrivKey"); + if (priv) { + bPGPprivkey = true; + if (bPGPloaded) + pgp_set_priv_key(priv); + mir_free(priv); + }// if (priv) + if (bPGPloaded && bUseKeyrings) { + char PubRingPath[MAX_PATH], SecRingPath[MAX_PATH]; + PubRingPath[0]='\0'; SecRingPath[0]='\0'; + if (pgp_get_version()<0x02000000) { // 6xx + bPGPkeyrings = pgp_open_keyrings(PubRingPath,SecRingPath); + } + else { + LPSTR tmp = db_get_sa(0,MODULENAME,"pgpPubRing"); + if (tmp) { + strncpy(PubRingPath,tmp,sizeof(PubRingPath)); + mir_free(tmp); + } + if (tmp = db_get_sa(0,MODULENAME,"pgpSecRing")) { + strncpy(SecRingPath,tmp,sizeof(SecRingPath)); + mir_free(tmp); + } + if (PubRingPath[0] && SecRingPath[0]) { + bPGPkeyrings = pgp_open_keyrings(PubRingPath,SecRingPath); + if (bPGPkeyrings) { + db_set_s(0,MODULENAME,"pgpPubRing",PubRingPath); + db_set_s(0,MODULENAME,"pgpSecRing",SecRingPath); + } + else { + db_unset(0, MODULENAME, "pgpPubRing"); + db_unset(0, MODULENAME, "pgpSecRing"); + } + } + } + }// if (bPGPloaded && bUseKeyrings) + }// if (bPGP) + Sent_NetLog("gpg_init"); -#endif + bGPG = db_get_b(0, MODULENAME, "gpg", 0); if (bGPG) { //GPG bGPGloaded = gpg_init(); @@ -256,23 +246,20 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) strncpy(gpgexec,tmp,sizeof(gpgexec)); mir_free(tmp); } - tmp = db_get_sa(0,MODULENAME,"gpgHome"); - if (tmp) { + if (tmp = db_get_sa(0,MODULENAME,"gpgHome")) { strncpy(gpghome,tmp,sizeof(gpghome)); mir_free(tmp); } if (db_get_b(0, MODULENAME, "gpgLogFlag",0)) { - tmp = db_get_sa(0,MODULENAME,"gpgLog"); - if (tmp) { + if (tmp = db_get_sa(0,MODULENAME,"gpgLog")) { gpg_set_log(tmp); mir_free(tmp); } } if (db_get_b(0, MODULENAME, "gpgTmpFlag",0)) { - tmp = db_get_sa(0,MODULENAME,"gpgTmp"); - if (tmp) { + if (tmp = db_get_sa(0,MODULENAME,"gpgTmp")) { gpg_set_tmp(tmp); mir_free(tmp); } @@ -290,33 +277,24 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) bSavePass = db_get_b(0,MODULENAME,"gpgSaveFlag",0); if (bSavePass) { - tmp = db_get_sa(0,MODULENAME,"gpgSave"); - if (tmp) { + if (tmp = db_get_sa(0,MODULENAME,"gpgSave")) { gpg_set_passphrases(tmp); mir_free(tmp); } } } -#if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("loadContactList"); -#endif loadContactList(); // add new skin sound SkinAddNewSound("IncomingSecureMessage",LPGEN("Incoming Secure Message"),"Sounds\\iSecureMessage.wav"); SkinAddNewSound("OutgoingSecureMessage",LPGEN("Outgoing Secure Message"),"Sounds\\oSecureMessage.wav"); -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("init extra icons"); -#endif // init extra icons - for (int i=0;i<1+MODE_CNT*IEC_CNT;i++) + for (int i=0; i < SIZEOF(g_IEC); i++) g_IEC[i] = (HANDLE)-1; -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("hook events"); -#endif HookEvent(ME_CLIST_PREBUILDCONTACTMENU, onRebuildContactMenu); g_hCLIcon = ExtraIcon_Register(MODULENAME, LPGEN("SecureIM status"), "sim_cm_est", onExtraImageListRebuilding, onExtraImageApplying); @@ -336,47 +314,33 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) CreateProtoServiceFunction(MODULENAME, PSS_MESSAGE"W", onSendMsgW); CreateProtoServiceFunction(MODULENAME, PSS_FILE, onSendFile); -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("create Native/RSA menu"); -#endif // create a menu item for creating a secure im connection to the user. - g_hMenu[0] = AddMenuItem(sim301,110000,g_hICO[ICO_CM_EST],MODULENAME"/SIM_EST",CMIF_NOTOFFLINE); - g_hMenu[1] = AddMenuItem(sim302,110001,g_hICO[ICO_CM_DIS],MODULENAME"/SIM_DIS",CMIF_NOTOFFLINE); + g_hMenu[0] = AddMenuItem(sim301, 110000, g_hICO[ICO_CM_EST], MODULENAME"/SIM_EST", CMIF_NOTOFFLINE); + g_hMenu[1] = AddMenuItem(sim302, 110001, g_hICO[ICO_CM_DIS], MODULENAME"/SIM_DIS", CMIF_NOTOFFLINE); if (ServiceExists(MS_CLIST_MENUBUILDSUBGROUP)) { - g_hMenu[2] = AddMenuItem(sim312[0],110002,NULL,NULL,CMIF_ROOTPOPUP); - g_hMenu[3] = AddSubItem(g_hMenu[2],sim232[0],110003,110002,MODULENAME"/SIM_ST_DIS"); - g_hMenu[4] = AddSubItem(g_hMenu[2],sim232[1],110004,110002,MODULENAME"/SIM_ST_ENA"); - g_hMenu[5] = AddSubItem(g_hMenu[2],sim232[2],110005,110002,MODULENAME"/SIM_ST_TRY"); + g_hMenu[2] = AddMenuItem(sim312[0], 110002, NULL, NULL, CMIF_ROOTPOPUP); + g_hMenu[3] = AddSubItem(g_hMenu[2], sim232[0], 110003, 110002, MODULENAME"/SIM_ST_DIS"); + g_hMenu[4] = AddSubItem(g_hMenu[2], sim232[1], 110004, 110002, MODULENAME"/SIM_ST_ENA"); + g_hMenu[5] = AddSubItem(g_hMenu[2], sim232[2], 110005, 110002, MODULENAME"/SIM_ST_TRY"); } else { g_hMenu[2] = 0; - g_hMenu[3] = AddMenuItem(sim232[0],110003,NULL,MODULENAME"/SIM_ST_DIS"); - g_hMenu[4] = AddMenuItem(sim232[1],110004,NULL,MODULENAME"/SIM_ST_ENA"); - g_hMenu[5] = AddMenuItem(sim232[2],110005,NULL,MODULENAME"/SIM_ST_TRY"); + g_hMenu[3] = AddMenuItem(sim232[0], 110003, NULL, MODULENAME"/SIM_ST_DIS"); + g_hMenu[4] = AddMenuItem(sim232[1], 110004, NULL, MODULENAME"/SIM_ST_ENA"); + g_hMenu[5] = AddMenuItem(sim232[2], 110005, NULL, MODULENAME"/SIM_ST_TRY"); } -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("create PGP/GPG menu"); -#endif - HICON icon; - if ( bPGPloaded ) { - icon=mode2icon(MODE_PGP|SECURED,2); - g_hMenu[6] = AddMenuItem(sim306,110006,icon,MODULENAME"/PGP_SET",0); - icon=mode2icon(MODE_PGP,2); - g_hMenu[7] = AddMenuItem(sim307,110007,icon,MODULENAME"/PGP_DEL",0); + if (bPGPloaded) { + g_hMenu[6] = AddMenuItem(sim306, 110006, mode2icon(MODE_PGP|SECURED,2), MODULENAME"/PGP_SET", 0); + g_hMenu[7] = AddMenuItem(sim307, 110007, mode2icon(MODE_PGP,2), MODULENAME"/PGP_DEL", 0); } if (bGPGloaded) { - icon=mode2icon(MODE_GPG|SECURED,2); - g_hMenu[8] = AddMenuItem(sim308,110008,icon,MODULENAME"/GPG_SET",0); - icon=mode2icon(MODE_GPG,2); - g_hMenu[9] = AddMenuItem(sim309,110009,icon,MODULENAME"/GPG_DEL",0); + g_hMenu[8] = AddMenuItem(sim308, 110008, mode2icon(MODE_GPG|SECURED,2), MODULENAME"/GPG_SET", 0); + g_hMenu[9] = AddMenuItem(sim309, 110009, mode2icon(MODE_GPG,2), MODULENAME"/GPG_DEL", 0); } -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("create Mode menu"); -#endif if (ServiceExists(MS_CLIST_MENUBUILDSUBGROUP)) { g_hMenu[10] = AddMenuItem(sim311[0],110010,NULL,NULL,CMIF_ROOTPOPUP); g_hMenu[11] = AddSubItem(g_hMenu[10],sim231[0],110011,110010,MODULENAME"/MODE_NAT"); @@ -392,9 +356,6 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) g_hMenu[14] = AddMenuItem(sim231[3],110014,NULL,MODULENAME"/MODE_RSA"); } -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("create srmm icons"); -#endif // add icon to srmm status icons if (ServiceExists(MS_MSG_ADDICON)) { StatusIconData sid = { sizeof(sid) }; @@ -430,9 +391,6 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) HookEvent(ME_MSG_ICONPRESSED, onIconPressed); } -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("onModuleLoaded end"); -#endif return 0; } @@ -454,9 +412,8 @@ int onSystemOKToExit(WPARAM wParam, LPARAM lParam) freeContactList(); free_rtfconv(); -#if defined(_DEBUG) || defined(NETLIB_LOG) + DeinitNetlib(); -#endif return 0; } diff --git a/plugins/SecureIM/src/mmi.cpp b/plugins/SecureIM/src/mmi.cpp index 09cc5f2db3..4a6b06bbe4 100644 --- a/plugins/SecureIM/src/mmi.cpp +++ b/plugins/SecureIM/src/mmi.cpp @@ -75,8 +75,8 @@ LPSTR to_hex(PBYTE bin, int len) { SAFE_FREE(m_hex); m_hex = (LPSTR) mir_alloc(len*3+1); LPSTR m_ptr = m_hex; - for ( int i=0; iutf8decode(szUtfMsg); LPSTR szMsg = mir_u2a(wszMsg); diff --git a/plugins/SecureIM/src/options.cpp b/plugins/SecureIM/src/options.cpp index 4789e9dfca..3cbbe13449 100644 --- a/plugins/SecureIM/src/options.cpp +++ b/plugins/SecureIM/src/options.cpp @@ -8,14 +8,14 @@ BOOL bChangeSortOrder = false; BOOL hasKey(pUinKey ptr) { BOOL ret = 0; - if ( ptr->mode==MODE_NATIVE ) { + if (ptr->mode == MODE_NATIVE) { LPSTR str = db_get_sa(ptr->hContact,MODULENAME,"PSK"); - ret = (str!=NULL); SAFE_FREE(str); + ret = (str != NULL); SAFE_FREE(str); } - else if ( ptr->mode==MODE_RSAAES ) { + else if (ptr->mode == MODE_RSAAES) { DBVARIANT dbv; dbv.type = DBVT_BLOB; - if ( DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0 ) { + if (DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0) { ret = 1; db_free(&dbv); } @@ -144,14 +144,14 @@ INT_PTR CALLBACK OptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara break; case ID_UPDATE_PLIST: - if ( !bPGP ) break; + if (!bPGP ) break; tci.mask = TCIF_PARAM; TabCtrl_GetItem(GetDlgItem(hwnd,IDC_OPTIONSTAB),2,&tci); SendMessage((HWND)tci.lParam,WM_COMMAND,ID_UPDATE_CLIST,0); break; case ID_UPDATE_GLIST: - if ( !bGPG ) break; + if (!bGPG ) break; tci.mask = TCIF_PARAM; TabCtrl_GetItem(GetDlgItem(hwnd,IDC_OPTIONSTAB),3,&tci); SendMessage((HWND)tci.lParam,WM_COMMAND,ID_UPDATE_GLIST,0); @@ -314,14 +314,14 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR idx = ListView_GetSelectionMark(hLV); ptr = (pUinKey) getListViewParam(hLV,idx); if (ptr) { - if ( !ptr->keyLoaded ) { + if (!ptr->keyLoaded) { createRSAcntx(ptr); loadRSAkey(ptr); } - if ( ptr->keyLoaded ) { + if (ptr->keyLoaded) { LPSTR buffer = (LPSTR) alloca(RSASIZE); exp->rsa_export_pubkey(ptr->cntx,buffer); - if ( !SaveExportRSAKeyDlg(hDlg,buffer,0)) + if (!SaveExportRSAKeyDlg(hDlg,buffer,0)) msgbox(hDlg,sim114,MODULENAME,MB_OK|MB_ICONEXCLAMATION); } } @@ -333,8 +333,8 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR if (ptr) { createRSAcntx(ptr); LPSTR pub = (LPSTR) alloca(RSASIZE); - if ( !LoadImportRSAKeyDlg(hDlg,pub,0)) return TRUE; - if ( exp->rsa_import_pubkey(ptr->cntx,pub)) { + if (!LoadImportRSAKeyDlg(hDlg,pub,0)) return TRUE; + if (exp->rsa_import_pubkey(ptr->cntx,pub)) { int len; exp->rsa_get_pubkey(ptr->cntx,(PBYTE)pub,&len); @@ -415,9 +415,9 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR ptr = (pUinKey) getListViewParam(hLV,idx); if (ptr) { ptr->tmode++; - if ( !bPGP && ptr->tmode==MODE_PGP ) ptr->tmode++; - if ( !bGPG && ptr->tmode==MODE_GPG ) ptr->tmode++; - if ( ptr->tmode>=MODE_CNT ) ptr->tmode=MODE_NATIVE; + if (!bPGP && ptr->tmode == MODE_PGP ) ptr->tmode++; + if (!bGPG && ptr->tmode == MODE_GPG ) ptr->tmode++; + if (ptr->tmode>=MODE_CNT ) ptr->tmode=MODE_NATIVE; setListViewMode(hLV,idx,ptr->tmode); setListViewIcon(hLV,idx,ptr); SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0); @@ -427,7 +427,7 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR idx = LPNMLISTVIEW(lParam)->iItem; ptr = (pUinKey) getListViewParam(hLV,idx); if (ptr) { - ptr->tstatus++; if (ptr->tstatus>(ptr->tmode==MODE_RSAAES?1:2)) ptr->tstatus=0; + ptr->tstatus++; if (ptr->tstatus>(ptr->tmode == MODE_RSAAES?1:2)) ptr->tstatus=0; setListViewStatus(hLV,idx,ptr->tstatus); setListViewIcon(hLV,idx,ptr); SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0); @@ -442,39 +442,39 @@ INT_PTR CALLBACK DlgProcOptionsGeneral(HWND hDlg, UINT wMsg, WPARAM wParam, LPAR if (ptr) { POINT p; GetCursorPos(&p); HMENU hMenu = NULL; - if ( ptr->tmode==MODE_NATIVE || ptr->tmode==MODE_RSAAES ) { - switch( lpLV->iSubItem ) { + if (ptr->tmode == MODE_NATIVE || ptr->tmode == MODE_RSAAES) { + switch( lpLV->iSubItem) { case 2: // mode hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDM_CLIST2)); break; case 3: // status - hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE((ptr->tmode==MODE_NATIVE)?IDM_CLIST01:IDM_CLIST11)); + hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE((ptr->tmode == MODE_NATIVE)?IDM_CLIST01:IDM_CLIST11)); break; case 4: // PSK/PUB case 5: // SHA1 - hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE((ptr->tmode==MODE_NATIVE)?IDM_CLIST02:IDM_CLIST12)); + hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE((ptr->tmode == MODE_NATIVE)?IDM_CLIST02:IDM_CLIST12)); break; default: // full menu - hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE((ptr->tmode==MODE_NATIVE)?IDM_CLIST0:IDM_CLIST1)); + hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE((ptr->tmode == MODE_NATIVE)?IDM_CLIST0:IDM_CLIST1)); break; } CheckMenuItem(hMenu, ID_DISABLED+ptr->tstatus, MF_CHECKED ); - if ( ptr->tmode==MODE_NATIVE ) { - if ( !hasKey(ptr)) EnableMenuItem(hMenu, ID_DELPSK, MF_GRAYED ); + if (ptr->tmode == MODE_NATIVE) { + if (!hasKey(ptr)) EnableMenuItem(hMenu, ID_DELPSK, MF_GRAYED ); } - else if ( ptr->tmode==MODE_RSAAES ) { - if ( !hasKey(ptr)) { + else if (ptr->tmode == MODE_RSAAES) { + if (!hasKey(ptr)) { EnableMenuItem(hMenu, ID_EXPPUBL, MF_GRAYED ); EnableMenuItem(hMenu, ID_DELPUBL, MF_GRAYED ); } } } - if ( !hMenu ) + if (!hMenu ) hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDM_CLIST2)); TranslateMenu(hMenu); CheckMenuItem(hMenu, ID_SIM_NATIVE+ptr->tmode, MF_CHECKED ); - if ( !bPGP ) EnableMenuItem(hMenu, ID_SIM_PGP, MF_GRAYED ); - if ( !bGPG ) EnableMenuItem(hMenu, ID_SIM_GPG, MF_GRAYED ); + if (!bPGP ) EnableMenuItem(hMenu, ID_SIM_PGP, MF_GRAYED ); + if (!bGPG ) EnableMenuItem(hMenu, ID_SIM_GPG, MF_GRAYED ); TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_LEFTALIGN | TPM_TOPALIGN, p.x, p.y, 0, hDlg, 0); DestroyMenu(hMenu); } @@ -538,7 +538,7 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM { LPSTR pub = (LPSTR) alloca(RSASIZE); exp->rsa_export_keypair(CPP_MODE_RSA,NULL,pub,NULL); - if ( !SaveExportRSAKeyDlg(hDlg,pub,0)) + if (!SaveExportRSAKeyDlg(hDlg,pub,0)) msgbox(hDlg,sim114,MODULENAME,MB_OK|MB_ICONEXCLAMATION); } return TRUE; @@ -547,10 +547,10 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM { LPSTR passphrase = (LPSTR) alloca(RSASIZE); int res = DialogBoxParam(g_hInst,MAKEINTRESOURCE(IDD_PASSPHRASE),NULL,DlgProcSetPassphrase,(LPARAM)passphrase); - if ( res==IDOK ) { + if (res == IDOK) { LPSTR priv = (LPSTR) alloca(RSASIZE); exp->rsa_export_keypair(CPP_MODE_RSA,priv,NULL,passphrase); - if ( !SaveExportRSAKeyDlg(hDlg,priv,1)) + if (!SaveExportRSAKeyDlg(hDlg,priv,1)) msgbox(hDlg,sim112,MODULENAME,MB_OK|MB_ICONEXCLAMATION); } } @@ -559,13 +559,13 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM case IDC_RSA_IMPPRIV: { LPSTR priv = (LPSTR) alloca(RSASIZE); - if ( !LoadImportRSAKeyDlg(hDlg,priv,1)) + if (!LoadImportRSAKeyDlg(hDlg,priv,1)) return TRUE; LPSTR passphrase = (LPSTR) alloca(RSASIZE); int res = DialogBoxParam(g_hInst,MAKEINTRESOURCE(IDD_PASSPHRASE),NULL,DlgProcSetPassphrase,(LPARAM)passphrase); - if ( res==IDOK ) { - if ( !exp->rsa_import_keypair(CPP_MODE_RSA,priv,passphrase)) + if (res == IDOK) { + if (!exp->rsa_import_keypair(CPP_MODE_RSA,priv,passphrase)) msgbox(hDlg,sim113,MODULENAME,MB_OK|MB_ICONEXCLAMATION); else // обновить SHA1 значение RefreshProtoDlg(hDlg); @@ -575,7 +575,7 @@ INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM case IDC_SPLITON: case IDC_SPLITOFF: - if ( HIWORD(wParam) == EN_CHANGE ) { + if (HIWORD(wParam) == EN_CHANGE) { idx = ListView_GetSelectionMark(hLV); if (idx == -1) break; @@ -699,7 +699,7 @@ INT_PTR CALLBACK DlgProcOptionsPGP(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM l case IDC_NO_KEYRINGS: { - BOOL bNoKR = (SendMessage(GetDlgItem(hDlg, IDC_NO_KEYRINGS),BM_GETCHECK,0L,0L)==BST_CHECKED); + BOOL bNoKR = (SendMessage(GetDlgItem(hDlg, IDC_NO_KEYRINGS),BM_GETCHECK,0L,0L) == BST_CHECKED); EnableWindow(GetDlgItem(hDlg, IDC_SET_KEYRINGS), !bNoKR); EnableWindow(GetDlgItem(hDlg, IDC_LOAD_PRIVKEY), bNoKR); SetDlgItemText(hDlg, IDC_KEYRING_STATUS, bNoKR?Translate(sim225):((bPGP9)?Translate(sim220):(bPGPkeyrings?Translate(sim216):Translate(sim217)))); @@ -861,7 +861,7 @@ INT_PTR CALLBACK DlgProcOptionsGPG(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM l if (LPNMLISTVIEW(lParam)->iSubItem == 3) { idx = LPNMLISTVIEW(lParam)->iItem; ptr = (pUinKey) getListViewParam(hLV,idx); - if ( !ptr ) break; + if (!ptr ) break; ptr->tgpgMode++; ptr->tgpgMode&=1; LV_SetItemTextA(hLV, LPNMLISTVIEW(lParam)->iItem, LPNMLISTVIEW(lParam)->iSubItem, (ptr->tgpgMode)?Translate(sim228):Translate(sim229)); SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0); @@ -893,7 +893,7 @@ INT_PTR CALLBACK DlgProcSetPSK(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: - if ( GetDlgItemTextA(hDlg, IDC_EDIT1, buffer, PSKSIZE) < 8) { + if (GetDlgItemTextA(hDlg, IDC_EDIT1, buffer, PSKSIZE) < 8) { msgbox1(hDlg, sim211, MODULENAME, MB_OK | MB_ICONEXCLAMATION); return TRUE; } @@ -990,8 +990,8 @@ void RefreshGeneralDlg(HWND hDlg, BOOL iInit) while (hContact) { pUinKey ptr = getUinKey(hContact); - if ( ptr && isSecureProtocol(hContact) && !isChatRoom(hContact)) { - if ( iInit ) { + if (ptr && isSecureProtocol(hContact) && !isChatRoom(hContact)) { + if (iInit) { ptr->tmode = ptr->mode; ptr->tstatus = ptr->status; } @@ -1009,7 +1009,7 @@ void RefreshGeneralDlg(HWND hDlg, BOOL iInit) setListViewMode(hLV, itemNum, ptr->tmode); setListViewStatus(hLV, itemNum, ptr->tstatus); - if ( ptr->mode==MODE_NATIVE ) setListViewPSK(hLV, itemNum, hasKey(ptr)); + if (ptr->mode == MODE_NATIVE ) setListViewPSK(hLV, itemNum, hasKey(ptr)); else setListViewPUB(hLV, itemNum, hasKey(ptr)); setListViewIcon(hLV, itemNum, ptr); } @@ -1078,11 +1078,11 @@ void RefreshPGPDlg(HWND hDlg, BOOL iInit) while (hContact) { pUinKey ptr = getUinKey(hContact); - if (ptr && ptr->mode==MODE_PGP && isSecureProtocol(hContact) /*&& !getMetaContact(hContact)*/ && !isChatRoom(hContact)) { + if (ptr && ptr->mode == MODE_PGP && isSecureProtocol(hContact) /*&& !getMetaContact(hContact)*/ && !isChatRoom(hContact)) { LPSTR szKeyID = db_get_sa(hContact,MODULENAME,"pgp_abbr"); lvi.iItem++; - lvi.iImage = (szKeyID!=0); + lvi.iImage = (szKeyID != 0); lvi.lParam = (LPARAM)ptr; getContactName(hContact, tmp); @@ -1140,14 +1140,14 @@ void RefreshGPGDlg(HWND hDlg, BOOL iInit) while (hContact) { pUinKey ptr = getUinKey(hContact); - if (ptr && ptr->mode==MODE_GPG && isSecureProtocol(hContact) /*&& !getMetaContact(hContact)*/ && !isChatRoom(hContact)) { - if ( iInit ) + if (ptr && ptr->mode == MODE_GPG && isSecureProtocol(hContact) /*&& !getMetaContact(hContact)*/ && !isChatRoom(hContact)) { + if (iInit ) ptr->tgpgMode = ptr->gpgMode; LPSTR szKeyID = db_get_sa(hContact,MODULENAME,"gpg"); lvi.iItem++; - lvi.iImage = (szKeyID!=0); + lvi.iImage = (szKeyID != 0); lvi.lParam = (LPARAM)ptr; getContactName(hContact, tmp); @@ -1215,7 +1215,7 @@ void ResetGeneralDlg(HWND hDlg) setListViewMode(hLV, itemNum, ptr->tmode); setListViewStatus(hLV, itemNum, ptr->tstatus); - if ( ptr->mode==MODE_NATIVE ) setListViewPSK(hLV, itemNum, 0); + if (ptr->mode == MODE_NATIVE ) setListViewPSK(hLV, itemNum, 0); else setListViewPUB(hLV, itemNum, 0); setListViewIcon(hLV, itemNum, ptr); } @@ -1245,29 +1245,29 @@ void ApplyGeneralSettings(HWND hDlg) mir_itoa(tmp,timeout,10); SetDlgItemText(hDlg,IDC_OKT,timeout); - bSFT = (SendMessage(GetDlgItem(hDlg, IDC_SFT),BM_GETCHECK,0L,0L)==BST_CHECKED); - bSOM = (SendMessage(GetDlgItem(hDlg, IDC_SOM),BM_GETCHECK,0L,0L)==BST_CHECKED); - bASI = (SendMessage(GetDlgItem(hDlg, IDC_ASI),BM_GETCHECK,0L,0L)==BST_CHECKED); - bMCD = (SendMessage(GetDlgItem(hDlg, IDC_MCD),BM_GETCHECK,0L,0L)==BST_CHECKED); - bSCM = (SendMessage(GetDlgItem(hDlg, IDC_SCM),BM_GETCHECK,0L,0L)==BST_CHECKED); - bDGP = (SendMessage(GetDlgItem(hDlg, IDC_DGP),BM_GETCHECK,0L,0L)==BST_CHECKED); - bAIP = (SendMessage(GetDlgItem(hDlg, IDC_AIP),BM_GETCHECK,0L,0L)==BST_CHECKED); - bNOL = (SendMessage(GetDlgItem(hDlg, IDC_NOL),BM_GETCHECK,0L,0L)==BST_CHECKED); - bAAK = (SendMessage(GetDlgItem(hDlg, IDC_AAK),BM_GETCHECK,0L,0L)==BST_CHECKED); - bMCM = (SendMessage(GetDlgItem(hDlg, IDC_MCM),BM_GETCHECK,0L,0L)==BST_CHECKED); + bSFT = (SendMessage(GetDlgItem(hDlg, IDC_SFT),BM_GETCHECK,0L,0L) == BST_CHECKED); + bSOM = (SendMessage(GetDlgItem(hDlg, IDC_SOM),BM_GETCHECK,0L,0L) == BST_CHECKED); + bASI = (SendMessage(GetDlgItem(hDlg, IDC_ASI),BM_GETCHECK,0L,0L) == BST_CHECKED); + bMCD = (SendMessage(GetDlgItem(hDlg, IDC_MCD),BM_GETCHECK,0L,0L) == BST_CHECKED); + bSCM = (SendMessage(GetDlgItem(hDlg, IDC_SCM),BM_GETCHECK,0L,0L) == BST_CHECKED); + bDGP = (SendMessage(GetDlgItem(hDlg, IDC_DGP),BM_GETCHECK,0L,0L) == BST_CHECKED); + bAIP = (SendMessage(GetDlgItem(hDlg, IDC_AIP),BM_GETCHECK,0L,0L) == BST_CHECKED); + bNOL = (SendMessage(GetDlgItem(hDlg, IDC_NOL),BM_GETCHECK,0L,0L) == BST_CHECKED); + bAAK = (SendMessage(GetDlgItem(hDlg, IDC_AAK),BM_GETCHECK,0L,0L) == BST_CHECKED); + bMCM = (SendMessage(GetDlgItem(hDlg, IDC_MCM),BM_GETCHECK,0L,0L) == BST_CHECKED); SetFlags(); // PGP &| GPG flags { tmp = 0; - i = SendMessage(GetDlgItem(hDlg, IDC_PGP),BM_GETCHECK,0L,0L)==BST_CHECKED; - if (i!=bPGP) { + i = SendMessage(GetDlgItem(hDlg, IDC_PGP),BM_GETCHECK,0L,0L) == BST_CHECKED; + if (i != bPGP) { bPGP = i; tmp++; db_set_b(0, MODULENAME, "pgp", bPGP); } - i = SendMessage(GetDlgItem(hDlg, IDC_GPG),BM_GETCHECK,0L,0L)==BST_CHECKED; - if (i!=bGPG) { + i = SendMessage(GetDlgItem(hDlg, IDC_GPG),BM_GETCHECK,0L,0L) == BST_CHECKED; + if (i != bGPG) { bGPG = i; tmp++; db_set_b(0, MODULENAME, "gpg", bGPG); } @@ -1276,20 +1276,20 @@ void ApplyGeneralSettings(HWND hDlg) HWND hLV = GetDlgItem(hDlg,IDC_STD_USERLIST); i = ListView_GetNextItem(hLV,(UINT)-1,LVNI_ALL); - while(i!=-1) { + while(i != -1) { pUinKey ptr = (pUinKey)getListViewParam(hLV,i); - if ( !ptr ) continue; - if ( ptr->mode!=ptr->tmode ) { + if (!ptr ) continue; + if (ptr->mode != ptr->tmode) { ptr->mode = ptr->tmode; db_set_b(ptr->hContact, MODULENAME, "mode", ptr->mode); } - if ( ptr->status!=ptr->tstatus ) { + if (ptr->status != ptr->tstatus) { ptr->status = ptr->tstatus; - if (ptr->status==STATUS_ENABLED) db_unset(ptr->hContact, MODULENAME, "StatusID"); + if (ptr->status == STATUS_ENABLED) db_unset(ptr->hContact, MODULENAME, "StatusID"); else db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status); } - if ( ptr->mode==MODE_NATIVE ) { - if ( getListViewPSK(hLV,i)) { + if (ptr->mode == MODE_NATIVE) { + if (getListViewPSK(hLV,i)) { LPSTR tmp = db_get_sa(ptr->hContact,MODULENAME,"tPSK"); db_set_s(ptr->hContact, MODULENAME, "PSK", tmp); mir_free(tmp); @@ -1298,8 +1298,8 @@ void ApplyGeneralSettings(HWND hDlg) db_unset(ptr->hContact, MODULENAME, "tPSK"); } - else if ( ptr->mode==MODE_RSAAES ) { - if ( !getListViewPUB(hLV,i)) + else if (ptr->mode == MODE_RSAAES) { + if (!getListViewPUB(hLV,i)) db_unset(ptr->hContact, MODULENAME, "rsa_pub"); } i = ListView_GetNextItem(hLV,i,LVNI_ALL); @@ -1328,7 +1328,7 @@ void ApplyProtoSettings(HWND hDlg) void ApplyPGPSettings(HWND hDlg) { - bUseKeyrings = !(SendMessage(GetDlgItem(hDlg, IDC_NO_KEYRINGS),BM_GETCHECK,0L,0L)==BST_CHECKED); + bUseKeyrings = !(SendMessage(GetDlgItem(hDlg, IDC_NO_KEYRINGS),BM_GETCHECK,0L,0L) == BST_CHECKED); db_set_b(0,MODULENAME,"ukr",bUseKeyrings); char *priv = db_get_sa(0,MODULENAME,"tpgpPrivKey"); @@ -1350,17 +1350,17 @@ void ApplyGPGSettings(HWND hDlg) GetDlgItemText(hDlg, IDC_GPGHOME_EDIT, tmp, sizeof(tmp)); db_set_s(0,MODULENAME,"gpgHome",tmp); - bSavePass = (SendMessage(GetDlgItem(hDlg, IDC_SAVEPASS_CBOX),BM_GETCHECK,0L,0L)==BST_CHECKED); + bSavePass = (SendMessage(GetDlgItem(hDlg, IDC_SAVEPASS_CBOX),BM_GETCHECK,0L,0L) == BST_CHECKED); db_set_b(0,MODULENAME,"gpgSaveFlag",bSavePass); - BOOL bgpgLogFlag = (SendMessage(GetDlgItem(hDlg, IDC_LOGGINGON_CBOX),BM_GETCHECK,0L,0L)==BST_CHECKED); + BOOL bgpgLogFlag = (SendMessage(GetDlgItem(hDlg, IDC_LOGGINGON_CBOX),BM_GETCHECK,0L,0L) == BST_CHECKED); db_set_b(0,MODULENAME,"gpgLogFlag",bgpgLogFlag); GetDlgItemText(hDlg, IDC_GPGLOGFILE_EDIT, tmp, sizeof(tmp)); db_set_s(0,MODULENAME,"gpgLog",tmp); if (bgpgLogFlag) gpg_set_log(tmp); else gpg_set_log(0); - BOOL bgpgTmpFlag = (SendMessage(GetDlgItem(hDlg, IDC_TMPPATHON_CBOX),BM_GETCHECK,0L,0L)==BST_CHECKED); + BOOL bgpgTmpFlag = (SendMessage(GetDlgItem(hDlg, IDC_TMPPATHON_CBOX),BM_GETCHECK,0L,0L) == BST_CHECKED); db_set_b(0,MODULENAME,"gpgTmpFlag",bgpgTmpFlag); GetDlgItemText(hDlg, IDC_GPGTMPPATH_EDIT, tmp, sizeof(tmp)); db_set_s(0,MODULENAME,"gpgTmp",tmp); @@ -1369,12 +1369,12 @@ void ApplyGPGSettings(HWND hDlg) HWND hLV = GetDlgItem(hDlg,IDC_GPG_USERLIST); int i = ListView_GetNextItem(hLV,(UINT)-1,LVNI_ALL); - while(i!=-1) { + while(i != -1) { pUinKey ptr = (pUinKey)getListViewParam(hLV,i); - if ( !ptr ) continue; - if ( ptr->gpgMode != ptr->tgpgMode ) { + if (!ptr ) continue; + if (ptr->gpgMode != ptr->tgpgMode) { ptr->gpgMode = ptr->tgpgMode; - if ( ptr->gpgMode ) db_set_b(ptr->hContact,MODULENAME,"gpgANSI",1); + if (ptr->gpgMode ) db_set_b(ptr->hContact,MODULENAME,"gpgANSI",1); else db_unset(ptr->hContact,MODULENAME,"gpgANSI"); } @@ -1433,7 +1433,7 @@ UINT getListViewPSK(HWND hLV, UINT iItem) { char str[128]; LV_GetItemTextA(hLV, iItem, 4, str, sizeof(str)); - return strncmp(str, Translate(sim206), sizeof(str))==0; + return strncmp(str, Translate(sim206), sizeof(str)) == 0; } void setListViewPSK(HWND hLV, UINT iItem, UINT iStatus) @@ -1447,7 +1447,7 @@ UINT getListViewPUB(HWND hLV, UINT iItem) { char str[128]; LV_GetItemTextA(hLV, iItem, 4, str, sizeof(str)); - return strncmp(str, Translate(sim233), sizeof(str))==0; + return strncmp(str, Translate(sim233), sizeof(str)) == 0; } void setListViewPUB(HWND hLV, UINT iItem, UINT iStatus) @@ -1457,18 +1457,18 @@ void setListViewPUB(HWND hLV, UINT iItem, UINT iStatus) LV_SetItemTextA(hLV, iItem, 4, str); LPSTR sha = NULL; - if ( iStatus ) { + if (iStatus) { DBVARIANT dbv; dbv.type = DBVT_BLOB; pUinKey ptr = (pUinKey) getListViewParam(hLV, iItem); - if ( DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0 ) { + if (DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0) { int len; exp->rsa_get_hash((PBYTE)dbv.pbVal,dbv.cpbVal,(PBYTE)str,&len); sha = mir_strdup(to_hex((PBYTE)str,len)); db_free(&dbv); } } - if ( sha ) { + if (sha) { LV_SetItemTextA(hLV, iItem, 5, sha); mir_free(sha); } @@ -1510,8 +1510,8 @@ int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) case 0x13: db_get_s(p1->hContact,MODULENAME,"pgp_abbr",&dbv1); db_get_s(p2->hContact,MODULENAME,"pgp_abbr",&dbv2); - s=(dbv1.type==DBVT_ASCIIZ); - d=(dbv2.type==DBVT_ASCIIZ); + s=(dbv1.type == DBVT_ASCIIZ); + d=(dbv2.type == DBVT_ASCIIZ); if (s && d) { s=strcmp(dbv1.pszVal,dbv2.pszVal); d=0; @@ -1540,10 +1540,10 @@ int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) case 0x05: db_get_s(p1->hContact,MODULENAME,"PSK",&dbv1); - s=(dbv1.type==DBVT_ASCIIZ); + s=(dbv1.type == DBVT_ASCIIZ); db_free(&dbv1); db_get_s(p2->hContact,MODULENAME,"PSK",&dbv2); - d=(dbv2.type==DBVT_ASCIIZ); + d=(dbv2.type == DBVT_ASCIIZ); db_free(&dbv2); return (s-d)*m; } @@ -1556,7 +1556,7 @@ void ListView_Sort(HWND hLV, LPARAM lParamSort) // restore sort column sprintf(t,"os%02x",(UINT)lParamSort&0xF0); - if ((lParamSort&0x0F)==0) + if ((lParamSort&0x0F) == 0) lParamSort=(int)db_get_b(0, MODULENAME, t, lParamSort+1); db_set_b(0, MODULENAME, t, (BYTE)lParamSort); @@ -1614,9 +1614,9 @@ LPSTR LoadKeys(LPCSTR file,BOOL priv) LPSTR keys = (LPSTR)mir_alloc(flen+1); int i=0; BOOL b=false; while(fgets(keys+i,128,f)) { - if (!b && strncmp(keys+i,beg,strlen(beg))==0) + if (!b && strncmp(keys+i,beg,strlen(beg)) == 0) b=true; - else if (b && strncmp(keys+i,end,strlen(end))==0) { + else if (b && strncmp(keys+i,end,strlen(end)) == 0) { i+=(int)strlen(keys+i); b=false; } @@ -1644,11 +1644,11 @@ BOOL SaveExportRSAKeyDlg(HWND hParent, LPSTR key, BOOL priv) ofn.lpstrFile = szFile; ofn.lpstrTitle = (priv) ? TranslateT("Save Private Key File") : TranslateT("Save Public Key File"); - if ( !GetSaveFileName(&ofn)) + if (!GetSaveFileName(&ofn)) return FALSE; FILE *f = _tfopen(szFile, _T("wb")); - if ( !f) + if (!f) return FALSE; fwrite(key, strlen(key), 1, f); fclose(f); @@ -1672,11 +1672,11 @@ BOOL LoadImportRSAKeyDlg(HWND hParent, LPSTR key, BOOL priv) mir_snprintf(temp, SIZEOF(temp), _T("%s (*.asc)%c*.asc%c%s (*.*)%c*.*%c%c"), Translate("ASC files"), 0, 0, Translate("All files"), 0, 0, 0); ofn.lpstrFilter = temp; ofn.lpstrTitle = (priv) ? TranslateT("Load Private Key File") : TranslateT("Load Public Key File"); - if ( !GetOpenFileName(&ofn)) + if (!GetOpenFileName(&ofn)) return FALSE; FILE *f = _tfopen(szFile, _T("rb")); - if ( !f) + if (!f) return FALSE; fseek(f, 0, SEEK_END); diff --git a/plugins/SecureIM/src/popupOptions.cpp b/plugins/SecureIM/src/popupOptions.cpp index 9f135b62fb..7098db2b0e 100644 --- a/plugins/SecureIM/src/popupOptions.cpp +++ b/plugins/SecureIM/src/popupOptions.cpp @@ -87,27 +87,27 @@ INT_PTR CALLBACK PopOptionsDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM l break; case IDC_EC: //set ec checkbox value - db_set_b(0, MODULENAME, "ec", (BYTE)(SendMessage(hec,BM_GETCHECK,0L,0L)==BST_CHECKED)); + db_set_b(0, MODULENAME, "ec", (BYTE)(SendMessage(hec,BM_GETCHECK,0L,0L) == BST_CHECKED)); break; case IDC_DC: //set dc checkbox value - db_set_b(0, MODULENAME, "dc", (BYTE)(SendMessage(hdc,BM_GETCHECK,0L,0L)==BST_CHECKED)); + db_set_b(0, MODULENAME, "dc", (BYTE)(SendMessage(hdc,BM_GETCHECK,0L,0L) == BST_CHECKED)); break; case IDC_SS: //set ss checkbox value - db_set_b(0, MODULENAME, "ss", (BYTE)(SendMessage(hss,BM_GETCHECK,0L,0L)==BST_CHECKED)); + db_set_b(0, MODULENAME, "ss", (BYTE)(SendMessage(hss,BM_GETCHECK,0L,0L) == BST_CHECKED)); break; case IDC_SR: //set sr checkbox value - db_set_b(0, MODULENAME, "sr", (BYTE)(SendMessage(hsr,BM_GETCHECK,0L,0L)==BST_CHECKED)); + db_set_b(0, MODULENAME, "sr", (BYTE)(SendMessage(hsr,BM_GETCHECK,0L,0L) == BST_CHECKED)); break; case IDC_KS: //set indicator checkbox value - db_set_b(0, MODULENAME, "ks", (BYTE)(SendMessage(hks,BM_GETCHECK,0L,0L)==BST_CHECKED)); + db_set_b(0, MODULENAME, "ks", (BYTE)(SendMessage(hks,BM_GETCHECK,0L,0L) == BST_CHECKED)); break; case IDC_KR: //set indicator checkbox value - db_set_b(0, MODULENAME, "kr", (BYTE)(SendMessage(hkr,BM_GETCHECK,0L,0L)==BST_CHECKED)); + db_set_b(0, MODULENAME, "kr", (BYTE)(SendMessage(hkr,BM_GETCHECK,0L,0L) == BST_CHECKED)); break; case IDC_TIMEKEY: //set timeout value diff --git a/plugins/SecureIM/src/rtfconv.cpp b/plugins/SecureIM/src/rtfconv.cpp index c046a61fbb..f8acf59059 100644 --- a/plugins/SecureIM/src/rtfconv.cpp +++ b/plugins/SecureIM/src/rtfconv.cpp @@ -8,14 +8,14 @@ RTFCONVSTRING pRtfconvString = NULL; BOOL load_rtfconv () { hRtfconv = LoadLibrary(_T("rtfconv.dll")) ; - if ( hRtfconv == NULL ) { + if (hRtfconv == NULL) { hRtfconv = LoadLibrary(_T("plugins\\rtfconv.dll")) ; - if ( hRtfconv == NULL ) + if (hRtfconv == NULL ) return FALSE; } pRtfconvString = (RTFCONVSTRING) GetProcAddress( hRtfconv, "RtfconvString" ) ; - if ( pRtfconvString == NULL ) { + if (pRtfconvString == NULL) { FreeLibrary( hRtfconv ) ; return FALSE; } @@ -25,7 +25,7 @@ BOOL load_rtfconv () { void free_rtfconv () { - if ( hRtfconv ) + if (hRtfconv ) FreeLibrary( hRtfconv ) ; pRtfconvString = NULL; hRtfconv = NULL; diff --git a/plugins/SecureIM/src/rtfconv.h b/plugins/SecureIM/src/rtfconv.h index c051836e25..eed541a85e 100644 --- a/plugins/SecureIM/src/rtfconv.h +++ b/plugins/SecureIM/src/rtfconv.h @@ -7,9 +7,8 @@ #define CONVMODE_USE_SYSTEM_TABLE 0x800000 /* Use OS's table only */ -typedef intptr_t (WINAPI *RTFCONVSTRING) ( const void *pSrcBuffer, void *pDstBuffer, - int nSrcCodePage, int nDstCodePage, unsigned long dwFlags, - size_t nMaxLen ); +typedef intptr_t (WINAPI *RTFCONVSTRING)(const void *pSrcBuffer, void *pDstBuffer, + int nSrcCodePage, int nDstCodePage, unsigned long dwFlags, size_t nMaxLen); extern RTFCONVSTRING pRtfconvString; diff --git a/plugins/SecureIM/src/splitmsg.cpp b/plugins/SecureIM/src/splitmsg.cpp index 74583df741..a21cb8ef44 100644 --- a/plugins/SecureIM/src/splitmsg.cpp +++ b/plugins/SecureIM/src/splitmsg.cpp @@ -2,11 +2,10 @@ // разбивает сообщение szMsg на части длиной iLen, возвращает строку вида PARTzPARTzz -LPSTR splitMsg(LPSTR szMsg, int iLen) { - -#if defined(_DEBUG) || defined(NETLIB_LOG) +LPSTR splitMsg(LPSTR szMsg, int iLen) +{ Sent_NetLog("split: msg: -----\n%s\n-----\n",szMsg); -#endif + int len = (int)strlen(szMsg); LPSTR out = (LPSTR) mir_alloc(len*2); LPSTR buf = out; @@ -20,9 +19,9 @@ LPSTR splitMsg(LPSTR szMsg, int iLen) { mir_snprintf(buf,32,"%s%04X%02X%02X",SIG_SECP,msg_id,part_num,part_all); memcpy(buf+LEN_SECP+8,szMsg,sz); *(buf+LEN_SECP+8+sz) = '\0'; -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("split: part: %s",buf); -#endif + buf += LEN_SECP+8+sz+1; szMsg += sz; len -= sz; @@ -33,16 +32,15 @@ LPSTR splitMsg(LPSTR szMsg, int iLen) { // собираем сообщение из частей, части храним в структуре у контакта -LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) { - -#if defined(_DEBUG) || defined(NETLIB_LOG) +LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) +{ Sent_NetLog("combine: part: %s",szMsg); -#endif + int msg_id,part_num,part_all; sscanf(szMsg,"%4X%2X%2X",&msg_id,&part_num,&part_all); // pPM ppm = NULL, pm = ptr->msgPart; - if ( !ptr->msgPart ) { + if (!ptr->msgPart) { pm = ptr->msgPart = new partitionMessage; memset(pm,0,sizeof(partitionMessage)); pm->id = msg_id; @@ -51,7 +49,7 @@ LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) { } else while(pm) { - if ( pm->id == msg_id ) break; + if (pm->id == msg_id ) break; ppm = pm; pm = pm->nextMessage; } if (!pm) { // nothing to found @@ -63,18 +61,18 @@ LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) { } pm->message[part_num] = new char[strlen(szMsg)]; strcpy(pm->message[part_num],szMsg+8); -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("combine: save part: %s",pm->message[part_num]); -#endif + int len=0,i; - for ( i=0; imessage[i]==NULL) break; + for ( i=0; imessage[i] == NULL) break; len+=(int)strlen(pm->message[i]); } - if ( i==part_all ) { // combine message + if (i == part_all) { // combine message SAFE_FREE(ptr->tmp); ptr->tmp = (LPSTR) mir_alloc(len+1); *(ptr->tmp)='\0'; - for ( i=0; itmp,pm->message[i]); delete pm->message[i]; } @@ -82,16 +80,14 @@ LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) { if (ppm) ppm->nextMessage = pm->nextMessage; else ptr->msgPart = pm->nextMessage; delete pm; -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("combine: all parts: -----\n%s\n-----\n", ptr->tmp); -#endif - // собрали одно сообщение + // combined one message return ptr->tmp; } -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("combine: not all parts"); -#endif - // еще не собрали + // not combined yet return NULL; } @@ -101,11 +97,11 @@ int splitMessageSend(pUinKey ptr, LPSTR szMsg) { int ret; int len = (int)strlen(szMsg); - int par = (getContactStatus(ptr->hContact)==ID_STATUS_OFFLINE)?ptr->proto->split_off:ptr->proto->split_on; - if ( par && len>par ) { + int par = (getContactStatus(ptr->hContact) == ID_STATUS_OFFLINE)?ptr->proto->split_off:ptr->proto->split_on; + if (par && len>par) { LPSTR msg = splitMsg(szMsg,par); LPSTR buf = msg; - while( *buf ) { + while( *buf) { len = (int)strlen(buf); LPSTR tmp = mir_strdup(buf); ret = CallContactService(ptr->hContact,PSS_MESSAGE,(WPARAM)PREF_METANODB,(LPARAM)tmp); diff --git a/plugins/SecureIM/src/svcs_clist.cpp b/plugins/SecureIM/src/svcs_clist.cpp index bcec8fb8fa..2b02df1092 100644 --- a/plugins/SecureIM/src/svcs_clist.cpp +++ b/plugins/SecureIM/src/svcs_clist.cpp @@ -9,15 +9,15 @@ int __cdecl onContactSettingChanged(WPARAM wParam,LPARAM lParam) { pUinKey ptr = getUinKey(hContact); int stat = getContactStatus(hContact); - if (!ptr || stat==-1) return 0; + if (!ptr || stat == -1) return 0; - if (stat==ID_STATUS_OFFLINE) { // go offline - if (ptr->mode==MODE_NATIVE && cpp_keyx(ptr->cntx)) { // have active context + if (stat == ID_STATUS_OFFLINE) { // go offline + if (ptr->mode == MODE_NATIVE && cpp_keyx(ptr->cntx)) { // have active context cpp_delete_context(ptr->cntx); ptr->cntx=0; // reset context showPopUpDC(hContact); // show popup "Disabled" ShowStatusIconNotify(hContact); // change icon in CL } - else if (ptr->mode==MODE_RSAAES && exp->rsa_get_state(ptr->cntx)==7) { + else if (ptr->mode == MODE_RSAAES && exp->rsa_get_state(ptr->cntx) == 7) { deleteRSAcntx(ptr); showPopUpDC(hContact); // show popup "Disabled" ShowStatusIconNotify(hContact); // change icon in CL @@ -58,20 +58,17 @@ int __cdecl onExtraImageListRebuilding(WPARAM, LPARAM) int __cdecl onExtraImageApplying(WPARAM wParam, LPARAM) { - if ( isSecureProtocol((HANDLE)wParam)) + if (isSecureProtocol((HANDLE)wParam)) ExtraIcon_SetIcon(g_hCLIcon, (HANDLE)wParam, mode2clicon( isContactSecured((HANDLE)wParam), 1)); return 0; } -int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam) { - -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("onRebuildContactMenu"); -#endif +int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam) +{ HANDLE hContact = (HANDLE)wParam; BOOL bMC = isProtoMetaContacts(hContact); - if ( bMC ) hContact = getMostOnline(hContact); // возьмем тот, через который пойдет сообщение + if (bMC ) hContact = getMostOnline(hContact); // возьмем тот, через который пойдет сообщение pUinKey ptr = getUinKey(hContact); int i; @@ -83,14 +80,14 @@ int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam) { // hide menu bars mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIF_HIDDEN; for (i=0;imode==MODE_NATIVE || ptr->mode==MODE_RSAAES)) { + if (isSecureProto && !isChat && isMiranda && + (ptr->mode == MODE_NATIVE || ptr->mode == MODE_RSAAES)) { // Native/RSAAES mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIM_ICON; - if ( !isSecured ) { + if (!isSecured) { // create secureim connection mi.hIcon = mode2icon(ptr->mode|SECURED,2); CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[0],(LPARAM)&mi); @@ -122,8 +119,8 @@ int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam) { CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[1],(LPARAM)&mi); } // set status menu - if ( bSCM && !bMC && - ( !isSecured || ptr->mode==MODE_PGP || ptr->mode==MODE_GPG )) { + if (bSCM && !bMC && + ( !isSecured || ptr->mode == MODE_PGP || ptr->mode == MODE_GPG )) { mi.flags = CMIM_FLAGS | CMIM_NAME | CMIM_ICON; mi.hIcon = g_hICO[ICO_ST_DIS+ptr->status]; @@ -131,32 +128,32 @@ int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam) { CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[2],(LPARAM)&mi); mi.flags = CMIM_FLAGS | CMIM_ICON; - for (i=0;i<=(ptr->mode==MODE_RSAAES?1:2);i++) { + for (i=0;i<=(ptr->mode == MODE_RSAAES?1:2);i++) { mi.hIcon = (i == ptr->status) ? g_hICO[ICO_ST_DIS+ptr->status] : NULL; CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[3+i],(LPARAM)&mi); } } } else - if ( isSecureProto && !isChat && (ptr->mode==MODE_PGP || ptr->mode==MODE_GPG)) { + if (isSecureProto && !isChat && (ptr->mode == MODE_PGP || ptr->mode == MODE_GPG)) { // PGP, GPG - if ( ptr->mode==MODE_PGP && bPGPloaded ) { + if (ptr->mode == MODE_PGP && bPGPloaded) { if ((bPGPkeyrings || bPGPprivkey) && !isGPG) { mi.flags = CMIM_FLAGS; CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[isPGP+6],(LPARAM)&mi); } } - if ( ptr->mode==MODE_GPG && bGPGloaded ) { + if (ptr->mode == MODE_GPG && bGPGloaded) { if (bGPGkeyrings && !isPGP) { mi.flags = CMIM_FLAGS; CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[isGPG+8],(LPARAM)&mi); } } } - if ( isSecureProto && !isChat && isMiranda ) { + if (isSecureProto && !isChat && isMiranda) { // set mode menu - if ( bMCM && !bMC && - ( !isSecured || ptr->mode==MODE_PGP || ptr->mode==MODE_GPG )) { + if (bMCM && !bMC && + ( !isSecured || ptr->mode == MODE_PGP || ptr->mode == MODE_GPG )) { mi.flags = CMIM_FLAGS | CMIM_NAME | CMIM_ICON; mi.hIcon = g_hICO[ICO_OV_NAT+ptr->mode]; @@ -165,8 +162,8 @@ int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam) { mi.flags = CMIM_FLAGS | CMIM_ICON; for (i=0;imode!=MODE_PGP && !bPGP ) continue; - if ( i==MODE_GPG && ptr->mode!=MODE_GPG && !bGPG ) continue; + if (i == MODE_PGP && ptr->mode != MODE_PGP && !bPGP ) continue; + if (i == MODE_GPG && ptr->mode != MODE_GPG && !bGPG ) continue; mi.hIcon = (i == ptr->mode) ? g_hICO[ICO_ST_ENA] : NULL; CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)g_hMenu[11+i],(LPARAM)&mi); } diff --git a/plugins/SecureIM/src/svcs_menu.cpp b/plugins/SecureIM/src/svcs_menu.cpp index 7190bbe785..516e941459 100644 --- a/plugins/SecureIM/src/svcs_menu.cpp +++ b/plugins/SecureIM/src/svcs_menu.cpp @@ -28,7 +28,7 @@ INT_PTR __cdecl Service_Status(WPARAM wParam, LPARAM lParam) pUinKey ptr = getUinKey((HANDLE)wParam); if (ptr) { ptr->status=ptr->tstatus=(BYTE)lParam; - if (ptr->status==STATUS_ENABLED) db_unset(ptr->hContact, MODULENAME, "StatusID"); + if (ptr->status == STATUS_ENABLED) db_unset(ptr->hContact, MODULENAME, "StatusID"); else db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status); } break; @@ -159,14 +159,14 @@ INT_PTR __cdecl Service_Mode(WPARAM wParam, LPARAM lParam) msgbox(NULL, sim111, MODULENAME, MB_OK); return 0; } - if ( lParam!=MODE_NATIVE && ptr->status>STATUS_ENABLED ) + if (lParam != MODE_NATIVE && ptr->status>STATUS_ENABLED ) Service_Status(wParam,STATUS_ENABLED+1); case MODE_PGP: case MODE_GPG: // нужно много проверок и отключение активного контекста если необходимо if (ptr) { - if ( ptr->cntx ) { + if (ptr->cntx) { cpp_delete_context(ptr->cntx); ptr->cntx = 0; ptr->keyLoaded = 0; 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 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 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(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; } diff --git a/plugins/SecureIM/src/svcs_rsa.cpp b/plugins/SecureIM/src/svcs_rsa.cpp index 552b79dab9..38adfa7cd8 100644 --- a/plugins/SecureIM/src/svcs_rsa.cpp +++ b/plugins/SecureIM/src/svcs_rsa.cpp @@ -1,21 +1,21 @@ #include "commonheaders.h" - pRSA_EXPORT exp = NULL; -RSA_IMPORT imp = { - rsa_inject, - rsa_check_pub, - rsa_notify +RSA_IMPORT imp = +{ + rsa_inject, + rsa_check_pub, + rsa_notify }; BOOL rsa_4096=0; - -int __cdecl rsa_inject(HANDLE context, LPCSTR msg) { +int __cdecl rsa_inject(HANDLE context, LPCSTR msg) +{ pUinKey ptr = getUinCtx(context); if (!ptr) return 0; -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("rsa_inject: '%s'", msg); -#endif + int len = (int)strlen(msg)+1; LPSTR buf = (LPSTR) mir_alloc(LEN_SECU+len); memcpy(buf,SIG_SECU,LEN_SECU); @@ -26,10 +26,10 @@ int __cdecl rsa_inject(HANDLE context, LPCSTR msg) { return 1; } - #define MSGSIZE 1024 -int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int sigLen) { +int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int sigLen) +{ int v=0, k=0; pUinKey ptr = getUinCtx(context); if (!ptr) return 0; LPSTR cnm = (LPSTR) mir_alloc(NAMSIZE); getContactNameA(ptr->hContact,cnm); @@ -37,20 +37,20 @@ int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int LPSTR msg = (LPSTR) mir_alloc(MSGSIZE); LPSTR sha = mir_strdup(to_hex(sig,sigLen)); LPSTR sha_old = NULL; -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("rsa_check_pub: %s %s %s", cnm, uin, sha); -#endif + DBVARIANT dbv; dbv.type = DBVT_BLOB; - if ( DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0 ) { + if (DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0) { k = 1; PBYTE buf = (PBYTE) alloca(sigLen); int len; exp->rsa_get_hash((PBYTE)dbv.pbVal,dbv.cpbVal,(PBYTE)buf,&len); sha_old = mir_strdup(to_hex(buf,len)); db_free(&dbv); } - if ( bAAK ) { - if ( k ) mir_snprintf(msg,MSGSIZE,Translate(sim523),cnm,uin,sha,sha_old); + if (bAAK) { + if (k ) mir_snprintf(msg,MSGSIZE,Translate(sim523),cnm,uin,sha,sha_old); else mir_snprintf(msg,MSGSIZE,Translate(sim521),cnm,uin,sha); showPopUpKRmsg(ptr->hContact,msg); HistoryLog(ptr->hContact,msg); @@ -60,9 +60,9 @@ int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int #endif } else { - if ( k ) mir_snprintf(msg,MSGSIZE,Translate(sim522),cnm,sha,sha_old); + if (k ) mir_snprintf(msg,MSGSIZE,Translate(sim522),cnm,sha,sha_old); else mir_snprintf(msg,MSGSIZE,Translate(sim520),cnm,sha); - v = (msgbox(0,msg,MODULENAME,MB_YESNO|MB_ICONQUESTION)==IDYES); + v = (msgbox(0,msg,MODULENAME,MB_YESNO|MB_ICONQUESTION) == IDYES); #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("rsa_check_pub: manual accepted %d",v); #endif @@ -85,20 +85,20 @@ int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int return v; } - -void __cdecl rsa_notify(HANDLE context, int state) { +void __cdecl rsa_notify(HANDLE context, int state) +{ pUinKey ptr = getUinCtx(context); if (!ptr) return; LPCSTR msg=NULL; -#if defined(_DEBUG) || defined(NETLIB_LOG) + Sent_NetLog("rsa_notify: 0x%x", state); -#endif - switch( state ) { - case 1: { + + switch( state) { + case 1: showPopUpEC(ptr->hContact); ShowStatusIconNotify(ptr->hContact); waitForExchange(ptr,2); // досылаем сообщения из очереди return; - } + case -1: // сессия разорвана по ошибке, неверный тип сообщения msg=sim501; break; case -2: // сессия разорвана по ошибке другой стороной @@ -109,11 +109,8 @@ void __cdecl rsa_notify(HANDLE context, int state) { msg=sim506; break; case -7: // таймаут установки соединения (10 секунд) msg=sim507; break; - case -8: { // сессия разорвана по причине "disabled" - msg=sim508; -// ptr->status=ptr->tstatus=STATUS_DISABLED; -// db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status); - } break; + case -8: // сессия разорвана по причине "disabled" + msg=sim508; break; case -0x10: // сессия разорвана по ошибке case -0x21: case -0x22: @@ -124,23 +121,25 @@ void __cdecl rsa_notify(HANDLE context, int state) { case -0x34: case -0x40: case -0x50: - case -0x60: { - char buf[1024]; - sprintf(buf,sim510,-state); - showPopUpDCmsg(ptr->hContact,buf); - ShowStatusIconNotify(ptr->hContact); - if (ptr->cntx) deleteRSAcntx(ptr); - waitForExchange(ptr,3); // досылаем нешифровано - return; - } + case -0x60: + { + char buf[1024]; + sprintf(buf,sim510,-state); + showPopUpDCmsg(ptr->hContact,buf); + ShowStatusIconNotify(ptr->hContact); + if (ptr->cntx) deleteRSAcntx(ptr); + waitForExchange(ptr,3); // досылаем нешифровано + } + return; + case -3: // соединение разорвано вручную - case -4: { // соединение разорвано вручную другой стороной + case -4: // соединение разорвано вручную другой стороной showPopUpDC(ptr->hContact); ShowStatusIconNotify(ptr->hContact); - if (ptr->cntx) deleteRSAcntx(ptr); + if (ptr->cntx) deleteRSAcntx(ptr); waitForExchange(ptr,3); // досылаем нешифровано return; - } + default: return; } @@ -150,9 +149,8 @@ void __cdecl rsa_notify(HANDLE context, int state) { waitForExchange(ptr,3); // досылаем нешифровано } - -unsigned __stdcall sttGenerateRSA( LPVOID param ) { - +void sttGenerateRSA(LPVOID) +{ char priv_key[4096]; int priv_len; char pub_key[4096]; int pub_len; @@ -174,49 +172,46 @@ unsigned __stdcall sttGenerateRSA( LPVOID param ) { cws.value.cpbVal = pub_len; CallService(MS_DB_CONTACT_WRITESETTING, 0, (LPARAM)&cws); - rsa_4096=1; - - return 0; + rsa_4096 = 1; } - // загружает паблик-ключ в RSA контекст -BYTE loadRSAkey(pUinKey ptr) { - if ( !ptr->keyLoaded ) { - DBVARIANT dbv; - dbv.type = DBVT_BLOB; - if ( DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0 ) { - ptr->keyLoaded = exp->rsa_set_pubkey(ptr->cntx,dbv.pbVal,dbv.cpbVal); -#if defined(_DEBUG) || defined(NETLIB_LOG) - Sent_NetLog("loadRSAkey %d", ptr->keyLoaded); -#endif - db_free(&dbv); - } - } - return ptr->keyLoaded; +BYTE loadRSAkey(pUinKey ptr) +{ + if (!ptr->keyLoaded) { + DBVARIANT dbv; + dbv.type = DBVT_BLOB; + if ( DBGetContactSetting(ptr->hContact,MODULENAME,"rsa_pub",&dbv) == 0) { + ptr->keyLoaded = exp->rsa_set_pubkey(ptr->cntx,dbv.pbVal,dbv.cpbVal); + Sent_NetLog("loadRSAkey %d", ptr->keyLoaded); + db_free(&dbv); + } + } + return ptr->keyLoaded; } // создает RSA контекст -void createRSAcntx(pUinKey ptr) { - if ( !ptr->cntx ) { +void createRSAcntx(pUinKey ptr) +{ + if (!ptr->cntx) { ptr->cntx = cpp_create_context(CPP_MODE_RSA); ptr->keyLoaded = 0; } } - // пересоздает RSA контекст -void resetRSAcntx(pUinKey ptr) { - if ( ptr->cntx ) { +void resetRSAcntx(pUinKey ptr) +{ + if (ptr->cntx) { cpp_delete_context(ptr->cntx); ptr->cntx = cpp_create_context(CPP_MODE_RSA); ptr->keyLoaded = 0; } } - // удаляет RSA контекст -void deleteRSAcntx(pUinKey ptr) { +void deleteRSAcntx(pUinKey ptr) +{ cpp_delete_context(ptr->cntx); ptr->cntx = 0; ptr->keyLoaded = 0; diff --git a/plugins/SecureIM/src/svcs_rsa.h b/plugins/SecureIM/src/svcs_rsa.h index 7535a61276..d054b48054 100644 --- a/plugins/SecureIM/src/svcs_rsa.h +++ b/plugins/SecureIM/src/svcs_rsa.h @@ -9,7 +9,7 @@ int __cdecl rsa_inject(HANDLE,LPCSTR); int __cdecl rsa_check_pub(HANDLE,PBYTE,int,PBYTE,int); void __cdecl rsa_notify(HANDLE,int); -unsigned __stdcall sttGenerateRSA(LPVOID); +void sttGenerateRSA(LPVOID); BYTE loadRSAkey(pUinKey); void createRSAcntx(pUinKey); void resetRSAcntx(pUinKey); diff --git a/plugins/SecureIM/src/svcs_srmm.cpp b/plugins/SecureIM/src/svcs_srmm.cpp index bfc3a3e371..bebe781c3f 100644 --- a/plugins/SecureIM/src/svcs_srmm.cpp +++ b/plugins/SecureIM/src/svcs_srmm.cpp @@ -12,14 +12,14 @@ int __cdecl onWindowEvent(WPARAM wParam, LPARAM lParam) int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; - if ( isProtoMetaContacts(hContact)) + if (isProtoMetaContacts(hContact)) hContact = getMostOnline(hContact); // возьмем тот, через который пойдет сообщение StatusIconClickData *sicd = (StatusIconClickData *)lParam; - if ( strcmp(sicd->szModule, MODULENAME) != 0 || !isSecureProtocol(hContact)) + if (strcmp(sicd->szModule, MODULENAME) != 0 || !isSecureProtocol(hContact)) return 0; // not our event - if ( !isContactPGP(hContact) && !isContactGPG(hContact) && !isChatRoom(hContact)) { + if (!isContactPGP(hContact) && !isContactGPG(hContact) && !isChatRoom(hContact)) { if (isContactSecured(hContact) & SECURED) Service_DisableIM(wParam,0); else -- cgit v1.2.3