int __cdecl Load(PLUGINLINK *link) { pluginLink = link; DisableThreadLibraryCalls(g_hInst); InitializeCriticalSection(&localQueueMutex); { char temp[MAX_PATH]; GetTempPath(sizeof(temp),temp); GetLongPathName(temp,TEMP,sizeof(TEMP)); TEMP_SIZE = strlen(TEMP); if(TEMP[TEMP_SIZE-1]=='\\') { TEMP_SIZE--; TEMP[TEMP_SIZE]='\0'; } } // get memoryManagerInterface address mir_getMMI( &mmi ); // check for support TrueColor Icons BOOL bIsComCtl6 = FALSE; HMODULE hComCtlDll = LoadLibrary("comctl32.dll"); if ( hComCtlDll ) { typedef HRESULT (CALLBACK *PFNDLLGETVERSION)(DLLVERSIONINFO*); PFNDLLGETVERSION pfnDllGetVersion = (PFNDLLGETVERSION) GetProcAddress(hComCtlDll,"DllGetVersion"); if ( pfnDllGetVersion ) { DLLVERSIONINFO dvi; memset(&dvi,0,sizeof(dvi)); dvi.cbSize = sizeof(dvi); HRESULT hRes = (*pfnDllGetVersion)( &dvi ); if ( SUCCEEDED(hRes) && dvi.dwMajorVersion >= 6 ) { bIsComCtl6 = TRUE; } } FreeLibrary(hComCtlDll); } if (bIsComCtl6) iBmpDepth = ILC_COLOR32 | ILC_MASK; // 32-bit images are supported else iBmpDepth = ILC_COLOR24 | ILC_MASK; // iBmpDepth = ILC_COLOR32 | ILC_MASK; char version[512]; CallService(MS_SYSTEM_GETVERSIONTEXT, sizeof(version), (LPARAM)&version); bCoreUnicode = strstr(version, "Unicode")!=0; iCoreVersion = CallService(MS_SYSTEM_GETVERSION,0,0); // load crypo++ dll if( !loadlib() ) { msgbox1(0,sim107,szModuleName,MB_OK|MB_ICONSTOP); return 1; } load_rtfconv(); // register plugin module PROTOCOLDESCRIPTOR pd; memset(&pd,0,sizeof(pd)); pd.cbSize = sizeof(pd); pd.szName = (char*)szModuleName; pd.type = PROTOTYPE_ENCRYPTION; CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd); // hook events AddHookFunction(ME_SYSTEM_MODULESLOADED, onModulesLoaded); AddHookFunction(ME_SYSTEM_OKTOEXIT, onSystemOKToExit); g_hEvent[0] = CreateHookableEvent(MODULENAME"/Disabled"); g_hEvent[1] = CreateHookableEvent(MODULENAME"/Established"); AddServiceFunction((LPCSTR)MODULENAME"/IsContactSecured",(MIRANDASERVICE)Service_IsContactSecured); AddServiceFunction((LPCSTR)MODULENAME"/SIM_EST",(MIRANDASERVICE)Service_CreateIM); AddServiceFunction((LPCSTR)MODULENAME"/SIM_DIS",(MIRANDASERVICE)Service_DisableIM); AddServiceFunction((LPCSTR)MODULENAME"/SIM_ST_DIS",(MIRANDASERVICE)Service_StatusDis); AddServiceFunction((LPCSTR)MODULENAME"/SIM_ST_ENA",(MIRANDASERVICE)Service_StatusEna); AddServiceFunction((LPCSTR)MODULENAME"/SIM_ST_TRY",(MIRANDASERVICE)Service_StatusTry); AddServiceFunction((LPCSTR)MODULENAME"/PGP_SET",(MIRANDASERVICE)Service_PGPsetKey); AddServiceFunction((LPCSTR)MODULENAME"/PGP_DEL",(MIRANDASERVICE)Service_PGPdelKey); AddServiceFunction((LPCSTR)MODULENAME"/GPG_SET",(MIRANDASERVICE)Service_GPGsetKey); AddServiceFunction((LPCSTR)MODULENAME"/GPG_DEL",(MIRANDASERVICE)Service_GPGdelKey); AddServiceFunction((LPCSTR)MODULENAME"/MODE_NAT",(MIRANDASERVICE)Service_ModeNative); AddServiceFunction((LPCSTR)MODULENAME"/MODE_PGP",(MIRANDASERVICE)Service_ModePGP); AddServiceFunction((LPCSTR)MODULENAME"/MODE_GPG",(MIRANDASERVICE)Service_ModeGPG); AddServiceFunction((LPCSTR)MODULENAME"/MODE_RSA",(MIRANDASERVICE)Service_ModeRSAAES); return 0; }
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<DBGetContactSettingWord(0,szModuleName,"ket",10)*10; i++) { Sleep( 100 ); if( ptr->waitForExchange != 1 ) break; } // for #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,szModuleName,MB_YESNO|MB_ICONQUESTION)==IDYES ) { EnterCriticalSection(&localQueueMutex); ptr->sendQueue = true; pWM ptrMessage = ptr->msgQueue; while( ptrMessage ) { #if defined(_DEBUG) || defined(NETLIB_LOG) 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); } ptr->waitForExchange = 0; 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); pWM tmp = ptrMessage; ptrMessage = ptrMessage->nextMessage; mir_free(tmp); } ptr->msgQueue = NULL; ptr->waitForExchange = 0; LeaveCriticalSection(&localQueueMutex); } else if( ptr->waitForExchange==0 ) { // очистить очередь EnterCriticalSection(&localQueueMutex); // we need to resend last send back message with new crypto Key pWM ptrMessage = ptr->msgQueue; while (ptrMessage) { mir_free(ptrMessage->Message); pWM tmp = ptrMessage; ptrMessage = ptrMessage->nextMessage; mir_free(tmp); } ptr->msgQueue = NULL; LeaveCriticalSection(&localQueueMutex); } return 0; }