1238104Sdes/* 2238104Sdes * parse.h 3238104Sdes * 4238104Sdes * a Net::DNS like library for C 5238104Sdes * LibDNS Team @ NLnet Labs 6238104Sdes * (c) NLnet Labs, 2005-2006 7238104Sdes * See the file LICENSE for the license 8238104Sdes */ 9238104Sdes 10238104Sdes#ifndef LDNS_PARSE_H 11238104Sdes#define LDNS_PARSE_H 12238104Sdes 13238104Sdes#include <ldns/common.h> 14238104Sdes#include <ldns/buffer.h> 15238104Sdes 16238104Sdes#ifdef __cplusplus 17238104Sdesextern "C" { 18238104Sdes#endif 19238104Sdes 20238104Sdes#define LDNS_PARSE_SKIP_SPACE "\f\n\r\v" 21238104Sdes#define LDNS_PARSE_NORMAL " \f\n\r\t\v" 22238104Sdes#define LDNS_PARSE_NO_NL " \t" 23238104Sdes#define LDNS_MAX_LINELEN 10230 24238104Sdes#define LDNS_MAX_KEYWORDLEN 32 25238104Sdes 26238104Sdes 27238104Sdes/** 28238104Sdes * \file 29238104Sdes * 30238104Sdes * Contains some low-level parsing functions, mostly used in the _frm_str 31238104Sdes * family of functions. 32238104Sdes */ 33238104Sdes 34238104Sdes/** 35238104Sdes * different type of directives in zone files 36238104Sdes * We now deal with $TTL, $ORIGIN and $INCLUDE. 37238104Sdes * The latter is not implemented in ldns (yet) 38238104Sdes */ 39238104Sdesenum ldns_enum_directive 40238104Sdes{ 41238104Sdes LDNS_DIR_TTL, 42238104Sdes LDNS_DIR_ORIGIN, 43238104Sdes LDNS_DIR_INCLUDE 44238104Sdes}; 45238104Sdestypedef enum ldns_enum_directive ldns_directive; 46238104Sdes 47238104Sdes/** 48238104Sdes * returns a token/char from the stream F. 49238104Sdes * This function deals with ( and ) in the stream, 50238104Sdes * and ignores them when encountered 51238104Sdes * \param[in] *f the file to read from 52238104Sdes * \param[out] *token the read token is put here 53238104Sdes * \param[in] *delim chars at which the parsing should stop 54238104Sdes * \param[in] *limit how much to read. If 0 the builtin maximum is used 55238104Sdes * \return 0 on error of EOF of the stream F. Otherwise return the length of what is read 56238104Sdes */ 57238104Sdesssize_t ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit); 58238104Sdes 59238104Sdes/** 60238104Sdes * returns a token/char from the stream F. 61238104Sdes * This function deals with ( and ) in the stream, 62238104Sdes * and ignores when it finds them. 63238104Sdes * \param[in] *f the file to read from 64238104Sdes * \param[out] *token the token is put here 65238104Sdes * \param[in] *delim chars at which the parsing should stop 66238104Sdes * \param[in] *limit how much to read. If 0 use builtin maximum 67238104Sdes * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) 68238104Sdes * \return 0 on error of EOF of F otherwise return the length of what is read 69238104Sdes */ 70238104Sdesssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr); 71238104Sdes 72238104Sdes/** 73238104Sdes * returns a token/char from the buffer b. 74238104Sdes * This function deals with ( and ) in the buffer, 75238104Sdes * and ignores when it finds them. 76238104Sdes * \param[in] *b the buffer to read from 77238104Sdes * \param[out] *token the token is put here 78238104Sdes * \param[in] *delim chars at which the parsing should stop 79238104Sdes * \param[in] *limit how much to read. If 0 the builtin maximum is used 80238104Sdes * \returns 0 on error of EOF of b. Otherwise return the length of what is read 81238104Sdes */ 82238104Sdesssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit); 83238104Sdes 84238104Sdes/* 85238104Sdes * searches for keyword and delim in a file. Gives everything back 86238104Sdes * after the keyword + k_del until we hit d_del 87238104Sdes * \param[in] f file pointer to read from 88238104Sdes * \param[in] keyword keyword to look for 89238104Sdes * \param[in] k_del keyword delimeter 90238104Sdes * \param[out] data the data found 91238104Sdes * \param[in] d_del the data delimeter 92238104Sdes * \param[in] data_limit maximum size the the data buffer 93238104Sdes * \return the number of character read 94238104Sdes */ 95238104Sdesssize_t ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit); 96238104Sdes 97238104Sdes/* 98238104Sdes * searches for keyword and delim. Gives everything back 99238104Sdes * after the keyword + k_del until we hit d_del 100238104Sdes * \param[in] f file pointer to read from 101238104Sdes * \param[in] keyword keyword to look for 102238104Sdes * \param[in] k_del keyword delimeter 103238104Sdes * \param[out] data the data found 104238104Sdes * \param[in] d_del the data delimeter 105238104Sdes * \param[in] data_limit maximum size the the data buffer 106238104Sdes * \param[in] line_nr pointer to an integer containing the current line number (for 107238104Sdesdebugging purposes) 108238104Sdes * \return the number of character read 109238104Sdes */ 110238104Sdesssize_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); 111238104Sdes 112238104Sdes/* 113238104Sdes * searches for keyword and delim in a buffer. Gives everything back 114238104Sdes * after the keyword + k_del until we hit d_del 115238104Sdes * \param[in] b buffer pointer to read from 116238104Sdes * \param[in] keyword keyword to look for 117238104Sdes * \param[in] k_del keyword delimeter 118238104Sdes * \param[out] data the data found 119238104Sdes * \param[in] d_del the data delimeter 120238104Sdes * \param[in] data_limit maximum size the the data buffer 121238104Sdes * \return the number of character read 122238104Sdes */ 123238104Sdesssize_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); 124238104Sdes 125238104Sdes/** 126238104Sdes * returns the next character from a buffer. Advances the position pointer with 1. 127238104Sdes * When end of buffer is reached returns EOF. This is the buffer's equivalent 128238104Sdes * for getc(). 129238104Sdes * \param[in] *buffer buffer to read from 130238104Sdes * \return EOF on failure otherwise return the character 131238104Sdes */ 132238104Sdesint ldns_bgetc(ldns_buffer *buffer); 133238104Sdes 134238104Sdes/** 135238104Sdes * skips all of the characters in the given string in the buffer, moving 136238104Sdes * the position to the first character that is not in *s. 137238104Sdes * \param[in] *buffer buffer to use 138238104Sdes * \param[in] *s characters to skip 139238104Sdes * \return void 140238104Sdes */ 141238104Sdesvoid ldns_bskipcs(ldns_buffer *buffer, const char *s); 142238104Sdes 143238104Sdes/** 144238104Sdes * skips all of the characters in the given string in the fp, moving 145238104Sdes * the position to the first character that is not in *s. 146238104Sdes * \param[in] *fp file to use 147238104Sdes * \param[in] *s characters to skip 148238104Sdes * \return void 149238104Sdes */ 150238104Sdesvoid ldns_fskipcs(FILE *fp, const char *s); 151238104Sdes 152238104Sdes 153238104Sdes/** 154238104Sdes * skips all of the characters in the given string in the fp, moving 155238104Sdes * the position to the first character that is not in *s. 156238104Sdes * \param[in] *fp file to use 157238104Sdes * \param[in] *s characters to skip 158238104Sdes * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) 159238104Sdes * \return void 160238104Sdes */ 161238104Sdesvoid ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr); 162238104Sdes 163238104Sdes#ifdef __cplusplus 164238104Sdes} 165238104Sdes#endif 166238104Sdes 167238104Sdes#endif /* LDNS_PARSE_H */ 168