7 #include "../include/byteorder.h"
9 #define PARSE_SCALARS (1<<0)
10 #define PARSE_BUFFERS (1<<1)
13 #define MIN(a,b) ((a)<(b)?(a):(b))
17 #define MAX(a,b) ((a)>(b)?(a):(b))
20 #define DEBUG(lvl, str) printf str;
21 #define DEBUGADD(lvl, str) printf str;
26 #define MARSHALLING(ps) (!(ps)->io)
27 #define UNMARSHALLING(ps) ((ps)->io)
30 typedef unsigned char uint8
;
31 typedef unsigned char uchar
;
32 typedef unsigned short uint16
;
33 typedef unsigned short wchar
;
34 typedef unsigned uint32
;
37 /* a null terminated unicode string */
38 typedef uint16 ZUSTRING
;
42 #define PSTRING_LEN 1024
43 #define FSTRING_LEN 256
45 typedef char pstring
[PSTRING_LEN
];
46 typedef char fstring
[FSTRING_LEN
];
54 /* zero a structure given a pointer to the structure */
55 #define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
57 #define MAX_UNISTRLEN 256
58 #define MAX_STRINGLEN 256
59 #define MAX_BUFFERLEN 512
61 typedef struct _io_struct
63 BOOL io
; /* parsing in or out of data stream */
65 * If the (incoming) data is big-endian. On output we are
66 * always little-endian.
69 BOOL is_dynamic
; /* Do we own this memory or not ? */
70 BOOL autoalign
; /* should we auto-align all elements? */
71 uint32 data_offset
; /* Current working offset into data. */
72 uint32 buffer_size
; /* Current size of the buffer. */
73 uint32 grow_size
; /* size requested via io_grow() calls */
74 char *data_p
; /* The buffer itself. */
78 char *io_mem_get(io_struct
*ps
, uint32 extra_size
);
79 BOOL
io_init(io_struct
*ps
, uint32 size
, BOOL io
);
80 void io_debug(io_struct
*ps
, int depth
, char *desc
, char *fn_name
);
81 BOOL
io_align(io_struct
*ps
, int align
);
82 BOOL
io_align4(io_struct
*ps
, int align
);
83 BOOL
io_align2(io_struct
*ps
, int align
);
84 BOOL
io_read(io_struct
*ps
, int fd
, size_t len
, int timeout
);
85 void dump_data(int level
,char *buf1
,int len
);
86 BOOL
io_alloc(char *name
, io_struct
*ps
, void **ptr
, unsigned size
);
87 BOOL
io_uint32(char *name
, io_struct
*ps
, int depth
, uint32
*data32
, unsigned flags
);
88 BOOL
io_uint16(char *name
, io_struct
*ps
, int depth
, uint16
*data16
, unsigned flags
);
89 BOOL
io_uint8(char *name
, io_struct
*ps
, int depth
, uint8
*data8
, unsigned flags
);
90 BOOL
io_pointer(char *desc
, io_struct
*ps
, int depth
, void **p
, unsigned flags
);
91 BOOL
io_SMBSTR(char *name
, io_struct
*ps
, int depth
, char **str
, unsigned flags
);
92 BOOL
io_io_struct(char *name
, io_struct
*ps
, int depth
, io_struct
*io
, unsigned flags
);
93 BOOL
io_wstring(char *name
, io_struct
*ps
, int depth
, uint16
*data16s
, int len
, unsigned flags
);
94 BOOL
io_uint8s_fixed(char *name
, io_struct
*ps
, int depth
, uint8
*data8s
, int len
, unsigned flags
);
95 BOOL
io_uint8s(char *name
, io_struct
*ps
, int depth
, uint8
**data8s
, int len
, unsigned flags
);
97 char *tab_depth(int depth
);
98 void *Realloc(void *p
,size_t size
);
99 void dump_data(int level
,char *buf1
,int len
);
100 void print_asc(int level
, uchar
const *buf
, int len
);
101 BOOL
io_ZUSTRING(char *name
, io_struct
*ps
, int depth
, uint16
**ustr
, unsigned flags
);
102 size_t strlen_w(void *src
);