[channel,rdpgfx] use dynamic WLog for server channel

This commit is contained in:
akallabeth
2024-01-29 12:18:30 +01:00
committed by Pascal Nowack
parent 4add7836fa
commit 01e415b801
2 changed files with 167 additions and 128 deletions

View File

@@ -108,14 +108,14 @@ static UINT rdpgfx_server_packet_send(RdpgfxServerContext* context, wStream* s)
if (!fs)
{
WLog_ERR(TAG, "Stream_New failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "Stream_New failed!");
error = CHANNEL_RC_NO_MEMORY;
goto out;
}
if (zgfx_compress_to_stream(context->priv->zgfx, fs, pSrcData, SrcSize, &flags) < 0)
{
WLog_ERR(TAG, "zgfx_compress_to_stream failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "zgfx_compress_to_stream failed!");
error = ERROR_INTERNAL_ERROR;
goto out;
}
@@ -123,15 +123,16 @@ static UINT rdpgfx_server_packet_send(RdpgfxServerContext* context, wStream* s)
if (!WTSVirtualChannelWrite(context->priv->rdpgfx_channel, (PCHAR)Stream_Buffer(fs),
Stream_GetPosition(fs), &written))
{
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelWrite failed!");
error = ERROR_INTERNAL_ERROR;
goto out;
}
if (written < Stream_GetPosition(fs))
{
WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written,
Stream_GetPosition(fs));
WLog_Print(context->priv->log, WLOG_WARN,
"Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written,
Stream_GetPosition(fs));
}
error = CHANNEL_RC_OK;
@@ -153,7 +154,7 @@ out:
*
* @return new stream
*/
static wStream* rdpgfx_server_single_packet_new(UINT16 cmdId, UINT32 dataLen)
static wStream* rdpgfx_server_single_packet_new(wLog* log, UINT16 cmdId, UINT32 dataLen)
{
UINT error;
wStream* s;
@@ -162,13 +163,13 @@ static wStream* rdpgfx_server_single_packet_new(UINT16 cmdId, UINT32 dataLen)
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
WLog_Print(log, WLOG_ERROR, "Stream_New failed!");
goto error;
}
if ((error = rdpgfx_server_packet_init_header(s, cmdId, pduLength)))
{
WLog_ERR(TAG, "Failed to init header with error %" PRIu32 "!", error);
WLog_Print(log, WLOG_ERROR, "Failed to init header with error %" PRIu32 "!", error);
goto error;
}
@@ -210,12 +211,12 @@ static UINT rdpgfx_send_caps_confirm_pdu(RdpgfxServerContext* context,
capsSet = capsConfirm->capsSet;
WINPR_ASSERT(capsSet);
s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_CAPSCONFIRM,
s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CAPSCONFIRM,
RDPGFX_CAPSET_BASE_SIZE + capsSet->length);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -249,17 +250,18 @@ static UINT rdpgfx_send_reset_graphics_pdu(RdpgfxServerContext* context,
/* Check monitorCount. This ensures total size within 340 bytes) */
if (pdu->monitorCount >= 16)
{
WLog_ERR(TAG, "Monitor count MUST be less than or equal to 16: %" PRIu32 "",
pdu->monitorCount);
WLog_Print(context->priv->log, WLOG_ERROR,
"Monitor count MUST be less than or equal to 16: %" PRIu32 "",
pdu->monitorCount);
return ERROR_INVALID_DATA;
}
s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_RESETGRAPHICS,
s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_RESETGRAPHICS,
RDPGFX_RESET_GRAPHICS_PDU_SIZE - RDPGFX_HEADER_SIZE);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -290,11 +292,12 @@ static UINT rdpgfx_send_reset_graphics_pdu(RdpgfxServerContext* context,
static UINT rdpgfx_send_evict_cache_entry_pdu(RdpgfxServerContext* context,
const RDPGFX_EVICT_CACHE_ENTRY_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_EVICTCACHEENTRY, 2);
wStream* s =
rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_EVICTCACHEENTRY, 2);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -314,12 +317,12 @@ static UINT rdpgfx_send_cache_import_reply_pdu(RdpgfxServerContext* context,
WINPR_ASSERT(pdu);
WLog_DBG(TAG, "reply with %" PRIu16 " entries", pdu->importedEntriesCount);
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_CACHEIMPORTREPLY,
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CACHEIMPORTREPLY,
2 + 2 * pdu->importedEntriesCount);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -355,7 +358,7 @@ rdpgfx_process_cache_import_offer_pdu(RdpgfxServerContext* context,
static UINT rdpgfx_send_create_surface_pdu(RdpgfxServerContext* context,
const RDPGFX_CREATE_SURFACE_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_CREATESURFACE, 7);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CREATESURFACE, 7);
WINPR_ASSERT(context);
WINPR_ASSERT(pdu);
@@ -364,7 +367,7 @@ static UINT rdpgfx_send_create_surface_pdu(RdpgfxServerContext* context,
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -383,11 +386,11 @@ static UINT rdpgfx_send_create_surface_pdu(RdpgfxServerContext* context,
static UINT rdpgfx_send_delete_surface_pdu(RdpgfxServerContext* context,
const RDPGFX_DELETE_SURFACE_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_DELETESURFACE, 2);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_DELETESURFACE, 2);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -420,12 +423,12 @@ static INLINE BOOL rdpgfx_write_end_frame_pdu(wStream* s, const RDPGFX_END_FRAME
static UINT rdpgfx_send_start_frame_pdu(RdpgfxServerContext* context,
const RDPGFX_START_FRAME_PDU* pdu)
{
wStream* s =
rdpgfx_server_single_packet_new(RDPGFX_CMDID_STARTFRAME, RDPGFX_START_FRAME_PDU_SIZE);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_STARTFRAME,
RDPGFX_START_FRAME_PDU_SIZE);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -440,11 +443,12 @@ static UINT rdpgfx_send_start_frame_pdu(RdpgfxServerContext* context,
*/
static UINT rdpgfx_send_end_frame_pdu(RdpgfxServerContext* context, const RDPGFX_END_FRAME_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_ENDFRAME, RDPGFX_END_FRAME_PDU_SIZE);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_ENDFRAME,
RDPGFX_END_FRAME_PDU_SIZE);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -535,7 +539,7 @@ static INLINE UINT16 rdpgfx_surface_command_cmdid(const RDPGFX_SURFACE_COMMAND*
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_write_h264_metablock(wStream* s, const RDPGFX_H264_METABLOCK* meta)
static UINT rdpgfx_write_h264_metablock(wLog* log, wStream* s, const RDPGFX_H264_METABLOCK* meta)
{
UINT32 index;
RECTANGLE_16* regionRect;
@@ -553,7 +557,8 @@ static UINT rdpgfx_write_h264_metablock(wStream* s, const RDPGFX_H264_METABLOCK*
if ((error = rdpgfx_write_rect16(s, regionRect)))
{
WLog_ERR(TAG, "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
WLog_Print(log, WLOG_ERROR, "rdpgfx_write_rect16 failed with error %" PRIu32 "!",
error);
return error;
}
}
@@ -576,13 +581,15 @@ static UINT rdpgfx_write_h264_metablock(wStream* s, const RDPGFX_H264_METABLOCK*
*
* @return 0 on success, otherwise a Win32 error code
*/
static INLINE UINT rdpgfx_write_h264_avc420(wStream* s, RDPGFX_AVC420_BITMAP_STREAM* havc420)
static INLINE UINT rdpgfx_write_h264_avc420(wLog* log, wStream* s,
RDPGFX_AVC420_BITMAP_STREAM* havc420)
{
UINT error = CHANNEL_RC_OK;
if ((error = rdpgfx_write_h264_metablock(s, &(havc420->meta))))
if ((error = rdpgfx_write_h264_metablock(log, s, &(havc420->meta))))
{
WLog_ERR(TAG, "rdpgfx_write_h264_metablock failed with error %" PRIu32 "!", error);
WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_metablock failed with error %" PRIu32 "!",
error);
return error;
}
@@ -600,7 +607,7 @@ static INLINE UINT rdpgfx_write_h264_avc420(wStream* s, RDPGFX_AVC420_BITMAP_STR
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_write_surface_command(wStream* s, const RDPGFX_SURFACE_COMMAND* cmd)
static UINT rdpgfx_write_surface_command(wLog* log, wStream* s, const RDPGFX_SURFACE_COMMAND* cmd)
{
UINT error = CHANNEL_RC_OK;
RDPGFX_AVC420_BITMAP_STREAM* havc420 = NULL;
@@ -620,7 +627,8 @@ static UINT rdpgfx_write_surface_command(wStream* s, const RDPGFX_SURFACE_COMMAN
break;
default:
WLog_ERR(TAG, "Format %s not supported!", FreeRDPGetColorFormatName(cmd->format));
WLog_Print(log, WLOG_ERROR, "Format %s not supported!",
FreeRDPGetColorFormatName(cmd->format));
return ERROR_INVALID_DATA;
}
@@ -655,11 +663,11 @@ static UINT rdpgfx_write_surface_command(wStream* s, const RDPGFX_SURFACE_COMMAN
if (cmd->codecId == RDPGFX_CODECID_AVC420)
{
havc420 = (RDPGFX_AVC420_BITMAP_STREAM*)cmd->extra;
error = rdpgfx_write_h264_avc420(s, havc420);
error = rdpgfx_write_h264_avc420(log, s, havc420);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpgfx_write_h264_avc420 failed!");
WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_avc420 failed!");
return error;
}
}
@@ -672,11 +680,11 @@ static UINT rdpgfx_write_surface_command(wStream* s, const RDPGFX_SURFACE_COMMAN
return ERROR_INTERNAL_ERROR;
Stream_Write_UINT32(s, havc444->cbAvc420EncodedBitstream1 | (havc444->LC << 30UL));
/* avc420EncodedBitstream1 */
error = rdpgfx_write_h264_avc420(s, havc420);
error = rdpgfx_write_h264_avc420(log, s, havc420);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpgfx_write_h264_avc420 failed!");
WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_avc420 failed!");
return error;
}
@@ -684,11 +692,11 @@ static UINT rdpgfx_write_surface_command(wStream* s, const RDPGFX_SURFACE_COMMAN
if (havc444->LC == 0)
{
havc420 = &(havc444->bitstream[1]);
error = rdpgfx_write_h264_avc420(s, havc420);
error = rdpgfx_write_h264_avc420(log, s, havc420);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpgfx_write_h264_avc420 failed!");
WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_avc420 failed!");
return error;
}
}
@@ -725,20 +733,20 @@ static UINT rdpgfx_send_surface_command(RdpgfxServerContext* context,
{
UINT error = CHANNEL_RC_OK;
wStream* s;
s = rdpgfx_server_single_packet_new(rdpgfx_surface_command_cmdid(cmd),
s = rdpgfx_server_single_packet_new(context->priv->log, rdpgfx_surface_command_cmdid(cmd),
rdpgfx_estimate_surface_command(cmd));
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
error = rdpgfx_write_surface_command(s, cmd);
error = rdpgfx_write_surface_command(context->priv->log, s, cmd);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpgfx_write_surface_command failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_write_surface_command failed!");
goto error;
}
@@ -781,7 +789,7 @@ static UINT rdpgfx_send_surface_frame_command(RdpgfxServerContext* context,
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -793,7 +801,8 @@ static UINT rdpgfx_send_surface_frame_command(RdpgfxServerContext* context,
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "Failed to init header with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"Failed to init header with error %" PRIu32 "!", error);
goto error;
}
@@ -809,15 +818,16 @@ static UINT rdpgfx_send_surface_frame_command(RdpgfxServerContext* context,
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "Failed to init header with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR, "Failed to init header with error %" PRIu32 "!",
error);
goto error;
}
error = rdpgfx_write_surface_command(s, cmd);
error = rdpgfx_write_surface_command(context->priv->log, s, cmd);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpgfx_write_surface_command failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_write_surface_command failed!");
goto error;
}
@@ -832,7 +842,8 @@ static UINT rdpgfx_send_surface_frame_command(RdpgfxServerContext* context,
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "Failed to init header with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"Failed to init header with error %" PRIu32 "!", error);
goto error;
}
@@ -855,11 +866,12 @@ error:
static UINT rdpgfx_send_delete_encoding_context_pdu(RdpgfxServerContext* context,
const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6);
wStream* s =
rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -879,12 +891,12 @@ static UINT rdpgfx_send_solid_fill_pdu(RdpgfxServerContext* context,
UINT error = CHANNEL_RC_OK;
UINT16 index;
RECTANGLE_16* fillRect;
wStream* s =
rdpgfx_server_single_packet_new(RDPGFX_CMDID_SOLIDFILL, 8 + 8 * pdu->fillRectCount);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_SOLIDFILL,
8 + 8 * pdu->fillRectCount);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -893,7 +905,8 @@ static UINT rdpgfx_send_solid_fill_pdu(RdpgfxServerContext* context,
/* fillPixel (4 bytes) */
if ((error = rdpgfx_write_color32(s, &(pdu->fillPixel))))
{
WLog_ERR(TAG, "rdpgfx_write_color32 failed with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_write_color32 failed with error %" PRIu32 "!", error);
goto error;
}
@@ -905,7 +918,8 @@ static UINT rdpgfx_send_solid_fill_pdu(RdpgfxServerContext* context,
if ((error = rdpgfx_write_rect16(s, fillRect)))
{
WLog_ERR(TAG, "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
goto error;
}
}
@@ -927,12 +941,12 @@ static UINT rdpgfx_send_surface_to_surface_pdu(RdpgfxServerContext* context,
UINT error = CHANNEL_RC_OK;
UINT16 index;
RDPGFX_POINT16* destPt;
wStream* s =
rdpgfx_server_single_packet_new(RDPGFX_CMDID_SURFACETOSURFACE, 14 + 4 * pdu->destPtsCount);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_SURFACETOSURFACE,
14 + 4 * pdu->destPtsCount);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -942,7 +956,8 @@ static UINT rdpgfx_send_surface_to_surface_pdu(RdpgfxServerContext* context,
/* rectSrc (8 bytes ) */
if ((error = rdpgfx_write_rect16(s, &(pdu->rectSrc))))
{
WLog_ERR(TAG, "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
goto error;
}
@@ -954,7 +969,8 @@ static UINT rdpgfx_send_surface_to_surface_pdu(RdpgfxServerContext* context,
if ((error = rdpgfx_write_point16(s, destPt)))
{
WLog_ERR(TAG, "rdpgfx_write_point16 failed with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_write_point16 failed with error %" PRIu32 "!", error);
goto error;
}
}
@@ -974,11 +990,12 @@ static UINT rdpgfx_send_surface_to_cache_pdu(RdpgfxServerContext* context,
const RDPGFX_SURFACE_TO_CACHE_PDU* pdu)
{
UINT error = CHANNEL_RC_OK;
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_SURFACETOCACHE, 20);
wStream* s =
rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_SURFACETOCACHE, 20);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -989,7 +1006,8 @@ static UINT rdpgfx_send_surface_to_cache_pdu(RdpgfxServerContext* context,
/* rectSrc (8 bytes ) */
if ((error = rdpgfx_write_rect16(s, &(pdu->rectSrc))))
{
WLog_ERR(TAG, "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_write_rect16 failed with error %" PRIu32 "!", error);
goto error;
}
@@ -1010,12 +1028,12 @@ static UINT rdpgfx_send_cache_to_surface_pdu(RdpgfxServerContext* context,
UINT error = CHANNEL_RC_OK;
UINT16 index;
RDPGFX_POINT16* destPt;
wStream* s =
rdpgfx_server_single_packet_new(RDPGFX_CMDID_CACHETOSURFACE, 6 + 4 * pdu->destPtsCount);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CACHETOSURFACE,
6 + 4 * pdu->destPtsCount);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -1029,7 +1047,8 @@ static UINT rdpgfx_send_cache_to_surface_pdu(RdpgfxServerContext* context,
if ((error = rdpgfx_write_point16(s, destPt)))
{
WLog_ERR(TAG, "rdpgfx_write_point16 failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_write_point16 failed with error %" PRIu32 "", error);
goto error;
}
}
@@ -1048,11 +1067,12 @@ error:
static UINT rdpgfx_send_map_surface_to_output_pdu(RdpgfxServerContext* context,
const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_MAPSURFACETOOUTPUT, 12);
wStream* s =
rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_MAPSURFACETOOUTPUT, 12);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -1071,11 +1091,12 @@ static UINT rdpgfx_send_map_surface_to_output_pdu(RdpgfxServerContext* context,
static UINT rdpgfx_send_map_surface_to_window_pdu(RdpgfxServerContext* context,
const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_MAPSURFACETOWINDOW, 18);
wStream* s =
rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_MAPSURFACETOWINDOW, 18);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -1090,11 +1111,12 @@ static UINT
rdpgfx_send_map_surface_to_scaled_window_pdu(RdpgfxServerContext* context,
const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW, 26);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log,
RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW, 26);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -1129,7 +1151,8 @@ static UINT rdpgfx_recv_frame_acknowledge_pdu(RdpgfxServerContext* context, wStr
IFCALLRET(context->FrameAcknowledge, error, context, &pdu);
if (error)
WLog_ERR(TAG, "context->FrameAcknowledge failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"context->FrameAcknowledge failed with error %" PRIu32 "", error);
}
return error;
@@ -1156,7 +1179,8 @@ static UINT rdpgfx_recv_cache_import_offer_pdu(RdpgfxServerContext* context, wSt
/* 2.2.2.16 RDPGFX_CACHE_IMPORT_OFFER_PDU */
if (pdu.cacheEntriesCount >= 5462)
{
WLog_ERR(TAG, "Invalid cacheEntriesCount: %" PRIu16 "", pdu.cacheEntriesCount);
WLog_Print(context->priv->log, WLOG_ERROR, "Invalid cacheEntriesCount: %" PRIu16 "",
pdu.cacheEntriesCount);
return ERROR_INVALID_DATA;
}
@@ -1175,7 +1199,8 @@ static UINT rdpgfx_recv_cache_import_offer_pdu(RdpgfxServerContext* context, wSt
IFCALLRET(context->CacheImportOffer, error, context, &pdu);
if (error)
WLog_ERR(TAG, "context->CacheImportOffer failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"context->CacheImportOffer failed with error %" PRIu32 "", error);
}
return error;
@@ -1235,7 +1260,8 @@ static UINT rdpgfx_recv_caps_advertise_pdu(RdpgfxServerContext* context, wStream
IFCALLRET(context->CapsAdvertise, error, context, &pdu);
if (error)
WLog_ERR(TAG, "context->CapsAdvertise failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"context->CapsAdvertise failed with error %" PRIu32 "", error);
fail:
free(capsSets);
@@ -1265,7 +1291,8 @@ static UINT rdpgfx_recv_qoe_frame_acknowledge_pdu(RdpgfxServerContext* context,
IFCALLRET(context->QoeFrameAcknowledge, error, context, &pdu);
if (error)
WLog_ERR(TAG, "context->QoeFrameAcknowledge failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"context->QoeFrameAcknowledge failed with error %" PRIu32 "", error);
}
return error;
@@ -1275,11 +1302,12 @@ static UINT
rdpgfx_send_map_surface_to_scaled_output_pdu(RdpgfxServerContext* context,
const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT, 20);
wStream* s = rdpgfx_server_single_packet_new(context->priv->log,
RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT, 20);
if (!s)
{
WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!");
return CHANNEL_RC_NO_MEMORY;
}
@@ -1306,7 +1334,8 @@ static UINT rdpgfx_server_receive_pdu(RdpgfxServerContext* context, wStream* s)
if ((error = rdpgfx_read_header(s, &header)))
{
WLog_ERR(TAG, "rdpgfx_read_header failed with error %" PRIu32 "!", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_read_header failed with error %" PRIu32 "!", error);
return error;
}
@@ -1319,37 +1348,37 @@ static UINT rdpgfx_server_receive_pdu(RdpgfxServerContext* context, wStream* s)
{
case RDPGFX_CMDID_FRAMEACKNOWLEDGE:
if ((error = rdpgfx_recv_frame_acknowledge_pdu(context, s)))
WLog_ERR(TAG,
"rdpgfx_recv_frame_acknowledge_pdu "
"failed with error %" PRIu32 "!",
error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_recv_frame_acknowledge_pdu "
"failed with error %" PRIu32 "!",
error);
break;
case RDPGFX_CMDID_CACHEIMPORTOFFER:
if ((error = rdpgfx_recv_cache_import_offer_pdu(context, s)))
WLog_ERR(TAG,
"rdpgfx_recv_cache_import_offer_pdu "
"failed with error %" PRIu32 "!",
error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_recv_cache_import_offer_pdu "
"failed with error %" PRIu32 "!",
error);
break;
case RDPGFX_CMDID_CAPSADVERTISE:
if ((error = rdpgfx_recv_caps_advertise_pdu(context, s)))
WLog_ERR(TAG,
"rdpgfx_recv_caps_advertise_pdu "
"failed with error %" PRIu32 "!",
error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_recv_caps_advertise_pdu "
"failed with error %" PRIu32 "!",
error);
break;
case RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE:
if ((error = rdpgfx_recv_qoe_frame_acknowledge_pdu(context, s)))
WLog_ERR(TAG,
"rdpgfx_recv_qoe_frame_acknowledge_pdu "
"failed with error %" PRIu32 "!",
error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_recv_qoe_frame_acknowledge_pdu "
"failed with error %" PRIu32 "!",
error);
break;
@@ -1360,8 +1389,9 @@ static UINT rdpgfx_server_receive_pdu(RdpgfxServerContext* context, wStream* s)
if (error)
{
WLog_ERR(TAG, "Error while parsing GFX cmdId: %s (0x%04" PRIX16 ")",
rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
WLog_Print(context->priv->log, WLOG_ERROR,
"Error while parsing GFX cmdId: %s (0x%04" PRIX16 ")",
rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
return error;
}
@@ -1369,8 +1399,9 @@ static UINT rdpgfx_server_receive_pdu(RdpgfxServerContext* context, wStream* s)
if (end != (beg + header.pduLength))
{
WLog_ERR(TAG, "Unexpected gfx pdu end: Actual: %" PRIuz ", Expected: %" PRIuz "", end,
(beg + header.pduLength));
WLog_Print(context->priv->log, WLOG_ERROR,
"Unexpected gfx pdu end: Actual: %" PRIuz ", Expected: %" PRIuz "", end,
(beg + header.pduLength));
Stream_SetPosition(s, (beg + header.pduLength));
}
@@ -1409,7 +1440,8 @@ static DWORD WINAPI rdpgfx_server_thread_func(LPVOID arg)
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"WaitForMultipleObjects failed with error %" PRIu32 "", error);
break;
}
@@ -1419,7 +1451,8 @@ static DWORD WINAPI rdpgfx_server_thread_func(LPVOID arg)
if ((error = rdpgfx_server_handle_messages(context)))
{
WLog_ERR(TAG, "rdpgfx_server_handle_messages failed with error %" PRIu32 "", error);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_server_handle_messages failed with error %" PRIu32 "", error);
break;
}
}
@@ -1450,7 +1483,7 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId,
(LPSTR*)&pSessionId, &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSQuerySessionInformationA failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "WTSQuerySessionInformationA failed!");
return FALSE;
}
@@ -1461,7 +1494,7 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
if (!priv->rdpgfx_channel)
{
WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelOpenEx failed!");
return FALSE;
}
@@ -1470,7 +1503,7 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
IFCALLRET(context->ChannelIdAssigned, status, context, channelId);
if (!status)
{
WLog_ERR(TAG, "context->ChannelIdAssigned failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "context->ChannelIdAssigned failed!");
goto fail;
}
@@ -1479,10 +1512,10 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
&BytesReturned) ||
(BytesReturned != sizeof(HANDLE)))
{
WLog_ERR(TAG,
"WTSVirtualChannelQuery failed "
"or invalid returned size(%" PRIu32 ")",
BytesReturned);
WLog_Print(context->priv->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed "
"or invalid returned size(%" PRIu32 ")",
BytesReturned);
if (buffer)
WTSFreeMemory(buffer);
@@ -1495,7 +1528,7 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
if (!(priv->zgfx = zgfx_context_new(TRUE)))
{
WLog_ERR(TAG, "Create zgfx context failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "Create zgfx context failed!");
goto fail;
}
@@ -1503,14 +1536,14 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
{
if (!(priv->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "CreateEvent failed!");
goto fail;
}
if (!(priv->thread =
CreateThread(NULL, 0, rdpgfx_server_thread_func, (void*)context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "CreateThread failed!");
goto fail;
}
}
@@ -1520,7 +1553,7 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context)
return TRUE;
}
WLog_ERR(TAG, "RDPGFX channel is already opened!");
WLog_Print(context->priv->log, WLOG_ERROR, "RDPGFX channel is already opened!");
return FALSE;
fail:
rdpgfx_server_close(context);
@@ -1572,8 +1605,9 @@ static BOOL rdpgfx_server_initialize(RdpgfxServerContext* context, BOOL external
if (context->priv->isOpened)
{
WLog_WARN(TAG, "Application error: RDPEGFX channel already initialized, "
"calling in this state is not possible!");
WLog_Print(context->priv->log, WLOG_WARN,
"Application error: RDPEGFX channel already initialized, "
"calling in this state is not possible!");
return FALSE;
}
@@ -1587,7 +1621,7 @@ RdpgfxServerContext* rdpgfx_server_context_new(HANDLE vcm)
if (!context)
{
WLog_ERR(TAG, "calloc failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "calloc failed!");
return NULL;
}
@@ -1627,12 +1661,16 @@ RdpgfxServerContext* rdpgfx_server_context_new(HANDLE vcm)
goto fail;
}
priv->log = WLog_Get(TAG);
if (!priv->log)
goto fail;
/* Create shared input stream */
priv->input_stream = Stream_New(NULL, 4);
if (!priv->input_stream)
{
WLog_ERR(TAG, "Stream_New failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "Stream_New failed!");
goto fail;
}
@@ -1698,7 +1736,7 @@ UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context)
if (GetLastError() == ERROR_NO_DATA)
return ERROR_NO_DATA;
WLog_ERR(TAG, "WTSVirtualChannelQuery failed");
WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelQuery failed");
return ERROR_INTERNAL_ERROR;
}
@@ -1716,7 +1754,7 @@ UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context)
if (GetLastError() == ERROR_NO_DATA)
return ERROR_NO_DATA;
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelRead failed!");
return ERROR_INTERNAL_ERROR;
}
@@ -1725,14 +1763,14 @@ UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context)
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
if (WTSVirtualChannelRead(priv->rdpgfx_channel, 0, (PCHAR)Stream_Buffer(s),
Stream_Capacity(s), &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelRead failed!");
return ERROR_INTERNAL_ERROR;
}
@@ -1743,10 +1781,10 @@ UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context)
{
if ((ret = rdpgfx_server_receive_pdu(context, s)))
{
WLog_ERR(TAG,
"rdpgfx_server_receive_pdu "
"failed with error %" PRIu32 "!",
ret);
WLog_Print(context->priv->log, WLOG_ERROR,
"rdpgfx_server_receive_pdu "
"failed with error %" PRIu32 "!",
ret);
return ret;
}
}

View File

@@ -35,6 +35,7 @@ struct s_rdpgfx_server_private
wStream* input_stream;
BOOL isOpened;
BOOL isReady;
wLog* log;
};
#endif /* FREERDP_CHANNEL_RDPGFX_SERVER_MAIN_H */