From 6ce87bd4775c9f83dd33ee43f88572c26a89fc9f Mon Sep 17 00:00:00 2001 From: Zavadovsky Yan Date: Sat, 21 Feb 2015 22:51:51 +0300 Subject: [PATCH 001/220] channels/rdpsnd: fix rdpsnd_opensles_set_format() logic If server says "PCM format" treat sound data as PCM, not ADPCM. This fixes noise from speakers when using Xrdp as server. --- .../rdpsnd/client/opensles/rdpsnd_opensles.c | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/channels/rdpsnd/client/opensles/rdpsnd_opensles.c b/channels/rdpsnd/client/opensles/rdpsnd_opensles.c index d73f91fbe..e0d13735c 100644 --- a/channels/rdpsnd/client/opensles/rdpsnd_opensles.c +++ b/channels/rdpsnd/client/opensles/rdpsnd_opensles.c @@ -136,32 +136,7 @@ static void rdpsnd_opensles_set_format(rdpsndDevicePlugin* device, opensles->rate = format->nSamplesPerSec; opensles->channels = format->nChannels; - - switch (format->wFormatTag) - { - case WAVE_FORMAT_PCM: - switch (format->wBitsPerSample) - { - case 4: - opensles->format = WAVE_FORMAT_ADPCM; - break; - - case 8: - opensles->format = WAVE_FORMAT_PCM; - break; - - case 16: - opensles->format = WAVE_FORMAT_ADPCM; - break; - } - break; - - case WAVE_FORMAT_ADPCM: - case WAVE_FORMAT_DVI_ADPCM: - opensles->format = format->wFormatTag; - break; - } - + opensles->format = format->wFormatTag; opensles->wformat = format->wFormatTag; opensles->block_size = format->nBlockAlign; } From 2c1aff1ab97b42c3251dd14692bbd2bed565dba2 Mon Sep 17 00:00:00 2001 From: Zavadovsky Yan Date: Sat, 21 Feb 2015 22:59:39 +0300 Subject: [PATCH 002/220] channels/rdpsnd: fix memory leak Pointer to sound data chunk must be put into queue otherwise bqPlayerCallback() will have nothing to free and memory will leak. --- channels/rdpsnd/client/opensles/opensl_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/channels/rdpsnd/client/opensles/opensl_io.c b/channels/rdpsnd/client/opensles/opensl_io.c index 5a4fb6fe0..8cbd313aa 100644 --- a/channels/rdpsnd/client/opensles/opensl_io.c +++ b/channels/rdpsnd/client/opensles/opensl_io.c @@ -298,6 +298,7 @@ int android_AudioOut(OPENSL_STREAM *p, const short *buffer,int size) void *data = calloc(size, sizeof(short)); memcpy(data, buffer, size * sizeof(short)); + Queue_Enqueue(p->queue, data); (*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue, data, sizeof(short) * size); From 253a60aaf3395913c0b5daad2f088c9f75150996 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 12 Aug 2015 10:49:59 +0200 Subject: [PATCH 003/220] Fixed GDI_BITMAP, now using custom deallocation function. gdi_surface_bits: Now properly discarding old bitmap before creating a new one. --- include/freerdp/gdi/bitmap.h | 3 ++- include/freerdp/gdi/gdi.h | 1 + libfreerdp/gdi/bitmap.c | 8 ++++++-- libfreerdp/gdi/dc.c | 7 +++++-- libfreerdp/gdi/gdi.c | 25 ++++++++++--------------- libfreerdp/gdi/graphics.c | 4 ++-- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/include/freerdp/gdi/bitmap.h b/include/freerdp/gdi/bitmap.h index 42caf0b13..e9d327ae0 100644 --- a/include/freerdp/gdi/bitmap.h +++ b/include/freerdp/gdi/bitmap.h @@ -38,7 +38,8 @@ FREERDP_API UINT32* gdi_GetPointer_32bpp(HGDI_BITMAP hBmp, int X, int Y); FREERDP_API void gdi_SetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y, BYTE pixel); FREERDP_API void gdi_SetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y, UINT16 pixel); FREERDP_API void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel); -FREERDP_API HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data); +FREERDP_API HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, + BYTE* data, void (*fkt_free)(void*)); FREERDP_API HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight); FREERDP_API BOOL gdi_BitBlt(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); diff --git a/include/freerdp/gdi/gdi.h b/include/freerdp/gdi/gdi.h index 9736ba724..804fb802e 100644 --- a/include/freerdp/gdi/gdi.h +++ b/include/freerdp/gdi/gdi.h @@ -178,6 +178,7 @@ struct _GDI_BITMAP int height; int scanline; BYTE* data; + void (*free)(void *); }; typedef struct _GDI_BITMAP GDI_BITMAP; typedef GDI_BITMAP* HGDI_BITMAP; diff --git a/libfreerdp/gdi/bitmap.c b/libfreerdp/gdi/bitmap.c index cc3ee84ed..b5cd25b73 100644 --- a/libfreerdp/gdi/bitmap.c +++ b/libfreerdp/gdi/bitmap.c @@ -130,10 +130,12 @@ INLINE void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel) * @param nHeight height * @param cBitsPerPixel bits per pixel * @param data pixel buffer + * @param fkt_free The function used for deallocation of the buffer, NULL for none. * @return new bitmap */ -HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data) +HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data, + void (*fkt_free)(void*)) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); @@ -147,6 +149,7 @@ HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* d hBitmap->width = nWidth; hBitmap->height = nHeight; hBitmap->data = data; + hBitmap->free = fkt_free; return hBitmap; } @@ -162,7 +165,7 @@ HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* d HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight) { - HGDI_BITMAP hBitmap = (HGDI_BITMAP) malloc(sizeof(GDI_BITMAP)); + HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); if (!hBitmap) return NULL; @@ -173,6 +176,7 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight) hBitmap->width = nWidth; hBitmap->height = nHeight; hBitmap->data = _aligned_malloc(nWidth * nHeight * hBitmap->bytesPerPixel, 16); + hBitmap->free = _aligned_free; if (!hBitmap->data) { free(hBitmap); diff --git a/libfreerdp/gdi/dc.c b/libfreerdp/gdi/dc.c index b816a77b5..f1032bef8 100644 --- a/libfreerdp/gdi/dc.c +++ b/libfreerdp/gdi/dc.c @@ -201,8 +201,11 @@ BOOL gdi_DeleteObject(HGDIOBJECT hgdiobject) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) hgdiobject; - if (hBitmap->data) - _aligned_free(hBitmap->data); + if (hBitmap->data && hBitmap->free) + { + hBitmap->free(hBitmap->data); + hBitmap->data = NULL; + } free(hBitmap); } diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 271ecd7ef..5572ecafd 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -399,7 +399,7 @@ gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* { gdiBitmap* bitmap; - bitmap = (gdiBitmap*) malloc(sizeof(gdiBitmap)); + bitmap = (gdiBitmap*) calloc(1, sizeof(gdiBitmap)); if (!bitmap) goto fail_bitmap; @@ -645,7 +645,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8, hatched, backColor, foreColor, gdi->palette); - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data, _aligned_free); if (!hBmp) { _aligned_free(data); @@ -703,7 +703,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) brush->data, backColor, foreColor, gdi->palette); } - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data, _aligned_free); if (!hBmp) { _aligned_free(data); @@ -937,7 +937,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) brush->data, backColor, foreColor, gdi->palette); } - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data, _aligned_free); if (!hBmp) { _aligned_free(data); @@ -1102,11 +1102,8 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); - gdi->image->bitmap->width = cmd->width; - gdi->image->bitmap->height = cmd->height; - gdi->image->bitmap->bitsPerPixel = cmd->bpp; - gdi->image->bitmap->bytesPerPixel = cmd->bpp / 8; - gdi->image->bitmap->data = gdi->bitmap_buffer; + gdi_DeleteObject(gdi->image->bitmap); + gdi->image->bitmap = gdi_CreateBitmap(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); } @@ -1127,11 +1124,8 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); - gdi->image->bitmap->width = cmd->width; - gdi->image->bitmap->height = cmd->height; - gdi->image->bitmap->bitsPerPixel = cmd->bpp; - gdi->image->bitmap->bytesPerPixel = cmd->bpp / 8; - gdi->image->bitmap->data = gdi->bitmap_buffer; + gdi_DeleteObject(gdi->image->bitmap); + gdi->image->bitmap = gdi_CreateBitmap(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); } @@ -1197,7 +1191,8 @@ BOOL gdi_init_primary(rdpGdi* gdi) if (!gdi->primary_buffer) gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height); else - gdi->primary->bitmap = gdi_CreateBitmap(gdi->width, gdi->height, gdi->dstBpp, gdi->primary_buffer); + gdi->primary->bitmap = gdi_CreateBitmap(gdi->width, gdi->height, gdi->dstBpp, + gdi->primary_buffer, NULL); if (!gdi->primary->bitmap) goto fail_bitmap; diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index 8e53c5280..8acb95394 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -92,7 +92,7 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int nWidth, int nHeight, int bpp, BYT freerdp_image_copy(pDstData, gdi->format, nDstStep, 0, 0, nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, gdi->palette); - bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstBpp, pDstData); + bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstBpp, pDstData, _aligned_free); return bitmap; } @@ -241,7 +241,7 @@ BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph) gdi_DeleteDC(gdi_glyph->hdc); return FALSE; } - gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data); + gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data, _aligned_free); if (!gdi_glyph->bitmap) { gdi_DeleteDC(gdi_glyph->hdc); From 8024a086cdae81a5bbc67c17f01a2532eb27f315 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 12 Aug 2015 11:15:07 +0200 Subject: [PATCH 004/220] Updated tests for new gdi_CreateBitmap API. --- libfreerdp/gdi/test/TestGdiBitBlt.c | 120 +++++++++++++-------------- libfreerdp/gdi/test/TestGdiClip.c | 4 +- libfreerdp/gdi/test/TestGdiCreate.c | 4 +- libfreerdp/gdi/test/TestGdiEllipse.c | 6 +- libfreerdp/gdi/test/TestGdiLine.c | 56 ++++++------- 5 files changed, 95 insertions(+), 95 deletions(-) diff --git a/libfreerdp/gdi/test/TestGdiBitBlt.c b/libfreerdp/gdi/test/TestGdiBitBlt.c index d9f51d79a..a45f5488f 100644 --- a/libfreerdp/gdi/test/TestGdiBitBlt.c +++ b/libfreerdp/gdi/test/TestGdiBitBlt.c @@ -589,64 +589,64 @@ int test_gdi_BitBlt_32bpp(void) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); + hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); @@ -1013,64 +1013,64 @@ int test_gdi_BitBlt_16bpp(void) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); + hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); @@ -1435,64 +1435,64 @@ int test_gdi_BitBlt_8bpp(void) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); + hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); diff --git a/libfreerdp/gdi/test/TestGdiClip.c b/libfreerdp/gdi/test/TestGdiClip.c index 0bc95258b..61f897a5d 100644 --- a/libfreerdp/gdi/test/TestGdiClip.c +++ b/libfreerdp/gdi/test/TestGdiClip.c @@ -28,7 +28,7 @@ int test_gdi_ClipCoords(void) hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; - bmp = gdi_CreateBitmap(1024, 768, 4, NULL); + bmp = gdi_CreateBitmap(1024, 768, 4, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); @@ -186,7 +186,7 @@ int test_gdi_InvalidateRegion(void) hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; - bmp = gdi_CreateBitmap(1024, 768, 4, NULL); + bmp = gdi_CreateBitmap(1024, 768, 4, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); diff --git a/libfreerdp/gdi/test/TestGdiCreate.c b/libfreerdp/gdi/test/TestGdiCreate.c index 584d68362..16ef8ae5e 100644 --- a/libfreerdp/gdi/test/TestGdiCreate.c +++ b/libfreerdp/gdi/test/TestGdiCreate.c @@ -83,7 +83,7 @@ int test_gdi_CreateBitmap(void) return -1; } - if (!(hBitmap = gdi_CreateBitmap(width, height, bpp, data))) + if (!(hBitmap = gdi_CreateBitmap(width, height, bpp, data, _aligned_free))) { printf("gdi_CreateBitmap failed\n"); return -1; @@ -199,7 +199,7 @@ int test_gdi_CreatePatternBrush(void) HGDI_BRUSH hBrush; HGDI_BITMAP hBitmap; - hBitmap = gdi_CreateBitmap(64, 64, 32, NULL); + hBitmap = gdi_CreateBitmap(64, 64, 32, NULL, NULL); hBrush = gdi_CreatePatternBrush(hBitmap); if (hBrush->objectType != GDIOBJECT_BRUSH) diff --git a/libfreerdp/gdi/test/TestGdiEllipse.c b/libfreerdp/gdi/test/TestGdiEllipse.c index 7d3b107e6..be46d3591 100644 --- a/libfreerdp/gdi/test/TestGdiEllipse.c +++ b/libfreerdp/gdi/test/TestGdiEllipse.c @@ -120,13 +120,13 @@ int TestGdiEllipse(int argc, char* argv[]) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); /* Test Case 1: (0,0) -> (16, 16) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS)) diff --git a/libfreerdp/gdi/test/TestGdiLine.c b/libfreerdp/gdi/test/TestGdiLine.c index 1ae64a030..87b1dff70 100644 --- a/libfreerdp/gdi/test/TestGdiLine.c +++ b/libfreerdp/gdi/test/TestGdiLine.c @@ -667,88 +667,88 @@ int TestGdiLine(int argc, char* argv[]) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_4, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_6, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_7, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_8, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_9, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_10, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_11, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_BLACK, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKNOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTCOPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_XORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTXORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOP, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGENOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_COPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_WHITE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); /* Test Case 1: (0,0) -> (15, 15) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS)) From e8554a51b85d1366c380675f8336075e402090eb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 12 Aug 2015 12:52:48 +0200 Subject: [PATCH 005/220] Selecting correct bitmap in hdc now. --- libfreerdp/gdi/gdi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 5572ecafd..4e4d70cbb 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -1104,6 +1104,7 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) gdi_DeleteObject(gdi->image->bitmap); gdi->image->bitmap = gdi_CreateBitmap(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); + gdi_SelectObject(gdi->image->hdc, (HGDIOBJECT) gdi->image->bitmap); gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); } @@ -1126,6 +1127,7 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) gdi_DeleteObject(gdi->image->bitmap); gdi->image->bitmap = gdi_CreateBitmap(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); + gdi_SelectObject(gdi->image->hdc, (HGDIOBJECT) gdi->image->bitmap); gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); } From db3fa9a0d2fc0d31112437b602212a187b14702d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 26 Aug 2015 12:14:46 +0200 Subject: [PATCH 006/220] Added gdi_CreateBitmapEx function. --- include/freerdp/gdi/bitmap.h | 2 + libfreerdp/gdi/bitmap.c | 7 +- libfreerdp/gdi/gdi.c | 16 ++-- libfreerdp/gdi/graphics.c | 4 +- libfreerdp/gdi/test/TestGdiBitBlt.c | 120 +++++++++++++-------------- libfreerdp/gdi/test/TestGdiClip.c | 4 +- libfreerdp/gdi/test/TestGdiCreate.c | 4 +- libfreerdp/gdi/test/TestGdiEllipse.c | 6 +- libfreerdp/gdi/test/TestGdiLine.c | 56 ++++++------- 9 files changed, 113 insertions(+), 106 deletions(-) diff --git a/include/freerdp/gdi/bitmap.h b/include/freerdp/gdi/bitmap.h index e9d327ae0..d1165e0e6 100644 --- a/include/freerdp/gdi/bitmap.h +++ b/include/freerdp/gdi/bitmap.h @@ -39,6 +39,8 @@ FREERDP_API void gdi_SetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y, BYTE pixel); FREERDP_API void gdi_SetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y, UINT16 pixel); FREERDP_API void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel); FREERDP_API HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, + BYTE* data); +FREERDP_API HGDI_BITMAP gdi_CreateBitmapEx(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data, void (*fkt_free)(void*)); FREERDP_API HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight); FREERDP_API BOOL gdi_BitBlt(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); diff --git a/libfreerdp/gdi/bitmap.c b/libfreerdp/gdi/bitmap.c index b5cd25b73..03486d8f6 100644 --- a/libfreerdp/gdi/bitmap.c +++ b/libfreerdp/gdi/bitmap.c @@ -134,7 +134,12 @@ INLINE void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel) * @return new bitmap */ -HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data, +HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data) +{ + return gdi_CreateBitmapEx(nWidth, nHeight, cBitsPerPixel, data, _aligned_free); +} + +HGDI_BITMAP gdi_CreateBitmapEx(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data, void (*fkt_free)(void*)) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 4e4d70cbb..11d4ade42 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -645,7 +645,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8, hatched, backColor, foreColor, gdi->palette); - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data, _aligned_free); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); if (!hBmp) { _aligned_free(data); @@ -703,7 +703,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) brush->data, backColor, foreColor, gdi->palette); } - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data, _aligned_free); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); if (!hBmp) { _aligned_free(data); @@ -937,7 +937,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) brush->data, backColor, foreColor, gdi->palette); } - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data, _aligned_free); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); if (!hBmp) { _aligned_free(data); @@ -1102,8 +1102,8 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); - gdi_DeleteObject(gdi->image->bitmap); - gdi->image->bitmap = gdi_CreateBitmap(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); + gdi_DeleteObject((HGDIOBJECT)gdi->image->bitmap); + gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); gdi_SelectObject(gdi->image->hdc, (HGDIOBJECT) gdi->image->bitmap); gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); @@ -1125,8 +1125,8 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); - gdi_DeleteObject(gdi->image->bitmap); - gdi->image->bitmap = gdi_CreateBitmap(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); + gdi_DeleteObject((HGDIOBJECT)gdi->image->bitmap); + gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); gdi_SelectObject(gdi->image->hdc, (HGDIOBJECT) gdi->image->bitmap); gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); @@ -1193,7 +1193,7 @@ BOOL gdi_init_primary(rdpGdi* gdi) if (!gdi->primary_buffer) gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height); else - gdi->primary->bitmap = gdi_CreateBitmap(gdi->width, gdi->height, gdi->dstBpp, + gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstBpp, gdi->primary_buffer, NULL); if (!gdi->primary->bitmap) diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index 8acb95394..8e53c5280 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -92,7 +92,7 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int nWidth, int nHeight, int bpp, BYT freerdp_image_copy(pDstData, gdi->format, nDstStep, 0, 0, nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, gdi->palette); - bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstBpp, pDstData, _aligned_free); + bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstBpp, pDstData); return bitmap; } @@ -241,7 +241,7 @@ BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph) gdi_DeleteDC(gdi_glyph->hdc); return FALSE; } - gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data, _aligned_free); + gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data); if (!gdi_glyph->bitmap) { gdi_DeleteDC(gdi_glyph->hdc); diff --git a/libfreerdp/gdi/test/TestGdiBitBlt.c b/libfreerdp/gdi/test/TestGdiBitBlt.c index a45f5488f..d9f51d79a 100644 --- a/libfreerdp/gdi/test/TestGdiBitBlt.c +++ b/libfreerdp/gdi/test/TestGdiBitBlt.c @@ -589,64 +589,64 @@ int test_gdi_BitBlt_32bpp(void) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data, _aligned_free); + hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); @@ -1013,64 +1013,64 @@ int test_gdi_BitBlt_16bpp(void) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data, _aligned_free); + hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); @@ -1435,64 +1435,64 @@ int test_gdi_BitBlt_8bpp(void) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data, _aligned_free); + hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); diff --git a/libfreerdp/gdi/test/TestGdiClip.c b/libfreerdp/gdi/test/TestGdiClip.c index 61f897a5d..627d36919 100644 --- a/libfreerdp/gdi/test/TestGdiClip.c +++ b/libfreerdp/gdi/test/TestGdiClip.c @@ -28,7 +28,7 @@ int test_gdi_ClipCoords(void) hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; - bmp = gdi_CreateBitmap(1024, 768, 4, NULL, NULL); + bmp = gdi_CreateBitmapEx(1024, 768, 4, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); @@ -186,7 +186,7 @@ int test_gdi_InvalidateRegion(void) hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; - bmp = gdi_CreateBitmap(1024, 768, 4, NULL, NULL); + bmp = gdi_CreateBitmapEx(1024, 768, 4, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); diff --git a/libfreerdp/gdi/test/TestGdiCreate.c b/libfreerdp/gdi/test/TestGdiCreate.c index 16ef8ae5e..584d68362 100644 --- a/libfreerdp/gdi/test/TestGdiCreate.c +++ b/libfreerdp/gdi/test/TestGdiCreate.c @@ -83,7 +83,7 @@ int test_gdi_CreateBitmap(void) return -1; } - if (!(hBitmap = gdi_CreateBitmap(width, height, bpp, data, _aligned_free))) + if (!(hBitmap = gdi_CreateBitmap(width, height, bpp, data))) { printf("gdi_CreateBitmap failed\n"); return -1; @@ -199,7 +199,7 @@ int test_gdi_CreatePatternBrush(void) HGDI_BRUSH hBrush; HGDI_BITMAP hBitmap; - hBitmap = gdi_CreateBitmap(64, 64, 32, NULL, NULL); + hBitmap = gdi_CreateBitmap(64, 64, 32, NULL); hBrush = gdi_CreatePatternBrush(hBitmap); if (hBrush->objectType != GDIOBJECT_BRUSH) diff --git a/libfreerdp/gdi/test/TestGdiEllipse.c b/libfreerdp/gdi/test/TestGdiEllipse.c index be46d3591..7d3b107e6 100644 --- a/libfreerdp/gdi/test/TestGdiEllipse.c +++ b/libfreerdp/gdi/test/TestGdiEllipse.c @@ -120,13 +120,13 @@ int TestGdiEllipse(int argc, char* argv[]) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); /* Test Case 1: (0,0) -> (16, 16) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS)) diff --git a/libfreerdp/gdi/test/TestGdiLine.c b/libfreerdp/gdi/test/TestGdiLine.c index 87b1dff70..1ae64a030 100644 --- a/libfreerdp/gdi/test/TestGdiLine.c +++ b/libfreerdp/gdi/test/TestGdiLine.c @@ -667,88 +667,88 @@ int TestGdiLine(int argc, char* argv[]) clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_4, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_6, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_7, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_8, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_9, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_10, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_11, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_BLACK, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKNOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTCOPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_XORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTXORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOP, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGENOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_COPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_WHITE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data, _aligned_free); + hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); /* Test Case 1: (0,0) -> (15, 15) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS)) From 32a1406dc4f64542eff4606b7aa51719b70bd12a Mon Sep 17 00:00:00 2001 From: bjcollins Date: Tue, 4 Aug 2015 16:52:44 -0500 Subject: [PATCH 007/220] Return FREERDP_ERROR_AUTHENTICATION_FAILED on an authentication failure when using NLA with xfreerdp. --- client/X11/xf_client.c | 7 +++++-- client/X11/xfreerdp.h | 1 + include/freerdp/freerdp.h | 2 ++ libfreerdp/core/connection.c | 13 ++++++++++--- libfreerdp/core/freerdp.c | 12 ++++++++++++ libfreerdp/core/transport.c | 29 +++++++++++++++++++++++++++++ libfreerdp/core/transport.h | 2 ++ 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index a788ab2b1..31efca8b7 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1530,7 +1530,10 @@ void* xf_client_thread(void* param) if (instance->settings->AuthenticationOnly || !status) { WLog_ERR(TAG, "Authentication only, exit status %d", !status); - exit_code = XF_EXIT_CONN_FAILED; + if (freerdp_get_nla_failure(instance)) + exit_code = XF_EXIT_NLA_AUTH_FAILURE; + else + exit_code = XF_EXIT_CONN_FAILED; goto disconnect; } @@ -1641,7 +1644,7 @@ disconnect: DWORD xf_exit_code_from_disconnect_reason(DWORD reason) { - if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONN_FAILED)) + if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_NLA_AUTH_FAILURE)) return reason; /* License error set */ else if (reason >= 0x100 && reason <= 0x10A) diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index 5e1bdfab1..ec02fd00b 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -268,6 +268,7 @@ enum XF_EXIT_CODE XF_EXIT_MEMORY = 129, XF_EXIT_PROTOCOL = 130, XF_EXIT_CONN_FAILED = 131, + XF_EXIT_NLA_AUTH_FAILURE = 132, XF_EXIT_UNKNOWN = 255, }; diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index d2db002fa..b4c42547a 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -293,6 +293,8 @@ FREERDP_API const char* getChannelErrorDescription(rdpContext* context); FREERDP_API void setChannelError(rdpContext* context, UINT errorNum, char* description); FREERDP_API BOOL checkChannelErrorEvent(rdpContext* context); +FREERDP_API BOOL freerdp_get_nla_failure(freerdp* instance); + #ifdef __cplusplus } #endif diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 295ed9907..c84e0a2e0 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -299,9 +299,16 @@ BOOL rdp_client_connect(rdpRdp* rdp) { if (rdp_check_fds(rdp) < 0) { - if (!freerdp_get_last_error(rdp->context)) - freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); - + if (rdp->transport->nlaFailure == TRUE) + { + if (!freerdp_get_last_error(rdp->context)) + freerdp_set_last_error(rdp->context, FREERDP_ERROR_AUTHENTICATION_FAILED); + } + else + { + if (!freerdp_get_last_error(rdp->context)) + freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); + } return FALSE; } } diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index cce07fe3b..00a37b332 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -815,3 +815,15 @@ FREERDP_API void setChannelError(rdpContext* context, UINT errorNum, char* descr strncpy(context->errorDescription, description, 499); SetEvent(context->channelErrorEvent); } + +BOOL freerdp_get_nla_failure(freerdp* instance) +{ + rdpRdp* rdp; + + rdp = instance->context->rdp; + + if (transport_get_nla_failure(rdp->transport)) + return TRUE; + + return FALSE; +} diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index f20a5aa03..18b0b0d61 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -58,6 +58,17 @@ static void* transport_client_thread(void* arg); + +static void test_function(SSL* ssl, int where, int ret) +{ + rdpTransport *transport; + if ((where | SSL_CB_ALERT) && (ret == 561)) + { + transport = (rdpTransport *) SSL_get_app_data(ssl); + transport->nlaFailure = TRUE; + } +} + wStream* transport_send_stream_init(rdpTransport* transport, int size) { wStream* s; @@ -146,6 +157,9 @@ BOOL transport_connect_tls(rdpTransport* transport) transport->frontBio = tls->bio; + BIO_callback_ctrl(tls->bio, BIO_CTRL_SET_CALLBACK, (bio_info_cb*) test_function); + SSL_set_app_data(tls->ssl, transport); + if (!transport->frontBio) { WLog_ERR(TAG, "unable to prepend a filtering TLS bio"); @@ -186,6 +200,7 @@ BOOL transport_connect_nla(rdpTransport* transport) if (nla_client_begin(rdp->nla) < 0) { + transport->nlaFailure = TRUE; if (!freerdp_get_last_error(context)) freerdp_set_last_error(context, FREERDP_ERROR_AUTHENTICATION_FAILED); @@ -343,6 +358,7 @@ BOOL transport_accept_nla(rdpTransport* transport) if (nla_authenticate(transport->nla) < 0) { + transport->nlaFailure = TRUE; WLog_ERR(TAG, "client authentication failure"); transport_set_nla_mode(transport, FALSE); nla_free(transport->nla); @@ -989,6 +1005,7 @@ rdpTransport* transport_new(rdpContext* context) transport->blocking = TRUE; transport->GatewayEnabled = FALSE; transport->layer = TRANSPORT_LAYER_TCP; + transport->nlaFailure = FALSE; if (!InitializeCriticalSectionAndSpinCount(&(transport->ReadLock), 4000)) goto out_free_connectedEvent; @@ -1027,3 +1044,15 @@ void transport_free(rdpTransport* transport) free(transport); } + +BOOL transport_get_nla_failure(rdpTransport* transport) +{ + if (transport != NULL) + { + if (transport->nlaFailure == TRUE) + return TRUE; + } + + return FALSE; +} + diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index 1c6c9dcc0..43eabbee4 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -77,6 +77,7 @@ struct rdp_transport CRITICAL_SECTION ReadLock; CRITICAL_SECTION WriteLock; ULONG written; + BOOL nlaFailure; }; wStream* transport_send_stream_init(rdpTransport* transport, int size); @@ -109,5 +110,6 @@ int transport_receive_pool_return(rdpTransport* transport, wStream* pdu); rdpTransport* transport_new(rdpContext* context); void transport_free(rdpTransport* transport); +BOOL transport_get_nla_failure(rdpTransport* transport); #endif From 7fbc7e45a7275fdc6066e1beb2ac718c858125d8 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 3 Sep 2015 14:45:40 -0500 Subject: [PATCH 008/220] Clean up NLA authentication failure handling code 1. Make use of freerdp_set_last_error to set authentication failure without the helper functions 2. Rename ssl callback function 3. Break out AuthenticationOnly exit handling from bad connect handling --- client/X11/xf_client.c | 26 +++++++++++++++++++++----- client/X11/xfreerdp.h | 2 +- libfreerdp/core/freerdp.c | 12 ------------ libfreerdp/core/transport.c | 18 ++---------------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 31efca8b7..9a3bffa1e 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1526,12 +1526,28 @@ void* xf_client_thread(void* param) xfc = (xfContext*) instance->context; - /* Connection succeeded. --authonly ? */ - if (instance->settings->AuthenticationOnly || !status) + /* --authonly ? */ + if (instance->settings->AuthenticationOnly) { WLog_ERR(TAG, "Authentication only, exit status %d", !status); - if (freerdp_get_nla_failure(instance)) - exit_code = XF_EXIT_NLA_AUTH_FAILURE; + if (!status) + { + if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_AUTHENTICATION_FAILED) + exit_code = XF_EXIT_AUTH_FAILURE; + else + exit_code = XF_EXIT_CONN_FAILED; + } + else + exit_code = XF_EXIT_SUCCESS; + goto disconnect; + } + + if (!status) + { + WLog_ERR(TAG, "Freerdp connect error exit status %d", !status); + exit_code = freerdp_error_info(instance); + if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_AUTHENTICATION_FAILED) + exit_code = XF_EXIT_AUTH_FAILURE; else exit_code = XF_EXIT_CONN_FAILED; goto disconnect; @@ -1644,7 +1660,7 @@ disconnect: DWORD xf_exit_code_from_disconnect_reason(DWORD reason) { - if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_NLA_AUTH_FAILURE)) + if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_AUTH_FAILURE)) return reason; /* License error set */ else if (reason >= 0x100 && reason <= 0x10A) diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index ec02fd00b..af5f9505c 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -268,7 +268,7 @@ enum XF_EXIT_CODE XF_EXIT_MEMORY = 129, XF_EXIT_PROTOCOL = 130, XF_EXIT_CONN_FAILED = 131, - XF_EXIT_NLA_AUTH_FAILURE = 132, + XF_EXIT_AUTH_FAILURE = 132, XF_EXIT_UNKNOWN = 255, }; diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 00a37b332..cce07fe3b 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -815,15 +815,3 @@ FREERDP_API void setChannelError(rdpContext* context, UINT errorNum, char* descr strncpy(context->errorDescription, description, 499); SetEvent(context->channelErrorEvent); } - -BOOL freerdp_get_nla_failure(freerdp* instance) -{ - rdpRdp* rdp; - - rdp = instance->context->rdp; - - if (transport_get_nla_failure(rdp->transport)) - return TRUE; - - return FALSE; -} diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 18b0b0d61..adf8a93d7 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -59,7 +59,7 @@ static void* transport_client_thread(void* arg); -static void test_function(SSL* ssl, int where, int ret) +static void transport_ssl_cb(SSL* ssl, int where, int ret) { rdpTransport *transport; if ((where | SSL_CB_ALERT) && (ret == 561)) @@ -157,7 +157,7 @@ BOOL transport_connect_tls(rdpTransport* transport) transport->frontBio = tls->bio; - BIO_callback_ctrl(tls->bio, BIO_CTRL_SET_CALLBACK, (bio_info_cb*) test_function); + BIO_callback_ctrl(tls->bio, BIO_CTRL_SET_CALLBACK, (bio_info_cb*) transport_ssl_cb); SSL_set_app_data(tls->ssl, transport); if (!transport->frontBio) @@ -200,7 +200,6 @@ BOOL transport_connect_nla(rdpTransport* transport) if (nla_client_begin(rdp->nla) < 0) { - transport->nlaFailure = TRUE; if (!freerdp_get_last_error(context)) freerdp_set_last_error(context, FREERDP_ERROR_AUTHENTICATION_FAILED); @@ -358,7 +357,6 @@ BOOL transport_accept_nla(rdpTransport* transport) if (nla_authenticate(transport->nla) < 0) { - transport->nlaFailure = TRUE; WLog_ERR(TAG, "client authentication failure"); transport_set_nla_mode(transport, FALSE); nla_free(transport->nla); @@ -1044,15 +1042,3 @@ void transport_free(rdpTransport* transport) free(transport); } - -BOOL transport_get_nla_failure(rdpTransport* transport) -{ - if (transport != NULL) - { - if (transport->nlaFailure == TRUE) - return TRUE; - } - - return FALSE; -} - From be47c6f782c223aa2bbfc101805c0987848f754b Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 3 Sep 2015 15:27:58 -0500 Subject: [PATCH 009/220] Remove unused functions from initial code to handle NLA authentication failures. --- include/freerdp/freerdp.h | 2 -- libfreerdp/core/transport.h | 1 - 2 files changed, 3 deletions(-) diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index b4c42547a..d2db002fa 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -293,8 +293,6 @@ FREERDP_API const char* getChannelErrorDescription(rdpContext* context); FREERDP_API void setChannelError(rdpContext* context, UINT errorNum, char* description); FREERDP_API BOOL checkChannelErrorEvent(rdpContext* context); -FREERDP_API BOOL freerdp_get_nla_failure(freerdp* instance); - #ifdef __cplusplus } #endif diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index 43eabbee4..7a025c403 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -110,6 +110,5 @@ int transport_receive_pool_return(rdpTransport* transport, wStream* pdu); rdpTransport* transport_new(rdpContext* context); void transport_free(rdpTransport* transport); -BOOL transport_get_nla_failure(rdpTransport* transport); #endif From ee3b39d70f7b9104134aa65c1bfb4a9d527ef1f8 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Tue, 15 Sep 2015 14:17:13 -0500 Subject: [PATCH 010/220] Remove unnecessary variable to keep track of nlaFailure, instead just set the NLA authentication error in the callback where it is detected. --- libfreerdp/core/connection.c | 12 ++---------- libfreerdp/core/transport.c | 4 ++-- libfreerdp/core/transport.h | 1 - 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index c84e0a2e0..5047aadfe 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -299,16 +299,8 @@ BOOL rdp_client_connect(rdpRdp* rdp) { if (rdp_check_fds(rdp) < 0) { - if (rdp->transport->nlaFailure == TRUE) - { - if (!freerdp_get_last_error(rdp->context)) - freerdp_set_last_error(rdp->context, FREERDP_ERROR_AUTHENTICATION_FAILED); - } - else - { - if (!freerdp_get_last_error(rdp->context)) - freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); - } + if (!freerdp_get_last_error(rdp->context)) + freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); return FALSE; } } diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index adf8a93d7..60ee13d22 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -65,7 +65,8 @@ static void transport_ssl_cb(SSL* ssl, int where, int ret) if ((where | SSL_CB_ALERT) && (ret == 561)) { transport = (rdpTransport *) SSL_get_app_data(ssl); - transport->nlaFailure = TRUE; + if (!freerdp_get_last_error(transport->context)) + freerdp_set_last_error(transport->context, FREERDP_ERROR_AUTHENTICATION_FAILED); } } @@ -1003,7 +1004,6 @@ rdpTransport* transport_new(rdpContext* context) transport->blocking = TRUE; transport->GatewayEnabled = FALSE; transport->layer = TRANSPORT_LAYER_TCP; - transport->nlaFailure = FALSE; if (!InitializeCriticalSectionAndSpinCount(&(transport->ReadLock), 4000)) goto out_free_connectedEvent; diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index 7a025c403..1c6c9dcc0 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -77,7 +77,6 @@ struct rdp_transport CRITICAL_SECTION ReadLock; CRITICAL_SECTION WriteLock; ULONG written; - BOOL nlaFailure; }; wStream* transport_send_stream_init(rdpTransport* transport, int size); From e8704544f4425047fd47ea9c30eb2bec7d22ad41 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Tue, 7 Jul 2015 16:39:29 -0500 Subject: [PATCH 011/220] - Use decodebin2 instead of old decodebin - decodebin has issues - Use autovideosink - xvimagesink does not work with cards with no xv ports available and cant be used if wanted to use the fluendo hardware accelerated playback codec - Use autoaudiosink - let gstreamer choose best audio playback plugin - Catch when autosinks add known elements so that we can manipulate properties on them - Adjust caps of various media types to work better with gstreamer, some codecs are picky about having certain fields available - Remove unneeded plugins such as "ffmpegcolorspace" and "videoscale" - these do not work correctly with fluendo hardware accelerated playback codec - Name audio/video gstreamer elements better for easier debugging - Update gstreamer pipeline and element properties to handle playback better - Detect when valid timestamps are available for buffer from server and try to account for when they are not valid - Start time is much more reliable then end time from server for various media formats, so use it when possible to make decisions instead of end time - Do not rebuild gstreamer pipeline for a seek(very expensive), instead reset gstreamer time to 0 and maintain offset between real time and gstreamer time - Change buffer filled function back to a buffer level function, so that we can use buffer level to make better choices above gstreamer decoder in tsmf - Remove ack function from gstreamer, instead rely on ack thread to handle acks - Rework X11 gstreamer code to handle various videosinks which implement the XOverlayInterface and to keep more detailed information on the sub-window that is used for display - Add check to see if a decoder is available for telling the server the client various media types - Add in support for M4S2 and WMA1 media types - Fix flush message handling, they are for individual streams and not the entire presentation - Delay eos response to try to allow more time for buffers to be loaded into decoder, as we anticipate acks to server and the server will issue stop as soon as we ack eos. - Fix issue with geometry info being ignored when resent for new streams within existing presentation - Fixed volume level initialization issue when a stream is stopped and restarted - Attempt to sync video/audio streams...because we run two different gstreamer pipelines - they can enter pause/playing states at different times and are thus not synchronized. Attempt to adjust video buffer timestamps based on difference between audio/video running time to account for this difference. This logic accounts for a huge improvement in audio/video sync(ie. lip sync to words) --- channels/tsmf/client/gstreamer/tsmf_X11.c | 191 ++++++-- .../tsmf/client/gstreamer/tsmf_gstreamer.c | 411 +++++++++++++----- .../tsmf/client/gstreamer/tsmf_platform.h | 8 +- channels/tsmf/client/tsmf_codec.c | 29 +- channels/tsmf/client/tsmf_constants.h | 2 + channels/tsmf/client/tsmf_decoder.c | 61 ++- channels/tsmf/client/tsmf_decoder.h | 4 +- channels/tsmf/client/tsmf_ifman.c | 24 +- channels/tsmf/client/tsmf_main.c | 42 +- channels/tsmf/client/tsmf_main.h | 3 +- channels/tsmf/client/tsmf_media.c | 320 ++++++++++---- channels/tsmf/client/tsmf_media.h | 3 +- 12 files changed, 845 insertions(+), 253 deletions(-) diff --git a/channels/tsmf/client/gstreamer/tsmf_X11.c b/channels/tsmf/client/gstreamer/tsmf_X11.c index 0ea6a166f..dfeb26e86 100644 --- a/channels/tsmf/client/gstreamer/tsmf_X11.c +++ b/channels/tsmf/client/gstreamer/tsmf_X11.c @@ -61,6 +61,12 @@ struct X11Handle #endif Display *disp; Window subwin; + BOOL subwinMapped; + GstXOverlay *overlay; + int subwinWidth; + int subwinHeight; + int subwinX; + int subwinY; }; static const char* get_shm_id() @@ -70,13 +76,73 @@ static const char* get_shm_id() return shm_id; } +static GstBusSyncReply tsmf_platform_bus_sync_handler(GstBus *bus, GstMessage *message, gpointer user_data) +{ + struct X11Handle* hdl; + + TSMFGstreamerDecoder* decoder = user_data; + + if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) + return GST_BUS_PASS; + + if (!gst_structure_has_name (message->structure, "prepare-xwindow-id")) + return GST_BUS_PASS; + + hdl = (struct X11Handle*) decoder->platform; + + if (hdl->subwin) + { + hdl->overlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message)); + +#if GST_VERSION_MAJOR > 0 + gst_video_overlay_set_window_handle(hdl->overlay, hdl->subwin); +#else + gst_x_overlay_set_window_handle(hdl->overlay, hdl->subwin); +#endif +#if GST_VERSION_MAJOR > 0 + gst_video_overlay_handle_events(hdl->overlay, TRUE); +#else + gst_x_overlay_handle_events(hdl->overlay, TRUE); +#endif + + if (hdl->subwinWidth != -1 && hdl->subwinHeight != -1 && hdl->subwinX != -1 && hdl->subwinY != -1) + { +#if GST_VERSION_MAJOR > 0 + + if (!gst_video_overlay_set_render_rectangle(hdl->overlay, 0, 0, hdl->swubwinWidth, hdl->subwinHeight)) + { + WLog_ERR(TAG, "Could not resize overlay!"); + } + + gst_video_overlay_expose(hdl->overlay); +#else + if (!gst_x_overlay_set_render_rectangle(hdl->overlay, 0, 0, hdl->subwinWidth, hdl->subwinHeight)) + { + WLog_ERR(TAG, "Could not resize overlay!"); + } + + gst_x_overlay_expose(hdl->overlay); +#endif + XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth, hdl->subwinHeight); + XSync(hdl->disp, FALSE); + } + } else { + g_warning ("Window was not available before retrieving the overlay!"); + } + + gst_message_unref (message); + + return GST_BUS_DROP; +} + const char* tsmf_platform_get_video_sink(void) { - return "xvimagesink"; + return "autovideosink"; } const char* tsmf_platform_get_audio_sink(void) { + //return "alsasink"; return "autoaudiosink"; } @@ -119,6 +185,12 @@ int tsmf_platform_create(TSMFGstreamerDecoder* decoder) return -4; } + hdl->subwinMapped = FALSE; + hdl->subwinX = -1; + hdl->subwinY = -1; + hdl->subwinWidth = -1; + hdl->subwinHeight = -1; + return 0; } @@ -147,12 +219,16 @@ int tsmf_platform_register_handler(TSMFGstreamerDecoder* decoder) bus = gst_pipeline_get_bus(GST_PIPELINE(decoder->pipe)); + gst_bus_set_sync_handler (bus, (GstBusSyncHandler) tsmf_platform_bus_sync_handler, decoder); + if (!bus) { WLog_ERR(TAG, "gst_pipeline_get_bus failed!"); return 1; } + gst_object_unref (bus); + return 0; } @@ -189,12 +265,6 @@ int tsmf_window_create(TSMFGstreamerDecoder* decoder) } else { -#if GST_VERSION_MAJOR > 0 - GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(decoder->outsink); -#else - GstXOverlay *overlay = GST_X_OVERLAY(decoder->outsink); -#endif - if (!decoder) return -1; @@ -205,38 +275,28 @@ int tsmf_window_create(TSMFGstreamerDecoder* decoder) if (!hdl->subwin) { - int event, error; hdl->subwin = XCreateSimpleWindow(hdl->disp, *(int *)hdl->xfwin, 0, 0, 1, 1, 0, 0, 0); if (!hdl->subwin) { WLog_ERR(TAG, "Could not create subwindow!"); } - - XMapWindow(hdl->disp, hdl->subwin); - XSync(hdl->disp, FALSE); -#if GST_VERSION_MAJOR > 0 - gst_video_overlay_set_window_handle(overlay, hdl->subwin); -#else - gst_x_overlay_set_window_handle(overlay, hdl->subwin); -#endif - decoder->ready = TRUE; -#if defined(WITH_XEXT) - hdl->has_shape = XShapeQueryExtension(hdl->disp, &event, &error); -#endif } -#if GST_VERSION_MAJOR > 0 - gst_video_overlay_handle_events(overlay, TRUE); -#else - gst_x_overlay_handle_events(overlay, TRUE); + tsmf_window_map(decoder); + + decoder->ready = TRUE; +#if defined(WITH_XEXT) + int event, error; + hdl->has_shape = XShapeQueryExtension(hdl->disp, &event, &error); #endif - return 0; } + + return 0; } int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, - int height, int nr_rects, RDP_RECT *rects) + int height, int nr_rects, RDP_RECT *rects) { struct X11Handle* hdl; @@ -259,26 +319,33 @@ int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, hdl = (struct X11Handle*) decoder->platform; DEBUG_TSMF("resize: x=%d, y=%d, w=%d, h=%d", x, y, width, height); + if (hdl->overlay) + { #if GST_VERSION_MAJOR > 0 - if (!gst_video_overlay_set_render_rectangle(overlay, 0, 0, width, height)) - { - WLog_ERR(TAG, "Could not resize overlay!"); - } + if (!gst_video_overlay_set_render_rectangle(overlay, 0, 0, width, height)) + { + WLog_ERR(TAG, "Could not resize overlay!"); + } - gst_video_overlay_expose(overlay); + gst_video_overlay_expose(overlay); #else - if (!gst_x_overlay_set_render_rectangle(overlay, 0, 0, width, height)) - { - WLog_ERR(TAG, "Could not resize overlay!"); - } + if (!gst_x_overlay_set_render_rectangle(overlay, 0, 0, width, height)) + { + WLog_ERR(TAG, "Could not resize overlay!"); + } - gst_x_overlay_expose(overlay); + gst_x_overlay_expose(overlay); #endif + } if (hdl->subwin) { - XMoveResizeWindow(hdl->disp, hdl->subwin, x, y, width, height); + hdl->subwinX = x; + hdl->subwinY = y; + hdl->subwinWidth = width; + hdl->subwinHeight = height; + XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth, hdl->subwinHeight); #if defined(WITH_XEXT) if (hdl->has_shape) @@ -299,7 +366,6 @@ int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, XShapeCombineRectangles(hdl->disp, hdl->subwin, ShapeBounding, x, y, xrects, nr_rects, ShapeSet, 0); free(xrects); } - #endif XSync(hdl->disp, FALSE); } @@ -323,6 +389,49 @@ int tsmf_window_resume(TSMFGstreamerDecoder* decoder) return 0; } +int tsmf_window_map(TSMFGstreamerDecoder* decoder) +{ + struct X11Handle* hdl; + if (!decoder) + return -1; + + hdl = (struct X11Handle*) decoder->platform; + + // Only need to map the window if it is not currently mapped + if ((hdl->subwin) && (!hdl->subwinMapped)) + { + XLockDisplay(hdl->disp); + XMapWindow(hdl->disp, hdl->subwin); + hdl->subwinMapped = TRUE; + XSync(hdl->disp, FALSE); + XUnlockDisplay(hdl->disp); + } + + return 0; +} + +int tsmf_window_unmap(TSMFGstreamerDecoder* decoder) +{ + struct X11Handle* hdl; + if (!decoder) + return -1; + + hdl = (struct X11Handle*) decoder->platform; + + // only need to unmap window if it is currently mapped + if ((hdl->subwin) && (hdl->subwinMapped)) + { + XLockDisplay(hdl->disp); + XUnmapWindow(hdl->disp, hdl->subwin); + hdl->subwinMapped = FALSE; + XSync(hdl->disp, FALSE); + XUnlockDisplay(hdl->disp); + } + + return 0; +} + + int tsmf_window_destroy(TSMFGstreamerDecoder* decoder) { struct X11Handle* hdl; @@ -345,7 +454,13 @@ int tsmf_window_destroy(TSMFGstreamerDecoder* decoder) XSync(hdl->disp, FALSE); } + hdl->overlay = NULL; hdl->subwin = 0; + hdl->subwinMapped = FALSE; + hdl->subwinX = -1; + hdl->subwinY = -1; + hdl->subwinWidth = -1; + hdl->subwinHeight = -1; return 0; } diff --git a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c index fac74c12a..f848346a1 100644 --- a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c +++ b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c @@ -45,10 +45,14 @@ #include #endif +// 1 second +#define SEEK_TOLERANCE 10000000 + static BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder); static void tsmf_gstreamer_clean_up(TSMFGstreamerDecoder* mdecoder); static int tsmf_gstreamer_pipeline_set_state(TSMFGstreamerDecoder* mdecoder, GstState desired_state); +static BOOL tsmf_gstreamer_buffer_level(ITSMFDecoder* decoder); const char* get_type(TSMFGstreamerDecoder* mdecoder) { @@ -57,8 +61,33 @@ const char* get_type(TSMFGstreamerDecoder* mdecoder) if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) return "VIDEO"; - else + else if (mdecoder->media_type == TSMF_MAJOR_TYPE_AUDIO) return "AUDIO"; + else + return "UNKNOWN"; +} + +static void cb_child_added(GstChildProxy *child_proxy, GObject *object, TSMFGstreamerDecoder* mdecoder) +{ + DEBUG_TSMF("NAME: %s", G_OBJECT_TYPE_NAME(object)); + + if (!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstXvImageSink") || !g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstXImageSink") || !g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstFluVAAutoSink")) + { + gst_base_sink_set_max_lateness((GstBaseSink *) object, 10000000); //nanoseconds + g_object_set(G_OBJECT(object), "sync", TRUE, NULL); //synchronize on the clock + g_object_set(G_OBJECT(object), "async", TRUE, NULL); //no async state changes - doc says not to do for streams synced to clock + } + + else if (!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstAlsaSink") || !g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstPulseSink")) + { + gst_base_sink_set_max_lateness((GstBaseSink *) object, 10000000); //nanoseconds + g_object_set(G_OBJECT(object), "slave-method", 1, NULL); //DEFAULT + g_object_set(G_OBJECT(object), "buffer-time", (gint64) 20000, NULL); //microseconds + g_object_set(G_OBJECT(object), "drift-tolerance", (gint64) 20000, NULL); //microseconds + g_object_set(G_OBJECT(object), "latency-time", (gint64) 10000, NULL); //microseconds + g_object_set(G_OBJECT(object), "sync", TRUE, NULL); //synchronize on the clock + g_object_set(G_OBJECT(object), "async", TRUE, NULL); //no async state changes - doc says not to do for streams synced to clock + } } static void tsmf_gstreamer_enough_data(GstAppSrc *src, gpointer user_data) @@ -81,20 +110,34 @@ static gboolean tsmf_gstreamer_seek_data(GstAppSrc *src, guint64 offset, gpointe (void) mdecoder; DEBUG_TSMF("%s offset=%llu", get_type(mdecoder), offset); - if (!mdecoder->paused) - tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PAUSED); - - gst_app_src_end_of_stream((GstAppSrc*) mdecoder->src); - - if (!mdecoder->paused) - tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING); - - if (mdecoder->sync_cb) - mdecoder->sync_cb(mdecoder->stream); - return TRUE; } +static void tsmf_gstreamer_change_volume(ITSMFDecoder* decoder, UINT32 newVolume, UINT32 muted) +{ + TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; + + if (!mdecoder || !mdecoder->pipe) + return; + + if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) + return; + + mdecoder->gstMuted = (BOOL) muted; + DEBUG_TSMF("mute=[%d]", mdecoder->gstMuted); + mdecoder->gstVolume = (double) newVolume / (double) 10000; + DEBUG_TSMF("gst_new_vol=[%f]", mdecoder->gstVolume); + + if (!mdecoder->volume) + return; + + if (!G_IS_OBJECT(mdecoder->volume)) + return; + + g_object_set(mdecoder->volume, "mute", mdecoder->gstMuted, NULL); + g_object_set(mdecoder->volume, "volume", mdecoder->gstVolume, NULL); +} + #ifdef __OpenBSD__ static inline GstClockTime tsmf_gstreamer_timestamp_ms_to_gst(UINT64 ms_timestamp) #else @@ -209,10 +252,13 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m { case TSMF_SUB_TYPE_WVC1: mdecoder->gst_caps = gst_caps_new_simple("video/x-wmv", + "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 3, - "format", G_TYPE_STRING, "WVC1", + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'V', 'C', '1'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, NULL); break; case TSMF_SUB_TYPE_MP4S: @@ -221,6 +267,8 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '2'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; case TSMF_SUB_TYPE_MP42: @@ -229,15 +277,29 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '2'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; case TSMF_SUB_TYPE_MP43: mdecoder->gst_caps = gst_caps_new_simple("video/x-msmpeg", + "msmpegversion", G_TYPE_INT, 43, "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '3'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; + case TSMF_SUB_TYPE_M4S2: + mdecoder->gst_caps = gst_caps_new_simple ("video/mpeg", + "mpegversion", G_TYPE_INT, 4, + "width", G_TYPE_INT, media_type->Width, + "height", G_TYPE_INT, media_type->Height, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', '4', 'S', '2'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, + NULL); + break; case TSMF_SUB_TYPE_WMA9: mdecoder->gst_caps = gst_caps_new_simple("audio/x-wma", "wmaversion", G_TYPE_INT, 3, @@ -249,6 +311,17 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "block_align", G_TYPE_INT, media_type->BlockAlign, NULL); break; + case TSMF_SUB_TYPE_WMA1: + mdecoder->gst_caps = gst_caps_new_simple ("audio/x-wma", + "wmaversion", G_TYPE_INT, 1, + "rate", G_TYPE_INT, media_type->SamplesPerSecond.Numerator, + "channels", G_TYPE_INT, media_type->Channels, + "bitrate", G_TYPE_INT, media_type->BitRate, + "depth", G_TYPE_INT, media_type->BitsPerSample, + "width", G_TYPE_INT, media_type->BitsPerSample, + "block_align", G_TYPE_INT, media_type->BlockAlign, + NULL); + break; case TSMF_SUB_TYPE_WMA2: mdecoder->gst_caps = gst_caps_new_simple("audio/x-wma", "wmaversion", G_TYPE_INT, 2, @@ -274,6 +347,8 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 1, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'M', 'V', '1'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; case TSMF_SUB_TYPE_WMV2: @@ -281,6 +356,9 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 2, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'M', 'V', '2'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, NULL); break; case TSMF_SUB_TYPE_WMV3: @@ -289,6 +367,9 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 3, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'M', 'V', '3'), + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, NULL); break; case TSMF_SUB_TYPE_AVC1: @@ -296,6 +377,10 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m mdecoder->gst_caps = gst_caps_new_simple("video/x-h264", "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, + "stream-format", G_TYPE_STRING, "byte-stream", + "alignment", G_TYPE_STRING, "nal", NULL); break; case TSMF_SUB_TYPE_AC3: @@ -319,6 +404,8 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "rate", G_TYPE_INT, media_type->SamplesPerSecond.Numerator, "channels", G_TYPE_INT, media_type->Channels, "mpegversion", G_TYPE_INT, 4, + "framed", G_TYPE_BOOLEAN, TRUE, + "stream-format", G_TYPE_STRING, "raw", NULL); break; case TSMF_SUB_TYPE_MP1A: @@ -347,6 +434,7 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "format", G_TYPE_STRING, "YUY2", "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, + "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); #endif break; @@ -358,11 +446,15 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m break; case TSMF_SUB_TYPE_MP2A: mdecoder->gst_caps = gst_caps_new_simple("audio/mpeg", - "mpegversion", G_TYPE_INT, 2, + "mpegversion", G_TYPE_INT, 1, "rate", G_TYPE_INT, media_type->SamplesPerSecond.Numerator, "channels", G_TYPE_INT, media_type->Channels, NULL); break; + case TSMF_SUB_TYPE_FLAC: + mdecoder->gst_caps = gst_caps_new_simple("audio/x-flac", + NULL); + break; default: WLog_ERR(TAG, "unknown format:(%d).", media_type->SubType); return FALSE; @@ -404,17 +496,18 @@ void tsmf_gstreamer_clean_up(TSMFGstreamerDecoder* mdecoder) gst_object_unref(mdecoder->pipe); } - tsmf_window_destroy(mdecoder); mdecoder->ready = FALSE; + mdecoder->paused = FALSE; + mdecoder->pipe = NULL; mdecoder->src = NULL; + mdecoder->queue = NULL; } BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) { - const char* appsrc = "appsrc name=source ! decodebin name=decoder !"; - const char* video = "autovideoconvert ! videoscale !"; - const char* audio = "audioconvert ! audiorate ! audioresample ! volume name=audiovolume !"; + const char* video = "appsrc name=videosource ! queue2 name=videoqueue ! decodebin2 name=videodecoder !"; + const char* audio = "appsrc name=audiosource ! queue2 name=audioqueue ! decodebin2 name=audiodecoder ! audioconvert ! audiorate ! audioresample ! volume name=audiovolume !"; char pipeline[1024]; if (!mdecoder) @@ -424,9 +517,9 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) * The only fixed elements necessary are appsrc and the volume element for audio streams. * The rest could easily be provided in gstreamer pipeline notation from command line. */ if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - sprintf_s(pipeline, sizeof(pipeline), "%s %s %s name=outsink", appsrc, video, tsmf_platform_get_video_sink()); + sprintf_s(pipeline, sizeof(pipeline), "%s %s name=videosink", video, tsmf_platform_get_video_sink()); else - sprintf_s(pipeline, sizeof(pipeline), "%s %s %s name=outsink", appsrc, audio, tsmf_platform_get_audio_sink()); + sprintf_s(pipeline, sizeof(pipeline), "%s %s name=audiosink", audio, tsmf_platform_get_audio_sink()); DEBUG_TSMF("pipeline=%s", pipeline); mdecoder->pipe = gst_parse_launch(pipeline, NULL); @@ -437,7 +530,10 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) return FALSE; } - mdecoder->src = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "source"); + if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) + mdecoder->src = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "videosource"); + else + mdecoder->src = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audiosource"); if (!mdecoder->src) { @@ -445,7 +541,21 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) return FALSE; } - mdecoder->outsink = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "outsink"); + if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) + mdecoder->queue = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "videoqueue"); + else + mdecoder->queue = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audioqueue"); + + if (!mdecoder->queue) + { + WLog_ERR(TAG, "Failed to get queue"); + return FALSE; + } + + if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) + mdecoder->outsink = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "videosink"); + else + mdecoder->outsink = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audiosink"); if (!mdecoder->outsink) { @@ -453,7 +563,9 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) return FALSE; } - if (mdecoder->media_type != TSMF_MAJOR_TYPE_VIDEO) + g_signal_connect(mdecoder->outsink, "child-added", G_CALLBACK(cb_child_added), mdecoder); + + if (mdecoder->media_type == TSMF_MAJOR_TYPE_AUDIO) { mdecoder->volume = gst_bin_get_by_name(GST_BIN(mdecoder->pipe), "audiovolume"); @@ -462,6 +574,8 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) WLog_ERR(TAG, "Failed to get volume"); return FALSE; } + + tsmf_gstreamer_change_volume((ITSMFDecoder*)mdecoder, mdecoder->gstVolume*((double) 10000), mdecoder->gstMuted); } tsmf_platform_register_handler(mdecoder); @@ -473,16 +587,45 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) tsmf_gstreamer_seek_data }; g_object_set(mdecoder->src, "format", GST_FORMAT_TIME, NULL); - g_object_set(mdecoder->src, "is-live", TRUE, NULL); - g_object_set(mdecoder->src, "block", TRUE, NULL); + g_object_set(mdecoder->src, "is-live", FALSE, NULL); + g_object_set(mdecoder->src, "block", FALSE, NULL); + g_object_set(mdecoder->src, "blocksize", 1024, NULL); gst_app_src_set_caps((GstAppSrc *) mdecoder->src, mdecoder->gst_caps); gst_app_src_set_callbacks((GstAppSrc *)mdecoder->src, &callbacks, mdecoder, NULL); gst_app_src_set_stream_type((GstAppSrc *) mdecoder->src, GST_APP_STREAM_TYPE_SEEKABLE); + gst_app_src_set_latency((GstAppSrc *) mdecoder->src, 0, -1); + gst_app_src_set_max_bytes((GstAppSrc *) mdecoder->src, (guint64) 0);//unlimited + g_object_set(G_OBJECT(mdecoder->queue), "use-buffering", FALSE, NULL); + g_object_set(G_OBJECT(mdecoder->queue), "use-rate-estimate", FALSE, NULL); + g_object_set(G_OBJECT(mdecoder->queue), "max-size-buffers", 0, NULL); + g_object_set(G_OBJECT(mdecoder->queue), "max-size-bytes", 0, NULL); + g_object_set(G_OBJECT(mdecoder->queue), "max-size-time", (guint64) 0, NULL); + + // Only set these properties if not an autosink, otherwise we will set properties when real sinks are added + if (!g_strcmp0(G_OBJECT_TYPE_NAME(mdecoder->outsink), "GstAutoVideoSink") && !g_strcmp0(G_OBJECT_TYPE_NAME(mdecoder->outsink), "GstAutoAudioSink")) + { + if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) + { + gst_base_sink_set_max_lateness((GstBaseSink *) mdecoder->outsink, 10000000); //nanoseconds + } + else + { + gst_base_sink_set_max_lateness((GstBaseSink *) mdecoder->outsink, 10000000); //nanoseconds + g_object_set(G_OBJECT(mdecoder->outsink), "buffer-time", (gint64) 20000, NULL); //microseconds + g_object_set(G_OBJECT(mdecoder->outsink), "drift-tolerance", (gint64) 20000, NULL); //microseconds + g_object_set(G_OBJECT(mdecoder->outsink), "latency-time", (gint64) 10000, NULL); //microseconds + g_object_set(G_OBJECT(mdecoder->outsink), "slave-method", 1, NULL); + } + g_object_set(G_OBJECT(mdecoder->outsink), "sync", TRUE, NULL); //synchronize on the clock + g_object_set(G_OBJECT(mdecoder->outsink), "async", TRUE, NULL); //no async state changes + } + tsmf_window_create(mdecoder); tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_READY); tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING); mdecoder->pipeline_start_time_valid = 0; mdecoder->shutdown = 0; + mdecoder->paused = FALSE; GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(mdecoder->pipe), GST_DEBUG_GRAPH_SHOW_ALL, get_type(mdecoder)); @@ -495,7 +638,7 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN GstBuffer *gst_buf; TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; UINT64 sample_time = tsmf_gstreamer_timestamp_ms_to_gst(start_time); - UINT64 sample_duration = tsmf_gstreamer_timestamp_ms_to_gst(duration); + BOOL useTimestamps = TRUE; if (!mdecoder) { @@ -509,9 +652,15 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN * We don't expect to block here often, since the pipeline should * have more than enough buffering. */ - DEBUG_TSMF("%s. Start:(%llu) End:(%llu) Duration:(%llu) Last End:(%llu)", - get_type(mdecoder), start_time, end_time, duration, - mdecoder->last_sample_end_time); + DEBUG_TSMF("%s. Start:(%d) End:(%d) Duration:(%d) Last Start:(%d)", + get_type(mdecoder), (int)start_time, (int)end_time, (int)duration, + (int)mdecoder->last_sample_start_time); + + if (mdecoder->shutdown) + { + WLog_ERR(TAG, "decodeEx called on shutdown decoder"); + return TRUE; + } if (mdecoder->gst_caps == NULL) { @@ -519,6 +668,9 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN return FALSE; } + if (!mdecoder->pipe) + tsmf_gstreamer_pipeline_build(mdecoder); + if (!mdecoder->src) { WLog_ERR(TAG, "failed to construct pipeline correctly. Unable to push buffer to source element."); @@ -533,53 +685,108 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN return FALSE; } + // Relative timestamping will sometimes be set to 0 + // so we ignore these timestamps just to be safe(bit 8) + if (extensions & 0x00000080) + { + DEBUG_TSMF("Ignoring the timestamps - relative - bit 8"); + useTimestamps = FALSE; + } + + //If no timestamps exist then we dont want to look at the timestamp values (bit 7) + if (extensions & 0x00000040) + { + DEBUG_TSMF("Ignoring the timestamps - none - bit 7"); + useTimestamps = FALSE; + } + + // If performing a seek + if (mdecoder->seeking) + { + mdecoder->seeking = FALSE; + tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PAUSED); + mdecoder->pipeline_start_time_valid = 0; + } + if (mdecoder->pipeline_start_time_valid) { - long long diff = start_time; - diff -= mdecoder->last_sample_end_time; + // Adjusted the condition for a seek to be based on start time only + // WMV1 and WMV2 files in particular have bad end time and duration values + // there seems to be no real side effects of just using the start time instead + UINT64 minTime = mdecoder->last_sample_start_time - (UINT64) SEEK_TOLERANCE; + UINT64 maxTime = mdecoder->last_sample_start_time + (UINT64) SEEK_TOLERANCE; - if (diff < 0) - diff *= -1; + // Make sure the minTime stops at 0 , should we be at the beginning of the stream + if (mdecoder->last_sample_start_time < (UINT64) SEEK_TOLERANCE) + minTime = 0; - /* The pipe is initialized, but there is a discontinuity. - * Seek to the start position... */ - if (diff > 50) + // If the start_time is valid and different from the previous start time by more than the seek tolerance, then we have a seek condition + if (((start_time > maxTime) || (start_time < minTime)) && useTimestamps) { - DEBUG_TSMF("%s seeking to %lld", get_type(mdecoder), start_time); + DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%d] > last_sample_start_time=[%d] OR ", (int)start_time, (int)mdecoder->last_sample_start_time); + DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%d] < last_sample_start_time=[%d] with", (int)start_time, (int)mdecoder->last_sample_start_time); + DEBUG_TSMF("tsmf_gstreamer_decodeEX: a tolerance of more than [%d] from the last sample", (int) SEEK_TOLERANCE); - if (!gst_element_seek(mdecoder->pipe, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, - GST_SEEK_TYPE_SET, sample_time, - GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) - { - WLog_ERR(TAG, "seek failed"); - } + mdecoder->seeking = TRUE; - mdecoder->pipeline_start_time_valid = 0; + // since we cant make the gstreamer pipeline jump to the new start time after a seek - we just maintain + // a offset between realtime and gstreamer time + mdecoder->seek_offset = start_time; } } else { - DEBUG_TSMF("%s start time %llu", get_type(mdecoder), sample_time); + DEBUG_TSMF("%s start time %d", get_type(mdecoder), start_time); + // Always set base/start time to 0. Will use seek offset to translate real buffer times + // back to 0. This allows the video to be started from anywhere and the ability to handle seeks + // without rebuilding the pipeline, etc. since that is costly + gst_element_set_base_time(mdecoder->pipe, tsmf_gstreamer_timestamp_ms_to_gst(0)); + gst_element_set_start_time(mdecoder->pipe, tsmf_gstreamer_timestamp_ms_to_gst(0)); mdecoder->pipeline_start_time_valid = 1; + + // Set the seek offset if buffer has valid timestamps. + if (useTimestamps) + mdecoder->seek_offset = start_time; + + if (!gst_element_seek(mdecoder->pipe, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, + GST_SEEK_TYPE_SET, 0, + GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) + { + WLog_ERR(TAG, "seek failed"); + } } #if GST_VERSION_MAJOR > 0 - GST_BUFFER_PTS(gst_buf) = sample_time; + if (useTimestamps) + GST_BUFFER_PTS(gst_buf) = sample_time - tsmf_gstreamer_timestamp_ms_to_gst(mdecoder->seek_offset); + else + GST_BUFFER_PTS(gst_buf) = GST_CLOCK_TIME_NONE; #else - GST_BUFFER_TIMESTAMP(gst_buf) = sample_time; + if (useTimestamps) + GST_BUFFER_TIMESTAMP(gst_buf) = sample_time - tsmf_gstreamer_timestamp_ms_to_gst(mdecoder->seek_offset); + else + GST_BUFFER_TIMESTAMP(gst_buf) = GST_CLOCK_TIME_NONE; #endif - GST_BUFFER_DURATION(gst_buf) = sample_duration; + GST_BUFFER_DURATION(gst_buf) = GST_CLOCK_TIME_NONE; + GST_BUFFER_OFFSET(gst_buf) = GST_BUFFER_OFFSET_NONE; + gst_buffer_set_caps(gst_buf, mdecoder->gst_caps); gst_app_src_push_buffer(GST_APP_SRC(mdecoder->src), gst_buf); if (mdecoder->ack_cb) - mdecoder->ack_cb(mdecoder->stream, TRUE); + mdecoder->ack_cb(mdecoder->stream, FALSE); - mdecoder->last_sample_end_time = end_time; - - if (GST_STATE(mdecoder->pipe) != GST_STATE_PLAYING) + // Should only update the last timestamps if the current ones are valid + if (useTimestamps) { - DEBUG_TSMF("%s: state=%s", get_type(mdecoder), gst_element_state_get_name(GST_STATE(mdecoder->pipe))); + mdecoder->last_sample_start_time = start_time; + mdecoder->last_sample_end_time = end_time; + } + if (mdecoder->pipe && (GST_STATE(mdecoder->pipe) != GST_STATE_PLAYING)) + { + DEBUG_TSMF("%s: state=%s", get_type(mdecoder), gst_element_state_get_name(GST_STATE(mdecoder->pipe))); + + DEBUG_TSMF("Paused: %i Shutdown: %i Ready: %i", mdecoder->paused, mdecoder->shutdown, mdecoder->ready); if (!mdecoder->paused && !mdecoder->shutdown && mdecoder->ready) tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING); } @@ -587,32 +794,6 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN return TRUE; } -static BOOL tsmf_gstreamer_change_volume(ITSMFDecoder* decoder, UINT32 newVolume, UINT32 muted) -{ - TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; - - if (!mdecoder || !mdecoder->pipe) - return FALSE; - - if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - return TRUE; - - mdecoder->gstMuted = (BOOL) muted; - DEBUG_TSMF("mute=[%d]", mdecoder->gstMuted); - mdecoder->gstVolume = (double) newVolume / (double) 10000; - DEBUG_TSMF("gst_new_vol=[%f]", mdecoder->gstVolume); - - if (!mdecoder->volume) - return FALSE; - - if (!G_IS_OBJECT(mdecoder->volume)) - return FALSE; - - g_object_set(mdecoder->volume, "mute", mdecoder->gstMuted, NULL); - g_object_set(mdecoder->volume, "volume", mdecoder->gstVolume, NULL); - return TRUE; -} - static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg control_msg, UINT32 *arg) { TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; @@ -626,15 +807,13 @@ static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg contro if (mdecoder->paused) { - WLog_ERR(TAG, "%s: Ignoring control PAUSE, already received!", get_type(mdecoder)); + WLog_ERR(TAG, "%s: Ignoring Control_Pause, already received!", get_type(mdecoder)); return TRUE; } tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PAUSED); + mdecoder->shutdown = 0; mdecoder->paused = TRUE; - - if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - tsmf_window_pause(mdecoder); } else if (control_msg == Control_Resume) { @@ -642,17 +821,12 @@ static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg contro if (!mdecoder->paused && !mdecoder->shutdown) { - WLog_ERR(TAG, "%s: Ignoring control RESUME, already received!", get_type(mdecoder)); + WLog_ERR(TAG, "%s: Ignoring Control_Resume, already received!", get_type(mdecoder)); return TRUE; } + mdecoder->shutdown = 0; mdecoder->paused = FALSE; - mdecoder->shutdown = FALSE; - - if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - tsmf_window_resume(mdecoder); - - tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING); } else if (control_msg == Control_Stop) { @@ -660,18 +834,29 @@ static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg contro if (mdecoder->shutdown) { - WLog_ERR(TAG, "%s: Ignoring control STOP, already received!", get_type(mdecoder)); + WLog_ERR(TAG, "%s: Ignoring Control_Stop, already received!", get_type(mdecoder)); return TRUE; } - mdecoder->shutdown = TRUE; /* Reset stamps, flush buffers, etc */ - tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PAUSED); + if (mdecoder->pipe) + { + tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_NULL); + tsmf_window_destroy(mdecoder); + tsmf_gstreamer_clean_up(mdecoder); + } + mdecoder->seek_offset = 0; + mdecoder->pipeline_start_time_valid = 0; + mdecoder->shutdown = 1; + } + else if (control_msg == Control_Restart) + { + DEBUG_TSMF("Control_Restart %s", get_type(mdecoder)); + mdecoder->shutdown = 0; + mdecoder->paused = FALSE; - if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - tsmf_window_pause(mdecoder); - - gst_app_src_end_of_stream((GstAppSrc *)mdecoder->src); + if (mdecoder->pipeline_start_time_valid) + tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING); } else WLog_ERR(TAG, "Unknown control message %08x", control_msg); @@ -679,7 +864,7 @@ static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg contro return TRUE; } -static BOOL tsmf_gstreamer_buffer_filled(ITSMFDecoder* decoder) +static BOOL tsmf_gstreamer_buffer_level(ITSMFDecoder* decoder) { TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; DEBUG_TSMF(""); @@ -687,10 +872,13 @@ static BOOL tsmf_gstreamer_buffer_filled(ITSMFDecoder* decoder) if (!mdecoder) return FALSE; - guint buff_max = 0; guint clbuff = 0; - DEBUG_TSMF("%s buffer fill %u/%u", get_type(mdecoder), clbuff, buff_max); - return clbuff >= buff_max ? TRUE : FALSE; + + if (G_IS_OBJECT(mdecoder->queue)) + g_object_get(mdecoder->queue, "current-level-buffers", &clbuff, NULL); + + DEBUG_TSMF("%s buffer level %u", get_type(mdecoder), clbuff); + return clbuff; } static void tsmf_gstreamer_free(ITSMFDecoder* decoder) @@ -700,7 +888,7 @@ static void tsmf_gstreamer_free(ITSMFDecoder* decoder) if (mdecoder) { - mdecoder->shutdown = 1; + tsmf_window_destroy(mdecoder); tsmf_gstreamer_clean_up(mdecoder); if (mdecoder->gst_caps) @@ -721,7 +909,10 @@ static UINT64 tsmf_gstreamer_get_running_time(ITSMFDecoder* decoder) return 0; if (!mdecoder->outsink) - return mdecoder->last_sample_end_time; + return mdecoder->last_sample_start_time; + + if (!mdecoder->pipe) + return 0; if (GST_STATE(mdecoder->pipe) != GST_STATE_PLAYING) return 0; @@ -729,11 +920,11 @@ static UINT64 tsmf_gstreamer_get_running_time(ITSMFDecoder* decoder) GstFormat fmt = GST_FORMAT_TIME; gint64 pos = 0; #if GST_VERSION_MAJOR > 0 - gst_element_query_position(mdecoder->outsink, fmt, &pos); + gst_element_query_position(mdecoder->pipe, fmt, &pos); #else - gst_element_query_position(mdecoder->outsink, &fmt, &pos); + gst_element_query_position(mdecoder->pipe, &fmt, &pos); #endif - return pos/100; + return (UINT64) (pos/100 + mdecoder->seek_offset); } static BOOL tsmf_gstreamer_update_rendering_area(ITSMFDecoder* decoder, @@ -757,7 +948,7 @@ BOOL tsmf_gstreamer_ack(ITSMFDecoder* decoder, BOOL (*cb)(void *, BOOL), void *s { TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; DEBUG_TSMF(""); - mdecoder->ack_cb = cb; + mdecoder->ack_cb = NULL;//cb; mdecoder->stream = stream; return TRUE; } @@ -800,13 +991,17 @@ ITSMFDecoder* freerdp_tsmf_client_subsystem_entry(void) decoder->iface.Control = tsmf_gstreamer_control; decoder->iface.DecodeEx = tsmf_gstreamer_decodeEx; decoder->iface.ChangeVolume = tsmf_gstreamer_change_volume; - decoder->iface.BufferFilled = tsmf_gstreamer_buffer_filled; + decoder->iface.BufferLevel = tsmf_gstreamer_buffer_level; decoder->iface.SetAckFunc = tsmf_gstreamer_ack; decoder->iface.SetSyncFunc = tsmf_gstreamer_sync; decoder->paused = FALSE; decoder->gstVolume = 0.5; decoder->gstMuted = FALSE; decoder->state = GST_STATE_VOID_PENDING; /* No real state yet */ + decoder->last_sample_start_time = 0; + decoder->last_sample_end_time = 0; + decoder->seek_offset = 0; + decoder->seeking = FALSE; if (tsmf_platform_create(decoder) < 0) { diff --git a/channels/tsmf/client/gstreamer/tsmf_platform.h b/channels/tsmf/client/gstreamer/tsmf_platform.h index 6748f4ea8..0d6fc5aa0 100644 --- a/channels/tsmf/client/gstreamer/tsmf_platform.h +++ b/channels/tsmf/client/gstreamer/tsmf_platform.h @@ -38,12 +38,16 @@ typedef struct _TSMFGstreamerDecoder GstElement *pipe; GstElement *src; + GstElement *queue; GstElement *outsink; GstElement *volume; BOOL ready; BOOL paused; + UINT64 last_sample_start_time; UINT64 last_sample_end_time; + BOOL seeking; + UINT64 seek_offset; double gstVolume; BOOL gstMuted; @@ -74,8 +78,8 @@ int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, int height, int nr_rect, RDP_RECT *visible); int tsmf_window_destroy(TSMFGstreamerDecoder* decoder); -int tsmf_window_pause(TSMFGstreamerDecoder* decoder); -int tsmf_window_resume(TSMFGstreamerDecoder* decoder); +int tsmf_window_map(TSMFGstreamerDecoder* decoder); +int tsmf_window_unmap(TSMFGstreamerDecoder* decoder); BOOL tsmf_gstreamer_add_pad(TSMFGstreamerDecoder* mdecoder); void tsmf_gstreamer_remove_pad(TSMFGstreamerDecoder* mdecoder); diff --git a/channels/tsmf/client/tsmf_codec.c b/channels/tsmf/client/tsmf_codec.c index 7ae5e283d..b5e5a42cd 100644 --- a/channels/tsmf/client/tsmf_codec.c +++ b/channels/tsmf/client/tsmf_codec.c @@ -75,6 +75,13 @@ static const TSMFMediaTypeMap tsmf_sub_type_map[] = TSMF_SUB_TYPE_WVC1 }, + /* 00000160-0000-0010-8000-00AA00389B71 */ + { + { 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }, + "MEDIASUBTYPE_WMAudioV1", /* V7, V8 has the same GUID */ + TSMF_SUB_TYPE_WMA1 + }, + /* 00000161-0000-0010-8000-00AA00389B71 */ { { 0x61, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }, @@ -173,6 +180,13 @@ static const TSMFMediaTypeMap tsmf_sub_type_map[] = TSMF_SUB_TYPE_MP42 }, + /* 3253344D-0000-0010-8000-00AA00389B71 */ + { + { 0x4D, 0x34, 0x53, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }, + "MEDIASUBTYPE_MP42", + TSMF_SUB_TYPE_M4S2 + }, + /* E436EB81-524F-11CE-9F53-0020AF0BA770 */ { { 0x81, 0xEB, 0x36, 0xE4, 0x4F, 0x52, 0xCE, 0x11, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 }, @@ -605,11 +619,22 @@ BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, wStream* s) BOOL tsmf_codec_check_media_type(const char* decoder_name, wStream* s) { BYTE* m; - BOOL ret; + BOOL ret = FALSE; TS_AM_MEDIA_TYPE mediatype; + static BOOL decoderAvailable = FALSE; + static BOOL firstRun = TRUE; + + if (firstRun) + { + firstRun =FALSE; + if (tsmf_check_decoder_available(decoder_name)) + decoderAvailable = TRUE; + } + Stream_GetPointer(s, m); - ret = tsmf_codec_parse_media_type(&mediatype, s); + if (decoderAvailable) + ret = tsmf_codec_parse_media_type(&mediatype, s); Stream_SetPointer(s, m); if (ret) diff --git a/channels/tsmf/client/tsmf_constants.h b/channels/tsmf/client/tsmf_constants.h index 1fee13a67..3ca92f645 100644 --- a/channels/tsmf/client/tsmf_constants.h +++ b/channels/tsmf/client/tsmf_constants.h @@ -125,6 +125,8 @@ #define TSMF_SUB_TYPE_VP8 24 #define TSMF_SUB_TYPE_VP9 25 #define TSMF_SUB_TYPE_H263 26 +#define TSMF_SUB_TYPE_M4S2 27 +#define TSMF_SUB_TYPE_WMA1 28 /* FormatType */ #define TSMF_FORMAT_TYPE_UNKNOWN 0 diff --git a/channels/tsmf/client/tsmf_decoder.c b/channels/tsmf/client/tsmf_decoder.c index 164e0d8be..319dbfcac 100644 --- a/channels/tsmf/client/tsmf_decoder.c +++ b/channels/tsmf/client/tsmf_decoder.c @@ -32,7 +32,7 @@ #include "tsmf_constants.h" #include "tsmf_decoder.h" -static ITSMFDecoder* tsmf_load_decoder_by_name(const char *name, TS_AM_MEDIA_TYPE *media_type) +static ITSMFDecoder* tsmf_load_decoder_by_name(const char *name) { ITSMFDecoder* decoder; TSMF_DECODER_ENTRY entry; @@ -50,33 +50,74 @@ static ITSMFDecoder* tsmf_load_decoder_by_name(const char *name, TS_AM_MEDIA_TYP return NULL; } - if (!decoder->SetFormat(decoder, media_type)) - { - decoder->Free(decoder); - decoder = NULL; - } - return decoder; } +static BOOL tsmf_decoder_set_format(ITSMFDecoder *decoder, TS_AM_MEDIA_TYPE* media_type) +{ + if (decoder->SetFormat(decoder, media_type)) + return TRUE; + else + return FALSE; +} + ITSMFDecoder* tsmf_load_decoder(const char* name, TS_AM_MEDIA_TYPE* media_type) { ITSMFDecoder* decoder = NULL; if (name) { - decoder = tsmf_load_decoder_by_name(name, media_type); + decoder = tsmf_load_decoder_by_name(name); } #if defined(WITH_GSTREAMER_1_0) || defined(WITH_GSTREAMER_0_10) if (!decoder) - decoder = tsmf_load_decoder_by_name("gstreamer", media_type); + decoder = tsmf_load_decoder_by_name("gstreamer"); #endif #if defined(WITH_FFMPEG) if (!decoder) - decoder = tsmf_load_decoder_by_name("ffmpeg", media_type); + decoder = tsmf_load_decoder_by_name("ffmpeg"); #endif + if (decoder) + { + if (!tsmf_decoder_set_format(decoder, media_type)) + { + decoder->Free(decoder); + decoder = NULL; + } + } + return decoder; } + +BOOL tsmf_check_decoder_available(const char* name) +{ + ITSMFDecoder* decoder = NULL; + BOOL retValue = FALSE; + + if (name) + { + decoder = tsmf_load_decoder_by_name(name); + } +#if defined(WITH_GSTREAMER_1_0) || defined(WITH_GSTREAMER_0_10) + if (!decoder) + decoder = tsmf_load_decoder_by_name("gstreamer"); +#endif + +#if defined(WITH_FFMPEG) + if (!decoder) + decoder = tsmf_load_decoder_by_name("ffmpeg"); +#endif + + if (decoder) + { + decoder->Free(decoder); + decoder = NULL; + retValue = TRUE; + } + + return retValue; +} + diff --git a/channels/tsmf/client/tsmf_decoder.h b/channels/tsmf/client/tsmf_decoder.h index d507b9e1b..d8450d49f 100644 --- a/channels/tsmf/client/tsmf_decoder.h +++ b/channels/tsmf/client/tsmf_decoder.h @@ -27,6 +27,7 @@ typedef enum _ITSMFControlMsg { Control_Pause, Control_Resume, + Control_Restart, Control_Stop } ITSMFControlMsg; @@ -58,7 +59,7 @@ struct _ITSMFDecoder /* Change Gstreamer Audio Volume */ BOOL (*ChangeVolume)(ITSMFDecoder *decoder, UINT32 newVolume, UINT32 muted); /* Check buffer level */ - BOOL (*BufferFilled)(ITSMFDecoder *decoder); + BOOL (*BufferLevel)(ITSMFDecoder *decoder); /* Register a callback for frame ack. */ BOOL (*SetAckFunc)(ITSMFDecoder *decoder, BOOL (*cb)(void *,BOOL), void *stream); /* Register a callback for stream seek detection. */ @@ -69,6 +70,7 @@ struct _ITSMFDecoder typedef ITSMFDecoder *(*TSMF_DECODER_ENTRY)(void); ITSMFDecoder *tsmf_load_decoder(const char *name, TS_AM_MEDIA_TYPE *media_type); +BOOL tsmf_check_decoder_available(const char* name); #endif diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index 392377210..3f4f2e608 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -553,6 +553,7 @@ UINT tsmf_ifman_set_allocator(TSMF_IFMAN* ifman) UINT tsmf_ifman_notify_preroll(TSMF_IFMAN* ifman) { DEBUG_TSMF(""); + tsmf_ifman_on_playback_paused(ifman); ifman->output_pending = TRUE; return CHANNEL_RC_OK; } @@ -637,6 +638,7 @@ UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman) { UINT32 StreamId; TSMF_PRESENTATION* presentation; + TSMF_STREAM* stream; if (Stream_GetRemainingLength(ifman->input) < 20) return ERROR_INVALID_DATA; @@ -653,8 +655,15 @@ UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman) return ERROR_NOT_FOUND; } - if (!tsmf_presentation_flush(presentation)) - return ERROR_INVALID_OPERATION; + // Flush message is for a stream, not the entire presentation + // therefore we only flush the stream as intended per the MS-RDPEV spec + stream = tsmf_stream_find_by_id(presentation, StreamId); + if (stream) + if (!tsmf_stream_flush(stream)) + return ERROR_INVALID_OPERATION; + else + WLog_ERR(TAG, "unknown stream id"); + ifman->output_pending = TRUE; return CHANNEL_RC_OK; @@ -668,7 +677,7 @@ UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman) UINT tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman) { UINT32 StreamId; - TSMF_STREAM* stream; + TSMF_STREAM* stream = NULL; TSMF_PRESENTATION* presentation; if (Stream_GetRemainingLength(ifman->input) < 20) @@ -684,17 +693,12 @@ UINT tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman) stream = tsmf_stream_find_by_id(presentation, StreamId); if (stream) - tsmf_stream_end(stream); + tsmf_stream_end(stream, ifman->message_id, ifman->channel_callback); } DEBUG_TSMF("StreamId %d", StreamId); - if (!Stream_EnsureRemainingCapacity(ifman->output, 16)) - return ERROR_OUTOFMEMORY; - Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ - Stream_Write_UINT32(ifman->output, StreamId); /* StreamId */ - Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_ENDOFSTREAM); /* EventId */ - Stream_Write_UINT32(ifman->output, 0); /* cbData */ + ifman->output_pending = TRUE; ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY; return CHANNEL_RC_OK; diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 0c8bdea3a..7d454a60b 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -36,7 +36,47 @@ #include "tsmf_main.h" -BOOL tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, +void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id) +{ + wStream* s; + int status; + TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) pChannelCallback; + + s = Stream_New(NULL, 24); + if (!s) + return FALSE; + + if (!callback) + { + DEBUG_TSMF("No callback reference - unable to send eos response!"); + return; + } + + if (callback && callback->stream_id && callback->channel && callback->channel->Write) + { + s = Stream_New(NULL, 24); + if (!s) + return FALSE; + Stream_Write_UINT32(s, TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY); + Stream_Write_UINT32(s, message_id); + Stream_Write_UINT32(s, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ + Stream_Write_UINT32(s, callback->stream_id); /* StreamId */ + Stream_Write_UINT32(s, TSMM_CLIENT_EVENT_ENDOFSTREAM); /* EventId */ + Stream_Write_UINT32(s, 0); /* cbData */ + DEBUG_TSMF("response size %i", Stream_GetPosition(s)); + + status = callback->channel->Write(callback->channel, Stream_GetPosition(s), Stream_Buffer(s), NULL); + if (status) + { + WLog_ERR(TAG, "response error %d", status); + } + Stream_Free(s, TRUE); + } + + return (status == 0); +} + +void tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size) { wStream *s; diff --git a/channels/tsmf/client/tsmf_main.h b/channels/tsmf/client/tsmf_main.h index e29a00ad4..c9489f33a 100644 --- a/channels/tsmf/client/tsmf_main.h +++ b/channels/tsmf/client/tsmf_main.h @@ -64,7 +64,8 @@ struct _TSMF_PLUGIN rdpContext* rdpcontext; }; -BOOL tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, +void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id); +void tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size); #endif diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 09b43efb8..e7c69ca1d 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -56,13 +56,23 @@ #define AUDIO_TOLERANCE 10000000LL +// 1 second +#define VIDEO_ADJUST_MAX 10000000 + +#define MAX_ACK_TIME 666667 + +#define AUDIO_MIN_BUFFER_LEVEL 3 +#define AUDIO_MAX_BUFFER_LEVEL 6 + +#define VIDEO_MIN_BUFFER_LEVEL 10 +#define VIDEO_MAX_BUFFER_LEVEL 30 + struct _TSMF_PRESENTATION { BYTE presentation_id[GUID_SIZE]; const char *audio_name; const char *audio_device; - int eos; IWTSVirtualChannelCallback *channel_callback; @@ -93,6 +103,9 @@ struct _TSMF_STREAM int major_type; int eos; + UINT32 eos_message_id; + IWTSVirtualChannelCallback* eos_channel_callback; + int delayed_stop; UINT32 width; UINT32 height; @@ -101,11 +114,17 @@ struct _TSMF_STREAM UINT32 channels; UINT32 bits_per_sample; + /* The start time of last played sample */ + UINT64 last_start_time; /* The end_time of last played sample */ UINT64 last_end_time; /* Next sample should not start before this system time. */ UINT64 next_start_time; + UINT32 minBufferLevel; + UINT32 maxBufferLevel; + UINT32 currentBufferLevel; + HANDLE play_thread; HANDLE ack_thread; HANDLE stopEvent; @@ -114,6 +133,8 @@ struct _TSMF_STREAM wQueue *sample_list; wQueue *sample_ack_list; rdpContext* rdpcontext; + + BOOL seeking; }; struct _TSMF_SAMPLE @@ -128,6 +149,8 @@ struct _TSMF_SAMPLE UINT32 decoded_size; UINT32 pixfmt; + BOOL invalidTimestamps; + TSMF_STREAM* stream; IWTSVirtualChannelCallback *channel_callback; UINT64 ack_time; @@ -170,7 +193,9 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) { /* Check if some other stream has earlier sample that needs to be played first */ - if (stream->last_end_time > AUDIO_TOLERANCE) + // Start time is more reliable than end time as some stream types seem to have incorrect + // end times from the server + if (stream->last_start_time > AUDIO_TOLERANCE) { ArrayList_Lock(presentation->stream_list); count = ArrayList_Count(presentation->stream_list); @@ -179,9 +204,12 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) { s = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index); - if (s != stream && !s->eos && s->last_end_time && - s->last_end_time < stream->last_end_time - AUDIO_TOLERANCE) + // Start time is more reliable than end time as some stream types seem to have incorrect + // end times from the server + if (s != stream && !s->eos && s->last_start_time && + s->last_start_time < stream->last_start_time - AUDIO_TOLERANCE) { + DEBUG_TSMF("Pending due to audio tolerance"); pending = TRUE; break; } @@ -192,8 +220,11 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) } else { - if (stream->last_end_time > presentation->audio_end_time) + // Start time is more reliable than end time as some stream types seem to have incorrect + // end times from the server + if (stream->last_start_time > presentation->audio_start_time) { + DEBUG_TSMF("Pending due to stream start time > audio start time"); pending = TRUE; } } @@ -206,9 +237,14 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) sample = (TSMF_SAMPLE *) Queue_Dequeue(stream->sample_list); - if (sample && (sample->end_time > stream->last_end_time)) + // Only update stream last end time if the sample end time is valid and greater than the current stream end time + if (sample && (sample->end_time > stream->last_end_time) && (!sample->invalidTimestamps)) stream->last_end_time = sample->end_time; + // Only update stream last start time if the sample start time is valid and greater than the current stream start time + if (sample && (sample->start_time > stream->last_start_time) && (!sample->invalidTimestamps)) + stream->last_start_time = sample->start_time; + return sample; } @@ -242,6 +278,8 @@ static BOOL tsmf_sample_queue_ack(TSMF_SAMPLE* sample) return Queue_Enqueue(sample->stream->sample_ack_list, sample); } +// Returns TRUE if no more samples are currently available +// Returns FALSE otherwise static BOOL tsmf_stream_process_ack(void* arg, BOOL force) { TSMF_STREAM* stream = arg; @@ -250,22 +288,38 @@ static BOOL tsmf_stream_process_ack(void* arg, BOOL force) BOOL rc = FALSE; if (!stream) - return FALSE; + return TRUE; Queue_Lock(stream->sample_ack_list); sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list); if (!sample) + { + rc = TRUE; goto finally; + } if (!force) { + // Do some min/max ack limiting if we have access to Buffer level information + if (stream->decoder->BufferLevel) + { + // Try to keep buffer level below max by withholding acks + if (stream->currentBufferLevel > stream->maxBufferLevel) + goto finally; + // Try to keep buffer level above min by pushing acks through quickly + else if (stream->currentBufferLevel < stream->minBufferLevel) + goto dequeue; + } + + // Time based acks only ack_time = get_current_time(); if (sample->ack_time > ack_time) goto finally; } +dequeue: sample = Queue_Dequeue(stream->sample_ack_list); if (sample) { @@ -295,6 +349,7 @@ TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, IWTSVirtualChannelCal CopyMemory(presentation->presentation_id, guid, GUID_SIZE); presentation->channel_callback = pChannelCallback; presentation->volume = 5000; /* 50% */ + presentation->muted = 0; if (!(presentation->stream_list = ArrayList_New(TRUE))) goto error_stream_list; @@ -372,9 +427,11 @@ static BOOL tsmf_sample_playback_video(TSMF_SAMPLE* sample) { t = get_current_time(); + // Start time is more reliable than end time as some stream types seem to have incorrect + // end times from the server if (stream->next_start_time > t && - (sample->end_time >= presentation->audio_start_time || - sample->end_time < stream->last_end_time)) + ((sample->start_time >= presentation->audio_start_time) || + ((sample->start_time < stream->last_start_time) && (!sample->invalidTimestamps)))) { USleep((stream->next_start_time - t) / 10); } @@ -449,9 +506,15 @@ static BOOL tsmf_sample_playback_audio(TSMF_SAMPLE* sample) } sample->ack_time = latency + get_current_time(); - stream->last_end_time = sample->end_time + latency; - stream->presentation->audio_start_time = sample->start_time + latency; - stream->presentation->audio_end_time = sample->end_time + latency; + + //Only update stream times if the sample timestamps are valid + if (!sample->invalidTimestamps) + { + stream->last_start_time = sample->start_time + latency; + stream->last_end_time = sample->end_time + latency; + stream->presentation->audio_start_time = sample->start_time + latency; + stream->presentation->audio_end_time = sample->end_time + latency; + } return ret; } @@ -467,6 +530,31 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) { if (stream->decoder->DecodeEx) { + // Try to "sync" video buffers to audio buffers by looking at the running time for each stream + // The difference between the two running times causes an offset between audio and video actual + // render times. So, we try to adjust timestamps on the video buffer to match those on the audio buffer. + if (stream->major_type == TSMF_MAJOR_TYPE_VIDEO) + { + TSMF_STREAM* temp_stream = NULL; + TSMF_PRESENTATION* presentation = stream->presentation; + ArrayList_Lock(presentation->stream_list); + int count = ArrayList_Count(presentation->stream_list); + int index = 0; + for (index = 0; index < count; index++) + { + temp_stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index); + if (temp_stream->major_type == TSMF_MAJOR_TYPE_AUDIO) + { + UINT64 video_time = (UINT64) stream->decoder->GetRunningTime(stream->decoder); + UINT64 audio_time = (UINT64) temp_stream->decoder->GetRunningTime(temp_stream->decoder); + sample->start_time += abs(video_time - audio_time) > VIDEO_ADJUST_MAX ? (video_time - audio_time) : VIDEO_ADJUST_MAX; + sample->end_time += abs(video_time - audio_time) > VIDEO_ADJUST_MAX ? (video_time - audio_time) : VIDEO_ADJUST_MAX; + break; + } + } + ArrayList_Unlock(presentation->stream_list); + } + ret = stream->decoder->DecodeEx(stream->decoder, sample->data, sample->data_size, sample->extensions, sample->start_time, sample->end_time, sample->duration); } @@ -543,37 +631,22 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) { TSMF_STREAM* stream = sample->stream; UINT64 ack_anticipation_time = get_current_time(); - UINT64 currentRunningTime = sample->start_time; BOOL buffer_filled = TRUE; - if (stream->decoder->GetRunningTime) + // Classify the buffer as filled once it reaches minimum level + if (stream->decoder->BufferLevel) { - currentRunningTime = stream->decoder->GetRunningTime(stream->decoder); - } - - if (stream->decoder->BufferFilled) - { - buffer_filled = stream->decoder->BufferFilled(stream->decoder); + if (stream->currentBufferLevel < stream->minBufferLevel) + buffer_filled = FALSE; } if (buffer_filled) { - if (currentRunningTime > sample->start_time) - { - ack_anticipation_time += sample->duration; - } - else if (currentRunningTime == 0) - { - ack_anticipation_time += sample->duration; - } - else - { - ack_anticipation_time += (sample->start_time - currentRunningTime); - } + ack_anticipation_time += (sample->duration/2 < MAX_ACK_TIME) ? sample->duration/2 : MAX_ACK_TIME; } else { - ack_anticipation_time += sample->duration / 2; + ack_anticipation_time += (sample->duration/2 < MAX_ACK_TIME) ? sample->duration/2 : MAX_ACK_TIME; } switch (sample->stream->major_type) @@ -608,31 +681,63 @@ static void* tsmf_stream_ack_func(void *arg) while (1) { - DWORD ev = WaitForMultipleObjects(2, hdl, FALSE, INFINITE); + DWORD ev = WaitForMultipleObjects(2, hdl, FALSE, 1000); - if (ev == WAIT_FAILED) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error); - break; - } - - if (ev == WAIT_OBJECT_0) - break; - - if (!stream->decoder) - continue; - - if (stream->decoder->SetAckFunc) - continue; - - if (tsmf_stream_process_ack(stream, FALSE)) + if (ev == WAIT_FAILED) { - error = ERROR_INTERNAL_ERROR; - WLog_ERR(TAG, "tsmf_stream_process_ack failed!"); + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error); break; } + if (stream->decoder) + if (stream->decoder->BufferLevel) + stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder); + + if (stream->eos) + { + while ((stream->currentBufferLevel > 0) || !(tsmf_stream_process_ack(stream, TRUE))) + { + DEBUG_TSMF("END OF STREAM PROCESSING!"); + if (stream->decoder->BufferLevel) + stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder); + else + stream->currentBufferLevel = 1; + + USleep(1000); + } + + tsmf_send_eos_response(stream->eos_channel_callback, stream->eos_message_id); + stream->eos = 0; + + if (stream->delayed_stop) + { + DEBUG_TSMF("Finishing delayed stream stop, now that eos has processed."); + tsmf_stream_flush(stream); + + if (stream->decoder->Control) + stream->decoder->Control(stream->decoder, Control_Stop, NULL); + } + } + + // Stream stopped force all of the acks to happen + if (ev == WAIT_OBJECT_0) + { + DEBUG_TSMF("ack: Stream stopped!"); + while(1) + { + if (tsmf_stream_process_ack(stream, TRUE)) + break; + USleep(1000); + } + break; + } + + if (tsmf_stream_process_ack(stream, FALSE)) + continue; + + if (stream->currentBufferLevel > stream->minBufferLevel) + USleep(1000); } if (error && stream->rdpcontext) @@ -646,7 +751,7 @@ static void* tsmf_stream_ack_func(void *arg) static void* tsmf_stream_playback_func(void *arg) { HANDLE hdl[2]; - TSMF_SAMPLE* sample; + TSMF_SAMPLE* sample = NULL; TSMF_STREAM* stream = (TSMF_STREAM *) arg; TSMF_PRESENTATION* presentation = stream->presentation; UINT error = CHANNEL_RC_OK; @@ -678,28 +783,33 @@ static void* tsmf_stream_playback_func(void *arg) while (1) { - status = WaitForMultipleObjects(2, hdl, FALSE, INFINITE); + status = WaitForMultipleObjects(2, hdl, FALSE, 1000); - if (status == WAIT_FAILED) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error); - break; - } + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error); + break; + } - status = WaitForSingleObject(stream->stopEvent, 0); - if (status == WAIT_FAILED) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); - break; - } + status = WaitForSingleObject(stream->stopEvent, 0); - if (status == WAIT_OBJECT_0) - break; + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); + break; + } - sample = tsmf_stream_pop_sample(stream, 0); + if (status == WAIT_OBJECT_0) + break; + + if (stream->decoder) + if (stream->decoder->BufferLevel) + stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder); + + sample = tsmf_stream_pop_sample(stream, 0); if (sample && !tsmf_sample_playback(sample)) { @@ -707,8 +817,12 @@ static void* tsmf_stream_playback_func(void *arg) error = ERROR_INTERNAL_ERROR; break; } + + if (stream->currentBufferLevel > stream->minBufferLevel) + USleep(1000); } + if (stream->audio) { stream->audio->Free(stream->audio); @@ -728,7 +842,9 @@ static BOOL tsmf_stream_start(TSMF_STREAM* stream) if (!stream || !stream->presentation || !stream->decoder || !stream->decoder->Control) return TRUE; - return stream->decoder->Control(stream->decoder, Control_Resume, NULL); + stream->eos = 0; + + return stream->decoder->Control(stream->decoder, Control_Restart, NULL); } static BOOL tsmf_stream_stop(TSMF_STREAM* stream) @@ -736,7 +852,23 @@ static BOOL tsmf_stream_stop(TSMF_STREAM* stream) if (!stream || !stream->decoder || !stream->decoder->Control) return TRUE; - return stream->decoder->Control(stream->decoder, Control_Stop, NULL); + // If stopping after eos - we delay until the eos has been processed + // this allows us to process any buffers that have been acked even though + // they have not actually been completely processes by the decoder + if (stream->eos) + { + DEBUG_TSMF("Setting up a delayed stop for once the eos has been processed."); + stream->delayed_stop = 1; + return TRUE; + } + // Otherwise force stop immediately + else + { + DEBUG_TSMF("Stop with no pending eos response, so do it immediately."); + tsmf_stream_flush(stream); + + return stream->decoder->Control(stream->decoder, Control_Stop, NULL); + } } static BOOL tsmf_stream_pause(TSMF_STREAM* stream) @@ -752,7 +884,9 @@ static BOOL tsmf_stream_restart(TSMF_STREAM* stream) if (!stream || !stream->decoder || !stream->decoder->Control) return TRUE; - return stream->decoder->Control(stream->decoder, Control_Resume, NULL); + stream->eos = 0; + + return stream->decoder->Control(stream->decoder, Control_Restart, NULL); } static BOOL tsmf_stream_change_volume(TSMF_STREAM* stream, UINT32 newVolume, UINT32 muted) @@ -902,6 +1036,9 @@ BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation) } ArrayList_Unlock(presentation->stream_list); + presentation->audio_start_time = 0; + presentation->audio_end_time = 0; + return ret; } @@ -922,6 +1059,9 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, if (!width || !height) return TRUE; + // Streams can be added/removed from the presentation and the server will resend geometry info when a new stream is + // added to the presentation. + /* if ((width == presentation->width) && (height == presentation->height) && (x == presentation->x) && (y == presentation->y) && (num_rects == presentation->nr_rects) && @@ -929,6 +1069,7 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, { return TRUE; } + */ presentation->x = x; presentation->y = y; @@ -969,7 +1110,7 @@ void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, const c presentation->audio_device = device; } -static BOOL tsmf_stream_flush(TSMF_STREAM* stream) +BOOL tsmf_stream_flush(TSMF_STREAM* stream) { BOOL ret = TRUE; @@ -979,6 +1120,9 @@ static BOOL tsmf_stream_flush(TSMF_STREAM* stream) ret = stream->audio->Flush(stream->audio); stream->eos = 0; + stream->eos_message_id = 0; + stream->eos_channel_callback = NULL; + stream->delayed_stop = 0; stream->last_end_time = 0; stream->next_start_time = 0; @@ -1049,6 +1193,14 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, return NULL; } + stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL; + stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL; + stream->currentBufferLevel = 1; + + stream->seeking = FALSE; + stream->eos = 0; + stream->eos_message_id = 0; + stream->eos_channel_callback = NULL; stream->stream_id = stream_id; stream->presentation = presentation; stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); @@ -1152,6 +1304,9 @@ BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char *name, wStream *s) mediatype.Width, mediatype.Height, mediatype.BitRate, (double) mediatype.SamplesPerSecond.Numerator / (double) mediatype.SamplesPerSecond.Denominator, mediatype.ExtraDataSize); + + stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL; + stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL; } else if (mediatype.MajorType == TSMF_MAJOR_TYPE_AUDIO) { @@ -1164,6 +1319,9 @@ BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char *name, wStream *s) if (stream->bits_per_sample == 0) stream->bits_per_sample = 16; + + stream->minBufferLevel = AUDIO_MIN_BUFFER_LEVEL; + stream->maxBufferLevel = AUDIO_MAX_BUFFER_LEVEL; } stream->major_type = mediatype.MajorType; @@ -1183,13 +1341,14 @@ BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char *name, wStream *s) return ret; } -void tsmf_stream_end(TSMF_STREAM* stream) +void tsmf_stream_end(TSMF_STREAM* stream, UINT32 message_id, IWTSVirtualChannelCallback* pChannelCallback) { if (!stream) return; stream->eos = 1; - stream->presentation->eos = 1; + stream->eos_message_id = message_id; + stream->eos_channel_callback = pChannelCallback; } void _tsmf_stream_free(TSMF_STREAM* stream) @@ -1197,8 +1356,7 @@ void _tsmf_stream_free(TSMF_STREAM* stream) if (!stream) return; - if (tsmf_stream_stop(stream)) - tsmf_stream_flush(stream); + tsmf_stream_stop(stream); SetEvent(stream->stopEvent); if (stream->play_thread) @@ -1267,6 +1425,10 @@ BOOL tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback *pC sample->end_time = end_time; sample->duration = duration; sample->extensions = extensions; + if ((sample->extensions & 0x00000080) || (sample->extensions & 0x00000040)) + sample->invalidTimestamps = TRUE; + else + sample->invalidTimestamps = FALSE; sample->stream = stream; sample->channel_callback = pChannelCallback; sample->data_size = data_size; diff --git a/channels/tsmf/client/tsmf_media.h b/channels/tsmf/client/tsmf_media.h index f697080f6..47f189f5d 100644 --- a/channels/tsmf/client/tsmf_media.h +++ b/channels/tsmf/client/tsmf_media.h @@ -55,8 +55,9 @@ void tsmf_presentation_free(TSMF_PRESENTATION *presentation); TSMF_STREAM *tsmf_stream_new(TSMF_PRESENTATION *presentation, UINT32 stream_id, rdpContext* rdpcontext); TSMF_STREAM *tsmf_stream_find_by_id(TSMF_PRESENTATION *presentation, UINT32 stream_id); BOOL tsmf_stream_set_format(TSMF_STREAM *stream, const char *name, wStream *s); -void tsmf_stream_end(TSMF_STREAM *stream); +void tsmf_stream_end(TSMF_STREAM *stream, UINT32 message_id, IWTSVirtualChannelCallback* pChannelCallback); void tsmf_stream_free(TSMF_STREAM *stream); +void tsmf_stream_flush(TSMF_STREAM* stream); BOOL tsmf_stream_push_sample(TSMF_STREAM *stream, IWTSVirtualChannelCallback *pChannelCallback, UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions, From 8d692995d6bef0835d1e06233770ee206808fb0c Mon Sep 17 00:00:00 2001 From: bjcollins Date: Wed, 8 Jul 2015 13:10:21 -0500 Subject: [PATCH 012/220] tsmf gstreamer fixes - Update patch based on feedback - Fix gstreamer 1.0 compatibility/build issue from first patch --- channels/tsmf/client/gstreamer/tsmf_X11.c | 30 ++-- .../tsmf/client/gstreamer/tsmf_gstreamer.c | 138 ++++++++++++------ channels/tsmf/client/tsmf_ifman.c | 5 +- channels/tsmf/client/tsmf_main.c | 10 +- channels/tsmf/client/tsmf_media.c | 68 +++++---- 5 files changed, 159 insertions(+), 92 deletions(-) diff --git a/channels/tsmf/client/gstreamer/tsmf_X11.c b/channels/tsmf/client/gstreamer/tsmf_X11.c index dfeb26e86..c32501301 100644 --- a/channels/tsmf/client/gstreamer/tsmf_X11.c +++ b/channels/tsmf/client/gstreamer/tsmf_X11.c @@ -62,7 +62,11 @@ struct X11Handle Display *disp; Window subwin; BOOL subwinMapped; +#if GST_VERSION_MAJOR > 0 + GstVideoOverlay *overlay; +#else GstXOverlay *overlay; +#endif int subwinWidth; int subwinHeight; int subwinX; @@ -85,31 +89,32 @@ static GstBusSyncReply tsmf_platform_bus_sync_handler(GstBus *bus, GstMessage *m if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) return GST_BUS_PASS; +#if GST_VERSION_MAJOR > 0 + if (!gst_is_video_overlay_prepare_window_handle_message (message)) + return GST_BUS_PASS; +#else if (!gst_structure_has_name (message->structure, "prepare-xwindow-id")) return GST_BUS_PASS; +#endif hdl = (struct X11Handle*) decoder->platform; if (hdl->subwin) { - hdl->overlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message)); - #if GST_VERSION_MAJOR > 0 + hdl->overlay = GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)); gst_video_overlay_set_window_handle(hdl->overlay, hdl->subwin); -#else - gst_x_overlay_set_window_handle(hdl->overlay, hdl->subwin); -#endif -#if GST_VERSION_MAJOR > 0 gst_video_overlay_handle_events(hdl->overlay, TRUE); #else + hdl->overlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message)); + gst_x_overlay_set_window_handle(hdl->overlay, hdl->subwin); gst_x_overlay_handle_events(hdl->overlay, TRUE); #endif if (hdl->subwinWidth != -1 && hdl->subwinHeight != -1 && hdl->subwinX != -1 && hdl->subwinY != -1) { #if GST_VERSION_MAJOR > 0 - - if (!gst_video_overlay_set_render_rectangle(hdl->overlay, 0, 0, hdl->swubwinWidth, hdl->subwinHeight)) + if (!gst_video_overlay_set_render_rectangle(hdl->overlay, 0, 0, hdl->subwinWidth, hdl->subwinHeight)) { WLog_ERR(TAG, "Could not resize overlay!"); } @@ -142,7 +147,6 @@ const char* tsmf_platform_get_video_sink(void) const char* tsmf_platform_get_audio_sink(void) { - //return "alsasink"; return "autoaudiosink"; } @@ -219,7 +223,11 @@ int tsmf_platform_register_handler(TSMFGstreamerDecoder* decoder) bus = gst_pipeline_get_bus(GST_PIPELINE(decoder->pipe)); +#if GST_VERSION_MAJOR > 0 + gst_bus_set_sync_handler (bus, (GstBusSyncHandler) tsmf_platform_bus_sync_handler, decoder, NULL); +#else gst_bus_set_sync_handler (bus, (GstBusSyncHandler) tsmf_platform_bus_sync_handler, decoder); +#endif if (!bus) { @@ -397,7 +405,7 @@ int tsmf_window_map(TSMFGstreamerDecoder* decoder) hdl = (struct X11Handle*) decoder->platform; - // Only need to map the window if it is not currently mapped + /* Only need to map the window if it is not currently mapped */ if ((hdl->subwin) && (!hdl->subwinMapped)) { XLockDisplay(hdl->disp); @@ -418,7 +426,7 @@ int tsmf_window_unmap(TSMFGstreamerDecoder* decoder) hdl = (struct X11Handle*) decoder->platform; - // only need to unmap window if it is currently mapped + /* only need to unmap window if it is currently mapped */ if ((hdl->subwin) && (hdl->subwinMapped)) { XLockDisplay(hdl->disp); diff --git a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c index f848346a1..2458d6ec5 100644 --- a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c +++ b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c @@ -45,8 +45,8 @@ #include #endif -// 1 second -#define SEEK_TOLERANCE 10000000 +/* 1 second = 10,000,000 100ns units*/ +#define SEEK_TOLERANCE 10*1000*1000 static BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder); static void tsmf_gstreamer_clean_up(TSMFGstreamerDecoder* mdecoder); @@ -59,12 +59,15 @@ const char* get_type(TSMFGstreamerDecoder* mdecoder) if (!mdecoder) return NULL; - if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - return "VIDEO"; - else if (mdecoder->media_type == TSMF_MAJOR_TYPE_AUDIO) - return "AUDIO"; - else - return "UNKNOWN"; + switch (mdecoder->media_type) + { + case TSMF_MAJOR_TYPE_VIDEO: + return "VIDEO"; + case TSMF_MAJOR_TYPE_AUDIO: + return "AUDIO"; + default: + return "UNKNOWN"; + } } static void cb_child_added(GstChildProxy *child_proxy, GObject *object, TSMFGstreamerDecoder* mdecoder) @@ -73,20 +76,20 @@ static void cb_child_added(GstChildProxy *child_proxy, GObject *object, TSMFGstr if (!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstXvImageSink") || !g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstXImageSink") || !g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstFluVAAutoSink")) { - gst_base_sink_set_max_lateness((GstBaseSink *) object, 10000000); //nanoseconds - g_object_set(G_OBJECT(object), "sync", TRUE, NULL); //synchronize on the clock - g_object_set(G_OBJECT(object), "async", TRUE, NULL); //no async state changes - doc says not to do for streams synced to clock + gst_base_sink_set_max_lateness((GstBaseSink *) object, 10000000); /* nanoseconds */ + g_object_set(G_OBJECT(object), "sync", TRUE, NULL); /* synchronize on the clock */ + g_object_set(G_OBJECT(object), "async", TRUE, NULL); /* no async state changes */ } else if (!g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstAlsaSink") || !g_strcmp0(G_OBJECT_TYPE_NAME(object), "GstPulseSink")) { - gst_base_sink_set_max_lateness((GstBaseSink *) object, 10000000); //nanoseconds - g_object_set(G_OBJECT(object), "slave-method", 1, NULL); //DEFAULT - g_object_set(G_OBJECT(object), "buffer-time", (gint64) 20000, NULL); //microseconds - g_object_set(G_OBJECT(object), "drift-tolerance", (gint64) 20000, NULL); //microseconds - g_object_set(G_OBJECT(object), "latency-time", (gint64) 10000, NULL); //microseconds - g_object_set(G_OBJECT(object), "sync", TRUE, NULL); //synchronize on the clock - g_object_set(G_OBJECT(object), "async", TRUE, NULL); //no async state changes - doc says not to do for streams synced to clock + gst_base_sink_set_max_lateness((GstBaseSink *) object, 10000000); /* nanoseconds */ + g_object_set(G_OBJECT(object), "slave-method", 1, NULL); + g_object_set(G_OBJECT(object), "buffer-time", (gint64) 20000, NULL); /* microseconds */ + g_object_set(G_OBJECT(object), "drift-tolerance", (gint64) 20000, NULL); /* microseconds */ + g_object_set(G_OBJECT(object), "latency-time", (gint64) 10000, NULL); /* microseconds */ + g_object_set(G_OBJECT(object), "sync", TRUE, NULL); /* synchronize on the clock */ + g_object_set(G_OBJECT(object), "async", TRUE, NULL); /* no async state changes */ } } @@ -256,7 +259,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 3, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "WVC1", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'V', 'C', '1'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, NULL); @@ -267,7 +274,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "MP42", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '2'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; @@ -277,7 +288,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, - "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '2'), +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "MP42", +#else + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '2'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; @@ -287,7 +302,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "bitrate", G_TYPE_UINT, media_type->BitRate, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "MP43", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', 'P', '4', '3'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; @@ -296,7 +315,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "mpegversion", G_TYPE_INT, 4, "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "M4S2", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('M', '4', 'S', '2'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; @@ -347,7 +370,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 1, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "WMV1", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'M', 'V', '1'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, NULL); break; @@ -356,7 +383,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 2, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "WMV2", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'M', 'V', '2'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, NULL); @@ -367,7 +398,11 @@ static BOOL tsmf_gstreamer_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* m "width", G_TYPE_INT, media_type->Width, "height", G_TYPE_INT, media_type->Height, "wmvversion", G_TYPE_INT, 3, +#if GST_VERSION_MAJOR > 0 + "format", G_TYPE_STRING, "WMV3", +#else "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('W', 'M', 'V', '3'), +#endif "framerate", GST_TYPE_FRACTION, media_type->SamplesPerSecond.Numerator, media_type->SamplesPerSecond.Denominator, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1 , 1, NULL); @@ -506,8 +541,13 @@ void tsmf_gstreamer_clean_up(TSMFGstreamerDecoder* mdecoder) BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) { +#if GST_VERSION_MAJOR > 0 + const char* video = "appsrc name=videosource ! queue2 name=videoqueue ! decodebin name=videodecoder !"; + const char* audio = "appsrc name=audiosource ! queue2 name=audioqueue ! decodebin name=audiodecoder ! audioconvert ! audiorate ! audioresample ! volume name=audiovolume !"; +#else const char* video = "appsrc name=videosource ! queue2 name=videoqueue ! decodebin2 name=videodecoder !"; const char* audio = "appsrc name=audiosource ! queue2 name=audioqueue ! decodebin2 name=audiodecoder ! audioconvert ! audiorate ! audioresample ! volume name=audiovolume !"; +#endif char pipeline[1024]; if (!mdecoder) @@ -601,23 +641,23 @@ BOOL tsmf_gstreamer_pipeline_build(TSMFGstreamerDecoder* mdecoder) g_object_set(G_OBJECT(mdecoder->queue), "max-size-bytes", 0, NULL); g_object_set(G_OBJECT(mdecoder->queue), "max-size-time", (guint64) 0, NULL); - // Only set these properties if not an autosink, otherwise we will set properties when real sinks are added + /* Only set these properties if not an autosink, otherwise we will set properties when real sinks are added */ if (!g_strcmp0(G_OBJECT_TYPE_NAME(mdecoder->outsink), "GstAutoVideoSink") && !g_strcmp0(G_OBJECT_TYPE_NAME(mdecoder->outsink), "GstAutoAudioSink")) { if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) { - gst_base_sink_set_max_lateness((GstBaseSink *) mdecoder->outsink, 10000000); //nanoseconds + gst_base_sink_set_max_lateness((GstBaseSink *) mdecoder->outsink, 10000000); /* nanoseconds */ } else { - gst_base_sink_set_max_lateness((GstBaseSink *) mdecoder->outsink, 10000000); //nanoseconds - g_object_set(G_OBJECT(mdecoder->outsink), "buffer-time", (gint64) 20000, NULL); //microseconds - g_object_set(G_OBJECT(mdecoder->outsink), "drift-tolerance", (gint64) 20000, NULL); //microseconds - g_object_set(G_OBJECT(mdecoder->outsink), "latency-time", (gint64) 10000, NULL); //microseconds + gst_base_sink_set_max_lateness((GstBaseSink *) mdecoder->outsink, 10000000); /* nanoseconds */ + g_object_set(G_OBJECT(mdecoder->outsink), "buffer-time", (gint64) 20000, NULL); /* microseconds */ + g_object_set(G_OBJECT(mdecoder->outsink), "drift-tolerance", (gint64) 20000, NULL); /* microseconds */ + g_object_set(G_OBJECT(mdecoder->outsink), "latency-time", (gint64) 10000, NULL); /* microseconds */ g_object_set(G_OBJECT(mdecoder->outsink), "slave-method", 1, NULL); } - g_object_set(G_OBJECT(mdecoder->outsink), "sync", TRUE, NULL); //synchronize on the clock - g_object_set(G_OBJECT(mdecoder->outsink), "async", TRUE, NULL); //no async state changes + g_object_set(G_OBJECT(mdecoder->outsink), "sync", TRUE, NULL); /* synchronize on the clock */ + g_object_set(G_OBJECT(mdecoder->outsink), "async", TRUE, NULL); /* no async state changes */ } tsmf_window_create(mdecoder); @@ -685,22 +725,23 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN return FALSE; } - // Relative timestamping will sometimes be set to 0 - // so we ignore these timestamps just to be safe(bit 8) + /* Relative timestamping will sometimes be set to 0 + * so we ignore these timestamps just to be safe(bit 8) + */ if (extensions & 0x00000080) { DEBUG_TSMF("Ignoring the timestamps - relative - bit 8"); useTimestamps = FALSE; } - //If no timestamps exist then we dont want to look at the timestamp values (bit 7) + /* If no timestamps exist then we dont want to look at the timestamp values (bit 7) */ if (extensions & 0x00000040) { DEBUG_TSMF("Ignoring the timestamps - none - bit 7"); useTimestamps = FALSE; } - // If performing a seek + /* If performing a seek */ if (mdecoder->seeking) { mdecoder->seeking = FALSE; @@ -710,17 +751,18 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN if (mdecoder->pipeline_start_time_valid) { - // Adjusted the condition for a seek to be based on start time only - // WMV1 and WMV2 files in particular have bad end time and duration values - // there seems to be no real side effects of just using the start time instead + /* Adjusted the condition for a seek to be based on start time only + * WMV1 and WMV2 files in particular have bad end time and duration values + * there seems to be no real side effects of just using the start time instead + */ UINT64 minTime = mdecoder->last_sample_start_time - (UINT64) SEEK_TOLERANCE; UINT64 maxTime = mdecoder->last_sample_start_time + (UINT64) SEEK_TOLERANCE; - // Make sure the minTime stops at 0 , should we be at the beginning of the stream + /* Make sure the minTime stops at 0 , should we be at the beginning of the stream */ if (mdecoder->last_sample_start_time < (UINT64) SEEK_TOLERANCE) minTime = 0; - // If the start_time is valid and different from the previous start time by more than the seek tolerance, then we have a seek condition + /* If the start_time is valid and different from the previous start time by more than the seek tolerance, then we have a seek condition */ if (((start_time > maxTime) || (start_time < minTime)) && useTimestamps) { DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%d] > last_sample_start_time=[%d] OR ", (int)start_time, (int)mdecoder->last_sample_start_time); @@ -729,22 +771,24 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN mdecoder->seeking = TRUE; - // since we cant make the gstreamer pipeline jump to the new start time after a seek - we just maintain - // a offset between realtime and gstreamer time + /* since we cant make the gstreamer pipeline jump to the new start time after a seek - we just maintain + * a offset between realtime and gstreamer time + */ mdecoder->seek_offset = start_time; } } else { DEBUG_TSMF("%s start time %d", get_type(mdecoder), start_time); - // Always set base/start time to 0. Will use seek offset to translate real buffer times - // back to 0. This allows the video to be started from anywhere and the ability to handle seeks - // without rebuilding the pipeline, etc. since that is costly + /* Always set base/start time to 0. Will use seek offset to translate real buffer times + * back to 0. This allows the video to be started from anywhere and the ability to handle seeks + * without rebuilding the pipeline, etc. since that is costly + */ gst_element_set_base_time(mdecoder->pipe, tsmf_gstreamer_timestamp_ms_to_gst(0)); gst_element_set_start_time(mdecoder->pipe, tsmf_gstreamer_timestamp_ms_to_gst(0)); mdecoder->pipeline_start_time_valid = 1; - // Set the seek offset if buffer has valid timestamps. + /* Set the seek offset if buffer has valid timestamps. */ if (useTimestamps) mdecoder->seek_offset = start_time; @@ -769,13 +813,13 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN #endif GST_BUFFER_DURATION(gst_buf) = GST_CLOCK_TIME_NONE; GST_BUFFER_OFFSET(gst_buf) = GST_BUFFER_OFFSET_NONE; +#if GST_VERSION_MAJOR > 0 +#else gst_buffer_set_caps(gst_buf, mdecoder->gst_caps); +#endif gst_app_src_push_buffer(GST_APP_SRC(mdecoder->src), gst_buf); - if (mdecoder->ack_cb) - mdecoder->ack_cb(mdecoder->stream, FALSE); - - // Should only update the last timestamps if the current ones are valid + /* Should only update the last timestamps if the current ones are valid */ if (useTimestamps) { mdecoder->last_sample_start_time = start_time; @@ -948,7 +992,7 @@ BOOL tsmf_gstreamer_ack(ITSMFDecoder* decoder, BOOL (*cb)(void *, BOOL), void *s { TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; DEBUG_TSMF(""); - mdecoder->ack_cb = NULL;//cb; + mdecoder->ack_cb = NULL; mdecoder->stream = stream; return TRUE; } diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index 3f4f2e608..644bde57a 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -655,8 +655,9 @@ UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman) return ERROR_NOT_FOUND; } - // Flush message is for a stream, not the entire presentation - // therefore we only flush the stream as intended per the MS-RDPEV spec + /* Flush message is for a stream, not the entire presentation + * therefore we only flush the stream as intended per the MS-RDPEV spec + */ stream = tsmf_stream_find_by_id(presentation, StreamId); if (stream) if (!tsmf_stream_flush(stream)) diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 7d454a60b..7957e97c4 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -38,7 +38,7 @@ void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id) { - wStream* s; + wStream* s = NULL; int status; TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) pChannelCallback; @@ -79,7 +79,7 @@ void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 void tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size) { - wStream *s; + wStream *s = NULL; int status = -1; TSMF_CHANNEL_CALLBACK *callback = (TSMF_CHANNEL_CALLBACK *) pChannelCallback; @@ -87,6 +87,12 @@ void tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, if (!s) return FALSE; + if (s == NULL) + { + WLog_ERR(TAG, "Stream creation error!"); + return; + } + Stream_Write_UINT32(s, TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY); Stream_Write_UINT32(s, message_id); Stream_Write_UINT32(s, PLAYBACK_ACK); /* FunctionId */ diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index e7c69ca1d..3414d1f18 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -56,8 +56,8 @@ #define AUDIO_TOLERANCE 10000000LL -// 1 second -#define VIDEO_ADJUST_MAX 10000000 +/* 1 second = 10,000,000 100ns units*/ +#define VIDEO_ADJUST_MAX 10*1000*1000 #define MAX_ACK_TIME 666667 @@ -193,8 +193,9 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) { /* Check if some other stream has earlier sample that needs to be played first */ - // Start time is more reliable than end time as some stream types seem to have incorrect - // end times from the server + /* Start time is more reliable than end time as some stream types seem to have incorrect + * end times from the server + */ if (stream->last_start_time > AUDIO_TOLERANCE) { ArrayList_Lock(presentation->stream_list); @@ -204,8 +205,9 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) { s = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index); - // Start time is more reliable than end time as some stream types seem to have incorrect - // end times from the server + /* Start time is more reliable than end time as some stream types seem to have incorrect + * end times from the server + */ if (s != stream && !s->eos && s->last_start_time && s->last_start_time < stream->last_start_time - AUDIO_TOLERANCE) { @@ -220,8 +222,9 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) } else { - // Start time is more reliable than end time as some stream types seem to have incorrect - // end times from the server + /* Start time is more reliable than end time as some stream types seem to have incorrect + * end times from the server + */ if (stream->last_start_time > presentation->audio_start_time) { DEBUG_TSMF("Pending due to stream start time > audio start time"); @@ -237,11 +240,11 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) sample = (TSMF_SAMPLE *) Queue_Dequeue(stream->sample_list); - // Only update stream last end time if the sample end time is valid and greater than the current stream end time + /* Only update stream last end time if the sample end time is valid and greater than the current stream end time */ if (sample && (sample->end_time > stream->last_end_time) && (!sample->invalidTimestamps)) stream->last_end_time = sample->end_time; - // Only update stream last start time if the sample start time is valid and greater than the current stream start time + /* Only update stream last start time if the sample start time is valid and greater than the current stream start time */ if (sample && (sample->start_time > stream->last_start_time) && (!sample->invalidTimestamps)) stream->last_start_time = sample->start_time; @@ -278,8 +281,9 @@ static BOOL tsmf_sample_queue_ack(TSMF_SAMPLE* sample) return Queue_Enqueue(sample->stream->sample_ack_list, sample); } -// Returns TRUE if no more samples are currently available -// Returns FALSE otherwise +/* Returns TRUE if no more samples are currently available + * Returns FALSE otherwise + */ static BOOL tsmf_stream_process_ack(void* arg, BOOL force) { TSMF_STREAM* stream = arg; @@ -301,18 +305,18 @@ static BOOL tsmf_stream_process_ack(void* arg, BOOL force) if (!force) { - // Do some min/max ack limiting if we have access to Buffer level information + /* Do some min/max ack limiting if we have access to Buffer level information */ if (stream->decoder->BufferLevel) { - // Try to keep buffer level below max by withholding acks + /* Try to keep buffer level below max by withholding acks */ if (stream->currentBufferLevel > stream->maxBufferLevel) goto finally; - // Try to keep buffer level above min by pushing acks through quickly + /* Try to keep buffer level above min by pushing acks through quickly */ else if (stream->currentBufferLevel < stream->minBufferLevel) goto dequeue; } - // Time based acks only + /* Time based acks only */ ack_time = get_current_time(); if (sample->ack_time > ack_time) @@ -427,8 +431,9 @@ static BOOL tsmf_sample_playback_video(TSMF_SAMPLE* sample) { t = get_current_time(); - // Start time is more reliable than end time as some stream types seem to have incorrect - // end times from the server + /* Start time is more reliable than end time as some stream types seem to have incorrect + * end times from the server + */ if (stream->next_start_time > t && ((sample->start_time >= presentation->audio_start_time) || ((sample->start_time < stream->last_start_time) && (!sample->invalidTimestamps)))) @@ -507,7 +512,7 @@ static BOOL tsmf_sample_playback_audio(TSMF_SAMPLE* sample) sample->ack_time = latency + get_current_time(); - //Only update stream times if the sample timestamps are valid + /* Only update stream times if the sample timestamps are valid */ if (!sample->invalidTimestamps) { stream->last_start_time = sample->start_time + latency; @@ -530,9 +535,10 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) { if (stream->decoder->DecodeEx) { - // Try to "sync" video buffers to audio buffers by looking at the running time for each stream - // The difference between the two running times causes an offset between audio and video actual - // render times. So, we try to adjust timestamps on the video buffer to match those on the audio buffer. + /* Try to "sync" video buffers to audio buffers by looking at the running time for each stream + * The difference between the two running times causes an offset between audio and video actual + * render times. So, we try to adjust timestamps on the video buffer to match those on the audio buffer. + */ if (stream->major_type == TSMF_MAJOR_TYPE_VIDEO) { TSMF_STREAM* temp_stream = NULL; @@ -633,7 +639,7 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) UINT64 ack_anticipation_time = get_current_time(); BOOL buffer_filled = TRUE; - // Classify the buffer as filled once it reaches minimum level + /* Classify the buffer as filled once it reaches minimum level */ if (stream->decoder->BufferLevel) { if (stream->currentBufferLevel < stream->minBufferLevel) @@ -720,7 +726,7 @@ static void* tsmf_stream_ack_func(void *arg) } } - // Stream stopped force all of the acks to happen + /* Stream stopped force all of the acks to happen */ if (ev == WAIT_OBJECT_0) { DEBUG_TSMF("ack: Stream stopped!"); @@ -852,16 +858,17 @@ static BOOL tsmf_stream_stop(TSMF_STREAM* stream) if (!stream || !stream->decoder || !stream->decoder->Control) return TRUE; - // If stopping after eos - we delay until the eos has been processed - // this allows us to process any buffers that have been acked even though - // they have not actually been completely processes by the decoder + /* If stopping after eos - we delay until the eos has been processed + * this allows us to process any buffers that have been acked even though + * they have not actually been completely processes by the decoder + */ if (stream->eos) { DEBUG_TSMF("Setting up a delayed stop for once the eos has been processed."); stream->delayed_stop = 1; return TRUE; } - // Otherwise force stop immediately + /* Otherwise force stop immediately */ else { DEBUG_TSMF("Stop with no pending eos response, so do it immediately."); @@ -1059,8 +1066,9 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, if (!width || !height) return TRUE; - // Streams can be added/removed from the presentation and the server will resend geometry info when a new stream is - // added to the presentation. + /* Streams can be added/removed from the presentation and the server will resend geometry info when a new stream is + * added to the presentation. + */ /* if ((width == presentation->width) && (height == presentation->height) && (x == presentation->x) && (y == presentation->y) && From ca097e7363de4c4356544a0cde7a81ace45801dc Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 3 Sep 2015 12:58:16 -0500 Subject: [PATCH 013/220] Fix minor issues with the previous tsmf commits. --- channels/tsmf/client/gstreamer/tsmf_X11.c | 13 +-- .../tsmf/client/gstreamer/tsmf_gstreamer.c | 17 +-- channels/tsmf/client/tsmf_ifman.c | 9 ++ channels/tsmf/client/tsmf_main.c | 33 +++--- channels/tsmf/client/tsmf_main.h | 4 +- channels/tsmf/client/tsmf_media.c | 102 +++++++----------- channels/tsmf/client/tsmf_media.h | 3 +- 7 files changed, 80 insertions(+), 101 deletions(-) diff --git a/channels/tsmf/client/gstreamer/tsmf_X11.c b/channels/tsmf/client/gstreamer/tsmf_X11.c index c32501301..7c026ee9e 100644 --- a/channels/tsmf/client/gstreamer/tsmf_X11.c +++ b/channels/tsmf/client/gstreamer/tsmf_X11.c @@ -313,11 +313,6 @@ int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, return -3; } -#if GST_VERSION_MAJOR > 0 - GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(decoder->outsink); -#else - GstXOverlay *overlay = GST_X_OVERLAY(decoder->outsink); -#endif if (!decoder) return -1; @@ -331,19 +326,19 @@ int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, { #if GST_VERSION_MAJOR > 0 - if (!gst_video_overlay_set_render_rectangle(overlay, 0, 0, width, height)) + if (!gst_video_overlay_set_render_rectangle(hdl->overlay, 0, 0, width, height)) { WLog_ERR(TAG, "Could not resize overlay!"); } - gst_video_overlay_expose(overlay); + gst_video_overlay_expose(hdl->overlay); #else - if (!gst_x_overlay_set_render_rectangle(overlay, 0, 0, width, height)) + if (!gst_x_overlay_set_render_rectangle(hdl->overlay, 0, 0, width, height)) { WLog_ERR(TAG, "Could not resize overlay!"); } - gst_x_overlay_expose(overlay); + gst_x_overlay_expose(hdl->overlay); #endif } diff --git a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c index 2458d6ec5..b283534ef 100644 --- a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c +++ b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c @@ -116,15 +116,15 @@ static gboolean tsmf_gstreamer_seek_data(GstAppSrc *src, guint64 offset, gpointe return TRUE; } -static void tsmf_gstreamer_change_volume(ITSMFDecoder* decoder, UINT32 newVolume, UINT32 muted) +static BOOL tsmf_gstreamer_change_volume(ITSMFDecoder* decoder, UINT32 newVolume, UINT32 muted) { TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; if (!mdecoder || !mdecoder->pipe) - return; + return TRUE; if (mdecoder->media_type == TSMF_MAJOR_TYPE_VIDEO) - return; + return TRUE; mdecoder->gstMuted = (BOOL) muted; DEBUG_TSMF("mute=[%d]", mdecoder->gstMuted); @@ -132,13 +132,15 @@ static void tsmf_gstreamer_change_volume(ITSMFDecoder* decoder, UINT32 newVolume DEBUG_TSMF("gst_new_vol=[%f]", mdecoder->gstVolume); if (!mdecoder->volume) - return; + return TRUE; if (!G_IS_OBJECT(mdecoder->volume)) - return; + return TRUE; g_object_set(mdecoder->volume, "mute", mdecoder->gstMuted, NULL); g_object_set(mdecoder->volume, "volume", mdecoder->gstVolume, NULL); + + return TRUE; } #ifdef __OpenBSD__ @@ -843,7 +845,10 @@ static BOOL tsmf_gstreamer_control(ITSMFDecoder* decoder, ITSMFControlMsg contro TSMFGstreamerDecoder* mdecoder = (TSMFGstreamerDecoder *) decoder; if (!mdecoder) - return FALSE; + { + WLog_ERR(TAG, "Control called with no decoder!"); + return TRUE; + } if (control_msg == Control_Pause) { diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index 644bde57a..efdfe2021 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -224,6 +224,7 @@ UINT tsmf_ifman_add_stream(TSMF_IFMAN* ifman, rdpContext* rdpcontext) if (!presentation) { + WLog_ERR(TAG, "unknown presentation id"); status = ERROR_NOT_FOUND; } else @@ -232,10 +233,16 @@ UINT tsmf_ifman_add_stream(TSMF_IFMAN* ifman, rdpContext* rdpcontext) Stream_Seek_UINT32(ifman->input); /* numMediaType */ stream = tsmf_stream_new(presentation, StreamId, rdpcontext); if (!stream) + { + WLog_ERR(TAG, "failed to create stream"); return ERROR_OUTOFMEMORY; + } if (!tsmf_stream_set_format(stream, ifman->decoder_name, ifman->input)) + { + WLog_ERR(TAG, "failed to set stream format"); return ERROR_OUTOFMEMORY; + } } ifman->output_pending = TRUE; @@ -660,8 +667,10 @@ UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman) */ stream = tsmf_stream_find_by_id(presentation, StreamId); if (stream) + { if (!tsmf_stream_flush(stream)) return ERROR_INVALID_OPERATION; + } else WLog_ERR(TAG, "unknown stream id"); diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 7957e97c4..d4a590086 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -36,7 +36,7 @@ #include "tsmf_main.h" -void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id) +BOOL tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id) { wStream* s = NULL; int status; @@ -49,21 +49,21 @@ void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 if (!callback) { DEBUG_TSMF("No callback reference - unable to send eos response!"); - return; + return FALSE; } if (callback && callback->stream_id && callback->channel && callback->channel->Write) { s = Stream_New(NULL, 24); if (!s) - return FALSE; + return FALSE; Stream_Write_UINT32(s, TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY); - Stream_Write_UINT32(s, message_id); - Stream_Write_UINT32(s, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ - Stream_Write_UINT32(s, callback->stream_id); /* StreamId */ - Stream_Write_UINT32(s, TSMM_CLIENT_EVENT_ENDOFSTREAM); /* EventId */ - Stream_Write_UINT32(s, 0); /* cbData */ - DEBUG_TSMF("response size %i", Stream_GetPosition(s)); + Stream_Write_UINT32(s, message_id); + Stream_Write_UINT32(s, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ + Stream_Write_UINT32(s, callback->stream_id); /* StreamId */ + Stream_Write_UINT32(s, TSMM_CLIENT_EVENT_ENDOFSTREAM); /* EventId */ + Stream_Write_UINT32(s, 0); /* cbData */ + DEBUG_TSMF("EOS response size %i", Stream_GetPosition(s)); status = callback->channel->Write(callback->channel, Stream_GetPosition(s), Stream_Buffer(s), NULL); if (status) @@ -76,7 +76,7 @@ void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 return (status == 0); } -void tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, +BOOL tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size) { wStream *s = NULL; @@ -87,12 +87,6 @@ void tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, if (!s) return FALSE; - if (s == NULL) - { - WLog_ERR(TAG, "Stream creation error!"); - return; - } - Stream_Write_UINT32(s, TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY); Stream_Write_UINT32(s, message_id); Stream_Write_UINT32(s, PLAYBACK_ACK); /* FunctionId */ @@ -100,7 +94,7 @@ void tsmf_playback_ack(IWTSVirtualChannelCallback *pChannelCallback, Stream_Write_UINT64(s, duration); /* DataDuration */ Stream_Write_UINT64(s, data_size); /* cbData */ - DEBUG_TSMF("response size %d", (int) Stream_GetPosition(s)); + DEBUG_TSMF("ACK response size %d", (int) Stream_GetPosition(s)); if (!callback || !callback->channel || !callback->channel->Write) { @@ -313,6 +307,11 @@ static UINT tsmf_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, input = NULL; ifman.input = NULL; + if (error) + { + WLog_ERR(TAG, "ifman data received processing error %d", error); + } + if (!processed) { switch (FunctionId) diff --git a/channels/tsmf/client/tsmf_main.h b/channels/tsmf/client/tsmf_main.h index c9489f33a..db3c94582 100644 --- a/channels/tsmf/client/tsmf_main.h +++ b/channels/tsmf/client/tsmf_main.h @@ -64,8 +64,8 @@ struct _TSMF_PLUGIN rdpContext* rdpcontext; }; -void tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id); -void tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, +BOOL tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id); +BOOL tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size); #endif diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 3414d1f18..78b8c78eb 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -327,7 +327,7 @@ dequeue: sample = Queue_Dequeue(stream->sample_ack_list); if (sample) { - rc = tsmf_sample_ack(sample); + tsmf_sample_ack(sample); tsmf_sample_free(sample); } @@ -572,9 +572,12 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) if (!ret) { - WLog_ERR(TAG, "decode error"); + WLog_ERR(TAG, "decode error, queue ack anyways"); if (!tsmf_sample_queue_ack(sample)) + { + WLog_ERR(TAG, "error queuing sample for ack"); return FALSE; + } return TRUE; } @@ -593,7 +596,7 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) WLog_ERR(TAG, "unable to decode video format"); if (!tsmf_sample_queue_ack(sample)) { - WLog_ERR(TAG, "error acking sample"); + WLog_ERR(TAG, "error queuing sample for ack"); } return FALSE; } @@ -601,8 +604,6 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) sample->pixfmt = pixfmt; } - ret = FALSE; - if (stream->decoder->GetDecodedDimension) { ret = stream->decoder->GetDecodedDimension(stream->decoder, &width, &height); @@ -658,18 +659,22 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) switch (sample->stream->major_type) { case TSMF_MAJOR_TYPE_VIDEO: - { - break; - } + { + break; + } case TSMF_MAJOR_TYPE_AUDIO: - { - break; - } + { + break; + } } sample->ack_time = ack_anticipation_time; - ret = tsmf_sample_queue_ack(sample); + if (!tsmf_sample_queue_ack(sample)) + { + WLog_ERR(TAG, "error queuing sample for ack"); + ret = FALSE; + } } return ret; @@ -761,7 +766,7 @@ static void* tsmf_stream_playback_func(void *arg) TSMF_STREAM* stream = (TSMF_STREAM *) arg; TSMF_PRESENTATION* presentation = stream->presentation; UINT error = CHANNEL_RC_OK; - DWORD status; + DWORD status; DEBUG_TSMF("in %d", stream->stream_id); @@ -798,7 +803,6 @@ static void* tsmf_stream_playback_func(void *arg) break; } - status = WaitForSingleObject(stream->stopEvent, 0); if (status == WAIT_FAILED) @@ -1004,7 +1008,7 @@ UINT tsmf_presentation_sync(TSMF_PRESENTATION* presentation) { UINT32 index; UINT32 count; - UINT error; + UINT error; ArrayList_Lock(presentation->stream_list); count = ArrayList_Count(presentation->stream_list); @@ -1013,15 +1017,15 @@ UINT tsmf_presentation_sync(TSMF_PRESENTATION* presentation) { TSMF_STREAM* stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index); if (WaitForSingleObject(stream->ready, 500) == WAIT_FAILED) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); - return error; - } + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); + return error; + } } ArrayList_Unlock(presentation->stream_list); - return CHANNEL_RC_OK; + return CHANNEL_RC_OK; } BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation) @@ -1031,8 +1035,6 @@ BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation) TSMF_STREAM* stream; BOOL ret = TRUE; - ret &= tsmf_presentation_flush(presentation); - ArrayList_Lock(presentation->stream_list); count = ArrayList_Count(presentation->stream_list); @@ -1067,17 +1069,8 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, return TRUE; /* Streams can be added/removed from the presentation and the server will resend geometry info when a new stream is - * added to the presentation. + * added to the presentation. So, always process a valid message. */ - /* - if ((width == presentation->width) && (height == presentation->height) && - (x == presentation->x) && (y == presentation->y) && - (num_rects == presentation->nr_rects) && - (0 == memcmp(rects, presentation->rects, num_rects * sizeof(RDP_RECT)))) - { - return TRUE; - } - */ presentation->x = x; presentation->y = y; @@ -1142,30 +1135,6 @@ BOOL tsmf_stream_flush(TSMF_STREAM* stream) return TRUE; } -BOOL tsmf_presentation_flush(TSMF_PRESENTATION* presentation) -{ - UINT32 index; - UINT32 count; - TSMF_STREAM* stream; - BOOL ret = TRUE; - - ArrayList_Lock(presentation->stream_list); - count = ArrayList_Count(presentation->stream_list); - - for (index = 0; index < count; index++) - { - stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index); - ret &= tsmf_stream_flush(stream); - } - - ArrayList_Unlock(presentation->stream_list); - presentation->eos = 0; - presentation->audio_start_time = 0; - presentation->audio_end_time = 0; - - return ret; -} - void _tsmf_presentation_free(TSMF_PRESENTATION* presentation) { tsmf_presentation_stop(presentation); @@ -1304,7 +1273,10 @@ BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char *name, wStream *s) } if (!tsmf_codec_parse_media_type(&mediatype, s)) + { + WLog_ERR(TAG, "unable to parse media type"); return FALSE; + } if (mediatype.MajorType == TSMF_MAJOR_TYPE_VIDEO) { @@ -1370,10 +1342,10 @@ void _tsmf_stream_free(TSMF_STREAM* stream) if (stream->play_thread) { if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED) - { - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); - return; - } + { + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); + return; + } CloseHandle(stream->play_thread); stream->play_thread = NULL; @@ -1382,10 +1354,10 @@ void _tsmf_stream_free(TSMF_STREAM* stream) if (stream->ack_thread) { if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED) - { - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); - return; - } + { + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); + return; + } CloseHandle(stream->ack_thread); stream->ack_thread = NULL; } diff --git a/channels/tsmf/client/tsmf_media.h b/channels/tsmf/client/tsmf_media.h index 47f189f5d..1760fe05a 100644 --- a/channels/tsmf/client/tsmf_media.h +++ b/channels/tsmf/client/tsmf_media.h @@ -49,7 +49,6 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION *presentation, int num_rects, RDP_RECT *rects); void tsmf_presentation_set_audio_device(TSMF_PRESENTATION *presentation, const char *name, const char *device); -BOOL tsmf_presentation_flush(TSMF_PRESENTATION *presentation); void tsmf_presentation_free(TSMF_PRESENTATION *presentation); TSMF_STREAM *tsmf_stream_new(TSMF_PRESENTATION *presentation, UINT32 stream_id, rdpContext* rdpcontext); @@ -57,7 +56,7 @@ TSMF_STREAM *tsmf_stream_find_by_id(TSMF_PRESENTATION *presentation, UINT32 stre BOOL tsmf_stream_set_format(TSMF_STREAM *stream, const char *name, wStream *s); void tsmf_stream_end(TSMF_STREAM *stream, UINT32 message_id, IWTSVirtualChannelCallback* pChannelCallback); void tsmf_stream_free(TSMF_STREAM *stream); -void tsmf_stream_flush(TSMF_STREAM* stream); +BOOL tsmf_stream_flush(TSMF_STREAM* stream); BOOL tsmf_stream_push_sample(TSMF_STREAM *stream, IWTSVirtualChannelCallback *pChannelCallback, UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions, From 0cb54119a508d7d7f6c4296c70b394d3629b57ae Mon Sep 17 00:00:00 2001 From: bjcollins Date: Wed, 16 Sep 2015 12:45:25 -0500 Subject: [PATCH 014/220] Remove strict dependency on Xext for tsmf, it is optional not required --- channels/tsmf/client/gstreamer/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/channels/tsmf/client/gstreamer/CMakeLists.txt b/channels/tsmf/client/gstreamer/CMakeLists.txt index 766c9e958..b42ca3670 100644 --- a/channels/tsmf/client/gstreamer/CMakeLists.txt +++ b/channels/tsmf/client/gstreamer/CMakeLists.txt @@ -48,12 +48,6 @@ else() tsmf_X11.c) set(LIBS ${LIBS} ${X11_LIBRARIES} ${XEXT_LIBRARIES}) - if(NOT XEXT_FOUND) - message(FATAL_ERROR "Xext library not found, but required for TSMF module.") - else() - add_definitions(-DWITH_XEXT=1) - endif() - endif() set(${MODULE_PREFIX}_SRCS "${SRC}") From d9754703f4f17b47f33bc48f5991203d413a99f6 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Wed, 16 Sep 2015 12:46:45 -0500 Subject: [PATCH 015/220] Fixed memory leak in tsmf_send_eos_response() function Correctly handled tsmf geometry updates with no rects = tsmf window should not be shown Add more X Display locking to tsmf gstreamer X11 module --- channels/tsmf/client/gstreamer/tsmf_X11.c | 55 ++++++++++++++++++----- channels/tsmf/client/tsmf_main.c | 6 +-- channels/tsmf/client/tsmf_media.c | 13 +++--- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/channels/tsmf/client/gstreamer/tsmf_X11.c b/channels/tsmf/client/gstreamer/tsmf_X11.c index 7c026ee9e..4d1be90dd 100644 --- a/channels/tsmf/client/gstreamer/tsmf_X11.c +++ b/channels/tsmf/client/gstreamer/tsmf_X11.c @@ -128,8 +128,10 @@ static GstBusSyncReply tsmf_platform_bus_sync_handler(GstBus *bus, GstMessage *m gst_x_overlay_expose(hdl->overlay); #endif + XLockDisplay(hdl->disp); XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth, hdl->subwinHeight); XSync(hdl->disp, FALSE); + XUnlockDisplay(hdl->disp); } } else { g_warning ("Window was not available before retrieving the overlay!"); @@ -283,7 +285,9 @@ int tsmf_window_create(TSMFGstreamerDecoder* decoder) if (!hdl->subwin) { + XLockDisplay(hdl->disp); hdl->subwin = XCreateSimpleWindow(hdl->disp, *(int *)hdl->xfwin, 0, 0, 1, 1, 0, 0, 0); + XUnlockDisplay(hdl->disp); if (!hdl->subwin) { @@ -296,7 +300,9 @@ int tsmf_window_create(TSMFGstreamerDecoder* decoder) decoder->ready = TRUE; #if defined(WITH_XEXT) int event, error; + XLockDisplay(hdl->disp); hdl->has_shape = XShapeQueryExtension(hdl->disp, &event, &error); + XUnlockDisplay(hdl->disp); #endif } @@ -348,29 +354,52 @@ int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, hdl->subwinY = y; hdl->subwinWidth = width; hdl->subwinHeight = height; - XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth, hdl->subwinHeight); -#if defined(WITH_XEXT) + XLockDisplay(hdl->disp); + XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth, hdl->subwinHeight); + + /* Unmap the window if there are no visibility rects */ + if (nr_rects == 0) + tsmf_window_unmap(decoder); + else + tsmf_window_map(decoder); + +#if defined(WITH_XEXT) if (hdl->has_shape) { int i; - XRectangle *xrects = calloc(nr_rects, sizeof(XRectangle)); - if (!xrects) - return -1; + XRectangle *xrects = NULL; - for (i = 0; i < nr_rects; i++) + if (nr_rects == 0) { - xrects[i].x = rects[i].x - x; - xrects[i].y = rects[i].y - y; - xrects[i].width = rects[i].width; - xrects[i].height = rects[i].height; + xrects = calloc(1, sizeof(XRectangle)); + xrects->x = x; + xrects->y = y; + xrects->width = width; + xrects->height = height; } + else + { + xrects = calloc(nr_rects, sizeof(XRectangle)); + } + + if (xrects) + { + for (i = 0; i < nr_rects; i++) + { + xrects[i].x = rects[i].x - x; + xrects[i].y = rects[i].y - y; + xrects[i].width = rects[i].width; + xrects[i].height = rects[i].height; + } - XShapeCombineRectangles(hdl->disp, hdl->subwin, ShapeBounding, x, y, xrects, nr_rects, ShapeSet, 0); - free(xrects); + XShapeCombineRectangles(hdl->disp, hdl->subwin, ShapeBounding, x, y, xrects, nr_rects, ShapeSet, 0); + free(xrects); + } } #endif XSync(hdl->disp, FALSE); + XUnlockDisplay(hdl->disp); } return 0; @@ -453,8 +482,10 @@ int tsmf_window_destroy(TSMFGstreamerDecoder* decoder) if (hdl->subwin) { + XLockDisplay(hdl->disp); XDestroyWindow(hdl->disp, hdl->subwin); XSync(hdl->disp, FALSE); + XUnlockDisplay(hdl->disp); } hdl->overlay = NULL; diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index d4a590086..511ee546d 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -39,13 +39,9 @@ BOOL tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id) { wStream* s = NULL; - int status; + int status = -1; TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) pChannelCallback; - s = Stream_New(NULL, 24); - if (!s) - return FALSE; - if (!callback) { DEBUG_TSMF("No callback reference - unable to send eos response!"); diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 78b8c78eb..26f5c5943 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -1057,29 +1057,26 @@ BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, UINT32 index; UINT32 count; TSMF_STREAM* stream; - void *tmp_rects; + void *tmp_rects = NULL; BOOL ret = TRUE; - if (num_rects < 1 || !rects) - return TRUE; - /* The server may send messages with invalid width / height. * Ignore those messages. */ if (!width || !height) return TRUE; /* Streams can be added/removed from the presentation and the server will resend geometry info when a new stream is - * added to the presentation. So, always process a valid message. + * added to the presentation. Also, num_rects is used to indicate whether or not the window is visible. + * So, always process a valid message with unchanged position/size and/or no visibility rects. */ presentation->x = x; presentation->y = y; presentation->width = width; presentation->height = height; - + tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects); - if (!tmp_rects) - return FALSE; + presentation->nr_rects = num_rects; presentation->rects = tmp_rects; From 9b2d5ce849a414b0e581ce618244404e953173f0 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 17 Sep 2015 16:19:55 -0500 Subject: [PATCH 016/220] Fix logic with stream syncing as the sync offset was not always calculated correctly, which could result in video playback freezing. Fixed formatting of some tsmf debugging timestamps so they are readable/usabe. --- .../tsmf/client/gstreamer/tsmf_gstreamer.c | 22 +++++++++---------- channels/tsmf/client/tsmf_ifman.c | 4 ++-- channels/tsmf/client/tsmf_media.c | 10 +++++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c index b283534ef..87feb45a6 100644 --- a/channels/tsmf/client/gstreamer/tsmf_gstreamer.c +++ b/channels/tsmf/client/gstreamer/tsmf_gstreamer.c @@ -694,9 +694,9 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN * We don't expect to block here often, since the pipeline should * have more than enough buffering. */ - DEBUG_TSMF("%s. Start:(%d) End:(%d) Duration:(%d) Last Start:(%d)", - get_type(mdecoder), (int)start_time, (int)end_time, (int)duration, - (int)mdecoder->last_sample_start_time); + DEBUG_TSMF("%s. Start:(%lu) End:(%lu) Duration:(%d) Last Start:(%lu)", + get_type(mdecoder), start_time, end_time, (int)duration, + mdecoder->last_sample_start_time); if (mdecoder->shutdown) { @@ -753,6 +753,8 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN if (mdecoder->pipeline_start_time_valid) { + DEBUG_TSMF("%s start time %lu", get_type(mdecoder), start_time); + /* Adjusted the condition for a seek to be based on start time only * WMV1 and WMV2 files in particular have bad end time and duration values * there seems to be no real side effects of just using the start time instead @@ -767,9 +769,10 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN /* If the start_time is valid and different from the previous start time by more than the seek tolerance, then we have a seek condition */ if (((start_time > maxTime) || (start_time < minTime)) && useTimestamps) { - DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%d] > last_sample_start_time=[%d] OR ", (int)start_time, (int)mdecoder->last_sample_start_time); - DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%d] < last_sample_start_time=[%d] with", (int)start_time, (int)mdecoder->last_sample_start_time); - DEBUG_TSMF("tsmf_gstreamer_decodeEX: a tolerance of more than [%d] from the last sample", (int) SEEK_TOLERANCE); + DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%lu] > last_sample_start_time=[%lu] OR ", start_time, mdecoder->last_sample_start_time); + DEBUG_TSMF("tsmf_gstreamer_decodeEx: start_time=[%lu] < last_sample_start_time=[%lu] with", start_time, mdecoder->last_sample_start_time); + DEBUG_TSMF("tsmf_gstreamer_decodeEX: a tolerance of more than [%lu] from the last sample", SEEK_TOLERANCE); + DEBUG_TSMF("tsmf_gstreamer_decodeEX: minTime=[%lu] maxTime=[%lu]", minTime, maxTime); mdecoder->seeking = TRUE; @@ -781,7 +784,7 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN } else { - DEBUG_TSMF("%s start time %d", get_type(mdecoder), start_time); + DEBUG_TSMF("%s start time %lu", get_type(mdecoder), start_time); /* Always set base/start time to 0. Will use seek offset to translate real buffer times * back to 0. This allows the video to be started from anywhere and the ability to handle seeks * without rebuilding the pipeline, etc. since that is costly @@ -832,7 +835,7 @@ static BOOL tsmf_gstreamer_decodeEx(ITSMFDecoder* decoder, const BYTE *data, UIN { DEBUG_TSMF("%s: state=%s", get_type(mdecoder), gst_element_state_get_name(GST_STATE(mdecoder->pipe))); - DEBUG_TSMF("Paused: %i Shutdown: %i Ready: %i", mdecoder->paused, mdecoder->shutdown, mdecoder->ready); + DEBUG_TSMF("%s Paused: %i Shutdown: %i Ready: %i", get_type(mdecoder), mdecoder->paused, mdecoder->shutdown, mdecoder->ready); if (!mdecoder->paused && !mdecoder->shutdown && mdecoder->ready) tsmf_gstreamer_pipeline_set_state(mdecoder, GST_STATE_PLAYING); } @@ -963,9 +966,6 @@ static UINT64 tsmf_gstreamer_get_running_time(ITSMFDecoder* decoder) if (!mdecoder->pipe) return 0; - if (GST_STATE(mdecoder->pipe) != GST_STATE_PLAYING) - return 0; - GstFormat fmt = GST_FORMAT_TIME; gint64 pos = 0; #if GST_VERSION_MAJOR > 0 diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index efdfe2021..b4a84dfdb 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -597,9 +597,9 @@ UINT tsmf_ifman_on_sample(TSMF_IFMAN* ifman) if (Stream_GetRemainingLength(ifman->input) < cbData) return ERROR_INVALID_DATA; - DEBUG_TSMF("MessageId %d StreamId %d SampleStartTime %d SampleEndTime %d " + DEBUG_TSMF("MessageId %d StreamId %d SampleStartTime %lu SampleEndTime %lu " "ThrottleDuration %d SampleExtensions %d cbData %d", - ifman->message_id, StreamId, (int)SampleStartTime, (int)SampleEndTime, + ifman->message_id, StreamId, SampleStartTime, SampleEndTime, (int)ThrottleDuration, SampleExtensions, cbData); presentation = tsmf_presentation_find_by_id(ifman->presentation_id); diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 26f5c5943..f7906e2e0 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -553,8 +553,14 @@ static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) { UINT64 video_time = (UINT64) stream->decoder->GetRunningTime(stream->decoder); UINT64 audio_time = (UINT64) temp_stream->decoder->GetRunningTime(temp_stream->decoder); - sample->start_time += abs(video_time - audio_time) > VIDEO_ADJUST_MAX ? (video_time - audio_time) : VIDEO_ADJUST_MAX; - sample->end_time += abs(video_time - audio_time) > VIDEO_ADJUST_MAX ? (video_time - audio_time) : VIDEO_ADJUST_MAX; + UINT64 max_adjust = VIDEO_ADJUST_MAX; + + if (video_time < audio_time) + max_adjust = -VIDEO_ADJUST_MAX; + + sample->start_time += abs(video_time - audio_time) < VIDEO_ADJUST_MAX ? (video_time - audio_time) : max_adjust; + sample->end_time += abs(video_time - audio_time) < VIDEO_ADJUST_MAX ? (video_time - audio_time) : max_adjust; + break; } } From bea27fd919b64ee8d97996409e279e1e83d13594 Mon Sep 17 00:00:00 2001 From: Jean-Louis Dupond Date: Sun, 4 Oct 2015 18:17:33 +0200 Subject: [PATCH 017/220] FindGStreamer_1_0: fix build failure for new gstreamer versions --- cmake/FindGStreamer_1_0.cmake | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cmake/FindGStreamer_1_0.cmake b/cmake/FindGStreamer_1_0.cmake index f7bf990db..3aa8fc6dc 100644 --- a/cmake/FindGStreamer_1_0.cmake +++ b/cmake/FindGStreamer_1_0.cmake @@ -53,17 +53,17 @@ set(GSTREAMER_1_0_MINIMUM_VERSION 1.0.5) # Helper macro to find a Gstreamer plugin (or Gstreamer itself) # _component_prefix is prepended to the _INCLUDE_DIRS and _LIBRARIES variables (eg. "GSTREAMER_1_0_AUDIO") # _pkgconfig_name is the component's pkg-config name (eg. "gstreamer-1.0", or "gstreamer-video-1.0"). -# _header is the component's header, relative to the gstreamer-1.0 directory (eg. "gst/gst.h"). # _library is the component's library name (eg. "gstreamer-1.0" or "gstvideo-1.0") -macro(FIND_GSTREAMER_COMPONENT _component_prefix _pkgconfig_name _header _library) +macro(FIND_GSTREAMER_COMPONENT _component_prefix _pkgconfig_name _library) # FIXME: The QUIET keyword can be used once we require CMake 2.8.2. - pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name}) - find_path(${_component_prefix}_INCLUDE_DIRS - NAMES ${_header} - HINTS ${PC_${_component_prefix}_INCLUDE_DIRS} ${PC_${_component_prefix}_INCLUDEDIR} - PATH_SUFFIXES gstreamer-1.0 - ) + string(REGEX MATCH "(.*)>=(.*)" _dummy "${_pkgconfig_name}") + if ("${CMAKE_MATCH_2}" STREQUAL "") + pkg_check_modules(PC_${_component_prefix} "${_pkgconfig_name} >= ${GStreamer_FIND_VERSION}") + else () + pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name}) + endif () + set(${_component_prefix}_INCLUDE_DIRS ${PC_${_component_prefix}_INCLUDE_DIRS}) find_library(${_component_prefix}_LIBRARIES NAMES ${_library} gstreamer_android @@ -78,8 +78,8 @@ endmacro() # 1.1. Find headers and libraries set(GLIB_ROOT_DIR ${GSTREAMER_1_0_ROOT_DIR}) find_package(Glib REQUIRED) -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0 gstreamer-1.0 gst/gst.h gstreamer-1.0) -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_BASE gstreamer-base-1.0 gst/gst.h gstbase-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0 gstreamer-1.0 gstreamer-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_BASE gstreamer-base-1.0 gstbase-1.0) # 1.2. Check Gstreamer version if (GSTREAMER_1_0_INCLUDE_DIRS) @@ -110,11 +110,11 @@ endif () # 2. Find Gstreamer plugins # ------------------------- -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_APP gstreamer-app-1.0 gst/app/gstappsink.h gstapp-1.0) -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_AUDIO gstreamer-audio-1.0 gst/audio/audio.h gstaudio-1.0) -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_FFT gstreamer-fft-1.0 gst/fft/gstfft.h gstfft-1.0) -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_PBUTILS gstreamer-pbutils-1.0 gst/pbutils/pbutils.h gstpbutils-1.0) -FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_VIDEO gstreamer-video-1.0 gst/video/video.h gstvideo-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_APP gstreamer-app-1.0 gstapp-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_AUDIO gstreamer-audio-1.0 gstaudio-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_FFT gstreamer-fft-1.0 gstfft-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_PBUTILS gstreamer-pbutils-1.0 gstpbutils-1.0) +FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_VIDEO gstreamer-video-1.0 gstvideo-1.0) # ------------------------------------------------ # 3. Process the COMPONENTS passed to FIND_PACKAGE From 86a3b30d25681a054d148a65fb5cf31858ca9198 Mon Sep 17 00:00:00 2001 From: "zihao.jiang" Date: Fri, 25 Sep 2015 01:29:40 +0800 Subject: [PATCH 018/220] Server/Shadow: Fix invalid ALIGN in shadow_client_send_bitmap_update --- server/shadow/shadow_client.c | 6 ++---- server/shadow/shadow_surface.c | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/server/shadow/shadow_client.c b/server/shadow/shadow_client.c index fc141fbe1..7bf5ea7f9 100644 --- a/server/shadow/shadow_client.c +++ b/server/shadow/shadow_client.c @@ -628,14 +628,12 @@ int shadow_client_send_bitmap_update(rdpShadowClient* client, rdpShadowSurface* if ((nWidth % 4) != 0) { - nXSrc -= (nWidth % 4); - nWidth += (nWidth % 4); + nWidth += (4 - (nWidth % 4)); } if ((nHeight % 4) != 0) { - nYSrc -= (nHeight % 4); - nHeight += (nHeight % 4); + nHeight += (4 - (nHeight % 4)); } for (yIdx = 0; yIdx < rows; yIdx++) diff --git a/server/shadow/shadow_surface.c b/server/shadow/shadow_surface.c index d01e4ab76..53d05a96f 100644 --- a/server/shadow/shadow_surface.c +++ b/server/shadow/shadow_surface.c @@ -23,7 +23,7 @@ #include "shadow.h" #include "shadow_surface.h" - +#define ALIGN_SCREEN_SIZE(size, align) ((size + align - 1) & (~(align - 1))) rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y, int width, int height) { rdpShadowSurface* surface; @@ -39,9 +39,9 @@ rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y, int surface->y = y; surface->width = width; surface->height = height; - surface->scanline = (surface->width + (surface->width % 4)) * 4; + surface->scanline = ALIGN_SCREEN_SIZE(surface->width, 4) * 4; - surface->data = (BYTE*) calloc(1, surface->scanline * surface->height); + surface->data = (BYTE*) calloc(1, surface->scanline * ALIGN_SCREEN_SIZE(surface->height, 4)); if (!surface->data) { free (surface); @@ -77,7 +77,7 @@ void shadow_surface_free(rdpShadowSurface* surface) BOOL shadow_surface_resize(rdpShadowSurface *surface, int x, int y, int width, int height) { BYTE* buffer = NULL; - int scanline = (width + (width % 4)) * 4; + int scanline = ALIGN_SCREEN_SIZE(width, 4) * 4; if (!surface) return FALSE; @@ -90,7 +90,7 @@ BOOL shadow_surface_resize(rdpShadowSurface *surface, int x, int y, int width, i return TRUE; } - buffer = (BYTE*) realloc(surface->data, scanline * height); + buffer = (BYTE*) realloc(surface->data, scanline * ALIGN_SCREEN_SIZE(height, 4)); if (buffer) { surface->x = x; From 1030f8dad8aa81ebf01a6a5158ac760e01c2df6f Mon Sep 17 00:00:00 2001 From: clouder Date: Thu, 8 Oct 2015 17:20:44 +0800 Subject: [PATCH 019/220] add values-zh/string.xml --- .../FreeRDPCore/res/values-zh/strings.xml | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 client/Android/FreeRDPCore/res/values-zh/strings.xml diff --git a/client/Android/FreeRDPCore/res/values-zh/strings.xml b/client/Android/FreeRDPCore/res/values-zh/strings.xml new file mode 100644 index 000000000..09757f3de --- /dev/null +++ b/client/Android/FreeRDPCore/res/values-zh/strings.xml @@ -0,0 +1,199 @@ + + + + + + 取消 + 继续 + 登陆 + 断开 + + 退出 + 关于 + 帮助 + 新建连接 + 设置 + + 操作 + 连接 + 编辑 + 删除 + + 键盘 + 功能键 + 触控鼠标 + 主目录 + 断开连接 + + 手动连接 + 活动会话数 + + 搜索 + + 登录 + 没有服务 + 连接中 … + 正在断开连接 … + 连接丢失 + 密码错误 + 用户名错误 + 新建连接 + + 主机信息 + 标签* + 远程主机ip或域名 + 端口 + 登录信息 + 登录信息 + 用户名 + 密码 + + 设置 + 显示 + 显示设置 + 颜色深度 + + High Color (16 Bit) + True Color (24 Bit) + Highest Quality (32 Bit) + + + 16 + 24 + 32 + + 分辨率 + 自动 + 全屏 + 自定义 + + 自动 + 全屏 + 自定义 + 640x480 + 720x480 + 800x600 + 1024x768 + 1280x1024 + 1440x900 + 1920x1080 + 1920x1200 + + + 自动 + 全屏 + 自定义 + 640x480 + 720x480 + 800x600 + 1024x768 + 1280x1024 + 1440x900 + 1920x1080 + 1920x1200 + + 宽度 + 高度 + 连接性能 + 性能设置 + RemoteFX + 桌面背景 + 字体平滑 + 桌面拼合 + 拖动是显示窗口内容 + 菜单动画效果 + 视觉样式 + 高级 + 高级设置 + 3G设置 + 使用3G网络时的显示设置 + 使用3G网络时的连接性能 + 路由 + 使用路由 + 路由设置 + SDCard 重定向 + 音频重定向 + + 不要播放 + 在远程主机播放 + 在此设备上播放 + + + 0 + 1 + 2 + + 麦克风重定向 + 连接协议 + + 自动 + RDP + TLS + NLA + + + 0 + 1 + 2 + 3 + + 远程程序 + 工作目录 + Async channel + Async transport + Async input + Async update + 控制台模式 + + ******* + 未设置 + 用户界面 + 隐藏状态栏 + 隐藏缩放控件 + 交换鼠标左右键 + 翻转滚动 + 触摸指针自动滚屏 + 退出时确认是否退出 + 省电设计 + 关闭空闲连接 + 安全 + 接受所有证书 + 清除证书缓存 + %1$d 秒后 + Disabled + + 连接设置 + 设置 + aFreeRDP - FreeRDP for Android + RDP Connections + 帮助 + 关于 + + 不保存即退出? + 点击 “继续” 继续编辑,点击 "取消" 放弃当前更改 + 建立连接失败! + + 由于主机不支持您的设置所以显示设置已经修改为适应主机的设置! + 清除证书缓存成功! + 清楚证书缓存失败! + + 证书验证 + 未能验证远程主机证书的安全性,是否连接? + 请输入您的证书 + 创建快捷方式 + 快捷方式名称: + 连接中 … + 正在登录 … + 关于aFreeRDP + 是否保存连接设置? + 连接设置还没保存! 是否保存? + 保存? + 是否保存更改? + 不再提示 + 退出? + 是否退出? + 清除证书缓存? + 是否清除所有的证书缓存? + Debug Level + Debug Settings + From 32e2f81cc5701d169036b86047642cf96a20435f Mon Sep 17 00:00:00 2001 From: Daniel Bungert Date: Wed, 14 Oct 2015 14:16:19 -0600 Subject: [PATCH 020/220] Clamp ultra-wide glyph opRight vals to desktop width --- libfreerdp/cache/glyph.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libfreerdp/cache/glyph.c b/libfreerdp/cache/glyph.c index 037c5a5d9..0157d40bc 100644 --- a/libfreerdp/cache/glyph.c +++ b/libfreerdp/cache/glyph.c @@ -260,6 +260,12 @@ BOOL update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fastIndex) if (opRight == 0) opRight = fastIndex->bkRight; + /* Server can send a massive number (32766) which appears to be + * undocumented special behavior for "Erase all the way right". + * X11 has nondeterministic results asking for a draw that wide. */ + if (opRight > context->instance->settings->DesktopWidth) + opRight = context->instance->settings->DesktopWidth; + if (x == -32768) x = fastIndex->bkLeft; @@ -313,6 +319,10 @@ BOOL update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph) if (opRight == 0) opRight = fastGlyph->bkRight; + /* See update_gdi_fast_index opRight comment. */ + if (opRight > context->instance->settings->DesktopWidth) + opRight = context->instance->settings->DesktopWidth; + if (x == -32768) x = fastGlyph->bkLeft; From 6d3565bd4c52125bda5d8bc0b30690d78615c2f5 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 14:29:48 -0500 Subject: [PATCH 021/220] Fix xf_rail_paint fencepost error The regions used to store and calculate the invalidRegion are exclusive of the bottom and right edges, not inclusive. Fixes "mouse droppings" in mspaint.exe when moving the mouse leftwards across the canvas. --- client/X11/xf_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index a788ab2b1..2df32f49e 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -342,7 +342,7 @@ BOOL xf_sw_end_paint(rdpContext* context) xf_lock_x11(xfc, FALSE); - xf_rail_paint(xfc, x, y, x + w - 1, y + h - 1); + xf_rail_paint(xfc, x, y, x + w, y + h); xf_unlock_x11(xfc, FALSE); } @@ -455,7 +455,7 @@ BOOL xf_hw_end_paint(rdpContext* context) xf_lock_x11(xfc, FALSE); - xf_rail_paint(xfc, x, y, x + w - 1, y + h - 1); + xf_rail_paint(xfc, x, y, x + w, y + h); xf_unlock_x11(xfc, FALSE); } From 964f0addbf873c371e0050b7c5ac5133e88130c1 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 14:31:15 -0500 Subject: [PATCH 022/220] Do not support fullscreen toggle keyboard sequence in remote_app mode. There is no support in interface for this and the fullscreen code is not designed to handle remote app windows. --- client/X11/xf_keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 1d6d9c06d..243e920d2 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -466,7 +466,7 @@ BOOL xf_keyboard_handle_special_keys(xfContext* xfc, KeySym keysym) return TRUE; } - if(xfc->fullscreen_toggle) + if(!xfc->remote_app && xfc->fullscreen_toggle) { if (keysym == XK_Return) { From 6934c18adff498441a54c5234501379a8fdd6176 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 14:35:07 -0500 Subject: [PATCH 023/220] Continue processing all other window orders for new remote app windows instead of existing after only looking at part of the information. For instance, window visibility rects are part of the message with the new order and were being ignored. --- client/X11/xf_rail.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index a4617a228..d407cc476 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -299,6 +299,7 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI appWindow->localWindowOffsetCorrX = 0; appWindow->localWindowOffsetCorrY = 0; + /* Ensure window always gets a window title */ if (fieldFlags & WINDOW_ORDER_FIELD_TITLE) { char* title = NULL; @@ -321,8 +322,6 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI HashTable_Add(xfc->railWindows, (void*) (UINT_PTR) orderInfo->windowId, (void*) appWindow); xf_AppWindowInit(xfc, appWindow); - - return TRUE; } else { From 5bfbee8f787206fc5dd912f396120f09ed654b55 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 14:39:59 -0500 Subject: [PATCH 024/220] Ensure that app windows always get a window type assigned to them. --- client/X11/xf_window.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index b7a4663e2..802613c6c 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -567,9 +567,11 @@ void xf_SetWindowStyle(xfContext* xfc, xfAppWindow* appWindow, UINT32 style, UIN } else { - XChangeProperty(xfc->display, appWindow->handle, xfc->_NET_WM_WINDOW_TYPE, - XA_ATOM, 32, PropModeReplace, (BYTE*) &window_type, 1); + window_type = xfc->_NET_WM_WINDOW_TYPE_NORMAL; } + + XChangeProperty(xfc->display, appWindow->handle, xfc->_NET_WM_WINDOW_TYPE, + XA_ATOM, 32, PropModeReplace, (BYTE*) &window_type, 1); } void xf_SetWindowText(xfContext* xfc, xfAppWindow* appWindow, char* name) From d1a8119dac13702bfba92aaab39f5f6c7e3b631f Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 14:47:10 -0500 Subject: [PATCH 025/220] RemoteApp support Remove use of WindowRects to affect window shape, the VisibilityRects are used for this purpose. --- client/X11/xf_rail.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index d407cc476..d5e949580 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -506,7 +506,8 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI if (fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) { - xf_SetWindowRects(xfc, appWindow, appWindow->windowRects, appWindow->numWindowRects); + /* We should only be using the visibility rects for shaping the window */ + //xf_SetWindowRects(xfc, appWindow, appWindow->windowRects, appWindow->numWindowRects); } if (fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) From cb4e4cf6fcb38efc6d0f9e2fd03c7036b9ede700 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 14:59:53 -0500 Subject: [PATCH 026/220] Store Miscellaneous X11 Atoms into variables to match how we handle other X11 Atoms. --- client/X11/xf_client.c | 5 +++++ client/X11/xf_window.c | 20 +++++++++++--------- client/X11/xfreerdp.h | 7 +++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 2df32f49e..49684cba7 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1850,7 +1850,11 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) xfc->_NET_WORKAREA = XInternAtom(xfc->display, "_NET_WORKAREA", False); xfc->_NET_WM_STATE = XInternAtom(xfc->display, "_NET_WM_STATE", False); xfc->_NET_WM_STATE_FULLSCREEN = XInternAtom(xfc->display, "_NET_WM_STATE_FULLSCREEN", False); + xfc->_NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + xfc->_NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_VERT", False); xfc->_NET_WM_FULLSCREEN_MONITORS = XInternAtom(xfc->display, "_NET_WM_FULLSCREEN_MONITORS", False); + xfc->_NET_WM_NAME = XInternAtom(xfc->display, "_NET_WM_NAME", False); + xfc->_NET_WM_PID = XInternAtom(xfc->display, "_NET_WM_PID", False); xfc->_NET_WM_WINDOW_TYPE = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE", False); xfc->_NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_NORMAL", False); xfc->_NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_DIALOG", False); @@ -1865,6 +1869,7 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) xfc->WM_DELETE_WINDOW = XInternAtom(xfc->display, "WM_DELETE_WINDOW", False); xfc->WM_STATE = XInternAtom(xfc->display, "WM_STATE", False); + xfc->UTF8_STRING = XInternAtom(xfc->display, "UTF8_STRING", FALSE); xfc->xfds = ConnectionNumber(xfc->display); xfc->screen_number = DefaultScreen(xfc->display); xfc->screen = ScreenOfDisplay(xfc->display, xfc->screen_number); diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 802613c6c..b9810e55a 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -327,7 +327,7 @@ static void xf_SetWindowPID(xfContext* xfc, Window window, pid_t pid) if (!pid) pid = getpid(); - am_wm_pid = XInternAtom(xfc->display, "_NET_WM_PID", False); + am_wm_pid = xfc->_NET_WM_PID; XChangeProperty(xfc->display, window, am_wm_pid, XA_CARDINAL, 32, PropModeReplace, (BYTE*) &pid, 1); @@ -579,8 +579,8 @@ void xf_SetWindowText(xfContext* xfc, xfAppWindow* appWindow, char* name) const size_t i = strlen(name); XStoreName(xfc->display, appWindow->handle, name); - Atom wm_Name = XInternAtom(xfc->display, "_NET_WM_NAME", FALSE); - Atom utf8Str = XInternAtom(xfc->display, "UTF8_STRING", FALSE); + Atom wm_Name = xfc->_NET_WM_NAME; + Atom utf8Str = xfc->UTF8_STRING; XChangeProperty(xfc->display, appWindow->handle, wm_Name, utf8Str, 8, PropModeReplace, (unsigned char *)name, i); @@ -823,9 +823,10 @@ void xf_ShowWindow(xfContext* xfc, xfAppWindow* appWindow, BYTE state) case WINDOW_SHOW_MAXIMIZED: /* Set the window as maximized */ - xf_SendClientEvent(xfc, appWindow->handle, xfc->_NET_WM_STATE, 4, 1, - XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_VERT", False), - XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False), 0); + xf_SendClientEvent(xfc, appWindow->handle, xfc->_NET_WM_STATE, 4, + _NET_WM_STATE_ADD, + xfc->_NET_WM_STATE_MAXIMIZED_VERT, + xfc->_NET_WM_STATE_MAXIMIZED_HORZ, 0); /* * This is a workaround for the case where the window is maximized locally before the rail server is told to maximize * the window, this appears to be a race condition where the local window with incomplete data and once the window is @@ -840,9 +841,10 @@ void xf_ShowWindow(xfContext* xfc, xfAppWindow* appWindow, BYTE state) case WINDOW_SHOW: /* Ensure the window is not maximized */ - xf_SendClientEvent(xfc, appWindow->handle, xfc->_NET_WM_STATE, 4, 0, - XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_VERT", False), - XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False), 0); + xf_SendClientEvent(xfc, appWindow->handle, xfc->_NET_WM_STATE, 4, + _NET_WM_STATE_REMOVE, + xfc->_NET_WM_STATE_MAXIMIZED_VERT, + xfc->_NET_WM_STATE_MAXIMIZED_HORZ, 0); /* * Ignore configure requests until both the Maximized properties have been processed * to prevent condition where WM overrides size of request due to one or both of these properties diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index 5e1bdfab1..a885536c7 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -185,6 +185,8 @@ struct xf_context xfClipboard* clipboard; CliprdrClientContext* cliprdr; + Atom UTF8_STRING; + Atom _NET_WM_ICON; Atom _MOTIF_WM_HINTS; Atom _NET_CURRENT_DESKTOP; @@ -192,11 +194,16 @@ struct xf_context Atom _NET_WM_STATE; Atom _NET_WM_STATE_FULLSCREEN; + Atom _NET_WM_STATE_MAXIMIZED_HORZ; + Atom _NET_WM_STATE_MAXIMIZED_VERT; Atom _NET_WM_STATE_SKIP_TASKBAR; Atom _NET_WM_STATE_SKIP_PAGER; Atom _NET_WM_FULLSCREEN_MONITORS; + Atom _NET_WM_NAME; + Atom _NET_WM_PID; + Atom _NET_WM_WINDOW_TYPE; Atom _NET_WM_WINDOW_TYPE_NORMAL; Atom _NET_WM_WINDOW_TYPE_DIALOG; From cc676c44687c58fc6042b0ec1684b9fcf2263757 Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 18:18:21 -0500 Subject: [PATCH 027/220] Remote app support All window state order offsets are signed according to the RDP spec, lets treat them as such. --- client/X11/xf_window.h | 16 ++++++++-------- include/freerdp/window.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client/X11/xf_window.h b/client/X11/xf_window.h index 9120fd1df..2fd9de22d 100644 --- a/client/X11/xf_window.h +++ b/client/X11/xf_window.h @@ -102,22 +102,22 @@ struct xf_app_window UINT32 dwExStyle; UINT32 showState; - UINT32 clientOffsetX; - UINT32 clientOffsetY; + INT32 clientOffsetX; + INT32 clientOffsetY; UINT32 clientAreaWidth; UINT32 clientAreaHeight; - UINT32 windowOffsetX; - UINT32 windowOffsetY; - UINT32 windowClientDeltaX; - UINT32 windowClientDeltaY; + INT32 windowOffsetX; + INT32 windowOffsetY; + INT32 windowClientDeltaX; + INT32 windowClientDeltaY; UINT32 windowWidth; UINT32 windowHeight; UINT32 numWindowRects; RECTANGLE_16* windowRects; - UINT32 visibleOffsetX; - UINT32 visibleOffsetY; + INT32 visibleOffsetX; + INT32 visibleOffsetY; UINT32 numVisibilityRects; RECTANGLE_16* visibilityRects; diff --git a/include/freerdp/window.h b/include/freerdp/window.h index c52c35c72..4a5b2b84f 100644 --- a/include/freerdp/window.h +++ b/include/freerdp/window.h @@ -174,22 +174,22 @@ struct _WINDOW_STATE_ORDER UINT32 extendedStyle; UINT32 showState; RAIL_UNICODE_STRING titleInfo; - UINT32 clientOffsetX; - UINT32 clientOffsetY; + INT32 clientOffsetX; + INT32 clientOffsetY; UINT32 clientAreaWidth; UINT32 clientAreaHeight; UINT32 RPContent; UINT32 rootParentHandle; - UINT32 windowOffsetX; - UINT32 windowOffsetY; - UINT32 windowClientDeltaX; - UINT32 windowClientDeltaY; + INT32 windowOffsetX; + INT32 windowOffsetY; + INT32 windowClientDeltaX; + INT32 windowClientDeltaY; UINT32 windowWidth; UINT32 windowHeight; UINT32 numWindowRects; RECTANGLE_16* windowRects; - UINT32 visibleOffsetX; - UINT32 visibleOffsetY; + INT32 visibleOffsetX; + INT32 visibleOffsetY; UINT32 numVisibilityRects; RECTANGLE_16* visibilityRects; }; From 8e27b6d05e9bfcc2b869583f14779bce1c07823e Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 18:41:55 -0500 Subject: [PATCH 028/220] RemoteApp Support 1. Remove all uses of "localWindowOffsetCorr" variables, they added an extra layer of complexity and they are not actually needed to handle coordination of window position/size between the local coordinate system and the remote one. This logic was causing issues in the case where the window was moved off the left side of the screen. 2. Update the xf_setWindowVisibilityRects function to offset the visibility rects as necessary when the window is hanging off the left side of the screen. 3. Stop sending mouse events when doing keyboard moves/sizes(as desired), and stop sending two mouse events for non-keyboard moves/sizes 4. Move location of new UTF8_STRING variable from previous commit 5. Refresh window and window shape for any window position/size updates, this helps keep the local and server windows in sync and works around some race conditions --- client/X11/xf_client.c | 3 +- client/X11/xf_event.c | 3 +- client/X11/xf_rail.c | 125 +++++++++++++++++------------------------ client/X11/xf_window.c | 22 +++----- client/X11/xf_window.h | 2 +- 5 files changed, 66 insertions(+), 89 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 49684cba7..a7afe4bfe 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1865,11 +1865,12 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) xfc->_NET_WM_STATE_SKIP_PAGER = XInternAtom(xfc->display, "_NET_WM_STATE_SKIP_PAGER", False); xfc->_NET_WM_MOVERESIZE = XInternAtom(xfc->display, "_NET_WM_MOVERESIZE", False); xfc->_NET_MOVERESIZE_WINDOW = XInternAtom(xfc->display, "_NET_MOVERESIZE_WINDOW", False); + + xfc->UTF8_STRING = XInternAtom(xfc->display, "UTF8_STRING", FALSE); xfc->WM_PROTOCOLS = XInternAtom(xfc->display, "WM_PROTOCOLS", False); xfc->WM_DELETE_WINDOW = XInternAtom(xfc->display, "WM_DELETE_WINDOW", False); xfc->WM_STATE = XInternAtom(xfc->display, "WM_STATE", False); - xfc->UTF8_STRING = XInternAtom(xfc->display, "UTF8_STRING", FALSE); xfc->xfds = ConnectionNumber(xfc->display); xfc->screen_number = DefaultScreen(xfc->display); xfc->screen = ScreenOfDisplay(xfc->display, xfc->screen_number); diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 5f13d503d..18328f392 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -278,7 +278,8 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win xf_event_adjust_coordinates(xfc, &x, &y); - input->MouseEvent(input, PTR_FLAGS_MOVE, x, y); + if (!app || xf_AppWindowFromX11Window(xfc,window)->local_move.direction != RAIL_WMSZ_KEYSIZE) + input->MouseEvent(input, PTR_FLAGS_MOVE, x, y); if (xfc->fullscreen && !app) { diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index d5e949580..22a941c53 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -119,25 +119,17 @@ void xf_rail_adjust_position(xfContext* xfc, xfAppWindow* appWindow) return; /* If current window position disagrees with RDP window position, send update to RDP server */ - if (appWindow->x != (appWindow->windowOffsetX - appWindow->localWindowOffsetCorrX) || - appWindow->y != (appWindow->windowOffsetY - appWindow->localWindowOffsetCorrY) || + if (appWindow->x != appWindow->windowOffsetX || + appWindow->y != appWindow->windowOffsetY || appWindow->width != appWindow->windowWidth || appWindow->height != appWindow->windowHeight) { - /* - * windowOffset corresponds to the window location on the rail server - * but our local window is based uses a local offset since the windowOffset - * can be negative and but X does not support negative values. Not using an - * offset can result in blank areas for a maximized window - */ windowMove.windowId = appWindow->windowId; /* * Calculate new size/position for the rail window(new values for windowOffsetX/windowOffsetY/windowWidth/windowHeight) on the server - * New position is based on: Current local rail window offset + - * Local offset correction(current correction value to translate the local window offset to the server rail window offset) */ - windowMove.left = appWindow->x + appWindow->localWindowOffsetCorrX; - windowMove.top = appWindow->y + appWindow->localWindowOffsetCorrY; + windowMove.left = appWindow->x; + windowMove.top = appWindow->y; windowMove.right = windowMove.left + appWindow->width; windowMove.bottom = windowMove.top + appWindow->height; @@ -163,12 +155,10 @@ void xf_rail_end_local_move(xfContext* xfc, xfAppWindow* appWindow) /* * Calculate new size/position for the rail window(new values for windowOffsetX/windowOffsetY/windowWidth/windowHeight) on the server - * New position is based on: Current local rail window offset + - * Local offset correction(current correction value to translate the local window offset to the server rail window offset) * */ - windowMove.left = appWindow->x + appWindow->localWindowOffsetCorrX; - windowMove.top = appWindow->y + appWindow->localWindowOffsetCorrY; + windowMove.left = appWindow->x; + windowMove.top = appWindow->y; windowMove.right = windowMove.left + appWindow->width; /* In the update to RDP the position is one past the window */ windowMove.bottom = windowMove.top + appWindow->height; @@ -180,8 +170,6 @@ void xf_rail_end_local_move(xfContext* xfc, xfAppWindow* appWindow) XQueryPointer(xfc->display, appWindow->handle, &root_window, &child_window, &x, &y, &child_x, &child_y, &mask); - input->MouseEvent(input, PTR_FLAGS_BUTTON1, x, y); - /* only send the mouse coordinates if not a keyboard move or size */ if ((appWindow->local_move.direction != _NET_WM_MOVERESIZE_MOVE_KEYBOARD) && (appWindow->local_move.direction != _NET_WM_MOVERESIZE_SIZE_KEYBOARD)) @@ -194,8 +182,8 @@ void xf_rail_end_local_move(xfContext* xfc, xfAppWindow* appWindow) * we can start to receive GDI orders for the new window dimensions before we * receive the RAIL ORDER for the new window size. This avoids that race condition. */ - appWindow->windowOffsetX = windowMove.left; - appWindow->windowOffsetY = windowMove.top; + appWindow->windowOffsetX = appWindow->x; + appWindow->windowOffsetY = appWindow->y; appWindow->windowWidth = appWindow->width; appWindow->windowHeight = appWindow->height; appWindow->local_move.state = LMS_TERMINATING; @@ -277,6 +265,7 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI xfAppWindow* appWindow = NULL; xfContext* xfc = (xfContext*) context; UINT32 fieldFlags = orderInfo->fieldFlags; + BOOL position_or_size_updated = FALSE; if (fieldFlags & WINDOW_ORDER_STATE_NEW) { @@ -296,9 +285,6 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI appWindow->width = appWindow->windowWidth = windowState->windowWidth; appWindow->height = appWindow->windowHeight = windowState->windowHeight; - appWindow->localWindowOffsetCorrX = 0; - appWindow->localWindowOffsetCorrY = 0; - /* Ensure window always gets a window title */ if (fieldFlags & WINDOW_ORDER_FIELD_TITLE) { @@ -332,37 +318,31 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI if (!appWindow) return FALSE; + /* Keep track of any position/size update so that we can force a refresh of the window */ + if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) || + (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) || + (fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) || + (fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) || + (fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) || + (fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) || + (fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)) + { + position_or_size_updated = TRUE; + } + + /* Update Parameters */ - if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) || - (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)) + if (fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) { - if (fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) - { - appWindow->windowOffsetX = windowState->windowOffsetX; - appWindow->windowOffsetY = windowState->windowOffsetY; + appWindow->windowOffsetX = windowState->windowOffsetX; + appWindow->windowOffsetY = windowState->windowOffsetY; + } - /* - * The rail server can give negative window coordinates when updating windowOffsetX and windowOffsetY, - * but we can only send unsigned integers to the rail server. Therefore, we maintain a local offset. - */ - - if (appWindow->windowOffsetX < 0) - appWindow->localWindowOffsetCorrX = 0 - appWindow->windowOffsetX; - else - appWindow->localWindowOffsetCorrX = 0; - - if (appWindow->windowOffsetY < 0) - appWindow->localWindowOffsetCorrY = 0 - appWindow->windowOffsetY; - else - appWindow->localWindowOffsetCorrY = 0; - } - - if (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) - { - appWindow->windowWidth = windowState->windowWidth; - appWindow->windowHeight = windowState->windowHeight; - } + if (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) + { + appWindow->windowWidth = windowState->windowWidth; + appWindow->windowHeight = windowState->windowHeight; } if (fieldFlags & WINDOW_ORDER_FIELD_OWNER) @@ -478,42 +458,43 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI xf_SetWindowText(xfc, appWindow, appWindow->title); } - if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) || - (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)) + if (position_or_size_updated) { + UINT32 visibilityRectsOffsetX = (appWindow->visibleOffsetX - (appWindow->clientOffsetX - appWindow->windowClientDeltaX)); + UINT32 visibilityRectsOffsetY = (appWindow->visibleOffsetY - (appWindow->clientOffsetY - appWindow->windowClientDeltaY)); + /* * The rail server like to set the window to a small size when it is minimized even though it is hidden * in some cases this can cause the window not to restore back to its original size. Therefore we don't * update our local window when that rail window state is minimized */ - if (appWindow->rail_state == WINDOW_SHOW_MINIMIZED) - return TRUE; + if (appWindow->rail_state != WINDOW_SHOW_MINIMIZED) + { - /* Do nothing if window is already in the correct position */ - if (appWindow->x == (appWindow->windowOffsetX - appWindow->localWindowOffsetCorrX) && - appWindow->y == (appWindow->windowOffsetY - appWindow->localWindowOffsetCorrY) && + /* Redraw window area if already in the correct position */ + if (appWindow->x == appWindow->windowOffsetX && + appWindow->y == appWindow->windowOffsetY && appWindow->width == appWindow->windowWidth && appWindow->height == appWindow->windowHeight) - { - xf_UpdateWindowArea(xfc, appWindow, 0, 0, appWindow->windowWidth, appWindow->windowHeight); - } - else - { - xf_MoveWindow(xfc, appWindow, appWindow->windowOffsetX - appWindow->localWindowOffsetCorrX, appWindow->windowOffsetY - appWindow->localWindowOffsetCorrY, - appWindow->windowWidth, appWindow->windowHeight); + { + xf_UpdateWindowArea(xfc, appWindow, 0, 0, appWindow->windowWidth, appWindow->windowHeight); + } + else + { + xf_MoveWindow(xfc, appWindow, appWindow->windowOffsetX, appWindow->windowOffsetY, + appWindow->windowWidth, appWindow->windowHeight); + } + + xf_SetWindowVisibilityRects(xfc, appWindow, visibilityRectsOffsetX, visibilityRectsOffsetY, appWindow->visibilityRects, appWindow->numVisibilityRects); } } - if (fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) + /* We should only be using the visibility rects for shaping the window */ + /*if (fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) { - /* We should only be using the visibility rects for shaping the window */ - //xf_SetWindowRects(xfc, appWindow, appWindow->windowRects, appWindow->numWindowRects); - } + xf_SetWindowRects(xfc, appWindow, appWindow->windowRects, appWindow->numWindowRects); + }*/ - if (fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) - { - xf_SetWindowVisibilityRects(xfc, appWindow, appWindow->visibilityRects, appWindow->numVisibilityRects); - } return TRUE; } diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index b9810e55a..f4c832be3 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -927,7 +927,7 @@ void xf_SetWindowRects(xfContext* xfc, xfAppWindow* appWindow, RECTANGLE_16* rec } -void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, RECTANGLE_16* rects, int nrects) +void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, UINT32 rectsOffsetX, UINT32 rectsOffsetY, RECTANGLE_16* rects, int nrects) { int i; XRectangle* xrects; @@ -946,7 +946,7 @@ void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, RECTANG xrects[i].height = rects[i].bottom - rects[i].top; } - XShapeCombineRectangles(xfc->display, appWindow->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0); + XShapeCombineRectangles(xfc->display, appWindow->handle, ShapeBounding, rectsOffsetX, rectsOffsetY, xrects, nrects, ShapeSet, 0); free(xrects); #endif @@ -955,20 +955,14 @@ void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, RECTANG void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int width, int height) { int ax, ay; - UINT32 translatedWindowOffsetX; - UINT32 translatedWindowOffsetY; - /* Translate the server rail window offset to a local offset */ - translatedWindowOffsetX = (appWindow->windowOffsetX - appWindow->localWindowOffsetCorrX); - translatedWindowOffsetY = (appWindow->windowOffsetY - appWindow->localWindowOffsetCorrY); + ax = x + appWindow->windowOffsetX; + ay = y + appWindow->windowOffsetY; - ax = x + translatedWindowOffsetX; - ay = y + translatedWindowOffsetY; - - if (ax + width > translatedWindowOffsetX + appWindow->width) - width = (translatedWindowOffsetX + appWindow->width - 1) - ax; - if (ay + height > translatedWindowOffsetY + appWindow->height) - height = (translatedWindowOffsetY + appWindow->height - 1) - ay; + if (ax + width > appWindow->windowOffsetX + appWindow->windowWidth) + width = (appWindow->windowOffsetX + appWindow->windowWidth - 1) - ax; + if (ay + height > appWindow->windowOffsetY + appWindow->windowHeight) + height = (appWindow->windowOffsetY + appWindow->windowHeight - 1) - ay; xf_lock_x11(xfc, TRUE); diff --git a/client/X11/xf_window.h b/client/X11/xf_window.h index 2fd9de22d..0a41c798a 100644 --- a/client/X11/xf_window.h +++ b/client/X11/xf_window.h @@ -160,7 +160,7 @@ void xf_MoveWindow(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int wid void xf_ShowWindow(xfContext* xfc, xfAppWindow* appWindow, BYTE state); //void xf_SetWindowIcon(xfContext* xfc, xfAppWindow* appWindow, rdpIcon* icon); void xf_SetWindowRects(xfContext* xfc, xfAppWindow* appWindow, RECTANGLE_16* rects, int nrects); -void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, RECTANGLE_16* rects, int nrects); +void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, UINT32 rectsOffsetX, UINT32 rectsOffsetY, RECTANGLE_16* rects, int nrects); void xf_SetWindowStyle(xfContext* xfc, xfAppWindow* appWindow, UINT32 style, UINT32 ex_style); void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int width, int height); void xf_DestroyWindow(xfContext* xfc, xfAppWindow* appWindow); From ace5bba0ed722cbf69369782f0124b4c2ed752af Mon Sep 17 00:00:00 2001 From: bjcollins Date: Thu, 15 Oct 2015 19:10:04 -0500 Subject: [PATCH 029/220] Cleanup unnecessary/unintended changes from last commit --- client/X11/xf_event.c | 3 +-- client/X11/xf_window.c | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 18328f392..5f13d503d 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -278,8 +278,7 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win xf_event_adjust_coordinates(xfc, &x, &y); - if (!app || xf_AppWindowFromX11Window(xfc,window)->local_move.direction != RAIL_WMSZ_KEYSIZE) - input->MouseEvent(input, PTR_FLAGS_MOVE, x, y); + input->MouseEvent(input, PTR_FLAGS_MOVE, x, y); if (xfc->fullscreen && !app) { diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index f4c832be3..973cc2374 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -959,10 +959,10 @@ void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, i ax = x + appWindow->windowOffsetX; ay = y + appWindow->windowOffsetY; - if (ax + width > appWindow->windowOffsetX + appWindow->windowWidth) - width = (appWindow->windowOffsetX + appWindow->windowWidth - 1) - ax; - if (ay + height > appWindow->windowOffsetY + appWindow->windowHeight) - height = (appWindow->windowOffsetY + appWindow->windowHeight - 1) - ay; + if (ax + width > appWindow->windowOffsetX + appWindow->width) + width = (appWindow->windowOffsetX + appWindow->width - 1) - ax; + if (ay + height > appWindow->windowOffsetY + appWindow->height) + height = (appWindow->windowOffsetY + appWindow->height - 1) - ay; xf_lock_x11(xfc, TRUE); From 934c4ff7a4a405109739604c4ddc9ad830d16a78 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 16 Oct 2015 15:54:26 +0800 Subject: [PATCH 030/220] update values-zh/strings.xml --- client/Android/FreeRDPCore/res/values-zh/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Android/FreeRDPCore/res/values-zh/strings.xml b/client/Android/FreeRDPCore/res/values-zh/strings.xml index 09757f3de..b4514265c 100644 --- a/client/Android/FreeRDPCore/res/values-zh/strings.xml +++ b/client/Android/FreeRDPCore/res/values-zh/strings.xml @@ -5,7 +5,7 @@ 取消 继续 - 登陆 + 登录 断开 退出 From 75ae38dff2b6fd59695ef1ba259e9bb0ffb2e0f7 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 16 Oct 2015 09:50:18 +0200 Subject: [PATCH 031/220] Silenced VerifyX509Certificate logging. Now only writing log entries if something was an actual error, otherwise stay silent. --- libfreerdp/crypto/tls.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 82ecea9a9..63ff9b4a8 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -67,12 +67,12 @@ static int bio_rdp_tls_write(BIO* bio, const char* buf, int size) return 0; BIO_clear_flags(bio, BIO_FLAGS_WRITE | BIO_FLAGS_READ | BIO_FLAGS_IO_SPECIAL); - + EnterCriticalSection(&tls->lock); status = SSL_write(tls->ssl, buf, size); error = SSL_get_error(tls->ssl, status); - + LeaveCriticalSection(&tls->lock); if (status <= 0) @@ -126,12 +126,12 @@ static int bio_rdp_tls_read(BIO* bio, char* buf, int size) BIO_clear_flags(bio, BIO_FLAGS_WRITE | BIO_FLAGS_READ | BIO_FLAGS_IO_SPECIAL); EnterCriticalSection(&tls->lock); - + status = SSL_read(tls->ssl, buf, size); error = SSL_get_error(tls->ssl, status); LeaveCriticalSection(&tls->lock); - + if (status <= 0) { switch (error) @@ -394,7 +394,7 @@ static int bio_rdp_tls_new(BIO* bio) return 0; bio->ptr = (void*) tls; - + InitializeCriticalSectionAndSpinCount(&tls->lock, 4000); return 1; @@ -425,7 +425,7 @@ static int bio_rdp_tls_free(BIO* bio) } DeleteCriticalSection(&tls->lock); - + free(tls); return 1; @@ -1105,17 +1105,19 @@ int tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname, int por status = -1; if (instance->VerifyX509Certificate) - { status = instance->VerifyX509Certificate(instance, pemCert, length, hostname, port, tls->isGatewayTransport); - } - - WLog_ERR(TAG, "(length = %d) status: %d%s", length, status, pemCert); + else + WLog_ERR(TAG, "No VerifyX509Certificate callback registered!"); free(pemCert); BIO_free(bio); if (status < 0) + { + WLog_ERR(TAG, "VerifyX509Certificate failed: (length = %d) status: [%d] %s", + length, status, pemCert); return -1; + } return (status == 0) ? 0 : 1; } From 26d102c6dc81850559224e80c991a9836e043998 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Fri, 16 Oct 2015 11:40:25 +0200 Subject: [PATCH 032/220] cliprdr/server: Don't call CloseHandle on EventHandle --- channels/cliprdr/server/cliprdr_main.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 4480f9716..23f29d8d3 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -1409,12 +1409,6 @@ static UINT cliprdr_server_close(CliprdrServerContext* context) cliprdr->ChannelHandle = NULL; } - if (cliprdr->ChannelEvent) - { - CloseHandle(cliprdr->ChannelEvent); - cliprdr->ChannelEvent = NULL; - } - return CHANNEL_RC_OK; } From 83d58ccfe8b8cab54a17fcc7e3c7879a8e2479f0 Mon Sep 17 00:00:00 2001 From: "zihao.jiang" Date: Fri, 16 Oct 2015 02:52:02 +0800 Subject: [PATCH 033/220] GDI: Fix usage of gdi_get_brush_pointer. Currently we get color from brush according to the offset in the paint region. According to MSDN https://msdn.microsoft.com/en-us/library/dd183396(v=vs.85).aspx, it should get color according to dest position instead of offset in paint region. --- include/freerdp/gdi/gdi.h | 2 ++ libfreerdp/gdi/16bpp.c | 23 ++++++++++------------- libfreerdp/gdi/32bpp.c | 25 +++++++++++-------------- libfreerdp/gdi/8bpp.c | 23 ++++++++++------------- libfreerdp/gdi/brush.c | 6 +++--- libfreerdp/gdi/gdi.c | 21 +++++++++++++++++++-- 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/include/freerdp/gdi/gdi.h b/include/freerdp/gdi/gdi.h index 9736ba724..87bcbc12b 100644 --- a/include/freerdp/gdi/gdi.h +++ b/include/freerdp/gdi/gdi.h @@ -224,6 +224,8 @@ struct _GDI_BRUSH int style; HGDI_BITMAP pattern; GDI_COLOR color; + int nXOrg; + int nYOrg; }; typedef struct _GDI_BRUSH GDI_BRUSH; typedef GDI_BRUSH* HGDI_BRUSH; diff --git a/libfreerdp/gdi/16bpp.c b/libfreerdp/gdi/16bpp.c index 1ee8a0f6b..e292d7c47 100644 --- a/libfreerdp/gdi/16bpp.c +++ b/libfreerdp/gdi/16bpp.c @@ -487,7 +487,7 @@ static BOOL BitBlt_PSDPxax_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); srcp++; dstp++; @@ -518,7 +518,7 @@ static BOOL BitBlt_SPna_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidt { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp & ~(*patp); srcp++; dstp++; @@ -543,7 +543,7 @@ static BOOL BitBlt_DPa_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp & *patp; dstp++; @@ -568,7 +568,7 @@ static BOOL BitBlt_PDxn_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidt { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp ^ ~(*patp); dstp++; } @@ -626,7 +626,7 @@ static BOOL BitBlt_MERGECOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp & *patp; srcp++; dstp++; @@ -692,13 +692,10 @@ static BOOL BitBlt_PATCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW } else { - /* align pattern to 8x8 grid to make sure transition - between different pattern blocks are smooth */ - if (hdcDest->brush->style == GDI_BS_HATCHED) { - xOffset = nXDest % 8; - yOffset = nYDest % 8 + 2; // +2 added after comparison to mstsc + xOffset = 0; + yOffset = 2; // +2 added after comparison to mstsc } else { @@ -713,7 +710,7 @@ static BOOL BitBlt_PATCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x+xOffset, y+yOffset); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x + xOffset, nYDest + y + yOffset); *dstp = *patp; dstp++; } @@ -759,7 +756,7 @@ static BOOL BitBlt_PATINVERT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *patp ^ *dstp; dstp++; } @@ -789,7 +786,7 @@ static BOOL BitBlt_PATPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n { for (x = 0; x < nWidth; x++) { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp | (*patp | ~(*srcp)); srcp++; dstp++; diff --git a/libfreerdp/gdi/32bpp.c b/libfreerdp/gdi/32bpp.c index f9124bbae..74d1b8065 100644 --- a/libfreerdp/gdi/32bpp.c +++ b/libfreerdp/gdi/32bpp.c @@ -526,7 +526,7 @@ static BOOL BitBlt_PSDPxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); srcp++; dstp++; @@ -583,7 +583,7 @@ static BOOL BitBlt_SPDSxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp ^ (*patp & (*dstp ^ *srcp)); srcp++; dstp++; @@ -614,7 +614,7 @@ static BOOL BitBlt_SPna_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidt { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp & ~(*patp); srcp++; @@ -668,7 +668,7 @@ static BOOL BitBlt_DPa_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp & *patp; dstp++; @@ -693,7 +693,7 @@ static BOOL BitBlt_PDxn_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidt { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp ^ ~(*patp); dstp++; @@ -723,7 +723,7 @@ static BOOL BitBlt_MERGECOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp & *patp; srcp++; @@ -790,13 +790,10 @@ static BOOL BitBlt_PATCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW } else { - /* align pattern to 8x8 grid to make sure transition - between different pattern blocks are smooth */ - if (hdcDest->brush->style == GDI_BS_HATCHED) { - xOffset = nXDest % 8; - yOffset = nYDest % 8 + 2; // +2 added after comparison to mstsc + xOffset = 0; + yOffset = 2; // +2 added after comparison to mstsc } else { @@ -811,7 +808,7 @@ static BOOL BitBlt_PATCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x+xOffset, y+yOffset); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x + xOffset, nYDest + y + yOffset); *dstp = *patp; dstp++; } @@ -857,7 +854,7 @@ static BOOL BitBlt_PATINVERT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *patp ^ *dstp; dstp++; } @@ -887,7 +884,7 @@ static BOOL BitBlt_PATPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n { for (x = 0; x < nWidth; x++) { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp | (*patp | ~(*srcp)); srcp++; dstp++; diff --git a/libfreerdp/gdi/8bpp.c b/libfreerdp/gdi/8bpp.c index 4299d38d3..1303bbccb 100644 --- a/libfreerdp/gdi/8bpp.c +++ b/libfreerdp/gdi/8bpp.c @@ -396,7 +396,7 @@ static BOOL BitBlt_PSDPxax_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi { for (x = 0; x < nWidth; x++) { - patp = (BYTE*) gdi_get_brush_pointer(hdcDest, x, y); + patp = (BYTE*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); srcp++; dstp++; @@ -427,7 +427,7 @@ static BOOL BitBlt_SPna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x, y); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp & ~(*patp); patp++; @@ -454,7 +454,7 @@ static BOOL BitBlt_DPa_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x, y); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp & *patp; dstp++; @@ -479,7 +479,7 @@ static BOOL BitBlt_PDxn_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x, y); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp ^ ~(*patp); patp++; @@ -538,7 +538,7 @@ static BOOL BitBlt_MERGECOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x, y); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *srcp & *patp; patp++; @@ -604,13 +604,10 @@ static BOOL BitBlt_PATCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi } else { - /* align pattern to 8x8 grid to make sure transition - between different pattern blocks are smooth */ - if (hdcDest->brush->style == GDI_BS_HATCHED) { - xOffset = nXDest % 8; - yOffset = nYDest % 8 + 2; // +2 added after comparison to mstsc + xOffset = 0; + yOffset = 2; // +2 added after comparison to mstsc } else { @@ -625,7 +622,7 @@ static BOOL BitBlt_PATCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x+xOffset, y+yOffset); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x + xOffset, nYDest + y + yOffset); *dstp = *patp; patp++; @@ -671,7 +668,7 @@ static BOOL BitBlt_PATINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x, y); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *patp ^ *dstp; patp++; @@ -703,7 +700,7 @@ static BOOL BitBlt_PATPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW { for (x = 0; x < nWidth; x++) { - patp = gdi_get_brush_pointer(hdcDest, x, y); + patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); *dstp = *dstp | (*patp | ~(*srcp)); patp++; diff --git a/libfreerdp/gdi/brush.c b/libfreerdp/gdi/brush.c index 0fadb9768..4a83e043c 100644 --- a/libfreerdp/gdi/brush.c +++ b/libfreerdp/gdi/brush.c @@ -53,7 +53,7 @@ p_PatBlt PatBlt_[5] = HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor) { - HGDI_BRUSH hBrush = (HGDI_BRUSH) malloc(sizeof(GDI_BRUSH)); + HGDI_BRUSH hBrush = (HGDI_BRUSH) calloc(1, sizeof(GDI_BRUSH)); if (!hBrush) return NULL; hBrush->objectType = GDIOBJECT_BRUSH; @@ -71,7 +71,7 @@ HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor) HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp) { - HGDI_BRUSH hBrush = (HGDI_BRUSH) malloc(sizeof(GDI_BRUSH)); + HGDI_BRUSH hBrush = (HGDI_BRUSH) calloc(1, sizeof(GDI_BRUSH)); if (!hBrush) return NULL; hBrush->objectType = GDIOBJECT_BRUSH; @@ -82,7 +82,7 @@ HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp) HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp) { - HGDI_BRUSH hBrush = (HGDI_BRUSH) malloc(sizeof(GDI_BRUSH)); + HGDI_BRUSH hBrush = (HGDI_BRUSH) calloc(1, sizeof(GDI_BRUSH)); if (!hBrush) return NULL; hBrush->objectType = GDIOBJECT_BRUSH; diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 271ecd7ef..3e62ad135 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -371,6 +371,13 @@ INLINE BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, int x, int y) } } +/** + * Get current color in brush bitmap according to dest coordinates.\n + * @msdn{dd183396} + * @param x dest x-coordinate + * @param y dest y-coordinate + * @return color + */ INLINE BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, int x, int y) { BYTE * p; @@ -381,10 +388,14 @@ INLINE BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, int x, int y) { HGDI_BITMAP hBmpBrush = hdcBrush->brush->pattern; + /* According to @msdn{dd183396}, the system always positions a brush bitmap + * at the brush origin and copy across the client area. + * Calculate the offset of the mapped pixel in the brush bitmap according to + * brush origin and dest coordinates */ if (x >= 0 && y >= 0) { - x = x % hBmpBrush->width; - y = y % hBmpBrush->height; + x = (x + hBmpBrush->width - (hdcBrush->brush->nXOrg % hBmpBrush->width)) % hBmpBrush->width; + y = (y + hBmpBrush->height - (hdcBrush->brush->nYOrg % hBmpBrush->height)) % hBmpBrush->height; p = hBmpBrush->data + (y * hBmpBrush->scanline) + (x * hBmpBrush->bytesPerPixel); return p; } @@ -661,6 +672,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) ret = FALSE; goto out_error; } + gdi->drawing->hdc->brush->nXOrg = brush->x; + gdi->drawing->hdc->brush->nYOrg = brush->y; if (!gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) @@ -719,6 +732,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) ret = FALSE; goto out_error; } + gdi->drawing->hdc->brush->nXOrg = brush->x; + gdi->drawing->hdc->brush->nYOrg = brush->y; if (!gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) @@ -952,6 +967,8 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) gdi_DeleteObject((HGDIOBJECT) hBmp); goto out_fail; } + gdi->drawing->hdc->brush->nXOrg = brush->x; + gdi->drawing->hdc->brush->nYOrg = brush->y; gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, From e8fb821be7f72166b3ef3fdf7a717d4766f81fc4 Mon Sep 17 00:00:00 2001 From: "zihao.jiang" Date: Sun, 18 Oct 2015 17:53:22 +0800 Subject: [PATCH 034/220] GDI: Fix gdi_bitmap_update to check dest buffer size. --- libfreerdp/gdi/gdi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 271ecd7ef..fd7236dc7 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -536,9 +536,14 @@ static BOOL gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) pDstData = gdi->primary_buffer; nDstStep = gdi->width * gdi->bytesPerPixel; - nWidth = bitmap->destRight - bitmap->destLeft + 1; /* clip width */ - nHeight = bitmap->destBottom - bitmap->destTop + 1; /* clip height */ + nWidth = MIN(bitmap->destRight, gdi->width - 1) - bitmap->destLeft + 1; /* clip width */ + nHeight = MIN(bitmap->destBottom, gdi->height - 1) - bitmap->destTop + 1; /* clip height */ + if (nWidth <= 0 || nHeight <= 0) + { + /* Empty bitmap */ + continue; + } status = freerdp_image_copy(pDstData, gdi->format, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, gdi->format, nSrcStep, nXSrc, nYSrc, gdi->palette); From 95fe9ecfab458489a2e3aa95772c6ef64d329b6a Mon Sep 17 00:00:00 2001 From: LookBehind Date: Tue, 20 Oct 2015 18:05:09 +0400 Subject: [PATCH 035/220] Fix rdp_recv_logon_error_info As https://msdn.microsoft.com/en-us/library/cc240641.aspx says - first is going errorNotificationType then errorNotificationData. --- libfreerdp/core/info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index fcebceb43..6fbff79da 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -723,14 +723,14 @@ BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s) BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s) { - UINT32 errorNotificationData; UINT32 errorNotificationType; + UINT32 errorNotificationData; if (Stream_GetRemainingLength(s) < 8) return FALSE; - Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */ Stream_Read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */ + Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */ WLog_DBG(TAG, "LogonErrorInfo: Data: 0x%04X Type: 0x%04X", errorNotificationData, errorNotificationType); From a4580923e77b4690a5fe90a8e37a042bc5a8fa06 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Tue, 20 Oct 2015 21:28:29 +0200 Subject: [PATCH 036/220] xfreerdp/clipr: fix self owned test and hardening - xf_cliprdr_is_self_owned() lied if multiple xfreerdp instances were running. - fixed a few unchecked callocs - added/modified and handled some return values in compliance with the new hardened channel api --- client/X11/xf_client.c | 4 +- client/X11/xf_cliprdr.c | 172 ++++++++++++++++++++++------------------ 2 files changed, 100 insertions(+), 76 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index a788ab2b1..b45f18c35 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1177,7 +1177,9 @@ BOOL xf_post_connect(freerdp* instance) update->PlaySound = xf_play_sound; update->SetKeyboardIndicators = xf_keyboard_set_indicators; - xfc->clipboard = xf_clipboard_new(xfc); + if (!(xfc->clipboard = xf_clipboard_new(xfc))) + return FALSE; + if (freerdp_channels_post_connect(channels, instance) < 0) return FALSE; diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index ea38b8ac9..c474e743e 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -63,7 +63,6 @@ struct xf_clipboard Window root_window; Atom clipboard_atom; Atom property_atom; - Atom identity_atom; int numClientFormats; xfCliprdrFormat clientFormats[20]; @@ -97,7 +96,7 @@ struct xf_clipboard BOOL xfixes_supported; }; -int xf_cliprdr_send_client_format_list(xfClipboard* clipboard); +UINT xf_cliprdr_send_client_format_list(xfClipboard* clipboard); static void xf_cliprdr_check_owner(xfClipboard* clipboard) { @@ -118,36 +117,9 @@ static void xf_cliprdr_check_owner(xfClipboard* clipboard) static BOOL xf_cliprdr_is_self_owned(xfClipboard* clipboard) { - Atom type; - UINT32 id = 0; - UINT32* pid = NULL; - int format, result = 0; - unsigned long length; - unsigned long bytes_left; xfContext* xfc = clipboard->xfc; - clipboard->owner = XGetSelectionOwner(xfc->display, clipboard->clipboard_atom); - - if (clipboard->owner != None) - { - result = XGetWindowProperty(xfc->display, clipboard->owner, - clipboard->identity_atom, 0, 4, 0, XA_INTEGER, - &type, &format, &length, &bytes_left, (BYTE**) &pid); - } - - if (pid) - { - id = *pid; - XFree(pid); - } - - if ((clipboard->owner == None) || (clipboard->owner == xfc->drawable)) - return FALSE; - - if (result != Success) - return FALSE; - - return (id ? TRUE : FALSE); + return XGetSelectionOwner(xfc->display, clipboard->clipboard_atom) == xfc->drawable; } static xfCliprdrFormat* xf_cliprdr_get_format_by_id(xfClipboard* clipboard, UINT32 formatId) @@ -191,7 +163,12 @@ static xfCliprdrFormat* xf_cliprdr_get_format_by_atom(xfClipboard* clipboard, At return NULL; } -static void xf_cliprdr_send_data_request(xfClipboard* clipboard, UINT32 formatId) +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT xf_cliprdr_send_data_request(xfClipboard* clipboard, UINT32 formatId) { CLIPRDR_FORMAT_DATA_REQUEST request; @@ -199,10 +176,15 @@ static void xf_cliprdr_send_data_request(xfClipboard* clipboard, UINT32 formatId request.requestedFormatId = formatId; - clipboard->context->ClientFormatDataRequest(clipboard->context, &request); + return clipboard->context->ClientFormatDataRequest(clipboard->context, &request); } -static void xf_cliprdr_send_data_response(xfClipboard* clipboard, BYTE* data, int size) +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT xf_cliprdr_send_data_response(xfClipboard* clipboard, BYTE* data, int size) { CLIPRDR_FORMAT_DATA_RESPONSE response; @@ -212,7 +194,7 @@ static void xf_cliprdr_send_data_response(xfClipboard* clipboard, BYTE* data, in response.dataLen = size; response.requestedFormatData = data; - clipboard->context->ClientFormatDataResponse(clipboard->context, &response); + return clipboard->context->ClientFormatDataResponse(clipboard->context, &response); } static void xf_cliprdr_get_requested_targets(xfClipboard* clipboard) @@ -236,7 +218,18 @@ static void xf_cliprdr_get_requested_targets(xfClipboard* clipboard) 0, 200, 0, XA_ATOM, &atom, &format_property, &length, &bytes_left, &data); if (length > 0) - formats = (CLIPRDR_FORMAT*) calloc(length, sizeof(CLIPRDR_FORMAT)); + { + if (!data) + { + WLog_ERR(TAG, "XGetWindowProperty set length = %d but data is NULL", length); + goto out; + } + if (!(formats = (CLIPRDR_FORMAT*) calloc(length, sizeof(CLIPRDR_FORMAT)))) + { + WLog_ERR(TAG, "failed to allocate %d CLIPRDR_FORMAT structs", length); + goto out; + } + } for (i = 0; i < length; i++) { @@ -252,8 +245,6 @@ static void xf_cliprdr_get_requested_targets(xfClipboard* clipboard) } } - XFree(data); - ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); formatList.msgFlags = CB_RESPONSE_OK; @@ -262,6 +253,9 @@ static void xf_cliprdr_get_requested_targets(xfClipboard* clipboard) clipboard->context->ClientFormatList(clipboard->context, &formatList); +out: + if (data) + XFree(data); free(formats); } @@ -515,7 +509,11 @@ static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard, XEvent* delayRespond = FALSE; - respond = (XEvent*) calloc(1, sizeof(XEvent)); + if (!(respond = (XEvent*) calloc(1, sizeof(XEvent)))) + { + WLog_ERR(TAG, "failed to allocate XEvent data"); + return FALSE; + } respond->xselection.property = None; respond->xselection.type = SelectionNotify; @@ -702,7 +700,12 @@ void xf_cliprdr_handle_xevent(xfContext* xfc, XEvent* event) } } -int xf_cliprdr_send_client_capabilities(xfClipboard* clipboard) +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT xf_cliprdr_send_client_capabilities(xfClipboard* clipboard) { CLIPRDR_CAPABILITIES capabilities; CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet; @@ -716,22 +719,33 @@ int xf_cliprdr_send_client_capabilities(xfClipboard* clipboard) generalCapabilitySet.version = CB_CAPS_VERSION_2; generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES; - clipboard->context->ClientCapabilities(clipboard->context, &capabilities); - - return 1; + return clipboard->context->ClientCapabilities(clipboard->context, &capabilities); } -int xf_cliprdr_send_client_format_list(xfClipboard* clipboard) +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT xf_cliprdr_send_client_format_list(xfClipboard* clipboard) { UINT32 i, numFormats; - CLIPRDR_FORMAT* formats; + CLIPRDR_FORMAT* formats = NULL; CLIPRDR_FORMAT_LIST formatList; xfContext* xfc = clipboard->xfc; + UINT ret; ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); numFormats = clipboard->numClientFormats; - formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT)); + if (numFormats) + { + if (!(formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT)))) + { + WLog_ERR(TAG, "failed to allocate %d CLIPRDR_FORMAT structs", numFormats); + return CHANNEL_RC_NO_MEMORY; + } + } for (i = 0; i < numFormats; i++) { @@ -743,7 +757,7 @@ int xf_cliprdr_send_client_format_list(xfClipboard* clipboard) formatList.numFormats = numFormats; formatList.formats = formats; - clipboard->context->ClientFormatList(clipboard->context, &formatList); + ret = clipboard->context->ClientFormatList(clipboard->context, &formatList); free(formats); @@ -754,10 +768,15 @@ int xf_cliprdr_send_client_format_list(xfClipboard* clipboard) clipboard->targets[1], clipboard->property_atom, xfc->drawable, CurrentTime); } - return 1; + return ret; } -int xf_cliprdr_send_client_format_list_response(xfClipboard* clipboard, BOOL status) +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT xf_cliprdr_send_client_format_list_response(xfClipboard* clipboard, BOOL status) { CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse; @@ -765,11 +784,14 @@ int xf_cliprdr_send_client_format_list_response(xfClipboard* clipboard, BOOL sta formatListResponse.msgFlags = status ? CB_RESPONSE_OK : CB_RESPONSE_FAIL; formatListResponse.dataLen = 0; - clipboard->context->ClientFormatListResponse(clipboard->context, &formatListResponse); - - return 1; + return clipboard->context->ClientFormatListResponse(clipboard->context, &formatListResponse); } +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ int xf_cliprdr_send_client_format_data_request(xfClipboard* clipboard, UINT32 formatId) { CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest; @@ -780,9 +802,7 @@ int xf_cliprdr_send_client_format_data_request(xfClipboard* clipboard, UINT32 fo formatDataRequest.requestedFormatId = formatId; clipboard->requestedFormatId = formatId; - clipboard->context->ClientFormatDataRequest(clipboard->context, &formatDataRequest); - - return 1; + return clipboard->context->ClientFormatDataRequest(clipboard->context, &formatDataRequest); } /** @@ -793,9 +813,13 @@ int xf_cliprdr_send_client_format_data_request(xfClipboard* clipboard, UINT32 fo static UINT xf_cliprdr_monitor_ready(CliprdrClientContext* context, CLIPRDR_MONITOR_READY* monitorReady) { xfClipboard* clipboard = (xfClipboard*) context->custom; + UINT ret; + + if ((ret = xf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK) + return ret; + if ((ret = xf_cliprdr_send_client_format_list(clipboard)) != CHANNEL_RC_OK) + return ret; - xf_cliprdr_send_client_capabilities(clipboard); - xf_cliprdr_send_client_format_list(clipboard); clipboard->sync = TRUE; return CHANNEL_RC_OK; @@ -824,6 +848,7 @@ static UINT xf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR CLIPRDR_FORMAT* format; xfClipboard* clipboard = (xfClipboard*) context->custom; xfContext* xfc = clipboard->xfc; + UINT ret; if (clipboard->data) { @@ -843,10 +868,14 @@ static UINT xf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR } clipboard->numServerFormats = formatList->numFormats; - clipboard->serverFormats = (CLIPRDR_FORMAT*) calloc(clipboard->numServerFormats, sizeof(CLIPRDR_FORMAT)); - if (!clipboard->serverFormats) - return CHANNEL_RC_NO_MEMORY; + if (clipboard->numServerFormats) + { + if (!(clipboard->serverFormats = (CLIPRDR_FORMAT*) calloc(clipboard->numServerFormats, sizeof(CLIPRDR_FORMAT)))) { + WLog_ERR(TAG, "failed to allocate %d CLIPRDR_FORMAT structs", clipboard->numServerFormats); + return CHANNEL_RC_NO_MEMORY; + } + } for (i = 0; i < formatList->numFormats; i++) { @@ -863,7 +892,7 @@ static UINT xf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR clipboard->numServerFormats = 0; free(clipboard->serverFormats); clipboard->serverFormats = NULL; - return -1; + return CHANNEL_RC_NO_MEMORY; } } } @@ -883,13 +912,13 @@ static UINT xf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR } } - xf_cliprdr_send_client_format_list_response(clipboard, TRUE); + ret = xf_cliprdr_send_client_format_list_response(clipboard, TRUE); XSetSelectionOwner(xfc->display, clipboard->clipboard_atom, xfc->drawable, CurrentTime); XFlush(xfc->display); - return CHANNEL_RC_OK; + return ret; } /** @@ -924,15 +953,10 @@ static UINT xf_cliprdr_server_format_data_request(CliprdrClientContext* context, XA_INTEGER, 32, PropModeReplace, (BYTE*) &formatId, 1); } else - { format = xf_cliprdr_get_format_by_id(clipboard, formatId); - } if (!format) - { - xf_cliprdr_send_data_response(clipboard, NULL, 0); - return CHANNEL_RC_OK; - } + return xf_cliprdr_send_data_response(clipboard, NULL, 0); clipboard->requestedFormatId = formatId; @@ -1055,11 +1079,14 @@ static UINT xf_cliprdr_server_format_data_response(CliprdrClientContext* context xfClipboard* xf_clipboard_new(xfContext* xfc) { int n; - UINT32 id; rdpChannels* channels; xfClipboard* clipboard; - clipboard = (xfClipboard*) calloc(1, sizeof(xfClipboard)); + if (!(clipboard = (xfClipboard*) calloc(1, sizeof(xfClipboard)))) + { + WLog_ERR(TAG, "failed to allocate xfClipboard data"); + return NULL; + } xfc->clipboard = clipboard; @@ -1082,12 +1109,7 @@ xfClipboard* xf_clipboard_new(xfContext* xfc) return NULL; } - id = 1; clipboard->property_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR", FALSE); - clipboard->identity_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR_ID", FALSE); - - XChangeProperty(xfc->display, xfc->drawable, clipboard->identity_atom, - XA_INTEGER, 32, PropModeReplace, (BYTE*) &id, 1); XSelectInput(xfc->display, clipboard->root_window, PropertyChangeMask); From b2398b3a9adccc17bbce21d113dc5e1366378e67 Mon Sep 17 00:00:00 2001 From: Martin Haimberger Date: Wed, 21 Oct 2015 01:11:06 -0700 Subject: [PATCH 037/220] wlog: fixed return values wlog used to return an int but the only meaning of the return value was: * negative ... error * 0 or positive ... success but the positve returned value was 1 or some id of some subsystem, nothing meaningful for the caller. For a more meaningful returnvalue we now use BOOL. If something goes wrong FALSE is returned. --- winpr/include/winpr/wlog.h | 36 ++--- winpr/libwinpr/utils/test/TestWLogCallback.c | 12 +- winpr/libwinpr/utils/wlog/Appender.c | 12 +- winpr/libwinpr/utils/wlog/BinaryAppender.c | 42 ++--- winpr/libwinpr/utils/wlog/CallbackAppender.c | 47 +++--- winpr/libwinpr/utils/wlog/ConsoleAppender.c | 35 +++-- winpr/libwinpr/utils/wlog/DataMessage.c | 10 +- winpr/libwinpr/utils/wlog/DataMessage.h | 2 +- winpr/libwinpr/utils/wlog/FileAppender.c | 42 ++--- winpr/libwinpr/utils/wlog/ImageMessage.c | 6 +- winpr/libwinpr/utils/wlog/ImageMessage.h | 2 +- winpr/libwinpr/utils/wlog/Layout.c | 3 +- winpr/libwinpr/utils/wlog/PacketMessage.c | 8 +- winpr/libwinpr/utils/wlog/PacketMessage.h | 2 +- winpr/libwinpr/utils/wlog/wlog.c | 157 +++++++++++-------- winpr/libwinpr/utils/wlog/wlog.h | 2 +- 16 files changed, 223 insertions(+), 195 deletions(-) diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 88e2f4a3c..7e76d2c6e 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -117,12 +117,12 @@ struct _wLogLayout #define WLOG_PACKET_INBOUND 1 #define WLOG_PACKET_OUTBOUND 2 -typedef int (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); -typedef int (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); -typedef int (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef int (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef int (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef int (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); +typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); +typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); #define WLOG_APPENDER_COMMON() \ DWORD Type; \ @@ -181,10 +181,10 @@ struct _wLogBinaryAppender }; typedef struct _wLogBinaryAppender wLogBinaryAppender; -typedef void (*CallbackAppenderMessage_t)(const wLogMessage *msg); -typedef void (*CallbackAppenderData_t)(const wLogMessage *msg); -typedef void (*CallbackAppenderImage_t)(const wLogMessage *msg); -typedef void (*CallbackAppenderPackage_t)(const wLogMessage *msg); +typedef BOOL (*CallbackAppenderMessage_t)(const wLogMessage *msg); +typedef BOOL (*CallbackAppenderData_t)(const wLogMessage *msg); +typedef BOOL (*CallbackAppenderImage_t)(const wLogMessage *msg); +typedef BOOL (*CallbackAppenderPackage_t)(const wLogMessage *msg); struct _wLogCallbackAppender { @@ -229,8 +229,8 @@ struct _wLog DWORD ChildrenSize; }; -WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...); -WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args); +WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...); +WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args); #define WLog_Print(_log, _log_level, _fmt, ...) \ do { \ @@ -314,20 +314,20 @@ WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) #define WLog_FATAL(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, fmt, ## __VA_ARGS__) WINPR_API DWORD WLog_GetLogLevel(wLog* log); -WINPR_API void WLog_SetLogLevel(wLog* log, DWORD logLevel); +WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel); WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType); -WINPR_API int WLog_OpenAppender(wLog* log); -WINPR_API int WLog_CloseAppender(wLog* log); +WINPR_API BOOL WLog_OpenAppender(wLog* log); +WINPR_API BOOL WLog_CloseAppender(wLog* log); -WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream); +WINPR_API BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream); WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename); WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath); -WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, +WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, CallbackAppenderData_t data); @@ -338,7 +338,7 @@ WINPR_API wLog* WLog_GetRoot(void); WINPR_API wLog* WLog_Get(LPCSTR name); WINPR_API BOOL WLog_Init(void); -WINPR_API void WLog_Uninit(void); +WINPR_API BOOL WLog_Uninit(void); #ifdef __cplusplus } diff --git a/winpr/libwinpr/utils/test/TestWLogCallback.c b/winpr/libwinpr/utils/test/TestWLogCallback.c index 2a6f8bb30..8cccbe52a 100644 --- a/winpr/libwinpr/utils/test/TestWLogCallback.c +++ b/winpr/libwinpr/utils/test/TestWLogCallback.c @@ -59,24 +59,28 @@ static BOOL check(const wLogMessage *msg) return rc; } -void CallbackAppenderMessage(const wLogMessage *msg) +BOOL CallbackAppenderMessage(const wLogMessage *msg) { check(msg); + return TRUE; } -void CallbackAppenderData(const wLogMessage *msg) +BOOL CallbackAppenderData(const wLogMessage *msg) { fprintf(stdout, "%s\n", __FUNCTION__); + return TRUE; } -void CallbackAppenderImage(const wLogMessage *msg) +BOOL CallbackAppenderImage(const wLogMessage *msg) { fprintf(stdout, "%s\n", __FUNCTION__); + return TRUE; } -void CallbackAppenderPackage(const wLogMessage *msg) +BOOL CallbackAppenderPackage(const wLogMessage *msg) { fprintf(stdout, "%s\n", __FUNCTION__); + return TRUE; } int TestWLogCallback(int argc, char* argv[]) diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index d54ec52ab..33b422c15 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -121,7 +121,7 @@ BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType) return log->Appender != NULL; } -int WLog_OpenAppender(wLog* log) +BOOL WLog_OpenAppender(wLog* log) { int status = 0; wLogAppender* appender; @@ -129,10 +129,10 @@ int WLog_OpenAppender(wLog* log) appender = WLog_GetLogAppender(log); if (!appender) - return -1; + return FALSE; if (!appender->Open) - return 0; + return TRUE; if (!appender->State) { @@ -143,7 +143,7 @@ int WLog_OpenAppender(wLog* log) return status; } -int WLog_CloseAppender(wLog* log) +BOOL WLog_CloseAppender(wLog* log) { int status = 0; wLogAppender* appender; @@ -151,10 +151,10 @@ int WLog_CloseAppender(wLog* log) appender = WLog_GetLogAppender(log); if (!appender) - return -1; + return FALSE; if (!appender->Close) - return 0; + return TRUE; if (appender->State) { diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.c b/winpr/libwinpr/utils/wlog/BinaryAppender.c index 50d9c86cd..0e9241e4d 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.c +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.c @@ -69,16 +69,16 @@ BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* append return TRUE; } -int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender) +BOOL WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender) { if (!log || !appender) - return -1; + return FALSE; if (!appender->FileName) { appender->FileName = (char*) malloc(MAX_PATH); if (!appender->FileName) - return -1; + return FALSE; sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId()); } @@ -86,44 +86,44 @@ int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender) { appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); if (!appender->FilePath) - return -1; + return FALSE; } if (!appender->FullFileName) { appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); if (!appender->FullFileName) - return -1; + return FALSE; } if (!PathFileExistsA(appender->FilePath)) { if (!PathMakePathA(appender->FilePath, 0)) - return -1; + return FALSE; UnixChangeFileMode(appender->FilePath, 0xFFFF); } appender->FileDescriptor = fopen(appender->FullFileName, "a+"); if (!appender->FileDescriptor) - return -1; + return FALSE; - return 0; + return TRUE; } -int WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender) +BOOL WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender) { if (!appender->FileDescriptor) - return 0; + return TRUE; fclose(appender->FileDescriptor); appender->FileDescriptor = NULL; - return 0; + return TRUE; } -int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) { FILE* fp; wStream* s; @@ -131,15 +131,15 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL int FileNameLength; int FunctionNameLength; int TextStringLength; - int ret = 1; + BOOL ret = TRUE; if (!log || !appender || !message) - return -1; + return FALSE; fp = appender->FileDescriptor; if (!fp) - return -1; + return FALSE; FileNameLength = strlen(message->FileName); FunctionNameLength = strlen(message->FunctionName); @@ -152,7 +152,7 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL s = Stream_New(NULL, MessageLength); if (!s) - return -1; + return FALSE; Stream_Write_UINT32(s, MessageLength); @@ -173,21 +173,21 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL Stream_SealLength(s); if (fwrite(Stream_Buffer(s), MessageLength, 1, fp) != 1) - ret = -1; + ret = FALSE; Stream_Free(s, TRUE); return ret; } -int WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) { - return 1; + return TRUE; } -int WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) { - return 1; + return TRUE; } wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log) diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.c b/winpr/libwinpr/utils/wlog/CallbackAppender.c index 907191789..593496b0f 100644 --- a/winpr/libwinpr/utils/wlog/CallbackAppender.c +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.c @@ -34,33 +34,34 @@ * Callback Appender */ -WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, +WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, CallbackAppenderData_t data) { if (!appender) - return; + return FALSE; if (appender->Type != WLOG_APPENDER_CALLBACK) - return; + return FALSE; appender->message = msg; appender->image = img; appender->package = pkg; appender->data = data; + return TRUE; } -int WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) +BOOL WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) { - return 0; + return TRUE; } -int WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender) +BOOL WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender) { - return 0; + return TRUE; } -int WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) { char prefix[WLOG_MAX_PREFIX_SIZE]; @@ -69,56 +70,48 @@ int WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender if (appender->message) { - appender->message(message); + return appender->message(message); } else { - return -1; + return FALSE; } - - return 1; } -int WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) { if (appender->data) { - appender->data(message); + return appender->data(message); } else { - return -1; + return FALSE; } - - return 1; } -int WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) { if (appender->image) { - appender->image(message); + return appender->image(message); } else { - return -1; + return FALSE; } - - return 1; } -int WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) { if (appender->package) { - appender->package(message); + return appender->package(message); } else { - return -1; + return FALSE; } - - return 1; } wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index 67ecdcb6e..ba5ed71c2 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -38,13 +38,13 @@ * Console Appender */ -void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream) +BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream) { if (!appender) - return; + return FALSE; if (appender->Type != WLOG_APPENDER_CONSOLE) - return; + return FALSE; if (outputStream < 0) outputStream = WLOG_CONSOLE_DEFAULT; @@ -55,19 +55,20 @@ void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* append appender->outputStream = WLOG_CONSOLE_STDERR; else appender->outputStream = WLOG_CONSOLE_DEFAULT; + return TRUE; } -int WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender) +BOOL WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender) { - return 0; + return TRUE; } -int WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender) +BOOL WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender) { - return 0; + return TRUE; } -int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; @@ -85,7 +86,7 @@ int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, OutputDebugStringA(MessageString); - return 1; + return TRUE; } #endif #ifdef ANDROID @@ -149,12 +150,12 @@ int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, if (message->Level != WLOG_OFF) fprintf(fp, "%s%s\n", message->PrefixString, message->TextString); #endif - return 1; + return TRUE; } static int g_DataId = 0; -int WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) { int DataId; char* FullFileName; @@ -166,12 +167,12 @@ int WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* append free(FullFileName); - return DataId; + return TRUE; } static int g_ImageId = 0; -int WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) { int ImageId; char* FullFileName; @@ -184,12 +185,12 @@ int WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appen free(FullFileName); - return ImageId; + return TRUE; } static int g_PacketId = 0; -int WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) { int PacketId; char* FullFileName; @@ -204,10 +205,10 @@ int WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appe } if (appender->PacketMessageContext) - WLog_PacketMessage_Write((wPcap*) appender->PacketMessageContext, + return WLog_PacketMessage_Write((wPcap*) appender->PacketMessageContext, message->PacketData, message->PacketLength, message->PacketFlags); - return PacketId; + return TRUE; } wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log) diff --git a/winpr/libwinpr/utils/wlog/DataMessage.c b/winpr/libwinpr/utils/wlog/DataMessage.c index 6cd5cea16..f27bbdf77 100644 --- a/winpr/libwinpr/utils/wlog/DataMessage.c +++ b/winpr/libwinpr/utils/wlog/DataMessage.c @@ -28,21 +28,21 @@ #include "../../log.h" #define TAG WINPR_TAG("utils.wlog") -int WLog_DataMessage_Write(char* filename, void* data, int length) +BOOL WLog_DataMessage_Write(char* filename, void* data, int length) { FILE* fp; - int ret = 0; + BOOL ret = TRUE; fp = fopen(filename, "w+b"); if (!fp) { - WLog_ERR(TAG, "failed to open file %s", filename); - return -1; + //WLog_ERR(TAG, "failed to open file %s", filename); + return FALSE; } if (fwrite(data, length, 1, fp) != 1) - ret = -1; + ret = FALSE; fclose(fp); return ret; } diff --git a/winpr/libwinpr/utils/wlog/DataMessage.h b/winpr/libwinpr/utils/wlog/DataMessage.h index bcfd917bd..3b30ae9a7 100644 --- a/winpr/libwinpr/utils/wlog/DataMessage.h +++ b/winpr/libwinpr/utils/wlog/DataMessage.h @@ -24,6 +24,6 @@ #include "wlog/wlog.h" -int WLog_DataMessage_Write(char* filename, void* data, int length); +BOOL WLog_DataMessage_Write(char* filename, void* data, int length); #endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index 46d13bbad..ad5a3aec4 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -67,23 +67,23 @@ BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, return TRUE; } -int WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender) +BOOL WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender) { if (!log || !appender) - return -1; + return FALSE; if (!appender->FilePath) { appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); if (!appender->FilePath) - return -1; + return FALSE; } if (!appender->FileName) { appender->FileName = (char*) malloc(MAX_PATH); if (!appender->FileName) - return -1; + return FALSE; sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId()); } @@ -92,51 +92,51 @@ int WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender) { appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); if (!appender->FullFileName) - return -1; + return FALSE; } if (!PathFileExistsA(appender->FilePath)) { if (!PathMakePathA(appender->FilePath, 0)) - return -1; + return FALSE; UnixChangeFileMode(appender->FilePath, 0xFFFF); } appender->FileDescriptor = fopen(appender->FullFileName, "a+"); if (!appender->FileDescriptor) - return -1; + return FALSE; - return 0; + return TRUE; } -int WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender) +BOOL WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender) { if (!log || !appender) - return -1; + return FALSE; if (!appender->FileDescriptor) - return 0; + return TRUE; fclose(appender->FileDescriptor); appender->FileDescriptor = NULL; - return 0; + return TRUE; } -int WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; if (!log || !appender || !message) - return -1; + return FALSE; fp = appender->FileDescriptor; if (!fp) - return -1; + return FALSE; message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); @@ -145,18 +145,18 @@ int WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMe fflush(fp); /* slow! */ - return 1; + return TRUE; } static int g_DataId = 0; -int WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) { int DataId; char* FullFileName; if (!log || !appender || !message) - return -1; + return FALSE; DataId = g_DataId++; FullFileName = WLog_Message_GetOutputFileName(DataId, "dat"); @@ -165,7 +165,7 @@ int WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wL free(FullFileName); - return DataId; + return TRUE; } static int g_ImageId = 0; @@ -176,7 +176,7 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w char* FullFileName; if (!log || !appender || !message) - return -1; + return FALSE; ImageId = g_ImageId++; FullFileName = WLog_Message_GetOutputFileName(ImageId, "bmp"); @@ -186,7 +186,7 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w free(FullFileName); - return ImageId; + return TRUE; } wLogFileAppender* WLog_FileAppender_New(wLog* log) diff --git a/winpr/libwinpr/utils/wlog/ImageMessage.c b/winpr/libwinpr/utils/wlog/ImageMessage.c index a8d2ab979..c09a7eb2a 100644 --- a/winpr/libwinpr/utils/wlog/ImageMessage.c +++ b/winpr/libwinpr/utils/wlog/ImageMessage.c @@ -26,14 +26,14 @@ #include "wlog/ImageMessage.h" -int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp) +BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp) { int status; status = winpr_bitmap_write(filename, data, width, height, bpp); if (status < 0) - return -1; + return FALSE; - return 1; + return TRUE; } diff --git a/winpr/libwinpr/utils/wlog/ImageMessage.h b/winpr/libwinpr/utils/wlog/ImageMessage.h index 8046a008a..84efa0e46 100644 --- a/winpr/libwinpr/utils/wlog/ImageMessage.h +++ b/winpr/libwinpr/utils/wlog/ImageMessage.h @@ -24,6 +24,6 @@ #include "wlog/wlog.h" -int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp); +BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp); #endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/Layout.c b/winpr/libwinpr/utils/wlog/Layout.c index d28a8cee7..741f7cb19 100644 --- a/winpr/libwinpr/utils/wlog/Layout.c +++ b/winpr/libwinpr/utils/wlog/Layout.c @@ -65,7 +65,7 @@ void WLog_PrintMessagePrefix(wLog* log, wLogMessage* message, const char* format va_end(args); } -void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message) +BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message) { char* p; int index; @@ -327,6 +327,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me args[11], args[12], args[13], args[14], args[15]); break; } + return TRUE; } wLogLayout* WLog_GetLogLayout(wLog* log) diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.c b/winpr/libwinpr/utils/wlog/PacketMessage.c index ae28b3f11..e3a063165 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.c +++ b/winpr/libwinpr/utils/wlog/PacketMessage.c @@ -375,7 +375,7 @@ static BOOL WLog_PacketMessage_Write_TcpHeader(wPcap* pcap, wTcpHeader* tcp) static UINT32 g_InboundSequenceNumber = 0; static UINT32 g_OutboundSequenceNumber = 0; -int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags) +BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags) { wTcpHeader tcp; wIPv4Header ipv4; @@ -385,7 +385,7 @@ int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags) ethernet.Type = 0x0800; if (!pcap || !pcap->fp) - return -1; + return FALSE; if (flags & WLOG_PACKET_OUTBOUND) { @@ -479,7 +479,7 @@ int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags) !WLog_PacketMessage_Write_IPv4Header(pcap, &ipv4) || !WLog_PacketMessage_Write_TcpHeader(pcap, &tcp) || !Pcap_Write_RecordContent(pcap, &record)) - return -1; + return FALSE; fflush(pcap->fp); - return 0; + return TRUE; } diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.h b/winpr/libwinpr/utils/wlog/PacketMessage.h index f06f4fdfa..1ee0dc241 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.h +++ b/winpr/libwinpr/utils/wlog/PacketMessage.h @@ -116,7 +116,7 @@ struct _wTcpHeader }; typedef struct _wTcpHeader wTcpHeader; -int WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags); +BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, DWORD length, DWORD flags); #endif /* WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index b91c42ffd..e9b5cf41a 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -63,52 +63,64 @@ const char* WLOG_LEVELS[7] = static DWORD g_FilterCount = 0; static wLogFilter* g_Filters = NULL; -static void log_recursion(const char* file, const char* fkt, int line) +static BOOL log_recursion(const char* file, const char* fkt, int line) { size_t used, i; void* bt = winpr_backtrace(20); + if (!bt) + return FALSE; char** msg = winpr_backtrace_symbols(bt, &used); + if (!msg) + return FALSE; #if defined(ANDROID) const char* tag = WINPR_TAG("utils.wlog"); - __android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!"); - __android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line); + if (__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!") < 0) + return FALSE; + if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line) < 0) + return FALSE; for (i=0; iState) - WLog_OpenAppender(log); + if (!WLog_OpenAppender(log)) + return FALSE; if (!appender->WriteMessage) - return -1; + return FALSE; EnterCriticalSection(&appender->lock); if (appender->recursive) - log_recursion(message->FileName, message->FunctionName, message->LineNumber); + status = log_recursion(message->FileName, message->FunctionName, message->LineNumber); else { appender->recursive = TRUE; @@ -120,25 +132,26 @@ int WLog_Write(wLog* log, wLogMessage* message) return status; } -int WLog_WriteData(wLog* log, wLogMessage* message) +BOOL WLog_WriteData(wLog* log, wLogMessage* message) { - int status = -1; + BOOL status; wLogAppender* appender; appender = WLog_GetLogAppender(log); if (!appender) - return -1; + return FALSE; if (!appender->State) - WLog_OpenAppender(log); + if (!WLog_OpenAppender(log)) + return FALSE; if (!appender->WriteDataMessage) - return -1; + return FALSE; EnterCriticalSection(&appender->lock); if (appender->recursive) - log_recursion(message->FileName, message->FunctionName, message->LineNumber); + status = log_recursion(message->FileName, message->FunctionName, message->LineNumber); else { appender->recursive = TRUE; @@ -150,25 +163,26 @@ int WLog_WriteData(wLog* log, wLogMessage* message) return status; } -int WLog_WriteImage(wLog* log, wLogMessage* message) +BOOL WLog_WriteImage(wLog* log, wLogMessage* message) { - int status = -1; + BOOL status; wLogAppender* appender; appender = WLog_GetLogAppender(log); if (!appender) - return -1; + return FALSE; if (!appender->State) - WLog_OpenAppender(log); + if (!WLog_OpenAppender(log)) + return FALSE; if (!appender->WriteImageMessage) - return -1; + return FALSE; EnterCriticalSection(&appender->lock); if (appender->recursive) - log_recursion(message->FileName, message->FunctionName, message->LineNumber); + status = log_recursion(message->FileName, message->FunctionName, message->LineNumber); else { appender->recursive = TRUE; @@ -180,25 +194,26 @@ int WLog_WriteImage(wLog* log, wLogMessage* message) return status; } -int WLog_WritePacket(wLog* log, wLogMessage* message) +BOOL WLog_WritePacket(wLog* log, wLogMessage* message) { - int status = -1; + BOOL status; wLogAppender* appender; appender = WLog_GetLogAppender(log); if (!appender) - return -1; + return FALSE; if (!appender->State) - WLog_OpenAppender(log); + if (!WLog_OpenAppender(log)) + return FALSE; if (!appender->WritePacketMessage) - return -1; + return FALSE; EnterCriticalSection(&appender->lock); if (appender->recursive) - log_recursion(message->FileName, message->FunctionName, message->LineNumber); + status = log_recursion(message->FileName, message->FunctionName, message->LineNumber); else { appender->recursive = TRUE; @@ -210,9 +225,9 @@ int WLog_WritePacket(wLog* log, wLogMessage* message) return status; } -int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) +BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) { - int status = -1; + BOOL status; if (message->Type == WLOG_MESSAGE_TEXT) { @@ -224,7 +239,8 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) else { char formattedLogMessage[WLOG_MAX_STRING_SIZE]; - wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args); + if (wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args) < 0) + return FALSE; message->TextString = formattedLogMessage; status = WLog_Write(log, message); } @@ -254,13 +270,14 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) return status; } -void WLog_PrintMessage(wLog* log, wLogMessage* message, ...) +BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...) { - int status; + BOOL status; va_list args; va_start(args, message); status = WLog_PrintMessageVA(log, message, args); va_end(args); + return status; } DWORD WLog_GetLogLevel(wLog* log) @@ -275,14 +292,18 @@ DWORD WLog_GetLogLevel(wLog* log) } } -void WLog_SetLogLevel(wLog* log, DWORD logLevel) +BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel) { + if (!log) + return FALSE; + if ((logLevel > WLOG_OFF) && (logLevel != WLOG_LEVEL_INHERIT)) { logLevel = WLOG_OFF; } log->Level = logLevel; + return TRUE; } int WLog_ParseLogLevel(const char* level) @@ -310,7 +331,7 @@ int WLog_ParseLogLevel(const char* level) return iLevel; } -int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) +BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name) { char* p; char* q; @@ -320,7 +341,7 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) count = 1; if(!name) - return -1; + return FALSE; p = (char*) name; @@ -335,14 +356,14 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) names = _strdup(name); if (!names) - return -1; + return FALSE; filter->NameCount = count; filter->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR)); if(!filter->Names) { free(names); filter->NameCount = 0; - return -1; + return FALSE; } filter->Names[count] = NULL; count = 0; @@ -356,7 +377,7 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) free(filter->Names); filter->Names = NULL; filter->NameCount = 0; - return -1; + return FALSE; } *q = '\0'; @@ -369,7 +390,7 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) free(filter->Names); filter->Names = NULL; filter->NameCount = 0; - return -1; + return FALSE; } filter->Level = (DWORD) iLevel; @@ -382,10 +403,10 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name) p++; } - return 0; + return TRUE; } -int WLog_ParseFilters() +BOOL WLog_ParseFilters() { char* p; char* env; @@ -397,15 +418,15 @@ int WLog_ParseFilters() nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0); if (nSize < 1) - return 0; + return TRUE; env = (LPSTR) malloc(nSize); if (!env) - return -1; + return FALSE; if (!GetEnvironmentVariableA("WLOG_FILTER", env, nSize)) - return -1; + return FALSE; count = 1; p = env; @@ -425,7 +446,7 @@ int WLog_ParseFilters() if (!strs) { free(env); - return -1; + return FALSE; } strs[count++] = p; @@ -444,7 +465,7 @@ int WLog_ParseFilters() { free(strs); free(env); - return -1; + return FALSE; } for (count = 0; count < g_FilterCount; count++) @@ -455,14 +476,14 @@ int WLog_ParseFilters() { free(strs); free(env); - return -1; + return FALSE; } } free(strs); free(env); - return 0; + return TRUE; } int WLog_GetFilterLogLevel(wLog* log) @@ -506,7 +527,7 @@ int WLog_GetFilterLogLevel(wLog* log) return iLevel; } -int WLog_ParseName(wLog* log, LPCSTR name) +BOOL WLog_ParseName(wLog* log, LPCSTR name) { char* p; int count; @@ -522,13 +543,13 @@ int WLog_ParseName(wLog* log, LPCSTR name) names = _strdup(name); if (!names) - return -1; + return FALSE; log->NameCount = count; log->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR)); if(!log->Names) { free(names); - return -1; + return FALSE; } log->Names[count] = NULL; count = 0; @@ -543,7 +564,7 @@ int WLog_ParseName(wLog* log, LPCSTR name) p++; } - return 0; + return TRUE; } wLog* WLog_New(LPCSTR name, wLog* rootLogger) @@ -562,7 +583,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger) if (!log->Name) goto out_fail; - if (WLog_ParseName(log, name) != 0) + if (!WLog_ParseName(log, name)) goto out_fail; log->Parent = rootLogger; @@ -689,7 +710,7 @@ fail: return NULL; } -int WLog_AddChild(wLog* parent, wLog* child) +BOOL WLog_AddChild(wLog* parent, wLog* child) { if (parent->ChildrenCount >= parent->ChildrenSize) { @@ -710,18 +731,18 @@ int WLog_AddChild(wLog* parent, wLog* child) if (parent->Children) free (parent->Children); parent->Children = NULL; - return -1; + return FALSE; } parent->Children = tmp; } } if (!parent->Children) - return -1; + return FALSE; parent->Children[parent->ChildrenCount++] = child; child->Parent = parent; - return 0; + return TRUE; } wLog* WLog_FindChild(LPCSTR name) @@ -732,6 +753,9 @@ wLog* WLog_FindChild(LPCSTR name) BOOL found = FALSE; root = WLog_GetRoot(); + if (!root) + return NULL; + for (index = 0; index < root->ChildrenCount; index++) { child = root->Children[index]; @@ -756,7 +780,11 @@ wLog* WLog_Get(LPCSTR name) return NULL; if (!(log = WLog_New(name, root))) return NULL; - WLog_AddChild(root, log); + if (!WLog_AddChild(root, log)) + { + WLog_Free(log); + return NULL; + } } return log; } @@ -766,14 +794,14 @@ BOOL WLog_Init() return WLog_GetRoot() != NULL; } -void WLog_Uninit() +BOOL WLog_Uninit() { DWORD index; wLog* child = NULL; wLog* root = g_RootLog; if (!root) - return; + return FALSE; for (index = 0; index < root->ChildrenCount; index++) { @@ -783,4 +811,5 @@ void WLog_Uninit() WLog_Free(root); g_RootLog = NULL; + return TRUE; } diff --git a/winpr/libwinpr/utils/wlog/wlog.h b/winpr/libwinpr/utils/wlog/wlog.h index 24d24ad74..737a18b01 100644 --- a/winpr/libwinpr/utils/wlog/wlog.h +++ b/winpr/libwinpr/utils/wlog/wlog.h @@ -25,7 +25,7 @@ #define WLOG_MAX_PREFIX_SIZE 512 #define WLOG_MAX_STRING_SIZE 8192 -void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message); +BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message); #include "wlog/Layout.h" #include "wlog/Appender.h" From 720c879661b4c3ad83d01b127da3d43810a05dee Mon Sep 17 00:00:00 2001 From: David FORT Date: Wed, 21 Oct 2015 16:13:15 +0200 Subject: [PATCH 038/220] Add a wLog syslog appender --- CMakeLists.txt | 1 + config.h.in | 1 + winpr/include/winpr/wlog.h | 9 ++ winpr/libwinpr/utils/CMakeLists.txt | 12 +- winpr/libwinpr/utils/wlog/Appender.c | 84 +++++++----- winpr/libwinpr/utils/wlog/Appender.h | 4 + winpr/libwinpr/utils/wlog/SyslogAppender.c | 144 +++++++++++++++++++++ winpr/libwinpr/utils/wlog/SyslogAppender.h | 35 +++++ 8 files changed, 255 insertions(+), 35 deletions(-) create mode 100644 winpr/libwinpr/utils/wlog/SyslogAppender.c create mode 100644 winpr/libwinpr/utils/wlog/SyslogAppender.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 64cc2075c..94e807499 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,6 +334,7 @@ if(NOT IOS) check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H) check_include_files(sys/strtio.h HAVE_SYS_STRTIO_H) check_include_files(sys/select.h HAVE_SYS_SELECT_H) + check_include_files(syslog.h HAVE_SYSLOG_H) else() set(HAVE_FCNTL_H 1) set(HAVE_UNISTD_H 1) diff --git a/config.h.in b/config.h.in index cf1e7f082..83f3ee641 100644 --- a/config.h.in +++ b/config.h.in @@ -32,6 +32,7 @@ #cmakedefine HAVE_TM_GMTOFF #cmakedefine HAVE_AIO_H #cmakedefine HAVE_POLL_H +#cmakedefine HAVE_SYSLOG_H #cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK #cmakedefine HAVE_VALGRIND_MEMCHECK_H #cmakedefine HAVE_EXECINFO_H diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 7e76d2c6e..f60e706a0 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -113,6 +113,7 @@ struct _wLogLayout #define WLOG_APPENDER_FILE 1 #define WLOG_APPENDER_BINARY 2 #define WLOG_APPENDER_CALLBACK 3 +#define WLOG_APPENDER_SYSLOG 4 #define WLOG_PACKET_INBOUND 1 #define WLOG_PACKET_OUTBOUND 2 @@ -197,6 +198,14 @@ struct _wLogCallbackAppender }; typedef struct _wLogCallbackAppender wLogCallbackAppender; +#ifdef HAVE_SYSLOG_H +struct _wLogSyslogAppender +{ + WLOG_APPENDER_COMMON(); +}; +typedef struct _wLogSyslogAppender wLogSyslogAppender; +#endif + /** * Filter */ diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index 949908ca3..654a321bd 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -51,6 +51,13 @@ set(${MODULE_PREFIX}_TRIO_SRCS trio/triop.h trio/triostr.c trio/triostr.h) + +if (HAVE_SYSLOG_H) + set(SYSLOG_SRCS + wlog/SyslogAppender.c + wlog/SyslogAppender.h + ) +endif() set(${MODULE_PREFIX}_WLOG_SRCS wlog/wlog.c @@ -76,7 +83,10 @@ set(${MODULE_PREFIX}_WLOG_SRCS wlog/CallbackAppender.c wlog/CallbackAppender.h wlog/ConsoleAppender.c - wlog/ConsoleAppender.h) + wlog/ConsoleAppender.h + ${SYSLOG_SRCS} + ) + set(${MODULE_PREFIX}_SRCS ini.c diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index 33b422c15..3ca867912 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -29,25 +29,34 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) { - wLogAppender* appender = NULL; + wLogAppender* appender; + if (!log) return NULL; - if (logAppenderType == WLOG_APPENDER_CONSOLE) + switch (logAppenderType) { + case WLOG_APPENDER_CONSOLE: appender = (wLogAppender*) WLog_ConsoleAppender_New(log); - } - else if (logAppenderType == WLOG_APPENDER_FILE) - { + break; + case WLOG_APPENDER_FILE: appender = (wLogAppender*) WLog_FileAppender_New(log); - } - else if (logAppenderType == WLOG_APPENDER_BINARY) - { + break; + case WLOG_APPENDER_BINARY: appender = (wLogAppender*) WLog_BinaryAppender_New(log); - } - else if (logAppenderType == WLOG_APPENDER_CALLBACK) - { + break; + case WLOG_APPENDER_CALLBACK: appender = (wLogAppender*) WLog_CallbackAppender_New(log); + break; +#ifdef HAVE_SYSLOG_H + case WLOG_APPENDER_SYSLOG: + appender = (wLogAppender*) WLog_SyslogAppender_New(log); + break; +#endif + default: + fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType); + appender = NULL; + break; } if (!appender) @@ -69,32 +78,39 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) void WLog_Appender_Free(wLog* log, wLogAppender* appender) { - if (appender) + if (!appender) + return; + + if (appender->Layout) { - if (appender->Layout) - { - WLog_Layout_Free(log, appender->Layout); - appender->Layout = NULL; - } + WLog_Layout_Free(log, appender->Layout); + appender->Layout = NULL; + } - DeleteCriticalSection(&appender->lock); + DeleteCriticalSection(&appender->lock); - if (appender->Type == WLOG_APPENDER_CONSOLE) - { - WLog_ConsoleAppender_Free(log, (wLogConsoleAppender*) appender); - } - else if (appender->Type == WLOG_APPENDER_FILE) - { - WLog_FileAppender_Free(log, (wLogFileAppender*) appender); - } - else if (appender->Type == WLOG_APPENDER_BINARY) - { - WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender); - } - else if (appender->Type == WLOG_APPENDER_CALLBACK) - { - WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender); - } + switch (appender->Type) + { + case WLOG_APPENDER_CONSOLE: + WLog_ConsoleAppender_Free(log, (wLogConsoleAppender*) appender); + break; + case WLOG_APPENDER_FILE: + WLog_FileAppender_Free(log, (wLogFileAppender*) appender); + break; + case WLOG_APPENDER_BINARY: + WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender); + break; + case WLOG_APPENDER_CALLBACK: + WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender); + break; +#ifdef HAVE_SYSLOG_H + case WLOG_APPENDER_SYSLOG: + WLog_SyslogAppender_Free(log, (wLogSyslogAppender *) appender); + break; +#endif + default: + fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type); + break; } } diff --git a/winpr/libwinpr/utils/wlog/Appender.h b/winpr/libwinpr/utils/wlog/Appender.h index 4be3306a0..165e348b8 100644 --- a/winpr/libwinpr/utils/wlog/Appender.h +++ b/winpr/libwinpr/utils/wlog/Appender.h @@ -27,6 +27,10 @@ #include "wlog/ConsoleAppender.h" #include "wlog/CallbackAppender.h" +#ifdef HAVE_SYSLOG_H +#include "wlog/SyslogAppender.h" +#endif + void WLog_Appender_Free(wLog* log, wLogAppender* appender); #include "wlog/wlog.h" diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.c b/winpr/libwinpr/utils/wlog/SyslogAppender.c new file mode 100644 index 000000000..1126fdc36 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.c @@ -0,0 +1,144 @@ +/** + * WinPR: Windows Portable Runtime + * WinPR Logger + * + * Copyright 2013 David FORT + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include + +#include "wlog/Message.h" +#include "wlog/SyslogAppender.h" + +static int getSyslogLevel(DWORD level) +{ + switch (level) + { + case WLOG_TRACE: + case WLOG_DEBUG: + return LOG_DEBUG; + case WLOG_INFO: + return LOG_INFO; + case WLOG_WARN: + return LOG_WARNING; + case WLOG_ERROR: + return LOG_ERR; + case WLOG_FATAL: + return LOG_CRIT; + case WLOG_OFF: + default: + return -1; + } +} + +static int WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) +{ + if (!log || !appender) + return -1; + + return 0; +} + +static int WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) +{ + if (!log || !appender) + return -1; + + return 0; +} + +static int WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +{ + int syslogLevel; + + if (!log || !appender || !message) + return -1; + + syslogLevel = getSyslogLevel(message->Level); + if (syslogLevel >= 0) + syslog(syslogLevel, "%s", message->TextString); + + return 1; +} + +static int WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +{ + int syslogLevel; + + if (!log || !appender || !message) + return -1; + + syslogLevel = getSyslogLevel(message->Level); + if (syslogLevel >= 0) + syslog(syslogLevel, "skipped data message of %d bytes", message->Length); + + return 0; +} + + + +static int WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +{ + int syslogLevel; + + if (!log || !appender || !message) + return -1; + + syslogLevel = getSyslogLevel(message->Level); + if (syslogLevel >= 0) + syslog(syslogLevel, "skipped image (%dx%dx%d)", message->ImageWidth, message->ImageHeight, message->ImageBpp); + + return 0; +} + +wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) +{ + wLogSyslogAppender* appender; + + appender = (wLogSyslogAppender*) calloc(1, sizeof(wLogSyslogAppender)); + if (!appender) + return NULL; + + appender->Type = WLOG_APPENDER_SYSLOG; + + appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Open; + appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Close; + appender->WriteMessage = + (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_SyslogAppender_WriteMessage; + appender->WriteDataMessage = + (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_SyslogAppender_WriteDataMessage; + appender->WriteImageMessage = + (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_SyslogAppender_WriteImageMessage; + + return appender; +} + +void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender) +{ + if (appender) + { + free(appender); + } +} diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.h b/winpr/libwinpr/utils/wlog/SyslogAppender.h new file mode 100644 index 000000000..2ce6b527c --- /dev/null +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.h @@ -0,0 +1,35 @@ +/** + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ +#define WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ + +#include + +#include "wlog/wlog.h" + +WINPR_API wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log); +WINPR_API void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender); + + +#endif /* WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ */ From d9080312bcb9f2aae07b918bcb471d82067df72e Mon Sep 17 00:00:00 2001 From: David FORT Date: Thu, 22 Oct 2015 10:54:21 +0200 Subject: [PATCH 039/220] Adapt to last wLog changes --- winpr/libwinpr/utils/wlog/SyslogAppender.c | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.c b/winpr/libwinpr/utils/wlog/SyslogAppender.c index 1126fdc36..169c5ae9e 100644 --- a/winpr/libwinpr/utils/wlog/SyslogAppender.c +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.c @@ -53,64 +53,62 @@ static int getSyslogLevel(DWORD level) } } -static int WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) +static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) { if (!log || !appender) - return -1; + return FALSE; - return 0; + return TRUE; } -static int WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) +static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) { if (!log || !appender) - return -1; + return FALSE; - return 0; + return TRUE; } -static int WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) { int syslogLevel; if (!log || !appender || !message) - return -1; + return FALSE; syslogLevel = getSyslogLevel(message->Level); if (syslogLevel >= 0) syslog(syslogLevel, "%s", message->TextString); - return 1; + return TRUE; } -static int WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) { int syslogLevel; if (!log || !appender || !message) - return -1; + return FALSE; syslogLevel = getSyslogLevel(message->Level); if (syslogLevel >= 0) syslog(syslogLevel, "skipped data message of %d bytes", message->Length); - return 0; + return TRUE; } - - -static int WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) { int syslogLevel; if (!log || !appender || !message) - return -1; + return FALSE; syslogLevel = getSyslogLevel(message->Level); if (syslogLevel >= 0) syslog(syslogLevel, "skipped image (%dx%dx%d)", message->ImageWidth, message->ImageHeight, message->ImageBpp); - return 0; + return TRUE; } wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) @@ -138,7 +136,5 @@ wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender) { if (appender) - { free(appender); - } } From 2d99f766675505cac6461f10e00861ba6e22b054 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Fri, 23 Oct 2015 08:49:24 +0200 Subject: [PATCH 040/220] cliprdr/server: Fix memory leak --- channels/cliprdr/server/cliprdr_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 23f29d8d3..e672fd601 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -1566,5 +1566,6 @@ void cliprdr_server_context_free(CliprdrServerContext* context) free(cliprdr->temporaryDirectory); } + free(context->handle); free(context); } From 08cbcb357716cbd7e338ffedb882ff4db3bafa74 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Fri, 23 Oct 2015 12:08:20 +0200 Subject: [PATCH 041/220] wlog: Fix variable definitions --- winpr/libwinpr/utils/wlog/wlog.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index e9b5cf41a..2da0ce10a 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -65,15 +65,19 @@ static wLogFilter* g_Filters = NULL; static BOOL log_recursion(const char* file, const char* fkt, int line) { + char** msg; size_t used, i; void* bt = winpr_backtrace(20); +#if defined(ANDROID) + const char* tag = WINPR_TAG("utils.wlog"); +#endif + if (!bt) return FALSE; - char** msg = winpr_backtrace_symbols(bt, &used); + msg = winpr_backtrace_symbols(bt, &used); if (!msg) return FALSE; #if defined(ANDROID) - const char* tag = WINPR_TAG("utils.wlog"); if (__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!") < 0) return FALSE; if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line) < 0) From a9d81ad083cee45f09bc7b53d30e4c3ecca43969 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 23 Oct 2015 17:18:53 +0200 Subject: [PATCH 042/220] winpr: fix compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit winpr/libwinpr/utils/wlog/wlog.c: In function ‘WLog_PrintMessageVA’: winpr/libwinpr/utils/wlog/wlog.c:234:7: warning: ‘status’ may be used uninitialized in this function [-Wmaybe-uninitialized] BOOL status; ^ gcc 4.9.2 --- winpr/libwinpr/utils/wlog/wlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 2da0ce10a..28c547cb8 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -231,7 +231,7 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message) BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) { - BOOL status; + BOOL status = FALSE; if (message->Type == WLOG_MESSAGE_TEXT) { From ab05a79c21df9d69acdbf5bed9fc122ac5a92bc8 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 23 Oct 2015 18:06:17 +0200 Subject: [PATCH 043/220] winpr/stream: don't allow 0-size streams --- winpr/libwinpr/utils/stream.c | 3 +++ winpr/libwinpr/utils/test/TestStream.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index b0d864bce..31d4493f2 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -70,6 +70,9 @@ wStream* Stream_New(BYTE* buffer, size_t size) { wStream* s; + if (!buffer && !size) + return NULL; + s = malloc(sizeof(wStream)); if (!s) diff --git a/winpr/libwinpr/utils/test/TestStream.c b/winpr/libwinpr/utils/test/TestStream.c index 96fb4fea8..005dcef1b 100644 --- a/winpr/libwinpr/utils/test/TestStream.c +++ b/winpr/libwinpr/utils/test/TestStream.c @@ -65,6 +65,16 @@ static BOOL TestStream_Verify(wStream* s, int mincap, int len, int pos) return TRUE; } +static BOOL TestStream_New() +{ + wStream *s = NULL; + /* Test creation of a 0-size stream with no buffer */ + s = Stream_New(NULL, 0); + if (s) + return FALSE; + return TRUE; +} + static BOOL TestStream_Create(int count, BOOL selfAlloc) { @@ -266,6 +276,8 @@ int TestStream(int argc, char* argv[]) if (!TestStream_Reading()) return 4; + if (!TestStream_New()) + return 5; /** * FIXME: Add tests for * Stream_Write_* From c70559d1288ebe8c97fcd1b024d13f8b0ce6edc1 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 23 Oct 2015 18:17:14 +0200 Subject: [PATCH 044/220] winpr API: add EnvironmentBlockToEnvpA * expose EnvironmentBlockToEnvpA * cleanup includes in process.c * removed unused "flag" variable in _CreateProcessExA * make ProcessHandleCloseHandle static --- winpr/include/winpr/environment.h | 2 + winpr/libwinpr/environment/environment.c | 49 ++++++++++++++++ winpr/libwinpr/thread/process.c | 71 +----------------------- 3 files changed, 53 insertions(+), 69 deletions(-) diff --git a/winpr/include/winpr/environment.h b/winpr/include/winpr/environment.h index d6329d827..34d9fb03c 100644 --- a/winpr/include/winpr/environment.h +++ b/winpr/include/winpr/environment.h @@ -110,6 +110,8 @@ WINPR_API LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge); WINPR_API DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer, DWORD nSize); WINPR_API BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue); +WINPR_API char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock); + #ifdef __cplusplus } #endif diff --git a/winpr/libwinpr/environment/environment.c b/winpr/libwinpr/environment/environment.c index dcdb24f30..58abed849 100644 --- a/winpr/libwinpr/environment/environment.c +++ b/winpr/libwinpr/environment/environment.c @@ -572,3 +572,52 @@ BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue) return TRUE; } + +char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock) +{ + char* p; + int index; + int count; + int length; + char** envp = NULL; + + count = 0; + if (!lpszEnvironmentBlock) + return NULL; + + p = (char*) lpszEnvironmentBlock; + + while (p[0] && p[1]) + { + length = strlen(p); + p += (length + 1); + count++; + } + + index = 0; + p = (char*) lpszEnvironmentBlock; + + envp = (char**) calloc(count + 1, sizeof(char*)); + if (!envp) + return NULL; + envp[count] = NULL; + + while (p[0] && p[1]) + { + length = strlen(p); + envp[index] = _strdup(p); + if (!envp[index]) + { + for (index -= 1; index >= 0; --index) + { + free(envp[index]); + } + free(envp); + return NULL; + } + p += (length + 1); + index++; + } + + return envp; +} diff --git a/winpr/libwinpr/thread/process.c b/winpr/libwinpr/thread/process.c index 52aac7728..2c179c77b 100644 --- a/winpr/libwinpr/thread/process.c +++ b/winpr/libwinpr/thread/process.c @@ -26,7 +26,6 @@ #include "../handle/nonehandle.h" #include -#include /** * CreateProcessA @@ -54,30 +53,16 @@ #ifndef _WIN32 -#ifdef HAVE_UNISTD_H -#include -#endif - #include -#include #include -#include #include -#include #include -#include -#include #include -#include -#include - -#include #include "thread.h" -#include "../handle/handle.h" #include "../security/security.h" #ifndef NSIG @@ -88,55 +73,6 @@ #endif #endif -char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock) -{ - char* p; - int index; - int count; - int length; - char** envp = NULL; - - count = 0; - if (!lpszEnvironmentBlock) - return NULL; - - p = (char*) lpszEnvironmentBlock; - - while (p[0] && p[1]) - { - length = strlen(p); - p += (length + 1); - count++; - } - - index = 0; - p = (char*) lpszEnvironmentBlock; - - envp = (char**) calloc(count + 1, sizeof(char*)); - if (!envp) - return NULL; - envp[count] = NULL; - - while (p[0] && p[1]) - { - length = strlen(p); - envp[index] = _strdup(p); - if (!envp[index]) - { - for (index -= 1; index >= 0; --index) - { - free(envp[index]); - } - free(envp); - return NULL; - } - p += (length + 1); - index++; - } - - return envp; -} - /** * If the file name does not contain a directory path, the system searches for the executable file in the following sequence: * @@ -151,7 +87,7 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock) * this per-application path in the search sequence, use the ShellExecute function. */ -char* FindApplicationPath(char* application) +static char* FindApplicationPath(char* application) { char* path; char* save; @@ -208,7 +144,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) { pid_t pid; - int flags; int numArgs; LPSTR* pArgs = NULL; char** envp = NULL; @@ -230,7 +165,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, if (!pArgs) return FALSE; - flags = 0; token = (WINPR_ACCESS_TOKEN*) hToken; @@ -532,7 +466,7 @@ BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode) } -BOOL ProcessHandleCloseHandle(HANDLE handle) +static BOOL ProcessHandleCloseHandle(HANDLE handle) { WINPR_PROCESS* process = (WINPR_PROCESS*) handle; free(process); @@ -586,6 +520,5 @@ HANDLE CreateProcessHandle(pid_t pid) return (HANDLE)process; } - #endif From 17a2d1ba1c2bf90ad666efb79b1a357bfa108b34 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 22 Oct 2015 09:01:30 +0200 Subject: [PATCH 045/220] Fixed clipboard file contents response and message to string. --- channels/cliprdr/client/cliprdr_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/channels/cliprdr/client/cliprdr_main.c b/channels/cliprdr/client/cliprdr_main.c index 708663381..18b594ed0 100644 --- a/channels/cliprdr/client/cliprdr_main.c +++ b/channels/cliprdr/client/cliprdr_main.c @@ -46,7 +46,7 @@ const char* const CB_MSG_TYPE_STRINGS[] = "CB_CLIP_CAPS", "CB_FILECONTENTS_REQUEST", "CB_FILECONTENTS_RESPONSE", - "CB_LOCK_CLIPDATA" + "CB_LOCK_CLIPDATA", "CB_UNLOCK_CLIPDATA" }; @@ -471,9 +471,9 @@ static UINT cliprdr_order_recv(cliprdrPlugin* cliprdr, wStream* s) Stream_Read_UINT16(s, msgFlags); /* msgFlags (2 bytes) */ Stream_Read_UINT32(s, dataLen); /* dataLen (4 bytes) */ - DEBUG_CLIPRDR("msgType: %s (%d), msgFlags: %d dataLen: %d", - CB_MSG_TYPE_STRINGS[msgType], msgType, msgFlags, dataLen); #ifdef WITH_DEBUG_CLIPRDR + WLog_DBG(TAG, "msgType: %s (%d), msgFlags: %d dataLen: %d", + CB_MSG_TYPE_STRINGS[msgType], msgType, msgFlags, dataLen); winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), dataLen + 8); #endif @@ -910,7 +910,7 @@ UINT cliprdr_client_file_contents_response(CliprdrClientContext* context, CLIPRD if (fileContentsResponse->dwFlags & FILECONTENTS_SIZE) fileContentsResponse->cbRequested = sizeof(UINT64); - s = cliprdr_packet_new(CB_FILECONTENTS_REQUEST, 0, + s = cliprdr_packet_new(CB_FILECONTENTS_RESPONSE, fileContentsResponse->msgFlags, 4 + fileContentsResponse->cbRequested); if (!s) From 34191cdafcf4982ef0de4ca42f765286882d9cce Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 22 Oct 2015 09:31:47 +0200 Subject: [PATCH 046/220] Fixed clipboard file transfer. --- client/Windows/wf_client.h | 2 +- client/Windows/wf_cliprdr.c | 1597 +++++++++++++++++++++-------------- client/Windows/wf_cliprdr.h | 116 +-- 3 files changed, 963 insertions(+), 752 deletions(-) diff --git a/client/Windows/wf_client.h b/client/Windows/wf_client.h index 5ec8f8293..8f65c442a 100644 --- a/client/Windows/wf_client.h +++ b/client/Windows/wf_client.h @@ -137,7 +137,7 @@ struct wf_context int yCurrentScroll; int yMaxScroll; - wfClipboard* clipboard; + void* clipboard; CliprdrClientContext* cliprdr; FloatBar* floatbar; diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index dc1868ff0..85aa28113 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -24,6 +24,14 @@ #include "config.h" #endif +#define CINTERFACE +#define COBJMACROS + +#include +#include +#include +#include + #include #include @@ -39,23 +47,119 @@ #define TAG CLIENT_TAG("windows") +#ifdef WITH_DEBUG_CLIPRDR +#define DEBUG_CLIPRDR(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__) +#else +#define DEBUG_CLIPRDR(fmt, ...) do { } while (0) +#endif + +struct format_mapping +{ + UINT32 remote_format_id; + UINT32 local_format_id; + WCHAR* name; +}; +typedef struct format_mapping formatMapping; + +struct _CliprdrEnumFORMATETC +{ + IEnumFORMATETC iEnumFORMATETC; + + LONG m_lRefCount; + LONG m_nIndex; + LONG m_nNumFormats; + FORMATETC* m_pFormatEtc; +}; +typedef struct _CliprdrEnumFORMATETC CliprdrEnumFORMATETC; + +struct _CliprdrStream +{ + IStream iStream; + + LONG m_lRefCount; + LONG m_lIndex; + ULARGE_INTEGER m_lSize; + ULARGE_INTEGER m_lOffset; + void* m_pData; +}; +typedef struct _CliprdrStream CliprdrStream; + +struct _CliprdrDataObject +{ + IDataObject iDataObject; + + LONG m_lRefCount; + FORMATETC* m_pFormatEtc; + STGMEDIUM* m_pStgMedium; + LONG m_nNumFormats; + LONG m_nStreams; + IStream** m_pStream; + void* m_pData; +}; +typedef struct _CliprdrDataObject CliprdrDataObject; + +struct wf_clipboard +{ + wfContext* wfc; + rdpChannels* channels; + CliprdrClientContext* context; + + BOOL sync; + UINT32 capabilities; + + size_t map_size; + size_t map_capacity; + formatMapping* format_mappings; + + UINT32 requestedFormatId; + + HWND hwnd; + HANDLE hmem; + HANDLE thread; + HANDLE response_data_event; + + LPDATAOBJECT data_obj; + ULONG req_fsize; + char* req_fdata; + HANDLE req_fevent; + + size_t nFiles; + size_t file_array_size; + WCHAR** file_names; + FILEDESCRIPTORW** fileDescriptor; +}; +typedef struct wf_clipboard wfClipboard; + extern BOOL WINAPI AddClipboardFormatListener(_In_ HWND hwnd); extern BOOL WINAPI RemoveClipboardFormatListener(_In_ HWND hwnd); #define WM_CLIPRDR_MESSAGE (WM_USER + 156) #define OLE_SETCLIPBOARD 1 -BOOL wf_create_file_obj(wfClipboard* cliprdrrdr, IDataObject** ppDataObject); -void wf_destroy_file_obj(IDataObject* instance); +static BOOL wf_create_file_obj(wfClipboard* cliprdrrdr, IDataObject** ppDataObject); +static void wf_destroy_file_obj(IDataObject* instance); +static UINT32 get_remote_format_id(wfClipboard* clipboard, UINT32 local_format); +static UINT cliprdr_send_data_request(wfClipboard* clipboard, UINT32 format); +static UINT cliprdr_send_lock(wfClipboard* clipboard); +static UINT cliprdr_send_unlock(wfClipboard* clipboard); +static UINT cliprdr_send_request_filecontents(wfClipboard* clipboard, void* streamid, + int index, int flag, DWORD positionhigh, + DWORD positionlow, ULONG request); + +static void CliprdrDataObject_Delete(CliprdrDataObject* instance); + +static CliprdrEnumFORMATETC* CliprdrEnumFORMATETC_New(int nFormats, FORMATETC* pFormatEtc); +static void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* instance); + +static void CliprdrStream_Delete(CliprdrStream* instance); /** * IStream */ -HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream* This, REFIID riid, void** ppvObject) +static HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream* This, + REFIID riid, void** ppvObject) { - CliprdrStream* instance = (CliprdrStream*) This; - if (IsEqualIID(riid, &IID_IStream) || IsEqualIID(riid, &IID_IUnknown)) { IStream_AddRef(This); @@ -69,18 +173,24 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream* This, REFIID rii } } -ULONG STDMETHODCALLTYPE CliprdrStream_AddRef(IStream* This) +static ULONG STDMETHODCALLTYPE CliprdrStream_AddRef(IStream* This) { CliprdrStream* instance = (CliprdrStream*) This; + if (!instance) + return 0; + return InterlockedIncrement(&instance->m_lRefCount); } -ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream* This) +static ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream* This) { LONG count; CliprdrStream* instance = (CliprdrStream*) This; + if (!instance) + return 0; + count = InterlockedDecrement(&instance->m_lRefCount); if (count == 0) @@ -94,23 +204,25 @@ ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream* This) } } -HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream* This, void *pv, ULONG cb, ULONG *pcbRead) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream* This, void *pv, + ULONG cb, ULONG *pcbRead) { int ret; CliprdrStream* instance = (CliprdrStream*) This; - wfClipboard* clipboard = (wfClipboard*) instance->m_pData; + wfClipboard* clipboard; - if (!pv || !pcbRead) + if (!pv || !pcbRead || !instance) return E_INVALIDARG; + clipboard = (wfClipboard*) instance->m_pData; *pcbRead = 0; if (instance->m_lOffset.QuadPart >= instance->m_lSize.QuadPart) - return E_FAIL; + return S_FALSE; ret = cliprdr_send_request_filecontents(clipboard, (void*) This, - instance->m_lIndex, FILECONTENTS_RANGE, - instance->m_lOffset.HighPart, instance->m_lOffset.LowPart, cb); + instance->m_lIndex, FILECONTENTS_RANGE, + instance->m_lOffset.HighPart, instance->m_lOffset.LowPart, cb); if (ret < 0) return E_FAIL; @@ -125,38 +237,46 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream* This, void *pv, ULONG cb, instance->m_lOffset.QuadPart += clipboard->req_fsize; if (clipboard->req_fsize < cb) - return E_FAIL; + return S_FALSE; return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Write(IStream* This, const void* pv, ULONG cb, ULONG *pcbWritten) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Write(IStream* This, const void* pv, + ULONG cb, ULONG *pcbWritten) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)pv; + (void)cb; + (void)pcbWritten; return STG_E_ACCESSDENIED; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream* This, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream* This, LARGE_INTEGER dlibMove, + DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) { ULONGLONG newoffset; CliprdrStream* instance = (CliprdrStream*) This; + if (!instance) + return E_INVALIDARG; + newoffset = instance->m_lOffset.QuadPart; switch (dwOrigin) { - case STREAM_SEEK_SET: - newoffset = dlibMove.QuadPart; - break; - case STREAM_SEEK_CUR: - newoffset += dlibMove.QuadPart; - break; - case STREAM_SEEK_END: - newoffset = instance->m_lSize.QuadPart + dlibMove.QuadPart; - break; - default: - return E_INVALIDARG; + case STREAM_SEEK_SET: + newoffset = dlibMove.QuadPart; + break; + case STREAM_SEEK_CUR: + newoffset += dlibMove.QuadPart; + break; + case STREAM_SEEK_END: + newoffset = instance->m_lSize.QuadPart + dlibMove.QuadPart; + break; + default: + return E_INVALIDARG; } if (newoffset < 0 || newoffset >= instance->m_lSize.QuadPart) @@ -170,52 +290,72 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream* This, LARGE_INTEGER dlibMo return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_SetSize(IStream* This, ULARGE_INTEGER libNewSize) +static HRESULT STDMETHODCALLTYPE CliprdrStream_SetSize(IStream* This, + ULARGE_INTEGER libNewSize) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)libNewSize; - return STG_E_INSUFFICIENTMEMORY; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_CopyTo(IStream* This, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER *pcbWritten) +static HRESULT STDMETHODCALLTYPE CliprdrStream_CopyTo(IStream* This, IStream* pstm, + ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, + ULARGE_INTEGER *pcbWritten) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)pstm; + (void)cb; + (void)pcbRead; + (void)pcbWritten; - return S_OK; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Commit(IStream* This, DWORD grfCommitFlags) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Commit(IStream* This, DWORD grfCommitFlags) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)grfCommitFlags; - return STG_E_MEDIUMFULL; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Revert(IStream* This) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Revert(IStream* This) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; - return STG_E_INSUFFICIENTMEMORY; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_LockRegion(IStream* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) +static HRESULT STDMETHODCALLTYPE CliprdrStream_LockRegion(IStream* This, ULARGE_INTEGER libOffset, + ULARGE_INTEGER cb, DWORD dwLockType) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)libOffset; + (void)cb; + (void)dwLockType; - return STG_E_INSUFFICIENTMEMORY; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_UnlockRegion(IStream* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) +static HRESULT STDMETHODCALLTYPE CliprdrStream_UnlockRegion(IStream* This, ULARGE_INTEGER libOffset, + ULARGE_INTEGER cb, DWORD dwLockType) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)libOffset; + (void)cb; + (void)dwLockType; - return STG_E_INSUFFICIENTMEMORY; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream* This, STATSTG* pstatstg, DWORD grfStatFlag) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream* This, STATSTG* pstatstg, DWORD grfStatFlag) { CliprdrStream* instance = (CliprdrStream*) This; + if (!instance) + return E_INVALIDARG; + if (pstatstg == NULL) return STG_E_INVALIDPOINTER; @@ -223,37 +363,39 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream* This, STATSTG* pstatstg, D switch (grfStatFlag) { - case STATFLAG_DEFAULT: - return STG_E_INSUFFICIENTMEMORY; + case STATFLAG_DEFAULT: + return STG_E_INSUFFICIENTMEMORY; - case STATFLAG_NONAME: - pstatstg->cbSize.QuadPart = instance->m_lSize.QuadPart; - pstatstg->grfLocksSupported = LOCK_EXCLUSIVE; - pstatstg->grfMode = GENERIC_READ; - pstatstg->grfStateBits = 0; - pstatstg->type = STGTY_STREAM; - break; + case STATFLAG_NONAME: + pstatstg->cbSize.QuadPart = instance->m_lSize.QuadPart; + pstatstg->grfLocksSupported = LOCK_EXCLUSIVE; + pstatstg->grfMode = GENERIC_READ; + pstatstg->grfStateBits = 0; + pstatstg->type = STGTY_STREAM; + break; - case STATFLAG_NOOPEN: - return STG_E_INVALIDFLAG; + case STATFLAG_NOOPEN: + return STG_E_INVALIDFLAG; - default: - return STG_E_INVALIDFLAG; + default: + return STG_E_INVALIDFLAG; } return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream* This, IStream** ppstm) +static HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream* This, IStream** ppstm) { - CliprdrStream* instance = (CliprdrStream*) This; + (void)This; + (void)ppstm; - return STG_E_INSUFFICIENTMEMORY; + return E_NOTIMPL; } -CliprdrStream* CliprdrStream_New(LONG index, void* pData) +static CliprdrStream* CliprdrStream_New(LONG index, void* pData) { IStream* iStream; + BOOL success = FALSE; CliprdrStream* instance; wfClipboard* clipboard = (wfClipboard*) pData; @@ -288,16 +430,22 @@ CliprdrStream* CliprdrStream_New(LONG index, void* pData) instance->m_lOffset.QuadPart = 0; /* get content size of this stream */ - cliprdr_send_request_filecontents(clipboard, (void*) instance, - instance->m_lIndex, FILECONTENTS_SIZE, 0, 0, 8); + if (cliprdr_send_request_filecontents(clipboard, (void*) instance, + instance->m_lIndex, + FILECONTENTS_SIZE, 0, 0, 8) == CHANNEL_RC_OK) + { + success = TRUE; + } + instance->m_lSize.QuadPart = *((LONGLONG*) clipboard->req_fdata); free(clipboard->req_fdata); } - else - { - free(instance); - instance = NULL; - } + } + + if (!success) + { + CliprdrStream_Delete(instance); + instance = NULL; } return instance; @@ -320,11 +468,14 @@ static int cliprdr_lookup_format(CliprdrDataObject* instance, FORMATETC* pFormat { int i; + if (!instance || !pFormatEtc) + return -1; + for (i = 0; i < instance->m_nNumFormats; i++) { if ((pFormatEtc->tymed & instance->m_pFormatEtc[i].tymed) && - pFormatEtc->cfFormat == instance->m_pFormatEtc[i].cfFormat && - pFormatEtc->dwAspect == instance->m_pFormatEtc[i].dwAspect) + pFormatEtc->cfFormat == instance->m_pFormatEtc[i].cfFormat && + pFormatEtc->dwAspect & instance->m_pFormatEtc[i].dwAspect) { return i; } @@ -333,9 +484,13 @@ static int cliprdr_lookup_format(CliprdrDataObject* instance, FORMATETC* pFormat return -1; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject* This, REFIID riid, void** ppvObject) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface( + IDataObject* This, REFIID riid, void** ppvObject) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + + if (!ppvObject) + return E_INVALIDARG; if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown)) { @@ -350,18 +505,24 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject* This, RE } } -ULONG STDMETHODCALLTYPE CliprdrDataObject_AddRef(IDataObject* This) +static ULONG STDMETHODCALLTYPE CliprdrDataObject_AddRef(IDataObject* This) { CliprdrDataObject* instance = (CliprdrDataObject*) This; + if (!instance) + return E_INVALIDARG; + return InterlockedIncrement(&instance->m_lRefCount); } -ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject* This) +static ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject* This) { LONG count; CliprdrDataObject* instance = (CliprdrDataObject*) This; + if (!instance) + return E_INVALIDARG; + count = InterlockedDecrement(&instance->m_lRefCount); if (count == 0) @@ -370,33 +531,34 @@ ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject* This) return 0; } else - { return count; - } } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC* pFormatEtc, STGMEDIUM* pMedium) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData( + IDataObject* This, FORMATETC* pFormatEtc, STGMEDIUM* pMedium) { int i, idx; CliprdrDataObject* instance = (CliprdrDataObject*) This; - wfClipboard* clipboard = (wfClipboard*) instance->m_pData; + wfClipboard* clipboard; - if (!pFormatEtc || !pMedium) - { + if (!pFormatEtc || !pMedium || !instance) + return E_INVALIDARG; + + clipboard = clipboard = (wfClipboard*) instance->m_pData; + + if (!clipboard) return E_INVALIDARG; - } if ((idx = cliprdr_lookup_format(instance, pFormatEtc)) == -1) - { return DV_E_FORMATETC; - } pMedium->tymed = instance->m_pFormatEtc[idx].tymed; pMedium->pUnkForRelease = 0; - if (instance->m_pFormatEtc[idx].cfFormat == clipboard->ID_FILEDESCRIPTORW) + if (instance->m_pFormatEtc[idx].cfFormat == RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW)) { - if (cliprdr_send_data_request(clipboard, instance->m_pFormatEtc[idx].cfFormat) != 0) + DWORD remote = get_remote_format_id(clipboard, instance->m_pFormatEtc[idx].cfFormat); + if (cliprdr_send_data_request(clipboard, remote) != 0) return E_UNEXPECTED; pMedium->hGlobal = clipboard->hmem; /* points to a FILEGROUPDESCRIPTOR structure */ @@ -404,7 +566,8 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC /* GlobalLock returns a pointer to the first byte of the memory block, * in which is a FILEGROUPDESCRIPTOR structure, whose first UINT member * is the number of FILEDESCRIPTOR's */ - instance->m_nStreams = *((PUINT) GlobalLock(clipboard->hmem)); + FILEGROUPDESCRIPTOR *dsc = (FILEGROUPDESCRIPTOR*) GlobalLock(clipboard->hmem); + instance->m_nStreams = dsc->cItems; GlobalUnlock(clipboard->hmem); if (instance->m_nStreams > 0) @@ -416,9 +579,7 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC if (instance->m_pStream) { for (i = 0; i < instance->m_nStreams; i++) - { instance->m_pStream[i] = (IStream*) CliprdrStream_New(i, clipboard); - } } } } @@ -436,7 +597,7 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC return E_OUTOFMEMORY; } } - else if (instance->m_pFormatEtc[idx].cfFormat == clipboard->ID_FILECONTENTS) + else if (instance->m_pFormatEtc[idx].cfFormat == RegisterClipboardFormat(CFSTR_FILECONTENTS)) { if (pFormatEtc->lindex < instance->m_nStreams) { @@ -444,45 +605,43 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC IDataObject_AddRef(instance->m_pStream[pFormatEtc->lindex]); } else - { return E_INVALIDARG; - } - } - else if (instance->m_pFormatEtc[idx].cfFormat == clipboard->ID_PREFERREDDROPEFFECT) - { - if (cliprdr_send_data_request(clipboard, instance->m_pFormatEtc[idx].cfFormat) != 0) - return E_UNEXPECTED; - - pMedium->hGlobal = clipboard->hmem; } else - { return E_UNEXPECTED; - } return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetDataHere(IDataObject* This, FORMATETC* pformatetc, STGMEDIUM* pmedium) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetDataHere( + IDataObject* This, FORMATETC* pformatetc, STGMEDIUM* pmedium) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + (void)pformatetc; + (void)pmedium; - return DATA_E_FORMATETC; + return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData(IDataObject* This, FORMATETC* pformatetc) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData( + IDataObject* This, FORMATETC* pformatetc) { CliprdrDataObject* instance = (CliprdrDataObject*) This; if (!pformatetc) return E_INVALIDARG; - return (cliprdr_lookup_format(instance, pformatetc) == -1) ? DV_E_FORMATETC : S_OK; + if (cliprdr_lookup_format(instance, pformatetc) == -1) + return DV_E_FORMATETC; + + return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject* This, FORMATETC* pformatectIn, FORMATETC* pformatetcOut) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc( + IDataObject* This, FORMATETC* pformatectIn, FORMATETC* pformatetcOut) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + (void)pformatectIn; if (!pformatetcOut) return E_INVALIDARG; @@ -492,18 +651,23 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject* T return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_SetData(IDataObject* This, FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_SetData( + IDataObject* This, FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + (void)pformatetc; + (void)pmedium; + (void)fRelease; return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject* This, DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc( + IDataObject* This, DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc) { CliprdrDataObject* instance = (CliprdrDataObject*) This; - if (!ppenumFormatEtc) + if (!instance || !ppenumFormatEtc) return E_INVALIDARG; if (dwDirection == DATADIR_GET) @@ -517,28 +681,39 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject* This, DWO } } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_DAdvise(IDataObject* This, FORMATETC* pformatetc, DWORD advf, IAdviseSink* pAdvSink, DWORD* pdwConnection) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_DAdvise( + IDataObject* This, FORMATETC* pformatetc, DWORD advf, + IAdviseSink* pAdvSink, DWORD* pdwConnection) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + (void)pformatetc; + (void)advf; + (void)pAdvSink; + (void)pdwConnection; return OLE_E_ADVISENOTSUPPORTED; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_DUnadvise(IDataObject* This, DWORD dwConnection) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_DUnadvise( + IDataObject* This, DWORD dwConnection) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + (void)dwConnection; return OLE_E_ADVISENOTSUPPORTED; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumDAdvise(IDataObject* This, IEnumSTATDATA** ppenumAdvise) +static HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumDAdvise( + IDataObject* This, IEnumSTATDATA** ppenumAdvise) { - CliprdrDataObject* instance = (CliprdrDataObject*) This; + (void)This; + (void)ppenumAdvise; return OLE_E_ADVISENOTSUPPORTED; } -CliprdrDataObject* CliprdrDataObject_New(FORMATETC* fmtetc, STGMEDIUM* stgmed, int count, void* data) +static CliprdrDataObject* CliprdrDataObject_New( + FORMATETC* fmtetc, STGMEDIUM* stgmed, int count, void* data) { int i; CliprdrDataObject* instance; @@ -546,50 +721,56 @@ CliprdrDataObject* CliprdrDataObject_New(FORMATETC* fmtetc, STGMEDIUM* stgmed, i instance = (CliprdrDataObject*) calloc(1, sizeof(CliprdrDataObject)); - if (instance) + if (!instance) + goto error; + + iDataObject = &instance->iDataObject; + + iDataObject->lpVtbl = (IDataObjectVtbl*) calloc(1, sizeof(IDataObjectVtbl)); + + if (!iDataObject->lpVtbl) + goto error; + + iDataObject->lpVtbl->QueryInterface = CliprdrDataObject_QueryInterface; + iDataObject->lpVtbl->AddRef = CliprdrDataObject_AddRef; + iDataObject->lpVtbl->Release = CliprdrDataObject_Release; + iDataObject->lpVtbl->GetData = CliprdrDataObject_GetData; + iDataObject->lpVtbl->GetDataHere = CliprdrDataObject_GetDataHere; + iDataObject->lpVtbl->QueryGetData = CliprdrDataObject_QueryGetData; + iDataObject->lpVtbl->GetCanonicalFormatEtc = CliprdrDataObject_GetCanonicalFormatEtc; + iDataObject->lpVtbl->SetData = CliprdrDataObject_SetData; + iDataObject->lpVtbl->EnumFormatEtc = CliprdrDataObject_EnumFormatEtc; + iDataObject->lpVtbl->DAdvise = CliprdrDataObject_DAdvise; + iDataObject->lpVtbl->DUnadvise = CliprdrDataObject_DUnadvise; + iDataObject->lpVtbl->EnumDAdvise = CliprdrDataObject_EnumDAdvise; + + instance->m_lRefCount = 1; + instance->m_nNumFormats = count; + instance->m_pData = data; + instance->m_nStreams = 0; + instance->m_pStream = NULL; + + if (count > 0) { - iDataObject = &instance->iDataObject; + instance->m_pFormatEtc = (FORMATETC*) calloc(count, sizeof(FORMATETC)); + if (!instance->m_pFormatEtc) + goto error; + instance->m_pStgMedium = (STGMEDIUM*) calloc(count, sizeof(STGMEDIUM)); + if (!instance->m_pStgMedium) + goto error; - iDataObject->lpVtbl = (IDataObjectVtbl*) calloc(1, sizeof(IDataObjectVtbl)); - - if (iDataObject->lpVtbl) + for (i = 0; i < count; i++) { - iDataObject->lpVtbl->QueryInterface = CliprdrDataObject_QueryInterface; - iDataObject->lpVtbl->AddRef = CliprdrDataObject_AddRef; - iDataObject->lpVtbl->Release = CliprdrDataObject_Release; - iDataObject->lpVtbl->GetData = CliprdrDataObject_GetData; - iDataObject->lpVtbl->GetDataHere = CliprdrDataObject_GetDataHere; - iDataObject->lpVtbl->QueryGetData = CliprdrDataObject_QueryGetData; - iDataObject->lpVtbl->GetCanonicalFormatEtc = CliprdrDataObject_GetCanonicalFormatEtc; - iDataObject->lpVtbl->SetData = CliprdrDataObject_SetData; - iDataObject->lpVtbl->EnumFormatEtc = CliprdrDataObject_EnumFormatEtc; - iDataObject->lpVtbl->DAdvise = CliprdrDataObject_DAdvise; - iDataObject->lpVtbl->DUnadvise = CliprdrDataObject_DUnadvise; - iDataObject->lpVtbl->EnumDAdvise = CliprdrDataObject_EnumDAdvise; - - instance->m_lRefCount = 1; - instance->m_nNumFormats = count; - instance->m_pData = data; - instance->m_nStreams = 0; - instance->m_pStream = NULL; - - instance->m_pFormatEtc = (FORMATETC*) calloc(count, sizeof(FORMATETC)); - instance->m_pStgMedium = (STGMEDIUM*) calloc(count, sizeof(STGMEDIUM)); - - for (i = 0; i < count; i++) - { - instance->m_pFormatEtc[i] = fmtetc[i]; - instance->m_pStgMedium[i] = stgmed[i]; - } - } - else - { - free(instance); - instance = NULL; + instance->m_pFormatEtc[i] = fmtetc[i]; + instance->m_pStgMedium[i] = stgmed[i]; } } return instance; + +error: + CliprdrDataObject_Delete(instance); + return NULL; } void CliprdrDataObject_Delete(CliprdrDataObject* instance) @@ -602,12 +783,10 @@ void CliprdrDataObject_Delete(CliprdrDataObject* instance) if (instance->m_pStream) { - int i; + LONG i; for (i = 0; i < instance->m_nStreams; i++) - { CliprdrStream_Release(instance->m_pStream[i]); - } free(instance->m_pStream); } @@ -616,15 +795,15 @@ void CliprdrDataObject_Delete(CliprdrDataObject* instance) } } -BOOL wf_create_file_obj(wfClipboard* clipboard, IDataObject** ppDataObject) +static BOOL wf_create_file_obj(wfClipboard* clipboard, IDataObject** ppDataObject) { - FORMATETC fmtetc[3]; - STGMEDIUM stgmeds[3]; + FORMATETC fmtetc[2]; + STGMEDIUM stgmeds[2]; if (!ppDataObject) return FALSE; - fmtetc[0].cfFormat = RegisterClipboardFormatW(CFSTR_FILEDESCRIPTORW); + fmtetc[0].cfFormat = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW); fmtetc[0].dwAspect = DVASPECT_CONTENT; fmtetc[0].lindex = 0; fmtetc[0].ptd = NULL; @@ -634,7 +813,7 @@ BOOL wf_create_file_obj(wfClipboard* clipboard, IDataObject** ppDataObject) stgmeds[0].hGlobal = NULL; stgmeds[0].pUnkForRelease = NULL; - fmtetc[1].cfFormat = RegisterClipboardFormatW(CFSTR_FILECONTENTS); + fmtetc[1].cfFormat = RegisterClipboardFormat(CFSTR_FILECONTENTS); fmtetc[1].dwAspect = DVASPECT_CONTENT; fmtetc[1].lindex = 0; fmtetc[1].ptd = NULL; @@ -644,22 +823,12 @@ BOOL wf_create_file_obj(wfClipboard* clipboard, IDataObject** ppDataObject) stgmeds[1].pstm = NULL; stgmeds[1].pUnkForRelease = NULL; - fmtetc[2].cfFormat = RegisterClipboardFormatW(CFSTR_PREFERREDDROPEFFECT); - fmtetc[2].dwAspect = DVASPECT_CONTENT; - fmtetc[2].lindex = 0; - fmtetc[2].ptd = NULL; - fmtetc[2].tymed = TYMED_HGLOBAL; - - stgmeds[2].tymed = TYMED_HGLOBAL; - stgmeds[2].hGlobal = NULL; - stgmeds[2].pUnkForRelease = NULL; - - *ppDataObject = (IDataObject*) CliprdrDataObject_New(fmtetc, stgmeds, 3, clipboard); + *ppDataObject = (IDataObject*) CliprdrDataObject_New(fmtetc, stgmeds, 2, clipboard); return (*ppDataObject) ? TRUE : FALSE; } -void wf_destroy_file_obj(IDataObject* instance) +static void wf_destroy_file_obj(IDataObject* instance) { if (instance) IDataObject_Release(instance); @@ -676,13 +845,15 @@ static void cliprdr_format_deep_copy(FORMATETC* dest, FORMATETC* source) if (source->ptd) { dest->ptd = (DVTARGETDEVICE*) CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); - *(dest->ptd) = *(source->ptd); + if (dest->ptd) + *(dest->ptd) = *(source->ptd); } } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC* This, REFIID riid, void** ppvObject) +static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface( + IEnumFORMATETC* This, REFIID riid, void** ppvObject) { - CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; + (void)This; if (IsEqualIID(riid, &IID_IEnumFORMATETC) || IsEqualIID(riid, &IID_IUnknown)) { @@ -697,18 +868,24 @@ HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC* Th } } -ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_AddRef(IEnumFORMATETC* This) +static ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_AddRef(IEnumFORMATETC* This) { CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; + if (!instance) + return 0; + return InterlockedIncrement(&instance->m_lRefCount); } -ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC* This) +static ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC* This) { LONG count; CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; + if (!instance) + return 0; + count = InterlockedDecrement(&instance->m_lRefCount); if (count == 0) @@ -722,12 +899,13 @@ ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC* This) } } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC* This, ULONG celt, FORMATETC* rgelt, ULONG* pceltFetched) +static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC* This, ULONG celt, + FORMATETC* rgelt, ULONG* pceltFetched) { ULONG copied = 0; CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; - if (!celt || !rgelt) + if (!instance || !celt || !rgelt) return E_INVALIDARG; while ((instance->m_nIndex < instance->m_nNumFormats) && (copied < celt)) @@ -741,10 +919,13 @@ HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC* This, ULONG return (copied == celt) ? S_OK : E_FAIL; } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC* This, ULONG celt) +static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC* This, ULONG celt) { CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; + if (!instance) + return E_INVALIDARG; + if (instance->m_nIndex + (LONG) celt > instance->m_nNumFormats) return E_FAIL; @@ -753,20 +934,23 @@ HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC* This, ULONG return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Reset(IEnumFORMATETC* This) +static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Reset(IEnumFORMATETC* This) { CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; + if (!instance) + return E_INVALIDARG; + instance->m_nIndex = 0; return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Clone(IEnumFORMATETC* This, IEnumFORMATETC **ppEnum) +static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Clone(IEnumFORMATETC* This, IEnumFORMATETC **ppEnum) { CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; - if (!ppEnum) + if (!instance || !ppEnum) return E_INVALIDARG; *ppEnum = (IEnumFORMATETC*) CliprdrEnumFORMATETC_New(instance->m_nNumFormats, instance->m_pFormatEtc); @@ -785,50 +969,51 @@ CliprdrEnumFORMATETC* CliprdrEnumFORMATETC_New(int nFormats, FORMATETC* pFormatE CliprdrEnumFORMATETC* instance; IEnumFORMATETC* iEnumFORMATETC; - if (!pFormatEtc) + if ((nFormats != 0) && !pFormatEtc) return NULL; instance = (CliprdrEnumFORMATETC*) calloc(1, sizeof(CliprdrEnumFORMATETC)); - if (instance) + if (!instance) + goto error; + + iEnumFORMATETC = &instance->iEnumFORMATETC; + + iEnumFORMATETC->lpVtbl = (IEnumFORMATETCVtbl*) calloc(1, sizeof(IEnumFORMATETCVtbl)); + + if (!iEnumFORMATETC->lpVtbl) + goto error; + + iEnumFORMATETC->lpVtbl->QueryInterface = CliprdrEnumFORMATETC_QueryInterface; + iEnumFORMATETC->lpVtbl->AddRef = CliprdrEnumFORMATETC_AddRef; + iEnumFORMATETC->lpVtbl->Release = CliprdrEnumFORMATETC_Release; + iEnumFORMATETC->lpVtbl->Next = CliprdrEnumFORMATETC_Next; + iEnumFORMATETC->lpVtbl->Skip = CliprdrEnumFORMATETC_Skip; + iEnumFORMATETC->lpVtbl->Reset = CliprdrEnumFORMATETC_Reset; + iEnumFORMATETC->lpVtbl->Clone = CliprdrEnumFORMATETC_Clone; + + instance->m_lRefCount = 0; + instance->m_nIndex = 0; + instance->m_nNumFormats = nFormats; + if (nFormats > 0) { - iEnumFORMATETC = &instance->iEnumFORMATETC; + instance->m_pFormatEtc = (FORMATETC*) calloc(nFormats, sizeof(FORMATETC)); + if (!instance->m_pFormatEtc) + goto error; - iEnumFORMATETC->lpVtbl = (IEnumFORMATETCVtbl*) calloc(1, sizeof(IEnumFORMATETCVtbl)); - - if (iEnumFORMATETC->lpVtbl) - { - iEnumFORMATETC->lpVtbl->QueryInterface = CliprdrEnumFORMATETC_QueryInterface; - iEnumFORMATETC->lpVtbl->AddRef = CliprdrEnumFORMATETC_AddRef; - iEnumFORMATETC->lpVtbl->Release = CliprdrEnumFORMATETC_Release; - iEnumFORMATETC->lpVtbl->Next = CliprdrEnumFORMATETC_Next; - iEnumFORMATETC->lpVtbl->Skip = CliprdrEnumFORMATETC_Skip; - iEnumFORMATETC->lpVtbl->Reset = CliprdrEnumFORMATETC_Reset; - iEnumFORMATETC->lpVtbl->Clone = CliprdrEnumFORMATETC_Clone; - - instance->m_lRefCount = 0; - instance->m_nIndex = 0; - instance->m_nNumFormats = nFormats; - instance->m_pFormatEtc = (FORMATETC*) calloc(nFormats, sizeof(FORMATETC)); - - for (i = 0; i < nFormats; i++) - { - cliprdr_format_deep_copy(&instance->m_pFormatEtc[i], &pFormatEtc[i]); - } - } - else - { - free(instance); - instance = NULL; - } + for (i = 0; i < nFormats; i++) + cliprdr_format_deep_copy(&instance->m_pFormatEtc[i], &pFormatEtc[i]); } - return instance; + +error: + CliprdrEnumFORMATETC_Delete(instance); + return NULL; } void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* instance) { - int i; + LONG i; if (instance) { @@ -851,46 +1036,67 @@ void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* instance) /***********************************************************************************/ -static UINT32 get_local_format_id_by_name(wfClipboard* clipboard, void* format_name) +static UINT32 get_local_format_id_by_name(wfClipboard* clipboard, const TCHAR* format_name) { - int i; + size_t i; formatMapping* map; + WCHAR* unicode_name; +#if !defined(UNICODE) + size_t size; +#endif + + if (!clipboard || !format_name) + return 0; + +#if defined(UNICODE) + unicode_name = _wcsdup(format_name); +#else + size = _tcslen(format_name); + unicode_name = calloc(size + 1, sizeof(WCHAR)); + if (!unicode_name) + return 0; + + MultiByteToWideChar(CP_OEMCP, 0, format_name, strlen(format_name), unicode_name, size); +#endif + if (!unicode_name) + return 0; for (i = 0; i < clipboard->map_size; i++) { map = &clipboard->format_mappings[i]; - - if ((clipboard->capabilities & CB_USE_LONG_FORMAT_NAMES) != 0) + if (map->name) { - if (map->name) + if (wcscmp(map->name, unicode_name) == 0) { - if (memcmp(map->name, format_name, wcslen((LPCWSTR) format_name)) == 0) - return map->local_format_id; + free (unicode_name); + return map->local_format_id; } } } + free (unicode_name); return 0; } static INLINE BOOL file_transferring(wfClipboard* clipboard) { - return get_local_format_id_by_name(clipboard, _T("FileGroupDescriptorW")) ? TRUE : FALSE; + return get_local_format_id_by_name(clipboard, CFSTR_FILEDESCRIPTORW) ? TRUE : FALSE; } static UINT32 get_remote_format_id(wfClipboard* clipboard, UINT32 local_format) { - int i; + UINT32 i; formatMapping* map; + if (!clipboard) + return 0; + for (i = 0; i < clipboard->map_size; i++) { map = &clipboard->format_mappings[i]; if (map->local_format_id == local_format) - { return map->remote_format_id; - } } return local_format; @@ -898,14 +1104,17 @@ static UINT32 get_remote_format_id(wfClipboard* clipboard, UINT32 local_format) static void map_ensure_capacity(wfClipboard* clipboard) { + if (!clipboard) + return; + if (clipboard->map_size >= clipboard->map_capacity) { - int new_size; + size_t new_size; formatMapping *new_map; new_size = clipboard->map_capacity * 2; new_map = (formatMapping*) realloc(clipboard->format_mappings, - sizeof(formatMapping) * new_size); + sizeof(formatMapping) * new_size); if (!new_map) return; clipboard->format_mappings = new_map; @@ -913,11 +1122,14 @@ static void map_ensure_capacity(wfClipboard* clipboard) } } -static void clear_format_map(wfClipboard* clipboard) +static BOOL clear_format_map(wfClipboard* clipboard) { - int i; + size_t i; formatMapping* map; + if (!clipboard) + return FALSE; + if (clipboard->format_mappings) { for (i = 0; i < clipboard->map_capacity; i++) @@ -932,106 +1144,118 @@ static void clear_format_map(wfClipboard* clipboard) } clipboard->map_size = 0; + return TRUE; } -int cliprdr_send_tempdir(wfClipboard* clipboard) +static UINT cliprdr_send_tempdir(wfClipboard* clipboard) { CLIPRDR_TEMP_DIRECTORY tempDirectory; - GetEnvironmentVariableA("TEMP", tempDirectory.szTempDir, sizeof(tempDirectory.szTempDir)); + if (!clipboard) + return -1; - clipboard->context->TempDirectory(clipboard->context, &tempDirectory); + if (GetEnvironmentVariableA("TEMP", tempDirectory.szTempDir, sizeof(tempDirectory.szTempDir)) == 0) + return -1; - return 1; + return clipboard->context->TempDirectory(clipboard->context, &tempDirectory); } -static int cliprdr_send_format_list(wfClipboard* clipboard) +static UINT cliprdr_send_format_list(wfClipboard* clipboard) { + UINT rc; int count; - int length; UINT32 index; UINT32 numFormats; UINT32 formatId = 0; char formatName[1024]; - CLIPRDR_FORMAT* format; CLIPRDR_FORMAT* formats; CLIPRDR_FORMAT_LIST formatList; + if (!clipboard) + return ERROR_INTERNAL_ERROR; + ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); if (!OpenClipboard(clipboard->hwnd)) - return -1; + return ERROR_INTERNAL_ERROR; count = CountClipboardFormats(); numFormats = (UINT32) count; formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT)); + if (!formats) + { + CloseClipboard(); + return CHANNEL_RC_NO_MEMORY; + } index = 0; while (formatId = EnumClipboardFormats(formatId)) + formats[index++].formatId = formatId;; + + numFormats = index; + + if (!CloseClipboard()) { - format = &formats[index++]; - - format->formatId = formatId; - - length = 0; - format->formatName = NULL; - - if (formatId >= CF_MAX) - { - length = GetClipboardFormatNameA(formatId, formatName, sizeof(formatName) - 1); - } - - if (length > 0) - { - format->formatName = _strdup(formatName); - } + free (formats); + return ERROR_INTERNAL_ERROR; } - CloseClipboard(); - - formatList.msgFlags = 0; - formatList.numFormats = numFormats; - formatList.formats = formats; - - clipboard->context->ClientFormatList(clipboard->context, &formatList); - for (index = 0; index < numFormats; index++) { - format = &formats[index]; - free(format->formatName); + GetClipboardFormatNameA(formats[index].formatId, formatName, sizeof(formatName)); + formats[index].formatName = _strdup(formatName); } + formatList.numFormats = numFormats; + formatList.formats = formats; + + rc = clipboard->context->ClientFormatList(clipboard->context, &formatList); + + for (index = 0; index < numFormats; index++) + free(formats[index].formatName); + free(formats); - return 1; + return rc; } -int cliprdr_send_data_request(wfClipboard* clipboard, UINT32 formatId) +static UINT cliprdr_send_data_request(wfClipboard* clipboard, UINT32 formatId) { + UINT rc; CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest; + if (!clipboard || !clipboard->context || + !clipboard->context->ClientFormatDataRequest) + return ERROR_INTERNAL_ERROR; + formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST; formatDataRequest.msgFlags = CB_RESPONSE_OK; formatDataRequest.requestedFormatId = formatId; clipboard->requestedFormatId = formatId; - clipboard->context->ClientFormatDataRequest(clipboard->context, &formatDataRequest); + rc = clipboard->context->ClientFormatDataRequest(clipboard->context, &formatDataRequest); - WaitForSingleObject(clipboard->response_data_event, INFINITE); - ResetEvent(clipboard->response_data_event); + if (WaitForSingleObject(clipboard->response_data_event, INFINITE) != WAIT_OBJECT_0) + rc = ERROR_INTERNAL_ERROR; + else if (!ResetEvent(clipboard->response_data_event)) + rc = ERROR_INTERNAL_ERROR; - return 0; + return rc; } -int cliprdr_send_request_filecontents(wfClipboard* clipboard, void* streamid, - int index, int flag, DWORD positionhigh, DWORD positionlow, ULONG nreq) +static UINT cliprdr_send_request_filecontents(wfClipboard* clipboard, const void* streamid, + int index, int flag, DWORD positionhigh, + DWORD positionlow, ULONG nreq) { + UINT rc; CLIPRDR_FILE_CONTENTS_REQUEST fileContentsRequest; - ZeroMemory(&fileContentsRequest, sizeof(CLIPRDR_FILE_CONTENTS_REQUEST)); + if (!clipboard || !clipboard->context || + !clipboard->context->ClientFileContentsRequest) + return ERROR_INTERNAL_ERROR; fileContentsRequest.streamId = (UINT32) streamid; fileContentsRequest.listIndex = index; @@ -1041,27 +1265,32 @@ int cliprdr_send_request_filecontents(wfClipboard* clipboard, void* streamid, fileContentsRequest.cbRequested = nreq; fileContentsRequest.clipDataId = 0; - clipboard->context->ClientFileContentsRequest(clipboard->context, &fileContentsRequest); + rc = clipboard->context->ClientFileContentsRequest(clipboard->context, &fileContentsRequest); - WaitForSingleObject(clipboard->req_fevent, INFINITE); - ResetEvent(clipboard->req_fevent); + if (WaitForSingleObject(clipboard->req_fevent, INFINITE) != WAIT_OBJECT_0) + rc = ERROR_INTERNAL_ERROR; + else if (!ResetEvent(clipboard->req_fevent)) + rc = ERROR_INTERNAL_ERROR; - return 0; + return rc; } -int cliprdr_send_response_filecontents(wfClipboard* clipboard, UINT32 streamId, UINT32 size, BYTE* data) +static UINT cliprdr_send_response_filecontents(wfClipboard* clipboard, + UINT32 streamId, UINT32 size, + BYTE* data) { CLIPRDR_FILE_CONTENTS_RESPONSE fileContentsResponse; - ZeroMemory(&fileContentsResponse, sizeof(CLIPRDR_FILE_CONTENTS_RESPONSE)); + if (!clipboard || !clipboard->context || + !clipboard->context->ClientFileContentsResponse) + return ERROR_INTERNAL_ERROR; fileContentsResponse.streamId = streamId; fileContentsResponse.cbRequested = size; fileContentsResponse.requestedData = data; - - clipboard->context->ClientFileContentsResponse(clipboard->context, &fileContentsResponse); + fileContentsResponse.msgFlags = CB_RESPONSE_OK; - return 0; + return clipboard->context->ClientFileContentsResponse(clipboard->context, &fileContentsResponse); } static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) @@ -1070,100 +1299,100 @@ static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM switch (Msg) { - case WM_CREATE: - DEBUG_CLIPRDR("info: WM_CREATE"); - clipboard = (wfClipboard*)((CREATESTRUCT*) lParam)->lpCreateParams; - if (!AddClipboardFormatListener(hWnd)) { - DEBUG_CLIPRDR("error: AddClipboardFormatListener failed with %#x.", GetLastError()); - } - clipboard->hwnd = hWnd; - break; + case WM_CREATE: + DEBUG_CLIPRDR("info: WM_CREATE"); + clipboard = (wfClipboard*)((CREATESTRUCT*) lParam)->lpCreateParams; + if (!AddClipboardFormatListener(hWnd)) { + DEBUG_CLIPRDR("error: AddClipboardFormatListener failed with %#x.", GetLastError()); + } + clipboard->hwnd = hWnd; + break; - case WM_CLOSE: - DEBUG_CLIPRDR("info: WM_CLOSE"); - RemoveClipboardFormatListener(hWnd); - break; + case WM_CLOSE: + DEBUG_CLIPRDR("info: WM_CLOSE"); + RemoveClipboardFormatListener(hWnd); + break; - case WM_CLIPBOARDUPDATE: - DEBUG_CLIPRDR("info: WM_CLIPBOARDUPDATE"); - if (clipboard->sync) - { - if ((GetClipboardOwner() != clipboard->hwnd) && + case WM_CLIPBOARDUPDATE: + DEBUG_CLIPRDR("info: WM_CLIPBOARDUPDATE"); + if (clipboard->sync) + { + if ((GetClipboardOwner() != clipboard->hwnd) && (S_FALSE == OleIsCurrentClipboard(clipboard->data_obj))) - { - if (clipboard->hmem) - { - GlobalFree(clipboard->hmem); - clipboard->hmem = NULL; - } - - cliprdr_send_format_list(clipboard); - } - } - break; - - case WM_RENDERALLFORMATS: - DEBUG_CLIPRDR("info: WM_RENDERALLFORMATS"); - /* discard all contexts in clipboard */ - if (!OpenClipboard(clipboard->hwnd)) { - DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError()); - break; - } - EmptyClipboard(); - CloseClipboard(); - break; - - case WM_RENDERFORMAT: - DEBUG_CLIPRDR("info: WM_RENDERFORMAT"); - if (cliprdr_send_data_request(clipboard, (UINT32) wParam) != 0) - { - DEBUG_CLIPRDR("error: cliprdr_send_data_request failed."); - break; - } - - if (!SetClipboardData((UINT) wParam, clipboard->hmem)) - { - DEBUG_CLIPRDR("SetClipboardData failed with 0x%x", GetLastError()); - if (clipboard->hmem) { GlobalFree(clipboard->hmem); clipboard->hmem = NULL; } - } - /* Note: GlobalFree() is not needed when success */ - break; - case WM_CLIPRDR_MESSAGE: - DEBUG_CLIPRDR("info: WM_CLIPRDR_MESSAGE"); - switch (wParam) + cliprdr_send_format_list(clipboard); + } + } + break; + + case WM_RENDERALLFORMATS: + DEBUG_CLIPRDR("info: WM_RENDERALLFORMATS"); + /* discard all contexts in clipboard */ + if (!OpenClipboard(clipboard->hwnd)) + { + DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError()); + break; + } + EmptyClipboard(); + CloseClipboard(); + break; + + case WM_RENDERFORMAT: + DEBUG_CLIPRDR("info: WM_RENDERFORMAT"); + if (cliprdr_send_data_request(clipboard, (UINT32) wParam) != 0) + { + DEBUG_CLIPRDR("error: cliprdr_send_data_request failed."); + break; + } + + if (!SetClipboardData((UINT) wParam, clipboard->hmem)) + { + DEBUG_CLIPRDR("SetClipboardData failed with 0x%x", GetLastError()); + + if (clipboard->hmem) { - case OLE_SETCLIPBOARD: - DEBUG_CLIPRDR("info: OLE_SETCLIPBOARD"); - if (wf_create_file_obj(clipboard, &clipboard->data_obj)) - { - if (OleSetClipboard(clipboard->data_obj) != S_OK) - { - wf_destroy_file_obj(clipboard->data_obj); - clipboard->data_obj = NULL; - } - } - break; + GlobalFree(clipboard->hmem); + clipboard->hmem = NULL; + } + } + /* Note: GlobalFree() is not needed when success */ + break; - default: - break; + case WM_CLIPRDR_MESSAGE: + DEBUG_CLIPRDR("info: WM_CLIPRDR_MESSAGE"); + switch (wParam) + { + case OLE_SETCLIPBOARD: + DEBUG_CLIPRDR("info: OLE_SETCLIPBOARD"); + if (wf_create_file_obj(clipboard, &clipboard->data_obj)) + { + if (OleSetClipboard(clipboard->data_obj) != S_OK) + { + wf_destroy_file_obj(clipboard->data_obj); + clipboard->data_obj = NULL; + } } break; - case WM_DESTROYCLIPBOARD: - case WM_ASKCBFORMATNAME: - case WM_HSCROLLCLIPBOARD: - case WM_PAINTCLIPBOARD: - case WM_SIZECLIPBOARD: - case WM_VSCROLLCLIPBOARD: default: - return DefWindowProc(hWnd, Msg, wParam, lParam); + break; + } + break; + + case WM_DESTROYCLIPBOARD: + case WM_ASKCBFORMATNAME: + case WM_HSCROLLCLIPBOARD: + case WM_PAINTCLIPBOARD: + case WM_SIZECLIPBOARD: + case WM_VSCROLLCLIPBOARD: + default: + return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; @@ -1190,9 +1419,9 @@ static int create_cliprdr_window(wfClipboard* clipboard) RegisterClassEx(&wnd_cls); clipboard->hwnd = CreateWindowEx(WS_EX_LEFT, - _T("ClipboardHiddenMessageProcessor"), - _T("rdpclip"), - 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, GetModuleHandle(NULL), clipboard); + _T("ClipboardHiddenMessageProcessor"), + _T("rdpclip"), + 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, GetModuleHandle(NULL), clipboard); if (!clipboard->hwnd) { @@ -1239,7 +1468,10 @@ static void* cliprdr_thread_func(void* arg) static void clear_file_array(wfClipboard* clipboard) { - int i; + size_t i; + + if (!clipboard) + return; /* clear file_names array */ if (clipboard->file_names) @@ -1249,6 +1481,9 @@ static void clear_file_array(wfClipboard* clipboard) free(clipboard->file_names[i]); clipboard->file_names[i] = NULL; } + + free (clipboard->file_names); + clipboard->file_names = NULL; } /* clear fileDescriptor array */ @@ -1259,48 +1494,59 @@ static void clear_file_array(wfClipboard* clipboard) free(clipboard->fileDescriptor[i]); clipboard->fileDescriptor[i] = NULL; } + free (clipboard->fileDescriptor); + clipboard->fileDescriptor = NULL; } + clipboard->file_array_size = 0; clipboard->nFiles = 0; } static BOOL wf_cliprdr_get_file_contents(WCHAR* file_name, BYTE* buffer, - int positionLow, int positionHigh, int nRequested, unsigned int* puSize) + LONG positionLow, LONG positionHigh, + DWORD nRequested, DWORD* puSize) { + BOOL res = FALSE; HANDLE hFile; - DWORD nGet; + DWORD nGet, rc; if (!file_name || !buffer || !puSize) { WLog_ERR(TAG, "get file contents Invalid Arguments."); return FALSE; } - - hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - return FALSE; - } - SetFilePointer(hFile, positionLow, (PLONG) &positionHigh, FILE_BEGIN); + hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + rc = SetFilePointer(hFile, positionLow, &positionHigh, FILE_BEGIN); + if (rc == INVALID_SET_FILE_POINTER) + goto error; if (!ReadFile(hFile, buffer, nRequested, &nGet, NULL)) { DWORD err = GetLastError(); DEBUG_CLIPRDR("ReadFile failed with 0x%x.", err); + goto error; } - CloseHandle(hFile); + res = TRUE; - *puSize = nGet; +error: + if (!CloseHandle(hFile)) + res = FALSE; - return TRUE; + if (res) + *puSize = nGet; + + return res; } /* path_name has a '\' at the end. e.g. c:\newfolder\, file_name is c:\newfolder\new.txt */ -static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pathLen) +static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, size_t pathLen) { HANDLE hFile; FILEDESCRIPTORW* fd; @@ -1311,7 +1557,7 @@ static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pat return NULL; hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hFile == INVALID_HANDLE_VALUE) { @@ -1336,17 +1582,21 @@ static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pat return fd; } -static void wf_cliprdr_array_ensure_capacity(wfClipboard* clipboard) +static BOOL wf_cliprdr_array_ensure_capacity(wfClipboard* clipboard) { + if (!clipboard) + return FALSE; + if (clipboard->nFiles == clipboard->file_array_size) { - int new_size; + size_t new_size; FILEDESCRIPTORW **new_fd; WCHAR **new_name; - new_size = clipboard->file_array_size * 2; + new_size = (clipboard->file_array_size + 1) * 2; - new_fd = (FILEDESCRIPTORW**) realloc(clipboard->fileDescriptor, new_size * sizeof(FILEDESCRIPTORW*)); + new_fd = (FILEDESCRIPTORW**) realloc(clipboard->fileDescriptor, + new_size * sizeof(FILEDESCRIPTORW*)); if (new_fd) clipboard->fileDescriptor = new_fd; @@ -1355,32 +1605,51 @@ static void wf_cliprdr_array_ensure_capacity(wfClipboard* clipboard) clipboard->file_names = new_name; if (!new_fd || !new_name) - return; + return FALSE; - clipboard->file_array_size *= new_size; + clipboard->file_array_size = new_size; } + + return TRUE; } -static void wf_cliprdr_add_to_file_arrays(wfClipboard* clipboard, WCHAR* full_file_name, int pathLen) +static BOOL wf_cliprdr_add_to_file_arrays(wfClipboard* clipboard, + WCHAR* full_file_name, size_t pathLen) { + if (!wf_cliprdr_array_ensure_capacity(clipboard)) + return FALSE; + /* add to name array */ clipboard->file_names[clipboard->nFiles] = (LPWSTR) malloc(MAX_PATH * 2); + if (!clipboard->file_names[clipboard->nFiles]) + return FALSE; + wcscpy_s(clipboard->file_names[clipboard->nFiles], MAX_PATH, full_file_name); /* add to descriptor array */ - clipboard->fileDescriptor[clipboard->nFiles] = wf_cliprdr_get_file_descriptor(full_file_name, pathLen); + clipboard->fileDescriptor[clipboard->nFiles] = + wf_cliprdr_get_file_descriptor(full_file_name, pathLen); + if (!clipboard->fileDescriptor[clipboard->nFiles]) + { + free (clipboard->file_names[clipboard->nFiles]); + return FALSE; + } clipboard->nFiles++; - wf_cliprdr_array_ensure_capacity(clipboard); + return TRUE; } -static void wf_cliprdr_traverse_directory(wfClipboard* clipboard, WCHAR* Dir, int pathLen) +static BOOL wf_cliprdr_traverse_directory(wfClipboard* clipboard, + WCHAR* Dir, size_t pathLen) { HANDLE hFind; WCHAR DirSpec[MAX_PATH]; WIN32_FIND_DATA FindFileData; + if (!clipboard || !Dir) + return FALSE; + StringCchCopy(DirSpec, MAX_PATH, Dir); StringCchCat(DirSpec, MAX_PATH, TEXT("\\*")); @@ -1389,14 +1658,14 @@ static void wf_cliprdr_traverse_directory(wfClipboard* clipboard, WCHAR* Dir, in if (hFind == INVALID_HANDLE_VALUE) { DEBUG_CLIPRDR("FindFirstFile failed with 0x%x.", GetLastError()); - return; + return FALSE; } while (FindNextFile(hFind, &FindFileData)) { if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 - && wcscmp(FindFileData.cFileName, _T(".")) == 0 - || wcscmp(FindFileData.cFileName, _T("..")) == 0) + && wcscmp(FindFileData.cFileName, _T(".")) == 0 + || wcscmp(FindFileData.cFileName, _T("..")) == 0) { continue; } @@ -1408,8 +1677,10 @@ static void wf_cliprdr_traverse_directory(wfClipboard* clipboard, WCHAR* Dir, in StringCchCopy(DirAdd, MAX_PATH, Dir); StringCchCat(DirAdd, MAX_PATH, _T("\\")); StringCchCat(DirAdd, MAX_PATH, FindFileData.cFileName); - wf_cliprdr_add_to_file_arrays(clipboard, DirAdd, pathLen); - wf_cliprdr_traverse_directory(clipboard, DirAdd, pathLen); + if (!wf_cliprdr_add_to_file_arrays(clipboard, DirAdd, pathLen)) + return FALSE; + if (!wf_cliprdr_traverse_directory(clipboard, DirAdd, pathLen)) + return FALSE; } else { @@ -1419,18 +1690,25 @@ static void wf_cliprdr_traverse_directory(wfClipboard* clipboard, WCHAR* Dir, in StringCchCat(fileName, MAX_PATH, _T("\\")); StringCchCat(fileName, MAX_PATH, FindFileData.cFileName); - wf_cliprdr_add_to_file_arrays(clipboard, fileName, pathLen); + if (!wf_cliprdr_add_to_file_arrays(clipboard, fileName, pathLen)) + return FALSE; } } FindClose(hFind); + + return TRUE; } -int wf_cliprdr_send_client_capabilities(wfClipboard* clipboard) +static UINT wf_cliprdr_send_client_capabilities(wfClipboard* clipboard) { CLIPRDR_CAPABILITIES capabilities; CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet; + if (!clipboard || !clipboard->context || + !clipboard->context->ClientCapabilities) + return ERROR_INTERNAL_ERROR; + capabilities.cCapabilitiesSets = 1; capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &(generalCapabilitySet); @@ -1438,11 +1716,13 @@ int wf_cliprdr_send_client_capabilities(wfClipboard* clipboard) generalCapabilitySet.capabilitySetLength = 12; generalCapabilitySet.version = CB_CAPS_VERSION_2; - generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES; + generalCapabilitySet.generalFlags = + CB_USE_LONG_FORMAT_NAMES | + CB_STREAM_FILECLIP_ENABLED | + CB_FILECLIP_NO_FILE_PATHS | + CB_CAN_LOCK_CLIPDATA; - clipboard->context->ClientCapabilities(clipboard->context, &capabilities); - - return 1; + return clipboard->context->ClientCapabilities(clipboard->context, &capabilities); } /** @@ -1450,15 +1730,21 @@ int wf_cliprdr_send_client_capabilities(wfClipboard* clipboard) * * @return 0 on success, otherwise a Win32 error code */ -static UINT wf_cliprdr_monitor_ready(CliprdrClientContext* context, CLIPRDR_MONITOR_READY* monitorReady) +static UINT wf_cliprdr_monitor_ready(CliprdrClientContext* context, + CLIPRDR_MONITOR_READY* monitorReady) { + UINT rc; wfClipboard* clipboard = (wfClipboard*) context->custom; - clipboard->sync = TRUE; - wf_cliprdr_send_client_capabilities(clipboard); - cliprdr_send_format_list(clipboard); + if (!context || !monitorReady) + return ERROR_INTERNAL_ERROR; - return CHANNEL_RC_OK; + clipboard->sync = TRUE; + rc = wf_cliprdr_send_client_capabilities(clipboard); + if (rc != CHANNEL_RC_OK) + return rc; + + return cliprdr_send_format_list(clipboard); } /** @@ -1466,27 +1752,31 @@ static UINT wf_cliprdr_monitor_ready(CliprdrClientContext* context, CLIPRDR_MONI * * @return 0 on success, otherwise a Win32 error code */ -static UINT wf_cliprdr_server_capabilities(CliprdrClientContext* context, CLIPRDR_CAPABILITIES* capabilities) +static UINT wf_cliprdr_server_capabilities(CliprdrClientContext* context, + CLIPRDR_CAPABILITIES* capabilities) { UINT32 index; CLIPRDR_CAPABILITY_SET* capabilitySet; wfClipboard* clipboard = (wfClipboard*) context->custom; + if (!context || !capabilities) + return ERROR_INTERNAL_ERROR; + for (index = 0; index < capabilities->cCapabilitiesSets; index++) { capabilitySet = &(capabilities->capabilitySets[index]); if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) && - (capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN)) + (capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN)) { CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet - = (CLIPRDR_GENERAL_CAPABILITY_SET*) capabilitySet; + = (CLIPRDR_GENERAL_CAPABILITY_SET*) capabilitySet; clipboard->capabilities = generalCapabilitySet->generalFlags; break; } } - + return CHANNEL_RC_OK; } @@ -1495,26 +1785,36 @@ static UINT wf_cliprdr_server_capabilities(CliprdrClientContext* context, CLIPRD * * @return 0 on success, otherwise a Win32 error code */ -static UINT wf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST* formatList) +static UINT wf_cliprdr_server_format_list(CliprdrClientContext* context, + CLIPRDR_FORMAT_LIST* formatList) { - UINT32 i, j; + UINT rc = ERROR_INTERNAL_ERROR; + UINT32 i; formatMapping* mapping; CLIPRDR_FORMAT* format; wfClipboard* clipboard = (wfClipboard*) context->custom; - clear_format_map(clipboard); + if (!clear_format_map(clipboard)) + return ERROR_INTERNAL_ERROR; - for (i = j = 0; i < formatList->numFormats; i++) + for (i = 0; i < formatList->numFormats; i++) { format = &(formatList->formats[i]); - mapping = &(clipboard->format_mappings[j++]); + mapping = &(clipboard->format_mappings[i]); mapping->remote_format_id = format->formatId; if (format->formatName) { - mapping->name = _strdup(format->formatName); - mapping->local_format_id = RegisterClipboardFormatA((LPCSTR) mapping->name); + int size = MultiByteToWideChar(CP_UTF8, 0, format->formatName, strlen(format->formatName), + NULL, 0); + mapping->name = calloc(size + 1, sizeof(WCHAR)); + if (mapping->name) + { + MultiByteToWideChar(CP_UTF8, 0, format->formatName, strlen(format->formatName), + mapping->name, size); + mapping->local_format_id = RegisterClipboardFormatW((LPWSTR) mapping->name); + } } else { @@ -1528,7 +1828,8 @@ static UINT wf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR if (file_transferring(clipboard)) { - PostMessage(clipboard->hwnd, WM_CLIPRDR_MESSAGE, OLE_SETCLIPBOARD, 0); + if (PostMessage(clipboard->hwnd, WM_CLIPRDR_MESSAGE, OLE_SETCLIPBOARD, 0)) + rc = CHANNEL_RC_OK; } else { @@ -1538,14 +1839,28 @@ static UINT wf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR if (EmptyClipboard()) { for (i = 0; i < (UINT32) clipboard->map_size; i++) - { SetClipboardData(clipboard->format_mappings[i].local_format_id, NULL); - } + rc = CHANNEL_RC_OK; } - CloseClipboard(); + if (!CloseClipboard() && GetLastError()) + return ERROR_INTERNAL_ERROR; } + return rc; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT wf_cliprdr_server_format_list_response(CliprdrClientContext* context, + CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse) +{ + (void)context; + (void)formatListResponse; + return CHANNEL_RC_OK; } @@ -1554,9 +1869,12 @@ static UINT wf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR * * @return 0 on success, otherwise a Win32 error code */ -static UINT wf_cliprdr_server_format_list_response(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse) +static UINT wf_cliprdr_server_lock_clipboard_data(CliprdrClientContext* context, + CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) { - wfClipboard* clipboard = (wfClipboard*) context->custom; + (void)context; + (void)lockClipboardData; + return CHANNEL_RC_OK; } @@ -1565,51 +1883,86 @@ static UINT wf_cliprdr_server_format_list_response(CliprdrClientContext* context * * @return 0 on success, otherwise a Win32 error code */ -UINT wf_cliprdr_server_lock_clipboard_data(CliprdrClientContext* context, CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) +static UINT wf_cliprdr_server_unlock_clipboard_data(CliprdrClientContext* context, + CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) { - wfClipboard* clipboard = (wfClipboard*) context->custom; + (void)context; + (void)unlockClipboardData; + return CHANNEL_RC_OK; } +static BOOL wf_cliprdr_process_filename(wfClipboard* clipboard, + WCHAR* wFileName, size_t str_len) +{ + size_t pathLen; + size_t offset = str_len; + + if (!clipboard || !wFileName) + return FALSE; + + /* find the last '\' in full file name */ + while(offset > 0) + { + if (wFileName[offset] == L'\\') + break; + else + offset--; + } + + pathLen = offset + 1; + + if (!wf_cliprdr_add_to_file_arrays(clipboard, wFileName, pathLen)) + return FALSE; + + if ((clipboard->fileDescriptor[clipboard->nFiles - 1]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) + { + /* this is a directory */ + if (!wf_cliprdr_traverse_directory(clipboard, wFileName, pathLen)) + return FALSE; + } + + return TRUE; +} + /** * Function description * * @return 0 on success, otherwise a Win32 error code */ -UINT wf_cliprdr_server_unlock_clipboard_data(CliprdrClientContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) +static UINT wf_cliprdr_server_format_data_request(CliprdrClientContext* context, + CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) { - wfClipboard* clipboard = (wfClipboard*) context->custom; - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT wf_cliprdr_server_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) -{ - int size = 0; - char* buff = NULL; + UINT rc; + size_t size = 0; + void* buff = NULL; char* globlemem = NULL; HANDLE hClipdata = NULL; UINT32 requestedFormatId; CLIPRDR_FORMAT_DATA_RESPONSE response; - wfClipboard* clipboard = (wfClipboard*) context->custom; + wfClipboard* clipboard; + + if (!context || !formatDataRequest) + return ERROR_INTERNAL_ERROR; + + clipboard = (wfClipboard*) context->custom; + + if (!clipboard) + return ERROR_INTERNAL_ERROR; requestedFormatId = formatDataRequest->requestedFormatId; - if (requestedFormatId == RegisterClipboardFormatW(_T("FileGroupDescriptorW"))) + if (requestedFormatId == RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW)) { - int len; - int i; + size_t len; + size_t i; WCHAR* wFileName; - unsigned int uSize; HRESULT result; LPDATAOBJECT dataObj; FORMATETC format_etc; STGMEDIUM stg_medium; DROPFILES* dropFiles; + FILEGROUPDESCRIPTORW* groupDsc; result = OleGetClipboard(&dataObj); @@ -1619,126 +1972,77 @@ static UINT wf_cliprdr_server_format_data_request(CliprdrClientContext* context, ZeroMemory(&format_etc, sizeof(FORMATETC)); ZeroMemory(&stg_medium, sizeof(STGMEDIUM)); - /* try to get FileGroupDescriptorW struct from OLE */ - format_etc.cfFormat = requestedFormatId; + /* get DROPFILES struct from OLE */ + format_etc.cfFormat = CF_HDROP; format_etc.tymed = TYMED_HGLOBAL; format_etc.dwAspect = 1; format_etc.lindex = -1; - format_etc.ptd = 0; result = IDataObject_GetData(dataObj, &format_etc, &stg_medium); - if (SUCCEEDED(result)) + if (FAILED(result)) { + DEBUG_CLIPRDR("dataObj->GetData failed."); + goto exit; + } + + dropFiles = (DROPFILES*) GlobalLock(stg_medium.hGlobal); + + if (!dropFiles) { - DEBUG_CLIPRDR("Got FileGroupDescriptorW."); - globlemem = (char*) GlobalLock(stg_medium.hGlobal); - uSize = GlobalSize(stg_medium.hGlobal); - size = uSize; - buff = (char*) malloc(uSize); - CopyMemory(buff, globlemem, uSize); GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); + clipboard->nFiles = 0; - clear_file_array(clipboard); + goto exit; + } + + clear_file_array(clipboard); + + if (dropFiles->fWide) + { + /* dropFiles contains file names */ + for (wFileName = (WCHAR*)((char*)dropFiles + dropFiles->pFiles); + (len = wcslen(wFileName)) > 0; wFileName += len + 1) + { + wf_cliprdr_process_filename(clipboard, wFileName, wcslen(wFileName)); + } } else { - /* get DROPFILES struct from OLE */ - format_etc.cfFormat = CF_HDROP; - format_etc.tymed = TYMED_HGLOBAL; - format_etc.dwAspect = 1; - format_etc.lindex = -1; + char* p; - result = IDataObject_GetData(dataObj, &format_etc, &stg_medium); - - if (FAILED(result)) { - DEBUG_CLIPRDR("dataObj->GetData failed."); - } - - globlemem = (char*) GlobalLock(stg_medium.hGlobal); - - if (!globlemem) + for (p = (char*)((char*)dropFiles + dropFiles->pFiles); + (len = strlen(p)) > 0; p += len + 1, clipboard->nFiles++) { - GlobalUnlock(stg_medium.hGlobal); + int cchWideChar; + WCHAR *wFileName; - ReleaseStgMedium(&stg_medium); - clipboard->nFiles = 0; + cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0); + wFileName = (LPWSTR) calloc(cchWideChar, sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, wFileName, cchWideChar); - goto exit; - } - uSize = GlobalSize(stg_medium.hGlobal); - - dropFiles = (DROPFILES*) malloc(uSize); - memcpy(dropFiles, globlemem, uSize); - - GlobalUnlock(stg_medium.hGlobal); - - ReleaseStgMedium(&stg_medium); - - clear_file_array(clipboard); - - if (dropFiles->fWide) - { - WCHAR* p; - int str_len; - int offset; - int pathLen; - - /* dropFiles contains file names */ - for (wFileName = (WCHAR*)((char*)dropFiles + dropFiles->pFiles); (len = wcslen(wFileName)) > 0; wFileName += len + 1) - { - /* get path name */ - str_len = wcslen(wFileName); - offset = str_len; - /* find the last '\' in full file name */ - for (p = wFileName + offset; *p != L'\\'; p--) - { - ; - } - p += 1; - pathLen = wcslen(wFileName) - wcslen(p); - - wf_cliprdr_add_to_file_arrays(clipboard, wFileName, pathLen); - - if ((clipboard->fileDescriptor[clipboard->nFiles - 1]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) - { - /* this is a directory */ - wf_cliprdr_traverse_directory(clipboard, wFileName, pathLen); - } - } - } - else - { - char* p; - - for (p = (char*)((char*)dropFiles + dropFiles->pFiles); (len = strlen(p)) > 0; p += len + 1, clipboard->nFiles++) - { - int cchWideChar; - - cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0); - clipboard->file_names[clipboard->nFiles] = (LPWSTR) malloc(cchWideChar * 2); - MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, clipboard->file_names[clipboard->nFiles], cchWideChar); - - map_ensure_capacity(clipboard); - } - } - -exit: - size = 4 + clipboard->nFiles * sizeof(FILEDESCRIPTORW); - buff = (char*) malloc(size); - - *((UINT32*) buff) = clipboard->nFiles; - - for (i = 0; i < clipboard->nFiles; i++) - { - if (clipboard->fileDescriptor[i]) - { - memcpy(buff + 4 + i * sizeof(FILEDESCRIPTORW), clipboard->fileDescriptor[i], sizeof(FILEDESCRIPTORW)); - } + wf_cliprdr_process_filename(clipboard, wFileName, cchWideChar); } } + GlobalUnlock(stg_medium.hGlobal); + + ReleaseStgMedium(&stg_medium); + +exit: + size = 4 + clipboard->nFiles * sizeof(FILEDESCRIPTORW); + groupDsc = (FILEGROUPDESCRIPTORW*) malloc(size); + if (groupDsc) + { + groupDsc->cItems = clipboard->nFiles; + for (i = 0; i < clipboard->nFiles; i++) + { + if (clipboard->fileDescriptor[i]) + groupDsc->fgd[i] = *clipboard->fileDescriptor[i]; + } + buff = groupDsc; + } IDataObject_Release(dataObj); } else @@ -1757,7 +2061,7 @@ exit: globlemem = (char*) GlobalLock(hClipdata); size = (int) GlobalSize(hClipdata); - buff = (char*) malloc(size); + buff = malloc(size); CopyMemory(buff, globlemem, size); GlobalUnlock(hClipdata); @@ -1771,11 +2075,11 @@ exit: response.dataLen = size; response.requestedFormatData = (BYTE*) buff; - clipboard->context->ClientFormatDataResponse(clipboard->context, &response); + rc = clipboard->context->ClientFormatDataResponse(clipboard->context, &response); free(buff); - return CHANNEL_RC_OK; + return rc; } /** @@ -1783,19 +2087,42 @@ exit: * * @return 0 on success, otherwise a Win32 error code */ -static UINT wf_cliprdr_server_format_data_response(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) +static UINT wf_cliprdr_server_format_data_response(CliprdrClientContext* context, + CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) { BYTE* data; HANDLE hMem; - wfClipboard* clipboard = (wfClipboard*) context->custom; + wfClipboard* clipboard; + + if (!context || !formatDataResponse) + return ERROR_INTERNAL_ERROR; + + clipboard = (wfClipboard*) context->custom; + + if (!clipboard) + return ERROR_INTERNAL_ERROR; + + hMem = GlobalAlloc(GMEM_MOVEABLE, formatDataResponse->dataLen); + if (!hMem) + return ERROR_INTERNAL_ERROR; - hMem = GlobalAlloc(GMEM_FIXED, formatDataResponse->dataLen); data = (BYTE*) GlobalLock(hMem); + if (!data) + { + GlobalFree(hMem); + return ERROR_INTERNAL_ERROR; + } + CopyMemory(data, formatDataResponse->requestedFormatData, formatDataResponse->dataLen); - GlobalUnlock(hMem); + if (!GlobalUnlock(hMem) && GetLastError()) + { + GlobalFree(hMem); + return ERROR_INTERNAL_ERROR; + } clipboard->hmem = hMem; - SetEvent(clipboard->response_data_event); + if (!SetEvent(clipboard->response_data_event)) + return ERROR_INTERNAL_ERROR; return CHANNEL_RC_OK; } @@ -1805,25 +2132,35 @@ static UINT wf_cliprdr_server_format_data_response(CliprdrClientContext* context * * @return 0 on success, otherwise a Win32 error code */ -UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest) +static UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, + CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest) { - UINT32 uSize = 0; + DWORD uSize = 0; BYTE* pData = NULL; HRESULT hRet = S_OK; FORMATETC vFormatEtc; LPDATAOBJECT pDataObj = NULL; STGMEDIUM vStgMedium; - LPSTREAM pStream = NULL; BOOL bIsStreamFile = TRUE; static LPSTREAM pStreamStc = NULL; static UINT32 uStreamIdStc = 0; - wfClipboard* clipboard = (wfClipboard*) context->custom; + wfClipboard* clipboard; + UINT rc = ERROR_INTERNAL_ERROR; + UINT sRc; + + if (!context || !fileContentsRequest) + return ERROR_INTERNAL_ERROR; + + clipboard = (wfClipboard*) context->custom; + + if (!clipboard) + return ERROR_INTERNAL_ERROR; if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE) fileContentsRequest->cbRequested = sizeof(UINT64); pData = (BYTE*) calloc(1, fileContentsRequest->cbRequested); - + if (!pData) goto error; @@ -1834,11 +2171,11 @@ UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIP WLog_ERR(TAG, "filecontents: get ole clipboard failed."); goto error; } - + ZeroMemory(&vFormatEtc, sizeof(FORMATETC)); ZeroMemory(&vStgMedium, sizeof(STGMEDIUM)); - vFormatEtc.cfFormat = clipboard->ID_FILECONTENTS; + vFormatEtc.cfFormat = RegisterClipboardFormat(CFSTR_FILECONTENTS); vFormatEtc.tymed = TYMED_ISTREAM; vFormatEtc.dwAspect = 1; vFormatEtc.lindex = fileContentsRequest->listIndex; @@ -1869,7 +2206,7 @@ UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIP if (hRet == S_OK) { - if (vFormatEtc2.cfFormat == clipboard->ID_FILECONTENTS) + if (vFormatEtc2.cfFormat == RegisterClipboardFormat(CFSTR_FILECONTENTS)) { hRet = IDataObject_GetData(pDataObj, &vFormatEtc, &vStgMedium); @@ -1915,10 +2252,7 @@ UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIP hRet = IStream_Seek(pStreamStc, dlibMove, STREAM_SEEK_SET, &dlibNewPosition); if (SUCCEEDED(hRet)) - { hRet = IStream_Read(pStreamStc, pData, fileContentsRequest->cbRequested, (PULONG) &uSize); - } - } } else @@ -1934,8 +2268,8 @@ UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIP BOOL bRet; bRet = wf_cliprdr_get_file_contents(clipboard->file_names[fileContentsRequest->listIndex], pData, - fileContentsRequest->nPositionLow, fileContentsRequest->nPositionHigh, - fileContentsRequest->cbRequested, &uSize); + fileContentsRequest->nPositionLow, fileContentsRequest->nPositionHigh, + fileContentsRequest->cbRequested, &uSize); if (bRet == FALSE) { @@ -1946,7 +2280,11 @@ UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIP } } - IDataObject_Release(pDataObj); + rc = CHANNEL_RC_OK; + +error: + if (pDataObj) + IDataObject_Release(pDataObj); if (uSize == 0) { @@ -1954,29 +2292,15 @@ UINT wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIP pData = NULL; } - cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, uSize, pData); + sRc = cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, + uSize, pData); free(pData); - return CHANNEL_RC_OK; + if (sRc != CHANNEL_RC_OK) + return sRc; -error: - if (pData) - { - free(pData); - pData = NULL; - } - - if (pDataObj) - { - IDataObject_Release(pDataObj); - pDataObj = NULL; - } - - WLog_ERR(TAG, "filecontents: send failed response."); - cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, 0, NULL); - - return ERROR_INTERNAL_ERROR; + return rc; } /** @@ -1984,33 +2308,52 @@ error: * * @return 0 on success, otherwise a Win32 error code */ -UINT wf_cliprdr_server_file_contents_response(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse) +static UINT wf_cliprdr_server_file_contents_response(CliprdrClientContext* context, + const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse) { - wfClipboard* clipboard = (wfClipboard*) context->custom; + wfClipboard* clipboard; + + if (!context || !fileContentsResponse) + return ERROR_INTERNAL_ERROR; + + clipboard = (wfClipboard*) context->custom; + + if (!clipboard) + return ERROR_INTERNAL_ERROR; clipboard->req_fsize = fileContentsResponse->cbRequested; clipboard->req_fdata = (char*) malloc(fileContentsResponse->cbRequested); + if (!clipboard->req_fdata) + return ERROR_INTERNAL_ERROR; + CopyMemory(clipboard->req_fdata, fileContentsResponse->requestedData, fileContentsResponse->cbRequested); - SetEvent(clipboard->req_fevent); + if (!SetEvent(clipboard->req_fevent)) + { + free (clipboard->req_fdata); + return ERROR_INTERNAL_ERROR; + } return CHANNEL_RC_OK; } -void wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr) +BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr) { wfClipboard* clipboard; rdpContext* context = (rdpContext*) wfc; + if (!context || !cliprdr) + return FALSE; + wfc->clipboard = (wfClipboard*) calloc(1, sizeof(wfClipboard)); if (!wfc->clipboard) - return; + return FALSE; clipboard = wfc->clipboard; clipboard->wfc = wfc; clipboard->context = cliprdr; - + clipboard->channels = context->channels; clipboard->sync = FALSE; @@ -2018,27 +2361,16 @@ void wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr) clipboard->map_size = 0; if (!(clipboard->format_mappings = (formatMapping*) calloc(1, sizeof(formatMapping) * clipboard->map_capacity))) - goto fail_format_mappings; - - clipboard->file_array_size = 32; - if (!(clipboard->file_names = (WCHAR**) calloc(1, clipboard->file_array_size * sizeof(WCHAR*)))) - goto fail_file_names; - - if (!(clipboard->fileDescriptor = (FILEDESCRIPTORW**) calloc(1, clipboard->file_array_size * sizeof(FILEDESCRIPTORW*)))) - goto fail_file_descriptor; + goto error; if (!(clipboard->response_data_event = CreateEvent(NULL, TRUE, FALSE, _T("response_data_event")))) - goto fail_data_event; + goto error; if (!(clipboard->req_fevent = CreateEvent(NULL, TRUE, FALSE, _T("request_filecontents_event")))) - goto fail_filecontents_event; - - clipboard->ID_FILEDESCRIPTORW = RegisterClipboardFormatW(CFSTR_FILEDESCRIPTORW); - clipboard->ID_FILECONTENTS = RegisterClipboardFormatW(CFSTR_FILECONTENTS); - clipboard->ID_PREFERREDDROPEFFECT = RegisterClipboardFormatW(CFSTR_PREFERREDDROPEFFECT); + goto error; if (!(clipboard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) cliprdr_thread_func, clipboard, 0, NULL))) - goto fail_clipboard_thread; + goto error; cliprdr->MonitorReady = wf_cliprdr_monitor_ready; cliprdr->ServerCapabilities = wf_cliprdr_server_capabilities; @@ -2052,38 +2384,29 @@ void wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr) cliprdr->ServerFileContentsResponse = wf_cliprdr_server_file_contents_response; cliprdr->custom = (void*) wfc->clipboard; - return; + return TRUE; -fail_clipboard_thread: - CloseHandle(clipboard->req_fevent); - clipboard->req_fevent = NULL; -fail_filecontents_event: - CloseHandle(clipboard->response_data_event); - clipboard->response_data_event = NULL; -fail_data_event: - free(clipboard->fileDescriptor); - clipboard->fileDescriptor = NULL; -fail_file_descriptor: - free(clipboard->file_names); - clipboard->file_names = NULL; -fail_file_names: - free(clipboard->format_mappings); - clipboard->format_mappings = NULL; -fail_format_mappings: - free(wfc->clipboard); - wfc->clipboard = NULL; - - return; +error: + wf_cliprdr_uninit(wfc, cliprdr); + return FALSE; } -void wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr) +BOOL wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr) { - wfClipboard* clipboard = wfc->clipboard; + wfClipboard* clipboard; + + if (!wfc || !cliprdr) + return FALSE; + + clipboard = wfc->clipboard; + + if (!clipboard) + return FALSE; cliprdr->custom = NULL; if (!clipboard) - return; + return FALSE; if (clipboard->hwnd) PostMessage(clipboard->hwnd, WM_QUIT, 0, 0); @@ -2104,9 +2427,9 @@ void wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr) clear_file_array(clipboard); clear_format_map(clipboard); - free(clipboard->file_names); - free(clipboard->fileDescriptor); free(clipboard->format_mappings); free(clipboard); + + return TRUE; } diff --git a/client/Windows/wf_cliprdr.h b/client/Windows/wf_cliprdr.h index 4c1944e8f..69cd052b9 100644 --- a/client/Windows/wf_cliprdr.h +++ b/client/Windows/wf_cliprdr.h @@ -19,121 +19,9 @@ #ifndef __WF_CLIPRDR_H #define __WF_CLIPRDR_H -#define CINTERFACE -#define COBJMACROS - -#include -#include - -typedef struct wf_clipboard wfClipboard; - #include "wf_client.h" -#include - -#ifdef WITH_DEBUG_CLIPRDR -#define DEBUG_CLIPRDR(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__) -#else -#define DEBUG_CLIPRDR(fmt, ...) do { } while (0) -#endif - -struct _CliprdrStream -{ - IStream iStream; - - LONG m_lRefCount; - LONG m_lIndex; - ULARGE_INTEGER m_lSize; - ULARGE_INTEGER m_lOffset; - void* m_pData; -}; -typedef struct _CliprdrStream CliprdrStream; - -CliprdrStream* CliprdrStream_New(LONG index, void* pData); -void CliprdrStream_Delete(CliprdrStream* instance); - -struct _CliprdrDataObject -{ - IDataObject iDataObject; - - LONG m_lRefCount; - FORMATETC* m_pFormatEtc; - STGMEDIUM* m_pStgMedium; - LONG m_nNumFormats; - LONG m_nStreams; - IStream** m_pStream; - void* m_pData; -}; -typedef struct _CliprdrDataObject CliprdrDataObject; - -CliprdrDataObject* CliprdrDataObject_New(FORMATETC* fmtetc, STGMEDIUM* stgmed, int count, void* data); -void CliprdrDataObject_Delete(CliprdrDataObject* instance); - -struct _CliprdrEnumFORMATETC -{ - IEnumFORMATETC iEnumFORMATETC; - - LONG m_lRefCount; - LONG m_nIndex; - LONG m_nNumFormats; - FORMATETC* m_pFormatEtc; -}; -typedef struct _CliprdrEnumFORMATETC CliprdrEnumFORMATETC; - -CliprdrEnumFORMATETC* CliprdrEnumFORMATETC_New(int nFormats, FORMATETC* pFormatEtc); -void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* This); - -struct format_mapping -{ - UINT32 remote_format_id; - UINT32 local_format_id; - void* name; /* Unicode or ASCII characters with NULL terminator */ -}; -typedef struct format_mapping formatMapping; - -struct wf_clipboard -{ - wfContext* wfc; - rdpChannels* channels; - CliprdrClientContext* context; - - BOOL sync; - UINT32 capabilities; - - int map_size; - int map_capacity; - formatMapping* format_mappings; - - UINT32 requestedFormatId; - - HWND hwnd; - HANDLE hmem; - HANDLE thread; - HANDLE response_data_event; - - /* file clipping */ - CLIPFORMAT ID_FILEDESCRIPTORW; - CLIPFORMAT ID_FILECONTENTS; - CLIPFORMAT ID_PREFERREDDROPEFFECT; - - LPDATAOBJECT data_obj; - ULONG req_fsize; - char* req_fdata; - HANDLE req_fevent; - - int nFiles; - int file_array_size; - WCHAR** file_names; - FILEDESCRIPTORW** fileDescriptor; -}; - -void wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr); -void wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr); - -int cliprdr_send_data_request(wfClipboard* clipboard, UINT32 format); -int cliprdr_send_lock(wfClipboard* clipboard); -int cliprdr_send_unlock(wfClipboard* clipboard); -int cliprdr_send_request_filecontents(wfClipboard* clipboard, void* streamid, - int index, int flag, DWORD positionhigh, DWORD positionlow, ULONG request); +BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr); +BOOL wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr); #endif /* __WF_CLIPRDR_H */ From d5385471a51eb8315d0cbda72e74a4522152877d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 22 Oct 2015 10:01:12 +0200 Subject: [PATCH 047/220] Disabled file locking, added response checks. --- client/Windows/wf_cliprdr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 85aa28113..638c8d930 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -1230,9 +1230,6 @@ static UINT cliprdr_send_data_request(wfClipboard* clipboard, UINT32 formatId) !clipboard->context->ClientFormatDataRequest) return ERROR_INTERNAL_ERROR; - formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST; - formatDataRequest.msgFlags = CB_RESPONSE_OK; - formatDataRequest.requestedFormatId = formatId; clipboard->requestedFormatId = formatId; @@ -1264,6 +1261,7 @@ static UINT cliprdr_send_request_filecontents(wfClipboard* clipboard, const void fileContentsRequest.nPositionHigh = positionhigh; fileContentsRequest.cbRequested = nreq; fileContentsRequest.clipDataId = 0; + fileContentsRequest.msgFlags = 0; rc = clipboard->context->ClientFileContentsRequest(clipboard->context, &fileContentsRequest); @@ -1719,8 +1717,7 @@ static UINT wf_cliprdr_send_client_capabilities(wfClipboard* clipboard) generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES | CB_STREAM_FILECLIP_ENABLED | - CB_FILECLIP_NO_FILE_PATHS | - CB_CAN_LOCK_CLIPDATA; + CB_FILECLIP_NO_FILE_PATHS; return clipboard->context->ClientCapabilities(clipboard->context, &capabilities); } @@ -1861,6 +1858,9 @@ static UINT wf_cliprdr_server_format_list_response(CliprdrClientContext* context (void)context; (void)formatListResponse; + if (formatListResponse->msgFlags != CB_RESPONSE_OK) + return E_FAIL; + return CHANNEL_RC_OK; } @@ -2069,8 +2069,6 @@ exit: CloseClipboard(); } - ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE)); - response.msgFlags = CB_RESPONSE_OK; response.dataLen = size; response.requestedFormatData = (BYTE*) buff; @@ -2094,6 +2092,9 @@ static UINT wf_cliprdr_server_format_data_response(CliprdrClientContext* context HANDLE hMem; wfClipboard* clipboard; + if (formatDataResponse->msgFlags != CB_RESPONSE_OK) + return E_FAIL; + if (!context || !formatDataResponse) return ERROR_INTERNAL_ERROR; @@ -2313,6 +2314,9 @@ static UINT wf_cliprdr_server_file_contents_response(CliprdrClientContext* conte { wfClipboard* clipboard; + if (fileContentsResponse->msgFlags != CB_RESPONSE_OK) + return E_FAIL; + if (!context || !fileContentsResponse) return ERROR_INTERNAL_ERROR; From 5de53096ed6537b20380ff3d032adc6534cba10c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 23 Oct 2015 11:31:54 +0200 Subject: [PATCH 048/220] Fixed directory copy from remote to local. --- client/Windows/wf_cliprdr.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 638c8d930..2a3e09037 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -80,6 +80,7 @@ struct _CliprdrStream LONG m_lIndex; ULARGE_INTEGER m_lSize; ULARGE_INTEGER m_lOffset; + FILEDESCRIPTORW m_Dsc; void* m_pData; }; typedef struct _CliprdrStream CliprdrStream; @@ -392,10 +393,11 @@ static HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream* This, IStream** pp return E_NOTIMPL; } -static CliprdrStream* CliprdrStream_New(LONG index, void* pData) +static CliprdrStream* CliprdrStream_New(LONG index, void* pData, const FILEDESCRIPTORW *dsc) { IStream* iStream; BOOL success = FALSE; + BOOL isDir = FALSE; CliprdrStream* instance; wfClipboard* clipboard = (wfClipboard*) pData; @@ -403,6 +405,8 @@ static CliprdrStream* CliprdrStream_New(LONG index, void* pData) if (instance) { + instance->m_Dsc = *dsc; + iStream = &instance->iStream; iStream->lpVtbl = (IStreamVtbl*) calloc(1, sizeof(IStreamVtbl)); @@ -429,16 +433,26 @@ static CliprdrStream* CliprdrStream_New(LONG index, void* pData) instance->m_pData = pData; instance->m_lOffset.QuadPart = 0; - /* get content size of this stream */ - if (cliprdr_send_request_filecontents(clipboard, (void*) instance, - instance->m_lIndex, - FILECONTENTS_SIZE, 0, 0, 8) == CHANNEL_RC_OK) + if (instance->m_Dsc.dwFlags & FD_ATTRIBUTES) { - success = TRUE; + if (instance->m_Dsc.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + isDir = TRUE; } - instance->m_lSize.QuadPart = *((LONGLONG*) clipboard->req_fdata); - free(clipboard->req_fdata); + if (((instance->m_Dsc.dwFlags & FD_FILESIZE) == 0) && !isDir) { + /* get content size of this stream */ + if (cliprdr_send_request_filecontents(clipboard, (void*) instance, + instance->m_lIndex, + FILECONTENTS_SIZE, 0, 0, 8) == CHANNEL_RC_OK) + { + success = TRUE; + } + + instance->m_lSize.QuadPart = *((LONGLONG*) clipboard->req_fdata); + free(clipboard->req_fdata); + } + else + success = TRUE; } } @@ -579,7 +593,11 @@ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData( if (instance->m_pStream) { for (i = 0; i < instance->m_nStreams; i++) - instance->m_pStream[i] = (IStream*) CliprdrStream_New(i, clipboard); + { + instance->m_pStream[i] = (IStream*) CliprdrStream_New(i, clipboard, &dsc->fgd[i]); + if (!instance->m_pStream[i]) + return E_OUTOFMEMORY; + } } } } From 57c90eacc645c2da5a2a24d01c623ac772783915 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 23 Oct 2015 12:07:36 +0200 Subject: [PATCH 049/220] Fixed clipboard format for directory copy. --- client/Windows/wf_cliprdr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 2a3e09037..07db8a945 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -1209,8 +1209,16 @@ static UINT cliprdr_send_format_list(wfClipboard* clipboard) index = 0; - while (formatId = EnumClipboardFormats(formatId)) - formats[index++].formatId = formatId;; + if (IsClipboardFormatAvailable(CF_HDROP)) + { + formats[index++].formatId = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW); + formats[index++].formatId = RegisterClipboardFormat(CFSTR_FILECONTENTS); + } + else + { + while (formatId = EnumClipboardFormats(formatId)) + formats[index++].formatId = formatId; + } numFormats = index; From b4dbe23d91687a08a7588ba236c43db0126517d3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 27 Oct 2015 09:57:15 +0100 Subject: [PATCH 050/220] Fixed mixed declaration. --- client/Windows/wf_cliprdr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 07db8a945..f8f90a3a8 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -571,6 +571,7 @@ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData( if (instance->m_pFormatEtc[idx].cfFormat == RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW)) { + FILEGROUPDESCRIPTOR *dsc; DWORD remote = get_remote_format_id(clipboard, instance->m_pFormatEtc[idx].cfFormat); if (cliprdr_send_data_request(clipboard, remote) != 0) return E_UNEXPECTED; @@ -580,7 +581,7 @@ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData( /* GlobalLock returns a pointer to the first byte of the memory block, * in which is a FILEGROUPDESCRIPTOR structure, whose first UINT member * is the number of FILEDESCRIPTOR's */ - FILEGROUPDESCRIPTOR *dsc = (FILEGROUPDESCRIPTOR*) GlobalLock(clipboard->hmem); + dsc = (FILEGROUPDESCRIPTOR*) GlobalLock(clipboard->hmem); instance->m_nStreams = dsc->cItems; GlobalUnlock(clipboard->hmem); From 730f43a38019c8ef0ca0ce1d6d2f3c2b38849e68 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Tue, 27 Oct 2015 17:12:33 +0100 Subject: [PATCH 051/220] cliprdr/server: Provide the server with a possibility to configure capabilities --- channels/cliprdr/server/cliprdr_main.c | 37 ++++++++++++++------------ channels/cliprdr/server/cliprdr_main.h | 5 ---- include/freerdp/server/cliprdr.h | 6 +++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index e672fd601..96d0dc79d 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -193,7 +193,7 @@ static UINT cliprdr_server_format_list(CliprdrServerContext* context, CLIPRDR_FO CLIPRDR_FORMAT* format; CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; - if (!cliprdr->useLongFormatNames) + if (!context->useLongFormatNames) { length = formatList->numFormats * 36; @@ -504,22 +504,21 @@ static UINT cliprdr_server_receive_general_capability(CliprdrServerContext* cont { UINT32 version; UINT32 generalFlags; - CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; Stream_Read_UINT32(s, version); /* version (4 bytes) */ Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */ - if (generalFlags & CB_USE_LONG_FORMAT_NAMES) - cliprdr->useLongFormatNames = TRUE; + if (context->useLongFormatNames) + context->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE; - if (generalFlags & CB_STREAM_FILECLIP_ENABLED) - cliprdr->streamFileClipEnabled = TRUE; + if (context->streamFileClipEnabled) + context->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE; - if (generalFlags & CB_FILECLIP_NO_FILE_PATHS) - cliprdr->fileClipNoFilePaths = TRUE; + if (context->fileClipNoFilePaths) + context->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE; - if (generalFlags & CB_CAN_LOCK_CLIPDATA) - cliprdr->canLockClipData = TRUE; + if (context->canLockClipData) + context->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE; return CHANNEL_RC_OK; } @@ -654,7 +653,7 @@ static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context, wS formatList.formats = NULL; formatList.numFormats = 0; } - else if (!cliprdr->useLongFormatNames) + else if (!context->useLongFormatNames) { formatList.numFormats = (dataLen / 36); @@ -1103,9 +1102,18 @@ static UINT cliprdr_server_init(CliprdrServerContext* context) generalFlags = 0; - if (cliprdr->useLongFormatNames) + if (context->useLongFormatNames) generalFlags |= CB_USE_LONG_FORMAT_NAMES; + if (context->streamFileClipEnabled) + generalFlags |= CB_STREAM_FILECLIP_ENABLED; + + if (context->fileClipNoFilePaths) + generalFlags |= CB_FILECLIP_NO_FILE_PATHS; + + if (context->canLockClipData) + generalFlags |= CB_CAN_LOCK_CLIPDATA; + capabilities.msgType = CB_CLIP_CAPS; capabilities.msgFlags = 0; capabilities.dataLen = 4 + CB_CAPSTYPE_GENERAL_LEN; @@ -1527,11 +1535,6 @@ CliprdrServerContext* cliprdr_server_context_new(HANDLE vcm) { cliprdr->vcm = vcm; - cliprdr->useLongFormatNames = TRUE; - cliprdr->streamFileClipEnabled = TRUE; - cliprdr->fileClipNoFilePaths = TRUE; - cliprdr->canLockClipData = TRUE; - cliprdr->s = Stream_New(NULL, 4096); if(!cliprdr->s) diff --git a/channels/cliprdr/server/cliprdr_main.h b/channels/cliprdr/server/cliprdr_main.h index 0c51e5c99..362d85a83 100644 --- a/channels/cliprdr/server/cliprdr_main.h +++ b/channels/cliprdr/server/cliprdr_main.h @@ -40,11 +40,6 @@ struct _cliprdr_server_private void* ChannelHandle; HANDLE ChannelEvent; - BOOL useLongFormatNames; - BOOL streamFileClipEnabled; - BOOL fileClipNoFilePaths; - BOOL canLockClipData; - wStream* s; char* temporaryDirectory; }; diff --git a/include/freerdp/server/cliprdr.h b/include/freerdp/server/cliprdr.h index e111c1533..d2e7efcb3 100644 --- a/include/freerdp/server/cliprdr.h +++ b/include/freerdp/server/cliprdr.h @@ -68,6 +68,12 @@ struct _cliprdr_server_context void* handle; void* custom; + /* clipboard capabilities - set by server */ + BOOL useLongFormatNames; + BOOL streamFileClipEnabled; + BOOL fileClipNoFilePaths; + BOOL canLockClipData; + psCliprdrOpen Open; psCliprdrClose Close; psCliprdrStart Start; From 382993d4d550c76a8dfb147c7758315205c9555e Mon Sep 17 00:00:00 2001 From: David FORT Date: Tue, 27 Oct 2015 21:45:26 +0100 Subject: [PATCH 052/220] Include config.h file when needed --- winpr/include/winpr/wlog.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index f60e706a0..6d88d3c6f 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -27,6 +27,10 @@ extern "C" { #include #include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + #include #include From ab6485b3bf06148b782c5c23e673eb72bc575289 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Wed, 28 Oct 2015 12:28:14 +0100 Subject: [PATCH 053/220] cliprdr/server: Add comment --- include/freerdp/server/cliprdr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/freerdp/server/cliprdr.h b/include/freerdp/server/cliprdr.h index d2e7efcb3..221d837b3 100644 --- a/include/freerdp/server/cliprdr.h +++ b/include/freerdp/server/cliprdr.h @@ -68,7 +68,7 @@ struct _cliprdr_server_context void* handle; void* custom; - /* clipboard capabilities - set by server */ + /* server clipboard capabilities - set by server - updated by the channel after client capability exchange */ BOOL useLongFormatNames; BOOL streamFileClipEnabled; BOOL fileClipNoFilePaths; From 0cf2a0e50b74910a2948046f9e097d487b814f04 Mon Sep 17 00:00:00 2001 From: David FORT Date: Thu, 29 Oct 2015 10:32:58 +0100 Subject: [PATCH 054/220] Don't include config.h in public headers In fact we don't need the ifdefery in public headers, so don't include unneeded config.h file. --- winpr/include/winpr/wlog.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 6d88d3c6f..488e893b6 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -27,10 +27,6 @@ extern "C" { #include #include -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - #include #include @@ -202,13 +198,11 @@ struct _wLogCallbackAppender }; typedef struct _wLogCallbackAppender wLogCallbackAppender; -#ifdef HAVE_SYSLOG_H struct _wLogSyslogAppender { WLOG_APPENDER_COMMON(); }; typedef struct _wLogSyslogAppender wLogSyslogAppender; -#endif /** * Filter From 25b1e394608db0816b056733f11059b18f61f113 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Thu, 29 Oct 2015 12:45:12 +0100 Subject: [PATCH 055/220] cliprdr/server: Server-side file content receiving used wrong callback --- channels/cliprdr/server/cliprdr_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 96d0dc79d..b082c830e 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -1004,9 +1004,9 @@ static UINT cliprdr_server_receive_filecontents_response(CliprdrServerContext* c response.cbRequested = header->dataLen - 4; response.requestedData = Stream_Pointer(s); /* requestedFileContentsData */ - IFCALLRET(context->ServerFileContentsResponse, error, context, &response); + IFCALLRET(context->ClientFileContentsResponse, error, context, &response); if (error) - WLog_ERR(TAG, "ServerFileContentsResponse failed with error %lu!", error); + WLog_ERR(TAG, "ClientFileContentsResponse failed with error %lu!", error); return error; } From c2a322f4d09de3b57e504b80a3811d1172f6298d Mon Sep 17 00:00:00 2001 From: David FORT Date: Thu, 29 Oct 2015 18:31:22 +0100 Subject: [PATCH 056/220] Support syslog type for the WLOG_APPENDER env var --- winpr/libwinpr/utils/wlog/wlog.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index e9b5cf41a..8564f1d93 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -694,6 +694,10 @@ wLog* WLog_GetRoot() logAppenderType = WLOG_APPENDER_FILE; else if (_stricmp(env, "BINARY") == 0) logAppenderType = WLOG_APPENDER_BINARY; +#ifdef HAVE_SYSLOG_H + else if (_stricmp(env, "SYSLOG") == 0) + logAppenderType = WLOG_APPENDER_SYSLOG; +#endif /* HAVE_SYSLOG_H */ free(env); } From 8d2aadfccdb825f4985e603d6f7cbc825fddb3af Mon Sep 17 00:00:00 2001 From: David FORT Date: Thu, 29 Oct 2015 18:33:42 +0100 Subject: [PATCH 057/220] Fixed a warning --- winpr/libwinpr/utils/wlog/wlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 8564f1d93..625510698 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -227,7 +227,7 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message) BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args) { - BOOL status; + BOOL status = FALSE; if (message->Type == WLOG_MESSAGE_TEXT) { From 9ea301983d145e6afbf835a9104ffa9f86974a68 Mon Sep 17 00:00:00 2001 From: David FORT Date: Fri, 30 Oct 2015 14:50:14 +0100 Subject: [PATCH 058/220] Adds a systemd journal appender --- CMakeLists.txt | 14 ++ cmake/Findlibsystemd.cmake | 44 +++++ config.h.in | 1 + winpr/include/winpr/wlog.h | 11 ++ winpr/libwinpr/utils/CMakeLists.txt | 11 ++ winpr/libwinpr/utils/wlog/Appender.c | 10 ++ winpr/libwinpr/utils/wlog/Appender.h | 4 + winpr/libwinpr/utils/wlog/JournaldAppender.c | 172 +++++++++++++++++++ winpr/libwinpr/utils/wlog/JournaldAppender.h | 35 ++++ winpr/libwinpr/utils/wlog/wlog.c | 4 + 10 files changed, 306 insertions(+) create mode 100644 cmake/Findlibsystemd.cmake create mode 100644 winpr/libwinpr/utils/wlog/JournaldAppender.c create mode 100644 winpr/libwinpr/utils/wlog/JournaldAppender.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 94e807499..e8268be12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -605,6 +605,20 @@ if(ANDROID) set(OPENSLES_FEATURE_TYPE "REQUIRED") endif() +if(UNIX) + set(WLOG_SYSTEMD_JOURNAL_FEATURE_TYPE "RECOMMENDED") + set(WLOG_SYSTEMD_JOURNAL_FEATURE_PURPOSE "systemd journal appender") + set(WLOG_SYSTEMD_JOURNAL_FEATURE_DESCRIPTION "allows to export wLog to systemd journal") + + #include(Findlibsystemd) + find_feature(libsystemd ${WLOG_SYSTEMD_JOURNAL_FEATURE_TYPE} ${WLOG_SYSTEMD_JOURNAL_FEATURE_PURPOSE} ${WLOG_SYSTEMD_JOURNAL_FEATURE_DESCRIPTION}) + + if(LIBSYSTEMD_FOUND) + set(HAVE_JOURNALD_H TRUE) + else() + unset(HAVE_JOURNALD_H) + endif() +endif(UNIX) find_feature(X11 ${X11_FEATURE_TYPE} ${X11_FEATURE_PURPOSE} ${X11_FEATURE_DESCRIPTION}) find_feature(Wayland ${WAYLAND_FEATURE_TYPE} ${WAYLAND_FEATURE_PURPOSE} ${WAYLAND_FEATURE_DESCRIPTION}) diff --git a/cmake/Findlibsystemd.cmake b/cmake/Findlibsystemd.cmake new file mode 100644 index 000000000..ee00c782c --- /dev/null +++ b/cmake/Findlibsystemd.cmake @@ -0,0 +1,44 @@ +# Module defines +# LIBSYSTEMD_FOUND - libsystemd libraries and includes found +# LIBSYSTEMD_INCLUDE_DIRS - the libsystemd include directories +# LIBSYSTEMD_LIBRARIES - the libsystemd libraries +# +# Cache entries: +# LIBSYSTEMD_LIBRARY - detected libsystemd library +# LIBSYSTEMD_INCLUDE_DIR - detected libsystemd include dir(s) +# + +if(LIBSYSTEMD_INCLUDE_DIR AND LIBSYSTEMD_LIBRARY) + # in cache already + set(LIBSYSTEMD_FOUND TRUE) + set(LIBSYSTEMD_LIBRARIES ${LIBSYSTEMD_LIBRARY}) + set(LIBSYSTEMD_INCLUDE_DIRS ${LIBSYSTEMD_INCLUDE_DIR}) +else() + + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(_LIBSYSTEMD_PC QUIET "libsystemd") + endif(PKG_CONFIG_FOUND) + + find_path(LIBSYSTEMD_INCLUDE_DIR systemd/sd-journal.h + ${_LIBSYSTEMD_PC_INCLUDE_DIRS} + /usr/include + /usr/local/include + ) + mark_as_advanced(LIBSYSTEMD_INCLUDE_DIR) + + find_library (LIBSYSTEMD_LIBRARY NAMES systemd + PATHS + ${_LIBSYSTEMD_PC_LIBDIR} + ) + mark_as_advanced(LIBSYSTEMD_LIBRARY) + + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(libsystemd DEFAULT_MSG LIBSYSTEMD_LIBRARY LIBSYSTEMD_INCLUDE_DIR) + + if(libsystemd_FOUND) + set(LIBSYSTEMD_LIBRARIES ${LIBSYSTEMD_LIBRARY}) + set(LIBSYSTEMD_INCLUDE_DIRS ${LIBSYSTEMD_INCLUDE_DIR}) + endif() + +endif() diff --git a/config.h.in b/config.h.in index 83f3ee641..e25162dd1 100644 --- a/config.h.in +++ b/config.h.in @@ -33,6 +33,7 @@ #cmakedefine HAVE_AIO_H #cmakedefine HAVE_POLL_H #cmakedefine HAVE_SYSLOG_H +#cmakedefine HAVE_JOURNALD_H #cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK #cmakedefine HAVE_VALGRIND_MEMCHECK_H #cmakedefine HAVE_EXECINFO_H diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 488e893b6..6e86f0806 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -114,6 +114,7 @@ struct _wLogLayout #define WLOG_APPENDER_BINARY 2 #define WLOG_APPENDER_CALLBACK 3 #define WLOG_APPENDER_SYSLOG 4 +#define WLOG_APPENDER_JOURNALD 5 #define WLOG_PACKET_INBOUND 1 #define WLOG_PACKET_OUTBOUND 2 @@ -204,6 +205,16 @@ struct _wLogSyslogAppender }; typedef struct _wLogSyslogAppender wLogSyslogAppender; +#ifdef HAVE_JOURNALD_H +struct _wLogJournaldAppender +{ + WLOG_APPENDER_COMMON(); + FILE *stream; +}; +typedef struct _wLogJournaldAppender wLogJournaldAppender; +#endif + + /** * Filter */ diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index 654a321bd..a84d180f8 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -58,6 +58,16 @@ if (HAVE_SYSLOG_H) wlog/SyslogAppender.h ) endif() + +if (LIBSYSTEMD_FOUND) + set(JOURNALD_SRCS + wlog/JournaldAppender.c + wlog/JournaldAppender.h + ) + + winpr_include_directory_add(${LIBSYSTEMD_INCLUDE_DIR}) + winpr_library_add(${LIBSYSTEMD_LIBRARY}) +endif() set(${MODULE_PREFIX}_WLOG_SRCS wlog/wlog.c @@ -85,6 +95,7 @@ set(${MODULE_PREFIX}_WLOG_SRCS wlog/ConsoleAppender.c wlog/ConsoleAppender.h ${SYSLOG_SRCS} + ${JOURNALD_SRCS} ) diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index 3ca867912..8008f6df3 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -52,6 +52,11 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) case WLOG_APPENDER_SYSLOG: appender = (wLogAppender*) WLog_SyslogAppender_New(log); break; +#endif +#ifdef HAVE_JOURNALD_H + case WLOG_APPENDER_JOURNALD: + appender = (wLogAppender*) WLog_JournaldAppender_New(log); + break; #endif default: fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType); @@ -107,6 +112,11 @@ void WLog_Appender_Free(wLog* log, wLogAppender* appender) case WLOG_APPENDER_SYSLOG: WLog_SyslogAppender_Free(log, (wLogSyslogAppender *) appender); break; +#endif +#ifdef HAVE_JOURNALD_H + case WLOG_APPENDER_JOURNALD: + WLog_JournaldAppender_Free(log, (wLogJournaldAppender *) appender); + break; #endif default: fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type); diff --git a/winpr/libwinpr/utils/wlog/Appender.h b/winpr/libwinpr/utils/wlog/Appender.h index 165e348b8..ccb57085a 100644 --- a/winpr/libwinpr/utils/wlog/Appender.h +++ b/winpr/libwinpr/utils/wlog/Appender.h @@ -31,6 +31,10 @@ #include "wlog/SyslogAppender.h" #endif +#ifdef HAVE_JOURNALD_H +#include "wlog/JournaldAppender.h" +#endif + void WLog_Appender_Free(wLog* log, wLogAppender* appender); #include "wlog/wlog.h" diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c new file mode 100644 index 000000000..a1e2b1e87 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -0,0 +1,172 @@ +/** + * WinPR: Windows Portable Runtime + * WinPR Logger + * + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include +#include +#include + +#include + +#include "wlog/Message.h" +#include "wlog/JournaldAppender.h" + + +static BOOL WLog_JournaldAppender_Open(wLog* log, wLogJournaldAppender* appender) +{ + if (!log || !appender) + return FALSE; + + return TRUE; +} + +static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appender) +{ + if (!log || !appender) + return FALSE; + + return TRUE; +} + +static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +{ + char *formatStr; + + if (!log || !appender || !message) + return FALSE; + + switch (message->Level) + { + case WLOG_TRACE: + case WLOG_DEBUG: + formatStr = "<7>%s\n"; + break; + case WLOG_INFO: + formatStr = "<6>%s\n"; + break; + case WLOG_WARN: + formatStr = "<4>%s\n"; + break; + case WLOG_ERROR: + formatStr = "<3>%s\n"; + break; + case WLOG_FATAL: + formatStr = "<2>%s\n"; + break; + case WLOG_OFF: + return TRUE; + default: + fprintf(stderr, "%s: unknown level %d\n", __FUNCTION__, message->Level); + return FALSE; + } + + fprintf(appender->stream, formatStr, message->TextString); + return TRUE; +} + +static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +{ + if (!log || !appender || !message) + return FALSE; + + return TRUE; +} + +static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +{ + if (!log || !appender || !message) + return FALSE; + + + return TRUE; +} + +wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) +{ + wLogJournaldAppender* appender; + DWORD nSize; + LPSTR env = NULL; + LPCSTR name; + int fd; + + appender = (wLogJournaldAppender*) calloc(1, sizeof(wLogJournaldAppender)); + if (!appender) + return NULL; + + appender->Type = WLOG_APPENDER_JOURNALD; + + appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Open; + appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Close; + appender->WriteMessage = + (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_JournaldAppender_WriteMessage; + appender->WriteDataMessage = + (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_JournaldAppender_WriteDataMessage; + appender->WriteImageMessage = + (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_JournaldAppender_WriteImageMessage; + + name = "WLOG_JOURNALD_ID"; + nSize = GetEnvironmentVariableA(name, NULL, 0); + if (nSize) + { + env = (LPSTR) malloc(nSize); + if (!env) + goto error_env_malloc; + + GetEnvironmentVariableA(name, env, nSize); + } + else + { + env = _strdup("winpr"); + } + + fd = sd_journal_stream_fd(env, LOG_INFO, 1); + if (fd < 0) + goto error_journal_fd; + + appender->stream = fdopen(fd, "w"); + if (!appender->stream) + goto error_stream_open; + return appender; + +error_stream_open: + close(fd); +error_journal_fd: + free(env); +error_env_malloc: + free(appender); + return NULL; +} + +void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender) +{ + if (appender) + { + if (appender->stream) + fclose(appender->stream); + free(appender); + } +} diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.h b/winpr/libwinpr/utils/wlog/JournaldAppender.h new file mode 100644 index 000000000..f3606eb03 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.h @@ -0,0 +1,35 @@ +/** + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ +#define WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ + +#include + +#include "wlog/wlog.h" + +WINPR_API wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log); +WINPR_API void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender); + + +#endif /* WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 1dbbda2c0..06bfa3ce8 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -702,6 +702,10 @@ wLog* WLog_GetRoot() else if (_stricmp(env, "SYSLOG") == 0) logAppenderType = WLOG_APPENDER_SYSLOG; #endif /* HAVE_SYSLOG_H */ +#ifdef HAVE_JOURNALD_H + else if (_stricmp(env, "SYSTEMD") == 0) + logAppenderType = WLOG_APPENDER_JOURNALD; +#endif free(env); } From 89156e53b79ae66fde7b178fcee4fbb000fde8a8 Mon Sep 17 00:00:00 2001 From: David FORT Date: Fri, 30 Oct 2015 20:20:42 +0100 Subject: [PATCH 059/220] Use unbuffered output --- winpr/libwinpr/utils/wlog/JournaldAppender.c | 1 + 1 file changed, 1 insertion(+) diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index a1e2b1e87..dfea43984 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -150,6 +150,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) appender->stream = fdopen(fd, "w"); if (!appender->stream) goto error_stream_open; + setbuffer(appender->stream, NULL, 0); return appender; error_stream_open: From e3915b66b7e8e6b577af40b7f14dd30ea170798c Mon Sep 17 00:00:00 2001 From: David FORT Date: Fri, 30 Oct 2015 20:22:25 +0100 Subject: [PATCH 060/220] Fix the env var leak --- winpr/libwinpr/utils/wlog/JournaldAppender.c | 1 + 1 file changed, 1 insertion(+) diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index dfea43984..797535790 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -151,6 +151,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) if (!appender->stream) goto error_stream_open; setbuffer(appender->stream, NULL, 0); + free(env); return appender; error_stream_open: From 2a8de84342503059e33cfa3a36ee864b1c97daf4 Mon Sep 17 00:00:00 2001 From: David FORT Date: Sun, 1 Nov 2015 21:34:03 +0100 Subject: [PATCH 061/220] Take in account @bmiklautz remarks * I have added a function to set the journal identifier * the appender name has been changed from SYSTEMD to JOURNALD --- winpr/include/winpr/wlog.h | 3 +- winpr/libwinpr/utils/wlog/JournaldAppender.c | 61 ++++++++++++++------ winpr/libwinpr/utils/wlog/JournaldAppender.h | 1 + winpr/libwinpr/utils/wlog/wlog.c | 2 +- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 6e86f0806..7ac9dd002 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -205,14 +205,13 @@ struct _wLogSyslogAppender }; typedef struct _wLogSyslogAppender wLogSyslogAppender; -#ifdef HAVE_JOURNALD_H struct _wLogJournaldAppender { WLOG_APPENDER_COMMON(); + char *identifier; FILE *stream; }; typedef struct _wLogJournaldAppender wLogJournaldAppender; -#endif /** diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index 797535790..4b8423018 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -35,12 +35,42 @@ #include "wlog/Message.h" #include "wlog/JournaldAppender.h" +BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id) +{ + if (appender->identifier) + free(appender->identifier); + + if (appender->stream) + { + fclose(appender->stream); + appender->stream = NULL; + } + + return ((appender->identifier = _strdup(id)) != NULL); +} static BOOL WLog_JournaldAppender_Open(wLog* log, wLogJournaldAppender* appender) { + int fd; + if (!log || !appender) return FALSE; + if (appender->stream) + return TRUE; + + fd = sd_journal_stream_fd(appender->identifier, LOG_INFO, 1); + if (fd < 0) + return FALSE; + + appender->stream = fdopen(fd, "w"); + if (!appender->stream) + { + close(fd); + return FALSE; + } + + setbuffer(appender->stream, NULL, 0); return TRUE; } @@ -109,9 +139,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) { wLogJournaldAppender* appender; DWORD nSize; - LPSTR env = NULL; LPCSTR name; - int fd; appender = (wLogJournaldAppender*) calloc(1, sizeof(wLogJournaldAppender)); if (!appender) @@ -132,32 +160,26 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) nSize = GetEnvironmentVariableA(name, NULL, 0); if (nSize) { - env = (LPSTR) malloc(nSize); - if (!env) + appender->identifier = (LPSTR) malloc(nSize); + if (!appender->identifier) goto error_env_malloc; - GetEnvironmentVariableA(name, env, nSize); + GetEnvironmentVariableA(name, appender->identifier, nSize); + + if (!WLog_JournaldAppender_Open(log, appender)) + goto error_open; } else { - env = _strdup("winpr"); + appender->identifier = _strdup("winpr"); + if (!appender->identifier) + goto error_env_malloc; } - fd = sd_journal_stream_fd(env, LOG_INFO, 1); - if (fd < 0) - goto error_journal_fd; - - appender->stream = fdopen(fd, "w"); - if (!appender->stream) - goto error_stream_open; - setbuffer(appender->stream, NULL, 0); - free(env); return appender; -error_stream_open: - close(fd); -error_journal_fd: - free(env); +error_open: + free(appender->identifier); error_env_malloc: free(appender); return NULL; @@ -169,6 +191,7 @@ void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender) { if (appender->stream) fclose(appender->stream); + free(appender->identifier); free(appender); } } diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.h b/winpr/libwinpr/utils/wlog/JournaldAppender.h index f3606eb03..9f2072d49 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.h +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.h @@ -30,6 +30,7 @@ WINPR_API wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log); WINPR_API void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender); +WINPR_API BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id); #endif /* WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 06bfa3ce8..7dc6208e8 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -703,7 +703,7 @@ wLog* WLog_GetRoot() logAppenderType = WLOG_APPENDER_SYSLOG; #endif /* HAVE_SYSLOG_H */ #ifdef HAVE_JOURNALD_H - else if (_stricmp(env, "SYSTEMD") == 0) + else if (_stricmp(env, "JOURNALD") == 0) logAppenderType = WLOG_APPENDER_JOURNALD; #endif From 0f1cedcbb8bdf011737d0cf414fbc26b6610d069 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Tue, 3 Nov 2015 12:05:47 +0100 Subject: [PATCH 062/220] codec/color: fix segfault in freerdp_image32_copy Code path for dstBytesPerPixel == 3 moved src and dst pointers beyond their respective buffers. --- libfreerdp/codec/color.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/codec/color.c b/libfreerdp/codec/color.c index 7e4235cb8..08c5c4284 100644 --- a/libfreerdp/codec/color.c +++ b/libfreerdp/codec/color.c @@ -3444,8 +3444,8 @@ int freerdp_image32_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDs pSrcPixel++; } - pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcStep]; - pDstPixel = (BYTE*) &((BYTE*) pDstPixel)[nDstStep]; + pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcPad]; + pDstPixel = (BYTE*) &((BYTE*) pDstPixel)[nDstPad]; } return 1; From b5288daea5f33a6bcdf04717a0ac49a067f3ce9b Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 3 Nov 2015 16:18:09 +0100 Subject: [PATCH 063/220] Fixed return values. --- winpr/libwinpr/path/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/path/path.c b/winpr/libwinpr/path/path.c index de7b2aaeb..2f853aad0 100644 --- a/winpr/libwinpr/path/path.c +++ b/winpr/libwinpr/path/path.c @@ -596,13 +596,13 @@ HRESULT PathCchRemoveExtensionW(PWSTR pszPath, size_t cchPath) BOOL PathCchIsRootA(PCSTR pszPath) { WLog_ERR(TAG, "%s: not implemented", __FUNCTION__); - return E_NOTIMPL; + return FALSE; } BOOL PathCchIsRootW(PCWSTR pszPath) { WLog_ERR(TAG, "%s: not implemented", __FUNCTION__); - return E_NOTIMPL; + return FALSE; } /** From d4d42710007f9006c0971c63cd778b7e7a9238f3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 3 Nov 2015 16:16:49 +0100 Subject: [PATCH 064/220] Disabled client builds if WITH_CLIENT is not set. --- client/CMakeLists.txt | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index b8b769922..37a811db2 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -19,7 +19,7 @@ add_subdirectory(common) -if(FREERDP_VENDOR) +if(FREERDP_VENDOR AND WITH_CLIENT) if(WIN32) add_subdirectory(Windows) else() @@ -58,28 +58,28 @@ if(FREERDP_VENDOR) endif() # Pick up other clients +if(WITH_CLIENT) + set(FILENAME "ModuleOptions.cmake") + file(GLOB FILEPATHS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/${FILENAME}") -set(FILENAME "ModuleOptions.cmake") -file(GLOB FILEPATHS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/${FILENAME}") - -foreach(FILEPATH ${FILEPATHS}) - if(${FILEPATH} MATCHES "^([^/]*)/+${FILENAME}") - string(REGEX REPLACE "^([^/]*)/+${FILENAME}" "\\1" FREERDP_CLIENT ${FILEPATH}) - set(FREERDP_CLIENT_ENABLED 0) - include(${FILEPATH}) - if(FREERDP_CLIENT_ENABLED) - if(NOT (${FREERDP_CLIENT_VENDOR} MATCHES "FreeRDP")) - list(APPEND FREERDP_EXTRA_CLIENTS ${FREERDP_CLIENT}) - if(${FREERDP_CLIENT_VENDOR} MATCHES "${VENDOR}") - set(CLIENT_VENDOR_PATH "client/${FREERDP_CLIENT}" PARENT_SCOPE) + foreach(FILEPATH ${FILEPATHS}) + if(${FILEPATH} MATCHES "^([^/]*)/+${FILENAME}") + string(REGEX REPLACE "^([^/]*)/+${FILENAME}" "\\1" FREERDP_CLIENT ${FILEPATH}) + set(FREERDP_CLIENT_ENABLED 0) + include(${FILEPATH}) + if(FREERDP_CLIENT_ENABLED) + if(NOT (${FREERDP_CLIENT_VENDOR} MATCHES "FreeRDP")) + list(APPEND FREERDP_EXTRA_CLIENTS ${FREERDP_CLIENT}) + if(${FREERDP_CLIENT_VENDOR} MATCHES "${VENDOR}") + set(CLIENT_VENDOR_PATH "client/${FREERDP_CLIENT}" PARENT_SCOPE) + endif() endif() endif() endif() - endif() -endforeach() - -foreach(FREERDP_CLIENT ${FREERDP_EXTRA_CLIENTS}) - add_subdirectory(${FREERDP_CLIENT}) -endforeach() + endforeach() + foreach(FREERDP_CLIENT ${FREERDP_EXTRA_CLIENTS}) + add_subdirectory(${FREERDP_CLIENT}) + endforeach() +endif() From 1ba4f9b67ff77b1d28aac8bb3d1de83f71e24c2a Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 4 Nov 2015 09:53:13 +0100 Subject: [PATCH 065/220] Added WITH_CLIENT_COMMON option. --- CMakeLists.txt | 4 ++-- cmake/ConfigOptions.cmake | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8268be12..718f9ff70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -776,8 +776,8 @@ if(WITH_CHANNELS) add_subdirectory(channels) endif() -if(WITH_CLIENT) - add_subdirectory(client) +if(WITH_CLIENT_COMMON OR WITH_CLIENT) +add_subdirectory(client) endif() if(WITH_SERVER) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 244fdcf6e..871d816c4 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -60,7 +60,8 @@ CMAKE_DEPENDENT_OPTION(TESTS_WTSAPI_EXTRA "Build extra WTSAPI tests (interactive option(WITH_SAMPLE "Build sample code" OFF) -option(WITH_CLIENT "Build client binaries" ON) +option(WITH_CLIENT_COMMON "Build client common library" ON) +cmake_dependent_option(WITH_CLIENT "Build client binaries" ON WITH_CLIENT_COMMON ON) option(WITH_SERVER "Build server binaries" OFF) option(STATIC_CHANNELS "Build channels statically" ON) From 9b7c35e122d970285bddf64d142b4c9ed964f45a Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 4 Nov 2015 13:15:37 +0100 Subject: [PATCH 066/220] Fixed WITH_CLIENT_CHANNELS dependencies. --- cmake/ConfigOptions.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 871d816c4..9d501c164 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -62,15 +62,15 @@ option(WITH_SAMPLE "Build sample code" OFF) option(WITH_CLIENT_COMMON "Build client common library" ON) cmake_dependent_option(WITH_CLIENT "Build client binaries" ON WITH_CLIENT_COMMON ON) + option(WITH_SERVER "Build server binaries" OFF) option(STATIC_CHANNELS "Build channels statically" ON) option(WITH_CHANNELS "Build virtual channel plugins" ON) -if(WITH_CLIENT AND WITH_CHANNELS) - option(WITH_CLIENT_CHANNELS "Build virtual channel plugins" ON) -endif() +cmake_dependent_option(WITH_CLIENT_CHANNELS "Build virtual channel plugins" ON + "WITH_CLIENT_COMMON;WITH_CHANNELS" ON) if(WITH_SERVER AND WITH_CHANNELS) option(WITH_SERVER_CHANNELS "Build virtual channel plugins" ON) From 48be0815c1f12f1f268135a0a214b327d79a9457 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Wed, 4 Nov 2015 15:01:31 +0100 Subject: [PATCH 067/220] client/X11: multimon/fullscreen fixes - fixed wrong calculation of xfc->fullscreenMonitors.[right|bottom] - only use _NET_WM_FULLSCREEN_MONITORS if at least 2 monitors are involved - call XMoveWindow before setting the _NET_WM_STATE_FULLSCREEN property --- client/X11/xf_monitor.c | 27 +++++++++++++-------------- client/X11/xf_window.c | 27 ++++++++++++--------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/client/X11/xf_monitor.c b/client/X11/xf_monitor.c index 920323ade..346bcd9c4 100644 --- a/client/X11/xf_monitor.c +++ b/client/X11/xf_monitor.c @@ -120,7 +120,6 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) int i; int nmonitors = 0; int primaryMonitorFound = FALSE; - int vX, vY, vWidth, vHeight; VIRTUAL_SCREEN* vscreen; rdpSettings* settings = xfc->settings; @@ -270,10 +269,10 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) if (settings->MonitorCount) { /* Initialize bounding rectangle for all monitors */ - vWidth = settings->MonitorDefArray[0].width; - vHeight = settings->MonitorDefArray[0].height; - vX = settings->MonitorDefArray[0].x; - vY = settings->MonitorDefArray[0].y; + int vX = settings->MonitorDefArray[0].x; + int vY = settings->MonitorDefArray[0].y; + int vR = vX + settings->MonitorDefArray[0].width; + int vB = vY + settings->MonitorDefArray[0].height; xfc->fullscreenMonitors.top = xfc->fullscreenMonitors.bottom = xfc->fullscreenMonitors.left = xfc->fullscreenMonitors.right = settings->MonitorDefArray[0].orig_screen; @@ -285,36 +284,36 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) /* does the same as gdk_rectangle_union */ int destX = MIN(vX, settings->MonitorDefArray[i].x); int destY = MIN(vY, settings->MonitorDefArray[i].y); - int destWidth = MAX(vX + vWidth, settings->MonitorDefArray[i].x + settings->MonitorDefArray[i].width) - destX; - int destHeight = MAX(vY + vHeight, settings->MonitorDefArray[i].y + settings->MonitorDefArray[i].height) - destY; + int destR = MAX(vR, settings->MonitorDefArray[i].x + settings->MonitorDefArray[i].width); + int destB = MAX(vB, settings->MonitorDefArray[i].y + settings->MonitorDefArray[i].height); if (vX != destX) xfc->fullscreenMonitors.left = settings->MonitorDefArray[i].orig_screen; if (vY != destY) xfc->fullscreenMonitors.top = settings->MonitorDefArray[i].orig_screen; - if (vWidth != destWidth) + if (vR != destR) xfc->fullscreenMonitors.right = settings->MonitorDefArray[i].orig_screen; - if (vHeight != destHeight) + if (vB != destB) xfc->fullscreenMonitors.bottom = settings->MonitorDefArray[i].orig_screen; vX = destX; vY = destY; - vWidth = destWidth; - vHeight = destHeight; + vR = destR; + vB = destB; } settings->DesktopPosX = vX; settings->DesktopPosY = vY; vscreen->area.left = 0; - vscreen->area.right = vWidth - 1; + vscreen->area.right = vR - vX - 1; vscreen->area.top = 0; - vscreen->area.bottom = vHeight - 1; + vscreen->area.bottom = vB - vY - 1; if (settings->Workarea) { vscreen->area.top = xfc->workArea.y; - vscreen->area.bottom = (vHeight - (vHeight - (xfc->workArea.height + xfc->workArea.y))) - 1; + vscreen->area.bottom = xfc->workArea.height + xfc->workArea.y - 1; } /* If there are multiple monitors and we have not selected a primary */ diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index b7a4663e2..db8bd255b 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -185,30 +185,27 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) */ startX = startX + xfc->instance->settings->MonitorLocalShiftX; startY = startY + xfc->instance->settings->MonitorLocalShiftY; - } - xf_ResizeDesktopWindow(xfc, window, width, height); - - /* Set the fullscreen state */ - xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, - fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE, - xfc->_NET_WM_STATE_FULLSCREEN, 0, 0); - - /* Only send monitor bounds if they are valid */ - if ((xfc->fullscreenMonitors.top >= 0) && - (xfc->fullscreenMonitors.bottom >= 0) && - (xfc->fullscreenMonitors.left >= 0) && - (xfc->fullscreenMonitors.right >= 0)) - { - xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_FULLSCREEN_MONITORS, 5, + /* Set monitor bounds */ + if (settings->MonitorCount > 1) + { + xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_FULLSCREEN_MONITORS, 5, xfc->fullscreenMonitors.top, xfc->fullscreenMonitors.bottom, xfc->fullscreenMonitors.left, xfc->fullscreenMonitors.right, 1); + } } + xf_ResizeDesktopWindow(xfc, window, width, height); + XMoveWindow(xfc->display, window->handle, startX, startY); + + /* Set the fullscreen state */ + xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, + fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE, + xfc->_NET_WM_STATE_FULLSCREEN, 0, 0); } /* http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html */ From 7ddd15d8deab94a8a2c1d61c792188fa7b6e21a2 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Wed, 4 Nov 2015 17:58:21 +0100 Subject: [PATCH 068/220] client/X11: fix post fullscreen repositioning --- client/X11/xf_window.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index db8bd255b..9e7ed6e38 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -200,12 +200,22 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) xf_ResizeDesktopWindow(xfc, window, width, height); - XMoveWindow(xfc->display, window->handle, startX, startY); + if (fullscreen) + { + /* enter full screen: move the window before adding NET_WM_STATE_FULLSCREEN */ + XMoveWindow(xfc->display, window->handle, startX, startY); + } /* Set the fullscreen state */ xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE, xfc->_NET_WM_STATE_FULLSCREEN, 0, 0); + + if (!fullscreen) + { + /* leave full screen: move the window after removing NET_WM_STATE_FULLSCREEN */ + XMoveWindow(xfc->display, window->handle, startX, startY); + } } /* http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html */ From 5fbf26acf2c231d4c4ac0636e4d1055194284b24 Mon Sep 17 00:00:00 2001 From: David FORT Date: Wed, 4 Nov 2015 18:11:19 +0100 Subject: [PATCH 069/220] Add an UDP appender to wLog This appender allows to receive the logs over a network connection using UDP packets. You can see the logs using a listening netcat, for example: nc -ul 127.0.0.1 20000. --- winpr/include/winpr/wlog.h | 12 ++ winpr/libwinpr/utils/CMakeLists.txt | 2 + winpr/libwinpr/utils/wlog/Appender.c | 6 + winpr/libwinpr/utils/wlog/Appender.h | 1 + winpr/libwinpr/utils/wlog/UdpAppender.c | 209 ++++++++++++++++++++++++ winpr/libwinpr/utils/wlog/UdpAppender.h | 35 ++++ winpr/libwinpr/utils/wlog/wlog.c | 2 + 7 files changed, 267 insertions(+) create mode 100644 winpr/libwinpr/utils/wlog/UdpAppender.c create mode 100644 winpr/libwinpr/utils/wlog/UdpAppender.h diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 7ac9dd002..f7c0efd17 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -32,6 +32,7 @@ extern "C" { #include #include +#include typedef struct _wLog wLog; typedef struct _wLogMessage wLogMessage; @@ -115,6 +116,7 @@ struct _wLogLayout #define WLOG_APPENDER_CALLBACK 3 #define WLOG_APPENDER_SYSLOG 4 #define WLOG_APPENDER_JOURNALD 5 +#define WLOG_APPENDER_UDP 6 #define WLOG_PACKET_INBOUND 1 #define WLOG_PACKET_OUTBOUND 2 @@ -213,6 +215,16 @@ struct _wLogJournaldAppender }; typedef struct _wLogJournaldAppender wLogJournaldAppender; +struct _wLogUdpAppender +{ + WLOG_APPENDER_COMMON(); + char *host; + struct sockaddr targetAddr; + int targetAddrLen; + SOCKET sock; +}; +typedef struct _wLogUdpAppender wLogUdpAppender; + /** * Filter diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index a84d180f8..2a8411966 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -94,6 +94,8 @@ set(${MODULE_PREFIX}_WLOG_SRCS wlog/CallbackAppender.h wlog/ConsoleAppender.c wlog/ConsoleAppender.h + wlog/UdpAppender.c + wlog/UdpAppender.h ${SYSLOG_SRCS} ${JOURNALD_SRCS} ) diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index 8008f6df3..a9c4d566f 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -58,6 +58,9 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) appender = (wLogAppender*) WLog_JournaldAppender_New(log); break; #endif + case WLOG_APPENDER_UDP: + appender = (wLogAppender*) WLog_UdpAppender_New(log); + break; default: fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType); appender = NULL; @@ -118,6 +121,9 @@ void WLog_Appender_Free(wLog* log, wLogAppender* appender) WLog_JournaldAppender_Free(log, (wLogJournaldAppender *) appender); break; #endif + case WLOG_APPENDER_UDP: + WLog_UdpAppender_Free(log, (wLogUdpAppender *) appender); + break; default: fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type); break; diff --git a/winpr/libwinpr/utils/wlog/Appender.h b/winpr/libwinpr/utils/wlog/Appender.h index ccb57085a..6b9b8ee21 100644 --- a/winpr/libwinpr/utils/wlog/Appender.h +++ b/winpr/libwinpr/utils/wlog/Appender.h @@ -26,6 +26,7 @@ #include "wlog/BinaryAppender.h" #include "wlog/ConsoleAppender.h" #include "wlog/CallbackAppender.h" +#include "wlog/UdpAppender.h" #ifdef HAVE_SYSLOG_H #include "wlog/SyslogAppender.h" diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c new file mode 100644 index 000000000..f20983733 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -0,0 +1,209 @@ +/** + * WinPR: Windows Portable Runtime + * WinPR Logger + * + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include +#include +#include + +#include + +#include "wlog/Message.h" +#include "wlog/UdpAppender.h" + +#ifndef _WIN32 +#include +#include +#include +#endif + +static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender) +{ + char addressString[256]; + struct addrinfo hints; + struct addrinfo* result; + int status, addrLen; + char *colonPos; + + + if (!log || !appender) + return FALSE; + + if (appender->targetAddrLen) /* already opened */ + return TRUE; + + colonPos = strchr(appender->host, ':'); + if (!colonPos) + return FALSE; + addrLen = colonPos - appender->host; + memcpy(addressString, appender->host, addrLen); + addressString[addrLen] = '\0'; + + ZeroMemory(&hints, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + + status = getaddrinfo(addressString, colonPos+1, &hints, &result); + if (status != 0) + return FALSE; + + if (result->ai_addrlen > sizeof(appender->targetAddr)) + { + freeaddrinfo(result); + return FALSE; + } + + memcpy(&appender->targetAddr, result->ai_addr, result->ai_addrlen); + appender->targetAddrLen = result->ai_addrlen; + + + return TRUE; +} + +BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host) +{ + + appender->targetAddrLen = 0; + if (appender->host) + free(appender->host); + + appender->host = _strdup(host); + return (appender->host != NULL) && WLog_UdpAppender_Open(NULL, appender); +} + +static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender) +{ + if (!log || !appender) + return FALSE; + + return TRUE; +} + +static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +{ + char prefix[WLOG_MAX_PREFIX_SIZE]; + + if (!log || !appender || !message) + return FALSE; + + message->PrefixString = prefix; + WLog_Layout_GetMessagePrefix(log, appender->Layout, message); + + _sendto(appender->sock, message->PrefixString, strlen(message->PrefixString), + 0, &appender->targetAddr, appender->targetAddrLen); + + _sendto(appender->sock, message->TextString, strlen(message->TextString), + 0, &appender->targetAddr, appender->targetAddrLen); + + _sendto(appender->sock, "\n", 1, 0, &appender->targetAddr, appender->targetAddrLen); + + return TRUE; +} + +static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +{ + if (!log || !appender || !message) + return FALSE; + + return TRUE; +} + +static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +{ + if (!log || !appender || !message) + return FALSE; + + + return TRUE; +} + +wLogUdpAppender* WLog_UdpAppender_New(wLog* log) +{ + wLogUdpAppender* appender; + DWORD nSize; + LPCSTR name; + + appender = (wLogUdpAppender*) calloc(1, sizeof(wLogUdpAppender)); + if (!appender) + return NULL; + + appender->Type = WLOG_APPENDER_UDP; + + appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Open; + appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Close; + appender->WriteMessage = + (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_UdpAppender_WriteMessage; + appender->WriteDataMessage = + (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_UdpAppender_WriteDataMessage; + appender->WriteImageMessage = + (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_UdpAppender_WriteImageMessage; + + appender->sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (appender->sock == INVALID_SOCKET) + goto error_sock; + + name = "WLOG_UDP_TARGET"; + nSize = GetEnvironmentVariableA(name, NULL, 0); + if (nSize) + { + appender->host = (LPSTR) malloc(nSize); + if (!appender->host) + goto error_env_malloc; + + GetEnvironmentVariableA(name, appender->host, nSize); + + if (!WLog_UdpAppender_Open(log, appender)) + goto error_open; + } + else + { + appender->host = _strdup("127.0.0.1:20000"); + if (!appender->host) + goto error_env_malloc; + } + + return appender; + +error_open: + free(appender->host); +error_env_malloc: + closesocket(appender->sock); +error_sock: + free(appender); + return NULL; +} + +void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender) +{ + if (appender) + { + if (appender->sock != INVALID_SOCKET) + { + closesocket(appender->sock); + appender->sock = INVALID_SOCKET; + } + free(appender->host); + free(appender); + } +} diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.h b/winpr/libwinpr/utils/wlog/UdpAppender.h new file mode 100644 index 000000000..cd25345f4 --- /dev/null +++ b/winpr/libwinpr/utils/wlog/UdpAppender.h @@ -0,0 +1,35 @@ +/** + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ +#define WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ + +#include + +#include "wlog/wlog.h" + +WINPR_API wLogUdpAppender* WLog_UdpAppender_New(wLog* log); +WINPR_API void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender); +WINPR_API BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host); + +#endif /* WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 7dc6208e8..123fe6384 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -706,6 +706,8 @@ wLog* WLog_GetRoot() else if (_stricmp(env, "JOURNALD") == 0) logAppenderType = WLOG_APPENDER_JOURNALD; #endif + else if (_stricmp(env, "UDP") == 0) + logAppenderType = WLOG_APPENDER_UDP; free(env); } From d6b5b906f449dc42441dddb6b5db7d76ae01e0d0 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Thu, 5 Nov 2015 18:10:05 +0100 Subject: [PATCH 070/220] winpr/argv: fix CommandLineToArgvA memory access - fixed access of unitialized memory beyond terminating null - minor simplifications --- winpr/libwinpr/thread/argv.c | 95 ++++++++++-------------------------- 1 file changed, 26 insertions(+), 69 deletions(-) diff --git a/winpr/libwinpr/thread/argv.c b/winpr/libwinpr/thread/argv.c index 2bd7dc4fb..ad96da236 100644 --- a/winpr/libwinpr/thread/argv.c +++ b/winpr/libwinpr/thread/argv.c @@ -101,7 +101,6 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) LPSTR* pArgs; int maxNumArgs; int maxBufferSize; - int currentIndex; int cmdLineLength; BOOL* lpEscapedChars; LPSTR lpEscapedCmdLine; @@ -167,36 +166,29 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) p += length; for (i = 0; i < (n / 2); i++) - { - *pOutput = '\\'; - pOutput++; - } + *pOutput++ = '\\'; p += n + 1; if ((n % 2) != 0) lpEscapedChars[pOutput - lpEscapedCmdLine] = TRUE; - *pOutput = '"'; - pOutput++; + *pOutput++ = '"'; pLastEnd = p; } - *pOutput = '\0'; - pOutput++; + *pOutput++ = '\0'; lpCmdLine = (LPCSTR) lpEscapedCmdLine; cmdLineLength = strlen(lpCmdLine); } maxNumArgs = 2; - currentIndex = 0; p = (char*) lpCmdLine; - while (currentIndex < cmdLineLength - 1) + while (p < lpCmdLine + cmdLineLength) { - index = strcspn(p, " \t"); - currentIndex += (index + 1); - p = (char*) &lpCmdLine[currentIndex]; + p += strcspn(p, " \t"); + p += strspn(p, " \t"); maxNumArgs++; } @@ -209,32 +201,24 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) pArgs = (LPSTR*) buffer; pOutput = (char*) &buffer[maxNumArgs * (sizeof(char*))]; numArgs = 0; - currentIndex = 0; p = (char*) lpCmdLine; - while (currentIndex < cmdLineLength) + while (p < lpCmdLine + cmdLineLength) { - pBeg = pEnd = p; + pBeg = p; while (1) { - index = strcspn(p, " \t\"\0"); - - if ((p[index] == '"') && (lpEscapedChars[&p[index] - lpCmdLine])) - { - p = &p[index + 1]; - continue; - } - - break; + p += strcspn(p, " \t\"\0"); + if ((*p != '"') || !lpEscapedChars[p - lpCmdLine]) + break; + p++; } - if (p[index] != '"') + if (*p != '"') { /* no whitespace escaped with double quotes */ - p = &p[index + 1]; - pEnd = p - 1; - length = (pEnd - pBeg); + length = p - pBeg; CopyMemory(pOutput, pBeg, length); pOutput[length] = '\0'; pArgs[numArgs++] = pOutput; @@ -242,62 +226,35 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) } else { - p = &p[index + 1]; + p++; while (1) { - index = strcspn(p, "\"\0"); - - if ((p[index] == '"') && (lpEscapedChars[&p[index] - lpCmdLine])) - { - p = &p[index + 1]; - continue; - } - - break; + p += strcspn(p, "\"\0"); + if ((*p != '"') || !lpEscapedChars[p - lpCmdLine]) + break; + p++; } - if (p[index] != '"') - { + if (*p != '"') WLog_ERR(TAG, "parsing error: uneven number of unescaped double quotes!"); - } - if (p[index] == '\0') - { - p = &p[index + 1]; - pEnd = p - 1; - } - else - { - p = &p[index + 1]; - index = strcspn(p, " \t\0"); - p = &p[index + 1]; - pEnd = p - 1; - } + if (*p && *(++p)) + p += strcspn(p, " \t\0"); - length = 0; pArgs[numArgs++] = pOutput; - while (pBeg < pEnd) + while (pBeg < p) { if (*pBeg != '"') - { - *pOutput = *pBeg; - pOutput++; - length++; - } - + *pOutput++ = *pBeg; pBeg++; } - *pOutput = '\0'; - pOutput++; + *pOutput++ = '\0'; } - while ((*p == ' ') || (*p == '\t')) - p++; - - currentIndex = (p - lpCmdLine); + p += strspn(p, " \t"); } free(lpEscapedCmdLine); From 458aaa121364cc431a35ee8f396631cda996b4ee Mon Sep 17 00:00:00 2001 From: David FORT Date: Fri, 6 Nov 2015 23:17:11 +0100 Subject: [PATCH 071/220] Take in account @nfedera's remarks --- winpr/libwinpr/utils/wlog/UdpAppender.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c index f20983733..bc161d37b 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.c +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -47,7 +47,7 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender) char *colonPos; - if (!log || !appender) + if (!appender) return FALSE; if (appender->targetAddrLen) /* already opened */ @@ -169,7 +169,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) { appender->host = (LPSTR) malloc(nSize); if (!appender->host) - goto error_env_malloc; + goto error_host_alloc; GetEnvironmentVariableA(name, appender->host, nSize); @@ -180,14 +180,14 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) { appender->host = _strdup("127.0.0.1:20000"); if (!appender->host) - goto error_env_malloc; + goto error_host_alloc; } return appender; error_open: free(appender->host); -error_env_malloc: +error_host_alloc: closesocket(appender->sock); error_sock: free(appender); From 8206ae440f905b123cb92c7abf8c861070ea8cd8 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Thu, 5 Nov 2015 12:29:41 +0100 Subject: [PATCH 072/220] Pump version to 2.0.0 --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8268be12..8ef132766 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,9 +68,9 @@ if ($ENV{BUILD_NUMBER}) set(BUILD_NUMBER $ENV{BUILD_NUMBER}) endif() set(WITH_LIBRARY_VERSIONING "ON") -set(FREERDP_VERSION_MAJOR "1") -set(FREERDP_VERSION_MINOR "2") -set(FREERDP_VERSION_REVISION "5") +set(FREERDP_VERSION_MAJOR "2") +set(FREERDP_VERSION_MINOR "0") +set(FREERDP_VERSION_REVISION "0") set(FREERDP_VERSION_SUFFIX "dev") set(FREERDP_API_VERSION "${FREERDP_VERSION_MAJOR}.${FREERDP_VERSION_MINOR}") set(FREERDP_VERSION "${FREERDP_API_VERSION}.${FREERDP_VERSION_REVISION}") From d73c4898c1766fc1f6a214b5c8dcc17648c29c7c Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Thu, 5 Nov 2015 14:02:07 +0100 Subject: [PATCH 073/220] Add build-config.h build-config.h should contain configure/compile time settings that are relevant for projects that use FreeRDP. For example the compiled in plugin search paths. --- .gitignore | 1 + channels/client/addin.c | 9 +++++---- config.h.in | 16 ---------------- include/CMakeLists.txt | 2 ++ include/freerdp/build-config.h.in | 20 ++++++++++++++++++++ libfreerdp/codec/rfx.c | 1 + libfreerdp/common/addin.c | 9 +++++---- libfreerdp/core/nla.c | 1 + libfreerdp/core/settings.c | 1 + server/Windows/wf_info.c | 2 ++ server/Windows/wf_interface.c | 1 + server/Windows/wf_peer.c | 1 + winpr/libwinpr/sspi/NTLM/ntlm.c | 1 + 13 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 include/freerdp/build-config.h.in diff --git a/.gitignore b/.gitignore index 98ca450a2..6853f6825 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ LICENSE.txt *Config.cmake *ConfigVersion.cmake include/freerdp/version.h +include/freerdp/build-config.h *.a.objlist.cmake *.a.objlist diff --git a/channels/client/addin.c b/channels/client/addin.c index 8f4d54bc3..a2d688006 100644 --- a/channels/client/addin.c +++ b/channels/client/addin.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "tables.h" @@ -181,22 +182,22 @@ FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSub if (pszName && pszSubsystem && pszType) { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client-%s-%s.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client-%s-%s.%s", pszName, pszSubsystem, pszType, pszExtension); } else if (pszName && pszType) { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client-?-%s.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client-?-%s.%s", pszName, pszType, pszExtension); } else if (pszName) { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client*.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client*.%s", pszName, pszExtension); } else { - sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"?-client*.%s", + sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"?-client*.%s", pszExtension); } diff --git a/config.h.in b/config.h.in index e25162dd1..0f39545f2 100644 --- a/config.h.in +++ b/config.h.in @@ -1,22 +1,6 @@ #ifndef __CONFIG_H #define __CONFIG_H -#define FREERDP_DATA_PATH "${FREERDP_DATA_PATH}" -#define FREERDP_KEYMAP_PATH "${FREERDP_KEYMAP_PATH}" -#define FREERDP_PLUGIN_PATH "${FREERDP_PLUGIN_PATH}" - -#define FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" - -#define FREERDP_LIBRARY_PATH "${FREERDP_LIBRARY_PATH}" - -#define FREERDP_ADDIN_PATH "${FREERDP_ADDIN_PATH}" - -#define CMAKE_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" -#define CMAKE_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" - -#define FREERDP_VENDOR_STRING "${VENDOR}" -#define FREERDP_PRODUCT_STRING "${PRODUCT}" - /* Include files */ #cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_UNISTD_H diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 06e2b77bd..8995688e3 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -18,10 +18,12 @@ # limitations under the License. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h) file(GLOB FREERDP_HEADERS "freerdp/*.h") install(FILES ${FREERDP_HEADERS} DESTINATION include/freerdp COMPONENT headers) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h DESTINATION include/freerdp COMPONENT headers) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h DESTINATION include/freerdp COMPONENT headers) install(DIRECTORY freerdp/cache DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") install(DIRECTORY freerdp/codec DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") diff --git a/include/freerdp/build-config.h.in b/include/freerdp/build-config.h.in new file mode 100644 index 000000000..788e27f2f --- /dev/null +++ b/include/freerdp/build-config.h.in @@ -0,0 +1,20 @@ +#ifndef FREERDP_BUILD_CONFIG_H +#define FREERDP_BUILD_CONFIG_H + +#define FREERDP_DATA_PATH "${FREERDP_DATA_PATH}" +#define FREERDP_KEYMAP_PATH "${FREERDP_KEYMAP_PATH}" +#define FREERDP_PLUGIN_PATH "${FREERDP_PLUGIN_PATH}" + +#define FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" + +#define FREERDP_LIBRARY_PATH "${FREERDP_LIBRARY_PATH}" + +#define FREERDP_ADDIN_PATH "${FREERDP_ADDIN_PATH}" + +#define FREERDP_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" +#define FREERDP_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" + +#define FREERDP_VENDOR_STRING "${VENDOR}" +#define FREERDP_PRODUCT_STRING "${PRODUCT}" + +#endif /* FREERDP_BUILD_CONFIG_H */ diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 7886daea4..cc8a61c38 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "rfx_constants.h" #include "rfx_types.h" diff --git a/libfreerdp/common/addin.c b/libfreerdp/common/addin.c index 52197b418..ce7cf7b9e 100644 --- a/libfreerdp/common/addin.c +++ b/libfreerdp/common/addin.c @@ -30,6 +30,7 @@ #include #include +#include LPSTR freerdp_get_library_install_path() @@ -143,7 +144,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE } else { - cchAddinFile = cchFileName + cchExt + 2 + sizeof(CMAKE_SHARED_LIBRARY_PREFIX); + cchAddinFile = cchFileName + cchExt + 2 + sizeof(FREERDP_SHARED_LIBRARY_PREFIX); pszAddinFile = (LPSTR) malloc(cchAddinFile + 1); if (!pszAddinFile) { @@ -151,7 +152,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE free(pszFilePath); return NULL; } - sprintf_s(pszAddinFile, cchAddinFile, CMAKE_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt); + sprintf_s(pszAddinFile, cchAddinFile, FREERDP_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt); cchAddinFile = strlen(pszAddinFile); } @@ -182,9 +183,9 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste { void* entry; LPSTR pszFileName; - size_t cchFileName = sizeof(CMAKE_SHARED_LIBRARY_PREFIX) + 32; + size_t cchFileName = sizeof(FREERDP_SHARED_LIBRARY_PREFIX) + 32; LPCSTR pszExtension; - LPCSTR pszPrefix = CMAKE_SHARED_LIBRARY_PREFIX; + LPCSTR pszPrefix = FREERDP_SHARED_LIBRARY_PREFIX; pszExtension = PathGetSharedLibraryExtensionA(0); diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 0fcbaa56f..22c013834 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -31,6 +31,7 @@ #include #include +#include #include #include diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index a89198ce4..2fb632fac 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -37,6 +37,7 @@ #include #include +#include #include diff --git a/server/Windows/wf_info.c b/server/Windows/wf_info.c index 460154bb7..a582bc835 100644 --- a/server/Windows/wf_info.c +++ b/server/Windows/wf_info.c @@ -23,6 +23,8 @@ #include +#include + #include #include diff --git a/server/Windows/wf_interface.c b/server/Windows/wf_interface.c index 216d3cae5..0dc8defd0 100644 --- a/server/Windows/wf_interface.c +++ b/server/Windows/wf_interface.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "wf_peer.h" #include "wf_settings.h" diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 4a4c493c9..ecb3a21bf 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -28,6 +28,7 @@ #include #include +#include #include "wf_info.h" #include "wf_input.h" diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index a210e45cc..9b732a8e2 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "ntlm.h" #include "../sspi.h" From 07417599ce151e16bf13407877b47525bbea74c4 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 9 Nov 2015 17:56:44 +0100 Subject: [PATCH 074/220] wlog: rework, cleanup and stabilize API * only expose necessary functions and types in header * don't expose appender internals * add generic function WLog_ConfigureAppender to have the possibility to configure appender specific settings * detect appender availability if WLog_SetLogAppenderType or WLog_Appender_New return FALSE or NULL respectively the appender isn't available or the initialization failed. This is very useful for the use with optional appenders. * add Free to the appender interface. At the time of the Free the appender is known and available so it can be called directly (instead of calling the right function according to the type) * make all appender internal function static * all appenders return the generic wLogAppender type now. Typecasts are internally done where necessary this abstracts the appenders more cleanly --- winpr/include/winpr/wlog.h | 235 ++++--------------- winpr/libwinpr/smartcard/smartcard_inspect.c | 10 +- winpr/libwinpr/utils/CMakeLists.txt | 1 - winpr/libwinpr/utils/test/TestWLog.c | 5 +- winpr/libwinpr/utils/test/TestWLogCallback.c | 11 +- winpr/libwinpr/utils/wlog/Appender.c | 192 +++++++-------- winpr/libwinpr/utils/wlog/Appender.h | 24 +- winpr/libwinpr/utils/wlog/BinaryAppender.c | 173 +++++++------- winpr/libwinpr/utils/wlog/BinaryAppender.h | 7 +- winpr/libwinpr/utils/wlog/CallbackAppender.c | 157 +++++++------ winpr/libwinpr/utils/wlog/CallbackAppender.h | 7 +- winpr/libwinpr/utils/wlog/ConsoleAppender.c | 135 ++++++----- winpr/libwinpr/utils/wlog/ConsoleAppender.h | 7 +- winpr/libwinpr/utils/wlog/DataMessage.c | 2 +- winpr/libwinpr/utils/wlog/DataMessage.h | 4 - winpr/libwinpr/utils/wlog/FileAppender.c | 163 +++++++------ winpr/libwinpr/utils/wlog/FileAppender.h | 7 +- winpr/libwinpr/utils/wlog/ImageMessage.c | 2 +- winpr/libwinpr/utils/wlog/ImageMessage.h | 4 - winpr/libwinpr/utils/wlog/JournaldAppender.c | 118 ++++++---- winpr/libwinpr/utils/wlog/JournaldAppender.h | 9 +- winpr/libwinpr/utils/wlog/Layout.c | 2 +- winpr/libwinpr/utils/wlog/Layout.h | 13 +- winpr/libwinpr/utils/wlog/Message.c | 4 +- winpr/libwinpr/utils/wlog/Message.h | 11 +- winpr/libwinpr/utils/wlog/PacketMessage.c | 2 +- winpr/libwinpr/utils/wlog/PacketMessage.h | 4 +- winpr/libwinpr/utils/wlog/SyslogAppender.c | 56 ++--- winpr/libwinpr/utils/wlog/SyslogAppender.h | 8 +- winpr/libwinpr/utils/wlog/TextMessage.c | 4 - winpr/libwinpr/utils/wlog/TextMessage.h | 30 --- winpr/libwinpr/utils/wlog/UdpAppender.c | 144 +++++++----- winpr/libwinpr/utils/wlog/UdpAppender.h | 4 +- winpr/libwinpr/utils/wlog/wlog.c | 11 +- winpr/libwinpr/utils/wlog/wlog.h | 53 +++++ 35 files changed, 764 insertions(+), 855 deletions(-) delete mode 100644 winpr/libwinpr/utils/wlog/TextMessage.h diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index f7c0efd17..0c50676df 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -3,6 +3,9 @@ * WinPR Logger * * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 Bernhard Miklautz + * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,32 +37,36 @@ extern "C" { #include #include -typedef struct _wLog wLog; -typedef struct _wLogMessage wLogMessage; -typedef struct _wLogLayout wLogLayout; -typedef struct _wLogAppender wLogAppender; - /** * Log Levels */ - -#define WLOG_TRACE 0 -#define WLOG_DEBUG 1 -#define WLOG_INFO 2 -#define WLOG_WARN 3 -#define WLOG_ERROR 4 -#define WLOG_FATAL 5 -#define WLOG_OFF 6 +#define WLOG_TRACE 0 +#define WLOG_DEBUG 1 +#define WLOG_INFO 2 +#define WLOG_WARN 3 +#define WLOG_ERROR 4 +#define WLOG_FATAL 5 +#define WLOG_OFF 6 #define WLOG_LEVEL_INHERIT 0xFFFF /** * Log Message */ +#define WLOG_MESSAGE_TEXT 0 +#define WLOG_MESSAGE_DATA 1 +#define WLOG_MESSAGE_IMAGE 2 +#define WLOG_MESSAGE_PACKET 3 -#define WLOG_MESSAGE_TEXT 0 -#define WLOG_MESSAGE_DATA 1 -#define WLOG_MESSAGE_IMAGE 2 -#define WLOG_MESSAGE_PACKET 3 +/** + * Log Appenders + */ +#define WLOG_APPENDER_CONSOLE 0 +#define WLOG_APPENDER_FILE 1 +#define WLOG_APPENDER_BINARY 2 +#define WLOG_APPENDER_CALLBACK 3 +#define WLOG_APPENDER_SYSLOG 4 +#define WLOG_APPENDER_JOURNALD 5 +#define WLOG_APPENDER_UDP 6 struct _wLogMessage { @@ -94,169 +101,13 @@ struct _wLogMessage int PacketLength; DWORD PacketFlags; }; +typedef struct _wLogMessage wLogMessage; +typedef struct _wLogLayout wLogLayout; +typedef struct _wLogAppender wLogAppender; +typedef struct _wLog wLog; -/** - * Log Layout - */ - -struct _wLogLayout -{ - DWORD Type; - - LPSTR FormatString; -}; - -/** - * Log Appenders - */ - -#define WLOG_APPENDER_CONSOLE 0 -#define WLOG_APPENDER_FILE 1 -#define WLOG_APPENDER_BINARY 2 -#define WLOG_APPENDER_CALLBACK 3 -#define WLOG_APPENDER_SYSLOG 4 -#define WLOG_APPENDER_JOURNALD 5 -#define WLOG_APPENDER_UDP 6 - -#define WLOG_PACKET_INBOUND 1 -#define WLOG_PACKET_OUTBOUND 2 - -typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); -typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); -typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); -typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); - -#define WLOG_APPENDER_COMMON() \ - DWORD Type; \ - DWORD State; \ - wLogLayout* Layout; \ - CRITICAL_SECTION lock; \ - BOOL recursive; \ - void* TextMessageContext; \ - void* DataMessageContext; \ - void* ImageMessageContext; \ - void* PacketMessageContext; \ - WLOG_APPENDER_OPEN_FN Open; \ - WLOG_APPENDER_CLOSE_FN Close; \ - WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \ - WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \ - WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \ - WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage - -struct _wLogAppender -{ - WLOG_APPENDER_COMMON(); -}; - -#define WLOG_CONSOLE_DEFAULT 0 -#define WLOG_CONSOLE_STDOUT 1 -#define WLOG_CONSOLE_STDERR 2 -#define WLOG_CONSOLE_DEBUG 4 - -struct _wLogConsoleAppender -{ - WLOG_APPENDER_COMMON(); - - int outputStream; -}; -typedef struct _wLogConsoleAppender wLogConsoleAppender; - -struct _wLogFileAppender -{ - WLOG_APPENDER_COMMON(); - - char* FileName; - char* FilePath; - char* FullFileName; - FILE* FileDescriptor; -}; -typedef struct _wLogFileAppender wLogFileAppender; - -struct _wLogBinaryAppender -{ - WLOG_APPENDER_COMMON(); - - char* FileName; - char* FilePath; - char* FullFileName; - FILE* FileDescriptor; -}; -typedef struct _wLogBinaryAppender wLogBinaryAppender; - -typedef BOOL (*CallbackAppenderMessage_t)(const wLogMessage *msg); -typedef BOOL (*CallbackAppenderData_t)(const wLogMessage *msg); -typedef BOOL (*CallbackAppenderImage_t)(const wLogMessage *msg); -typedef BOOL (*CallbackAppenderPackage_t)(const wLogMessage *msg); - -struct _wLogCallbackAppender -{ - WLOG_APPENDER_COMMON(); - - CallbackAppenderMessage_t message; - CallbackAppenderData_t data; - CallbackAppenderImage_t image; - CallbackAppenderPackage_t package; -}; -typedef struct _wLogCallbackAppender wLogCallbackAppender; - -struct _wLogSyslogAppender -{ - WLOG_APPENDER_COMMON(); -}; -typedef struct _wLogSyslogAppender wLogSyslogAppender; - -struct _wLogJournaldAppender -{ - WLOG_APPENDER_COMMON(); - char *identifier; - FILE *stream; -}; -typedef struct _wLogJournaldAppender wLogJournaldAppender; - -struct _wLogUdpAppender -{ - WLOG_APPENDER_COMMON(); - char *host; - struct sockaddr targetAddr; - int targetAddrLen; - SOCKET sock; -}; -typedef struct _wLogUdpAppender wLogUdpAppender; - - -/** - * Filter - */ - -struct _wLogFilter -{ - DWORD Level; - LPSTR* Names; - DWORD NameCount; -}; -typedef struct _wLogFilter wLogFilter; - -/** - * Logger - */ - -struct _wLog -{ - LPSTR Name; - DWORD Level; - - BOOL IsRoot; - LPSTR* Names; - DWORD NameCount; - wLogAppender* Appender; - - wLog* Parent; - wLog** Children; - DWORD ChildrenCount; - DWORD ChildrenSize; -}; +#define WLOG_PACKET_INBOUND 1 +#define WLOG_PACKET_OUTBOUND 2 WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...); WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args); @@ -345,20 +196,11 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args WINPR_API DWORD WLog_GetLogLevel(wLog* log); WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel); -WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType); - +WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); WINPR_API BOOL WLog_OpenAppender(wLog* log); WINPR_API BOOL WLog_CloseAppender(wLog* log); - -WINPR_API BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream); - -WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename); -WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath); - -WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, - CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, - CallbackAppenderData_t data); +WINPR_API BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value); WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log); WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format); @@ -369,6 +211,19 @@ WINPR_API wLog* WLog_Get(LPCSTR name); WINPR_API BOOL WLog_Init(void); WINPR_API BOOL WLog_Uninit(void); +typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage *msg); +typedef BOOL (*wLogCallbackData_t)(const wLogMessage *msg); +typedef BOOL (*wLogCallbackImage_t)(const wLogMessage *msg); +typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage *msg); + +struct _wLogCallbacks { + wLogCallbackData_t data; + wLogCallbackImage_t image; + wLogCallbackMessage_t message; + wLogCallbackPackage_t package; +}; +typedef struct _wLogCallbacks wLogCallbacks; + #ifdef __cplusplus } #endif diff --git a/winpr/libwinpr/smartcard/smartcard_inspect.c b/winpr/libwinpr/smartcard/smartcard_inspect.c index c36fc87e5..9b872f11c 100644 --- a/winpr/libwinpr/smartcard/smartcard_inspect.c +++ b/winpr/libwinpr/smartcard/smartcard_inspect.c @@ -1269,7 +1269,7 @@ SCardApiFunctionTable Inspect_SCardApiFunctionTable = void Inspect_InitLog() { wLogLayout* layout; - wLogFileAppender* appender; + wLogAppender* appender; const char* filepath = SMARTCARD_INSPECT_FILEPATH; if (g_Log) @@ -1284,10 +1284,12 @@ void Inspect_InitLog() WLog_SetLogLevel(g_Log, WLOG_DEBUG); WLog_SetLogAppenderType(g_Log, WLOG_APPENDER_FILE); - appender = (wLogFileAppender*) WLog_GetLogAppender(g_Log); + appender = WLog_GetLogAppender(g_Log); + if (!appender) + return; - WLog_FileAppender_SetOutputFileName(g_Log, appender, "WinSCard.txt"); - WLog_FileAppender_SetOutputFilePath(g_Log, appender, filepath); + WLog_ConfigureAppender(appender, "outputfilename", "WinSCard.txt"); + WLog_ConfigureAppender(appender, "outputfilepath", (void *)filepath); layout = WLog_GetLogLayout(g_Log); WLog_Layout_SetPrefixFormat(g_Log, layout, "[%mn] "); diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index 2a8411966..e305d0627 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -77,7 +77,6 @@ set(${MODULE_PREFIX}_WLOG_SRCS wlog/Message.c wlog/Message.h wlog/TextMessage.c - wlog/TextMessage.h wlog/DataMessage.c wlog/DataMessage.h wlog/ImageMessage.c diff --git a/winpr/libwinpr/utils/test/TestWLog.c b/winpr/libwinpr/utils/test/TestWLog.c index 34008003d..74e1c15a7 100644 --- a/winpr/libwinpr/utils/test/TestWLog.c +++ b/winpr/libwinpr/utils/test/TestWLog.c @@ -19,7 +19,10 @@ int TestWLog(int argc, char* argv[]) WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY); appender = WLog_GetLogAppender(root); - WLog_ConsoleAppender_SetOutputStream(root, (wLogConsoleAppender*) appender, WLOG_CONSOLE_STDERR); + if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log")) + return 1; + if(!WLog_ConfigureAppender(appender, "outputfilepath", "/tmp/")) + return 1; layout = WLog_GetLogLayout(root); WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - "); diff --git a/winpr/libwinpr/utils/test/TestWLogCallback.c b/winpr/libwinpr/utils/test/TestWLogCallback.c index 8cccbe52a..25330057b 100644 --- a/winpr/libwinpr/utils/test/TestWLogCallback.c +++ b/winpr/libwinpr/utils/test/TestWLogCallback.c @@ -90,6 +90,7 @@ int TestWLogCallback(int argc, char* argv[]) wLog* logB; wLogLayout* layout; wLogAppender* appender; + wLogCallbacks callbacks; function = __FUNCTION__; WLog_Init(); @@ -100,9 +101,13 @@ int TestWLogCallback(int argc, char* argv[]) appender = WLog_GetLogAppender(root); - WLog_CallbackAppender_SetCallbacks(root, (wLogCallbackAppender*) appender, - CallbackAppenderMessage, CallbackAppenderImage, CallbackAppenderPackage, - CallbackAppenderData); + callbacks.data = CallbackAppenderData; + callbacks.image = CallbackAppenderImage; + callbacks.message = CallbackAppenderMessage; + callbacks.package = CallbackAppenderPackage; + + if (!WLog_ConfigureAppender(appender, "callbacks", (void *)&callbacks)) + return -1; layout = WLog_GetLogLayout(root); WLog_Layout_SetPrefixFormat(root, layout, "%mn"); diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index a9c4d566f..8946d9695 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -21,68 +21,7 @@ #include "config.h" #endif -#include - -#include "wlog/Layout.h" - -#include "wlog/Appender.h" - -wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) -{ - wLogAppender* appender; - - if (!log) - return NULL; - - switch (logAppenderType) - { - case WLOG_APPENDER_CONSOLE: - appender = (wLogAppender*) WLog_ConsoleAppender_New(log); - break; - case WLOG_APPENDER_FILE: - appender = (wLogAppender*) WLog_FileAppender_New(log); - break; - case WLOG_APPENDER_BINARY: - appender = (wLogAppender*) WLog_BinaryAppender_New(log); - break; - case WLOG_APPENDER_CALLBACK: - appender = (wLogAppender*) WLog_CallbackAppender_New(log); - break; -#ifdef HAVE_SYSLOG_H - case WLOG_APPENDER_SYSLOG: - appender = (wLogAppender*) WLog_SyslogAppender_New(log); - break; -#endif -#ifdef HAVE_JOURNALD_H - case WLOG_APPENDER_JOURNALD: - appender = (wLogAppender*) WLog_JournaldAppender_New(log); - break; -#endif - case WLOG_APPENDER_UDP: - appender = (wLogAppender*) WLog_UdpAppender_New(log); - break; - default: - fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType); - appender = NULL; - break; - } - - if (!appender) - appender = (wLogAppender*) WLog_ConsoleAppender_New(log); - - if (!appender) - return NULL; - - if (!(appender->Layout = WLog_Layout_New(log))) - { - WLog_Appender_Free(log, appender); - return NULL; - } - - InitializeCriticalSectionAndSpinCount(&appender->lock, 4000); - - return appender; -} +#include "Appender.h" void WLog_Appender_Free(wLog* log, wLogAppender* appender) { @@ -96,38 +35,7 @@ void WLog_Appender_Free(wLog* log, wLogAppender* appender) } DeleteCriticalSection(&appender->lock); - - switch (appender->Type) - { - case WLOG_APPENDER_CONSOLE: - WLog_ConsoleAppender_Free(log, (wLogConsoleAppender*) appender); - break; - case WLOG_APPENDER_FILE: - WLog_FileAppender_Free(log, (wLogFileAppender*) appender); - break; - case WLOG_APPENDER_BINARY: - WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender); - break; - case WLOG_APPENDER_CALLBACK: - WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender); - break; -#ifdef HAVE_SYSLOG_H - case WLOG_APPENDER_SYSLOG: - WLog_SyslogAppender_Free(log, (wLogSyslogAppender *) appender); - break; -#endif -#ifdef HAVE_JOURNALD_H - case WLOG_APPENDER_JOURNALD: - WLog_JournaldAppender_Free(log, (wLogJournaldAppender *) appender); - break; -#endif - case WLOG_APPENDER_UDP: - WLog_UdpAppender_Free(log, (wLogUdpAppender *) appender); - break; - default: - fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type); - break; - } + appender->Free(appender); } wLogAppender* WLog_GetLogAppender(wLog* log) @@ -141,18 +49,6 @@ wLogAppender* WLog_GetLogAppender(wLog* log) return log->Appender; } -BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType) -{ - if (log->Appender) - { - WLog_Appender_Free(log, log->Appender); - log->Appender = NULL; - } - - log->Appender = WLog_Appender_New(log, logAppenderType); - return log->Appender != NULL; -} - BOOL WLog_OpenAppender(wLog* log) { int status = 0; @@ -196,3 +92,87 @@ BOOL WLog_CloseAppender(wLog* log) return status; } + +wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType) +{ + wLogAppender* appender; + + if (!log) + return NULL; + + switch (logAppenderType) + { + case WLOG_APPENDER_CONSOLE: + appender = WLog_ConsoleAppender_New(log); + break; + case WLOG_APPENDER_FILE: + appender = WLog_FileAppender_New(log); + break; + case WLOG_APPENDER_BINARY: + appender = WLog_BinaryAppender_New(log); + break; + case WLOG_APPENDER_CALLBACK: + appender = WLog_CallbackAppender_New(log); + break; +#ifdef HAVE_SYSLOG_H + case WLOG_APPENDER_SYSLOG: + appender = WLog_SyslogAppender_New(log); + break; +#endif +#ifdef HAVE_JOURNALD_H + case WLOG_APPENDER_JOURNALD: + appender = WLog_JournaldAppender_New(log); + break; +#endif + case WLOG_APPENDER_UDP: + appender = (wLogAppender*) WLog_UdpAppender_New(log); + break; + default: + fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType); + appender = NULL; + break; + } + + if (!appender) + appender = (wLogAppender*) WLog_ConsoleAppender_New(log); + + if (!appender) + return NULL; + + if (!(appender->Layout = WLog_Layout_New(log))) + { + WLog_Appender_Free(log, appender); + return NULL; + } + + InitializeCriticalSectionAndSpinCount(&appender->lock, 4000); + + return appender; +} + +BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType) +{ + if (!log) + return FALSE; + + if (log->Appender) + { + WLog_Appender_Free(log, log->Appender); + log->Appender = NULL; + } + + log->Appender = WLog_Appender_New(log, logAppenderType); + return log->Appender != NULL; +} + +BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value) +{ + if (!appender || !setting || !strlen(setting)) + return FALSE; + + if (appender->Set) + return appender->Set(appender, setting, value); + else + return FALSE; + +} diff --git a/winpr/libwinpr/utils/wlog/Appender.h b/winpr/libwinpr/utils/wlog/Appender.h index 6b9b8ee21..45aac3601 100644 --- a/winpr/libwinpr/utils/wlog/Appender.h +++ b/winpr/libwinpr/utils/wlog/Appender.h @@ -20,25 +20,21 @@ #ifndef WINPR_WLOG_APPENDER_PRIVATE_H #define WINPR_WLOG_APPENDER_PRIVATE_H -#include - -#include "wlog/FileAppender.h" -#include "wlog/BinaryAppender.h" -#include "wlog/ConsoleAppender.h" -#include "wlog/CallbackAppender.h" -#include "wlog/UdpAppender.h" - -#ifdef HAVE_SYSLOG_H -#include "wlog/SyslogAppender.h" -#endif +#include "wlog.h" +#include "FileAppender.h" +#include "ConsoleAppender.h" +#include "BinaryAppender.h" +#include "CallbackAppender.h" #ifdef HAVE_JOURNALD_H -#include "wlog/JournaldAppender.h" +#include "JournaldAppender.h" #endif +#ifdef HAVE_SYSLOG_H +#include "SyslogAppender.h" +#endif +#include "UdpAppender.h" void WLog_Appender_Free(wLog* log, wLogAppender* appender); -#include "wlog/wlog.h" - #endif /* WINPR_WLOG_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.c b/winpr/libwinpr/utils/wlog/BinaryAppender.c index 0e9241e4d..74d998bbc 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.c +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.c @@ -23,107 +23,87 @@ #include "config.h" #endif -#include - +#include "BinaryAppender.h" #include #include #include -#include #include -#include -#include "wlog/Message.h" - -#include "wlog/BinaryAppender.h" - -/** - * Binary Appender - */ - -BOOL WLog_BinaryAppender_SetOutputFileName(wLog* log, wLogBinaryAppender* appender, const char* filename) +struct _wLogBinaryAppender { - if (!appender || !filename) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_BINARY) - return FALSE; + char* FileName; + char* FilePath; + char* FullFileName; + FILE* FileDescriptor; +}; +typedef struct _wLogBinaryAppender wLogBinaryAppender; - appender->FileName = _strdup(filename); - if (!appender->FileName) - return FALSE; - return TRUE; -} - -BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* appender, const char* filepath) -{ - if (!appender || !filepath) - return FALSE; - - if (appender->Type != WLOG_APPENDER_BINARY) - return FALSE; - - appender->FilePath = _strdup(filepath); - if (!appender->FilePath) - return FALSE; - return TRUE; -} - -BOOL WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender) +static BOOL WLog_BinaryAppender_Open(wLog* log, wLogAppender* appender) { + wLogBinaryAppender* binaryAppender; if (!log || !appender) return FALSE; - if (!appender->FileName) + binaryAppender = (wLogBinaryAppender *)appender; + if (!binaryAppender->FileName) { - appender->FileName = (char*) malloc(MAX_PATH); - if (!appender->FileName) + binaryAppender->FileName = (char*) malloc(MAX_PATH); + if (!binaryAppender->FileName) return FALSE; - sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId()); + sprintf_s(binaryAppender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId()); } - if (!appender->FilePath) + if (!binaryAppender->FilePath) { - appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); - if (!appender->FilePath) + binaryAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); + if (!binaryAppender->FilePath) return FALSE; } - if (!appender->FullFileName) + if (!binaryAppender->FullFileName) { - appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); - if (!appender->FullFileName) + binaryAppender->FullFileName = GetCombinedPath(binaryAppender->FilePath, binaryAppender->FileName); + if (!binaryAppender->FullFileName) return FALSE; } - if (!PathFileExistsA(appender->FilePath)) + if (!PathFileExistsA(binaryAppender->FilePath)) { - if (!PathMakePathA(appender->FilePath, 0)) + if (!PathMakePathA(binaryAppender->FilePath, 0)) return FALSE; - UnixChangeFileMode(appender->FilePath, 0xFFFF); + UnixChangeFileMode(binaryAppender->FilePath, 0xFFFF); } - appender->FileDescriptor = fopen(appender->FullFileName, "a+"); + binaryAppender->FileDescriptor = fopen(binaryAppender->FullFileName, "a+"); - if (!appender->FileDescriptor) + if (!binaryAppender->FileDescriptor) return FALSE; return TRUE; } -BOOL WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender) +static BOOL WLog_BinaryAppender_Close(wLog* log, wLogAppender* appender) { - if (!appender->FileDescriptor) + wLogBinaryAppender* binaryAppender; + + if (!appender) + return FALSE; + + binaryAppender = (wLogBinaryAppender *)appender; + if (!binaryAppender->FileDescriptor) return TRUE; - fclose(appender->FileDescriptor); + fclose(binaryAppender->FileDescriptor); - appender->FileDescriptor = NULL; + binaryAppender->FileDescriptor = NULL; return TRUE; } -BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { FILE* fp; wStream* s; @@ -132,11 +112,14 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w int FunctionNameLength; int TextStringLength; BOOL ret = TRUE; + wLogBinaryAppender* binaryAppender; if (!log || !appender || !message) return FALSE; - fp = appender->FileDescriptor; + binaryAppender = (wLogBinaryAppender *)appender; + + fp = binaryAppender->FileDescriptor; if (!fp) return FALSE; @@ -180,17 +163,55 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w return ret; } -BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +static BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { return TRUE; } -BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) +static BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { return TRUE; } -wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log) +static BOOL WLog_BinaryAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogBinaryAppender *binaryAppender = (wLogBinaryAppender *) appender; + + if (!value || !strlen(value)) + return FALSE; + + if (!strcmp("outputfilename", setting)) + { + binaryAppender->FileName = _strdup((const char *)value); + if (!binaryAppender->FileName) + return FALSE; + } + else if (!strcmp("outputfilepath", setting)) + { + binaryAppender->FilePath = _strdup((const char *)value); + if (!binaryAppender->FilePath) + return FALSE; + } + else + return FALSE; + + return TRUE; +} + +static void WLog_BinaryAppender_Free(wLogAppender* appender) +{ + wLogBinaryAppender *binaryAppender; + if (appender) + { + binaryAppender = (wLogBinaryAppender *)appender; + free(binaryAppender->FileName); + free(binaryAppender->FilePath); + free(binaryAppender->FullFileName); + free(binaryAppender); + } +} + +wLogAppender* WLog_BinaryAppender_New(wLog* log) { wLogBinaryAppender* BinaryAppender; @@ -199,25 +220,13 @@ wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log) return NULL; BinaryAppender->Type = WLOG_APPENDER_BINARY; - BinaryAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Open; - BinaryAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Close; - BinaryAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_BinaryAppender_WriteMessage; - BinaryAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_BinaryAppender_WriteDataMessage; - BinaryAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_BinaryAppender_WriteImageMessage; + BinaryAppender->Open = WLog_BinaryAppender_Open; + BinaryAppender->Close = WLog_BinaryAppender_Close; + BinaryAppender->WriteMessage = WLog_BinaryAppender_WriteMessage; + BinaryAppender->WriteDataMessage = WLog_BinaryAppender_WriteDataMessage; + BinaryAppender->WriteImageMessage = WLog_BinaryAppender_WriteImageMessage; + BinaryAppender->Free = WLog_BinaryAppender_Free; + BinaryAppender->Set = WLog_BinaryAppender_Set; - return BinaryAppender; -} - -void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender) -{ - if (appender) - { - free(appender->FileName); - free(appender->FilePath); - free(appender->FullFileName); - free(appender); - } + return (wLogAppender *)BinaryAppender; } diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.h b/winpr/libwinpr/utils/wlog/BinaryAppender.h index 09bdf47a7..22f1075df 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.h +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_BINARY_APPENDER_PRIVATE_H #define WINPR_WLOG_BINARY_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log); -WINPR_API void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender); +WINPR_API wLogAppender* WLog_BinaryAppender_New(wLog* log); #endif /* WINPR_WLOG_BINARY_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.c b/winpr/libwinpr/utils/wlog/CallbackAppender.c index 593496b0f..8a1719ff4 100644 --- a/winpr/libwinpr/utils/wlog/CallbackAppender.c +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.c @@ -21,100 +21,114 @@ #include "config.h" #endif -#include -#include +#include "CallbackAppender.h" -#include -#include "wlog/Message.h" - -#include "wlog/CallbackAppender.h" - -/** - * Callback Appender - */ - -WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender, - CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg, - CallbackAppenderData_t data) +struct _wLogCallbackAppender { - if (!appender) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_CALLBACK) - return FALSE; + wLogCallbacks *callbacks; +}; +typedef struct _wLogCallbackAppender wLogCallbackAppender; - appender->message = msg; - appender->image = img; - appender->package = pkg; - appender->data = data; - return TRUE; -} - -BOOL WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender) +static BOOL WLog_CallbackAppender_Open(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender) +static BOOL WLog_CallbackAppender_Close(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); - if (appender->message) - { - return appender->message(message); - } + callbackAppender = (wLogCallbackAppender *)appender; + + if (callbackAppender->callbacks && callbackAppender->callbacks->message) + return callbackAppender->callbacks->message(message); else - { return FALSE; - } } -BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { - if (appender->data) - { - return appender->data(message); - } - else - { + + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; + + callbackAppender = (wLogCallbackAppender *)appender; + if (callbackAppender->callbacks && callbackAppender->callbacks->data) + return callbackAppender->callbacks->data(message); + else return FALSE; - } } -BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { - if (appender->image) - { - return appender->image(message); - } - else - { + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; + + callbackAppender = (wLogCallbackAppender *)appender; + if (callbackAppender->callbacks && callbackAppender->callbacks->image) + return callbackAppender->callbacks->image(message); + else return FALSE; - } } -BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message) +static BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { - if (appender->package) - { - return appender->package(message); - } - else - { + wLogCallbackAppender* callbackAppender; + if (!appender) + return FALSE; + + callbackAppender = (wLogCallbackAppender *)appender; + if (callbackAppender->callbacks && callbackAppender->callbacks->package) + return callbackAppender->callbacks->package(message); + else return FALSE; - } } -wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) +static BOOL WLog_CallbackAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogCallbackAppender *callbackAppender = (wLogCallbackAppender *)appender; + + if (!value || strcmp(setting, "callbacks")) + return FALSE; + + if (!(callbackAppender->callbacks = calloc(1, sizeof(wLogCallbacks)))) { + return FALSE; + } + + callbackAppender->callbacks = memcpy(callbackAppender->callbacks, value, sizeof(wLogCallbacks)); + return TRUE; +} + +static void WLog_CallbackAppender_Free(wLogAppender* appender) +{ + wLogCallbackAppender *callbackAppender; + if (!appender) { + return; + } + + callbackAppender = (wLogCallbackAppender *)appender; + + free(callbackAppender->callbacks); + free(appender); +} + +wLogAppender* WLog_CallbackAppender_New(wLog* log) { wLogCallbackAppender* CallbackAppender; @@ -124,21 +138,14 @@ wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log) CallbackAppender->Type = WLOG_APPENDER_CALLBACK; - CallbackAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Open; - CallbackAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Close; - CallbackAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_CallbackAppender_WriteMessage; - CallbackAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_CallbackAppender_WriteDataMessage; - CallbackAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_CallbackAppender_WriteImageMessage; - CallbackAppender->WritePacketMessage = - (WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_CallbackAppender_WritePacketMessage; + CallbackAppender->Open = WLog_CallbackAppender_Open; + CallbackAppender->Close = WLog_CallbackAppender_Close; + CallbackAppender->WriteMessage = WLog_CallbackAppender_WriteMessage; + CallbackAppender->WriteDataMessage = WLog_CallbackAppender_WriteDataMessage; + CallbackAppender->WriteImageMessage = WLog_CallbackAppender_WriteImageMessage; + CallbackAppender->WritePacketMessage = WLog_CallbackAppender_WritePacketMessage; + CallbackAppender->Free = WLog_CallbackAppender_Free; + CallbackAppender->Set = WLog_CallbackAppender_Set; - return CallbackAppender; -} - -void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender) -{ - free(appender); + return (wLogAppender *)CallbackAppender; } diff --git a/winpr/libwinpr/utils/wlog/CallbackAppender.h b/winpr/libwinpr/utils/wlog/CallbackAppender.h index a23153c44..2a7f7822c 100644 --- a/winpr/libwinpr/utils/wlog/CallbackAppender.h +++ b/winpr/libwinpr/utils/wlog/CallbackAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H #define WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log); -WINPR_API void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender); +wLogAppender* WLog_CallbackAppender_New(wLog* log); #endif /* WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index ba5ed71c2..4dce9fb6e 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -21,57 +21,45 @@ #include "config.h" #endif -#include -#include - -#include - -#include "wlog/Message.h" - -#include "wlog/ConsoleAppender.h" +#include "ConsoleAppender.h" +#include "Message.h" #ifdef ANDROID #include #endif -/** - * Console Appender - */ +#define WLOG_CONSOLE_DEFAULT 0 +#define WLOG_CONSOLE_STDOUT 1 +#define WLOG_CONSOLE_STDERR 2 +#define WLOG_CONSOLE_DEBUG 4 -BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream) +struct _wLogConsoleAppender { - if (!appender) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_CONSOLE) - return FALSE; + int outputStream; +}; +typedef struct _wLogConsoleAppender wLogConsoleAppender; - if (outputStream < 0) - outputStream = WLOG_CONSOLE_DEFAULT; - - if (outputStream == WLOG_CONSOLE_STDOUT) - appender->outputStream = WLOG_CONSOLE_STDOUT; - else if (outputStream == WLOG_CONSOLE_STDERR) - appender->outputStream = WLOG_CONSOLE_STDERR; - else - appender->outputStream = WLOG_CONSOLE_DEFAULT; - return TRUE; -} - -BOOL WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender) +static BOOL WLog_ConsoleAppender_Open(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender) +static BOOL WLog_ConsoleAppender_Close(wLog* log, wLogAppender* appender) { return TRUE; } -BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; + if (!appender) + return FALSE; + + wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender; + message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); @@ -124,7 +112,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, __android_log_print(level, log->Name, "%s%s", message->PrefixString, message->TextString); #else - switch(appender->outputStream) + switch(consoleAppender->outputStream) { case WLOG_CONSOLE_STDOUT: fp = stdout; @@ -155,7 +143,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, static int g_DataId = 0; -BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int DataId; char* FullFileName; @@ -172,7 +160,7 @@ BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appen static int g_ImageId = 0; -BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int ImageId; char* FullFileName; @@ -190,7 +178,7 @@ BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appe static int g_PacketId = 0; -BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message) +static BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int PacketId; char* FullFileName; @@ -210,41 +198,31 @@ BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* app return TRUE; } - -wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log) +static BOOL WLog_ConsoleAppender_Set(wLogAppender* appender, const char *setting, void *value) { - wLogConsoleAppender* ConsoleAppender; + wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender; - ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender)); + if (!value || !strlen(value)) + return FALSE; - if (!ConsoleAppender) - return NULL; + if (strcmp("outputstream", setting)) + return FALSE; - ConsoleAppender->Type = WLOG_APPENDER_CONSOLE; + if (!strcmp("stdout", value)) + consoleAppender->outputStream = WLOG_CONSOLE_STDOUT; + else if (!strcmp("stderr", value)) + consoleAppender->outputStream = WLOG_CONSOLE_STDERR; + else if (!strcmp("default", value)) + consoleAppender->outputStream = WLOG_CONSOLE_DEFAULT; + else if (!strcmp("debug", value)) + consoleAppender->outputStream = WLOG_CONSOLE_DEBUG; + else + return FALSE; - ConsoleAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Open; - ConsoleAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Close; - - ConsoleAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_ConsoleAppender_WriteMessage; - ConsoleAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_ConsoleAppender_WriteDataMessage; - ConsoleAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_ConsoleAppender_WriteImageMessage; - ConsoleAppender->WritePacketMessage = - (WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_ConsoleAppender_WritePacketMessage; - - ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT; - -#ifdef _WIN32 - if (IsDebuggerPresent()) - ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG; -#endif - - return ConsoleAppender; + return TRUE; } -void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender) +static void WLog_ConsoleAppender_Free(wLogAppender* appender) { if (appender) { @@ -256,3 +234,34 @@ void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender) free(appender); } } + +wLogAppender* WLog_ConsoleAppender_New(wLog* log) +{ + wLogConsoleAppender* ConsoleAppender; + + ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender)); + + if (!ConsoleAppender) + return NULL; + + ConsoleAppender->Type = WLOG_APPENDER_CONSOLE; + + ConsoleAppender->Open = WLog_ConsoleAppender_Open; + ConsoleAppender->Close = WLog_ConsoleAppender_Close; + ConsoleAppender->WriteMessage = WLog_ConsoleAppender_WriteMessage; + ConsoleAppender->WriteDataMessage = WLog_ConsoleAppender_WriteDataMessage; + ConsoleAppender->WriteImageMessage = WLog_ConsoleAppender_WriteImageMessage; + ConsoleAppender->WritePacketMessage = WLog_ConsoleAppender_WritePacketMessage; + ConsoleAppender->Set = WLog_ConsoleAppender_Set; + ConsoleAppender->Free = WLog_ConsoleAppender_Free; + + ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT; + +#ifdef _WIN32 + if (IsDebuggerPresent()) + ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG; +#endif + + return (wLogAppender *)ConsoleAppender; +} + diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.h b/winpr/libwinpr/utils/wlog/ConsoleAppender.h index e5871e847..e6ff1185c 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.h +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H #define WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log); -WINPR_API void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender); +wLogAppender* WLog_ConsoleAppender_New(wLog* log); #endif /* WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/DataMessage.c b/winpr/libwinpr/utils/wlog/DataMessage.c index f27bbdf77..ce4a1f60a 100644 --- a/winpr/libwinpr/utils/wlog/DataMessage.c +++ b/winpr/libwinpr/utils/wlog/DataMessage.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include +#include "wlog.h" #include "wlog/DataMessage.h" diff --git a/winpr/libwinpr/utils/wlog/DataMessage.h b/winpr/libwinpr/utils/wlog/DataMessage.h index 3b30ae9a7..f91a42c47 100644 --- a/winpr/libwinpr/utils/wlog/DataMessage.h +++ b/winpr/libwinpr/utils/wlog/DataMessage.h @@ -20,10 +20,6 @@ #ifndef WINPR_WLOG_DATA_MESSAGE_PRIVATE_H #define WINPR_WLOG_DATA_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" - BOOL WLog_DataMessage_Write(char* filename, void* data, int length); #endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index ad5a3aec4..576841611 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -21,30 +21,28 @@ #include "config.h" #endif +#include "FileAppender.h" +#include "Message.h" + #include #include #include #include -#include -#include - -#include "wlog/Message.h" - -#include "wlog/FileAppender.h" - -/** - * File Appender - */ - -BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename) +struct _wLogFileAppender { - if (!appender || !filename) - return FALSE; + WLOG_APPENDER_COMMON(); - if (appender->Type != WLOG_APPENDER_FILE) - return FALSE; + char* FileName; + char* FilePath; + char* FullFileName; + FILE* FileDescriptor; +}; +typedef struct _wLogFileAppender wLogFileAppender; + +static BOOL WLog_FileAppender_SetOutputFileName(wLogFileAppender* appender, const char* filename) +{ appender->FileName = _strdup(filename); if (!appender->FileName) return FALSE; @@ -52,14 +50,8 @@ BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, return TRUE; } -BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath) +static BOOL WLog_FileAppender_SetOutputFilePath(wLogFileAppender* appender, const char* filepath) { - if (!appender || !filepath) - return FALSE; - - if (appender->Type != WLOG_APPENDER_FILE) - return FALSE; - appender->FilePath = _strdup(filepath); if (!appender->FilePath) return FALSE; @@ -67,73 +59,83 @@ BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, return TRUE; } -BOOL WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender) +static BOOL WLog_FileAppender_Open(wLog* log, wLogAppender* appender) { + wLogFileAppender *fileAppender; + if (!log || !appender) return FALSE; - if (!appender->FilePath) + fileAppender = (wLogFileAppender *)appender; + + if (!fileAppender->FilePath) { - appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); - if (!appender->FilePath) + fileAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog"); + if (!fileAppender->FilePath) return FALSE; } - if (!appender->FileName) + if (!fileAppender->FileName) { - appender->FileName = (char*) malloc(MAX_PATH); - if (!appender->FileName) + fileAppender->FileName = (char*) malloc(MAX_PATH); + if (!fileAppender->FileName) return FALSE; - sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId()); + sprintf_s(fileAppender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId()); } - if (!appender->FullFileName) + if (!fileAppender->FullFileName) { - appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName); - if (!appender->FullFileName) + fileAppender->FullFileName = GetCombinedPath(fileAppender->FilePath, fileAppender->FileName); + if (!fileAppender->FullFileName) return FALSE; } - if (!PathFileExistsA(appender->FilePath)) + if (!PathFileExistsA(fileAppender->FilePath)) { - if (!PathMakePathA(appender->FilePath, 0)) + if (!PathMakePathA(fileAppender->FilePath, 0)) return FALSE; - UnixChangeFileMode(appender->FilePath, 0xFFFF); + UnixChangeFileMode(fileAppender->FilePath, 0xFFFF); } - appender->FileDescriptor = fopen(appender->FullFileName, "a+"); + fileAppender->FileDescriptor = fopen(fileAppender->FullFileName, "a+"); - if (!appender->FileDescriptor) + if (!fileAppender->FileDescriptor) return FALSE; return TRUE; } -BOOL WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender) +static BOOL WLog_FileAppender_Close(wLog* log, wLogAppender* appender) { + wLogFileAppender *fileAppender; if (!log || !appender) return FALSE; - if (!appender->FileDescriptor) + fileAppender = (wLogFileAppender *)appender; + + if (!fileAppender->FileDescriptor) return TRUE; - fclose(appender->FileDescriptor); + fclose(fileAppender->FileDescriptor); - appender->FileDescriptor = NULL; + fileAppender->FileDescriptor = NULL; return TRUE; } -BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +static BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogFileAppender *fileAppender; if (!log || !appender || !message) return FALSE; - fp = appender->FileDescriptor; + fileAppender = (wLogFileAppender *)appender; + + fp = fileAppender->FileDescriptor; if (!fp) return FALSE; @@ -150,7 +152,7 @@ BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogM static int g_DataId = 0; -BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +static BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int DataId; char* FullFileName; @@ -170,7 +172,7 @@ BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, w static int g_ImageId = 0; -int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message) +static int WLog_FileAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int ImageId; char* FullFileName; @@ -189,7 +191,38 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w return TRUE; } -wLogFileAppender* WLog_FileAppender_New(wLog* log) +static BOOL WLog_FileAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogFileAppender *fileAppender = (wLogFileAppender *) appender; + + if (!value || !strlen(value)) + return FALSE; + + if (!strcmp("outputfilename", setting)) + return WLog_FileAppender_SetOutputFileName(fileAppender, (const char *)value); + else if (!strcmp("outputfilepath", setting)) + return WLog_FileAppender_SetOutputFilePath(fileAppender, (const char *)value); + else + return FALSE; + + return TRUE; +} + +static void WLog_FileAppender_Free(wLogAppender* appender) +{ + wLogFileAppender* fileAppender = NULL; + + if (appender) + { + fileAppender = (wLogFileAppender *)appender; + free(fileAppender->FileName); + free(fileAppender->FilePath); + free(fileAppender->FullFileName); + free(fileAppender); + } +} + +wLogAppender* WLog_FileAppender_New(wLog* log) { LPSTR env; LPCSTR name; @@ -203,14 +236,13 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) FileAppender->Type = WLOG_APPENDER_FILE; - FileAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Open; - FileAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Close; - FileAppender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_FileAppender_WriteMessage; - FileAppender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_FileAppender_WriteDataMessage; - FileAppender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_FileAppender_WriteImageMessage; + FileAppender->Open = WLog_FileAppender_Open; + FileAppender->Close = WLog_FileAppender_Close; + FileAppender->WriteMessage = WLog_FileAppender_WriteMessage; + FileAppender->WriteDataMessage = WLog_FileAppender_WriteDataMessage; + FileAppender->WriteImageMessage = WLog_FileAppender_WriteImageMessage; + FileAppender->Free = WLog_FileAppender_Free; + FileAppender->Set = WLog_FileAppender_Set; name = "WLOG_FILEAPPENDER_OUTPUT_FILE_PATH"; nSize = GetEnvironmentVariableA(name, NULL, 0); @@ -221,7 +253,7 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) goto error_free; nSize = GetEnvironmentVariableA(name, env, nSize); - status = WLog_FileAppender_SetOutputFilePath(log, FileAppender, env); + status = WLog_FileAppender_SetOutputFilePath(FileAppender, env); free(env); if (!status) @@ -236,15 +268,15 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) if (!env) goto error_output_file_name; - nSize = GetEnvironmentVariableA(name, env, nSize); - status = WLog_FileAppender_SetOutputFileName(log, FileAppender, env); + GetEnvironmentVariableA(name, env, nSize); + status = WLog_FileAppender_SetOutputFileName(FileAppender, env); free(env); if (!status) goto error_output_file_name; } - return FileAppender; + return (wLogAppender *)FileAppender; error_output_file_name: free(FileAppender->FilePath); @@ -252,14 +284,3 @@ error_free: free(FileAppender); return NULL; } - -void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender) -{ - if (appender) - { - free(appender->FileName); - free(appender->FilePath); - free(appender->FullFileName); - free(appender); - } -} diff --git a/winpr/libwinpr/utils/wlog/FileAppender.h b/winpr/libwinpr/utils/wlog/FileAppender.h index de51249df..6f2f96eac 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.h +++ b/winpr/libwinpr/utils/wlog/FileAppender.h @@ -20,11 +20,8 @@ #ifndef WINPR_WLOG_FILE_APPENDER_PRIVATE_H #define WINPR_WLOG_FILE_APPENDER_PRIVATE_H -#include +#include "wlog.h" -#include "wlog/wlog.h" - -WINPR_API wLogFileAppender* WLog_FileAppender_New(wLog* log); -WINPR_API void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender); +wLogAppender* WLog_FileAppender_New(wLog* log); #endif /* WINPR_WLOG_FILE_APPENDER_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/ImageMessage.c b/winpr/libwinpr/utils/wlog/ImageMessage.c index c09a7eb2a..94da680e3 100644 --- a/winpr/libwinpr/utils/wlog/ImageMessage.c +++ b/winpr/libwinpr/utils/wlog/ImageMessage.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include +#include "wlog.h" #include #include "wlog/ImageMessage.h" diff --git a/winpr/libwinpr/utils/wlog/ImageMessage.h b/winpr/libwinpr/utils/wlog/ImageMessage.h index 84efa0e46..11ce9e977 100644 --- a/winpr/libwinpr/utils/wlog/ImageMessage.h +++ b/winpr/libwinpr/utils/wlog/ImageMessage.h @@ -20,10 +20,6 @@ #ifndef WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H #define WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" - BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp); #endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */ diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index 4b8423018..a64756260 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -22,59 +22,52 @@ #include "config.h" #endif +#include "JournaldAppender.h" + #include #include #include #include #include -#include -#include -#include "wlog/Message.h" -#include "wlog/JournaldAppender.h" - -BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id) +struct _wLogJournaldAppender { - if (appender->identifier) - free(appender->identifier); + WLOG_APPENDER_COMMON(); + char *identifier; + FILE *stream; +}; +typedef struct _wLogJournaldAppender wLogJournaldAppender; - if (appender->stream) - { - fclose(appender->stream); - appender->stream = NULL; - } - - return ((appender->identifier = _strdup(id)) != NULL); -} - -static BOOL WLog_JournaldAppender_Open(wLog* log, wLogJournaldAppender* appender) +static BOOL WLog_JournaldAppender_Open(wLog* log, wLogAppender* appender) { int fd; + wLogJournaldAppender *journaldAppender; if (!log || !appender) return FALSE; - if (appender->stream) + journaldAppender = (wLogJournaldAppender*)appender; + if (journaldAppender->stream) return TRUE; - fd = sd_journal_stream_fd(appender->identifier, LOG_INFO, 1); + fd = sd_journal_stream_fd(journaldAppender->identifier, LOG_INFO, 1); if (fd < 0) return FALSE; - appender->stream = fdopen(fd, "w"); - if (!appender->stream) + journaldAppender->stream = fdopen(fd, "w"); + if (!journaldAppender->stream) { close(fd); return FALSE; } - setbuffer(appender->stream, NULL, 0); + setbuffer(journaldAppender->stream, NULL, 0); return TRUE; } -static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appender) +static BOOL WLog_JournaldAppender_Close(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -82,13 +75,16 @@ static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appende return TRUE; } -static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { char *formatStr; + wLogJournaldAppender* journaldAppender; if (!log || !appender || !message) return FALSE; + journaldAppender = (wLogJournaldAppender *)appender; + switch (message->Level) { case WLOG_TRACE: @@ -114,11 +110,11 @@ static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* return FALSE; } - fprintf(appender->stream, formatStr, message->TextString); + fprintf(journaldAppender->stream, formatStr, message->TextString); return TRUE; } -static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -126,7 +122,7 @@ static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppend return TRUE; } -static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message) +static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -135,7 +131,40 @@ static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppen return TRUE; } -wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) +static BOOL WLog_JournaldAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogJournaldAppender* journaldAppender = (wLogJournaldAppender *)appender; + + if (!value || !strlen(value)) + return FALSE; + + if (strcmp("identifier", setting)) + return FALSE; + + /* If the stream is already open the identifier can't be changed */ + if (journaldAppender->stream) + return FALSE; + + if (journaldAppender->identifier) + free(journaldAppender->identifier); + + return ((journaldAppender->identifier = _strdup((const char *)value)) != NULL); +} + +static void WLog_JournaldAppender_Free(wLogAppender* appender) +{ + wLogJournaldAppender *journaldAppender; + if (appender) + { + journaldAppender = (wLogJournaldAppender*)appender; + if (journaldAppender->stream) + fclose(journaldAppender->stream); + free(journaldAppender->identifier); + free(journaldAppender); + } +} + +wLogAppender* WLog_JournaldAppender_New(wLog* log) { wLogJournaldAppender* appender; DWORD nSize; @@ -146,15 +175,13 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) return NULL; appender->Type = WLOG_APPENDER_JOURNALD; - - appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Open; - appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Close; - appender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_JournaldAppender_WriteMessage; - appender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_JournaldAppender_WriteDataMessage; - appender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_JournaldAppender_WriteImageMessage; + appender->Open = WLog_JournaldAppender_Open; + appender->Close = WLog_JournaldAppender_Close; + appender->WriteMessage = WLog_JournaldAppender_WriteMessage; + appender->WriteDataMessage = WLog_JournaldAppender_WriteDataMessage; + appender->WriteImageMessage = WLog_JournaldAppender_WriteImageMessage; + appender->Set = WLog_JournaldAppender_Set; + appender->Free = WLog_JournaldAppender_Free; name = "WLOG_JOURNALD_ID"; nSize = GetEnvironmentVariableA(name, NULL, 0); @@ -166,7 +193,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) GetEnvironmentVariableA(name, appender->identifier, nSize); - if (!WLog_JournaldAppender_Open(log, appender)) + if (!WLog_JournaldAppender_Open(log, (wLogAppender *)appender)) goto error_open; } else @@ -176,7 +203,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log) goto error_env_malloc; } - return appender; + return (wLogAppender *)appender; error_open: free(appender->identifier); @@ -184,14 +211,3 @@ error_env_malloc: free(appender); return NULL; } - -void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender) -{ - if (appender) - { - if (appender->stream) - fclose(appender->stream); - free(appender->identifier); - free(appender); - } -} diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.h b/winpr/libwinpr/utils/wlog/JournaldAppender.h index 9f2072d49..49223c516 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.h +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.h @@ -24,13 +24,8 @@ #ifndef WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ #define WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ -#include - -#include "wlog/wlog.h" - -WINPR_API wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log); -WINPR_API void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender); -WINPR_API BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id); +#include "wlog.h" +wLogAppender* WLog_JournaldAppender_New(wLog* log); #endif /* WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/Layout.c b/winpr/libwinpr/utils/wlog/Layout.c index 741f7cb19..ddca2133e 100644 --- a/winpr/libwinpr/utils/wlog/Layout.c +++ b/winpr/libwinpr/utils/wlog/Layout.c @@ -30,7 +30,7 @@ #include #include -#include +#include "wlog.h" #include "wlog/Layout.h" diff --git a/winpr/libwinpr/utils/wlog/Layout.h b/winpr/libwinpr/utils/wlog/Layout.h index 81683ac76..df31d4d6d 100644 --- a/winpr/libwinpr/utils/wlog/Layout.h +++ b/winpr/libwinpr/utils/wlog/Layout.h @@ -20,7 +20,18 @@ #ifndef WINPR_WLOG_LAYOUT_PRIVATE_H #define WINPR_WLOG_LAYOUT_PRIVATE_H -#include +#include "wlog.h" + +/** + * Log Layout + */ + +struct _wLogLayout +{ + DWORD Type; + + LPSTR FormatString; +}; wLogLayout* WLog_Layout_New(wLog* log); void WLog_Layout_Free(wLog* log, wLogLayout* layout); diff --git a/winpr/libwinpr/utils/wlog/Message.c b/winpr/libwinpr/utils/wlog/Message.c index c8567b92e..77f94d7df 100644 --- a/winpr/libwinpr/utils/wlog/Message.c +++ b/winpr/libwinpr/utils/wlog/Message.c @@ -25,9 +25,9 @@ #include #include -#include +#include "wlog.h" -#include "wlog/Message.h" +#include "Message.h" char* WLog_Message_GetOutputFileName(int id, const char* ext) { diff --git a/winpr/libwinpr/utils/wlog/Message.h b/winpr/libwinpr/utils/wlog/Message.h index 4ad0227c4..c65b33cf0 100644 --- a/winpr/libwinpr/utils/wlog/Message.h +++ b/winpr/libwinpr/utils/wlog/Message.h @@ -20,14 +20,9 @@ #ifndef WINPR_WLOG_MESSAGE_PRIVATE_H #define WINPR_WLOG_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" - -#include "wlog/TextMessage.h" -#include "wlog/DataMessage.h" -#include "wlog/ImageMessage.h" -#include "wlog/PacketMessage.h" +#include "DataMessage.h" +#include "ImageMessage.h" +#include "PacketMessage.h" char* WLog_Message_GetOutputFileName(int id, const char* ext); diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.c b/winpr/libwinpr/utils/wlog/PacketMessage.c index e3a063165..9bcddbbe1 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.c +++ b/winpr/libwinpr/utils/wlog/PacketMessage.c @@ -23,7 +23,7 @@ #include "config.h" #endif -#include +#include "wlog.h" #include "wlog/PacketMessage.h" diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.h b/winpr/libwinpr/utils/wlog/PacketMessage.h index 1ee0dc241..e0b73526a 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.h +++ b/winpr/libwinpr/utils/wlog/PacketMessage.h @@ -20,9 +20,7 @@ #ifndef WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H #define WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H -#include - -#include "wlog/wlog.h" +#include "wlog.h" #define PCAP_MAGIC_NUMBER 0xA1B2C3D4 diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.c b/winpr/libwinpr/utils/wlog/SyslogAppender.c index 169c5ae9e..7b86c35d1 100644 --- a/winpr/libwinpr/utils/wlog/SyslogAppender.c +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.c @@ -2,7 +2,8 @@ * WinPR: Windows Portable Runtime * WinPR Logger * - * Copyright 2013 David FORT + * Copyright © 2015 Thincast Technologies GmbH + * Copyright © 2015 David FORT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +22,14 @@ #include "config.h" #endif +#include "SyslogAppender.h" #include -#include -#include -#include - -#include - -#include "wlog/Message.h" -#include "wlog/SyslogAppender.h" +struct _wLogSyslogAppender +{ + WLOG_APPENDER_COMMON(); +}; +typedef struct _wLogSyslogAppender wLogSyslogAppender; static int getSyslogLevel(DWORD level) { @@ -53,7 +52,7 @@ static int getSyslogLevel(DWORD level) } } -static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) +static BOOL WLog_SyslogAppender_Open(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -61,7 +60,7 @@ static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender) return TRUE; } -static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) +static BOOL WLog_SyslogAppender_Close(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -69,7 +68,7 @@ static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender) return TRUE; } -static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int syslogLevel; @@ -83,7 +82,7 @@ static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appe return TRUE; } -static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int syslogLevel; @@ -97,7 +96,7 @@ static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* return TRUE; } -static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message) +static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int syslogLevel; @@ -111,7 +110,12 @@ static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* return TRUE; } -wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) +void WLog_SyslogAppender_Free(wLogAppender* appender) +{ + free(appender); +} + +wLogAppender* WLog_SyslogAppender_New(wLog* log) { wLogSyslogAppender* appender; @@ -121,20 +125,12 @@ wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log) appender->Type = WLOG_APPENDER_SYSLOG; - appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Open; - appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Close; - appender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_SyslogAppender_WriteMessage; - appender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_SyslogAppender_WriteDataMessage; - appender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_SyslogAppender_WriteImageMessage; + appender->Open = WLog_SyslogAppender_Open; + appender->Close = WLog_SyslogAppender_Close; + appender->WriteMessage = WLog_SyslogAppender_WriteMessage; + appender->WriteDataMessage = WLog_SyslogAppender_WriteDataMessage; + appender->WriteImageMessage = WLog_SyslogAppender_WriteImageMessage; + appender->Free = WLog_SyslogAppender_Free; - return appender; -} - -void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender) -{ - if (appender) - free(appender); + return (wLogAppender*)appender; } diff --git a/winpr/libwinpr/utils/wlog/SyslogAppender.h b/winpr/libwinpr/utils/wlog/SyslogAppender.h index 2ce6b527c..be6b872be 100644 --- a/winpr/libwinpr/utils/wlog/SyslogAppender.h +++ b/winpr/libwinpr/utils/wlog/SyslogAppender.h @@ -24,12 +24,8 @@ #ifndef WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ #define WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ -#include - -#include "wlog/wlog.h" - -WINPR_API wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log); -WINPR_API void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender); +#include "wlog.h" +wLogAppender* WLog_SyslogAppender_New(wLog* log); #endif /* WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/TextMessage.c b/winpr/libwinpr/utils/wlog/TextMessage.c index e5f110896..f127360d3 100644 --- a/winpr/libwinpr/utils/wlog/TextMessage.c +++ b/winpr/libwinpr/utils/wlog/TextMessage.c @@ -21,10 +21,6 @@ #include "config.h" #endif -#include - -#include "wlog/TextMessage.h" - void wlog_TextMessage_dummy() { /* avoid no symbol ranlib warning */ diff --git a/winpr/libwinpr/utils/wlog/TextMessage.h b/winpr/libwinpr/utils/wlog/TextMessage.h deleted file mode 100644 index 29b02065f..000000000 --- a/winpr/libwinpr/utils/wlog/TextMessage.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * WinPR: Windows Portable Runtime - * WinPR Logger - * - * Copyright 2013 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H -#define WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H - -#include - -#include "wlog/wlog.h" - - - -#endif /* WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H */ - diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c index bc161d37b..76c43bcad 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.c +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -25,39 +25,42 @@ #include #include -#include -#include +#include "wlog.h" -#include "wlog/Message.h" -#include "wlog/UdpAppender.h" -#ifndef _WIN32 -#include -#include -#include -#endif - -static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender) +struct _wLogUdpAppender { + WLOG_APPENDER_COMMON(); + char *host; + struct sockaddr targetAddr; + int targetAddrLen; + SOCKET sock; +}; +typedef struct _wLogUdpAppender wLogUdpAppender; + +static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender) +{ + wLogUdpAppender *udpAppender; char addressString[256]; struct addrinfo hints; struct addrinfo* result; int status, addrLen; char *colonPos; - if (!appender) return FALSE; - if (appender->targetAddrLen) /* already opened */ + udpAppender = (wLogUdpAppender*)appender; + + if (udpAppender->targetAddrLen) /* already opened */ return TRUE; - colonPos = strchr(appender->host, ':'); + colonPos = strchr(udpAppender->host, ':'); if (!colonPos) return FALSE; - addrLen = colonPos - appender->host; - memcpy(addressString, appender->host, addrLen); + addrLen = colonPos - udpAppender->host; + memcpy(addressString, udpAppender->host, addrLen); addressString[addrLen] = '\0'; ZeroMemory(&hints, sizeof(hints)); @@ -68,31 +71,19 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender) if (status != 0) return FALSE; - if (result->ai_addrlen > sizeof(appender->targetAddr)) + if (result->ai_addrlen > sizeof(udpAppender->targetAddr)) { freeaddrinfo(result); return FALSE; } - memcpy(&appender->targetAddr, result->ai_addr, result->ai_addrlen); - appender->targetAddrLen = result->ai_addrlen; - + memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen); + udpAppender->targetAddrLen = result->ai_addrlen; return TRUE; } -BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host) -{ - - appender->targetAddrLen = 0; - if (appender->host) - free(appender->host); - - appender->host = _strdup(host); - return (appender->host != NULL) && WLog_UdpAppender_Open(NULL, appender); -} - -static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender) +static BOOL WLog_UdpAppender_Close(wLog* log, wLogAppender* appender) { if (!log || !appender) return FALSE; @@ -100,28 +91,32 @@ static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender) return TRUE; } -static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogUdpAppender *udpAppender; + if (!log || !appender || !message) return FALSE; + udpAppender = (wLogUdpAppender *)appender; + message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); - _sendto(appender->sock, message->PrefixString, strlen(message->PrefixString), - 0, &appender->targetAddr, appender->targetAddrLen); + _sendto(udpAppender->sock, message->PrefixString, strlen(message->PrefixString), + 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); - _sendto(appender->sock, message->TextString, strlen(message->TextString), - 0, &appender->targetAddr, appender->targetAddrLen); + _sendto(udpAppender->sock, message->TextString, strlen(message->TextString), + 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); - _sendto(appender->sock, "\n", 1, 0, &appender->targetAddr, appender->targetAddrLen); + _sendto(udpAppender->sock, "\n", 1, 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); return TRUE; } -static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -129,7 +124,7 @@ static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* append return TRUE; } -static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message) +static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { if (!log || !appender || !message) return FALSE; @@ -138,7 +133,41 @@ static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appen return TRUE; } -wLogUdpAppender* WLog_UdpAppender_New(wLog* log) +static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char *setting, void *value) +{ + wLogUdpAppender *udpAppender = (wLogUdpAppender *)appender; + + if (!value || !strlen(value)) + return FALSE; + + if (strcmp("target", setting)) + return FALSE; + + udpAppender->targetAddrLen = 0; + if (udpAppender->host) + free(udpAppender->host); + + udpAppender->host = _strdup((const char *)value); + return (udpAppender->host != NULL) && WLog_UdpAppender_Open(NULL, appender); +} + +static void WLog_UdpAppender_Free(wLogAppender* appender) +{ + wLogUdpAppender* udpAppender; + if (appender) + { + udpAppender = (wLogUdpAppender *)appender; + if (udpAppender->sock != INVALID_SOCKET) + { + closesocket(udpAppender->sock); + udpAppender->sock = INVALID_SOCKET; + } + free(udpAppender->host); + free(udpAppender); + } +} + +wLogAppender* WLog_UdpAppender_New(wLog* log) { wLogUdpAppender* appender; DWORD nSize; @@ -150,14 +179,13 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) appender->Type = WLOG_APPENDER_UDP; - appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Open; - appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Close; - appender->WriteMessage = - (WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_UdpAppender_WriteMessage; - appender->WriteDataMessage = - (WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_UdpAppender_WriteDataMessage; - appender->WriteImageMessage = - (WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_UdpAppender_WriteImageMessage; + appender->Open = WLog_UdpAppender_Open; + appender->Close = WLog_UdpAppender_Close; + appender->WriteMessage = WLog_UdpAppender_WriteMessage; + appender->WriteDataMessage = WLog_UdpAppender_WriteDataMessage; + appender->WriteImageMessage = WLog_UdpAppender_WriteImageMessage; + appender->Free = WLog_UdpAppender_Free; + appender->Set = WLog_UdpAppender_Set; appender->sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (appender->sock == INVALID_SOCKET) @@ -173,7 +201,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) GetEnvironmentVariableA(name, appender->host, nSize); - if (!WLog_UdpAppender_Open(log, appender)) + if (!WLog_UdpAppender_Open(log, (wLogAppender *)appender)) goto error_open; } else @@ -183,7 +211,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log) goto error_host_alloc; } - return appender; + return (wLogAppender*)appender; error_open: free(appender->host); @@ -193,17 +221,3 @@ error_sock: free(appender); return NULL; } - -void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender) -{ - if (appender) - { - if (appender->sock != INVALID_SOCKET) - { - closesocket(appender->sock); - appender->sock = INVALID_SOCKET; - } - free(appender->host); - free(appender); - } -} diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.h b/winpr/libwinpr/utils/wlog/UdpAppender.h index cd25345f4..c2d99a93e 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.h +++ b/winpr/libwinpr/utils/wlog/UdpAppender.h @@ -28,8 +28,6 @@ #include "wlog/wlog.h" -WINPR_API wLogUdpAppender* WLog_UdpAppender_New(wLog* log); -WINPR_API void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender); -WINPR_API BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host); +wLogAppender* WLog_UdpAppender_New(wLog* log); #endif /* WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ */ diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 123fe6384..5f2a1bb7b 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -33,11 +33,16 @@ #include #endif -#include +#include "wlog.h" -#include "wlog/wlog.h" -#include "../../log.h" +struct _wLogFilter +{ + DWORD Level; + LPSTR* Names; + DWORD NameCount; +}; +typedef struct _wLogFilter wLogFilter; /** * References for general logging concepts: diff --git a/winpr/libwinpr/utils/wlog/wlog.h b/winpr/libwinpr/utils/wlog/wlog.h index 737a18b01..5f8dd55c9 100644 --- a/winpr/libwinpr/utils/wlog/wlog.h +++ b/winpr/libwinpr/utils/wlog/wlog.h @@ -25,9 +25,62 @@ #define WLOG_MAX_PREFIX_SIZE 512 #define WLOG_MAX_STRING_SIZE 8192 + +typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender); +typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender); +typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message); +typedef BOOL (*WLOG_APPENDER_SET)(wLogAppender* appender, const char *setting, void *value); +typedef void (*WLOG_APPENDER_FREE)(wLogAppender* appender); + +#define WLOG_APPENDER_COMMON() \ + DWORD Type; \ + DWORD State; \ + wLogLayout* Layout; \ + CRITICAL_SECTION lock; \ + BOOL recursive; \ + void* TextMessageContext; \ + void* DataMessageContext; \ + void* ImageMessageContext; \ + void* PacketMessageContext; \ + WLOG_APPENDER_OPEN_FN Open; \ + WLOG_APPENDER_CLOSE_FN Close; \ + WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \ + WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \ + WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \ + WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage; \ + WLOG_APPENDER_FREE Free; \ + WLOG_APPENDER_SET Set + + +struct _wLogAppender +{ + WLOG_APPENDER_COMMON(); +}; + +struct _wLog +{ + LPSTR Name; + DWORD Level; + + BOOL IsRoot; + LPSTR* Names; + DWORD NameCount; + wLogAppender* Appender; + + wLog* Parent; + wLog** Children; + DWORD ChildrenCount; + DWORD ChildrenSize; +}; + + BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message); #include "wlog/Layout.h" #include "wlog/Appender.h" + #endif /* WINPR_WLOG_PRIVATE_H */ From 67368b2ec716c118301e37796311be7841ad8032 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 9 Nov 2015 18:27:38 +0100 Subject: [PATCH 075/220] Adapt error level for debug messages When using xfreerdp a regular invocation should really only report grave problems as error. "Regular" messages should be either info or even debug. --- client/X11/xf_window.c | 2 +- winpr/libwinpr/utils/sam.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 28f8bc8f1..95c29a066 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -239,7 +239,7 @@ BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int leng if (actual_type == None) { - WLog_ERR(TAG, "Property %lu does not exist", property); + WLog_INFO(TAG, "Property %lu does not exist", property); return FALSE; } diff --git a/winpr/libwinpr/utils/sam.c b/winpr/libwinpr/utils/sam.c index 08c5b1441..d097c0a26 100644 --- a/winpr/libwinpr/utils/sam.c +++ b/winpr/libwinpr/utils/sam.c @@ -70,7 +70,7 @@ WINPR_SAM* SamOpen(BOOL read_only) sam->fp = fp; } else - WLog_ERR(TAG, "Could not open SAM file!"); + WLog_DBG(TAG, "Could not open SAM file!"); return sam; } From 0cdb4f792490cdc50f10454e7b6ac0f8e10109a8 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 9 Nov 2015 19:26:34 +0100 Subject: [PATCH 076/220] Fix compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc (Debian 4.9.2-10) 4.9.2 winpr/libwinpr/thread/argv.c: In function ‘CommandLineToArgvA’: winpr/libwinpr/thread/argv.c:94:6: warning: unused variable ‘index’ [-Wunused-variable] int index; winpr/libwinpr/file/test/TestFileGetStdHandle.c: In function ‘TestFileGetStdHandle’: winpr/libwinpr/file/test/TestFileGetStdHandle.c:44:2: warning: implicit declaration of function ‘CloseHandle’ [-Wimplicit-function-declaration] CloseHandle(stdout); ^ libfreerdp/codec/test/TestFreeRDPRegion.c: In function ‘test_norbert2_case’: libfreerdp/codec/test/TestFreeRDPRegion.c:697:6: warning: unused variable ‘i’ [-Wunused-variable] int i; channels/cliprdr/server/cliprdr_main.c: In function ‘cliprdr_server_receive_format_list’: channels/cliprdr/server/cliprdr_main.c:636:24: warning: unused variable ‘cliprdr’ [-Wunused-variable] CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; ^ channels/cliprdr/server/cliprdr_main.c: In function ‘cliprdr_server_init’: channels/cliprdr/server/cliprdr_main.c:1097:24: warning: unused variable ‘cliprdr’ [-Wunused-variable] CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; --- channels/cliprdr/server/cliprdr_main.c | 2 -- libfreerdp/codec/test/TestFreeRDPRegion.c | 1 - winpr/libwinpr/file/test/TestFileGetStdHandle.c | 3 ++- winpr/libwinpr/thread/argv.c | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index b082c830e..a73b2b98c 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -633,7 +633,6 @@ static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context, wS WCHAR* wszFormatName; CLIPRDR_FORMAT* formats = NULL; CLIPRDR_FORMAT_LIST formatList; - CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; UINT error = CHANNEL_RC_OK; dataLen = header->dataLen; @@ -1094,7 +1093,6 @@ static UINT cliprdr_server_init(CliprdrServerContext* context) CLIPRDR_CAPABILITIES capabilities; CLIPRDR_MONITOR_READY monitorReady; CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet; - CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; UINT error; ZeroMemory(&capabilities, sizeof(capabilities)); diff --git a/libfreerdp/codec/test/TestFreeRDPRegion.c b/libfreerdp/codec/test/TestFreeRDPRegion.c index 1694baa59..5530d96bf 100644 --- a/libfreerdp/codec/test/TestFreeRDPRegion.c +++ b/libfreerdp/codec/test/TestFreeRDPRegion.c @@ -694,7 +694,6 @@ static int test_norbert2_case() { int retCode = -1; const RECTANGLE_16 *rects; int nbRects = 0; - int i; RECTANGLE_16 rect1 = { 464, 696, 476, 709 }; RECTANGLE_16 rect2 = { 0, 0, 1024, 32 }; diff --git a/winpr/libwinpr/file/test/TestFileGetStdHandle.c b/winpr/libwinpr/file/test/TestFileGetStdHandle.c index 07d00f8c3..225434f29 100644 --- a/winpr/libwinpr/file/test/TestFileGetStdHandle.c +++ b/winpr/libwinpr/file/test/TestFileGetStdHandle.c @@ -20,6 +20,7 @@ */ #include +#include #include #include @@ -44,4 +45,4 @@ int TestFileGetStdHandle(int argc, char* argv[]) CloseHandle(stdout); return 0; -} \ No newline at end of file +} diff --git a/winpr/libwinpr/thread/argv.c b/winpr/libwinpr/thread/argv.c index ad96da236..6ca2ab527 100644 --- a/winpr/libwinpr/thread/argv.c +++ b/winpr/libwinpr/thread/argv.c @@ -91,7 +91,6 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) { char* p; - int index; int length; char* pBeg; char* pEnd; From 57f952bbbcf31b411b2b7351ffa398471da43af6 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 9 Nov 2015 19:37:02 +0100 Subject: [PATCH 077/220] wlog: fix android build --- winpr/libwinpr/utils/wlog/wlog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 5f2a1bb7b..8a3416448 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -31,6 +31,7 @@ #if defined(ANDROID) #include +#include "../log.h" #endif #include "wlog.h" From 25137988feb19bc72d91d1bd379ef44e1d272c2d Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 9 Nov 2015 19:47:51 +0100 Subject: [PATCH 078/220] wlog: fix build on windows --- winpr/libwinpr/utils/wlog/ConsoleAppender.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index 4dce9fb6e..49cd94f81 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -65,7 +65,7 @@ static BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogAppender* appender, WLog_Layout_GetMessagePrefix(log, appender->Layout, message); #ifdef _WIN32 - if (appender->outputStream == WLOG_CONSOLE_DEBUG) + if (consoleAppender->outputStream == WLOG_CONSOLE_DEBUG) { char MessageString[4096]; From 59cc6c41179e00f1af35a7c74f5e0e7c72ad4e38 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 9 Nov 2015 20:30:23 +0100 Subject: [PATCH 079/220] wlog: add some rudimentary documentation --- docs/wlog.md | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 docs/wlog.md diff --git a/docs/wlog.md b/docs/wlog.md new file mode 100644 index 000000000..729d80461 --- /dev/null +++ b/docs/wlog.md @@ -0,0 +1,145 @@ +# Overview + +WLog is a configurable and flexible logging system used throughout winpr and +FreeRDP. + +The primary concept is to have a hierarchy of loggers that can be be configured +independently. + +TODO add more details and configuration examples. + + + +# Environment variables + +* WLOG_APPENDER - the appender to use +* WLOG_PREFIX - configure the prefix used for outputting the message (see + Format for more details and examples) +* WLOG_LEVEL - the level to output messages for +* WLOG_FILTER - sets a filter for WLog messages. Only the filtered messages are +printed +* WLOG_FILEAPPENDER_OUTPUT_FILE_PATH - set the output file path for the file +file appender +* WLOG_FILEAPPENDER_OUTPUT_FILE_NAME - set the output file name for the output +appender +* WLOG_JOURNALD_ID - identifier used by the journal appender +* WLOG_UDP_TARGET - target to use for the UDP appender in the format host:port + +# Levels + +The WLog are complementary the higher level always includes the lower ones. +The level list below is top down. Top the highest level. + +* WLOG_TRACE - print everything including package dumps +* WLOG_DEBUG - debug messages +* WLOG_INFO - general informations +* WLOG_WARN - warnings +* WLOG_ERROR - error +* WLOG_FATAL - fatal problems +* WLOG_OFF - completely disable the wlog output + + +# Format + +The format a logger prints in has the following possible options: + +* "lv" - log level +* "mn" - module name +* "fl" - file name +* "fn" - function +* "ln" - line number +* "pid" - process id +* "tid" - thread id +* "yr" - year +* "mo" - month +* "dw" - day of week +* "hr" - hour +* "mi" - minute +* "se" - second +* "ml" - milliseconds + +A maximum of 16 options can be used per format string. + +An example that generally sets the WLOG_PREFIX for xfreerdp would look like: +``` +WLOG_PREFIX="pid=%pid:tid=%tid:fn=%fn -" xfreerdp /v:xxx +``` + +# Appenders + +WLog uses different appenders that define where the log output should be written +to. If the application doesn't explicitly configure the appenders the above +described variable WLOG_APPENDER can be used to choose one appender. + +The following represents an overview about all appenders and their possible +configuration values. + +### Binary + +Write the log data into a binary format file. + +Options: +* "outputfilename", value const char* - file to write the data to +* "outputfilepath", value const char* - location of the output file + +### Callback +The callback appender can be used from an application to get all log messages +back the application. For example if an application wants to handle the log +output itself. + +Options: + +* "callbacks", value struct wLogCallbacks*, callbacks to use + +### Console + +The console appender writes to the console. Depending of the operating system +the application runs on the output might be handled differently. For example +on android log print would be used. + +Options: + + +* "outputstream", value const char * - output stream to write to + * "stdout" - write everything to stdout + * "stderr" - write everything to stderr + * "default" - use the default settings - in this case errors and fatal would + go to stderr everything else to stdout + * debug - use the debug output. Only used on windows on all operating systems + this behaves as as if default was set. + +### File +The file appender writes the textual output to a file. + +Options: + +* "outputfilename", value const char*, filename to use +* "outputfilepath", value const char*, location of the file + +### Udp + +This appender sends the loging messages to a pre-defined remote host via UDP. + +Options: + +* "target", value const char*, target to send the data too in the format +host:port + +If no target is set the default one 127.0.0.1:20000 is used. To receive the +log messages one can use netcat. To receive the default target the following +command could be used. +``` +nc -u 127.0.0.1 -p 20000 -l +``` + +### Syslog (optional) + +Use syslog for outputting the debug messages. No options available. + +### Journald (optional) + +For outputting the log messages to journald this appender can be used. +The available options are: + +* "identifier", value const char*, the identifier to use for journald (default + is winpr) From 857c003e473e5c0d149db506d0e0b823e53852ab Mon Sep 17 00:00:00 2001 From: Wouter van Kesteren Date: Mon, 9 Nov 2015 21:57:41 +0100 Subject: [PATCH 080/220] cmake: tweak manpage install location This patch is needed when wanting to install binaries/libraries to other locations than data. The linux distro Exherbo installs binaries and libraries to /usr//bin, /usr//lib respectively but manpages should still go in /usr/share/man/ because they are architecture independent, without this patch they go in /usr//share/man unconditionally. cmake documentation states: DATAROOTDIR - read-only architecture-independent data root (share) So this patch makes it use that so that its configurable. --- client/X11/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/X11/CMakeLists.txt b/client/X11/CMakeLists.txt index 621ee9a79..3c0b1c68f 100644 --- a/client/X11/CMakeLists.txt +++ b/client/X11/CMakeLists.txt @@ -111,7 +111,7 @@ if(WITH_MANPAGES) if(OPENBSD) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xfreerdp.1 DESTINATION man/man1) else() - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xfreerdp.1 DESTINATION share/man/man1) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xfreerdp.1 DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/man/man1) endif() else() message(WARNING "WITH_MANPAGES was set, but xsltproc was not found. man-pages will not be installed") From 34c707304b16c83f0ba711c6f6b35f4168791ffb Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Tue, 10 Nov 2015 12:05:23 +0100 Subject: [PATCH 081/220] wlog: change variable naming and fix documentation * change State to active and make it BOOL since it's only got two used values * fix some typos in the documentation --- docs/wlog.md | 14 ++++++++++---- winpr/libwinpr/utils/wlog/Appender.c | 8 ++++---- winpr/libwinpr/utils/wlog/wlog.c | 8 ++++---- winpr/libwinpr/utils/wlog/wlog.h | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/wlog.md b/docs/wlog.md index 729d80461..e6d1286ae 100644 --- a/docs/wlog.md +++ b/docs/wlog.md @@ -12,7 +12,13 @@ TODO add more details and configuration examples. # Environment variables -* WLOG_APPENDER - the appender to use +* WLOG_APPENDER - the appender to use possible values below also see the Appender section. + * CONSOLE + * FILE + * BINARY + * SYSLOG + * JOURNALD + * UDP * WLOG_PREFIX - configure the prefix used for outputting the message (see Format for more details and examples) * WLOG_LEVEL - the level to output messages for @@ -34,7 +40,7 @@ The level list below is top down. Top the highest level. * WLOG_DEBUG - debug messages * WLOG_INFO - general informations * WLOG_WARN - warnings -* WLOG_ERROR - error +* WLOG_ERROR - errors * WLOG_FATAL - fatal problems * WLOG_OFF - completely disable the wlog output @@ -56,7 +62,7 @@ The format a logger prints in has the following possible options: * "hr" - hour * "mi" - minute * "se" - second -* "ml" - milliseconds +* "ml" - millisecond A maximum of 16 options can be used per format string. @@ -118,7 +124,7 @@ Options: ### Udp -This appender sends the loging messages to a pre-defined remote host via UDP. +This appender sends the logging messages to a pre-defined remote host via UDP. Options: diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index 8946d9695..461023fea 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -62,10 +62,10 @@ BOOL WLog_OpenAppender(wLog* log) if (!appender->Open) return TRUE; - if (!appender->State) + if (!appender->active) { status = appender->Open(log, appender); - appender->State = 1; + appender->active = TRUE; } return status; @@ -84,10 +84,10 @@ BOOL WLog_CloseAppender(wLog* log) if (!appender->Close) return TRUE; - if (appender->State) + if (appender->active) { status = appender->Close(log, appender); - appender->State = 0; + appender->active = FALSE; } return status; diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 8a3416448..5526e693e 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -120,7 +120,7 @@ BOOL WLog_Write(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; @@ -151,7 +151,7 @@ BOOL WLog_WriteData(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; @@ -182,7 +182,7 @@ BOOL WLog_WriteImage(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; @@ -213,7 +213,7 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message) if (!appender) return FALSE; - if (!appender->State) + if (!appender->active) if (!WLog_OpenAppender(log)) return FALSE; diff --git a/winpr/libwinpr/utils/wlog/wlog.h b/winpr/libwinpr/utils/wlog/wlog.h index 5f8dd55c9..c3cc83e70 100644 --- a/winpr/libwinpr/utils/wlog/wlog.h +++ b/winpr/libwinpr/utils/wlog/wlog.h @@ -37,7 +37,7 @@ typedef void (*WLOG_APPENDER_FREE)(wLogAppender* appender); #define WLOG_APPENDER_COMMON() \ DWORD Type; \ - DWORD State; \ + BOOL active; \ wLogLayout* Layout; \ CRITICAL_SECTION lock; \ BOOL recursive; \ From be0845b46c2e70267f7aa68b984bd4f6341fb041 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Tue, 10 Nov 2015 13:40:52 +0100 Subject: [PATCH 082/220] wlog/journald: don't set a default identifier Don't set the identifier to "winpr" as default value because journald will use the programs name as default if no identifier is set. This way a program using WLog doesn't need to set an identifier (except it want something different then it's name). --- winpr/libwinpr/utils/wlog/JournaldAppender.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index a64756260..31ac150ee 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -196,12 +196,6 @@ wLogAppender* WLog_JournaldAppender_New(wLog* log) if (!WLog_JournaldAppender_Open(log, (wLogAppender *)appender)) goto error_open; } - else - { - appender->identifier = _strdup("winpr"); - if (!appender->identifier) - goto error_env_malloc; - } return (wLogAppender *)appender; From 7b371560fce07a194ec0b6cc720e10ee528ef0ed Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 10 Nov 2015 14:18:51 +0100 Subject: [PATCH 083/220] Fixed cmake_dependent_option use. --- cmake/ConfigOptions.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 9d501c164..965bba732 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -61,7 +61,7 @@ CMAKE_DEPENDENT_OPTION(TESTS_WTSAPI_EXTRA "Build extra WTSAPI tests (interactive option(WITH_SAMPLE "Build sample code" OFF) option(WITH_CLIENT_COMMON "Build client common library" ON) -cmake_dependent_option(WITH_CLIENT "Build client binaries" ON WITH_CLIENT_COMMON ON) +cmake_dependent_option(WITH_CLIENT "Build client binaries" ON "WITH_CLIENT_COMMON" OFF) option(WITH_SERVER "Build server binaries" OFF) @@ -70,7 +70,7 @@ option(STATIC_CHANNELS "Build channels statically" ON) option(WITH_CHANNELS "Build virtual channel plugins" ON) cmake_dependent_option(WITH_CLIENT_CHANNELS "Build virtual channel plugins" ON - "WITH_CLIENT_COMMON;WITH_CHANNELS" ON) + "WITH_CLIENT_COMMON;WITH_CHANNELS" OFF) if(WITH_SERVER AND WITH_CHANNELS) option(WITH_SERVER_CHANNELS "Build virtual channel plugins" ON) From bff63b3ee255adb24df21c6898b9acad4fcb0e18 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Tue, 10 Nov 2015 16:29:09 +0100 Subject: [PATCH 084/220] wlog: cleanup API includes Only include necessary header files. --- winpr/include/winpr/wlog.h | 6 ------ winpr/libwinpr/utils/wlog/UdpAppender.c | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 0c50676df..f7d7ec0c1 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -27,15 +27,9 @@ extern "C" { #endif -#include -#include - -#include #include - #include #include -#include /** * Log Levels diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c index 76c43bcad..bb173921f 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.c +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -25,6 +25,7 @@ #include #include +#include #include "wlog.h" From d83386bf87b2cc1ff11d5632dbff59041d19901a Mon Sep 17 00:00:00 2001 From: bjcollins Date: Tue, 10 Nov 2015 10:59:13 -0600 Subject: [PATCH 085/220] Fix issue with previous commit, Xext is not required for tsmf but the definition for it still needs to be added when found. --- channels/tsmf/client/gstreamer/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/channels/tsmf/client/gstreamer/CMakeLists.txt b/channels/tsmf/client/gstreamer/CMakeLists.txt index b42ca3670..d0a6eab9c 100644 --- a/channels/tsmf/client/gstreamer/CMakeLists.txt +++ b/channels/tsmf/client/gstreamer/CMakeLists.txt @@ -48,6 +48,10 @@ else() tsmf_X11.c) set(LIBS ${LIBS} ${X11_LIBRARIES} ${XEXT_LIBRARIES}) + if(XEXT_FOUND) + add_definitions(-DWITH_XEXT=1) + endif() + endif() set(${MODULE_PREFIX}_SRCS "${SRC}") From 044ebaafcd2141a4b0c6712b4c9b25d7f339f865 Mon Sep 17 00:00:00 2001 From: Mehul Dhorda Date: Tue, 10 Nov 2015 11:39:37 -0800 Subject: [PATCH 086/220] Fixed build errors that occur when setting WITH_IOSAUDIO build option. - Replaced } with ) in CMakeLists.txt - Included header in TPCircularBuffer.c which is required for the TAG define --- channels/rdpsnd/client/ios/CMakeLists.txt | 2 +- channels/rdpsnd/client/ios/TPCircularBuffer.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/channels/rdpsnd/client/ios/CMakeLists.txt b/channels/rdpsnd/client/ios/CMakeLists.txt index b9a961714..c2beec711 100644 --- a/channels/rdpsnd/client/ios/CMakeLists.txt +++ b/channels/rdpsnd/client/ios/CMakeLists.txt @@ -38,7 +38,7 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${CORE_AUDIO} ${CORE_FOUNDATION}) -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp} +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) diff --git a/channels/rdpsnd/client/ios/TPCircularBuffer.c b/channels/rdpsnd/client/ios/TPCircularBuffer.c index 137ec789f..1c9402799 100644 --- a/channels/rdpsnd/client/ios/TPCircularBuffer.c +++ b/channels/rdpsnd/client/ios/TPCircularBuffer.c @@ -30,6 +30,7 @@ #include #include "TPCircularBuffer.h" +#include "rdpsnd_main.h" #include #include From f6e17ec65c07fa746ab521a3f9a0e3d90f11efb9 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 12 Nov 2015 16:04:31 +0100 Subject: [PATCH 087/220] Added audin support for mac os. --- channels/audin/client/CMakeLists.txt | 4 + channels/audin/client/audin_main.c | 171 ++++++++------------------- include/freerdp/client/audin.h | 2 +- include/freerdp/codec/audio.h | 1 + libfreerdp/codec/audio.c | 3 + 5 files changed, 61 insertions(+), 120 deletions(-) diff --git a/channels/audin/client/CMakeLists.txt b/channels/audin/client/CMakeLists.txt index 81b9cbb4e..a13a930c3 100644 --- a/channels/audin/client/CMakeLists.txt +++ b/channels/audin/client/CMakeLists.txt @@ -52,3 +52,7 @@ endif() if(WITH_WINMM) add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "winmm" "") endif() + +if(WITH_MACAUDIO) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "mac" "") +endif() diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 455257066..17bb60f7d 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -5,6 +5,7 @@ * Copyright 2010-2011 Vic Lee * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2015 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -195,7 +196,7 @@ static UINT audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, Stream_Read_UINT16(s, format.cbSize); format.data = Stream_Pointer(s); Stream_Seek(s, format.cbSize); - + DEBUG_DVC("wFormatTag=%d nChannels=%d nSamplesPerSec=%d " "nBlockAlign=%d wBitsPerSample=%d cbSize=%d", format.wFormatTag, format.nChannels, format.nSamplesPerSec, @@ -310,7 +311,7 @@ static UINT audin_send_open_reply_pdu(IWTSVirtualChannelCallback* pChannelCallba * * @return 0 on success, otherwise a Win32 error code */ -static UINT audin_receive_wave_data(BYTE* data, int size, void* user_data) +static UINT audin_receive_wave_data(const BYTE* data, int size, void* user_data) { UINT error; wStream* out; @@ -667,7 +668,7 @@ static UINT audin_load_device_plugin(IWTSPlugin* pPlugin, const char* name, ADDI * * @return 0 on success, otherwise a Win32 error code */ -UINT audin_set_subsystem(AUDIN_PLUGIN* audin, char* subsystem) +static UINT audin_set_subsystem(AUDIN_PLUGIN* audin, char* subsystem) { free(audin->subsystem); audin->subsystem = _strdup(subsystem); @@ -684,7 +685,7 @@ UINT audin_set_subsystem(AUDIN_PLUGIN* audin, char* subsystem) * * @return 0 on success, otherwise a Win32 error code */ -UINT audin_set_device_name(AUDIN_PLUGIN* audin, char* device_name) +static UINT audin_set_device_name(AUDIN_PLUGIN* audin, char* device_name) { free(audin->device_name); audin->device_name = _strdup(device_name); @@ -696,7 +697,7 @@ UINT audin_set_device_name(AUDIN_PLUGIN* audin, char* device_name) return CHANNEL_RC_OK; } -COMMAND_LINE_ARGUMENT_A audin_args[] = +static COMMAND_LINE_ARGUMENT_A audin_args[] = { { "sys", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "subsystem" }, { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "device" }, @@ -779,9 +780,38 @@ static BOOL audin_process_addin_args(IWTSPlugin* pPlugin, ADDIN_ARGV* args) */ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) { + struct SubsystemEntry + { + char *subsystem; + char *device; + }; + UINT error = CHANNEL_RC_OK; ADDIN_ARGV* args; AUDIN_PLUGIN* audin; + struct SubsystemEntry entries[] = + { +#if defined(WITH_PULSE) + {"pulse", ""}, +#endif +#if defined(WITH_OSS) + {"oss", "default"}, +#endif +#if defined(WITH_ALSA) + {"alsa", "default"}, +#endif +#if defined(WITH_OPENSLES) + {"opensles", "default"}, +#endif +#if defined(WITH_WINMM) + {"winmm", "default"}, +#endif +#if defined(WITH_MACAUDIO) + {"mac", "default"}, +#endif + {NULL,NULL} + }; + struct SubsystemEntry *entry = &entries[0]; assert(pEntryPoints); assert(pEntryPoints->GetPlugin); @@ -807,123 +837,26 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) args = pEntryPoints->GetPluginData(pEntryPoints); audin->rdpcontext = ((freerdp*)((rdpSettings*) pEntryPoints->GetRdpSettings(pEntryPoints))->instance)->context; - if (error == CHANNEL_RC_OK) - audin_process_addin_args((IWTSPlugin*) audin, args); - else + while (entry && entry->subsystem && !audin->device) { - WLog_ERR(TAG, "RegisterPlugin failed with error %lu!", error); - return error; - } + if ((error = audin_set_subsystem(audin, entry->subsystem))) + { + WLog_ERR(TAG, "audin_set_subsystem for %s failed with error %lu!", + entry->subsystem, error); + } + else if ((error = audin_set_device_name(audin, entry->device))) + { + WLog_ERR(TAG, "audin_set_device_name for %s failed with error %lu!", + entry->subsystem, error); + } + else if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) + { + WLog_ERR(TAG, "audin_load_device_plugin %s failed with error %lu!", + entry->subsystem, error); + } - if (audin->subsystem && (error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) { - WLog_ERR(TAG, "audin_load_device_plugin failed!"); - return error; - } - -#if defined(WITH_PULSE) - if (!audin->device) - { - if ((error = audin_set_subsystem(audin, "pulse"))) - { - WLog_ERR(TAG, "audin_set_subsystem for pulse failed with error %lu!", error); - return error; - } - if ((error = audin_set_device_name(audin, ""))) - { - WLog_ERR(TAG, "audin_set_device_name for pulse failed with error %lu!", error); - return error; - } - if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) - { - WLog_ERR(TAG, "audin_load_device_plugin for pulse failed with error %lu!", error); - return error; - } + entry++; } -#endif - -#if defined(WITH_OSS) - if (!audin->device) - { - if ((error = audin_set_subsystem(audin, "oss"))) - { - WLog_ERR(TAG, "audin_set_subsystem for oss failed with error %lu!", error); - return error; - } - if ((error = audin_set_device_name(audin, "default"))) - { - WLog_ERR(TAG, "audin_set_device_name for oss failed with error %lu!", error); - return error; - } - if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) - { - WLog_ERR(TAG, "audin_load_device_plugin oss pulse failed with error %lu!", error); - return error; - } - } -#endif - -#if defined(WITH_ALSA) - if (!audin->device) - { - if ((error = audin_set_subsystem(audin, "alsa"))) - { - WLog_ERR(TAG, "audin_set_subsystem for alsa failed with error %lu!", error); - return error; - } - if ((error = audin_set_device_name(audin, "default"))) - { - WLog_ERR(TAG, "audin_set_device_name for alsa failed with error %lu!", error); - return error; - } - if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) - { - WLog_ERR(TAG, "audin_load_device_plugin oss alsa failed with error %lu!", error); - return error; - } - } -#endif - -#if defined(WITH_OPENSLES) - if (!audin->device) - { - if ((error = audin_set_subsystem(audin, "opensles"))) - { - WLog_ERR(TAG, "audin_set_subsystem for opensles failed with error %lu!", error); - return error; - } - if ((error = audin_set_device_name(audin, "default"))) - { - WLog_ERR(TAG, "audin_set_device_name for opensles failed with error %lu!", error); - return error; - } - if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) - { - WLog_ERR(TAG, "audin_load_device_plugin oss opensles failed with error %lu!", error); - return error; - } - } -#endif - -#if defined(WITH_WINMM) - if (!audin->device) - { - if ((error = audin_set_subsystem(audin, "winmm"))) - { - WLog_ERR(TAG, "audin_set_subsystem for winmm failed with error %lu!", error); - return error; - } - if ((error = audin_set_device_name(audin, "default"))) - { - WLog_ERR(TAG, "audin_set_device_name for winmm failed with error %lu!", error); - return error; - } - if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) - { - WLog_ERR(TAG, "audin_load_device_plugin oss winmm failed with error %lu!", error); - return error; - } - } -#endif if (audin->device == NULL) { diff --git a/include/freerdp/client/audin.h b/include/freerdp/client/audin.h index 87eec5d2d..56a7f0046 100644 --- a/include/freerdp/client/audin.h +++ b/include/freerdp/client/audin.h @@ -29,7 +29,7 @@ * Subsystem Interface */ -typedef UINT (*AudinReceive) (BYTE* data, int size, void* userData); +typedef UINT (*AudinReceive) (const BYTE* data, int size, void* userData); typedef struct audin_format audinFormat; struct audin_format diff --git a/include/freerdp/codec/audio.h b/include/freerdp/codec/audio.h index d797f84f3..c018c715b 100644 --- a/include/freerdp/codec/audio.h +++ b/include/freerdp/codec/audio.h @@ -181,6 +181,7 @@ typedef struct AUDIO_FORMAT AUDIO_FORMAT; #define WAVE_FORMAT_NORRIS 0x1400 #define WAVE_FORMAT_SOUNDSPACE_MUSICOMPRESS 0x1500 #define WAVE_FORMAT_DVM 0x2000 +#define WAVE_FORMAT_AAC_MS 0xA106 /** * Audio Format Functions diff --git a/libfreerdp/codec/audio.c b/libfreerdp/codec/audio.c index 6d96628a9..068f2f541 100644 --- a/libfreerdp/codec/audio.c +++ b/libfreerdp/codec/audio.c @@ -105,6 +105,9 @@ char* rdpsnd_get_audio_tag_string(UINT16 wFormatTag) case WAVE_FORMAT_WMAUDIO2: return "WAVE_FORMAT_WMAUDIO2"; + + case WAVE_FORMAT_AAC_MS: + return "WAVE_FORMAT_AAC_MS"; } return "WAVE_FORMAT_UNKNOWN"; From f4a466b7986bb2f3fd139624ba88e3fc15033eaa Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 13 Nov 2015 11:47:58 +0100 Subject: [PATCH 088/220] Added mac implementation. --- channels/audin/client/mac/CMakeLists.txt | 34 ++ channels/audin/client/mac/audin_mac.c | 461 +++++++++++++++++++++++ 2 files changed, 495 insertions(+) create mode 100644 channels/audin/client/mac/CMakeLists.txt create mode 100644 channels/audin/client/mac/audin_mac.c diff --git a/channels/audin/client/mac/CMakeLists.txt b/channels/audin/client/mac/CMakeLists.txt new file mode 100644 index 000000000..feca0d622 --- /dev/null +++ b/channels/audin/client/mac/CMakeLists.txt @@ -0,0 +1,34 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Armin Novak +# Copyright (c) 2015 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "mac" "") + +set(${MODULE_PREFIX}_SRCS + audin_mac.c) + +include_directories(..) +include_directories(${MAC_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") + +set(${MODULE_PREFIX}_LIBS freerdp ${MAC_LIBRARIES}) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + diff --git a/channels/audin/client/mac/audin_mac.c b/channels/audin/client/mac/audin_mac.c new file mode 100644 index 000000000..07b789477 --- /dev/null +++ b/channels/audin/client/mac/audin_mac.c @@ -0,0 +1,461 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - Mac OS X implementation + * + * Copyright (c) 2015 Armin Novak + * Copyright 2015 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "audin_main.h" + +#define MAC_AUDIO_QUEUE_NUM_BUFFERS 100 +#define MAC_AUDIO_QUEUE_BUFFER_SIZE 32768 + +typedef struct _AudinMacDevice +{ + IAudinDevice iface; + + FREERDP_DSP_CONTEXT* dsp_context; + + audinFormat format; + UINT32 FramesPerPacket; + int dev_unit; + + AudinReceive receive; + void* user_data; + + rdpContext* rdpcontext; + + bool isOpen; + AudioQueueRef audioQueue; + AudioStreamBasicDescription audioFormat; + AudioQueueBufferRef audioBuffers[MAC_AUDIO_QUEUE_NUM_BUFFERS]; +} AudinMacDevice; + +static AudioFormatID audin_mac_get_format(const audinFormat* format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + return kAudioFormatLinearPCM; + /* + case WAVE_FORMAT_GSM610: + return kAudioFormatMicrosoftGSM; + case WAVE_FORMAT_ALAW: + return kAudioFormatALaw; + case WAVE_FORMAT_MULAW: + return kAudioFormatULaw; + case WAVE_FORMAT_AAC_MS: + return kAudioFormatMPEG4AAC; + case WAVE_FORMAT_ADPCM: + case WAVE_FORMAT_DVI_ADPCM: + return kAudioFormatLinearPCM; + */ + } + + return 0; +} + +static AudioFormatFlags audin_mac_get_flags_for_format(const audinFormat* format) +{ + switch(format->wFormatTag) + { + case WAVE_FORMAT_DVI_ADPCM: + case WAVE_FORMAT_ADPCM: + case WAVE_FORMAT_PCM: + return kAudioFormatFlagIsSignedInteger; + default: + return 0; + } +} + +static BOOL audin_mac_format_supported(IAudinDevice* device, audinFormat* format) +{ + AudioFormatID req_fmt = 0; + + if (device == NULL || format == NULL) + return FALSE; + + req_fmt = audin_mac_get_format(format); + + if (req_fmt == 0) + return FALSE; + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_mac_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket) +{ + AudinMacDevice* mac = (AudinMacDevice*)device; + + if (device == NULL || format == NULL) + return ERROR_INVALID_PARAMETER; + + mac->FramesPerPacket = FramesPerPacket; + CopyMemory(&(mac->format), format, sizeof(audinFormat)); + + WLog_INFO(TAG, "Audio Format %s [channels=%d, samples=%d, bits=%d]", + rdpsnd_get_audio_tag_string(format->wFormatTag), + format->nChannels, format->nSamplesPerSec, format->wBitsPerSample); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_ADPCM: + case WAVE_FORMAT_DVI_ADPCM: + mac->FramesPerPacket *= 4; /* Compression ratio. */ + mac->format.wBitsPerSample *= 4; + break; + } + + mac->audioFormat.mBitsPerChannel = mac->format.wBitsPerSample; + mac->audioFormat.mChannelsPerFrame = mac->format.nChannels; + mac->audioFormat.mFormatFlags = audin_mac_get_flags_for_format(format); + mac->audioFormat.mFormatID = audin_mac_get_format(format); + mac->audioFormat.mFramesPerPacket = 1; + mac->audioFormat.mSampleRate = mac->format.nSamplesPerSec; + mac->audioFormat.mBytesPerFrame = + mac->audioFormat.mChannelsPerFrame * mac->audioFormat.mBitsPerChannel / 8; + mac->audioFormat.mBytesPerPacket = + mac->audioFormat.mBytesPerFrame * mac->audioFormat.mFramesPerPacket; + + return CHANNEL_RC_OK; +} + +static void mac_audio_queue_input_cb(void *aqData, + AudioQueueRef inAQ, + AudioQueueBufferRef inBuffer, + const AudioTimeStamp *inStartTime, + UInt32 inNumPackets, + const AudioStreamPacketDescription *inPacketDesc) +{ + AudinMacDevice* mac = (AudinMacDevice*)aqData; + UINT error; + int encoded_size; + const BYTE *encoded_data; + BYTE *buffer = inBuffer->mAudioData; + int buffer_size = inBuffer->mAudioDataByteSize; + + (void)inAQ; + (void)inStartTime; + (void)inNumPackets; + (void)inPacketDesc; + + + /* Process. */ + switch (mac->format.wFormatTag) { + case WAVE_FORMAT_ADPCM: + if (!mac->dsp_context->encode_ms_adpcm(mac->dsp_context, + buffer, buffer_size, mac->format.nChannels, mac->format.nBlockAlign)) + { + SetLastError(ERROR_INTERNAL_ERROR); + return; + } + encoded_data = mac->dsp_context->adpcm_buffer; + encoded_size = mac->dsp_context->adpcm_size; + break; + case WAVE_FORMAT_DVI_ADPCM: + if (!mac->dsp_context->encode_ima_adpcm(mac->dsp_context, + buffer, buffer_size, mac->format.nChannels, mac->format.nBlockAlign)) + { + SetLastError(ERROR_INTERNAL_ERROR); + break; + } + encoded_data = mac->dsp_context->adpcm_buffer; + encoded_size = mac->dsp_context->adpcm_size; + break; + default: + encoded_data = buffer; + encoded_size = buffer_size; + break; + } + + if ((error = mac->receive(encoded_data, encoded_size, mac->user_data))) + { + WLog_ERR(TAG, "mac->receive failed with error %lu", error); + SetLastError(ERROR_INTERNAL_ERROR); + return; + } + +} + +static UINT audin_mac_close(IAudinDevice *device) +{ + UINT errCode = CHANNEL_RC_OK; + char errString[1024]; + OSStatus devStat; + AudinMacDevice *mac = (AudinMacDevice*)device; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if (mac->isOpen) + { + devStat = AudioQueueStop(mac->audioQueue, true); + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueStop failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + } + mac->isOpen = false; + } + + if (mac->audioQueue) + { + devStat = AudioQueueDispose(mac->audioQueue, true); + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueDispose failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + } + + mac->audioQueue = NULL; + } + + mac->receive = NULL; + mac->user_data = NULL; + + return errCode; +} + +static UINT audin_mac_open(IAudinDevice *device, AudinReceive receive, void *user_data) { + AudinMacDevice *mac = (AudinMacDevice*)device; + DWORD errCode; + char errString[1024]; + OSStatus devStat; + size_t index; + + mac->receive = receive; + mac->user_data = user_data; + + devStat = AudioQueueNewInput(&(mac->audioFormat), mac_audio_queue_input_cb, + mac, NULL, kCFRunLoopCommonModes, 0, &(mac->audioQueue)); + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueNewInput failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + for (index = 0; index < MAC_AUDIO_QUEUE_NUM_BUFFERS; index++) + { + devStat = AudioQueueAllocateBuffer(mac->audioQueue, MAC_AUDIO_QUEUE_BUFFER_SIZE, + &mac->audioBuffers[index]); + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueAllocateBuffer failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + devStat = AudioQueueEnqueueBuffer(mac->audioQueue, + mac->audioBuffers[index], + 0, + NULL); + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueEnqueueBuffer failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + } + + freerdp_dsp_context_reset_adpcm(mac->dsp_context); + + devStat = AudioQueueStart(mac->audioQueue, NULL); + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueStart failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + mac->isOpen = true; + + return CHANNEL_RC_OK; + +err_out: + audin_mac_close(device); + return CHANNEL_RC_INITIALIZATION_ERROR; +} + +static UINT audin_mac_free(IAudinDevice* device) +{ + AudinMacDevice *mac = (AudinMacDevice*)device; + + int error; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if ((error = audin_mac_close(device))) + { + WLog_ERR(TAG, "audin_oss_close failed with error code %d!", error); + } + freerdp_dsp_context_free(mac->dsp_context); + free(mac); + + return CHANNEL_RC_OK; +} + +static COMMAND_LINE_ARGUMENT_A audin_mac_args[] = +{ + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } +}; + +static UINT audin_mac_parse_addin_args(AudinMacDevice *device, ADDIN_ARGV *args) +{ + DWORD errCode; + char errString[1024]; + int status; + char* str_num, *eptr; + DWORD flags; + COMMAND_LINE_ARGUMENT_A* arg; + AudinMacDevice* mac = (AudinMacDevice*)device; + + if (args->argc == 1) + return CHANNEL_RC_OK; + + flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, audin_mac_args, flags, mac, NULL, NULL); + + if (status < 0) + return ERROR_INVALID_PARAMETER; + + arg = audin_mac_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) + CommandLineSwitchCase(arg, "dev") + { + str_num = _strdup(arg->Value); + if (!str_num) + { + errCode = GetLastError(); + WLog_ERR(TAG, "_strdup failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + return CHANNEL_RC_NO_MEMORY; + } + mac->dev_unit = strtol(str_num, &eptr, 10); + + if (mac->dev_unit < 0 || *eptr != '\0') + mac->dev_unit = -1; + + free(str_num); + } + CommandLineSwitchEnd(arg) + } + while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +#ifdef STATIC_CHANNELS +#define freerdp_audin_client_subsystem_entry mac_freerdp_audin_client_subsystem_entry +#endif + +UINT freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints) +{ + DWORD errCode; + char errString[1024]; + ADDIN_ARGV *args; + AudinMacDevice *mac; + UINT error; + + mac = (AudinMacDevice*)calloc(1, sizeof(AudinMacDevice)); + if (!mac) + { + errCode = GetLastError(); + WLog_ERR(TAG, "calloc failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + return CHANNEL_RC_NO_MEMORY; + } + + mac->iface.Open = audin_mac_open; + mac->iface.FormatSupported = audin_mac_format_supported; + mac->iface.SetFormat = audin_mac_set_format; + mac->iface.Close = audin_mac_close; + mac->iface.Free = audin_mac_free; + mac->rdpcontext = pEntryPoints->rdpcontext; + + mac->dev_unit = -1; + args = pEntryPoints->args; + + if ((error = audin_mac_parse_addin_args(mac, args))) + { + WLog_ERR(TAG, "audin_mac_parse_addin_args failed with %lu!", error); + goto error_out; + } + + mac->dsp_context = freerdp_dsp_context_new(); + if (!mac->dsp_context) + { + WLog_ERR(TAG, "freerdp_dsp_context_new failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) mac))) + { + WLog_ERR(TAG, "RegisterAudinDevice failed with error %lu!", error); + goto error_out; + } + + return CHANNEL_RC_OK; + +error_out: + freerdp_dsp_context_free(mac->dsp_context); + free(mac); + return error; + +} From 428ac98b9a7df0461365426b2825849de52abffb Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Tue, 17 Nov 2015 23:29:07 +0100 Subject: [PATCH 089/220] pkg: update version infos to 2.0 --- packaging/deb/freerdp-nightly/changelog | 6 ++++++ packaging/rpm/freerdp-nightly.spec | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packaging/deb/freerdp-nightly/changelog b/packaging/deb/freerdp-nightly/changelog index 01c864670..4248a0fcc 100644 --- a/packaging/deb/freerdp-nightly/changelog +++ b/packaging/deb/freerdp-nightly/changelog @@ -1,3 +1,9 @@ +freerdp-nightly (2.0.0) unstable; urgency=low + + * Update version to 2.0.0 + + -- FreeRDP Tue, 17 Nov 2015 23:26:12 +0100 + freerdp-nightly (1.2.1) unstable; urgency=low * Update version to 1.2.1 diff --git a/packaging/rpm/freerdp-nightly.spec b/packaging/rpm/freerdp-nightly.spec index bcc1507c2..bb6da1ab2 100644 --- a/packaging/rpm/freerdp-nightly.spec +++ b/packaging/rpm/freerdp-nightly.spec @@ -8,7 +8,7 @@ %define INSTALL_PREFIX /opt/freerdp-nightly/ Name: freerdp-nightly -Version: 1.2.1 +Version: 2.0 Release: 0 License: ASL 2.0 Summary: Free implementation of the Remote Desktop Protocol (RDP) @@ -36,8 +36,8 @@ BuildRequires: uuid-devel BuildRequires: libxml2-devel BuildRequires: zlib-devel -# Suse 1320+ -%if 0%{?suse_version} >= 1320 +# (Open)Suse +%if %{defined suse_version} BuildRequires: docbook-xsl-stylesheets BuildRequires: libxslt-tools BuildRequires: pkg-config @@ -153,6 +153,8 @@ export NO_BRP_CHECK_RPATH true %changelog +* Tue Nov 16 2015 FreeRDP Team - 2.0.0-0 +- Update version information and support for OpenSuse 42.1 * Tue Feb 03 2015 FreeRDP Team - 1.2.1-0 - Update version information * Fri Jan 23 2015 Bernhard Miklautz - 1.2.0-0 From 75fc2010a7b5f34baacbb862a43d77e732322b71 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 18 Nov 2015 09:49:40 +0100 Subject: [PATCH 090/220] Fixed CLIPRDR_FILEDESCRIPTOR --- include/freerdp/channels/cliprdr.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/include/freerdp/channels/cliprdr.h b/include/freerdp/channels/cliprdr.h index 2bd692ca2..ba7fb1bda 100644 --- a/include/freerdp/channels/cliprdr.h +++ b/include/freerdp/channels/cliprdr.h @@ -86,14 +86,21 @@ typedef struct _CLIPRDR_MFPICT CLIPRDR_MFPICT; struct _CLIPRDR_FILEDESCRIPTOR { - UINT32 flags; - BYTE reserved1[32]; - UINT32 fileAttributes; - BYTE reserved2[16]; - UINT64 lastWriteTime; - UINT32 fileSizeHigh; - UINT32 fileSizeLow; - char fileName[520]; + DWORD dwFlags; + BYTE clsid[16]; + BYTE sizel[8]; + BYTE pointl[8]; + DWORD dwFileAttributes; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + DWORD nFileSizeHigh; + DWORD nFileSizeLow; + union + { + WCHAR w[260]; + CHAR c[520]; + } cFileName; }; typedef struct _CLIPRDR_FILEDESCRIPTOR CLIPRDR_FILEDESCRIPTOR; From 3070cab0faa868ecf8339a2aa93750dd69e079f9 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Thu, 19 Nov 2015 14:12:26 +0100 Subject: [PATCH 091/220] cliprdr/server: Fix parsing of file contents request PDU --- channels/cliprdr/server/cliprdr_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index a73b2b98c..4ffa71e8b 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -955,7 +955,7 @@ static UINT cliprdr_server_receive_filecontents_request(CliprdrServerContext* co request.msgFlags = header->msgFlags; request.dataLen = header->dataLen; - if (Stream_GetRemainingLength(s) < 28) + if (Stream_GetRemainingLength(s) < 24) { WLog_ERR(TAG, "not enought data in stream!"); return ERROR_INVALID_DATA; @@ -967,7 +967,10 @@ static UINT cliprdr_server_receive_filecontents_request(CliprdrServerContext* co Stream_Read_UINT32(s, request.nPositionLow); /* nPositionLow (4 bytes) */ Stream_Read_UINT32(s, request.nPositionHigh); /* nPositionHigh (4 bytes) */ Stream_Read_UINT32(s, request.cbRequested); /* cbRequested (4 bytes) */ - Stream_Read_UINT32(s, request.clipDataId); /* clipDataId (4 bytes) */ + if (Stream_GetRemainingLength(s) < 4) /* clipDataId (4 bytes) optional */ + request.clipDataId = 0; + else + Stream_Read_UINT32(s, request.clipDataId); IFCALLRET(context->ClientFileContentsRequest, error, context, &request); if (error) From fc2768f80741c81d9965e5fcc1e6a65ffb3e79dd Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Thu, 19 Nov 2015 16:17:36 +0100 Subject: [PATCH 092/220] cliprdr/server: Fix incorrect message header --- channels/cliprdr/server/cliprdr_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 4ffa71e8b..bf3ea94f2 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -470,7 +470,7 @@ static UINT cliprdr_server_file_contents_response(CliprdrServerContext* context, if (fileContentsResponse->dwFlags & FILECONTENTS_SIZE) fileContentsResponse->cbRequested = sizeof(UINT64); - s = cliprdr_server_packet_new(CB_FILECONTENTS_REQUEST, 0, + s = cliprdr_server_packet_new(CB_FILECONTENTS_RESPONSE, 0, 4 + fileContentsResponse->cbRequested); if (!s) From 6890e0b84d635f83e68e964b88c2dc489ee21636 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Thu, 19 Nov 2015 16:29:57 +0100 Subject: [PATCH 093/220] cliprdr/server: Fix incorrect message flags --- channels/cliprdr/server/cliprdr_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index bf3ea94f2..24a34c57f 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -470,7 +470,7 @@ static UINT cliprdr_server_file_contents_response(CliprdrServerContext* context, if (fileContentsResponse->dwFlags & FILECONTENTS_SIZE) fileContentsResponse->cbRequested = sizeof(UINT64); - s = cliprdr_server_packet_new(CB_FILECONTENTS_RESPONSE, 0, + s = cliprdr_server_packet_new(CB_FILECONTENTS_RESPONSE, fileContentsResponse->msgFlags, 4 + fileContentsResponse->cbRequested); if (!s) From 428cbd802dfe2dbfefb1348e1d260412147bcc6a Mon Sep 17 00:00:00 2001 From: Nito Martinez Date: Fri, 20 Nov 2015 02:44:35 +0100 Subject: [PATCH 094/220] Fixes #2982. The idea is to be able to create the socket externally and pass that socket FD to FreeRDP so that it can be used there. The idea suggested is to use the following interface: settings->ServerHostname = "|" settings->ServerPort = SocketFD --- libfreerdp/core/tcp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index 58dd96d50..6496f75a4 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -1047,6 +1047,7 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, UINT32 optval; socklen_t optlen; BOOL ipcSocket = FALSE; + BOOL useExternalDefinedSocket = FALSE; if (!hostname) return -1; @@ -1054,12 +1055,18 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, if (hostname[0] == '/') ipcSocket = TRUE; + if (hostname[0] == '|') + useExternalDefinedSocket = TRUE; + if (ipcSocket) { sockfd = freerdp_uds_connect(hostname); if (sockfd < 0) return -1; + } else if (useExternalDefinedSocket) + { + sockfd = port; } else { From 89d8a68f4a43f84208a343ec0974284733e7b569 Mon Sep 17 00:00:00 2001 From: Nito Martinez Date: Wed, 25 Nov 2015 08:36:49 +0100 Subject: [PATCH 095/220] Disable setting socket options for preexisting socket like: keepalive and tcp_nodelay, these should be set extenally if needed. Do not close the socket if the clientaddress could not be set --- libfreerdp/core/tcp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index 6496f75a4..00a1c4514 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -1150,7 +1150,8 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, settings->ClientAddress = freerdp_tcp_get_ip_address(sockfd); if (!settings->ClientAddress) { - close(sockfd); + if (!useExternalDefinedSocket) + close(sockfd); WLog_ERR(TAG, "Couldn't get socket ip address"); return -1; } @@ -1158,7 +1159,7 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, optval = 1; optlen = sizeof(optval); - if (!ipcSocket) + if (!ipcSocket && !useExternalDefinedSocket) { if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*) &optval, optlen) < 0) WLog_ERR(TAG, "unable to set TCP_NODELAY"); @@ -1181,7 +1182,7 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, } } - if (!ipcSocket) + if (!ipcSocket && !useExternalDefinedSocket) { if (!freerdp_tcp_set_keep_alive_mode(sockfd)) { From 2d5c78849e32bef8be06db7907675d011b851665 Mon Sep 17 00:00:00 2001 From: Nito Martinez Date: Thu, 26 Nov 2015 09:50:03 +0100 Subject: [PATCH 096/220] Fix formatting: else if in its own line and no brackets for single statements --- libfreerdp/core/tcp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index 00a1c4514..ce026ce8f 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -1064,10 +1064,9 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, if (sockfd < 0) return -1; - } else if (useExternalDefinedSocket) - { - sockfd = port; } + else if (useExternalDefinedSocket) + sockfd = port; else { sockfd = -1; From 602d2715a27d8188c81f3357198f24727c69a797 Mon Sep 17 00:00:00 2001 From: Xiaodong Qi Date: Sun, 29 Nov 2015 00:14:29 +0800 Subject: [PATCH 097/220] Fix compilation error under Visual Studio 2010 Visual Studio 2010 use a compiler that supports only C89, which only supports declaring variable at top of a local scope. Moving scope variable to the top of function should solve this problem. --- winpr/libwinpr/utils/wlog/ConsoleAppender.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index 49cd94f81..a150ae625 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -55,10 +55,11 @@ static BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogAppender* appender, { FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; + wLogConsoleAppender *consoleAppender; if (!appender) return FALSE; - wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender; + consoleAppender = (wLogConsoleAppender *)appender; message->PrefixString = prefix; From a04f1f8fc59a72ce7330c4dbbe6d4be3f3ff698d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 9 Dec 2015 18:27:05 +0100 Subject: [PATCH 098/220] Added missing _snprintf define. --- winpr/include/winpr/string.h | 1 + 1 file changed, 1 insertion(+) diff --git a/winpr/include/winpr/string.h b/winpr/include/winpr/string.h index ddcaeaf46..555d05306 100644 --- a/winpr/include/winpr/string.h +++ b/winpr/include/winpr/string.h @@ -153,6 +153,7 @@ WINPR_API int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2); #endif #define sprintf_s snprintf +#define _snprintf snprintf #define _scprintf(_fmt, ...) snprintf(NULL, 0, _fmt, ## __VA_ARGS__) #define _scprintf(_fmt, ...) snprintf(NULL, 0, _fmt, ## __VA_ARGS__) From d0e3528c8e07124964f873a733ab9b37f3ed0a0a Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 9 Dec 2015 18:27:37 +0100 Subject: [PATCH 099/220] Added winpr_strerror function. --- winpr/include/winpr/debug.h | 1 + winpr/libwinpr/utils/debug.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/winpr/include/winpr/debug.h b/winpr/include/winpr/debug.h index 3d2cde68a..362bafd5a 100644 --- a/winpr/include/winpr/debug.h +++ b/winpr/include/winpr/debug.h @@ -32,6 +32,7 @@ WINPR_API void* winpr_backtrace(DWORD size); WINPR_API void winpr_backtrace_free(void* buffer); WINPR_API char** winpr_backtrace_symbols(void* buffer, size_t* used); WINPR_API void winpr_backtrace_symbols_fd(void* buffer, int fd); +WINPR_API char* winpr_strerror(DWORD dw, char* dmsg, size_t size); #ifdef __cplusplus } diff --git a/winpr/libwinpr/utils/debug.c b/winpr/libwinpr/utils/debug.c index d90d1e021..0b3150e05 100644 --- a/winpr/libwinpr/utils/debug.c +++ b/winpr/libwinpr/utils/debug.c @@ -471,3 +471,29 @@ void winpr_log_backtrace(const char* tag, DWORD level, DWORD size) winpr_backtrace_free(stack); } +char* winpr_strerror(DWORD dw, char* dmsg, size_t size) { + LPTSTR msg = NULL; + DWORD rc; + +#if defined(_WIN32) + rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, dw, 0, (LPTSTR)&msg, 0, NULL); + if (rc) { +#if defined(UNICODE) + WideCharToMultiByte(CP_ACP, 0, msg, rc, dmsg, size - 1, NULL, NULL); +#else + memcpy(dmsg, msg, min(rc, size - 1)); +#endif + dmsg[min(rc, size - 1)] = 0; + LocalFree(msg); + } else { + _snprintf(dmsg, size, "FAILURE: %08X", GetLastError()); + } +#else + _snprintf(dmsg, size, "%s", strerror(dw)); +#endif + + return dmsg; +} From 19744f3bb865e1fde2b33155a96b2379244a9edf Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 9 Dec 2015 18:29:16 +0100 Subject: [PATCH 100/220] Added additional file functions and tests. --- winpr/include/winpr/file.h | 9 + winpr/libwinpr/file/file.c | 429 +++++++++++++++++- winpr/libwinpr/file/file.h | 61 +++ winpr/libwinpr/file/generic.c | 271 ++++++++++- winpr/libwinpr/file/namedPipeClient.c | 15 +- winpr/libwinpr/file/test/TestFileCreateFile.c | 63 ++- winpr/libwinpr/handle/handle.h | 41 +- winpr/libwinpr/pipe/pipe.c | 17 +- 8 files changed, 853 insertions(+), 53 deletions(-) create mode 100644 winpr/libwinpr/file/file.h diff --git a/winpr/include/winpr/file.h b/winpr/include/winpr/file.h index afe858878..f0129e212 100644 --- a/winpr/include/winpr/file.h +++ b/winpr/include/winpr/file.h @@ -165,6 +165,13 @@ #define STD_OUTPUT_HANDLE (DWORD)-11 #define STD_ERROR_HANDLE (DWORD)-12 +#define FILE_BEGIN 0 +#define FILE_CURRENT 1 +#define FILE_END 2 + +#define LOCKFILE_FAIL_IMMEDIATELY 1 +#define LOCKFILE_EXCLUSIVE_LOCK 2 + typedef union _FILE_SEGMENT_ELEMENT { PVOID64 Buffer; @@ -261,6 +268,8 @@ WINPR_API BOOL FlushFileBuffers(HANDLE hFile); WINPR_API BOOL SetEndOfFile(HANDLE hFile); +WINPR_API DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); + WINPR_API DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 49d6a5d96..a0f197670 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -30,19 +30,12 @@ #define TAG WINPR_TAG("file") #include +#include -#include "../handle/handle.h" +#include "file.h" #include #include - -struct winpr_file -{ - WINPR_HANDLE_DEF(); - - int fd; -}; - -typedef struct winpr_file WINPR_FILE; +#include static BOOL FileIsHandled(HANDLE handle) { @@ -84,10 +77,81 @@ static BOOL FileCloseHandle(HANDLE handle) { } } - free(handle); + free(file->lpFileName); + free(file); return TRUE; } +static BOOL FileSetEndOfFile(HANDLE hFile) +{ + WINPR_FILE* pFile = (WINPR_FILE*) hFile; + DWORD lowSize, highSize; + off_t size; + + if (!hFile) + return FALSE; + + lowSize = GetFileSize(hFile, &highSize); + if (lowSize == INVALID_FILE_SIZE) + return FALSE; + + size = lowSize | ((off_t)highSize << 32); + if (ftruncate(pFile->fd, size) < 0) + { + WLog_ERR(TAG, "ftruncate %d failed with %s [%08X]", + pFile->fd, strerror(errno), errno); + return FALSE; + } + + return TRUE; +} + + +static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, + PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) +{ + WINPR_FILE* pFile = (WINPR_FILE*) hFile; + long offset = lDistanceToMove; + int whence; + FILE* fp; + + if (!hFile) + return INVALID_SET_FILE_POINTER; + + fp = fdopen(pFile->fd, "w"); + + if (!fp) + { + WLog_ERR(TAG, "fdopen(%d) failed with %s [%08X]", pFile->fd, + strerror(errno), errno); + return INVALID_SET_FILE_POINTER; + } + + switch(dwMoveMethod) + { + case FILE_BEGIN: + whence = SEEK_SET; + break; + case FILE_END: + whence = SEEK_END; + break; + case FILE_CURRENT: + whence = SEEK_CUR; + break; + default: + return INVALID_SET_FILE_POINTER; + } + + if (fseek(fp, offset, whence)) + { + WLog_ERR(TAG, "fseek(%d) failed with %s [%08X]", pFile->fd, + strerror(errno), errno); + return INVALID_SET_FILE_POINTER; + } + + return ftell(fp); +} + static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped) { @@ -159,29 +223,347 @@ static BOOL FileWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrit return TRUE; } +static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) +{ + WINPR_FILE* file; + FILE* fp; + long cur, size; -static HANDLE_OPS ops = { - FileIsHandled, - FileCloseHandle, - FileGetFd, - NULL, /* CleanupHandle */ - FileRead, - FileWrite + if (!Object) + return 0; + + file = (WINPR_FILE *)Object; + fp = fdopen(file->fd, "r"); + + if (!fp) + { + WLog_ERR(TAG, "fdopen(%d) failed with %s [%08X]", file->fd, + strerror(errno), errno); + return INVALID_FILE_SIZE; + } + + cur = ftell(fp); + + if (cur < 0) + { + WLog_ERR(TAG, "ftell(%d) failed with %s [%08X]", file->fd, + strerror(errno), errno); + return INVALID_FILE_SIZE; + } + + if (fseek(fp, 0, SEEK_END) != 0) + { + WLog_ERR(TAG, "fseek(%d) failed with %s [%08X]", file->fd, + strerror(errno), errno); + return INVALID_FILE_SIZE; + } + + size = ftell(fp); + + if (size < 0) + { + WLog_ERR(TAG, "ftell(%d) failed with %s [%08X]", file->fd, + strerror(errno), errno); + return INVALID_FILE_SIZE; + } + + if (fseek(fp, cur, SEEK_SET) != 0) + { + WLog_ERR(TAG, "ftell(%d) failed with %s [%08X]", file->fd, + strerror(errno), errno); + return INVALID_FILE_SIZE; + } + + if (lpFileSizeHigh) + *lpFileSizeHigh = 0; + + return size; +} + +static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, + DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, + LPOVERLAPPED lpOverlapped) + { + int lock; + WINPR_FILE* pFile = (WINPR_FILE*)hFile; + + if (!hFile) + return FALSE; + + if (pFile->bLocked) + { + WLog_ERR(TAG, "File %d already locked!", pFile->fd); + return FALSE; + } + + if (lpOverlapped) + { + WLog_ERR(TAG, "lpOverlapped not implemented!"); + return FALSE; + } + + if (dwFlags & LOCKFILE_EXCLUSIVE_LOCK) + lock = LOCK_EX; + else + lock = LOCK_SH; + + if (dwFlags & LOCKFILE_FAIL_IMMEDIATELY) + lock |= LOCK_NB; + + if (flock(pFile->fd, lock) < 0) + { + WLog_ERR(TAG, "flock failed with %s [%08X]", + strerror(errno), errno); + return FALSE; + } + + pFile->bLocked = TRUE; + + return TRUE; +} + +static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, + DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh) +{ + WINPR_FILE* pFile = (WINPR_FILE*)hFile; + + if (!hFile) + return FALSE; + + if (!pFile->bLocked) + { + WLog_ERR(TAG, "File %d is not locked!", pFile->fd); + return FALSE; + } + + if (flock(pFile->fd, LOCK_UN) < 0) + { + WLog_ERR(TAG, "flock(LOCK_UN) %d failed with %s [%08X]", + pFile->fd, strerror(errno), errno); + return FALSE; + } + + return TRUE; +} + +static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, + DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped) +{ + WINPR_FILE* pFile = (WINPR_FILE*)hFile; + + if (!hFile) + return FALSE; + + if (!pFile->bLocked) + { + WLog_ERR(TAG, "File %d is not locked!", pFile->fd); + return FALSE; + } + + if (lpOverlapped) + { + WLog_ERR(TAG, "lpOverlapped not implemented!"); + return FALSE; + } + + if (flock(pFile->fd, LOCK_UN) < 0) + { + WLog_ERR(TAG, "flock(LOCK_UN) %d failed with %s [%08X]", + pFile->fd, strerror(errno), errno); + return FALSE; + } + + return TRUE; +} + +static HANDLE_OPS fileOps = { + FileIsHandled, + FileCloseHandle, + FileGetFd, + NULL, /* CleanupHandle */ + FileRead, + NULL, /* FileReadEx */ + NULL, /* FileReadScatter */ + FileWrite, + NULL, /* FileWriteEx */ + NULL, /* FileWriteGather */ + FileGetFileSize, + NULL, /* FlushFileBuffers */ + FileSetEndOfFile, + FileSetFilePointer, + NULL, /* SetFilePointerEx */ + NULL, /* FileLockFile */ + FileLockFileEx, + FileUnlockFile, + FileUnlockFileEx }; -static WINPR_FILE *FileHandle_New() +static HANDLE_OPS pipeOps = { + FileIsHandled, + FileCloseHandle, + FileGetFd, + NULL, /* CleanupHandle */ + FileRead, + NULL, /* FileReadEx */ + NULL, /* FileReadScatter */ + FileWrite, + NULL, /* FileWriteEx */ + NULL, /* FileWriteGather */ + NULL, /* FileGetFileSize */ + NULL, /* FlushFileBuffers */ + NULL, /* FileSetEndOfFile */ + NULL, /* FileSetFilePointer */ + NULL, /* SetFilePointerEx */ + NULL, /* FileLockFile */ + NULL, /* FileLockFileEx */ + NULL, /* FileUnlockFile */ + NULL /* FileUnlockFileEx */ + +}; + + +static const char* FileGetMode(DWORD dwDesiredAccess, DWORD dwCreationDisposition, BOOL* create) +{ + BOOL writeable = dwDesiredAccess & GENERIC_WRITE; + + switch(dwCreationDisposition) + { + case CREATE_ALWAYS: + *create = TRUE; + return (writeable) ? "wb+" : "rwb"; + case CREATE_NEW: + *create = TRUE; + return "wb+"; + case OPEN_ALWAYS: + *create = TRUE; + return "rb+"; + case OPEN_EXISTING: + *create = FALSE; + return "rb+"; + case TRUNCATE_EXISTING: + *create = FALSE; + return "wb+"; + default: + *create = FALSE; + return ""; + } +} + +static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) +{ + WINPR_FILE* pFile; + BOOL create; + const char* mode = FileGetMode(dwDesiredAccess, dwCreationDisposition, &create); + int lock; + + pFile = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); + if (!pFile) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return INVALID_HANDLE_VALUE; + } + + WINPR_HANDLE_SET_TYPE_AND_MODE(pFile, HANDLE_TYPE_FILE, WINPR_FD_READ); + pFile->ops = &fileOps; + + pFile->lpFileName = _strdup(lpFileName); + if (!pFile->lpFileName) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + free(pFile); + return INVALID_HANDLE_VALUE; + } + + pFile->dwOpenMode = dwDesiredAccess; + pFile->dwShareMode = dwShareMode; + pFile->dwFlagsAndAttributes = dwFlagsAndAttributes; + pFile->lpSecurityAttributes = lpSecurityAttributes; + pFile->dwCreationDisposition = dwCreationDisposition; + pFile->hTemplateFile = hTemplateFile; + + if (create) + { + FILE* fp = fopen(pFile->lpFileName, "ab"); + if (!fp) + { + free(pFile->lpFileName); + free(pFile); + return INVALID_HANDLE_VALUE; + } + fclose(fp); + } + + { + FILE* fp = fopen(pFile->lpFileName, mode); + pFile->fd = fileno(fp); + } + if (pFile->fd < 0) + { + WLog_ERR(TAG, "Failed to open file %s with mode %s", + pFile->lpFileName, mode); + + free(pFile->lpFileName); + free(pFile); + return INVALID_HANDLE_VALUE; + } + + if (dwShareMode & FILE_SHARE_READ) + lock = LOCK_SH; + if (dwShareMode & FILE_SHARE_WRITE) + lock = LOCK_EX; + + if (dwShareMode & (FILE_SHARE_READ | FILE_SHARE_WRITE)) + { + if (flock(pFile->fd, lock) < 0) + { + WLog_ERR(TAG, "flock failed with %s [%08X]", + strerror(errno), errno); + close(pFile->fd); + free(pFile->lpFileName); + free(pFile); + return INVALID_HANDLE_VALUE; + } + + pFile->bLocked = TRUE; + } + + return pFile; +} + +BOOL IsFileDevice(LPCTSTR lpDeviceName) +{ + return TRUE; +} + +HANDLE_CREATOR _FileHandleCreator = +{ + IsFileDevice, + FileCreateFileA +}; + +HANDLE_CREATOR *GetFileHandleCreator(void) +{ + return &_FileHandleCreator; +} + + +static WINPR_FILE *FileHandle_New(int fd) { WINPR_FILE *pFile; HANDLE hFile; + char name[MAX_PATH]; + _snprintf(name, sizeof(name), "pipe_device_%d", fd); pFile = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); if (!pFile) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } - pFile->fd = -1; - pFile->ops = &ops; + pFile->fd = fd; + pFile->ops = &pipeOps; + pFile->lpFileName = _strdup(name); hFile = (HANDLE) pFile; WINPR_HANDLE_SET_TYPE_AND_MODE(pFile, HANDLE_TYPE_FILE, WINPR_FD_READ); @@ -206,11 +588,10 @@ HANDLE GetStdHandle(DWORD nStdHandle) default: return INVALID_HANDLE_VALUE; } - pFile = FileHandle_New(); + pFile = FileHandle_New(fd); if (!pFile) return INVALID_HANDLE_VALUE; - pFile->fd = fd; return (HANDLE)pFile; } @@ -239,7 +620,7 @@ HANDLE GetFileHandleForFileDescriptor(int fd) if (fcntl(fd, F_GETFD) == -1 && errno == EBADF) return INVALID_HANDLE_VALUE; - pFile = FileHandle_New(); + pFile = FileHandle_New(fd); if (!pFile) return INVALID_HANDLE_VALUE; pFile->fd = fd; diff --git a/winpr/libwinpr/file/file.h b/winpr/libwinpr/file/file.h new file mode 100644 index 000000000..fc2879366 --- /dev/null +++ b/winpr/libwinpr/file/file.h @@ -0,0 +1,61 @@ +/** + * WinPR: Windows Portable Runtime + * File Functions + * + * Copyright 2015 Armin Novak + * Copyright 2015 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_FILE_PRIV_H +#define WINPR_FILE_PRIV_H + +#include +#include + +#include +#include +#include + +#ifndef _WIN32 + +#include +#include "../handle/handle.h" + +struct winpr_file +{ + WINPR_HANDLE_DEF(); + + int fd; + + char* lpFileName; + + DWORD dwOpenMode; + DWORD dwShareMode; + DWORD dwFlagsAndAttributes; + + LPSECURITY_ATTRIBUTES lpSecurityAttributes; + DWORD dwCreationDisposition; + HANDLE hTemplateFile; + + BOOL bLocked; +}; +typedef struct winpr_file WINPR_FILE; + +HANDLE_CREATOR *GetFileHandleCreator(void); + +#endif /* _WIN32 */ + +#endif /* WINPR_FILE_PRIV_H */ + diff --git a/winpr/libwinpr/file/generic.c b/winpr/libwinpr/file/generic.c index 6a8a265c6..8719787ad 100644 --- a/winpr/libwinpr/file/generic.c +++ b/winpr/libwinpr/file/generic.c @@ -65,6 +65,8 @@ #include "../pipe/pipe.h" +#include "file.h" + /** * api-ms-win-core-file-l1-2-0.dll: * @@ -195,6 +197,7 @@ static void _HandleCreatorsInit() #if defined __linux__ && !defined ANDROID ArrayList_Add(_HandleCreators, GetCommHandleCreator()); #endif /* __linux__ && !defined ANDROID */ + ArrayList_Add(_HandleCreators, GetFileHandleCreator()); } @@ -253,8 +256,9 @@ HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, if (creator && creator->IsHandled(lpFileName)) { - HANDLE newHandle = creator->CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, - dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + HANDLE newHandle = creator->CreateFileA(lpFileName, dwDesiredAccess, + dwShareMode, lpSecurityAttributes, dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); ArrayList_Unlock(_HandleCreators); return newHandle; } @@ -267,7 +271,17 @@ HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { - return NULL; + LPSTR lpFileNameA = NULL; + HANDLE hdl; + + if (ConvertFromUnicode(CP_UTF8, 0, lpFileName, -1, &lpFileNameA, 0, NULL, NULL)) + return NULL; + + hdl= CreateFileA(lpFileNameA, dwDesiredAccess, dwShareMode, lpSecurityAttributes, + dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + free (lpFileNameA); + + return hdl; } BOOL DeleteFileA(LPCSTR lpFileName) @@ -279,7 +293,15 @@ BOOL DeleteFileA(LPCSTR lpFileName) BOOL DeleteFileW(LPCWSTR lpFileName) { - return TRUE; + LPSTR lpFileNameA = NULL; + BOOL rc = FALSE; + + if (ConvertFromUnicode(CP_UTF8, 0, lpFileName, -1, &lpFileNameA, 0, NULL, NULL)) + return FALSE; + rc = DeleteFileA(lpFileNameA); + free (lpFileNameA); + + return rc; } BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, @@ -304,22 +326,55 @@ BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, handle = (WINPR_HANDLE *)hFile; if (handle->ops->ReadFile) - return handle->ops->ReadFile(handle, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped); + return handle->ops->ReadFile(handle, lpBuffer, nNumberOfBytesToRead, + lpNumberOfBytesRead, lpOverlapped); WLog_ERR(TAG, "ReadFile operation not implemented"); return FALSE; } BOOL ReadFileEx(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, - LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) + LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) { + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->ReadFileEx) + return handle->ops->ReadFileEx(handle, lpBuffer, nNumberOfBytesToRead, + lpOverlapped, lpCompletionRoutine); + + WLog_ERR(TAG, "ReadFileEx operation not implemented"); + return FALSE; + return TRUE; } BOOL ReadFileScatter(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[], - DWORD nNumberOfBytesToRead, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped) + DWORD nNumberOfBytesToRead, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->ReadFileScatter) + return handle->ops->ReadFileScatter(handle, aSegmentArray, nNumberOfBytesToRead, + lpReserved, lpOverlapped); + + WLog_ERR(TAG, "ReadFileScatter operation not implemented"); + return FALSE; } BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, @@ -336,68 +391,236 @@ BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, handle = (WINPR_HANDLE *)hFile; if (handle->ops->WriteFile) - return handle->ops->WriteFile(handle, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped); + return handle->ops->WriteFile(handle, lpBuffer, nNumberOfBytesToWrite, + lpNumberOfBytesWritten, lpOverlapped); - WLog_ERR(TAG, "ReadFile operation not implemented"); + WLog_ERR(TAG, "WriteFile operation not implemented"); return FALSE; } BOOL WriteFileEx(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, - LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) + LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->WriteFileEx) + return handle->ops->WriteFileEx(handle, lpBuffer, nNumberOfBytesToWrite, + lpOverlapped, lpCompletionRoutine); + + WLog_ERR(TAG, "WriteFileEx operation not implemented"); + return FALSE; } BOOL WriteFileGather(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[], - DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped) + DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->WriteFileGather) + return handle->ops->WriteFileGather(handle, aSegmentArray, nNumberOfBytesToWrite, + lpReserved, lpOverlapped); + + WLog_ERR(TAG, "WriteFileGather operation not implemented"); + return FALSE; } BOOL FlushFileBuffers(HANDLE hFile) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->FlushFileBuffers) + return handle->ops->FlushFileBuffers(handle); + + WLog_ERR(TAG, "FlushFileBuffers operation not implemented"); + return FALSE; } BOOL SetEndOfFile(HANDLE hFile) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->SetEndOfFile) + return handle->ops->SetEndOfFile(handle); + + WLog_ERR(TAG, "SetEndOfFile operation not implemented"); + return FALSE; +} + +DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) +{ + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->GetFileSize) + return handle->ops->GetFileSize(handle, lpFileSizeHigh); + + WLog_ERR(TAG, "GetFileSize operation not implemented"); + return 0; } DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->SetFilePointer) + return handle->ops->SetFilePointer(handle, lDistanceToMove, + lpDistanceToMoveHigh, dwMoveMethod); + + WLog_ERR(TAG, "SetFilePointer operation not implemented"); + return 0; } BOOL SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, - PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod) + PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->SetFilePointerEx) + return handle->ops->SetFilePointerEx(handle, liDistanceToMove, + lpNewFilePointer, dwMoveMethod); + + WLog_ERR(TAG, "SetFilePointerEx operation not implemented"); + return 0; } BOOL LockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->LockFile) + return handle->ops->LockFile(handle, dwFileOffsetLow, dwFileOffsetHigh, + nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh); + + WLog_ERR(TAG, "LockFile operation not implemented"); + return FALSE; } BOOL LockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, - DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped) + DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->LockFileEx) + return handle->ops->LockFileEx(handle, dwFlags, dwReserved, + nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, lpOverlapped); + + WLog_ERR(TAG, "LockFileEx operation not implemented"); + return FALSE; } BOOL UnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->UnlockFile) + return handle->ops->UnlockFile(handle, dwFileOffsetLow, dwFileOffsetHigh, + nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh); + + WLog_ERR(TAG, "UnLockFile operation not implemented"); + return FALSE; } BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped) { - return TRUE; + ULONG Type; + WINPR_HANDLE *handle; + + if (hFile == INVALID_HANDLE_VALUE) + return FALSE; + + if (!winpr_Handle_GetInfo(hFile, &Type, &handle)) + return FALSE; + + handle = (WINPR_HANDLE *)hFile; + if (handle->ops->UnlockFileEx) + return handle->ops->UnlockFileEx(handle, dwReserved, + nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped); + + WLog_ERR(TAG, "UnLockFileEx operation not implemented"); + return FALSE; } struct _WIN32_FILE_SEARCH diff --git a/winpr/libwinpr/file/namedPipeClient.c b/winpr/libwinpr/file/namedPipeClient.c index d2aed74fd..b78f8eb7c 100644 --- a/winpr/libwinpr/file/namedPipeClient.c +++ b/winpr/libwinpr/file/namedPipeClient.c @@ -111,7 +111,20 @@ static HANDLE_OPS ops = { NamedPipeClientGetFd, NULL, /* CleanupHandle */ NamedPipeRead, - NamedPipeWrite + NULL, /* FileReadEx */ + NULL, /* FileReadScatter */ + NamedPipeWrite, + NULL, /* FileWriteEx */ + NULL, /* FileWriteGather */ + NULL, /* FileGetFileSize */ + NULL, /* FlushFileBuffers */ + NULL, /* FileSetEndOfFile */ + NULL, /* FileSetFilePointer */ + NULL, /* SetFilePointerEx */ + NULL, /* FileLockFile */ + NULL, /* FileLockFileEx */ + NULL, /* FileUnlockFile */ + NULL /* FileUnlockFileEx */ }; static HANDLE NamedPipeClientCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, diff --git a/winpr/libwinpr/file/test/TestFileCreateFile.c b/winpr/libwinpr/file/test/TestFileCreateFile.c index 39b6a26c7..96281060d 100644 --- a/winpr/libwinpr/file/test/TestFileCreateFile.c +++ b/winpr/libwinpr/file/test/TestFileCreateFile.c @@ -2,9 +2,70 @@ #include #include #include +#include #include int TestFileCreateFile(int argc, char* argv[]) { - return 0; + HANDLE handle; + HRESULT hr; + DWORD written; + const char buffer[] = "Some random text\r\njust want it done."; + char cmp[sizeof(buffer)]; + LPSTR name = GetKnownSubPath(KNOWN_PATH_TEMP, "CreateFile.testfile"); + + int rc = 0; + + if (!name) + return -1; + + /* On windows we would need '\\' or '/' as seperator. + * Single '\' do not work. */ + hr = PathCchConvertStyleA(name, strlen(name), PATH_STYLE_UNIX); + if (FAILED(hr)) + rc = -1; + + handle = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + if (!handle) + { + free(name); + return -1; + } + + if (!PathFileExistsA(name)) + rc = -1; + + if (!WriteFile(handle, buffer, sizeof(buffer), &written, NULL)) + rc = -1; + + if (written != sizeof(buffer)) + rc = -1; + + written = SetFilePointer(handle, 0, NULL, FILE_BEGIN); + + if (written != 0) + rc = -1; + + if (!ReadFile(handle, cmp, sizeof(cmp), &written, NULL)) + rc = -1; + + if (written != sizeof(cmp)) + rc = -1; + + if (memcmp(buffer, cmp, sizeof(buffer))) + rc = -1; + + if (!CloseHandle(handle)) + rc = -1; + + if (!DeleteFileA(name)) + rc = -1; + + if (PathFileExistsA(name)) + rc = -1; + + free(name); + + return rc; } diff --git a/winpr/libwinpr/handle/handle.h b/winpr/libwinpr/handle/handle.h index 7dd620062..d2669baa7 100644 --- a/winpr/libwinpr/handle/handle.h +++ b/winpr/libwinpr/handle/handle.h @@ -50,9 +50,33 @@ typedef BOOL (*pcCloseHandle)(HANDLE handle); typedef int (*pcGetFd)(HANDLE handle); typedef DWORD (*pcCleanupHandle)(HANDLE handle); typedef BOOL (*pcReadFile)(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, - LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); + LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); +typedef BOOL (*pcReadFileEx)(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, + LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); +typedef BOOL (*pcReadFileScatter)(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[], + DWORD nNumberOfBytesToRead, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped); typedef BOOL (*pcWriteFile)(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped); + LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped); +typedef BOOL (*pcWriteFileEx)(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, + LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); +typedef BOOL (*pcWriteFileGather)(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[], + DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped); +typedef DWORD (*pcGetFileSize)(HANDLE handle, LPDWORD lpFileSizeHigh); +typedef BOOL (*pcFlushFileBuffers)(HANDLE hFile); +typedef BOOL (*pcSetEndOfFile)(HANDLE handle); +typedef DWORD(*pcSetFilePointer)(HANDLE handle, LONG lDistanceToMove, + PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); +typedef BOOL (*pcSetFilePointerEx)(HANDLE hFile, LARGE_INTEGER liDistanceToMove, + PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod); +typedef BOOL (*pcLockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, + DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh); +typedef BOOL (*pcLockFileEx)(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, + DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, + LPOVERLAPPED lpOverlapped); +typedef BOOL (*pcUnlockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, + DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh); +typedef BOOL (*pcUnlockFileEx)(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, + DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped); typedef struct _HANDLE_OPS { @@ -61,7 +85,20 @@ typedef struct _HANDLE_OPS pcGetFd GetFd; pcCleanupHandle CleanupHandle; pcReadFile ReadFile; + pcReadFileEx ReadFileEx; + pcReadFileScatter ReadFileScatter; pcWriteFile WriteFile; + pcWriteFileEx WriteFileEx; + pcWriteFileGather WriteFileGather; + pcGetFileSize GetFileSize; + pcFlushFileBuffers FlushFileBuffers; + pcSetEndOfFile SetEndOfFile; + pcSetFilePointer SetFilePointer; + pcSetFilePointerEx SetFilePointerEx; + pcLockFile LockFile; + pcLockFileEx LockFileEx; + pcUnlockFile UnlockFile; + pcUnlockFileEx UnlockFileEx; } HANDLE_OPS; struct winpr_handle diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index 28d9eede3..02beb5d5b 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -178,7 +178,20 @@ static HANDLE_OPS ops = { PipeGetFd, NULL, /* CleanupHandle */ PipeRead, - PipeWrite + NULL, /* FileReadEx */ + NULL, /* FileReadScatter */ + PipeWrite, + NULL, /* FileWriteEx */ + NULL, /* FileWriteGather */ + NULL, /* FileGetFileSize */ + NULL, /* FlushFileBuffers */ + NULL, /* FileSetEndOfFile */ + NULL, /* FileSetFilePointer */ + NULL, /* SetFilePointerEx */ + NULL, /* FileLockFile */ + NULL, /* FileLockFileEx */ + NULL, /* FileUnlockFile */ + NULL /* FileUnlockFileEx */ }; @@ -409,6 +422,8 @@ static HANDLE_OPS namedOps = { NamedPipeGetFd, NULL, /* CleanupHandle */ NamedPipeRead, + NULL, + NULL, NamedPipeWrite }; From df528cefc57a5355fd071c1e03a555fd719bca19 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 9 Dec 2015 18:29:41 +0100 Subject: [PATCH 101/220] Using locking winpr file functions for known hosts. --- libfreerdp/crypto/certificate.c | 241 +++++++++++++++++--------------- 1 file changed, 131 insertions(+), 110 deletions(-) diff --git a/libfreerdp/crypto/certificate.c b/libfreerdp/crypto/certificate.c index e8d292377..7665677e5 100644 --- a/libfreerdp/crypto/certificate.c +++ b/libfreerdp/crypto/certificate.c @@ -116,63 +116,55 @@ fail: static int certificate_data_match_legacy(rdpCertificateStore* certificate_store, rdpCertificateData* certificate_data) { - FILE* fp; + HANDLE fp; int match = 1; char* data; char* mdata; char* pline; char* hostname; - long size; + DWORD lowSize, highSize; + UINT64 size; size_t length; + DWORD read; - fp = fopen(certificate_store->legacy_file, "rb"); - if (!fp) + /* Assure POSIX style paths, CreateFile expects either '/' or '\\' */ + PathCchConvertStyleA(certificate_store->legacy_file, strlen(certificate_store->legacy_file), PATH_STYLE_UNIX); + fp = CreateFileA(certificate_store->legacy_file, GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (fp == INVALID_HANDLE_VALUE) return match; - if (fseek(fp, 0, SEEK_END) < 0) + if ((lowSize = GetFileSize(fp, &highSize)) == INVALID_FILE_SIZE) { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->legacy_file, strerror(errno), errno); - fclose(fp); - return match; - } - if ((size = ftell(fp)) < 0) - { - WLog_ERR(TAG, "ftell(%s) returned %s [%08X]", - certificate_store->legacy_file, strerror(errno), errno); - fclose(fp); - return match; - } - if (fseek(fp, 0, SEEK_SET) < 0) - { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->legacy_file, strerror(errno), errno); - fclose(fp); + WLog_ERR(TAG, "GetFileSize(%s) returned %s [%08X]", + certificate_store->legacy_file, strerror(errno), GetLastError()); + CloseHandle(fp); return match; } + size = (UINT64)lowSize | ((UINT64)highSize << 32); if (size < 1) { - fclose(fp); + CloseHandle(fp); return match; } mdata = (char*) malloc(size + 2); if (!mdata) { - fclose(fp); + CloseHandle(fp); return match; } data = mdata; - if (fread(data, size, 1, fp) != 1) + if (!ReadFile(fp, data, size, &read, NULL) || (read != size)) { free(data); - fclose(fp); + CloseHandle(fp); return match; } - fclose(fp); + CloseHandle(fp); data[size] = '\n'; data[size + 1] = '\0'; @@ -243,67 +235,59 @@ static int certificate_data_match_raw(rdpCertificateStore* certificate_store, char** fprint) { BOOL found = FALSE; - FILE* fp; + HANDLE fp; size_t length; char* data; char* mdata; char* pline; int match = 1; - long int size; + DWORD lowSize, highSize; + UINT64 size; char* hostname = NULL; char* subject = NULL; char* issuer = NULL; char* fingerprint = NULL; unsigned short port = 0; + DWORD read; - fp = fopen(certificate_store->file, "rb"); + /* Assure POSIX style paths, CreateFile expects either '/' or '\\' */ + PathCchConvertStyleA(certificate_store->file, strlen(certificate_store->file), PATH_STYLE_UNIX); + fp = CreateFileA(certificate_store->file, GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL, NULL); - if (!fp) + if (fp == INVALID_HANDLE_VALUE) return match; - if (fseek(fp, 0, SEEK_END) < 0) + if ((lowSize = GetFileSize(fp, &highSize)) == INVALID_FILE_SIZE) { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); - return match; - } - if ((size = ftell(fp)) < 0) - { - WLog_ERR(TAG, "ftell(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); - return match; - } - if (fseek(fp, 0, SEEK_SET) < 0) - { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); + WLog_ERR(TAG, "GetFileSize(%s) returned %s [%08X]", + certificate_store->legacy_file, strerror(errno), GetLastError()); + CloseHandle(fp); return match; } + size = (UINT64)lowSize | ((UINT64)highSize << 32); if (size < 1) { - fclose(fp); + CloseHandle(fp); return match; } mdata = (char*) malloc(size + 2); if (!mdata) { - fclose(fp); + CloseHandle(fp); return match; } data = mdata; - if (fread(data, size, 1, fp) != 1) + if (!ReadFile(fp, data, size, &read, NULL) || (read != size)) { - fclose(fp); free(data); + CloseHandle(fp); return match; } - fclose(fp); + CloseHandle(fp); data[size] = '\n'; data[size + 1] = '\0'; @@ -371,40 +355,36 @@ int certificate_data_match(rdpCertificateStore* certificate_store, BOOL certificate_data_replace(rdpCertificateStore* certificate_store, rdpCertificateData* certificate_data) { - FILE* fp; + HANDLE fp; BOOL rc = FALSE; size_t length; char* data; char* sdata; char* pline; - long int size; + UINT64 size; + DWORD read, written; + DWORD lowSize, highSize; - fp = fopen(certificate_store->file, "rb"); + /* Assure POSIX style paths, CreateFile expects either '/' or '\\' */ + PathCchConvertStyleA(certificate_store->file, strlen(certificate_store->file), PATH_STYLE_UNIX); + fp = CreateFileA(certificate_store->file, GENERIC_READ | GENERIC_WRITE, 0, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (!fp) + if (fp == INVALID_HANDLE_VALUE) return FALSE; - /* Read the current contents of the file. */ - if (fseek(fp, 0, SEEK_END) < 0) + + if ((lowSize = GetFileSize(fp, &highSize)) == INVALID_FILE_SIZE) { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); + WLog_ERR(TAG, "GetFileSize(%s) returned %s [%08X]", + certificate_store->legacy_file, strerror(errno), GetLastError()); + CloseHandle(fp); return FALSE; } + size = (UINT64)lowSize | ((UINT64)highSize << 32); - if ((size = ftell(fp)) < 0) + if (size < 1) { - WLog_ERR(TAG, "ftell(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); - return FALSE; - } - - if (fseek(fp, 0, SEEK_SET) < 0) - { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); + CloseHandle(fp); return FALSE; } @@ -415,22 +395,26 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, return FALSE; } - if (fread(data, size, 1, fp) != 1) + if (!ReadFile(fp, data, size, &read, NULL) || (read != size)) { - fclose(fp); free(data); + CloseHandle(fp); return FALSE; } - fclose(fp); - - fp = fopen(certificate_store->file, "wb"); - - if (fp == NULL) + if (SetFilePointer(fp, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { - WLog_ERR(TAG, "freopen(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - free(data); + WLog_ERR(TAG, "SetFilePointer(%s) returned %s [%08X]", + certificate_store->file, strerror(errno), GetLastError()); + CloseHandle(fp); + return FALSE; + } + + if (!SetEndOfFile(fp)) + { + WLog_ERR(TAG, "SetEndOfFile(%s) returned %s [%08X]", + certificate_store->file, strerror(errno), GetLastError()); + CloseHandle(fp); return FALSE; } @@ -451,6 +435,7 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, char* fingerprint = NULL; char* subject = NULL; char* issuer = NULL; + char* tdata; if (!certificate_split_line(pline, &hostname, &port, &subject, &issuer, &fingerprint)) WLog_WARN(TAG, "Skipping invalid %s entry %s!", @@ -464,26 +449,41 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, fingerprint = certificate_data->fingerprint; rc = TRUE; } - if (fprintf(fp, "%s %hu %s %s %s\n", hostname, port, fingerprint, subject, issuer) < 0) + + size = _snprintf(NULL, 0, "%s %hu %s %s %s\n", hostname, port, fingerprint, subject, issuer); + tdata = malloc(size + 1); + if (!tdata) { - WLog_ERR(TAG, "fprintf(%s) returned %s [%08X]", + WLog_ERR(TAG, "malloc(%s) returned %s [%08X]", certificate_store->file, strerror(errno), errno); - fclose(fp); + CloseHandle(fp); return FALSE; } + + if (_snprintf(tdata, size + 1, "%s %hu %s %s %s\n", hostname, port, fingerprint, subject, issuer) != size) + { + WLog_ERR(TAG, "_snprintf(%s) returned %s [%08X]", + certificate_store->file, strerror(errno), errno); + free(tdata); + CloseHandle(fp); + return FALSE; + } + if (!WriteFile(fp, tdata, size, &written, NULL) || (written != size)) + { + WLog_ERR(TAG, "WriteFile(%s) returned %s [%08X]", + certificate_store->file, strerror(errno), errno); + free(tdata); + CloseHandle(fp); + return FALSE; + } + free(tdata); } } pline = StrSep(&sdata, "\r\n"); } - if (fflush(fp) != 0) - { - WLog_WARN(TAG, "fflush(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - } - - fclose(fp); + CloseHandle(fp); free(data); return rc; @@ -533,39 +533,60 @@ BOOL certificate_split_line(char* line, char** host, UINT16* port, char** subjec BOOL certificate_data_print(rdpCertificateStore* certificate_store, rdpCertificateData* certificate_data) { - FILE* fp; + HANDLE fp; + char* tdata; + UINT64 size; + DWORD written; /* reopen in append mode */ - fp = fopen(certificate_store->file, "ab"); + /* Assure POSIX style paths, CreateFile expects either '/' or '\\' */ + PathCchConvertStyleA(certificate_store->file, strlen(certificate_store->file), PATH_STYLE_UNIX); + fp = CreateFileA(certificate_store->file, GENERIC_WRITE, 0, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (!fp) + if (fp == INVALID_HANDLE_VALUE) return FALSE; - if (fseek(fp, 0, SEEK_END) < 0) + if (SetFilePointer(fp, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) { - WLog_ERR(TAG, "fseek(%s) returned %s [%08X]", - certificate_store->file, strerror(errno), errno); - fclose(fp); + WLog_ERR(TAG, "SetFilePointer(%s) returned %s [%08X]", + certificate_store->file, strerror(errno), GetLastError()); + CloseHandle(fp); return FALSE; } - if (fprintf(fp, "%s %hu %s %s %s\n", certificate_data->hostname, certificate_data->port, + size = _snprintf(NULL, 0, "%s %hu %s %s %s\n", certificate_data->hostname, certificate_data->port, certificate_data->fingerprint, certificate_data->subject, - certificate_data->issuer) < 0) + certificate_data->issuer); + tdata = malloc(size + 1); + if (!tdata) { - WLog_ERR(TAG, "fprintf(%s) returned %s [%08X]", + WLog_ERR(TAG, "malloc(%s) returned %s [%08X]", certificate_store->file, strerror(errno), errno); - fclose(fp); + CloseHandle(fp); return FALSE; } - - if (fflush(fp) != 0) + if (_snprintf(tdata, size + 1, "%s %hu %s %s %s\n", certificate_data->hostname, certificate_data->port, + certificate_data->fingerprint, certificate_data->subject, + certificate_data->issuer) != size) { - WLog_WARN(TAG, "fflush(%s) returned %s [%08X]", + WLog_ERR(TAG, "_snprintf(%s) returned %s [%08X]", certificate_store->file, strerror(errno), errno); + free(tdata); + CloseHandle(fp); + return FALSE; } + if (!WriteFile(fp, tdata, size, &written, NULL) || (written != size)) + { + WLog_ERR(TAG, "WriteFile(%s) returned %s [%08X]", + certificate_store->file, strerror(errno), errno); + free(tdata); + CloseHandle(fp); + return FALSE; + } + free(tdata); - fclose(fp); + CloseHandle(fp); return TRUE; } From 400d1b8b9666a138142399966f7d7db57683a904 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 10 Dec 2015 10:37:44 +0100 Subject: [PATCH 102/220] Fixed open mode for fdopen. --- winpr/libwinpr/file/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index a0f197670..ac618a024 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -118,7 +118,7 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, if (!hFile) return INVALID_SET_FILE_POINTER; - fp = fdopen(pFile->fd, "w"); + fp = fdopen(pFile->fd, "wb"); if (!fp) { @@ -233,7 +233,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) return 0; file = (WINPR_FILE *)Object; - fp = fdopen(file->fd, "r"); + fp = fdopen(file->fd, "wb"); if (!fp) { @@ -496,7 +496,9 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw { FILE* fp = fopen(pFile->lpFileName, mode); - pFile->fd = fileno(fp); + pFile->fd = -1; + if (fp) + pFile->fd = fileno(fp); } if (pFile->fd < 0) { From fe51dd1e108f8ae2eced90f4d269d52c03ea24fb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 10 Dec 2015 10:39:37 +0100 Subject: [PATCH 103/220] Fixed logging, added file name. --- winpr/libwinpr/file/file.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index ac618a024..6cd848280 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -122,7 +122,7 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, if (!fp) { - WLog_ERR(TAG, "fdopen(%d) failed with %s [%08X]", pFile->fd, + WLog_ERR(TAG, "fdopen(%s) failed with %s [%08X]", pFile->lpFileName, strerror(errno), errno); return INVALID_SET_FILE_POINTER; } @@ -144,7 +144,7 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, if (fseek(fp, offset, whence)) { - WLog_ERR(TAG, "fseek(%d) failed with %s [%08X]", pFile->fd, + WLog_ERR(TAG, "fseek(%s) failed with %s [%08X]", pFile->lpFileName, strerror(errno), errno); return INVALID_SET_FILE_POINTER; } @@ -237,7 +237,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) if (!fp) { - WLog_ERR(TAG, "fdopen(%d) failed with %s [%08X]", file->fd, + WLog_ERR(TAG, "fopen(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); return INVALID_FILE_SIZE; } @@ -246,14 +246,14 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) if (cur < 0) { - WLog_ERR(TAG, "ftell(%d) failed with %s [%08X]", file->fd, + WLog_ERR(TAG, "ftell(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); return INVALID_FILE_SIZE; } if (fseek(fp, 0, SEEK_END) != 0) { - WLog_ERR(TAG, "fseek(%d) failed with %s [%08X]", file->fd, + WLog_ERR(TAG, "fseek(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); return INVALID_FILE_SIZE; } @@ -262,14 +262,14 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) if (size < 0) { - WLog_ERR(TAG, "ftell(%d) failed with %s [%08X]", file->fd, + WLog_ERR(TAG, "ftell(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); return INVALID_FILE_SIZE; } if (fseek(fp, cur, SEEK_SET) != 0) { - WLog_ERR(TAG, "ftell(%d) failed with %s [%08X]", file->fd, + WLog_ERR(TAG, "ftell(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); return INVALID_FILE_SIZE; } @@ -292,7 +292,7 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, if (pFile->bLocked) { - WLog_ERR(TAG, "File %d already locked!", pFile->fd); + WLog_ERR(TAG, "File %s already locked!", pFile->lpFileName); return FALSE; } @@ -332,14 +332,14 @@ static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffs if (!pFile->bLocked) { - WLog_ERR(TAG, "File %d is not locked!", pFile->fd); + WLog_ERR(TAG, "File %s is not locked!", pFile->lpFileName); return FALSE; } if (flock(pFile->fd, LOCK_UN) < 0) { - WLog_ERR(TAG, "flock(LOCK_UN) %d failed with %s [%08X]", - pFile->fd, strerror(errno), errno); + WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [%08X]", + pFile->lpFileName, strerror(errno), errno); return FALSE; } @@ -356,7 +356,7 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte if (!pFile->bLocked) { - WLog_ERR(TAG, "File %d is not locked!", pFile->fd); + WLog_ERR(TAG, "File %s is not locked!", pFile->lpFileName); return FALSE; } @@ -368,8 +368,8 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte if (flock(pFile->fd, LOCK_UN) < 0) { - WLog_ERR(TAG, "flock(LOCK_UN) %d failed with %s [%08X]", - pFile->fd, strerror(errno), errno); + WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [%08X]", + pFile->lpFileName, strerror(errno), errno); return FALSE; } @@ -398,7 +398,7 @@ static HANDLE_OPS fileOps = { FileUnlockFileEx }; -static HANDLE_OPS pipeOps = { +static HANDLE_OPS shmOps = { FileIsHandled, FileCloseHandle, FileGetFd, @@ -556,7 +556,7 @@ static WINPR_FILE *FileHandle_New(int fd) HANDLE hFile; char name[MAX_PATH]; - _snprintf(name, sizeof(name), "pipe_device_%d", fd); + _snprintf(name, sizeof(name), "device_%d", fd); pFile = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); if (!pFile) { @@ -564,7 +564,7 @@ static WINPR_FILE *FileHandle_New(int fd) return NULL; } pFile->fd = fd; - pFile->ops = &pipeOps; + pFile->ops = &shmOps; pFile->lpFileName = _strdup(name); hFile = (HANDLE) pFile; From f0e3a2d8454a179222a073132cb49fb8492fc5c1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 10 Dec 2015 10:40:14 +0100 Subject: [PATCH 104/220] Added extended file seek tests. --- winpr/libwinpr/file/test/TestFileCreateFile.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/winpr/libwinpr/file/test/TestFileCreateFile.c b/winpr/libwinpr/file/test/TestFileCreateFile.c index 96281060d..547d322af 100644 --- a/winpr/libwinpr/file/test/TestFileCreateFile.c +++ b/winpr/libwinpr/file/test/TestFileCreateFile.c @@ -3,6 +3,7 @@ #include #include #include +#include #include int TestFileCreateFile(int argc, char* argv[]) @@ -42,7 +43,17 @@ int TestFileCreateFile(int argc, char* argv[]) if (written != sizeof(buffer)) rc = -1; - written = SetFilePointer(handle, 0, NULL, FILE_BEGIN); + written = SetFilePointer(handle, 5, NULL, FILE_BEGIN); + + if (written != 5) + rc = -1; + + written = SetFilePointer(handle, 0, NULL, FILE_CURRENT); + + if (written != 5) + rc = -1; + + written = SetFilePointer(handle, -5, NULL, FILE_CURRENT); if (written != 0) rc = -1; From 65062633c2156642cf093bb7f4dfc50c8687a478 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 10 Dec 2015 13:57:05 +0100 Subject: [PATCH 105/220] Fixed memory leak. --- libfreerdp/crypto/certificate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libfreerdp/crypto/certificate.c b/libfreerdp/crypto/certificate.c index 7665677e5..4e2618dfa 100644 --- a/libfreerdp/crypto/certificate.c +++ b/libfreerdp/crypto/certificate.c @@ -406,6 +406,7 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, { WLog_ERR(TAG, "SetFilePointer(%s) returned %s [%08X]", certificate_store->file, strerror(errno), GetLastError()); + free(data); CloseHandle(fp); return FALSE; } @@ -414,6 +415,7 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, { WLog_ERR(TAG, "SetEndOfFile(%s) returned %s [%08X]", certificate_store->file, strerror(errno), GetLastError()); + free(data); CloseHandle(fp); return FALSE; } @@ -456,6 +458,7 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, { WLog_ERR(TAG, "malloc(%s) returned %s [%08X]", certificate_store->file, strerror(errno), errno); + free(data); CloseHandle(fp); return FALSE; } @@ -465,6 +468,7 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, WLog_ERR(TAG, "_snprintf(%s) returned %s [%08X]", certificate_store->file, strerror(errno), errno); free(tdata); + free(data); CloseHandle(fp); return FALSE; } @@ -473,6 +477,7 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store, WLog_ERR(TAG, "WriteFile(%s) returned %s [%08X]", certificate_store->file, strerror(errno), errno); free(tdata); + free(data); CloseHandle(fp); return FALSE; } From 60109329847c0455a64f19443bff92f281092889 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 14 Dec 2015 09:23:42 +0100 Subject: [PATCH 106/220] Fixed possible race on file creation. --- winpr/libwinpr/file/file.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 6cd848280..b0eb565b8 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -456,6 +456,7 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw BOOL create; const char* mode = FileGetMode(dwDesiredAccess, dwCreationDisposition, &create); int lock; + FILE* fp = NULL; pFile = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); if (!pFile) @@ -484,22 +485,24 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw if (create) { - FILE* fp = fopen(pFile->lpFileName, "ab"); + fp = fopen(pFile->lpFileName, "ab"); if (!fp) { free(pFile->lpFileName); free(pFile); return INVALID_HANDLE_VALUE; } - fclose(fp); + + fp = freopen(pFile->lpFileName, mode, fp); } - { - FILE* fp = fopen(pFile->lpFileName, mode); - pFile->fd = -1; - if (fp) - pFile->fd = fileno(fp); - } + if (NULL == fp) + fp = fopen(pFile->lpFileName, mode); + + pFile->fd = -1; + if (fp) + pFile->fd = fileno(fp); + if (pFile->fd < 0) { WLog_ERR(TAG, "Failed to open file %s with mode %s", From 63894eb4e74197481350fee92986e39ffee3a27e Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 12:09:39 +0200 Subject: [PATCH 107/220] Using stdint.h and stdbool.h for type definitions When stdint.h or stdbool.h are detected, use these standard types for definitions in wtypes.h --- CMakeLists.txt | 10 +++ config.h.in | 1 - winpr/include/winpr/wtypes.h | 132 ++++++++++++++++++++++++++++++----- 3 files changed, 123 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 411bdef73..abacb3650 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,6 +328,7 @@ if(NOT IOS) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(execinfo.h HAVE_EXECINFO_H) check_include_files(stdint.h HAVE_STDINT_H) + check_include_files(stdbool.h HAVE_STDBOOL_H) check_include_files(inttypes.h HAVE_INTTYPES_H) check_include_files(sys/modem.h HAVE_SYS_MODEM_H) check_include_files(sys/filio.h HAVE_SYS_FILIO_H) @@ -339,10 +340,19 @@ else() set(HAVE_FCNTL_H 1) set(HAVE_UNISTD_H 1) set(HAVE_STDINT_H 1) + set(HAVE_STDBOOL_H 1) set(HAVE_INTTYPES_H 1) set(HAVE_SYS_FILIO_H 1) endif() +if(HAVE_STDBOOL_H) + add_definitions(-DHAVE_STDBOOL_H) +endif() + +if(HAVE_STDINT_H) + add_definitions(-DHAVE_STDINT_H) +endif() + if(NOT IOS) check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF) else() diff --git a/config.h.in b/config.h.in index 0f39545f2..df24a3071 100644 --- a/config.h.in +++ b/config.h.in @@ -4,7 +4,6 @@ /* Include files */ #cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_UNISTD_H -#cmakedefine HAVE_STDINT_H #cmakedefine HAVE_INTTYPES_H #cmakedefine HAVE_SYS_MODEM_H #cmakedefine HAVE_SYS_FILIO_H diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 271b8c160..635c106b2 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -28,6 +28,14 @@ #include +#if defined(HAVE_STDBOOL_H) +#include +#endif + +#if defined(HAVE_STDINT_H) +#include +#endif + #ifdef _WIN32 #include #endif @@ -49,17 +57,39 @@ #define NEAR #endif +#if defined(HAVE_STDINT_H) +#define int8_t char +#define int16_t short +#define int32_t int +#define int64_t long long +#else #define __int8 char #define __int16 short #define __int32 int #define __int64 long long - -#if defined(__x86_64__) || defined(__arm64__) -#define __int3264 __int64 -#else -#define __int3264 __int32 #endif +#if defined(HAVE_STDINT_H) +#if defined(__x86_64__) || defined(__arm64__) +#define __int3264 int64_t +#define __uint3264 uint64_t +#else +#define __int3264 int32_t +#define __uint3264 uint32_t +#endif +#else +#if defined(__x86_64__) || defined(__arm64__) +#define __int3264 __int64 +#define __uint3264 unsigned __int64 +#else +#define __int3264 __int32 +#define __uint3264 unsigned __int32 +#endif +#endif + +#if defined(HAVE_STDBOOL_H) +typedef bool BOOL; +#else #ifndef __OBJC__ #if defined(__APPLE__) typedef signed char BOOL; @@ -69,10 +99,15 @@ typedef int BOOL; #endif #endif #endif +#endif typedef BOOL *PBOOL, *LPBOOL; -#if defined(__LP64__) || defined(__APPLE__) +#if defined(HAVE_STDINT_H) +typedef int32_t LONG; +typedef uint32_t DWORD; +typedef uint32_t ULONG; +#elif defined(__LP64__) || defined(__APPLE__) typedef int LONG; typedef unsigned int DWORD; typedef unsigned int ULONG; @@ -82,27 +117,50 @@ typedef unsigned long DWORD; typedef unsigned long ULONG; #endif +#if defined(HAVE_STDINT_H) +typedef uint8_t BYTE, *PBYTE, *LPBYTE; +#else typedef unsigned char BYTE, *PBYTE, *LPBYTE; +#endif + typedef BYTE BOOLEAN, *PBOOLEAN; +#if defined(wchar_t) +typedef wchar_t WCHAR, *PWCHAR; +#else typedef unsigned short WCHAR, *PWCHAR; +#endif typedef WCHAR* BSTR; typedef char CHAR, *PCHAR; typedef DWORD *PDWORD, *LPDWORD; +#if defined(HAVE_STDINT_H) +typedef uint32_t DWORD32; +typedef uint64_t DWORD64; +typedef uint64_t ULONGLONG; +#else typedef unsigned int DWORD32; typedef unsigned __int64 DWORD64; typedef unsigned __int64 ULONGLONG; +#endif typedef ULONGLONG DWORDLONG, *PDWORDLONG; typedef float FLOAT; typedef unsigned char UCHAR, *PUCHAR; typedef short SHORT; #ifndef FALSE +#if defined(HAVE_STDBOOL_H) +#define FALSE false +#else #define FALSE 0 #endif +#endif #ifndef TRUE +#if defined(HAVE_STDBOOL_H) +#define TRUE true +#else #define TRUE 1 #endif +#endif #define CONST const #define CALLBACK @@ -119,25 +177,41 @@ typedef HANDLE HMENU; typedef DWORD HCALL; typedef int INT, *LPINT; +#if defined(HAVE_STDINT_H) +typedef int8_t INT8; +typedef int16_t INT16; +typedef int32_t INT32; +typedef int64_t INT64; +#else typedef signed char INT8; typedef signed short INT16; #ifndef XMD_H typedef signed int INT32; typedef signed __int64 INT64; #endif +#endif typedef const WCHAR* LMCSTR; typedef WCHAR* LMSTR; typedef LONG *PLONG, *LPLONG; +#if defined(HAVE_STDINT_H) +typedef int64_t LONGLONG; +#else typedef signed __int64 LONGLONG; +#endif typedef __int3264 LONG_PTR, *PLONG_PTR; -typedef unsigned __int3264 ULONG_PTR, *PULONG_PTR; +typedef __uint3264 ULONG_PTR, *PULONG_PTR; +#if defined(HAVE_STDINT_H) +typedef int32_t LONG32; +typedef int64_t LONG64; +#else typedef signed int LONG32; #ifndef XMD_H typedef signed __int64 LONG64; #endif +#endif typedef CHAR *PSTR, *LPSTR, *LPCH; typedef const CHAR *LPCSTR,*PCSTR; @@ -145,13 +219,23 @@ typedef const CHAR *LPCSTR,*PCSTR; typedef WCHAR *LPWSTR, *PWSTR, *LPWCH; typedef const WCHAR *LPCWSTR,*PCWSTR; +typedef unsigned int UINT; +#if defined(HAVE_STDINT_H) +typedef uint64_t QWORD; + +typedef uint8_t UINT8; +typedef uint16_t UINT16; +typedef uint32_t UINT32; +typedef uint64_t UINT64; +#else typedef unsigned __int64 QWORD; -typedef unsigned int UINT; typedef unsigned char UINT8; typedef unsigned short UINT16; typedef unsigned int UINT32; typedef unsigned __int64 UINT64; +#endif + typedef ULONG *PULONG; typedef LONG HRESULT; @@ -160,15 +244,25 @@ typedef SCODE *PSCODE; typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; typedef ULONG_PTR SIZE_T; +#if defined(HAVE_STDINT_H) +typedef uint32_t ULONG32; +typedef uint64_t ULONG64; +typedef uint16_t USHORT; +typedef uint16_t WORD, *PWORD, *LPWORD; +#else typedef unsigned int ULONG32; typedef unsigned __int64 ULONG64; -typedef wchar_t UNICODE; typedef unsigned short USHORT; +typedef unsigned short WORD, *PWORD, *LPWORD; +#endif +typedef wchar_t UNICODE; #define VOID void typedef void *PVOID, *LPVOID; typedef void *PVOID64, *LPVOID64; -typedef unsigned short WORD, *PWORD, *LPWORD; +#if defined(HAVE_STDINT_H) +typedef intptr_t INT_PTR; +typedef uintptr_t UINT_PTR; #if defined(__x86_64__) || defined(__arm64__) typedef __int64 INT_PTR; typedef unsigned __int64 UINT_PTR; @@ -273,19 +367,19 @@ typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; typedef struct _RPC_SID { - unsigned char Revision; - unsigned char SubAuthorityCount; + UCHAR Revision; + UCHAR SubAuthorityCount; RPC_SID_IDENTIFIER_AUTHORITY IdentifierAuthority; - unsigned long SubAuthority[]; + ULONG SubAuthority[]; } RPC_SID, *PRPC_SID, *PSID; typedef struct _ACL { - unsigned char AclRevision; - unsigned char Sbz1; - unsigned short AclSize; - unsigned short AceCount; - unsigned short Sbz2; + UCHAR AclRevision; + UCHAR Sbz1; + USHORT AclSize; + USHORT AceCount; + USHORT Sbz2; } ACL, *PACL; typedef struct _SECURITY_DESCRIPTOR @@ -329,7 +423,7 @@ typedef double DOUBLE; typedef void* PCONTEXT_HANDLE; typedef PCONTEXT_HANDLE* PPCONTEXT_HANDLE; -typedef unsigned long error_status_t; +typedef ULONG error_status_t; #ifndef _NTDEF_ typedef LONG NTSTATUS; From 74c15a6309a9154389220461774d80aa6f1107aa Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 13:52:35 +0200 Subject: [PATCH 108/220] Fixed freerdp_assistance_file_new argument declaration --- include/freerdp/assistance.h | 2 +- libfreerdp/common/assistance.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/freerdp/assistance.h b/include/freerdp/assistance.h index 23ce9339e..48301a2ae 100644 --- a/include/freerdp/assistance.h +++ b/include/freerdp/assistance.h @@ -77,7 +77,7 @@ FREERDP_API int freerdp_assistance_decrypt(rdpAssistanceFile* file, const char* FREERDP_API int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* file, rdpSettings* settings); -FREERDP_API rdpAssistanceFile* freerdp_assistance_file_new(); +FREERDP_API rdpAssistanceFile* freerdp_assistance_file_new(void); FREERDP_API void freerdp_assistance_file_free(rdpAssistanceFile* file); #ifdef __cplusplus diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index 2855a2b0a..9e4702e7c 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -1193,7 +1193,7 @@ int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* fil return 1; } -rdpAssistanceFile* freerdp_assistance_file_new() +rdpAssistanceFile* freerdp_assistance_file_new(void) { return (rdpAssistanceFile*) calloc(1, sizeof(rdpAssistanceFile)); } From 639c1760042c1136311f7b16c1aa52f7761ab0f1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 13:53:37 +0200 Subject: [PATCH 109/220] Fixed DecodeEx return value --- channels/tsmf/client/tsmf_decoder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels/tsmf/client/tsmf_decoder.h b/channels/tsmf/client/tsmf_decoder.h index d507b9e1b..fe8d99fd5 100644 --- a/channels/tsmf/client/tsmf_decoder.h +++ b/channels/tsmf/client/tsmf_decoder.h @@ -49,7 +49,7 @@ struct _ITSMFDecoder /* Optional Contol function */ BOOL (*Control)(ITSMFDecoder *decoder, ITSMFControlMsg control_msg, UINT32 *arg); /* Decode a sample with extended interface. */ - int (*DecodeEx)(ITSMFDecoder *decoder, const BYTE *data, UINT32 data_size, UINT32 extensions, + BOOL (*DecodeEx)(ITSMFDecoder *decoder, const BYTE *data, UINT32 data_size, UINT32 extensions, UINT64 start_time, UINT64 end_time, UINT64 duration); /* Get current play time */ UINT64(*GetRunningTime)(ITSMFDecoder *decoder); From 90251f5e0d75c9e85500f6fac00d5c633bf02e17 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 13:54:19 +0200 Subject: [PATCH 110/220] Fixed OnNewChannelConnection arguments --- channels/audin/client/audin_main.c | 2 +- channels/disp/client/disp_main.c | 2 +- channels/drdynvc/client/drdynvc_main.c | 6 +++--- channels/echo/client/echo_main.c | 2 +- channels/rdpei/client/rdpei_main.c | 2 +- channels/rdpgfx/client/rdpgfx_main.c | 2 +- channels/tsmf/client/tsmf_main.c | 2 +- channels/urbdrc/client/urbdrc_main.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 17bb60f7d..373ae86dc 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -522,7 +522,7 @@ static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept, + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) { AUDIN_CHANNEL_CALLBACK* callback; diff --git a/channels/disp/client/disp_main.c b/channels/disp/client/disp_main.c index 6486388ba..d70f61964 100644 --- a/channels/disp/client/disp_main.c +++ b/channels/disp/client/disp_main.c @@ -254,7 +254,7 @@ static UINT disp_on_close(IWTSVirtualChannelCallback* pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT disp_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept, + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) { DISP_CHANNEL_CALLBACK* callback; diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index cfe8679bc..83e8497b8 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -436,7 +436,7 @@ static UINT dvcman_close_channel_iface(IWTSVirtualChannel* pChannel) UINT dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId, const char* ChannelName) { int i; - int bAccept; + BOOL bAccept; DVCMAN_LISTENER* listener; DVCMAN_CHANNEL* channel; DrdynvcClientContext* context; @@ -462,11 +462,11 @@ UINT dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 Channe channel->iface.Write = dvcman_write_channel; channel->iface.Close = dvcman_close_channel_iface; - bAccept = 1; + bAccept = TRUE; pCallback = NULL; if ((error = listener->listener_callback->OnNewChannelConnection(listener->listener_callback, - (IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback)) == CHANNEL_RC_OK && bAccept == 1) + (IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback)) == CHANNEL_RC_OK && bAccept) { WLog_DBG(TAG, "listener %s created new channel %d", listener->channel_name, channel->channel_id); diff --git a/channels/echo/client/echo_main.c b/channels/echo/client/echo_main.c index 871b75b89..fe2d3631c 100644 --- a/channels/echo/client/echo_main.c +++ b/channels/echo/client/echo_main.c @@ -96,7 +96,7 @@ static UINT echo_on_close(IWTSVirtualChannelCallback* pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT echo_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept, + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) { ECHO_CHANNEL_CALLBACK* callback; diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c index 7494d4b0e..d1cbb7c07 100644 --- a/channels/rdpei/client/rdpei_main.c +++ b/channels/rdpei/client/rdpei_main.c @@ -596,7 +596,7 @@ static UINT rdpei_on_close(IWTSVirtualChannelCallback* pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT rdpei_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept, + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) { RDPEI_CHANNEL_CALLBACK* callback; diff --git a/channels/rdpgfx/client/rdpgfx_main.c b/channels/rdpgfx/client/rdpgfx_main.c index cf18fc4c7..7da8c9fd2 100644 --- a/channels/rdpgfx/client/rdpgfx_main.c +++ b/channels/rdpgfx/client/rdpgfx_main.c @@ -1265,7 +1265,7 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept, + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) { RDPGFX_CHANNEL_CALLBACK* callback; diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 0c8bdea3a..b473954dc 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -351,7 +351,7 @@ static UINT tsmf_on_close(IWTSVirtualChannelCallback *pChannelCallback) static UINT tsmf_on_new_channel_connection(IWTSListenerCallback *pListenerCallback, IWTSVirtualChannel *pChannel, BYTE *Data, - int *pbAccept, + BOOL *pbAccept, IWTSVirtualChannelCallback **ppCallback) { TSMF_CHANNEL_CALLBACK* callback; diff --git a/channels/urbdrc/client/urbdrc_main.c b/channels/urbdrc/client/urbdrc_main.c index d69205d60..78cd77da0 100644 --- a/channels/urbdrc/client/urbdrc_main.c +++ b/channels/urbdrc/client/urbdrc_main.c @@ -1335,7 +1335,7 @@ static UINT urbdrc_on_close(IWTSVirtualChannelCallback * pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT urbdrc_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel * pChannel, BYTE* pData, int* pbAccept, IWTSVirtualChannelCallback** ppCallback) + IWTSVirtualChannel * pChannel, BYTE* pData, BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) { URBDRC_LISTENER_CALLBACK* listener_callback = (URBDRC_LISTENER_CALLBACK*) pListenerCallback; URBDRC_CHANNEL_CALLBACK* callback; From 00b8d802d291a93e809e3328c883f2253db1ee69 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 13:54:41 +0200 Subject: [PATCH 111/220] Fixed callback function return --- libfreerdp/codec/jpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/codec/jpeg.c b/libfreerdp/codec/jpeg.c index 784b5a7df..9fa90bf15 100644 --- a/libfreerdp/codec/jpeg.c +++ b/libfreerdp/codec/jpeg.c @@ -45,7 +45,7 @@ static void my_init_source(j_decompress_ptr cinfo) } /*****************************************************************************/ -static BOOL my_fill_input_buffer(j_decompress_ptr cinfo) +static boolean my_fill_input_buffer(j_decompress_ptr cinfo) { struct mydata_decomp* md; @@ -61,7 +61,7 @@ static void my_skip_input_data(j_decompress_ptr cinfo, long num_bytes) } /*****************************************************************************/ -static BOOL my_resync_to_restart(j_decompress_ptr cinfo, int desired) +static boolean my_resync_to_restart(j_decompress_ptr cinfo, int desired) { return 1; } From c8652371e7bb7a37ebb7b197eceded5b29505b3f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 15:05:18 +0200 Subject: [PATCH 112/220] Removed stdbool define for iOS. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abacb3650..925f0e40d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,7 +340,7 @@ else() set(HAVE_FCNTL_H 1) set(HAVE_UNISTD_H 1) set(HAVE_STDINT_H 1) - set(HAVE_STDBOOL_H 1) + set(HAVE_STDBOOL_H 0) set(HAVE_INTTYPES_H 1) set(HAVE_SYS_FILIO_H 1) endif() From 6e69caad9f21046c25a56c8170658cd9c2795063 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 15:11:08 +0200 Subject: [PATCH 113/220] Disabled definition of BOOL for objective C --- winpr/include/winpr/wtypes.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 635c106b2..b734a8c33 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -87,7 +87,7 @@ #endif #endif -#if defined(HAVE_STDBOOL_H) +#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) typedef bool BOOL; #else #ifndef __OBJC__ @@ -147,7 +147,7 @@ typedef unsigned char UCHAR, *PUCHAR; typedef short SHORT; #ifndef FALSE -#if defined(HAVE_STDBOOL_H) +#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) #define FALSE false #else #define FALSE 0 @@ -155,7 +155,7 @@ typedef short SHORT; #endif #ifndef TRUE -#if defined(HAVE_STDBOOL_H) +#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) #define TRUE true #else #define TRUE 1 From ff24885ff3d53790bf66c4ee4baab5d4fe57144f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 7 Sep 2015 16:34:23 +0200 Subject: [PATCH 114/220] Fixed mixup of type defines. --- winpr/include/winpr/wtypes.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index b734a8c33..b363ff3e4 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -58,15 +58,23 @@ #endif #if defined(HAVE_STDINT_H) -#define int8_t char -#define int16_t short -#define int32_t int -#define int64_t long long +#define __int8 int8_t +#define __uint8 uint8_t +#define __int16 int16_t +#define __uint16 uint16_t +#define __int32 int32_t +#define __uint32 uint32_t +#define __int64 int64_t +#define __uint64 uint64_t #else #define __int8 char +#define __uint8 unsigned char #define __int16 short +#define __uint16 unsigned short #define __int32 int +#define __uint32 unsigned int #define __int64 long long +#define __uint64 unsigned long long #endif #if defined(HAVE_STDINT_H) @@ -207,7 +215,6 @@ typedef int32_t LONG32; typedef int64_t LONG64; #else typedef signed int LONG32; - #ifndef XMD_H typedef signed __int64 LONG64; #endif @@ -263,7 +270,7 @@ typedef void *PVOID64, *LPVOID64; #if defined(HAVE_STDINT_H) typedef intptr_t INT_PTR; typedef uintptr_t UINT_PTR; -#if defined(__x86_64__) || defined(__arm64__) +#elif __x86_64__ typedef __int64 INT_PTR; typedef unsigned __int64 UINT_PTR; #else From 533e14745e858534c861a9fe9bdb26c0abc39a3f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 8 Sep 2015 13:03:13 +0200 Subject: [PATCH 115/220] Fixed broken objective C detection. --- winpr/include/winpr/wtypes.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index b363ff3e4..1a7191fc6 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -88,11 +88,10 @@ #else #if defined(__x86_64__) || defined(__arm64__) #define __int3264 __int64 -#define __uint3264 unsigned __int64 +#define __uint3264 __uint64 #else #define __int3264 __int32 -#define __uint3264 unsigned __int32 -#endif +#define __uint3264 __uint32 #endif #if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) From d339b986de980a0e96ca78cb933deb3feb31acab Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 10 Nov 2015 11:45:49 +0100 Subject: [PATCH 116/220] Fixed broken #if #endif. --- winpr/include/winpr/wtypes.h | 1 + 1 file changed, 1 insertion(+) diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 1a7191fc6..2ba38fb1e 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -93,6 +93,7 @@ #define __int3264 __int32 #define __uint3264 __uint32 #endif +#endif #if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) typedef bool BOOL; From d81784cec62e25cf9a440fd198e9dec3659e7b9a Mon Sep 17 00:00:00 2001 From: Binyamin Sagal Date: Tue, 24 Nov 2015 15:41:46 +0200 Subject: [PATCH 117/220] remove horizontal scroll maping to forward/back partal fix for #2302 --- client/X11/xf_event.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 5f13d503d..25023d512 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -334,20 +334,21 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win flags = PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0088; break; - case 6: /* wheel left or back */ case 8: /* back */ case 97: /* Xming */ extended = TRUE; flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON1; break; - case 7: /* wheel right or forward */ case 9: /* forward */ case 112: /* Xming */ extended = TRUE; flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON2; break; + //TODO handle: case 6: /* wheel left or back */ + //TODO handle: case 7: /* wheel right or forward */ + default: x = 0; y = 0; From a5db7117c80c8ada6bc7f4d7a573d3025acd7d7a Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 14 Dec 2015 18:29:23 +0100 Subject: [PATCH 118/220] Implemented horizontal wheel support. Horizontal mouse wheel input capabilities are now checked and if available mouse buttons 6 and 7 are mapped to the horizontal wheel for the X11 client. --- client/X11/xf_event.c | 17 +- include/freerdp/input.h | 1 + include/freerdp/settings.h | 3 +- libfreerdp/core/capabilities.c | 4 +- libfreerdp/core/capabilities.h | 2 + libfreerdp/core/settings.c | 508 ++++++++++++++++----------------- 6 files changed, 275 insertions(+), 260 deletions(-) diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 25023d512..e5d80586c 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -331,7 +331,7 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win case 5: wheel = TRUE; - flags = PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0088; + flags = PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078; break; case 8: /* back */ @@ -346,9 +346,18 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON2; break; - //TODO handle: case 6: /* wheel left or back */ - //TODO handle: case 7: /* wheel right or forward */ - + case 6: /* wheel left */ + wheel = TRUE; + if (xfc->settings->HasHorizontalWheel) + flags = PTR_FLAGS_HWHEEL | 0x0078; + break; + + case 7: /* wheel right */ + wheel = TRUE; + if (xfc->settings->HasHorizontalWheel) + flags = PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078; + break; + default: x = 0; y = 0; diff --git a/include/freerdp/input.h b/include/freerdp/input.h index 57047129a..cbca343d2 100644 --- a/include/freerdp/input.h +++ b/include/freerdp/input.h @@ -35,6 +35,7 @@ typedef struct rdp_input rdpInput; #define KBD_FLAGS_RELEASE 0x8000 /* Pointer Flags */ +#define PTR_FLAGS_HWHEEL 0x0400 #define PTR_FLAGS_WHEEL 0x0200 #define PTR_FLAGS_WHEEL_NEGATIVE 0x0100 #define PTR_FLAGS_MOVE 0x0800 diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 388551a11..5b3d43199 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1232,7 +1232,8 @@ struct rdp_settings ALIGN64 BOOL MultiTouchInput; /* 2631 */ ALIGN64 BOOL MultiTouchGestures; /* 2632 */ ALIGN64 UINT32 KeyboardHook; /* 2633 */ - UINT64 padding2688[2688 - 2634]; /* 2634 */ + ALIGN64 BOOL HasHorizontalWheel; /* 2634 */ + UINT64 padding2688[2688 - 2635]; /* 2635 */ /* Brush Capabilities */ ALIGN64 UINT32 BrushSupportLevel; /* 2688 */ diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 0192b51fe..c1ac6d50a 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -1236,6 +1236,8 @@ BOOL rdp_read_input_capability_set(wStream* s, UINT16 length, rdpSettings* setti { /* advertised by RDP 5.2, 6.0, 6.1 and 7.0 servers */ } + else if (inputFlags & TS_INPUT_FLAG_MOUSE_HWHEEL) + settings->HasHorizontalWheel = TRUE; else { /* server does not support fastpath input */ @@ -1261,7 +1263,7 @@ void rdp_write_input_capability_set(wStream* s, rdpSettings* settings) header = rdp_capability_set_start(s); - inputFlags = INPUT_FLAG_SCANCODES | INPUT_FLAG_MOUSEX | INPUT_FLAG_UNICODE; + inputFlags = INPUT_FLAG_SCANCODES | INPUT_FLAG_MOUSEX | INPUT_FLAG_UNICODE | TS_INPUT_FLAG_MOUSE_HWHEEL; if (settings->FastPathInput) { diff --git a/libfreerdp/core/capabilities.h b/libfreerdp/core/capabilities.h index 4a6191d92..06ed108c5 100644 --- a/libfreerdp/core/capabilities.h +++ b/libfreerdp/core/capabilities.h @@ -98,6 +98,8 @@ #define INPUT_FLAG_FASTPATH_INPUT 0x0008 #define INPUT_FLAG_UNICODE 0x0010 #define INPUT_FLAG_FASTPATH_INPUT2 0x0020 +#define TS_INPUT_FLAG_MOUSE_HWHEEL 0x0100 +#define TS_INPUT_FLAG_QOE_TIMESTAMPS 0x0200 /* Font Support Flags */ #define FONTSUPPORT_FONTLIST 0x0001 diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 2fb632fac..df905ab7a 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -230,306 +230,306 @@ rdpSettings* freerdp_settings_new(DWORD flags) if (!settings) return NULL; - settings->ServerMode = (flags & FREERDP_SETTINGS_SERVER_MODE) ? TRUE : FALSE; - settings->WaitForOutputBufferFlush = TRUE; + settings->ServerMode = (flags & FREERDP_SETTINGS_SERVER_MODE) ? TRUE : FALSE; + settings->WaitForOutputBufferFlush = TRUE; - settings->DesktopWidth = 1024; - settings->DesktopHeight = 768; - settings->Workarea = FALSE; - settings->Fullscreen = FALSE; - settings->GrabKeyboard = TRUE; - settings->Decorations = TRUE; - settings->RdpVersion = 7; - settings->ColorDepth = 16; - settings->ExtSecurity = FALSE; - settings->NlaSecurity = TRUE; - settings->TlsSecurity = TRUE; - settings->RdpSecurity = TRUE; - settings->NegotiateSecurityLayer = TRUE; - settings->RestrictedAdminModeRequired = FALSE; - settings->MstscCookieMode = FALSE; - settings->CookieMaxLength = DEFAULT_COOKIE_MAX_LENGTH; - settings->ClientBuild = 2600; - settings->KeyboardType = 4; - settings->KeyboardSubType = 0; - settings->KeyboardFunctionKey = 12; - settings->KeyboardLayout = 0; - settings->UseRdpSecurityLayer = FALSE; - settings->SaltedChecksum = TRUE; - settings->ServerPort = 3389; - settings->GatewayPort = 443; - settings->DesktopResize = TRUE; - settings->ToggleFullscreen = TRUE; - settings->DesktopPosX = 0; - settings->DesktopPosY = 0; + settings->DesktopWidth = 1024; + settings->DesktopHeight = 768; + settings->Workarea = FALSE; + settings->Fullscreen = FALSE; + settings->GrabKeyboard = TRUE; + settings->Decorations = TRUE; + settings->RdpVersion = 7; + settings->ColorDepth = 16; + settings->ExtSecurity = FALSE; + settings->NlaSecurity = TRUE; + settings->TlsSecurity = TRUE; + settings->RdpSecurity = TRUE; + settings->NegotiateSecurityLayer = TRUE; + settings->RestrictedAdminModeRequired = FALSE; + settings->MstscCookieMode = FALSE; + settings->CookieMaxLength = DEFAULT_COOKIE_MAX_LENGTH; + settings->ClientBuild = 2600; + settings->KeyboardType = 4; + settings->KeyboardSubType = 0; + settings->KeyboardFunctionKey = 12; + settings->KeyboardLayout = 0; + settings->UseRdpSecurityLayer = FALSE; + settings->SaltedChecksum = TRUE; + settings->ServerPort = 3389; + settings->GatewayPort = 443; + settings->DesktopResize = TRUE; + settings->ToggleFullscreen = TRUE; + settings->DesktopPosX = 0; + settings->DesktopPosY = 0; - settings->PerformanceFlags = PERF_FLAG_NONE; - settings->AllowFontSmoothing = FALSE; - settings->AllowDesktopComposition = FALSE; - settings->DisableWallpaper = FALSE; - settings->DisableFullWindowDrag = TRUE; - settings->DisableMenuAnims = TRUE; - settings->DisableThemes = FALSE; - settings->ConnectionType = CONNECTION_TYPE_LAN; + settings->PerformanceFlags = PERF_FLAG_NONE; + settings->AllowFontSmoothing = FALSE; + settings->AllowDesktopComposition = FALSE; + settings->DisableWallpaper = FALSE; + settings->DisableFullWindowDrag = TRUE; + settings->DisableMenuAnims = TRUE; + settings->DisableThemes = FALSE; + settings->ConnectionType = CONNECTION_TYPE_LAN; - settings->EncryptionMethods = ENCRYPTION_METHOD_NONE; - settings->EncryptionLevel = ENCRYPTION_LEVEL_NONE; + settings->EncryptionMethods = ENCRYPTION_METHOD_NONE; + settings->EncryptionLevel = ENCRYPTION_LEVEL_NONE; - settings->CompressionEnabled = TRUE; + settings->CompressionEnabled = TRUE; - if (settings->ServerMode) - settings->CompressionLevel = PACKET_COMPR_TYPE_RDP61; - else - settings->CompressionLevel = PACKET_COMPR_TYPE_RDP61; + if (settings->ServerMode) + settings->CompressionLevel = PACKET_COMPR_TYPE_RDP61; + else + settings->CompressionLevel = PACKET_COMPR_TYPE_RDP61; - settings->Authentication = TRUE; - settings->AuthenticationOnly = FALSE; - settings->CredentialsFromStdin = FALSE; - settings->DisableCredentialsDelegation = FALSE; - settings->AuthenticationLevel = 2; + settings->Authentication = TRUE; + settings->AuthenticationOnly = FALSE; + settings->CredentialsFromStdin = FALSE; + settings->DisableCredentialsDelegation = FALSE; + settings->AuthenticationLevel = 2; - settings->ChannelCount = 0; - settings->ChannelDefArraySize = 32; - settings->ChannelDefArray = (CHANNEL_DEF*) calloc(settings->ChannelDefArraySize, sizeof(CHANNEL_DEF)); - if (!settings->ChannelDefArray) - goto out_fail; - - settings->MonitorCount = 0; - settings->MonitorDefArraySize = 32; - settings->MonitorDefArray = (rdpMonitor*) calloc(settings->MonitorDefArraySize, sizeof(rdpMonitor)); - if (!settings->MonitorDefArray) - goto out_fail; - - settings->MonitorLocalShiftX = 0; - settings->MonitorLocalShiftY = 0; - - settings->MonitorIds = (UINT32*) calloc(16, sizeof(UINT32)); - if(!settings->MonitorIds) - goto out_fail; - - if (!settings_get_computer_name(settings)) + settings->ChannelCount = 0; + settings->ChannelDefArraySize = 32; + settings->ChannelDefArray = (CHANNEL_DEF*) calloc(settings->ChannelDefArraySize, sizeof(CHANNEL_DEF)); + if (!settings->ChannelDefArray) goto out_fail; - settings->ReceivedCapabilities = calloc(1, 32); - if (!settings->ReceivedCapabilities) - goto out_fail; + settings->MonitorCount = 0; + settings->MonitorDefArraySize = 32; + settings->MonitorDefArray = (rdpMonitor*) calloc(settings->MonitorDefArraySize, sizeof(rdpMonitor)); + if (!settings->MonitorDefArray) + goto out_fail; - settings->OrderSupport = calloc(1, 32); - if (!settings->OrderSupport) - goto out_fail; + settings->MonitorLocalShiftX = 0; + settings->MonitorLocalShiftY = 0; - settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE; - settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = TRUE; - settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; - settings->OrderSupport[NEG_MEMBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_MEM3BLT_INDEX] = TRUE; - settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = TRUE; - settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE; - settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE; - settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYGON_SC_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYGON_CB_INDEX] = TRUE; - settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = TRUE; - settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = TRUE; + settings->MonitorIds = (UINT32*) calloc(16, sizeof(UINT32)); + if(!settings->MonitorIds) + goto out_fail; - settings->ClientProductId = calloc(1, 32); - if (!settings->ClientProductId) - goto out_fail; + if (!settings_get_computer_name(settings)) + goto out_fail; - settings->ClientHostname = calloc(1, 32); - if (!settings->ClientHostname) - goto out_fail; - gethostname(settings->ClientHostname, 31); - settings->ClientHostname[31] = 0; + settings->ReceivedCapabilities = calloc(1, 32); + if (!settings->ReceivedCapabilities) + goto out_fail; - settings->ColorPointerFlag = TRUE; - settings->LargePointerFlag = TRUE; - settings->PointerCacheSize = 20; - settings->SoundBeepsEnabled = TRUE; + settings->OrderSupport = calloc(1, 32); + if (!settings->OrderSupport) + goto out_fail; - settings->DrawGdiPlusEnabled = FALSE; + settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE; + settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = TRUE; + settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE; + settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = TRUE; + settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; + settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; + settings->OrderSupport[NEG_MEMBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_MEM3BLT_INDEX] = TRUE; + settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = TRUE; + settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE; + settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE; + settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE; + settings->OrderSupport[NEG_POLYGON_SC_INDEX] = TRUE; + settings->OrderSupport[NEG_POLYGON_CB_INDEX] = TRUE; + settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = TRUE; + settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = TRUE; - settings->DrawAllowSkipAlpha = TRUE; - settings->DrawAllowColorSubsampling = FALSE; - settings->DrawAllowDynamicColorFidelity = FALSE; + settings->ClientProductId = calloc(1, 32); + if (!settings->ClientProductId) + goto out_fail; - settings->FrameMarkerCommandEnabled = TRUE; - settings->SurfaceFrameMarkerEnabled = TRUE; - settings->BitmapCacheV3Enabled = FALSE; + settings->ClientHostname = calloc(1, 32); + if (!settings->ClientHostname) + goto out_fail; + gethostname(settings->ClientHostname, 31); + settings->ClientHostname[31] = 0; - settings->BitmapCacheEnabled = TRUE; - settings->BitmapCachePersistEnabled = FALSE; - settings->AllowCacheWaitingList = TRUE; + settings->ColorPointerFlag = TRUE; + settings->LargePointerFlag = TRUE; + settings->PointerCacheSize = 20; + settings->SoundBeepsEnabled = TRUE; - settings->BitmapCacheV2NumCells = 5; - settings->BitmapCacheV2CellInfo = (BITMAP_CACHE_V2_CELL_INFO*) malloc(sizeof(BITMAP_CACHE_V2_CELL_INFO) * 6); - if (!settings->BitmapCacheV2CellInfo) - goto out_fail; - settings->BitmapCacheV2CellInfo[0].numEntries = 600; - settings->BitmapCacheV2CellInfo[0].persistent = FALSE; - settings->BitmapCacheV2CellInfo[1].numEntries = 600; - settings->BitmapCacheV2CellInfo[1].persistent = FALSE; - settings->BitmapCacheV2CellInfo[2].numEntries = 2048; - settings->BitmapCacheV2CellInfo[2].persistent = FALSE; - settings->BitmapCacheV2CellInfo[3].numEntries = 4096; - settings->BitmapCacheV2CellInfo[3].persistent = FALSE; - settings->BitmapCacheV2CellInfo[4].numEntries = 2048; - settings->BitmapCacheV2CellInfo[4].persistent = FALSE; + settings->DrawGdiPlusEnabled = FALSE; - settings->NoBitmapCompressionHeader = TRUE; + settings->DrawAllowSkipAlpha = TRUE; + settings->DrawAllowColorSubsampling = FALSE; + settings->DrawAllowDynamicColorFidelity = FALSE; - settings->RefreshRect = TRUE; - settings->SuppressOutput = TRUE; + settings->FrameMarkerCommandEnabled = TRUE; + settings->SurfaceFrameMarkerEnabled = TRUE; + settings->BitmapCacheV3Enabled = FALSE; - settings->GlyphSupportLevel = GLYPH_SUPPORT_FULL; - settings->GlyphCache = malloc(sizeof(GLYPH_CACHE_DEFINITION) * 10); - if(!settings->GlyphCache) - goto out_fail; - settings->FragCache = malloc(sizeof(GLYPH_CACHE_DEFINITION)); - if(!settings->FragCache) - goto out_fail; - settings->GlyphCache[0].cacheEntries = 254; - settings->GlyphCache[0].cacheMaximumCellSize = 4; - settings->GlyphCache[1].cacheEntries = 254; - settings->GlyphCache[1].cacheMaximumCellSize = 4; - settings->GlyphCache[2].cacheEntries = 254; - settings->GlyphCache[2].cacheMaximumCellSize = 8; - settings->GlyphCache[3].cacheEntries = 254; - settings->GlyphCache[3].cacheMaximumCellSize = 8; - settings->GlyphCache[4].cacheEntries = 254; - settings->GlyphCache[4].cacheMaximumCellSize = 16; - settings->GlyphCache[5].cacheEntries = 254; - settings->GlyphCache[5].cacheMaximumCellSize = 32; - settings->GlyphCache[6].cacheEntries = 254; - settings->GlyphCache[6].cacheMaximumCellSize = 64; - settings->GlyphCache[7].cacheEntries = 254; - settings->GlyphCache[7].cacheMaximumCellSize = 128; - settings->GlyphCache[8].cacheEntries = 254; - settings->GlyphCache[8].cacheMaximumCellSize = 256; - settings->GlyphCache[9].cacheEntries = 64; - settings->GlyphCache[9].cacheMaximumCellSize = 256; - settings->FragCache->cacheEntries = 256; - settings->FragCache->cacheMaximumCellSize = 256; + settings->BitmapCacheEnabled = TRUE; + settings->BitmapCachePersistEnabled = FALSE; + settings->AllowCacheWaitingList = TRUE; - settings->OffscreenSupportLevel = TRUE; - settings->OffscreenCacheSize = 7680; - settings->OffscreenCacheEntries = 2000; + settings->BitmapCacheV2NumCells = 5; + settings->BitmapCacheV2CellInfo = (BITMAP_CACHE_V2_CELL_INFO*) malloc(sizeof(BITMAP_CACHE_V2_CELL_INFO) * 6); + if (!settings->BitmapCacheV2CellInfo) + goto out_fail; + settings->BitmapCacheV2CellInfo[0].numEntries = 600; + settings->BitmapCacheV2CellInfo[0].persistent = FALSE; + settings->BitmapCacheV2CellInfo[1].numEntries = 600; + settings->BitmapCacheV2CellInfo[1].persistent = FALSE; + settings->BitmapCacheV2CellInfo[2].numEntries = 2048; + settings->BitmapCacheV2CellInfo[2].persistent = FALSE; + settings->BitmapCacheV2CellInfo[3].numEntries = 4096; + settings->BitmapCacheV2CellInfo[3].persistent = FALSE; + settings->BitmapCacheV2CellInfo[4].numEntries = 2048; + settings->BitmapCacheV2CellInfo[4].persistent = FALSE; - settings->DrawNineGridCacheSize = 2560; - settings->DrawNineGridCacheEntries = 256; + settings->NoBitmapCompressionHeader = TRUE; - settings->ClientDir = _strdup(client_dll); - if (!settings->ClientDir) - goto out_fail; + settings->RefreshRect = TRUE; + settings->SuppressOutput = TRUE; - settings->RemoteAppNumIconCaches = 3; - settings->RemoteAppNumIconCacheEntries = 12; + settings->GlyphSupportLevel = GLYPH_SUPPORT_FULL; + settings->GlyphCache = malloc(sizeof(GLYPH_CACHE_DEFINITION) * 10); + if(!settings->GlyphCache) + goto out_fail; + settings->FragCache = malloc(sizeof(GLYPH_CACHE_DEFINITION)); + if(!settings->FragCache) + goto out_fail; + settings->GlyphCache[0].cacheEntries = 254; + settings->GlyphCache[0].cacheMaximumCellSize = 4; + settings->GlyphCache[1].cacheEntries = 254; + settings->GlyphCache[1].cacheMaximumCellSize = 4; + settings->GlyphCache[2].cacheEntries = 254; + settings->GlyphCache[2].cacheMaximumCellSize = 8; + settings->GlyphCache[3].cacheEntries = 254; + settings->GlyphCache[3].cacheMaximumCellSize = 8; + settings->GlyphCache[4].cacheEntries = 254; + settings->GlyphCache[4].cacheMaximumCellSize = 16; + settings->GlyphCache[5].cacheEntries = 254; + settings->GlyphCache[5].cacheMaximumCellSize = 32; + settings->GlyphCache[6].cacheEntries = 254; + settings->GlyphCache[6].cacheMaximumCellSize = 64; + settings->GlyphCache[7].cacheEntries = 254; + settings->GlyphCache[7].cacheMaximumCellSize = 128; + settings->GlyphCache[8].cacheEntries = 254; + settings->GlyphCache[8].cacheMaximumCellSize = 256; + settings->GlyphCache[9].cacheEntries = 64; + settings->GlyphCache[9].cacheMaximumCellSize = 256; + settings->FragCache->cacheEntries = 256; + settings->FragCache->cacheMaximumCellSize = 256; - settings->VirtualChannelChunkSize = CHANNEL_CHUNK_LENGTH; + settings->OffscreenSupportLevel = TRUE; + settings->OffscreenCacheSize = 7680; + settings->OffscreenCacheEntries = 2000; - settings->MultifragMaxRequestSize = 0xFFFF; + settings->DrawNineGridCacheSize = 2560; + settings->DrawNineGridCacheEntries = 256; - settings->GatewayUseSameCredentials = FALSE; - settings->GatewayBypassLocal = FALSE; - settings->GatewayRpcTransport = TRUE; - settings->GatewayHttpTransport = TRUE; - settings->GatewayUdpTransport = TRUE; + settings->ClientDir = _strdup(client_dll); + if (!settings->ClientDir) + goto out_fail; - settings->FastPathInput = TRUE; - settings->FastPathOutput = TRUE; + settings->RemoteAppNumIconCaches = 3; + settings->RemoteAppNumIconCacheEntries = 12; - settings->FrameAcknowledge = 2; - settings->MouseMotion = TRUE; + settings->VirtualChannelChunkSize = CHANNEL_CHUNK_LENGTH; - settings->NSCodecColorLossLevel = 3; - settings->NSCodecAllowSubsampling = TRUE; - settings->NSCodecAllowDynamicColorFidelity = TRUE; + settings->MultifragMaxRequestSize = 0xFFFF; - settings->AutoReconnectionEnabled = FALSE; - settings->AutoReconnectMaxRetries = 20; + settings->GatewayUseSameCredentials = FALSE; + settings->GatewayBypassLocal = FALSE; + settings->GatewayRpcTransport = TRUE; + settings->GatewayHttpTransport = TRUE; + settings->GatewayUdpTransport = TRUE; - settings->GfxThinClient = TRUE; - settings->GfxSmallCache = FALSE; - settings->GfxProgressive = FALSE; - settings->GfxProgressiveV2 = FALSE; - settings->GfxH264 = FALSE; + settings->FastPathInput = TRUE; + settings->FastPathOutput = TRUE; - settings->ClientAutoReconnectCookie = (ARC_CS_PRIVATE_PACKET*) calloc(1, sizeof(ARC_CS_PRIVATE_PACKET)); - if (!settings->ClientAutoReconnectCookie) - goto out_fail; - settings->ServerAutoReconnectCookie = (ARC_SC_PRIVATE_PACKET*) calloc(1, sizeof(ARC_SC_PRIVATE_PACKET)); - if (!settings->ServerAutoReconnectCookie) - goto out_fail; + settings->FrameAcknowledge = 2; + settings->MouseMotion = TRUE; - settings->ClientTimeZone = (TIME_ZONE_INFO*) calloc(1,sizeof(TIME_ZONE_INFO)); - if (!settings->ClientTimeZone) - goto out_fail; + settings->NSCodecColorLossLevel = 3; + settings->NSCodecAllowSubsampling = TRUE; + settings->NSCodecAllowDynamicColorFidelity = TRUE; - settings->DeviceArraySize = 16; - settings->DeviceArray = (RDPDR_DEVICE**) calloc(1, sizeof(RDPDR_DEVICE*) * settings->DeviceArraySize); - if (!settings->DeviceArray) - goto out_fail; + settings->AutoReconnectionEnabled = FALSE; + settings->AutoReconnectMaxRetries = 20; - settings->StaticChannelArraySize = 16; - settings->StaticChannelArray = (ADDIN_ARGV**) - calloc(1, sizeof(ADDIN_ARGV*) * settings->StaticChannelArraySize); - if (!settings->StaticChannelArray) - goto out_fail; + settings->GfxThinClient = TRUE; + settings->GfxSmallCache = FALSE; + settings->GfxProgressive = FALSE; + settings->GfxProgressiveV2 = FALSE; + settings->GfxH264 = FALSE; - settings->DynamicChannelArraySize = 16; - settings->DynamicChannelArray = (ADDIN_ARGV**) - calloc(1, sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize); - if(!settings->DynamicChannelArray) - goto out_fail; + settings->ClientAutoReconnectCookie = (ARC_CS_PRIVATE_PACKET*) calloc(1, sizeof(ARC_CS_PRIVATE_PACKET)); + if (!settings->ClientAutoReconnectCookie) + goto out_fail; + settings->ServerAutoReconnectCookie = (ARC_SC_PRIVATE_PACKET*) calloc(1, sizeof(ARC_SC_PRIVATE_PACKET)); + if (!settings->ServerAutoReconnectCookie) + goto out_fail; - settings->HomePath = GetKnownPath(KNOWN_PATH_HOME); - if (!settings->HomePath) - goto out_fail; + settings->ClientTimeZone = (TIME_ZONE_INFO*) calloc(1,sizeof(TIME_ZONE_INFO)); + if (!settings->ClientTimeZone) + goto out_fail; - /* For default FreeRDP continue using same config directory - * as in old releases. - * Custom builds use / as config folder. */ - if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING)) + settings->DeviceArraySize = 16; + settings->DeviceArray = (RDPDR_DEVICE**) calloc(1, sizeof(RDPDR_DEVICE*) * settings->DeviceArraySize); + if (!settings->DeviceArray) + goto out_fail; + + settings->StaticChannelArraySize = 16; + settings->StaticChannelArray = (ADDIN_ARGV**) + calloc(1, sizeof(ADDIN_ARGV*) * settings->StaticChannelArraySize); + if (!settings->StaticChannelArray) + goto out_fail; + + settings->DynamicChannelArraySize = 16; + settings->DynamicChannelArray = (ADDIN_ARGV**) + calloc(1, sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize); + if(!settings->DynamicChannelArray) + goto out_fail; + + settings->HomePath = GetKnownPath(KNOWN_PATH_HOME); + if (!settings->HomePath) + goto out_fail; + + /* For default FreeRDP continue using same config directory + * as in old releases. + * Custom builds use / as config folder. */ + if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING)) + { + base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, + FREERDP_VENDOR_STRING); + if (base) { - base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, - FREERDP_VENDOR_STRING); - if (base) - { - settings->ConfigPath = GetCombinedPath( - base, - FREERDP_PRODUCT_STRING); - } - free (base); - } else { - int i; - char product[sizeof(FREERDP_PRODUCT_STRING)]; - - memset(product, 0, sizeof(product)); - for (i=0; iConfigPath = GetKnownSubPath( - KNOWN_PATH_XDG_CONFIG_HOME, - product); + settings->ConfigPath = GetCombinedPath( + base, + FREERDP_PRODUCT_STRING); } + free (base); + } else { + int i; + char product[sizeof(FREERDP_PRODUCT_STRING)]; - if (!settings->ConfigPath) - goto out_fail; + memset(product, 0, sizeof(product)); + for (i=0; iConfigPath = GetKnownSubPath( + KNOWN_PATH_XDG_CONFIG_HOME, + product); + } - settings->SettingsModified = (BYTE*) calloc(1, sizeof(rdpSettings) / 8 ); - if(!settings->SettingsModified) - goto out_fail; + if (!settings->ConfigPath) + goto out_fail; + + settings_load_hkey_local_machine(settings); + + settings->SettingsModified = (BYTE*) calloc(1, sizeof(rdpSettings) / 8 ); + if(!settings->SettingsModified) + goto out_fail; return settings; From 23fea1615f05e100793a4add042e5df3fae3229e Mon Sep 17 00:00:00 2001 From: Binyamin Sagal Date: Mon, 14 Dec 2015 21:48:31 +0200 Subject: [PATCH 119/220] Fix horizontal scrolling direction and capability detection --- client/X11/xf_event.c | 4 ++-- libfreerdp/core/capabilities.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index e5d80586c..65291ac8c 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -349,13 +349,13 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win case 6: /* wheel left */ wheel = TRUE; if (xfc->settings->HasHorizontalWheel) - flags = PTR_FLAGS_HWHEEL | 0x0078; + flags = PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078; break; case 7: /* wheel right */ wheel = TRUE; if (xfc->settings->HasHorizontalWheel) - flags = PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078; + flags = PTR_FLAGS_HWHEEL | 0x0078; break; default: diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index c1ac6d50a..32ea34dff 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -1236,13 +1236,14 @@ BOOL rdp_read_input_capability_set(wStream* s, UINT16 length, rdpSettings* setti { /* advertised by RDP 5.2, 6.0, 6.1 and 7.0 servers */ } - else if (inputFlags & TS_INPUT_FLAG_MOUSE_HWHEEL) - settings->HasHorizontalWheel = TRUE; else { /* server does not support fastpath input */ settings->FastPathInput = FALSE; } + if (inputFlags & TS_INPUT_FLAG_MOUSE_HWHEEL) { + settings->HasHorizontalWheel = TRUE; + } } return TRUE; } From e223684fcb53a54c7541595730ed6b8526c01139 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 31 Jul 2015 11:31:21 +0200 Subject: [PATCH 120/220] args arrays static. When creating static builds the args arrays collided due to global visibility. --- client/common/cmdline.c | 2 +- winpr/tools/makecert/makecert.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 4fcac49ef..0ab7f324f 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -42,7 +42,7 @@ #include #define TAG CLIENT_TAG("common.cmdline") -COMMAND_LINE_ARGUMENT_A args[] = +static COMMAND_LINE_ARGUMENT_A args[] = { { "v", COMMAND_LINE_VALUE_REQUIRED, "[:port]", NULL, NULL, -1, NULL, "Server hostname" }, { "port", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "Server port" }, diff --git a/winpr/tools/makecert/makecert.c b/winpr/tools/makecert/makecert.c index 79de3f486..f4f4858bd 100644 --- a/winpr/tools/makecert/makecert.c +++ b/winpr/tools/makecert/makecert.c @@ -61,7 +61,7 @@ struct _MAKECERT_CONTEXT int duration_months; }; -COMMAND_LINE_ARGUMENT_A args[] = +static COMMAND_LINE_ARGUMENT_A args[] = { /* Custom Options */ From cb958ba9c62f05d101b886218d885d2c26c6ba55 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 31 Jul 2015 11:35:54 +0200 Subject: [PATCH 121/220] Added pdb files to package target. Fixed name collision with freerdp-shadow targets. --- CMakeCPack.cmake | 8 ++- channels/CMakeLists.txt | 10 ---- channels/audin/client/CMakeLists.txt | 5 +- channels/audin/client/alsa/CMakeLists.txt | 4 ++ channels/audin/client/winmm/CMakeLists.txt | 4 ++ channels/audin/server/CMakeLists.txt | 2 +- channels/cliprdr/client/CMakeLists.txt | 2 - channels/cliprdr/server/CMakeLists.txt | 2 - channels/disp/client/CMakeLists.txt | 4 ++ channels/drdynvc/client/CMakeLists.txt | 2 +- channels/drdynvc/server/CMakeLists.txt | 1 + channels/drive/client/CMakeLists.txt | 4 ++ channels/echo/client/CMakeLists.txt | 4 ++ channels/echo/server/CMakeLists.txt | 3 +- channels/encomsp/client/CMakeLists.txt | 1 + channels/encomsp/server/CMakeLists.txt | 1 + channels/parallel/client/CMakeLists.txt | 4 ++ channels/printer/client/CMakeLists.txt | 4 ++ channels/rail/client/CMakeLists.txt | 1 + channels/rdpdr/client/CMakeLists.txt | 1 + channels/rdpdr/server/CMakeLists.txt | 1 + channels/rdpei/client/CMakeLists.txt | 4 ++ channels/rdpei/server/CMakeLists.txt | 1 + channels/rdpgfx/client/CMakeLists.txt | 4 ++ channels/rdpsnd/client/CMakeLists.txt | 1 + channels/rdpsnd/client/winmm/CMakeLists.txt | 3 + channels/rdpsnd/server/CMakeLists.txt | 1 + channels/remdesk/client/CMakeLists.txt | 1 + channels/remdesk/server/CMakeLists.txt | 1 + channels/serial/client/CMakeLists.txt | 4 ++ channels/smartcard/client/CMakeLists.txt | 1 + channels/tsmf/client/CMakeLists.txt | 4 ++ channels/tsmf/client/ffmpeg/CMakeLists.txt | 4 ++ channels/tsmf/client/gstreamer/CMakeLists.txt | 4 ++ channels/urbdrc/client/CMakeLists.txt | 4 ++ channels/urbdrc/client/libusb/CMakeLists.txt | 4 ++ client/Windows/CMakeLists.txt | 10 +++- client/Windows/cli/CMakeLists.txt | 5 +- client/common/CMakeLists.txt | 4 ++ cmake/ConfigOptions.cmake | 1 + libfreerdp/CMakeLists.txt | 60 ++++++++++--------- rdtk/librdtk/CMakeLists.txt | 3 + server/Sample/CMakeLists.txt | 5 +- server/Windows/CMakeLists.txt | 8 +++ server/Windows/cli/CMakeLists.txt | 4 ++ server/common/CMakeLists.txt | 7 +++ server/shadow/CMakeLists.txt | 11 +++- winpr/libwinpr/CMakeLists.txt | 3 + winpr/tools/hash/CMakeLists.txt | 6 ++ winpr/tools/makecert/CMakeLists.txt | 2 - winpr/tools/makecert/cli/CMakeLists.txt | 5 ++ 51 files changed, 186 insertions(+), 57 deletions(-) diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake index f33be3db1..ca749c0cc 100644 --- a/CMakeCPack.cmake +++ b/CMakeCPack.cmake @@ -60,7 +60,7 @@ set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/resources\\\\FreeRDP_Install.bmp") set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/resources\\\\FreeRDP_Icon_96px.ico") set(CPACK_NSIS_MUI_UNICON "${CMAKE_SOURCE_DIR}/resource\\\\FreeRDP_Icon_96px.ico") -set(CPACK_COMPONENTS_ALL client server libraries headers) +set(CPACK_COMPONENTS_ALL client server libraries headers symbols tools) if(MSVC) if(MSVC_RUNTIME STREQUAL "dynamic") @@ -85,6 +85,12 @@ set(CPACK_COMPONENT_LIBRARIES_GROUP "Runtime") set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Headers") set(CPACK_COMPONENT_HEADERS_GROUP "Development") +set(CPACK_COMPONENT_SYMBOLS_DISPLAY_NAME "Symbols") +set(CPACK_COMPONENT_SYMBOLS_GROUP "Development") + +set(CPACK_COMPONENT_TOOLS_DISPLAY_NAME "Tools") +set(CPACK_COMPONENT_TOOLS_GROUP "Applications") + set(CPACK_COMPONENT_GROUP_RUNTIME_DESCRIPTION "Runtime") set(CPACK_COMPONENT_GROUP_APPLICATIONS_DESCRIPTION "Applications") set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "Development") diff --git a/channels/CMakeLists.txt b/channels/CMakeLists.txt index 540b1ac91..cb7880c34 100644 --- a/channels/CMakeLists.txt +++ b/channels/CMakeLists.txt @@ -155,10 +155,6 @@ macro(add_channel_client_subsystem _channel_prefix _channel_name _subsystem _typ endmacro(add_channel_client_subsystem) macro(add_channel_client_library _module_prefix _module_name _channel_name _dynamic _entry) - if(${_dynamic} AND MSVC AND (NOT STATIC_CHANNELS)) - set(${_module_prefix}_SRCS ${${_module_prefix}_SRCS} module.def) - endif() - if(${_dynamic} AND (NOT STATIC_CHANNELS)) # On windows create dll version information. # Vendor, product and year are already set in top level CMakeLists.txt @@ -188,9 +184,6 @@ macro(add_channel_client_library _module_prefix _module_name _channel_name _dyna endmacro(add_channel_client_library) macro(add_channel_client_subsystem_library _module_prefix _module_name _channel_name _type _dynamic _entry) - if(${_dynamic} AND MSVC AND (NOT STATIC_CHANNELS)) - set(${_module_prefix}_SRCS ${${_module_prefix}_SRCS} module.def) - endif() if(${_dynamic} AND (NOT STATIC_CHANNELS)) # On windows create dll version information. # Vendor, product and year are already set in top level CMakeLists.txt @@ -219,9 +212,6 @@ macro(add_channel_client_subsystem_library _module_prefix _module_name _channel_ endmacro(add_channel_client_subsystem_library) macro(add_channel_server_library _module_prefix _module_name _channel_name _dynamic _entry) - if(${_dynamic} AND MSVC AND (NOT STATIC_CHANNELS)) - set(${_module_prefix}_SRCS ${${_module_prefix}_SRCS} module.def) - endif() if(${_dynamic} AND (NOT STATIC_CHANNELS)) # On windows create dll version information. # Vendor, product and year are already set in top level CMakeLists.txt diff --git a/channels/audin/client/CMakeLists.txt b/channels/audin/client/CMakeLists.txt index a13a930c3..32e3e3bde 100644 --- a/channels/audin/client/CMakeLists.txt +++ b/channels/audin/client/CMakeLists.txt @@ -25,11 +25,12 @@ include_directories(..) add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") - - target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/audin/client/alsa/CMakeLists.txt b/channels/audin/client/alsa/CMakeLists.txt index 46c756bc7..bb2df3230 100644 --- a/channels/audin/client/alsa/CMakeLists.txt +++ b/channels/audin/client/alsa/CMakeLists.txt @@ -33,3 +33,7 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + diff --git a/channels/audin/client/winmm/CMakeLists.txt b/channels/audin/client/winmm/CMakeLists.txt index a71f1c6d8..52dd91dd6 100644 --- a/channels/audin/client/winmm/CMakeLists.txt +++ b/channels/audin/client/winmm/CMakeLists.txt @@ -33,4 +33,8 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/winmm") diff --git a/channels/audin/server/CMakeLists.txt b/channels/audin/server/CMakeLists.txt index 7f5308957..be2ee52b5 100644 --- a/channels/audin/server/CMakeLists.txt +++ b/channels/audin/server/CMakeLists.txt @@ -27,5 +27,5 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/cliprdr/client/CMakeLists.txt b/channels/cliprdr/client/CMakeLists.txt index 99f3b6621..867ed7230 100644 --- a/channels/cliprdr/client/CMakeLists.txt +++ b/channels/cliprdr/client/CMakeLists.txt @@ -25,8 +25,6 @@ set(${MODULE_PREFIX}_SRCS add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") - - set(${MODULE_PREFIX}_LIBS freerdp winpr) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/cliprdr/server/CMakeLists.txt b/channels/cliprdr/server/CMakeLists.txt index 41d993236..5bd32583a 100644 --- a/channels/cliprdr/server/CMakeLists.txt +++ b/channels/cliprdr/server/CMakeLists.txt @@ -23,8 +23,6 @@ set(${MODULE_PREFIX}_SRCS add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") - - target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/disp/client/CMakeLists.txt b/channels/disp/client/CMakeLists.txt index f5072e5d9..61adc34d3 100644 --- a/channels/disp/client/CMakeLists.txt +++ b/channels/disp/client/CMakeLists.txt @@ -33,4 +33,8 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/drdynvc/client/CMakeLists.txt b/channels/drdynvc/client/CMakeLists.txt index 3401865af..0c323c0cc 100644 --- a/channels/drdynvc/client/CMakeLists.txt +++ b/channels/drdynvc/client/CMakeLists.txt @@ -24,5 +24,5 @@ set(${MODULE_PREFIX}_SRCS add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/drdynvc/server/CMakeLists.txt b/channels/drdynvc/server/CMakeLists.txt index 4729a8287..d0de5d5d9 100644 --- a/channels/drdynvc/server/CMakeLists.txt +++ b/channels/drdynvc/server/CMakeLists.txt @@ -29,4 +29,5 @@ target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/drive/client/CMakeLists.txt b/channels/drive/client/CMakeLists.txt index a9e0c2631..64495875f 100644 --- a/channels/drive/client/CMakeLists.txt +++ b/channels/drive/client/CMakeLists.txt @@ -37,4 +37,8 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/echo/client/CMakeLists.txt b/channels/echo/client/CMakeLists.txt index 9db6718bf..d7b69576d 100644 --- a/channels/echo/client/CMakeLists.txt +++ b/channels/echo/client/CMakeLists.txt @@ -31,4 +31,8 @@ target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/echo/server/CMakeLists.txt b/channels/echo/server/CMakeLists.txt index 4fcf3a3b8..3d6b60807 100644 --- a/channels/echo/server/CMakeLists.txt +++ b/channels/echo/server/CMakeLists.txt @@ -27,5 +27,6 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - + + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/encomsp/client/CMakeLists.txt b/channels/encomsp/client/CMakeLists.txt index f4d0e4c70..f43bf6258 100644 --- a/channels/encomsp/client/CMakeLists.txt +++ b/channels/encomsp/client/CMakeLists.txt @@ -31,4 +31,5 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/encomsp/server/CMakeLists.txt b/channels/encomsp/server/CMakeLists.txt index 24246268d..f0ea76b1c 100644 --- a/channels/encomsp/server/CMakeLists.txt +++ b/channels/encomsp/server/CMakeLists.txt @@ -33,4 +33,5 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/parallel/client/CMakeLists.txt b/channels/parallel/client/CMakeLists.txt index 6966ed5ea..8713a3da6 100644 --- a/channels/parallel/client/CMakeLists.txt +++ b/channels/parallel/client/CMakeLists.txt @@ -28,4 +28,8 @@ target_link_libraries(${MODULE_NAME} freerdp winpr) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/printer/client/CMakeLists.txt b/channels/printer/client/CMakeLists.txt index 0d43436c2..be756452a 100644 --- a/channels/printer/client/CMakeLists.txt +++ b/channels/printer/client/CMakeLists.txt @@ -50,4 +50,8 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rail/client/CMakeLists.txt b/channels/rail/client/CMakeLists.txt index 111e59263..745ac1689 100644 --- a/channels/rail/client/CMakeLists.txt +++ b/channels/rail/client/CMakeLists.txt @@ -33,4 +33,5 @@ target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpdr/client/CMakeLists.txt b/channels/rdpdr/client/CMakeLists.txt index 884bf98be..c672c5238 100644 --- a/channels/rdpdr/client/CMakeLists.txt +++ b/channels/rdpdr/client/CMakeLists.txt @@ -35,4 +35,5 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpdr/server/CMakeLists.txt b/channels/rdpdr/server/CMakeLists.txt index e5a98cb64..8da697f6d 100644 --- a/channels/rdpdr/server/CMakeLists.txt +++ b/channels/rdpdr/server/CMakeLists.txt @@ -29,4 +29,5 @@ target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/rdpei/client/CMakeLists.txt b/channels/rdpei/client/CMakeLists.txt index 875efac86..7cad5201a 100644 --- a/channels/rdpei/client/CMakeLists.txt +++ b/channels/rdpei/client/CMakeLists.txt @@ -32,4 +32,8 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpei/server/CMakeLists.txt b/channels/rdpei/server/CMakeLists.txt index e98c4576f..a20c36cec 100644 --- a/channels/rdpei/server/CMakeLists.txt +++ b/channels/rdpei/server/CMakeLists.txt @@ -35,4 +35,5 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/rdpgfx/client/CMakeLists.txt b/channels/rdpgfx/client/CMakeLists.txt index c06274d7a..d657a2f79 100644 --- a/channels/rdpgfx/client/CMakeLists.txt +++ b/channels/rdpgfx/client/CMakeLists.txt @@ -35,5 +35,9 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpsnd/client/CMakeLists.txt b/channels/rdpsnd/client/CMakeLists.txt index de63a3261..ce09b8b17 100644 --- a/channels/rdpsnd/client/CMakeLists.txt +++ b/channels/rdpsnd/client/CMakeLists.txt @@ -29,6 +29,7 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") if(WITH_OSS) diff --git a/channels/rdpsnd/client/winmm/CMakeLists.txt b/channels/rdpsnd/client/winmm/CMakeLists.txt index 11fa19026..45a4f332b 100644 --- a/channels/rdpsnd/client/winmm/CMakeLists.txt +++ b/channels/rdpsnd/client/winmm/CMakeLists.txt @@ -33,5 +33,8 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/WinMM") diff --git a/channels/rdpsnd/server/CMakeLists.txt b/channels/rdpsnd/server/CMakeLists.txt index afdd9db56..990275f38 100644 --- a/channels/rdpsnd/server/CMakeLists.txt +++ b/channels/rdpsnd/server/CMakeLists.txt @@ -29,4 +29,5 @@ target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/remdesk/client/CMakeLists.txt b/channels/remdesk/client/CMakeLists.txt index 570c5e62c..744e3ec12 100644 --- a/channels/remdesk/client/CMakeLists.txt +++ b/channels/remdesk/client/CMakeLists.txt @@ -29,4 +29,5 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/remdesk/server/CMakeLists.txt b/channels/remdesk/server/CMakeLists.txt index dad21c276..cdcbbabac 100644 --- a/channels/remdesk/server/CMakeLists.txt +++ b/channels/remdesk/server/CMakeLists.txt @@ -31,4 +31,5 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/serial/client/CMakeLists.txt b/channels/serial/client/CMakeLists.txt index 3ca69cc89..8611755ef 100644 --- a/channels/serial/client/CMakeLists.txt +++ b/channels/serial/client/CMakeLists.txt @@ -28,4 +28,8 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/smartcard/client/CMakeLists.txt b/channels/smartcard/client/CMakeLists.txt index 05e4405c9..dc25a6c43 100644 --- a/channels/smartcard/client/CMakeLists.txt +++ b/channels/smartcard/client/CMakeLists.txt @@ -32,4 +32,5 @@ target_link_libraries(${MODULE_NAME} winpr freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/tsmf/client/CMakeLists.txt b/channels/tsmf/client/CMakeLists.txt index b47a616a2..b13b29187 100644 --- a/channels/tsmf/client/CMakeLists.txt +++ b/channels/tsmf/client/CMakeLists.txt @@ -44,6 +44,10 @@ target_link_libraries(${MODULE_NAME} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") if(WITH_FFMPEG) diff --git a/channels/tsmf/client/ffmpeg/CMakeLists.txt b/channels/tsmf/client/ffmpeg/CMakeLists.txt index 96c3efb4b..7f9131bc4 100644 --- a/channels/tsmf/client/ffmpeg/CMakeLists.txt +++ b/channels/tsmf/client/ffmpeg/CMakeLists.txt @@ -40,3 +40,7 @@ else() endif() install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + diff --git a/channels/tsmf/client/gstreamer/CMakeLists.txt b/channels/tsmf/client/gstreamer/CMakeLists.txt index d0a6eab9c..06347ffda 100644 --- a/channels/tsmf/client/gstreamer/CMakeLists.txt +++ b/channels/tsmf/client/gstreamer/CMakeLists.txt @@ -65,3 +65,7 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N target_link_libraries(${MODULE_NAME} ${LIBS} freerdp) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + diff --git a/channels/urbdrc/client/CMakeLists.txt b/channels/urbdrc/client/CMakeLists.txt index 5b0bc314a..7694c4303 100644 --- a/channels/urbdrc/client/CMakeLists.txt +++ b/channels/urbdrc/client/CMakeLists.txt @@ -50,6 +50,10 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") # libusb subsystem diff --git a/channels/urbdrc/client/libusb/CMakeLists.txt b/channels/urbdrc/client/libusb/CMakeLists.txt index 696523d17..c9db8d65f 100644 --- a/channels/urbdrc/client/libusb/CMakeLists.txt +++ b/channels/urbdrc/client/libusb/CMakeLists.txt @@ -46,3 +46,7 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) +endif() + diff --git a/client/Windows/CMakeLists.txt b/client/Windows/CMakeLists.txt index aef68b16d..e4a5fa3b7 100644 --- a/client/Windows/CMakeLists.txt +++ b/client/Windows/CMakeLists.txt @@ -66,9 +66,9 @@ if(WITH_CLIENT_INTERFACE) add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) endif() if (WITH_LIBRARY_VERSIONING) - set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) + set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) endif() - + else() set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} cli/wfreerdp.c cli/wfreerdp.h) add_executable(${MODULE_NAME} WIN32 ${${MODULE_PREFIX}_SRCS}) @@ -80,9 +80,15 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) if(WITH_CLIENT_INTERFACE) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) + if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + endif() add_subdirectory(cli) else() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) + if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) + endif() endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Windows") diff --git a/client/Windows/cli/CMakeLists.txt b/client/Windows/cli/CMakeLists.txt index 35da67382..2dd0de701 100644 --- a/client/Windows/cli/CMakeLists.txt +++ b/client/Windows/cli/CMakeLists.txt @@ -46,8 +46,9 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} wfreerdp-client) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -if(VENDOR MATCHES "FreeRDP") - install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) +install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Windows") diff --git a/client/common/CMakeLists.txt b/client/common/CMakeLists.txt index 9f6e4bf90..101d6e198 100644 --- a/client/common/CMakeLists.txt +++ b/client/common/CMakeLists.txt @@ -84,6 +84,10 @@ endif() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Common") if(BUILD_TESTING) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 965bba732..90ffb0e0b 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -120,6 +120,7 @@ option(WITH_DEBUG_X11_LOCAL_MOVESIZE "Print X11 Client local movesize debug mess option(WITH_DEBUG_X11 "Print X11 Client debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_XV "Print XVideo debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_RINGBUFFER "Enable Ringbuffer debug messages" ${DEFAULT_DEBUG_OPTION}) +option(WITH_DEBUG_SYMBOLS "Pack debug symbols to installer" NO) if(ANDROID) include(ConfigOptionsAndroid) diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt index 7e75370a9..00f751757 100644 --- a/libfreerdp/CMakeLists.txt +++ b/libfreerdp/CMakeLists.txt @@ -21,8 +21,8 @@ set(MODULE_PREFIX "FREERDP") # Create imported targets for Intel IPP libraries if(IPP_FOUND) - foreach(ipp_lib ${IPP_LIBRARIES}) - add_library("${ipp_lib}_imported" STATIC IMPORTED) + foreach(ipp_lib ${IPP_LIBRARIES}) + add_library("${ipp_lib}_imported" STATIC IMPORTED) set_property(TARGET "${ipp_lib}_imported" PROPERTY IMPORTED_LOCATION "${IPP_LIBRARY_DIRS}/${ipp_lib}") endforeach() endif() @@ -34,22 +34,22 @@ set(LIBFREERDP_INCLUDES "") set(LIBFREERDP_DEFINITIONS "") macro (freerdp_module_add) - file (RELATIVE_PATH _relPath "${LIBFREERDP_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") - foreach (_src ${ARGN}) - if (_relPath) - list (APPEND LIBFREERDP_SRCS "${_relPath}/${_src}") - else() - list (APPEND LIBFREERDP_SRCS "${_src}") - endif() - endforeach() - if (_relPath) - set (LIBFREERDP_SRCS ${LIBFREERDP_SRCS} PARENT_SCOPE) - endif() + file (RELATIVE_PATH _relPath "${LIBFREERDP_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + foreach (_src ${ARGN}) + if (_relPath) + list (APPEND LIBFREERDP_SRCS "${_relPath}/${_src}") + else() + list (APPEND LIBFREERDP_SRCS "${_src}") + endif() + endforeach() + if (_relPath) + set (LIBFREERDP_SRCS ${LIBFREERDP_SRCS} PARENT_SCOPE) + endif() endmacro() macro (freerdp_include_directory_add) - file (RELATIVE_PATH _relPath "${LIBFREERDP_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") - foreach (_inc ${ARGN}) + file (RELATIVE_PATH _relPath "${LIBFREERDP_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + foreach (_inc ${ARGN}) if (IS_ABSOLUTE ${_inc}) list (APPEND LIBFREERDP_INCLUDES "${_inc}") else() @@ -59,24 +59,24 @@ macro (freerdp_include_directory_add) list (APPEND LIBFREERDP_INCLUDES "${_inc}") endif() endif() - endforeach() - if (_relPath) - set (LIBFREERDP_INCLUDES ${LIBFREERDP_INCLUDES} PARENT_SCOPE) - endif() + endforeach() + if (_relPath) + set (LIBFREERDP_INCLUDES ${LIBFREERDP_INCLUDES} PARENT_SCOPE) + endif() endmacro() macro (freerdp_library_add) - foreach (_lib ${ARGN}) - list (APPEND LIBFREERDP_LIBS "${_lib}") - endforeach() - set (LIBFREERDP_LIBS ${LIBFREERDP_LIBS} PARENT_SCOPE) + foreach (_lib ${ARGN}) + list (APPEND LIBFREERDP_LIBS "${_lib}") + endforeach() + set (LIBFREERDP_LIBS ${LIBFREERDP_LIBS} PARENT_SCOPE) endmacro() macro (freerdp_definition_add) - foreach (_define ${ARGN}) - list (APPEND LIBFREERDP_DEFINITIONS "${_define}") - endforeach() - set (LIBFREERDP_DEFINITIONS ${LIBFREERDP_DEFINITIONS} PARENT_SCOPE) + foreach (_define ${ARGN}) + list (APPEND LIBFREERDP_DEFINITIONS "${_define}") + endforeach() + set (LIBFREERDP_DEFINITIONS ${LIBFREERDP_DEFINITIONS} PARENT_SCOPE) endmacro() set(${MODULE_PREFIX}_SUBMODULES @@ -263,7 +263,7 @@ freerdp_module_add(${PRIMITIVES_SRCS}) if(IPP_FOUND) freerdp_include_directory_add(${IPP_INCLUDE_DIRS}) - foreach(ipp_lib ${IPP_LIBRARIES}) + foreach(ipp_lib ${IPP_LIBRARIES}) freerdp_library_add("${ipp_lib}_imported") endforeach() endif() @@ -308,4 +308,8 @@ endif() target_link_libraries(${MODULE_NAME} ${LIBFREERDP_LIBS} winpr) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/libfreerdp") diff --git a/rdtk/librdtk/CMakeLists.txt b/rdtk/librdtk/CMakeLists.txt index 950cc7d4b..7b255657d 100644 --- a/rdtk/librdtk/CMakeLists.txt +++ b/rdtk/librdtk/CMakeLists.txt @@ -65,6 +65,9 @@ endif() target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT RdTkTargets) +if (MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "RdTk") diff --git a/server/Sample/CMakeLists.txt b/server/Sample/CMakeLists.txt index 397e7048c..9e92437cd 100644 --- a/server/Sample/CMakeLists.txt +++ b/server/Sample/CMakeLists.txt @@ -50,6 +50,9 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-server) set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server) +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Sample") diff --git a/server/Windows/CMakeLists.txt b/server/Windows/CMakeLists.txt index 6d047fcee..fc7b159f2 100644 --- a/server/Windows/CMakeLists.txt +++ b/server/Windows/CMakeLists.txt @@ -99,8 +99,16 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) if(WITH_SERVER_INTERFACE) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) + + if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + endif() else() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server) + + if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) + endif() endif() if(WITH_SERVER_INTERFACE) diff --git a/server/Windows/cli/CMakeLists.txt b/server/Windows/cli/CMakeLists.txt index 39d94c7c3..e60de909d 100644 --- a/server/Windows/cli/CMakeLists.txt +++ b/server/Windows/cli/CMakeLists.txt @@ -48,4 +48,8 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server) +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Windows") diff --git a/server/common/CMakeLists.txt b/server/common/CMakeLists.txt index c8f2c81a3..373caa9d4 100644 --- a/server/common/CMakeLists.txt +++ b/server/common/CMakeLists.txt @@ -21,6 +21,10 @@ set(MODULE_PREFIX "FREERDP_SERVER") set(${MODULE_PREFIX}_SRCS server.c) +foreach(FREERDP_CHANNELS_SERVER_SRC ${FREERDP_CHANNELS_SERVER_SRCS}) + set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} "${FREERDP_CHANNELS_SERVER_SRC}") +endforeach() + if(MSVC) set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def) endif() @@ -59,6 +63,9 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Common") export_complex_library(LIBNAME ${MODULE_NAME}) diff --git a/server/shadow/CMakeLists.txt b/server/shadow/CMakeLists.txt index eda2f617d..d51371f68 100644 --- a/server/shadow/CMakeLists.txt +++ b/server/shadow/CMakeLists.txt @@ -250,6 +250,10 @@ endif() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT server) +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/shadow") # command-line executable @@ -277,12 +281,15 @@ if (WIN32) endif() add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) -set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "freerdp-shadow") set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-shadow) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server) +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/shadow") diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt index 5a802ba49..711dbb5c1 100644 --- a/winpr/libwinpr/CMakeLists.txt +++ b/winpr/libwinpr/CMakeLists.txt @@ -120,4 +120,7 @@ endif() add_definitions(${WINPR_DEFINITIONS}) target_link_libraries(${MODULE_NAME} ${WINPR_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT WinPRTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/libwinpr") diff --git a/winpr/tools/hash/CMakeLists.txt b/winpr/tools/hash/CMakeLists.txt index 8ab20e837..7b9195a05 100644 --- a/winpr/tools/hash/CMakeLists.txt +++ b/winpr/tools/hash/CMakeLists.txt @@ -43,4 +43,10 @@ set(${MODULE_PREFIX}_LIBS winpr) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools EXPORT WinPRTargets) + +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) +endif() + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") diff --git a/winpr/tools/makecert/CMakeLists.txt b/winpr/tools/makecert/CMakeLists.txt index ce72f7d2b..b33e7b15f 100644 --- a/winpr/tools/makecert/CMakeLists.txt +++ b/winpr/tools/makecert/CMakeLists.txt @@ -42,8 +42,6 @@ endif() target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT WinPRTargets) - add_subdirectory(cli) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") diff --git a/winpr/tools/makecert/cli/CMakeLists.txt b/winpr/tools/makecert/cli/CMakeLists.txt index 3e3086e32..6a08a1b88 100644 --- a/winpr/tools/makecert/cli/CMakeLists.txt +++ b/winpr/tools/makecert/cli/CMakeLists.txt @@ -47,3 +47,8 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools EXPORT WinPRTargets) +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) +endif() + From 6ed43cd6ecdbabaecc02c735da732ffe2cc9e729 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 19 Aug 2015 09:02:20 +0200 Subject: [PATCH 122/220] Updated pdb file locations. Now supporting generators NMake and Visual Studio. --- CMakeLists.txt | 9 +++++++ channels/rdpsnd/client/winmm/CMakeLists.txt | 2 +- client/Windows/CMakeLists.txt | 4 +-- client/Windows/cli/CMakeLists.txt | 2 +- client/common/CMakeLists.txt | 6 ++--- libfreerdp/CMakeLists.txt | 6 ++--- rdtk/librdtk/CMakeLists.txt | 2 +- server/Sample/CMakeLists.txt | 2 +- server/common/CMakeLists.txt | 2 +- winpr/libwinpr/CMakeLists.txt | 30 ++++++++++----------- winpr/tools/makecert/cli/CMakeLists.txt | 2 +- 11 files changed, 38 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 411bdef73..0907cc1cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,15 @@ if(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN") + set(CMAKE_USE_RELATIVE_PATH ON) + if (${CMAKE_GENERATOR} MATCHES "NMake Makefile*") + set(CMAKE_PDB_BINARY_DIR ${CMAKE_BINARY_DIR}) + elseif (${CMAKE_GENERATOR} MATCHES "Visual Studio*") + set(CMAKE_PDB_BINARY_DIR "${CMAKE_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}") + else() + message(FATAL "Unknown generator ${CMAKE_GENERATOR}") + endif() + # Set product and vendor for dll and exe version information. set(RC_VERSION_VENDOR ${VENDOR}) set(RC_VERSION_PRODUCT ${PRODUCT}) diff --git a/channels/rdpsnd/client/winmm/CMakeLists.txt b/channels/rdpsnd/client/winmm/CMakeLists.txt index 45a4f332b..e1515b9ac 100644 --- a/channels/rdpsnd/client/winmm/CMakeLists.txt +++ b/channels/rdpsnd/client/winmm/CMakeLists.txt @@ -34,7 +34,7 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/WinMM") diff --git a/client/Windows/CMakeLists.txt b/client/Windows/CMakeLists.txt index e4a5fa3b7..d2d513f7d 100644 --- a/client/Windows/CMakeLists.txt +++ b/client/Windows/CMakeLists.txt @@ -81,13 +81,13 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) if(WITH_CLIENT_INTERFACE) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() add_subdirectory(cli) else() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) if (WITH_DEBUG_SYMBOLS AND MSVC) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) endif() endif() diff --git a/client/Windows/cli/CMakeLists.txt b/client/Windows/cli/CMakeLists.txt index 2dd0de701..02726118f 100644 --- a/client/Windows/cli/CMakeLists.txt +++ b/client/Windows/cli/CMakeLists.txt @@ -48,7 +48,7 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) if (WITH_DEBUG_SYMBOLS AND MSVC) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Windows") diff --git a/client/common/CMakeLists.txt b/client/common/CMakeLists.txt index 101d6e198..747b2f2ce 100644 --- a/client/common/CMakeLists.txt +++ b/client/common/CMakeLists.txt @@ -70,10 +70,10 @@ endif() set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${FREERDP_CHANNELS_CLIENT_LIBS}) - + set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES}) - + set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) if(OPENBSD) @@ -85,7 +85,7 @@ endif() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Common") diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt index 00f751757..675d6b663 100644 --- a/libfreerdp/CMakeLists.txt +++ b/libfreerdp/CMakeLists.txt @@ -242,7 +242,7 @@ if(WITH_SSE2) endif() elseif(WITH_NEON) if(CMAKE_COMPILER_IS_GNUCC) - set(OPTIMIZATION "${OPTIMIZATION} -mfpu=neon") + set(OPTIMIZATION "${OPTIMIZATION} -mfpu=neon") endif() # TODO: Add MSVC equivalent endif() @@ -302,14 +302,14 @@ add_definitions(${LIBFREERDP_DEFINITIONS}) set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C) if (WITH_LIBRARY_VERSIONING) - set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) + set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) endif() target_link_libraries(${MODULE_NAME} ${LIBFREERDP_LIBS} winpr) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/libfreerdp") diff --git a/rdtk/librdtk/CMakeLists.txt b/rdtk/librdtk/CMakeLists.txt index 7b255657d..e12f162b6 100644 --- a/rdtk/librdtk/CMakeLists.txt +++ b/rdtk/librdtk/CMakeLists.txt @@ -66,7 +66,7 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT RdTkTargets) if (MSVC AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "RdTk") diff --git a/server/Sample/CMakeLists.txt b/server/Sample/CMakeLists.txt index 9e92437cd..451f3e960 100644 --- a/server/Sample/CMakeLists.txt +++ b/server/Sample/CMakeLists.txt @@ -52,7 +52,7 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server) if (WITH_DEBUG_SYMBOLS AND MSVC) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Sample") diff --git a/server/common/CMakeLists.txt b/server/common/CMakeLists.txt index 373caa9d4..1f01d0076 100644 --- a/server/common/CMakeLists.txt +++ b/server/common/CMakeLists.txt @@ -64,7 +64,7 @@ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Common") diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt index 711dbb5c1..65f9af0ec 100644 --- a/winpr/libwinpr/CMakeLists.txt +++ b/winpr/libwinpr/CMakeLists.txt @@ -18,7 +18,7 @@ if (APPLE) # flat_namespace should be avoided, but is required for -undefined warning. Since WinPR currently has # a lot of undefined symbols in use, use this hack until they're filled out. - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-flat_namespace,-undefined,warning") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-flat_namespace,-undefined,warning") endif() set(WINPR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) @@ -44,15 +44,15 @@ endmacro() macro (winpr_include_directory_add) file (RELATIVE_PATH _relPath "${WINPR_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") foreach (_inc ${ARGN}) - if (IS_ABSOLUTE ${_inc}) - list (APPEND WINPR_INCLUDES "${_inc}") - else() - if (_relPath) - list (APPEND WINPR_INCLUDES "${_relPath}/${_inc}") - else() - list (APPEND WINPR_INCLUDES "${_inc}") - endif() - endif() + if (IS_ABSOLUTE ${_inc}) + list (APPEND WINPR_INCLUDES "${_inc}") + else() + if (_relPath) + list (APPEND WINPR_INCLUDES "${_relPath}/${_inc}") + else() + list (APPEND WINPR_INCLUDES "${_inc}") + endif() + endif() endforeach() if (_relPath) set (WINPR_INCLUDES ${WINPR_INCLUDES} PARENT_SCOPE) @@ -74,15 +74,15 @@ macro (winpr_definition_add) endmacro() # Level "1" API as defined for MinCore.lib -set(WINPR_CORE synch locale library file comm pipe interlocked security +set(WINPR_CORE synch locale library file comm pipe interlocked security environment crypto registry credentials path io memory input shell - heap utils error com timezone sysinfo pool handle thread) + heap utils error com timezone sysinfo pool handle thread) foreach(DIR ${WINPR_CORE}) add_subdirectory(${DIR}) endforeach() -set(WINPR_LEVEL2 winsock sspi winhttp asn1 sspicli crt bcrypt rpc credui +set(WINPR_LEVEL2 winsock sspi winhttp asn1 sspicli crt bcrypt rpc credui wtsapi dsparse wnd smartcard nt clipboard) foreach(DIR ${WINPR_LEVEL2}) @@ -114,13 +114,13 @@ endif() add_library(${MODULE_NAME} ${WINPR_SRCS}) set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C) if (WITH_LIBRARY_VERSIONING) - set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SOVERSION ${WINPR_VERSION}) + set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SOVERSION ${WINPR_VERSION}) endif() add_definitions(${WINPR_DEFINITIONS}) target_link_libraries(${MODULE_NAME} ${WINPR_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT WinPRTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/libwinpr") diff --git a/winpr/tools/makecert/cli/CMakeLists.txt b/winpr/tools/makecert/cli/CMakeLists.txt index 6a08a1b88..f175e72d5 100644 --- a/winpr/tools/makecert/cli/CMakeLists.txt +++ b/winpr/tools/makecert/cli/CMakeLists.txt @@ -49,6 +49,6 @@ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools EXPORT WinPRTargets) if (WITH_DEBUG_SYMBOLS AND MSVC) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) + install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols) endif() From 197ba27d72a28161c448df57e9c3751cc2ef11fa Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 15 Dec 2015 17:19:58 +0100 Subject: [PATCH 123/220] Changed symbol install to OFF. --- cmake/ConfigOptions.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 90ffb0e0b..47019f654 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -120,7 +120,8 @@ option(WITH_DEBUG_X11_LOCAL_MOVESIZE "Print X11 Client local movesize debug mess option(WITH_DEBUG_X11 "Print X11 Client debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_XV "Print XVideo debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_RINGBUFFER "Enable Ringbuffer debug messages" ${DEFAULT_DEBUG_OPTION}) -option(WITH_DEBUG_SYMBOLS "Pack debug symbols to installer" NO) + +option(WITH_DEBUG_SYMBOLS "Pack debug symbols to installer" OFF) if(ANDROID) include(ConfigOptionsAndroid) From 6ca89620452fc36b17cf01ed283d3ccf00594e6b Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Mon, 13 Jul 2015 22:59:18 +0200 Subject: [PATCH 124/220] Map logical to physical mouse button events RDP expects to receive an indicator of the physical mouse button that was pressed on the client, whereas X11 deliver a value for which logical mouse button that was pressed. This patch introduces a (reverse) mapping from logical mouse buttons to physical mouse buttons, so that the RDP server can do correct mapping for the event on its end. However, no actual mapping is done here; this patch just introduces the framework to do so. Thus, there should be no behavioural change from this patch alone. There is an implicit assumption that only the first three buttons are mapped to eachother. Enabling more a general mapping would require extensive changes to the event handling as fourth logical button and up is used for special functionality such as wheel. --- client/X11/xf_client.c | 41 +++++++++++++++++++++++++++++++++++++++++ client/X11/xf_event.c | 28 ++++++++-------------------- client/X11/xfreerdp.h | 11 +++++++++++ 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 0c164106f..1221cec4e 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -935,6 +935,46 @@ void xf_check_extensions(xfContext* context) #endif } +/* Assignment of physical (not logical) mouse buttons to wire flags. */ +/* Notice that the middle button is 2 in X11, but 3 in RDP. */ +static const int xf_button_flags[NUM_BUTTONS_MAPPED] = { + PTR_FLAGS_BUTTON1, + PTR_FLAGS_BUTTON3, + PTR_FLAGS_BUTTON2 +}; + +static void xf_button_map_init (xfContext* xfc) +{ + /* loop counter for array initialization */ + int physical; + int logical; + + /* logical mouse button which is used for each physical mouse */ + /* button (indexed from zero). This is the default map. */ + unsigned char x11_map[NUM_BUTTONS_MAPPED] = { + Button1, + Button2, + Button3 + }; + + /* iterate over all (mapped) physical buttons; for each of them */ + /* find the logical button in X11, and assign to this the */ + /* appropriate value to send over the RDP wire. */ + for (physical = 0; physical < NUM_BUTTONS_MAPPED; ++physical) + { + logical = x11_map[physical]; + if (Button1 <= logical && logical <= Button3) + { + xfc->button_map[logical-BUTTON_BASE] = xf_button_flags[physical]; + } + else + { + WLog_ERR(TAG,"Mouse physical button %d is mapped to logical button %d", + physical, logical); + } + } +} + /** * Callback given to freerdp_connect() to process the pre-connect operations. * It will fill the rdp_freerdp structure (instance) with the appropriate options to use for the connection. @@ -1058,6 +1098,7 @@ BOOL xf_pre_connect(freerdp* instance) xfc->decorations = settings->Decorations; xfc->grab_keyboard = settings->GrabKeyboard; xfc->fullscreen_toggle = settings->ToggleFullscreen; + xf_button_map_init (xfc); return TRUE; } diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 65291ac8c..2948693dc 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -312,16 +312,10 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win switch (button) { - case 1: - flags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1; - break; - - case 2: - flags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3; - break; - - case 3: - flags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2; + case Button1: + case Button2: + case Button3: + flags = PTR_FLAGS_DOWN | xfc->button_map[button-BUTTON_BASE]; break; case 4: @@ -422,16 +416,10 @@ BOOL xf_generic_ButtonRelease(xfContext* xfc, int x, int y, int button, Window w switch (button) { - case 1: - flags = PTR_FLAGS_BUTTON1; - break; - - case 2: - flags = PTR_FLAGS_BUTTON3; - break; - - case 3: - flags = PTR_FLAGS_BUTTON2; + case Button1: + case Button2: + case Button3: + flags = xfc->button_map[button-BUTTON_BASE]; break; case 6: diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index d59ae1ebf..b90ac095b 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -79,6 +79,14 @@ typedef struct xf_glyph xfGlyph; typedef struct xf_clipboard xfClipboard; +/* Value of the first logical button number in X11 which must be */ +/* subtracted to go from a button number in X11 to an index into */ +/* a per-button array. */ +#define BUTTON_BASE Button1 + +/* Number of buttons that are mapped from X11 to RDP button events. */ +#define NUM_BUTTONS_MAPPED 3 + struct xf_context { rdpContext context; @@ -228,6 +236,9 @@ struct xf_context BOOL xkbAvailable; BOOL xrenderAvailable; + + /* value to be sent over wire for each logical client mouse button */ + int button_map[NUM_BUTTONS_MAPPED]; }; BOOL xf_create_window(xfContext* xfc); From 9f43291126e86fac390e366773ad9761ab9b97b2 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 14 Jul 2015 00:31:12 +0200 Subject: [PATCH 125/220] Get pointer button mapping from input system If XInput extension is available, then find the (first) pointer device and use the button mapping of that one. If there are more than one pointer devices, they could have different button mappings, but it is not clear how this should be communicated to the RDP server. If XInput is not available, attempt to fallback to the old global mapping. (This mapping exists, but is not correct if there actually is an XInput extension loaded, as it is then not used). --- client/X11/xf_client.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 1221cec4e..f21bfbfc6 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -35,6 +35,7 @@ #endif #ifdef WITH_XI +#include #include #endif @@ -935,6 +936,92 @@ void xf_check_extensions(xfContext* context) #endif } +#ifdef WITH_XI +/* Input device which does NOT have the correct mapping. We must disregard */ +/* this device when trying to find the input device which is the pointer. */ +static const char TEST_PTR_STR [] = "Virtual core XTEST pointer"; +static const size_t TEST_PTR_LEN = sizeof (TEST_PTR_STR) / sizeof (char); + +/* Invalid device identifier which indicate failure. */ +static const int INVALID_XID = -1; +#endif /* WITH_XI */ + +static void xf_get_x11_button_map (xfContext* xfc, unsigned char* x11_map) +{ +#ifdef WITH_XI + int opcode, event, error; + int xid; + XDevice* ptr_dev; + XExtensionVersion* version; + XDeviceInfo* devices1; + XIDeviceInfo* devices2; + int i, num_devices; + + if (XQueryExtension (xfc->display, "XInputExtension", &opcode, &event, &error)) + { + WLog_DBG(TAG, "Searching for XInput pointer device"); + xid = INVALID_XID; + /* loop through every device, looking for a pointer */ + version = XGetExtensionVersion (xfc->display, INAME); + if (version->major_version >= 2) + { + /* XID of pointer device using XInput version 2 */ + devices2 = XIQueryDevice (xfc->display, XIAllDevices, &num_devices); + if (devices2) + { + for (i = 0; i < num_devices; ++i) + { + if ((devices2[i].use == XISlavePointer) && + (strncmp (devices2[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0)) + { + xid = devices2[i].deviceid; + break; + } + } + XIFreeDeviceInfo (devices2); + } + } + else + { + /* XID of pointer device using XInput version 1 */ + devices1 = XListInputDevices (xfc->display, &num_devices); + if (devices1) + { + for (i = 0; i < num_devices; ++i) + { + if ((devices1[i].use == IsXExtensionPointer) && + (strncmp (devices1[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0)) + { + xid = devices1[i].id; + break; + } + } + XFreeDeviceList (devices1); + } + } + XFree (version); + /* get button mapping from input extension if there is a pointer device; */ + /* otherwise leave unchanged. */ + if (xid != INVALID_XID) + { + WLog_DBG(TAG, "Pointer device: %d", xid); + ptr_dev = XOpenDevice (xfc->display, xid); + XGetDeviceButtonMapping (xfc->display, ptr_dev, x11_map, NUM_BUTTONS_MAPPED); + XCloseDevice (xfc->display, ptr_dev); + } + else + { + WLog_DBG(TAG, "No pointer device found!"); + } + } + else +#endif /* WITH_XI */ + { + WLog_DBG(TAG, "Get global pointer mapping (no XInput)"); + XGetPointerMapping (xfc->display, x11_map, NUM_BUTTONS_MAPPED); + } +} + /* Assignment of physical (not logical) mouse buttons to wire flags. */ /* Notice that the middle button is 2 in X11, but 3 in RDP. */ static const int xf_button_flags[NUM_BUTTONS_MAPPED] = { @@ -957,6 +1044,9 @@ static void xf_button_map_init (xfContext* xfc) Button3 }; + /* query system for actual remapping */ + xf_get_x11_button_map (xfc, x11_map); + /* iterate over all (mapped) physical buttons; for each of them */ /* find the logical button in X11, and assign to this the */ /* appropriate value to send over the RDP wire. */ From 600d3c5ccb495fd59b11df0efa5b598165116b5d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 14 Jul 2015 01:03:33 +0200 Subject: [PATCH 126/220] Add option to disable pointer button mapping In case the old behaviour of not reverse-mapping the mouse buttons is desirable, a command-line option is added to disable the mapping. This option is made experimental for the time being. The default is to do the reverse mapping, as this is the intuitive behaviour (the mouse then works as it would on the console). --- client/X11/xf_client.c | 5 ++++- client/common/cmdline.c | 5 +++++ include/freerdp/settings.h | 1 + libfreerdp/core/settings.c | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index f21bfbfc6..8a885cf63 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1045,7 +1045,10 @@ static void xf_button_map_init (xfContext* xfc) }; /* query system for actual remapping */ - xf_get_x11_button_map (xfc, x11_map); + if (!xfc->settings->UnmapButtons) + { + xf_get_x11_button_map (xfc, x11_map); + } /* iterate over all (mapped) physical buttons; for each of them */ /* find the logical button in X11, and assign to this the */ diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 4fcac49ef..0945c1a78 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -107,6 +107,7 @@ COMMAND_LINE_ARGUMENT_A args[] = { "usb", COMMAND_LINE_VALUE_REQUIRED, "[dbg][dev][id|addr][auto]", NULL, NULL, -1, NULL, "Redirect USB device" }, { "multitouch", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Redirect multitouch input" }, { "gestures", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Consume multitouch input locally" }, + { "unmap-buttons", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Let server see real physical pointer button"}, { "echo", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "echo", "Echo channel" }, { "disp", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Display control" }, { "fonts", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Smooth fonts (ClearType)" }, @@ -2142,6 +2143,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, { settings->GrabKeyboard = arg->Value ? TRUE : FALSE; } + CommandLineSwitchCase(arg, "unmap-buttons") + { + settings->UnmapButtons = arg->Value ? TRUE : FALSE; + } CommandLineSwitchCase(arg, "toggle-fullscreen") { settings->ToggleFullscreen = arg->Value ? TRUE : FALSE; diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 5b3d43199..1de9a9f9a 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1422,6 +1422,7 @@ struct rdp_settings /* * Extensions */ + ALIGN64 BOOL UnmapButtons; /* Extensions */ ALIGN64 int num_extensions; /* */ diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index df905ab7a..0ddd7d2c4 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -262,6 +262,7 @@ rdpSettings* freerdp_settings_new(DWORD flags) settings->ToggleFullscreen = TRUE; settings->DesktopPosX = 0; settings->DesktopPosY = 0; + settings->UnmapButtons = FALSE; settings->PerformanceFlags = PERF_FLAG_NONE; settings->AllowFontSmoothing = FALSE; From 03a1ff814d8983b3a6076cc41cdb654585153066 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 16 Dec 2015 15:15:46 +0100 Subject: [PATCH 127/220] Fixed unused warnings. --- winpr/libwinpr/utils/debug.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/winpr/libwinpr/utils/debug.c b/winpr/libwinpr/utils/debug.c index 0b3150e05..a911f424c 100644 --- a/winpr/libwinpr/utils/debug.c +++ b/winpr/libwinpr/utils/debug.c @@ -472,10 +472,10 @@ void winpr_log_backtrace(const char* tag, DWORD level, DWORD size) } char* winpr_strerror(DWORD dw, char* dmsg, size_t size) { +#if defined(_WIN32) LPTSTR msg = NULL; DWORD rc; -#if defined(_WIN32) rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -483,17 +483,17 @@ char* winpr_strerror(DWORD dw, char* dmsg, size_t size) { if (rc) { #if defined(UNICODE) WideCharToMultiByte(CP_ACP, 0, msg, rc, dmsg, size - 1, NULL, NULL); -#else +#else /* defined(UNICODE) */ memcpy(dmsg, msg, min(rc, size - 1)); -#endif +#endif /* defined(UNICODE) */ dmsg[min(rc, size - 1)] = 0; LocalFree(msg); } else { _snprintf(dmsg, size, "FAILURE: %08X", GetLastError()); } -#else +#else /* defined(_WIN32) */ _snprintf(dmsg, size, "%s", strerror(dw)); -#endif +#endif /* defined(_WIN32) */ return dmsg; } From 5b2f4f50a0d0e0b64a54df49aa32007d967f18ca Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 16 Dec 2015 17:35:59 +0100 Subject: [PATCH 128/220] Fixed FILE* leak and EndOfFile settings. --- winpr/libwinpr/file/file.c | 111 ++++++++++++++++++------------------- winpr/libwinpr/file/file.h | 2 +- 2 files changed, 54 insertions(+), 59 deletions(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index b0eb565b8..e58b2249b 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -57,7 +57,7 @@ static int FileGetFd(HANDLE handle) if (!FileIsHandled(handle)) return -1; - return file->fd; + return fileno(file->fp); } static BOOL FileCloseHandle(HANDLE handle) { @@ -66,14 +66,13 @@ static BOOL FileCloseHandle(HANDLE handle) { if (!FileIsHandled(handle)) return FALSE; - if (file->fd != -1) + if (file->fp) { - /* Don't close stdin/stdout/stderr */ - if (file->fd > 2) + if (fileno(file->fp) > 2) { - close(file->fd); - file->fd = -1; + fclose(file->fp); + file->fp = NULL; } } @@ -85,21 +84,16 @@ static BOOL FileCloseHandle(HANDLE handle) { static BOOL FileSetEndOfFile(HANDLE hFile) { WINPR_FILE* pFile = (WINPR_FILE*) hFile; - DWORD lowSize, highSize; off_t size; if (!hFile) return FALSE; - lowSize = GetFileSize(hFile, &highSize); - if (lowSize == INVALID_FILE_SIZE) - return FALSE; - - size = lowSize | ((off_t)highSize << 32); - if (ftruncate(pFile->fd, size) < 0) + size = ftell(pFile->fp); + if (ftruncate(fileno(pFile->fp), size) < 0) { - WLog_ERR(TAG, "ftruncate %d failed with %s [%08X]", - pFile->fd, strerror(errno), errno); + WLog_ERR(TAG, "ftruncate %s failed with %s [%08X]", + pFile->lpFileName, strerror(errno), errno); return FALSE; } @@ -118,12 +112,11 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, if (!hFile) return INVALID_SET_FILE_POINTER; - fp = fdopen(pFile->fd, "wb"); + fp = pFile->fp; if (!fp) { - WLog_ERR(TAG, "fdopen(%s) failed with %s [%08X]", pFile->lpFileName, - strerror(errno), errno); + WLog_ERR(TAG, "No file pointer for(%s)", pFile->lpFileName); return INVALID_SET_FILE_POINTER; } @@ -155,7 +148,7 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped) { - int io_status; + size_t io_status; WINPR_FILE* file; BOOL status = TRUE; @@ -169,13 +162,9 @@ static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, } file = (WINPR_FILE *)Object; - do - { - io_status = read(file->fd, lpBuffer, nNumberOfBytesToRead); - } - while ((io_status < 0) && (errno == EINTR)); + io_status = fread(lpBuffer, nNumberOfBytesToRead, 1, file->fp); - if (io_status < 0) + if (io_status != 1) { status = FALSE; @@ -188,7 +177,7 @@ static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, } if (lpNumberOfBytesRead) - *lpNumberOfBytesRead = io_status; + *lpNumberOfBytesRead = nNumberOfBytesToRead; return status; } @@ -196,7 +185,7 @@ static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, static BOOL FileWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped) { - int io_status; + size_t io_status; WINPR_FILE* file; if (!Object) @@ -210,16 +199,14 @@ static BOOL FileWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrit file = (WINPR_FILE *)Object; - do - { - io_status = write(file->fd, lpBuffer, nNumberOfBytesToWrite); - } - while ((io_status < 0) && (errno == EINTR)); + io_status = fwrite(lpBuffer, nNumberOfBytesToWrite, 1, file->fp); + if (io_status != 1) + return FALSE; if ((io_status < 0) && (errno == EWOULDBLOCK)) io_status = 0; - *lpNumberOfBytesWritten = io_status; + *lpNumberOfBytesWritten = nNumberOfBytesToWrite; return TRUE; } @@ -233,7 +220,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) return 0; file = (WINPR_FILE *)Object; - fp = fdopen(file->fd, "wb"); + fp = file->fp; if (!fp) { @@ -310,7 +297,7 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, if (dwFlags & LOCKFILE_FAIL_IMMEDIATELY) lock |= LOCK_NB; - if (flock(pFile->fd, lock) < 0) + if (flock(fileno(pFile->fp), lock) < 0) { WLog_ERR(TAG, "flock failed with %s [%08X]", strerror(errno), errno); @@ -336,7 +323,7 @@ static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffs return FALSE; } - if (flock(pFile->fd, LOCK_UN) < 0) + if (flock(fileno(pFile->fp), LOCK_UN) < 0) { WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [%08X]", pFile->lpFileName, strerror(errno), errno); @@ -366,7 +353,7 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte return FALSE; } - if (flock(pFile->fd, LOCK_UN) < 0) + if (flock(fileno(pFile->fp), LOCK_UN) < 0) { WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [%08X]", pFile->lpFileName, strerror(errno), errno); @@ -499,14 +486,11 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw if (NULL == fp) fp = fopen(pFile->lpFileName, mode); - pFile->fd = -1; - if (fp) - pFile->fd = fileno(fp); - - if (pFile->fd < 0) + pFile->fp = fp; + if (!pFile->fp) { - WLog_ERR(TAG, "Failed to open file %s with mode %s", - pFile->lpFileName, mode); + WLog_ERR(TAG, "Failed to open file pointer for %s", + pFile->lpFileName); free(pFile->lpFileName); free(pFile); @@ -520,13 +504,11 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw if (dwShareMode & (FILE_SHARE_READ | FILE_SHARE_WRITE)) { - if (flock(pFile->fd, lock) < 0) + if (flock(fileno(pFile->fp), lock) < 0) { WLog_ERR(TAG, "flock failed with %s [%08X]", strerror(errno), errno); - close(pFile->fd); - free(pFile->lpFileName); - free(pFile); + FileCloseHandle(pFile); return INVALID_HANDLE_VALUE; } @@ -553,20 +535,20 @@ HANDLE_CREATOR *GetFileHandleCreator(void) } -static WINPR_FILE *FileHandle_New(int fd) +static WINPR_FILE *FileHandle_New(FILE* fp) { WINPR_FILE *pFile; HANDLE hFile; char name[MAX_PATH]; - _snprintf(name, sizeof(name), "device_%d", fd); + _snprintf(name, sizeof(name), "device_%d", fileno(fp)); pFile = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); if (!pFile) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } - pFile->fd = fd; + pFile->fp = fp; pFile->ops = &shmOps; pFile->lpFileName = _strdup(name); @@ -577,23 +559,24 @@ static WINPR_FILE *FileHandle_New(int fd) HANDLE GetStdHandle(DWORD nStdHandle) { - int fd; + FILE* fp; WINPR_FILE *pFile; + switch (nStdHandle) { case STD_INPUT_HANDLE: - fd = STDIN_FILENO; + fp = stdin; break; case STD_OUTPUT_HANDLE: - fd = STDOUT_FILENO; + fp = stdout; break; case STD_ERROR_HANDLE: - fd = STDERR_FILENO; + fp = stderr; break; default: return INVALID_HANDLE_VALUE; } - pFile = FileHandle_New(fd); + pFile = FileHandle_New(fp); if (!pFile) return INVALID_HANDLE_VALUE; @@ -620,16 +603,28 @@ HANDLE GetFileHandleForFileDescriptor(int fd) return (HANDLE)_get_osfhandle(fd); #else /* WIN32 */ WINPR_FILE *pFile; + FILE* fp; + int flags; /* Make sure it's a valid fd */ if (fcntl(fd, F_GETFD) == -1 && errno == EBADF) return INVALID_HANDLE_VALUE; - pFile = FileHandle_New(fd); + flags = fcntl(fd, F_GETFL); + if (flags == -1) + return INVALID_HANDLE_VALUE; + + if (flags & O_WRONLY) + fp = fdopen(fd, "wb"); + else + fp = fdopen(fd, "rb"); + + pFile = FileHandle_New(fp); if (!pFile) return INVALID_HANDLE_VALUE; - pFile->fd = fd; + return (HANDLE)pFile; #endif /* WIN32 */ } + diff --git a/winpr/libwinpr/file/file.h b/winpr/libwinpr/file/file.h index fc2879366..af0916753 100644 --- a/winpr/libwinpr/file/file.h +++ b/winpr/libwinpr/file/file.h @@ -37,7 +37,7 @@ struct winpr_file { WINPR_HANDLE_DEF(); - int fd; + FILE* fp; char* lpFileName; From 79707cb7fd2a15198370fb03b1b523917789be38 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Dec 2015 17:45:59 +0100 Subject: [PATCH 129/220] makecert: fix installation of .a file Since cb958ba9c62f05d101b886218d885d2c26c6ba55 libwinpr-makecert-tool.a wasn't installed anymore. --- winpr/tools/makecert/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/winpr/tools/makecert/CMakeLists.txt b/winpr/tools/makecert/CMakeLists.txt index b33e7b15f..ce72f7d2b 100644 --- a/winpr/tools/makecert/CMakeLists.txt +++ b/winpr/tools/makecert/CMakeLists.txt @@ -42,6 +42,8 @@ endif() target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT WinPRTargets) + add_subdirectory(cli) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") From 06307f1ac142355f8cde14fd9f52b833db148116 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Dec 2015 18:33:19 +0100 Subject: [PATCH 130/220] winpr/file: disable buffering When FILE streams are used per default buffering is enabled but WriteFile/ReadFile shouldn't do any extra buffering. --- winpr/libwinpr/file/file.c | 44 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index e58b2249b..066a76e16 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -107,19 +107,10 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, WINPR_FILE* pFile = (WINPR_FILE*) hFile; long offset = lDistanceToMove; int whence; - FILE* fp; if (!hFile) return INVALID_SET_FILE_POINTER; - fp = pFile->fp; - - if (!fp) - { - WLog_ERR(TAG, "No file pointer for(%s)", pFile->lpFileName); - return INVALID_SET_FILE_POINTER; - } - switch(dwMoveMethod) { case FILE_BEGIN: @@ -135,14 +126,14 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, return INVALID_SET_FILE_POINTER; } - if (fseek(fp, offset, whence)) + if (fseek(pFile->fp, offset, whence)) { WLog_ERR(TAG, "fseek(%s) failed with %s [%08X]", pFile->lpFileName, strerror(errno), errno); return INVALID_SET_FILE_POINTER; } - return ftell(fp); + return ftell(pFile->fp); } static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, @@ -213,23 +204,14 @@ static BOOL FileWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrit static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) { WINPR_FILE* file; - FILE* fp; long cur, size; if (!Object) return 0; file = (WINPR_FILE *)Object; - fp = file->fp; - if (!fp) - { - WLog_ERR(TAG, "fopen(%s) failed with %s [%08X]", file->lpFileName, - strerror(errno), errno); - return INVALID_FILE_SIZE; - } - - cur = ftell(fp); + cur = ftell(file->fp); if (cur < 0) { @@ -238,14 +220,14 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) return INVALID_FILE_SIZE; } - if (fseek(fp, 0, SEEK_END) != 0) + if (fseek(file->fp, 0, SEEK_END) != 0) { WLog_ERR(TAG, "fseek(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); return INVALID_FILE_SIZE; } - size = ftell(fp); + size = ftell(file->fp); if (size < 0) { @@ -254,7 +236,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) return INVALID_FILE_SIZE; } - if (fseek(fp, cur, SEEK_SET) != 0) + if (fseek(file->fp, cur, SEEK_SET) != 0) { WLog_ERR(TAG, "ftell(%s) failed with %s [%08X]", file->lpFileName, strerror(errno), errno); @@ -489,14 +471,15 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw pFile->fp = fp; if (!pFile->fp) { - WLog_ERR(TAG, "Failed to open file pointer for %s", - pFile->lpFileName); - + /* This case can occur when trying to open a + * not existing file without create flag. */ free(pFile->lpFileName); free(pFile); return INVALID_HANDLE_VALUE; } + setvbuf(fp, NULL, _IONBF, 0); + if (dwShareMode & FILE_SHARE_READ) lock = LOCK_SH; if (dwShareMode & FILE_SHARE_WRITE) @@ -538,7 +521,6 @@ HANDLE_CREATOR *GetFileHandleCreator(void) static WINPR_FILE *FileHandle_New(FILE* fp) { WINPR_FILE *pFile; - HANDLE hFile; char name[MAX_PATH]; _snprintf(name, sizeof(name), "device_%d", fileno(fp)); @@ -552,7 +534,6 @@ static WINPR_FILE *FileHandle_New(FILE* fp) pFile->ops = &shmOps; pFile->lpFileName = _strdup(name); - hFile = (HANDLE) pFile; WINPR_HANDLE_SET_TYPE_AND_MODE(pFile, HANDLE_TYPE_FILE, WINPR_FD_READ); return pFile; } @@ -619,6 +600,11 @@ HANDLE GetFileHandleForFileDescriptor(int fd) else fp = fdopen(fd, "rb"); + if (!fp) + return INVALID_HANDLE_VALUE; + + setvbuf(fp, NULL, _IONBF, 0); + pFile = FileHandle_New(fp); if (!pFile) return INVALID_HANDLE_VALUE; From 6f6f0b0c532e5d60280c392385ac6c1bd174c28e Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 16 Dec 2015 23:21:43 +0100 Subject: [PATCH 131/220] Move UnmapButtons settings to stable ABI section The Miscellaneous section is chosen because choosing not to map the buttons is not a property of the input system, but rather an ad-hoc setting to be applied to this session. --- include/freerdp/settings.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 1de9a9f9a..d96d35293 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1106,7 +1106,8 @@ struct rdp_settings ALIGN64 BOOL LocalConnection; /* 1602 */ ALIGN64 BOOL AuthenticationOnly; /* 1603 */ ALIGN64 BOOL CredentialsFromStdin; /* 1604 */ - UINT64 padding1664[1664 - 1605]; /* 1605 */ + ALIGN64 BOOL UnmapButtons; /* 1605 */ + UINT64 padding1664[1664 - 1606]; /* 1606 */ /* Names */ ALIGN64 char* ComputerName; /* 1664 */ @@ -1422,7 +1423,6 @@ struct rdp_settings /* * Extensions */ - ALIGN64 BOOL UnmapButtons; /* Extensions */ ALIGN64 int num_extensions; /* */ From 864f06b161990ebb4c43fb64a1b033adb1ed3f97 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 17 Dec 2015 10:59:59 +0100 Subject: [PATCH 132/220] Added missing include. --- winpr/include/winpr/wlog.h | 1 + 1 file changed, 1 insertion(+) diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index f7d7ec0c1..7da8aa51a 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -27,6 +27,7 @@ extern "C" { #endif +#include #include #include #include From 120e5e2d43a53f631aeb41473f87b8715212e0c9 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 17 Dec 2015 11:28:03 +0100 Subject: [PATCH 133/220] Moved header detection defines to config.h --- CMakeLists.txt | 8 -------- config.h.in | 2 ++ winpr/include/winpr/wtypes.h | 4 ++++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 925f0e40d..6bc98ec16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,14 +345,6 @@ else() set(HAVE_SYS_FILIO_H 1) endif() -if(HAVE_STDBOOL_H) - add_definitions(-DHAVE_STDBOOL_H) -endif() - -if(HAVE_STDINT_H) - add_definitions(-DHAVE_STDINT_H) -endif() - if(NOT IOS) check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF) else() diff --git a/config.h.in b/config.h.in index df24a3071..9dc44bdba 100644 --- a/config.h.in +++ b/config.h.in @@ -4,6 +4,8 @@ /* Include files */ #cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_UNISTD_H +#cmakedefine HAVE_STDINT_H +#cmakedefine HAVE_STDBOOL_H #cmakedefine HAVE_INTTYPES_H #cmakedefine HAVE_SYS_MODEM_H #cmakedefine HAVE_SYS_FILIO_H diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 2ba38fb1e..66b545b5a 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -23,6 +23,10 @@ /* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ /* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include From f8565b8b7503aedbf75468ec5fb9c4c3a91d3366 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 17 Dec 2015 12:01:52 +0100 Subject: [PATCH 134/220] Generating wtypes.h now with used defines. --- winpr/include/CMakeLists.txt | 1 + winpr/include/winpr/wtypes.h | 7 +- winpr/include/winpr/wtypes.h.in | 489 ++++++++++++++++++++++++++++++++ 3 files changed, 493 insertions(+), 4 deletions(-) create mode 100644 winpr/include/winpr/wtypes.h.in diff --git a/winpr/include/CMakeLists.txt b/winpr/include/CMakeLists.txt index 3ce562e29..1121008ad 100644 --- a/winpr/include/CMakeLists.txt +++ b/winpr/include/CMakeLists.txt @@ -16,6 +16,7 @@ # limitations under the License. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/version.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr/wtypes.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/wtypes.h) file(GLOB WINPR_HEADERS "winpr/*.h") install(FILES ${WINPR_HEADERS} DESTINATION include/winpr COMPONENT headers) diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 66b545b5a..7bbd695b2 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -20,13 +20,12 @@ #ifndef WINPR_WTYPES_H #define WINPR_WTYPES_H +#define HAVE_STDINT_H +#define HAVE_STDBOOL_H + /* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ /* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include diff --git a/winpr/include/winpr/wtypes.h.in b/winpr/include/winpr/wtypes.h.in new file mode 100644 index 000000000..af23bce2a --- /dev/null +++ b/winpr/include/winpr/wtypes.h.in @@ -0,0 +1,489 @@ +/** + * WinPR: Windows Portable Runtime + * Windows Data Types + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_WTYPES_H +#define WINPR_WTYPES_H + +#cmakedefine HAVE_STDINT_H +#cmakedefine HAVE_STDBOOL_H + +/* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ +/* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ + +#include +#include + +#include + +#if defined(HAVE_STDBOOL_H) +#include +#endif + +#if defined(HAVE_STDINT_H) +#include +#endif + +#ifdef _WIN32 +#include +#endif + +#if defined(__OBJC__) && defined(__APPLE__) +#include +#endif + +#ifndef _WIN32 + +#define WINAPI +#define CDECL + +#ifndef FAR +#define FAR +#endif + +#ifndef NEAR +#define NEAR +#endif + +#if defined(HAVE_STDINT_H) +#define __int8 int8_t +#define __uint8 uint8_t +#define __int16 int16_t +#define __uint16 uint16_t +#define __int32 int32_t +#define __uint32 uint32_t +#define __int64 int64_t +#define __uint64 uint64_t +#else +#define __int8 char +#define __uint8 unsigned char +#define __int16 short +#define __uint16 unsigned short +#define __int32 int +#define __uint32 unsigned int +#define __int64 long long +#define __uint64 unsigned long long +#endif + +#if defined(HAVE_STDINT_H) +#if defined(__x86_64__) || defined(__arm64__) +#define __int3264 int64_t +#define __uint3264 uint64_t +#else +#define __int3264 int32_t +#define __uint3264 uint32_t +#endif +#else +#if defined(__x86_64__) || defined(__arm64__) +#define __int3264 __int64 +#define __uint3264 __uint64 +#else +#define __int3264 __int32 +#define __uint3264 __uint32 +#endif +#endif + +#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +typedef bool BOOL; +#else +#ifndef __OBJC__ +#if defined(__APPLE__) +typedef signed char BOOL; +#else +#ifndef XMD_H +typedef int BOOL; +#endif +#endif +#endif +#endif + +typedef BOOL *PBOOL, *LPBOOL; + +#if defined(HAVE_STDINT_H) +typedef int32_t LONG; +typedef uint32_t DWORD; +typedef uint32_t ULONG; +#elif defined(__LP64__) || defined(__APPLE__) +typedef int LONG; +typedef unsigned int DWORD; +typedef unsigned int ULONG; +#else +typedef long LONG; +typedef unsigned long DWORD; +typedef unsigned long ULONG; +#endif + +#if defined(HAVE_STDINT_H) +typedef uint8_t BYTE, *PBYTE, *LPBYTE; +#else +typedef unsigned char BYTE, *PBYTE, *LPBYTE; +#endif + +typedef BYTE BOOLEAN, *PBOOLEAN; +#if defined(wchar_t) +typedef wchar_t WCHAR, *PWCHAR; +#else +typedef unsigned short WCHAR, *PWCHAR; +#endif +typedef WCHAR* BSTR; +typedef char CHAR, *PCHAR; +typedef DWORD *PDWORD, *LPDWORD; +#if defined(HAVE_STDINT_H) +typedef uint32_t DWORD32; +typedef uint64_t DWORD64; +typedef uint64_t ULONGLONG; +#else +typedef unsigned int DWORD32; +typedef unsigned __int64 DWORD64; +typedef unsigned __int64 ULONGLONG; +#endif +typedef ULONGLONG DWORDLONG, *PDWORDLONG; +typedef float FLOAT; +typedef unsigned char UCHAR, *PUCHAR; +typedef short SHORT; + +#ifndef FALSE +#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#define FALSE false +#else +#define FALSE 0 +#endif +#endif + +#ifndef TRUE +#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#define TRUE true +#else +#define TRUE 1 +#endif +#endif + +#define CONST const +#define CALLBACK + +typedef void* HANDLE, *PHANDLE, *LPHANDLE; +typedef HANDLE HINSTANCE; +typedef HANDLE HMODULE; +typedef HANDLE HWND; +typedef HANDLE HBITMAP; +typedef HANDLE HICON; +typedef HANDLE HCURSOR; +typedef HANDLE HBRUSH; +typedef HANDLE HMENU; + +typedef DWORD HCALL; +typedef int INT, *LPINT; +#if defined(HAVE_STDINT_H) +typedef int8_t INT8; +typedef int16_t INT16; +typedef int32_t INT32; +typedef int64_t INT64; +#else +typedef signed char INT8; +typedef signed short INT16; +#ifndef XMD_H +typedef signed int INT32; +typedef signed __int64 INT64; +#endif +#endif +typedef const WCHAR* LMCSTR; +typedef WCHAR* LMSTR; +typedef LONG *PLONG, *LPLONG; +#if defined(HAVE_STDINT_H) +typedef int64_t LONGLONG; +#else +typedef signed __int64 LONGLONG; +#endif + +typedef __int3264 LONG_PTR, *PLONG_PTR; +typedef __uint3264 ULONG_PTR, *PULONG_PTR; + +#if defined(HAVE_STDINT_H) +typedef int32_t LONG32; +typedef int64_t LONG64; +#else +typedef signed int LONG32; +#ifndef XMD_H +typedef signed __int64 LONG64; +#endif +#endif + +typedef CHAR *PSTR, *LPSTR, *LPCH; +typedef const CHAR *LPCSTR,*PCSTR; + +typedef WCHAR *LPWSTR, *PWSTR, *LPWCH; +typedef const WCHAR *LPCWSTR,*PCWSTR; + +typedef unsigned int UINT; +#if defined(HAVE_STDINT_H) +typedef uint64_t QWORD; + +typedef uint8_t UINT8; +typedef uint16_t UINT16; +typedef uint32_t UINT32; +typedef uint64_t UINT64; +#else +typedef unsigned __int64 QWORD; + +typedef unsigned char UINT8; +typedef unsigned short UINT16; +typedef unsigned int UINT32; +typedef unsigned __int64 UINT64; +#endif + +typedef ULONG *PULONG; + +typedef LONG HRESULT; +typedef LONG SCODE; +typedef SCODE *PSCODE; + +typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; +typedef ULONG_PTR SIZE_T; +#if defined(HAVE_STDINT_H) +typedef uint32_t ULONG32; +typedef uint64_t ULONG64; +typedef uint16_t USHORT; +typedef uint16_t WORD, *PWORD, *LPWORD; +#else +typedef unsigned int ULONG32; +typedef unsigned __int64 ULONG64; +typedef unsigned short USHORT; +typedef unsigned short WORD, *PWORD, *LPWORD; +#endif +typedef wchar_t UNICODE; +#define VOID void +typedef void *PVOID, *LPVOID; +typedef void *PVOID64, *LPVOID64; + +#if defined(HAVE_STDINT_H) +typedef intptr_t INT_PTR; +typedef uintptr_t UINT_PTR; +#elif __x86_64__ +typedef __int64 INT_PTR; +typedef unsigned __int64 UINT_PTR; +#else +typedef int INT_PTR; +typedef unsigned int UINT_PTR; +#endif + +typedef struct _GUID +{ + UINT32 Data1; + UINT16 Data2; + UINT16 Data3; + BYTE Data4[8]; +} GUID, UUID, *PGUID, *LPGUID, *LPCGUID; + +typedef struct _LUID +{ + DWORD LowPart; + LONG HighPart; +} LUID, *PLUID; + +typedef GUID IID; +typedef IID* REFIID; + +#ifdef UNICODE +#define _T(x) L ## x +#else +#define _T(x) x +#endif + +#ifdef UNICODE +typedef LPWSTR PTSTR; +typedef LPWSTR LPTCH; +typedef LPWSTR LPTSTR; +typedef LPCWSTR LPCTSTR; +#else +typedef LPSTR PTSTR; +typedef LPSTR LPTCH; +typedef LPSTR LPTSTR; +typedef LPCSTR LPCTSTR; +#endif + +typedef union _ULARGE_INTEGER +{ + struct + { + DWORD LowPart; + DWORD HighPart; + }; + + struct + { + DWORD LowPart; + DWORD HighPart; + } u; + + ULONGLONG QuadPart; +} ULARGE_INTEGER, *PULARGE_INTEGER; + +typedef union _LARGE_INTEGER +{ + struct + { + DWORD LowPart; + LONG HighPart; + }; + + struct + { + DWORD LowPart; + LONG HighPart; + } u; + + LONGLONG QuadPart; +} LARGE_INTEGER, *PLARGE_INTEGER; + +typedef struct _FILETIME +{ + DWORD dwLowDateTime; + DWORD dwHighDateTime; +} FILETIME, *PFILETIME, *LPFILETIME; + +typedef struct _SYSTEMTIME +{ + WORD wYear; + WORD wMonth; + WORD wDayOfWeek; + WORD wDay; + WORD wHour; + WORD wMinute; + WORD wSecond; + WORD wMilliseconds; +} SYSTEMTIME,*PSYSTEMTIME,*LPSYSTEMTIME; + +typedef struct _RPC_SID_IDENTIFIER_AUTHORITY +{ + BYTE Value[6]; +} RPC_SID_IDENTIFIER_AUTHORITY; + +typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; + +typedef struct _RPC_SID +{ + UCHAR Revision; + UCHAR SubAuthorityCount; + RPC_SID_IDENTIFIER_AUTHORITY IdentifierAuthority; + ULONG SubAuthority[]; +} RPC_SID, *PRPC_SID, *PSID; + +typedef struct _ACL +{ + UCHAR AclRevision; + UCHAR Sbz1; + USHORT AclSize; + USHORT AceCount; + USHORT Sbz2; +} ACL, *PACL; + +typedef struct _SECURITY_DESCRIPTOR +{ + UCHAR Revision; + UCHAR Sbz1; + USHORT Control; + PSID Owner; + PSID Group; + PACL Sacl; + PACL Dacl; +} SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR; + +typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL; + +typedef struct _SECURITY_ATTRIBUTES +{ + DWORD nLength; + LPVOID lpSecurityDescriptor; + BOOL bInheritHandle; +} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; + +typedef struct _PROCESS_INFORMATION +{ + HANDLE hProcess; + HANDLE hThread; + DWORD dwProcessId; + DWORD dwThreadId; +} PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION; + +typedef DWORD (*PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter); +typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; + +typedef void* FARPROC; + +#endif + +typedef BYTE byte; +typedef double DOUBLE; + +typedef void* PCONTEXT_HANDLE; +typedef PCONTEXT_HANDLE* PPCONTEXT_HANDLE; + +typedef ULONG error_status_t; + +#ifndef _NTDEF_ +typedef LONG NTSTATUS; +typedef NTSTATUS *PNTSTATUS; +#endif + +#ifndef _LPCBYTE_DEFINED +#define _LPCBYTE_DEFINED +typedef const BYTE *LPCBYTE; +#endif + +#ifndef _LPCVOID_DEFINED +#define _LPCVOID_DEFINED +typedef const VOID *LPCVOID; +#endif + +#ifndef _WIN32 + +typedef struct tagDEC +{ + USHORT wReserved; + union { + struct { + BYTE scale; + BYTE sign; + } DUMMYSTRUCTNAME; + USHORT signscale; + } DUMMYUNIONNAME; + ULONG Hi32; + union { + struct { + ULONG Lo32; + ULONG Mid32; + } DUMMYSTRUCTNAME2; + ULONGLONG Lo64; + } DUMMYUNIONNAME2; +} DECIMAL; + +typedef DECIMAL *LPDECIMAL; + +#define DECIMAL_NEG ((BYTE) 0x80) +#define DECIMAL_SETZERO(dec) { (dec).Lo64 = 0; (dec).Hi32 = 0; (dec).signscale = 0; } + +typedef char CCHAR; +typedef DWORD LCID; +typedef PDWORD PLCID; +typedef WORD LANGID; + +#endif + +#include + +#endif /* WINPR_WTYPES_H */ From ef23b4568c062d6a15e410be5e4c15bb38460af3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 17 Dec 2015 13:15:00 +0100 Subject: [PATCH 135/220] Renamed HAVE_STDXX_H in public header. --- winpr/include/winpr/wtypes.h | 36 ++++++++++++++++----------------- winpr/include/winpr/wtypes.h.in | 36 ++++++++++++++++----------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 7bbd695b2..689f32f2f 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -20,8 +20,8 @@ #ifndef WINPR_WTYPES_H #define WINPR_WTYPES_H -#define HAVE_STDINT_H -#define HAVE_STDBOOL_H +#define WINPR_HAVE_STDINT_H 0 +#define WINPR_HAVE_STDINT_H 0 /* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ /* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ @@ -31,11 +31,11 @@ #include -#if defined(HAVE_STDBOOL_H) +#if WINPR_HAVE_STDBOOL_H #include #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H #include #endif @@ -60,7 +60,7 @@ #define NEAR #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H #define __int8 int8_t #define __uint8 uint8_t #define __int16 int16_t @@ -80,7 +80,7 @@ #define __uint64 unsigned long long #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H #if defined(__x86_64__) || defined(__arm64__) #define __int3264 int64_t #define __uint3264 uint64_t @@ -98,7 +98,7 @@ #endif #endif -#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) typedef bool BOOL; #else #ifndef __OBJC__ @@ -114,7 +114,7 @@ typedef int BOOL; typedef BOOL *PBOOL, *LPBOOL; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int32_t LONG; typedef uint32_t DWORD; typedef uint32_t ULONG; @@ -128,7 +128,7 @@ typedef unsigned long DWORD; typedef unsigned long ULONG; #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint8_t BYTE, *PBYTE, *LPBYTE; #else typedef unsigned char BYTE, *PBYTE, *LPBYTE; @@ -143,7 +143,7 @@ typedef unsigned short WCHAR, *PWCHAR; typedef WCHAR* BSTR; typedef char CHAR, *PCHAR; typedef DWORD *PDWORD, *LPDWORD; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint32_t DWORD32; typedef uint64_t DWORD64; typedef uint64_t ULONGLONG; @@ -158,7 +158,7 @@ typedef unsigned char UCHAR, *PUCHAR; typedef short SHORT; #ifndef FALSE -#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) #define FALSE false #else #define FALSE 0 @@ -166,7 +166,7 @@ typedef short SHORT; #endif #ifndef TRUE -#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) #define TRUE true #else #define TRUE 1 @@ -188,7 +188,7 @@ typedef HANDLE HMENU; typedef DWORD HCALL; typedef int INT, *LPINT; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int8_t INT8; typedef int16_t INT16; typedef int32_t INT32; @@ -204,7 +204,7 @@ typedef signed __int64 INT64; typedef const WCHAR* LMCSTR; typedef WCHAR* LMSTR; typedef LONG *PLONG, *LPLONG; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int64_t LONGLONG; #else typedef signed __int64 LONGLONG; @@ -213,7 +213,7 @@ typedef signed __int64 LONGLONG; typedef __int3264 LONG_PTR, *PLONG_PTR; typedef __uint3264 ULONG_PTR, *PULONG_PTR; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int32_t LONG32; typedef int64_t LONG64; #else @@ -230,7 +230,7 @@ typedef WCHAR *LPWSTR, *PWSTR, *LPWCH; typedef const WCHAR *LPCWSTR,*PCWSTR; typedef unsigned int UINT; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint64_t QWORD; typedef uint8_t UINT8; @@ -254,7 +254,7 @@ typedef SCODE *PSCODE; typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; typedef ULONG_PTR SIZE_T; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint32_t ULONG32; typedef uint64_t ULONG64; typedef uint16_t USHORT; @@ -270,7 +270,7 @@ typedef wchar_t UNICODE; typedef void *PVOID, *LPVOID; typedef void *PVOID64, *LPVOID64; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef intptr_t INT_PTR; typedef uintptr_t UINT_PTR; #elif __x86_64__ diff --git a/winpr/include/winpr/wtypes.h.in b/winpr/include/winpr/wtypes.h.in index af23bce2a..09fba0d20 100644 --- a/winpr/include/winpr/wtypes.h.in +++ b/winpr/include/winpr/wtypes.h.in @@ -20,8 +20,8 @@ #ifndef WINPR_WTYPES_H #define WINPR_WTYPES_H -#cmakedefine HAVE_STDINT_H -#cmakedefine HAVE_STDBOOL_H +#define WINPR_HAVE_STDINT_H @HAVE_STDINT_H@ +#define WINPR_HAVE_STDINT_H @HAVE_STDBOOL_H@ /* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ /* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ @@ -31,11 +31,11 @@ #include -#if defined(HAVE_STDBOOL_H) +#if WINPR_HAVE_STDBOOL_H #include #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H #include #endif @@ -60,7 +60,7 @@ #define NEAR #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H #define __int8 int8_t #define __uint8 uint8_t #define __int16 int16_t @@ -80,7 +80,7 @@ #define __uint64 unsigned long long #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H #if defined(__x86_64__) || defined(__arm64__) #define __int3264 int64_t #define __uint3264 uint64_t @@ -98,7 +98,7 @@ #endif #endif -#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) typedef bool BOOL; #else #ifndef __OBJC__ @@ -114,7 +114,7 @@ typedef int BOOL; typedef BOOL *PBOOL, *LPBOOL; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int32_t LONG; typedef uint32_t DWORD; typedef uint32_t ULONG; @@ -128,7 +128,7 @@ typedef unsigned long DWORD; typedef unsigned long ULONG; #endif -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint8_t BYTE, *PBYTE, *LPBYTE; #else typedef unsigned char BYTE, *PBYTE, *LPBYTE; @@ -143,7 +143,7 @@ typedef unsigned short WCHAR, *PWCHAR; typedef WCHAR* BSTR; typedef char CHAR, *PCHAR; typedef DWORD *PDWORD, *LPDWORD; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint32_t DWORD32; typedef uint64_t DWORD64; typedef uint64_t ULONGLONG; @@ -158,7 +158,7 @@ typedef unsigned char UCHAR, *PUCHAR; typedef short SHORT; #ifndef FALSE -#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) #define FALSE false #else #define FALSE 0 @@ -166,7 +166,7 @@ typedef short SHORT; #endif #ifndef TRUE -#if defined(HAVE_STDBOOL_H) && !defined(__OBJC__) +#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) #define TRUE true #else #define TRUE 1 @@ -188,7 +188,7 @@ typedef HANDLE HMENU; typedef DWORD HCALL; typedef int INT, *LPINT; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int8_t INT8; typedef int16_t INT16; typedef int32_t INT32; @@ -204,7 +204,7 @@ typedef signed __int64 INT64; typedef const WCHAR* LMCSTR; typedef WCHAR* LMSTR; typedef LONG *PLONG, *LPLONG; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int64_t LONGLONG; #else typedef signed __int64 LONGLONG; @@ -213,7 +213,7 @@ typedef signed __int64 LONGLONG; typedef __int3264 LONG_PTR, *PLONG_PTR; typedef __uint3264 ULONG_PTR, *PULONG_PTR; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef int32_t LONG32; typedef int64_t LONG64; #else @@ -230,7 +230,7 @@ typedef WCHAR *LPWSTR, *PWSTR, *LPWCH; typedef const WCHAR *LPCWSTR,*PCWSTR; typedef unsigned int UINT; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint64_t QWORD; typedef uint8_t UINT8; @@ -254,7 +254,7 @@ typedef SCODE *PSCODE; typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; typedef ULONG_PTR SIZE_T; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef uint32_t ULONG32; typedef uint64_t ULONG64; typedef uint16_t USHORT; @@ -270,7 +270,7 @@ typedef wchar_t UNICODE; typedef void *PVOID, *LPVOID; typedef void *PVOID64, *LPVOID64; -#if defined(HAVE_STDINT_H) +#if WINPR_HAVE_STDINT_H typedef intptr_t INT_PTR; typedef uintptr_t UINT_PTR; #elif __x86_64__ From 33500b400d73d009f8b511323dfb5db705dc90ee Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 17 Dec 2015 13:30:41 +0100 Subject: [PATCH 136/220] Removed obsolete wtypes.h --- winpr/include/winpr/wtypes.h | 489 ----------------------------------- 1 file changed, 489 deletions(-) delete mode 100644 winpr/include/winpr/wtypes.h diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h deleted file mode 100644 index 689f32f2f..000000000 --- a/winpr/include/winpr/wtypes.h +++ /dev/null @@ -1,489 +0,0 @@ -/** - * WinPR: Windows Portable Runtime - * Windows Data Types - * - * Copyright 2012 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WINPR_WTYPES_H -#define WINPR_WTYPES_H - -#define WINPR_HAVE_STDINT_H 0 -#define WINPR_HAVE_STDINT_H 0 - -/* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ -/* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ - -#include -#include - -#include - -#if WINPR_HAVE_STDBOOL_H -#include -#endif - -#if WINPR_HAVE_STDINT_H -#include -#endif - -#ifdef _WIN32 -#include -#endif - -#if defined(__OBJC__) && defined(__APPLE__) -#include -#endif - -#ifndef _WIN32 - -#define WINAPI -#define CDECL - -#ifndef FAR -#define FAR -#endif - -#ifndef NEAR -#define NEAR -#endif - -#if WINPR_HAVE_STDINT_H -#define __int8 int8_t -#define __uint8 uint8_t -#define __int16 int16_t -#define __uint16 uint16_t -#define __int32 int32_t -#define __uint32 uint32_t -#define __int64 int64_t -#define __uint64 uint64_t -#else -#define __int8 char -#define __uint8 unsigned char -#define __int16 short -#define __uint16 unsigned short -#define __int32 int -#define __uint32 unsigned int -#define __int64 long long -#define __uint64 unsigned long long -#endif - -#if WINPR_HAVE_STDINT_H -#if defined(__x86_64__) || defined(__arm64__) -#define __int3264 int64_t -#define __uint3264 uint64_t -#else -#define __int3264 int32_t -#define __uint3264 uint32_t -#endif -#else -#if defined(__x86_64__) || defined(__arm64__) -#define __int3264 __int64 -#define __uint3264 __uint64 -#else -#define __int3264 __int32 -#define __uint3264 __uint32 -#endif -#endif - -#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) -typedef bool BOOL; -#else -#ifndef __OBJC__ -#if defined(__APPLE__) -typedef signed char BOOL; -#else -#ifndef XMD_H -typedef int BOOL; -#endif -#endif -#endif -#endif - -typedef BOOL *PBOOL, *LPBOOL; - -#if WINPR_HAVE_STDINT_H -typedef int32_t LONG; -typedef uint32_t DWORD; -typedef uint32_t ULONG; -#elif defined(__LP64__) || defined(__APPLE__) -typedef int LONG; -typedef unsigned int DWORD; -typedef unsigned int ULONG; -#else -typedef long LONG; -typedef unsigned long DWORD; -typedef unsigned long ULONG; -#endif - -#if WINPR_HAVE_STDINT_H -typedef uint8_t BYTE, *PBYTE, *LPBYTE; -#else -typedef unsigned char BYTE, *PBYTE, *LPBYTE; -#endif - -typedef BYTE BOOLEAN, *PBOOLEAN; -#if defined(wchar_t) -typedef wchar_t WCHAR, *PWCHAR; -#else -typedef unsigned short WCHAR, *PWCHAR; -#endif -typedef WCHAR* BSTR; -typedef char CHAR, *PCHAR; -typedef DWORD *PDWORD, *LPDWORD; -#if WINPR_HAVE_STDINT_H -typedef uint32_t DWORD32; -typedef uint64_t DWORD64; -typedef uint64_t ULONGLONG; -#else -typedef unsigned int DWORD32; -typedef unsigned __int64 DWORD64; -typedef unsigned __int64 ULONGLONG; -#endif -typedef ULONGLONG DWORDLONG, *PDWORDLONG; -typedef float FLOAT; -typedef unsigned char UCHAR, *PUCHAR; -typedef short SHORT; - -#ifndef FALSE -#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) -#define FALSE false -#else -#define FALSE 0 -#endif -#endif - -#ifndef TRUE -#if WINPR_HAVE_STDBOOL_H && !defined(__OBJC__) -#define TRUE true -#else -#define TRUE 1 -#endif -#endif - -#define CONST const -#define CALLBACK - -typedef void* HANDLE, *PHANDLE, *LPHANDLE; -typedef HANDLE HINSTANCE; -typedef HANDLE HMODULE; -typedef HANDLE HWND; -typedef HANDLE HBITMAP; -typedef HANDLE HICON; -typedef HANDLE HCURSOR; -typedef HANDLE HBRUSH; -typedef HANDLE HMENU; - -typedef DWORD HCALL; -typedef int INT, *LPINT; -#if WINPR_HAVE_STDINT_H -typedef int8_t INT8; -typedef int16_t INT16; -typedef int32_t INT32; -typedef int64_t INT64; -#else -typedef signed char INT8; -typedef signed short INT16; -#ifndef XMD_H -typedef signed int INT32; -typedef signed __int64 INT64; -#endif -#endif -typedef const WCHAR* LMCSTR; -typedef WCHAR* LMSTR; -typedef LONG *PLONG, *LPLONG; -#if WINPR_HAVE_STDINT_H -typedef int64_t LONGLONG; -#else -typedef signed __int64 LONGLONG; -#endif - -typedef __int3264 LONG_PTR, *PLONG_PTR; -typedef __uint3264 ULONG_PTR, *PULONG_PTR; - -#if WINPR_HAVE_STDINT_H -typedef int32_t LONG32; -typedef int64_t LONG64; -#else -typedef signed int LONG32; -#ifndef XMD_H -typedef signed __int64 LONG64; -#endif -#endif - -typedef CHAR *PSTR, *LPSTR, *LPCH; -typedef const CHAR *LPCSTR,*PCSTR; - -typedef WCHAR *LPWSTR, *PWSTR, *LPWCH; -typedef const WCHAR *LPCWSTR,*PCWSTR; - -typedef unsigned int UINT; -#if WINPR_HAVE_STDINT_H -typedef uint64_t QWORD; - -typedef uint8_t UINT8; -typedef uint16_t UINT16; -typedef uint32_t UINT32; -typedef uint64_t UINT64; -#else -typedef unsigned __int64 QWORD; - -typedef unsigned char UINT8; -typedef unsigned short UINT16; -typedef unsigned int UINT32; -typedef unsigned __int64 UINT64; -#endif - -typedef ULONG *PULONG; - -typedef LONG HRESULT; -typedef LONG SCODE; -typedef SCODE *PSCODE; - -typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; -typedef ULONG_PTR SIZE_T; -#if WINPR_HAVE_STDINT_H -typedef uint32_t ULONG32; -typedef uint64_t ULONG64; -typedef uint16_t USHORT; -typedef uint16_t WORD, *PWORD, *LPWORD; -#else -typedef unsigned int ULONG32; -typedef unsigned __int64 ULONG64; -typedef unsigned short USHORT; -typedef unsigned short WORD, *PWORD, *LPWORD; -#endif -typedef wchar_t UNICODE; -#define VOID void -typedef void *PVOID, *LPVOID; -typedef void *PVOID64, *LPVOID64; - -#if WINPR_HAVE_STDINT_H -typedef intptr_t INT_PTR; -typedef uintptr_t UINT_PTR; -#elif __x86_64__ -typedef __int64 INT_PTR; -typedef unsigned __int64 UINT_PTR; -#else -typedef int INT_PTR; -typedef unsigned int UINT_PTR; -#endif - -typedef struct _GUID -{ - UINT32 Data1; - UINT16 Data2; - UINT16 Data3; - BYTE Data4[8]; -} GUID, UUID, *PGUID, *LPGUID, *LPCGUID; - -typedef struct _LUID -{ - DWORD LowPart; - LONG HighPart; -} LUID, *PLUID; - -typedef GUID IID; -typedef IID* REFIID; - -#ifdef UNICODE -#define _T(x) L ## x -#else -#define _T(x) x -#endif - -#ifdef UNICODE -typedef LPWSTR PTSTR; -typedef LPWSTR LPTCH; -typedef LPWSTR LPTSTR; -typedef LPCWSTR LPCTSTR; -#else -typedef LPSTR PTSTR; -typedef LPSTR LPTCH; -typedef LPSTR LPTSTR; -typedef LPCSTR LPCTSTR; -#endif - -typedef union _ULARGE_INTEGER -{ - struct - { - DWORD LowPart; - DWORD HighPart; - }; - - struct - { - DWORD LowPart; - DWORD HighPart; - } u; - - ULONGLONG QuadPart; -} ULARGE_INTEGER, *PULARGE_INTEGER; - -typedef union _LARGE_INTEGER -{ - struct - { - DWORD LowPart; - LONG HighPart; - }; - - struct - { - DWORD LowPart; - LONG HighPart; - } u; - - LONGLONG QuadPart; -} LARGE_INTEGER, *PLARGE_INTEGER; - -typedef struct _FILETIME -{ - DWORD dwLowDateTime; - DWORD dwHighDateTime; -} FILETIME, *PFILETIME, *LPFILETIME; - -typedef struct _SYSTEMTIME -{ - WORD wYear; - WORD wMonth; - WORD wDayOfWeek; - WORD wDay; - WORD wHour; - WORD wMinute; - WORD wSecond; - WORD wMilliseconds; -} SYSTEMTIME,*PSYSTEMTIME,*LPSYSTEMTIME; - -typedef struct _RPC_SID_IDENTIFIER_AUTHORITY -{ - BYTE Value[6]; -} RPC_SID_IDENTIFIER_AUTHORITY; - -typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; - -typedef struct _RPC_SID -{ - UCHAR Revision; - UCHAR SubAuthorityCount; - RPC_SID_IDENTIFIER_AUTHORITY IdentifierAuthority; - ULONG SubAuthority[]; -} RPC_SID, *PRPC_SID, *PSID; - -typedef struct _ACL -{ - UCHAR AclRevision; - UCHAR Sbz1; - USHORT AclSize; - USHORT AceCount; - USHORT Sbz2; -} ACL, *PACL; - -typedef struct _SECURITY_DESCRIPTOR -{ - UCHAR Revision; - UCHAR Sbz1; - USHORT Control; - PSID Owner; - PSID Group; - PACL Sacl; - PACL Dacl; -} SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR; - -typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL; - -typedef struct _SECURITY_ATTRIBUTES -{ - DWORD nLength; - LPVOID lpSecurityDescriptor; - BOOL bInheritHandle; -} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; - -typedef struct _PROCESS_INFORMATION -{ - HANDLE hProcess; - HANDLE hThread; - DWORD dwProcessId; - DWORD dwThreadId; -} PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION; - -typedef DWORD (*PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter); -typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; - -typedef void* FARPROC; - -#endif - -typedef BYTE byte; -typedef double DOUBLE; - -typedef void* PCONTEXT_HANDLE; -typedef PCONTEXT_HANDLE* PPCONTEXT_HANDLE; - -typedef ULONG error_status_t; - -#ifndef _NTDEF_ -typedef LONG NTSTATUS; -typedef NTSTATUS *PNTSTATUS; -#endif - -#ifndef _LPCBYTE_DEFINED -#define _LPCBYTE_DEFINED -typedef const BYTE *LPCBYTE; -#endif - -#ifndef _LPCVOID_DEFINED -#define _LPCVOID_DEFINED -typedef const VOID *LPCVOID; -#endif - -#ifndef _WIN32 - -typedef struct tagDEC -{ - USHORT wReserved; - union { - struct { - BYTE scale; - BYTE sign; - } DUMMYSTRUCTNAME; - USHORT signscale; - } DUMMYUNIONNAME; - ULONG Hi32; - union { - struct { - ULONG Lo32; - ULONG Mid32; - } DUMMYSTRUCTNAME2; - ULONGLONG Lo64; - } DUMMYUNIONNAME2; -} DECIMAL; - -typedef DECIMAL *LPDECIMAL; - -#define DECIMAL_NEG ((BYTE) 0x80) -#define DECIMAL_SETZERO(dec) { (dec).Lo64 = 0; (dec).Hi32 = 0; (dec).signscale = 0; } - -typedef char CCHAR; -typedef DWORD LCID; -typedef PDWORD PLCID; -typedef WORD LANGID; - -#endif - -#include - -#endif /* WINPR_WTYPES_H */ From d25855b2878b817c4ea94cb3ad31c761a9f940e4 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 17 Dec 2015 16:25:16 +0100 Subject: [PATCH 137/220] Added comment to generated defines. --- winpr/include/winpr/wtypes.h.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/winpr/include/winpr/wtypes.h.in b/winpr/include/winpr/wtypes.h.in index 09fba0d20..f067461d1 100644 --- a/winpr/include/winpr/wtypes.h.in +++ b/winpr/include/winpr/wtypes.h.in @@ -20,7 +20,9 @@ #ifndef WINPR_WTYPES_H #define WINPR_WTYPES_H +/* Set by CMake during configuration. */ #define WINPR_HAVE_STDINT_H @HAVE_STDINT_H@ +/* Set by CMake during configuration. */ #define WINPR_HAVE_STDINT_H @HAVE_STDBOOL_H@ /* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ From 60ae27b00a7000772d22dd07075d269a33b73e76 Mon Sep 17 00:00:00 2001 From: "zihao.jiang" Date: Sun, 28 Jun 2015 16:20:49 +0800 Subject: [PATCH 138/220] server/shadow: Completely decouple subsystem implementations and shadow framework internal details. It will be completely possible to implement subsystem with only include/freerdp/server/shadow.h and libfreerdp-shadow. Details as following: 1. Exported surface structure as subsystem implementations deeply depend on it to send image update 2. Export capture APIs. They are actually indepent APIs to help compare and calculate image difference. 3. Introduce API to trigger client frame update. Conceal details in subsystem->updateEvent 4. Pass client to client callbacks. Subsystem implementation may need to know 'which client' send the interaction event as well as the authentication request. Add this support in callback definition before anyone really use shadow framework APIs to implement a custom subsystem. Also added callback for client capability exchange 5. Remove X11_ShadowSubsystem Mac_ShadowSubsystem Win_ShadowSubsystem from libfreerdp-shadow. Discard FREERDP_API mark on ShadowSubsystemEntry functions and make them be compiled together with shadow.c in CMakeLists.txt. This is required from PR #2751. Now subsystem implementations and shadow.c could be regarded as an example for shadow framework. --- include/freerdp/server/shadow.h | 36 +++++-- server/shadow/CMakeLists.txt | 164 +++++++++++++++---------------- server/shadow/Mac/mac_shadow.c | 21 ++-- server/shadow/Win/win_shadow.c | 30 +++--- server/shadow/X11/x11_shadow.c | 23 ++--- server/shadow/shadow_audin.c | 2 +- server/shadow/shadow_capture.h | 3 - server/shadow/shadow_client.c | 12 ++- server/shadow/shadow_input.c | 10 +- server/shadow/shadow_subsystem.c | 5 + server/shadow/shadow_surface.h | 15 --- 11 files changed, 160 insertions(+), 161 deletions(-) diff --git a/include/freerdp/server/shadow.h b/include/freerdp/server/shadow.h index 72cc81410..5e8c71bf6 100644 --- a/include/freerdp/server/shadow.h +++ b/include/freerdp/server/shadow.h @@ -64,18 +64,19 @@ typedef int (*pfnShadowSubsystemStop)(rdpShadowSubsystem* subsystem); typedef int (*pfnShadowEnumMonitors)(MONITOR_DEF* monitors, int maxMonitors); -typedef int (*pfnShadowAuthenticate)(rdpShadowSubsystem* subsystem, +typedef int (*pfnShadowAuthenticate)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, const char* user, const char* domain, const char* password); typedef BOOL (*pfnShadowClientConnect)(rdpShadowSubsystem* subsystem, rdpShadowClient* client); typedef void (*pfnShadowClientDisconnect)(rdpShadowSubsystem* subsystem, rdpShadowClient* client); +typedef BOOL (*pfnShadowClientCapabilities)(rdpShadowSubsystem* subsystem, rdpShadowClient* client); -typedef int (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem, UINT32 flags); -typedef int (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem, UINT16 flags, UINT16 code); -typedef int (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem, UINT16 flags, UINT16 code); -typedef int (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y); -typedef int (*pfnShadowExtendedMouseEvent)(rdpShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y); +typedef int (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags); +typedef int (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code); +typedef int (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code); +typedef int (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y); +typedef int (*pfnShadowExtendedMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y); -typedef void (*pfnShadowChannelAudinServerReceiveSamples)(rdpShadowSubsystem* subsystem, const void* buf, int nframes); +typedef void (*pfnShadowChannelAudinServerReceiveSamples)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, const void* buf, int nframes); struct rdp_shadow_client { @@ -130,6 +131,21 @@ struct rdp_shadow_server freerdp_listener* listener; }; +struct rdp_shadow_surface +{ + rdpShadowServer* server; + + int x; + int y; + int width; + int height; + int scanline; + BYTE* data; + + CRITICAL_SECTION lock; + REGION16 invalidRegion; +}; + struct _RDP_SHADOW_ENTRY_POINTS { pfnShadowSubsystemNew New; @@ -174,6 +190,7 @@ struct _RDP_SHADOW_ENTRY_POINTS pfnShadowAuthenticate Authenticate; \ pfnShadowClientConnect ClientConnect; \ pfnShadowClientDisconnect ClientDisconnect; \ + pfnShadowClientCapabilities ClientCapabilities; \ \ rdpShadowServer* server @@ -278,6 +295,11 @@ FREERDP_API int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors); FREERDP_API rdpShadowServer* shadow_server_new(); FREERDP_API void shadow_server_free(rdpShadowServer* server); +FREERDP_API int shadow_capture_align_clip_rect(RECTANGLE_16* rect, RECTANGLE_16* clip); +FREERDP_API int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth, int nHeight, BYTE* pData2, int nStep2, RECTANGLE_16* rect); + +FREERDP_API void shadow_subsystem_frame_update(rdpShadowSubsystem* subsystem); + FREERDP_API BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam); FREERDP_API int shadow_client_boardcast_msg(rdpShadowServer* server, void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam); FREERDP_API int shadow_client_boardcast_quit(rdpShadowServer* server, int nExitCode); diff --git a/server/shadow/CMakeLists.txt b/server/shadow/CMakeLists.txt index d51371f68..ce5ac7f79 100644 --- a/server/shadow/CMakeLists.txt +++ b/server/shadow/CMakeLists.txt @@ -18,6 +18,87 @@ set(MODULE_NAME "freerdp-shadow") set(MODULE_PREFIX "FREERDP_SERVER_SHADOW") +include_directories(${OPENSSL_INCLUDE_DIR}) + +set(${MODULE_PREFIX}_SRCS + shadow_client.c + shadow_client.h + shadow_lobby.c + shadow_lobby.h + shadow_input.c + shadow_input.h + shadow_screen.c + shadow_screen.h + shadow_surface.c + shadow_surface.h + shadow_encoder.c + shadow_encoder.h + shadow_capture.c + shadow_capture.h + shadow_channels.c + shadow_channels.h + shadow_encomsp.c + shadow_encomsp.h + shadow_remdesk.c + shadow_remdesk.h + shadow_rdpsnd.c + shadow_rdpsnd.h + shadow_audin.c + shadow_audin.h + shadow_subsystem.c + shadow_subsystem.h + shadow_mcevent.c + shadow_mcevent.h + shadow_server.c + shadow.h) + +# On windows create dll version information. +# Vendor, product and year are already set in top level CMakeLists.txt +if (WIN32) + set (RC_VERSION_MAJOR ${FREERDP_VERSION_MAJOR}) + set (RC_VERSION_MINOR ${FREERDP_VERSION_MINOR}) + set (RC_VERSION_BUILD ${FREERDP_VERSION_REVISION}) + set (RC_VERSION_PATCH 0) + set (RC_VERSION_FILE "${CMAKE_SHARED_LIBRARY_PREFIX}${MODULE_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}" ) + + configure_file( + ${CMAKE_SOURCE_DIR}/cmake/WindowsDLLVersion.rc.in + ${CMAKE_CURRENT_BINARY_DIR}/version.rc + @ONLY) + + set ( ${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) +endif() + +add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +list(APPEND ${MODULE_PREFIX}_LIBS freerdp) +list(APPEND ${MODULE_PREFIX}_LIBS freerdp-server) +list(APPEND ${MODULE_PREFIX}_LIBS freerdp-client) + +list(APPEND ${MODULE_PREFIX}_LIBS winpr) +list(APPEND ${MODULE_PREFIX}_LIBS winpr-makecert-tool) + +list(APPEND ${MODULE_PREFIX}_LIBS rdtk) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +if (WITH_LIBRARY_VERSIONING) + set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) +endif() + +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT server) + +if (WITH_DEBUG_SYMBOLS AND MSVC) + install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) +endif() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/shadow") + +# command-line executable + +set(MODULE_NAME "freerdp-shadow-cli") +set(MODULE_PREFIX "FREERDP_SERVER_SHADOW_CLI") + if(WIN32) set(WITH_SHADOW_WIN 1) elseif(X11_FOUND AND NOT APPLE) @@ -146,39 +227,8 @@ if(WITH_SHADOW_MAC) list(APPEND ${MODULE_PREFIX}_MAC_LIBS ${IOKIT} ${IOSURFACE} ${CARBON}) endif() -include_directories(${OPENSSL_INCLUDE_DIR}) - set(${MODULE_PREFIX}_SRCS - shadow_client.c - shadow_client.h - shadow_lobby.c - shadow_lobby.h - shadow_input.c - shadow_input.h - shadow_screen.c - shadow_screen.h - shadow_surface.c - shadow_surface.h - shadow_encoder.c - shadow_encoder.h - shadow_capture.c - shadow_capture.h - shadow_channels.c - shadow_channels.h - shadow_encomsp.c - shadow_encomsp.h - shadow_remdesk.c - shadow_remdesk.h - shadow_rdpsnd.c - shadow_rdpsnd.h - shadow_audin.c - shadow_audin.h - shadow_subsystem.c - shadow_subsystem.h - shadow_mcevent.c - shadow_mcevent.h - shadow_server.c - shadow.h) + shadow.c) set(${MODULE_PREFIX}_WIN_SRCS Win/win_rdp.c @@ -214,56 +264,6 @@ endif() list(APPEND ${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_AUTH_LIBS}) -# On windows create dll version information. -# Vendor, product and year are already set in top level CMakeLists.txt -if (WIN32) - set (RC_VERSION_MAJOR ${FREERDP_VERSION_MAJOR}) - set (RC_VERSION_MINOR ${FREERDP_VERSION_MINOR}) - set (RC_VERSION_BUILD ${FREERDP_VERSION_REVISION}) - set (RC_VERSION_PATCH 0) - set (RC_VERSION_FILE "${CMAKE_SHARED_LIBRARY_PREFIX}${MODULE_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}" ) - - configure_file( - ${CMAKE_SOURCE_DIR}/cmake/WindowsDLLVersion.rc.in - ${CMAKE_CURRENT_BINARY_DIR}/version.rc - @ONLY) - - set ( ${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) -endif() - -add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) - -list(APPEND ${MODULE_PREFIX}_LIBS freerdp) -list(APPEND ${MODULE_PREFIX}_LIBS freerdp-server) -list(APPEND ${MODULE_PREFIX}_LIBS freerdp-client) - -list(APPEND ${MODULE_PREFIX}_LIBS winpr) -list(APPEND ${MODULE_PREFIX}_LIBS winpr-makecert-tool) - -list(APPEND ${MODULE_PREFIX}_LIBS rdtk) - -target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -if (WITH_LIBRARY_VERSIONING) - set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) -endif() - -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT server) - -if (WITH_DEBUG_SYMBOLS AND MSVC) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) -endif() - -set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/shadow") - -# command-line executable - -set(MODULE_NAME "freerdp-shadow-cli") -set(MODULE_PREFIX "FREERDP_SERVER_SHADOW_CLI") - -set(${MODULE_PREFIX}_SRCS - shadow.c) - # On windows create dll version information. # Vendor, product and year are already set in top level CMakeLists.txt if (WIN32) diff --git a/server/shadow/Mac/mac_shadow.c b/server/shadow/Mac/mac_shadow.c index 1c6bfe492..2fd5f96d4 100644 --- a/server/shadow/Mac/mac_shadow.c +++ b/server/shadow/Mac/mac_shadow.c @@ -25,13 +25,6 @@ #include #include -#include "../shadow_screen.h" -#include "../shadow_client.h" -#include "../shadow_surface.h" -#include "../shadow_capture.h" -#include "../shadow_subsystem.h" -#include "../shadow_mcevent.h" - #include "mac_shadow.h" #define TAG SERVER_TAG("shadow.mac") @@ -39,12 +32,12 @@ static macShadowSubsystem* g_Subsystem = NULL; -void mac_shadow_input_synchronize_event(macShadowSubsystem* subsystem, UINT32 flags) +void mac_shadow_input_synchronize_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags) { } -void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem, UINT16 flags, UINT16 code) +void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) { DWORD vkcode; DWORD keycode; @@ -87,12 +80,12 @@ void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem, UINT16 flags CFRelease(source); } -void mac_shadow_input_unicode_keyboard_event(macShadowSubsystem* subsystem, UINT16 flags, UINT16 code) +void mac_shadow_input_unicode_keyboard_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) { } -void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) +void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { UINT32 scrollX = 0; UINT32 scrollY = 0; @@ -196,7 +189,7 @@ void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem, UINT16 flags, U } } -void mac_shadow_input_extended_mouse_event(macShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) +void mac_shadow_input_extended_mouse_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { } @@ -366,7 +359,7 @@ void (^mac_capture_stream_handler)(CGDisplayStreamFrameStatus, uint64_t, IOSurfa count = ArrayList_Count(server->clients); - shadow_multiclient_publish_and_wait(subsystem->updateEvent); + shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem); if (count == 1) { @@ -667,7 +660,7 @@ macShadowSubsystem* mac_shadow_subsystem_new() return subsystem; } -FREERDP_API int Mac_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) +int Mac_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) { pEntryPoints->New = (pfnShadowSubsystemNew) mac_shadow_subsystem_new; pEntryPoints->Free = (pfnShadowSubsystemFree) mac_shadow_subsystem_free; diff --git a/server/shadow/Win/win_shadow.c b/server/shadow/Win/win_shadow.c index 0a05cb1a4..d1dbc5888 100644 --- a/server/shadow/Win/win_shadow.c +++ b/server/shadow/Win/win_shadow.c @@ -24,22 +24,16 @@ #include #include -#include "../shadow_screen.h" -#include "../shadow_surface.h" -#include "../shadow_capture.h" -#include "../shadow_subsystem.h" -#include "../shadow_mcevent.h" - #include "win_shadow.h" #define TAG SERVER_TAG("shadow.win") -void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem, UINT32 flags) +void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags) { } -void win_shadow_input_keyboard_event(winShadowSubsystem* subsystem, UINT16 flags, UINT16 code) +void win_shadow_input_keyboard_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) { INPUT event; @@ -59,7 +53,7 @@ void win_shadow_input_keyboard_event(winShadowSubsystem* subsystem, UINT16 flags SendInput(1, &event, sizeof(INPUT)); } -void win_shadow_input_unicode_keyboard_event(winShadowSubsystem* subsystem, UINT16 flags, UINT16 code) +void win_shadow_input_unicode_keyboard_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) { INPUT event; @@ -76,7 +70,7 @@ void win_shadow_input_unicode_keyboard_event(winShadowSubsystem* subsystem, UINT SendInput(1, &event, sizeof(INPUT)); } -void win_shadow_input_mouse_event(winShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) +void win_shadow_input_mouse_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { INPUT event; float width; @@ -143,7 +137,7 @@ void win_shadow_input_mouse_event(winShadowSubsystem* subsystem, UINT16 flags, U } } -void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) +void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { INPUT event; float width; @@ -187,20 +181,20 @@ void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem, UINT16 int win_shadow_invalidate_region(winShadowSubsystem* subsystem, int x, int y, int width, int height) { rdpShadowServer* server; - rdpShadowScreen* screen; + rdpShadowSurface* surface; RECTANGLE_16 invalidRect; server = subsystem->server; - screen = server->screen; + surface = server->surface; invalidRect.left = x; invalidRect.top = y; invalidRect.right = x + width; invalidRect.bottom = y + height; - EnterCriticalSection(&(screen->lock)); - region16_union_rect(&(screen->invalidRegion), &(screen->invalidRegion), &invalidRect); - LeaveCriticalSection(&(screen->lock)); + EnterCriticalSection(&(surface->lock)); + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); + LeaveCriticalSection(&(surface->lock)); return 1; } @@ -288,7 +282,7 @@ int win_shadow_surface_copy(winShadowSubsystem* subsystem) count = ArrayList_Count(server->clients); - shadow_multiclient_publish_and_wait(subsystem->updateEvent); + shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem); ArrayList_Unlock(server->clients); @@ -525,7 +519,7 @@ winShadowSubsystem* win_shadow_subsystem_new() return subsystem; } -FREERDP_API int Win_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) +int Win_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) { pEntryPoints->New = (pfnShadowSubsystemNew) win_shadow_subsystem_new; pEntryPoints->Free = (pfnShadowSubsystemFree) win_shadow_subsystem_free; diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index 98af9f8a4..9a16662a9 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -40,13 +40,6 @@ #include #include -#include "../shadow_screen.h" -#include "../shadow_client.h" -#include "../shadow_capture.h" -#include "../shadow_surface.h" -#include "../shadow_subsystem.h" -#include "../shadow_mcevent.h" - #include "x11_shadow.h" #define TAG SERVER_TAG("shadow.x11") @@ -161,7 +154,7 @@ int x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info) return 1; } -int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user, const char* domain, const char* password) +int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, rdpShadowClient* client, const char* user, const char* domain, const char* password) { int pam_status; SHADOW_PAM_AUTH_INFO* info; @@ -215,12 +208,12 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user, #endif -void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem, UINT32 flags) +void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags) { } -void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 code) +void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) { #ifdef WITH_XTEST DWORD vkcode; @@ -256,12 +249,12 @@ void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, UINT16 flags #endif } -void x11_shadow_input_unicode_keyboard_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 code) +void x11_shadow_input_unicode_keyboard_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) { } -void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) +void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST int button = 0; @@ -314,7 +307,7 @@ void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, UINT16 flags, U #endif } -void x11_shadow_input_extended_mouse_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) +void x11_shadow_input_extended_mouse_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST int button = 0; @@ -793,7 +786,7 @@ int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem) count = ArrayList_Count(server->clients); - shadow_multiclient_publish_and_wait(subsystem->updateEvent); + shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem); if (count == 1) { @@ -1444,7 +1437,7 @@ void x11_shadow_subsystem_free(x11ShadowSubsystem* subsystem) free(subsystem); } -FREERDP_API int X11_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) +int X11_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) { pEntryPoints->New = (pfnShadowSubsystemNew) x11_shadow_subsystem_new; pEntryPoints->Free = (pfnShadowSubsystemFree) x11_shadow_subsystem_free; diff --git a/server/shadow/shadow_audin.c b/server/shadow/shadow_audin.c index 6e35f3f3e..c655c82a0 100644 --- a/server/shadow/shadow_audin.c +++ b/server/shadow/shadow_audin.c @@ -93,7 +93,7 @@ static UINT AudinServerReceiveSamples(audin_server_context* context, const void* return CHANNEL_RC_OK; if (subsystem->AudinServerReceiveSamples) - subsystem->AudinServerReceiveSamples(subsystem, buf, nframes); + subsystem->AudinServerReceiveSamples(subsystem, client, buf, nframes); return CHANNEL_RC_OK; } diff --git a/server/shadow/shadow_capture.h b/server/shadow/shadow_capture.h index 3ce3cddb0..f5e7404c5 100644 --- a/server/shadow/shadow_capture.h +++ b/server/shadow/shadow_capture.h @@ -38,9 +38,6 @@ struct rdp_shadow_capture extern "C" { #endif -int shadow_capture_align_clip_rect(RECTANGLE_16* rect, RECTANGLE_16* clip); -int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth, int nHeight, BYTE* pData2, int nStep2, RECTANGLE_16* rect); - rdpShadowCapture* shadow_capture_new(rdpShadowServer* server); void shadow_capture_free(rdpShadowCapture* capture); diff --git a/server/shadow/shadow_client.c b/server/shadow/shadow_client.c index 32e54d10c..6c5d80bc3 100644 --- a/server/shadow/shadow_client.c +++ b/server/shadow/shadow_client.c @@ -179,6 +179,16 @@ void shadow_client_message_free(wMessage* message) BOOL shadow_client_capabilities(freerdp_peer* peer) { + rdpShadowSubsystem* subsystem; + rdpShadowClient* client; + + client = (rdpShadowClient*) peer->context; + subsystem = client->server->subsystem; + + if (subsystem->ClientCapabilities) + { + return subsystem->ClientCapabilities(subsystem, client); + } return TRUE; } @@ -243,7 +253,7 @@ BOOL shadow_client_post_connect(freerdp_peer* peer) { if (subsystem->Authenticate) { - authStatus = subsystem->Authenticate(subsystem, + authStatus = subsystem->Authenticate(subsystem, client, settings->Username, settings->Domain, settings->Password); } } diff --git a/server/shadow/shadow_input.c b/server/shadow/shadow_input.c index e12878965..7f97b2911 100644 --- a/server/shadow/shadow_input.c +++ b/server/shadow/shadow_input.c @@ -32,7 +32,7 @@ BOOL shadow_input_synchronize_event(rdpInput* input, UINT32 flags) if (subsystem->SynchronizeEvent) { - subsystem->SynchronizeEvent(subsystem, flags); + subsystem->SynchronizeEvent(subsystem, client, flags); } return TRUE; } @@ -47,7 +47,7 @@ BOOL shadow_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) if (subsystem->KeyboardEvent) { - subsystem->KeyboardEvent(subsystem, flags, code); + subsystem->KeyboardEvent(subsystem, client, flags, code); } return TRUE; } @@ -62,7 +62,7 @@ BOOL shadow_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 c if (subsystem->UnicodeKeyboardEvent) { - subsystem->UnicodeKeyboardEvent(subsystem, flags, code); + subsystem->UnicodeKeyboardEvent(subsystem, client, flags, code); } return TRUE; } @@ -98,7 +98,7 @@ BOOL shadow_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) if (subsystem->MouseEvent) { - subsystem->MouseEvent(subsystem, flags, x, y); + subsystem->MouseEvent(subsystem, client, flags, x, y); } return TRUE; } @@ -122,7 +122,7 @@ BOOL shadow_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, if (subsystem->ExtendedMouseEvent) { - subsystem->ExtendedMouseEvent(subsystem, flags, x, y); + subsystem->ExtendedMouseEvent(subsystem, client, flags, x, y); } return TRUE; } diff --git a/server/shadow/shadow_subsystem.c b/server/shadow/shadow_subsystem.c index 80a6fdeb3..0cbb46f5e 100644 --- a/server/shadow/shadow_subsystem.c +++ b/server/shadow/shadow_subsystem.c @@ -271,3 +271,8 @@ int shadow_subsystem_pointer_convert_alpha_pointer_data(BYTE* pixels, BOOL premu return 1; } + +void shadow_subsystem_frame_update(rdpShadowSubsystem* subsystem) +{ + shadow_multiclient_publish_and_wait(subsystem->updateEvent); +} diff --git a/server/shadow/shadow_surface.h b/server/shadow/shadow_surface.h index eeae82220..2eefe5e33 100644 --- a/server/shadow/shadow_surface.h +++ b/server/shadow/shadow_surface.h @@ -24,21 +24,6 @@ #include #include -struct rdp_shadow_surface -{ - rdpShadowServer* server; - - int x; - int y; - int width; - int height; - int scanline; - BYTE* data; - - CRITICAL_SECTION lock; - REGION16 invalidRegion; -}; - #ifdef __cplusplus extern "C" { #endif From aa2709a999d87ef03b2f0ad5ca196ede7c7e496b Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Dec 2015 16:25:09 +0100 Subject: [PATCH 139/220] winpr: create a specific winpr nt file handle There exist two definitions of WINPR_FILE: in file/ and in nt/. Both are different definitions used differently. Therefore split them into WINPR_FILE and WINPR_NT_FILE. --- winpr/libwinpr/nt/nt.c | 29 +++++++++++++++++++-------- winpr/libwinpr/nt/nt.h | 45 ------------------------------------------ 2 files changed, 21 insertions(+), 53 deletions(-) delete mode 100644 winpr/libwinpr/nt/nt.h diff --git a/winpr/libwinpr/nt/nt.c b/winpr/libwinpr/nt/nt.c index b45509ff0..7b6d2128b 100644 --- a/winpr/libwinpr/nt/nt.c +++ b/winpr/libwinpr/nt/nt.c @@ -57,12 +57,25 @@ VOID _InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes, #ifndef _WIN32 -#include "nt.h" #include - #include +#include "../handle/handle.h" + +struct winpr_nt_file +{ + WINPR_HANDLE_DEF(); + + ACCESS_MASK DesiredAccess; + OBJECT_ATTRIBUTES ObjectAttributes; + ULONG FileAttributes; + ULONG ShareAccess; + ULONG CreateDisposition; + ULONG CreateOptions; +}; +typedef struct winpr_nt_file WINPR_NT_FILE; + static pthread_once_t _TebOnceControl = PTHREAD_ONCE_INIT; static pthread_key_t _TebKey; @@ -210,9 +223,9 @@ NTSTATUS _NtCreateFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, PLARGE_INTEGER AllocationSize, ULONG FileAttributes, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength) { - WINPR_FILE* pFileHandle; + WINPR_NT_FILE* pFileHandle; - pFileHandle = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); + pFileHandle = (WINPR_NT_FILE*) calloc(1, sizeof(WINPR_NT_FILE)); if (!pFileHandle) return STATUS_NO_MEMORY; @@ -241,9 +254,9 @@ NTSTATUS _NtOpenFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions) { - WINPR_FILE* pFileHandle; + WINPR_NT_FILE* pFileHandle; - pFileHandle = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); + pFileHandle = (WINPR_NT_FILE*) calloc(1, sizeof(WINPR_NT_FILE)); if (!pFileHandle) return STATUS_NO_MEMORY; @@ -298,12 +311,12 @@ NTSTATUS _NtDeviceIoControlFile(HANDLE FileHandle, HANDLE Event, NTSTATUS _NtClose(HANDLE Handle) { - WINPR_FILE* pFileHandle; + WINPR_NT_FILE* pFileHandle; if (!Handle) return 0; - pFileHandle = (WINPR_FILE*) Handle; + pFileHandle = (WINPR_NT_FILE*) Handle; free(pFileHandle); diff --git a/winpr/libwinpr/nt/nt.h b/winpr/libwinpr/nt/nt.h deleted file mode 100644 index 52eda2f98..000000000 --- a/winpr/libwinpr/nt/nt.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * WinPR: Windows Portable Runtime - * Windows Native System Services - * - * Copyright 2013 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WINPR_NT_PRIVATE_H -#define WINPR_NT_PRIVATE_H - -#ifndef _WIN32 - -#include - -#include "../handle/handle.h" - -struct winpr_file -{ - WINPR_HANDLE_DEF(); - - ACCESS_MASK DesiredAccess; - OBJECT_ATTRIBUTES ObjectAttributes; - ULONG FileAttributes; - ULONG ShareAccess; - ULONG CreateDisposition; - ULONG CreateOptions; -}; -typedef struct winpr_file WINPR_FILE; - -#endif - -#endif /* WINPR_NT_PRIVATE_H */ - From a9e3368d4473e146c54ede37e3edd331e6e68d59 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 12 Jan 2016 16:38:53 +0100 Subject: [PATCH 140/220] Fixed broken duplicate define. --- winpr/include/winpr/wtypes.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/include/winpr/wtypes.h.in b/winpr/include/winpr/wtypes.h.in index f067461d1..ffa94cf05 100644 --- a/winpr/include/winpr/wtypes.h.in +++ b/winpr/include/winpr/wtypes.h.in @@ -23,7 +23,7 @@ /* Set by CMake during configuration. */ #define WINPR_HAVE_STDINT_H @HAVE_STDINT_H@ /* Set by CMake during configuration. */ -#define WINPR_HAVE_STDINT_H @HAVE_STDBOOL_H@ +#define WINPR_HAVE_STDBOOL_H @HAVE_STDBOOL_H@ /* MSDN: Windows Data Types - http://msdn.microsoft.com/en-us/library/aa383751/ */ /* [MS-DTYP]: Windows Data Types - http://msdn.microsoft.com/en-us/library/cc230273/ */ From 601c0b8f1fa082451fc75d18571454717f56d5a6 Mon Sep 17 00:00:00 2001 From: Giovanni Panozzo Date: Mon, 21 Dec 2015 08:00:14 +0100 Subject: [PATCH 141/220] Add cmake flag -DWITH_SANITIZE_ADDRESS=on to enable GCC and clang AddressSanitizer --- CMakeLists.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 922b59719..7178064f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,30 @@ if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang") endif() endif() +# Enable address sanitizer, where supported and when required +if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCC) + if(WITH_SANITIZE_ADDRESS) + if (DEFINED CMAKE_REQUIRED_FLAGS) + set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + endif() + set(CMAKE_REQUIRED_FLAGS "-fsanitize=address") + CHECK_C_COMPILER_FLAG ("-fsanitize=address" fsanitize-address) + if(fsanitize-address) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + endif() + if (DEFINED SAVE_CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS}) + else() + unset(CMAKE_REQUIRED_FLAGS) + endif() + + CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer) + if(fno-omit-frame-pointer) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer") + endif() + endif() +endif() + if(MSVC) # Remove previous warning definitions, # NMake is otherwise complaining. From 25363c05d66723bc0b22cde631fa53aed8b9accf Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 30 Dec 2015 18:42:54 +0100 Subject: [PATCH 142/220] update .gitignore files * add missing entries --- server/shadow/.gitignore | 2 +- winpr/include/winpr/.gitignore | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/shadow/.gitignore b/server/shadow/.gitignore index 662d7d541..d21ea72ef 100644 --- a/server/shadow/.gitignore +++ b/server/shadow/.gitignore @@ -1,2 +1,2 @@ -freerdp-shadow +freerdp-shadow-cli diff --git a/winpr/include/winpr/.gitignore b/winpr/include/winpr/.gitignore index 67020331b..60c26bb4f 100644 --- a/winpr/include/winpr/.gitignore +++ b/winpr/include/winpr/.gitignore @@ -1 +1,2 @@ version.h +wtypes.h From b8136a376992dc0ba037ca402e7a7c4eca6c412b Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 30 Dec 2015 18:45:09 +0100 Subject: [PATCH 143/220] build: remove FREERDP_MONOLITHIC_BUILD FREERDP_MONOLITHIC_BUILD was obsolete for a while and unused --- CMakeLists.txt | 5 +---- FreeRDPConfig.cmake.in | 1 - cmake/ComplexLibrary.cmake | 28 ---------------------------- winpr/CMakeLists.txt | 4 +--- winpr/WinPRConfig.cmake.in | 1 - 5 files changed, 2 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 922b59719..4b19b2981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -806,12 +806,9 @@ if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") set(FREERDP_INCLUDE_DIR "include") - # keep for legacy builds - set(FREERDP_MONOLITHIC_BUILD OFF) - configure_package_config_file(FreeRDPConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfig.cmake INSTALL_DESTINATION ${FREERDP_CMAKE_INSTALL_DIR} - PATH_VARS FREERDP_INCLUDE_DIR FREERDP_MONOLITHIC_BUILD) + PATH_VARS FREERDP_INCLUDE_DIR) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfigVersion.cmake VERSION ${FREERDP_VERSION} COMPATIBILITY SameMajorVersion) diff --git a/FreeRDPConfig.cmake.in b/FreeRDPConfig.cmake.in index 7dcea99de..a2321e727 100644 --- a/FreeRDPConfig.cmake.in +++ b/FreeRDPConfig.cmake.in @@ -4,7 +4,6 @@ set(FreeRDP_VERSION_MAJOR "@FREERDP_VERSION_MAJOR@") set(FreeRDP_VERSION_MINOR "@FREERDP_VERSION_MINOR@") set(FreeRDP_VERSION_REVISION "@FREERDP_VERSION_REVISION@") -set(FreeRDP_MONOLITHIC_BUILD "@FREERDP_MONOLITHIC_BUILD@") set_and_check(FreeRDP_INCLUDE_DIR "@PACKAGE_FREERDP_INCLUDE_DIR@") diff --git a/cmake/ComplexLibrary.cmake b/cmake/ComplexLibrary.cmake index c6c54aae2..703e9376a 100644 --- a/cmake/ComplexLibrary.cmake +++ b/cmake/ComplexLibrary.cmake @@ -3,34 +3,6 @@ include(EchoTarget) include(CMakeParseArguments) -macro(set_complex_link_libraries) - - set(PREFIX "COMPLEX_LIBRARY") - - cmake_parse_arguments(${PREFIX} - "INTERNAL" - "MODULE;VARIABLE;MONOLITHIC" - "MODULES" - ${ARGN}) - - if(NOT DEFINED ${PREFIX}_MONOLITHIC) - set(${PREFIX}_MONOLITHIC FALSE) - endif() - - if(${${PREFIX}_MONOLITHIC}) - if(${${PREFIX}_INTERNAL}) - set(${PREFIX}_LIBS) - else() - set(${PREFIX}_LIBS ${${PREFIX}_MODULE}) - endif() - else() - set(${PREFIX}_LIBS ${${PREFIX}_MODULES}) - endif() - - set(${${PREFIX}_VARIABLE} ${${${PREFIX}_VARIABLE}} ${${PREFIX}_LIBS}) - -endmacro(set_complex_link_libraries) - # - add a new library to a module for export # MODULE - module the library belongs to # LIBNAME - name of the library diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index 12e515e6f..1021d164e 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -164,12 +164,10 @@ if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") set(WINPR_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/WinPR") set(WINPR_INCLUDE_DIR "include") - # Keep this for legacy builds - set(WINPR_MONOLITHIC_BUILD OFF) configure_package_config_file(WinPRConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/WinPRConfig.cmake INSTALL_DESTINATION ${WINPR_CMAKE_INSTALL_DIR} - PATH_VARS WINPR_INCLUDE_DIR WINPR_MONOLITHIC_BUILD) + PATH_VARS WINPR_INCLUDE_DIR) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/WinPRConfigVersion.cmake VERSION ${WINPR_VERSION} COMPATIBILITY SameMajorVersion) diff --git a/winpr/WinPRConfig.cmake.in b/winpr/WinPRConfig.cmake.in index 3a7a6c005..00c69c984 100644 --- a/winpr/WinPRConfig.cmake.in +++ b/winpr/WinPRConfig.cmake.in @@ -4,7 +4,6 @@ set(WinPR_VERSION_MAJOR "@WINPR_VERSION_MAJOR@") set(WinPR_VERSION_MINOR "@WINPR_VERSION_MINOR@") set(WinPR_VERSION_REVISION "@WINPR_VERSION_REVISION@") -set(WinPR_MONOLITHIC_BUILD "@WINPR_MONOLITHIC_BUILD@") set_and_check(WinPR_INCLUDE_DIR "@PACKAGE_WINPR_INCLUDE_DIR@") From 6fa36081112c46951096cddfacc0f760e4728b25 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 8 Jan 2016 14:07:35 +0100 Subject: [PATCH 144/220] cleanup cmake exports and pkg-config files With this commit the "exported" components (usable with pkg-config and cmake find module package) * winpr - winpr library and headers * freerdp - core library and headers * freerdp-client - client specific library * freerdp-server - server specific library * rdtk - rdtk headers and library To allow the installation of multiple different version (different major number) the include files were moved into the respective sub folder: freerdp -> freerdp{MAJOR}/freerdp (currently freerdp2/freerdp/) winpr -> winpr{MAJOR}/winpr (currently winrp1/winpr/) rdtk -> rdpk{MAJOR}/rdtk (currently rdtk0/rdtk/ The generated pkg-config and cmake find modules now also include the major version number. Currently the following pkg-config are generated and installed. * winpr1 * freerdp2 * freerdp-server2 * freerdp-client2 * rdtk0 As cmake is able to handle multiple versions out of the box the following can be used to find a specific module: find_package(WinPR) find_package(FreeRDP) find_package(FreeRDP-Server) find_package(FreeRDP-Client) find_package(RdTk) As cmake doesn't automatically resolve dependencies for packages it is necessary to manually include the requirements. For example if FreeRDP-Client is required WinPR and FreeRDP need to be included (find_package) as well. This commit also fixes the installation when STATIC_CHANNELS are built. WITH STATIC_CHANNELS all channels are linked into libfreerdp-client, for this all channels are generated as linker archive and linked together in the final step. Before the intermediate linker archives were, although not required and useful, installed. Same applies for server side channels. --- CMakeLists.txt | 45 ++++--------------- channels/CMakeLists.txt | 17 +++++++ channels/audin/client/CMakeLists.txt | 1 - channels/audin/client/alsa/CMakeLists.txt | 7 --- channels/audin/client/mac/CMakeLists.txt | 3 -- channels/audin/client/opensles/CMakeLists.txt | 2 - channels/audin/client/oss/CMakeLists.txt | 2 - channels/audin/client/pulse/CMakeLists.txt | 2 - channels/audin/client/winmm/CMakeLists.txt | 2 - channels/audin/server/CMakeLists.txt | 2 - channels/cliprdr/client/CMakeLists.txt | 2 - channels/cliprdr/server/CMakeLists.txt | 2 - channels/disp/client/CMakeLists.txt | 1 - channels/drdynvc/client/CMakeLists.txt | 1 - channels/drdynvc/server/CMakeLists.txt | 2 - channels/drive/client/CMakeLists.txt | 1 - channels/echo/client/CMakeLists.txt | 1 - channels/echo/server/CMakeLists.txt | 2 - channels/encomsp/client/CMakeLists.txt | 6 --- channels/encomsp/server/CMakeLists.txt | 2 - channels/parallel/client/CMakeLists.txt | 1 - channels/printer/client/CMakeLists.txt | 1 - channels/rail/client/CMakeLists.txt | 2 - channels/rdpdr/client/CMakeLists.txt | 2 - channels/rdpdr/server/CMakeLists.txt | 2 - channels/rdpei/client/CMakeLists.txt | 1 - channels/rdpei/server/CMakeLists.txt | 2 - channels/rdpgfx/client/CMakeLists.txt | 2 - channels/rdpsnd/client/CMakeLists.txt | 2 - channels/rdpsnd/client/alsa/CMakeLists.txt | 2 - channels/rdpsnd/client/ios/CMakeLists.txt | 2 - channels/rdpsnd/client/mac/CMakeLists.txt | 2 - .../rdpsnd/client/opensles/CMakeLists.txt | 2 - channels/rdpsnd/client/oss/CMakeLists.txt | 2 - channels/rdpsnd/client/pulse/CMakeLists.txt | 2 - channels/rdpsnd/client/winmm/CMakeLists.txt | 1 - channels/rdpsnd/server/CMakeLists.txt | 2 - channels/remdesk/client/CMakeLists.txt | 2 - channels/remdesk/server/CMakeLists.txt | 4 -- channels/serial/client/CMakeLists.txt | 1 - channels/server/channels.c | 9 ++++ channels/smartcard/client/CMakeLists.txt | 2 - channels/tsmf/client/CMakeLists.txt | 2 - channels/tsmf/client/alsa/CMakeLists.txt | 2 - channels/tsmf/client/ffmpeg/CMakeLists.txt | 1 - channels/tsmf/client/gstreamer/CMakeLists.txt | 6 --- channels/tsmf/client/oss/CMakeLists.txt | 2 - channels/tsmf/client/pulse/CMakeLists.txt | 2 - channels/urbdrc/client/CMakeLists.txt | 2 - channels/urbdrc/client/libusb/CMakeLists.txt | 2 - client/.gitignore | 1 + client/CMakeLists.txt | 21 +++++++++ client/FreeRDP-ClientConfig.cmake.in | 10 +++++ client/Windows/CMakeLists.txt | 2 +- client/X11/CMakeLists.txt | 4 +- client/common/CMakeLists.txt | 12 +++-- client/freerdp-client.pc.in | 15 +++++++ include/CMakeLists.txt | 25 ++++++----- libfreerdp/CMakeLists.txt | 24 ++++++++++ .../FreeRDPConfig.cmake.in | 0 freerdp.pc.in => libfreerdp/freerdp.pc.in | 8 ++-- rdtk/CMakeLists.txt | 14 +++--- rdtk/include/CMakeLists.txt | 2 +- rdtk/rdtk.pc.in | 15 +++++++ server/.gitignore | 1 + server/CMakeLists.txt | 22 +++++++++ server/FreeRDP-ServerConfig.cmake.in | 10 +++++ server/common/CMakeLists.txt | 20 ++++----- server/freerdp-server.pc.in | 15 +++++++ server/shadow/CMakeLists.txt | 2 - third-party/.gitignore | 1 + winpr/.gitignore | 1 - winpr/CMakeLists.txt | 12 +++-- winpr/include/CMakeLists.txt | 5 ++- winpr.pc.in => winpr/winpr.pc.in | 8 ++-- 75 files changed, 228 insertions(+), 192 deletions(-) create mode 100644 client/FreeRDP-ClientConfig.cmake.in create mode 100644 client/freerdp-client.pc.in rename FreeRDPConfig.cmake.in => libfreerdp/FreeRDPConfig.cmake.in (100%) rename freerdp.pc.in => libfreerdp/freerdp.pc.in (68%) create mode 100644 rdtk/rdtk.pc.in create mode 100644 server/FreeRDP-ServerConfig.cmake.in create mode 100644 server/freerdp-server.pc.in rename winpr.pc.in => winpr/winpr.pc.in (74%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b19b2981..68ff44e06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ if (FREERDP_VERSION_SUFFIX) else() set(FREERDP_VERSION_FULL "${FREERDP_VERSION}") endif() +set(FREERDP_INCLUDE_DIR "include/freerdp${FREERDP_VERSION_MAJOR}/") # Allow to search the host machine for git if(ANDROID OR IOS) @@ -787,6 +788,14 @@ if(WITH_CHANNELS) add_subdirectory(channels) endif() +if (${CMAKE_VERSION} VERSION_LESS 2.8.12) + set(PUBLIC_KEYWORD "") + set(PRIVATE_KEYWORD "") +else() + set(PUBLIC_KEYWORD "PUBLIC") + set(PRIVATE_KEYWORD "PRIVATE") +endif() + if(WITH_CLIENT_COMMON OR WITH_CLIENT) add_subdirectory(client) endif() @@ -795,31 +804,6 @@ if(WITH_SERVER) add_subdirectory(server) endif() - -# Exporting - -if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") - - export(PACKAGE freerdp) - - set(FREERDP_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/FreeRDP") - - set(FREERDP_INCLUDE_DIR "include") - - configure_package_config_file(FreeRDPConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfig.cmake - INSTALL_DESTINATION ${FREERDP_CMAKE_INSTALL_DIR} - PATH_VARS FREERDP_INCLUDE_DIR) - - write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfigVersion.cmake - VERSION ${FREERDP_VERSION} COMPATIBILITY SameMajorVersion) - - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfigVersion.cmake - DESTINATION ${FREERDP_CMAKE_INSTALL_DIR}) - - install(EXPORT FreeRDPTargets DESTINATION ${FREERDP_CMAKE_INSTALL_DIR}) - -endif() - # Packaging set(CMAKE_CPACK_INCLUDE_FILE "CMakeCPack.cmake") @@ -835,14 +819,3 @@ endif() #message("VENDOR: ${VENDOR} CLIENT_VENDOR_PATH: ${CLIENT_VENDOR_PATH} CMAKE_CPACK_INCLUDE_FILE: ${CMAKE_CPACK_INCLUDE_FILE}") include(${CMAKE_CPACK_INCLUDE_FILE}) - -set(FREERDP_PC_LIBS "-lfreerdp -lfreerdp-client") -set(WINPR_PC_LIBS "-lwinpr") -if (WITH_SERVER) - set(FREERDP_PC_LIBS "${FREERDP_PC_LIBS} -lfreerdp-server") -endif() - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp.pc @ONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr.pc.in ${CMAKE_CURRENT_BINARY_DIR}/winpr.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/channels/CMakeLists.txt b/channels/CMakeLists.txt index cb7880c34..548a0057b 100644 --- a/channels/CMakeLists.txt +++ b/channels/CMakeLists.txt @@ -154,6 +154,20 @@ macro(add_channel_client_subsystem _channel_prefix _channel_name _subsystem _typ endif() endmacro(add_channel_client_subsystem) +macro(channel_install _targets _destination _export_target) + if (NOT STATIC_CHANNELS OR ${CMAKE_VERSION} VERSION_LESS 2.8.12) + install(TARGETS ${_targets} DESTINATION ${_destination} EXPORT ${_export_target}) + endif() +endmacro(channel_install) + +macro(server_channel_install _targets _destination) + channel_install(${_targets} ${_destination} "FreeRDP-ServerTargets") +endmacro(server_channel_install) + +macro(client_channel_install _targets _destination) + channel_install(${_targets} ${_destination} "FreeRDP-ClientTargets") +endmacro(client_channel_install) + macro(add_channel_client_library _module_prefix _module_name _channel_name _dynamic _entry) if(${_dynamic} AND (NOT STATIC_CHANNELS)) # On windows create dll version information. @@ -174,6 +188,7 @@ macro(add_channel_client_library _module_prefix _module_name _channel_name _dyna endif() add_library(${_module_name} ${${_module_prefix}_SRCS}) + client_channel_install(${_module_name} ${FREERDP_ADDIN_PATH}) else() set(${_module_prefix}_STATIC ON PARENT_SCOPE) set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE) @@ -203,6 +218,7 @@ macro(add_channel_client_subsystem_library _module_prefix _module_name _channel_ endif() add_library(${_module_name} ${${_module_prefix}_SRCS}) + client_channel_install(${_module_name} ${FREERDP_ADDIN_PATH}) else() set(${_module_prefix}_STATIC ON PARENT_SCOPE) set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE) @@ -230,6 +246,7 @@ macro(add_channel_server_library _module_prefix _module_name _channel_name _dyna endif() add_library(${_module_name} ${${_module_prefix}_SRCS}) + server_channel_install(${_module_name} ${FREERDP_ADDIN_PATH}) else() set(${_module_prefix}_STATIC ON PARENT_SCOPE) set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE) diff --git a/channels/audin/client/CMakeLists.txt b/channels/audin/client/CMakeLists.txt index 32e3e3bde..1f593b8e2 100644 --- a/channels/audin/client/CMakeLists.txt +++ b/channels/audin/client/CMakeLists.txt @@ -27,7 +27,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/audin/client/alsa/CMakeLists.txt b/channels/audin/client/alsa/CMakeLists.txt index bb2df3230..9a90387d9 100644 --- a/channels/audin/client/alsa/CMakeLists.txt +++ b/channels/audin/client/alsa/CMakeLists.txt @@ -30,10 +30,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N set(${MODULE_PREFIX}_LIBS freerdp ${ALSA_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - -if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) -endif() - diff --git a/channels/audin/client/mac/CMakeLists.txt b/channels/audin/client/mac/CMakeLists.txt index feca0d622..a5371c1ea 100644 --- a/channels/audin/client/mac/CMakeLists.txt +++ b/channels/audin/client/mac/CMakeLists.txt @@ -29,6 +29,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N set(${MODULE_PREFIX}_LIBS freerdp ${MAC_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - diff --git a/channels/audin/client/opensles/CMakeLists.txt b/channels/audin/client/opensles/CMakeLists.txt index 8844c22ec..abc69219f 100644 --- a/channels/audin/client/opensles/CMakeLists.txt +++ b/channels/audin/client/opensles/CMakeLists.txt @@ -31,5 +31,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N set(${MODULE_PREFIX}_LIBS freerdp ${OPENSLES_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/audin/client/oss/CMakeLists.txt b/channels/audin/client/oss/CMakeLists.txt index 1b34fd0de..315e71e60 100644 --- a/channels/audin/client/oss/CMakeLists.txt +++ b/channels/audin/client/oss/CMakeLists.txt @@ -31,5 +31,3 @@ set(${MODULE_PREFIX}_LIBS freerdp ${OSS_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - diff --git a/channels/audin/client/pulse/CMakeLists.txt b/channels/audin/client/pulse/CMakeLists.txt index 5047aaef5..10000f4b3 100644 --- a/channels/audin/client/pulse/CMakeLists.txt +++ b/channels/audin/client/pulse/CMakeLists.txt @@ -30,5 +30,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N set(${MODULE_PREFIX}_LIBS freerdp ${PULSE_LIBRARY}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/audin/client/winmm/CMakeLists.txt b/channels/audin/client/winmm/CMakeLists.txt index 52dd91dd6..c7d3e2b14 100644 --- a/channels/audin/client/winmm/CMakeLists.txt +++ b/channels/audin/client/winmm/CMakeLists.txt @@ -31,8 +31,6 @@ set(${MODULE_PREFIX}_LIBS freerdp winmm.lib) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/audin/server/CMakeLists.txt b/channels/audin/server/CMakeLists.txt index be2ee52b5..4d4004fb3 100644 --- a/channels/audin/server/CMakeLists.txt +++ b/channels/audin/server/CMakeLists.txt @@ -26,6 +26,4 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/cliprdr/client/CMakeLists.txt b/channels/cliprdr/client/CMakeLists.txt index 867ed7230..c8ca54482 100644 --- a/channels/cliprdr/client/CMakeLists.txt +++ b/channels/cliprdr/client/CMakeLists.txt @@ -27,6 +27,4 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE set(${MODULE_PREFIX}_LIBS freerdp winpr) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/cliprdr/server/CMakeLists.txt b/channels/cliprdr/server/CMakeLists.txt index 5bd32583a..911c7a4ad 100644 --- a/channels/cliprdr/server/CMakeLists.txt +++ b/channels/cliprdr/server/CMakeLists.txt @@ -25,6 +25,4 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/disp/client/CMakeLists.txt b/channels/disp/client/CMakeLists.txt index 61adc34d3..6bed7bfff 100644 --- a/channels/disp/client/CMakeLists.txt +++ b/channels/disp/client/CMakeLists.txt @@ -31,7 +31,6 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/drdynvc/client/CMakeLists.txt b/channels/drdynvc/client/CMakeLists.txt index 0c323c0cc..244d1985f 100644 --- a/channels/drdynvc/client/CMakeLists.txt +++ b/channels/drdynvc/client/CMakeLists.txt @@ -23,6 +23,5 @@ set(${MODULE_PREFIX}_SRCS add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/drdynvc/server/CMakeLists.txt b/channels/drdynvc/server/CMakeLists.txt index d0de5d5d9..fe2bd61c2 100644 --- a/channels/drdynvc/server/CMakeLists.txt +++ b/channels/drdynvc/server/CMakeLists.txt @@ -27,7 +27,5 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/drive/client/CMakeLists.txt b/channels/drive/client/CMakeLists.txt index 64495875f..3d5afae04 100644 --- a/channels/drive/client/CMakeLists.txt +++ b/channels/drive/client/CMakeLists.txt @@ -35,7 +35,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/echo/client/CMakeLists.txt b/channels/echo/client/CMakeLists.txt index d7b69576d..7c15794dc 100644 --- a/channels/echo/client/CMakeLists.txt +++ b/channels/echo/client/CMakeLists.txt @@ -29,7 +29,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/echo/server/CMakeLists.txt b/channels/echo/server/CMakeLists.txt index 3d6b60807..e69b55501 100644 --- a/channels/echo/server/CMakeLists.txt +++ b/channels/echo/server/CMakeLists.txt @@ -26,7 +26,5 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/encomsp/client/CMakeLists.txt b/channels/encomsp/client/CMakeLists.txt index f43bf6258..dd855b830 100644 --- a/channels/encomsp/client/CMakeLists.txt +++ b/channels/encomsp/client/CMakeLists.txt @@ -26,10 +26,4 @@ set(${MODULE_PREFIX}_SRCS add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") - -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/encomsp/server/CMakeLists.txt b/channels/encomsp/server/CMakeLists.txt index f0ea76b1c..10ac0c6d9 100644 --- a/channels/encomsp/server/CMakeLists.txt +++ b/channels/encomsp/server/CMakeLists.txt @@ -31,7 +31,5 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/parallel/client/CMakeLists.txt b/channels/parallel/client/CMakeLists.txt index 8713a3da6..21f4a03d6 100644 --- a/channels/parallel/client/CMakeLists.txt +++ b/channels/parallel/client/CMakeLists.txt @@ -26,7 +26,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} freerdp winpr) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/printer/client/CMakeLists.txt b/channels/printer/client/CMakeLists.txt index be756452a..b433d8a4f 100644 --- a/channels/printer/client/CMakeLists.txt +++ b/channels/printer/client/CMakeLists.txt @@ -48,7 +48,6 @@ endif() target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/rail/client/CMakeLists.txt b/channels/rail/client/CMakeLists.txt index 745ac1689..a4653e08d 100644 --- a/channels/rail/client/CMakeLists.txt +++ b/channels/rail/client/CMakeLists.txt @@ -31,7 +31,5 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpdr/client/CMakeLists.txt b/channels/rdpdr/client/CMakeLists.txt index c672c5238..488c174c2 100644 --- a/channels/rdpdr/client/CMakeLists.txt +++ b/channels/rdpdr/client/CMakeLists.txt @@ -33,7 +33,5 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpdr/server/CMakeLists.txt b/channels/rdpdr/server/CMakeLists.txt index 8da697f6d..63f8a0437 100644 --- a/channels/rdpdr/server/CMakeLists.txt +++ b/channels/rdpdr/server/CMakeLists.txt @@ -27,7 +27,5 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/rdpei/client/CMakeLists.txt b/channels/rdpei/client/CMakeLists.txt index 7cad5201a..723cbc0fc 100644 --- a/channels/rdpei/client/CMakeLists.txt +++ b/channels/rdpei/client/CMakeLists.txt @@ -30,7 +30,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/rdpei/server/CMakeLists.txt b/channels/rdpei/server/CMakeLists.txt index a20c36cec..9f531da0d 100644 --- a/channels/rdpei/server/CMakeLists.txt +++ b/channels/rdpei/server/CMakeLists.txt @@ -33,7 +33,5 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/rdpgfx/client/CMakeLists.txt b/channels/rdpgfx/client/CMakeLists.txt index d657a2f79..1dbf82f80 100644 --- a/channels/rdpgfx/client/CMakeLists.txt +++ b/channels/rdpgfx/client/CMakeLists.txt @@ -33,8 +33,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/rdpsnd/client/CMakeLists.txt b/channels/rdpsnd/client/CMakeLists.txt index ce09b8b17..f2fc1aa16 100644 --- a/channels/rdpsnd/client/CMakeLists.txt +++ b/channels/rdpsnd/client/CMakeLists.txt @@ -27,8 +27,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/rdpsnd/client/alsa/CMakeLists.txt b/channels/rdpsnd/client/alsa/CMakeLists.txt index cdbce489d..761a639d0 100644 --- a/channels/rdpsnd/client/alsa/CMakeLists.txt +++ b/channels/rdpsnd/client/alsa/CMakeLists.txt @@ -33,6 +33,4 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${ALSA_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/ALSA") diff --git a/channels/rdpsnd/client/ios/CMakeLists.txt b/channels/rdpsnd/client/ios/CMakeLists.txt index c2beec711..ae9f9a797 100644 --- a/channels/rdpsnd/client/ios/CMakeLists.txt +++ b/channels/rdpsnd/client/ios/CMakeLists.txt @@ -42,6 +42,4 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/ios") diff --git a/channels/rdpsnd/client/mac/CMakeLists.txt b/channels/rdpsnd/client/mac/CMakeLists.txt index 035d16cb4..449b345a1 100644 --- a/channels/rdpsnd/client/mac/CMakeLists.txt +++ b/channels/rdpsnd/client/mac/CMakeLists.txt @@ -42,6 +42,4 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/Mac") diff --git a/channels/rdpsnd/client/opensles/CMakeLists.txt b/channels/rdpsnd/client/opensles/CMakeLists.txt index 7153eed82..410a4b425 100644 --- a/channels/rdpsnd/client/opensles/CMakeLists.txt +++ b/channels/rdpsnd/client/opensles/CMakeLists.txt @@ -31,5 +31,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N set(${MODULE_PREFIX}_LIBS freerdp ${OPENSLES_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/rdpsnd/client/oss/CMakeLists.txt b/channels/rdpsnd/client/oss/CMakeLists.txt index c5f9618fc..53ae5fa7b 100644 --- a/channels/rdpsnd/client/oss/CMakeLists.txt +++ b/channels/rdpsnd/client/oss/CMakeLists.txt @@ -33,6 +33,4 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${OSS_LIBRARIES}) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/OSS") diff --git a/channels/rdpsnd/client/pulse/CMakeLists.txt b/channels/rdpsnd/client/pulse/CMakeLists.txt index 79095223e..a12d71844 100644 --- a/channels/rdpsnd/client/pulse/CMakeLists.txt +++ b/channels/rdpsnd/client/pulse/CMakeLists.txt @@ -36,6 +36,4 @@ endif() target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/Pulse") diff --git a/channels/rdpsnd/client/winmm/CMakeLists.txt b/channels/rdpsnd/client/winmm/CMakeLists.txt index e1515b9ac..43c7257a3 100644 --- a/channels/rdpsnd/client/winmm/CMakeLists.txt +++ b/channels/rdpsnd/client/winmm/CMakeLists.txt @@ -32,7 +32,6 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/rdpsnd/server/CMakeLists.txt b/channels/rdpsnd/server/CMakeLists.txt index 990275f38..62d57be5e 100644 --- a/channels/rdpsnd/server/CMakeLists.txt +++ b/channels/rdpsnd/server/CMakeLists.txt @@ -27,7 +27,5 @@ add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/remdesk/client/CMakeLists.txt b/channels/remdesk/client/CMakeLists.txt index 744e3ec12..1c289b9d8 100644 --- a/channels/remdesk/client/CMakeLists.txt +++ b/channels/remdesk/client/CMakeLists.txt @@ -27,7 +27,5 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/remdesk/server/CMakeLists.txt b/channels/remdesk/server/CMakeLists.txt index cdcbbabac..dc59a1129 100644 --- a/channels/remdesk/server/CMakeLists.txt +++ b/channels/remdesk/server/CMakeLists.txt @@ -23,13 +23,9 @@ set(${MODULE_PREFIX}_SRCS add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") - - set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server") diff --git a/channels/serial/client/CMakeLists.txt b/channels/serial/client/CMakeLists.txt index 8611755ef..086e1419e 100644 --- a/channels/serial/client/CMakeLists.txt +++ b/channels/serial/client/CMakeLists.txt @@ -26,7 +26,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) diff --git a/channels/server/channels.c b/channels/server/channels.c index cb312c849..84ccf6e15 100644 --- a/channels/server/channels.c +++ b/channels/server/channels.c @@ -47,6 +47,8 @@ #include #include #include +#include +#include void freerdp_channels_dummy() { @@ -70,6 +72,13 @@ void freerdp_channels_dummy() rdpei_server_context_new(NULL); rdpei_server_context_free(NULL); + + remdesk_server_context_new(NULL); + remdesk_server_context_free(NULL); + + encomsp_server_context_new(NULL); + encomsp_server_context_free(NULL); + } /** diff --git a/channels/smartcard/client/CMakeLists.txt b/channels/smartcard/client/CMakeLists.txt index dc25a6c43..1af49ef87 100644 --- a/channels/smartcard/client/CMakeLists.txt +++ b/channels/smartcard/client/CMakeLists.txt @@ -30,7 +30,5 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE target_link_libraries(${MODULE_NAME} winpr freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") diff --git a/channels/tsmf/client/CMakeLists.txt b/channels/tsmf/client/CMakeLists.txt index b13b29187..24866029c 100644 --- a/channels/tsmf/client/CMakeLists.txt +++ b/channels/tsmf/client/CMakeLists.txt @@ -42,8 +42,6 @@ add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE target_link_libraries(${MODULE_NAME} freerdp) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/tsmf/client/alsa/CMakeLists.txt b/channels/tsmf/client/alsa/CMakeLists.txt index 0466de04c..f1d5292dc 100644 --- a/channels/tsmf/client/alsa/CMakeLists.txt +++ b/channels/tsmf/client/alsa/CMakeLists.txt @@ -28,5 +28,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N target_link_libraries(${MODULE_NAME} freerdp ${ALSA_LIBRARIES}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/tsmf/client/ffmpeg/CMakeLists.txt b/channels/tsmf/client/ffmpeg/CMakeLists.txt index 7f9131bc4..e18e0b3e2 100644 --- a/channels/tsmf/client/ffmpeg/CMakeLists.txt +++ b/channels/tsmf/client/ffmpeg/CMakeLists.txt @@ -39,7 +39,6 @@ else() target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) endif() -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/tsmf/client/gstreamer/CMakeLists.txt b/channels/tsmf/client/gstreamer/CMakeLists.txt index 06347ffda..8557f6e09 100644 --- a/channels/tsmf/client/gstreamer/CMakeLists.txt +++ b/channels/tsmf/client/gstreamer/CMakeLists.txt @@ -63,9 +63,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N target_link_libraries(${MODULE_NAME} ${LIBS} freerdp) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) -if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) - install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) -endif() - diff --git a/channels/tsmf/client/oss/CMakeLists.txt b/channels/tsmf/client/oss/CMakeLists.txt index b0d39b6a9..4137f437b 100644 --- a/channels/tsmf/client/oss/CMakeLists.txt +++ b/channels/tsmf/client/oss/CMakeLists.txt @@ -28,5 +28,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N target_link_libraries(${MODULE_NAME} freerdp ${OSS_LIBRARIES}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/tsmf/client/pulse/CMakeLists.txt b/channels/tsmf/client/pulse/CMakeLists.txt index a93854a53..ab8a5ac4b 100644 --- a/channels/tsmf/client/pulse/CMakeLists.txt +++ b/channels/tsmf/client/pulse/CMakeLists.txt @@ -28,5 +28,3 @@ add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_N target_link_libraries(${MODULE_NAME} freerdp) - -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) diff --git a/channels/urbdrc/client/CMakeLists.txt b/channels/urbdrc/client/CMakeLists.txt index 7694c4303..5b2a831c0 100644 --- a/channels/urbdrc/client/CMakeLists.txt +++ b/channels/urbdrc/client/CMakeLists.txt @@ -48,8 +48,6 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/channels/urbdrc/client/libusb/CMakeLists.txt b/channels/urbdrc/client/libusb/CMakeLists.txt index c9db8d65f..84a857d07 100644 --- a/channels/urbdrc/client/libusb/CMakeLists.txt +++ b/channels/urbdrc/client/libusb/CMakeLists.txt @@ -44,8 +44,6 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) -install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH} EXPORT FreeRDPTargets) - if (WITH_DEBUG_SYMBOLS AND MSVC AND NOT STATIC_CHANNELS AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${FREERDP_ADDIN_PATH} COMPONENT symbols) endif() diff --git a/client/.gitignore b/client/.gitignore index e40f517bf..9ad5b74c0 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -9,3 +9,4 @@ !/X11 !/Wayland !/CMakeLists.txt +!*.in diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 37a811db2..1e5c77223 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -83,3 +83,24 @@ if(WITH_CLIENT) endforeach() endif() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp-client.pc.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp-client${FREERDP_VERSION_MAJOR}.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp-client${FREERDP_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") + + export(PACKAGE freerdp-client) + + set(FREERDP_CLIENT_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/FreeRDP-Client${FREERDP_VERSION_MAJOR}") + + configure_package_config_file(FreeRDP-ClientConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfig.cmake + INSTALL_DESTINATION ${FREERDP_CLIENT_CMAKE_INSTALL_DIR} + PATH_VARS FREERDP_INCLUDE_DIR) + + write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfigVersion.cmake + VERSION ${FREERDP_VERSION} COMPATIBILITY SameMajorVersion) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfigVersion.cmake + DESTINATION ${FREERDP_CLIENT_CMAKE_INSTALL_DIR}) + + install(EXPORT FreeRDP-ClientTargets DESTINATION ${FREERDP_CLIENT_CMAKE_INSTALL_DIR}) + +endif() diff --git a/client/FreeRDP-ClientConfig.cmake.in b/client/FreeRDP-ClientConfig.cmake.in new file mode 100644 index 000000000..ba3b8d192 --- /dev/null +++ b/client/FreeRDP-ClientConfig.cmake.in @@ -0,0 +1,10 @@ + +@PACKAGE_INIT@ + +set(FreeRDP_VERSION_MAJOR "@FREERDP_VERSION_MAJOR@") +set(FreeRDP_VERSION_MINOR "@FREERDP_VERSION_MINOR@") +set(FreeRDP_VERSION_REVISION "@FREERDP_VERSION_REVISION@") + +set_and_check(FreeRDP_INCLUDE_DIR "@PACKAGE_FREERDP_INCLUDE_DIR@") + +include("${CMAKE_CURRENT_LIST_DIR}/FreeRDP-ClientTargets.cmake") diff --git a/client/Windows/CMakeLists.txt b/client/Windows/CMakeLists.txt index d2d513f7d..aab5cecf1 100644 --- a/client/Windows/CMakeLists.txt +++ b/client/Windows/CMakeLists.txt @@ -79,7 +79,7 @@ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) if(WITH_CLIENT_INTERFACE) - install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) + install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() diff --git a/client/X11/CMakeLists.txt b/client/X11/CMakeLists.txt index 3c0b1c68f..f65817f89 100644 --- a/client/X11/CMakeLists.txt +++ b/client/X11/CMakeLists.txt @@ -74,7 +74,7 @@ set(${MODULE_PREFIX}_LIBS ${CMAKE_DL_LIBS}) if(WITH_MANPAGES) - find_program( XSLTPROC_EXECUTABLE NAMES xsltproc) + find_program(XSLTPROC_EXECUTABLE NAMES xsltproc) if(DOCBOOKXSL_FOUND AND XSLTPROC_EXECUTABLE) @@ -211,7 +211,7 @@ if(WITH_IPP) endif() if(WITH_CLIENT_INTERFACE) - install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) + install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) add_subdirectory(cli) else() install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) diff --git a/client/common/CMakeLists.txt b/client/common/CMakeLists.txt index 747b2f2ce..5502696d9 100644 --- a/client/common/CMakeLists.txt +++ b/client/common/CMakeLists.txt @@ -67,22 +67,20 @@ if (WITH_LIBRARY_VERSIONING) set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) endif() - -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} - ${FREERDP_CHANNELS_CLIENT_LIBS}) - set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES}) set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) +target_link_libraries(${MODULE_NAME} ${PRIVATE_KEYWORD} ${FREERDP_CHANNELS_CLIENT_LIBS}) if(OPENBSD) - target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} ossaudio) + target_link_libraries(${MODULE_NAME} ${PUBLIC_KEYWORD} ${${MODULE_PREFIX}_LIBS} ossaudio) else() - target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + target_link_libraries(${MODULE_NAME} ${PUBLIC_KEYWORD} ${${MODULE_PREFIX}_LIBS}) endif() -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) + +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDP-ClientTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) diff --git a/client/freerdp-client.pc.in b/client/freerdp-client.pc.in new file mode 100644 index 000000000..5013a5f0a --- /dev/null +++ b/client/freerdp-client.pc.in @@ -0,0 +1,15 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=${prefix}@FREERDP_INCLUDE_DIR@ +libs=-lfreerdp-client + +Name: FreeRDP client +Description: FreeRDP: A Remote Desktop Protocol Implementation +URL: http://www.freerdp.com/ +Version: @FREERDP_VERSION@ +Requires: +Requires.private: @WINPR_PKG_CONFIG_FILENAME@ freerdp@FREERDP_VERSION_MAJOR@ +Libs: -L${libdir} ${libs} +Libs.private: -ldl -lpthread +Cflags: -I${includedir} diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 8995688e3..a020dc534 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -19,18 +19,19 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h) +set(FREERDP_INSTALL_INCLUDE_DIR include/freerdp${FREERDP_VERSION_MAJOR}/freerdp) file(GLOB FREERDP_HEADERS "freerdp/*.h") -install(FILES ${FREERDP_HEADERS} DESTINATION include/freerdp COMPONENT headers) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h DESTINATION include/freerdp COMPONENT headers) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h DESTINATION include/freerdp COMPONENT headers) +install(FILES ${FREERDP_HEADERS} DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers) -install(DIRECTORY freerdp/cache DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/codec DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/crypto DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/gdi DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/locale DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/utils DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/client DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/server DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") -install(DIRECTORY freerdp/channels DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/cache DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/codec DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/crypto DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/gdi DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/locale DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/utils DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/client DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/server DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(DIRECTORY freerdp/channels DESTINATION ${FREERDP_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt index 675d6b663..41159a56c 100644 --- a/libfreerdp/CMakeLists.txt +++ b/libfreerdp/CMakeLists.txt @@ -313,3 +313,27 @@ if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/libfreerdp") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp${FREERDP_VERSION_MAJOR}.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp${FREERDP_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + +## cmake project +if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") + + export(PACKAGE freerdp) + + set(FREERDP_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/FreeRDP${FREERDP_VERSION_MAJOR}") + + configure_package_config_file(FreeRDPConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfig.cmake + INSTALL_DESTINATION ${FREERDP_CMAKE_INSTALL_DIR} + PATH_VARS FREERDP_INCLUDE_DIR) + + write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfigVersion.cmake + VERSION ${FREERDP_VERSION} COMPATIBILITY SameMajorVersion) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FreeRDPConfigVersion.cmake + DESTINATION ${FREERDP_CMAKE_INSTALL_DIR}) + + install(EXPORT FreeRDPTargets DESTINATION ${FREERDP_CMAKE_INSTALL_DIR}) + +endif() diff --git a/FreeRDPConfig.cmake.in b/libfreerdp/FreeRDPConfig.cmake.in similarity index 100% rename from FreeRDPConfig.cmake.in rename to libfreerdp/FreeRDPConfig.cmake.in diff --git a/freerdp.pc.in b/libfreerdp/freerdp.pc.in similarity index 68% rename from freerdp.pc.in rename to libfreerdp/freerdp.pc.in index ca0d63cbb..456b284fd 100644 --- a/freerdp.pc.in +++ b/libfreerdp/freerdp.pc.in @@ -1,15 +1,15 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_PREFIX@/include -libs=@FREERDP_PC_LIBS@ +includedir=${prefix}/@FREERDP_INCLUDE_DIR@ +libs=-lfreerdp Name: FreeRDP Description: FreeRDP: A Remote Desktop Protocol Implementation URL: http://www.freerdp.com/ -Version: @FREERDP_VERSION_FULL@ +Version: @FREERDP_VERSION@ Requires: -Requires.private: winpr zlib libssl +Requires.private: @WINPR_PKG_CONFIG_FILENAME@ libssl Libs: -L${libdir} ${libs} Libs.private: -ldl -lpthread Cflags: -I${includedir} diff --git a/rdtk/CMakeLists.txt b/rdtk/CMakeLists.txt index 73c64facd..287f210a0 100644 --- a/rdtk/CMakeLists.txt +++ b/rdtk/CMakeLists.txt @@ -41,13 +41,12 @@ include(GNUInstallDirsWrapper) include(CMakePackageConfigHelpers) # Soname versioning -set(RDTK_VERSION_MAJOR "1") -set(RDTK_VERSION_MINOR "1") -set(RDTK_VERSION_REVISION "0") +set(RDTK_VERSION_MAJOR "0") +set(RDTK_VERSION_MINOR "0") +set(RDTK_VERSION_REVISION "1") set(RDTK_API_VERSION "${RDTK_VERSION_MAJOR}.${RDTK_VERSION_MINOR}") set(RDTK_VERSION "${RDTK_API_VERSION}.${RDTK_VERSION_REVISION}") set(RDTK_VERSION_FULL "${RDTK_VERSION}") -set(RDTK_VERSION_FULL ${RDTK_VERSION_FULL} PARENT_SCOPE) # Default to release build type if(NOT CMAKE_BUILD_TYPE) @@ -74,14 +73,15 @@ if(WITH_SAMPLE) endif() # Exporting +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rdtk.pc.in ${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") - export(PACKAGE rdtk) - set(RDTK_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/RdTk") + set(RDTK_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/RdTk${RDTK_VERSION_MAJOR}") - set(RDTK_INCLUDE_DIR "include") + set(RDTK_INCLUDE_DIR "include/rdtk${RDTK_VERSION_MAJOR}") configure_package_config_file(RdTkConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/RdTkConfig.cmake INSTALL_DESTINATION ${RDTK_CMAKE_INSTALL_DIR} PATH_VARS RDTK_INCLUDE_DIR) diff --git a/rdtk/include/CMakeLists.txt b/rdtk/include/CMakeLists.txt index d35c350de..a363933c0 100644 --- a/rdtk/include/CMakeLists.txt +++ b/rdtk/include/CMakeLists.txt @@ -16,5 +16,5 @@ # limitations under the License. file(GLOB RDTK_HEADERS "rdtk/*.h") -install(FILES ${RDTK_HEADERS} DESTINATION include/rdtk COMPONENT headers) +install(FILES ${RDTK_HEADERS} DESTINATION include/rdtk${RDTK_VERSION_MAJOR}/rdtk COMPONENT headers) diff --git a/rdtk/rdtk.pc.in b/rdtk/rdtk.pc.in new file mode 100644 index 000000000..323916eab --- /dev/null +++ b/rdtk/rdtk.pc.in @@ -0,0 +1,15 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=${prefix}/@RDTK_INCLUDE_DIR@ +libs=-lrdtk + +Name: Remote Desktop Tool Kit +Description: FreeRDP RDTK: A toolkit implementation for RDP +URL: http://www.freerdp.com/ +Version: @RDTK_VERSION_FULL@ +Requires: +Requires.private: @WINPR_PKG_CONFIG_FILENAME@ freerdp@FREERDP_VERSION_MAJOR@ +Libs: -L${libdir} ${libs} +Libs.private: -ldl -lpthread +Cflags: -I${includedir} diff --git a/server/.gitignore b/server/.gitignore index ef902f781..5685908a6 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -6,3 +6,4 @@ !/X11 !/shadow !/CmakeLists.txt +!*.in diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index ee9458e4b..24f7bb182 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -64,3 +64,25 @@ foreach(FREERDP_SERVER ${FREERDP_EXTRA_SERVERS}) add_subdirectory(${FREERDP_SERVER}) endforeach() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp-server.pc.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp-server${FREERDP_VERSION_MAJOR}.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp-server${FREERDP_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + +if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") + + export(PACKAGE freerdp-server) + + set(FREERDP_SERVER_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/FreeRDP-Server${FREERDP_VERSION_MAJOR}") + + configure_package_config_file(FreeRDP-ServerConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ServerConfig.cmake + INSTALL_DESTINATION ${FREERDP_SERVER_CMAKE_INSTALL_DIR} + PATH_VARS FREERDP_INCLUDE_DIR) + + write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ServerConfigVersion.cmake + VERSION ${FREERDP_VERSION} COMPATIBILITY SameMajorVersion) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ServerConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ServerConfigVersion.cmake + DESTINATION ${FREERDP_SERVER_CMAKE_INSTALL_DIR}) + + install(EXPORT FreeRDP-ServerTargets DESTINATION ${FREERDP_SERVER_CMAKE_INSTALL_DIR}) + +endif() diff --git a/server/FreeRDP-ServerConfig.cmake.in b/server/FreeRDP-ServerConfig.cmake.in new file mode 100644 index 000000000..2f2788bd2 --- /dev/null +++ b/server/FreeRDP-ServerConfig.cmake.in @@ -0,0 +1,10 @@ + +@PACKAGE_INIT@ + +set(FreeRDP_VERSION_MAJOR "@FREERDP_VERSION_MAJOR@") +set(FreeRDP_VERSION_MINOR "@FREERDP_VERSION_MINOR@") +set(FreeRDP_VERSION_REVISION "@FREERDP_VERSION_REVISION@") + +set_and_check(FreeRDP_INCLUDE_DIR "@PACKAGE_FREERDP_INCLUDE_DIR@") + +include("${CMAKE_CURRENT_LIST_DIR}/FreeRDP-ServerTargets.cmake") diff --git a/server/common/CMakeLists.txt b/server/common/CMakeLists.txt index 1f01d0076..d5b990610 100644 --- a/server/common/CMakeLists.txt +++ b/server/common/CMakeLists.txt @@ -18,6 +18,13 @@ set(MODULE_NAME "freerdp-server") set(MODULE_PREFIX "FREERDP_SERVER") +# Policy CMP0022: INTERFACE_LINK_LIBRARIES defines the link +# interface. Run "cmake --help-policy CMP0022" for policy details. Use the +# cmake_policy command to set the policy and suppress this warning. +if(POLICY CMP0022) + cmake_policy(SET CMP0022 NEW) +endif() + set(${MODULE_PREFIX}_SRCS server.c) @@ -29,10 +36,6 @@ if(MSVC) set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def) endif() -foreach(FREERDP_CHANNELS_SERVER_SRC ${FREERDP_CHANNELS_SERVER_SRCS}) - set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} - "${FREERDP_CHANNELS_SERVER_SRC}") -endforeach() # On windows create dll version information. # Vendor, product and year are already set in top level CMakeLists.txt @@ -56,13 +59,10 @@ if (WITH_LIBRARY_VERSIONING) set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) endif() +target_link_libraries(${MODULE_NAME} ${PRIVATE_KEYWORD} ${FREERDP_CHANNELS_SERVER_LIBS}) +target_link_libraries(${MODULE_NAME} ${PUBLIC_KEYWORD} winpr freerdp) -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} - ${FREERDP_CHANNELS_SERVER_LIBS}) - -target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDP-ServerTargets) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) endif() diff --git a/server/freerdp-server.pc.in b/server/freerdp-server.pc.in new file mode 100644 index 000000000..f9ef4c345 --- /dev/null +++ b/server/freerdp-server.pc.in @@ -0,0 +1,15 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=${prefix}/@FREERDP_INCLUDE_DIR@ +libs=-lfreerdp-server + +Name: FreeRDP server +Description: FreeRDP: A Remote Desktop Protocol Implementation +URL: http://www.freerdp.com/ +Version: @FREERDP_VERSION@ +Requires: +Requires.private: @WINPR_PKG_CONFIG_FILENAME@ freerdp@FREERDP_VERSION_MAJOR@ +Libs: -L${libdir} ${libs} +Libs.private: -ldl -lpthread +Cflags: -I${includedir} diff --git a/server/shadow/CMakeLists.txt b/server/shadow/CMakeLists.txt index ce5ac7f79..421d4bd82 100644 --- a/server/shadow/CMakeLists.txt +++ b/server/shadow/CMakeLists.txt @@ -73,8 +73,6 @@ add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) list(APPEND ${MODULE_PREFIX}_LIBS freerdp) list(APPEND ${MODULE_PREFIX}_LIBS freerdp-server) -list(APPEND ${MODULE_PREFIX}_LIBS freerdp-client) - list(APPEND ${MODULE_PREFIX}_LIBS winpr) list(APPEND ${MODULE_PREFIX}_LIBS winpr-makecert-tool) diff --git a/third-party/.gitignore b/third-party/.gitignore index efc4279f7..bbf8a76fc 100644 --- a/third-party/.gitignore +++ b/third-party/.gitignore @@ -1,4 +1,5 @@ * **/* !CMakeLists.txt +!*.pc.in diff --git a/winpr/.gitignore b/winpr/.gitignore index 68936e807..c2fee8dd4 100644 --- a/winpr/.gitignore +++ b/winpr/.gitignore @@ -1,3 +1,2 @@ tools/hash/winpr-hash tools/reg/winpr-reg - diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index 1021d164e..96962f215 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -51,11 +51,12 @@ include(CMakePackageConfigHelpers) set(WINPR_VERSION_MAJOR "1") set(WINPR_VERSION_MINOR "1") set(WINPR_VERSION_REVISION "0") -set(WINPR_VERSION "${WINPR_VERSION_MAJOR}.${WINPR_VERSION_MINOR}") -set(WINPR_VERSION_FULL "${WINPR_VERSION}.${WINPR_VERSION_REVISION}") +set(WINPR_VERSION "${WINPR_VERSION_MAJOR}.${WINPR_VERSION_MINOR}.${WINPR_VERSION_REVISION}") +set(WINPR_VERSION_FULL "${WINPR_VERSION}") if(FREERDP_BUILD) set(WINPR_VERSION_FULL ${WINPR_VERSION_FULL} PARENT_SCOPE) + set(WINPR_VERSION_FULL ${WINPR_VERSION} PARENT_SCOPE) else() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) @@ -161,9 +162,9 @@ if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") export(PACKAGE winpr) - set(WINPR_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/WinPR") + set(WINPR_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/WinPR${WINPR_VERSION_MAJOR}") - set(WINPR_INCLUDE_DIR "include") + set(WINPR_INCLUDE_DIR "include/winpr${WINPR_VERSION_MAJOR}") configure_package_config_file(WinPRConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/WinPRConfig.cmake INSTALL_DESTINATION ${WINPR_CMAKE_INSTALL_DIR} @@ -179,3 +180,6 @@ if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") endif() +set(WINPR_PKG_CONFIG_FILENAME winpr${WINPR_VERSION_MAJOR} PARENT_SCOPE) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr.pc.in ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/winpr/include/CMakeLists.txt b/winpr/include/CMakeLists.txt index 1121008ad..928f88f18 100644 --- a/winpr/include/CMakeLists.txt +++ b/winpr/include/CMakeLists.txt @@ -17,7 +17,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/version.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr/wtypes.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/wtypes.h) +set(WINPR_INSTALL_INCLUDE_DIR include/winpr${WINPR_VERSION_MAJOR}/winpr) file(GLOB WINPR_HEADERS "winpr/*.h") -install(FILES ${WINPR_HEADERS} DESTINATION include/winpr COMPONENT headers) -install(DIRECTORY winpr/tools DESTINATION include/winpr COMPONENT headers FILES_MATCHING PATTERN "*.h") +install(FILES ${WINPR_HEADERS} DESTINATION ${WINPR_INSTALL_INCLUDE_DIR} COMPONENT headers) +install(DIRECTORY winpr/tools DESTINATION ${WINPR_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") diff --git a/winpr.pc.in b/winpr/winpr.pc.in similarity index 74% rename from winpr.pc.in rename to winpr/winpr.pc.in index 5be9979f6..58dc08afa 100644 --- a/winpr.pc.in +++ b/winpr/winpr.pc.in @@ -1,14 +1,14 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_PREFIX@/include -libs=@WINPR_PC_LIBS@ +includedir=${libdir}/@WINPR_INCLUDE_DIR@ +libs=-lwinpr Name: WinPR Description: WinPR: Windows Portable Runtime URL: http://www.freerdp.com/ -Version: @WINPR_VERSION_FULL@ -Requires: +Version: @WINPR_VERSION@ +Requires: Requires.private: zlib libssl Libs: -L${libdir} ${libs} Libs.private: -ldl -lrt -lm -lpthread From 7c03db342ca5602e2a4e58255077320eff6e9c35 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 11 Jan 2016 16:18:40 +0100 Subject: [PATCH 145/220] add parameter buildconfig Extend winpr and client/common to support a new option "/buildconfig". When used build the following build specific information is print: * cmake options * cflags * compiler * target architecture * cmake build type --- .gitignore | 1 + CMakeLists.txt | 10 ++++++++++ buildflags.h.in | 11 +++++++++++ client/common/cmdline.c | 18 ++++++++++++++++++ winpr/include/winpr/cmdline.h | 2 ++ winpr/libwinpr/utils/cmdline.c | 2 ++ 6 files changed, 44 insertions(+) create mode 100644 buildflags.h.in diff --git a/.gitignore b/.gitignore index 6853f6825..34ff16e31 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ LICENSE.txt *ConfigVersion.cmake include/freerdp/version.h include/freerdp/build-config.h +buildflags.h *.a.objlist.cmake *.a.objlist diff --git a/CMakeLists.txt b/CMakeLists.txt index 68ff44e06..d15c6bf88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -819,3 +819,13 @@ endif() #message("VENDOR: ${VENDOR} CLIENT_VENDOR_PATH: ${CLIENT_VENDOR_PATH} CMAKE_CPACK_INCLUDE_FILE: ${CMAKE_CPACK_INCLUDE_FILE}") include(${CMAKE_CPACK_INCLUDE_FILE}) + +set(FREERDP_BUILD_CONFIG_LIST "") +GET_CMAKE_PROPERTY(res VARIABLES) +FOREACH(var ${res}) + IF (var MATCHES "^WITH_*|^BUILD_TESTING|^STATIC_CHANNELS|^HAVE_*") + LIST(APPEND FREERDP_BUILD_CONFIG_LIST "${var}=${${var}}") + ENDIF() +ENDFOREACH() +string(REPLACE ";" " " FREERDP_BUILD_CONFIG "${FREERDP_BUILD_CONFIG_LIST}") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/buildflags.h.in ${CMAKE_CURRENT_BINARY_DIR}/buildflags.h) diff --git a/buildflags.h.in b/buildflags.h.in new file mode 100644 index 000000000..0b8b31092 --- /dev/null +++ b/buildflags.h.in @@ -0,0 +1,11 @@ +#ifndef _FREERDP_BUILD_FLAGS_H +#define _FREERDP_BUILD_FLAGS_H + +#define CFLAGS "${CMAKE_C_FLAGS}" +#define COMPILER_ID "${CMAKE_C_COMPILER_ID}" +#define COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION}" +#define TARGET_ARCH "${TARGET_ARCH}" +#define BUILD_CONFIG "${FREERDP_BUILD_CONFIG}" +#define BUILD_TYPE "${CMAKE_BUILD_TYPE}" + +#endif /*_FREERDP_BUILD_FLAGS_H */ diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 91f362ddd..517ee0e06 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -21,6 +21,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "buildflags.h" #include @@ -171,6 +172,7 @@ static COMMAND_LINE_ARGUMENT_A args[] = { "assistance", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "Remote assistance password" }, { "encryption-methods", COMMAND_LINE_VALUE_REQUIRED, "<40,56,128,FIPS>", NULL, NULL, -1, NULL, "RDP standard security encryption methods" }, { "from-stdin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Read credentials from stdin, do not use defaults." }, + { "buildconfig", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_BUILDCONFIG, NULL, NULL, NULL, -1, NULL, "print the build configuration" }, { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; @@ -180,6 +182,16 @@ int freerdp_client_print_version() return 1; } +int freerdp_client_print_buildconfig() +{ + printf("Build configuration: %s\n", BUILD_CONFIG); + printf("Build type: %s\n", BUILD_TYPE); + printf("CFLAGS: %s\n", CFLAGS); + printf("Compiler: %s, %s\n", COMPILER_ID, COMPILER_VERSION); + printf("Target architecture: %s\n", TARGET_ARCH); + return 1; +} + int freerdp_client_print_command_line_help(int argc, char** argv) { char* str; @@ -1352,6 +1364,12 @@ int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int freerdp_client_print_version(); return COMMAND_LINE_STATUS_PRINT_VERSION; } + if (status == COMMAND_LINE_STATUS_PRINT_BUILDCONFIG) + { + freerdp_client_print_version(); + freerdp_client_print_buildconfig(); + return COMMAND_LINE_STATUS_PRINT_BUILDCONFIG; + } else if (status == COMMAND_LINE_STATUS_PRINT) { arg = CommandLineFindArgumentA(args, "kbd-list"); diff --git a/winpr/include/winpr/cmdline.h b/winpr/include/winpr/cmdline.h index ef41a6be8..b843ee7eb 100644 --- a/winpr/include/winpr/cmdline.h +++ b/winpr/include/winpr/cmdline.h @@ -39,6 +39,7 @@ #define COMMAND_LINE_PRINT 0x00000200 #define COMMAND_LINE_PRINT_HELP 0x00000400 #define COMMAND_LINE_PRINT_VERSION 0x00000800 +#define COMMAND_LINE_PRINT_BUILDCONFIG 0x00001000 /* Command-Line Argument Output Flags */ @@ -78,6 +79,7 @@ #define COMMAND_LINE_STATUS_PRINT -2001 #define COMMAND_LINE_STATUS_PRINT_HELP -2002 #define COMMAND_LINE_STATUS_PRINT_VERSION -2003 +#define COMMAND_LINE_STATUS_PRINT_BUILDCONFIG -2004 /* Command-Line Macros */ diff --git a/winpr/libwinpr/utils/cmdline.c b/winpr/libwinpr/utils/cmdline.c index e55b738f1..cc22d5de7 100644 --- a/winpr/libwinpr/utils/cmdline.c +++ b/winpr/libwinpr/utils/cmdline.c @@ -363,6 +363,8 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A* return COMMAND_LINE_STATUS_PRINT_HELP; else if (options[j].Flags & COMMAND_LINE_PRINT_VERSION) return COMMAND_LINE_STATUS_PRINT_VERSION; + else if (options[j].Flags & COMMAND_LINE_PRINT_BUILDCONFIG) + return COMMAND_LINE_STATUS_PRINT_BUILDCONFIG; } if (!found && (flags & COMMAND_LINE_IGN_UNKNOWN_KEYWORD) == 0) From aa80f63b4ab19101cbdc376f7e0613ed410fee11 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Tue, 12 Jan 2016 17:43:14 +0100 Subject: [PATCH 146/220] tls: enable tls 1+ Currently TLS version 1.0 is used implicitly by using the TLSv1_method. To be able to also use TLS 1.1 and later use SSLv23_client_method instead. To make sure SSLv2 or SSLv3 isn't used disable them. --- libfreerdp/crypto/tls.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 63ff9b4a8..90de48b2f 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -798,7 +798,13 @@ int tls_connect(rdpTls* tls, BIO* underlying) */ options |= SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS; - if (!tls_prepare(tls, underlying, TLSv1_client_method(), options, TRUE)) + /** + * disable SSLv2 and SSLv3 + */ + options |= SSL_OP_NO_SSLv2; + options |= SSL_OP_NO_SSLv3; + + if (!tls_prepare(tls, underlying, SSLv23_client_method(), options, TRUE)) return FALSE; return tls_do_handshake(tls, TRUE); From 6ca564479e967c0807d73334eec9e69d23714e30 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 13 Jan 2016 14:14:04 +0100 Subject: [PATCH 147/220] pkg: fix .deb based packages Update the deb based packages to the latest changes --- packaging/deb/freerdp-nightly/freerdp-nightly-dev.install | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/deb/freerdp-nightly/freerdp-nightly-dev.install b/packaging/deb/freerdp-nightly/freerdp-nightly-dev.install index 99ce27cf4..8d14f4c2e 100644 --- a/packaging/deb/freerdp-nightly/freerdp-nightly-dev.install +++ b/packaging/deb/freerdp-nightly/freerdp-nightly-dev.install @@ -1,6 +1,5 @@ opt/freerdp-nightly/lib/*.a opt/freerdp-nightly/lib/*.so -opt/freerdp-nightly/lib/freerdp/*.a opt/freerdp-nightly/lib/pkgconfig opt/freerdp-nightly/lib/cmake opt/freerdp-nightly/include From bedb4a2d64b7fa5e49dac44af079f38f6f182652 Mon Sep 17 00:00:00 2001 From: abma Date: Wed, 13 Jan 2016 23:05:32 +0100 Subject: [PATCH 148/220] fix #3051: fullscreen switching with CTRL+ALT+ENTER doesn't work any more --- client/X11/xf_keyboard.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 243e920d2..02af8c30d 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -154,7 +154,7 @@ void xf_keyboard_key_press(xfContext* xfc, BYTE keycode, KeySym keysym) if (keycode < 8) return; - xfc->KeyboardState[keycode] = keysym; + xfc->KeyboardState[keycode] = TRUE; if (xf_keyboard_handle_special_keys(xfc, keysym)) return; @@ -167,7 +167,7 @@ void xf_keyboard_key_release(xfContext* xfc, BYTE keycode) if (keycode < 8) return; - xfc->KeyboardState[keycode] = NoSymbol; + xfc->KeyboardState[keycode] = FALSE; xf_keyboard_send_key(xfc, FALSE, keycode); } @@ -179,7 +179,7 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) for (keycode = 0; keycode < ARRAYSIZE(xfc->KeyboardState); keycode++) { - if (xfc->KeyboardState[keycode] != NoSymbol) + if (!xfc->KeyboardState[keycode]) { rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(keycode); @@ -189,7 +189,7 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) freerdp_input_send_keyboard_event_ex(xfc->instance->input, FALSE, RDP_SCANCODE_TAB); freerdp_input_send_keyboard_event_ex(xfc->instance->input, FALSE, rdp_scancode); - xfc->KeyboardState[keycode] = NoSymbol; + xfc->KeyboardState[keycode] = FALSE; } } } @@ -197,7 +197,7 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) BOOL xf_keyboard_key_pressed(xfContext* xfc, KeySym keysym) { KeyCode keycode = XKeysymToKeycode(xfc->display, keysym); - return (xfc->KeyboardState[keycode] == keysym); + return xfc->KeyboardState[keycode]; } void xf_keyboard_send_key(xfContext* xfc, BOOL down, BYTE keycode) From 3232be51b08d92cb0935ab5ec0e9e41800091432 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 13 Jan 2016 17:37:19 +0100 Subject: [PATCH 149/220] Use major version only for SOVERSION For 2.0+ major will be increased if ABI/API isn't compatible anymore. --- CMakeLists.txt | 4 ++-- rdtk/CMakeLists.txt | 4 ++-- winpr/CMakeLists.txt | 7 +++++-- winpr/libwinpr/CMakeLists.txt | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e2f908d7..7b7cd6bc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,8 +72,8 @@ set(FREERDP_VERSION_MAJOR "2") set(FREERDP_VERSION_MINOR "0") set(FREERDP_VERSION_REVISION "0") set(FREERDP_VERSION_SUFFIX "dev") -set(FREERDP_API_VERSION "${FREERDP_VERSION_MAJOR}.${FREERDP_VERSION_MINOR}") -set(FREERDP_VERSION "${FREERDP_API_VERSION}.${FREERDP_VERSION_REVISION}") +set(FREERDP_API_VERSION "${FREERDP_VERSION_MAJOR}") +set(FREERDP_VERSION "${FREERDP_VERSION_MAJOR}.${FREERDP_VERSION_MINOR}.${FREERDP_VERSION_REVISION}") if (FREERDP_VERSION_SUFFIX) set(FREERDP_VERSION_FULL "${FREERDP_VERSION}-${FREERDP_VERSION_SUFFIX}") else() diff --git a/rdtk/CMakeLists.txt b/rdtk/CMakeLists.txt index 287f210a0..6faea306c 100644 --- a/rdtk/CMakeLists.txt +++ b/rdtk/CMakeLists.txt @@ -44,8 +44,8 @@ include(CMakePackageConfigHelpers) set(RDTK_VERSION_MAJOR "0") set(RDTK_VERSION_MINOR "0") set(RDTK_VERSION_REVISION "1") -set(RDTK_API_VERSION "${RDTK_VERSION_MAJOR}.${RDTK_VERSION_MINOR}") -set(RDTK_VERSION "${RDTK_API_VERSION}.${RDTK_VERSION_REVISION}") +set(RDTK_API_VERSION "${RDTK_VERSION_MAJOR}") +set(RDTK_VERSION "${RDTK_VERSION_MAJOR}.${RDTK_VERSION_MINOR}.${RDTK_VERSION_REVISION}") set(RDTK_VERSION_FULL "${RDTK_VERSION}") # Default to release build type diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index 96962f215..c071b3b26 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -53,10 +53,11 @@ set(WINPR_VERSION_MINOR "1") set(WINPR_VERSION_REVISION "0") set(WINPR_VERSION "${WINPR_VERSION_MAJOR}.${WINPR_VERSION_MINOR}.${WINPR_VERSION_REVISION}") set(WINPR_VERSION_FULL "${WINPR_VERSION}") +set(WINPR_API_VERSION "${WINPR_VERSION_MAJOR}") if(FREERDP_BUILD) set(WINPR_VERSION_FULL ${WINPR_VERSION_FULL} PARENT_SCOPE) - set(WINPR_VERSION_FULL ${WINPR_VERSION} PARENT_SCOPE) + set(WINPR_VERSION ${WINPR_VERSION} PARENT_SCOPE) else() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) @@ -180,6 +181,8 @@ if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") endif() -set(WINPR_PKG_CONFIG_FILENAME winpr${WINPR_VERSION_MAJOR} PARENT_SCOPE) +if(FREERDP_BUILD) + set(WINPR_PKG_CONFIG_FILENAME winpr${WINPR_VERSION_MAJOR} PARENT_SCOPE) +endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr.pc.in ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt index 65f9af0ec..3ea073ce9 100644 --- a/winpr/libwinpr/CMakeLists.txt +++ b/winpr/libwinpr/CMakeLists.txt @@ -114,7 +114,7 @@ endif() add_library(${MODULE_NAME} ${WINPR_SRCS}) set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C) if (WITH_LIBRARY_VERSIONING) - set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SOVERSION ${WINPR_VERSION}) + set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION} SOVERSION ${WINPR_API_VERSION}) endif() add_definitions(${WINPR_DEFINITIONS}) From ba286684c488cfd174c3c0f8b824fc3372189061 Mon Sep 17 00:00:00 2001 From: abma Date: Fri, 15 Jan 2016 01:59:08 +0100 Subject: [PATCH 150/220] fix keyboard release (thanks hardening!) --- client/X11/xf_keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 02af8c30d..3e11b9545 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -179,7 +179,7 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) for (keycode = 0; keycode < ARRAYSIZE(xfc->KeyboardState); keycode++) { - if (!xfc->KeyboardState[keycode]) + if (xfc->KeyboardState[keycode]) { rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(keycode); From a0d6a1f77f4e2a00fff9c071a8c10fda9197ca21 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 14 Jan 2016 15:36:34 +0100 Subject: [PATCH 151/220] Fixed memory leak. --- libfreerdp/gdi/gfx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index c5cdd7625..5d8ba5944 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -717,7 +717,10 @@ UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* surface->codecs = codecs_new(gdi->context); if (!surface->codecs) + { + free (surface); return CHANNEL_RC_NO_MEMORY; + } surface->surfaceId = createSurface->surfaceId; surface->width = (UINT32) createSurface->width; From e7c8ea4db9f660beec0c7a4b080f45d53487198a Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 14 Jan 2016 15:42:20 +0100 Subject: [PATCH 152/220] Fixed memory leak. --- client/X11/xf_gfx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 41cee3429..a2a8f6115 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -709,7 +709,10 @@ UINT xf_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* c surface->codecs = codecs_new((rdpContext*) xfc); if (!surface->codecs) + { + free (surface); return CHANNEL_RC_NO_MEMORY; + } surface->surfaceId = createSurface->surfaceId; surface->width = (UINT32) createSurface->width; From aa90673008af9fc714d997e56ff5f0fc38eaa47a Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 14 Jan 2016 15:55:25 +0100 Subject: [PATCH 153/220] Fixed memory leak on cleanup. --- channels/rdpdr/client/rdpdr_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 24f228e12..30bd2681d 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -413,6 +413,8 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr) dev_array[size].path = word; dev_array[size++].to_add = TRUE; } + else + free (word); } free(line); } @@ -502,7 +504,7 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr) cleanup: for (i = 0; i < size; i++) - free (dev_array[size].path); + free (dev_array[i].path); return error ? error : rdpdr_send_device_list_announce_request(rdpdr, TRUE); } From 9b160d4570c1409bd929d9d3f151069be203de9d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 14 Jan 2016 16:00:31 +0100 Subject: [PATCH 154/220] Fixed uninitialized value. --- winpr/libwinpr/file/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 066a76e16..27332e289 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -424,7 +424,7 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw WINPR_FILE* pFile; BOOL create; const char* mode = FileGetMode(dwDesiredAccess, dwCreationDisposition, &create); - int lock; + int lock = 0; FILE* fp = NULL; pFile = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE)); From d2ab27626a59a7f2287de184e0c037fa7b2829e6 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 15 Jan 2016 10:16:08 +0100 Subject: [PATCH 155/220] Fix memory leak in lodepng_zlib_compress --- winpr/libwinpr/utils/lodepng/lodepng.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winpr/libwinpr/utils/lodepng/lodepng.c b/winpr/libwinpr/utils/lodepng/lodepng.c index a970f0078..61f5ce384 100644 --- a/winpr/libwinpr/utils/lodepng/lodepng.c +++ b/winpr/libwinpr/utils/lodepng/lodepng.c @@ -2208,6 +2208,12 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig *out = outv.data; *outsize = outv.size; } + else + { + *out = NULL; + *outsize = 0; + ucvector_cleanup(&outv); + } return error; } From ede0da3280cbbfcb3d98ea9977393502230c4159 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 15 Jan 2016 13:23:45 +0100 Subject: [PATCH 156/220] build: fix a problem with cmake version 2.8.11 Starting with cmake 2.8.10 FreeRDP exports a cmake find module. With 2.8.12 the PRIVATE/PUBLIC keywords were introduced in cmake. When building with 2.8.11 it is not possible to mark link dependencies as private and therefore they need to be exported. --- channels/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/channels/CMakeLists.txt b/channels/CMakeLists.txt index 548a0057b..a39569758 100644 --- a/channels/CMakeLists.txt +++ b/channels/CMakeLists.txt @@ -155,9 +155,7 @@ macro(add_channel_client_subsystem _channel_prefix _channel_name _subsystem _typ endmacro(add_channel_client_subsystem) macro(channel_install _targets _destination _export_target) - if (NOT STATIC_CHANNELS OR ${CMAKE_VERSION} VERSION_LESS 2.8.12) install(TARGETS ${_targets} DESTINATION ${_destination} EXPORT ${_export_target}) - endif() endmacro(channel_install) macro(server_channel_install _targets _destination) @@ -195,6 +193,9 @@ macro(add_channel_client_library _module_prefix _module_name _channel_name _dyna set(${_module_prefix}_CHANNEL ${_channel_name} PARENT_SCOPE) set(${_module_prefix}_ENTRY ${_entry} PARENT_SCOPE) add_library(${_module_name} STATIC ${${_module_prefix}_SRCS}) + if (${CMAKE_VERSION} VERSION_LESS 2.8.12) + client_channel_install(${_module_name} ${FREERDP_ADDIN_PATH}) + endif() endif() endmacro(add_channel_client_library) @@ -224,6 +225,9 @@ macro(add_channel_client_subsystem_library _module_prefix _module_name _channel_ set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE) set(${_module_prefix}_TYPE ${_type} PARENT_SCOPE) add_library(${_module_name} STATIC ${${_module_prefix}_SRCS}) + if (${CMAKE_VERSION} VERSION_LESS 2.8.12) + client_channel_install(${_module_name} ${FREERDP_ADDIN_PATH}) + endif() endif() endmacro(add_channel_client_subsystem_library) @@ -253,6 +257,9 @@ macro(add_channel_server_library _module_prefix _module_name _channel_name _dyna set(${_module_prefix}_CHANNEL ${_channel_name} PARENT_SCOPE) set(${_module_prefix}_ENTRY ${_entry} PARENT_SCOPE) add_library(${_module_name} STATIC ${${_module_prefix}_SRCS}) + if (${CMAKE_VERSION} VERSION_LESS 2.8.12) + server_channel_install(${_module_name} ${FREERDP_ADDIN_PATH}) + endif() endif() endmacro(add_channel_server_library) From 123cd523e06b54349d5a62bf82d69c08ca947e7d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 18 Jan 2016 09:18:42 +0100 Subject: [PATCH 157/220] Fixed SRCCOPY, using memmove now. memcpy is not defined, if source and destination overlap. --- libfreerdp/gdi/16bpp.c | 2 +- libfreerdp/gdi/8bpp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/gdi/16bpp.c b/libfreerdp/gdi/16bpp.c index e292d7c47..858056aee 100644 --- a/libfreerdp/gdi/16bpp.c +++ b/libfreerdp/gdi/16bpp.c @@ -160,7 +160,7 @@ static BOOL BitBlt_SRCCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); if (srcp != 0 && dstp != 0) - memcpy(dstp, srcp, nWidth * hdcDest->bytesPerPixel); + memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); } return TRUE; diff --git a/libfreerdp/gdi/8bpp.c b/libfreerdp/gdi/8bpp.c index 1303bbccb..1f90b60c4 100644 --- a/libfreerdp/gdi/8bpp.c +++ b/libfreerdp/gdi/8bpp.c @@ -105,7 +105,7 @@ static BOOL BitBlt_SRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); if (srcp != 0 && dstp != 0) - memcpy(dstp, srcp, nWidth * hdcDest->bytesPerPixel); + memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); } return TRUE; From 93f3c060d2faec4c5057ad83ea4e1dea5139f2db Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 18 Jan 2016 09:32:34 +0100 Subject: [PATCH 158/220] Fixed memory overlap check. --- libfreerdp/gdi/region.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/gdi/region.c b/libfreerdp/gdi/region.c index 888a8483f..a749320ad 100644 --- a/libfreerdp/gdi/region.c +++ b/libfreerdp/gdi/region.c @@ -234,8 +234,8 @@ INLINE BOOL gdi_CopyOverlap(int x, int y, int width, int height, int srcx, int s gdi_CRgnToRect(x, y, width, height, &dst); gdi_CRgnToRect(srcx, srcy, width, height, &src); - return (dst.right > src.left && dst.left < src.right && - dst.bottom > src.top && dst.top < src.bottom) ? TRUE : FALSE; + return (dst.right >= src.left && dst.left <= src.right && + dst.bottom >= src.top && dst.top <= src.bottom) ? TRUE : FALSE; } /** From 5542fef75d155faccc74dd49b86f754cc7df61ea Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 18 Jan 2016 10:08:12 +0100 Subject: [PATCH 159/220] Resetting abort event on freerdp_connect. --- libfreerdp/core/freerdp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index cce07fe3b..24e825c67 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -71,6 +71,7 @@ BOOL freerdp_connect(freerdp* instance) connectErrorCode = 0; freerdp_set_last_error(instance->context, FREERDP_ERROR_SUCCESS); clearChannelError(instance->context); + ResetEvent(instance->context->abortEvent); rdp = instance->context->rdp; settings = instance->settings; From 20ada7d3478a9ae87382100cd6d26bc1c9e05aac Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 18 Jan 2016 22:45:40 +0100 Subject: [PATCH 160/220] Fix pkg-config generation. --- rdtk/CMakeLists.txt | 3 +-- winpr/winpr.pc.in | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rdtk/CMakeLists.txt b/rdtk/CMakeLists.txt index 6faea306c..08b7648f9 100644 --- a/rdtk/CMakeLists.txt +++ b/rdtk/CMakeLists.txt @@ -73,6 +73,7 @@ if(WITH_SAMPLE) endif() # Exporting +set(RDTK_INCLUDE_DIR "include/rdtk${RDTK_VERSION_MAJOR}") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rdtk.pc.in ${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) @@ -81,8 +82,6 @@ if(${CMAKE_VERSION} VERSION_GREATER "2.8.10") set(RDTK_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/RdTk${RDTK_VERSION_MAJOR}") - set(RDTK_INCLUDE_DIR "include/rdtk${RDTK_VERSION_MAJOR}") - configure_package_config_file(RdTkConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/RdTkConfig.cmake INSTALL_DESTINATION ${RDTK_CMAKE_INSTALL_DIR} PATH_VARS RDTK_INCLUDE_DIR) diff --git a/winpr/winpr.pc.in b/winpr/winpr.pc.in index 58dc08afa..4c3063798 100644 --- a/winpr/winpr.pc.in +++ b/winpr/winpr.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=${libdir}/@WINPR_INCLUDE_DIR@ +includedir=${prefix}/@WINPR_INCLUDE_DIR@ libs=-lwinpr Name: WinPR From ca9e908f3c72f081df9c40730602167a29506656 Mon Sep 17 00:00:00 2001 From: davewheel Date: Thu, 14 Jan 2016 21:00:41 +0100 Subject: [PATCH 161/220] Fix a security issue in monitors packet handling The number of announced monitors was not checked, so if a client was announcing a big number, it could override other fields in settings and more... --- libfreerdp/core/gcc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index 18bf20b9d..af0b9c3cf 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -1594,6 +1594,12 @@ BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) Stream_Read_UINT32(s, flags); /* flags */ Stream_Read_UINT32(s, monitorCount); /* monitorCount */ + if (monitorCount > settings->MonitorDefArraySize) + { + WLog_ERR(TAG, "too many announced monitors(%d), clamping to %d", monitorCount, settings->MonitorDefArraySize); + monitorCount = settings->MonitorDefArraySize; + } + if (((blockLength - 8) / 20) < monitorCount) return FALSE; From 121a2348663a8299bb26fcf2d4e9720f5ac868c6 Mon Sep 17 00:00:00 2001 From: davewheel Date: Wed, 20 Jan 2016 16:54:15 +0100 Subject: [PATCH 162/220] Add better handling of monitors This patch makes FreeRDP announce the support for monitor layout PDU. It also adds support for servers to announce the monitors layout. --- include/freerdp/update.h | 4 +++- libfreerdp/core/activation.c | 25 +++++++++++++++++++++++++ libfreerdp/core/gcc.c | 6 ++++++ libfreerdp/core/rdp.c | 29 ++++++++++++++++------------- libfreerdp/core/rdp.h | 2 ++ libfreerdp/core/settings.c | 1 + 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/include/freerdp/update.h b/include/freerdp/update.h index 527d29196..16829b167 100644 --- a/include/freerdp/update.h +++ b/include/freerdp/update.h @@ -148,6 +148,7 @@ typedef BOOL (*pSetKeyboardIndicators)(rdpContext* context, UINT16 led_flags); typedef BOOL (*pRefreshRect)(rdpContext* context, BYTE count, RECTANGLE_16* areas); typedef BOOL (*pSuppressOutput)(rdpContext* context, BYTE allow, RECTANGLE_16* area); +typedef BOOL (*pRemoteMonitors)(rdpContext* context, UINT32 count, const MONITOR_DEF *monitors); typedef BOOL (*pSurfaceCommand)(rdpContext* context, wStream* s); typedef BOOL (*pSurfaceBits)(rdpContext* context, SURFACE_BITS_COMMAND* surfaceBitsCommand); @@ -180,7 +181,8 @@ struct rdp_update pRefreshRect RefreshRect; /* 48 */ pSuppressOutput SuppressOutput; /* 49 */ - UINT32 paddingD[64 - 50]; /* 50 */ + pRemoteMonitors RemoteMonitors; /* 50 */ + UINT32 paddingD[64 - 51]; /* 51 */ pSurfaceCommand SurfaceCommand; /* 64 */ pSurfaceBits SurfaceBits; /* 65 */ diff --git a/libfreerdp/core/activation.c b/libfreerdp/core/activation.c index 97ea42657..2db0566a0 100644 --- a/libfreerdp/core/activation.c +++ b/libfreerdp/core/activation.c @@ -364,9 +364,34 @@ BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s) { + rdpSettings *settings = rdp->settings; + if (!rdp_recv_client_font_list_pdu(s)) return FALSE; + if (settings->SupportMonitorLayoutPdu && settings->MonitorCount) + { + /* client supports the monitorLayout PDU, let's send him the monitors if any */ + wStream *st; + BOOL r; + + st = rdp_data_pdu_init(rdp); + if (!st) + return FALSE; + + if (!rdp_write_monitor_layout_pdu(st, settings->MonitorCount, settings->MonitorDefArray)) + { + Stream_Free(st, TRUE); + return FALSE; + } + + r = rdp_send_data_pdu(rdp, st, DATA_PDU_TYPE_MONITOR_LAYOUT, 0); + Stream_Free(st, TRUE); + + if (!r) + return FALSE; + } + if (!rdp_send_server_font_map_pdu(rdp)) return FALSE; diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index af0b9c3cf..f4b0bee87 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -761,6 +761,9 @@ BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) if (settings->SupportDynamicTimeZone) settings->SupportDynamicTimeZone = (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE) ? TRUE : FALSE; + if (settings->SupportMonitorLayoutPdu) + settings->SupportMonitorLayoutPdu = (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU) ? TRUE : FALSE; + if (!(earlyCapabilityFlags & RNS_UD_CS_VALID_CONNECTION_TYPE)) connectionType = 0; @@ -866,6 +869,9 @@ void gcc_write_client_core_data(wStream* s, rdpMcs* mcs) if (settings->SupportDynamicTimeZone) earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE; + if (settings->SupportMonitorLayoutPdu) + earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU; + Stream_Write_UINT16(s, highColorDepth); /* highColorDepth */ Stream_Write_UINT16(s, supportedColorDepths); /* supportedColorDepths */ diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index f49ae99c1..655a032a1 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -706,13 +706,14 @@ BOOL rdp_recv_monitor_layout_pdu(rdpRdp* rdp, wStream* s) UINT32 monitorCount; MONITOR_DEF* monitor; MONITOR_DEF* monitorDefArray; + BOOL ret = TRUE; if (Stream_GetRemainingLength(s) < 4) return FALSE; Stream_Read_UINT32(s, monitorCount); /* monitorCount (4 bytes) */ - if (Stream_GetRemainingLength(s) < (monitorCount * 20)) + if ((Stream_GetRemainingLength(s) / 20) < monitorCount) return FALSE; monitorDefArray = (MONITOR_DEF*) calloc(monitorCount, sizeof(MONITOR_DEF)); @@ -720,9 +721,8 @@ BOOL rdp_recv_monitor_layout_pdu(rdpRdp* rdp, wStream* s) if (!monitorDefArray) return FALSE; - for (index = 0; index < monitorCount; index++) + for (monitor = monitorDefArray, index = 0; index < monitorCount; index++, monitor++) { - monitor = &(monitorDefArray[index]); Stream_Read_UINT32(s, monitor->left); /* left (4 bytes) */ Stream_Read_UINT32(s, monitor->top); /* top (4 bytes) */ Stream_Read_UINT32(s, monitor->right); /* right (4 bytes) */ @@ -730,27 +730,30 @@ BOOL rdp_recv_monitor_layout_pdu(rdpRdp* rdp, wStream* s) Stream_Read_UINT32(s, monitor->flags); /* flags (4 bytes) */ } + IFCALLRET(rdp->update->RemoteMonitors, ret, rdp->context, monitorCount, monitorDefArray); + free(monitorDefArray); - return TRUE; + return ret; } -BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount, MONITOR_DEF* monitorDefArray) +BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount, const rdpMonitor* monitorDefArray) { UINT32 index; - MONITOR_DEF* monitor; + const rdpMonitor* monitor; + if (!Stream_EnsureRemainingCapacity(s, 4 + (monitorCount * 20))) return FALSE; + Stream_Write_UINT32(s, monitorCount); /* monitorCount (4 bytes) */ - for (index = 0; index < monitorCount; index++) + for (index = 0, monitor = monitorDefArray; index < monitorCount; index++, monitor++) { - monitor = &(monitorDefArray[index]); - Stream_Write_UINT32(s, monitor->left); /* left (4 bytes) */ - Stream_Write_UINT32(s, monitor->top); /* top (4 bytes) */ - Stream_Write_UINT32(s, monitor->right); /* right (4 bytes) */ - Stream_Write_UINT32(s, monitor->bottom); /* bottom (4 bytes) */ - Stream_Write_UINT32(s, monitor->flags); /* flags (4 bytes) */ + Stream_Write_UINT32(s, monitor->x); /* left (4 bytes) */ + Stream_Write_UINT32(s, monitor->y); /* top (4 bytes) */ + Stream_Write_UINT32(s, monitor->x + monitor->width - 1); /* right (4 bytes) */ + Stream_Write_UINT32(s, monitor->y + monitor->height - 1); /* bottom (4 bytes) */ + Stream_Write_UINT32(s, monitor->is_primary ? 0x01 : 0x00); /* flags (4 bytes) */ } return TRUE; diff --git a/libfreerdp/core/rdp.h b/libfreerdp/core/rdp.h index f756220c5..ad24bd4f1 100644 --- a/libfreerdp/core/rdp.h +++ b/libfreerdp/core/rdp.h @@ -214,6 +214,8 @@ int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s); void rdp_read_flow_control_pdu(wStream* s, UINT16* type); +BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount, const rdpMonitor* monitorDefArray); + int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra); int rdp_check_fds(rdpRdp* rdp); diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 0ddd7d2c4..456a4e31c 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -295,6 +295,7 @@ rdpSettings* freerdp_settings_new(DWORD flags) if (!settings->ChannelDefArray) goto out_fail; + settings->SupportMonitorLayoutPdu = TRUE; settings->MonitorCount = 0; settings->MonitorDefArraySize = 32; settings->MonitorDefArray = (rdpMonitor*) calloc(settings->MonitorDefArraySize, sizeof(rdpMonitor)); From a971f9e4bc3bd827df4745dcfc6a6f5d7d527a02 Mon Sep 17 00:00:00 2001 From: davewheel Date: Wed, 20 Jan 2016 22:21:05 +0100 Subject: [PATCH 163/220] Handle more NTLM attributes This patch adds the management of more NTLM attributes. Sponsored by: Wheel Systems (http://www.wheelsystems.com) --- winpr/include/winpr/sspi.h | 9 +++- winpr/libwinpr/sspi/NTLM/ntlm.c | 84 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/winpr/include/winpr/sspi.h b/winpr/include/winpr/sspi.h index 92e0aa34b..8ce78312f 100644 --- a/winpr/include/winpr/sspi.h +++ b/winpr/include/winpr/sspi.h @@ -999,8 +999,13 @@ extern "C" { #define SECPKG_ATTR_AUTH_NTLM_HASH 1003 #define SECPKG_ATTR_AUTH_NTLM_MESSAGE 1100 #define SECPKG_ATTR_AUTH_NTLM_TIMESTAMP 1101 -#define SECPKG_ATTR_AUTH_NTLM_CLIENT_CHALLENGE 1102 -#define SECPKG_ATTR_AUTH_NTLM_SERVER_CHALLENGE 1103 +#define SECPKG_ATTR_AUTH_NTLM_CLIENT_CHALLENGE 1102 +#define SECPKG_ATTR_AUTH_NTLM_SERVER_CHALLENGE 1103 +#define SECPKG_ATTR_AUTH_NTLM_NTPROOF_VALUE 1104 +#define SECPKG_ATTR_AUTH_NTLM_RANDKEY 1105 +#define SECPKG_ATTR_AUTH_NTLM_MIC 1106 +#define SECPKG_ATTR_AUTH_NTLM_MIC_VALUE 1107 + struct _SecPkgContext_AuthIdentity { diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index 9b732a8e2..2a7beb0b5 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -685,6 +685,90 @@ SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesW(PCtxtHandle phContext, UL return SEC_E_OK; } + else if (ulAttribute == SECPKG_ATTR_AUTH_NTLM_NTPROOF_VALUE) + { + BYTE *blob; + SecBuffer *ntproof, *target; + + ntproof = (SecBuffer *)pBuffer; + target = &context->ChallengeTargetInfo; + + if (!sspi_SecBufferAlloc(ntproof, 36 + target->cbBuffer)) + return (SEC_E_INSUFFICIENT_MEMORY); + + blob = (BYTE *)ntproof->pvBuffer; + /* Server challenge. */ + CopyMemory(blob, context->ServerChallenge, 8); + /* Response version. */ + blob[8] = 1; + /* Highest response version understood by the client. */ + blob[9] = 1; + /* Reserved 6B. */ + /* Time. */ + CopyMemory(&blob[16], context->Timestamp, 8); + /* Client challenge. */ + CopyMemory(&blob[24], context->ClientChallenge, 8); + /* Reserved 4B. */ + /* Server name. */ + CopyMemory(&blob[36], target->pvBuffer, target->cbBuffer); + + return (SEC_E_OK); + } + else if (ulAttribute == SECPKG_ATTR_AUTH_NTLM_RANDKEY) + { + SecBuffer *randkey; + + randkey = (SecBuffer *) pBuffer; + if (!sspi_SecBufferAlloc(randkey, 16)) + return (SEC_E_INSUFFICIENT_MEMORY); + + CopyMemory(randkey->pvBuffer, context->EncryptedRandomSessionKey, 16); + + return (SEC_E_OK); + } + else if (ulAttribute == SECPKG_ATTR_AUTH_NTLM_MIC) + { + SecBuffer *mic; + NTLM_AUTHENTICATE_MESSAGE *message; + + mic = (SecBuffer *) pBuffer; + message = &context->AUTHENTICATE_MESSAGE; + + if (!sspi_SecBufferAlloc(mic, 16)) + return (SEC_E_INSUFFICIENT_MEMORY); + + CopyMemory(mic->pvBuffer, message->MessageIntegrityCheck, 16); + + return (SEC_E_OK); + } + else if (ulAttribute == SECPKG_ATTR_AUTH_NTLM_MIC_VALUE) + { + BYTE *blob; + SecBuffer *micvalue; + ULONG msgSize = context->NegotiateMessage.cbBuffer + context->ChallengeMessage.cbBuffer + + context->AuthenticateMessage.cbBuffer; + + micvalue = (SecBuffer *) pBuffer; + + if (!sspi_SecBufferAlloc(micvalue, msgSize)) + return (SEC_E_INSUFFICIENT_MEMORY); + + blob = (BYTE *) micvalue->pvBuffer; + + CopyMemory(blob, context->NegotiateMessage.pvBuffer, context->NegotiateMessage.cbBuffer); + blob += context->NegotiateMessage.cbBuffer; + + CopyMemory(blob, context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer); + blob += context->ChallengeMessage.cbBuffer; + + CopyMemory(blob, context->AuthenticateMessage.pvBuffer, context->AuthenticateMessage.cbBuffer); + + blob += context->MessageIntegrityCheckOffset; + ZeroMemory(blob, 16); + + return (SEC_E_OK); + } + return SEC_E_UNSUPPORTED_FUNCTION; } From d5b8585a39931518504f53c6a643cd6a5e4d789d Mon Sep 17 00:00:00 2001 From: davewheel Date: Thu, 21 Jan 2016 00:17:59 +0100 Subject: [PATCH 164/220] Allow to specify the raw content of crypto materials Sometime it's possible that your server application doesn't have access to files (when running in a very restricted environment for example). This patch allows to ship the private key and certificate as a string. Sponsored by: Wheel Systems (http://www.wheelsystems.com) --- include/freerdp/crypto/tls.h | 2 +- include/freerdp/settings.h | 9 +++- libfreerdp/common/settings.c | 21 +++++++++ libfreerdp/core/certificate.c | 77 +++++++++++++++++--------------- libfreerdp/core/certificate.h | 1 + libfreerdp/core/nego.c | 2 +- libfreerdp/core/peer.c | 10 ++++- libfreerdp/core/settings.c | 6 +++ libfreerdp/core/transport.c | 4 +- libfreerdp/crypto/tls.c | 82 ++++++++++++++++++++++++++++++++--- 10 files changed, 168 insertions(+), 46 deletions(-) diff --git a/include/freerdp/crypto/tls.h b/include/freerdp/crypto/tls.h index 8d8daeca1..06dc97c68 100644 --- a/include/freerdp/crypto/tls.h +++ b/include/freerdp/crypto/tls.h @@ -89,7 +89,7 @@ struct rdp_tls #endif FREERDP_API int tls_connect(rdpTls* tls, BIO *underlying); -FREERDP_API BOOL tls_accept(rdpTls* tls, BIO *underlying, const char* cert_file, const char* privatekey_file); +FREERDP_API BOOL tls_accept(rdpTls* tls, BIO *underlying, rdpSettings *settings); FREERDP_API BOOL tls_send_alert(rdpTls* tls); FREERDP_API int tls_write_all(rdpTls* tls, const BYTE* data, int length); diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index d96d35293..268c6351e 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -655,6 +655,10 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL; #define FreeRDP_RdpServerRsaKey 1413 #define FreeRDP_RdpServerCertificate 1414 #define FreeRDP_ExternalCertificateManagement 1415 +#define FreeRDP_CertificateContent 1416 +#define FreeRDP_PrivateKeyContent 1417 +#define FreeRDP_RdpKeyContent 1418 + #define FreeRDP_Workarea 1536 #define FreeRDP_Fullscreen 1537 #define FreeRDP_PercentScreen 1538 @@ -1071,7 +1075,10 @@ struct rdp_settings ALIGN64 rdpRsaKey* RdpServerRsaKey; /* 1413 */ ALIGN64 rdpCertificate* RdpServerCertificate; /* 1414 */ ALIGN64 BOOL ExternalCertificateManagement; /* 1415 */ - UINT64 padding1472[1472 - 1416]; /* 1416 */ + ALIGN64 char *CertificateContent; /* 1416 */ + ALIGN64 char *PrivateKeyContent; /* 1417 */ + ALIGN64 char* RdpKeyContent; /* 1418 */ + UINT64 padding1472[1472 - 1419]; /* 1419 */ UINT64 padding1536[1536 - 1472]; /* 1472 */ /** diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index b31d3b242..859357a2a 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -2381,6 +2381,15 @@ char* freerdp_get_param_string(rdpSettings* settings, int id) case FreeRDP_RdpKeyFile: return settings->RdpKeyFile; + case FreeRDP_CertificateContent: + return settings->CertificateContent; + + case FreeRDP_PrivateKeyContent: + return settings->PrivateKeyContent; + + case FreeRDP_RdpKeyContent: + return settings->RdpKeyContent; + case FreeRDP_WindowTitle: return settings->WindowTitle; @@ -2551,6 +2560,18 @@ int freerdp_set_param_string(rdpSettings* settings, int id, const char* param) tmp = &settings->PrivateKeyFile; break; + case FreeRDP_CertificateContent: + tmp = &settings->CertificateContent; + break; + + case FreeRDP_PrivateKeyContent: + tmp = &settings->PrivateKeyContent; + break; + + case FreeRDP_RdpKeyContent: + tmp = &settings->RdpKeyContent; + break; + case FreeRDP_RdpKeyFile: tmp = &settings->RdpKeyFile; break; diff --git a/libfreerdp/core/certificate.c b/libfreerdp/core/certificate.c index 3fde935f5..a793af831 100644 --- a/libfreerdp/core/certificate.c +++ b/libfreerdp/core/certificate.c @@ -662,54 +662,22 @@ BOOL certificate_read_server_certificate(rdpCertificate* certificate, BYTE* serv return ret; } -rdpRsaKey* key_new(const char* keyfile) +rdpRsaKey* key_new_from_content(const char *keycontent, const char *keyfile) { BIO* bio = NULL; - FILE* fp = NULL; RSA* rsa = NULL; - int length; - BYTE* buffer = NULL; rdpRsaKey* key = NULL; key = (rdpRsaKey*) calloc(1, sizeof(rdpRsaKey)); - if (!key) return NULL; - fp = fopen(keyfile, "r+b"); - - if (!fp) - { - WLog_ERR(TAG, "unable to open RSA key file %s: %s.", keyfile, strerror(errno)); - goto out_free; - } - - if (fseek(fp, 0, SEEK_END) < 0) - goto out_free; - if ((length = ftell(fp)) < 0) - goto out_free; - if (fseek(fp, 0, SEEK_SET) < 0) - goto out_free; - - buffer = (BYTE*) malloc(length); - - if (!buffer) - goto out_free; - - if (fread((void*) buffer, length, 1, fp) != 1) - goto out_free; - fclose(fp); - fp = NULL; - - bio = BIO_new_mem_buf((void*) buffer, length); - + bio = BIO_new_mem_buf((void *)keycontent, strlen(keycontent)); if (!bio) goto out_free; rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL); BIO_free(bio); - free(buffer); - buffer = NULL; if (!rsa) { @@ -764,11 +732,50 @@ out_free_modulus: free(key->Modulus); out_free_rsa: RSA_free(rsa); +out_free: + free(key); + return NULL; +} + + +rdpRsaKey* key_new(const char* keyfile) +{ + FILE* fp = NULL; + int length; + char* buffer = NULL; + rdpRsaKey* key = NULL; + + fp = fopen(keyfile, "r+b"); + if (!fp) + { + WLog_ERR(TAG, "unable to open RSA key file %s: %s.", keyfile, strerror(errno)); + goto out_free; + } + + if (fseek(fp, 0, SEEK_END) < 0) + goto out_free; + if ((length = ftell(fp)) < 0) + goto out_free; + if (fseek(fp, 0, SEEK_SET) < 0) + goto out_free; + + buffer = (char *)malloc(length + 1); + if (!buffer) + goto out_free; + + if (fread((void*) buffer, length, 1, fp) != 1) + goto out_free; + fclose(fp); + buffer[length] = '\0'; + + key = key_new_from_content(buffer, keyfile); + free(buffer); + return key; + out_free: if (fp) fclose(fp); free(buffer); - free(key); return NULL; } diff --git a/libfreerdp/core/certificate.h b/libfreerdp/core/certificate.h index 6b3195f35..a48701ba3 100644 --- a/libfreerdp/core/certificate.h +++ b/libfreerdp/core/certificate.h @@ -59,6 +59,7 @@ rdpCertificate* certificate_new(void); void certificate_free(rdpCertificate* certificate); rdpRsaKey* key_new(const char *keyfile); +rdpRsaKey* key_new_from_content(const char *keycontent, const char *keyfile); void key_free(rdpRsaKey* key); #define CERTIFICATE_TAG FREERDP_TAG("core.certificate") diff --git a/libfreerdp/core/nego.c b/libfreerdp/core/nego.c index 67fcb6392..7cb6209fa 100644 --- a/libfreerdp/core/nego.c +++ b/libfreerdp/core/nego.c @@ -1086,7 +1086,7 @@ BOOL nego_send_negotiation_response(rdpNego* nego) settings->EncryptionLevel = ENCRYPTION_LEVEL_NONE; } - if (!settings->RdpServerRsaKey && !settings->RdpKeyFile) + if (!settings->RdpServerRsaKey && !settings->RdpKeyFile && !settings->RdpKeyContent) { WLog_ERR(TAG, "Missing server certificate"); return FALSE; diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index 84b4dc926..8318c4d8d 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -219,13 +219,21 @@ static BOOL freerdp_peer_initialize(freerdp_peer* client) if (settings->RdpKeyFile) { settings->RdpServerRsaKey = key_new(settings->RdpKeyFile); - if (!settings->RdpServerRsaKey) { WLog_ERR(TAG, "invalid RDP key file %s", settings->RdpKeyFile); return FALSE; } } + else if (settings->RdpKeyContent) + { + settings->RdpServerRsaKey = key_new_from_content(settings->RdpKeyContent, NULL); + if (!settings->RdpServerRsaKey) + { + WLog_ERR(TAG, "invalid RDP key content"); + return FALSE; + } + } return TRUE; } diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 0ddd7d2c4..bab861255 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -597,6 +597,9 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings) CHECKED_STRDUP(CertificateFile); /* 1410 */ CHECKED_STRDUP(PrivateKeyFile); /* 1411 */ CHECKED_STRDUP(RdpKeyFile); /* 1412 */ + CHECKED_STRDUP(CertificateContent); /* 1416 */ + CHECKED_STRDUP(PrivateKeyContent); /* 1417 */ + CHECKED_STRDUP(RdpKeyContent); /* 1418 */ CHECKED_STRDUP(WindowTitle); /* 1542 */ CHECKED_STRDUP(WmClass); /* 1549 */ CHECKED_STRDUP(ComputerName); /* 1664 */ @@ -924,6 +927,9 @@ void freerdp_settings_free(rdpSettings* settings) free(settings->ServerCertificate); free(settings->RdpKeyFile); certificate_free(settings->RdpServerCertificate); + free(settings->CertificateContent); + free(settings->PrivateKeyContent); + free(settings->RdpKeyContent); free(settings->ClientAutoReconnectCookie); free(settings->ServerAutoReconnectCookie); free(settings->ClientTimeZone); diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 0d132fe73..f7678b9fd 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -322,7 +322,7 @@ BOOL transport_accept_tls(rdpTransport* transport) transport->layer = TRANSPORT_LAYER_TLS; - if (!tls_accept(transport->tls, transport->frontBio, settings->CertificateFile, settings->PrivateKeyFile)) + if (!tls_accept(transport->tls, transport->frontBio, settings)) return FALSE; transport->frontBio = transport->tls->bio; @@ -340,7 +340,7 @@ BOOL transport_accept_nla(rdpTransport* transport) transport->layer = TRANSPORT_LAYER_TLS; - if (!tls_accept(transport->tls, transport->frontBio, settings->CertificateFile, settings->PrivateKeyFile)) + if (!tls_accept(transport->tls, transport->frontBio, settings)) return FALSE; transport->frontBio = transport->tls->bio; diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 90de48b2f..14d0c2ce2 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -823,9 +823,12 @@ static void tls_openssl_tlsext_debug_callback(SSL *s, int client_server, } #endif -BOOL tls_accept(rdpTls* tls, BIO* underlying, const char* cert_file, const char* privatekey_file) +BOOL tls_accept(rdpTls* tls, BIO* underlying, rdpSettings *settings) { long options = 0; + BIO *bio; + RSA *rsa; + X509 *x509; /** * SSL_OP_NO_SSLv2: @@ -867,16 +870,85 @@ BOOL tls_accept(rdpTls* tls, BIO* underlying, const char* cert_file, const char* if (!tls_prepare(tls, underlying, SSLv23_server_method(), options, FALSE)) return FALSE; - if (SSL_use_RSAPrivateKey_file(tls->ssl, privatekey_file, SSL_FILETYPE_PEM) <= 0) + if (settings->PrivateKeyFile) { - WLog_ERR(TAG, "SSL_CTX_use_RSAPrivateKey_file failed"); - WLog_ERR(TAG, "PrivateKeyFile: %s", privatekey_file); + bio = BIO_new_file(settings->PrivateKeyFile, "rb+"); + if (!bio) + { + WLog_ERR(TAG, "BIO_new_file failed for private key %s", settings->PrivateKeyFile); + return FALSE; + } + } + else if (settings->PrivateKeyContent) + { + bio = BIO_new_mem_buf(settings->PrivateKeyContent, strlen(settings->PrivateKeyContent)); + if (!bio) + { + WLog_ERR(TAG, "BIO_new_mem_buf failed for private key"); + return FALSE; + } + } + else + { + WLog_ERR(TAG, "no private key defined"); return FALSE; } - if (SSL_use_certificate_file(tls->ssl, cert_file, SSL_FILETYPE_PEM) <= 0) + rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL); + BIO_free(bio); + + if (!rsa) + { + WLog_ERR(TAG, "invalid private key"); + return FALSE; + } + + if (SSL_use_RSAPrivateKey(tls->ssl, rsa) <= 0) + { + WLog_ERR(TAG, "SSL_CTX_use_RSAPrivateKey_file failed"); + RSA_free(rsa); + return FALSE; + } + + + if (settings->CertificateFile) + { + bio = BIO_new_file(settings->CertificateFile, "rb+"); + if (!bio) + { + WLog_ERR(TAG, "BIO_new_file failed for certificate %s", settings->CertificateFile); + return FALSE; + } + } + else if (settings->CertificateContent) + { + bio = BIO_new_mem_buf(settings->CertificateContent, strlen(settings->CertificateContent)); + if (!bio) + { + WLog_ERR(TAG, "BIO_new_mem_buf failed for certificate"); + return FALSE; + } + } + else + { + WLog_ERR(TAG, "no certificate defined"); + return FALSE; + } + + x509 = PEM_read_bio_X509(bio, NULL, NULL, 0); + BIO_free(bio); + + if (!x509) + { + WLog_ERR(TAG, "invalid certificate"); + return FALSE; + } + + + if (SSL_use_certificate(tls->ssl, x509) <= 0) { WLog_ERR(TAG, "SSL_use_certificate_file failed"); + X509_free(x509); return FALSE; } From 78d3f4560150096b8fcad8a72760b8869fadd872 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 21 Jan 2016 15:26:32 +0100 Subject: [PATCH 165/220] Added cmake patch from @david-geiger --- winpr/include/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/winpr/include/CMakeLists.txt b/winpr/include/CMakeLists.txt index 928f88f18..452383d0d 100644 --- a/winpr/include/CMakeLists.txt +++ b/winpr/include/CMakeLists.txt @@ -21,4 +21,6 @@ set(WINPR_INSTALL_INCLUDE_DIR include/winpr${WINPR_VERSION_MAJOR}/winpr) file(GLOB WINPR_HEADERS "winpr/*.h") install(FILES ${WINPR_HEADERS} DESTINATION ${WINPR_INSTALL_INCLUDE_DIR} COMPONENT headers) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr/version.h DESTINATION ${WINPR_INSTALL_INCLUDE_DIR} COMPONENT headers) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr/wtypes.h DESTINATION ${WINPR_INSTALL_INCLUDE_DIR} COMPONENT headers) install(DIRECTORY winpr/tools DESTINATION ${WINPR_INSTALL_INCLUDE_DIR} COMPONENT headers FILES_MATCHING PATTERN "*.h") From 73ec3d6acaea4ca69dfd43df3cb847cc83310324 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 21 Jan 2016 14:47:10 +0100 Subject: [PATCH 166/220] Removed fixed size strings. --- libfreerdp/core/gateway/rdg.c | 16 ++++++++++++---- libfreerdp/core/gcc.c | 8 ++++---- libfreerdp/core/settings.c | 6 ++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libfreerdp/core/gateway/rdg.c b/libfreerdp/core/gateway/rdg.c index 4c355be29..2ede960ca 100644 --- a/libfreerdp/core/gateway/rdg.c +++ b/libfreerdp/core/gateway/rdg.c @@ -198,14 +198,21 @@ BOOL rdg_send_tunnel_authorization(rdpRdg* rdg) int i; wStream* s; BOOL status; - char* clientName = rdg->settings->ClientHostname; - UINT16 clientNameLen = strlen(clientName) + 1; + WCHAR* clientName = NULL; + UINT16 clientNameLen; UINT32 packetSize = 12 + clientNameLen * 2; + clientNameLen = ConvertToUnicode(CP_UTF8, 0, rdg->settings->ClientHostname, -1, &clientName, 0); + if (!clientName) + return FALSE; + s = Stream_New(NULL, packetSize); if (!s) + { + free(clientName); return FALSE; + } Stream_Write_UINT16(s, PKT_TYPE_TUNNEL_AUTH); /* Type (2 bytes) */ Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ @@ -215,15 +222,16 @@ BOOL rdg_send_tunnel_authorization(rdpRdg* rdg) Stream_Write_UINT16(s, clientNameLen * 2); /* Client name string length */ for (i = 0; i < clientNameLen; i++) - { Stream_Write_UINT16(s, clientName[i]); - } + + Stream_Write_UINT16(s, 0); Stream_SealLength(s); status = rdg_write_packet(rdg, s); Stream_Free(s, TRUE); + free(clientName); if (status) { diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index 18bf20b9d..460556d77 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -591,8 +591,8 @@ BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) /* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */ ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), 32 / 2, &str, 0, NULL, NULL); Stream_Seek(s, 32); - sprintf_s(settings->ClientHostname, 31, "%s", str); - settings->ClientHostname[31] = 0; + free(settings->ClientHostname); + settings->ClientHostname = str; free(str); str = NULL; @@ -649,8 +649,8 @@ BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), 64 / 2, &str, 0, NULL, NULL); Stream_Seek(s, 64); /* clientDigProductId (64 bytes) */ - sprintf_s(settings->ClientProductId, 32, "%s", str); - free(str); + free(settings->ClientProductId); + settings->ClientProductId = str; blockLength -= 64; if (blockLength < 1) diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 0ddd7d2c4..3d638a69f 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -728,14 +728,12 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings) CopyMemory(_settings->ReceivedCapabilities, settings->ReceivedCapabilities, 32); CopyMemory(_settings->OrderSupport, settings->OrderSupport, 32); - _settings->ClientHostname = malloc(32); + _settings->ClientHostname = _strdup(settings->ClientHostname); if (!_settings->ClientHostname) goto out_fail; - _settings->ClientProductId = malloc(32); + _settings->ClientProductId = _strdup(settings->ClientProductId); if (!_settings->ClientProductId) goto out_fail; - CopyMemory(_settings->ClientHostname, settings->ClientHostname, 32); - CopyMemory(_settings->ClientProductId, settings->ClientProductId, 32); _settings->BitmapCacheV2CellInfo = (BITMAP_CACHE_V2_CELL_INFO*) malloc(sizeof(BITMAP_CACHE_V2_CELL_INFO) * 6); if (!_settings->BitmapCacheV2CellInfo) From c5a4ce7893cf5508faaacb71caf24c2a2ad6bf0c Mon Sep 17 00:00:00 2001 From: Giovanni Panozzo Date: Wed, 20 Jan 2016 12:22:32 +0100 Subject: [PATCH 167/220] Improve error logging after calling some BIO_ functions --- libfreerdp/core/transport.c | 63 +++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 0d132fe73..005243f50 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -371,6 +371,53 @@ BOOL transport_accept_nla(rdpTransport* transport) return TRUE; } +#define WLog_ERR_BIO(tag, biofunc, bio) \ + transport_bio_error_log(tag, biofunc, bio, __FILE__, __FUNCTION__, __LINE__) + +static void transport_bio_error_log(LPCSTR tag, LPCSTR biofunc, BIO* bio, + LPCSTR file, LPCSTR func, DWORD line) +{ + unsigned long sslerr; + char *buf; + wLog* log; + wLogMessage log_message; + int saveerrno; + + saveerrno = errno; + + log = WLog_Get(tag); + if (!log) + return; + + log_message.Level = WLOG_ERROR; + if (log_message.Level < WLog_GetLogLevel(log)) + return; + + log_message.Type = WLOG_MESSAGE_TEXT; + log_message.LineNumber = line; + log_message.FileName = file; + log_message.FunctionName = func; + + if (ERR_peek_error() == 0) + { + log_message.FormatString = "%s returned a system error %d: %s"; + WLog_PrintMessage(log, &log_message, biofunc, saveerrno, strerror(saveerrno)); + return; + } + + buf = malloc(120); + if (buf) + { + while((sslerr = ERR_get_error())) + { + ERR_error_string_n(sslerr, buf, 120); + log_message.FormatString = "%s returned an error: %s"; + WLog_PrintMessage(log, &log_message, biofunc, buf); + } + free(buf); + } +} + int transport_read_layer(rdpTransport* transport, BYTE* data, int bytes) { int read = 0; @@ -391,6 +438,12 @@ int transport_read_layer(rdpTransport* transport, BYTE* data, int bytes) if (!transport->frontBio || !BIO_should_retry(transport->frontBio)) { /* something unexpected happened, let's close */ + if (!transport->frontBio) + { + WLog_ERR(TAG, "BIO_read: transport->frontBio null"); + return -1; + } + WLog_ERR_BIO(TAG, "BIO_read", transport->frontBio); transport->layer = TRANSPORT_LAYER_CLOSED; return -1; } @@ -402,7 +455,7 @@ int transport_read_layer(rdpTransport* transport, BYTE* data, int bytes) /* blocking means that we can't continue until we have read the number of requested bytes */ if (BIO_wait_read(transport->frontBio, 100) < 0) { - WLog_ERR(TAG, "error when selecting for read"); + WLog_ERR_BIO(TAG, "BIO_wait_read", transport->frontBio); return -1; } @@ -625,15 +678,21 @@ int transport_write(rdpTransport* transport, wStream* s) * is a SSL or TSG BIO in the chain. */ if (!BIO_should_retry(transport->frontBio)) + { + WLog_ERR_BIO(TAG, "BIO_should_retry", transport->frontBio); goto out_cleanup; + } /* non-blocking can live with blocked IOs */ if (!transport->blocking) + { + WLog_ERR_BIO(TAG, "BIO_write", transport->frontBio); goto out_cleanup; + } if (BIO_wait_write(transport->frontBio, 100) < 0) { - WLog_ERR(TAG, "error when selecting for write"); + WLog_ERR_BIO(TAG, "BIO_wait_write", transport->frontBio); status = -1; goto out_cleanup; } From 46a079fcb6e06f94dbf97e718019a301b6cfd60b Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sat, 23 Jan 2016 15:16:13 +0100 Subject: [PATCH 168/220] Added new command line options for logger. The new command line options /log-level: and /log-filters:: allow setting default log level and log module filter to be set. --- client/common/cmdline.c | 14 +++ winpr/include/winpr/wlog.h | 3 + winpr/libwinpr/utils/wlog/wlog.c | 160 +++++++++++++++++++------------ 3 files changed, 116 insertions(+), 61 deletions(-) diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 517ee0e06..42fa8d14b 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -173,6 +174,8 @@ static COMMAND_LINE_ARGUMENT_A args[] = { "encryption-methods", COMMAND_LINE_VALUE_REQUIRED, "<40,56,128,FIPS>", NULL, NULL, -1, NULL, "RDP standard security encryption methods" }, { "from-stdin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Read credentials from stdin, do not use defaults." }, { "buildconfig", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_BUILDCONFIG, NULL, NULL, NULL, -1, NULL, "print the build configuration" }, + { "log-level", COMMAND_LINE_VALUE_REQUIRED, "[OFF|FATAL|ERROR|WARN|INFO|DEBUG|TRACE]", NULL, NULL, -1, NULL, "Set the default log level" }, + { "log-filters", COMMAND_LINE_VALUE_REQUIRED, ":[, :][, ...]]", NULL, NULL, -1, NULL, "Set logger filters" }, { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; @@ -2106,6 +2109,17 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, { settings->CredentialsFromStdin = TRUE; } + CommandLineSwitchCase(arg, "log-level") + { + wLog* root = WLog_GetRoot(); + if (!WLog_SetStringLogLevel(root, arg->Value)) + return COMMAND_LINE_ERROR; + } + CommandLineSwitchCase(arg, "log-filters") + { + if (!WLog_AddStringLogFilters(arg->Value)) + return COMMAND_LINE_ERROR; + } CommandLineSwitchCase(arg, "sec-rdp") { settings->RdpSecurity = arg->Value ? TRUE : FALSE; diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 7da8aa51a..fc8a67703 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -190,6 +190,9 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args WINPR_API DWORD WLog_GetLogLevel(wLog* log); WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel); +WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level); +WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter); + WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType); WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 5526e693e..7d74cf67c 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -55,7 +55,7 @@ typedef struct _wLogFilter wLogFilter; * http://docs.python.org/2/library/logging.html */ -const char* WLOG_LEVELS[7] = +LPCSTR WLOG_LEVELS[7] = { "TRACE", "DEBUG", @@ -69,13 +69,16 @@ const char* WLOG_LEVELS[7] = static DWORD g_FilterCount = 0; static wLogFilter* g_Filters = NULL; -static BOOL log_recursion(const char* file, const char* fkt, int line) +static int WLog_ParseLogLevel(LPCSTR level); +static BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name); + +static BOOL log_recursion(LPCSTR file, LPCSTR fkt, int line) { char** msg; size_t used, i; void* bt = winpr_backtrace(20); #if defined(ANDROID) - const char* tag = WINPR_TAG("utils.wlog"); + LPCSTR tag = WINPR_TAG("utils.wlog"); #endif if (!bt) @@ -302,6 +305,92 @@ DWORD WLog_GetLogLevel(wLog* log) } } +BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level) +{ + int lvl; + if (!log || !level) + return FALSE; + + lvl = WLog_ParseLogLevel(level); + if (lvl < 0) + return FALSE; + + return WLog_SetLogLevel(log, lvl); +} + +BOOL WLog_AddStringLogFilters(LPCSTR filter) +{ + DWORD pos; + DWORD size; + DWORD count; + DWORD status; + LPSTR p; + LPSTR s; + LPSTR cp; + wLogFilter* tmp; + + if (!filter) + return FALSE; + + count = 1; + p = (LPSTR)filter; + + while ((p = strchr(p, ',')) != NULL) + { + count++; + p++; + } + + pos = g_FilterCount; + size = g_FilterCount + count; + tmp = (wLogFilter*) realloc(g_Filters, size * sizeof(wLogFilter)); + + if (!tmp) + { + free (g_Filters); + return FALSE; + } + g_Filters = tmp; + + cp = (LPSTR)_strdup(filter); + if (!cp) + return FALSE; + + p = cp; + s = cp; + + do + { + p = strchr(p, ','); + if (p) + *p = '\0'; + + if (pos < size) + { + status = WLog_ParseFilter(&g_Filters[pos++], s); + if (status < 0) + { + free (cp); + return FALSE; + } + } + else + break; + + if (p) + { + s = p + 1; + p++; + } + } + while (p != NULL); + + g_FilterCount = size; + free (cp); + + return TRUE; +} + BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel) { if (!log) @@ -316,7 +405,7 @@ BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel) return TRUE; } -int WLog_ParseLogLevel(const char* level) +int WLog_ParseLogLevel(LPCSTR level) { int iLevel = -1; @@ -418,12 +507,12 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name) BOOL WLog_ParseFilters() { - char* p; + BOOL res; char* env; - DWORD count; DWORD nSize; - int status; - LPCSTR* strs; + + g_Filters = NULL; + g_FilterCount = 0; nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0); @@ -438,62 +527,11 @@ BOOL WLog_ParseFilters() if (!GetEnvironmentVariableA("WLOG_FILTER", env, nSize)) return FALSE; - count = 1; - p = env; + res = WLog_AddStringLogFilters(env); - while ((p = strchr(p, ',')) != NULL) - { - count++; - p++; - } - - g_FilterCount = count; - p = env; - - count = 0; - strs = (LPCSTR*) calloc(g_FilterCount, sizeof(LPCSTR)); - - if (!strs) - { - free(env); - return FALSE; - } - - strs[count++] = p; - - while ((p = strchr(p, ',')) != NULL) - { - if (count < g_FilterCount) - strs[count++] = p + 1; - *p = '\0'; - p++; - } - - g_Filters = calloc(g_FilterCount, sizeof(wLogFilter)); - - if (!g_Filters) - { - free(strs); - free(env); - return FALSE; - } - - for (count = 0; count < g_FilterCount; count++) - { - status = WLog_ParseFilter(&g_Filters[count], strs[count]); - - if (status < 0) - { - free(strs); - free(env); - return FALSE; - } - } - - free(strs); free(env); - return TRUE; + return res; } int WLog_GetFilterLogLevel(wLog* log) From deffd0d781f90e4a44b593450d5f9de6f99c839d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 24 Jan 2016 15:21:06 +0100 Subject: [PATCH 169/220] Fixed argument checks for drive channel. --- channels/rdpdr/client/devman.c | 22 ++++++ channels/rdpdr/client/rdpdr_capabilities.c | 7 +- channels/rdpdr/client/rdpdr_capabilities.h | 2 +- channels/rdpdr/client/rdpdr_main.c | 78 ++++++++++++++++++---- 4 files changed, 95 insertions(+), 14 deletions(-) diff --git a/channels/rdpdr/client/devman.c b/channels/rdpdr/client/devman.c index 2e1666204..315339d92 100644 --- a/channels/rdpdr/client/devman.c +++ b/channels/rdpdr/client/devman.c @@ -6,6 +6,7 @@ * Copyright 2010-2012 Marc-Andre Moreau * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +43,9 @@ void devman_device_free(DEVICE* device) { + if (!device) + return; + IFCALL(device->Free, device); } @@ -49,6 +53,9 @@ DEVMAN* devman_new(rdpdrPlugin* rdpdr) { DEVMAN* devman; + if (!rdpdr) + return NULL; + devman = (DEVMAN*) calloc(1, sizeof(DEVMAN)); if (!devman) @@ -84,6 +91,9 @@ void devman_unregister_device(DEVMAN* devman, void* key) { DEVICE* device; + if (!devman || !key) + return; + device = (DEVICE*) ListDictionary_Remove(devman->devices, key); if (device) @@ -99,6 +109,12 @@ static UINT devman_register_device(DEVMAN* devman, DEVICE* device) { void* key = NULL; + if (!devman || !device) + return ERROR_INVALID_PARAMETER; + + if (device->type != RDPDR_DTYP_FILESYSTEM) + return CHANNEL_RC_OK; + device->id = devman->id_sequence++; key = (void*) (size_t) device->id; @@ -115,6 +131,9 @@ DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id) DEVICE* device = NULL; void* key = (void*) (size_t) id; + if (!devman) + return NULL; + device = (DEVICE*) ListDictionary_GetItemValue(devman->devices, key); return device; @@ -137,6 +156,9 @@ UINT devman_load_device_service(DEVMAN* devman, RDPDR_DEVICE* device, rdpContext DEVICE_SERVICE_ENTRY_POINTS ep; PDEVICE_SERVICE_ENTRY entry = NULL; + if (!devman || !device || !rdpcontext) + return ERROR_INVALID_PARAMETER; + if (device->Type == RDPDR_DTYP_FILESYSTEM) ServiceName = DRIVE_SERVICE_NAME; else if (device->Type == RDPDR_DTYP_PRINT) diff --git a/channels/rdpdr/client/rdpdr_capabilities.c b/channels/rdpdr/client/rdpdr_capabilities.c index 26f6d529e..1198a53c9 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.c +++ b/channels/rdpdr/client/rdpdr_capabilities.c @@ -128,12 +128,15 @@ static void rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s) Stream_Seek(s, capabilityLength - 4); } -void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s) +UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s) { UINT16 i; UINT16 numCapabilities; UINT16 capabilityType; + if (!rdpdr || !s) + return ERROR_INVALID_PARAMETER; + Stream_Read_UINT16(s, numCapabilities); Stream_Seek(s, 2); /* pad (2 bytes) */ @@ -167,6 +170,8 @@ void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s) break; } } + + return CHANNEL_RC_OK; } /** diff --git a/channels/rdpdr/client/rdpdr_capabilities.h b/channels/rdpdr/client/rdpdr_capabilities.h index bc2ef8b9e..d4e1ecb27 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.h +++ b/channels/rdpdr/client/rdpdr_capabilities.h @@ -25,7 +25,7 @@ #include "rdpdr_main.h" -void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s); +UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s); UINT rdpdr_send_capability_response(rdpdrPlugin* rdpdr); #endif /* FREERDP_CHANNEL_RDPDR_CLIENT_CAPABILITIES_H */ diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 30bd2681d..9581ab0ae 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -81,6 +81,9 @@ static UINT rdpdr_send_device_list_remove_request(rdpdrPlugin* rdpdr, UINT32 cou UINT32 i; wStream* s; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + s = Stream_New(NULL, 256); if (!s) { @@ -429,7 +432,7 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr) BOOL dev_found = FALSE; device_ext = (DEVICE_DRIVE_EXT *)ListDictionary_GetItemValue(rdpdr->devman->devices, (void *)keys[j]); - if (!device_ext) + if (!device_ext || !device_ext->path) continue; /* not plugable device */ @@ -592,6 +595,10 @@ out: static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr) { UINT error; + + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + if (rdpdr->hotplugThread) { if (rdpdr->stopEvent) @@ -623,6 +630,9 @@ static UINT rdpdr_process_connect(rdpdrPlugin* rdpdr) rdpSettings* settings; UINT error = CHANNEL_RC_OK; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + rdpdr->devman = devman_new(rdpdr); if (!rdpdr->devman) { @@ -661,13 +671,18 @@ static UINT rdpdr_process_connect(rdpdrPlugin* rdpdr) return error; } -static void rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, wStream* s) { + if (!rdpdr || !s) + return ERROR_INVALID_PARAMETER; + Stream_Read_UINT16(s, rdpdr->versionMajor); Stream_Read_UINT16(s, rdpdr->versionMinor); Stream_Read_UINT32(s, rdpdr->clientID); rdpdr->sequenceId++; + + return CHANNEL_RC_OK; } /** @@ -679,6 +694,9 @@ static UINT rdpdr_send_client_announce_reply(rdpdrPlugin* rdpdr) { wStream* s; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + s = Stream_New(NULL, 12); if (!s) { @@ -707,6 +725,9 @@ static UINT rdpdr_send_client_name_request(rdpdrPlugin* rdpdr) WCHAR* computerNameW = NULL; size_t computerNameLenW; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + if (!rdpdr->computerName[0]) gethostname(rdpdr->computerName, sizeof(rdpdr->computerName) - 1); @@ -733,12 +754,15 @@ static UINT rdpdr_send_client_name_request(rdpdrPlugin* rdpdr) return rdpdr_send(rdpdr, s); } -static void rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, wStream* s) { UINT16 versionMajor; UINT16 versionMinor; UINT32 clientID; + if (!rdpdr || !s) + return ERROR_INVALID_PARAMETER; + Stream_Read_UINT16(s, versionMajor); Stream_Read_UINT16(s, versionMinor); Stream_Read_UINT32(s, clientID); @@ -750,9 +774,9 @@ static void rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, wStream* s } if (clientID != rdpdr->clientID) - { rdpdr->clientID = clientID; - } + + return CHANNEL_RC_OK; } /** @@ -774,6 +798,9 @@ static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use int keyCount; ULONG_PTR* pKeys; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + s = Stream_New(NULL, 256); if (!s) { @@ -859,6 +886,9 @@ static UINT rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s) IRP* irp; UINT error = CHANNEL_RC_OK; + if (!rdpdr || !s) + return ERROR_INVALID_PARAMETER; + irp = irp_new(rdpdr->devman, s); if (!irp) @@ -888,6 +918,9 @@ static UINT rdpdr_process_init(rdpdrPlugin* rdpdr) ULONG_PTR* pKeys; UINT error = CHANNEL_RC_OK; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + pKeys = NULL; keyCount = ListDictionary_GetKeys(rdpdr->devman->devices, &pKeys); @@ -921,6 +954,9 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) UINT32 status; UINT error; + if (!rdpdr || !s) + return ERROR_INVALID_PARAMETER; + Stream_Read_UINT16(s, component); /* Component (2 bytes) */ Stream_Read_UINT16(s, packetId); /* PacketId (2 bytes) */ @@ -929,7 +965,8 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) switch (packetId) { case PAKID_CORE_SERVER_ANNOUNCE: - rdpdr_process_server_announce_request(rdpdr, s); + if ((error = rdpdr_process_server_announce_request(rdpdr, s))) + return error; if ((error = rdpdr_send_client_announce_reply(rdpdr))) { WLog_ERR(TAG, "rdpdr_send_client_announce_reply failed with error %lu", error); @@ -948,7 +985,8 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) break; case PAKID_CORE_SERVER_CAPABILITY: - rdpdr_process_capability_request(rdpdr, s); + if ((error = rdpdr_process_capability_request(rdpdr, s))) + return error; if ((error = rdpdr_send_capability_response(rdpdr))) { WLog_ERR(TAG, "rdpdr_send_capability_response failed with error %lu", error); @@ -957,7 +995,9 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) break; case PAKID_CORE_CLIENTID_CONFIRM: - rdpdr_process_server_clientid_confirm(rdpdr, s); + if ((error = rdpdr_process_server_clientid_confirm(rdpdr, s))) + return error; + if ((error = rdpdr_send_device_list_announce_request(rdpdr, FALSE))) { WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu", error); @@ -1132,10 +1172,11 @@ UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s) UINT status; rdpdrPlugin* plugin = (rdpdrPlugin*) rdpdr; + if (!rdpdr || !s) + return ERROR_INVALID_PARAMETER; + if (!plugin) - { status = CHANNEL_RC_BAD_INIT_HANDLE; - } else { status = plugin->channelEntryPoints.pVirtualChannelWrite(plugin->OpenHandle, @@ -1162,6 +1203,9 @@ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, { wStream* data_in; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) { /* @@ -1256,6 +1300,12 @@ static void* rdpdr_virtual_channel_client_thread(void* arg) rdpdrPlugin* rdpdr = (rdpdrPlugin*) arg; UINT error; + if (!rdpdr) + { + ExitThread((DWORD) ERROR_INVALID_PARAMETER); + return NULL; + } + if ((error = rdpdr_process_connect(rdpdr))) { WLog_ERR(TAG, "rdpdr_process_connect failed with error %lu!", error); @@ -1304,6 +1354,9 @@ static UINT rdpdr_virtual_channel_event_connected(rdpdrPlugin* rdpdr, LPVOID pDa UINT32 status; UINT error; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + status = rdpdr->channelEntryPoints.pVirtualChannelOpen(rdpdr->InitHandle, &rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event); @@ -1345,6 +1398,9 @@ static UINT rdpdr_virtual_channel_event_disconnected(rdpdrPlugin* rdpdr) { UINT error; + if (!rdpdr) + return ERROR_INVALID_PARAMETER; + if (MessageQueue_PostQuit(rdpdr->queue, 0) && (WaitForSingleObject(rdpdr->thread, INFINITE) == WAIT_FAILED)) { error = GetLastError(); @@ -1444,7 +1500,6 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) rdpdrPlugin* rdpdr; CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx; - rdpdr = (rdpdrPlugin*) calloc(1, sizeof(rdpdrPlugin)); if (!rdpdr) @@ -1473,7 +1528,6 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) CopyMemory(&(rdpdr->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP)); - rc = rdpdr->channelEntryPoints.pVirtualChannelInit(&rdpdr->InitHandle, &rdpdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, rdpdr_virtual_channel_init_event); From 137825ed9f5a6603f40ecdf3dbf8e720bfeeee4e Mon Sep 17 00:00:00 2001 From: David FORT Date: Mon, 25 Jan 2016 19:11:35 +0100 Subject: [PATCH 170/220] Stream_EnsureCapacity return value aren't checked in capabilities_write --- libfreerdp/core/capabilities.c | 293 +++++++++++++++++++++------------ libfreerdp/core/capabilities.h | 2 +- 2 files changed, 192 insertions(+), 103 deletions(-) diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 32ea34dff..46bc9986d 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -223,12 +223,13 @@ BOOL rdp_read_general_capability_set(wStream* s, UINT16 length, rdpSettings* set * @param settings settings */ -void rdp_write_general_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_general_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 extraFlags; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -259,6 +260,7 @@ void rdp_write_general_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT8(s, settings->SuppressOutput); /* suppressOutputSupport (1 byte) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_GENERAL); + return TRUE; } BOOL rdp_print_general_capability_set(wStream* s, UINT16 length) @@ -372,13 +374,14 @@ BOOL rdp_read_bitmap_capability_set(wStream* s, UINT16 length, rdpSettings* sett * @param settings settings */ -void rdp_write_bitmap_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_bitmap_capability_set(wStream* s, rdpSettings* settings) { int header; BYTE drawingFlags = 0; UINT16 preferredBitsPerPixel; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -421,6 +424,7 @@ void rdp_write_bitmap_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2OctetsB (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP); + return TRUE; } BOOL rdp_print_bitmap_capability_set(wStream* s, UINT16 length) @@ -543,14 +547,15 @@ BOOL rdp_read_order_capability_set(wStream* s, UINT16 length, rdpSettings* setti * @param settings settings */ -void rdp_write_order_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_order_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 orderFlags; UINT16 orderSupportExFlags; UINT16 textANSICodePage; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -591,6 +596,7 @@ void rdp_write_order_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2OctetsE (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_ORDER); + return TRUE; } BOOL rdp_print_order_capability_set(wStream* s, UINT16 length) @@ -721,13 +727,14 @@ BOOL rdp_read_bitmap_cache_capability_set(wStream* s, UINT16 length, rdpSettings * @param settings settings */ -void rdp_write_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) { int bpp; int header; UINT16 size; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -753,6 +760,7 @@ void rdp_write_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, size); /* Cache2MaximumCellSize (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE); + return TRUE; } BOOL rdp_print_bitmap_cache_capability_set(wStream* s, UINT16 length) @@ -825,11 +833,12 @@ BOOL rdp_read_control_capability_set(wStream* s, UINT16 length, rdpSettings* set * @param settings settings */ -void rdp_write_control_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_control_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -839,6 +848,7 @@ void rdp_write_control_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 2); /* detachInterest (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_CONTROL); + return TRUE; } BOOL rdp_print_control_capability_set(wStream* s, UINT16 length) @@ -891,11 +901,12 @@ BOOL rdp_read_window_activation_capability_set(wStream* s, UINT16 length, rdpSet * @param settings settings */ -void rdp_write_window_activation_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_window_activation_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -905,6 +916,7 @@ void rdp_write_window_activation_capability_set(wStream* s, rdpSettings* setting Stream_Write_UINT16(s, 0); /* windowManagerKeyFlag (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_ACTIVATION); + return TRUE; } BOOL rdp_print_window_activation_capability_set(wStream* s, UINT16 length) @@ -972,12 +984,13 @@ BOOL rdp_read_pointer_capability_set(wStream* s, UINT16 length, rdpSettings* set * @param settings settings */ -void rdp_write_pointer_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_pointer_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 colorPointerFlag; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -992,6 +1005,7 @@ void rdp_write_pointer_capability_set(wStream* s, rdpSettings* settings) } rdp_capability_set_finish(s, header, CAPSET_TYPE_POINTER); + return TRUE; } BOOL rdp_print_pointer_capability_set(wStream* s, UINT16 length) @@ -1039,12 +1053,13 @@ BOOL rdp_read_share_capability_set(wStream* s, UINT16 length, rdpSettings* setti * @param settings settings */ -void rdp_write_share_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_share_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 nodeId; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1054,6 +1069,7 @@ void rdp_write_share_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_SHARE); + return TRUE; } BOOL rdp_print_share_capability_set(wStream* s, UINT16 length) @@ -1098,11 +1114,12 @@ BOOL rdp_read_color_cache_capability_set(wStream* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_color_cache_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_color_cache_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1110,6 +1127,7 @@ void rdp_write_color_cache_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_COLOR_CACHE); + return TRUE; } BOOL rdp_print_color_cache_capability_set(wStream* s, UINT16 length) @@ -1158,12 +1176,13 @@ BOOL rdp_read_sound_capability_set(wStream* s, UINT16 length, rdpSettings* setti * @param settings settings */ -void rdp_write_sound_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_sound_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 soundFlags; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1173,6 +1192,7 @@ void rdp_write_sound_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2OctetsA (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_SOUND); + return TRUE; } BOOL rdp_print_sound_capability_set(wStream* s, UINT16 length) @@ -1255,12 +1275,13 @@ BOOL rdp_read_input_capability_set(wStream* s, UINT16 length, rdpSettings* setti * @param settings settings */ -void rdp_write_input_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_input_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 inputFlags; - Stream_EnsureRemainingCapacity(s, 128); + if (!Stream_EnsureRemainingCapacity(s, 128)) + return FALSE; header = rdp_capability_set_start(s); @@ -1281,6 +1302,7 @@ void rdp_write_input_capability_set(wStream* s, rdpSettings* settings) Stream_Zero(s, 64); /* imeFileName (64 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_INPUT); + return TRUE; } BOOL rdp_print_input_capability_set(wStream* s, UINT16 length) @@ -1338,11 +1360,12 @@ BOOL rdp_read_font_capability_set(wStream* s, UINT16 length, rdpSettings* settin * @param settings settings */ -void rdp_write_font_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_font_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1350,6 +1373,7 @@ void rdp_write_font_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_FONT); + return TRUE; } BOOL rdp_print_font_capability_set(wStream* s, UINT16 length) @@ -1394,17 +1418,19 @@ BOOL rdp_read_brush_capability_set(wStream* s, UINT16 length, rdpSettings* setti * @param settings settings */ -void rdp_write_brush_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_brush_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); Stream_Write_UINT32(s, BRUSH_COLOR_FULL); /* brushSupportLevel (4 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_BRUSH); + return TRUE; } BOOL rdp_print_brush_capability_set(wStream* s, UINT16 length) @@ -1482,11 +1508,12 @@ BOOL rdp_read_glyph_cache_capability_set(wStream* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_glyph_cache_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_glyph_cache_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -1508,6 +1535,7 @@ void rdp_write_glyph_cache_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_GLYPH_CACHE); + return TRUE; } BOOL rdp_print_glyph_cache_capability_set(wStream* s, UINT16 length) @@ -1584,12 +1612,13 @@ BOOL rdp_read_offscreen_bitmap_cache_capability_set(wStream* s, UINT16 length, r * @param settings settings */ -void rdp_write_offscreen_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_offscreen_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 offscreenSupportLevel = FALSE; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1601,6 +1630,7 @@ void rdp_write_offscreen_bitmap_cache_capability_set(wStream* s, rdpSettings* se Stream_Write_UINT16(s, settings->OffscreenCacheEntries); /* offscreenCacheEntries (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_OFFSCREEN_CACHE); + return TRUE; } BOOL rdp_print_offscreen_bitmap_cache_capability_set(wStream* s, UINT16 length) @@ -1749,12 +1779,13 @@ BOOL rdp_read_bitmap_cache_v2_capability_set(wStream* s, UINT16 length, rdpSetti * @param settings settings */ -void rdp_write_bitmap_cache_v2_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_bitmap_cache_v2_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 cacheFlags; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -1774,6 +1805,7 @@ void rdp_write_bitmap_cache_v2_capability_set(wStream* s, rdpSettings* settings) Stream_Zero(s, 12); /* pad3 (12 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE_V2); + return TRUE; } BOOL rdp_print_bitmap_cache_v2_capability_set(wStream* s, UINT16 length) @@ -1843,12 +1875,13 @@ BOOL rdp_read_virtual_channel_capability_set(wStream* s, UINT16 length, rdpSetti * @param settings settings */ -void rdp_write_virtual_channel_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_virtual_channel_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 flags; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1858,6 +1891,7 @@ void rdp_write_virtual_channel_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT32(s, settings->VirtualChannelChunkSize); /* VCChunkSize (4 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_VIRTUAL_CHANNEL); + return TRUE; } BOOL rdp_print_virtual_channel_capability_set(wStream* s, UINT16 length) @@ -1914,12 +1948,13 @@ BOOL rdp_read_draw_nine_grid_cache_capability_set(wStream* s, UINT16 length, rdp * @param settings settings */ -void rdp_write_draw_nine_grid_cache_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_draw_nine_grid_cache_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 drawNineGridSupportLevel; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1930,6 +1965,7 @@ void rdp_write_draw_nine_grid_cache_capability_set(wStream* s, rdpSettings* sett Stream_Write_UINT16(s, settings->DrawNineGridCacheEntries); /* drawNineGridCacheEntries (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_DRAW_NINE_GRID_CACHE); + return TRUE; } void rdp_write_gdiplus_cache_entries(wStream* s, UINT16 gce, UINT16 bce, UINT16 pce, UINT16 ice, UINT16 ace) @@ -2090,12 +2126,13 @@ BOOL rdp_read_remote_programs_capability_set(wStream* s, UINT16 length, rdpSetti * @param settings settings */ -void rdp_write_remote_programs_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_remote_programs_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 railSupportLevel; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -2107,6 +2144,7 @@ void rdp_write_remote_programs_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT32(s, railSupportLevel); /* railSupportLevel (4 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_RAIL); + return TRUE; } BOOL rdp_print_remote_programs_capability_set(wStream* s, UINT16 length) @@ -2149,12 +2187,13 @@ BOOL rdp_read_window_list_capability_set(wStream* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_window_list_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_window_list_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 wndSupportLevel; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -2165,6 +2204,7 @@ void rdp_write_window_list_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, settings->RemoteAppNumIconCacheEntries); /* numIconCacheEntries (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_WINDOW); + return TRUE; } BOOL rdp_print_window_list_capability_set(wStream* s, UINT16 length) @@ -2317,11 +2357,12 @@ BOOL rdp_read_multifragment_update_capability_set(wStream* s, UINT16 length, rdp * @param settings settings */ -void rdp_write_multifragment_update_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_multifragment_update_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; if (settings->ServerMode) { @@ -2351,6 +2392,7 @@ void rdp_write_multifragment_update_capability_set(wStream* s, rdpSettings* sett Stream_Write_UINT32(s, settings->MultifragMaxRequestSize); /* MaxRequestSize (4 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_MULTI_FRAGMENT_UPDATE); + return TRUE; } BOOL rdp_print_multifragment_update_capability_set(wStream* s, UINT16 length) @@ -2395,12 +2437,13 @@ BOOL rdp_read_large_pointer_capability_set(wStream* s, UINT16 length, rdpSetting * @param settings settings */ -void rdp_write_large_pointer_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_large_pointer_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 largePointerSupportFlags; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -2409,6 +2452,7 @@ void rdp_write_large_pointer_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, largePointerSupportFlags); /* largePointerSupportFlags (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_LARGE_POINTER); + return TRUE; } BOOL rdp_print_large_pointer_capability_set(wStream* s, UINT16 length) @@ -2455,12 +2499,13 @@ BOOL rdp_read_surface_commands_capability_set(wStream* s, UINT16 length, rdpSett * @param settings settings */ -void rdp_write_surface_commands_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_surface_commands_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 cmdFlags; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -2473,6 +2518,7 @@ void rdp_write_surface_commands_capability_set(wStream* s, rdpSettings* settings Stream_Write_UINT32(s, 0); /* reserved (4 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_SURFACE_COMMANDS); + return TRUE; } BOOL rdp_print_surface_commands_capability_set(wStream* s, UINT16 length) @@ -2785,12 +2831,13 @@ BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, UINT16 length, rdpSetting * @param s stream * @param settings settings */ -void rdp_write_rfx_client_capability_container(wStream* s, rdpSettings* settings) +BOOL rdp_write_rfx_client_capability_container(wStream* s, rdpSettings* settings) { UINT32 captureFlags; BYTE codecMode; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; captureFlags = settings->RemoteFxOnly ? 0 : CARDP_CAPS_CAPTURE_NON_CAC; codecMode = settings->RemoteFxCodecMode; @@ -2830,6 +2877,7 @@ void rdp_write_rfx_client_capability_container(wStream* s, rdpSettings* settings Stream_Write_UINT8(s, CLW_COL_CONV_ICT); /* colConvBits */ Stream_Write_UINT8(s, CLW_XFORM_DWT_53_A); /* transformBits */ Stream_Write_UINT8(s, CLW_ENTROPY_RLGR3); /* entropyBits */ + return TRUE; } /** @@ -2837,7 +2885,7 @@ void rdp_write_rfx_client_capability_container(wStream* s, rdpSettings* settings * @param s stream * @param settings settings */ -void rdp_write_nsc_client_capability_container(wStream* s, rdpSettings* settings) +BOOL rdp_write_nsc_client_capability_container(wStream* s, rdpSettings* settings) { BYTE colorLossLevel; BYTE fAllowSubsampling; @@ -2853,7 +2901,8 @@ void rdp_write_nsc_client_capability_container(wStream* s, rdpSettings* settings if (colorLossLevel > 7) colorLossLevel = 7; - Stream_EnsureRemainingCapacity(s, 8); + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; Stream_Write_UINT16(s, 3); /* codecPropertiesLength */ @@ -2861,14 +2910,17 @@ void rdp_write_nsc_client_capability_container(wStream* s, rdpSettings* settings Stream_Write_UINT8(s, fAllowDynamicFidelity); /* fAllowDynamicFidelity (1 byte) */ Stream_Write_UINT8(s, fAllowSubsampling); /* fAllowSubsampling (1 byte) */ Stream_Write_UINT8(s, colorLossLevel); /* colorLossLevel (1 byte) */ + return TRUE; } -void rdp_write_jpeg_client_capability_container(wStream* s, rdpSettings* settings) +BOOL rdp_write_jpeg_client_capability_container(wStream* s, rdpSettings* settings) { - Stream_EnsureRemainingCapacity(s, 8); + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; Stream_Write_UINT16(s, 1); /* codecPropertiesLength */ Stream_Write_UINT8(s, settings->JpegQuality); + return TRUE; } /** @@ -2876,20 +2928,24 @@ void rdp_write_jpeg_client_capability_container(wStream* s, rdpSettings* setting * @param s stream * @param settings settings */ -void rdp_write_rfx_server_capability_container(wStream* s, rdpSettings* settings) +BOOL rdp_write_rfx_server_capability_container(wStream* s, rdpSettings* settings) { - Stream_EnsureRemainingCapacity(s, 8); + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; Stream_Write_UINT16(s, 4); /* codecPropertiesLength */ Stream_Write_UINT32(s, 0); /* reserved */ + return TRUE; } -void rdp_write_jpeg_server_capability_container(wStream* s, rdpSettings* settings) +BOOL rdp_write_jpeg_server_capability_container(wStream* s, rdpSettings* settings) { - Stream_EnsureRemainingCapacity(s, 8); + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; Stream_Write_UINT16(s, 1); /* codecPropertiesLength */ Stream_Write_UINT8(s, 75); + return TRUE; } /** @@ -2897,12 +2953,14 @@ void rdp_write_jpeg_server_capability_container(wStream* s, rdpSettings* setting * @param s stream * @param settings settings */ -void rdp_write_nsc_server_capability_container(wStream* s, rdpSettings* settings) +BOOL rdp_write_nsc_server_capability_container(wStream* s, rdpSettings* settings) { - Stream_EnsureRemainingCapacity(s, 8); + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; Stream_Write_UINT16(s, 4); /* codecPropertiesLength */ Stream_Write_UINT32(s, 0); /* reserved */ + return TRUE; } /** @@ -2912,12 +2970,13 @@ void rdp_write_nsc_server_capability_container(wStream* s, rdpSettings* settings * @param settings settings */ -void rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) { int header; BYTE bitmapCodecCount; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -2941,12 +3000,14 @@ void rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) if (settings->ServerMode) { Stream_Write_UINT8(s, 0); /* codecID is defined by the client */ - rdp_write_rfx_server_capability_container(s, settings); + if (!rdp_write_rfx_server_capability_container(s, settings)) + return FALSE; } else { Stream_Write_UINT8(s, RDP_CODEC_ID_REMOTEFX); /* codecID */ - rdp_write_rfx_client_capability_container(s, settings); + if (!rdp_write_rfx_client_capability_container(s, settings)) + return FALSE; } } @@ -2957,12 +3018,14 @@ void rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) if (settings->ServerMode) { Stream_Write_UINT8(s, 0); /* codecID is defined by the client */ - rdp_write_nsc_server_capability_container(s, settings); + if (!rdp_write_nsc_server_capability_container(s, settings)) + return FALSE; } else { Stream_Write_UINT8(s, RDP_CODEC_ID_NSCODEC); /* codecID */ - rdp_write_nsc_client_capability_container(s, settings); + if (!rdp_write_nsc_client_capability_container(s, settings)) + return FALSE; } } @@ -2973,12 +3036,14 @@ void rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) if (settings->ServerMode) { Stream_Write_UINT8(s, 0); /* codecID is defined by the client */ - rdp_write_jpeg_server_capability_container(s, settings); + if (!rdp_write_jpeg_server_capability_container(s, settings)) + return FALSE; } else { Stream_Write_UINT8(s, RDP_CODEC_ID_JPEG); /* codecID */ - rdp_write_jpeg_client_capability_container(s, settings); + if (!rdp_write_jpeg_client_capability_container(s, settings)) + return FALSE; } } @@ -2989,16 +3054,19 @@ void rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) if (settings->ServerMode) { Stream_Write_UINT8(s, 0); /* codecID is defined by the client */ - rdp_write_rfx_server_capability_container(s, settings); + if (!rdp_write_rfx_server_capability_container(s, settings)) + return FALSE; } else { Stream_Write_UINT8(s, RDP_CODEC_ID_IMAGE_REMOTEFX); /* codecID */ - rdp_write_rfx_client_capability_container(s, settings); + if (!rdp_write_rfx_client_capability_container(s, settings)) + return FALSE; } } rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CODECS); + return TRUE; } BOOL rdp_print_bitmap_codecs_capability_set(wStream* s, UINT16 length) @@ -3074,17 +3142,19 @@ BOOL rdp_read_frame_acknowledge_capability_set(wStream* s, UINT16 length, rdpSet * @param settings settings */ -void rdp_write_frame_acknowledge_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_frame_acknowledge_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); Stream_Write_UINT32(s, settings->FrameAcknowledge); /* (4 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_FRAME_ACKNOWLEDGE); + return TRUE; } BOOL rdp_print_frame_acknowledge_capability_set(wStream* s, UINT16 length) @@ -3112,16 +3182,18 @@ BOOL rdp_read_bitmap_cache_v3_codec_id_capability_set(wStream* s, UINT16 length, return TRUE; } -void rdp_write_bitmap_cache_v3_codec_id_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_bitmap_cache_v3_codec_id_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); Stream_Write_UINT8(s, settings->BitmapCacheV3CodecId); rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE_V3_CODEC_ID); + return TRUE; } BOOL rdp_print_bitmap_cache_v3_codec_id_capability_set(wStream* s, UINT16 length) @@ -3798,12 +3870,13 @@ BOOL rdp_recv_confirm_active(rdpRdp* rdp, wStream* s) return status; } -void rdp_write_confirm_active(wStream* s, rdpSettings* settings) +BOOL rdp_write_confirm_active(wStream* s, rdpSettings* settings) { int bm, em, lm; UINT16 numberCapabilities; UINT16 lengthSourceDescriptor; UINT16 lengthCombinedCapabilities; + BOOL ret; lengthSourceDescriptor = sizeof(SOURCE_DESCRIPTOR); @@ -3821,37 +3894,46 @@ void rdp_write_confirm_active(wStream* s, rdpSettings* settings) /* Capability Sets */ numberCapabilities = 15; - rdp_write_general_capability_set(s, settings); - rdp_write_bitmap_capability_set(s, settings); - rdp_write_order_capability_set(s, settings); + if (!rdp_write_general_capability_set(s, settings) || + !rdp_write_bitmap_capability_set(s, settings) || + !rdp_write_order_capability_set(s, settings)) + return FALSE; if (settings->RdpVersion >= 5) - rdp_write_bitmap_cache_v2_capability_set(s, settings); + ret = rdp_write_bitmap_cache_v2_capability_set(s, settings); else - rdp_write_bitmap_cache_capability_set(s, settings); + ret = rdp_write_bitmap_cache_capability_set(s, settings); - rdp_write_pointer_capability_set(s, settings); - rdp_write_input_capability_set(s, settings); - rdp_write_brush_capability_set(s, settings); - rdp_write_glyph_cache_capability_set(s, settings); - rdp_write_virtual_channel_capability_set(s, settings); - rdp_write_sound_capability_set(s, settings); - rdp_write_share_capability_set(s, settings); - rdp_write_font_capability_set(s, settings); - rdp_write_control_capability_set(s, settings); - rdp_write_color_cache_capability_set(s, settings); - rdp_write_window_activation_capability_set(s, settings); + if (!ret) + return FALSE; + + if (!rdp_write_pointer_capability_set(s, settings) || + !rdp_write_input_capability_set(s, settings) || + !rdp_write_brush_capability_set(s, settings) || + !rdp_write_glyph_cache_capability_set(s, settings) || + !rdp_write_virtual_channel_capability_set(s, settings) || + !rdp_write_sound_capability_set(s, settings) || + !rdp_write_share_capability_set(s, settings) || + !rdp_write_font_capability_set(s, settings) || + !rdp_write_control_capability_set(s, settings) || + !rdp_write_color_cache_capability_set(s, settings) || + !rdp_write_window_activation_capability_set(s, settings)) + { + return FALSE; + } if (settings->OffscreenSupportLevel) { numberCapabilities++; - rdp_write_offscreen_bitmap_cache_capability_set(s, settings); + if (!rdp_write_offscreen_bitmap_cache_capability_set(s, settings)) + return FALSE; } if (settings->DrawNineGridEnabled) { numberCapabilities++; - rdp_write_draw_nine_grid_cache_capability_set(s, settings); + if (!rdp_write_draw_nine_grid_cache_capability_set(s, settings)) + return FALSE; } if (settings->ReceivedCapabilities[CAPSET_TYPE_LARGE_POINTER]) @@ -3859,33 +3941,38 @@ void rdp_write_confirm_active(wStream* s, rdpSettings* settings) if (settings->LargePointerFlag) { numberCapabilities++; - rdp_write_large_pointer_capability_set(s, settings); + if (!rdp_write_large_pointer_capability_set(s, settings)) + return FALSE; } } if (settings->RemoteApplicationMode) { numberCapabilities += 2; - rdp_write_remote_programs_capability_set(s, settings); - rdp_write_window_list_capability_set(s, settings); + if (!rdp_write_remote_programs_capability_set(s, settings) || + !rdp_write_window_list_capability_set(s, settings)) + return FALSE; } if (settings->ReceivedCapabilities[CAPSET_TYPE_MULTI_FRAGMENT_UPDATE]) { numberCapabilities++; - rdp_write_multifragment_update_capability_set(s, settings); + if (!rdp_write_multifragment_update_capability_set(s, settings)) + return FALSE; } if (settings->ReceivedCapabilities[CAPSET_TYPE_SURFACE_COMMANDS]) { numberCapabilities++; - rdp_write_surface_commands_capability_set(s, settings); + if (!rdp_write_surface_commands_capability_set(s, settings)) + return FALSE; } if (settings->ReceivedCapabilities[CAPSET_TYPE_BITMAP_CODECS]) { numberCapabilities++; - rdp_write_bitmap_codecs_capability_set(s, settings); + if (!rdp_write_bitmap_codecs_capability_set(s, settings)) + return FALSE; } if (!settings->ReceivedCapabilities[CAPSET_TYPE_FRAME_ACKNOWLEDGE]) @@ -3894,7 +3981,8 @@ void rdp_write_confirm_active(wStream* s, rdpSettings* settings) if (settings->FrameAcknowledge) { numberCapabilities++; - rdp_write_frame_acknowledge_capability_set(s, settings); + if (!rdp_write_frame_acknowledge_capability_set(s, settings)) + return FALSE; } if (settings->ReceivedCapabilities[CAPSET_TYPE_BITMAP_CACHE_V3_CODEC_ID]) @@ -3902,7 +3990,8 @@ void rdp_write_confirm_active(wStream* s, rdpSettings* settings) if (settings->BitmapCacheV3CodecId != 0) { numberCapabilities++; - rdp_write_bitmap_cache_v3_codec_id_capability_set(s, settings); + if (!rdp_write_bitmap_cache_v3_codec_id_capability_set(s, settings)) + return FALSE; } } @@ -3923,6 +4012,7 @@ void rdp_write_confirm_active(wStream* s, rdpSettings* settings) #endif Stream_SetPosition(s, em); + return TRUE; } BOOL rdp_send_confirm_active(rdpRdp* rdp) @@ -3935,9 +4025,8 @@ BOOL rdp_send_confirm_active(rdpRdp* rdp) rdp_init_stream_pdu(rdp, s); - rdp_write_confirm_active(s, rdp->settings); - - status = rdp_send_pdu(rdp, s, PDU_TYPE_CONFIRM_ACTIVE, rdp->mcs->userId); + status = rdp_write_confirm_active(s, rdp->settings) && + rdp_send_pdu(rdp, s, PDU_TYPE_CONFIRM_ACTIVE, rdp->mcs->userId); Stream_Free(s, TRUE); diff --git a/libfreerdp/core/capabilities.h b/libfreerdp/core/capabilities.h index 06ed108c5..441fb170a 100644 --- a/libfreerdp/core/capabilities.h +++ b/libfreerdp/core/capabilities.h @@ -172,7 +172,7 @@ BOOL rdp_recv_demand_active(rdpRdp* rdp, wStream* s); void rdp_write_demand_active(wStream* s, rdpSettings* settings); BOOL rdp_send_demand_active(rdpRdp* rdp); BOOL rdp_recv_confirm_active(rdpRdp* rdp, wStream* s); -void rdp_write_confirm_active(wStream* s, rdpSettings* settings); +BOOL rdp_write_confirm_active(wStream* s, rdpSettings* settings); BOOL rdp_send_confirm_active(rdpRdp* rdp); #endif /* __CAPABILITIES_H */ From 106479d6f27cdd34a8d7dd8e654d890542ab1fcb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 26 Jan 2016 09:34:22 +0100 Subject: [PATCH 171/220] Fixed clientNameLen initialization. --- libfreerdp/core/gateway/rdg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfreerdp/core/gateway/rdg.c b/libfreerdp/core/gateway/rdg.c index 2ede960ca..3f3bab8ec 100644 --- a/libfreerdp/core/gateway/rdg.c +++ b/libfreerdp/core/gateway/rdg.c @@ -200,12 +200,13 @@ BOOL rdg_send_tunnel_authorization(rdpRdg* rdg) BOOL status; WCHAR* clientName = NULL; UINT16 clientNameLen; - UINT32 packetSize = 12 + clientNameLen * 2; + UINT32 packetSize; clientNameLen = ConvertToUnicode(CP_UTF8, 0, rdg->settings->ClientHostname, -1, &clientName, 0); if (!clientName) return FALSE; + packetSize = 12 + clientNameLen * 2 + sizeof(WCHAR); s = Stream_New(NULL, packetSize); if (!s) From 708d0cb3c0a8195acb19718d0214b7360044cc8a Mon Sep 17 00:00:00 2001 From: David FORT Date: Tue, 26 Jan 2016 16:14:48 +0100 Subject: [PATCH 172/220] Check server and client capabilities Most of the capabilities are sent by both the client and the server. But for some the specs specify that they are only supposed to be only send by the server or the client. This patch ensures this. Without this patch a malicious client can change server settings and a malicious server can modify client settings. --- libfreerdp/core/capabilities.c | 168 +++++++++++++++++++-------------- 1 file changed, 99 insertions(+), 69 deletions(-) diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 46bc9986d..8205f43e5 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -31,8 +31,6 @@ #define TAG FREERDP_TAG("core.capabilities") -#ifdef WITH_DEBUG_CAPABILITIES - const char* const CAPSET_TYPE_STRINGS[] = { "Unknown", @@ -68,7 +66,13 @@ const char* const CAPSET_TYPE_STRINGS[] = "Frame Acknowledge" }; -#endif +static const char *get_capability_name(UINT16 type) +{ + if (type > CAPSET_TYPE_FRAME_ACKNOWLEDGE) + return ""; + + return CAPSET_TYPE_STRINGS[type]; +} BOOL rdp_print_capability_sets(wStream* s, UINT16 numberCapabilities, BOOL receiving); @@ -3401,6 +3405,7 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa UINT16 type; UINT16 length; BYTE *bm, *em; + BOOL treated; Stream_GetPointer(s, mark); count = numberCapabilities; @@ -3428,6 +3433,7 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa return FALSE; } + treated = TRUE; switch (type) { case CAPSET_TYPE_GENERAL: @@ -3445,26 +3451,21 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa return FALSE; break; - case CAPSET_TYPE_BITMAP_CACHE: - if (!rdp_read_bitmap_cache_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_CONTROL: - if (!rdp_read_control_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_ACTIVATION: - if (!rdp_read_window_activation_capability_set(s, length, settings)) - return FALSE; - break; - case CAPSET_TYPE_POINTER: if (!rdp_read_pointer_capability_set(s, length, settings)) return FALSE; break; + case CAPSET_TYPE_INPUT: + if (!rdp_read_input_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_VIRTUAL_CHANNEL: + if (!rdp_read_virtual_channel_capability_set(s, length, settings)) + return FALSE; + break; + case CAPSET_TYPE_SHARE: if (!rdp_read_share_capability_set(s, length, settings)) return FALSE; @@ -3475,56 +3476,11 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa return FALSE; break; - case CAPSET_TYPE_SOUND: - if (!rdp_read_sound_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_INPUT: - if (!rdp_read_input_capability_set(s, length, settings)) - return FALSE; - break; - case CAPSET_TYPE_FONT: if (!rdp_read_font_capability_set(s, length, settings)) return FALSE; break; - case CAPSET_TYPE_BRUSH: - if (!rdp_read_brush_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_GLYPH_CACHE: - if (!rdp_read_glyph_cache_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_OFFSCREEN_CACHE: - if (!rdp_read_offscreen_bitmap_cache_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_BITMAP_CACHE_HOST_SUPPORT: - if (!rdp_read_bitmap_cache_host_support_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_BITMAP_CACHE_V2: - if (!rdp_read_bitmap_cache_v2_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_VIRTUAL_CHANNEL: - if (!rdp_read_virtual_channel_capability_set(s, length, settings)) - return FALSE; - break; - - case CAPSET_TYPE_DRAW_NINE_GRID_CACHE: - if (!rdp_read_draw_nine_grid_cache_capability_set(s, length, settings)) - return FALSE; - break; - case CAPSET_TYPE_DRAW_GDI_PLUS: if (!rdp_read_draw_gdiplus_cache_capability_set(s, length, settings)) return FALSE; @@ -3540,11 +3496,6 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa return FALSE; break; - case CAPSET_TYPE_COMP_DESK: - if (!rdp_read_desktop_composition_capability_set(s, length, settings)) - return FALSE; - break; - case CAPSET_TYPE_MULTI_FRAGMENT_UPDATE: if (!rdp_read_multifragment_update_capability_set(s, length, settings)) return FALSE; @@ -3555,6 +3506,11 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa return FALSE; break; + case CAPSET_TYPE_COMP_DESK: + if (!rdp_read_desktop_composition_capability_set(s, length, settings)) + return FALSE; + break; + case CAPSET_TYPE_SURFACE_COMMANDS: if (!rdp_read_surface_commands_capability_set(s, length, settings)) return FALSE; @@ -3576,10 +3532,84 @@ BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCa break; default: - WLog_ERR(TAG, "unknown capability type %d", type); + treated = FALSE; break; } + if (!treated) + { + if (settings->ServerMode) + { + /* treating capabilities that are supposed to be send only from the client */ + switch (type) + { + case CAPSET_TYPE_BITMAP_CACHE: + if (!rdp_read_bitmap_cache_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_BITMAP_CACHE_V2: + if (!rdp_read_bitmap_cache_v2_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_BRUSH: + if (!rdp_read_brush_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_GLYPH_CACHE: + if (!rdp_read_glyph_cache_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_OFFSCREEN_CACHE: + if (!rdp_read_offscreen_bitmap_cache_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_SOUND: + if (!rdp_read_sound_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_CONTROL: + if (!rdp_read_control_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_ACTIVATION: + if (!rdp_read_window_activation_capability_set(s, length, settings)) + return FALSE; + break; + + case CAPSET_TYPE_DRAW_NINE_GRID_CACHE: + if (!rdp_read_draw_nine_grid_cache_capability_set(s, length, settings)) + return FALSE; + break; + + default: + WLog_ERR(TAG, "capability %s(%d) not expected from client", get_capability_name(type), type); + return FALSE; + } + } + else + { + /* treating capabilities that are supposed to be send only from the server */ + switch (type) + { + case CAPSET_TYPE_BITMAP_CACHE_HOST_SUPPORT: + if (!rdp_read_bitmap_cache_host_support_capability_set(s, length, settings)) + return FALSE; + break; + + default: + WLog_ERR(TAG, "capability %s(%d) not expected from server", get_capability_name(type), type); + return FALSE; + } + } + } + if (s->pointer != em) { WLog_ERR(TAG, "incorrect offset, type:0x%02X actual:%d expected:%d", From 974d2ef433cd867728ace80d6c5decf965f684f3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 26 Jan 2016 21:35:16 +0100 Subject: [PATCH 173/220] Fix #3081, client string encoding. --- libfreerdp/core/capabilities.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 46bc9986d..4ba120116 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -547,12 +547,12 @@ BOOL rdp_read_order_capability_set(wStream* s, UINT16 length, rdpSettings* setti * @param settings settings */ -BOOL rdp_write_order_capability_set(wStream* s, rdpSettings* settings) +static BOOL rdp_write_order_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 orderFlags; UINT16 orderSupportExFlags; - UINT16 textANSICodePage; + UINT16 textANSICodePage = 0; if (!Stream_EnsureRemainingCapacity(s, 64)) return FALSE; @@ -560,7 +560,8 @@ BOOL rdp_write_order_capability_set(wStream* s, rdpSettings* settings) header = rdp_capability_set_start(s); /* see [MSDN-CP]: http://msdn.microsoft.com/en-us/library/dd317756 */ - textANSICodePage = 65001; /* Unicode (UTF-8) */ + if (!settings->ServerMode) + textANSICodePage = 65001; /* Unicode (UTF-8) */ orderSupportExFlags = 0; orderFlags = NEGOTIATE_ORDER_SUPPORT | ZERO_BOUNDS_DELTA_SUPPORT | COLOR_INDEX_SUPPORT; @@ -592,7 +593,7 @@ BOOL rdp_write_order_capability_set(wStream* s, rdpSettings* settings) Stream_Write_UINT32(s, 230400); /* desktopSaveSize (4 bytes) */ Stream_Write_UINT16(s, 0); /* pad2OctetsC (2 bytes) */ Stream_Write_UINT16(s, 0); /* pad2OctetsD (2 bytes) */ - Stream_Write_UINT16(s, 0); /* textANSICodePage (2 bytes) */ + Stream_Write_UINT16(s, textANSICodePage); /* textANSICodePage (2 bytes) */ Stream_Write_UINT16(s, 0); /* pad2OctetsE (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_ORDER); From 06adbc971a9aa5c341f7ec0288588fa41e848657 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 27 Jan 2016 11:21:04 +0100 Subject: [PATCH 174/220] Fixed realloc check, renamed filter variable. --- winpr/libwinpr/utils/wlog/wlog.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 7d74cf67c..4553dcdb2 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -325,7 +325,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter) DWORD count; DWORD status; LPSTR p; - LPSTR s; + LPSTR filterStr; LPSTR cp; wLogFilter* tmp; @@ -346,10 +346,8 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter) tmp = (wLogFilter*) realloc(g_Filters, size * sizeof(wLogFilter)); if (!tmp) - { - free (g_Filters); return FALSE; - } + g_Filters = tmp; cp = (LPSTR)_strdup(filter); @@ -357,7 +355,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter) return FALSE; p = cp; - s = cp; + filterStr = cp; do { @@ -367,7 +365,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter) if (pos < size) { - status = WLog_ParseFilter(&g_Filters[pos++], s); + status = WLog_ParseFilter(&g_Filters[pos++], filterStr); if (status < 0) { free (cp); @@ -379,7 +377,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter) if (p) { - s = p + 1; + filterStr = p + 1; p++; } } From e08ca73ddcf2a4d8dcbb747c92629b54547eb687 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 27 Jan 2016 19:26:52 +0100 Subject: [PATCH 175/220] Improved error checks. --- channels/rdpdr/client/rdpdr_capabilities.c | 101 ++++-- channels/rdpdr/client/rdpdr_main.c | 360 ++++++++++----------- 2 files changed, 246 insertions(+), 215 deletions(-) diff --git a/channels/rdpdr/client/rdpdr_capabilities.c b/channels/rdpdr/client/rdpdr_capabilities.c index 1198a53c9..4de411674 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.c +++ b/channels/rdpdr/client/rdpdr_capabilities.c @@ -60,12 +60,21 @@ static void rdpdr_write_general_capset(rdpdrPlugin* rdpdr, wStream* s) } /* Process device direction general capability set */ -static void rdpdr_process_general_capset(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_general_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return CHANNEL_RC_NO_BUFFER; + Stream_Read_UINT16(s, capabilityLength); + + if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + return CHANNEL_RC_NO_BUFFER; + Stream_Seek(s, capabilityLength - 4); + + return CHANNEL_RC_OK; } /* Output printer direction capability set */ @@ -75,12 +84,21 @@ static void rdpdr_write_printer_capset(rdpdrPlugin* rdpdr, wStream* s) } /* Process printer direction capability set */ -static void rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return CHANNEL_RC_NO_BUFFER; + Stream_Read_UINT16(s, capabilityLength); + + if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + return CHANNEL_RC_NO_BUFFER; + Stream_Seek(s, capabilityLength - 4); + + return CHANNEL_RC_OK; } /* Output port redirection capability set */ @@ -90,12 +108,21 @@ static void rdpdr_write_port_capset(rdpdrPlugin* rdpdr, wStream* s) } /* Process port redirection capability set */ -static void rdpdr_process_port_capset(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_port_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return CHANNEL_RC_NO_BUFFER; + Stream_Read_UINT16(s, capabilityLength); + + if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + return CHANNEL_RC_NO_BUFFER; + Stream_Seek(s, capabilityLength - 4); + + return CHANNEL_RC_OK; } /* Output drive redirection capability set */ @@ -105,12 +132,21 @@ static void rdpdr_write_drive_capset(rdpdrPlugin* rdpdr, wStream* s) } /* Process drive redirection capability set */ -static void rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return CHANNEL_RC_NO_BUFFER; + Stream_Read_UINT16(s, capabilityLength); + + if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + return CHANNEL_RC_NO_BUFFER; + Stream_Seek(s, capabilityLength - 4); + + return CHANNEL_RC_OK; } /* Output smart card redirection capability set */ @@ -120,55 +156,74 @@ static void rdpdr_write_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s) } /* Process smartcard redirection capability set */ -static void rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s) +static UINT rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return CHANNEL_RC_NO_BUFFER; + Stream_Read_UINT16(s, capabilityLength); + + if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + return CHANNEL_RC_NO_BUFFER; + Stream_Seek(s, capabilityLength - 4); + + return CHANNEL_RC_OK; } UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s) { + UINT status = CHANNEL_RC_OK; UINT16 i; UINT16 numCapabilities; UINT16 capabilityType; if (!rdpdr || !s) - return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_NULL_DATA; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, numCapabilities); Stream_Seek(s, 2); /* pad (2 bytes) */ + if (!Stream_EnsureRemainingCapacity(s, sizeof(UINT16) * numCapabilities)) + return CHANNEL_RC_NO_BUFFER; + for (i = 0; i < numCapabilities; i++) { Stream_Read_UINT16(s, capabilityType); switch (capabilityType) { - case CAP_GENERAL_TYPE: - rdpdr_process_general_capset(rdpdr, s); - break; + case CAP_GENERAL_TYPE: + status = rdpdr_process_general_capset(rdpdr, s); + break; - case CAP_PRINTER_TYPE: - rdpdr_process_printer_capset(rdpdr, s); - break; + case CAP_PRINTER_TYPE: + rdpdr_process_printer_capset(rdpdr, s); + break; - case CAP_PORT_TYPE: - rdpdr_process_port_capset(rdpdr, s); - break; + case CAP_PORT_TYPE: + rdpdr_process_port_capset(rdpdr, s); + break; - case CAP_DRIVE_TYPE: - rdpdr_process_drive_capset(rdpdr, s); - break; + case CAP_DRIVE_TYPE: + rdpdr_process_drive_capset(rdpdr, s); + break; - case CAP_SMARTCARD_TYPE: - rdpdr_process_smartcard_capset(rdpdr, s); - break; + case CAP_SMARTCARD_TYPE: + rdpdr_process_smartcard_capset(rdpdr, s); + break; - default: - break; + default: + break; } + + if (status != CHANNEL_RC_OK) + return status; } return CHANNEL_RC_OK; diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 9581ab0ae..ae097fa87 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -81,10 +81,7 @@ static UINT rdpdr_send_device_list_remove_request(rdpdrPlugin* rdpdr, UINT32 cou UINT32 i; wStream* s; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - - s = Stream_New(NULL, 256); + s = Stream_New(NULL, count * sizeof(UINT32) + 8); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); @@ -520,15 +517,15 @@ static void* drive_hotplug_thread_func(void* arg) struct timeval tv; int rv; UINT error; - DWORD status; + DWORD status; rdpdr = (rdpdrPlugin*) arg; if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) { WLog_ERR(TAG, "CreateEvent failed!"); - error = ERROR_INTERNAL_ERROR; - goto out; + error = ERROR_INTERNAL_ERROR; + goto out; } mfd = open("/proc/mounts", O_RDONLY, 0); @@ -536,8 +533,8 @@ static void* drive_hotplug_thread_func(void* arg) if (mfd < 0) { WLog_ERR(TAG, "ERROR: Unable to open /proc/mounts."); - error = ERROR_INTERNAL_ERROR; - goto out; + error = ERROR_INTERNAL_ERROR; + goto out; } FD_ZERO(&rfds); @@ -548,18 +545,18 @@ static void* drive_hotplug_thread_func(void* arg) if ((error = handle_hotplug(rdpdr))) { WLog_ERR(TAG, "handle_hotplug failed with error %lu!", error); - goto out; + goto out; } while ((rv = select(mfd+1, NULL, NULL, &rfds, &tv)) >= 0) { - status = WaitForSingleObject(rdpdr->stopEvent, 0); - if (status == WAIT_FAILED) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); - goto out; - } + status = WaitForSingleObject(rdpdr->stopEvent, 0); + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); + goto out; + } if (status == WAIT_OBJECT_0) break; @@ -569,7 +566,7 @@ static void* drive_hotplug_thread_func(void* arg) if ((error = handle_hotplug(rdpdr))) { WLog_ERR(TAG, "handle_hotplug failed with error %lu!", error); - goto out; + goto out; } } @@ -580,11 +577,11 @@ static void* drive_hotplug_thread_func(void* arg) } out: - if (error && rdpdr->rdpcontext) - setChannelError(rdpdr->rdpcontext, error, "drive_hotplug_thread_func reported an error"); + if (error && rdpdr->rdpcontext) + setChannelError(rdpdr->rdpcontext, error, "drive_hotplug_thread_func reported an error"); - ExitThread((DWORD)error); - return NULL; + ExitThread((DWORD)error); + return NULL; } /** @@ -594,10 +591,7 @@ out: */ static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr) { - UINT error; - - if (!rdpdr) - return ERROR_INVALID_PARAMETER; + UINT error; if (rdpdr->hotplugThread) { @@ -605,14 +599,14 @@ static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr) SetEvent(rdpdr->stopEvent); if (WaitForSingleObject(rdpdr->hotplugThread, INFINITE) == WAIT_FAILED) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); - return error; - } + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); + return error; + } rdpdr->hotplugThread = NULL; } - return CHANNEL_RC_OK; + return CHANNEL_RC_OK; } #endif @@ -630,9 +624,6 @@ static UINT rdpdr_process_connect(rdpdrPlugin* rdpdr) rdpSettings* settings; UINT error = CHANNEL_RC_OK; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - rdpdr->devman = devman_new(rdpdr); if (!rdpdr->devman) { @@ -673,8 +664,8 @@ static UINT rdpdr_process_connect(rdpdrPlugin* rdpdr) static UINT rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, wStream* s) { - if (!rdpdr || !s) - return ERROR_INVALID_PARAMETER; + if (!Stream_EnsureRemainingCapacity(s, 8)) + return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, rdpdr->versionMajor); Stream_Read_UINT16(s, rdpdr->versionMinor); @@ -694,14 +685,11 @@ static UINT rdpdr_send_client_announce_reply(rdpdrPlugin* rdpdr) { wStream* s; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - s = Stream_New(NULL, 12); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); - return CHANNEL_RC_OK; + return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, RDPDR_CTYP_CORE); /* Component (2 bytes) */ @@ -725,9 +713,6 @@ static UINT rdpdr_send_client_name_request(rdpdrPlugin* rdpdr) WCHAR* computerNameW = NULL; size_t computerNameLenW; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - if (!rdpdr->computerName[0]) gethostname(rdpdr->computerName, sizeof(rdpdr->computerName) - 1); @@ -760,8 +745,8 @@ static UINT rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, wStream* s UINT16 versionMinor; UINT32 clientID; - if (!rdpdr || !s) - return ERROR_INVALID_PARAMETER; + if (!Stream_EnsureRemainingCapacity(s, 8)) + return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, versionMajor); Stream_Read_UINT16(s, versionMinor); @@ -798,9 +783,6 @@ static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use int keyCount; ULONG_PTR* pKeys; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - s = Stream_New(NULL, 256); if (!s) { @@ -831,7 +813,7 @@ static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use */ if ((rdpdr->versionMinor == 0x0005) || - (device->type == RDPDR_DTYP_SMARTCARD) || userLoggedOn) + (device->type == RDPDR_DTYP_SMARTCARD) || userLoggedOn) { data_len = (int) (device->data == NULL ? 0 : Stream_GetPosition(device->data)); if (!Stream_EnsureRemainingCapacity(s, 20 + data_len)) @@ -886,9 +868,6 @@ static UINT rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s) IRP* irp; UINT error = CHANNEL_RC_OK; - if (!rdpdr || !s) - return ERROR_INVALID_PARAMETER; - irp = irp_new(rdpdr->devman, s); if (!irp) @@ -899,10 +878,10 @@ static UINT rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s) IFCALLRET(irp->device->IRPRequest, error, irp->device, irp); - if (error) - WLog_ERR(TAG, "device->IRPRequest failed with error %lu", error); + if (error) + WLog_ERR(TAG, "device->IRPRequest failed with error %lu", error); - return error; + return error; } /** @@ -918,9 +897,6 @@ static UINT rdpdr_process_init(rdpdrPlugin* rdpdr) ULONG_PTR* pKeys; UINT error = CHANNEL_RC_OK; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - pKeys = NULL; keyCount = ListDictionary_GetKeys(rdpdr->devman->devices, &pKeys); @@ -955,7 +931,10 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) UINT error; if (!rdpdr || !s) - return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_NULL_DATA; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, component); /* Component (2 bytes) */ Stream_Read_UINT16(s, packetId); /* PacketId (2 bytes) */ @@ -964,74 +943,77 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) { switch (packetId) { - case PAKID_CORE_SERVER_ANNOUNCE: - if ((error = rdpdr_process_server_announce_request(rdpdr, s))) - return error; - if ((error = rdpdr_send_client_announce_reply(rdpdr))) - { - WLog_ERR(TAG, "rdpdr_send_client_announce_reply failed with error %lu", error); - return error; - } - if ((error = rdpdr_send_client_name_request(rdpdr))) - { - WLog_ERR(TAG, "rdpdr_send_client_name_request failed with error %lu", error); - return error; - } - if ((error = rdpdr_process_init(rdpdr))) - { - WLog_ERR(TAG, "rdpdr_process_init failed with error %lu", error); - return error; - } - break; + case PAKID_CORE_SERVER_ANNOUNCE: + if ((error = rdpdr_process_server_announce_request(rdpdr, s))) + return error; + if ((error = rdpdr_send_client_announce_reply(rdpdr))) + { + WLog_ERR(TAG, "rdpdr_send_client_announce_reply failed with error %lu", error); + return error; + } + if ((error = rdpdr_send_client_name_request(rdpdr))) + { + WLog_ERR(TAG, "rdpdr_send_client_name_request failed with error %lu", error); + return error; + } + if ((error = rdpdr_process_init(rdpdr))) + { + WLog_ERR(TAG, "rdpdr_process_init failed with error %lu", error); + return error; + } + break; - case PAKID_CORE_SERVER_CAPABILITY: - if ((error = rdpdr_process_capability_request(rdpdr, s))) - return error; - if ((error = rdpdr_send_capability_response(rdpdr))) - { - WLog_ERR(TAG, "rdpdr_send_capability_response failed with error %lu", error); - return error; - } - break; + case PAKID_CORE_SERVER_CAPABILITY: + if ((error = rdpdr_process_capability_request(rdpdr, s))) + return error; + if ((error = rdpdr_send_capability_response(rdpdr))) + { + WLog_ERR(TAG, "rdpdr_send_capability_response failed with error %lu", error); + return error; + } + break; - case PAKID_CORE_CLIENTID_CONFIRM: - if ((error = rdpdr_process_server_clientid_confirm(rdpdr, s))) - return error; + case PAKID_CORE_CLIENTID_CONFIRM: + if ((error = rdpdr_process_server_clientid_confirm(rdpdr, s))) + return error; - if ((error = rdpdr_send_device_list_announce_request(rdpdr, FALSE))) - { - WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu", error); - return error; - } - break; + if ((error = rdpdr_send_device_list_announce_request(rdpdr, FALSE))) + { + WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu", error); + return error; + } + break; - case PAKID_CORE_USER_LOGGEDON: - if ((error = rdpdr_send_device_list_announce_request(rdpdr, TRUE))) - { - WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu", error); - return error; - } - break; + case PAKID_CORE_USER_LOGGEDON: + if ((error = rdpdr_send_device_list_announce_request(rdpdr, TRUE))) + { + WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu", error); + return error; + } + break; - case PAKID_CORE_DEVICE_REPLY: - /* connect to a specific resource */ - Stream_Read_UINT32(s, deviceId); - Stream_Read_UINT32(s, status); - break; + case PAKID_CORE_DEVICE_REPLY: + /* connect to a specific resource */ + if (Stream_EnsureRemainingCapacity(s, 8)) + return CHANNEL_RC_NO_BUFFER; - case PAKID_CORE_DEVICE_IOREQUEST: - if ((error = rdpdr_process_irp(rdpdr, s))) - { - WLog_ERR(TAG, "rdpdr_process_irp failed with error %lu", error); - return error; - } - s = NULL; - break; + Stream_Read_UINT32(s, deviceId); + Stream_Read_UINT32(s, status); + break; - default: - WLog_ERR(TAG, "RDPDR_CTYP_CORE unknown PacketId: 0x%04X", packetId); - return ERROR_INVALID_DATA; - break; + case PAKID_CORE_DEVICE_IOREQUEST: + if ((error = rdpdr_process_irp(rdpdr, s))) + { + WLog_ERR(TAG, "rdpdr_process_irp failed with error %lu", error); + return error; + } + s = NULL; + break; + + default: + WLog_ERR(TAG, "RDPDR_CTYP_CORE unknown PacketId: 0x%04X", packetId); + return ERROR_INVALID_DATA; + break; } } @@ -1039,21 +1021,24 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) { switch (packetId) { - case PAKID_PRN_CACHE_DATA: - { - UINT32 eventID; - Stream_Read_UINT32(s, eventID); - WLog_ERR(TAG, "Ignoring unhandled message PAKID_PRN_CACHE_DATA (EventID: 0x%04X)", eventID); - } - break; + case PAKID_PRN_CACHE_DATA: + { + UINT32 eventID; + if (Stream_EnsureRemainingCapacity(s, 4)) + return CHANNEL_RC_NO_BUFFER; - case PAKID_PRN_USING_XPS: - WLog_ERR(TAG, "Ignoring unhandled message PAKID_PRN_USING_XPS"); - break; + Stream_Read_UINT32(s, eventID); + WLog_ERR(TAG, "Ignoring unhandled message PAKID_PRN_CACHE_DATA (EventID: 0x%04X)", eventID); + } + break; - default: - WLog_ERR(TAG, "Unknown printing component packetID: 0x%04X", packetId); - return ERROR_INVALID_DATA; + case PAKID_PRN_USING_XPS: + WLog_ERR(TAG, "Ignoring unhandled message PAKID_PRN_USING_XPS"); + break; + + default: + WLog_ERR(TAG, "Unknown printing component packetID: 0x%04X", packetId); + return ERROR_INVALID_DATA; } } else @@ -1173,14 +1158,14 @@ UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s) rdpdrPlugin* plugin = (rdpdrPlugin*) rdpdr; if (!rdpdr || !s) - return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_NULL_DATA; if (!plugin) status = CHANNEL_RC_BAD_INIT_HANDLE; else { status = plugin->channelEntryPoints.pVirtualChannelWrite(plugin->OpenHandle, - Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s); + Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s); } if (status != CHANNEL_RC_OK) @@ -1199,13 +1184,10 @@ UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s) * @return 0 on success, otherwise a Win32 error code */ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, - void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) + void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) { wStream* data_in; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) { /* @@ -1260,14 +1242,14 @@ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, } static VOID VCAPITYPE rdpdr_virtual_channel_open_event(DWORD openHandle, UINT event, - LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) + LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) { rdpdrPlugin* rdpdr; UINT error = CHANNEL_RC_OK; rdpdr = (rdpdrPlugin*) rdpdr_get_open_handle_data(openHandle); - if (!rdpdr) + if (!rdpdr || !pData) { WLog_ERR(TAG, "rdpdr_virtual_channel_open_event: error no match"); return; @@ -1275,17 +1257,17 @@ static VOID VCAPITYPE rdpdr_virtual_channel_open_event(DWORD openHandle, UINT ev switch (event) { - case CHANNEL_EVENT_DATA_RECEIVED: - if ((error = rdpdr_virtual_channel_event_data_received(rdpdr, pData, dataLength, totalLength, dataFlags))) - WLog_ERR(TAG, "rdpdr_virtual_channel_event_data_received failed with error %lu!", error ); - break; + case CHANNEL_EVENT_DATA_RECEIVED: + if ((error = rdpdr_virtual_channel_event_data_received(rdpdr, pData, dataLength, totalLength, dataFlags))) + WLog_ERR(TAG, "rdpdr_virtual_channel_event_data_received failed with error %lu!", error ); + break; - case CHANNEL_EVENT_WRITE_COMPLETE: - Stream_Free((wStream*) pData, TRUE); - break; + case CHANNEL_EVENT_WRITE_COMPLETE: + Stream_Free((wStream*) pData, TRUE); + break; - case CHANNEL_EVENT_USER: - break; + case CHANNEL_EVENT_USER: + break; } if (error && rdpdr->rdpcontext) setChannelError(rdpdr->rdpcontext, error, "rdpdr_virtual_channel_open_event reported an error"); @@ -1302,7 +1284,7 @@ static void* rdpdr_virtual_channel_client_thread(void* arg) if (!rdpdr) { - ExitThread((DWORD) ERROR_INVALID_PARAMETER); + ExitThread((DWORD) CHANNEL_RC_NULL_DATA); return NULL; } @@ -1354,20 +1336,17 @@ static UINT rdpdr_virtual_channel_event_connected(rdpdrPlugin* rdpdr, LPVOID pDa UINT32 status; UINT error; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - status = rdpdr->channelEntryPoints.pVirtualChannelOpen(rdpdr->InitHandle, - &rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event); + &rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event); - if (status != CHANNEL_RC_OK) - { - WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]", - WTSErrorToString(status), status); - return status; - } + if (status != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]", + WTSErrorToString(status), status); + return status; + } - if ((error = rdpdr_add_open_handle_data(rdpdr->OpenHandle, rdpdr))) + if ((error = rdpdr_add_open_handle_data(rdpdr->OpenHandle, rdpdr))) { WLog_ERR(TAG, "rdpdr_add_open_handle_data failed with error %lu!", error); return error; @@ -1398,15 +1377,12 @@ static UINT rdpdr_virtual_channel_event_disconnected(rdpdrPlugin* rdpdr) { UINT error; - if (!rdpdr) - return ERROR_INVALID_PARAMETER; - if (MessageQueue_PostQuit(rdpdr->queue, 0) && (WaitForSingleObject(rdpdr->thread, INFINITE) == WAIT_FAILED)) - { - error = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); - return error; - } + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); + return error; + } MessageQueue_Free(rdpdr->queue); CloseHandle(rdpdr->thread); @@ -1415,10 +1391,10 @@ static UINT rdpdr_virtual_channel_event_disconnected(rdpdrPlugin* rdpdr) rdpdr->thread = NULL; if ((error = drive_hotplug_thread_terminate(rdpdr))) - { - WLog_ERR(TAG, "drive_hotplug_thread_terminate failed with error %lu!", error); - return error; - } + { + WLog_ERR(TAG, "drive_hotplug_thread_terminate failed with error %lu!", error); + return error; + } error = rdpdr->channelEntryPoints.pVirtualChannelClose(rdpdr->OpenHandle); if (CHANNEL_RC_OK != error) @@ -1465,25 +1441,25 @@ static VOID VCAPITYPE rdpdr_virtual_channel_init_event(LPVOID pInitHandle, UINT switch (event) { - case CHANNEL_EVENT_INITIALIZED: - break; - case CHANNEL_EVENT_CONNECTED: - if ((error = rdpdr_virtual_channel_event_connected(rdpdr, pData, dataLength))) - WLog_ERR(TAG, "rdpdr_virtual_channel_event_connected failed with error %lu!", error); - break; + case CHANNEL_EVENT_INITIALIZED: + break; + case CHANNEL_EVENT_CONNECTED: + if ((error = rdpdr_virtual_channel_event_connected(rdpdr, pData, dataLength))) + WLog_ERR(TAG, "rdpdr_virtual_channel_event_connected failed with error %lu!", error); + break; - case CHANNEL_EVENT_DISCONNECTED: - if ((error = rdpdr_virtual_channel_event_disconnected(rdpdr))) - WLog_ERR(TAG, "rdpdr_virtual_channel_event_disconnected failed with error %lu!", error); - break; + case CHANNEL_EVENT_DISCONNECTED: + if ((error = rdpdr_virtual_channel_event_disconnected(rdpdr))) + WLog_ERR(TAG, "rdpdr_virtual_channel_event_disconnected failed with error %lu!", error); + break; - case CHANNEL_EVENT_TERMINATED: - rdpdr_virtual_channel_event_terminated(rdpdr); - break; - default: - WLog_ERR(TAG, "unknown event %d!", event); - error = ERROR_INVALID_DATA; - break; + case CHANNEL_EVENT_TERMINATED: + rdpdr_virtual_channel_event_terminated(rdpdr); + break; + default: + WLog_ERR(TAG, "unknown event %d!", event); + error = ERROR_INVALID_DATA; + break; } if (error && rdpdr->rdpcontext) From 3d22cbe2b835bad04f2e6305aa9020ee4cc0361f Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Wed, 13 Jan 2016 15:09:03 -0800 Subject: [PATCH 176/220] Fix png image loading that needed write access --- winpr/libwinpr/utils/image.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/image.c b/winpr/libwinpr/utils/image.c index ea8bc97ac..ece386787 100644 --- a/winpr/libwinpr/utils/image.c +++ b/winpr/libwinpr/utils/image.c @@ -3,6 +3,8 @@ * Image Utils * * Copyright 2014 Marc-Andre Moreau + * Copyright 2016 Inuvika Inc. + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -308,7 +310,7 @@ int winpr_image_read(wImage* image, const char* filename) BYTE sig[8]; int status = -1; - fp = fopen(filename, "r+b"); + fp = fopen(filename, "rb"); if (!fp) { From 62a559ad03293217d66babdd1c7c3db57971230d Mon Sep 17 00:00:00 2001 From: clangm Date: Wed, 27 Jan 2016 15:40:08 -0700 Subject: [PATCH 177/220] fix typo Pretty sure that's supposed to be __MACOSX__, not __MAXOSX__ --- winpr/libwinpr/smartcard/smartcard_pcsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 5256828f9..34cfc88a8 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -1996,7 +1996,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard, { if (pcchReaderLenAlloc) { -#ifdef __MAXOSX__ +#ifdef __MACOSX__ /** * Workaround for SCardStatus Bug in MAC OS X Yosemite */ From 57f1e26f36af5c5bf02d21043617c9769dda0225 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 28 Jan 2016 11:12:20 +0100 Subject: [PATCH 178/220] Checking capability read return. Updated copyright headers. --- channels/rdpdr/client/rdpdr_capabilities.c | 11 ++++++----- channels/rdpdr/client/rdpdr_main.c | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/channels/rdpdr/client/rdpdr_capabilities.c b/channels/rdpdr/client/rdpdr_capabilities.c index 4de411674..4a64f98b6 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.c +++ b/channels/rdpdr/client/rdpdr_capabilities.c @@ -4,8 +4,9 @@ * * Copyright 2010-2011 Vic Lee * Copyright 2010-2012 Marc-Andre Moreau - * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015-2016 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -203,19 +204,19 @@ UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s) break; case CAP_PRINTER_TYPE: - rdpdr_process_printer_capset(rdpdr, s); + status = rdpdr_process_printer_capset(rdpdr, s); break; case CAP_PORT_TYPE: - rdpdr_process_port_capset(rdpdr, s); + status = rdpdr_process_port_capset(rdpdr, s); break; case CAP_DRIVE_TYPE: - rdpdr_process_drive_capset(rdpdr, s); + status = rdpdr_process_drive_capset(rdpdr, s); break; case CAP_SMARTCARD_TYPE: - rdpdr_process_smartcard_capset(rdpdr, s); + status = rdpdr_process_smartcard_capset(rdpdr, s); break; default: diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index ae097fa87..da26ca184 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -4,8 +4,9 @@ * * Copyright 2010-2011 Vic Lee * Copyright 2010-2012 Marc-Andre Moreau - * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015-2016 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 8595e395ab661bbe38f072b0dae331cf8b34c316 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 28 Jan 2016 11:45:06 +0100 Subject: [PATCH 179/220] Fixed size checks (thanks to @virtman) --- channels/drdynvc/client/drdynvc_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index 83e8497b8..29111fde8 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -728,7 +728,7 @@ UINT drdynvc_send(drdynvcPlugin* drdynvc, wStream* s) UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, BYTE* data, UINT32 dataSize) { wStream* data_out; - unsigned long pos = 0; + unsigned long pos; UINT32 cbChId; UINT32 cbLen; unsigned long chunkLength; @@ -747,9 +747,9 @@ UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, BYTE* data, UI Stream_SetPosition(data_out, 1); cbChId = drdynvc_write_variable_uint(data_out, ChannelId); + pos = Stream_GetPosition(data_out); if (dataSize == 0) { - pos = Stream_GetPosition(data_out); Stream_SetPosition(data_out, 0); Stream_Write_UINT8(data_out, 0x40 | cbChId); Stream_SetPosition(data_out, pos); @@ -758,7 +758,6 @@ UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, BYTE* data, UI } else if (dataSize <= CHANNEL_CHUNK_LENGTH - pos) { - pos = Stream_GetPosition(data_out); Stream_SetPosition(data_out, 0); Stream_Write_UINT8(data_out, 0x30 | cbChId); Stream_SetPosition(data_out, pos); From 6f50589c05cdda12c01eba3815a4f28c516eecf0 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 28 Jan 2016 12:05:14 +0100 Subject: [PATCH 180/220] Cleared up error code usage. --- channels/rdpdr/client/irp.c | 21 +++++++++++++++++++-- channels/rdpdr/client/irp.h | 2 +- channels/rdpdr/client/rdpdr_main.c | 11 +++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/channels/rdpdr/client/irp.c b/channels/rdpdr/client/irp.c index 2d1f96506..899b89a9f 100644 --- a/channels/rdpdr/client/irp.c +++ b/channels/rdpdr/client/irp.c @@ -77,18 +77,28 @@ static UINT irp_complete(IRP* irp) return error; } -IRP* irp_new(DEVMAN* devman, wStream* s) +IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error) { IRP* irp; DEVICE* device; UINT32 DeviceId; + if (!Stream_EnsureRemainingCapacity(s, 20)) + { + if (error) + *error = CHANNEL_RC_NO_BUFFER; + return NULL; + } + Stream_Read_UINT32(s, DeviceId); /* DeviceId (4 bytes) */ device = devman_get_device_by_id(devman, DeviceId); if (!device) { - WLog_ERR(TAG, "devman_get_device_by_id failed!"); + WLog_WARN(TAG, "devman_get_device_by_id failed!"); + if (error) + *error = CHANNEL_RC_OK; + return NULL; }; @@ -97,6 +107,8 @@ IRP* irp_new(DEVMAN* devman, wStream* s) if (!irp) { WLog_ERR(TAG, "_aligned_malloc failed!"); + if (error) + *error = CHANNEL_RC_NO_MEMORY; return NULL; } @@ -117,6 +129,8 @@ IRP* irp_new(DEVMAN* devman, wStream* s) { WLog_ERR(TAG, "Stream_New failed!"); _aligned_free(irp); + if (error) + *error = CHANNEL_RC_NO_MEMORY; return NULL; } Stream_Write_UINT16(irp->output, RDPDR_CTYP_CORE); /* Component (2 bytes) */ @@ -131,5 +145,8 @@ IRP* irp_new(DEVMAN* devman, wStream* s) irp->thread = NULL; irp->cancelled = FALSE; + if (error) + *error = CHANNEL_RC_OK; + return irp; } diff --git a/channels/rdpdr/client/irp.h b/channels/rdpdr/client/irp.h index d94366373..17d75acde 100644 --- a/channels/rdpdr/client/irp.h +++ b/channels/rdpdr/client/irp.h @@ -23,6 +23,6 @@ #include "rdpdr_main.h" -IRP* irp_new(DEVMAN* devman, wStream* s); +IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error); #endif /* FREERDP_CHANNEL_RDPDR_CLIENT_IRP_H */ diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index da26ca184..3378f92bc 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -497,7 +497,6 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr) free(drive->Path); free(drive->Name); free(drive); - error = CHANNEL_RC_NO_MEMORY; goto cleanup; } } @@ -820,7 +819,7 @@ static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use if (!Stream_EnsureRemainingCapacity(s, 20 + data_len)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); - return CHANNEL_RC_NO_MEMORY; + return CHANNEL_RC_NO_BUFFER; } Stream_Write_UINT32(s, device->type); /* deviceType */ @@ -869,12 +868,12 @@ static UINT rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s) IRP* irp; UINT error = CHANNEL_RC_OK; - irp = irp_new(rdpdr->devman, s); + irp = irp_new(rdpdr->devman, s, &error); if (!irp) { - WLog_ERR(TAG, "irp_new failed!"); - return CHANNEL_RC_NO_MEMORY; + WLog_ERR(TAG, "irp_new failed with %lu!", error); + return error; } IFCALLRET(irp->device->IRPRequest, error, irp->device, irp); @@ -1217,7 +1216,7 @@ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, if (!Stream_EnsureRemainingCapacity(data_in, (int) dataLength)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); - return CHANNEL_RC_NO_MEMORY; + return CHANNEL_RC_NO_BUFFER; } Stream_Write(data_in, pData, dataLength); From c2515340c304e7e5d4107f51abac2d3b60d57cf0 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 28 Jan 2016 12:08:57 +0100 Subject: [PATCH 181/220] Fixed return value of WLog_FileAppender_WriteImageMessage --- winpr/libwinpr/utils/wlog/FileAppender.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index 576841611..8c921283a 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -172,7 +172,7 @@ static BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogAppender* appender static int g_ImageId = 0; -static int WLog_FileAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) +static BOOL WLog_FileAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { int ImageId; char* FullFileName; From d847993a0c3fb26147a3d652a97336a5656b5343 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 28 Jan 2016 12:25:44 +0100 Subject: [PATCH 182/220] Using Stream_ReminingLength for read checks. --- channels/rdpdr/client/irp.c | 2 +- channels/rdpdr/client/rdpdr_capabilities.c | 24 +++++++++++----------- channels/rdpdr/client/rdpdr_main.c | 10 ++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/channels/rdpdr/client/irp.c b/channels/rdpdr/client/irp.c index 899b89a9f..d98870d9d 100644 --- a/channels/rdpdr/client/irp.c +++ b/channels/rdpdr/client/irp.c @@ -83,7 +83,7 @@ IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error) DEVICE* device; UINT32 DeviceId; - if (!Stream_EnsureRemainingCapacity(s, 20)) + if (Stream_GetRemainingLength(s) < 20) { if (error) *error = CHANNEL_RC_NO_BUFFER; diff --git a/channels/rdpdr/client/rdpdr_capabilities.c b/channels/rdpdr/client/rdpdr_capabilities.c index 4a64f98b6..4dba231e2 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.c +++ b/channels/rdpdr/client/rdpdr_capabilities.c @@ -65,12 +65,12 @@ static UINT rdpdr_process_general_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; - if (!Stream_EnsureRemainingCapacity(s, 2)) + if (Stream_GetRemainingLength(s) < 2) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, capabilityLength); - if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + if (Stream_GetRemainingLength(s) < capabilityLength - 4) return CHANNEL_RC_NO_BUFFER; Stream_Seek(s, capabilityLength - 4); @@ -89,12 +89,12 @@ static UINT rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; - if (!Stream_EnsureRemainingCapacity(s, 2)) + if (Stream_GetRemainingLength(s) < 2) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, capabilityLength); - if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + if (Stream_GetRemainingLength(s) < capabilityLength - 4) return CHANNEL_RC_NO_BUFFER; Stream_Seek(s, capabilityLength - 4); @@ -113,12 +113,12 @@ static UINT rdpdr_process_port_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; - if (!Stream_EnsureRemainingCapacity(s, 2)) + if (Stream_GetRemainingLength(s) < 2) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, capabilityLength); - if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + if (Stream_GetRemainingLength(s) < capabilityLength - 4) return CHANNEL_RC_NO_BUFFER; Stream_Seek(s, capabilityLength - 4); @@ -137,12 +137,12 @@ static UINT rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; - if (!Stream_EnsureRemainingCapacity(s, 2)) + if (Stream_GetRemainingLength(s) < 2) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, capabilityLength); - if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + if (Stream_GetRemainingLength(s) < capabilityLength - 4) return CHANNEL_RC_NO_BUFFER; Stream_Seek(s, capabilityLength - 4); @@ -161,12 +161,12 @@ static UINT rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s) { UINT16 capabilityLength; - if (!Stream_EnsureRemainingCapacity(s, 2)) + if (Stream_GetRemainingLength(s) < 2) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, capabilityLength); - if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4)) + if (Stream_GetRemainingLength(s) < capabilityLength - 4) return CHANNEL_RC_NO_BUFFER; Stream_Seek(s, capabilityLength - 4); @@ -184,13 +184,13 @@ UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s) if (!rdpdr || !s) return CHANNEL_RC_NULL_DATA; - if (!Stream_EnsureRemainingCapacity(s, 4)) + if (Stream_GetRemainingLength(s) < 4) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, numCapabilities); Stream_Seek(s, 2); /* pad (2 bytes) */ - if (!Stream_EnsureRemainingCapacity(s, sizeof(UINT16) * numCapabilities)) + if (Stream_GetRemainingLength(s) < sizeof(UINT16) * numCapabilities) return CHANNEL_RC_NO_BUFFER; for (i = 0; i < numCapabilities; i++) diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 3378f92bc..62da00b51 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -664,7 +664,7 @@ static UINT rdpdr_process_connect(rdpdrPlugin* rdpdr) static UINT rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, wStream* s) { - if (!Stream_EnsureRemainingCapacity(s, 8)) + if (Stream_GetRemainingLength(s) < 8) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, rdpdr->versionMajor); @@ -745,7 +745,7 @@ static UINT rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, wStream* s UINT16 versionMinor; UINT32 clientID; - if (!Stream_EnsureRemainingCapacity(s, 8)) + if (Stream_GetRemainingLength(s) < 8) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, versionMajor); @@ -933,7 +933,7 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) if (!rdpdr || !s) return CHANNEL_RC_NULL_DATA; - if (!Stream_EnsureRemainingCapacity(s, 4)) + if (Stream_GetRemainingLength(s) < 4) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT16(s, component); /* Component (2 bytes) */ @@ -994,7 +994,7 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) case PAKID_CORE_DEVICE_REPLY: /* connect to a specific resource */ - if (Stream_EnsureRemainingCapacity(s, 8)) + if (Stream_GetRemainingLength(s) < 8) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT32(s, deviceId); @@ -1024,7 +1024,7 @@ static UINT rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s) case PAKID_PRN_CACHE_DATA: { UINT32 eventID; - if (Stream_EnsureRemainingCapacity(s, 4)) + if (Stream_GetRemainingLength(s) < 4) return CHANNEL_RC_NO_BUFFER; Stream_Read_UINT32(s, eventID); From 035f127081c3e911b55fe8232f6f19261ccef910 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 28 Jan 2016 14:26:50 +0100 Subject: [PATCH 183/220] Added get_build_config functions. --- client/common/cmdline.c | 7 +------ include/freerdp/freerdp.h | 1 + libfreerdp/core/freerdp.c | 17 ++++++++++++++--- libfreerdp/core/test/TestVersion.c | 4 ++++ winpr/include/winpr/winpr.h | 1 + winpr/libwinpr/utils/test/TestVersion.c | 4 ++++ winpr/libwinpr/utils/winpr.c | 17 ++++++++++++++--- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 42fa8d14b..6d1c46890 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -21,7 +21,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "buildflags.h" #include @@ -187,11 +186,7 @@ int freerdp_client_print_version() int freerdp_client_print_buildconfig() { - printf("Build configuration: %s\n", BUILD_CONFIG); - printf("Build type: %s\n", BUILD_TYPE); - printf("CFLAGS: %s\n", CFLAGS); - printf("Compiler: %s, %s\n", COMPILER_ID, COMPILER_VERSION); - printf("Target architecture: %s\n", TARGET_ARCH); + printf("%s", freerdp_get_build_config()); return 1; } diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index d2db002fa..cbc539887 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -272,6 +272,7 @@ FREERDP_API void freerdp_get_version(int* major, int* minor, int* revision); FREERDP_API const char* freerdp_get_version_string(void); FREERDP_API const char* freerdp_get_build_date(void); FREERDP_API const char* freerdp_get_build_revision(void); +FREERDP_API const char* freerdp_get_build_config(void); FREERDP_API freerdp* freerdp_new(void); FREERDP_API void freerdp_free(freerdp* instance); diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index cce07fe3b..18c2f56d1 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -30,6 +30,7 @@ #include "transport.h" #include "connection.h" #include "message.h" +#include "buildflags.h" #include @@ -438,13 +439,23 @@ const char* freerdp_get_version_string(void) const char* freerdp_get_build_date(void) { - static char build_date[64]; - - sprintf_s(build_date, sizeof(build_date), "%s %s", __DATE__, __TIME__); + static char build_date[] = __DATE__ " " __TIME__; return build_date; } +const char* freerdp_get_build_config(void) +{ + static const char build_config[] = + "Build configuration: " BUILD_CONFIG "\n" + "Build type: " BUILD_TYPE "\n" + "CFLAGS: " CFLAGS "\n" + "Compiler: " COMPILER_ID ", " COMPILER_VERSION "\n" + "Target architecture: " TARGET_ARCH "\n"; + + return build_config; +} + const char* freerdp_get_build_revision(void) { return GIT_REVISION; diff --git a/libfreerdp/core/test/TestVersion.c b/libfreerdp/core/test/TestVersion.c index 3203088c0..146e81f1b 100644 --- a/libfreerdp/core/test/TestVersion.c +++ b/libfreerdp/core/test/TestVersion.c @@ -33,6 +33,10 @@ int TestVersion(int argc, char* argv[]) if (!build) return -1; + build = freerdp_get_build_config(); + if (!build) + return -1; + return 0; } diff --git a/winpr/include/winpr/winpr.h b/winpr/include/winpr/winpr.h index 87cc17d1c..4e9250974 100644 --- a/winpr/include/winpr/winpr.h +++ b/winpr/include/winpr/winpr.h @@ -51,5 +51,6 @@ WINPR_API void winpr_get_version(int* major, int* minor, int* revision); WINPR_API const char* winpr_get_version_string(void); WINPR_API const char* winpr_get_build_date(void); WINPR_API const char* winpr_get_build_revision(void); +WINPR_API const char* winpr_get_build_config(void); #endif /* WINPR_H */ diff --git a/winpr/libwinpr/utils/test/TestVersion.c b/winpr/libwinpr/utils/test/TestVersion.c index cef572892..60c4f900b 100644 --- a/winpr/libwinpr/utils/test/TestVersion.c +++ b/winpr/libwinpr/utils/test/TestVersion.c @@ -36,6 +36,10 @@ int TestVersion(int argc, char* argv[]) if (!build) return -1; + build = winpr_get_build_config(); + if (!build) + return -1; + return 0; } diff --git a/winpr/libwinpr/utils/winpr.c b/winpr/libwinpr/utils/winpr.c index e6dbd9056..409368998 100644 --- a/winpr/libwinpr/utils/winpr.c +++ b/winpr/libwinpr/utils/winpr.c @@ -22,6 +22,8 @@ #include "config.h" #endif +#include "buildflags.h" + #include #include #include @@ -46,9 +48,7 @@ const char* winpr_get_version_string(void) const char* winpr_get_build_date(void) { - static char build_date[64]; - - sprintf_s(build_date, sizeof(build_date), "%s %s", __DATE__, __TIME__); + static char build_date[] = __DATE__ " " __TIME__; return build_date; } @@ -58,3 +58,14 @@ const char* winpr_get_build_revision(void) return GIT_REVISION; } +const char* winpr_get_build_config(void) +{ + static const char build_config[] = + "Build configuration: " BUILD_CONFIG "\n" + "Build type: " BUILD_TYPE "\n" + "CFLAGS: " CFLAGS "\n" + "Compiler: " COMPILER_ID ", " COMPILER_VERSION "\n" + "Target architecture: " TARGET_ARCH "\n"; + + return build_config; +} From b6dd7bbb886eb14565637e98be3cbf7df8496161 Mon Sep 17 00:00:00 2001 From: David FORT Date: Thu, 28 Jan 2016 15:12:26 +0100 Subject: [PATCH 184/220] Check more Stream_EnsureCapacity results when writing capabilities --- libfreerdp/core/capabilities.c | 63 ++++++++++++++++++++-------------- libfreerdp/core/capabilities.h | 2 +- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 01f1b1208..114cfd2ee 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -1689,11 +1689,12 @@ BOOL rdp_read_bitmap_cache_host_support_capability_set(wStream* s, UINT16 length * @param settings settings */ -void rdp_write_bitmap_cache_host_support_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_bitmap_cache_host_support_capability_set(wStream* s, rdpSettings* settings) { int header; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -1702,6 +1703,7 @@ void rdp_write_bitmap_cache_host_support_capability_set(wStream* s, rdpSettings* Stream_Write_UINT16(s, 0); /* pad2 (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE_HOST_SUPPORT); + return TRUE; } BOOL rdp_print_bitmap_cache_host_support_capability_set(wStream* s, UINT16 length) @@ -2053,13 +2055,14 @@ BOOL rdp_read_draw_gdiplus_cache_capability_set(wStream* s, UINT16 length, rdpSe * @param settings settings */ -void rdp_write_draw_gdiplus_cache_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_draw_gdiplus_cache_capability_set(wStream* s, rdpSettings* settings) { int header; UINT32 drawGDIPlusSupportLevel; UINT32 drawGdiplusCacheLevel; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; header = rdp_capability_set_start(s); @@ -2074,6 +2077,7 @@ void rdp_write_draw_gdiplus_cache_capability_set(wStream* s, rdpSettings* settin rdp_write_gdiplus_image_cache_properties(s, 4096, 256, 128); /* GdipImageCacheProperties (6 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_DRAW_GDI_PLUS); + return TRUE; } BOOL rdp_print_draw_gdiplus_cache_capability_set(wStream* s, UINT16 length) @@ -2256,12 +2260,13 @@ BOOL rdp_read_desktop_composition_capability_set(wStream* s, UINT16 length, rdpS * @param settings settings */ -void rdp_write_desktop_composition_capability_set(wStream* s, rdpSettings* settings) +BOOL rdp_write_desktop_composition_capability_set(wStream* s, rdpSettings* settings) { int header; UINT16 compDeskSupportLevel; - Stream_EnsureRemainingCapacity(s, 32); + if (!Stream_EnsureRemainingCapacity(s, 32)) + return FALSE; header = rdp_capability_set_start(s); @@ -2270,6 +2275,7 @@ void rdp_write_desktop_composition_capability_set(wStream* s, rdpSettings* setti Stream_Write_UINT16(s, compDeskSupportLevel); /* compDeskSupportLevel (2 bytes) */ rdp_capability_set_finish(s, header, CAPSET_TYPE_COMP_DESK); + return TRUE; } BOOL rdp_print_desktop_composition_capability_set(wStream* s, UINT16 length) @@ -3748,13 +3754,14 @@ BOOL rdp_recv_demand_active(rdpRdp* rdp, wStream* s) return TRUE; } -void rdp_write_demand_active(wStream* s, rdpSettings* settings) +BOOL rdp_write_demand_active(wStream* s, rdpSettings* settings) { int bm, em, lm; UINT16 numberCapabilities; UINT16 lengthCombinedCapabilities; - Stream_EnsureRemainingCapacity(s, 64); + if (!Stream_EnsureRemainingCapacity(s, 64)) + return FALSE; Stream_Write_UINT32(s, settings->ShareId); /* shareId (4 bytes) */ Stream_Write_UINT16(s, 4); /* lengthSourceDescriptor (2 bytes) */ @@ -3768,25 +3775,29 @@ void rdp_write_demand_active(wStream* s, rdpSettings* settings) Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ numberCapabilities = 14; - rdp_write_general_capability_set(s, settings); - rdp_write_bitmap_capability_set(s, settings); - rdp_write_order_capability_set(s, settings); - rdp_write_pointer_capability_set(s, settings); - rdp_write_input_capability_set(s, settings); - rdp_write_virtual_channel_capability_set(s, settings); - rdp_write_share_capability_set(s, settings); - rdp_write_font_capability_set(s, settings); - rdp_write_multifragment_update_capability_set(s, settings); - rdp_write_large_pointer_capability_set(s, settings); - rdp_write_desktop_composition_capability_set(s, settings); - rdp_write_surface_commands_capability_set(s, settings); - rdp_write_bitmap_codecs_capability_set(s, settings); - rdp_write_frame_acknowledge_capability_set(s, settings); + if (!rdp_write_general_capability_set(s, settings) || + !rdp_write_bitmap_capability_set(s, settings) || + !rdp_write_order_capability_set(s, settings) || + !rdp_write_pointer_capability_set(s, settings) || + !rdp_write_input_capability_set(s, settings) || + !rdp_write_virtual_channel_capability_set(s, settings) || + !rdp_write_share_capability_set(s, settings) || + !rdp_write_font_capability_set(s, settings) || + !rdp_write_multifragment_update_capability_set(s, settings) || + !rdp_write_large_pointer_capability_set(s, settings) || + !rdp_write_desktop_composition_capability_set(s, settings) || + !rdp_write_surface_commands_capability_set(s, settings) || + !rdp_write_bitmap_codecs_capability_set(s, settings) || + !rdp_write_frame_acknowledge_capability_set(s, settings)) + { + return FALSE; + } if (settings->BitmapCachePersistEnabled) { numberCapabilities++; - rdp_write_bitmap_cache_host_support_capability_set(s, settings); + if (!rdp_write_bitmap_cache_host_support_capability_set(s, settings)) + return FALSE; } em = Stream_GetPosition(s); @@ -3808,6 +3819,7 @@ void rdp_write_demand_active(wStream* s, rdpSettings* settings) Stream_SetPosition(s, em); Stream_Write_UINT32(s, 0); /* sessionId */ + return TRUE; } BOOL rdp_send_demand_active(rdpRdp* rdp) @@ -3822,9 +3834,8 @@ BOOL rdp_send_demand_active(rdpRdp* rdp) rdp->settings->ShareId = 0x10000 + rdp->mcs->userId; - rdp_write_demand_active(s, rdp->settings); - - status = rdp_send_pdu(rdp, s, PDU_TYPE_DEMAND_ACTIVE, rdp->mcs->userId); + status = rdp_write_demand_active(s, rdp->settings) && + rdp_send_pdu(rdp, s, PDU_TYPE_DEMAND_ACTIVE, rdp->mcs->userId); Stream_Free(s, TRUE); diff --git a/libfreerdp/core/capabilities.h b/libfreerdp/core/capabilities.h index 441fb170a..14c147d54 100644 --- a/libfreerdp/core/capabilities.h +++ b/libfreerdp/core/capabilities.h @@ -169,7 +169,7 @@ BOOL rdp_recv_get_active_header(rdpRdp* rdp, wStream* s, UINT16* pChannelId); BOOL rdp_recv_demand_active(rdpRdp* rdp, wStream* s); -void rdp_write_demand_active(wStream* s, rdpSettings* settings); +BOOL rdp_write_demand_active(wStream* s, rdpSettings* settings); BOOL rdp_send_demand_active(rdpRdp* rdp); BOOL rdp_recv_confirm_active(rdpRdp* rdp, wStream* s); BOOL rdp_write_confirm_active(wStream* s, rdpSettings* settings); From 8ef64aee96868fc243c7d5c00b67577ff755fb59 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Mon, 25 Jan 2016 13:53:19 -0800 Subject: [PATCH 185/220] Add ADPCM codec for Mac client --- channels/rdpsnd/client/mac/rdpsnd_mac.c | 101 ++++++++++++++++++++---- 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/channels/rdpsnd/client/mac/rdpsnd_mac.c b/channels/rdpsnd/client/mac/rdpsnd_mac.c index 00588f52a..c38236f6d 100644 --- a/channels/rdpsnd/client/mac/rdpsnd_mac.c +++ b/channels/rdpsnd/client/mac/rdpsnd_mac.c @@ -5,6 +5,8 @@ * Copyright 2012 Laxmikant Rashinkar * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Inuvika Inc. + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +56,12 @@ struct rdpsnd_mac_plugin AudioQueueRef audioQueue; AudioStreamBasicDescription audioFormat; AudioQueueBufferRef audioBuffers[MAC_AUDIO_QUEUE_NUM_BUFFERS]; + + Float64 lastStartTime; + + int wformat; + int block_size; + FREERDP_DSP_CONTEXT* dsp_context; }; typedef struct rdpsnd_mac_plugin rdpsndMacPlugin; @@ -69,6 +77,15 @@ static BOOL rdpsnd_mac_set_format(rdpsndDevicePlugin* device, AUDIO_FORMAT* form mac->latency = (UINT32) latency; CopyMemory(&(mac->format), format, sizeof(AUDIO_FORMAT)); + mac->audioFormat.mSampleRate = format->nSamplesPerSec; + mac->audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; + mac->audioFormat.mFramesPerPacket = 1; + mac->audioFormat.mChannelsPerFrame = format->nChannels; + mac->audioFormat.mBitsPerChannel = format->wBitsPerSample; + mac->audioFormat.mBytesPerFrame = (format->wBitsPerSample * format->nChannels) / 8; + mac->audioFormat.mBytesPerPacket = format->nBlockAlign; + mac->audioFormat.mReserved = 0; + switch (format->wFormatTag) { case WAVE_FORMAT_ALAW: @@ -83,6 +100,14 @@ static BOOL rdpsnd_mac_set_format(rdpsndDevicePlugin* device, AUDIO_FORMAT* form mac->audioFormat.mFormatID = kAudioFormatLinearPCM; break; + case WAVE_FORMAT_ADPCM: + case WAVE_FORMAT_DVI_ADPCM: + mac->audioFormat.mFormatID = kAudioFormatLinearPCM; + mac->audioFormat.mBitsPerChannel = 16; + mac->audioFormat.mBytesPerFrame = (16 * format->nChannels) / 8; + mac->audioFormat.mBytesPerPacket = mac->audioFormat.mFramesPerPacket * mac->audioFormat.mBytesPerFrame; + break; + case WAVE_FORMAT_GSM610: mac->audioFormat.mFormatID = kAudioFormatMicrosoftGSM; break; @@ -91,14 +116,8 @@ static BOOL rdpsnd_mac_set_format(rdpsndDevicePlugin* device, AUDIO_FORMAT* form break; } - mac->audioFormat.mSampleRate = format->nSamplesPerSec; - mac->audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; - mac->audioFormat.mFramesPerPacket = 1; - mac->audioFormat.mChannelsPerFrame = format->nChannels; - mac->audioFormat.mBitsPerChannel = format->wBitsPerSample; - mac->audioFormat.mBytesPerFrame = (format->wBitsPerSample * format->nChannels) / 8; - mac->audioFormat.mBytesPerPacket = format->nBlockAlign; - mac->audioFormat.mReserved = 0; + mac->wformat = format->wFormatTag; + mac->block_size = format->nBlockAlign; rdpsnd_print_audio_format(format); return TRUE; @@ -122,6 +141,8 @@ static BOOL rdpsnd_mac_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, in return FALSE; } + freerdp_dsp_context_reset_adpcm(mac->dsp_context); + status = AudioQueueNewOutput(&(mac->audioFormat), mac_audio_queue_output_cb, mac, NULL, NULL, 0, &(mac->audioQueue)); @@ -156,7 +177,9 @@ static BOOL rdpsnd_mac_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, in return FALSE; } } - + + mac->lastStartTime = 0; + mac->isOpen = TRUE; return TRUE; } @@ -184,6 +207,8 @@ static void rdpsnd_mac_free(rdpsndDevicePlugin* device) device->Close(device); + freerdp_dsp_context_free(mac->dsp_context); + free(mac); } @@ -205,6 +230,10 @@ static BOOL rdpsnd_mac_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT { return FALSE; } + else if (format->wFormatTag == WAVE_FORMAT_ADPCM || format->wFormatTag == WAVE_FORMAT_DVI_ADPCM) + { + return TRUE; + } return FALSE; } @@ -258,10 +287,42 @@ static void rdpsnd_mac_start(rdpsndDevicePlugin* device) } } -static void rdpsnd_mac_play(rdpsndDevicePlugin* device, BYTE* data, int size) +static BOOL rdpsnd_mac_wave_decode(rdpsndDevicePlugin* device, RDPSND_WAVE* wave) +{ + int length; + BYTE* data; + rdpsndMacPlugin* mac = (rdpsndMacPlugin*) device; + + if (mac->wformat == WAVE_FORMAT_ADPCM) + { + mac->dsp_context->decode_ms_adpcm(mac->dsp_context, wave->data, wave->length, mac->format.nChannels, mac->block_size); + length = mac->dsp_context->adpcm_size; + data = mac->dsp_context->adpcm_buffer; + } + else if (mac->wformat == WAVE_FORMAT_DVI_ADPCM) + { + mac->dsp_context->decode_ima_adpcm(mac->dsp_context, wave->data, wave->length, mac->format.nChannels, mac->block_size); + length = mac->dsp_context->adpcm_size; + data = mac->dsp_context->adpcm_buffer; + } + else + { + length = wave->length; + data = wave->data; + } + + wave->data = (BYTE*) malloc(length); + CopyMemory(wave->data, data, length); + wave->length = length; + + return TRUE; +} + +static void rdpsnd_mac_waveplay(rdpsndDevicePlugin* device, RDPSND_WAVE* wave) { int length; AudioQueueBufferRef audioBuffer; + AudioTimeStamp outActualStartTime; rdpsndMacPlugin* mac = (rdpsndMacPlugin*) device; if (!mac->isOpen) @@ -269,13 +330,18 @@ static void rdpsnd_mac_play(rdpsndDevicePlugin* device, BYTE* data, int size) audioBuffer = mac->audioBuffers[mac->audioBufferIndex]; - length = size > audioBuffer->mAudioDataBytesCapacity ? audioBuffer->mAudioDataBytesCapacity : size; + length = wave->length > audioBuffer->mAudioDataBytesCapacity ? audioBuffer->mAudioDataBytesCapacity : wave->length; - CopyMemory(audioBuffer->mAudioData, data, length); + CopyMemory(audioBuffer->mAudioData, wave->data, length); audioBuffer->mAudioDataByteSize = length; - - AudioQueueEnqueueBuffer(mac->audioQueue, audioBuffer, 0, 0); - + audioBuffer->mUserData = wave; + + AudioQueueEnqueueBufferWithParameters(mac->audioQueue, audioBuffer, 0, 0, 0, 0, 0, NULL, NULL, &outActualStartTime); + UInt64 startTimeDelta = (outActualStartTime.mSampleTime - mac->lastStartTime) / 100.0; + wave->wLocalTimeB = wave->wLocalTimeA + startTimeDelta + wave->wAudioLength; + wave->wTimeStampB = wave->wTimeStampA + wave->wLocalTimeB - wave->wLocalTimeA; + mac->lastStartTime = outActualStartTime.mSampleTime; + mac->audioBufferIndex++; if (mac->audioBufferIndex >= MAC_AUDIO_QUEUE_NUM_BUFFERS) @@ -308,10 +374,13 @@ UINT freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS p mac->device.FormatSupported = rdpsnd_mac_format_supported; mac->device.SetFormat = rdpsnd_mac_set_format; mac->device.SetVolume = rdpsnd_mac_set_volume; - mac->device.Play = rdpsnd_mac_play; + mac->device.WaveDecode = rdpsnd_mac_wave_decode; + mac->device.WavePlay = rdpsnd_mac_waveplay; mac->device.Start = rdpsnd_mac_start; mac->device.Close = rdpsnd_mac_close; mac->device.Free = rdpsnd_mac_free; + + mac->dsp_context = freerdp_dsp_context_new(); pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*) mac); From 3f5ce2d43f74c453336454f468e16dd273bc83e6 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Fri, 29 Jan 2016 09:58:48 -0800 Subject: [PATCH 186/220] Refactor format_supported with a nice switch() statement --- channels/rdpsnd/client/mac/rdpsnd_mac.c | 31 +++++++++---------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/channels/rdpsnd/client/mac/rdpsnd_mac.c b/channels/rdpsnd/client/mac/rdpsnd_mac.c index c38236f6d..5867480bd 100644 --- a/channels/rdpsnd/client/mac/rdpsnd_mac.c +++ b/channels/rdpsnd/client/mac/rdpsnd_mac.c @@ -214,26 +214,17 @@ static void rdpsnd_mac_free(rdpsndDevicePlugin* device) static BOOL rdpsnd_mac_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT* format) { - if (format->wFormatTag == WAVE_FORMAT_PCM) - { - return TRUE; - } - else if (format->wFormatTag == WAVE_FORMAT_ALAW) - { - return TRUE; - } - else if (format->wFormatTag == WAVE_FORMAT_MULAW) - { - return TRUE; - } - else if (format->wFormatTag == WAVE_FORMAT_GSM610) - { - return FALSE; - } - else if (format->wFormatTag == WAVE_FORMAT_ADPCM || format->wFormatTag == WAVE_FORMAT_DVI_ADPCM) - { - return TRUE; - } + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + case WAVE_FORMAT_ALAW: + case WAVE_FORMAT_MULAW: + case WAVE_FORMAT_ADPCM: + case WAVE_FORMAT_DVI_ADPCM: + return TRUE; + case WAVE_FORMAT_GSM610: + return FALSE; + } return FALSE; } From 7b9881ef6ac93fff014b180965c306bbcefb8e8f Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 1 Feb 2016 12:47:00 +0100 Subject: [PATCH 187/220] pkg/deb: fix nightly builds with the latest cmake changes related to static channels builds fail on wheezy and precise this fixes the problem. --- packaging/deb/freerdp-nightly/rules | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/deb/freerdp-nightly/rules b/packaging/deb/freerdp-nightly/rules index 963cbbf70..c9e0a960a 100755 --- a/packaging/deb/freerdp-nightly/rules +++ b/packaging/deb/freerdp-nightly/rules @@ -36,6 +36,7 @@ override_dh_strip: override_dh_install: mkdir -p debian/tmp/opt/freerdp-nightly/lib/cmake/ + rm -rf debian/tmp/opt/freerdp-nightly/lib/freerdp/*.a dh_install --fail-missing From cd05ea7452b4552b9ce80c58a74ec94f7eff9dca Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 1 Feb 2016 15:09:51 +0100 Subject: [PATCH 188/220] Fixed error checks for command line parser. --- client/common/client.c | 10 +- client/common/cmdline.c | 279 ++++++++++++++++------------- client/common/file.c | 6 +- include/freerdp/client/cmdline.h | 19 +- libfreerdp/core/test/TestConnect.c | 2 +- 5 files changed, 169 insertions(+), 147 deletions(-) diff --git a/client/common/client.c b/client/common/client.c index 7d2e5c8d4..4da191912 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -29,13 +29,13 @@ #include #include -BOOL freerdp_client_common_new(freerdp* instance, rdpContext* context) +static BOOL freerdp_client_common_new(freerdp* instance, rdpContext* context) { RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints; return pEntryPoints->ClientNew(instance, context); } -void freerdp_client_common_free(freerdp* instance, rdpContext* context) +static void freerdp_client_common_free(freerdp* instance, rdpContext* context) { RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints; pEntryPoints->ClientFree(instance, context); @@ -152,7 +152,7 @@ static BOOL freerdp_client_settings_post_process(rdpSettings* settings) } } } - + /* Moved logic for Multimon and Span monitors to force fullscreen, so * that the rdp file also triggers this functionality */ if (settings->SpanMonitors) @@ -164,7 +164,7 @@ static BOOL freerdp_client_settings_post_process(rdpSettings* settings) { settings->Fullscreen = TRUE; } - + return TRUE; out_error: @@ -197,7 +197,7 @@ int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc, { status = freerdp_client_settings_parse_assistance_file(settings, settings->AssistanceFile); } - + /* Only call post processing if no status/error was returned*/ if (status < 0) return status; diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 6d1c46890..756ae1f3a 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -178,19 +178,19 @@ static COMMAND_LINE_ARGUMENT_A args[] = { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; -int freerdp_client_print_version() +BOOL freerdp_client_print_version() { printf("This is FreeRDP version %s (git %s)\n", FREERDP_VERSION_FULL, GIT_REVISION); - return 1; + return TRUE; } -int freerdp_client_print_buildconfig() +BOOL freerdp_client_print_buildconfig() { printf("%s", freerdp_get_build_config()); - return 1; + return TRUE; } -int freerdp_client_print_command_line_help(int argc, char** argv) +BOOL freerdp_client_print_command_line_help(int argc, char** argv) { char* str; int length; @@ -229,7 +229,7 @@ int freerdp_client_print_command_line_help(int argc, char** argv) length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2); str = (char*) calloc(length + 1UL, sizeof(char)); if (!str) - return -1; + return FALSE; sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format); printf("%-20s", str); free(str); @@ -246,9 +246,9 @@ int freerdp_client_print_command_line_help(int argc, char** argv) length = (int) strlen(arg->Name) + 32; str = (char*) calloc(length + 1UL, sizeof(char)); if (!str) - return -1; + return FALSE; sprintf_s(str, length + 1, "%s (default:%s)", arg->Name, - arg->Default ? "on" : "off"); + arg->Default ? "on" : "off"); printf(" %s", arg->Default ? "-" : "+"); @@ -294,10 +294,10 @@ int freerdp_client_print_command_line_help(int argc, char** argv) printf("More documentation is coming, in the meantime consult source files\n"); printf("\n"); - return 1; + return TRUE; } -int freerdp_client_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv) +static int freerdp_client_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv) { if (index == 1) { @@ -334,21 +334,21 @@ int freerdp_client_command_line_pre_filter(void* context, int index, int argc, L return 0; } -int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params) +BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params) { if (strcmp(params[0], "drive") == 0) { RDPDR_DRIVE* drive; if (count < 3) - return -1; + return FALSE; settings->DeviceRedirection = TRUE; drive = (RDPDR_DRIVE*) calloc(1, sizeof(RDPDR_DRIVE)); if (!drive) - return -1; + return FALSE; drive->Type = RDPDR_DTYP_FILESYSTEM; @@ -357,7 +357,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p if (!(drive->Name = _strdup(params[1]))) { free(drive); - return -1; + return FALSE; } } @@ -367,7 +367,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p { free(drive->Name); free(drive); - return -1; + return FALSE; } } @@ -376,17 +376,17 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(drive->Path); free(drive->Name); free(drive); - return -1; + return FALSE; } - return 1; + return TRUE; } else if (strcmp(params[0], "printer") == 0) { RDPDR_PRINTER* printer; if (count < 1) - return -1; + return FALSE; settings->RedirectPrinters = TRUE; settings->DeviceRedirection = TRUE; @@ -396,7 +396,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p printer = (RDPDR_PRINTER*) calloc(1, sizeof(RDPDR_PRINTER)); if (!printer) - return -1; + return FALSE; printer->Type = RDPDR_DTYP_PRINT; @@ -405,7 +405,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p if (!(printer->Name = _strdup(params[1]))) { free(printer); - return -1; + return FALSE; } } @@ -415,7 +415,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p { free(printer->Name); free(printer); - return -1; + return FALSE; } } @@ -425,19 +425,19 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(printer->DriverName); free(printer->Name); free(printer); - return -1; + return FALSE; } } - return 1; + return TRUE; } else if (strcmp(params[0], "smartcard") == 0) { RDPDR_SMARTCARD* smartcard; if (count < 1) - return -1; + return FALSE; settings->RedirectSmartCards = TRUE; settings->DeviceRedirection = TRUE; @@ -447,7 +447,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); if (!smartcard) - return -1; + return FALSE; smartcard->Type = RDPDR_DTYP_SMARTCARD; @@ -456,7 +456,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p if (!(smartcard->Name = _strdup(params[1]))) { free(smartcard); - return -1; + return FALSE; } } @@ -466,7 +466,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p { free(smartcard->Name); free(smartcard); - return -1; + return FALSE; } } if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard)) @@ -474,18 +474,18 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(smartcard->Path); free(smartcard->Name); free(smartcard); - return -1; + return FALSE; } } - return 1; + return TRUE; } else if (strcmp(params[0], "serial") == 0) { RDPDR_SERIAL* serial; if (count < 1) - return -1; + return FALSE; settings->RedirectSerialPorts = TRUE; settings->DeviceRedirection = TRUE; @@ -493,7 +493,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p serial = (RDPDR_SERIAL*) calloc(1, sizeof(RDPDR_SERIAL)); if (!serial) - return -1; + return FALSE; serial->Type = RDPDR_DTYP_SERIAL; @@ -502,7 +502,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p if (!(serial->Name = _strdup(params[1]))) { free(serial); - return -1; + return FALSE; } } @@ -512,7 +512,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p { free(serial->Name); free(serial); - return -1; + return FALSE; } } @@ -523,7 +523,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(serial->Path); free(serial->Name); free(serial); - return -1; + return FALSE; } } @@ -535,7 +535,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(serial->Path); free(serial->Name); free(serial); - return -1; + return FALSE; } } @@ -546,17 +546,17 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(serial->Path); free(serial->Name); free(serial); - return -1; + return FALSE; } - return 1; + return TRUE; } else if (strcmp(params[0], "parallel") == 0) { RDPDR_PARALLEL* parallel; if (count < 1) - return -1; + return FALSE; settings->RedirectParallelPorts = TRUE; settings->DeviceRedirection = TRUE; @@ -564,7 +564,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p parallel = (RDPDR_PARALLEL*) calloc(1, sizeof(RDPDR_PARALLEL)); if (!parallel) - return -1; + return FALSE; parallel->Type = RDPDR_DTYP_PARALLEL; @@ -573,7 +573,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p if (!(parallel->Name = _strdup(params[1]))) { free(parallel); - return -1; + return FALSE; } } @@ -583,7 +583,7 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p { free(parallel->Name); free(parallel); - return -1; + return FALSE; } } @@ -592,23 +592,23 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p free(parallel->Path); free(parallel->Name); free(parallel); - return -1; + return FALSE; } - return 1; + return TRUE; } - return 0; + return FALSE; } -int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params) +BOOL freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params) { int index; ADDIN_ARGV* args; args = (ADDIN_ARGV*) calloc(1, sizeof(ADDIN_ARGV)); if (!args) - return -1; + return FALSE; args->argc = count; args->argv = (char**) calloc(args->argc, sizeof(char*)); @@ -630,7 +630,7 @@ int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** p if (!freerdp_static_channel_collection_add(settings, args)) goto error_argv_index; - return 0; + return TRUE; error_argv_index: for (index = 0; index < args->argc; index++) @@ -639,17 +639,17 @@ error_argv_strdup: free(args->argv); error_argv: free(args); - return -1; + return FALSE; } -int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params) +BOOL freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params) { int index; ADDIN_ARGV* args; args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV)); if (!args) - return -1; + return FALSE; args->argc = count; args->argv = (char**) calloc(args->argc, sizeof(char*)); @@ -671,7 +671,7 @@ int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** if (!freerdp_dynamic_channel_collection_add(settings, args)) goto error_argv_index; - return 0; + return TRUE; error_argv_index: for (index = 0; index < args->argc; index++) @@ -680,7 +680,7 @@ error_argv_strdup: free(args->argv); error_argv: free(args); - return -1; + return FALSE; } static char** freerdp_command_line_parse_comma_separated_values(char* list, int* count) @@ -743,21 +743,21 @@ static char** freerdp_command_line_parse_comma_separated_values_offset(char* lis return p; } -int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg) +static int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg) { rdpSettings* settings = (rdpSettings*) context; - int status = 0; + BOOL status = FALSE; CommandLineSwitchStart(arg) - CommandLineSwitchCase(arg, "a") + CommandLineSwitchCase(arg, "a") { char** p; int count; p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count); - if (freerdp_client_add_device_channel(settings, count, p) > 0) + if ((status = freerdp_client_add_device_channel(settings, count, p))) { settings->DeviceRedirection = TRUE; } @@ -782,7 +782,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count); - freerdp_client_add_dynamic_channel(settings, count, p); + status = freerdp_client_add_dynamic_channel(settings, count, p); free(p); } @@ -794,7 +794,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "drive"; - freerdp_client_add_device_channel(settings, count, p); + status = freerdp_client_add_device_channel(settings, count, p); free(p); } @@ -806,7 +806,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "serial"; - freerdp_client_add_device_channel(settings, count, p); + status = freerdp_client_add_device_channel(settings, count, p); free(p); } @@ -818,7 +818,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "parallel"; - freerdp_client_add_device_channel(settings, count, p); + status = freerdp_client_add_device_channel(settings, count, p); free(p); } @@ -830,7 +830,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "smartcard"; - freerdp_client_add_device_channel(settings, count, p); + status = freerdp_client_add_device_channel(settings, count, p); free(p); } @@ -844,7 +844,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "printer"; - freerdp_client_add_device_channel(settings, count, p); + status = freerdp_client_add_device_channel(settings, count, p); free(p); } @@ -856,7 +856,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT count = 1; p[0] = "printer"; - freerdp_client_add_device_channel(settings, count, p); + status = freerdp_client_add_device_channel(settings, count, p); } } CommandLineSwitchCase(arg, "usb") @@ -867,7 +867,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "urbdrc"; - freerdp_client_add_dynamic_channel(settings, count, p); + status = freerdp_client_add_dynamic_channel(settings, count, p); free(p); } @@ -922,7 +922,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "audin"; - freerdp_client_add_dynamic_channel(settings, count, p); + status = freerdp_client_add_dynamic_channel(settings, count, p); free(p); } @@ -934,7 +934,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT count = 1; p[0] = "audin"; - freerdp_client_add_dynamic_channel(settings, count, p); + status = freerdp_client_add_dynamic_channel(settings, count, p); } } CommandLineSwitchCase(arg, "multimedia") @@ -947,7 +947,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count); p[0] = "tsmf"; - freerdp_client_add_dynamic_channel(settings, count, p); + status = freerdp_client_add_dynamic_channel(settings, count, p); free(p); } @@ -959,7 +959,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT count = 1; p[0] = "tsmf"; - freerdp_client_add_dynamic_channel(settings, count, p); + status = freerdp_client_add_dynamic_channel(settings, count, p); } } CommandLineSwitchCase(arg, "heartbeat") @@ -974,10 +974,10 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT CommandLineSwitchEnd(arg) - return status; + return status ? 1 : 0; } -int freerdp_parse_username(char* username, char** user, char** domain) +BOOL freerdp_parse_username(char* username, char** user, char** domain) { char* p; int length = 0; @@ -992,14 +992,14 @@ int freerdp_parse_username(char* username, char** user, char** domain) length = (int) (p - username); *user = _strdup(&p[1]); if (!*user) - return -1; + return FALSE; *domain = (char*) calloc(length + 1UL, sizeof(char)); if (!*domain) { free (*user); *user = NULL; - return -1; + return FALSE; } strncpy(*domain, username, length); @@ -1013,7 +1013,7 @@ int freerdp_parse_username(char* username, char** user, char** domain) */ *user = _strdup(username); if (!*user) - return -1; + return FALSE; *domain = _strdup("\0"); @@ -1021,16 +1021,16 @@ int freerdp_parse_username(char* username, char** user, char** domain) { free(*user); *user = NULL; - return -1; + return FALSE; } } else - return -1; + return FALSE; - return 0; + return TRUE; } -int freerdp_parse_hostname(char* hostname, char** host, int* port) +BOOL freerdp_parse_hostname(char* hostname, char** host, int* port) { char* p; int length; @@ -1043,7 +1043,7 @@ int freerdp_parse_hostname(char* hostname, char** host, int* port) *host = (char*) calloc(length + 1UL, sizeof(char)); if (!(*host)) - return -1; + return FALSE; CopyMemory(*host, hostname, length); (*host)[length] = '\0'; @@ -1054,15 +1054,15 @@ int freerdp_parse_hostname(char* hostname, char** host, int* port) *host = _strdup(hostname); if (!(*host)) - return -1; + return FALSE; *port = -1; } - return 0; + return TRUE; } -int freerdp_set_connection_type(rdpSettings* settings, int type) +BOOL freerdp_set_connection_type(rdpSettings* settings, int type) { settings->ConnectionType = type; @@ -1132,7 +1132,7 @@ int freerdp_set_connection_type(rdpSettings* settings, int type) settings->NetworkAutoDetect = TRUE; } - return 0; + return TRUE; } int freerdp_map_keyboard_layout_name_to_id(char* name) @@ -1189,7 +1189,7 @@ int freerdp_map_keyboard_layout_name_to_id(char* name) return 0; } -int freerdp_detect_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv) +static int freerdp_detect_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv) { int length; @@ -1218,7 +1218,7 @@ int freerdp_detect_command_line_pre_filter(void* context, int index, int argc, L } int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, - int* count, BOOL ignoreUnknown) + int* count, BOOL ignoreUnknown) { int status; DWORD flags; @@ -1238,7 +1238,7 @@ int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, CommandLineClearArgumentsA(args); status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, - NULL, freerdp_detect_command_line_pre_filter, NULL); + NULL, freerdp_detect_command_line_pre_filter, NULL); if (status < 0) return status; @@ -1261,7 +1261,7 @@ int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, } int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, - int* count, BOOL ignoreUnknown) + int* count, BOOL ignoreUnknown) { int status; DWORD flags; @@ -1282,7 +1282,7 @@ int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, CommandLineClearArgumentsA(args); status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, - NULL, freerdp_detect_command_line_pre_filter, NULL); + NULL, freerdp_detect_command_line_pre_filter, NULL); if (status < 0) return status; @@ -1305,7 +1305,7 @@ int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, } static BOOL freerdp_client_detect_command_line(int argc, char** argv, - DWORD* flags, BOOL ignoreUnknown) + DWORD* flags, BOOL ignoreUnknown) { int old_cli_status; int old_cli_count; @@ -1348,7 +1348,7 @@ static BOOL freerdp_client_detect_command_line(int argc, char** argv, } WLog_DBG(TAG, "windows: %d/%d posix: %d/%d compat: %d/%d", windows_cli_status, windows_cli_count, - posix_cli_status, posix_cli_count, old_cli_status, old_cli_count); + posix_cli_status, posix_cli_count, old_cli_status, old_cli_count); return compatibility; } @@ -1420,7 +1420,7 @@ int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int } int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, - int argc, char** argv, BOOL allowUnknown) + int argc, char** argv, BOOL allowUnknown) { char* p; char* user = NULL; @@ -1448,7 +1448,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, flags |= COMMAND_LINE_IGN_UNKNOWN_KEYWORD; } status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, settings, - freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter); + freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter); if (status < 0) return status; @@ -1465,7 +1465,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, CommandLineSwitchStart(arg) - CommandLineSwitchCase(arg, "v") + CommandLineSwitchCase(arg, "v") { p = strchr(arg->Value, '['); /* ipv4 */ @@ -1497,7 +1497,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, length = p2 - p; if (!(settings->ServerHostname = (char*) calloc(length, sizeof(char)))) - return COMMAND_LINE_ERROR; + return COMMAND_LINE_ERROR_MEMORY; strncpy(settings->ServerHostname, p+1, length-1); if (*(p2 + 1) == ':') { @@ -1921,14 +1921,15 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, else if (_stricmp(arg->Value, "lan") == 0) type = CONNECTION_TYPE_LAN; else if ((_stricmp(arg->Value, "autodetect") == 0) || - (_stricmp(arg->Value, "auto") == 0) || - (_stricmp(arg->Value, "detect") == 0)) + (_stricmp(arg->Value, "auto") == 0) || + (_stricmp(arg->Value, "detect") == 0)) { type = CONNECTION_TYPE_AUTODETECT; } } - freerdp_set_connection_type(settings, type); + if (!freerdp_set_connection_type(settings, type)) + return COMMAND_LINE_ERROR; } CommandLineSwitchCase(arg, "fonts") { @@ -2267,7 +2268,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, BYTE *base64; int length; crypto_base64_decode((const char *) (arg->Value), (int) strlen(arg->Value), - &base64, &length); + &base64, &length); if ((base64 != NULL) && (length == sizeof(ARC_SC_PRIVATE_PACKET))) { memcpy(settings->ServerAutoReconnectCookie, base64, length); @@ -2298,10 +2299,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, if (!settings->Domain && user) { - int ret; + BOOL ret; ret = freerdp_parse_username(user, &settings->Username, &settings->Domain); free(user); - if (ret != 0 ) + if (!ret) return COMMAND_LINE_ERROR; } else @@ -2309,11 +2310,11 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, if (!settings->GatewayDomain && gwUser) { - int ret; + BOOL ret; ret = freerdp_parse_username(gwUser, &settings->GatewayUsername, - &settings->GatewayDomain); + &settings->GatewayDomain); free(gwUser); - if (ret != 0) + if (!ret) return COMMAND_LINE_ERROR; } else @@ -2353,7 +2354,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, return status; } -int freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings, char* name, void* data) +static BOOL freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings, char* name, void* data) { void* entry; @@ -2364,20 +2365,20 @@ int freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* if (freerdp_channels_client_load(channels, settings, entry, data) == 0) { WLog_INFO(TAG, "loading channel %s", name); - return 0; + return TRUE; } } - return -1; + return FALSE; } -int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) +BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) { UINT32 index; ADDIN_ARGV* args; if ((freerdp_static_channel_collection_find(settings, "rdpsnd")) || - (freerdp_dynamic_channel_collection_find(settings, "tsmf"))) + (freerdp_dynamic_channel_collection_find(settings, "tsmf"))) { settings->DeviceRedirection = TRUE; /* rdpsnd requires rdpdr to be registered */ settings->AudioPlayback = TRUE; /* Both rdpsnd and tsmf require this flag to be set */ @@ -2389,14 +2390,14 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) } if (settings->NetworkAutoDetect || - settings->SupportHeartbeatPdu || - settings->SupportMultitransport) + settings->SupportHeartbeatPdu || + settings->SupportMultitransport) { settings->DeviceRedirection = TRUE; /* these RDP8 features require rdpdr to be registered */ } if (settings->RedirectDrives || settings->RedirectHomeDrive || settings->RedirectSerialPorts - || settings->RedirectSmartCards || settings->RedirectPrinters) + || settings->RedirectSmartCards || settings->RedirectPrinters) { settings->DeviceRedirection = TRUE; /* All of these features require rdpdr */ } @@ -2411,7 +2412,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) params[1] = "media"; params[2] = "*"; - freerdp_client_add_device_channel(settings, 3, (char**) params); + if (!freerdp_client_add_device_channel(settings, 3, (char**) params)) + return FALSE; } } @@ -2425,13 +2427,15 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) params[1] = "home"; params[2] = "%"; - freerdp_client_add_device_channel(settings, 3, (char**) params); + if (!freerdp_client_add_device_channel(settings, 3, (char**) params)) + return FALSE; } } if (settings->DeviceRedirection) { - freerdp_client_load_static_channel_addin(channels, settings, "rdpdr", settings); + if (!freerdp_client_load_static_channel_addin(channels, settings, "rdpdr", settings)) + return FALSE; if (!freerdp_static_channel_collection_find(settings, "rdpsnd")) { @@ -2440,7 +2444,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) params[0] = "rdpsnd"; params[1] = "sys:fake"; - freerdp_client_add_static_channel(settings, 2, (char**) params); + if (!freerdp_client_add_static_channel(settings, 2, (char**) params)) + return FALSE; } } @@ -2451,10 +2456,11 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); if (!smartcard) - return -1; + return FALSE; smartcard->Type = RDPDR_DTYP_SMARTCARD; - freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard); + if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard)) + return FALSE; } if (settings->RedirectPrinters) @@ -2464,10 +2470,11 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) printer = (RDPDR_PRINTER*) calloc(1, sizeof(RDPDR_PRINTER)); if (!printer) - return -1; + return FALSE; printer->Type = RDPDR_DTYP_PRINT; - freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer); + if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer)) + return FALSE; } if (settings->RedirectClipboard) @@ -2478,7 +2485,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) params[0] = "cliprdr"; - freerdp_client_add_static_channel(settings, 1, (char**) params); + if (!freerdp_client_add_static_channel(settings, 1, (char**) params)) + return FALSE; } } @@ -2496,20 +2504,28 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) } if (settings->EncomspVirtualChannel) - freerdp_client_load_static_channel_addin(channels, settings, "encomsp", settings); + { + if (!freerdp_client_load_static_channel_addin(channels, settings, "encomsp", settings)) + return FALSE; + } if (settings->RemdeskVirtualChannel) - freerdp_client_load_static_channel_addin(channels, settings, "remdesk", settings); + { + if (!freerdp_client_load_static_channel_addin(channels, settings, "remdesk", settings)) + return FALSE; + } for (index = 0; index < settings->StaticChannelCount; index++) { args = settings->StaticChannelArray[index]; - freerdp_client_load_static_channel_addin(channels, settings, args->argv[0], args); + if (!freerdp_client_load_static_channel_addin(channels, settings, args->argv[0], args)) + return FALSE; } if (settings->RemoteApplicationMode) { - freerdp_client_load_static_channel_addin(channels, settings, "rail", settings); + if (!freerdp_client_load_static_channel_addin(channels, settings, "rail", settings)) + return FALSE; } if (settings->MultiTouchInput) @@ -2520,7 +2536,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) count = 1; p[0] = "rdpei"; - freerdp_client_add_dynamic_channel(settings, count, p); + if (!freerdp_client_add_dynamic_channel(settings, count, p)) + return FALSE; } if (settings->SupportGraphicsPipeline) @@ -2531,7 +2548,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) count = 1; p[0] = "rdpgfx"; - freerdp_client_add_dynamic_channel(settings, count, p); + if (!freerdp_client_add_dynamic_channel(settings, count, p)) + return FALSE; } if (settings->SupportEchoChannel) @@ -2542,7 +2560,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) count = 1; p[0] = "echo"; - freerdp_client_add_dynamic_channel(settings, count, p); + if (!freerdp_client_add_dynamic_channel(settings, count, p)) + return FALSE; } if (settings->SupportDisplayControl) @@ -2553,7 +2572,8 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) count = 1; p[0] = "disp"; - freerdp_client_add_dynamic_channel(settings, count, p); + if (!freerdp_client_add_dynamic_channel(settings, count, p)) + return FALSE; } if (settings->DynamicChannelCount) @@ -2561,8 +2581,9 @@ int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) if (settings->SupportDynamicChannels) { - freerdp_client_load_static_channel_addin(channels, settings, "drdynvc", settings); + if (!freerdp_client_load_static_channel_addin(channels, settings, "drdynvc", settings)) + return FALSE; } - return 1; + return TRUE; } diff --git a/client/common/file.c b/client/common/file.c index f4b23fa02..b66262169 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -880,7 +880,7 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* char* user = NULL; char* domain = NULL; - if (freerdp_parse_username(file->Username, &user, &domain) != 0) + if (!freerdp_parse_username(file->Username, &user, &domain)) return FALSE; if (freerdp_set_param_string(settings, FreeRDP_Username, user) != 0) return FALSE; @@ -900,7 +900,7 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* int port = -1; char* host = NULL; - if (freerdp_parse_hostname(file->FullAddress, &host, &port) != 0) + if (!freerdp_parse_hostname(file->FullAddress, &host, &port)) return FALSE; if (freerdp_set_param_string(settings, FreeRDP_ServerHostname, host) != 0) @@ -1022,7 +1022,7 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* int port = -1; char* host = NULL; - if (freerdp_parse_hostname(file->GatewayHostname, &host, &port) != 0) + if (!freerdp_parse_hostname(file->GatewayHostname, &host, &port)) return FALSE; if (freerdp_set_param_string(settings, FreeRDP_GatewayHostname, host) != 0) diff --git a/include/freerdp/client/cmdline.h b/include/freerdp/client/cmdline.h index 834ebeb98..621a9976e 100644 --- a/include/freerdp/client/cmdline.h +++ b/include/freerdp/client/cmdline.h @@ -30,18 +30,19 @@ extern "C" { FREERDP_API int freerdp_client_settings_parse_command_line_arguments( rdpSettings* settings, int argc, char** argv, BOOL allowUnknown); FREERDP_API int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int status, int argc, char** argv); -FREERDP_API int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings); +FREERDP_API BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings); -FREERDP_API int freerdp_client_print_version(void); -FREERDP_API int freerdp_client_print_command_line_help(int argc, char** argv); +FREERDP_API BOOL freerdp_client_print_version(void); +FREERDP_API BOOL freerdp_client_print_buildconfig(void); +FREERDP_API BOOL freerdp_client_print_command_line_help(int argc, char** argv); -FREERDP_API int freerdp_parse_username(char* username, char** user, char** domain); -FREERDP_API int freerdp_parse_hostname(char* hostname, char** host, int* port); -FREERDP_API int freerdp_set_connection_type(rdpSettings* settings, int type); +FREERDP_API BOOL freerdp_parse_username(char* username, char** user, char** domain); +FREERDP_API BOOL freerdp_parse_hostname(char* hostname, char** host, int* port); +FREERDP_API BOOL freerdp_set_connection_type(rdpSettings* settings, int type); -FREERDP_API int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params); -FREERDP_API int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params); -FREERDP_API int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params); +FREERDP_API BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params); +FREERDP_API BOOL freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params); +FREERDP_API BOOL freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params); #ifdef __cplusplus } diff --git a/libfreerdp/core/test/TestConnect.c b/libfreerdp/core/test/TestConnect.c index 5dec3e7d4..91f6b02c7 100644 --- a/libfreerdp/core/test/TestConnect.c +++ b/libfreerdp/core/test/TestConnect.c @@ -22,7 +22,7 @@ static int runInstance(int argc, char* argv[], freerdp** inst) if (freerdp_client_settings_parse_command_line(instance->settings, argc, argv, FALSE) < 0) goto finish; - if (freerdp_client_load_addins(instance->context->channels, instance->settings) != 1) + if (!freerdp_client_load_addins(instance->context->channels, instance->settings)) goto finish; if (s_sync) From 61633a1c66f637e1076599e697c75a9129519f65 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 1 Feb 2016 15:21:07 +0100 Subject: [PATCH 189/220] Fixed android build issues. --- CMakeLists.txt | 119 ++++++++++---------- cmake/AndroidToolchain.cmake | 2 +- cmake/ConfigOptionsAndroid.cmake | 11 -- config.h.in | 1 - winpr/libwinpr/CMakeLists.txt | 4 + winpr/libwinpr/path/shell.c | 5 - winpr/libwinpr/shell/CMakeLists.txt | 4 +- winpr/libwinpr/utils/wlog/ConsoleAppender.c | 12 ++ 8 files changed, 78 insertions(+), 80 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b7cd6bc0..78e5ee704 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,17 +81,27 @@ else() endif() set(FREERDP_INCLUDE_DIR "include/freerdp${FREERDP_VERSION_MAJOR}/") +# Make paths absolute +if (CMAKE_INSTALL_PREFIX) + get_filename_component(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE) +endif() +if (FREERDP_EXTERNAL_PATH) + get_filename_component (FREERDP_EXTERNAL_PATH "${FREERDP_EXTERNAL_PATH}" ABSOLUTE) +endif() + # Allow to search the host machine for git if(ANDROID OR IOS) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) endif(ANDROID OR IOS) + include(GetGitRevisionDescription) git_get_exact_tag(GIT_REVISION --tags --always) + if (${GIT_REVISION} STREQUAL "n/a") - git_rev_parse(GIT_REVISION --short) + git_rev_parse (GIT_REVISION --short) endif() if(ANDROID OR IOS) - SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) + SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) endif(ANDROID OR IOS) message(STATUS "Git Revision ${GIT_REVISION}") @@ -105,7 +115,7 @@ if(NOT CMAKE_BUILD_TYPE) endif() if(NOT DEFINED BUILD_SHARED_LIBS) - if(ANDROID OR IOS OR APPLE) + if(IOS OR APPLE) set(BUILD_SHARED_LIBS OFF) else() set(BUILD_SHARED_LIBS ON) @@ -299,11 +309,11 @@ if(MSVC) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) - if(CMAKE_BUILD_TYPE STREQUAL "Release") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi") - endif() + if(CMAKE_BUILD_TYPE STREQUAL "Release") + else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi") + endif() endif() @@ -406,9 +416,9 @@ if(APPLE) # Temporarily disabled, causes the cmake script to be reexecuted, causing the compilation to fail. # Workaround: specify the parameter in the command-line -# if(WITH_CLANG) -# set(CMAKE_C_COMPILER "clang") -# endif() +# if(WITH_CLANG) +# set(CMAKE_C_COMPILER "clang") +# endif() if (WITH_VERBOSE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -v") @@ -420,14 +430,18 @@ endif(APPLE) if(OPENBSD) set(WITH_MANPAGES "ON") set(WITH_ALSA "OFF") - set(WITH_PULSE "OFF") - set(WITH_OSS "ON") + set(WITH_PULSE "OFF") + set(WITH_OSS "ON") set(WITH_WAYLAND "OFF") endif() # Android if(ANDROID) - set(WITH_LIBRARY_VERSIONING "OFF") + set(WITH_LIBRARY_VERSIONING "OFF") + + if (${ANDROID_ABI} STREQUAL "armeabi") + set (WITH_NEON OFF) + endif() if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") add_definitions(-DNDK_DEBUG=1) @@ -439,40 +453,23 @@ if(ANDROID) endif() set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -llog") - if (NOT FREERDP_EXTERNAL_JPEG_PATH) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg8d") - set(FREERDP_EXTERNAL_JPEG_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg8d") + if (NOT FREERDP_EXTERNAL_PATH) + if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/") + set (FREERDP_EXTERNAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/") else() - message(STATUS "FREERDP_EXTERNAL_SSL_PATH not set! - Needs to be set if openssl is not found in the android NDK (which usually isn't)") + message(STATUS "FREERDP_EXTERNAL_PATH not set!") endif() endif() - if (NOT FREERDP_EXTERNAL_SSL_PATH) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/openssl") - set(FREERDP_EXTERNAL_SSL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/openssl") - else() - message(STATUS "FREERDP_EXTERNAL_SSL_PATH not set! - Needs to be set if openssl is not found in the android NDK (which usually isn't)") - endif() - if(WITH_GPROF) - if (NOT FREERDP_EXTERNAL_PROFILER_PATH) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/android-ndk-profiler") - set(FREERDP_EXTERNAL_PROFILER_PATH - "${CMAKE_CURRENT_SOURCE_DIR}/external/android-ndk-profiler") - else() - message(STATUS "FREERDP_EXTERNAL_PROFILER_PATH not set!") - endif() - endif() - endif() -endif() -set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${FREERDP_EXTERNAL_SSL_PATH} ${FREERDP_EXTERNAL_JPEG_PATH}) -set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${FREERDP_EXTERNAL_PROFILER_PATH}) - set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/client/Android/FreeRDPCore/jni/${ANDROID_ABI}) - CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/regenerate_jni_headers.sh.cmake - ${CMAKE_BINARY_DIR}/scripts/regenerate_jni_headers.sh @ONLY) + list (APPEND CMAKE_INCLUDE_PATH ${FREERDP_EXTERNAL_PATH}/include) + list (APPEND CMAKE_LIBRARY_PATH ${FREERDP_EXTERNAL_PATH}/${ANDROID_ABI}/ ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH ) + if (WITH_GPROF) - CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/gprof_generate.sh.cmake ${CMAKE_BINARY_DIR}/scripts/gprof_generate.sh @ONLY) + CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/gprof_generate.sh.cmake + ${CMAKE_BINARY_DIR}/scripts/gprof_generate.sh @ONLY) endif(WITH_GPROF) - endif() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) @@ -486,9 +483,9 @@ if(NOT WIN32) endif() if(WITH_VALGRIND_MEMCHECK) - check_include_files(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H) + check_include_files(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H) else() - unset(HAVE_VALGRIND_MEMCHECK_H CACHE) + unset(HAVE_VALGRIND_MEMCHECK_H CACHE) endif() if(UNIX OR CYGWIN) @@ -626,6 +623,21 @@ if(APPLE) set(OPENSLES_FEATURE_TYPE "DISABLED") endif() +if(UNIX AND NOT ANDROID) + set(WLOG_SYSTEMD_JOURNAL_FEATURE_TYPE "RECOMMENDED") + set(WLOG_SYSTEMD_JOURNAL_FEATURE_PURPOSE "systemd journal appender") + set(WLOG_SYSTEMD_JOURNAL_FEATURE_DESCRIPTION "allows to export wLog to systemd journal") + + #include(Findlibsystemd) + find_feature(libsystemd ${WLOG_SYSTEMD_JOURNAL_FEATURE_TYPE} ${WLOG_SYSTEMD_JOURNAL_FEATURE_PURPOSE} ${WLOG_SYSTEMD_JOURNAL_FEATURE_DESCRIPTION}) + + if(LIBSYSTEMD_FOUND) + set(HAVE_JOURNALD_H TRUE) + else() + unset(HAVE_JOURNALD_H) + endif() +endif(UNIX AND NOT ANDROID) + if(ANDROID) set(X11_FEATURE_TYPE "DISABLED") set(WAYLAND_FEATURE_TYPE "DISABLED") @@ -641,21 +653,6 @@ if(ANDROID) set(OPENSLES_FEATURE_TYPE "REQUIRED") endif() -if(UNIX) - set(WLOG_SYSTEMD_JOURNAL_FEATURE_TYPE "RECOMMENDED") - set(WLOG_SYSTEMD_JOURNAL_FEATURE_PURPOSE "systemd journal appender") - set(WLOG_SYSTEMD_JOURNAL_FEATURE_DESCRIPTION "allows to export wLog to systemd journal") - - #include(Findlibsystemd) - find_feature(libsystemd ${WLOG_SYSTEMD_JOURNAL_FEATURE_TYPE} ${WLOG_SYSTEMD_JOURNAL_FEATURE_PURPOSE} ${WLOG_SYSTEMD_JOURNAL_FEATURE_DESCRIPTION}) - - if(LIBSYSTEMD_FOUND) - set(HAVE_JOURNALD_H TRUE) - else() - unset(HAVE_JOURNALD_H) - endif() -endif(UNIX) - find_feature(X11 ${X11_FEATURE_TYPE} ${X11_FEATURE_PURPOSE} ${X11_FEATURE_DESCRIPTION}) find_feature(Wayland ${WAYLAND_FEATURE_TYPE} ${WAYLAND_FEATURE_PURPOSE} ${WAYLAND_FEATURE_DESCRIPTION}) find_feature(DirectFB ${DIRECTFB_FEATURE_TYPE} ${DIRECTFB_FEATURE_PURPOSE} ${DIRECTFB_FEATURE_DESCRIPTION}) @@ -728,8 +725,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DI # RPATH configuration if(CMAKE_SKIP_RPATH) - set(CMAKE_SKIP_RPATH FALSE) - set(CMAKE_SKIP_INSTALL_RPATH TRUE) + set(CMAKE_SKIP_RPATH FALSE) + set(CMAKE_SKIP_INSTALL_RPATH TRUE) endif() set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) diff --git a/cmake/AndroidToolchain.cmake b/cmake/AndroidToolchain.cmake index dfbe39eb2..3752bbcc0 100644 --- a/cmake/AndroidToolchain.cmake +++ b/cmake/AndroidToolchain.cmake @@ -1627,7 +1627,7 @@ if(NOT _CMAKE_IN_TRY_COMPILE) else() set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) endif() - set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_OUTPUT_ABI_NAME}" CACHE PATH "path for android libs" ) + set( CMAKE_INSTALL_LIBDIR "${ANDROID_NDK_OUTPUT_ABI_NAME}" CACHE PATH "path for android libs" ) endif() # copy shaed stl library to build directory diff --git a/cmake/ConfigOptionsAndroid.cmake b/cmake/ConfigOptionsAndroid.cmake index 780b4e18b..07dd60410 100644 --- a/cmake/ConfigOptionsAndroid.cmake +++ b/cmake/ConfigOptionsAndroid.cmake @@ -15,19 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(JAVA_DEBUG_DEFAULT "off") -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set(JAVA_DEBUG_DEFAULT "on") -endif() - -option(WITH_DEBUG_ANDROID_JNI "Enable debug output for android jni bindings" ${DEFAULT_DEBUG_OPTION}) -option(WITH_ANDROID_DEBUG_MENU "Enable debug output for android jni bindings" ${DEFAULT_DEBUG_OPTION}) option(WITH_OPENSLES "Enable sound and microphone redirection using OpenSLES" ON) -option(ANDROID_BUILD_JAVA "Automatically android java code - build type depends on CMAKE_BUILD_TYPE" ON) -option(ANDROID_BUILD_JAVA_DEBUG "Create a android debug package" ${JAVA_DEBUG_DEFAULT}) -set(ANDROID_APP_VERSION 3 CACHE STRING "Application version") set(ANDROID_APP_TARGET_SDK 21 CACHE STRING "Application target android SDK") set(ANDROID_APP_MIN_SDK 14 CACHE STRING "Application minimum android SDK requirement") -set(ANDROID_APP_GOOGLE_TARGET_SDK "16" CACHE STRING "Application target google SDK") diff --git a/config.h.in b/config.h.in index 9dc44bdba..3f4459058 100644 --- a/config.h.in +++ b/config.h.in @@ -89,6 +89,5 @@ #cmakedefine WITH_DEBUG_X11_CLIPRDR #cmakedefine WITH_DEBUG_X11_LOCAL_MOVESIZE #cmakedefine WITH_DEBUG_XV -#cmakedefine WITH_DEBUG_ANDROID_JNI #cmakedefine WITH_DEBUG_RINGBUFFER #endif diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt index 3ea073ce9..f49cb8dc8 100644 --- a/winpr/libwinpr/CMakeLists.txt +++ b/winpr/libwinpr/CMakeLists.txt @@ -73,6 +73,10 @@ macro (winpr_definition_add) set (WINPR_DEFINITIONS ${WINPR_DEFINITIONS} PARENT_SCOPE) endmacro() +if (ANDROID) + winpr_library_add(log) +endif() + # Level "1" API as defined for MinCore.lib set(WINPR_CORE synch locale library file comm pipe interlocked security environment crypto registry credentials path io memory input shell diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index dd529863c..b35f6293d 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -76,11 +76,6 @@ static char* GetPath_HOME(void) #ifdef _WIN32 path = GetEnvAlloc("UserProfile"); -#elif defined(ANDROID) - path = malloc(2); - if (!path) - return NULL; - strcpy(path, "/"); #else path = GetEnvAlloc("HOME"); #endif diff --git a/winpr/libwinpr/shell/CMakeLists.txt b/winpr/libwinpr/shell/CMakeLists.txt index 41796701a..24b47e3ca 100644 --- a/winpr/libwinpr/shell/CMakeLists.txt +++ b/winpr/libwinpr/shell/CMakeLists.txt @@ -15,4 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -winpr_module_add(shell.c) +if (NOT ANDROID) + winpr_module_add(shell.c) +endif() diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index a150ae625..5b57143bd 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -146,6 +146,9 @@ static int g_DataId = 0; static BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { +#if defined(ANDROID) + return FALSE; +#else int DataId; char* FullFileName; @@ -157,12 +160,16 @@ static BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogAppender* appen free(FullFileName); return TRUE; +#endif } static int g_ImageId = 0; static BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { +#if defined(ANDROID) + return FALSE; +#else int ImageId; char* FullFileName; @@ -175,12 +182,16 @@ static BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogAppender* appe free(FullFileName); return TRUE; +#endif } static int g_PacketId = 0; static BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message) { +#if defined(ANDROID) + return FALSE; +#else int PacketId; char* FullFileName; @@ -198,6 +209,7 @@ static BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogAppender* app message->PacketData, message->PacketLength, message->PacketFlags); return TRUE; +#endif } static BOOL WLog_ConsoleAppender_Set(wLogAppender* appender, const char *setting, void *value) { From d04eb12a473137fe48ae4e5aa56222b3ab4cb1b3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 1 Feb 2016 15:22:10 +0100 Subject: [PATCH 190/220] Added new android build scripts. --- scripts/android-build-common.sh | 269 ++++++++++++++++++ scripts/android-build-freerdp.sh | 140 +++++++++ scripts/android-build-jpeg.sh | 41 +++ scripts/android-build-openh264.sh | 58 ++++ scripts/android-build-openssl.sh | 121 ++++++++ scripts/android-build.conf | 22 ++ scripts/android_setup_build_env.sh | 134 --------- .../openssl-disable-library-versioning.patch | 24 ++ 8 files changed, 675 insertions(+), 134 deletions(-) create mode 100644 scripts/android-build-common.sh create mode 100755 scripts/android-build-freerdp.sh create mode 100755 scripts/android-build-jpeg.sh create mode 100755 scripts/android-build-openh264.sh create mode 100755 scripts/android-build-openssl.sh create mode 100644 scripts/android-build.conf delete mode 100755 scripts/android_setup_build_env.sh create mode 100644 scripts/openssl-disable-library-versioning.patch diff --git a/scripts/android-build-common.sh b/scripts/android-build-common.sh new file mode 100644 index 000000000..d58d0ed51 --- /dev/null +++ b/scripts/android-build-common.sh @@ -0,0 +1,269 @@ +#!/bin/bash + +if [ -z $BUILD_ARCH ]; then + BUILD_ARCH="armeabi armeabi-v7a mips mips64 x86 x86_64 arm64-v8a" +fi + +if [ -z $NDK_TARGET ]; then + NDK_TARGET=21 +fi + +if [ -z $ANDROID_SDK ]; then + ANDROID_SDK="missing" +fi + +if [ -z $ANDROID_NDK ]; then + ANDROID_NDK="missing" +fi + +if [ -z $BUILD_DST ]; then + BUILD_DST=$(pwd)/libs +fi + +if [ -z $BUILD_SRC ]; then + BUILD_SRC=$(pwd)/src +fi + +if [ -z $SCM_URL ]; then + SCM_URL="missing" +fi + +if [ -z $SCM_TAG ]; then + SCM_TAG=master +fi + +CLEAN_BUILD_DIR=0 + +function common_help { + echo "$(BASHSOURCE[0]) supports the following arguments:" + echo " --sdk The base directory of your android SDK" + echo " ANDROID_SDK=$ANDROID_SDK" + echo " --ndk The base directory of your android NDK defa" + echo " ANDROID_NDK=$ANDROID_NDK" + echo " --arch A list of architectures to build" + echo " BUILD_ARCH=$BUILD_ARCH" + echo " --dst The destination directory for include and library files" + echo " BUILD_DST=$BUILD_DST" + echo " --src The source directory for SCM checkout" + echo " BUILD_SRC=$BUILD_SRC" + echo " --url The SCM source url" + echo " SCM_URL=$SCM_URL" + echo " --tag The SCM branch or tag to check out" + echo " SCM_TAG=$SCM_TAG" + echo " --clean Clean the destination before build" + echo " --help Display this help" + exit 0 +} + +function common_run { + echo "[RUN] $@" + "$@" + RES=$? + if [[ $RES -ne 0 ]]; + then + echo "[ERROR] $@ retured $RES" + exit 1 + fi +} + +function common_parse_arguments { + while [[ $# > 0 ]] + do + key="$1" + case $key in + --conf) + source "$2" + shift + ;; + + --sdk) + ANDROID_SDK="$2" + shift + ;; + + --ndk) + ANDROID_NDK="$2" + shift + ;; + + --arch) + BUILD_ARCH="$2" + shift + ;; + + --dst) + BUILD_DST="$2" + shift + ;; + + --src) + BUILD_SRC="$2" + shift + ;; + + --url) + SCM_URL="$2" + shift + ;; + + --tag) + SCM_TAG="$2" + shift + ;; + + --clean) + CLEAN_BUILD_DIR=1 + shift + ;; + + --help) + common_help + shift + ;; + + *) # Unknown + ;; + esac + shift + done +} + +function common_check_requirements { + if [[ ! -d $ANDROID_SDK ]]; + then + echo "export ANDROID_SDK to point to your SDK location." + exit 1 + fi + + if [[ ! -d $ANDROID_NDK ]]; + then + echo "export ANDROID_NDK to point to your NDK location." + exit 1 + fi + + if [[ -z $BUILD_DST ]]; + then + echo "Destination directory not valid" + exit 1 + fi + + if [[ -z $BUILD_SRC ]]; + then + echo "Source directory not valid" + exit 1 + fi + + if [[ -z $SCM_URL ]]; + then + echo "Source URL not defined! Define SCM_URL" + exit 1 + fi + + if [[ -z $SCM_TAG ]]; + then + echo "SCM TAG / BRANCH not defined! Define SCM_TAG" + exit 1 + fi + + if [[ -z $NDK_TARGET ]]; + then + echo "Android platform NDK_TARGET not defined" + exit 1 + fi + + if [ -x $ANDROID_NDK/ndk-build ]; then + NDK_BUILD=$ANDROID_NDK/ndk-build + else + echo "ndk-build not found in NDK directory $ANDROID_NDK" + echo "assuming ndk-build is in path..." + NDK_BUILD=ndk-build + fi + + if [[ -z $NDK_BUILD ]]; + then + echo "Android ndk-build not detected" + exit 1 + fi + + for CMD in make git cmake $NDK_BUILD + do + if ! type $CMD >/dev/null; then + echo "Command $CMD not found. Install and add it to the PATH." + exit 1 + fi + done + + if [ "${BUILD_SRC:0:1}" != "/" ]; + then + BUILD_SRC=$(pwd)/$BUILD_SRC + fi + if [ "${BUILD_DST:0:1}" != "/" ]; + then + BUILD_DST=$(pwd)/$BUILD_DST + fi +} + +function common_update { + if [ $# -ne 3 ]; + then + echo "Invalid arguments to update function $@" + exit 1 + fi + + echo "Preparing checkout..." + BASE=$(pwd) + if [[ ! -d $3 ]]; + then + common_run mkdir -p $3 + common_run cd $3 + common_run git clone $1 $3 + fi + + common_run cd $BASE + common_run cd $3 + common_run git fetch + common_run git reset --hard HEAD + common_run git checkout $2 + common_run cd $BASE +} + +function common_clean { + if [ $CLEAN_BUILD_DIR -ne 1 ]; + then + return + fi + + if [ $# -ne 1 ]; + then + echo "Invalid arguments to clean function $@" + exit 1 + fi + + echo "Cleaning up $1..." + common_run rm -rf $1 +} + +function common_copy { + if [ $# -ne 2 ]; + then + echo "Invalid arguments to copy function $@" + exit 1 + fi + if [ ! -d $1 ] || [ ! -d $1/include ] || [ ! -d $1/libs ]; + then + echo "Invalid source $1" + exit 1 + fi + if [ -z $2 ]; + then + echo "Invalid destination $2" + exit 1 + fi + + if [ ! -d $2 ]; + then + common_run mkdir -p $2 + fi + common_run cp -L -r $1/include $2 + common_run cp -L -r $1/libs/* $2 +} diff --git a/scripts/android-build-freerdp.sh b/scripts/android-build-freerdp.sh new file mode 100755 index 000000000..482c6b729 --- /dev/null +++ b/scripts/android-build-freerdp.sh @@ -0,0 +1,140 @@ +#!/bin/bash + +JPEG_TAG=master +OPENH264_TAG=master +OPENSSL_TAG=master + +WITH_JPEG=0 +WITH_OPENH264=0 +WITH_OPENSSL=0 + +SRC_DIR=$(pwd) +BUILD_SRC=$(pwd) +BUILD_DST=$(pwd) + +CMAKE_BUILD_TYPE=Debug +BUILD_DEPS=0 + +SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}") +source $SCRIPT_PATH/android-build-common.sh +source $SCRIPT_PATH/android-build.conf + +# Parse arguments. +REMAINING="" +while [[ $# > 0 ]] +do + key="$1" + case $key in + --src) + SRC_DIR="$2" + shift + ;; + --jpeg) + WITH_JPEG=1 + shift + ;; + --openh264) + WITH_OPENH264=1 + shift + ;; + --openssl) + WITH_OPENSSL=1 + shift + ;; + --debug) + CMAKE_BUILD_TYPE=Debug + shift + ;; + --release) + CMAKE_BUILD_TYPE=Release + shift + ;; + --relWithDebug) + CMAKE_BUILD_TYPE=RelWithDebug + shift + ;; + --build-deps) + BUILD_DEPS=1 + shift + ;; + *) + REMAINING="$REMAINING $key" + shift + ;; + esac +done +common_parse_arguments $REMAINING + +# clean up top +if [ -d $BUILD_SRC ]; +then + common_clean $BUILD_SRC +fi + +if [ -d $BUILD_DST ]; +then + common_run mkdir -p $BUILD_DST +fi + +# Prepare the environment +common_run mkdir -p $BUILD_SRC + +CMAKE_CMD_ARGS="-DANDROID_NDK=$ANDROID_NDK \ + -DCMAKE_TOOLCHAIN_FILE=$SRC_DIR/cmake/AndroidToolchain.cmake \ + -DCMAKE_INSTALL_PREFIX=$BUILD_DST \ + -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ + -DFREERDP_EXTERNAL_PATH=$BUILD_DST" + +BASE=$(pwd) +for ARCH in $BUILD_ARCH +do + # build dependencies. + if [ $WITH_JPEG -ne 0 ]; + then + if [ $BUILD_DEPS -ne 0 ]; + then + common_run bash $SCRIPT_PATH/android-build-jpeg.sh \ + --src $BUILD_SRC/jpeg --dst $BUILD_DST \ + --sdk $ANDROID_SDK --ndk $ANDROID_NDK \ + --arch $ARCH \ + --tag $JPEG_TAG + fi + CMAKE_CMD_ARGS="$CMAKE_CMD_ARGS -DWITH_JPEG=ON" + fi + if [ $WITH_OPENH264 -ne 0 ]; + then + if [ $BUILD_DEPS -ne 0 ]; + then + common_run bash $SCRIPT_PATH/android-build-openh264.sh \ + --src $BUILD_SRC/openh264 --dst $BUILD_DST \ + --sdk $ANDROID_SDK --ndk $ANDROID_NDK \ + --arch $ARCH \ + --tag $OPENH264_TAG + fi + CMAKE_CMD_ARGS="$CMAKE_CMD_ARGS -DWITH_OPENH264=ON" + fi + if [ $WITH_OPENSSL -ne 0 ]; + then + if [ $BUILD_DEPS -ne 0 ]; + then + common_run bash $SCRIPT_PATH/android-build-openssl.sh \ + --src $BUILD_SRC/openssl --dst $BUILD_DST \ + --sdk $ANDROID_SDK --ndk $ANDROID_NDK \ + --arch $ARCH \ + --tag $OPENSSL_TAG + fi + fi + + # Build and install the library. + common_run cd $BASE + common_run mkdir -p $BUILD_SRC/freerdp-build/$ARCH + common_run cd $BUILD_SRC/freerdp-build/$ARCH + common_run export ANDROID_NDK=$ANDROID_NDK + common_run cmake $CMAKE_CMD_ARGS \ + -DANDROID_ABI=$ARCH \ + $SRC_DIR + echo $(pwd) + common_run cmake --build . --target install +done + +echo "Successfully build library for architectures $BUILD_ARCH" diff --git a/scripts/android-build-jpeg.sh b/scripts/android-build-jpeg.sh new file mode 100755 index 000000000..7b06adf33 --- /dev/null +++ b/scripts/android-build-jpeg.sh @@ -0,0 +1,41 @@ +#!/bin/bash +SCM_URL=https://github.com/akallabeth/jpeg8d.git +SCM_TAG=master + +source $(dirname "${BASH_SOURCE[0]}")/android-build-common.sh + +function usage { + echo $0 [arguments] + echo "\tThe script checks out the OpenH264 git repository" + echo "\tto a local source directory, builds and installs" + echo "\tthe library for all architectures defined to" + echo "\tthe destination directory." + echo "" + echo "\t[-s|--source-dir ]" + echo "\t[-d|--destination-dir ]" + echo "\t[-a|--arch ]" + echo "\t[-t|--tag ]" + echo "\t[--scm-url ]" + echo "\t[--ndk ]" + echo "\t[--sdk ]" + exit 1 +} + +function build { + echo "Building architectures $BUILD_ARCH..." + BASE=$(pwd) + common_run cd $BUILD_SRC + common_run $NDK_BUILD V=1 APP_ABI="${BUILD_ARCH}" -j clean + common_run $NDK_BUILD V=1 APP_ABI="${BUILD_ARCH}" -j + common_run cd $BASE +} + +# Run the main program. +common_parse_arguments $@ +common_check_requirements +common_update $SCM_URL $SCM_TAG $BUILD_SRC +common_clean $BUILD_DST + +build + +common_copy $BUILD_SRC $BUILD_DST diff --git a/scripts/android-build-openh264.sh b/scripts/android-build-openh264.sh new file mode 100755 index 000000000..22aef4ef6 --- /dev/null +++ b/scripts/android-build-openh264.sh @@ -0,0 +1,58 @@ +#!/bin/bash +SCM_URL=https://github.com/cisco/openh264 +SCM_TAG=master + +source $(dirname "${BASH_SOURCE[0]}")/android-build-common.sh + +function build { + echo "Building architecture $1..." + BASE=$(pwd) + common_run cd $BUILD_SRC + PATH=$ANDROID_SDK/tools:$ANDROID_NDK:$PATH + MAKE="make PATH=$PATH OS=android NDKROOT=$ANDROID_NDK TARGET=android-$2 NDKLEVEL=$2 ARCH=$1 -j" + common_run git clean -xdf + common_run $MAKE + # Install creates a non optimal directory layout, fix that + common_run $MAKE PREFIX=$BUILD_SRC/libs/$1 install + common_run cd $BASE +} + +# Run the main program. +common_parse_arguments $@ +common_check_requirements +common_update $SCM_URL $SCM_TAG $BUILD_SRC +common_clean $BUILD_DST + +for ARCH in $BUILD_ARCH +do + case $ARCH in + "armeabi") + OARCH="arm" + ;; + "armeabi-v7a") + OARCH="arm" + ;; + "arm64-v8a") + OARCH="arm64" + ;; + *) + OARCH=$ARCH + ;; + esac + + echo "$ARCH=$OARCH" + + build $OARCH $NDK_TARGET + + if [ ! -d $BUILD_DST/include ]; + then + common_run mkdir -p $BUILD_DST/include + fi + + common_run cp -L -r $BUILD_SRC/libs/$OARCH/include/ $BUILD_DST/ + if [ ! -d $BUILD_DST/$ARCH ]; + then + common_run mkdir -p $BUILD_DST/$ARCH + fi + common_run cp -L $BUILD_SRC/libs/$OARCH/lib/*.so $BUILD_DST/$ARCH/ +done diff --git a/scripts/android-build-openssl.sh b/scripts/android-build-openssl.sh new file mode 100755 index 000000000..3e376fe0f --- /dev/null +++ b/scripts/android-build-openssl.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +SCM_URL=https://github.com/openssl/openssl +SCM_TAG=master + +COMPILER=4.9 + +source $(dirname "${BASH_SOURCE[0]}")/android-build-common.sh + +function build { + if [ $# -ne 5 ]; + then + echo "Invalid arguments $@" + exit 1 + fi + + CONFIG=$1 + ARCH_PREFIX=$2 + DST_PREFIX=$3 + TOOLCHAIN_PREFIX=$4 + PLATFORM_PREFIX=$5 + + TMP_DIR=$ANDROID_NDK/toolchains/$TOOLCHAIN_PREFIX$COMPILER/prebuilt/ + HOST_PLATFORM=$(ls $TMP_DIR) + if [ ! -d $TMP_DIR$HOST_POLATFORM ]; + then + echo "could not determine NDK host platform in $ANDROID_NDK/toolchains/$TOOLCHAIN_PREFIX$COMPILER/prebuilt/" + exit 1 + fi + + common_run export CROSS_SYSROOT=$ANDROID_NDK/platforms/android-$NDK_TARGET/$PLATFORM_PREFIX + common_run export ANDROID_DEV=$ANDROID_NDK/platforms/android-$NDK_TARGET/$PLATFORM_PREFIX/usr + common_run export CROSS_COMPILE=$ARCH_PREFIX + common_run export PATH=$ANDROID_NDK/toolchains/$TOOLCHAIN_PREFIX$COMPILER/prebuilt/$HOST_PLATFORM/bin/:$ORG_PATH + + echo "CONFIG=$CONFIG" + echo "ARCH_PREFIX=$ARCH_PREFIX" + echo "DST_PREFIX=$DST_PREFIX" + echo "TOOLCHAIN_PREFIX=$TOOLCHAIN_PREFIX" + echo "PLATFORM_PREFIX=$PLATFORM_PREFIX" + echo "CROSS_SYSROOT=$CROSS_SYSROOT" + echo "CROSS_COMPILE=$CROSS_COMPILE" + echo "PATH=$PATH" + + BASE=$(pwd) + DST_DIR=$BUILD_DST/$DST_PREFIX + common_run cd $BUILD_SRC + common_run git clean -xdf + common_run ./Configure --openssldir=$DST_DIR $CONFIG shared + common_run make -j build_libs + + if [ ! -d $DST_DIR ]; + then + common_run mkdir -p $DST_DIR + fi + + common_run cp -L libssl.so $DST_DIR + common_run cp -L libcrypto.so $DST_DIR + common_run cd $BASE +} + +# Run the main program. +common_parse_arguments $@ +common_check_requirements +common_update $SCM_URL $SCM_TAG $BUILD_SRC +common_clean $BUILD_DST + +# Patch openssl +BASE=$(pwd) +common_run cd $BUILD_SRC +common_run git am $(dirname "${BASH_SOURCE[0]}")/openssl-disable-library-versioning.patch +common_run cd $BASE + +ORG_PATH=$PATH +for ARCH in $BUILD_ARCH +do + + case $ARCH in + "armeabi") + build "android" "arm-linux-androideabi-" \ + $ARCH "arm-linux-androideabi-" "arch-arm" + ;; + "armeabi-v7a") + build "android-armv7" "arm-linux-androideabi-" \ + $ARCH "arm-linux-androideabi-" "arch-arm" + ;; + "mips") + build "android-mips" "mipsel-linux-android-" \ + $ARCH "mipsel-linux-android-" "arch-mips" + ;; + "mips64") + echo "[WARNING] Skipping unsupported architecture $ARCH" + continue + build "android-mips" "mipsel-linux-android-" \ + $ARCH "mipsel-linux-android-" "arch-mips" + ;; + "x86") + build "android-x86" "i686-linux-android-" \ + $ARCH "x86-" "arch-x86" + ;; + "arm64-v8a") + build "android64-aarch64" "aarch64-linux-android-" \ + $ARCH "aarch64-linux-android-" "arch-arm64" + ;; + "x86_64") + build "android64" "x86_64-linux-android-" \ + $ARCH "x86_64-" "arch-x86_64" + ;; + *) + echo "[WARNING] Skipping unsupported architecture $ARCH" + continue + ;; + esac +done + +if [ ! -d $BUILD_DST/include ]; +then + common_run mkdir -p $BUILD_DST/include +fi +common_run cp -L -r $BUILD_SRC/include/openssl $BUILD_DST/include/ + diff --git a/scripts/android-build.conf b/scripts/android-build.conf new file mode 100644 index 000000000..fff1ab298 --- /dev/null +++ b/scripts/android-build.conf @@ -0,0 +1,22 @@ +#!/bin/bash +# +# Android build confguration +SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}") +SCRIPT_PATH=$(realpath "$SCRIPT_PATH") + +WITH_JPEG=1 +WITH_OPENH264=1 +WITH_OPENSSL=1 +BUILD_DEPS=1 + +JPEG_TAG=master +OPENH264_TAG=v1.5.0 +OPENSSL_TAG=OpenSSL_1_0_2f + +SRC_DIR=$SCRIPT_PATH/.. +BUILD_DST=$SCRIPT_PATH/../client/Android/Studio/freeRDPCore/src/main/jniLibs +BUILD_SRC=$SRC_DIR/build + +CMAKE_BUILD_TYPE=Debug + +BUILD_ARCH="armeabi armeabi-v7a x86" diff --git a/scripts/android_setup_build_env.sh b/scripts/android_setup_build_env.sh deleted file mode 100755 index 9d0fd2749..000000000 --- a/scripts/android_setup_build_env.sh +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/sh -# -# This script checks out or updates and builds third party libraries -# required for the android build. -# -# Specifically these are: -# - OpenSSL -# - Android NDK Profiler -# - Jpeg library -# -# Usage: -# android_setup_build_env.sh - -OPENSSL_SCM=https://github.com/akallabeth/openssl-android.git -OPENSSL_TAG=1.0.1h-fips-2.0.7 -NDK_PROFILER_SCM=https://github.com/richq/android-ndk-profiler.git -JPEG_LIBRARY_SCM=https://github.com/akallabeth/jpeg8d.git - -SCRIPT_NAME=$(basename $0) - -if [ -x $ANDROID_NDK/ndk-build ]; then - NDK_BUILD=$ANDROID_NDK/ndk-build -else - echo "ndk-build not found in NDK directory $ANDROID_NDK" - echo "assuming ndk-build is in path..." - NDK_BUILD=ndk-build -fi - -if [ $# -ne 1 ]; then - - echo "Missing command line argument, current directory as root." - ROOT=`pwd` - ROOT=$ROOT/external -else - ROOT=`readlink -f $1` -fi - -if [ ! -d $ROOT ]; then - echo "Argument '$ROOT' is not a directory." - exit -2 -fi -echo "Using '$ROOT' as root." - -echo "Preparing OpenSSL..." -OPENSSL_SRC=$ROOT/openssl-build -if [ -d $OPENSSL_SRC ]; then - cd $OPENSSL_SRC - git fetch - RETVAL=$? -else - git clone $OPENSSL_SCM $OPENSSL_SRC - RETVAL=$? -fi -if [ $RETVAL -ne 0 ]; then - echo "Failed to execute git command [$RETVAL]" - exit -3 -fi -cd $OPENSSL_SRC - -# We want to build a specific TAG -git checkout $OPENSSL_TAG - -make clean -# The makefile has a bug, which aborts during -# first compilation. Rerun make to build the whole lib. -make -RETVAL=$? -if [ $RETVAL -ne 0 ]; then - echo "Failed to execute make command [$RETVAL]" - exit -4 -fi -# Copy the created library to the default openssl directory, -# so that CMake will detect it automatically. -SSL_ROOT=`find $OPENSSL_SRC -type d -name "openssl-?.?.*"` -if [ -z "$SSL_ROOT" ]; then - echo "OpenSSL was not build successfully, aborting." - exit -42 -fi -mkdir -p $SSL_ROOT/lib -cp $SSL_ROOT/*.a $SSL_ROOT/lib/ - -rm -f $ROOT/openssl -ln -s $SSL_ROOT $ROOT/openssl - -echo "Preparing NDK profiler..." -NDK_PROFILER_SRC=$ROOT/android-ndk-profiler -if [ -d $NDK_PROFILER_SRC ]; then - cd $NDK_PROFILER_SRC - git pull - RETVAL=$? -else - git clone $NDK_PROFILER_SCM $NDK_PROFILER_SRC - RETVAL=$? -fi -if [ $RETVAL -ne 0 ]; then - echo "Failed to execute git command [$RETVAL]" - exit -5 -fi -cd $NDK_PROFILER_SRC -$NDK_BUILD V=1 APP_ABI=armeabi-v7a clean -$NDK_BUILD V=1 APP_ABI=armeabi-v7a -RETVAL=$? -if [ $RETVAL -ne 0 ]; then - echo "Failed to execute $NDK_BUILD command [$RETVAL]" - exit -6 -fi - -echo "Preparing JPEG library..." -JPEG_LIBRARY_SRC=$ROOT/jpeg8d -if [ -d $JPEG_LIBRARY_SRC ]; then - cd $JPEG_LIBRARY_SRC - git pull - RETVAL=$? -else - git clone $JPEG_LIBRARY_SCM $JPEG_LIBRARY_SRC - RETVAL=$? -fi -if [ $RETVAL -ne 0 ]; then - echo "Failed to execute git command [$RETVAL]" - exit -6 -fi -cd $JPEG_LIBRARY_SRC -$NDK_BUILD V=1 APP_ABI=armeabi-v7a clean -$NDK_BUILD V=1 APP_ABI=armeabi-v7a -RETVAL=$? -if [ $RETVAL -ne 0 ]; then - echo "Failed to execute $NDK_BUILD command [$RETVAL]" - exit -7 -fi -mkdir -p $JPEG_LIBRARY_SRC/lib -cp $JPEG_LIBRARY_SRC/obj/local/armeabi-v7a/*.a $JPEG_LIBRARY_SRC/lib/ - -echo "Prepared external libraries, you can now build the application." -exit 0 diff --git a/scripts/openssl-disable-library-versioning.patch b/scripts/openssl-disable-library-versioning.patch new file mode 100644 index 000000000..9f2f69107 --- /dev/null +++ b/scripts/openssl-disable-library-versioning.patch @@ -0,0 +1,24 @@ +From 12f0521bbb3f046db8c7854364135d8247cf982e Mon Sep 17 00:00:00 2001 +From: Armin Novak +Date: Fri, 29 Jan 2016 17:04:12 +0100 +Subject: [PATCH] Disabled library versioning. + +--- + Makefile.shared | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/Makefile.shared b/Makefile.shared +index e753f44..5cffcc2 100644 +--- a/Makefile.shared ++++ b/Makefile.shared +@@ -81,7 +81,6 @@ CALC_VERSIONS= \ + prev=""; \ + for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \ + SHLIB_SOVER_NODOT=$$v; \ +- SHLIB_SOVER=.$$v; \ + if [ -n "$$prev" ]; then \ + SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \ + fi; \ +-- +2.1.4 + From 54a7d799d1e9dc7698425b7172a8bf81a4147168 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 1 Feb 2016 15:25:40 +0100 Subject: [PATCH 191/220] Restructured client project, moved to gradle build. --- client/Android/.gitignore | 15 - client/Android/CMakeLists.txt | 86 +- client/Android/FreeRDPCore/.classpath | 9 - client/Android/FreeRDPCore/.gitignore | 4 - client/Android/FreeRDPCore/.project | 53 - client/Android/FreeRDPCore/CMakeLists.txt | 48 - .../Android/FreeRDPCore/ant.properties.cmake | 20 - client/Android/FreeRDPCore/build.xml.cmake | 92 -- .../Android/FreeRDPCore/jni/Android.mk.cmake | 8 - .../FreeRDPCore/jni/Application.mk.cmake | 1 - client/Android/FreeRDPCore/jni/CMakeLists.txt | 73 - .../Android/FreeRDPCore/jni/android_debug.h | 31 - .../Android/FreeRDPCore/jni/android_freerdp.c | 1290 ----------------- .../Android/FreeRDPCore/jni/android_freerdp.h | 71 - .../jni/generated/android_freerdp_jni.c | 142 -- ..._freerdp_freerdpcore_services_LibFreeRDP.h | 173 --- client/Android/FreeRDPCore/lint.xml | 3 - .../FreeRDPCore/local.properties.cmake | 2 - .../FreeRDPCore/project.properties.cmake | 16 - .../freerdpcore/application/GlobalApp.java | 214 --- .../freerdpcore/services/BookmarkDB.java | 228 --- .../freerdpcore/services/LibFreeRDP.java | 308 ---- .../utils/BuildConfiguration.java.in | 15 - client/Android/ModuleOptions.cmake | 4 - client/Android/Studio/.gitignore | 37 + client/Android/Studio/aFreeRDP/build.gradle | 23 + client/Android/Studio/aFreeRDP/lint.xml | 3 + .../aFreeRDP/src/main/AndroidManifest.xml} | 12 +- .../src/main}/assets/FreeRDP_Logo.png | Bin .../src/main}/assets/about_page/about.html | 0 .../main}/assets/about_page/about_phone.html | 0 .../about_page/background_transparent.png | Bin .../aFreeRDP/src/main}/assets/background.jpg | Bin .../src/main}/assets/de_about_page/about.html | 0 .../assets/de_about_page/about_phone.html | 0 .../de_about_page/background_transparent.png | Bin .../main}/assets/de_help_page/gestures.html | 0 .../main}/assets/de_help_page/gestures.png | Bin .../assets/de_help_page/gestures_phone.html | 0 .../assets/de_help_page/gestures_phone.png | Bin .../assets/de_help_page/nav_gestures.png | Bin .../main}/assets/de_help_page/nav_toolbar.png | Bin .../assets/de_help_page/nav_touch_pointer.png | Bin .../main}/assets/de_help_page/toolbar.html | 0 .../src/main}/assets/de_help_page/toolbar.png | Bin .../assets/de_help_page/toolbar_phone.html | 0 .../assets/de_help_page/toolbar_phone.png | Bin .../assets/de_help_page/touch_pointer.html | 0 .../assets/de_help_page/touch_pointer.png | Bin .../de_help_page/touch_pointer_phone.html | 0 .../de_help_page/touch_pointer_phone.png | Bin .../src/main}/assets/help_page/gestures.html | 0 .../src/main}/assets/help_page/gestures.png | Bin .../assets/help_page/gestures_phone.html | 0 .../main}/assets/help_page/gestures_phone.png | Bin .../main}/assets/help_page/nav_gestures.png | Bin .../main}/assets/help_page/nav_toolbar.png | Bin .../assets/help_page/nav_touch_pointer.png | Bin .../src/main}/assets/help_page/toolbar.html | 0 .../src/main}/assets/help_page/toolbar.png | Bin .../main}/assets/help_page/toolbar_phone.html | 0 .../main}/assets/help_page/toolbar_phone.png | Bin .../main}/assets/help_page/touch_pointer.html | 0 .../main}/assets/help_page/touch_pointer.png | Bin .../assets/help_page/touch_pointer_phone.html | 0 .../assets/help_page/touch_pointer_phone.png | Bin .../afreerdp/application/GlobalApp.java | 0 .../drawable-hdpi/icon_launcher_freerdp.png | Bin .../drawable-ldpi/icon_launcher_freerdp.png | Bin .../drawable-mdpi/icon_launcher_freerdp.png | Bin .../main}/res/drawable/button_background.xml | 0 .../res/drawable/icon_launcher_freerdp.png | Bin .../res/drawable/separator_background.xml | 0 .../src/main}/res/values-es/strings.xml | 2 +- .../src/main}/res/values-fr/strings.xml | 2 +- .../src/main}/res/values-nl/strings.xml | 2 +- .../aFreeRDP/src/main}/res/values/strings.xml | 2 +- .../aFreeRDP/src/main}/res/xml/searchable.xml | 0 client/Android/Studio/build.gradle | 15 + .../Android/Studio/freeRDPCore/build.gradle | 22 + client/Android/Studio/freeRDPCore/lint.xml | 3 + .../freeRDPCore/src/main/AndroidManifest.xml} | 18 +- .../freerdpcore/application/GlobalApp.java | 186 +++ .../application/GlobalSettings.java | 0 .../application/NetworkStateReceiver.java | 0 .../application/ScreenReceiver.java | 0 .../freerdpcore/application/SessionState.java | 0 .../freerdpcore/domain/BookmarkBase.java | 26 +- .../domain/ConnectionReference.java | 0 .../freerdpcore/domain/ManualBookmark.java | 0 .../domain/PlaceholderBookmark.java | 0 .../domain/QuickConnectBookmark.java | 0 .../presentation/AboutActivity.java | 0 .../ApplicationSettingsActivity.java | 0 .../presentation/BookmarkActivity.java | 11 - .../presentation/HelpActivity.java | 0 .../presentation/HomeActivity.java | 0 .../presentation/ScrollView2D.java | 0 .../presentation/SessionActivity.java | 227 +-- .../freerdpcore/presentation/SessionView.java | 4 +- .../presentation/ShortcutsActivity.java | 0 .../presentation/TouchPointerView.java | 0 .../services/BookmarkBaseGateway.java | 0 .../freerdpcore/services/BookmarkDB.java | 227 +++ .../services/FreeRDPSuggestionProvider.java | 0 .../freerdpcore/services/HistoryDB.java | 0 .../freerdpcore/services/LibFreeRDP.java | 373 +++++ .../services/ManualBookmarkGateway.java | 0 .../services/QuickConnectHistoryGateway.java | 0 .../SessionRequestHandlerActivity.java | 0 .../utils/BookmarkArrayAdapter.java | 0 .../freerdpcore/utils/ButtonPreference.java | 0 .../utils/ClipboardManagerProxy.java | 0 .../utils/DoubleGestureDetector.java | 0 .../freerdpcore/utils/GestureDetector.java | 0 .../utils/IntEditTextPreference.java | 0 .../freerdpcore/utils/IntListPreference.java | 0 .../freerdpcore/utils/KeyboardMapper.java | 0 .../com/freerdp/freerdpcore/utils/Mouse.java | 0 .../freerdpcore/utils/RDPFileParser.java | 0 .../utils/SeparatedListAdapter.java | 0 .../res/drawable-hdpi/icon_button_add.png | Bin .../res/drawable-hdpi/icon_edittext_clear.png | Bin .../drawable-hdpi/icon_edittext_search.png | Bin .../drawable-hdpi/icon_launcher_freerdp.png | Bin .../res/drawable-hdpi/icon_menu_about.png | Bin .../main}/res/drawable-hdpi/icon_menu_add.png | Bin .../res/drawable-hdpi/icon_menu_close.png | Bin .../drawable-hdpi/icon_menu_disconnect.png | Bin .../drawable-hdpi/icon_menu_ext_keyboard.png | Bin .../res/drawable-hdpi/icon_menu_help.png | Bin .../drawable-hdpi/icon_menu_preferences.png | Bin .../res/drawable-hdpi/icon_menu_settings.png | Bin .../drawable-hdpi/icon_menu_sys_keyboard.png | Bin .../drawable-hdpi/icon_menu_touch_pointer.png | Bin .../main}/res/drawable-hdpi/icon_star_off.png | Bin .../main}/res/drawable-hdpi/icon_star_on.png | Bin .../res/drawable-hdpi/search_plate.9.png | Bin .../res/drawable-hdpi/sym_keyboard_delete.png | Bin .../sym_keyboard_feedback_delete.png | Bin .../sym_keyboard_feedback_return.png | Bin .../res/drawable-hdpi/sym_keyboard_return.png | Bin .../res/drawable-ldpi/icon_button_add.png | Bin .../drawable-ldpi/icon_edittext_search.png | Bin .../drawable-ldpi/icon_launcher_freerdp.png | Bin .../res/drawable-ldpi/icon_menu_about.png | Bin .../main}/res/drawable-ldpi/icon_menu_add.png | Bin .../drawable-ldpi/icon_menu_disconnect.png | Bin .../res/drawable-ldpi/icon_menu_exit.png | Bin .../drawable-ldpi/icon_menu_ext_keyboard.png | Bin .../res/drawable-ldpi/icon_menu_help.png | Bin .../drawable-ldpi/icon_menu_preferences.png | Bin .../res/drawable-ldpi/icon_menu_settings.png | Bin .../drawable-ldpi/icon_menu_sys_keyboard.png | Bin .../drawable-ldpi/icon_menu_touch_pointer.png | Bin .../main}/res/drawable-ldpi/icon_star_off.png | Bin .../main}/res/drawable-ldpi/icon_star_on.png | Bin .../res/drawable-ldpi/search_plate.9.png | Bin .../res/drawable-ldpi/sym_keyboard_delete.png | Bin .../sym_keyboard_feedback_delete.png | Bin .../sym_keyboard_feedback_return.png | Bin .../res/drawable-ldpi/sym_keyboard_return.png | Bin .../res/drawable-mdpi/icon_button_add.png | Bin .../res/drawable-mdpi/icon_edittext_clear.png | Bin .../drawable-mdpi/icon_edittext_search.png | Bin .../drawable-mdpi/icon_launcher_freerdp.png | Bin .../res/drawable-mdpi/icon_menu_about.png | Bin .../main}/res/drawable-mdpi/icon_menu_add.png | Bin .../drawable-mdpi/icon_menu_disconnect.png | Bin .../res/drawable-mdpi/icon_menu_exit.png | Bin .../drawable-mdpi/icon_menu_ext_keyboard.png | Bin .../res/drawable-mdpi/icon_menu_help.png | Bin .../drawable-mdpi/icon_menu_preferences.png | Bin .../res/drawable-mdpi/icon_menu_settings.png | Bin .../drawable-mdpi/icon_menu_sys_keyboard.png | Bin .../drawable-mdpi/icon_menu_touch_pointer.png | Bin .../main}/res/drawable-mdpi/icon_star_off.png | Bin .../main}/res/drawable-mdpi/icon_star_on.png | Bin .../res/drawable-mdpi/search_plate.9.png | Bin .../res/drawable-mdpi/sym_keyboard_delete.png | Bin .../sym_keyboard_feedback_delete.png | Bin .../sym_keyboard_feedback_return.png | Bin .../res/drawable-mdpi/sym_keyboard_return.png | Bin .../main}/res/drawable/button_background.xml | 0 .../main}/res/drawable/icon_button_cancel.png | Bin .../res/drawable/icon_launcher_freerdp.png | Bin .../res/drawable/separator_background.xml | 0 .../res/drawable/sym_keyboard_arrows.png | Bin .../drawable/sym_keyboard_arrows_black.png | Bin .../res/drawable/sym_keyboard_down_arrow.png | Bin .../sym_keyboard_down_arrow_black.png | Bin .../res/drawable/sym_keyboard_left_arrow.png | Bin .../sym_keyboard_left_arrow_black.png | Bin .../main}/res/drawable/sym_keyboard_menu.png | Bin .../res/drawable/sym_keyboard_menu_black.png | Bin .../res/drawable/sym_keyboard_right_arrow.png | Bin .../sym_keyboard_right_arrow_black.png | Bin .../res/drawable/sym_keyboard_up_arrow.png | Bin .../drawable/sym_keyboard_up_arrow_black.png | Bin .../res/drawable/sym_keyboard_winkey.png | Bin .../drawable/sym_keyboard_winkey_black.png | Bin .../res/drawable/touch_pointer_active.png | Bin .../res/drawable/touch_pointer_default.png | Bin .../drawable/touch_pointer_extkeyboard.png | Bin .../res/drawable/touch_pointer_keyboard.png | Bin .../res/drawable/touch_pointer_lclick.png | Bin .../res/drawable/touch_pointer_rclick.png | Bin .../res/drawable/touch_pointer_reset.png | Bin .../res/drawable/touch_pointer_scroll.png | Bin .../main}/res/layout/bookmark_list_item.xml | 0 .../main}/res/layout/button_preference.xml | 0 .../src/main}/res/layout/credentials.xml | 0 .../res/layout/dont_show_again_dialog.xml | 0 .../freeRDPCore/src/main}/res/layout/home.xml | 2 +- .../src/main}/res/layout/list_header.xml | 0 .../src/main}/res/layout/session.xml | 2 +- .../main}/res/layout/session_list_item.xml | 0 .../src/main}/res/layout/super_bar.xml | 0 .../main}/res/menu/bookmark_context_menu.xml | 0 .../src/main}/res/menu/home_menu.xml | 0 .../src/main}/res/menu/session_menu.xml | 0 .../src/main}/res/values-de/strings.xml | 2 +- .../src/main}/res/values-es/strings.xml | 2 +- .../src/main}/res/values-fr/strings.xml | 0 .../src/main}/res/values-land/dimens.xml | 0 .../src/main}/res/values-nl/strings.xml | 2 +- .../src/main}/res/values-zh/strings.xml | 2 +- .../src/main}/res/values/attrs.xml | 0 .../src/main}/res/values/dimens.xml | 0 .../src/main}/res/values/integers.xml | 0 .../src/main}/res/values/strings.xml | 5 +- .../src/main}/res/values/theme.xml | 2 +- .../src/main}/res/xml/advanced_settings.xml | 0 .../main}/res/xml/application_settings.xml | 0 .../src/main}/res/xml/bookmark_settings.xml | 0 .../main}/res/xml/credentials_settings.xml | 0 .../src/main}/res/xml/cursor_keyboard.xml | 0 .../src/main}/res/xml/debug_settings.xml | 0 .../src/main}/res/xml/gateway_settings.xml | 0 .../src/main}/res/xml/modifiers_keyboard.xml | 0 .../src/main}/res/xml/numpad_keyboard.xml | 0 .../src/main}/res/xml/performance_flags.xml | 8 +- .../main}/res/xml/performance_flags_3g.xml | 0 .../src/main}/res/xml/screen_settings.xml | 0 .../src/main}/res/xml/screen_settings_3g.xml | 0 .../main}/res/xml/specialkeys_keyboard.xml | 0 .../Studio/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + client/Android/Studio/gradlew | 160 ++ client/Android/Studio/gradlew.bat | 90 ++ client/Android/Studio/settings.gradle | 2 + client/Android/aFreeRDP/.classpath | 9 - client/Android/aFreeRDP/.gitignore | 4 - client/Android/aFreeRDP/.project | 98 -- client/Android/aFreeRDP/CMakeLists.txt | 74 - client/Android/aFreeRDP/ant.properties.cmake | 19 - client/Android/aFreeRDP/build.xml.cmake | 91 -- client/Android/aFreeRDP/jni/Android.mk.cmake | 1 - .../Android/aFreeRDP/jni/Application.mk.cmake | 1 - client/Android/aFreeRDP/jni/CMakeLists.txt | 22 - client/Android/aFreeRDP/lint.xml | 3 - .../Android/aFreeRDP/local.properties.cmake | 2 - client/Android/aFreeRDP/proguard-project.txt | 20 - .../Android/aFreeRDP/project.properties.cmake | 13 - .../{FreeRDPCore/jni => }/android_cliprdr.c | 1 - .../{FreeRDPCore/jni => }/android_cliprdr.h | 2 + .../{FreeRDPCore/jni => }/android_event.c | 208 +-- .../{FreeRDPCore/jni => }/android_event.h | 23 +- client/Android/android_freerdp.c | 1148 +++++++++++++++ client/Android/android_freerdp.h | 45 + .../jni/generated => }/android_freerdp_jni.h | 4 +- .../jni => }/android_jni_callback.c | 39 +- .../jni => }/android_jni_callback.h | 2 +- .../{FreeRDPCore/jni => }/android_jni_utils.c | 59 +- .../{FreeRDPCore/jni => }/android_jni_utils.h | 5 +- 275 files changed, 2711 insertions(+), 3568 deletions(-) delete mode 100644 client/Android/.gitignore delete mode 100644 client/Android/FreeRDPCore/.classpath delete mode 100644 client/Android/FreeRDPCore/.gitignore delete mode 100644 client/Android/FreeRDPCore/.project delete mode 100644 client/Android/FreeRDPCore/CMakeLists.txt delete mode 100644 client/Android/FreeRDPCore/ant.properties.cmake delete mode 100644 client/Android/FreeRDPCore/build.xml.cmake delete mode 100644 client/Android/FreeRDPCore/jni/Android.mk.cmake delete mode 100644 client/Android/FreeRDPCore/jni/Application.mk.cmake delete mode 100644 client/Android/FreeRDPCore/jni/CMakeLists.txt delete mode 100644 client/Android/FreeRDPCore/jni/android_debug.h delete mode 100644 client/Android/FreeRDPCore/jni/android_freerdp.c delete mode 100644 client/Android/FreeRDPCore/jni/android_freerdp.h delete mode 100644 client/Android/FreeRDPCore/jni/generated/android_freerdp_jni.c delete mode 100644 client/Android/FreeRDPCore/jni/generated/com_freerdp_freerdpcore_services_LibFreeRDP.h delete mode 100644 client/Android/FreeRDPCore/lint.xml delete mode 100644 client/Android/FreeRDPCore/local.properties.cmake delete mode 100644 client/Android/FreeRDPCore/project.properties.cmake delete mode 100644 client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java delete mode 100644 client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/BookmarkDB.java delete mode 100644 client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/LibFreeRDP.java delete mode 100644 client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/BuildConfiguration.java.in delete mode 100644 client/Android/ModuleOptions.cmake create mode 100644 client/Android/Studio/.gitignore create mode 100644 client/Android/Studio/aFreeRDP/build.gradle create mode 100644 client/Android/Studio/aFreeRDP/lint.xml rename client/Android/{aFreeRDP/AndroidManifest.xml.cmake => Studio/aFreeRDP/src/main/AndroidManifest.xml} (90%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/FreeRDP_Logo.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/about_page/about.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/about_page/about_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/about_page/background_transparent.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/background.jpg (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_about_page/about.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_about_page/about_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_about_page/background_transparent.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/gestures.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/gestures.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/gestures_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/gestures_phone.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/nav_gestures.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/nav_toolbar.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/nav_touch_pointer.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/toolbar.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/toolbar.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/toolbar_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/toolbar_phone.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/touch_pointer.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/touch_pointer.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/touch_pointer_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/de_help_page/touch_pointer_phone.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/gestures.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/gestures.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/gestures_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/gestures_phone.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/nav_gestures.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/nav_toolbar.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/nav_touch_pointer.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/toolbar.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/toolbar.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/toolbar_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/toolbar_phone.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/touch_pointer.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/touch_pointer.png (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/touch_pointer_phone.html (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/assets/help_page/touch_pointer_phone.png (100%) rename client/Android/{aFreeRDP/src => Studio/aFreeRDP/src/main/java}/com/freerdp/afreerdp/application/GlobalApp.java (100%) rename client/Android/{FreeRDPCore => Studio/aFreeRDP/src/main}/res/drawable-hdpi/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/aFreeRDP/src/main}/res/drawable-ldpi/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/aFreeRDP/src/main}/res/drawable-mdpi/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/aFreeRDP/src/main}/res/drawable/button_background.xml (100%) rename client/Android/{FreeRDPCore => Studio/aFreeRDP/src/main}/res/drawable/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/aFreeRDP/src/main}/res/drawable/separator_background.xml (100%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/res/values-es/strings.xml (80%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/res/values-fr/strings.xml (80%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/res/values-nl/strings.xml (80%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/res/values/strings.xml (80%) rename client/Android/{aFreeRDP => Studio/aFreeRDP/src/main}/res/xml/searchable.xml (100%) create mode 100644 client/Android/Studio/build.gradle create mode 100644 client/Android/Studio/freeRDPCore/build.gradle create mode 100644 client/Android/Studio/freeRDPCore/lint.xml rename client/Android/{FreeRDPCore/AndroidManifest.xml.cmake => Studio/freeRDPCore/src/main/AndroidManifest.xml} (86%) create mode 100644 client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/GlobalApp.java rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/application/GlobalSettings.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/application/NetworkStateReceiver.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/application/ScreenReceiver.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/application/SessionState.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/domain/BookmarkBase.java (98%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/domain/ConnectionReference.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/domain/ManualBookmark.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/domain/PlaceholderBookmark.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/domain/QuickConnectBookmark.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/AboutActivity.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/ApplicationSettingsActivity.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/BookmarkActivity.java (98%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/HelpActivity.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/HomeActivity.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/ScrollView2D.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/SessionActivity.java (91%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/SessionView.java (99%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/ShortcutsActivity.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/presentation/TouchPointerView.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/services/BookmarkBaseGateway.java (100%) create mode 100644 client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/BookmarkDB.java rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/services/FreeRDPSuggestionProvider.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/services/HistoryDB.java (100%) create mode 100644 client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/services/ManualBookmarkGateway.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/services/QuickConnectHistoryGateway.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/services/SessionRequestHandlerActivity.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/BookmarkArrayAdapter.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/ButtonPreference.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/ClipboardManagerProxy.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/DoubleGestureDetector.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/GestureDetector.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/IntEditTextPreference.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/IntListPreference.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/KeyboardMapper.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/Mouse.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/RDPFileParser.java (100%) rename client/Android/{FreeRDPCore/src => Studio/freeRDPCore/src/main/java}/com/freerdp/freerdpcore/utils/SeparatedListAdapter.java (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_button_add.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_edittext_clear.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_edittext_search.png (100%) rename client/Android/{aFreeRDP => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_about.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_add.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_close.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_disconnect.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_ext_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_help.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_preferences.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_settings.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_sys_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_menu_touch_pointer.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_star_off.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/icon_star_on.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/search_plate.9.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/sym_keyboard_delete.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/sym_keyboard_feedback_delete.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/sym_keyboard_feedback_return.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-hdpi/sym_keyboard_return.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_button_add.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_edittext_search.png (100%) rename client/Android/{aFreeRDP => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_about.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_add.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_disconnect.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_exit.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_ext_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_help.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_preferences.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_settings.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_sys_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_menu_touch_pointer.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_star_off.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/icon_star_on.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/search_plate.9.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/sym_keyboard_delete.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/sym_keyboard_feedback_delete.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/sym_keyboard_feedback_return.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-ldpi/sym_keyboard_return.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_button_add.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_edittext_clear.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_edittext_search.png (100%) rename client/Android/{aFreeRDP => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_launcher_freerdp.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_about.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_add.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_disconnect.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_exit.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_ext_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_help.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_preferences.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_settings.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_sys_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_menu_touch_pointer.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_star_off.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/icon_star_on.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/search_plate.9.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/sym_keyboard_delete.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/sym_keyboard_feedback_delete.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/sym_keyboard_feedback_return.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable-mdpi/sym_keyboard_return.png (100%) rename client/Android/{aFreeRDP => Studio/freeRDPCore/src/main}/res/drawable/button_background.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/icon_button_cancel.png (100%) rename client/Android/{aFreeRDP => Studio/freeRDPCore/src/main}/res/drawable/icon_launcher_freerdp.png (100%) rename client/Android/{aFreeRDP => Studio/freeRDPCore/src/main}/res/drawable/separator_background.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_arrows.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_arrows_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_down_arrow.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_down_arrow_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_left_arrow.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_left_arrow_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_menu.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_menu_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_right_arrow.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_right_arrow_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_up_arrow.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_up_arrow_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_winkey.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/sym_keyboard_winkey_black.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_active.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_default.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_extkeyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_keyboard.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_lclick.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_rclick.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_reset.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/drawable/touch_pointer_scroll.png (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/bookmark_list_item.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/button_preference.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/credentials.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/dont_show_again_dialog.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/home.xml (95%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/list_header.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/session.xml (98%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/session_list_item.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/layout/super_bar.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/menu/bookmark_context_menu.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/menu/home_menu.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/menu/session_menu.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values-de/strings.xml (99%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values-es/strings.xml (97%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values-fr/strings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values-land/dimens.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values-nl/strings.xml (99%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values-zh/strings.xml (99%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values/attrs.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values/dimens.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values/integers.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values/strings.xml (98%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/values/theme.xml (98%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/advanced_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/application_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/bookmark_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/credentials_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/cursor_keyboard.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/debug_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/gateway_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/modifiers_keyboard.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/numpad_keyboard.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/performance_flags.xml (77%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/performance_flags_3g.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/screen_settings.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/screen_settings_3g.xml (100%) rename client/Android/{FreeRDPCore => Studio/freeRDPCore/src/main}/res/xml/specialkeys_keyboard.xml (100%) create mode 100644 client/Android/Studio/gradle/wrapper/gradle-wrapper.jar create mode 100644 client/Android/Studio/gradle/wrapper/gradle-wrapper.properties create mode 100755 client/Android/Studio/gradlew create mode 100644 client/Android/Studio/gradlew.bat create mode 100644 client/Android/Studio/settings.gradle delete mode 100644 client/Android/aFreeRDP/.classpath delete mode 100644 client/Android/aFreeRDP/.gitignore delete mode 100644 client/Android/aFreeRDP/.project delete mode 100644 client/Android/aFreeRDP/CMakeLists.txt delete mode 100644 client/Android/aFreeRDP/ant.properties.cmake delete mode 100644 client/Android/aFreeRDP/build.xml.cmake delete mode 100644 client/Android/aFreeRDP/jni/Android.mk.cmake delete mode 100644 client/Android/aFreeRDP/jni/Application.mk.cmake delete mode 100644 client/Android/aFreeRDP/jni/CMakeLists.txt delete mode 100644 client/Android/aFreeRDP/lint.xml delete mode 100644 client/Android/aFreeRDP/local.properties.cmake delete mode 100644 client/Android/aFreeRDP/proguard-project.txt delete mode 100644 client/Android/aFreeRDP/project.properties.cmake rename client/Android/{FreeRDPCore/jni => }/android_cliprdr.c (99%) rename client/Android/{FreeRDPCore/jni => }/android_cliprdr.h (96%) rename client/Android/{FreeRDPCore/jni => }/android_event.c (63%) rename client/Android/{FreeRDPCore/jni => }/android_event.h (68%) create mode 100644 client/Android/android_freerdp.c create mode 100644 client/Android/android_freerdp.h rename client/Android/{FreeRDPCore/jni/generated => }/android_freerdp_jni.h (90%) rename client/Android/{FreeRDPCore/jni => }/android_jni_callback.c (82%) rename client/Android/{FreeRDPCore/jni => }/android_jni_callback.h (93%) rename client/Android/{FreeRDPCore/jni => }/android_jni_utils.c (79%) rename client/Android/{FreeRDPCore/jni => }/android_jni_utils.h (89%) diff --git a/client/Android/.gitignore b/client/Android/.gitignore deleted file mode 100644 index 5eb07b8f5..000000000 --- a/client/Android/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Ignore directories -bin/ -obj/ -gen/ -jni/external/* -!libs -libs/armeabi* -AndroidManifest.xml -local.properties -!.project -appcompat_v7 - -FreeRDPCore/project.properties -FreeRDPCore/src/com/freerdp/freerdpcore/utils/BuildConfiguration.java -aFreeRDP/project.properties diff --git a/client/Android/CMakeLists.txt b/client/Android/CMakeLists.txt index 1ddef5ba6..d238eb6d2 100644 --- a/client/Android/CMakeLists.txt +++ b/client/Android/CMakeLists.txt @@ -1,6 +1,7 @@ # FreeRDP: A Remote Desktop Protocol Implementation # Android Client # +# Copyright 2012 Marc-Andre Moreau # Copyright 2013 Bernhard Miklautz # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,68 +16,39 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (NOT ANDROID_NDK) - message(FATAL_ERROR "ANDROID_NDK not set but required for building android native library.") +set(MODULE_NAME "freerdp-android") +set(MODULE_PREFIX "FREERDP_CLIENT_ANDROID") + +include_directories(.) + +if(CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-sign") endif() -set(CMAKE_PROGRAM_PATH ${ANDROID_NDK}) -find_program(NDK_COMMAND ndk-build CMAKE_FIND_ROOT_PATH_BOTH) +set(${MODULE_PREFIX}_SRCS + android_event.c + android_event.h + android_freerdp.c + android_freerdp.h + android_jni_utils.c + android_jni_utils.h + android_jni_callback.c + android_jni_callback.h) -if(NDK_COMMAND STREQUAL "NDK_COMMAND-NOTFOUND") - message(FATAL_ERROR "ndk-build not found but required to build native lib") +if(WITH_CLIENT_CHANNELS) + set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} + android_cliprdr.c + android_cliprdr.h) endif() -set(NDK_LIB_CFG "${CMAKE_CURRENT_BINARY_DIR}/FreeRDPCore/jni/Android.mk") -if(ANDROID_BUILD_JAVA) - if (NOT ANDROID_SDK) - message(FATAL_ERROR "ANDROID_SDK not set but required for building the java gui (ANDROID_BUILD_JAVA)") - endif() - # And isn't shiped with the android ndk/sdk so - # we need to find it on the local machine - SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) - find_program(ANT_COMMAND ant) - SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) +add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS}) - if(ANT_COMMAND STREQUAL "ANT_COMMAND-NOTFOUND") - message(FATAL_ERROR "ant not found but required to build android java") - endif() -endif(ANDROID_BUILD_JAVA) +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-client) +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) -set(ANDROID_COMMAND "${ANDROID_SDK}/tools/android") -if(NOT EXISTS ${ANDROID_COMMAND}) - message(FATAL_ERROR "android not found but required to build android java") -endif() +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} dl) +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} log) +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} jnigraphics) -if(ANDROID_BUILD_JAVA_DEBUG) - set(ANDROID_BUILD_TYPE "debug") -else() - set(ANDROID_BUILD_TYPE "release") -endif() - -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set(ANDROID_DEBUG_ENABLE "true") - set(NDK_DEBUG "1") -else() - set(ANDROID_DEBUG_ENABLE "false") - set(NDK_DEBUG "0") -endif() - -set(APPCOMPAT_DIR "${CMAKE_CURRENT_BINARY_DIR}/appcompat_v7") -set(supportdir "${ANDROID_SDK}/extras/android/support/v7/appcompat") -set(compatibilitydir "${ANDROID_SDK}/extras/android/compatibility/v7/appcompat") -if(EXISTS "${supportdir}" AND IS_DIRECTORY "${supportdir}") - add_custom_target(copy_appcompat ALL - COMMAND ${CMAKE_COMMAND} -E copy_directory "${supportdir}" ${APPCOMPAT_DIR} - COMMAND ${ANDROID_COMMAND} update lib-project -p ${APPCOMPAT_DIR} -t android-${ANDROID_APP_TARGET_SDK} - ) -elseif(EXISTS "${compatibilitydir}" AND IS_DIRECTORY "${compatibilitydir}") - add_custom_target(copy_appcompat ALL - COMMAND ${CMAKE_COMMAND} -E copy_directory "${compatibilitydir}" ${APPCOMPAT_DIR} - COMMAND ${ANDROID_COMMAND} update lib-project -p ${APPCOMPAT_DIR} -t android-${ANDROID_APP_TARGET_SDK} - ) -else() - message( FATAL_ERROR "${ANDROID_SDK}/extras/android/{support|compatibility}/v7/appcompat directory not found. Please install a recent version of Android Support Library, CMake will now exit." ) -endif() - -add_subdirectory(FreeRDPCore) -add_subdirectory(aFreeRDP) +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT AndroidTargets) diff --git a/client/Android/FreeRDPCore/.classpath b/client/Android/FreeRDPCore/.classpath deleted file mode 100644 index 51769745b..000000000 --- a/client/Android/FreeRDPCore/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/client/Android/FreeRDPCore/.gitignore b/client/Android/FreeRDPCore/.gitignore deleted file mode 100644 index 2d8df2acd..000000000 --- a/client/Android/FreeRDPCore/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -ant.properties -build.xml -jni/Android.mk -jni/Application.mk diff --git a/client/Android/FreeRDPCore/.project b/client/Android/FreeRDPCore/.project deleted file mode 100644 index bfc09afd1..000000000 --- a/client/Android/FreeRDPCore/.project +++ /dev/null @@ -1,53 +0,0 @@ - - - FreeRDPCore - - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - diff --git a/client/Android/FreeRDPCore/CMakeLists.txt b/client/Android/FreeRDPCore/CMakeLists.txt deleted file mode 100644 index a95f11f2d..000000000 --- a/client/Android/FreeRDPCore/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# FreeRDP: A Remote Desktop Protocol Implementation -# Android Client -# -# Copyright 2012 Marc-Andre Moreau -# Copyright 2013 Bernhard Miklautz -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set(ANDROID_PACKAGE_NAME "aFreeRDPCore") - -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest.xml.cmake - ${CMAKE_CURRENT_BINARY_DIR}/AndroidManifest.xml @ONLY) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build.xml.cmake - ${CMAKE_CURRENT_BINARY_DIR}/build.xml @ONLY) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/project.properties.cmake - ${CMAKE_CURRENT_BINARY_DIR}/project.properties @ONLY) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ant.properties.cmake - ${CMAKE_CURRENT_BINARY_DIR}/ant.properties @ONLY) - -# Generate a Java class with static members set to the CMake -# configuration properties. -set(JAVA_CFG "src/com/freerdp/freerdpcore/utils/BuildConfiguration.java") -set(JAVA_CFG_OUT "${CMAKE_CURRENT_BINARY_DIR}/${JAVA_CFG}") -set(JAVA_CFG_IN "${CMAKE_CURRENT_SOURCE_DIR}/${JAVA_CFG}.in") - -CONFIGURE_FILE(${JAVA_CFG_IN} ${JAVA_CFG_OUT}) - -file(COPY res DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - -if (ANDROID_SDK) - CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/local.properties.cmake - ${CMAKE_CURRENT_BINARY_DIR}/local.properties @ONLY) -endif() - -add_subdirectory(jni) - -SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "gen;bin;obj;libs") - diff --git a/client/Android/FreeRDPCore/ant.properties.cmake b/client/Android/FreeRDPCore/ant.properties.cmake deleted file mode 100644 index 83cd860ec..000000000 --- a/client/Android/FreeRDPCore/ant.properties.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked into Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. -build.dir=@CMAKE_CURRENT_BINARY_DIR@ -source.path=@CMAKE_CURRENT_SOURCE_DIR@/src:@CMAKE_CURRENT_BINARY_DIR@/src -out.dir=@CMAKE_CURRENT_BINARY_DIR@/bin - diff --git a/client/Android/FreeRDPCore/build.xml.cmake b/client/Android/FreeRDPCore/build.xml.cmake deleted file mode 100644 index f07d7de42..000000000 --- a/client/Android/FreeRDPCore/build.xml.cmake +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/client/Android/FreeRDPCore/jni/Android.mk.cmake b/client/Android/FreeRDPCore/jni/Android.mk.cmake deleted file mode 100644 index 94452ea92..000000000 --- a/client/Android/FreeRDPCore/jni/Android.mk.cmake +++ /dev/null @@ -1,8 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := freerdp-android -LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfreerdp-android.so -LOCAL_EXPORT_C_INCLUDES := ../../../../include -include $(PREBUILT_SHARED_LIBRARY) diff --git a/client/Android/FreeRDPCore/jni/Application.mk.cmake b/client/Android/FreeRDPCore/jni/Application.mk.cmake deleted file mode 100644 index 3655c4062..000000000 --- a/client/Android/FreeRDPCore/jni/Application.mk.cmake +++ /dev/null @@ -1 +0,0 @@ -APP_ABI := @ANDROID_ABI@ diff --git a/client/Android/FreeRDPCore/jni/CMakeLists.txt b/client/Android/FreeRDPCore/jni/CMakeLists.txt deleted file mode 100644 index 2b704b79d..000000000 --- a/client/Android/FreeRDPCore/jni/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -# FreeRDP: A Remote Desktop Protocol Implementation -# Android Client -# -# Copyright 2012 Marc-Andre Moreau -# Copyright 2013 Bernhard Miklautz -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set(MODULE_NAME "freerdp-android") -set(MODULE_PREFIX "FREERDP_CLIENT_ANDROID") - -include_directories(.) -include_directories(generated) - -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Application.mk.cmake - ${CMAKE_CURRENT_BINARY_DIR}/Application.mk @ONLY) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Android.mk.cmake - ${CMAKE_CURRENT_BINARY_DIR}/Android.mk @ONLY) - -if(CMAKE_COMPILER_IS_GNUCC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-sign") -endif() - -set(${MODULE_PREFIX}_SRCS - android_debug.h - android_event.c - android_event.h - android_freerdp.c - android_freerdp.h - android_jni_utils.c - android_jni_utils.h - android_jni_callback.c - android_jni_callback.h) - -set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} - generated/android_freerdp_jni.c - generated/android_freerdp_jni.h) - -if(WITH_CLIENT_CHANNELS) - set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} - android_cliprdr.c - android_cliprdr.h) -endif() - -add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS}) - -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-client) -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) - -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} dl) -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} log) -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} jnigraphics) - -target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) - -file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_ABI}") -set_target_properties(${MODULE_NAME} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_ABI}") - -set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Android") - -get_property(LIB_ABSNAME TARGET ${MODULE_NAME} PROPERTY LOCATION) - diff --git a/client/Android/FreeRDPCore/jni/android_debug.h b/client/Android/FreeRDPCore/jni/android_debug.h deleted file mode 100644 index b48e7f469..000000000 --- a/client/Android/FreeRDPCore/jni/android_debug.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * Android Debug Interface - * - * Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef FREERDP_ANDROID_DEBUG_H -#define FREERDP_ANDROID_DEBUG_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#define ANDROID_TAG CLIENT_TAG("android") -#ifdef WITH_DEBUG_ANDROID_JNI -#define DEBUG_ANDROID(fmt, ...) WLog_DBG(ANDROID_TAG, fmt, ## __VA_ARGS__) -#else -#define DEBUG_ANDROID(fmt, ...) do { } while (0) -#endif - - - -#endif /* FREERDP_ANDROID_DEBUG_H */ - diff --git a/client/Android/FreeRDPCore/jni/android_freerdp.c b/client/Android/FreeRDPCore/jni/android_freerdp.c deleted file mode 100644 index 01bc19122..000000000 --- a/client/Android/FreeRDPCore/jni/android_freerdp.c +++ /dev/null @@ -1,1290 +0,0 @@ -/* - Android JNI Client Layer - - Copyright 2010-2012 Marc-Andre Moreau - Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz - Copyright 2013 Thincast Technologies GmbH, Author: Armin Novak - Copyright 2015 Bernhard Miklautz - - This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "android_freerdp.h" -#include "android_jni_callback.h" -#include "android_jni_utils.h" -#include "android_debug.h" -#include "android_cliprdr.h" - -#if defined(WITH_GPROF) -#include "jni/prof.h" -#endif - - -static BOOL android_context_new(freerdp* instance, rdpContext* context) -{ - if (!(context->channels = freerdp_channels_new())) - return FALSE; - - if (!android_event_queue_init(instance)) - { - freerdp_channels_free(context->channels); - return FALSE; - } - return TRUE; -} - -static void android_context_free(freerdp* instance, rdpContext* context) -{ - if (context && context->channels) - { - freerdp_channels_close(context->channels, instance); - freerdp_channels_free(context->channels); - context->channels = NULL; - } - android_event_queue_uninit(instance); -} - -static void android_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e) -{ - rdpSettings* settings = context->settings; - androidContext* afc = (androidContext*) context; - - if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) - { - DEBUG_ANDROID("Unhandled case.. RDPEI_DVC_CHANNEL_NAME"); - } - else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) - { - if (settings->SoftwareGdi) - gdi_graphics_pipeline_init(context->gdi, (RdpgfxClientContext*) e->pInterface); - } - else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) - { - android_cliprdr_init(afc, (CliprdrClientContext*) e->pInterface); - } -} - -static void android_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e) -{ - rdpSettings* settings = context->settings; - androidContext* afc = (androidContext*) context; - - if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) - { - DEBUG_ANDROID("Unhandled case.. RDPEI_DVC_CHANNEL_NAME"); - } - else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) - { - if (settings->SoftwareGdi) - gdi_graphics_pipeline_uninit(context->gdi, (RdpgfxClientContext*) e->pInterface); - } - else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) - { - android_cliprdr_uninit(afc, (CliprdrClientContext*) e->pInterface); - } -} - -static BOOL android_begin_paint(rdpContext* context) -{ - rdpGdi* gdi = context->gdi; - gdi->primary->hdc->hwnd->invalid->null = 1; - gdi->primary->hdc->hwnd->ninvalid = 0; - return TRUE; -} - -static BOOL android_end_paint(rdpContext* context) -{ - int i; - int ninvalid; - HGDI_RGN cinvalid; - int x1, y1, x2, y2; - androidContext *ctx = (androidContext*)context; - rdpSettings* settings = context->instance->settings; - - assert(ctx); - assert(settings); - assert(context->instance); - - ninvalid = ctx->rdpCtx.gdi->primary->hdc->hwnd->ninvalid; - if (ninvalid == 0) - { - DEBUG_ANDROID("ui_update: ninvalid=%d", ninvalid); - return TRUE; - } - - cinvalid = ctx->rdpCtx.gdi->primary->hdc->hwnd->cinvalid; - - x1 = cinvalid[0].x; - y1 = cinvalid[0].y; - x2 = cinvalid[0].x + cinvalid[0].w; - y2 = cinvalid[0].y + cinvalid[0].h; - - for (i = 0; i < ninvalid; i++) - { - x1 = MIN(x1, cinvalid[i].x); - y1 = MIN(y1, cinvalid[i].y); - x2 = MAX(x2, cinvalid[i].x + cinvalid[i].w); - y2 = MAX(y2, cinvalid[i].y + cinvalid[i].h); - } - - DEBUG_ANDROID("ui_update: ninvalid=%d x=%d, y=%d, width=%d, height=%d, bpp=%d", - ninvalid, x1, y1, x2 - x1, y2 - y1, settings->ColorDepth); - - freerdp_callback("OnGraphicsUpdate", "(IIIII)V", context->instance, - x1, y1, x2 - x1, y2 - y1); - return TRUE; -} - -static BOOL android_desktop_resize(rdpContext* context) -{ - DEBUG_ANDROID("ui_desktop_resize"); - - assert(context); - assert(context->settings); - assert(context->instance); - - freerdp_callback("OnGraphicsResize", "(IIII)V", - context->instance, context->settings->DesktopWidth, - context->settings->DesktopHeight, context->settings->ColorDepth); - return TRUE; -} - -static BOOL android_pre_connect(freerdp* instance) -{ - DEBUG_ANDROID("android_pre_connect"); - - rdpSettings* settings = instance->settings; - BOOL bitmap_cache = settings->BitmapCacheEnabled; - settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE; - settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE; - settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; - settings->OrderSupport[NEG_MEMBLT_INDEX] = bitmap_cache; - settings->OrderSupport[NEG_MEM3BLT_INDEX] = TRUE; - settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = bitmap_cache; - settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE; - settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE; - settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE; - settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE; - settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE; - settings->OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE; - settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE; - settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE; - - settings->FrameAcknowledge = 10; - - PubSub_SubscribeChannelConnected(instance->context->pubSub, - (pChannelConnectedEventHandler) android_OnChannelConnectedEventHandler); - - PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - (pChannelDisconnectedEventHandler) android_OnChannelDisconnectedEventHandler); - - freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0); - freerdp_client_load_addins(instance->context->channels, instance->settings); - - freerdp_channels_pre_connect(instance->context->channels, instance); - - return TRUE; -} - -static BOOL android_post_connect(freerdp* instance) -{ - UINT32 gdi_flags; - rdpSettings *settings = instance->settings; - - DEBUG_ANDROID("android_post_connect"); - - assert(instance); - assert(settings); - - freerdp_callback("OnSettingsChanged", "(IIII)V", instance, - settings->DesktopWidth, settings->DesktopHeight, - settings->ColorDepth); - - if (!(instance->context->cache = cache_new(settings))) - return FALSE; - - if (instance->settings->ColorDepth > 16) - gdi_flags = CLRBUF_32BPP | CLRCONV_ALPHA | CLRCONV_INVERT; - else - gdi_flags = CLRBUF_16BPP; - - if (!gdi_init(instance, gdi_flags, NULL)) - return FALSE; - - instance->update->BeginPaint = android_begin_paint; - instance->update->EndPaint = android_end_paint; - instance->update->DesktopResize = android_desktop_resize; - - if (freerdp_channels_post_connect(instance->context->channels, instance) < 0) - return FALSE; - - freerdp_callback("OnConnectionSuccess", "(I)V", instance); - - return TRUE; -} - -static void android_post_disconnect(freerdp* instance) -{ - DEBUG_ANDROID("android_post_disconnect"); - gdi_free(instance); - cache_free(instance->context->cache); -} - -static BOOL android_authenticate(freerdp* instance, char** username, char** password, char** domain) -{ - DEBUG_ANDROID("Authenticate user:"); - DEBUG_ANDROID(" Username: %s", *username); - DEBUG_ANDROID(" Domain: %s", *domain); - - JNIEnv* env; - jboolean attached = jni_attach_thread(&env); - jobject jstr1 = create_string_builder(env, *username); - jobject jstr2 = create_string_builder(env, *domain); - jobject jstr3 = create_string_builder(env, *password); - - jboolean res = freerdp_callback_bool_result("OnAuthenticate", "(ILjava/lang/StringBuilder;Ljava/lang/StringBuilder;Ljava/lang/StringBuilder;)Z", instance, jstr1, jstr2, jstr3); - - if (res == JNI_TRUE) - { - // read back string values - free(*username); - *username = get_string_from_string_builder(env, jstr1); - - free(*domain); - *domain = get_string_from_string_builder(env, jstr2); - - free(*password); - *password = get_string_from_string_builder(env, jstr3); - } - - if (attached == JNI_TRUE) - jni_detach_thread(); - - return ((res == JNI_TRUE) ? TRUE : FALSE); -} - -static BOOL android_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint) -{ - DEBUG_ANDROID("Certificate details:"); - DEBUG_ANDROID("\tSubject: %s", subject); - DEBUG_ANDROID("\tIssuer: %s", issuer); - DEBUG_ANDROID("\tThumbprint: %s", fingerprint); - DEBUG_ANDROID("The above X.509 certificate could not be verified, possibly because you do not have " - "the CA certificate in your certificate store, or the certificate has expired." - "Please look at the documentation on how to create local certificate store for a private CA.\n"); - - JNIEnv* env; - jboolean attached = jni_attach_thread(&env); - jstring jstr1 = (*env)->NewStringUTF(env, subject); - jstring jstr2 = (*env)->NewStringUTF(env, issuer); - jstring jstr3 = (*env)->NewStringUTF(env, fingerprint); - - jboolean res = freerdp_callback_bool_result("OnVerifyCertificate", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", instance, jstr1, jstr2, jstr3); - - if (attached == JNI_TRUE) - jni_detach_thread(); - - return ((res == JNI_TRUE) ? TRUE : FALSE); -} - -static BOOL android_verify_changed_certificate(freerdp* instance, char* subject, char* issuer, - char* new_fingerprint, char* old_subject, char* old_issuer, char* old_fingerprint) -{ - return android_verify_certificate(instance, subject, issuer, new_fingerprint); -} - -static void* jni_input_thread(void* arg) -{ - HANDLE event[3]; - wMessageQueue* queue; - freerdp* instance = (freerdp*) arg; - androidContext *aCtx = (androidContext*)instance->context; - - assert(NULL != instance); - assert(NULL != aCtx); - - DEBUG_ANDROID("input_thread Start."); - - if (!(queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE))) - goto fail_get_message_queue; - - if (!(event[0] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, - aCtx->event_queue->pipe_fd[0], WINPR_FD_READ))) - goto fail_create_event_0; - - if (!(event[1] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, - aCtx->event_queue->pipe_fd[1], WINPR_FD_READ))) - goto fail_create_event_1; - - if (!(event[2] = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE))) - goto fail_get_message_queue_event; - - do - { - DWORD rc = WaitForMultipleObjects(3, event, FALSE, INFINITE); - if ((rc < WAIT_OBJECT_0) || (rc > WAIT_OBJECT_0 + 2)) - continue; - - if (rc == WAIT_OBJECT_0 + 2) - { - wMessage msg; - - MessageQueue_Peek(queue, &msg, FALSE); - if (msg.id == WMQ_QUIT) - break; - } - if (android_check_fds(instance) != TRUE) - break; - } - while(1); - - DEBUG_ANDROID("input_thread Quit."); - -fail_get_message_queue_event: - CloseHandle(event[1]); -fail_create_event_1: - CloseHandle(event[0]); -fail_create_event_0: - MessageQueue_PostQuit(queue, 0); -fail_get_message_queue: - - ExitThread(0); - return NULL; -} - -static void* jni_channels_thread(void* arg) -{ - int status; - HANDLE event; - rdpChannels* channels; - freerdp* instance = (freerdp*) arg; - - assert(NULL != instance); - - DEBUG_ANDROID("Channels_thread Start."); - - channels = instance->context->channels; - event = freerdp_channels_get_event_handle(instance); - - while (WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0) - { - status = freerdp_channels_process_pending_messages(instance); - - if (!status) - break; - } - - DEBUG_ANDROID("channels_thread Quit."); - - ExitThread(0); - return NULL; -} - -static int android_freerdp_run(freerdp* instance) -{ - int i; - int fds; - int max_fds; - int rcount; - int wcount; - int fd_input_event; - HANDLE input_event = NULL; - void* rfds[32]; - void* wfds[32]; - fd_set rfds_set; - fd_set wfds_set; - int select_status; - struct timeval timeout; - - const rdpSettings* settings = instance->context->settings; - - HANDLE input_thread = NULL; - HANDLE channels_thread = NULL; - - BOOL async_input = settings->AsyncInput; - BOOL async_channels = settings->AsyncChannels; - BOOL async_transport = settings->AsyncTransport; - - DEBUG_ANDROID("AsyncUpdate=%d", settings->AsyncUpdate); - DEBUG_ANDROID("AsyncInput=%d", settings->AsyncInput); - DEBUG_ANDROID("AsyncChannels=%d", settings->AsyncChannels); - DEBUG_ANDROID("AsyncTransport=%d", settings->AsyncTransport); - - memset(rfds, 0, sizeof(rfds)); - memset(wfds, 0, sizeof(wfds)); - - if (!freerdp_connect(instance)) - { - freerdp_callback("OnConnectionFailure", "(I)V", instance); - return 0; - } - - if (async_input) - { - if (!(input_thread = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE) jni_input_thread, instance, 0, NULL))) - { - DEBUG_ANDROID("Failed to create async input thread\n"); - goto disconnect; - } - } - - if (async_channels) - { - if (!(channels_thread = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE) jni_channels_thread, instance, 0, NULL))) - { - DEBUG_ANDROID("Failed to create async channels thread\n"); - goto disconnect; - } - } - - ((androidContext*)instance->context)->is_connected = TRUE; - while (!freerdp_shall_disconnect(instance)) - { - rcount = 0; - wcount = 0; - - if (!async_transport) - { - if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) - { - DEBUG_ANDROID("Failed to get FreeRDP file descriptor\n"); - break; - } - } - - if (!async_channels) - { - if (freerdp_channels_get_fds(instance->context->channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) - { - DEBUG_ANDROID("Failed to get channel manager file descriptor\n"); - break; - } - } - - if (!async_input) - { - if (android_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) - { - DEBUG_ANDROID("Failed to get android file descriptor\n"); - break; - } - } - else - { - input_event = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE); - fd_input_event = GetEventFileDescriptor(input_event); - rfds[rcount++] = (void*) (long) fd_input_event; - } - - max_fds = 0; - FD_ZERO(&rfds_set); - FD_ZERO(&wfds_set); - - for (i = 0; i < rcount; i++) - { - fds = (int)(long)(rfds[i]); - - if (fds > max_fds) - max_fds = fds; - - FD_SET(fds, &rfds_set); - } - - if (max_fds == 0) - break; - - timeout.tv_sec = 1; - timeout.tv_usec = 0; - - select_status = select(max_fds + 1, &rfds_set, NULL, NULL, &timeout); - - if (select_status == 0) - continue; - else if (select_status == -1) - { - /* these are not really errors */ - if (!((errno == EAGAIN) || - (errno == EWOULDBLOCK) || - (errno == EINPROGRESS) || - (errno == EINTR))) /* signal occurred */ - { - DEBUG_ANDROID("android_run: select failed\n"); - break; - } - } - - if (freerdp_shall_disconnect(instance)) - break; - - if (!async_transport) - { - if (freerdp_check_fds(instance) != TRUE) - { - DEBUG_ANDROID("Failed to check FreeRDP file descriptor\n"); - break; - } - } - - if (!async_input) - { - if (android_check_fds(instance) != TRUE) - { - DEBUG_ANDROID("Failed to check android file descriptor\n"); - break; - } - } - else if (input_event) - { - if (WaitForSingleObject(input_event, 0) == WAIT_OBJECT_0) - { - if (!freerdp_message_queue_process_pending_messages(instance, - FREERDP_INPUT_MESSAGE_QUEUE)) - { - DEBUG_ANDROID("User Disconnect"); - break; - } - } - } - - if (!async_channels) - { - if (freerdp_channels_check_fds(instance->context->channels, instance) != TRUE) - { - DEBUG_ANDROID("Failed to check channel manager file descriptor\n"); - break; - } - } - } - -disconnect: - DEBUG_ANDROID("Prepare shutdown..."); - - // issue another OnDisconnecting here in case the disconnect was initiated by the server and not our client - freerdp_callback("OnDisconnecting", "(I)V", instance); - - DEBUG_ANDROID("Close channels..."); - freerdp_channels_disconnect(instance->context->channels, instance); - - DEBUG_ANDROID("Cleanup threads..."); - - if (async_channels && channels_thread) - { - WaitForSingleObject(channels_thread, INFINITE); - CloseHandle(channels_thread); - } - - if (async_input && input_thread) - { - wMessageQueue* input_queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE); - if (input_queue) - { - if (MessageQueue_PostQuit(input_queue, 0)) - WaitForSingleObject(input_thread, INFINITE); - } - CloseHandle(input_thread); - } - - DEBUG_ANDROID("run Disconnecting..."); - freerdp_disconnect(instance); - freerdp_callback("OnDisconnected", "(I)V", instance); - - DEBUG_ANDROID("run Quit."); - - return 0; -} - -static void* android_thread_func(void* param) -{ - freerdp* instance = param; - - DEBUG_ANDROID("android_thread_func Start."); - - assert(instance); - - android_freerdp_run(instance); - - DEBUG_ANDROID("android_thread_func Quit."); - - ExitThread(0); - return NULL; -} - -JNIEXPORT jint JNICALL jni_freerdp_new(JNIEnv *env, jclass cls) -{ - freerdp* instance; - -#if defined(WITH_GPROF) - setenv("CPUPROFILE_FREQUENCY", "200", 1); - monstartup("libfreerdp-android.so"); -#endif - - // create instance - if (!(instance = freerdp_new())) - return (jint)NULL; - instance->PreConnect = android_pre_connect; - instance->PostConnect = android_post_connect; - instance->PostDisconnect = android_post_disconnect; - instance->Authenticate = android_authenticate; - instance->VerifyCertificate = android_verify_certificate; - instance->VerifyChangedCertificate = android_verify_changed_certificate; - - // create context - instance->ContextSize = sizeof(androidContext); - instance->ContextNew = android_context_new; - instance->ContextFree = android_context_free; - - if (!freerdp_context_new(instance)) - { - freerdp_free(instance); - instance = NULL; - } - - return (jint) instance; -} - -JNIEXPORT void JNICALL jni_freerdp_free(JNIEnv *env, jclass cls, jint instance) -{ - freerdp* inst = (freerdp*)instance; - - freerdp_context_free(inst); - freerdp_free(inst); - -#if defined(WITH_GPROF) - moncleanup(); -#endif -} - -JNIEXPORT jboolean JNICALL jni_freerdp_connect(JNIEnv *env, jclass cls, jint instance) -{ - freerdp* inst = (freerdp*)instance; - androidContext* ctx = (androidContext*)inst->context; - - assert(inst); - assert(ctx); - - if (!(ctx->thread = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE)android_thread_func, inst, 0, NULL))) - { - return JNI_FALSE; - } - - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_disconnect(JNIEnv *env, jclass cls, jint instance) -{ - freerdp* inst = (freerdp*)instance; - androidContext* ctx = (androidContext*)inst->context; - ANDROID_EVENT* event = (ANDROID_EVENT*)android_event_disconnect_new(); - if (!event) - return JNI_FALSE; - - DEBUG_ANDROID("DISCONNECT!"); - - assert(inst); - assert(ctx); - assert(event); - - if (!android_push_event(inst, event)) - { - android_event_disconnect_free(event); - return JNI_FALSE; - } - - WaitForSingleObject(ctx->thread, INFINITE); - CloseHandle(ctx->thread); - ctx->thread = NULL; - - freerdp_callback("OnDisconnecting", "(I)V", instance); - - return (jboolean) JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_cancel_connection(JNIEnv *env, jclass cls, jint instance) -{ - return jni_freerdp_disconnect(env, cls, instance); -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, jint instance, jstring jdirectory) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - - const jbyte* directory = (*env)->GetStringUTFChars(env, jdirectory, NULL); - if (!directory) - return JNI_FALSE; - - free(settings->HomePath); - free(settings->ConfigPath); - settings->HomePath = settings->ConfigPath = NULL; - - int config_dir_len = strlen(directory) + 10; /* +9 chars for /.freerdp and +1 for \0 */ - char* config_dir_buf = (char*)malloc(config_dir_len); - if (!config_dir_buf) - goto out_malloc_fail; - - strcpy(config_dir_buf, directory); - strcat(config_dir_buf, "/.freerdp"); - settings->HomePath = strdup(directory); - if (!settings->HomePath) - goto out_strdup_fail; - settings->ConfigPath = config_dir_buf; /* will be freed by freerdp library */ - - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); - return JNI_TRUE; - -out_strdup_fail: - free(config_dir_buf); -out_malloc_fail: - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); - return JNI_FALSE; - -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, jint instance, - jstring jhostname, jstring jusername, jstring jpassword, jstring jdomain, jint width, jint height, - jint color_depth, jint port, jboolean console, jint security, jstring jcertname) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - - const jbyte *hostname; - const jbyte *username; - const jbyte *password; - const jbyte *domain; - const jbyte *certname; - - if(!(hostname = (*env)->GetStringUTFChars(env, jhostname, NULL))) - return JNI_FALSE; - if (!(username = (*env)->GetStringUTFChars(env, jusername, NULL))) - goto out_fail_username; - if (!(password = (*env)->GetStringUTFChars(env, jpassword, NULL))) - goto out_fail_password; - if (!(domain = (*env)->GetStringUTFChars(env, jdomain, NULL))) - goto out_fail_domain; - if (!(certname = (*env)->GetStringUTFChars(env, jcertname, NULL))) - goto out_fail_certname; - - - DEBUG_ANDROID("hostname: %s", (char*) hostname); - DEBUG_ANDROID("username: %s", (char*) username); - DEBUG_ANDROID("password: %s", (char*) password); - DEBUG_ANDROID("domain: %s", (char*) domain); - DEBUG_ANDROID("width: %d", width); - DEBUG_ANDROID("height: %d", height); - DEBUG_ANDROID("color depth: %d", color_depth); - DEBUG_ANDROID("port: %d", port); - DEBUG_ANDROID("security: %d", security); - - settings->DesktopWidth = width; - settings->DesktopHeight = height; - settings->ColorDepth = color_depth; - settings->ServerPort = port; - - // Hack for 16 bit RDVH connections: - // In this case we get screen corruptions when we have an odd screen resolution width ... need to investigate what is causing this... - if (color_depth <= 16) - settings->DesktopWidth &= (~1); - - if (!(settings->ServerHostname = strdup(hostname))) - goto out_fail_strdup; - - if (username && strlen(username) > 0) - { - if (!(settings->Username = strdup(username))) - goto out_fail_strdup; - } - - if (password && strlen(password) > 0) - { - if (!(settings->Password = strdup(password))) - goto out_fail_strdup; - settings->AutoLogonEnabled = TRUE; - } - - if (!(settings->Domain = strdup(domain))) - goto out_fail_strdup; - - if (certname && strlen(certname) > 0) - { - if (!(settings->CertificateName = strdup(certname))) - goto out_fail_strdup; - } - - settings->ConsoleSession = (console == JNI_TRUE) ? TRUE : FALSE; - - settings->SoftwareGdi = TRUE; - settings->BitmapCacheV3Enabled = TRUE; - - switch ((int) security) - { - case 1: - /* Standard RDP */ - settings->RdpSecurity = TRUE; - settings->TlsSecurity = FALSE; - settings->NlaSecurity = FALSE; - settings->ExtSecurity = FALSE; - settings->UseRdpSecurityLayer = TRUE; - break; - - case 2: - /* TLS */ - settings->NlaSecurity = FALSE; - settings->TlsSecurity = TRUE; - settings->RdpSecurity = FALSE; - settings->ExtSecurity = FALSE; - break; - - case 3: - /* NLA */ - settings->NlaSecurity = TRUE; - settings->TlsSecurity = FALSE; - settings->RdpSecurity = FALSE; - settings->ExtSecurity = FALSE; - break; - - default: - break; - } - - // set US keyboard layout - settings->KeyboardLayout = 0x0409; - - (*env)->ReleaseStringUTFChars(env, jhostname, hostname); - (*env)->ReleaseStringUTFChars(env, jusername, username); - (*env)->ReleaseStringUTFChars(env, jpassword, password); - (*env)->ReleaseStringUTFChars(env, jdomain, domain); - (*env)->ReleaseStringUTFChars(env, jcertname, certname); - - return JNI_TRUE; - - -out_fail_strdup: - (*env)->ReleaseStringUTFChars(env, jcertname, certname); -out_fail_certname: - (*env)->ReleaseStringUTFChars(env, jdomain, domain); -out_fail_domain: - (*env)->ReleaseStringUTFChars(env, jpassword, password); -out_fail_password: - (*env)->ReleaseStringUTFChars(env, jusername, username); -out_fail_username: - (*env)->ReleaseStringUTFChars(env, jhostname, hostname); - return JNI_FALSE; -} - -JNIEXPORT void JNICALL jni_freerdp_set_performance_flags( - JNIEnv *env, jclass cls, jint instance, jboolean remotefx, - jboolean disableWallpaper, jboolean disableFullWindowDrag, - jboolean disableMenuAnimations, jboolean disableTheming, - jboolean enableFontSmoothing, jboolean enableDesktopComposition) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - - DEBUG_ANDROID("remotefx: %d", (remotefx == JNI_TRUE) ? 1 : 0); - if (remotefx == JNI_TRUE) - { - settings->RemoteFxCodec = TRUE; - settings->FastPathOutput = TRUE; - settings->ColorDepth = 32; - settings->LargePointerFlag = TRUE; - settings->FrameMarkerCommandEnabled = TRUE; - } - else - { - /* enable NSCodec if we don't use remotefx */ - settings->NSCodec = TRUE; - } - - /* store performance settings */ - settings->DisableWallpaper = (disableWallpaper == JNI_TRUE) ? TRUE : FALSE; - settings->DisableFullWindowDrag = (disableFullWindowDrag == JNI_TRUE) ? TRUE : FALSE; - settings->DisableMenuAnims = (disableMenuAnimations == JNI_TRUE) ? TRUE : FALSE; - settings->DisableThemes = (disableTheming == JNI_TRUE) ? TRUE : FALSE; - settings->AllowFontSmoothing = (enableFontSmoothing == JNI_TRUE) ? TRUE : FALSE; - settings->AllowDesktopComposition = (enableDesktopComposition == JNI_TRUE) ? TRUE : FALSE; - - /* Create performance flags from settings */ - freerdp_performance_flags_make(settings); - - DEBUG_ANDROID("performance_flags: %04X", settings->PerformanceFlags); -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls, - jint instance, jstring jRemoteProgram, jstring jWorkDir, - jboolean async_channel, jboolean async_transport, jboolean async_input, - jboolean async_update) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - jboolean ret = JNI_FALSE; - - const jbyte *remote_program; - const jbyte *work_dir; - - if (!(remote_program = (*env)->GetStringUTFChars(env, jRemoteProgram, NULL))) - return JNI_FALSE; - - if (!(work_dir = (*env)->GetStringUTFChars(env, jWorkDir, NULL))) - goto out_fail_work_dir; - - DEBUG_ANDROID("Remote Program: %s", (char*) remote_program); - DEBUG_ANDROID("Work Dir: %s", (char*) work_dir); - - /* Enable async mode. */ - settings->AsyncUpdate = async_update; - settings->AsyncChannels = async_channel; - settings->AsyncTransport = async_transport; - settings->AsyncInput = async_input; - - if (remote_program && strlen(remote_program) > 0) - { - if (!(settings->AlternateShell = strdup(remote_program))) - goto out_fail_strdup; - } - - if (work_dir && strlen(work_dir) > 0) - { - if (!(settings->ShellWorkingDirectory = strdup(work_dir))) - goto out_fail_strdup; - } - - ret = JNI_TRUE; - -out_fail_strdup: - (*env)->ReleaseStringUTFChars(env, jWorkDir, work_dir); -out_fail_work_dir: - (*env)->ReleaseStringUTFChars(env, jRemoteProgram, remote_program); - return ret; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_drive_redirection(JNIEnv *env, jclass cls, jint instance, jstring jpath) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - char* args[] = {"drive", "Android", ""}; - jboolean ret = JNI_FALSE; - - const jbyte *path = (*env)->GetStringUTFChars(env, jpath, NULL); - if (!path) - return JNI_FALSE; - DEBUG_ANDROID("drive redirect: %s", (char*)path); - - args[2] = (char*)path; - if (freerdp_client_add_device_channel(settings, 3, args) == -1) - { - settings->DeviceRedirection = FALSE; - goto out_fail; - } - - settings->DeviceRedirection = TRUE; - - ret = JNI_TRUE; -out_fail: - (*env)->ReleaseStringUTFChars(env, jpath, path); - return ret; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env, - jclass cls, jint instance, jint redirect) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - - DEBUG_ANDROID("sound: %s", - redirect ? ((redirect == 1) ? "Server" : "Redirect") : "None"); - - settings->AudioPlayback = (redirect == 2) ? TRUE : FALSE; - if (settings->AudioPlayback) - { - int ret; - char* p[1] = {"rdpsnd"}; - int count = 1; - - ret = freerdp_client_add_static_channel(settings, count, p); - - if(ret == -1) - return JNI_FALSE; - } - settings->RemoteConsoleAudio = (redirect == 1) ? TRUE : FALSE; - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env, - jclass cls, jint instance, jboolean enable) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - - DEBUG_ANDROID("microphone redirect: %s", enable ? "TRUE" : "FALSE"); - - settings->AudioCapture = enable; - if (enable) - { - int ret; - char* p[1] = {"audin"}; - int count = 1; - - ret = freerdp_client_add_dynamic_channel(settings, count, p); - - if (ret == -1) - return JNI_FALSE; - - } - return JNI_TRUE; -} - -JNIEXPORT void JNICALL jni_freerdp_set_clipboard_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - - DEBUG_ANDROID("clipboard redirect: %s", enable ? "TRUE" : "FALSE"); - - settings->RedirectClipboard = enable ? TRUE : FALSE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jint instance, jstring jgatewayhostname, jint port, - jstring jgatewayusername, jstring jgatewaypassword, jstring jgatewaydomain) -{ - freerdp* inst = (freerdp*)instance; - rdpSettings * settings = inst->settings; - jboolean ret = JNI_FALSE; - - const jbyte *gatewayhostname; - const jbyte *gatewayusername; - const jbyte *gatewaypassword; - const jbyte *gatewaydomain; - - if (!(gatewayhostname = (*env)->GetStringUTFChars(env, jgatewayhostname, NULL))) - return JNI_FALSE; - if (!(gatewayusername = (*env)->GetStringUTFChars(env, jgatewayusername, NULL))) - goto out_fail_username; - if (!(gatewaypassword = (*env)->GetStringUTFChars(env, jgatewaypassword, NULL))) - goto out_fail_password; - if (!(gatewaydomain = (*env)->GetStringUTFChars(env, jgatewaydomain, NULL))) - goto out_fail_domain; - - DEBUG_ANDROID("gatewayhostname: %s", (char*) gatewayhostname); - DEBUG_ANDROID("gatewayport: %d", port); - DEBUG_ANDROID("gatewayusername: %s", (char*) gatewayusername); - DEBUG_ANDROID("gatewaypassword: %s", (char*) gatewaypassword); - DEBUG_ANDROID("gatewaydomain: %s", (char*) gatewaydomain); - - settings->GatewayPort = port; - settings->GatewayUsageMethod = TSC_PROXY_MODE_DIRECT; - settings->GatewayEnabled = TRUE; - settings->GatewayUseSameCredentials = FALSE; - settings->GatewayHostname = strdup(gatewayhostname); - settings->GatewayUsername = strdup(gatewayusername); - settings->GatewayPassword = strdup(gatewaypassword); - settings->GatewayDomain = strdup(gatewaydomain); - if (!settings->GatewayHostname || !settings->GatewayUsername || - !settings->GatewayPassword || !settings->GatewayDomain) - { - goto out_fail_strdup; - } - - - ret = JNI_TRUE; - -out_fail_strdup: - (*env)->ReleaseStringUTFChars(env, jgatewaydomain, gatewaydomain); -out_fail_domain: - (*env)->ReleaseStringUTFChars(env, jgatewaypassword, gatewaypassword); -out_fail_password: - (*env)->ReleaseStringUTFChars(env, jgatewayusername, gatewayusername); -out_fail_username: - (*env)->ReleaseStringUTFChars(env, jgatewayhostname, gatewayhostname); - - return ret; -} - -static void copy_pixel_buffer(UINT8* dstBuf, UINT8* srcBuf, int x, int y, int width, int height, int wBuf, int hBuf, int bpp) -{ - int i; - int length; - int scanline; - UINT8 *dstp, *srcp; - - length = width * bpp; - scanline = wBuf * bpp; - - srcp = (UINT8*) &srcBuf[(scanline * y) + (x * bpp)]; - dstp = (UINT8*) &dstBuf[(scanline * y) + (x * bpp)]; - - for (i = 0; i < height; i++) - { - memcpy(dstp, srcp, length); - srcp += scanline; - dstp += scanline; - } -} - -JNIEXPORT jboolean JNICALL jni_freerdp_update_graphics( - JNIEnv *env, jclass cls, jint instance, jobject bitmap, jint x, jint y, jint width, jint height) -{ - - int ret; - void* pixels; - AndroidBitmapInfo info; - freerdp* inst = (freerdp*)instance; - rdpGdi *gdi = inst->context->gdi; - - if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) - { - DEBUG_ANDROID("AndroidBitmap_getInfo() failed ! error=%d", ret); - return JNI_FALSE; - } - - if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) - { - DEBUG_ANDROID("AndroidBitmap_lockPixels() failed ! error=%d", ret); - return JNI_FALSE; - } - - copy_pixel_buffer(pixels, gdi->primary_buffer, x, y, width, height, gdi->width, gdi->height, gdi->bytesPerPixel); - - AndroidBitmap_unlockPixels(env, bitmap); - - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_send_key_event( - JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down) -{ - DWORD scancode; - ANDROID_EVENT* event; - - freerdp* inst = (freerdp*)instance; - - scancode = GetVirtualScanCodeFromVirtualKeyCode(keycode, 4); - int flags = (down == JNI_TRUE) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE; - flags |= (scancode & KBDEXT) ? KBD_FLAGS_EXTENDED : 0; - event = (ANDROID_EVENT*) android_event_key_new(flags, scancode & 0xFF); - if (!event) - return JNI_FALSE; - - if (!android_push_event(inst, event)) - { - android_event_key_free((ANDROID_EVENT_KEY *)event); - return JNI_FALSE; - } - - DEBUG_ANDROID("send_key_event: %d, %d", (int)scancode, flags); - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_send_unicodekey_event( - JNIEnv *env, jclass cls, jint instance, jint keycode) -{ - ANDROID_EVENT* event; - - freerdp* inst = (freerdp*)instance; - event = (ANDROID_EVENT*) android_event_unicodekey_new(keycode); - if (!event) - return JNI_FALSE; - if (!android_push_event(inst, event)) - { - android_event_unicodekey_free((ANDROID_EVENT_KEY *)event); - return JNI_FALSE; - } - - DEBUG_ANDROID("send_unicodekey_event: %d", keycode); - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_send_cursor_event( - JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags) -{ - ANDROID_EVENT* event; - - freerdp* inst = (freerdp*)instance; - event = (ANDROID_EVENT*) android_event_cursor_new(flags, x, y); - if (!event) - return JNI_FALSE; - - if (!android_push_event(inst, event)) - { - android_event_cursor_free((ANDROID_EVENT_CURSOR *)event); - return JNI_FALSE; - } - - DEBUG_ANDROID("send_cursor_event: (%d, %d), %d", x, y, flags); - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL jni_freerdp_send_clipboard_data(JNIEnv *env, jclass cls, jint instance, jstring jdata) -{ - ANDROID_EVENT* event; - freerdp* inst = (freerdp*)instance; - const jbyte *data = jdata != NULL ? (*env)->GetStringUTFChars(env, jdata, NULL) : NULL; - int data_length = data ? strlen(data) : 0; - jboolean ret = JNI_FALSE;; - - event = (ANDROID_EVENT*) android_event_clipboard_new((void*)data, data_length); - if (!event) - goto out_fail; - - if (!android_push_event(inst, event)) - { - android_event_clipboard_free((ANDROID_EVENT_CLIPBOARD *)event); - goto out_fail; - } - - DEBUG_ANDROID("send_clipboard_data: (%s)", data); - - ret = JNI_TRUE; -out_fail: - if (data) - (*env)->ReleaseStringUTFChars(env, jdata, data); - return ret; -} - -JNIEXPORT jstring JNICALL jni_freerdp_get_version(JNIEnv *env, jclass cls) -{ - return (*env)->NewStringUTF(env, GIT_REVISION); -} diff --git a/client/Android/FreeRDPCore/jni/android_freerdp.h b/client/Android/FreeRDPCore/jni/android_freerdp.h deleted file mode 100644 index d6f5f4dfe..000000000 --- a/client/Android/FreeRDPCore/jni/android_freerdp.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - Android JNI Client Layer - - Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz - - This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -#ifndef __ANDROID_FREERDP_H -#define __ANDROID_FREERDP_H - -#include - -#include -#include - -#include -#include - -#include "android_event.h" - -struct android_context -{ - rdpContext rdpCtx; - - ANDROID_EVENT_QUEUE* event_queue; - HANDLE thread; - - BOOL is_connected; - - BOOL clipboardSync; - wClipboard* clipboard; - UINT32 numServerFormats; - UINT32 requestedFormatId; - HANDLE clipboardRequestEvent; - CLIPRDR_FORMAT* serverFormats; - CliprdrClientContext* cliprdr; - UINT32 clipboardCapabilities; -}; -typedef struct android_context androidContext; - -JNIEXPORT jint JNICALL jni_freerdp_new(JNIEnv *env, jclass cls); -JNIEXPORT void JNICALL jni_freerdp_free(JNIEnv *env, jclass cls, jint instance); -JNIEXPORT jboolean JNICALL jni_freerdp_connect(JNIEnv *env, jclass cls, jint instance); -JNIEXPORT jboolean JNICALL jni_freerdp_disconnect(JNIEnv *env, jclass cls, jint instance); -JNIEXPORT jboolean JNICALL jni_freerdp_cancel_connection(JNIEnv *env, jclass cls, jint instance); -JNIEXPORT jboolean JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, jint instance, - jstring jhostname, jstring jusername, jstring jpassword, jstring jdomain, jint width, - jint height, jint color_depth, jint port, jboolean console, jint security, jstring jcertname); -JNIEXPORT void JNICALL jni_freerdp_set_performance_flags(JNIEnv *env, jclass cls, jint instance, jboolean remotefx, jboolean disableWallpaper, jboolean disableFullWindowDrag, - jboolean disableMenuAnimations, jboolean disableTheming, jboolean enableFontSmoothing, jboolean enableDesktopComposition); -JNIEXPORT jboolean JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls, - jint instance, jstring jRemoteProgram, jstring jWorkDir, - jboolean async_channel, jboolean async_transport, jboolean async_input, - jboolean async_update); -JNIEXPORT jboolean JNICALL jni_freerdp_set_drive_redirection(JNIEnv *env, jclass cls, jint instance, jstring jpath); -JNIEXPORT jboolean JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env, jclass cls, jint instance, jint redirect); -JNIEXPORT jboolean JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable); -JNIEXPORT void JNICALL jni_freerdp_set_clipboard_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable); -JNIEXPORT jboolean JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jint instance, jstring jgatewayhostname, jint port, jstring jgatewayusername, jstring jgatewaypassword, jstring jgatewaydomain); -JNIEXPORT jboolean JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, jint instance, jstring jdirectory); -JNIEXPORT jboolean JNICALL jni_freerdp_update_graphics(JNIEnv *env, jclass cls, jint instance, jobject bitmap, jint x, jint y, jint width, jint height); -JNIEXPORT jboolean JNICALL jni_freerdp_send_cursor_event(JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags); -JNIEXPORT jboolean JNICALL jni_freerdp_send_key_event(JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down); -JNIEXPORT jboolean JNICALL jni_freerdp_send_unicodekey_event(JNIEnv *env, jclass cls, jint instance, jint keycode); -JNIEXPORT jboolean JNICALL jni_freerdp_send_clipboard_data(JNIEnv *env, jclass cls, jint instance, jstring jdata); -JNIEXPORT jstring JNICALL jni_freerdp_get_version(JNIEnv *env, jclass cls); - -#endif /* __ANDROID_FREERDP_H */ - diff --git a/client/Android/FreeRDPCore/jni/generated/android_freerdp_jni.c b/client/Android/FreeRDPCore/jni/generated/android_freerdp_jni.c deleted file mode 100644 index 77b9137fb..000000000 --- a/client/Android/FreeRDPCore/jni/generated/android_freerdp_jni.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - FreeRDP: A Remote Desktop Protocol client. - Android JNI Bindings and Native Code - - Copyright 2010 Marc-Andre Moreau - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#include "android_freerdp.h" -#include "android_freerdp_jni.h" - -JNIEXPORT jint JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1new(JNIEnv *env, jclass cls) -{ - return jni_freerdp_new(env, cls); -} - -JNIEXPORT void JNICALL JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1free(JNIEnv *env, jclass cls, jint instance) -{ - jni_freerdp_free(env, cls, instance); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1connect(JNIEnv *env, jclass cls, jint instance) -{ - return jni_freerdp_connect(env, cls, instance); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1disconnect(JNIEnv *env, jclass cls, jint instance) -{ - return jni_freerdp_disconnect(env, cls, instance); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1cancel_1connection(JNIEnv *env, jclass cls, jint instance) -{ - return jni_freerdp_cancel_connection(env, cls, instance); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1connection_1info(JNIEnv *env, jclass cls, jint instance, - jstring jhostname, jstring jusername, jstring jpassword, jstring jdomain, jint width, jint height, jint color_depth, jint port, - jboolean console, jint security, jstring certname) -{ - return jni_freerdp_set_connection_info(env, cls, instance, jhostname, jusername, jpassword, jdomain, - width, height, color_depth, port, console, security, certname); -} - -JNIEXPORT jboolean JNICALL -Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1advanced_1settings( - JNIEnv *env, jclass cls, jint instance, jstring remote_program, jstring work_dir, - jboolean async_channel, jboolean async_transport, jboolean async_input, - jboolean async_update) -{ - return jni_freerdp_set_advanced_settings(env, cls, instance, remote_program, work_dir, - async_channel, async_transport, async_input, async_update); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1data_1directory(JNIEnv *env, jclass cls, jint instance, jstring directory) -{ - return jni_freerdp_set_data_directory(env, cls, instance, directory); -} - -JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1performance_1flags( - JNIEnv *env, jclass cls, jint instance, jboolean remotefx, jboolean disableWallpaper, jboolean disableFullWindowDrag, - jboolean disableMenuAnimations, jboolean disableTheming, jboolean enableFontSmoothing, jboolean enableDesktopComposition) -{ - jni_freerdp_set_performance_flags(env, cls, instance, remotefx, disableWallpaper, disableFullWindowDrag, disableMenuAnimations, disableTheming, enableFontSmoothing, enableDesktopComposition); -} - -JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1clipboard_1redirection - (JNIEnv *env, jclass cls, jint inst, jboolean enable) -{ - jni_freerdp_set_clipboard_redirection(env, cls, inst, enable); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1sound_1redirection - (JNIEnv *env, jclass cls, jint inst, jint redirect) -{ - return jni_freerdp_set_sound_redirection(env, cls, inst, redirect); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1microphone_1redirection - (JNIEnv *env, jclass cls, jint inst, jboolean redirect) -{ - return jni_freerdp_set_microphone_redirection(env, cls, inst, redirect); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1drive_1redirection - (JNIEnv *env, jclass cls, jint inst, jstring path) -{ - return jni_freerdp_set_drive_redirection(env, cls, inst, path); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1gateway_1info - (JNIEnv *env, jclass cls, jint inst, jstring hostname, jint port, jstring username, jstring password, jstring domain) -{ - return jni_freerdp_set_gateway_info(env, cls, inst, hostname, port, username, password, domain); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1update_1graphics( - JNIEnv *env, jclass cls, jint instance, jobject bitmap, jint x, jint y, jint width, jint height) -{ - return jni_freerdp_update_graphics(env, cls, instance, bitmap, x, y, width, height); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event( - JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags) -{ - return jni_freerdp_send_cursor_event(env, cls, instance, x, y, flags); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event( - JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down) -{ - return jni_freerdp_send_key_event(env, cls, instance, keycode, down); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event - (JNIEnv *env, jclass cls, jint instance, jint keycode) -{ - return jni_freerdp_send_unicodekey_event(env, cls, instance, keycode); -} - -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data - (JNIEnv *env, jclass cls, jint instance, jstring data) -{ - return jni_freerdp_send_clipboard_data(env, cls, instance, data); -} - -JNIEXPORT jstring JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1version(JNIEnv *env, jclass cls) -{ - return jni_freerdp_get_version(env, cls); -} - diff --git a/client/Android/FreeRDPCore/jni/generated/com_freerdp_freerdpcore_services_LibFreeRDP.h b/client/Android/FreeRDPCore/jni/generated/com_freerdp_freerdpcore_services_LibFreeRDP.h deleted file mode 100644 index 50b0c74f8..000000000 --- a/client/Android/FreeRDPCore/jni/generated/com_freerdp_freerdpcore_services_LibFreeRDP.h +++ /dev/null @@ -1,173 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_freerdp_freerdpcore_services_LibFreeRDP */ - -#ifndef _Included_com_freerdp_freerdpcore_services_LibFreeRDP -#define _Included_com_freerdp_freerdpcore_services_LibFreeRDP -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_new - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1new - (JNIEnv *, jclass); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_free - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1free - (JNIEnv *, jclass, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_connect - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1connect - (JNIEnv *, jclass, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_disconnect - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1disconnect - (JNIEnv *, jclass, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_cancel_connection - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1cancel_1connection - (JNIEnv *, jclass, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_connection_info - * Signature: (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIZILjava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1connection_1info - (JNIEnv *, jclass, jint, jstring, jstring, jstring, jstring, jint, jint, jint, jint, jboolean, jint, jstring); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_performance_flags - * Signature: (IZZZZZZZ)V - */ -JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1performance_1flags - (JNIEnv *, jclass, jint, jboolean, jboolean, jboolean, jboolean, jboolean, jboolean, jboolean); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_advanced_settings - * Signature: (ILjava/lang/String;Ljava/lang/String;ZZZZ)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1advanced_1settings - (JNIEnv *, jclass, jint, jstring, jstring, jboolean, jboolean, jboolean, jboolean); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_data_directory - * Signature: (ILjava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1data_1directory - (JNIEnv *, jclass, jint, jstring); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_clipboard_redirection - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1clipboard_1redirection - (JNIEnv *, jclass, jint, jboolean); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_sound_redirection - * Signature: (II)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1sound_1redirection - (JNIEnv *, jclass, jint, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_microphone_redirection - * Signature: (IZ)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1microphone_1redirection - (JNIEnv *, jclass, jint, jboolean); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_drive_redirection - * Signature: (ILjava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1drive_1redirection - (JNIEnv *, jclass, jint, jstring); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_set_gateway_info - * Signature: (ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1gateway_1info - (JNIEnv *, jclass, jint, jstring, jint, jstring, jstring, jstring); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_update_graphics - * Signature: (ILandroid/graphics/Bitmap;IIII)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1update_1graphics - (JNIEnv *, jclass, jint, jobject, jint, jint, jint, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_send_cursor_event - * Signature: (IIII)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event - (JNIEnv *, jclass, jint, jint, jint, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_send_key_event - * Signature: (IIZ)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event - (JNIEnv *, jclass, jint, jint, jboolean); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_send_unicodekey_event - * Signature: (II)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event - (JNIEnv *, jclass, jint, jint); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_send_clipboard_data - * Signature: (ILjava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data - (JNIEnv *, jclass, jint, jstring); - -/* - * Class: com_freerdp_freerdpcore_services_LibFreeRDP - * Method: freerdp_get_version - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1version - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/client/Android/FreeRDPCore/lint.xml b/client/Android/FreeRDPCore/lint.xml deleted file mode 100644 index ee0eead5b..000000000 --- a/client/Android/FreeRDPCore/lint.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/client/Android/FreeRDPCore/local.properties.cmake b/client/Android/FreeRDPCore/local.properties.cmake deleted file mode 100644 index 159126370..000000000 --- a/client/Android/FreeRDPCore/local.properties.cmake +++ /dev/null @@ -1,2 +0,0 @@ -# This file is automatically generated by cmake. -sdk.dir=@ANDROID_SDK@ diff --git a/client/Android/FreeRDPCore/project.properties.cmake b/client/Android/FreeRDPCore/project.properties.cmake deleted file mode 100644 index 09c72f4a9..000000000 --- a/client/Android/FreeRDPCore/project.properties.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system edit -# "ant.properties", and override values to adapt the script to your -# project structure. -# -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - -# Project target. -target=android-@ANDROID_APP_TARGET_SDK@ -android.library=true -android.library.reference.1=../appcompat_v7 diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java deleted file mode 100644 index eea1bfd4f..000000000 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - Android Main Application - - Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz - - This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -package com.freerdp.freerdpcore.application; - -import android.app.Application; -import android.content.Intent; -import android.content.IntentFilter; -import android.util.Log; - -import java.util.*; - -import com.freerdp.freerdpcore.application.SessionState; -import com.freerdp.freerdpcore.domain.BookmarkBase; -import com.freerdp.freerdpcore.services.BookmarkDB; -import com.freerdp.freerdpcore.services.HistoryDB; -import com.freerdp.freerdpcore.services.LibFreeRDP; -import com.freerdp.freerdpcore.services.ManualBookmarkGateway; -import com.freerdp.freerdpcore.services.QuickConnectHistoryGateway; - -public class GlobalApp extends Application implements LibFreeRDP.EventListener -{ - private static Map sessionMap; - - public static boolean ConnectedTo3G = false; - - // event notification defines - public static final String EVENT_TYPE = "EVENT_TYPE"; - public static final String EVENT_PARAM = "EVENT_PARAM"; - public static final String EVENT_STATUS = "EVENT_STATUS"; - public static final String EVENT_ERROR = "EVENT_ERROR"; - - public static final String ACTION_EVENT_FREERDP = "com.freerdp.freerdp.event.freerdp"; - - public static final int FREERDP_EVENT_CONNECTION_SUCCESS = 1; - public static final int FREERDP_EVENT_CONNECTION_FAILURE = 2; - public static final int FREERDP_EVENT_DISCONNECTED = 3; - - private static BookmarkDB bookmarkDB; - private static ManualBookmarkGateway manualBookmarkGateway; - - private static HistoryDB historyDB; - private static QuickConnectHistoryGateway quickConnectHistoryGateway; - - // timer for disconnecting sessions after the screen was turned off - private static Timer disconnectTimer = null; - - // TimerTask for disconnecting sessions after screen was turned off - private static class DisconnectTask extends TimerTask - { - @Override - public void run() { - Log.v("DisconnectTask", "Doing action"); - - // disconnect any running rdp session - Collection sessions = GlobalApp.getSessions(); - for (SessionState session : sessions) - { - LibFreeRDP.disconnect(session.getInstance()); - } - } - } - - - public GlobalApp() - { - sessionMap = Collections.synchronizedMap(new HashMap()); - - GlobalApp.load(); - LibFreeRDP.setEventListener(this); - } - - @Override - public void onCreate() - { - super.onCreate(); - - bookmarkDB = new BookmarkDB(this); - - manualBookmarkGateway = new ManualBookmarkGateway(bookmarkDB); - - historyDB = new HistoryDB(this); - quickConnectHistoryGateway = new QuickConnectHistoryGateway(historyDB); - - GlobalSettings.init(this); - ConnectedTo3G = NetworkStateReceiver.isConnectedTo3G(this); - - // init screen receiver here (this can't be declared in AndroidManifest - refer to: - // http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ - IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_SCREEN_OFF); - registerReceiver(new ScreenReceiver(), filter); - } - - public static ManualBookmarkGateway getManualBookmarkGateway() - { - return manualBookmarkGateway; - } - - public static QuickConnectHistoryGateway getQuickConnectHistoryGateway() - { - return quickConnectHistoryGateway; - } - - static private void load() - { - final String libname = "freerdp-android"; - final String LD_PATH = System.getProperty("java.library.path"); - - Log.v("LibFreeRDP", "Trying to load library " + libname + " from LD_PATH: " + LD_PATH); - - try { - System.loadLibrary(libname); - } catch (UnsatisfiedLinkError e) { - Log.e("LibFreeRDP", e.toString()); - } - } - - // Disconnect handling for Screen on/off events - static public void startDisconnectTimer() - { - int timeoutMinutes = GlobalSettings.getDisconnectTimeout(); - if (timeoutMinutes > 0) - { - // start disconnect timeout... - disconnectTimer = new Timer(); - disconnectTimer.schedule(new DisconnectTask(), timeoutMinutes * 60 * 1000); - } - } - - static public void cancelDisconnectTimer() - { - // cancel any pending timer events - if (disconnectTimer != null) - { - disconnectTimer.cancel(); - disconnectTimer.purge(); - disconnectTimer = null; - } - } - - // RDP session handling - static public SessionState createSession(BookmarkBase bookmark) - { - SessionState session = new SessionState(LibFreeRDP.newInstance(), bookmark); - sessionMap.put(Integer.valueOf(session.getInstance()), session); - return session; - } - - static public SessionState getSession(int instance) - { - return sessionMap.get(instance); - } - - static public Collection getSessions() - { - // return a copy of the session items - return new ArrayList(sessionMap.values()); - } - - static public void freeSession(int instance) - { - if (GlobalApp.sessionMap.containsKey(instance)) - { - GlobalApp.sessionMap.remove(instance); - LibFreeRDP.freeInstance(instance); - } - } - - // helper to send FreeRDP notifications - private void sendRDPNotification(int type, int param) - { - // send broadcast - Intent intent = new Intent(ACTION_EVENT_FREERDP); - intent.putExtra(EVENT_TYPE, type); - intent.putExtra(EVENT_PARAM, param); - sendBroadcast(intent); - } - - // ////////////////////////////////////////////////////////////////////// - // Implementation of LibFreeRDP.EventListener - public void OnConnectionSuccess(int instance) - { - Log.v("LibFreeRDP", "OnConnectionSuccess"); - sendRDPNotification(FREERDP_EVENT_CONNECTION_SUCCESS, instance); - } - - public void OnConnectionFailure(int instance) - { - Log.v("LibFreeRDP", "OnConnectionFailure"); - - // send notification to session activity - sendRDPNotification(FREERDP_EVENT_CONNECTION_FAILURE, instance); - } - - public void OnDisconnecting(int instance) - { - Log.v("LibFreeRDP", "OnDisconnecting"); - - // send disconnect notification - sendRDPNotification(FREERDP_EVENT_DISCONNECTED, instance); - } - - public void OnDisconnected(int instance) - { - Log.v("LibFreeRDP", "OnDisconnected"); - } -} diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/BookmarkDB.java b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/BookmarkDB.java deleted file mode 100644 index b1f47cb49..000000000 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/BookmarkDB.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - Android Bookmark Database - - Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz - - This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -package com.freerdp.freerdpcore.services; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import android.content.Context; -import android.provider.BaseColumns; -import android.util.Log; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; - -public class BookmarkDB extends SQLiteOpenHelper -{ - private static final int DB_VERSION = 6; - private static final String DB_NAME = "bookmarks.db"; - - public static final String ID = BaseColumns._ID; - - public BookmarkDB(Context context) - { - super(context, DB_NAME, null, DB_VERSION); - } - - @Override - public void onCreate(SQLiteDatabase db) - { - String sqlScreenSettings = - "CREATE TABLE tbl_screen_settings (" - + ID + " INTEGER PRIMARY KEY, " - + "colors INTEGER DEFAULT 16, " - + "resolution INTEGER DEFAULT 0, " - + "width, " - + "height);"; - - db.execSQL(sqlScreenSettings); - - String sqlPerformanceFlags = - "CREATE TABLE tbl_performance_flags (" - + ID + " INTEGER PRIMARY KEY, " - + "perf_remotefx INTEGER, " - + "perf_wallpaper INTEGER, " - + "perf_theming INTEGER, " - + "perf_full_window_drag INTEGER, " - + "perf_menu_animations INTEGER, " - + "perf_font_smoothing INTEGER, " - + "perf_desktop_composition INTEGER);"; - - db.execSQL(sqlPerformanceFlags); - - String sqlManualBookmarks = getManualBookmarksCreationString(); - db.execSQL(sqlManualBookmarks); - - - // Insert a test entry - String sqlInsertDefaultScreenEntry = - "INSERT INTO tbl_screen_settings (" - + "colors, " - + "resolution, " - + "width, " - + "height) " - + "VALUES ( " - + "32, 1, 1024, 768);"; - db.execSQL(sqlInsertDefaultScreenEntry); - db.execSQL(sqlInsertDefaultScreenEntry); - - String sqlInsertDefaultPerfFlags = - "INSERT INTO tbl_performance_flags (" - + "perf_remotefx, " - + "perf_wallpaper, " - + "perf_theming, " - + "perf_full_window_drag, " - + "perf_menu_animations, " - + "perf_font_smoothing, " - + "perf_desktop_composition) " - + "VALUES ( " - + "1, 0, 0, 0, 0, 0, 0);"; - db.execSQL(sqlInsertDefaultPerfFlags); - db.execSQL(sqlInsertDefaultPerfFlags); - - String sqlInsertDefaultSessionEntry = - "INSERT INTO tbl_manual_bookmarks (" - + "label, " - + "hostname, " - + "username, " - + "password, " - + "domain, " - + "port, " - + "screen_settings, " - + "performance_flags, " - + "screen_3g, " - + "performance_3g, " - + "redirect_sdcard, " - + "redirect_sound, " - + "redirect_microphone, " - + "security, " - + "remote_program, " - + "work_dir, " - + "async_channel, " - + "async_transport, " - + "async_input, " - + "async_update, " - + "console_mode, " - + "debug_level ) " - + "VALUES ( " - + "'Test Server', " - + "'testservice.afreerdp.com', " - + "'', " - + "'', " - + "'', " - + "3389, " - + "1, 1, 2, 2, 0, 0, 0, 0, " - + "'', '', " - + "1, 1, 1, 1, 0, 0);"; - db.execSQL(sqlInsertDefaultSessionEntry); - } - - private String getManualBookmarksCreationString() - { - return ( - "CREATE TABLE IF NOT EXISTS tbl_manual_bookmarks (" - + ID + " INTEGER PRIMARY KEY, " - + "label TEXT NOT NULL, " - + "hostname TEXT NOT NULL, " - + "username TEXT NOT NULL, " - + "password TEXT, " - + "domain TEXT, " - + "port TEXT, " - + "screen_settings INTEGER NOT NULL, " - + "performance_flags INTEGER NOT NULL, " - - + "enable_gateway_settings INTEGER DEFAULT 0, " - + "gateway_hostname TEXT, " - + "gateway_port INTEGER DEFAULT 443, " - + "gateway_username TEXT, " - + "gateway_password TEXT, " - + "gateway_domain TEXT, " - - + "enable_3g_settings INTEGER DEFAULT 0, " - + "screen_3g INTEGER NOT NULL, " - + "performance_3g INTEGER NOT NULL, " - + "redirect_sdcard INTEGER DEFAULT 0, " - + "redirect_sound INTEGER DEFAULT 0, " - + "redirect_microphone INTEGER DEFAULT 0, " - + "security INTEGER, " - + "remote_program TEXT, " - + "work_dir TEXT, " - + "async_channel INTEGER DEFAULT 0, " - + "async_transport INTEGER DEFAULT 0, " - + "async_input INTEGER DEFAULT 0, " - + "async_update INTEGER DEFAULT 0, " - + "console_mode INTEGER, " - + "debug_level INTEGER DEFAULT 0, " - - + "FOREIGN KEY(screen_settings) REFERENCES tbl_screen_settings(" + ID + "), " - + "FOREIGN KEY(performance_flags) REFERENCES tbl_performance_flags(" + ID + "), " - + "FOREIGN KEY(screen_3g) REFERENCES tbl_screen_settings(" + ID + "), " - + "FOREIGN KEY(performance_3g) REFERENCES tbl_performance_flags(" + ID + ") " - - + ");"); - } - - // from http://stackoverflow.com/questions/3424156/upgrade-sqlite-database-from-one-version-to-another - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) - { - db.beginTransaction(); - - // run a table creation with if not exists (we are doing an upgrade, so the table might - // not exists yet, it will fail alter and drop) - db.execSQL(getManualBookmarksCreationString()); - // put in a list the existing columns - List columns = GetColumns(db, "tbl_manual_bookmarks"); - // backup table - db.execSQL("ALTER TABLE tbl_manual_bookmarks RENAME TO 'temp_tbl_manual_bookmarks'"); - // create new table (with new scheme) - db.execSQL(getManualBookmarksCreationString()); - // get the intersection with the new columns, this time columns taken from the upgraded table - columns.retainAll(GetColumns(db, "tbl_manual_bookmarks")); - // restore data - String cols = joinStrings(columns, ","); - db.execSQL(String.format("INSERT INTO %s (%s) SELECT %s from 'temp_%s", "tbl_manual_bookmarks", cols, cols, "tbl_manual_bookmarks'")); - // remove backup table - db.execSQL("DROP table 'temp_tbl_manual_bookmarks'"); - - db.setTransactionSuccessful(); - db.endTransaction(); - } - - private static List GetColumns(SQLiteDatabase db, String tableName) { - List ar = null; - Cursor c = null; - try { - c = db.rawQuery("SELECT * FROM " + tableName + " LIMIT 1", null); - if (c != null) { - ar = new ArrayList(Arrays.asList(c.getColumnNames())); - } - } catch (Exception e) { - Log.v(tableName, e.getMessage(), e); - e.printStackTrace(); - } finally { - if (c != null) - c.close(); - } - return ar; - } - - private static String joinStrings(List list, String delim) { - StringBuilder buf = new StringBuilder(); - int num = list.size(); - for (int i = 0; i < num; i++) { - if (i != 0) - buf.append(delim); - buf.append((String) list.get(i)); - } - return buf.toString(); - } -} diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/LibFreeRDP.java b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/LibFreeRDP.java deleted file mode 100644 index c5e896f34..000000000 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/LibFreeRDP.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - Android FreeRDP JNI Wrapper - - Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz - - This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -package com.freerdp.freerdpcore.services; - - -import com.freerdp.freerdpcore.application.GlobalApp; -import com.freerdp.freerdpcore.application.SessionState; -import com.freerdp.freerdpcore.domain.BookmarkBase; -import com.freerdp.freerdpcore.domain.ManualBookmark; - -import android.graphics.Bitmap; - -public class LibFreeRDP -{ - private static native int freerdp_new(); - private static native void freerdp_free(int inst); - private static native boolean freerdp_connect(int inst); - private static native boolean freerdp_disconnect(int inst); - private static native boolean freerdp_cancel_connection(int inst); - - private static native boolean freerdp_set_connection_info(int inst, - String hostname, String username, String password, String domain, - int width, int height, int color_depth, int port, boolean console, - int security, String certname); - - private static native void freerdp_set_performance_flags(int inst, - boolean remotefx, boolean disableWallpaper, boolean disableFullWindowDrag, - boolean disableMenuAnimations, boolean disableTheming, - boolean enableFontSmoothing, boolean enableDesktopComposition); - - private static native boolean freerdp_set_advanced_settings(int inst, - String remoteProgram, String workDir, boolean async_channel, - boolean async_transport, boolean async_input, boolean async_update); - - private static native boolean freerdp_set_data_directory(int inst, String directory); - - private static native void freerdp_set_clipboard_redirection(int inst, boolean enable); - private static native boolean freerdp_set_sound_redirection(int inst, int redirect); - private static native boolean freerdp_set_microphone_redirection(int inst, boolean enable); - private static native boolean freerdp_set_drive_redirection(int inst, String path); - - private static native boolean freerdp_set_gateway_info(int inst, String gatewayhostname, int port, - String gatewayusername, String gatewaypassword, String gatewaydomain); - - private static native boolean freerdp_update_graphics(int inst, - Bitmap bitmap, int x, int y, int width, int height); - - private static native boolean freerdp_send_cursor_event(int inst, int x, int y, int flags); - private static native boolean freerdp_send_key_event(int inst, int keycode, boolean down); - private static native boolean freerdp_send_unicodekey_event(int inst, int keycode); - private static native boolean freerdp_send_clipboard_data(int inst, String data); - - private static native String freerdp_get_version(); - - private static final String TAG = "LibFreeRDP"; - - public static interface EventListener - { - void OnConnectionSuccess(int instance); - void OnConnectionFailure(int instance); - void OnDisconnecting(int instance); - void OnDisconnected(int instance); - } - - public static interface UIEventListener - { - void OnSettingsChanged(int width, int height, int bpp); - boolean OnAuthenticate(StringBuilder username, StringBuilder domain, StringBuilder password); - boolean OnVerifiyCertificate(String subject, String issuer, String fingerprint); - void OnGraphicsUpdate(int x, int y, int width, int height); - void OnGraphicsResize(int width, int height, int bpp); - void OnRemoteClipboardChanged(String data); - } - - private static EventListener listener; - - public static void setEventListener(EventListener l) - { - listener = l; - } - - public static int newInstance() - { - return freerdp_new(); - } - - public static void freeInstance(int inst) - { - freerdp_free(inst); - } - - public static boolean connect(int inst) - { - return freerdp_connect(inst); - } - - public static boolean disconnect(int inst) - { - return freerdp_disconnect(inst); - } - - public static boolean cancelConnection(int inst) - { - return freerdp_cancel_connection(inst); - } - - public static boolean setConnectionInfo(int inst, BookmarkBase bookmark) - { - BookmarkBase.ScreenSettings screenSettings = bookmark.getActiveScreenSettings(); - - int port; - String hostname; - String certName = ""; - if(bookmark.getType() == BookmarkBase.TYPE_MANUAL) - { - port = bookmark.get().getPort(); - hostname = bookmark.get().getHostname(); - } - else - { - assert false; - return false; - } - - freerdp_set_connection_info(inst, - hostname, - bookmark.getUsername(), - bookmark.getPassword(), - bookmark.getDomain(), - screenSettings.getWidth(), - screenSettings.getHeight(), - screenSettings.getColors(), - port, - bookmark.getAdvancedSettings().getConsoleMode(), - bookmark.getAdvancedSettings().getSecurity(), - certName); - - BookmarkBase.PerformanceFlags flags = bookmark.getActivePerformanceFlags(); - freerdp_set_performance_flags(inst, - flags.getRemoteFX(), - !flags.getWallpaper(), - !flags.getFullWindowDrag(), - !flags.getMenuAnimations(), - !flags.getTheming(), - flags.getFontSmoothing(), - flags.getDesktopComposition()); - - BookmarkBase.AdvancedSettings advancedSettings = bookmark.getAdvancedSettings(); - BookmarkBase.DebugSettings debugSettings = bookmark.getDebugSettings(); - freerdp_set_advanced_settings(inst, advancedSettings.getRemoteProgram(), - advancedSettings.getWorkDir(), debugSettings.getAsyncChannel(), - debugSettings.getAsyncTransport(), debugSettings.getAsyncInput(), - debugSettings.getAsyncUpdate()); - - // drive redirection enabled? - if (advancedSettings.getRedirectSDCard()) - freerdp_set_drive_redirection(inst, android.os.Environment.getExternalStorageDirectory().getPath()); - - // always enable clipboard redirection - freerdp_set_clipboard_redirection(inst, true); - - // Gateway enabled? - if (bookmark.getType() == BookmarkBase.TYPE_MANUAL && bookmark.get().getEnableGatewaySettings()) - { - ManualBookmark.GatewaySettings gatewaySettings = bookmark.get().getGatewaySettings(); - freerdp_set_gateway_info(inst, gatewaySettings.getHostname(), gatewaySettings.getPort(), - gatewaySettings.getUsername(), gatewaySettings.getPassword(), gatewaySettings.getDomain()); - } - - // Sound redirection - freerdp_set_sound_redirection(inst, - advancedSettings.getRedirectSound()); - - // Microphone redirection - freerdp_set_microphone_redirection(inst, - advancedSettings.getRedirectMicrophone()); - - return true; - } - - public static boolean setDataDirectory(int inst, String directory) - { - return freerdp_set_data_directory(inst, directory); - } - - public static boolean updateGraphics(int inst, Bitmap bitmap, int x, int y, int width, int height) - { - return freerdp_update_graphics(inst, bitmap, x, y, width, height); - } - - public static boolean sendCursorEvent(int inst, int x, int y, int flags) - { - return freerdp_send_cursor_event(inst, x, y, flags); - } - - public static boolean sendKeyEvent(int inst, int keycode, boolean down) - { - return freerdp_send_key_event(inst, keycode, down); - } - - public static boolean sendUnicodeKeyEvent(int inst, int keycode) - { - return freerdp_send_unicodekey_event(inst, keycode); - } - - public static boolean sendClipboardData(int inst, String data) - { - return freerdp_send_clipboard_data(inst, data); - } - - private static void OnConnectionSuccess(int inst) - { - if (listener != null) - listener.OnConnectionSuccess(inst); - } - - private static void OnConnectionFailure(int inst) - { - if (listener != null) - listener.OnConnectionFailure(inst); - } - - private static void OnDisconnecting(int inst) - { - if (listener != null) - listener.OnDisconnecting(inst); - } - - private static void OnDisconnected(int inst) - { - if (listener != null) - listener.OnDisconnected(inst); - } - - private static void OnSettingsChanged(int inst, int width, int height, int bpp) - { - SessionState s = GlobalApp.getSession(inst); - if (s == null) - return; - UIEventListener uiEventListener = s.getUIEventListener(); - if (uiEventListener != null) - uiEventListener.OnSettingsChanged(width, height, bpp); - } - - private static boolean OnAuthenticate(int inst, StringBuilder username, StringBuilder domain, StringBuilder password) - { - SessionState s = GlobalApp.getSession(inst); - if (s == null) - return false; - UIEventListener uiEventListener = s.getUIEventListener(); - if (uiEventListener != null) - return uiEventListener.OnAuthenticate(username, domain, password); - return false; - } - - private static boolean OnVerifyCertificate(int inst, String subject, String issuer, String fingerprint) - { - SessionState s = GlobalApp.getSession(inst); - if (s == null) - return false; - UIEventListener uiEventListener = s.getUIEventListener(); - if (uiEventListener != null) - return uiEventListener.OnVerifiyCertificate(subject, issuer, fingerprint); - return false; - } - - private static void OnGraphicsUpdate(int inst, int x, int y, int width, int height) - { - SessionState s = GlobalApp.getSession(inst); - if (s == null) - return; - UIEventListener uiEventListener = s.getUIEventListener(); - if (uiEventListener != null) - uiEventListener.OnGraphicsUpdate(x, y, width, height); - } - - private static void OnGraphicsResize(int inst, int width, int height, int bpp) - { - SessionState s = GlobalApp.getSession(inst); - if (s == null) - return; - UIEventListener uiEventListener = s.getUIEventListener(); - if (uiEventListener != null) - uiEventListener.OnGraphicsResize(width, height, bpp); - } - - private static void OnRemoteClipboardChanged(int inst, String data) - { - SessionState s = GlobalApp.getSession(inst); - if (s == null) - return; - UIEventListener uiEventListener = s.getUIEventListener(); - if (uiEventListener != null) - uiEventListener.OnRemoteClipboardChanged(data); - } - - public static String getVersion() - { - return freerdp_get_version(); - } -} diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/BuildConfiguration.java.in b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/BuildConfiguration.java.in deleted file mode 100644 index e0a72c95a..000000000 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/BuildConfiguration.java.in +++ /dev/null @@ -1,15 +0,0 @@ -package com.freerdp.freerdpcore.utils; - -public class BuildConfiguration { - public static final String WITH_ANDROID_DEBUG_MENU = "@WITH_ANDROID_DEBUG_MENU@"; - - public static final int FREERDP_VERSION_MAJOR = @FREERDP_VERSION_MAJOR@; - public static final int FREERDP_VERSION_MINOR = @FREERDP_VERSION_MINOR@; - public static final int FREERDP_VERSION_REVISION = @FREERDP_VERSION_REVISION@; - - public static final String FREERDP_VERSION_SUFFIX = "@FREERDP_VERSION_SUFFIX@"; - public static final String FREERDP_API_VERSION = "@FREERDP_API_VERSION@"; - public static final String FREERDP_VERSION = "@FREERDP_VERSION@"; - public static final String FREERDP_VERSION_FULL = "@FREERDP_VERSION_FULL@"; - public static final String GIT_REVISION = "@GIT_REVISION@"; - } diff --git a/client/Android/ModuleOptions.cmake b/client/Android/ModuleOptions.cmake deleted file mode 100644 index 38f85b400..000000000 --- a/client/Android/ModuleOptions.cmake +++ /dev/null @@ -1,4 +0,0 @@ - -set(FREERDP_CLIENT_NAME "afreerdp") -set(FREERDP_CLIENT_PLATFORM "Android") -set(FREERDP_CLIENT_VENDOR "FreeRDP") diff --git a/client/Android/Studio/.gitignore b/client/Android/Studio/.gitignore new file mode 100644 index 000000000..a2dc2317b --- /dev/null +++ b/client/Android/Studio/.gitignore @@ -0,0 +1,37 @@ +#built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Windows thumbnail db +Thumbs.db + +# OSX files +.DS_Store + +# Eclipse project files +.classpath +.project + +# Android Studio +*.iml +.idea +#.idea/workspace.xml - remove # and delete .idea if it better suit your needs. +.gradle +build/ + +#NDK +obj/ +jniLibs/ diff --git a/client/Android/Studio/aFreeRDP/build.gradle b/client/Android/Studio/aFreeRDP/build.gradle new file mode 100644 index 000000000..ff43e71cf --- /dev/null +++ b/client/Android/Studio/aFreeRDP/build.gradle @@ -0,0 +1,23 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "com.freerdp.afreerdp" + minSdkVersion 14 + targetSdkVersion 21 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} + +dependencies { + compile project(':freeRDPCore') +} diff --git a/client/Android/Studio/aFreeRDP/lint.xml b/client/Android/Studio/aFreeRDP/lint.xml new file mode 100644 index 000000000..8423c0ef9 --- /dev/null +++ b/client/Android/Studio/aFreeRDP/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/client/Android/aFreeRDP/AndroidManifest.xml.cmake b/client/Android/Studio/aFreeRDP/src/main/AndroidManifest.xml similarity index 90% rename from client/Android/aFreeRDP/AndroidManifest.xml.cmake rename to client/Android/Studio/aFreeRDP/src/main/AndroidManifest.xml index 8cec9833d..420091049 100644 --- a/client/Android/aFreeRDP/AndroidManifest.xml.cmake +++ b/client/Android/Studio/aFreeRDP/src/main/AndroidManifest.xml @@ -1,14 +1,14 @@ - + + android:versionCode="3" + android:versionName="e83f97b" > + android:targetSdkVersion="21" + android:minSdkVersion="14"/> diff --git a/client/Android/aFreeRDP/assets/FreeRDP_Logo.png b/client/Android/Studio/aFreeRDP/src/main/assets/FreeRDP_Logo.png similarity index 100% rename from client/Android/aFreeRDP/assets/FreeRDP_Logo.png rename to client/Android/Studio/aFreeRDP/src/main/assets/FreeRDP_Logo.png diff --git a/client/Android/aFreeRDP/assets/about_page/about.html b/client/Android/Studio/aFreeRDP/src/main/assets/about_page/about.html similarity index 100% rename from client/Android/aFreeRDP/assets/about_page/about.html rename to client/Android/Studio/aFreeRDP/src/main/assets/about_page/about.html diff --git a/client/Android/aFreeRDP/assets/about_page/about_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/about_page/about_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/about_page/about_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/about_page/about_phone.html diff --git a/client/Android/aFreeRDP/assets/about_page/background_transparent.png b/client/Android/Studio/aFreeRDP/src/main/assets/about_page/background_transparent.png similarity index 100% rename from client/Android/aFreeRDP/assets/about_page/background_transparent.png rename to client/Android/Studio/aFreeRDP/src/main/assets/about_page/background_transparent.png diff --git a/client/Android/aFreeRDP/assets/background.jpg b/client/Android/Studio/aFreeRDP/src/main/assets/background.jpg similarity index 100% rename from client/Android/aFreeRDP/assets/background.jpg rename to client/Android/Studio/aFreeRDP/src/main/assets/background.jpg diff --git a/client/Android/aFreeRDP/assets/de_about_page/about.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/about.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_about_page/about.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/about.html diff --git a/client/Android/aFreeRDP/assets/de_about_page/about_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/about_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_about_page/about_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/about_phone.html diff --git a/client/Android/aFreeRDP/assets/de_about_page/background_transparent.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/background_transparent.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_about_page/background_transparent.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/background_transparent.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/gestures.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/gestures.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures.html diff --git a/client/Android/aFreeRDP/assets/de_help_page/gestures.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/gestures.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/gestures_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/gestures_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.html diff --git a/client/Android/aFreeRDP/assets/de_help_page/gestures_phone.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/gestures_phone.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/nav_gestures.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_gestures.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/nav_gestures.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_gestures.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/nav_toolbar.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_toolbar.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/nav_toolbar.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_toolbar.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/nav_touch_pointer.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_touch_pointer.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/nav_touch_pointer.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_touch_pointer.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/toolbar.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/toolbar.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.html diff --git a/client/Android/aFreeRDP/assets/de_help_page/toolbar.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/toolbar.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/toolbar_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/toolbar_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.html diff --git a/client/Android/aFreeRDP/assets/de_help_page/toolbar_phone.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/toolbar_phone.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/touch_pointer.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/touch_pointer.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.html diff --git a/client/Android/aFreeRDP/assets/de_help_page/touch_pointer.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/touch_pointer.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.png diff --git a/client/Android/aFreeRDP/assets/de_help_page/touch_pointer_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/touch_pointer_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer_phone.html diff --git a/client/Android/aFreeRDP/assets/de_help_page/touch_pointer_phone.png b/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer_phone.png similarity index 100% rename from client/Android/aFreeRDP/assets/de_help_page/touch_pointer_phone.png rename to client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer_phone.png diff --git a/client/Android/aFreeRDP/assets/help_page/gestures.html b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures.html similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/gestures.html rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures.html diff --git a/client/Android/aFreeRDP/assets/help_page/gestures.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/gestures.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures.png diff --git a/client/Android/aFreeRDP/assets/help_page/gestures_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/gestures_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures_phone.html diff --git a/client/Android/aFreeRDP/assets/help_page/gestures_phone.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures_phone.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/gestures_phone.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/gestures_phone.png diff --git a/client/Android/aFreeRDP/assets/help_page/nav_gestures.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/nav_gestures.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/nav_gestures.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/nav_gestures.png diff --git a/client/Android/aFreeRDP/assets/help_page/nav_toolbar.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/nav_toolbar.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/nav_toolbar.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/nav_toolbar.png diff --git a/client/Android/aFreeRDP/assets/help_page/nav_touch_pointer.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/nav_touch_pointer.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/nav_touch_pointer.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/nav_touch_pointer.png diff --git a/client/Android/aFreeRDP/assets/help_page/toolbar.html b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.html similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/toolbar.html rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.html diff --git a/client/Android/aFreeRDP/assets/help_page/toolbar.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/toolbar.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.png diff --git a/client/Android/aFreeRDP/assets/help_page/toolbar_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/toolbar_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar_phone.html diff --git a/client/Android/aFreeRDP/assets/help_page/toolbar_phone.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar_phone.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/toolbar_phone.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar_phone.png diff --git a/client/Android/aFreeRDP/assets/help_page/touch_pointer.html b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer.html similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/touch_pointer.html rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer.html diff --git a/client/Android/aFreeRDP/assets/help_page/touch_pointer.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/touch_pointer.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer.png diff --git a/client/Android/aFreeRDP/assets/help_page/touch_pointer_phone.html b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer_phone.html similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/touch_pointer_phone.html rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer_phone.html diff --git a/client/Android/aFreeRDP/assets/help_page/touch_pointer_phone.png b/client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer_phone.png similarity index 100% rename from client/Android/aFreeRDP/assets/help_page/touch_pointer_phone.png rename to client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer_phone.png diff --git a/client/Android/aFreeRDP/src/com/freerdp/afreerdp/application/GlobalApp.java b/client/Android/Studio/aFreeRDP/src/main/java/com/freerdp/afreerdp/application/GlobalApp.java similarity index 100% rename from client/Android/aFreeRDP/src/com/freerdp/afreerdp/application/GlobalApp.java rename to client/Android/Studio/aFreeRDP/src/main/java/com/freerdp/afreerdp/application/GlobalApp.java diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_launcher_freerdp.png b/client/Android/Studio/aFreeRDP/src/main/res/drawable-hdpi/icon_launcher_freerdp.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_launcher_freerdp.png rename to client/Android/Studio/aFreeRDP/src/main/res/drawable-hdpi/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_launcher_freerdp.png b/client/Android/Studio/aFreeRDP/src/main/res/drawable-ldpi/icon_launcher_freerdp.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_launcher_freerdp.png rename to client/Android/Studio/aFreeRDP/src/main/res/drawable-ldpi/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_launcher_freerdp.png b/client/Android/Studio/aFreeRDP/src/main/res/drawable-mdpi/icon_launcher_freerdp.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_launcher_freerdp.png rename to client/Android/Studio/aFreeRDP/src/main/res/drawable-mdpi/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable/button_background.xml b/client/Android/Studio/aFreeRDP/src/main/res/drawable/button_background.xml similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/button_background.xml rename to client/Android/Studio/aFreeRDP/src/main/res/drawable/button_background.xml diff --git a/client/Android/FreeRDPCore/res/drawable/icon_launcher_freerdp.png b/client/Android/Studio/aFreeRDP/src/main/res/drawable/icon_launcher_freerdp.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/icon_launcher_freerdp.png rename to client/Android/Studio/aFreeRDP/src/main/res/drawable/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable/separator_background.xml b/client/Android/Studio/aFreeRDP/src/main/res/drawable/separator_background.xml similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/separator_background.xml rename to client/Android/Studio/aFreeRDP/src/main/res/drawable/separator_background.xml diff --git a/client/Android/aFreeRDP/res/values-es/strings.xml b/client/Android/Studio/aFreeRDP/src/main/res/values-es/strings.xml similarity index 80% rename from client/Android/aFreeRDP/res/values-es/strings.xml rename to client/Android/Studio/aFreeRDP/src/main/res/values-es/strings.xml index f0aa7c6af..23ba45774 100644 --- a/client/Android/aFreeRDP/res/values-es/strings.xml +++ b/client/Android/Studio/aFreeRDP/src/main/res/values-es/strings.xml @@ -1,4 +1,4 @@ - + aFreeRDP diff --git a/client/Android/aFreeRDP/res/values-fr/strings.xml b/client/Android/Studio/aFreeRDP/src/main/res/values-fr/strings.xml similarity index 80% rename from client/Android/aFreeRDP/res/values-fr/strings.xml rename to client/Android/Studio/aFreeRDP/src/main/res/values-fr/strings.xml index 3c36d79ff..980236c4b 100644 --- a/client/Android/aFreeRDP/res/values-fr/strings.xml +++ b/client/Android/Studio/aFreeRDP/src/main/res/values-fr/strings.xml @@ -1,4 +1,4 @@ - + aFreeRDP diff --git a/client/Android/aFreeRDP/res/values-nl/strings.xml b/client/Android/Studio/aFreeRDP/src/main/res/values-nl/strings.xml similarity index 80% rename from client/Android/aFreeRDP/res/values-nl/strings.xml rename to client/Android/Studio/aFreeRDP/src/main/res/values-nl/strings.xml index f0aa7c6af..23ba45774 100644 --- a/client/Android/aFreeRDP/res/values-nl/strings.xml +++ b/client/Android/Studio/aFreeRDP/src/main/res/values-nl/strings.xml @@ -1,4 +1,4 @@ - + aFreeRDP diff --git a/client/Android/aFreeRDP/res/values/strings.xml b/client/Android/Studio/aFreeRDP/src/main/res/values/strings.xml similarity index 80% rename from client/Android/aFreeRDP/res/values/strings.xml rename to client/Android/Studio/aFreeRDP/src/main/res/values/strings.xml index f0aa7c6af..23ba45774 100644 --- a/client/Android/aFreeRDP/res/values/strings.xml +++ b/client/Android/Studio/aFreeRDP/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ - + aFreeRDP diff --git a/client/Android/aFreeRDP/res/xml/searchable.xml b/client/Android/Studio/aFreeRDP/src/main/res/xml/searchable.xml similarity index 100% rename from client/Android/aFreeRDP/res/xml/searchable.xml rename to client/Android/Studio/aFreeRDP/src/main/res/xml/searchable.xml diff --git a/client/Android/Studio/build.gradle b/client/Android/Studio/build.gradle new file mode 100644 index 000000000..f4d8c542e --- /dev/null +++ b/client/Android/Studio/build.gradle @@ -0,0 +1,15 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.5.0' + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/client/Android/Studio/freeRDPCore/build.gradle b/client/Android/Studio/freeRDPCore/build.gradle new file mode 100644 index 000000000..44467f784 --- /dev/null +++ b/client/Android/Studio/freeRDPCore/build.gradle @@ -0,0 +1,22 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 21 + buildToolsVersion "23.0.2" + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 21 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} + +dependencies { + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/client/Android/Studio/freeRDPCore/lint.xml b/client/Android/Studio/freeRDPCore/lint.xml new file mode 100644 index 000000000..8423c0ef9 --- /dev/null +++ b/client/Android/Studio/freeRDPCore/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/client/Android/FreeRDPCore/AndroidManifest.xml.cmake b/client/Android/Studio/freeRDPCore/src/main/AndroidManifest.xml similarity index 86% rename from client/Android/FreeRDPCore/AndroidManifest.xml.cmake rename to client/Android/Studio/freeRDPCore/src/main/AndroidManifest.xml index 1e50d7caf..3b7ce2030 100644 --- a/client/Android/FreeRDPCore/AndroidManifest.xml.cmake +++ b/client/Android/Studio/freeRDPCore/src/main/AndroidManifest.xml @@ -1,21 +1,23 @@ - + + android:versionCode="3" + android:versionName="e83f97b" > + android:targetSdkVersion="21" + android:minSdkVersion="14"/> - - + + + + + android:debuggable="false"> sessionMap; + + private static final String TAG = "GlobalApp"; + + public static boolean ConnectedTo3G = false; + + // event notification defines + public static final String EVENT_TYPE = "EVENT_TYPE"; + public static final String EVENT_PARAM = "EVENT_PARAM"; + public static final String EVENT_STATUS = "EVENT_STATUS"; + public static final String EVENT_ERROR = "EVENT_ERROR"; + + public static final String ACTION_EVENT_FREERDP = "com.freerdp.freerdp.event.freerdp"; + + public static final int FREERDP_EVENT_CONNECTION_SUCCESS = 1; + public static final int FREERDP_EVENT_CONNECTION_FAILURE = 2; + public static final int FREERDP_EVENT_DISCONNECTED = 3; + + private static BookmarkDB bookmarkDB; + private static ManualBookmarkGateway manualBookmarkGateway; + + private static HistoryDB historyDB; + private static QuickConnectHistoryGateway quickConnectHistoryGateway; + + // timer for disconnecting sessions after the screen was turned off + private static Timer disconnectTimer = null; + + // TimerTask for disconnecting sessions after screen was turned off + private static class DisconnectTask extends TimerTask { + @Override + public void run() { + Log.v("DisconnectTask", "Doing action"); + + // disconnect any running rdp session + Collection sessions = GlobalApp.getSessions(); + for (SessionState session : sessions) { + LibFreeRDP.disconnect(session.getInstance()); + } + } + } + + + public GlobalApp() { + sessionMap = Collections.synchronizedMap(new HashMap()); + + LibFreeRDP.setEventListener(this); + } + + @Override + public void onCreate() { + super.onCreate(); + + bookmarkDB = new BookmarkDB(this); + + manualBookmarkGateway = new ManualBookmarkGateway(bookmarkDB); + + historyDB = new HistoryDB(this); + quickConnectHistoryGateway = new QuickConnectHistoryGateway(historyDB); + + GlobalSettings.init(this); + ConnectedTo3G = NetworkStateReceiver.isConnectedTo3G(this); + + // init screen receiver here (this can't be declared in AndroidManifest - refer to: + // http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ + IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); + filter.addAction(Intent.ACTION_SCREEN_OFF); + registerReceiver(new ScreenReceiver(), filter); + } + + public static ManualBookmarkGateway getManualBookmarkGateway() { + return manualBookmarkGateway; + } + + public static QuickConnectHistoryGateway getQuickConnectHistoryGateway() { + return quickConnectHistoryGateway; + } + + // Disconnect handling for Screen on/off events + static public void startDisconnectTimer() { + int timeoutMinutes = GlobalSettings.getDisconnectTimeout(); + if (timeoutMinutes > 0) { + // start disconnect timeout... + disconnectTimer = new Timer(); + disconnectTimer.schedule(new DisconnectTask(), timeoutMinutes * 60 * 1000); + } + } + + static public void cancelDisconnectTimer() { + // cancel any pending timer events + if (disconnectTimer != null) { + disconnectTimer.cancel(); + disconnectTimer.purge(); + disconnectTimer = null; + } + } + + // RDP session handling + static public SessionState createSession(BookmarkBase bookmark, Context context) { + SessionState session = new SessionState(LibFreeRDP.newInstance(context), bookmark); + sessionMap.put(Integer.valueOf(session.getInstance()), session); + return session; + } + + static public SessionState getSession(int instance) { + return sessionMap.get(instance); + } + + static public Collection getSessions() { + // return a copy of the session items + return new ArrayList(sessionMap.values()); + } + + static public void freeSession(int instance) { + if (GlobalApp.sessionMap.containsKey(instance)) { + GlobalApp.sessionMap.remove(instance); + LibFreeRDP.freeInstance(instance); + } + } + + // helper to send FreeRDP notifications + private void sendRDPNotification(int type, int param) { + // send broadcast + Intent intent = new Intent(ACTION_EVENT_FREERDP); + intent.putExtra(EVENT_TYPE, type); + intent.putExtra(EVENT_PARAM, param); + sendBroadcast(intent); + } + + @Override + public void OnPreConnect(int instance) { + Log.v(TAG, "OnPreConnect"); + } + + // ////////////////////////////////////////////////////////////////////// + // Implementation of LibFreeRDP.EventListener + public void OnConnectionSuccess(int instance) { + Log.v(TAG, "OnConnectionSuccess"); + sendRDPNotification(FREERDP_EVENT_CONNECTION_SUCCESS, instance); + } + + public void OnConnectionFailure(int instance) { + Log.v(TAG, "OnConnectionFailure"); + + // send notification to session activity + sendRDPNotification(FREERDP_EVENT_CONNECTION_FAILURE, instance); + } + + public void OnDisconnecting(int instance) { + Log.v(TAG, "OnDisconnecting"); + + // send disconnect notification + sendRDPNotification(FREERDP_EVENT_DISCONNECTED, instance); + } + + public void OnDisconnected(int instance) { + Log.v(TAG, "OnDisconnected"); + } +} diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalSettings.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/GlobalSettings.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalSettings.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/GlobalSettings.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/NetworkStateReceiver.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/NetworkStateReceiver.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/NetworkStateReceiver.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/NetworkStateReceiver.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/ScreenReceiver.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/ScreenReceiver.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/ScreenReceiver.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/ScreenReceiver.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/SessionState.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/SessionState.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/SessionState.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/application/SessionState.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/BookmarkBase.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/BookmarkBase.java similarity index 98% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/BookmarkBase.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/BookmarkBase.java index eb8176ca2..eaf1eb68a 100644 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/BookmarkBase.java +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/BookmarkBase.java @@ -27,6 +27,8 @@ public class BookmarkBase implements Parcelable, Cloneable { // performance flags public static class PerformanceFlags implements Parcelable { private boolean remotefx; + private boolean gfx; + private boolean h264; private boolean wallpaper; private boolean theming; private boolean fullWindowDrag; @@ -36,6 +38,8 @@ public class BookmarkBase implements Parcelable, Cloneable { public PerformanceFlags() { remotefx = false; + gfx = false; + h264 = false; wallpaper = false; theming = false; fullWindowDrag = false; @@ -46,6 +50,8 @@ public class BookmarkBase implements Parcelable, Cloneable { public PerformanceFlags(Parcel parcel) { remotefx = parcel.readInt() == 1; + gfx = parcel.readInt() == 1; + h264 = parcel.readInt() == 1; wallpaper = parcel.readInt() == 1; theming = parcel.readInt() == 1; fullWindowDrag = (parcel.readInt() == 1); @@ -57,11 +63,27 @@ public class BookmarkBase implements Parcelable, Cloneable { public boolean getRemoteFX() { return remotefx; } - + public void setRemoteFX(boolean remotefx) { this.remotefx = remotefx; } + public boolean getGfx() { + return gfx; + } + + public void setGfx(boolean gfx) { + this.gfx = gfx; + } + + public boolean getH264() { + return h264; + } + + public void setH264(boolean h264) { + this.h264 = h264; + } + public boolean getWallpaper() { return wallpaper; } @@ -129,6 +151,8 @@ public class BookmarkBase implements Parcelable, Cloneable { @Override public void writeToParcel(Parcel out, int flags) { out.writeInt(remotefx ? 1 : 0); + out.writeInt(gfx ? 1 : 0); + out.writeInt(h264 ? 1 : 0); out.writeInt(wallpaper ? 1 : 0); out.writeInt(theming ? 1 : 0); out.writeInt(fullWindowDrag ? 1 : 0); diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/ConnectionReference.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/ConnectionReference.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/ConnectionReference.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/ConnectionReference.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/ManualBookmark.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/ManualBookmark.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/ManualBookmark.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/ManualBookmark.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/PlaceholderBookmark.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/PlaceholderBookmark.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/PlaceholderBookmark.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/PlaceholderBookmark.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/QuickConnectBookmark.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/QuickConnectBookmark.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/domain/QuickConnectBookmark.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/domain/QuickConnectBookmark.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/AboutActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/AboutActivity.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/AboutActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/AboutActivity.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/ApplicationSettingsActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/ApplicationSettingsActivity.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/ApplicationSettingsActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/ApplicationSettingsActivity.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/BookmarkActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/BookmarkActivity.java similarity index 98% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/BookmarkActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/BookmarkActivity.java index 5df4b776e..9c8140ecb 100644 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/BookmarkActivity.java +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/BookmarkActivity.java @@ -20,7 +20,6 @@ import com.freerdp.freerdpcore.domain.ConnectionReference; import com.freerdp.freerdpcore.domain.ManualBookmark; import com.freerdp.freerdpcore.services.BookmarkBaseGateway; import com.freerdp.freerdpcore.utils.RDPFileParser; -import com.freerdp.freerdpcore.utils.BuildConfiguration; import android.app.AlertDialog; import android.content.ComponentName; @@ -172,16 +171,6 @@ public class BookmarkActivity extends PreferenceActivity implements current_preferences = PREFERENCES_BOOKMARK; } - // Hide debug settings, if not activated. - if (!BuildConfiguration.WITH_ANDROID_DEBUG_MENU - .equalsIgnoreCase("ON")) { - Preference pref = findPreference("bookmark.debug"); - PreferenceCategory cat = (PreferenceCategory)findPreference("category.settings"); - if (pref != null) { - cat.removePreference(pref); - } - } - // update UI with bookmark data SharedPreferences spref = getPreferenceManager().getSharedPreferences(); initSettings(spref); diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/HelpActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/HelpActivity.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/HelpActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/HelpActivity.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/HomeActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/HomeActivity.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/HomeActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/HomeActivity.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/ScrollView2D.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/ScrollView2D.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/ScrollView2D.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/ScrollView2D.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java similarity index 91% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java index fcae85a57..08bc61395 100644 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java @@ -83,71 +83,71 @@ public class SessionActivity extends ActionBarActivity implements @Override public void handleMessage(Message msg) { switch (msg.what) { - case GRAPHICS_CHANGED: { - sessionView.onSurfaceChange(session); - scrollView.requestLayout(); - break; - } - case REFRESH_SESSIONVIEW: { - sessionView.invalidateRegion(); - break; - } - case DISPLAY_TOAST: { - Toast errorToast = Toast.makeText(getApplicationContext(), - msg.obj.toString(), Toast.LENGTH_LONG); - errorToast.show(); - break; - } - case HIDE_ZOOMCONTROLS: { - zoomControls.hide(); - break; - } - case SEND_MOVE_EVENT: { - LibFreeRDP.sendCursorEvent(session.getInstance(), msg.arg1, - msg.arg2, Mouse.getMoveEvent()); - break; - } - case SHOW_DIALOG: { - // create and show the dialog - ((Dialog) msg.obj).show(); - break; - } - case SCROLLING_REQUESTED: { - int scrollX = 0; - int scrollY = 0; - float[] pointerPos = touchPointerView.getPointerPosition(); + case GRAPHICS_CHANGED: { + sessionView.onSurfaceChange(session); + scrollView.requestLayout(); + break; + } + case REFRESH_SESSIONVIEW: { + sessionView.invalidateRegion(); + break; + } + case DISPLAY_TOAST: { + Toast errorToast = Toast.makeText(getApplicationContext(), + msg.obj.toString(), Toast.LENGTH_LONG); + errorToast.show(); + break; + } + case HIDE_ZOOMCONTROLS: { + zoomControls.hide(); + break; + } + case SEND_MOVE_EVENT: { + LibFreeRDP.sendCursorEvent(session.getInstance(), msg.arg1, + msg.arg2, Mouse.getMoveEvent()); + break; + } + case SHOW_DIALOG: { + // create and show the dialog + ((Dialog) msg.obj).show(); + break; + } + case SCROLLING_REQUESTED: { + int scrollX = 0; + int scrollY = 0; + float[] pointerPos = touchPointerView.getPointerPosition(); - if (pointerPos[0] > (screen_width - touchPointerView - .getPointerWidth())) - scrollX = SCROLLING_DISTANCE; - else if (pointerPos[0] < 0) - scrollX = -SCROLLING_DISTANCE; + if (pointerPos[0] > (screen_width - touchPointerView + .getPointerWidth())) + scrollX = SCROLLING_DISTANCE; + else if (pointerPos[0] < 0) + scrollX = -SCROLLING_DISTANCE; - if (pointerPos[1] > (screen_height - touchPointerView - .getPointerHeight())) - scrollY = SCROLLING_DISTANCE; - else if (pointerPos[1] < 0) - scrollY = -SCROLLING_DISTANCE; + if (pointerPos[1] > (screen_height - touchPointerView + .getPointerHeight())) + scrollY = SCROLLING_DISTANCE; + else if (pointerPos[1] < 0) + scrollY = -SCROLLING_DISTANCE; - scrollView.scrollBy(scrollX, scrollY); + scrollView.scrollBy(scrollX, scrollY); - // see if we reached the min/max scroll positions - if (scrollView.getScrollX() == 0 - || scrollView.getScrollX() == (sessionView.getWidth() - scrollView - .getWidth())) - scrollX = 0; - if (scrollView.getScrollY() == 0 - || scrollView.getScrollY() == (sessionView.getHeight() - scrollView - .getHeight())) - scrollY = 0; + // see if we reached the min/max scroll positions + if (scrollView.getScrollX() == 0 + || scrollView.getScrollX() == (sessionView.getWidth() - scrollView + .getWidth())) + scrollX = 0; + if (scrollView.getScrollY() == 0 + || scrollView.getScrollY() == (sessionView.getHeight() - scrollView + .getHeight())) + scrollY = 0; - if (scrollX != 0 || scrollY != 0) - uiHandler.sendEmptyMessageDelayed(SCROLLING_REQUESTED, - SCROLLING_TIMEOUT); - else - Log.v(TAG, "Stopping auto-scroll"); - break; - } + if (scrollX != 0 || scrollY != 0) + uiHandler.sendEmptyMessageDelayed(SCROLLING_REQUESTED, + SCROLLING_TIMEOUT); + else + Log.v(TAG, "Stopping auto-scroll"); + break; + } } } } @@ -216,16 +216,16 @@ public class SessionActivity extends ActionBarActivity implements return; switch (intent.getExtras().getInt(GlobalApp.EVENT_TYPE, -1)) { - case GlobalApp.FREERDP_EVENT_CONNECTION_SUCCESS: - OnConnectionSuccess(context); - break; + case GlobalApp.FREERDP_EVENT_CONNECTION_SUCCESS: + OnConnectionSuccess(context); + break; - case GlobalApp.FREERDP_EVENT_CONNECTION_FAILURE: - OnConnectionFailure(context); - break; - case GlobalApp.FREERDP_EVENT_DISCONNECTED: - OnDisconnected(context); - break; + case GlobalApp.FREERDP_EVENT_CONNECTION_FAILURE: + OnConnectionFailure(context); + break; + case GlobalApp.FREERDP_EVENT_DISCONNECTED: + OnDisconnected(context); + break; } } @@ -247,7 +247,7 @@ public class SessionActivity extends ActionBarActivity implements if (ConnectionReference.isHostnameReference(bundle .getString(PARAM_CONNECTION_REFERENCE))) { assert session.getBookmark().getType() == BookmarkBase.TYPE_MANUAL; - String item = session.getBookmark(). get() + String item = session.getBookmark().get() .getHostname(); if (!GlobalApp.getQuickConnectHistoryGateway() .historyItemExists(item)) @@ -361,7 +361,7 @@ public class SessionActivity extends ActionBarActivity implements new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, - int which) { + int which) { callbackDialogResult = true; synchronized (dialog) { dialog.notify(); @@ -372,7 +372,7 @@ public class SessionActivity extends ActionBarActivity implements new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, - int which) { + int which) { callbackDialogResult = false; connectCancelledByUser = true; synchronized (dialog) { @@ -391,7 +391,7 @@ public class SessionActivity extends ActionBarActivity implements new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, - int which) { + int which) { callbackDialogResult = true; synchronized (dialog) { dialog.notify(); @@ -402,7 +402,7 @@ public class SessionActivity extends ActionBarActivity implements new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, - int which) { + int which) { callbackDialogResult = false; connectCancelledByUser = true; synchronized (dialog) { @@ -415,14 +415,14 @@ public class SessionActivity extends ActionBarActivity implements private boolean hasHardwareMenuButton() { if (Build.VERSION.SDK_INT <= 10) return true; - + if (Build.VERSION.SDK_INT >= 14) { boolean rc = false; final ViewConfiguration cfg = ViewConfiguration.get(this); - + return cfg.hasPermanentMenuKey(); } - + return false; } @@ -626,7 +626,7 @@ public class SessionActivity extends ActionBarActivity implements String refStr = bundle.getString(PARAM_CONNECTION_REFERENCE); if (ConnectionReference.isHostnameReference(refStr)) { bookmark = new ManualBookmark(); - bookmark. get().setHostname( + bookmark.get().setHostname( ConnectionReference.getHostname(refStr)); } else if (ConnectionReference.isBookmarkReference(refStr)) { if (ConnectionReference.isManualBookmarkReference(refStr)) @@ -647,13 +647,9 @@ public class SessionActivity extends ActionBarActivity implements } private void connect(BookmarkBase bookmark) { - session = GlobalApp.createSession(bookmark); + session = GlobalApp.createSession(bookmark, getApplicationContext()); session.setUIEventListener(this); - // set writeable data directory - LibFreeRDP.setDataDirectory(session.getInstance(), getFilesDir() - .toString()); - BookmarkBase.ScreenSettings screenSettings = session.getBookmark() .getActiveScreenSettings(); Log.v(TAG, "Screen Resolution: " + screenSettings.getResolutionString()); @@ -712,7 +708,7 @@ public class SessionActivity extends ActionBarActivity implements // displays either the system or the extended keyboard or non of them private void showKeyboard(boolean showSystemKeyboard, - boolean showExtendedKeyboard) { + boolean showExtendedKeyboard) { // no matter what we are doing ... hide the zoom controls // TODO: this is not working correctly as hiding the keyboard issues a // onScrollChange notification showing the control again ... @@ -769,25 +765,25 @@ public class SessionActivity extends ActionBarActivity implements // check if any key is in the keycodes list List keys = modifiersKeyboard.getKeys(); - for (Iterator it = keys.iterator(); it.hasNext();) { + for (Iterator it = keys.iterator(); it.hasNext(); ) { // if the key is a sticky key - just set it to off Keyboard.Key curKey = it.next(); if (curKey.sticky) { switch (keyboardMapper.getModifierState(curKey.codes[0])) { - case KeyboardMapper.KEYSTATE_ON: - curKey.on = true; - curKey.pressed = false; - break; + case KeyboardMapper.KEYSTATE_ON: + curKey.on = true; + curKey.pressed = false; + break; - case KeyboardMapper.KEYSTATE_OFF: - curKey.on = false; - curKey.pressed = false; - break; + case KeyboardMapper.KEYSTATE_OFF: + curKey.on = false; + curKey.pressed = false; + break; - case KeyboardMapper.KEYSTATE_LOCKED: - curKey.on = true; - curKey.pressed = true; - break; + case KeyboardMapper.KEYSTATE_LOCKED: + curKey.on = true; + curKey.pressed = true; + break; } } } @@ -860,6 +856,15 @@ public class SessionActivity extends ActionBarActivity implements keyboardMapper.sendAltF4(); } + @Override + public boolean onKeyLongPress(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK) { + LibFreeRDP.disconnect(session.getInstance()); + return true; + } + return super.onKeyLongPress(keyCode, event); + } + // android keyboard input handling // We always use the unicode value to process input from the android // keyboard except if key modifiers @@ -933,20 +938,20 @@ public class SessionActivity extends ActionBarActivity implements @Override public void switchKeyboard(int keyboardType) { switch (keyboardType) { - case KeyboardMapper.KEYBOARD_TYPE_FUNCTIONKEYS: - keyboardView.setKeyboard(specialkeysKeyboard); - break; + case KeyboardMapper.KEYBOARD_TYPE_FUNCTIONKEYS: + keyboardView.setKeyboard(specialkeysKeyboard); + break; - case KeyboardMapper.KEYBOARD_TYPE_NUMPAD: - keyboardView.setKeyboard(numpadKeyboard); - break; + case KeyboardMapper.KEYBOARD_TYPE_NUMPAD: + keyboardView.setKeyboard(numpadKeyboard); + break; - case KeyboardMapper.KEYBOARD_TYPE_CURSOR: - keyboardView.setKeyboard(cursorKeyboard); - break; + case KeyboardMapper.KEYBOARD_TYPE_CURSOR: + keyboardView.setKeyboard(cursorKeyboard); + break; - default: - break; + default: + break; } } @@ -1020,7 +1025,7 @@ public class SessionActivity extends ActionBarActivity implements @Override public boolean OnAuthenticate(StringBuilder username, StringBuilder domain, - StringBuilder password) { + StringBuilder password) { // this is where the return code of our dialog will be stored callbackDialogResult = false; @@ -1062,7 +1067,7 @@ public class SessionActivity extends ActionBarActivity implements @Override public boolean OnVerifiyCertificate(String subject, String issuer, - String fingerprint) { + String fingerprint) { // see if global settings says accept all if (GlobalSettings.getAcceptAllCertificates()) @@ -1109,7 +1114,7 @@ public class SessionActivity extends ActionBarActivity implements @Override public void onScrollChanged(ScrollView2D scrollView, int x, int y, - int oldx, int oldy) { + int oldx, int oldy) { zoomControls.setIsZoomInEnabled(!sessionView.isAtMaxZoom()); zoomControls.setIsZoomOutEnabled(!sessionView.isAtMinZoom()); if (!GlobalSettings.getHideZoomControls() diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionView.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionView.java similarity index 99% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionView.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionView.java index ea2b0cc07..6d0780690 100644 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionView.java +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionView.java @@ -28,6 +28,8 @@ import com.freerdp.freerdpcore.utils.GestureDetector; public class SessionView extends View { + private static final String TAG = "SessionView"; + public interface SessionViewListener { abstract void onSessionViewBeginTouch(); abstract void onSessionViewEndTouch(); @@ -291,7 +293,7 @@ public class SessionView extends View @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - Log.v("SessionView", width + "x" + height); + Log.v(TAG, width + "x" + height); this.setMeasuredDimension((int)(width * scaleFactor) + touchPointerPaddingWidth, (int)(height * scaleFactor) + touchPointerPaddingHeight); } diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/ShortcutsActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/ShortcutsActivity.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/ShortcutsActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/ShortcutsActivity.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/TouchPointerView.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/TouchPointerView.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/TouchPointerView.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/TouchPointerView.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/BookmarkBaseGateway.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/BookmarkBaseGateway.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/BookmarkBaseGateway.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/BookmarkBaseGateway.java diff --git a/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/BookmarkDB.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/BookmarkDB.java new file mode 100644 index 000000000..7796f440a --- /dev/null +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/BookmarkDB.java @@ -0,0 +1,227 @@ +/* + Android Bookmark Database + + Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz + + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +package com.freerdp.freerdpcore.services; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import android.content.Context; +import android.provider.BaseColumns; +import android.util.Log; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class BookmarkDB extends SQLiteOpenHelper { + private static final int DB_VERSION = 7; + private static final String DB_NAME = "bookmarks.db"; + + public static final String ID = BaseColumns._ID; + + public BookmarkDB(Context context) { + super(context, DB_NAME, null, DB_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + String sqlScreenSettings = + "CREATE TABLE tbl_screen_settings (" + + ID + " INTEGER PRIMARY KEY, " + + "colors INTEGER DEFAULT 16, " + + "resolution INTEGER DEFAULT 0, " + + "width, " + + "height);"; + + db.execSQL(sqlScreenSettings); + + String sqlPerformanceFlags = + "CREATE TABLE tbl_performance_flags (" + + ID + " INTEGER PRIMARY KEY, " + + "perf_remotefx INTEGER, " + + "perf_gfx INTEGER," + + "perf_gfx_h264 INTEGER," + + "perf_wallpaper INTEGER, " + + "perf_theming INTEGER, " + + "perf_full_window_drag INTEGER, " + + "perf_menu_animations INTEGER, " + + "perf_font_smoothing INTEGER, " + + "perf_desktop_composition INTEGER);"; + + db.execSQL(sqlPerformanceFlags); + + String sqlManualBookmarks = getManualBookmarksCreationString(); + db.execSQL(sqlManualBookmarks); + + + // Insert a test entry + String sqlInsertDefaultScreenEntry = + "INSERT INTO tbl_screen_settings (" + + "colors, " + + "resolution, " + + "width, " + + "height) " + + "VALUES ( " + + "32, 1, 1024, 768);"; + db.execSQL(sqlInsertDefaultScreenEntry); + db.execSQL(sqlInsertDefaultScreenEntry); + + String sqlInsertDefaultPerfFlags = + "INSERT INTO tbl_performance_flags (" + + "perf_remotefx, " + + "perf_gfx" + + "perf_gfx_h264" + + "perf_wallpaper, " + + "perf_theming, " + + "perf_full_window_drag, " + + "perf_menu_animations, " + + "perf_font_smoothing, " + + "perf_desktop_composition) " + + "VALUES ( " + + "1, 1, 1, 0, 0, 0, 0, 0, 0);"; + db.execSQL(sqlInsertDefaultPerfFlags); + db.execSQL(sqlInsertDefaultPerfFlags); + + String sqlInsertDefaultSessionEntry = + "INSERT INTO tbl_manual_bookmarks (" + + "label, " + + "hostname, " + + "username, " + + "password, " + + "domain, " + + "port, " + + "screen_settings, " + + "performance_flags, " + + "screen_3g, " + + "performance_3g, " + + "redirect_sdcard, " + + "redirect_sound, " + + "redirect_microphone, " + + "security, " + + "remote_program, " + + "work_dir, " + + "async_channel, " + + "async_transport, " + + "async_input, " + + "async_update, " + + "console_mode, " + + "debug_level ) " + + "VALUES ( " + + "'Test Server', " + + "'testservice.afreerdp.com', " + + "'', " + + "'', " + + "'', " + + "3389, " + + "1, 1, 2, 2, 0, 0, 0, 0, " + + "'', '', " + + "1, 1, 1, 1, 0, 0);"; + db.execSQL(sqlInsertDefaultSessionEntry); + } + + private String getManualBookmarksCreationString() { + return ( + "CREATE TABLE IF NOT EXISTS tbl_manual_bookmarks (" + + ID + " INTEGER PRIMARY KEY, " + + "label TEXT NOT NULL, " + + "hostname TEXT NOT NULL, " + + "username TEXT NOT NULL, " + + "password TEXT, " + + "domain TEXT, " + + "port TEXT, " + + "screen_settings INTEGER NOT NULL, " + + "performance_flags INTEGER NOT NULL, " + + + "enable_gateway_settings INTEGER DEFAULT 0, " + + "gateway_hostname TEXT, " + + "gateway_port INTEGER DEFAULT 443, " + + "gateway_username TEXT, " + + "gateway_password TEXT, " + + "gateway_domain TEXT, " + + + "enable_3g_settings INTEGER DEFAULT 0, " + + "screen_3g INTEGER NOT NULL, " + + "performance_3g INTEGER NOT NULL, " + + "redirect_sdcard INTEGER DEFAULT 0, " + + "redirect_sound INTEGER DEFAULT 0, " + + "redirect_microphone INTEGER DEFAULT 0, " + + "security INTEGER, " + + "remote_program TEXT, " + + "work_dir TEXT, " + + "async_channel INTEGER DEFAULT 0, " + + "async_transport INTEGER DEFAULT 0, " + + "async_input INTEGER DEFAULT 0, " + + "async_update INTEGER DEFAULT 0, " + + "console_mode INTEGER, " + + "debug_level INTEGER DEFAULT 0, " + + + "FOREIGN KEY(screen_settings) REFERENCES tbl_screen_settings(" + ID + "), " + + "FOREIGN KEY(performance_flags) REFERENCES tbl_performance_flags(" + ID + "), " + + "FOREIGN KEY(screen_3g) REFERENCES tbl_screen_settings(" + ID + "), " + + "FOREIGN KEY(performance_3g) REFERENCES tbl_performance_flags(" + ID + ") " + + + ");"); + } + + // from http://stackoverflow.com/questions/3424156/upgrade-sqlite-database-from-one-version-to-another + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.beginTransaction(); + + // run a table creation with if not exists (we are doing an upgrade, so the table might + // not exists yet, it will fail alter and drop) + db.execSQL(getManualBookmarksCreationString()); + // put in a list the existing columns + List columns = GetColumns(db, "tbl_manual_bookmarks"); + // backup table + db.execSQL("ALTER TABLE tbl_manual_bookmarks RENAME TO 'temp_tbl_manual_bookmarks'"); + // create new table (with new scheme) + db.execSQL(getManualBookmarksCreationString()); + // get the intersection with the new columns, this time columns taken from the upgraded table + columns.retainAll(GetColumns(db, "tbl_manual_bookmarks")); + // restore data + String cols = joinStrings(columns, ","); + db.execSQL(String.format("INSERT INTO %s (%s) SELECT %s from 'temp_%s", "tbl_manual_bookmarks", cols, cols, "tbl_manual_bookmarks'")); + // remove backup table + db.execSQL("DROP table 'temp_tbl_manual_bookmarks'"); + + db.setTransactionSuccessful(); + db.endTransaction(); + } + + private static List GetColumns(SQLiteDatabase db, String tableName) { + List ar = null; + Cursor c = null; + try { + c = db.rawQuery("SELECT * FROM " + tableName + " LIMIT 1", null); + if (c != null) { + ar = new ArrayList(Arrays.asList(c.getColumnNames())); + } + } catch (Exception e) { + Log.v(tableName, e.getMessage(), e); + e.printStackTrace(); + } finally { + if (c != null) + c.close(); + } + return ar; + } + + private static String joinStrings(List list, String delim) { + StringBuilder buf = new StringBuilder(); + int num = list.size(); + for (int i = 0; i < num; i++) { + if (i != 0) + buf.append(delim); + buf.append((String) list.get(i)); + } + return buf.toString(); + } +} diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/FreeRDPSuggestionProvider.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/FreeRDPSuggestionProvider.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/FreeRDPSuggestionProvider.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/FreeRDPSuggestionProvider.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/HistoryDB.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/HistoryDB.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/HistoryDB.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/HistoryDB.java diff --git a/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java new file mode 100644 index 000000000..c07a5d26e --- /dev/null +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java @@ -0,0 +1,373 @@ +/* + Android FreeRDP JNI Wrapper + + Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz + + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +package com.freerdp.freerdpcore.services; + + +import com.freerdp.freerdpcore.application.GlobalApp; +import com.freerdp.freerdpcore.application.SessionState; +import com.freerdp.freerdpcore.domain.BookmarkBase; +import com.freerdp.freerdpcore.domain.ManualBookmark; + +import android.content.Context; +import android.graphics.Bitmap; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +public class LibFreeRDP { + private static final String TAG = "LibFreeRDP"; + + static { + final String[] libraries = { + "openh264", "crypto", "ssl", "jpeg", "winpr", + "freerdp", "freerdp-client", "freerdp-android"}; + final String LD_PATH = System.getProperty("java.library.path"); + + for (String lib : libraries) { + try { + Log.v(TAG, "Trying to load library " + lib + " from LD_PATH: " + LD_PATH); + System.loadLibrary(lib); + } catch (UnsatisfiedLinkError e) { + Log.e(TAG, "Failed to load library " + lib + ": " + e.toString()); + } + } + } + + private static native String freerdp_get_jni_version(); + + private static native String freerdp_get_version(); + + private static native String freerdp_get_build_date(); + + private static native String freerdp_get_build_revision(); + + private static native String freerdp_get_build_config(); + + private static native int freerdp_new(Context context); + + private static native void freerdp_free(int inst); + + private static native boolean freerdp_parse_arguments(int inst, String[] args); + + private static native boolean freerdp_connect(int inst); + + private static native boolean freerdp_disconnect(int inst); + + private static native boolean freerdp_update_graphics(int inst, + Bitmap bitmap, int x, int y, int width, int height); + + private static native boolean freerdp_send_cursor_event(int inst, int x, int y, int flags); + + private static native boolean freerdp_send_key_event(int inst, int keycode, boolean down); + + private static native boolean freerdp_send_unicodekey_event(int inst, int keycode); + + private static native boolean freerdp_send_clipboard_data(int inst, String data); + + public static interface EventListener { + void OnPreConnect(int instance); + + void OnConnectionSuccess(int instance); + + void OnConnectionFailure(int instance); + + void OnDisconnecting(int instance); + + void OnDisconnected(int instance); + } + + public static interface UIEventListener { + void OnSettingsChanged(int width, int height, int bpp); + + boolean OnAuthenticate(StringBuilder username, StringBuilder domain, StringBuilder password); + + boolean OnVerifiyCertificate(String subject, String issuer, String fingerprint); + + void OnGraphicsUpdate(int x, int y, int width, int height); + + void OnGraphicsResize(int width, int height, int bpp); + + void OnRemoteClipboardChanged(String data); + } + + private static EventListener listener; + + public static void setEventListener(EventListener l) { + listener = l; + } + + public static int newInstance(Context context) { + return freerdp_new(context); + } + + public static void freeInstance(int inst) { + freerdp_free(inst); + } + + public static boolean connect(int inst) { + return freerdp_connect(inst); + } + + public static boolean disconnect(int inst) { + return freerdp_disconnect(inst); + } + + public static boolean cancelConnection(int inst) { + return freerdp_disconnect(inst); + } + + private static String addFlag(String name, boolean enabled) { + if (enabled) { + return "+" + name; + } + return "-" + name; + } + + public static boolean setConnectionInfo(int inst, BookmarkBase bookmark) { + BookmarkBase.ScreenSettings screenSettings = bookmark.getActiveScreenSettings(); + BookmarkBase.AdvancedSettings advanced = bookmark.getAdvancedSettings(); + BookmarkBase.DebugSettings debug = bookmark.getDebugSettings(); + + String arg; + ArrayList args = new ArrayList(); + + args.add(TAG); + args.add("/gdi:sw"); + + String certName = ""; + if (bookmark.getType() != BookmarkBase.TYPE_MANUAL) { + return false; + } + + int port = bookmark.get().getPort(); + String hostname = bookmark.get().getHostname(); + + args.add("/v:" + hostname); + args.add("/port:" + String.valueOf(port)); + + arg = bookmark.getUsername(); + if (!arg.isEmpty()) { + args.add("/u:" + arg); + } + arg = bookmark.getDomain(); + if (!arg.isEmpty()) { + args.add("/d:" + arg); + } + arg = bookmark.getPassword(); + if (!arg.isEmpty()) { + args.add("/p:" + arg); + } + + args.add(String.format("/size:%dx%d", screenSettings.getWidth(), + screenSettings.getHeight())); + args.add("/bpp:" + String.valueOf(screenSettings.getColors())); + + if (advanced.getConsoleMode()) { + args.add("/admin"); + } + + switch (advanced.getSecurity()) { + case 3: // NLA + args.add("/sec-nla"); + break; + case 2: // TLS + args.add("/sec-tls"); + break; + case 1: // RDP + args.add("/sec-rdp"); + break; + default: + break; + } + + if (!certName.isEmpty()) { + args.add("/cert-name:" + certName); + } + + BookmarkBase.PerformanceFlags flags = bookmark.getActivePerformanceFlags(); + if (flags.getRemoteFX()) { + args.add("/rfx"); + } + + if (flags.getGfx()) { + args.add("/gfx"); + } + + if (flags.getH264()) { + args.add("/h264"); + } + + args.add(addFlag("wallpaper", flags.getWallpaper())); + args.add(addFlag("window-drag", flags.getFullWindowDrag())); + args.add(addFlag("menu-anims", flags.getMenuAnimations())); + args.add(addFlag("themes", flags.getTheming())); + args.add(addFlag("fonts", flags.getFontSmoothing())); + args.add(addFlag("aero", flags.getDesktopComposition())); + + if (!advanced.getRemoteProgram().isEmpty()) { + args.add("/app:" + advanced.getRemoteProgram()); + } + + if (!advanced.getWorkDir().isEmpty()) { + args.add("/shell-dir:" + advanced.getWorkDir()); + } + + args.add(addFlag("async-channels", debug.getAsyncChannel())); + args.add(addFlag("async-transport", debug.getAsyncTransport())); + args.add(addFlag("async-input", debug.getAsyncInput())); + args.add(addFlag("async-update", debug.getAsyncUpdate())); + + if (advanced.getRedirectSDCard()) { + String path = android.os.Environment.getExternalStorageDirectory().getPath(); + args.add("/drive:sdcard," + path); + } + + args.add("/clipboard"); + + // Gateway enabled? + if (bookmark.getType() == BookmarkBase.TYPE_MANUAL && bookmark.get().getEnableGatewaySettings()) { + ManualBookmark.GatewaySettings gateway = bookmark.get().getGatewaySettings(); + + args.add(String.format("/g:%s:%d", gateway.getHostname(), gateway.getPort())); + + arg = gateway.getUsername(); + if (!arg.isEmpty()) { + args.add("/gu:" + arg); + } + arg = gateway.getDomain(); + if (!arg.isEmpty()) { + args.add("/gd:" + arg); + } + arg = gateway.getPassword(); + if (!arg.isEmpty()) { + args.add("/gp:" + arg); + } + } + + /* 0 ... disable + 1 ... local + 2 ... remote */ + args.add("/audio-mode:" + String.valueOf(advanced.getRedirectSound())); + + if (advanced.getRedirectMicrophone()) { + args.add("/microphone"); + } + + args.add("/log-level:TRACE"); + String[] arrayArgs = args.toArray(new String[args.size()]); + return freerdp_parse_arguments(inst, arrayArgs); + } + + public static boolean updateGraphics(int inst, Bitmap bitmap, int x, int y, int width, int height) { + return freerdp_update_graphics(inst, bitmap, x, y, width, height); + } + + public static boolean sendCursorEvent(int inst, int x, int y, int flags) { + return freerdp_send_cursor_event(inst, x, y, flags); + } + + public static boolean sendKeyEvent(int inst, int keycode, boolean down) { + return freerdp_send_key_event(inst, keycode, down); + } + + public static boolean sendUnicodeKeyEvent(int inst, int keycode) { + return freerdp_send_unicodekey_event(inst, keycode); + } + + public static boolean sendClipboardData(int inst, String data) { + return freerdp_send_clipboard_data(inst, data); + } + + private static void OnConnectionSuccess(int inst) { + if (listener != null) + listener.OnConnectionSuccess(inst); + } + + private static void OnConnectionFailure(int inst) { + if (listener != null) + listener.OnConnectionFailure(inst); + } + + private static void OnPreConnect(int inst) { + if (listener != null) + listener.OnPreConnect(inst); + } + + private static void OnDisconnecting(int inst) { + if (listener != null) + listener.OnDisconnecting(inst); + } + + private static void OnDisconnected(int inst) { + if (listener != null) + listener.OnDisconnected(inst); + } + + private static void OnSettingsChanged(int inst, int width, int height, int bpp) { + SessionState s = GlobalApp.getSession(inst); + if (s == null) + return; + UIEventListener uiEventListener = s.getUIEventListener(); + if (uiEventListener != null) + uiEventListener.OnSettingsChanged(width, height, bpp); + } + + private static boolean OnAuthenticate(int inst, StringBuilder username, StringBuilder domain, StringBuilder password) { + SessionState s = GlobalApp.getSession(inst); + if (s == null) + return false; + UIEventListener uiEventListener = s.getUIEventListener(); + if (uiEventListener != null) + return uiEventListener.OnAuthenticate(username, domain, password); + return false; + } + + private static boolean OnVerifyCertificate(int inst, String subject, String issuer, String fingerprint) { + SessionState s = GlobalApp.getSession(inst); + if (s == null) + return false; + UIEventListener uiEventListener = s.getUIEventListener(); + if (uiEventListener != null) + return uiEventListener.OnVerifiyCertificate(subject, issuer, fingerprint); + return false; + } + + private static void OnGraphicsUpdate(int inst, int x, int y, int width, int height) { + SessionState s = GlobalApp.getSession(inst); + if (s == null) + return; + UIEventListener uiEventListener = s.getUIEventListener(); + if (uiEventListener != null) + uiEventListener.OnGraphicsUpdate(x, y, width, height); + } + + private static void OnGraphicsResize(int inst, int width, int height, int bpp) { + SessionState s = GlobalApp.getSession(inst); + if (s == null) + return; + UIEventListener uiEventListener = s.getUIEventListener(); + if (uiEventListener != null) + uiEventListener.OnGraphicsResize(width, height, bpp); + } + + private static void OnRemoteClipboardChanged(int inst, String data) { + SessionState s = GlobalApp.getSession(inst); + if (s == null) + return; + UIEventListener uiEventListener = s.getUIEventListener(); + if (uiEventListener != null) + uiEventListener.OnRemoteClipboardChanged(data); + } + + public static String getVersion() { + return freerdp_get_version(); + } +} diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/ManualBookmarkGateway.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/ManualBookmarkGateway.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/ManualBookmarkGateway.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/ManualBookmarkGateway.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/QuickConnectHistoryGateway.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/QuickConnectHistoryGateway.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/QuickConnectHistoryGateway.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/QuickConnectHistoryGateway.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/SessionRequestHandlerActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/SessionRequestHandlerActivity.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/services/SessionRequestHandlerActivity.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/SessionRequestHandlerActivity.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/BookmarkArrayAdapter.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/BookmarkArrayAdapter.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/BookmarkArrayAdapter.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/BookmarkArrayAdapter.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/ButtonPreference.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/ButtonPreference.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/ButtonPreference.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/ButtonPreference.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/ClipboardManagerProxy.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/ClipboardManagerProxy.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/ClipboardManagerProxy.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/ClipboardManagerProxy.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/DoubleGestureDetector.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/DoubleGestureDetector.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/DoubleGestureDetector.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/DoubleGestureDetector.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/GestureDetector.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/GestureDetector.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/GestureDetector.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/GestureDetector.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/IntEditTextPreference.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/IntEditTextPreference.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/IntEditTextPreference.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/IntEditTextPreference.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/IntListPreference.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/IntListPreference.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/IntListPreference.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/IntListPreference.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/KeyboardMapper.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/KeyboardMapper.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/KeyboardMapper.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/KeyboardMapper.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/Mouse.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/Mouse.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/Mouse.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/Mouse.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/RDPFileParser.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/RDPFileParser.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/RDPFileParser.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/RDPFileParser.java diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/SeparatedListAdapter.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/SeparatedListAdapter.java similarity index 100% rename from client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/utils/SeparatedListAdapter.java rename to client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/utils/SeparatedListAdapter.java diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_button_add.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_button_add.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_button_add.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_button_add.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_edittext_clear.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_edittext_clear.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_edittext_clear.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_edittext_clear.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_edittext_search.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_edittext_search.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_edittext_search.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_edittext_search.png diff --git a/client/Android/aFreeRDP/res/drawable-hdpi/icon_launcher_freerdp.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_launcher_freerdp.png similarity index 100% rename from client/Android/aFreeRDP/res/drawable-hdpi/icon_launcher_freerdp.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_about.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_about.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_about.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_about.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_add.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_add.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_add.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_add.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_close.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_close.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_close.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_close.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_disconnect.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_disconnect.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_disconnect.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_disconnect.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_ext_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_ext_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_ext_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_ext_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_help.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_help.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_help.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_help.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_preferences.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_preferences.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_preferences.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_preferences.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_settings.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_settings.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_settings.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_settings.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_sys_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_sys_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_sys_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_sys_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_touch_pointer.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_touch_pointer.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_menu_touch_pointer.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_menu_touch_pointer.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_star_off.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_star_off.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_star_off.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_star_off.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/icon_star_on.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_star_on.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/icon_star_on.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/icon_star_on.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/search_plate.9.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/search_plate.9.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/search_plate.9.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/search_plate.9.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_delete.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_delete.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_delete.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_delete.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_feedback_delete.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_feedback_delete.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_feedback_delete.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_feedback_delete.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_feedback_return.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_feedback_return.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_feedback_return.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_feedback_return.png diff --git a/client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_return.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_return.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-hdpi/sym_keyboard_return.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-hdpi/sym_keyboard_return.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_button_add.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_button_add.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_button_add.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_button_add.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_edittext_search.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_edittext_search.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_edittext_search.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_edittext_search.png diff --git a/client/Android/aFreeRDP/res/drawable-ldpi/icon_launcher_freerdp.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_launcher_freerdp.png similarity index 100% rename from client/Android/aFreeRDP/res/drawable-ldpi/icon_launcher_freerdp.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_about.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_about.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_about.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_about.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_add.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_add.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_add.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_add.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_disconnect.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_disconnect.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_disconnect.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_disconnect.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_exit.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_exit.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_exit.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_exit.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_ext_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_ext_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_ext_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_ext_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_help.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_help.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_help.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_help.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_preferences.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_preferences.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_preferences.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_preferences.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_settings.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_settings.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_settings.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_settings.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_sys_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_sys_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_sys_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_sys_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_touch_pointer.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_touch_pointer.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_menu_touch_pointer.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_touch_pointer.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_star_off.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_star_off.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_star_off.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_star_off.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/icon_star_on.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_star_on.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/icon_star_on.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_star_on.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/search_plate.9.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/search_plate.9.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/search_plate.9.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/search_plate.9.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_delete.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_delete.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_delete.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_delete.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_feedback_delete.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_feedback_delete.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_feedback_delete.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_feedback_delete.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_feedback_return.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_feedback_return.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_feedback_return.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_feedback_return.png diff --git a/client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_return.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_return.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-ldpi/sym_keyboard_return.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/sym_keyboard_return.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_button_add.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_button_add.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_button_add.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_button_add.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_edittext_clear.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_edittext_clear.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_edittext_clear.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_edittext_clear.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_edittext_search.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_edittext_search.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_edittext_search.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_edittext_search.png diff --git a/client/Android/aFreeRDP/res/drawable-mdpi/icon_launcher_freerdp.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_launcher_freerdp.png similarity index 100% rename from client/Android/aFreeRDP/res/drawable-mdpi/icon_launcher_freerdp.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_launcher_freerdp.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_about.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_about.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_about.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_about.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_add.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_add.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_add.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_add.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_disconnect.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_disconnect.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_disconnect.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_disconnect.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_exit.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_exit.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_exit.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_exit.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_ext_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_ext_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_ext_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_ext_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_help.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_help.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_help.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_help.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_preferences.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_preferences.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_preferences.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_preferences.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_settings.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_settings.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_settings.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_settings.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_sys_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_sys_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_sys_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_sys_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_touch_pointer.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_touch_pointer.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_menu_touch_pointer.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_menu_touch_pointer.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_star_off.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_star_off.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_star_off.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_star_off.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/icon_star_on.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_star_on.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/icon_star_on.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/icon_star_on.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/search_plate.9.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/search_plate.9.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/search_plate.9.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/search_plate.9.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_delete.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_delete.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_delete.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_delete.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_feedback_delete.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_feedback_delete.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_feedback_delete.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_feedback_delete.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_feedback_return.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_feedback_return.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_feedback_return.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_feedback_return.png diff --git a/client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_return.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_return.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable-mdpi/sym_keyboard_return.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable-mdpi/sym_keyboard_return.png diff --git a/client/Android/aFreeRDP/res/drawable/button_background.xml b/client/Android/Studio/freeRDPCore/src/main/res/drawable/button_background.xml similarity index 100% rename from client/Android/aFreeRDP/res/drawable/button_background.xml rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/button_background.xml diff --git a/client/Android/FreeRDPCore/res/drawable/icon_button_cancel.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/icon_button_cancel.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/icon_button_cancel.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/icon_button_cancel.png diff --git a/client/Android/aFreeRDP/res/drawable/icon_launcher_freerdp.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/icon_launcher_freerdp.png similarity index 100% rename from client/Android/aFreeRDP/res/drawable/icon_launcher_freerdp.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/icon_launcher_freerdp.png diff --git a/client/Android/aFreeRDP/res/drawable/separator_background.xml b/client/Android/Studio/freeRDPCore/src/main/res/drawable/separator_background.xml similarity index 100% rename from client/Android/aFreeRDP/res/drawable/separator_background.xml rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/separator_background.xml diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_arrows.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_arrows.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_arrows.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_arrows.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_arrows_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_arrows_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_arrows_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_arrows_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_down_arrow.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_down_arrow.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_down_arrow.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_down_arrow.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_down_arrow_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_down_arrow_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_down_arrow_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_down_arrow_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_left_arrow.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_left_arrow.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_left_arrow.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_left_arrow.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_left_arrow_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_left_arrow_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_left_arrow_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_left_arrow_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_menu.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_menu.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_menu.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_menu.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_menu_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_menu_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_menu_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_menu_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_right_arrow.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_right_arrow.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_right_arrow.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_right_arrow.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_right_arrow_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_right_arrow_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_right_arrow_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_right_arrow_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_up_arrow.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_up_arrow.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_up_arrow.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_up_arrow.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_up_arrow_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_up_arrow_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_up_arrow_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_up_arrow_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_winkey.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_winkey.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_winkey.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_winkey.png diff --git a/client/Android/FreeRDPCore/res/drawable/sym_keyboard_winkey_black.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_winkey_black.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/sym_keyboard_winkey_black.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_winkey_black.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_active.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_active.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_active.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_active.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_default.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_default.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_default.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_default.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_extkeyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_extkeyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_extkeyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_extkeyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_keyboard.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_keyboard.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_keyboard.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_keyboard.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_lclick.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_lclick.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_lclick.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_lclick.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_rclick.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_rclick.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_rclick.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_rclick.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_reset.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_reset.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_reset.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_reset.png diff --git a/client/Android/FreeRDPCore/res/drawable/touch_pointer_scroll.png b/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_scroll.png similarity index 100% rename from client/Android/FreeRDPCore/res/drawable/touch_pointer_scroll.png rename to client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_scroll.png diff --git a/client/Android/FreeRDPCore/res/layout/bookmark_list_item.xml b/client/Android/Studio/freeRDPCore/src/main/res/layout/bookmark_list_item.xml similarity index 100% rename from client/Android/FreeRDPCore/res/layout/bookmark_list_item.xml rename to client/Android/Studio/freeRDPCore/src/main/res/layout/bookmark_list_item.xml diff --git a/client/Android/FreeRDPCore/res/layout/button_preference.xml b/client/Android/Studio/freeRDPCore/src/main/res/layout/button_preference.xml similarity index 100% rename from client/Android/FreeRDPCore/res/layout/button_preference.xml rename to client/Android/Studio/freeRDPCore/src/main/res/layout/button_preference.xml diff --git a/client/Android/FreeRDPCore/res/layout/credentials.xml b/client/Android/Studio/freeRDPCore/src/main/res/layout/credentials.xml similarity index 100% rename from client/Android/FreeRDPCore/res/layout/credentials.xml rename to client/Android/Studio/freeRDPCore/src/main/res/layout/credentials.xml diff --git a/client/Android/FreeRDPCore/res/layout/dont_show_again_dialog.xml b/client/Android/Studio/freeRDPCore/src/main/res/layout/dont_show_again_dialog.xml similarity index 100% rename from client/Android/FreeRDPCore/res/layout/dont_show_again_dialog.xml rename to client/Android/Studio/freeRDPCore/src/main/res/layout/dont_show_again_dialog.xml diff --git a/client/Android/FreeRDPCore/res/layout/home.xml b/client/Android/Studio/freeRDPCore/src/main/res/layout/home.xml similarity index 95% rename from client/Android/FreeRDPCore/res/layout/home.xml rename to client/Android/Studio/freeRDPCore/src/main/res/layout/home.xml index bc311f573..519bd8327 100644 --- a/client/Android/FreeRDPCore/res/layout/home.xml +++ b/client/Android/Studio/freeRDPCore/src/main/res/layout/home.xml @@ -1,4 +1,4 @@ - + Ja diff --git a/client/Android/FreeRDPCore/res/values-es/strings.xml b/client/Android/Studio/freeRDPCore/src/main/res/values-es/strings.xml similarity index 97% rename from client/Android/FreeRDPCore/res/values-es/strings.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values-es/strings.xml index 192045a0a..161629954 100644 --- a/client/Android/FreeRDPCore/res/values-es/strings.xml +++ b/client/Android/Studio/freeRDPCore/src/main/res/values-es/strings.xml @@ -1,4 +1,4 @@ - + Si diff --git a/client/Android/FreeRDPCore/res/values-fr/strings.xml b/client/Android/Studio/freeRDPCore/src/main/res/values-fr/strings.xml similarity index 100% rename from client/Android/FreeRDPCore/res/values-fr/strings.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values-fr/strings.xml diff --git a/client/Android/FreeRDPCore/res/values-land/dimens.xml b/client/Android/Studio/freeRDPCore/src/main/res/values-land/dimens.xml similarity index 100% rename from client/Android/FreeRDPCore/res/values-land/dimens.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values-land/dimens.xml diff --git a/client/Android/FreeRDPCore/res/values-nl/strings.xml b/client/Android/Studio/freeRDPCore/src/main/res/values-nl/strings.xml similarity index 99% rename from client/Android/FreeRDPCore/res/values-nl/strings.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values-nl/strings.xml index 5a28bb7d9..6167cb12f 100644 --- a/client/Android/FreeRDPCore/res/values-nl/strings.xml +++ b/client/Android/Studio/freeRDPCore/src/main/res/values-nl/strings.xml @@ -1,4 +1,4 @@ - + Ja diff --git a/client/Android/FreeRDPCore/res/values-zh/strings.xml b/client/Android/Studio/freeRDPCore/src/main/res/values-zh/strings.xml similarity index 99% rename from client/Android/FreeRDPCore/res/values-zh/strings.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values-zh/strings.xml index b4514265c..bb98f94c9 100644 --- a/client/Android/FreeRDPCore/res/values-zh/strings.xml +++ b/client/Android/Studio/freeRDPCore/src/main/res/values-zh/strings.xml @@ -1,4 +1,4 @@ - + diff --git a/client/Android/FreeRDPCore/res/values/attrs.xml b/client/Android/Studio/freeRDPCore/src/main/res/values/attrs.xml similarity index 100% rename from client/Android/FreeRDPCore/res/values/attrs.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values/attrs.xml diff --git a/client/Android/FreeRDPCore/res/values/dimens.xml b/client/Android/Studio/freeRDPCore/src/main/res/values/dimens.xml similarity index 100% rename from client/Android/FreeRDPCore/res/values/dimens.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values/dimens.xml diff --git a/client/Android/FreeRDPCore/res/values/integers.xml b/client/Android/Studio/freeRDPCore/src/main/res/values/integers.xml similarity index 100% rename from client/Android/FreeRDPCore/res/values/integers.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values/integers.xml diff --git a/client/Android/FreeRDPCore/res/values/strings.xml b/client/Android/Studio/freeRDPCore/src/main/res/values/strings.xml similarity index 98% rename from client/Android/FreeRDPCore/res/values/strings.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values/strings.xml index d2342e0fe..495c9b85c 100644 --- a/client/Android/FreeRDPCore/res/values/strings.xml +++ b/client/Android/Studio/freeRDPCore/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ - + Yes @@ -27,6 +27,7 @@ Manual Connections Active Sessions + foobar Connect to Computer @@ -97,6 +98,8 @@ Performance Performance Settings RemoteFX + GFX + H264 Desktop Background Font Smoothing Desktop Composition diff --git a/client/Android/FreeRDPCore/res/values/theme.xml b/client/Android/Studio/freeRDPCore/src/main/res/values/theme.xml similarity index 98% rename from client/Android/FreeRDPCore/res/values/theme.xml rename to client/Android/Studio/freeRDPCore/src/main/res/values/theme.xml index 5457b1991..99a6103fa 100644 --- a/client/Android/FreeRDPCore/res/values/theme.xml +++ b/client/Android/Studio/freeRDPCore/src/main/res/values/theme.xml @@ -1,4 +1,4 @@ - +