Fix #4239: Various memory leaks

* Fixed all tests, now can be run with -DWITH_ADDRESS_SANITIZER=ON compiled.
* Enabled address sanitizer for nightly builds.
This commit is contained in:
Armin Novak 2017-11-15 09:11:12 +01:00
parent 3b670703fb
commit 7305828122
39 changed files with 873 additions and 610 deletions

View File

@ -1,5 +1,6 @@
message("PRELOADING android cache") message("PRELOADING android cache")
set(CMAKE_TOOLCHAIN_FILE "cmake/AndroidToolchain.cmake" CACHE PATH "ToolChain file") set(CMAKE_TOOLCHAIN_FILE "cmake/AndroidToolchain.cmake" CACHE PATH "ToolChain file")
set(WITH_SANITIZE_ADDRESS ON)
set(FREERDP_EXTERNAL_SSL_PATH $ENV{ANDROID_SSL_PATH} CACHE PATH "android ssl") set(FREERDP_EXTERNAL_SSL_PATH $ENV{ANDROID_SSL_PATH} CACHE PATH "android ssl")
# ANDROID_NDK and ANDROID_SDK must be set as environment variable # ANDROID_NDK and ANDROID_SDK must be set as environment variable
#set(ANDROID_NDK $ENV{ANDROID_SDK} CACHE PATH "Android NDK") #set(ANDROID_NDK $ENV{ANDROID_SDK} CACHE PATH "Android NDK")

View File

@ -8,3 +8,4 @@ set (WITH_FFMPEG OFF CACHE BOOL "ffmepg support")
set (WITH_XV OFF CACHE BOOL "xvideo support") set (WITH_XV OFF CACHE BOOL "xvideo support")
set (BUILD_TESTING ON CACHE BOOL "build testing") set (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_XSHM OFF CACHE BOOL "build with xshm support") set (WITH_XSHM OFF CACHE BOOL "build with xshm support")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -3,3 +3,4 @@ set(CMAKE_TOOLCHAIN_FILE "cmake/iOSToolchain.cmake" CACHE PATH "ToolChain file")
set (FREERDP_IOS_EXTERNAL_SSL_PATH $ENV{FREERDP_IOS_EXTERNAL_SSL_PATH} CACHE PATH "android ssl") set (FREERDP_IOS_EXTERNAL_SSL_PATH $ENV{FREERDP_IOS_EXTERNAL_SSL_PATH} CACHE PATH "android ssl")
set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type") set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type")
set (IOS_PLATFORM "SIMULATOR" CACHE STRING "iso platfrorm to build") set (IOS_PLATFORM "SIMULATOR" CACHE STRING "iso platfrorm to build")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -47,3 +47,4 @@ set (WITH_DEBUG_X11_LOCAL_MOVESIZE OFF CACHE BOOL "enable debug")
set (WITH_DEBUG_XV OFF CACHE BOOL "enable debug") set (WITH_DEBUG_XV OFF CACHE BOOL "enable debug")
set (WITH_SAMPLE ON CACHE BOOL "samples") set (WITH_SAMPLE ON CACHE BOOL "samples")
set (WITH_NO_UNDEFINED ON CACHE BOOL "don't link with undefined symbols") set (WITH_NO_UNDEFINED ON CACHE BOOL "don't link with undefined symbols")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -4,3 +4,4 @@ set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type")
set (WITH_CUPS ON CACHE BOOL "CUPS printing") set (WITH_CUPS ON CACHE BOOL "CUPS printing")
set (WITH_X11 ON CACHE BOOL "Enable X11") set (WITH_X11 ON CACHE BOOL "Enable X11")
set (BUILD_TESTING ON CACHE BOOL "build testing") set (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -8,3 +8,4 @@ set (WITH_FFMPEG OFF CACHE BOOL "ffmepg support")
set (WITH_XV OFF CACHE BOOL "xvideo support") set (WITH_XV OFF CACHE BOOL "xvideo support")
set (BUILD_TESTING ON CACHE BOOL "build testing") set (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_XSHM OFF CACHE BOOL "build with xshm support") set (WITH_XSHM OFF CACHE BOOL "build with xshm support")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -2,3 +2,4 @@ message("PRELOADING windows cache")
set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type") set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type")
set (WITH_SERVER "ON" CACHE BOOL "Build server binaries") set (WITH_SERVER "ON" CACHE BOOL "Build server binaries")
set (BUILD_TESTING ON CACHE BOOL "build testing") set (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -29,10 +29,10 @@ static int test_ZGfxCompressFox(void)
int rc = -1; int rc = -1;
int status; int status;
UINT32 Flags; UINT32 Flags;
BYTE* pSrcData; BYTE* pSrcData = NULL;
UINT32 SrcSize; UINT32 SrcSize;
UINT32 DstSize; UINT32 DstSize;
BYTE* pDstData; BYTE* pDstData = NULL;
ZGFX_CONTEXT* zgfx; ZGFX_CONTEXT* zgfx;
UINT32 expectedSize; UINT32 expectedSize;
zgfx = zgfx_context_new(TRUE); zgfx = zgfx_context_new(TRUE);
@ -70,6 +70,7 @@ static int test_ZGfxCompressFox(void)
rc = 0; rc = 0;
fail: fail:
free(pDstData);
zgfx_context_free(zgfx); zgfx_context_free(zgfx);
return rc; return rc;
} }
@ -82,7 +83,7 @@ static int test_ZGfxDecompressFoxSingle(void)
BYTE* pSrcData; BYTE* pSrcData;
UINT32 SrcSize; UINT32 SrcSize;
UINT32 DstSize; UINT32 DstSize;
BYTE* pDstData; BYTE* pDstData = NULL;
ZGFX_CONTEXT* zgfx; ZGFX_CONTEXT* zgfx;
UINT32 expectedSize; UINT32 expectedSize;
zgfx = zgfx_context_new(TRUE); zgfx = zgfx_context_new(TRUE);
@ -120,6 +121,7 @@ static int test_ZGfxDecompressFoxSingle(void)
rc = 0; rc = 0;
fail: fail:
free(pDstData);
zgfx_context_free(zgfx); zgfx_context_free(zgfx);
return rc; return rc;
} }
@ -132,7 +134,7 @@ static int test_ZGfxDecompressFoxMultipart(void)
BYTE* pSrcData; BYTE* pSrcData;
UINT32 SrcSize; UINT32 SrcSize;
UINT32 DstSize; UINT32 DstSize;
BYTE* pDstData; BYTE* pDstData = NULL;
ZGFX_CONTEXT* zgfx; ZGFX_CONTEXT* zgfx;
UINT32 expectedSize; UINT32 expectedSize;
zgfx = zgfx_context_new(TRUE); zgfx = zgfx_context_new(TRUE);
@ -170,6 +172,7 @@ static int test_ZGfxDecompressFoxMultipart(void)
rc = 0; rc = 0;
fail: fail:
free(pDstData);
zgfx_context_free(zgfx); zgfx_context_free(zgfx);
return rc; return rc;
} }
@ -182,9 +185,9 @@ static int test_ZGfxCompressConsistent(void)
BYTE* pSrcData; BYTE* pSrcData;
UINT32 SrcSize; UINT32 SrcSize;
UINT32 DstSize; UINT32 DstSize;
BYTE* pDstData; BYTE* pDstData = NULL;
UINT32 DstSize2; UINT32 DstSize2;
BYTE* pDstData2; BYTE* pDstData2 = NULL;
ZGFX_CONTEXT* zgfx; ZGFX_CONTEXT* zgfx;
UINT32 expectedSize; UINT32 expectedSize;
BYTE BigBuffer[65536]; BYTE BigBuffer[65536];
@ -240,6 +243,8 @@ static int test_ZGfxCompressConsistent(void)
rc = 0; rc = 0;
fail: fail:
free(pDstData);
free(pDstData2);
zgfx_context_free(zgfx); zgfx_context_free(zgfx);
return rc; return rc;
} }

View File

@ -609,6 +609,7 @@ static int test_r1_inter_r3(void)
retCode = 0; retCode = 0;
out: out:
region16_uninit(&region); region16_uninit(&region);
region16_uninit(&intersection);
return retCode; return retCode;
} }

View File

@ -279,6 +279,10 @@ freerdp_connect_finally:
EventArgsInit(&e, "freerdp"); EventArgsInit(&e, "freerdp");
e.result = status ? 0 : -1; e.result = status ? 0 : -1;
PubSub_OnConnectionResult(instance->context->pubSub, instance->context, &e); PubSub_OnConnectionResult(instance->context->pubSub, instance->context, &e);
if (!status)
freerdp_disconnect(instance);
return status; return status;
} }

View File

@ -754,6 +754,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
struct sockaddr* addr, struct sockaddr* addr,
socklen_t addrlen, int timeout) socklen_t addrlen, int timeout)
{ {
BOOL rc = FALSE;
HANDLE handles[2]; HANDLE handles[2];
int status = 0; int status = 0;
int count = 0; int count = 0;
@ -769,7 +770,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
if (status < 0) if (status < 0)
{ {
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError()); WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
return FALSE; goto fail;
} }
handles[count++] = context->abortEvent; handles[count++] = context->abortEvent;
@ -786,7 +787,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
break; break;
default: default:
return FALSE; goto fail;
} }
} }
@ -797,7 +798,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
if (status == WAIT_OBJECT_0 + 1) if (status == WAIT_OBJECT_0 + 1)
freerdp_set_last_error(context, FREERDP_ERROR_CONNECT_CANCELLED); freerdp_set_last_error(context, FREERDP_ERROR_CONNECT_CANCELLED);
return FALSE; goto fail;
} }
status = recv(sockfd, NULL, 0, 0); status = recv(sockfd, NULL, 0, 0);
@ -805,22 +806,24 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
if (status == SOCKET_ERROR) if (status == SOCKET_ERROR)
{ {
if (WSAGetLastError() == WSAECONNRESET) if (WSAGetLastError() == WSAECONNRESET)
return FALSE; goto fail;
} }
status = WSAEventSelect(sockfd, handles[0], 0); status = WSAEventSelect(sockfd, handles[0], 0);
CloseHandle(handles[0]);
if (status < 0) if (status < 0)
{ {
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError()); WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
return FALSE; goto fail;
} }
if (_ioctlsocket(sockfd, FIONBIO, &arg) != 0) if (_ioctlsocket(sockfd, FIONBIO, &arg) != 0)
return FALSE; goto fail;
return TRUE; rc = TRUE;
fail:
CloseHandle(handles[0]);
return rc;
} }
static int freerdp_tcp_connect_multi(rdpContext* context, char** hostnames, static int freerdp_tcp_connect_multi(rdpContext* context, char** hostnames,

View File

@ -306,6 +306,8 @@ int TestKnownHosts(int argc, char* argv[])
rc = 0; rc = 0;
finish: finish:
free(current.ConfigPath);
free(legacy.ConfigPath);
if (store) if (store)
certificate_store_free(store); certificate_store_free(store);
if (data) if (data)

View File

@ -530,7 +530,7 @@ static BOOL test_gdi_BitBlt(UINT32 SrcFormat, UINT32 DstFormat)
goto fail; goto fail;
hBmpDstOriginal = test_convert_to_bitmap(bmp_DST, RawFormat, 0, 0, 0, hBmpDstOriginal = test_convert_to_bitmap(bmp_DST, RawFormat, 0, 0, 0,
DstFormat, 0, 0, 0, 16, 16, hPalette); SrcFormat, 0, 0, 0, 16, 16, hPalette);
if (!hBmpDstOriginal) if (!hBmpDstOriginal)
goto fail; goto fail;

View File

@ -14,11 +14,12 @@
static int test_gdi_ClipCoords(void) static int test_gdi_ClipCoords(void)
{ {
int rc = -1;
BOOL draw; BOOL draw;
HGDI_DC hdc; HGDI_DC hdc;
HGDI_RGN rgn1; HGDI_RGN rgn1 = NULL;
HGDI_RGN rgn2; HGDI_RGN rgn2 = NULL;
HGDI_BITMAP bmp; HGDI_BITMAP bmp = NULL;
const UINT32 format = PIXEL_FORMAT_ARGB32; const UINT32 format = PIXEL_FORMAT_ARGB32;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
@ -42,7 +43,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* region all inside clipping region */ /* region all inside clipping region */
gdi_SetClipRgn(hdc, 0, 0, 1024, 768); gdi_SetClipRgn(hdc, 0, 0, 1024, 768);
@ -51,7 +52,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* region all outside clipping region, on the left */ /* region all outside clipping region, on the left */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -61,7 +62,7 @@ static int test_gdi_ClipCoords(void)
NULL); NULL);
if (draw) if (draw)
return -1; goto fail;
/* region all outside clipping region, on the right */ /* region all outside clipping region, on the right */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -71,7 +72,7 @@ static int test_gdi_ClipCoords(void)
NULL); NULL);
if (draw) if (draw)
return -1; goto fail;
/* region all outside clipping region, on top */ /* region all outside clipping region, on top */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -81,7 +82,7 @@ static int test_gdi_ClipCoords(void)
NULL); NULL);
if (draw) if (draw)
return -1; goto fail;
/* region all outside clipping region, at the bottom */ /* region all outside clipping region, at the bottom */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -91,7 +92,7 @@ static int test_gdi_ClipCoords(void)
NULL); NULL);
if (draw) if (draw)
return -1; goto fail;
/* left outside, right = clip, top = clip, bottom = clip */ /* left outside, right = clip, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -100,7 +101,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* left outside, right inside, top = clip, bottom = clip */ /* left outside, right inside, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -109,7 +110,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* left = clip, right outside, top = clip, bottom = clip */ /* left = clip, right outside, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -118,7 +119,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* left inside, right outside, top = clip, bottom = clip */ /* left inside, right outside, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -127,7 +128,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* top outside, bottom = clip, left = clip, right = clip */ /* top outside, bottom = clip, left = clip, right = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -136,7 +137,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* top = clip, bottom outside, left = clip, right = clip */ /* top = clip, bottom outside, left = clip, right = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -145,7 +146,7 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
/* top = clip, bottom = clip, top = clip, bottom = clip */ /* top = clip, bottom = clip, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -154,18 +155,32 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2)) if (!gdi_EqualRgn(rgn1, rgn2))
return -1; goto fail;
return 0; rc = 0;
fail:
if (rgn1)
gdi_DeleteObject((HGDIOBJECT)rgn1);
if (rgn2)
gdi_DeleteObject((HGDIOBJECT)rgn2);
if (bmp)
gdi_DeleteObject((HGDIOBJECT)bmp);
gdi_DeleteDC(hdc);
return rc;
} }
static int test_gdi_InvalidateRegion(void) static int test_gdi_InvalidateRegion(void)
{ {
int rc = -1;
HGDI_DC hdc; HGDI_DC hdc;
HGDI_RGN rgn1; HGDI_RGN rgn1 = NULL;
HGDI_RGN rgn2; HGDI_RGN rgn2 = NULL;
HGDI_RGN invalid; HGDI_RGN invalid = NULL;
HGDI_BITMAP bmp; HGDI_BITMAP bmp = NULL;
const UINT32 format = PIXEL_FORMAT_XRGB32; const UINT32 format = PIXEL_FORMAT_XRGB32;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
@ -195,7 +210,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* region same as invalid region */ /* region same as invalid region */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -204,7 +219,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* left outside */ /* left outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -213,7 +228,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* right outside */ /* right outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -222,7 +237,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* top outside */ /* top outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -231,7 +246,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* bottom outside */ /* bottom outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -240,7 +255,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* left outside, right outside */ /* left outside, right outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -249,7 +264,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* top outside, bottom outside */ /* top outside, bottom outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -258,7 +273,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* all outside, left */ /* all outside, left */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -267,7 +282,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* all outside, right */ /* all outside, right */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -276,7 +291,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* all outside, top */ /* all outside, top */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -285,7 +300,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* all outside, bottom */ /* all outside, bottom */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -294,7 +309,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* all outside */ /* all outside */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -303,7 +318,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
/* everything */ /* everything */
gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -312,8 +327,21 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2)) if (!gdi_EqualRgn(invalid, rgn2))
return -1; goto fail;
rc = 0;
fail:
if (rgn1)
gdi_DeleteObject((HGDIOBJECT)rgn1);
if (rgn2)
gdi_DeleteObject((HGDIOBJECT)rgn2);
if (bmp)
gdi_DeleteObject((HGDIOBJECT)bmp);
gdi_DeleteDC(hdc);
return 0; return 0;
} }

View File

@ -34,6 +34,7 @@ static const UINT32 colorFormatCount = sizeof(colorFormatList) / sizeof(
static int test_gdi_GetDC(void) static int test_gdi_GetDC(void)
{ {
int rc = -1;
HGDI_DC hdc; HGDI_DC hdc;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
@ -43,18 +44,22 @@ static int test_gdi_GetDC(void)
} }
if (hdc->format != PIXEL_FORMAT_XRGB32) if (hdc->format != PIXEL_FORMAT_XRGB32)
return -1; goto fail;
if (hdc->drawMode != GDI_R2_BLACK) if (hdc->drawMode != GDI_R2_BLACK)
return -1; goto fail;
return 0; rc = 0;
fail:
gdi_DeleteDC(hdc);
return rc;
} }
static int test_gdi_CreateCompatibleDC(void) static int test_gdi_CreateCompatibleDC(void)
{ {
HGDI_DC hdc; int rc = -1;
HGDI_DC chdc; HGDI_DC hdc = NULL;
HGDI_DC chdc = NULL;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
{ {
@ -68,25 +73,33 @@ static int test_gdi_CreateCompatibleDC(void)
if (!(chdc = gdi_CreateCompatibleDC(hdc))) if (!(chdc = gdi_CreateCompatibleDC(hdc)))
{ {
printf("gdi_CreateCompatibleDC failed\n"); printf("gdi_CreateCompatibleDC failed\n");
return -1; goto fail;
} }
if (chdc->format != hdc->format) if (chdc->format != hdc->format)
return -1; goto fail;
if (chdc->drawMode != hdc->drawMode) if (chdc->drawMode != hdc->drawMode)
return -1; goto fail;
return 0; rc = 0;
fail:
if (chdc)
gdi_DeleteDC(chdc);
gdi_DeleteDC(hdc);
return rc;
} }
static int test_gdi_CreateBitmap(void) static int test_gdi_CreateBitmap(void)
{ {
int rc = -1;
UINT32 format = PIXEL_FORMAT_ARGB32; UINT32 format = PIXEL_FORMAT_ARGB32;
UINT32 width; UINT32 width;
UINT32 height; UINT32 height;
BYTE* data; BYTE* data;
HGDI_BITMAP hBitmap; HGDI_BITMAP hBitmap = NULL;
width = 32; width = 32;
height = 16; height = 16;
@ -99,34 +112,42 @@ static int test_gdi_CreateBitmap(void)
if (!(hBitmap = gdi_CreateBitmap(width, height, format, data))) if (!(hBitmap = gdi_CreateBitmap(width, height, format, data)))
{ {
printf("gdi_CreateBitmap failed\n"); printf("gdi_CreateBitmap failed\n");
return -1; goto fail;
} }
if (hBitmap->objectType != GDIOBJECT_BITMAP) if (hBitmap->objectType != GDIOBJECT_BITMAP)
return -1; goto fail;
if (hBitmap->format != format) if (hBitmap->format != format)
return -1; goto fail;
if (hBitmap->width != width) if (hBitmap->width != width)
return -1; goto fail;
if (hBitmap->height != height) if (hBitmap->height != height)
return -1; goto fail;
if (hBitmap->data != data) if (hBitmap->data != data)
return -1; goto fail;
rc = 0;
fail:
if (hBitmap)
gdi_DeleteObject((HGDIOBJECT) hBitmap); gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0; else
free(data);
return rc;
} }
static int test_gdi_CreateCompatibleBitmap(void) static int test_gdi_CreateCompatibleBitmap(void)
{ {
int rc = -1;
HGDI_DC hdc; HGDI_DC hdc;
UINT32 width; UINT32 width;
UINT32 height; UINT32 height;
HGDI_BITMAP hBitmap; HGDI_BITMAP hBitmap = NULL;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
{ {
@ -140,26 +161,33 @@ static int test_gdi_CreateCompatibleBitmap(void)
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
if (hBitmap->objectType != GDIOBJECT_BITMAP) if (hBitmap->objectType != GDIOBJECT_BITMAP)
return -1; goto fail;
if (hBitmap->format != hdc->format) if (hBitmap->format != hdc->format)
return -1; goto fail;
if (hBitmap->width != width) if (hBitmap->width != width)
return -1; goto fail;
if (hBitmap->height != height) if (hBitmap->height != height)
return -1; goto fail;
if (!hBitmap->data) if (!hBitmap->data)
return -1; goto fail;
rc = 0;
fail:
if (hBitmap)
gdi_DeleteObject((HGDIOBJECT) hBitmap); gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
gdi_DeleteDC(hdc);
return rc;
} }
static int test_gdi_CreatePen(void) static int test_gdi_CreatePen(void)
{ {
int rc = -1;
const UINT32 format = PIXEL_FORMAT_RGBA32; const UINT32 format = PIXEL_FORMAT_RGBA32;
HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD,
format, NULL); format, NULL);
@ -171,92 +199,116 @@ static int test_gdi_CreatePen(void)
} }
if (hPen->style != GDI_PS_SOLID) if (hPen->style != GDI_PS_SOLID)
return -1; goto fail;
if (hPen->width != 8) if (hPen->width != 8)
return -1; goto fail;
if (hPen->color != 0xAABBCCDD) if (hPen->color != 0xAABBCCDD)
return -1; goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT) hPen); gdi_DeleteObject((HGDIOBJECT) hPen);
return 0; return rc;
} }
static int test_gdi_CreateSolidBrush(void) static int test_gdi_CreateSolidBrush(void)
{ {
int rc = -1;
HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD); HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD);
if (hBrush->objectType != GDIOBJECT_BRUSH) if (hBrush->objectType != GDIOBJECT_BRUSH)
return -1; goto fail;
if (hBrush->style != GDI_BS_SOLID) if (hBrush->style != GDI_BS_SOLID)
return -1; goto fail;
if (hBrush->color != 0xAABBCCDD) if (hBrush->color != 0xAABBCCDD)
return -1; goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT) hBrush); gdi_DeleteObject((HGDIOBJECT) hBrush);
return 0; return rc;
} }
static int test_gdi_CreatePatternBrush(void) static int test_gdi_CreatePatternBrush(void)
{ {
int rc = -1;
HGDI_BRUSH hBrush; HGDI_BRUSH hBrush;
HGDI_BITMAP hBitmap; HGDI_BITMAP hBitmap;
hBitmap = gdi_CreateBitmap(64, 64, 32, NULL); hBitmap = gdi_CreateBitmap(64, 64, 32, NULL);
hBrush = gdi_CreatePatternBrush(hBitmap); hBrush = gdi_CreatePatternBrush(hBitmap);
if (!hBitmap || !hBrush)
goto fail;
if (hBrush->objectType != GDIOBJECT_BRUSH) if (hBrush->objectType != GDIOBJECT_BRUSH)
return -1; goto fail;
if (hBrush->style != GDI_BS_PATTERN) if (hBrush->style != GDI_BS_PATTERN)
return -1; goto fail;
if (hBrush->pattern != hBitmap) if (hBrush->pattern != hBitmap)
return -1; goto fail;
rc = 0;
fail:
if (hBitmap)
gdi_DeleteObject((HGDIOBJECT) hBitmap); gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
if (hBrush)
gdi_DeleteObject((HGDIOBJECT) hBrush);
return rc;
} }
static int test_gdi_CreateRectRgn(void) static int test_gdi_CreateRectRgn(void)
{ {
int x1 = 32; int rc = -1;
int y1 = 64; UINT32 x1 = 32;
int x2 = 128; UINT32 y1 = 64;
int y2 = 256; UINT32 x2 = 128;
UINT32 y2 = 256;
HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2); HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);
if (!hRegion)
return rc;
if (hRegion->objectType != GDIOBJECT_REGION) if (hRegion->objectType != GDIOBJECT_REGION)
return -1; goto fail;
if (hRegion->x != x1) if (hRegion->x != x1)
return -1; goto fail;
if (hRegion->y != y1) if (hRegion->y != y1)
return -1; goto fail;
if (hRegion->w != x2 - x1 + 1) if (hRegion->w != x2 - x1 + 1)
return -1; goto fail;
if (hRegion->h != y2 - y1 + 1) if (hRegion->h != y2 - y1 + 1)
return -1; goto fail;
if (hRegion->null) if (hRegion->null)
return -1; goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT) hRegion); gdi_DeleteObject((HGDIOBJECT) hRegion);
return 0; return rc;
} }
static int test_gdi_CreateRect(void) static int test_gdi_CreateRect(void)
{ {
int rc = -1;
HGDI_RECT hRect; HGDI_RECT hRect;
int x1 = 32; UINT32 x1 = 32;
int y1 = 64; UINT32 y1 = 64;
int x2 = 128; UINT32 x2 = 128;
int y2 = 256; UINT32 y2 = 256;
if (!(hRect = gdi_CreateRect(x1, y1, x2, y2))) if (!(hRect = gdi_CreateRect(x1, y1, x2, y2)))
{ {
@ -265,22 +317,24 @@ static int test_gdi_CreateRect(void)
} }
if (hRect->objectType != GDIOBJECT_RECT) if (hRect->objectType != GDIOBJECT_RECT)
return -1; goto fail;
if (hRect->left != x1) if (hRect->left != x1)
return -1; goto fail;
if (hRect->top != y1) if (hRect->top != y1)
return -1; goto fail;
if (hRect->right != x2) if (hRect->right != x2)
return -1; goto fail;
if (hRect->bottom != y2) if (hRect->bottom != y2)
return -1; goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT) hRect); gdi_DeleteObject((HGDIOBJECT) hRect);
return 0; return rc;
} }
static BOOL test_gdi_GetPixel(void) static BOOL test_gdi_GetPixel(void)
@ -305,6 +359,13 @@ static BOOL test_gdi_GetPixel(void)
hdc->format = colorFormatList[x]; hdc->format = colorFormatList[x];
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
if (!hBitmap)
{
gdi_DeleteDC(hdc);
return -1;
}
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap); gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
bpp = GetBytesPerPixel(hBitmap->format); bpp = GetBytesPerPixel(hBitmap->format);
@ -390,6 +451,7 @@ static BOOL test_gdi_SetPixel(void)
static int test_gdi_SetROP2(void) static int test_gdi_SetROP2(void)
{ {
int rc = -1;
HGDI_DC hdc; HGDI_DC hdc;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
@ -401,16 +463,20 @@ static int test_gdi_SetROP2(void)
gdi_SetROP2(hdc, GDI_R2_BLACK); gdi_SetROP2(hdc, GDI_R2_BLACK);
if (hdc->drawMode != GDI_R2_BLACK) if (hdc->drawMode != GDI_R2_BLACK)
return -1; goto fail;
return 0; rc = 0;
fail:
gdi_DeleteDC(hdc);
return rc;
} }
static int test_gdi_MoveToEx(void) static int test_gdi_MoveToEx(void)
{ {
int rc = -1;
HGDI_DC hdc; HGDI_DC hdc;
HGDI_PEN hPen; HGDI_PEN hPen = NULL;
HGDI_POINT prevPoint; HGDI_POINT prevPoint = NULL;
const UINT32 format = PIXEL_FORMAT_RGBA32; const UINT32 format = PIXEL_FORMAT_RGBA32;
gdiPalette* palette = NULL; gdiPalette* palette = NULL;
@ -423,35 +489,43 @@ static int test_gdi_MoveToEx(void)
if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette))) if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette)))
{ {
printf("gdi_CreatePen failed\n"); printf("gdi_CreatePen failed\n");
return -1; goto fail;
} }
gdi_SelectObject(hdc, (HGDIOBJECT) hPen); gdi_SelectObject(hdc, (HGDIOBJECT) hPen);
gdi_MoveToEx(hdc, 128, 256, NULL); gdi_MoveToEx(hdc, 128, 256, NULL);
if (hdc->pen->posX != 128) if (hdc->pen->posX != 128)
return -1; goto fail;
if (hdc->pen->posY != 256) if (hdc->pen->posY != 256)
return -1; goto fail;
prevPoint = (HGDI_POINT) malloc(sizeof(GDI_POINT)); prevPoint = (HGDI_POINT) malloc(sizeof(GDI_POINT));
ZeroMemory(prevPoint, sizeof(GDI_POINT)); ZeroMemory(prevPoint, sizeof(GDI_POINT));
gdi_MoveToEx(hdc, 64, 128, prevPoint); gdi_MoveToEx(hdc, 64, 128, prevPoint);
if (prevPoint->x != 128) if (prevPoint->x != 128)
return -1; goto fail;
if (prevPoint->y != 256) if (prevPoint->y != 256)
return -1; goto fail;
if (hdc->pen->posX != 64) if (hdc->pen->posX != 64)
return -1; goto fail;
if (hdc->pen->posY != 128) if (hdc->pen->posY != 128)
return -1; goto fail;
return 0; rc = 0;
fail:
if (hPen)
gdi_DeleteObject((HGDIOBJECT)hPen);
free(prevPoint);
gdi_DeleteDC(hdc);
return rc;
} }
int TestGdiCreate(int argc, char* argv[]) int TestGdiCreate(int argc, char* argv[])

View File

@ -809,6 +809,7 @@ int TestGdiLine(int argc, char* argv[])
for (x = 0; x < map_size; x++) for (x = 0; x < map_size; x++)
gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp); gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp);
gdi_DeleteObject((HGDIOBJECT)hBmp);
gdi_DeleteObject((HGDIOBJECT) pen); gdi_DeleteObject((HGDIOBJECT) pen);
gdi_DeleteDC(hdc); gdi_DeleteDC(hdc);

View File

@ -16,67 +16,71 @@
static int test_gdi_PtInRect(void) static int test_gdi_PtInRect(void)
{ {
int rc = -1;
HGDI_RECT hRect; HGDI_RECT hRect;
int left = 20; UINT32 left = 20;
int top = 40; UINT32 top = 40;
int right = 60; UINT32 right = 60;
int bottom = 80; UINT32 bottom = 80;
if (!(hRect = gdi_CreateRect(left, top, right, bottom))) if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
{ {
printf("gdi_CreateRect failed\n"); printf("gdi_CreateRect failed\n");
return -1; return rc;
} }
if (gdi_PtInRect(hRect, 0, 0)) if (gdi_PtInRect(hRect, 0, 0))
return -1; goto fail;
if (gdi_PtInRect(hRect, 500, 500)) if (gdi_PtInRect(hRect, 500, 500))
return -1; goto fail;
if (gdi_PtInRect(hRect, 40, 100)) if (gdi_PtInRect(hRect, 40, 100))
return -1; goto fail;
if (gdi_PtInRect(hRect, 10, 40)) if (gdi_PtInRect(hRect, 10, 40))
return -1; goto fail;
if (!gdi_PtInRect(hRect, 30, 50)) if (!gdi_PtInRect(hRect, 30, 50))
return -1; goto fail;
if (!gdi_PtInRect(hRect, left, top)) if (!gdi_PtInRect(hRect, left, top))
return -1; goto fail;
if (!gdi_PtInRect(hRect, right, bottom)) if (!gdi_PtInRect(hRect, right, bottom))
return -1; goto fail;
if (!gdi_PtInRect(hRect, right, 60)) if (!gdi_PtInRect(hRect, right, 60))
return -1; goto fail;
if (!gdi_PtInRect(hRect, 40, bottom)) if (!gdi_PtInRect(hRect, 40, bottom))
return -1; goto fail;
return 0; rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT)hRect);
return rc;
} }
int test_gdi_FillRect(void) int test_gdi_FillRect(void)
{ {
int rc = -1; int rc = -1;
HGDI_DC hdc; HGDI_DC hdc = NULL;
HGDI_RECT hRect; HGDI_RECT hRect = NULL;
HGDI_BRUSH hBrush = NULL; HGDI_BRUSH hBrush = NULL;
HGDI_BITMAP hBitmap = NULL; HGDI_BITMAP hBitmap = NULL;
UINT32 color; UINT32 color;
UINT32 pixel; UINT32 pixel;
UINT32 rawPixel; UINT32 rawPixel;
int x, y; UINT32 x, y;
int badPixels; UINT32 badPixels;
int goodPixels; UINT32 goodPixels;
int width = 200; UINT32 width = 200;
int height = 300; UINT32 height = 300;
int left = 20; UINT32 left = 20;
int top = 40; UINT32 top = 40;
int right = 60; UINT32 right = 60;
int bottom = 80; UINT32 bottom = 80;
if (!(hdc = gdi_GetDC())) if (!(hdc = gdi_GetDC()))
{ {
@ -144,6 +148,8 @@ int test_gdi_FillRect(void)
fail: fail:
gdi_DeleteObject((HGDIOBJECT) hBrush); gdi_DeleteObject((HGDIOBJECT) hBrush);
gdi_DeleteObject((HGDIOBJECT) hBitmap); gdi_DeleteObject((HGDIOBJECT) hBitmap);
gdi_DeleteObject((HGDIOBJECT)hRect);
gdi_DeleteDC(hdc);
return rc; return rc;
} }

View File

@ -130,7 +130,9 @@ BOOL test_assert_bitmaps_equal(HGDI_BITMAP hBmpActual,
if (!bitmapsEqual) if (!bitmapsEqual)
{ {
printf("\n%s\n", name); printf("Testing ROP %s [%s|%s]\n", name,
GetColorFormatName(hBmpActual->format),
GetColorFormatName(hBmpExpected->format));
test_dump_bitmap(hBmpActual, "Actual"); test_dump_bitmap(hBmpActual, "Actual");
test_dump_bitmap(hBmpExpected, "Expected"); test_dump_bitmap(hBmpExpected, "Expected");
fflush(stdout); fflush(stdout);

View File

@ -935,7 +935,7 @@ int main(int argc, char* argv[])
} }
/* Open the server socket and start listening. */ /* Open the server socket and start listening. */
sprintf_s(name, sizeof(name), "tfreerdp-server.%d", port); sprintf_s(name, sizeof(name), "tfreerdp-server.%ld", port);
file = GetKnownSubPath(KNOWN_PATH_TEMP, name); file = GetKnownSubPath(KNOWN_PATH_TEMP, name);
if (!file) if (!file)

View File

@ -85,7 +85,8 @@ typedef struct _TP_IO TP_IO, *PTP_IO;
typedef VOID (*PTP_WORK_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work); typedef VOID (*PTP_WORK_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work);
typedef VOID (*PTP_TIMER_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_TIMER Timer); typedef VOID (*PTP_TIMER_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_TIMER Timer);
typedef VOID (*PTP_WAIT_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WAIT Wait, TP_WAIT_RESULT WaitResult); typedef VOID (*PTP_WAIT_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WAIT Wait,
TP_WAIT_RESULT WaitResult);
#endif #endif
@ -105,7 +106,8 @@ logic tries to fix that.
#ifndef PTP_WIN32_IO_CALLBACK_DEFINED #ifndef PTP_WIN32_IO_CALLBACK_DEFINED
typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PVOID Overlapped, typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context,
PVOID Overlapped,
ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io); ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io);
#endif #endif
@ -122,7 +124,8 @@ extern "C" {
#ifdef WINPR_THREAD_POOL #ifdef WINPR_THREAD_POOL
WINPR_API PTP_WAIT winpr_CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); WINPR_API PTP_WAIT winpr_CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolWait(PTP_WAIT pwa); WINPR_API VOID winpr_CloseThreadpoolWait(PTP_WAIT pwa);
WINPR_API VOID winpr_SetThreadpoolWait(PTP_WAIT pwa, HANDLE h, PFILETIME pftTimeout); WINPR_API VOID winpr_SetThreadpoolWait(PTP_WAIT pwa, HANDLE h, PFILETIME pftTimeout);
WINPR_API VOID winpr_WaitForThreadpoolWaitCallbacks(PTP_WAIT pwa, BOOL fCancelPendingCallbacks); WINPR_API VOID winpr_WaitForThreadpoolWaitCallbacks(PTP_WAIT pwa, BOOL fCancelPendingCallbacks);
@ -134,10 +137,12 @@ WINPR_API VOID winpr_WaitForThreadpoolWaitCallbacks(PTP_WAIT pwa, BOOL fCancelPe
/* Work */ /* Work */
WINPR_API PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); WINPR_API PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolWork(PTP_WORK pwk); WINPR_API VOID winpr_CloseThreadpoolWork(PTP_WORK pwk);
WINPR_API VOID winpr_SubmitThreadpoolWork(PTP_WORK pwk); WINPR_API VOID winpr_SubmitThreadpoolWork(PTP_WORK pwk);
WINPR_API BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); WINPR_API BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallbacks); WINPR_API VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallbacks);
#define CreateThreadpoolWork winpr_CreateThreadpoolWork #define CreateThreadpoolWork winpr_CreateThreadpoolWork
@ -148,10 +153,12 @@ WINPR_API VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPe
/* Timer */ /* Timer */
WINPR_API PTP_TIMER winpr_CreateThreadpoolTimer(PTP_TIMER_CALLBACK pfnti, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); WINPR_API PTP_TIMER winpr_CreateThreadpoolTimer(PTP_TIMER_CALLBACK pfnti, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolTimer(PTP_TIMER pti); WINPR_API VOID winpr_CloseThreadpoolTimer(PTP_TIMER pti);
WINPR_API BOOL winpr_IsThreadpoolTimerSet(PTP_TIMER pti); WINPR_API BOOL winpr_IsThreadpoolTimerSet(PTP_TIMER pti);
WINPR_API VOID winpr_SetThreadpoolTimer(PTP_TIMER pti, PFILETIME pftDueTime, DWORD msPeriod, DWORD msWindowLength); WINPR_API VOID winpr_SetThreadpoolTimer(PTP_TIMER pti, PFILETIME pftDueTime, DWORD msPeriod,
DWORD msWindowLength);
WINPR_API VOID winpr_WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancelPendingCallbacks); WINPR_API VOID winpr_WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancelPendingCallbacks);
#define CreateThreadpoolTimer winpr_CreateThreadpoolTimer #define CreateThreadpoolTimer winpr_CreateThreadpoolTimer
@ -162,7 +169,8 @@ WINPR_API VOID winpr_WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancel
/* I/O */ /* I/O */
WINPR_API PTP_IO winpr_CreateThreadpoolIo(HANDLE fl, PTP_WIN32_IO_CALLBACK pfnio, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); WINPR_API PTP_IO winpr_CreateThreadpoolIo(HANDLE fl, PTP_WIN32_IO_CALLBACK pfnio, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolIo(PTP_IO pio); WINPR_API VOID winpr_CloseThreadpoolIo(PTP_IO pio);
WINPR_API VOID winpr_StartThreadpoolIo(PTP_IO pio); WINPR_API VOID winpr_StartThreadpoolIo(PTP_IO pio);
WINPR_API VOID winpr_CancelThreadpoolIo(PTP_IO pio); WINPR_API VOID winpr_CancelThreadpoolIo(PTP_IO pio);
@ -176,10 +184,14 @@ WINPR_API VOID winpr_WaitForThreadpoolIoCallbacks(PTP_IO pio, BOOL fCancelPendin
/* Clean-up Group */ /* Clean-up Group */
WINPR_API VOID winpr_SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg,
PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng);
WINPR_API PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void); WINPR_API PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void);
WINPR_API VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext); WINPR_API VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg,
BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
WINPR_API VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg); WINPR_API VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg);
#define SetThreadpoolCallbackCleanupGroup winpr_SetThreadpoolCallbackCleanupGroup
#define CreateThreadpoolCleanupGroup winpr_CreateThreadpoolCleanupGroup #define CreateThreadpoolCleanupGroup winpr_CreateThreadpoolCleanupGroup
#define CloseThreadpoolCleanupGroupMembers winpr_CloseThreadpoolCleanupGroupMembers #define CloseThreadpoolCleanupGroupMembers winpr_CloseThreadpoolCleanupGroupMembers
#define CloseThreadpoolCleanupGroup winpr_CloseThreadpoolCleanupGroup #define CloseThreadpoolCleanupGroup winpr_CloseThreadpoolCleanupGroup
@ -220,12 +232,6 @@ static INLINE VOID SetThreadpoolCallbackPool(PTP_CALLBACK_ENVIRON pcbe, PTP_POOL
pcbe->Pool = ptpp; pcbe->Pool = ptpp;
} }
static INLINE VOID SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg, PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng)
{
pcbe->CleanupGroup = ptpcg;
pcbe->CleanupGroupCancelCallback = pfng;
}
static INLINE VOID SetThreadpoolCallbackRunsLong(PTP_CALLBACK_ENVIRON pcbe) static INLINE VOID SetThreadpoolCallbackRunsLong(PTP_CALLBACK_ENVIRON pcbe)
{ {
pcbe->u.s.LongFunction = 1; pcbe->u.s.LongFunction = 1;
@ -244,9 +250,11 @@ WINPR_API BOOL winpr_CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci);
/* Callback Clean-up */ /* Callback Clean-up */
WINPR_API VOID winpr_SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt); WINPR_API VOID winpr_SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt);
WINPR_API VOID winpr_ReleaseSemaphoreWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE sem, DWORD crel); WINPR_API VOID winpr_ReleaseSemaphoreWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE sem,
DWORD crel);
WINPR_API VOID winpr_ReleaseMutexWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE mut); WINPR_API VOID winpr_ReleaseMutexWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE mut);
WINPR_API VOID winpr_LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, PCRITICAL_SECTION pcs); WINPR_API VOID winpr_LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci,
PCRITICAL_SECTION pcs);
WINPR_API VOID winpr_FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod); WINPR_API VOID winpr_FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod);
WINPR_API VOID winpr_DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci); WINPR_API VOID winpr_DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci);

View File

@ -5,23 +5,23 @@
#include <winpr/tchar.h> #include <winpr/tchar.h>
#include <winpr/dsparse.h> #include <winpr/dsparse.h>
LPCTSTR testServiceClass = _T("HTTP"); static LPCTSTR testServiceClass = _T("HTTP");
LPCTSTR testServiceName = _T("LAB1-W2K8R2-GW.lab1.awake.local"); static LPCTSTR testServiceName = _T("LAB1-W2K8R2-GW.lab1.awake.local");
LPCTSTR testSpn = _T("HTTP/LAB1-W2K8R2-GW.lab1.awake.local"); static LPCTSTR testSpn = _T("HTTP/LAB1-W2K8R2-GW.lab1.awake.local");
int TestDsMakeSpn(int argc, char* argv[]) int TestDsMakeSpn(int argc, char* argv[])
{ {
LPTSTR Spn; int rc = -1;
LPTSTR Spn = NULL;
DWORD status; DWORD status;
DWORD SpnLength; DWORD SpnLength;
SpnLength = -1; SpnLength = -1;
status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL); status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL);
if (status != ERROR_INVALID_PARAMETER) if (status != ERROR_INVALID_PARAMETER)
{ {
_tprintf(_T("DsMakeSpn: expected ERROR_INVALID_PARAMETER\n")); _tprintf(_T("DsMakeSpn: expected ERROR_INVALID_PARAMETER\n"));
return -1; goto fail;
} }
SpnLength = 0; SpnLength = 0;
@ -30,40 +30,42 @@ int TestDsMakeSpn(int argc, char* argv[])
if (status != ERROR_BUFFER_OVERFLOW) if (status != ERROR_BUFFER_OVERFLOW)
{ {
_tprintf(_T("DsMakeSpn: expected ERROR_BUFFER_OVERFLOW\n")); _tprintf(_T("DsMakeSpn: expected ERROR_BUFFER_OVERFLOW\n"));
return -1; goto fail;
} }
if (SpnLength != 37) if (SpnLength != 37)
{ {
_tprintf(_T("DsMakeSpn: SpnLength mismatch: Actual: %")_T(PRIu32)_T(", Expected: 37\n"), SpnLength); _tprintf(_T("DsMakeSpn: SpnLength mismatch: Actual: %")_T(PRIu32)_T(", Expected: 37\n"), SpnLength);
return -1; goto fail;
} }
/* SpnLength includes null terminator */ /* SpnLength includes null terminator */
Spn = (LPTSTR) calloc(SpnLength, sizeof(TCHAR)); Spn = (LPTSTR) calloc(SpnLength, sizeof(TCHAR));
if (!Spn) if (!Spn)
{ {
_tprintf(_T("DsMakeSpn: Unable to allocate memroy\n")); _tprintf(_T("DsMakeSpn: Unable to allocate memroy\n"));
return -1; goto fail;
} }
status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, Spn); status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, Spn);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
_tprintf(_T("DsMakeSpn: expected ERROR_SUCCESS\n")); _tprintf(_T("DsMakeSpn: expected ERROR_SUCCESS\n"));
return -1; goto fail;
} }
if (_tcscmp(Spn, testSpn) != 0) if (_tcscmp(Spn, testSpn) != 0)
{ {
_tprintf(_T("DsMakeSpn: SPN mismatch: Actual: %s, Expected: %s\n"), Spn, testSpn); _tprintf(_T("DsMakeSpn: SPN mismatch: Actual: %s, Expected: %s\n"), Spn, testSpn);
return -1; goto fail;
} }
_tprintf(_T("DsMakeSpn: %s\n"), Spn); _tprintf(_T("DsMakeSpn: %s\n"), Spn);
rc = 0;
return 0; fail:
free(Spn);
return rc;
} }

View File

@ -12,10 +12,8 @@ int TestEnvironmentMergeEnvironmentStrings(int argc, char* argv[])
LPTCH lpszEnvironmentBlock; LPTCH lpszEnvironmentBlock;
LPTCH lpsz2Merge = "SHELL=123\0test=1\0test1=2\0DISPLAY=:77\0\0"; LPTCH lpsz2Merge = "SHELL=123\0test=1\0test1=2\0DISPLAY=:77\0\0";
LPTCH lpszMergedEnvironmentBlock; LPTCH lpszMergedEnvironmentBlock;
lpszEnvironmentBlock = GetEnvironmentStrings(); lpszEnvironmentBlock = GetEnvironmentStrings();
lpszMergedEnvironmentBlock = MergeEnvironmentStrings(lpszEnvironmentBlock, lpsz2Merge); lpszMergedEnvironmentBlock = MergeEnvironmentStrings(lpszEnvironmentBlock, lpsz2Merge);
p = (TCHAR*) lpszMergedEnvironmentBlock; p = (TCHAR*) lpszMergedEnvironmentBlock;
while (p[0] && p[1]) while (p[0] && p[1])
@ -25,9 +23,9 @@ int TestEnvironmentMergeEnvironmentStrings(int argc, char* argv[])
p += (length + 1); p += (length + 1);
} }
FreeEnvironmentStrings(lpszMergedEnvironmentBlock);
FreeEnvironmentStrings(lpszEnvironmentBlock); FreeEnvironmentStrings(lpszEnvironmentBlock);
#endif #endif
return 0; return 0;
} }

View File

@ -16,37 +16,36 @@ int TestFileFindFirstFile(int argc, char* argv[])
LPTSTR BasePath; LPTSTR BasePath;
WIN32_FIND_DATA FindData; WIN32_FIND_DATA FindData;
TCHAR FilePath[PATHCCH_MAX_CCH]; TCHAR FilePath[PATHCCH_MAX_CCH];
str = argv[1]; str = argv[1];
#ifdef UNICODE #ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0); length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR)); BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR));
if (!BasePath) if (!BasePath)
{ {
_tprintf(_T("Unable to allocate memory\n")); _tprintf(_T("Unable to allocate memory\n"));
return -1; return -1;
} }
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
BasePath[length] = 0; BasePath[length] = 0;
#else #else
BasePath = _strdup(str); BasePath = _strdup(str);
if (!BasePath) if (!BasePath)
{ {
printf("Unable to allocate memory\n"); printf("Unable to allocate memory\n");
return -1; return -1;
} }
length = strlen(BasePath); length = strlen(BasePath);
#endif #endif
CopyMemory(FilePath, BasePath, length * sizeof(TCHAR)); CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
FilePath[length] = 0; FilePath[length] = 0;
PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS); PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestFile1")); NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestFile1"));
free(BasePath);
_tprintf(_T("Finding file: %s\n"), FilePath); _tprintf(_T("Finding file: %s\n"), FilePath);
hFind = FindFirstFile(FilePath, &FindData); hFind = FindFirstFile(FilePath, &FindData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
@ -65,6 +64,5 @@ int TestFileFindFirstFile(int argc, char* argv[])
} }
FindClose(hFind); FindClose(hFind);
return 0; return 0;
} }

View File

@ -18,40 +18,38 @@ int TestFileFindNextFile(int argc, char* argv[])
LPTSTR BasePath; LPTSTR BasePath;
WIN32_FIND_DATA FindData; WIN32_FIND_DATA FindData;
TCHAR FilePath[PATHCCH_MAX_CCH]; TCHAR FilePath[PATHCCH_MAX_CCH];
str = argv[1]; str = argv[1];
#ifdef UNICODE #ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0); length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR)); BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR));
if (!BasePath) if (!BasePath)
{ {
_tprintf(_T("Unable to allocate memory")); _tprintf(_T("Unable to allocate memory"));
return -1; return -1;
} }
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
BasePath[length] = 0; BasePath[length] = 0;
#else #else
BasePath = _strdup(str); BasePath = _strdup(str);
if (!BasePath) if (!BasePath)
{ {
printf("Unable to allocate memory"); printf("Unable to allocate memory");
return -1; return -1;
} }
length = strlen(BasePath); length = strlen(BasePath);
#endif #endif
/* Simple filter matching all files inside current directory */ /* Simple filter matching all files inside current directory */
CopyMemory(FilePath, BasePath, length * sizeof(TCHAR)); CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
FilePath[length] = 0; FilePath[length] = 0;
PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS); PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2")); NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2"));
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2File*")); NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2File*"));
free(BasePath);
_tprintf(_T("Finding file: %s\n"), FilePath); _tprintf(_T("Finding file: %s\n"), FilePath);
hFind = FindFirstFile(FilePath, &FindData); hFind = FindFirstFile(FilePath, &FindData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
@ -66,7 +64,8 @@ int TestFileFindNextFile(int argc, char* argv[])
* The current implementation does not enforce a particular order * The current implementation does not enforce a particular order
*/ */
if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) && (_tcscmp(FindData.cFileName, testDirectory2File2) != 0)) if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) &&
(_tcscmp(FindData.cFileName, testDirectory2File2) != 0))
{ {
_tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"), _tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"),
testDirectory2File1, FindData.cFileName); testDirectory2File1, FindData.cFileName);
@ -81,7 +80,8 @@ int TestFileFindNextFile(int argc, char* argv[])
return -1; return -1;
} }
if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) && (_tcscmp(FindData.cFileName, testDirectory2File2) != 0)) if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) &&
(_tcscmp(FindData.cFileName, testDirectory2File2) != 0))
{ {
_tprintf(_T("FindNextFile failure: Expected: %s, Actual: %s\n"), _tprintf(_T("FindNextFile failure: Expected: %s, Actual: %s\n"),
testDirectory2File2, FindData.cFileName); testDirectory2File2, FindData.cFileName);
@ -97,7 +97,6 @@ int TestFileFindNextFile(int argc, char* argv[])
} }
FindClose(hFind); FindClose(hFind);
return 0; return 0;
} }

View File

@ -21,10 +21,9 @@ int TestNtCreateFile(int argc, char* argv[])
OBJECT_ATTRIBUTES attributes; OBJECT_ATTRIBUTES attributes;
IO_STATUS_BLOCK ioStatusBlock; IO_STATUS_BLOCK ioStatusBlock;
int result = -1; int result = -1;
_RtlInitAnsiString(&aString, TESTFILE); _RtlInitAnsiString(&aString, TESTFILE);
ntstatus = _RtlAnsiStringToUnicodeString(&uString, &aString, TRUE); ntstatus = _RtlAnsiStringToUnicodeString(&uString, &aString, TRUE);
if (ntstatus != STATUS_SUCCESS) if (ntstatus != STATUS_SUCCESS)
{ {
printf("_RtlAnsiStringToUnicodeString failure: 0x%08"PRIX32"\n", ntstatus); printf("_RtlAnsiStringToUnicodeString failure: 0x%08"PRIX32"\n", ntstatus);
@ -33,13 +32,10 @@ int TestNtCreateFile(int argc, char* argv[])
handle = NULL; handle = NULL;
ZeroMemory(&ioStatusBlock, sizeof(IO_STATUS_BLOCK)); ZeroMemory(&ioStatusBlock, sizeof(IO_STATUS_BLOCK));
_InitializeObjectAttributes(&attributes, &uString, 0, NULL, NULL); _InitializeObjectAttributes(&attributes, &uString, 0, NULL, NULL);
DesiredAccess = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE; DesiredAccess = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
CreateOptions = FILE_DIRECTORY_FILE | FILE_WRITE_THROUGH; CreateOptions = FILE_DIRECTORY_FILE | FILE_WRITE_THROUGH;
CreateDisposition = FILE_OVERWRITE_IF; CreateDisposition = FILE_OVERWRITE_IF;
ntstatus = _NtCreateFile(&handle, DesiredAccess, &attributes, &ioStatusBlock, ntstatus = _NtCreateFile(&handle, DesiredAccess, &attributes, &ioStatusBlock,
0, 0, CreateDisposition, CreateOptions, 0, 0, 0); 0, 0, CreateDisposition, CreateOptions, 0, 0, 0);
@ -49,8 +45,6 @@ int TestNtCreateFile(int argc, char* argv[])
goto out; goto out;
} }
_RtlFreeUnicodeString(&uString);
ntstatus = _NtClose(handle); ntstatus = _NtClose(handle);
if (ntstatus != STATUS_SUCCESS) if (ntstatus != STATUS_SUCCESS)
@ -60,10 +54,10 @@ int TestNtCreateFile(int argc, char* argv[])
} }
result = 0; result = 0;
out: out:
_RtlFreeUnicodeString(&uString);
#ifndef _WIN32 #ifndef _WIN32
if (result == 0) if (result == 0)
{ {
printf("%s: Error, this test is currently expected not to succeed on this platform.\n", printf("%s: Error, this test is currently expected not to succeed on this platform.\n",
@ -76,7 +70,7 @@ out:
__FUNCTION__); __FUNCTION__);
result = 0; result = 0;
} }
#endif
#endif
return result; return result;
} }

View File

@ -7,43 +7,53 @@
int TestPathShell(int argc, char* argv[]) int TestPathShell(int argc, char* argv[])
{ {
char* path; const int paths[] =
{
KNOWN_PATH_HOME,
KNOWN_PATH_TEMP,
KNOWN_PATH_XDG_DATA_HOME,
KNOWN_PATH_XDG_CONFIG_HOME,
KNOWN_PATH_XDG_CACHE_HOME,
KNOWN_PATH_XDG_RUNTIME_DIR,
KNOWN_PATH_XDG_CONFIG_HOME
};
const char* names[] =
{
"KNOWN_PATH_HOME",
"KNOWN_PATH_TEMP",
"KNOWN_PATH_XDG_DATA_HOME",
"KNOWN_PATH_XDG_CONFIG_HOME",
"KNOWN_PATH_XDG_CACHE_HOME",
"KNOWN_PATH_XDG_RUNTIME_DIR",
"KNOWN_PATH_XDG_CONFIG_HOME"
};
int rc = 0;
size_t x;
for (x = 0; x < sizeof(paths) / sizeof(paths[0]); x++)
{
const int id = paths[x];
const char* name = names[x];
{
char* path = GetKnownPath(id);
path = GetKnownPath(KNOWN_PATH_HOME);
if (!path) if (!path)
return -1; rc = -1;
printf("KNOWN_PATH_HOME: %s\n", path);
printf("%s Path: %s\n", name, path);
free(path);
}
{
char* path = GetKnownSubPath(id, "freerdp");
path = GetKnownPath(KNOWN_PATH_TEMP);
if (!path) if (!path)
return -1; rc = -1;
printf("KNOWN_PATH_TEMP: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_DATA_HOME); printf("%s SubPath: %s\n", name, path);
if (!path) free(path);
return -1; }
printf("KNOWN_PATH_DATA: %s\n", path); }
path = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME); return rc;
if (!path)
return -1;
printf("KNOWN_PATH_CONFIG: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_CACHE_HOME);
if (!path)
return -1;
printf("KNOWN_PATH_CACHE: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_RUNTIME_DIR);
if (!path)
return -1;
printf("KNOWN_PATH_RUNTIME: %s\n", path);
path = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
if (!path)
return -1;
printf("KNOWN_PATH_CONFIG SubPath: %s\n", path);
return 0;
} }

View File

@ -32,58 +32,105 @@
#ifdef _WIN32 #ifdef _WIN32
static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT; static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT;
static PTP_CLEANUP_GROUP(WINAPI* pCreateThreadpoolCleanupGroup)(); static PTP_CLEANUP_GROUP(WINAPI* pCreateThreadpoolCleanupGroup)();
static VOID (WINAPI * pCloseThreadpoolCleanupGroupMembers)(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext); static VOID (WINAPI* pCloseThreadpoolCleanupGroupMembers)(PTP_CLEANUP_GROUP ptpcg,
BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
static VOID (WINAPI* pCloseThreadpoolCleanupGroup)(PTP_CLEANUP_GROUP ptpcg); static VOID (WINAPI* pCloseThreadpoolCleanupGroup)(PTP_CLEANUP_GROUP ptpcg);
static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
{ {
HMODULE kernel32 = LoadLibraryA("kernel32.dll"); HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32) if (kernel32)
{ {
pCreateThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CreateThreadpoolCleanupGroup"); pCreateThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CreateThreadpoolCleanupGroup");
pCloseThreadpoolCleanupGroupMembers = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroupMembers"); pCloseThreadpoolCleanupGroupMembers = (void*)GetProcAddress(kernel32,
"CloseThreadpoolCleanupGroupMembers");
pCloseThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroup"); pCloseThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroup");
} }
return TRUE; return TRUE;
} }
#endif #endif
PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup() PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void)
{ {
PTP_CLEANUP_GROUP cleanupGroup = NULL; PTP_CLEANUP_GROUP cleanupGroup = NULL;
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCreateThreadpoolCleanupGroup) if (pCreateThreadpoolCleanupGroup)
return pCreateThreadpoolCleanupGroup(); return pCreateThreadpoolCleanupGroup();
#endif
cleanupGroup = (PTP_CLEANUP_GROUP) malloc(sizeof(TP_CLEANUP_GROUP)); #else
return cleanupGroup; cleanupGroup = (PTP_CLEANUP_GROUP) calloc(1, sizeof(TP_CLEANUP_GROUP));
if (!cleanupGroup)
return NULL;
cleanupGroup->groups = ArrayList_New(FALSE);
if (!cleanupGroup->groups)
{
free(cleanupGroup);
return NULL;
} }
VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext) return cleanupGroup;
#endif
}
VOID winpr_SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg,
PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng)
{
pcbe->CleanupGroup = ptpcg;
pcbe->CleanupGroupCancelCallback = pfng;
#ifndef _WIN32
pcbe->CleanupGroup->env = pcbe;
#endif
}
VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks,
PVOID pvCleanupContext)
{ {
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCloseThreadpoolCleanupGroupMembers) if (pCloseThreadpoolCleanupGroupMembers)
{ {
pCloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext); pCloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext);
return; return;
} }
#else
while (ArrayList_Count(ptpcg->groups) > 0)
{
PTP_WORK work = ArrayList_GetItem(ptpcg->groups, 0);
winpr_CloseThreadpoolWork(work);
}
#endif #endif
/* No default implementation */
} }
VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg) VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg)
{ {
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCloseThreadpoolCleanupGroup) if (pCloseThreadpoolCleanupGroup)
{ {
pCloseThreadpoolCleanupGroup(ptpcg); pCloseThreadpoolCleanupGroup(ptpcg);
return; return;
} }
#endif
#else
if (ptpcg && ptpcg->groups)
ArrayList_Free(ptpcg->groups);
ptpcg->env->CleanupGroup = NULL;
free(ptpcg); free(ptpcg);
#endif
} }
#endif /* WINPR_THREAD_POOL defined */ #endif /* WINPR_THREAD_POOL defined */

View File

@ -64,10 +64,15 @@ struct _TP_IO
struct _TP_CLEANUP_GROUP struct _TP_CLEANUP_GROUP
{ {
#ifndef _WIN32
wArrayList* groups;
PTP_CALLBACK_ENVIRON env;
#else
void* dummy; void* dummy;
#endif
}; };
PTP_POOL GetDefaultThreadpool(); PTP_POOL GetDefaultThreadpool(void);
#endif /* WINPR_POOL_PRIVATE_H */ #endif /* WINPR_POOL_PRIVATE_H */

View File

@ -5,13 +5,12 @@
static LONG count = 0; static LONG count = 0;
void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work) static void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
{ {
int index; int index;
BYTE a[1024]; BYTE a[1024];
BYTE b[1024]; BYTE b[1024];
BYTE c[1024]; BYTE c[1024];
printf("Hello %s: %03"PRId32" (thread: 0x%08"PRIX32")\n", (char*) context, printf("Hello %s: %03"PRId32" (thread: 0x%08"PRIX32")\n", (char*) context,
InterlockedIncrement(&count), GetCurrentThreadId()); InterlockedIncrement(&count), GetCurrentThreadId());
@ -27,22 +26,17 @@ void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, P
} }
} }
int TestPoolWork(int argc, char* argv[]) static BOOL test1(void)
{ {
int index; int index;
PTP_POOL pool;
PTP_WORK work; PTP_WORK work;
PTP_CLEANUP_GROUP cleanupGroup;
TP_CALLBACK_ENVIRON environment;
printf("Global Thread Pool\n"); printf("Global Thread Pool\n");
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", NULL); work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", NULL);
if (!work) if (!work)
{ {
printf("CreateThreadpoolWork failure\n"); printf("CreateThreadpoolWork failure\n");
return -1; return FALSE;
} }
/** /**
@ -55,55 +49,63 @@ int TestPoolWork(int argc, char* argv[])
WaitForThreadpoolWorkCallbacks(work, FALSE); WaitForThreadpoolWorkCallbacks(work, FALSE);
CloseThreadpoolWork(work); CloseThreadpoolWork(work);
return TRUE;
}
static BOOL test2(void)
{
BOOL rc = FALSE;
int index;
PTP_POOL pool;
PTP_WORK work;
PTP_CLEANUP_GROUP cleanupGroup;
TP_CALLBACK_ENVIRON environment;
printf("Private Thread Pool\n"); printf("Private Thread Pool\n");
if (!(pool = CreateThreadpool(NULL))) if (!(pool = CreateThreadpool(NULL)))
{ {
printf("CreateThreadpool failure\n"); printf("CreateThreadpool failure\n");
return -1; return FALSE;
} }
if (!SetThreadpoolThreadMinimum(pool, 4)) if (!SetThreadpoolThreadMinimum(pool, 4))
{ {
printf("SetThreadpoolThreadMinimum failure\n"); printf("SetThreadpoolThreadMinimum failure\n");
return -1; goto fail;
} }
SetThreadpoolThreadMaximum(pool, 8); SetThreadpoolThreadMaximum(pool, 8);
InitializeThreadpoolEnvironment(&environment); InitializeThreadpoolEnvironment(&environment);
SetThreadpoolCallbackPool(&environment, pool); SetThreadpoolCallbackPool(&environment, pool);
cleanupGroup = CreateThreadpoolCleanupGroup(); cleanupGroup = CreateThreadpoolCleanupGroup();
if (!cleanupGroup) if (!cleanupGroup)
{ {
printf("CreateThreadpoolCleanupGroup failure\n"); printf("CreateThreadpoolCleanupGroup failure\n");
return -1; goto fail;
} }
SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL); SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL);
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", &environment); work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", &environment);
if (!work) if (!work)
{ {
printf("CreateThreadpoolWork failure\n"); printf("CreateThreadpoolWork failure\n");
return -1; goto fail;
} }
for (index = 0; index < 10; index++) for (index = 0; index < 10; index++)
SubmitThreadpoolWork(work); SubmitThreadpoolWork(work);
WaitForThreadpoolWorkCallbacks(work, FALSE); WaitForThreadpoolWorkCallbacks(work, FALSE);
rc = TRUE;
fail:
if (cleanupGroup)
{
CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL); CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
CloseThreadpoolCleanupGroup(cleanupGroup); CloseThreadpoolCleanupGroup(cleanupGroup);
DestroyThreadpoolEnvironment(&environment); DestroyThreadpoolEnvironment(&environment);
/** /**
* See Remarks at https://msdn.microsoft.com/en-us/library/windows/desktop/ms682043(v=vs.85).aspx * See Remarks at https://msdn.microsoft.com/en-us/library/windows/desktop/ms682043(v=vs.85).aspx
* If there is a cleanup group associated with the work object, * If there is a cleanup group associated with the work object,
@ -111,10 +113,22 @@ int TestPoolWork(int argc, char* argv[])
* calling the CloseThreadpoolCleanupGroupMembers function releases the work, wait, * calling the CloseThreadpoolCleanupGroupMembers function releases the work, wait,
* and timer objects associated with the cleanup group. * and timer objects associated with the cleanup group.
*/ */
#if 0
/* CloseThreadpoolWork(work); // this would segfault, see comment above. */ CloseThreadpoolWork(work); // this would segfault, see comment above. */
#endif
}
CloseThreadpool(pool); CloseThreadpool(pool);
return rc;
}
int TestPoolWork(int argc, char* argv[])
{
if (!test1())
return -1;
if (!test2())
return -1;
return 0; return 0;
} }

View File

@ -33,15 +33,18 @@
#ifdef _WIN32 #ifdef _WIN32
static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT; static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT;
static PTP_WORK(WINAPI* pCreateThreadpoolWork)(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); static PTP_WORK(WINAPI* pCreateThreadpoolWork)(PTP_WORK_CALLBACK pfnwk, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
static VOID (WINAPI* pCloseThreadpoolWork)(PTP_WORK pwk); static VOID (WINAPI* pCloseThreadpoolWork)(PTP_WORK pwk);
static VOID (WINAPI* pSubmitThreadpoolWork)(PTP_WORK pwk); static VOID (WINAPI* pSubmitThreadpoolWork)(PTP_WORK pwk);
static BOOL (WINAPI* pTrySubmitThreadpoolCallback)(PTP_SIMPLE_CALLBACK pfns, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); static BOOL (WINAPI* pTrySubmitThreadpoolCallback)(PTP_SIMPLE_CALLBACK pfns, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe);
static VOID (WINAPI* pWaitForThreadpoolWorkCallbacks)(PTP_WORK pwk, BOOL fCancelPendingCallbacks); static VOID (WINAPI* pWaitForThreadpoolWorkCallbacks)(PTP_WORK pwk, BOOL fCancelPendingCallbacks);
static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
{ {
HMODULE kernel32 = LoadLibraryA("kernel32.dll"); HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32) if (kernel32)
{ {
pCreateThreadpoolWork = (void*)GetProcAddress(kernel32, "CreateThreadpoolWork"); pCreateThreadpoolWork = (void*)GetProcAddress(kernel32, "CreateThreadpoolWork");
@ -50,6 +53,7 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID *context)
pTrySubmitThreadpoolCallback = (void*)GetProcAddress(kernel32, "TrySubmitThreadpoolCallback"); pTrySubmitThreadpoolCallback = (void*)GetProcAddress(kernel32, "TrySubmitThreadpoolCallback");
pWaitForThreadpoolWorkCallbacks = (void*)GetProcAddress(kernel32, "WaitForThreadpoolWorkCallbacks"); pWaitForThreadpoolWorkCallbacks = (void*)GetProcAddress(kernel32, "WaitForThreadpoolWorkCallbacks");
} }
return TRUE; return TRUE;
} }
#endif #endif
@ -71,10 +75,12 @@ PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLB
PTP_WORK work = NULL; PTP_WORK work = NULL;
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCreateThreadpoolWork) if (pCreateThreadpoolWork)
return pCreateThreadpoolWork(pfnwk, pv, pcbe); return pCreateThreadpoolWork(pfnwk, pv, pcbe);
#endif #endif
work = (PTP_WORK) malloc(sizeof(TP_WORK)); work = (PTP_WORK) calloc(1, sizeof(TP_WORK));
if (work) if (work)
{ {
@ -83,9 +89,16 @@ PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLB
pcbe = &DEFAULT_CALLBACK_ENVIRONMENT; pcbe = &DEFAULT_CALLBACK_ENVIRONMENT;
pcbe->Pool = GetDefaultThreadpool(); pcbe->Pool = GetDefaultThreadpool();
} }
work->CallbackEnvironment = pcbe; work->CallbackEnvironment = pcbe;
work->WorkCallback = pfnwk; work->WorkCallback = pfnwk;
work->CallbackParameter = pv; work->CallbackParameter = pv;
#ifndef _WIN32
if (pcbe->CleanupGroup)
ArrayList_Add(pcbe->CleanupGroup->groups, work);
#endif
} }
return work; return work;
@ -95,11 +108,18 @@ VOID winpr_CloseThreadpoolWork(PTP_WORK pwk)
{ {
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCloseThreadpoolWork) if (pCloseThreadpoolWork)
{ {
pCloseThreadpoolWork(pwk); pCloseThreadpoolWork(pwk);
return; return;
} }
#else
if (pwk->CallbackEnvironment->CleanupGroup)
ArrayList_Remove(pwk->CallbackEnvironment->CleanupGroup->groups, pwk);
#endif #endif
free(pwk); free(pwk);
} }
@ -110,14 +130,16 @@ VOID winpr_SubmitThreadpoolWork(PTP_WORK pwk)
PTP_CALLBACK_INSTANCE callbackInstance; PTP_CALLBACK_INSTANCE callbackInstance;
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pSubmitThreadpoolWork) if (pSubmitThreadpoolWork)
{ {
pSubmitThreadpoolWork(pwk); pSubmitThreadpoolWork(pwk);
return; return;
} }
#endif #endif
pool = pwk->CallbackEnvironment->Pool; pool = pwk->CallbackEnvironment->Pool;
callbackInstance = (PTP_CALLBACK_INSTANCE) malloc(sizeof(TP_CALLBACK_INSTANCE)); callbackInstance = (PTP_CALLBACK_INSTANCE) calloc(1, sizeof(TP_CALLBACK_INSTANCE));
if (callbackInstance) if (callbackInstance)
{ {
@ -127,12 +149,15 @@ VOID winpr_SubmitThreadpoolWork(PTP_WORK pwk)
} }
} }
BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv, PTP_CALLBACK_ENVIRON pcbe) BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv,
PTP_CALLBACK_ENVIRON pcbe)
{ {
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pTrySubmitThreadpoolCallback) if (pTrySubmitThreadpoolCallback)
return pTrySubmitThreadpoolCallback(pfns, pv, pcbe); return pTrySubmitThreadpoolCallback(pfns, pv, pcbe);
#endif #endif
WLog_ERR(TAG, "TrySubmitThreadpoolCallback is not implemented"); WLog_ERR(TAG, "TrySubmitThreadpoolCallback is not implemented");
return FALSE; return FALSE;
@ -144,11 +169,13 @@ VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallb
PTP_POOL pool; PTP_POOL pool;
#ifdef _WIN32 #ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pWaitForThreadpoolWorkCallbacks) if (pWaitForThreadpoolWorkCallbacks)
{ {
pWaitForThreadpoolWorkCallbacks(pwk, fCancelPendingCallbacks); pWaitForThreadpoolWorkCallbacks(pwk, fCancelPendingCallbacks);
return; return;
} }
#endif #endif
pool = pwk->CallbackEnvironment->Pool; pool = pwk->CallbackEnvironment->Pool;
event = CountdownEvent_WaitHandle(pool->WorkComplete); event = CountdownEvent_WaitHandle(pool->WorkComplete);

View File

@ -63,7 +63,7 @@ extern const SecPkgInfoW SCHANNEL_SecPkgInfoW;
extern const SecurityFunctionTableA SCHANNEL_SecurityFunctionTableA; extern const SecurityFunctionTableA SCHANNEL_SecurityFunctionTableA;
extern const SecurityFunctionTableW SCHANNEL_SecurityFunctionTableW; extern const SecurityFunctionTableW SCHANNEL_SecurityFunctionTableW;
const SecPkgInfoA* SecPkgInfoA_LIST[] = static const SecPkgInfoA* SecPkgInfoA_LIST[] =
{ {
&NTLM_SecPkgInfoA, &NTLM_SecPkgInfoA,
&KERBEROS_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
@ -72,7 +72,7 @@ const SecPkgInfoA* SecPkgInfoA_LIST[] =
&SCHANNEL_SecPkgInfoA &SCHANNEL_SecPkgInfoA
}; };
const SecPkgInfoW* SecPkgInfoW_LIST[] = static const SecPkgInfoW* SecPkgInfoW_LIST[] =
{ {
&NTLM_SecPkgInfoW, &NTLM_SecPkgInfoW,
&KERBEROS_SecPkgInfoW, &KERBEROS_SecPkgInfoW,
@ -81,24 +81,24 @@ const SecPkgInfoW* SecPkgInfoW_LIST[] =
&SCHANNEL_SecPkgInfoW &SCHANNEL_SecPkgInfoW
}; };
SecurityFunctionTableA winpr_SecurityFunctionTableA; static SecurityFunctionTableA winpr_SecurityFunctionTableA;
SecurityFunctionTableW winpr_SecurityFunctionTableW; static SecurityFunctionTableW winpr_SecurityFunctionTableW;
struct _SecurityFunctionTableA_NAME struct _SecurityFunctionTableA_NAME
{ {
SEC_CHAR* Name; const SEC_CHAR* Name;
const SecurityFunctionTableA* SecurityFunctionTable; const SecurityFunctionTableA* SecurityFunctionTable;
}; };
typedef struct _SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME; typedef struct _SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME;
struct _SecurityFunctionTableW_NAME struct _SecurityFunctionTableW_NAME
{ {
SEC_WCHAR* Name; const SEC_WCHAR* Name;
const SecurityFunctionTableW* SecurityFunctionTable; const SecurityFunctionTableW* SecurityFunctionTable;
}; };
typedef struct _SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME; typedef struct _SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME;
const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] =
{ {
{ "NTLM", &NTLM_SecurityFunctionTableA }, { "NTLM", &NTLM_SecurityFunctionTableA },
{ "Kerberos", &KERBEROS_SecurityFunctionTableA }, { "Kerberos", &KERBEROS_SecurityFunctionTableA },
@ -107,13 +107,13 @@ const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] =
{ "Schannel", &SCHANNEL_SecurityFunctionTableA } { "Schannel", &SCHANNEL_SecurityFunctionTableA }
}; };
WCHAR NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' }; static const WCHAR NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' };
WCHAR KERBEROS_NAME_W[] = { 'K', 'e', 'r', 'b', 'e', 'r', 'o', 's', '\0' }; static const WCHAR KERBEROS_NAME_W[] = { 'K', 'e', 'r', 'b', 'e', 'r', 'o', 's', '\0' };
WCHAR NEGOTIATE_NAME_W[] = { 'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', '\0' }; static const WCHAR NEGOTIATE_NAME_W[] = { 'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', '\0' };
WCHAR CREDSSP_NAME_W[] = { 'C', 'r', 'e', 'd', 'S', 'S', 'P', '\0' }; static const WCHAR CREDSSP_NAME_W[] = { 'C', 'r', 'e', 'd', 'S', 'S', 'P', '\0' };
WCHAR SCHANNEL_NAME_W[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', '\0' }; static const WCHAR SCHANNEL_NAME_W[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', '\0' };
const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] =
{ {
{ NTLM_NAME_W, &NTLM_SecurityFunctionTableW }, { NTLM_NAME_W, &NTLM_SecurityFunctionTableW },
{ KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW }, { KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW },
@ -140,9 +140,9 @@ struct _CONTEXT_BUFFER_ALLOC_TABLE
}; };
typedef struct _CONTEXT_BUFFER_ALLOC_TABLE CONTEXT_BUFFER_ALLOC_TABLE; typedef struct _CONTEXT_BUFFER_ALLOC_TABLE CONTEXT_BUFFER_ALLOC_TABLE;
CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable; static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = { 0 };
int sspi_ContextBufferAllocTableNew() static int sspi_ContextBufferAllocTableNew(void)
{ {
size_t size; size_t size;
ContextBufferAllocTable.entries = NULL; ContextBufferAllocTable.entries = NULL;
@ -157,7 +157,7 @@ int sspi_ContextBufferAllocTableNew()
return 1; return 1;
} }
int sspi_ContextBufferAllocTableGrow() static int sspi_ContextBufferAllocTableGrow(void)
{ {
size_t size; size_t size;
CONTEXT_BUFFER_ALLOC_ENTRY* entries; CONTEXT_BUFFER_ALLOC_ENTRY* entries;
@ -182,18 +182,22 @@ int sspi_ContextBufferAllocTableGrow()
return 1; return 1;
} }
void sspi_ContextBufferAllocTableFree() static void sspi_ContextBufferAllocTableFree(void)
{
if (ContextBufferAllocTable.cEntries == 0)
{ {
ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0; ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
free(ContextBufferAllocTable.entries); free(ContextBufferAllocTable.entries);
ContextBufferAllocTable.entries = NULL;
}
} }
void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size) static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size)
{ {
int index; UINT32 index;
void* contextBuffer; void* contextBuffer;
for (index = 0; index < (int) ContextBufferAllocTable.cMaxEntries; index++) for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
{ {
if (!ContextBufferAllocTable.entries[index].contextBuffer) if (!ContextBufferAllocTable.entries[index].contextBuffer)
{ {
@ -218,7 +222,7 @@ void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size)
return sspi_ContextBufferAlloc(allocatorIndex, size); return sspi_ContextBufferAlloc(allocatorIndex, size);
} }
SSPI_CREDENTIALS* sspi_CredentialsNew() SSPI_CREDENTIALS* sspi_CredentialsNew(void)
{ {
SSPI_CREDENTIALS* credentials; SSPI_CREDENTIALS* credentials;
credentials = (SSPI_CREDENTIALS*) calloc(1, sizeof(SSPI_CREDENTIALS)); credentials = (SSPI_CREDENTIALS*) calloc(1, sizeof(SSPI_CREDENTIALS));
@ -281,7 +285,7 @@ void sspi_SecBufferFree(PSecBuffer SecBuffer)
SecBuffer->cbBuffer = 0; SecBuffer->cbBuffer = 0;
} }
SecHandle* sspi_SecureHandleAlloc() SecHandle* sspi_SecureHandleAlloc(void)
{ {
SecHandle* handle = (SecHandle*) calloc(1, sizeof(SecHandle)); SecHandle* handle = (SecHandle*) calloc(1, sizeof(SecHandle));
@ -476,29 +480,27 @@ PSecBuffer sspi_FindSecBuffer(PSecBufferDesc pMessage, ULONG BufferType)
return pSecBuffer; return pSecBuffer;
} }
static BOOL sspi_initialized = FALSE; static BOOL CALLBACK sspi_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context)
void sspi_GlobalInit()
{
if (!sspi_initialized)
{ {
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
sspi_ContextBufferAllocTableNew(); sspi_ContextBufferAllocTableNew();
sspi_initialized = TRUE; return TRUE;
}
} }
void sspi_GlobalFinish() void sspi_GlobalInit(void)
{ {
if (sspi_initialized) static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
DWORD flags = 0;
InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
}
void sspi_GlobalFinish(void)
{ {
sspi_ContextBufferAllocTableFree(); sspi_ContextBufferAllocTableFree();
} }
sspi_initialized = FALSE; static SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Name)
}
SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Name)
{ {
int index; int index;
UINT32 cPackages; UINT32 cPackages;
@ -515,12 +517,12 @@ SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Na
return NULL; return NULL;
} }
SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameW(const SEC_WCHAR* Name) static SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameW(const SEC_WCHAR* Name)
{ {
return NULL; return NULL;
} }
SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name) static SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name)
{ {
int index; int index;
UINT32 cPackages; UINT32 cPackages;
@ -537,7 +539,7 @@ SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* N
return NULL; return NULL;
} }
SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name) static SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name)
{ {
int status; int status;
SEC_WCHAR* NameW = NULL; SEC_WCHAR* NameW = NULL;
@ -552,15 +554,15 @@ SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Na
return table; return table;
} }
void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer); static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer);
void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer); static void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer);
void sspi_ContextBufferFree(void* contextBuffer) static void sspi_ContextBufferFree(void* contextBuffer)
{ {
int index; UINT32 index;
UINT32 allocatorIndex; UINT32 allocatorIndex;
for (index = 0; index < (int) ContextBufferAllocTable.cMaxEntries; index++) for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
{ {
if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer) if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
{ {
@ -590,7 +592,7 @@ void sspi_ContextBufferFree(void* contextBuffer)
/* Package Management */ /* Package Management */
SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages, static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
PSecPkgInfoW* ppPackageInfo) PSecPkgInfoW* ppPackageInfo)
{ {
int index; int index;
@ -619,7 +621,7 @@ SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages, static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
PSecPkgInfoA* ppPackageInfo) PSecPkgInfoA* ppPackageInfo)
{ {
int index; int index;
@ -654,7 +656,7 @@ SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
return SEC_E_OK; return SEC_E_OK;
} }
void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer) static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer)
{ {
int index; int index;
UINT32 cPackages; UINT32 cPackages;
@ -680,7 +682,7 @@ SecurityFunctionTableA* SEC_ENTRY winpr_InitSecurityInterfaceA(void)
return &winpr_SecurityFunctionTableA; return &winpr_SecurityFunctionTableA;
} }
SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName, static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
PSecPkgInfoW* ppPackageInfo) PSecPkgInfoW* ppPackageInfo)
{ {
int index; int index;
@ -714,7 +716,7 @@ SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageN
return SEC_E_SECPKG_NOT_FOUND; return SEC_E_SECPKG_NOT_FOUND;
} }
SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName, static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
PSecPkgInfoA* ppPackageInfo) PSecPkgInfoA* ppPackageInfo)
{ {
int index; int index;
@ -769,7 +771,7 @@ void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer)
/* Credential Management */ /* Credential Management */
SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal, static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal,
SEC_WCHAR* pszPackage, SEC_WCHAR* pszPackage,
ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry) void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
@ -795,7 +797,7 @@ SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipa
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal, static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal,
SEC_CHAR* pszPackage, SEC_CHAR* pszPackage,
ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry) void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
@ -821,7 +823,7 @@ SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(PCtxtHandle phContext, ULONG fFlags, static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(PCtxtHandle phContext, ULONG fFlags,
PSecBuffer pPackedContext, HANDLE* pToken) PSecBuffer pPackedContext, HANDLE* pToken)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
@ -851,7 +853,7 @@ SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(PCtxtHandle phContext, ULO
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(PCredHandle phCredential) static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(PCredHandle phCredential)
{ {
char* Name; char* Name;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -880,7 +882,7 @@ SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(PCredHandle phCredential)
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage, static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
PSecBuffer pPackedContext, HANDLE pToken, PCtxtHandle phContext) PSecBuffer pPackedContext, HANDLE pToken, PCtxtHandle phContext)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
@ -910,7 +912,7 @@ SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage, static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
PSecBuffer pPackedContext, HANDLE pToken, PCtxtHandle phContext) PSecBuffer pPackedContext, HANDLE pToken, PCtxtHandle phContext)
{ {
char* Name = NULL; char* Name = NULL;
@ -940,7 +942,7 @@ SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(PCredHandle phCredential, static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(PCredHandle phCredential,
ULONG ulAttribute, void* pBuffer) ULONG ulAttribute, void* pBuffer)
{ {
SEC_WCHAR* Name; SEC_WCHAR* Name;
@ -970,7 +972,7 @@ SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(PCredHandle phCreden
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(PCredHandle phCredential, static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(PCredHandle phCredential,
ULONG ulAttribute, void* pBuffer) ULONG ulAttribute, void* pBuffer)
{ {
char* Name; char* Name;
@ -1002,7 +1004,7 @@ SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(PCredHandle phCreden
/* Context Management */ /* Context Management */
SECURITY_STATUS SEC_ENTRY winpr_AcceptSecurityContext(PCredHandle phCredential, static SECURITY_STATUS SEC_ENTRY winpr_AcceptSecurityContext(PCredHandle phCredential,
PCtxtHandle phContext, PCtxtHandle phContext,
PSecBufferDesc pInput, ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext, PSecBufferDesc pInput, ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp) PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp)
@ -1035,7 +1037,8 @@ SECURITY_STATUS SEC_ENTRY winpr_AcceptSecurityContext(PCredHandle phCredential,
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(PCtxtHandle phContext, PSecBufferDesc pInput) static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(PCtxtHandle phContext,
PSecBufferDesc pInput)
{ {
char* Name = NULL; char* Name = NULL;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -1064,7 +1067,8 @@ SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(PCtxtHandle phContext, PSecBuf
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(PCtxtHandle phContext, PSecBufferDesc pToken) static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(PCtxtHandle phContext,
PSecBufferDesc pToken)
{ {
char* Name = NULL; char* Name = NULL;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -1093,7 +1097,7 @@ SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(PCtxtHandle phContext, PSecBuf
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(PCtxtHandle phContext) static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(PCtxtHandle phContext)
{ {
char* Name = NULL; char* Name = NULL;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -1122,7 +1126,7 @@ SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(PCtxtHandle phContext)
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(void* pvContextBuffer) static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(void* pvContextBuffer)
{ {
if (!pvContextBuffer) if (!pvContextBuffer)
return SEC_E_INVALID_HANDLE; return SEC_E_INVALID_HANDLE;
@ -1131,7 +1135,7 @@ SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(void* pvContextBuffer)
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(PCtxtHandle phContext) static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(PCtxtHandle phContext)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -1160,7 +1164,7 @@ SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(PCtxtHandle phContext
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(PCredHandle phCredential, static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(PCredHandle phCredential,
PCtxtHandle phContext, PCtxtHandle phContext,
SEC_WCHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, SEC_WCHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
@ -1195,7 +1199,7 @@ SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(PCredHandle phCredent
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(PCredHandle phCredential, static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(PCredHandle phCredential,
PCtxtHandle phContext, PCtxtHandle phContext,
SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
@ -1230,7 +1234,8 @@ SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(PCredHandle phCredent
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(PCtxtHandle phContext,
ULONG ulAttribute,
void* pBuffer) void* pBuffer)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
@ -1260,7 +1265,8 @@ SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(PCtxtHandle phContext, U
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute, static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(PCtxtHandle phContext,
ULONG ulAttribute,
void* pBuffer) void* pBuffer)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
@ -1290,7 +1296,8 @@ SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(PCtxtHandle phContext, U
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(PCtxtHandle phContext, HANDLE* phToken) static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(PCtxtHandle phContext,
HANDLE* phToken)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -1319,7 +1326,8 @@ SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(PCtxtHandle phContext,
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(PCtxtHandle phContext,
ULONG ulAttribute,
void* pBuffer, ULONG cbBuffer) void* pBuffer, ULONG cbBuffer)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
@ -1349,7 +1357,8 @@ SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(PCtxtHandle phContext, ULO
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute, static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(PCtxtHandle phContext,
ULONG ulAttribute,
void* pBuffer, ULONG cbBuffer) void* pBuffer, ULONG cbBuffer)
{ {
char* Name; char* Name;
@ -1379,7 +1388,7 @@ SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(PCtxtHandle phContext, ULO
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(PCtxtHandle phContext) static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(PCtxtHandle phContext)
{ {
SEC_CHAR* Name; SEC_CHAR* Name;
SECURITY_STATUS status; SECURITY_STATUS status;
@ -1410,7 +1419,8 @@ SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(PCtxtHandle phContext)
/* Message Support */ /* Message Support */
SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage, static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(PCtxtHandle phContext,
PSecBufferDesc pMessage,
ULONG MessageSeqNo, PULONG pfQOP) ULONG MessageSeqNo, PULONG pfQOP)
{ {
char* Name; char* Name;
@ -1440,7 +1450,7 @@ SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(PCtxtHandle phContext, PSecBuffer
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(PCtxtHandle phContext, ULONG fQOP, static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
PSecBufferDesc pMessage, ULONG MessageSeqNo) PSecBufferDesc pMessage, ULONG MessageSeqNo)
{ {
char* Name; char* Name;
@ -1470,7 +1480,7 @@ SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(PCtxtHandle phContext, ULONG fQOP
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(PCtxtHandle phContext, ULONG fQOP, static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
PSecBufferDesc pMessage, ULONG MessageSeqNo) PSecBufferDesc pMessage, ULONG MessageSeqNo)
{ {
char* Name; char* Name;
@ -1500,7 +1510,8 @@ SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext, PSecBufferDesc pMessage, static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext,
PSecBufferDesc pMessage,
ULONG MessageSeqNo, PULONG pfQOP) ULONG MessageSeqNo, PULONG pfQOP)
{ {
char* Name; char* Name;
@ -1530,7 +1541,7 @@ SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext, PSecBuffe
return status; return status;
} }
SecurityFunctionTableA winpr_SecurityFunctionTableA = static SecurityFunctionTableA winpr_SecurityFunctionTableA =
{ {
1, /* dwVersion */ 1, /* dwVersion */
winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */ winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */
@ -1562,7 +1573,7 @@ SecurityFunctionTableA winpr_SecurityFunctionTableA =
winpr_SetContextAttributesA, /* SetContextAttributes */ winpr_SetContextAttributesA, /* SetContextAttributes */
}; };
SecurityFunctionTableW winpr_SecurityFunctionTableW = static SecurityFunctionTableW winpr_SecurityFunctionTableW =
{ {
1, /* dwVersion */ 1, /* dwVersion */
winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */ winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */

View File

@ -10,6 +10,7 @@ static const char* test_Password = "Password";
int TestAcquireCredentialsHandle(int argc, char* argv[]) int TestAcquireCredentialsHandle(int argc, char* argv[])
{ {
int rc = -1;
SECURITY_STATUS status; SECURITY_STATUS status;
CredHandle credentials; CredHandle credentials;
TimeStamp expiration; TimeStamp expiration;
@ -23,13 +24,7 @@ int TestAcquireCredentialsHandle(int argc, char* argv[])
identity.Password = (UINT16*) _strdup(test_Password); identity.Password = (UINT16*) _strdup(test_Password);
if (!identity.User || !identity.Domain || !identity.Password) if (!identity.User || !identity.Domain || !identity.Password)
{ goto fail;
free(identity.User);
free(identity.Domain);
free(identity.Password);
fprintf(stderr, "Memory allocation failed\n");
return -1;
}
identity.UserLength = strlen(test_User); identity.UserLength = strlen(test_User);
identity.DomainLength = strlen(test_Domain); identity.DomainLength = strlen(test_Domain);
@ -39,20 +34,23 @@ int TestAcquireCredentialsHandle(int argc, char* argv[])
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration); SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
if (status != SEC_E_OK) if (status != SEC_E_OK)
{ goto fail;
sspi_GlobalFinish();
return -1;
}
status = table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names); status = table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names);
if (status != SEC_E_OK) if (status != SEC_E_OK)
{ goto fail;
rc = 0;
fail:
if (SecIsValidHandle(&credentials))
table->FreeCredentialsHandle(&credentials);
free(identity.User);
free(identity.Domain);
free(identity.Password);
sspi_GlobalFinish(); sspi_GlobalFinish();
return -1; return rc;
}
sspi_GlobalFinish();
return 0;
} }

View File

@ -10,16 +10,17 @@ static const char* test_Password = "Password";
int TestInitializeSecurityContext(int argc, char* argv[]) int TestInitializeSecurityContext(int argc, char* argv[])
{ {
int rc = -1;
UINT32 cbMaxLen; UINT32 cbMaxLen;
UINT32 fContextReq; UINT32 fContextReq;
void* output_buffer; void* output_buffer = NULL;
CtxtHandle context; CtxtHandle context;
ULONG pfContextAttr; ULONG pfContextAttr;
SECURITY_STATUS status; SECURITY_STATUS status;
CredHandle credentials; CredHandle credentials;
TimeStamp expiration; TimeStamp expiration;
PSecPkgInfo pPackageInfo; PSecPkgInfo pPackageInfo;
SEC_WINNT_AUTH_IDENTITY identity; SEC_WINNT_AUTH_IDENTITY identity = { 0 };
SecurityFunctionTable* table; SecurityFunctionTable* table;
PSecBuffer p_SecBuffer; PSecBuffer p_SecBuffer;
SecBuffer output_SecBuffer; SecBuffer output_SecBuffer;
@ -31,7 +32,7 @@ int TestInitializeSecurityContext(int argc, char* argv[])
if (status != SEC_E_OK) if (status != SEC_E_OK)
{ {
printf("QuerySecurityPackageInfo status: 0x%08"PRIX32"\n", status); printf("QuerySecurityPackageInfo status: 0x%08"PRIX32"\n", status);
return -1; goto fail;
} }
cbMaxLen = pPackageInfo->cbMaxToken; cbMaxLen = pPackageInfo->cbMaxToken;
@ -40,13 +41,7 @@ int TestInitializeSecurityContext(int argc, char* argv[])
identity.Password = (UINT16*) _strdup(test_Password); identity.Password = (UINT16*) _strdup(test_Password);
if (!identity.User || !identity.Domain || !identity.Password) if (!identity.User || !identity.Domain || !identity.Password)
{ goto fail;
free(identity.User);
free(identity.Domain);
free(identity.Password);
fprintf(stderr, "Memory allocation failed\n");
return -1;
}
identity.UserLength = strlen(test_User); identity.UserLength = strlen(test_User);
identity.DomainLength = strlen(test_Domain); identity.DomainLength = strlen(test_Domain);
@ -58,8 +53,7 @@ int TestInitializeSecurityContext(int argc, char* argv[])
if (status != SEC_E_OK) if (status != SEC_E_OK)
{ {
printf("AcquireCredentialsHandle status: 0x%08"PRIX32"\n", status); printf("AcquireCredentialsHandle status: 0x%08"PRIX32"\n", status);
sspi_GlobalFinish(); goto fail;
return -1;
} }
fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY | fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY |
@ -69,8 +63,7 @@ int TestInitializeSecurityContext(int argc, char* argv[])
if (!output_buffer) if (!output_buffer)
{ {
printf("Memory allocation failed\n"); printf("Memory allocation failed\n");
sspi_GlobalFinish(); goto fail;
return -1;
} }
output_SecBuffer_desc.ulVersion = 0; output_SecBuffer_desc.ulVersion = 0;
@ -85,8 +78,7 @@ int TestInitializeSecurityContext(int argc, char* argv[])
if (status != SEC_I_CONTINUE_NEEDED) if (status != SEC_I_CONTINUE_NEEDED)
{ {
printf("InitializeSecurityContext status: 0x%08"PRIX32"\n", status); printf("InitializeSecurityContext status: 0x%08"PRIX32"\n", status);
sspi_GlobalFinish(); goto fail;
return -1;
} }
printf("cBuffers: %"PRIu32" ulVersion: %"PRIu32"\n", output_SecBuffer_desc.cBuffers, printf("cBuffers: %"PRIu32" ulVersion: %"PRIu32"\n", output_SecBuffer_desc.cBuffers,
@ -94,9 +86,26 @@ int TestInitializeSecurityContext(int argc, char* argv[])
p_SecBuffer = &output_SecBuffer_desc.pBuffers[0]; p_SecBuffer = &output_SecBuffer_desc.pBuffers[0];
printf("BufferType: 0x%08"PRIX32" cbBuffer: %"PRIu32"\n", p_SecBuffer->BufferType, printf("BufferType: 0x%08"PRIX32" cbBuffer: %"PRIu32"\n", p_SecBuffer->BufferType,
p_SecBuffer->cbBuffer); p_SecBuffer->cbBuffer);
table->FreeCredentialsHandle(&credentials); status = table->DeleteSecurityContext(&context);
FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish(); if (status != SEC_E_OK)
return 0; {
printf("DeleteSecurityContext status: 0x%08"PRIX32"\n", status);
goto fail;
}
rc = 0;
fail:
free(identity.User);
free(identity.Domain);
free(identity.Password);
free(output_buffer);
if (SecIsValidHandle(&credentials))
table->FreeCredentialsHandle(&credentials);
FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish();
return rc;
} }

View File

@ -6,20 +6,23 @@
int TestQuerySecurityPackageInfo(int argc, char* argv[]) int TestQuerySecurityPackageInfo(int argc, char* argv[])
{ {
int rc;
SECURITY_STATUS status; SECURITY_STATUS status;
SecPkgInfo* pPackageInfo; SecPkgInfo* pPackageInfo;
sspi_GlobalInit(); sspi_GlobalInit();
status = QuerySecurityPackageInfo(NTLM_SSP_NAME, &pPackageInfo); status = QuerySecurityPackageInfo(NTLM_SSP_NAME, &pPackageInfo);
if (status != SEC_E_OK) if (status != SEC_E_OK)
rc = -1;
else
{ {
sspi_GlobalFinish();
return -1;
}
_tprintf(_T("\nQuerySecurityPackageInfo:\n")); _tprintf(_T("\nQuerySecurityPackageInfo:\n"));
_tprintf(_T("\"%s\", \"%s\"\n"), pPackageInfo->Name, pPackageInfo->Comment); _tprintf(_T("\"%s\", \"%s\"\n"), pPackageInfo->Name, pPackageInfo->Comment);
sspi_GlobalFinish(); rc = 0;
return 0; }
FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish();
return rc;
} }

View File

@ -107,12 +107,22 @@ BOOL TimerCloseHandle(HANDLE handle)
if (!TimerIsHandled(handle)) if (!TimerIsHandled(handle))
return FALSE; return FALSE;
#ifdef __linux__ if (!timer->lpArgToCompletionRoutine)
{
#ifdef HAVE_TIMERFD_H
if (timer->fd != -1) if (timer->fd != -1)
close(timer->fd); close(timer->fd);
#endif #endif
}
else
{
#ifdef WITH_POSIX_TIMER
timer_delete(timer->tid);
#endif
}
free(timer); free(timer);
return TRUE; return TRUE;
} }

View File

@ -160,9 +160,7 @@ wKeyValuePair* HashTable_Get(wHashTable* table, void* key)
{ {
UINT32 hashValue; UINT32 hashValue;
wKeyValuePair* pair; wKeyValuePair* pair;
hashValue = table->hash(key) % table->numOfBuckets; hashValue = table->hash(key) % table->numOfBuckets;
pair = table->bucketArray[hashValue]; pair = table->bucketArray[hashValue];
while (pair && !table->keyCompare(key, pair->key)) while (pair && !table->keyCompare(key, pair->key))
@ -238,6 +236,7 @@ int HashTable_Add(wHashTable* table, void* key, void* value)
{ {
if (table->keyFree) if (table->keyFree)
table->keyFree(pair->key); table->keyFree(pair->key);
pair->key = key; pair->key = key;
} }
@ -245,6 +244,7 @@ int HashTable_Add(wHashTable* table, void* key, void* value)
{ {
if (table->valueFree) if (table->valueFree)
table->valueFree(pair->value); table->valueFree(pair->value);
pair->value = value; pair->value = value;
} }
} }
@ -295,7 +295,6 @@ BOOL HashTable_Remove(wHashTable* table, void* key)
EnterCriticalSection(&table->lock); EnterCriticalSection(&table->lock);
hashValue = table->hash(key) % table->numOfBuckets; hashValue = table->hash(key) % table->numOfBuckets;
pair = table->bucketArray[hashValue]; pair = table->bucketArray[hashValue];
while (pair && !table->keyCompare(key, pair->key)) while (pair && !table->keyCompare(key, pair->key))
@ -322,7 +321,6 @@ BOOL HashTable_Remove(wHashTable* table, void* key)
table->bucketArray[hashValue] = pair->next; table->bucketArray[hashValue] = pair->next;
free(pair); free(pair);
table->numOfElements--; table->numOfElements--;
if (table->lowerRehashThreshold > 0.0) if (table->lowerRehashThreshold > 0.0)
@ -388,7 +386,12 @@ BOOL HashTable_SetItemValue(wHashTable* table, void* key, void* value)
if (!pair) if (!pair)
status = FALSE; status = FALSE;
else else
{
if (table->valueClone && table->valueFree)
table->valueFree(pair->value);
pair->value = value; pair->value = value;
}
if (table->synchronized) if (table->synchronized)
LeaveCriticalSection(&table->lock); LeaveCriticalSection(&table->lock);
@ -424,7 +427,6 @@ void HashTable_Clear(wHashTable* table)
table->valueFree(pair->value); table->valueFree(pair->value);
free(pair); free(pair);
pair = nextPair; pair = nextPair;
} }
@ -482,9 +484,7 @@ int HashTable_GetKeys(wHashTable* table, ULONG_PTR** ppKeys)
while (pair) while (pair)
{ {
nextPair = pair->next; nextPair = pair->next;
pKeys[iKey++] = (ULONG_PTR) pair->key; pKeys[iKey++] = (ULONG_PTR) pair->key;
pair = nextPair; pair = nextPair;
} }
} }
@ -493,7 +493,6 @@ int HashTable_GetKeys(wHashTable* table, ULONG_PTR** ppKeys)
LeaveCriticalSection(&table->lock); LeaveCriticalSection(&table->lock);
*ppKeys = pKeys; *ppKeys = pKeys;
return count; return count;
} }
@ -580,18 +579,14 @@ BOOL HashTable_ContainsValue(wHashTable* table, void* value)
wHashTable* HashTable_New(BOOL synchronized) wHashTable* HashTable_New(BOOL synchronized)
{ {
wHashTable* table; wHashTable* table;
table = (wHashTable*) calloc(1, sizeof(wHashTable)); table = (wHashTable*) calloc(1, sizeof(wHashTable));
if (table) if (table)
{ {
table->synchronized = synchronized; table->synchronized = synchronized;
InitializeCriticalSectionAndSpinCount(&(table->lock), 4000); InitializeCriticalSectionAndSpinCount(&(table->lock), 4000);
table->numOfBuckets = 64; table->numOfBuckets = 64;
table->numOfElements = 0; table->numOfElements = 0;
table->bucketArray = (wKeyValuePair**) calloc(table->numOfBuckets, sizeof(wKeyValuePair*)); table->bucketArray = (wKeyValuePair**) calloc(table->numOfBuckets, sizeof(wKeyValuePair*));
if (!table->bucketArray) if (!table->bucketArray)
@ -603,7 +598,6 @@ wHashTable* HashTable_New(BOOL synchronized)
table->idealRatio = 3.0; table->idealRatio = 3.0;
table->lowerRehashThreshold = 0.0; table->lowerRehashThreshold = 0.0;
table->upperRehashThreshold = 15.0; table->upperRehashThreshold = 15.0;
table->hash = HashTable_PointerHash; table->hash = HashTable_PointerHash;
table->keyCompare = HashTable_PointerCompare; table->keyCompare = HashTable_PointerCompare;
table->valueCompare = HashTable_PointerCompare; table->valueCompare = HashTable_PointerCompare;
@ -639,13 +633,11 @@ void HashTable_Free(wHashTable* table)
table->valueFree(pair->value); table->valueFree(pair->value);
free(pair); free(pair);
pair = nextPair; pair = nextPair;
} }
} }
DeleteCriticalSection(&(table->lock)); DeleteCriticalSection(&(table->lock));
free(table->bucketArray); free(table->bucketArray);
free(table); free(table);
} }

View File

@ -7,6 +7,7 @@ int TestBacktrace(int argc, char* argv[])
size_t used, x; size_t used, x;
char** msg; char** msg;
void* stack = winpr_backtrace(20); void* stack = winpr_backtrace(20);
if (!stack) if (!stack)
{ {
fprintf(stderr, "winpr_backtrace failed!\n"); fprintf(stderr, "winpr_backtrace failed!\n");
@ -14,15 +15,17 @@ int TestBacktrace(int argc, char* argv[])
} }
msg = winpr_backtrace_symbols(stack, &used); msg = winpr_backtrace_symbols(stack, &used);
if (msg) if (msg)
{ {
for (x = 0; x < used; x++) for (x = 0; x < used; x++)
printf("%"PRIuz": %s\n", x, msg[x]); printf("%"PRIuz": %s\n", x, msg[x]);
rc = 0; rc = 0;
} }
winpr_backtrace_symbols_fd(stack, fileno(stdout)); winpr_backtrace_symbols_fd(stack, fileno(stdout));
winpr_backtrace_free(stack); winpr_backtrace_free(stack);
free(msg);
return rc; return rc;
} }

View File

@ -11,68 +11,64 @@ static char* val1 = "val1";
static char* val2 = "val2"; static char* val2 = "val2";
static char* val3 = "val3"; static char* val3 = "val3";
int test_hash_table_pointer() static int test_hash_table_pointer(void)
{ {
int rc = -1;
int count; int count;
char* value; char* value;
wHashTable* table; wHashTable* table;
table = HashTable_New(TRUE); table = HashTable_New(TRUE);
if (!table) if (!table)
return -1; return -1;
HashTable_Add(table, key1, val1); HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2); HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3); HashTable_Add(table, key3, val3);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 3) if (count != 3)
{ {
printf("HashTable_Count: Expected : 3, Actual: %d\n", count); printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Remove(table, key2); HashTable_Remove(table, key2);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 2) if (count != 2)
{ {
printf("HashTable_Count: Expected : 2, Actual: %d\n", count); printf("HashTable_Count: Expected : 2, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Remove(table, key3); HashTable_Remove(table, key3);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 1) if (count != 1)
{ {
printf("HashTable_Count: Expected : 1, Actual: %d\n", count); printf("HashTable_Count: Expected : 1, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Remove(table, key1); HashTable_Remove(table, key1);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 0) if (count != 0)
{ {
printf("HashTable_Count: Expected : 0, Actual: %d\n", count); printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Add(table, key1, val1); HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2); HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3); HashTable_Add(table, key3, val3);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 3) if (count != 3)
{ {
printf("HashTable_Count: Expected : 3, Actual: %d\n", count); printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
return -1; goto fail;
} }
value = (char*) HashTable_GetItemValue(table, key1); value = (char*) HashTable_GetItemValue(table, key1);
@ -80,7 +76,7 @@ int test_hash_table_pointer()
if (strcmp(value, val1) != 0) if (strcmp(value, val1) != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val1, value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val1, value);
return -1; goto fail;
} }
value = (char*) HashTable_GetItemValue(table, key2); value = (char*) HashTable_GetItemValue(table, key2);
@ -88,7 +84,7 @@ int test_hash_table_pointer()
if (strcmp(value, val2) != 0) if (strcmp(value, val2) != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val2, value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val2, value);
return -1; goto fail;
} }
value = (char*) HashTable_GetItemValue(table, key3); value = (char*) HashTable_GetItemValue(table, key3);
@ -96,59 +92,59 @@ int test_hash_table_pointer()
if (strcmp(value, val3) != 0) if (strcmp(value, val3) != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val3, value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val3, value);
return -1; goto fail;
} }
HashTable_SetItemValue(table, key2, "apple"); HashTable_SetItemValue(table, key2, "apple");
value = (char*) HashTable_GetItemValue(table, key2); value = (char*) HashTable_GetItemValue(table, key2);
if (strcmp(value, "apple") != 0) if (strcmp(value, "apple") != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", "apple", value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
return -1; goto fail;
} }
if (!HashTable_Contains(table, key2)) if (!HashTable_Contains(table, key2))
{ {
printf("HashTable_Contains: Expected : TRUE, Actual: FALSE\n"); printf("HashTable_Contains: Expected : TRUE, Actual: FALSE\n");
return -1; goto fail;
} }
if (!HashTable_Remove(table, key2)) if (!HashTable_Remove(table, key2))
{ {
printf("HashTable_Remove: Expected : TRUE, Actual: FALSE\n"); printf("HashTable_Remove: Expected : TRUE, Actual: FALSE\n");
return -1; goto fail;
} }
if (HashTable_Remove(table, key2)) if (HashTable_Remove(table, key2))
{ {
printf("HashTable_Remove: Expected : FALSE, Actual: TRUE\n"); printf("HashTable_Remove: Expected : FALSE, Actual: TRUE\n");
return -1; goto fail;
} }
HashTable_Clear(table); HashTable_Clear(table);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 0) if (count != 0)
{ {
printf("HashTable_Count: Expected : 0, Actual: %d\n", count); printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
return -1; goto fail;
} }
rc = 1;
fail:
HashTable_Free(table); HashTable_Free(table);
return rc;
return 1;
} }
int test_hash_table_string() static int test_hash_table_string(void)
{ {
int rc = -1;
int count; int count;
char* value; char* value;
wHashTable* table; wHashTable* table;
table = HashTable_New(TRUE); table = HashTable_New(TRUE);
if (!table) if (!table)
return -1; return -1;
@ -159,59 +155,53 @@ int test_hash_table_string()
table->valueClone = HashTable_StringClone; table->valueClone = HashTable_StringClone;
table->keyFree = HashTable_StringFree; table->keyFree = HashTable_StringFree;
table->valueFree = HashTable_StringFree; table->valueFree = HashTable_StringFree;
HashTable_Add(table, key1, val1); HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2); HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3); HashTable_Add(table, key3, val3);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 3) if (count != 3)
{ {
printf("HashTable_Count: Expected : 3, Actual: %d\n", count); printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Remove(table, key2); HashTable_Remove(table, key2);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 2) if (count != 2)
{ {
printf("HashTable_Count: Expected : 3, Actual: %d\n", count); printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Remove(table, key3); HashTable_Remove(table, key3);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 1) if (count != 1)
{ {
printf("HashTable_Count: Expected : 1, Actual: %d\n", count); printf("HashTable_Count: Expected : 1, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Remove(table, key1); HashTable_Remove(table, key1);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 0) if (count != 0)
{ {
printf("HashTable_Count: Expected : 0, Actual: %d\n", count); printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
return -1; goto fail;
} }
HashTable_Add(table, key1, val1); HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2); HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3); HashTable_Add(table, key3, val3);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 3) if (count != 3)
{ {
printf("HashTable_Count: Expected : 3, Actual: %d\n", count); printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
return -1; goto fail;
} }
value = (char*) HashTable_GetItemValue(table, key1); value = (char*) HashTable_GetItemValue(table, key1);
@ -219,7 +209,7 @@ int test_hash_table_string()
if (strcmp(value, val1) != 0) if (strcmp(value, val1) != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val1, value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val1, value);
return -1; goto fail;
} }
value = (char*) HashTable_GetItemValue(table, key2); value = (char*) HashTable_GetItemValue(table, key2);
@ -227,7 +217,7 @@ int test_hash_table_string()
if (strcmp(value, val2) != 0) if (strcmp(value, val2) != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val2, value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val2, value);
return -1; goto fail;
} }
value = (char*) HashTable_GetItemValue(table, key3); value = (char*) HashTable_GetItemValue(table, key3);
@ -235,50 +225,49 @@ int test_hash_table_string()
if (strcmp(value, val3) != 0) if (strcmp(value, val3) != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val3, value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val3, value);
return -1; goto fail;
} }
HashTable_SetItemValue(table, key2, "apple"); HashTable_SetItemValue(table, key2, "apple");
value = (char*) HashTable_GetItemValue(table, key2); value = (char*) HashTable_GetItemValue(table, key2);
if (strcmp(value, "apple") != 0) if (strcmp(value, "apple") != 0)
{ {
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", "apple", value); printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
return -1; goto fail;
} }
if (!HashTable_Contains(table, key2)) if (!HashTable_Contains(table, key2))
{ {
printf("HashTable_Contains: Expected : TRUE, Actual: FALSE\n"); printf("HashTable_Contains: Expected : TRUE, Actual: FALSE\n");
return -1; goto fail;
} }
if (!HashTable_Remove(table, key2)) if (!HashTable_Remove(table, key2))
{ {
printf("HashTable_Remove: Expected : TRUE, Actual: FALSE\n"); printf("HashTable_Remove: Expected : TRUE, Actual: FALSE\n");
return -1; goto fail;
} }
if (HashTable_Remove(table, key2)) if (HashTable_Remove(table, key2))
{ {
printf("HashTable_Remove: Expected : FALSE, Actual: TRUE\n"); printf("HashTable_Remove: Expected : FALSE, Actual: TRUE\n");
return -1; goto fail;
} }
HashTable_Clear(table); HashTable_Clear(table);
count = HashTable_Count(table); count = HashTable_Count(table);
if (count != 0) if (count != 0)
{ {
printf("HashTable_Count: Expected : 0, Actual: %d\n", count); printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
return -1; goto fail;
} }
rc = 1;
fail:
HashTable_Free(table); HashTable_Free(table);
return rc;
return 1;
} }
int TestHashTable(int argc, char* argv[]) int TestHashTable(int argc, char* argv[])

View File

@ -52,13 +52,14 @@ static void *read_image(const char *src, size_t *size)
success = 1; success = 1;
*size = src_size; *size = src_size;
cleanup: cleanup:
if (a && !success) if (a && !success)
{ {
free(a); free(a);
a = NULL; a = NULL;
} }
if (fsrc) if (fsrc)
fclose(fsrc); fclose(fsrc);
@ -68,6 +69,7 @@ cleanup:
static int img_compare(wImage* image, wImage* image2, BOOL ignoreType) static int img_compare(wImage* image, wImage* image2, BOOL ignoreType)
{ {
int rc = -1; int rc = -1;
if ((image->type != image2->type) && !ignoreType) if ((image->type != image2->type) && !ignoreType)
{ {
fprintf(stderr, "Image type mismatch %d:%d\n", image->type, image2->type); fprintf(stderr, "Image type mismatch %d:%d\n", image->type, image2->type);
@ -100,7 +102,8 @@ static int img_compare(wImage *image, wImage *image2, BOOL ignoreType)
if (image->bytesPerPixel != image2->bytesPerPixel) if (image->bytesPerPixel != image2->bytesPerPixel)
{ {
fprintf(stderr, "Image bytesPerPixel mismatch %d:%d\n", image->bytesPerPixel, image2->bytesPerPixel); fprintf(stderr, "Image bytesPerPixel mismatch %d:%d\n", image->bytesPerPixel,
image2->bytesPerPixel);
goto cleanup; goto cleanup;
} }
@ -117,7 +120,6 @@ static wImage *get_image(const char *src)
{ {
int status; int status;
wImage* image = NULL; wImage* image = NULL;
image = winpr_image_new(); image = winpr_image_new();
if (!image) if (!image)
@ -136,7 +138,6 @@ static wImage *get_image(const char *src)
} }
cleanup: cleanup:
return image; return image;
} }
@ -182,6 +183,7 @@ static int create_test(const char *src, const char *dst_png, const char *dst_bmp
/* Read image from buffer, compare. */ /* Read image from buffer, compare. */
buffer = read_image(src, &bsize); buffer = read_image(src, &bsize);
if (!buffer) if (!buffer)
{ {
fprintf(stderr, "Failed to read image %s!\n", src); fprintf(stderr, "Failed to read image %s!\n", src);
@ -205,42 +207,50 @@ static int create_test(const char *src, const char *dst_png, const char *dst_bmp
} }
rc = img_compare(image, image2, TRUE); rc = img_compare(image, image2, TRUE);
if (rc) if (rc)
goto cleanup; goto cleanup;
image3 = get_image(dst_png); image3 = get_image(dst_png);
if (!image3) if (!image3)
goto cleanup; goto cleanup;
rc = img_compare(image, image3, TRUE); rc = img_compare(image, image3, TRUE);
if (rc) if (rc)
goto cleanup; goto cleanup;
image4 = get_image(dst_bmp); image4 = get_image(dst_bmp);
if (!image4) if (!image4)
goto cleanup; goto cleanup;
rc = img_compare(image, image4, TRUE); rc = img_compare(image, image4, TRUE);
if (rc) if (rc)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
if (image) if (image)
winpr_image_free(image, TRUE); winpr_image_free(image, TRUE);
if (image2) if (image2)
winpr_image_free(image2, TRUE); winpr_image_free(image2, TRUE);
if (image3) if (image3)
winpr_image_free(image3, TRUE); winpr_image_free(image3, TRUE);
if (image4) if (image4)
winpr_image_free(image4, TRUE); winpr_image_free(image4, TRUE);
free(buffer); free(buffer);
return ret; return ret;
} }
int test_image_png_to_bmp() static int test_image_png_to_bmp(void)
{ {
char* buffer = TEST_SOURCE_PATH; char* buffer = TEST_SOURCE_PATH;
char src_png[PATH_MAX]; char src_png[PATH_MAX];
@ -255,7 +265,10 @@ int test_image_png_to_bmp()
return -1; return -1;
if (!buffer) if (!buffer)
{
free(tmp);
return -1; return -1;
}
sprintf_s(src_png, sizeof(src_png), "%s/lodepng_32bit.png", buffer); sprintf_s(src_png, sizeof(src_png), "%s/lodepng_32bit.png", buffer);
sprintf_s(src_bmp, sizeof(src_bmp), "%s/lodepng_32bit.bmp", buffer); sprintf_s(src_bmp, sizeof(src_bmp), "%s/lodepng_32bit.bmp", buffer);
@ -263,6 +276,7 @@ int test_image_png_to_bmp()
sprintf_s(dst_bmp, sizeof(dst_bmp), "%s/lodepng_32bit.bmp", tmp); sprintf_s(dst_bmp, sizeof(dst_bmp), "%s/lodepng_32bit.bmp", tmp);
sprintf_s(dst_png2, sizeof(dst_png2), "%s/lodepng_32bit-2.png", tmp); sprintf_s(dst_png2, sizeof(dst_png2), "%s/lodepng_32bit-2.png", tmp);
sprintf_s(dst_bmp2, sizeof(dst_bmp2), "%s/lodepng_32bit-2.bmp", tmp); sprintf_s(dst_bmp2, sizeof(dst_bmp2), "%s/lodepng_32bit-2.bmp", tmp);
free(tmp);
if (create_test(src_png, dst_png, dst_bmp)) if (create_test(src_png, dst_png, dst_bmp))
return -1; return -1;
@ -276,7 +290,6 @@ int test_image_png_to_bmp()
int TestImage(int argc, char* argv[]) int TestImage(int argc, char* argv[])
{ {
int rc = test_image_png_to_bmp(); int rc = test_image_png_to_bmp();
return rc; return rc;
} }