Initial vendor import of ldns-1.6.4 into contrib.
[dragonfly.git] / contrib / ldns / ldns / parse.h
1 /*
2  * parse.h 
3  *
4  * a Net::DNS like library for C
5  * LibDNS Team @ NLnet Labs
6  * (c) NLnet Labs, 2005-2006
7  * See the file LICENSE for the license
8  */
9
10 #ifndef LDNS_PARSE_H
11 #define LDNS_PARSE_H
12
13 #include <ldns/common.h>
14 #include <ldns/buffer.h>
15
16 #define LDNS_PARSE_SKIP_SPACE           "\f\n\r\v"
17 #define LDNS_PARSE_NORMAL               " \f\n\r\t\v"
18 #define LDNS_PARSE_NO_NL                " \t"
19 #define LDNS_MAX_LINELEN                10230
20 #define LDNS_MAX_KEYWORDLEN             32
21
22
23 /**
24  * \file
25  *
26  * Contains some low-level parsing functions, mostly used in the _frm_str
27  * family of functions.
28  */
29  
30 /**
31  * different type of directives in zone files
32  * We now deal with $TTL, $ORIGIN and $INCLUDE.
33  * The latter is not implemented in ldns (yet)
34  */
35 enum ldns_enum_directive
36 {
37         LDNS_DIR_TTL,
38         LDNS_DIR_ORIGIN,
39         LDNS_DIR_INCLUDE
40 };
41 typedef enum ldns_enum_directive ldns_directive;
42
43 /** 
44  * returns a token/char from the stream F.
45  * This function deals with ( and ) in the stream,
46  * and ignores them when encountered
47  * \param[in] *f the file to read from
48  * \param[out] *token the read token is put here
49  * \param[in] *delim chars at which the parsing should stop
50  * \param[in] *limit how much to read. If 0 the builtin maximum is used
51  * \return 0 on error of EOF of the stream F.  Otherwise return the length of what is read
52  */
53 ssize_t ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit);
54
55 /** 
56  * returns a token/char from the stream F.
57  * This function deals with ( and ) in the stream,
58  * and ignores when it finds them.
59  * \param[in] *f the file to read from
60  * \param[out] *token the token is put here
61  * \param[in] *delim chars at which the parsing should stop
62  * \param[in] *limit how much to read. If 0 use builtin maximum
63  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
64  * \return 0 on error of EOF of F otherwise return the length of what is read
65  */
66 ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr);
67
68 /**
69  * returns a token/char from the buffer b.
70  * This function deals with ( and ) in the buffer,
71  * and ignores when it finds them.
72  * \param[in] *b the buffer to read from
73  * \param[out] *token the token is put here
74  * \param[in] *delim chars at which the parsing should stop
75  * \param[in] *limit how much to read. If 0 the builtin maximum is used
76  * \returns 0 on error of EOF of b. Otherwise return the length of what is read
77  */
78 ssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit);
79
80 /*
81  * searches for keyword and delim in a file. Gives everything back
82  * after the keyword + k_del until we hit d_del
83  * \param[in] f file pointer to read from
84  * \param[in] keyword keyword to look for
85  * \param[in] k_del keyword delimeter 
86  * \param[out] data the data found 
87  * \param[in] d_del the data delimeter
88  * \param[in] data_limit maximum size the the data buffer
89  * \return the number of character read
90  */
91 ssize_t ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
92
93 /*
94  * searches for keyword and delim. Gives everything back
95  * after the keyword + k_del until we hit d_del
96  * \param[in] f file pointer to read from
97  * \param[in] keyword keyword to look for
98  * \param[in] k_del keyword delimeter 
99  * \param[out] data the data found 
100  * \param[in] d_del the data delimeter
101  * \param[in] data_limit maximum size the the data buffer
102  * \param[in] line_nr pointer to an integer containing the current line number (for
103 debugging purposes)
104  * \return the number of character read
105  */
106 ssize_t ldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit, int *line_nr);
107
108 /*
109  * searches for keyword and delim in a buffer. Gives everything back
110  * after the keyword + k_del until we hit d_del
111  * \param[in] b buffer pointer to read from
112  * \param[in] keyword keyword to look for
113  * \param[in] k_del keyword delimeter 
114  * \param[out] data the data found 
115  * \param[in] d_del the data delimeter
116  * \param[in] data_limit maximum size the the data buffer
117  * \return the number of character read
118  */
119 ssize_t ldns_bget_keyword_data(ldns_buffer *b, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
120
121 /**
122  * returns the next character from a buffer. Advances the position pointer with 1.
123  * When end of buffer is reached returns EOF. This is the buffer's equivalent
124  * for getc().
125  * \param[in] *buffer buffer to read from
126  * \return EOF on failure otherwise return the character
127  */
128 int ldns_bgetc(ldns_buffer *buffer);
129
130 /**
131  * skips all of the characters in the given string in the buffer, moving
132  * the position to the first character that is not in *s.
133  * \param[in] *buffer buffer to use
134  * \param[in] *s characters to skip
135  * \return void
136  */
137 void ldns_bskipcs(ldns_buffer *buffer, const char *s);
138
139 /**
140  * skips all of the characters in the given string in the fp, moving
141  * the position to the first character that is not in *s.
142  * \param[in] *fp file to use
143  * \param[in] *s characters to skip
144  * \return void
145  */
146 void ldns_fskipcs(FILE *fp, const char *s);
147
148
149 /**
150  * skips all of the characters in the given string in the fp, moving
151  * the position to the first character that is not in *s.
152  * \param[in] *fp file to use
153  * \param[in] *s characters to skip
154  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
155  * \return void
156  */
157 void ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr);
158
159 #endif /* LDNS_PARSE_H */