Merge pull request #4239 from akallabeth/test_memleak_fixes

Test memleak fixes
This commit is contained in:
Martin Fleisz 2017-12-20 12:38:38 +01:00 committed by GitHub
commit bfe8359b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 836 additions and 592 deletions

View File

@ -1,5 +1,6 @@
message("PRELOADING android cache")
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")
# ANDROID_NDK and ANDROID_SDK must be set as environment variable
#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 (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_XSHM OFF CACHE BOOL "build with xshm support")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -1,5 +1,6 @@
message("PRELOADING android cache")
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 (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 (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_SAMPLE ON CACHE BOOL "samples")
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_X11 ON CACHE BOOL "Enable X11")
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 (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_XSHM OFF CACHE BOOL "build with xshm support")
set (WITH_SANITIZE_ADDRESS ON)

View File

@ -1,4 +1,5 @@
message("PRELOADING windows cache")
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 (WITH_SANITIZE_ADDRESS ON)

View File

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

View File

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

View File

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

View File

@ -754,6 +754,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
struct sockaddr* addr,
socklen_t addrlen, int timeout)
{
BOOL rc = FALSE;
HANDLE handles[2];
int status = 0;
int count = 0;
@ -769,7 +770,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
if (status < 0)
{
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
return FALSE;
goto fail;
}
handles[count++] = context->abortEvent;
@ -786,7 +787,7 @@ static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd,
break;
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)
freerdp_set_last_error(context, FREERDP_ERROR_CONNECT_CANCELLED);
return FALSE;
goto fail;
}
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 (WSAGetLastError() == WSAECONNRESET)
return FALSE;
goto fail;
}
status = WSAEventSelect(sockfd, handles[0], 0);
CloseHandle(handles[0]);
if (status < 0)
{
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
return FALSE;
goto fail;
}
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,

View File

@ -24,13 +24,13 @@
static int prepare(const char* currentFileV2, const char* legacyFileV2, const char* legacyFile)
{
char* legacy[] = {
"someurl ff:11:22:dd\r\n",
"otherurl aa:bb:cc:dd\r",
"legacyurl aa:bb:cc:dd\n"
"someurl ff:11:22:dd\r\n",
"otherurl aa:bb:cc:dd\r",
"legacyurl aa:bb:cc:dd\n"
};
char* hosts[] = {
"someurl 3389 ff:11:22:dd subject issuer\r\n",
"otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r",
"someurl 3389 ff:11:22:dd subject issuer\r\n",
"otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r",
};
FILE* fl = NULL;
FILE* fc = NULL;
@ -47,7 +47,7 @@ static int prepare(const char* currentFileV2, const char* legacyFileV2, const ch
for (i=0; i<sizeof(hosts)/sizeof(hosts[0]); i++)
{
if (fwrite(hosts[i], strlen(hosts[i]), 1, fl) != 1 ||
fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
goto finish;
}
@ -135,7 +135,7 @@ int TestKnownHosts(int argc, char* argv[])
goto finish;
}
store = certificate_store_new(&current);
store = certificate_store_new(&current);
if (!store)
{
fprintf(stderr, "Could not create certificate store!\n");
@ -306,6 +306,8 @@ int TestKnownHosts(int argc, char* argv[])
rc = 0;
finish:
free(current.ConfigPath);
free(legacy.ConfigPath);
if (store)
certificate_store_free(store);
if (data)

View File

@ -530,7 +530,7 @@ static BOOL test_gdi_BitBlt(UINT32 SrcFormat, UINT32 DstFormat)
goto fail;
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)
goto fail;

View File

@ -14,11 +14,12 @@
static int test_gdi_ClipCoords(void)
{
int rc = -1;
BOOL draw;
HGDI_DC hdc;
HGDI_RGN rgn1;
HGDI_RGN rgn2;
HGDI_BITMAP bmp;
HGDI_RGN rgn1 = NULL;
HGDI_RGN rgn2 = NULL;
HGDI_BITMAP bmp = NULL;
const UINT32 format = PIXEL_FORMAT_ARGB32;
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* region all inside clipping region */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* region all outside clipping region, on the left */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -61,7 +62,7 @@ static int test_gdi_ClipCoords(void)
NULL);
if (draw)
return -1;
goto fail;
/* region all outside clipping region, on the right */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -71,7 +72,7 @@ static int test_gdi_ClipCoords(void)
NULL);
if (draw)
return -1;
goto fail;
/* region all outside clipping region, on top */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -81,7 +82,7 @@ static int test_gdi_ClipCoords(void)
NULL);
if (draw)
return -1;
goto fail;
/* region all outside clipping region, at the bottom */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -91,7 +92,7 @@ static int test_gdi_ClipCoords(void)
NULL);
if (draw)
return -1;
goto fail;
/* left outside, right = clip, top = clip, bottom = clip */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* left outside, right inside, top = clip, bottom = clip */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* left = clip, right outside, top = clip, bottom = clip */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* left inside, right outside, top = clip, bottom = clip */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* top outside, bottom = clip, left = clip, right = clip */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* top = clip, bottom outside, left = clip, right = clip */
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);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
/* top = clip, bottom = clip, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
@ -154,18 +155,27 @@ static int test_gdi_ClipCoords(void)
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
return -1;
goto fail;
return 0;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT)rgn1);
gdi_DeleteObject((HGDIOBJECT)rgn2);
gdi_DeleteObject((HGDIOBJECT)bmp);
gdi_DeleteDC(hdc);
return rc;
}
static int test_gdi_InvalidateRegion(void)
{
int rc = -1;
HGDI_DC hdc;
HGDI_RGN rgn1;
HGDI_RGN rgn2;
HGDI_RGN invalid;
HGDI_BITMAP bmp;
HGDI_RGN rgn1 = NULL;
HGDI_RGN rgn2 = NULL;
HGDI_RGN invalid = NULL;
HGDI_BITMAP bmp = NULL;
const UINT32 format = PIXEL_FORMAT_XRGB32;
if (!(hdc = gdi_GetDC()))
@ -195,7 +205,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* region same as invalid region */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -204,7 +214,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* left outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -213,7 +223,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* right outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -222,7 +232,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* top outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -231,7 +241,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* bottom outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -240,7 +250,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* left outside, right outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -249,7 +259,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* top outside, bottom outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -258,7 +268,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* all outside, left */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -267,7 +277,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* all outside, right */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -276,7 +286,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* all outside, top */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -285,7 +295,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* all outside, bottom */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -294,7 +304,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* all outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -303,7 +313,7 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
/* everything */
gdi_SetRgn(invalid, 300, 300, 100, 100);
@ -312,8 +322,16 @@ static int test_gdi_InvalidateRegion(void)
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
return -1;
goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT)rgn1);
gdi_DeleteObject((HGDIOBJECT)rgn2);
gdi_DeleteObject((HGDIOBJECT)bmp);
gdi_DeleteDC(hdc);
return 0;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -935,7 +935,7 @@ int main(int argc, char* argv[])
}
/* 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);
if (!file)

View File

@ -61,9 +61,9 @@ typedef struct _TP_CALLBACK_ENVIRON_V1
DWORD Flags;
struct
{
DWORD LongFunction:1;
DWORD Persistent:1;
DWORD Private:30;
DWORD LongFunction: 1;
DWORD Persistent: 1;
DWORD Private: 30;
} s;
} u;
} TP_CALLBACK_ENVIRON_V1;
@ -85,14 +85,15 @@ 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_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
/*
There is a bug in the Win8 header that defines the IO
/*
There is a bug in the Win8 header that defines the IO
callback unconditionally. Versions of Windows greater
than XP will conditionally define it. The following
than XP will conditionally define it. The following
logic tries to fix that.
*/
#ifdef _THREADPOOLAPISET_H_
@ -105,8 +106,9 @@ logic tries to fix that.
#ifndef PTP_WIN32_IO_CALLBACK_DEFINED
typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PVOID Overlapped,
ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io);
typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context,
PVOID Overlapped,
ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io);
#endif
@ -122,7 +124,8 @@ extern "C" {
#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_SetThreadpoolWait(PTP_WAIT pwa, HANDLE h, PFILETIME pftTimeout);
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 */
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_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);
#define CreateThreadpoolWork winpr_CreateThreadpoolWork
@ -148,10 +153,12 @@ WINPR_API VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPe
/* 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 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);
#define CreateThreadpoolTimer winpr_CreateThreadpoolTimer
@ -162,7 +169,8 @@ WINPR_API VOID winpr_WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancel
/* 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_StartThreadpoolIo(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 */
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 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);
#define SetThreadpoolCallbackCleanupGroup winpr_SetThreadpoolCallbackCleanupGroup
#define CreateThreadpoolCleanupGroup winpr_CreateThreadpoolCleanupGroup
#define CloseThreadpoolCleanupGroupMembers winpr_CloseThreadpoolCleanupGroupMembers
#define CloseThreadpoolCleanupGroup winpr_CloseThreadpoolCleanupGroup
@ -220,12 +232,6 @@ static INLINE VOID SetThreadpoolCallbackPool(PTP_CALLBACK_ENVIRON pcbe, PTP_POOL
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)
{
pcbe->u.s.LongFunction = 1;
@ -244,9 +250,11 @@ WINPR_API BOOL winpr_CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci);
/* Callback Clean-up */
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_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_DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,43 +7,53 @@
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;
path = GetKnownPath(KNOWN_PATH_HOME);
if (!path)
return -1;
printf("KNOWN_PATH_HOME: %s\n", path);
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_TEMP);
if (!path)
return -1;
printf("KNOWN_PATH_TEMP: %s\n", path);
if (!path)
rc = -1;
path = GetKnownPath(KNOWN_PATH_XDG_DATA_HOME);
if (!path)
return -1;
printf("KNOWN_PATH_DATA: %s\n", path);
printf("%s Path: %s\n", name, path);
free(path);
}
{
char* path = GetKnownSubPath(id, "freerdp");
path = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME);
if (!path)
return -1;
printf("KNOWN_PATH_CONFIG: %s\n", path);
if (!path)
rc = -1;
path = GetKnownPath(KNOWN_PATH_XDG_CACHE_HOME);
if (!path)
return -1;
printf("KNOWN_PATH_CACHE: %s\n", path);
printf("%s SubPath: %s\n", name, path);
free(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;
return rc;
}

View File

@ -31,59 +31,106 @@
#ifdef _WIN32
static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT;
static PTP_CLEANUP_GROUP (WINAPI * pCreateThreadpoolCleanupGroup)();
static VOID (WINAPI * pCloseThreadpoolCleanupGroupMembers)(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
static VOID (WINAPI * pCloseThreadpoolCleanupGroup)(PTP_CLEANUP_GROUP ptpcg);
static PTP_CLEANUP_GROUP(WINAPI* pCreateThreadpoolCleanupGroup)();
static VOID (WINAPI* pCloseThreadpoolCleanupGroupMembers)(PTP_CLEANUP_GROUP ptpcg,
BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
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");
if (kernel32)
{
pCreateThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CreateThreadpoolCleanupGroup");
pCloseThreadpoolCleanupGroupMembers = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroupMembers");
pCloseThreadpoolCleanupGroupMembers = (void*)GetProcAddress(kernel32,
"CloseThreadpoolCleanupGroupMembers");
pCloseThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroup");
}
return TRUE;
}
#endif
PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup()
PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void)
{
PTP_CLEANUP_GROUP cleanupGroup = NULL;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCreateThreadpoolCleanupGroup)
return pCreateThreadpoolCleanupGroup();
#endif
cleanupGroup = (PTP_CLEANUP_GROUP) malloc(sizeof(TP_CLEANUP_GROUP));
#else
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;
}
return cleanupGroup;
#endif
}
VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext)
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
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCloseThreadpoolCleanupGroupMembers)
{
pCloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext);
return;
}
#else
while (ArrayList_Count(ptpcg->groups) > 0)
{
PTP_WORK work = ArrayList_GetItem(ptpcg->groups, 0);
winpr_CloseThreadpoolWork(work);
}
#endif
/* No default implementation */
}
VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg)
{
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCloseThreadpoolCleanupGroup)
{
pCloseThreadpoolCleanupGroup(ptpcg);
return;
}
#endif
#else
if (ptpcg && ptpcg->groups)
ArrayList_Free(ptpcg->groups);
ptpcg->env->CleanupGroup = NULL;
free(ptpcg);
#endif
}
#endif /* WINPR_THREAD_POOL defined */

View File

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

View File

@ -5,15 +5,14 @@
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;
BYTE a[1024];
BYTE b[1024];
BYTE c[1024];
printf("Hello %s: %03"PRId32" (thread: 0x%08"PRIX32")\n", (char*) context,
InterlockedIncrement(&count), GetCurrentThreadId());
InterlockedIncrement(&count), GetCurrentThreadId());
for (index = 0; index < 100; index++)
{
@ -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;
PTP_POOL pool;
PTP_WORK work;
PTP_CLEANUP_GROUP cleanupGroup;
TP_CALLBACK_ENVIRON environment;
printf("Global Thread Pool\n");
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", NULL);
if (!work)
{
printf("CreateThreadpoolWork failure\n");
return -1;
return FALSE;
}
/**
@ -55,66 +49,86 @@ int TestPoolWork(int argc, char* argv[])
WaitForThreadpoolWorkCallbacks(work, FALSE);
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");
if (!(pool = CreateThreadpool(NULL)))
{
printf("CreateThreadpool failure\n");
return -1;
return FALSE;
}
if (!SetThreadpoolThreadMinimum(pool, 4))
{
printf("SetThreadpoolThreadMinimum failure\n");
return -1;
goto fail;
}
SetThreadpoolThreadMaximum(pool, 8);
InitializeThreadpoolEnvironment(&environment);
SetThreadpoolCallbackPool(&environment, pool);
cleanupGroup = CreateThreadpoolCleanupGroup();
if (!cleanupGroup)
{
printf("CreateThreadpoolCleanupGroup failure\n");
return -1;
goto fail;
}
SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL);
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", &environment);
if (!work)
{
printf("CreateThreadpoolWork failure\n");
return -1;
goto fail;
}
for (index = 0; index < 10; index++)
SubmitThreadpoolWork(work);
WaitForThreadpoolWorkCallbacks(work, FALSE);
rc = TRUE;
fail:
CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
CloseThreadpoolCleanupGroup(cleanupGroup);
DestroyThreadpoolEnvironment(&environment);
/**
* 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,
* it is not necessary to call CloseThreadpoolWork !
* calling the CloseThreadpoolCleanupGroupMembers function releases the work, wait,
* and timer objects associated with the cleanup group.
*/
/* CloseThreadpoolWork(work); // this would segfault, see comment above. */
if (cleanupGroup)
{
CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
CloseThreadpoolCleanupGroup(cleanupGroup);
DestroyThreadpoolEnvironment(&environment);
/**
* 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,
* it is not necessary to call CloseThreadpoolWork !
* calling the CloseThreadpoolCleanupGroupMembers function releases the work, wait,
* and timer objects associated with the cleanup group.
*/
#if 0
CloseThreadpoolWork(work); // this would segfault, see comment above. */
#endif
}
CloseThreadpool(pool);
return rc;
}
int TestPoolWork(int argc, char* argv[])
{
if (!test1())
return -1;
if (!test2())
return -1;
return 0;
}

View File

@ -33,15 +33,18 @@
#ifdef _WIN32
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* 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 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");
if (kernel32)
{
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");
pWaitForThreadpoolWorkCallbacks = (void*)GetProcAddress(kernel32, "WaitForThreadpoolWorkCallbacks");
}
return TRUE;
}
#endif
@ -71,10 +75,12 @@ PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLB
PTP_WORK work = NULL;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCreateThreadpoolWork)
return pCreateThreadpoolWork(pfnwk, pv, pcbe);
#endif
work = (PTP_WORK) malloc(sizeof(TP_WORK));
work = (PTP_WORK) calloc(1, sizeof(TP_WORK));
if (work)
{
@ -83,9 +89,16 @@ PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLB
pcbe = &DEFAULT_CALLBACK_ENVIRONMENT;
pcbe->Pool = GetDefaultThreadpool();
}
work->CallbackEnvironment = pcbe;
work->WorkCallback = pfnwk;
work->CallbackParameter = pv;
#ifndef _WIN32
if (pcbe->CleanupGroup)
ArrayList_Add(pcbe->CleanupGroup->groups, work);
#endif
}
return work;
@ -95,11 +108,18 @@ VOID winpr_CloseThreadpoolWork(PTP_WORK pwk)
{
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pCloseThreadpoolWork)
{
pCloseThreadpoolWork(pwk);
return;
}
#else
if (pwk->CallbackEnvironment->CleanupGroup)
ArrayList_Remove(pwk->CallbackEnvironment->CleanupGroup->groups, pwk);
#endif
free(pwk);
}
@ -110,14 +130,16 @@ VOID winpr_SubmitThreadpoolWork(PTP_WORK pwk)
PTP_CALLBACK_INSTANCE callbackInstance;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pSubmitThreadpoolWork)
{
pSubmitThreadpoolWork(pwk);
return;
}
#endif
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)
{
@ -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
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pTrySubmitThreadpoolCallback)
return pTrySubmitThreadpoolCallback(pfns, pv, pcbe);
#endif
WLog_ERR(TAG, "TrySubmitThreadpoolCallback is not implemented");
return FALSE;
@ -144,11 +169,13 @@ VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallb
PTP_POOL pool;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
if (pWaitForThreadpoolWorkCallbacks)
{
pWaitForThreadpoolWorkCallbacks(pwk, fCancelPendingCallbacks);
return;
}
#endif
pool = pwk->CallbackEnvironment->Pool;
event = CountdownEvent_WaitHandle(pool->WorkComplete);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -265,7 +265,10 @@ static int test_image_png_to_bmp(void)
return -1;
if (!buffer)
{
free(tmp);
return -1;
}
sprintf_s(src_png, sizeof(src_png), "%s/lodepng_32bit.png", buffer);
sprintf_s(src_bmp, sizeof(src_bmp), "%s/lodepng_32bit.bmp", buffer);
@ -273,6 +276,7 @@ static int test_image_png_to_bmp(void)
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_bmp2, sizeof(dst_bmp2), "%s/lodepng_32bit-2.bmp", tmp);
free(tmp);
if (create_test(src_png, dst_png, dst_bmp))
return -1;