Home | History | Annotate | Line # | Download | only in sldns
      1      1.1  christos /*
      2      1.1  christos  * parse.h
      3      1.1  christos  *
      4      1.1  christos  * a Net::DNS like library for C
      5      1.1  christos  * LibDNS Team @ NLnet Labs
      6      1.1  christos  * (c) NLnet Labs, 2005-2006
      7      1.1  christos  * See the file LICENSE for the license
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos #ifndef LDNS_PARSE_H
     11      1.1  christos #define LDNS_PARSE_H
     12      1.1  christos 
     13      1.1  christos struct sldns_buffer;
     14      1.1  christos 
     15      1.1  christos #ifdef __cplusplus
     16      1.1  christos extern "C" {
     17      1.1  christos #endif
     18      1.1  christos 
     19      1.1  christos #define LDNS_PARSE_SKIP_SPACE		"\f\n\r\v"
     20      1.1  christos #define LDNS_PARSE_NORMAL		" \f\n\r\t\v"
     21      1.1  christos #define LDNS_PARSE_NO_NL		" \t"
     22      1.1  christos #define LDNS_MAX_LINELEN		10230
     23      1.1  christos #define LDNS_MAX_KEYWORDLEN		32
     24      1.1  christos 
     25      1.1  christos 
     26      1.1  christos /**
     27      1.1  christos  * \file
     28      1.1  christos  *
     29      1.1  christos  * Contains some low-level parsing functions, mostly used in the _frm_str
     30      1.1  christos  * family of functions.
     31      1.1  christos  */
     32      1.1  christos 
     33      1.1  christos /**
     34      1.1  christos  * different type of directives in zone files
     35      1.1  christos  * We now deal with $TTL, $ORIGIN and $INCLUDE.
     36      1.1  christos  * The latter is not implemented in ldns (yet)
     37      1.1  christos  */
     38      1.1  christos enum sldns_enum_directive
     39      1.1  christos {
     40      1.1  christos 	LDNS_DIR_TTL,
     41      1.1  christos 	LDNS_DIR_ORIGIN,
     42      1.1  christos 	LDNS_DIR_INCLUDE
     43      1.1  christos };
     44      1.1  christos typedef enum sldns_enum_directive sldns_directive;
     45      1.1  christos 
     46      1.1  christos /**
     47      1.1  christos  * returns a token/char from the stream F.
     48      1.1  christos  * This function deals with ( and ) in the stream,
     49      1.1  christos  * and ignores them when encountered
     50      1.1  christos  * \param[in] *f the file to read from
     51      1.1  christos  * \param[out] *token the read token is put here
     52      1.1  christos  * \param[in] *delim chars at which the parsing should stop
     53      1.1  christos  * \param[in] *limit how much to read. If 0 the builtin maximum is used
     54      1.1  christos  * \return 0 on error of EOF of the stream F.  Otherwise return the length of what is read
     55      1.1  christos  */
     56      1.1  christos ssize_t sldns_fget_token(FILE *f, char *token, const char *delim, size_t limit);
     57      1.1  christos 
     58      1.1  christos /**
     59      1.1  christos  * returns a token/char from the stream F.
     60      1.1  christos  * This function deals with ( and ) in the stream,
     61      1.1  christos  * and ignores when it finds them.
     62      1.1  christos  * \param[in] *f the file to read from
     63      1.1  christos  * \param[out] *token the token is put here
     64      1.1  christos  * \param[in] *delim chars at which the parsing should stop
     65      1.1  christos  * \param[in] *limit how much to read. If 0 use builtin maximum
     66      1.1  christos  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
     67      1.1  christos  * \return 0 on error of EOF of F otherwise return the length of what is read
     68      1.1  christos  */
     69      1.1  christos ssize_t sldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr);
     70      1.1  christos 
     71      1.1  christos /**
     72      1.1  christos  * returns a token/char from the buffer b.
     73      1.1  christos  * This function deals with ( and ) in the buffer,
     74      1.1  christos  * and ignores when it finds them.
     75      1.1  christos  * \param[in] *b the buffer to read from
     76      1.1  christos  * \param[out] *token the token is put here
     77      1.1  christos  * \param[in] *delim chars at which the parsing should stop
     78      1.1  christos  * \param[in] *limit how much to read. If 0 the builtin maximum is used
     79      1.1  christos  * \param[in] *par if you pass nonNULL, set to 0 on first call, the parenthesis
     80      1.1  christos  * state is stored in it, for use on next call.  User must check it is back
     81      1.1  christos  * to zero after last bget in string (for parse error).  If you pass NULL,
     82      1.1  christos  * the entire parenthesized string is read in.
     83      1.1  christos  * \param[in] skipw string with whitespace to skip before the start of the
     84      1.1  christos  * token, like " ", or " \t", or NULL for none.
     85      1.1  christos  * \returns 0 on error of EOF of b. Otherwise return the length of what is read
     86      1.1  christos  */
     87      1.1  christos ssize_t sldns_bget_token_par(struct sldns_buffer *b, char *token, const char *delim, size_t limit, int* par, const char* skipw);
     88      1.1  christos 
     89      1.1  christos /**
     90      1.1  christos  * returns a token/char from the buffer b.
     91      1.1  christos  * This function deals with ( and ) in the buffer,
     92      1.1  christos  * and ignores when it finds them.
     93      1.1  christos  * \param[in] *b the buffer to read from
     94      1.1  christos  * \param[out] *token the token is put here
     95      1.1  christos  * \param[in] *delim chars at which the parsing should stop
     96      1.1  christos  * \param[in] *limit how much to read. If 0 the builtin maximum is used
     97      1.1  christos  * \returns 0 on error of EOF of b. Otherwise return the length of what is read
     98      1.1  christos  */
     99      1.1  christos ssize_t sldns_bget_token(struct sldns_buffer *b, char *token, const char *delim, size_t limit);
    100      1.1  christos 
    101      1.1  christos /*
    102      1.1  christos  * searches for keyword and delim in a file. Gives everything back
    103      1.1  christos  * after the keyword + k_del until we hit d_del
    104      1.1  christos  * \param[in] f file pointer to read from
    105      1.1  christos  * \param[in] keyword keyword to look for
    106  1.1.1.2  christos  * \param[in] k_del keyword delimiter
    107      1.1  christos  * \param[out] data the data found
    108  1.1.1.2  christos  * \param[in] d_del the data delimiter
    109  1.1.1.4  christos  * \param[in] data_limit maximum size the data buffer
    110      1.1  christos  * \return the number of character read
    111      1.1  christos  */
    112      1.1  christos 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);
    113      1.1  christos 
    114      1.1  christos /*
    115      1.1  christos  * searches for keyword and delim. Gives everything back
    116      1.1  christos  * after the keyword + k_del until we hit d_del
    117      1.1  christos  * \param[in] f file pointer to read from
    118      1.1  christos  * \param[in] keyword keyword to look for
    119  1.1.1.2  christos  * \param[in] k_del keyword delimiter
    120      1.1  christos  * \param[out] data the data found
    121  1.1.1.2  christos  * \param[in] d_del the data delimiter
    122  1.1.1.4  christos  * \param[in] data_limit maximum size the data buffer
    123      1.1  christos  * \param[in] line_nr pointer to an integer containing the current line number (for
    124      1.1  christos debugging purposes)
    125      1.1  christos  * \return the number of character read
    126      1.1  christos  */
    127      1.1  christos 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);
    128      1.1  christos 
    129      1.1  christos /*
    130      1.1  christos  * searches for keyword and delim in a buffer. Gives everything back
    131      1.1  christos  * after the keyword + k_del until we hit d_del
    132      1.1  christos  * \param[in] b buffer pointer to read from
    133      1.1  christos  * \param[in] keyword keyword to look for
    134  1.1.1.2  christos  * \param[in] k_del keyword delimiter
    135      1.1  christos  * \param[out] data the data found
    136  1.1.1.2  christos  * \param[in] d_del the data delimiter
    137  1.1.1.4  christos  * \param[in] data_limit maximum size the data buffer
    138      1.1  christos  * \return the number of character read
    139      1.1  christos  */
    140      1.1  christos 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);
    141      1.1  christos 
    142      1.1  christos /**
    143      1.1  christos  * returns the next character from a buffer. Advances the position pointer with 1.
    144      1.1  christos  * When end of buffer is reached returns EOF. This is the buffer's equivalent
    145      1.1  christos  * for getc().
    146      1.1  christos  * \param[in] *buffer buffer to read from
    147      1.1  christos  * \return EOF on failure otherwise return the character
    148      1.1  christos  */
    149      1.1  christos int sldns_bgetc(struct sldns_buffer *buffer);
    150      1.1  christos 
    151      1.1  christos /**
    152      1.1  christos  * skips all of the characters in the given string in the buffer, moving
    153      1.1  christos  * the position to the first character that is not in *s.
    154      1.1  christos  * \param[in] *buffer buffer to use
    155      1.1  christos  * \param[in] *s characters to skip
    156      1.1  christos  */
    157      1.1  christos void sldns_bskipcs(struct sldns_buffer *buffer, const char *s);
    158      1.1  christos 
    159      1.1  christos /**
    160      1.1  christos  * skips all of the characters in the given string in the fp, moving
    161      1.1  christos  * the position to the first character that is not in *s.
    162      1.1  christos  * \param[in] *fp file to use
    163      1.1  christos  * \param[in] *s characters to skip
    164      1.1  christos  */
    165      1.1  christos void sldns_fskipcs(FILE *fp, const char *s);
    166      1.1  christos 
    167      1.1  christos 
    168      1.1  christos /**
    169      1.1  christos  * skips all of the characters in the given string in the fp, moving
    170      1.1  christos  * the position to the first character that is not in *s.
    171      1.1  christos  * \param[in] *fp file to use
    172      1.1  christos  * \param[in] *s characters to skip
    173      1.1  christos  * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
    174      1.1  christos  */
    175      1.1  christos void sldns_fskipcs_l(FILE *fp, const char *s, int *line_nr);
    176      1.1  christos 
    177      1.1  christos #ifdef __cplusplus
    178      1.1  christos }
    179      1.1  christos #endif
    180      1.1  christos 
    181      1.1  christos #endif /* LDNS_PARSE_H */
    182