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
13 #include <ldns/common.h>
14 #include <ldns/buffer.h>
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
26 * Contains some low-level parsing functions, mostly used in the _frm_str
27 * family of functions.
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)
35 enum ldns_enum_directive
41 typedef enum ldns_enum_directive ldns_directive;
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
53 ssize_t ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit);
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
66 ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr);
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
78 ssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit);
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
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);
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
104 * \return the number of character read
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);
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
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);
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
125 * \param[in] *buffer buffer to read from
126 * \return EOF on failure otherwise return the character
128 int ldns_bgetc(ldns_buffer *buffer);
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
137 void ldns_bskipcs(ldns_buffer *buffer, const char *s);
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
146 void ldns_fskipcs(FILE *fp, const char *s);
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)
157 void ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr);
159 #endif /* LDNS_PARSE_H */