FreeRDP
Loading...
Searching...
No Matches
rdpgfx_common.c
1
22#include <freerdp/config.h>
23
24#include <winpr/crt.h>
25#include <winpr/assert.h>
26#include <winpr/stream.h>
27
28#include "rdpgfx_common.h"
29
35UINT rdpgfx_read_header(wLog* log, wStream* s, RDPGFX_HEADER* header)
36{
37 WINPR_ASSERT(s);
38 WINPR_ASSERT(header);
39
40 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
41 return CHANNEL_RC_NO_MEMORY;
42
43 Stream_Read_UINT16(s, header->cmdId); /* cmdId (2 bytes) */
44 Stream_Read_UINT16(s, header->flags); /* flags (2 bytes) */
45 Stream_Read_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
46
47 if (header->pduLength < 8)
48 {
49 WLog_Print(log, WLOG_ERROR, "header->pduLength %u less than 8!", header->pduLength);
50 return ERROR_INVALID_DATA;
51 }
52 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, (header->pduLength - 8)))
53 return ERROR_INVALID_DATA;
54
55 return CHANNEL_RC_OK;
56}
57
63UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header)
64{
65 WINPR_ASSERT(s);
66 WINPR_ASSERT(header);
67
68 if (!Stream_EnsureRemainingCapacity(s, 8))
69 return CHANNEL_RC_NO_MEMORY;
70 Stream_Write_UINT16(s, header->cmdId); /* cmdId (2 bytes) */
71 Stream_Write_UINT16(s, header->flags); /* flags (2 bytes) */
72 Stream_Write_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
73 return CHANNEL_RC_OK;
74}
75
81UINT rdpgfx_read_point16(wLog* log, wStream* s, RDPGFX_POINT16* pt16)
82{
83 WINPR_ASSERT(s);
84 WINPR_ASSERT(pt16);
85
86 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
87 return ERROR_INVALID_DATA;
88
89 Stream_Read_UINT16(s, pt16->x); /* x (2 bytes) */
90 Stream_Read_UINT16(s, pt16->y); /* y (2 bytes) */
91 return CHANNEL_RC_OK;
92}
93
99UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16)
100{
101 WINPR_ASSERT(s);
102 WINPR_ASSERT(point16);
103
104 if (!Stream_EnsureRemainingCapacity(s, 4))
105 return CHANNEL_RC_NO_MEMORY;
106
107 Stream_Write_UINT16(s, point16->x); /* x (2 bytes) */
108 Stream_Write_UINT16(s, point16->y); /* y (2 bytes) */
109 return CHANNEL_RC_OK;
110}
111
117UINT rdpgfx_read_rect16(wLog* log, wStream* s, RECTANGLE_16* rect16)
118{
119 WINPR_ASSERT(s);
120 WINPR_ASSERT(rect16);
121
122 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
123 return ERROR_INVALID_DATA;
124
125 Stream_Read_UINT16(s, rect16->left); /* left (2 bytes) */
126 Stream_Read_UINT16(s, rect16->top); /* top (2 bytes) */
127 Stream_Read_UINT16(s, rect16->right); /* right (2 bytes) */
128 Stream_Read_UINT16(s, rect16->bottom); /* bottom (2 bytes) */
129 if (rect16->left >= rect16->right)
130 return ERROR_INVALID_DATA;
131 if (rect16->top >= rect16->bottom)
132 return ERROR_INVALID_DATA;
133 return CHANNEL_RC_OK;
134}
135
141UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16)
142{
143 WINPR_ASSERT(s);
144 WINPR_ASSERT(rect16);
145
146 if (!Stream_EnsureRemainingCapacity(s, 8))
147 return CHANNEL_RC_NO_MEMORY;
148
149 Stream_Write_UINT16(s, rect16->left); /* left (2 bytes) */
150 Stream_Write_UINT16(s, rect16->top); /* top (2 bytes) */
151 Stream_Write_UINT16(s, rect16->right); /* right (2 bytes) */
152 Stream_Write_UINT16(s, rect16->bottom); /* bottom (2 bytes) */
153 return CHANNEL_RC_OK;
154}
155
161UINT rdpgfx_read_color32(wLog* log, wStream* s, RDPGFX_COLOR32* color32)
162{
163 WINPR_ASSERT(s);
164 WINPR_ASSERT(color32);
165
166 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
167 return ERROR_INVALID_DATA;
168
169 Stream_Read_UINT8(s, color32->B); /* B (1 byte) */
170 Stream_Read_UINT8(s, color32->G); /* G (1 byte) */
171 Stream_Read_UINT8(s, color32->R); /* R (1 byte) */
172 Stream_Read_UINT8(s, color32->XA); /* XA (1 byte) */
173 return CHANNEL_RC_OK;
174}
175
181UINT rdpgfx_write_color32(wStream* s, const RDPGFX_COLOR32* color32)
182{
183 WINPR_ASSERT(s);
184 WINPR_ASSERT(color32);
185
186 if (!Stream_EnsureRemainingCapacity(s, 4))
187 return CHANNEL_RC_NO_MEMORY;
188
189 Stream_Write_UINT8(s, color32->B); /* B (1 byte) */
190 Stream_Write_UINT8(s, color32->G); /* G (1 byte) */
191 Stream_Write_UINT8(s, color32->R); /* R (1 byte) */
192 Stream_Write_UINT8(s, color32->XA); /* XA (1 byte) */
193 return CHANNEL_RC_OK;
194}