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