diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-01 19:37:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-01 19:37:35 +0000 |
commit | 754c5e27f878dc4a46131593e00e78e054faa995 (patch) | |
tree | e49b137bf04d56c58c50f5fb1760a6cf84bca658 /plugins/SecureIM/src/crypt_misc.cpp | |
parent | 14ad5bd238bb3fb2edf8284a1c35f175e2f31d5f (diff) |
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
Diffstat (limited to 'plugins/SecureIM/src/crypt_misc.cpp')
-rw-r--r-- | plugins/SecureIM/src/crypt_misc.cpp | 140 |
1 files changed, 54 insertions, 86 deletions
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;i<db_get_w(0,MODULENAME,"ket",10)*10; i++) {
- Sleep( 100 );
- if ( ptr->waitForExchange != 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;
}
}
|