Make sure we don't clobber the stack when response consists of the empty
[Samba/gebeck_regimport.git] / source3 / include / genparser.h
blobf28cd78249dad7b05922b806ae45bc23611931c5
1 /*
2 Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef _GENPARSER_H
20 #define _GENPARSER_H
22 /* these macros are needed for genstruct auto-parsers */
23 #ifndef GENSTRUCT
24 #define GENSTRUCT
25 #define _LEN(x)
26 #define _NULLTERM
27 #endif
30 automatic marshalling/unmarshalling system for C structures
33 /* flag to mark a fixed size array as actually being null terminated */
34 #define FLAG_NULLTERM 1
35 #define FLAG_ALWAYS 2
37 struct enum_struct {
38 const char *name;
39 unsigned value;
42 /* intermediate dumps are stored in one of these */
43 struct parse_string {
44 unsigned allocated;
45 unsigned length;
46 char *s;
49 typedef int (*gen_dump_fn)(TALLOC_CTX *, struct parse_string *, const char *ptr, unsigned indent);
50 typedef int (*gen_parse_fn)(TALLOC_CTX *, char *ptr, const char *str);
52 /* genstruct.pl generates arrays of these */
53 struct parse_struct {
54 const char *name;
55 unsigned ptr_count;
56 unsigned size;
57 unsigned offset;
58 unsigned array_len;
59 const char *dynamic_len;
60 unsigned flags;
61 gen_dump_fn dump_fn;
62 gen_parse_fn parse_fn;
65 #define DUMP_PARSE_DECL(type) \
66 int gen_dump_ ## type(TALLOC_CTX *, struct parse_string *, const char *, unsigned); \
67 int gen_parse_ ## type(TALLOC_CTX *, char *, const char *);
69 DUMP_PARSE_DECL(char)
70 DUMP_PARSE_DECL(int)
71 DUMP_PARSE_DECL(unsigned)
72 DUMP_PARSE_DECL(double)
73 DUMP_PARSE_DECL(float)
75 #define gen_dump_unsigned_char gen_dump_char
76 #define gen_parse_unsigned_char gen_parse_char
78 #endif /* _GENPARSER_H */