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
19 #define LDNS_PARSE_SKIP_SPACE "\f\n\r\v"
20 #define LDNS_PARSE_NORMAL " \f\n\r\t\v"
21 #define LDNS_PARSE_NO_NL " \t"
22 #define LDNS_MAX_LINELEN 10230
23 #define LDNS_MAX_KEYWORDLEN 32
29 * Contains some low-level parsing functions, mostly used in the _frm_str
30 * family of functions.
34 * different type of directives in zone files
35 * We now deal with $TTL, $ORIGIN and $INCLUDE.
36 * The latter is not implemented in ldns (yet)
38 enum sldns_enum_directive
44 typedef enum sldns_enum_directive sldns_directive;
47 * returns a token/char from the stream F.
48 * This function deals with ( and ) in the stream,
49 * and ignores them when encountered
50 * \param[in] *f the file to read from
51 * \param[out] *token the read token is put here
52 * \param[in] *delim chars at which the parsing should stop
53 * \param[in] *limit how much to read. If 0 the builtin maximum is used
54 * \return 0 on error of EOF of the stream F. Otherwise return the length of what is read
56 ssize_t sldns_fget_token(FILE *f, char *token, const char *delim, size_t limit);
59 * returns a token/char from the stream F.
60 * This function deals with ( and ) in the stream,
61 * and ignores when it finds them.
62 * \param[in] *f the file to read from
63 * \param[out] *token the token is put here
64 * \param[in] *delim chars at which the parsing should stop
65 * \param[in] *limit how much to read. If 0 use builtin maximum
66 * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
67 * \return 0 on error of EOF of F otherwise return the length of what is read
69 ssize_t sldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr);
72 * returns a token/char from the buffer b.
73 * This function deals with ( and ) in the buffer,
74 * and ignores when it finds them.
75 * \param[in] *b the buffer to read from
76 * \param[out] *token the token is put here
77 * \param[in] *delim chars at which the parsing should stop
78 * \param[in] *limit how much to read. If 0 the builtin maximum is used
79 * \param[in] *par if you pass nonNULL, set to 0 on first call, the parenthesis
80 * state is stored in it, for use on next call. User must check it is back
81 * to zero after last bget in string (for parse error). If you pass NULL,
82 * the entire parenthesized string is read in.
83 * \param[in] skipw string with whitespace to skip before the start of the
84 * token, like " ", or " \t", or NULL for none.
85 * \returns 0 on error of EOF of b. Otherwise return the length of what is read
87 ssize_t sldns_bget_token_par(struct sldns_buffer *b, char *token, const char *delim, size_t limit, int* par, const char* skipw);
90 * returns a token/char from the buffer b.
91 * This function deals with ( and ) in the buffer,
92 * and ignores when it finds them.
93 * \param[in] *b the buffer to read from
94 * \param[out] *token the token is put here
95 * \param[in] *delim chars at which the parsing should stop
96 * \param[in] *limit how much to read. If 0 the builtin maximum is used
97 * \returns 0 on error of EOF of b. Otherwise return the length of what is read
99 ssize_t sldns_bget_token(struct sldns_buffer *b, char *token, const char *delim, size_t limit);
102 * searches for keyword and delim in a file. Gives everything back
103 * after the keyword + k_del until we hit d_del
104 * \param[in] f file pointer to read from
105 * \param[in] keyword keyword to look for
106 * \param[in] k_del keyword delimeter
107 * \param[out] data the data found
108 * \param[in] d_del the data delimeter
109 * \param[in] data_limit maximum size the the data buffer
110 * \return the number of character read
112 ssize_t sldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
115 * searches for keyword and delim. Gives everything back
116 * after the keyword + k_del until we hit d_del
117 * \param[in] f file pointer to read from
118 * \param[in] keyword keyword to look for
119 * \param[in] k_del keyword delimeter
120 * \param[out] data the data found
121 * \param[in] d_del the data delimeter
122 * \param[in] data_limit maximum size the the data buffer
123 * \param[in] line_nr pointer to an integer containing the current line number (for
125 * \return the number of character read
127 ssize_t sldns_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);
130 * searches for keyword and delim in a buffer. Gives everything back
131 * after the keyword + k_del until we hit d_del
132 * \param[in] b buffer pointer to read from
133 * \param[in] keyword keyword to look for
134 * \param[in] k_del keyword delimeter
135 * \param[out] data the data found
136 * \param[in] d_del the data delimeter
137 * \param[in] data_limit maximum size the the data buffer
138 * \return the number of character read
140 ssize_t sldns_bget_keyword_data(struct sldns_buffer *b, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
143 * returns the next character from a buffer. Advances the position pointer with 1.
144 * When end of buffer is reached returns EOF. This is the buffer's equivalent
146 * \param[in] *buffer buffer to read from
147 * \return EOF on failure otherwise return the character
149 int sldns_bgetc(struct sldns_buffer *buffer);
152 * skips all of the characters in the given string in the buffer, moving
153 * the position to the first character that is not in *s.
154 * \param[in] *buffer buffer to use
155 * \param[in] *s characters to skip
158 void sldns_bskipcs(struct sldns_buffer *buffer, const char *s);
161 * skips all of the characters in the given string in the fp, moving
162 * the position to the first character that is not in *s.
163 * \param[in] *fp file to use
164 * \param[in] *s characters to skip
167 void sldns_fskipcs(FILE *fp, const char *s);
171 * skips all of the characters in the given string in the fp, moving
172 * the position to the first character that is not in *s.
173 * \param[in] *fp file to use
174 * \param[in] *s characters to skip
175 * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
178 void sldns_fskipcs_l(FILE *fp, const char *s, int *line_nr);
184 #endif /* LDNS_PARSE_H */