Пример #1
0
int __cdecl onContactSettingChanged(WPARAM wParam,LPARAM lParam) {

	HANDLE hContact = (HANDLE)wParam;
	DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;
	if (!hContact || strcmp(cws->szSetting,"Status")) return 0;

	pUinKey ptr = getUinKey(hContact);
	int stat = getContactStatus(hContact);
	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
			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) {
			deleteRSAcntx(ptr);
			showPopupDC(hContact);	// show popup "Disabled"
			ShowStatusIconNotify(hContact); // change icon in CL
		}
	}
	else { // go not offline
		if (ptr->offlineKey) {
			cpp_reset_context(ptr->cntx);
			ptr->offlineKey = false;
		}
		ShowStatusIconNotify(hContact); // change icon in CL
	}
	return 0;
}
Пример #2
0
INT_PTR __cdecl Service_Mode(WPARAM wParam, LPARAM lParam) {

    pUinKey ptr = getUinKey((HANDLE)wParam);

    switch(--lParam) {
    case MODE_NATIVE:
    case MODE_RSAAES:
        if( isContactSecured((HANDLE)wParam)&SECURED ) {
            msgbox(NULL, sim111, szModuleName, MB_OK);
            return 0;
        }
        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 ) {
                cpp_delete_context(ptr->cntx);
                ptr->cntx = 0;
                ptr->keyLoaded = 0;
            }
            ptr->mode=(BYTE)lParam;
            DBWriteContactSettingByte((HANDLE)wParam, szModuleName, "mode", (BYTE)lParam);
        }
        ShowStatusIcon((HANDLE)wParam);
        break;
    }

    return 1;
}
Пример #3
0
INT_PTR __cdecl Service_GPGdelKey(WPARAM wParam, LPARAM)
{
	if (bGPGloaded)
		db_unset(wParam, MODULENAME, "gpg");
	{
		pUinKey ptr = getUinKey(wParam);
		cpp_delete_context(ptr->cntx); ptr->cntx = 0;
	}
	ShowStatusIconNotify(wParam);
	return 1;
}
Пример #4
0
INT_PTR __cdecl Service_GPGdelKey(WPARAM wParam, LPARAM lParam) {

    if(bGPGloaded) {
        DBDeleteContactSetting((HANDLE)wParam, szModuleName, "gpg");
    }
    {
        pUinKey ptr = getUinKey((HANDLE)wParam);
        cpp_delete_context(ptr->cntx);
        ptr->cntx=0;
    }
    ShowStatusIconNotify((HANDLE)wParam);
    return 1;
}
Пример #5
0
INT_PTR __cdecl Service_PGPdelKey(WPARAM wParam, LPARAM)
{
	if (bPGPloaded) {
		db_unset(wParam, MODULENAME, "pgp");
		db_unset(wParam, MODULENAME, "pgp_mode");
		db_unset(wParam, MODULENAME, "pgp_abbr");
	}
	{
		pUinKey ptr = getUinKey(wParam);
		cpp_delete_context(ptr->cntx); ptr->cntx = 0;
	}
	ShowStatusIconNotify(wParam);
	return 1;
}
Пример #6
0
INT_PTR __cdecl Service_PGPsetKey(WPARAM wParam, LPARAM lParam) {

    BOOL del = true;
    if(bPGPloaded) {
        if(bPGPkeyrings) {
            char szKeyID[128];
            szKeyID[0]='\0';
            PVOID KeyID = pgp_select_keyid(GetForegroundWindow(),szKeyID);
            if(szKeyID[0]) {
                DBDeleteContactSetting((HANDLE)wParam,szModuleName,"pgp");
                DBCONTACTWRITESETTING cws;
                memset(&cws,0,sizeof(cws));
                cws.szModule = szModuleName;
                cws.szSetting = "pgp";
                cws.value.type = DBVT_BLOB;
                cws.value.pbVal = (LPBYTE)KeyID;
                cws.value.cpbVal = pgp_size_keyid();
                CallService(MS_DB_CONTACT_WRITESETTING,wParam,(LPARAM)&cws);
                DBWriteContactSettingByte((HANDLE)wParam,szModuleName,"pgp_mode",0);
                DBWriteContactSettingString((HANDLE)wParam,szModuleName,"pgp_abbr",szKeyID);
                del = false;
            }
        }
        else if(bPGPprivkey) {
            char KeyPath[MAX_PATH];
            KeyPath[0]='\0';
            if(ShowSelectKeyDlg(0,KeyPath)) {
                char *publ = LoadKeys(KeyPath,false);
                if(publ) {
                    DBDeleteContactSetting((HANDLE)wParam,szModuleName,"pgp");
                    myDBWriteStringEncode((HANDLE)wParam,szModuleName,"pgp",publ);
                    DBWriteContactSettingByte((HANDLE)wParam,szModuleName,"pgp_mode",1);
                    DBWriteContactSettingString((HANDLE)wParam,szModuleName,"pgp_abbr","(binary)");
                    mir_free(publ);
                    del = false;
                }
            }
        }
    }

    if(del) Service_PGPdelKey(wParam,lParam);
    else {
        pUinKey ptr = getUinKey((HANDLE)wParam);
        cpp_delete_context(ptr->cntx);
        ptr->cntx=0;
    }
    ShowStatusIconNotify((HANDLE)wParam);
    return 1;
}
Пример #7
0
INT_PTR __cdecl Service_Status(WPARAM wParam, LPARAM lParam) {

    switch(--lParam) {
    case STATUS_DISABLED:
    case STATUS_ENABLED:
    case STATUS_ALWAYSTRY:
        pUinKey ptr = getUinKey((HANDLE)wParam);
        if(ptr) {
            ptr->status=ptr->tstatus=(BYTE)lParam;
            if(ptr->status==STATUS_ENABLED)	DBDeleteContactSetting(ptr->hContact, szModuleName, "StatusID");
            else 				DBWriteContactSettingByte(ptr->hContact, szModuleName, "StatusID", ptr->status);
        }
        break;
    }

    return 1;
}
Пример #8
0
INT_PTR __cdecl Service_Status(WPARAM wParam, LPARAM lParam)
{
	switch (--lParam) {
	case STATUS_DISABLED:
	case STATUS_ENABLED:
	case STATUS_ALWAYSTRY:
		pUinKey ptr = getUinKey(wParam);
		if (ptr) {
			ptr->status = ptr->tstatus = (BYTE)lParam;
			if (ptr->status == STATUS_ENABLED)
				db_unset(ptr->hContact, MODULENAME, "StatusID");
			else
				db_set_b(ptr->hContact, MODULENAME, "StatusID", ptr->status);
		}
		break;
	}

	return 1;
}
Пример #9
0
INT_PTR __cdecl Service_GPGsetKey(WPARAM wParam, LPARAM lParam)
{
	bool del = true;
	if (bGPGloaded && bGPGkeyrings) {
		char szKeyID[128]; szKeyID[0] = '\0';
		gpg_select_keyid(GetForegroundWindow(), szKeyID);
		if (szKeyID[0]) {
			db_set_s(wParam, MODULENAME, "gpg", szKeyID);
			del = false;
		}
	}

	if (del)
		Service_GPGdelKey(wParam, lParam);
	else {
		pUinKey ptr = getUinKey(wParam);
		cpp_delete_context(ptr->cntx); ptr->cntx = 0;
	}
	ShowStatusIconNotify(wParam);
	return 1;
}
Пример #10
0
INT_PTR __cdecl Service_PGPsetKey(WPARAM wParam, LPARAM lParam)
{
	BOOL del = true;
	if (bPGPloaded) {
		if (bPGPkeyrings) {
			char szKeyID[128]; szKeyID[0] = '\0';
			PVOID KeyID = pgp_select_keyid(GetForegroundWindow(), szKeyID);
			if (szKeyID[0]) {
				db_unset(wParam, MODULENAME, "pgp");
				db_set_blob(wParam, MODULENAME, "pgp", KeyID, pgp_size_keyid());
				db_set_b(wParam, MODULENAME, "pgp_mode", 0);
				db_set_s(wParam, MODULENAME, "pgp_abbr", szKeyID);
				del = false;
			}
		}
		else if (bPGPprivkey) {
			char KeyPath[MAX_PATH]; KeyPath[0] = '\0';
			if (ShowSelectKeyDlg(0, KeyPath)) {
				char *publ = LoadKeys(KeyPath, false);
				if (publ) {
					db_unset(wParam, MODULENAME, "pgp");
					db_set_s(wParam, MODULENAME, "pgp", publ);
					db_set_b(wParam, MODULENAME, "pgp_mode", 1);
					db_set_s(wParam, MODULENAME, "pgp_abbr", "(binary)");
					mir_free(publ);
					del = false;
				}
			}
		}
	}

	if (del)
		Service_PGPdelKey(wParam, lParam);
	else {
		pUinKey ptr = getUinKey(wParam);
		cpp_delete_context(ptr->cntx); ptr->cntx = 0;
	}
	ShowStatusIconNotify(wParam);
	return 1;
}
Пример #11
0
INT_PTR __cdecl Service_GPGsetKey(WPARAM wParam, LPARAM lParam) {

    BOOL del = true;
    if(bGPGloaded && bGPGkeyrings) {
        char szKeyID[128];
        szKeyID[0]='\0';
        gpg_select_keyid(GetForegroundWindow(),szKeyID);
        if(szKeyID[0]) {
            DBWriteContactSettingString((HANDLE)wParam,szModuleName,"gpg",szKeyID);
            del = false;
        }
    }

    if(del) Service_GPGdelKey(wParam,lParam);
    else {
        pUinKey ptr = getUinKey((HANDLE)wParam);
        cpp_delete_context(ptr->cntx);
        ptr->cntx=0;
    }
    ShowStatusIconNotify((HANDLE)wParam);
    return 1;
}
Пример #12
0
int __cdecl onRebuildContactMenu(WPARAM wParam,LPARAM lParam)
{
	HANDLE hContact = (HANDLE)wParam;
	BOOL bMC = isProtoMetaContacts(hContact);
	if (bMC ) hContact = getMostOnline(hContact); // возьмем тот, через который пойдет сообщение
	pUinKey ptr = getUinKey(hContact);
	int i;
	CLISTMENUITEM mi = { sizeof(mi) };

	ShowStatusIconNotify(hContact);

	// check offline/online
	if (!ptr) {
		// hide menu bars
		for (i=0; i < SIZEOF(g_hMenu); i++)
			Menu_ShowItem(g_hMenu[i], false);
		return 0;
	}

	bool isSecureProto = isSecureProtocol(hContact);
	bool isPGP = isContactPGP(hContact);
	bool isGPG = isContactGPG(hContact);
	bool isSecured = (isContactSecured(hContact)&SECURED) != 0;
	bool isChat = isChatRoom(hContact);
	bool isMiranda = isClientMiranda(hContact);

	// hide all menu bars
	for (i=0; i < SIZEOF(g_hMenu); i++)
		Menu_ShowItem(g_hMenu[i], false);

	if (isSecureProto && !isChat && isMiranda && 
	    (ptr->mode == MODE_NATIVE || ptr->mode == MODE_RSAAES)) {
		// Native/RSAAES
		mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIM_ICON;
		if (!isSecured) {
			// create secureim connection
			mi.hIcon = mode2icon(ptr->mode|SECURED,2);
			Menu_ModifyItem(g_hMenu[0], &mi);
		}
		else {
			// disable secureim connection
			mi.hIcon = mode2icon(ptr->mode,2);
			Menu_ModifyItem(g_hMenu[1], &mi);
		}
		// set status menu
		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];
			mi.pszName = (LPSTR)sim312[ptr->status];
			Menu_ModifyItem(g_hMenu[2], &mi);

			mi.flags = CMIM_FLAGS | CMIM_ICON;
			for (i=0;i<=(ptr->mode == MODE_RSAAES?1:2);i++) {
				mi.hIcon = (i == ptr->status) ? g_hICO[ICO_ST_DIS+ptr->status] : NULL;
				Menu_ModifyItem(g_hMenu[3+i], &mi);
			}
		}
	}
	else if (isSecureProto && !isChat && (ptr->mode == MODE_PGP || ptr->mode == MODE_GPG)) {
		// PGP, GPG
		if (ptr->mode == MODE_PGP && bPGPloaded)
			if ((bPGPkeyrings || bPGPprivkey) && !isGPG)
				Menu_ShowItem(g_hMenu[isPGP+6], true);

		if (ptr->mode == MODE_GPG && bGPGloaded)
			if (bGPGkeyrings && !isPGP)
				Menu_ShowItem(g_hMenu[isGPG+8], true);
	}
	if (isSecureProto && !isChat && isMiranda) {
		// set mode menu
		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];
			mi.pszName = (LPSTR)sim311[ptr->mode];
			Menu_ModifyItem(g_hMenu[10], &mi);

			mi.flags = CMIM_FLAGS | CMIM_ICON;
			for (i=0;i<MODE_CNT;i++) {
				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;
				Menu_ModifyItem(g_hMenu[11+i], &mi);
			}
		}
	}

	return 0;
}
Пример #13
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;
}