23#include <winpr/stream.h>
48#define WINPR_NDR_PTR_NULL (0UL)
62#define WINPR_NDR_SIMPLE_TYPE_DECL(PREFIX, LOWER, UPPER) \
63 WINPR_ATTR_NODISCARD \
64 WINPR_API BOOL PREFIX##_decoder_read_##LOWER(WinPrNdrDecoder* context, wStream* s, UPPER* v); \
65 WINPR_ATTR_NODISCARD \
66 WINPR_API BOOL PREFIX##_decoder_read_##LOWER##_(WinPrNdrDecoder* context, wStream* s, \
67 const void* hints, void* v); \
68 WINPR_ATTR_NODISCARD \
69 WINPR_API BOOL PREFIX##_encoder_write_##LOWER(WinPrNdrEncoder* context, wStream* s, UPPER v); \
70 WINPR_ATTR_NODISCARD \
71 WINPR_API BOOL PREFIX##_encoder_write_##LOWER##_(WinPrNdrEncoder* context, wStream* s, \
72 const void* hints, const void* v); \
73 WINPR_API extern const WinPrNdrMessageDescr PREFIX##_##LOWER##_descr_s; \
74 WINPR_ATTR_NODISCARD \
75 WINPR_API WinPrNdrMessageType PREFIX##_##LOWER##_descr(void)
91#define WINPR_NDR_ARRAY_OF_TYPE_DECL(PREFIX, TYPE, UPPERTYPE) \
92 WINPR_ATTR_NODISCARD \
93 WINPR_API BOOL PREFIX##_decoder_read_##TYPE##Array(WinPrNdrDecoder* context, wStream* s, \
94 const void* hints, void* v); \
95 WINPR_ATTR_NODISCARD \
96 WINPR_API BOOL PREFIX##_encoder_write_##TYPE##Array(WinPrNdrEncoder* context, wStream* s, \
97 const void* hints, const void* v); \
98 WINPR_API void PREFIX##_destroy_##TYPE##Array(const void* hints, void* obj); \
99 WINPR_API extern const WinPrNdrMessageDescr PREFIX##_##TYPE##Array_descr_s; \
100 WINPR_ATTR_NODISCARD \
101 WINPR_API WinPrNdrMessageType PREFIX##_##TYPE##Array_descr(void); \
103 WINPR_ATTR_NODISCARD \
104 WINPR_API BOOL PREFIX##_decoder_read_##TYPE##VaryingArray( \
105 WinPrNdrDecoder* context, wStream* s, const void* hints, void* v); \
106 WINPR_ATTR_NODISCARD \
107 WINPR_API BOOL PREFIX##_encoder_write_##TYPE##VaryingArray( \
108 WinPrNdrEncoder* context, wStream* s, const void* hints, const void* v); \
109 WINPR_API extern const WinPrNdrMessageDescr PREFIX##_##TYPE##VaryingArray_descr_s; \
110 WINPR_ATTR_NODISCARD \
111 WINPR_API WinPrNdrMessageType PREFIX##_##TYPE##VaryingArray_descr(void)
120#define WINPR_NDR_STRUCT_MESSAGE_DEFINE(PREFIX, CTYPE) \
121 static BOOL PREFIX##_read(WinPrNdrDecoder* context, wStream* s, const void* hints, void* obj) \
123 WINPR_UNUSED(hints); \
124 return winpr_ndr_decoder_read_fromDescr(context, s, &PREFIX##_struct, obj); \
126 static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
129 WINPR_UNUSED(hints); \
130 return winpr_ndr_encoder_write_fromDescr(context, s, &PREFIX##_struct, obj); \
132 static void PREFIX##_destroy(const void* hints, void* obj) \
134 WINPR_UNUSED(hints); \
135 winpr_ndr_struct_destroy(&PREFIX##_struct, obj); \
137 static void PREFIX##_dump(wLog* logger, UINT32 lvl, size_t indentLevel, const void* obj) \
139 winpr_ndr_struct_dump_fromDescr(logger, lvl, indentLevel, &PREFIX##_struct, obj); \
141 static const WinPrNdrMessageDescr PREFIX##_descr_s = { WINPR_NDR_ARITY_SIMPLE, sizeof(CTYPE), \
142 PREFIX##_read, PREFIX##_write, \
143 PREFIX##_destroy, PREFIX##_dump }
151#define WINPR_NDR_ARRAY_MESSAGE_DEFINE(PREFIX, ITEMPREFIX, CTYPE) \
152 static BOOL PREFIX##_read(WinPrNdrDecoder* context, wStream* s, const void* hints, void* obj) \
154 return winpr_ndr_decoder_read_uconformant_array(context, s, hints, &ITEMPREFIX##_descr_s, \
157 static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
160 WINPR_ASSERT(hints); \
161 const WinPrNdrArrayHints* ahints = hints; \
162 return winpr_ndr_encoder_write_uconformant_array(context, s, ahints->count, \
163 &ITEMPREFIX##_descr_s, obj); \
165 static void PREFIX##_destroy(const void* hints, void* obj) \
167 WINPR_ASSERT(hints); \
168 const WinPrNdrArrayHints* ahints = hints; \
169 CTYPE* items = obj; \
170 for (UINT32 i = 0; i < ahints->count; i++) \
171 ITEMPREFIX##_destroy(nullptr, &items[i]); \
173 static const WinPrNdrMessageDescr PREFIX##_descr_s = { \
174 WINPR_NDR_ARITY_ARRAYOF, sizeof(CTYPE), PREFIX##_read, \
175 PREFIX##_write, PREFIX##_destroy, nullptr \
186#define WINPR_NDR_UNION_MESSAGE_DEFINE(PREFIX, CTYPE) \
187 static BOOL PREFIX##_read(WinPrNdrDecoder* context, wStream* s, const void* hints, void* obj) \
189 WINPR_ASSERT(hints); \
190 return winpr_ndr_decoder_read_union(context, s, &PREFIX##_union, \
191 winpr_ndr_union_switch_value(&PREFIX##_union, hints), \
194 static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
197 WINPR_ASSERT(hints); \
198 return winpr_ndr_encoder_write_union(context, s, &PREFIX##_union, \
199 winpr_ndr_union_switch_value(&PREFIX##_union, hints), \
202 static void PREFIX##_destroy(const void* hints, void* obj) \
205 winpr_ndr_union_destroy(&PREFIX##_union, \
206 winpr_ndr_union_switch_value(&PREFIX##_union, hints), obj); \
208 static const WinPrNdrMessageDescr PREFIX##_descr_s = { WINPR_NDR_ARITY_SIMPLE, sizeof(CTYPE), \
209 PREFIX##_read, PREFIX##_write, \
210 PREFIX##_destroy, nullptr }
220 typedef struct WinPrNdrDecoder_s WinPrNdrDecoder;
225 typedef struct WinPrNdrEncoder_s WinPrNdrEncoder;
407 WINPR_ASSERT(pcontext);
485 const
void* data,
size_t sz);
604 UINT32 switchValue,
const void* src);
659 WINPR_ASSERT(pcontext);
768 void* hints,
void** target);
1010 WINPR_ATTR_NODISCARD
1045 WINPR_ATTR_NODISCARD
1047 const
void* switchField);
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_allocatePtr(WinPrNdrEncoder *context, const void *ptr, winpr_ndr_refid *prefId, BOOL *pnewPtr)
allocates the referent id of an embedded pointer
BOOL(* WINPR_NDR_READER_FN)(WinPrNdrDecoder *context, wStream *s, const void *hints, void *target)
reads a message
WinPrNdrFieldStruct field
WINPR_API void winpr_ndr_decoder_free(WinPrNdrDecoder *context)
frees a decoder
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_end_object(WinPrNdrEncoder *context, wStream *s)
ends the serialized object started with winpr_ndr_encoder_start_object()
UINT32 winpr_ndr_refid
a referent id, the wire value of a pointer (WINPR_NDR_PTR_NULL for a null pointer)
WinPrNdrPointerType
pointer or not and if null is accepted
@ WINPR_NDR_POINTER_NON_NULL
WinPrNdrPointerType pointerType
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_wchar(WinPrNdrEncoder *context, wStream *s, const WCHAR *ptr)
writes a WCHAR stored in UTF-16LE, aligned on 2 bytes
WINPR_API void * winpr_ndr_pointer_ref(void *ptr)
takes a reference on a referent
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_string_varying_descr(void)
the message type of winpr_ndr_string_varying_descr_s
WINPR_ATTR_NODISCARD WINPR_API winpr_ndr_refid winpr_ndr_pointer_refid(const void *ptr)
a referent id built from the value of a pointer
void(* WINPR_NDR_DUMP_FN)(wLog *logger, UINT32 lvl, size_t indentLevel, const void *obj)
dumps a message in the logs
WINPR_API void winpr_ndr_struct_dump_fromDescr(wLog *logger, UINT32 lvl, size_t identLevel, const WinPrNdrStructDescr *descr, const void *obj)
dumps a structure in the logs from its descriptor
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_header(WinPrNdrEncoder *context, wStream *s)
writes the common type header ([MS-RPCE] 2.2.6.1): version, endianness, header length and filler
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_array(WinPrNdrDecoder *context, wStream *s, const WinPrNdrArrayHints *hints, WinPrNdrMessageType itemType, void *vtarget)
reads a conformant array: its count and the items
static INLINE void winpr_ndr_decoder_destroy(WinPrNdrDecoder **pcontext)
frees a decoder and resets the pointer
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_skip_bytes(WinPrNdrDecoder *context, wStream *s, size_t nbytes)
skips bytes
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointedMessageEx(WinPrNdrDecoder *context, wStream *s, winpr_ndr_refid ptrId, WinPrNdrMessageType descr, void *hints, void **target)
reads the referent of a unique pointer
const WinPrNdrFieldStruct * fields
void(* WINPR_NDR_DESTROY_FN)(const void *hints, void *obj)
releases the content of a message, not the message storage itself
BOOL(* WINPR_NDR_WRITER_FN)(WinPrNdrEncoder *context, wStream *s, const void *hints, const void *obj)
writes a message
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_fromDescr(WinPrNdrDecoder *context, wStream *s, const WinPrNdrStructDescr *descr, void *target)
reads a structure from its descriptor
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_data(WinPrNdrEncoder *context, wStream *s, const void *data, size_t sz)
writes raw bytes, without alignment
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_varying_array(WinPrNdrDecoder *context, wStream *s, const WinPrNdrVaryingArrayHints *hints, WinPrNdrMessageType itemType, void *ptarget)
reads a conformant varying array: its maximum count, offset, actual count and the items
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_wstring_varying_descr(void)
the message type of winpr_ndr_wstring_varying_descr_s
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_treat_deferreds(WinPrNdrEncoder *context, wStream *s)
writes the pending deferred referents
#define WINPR_NDR_SIMPLE_TYPE_DECL(PREFIX, LOWER, UPPER)
declares the functions and the message descriptor of a simple type
WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new(BOOL bigEndianDrep, BYTE version)
creates a decoder
WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_new(BOOL bigEndianDrep, BYTE version)
creates an encoder
static INLINE void winpr_ndr_encoder_destroy(WinPrNdrEncoder **pcontext)
frees an encoder and resets the pointer
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_union(WinPrNdrDecoder *context, wStream *s, const WinPrNdrUnionDescr *descr, UINT32 switchValue, void *target)
reads a union, its discriminant must be switchValue
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_string_conformant_descr(void)
the message type of winpr_ndr_string_conformant_descr_s
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_toplevel_refid(WinPrNdrEncoder *context, wStream *s)
writes a new referent id for a non-null top-level pointer
WINPR_NDR_DESTROY_FN destroyFn
WINPR_ATTR_NODISCARD WINPR_API size_t winpr_ndr_pointer_size(const void *ptr)
the size of a referent, as allocated by winpr_ndr_pointer_new()
const WinPrNdrMessageDescr * WinPrNdrMessageType
a message type, a pointer on its descriptor
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_wchar(WinPrNdrDecoder *context, wStream *s, WCHAR *ptr)
reads a WCHAR, aligned on 2 bytes
WinPrNdrTypeArity
arity of a message
@ WINPR_NDR_ARITY_VARYING_ARRAYOF
@ WINPR_NDR_ARITY_ARRAYOF
@ WINPR_NDR_ARITY_SELF_ALLOCATED
WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_varying_descr_s
[string] char*: a conformant varying string of char, read in a char* allocated with winpr_ndr_pointer...
WINPR_API void winpr_ndr_encoder_free(WinPrNdrEncoder *context)
frees an encoder
WINPR_API const WinPrNdrMessageDescr winpr_ndr_wstring_varying_descr_s
[string] wchar_t*: a conformant varying string of WCHAR, read in a WCHAR* allocated with winpr_ndr_po...
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_refpointer(WinPrNdrDecoder *context, wStream *s, UINT32 *refId)
reads a referent id
WINPR_API void winpr_ndr_decoder_bytes_read(WinPrNdrDecoder *context, size_t len)
accounts for bytes read directly from the stream, for the alignments
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_align(WinPrNdrDecoder *context, wStream *s, size_t sz)
skips the padding to align the current object offset
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_varying_array(WinPrNdrEncoder *context, wStream *s, const WinPrNdrVaryingArrayHints *hints, WinPrNdrMessageType itemType, const void *src)
writes a conformant varying array: its maximum count, offset 0, actual count and the items
WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_from_decoder(const WinPrNdrDecoder *src)
creates an encoder with the same endianness and version as a decoder, to answer the message it decode...
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_union(WinPrNdrEncoder *context, wStream *s, const WinPrNdrUnionDescr *descr, UINT32 switchValue, const void *src)
writes the discriminant and the arm of a union
WINPR_API void * winpr_ndr_pointer_new(WinPrNdrMessageType descr, const void *hints, size_t size)
allocates a referent
WINPR_API void winpr_ndr_encoder_bytes_written(WinPrNdrEncoder *context, size_t len)
accounts for bytes written directly in the stream, for the alignments
WINPR_API void winpr_ndr_pointer_release(void *ptr)
releases a referent
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_object(WinPrNdrDecoder *context, wStream *s, wStream *object)
reads the private header of a serialized object ([MS-RPCE] 2.2.6 type serialization version 1)
const WinPrNdrUnionArm * arms
const WinPrNdrUnionArm * defaultArm
#define WINPR_NDR_ARRAY_OF_TYPE_DECL(PREFIX, TYPE, UPPERTYPE)
declares the functions and the message descriptors of the arrays of a simple type
WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new_fromStream(wStream *s)
reads the common type header ([MS-RPCE] 2.2.6.1) and creates a decoder for its version and endianness
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_wchar_descr(void)
the message type of winpr_ndr_wchar_descr_s
WINPR_ATTR_NODISCARD WINPR_API UINT32 winpr_ndr_union_switch_value(const WinPrNdrUnionDescr *descr, const void *switchField)
the value of the [switch_is()] field of a union
WINPR_API const WinPrNdrMessageDescr winpr_ndr_wchar_descr_s
a WCHAR, stored in UTF-16LE in memory
WINPR_NDR_WRITER_FN writeFn
WINPR_API void winpr_ndr_struct_destroy(const WinPrNdrStructDescr *descr, void *pptr)
releases the content of a structure from its descriptor
WINPR_NDR_READER_FN readFn
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_fromDescr(WinPrNdrEncoder *context, wStream *s, const WinPrNdrStructDescr *descr, const void *src)
writes a structure from its descriptor
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_push_deferreds(WinPrNdrDecoder *context, WinPrNdrDeferredEntry *deferreds, size_t ndeferred)
adds deferred pointers, read by the next winpr_ndr_decoder_treat_deferreds()
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_array(WinPrNdrEncoder *context, wStream *s, UINT32 len, WinPrNdrMessageType itemType, const BYTE *ptr)
writes a conformant array: its count and the items
WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_conformant_descr_s
conformant string of char, read in a char* allocated with winpr_ndr_pointer_new()
WINPR_API void winpr_ndr_union_destroy(const WinPrNdrUnionDescr *descr, UINT32 switchValue, void *obj)
releases the content of the arm switchValue of a union
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_align(WinPrNdrEncoder *context, wStream *s, size_t sz)
writes zero padding to align the current object offset
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointer_ex(WinPrNdrDecoder *context, wStream *s, const char *name, WinPrNdrMessageType descr, void *hints, void **target)
reads a full pointer ([ptr])
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_start_object(WinPrNdrEncoder *context, wStream *s)
starts a serialized object ([MS-RPCE] 2.2.6 type serialization version 1)
WinPrNdrMessageType typeDescr
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_treat_deferreds(WinPrNdrDecoder *context, wStream *s)
reads the pending deferred referents
hints for a conformant array
a deferred pointer, a referent to read after the current construct
descriptor of a field in a structure
an arm of a non-encapsulated union
a non-encapsulated union ([switch_type()])
hints for a conformant varying array