mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-12-05 07:43:58 +08:00
Fixed #2006: Use InitOnceExecuteOnce
This commit is contained in:
parent
f7f52c4b67
commit
d03f9858af
@ -24,14 +24,33 @@
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/library.h>
|
||||
#include <winpr/smartcard.h>
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include "smartcard.h"
|
||||
|
||||
#include "smartcard_inspect.h"
|
||||
|
||||
static BOOL g_Initialized = FALSE;
|
||||
static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT;
|
||||
static PSCardApiFunctionTable g_SCardApi = NULL;
|
||||
|
||||
#define SCARDAPI_STUB_CALL_LONG(_name, ...) \
|
||||
InitOnceExecuteOnce(&g_Initialized, InitializeSCardApiStubs, NULL, NULL); \
|
||||
if (!g_SCardApi || !g_SCardApi->pfn ## _name) \
|
||||
return SCARD_E_NO_SERVICE; \
|
||||
return g_SCardApi->pfn ## _name ( __VA_ARGS__ )
|
||||
|
||||
#define SCARDAPI_STUB_CALL_HANDLE(_name, ...) \
|
||||
InitOnceExecuteOnce(&g_Initialized, InitializeSCardApiStubs, NULL, NULL); \
|
||||
if (!g_SCardApi || !g_SCardApi->pfn ## _name) \
|
||||
return NULL; \
|
||||
return g_SCardApi->pfn ## _name ( __VA_ARGS__ )
|
||||
|
||||
#define SCARDAPI_STUB_CALL_VOID(_name, ...) \
|
||||
InitOnceExecuteOnce(&g_Initialized, InitializeSCardApiStubs, NULL, NULL); \
|
||||
if (!g_SCardApi || !g_SCardApi->pfn ## _name) \
|
||||
return; \
|
||||
g_SCardApi->pfn ## _name ( __VA_ARGS__ )
|
||||
|
||||
/**
|
||||
* Standard Windows Smart Card API
|
||||
*/
|
||||
@ -40,6 +59,24 @@ const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
|
||||
const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
|
||||
const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
|
||||
|
||||
static BOOL CALLBACK InitializeSCardApiStubs(PINIT_ONCE once, PVOID param, PVOID* context)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
|
||||
if (PCSC_InitializeSCardApi() >= 0)
|
||||
g_SCardApi = PCSC_GetSCardApiFunctionTable();
|
||||
|
||||
#else
|
||||
|
||||
if (WinSCard_InitializeSCardApi() >= 0)
|
||||
g_SCardApi = WinSCard_GetSCardApiFunctionTable();
|
||||
|
||||
#endif
|
||||
#ifdef WITH_SMARTCARD_INSPECT
|
||||
g_SCardApi = Inspect_RegisterSCardApi(g_SCardApi);
|
||||
#endif
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI SCardEstablishContext(DWORD dwScope,
|
||||
LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
|
||||
{
|
||||
@ -1153,26 +1190,3 @@ WINSCARDAPI char* WINAPI SCardGetReaderStateString(DWORD dwReaderState)
|
||||
|
||||
return szReaderState;
|
||||
}
|
||||
|
||||
void InitializeSCardApiStubs(void)
|
||||
{
|
||||
g_Initialized = TRUE;
|
||||
#ifndef _WIN32
|
||||
|
||||
if (PCSC_InitializeSCardApi() >= 0)
|
||||
{
|
||||
g_SCardApi = PCSC_GetSCardApiFunctionTable();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (WinSCard_InitializeSCardApi() >= 0)
|
||||
{
|
||||
g_SCardApi = WinSCard_GetSCardApiFunctionTable();
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef WITH_SMARTCARD_INSPECT
|
||||
g_SCardApi = Inspect_RegisterSCardApi(g_SCardApi);
|
||||
#endif
|
||||
}
|
||||
|
@ -22,29 +22,6 @@
|
||||
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
#define SCARDAPI_STUB_CALL_LONG(_name, ...) \
|
||||
if (!g_Initialized) \
|
||||
InitializeSCardApiStubs(); \
|
||||
if (!g_SCardApi || !g_SCardApi->pfn ## _name) \
|
||||
return SCARD_E_NO_SERVICE; \
|
||||
return g_SCardApi->pfn ## _name ( __VA_ARGS__ )
|
||||
|
||||
#define SCARDAPI_STUB_CALL_HANDLE(_name, ...) \
|
||||
if (!g_Initialized) \
|
||||
InitializeSCardApiStubs(); \
|
||||
if (!g_SCardApi || !g_SCardApi->pfn ## _name) \
|
||||
return NULL; \
|
||||
return g_SCardApi->pfn ## _name ( __VA_ARGS__ )
|
||||
|
||||
#define SCARDAPI_STUB_CALL_VOID(_name, ...) \
|
||||
if (!g_Initialized) \
|
||||
InitializeSCardApiStubs(); \
|
||||
if (!g_SCardApi || !g_SCardApi->pfn ## _name) \
|
||||
return; \
|
||||
g_SCardApi->pfn ## _name ( __VA_ARGS__ )
|
||||
|
||||
void InitializeSCardApiStubs(void);
|
||||
|
||||
#ifndef _WIN32
|
||||
#include "smartcard_pcsc.h"
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user