Exemple #1
0
static CCard *GetCardInstance(const char *csReader, SCARDHANDLE hCard,
                              CContext *poContext, CPinpad *poPinpad,
                              const std::string &csPluginPath, CDynamicLib &oCardPluginLib)
{
    CCard * poCard = NULL;

    unsigned long ulErr = oCardPluginLib.Open(csPluginPath);
    if (ulErr != EIDMW_OK)
    {
        MWLOG(LEV_ERROR, MOD_CAL, L"Couldn't load card plugin \"%ls\", err = 0x%0x",
              utilStringWiden(csPluginPath).c_str(), ulErr);
    }
    else
    {
        GETCARDINSTANCE pGetCardInstance =
            (GETCARDINSTANCE) oCardPluginLib.GetAddress(csGetCardInstanceName);
        if (pGetCardInstance == NULL)
        {
            MWLOG(LEV_ERROR, MOD_CAL, L"Function \"GetCardInstance\" not found in \"%ls\"",
                  utilStringWiden(csPluginPath).c_str());
        }
        else
        {
            poCard = pGetCardInstance(PLUGIN_VERSION, csReader, hCard, poContext, poPinpad);
            if (poCard)
            {
                MWLOG(LEV_DEBUG, MOD_CAL, L"    CardFactory: using plugin \"%ls\"",
                      utilStringWiden(csPluginPath).c_str());
            }
        }
    }

    return poCard;
}
Exemple #2
0
	void SharedMem::Delete(int iSegmentID)
	{

		// delete the shared memory area
		// once all processes have detached from this segment

		int iAttachedProcs = getNAttached(iSegmentID);

		if (iAttachedProcs > -1)
		{

			MWLOG(LEV_DEBUG, MOD_DLG,
			      L"  SharedMem::Delete : request to delete memory segment with ID %d. N proc = %d",
			      iSegmentID, iAttachedProcs);

			// check that no process is attached to this segment
			if (iAttachedProcs == 0)
			{
				if (shmctl(iSegmentID, IPC_RMID, NULL) == 1)
				{
					MWLOG(LEV_ERROR, MOD_DLG,
					      L"  SharedMem::Delete shmctl: %s",
					      strerror(errno));
					throw CMWEXCEPTION(EIDMW_ERR_MEMORY);
				}
				MWLOG(LEV_DEBUG, MOD_DLG,
				      L"  SharedMem::Delete : deleted memory segment with ID %d",
				      iSegmentID);
			}
		}
	}
Exemple #3
0
CByteArray CPkiCard::VerifyAndSign(const tPrivKey & key, const tPin & Pin,
        unsigned long algo, const CByteArray & oData)
{
	CByteArray retBytes;
    try
    {
        retBytes = SignInternal(key, algo, oData, &Pin);				
    }
		catch(CMWException & e)
		{
			if ((unsigned)e.GetError() == EIDMW_ERR_PIN_BAD)
			{
				MWLOG(LEV_INFO, MOD_CAL, L"     Couldn't sign, asking PIN and trying again");
				// Bad PIN: show a dialog to ask the user to try again
				bool retry = AskPinRetry(PIN_OP_VERIFY,Pin, m_ulRemaining,&key);
				if(retry)
					retBytes = VerifyAndSign(key, Pin, algo, oData);	
				else
					throw e;
			}
			else if ((unsigned)e.GetError() == EIDMW_ERR_PIN_BLOCKED)
			{
				MWLOG(LEV_WARN, MOD_CAL, L"     PIN blocked");
				// PIN blocked: show a dialog to tell the user
				AskPinRetry(PIN_OP_VERIFY,Pin,0,&key);
				throw e;
			}
			else
				throw e;
		}				
	return retBytes;
}
/** Obtain the SIS-data via the plugin library
*/
CCard * SISPluginReadData(const char *csReader, SCARDHANDLE hCard,
	CContext *poContext, CPinpad *poPinpad,
	CDynamicLib &oCardPluginLib)
{
	CCard *poCard = NULL;

	if (!m_bPluginInfosOK)
		GetPluginInfos();

	for (size_t i = 0; poCard == NULL && i < PlugInCount(); i++)
	{
		if (!StartsWith(csReader, GetPlugInReader(i).c_str()))
			continue;

		std::string csPluginPath = GetPlugInPath(i);
		unsigned long ulErr = oCardPluginLib.Open(csPluginPath);
		if (ulErr != EIDMW_OK)
		{
			MWLOG(LEV_ERROR, MOD_CAL, L"Couldn't load SIS plugin \"%ls\", err = 0x%0x",
				utilStringWiden(csPluginPath).c_str(), ulErr);
			continue;
		}

		SISPLUGINREADCARD pSisPluginReadCard =
				(SISPLUGINREADCARD) oCardPluginLib.GetAddress("SISPluginReadCard");
		if (pSisPluginReadCard == NULL)
		{
			MWLOG(LEV_ERROR, MOD_CAL, L"Function \"SISPluginReadCard\" not found in \"%ls\"",
				utilStringWiden(csPluginPath).c_str(), ulErr);
			continue;
		}

		tPCSCfunctions xPCSCFunctions;
		GetPCSCFunctions(&poContext->m_oPCSC, &xPCSCFunctions);

		unsigned char tucData[500];
		SCARDHANDLE hCrd = hCard;
		long lErr = pSisPluginReadCard(SISPLUGIN_VERSION, &xPCSCFunctions,
			csReader, &hCrd, tucData, 0, NULL);
		hCard = (unsigned long) hCrd;

		if (lErr != 0)
		{
			MWLOG(LEV_ERROR, MOD_CAL, L"Function \"SISPluginReadCard\" in \"%ls\" returned 0x%0x (%d)",
				utilStringWiden(csPluginPath).c_str(), lErr, lErr);
			continue;
		}

		MWLOG(LEV_DEBUG, MOD_CAL, L"Using SIS plugin \"%ls\"",
			utilStringWiden(csPluginPath).c_str());
		poCard = new CSISCard(hCard, poContext, poPinpad, CByteArray(tucData, 404));

		break;
	}

	return poCard;;
}
Exemple #5
0
	void SharedMem::Detach(void *content)
	{
		MWLOG(LEV_DEBUG, MOD_DLG,
		      L"  SharedMem::Detach segment with ID %d", m_iShmid);

		if (shmdt(content) == -1)
		{
			MWLOG(LEV_ERROR, MOD_DLG,
			      L"  SharedMem::Detach shmdt: %s",
			      strerror(errno));
			throw CMWEXCEPTION(EIDMW_ERR_MEMORY);
		}
	}
Exemple #6
0
void CReader::Disconnect(tDisconnectMode disconnectMode)
{
	m_oPKCS15.Clear(NULL);

	if (m_poCard != NULL)
	{
		// Strange behaviour with Ctrl-C:
		// It's possible that this function is called multiple times. Normally,
		// this doesn't hurt except that after a Ctrl-C, m_poCard->Disconnect()
		// throws us out of this function WITHOUT an exception! So the m_poCard
		// is not deleted() and set to NULL allthough the next call to this function
		// it contains rubbisch => CRASH.
		// So we set m_poCard = NULL in advance, and only if an exception is thrown
		// we assign it the old value.
		CCard *poTemp = m_poCard;
		m_poCard = NULL;
		try {
			poTemp->Disconnect(disconnectMode);
			MWLOG(LEV_INFO, MOD_CAL, L" Disconnected from card in reader %ls",
				m_wsReader.c_str());
			delete poTemp;
		}
		catch(...) {
			m_poCard = poTemp;
		}
	}
}
Exemple #7
0
void CPkiCard::WriteUncachedFile(const std::string & csPath,
    unsigned long ulOffset, const CByteArray & oData)
{
    CAutoLock autolock(this);

    tFileInfo fileInfo = SelectFile(csPath, true);

    const unsigned char *pucData = oData.GetBytes();
    unsigned long ulDataLen = oData.Size();
    for (unsigned long i = 0; i < ulDataLen; i += MAX_APDU_WRITE_LEN)
    {
        unsigned long ulLen = ulDataLen - i;
		if (ulLen > MAX_APDU_WRITE_LEN)
            ulLen = MAX_APDU_WRITE_LEN;

        CByteArray oResp = UpdateBinary(ulOffset + i, CByteArray(pucData + i, ulLen));
		unsigned long ulSW12 = getSW12(oResp);
		if (ulSW12 == 0x6982)
			throw CNotAuthenticatedException(
				EIDMW_ERR_NOT_AUTHENTICATED, fileInfo.lWritePINRef);
		else if (ulSW12 != 0x9000)
			throw CMWEXCEPTION(m_poContext->m_oPCSC.SW12ToErr(ulSW12));
    }

	MWLOG(LEV_INFO, MOD_CAL, L"Written file %ls to card", utilStringWiden(csPath).c_str());

}
CSocketServer::CSocketServer(int port, int connections, e_socketType type) throw(CMWException)
: CSocket()
{
	sockaddr_in address;
	memset(&address, 0, sizeof(address));

	address.sin_family = PF_INET;
	address.sin_port = htons(port);
	m_socket = socket(AF_INET, SOCK_STREAM, 0);
	if (m_socket == INVALID_SOCKET)
	  {
	    MWLOG(LEV_ERROR, MOD_CAL, L"  CSocketServer: can't open a socket on port %s ", port);
	    throw CMWEXCEPTION(EIDMW_ERR_SOCKET_SOCKET);
	  }

	if (type == NonBlockingSocket)
	  {
	    // enable non-blocking mode
	    unsigned long arg = 1;
#ifdef WIN32
	    ioctlsocket(m_socket, FIONBIO, &arg);
#else
	    if(ioctl(m_socket, FIONBIO, &arg) != 0)
		{
			MWLOG(LEV_ERROR,MOD_CAL,L"  CSocketServer: ioctl failed, %s",strerror(errno));
			throw CMWEXCEPTION(EIDMW_ERR_SOCKET_SOCKET);
	    }
#endif
	  }

	if (bind(m_socket, (sockaddr *)&address, sizeof(sockaddr_in) ) == SOCKET_ERROR)
	{
#ifdef WIN32
		closesocket(m_socket);
#else
		close(m_socket);
#endif
		MWLOG(LEV_ERROR, MOD_CAL, L"  CSocketServer: error in binding socket at port %d ", port);
		throw CMWEXCEPTION(EIDMW_ERR_SOCKET_BIND);
	}

	listen(m_socket, connections == 0 ? SOMAXCONN : connections);
}
Exemple #9
0
static CCard *ConnectGetCardInstance(const char *csReader,
                                     CContext *poContext, CPinpad *poPinpad,
                                     const std::string &csPluginPath, CDynamicLib &oCardPluginLib)
{
    CCard * poCard = NULL;

    try
    {
        unsigned long ulErr = oCardPluginLib.Open(csPluginPath);
        if (ulErr != EIDMW_OK)
        {
            MWLOG(LEV_ERROR, MOD_CAL, L"Couldn't load reader specific plugin \"%ls\", err = 0x%0x",
                  utilStringWiden(csPluginPath).c_str(), ulErr);
        }
        else
        {
            CONNECTGETCARDINSTANCE pConnectGetCardInstance =
                (CONNECTGETCARDINSTANCE) oCardPluginLib.GetAddress(csConnectGetCardInstanceName);
            if (pConnectGetCardInstance == NULL)
            {
                MWLOG(LEV_ERROR, MOD_CAL, L"Function \"ConnectGetCardInstance\" not found in \"%ls\"",
                      utilStringWiden(csPluginPath).c_str());
            }
            else
                poCard = pConnectGetCardInstance(PLUGIN_VERSION, csReader, poContext, poPinpad);
            if (poCard)
            {
                MWLOG(LEV_DEBUG, MOD_CAL, L"    CardFactory: connected via plugin \"%ls\"",
                      utilStringWiden(csPluginPath).c_str());
            }
        }
    }
    catch(CMWException &e)
    {
        MWLOG(LEV_ERROR, MOD_CAL, L"Exception in ConnectGetCardInstance(): err = 0x%0x\n", e.GetError());
    }
    catch (...)
    {
        MWLOG(LEV_ERROR, MOD_CAL, L"Unknown error in ConnectGetCardInstance()");
    }

    return poCard;
}
Exemple #10
0
CByteArray CPkiCard::Sign(const tPrivKey & key, const tPin & Pin,
        unsigned long algo, const CByteArray & oData)
{
	// If SSO (Single Sign-On) is false and we didn't verify the
	// PIN yet, then we do this first without trying if it's
	// realy needed.
	if (!m_poContext->m_bSSO)
	{
		bool bFound = false;
		for (size_t i = 0; i < m_verifiedPINs.size() && !bFound; i++)
			bFound = (m_verifiedPINs[i] == Pin.ulID);

		if (!bFound)
		{
			MWLOG(LEV_INFO, MOD_CAL, L"     No SSO: ask PIN and sign (key: ID=0x%0x, algo=0x%0x, "
				L"%d bytes input)", key.ulID, algo, oData.Size());
			return SignInternal(key, algo, oData, &Pin);
		}
	}

	// First try to sign.
    // If this returns a "Security conditions not satisfied"
    // then first do a Pin verify and then try again
	MWLOG(LEV_INFO, MOD_CAL, L"     Trying to Sign (key: ID=0x%0x, algo=0x%0x, "
		L"%d bytes input)", key.ulID, algo, oData.Size());
    try
    {
        return SignInternal(key, algo, oData);
    }
    catch(CMWException & e)
    {
      if ((unsigned)e.GetError() == EIDMW_ERR_NOT_AUTHENTICATED)
        {
					MWLOG(LEV_INFO, MOD_CAL, L"     Couldn't sign, asking PIN and trying again");
					return VerifyAndSign(key, Pin, algo, oData);	
        }
        else
            throw e;
    }
}
Exemple #11
0
	int SharedMem::getNAttached(int iSegmentID)
	{
		shmid_ds tResult;

		if (shmctl(iSegmentID, IPC_STAT, &tResult) == -1)
		{
			MWLOG(LEV_DEBUG, MOD_DLG,
			      L"  SharedMem::getNAttached shmctl: %s",
			      strerror(errno));
			return -1;
		}
		return tResult.shm_nattch;
	}
Exemple #12
0
	void SharedMem::Attach(size_t tMemorySize,
			       const char *csReadableFilePath, void **content)
	{
		m_csFilename = csReadableFilePath;

		// create a key on the base of the file name passed
		m_tKey = ftok(csReadableFilePath, 0666 | IPC_CREAT);
		if (m_tKey == (key_t) - 1)
		{
			MWLOG(LEV_ERROR, MOD_DLG,
			      L"  SharedMem::Attach ftok: %s",
			      strerror(errno));
			throw CMWEXCEPTION(EIDMW_ERR_MEMORY);
		}
		// create the memory segment and get its ID
		m_iShmid = shmget(m_tKey, tMemorySize, 0666 | IPC_CREAT);
		if (m_iShmid == -1)
		{
			MWLOG(LEV_ERROR, MOD_DLG,
			      L"  SharedMem::Attach shmid: %s",
			      strerror(errno));
			throw CMWEXCEPTION(EIDMW_ERR_MEMORY);
		}
		// attach the pointer
		if ((*content =
		     (void *) shmat(m_iShmid, 0, 0)) == (void *) -1)
		{
			MWLOG(LEV_ERROR, MOD_DLG,
			      L"  SharedMem::Attach shmat: %s",
			      strerror(errno));
			throw CMWEXCEPTION(EIDMW_ERR_MEMORY);
		}

		MWLOG(LEV_DEBUG, MOD_DLG,
		      L"  SharedMem::Attach attached segment with ID %d",
		      m_iShmid);
	}
Exemple #13
0
unsigned long CReader::SetEventCallback(
	void (* callback)(long lRet, unsigned long ulState, void *pvRef), void *pvRef)
{
	unsigned long ulHandle;
	CEventCallbackThread & oEventCallbackTread =
		m_poContext->m_oThreadPool.NewThread(&m_poContext->m_oPCSC,
			m_csReader, callback, ulHandle, pvRef);

	// Start the thread
	oEventCallbackTread.Start();

	MWLOG(LEV_INFO, MOD_CAL, L"    Started event callback thread %d", ulHandle);

	return ulHandle;
}
Exemple #14
0
bool CReader::Connect()
{
	if (m_poCard != NULL)
		Disconnect(DISCONNECT_LEAVE_CARD);

	m_poCard = CardConnect(m_csReader, m_poContext, NULL, m_oCardPluginLib);
	if (m_poCard != NULL)
	{
		m_oPKCS15.SetCard(m_poCard);
		if (m_oPinpad->UsePinpad())
		{
			MWLOG(LEV_DEBUG, MOD_CAL, L"Using Pinpad reader.");
			m_poCard->setPinpadHandler(m_oPinpad->getPinpadHandler(m_poCard->m_hCard));

		}
		else
			MWLOG(LEV_DEBUG, MOD_CAL, L"Using non-pinpad reader.");

		MWLOG(LEV_INFO, MOD_CAL, L" Connected to %ls card in reader %ls",
				Type2String(m_poCard->GetType()), m_wsReader.c_str());
	}

	return m_poCard != NULL;
}
void APL_CryptoFwk::resetProxy()
{
	APL_Config conf_pac(CConfig::EIDMW_CONFIG_PARAM_PROXY_PACFILE);     
	m_proxy_pac = conf_pac.getString();

	APL_Config conf_host(CConfig::EIDMW_CONFIG_PARAM_PROXY_HOST);     
	m_proxy_host = conf_host.getString();

	APL_Config conf_port(CConfig::EIDMW_CONFIG_PARAM_PROXY_PORT); 
	char buffer[10];
	sprintf_s(buffer,sizeof(buffer),"%ld",conf_port.getLong());
	m_proxy_port = buffer;

	MWLOG(LEV_INFO, MOD_SSL, L"Proxy settings: pac='%ls', host='%ls' and port=%ls",utilStringWiden(m_proxy_pac).c_str(),utilStringWiden(m_proxy_host).c_str(),utilStringWiden(m_proxy_port).c_str());
}
Exemple #16
0
tHashAlgo GetHashAlgo(ALG_ID Algid)
{
	switch (Algid)
	{
	case CALG_MD5:
		return ALGO_MD5;
	case CALG_SHA1:
		return ALGO_SHA1;
	case CALG_SHA_256:
		return ALGO_SHA256;
	case CALG_SSL3_SHAMD5:
		return ALGO_MD5_SHA1;
	default:
		MWLOG(LEV_INFO, MOD_CSP, L"  Hash algo: unknown (returning an error)");
		throw CMWEXCEPTION(EIDMW_ERR_PARAM_BAD);
	}
}
Exemple #17
0
unsigned long GetSignAlgo(ALG_ID Algid)
{
	switch (Algid)
	{
	case CALG_MD5:
		return SIGN_ALGO_MD5_RSA_PKCS;
	case CALG_SHA1:
		return SIGN_ALGO_SHA1_RSA_PKCS;
	case CALG_SHA_256:
		return SIGN_ALGO_SHA256_RSA_PKCS;
	case CALG_SSL3_SHAMD5:
		return SIGN_ALGO_RSA_PKCS;
	default:
		MWLOG(LEV_INFO, MOD_CSP, L"  Hash algo: unknown (returning an error)");
		throw CMWEXCEPTION(EIDMW_ERR_PARAM_BAD);
	}
}
Exemple #18
0
CByteArray CPkiCard::ReadUncachedFile(const std::string & csPath,
    unsigned long ulOffset, unsigned long ulMaxLen)
{
    CByteArray oData(ulMaxLen);

	CAutoLock autolock(this);

    tFileInfo fileInfo = SelectFile(csPath, true);

    // Loop until we've read ulMaxLen bytes or until EOF (End Of File)
    bool bEOF = false;
    for (unsigned long i = 0; i < ulMaxLen && !bEOF; i += MAX_APDU_READ_LEN)
    {
        unsigned long ulLen = ulMaxLen - i <= MAX_APDU_READ_LEN ?
            ulMaxLen - i : MAX_APDU_READ_LEN;

        CByteArray oResp = ReadBinary(ulOffset + i, ulLen);

        unsigned long ulSW12 = getSW12(oResp);
		// If the file is a multiple of the block read size, you will get
		// an SW12 = 6B00 (at least with BE eID) but that OK then..
        if (ulSW12 == 0x9000 || (i != 0 && ulSW12 == 0x6B00))
            oData.Append(oResp.GetBytes(), oResp.Size() - 2);
		else if (ulSW12 == 0x6982) {
			throw CNotAuthenticatedException(
				EIDMW_ERR_NOT_AUTHENTICATED, fileInfo.lReadPINRef);
		}
		else if (ulSW12 == 0x6B00)
			throw CMWEXCEPTION(EIDMW_ERR_PARAM_RANGE);
		else if (ulSW12 == 0x6D00)
			throw CMWEXCEPTION(EIDMW_ERR_NOT_ACTIVATED);
		else
            throw CMWEXCEPTION(m_poContext->m_oPCSC.SW12ToErr(ulSW12));

        // If the driver/reader itself did the 6CXX handling,
        // we assume we're at the EOF
        if (oResp.Size() < MAX_APDU_READ_LEN)
            bEOF = true;
    }

	MWLOG(LEV_INFO, MOD_CAL, L"   Read file %ls (%d bytes) from card",
		utilStringWiden(csPath).c_str(), oData.Size());

    return oData;
}
Exemple #19
0
tCardStatus CReader::Status(bool bReconnect)
{
	tCardStatus status;
	static int iStatusCount = 0;

	if (m_poCard == NULL)
	{
		if (m_poContext->m_oPCSC.Status(m_csReader)){
			status = Connect() ? CARD_INSERTED : CARD_NOT_PRESENT;
		}
		else
			status = CARD_NOT_PRESENT;
	}
	else
	{
		bool bCardStillPresent = m_poCard->Status();
		if (bCardStillPresent){
			status = CARD_STILL_PRESENT;
		}else
		{	
			Disconnect();
			// if bReconnect = true, then we try to connect to a
			// possibly new card that has been inserted
			if (bReconnect && m_poContext->m_oPCSC.Status(m_csReader))
				status = Connect() ? CARD_OTHER : CARD_REMOVED;
			else
				status = CARD_REMOVED;
		}
	}

	if (iStatusCount < 5)
	{
		MWLOG(LEV_DEBUG, MOD_CAL, L"    ReaderStatus(): %ls", Status2String(status));
		iStatusCount++;
	}

	return status;
}
Exemple #20
0
LRESULT dlgWndPinpadInfo::ProcecEvent(	UINT		uMsg,			// Message For This Window
									WPARAM		wParam,			// Additional Message Information
									LPARAM		lParam )		// Additional Message Information
{
	PAINTSTRUCT ps;
	RECT rect;

	switch( uMsg )
	{

	case WM_PAINT:
		{
			m_hDC = BeginPaint( m_hWnd, &ps );

			HDC hdcMem;

			hdcMem = CreateCompatibleDC( m_hDC );

			HGDIOBJ oldObj = SelectObject( hdcMem , ImagePIN );

			GetClientRect( m_hWnd, &rect );
			//Size of the background Image
			MaskBlt( m_hDC, 4, 8,
				410, 261,	hdcMem, 0, 0,
				ImagePIN_Mask, 0, 0, MAKEROP4( SRCCOPY, 0x00AA0029 ) );
		
			
			SelectObject( hdcMem, oldObj );
			DeleteDC(hdcMem);

			GetClientRect( m_hWnd, &rect );
			rect.left += IMG_SIZE + 100;
			rect.top = 32;
			rect.right -= 8;
			rect.bottom = 136 - 8;
			SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
			SelectObject( m_hDC, TextFont );
			DrawText( m_hDC, m_szHeader, -1, &rect, DT_WORDBREAK );

			//Change top header dimensions
			GetClientRect( m_hWnd, &rect );
			rect.left += IMG_SIZE + 100;
			rect.top = 60;
			rect.right -= 20;
			rect.bottom = rect.bottom - 60;
			SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
			SelectObject( m_hDC, TextFont );
			DrawText( m_hDC, m_szMessage, -1, &rect, DT_WORDBREAK );

			EndPaint( m_hWnd, &ps );

			SetForegroundWindow( m_hWnd );

			return 0;

/*
			m_hDC = BeginPaint( m_hWnd, &ps );

			HDC hdcMem;

			GetClientRect( m_hWnd, &rect );
			rect.bottom = rect.top + IMG_SIZE + 8;//rect.bottom / 2;
			FillRect( m_hDC, &rect, CreateSolidBrush( RGB(255, 255, 255) ) );

			hdcMem = CreateCompatibleDC( m_hDC );
			SelectObject( hdcMem , ImagePIN );
			BitBlt( m_hDC, 4, 4, IMG_SIZE, IMG_SIZE, hdcMem,
				0, 0, SRCCOPY );

			DeleteDC(hdcMem);

			rect.left += 136;
			rect.top += 32;
			rect.right -= 8;
			rect.bottom = 136 - 8;
			//SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
			DrawText( m_hDC, m_szHeader, -1, &rect, DT_WORDBREAK );

			GetClientRect( m_hWnd, &rect );
			rect.top=rect.top + IMG_SIZE + 8;

			rect.top = rect.top + 8;
			rect.bottom = rect.bottom - 8;
			rect.left = rect.left + 8;
			rect.right = rect.right - 8;
			FillRect( m_hDC, &rect, CreateSolidBrush( RGB(255, 255, 255) ) );

			rect.top = rect.top + 8;
			rect.bottom = rect.bottom - 8;
			rect.left = rect.left + 8;
			rect.right = rect.right - 8;
			DrawText( m_hDC, m_szMessage, -1, &rect, DT_WORDBREAK );

			EndPaint( m_hWnd, &ps );

			SetForegroundWindow( m_hWnd );

			return 0;
			*/
		}

		case WM_CREATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndPinpadInfo::ProcecEvent WM_CLOSE (wParam=%X, lParam=%X)",wParam,lParam);

			HMENU hSysMenu;

			hSysMenu = GetSystemMenu( m_hWnd, FALSE);
			EnableMenuItem( hSysMenu, 2, MF_BYPOSITION | MF_GRAYED );

			return 1;
		}

		case WM_CLOSE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndPinpadInfo::ProcecEvent WM_CLOSE (wParam=%X, lParam=%X)",wParam,lParam);

			if( m_ulHandle )
			{
				unsigned long tmp = m_ulHandle;
				m_ulHandle = 0;
				DlgClosePinpadInfo( tmp );
			}
			return  0;
		}

		case WM_DESTROY: 
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndModal::ProcecEvent WM_DESTROY (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		default:
		{
			return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
		}
	}
	return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
}
Exemple #21
0
CByteArray CPkiCard::MakePinBuf(const tPin & Pin, const std::string & csPin,
	bool bEmptyPin)
{
    CByteArray oBuf(16);
    unsigned long i;

	unsigned long ulPinLen = bEmptyPin ? 0 : (unsigned long) csPin.size();

	if (!bEmptyPin)
	{
		// Test if it's a valid PIN value
		if (Pin.ulMinLen != 0 && ulPinLen < Pin.ulMinLen)
		{
			MWLOG(LEV_WARN, MOD_CAL, L"PIN length is %d, should be at least %d", ulPinLen, Pin.ulMinLen);
			throw CMWEXCEPTION(EIDMW_ERR_PIN_FORMAT);
		}
		if (Pin.ulMaxLen != 0 && ulPinLen > Pin.ulMaxLen)
		{
			MWLOG(LEV_WARN, MOD_CAL, L"PIN length is %d, should be at most %d", ulPinLen, Pin.ulMaxLen);
			throw CMWEXCEPTION(EIDMW_ERR_PIN_FORMAT);
		}
	}

	for (i = 0; i < ulPinLen; i++)
    {
        if (!IsDigit(csPin[i]))
        {
            MWLOG(LEV_WARN, MOD_CAL, L"The PIN contains non-digit values");
            throw CMWEXCEPTION(EIDMW_ERR_PIN_FORMAT);
        }
    }

    switch(Pin.encoding)
    {
    case PIN_ENC_ASCII:
        for (i = 0; i < ulPinLen; i++)
            oBuf.Append((unsigned char) csPin[i]);
        for ( ; i < Pin.ulStoredLen; i++)
            oBuf.Append(Pin.ucPadChar);
        break;
    case PIN_ENC_GP:
        oBuf.Append((unsigned char) (0x20 + ulPinLen));
        // no break here
    case PIN_ENC_BCD:
        i = 0;
        while (i < ulPinLen)
        {
            unsigned char uc = (unsigned char) (16 * (csPin[i] - '0'));
            i++;
            if (i < ulPinLen)
                uc += (unsigned char) (csPin[i] - '0');
            else
                uc += (unsigned char) (Pin.ucPadChar % 16);
            i++;
            oBuf.Append(uc);
        }
		while (oBuf.Size() < Pin.ulStoredLen)
            oBuf.Append((unsigned char)
                Pin.ucPadChar > 0x0F ? Pin.ucPadChar : Pin.ucPadChar % 16);
        break;
    default:
        throw CMWEXCEPTION(EIDMW_ERR_PARAM_BAD);
    }

    return oBuf;
}
Exemple #22
0
LRESULT Win32Dialog::ProcecEvent
			(	UINT		uMsg,			// Message For This Window
				WPARAM		wParam,			// Additional Message Information
				LPARAM		lParam )		// Additional Message Information
{
	if( m_hWnd == NULL )
		return 0;

	PAINTSTRUCT ps;
	RECT rect;

	switch( uMsg )
	{
		case WM_PAINT:
		{
			m_hDC = BeginPaint( m_hWnd, &ps );
				SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
				GetClientRect( m_hWnd, &rect );
				DrawText( m_hDC, L"Virtual Hello World!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
			EndPaint( m_hWnd, &ps );

			SetForegroundWindow( m_hWnd );

			return 0;
		}

		case WM_NCACTIVATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::ProcecEvent WM_NCACTIVATE (wParam=%X, lParam=%X)",wParam,lParam);
			
			if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			{
				ShowWindow( m_hWnd, SW_SHOW );
				SetFocus( m_hWnd );
				return 0;
			}
			break;
		}

		case WM_KILLFOCUS:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::ProcecEvent WM_KILLFOCUS (wParam=%X, lParam=%X)",wParam,lParam);

			if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			{
				if( GetParent((HWND)wParam ) != m_hWnd )
				{
					SetFocus( m_hWnd );
					return 0;
				}
			}
			break;
		}

		case WM_CREATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::ProcecEvent WM_CREATE (wParam=%X, lParam=%X)",wParam,lParam);

			HMENU hSysMenu;

			hSysMenu = GetSystemMenu( m_hWnd, FALSE);
			RemoveMenu( hSysMenu, 2, MF_BYPOSITION );
			return 0;
		}

		case WM_CLOSE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::ProcecEvent WM_CLOSE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
			if( m_ModalHold )
			{
				ShowWindow( m_hWnd, SW_MINIMIZE );
				return 0;
			}
		}

		case WM_DESTROY: 
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::ProcecEvent WM_DESTROY (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		default:
		{
			return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
		}
	}
	return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
}
	CrlMemoryCache()
	{
		MWLOG(LEV_INFO, MOD_SSL, L"Create CrlMemoryCache");
		m_CrlMemoryArray=new CrlMemoryElement[CRL_MEMORY_CACHE_SIZE];
	}
Exemple #24
0
bool Win32Dialog::CreateWnd( const wchar_t* title, int width, int height, int Icon, HWND Parent )
{
	if( m_hWnd )
		return false;

	MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::CreateWnd (Parent=%X)",Parent);

	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	RECT		DeskRect;

	WindowRect.left = (long)0;			// Set Left Value To 0
	WindowRect.right = (long)width;		// Set Right Value To Requested Width
	WindowRect.top = (long)0;			// Set Top Value To 0
	WindowRect.bottom = (long)height;	// Set Bottom Value To Requested Height
	GetClientRect( GetDesktopWindow(), &DeskRect );

	WNDCLASS	wc;						// Windows Class Structure
	HICON hIco;
	if( Icon == 0 )
		hIco = LoadIcon( NULL, IDI_WINLOGO );
	else
		hIco = LoadIcon( m_hInstance, MAKEINTRESOURCE(Icon) );

	wc.style			= CS_HREDRAW | CS_VREDRAW; // | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC)WndProc;							// WndProc Handles Messages
	wc.cbClsExtra		= 0;										// No Extra Window Data
	wc.cbWndExtra		= 0; //DLGWINDOWEXTRA;							// No Extra Window Data
	wc.hInstance		= m_hInstance;								// Set The Instance
	wc.hIcon			= hIco;			// Load The Default Icon
	wc.hCursor			= LoadCursor( NULL, IDC_ARROW );			// Load The Arrow Pointer
	wc.hbrBackground	= (HBRUSH)GetSysColorBrush( COLOR_3DFACE );	// What Color we want in our background
	wc.lpszMenuName		= NULL;										// We Don't Want A Menu
	wc.lpszClassName	= m_appName;								// Set The Class Name

	if( !RegisterClass( &wc ) )									// Attempt To Register The Window Class
	{
		unsigned long err = GetLastError();
		MWLOG(LEV_WARN, MOD_DLG, L"  --> Win32Dialog::CreateWnd - Failed To Register The Window Class - Error=%ld",err);
		return false;											// Return FALSE
	}

	dwStyle = WS_CAPTION | WS_VISIBLE |  WS_SYSMENU | WS_OVERLAPPED;
	dwExStyle = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_WINDOWEDGE | WS_EX_TOPMOST;
	if( m_ModalHold )
	{
		dwStyle |= WS_POPUP;
		dwExStyle |= WS_EX_DLGMODALFRAME;
	}

	AdjustWindowRectEx( &WindowRect, dwStyle, FALSE, dwExStyle );	// Adjust Window To True Requested Size

	Active_lpWnd = this;
	// Create The Window
	if( !( m_hWnd = Active_hWnd = CreateWindowEx(	dwExStyle,			// Extended Style For The Window
								m_appName,							// Class Name
								title,								// Window Title
								dwStyle,							// Defined Window Style
								DeskRect.right/2 - (WindowRect.right-WindowRect.left)/2,
								DeskRect.bottom/2 - (WindowRect.bottom-WindowRect.top)/2,
								//CW_USEDEFAULT, CW_USEDEFAULT,		// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								Parent,								// No Parent Window
								NULL,								// No Menu
								m_hInstance,							// Instance
								(LPVOID)Active_lpWnd)))								// Dont Pass Anything To WM_CREATE
	{
		unsigned long err = GetLastError();
		KillWindow( );								// Reset The Display
		MWLOG(LEV_WARN, MOD_DLG, L"  --> Win32Dialog::CreateWnd - Window Creation Error - Error=%ld",err);
		return false;								// Return FALSE
	}
	MWLOG(LEV_DEBUG, MOD_DLG, L"  --> Win32Dialog::CreateWnd - CreateWindowEx (m_hWnd=%X)",m_hWnd);

	WndMap.insert( TD_WNDPAIR( m_hWnd, this ) );

	return true;
}
	~CrlMemoryCache()
	{
		MWLOG(LEV_INFO, MOD_SSL, L"Delete CrlMemoryCache");
		delete[] m_CrlMemoryArray;
		MWLOG(LEV_INFO, MOD_SSL, L" ---> CrlMemoryCache deleted");
	}
LRESULT dlgWndAskPIN::ProcecEvent
			(	UINT		uMsg,			// Message For This Window
				WPARAM		wParam,			// Additional Message Information
				LPARAM		lParam )		// Additional Message Information
{
	PAINTSTRUCT ps;
	RECT rect;

	switch( uMsg )
	{ 
		case WM_COMMAND:
		{
			switch( LOWORD(wParam) )
			{
				case IDC_EDIT:
				{
					if( EN_CHANGE == HIWORD(wParam) )
					{
						long len = (long)SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_GETTEXTLENGTH, 0, 0 );
						EnableWindow( GetDlgItem( m_hWnd, IDOK ), ( (unsigned int)len >= m_ulPinMinLen ) );
					}
					return TRUE;
				}

				case IDB_OK:
					GetPinResult();
					dlgResult = eIDMW::DLG_OK;
					close();
					return TRUE;

				case IDB_CANCEL:
					dlgResult = eIDMW::DLG_CANCEL;
					close();
					return TRUE;

				default:
					unsigned short tmp = LOWORD(wParam);
					if( tmp >= IDB_KeypadStart && tmp < IDB_KeypadEnd ) // Keypad Buttons
					{
						wchar_t nameBuf[128];
						SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_GETTEXT, (WPARAM)(sizeof(nameBuf)), (LPARAM)nameBuf );
						size_t iPos = wcslen( nameBuf );
						if( iPos >= m_ulPinMaxLen )
							return TRUE;
						if( tmp == IDB_KeypadEnd - 1 ) // Keypad Button 0
						{
							nameBuf[ iPos++ ] = L'0';
						}
						else // Keypad Button 1 to 9
						{
							nameBuf[ iPos++ ] = 49 + tmp - IDB_KeypadStart;
						}
						nameBuf[ iPos++ ] = NULL;
						SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_SETTEXT, 0, (LPARAM)nameBuf );
						return TRUE;
					}
					if( tmp == IDB_KeypadEnd ) // Keypad Button CE
					{
						SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_SETTEXT, 0, (LPARAM)"" );
						//clear
					}
					return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
			}
		}

		case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
			if( lpDrawItem->CtlType & ODT_BUTTON )
			{
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - WM_DRAWITEM lParam=%x, wParam=%ld",lParam,wParam);
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - Entering WM_DRAWITEM lpDrawItem->hDC=%ld",lpDrawItem->hDC);

				FillRect( lpDrawItem->hDC, &lpDrawItem->rcItem, CreateSolidBrush( GetSysColor( COLOR_3DFACE ) ) );
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - WM_DRAWITEM top=%ld, bottom=%ld, left=%ld, right=%ld",
					//lpDrawItem->rcItem.top,lpDrawItem->rcItem.bottom,lpDrawItem->rcItem.left,lpDrawItem->rcItem.right);

				HDC hdcMem = CreateCompatibleDC( lpDrawItem->hDC );
				SelectObject( hdcMem , ImageKP_BTN[11] );
				MaskBlt( lpDrawItem->hDC, (lpDrawItem->rcItem.right - KP_BTN_SIZE) / 2, (lpDrawItem->rcItem.bottom - KP_BTN_SIZE) / 2,
					KP_BTN_SIZE, KP_BTN_SIZE, hdcMem, 0, 0,
					ImageKP_BTN_Mask, 0, 0, MAKEROP4( SRCCOPY, 0x00AA0029 ) );

				unsigned int iNum = 0;
				if( lpDrawItem->CtlID == IDB_KeypadEnd )
				{
					iNum = 10;
				}
				else if( lpDrawItem->CtlID >= IDB_KeypadStart && lpDrawItem->CtlID < IDB_KeypadEnd -2 )
				{
					iNum = lpDrawItem->CtlID - IDB_KeypadStart +1;
				}
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - WM_DRAWITEM iNum=%ld",iNum);

				SelectObject( hdcMem , ImageKP_BTN[iNum] );
				BitBlt( lpDrawItem->hDC, (lpDrawItem->rcItem.right - KP_LBL_SIZE) / 2, (lpDrawItem->rcItem.bottom - KP_LBL_SIZE) / 2, 
						KP_LBL_SIZE, KP_LBL_SIZE, hdcMem, 0, 0, SRCCOPY );
				DeleteDC(hdcMem);

				if( lpDrawItem->itemState & ODS_SELECTED )
					DrawEdge( lpDrawItem->hDC, &lpDrawItem->rcItem, EDGE_RAISED, BF_RECT );
				
				if( lpDrawItem->itemState & ODS_HOTLIGHT )
					DrawEdge( lpDrawItem->hDC, &lpDrawItem->rcItem, EDGE_SUNKEN, BF_RECT );
				
				if( lpDrawItem->itemState & ODS_FOCUS )
				{
					GetClientRect( lpDrawItem->hwndItem, &rect );
					rect.left += 2;
					rect.right -= 2;
					rect.top += 2;
					rect.bottom -= 2;
					DrawFocusRect( lpDrawItem->hDC, &rect );
				}
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - Leaving WM_DRAWITEM lpDrawItem->hDC=%ld",lpDrawItem->hDC);
				return TRUE;
			}
			break;
		}

		case WM_SIZE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_SIZE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return 0;
			break;
		}

		case WM_PAINT:
		{
			//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : WM_PAINT");
			m_hDC = BeginPaint( m_hWnd, &ps );

			HDC hdcMem;

			hdcMem = CreateCompatibleDC( m_hDC );

			HGDIOBJ oldObj = SelectObject( hdcMem , ImagePIN );

			GetClientRect( m_hWnd, &rect );
			MaskBlt( m_hDC, 4, m_KeypadHeight + 8,
				IMG_SIZE, IMG_SIZE,	hdcMem, 0, 0,
				ImagePIN_Mask, 0, 0, MAKEROP4( SRCCOPY, 0x00AA0029 ) );
		
			
			SelectObject( hdcMem, oldObj );
			DeleteDC(hdcMem);

			if( m_UseKeypad )
			{
				GetClientRect( m_hWnd, &rect );
				rect.left += 8;
				rect.right -= 8;
				rect.top += 8;
				rect.bottom = m_KeypadHeight;

				DrawEdge( m_hDC, &rect, EDGE_RAISED, BF_RECT );
			}

			GetClientRect( m_hWnd, &rect );
			rect.left += IMG_SIZE + 16;
			rect.top = m_KeypadHeight + 8;
			rect.right -= 8;
			rect.bottom = rect.bottom - 40;
			SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
			SelectObject( m_hDC, TextFont );
			DrawText( m_hDC, szHeader, -1, &rect, DT_WORDBREAK );

			EndPaint( m_hWnd, &ps );

			SetForegroundWindow( m_hWnd );

			return 0;
		}

		case WM_ACTIVATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_ACTIVATE (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		case WM_NCACTIVATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_NCACTIVATE (wParam=%X, lParam=%X)",wParam,lParam);

			//if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			//{
			//	ShowWindow( m_hWnd, SW_SHOW );
			//	SetFocus( m_hWnd );
			//	return 0;
			//}
			if(!wParam)
			{
				SetFocus( m_hWnd );
				return 0;
			}
			break;
		}

		case WM_SETFOCUS:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_SETFOCUS (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		case WM_KILLFOCUS:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_KILLFOCUS (wParam=%X, lParam=%X)",wParam,lParam);

			//if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			//{
			//	if( GetParent((HWND)wParam ) != m_hWnd )
			//	{
			//		SetFocus( m_hWnd );
			//		return 0;
			//	}
			//}
			break;
		}

		case WM_CREATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_CREATE (wParam=%X, lParam=%X)",wParam,lParam);

			HMENU hSysMenu;

			hSysMenu = GetSystemMenu( m_hWnd, FALSE );
			EnableMenuItem( hSysMenu, 3, MF_BYPOSITION | MF_GRAYED );
			SendMessage( m_hWnd, DM_SETDEFID, (WPARAM) IDC_EDIT, (LPARAM) 0); 

			return DefWindowProc( (HWND)((CREATESTRUCT *)lParam)->lpCreateParams, uMsg, wParam, lParam );
		}

		case WM_CLOSE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_CLOSE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return DefWindowProc( m_hWnd, uMsg, wParam, lParam );

			ShowWindow( m_hWnd, SW_MINIMIZE );
			return 0;
		}

		case WM_DESTROY: 
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_DESTROY (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		default:
		{
			return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
		}
	}
	return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
}
Exemple #27
0
void CReader::StopEventCallback(unsigned long ulHandle)
{
	m_poContext->m_oThreadPool.RemoveThread(ulHandle);
	MWLOG(LEV_INFO, MOD_CAL, L"    Stopped event callback thread %d", ulHandle);
}
Exemple #28
0
LRESULT dlgWndBadPIN::ProcecEvent
			(	UINT		uMsg,			// Message For This Window
				WPARAM		wParam,			// Additional Message Information
				LPARAM		lParam )		// Additional Message Information
{
	PAINTSTRUCT ps;
	RECT rect;

	switch( uMsg )
	{
		case WM_COMMAND:
		{
			switch( LOWORD(wParam) )
			{

				case IDB_OK:
					dlgResult = eIDMW::DLG_OK;
					close();
					return TRUE;

				case IDB_CANCEL:
					dlgResult = eIDMW::DLG_CANCEL;
					close();
					return TRUE;

				case IDB_RETRY:
					dlgResult = eIDMW::DLG_RETRY;
					close();
					return TRUE;

				default:
					return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
			}
		}


		case WM_SIZE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndBadPIN::ProcecEvent WM_SIZE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return 0;
			break;
		}

		case WM_PAINT:
		{
			m_hDC = BeginPaint( m_hWnd, &ps );

				HDC hdcMem;

				hdcMem = CreateCompatibleDC( m_hDC );
				SelectObject( hdcMem , ImagePIN );

				MaskBlt( m_hDC, 4, 4, IMG_SIZE, IMG_SIZE,
					hdcMem, 0, 0,
					ImagePIN_Mask, 0, 0,
					MAKEROP4( SRCCOPY, 0x00AA0029 ) );

				DeleteDC(hdcMem);

				GetClientRect( m_hWnd, &rect );
				rect.left += 136;
				rect.top += 32;
				rect.right -= 8;
				rect.bottom = 136 - 8;
				SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
				SelectObject( m_hDC, TextFont );
				DrawText( m_hDC, szHeader, -1, &rect, DT_WORDBREAK );

			EndPaint( m_hWnd, &ps );

			SetForegroundWindow( m_hWnd );

			return 0;
		}

		case WM_NCACTIVATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndBadPIN::ProcecEvent WM_NCACTIVATE (wParam=%X, lParam=%X)",wParam,lParam);

			if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			{
				ShowWindow( m_hWnd, SW_SHOW );
				SetFocus( m_hWnd );
				return 0;
			}
			break;
		}

		case WM_KILLFOCUS:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndBadPIN::ProcecEvent WM_KILLFOCUS (wParam=%X, lParam=%X)",wParam,lParam);

			if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			{
				if( GetParent((HWND)wParam ) != m_hWnd )
				{
					SetFocus( m_hWnd );
					return 0;
				}
			}
			break;
		}

		case WM_CREATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndBadPIN::ProcecEvent WM_CREATE (wParam=%X, lParam=%X)",wParam,lParam);

			HMENU hSysMenu;

			hSysMenu = GetSystemMenu( m_hWnd, FALSE );
			EnableMenuItem( hSysMenu, 2, MF_BYPOSITION | MF_GRAYED );

			return 1;
		}


		case WM_CLOSE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndBadPIN::ProcecEvent WM_CLOSE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return DefWindowProc( m_hWnd, uMsg, wParam, lParam );

			ShowWindow( m_hWnd, SW_MINIMIZE );
			return 0;
		}

		case WM_DESTROY: 
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndBadPIN::ProcecEvent WM_DESTROY (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		default:
		{
			return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
		}
	}
	return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
}
Exemple #29
0
tCardFileStatus APL_CardFile::LoadData(bool bForceReload)
{
	CAutoMutex autoMutex(&m_Mutex);		//We lock for only one instantiation

	std::wstring strPath = utilStringWiden(m_path);
	const wchar_t *wsPath= strPath.c_str();

	if(m_card!=NULL && (m_status==CARDFILESTATUS_UNREAD || bForceReload))
	{
		try
		{
			//Fill the m_data with the content of the file
			MWLOG(LEV_INFO, MOD_APL, L"LoadData: Ask for file %ls", wsPath);	//TODO replace by DEBUG
			ReadFile();
			MWLOG(LEV_INFO, MOD_APL, L"LoadData: Read file %ls ok", wsPath);	//TODO replace by DEBUG
		}
		catch(CMWException& e)
		{
			unsigned long err = e.GetError();
			if (err == EIDMW_ERR_FILE_NOT_FOUND)
			{
				MWLOG(LEV_INFO, MOD_APL, L"LoadData: File %ls not found", wsPath);
				m_status=CARDFILESTATUS_ERROR_NOFILE;
				return m_status;
			}

			if (err == EIDMW_ERR_CARD_COMM)
			{
				MWLOG(LEV_WARN, MOD_APL, L"LoadData: Could not read file : %ls - Error : 0x%x", wsPath,e.GetError());
				m_status=CARDFILESTATUS_ERROR_NOFILE;
				return m_status;
			}

			if (err == EIDMW_ERR_NOT_ACTIVATED)
			{
				MWLOG(LEV_WARN, MOD_APL, L"LoadData: Could not read file : %ls - Error : 0x%x", wsPath,e.GetError());
				m_status=CARDFILESTATUS_ERROR_NOFILE;
				return m_status;
			}

			MWLOG(LEV_ERROR, MOD_APL, L"LoadData: Could not read file : %ls - Error : 0x%x", wsPath,e.GetError());
			throw e;
		}
	}

	//Get the status
	//m_status=VerifyFile();
	m_status=CARDFILESTATUS_OK;

	//If Status ok, map the fields
	if(m_status==CARDFILESTATUS_OK)
		if(!MapFields())
			m_status=CARDFILESTATUS_ERROR_FORMAT;

	if(m_status!=CARDFILESTATUS_OK)
	{
		EmptyFields();
		if(!m_keepdata)
			m_data.ClearContents();
	}

	MWLOG(LEV_INFO, MOD_APL, L"LoadData: File : %ls - status : 0x%x", wsPath,m_status);

	return m_status;
}