22 #include <freerdp/config.h>
24 #include <winpr/crt.h>
25 #include <winpr/assert.h>
26 #include <winpr/stream.h>
27 #include <freerdp/channels/log.h>
29 #define TAG CHANNELS_TAG("rdpgfx.common")
31 #include "rdpgfx_common.h"
43 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
44 return CHANNEL_RC_NO_MEMORY;
46 Stream_Read_UINT16(s, header->cmdId);
47 Stream_Read_UINT16(s, header->flags);
48 Stream_Read_UINT32(s, header->pduLength);
50 if (header->pduLength < 8)
52 WLog_ERR(TAG,
"header->pduLength %u less than 8!", header->pduLength);
53 return ERROR_INVALID_DATA;
55 if (!Stream_CheckAndLogRequiredLength(TAG, s, (header->pduLength - 8)))
56 return ERROR_INVALID_DATA;
71 if (!Stream_EnsureRemainingCapacity(s, 8))
72 return CHANNEL_RC_NO_MEMORY;
73 Stream_Write_UINT16(s, header->cmdId);
74 Stream_Write_UINT16(s, header->flags);
75 Stream_Write_UINT32(s, header->pduLength);
89 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
90 return ERROR_INVALID_DATA;
92 Stream_Read_UINT16(s, pt16->x);
93 Stream_Read_UINT16(s, pt16->y);
105 WINPR_ASSERT(point16);
107 if (!Stream_EnsureRemainingCapacity(s, 4))
108 return CHANNEL_RC_NO_MEMORY;
110 Stream_Write_UINT16(s, point16->x);
111 Stream_Write_UINT16(s, point16->y);
112 return CHANNEL_RC_OK;
123 WINPR_ASSERT(rect16);
125 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
126 return ERROR_INVALID_DATA;
128 Stream_Read_UINT16(s, rect16->left);
129 Stream_Read_UINT16(s, rect16->top);
130 Stream_Read_UINT16(s, rect16->right);
131 Stream_Read_UINT16(s, rect16->bottom);
132 if (rect16->left >= rect16->right)
133 return ERROR_INVALID_DATA;
134 if (rect16->top >= rect16->bottom)
135 return ERROR_INVALID_DATA;
136 return CHANNEL_RC_OK;
147 WINPR_ASSERT(rect16);
149 if (!Stream_EnsureRemainingCapacity(s, 8))
150 return CHANNEL_RC_NO_MEMORY;
152 Stream_Write_UINT16(s, rect16->left);
153 Stream_Write_UINT16(s, rect16->top);
154 Stream_Write_UINT16(s, rect16->right);
155 Stream_Write_UINT16(s, rect16->bottom);
156 return CHANNEL_RC_OK;
167 WINPR_ASSERT(color32);
169 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
170 return ERROR_INVALID_DATA;
172 Stream_Read_UINT8(s, color32->B);
173 Stream_Read_UINT8(s, color32->G);
174 Stream_Read_UINT8(s, color32->R);
175 Stream_Read_UINT8(s, color32->XA);
176 return CHANNEL_RC_OK;
187 WINPR_ASSERT(color32);
189 if (!Stream_EnsureRemainingCapacity(s, 4))
190 return CHANNEL_RC_NO_MEMORY;
192 Stream_Write_UINT8(s, color32->B);
193 Stream_Write_UINT8(s, color32->G);
194 Stream_Write_UINT8(s, color32->R);
195 Stream_Write_UINT8(s, color32->XA);
196 return CHANNEL_RC_OK;