FreeRDP
ndr.h
1 
20 #ifndef CHANNELS_RDPEAR_NDR_H_
21 #define CHANNELS_RDPEAR_NDR_H_
22 
23 #include <winpr/stream.h>
24 #include <freerdp/api.h>
25 
26 #define NDR_PTR_NULL (0UL)
27 
28 #define NDR_SIMPLE_TYPE_DECL(LOWER, UPPER) \
29  BOOL ndr_read_##LOWER(NdrContext* context, wStream* s, UPPER* v); \
30  BOOL ndr_read_##LOWER##_(NdrContext* context, wStream* s, const void* hints, void* v); \
31  BOOL ndr_write_##LOWER(NdrContext* context, wStream* s, UPPER v); \
32  BOOL ndr_write_##LOWER##_(NdrContext* context, wStream* s, const void* hints, const void* v); \
33  extern const NdrMessageDescr ndr_##LOWER##_descr_s; \
34  NdrMessageType ndr_##LOWER##_descr(void)
35 
36 #define NDR_ARRAY_OF_TYPE_DECL(TYPE, UPPERTYPE) \
37  BOOL ndr_read_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, void* v); \
38  BOOL ndr_write_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, \
39  const void* v); \
40  void ndr_destroy_##TYPE##Array(NdrContext* context, const void* hints, void* obj); \
41  extern const NdrMessageDescr ndr_##TYPE##Array_descr_s; \
42  NdrMessageType ndr_##TYPE##Array_descr(void); \
43  \
44  BOOL ndr_read_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \
45  void* v); \
46  BOOL ndr_write_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \
47  const void* v); \
48  extern const NdrMessageDescr ndr_##TYPE##VaryingArray_descr_s; \
49  NdrMessageType ndr_##TYPE##VaryingArray_descr(void)
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 
56  typedef struct NdrContext_s NdrContext;
57 
58  typedef UINT32 ndr_refid;
59 
60  typedef BOOL (*NDR_READER_FN)(NdrContext* context, wStream* s, const void* hints, void* target);
61  typedef BOOL (*NDR_WRITER_FN)(NdrContext* context, wStream* s, const void* hints,
62  const void* obj);
63  typedef void (*NDR_DESTROY_FN)(NdrContext* context, const void* hints, void* obj);
64  typedef void (*NDR_DUMP_FN)(wLog* logger, UINT32 lvl, size_t indentLevel, const void* obj);
65 
67  typedef enum
68  {
69  NDR_ARITY_SIMPLE,
70  NDR_ARITY_ARRAYOF,
71  NDR_ARITY_VARYING_ARRAYOF,
72  } NdrTypeArity;
73 
75  typedef struct
76  {
77  NdrTypeArity arity;
78  size_t itemSize;
79  NDR_READER_FN readFn;
80  NDR_WRITER_FN writeFn;
81  NDR_DESTROY_FN destroyFn;
82  NDR_DUMP_FN dumpFn;
84 
85  typedef const NdrMessageDescr* NdrMessageType;
86 
88  typedef enum
89  {
90  NDR_NOT_POINTER,
91  NDR_POINTER_NON_NULL,
92  NDR_POINTER
93  } NdrPointerType;
94 
96  typedef struct
97  {
98  const char* name;
99  size_t structOffset;
100  NdrPointerType pointerType;
101  ssize_t hintsField;
102  NdrMessageType typeDescr;
103  } NdrFieldStruct;
104 
106  typedef struct
107  {
108  const char* name;
109  size_t nfields;
110  const NdrFieldStruct* fields;
111  } NdrStructDescr;
112 
114  typedef struct
115  {
116  ndr_refid ptrId;
117  const char* name;
118  void* hints;
119  void* target;
120  NdrMessageType msg;
122 
123  void ndr_context_free(NdrContext* context);
124 
125  static INLINE void ndr_context_destroy(NdrContext** pcontext)
126  {
127  WINPR_ASSERT(pcontext);
128  ndr_context_free(*pcontext);
129  *pcontext = NULL;
130  }
131 
132  WINPR_ATTR_MALLOC(ndr_context_free, 1)
133  NdrContext* ndr_context_new(BOOL bigEndianDrep, BYTE version);
134 
135  void ndr_context_reset(NdrContext* context);
136 
137  WINPR_ATTR_MALLOC(ndr_context_free, 1)
138  NdrContext* ndr_context_copy(const NdrContext* src);
139 
140  WINPR_ATTR_MALLOC(ndr_context_free, 1)
141  NdrContext* ndr_read_header(wStream* s);
142 
143  BOOL ndr_write_header(NdrContext* context, wStream* s);
144 
145  NDR_SIMPLE_TYPE_DECL(uint8, UINT8);
146  NDR_SIMPLE_TYPE_DECL(uint16, UINT16);
147  NDR_SIMPLE_TYPE_DECL(uint32, UINT32);
148  NDR_SIMPLE_TYPE_DECL(uint64, UINT64);
149 
150  NDR_ARRAY_OF_TYPE_DECL(uint8, BYTE);
151  NDR_ARRAY_OF_TYPE_DECL(uint16, UINT16);
152 
153  BOOL ndr_skip_bytes(NdrContext* context, wStream* s, size_t nbytes);
154  BOOL ndr_read_align(NdrContext* context, wStream* s, size_t sz);
155  BOOL ndr_write_align(NdrContext* context, wStream* s, size_t sz);
156 
157  BOOL ndr_read_pickle(NdrContext* context, wStream* s);
158  BOOL ndr_write_pickle(NdrContext* context, wStream* s);
159 
160  BOOL ndr_read_constructed(NdrContext* context, wStream* s, wStream* target);
161  BOOL ndr_write_constructed(NdrContext* context, wStream* s, wStream* payload);
162 
163  BOOL ndr_start_constructed(NdrContext* context, wStream* s);
164  BOOL ndr_end_constructed(NdrContext* context, wStream* s);
165 
166  BOOL ndr_read_wchar(NdrContext* context, wStream* s, WCHAR* ptr);
167 
169  typedef struct
170  {
171  UINT32 length;
172  UINT32 maxLength;
174 
175  BOOL ndr_read_uconformant_varying_array(NdrContext* context, wStream* s,
176  const NdrVaryingArrayHints* hints,
177  NdrMessageType itemType, void* ptarget);
178  BOOL ndr_write_uconformant_varying_array(NdrContext* context, wStream* s,
179  const NdrVaryingArrayHints* hints,
180  NdrMessageType itemType, const void* src);
181 
183  typedef struct
184  {
185  UINT32 count;
186  } NdrArrayHints;
187 
188  BOOL ndr_read_uconformant_array(NdrContext* context, wStream* s, const NdrArrayHints* hints,
189  NdrMessageType itemType, void* vtarget);
190  BOOL ndr_write_uconformant_array(NdrContext* context, wStream* s, UINT32 len,
191  NdrMessageType itemType, const BYTE* ptr);
192 
193  BOOL ndr_struct_read_fromDescr(NdrContext* context, wStream* s, const NdrStructDescr* descr,
194  void* target);
195  BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStructDescr* descr,
196  const void* src);
197  void ndr_struct_dump_fromDescr(wLog* logger, UINT32 lvl, size_t identLevel,
198  const NdrStructDescr* descr, const void* obj);
199  void ndr_struct_destroy(NdrContext* context, const NdrStructDescr* descr, void* pptr);
200 
201  ndr_refid ndr_pointer_refid(const void* ptr);
202  BOOL ndr_read_refpointer(NdrContext* context, wStream* s, UINT32* refId);
203  BOOL ndr_context_allocatePtr(NdrContext* context, const void* ptr, ndr_refid* prefId,
204  BOOL* pnewPtr);
205 
206  BOOL ndr_read_pointedMessageEx(NdrContext* context, wStream* s, ndr_refid ptrId,
207  NdrMessageType descr, void* hints, void** target);
208 
209  BOOL ndr_push_deferreds(NdrContext* context, NdrDeferredEntry* deferreds, size_t ndeferred);
210  BOOL ndr_treat_deferred_read(NdrContext* context, wStream* s);
211  BOOL ndr_treat_deferred_write(NdrContext* context, wStream* s);
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif /* CHANNELS_RDPEAR_NDR_H_ */
hints for a conformant array
Definition: ndr.h:184
a deferred pointer
Definition: ndr.h:115
descriptor of a field in a structure
Definition: ndr.h:97
message descriptor
Definition: ndr.h:76
structure descriptor
Definition: ndr.h:107
hints for a varying conformant array
Definition: ndr.h:170