#include <stdio.h>
#include <isc/lang.h>
#include <isc/region.h>
#include <isc/types.h>
Go to the source code of this file.
Data Structures | |
union | isc_tokenvalue_t |
struct | isc_token |
Defines | |
#define | ISC_LEX_H 1 |
#define | ISC_LEXOPT_EOL 0x01 |
Want end-of-line token. | |
#define | ISC_LEXOPT_EOF 0x02 |
Want end-of-file token. | |
#define | ISC_LEXOPT_INITIALWS 0x04 |
Want initial whitespace. | |
#define | ISC_LEXOPT_NUMBER 0x08 |
Recognize numbers. | |
#define | ISC_LEXOPT_QSTRING 0x10 |
Recognize qstrings. | |
#define | ISC_LEXOPT_DNSMULTILINE 0x20 |
Handle '(' and ')'. | |
#define | ISC_LEXOPT_NOMORE 0x40 |
Want "no more" token. | |
#define | ISC_LEXOPT_CNUMBER 0x80 |
Recognize octal and hex. | |
#define | ISC_LEXOPT_ESCAPE 0x100 |
Recognize escapes. | |
#define | ISC_LEXOPT_QSTRINGMULTILINE 0x200 |
Allow multiline "" strings. | |
#define | ISC_LEXOPT_OCTAL 0x400 |
Expect a octal number. | |
#define | ISC_LEXCOMMENT_C 0x01 |
#define | ISC_LEXCOMMENT_CPLUSPLUS 0x02 |
#define | ISC_LEXCOMMENT_SHELL 0x04 |
#define | ISC_LEXCOMMENT_DNSMASTERFILE 0x08 |
Typedefs | |
typedef char | isc_lexspecials_t [256] |
typedef struct isc_token | isc_token_t |
Enumerations | |
enum | isc_tokentype_t { isc_tokentype_unknown = 0, isc_tokentype_string = 1, isc_tokentype_number = 2, isc_tokentype_qstring = 3, isc_tokentype_eol = 4, isc_tokentype_eof = 5, isc_tokentype_initialws = 6, isc_tokentype_special = 7, isc_tokentype_nomore = 8 } |
Functions | |
isc_result_t | isc_lex_create (isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp) |
Create a lexer. | |
void | isc_lex_destroy (isc_lex_t **lexp) |
Destroy the lexer. | |
unsigned int | isc_lex_getcomments (isc_lex_t *lex) |
Return the current lexer commenting styles. | |
void | isc_lex_setcomments (isc_lex_t *lex, unsigned int comments) |
Set allowed lexer commenting styles. | |
void | isc_lex_getspecials (isc_lex_t *lex, isc_lexspecials_t specials) |
Put the current list of specials into 'specials'. | |
void | isc_lex_setspecials (isc_lex_t *lex, isc_lexspecials_t specials) |
isc_result_t | isc_lex_openfile (isc_lex_t *lex, const char *filename) |
Open 'filename' and make it the current input source for 'lex'. | |
isc_result_t | isc_lex_openstream (isc_lex_t *lex, FILE *stream) |
Make 'stream' the current input source for 'lex'. | |
isc_result_t | isc_lex_openbuffer (isc_lex_t *lex, isc_buffer_t *buffer) |
Make 'buffer' the current input source for 'lex'. | |
isc_result_t | isc_lex_close (isc_lex_t *lex) |
Close the most recently opened object (i.e. file or buffer). | |
isc_result_t | isc_lex_gettoken (isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) |
Get the next token. | |
isc_result_t | isc_lex_getmastertoken (isc_lex_t *lex, isc_token_t *token, isc_tokentype_t expect, isc_boolean_t eol) |
Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles quoted strings and end of line correctly for master files. It also ungets unexpected tokens. | |
isc_result_t | isc_lex_getoctaltoken (isc_lex_t *lex, isc_token_t *token, isc_boolean_t eol) |
Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles end of line correctly for master files. It also ungets unexpected tokens. | |
void | isc_lex_ungettoken (isc_lex_t *lex, isc_token_t *tokenp) |
Unget the current token. | |
void | isc_lex_getlasttokentext (isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r) |
Returns a region containing the text of the last token returned. | |
char * | isc_lex_getsourcename (isc_lex_t *lex) |
Return the input source name. | |
unsigned long | isc_lex_getsourceline (isc_lex_t *lex) |
Return the input source line number. | |
isc_result_t | isc_lex_setsourcename (isc_lex_t *lex, const char *name) |
Assigns a new name to the input source. | |
isc_boolean_t | isc_lex_isfile (isc_lex_t *lex) |
Return whether the current input source is a file. |
Definition in file lex.h.
#define ISC_LEXOPT_EOL 0x01 |
Want end-of-line token.
Various options for isc_lex_gettoken().
Definition at line 71 of file lex.h.
Referenced by dns_rdata_fromtext(), dns_view_loadnta(), dst__privstruct_parse(), gettoken(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), and isc_lex_gettoken().
#define ISC_LEXOPT_EOF 0x02 |
Want end-of-file token.
Definition at line 72 of file lex.h.
Referenced by cfg_gettoken(), dns_rdata_fromtext(), dns_view_loadnta(), gettoken(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), and isc_lex_gettoken().
#define ISC_LEXOPT_INITIALWS 0x04 |
Want initial whitespace.
Definition at line 73 of file lex.h.
Referenced by isc_lex_gettoken(), and load_text().
#define ISC_LEXOPT_NUMBER 0x08 |
Recognize numbers.
Definition at line 74 of file lex.h.
Referenced by cfg_parse_dscp(), cfg_parse_netprefix(), cfg_parse_rawport(), cfg_parse_uint32(), dst__privstruct_parse(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), isc_lex_gettoken(), parse_logseverity(), parse_optional_uint32(), and parse_portrange().
#define ISC_LEXOPT_QSTRING 0x10 |
Recognize qstrings.
Definition at line 75 of file lex.h.
Referenced by isc_lex_getmastertoken(), isc_lex_gettoken(), and load_text().
#define ISC_LEXOPT_DNSMULTILINE 0x20 |
Handle '(' and ')'.
The ISC_LEXOPT_DNSMULTILINE option handles the processing of '(' and ')' in the DNS master file format. If this option is set, then the ISC_LEXOPT_INITIALWS and ISC_LEXOPT_EOL options will be ignored when the paren count is > 0. To use this option, '(' and ')' must be special characters.
Definition at line 86 of file lex.h.
Referenced by dns_rdata_fromtext(), dst_key_read_public(), gettoken(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), and isc_lex_gettoken().
#define ISC_LEXOPT_NOMORE 0x40 |
Want "no more" token.
Definition at line 87 of file lex.h.
Referenced by cfg_gettoken(), and isc_lex_gettoken().
#define ISC_LEXOPT_CNUMBER 0x80 |
Recognize octal and hex.
Definition at line 89 of file lex.h.
Referenced by cfg_parse_dscp(), cfg_parse_uint32(), isc_lex_gettoken(), parse_optional_uint32(), and parse_portrange().
#define ISC_LEXOPT_ESCAPE 0x100 |
Recognize escapes.
Definition at line 90 of file lex.h.
Referenced by dns_rdata_fromtext(), gettoken(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), and isc_lex_gettoken().
#define ISC_LEXOPT_QSTRINGMULTILINE 0x200 |
#define ISC_LEXOPT_OCTAL 0x400 |
Expect a octal number.
Definition at line 92 of file lex.h.
Referenced by isc_lex_getoctaltoken(), and isc_lex_gettoken().
#define ISC_LEXCOMMENT_C 0x01 |
Various commenting styles, which may be changed at any time with isc_lex_setcomments().
Definition at line 100 of file lex.h.
Referenced by cfg_parser_create(), and isc_lex_gettoken().
#define ISC_LEXCOMMENT_CPLUSPLUS 0x02 |
Various commenting styles, which may be changed at any time with isc_lex_setcomments().
Definition at line 101 of file lex.h.
Referenced by cfg_parser_create(), and isc_lex_gettoken().
#define ISC_LEXCOMMENT_SHELL 0x04 |
Various commenting styles, which may be changed at any time with isc_lex_setcomments().
Definition at line 102 of file lex.h.
Referenced by cfg_parser_create(), and isc_lex_gettoken().
#define ISC_LEXCOMMENT_DNSMASTERFILE 0x08 |
Various commenting styles, which may be changed at any time with isc_lex_setcomments().
Definition at line 103 of file lex.h.
Referenced by dst_key_read_public(), isc_lex_gettoken(), and loadctx_create().
typedef char isc_lexspecials_t[256] |
typedef struct isc_token isc_token_t |
enum isc_tokentype_t |
isc_result_t isc_lex_create | ( | isc_mem_t * | mctx, | |
size_t | max_token, | |||
isc_lex_t ** | lexp | |||
) |
Create a lexer.
'max_token' is a hint of the number of bytes in the largest token.
Requires:
Definition at line 91 of file lex.c.
References isc_lex::comment_ok, isc_lex::comments, isc_lex::data, INIT_LIST, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISC_TRUE, isc_lex::last_was_eol, LEX_MAGIC, isc_lex::magic, isc_lex::max_token, isc_lex::mctx, isc_lex::paren_count, REQUIRE, isc_lex::saved_paren_count, and isc_lex::specials.
Referenced by ATF_TC_BODY(), cfg_parser_create(), dns_sdb_putrr(), dns_sdlz_putrr(), dns_view_loadnta(), dst_key_fromnamedfile(), dst_key_privatefrombuffer(), dst_key_read_public(), loadctx_create(), and parse_rdata().
void isc_lex_destroy | ( | isc_lex_t ** | lexp | ) |
Destroy the lexer.
Requires:
Definition at line 126 of file lex.c.
References isc_lex::data, EMPTY, isc_lex_close(), isc_mem_put, ISC_R_SUCCESS, isc_lex::magic, isc_lex::max_token, isc_lex::mctx, REQUIRE, RUNTIME_CHECK, and VALID_LEX.
Referenced by cfg_parser_create(), cfg_parser_destroy(), dns_sdb_putrr(), dns_sdlz_putrr(), dns_view_loadnta(), dst_key_fromnamedfile(), dst_key_privatefrombuffer(), dst_key_read_public(), loadctx_destroy(), and parse_rdata().
unsigned int isc_lex_getcomments | ( | isc_lex_t * | lex | ) |
Return the current lexer commenting styles.
Requires:
Definition at line 148 of file lex.c.
References isc_lex::comments, REQUIRE, and VALID_LEX.
void isc_lex_setcomments | ( | isc_lex_t * | lex, | |
unsigned int | comments | |||
) |
Set allowed lexer commenting styles.
Requires:
Definition at line 159 of file lex.c.
References isc_lex::comments, REQUIRE, and VALID_LEX.
Referenced by cfg_parser_create(), dst_key_read_public(), and loadctx_create().
void isc_lex_getspecials | ( | isc_lex_t * | lex, | |
isc_lexspecials_t | specials | |||
) |
Put the current list of specials into 'specials'.
Requires:
Definition at line 170 of file lex.c.
References REQUIRE, isc_lex::specials, and VALID_LEX.
void isc_lex_setspecials | ( | isc_lex_t * | lex, | |
isc_lexspecials_t | specials | |||
) |
The characters in 'specials' are returned as tokens. Along with whitespace, they delimit strings and numbers.
Note:
Definition at line 181 of file lex.c.
References REQUIRE, isc_lex::specials, and VALID_LEX.
Referenced by cfg_parser_create(), dst_key_read_public(), and loadctx_create().
isc_result_t isc_lex_openfile | ( | isc_lex_t * | lex, | |
const char * | filename | |||
) |
Open 'filename' and make it the current input source for 'lex'.
Requires:
Definition at line 229 of file lex.c.
References ISC_R_SUCCESS, isc_stdio_open(), ISC_TRUE, new_source(), REQUIRE, inputsource::result, and VALID_LEX.
Referenced by dns_view_loadnta(), dst_key_fromnamedfile(), dst_key_read_public(), openfile_text(), and parser_openfile().
isc_result_t isc_lex_openstream | ( | isc_lex_t * | lex, | |
FILE * | stream | |||
) |
Make 'stream' the current input source for 'lex'.
Requires:
Definition at line 250 of file lex.c.
References ISC_FALSE, ISC_TRUE, inputsource::name, new_source(), REQUIRE, and VALID_LEX.
Referenced by dns_master_loadstream(), and dns_master_loadstreaminc().
isc_result_t isc_lex_openbuffer | ( | isc_lex_t * | lex, | |
isc_buffer_t * | buffer | |||
) |
Make 'buffer' the current input source for 'lex'.
Requires:
Definition at line 265 of file lex.c.
References ISC_FALSE, inputsource::name, new_source(), REQUIRE, and VALID_LEX.
Referenced by ATF_TC_BODY(), cfg_parse_buffer(), dns_master_loadbuffer(), dns_master_loadbufferinc(), dns_sdb_putrr(), dns_sdlz_putrr(), dst_key_privatefrombuffer(), generate(), and parse_rdata().
isc_result_t isc_lex_close | ( | isc_lex_t * | lex | ) |
Close the most recently opened object (i.e. file or buffer).
Returns:
Definition at line 280 of file lex.c.
References HEAD, inputsource::input, inputsource::is_file, isc_buffer_free(), ISC_LIST_UNLINK, isc_mem_free, isc_mem_put, ISC_R_NOMORE, ISC_R_SUCCESS, inputsource::last_was_eol, isc_lex::last_was_eol, isc_lex::mctx, inputsource::name, inputsource::need_close, inputsource::pushback, REQUIRE, and VALID_LEX.
Referenced by cfg_gettoken(), cfg_parser_reset(), dns_view_loadnta(), generate(), isc_lex_destroy(), and load_text().
isc_result_t isc_lex_gettoken | ( | isc_lex_t * | lex, | |
unsigned int | options, | |||
isc_token_t * | tokenp | |||
) |
Get the next token.
Requires:
Definition at line 356 of file lex.c.
References isc_tokenvalue_t::as_char, isc_tokenvalue_t::as_textregion, isc_tokenvalue_t::as_ulong, inputsource::at_eof, isc_textregion::base, isc_buffer::base, buffer, isc_lex::comment_ok, isc_lex::comments, isc_buffer::current, isc_lex::data, FATAL_ERROR, grow_data(), HEAD, inputsource::ignored, inputsource::input, INSIST, inputsource::is_file, isc_buffer_compact(), isc_buffer_consumedlength, isc_buffer_getuint8(), isc_buffer_remaininglength, ISC_FALSE, ISC_LEXCOMMENT_C, ISC_LEXCOMMENT_CPLUSPLUS, ISC_LEXCOMMENT_DNSMASTERFILE, ISC_LEXCOMMENT_SHELL, ISC_LEXOPT_CNUMBER, ISC_LEXOPT_DNSMULTILINE, ISC_LEXOPT_EOF, ISC_LEXOPT_EOL, ISC_LEXOPT_ESCAPE, ISC_LEXOPT_INITIALWS, ISC_LEXOPT_NOMORE, ISC_LEXOPT_NUMBER, ISC_LEXOPT_OCTAL, ISC_LEXOPT_QSTRING, ISC_LEXOPT_QSTRINGMULTILINE, ISC_MSG_UNEXPECTEDSTATE, isc_msgcat_get(), ISC_MSGSET_LEX, isc_parse_uint32(), ISC_R_BADNUMBER, ISC_R_EOF, ISC_R_IOERROR, ISC_R_NOMORE, ISC_R_SUCCESS, ISC_R_UNBALANCED, ISC_R_UNBALANCEDQUOTES, ISC_R_UNEXPECTEDEND, isc_tokentype_eof, isc_tokentype_eol, isc_tokentype_initialws, isc_tokentype_nomore, isc_tokentype_number, isc_tokentype_qstring, isc_tokentype_special, isc_tokentype_string, ISC_TRUE, IWSEOL, isc_lex::last_was_eol, isc_textregion::length, lexstate_ccomment, lexstate_ccommentend, lexstate_crlf, lexstate_eatline, lexstate_maybecomment, lexstate_number, lexstate_qstring, lexstate_start, lexstate_string, inputsource::line, isc_lex::max_token, isc_lex::paren_count, pushandgrow(), inputsource::pushback, REQUIRE, inputsource::result, inputsource::saved_line, isc_lex::saved_paren_count, isc_lex::specials, isc_token::type, isc_buffer::used, VALID_LEX, and isc_token::value.
Referenced by ATF_TC_BODY(), cfg_gettoken(), dns_rdata_fromtext(), dns_view_loadnta(), dst__privstruct_parse(), gettoken(), isc_lex_getmastertoken(), and isc_lex_getoctaltoken().
isc_result_t isc_lex_getmastertoken | ( | isc_lex_t * | lex, | |
isc_token_t * | token, | |||
isc_tokentype_t | expect, | |||
isc_boolean_t | eol | |||
) |
Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles quoted strings and end of line correctly for master files. It also ungets unexpected tokens.
Requires:
Definition at line 802 of file lex.c.
References isc_lex_gettoken(), isc_lex_ungettoken(), ISC_LEXOPT_DNSMULTILINE, ISC_LEXOPT_EOF, ISC_LEXOPT_EOL, ISC_LEXOPT_ESCAPE, ISC_LEXOPT_NUMBER, ISC_LEXOPT_QSTRING, ISC_R_BADNUMBER, ISC_R_RANGE, ISC_R_SUCCESS, ISC_R_UNEXPECTEDEND, ISC_R_UNEXPECTEDTOKEN, isc_tokentype_eof, isc_tokentype_eol, isc_tokentype_number, isc_tokentype_qstring, isc_tokentype_string, inputsource::result, and isc_token::type.
Referenced by atob_tobuffer(), base32_tobuffer(), dns_rdata_fromtext(), fromtext_afsdb(), fromtext_any_tsig(), fromtext_caa(), fromtext_cdnskey(), fromtext_cds(), fromtext_cert(), fromtext_ch_a(), fromtext_cname(), fromtext_dlv(), fromtext_dname(), fromtext_dnskey(), fromtext_ds(), fromtext_eui48(), fromtext_eui64(), fromtext_gpos(), fromtext_hinfo(), fromtext_hip(), fromtext_hs_a(), fromtext_in_a(), fromtext_in_a6(), fromtext_in_aaaa(), fromtext_in_apl(), fromtext_in_kx(), fromtext_in_nsap(), fromtext_in_nsap_ptr(), fromtext_in_px(), fromtext_in_srv(), fromtext_in_wks(), fromtext_ipseckey(), fromtext_isdn(), fromtext_key(), fromtext_keydata(), fromtext_l32(), fromtext_l64(), fromtext_loc(), fromtext_lp(), fromtext_mb(), fromtext_md(), fromtext_mf(), fromtext_mg(), fromtext_minfo(), fromtext_mr(), fromtext_mx(), fromtext_naptr(), fromtext_nid(), fromtext_ns(), fromtext_nsec(), fromtext_nsec3(), fromtext_nsec3param(), fromtext_nxt(), fromtext_ptr(), fromtext_rp(), fromtext_rrsig(), fromtext_rt(), fromtext_sig(), fromtext_soa(), fromtext_spf(), fromtext_sshfp(), fromtext_tkey(), fromtext_tlsa(), fromtext_txt(), fromtext_uri(), fromtext_x25(), isc_base64_tobuffer(), isc_hex_tobuffer(), and unknown_fromtext().
isc_result_t isc_lex_getoctaltoken | ( | isc_lex_t * | lex, | |
isc_token_t * | token, | |||
isc_boolean_t | eol | |||
) |
Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles end of line correctly for master files. It also ungets unexpected tokens.
Requires:
Definition at line 838 of file lex.c.
References isc_lex_gettoken(), isc_lex_ungettoken(), ISC_LEXOPT_DNSMULTILINE, ISC_LEXOPT_EOF, ISC_LEXOPT_EOL, ISC_LEXOPT_ESCAPE, ISC_LEXOPT_NUMBER, ISC_LEXOPT_OCTAL, ISC_R_BADNUMBER, ISC_R_RANGE, ISC_R_SUCCESS, ISC_R_UNEXPECTEDEND, isc_tokentype_eof, isc_tokentype_eol, isc_tokentype_number, inputsource::result, and isc_token::type.
Referenced by fromtext_ch_a().
void isc_lex_ungettoken | ( | isc_lex_t * | lex, | |
isc_token_t * | tokenp | |||
) |
Unget the current token.
Requires:
Definition at line 865 of file lex.c.
References inputsource::at_eof, HEAD, isc_buffer_consumedlength, isc_buffer_first, ISC_FALSE, isc_tokentype_eof, inputsource::line, isc_lex::paren_count, inputsource::pushback, REQUIRE, inputsource::saved_line, isc_lex::saved_paren_count, isc_token::type, UNUSED, and VALID_LEX.
Referenced by base32_tobuffer(), cfg_ungettoken(), dns_rdata_fromtext(), fromtext_hip(), fromtext_in_apl(), fromtext_in_wks(), fromtext_isdn(), fromtext_loc(), fromtext_nsec(), fromtext_nsec3(), fromtext_nxt(), fromtext_spf(), fromtext_txt(), isc_base64_tobuffer(), isc_hex_tobuffer(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), and load_text().
void isc_lex_getlasttokentext | ( | isc_lex_t * | lex, | |
isc_token_t * | tokenp, | |||
isc_region_t * | r | |||
) |
Returns a region containing the text of the last token returned.
Requires:
Definition at line 887 of file lex.c.
References isc_region::base, HEAD, inputsource::ignored, INSIST, isc_buffer_base, isc_buffer_consumedlength, isc_tokentype_eof, isc_region::length, inputsource::pushback, REQUIRE, isc_token::type, UNUSED, and VALID_LEX.
Referenced by parse_token(), and parser_complain().
char* isc_lex_getsourcename | ( | isc_lex_t * | lex | ) |
Return the input source name.
Requires:
Definition at line 909 of file lex.c.
References HEAD, inputsource::name, REQUIRE, and VALID_LEX.
Referenced by cfg_gettoken(), dns_rdata_fromtext(), fromtext_loc(), fromtext_warneof(), getquad(), gettoken(), load_text(), warn_badmx(), and warn_badname().
unsigned long isc_lex_getsourceline | ( | isc_lex_t * | lex | ) |
Return the input source line number.
Requires:
Definition at line 922 of file lex.c.
References HEAD, inputsource::line, REQUIRE, and VALID_LEX.
Referenced by cfg_gettoken(), dns_rdata_fromtext(), fromtext_loc(), fromtext_warneof(), getquad(), gettoken(), load_text(), warn_badmx(), and warn_badname().
isc_result_t isc_lex_setsourcename | ( | isc_lex_t * | lex, | |
const char * | name | |||
) |
Assigns a new name to the input source.
Requires:
Definition at line 936 of file lex.c.
References HEAD, isc_mem_free, isc_mem_strdup, ISC_R_NOMEMORY, ISC_R_NOTFOUND, ISC_R_SUCCESS, isc_lex::mctx, inputsource::name, REQUIRE, and VALID_LEX.
isc_boolean_t isc_lex_isfile | ( | isc_lex_t * | lex | ) |
Return whether the current input source is a file.
Requires:
Definition at line 954 of file lex.c.
References HEAD, inputsource::is_file, ISC_FALSE, REQUIRE, and VALID_LEX.
Referenced by fromtext_warneof().