summaryrefslogtreecommitdiff
path: root/source3/aparser/parser.h
blob: 52d1b839414850946746134397ce1309ae570470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <ctype.h>
#include "../include/byteorder.h"

#define PARSE_SCALARS (1<<0)
#define PARSE_BUFFERS (1<<1)

#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif

#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
/* Maximum PDU fragment size. */
#define MAX_PDU_FRAG_LEN 0x1630

#define DEBUG(lvl, str) printf str;

#define MARSHALL 0
#define UNMARSHALL 1

#define MARSHALLING(ps) (!(ps)->io)
#define UNMARSHALLING(ps) ((ps)->io)

typedef int BOOL;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned short wchar;
typedef unsigned uint32;

#define False 0
#define True 1

typedef char pstring[1024];

/* zero a structure given a pointer to the structure */
#define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }

#define MAX_UNISTRLEN 256
#define MAX_STRINGLEN 256
#define MAX_BUFFERLEN 512

typedef struct _prs_struct 
{
	BOOL io; /* parsing in or out of data stream */
	/* 
	 * If the (incoming) data is big-endian. On output we are
	 * always little-endian.
	 */ 
	BOOL bigendian_data;
	BOOL is_dynamic; /* Do we own this memory or not ? */
	uint32 data_offset; /* Current working offset into data. */
	uint32 buffer_size; /* Current size of the buffer. */
	uint32 grow_size; /* size requested via prs_grow() calls */
	char *data_p; /* The buffer itself. */
} prs_struct;


char *prs_mem_get(prs_struct *ps, uint32 extra_size);
BOOL prs_init(prs_struct *ps, uint32 size, BOOL io);
void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name);
BOOL prs_align(prs_struct *ps, int align);
void print_asc(int level, unsigned char *buf,int len);
BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout);
void dump_data(int level,char *buf1,int len);
BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size);
BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned flags);
BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned flags);
BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flags);
BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags);
BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len, unsigned flags);