mirror of
https://github.com/NLnetLabs/unbound.git
synced 2024-09-21 06:37:08 +00:00
Config file.
git-svn-id: file:///svn/unbound/trunk@131 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
d6a8a0c37b
commit
4e33e351a3
17
Makefile.in
17
Makefile.in
@ -27,6 +27,8 @@ doxygen=@doxygen@
|
||||
libtool=@libtool@
|
||||
ldnsdir=@ldnsdir@
|
||||
|
||||
YACC=@YACC@
|
||||
LEX=@LEX@
|
||||
CC=@CC@
|
||||
CPPFLAGS=-I. @CPPFLAGS@ @DEFS@
|
||||
CFLAGS=-I. @CFLAGS@
|
||||
@ -48,7 +50,7 @@ LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int
|
||||
|
||||
INSTALL=$(srcdir)/install-sh
|
||||
|
||||
COMMON_SRC=$(wildcard services/*.c util/*.c)
|
||||
COMMON_SRC=$(wildcard services/*.c util/*.c) util/configparser.c util/configlexer.c
|
||||
COMMON_OBJ=$(addprefix $(BUILD),$(COMMON_SRC:.c=.o))
|
||||
COMPAT_OBJ=$(addprefix $(BUILD)compat/,$(LIBOBJS))
|
||||
UNITTEST_SRC=testcode/unitmain.c $(COMMON_SRC)
|
||||
@ -90,6 +92,18 @@ testcode/ldns-testpkts.c: $(ldnsdir)/examples/ldns-testpkts.c \
|
||||
cp $(ldnsdir)/examples/ldns-testpkts.c testcode/ldns-testpkts.c
|
||||
cp $(ldnsdir)/examples/ldns-testpkts.h testcode/ldns-testpkts.h
|
||||
|
||||
util/config_file.c: util/configparser.h
|
||||
util/configlexer.c: $(srcdir)/util/configlexer.lex util/configparser.h
|
||||
$(INFO) Lex $<
|
||||
@if test ! -d util; then $(INSTALL) -d util; fi
|
||||
$Qecho "#include \"util/configyyrename.h\"" > $@
|
||||
$Q$(LEX) -i -t $< >> $@
|
||||
|
||||
util/configparser.c util/configparser.h: $(srcdir)/util/configparser.y
|
||||
$(INFO) Yacc $<
|
||||
@if test ! -d util; then $(INSTALL) -d util; fi
|
||||
$Q$(YACC) -d -o util/configparser.c $<
|
||||
|
||||
clean:
|
||||
rm -f *.o *.d *.lo *~ tags
|
||||
rm -rf autom4te.cache .libs build doc/html
|
||||
@ -97,6 +111,7 @@ clean:
|
||||
realclean: clean
|
||||
rm -f config.status config.log config.h.in config.h
|
||||
rm -f configure config.sub config.guess ltmain.sh aclocal.m4 libtool
|
||||
rm -f util/configlexer.c util/configparser.c util/configparser.h
|
||||
rm -f Makefile
|
||||
|
||||
lint:
|
||||
|
@ -263,6 +263,8 @@ AC_CANONICAL_HOST
|
||||
if echo "$host_os" | grep "sunos4" >/dev/null; then
|
||||
lt_cv_sys_max_cmd_len=32750;
|
||||
fi
|
||||
AC_PROG_LEX
|
||||
AC_PROG_YACC
|
||||
AC_PROG_LIBTOOL
|
||||
|
||||
# Checks for header files.
|
||||
@ -476,6 +478,8 @@ AH_BOTTOM([
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
@ -533,6 +537,9 @@ AH_BOTTOM([
|
||||
# endif
|
||||
#endif /* CHECKED_INET6 */
|
||||
|
||||
/* maximum nesting of included files */
|
||||
#define MAXINCLUDES 10
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
#include <stdarg.h>
|
||||
int snprintf (char *str, size_t count, const char *fmt, ...);
|
||||
|
@ -51,7 +51,6 @@
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
/** timeout in seconds for UDP queries to auth servers. TODO: proper rtt */
|
||||
|
@ -1,6 +1,9 @@
|
||||
20 February 2007: Wouter
|
||||
- Added locks code and pthread spinlock detection.
|
||||
- can use no locks, or solaris native thread library.
|
||||
- added yacc and lex configure, and config file parsing code.
|
||||
also makedist.sh, and manpage.
|
||||
- put include errno.h in config.h
|
||||
|
||||
19 February 2007: Wouter
|
||||
- Created 0.0 svn tag.
|
||||
|
61
doc/unbound.conf.5
Normal file
61
doc/unbound.conf.5
Normal file
@ -0,0 +1,61 @@
|
||||
.\"
|
||||
.\" unbound.conf.5 -- unbound.conf manual
|
||||
.\"
|
||||
.\" Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
.\"
|
||||
.\" See LICENSE for the license.
|
||||
.\"
|
||||
.\"
|
||||
.Dd @date@
|
||||
.Os FreeBSD
|
||||
.Dt unbound.conf 5
|
||||
.Sh NAME
|
||||
.Nm unbound.conf
|
||||
.Nd Unbound configuration file.
|
||||
.Sh SYNOPSIS
|
||||
.Nm unbound.conf
|
||||
.Sh DESCRIPTION
|
||||
.Ic unbound.conf
|
||||
is used to configure
|
||||
.Xr unbound 8 .
|
||||
The file format has attributes and values. Some attributes have attributes inside them.
|
||||
The notation is: attribute: value.
|
||||
|
||||
Comments start with # and last to the end of line. Empty lines are
|
||||
ignored as is whitespace at the beginning of a line.
|
||||
|
||||
.El
|
||||
.Sh FILE FORMAT
|
||||
There must be whitespace between keywords. Attribute keywords end with a colon ':'. An attribute
|
||||
is followed by its containing attributes, or a value.
|
||||
|
||||
.Pp
|
||||
Files can be included using the
|
||||
.Ic include:
|
||||
directive. It can appear anywhere, and takes a single filename as an argument.
|
||||
Processing continues as if the text from the included file was copied into
|
||||
the config file at that point.
|
||||
|
||||
.Ss Server Options
|
||||
There may only be one
|
||||
.Ic server:
|
||||
clause.
|
||||
.Bl -tag -width indent
|
||||
.It \fBverbosity:\fR <number>
|
||||
The verbosity number, level 0 means no verbosity, only errors. Level 1
|
||||
gives operational information. Level 2 gives query level information,
|
||||
output per query. Level 3 gives algorithm level information.
|
||||
.It \fBnum-threads:\fR <number>
|
||||
The number of threads to create to serve clients. Use 1 for no threading.
|
||||
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent
|
||||
.It Pa unbound.conf
|
||||
unbound configuration file.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr unbound 8
|
||||
.Sh AUTHORS
|
||||
.Ic Unbound
|
||||
was written by NLnet Labs. Please see CREDITS file
|
||||
in the distribution for further details.
|
@ -183,7 +183,10 @@ autoheader || error_cleanup "Autoheader failed."
|
||||
|
||||
rm -r autom4te* || error_cleanup "Failed to remove autoconf cache directory."
|
||||
|
||||
# info "Building lexer and parser."
|
||||
info "Building lexer and parser."
|
||||
echo "#include \"util/configyyrename.h\"" > util/configlexer.c || error_cleanup "Failed to create configlexer"
|
||||
flex -i -t util/configlexer.lex >> util/configlexer.c || error_cleanup "Failed to create configlexer"
|
||||
bison -y -d -o util/configparser.c util/configparser.y || error_cleanup "Failed to create configparser"
|
||||
|
||||
# copy ldns-testpkts from ldns examples
|
||||
#cp $LDNSDIR/examples/ldns-testpkts.c testcode/ldns-testpkts.c || error_cleanup "copy ldns/examples/.. failed"
|
||||
|
@ -49,7 +49,6 @@
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/** number of queued TCP connections for listen() */
|
||||
|
@ -50,7 +50,6 @@
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/** number of times to retry making a random ID that is unique. */
|
||||
|
116
util/config_file.c
Normal file
116
util/config_file.c
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* util/config_file.c - reads and stores the config file for unbound.
|
||||
*
|
||||
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* This file contains functions for the config file.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
|
||||
#include "util/configyyrename.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/configparser.h"
|
||||
struct config_parser_state* cfg_parser = 0;
|
||||
extern FILE* ub_c_in, *ub_c_out;
|
||||
int ub_c_parse(void);
|
||||
int ub_c_lex(void);
|
||||
int ub_c_wrap(void);
|
||||
void ub_c_error(const char *message);
|
||||
|
||||
struct config_file*
|
||||
config_create()
|
||||
{
|
||||
struct config_file* cfg;
|
||||
cfg = (struct config_file*)calloc(1, sizeof(struct config_file));
|
||||
if(!cfg)
|
||||
return NULL;
|
||||
/* the defaults if no config is present */
|
||||
cfg->verbosity = 1;
|
||||
cfg->num_threads = 1;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
int
|
||||
config_read(struct config_file* cfg, const char* filename)
|
||||
{
|
||||
FILE *in = fopen(filename, "r");
|
||||
if(!in) {
|
||||
log_err("Could not open %s: %s", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
fclose(in);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
config_delete(struct config_file* cfg)
|
||||
{
|
||||
if(!cfg) return;
|
||||
free(cfg->fwd_address);
|
||||
free(cfg);
|
||||
}
|
||||
|
||||
void ub_c_error_va_list(const char *fmt, va_list args)
|
||||
{
|
||||
cfg_parser->errors++;
|
||||
fprintf(stderr, "%s:%d: error: ", cfg_parser->filename,
|
||||
cfg_parser->line);
|
||||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void ub_c_error_msg(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
ub_c_error_va_list(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void ub_c_error(const char *str)
|
||||
{
|
||||
cfg_parser->errors++;
|
||||
fprintf(stderr, "%s:%d: error: %s\n", cfg_parser->filename,
|
||||
cfg_parser->line, str);
|
||||
}
|
||||
|
||||
int ub_c_wrap()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
97
util/config_file.h
Normal file
97
util/config_file.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* util/config_file.h - reads and stores the config file for unbound.
|
||||
*
|
||||
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* This file contains functions for the config file.
|
||||
*/
|
||||
|
||||
#ifndef UTIL_CONFIG_FILE_H
|
||||
#define UTIL_CONFIG_FILE_H
|
||||
|
||||
/**
|
||||
* The configuration options.
|
||||
* Strings are malloced.
|
||||
*/
|
||||
struct config_file {
|
||||
/** verbosity level as specified in the config file */
|
||||
int verbosity;
|
||||
|
||||
/** number of threads to create */
|
||||
int num_threads;
|
||||
|
||||
/** forwarder address. string. If not NULL fwder mode is enabled. */
|
||||
char* fwd_address;
|
||||
/** forwarder port */
|
||||
int fwd_port;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create config file structure. Filled with default values.
|
||||
* @return: the new structure or NULL on memory error.
|
||||
*/
|
||||
struct config_file* config_create();
|
||||
|
||||
/**
|
||||
* Read the config file from the specified filename.
|
||||
* @param config: where options are stored into, must be freshly created.
|
||||
* @param filename: name of configfile.
|
||||
* @return: false on error.
|
||||
*/
|
||||
int config_read(struct config_file* config, const char* filename);
|
||||
|
||||
/**
|
||||
* Destroy the config file structure.
|
||||
* @param config: to delete.
|
||||
*/
|
||||
void config_delete(struct config_file* config);
|
||||
|
||||
/**
|
||||
* Used during options parsing
|
||||
*/
|
||||
struct config_parser_state {
|
||||
char* filename;
|
||||
int line;
|
||||
int errors;
|
||||
struct config_file* cfg;
|
||||
};
|
||||
|
||||
extern struct config_parser_state* cfg_parser;
|
||||
/* parsing helpers */
|
||||
void ub_c_error(const char* msg);
|
||||
void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
|
||||
#endif /* UTIL_CONFIG_FILE_H */
|
159
util/configlexer.lex
Normal file
159
util/configlexer.lex
Normal file
@ -0,0 +1,159 @@
|
||||
%{
|
||||
/*
|
||||
* configlexer.lex - lexical analyzer for unbound config file
|
||||
*
|
||||
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved
|
||||
*
|
||||
* See LICENSE for the license.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "util/configyyrename.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/configparser.h"
|
||||
void ub_c_error(const char *message);
|
||||
|
||||
#define YY_NO_UNPUT
|
||||
|
||||
#if 0
|
||||
#define LEXOUT(s) printf s /* used ONLY when debugging */
|
||||
#else
|
||||
#define LEXOUT(s)
|
||||
#endif
|
||||
|
||||
struct inc_state {
|
||||
char* filename;
|
||||
int line;
|
||||
};
|
||||
static struct inc_state parse_stack[MAXINCLUDES];
|
||||
static YY_BUFFER_STATE include_stack[MAXINCLUDES];
|
||||
static int config_include_stack_ptr = 0;
|
||||
|
||||
static void config_start_include(const char* filename)
|
||||
{
|
||||
FILE *input;
|
||||
if(strlen(filename) == 0) {
|
||||
ub_c_error_msg("empty include file name");
|
||||
return;
|
||||
}
|
||||
if(config_include_stack_ptr >= MAXINCLUDES) {
|
||||
ub_c_error_msg("includes nested too deeply, skipped (>%d)", MAXINCLUDES);
|
||||
return;
|
||||
}
|
||||
input = fopen(filename, "r");
|
||||
if(!input) {
|
||||
ub_c_error_msg("cannot open include file '%s': %s",
|
||||
filename, strerror(errno));
|
||||
return;
|
||||
}
|
||||
LEXOUT(("switch_to_include_file(%s) ", filename));
|
||||
parse_stack[config_include_stack_ptr].filename = cfg_parser->filename;
|
||||
parse_stack[config_include_stack_ptr].line = cfg_parser->line;
|
||||
include_stack[config_include_stack_ptr] = YY_CURRENT_BUFFER;
|
||||
cfg_parser->filename = strdup(filename);
|
||||
cfg_parser->line = 1;
|
||||
yy_switch_to_buffer(yy_create_buffer(input, YY_BUF_SIZE));
|
||||
++config_include_stack_ptr;
|
||||
}
|
||||
|
||||
static void config_end_include(void)
|
||||
{
|
||||
--config_include_stack_ptr;
|
||||
free(cfg_parser->filename);
|
||||
cfg_parser->filename = parse_stack[config_include_stack_ptr].filename;
|
||||
cfg_parser->line = parse_stack[config_include_stack_ptr].line;
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
yy_switch_to_buffer(include_stack[config_include_stack_ptr]);
|
||||
}
|
||||
|
||||
#ifndef yy_set_bol /* compat definition, for flex 2.4.6 */
|
||||
#define yy_set_bol(at_bol) \
|
||||
{ \
|
||||
if ( ! yy_current_buffer ) \
|
||||
yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
|
||||
yy_current_buffer->yy_ch_buf[0] = ((at_bol)?'\n':' '); \
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
SPACE [ \t]
|
||||
LETTER [a-zA-Z]
|
||||
UNQUOTEDLETTER [^\"\n\r \t\\]|\\.
|
||||
NEWLINE [\r\n]
|
||||
COMMENT \#
|
||||
COLON \:
|
||||
ANY [^\"\n\r\\]|\\.
|
||||
|
||||
%x quotedstring include include_quoted
|
||||
|
||||
%%
|
||||
{SPACE}* { LEXOUT(("SP ")); /* ignore */ }
|
||||
{SPACE}*{COMMENT}.* { LEXOUT(("comment(%s) ", yytext)); /* ignore */ }
|
||||
server{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_SERVER;}
|
||||
num-threads{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_NUM_THREADS;}
|
||||
verbosity{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_VERBOSITY;}
|
||||
{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;}
|
||||
|
||||
/* Quoted strings. Strip leading and ending quotes */
|
||||
\" { BEGIN(quotedstring); LEXOUT(("QS ")); }
|
||||
<quotedstring><<EOF>> {
|
||||
yyerror("EOF inside quoted string");
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
<quotedstring>{ANY}* { LEXOUT(("STR(%s) ", yytext)); yymore(); }
|
||||
<quotedstring>\n { cfg_parser->line++; yymore(); }
|
||||
<quotedstring>\" {
|
||||
LEXOUT(("QE "));
|
||||
BEGIN(INITIAL);
|
||||
yytext[yyleng - 1] = '\0';
|
||||
yylval.str = strdup(yytext);
|
||||
return STRING;
|
||||
}
|
||||
|
||||
/* include: directive */
|
||||
include{COLON} { LEXOUT(("v(%s) ", yytext)); BEGIN(include); }
|
||||
<include><<EOF>> {
|
||||
yyerror("EOF inside include directive");
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
<include>{SPACE}* { LEXOUT(("ISP ")); /* ignore */ }
|
||||
<include>{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;}
|
||||
<include>\" { LEXOUT(("IQS ")); BEGIN(include_quoted); }
|
||||
<include>{UNQUOTEDLETTER}* {
|
||||
LEXOUT(("Iunquotedstr(%s) ", yytext));
|
||||
config_start_include(yytext);
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
<include_quoted><<EOF>> {
|
||||
yyerror("EOF inside quoted string");
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
<include_quoted>{ANY}* { LEXOUT(("ISTR(%s) ", yytext)); yymore(); }
|
||||
<include_quoted>{NEWLINE} { cfg_parser->line++; yymore(); }
|
||||
<include_quoted>\" {
|
||||
LEXOUT(("IQE "));
|
||||
yytext[yyleng - 1] = '\0';
|
||||
config_start_include(yytext);
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
<INITIAL><<EOF>> {
|
||||
yy_set_bol(1); /* Set beginning of line, so "^" rules match. */
|
||||
if (config_include_stack_ptr == 0) {
|
||||
yyterminate();
|
||||
} else {
|
||||
fclose(yyin);
|
||||
config_end_include();
|
||||
}
|
||||
}
|
||||
|
||||
{UNQUOTEDLETTER}* { LEXOUT(("unquotedstr(%s) ", yytext));
|
||||
yylval.str = strdup(yytext); return STRING; }
|
||||
|
||||
%%
|
108
util/configparser.y
Normal file
108
util/configparser.y
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* configparser.y -- yacc grammar for unbound configuration files
|
||||
*
|
||||
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
%{
|
||||
#include "config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "util/configyyrename.h"
|
||||
#include "util/config_file.h"
|
||||
|
||||
int ub_c_lex(void);
|
||||
void ub_c_error(const char *message);
|
||||
|
||||
/* these need to be global, otherwise they cannot be used inside yacc */
|
||||
extern struct config_parser_state* cfg_parser;
|
||||
static int server_settings_seen = 0;
|
||||
|
||||
#if 0
|
||||
#define OUTYY(s) printf s /* used ONLY when debugging */
|
||||
#else
|
||||
#define OUTYY(s)
|
||||
#endif
|
||||
|
||||
%}
|
||||
%union {
|
||||
char* str;
|
||||
}
|
||||
|
||||
%token SPACE LETTER NEWLINE COMMENT COLON ANY ZONESTR
|
||||
%token <str> STRING
|
||||
%token VAR_SERVER VAR_VERBOSITY VAR_NUM_THREADS
|
||||
|
||||
%%
|
||||
toplevelvars: /* empty */ | toplevelvars toplevelvar ;
|
||||
toplevelvar: serverstart contents_server ;
|
||||
|
||||
/* server: declaration */
|
||||
serverstart: VAR_SERVER
|
||||
{ OUTYY(("\nP(server:)\n"));
|
||||
if(server_settings_seen) {
|
||||
yyerror("duplicate server: element.");
|
||||
}
|
||||
server_settings_seen = 1;
|
||||
}
|
||||
;
|
||||
contents_server: contents_server content_server | ;
|
||||
content_server: server_num_threads | server_verbosity;
|
||||
server_num_threads: VAR_NUM_THREADS STRING
|
||||
{
|
||||
OUTYY(("P(server_num_threads:%s)\n", $2));
|
||||
if(atoi($2) == 0 && strcmp($2, "0") != 0)
|
||||
yyerror("number expected");
|
||||
else cfg_parser->cfg->num_threads = atoi($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_verbosity: VAR_VERBOSITY STRING
|
||||
{
|
||||
OUTYY(("P(server_verbosity:%s)\n", $2));
|
||||
if(atoi($2) == 0 && strcmp($2, "0") != 0)
|
||||
yyerror("number expected");
|
||||
else cfg_parser->cfg->verbosity = atoi($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
/* parse helper routines could be here */
|
89
util/configyyrename.h
Normal file
89
util/configyyrename.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* configyyrename.h -- renames for config file yy values to avoid conflicts.
|
||||
*
|
||||
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* See LICENSE for the license.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UTIL_CONFIGYYRENAME_H
|
||||
#define UTIL_CONFIGYYRENAME_H
|
||||
#include "config.h"
|
||||
|
||||
/* defines to change symbols so that no yacc/lex symbols clash */
|
||||
#define yymaxdepth ub_c_maxdepth
|
||||
#define yyparse ub_c_parse
|
||||
#define yylex ub_c_lex
|
||||
#define yyerror ub_c_error
|
||||
#define yylval ub_c_lval
|
||||
#define yychar ub_c_char
|
||||
#define yydebug ub_c_debug
|
||||
#define yypact ub_c_pact
|
||||
#define yyr1 ub_c_r1
|
||||
#define yyr2 ub_c_r2
|
||||
#define yydef ub_c_def
|
||||
#define yychk ub_c_chk
|
||||
#define yypgo ub_c_pgo
|
||||
#define yyact ub_c_act
|
||||
#define yyexca ub_c_exca
|
||||
#define yyerrflag ub_c_errflag
|
||||
#define yynerrs ub_c_nerrs
|
||||
#define yyps ub_c_ps
|
||||
#define yypv ub_c_pv
|
||||
#define yys ub_c_s
|
||||
#define yy_yys ub_c_yys
|
||||
#define yystate ub_c_state
|
||||
#define yytmp ub_c_tmp
|
||||
#define yyv ub_c_v
|
||||
#define yy_yyv ub_c_yyv
|
||||
#define yyval ub_c_val
|
||||
#define yylloc ub_c_lloc
|
||||
#define yyreds ub_c_reds
|
||||
#define yytoks ub_c_toks
|
||||
#define yylhs ub_c_yylhs
|
||||
#define yylen ub_c_yylen
|
||||
#define yydefred ub_c_yydefred
|
||||
#define yydgoto ub_c_yydgoto
|
||||
#define yysindex ub_c_yysindex
|
||||
#define yyrindex ub_c_yyrindex
|
||||
#define yygindex ub_c_yygindex
|
||||
#define yytable ub_c_yytable
|
||||
#define yycheck ub_c_yycheck
|
||||
#define yyname ub_c_yyname
|
||||
#define yyrule ub_c_yyrule
|
||||
#define yyin ub_c_in
|
||||
#define yyout ub_c_out
|
||||
#define yywrap ub_c_wrap
|
||||
#define yy_load_buffer_state ub_c_load_buffer_state
|
||||
#define yy_switch_to_buffer ub_c_switch_to_buffer
|
||||
#define yy_flush_buffer ub_c_flush_buffer
|
||||
#define yy_init_buffer ub_c_init_buffer
|
||||
#define yy_scan_buffer ub_c_scan_buffer
|
||||
#define yy_scan_bytes ub_c_scan_bytes
|
||||
#define yy_scan_string ub_c_scan_string
|
||||
#define yy_create_buffer ub_c_create_buffer
|
||||
#define yyrestart ub_c_restart
|
||||
#define yy_delete_buffer ub_c_delete_buffer
|
||||
#define yypop_buffer_state ub_c_pop_buffer_state
|
||||
#define yypush_buffer_state ub_c_push_buffer_state
|
||||
#define yyunput ub_c_unput
|
||||
#define yyset_in ub_c_set_in
|
||||
#define yyget_in ub_c_get_in
|
||||
#define yyset_out ub_c_set_out
|
||||
#define yyget_out ub_c_get_out
|
||||
#define yyget_lineno ub_c_get_lineno
|
||||
#define yyset_lineno ub_c_set_lineno
|
||||
#define yyset_debug ub_c_set_debug
|
||||
#define yyget_debug ub_c_get_debug
|
||||
#define yy_flex_debug ub_c_flex_debug
|
||||
#define yylex_destroy ub_c_lex_destroy
|
||||
#define yyfree ub_c_free
|
||||
#define yyrealloc ub_c_realloc
|
||||
#define yyalloc ub_c_alloc
|
||||
#define yymalloc ub_c_malloc
|
||||
#define yyget_leng ub_c_get_leng
|
||||
#define yylineno ub_c_lineno
|
||||
#define yyget_text ub_c_get_text
|
||||
|
||||
#endif /* UTIL_CONFIGYYRENAME_H */
|
@ -41,7 +41,6 @@
|
||||
|
||||
#include "util/netevent.h"
|
||||
#include "util/log.h"
|
||||
#include <errno.h>
|
||||
|
||||
/* -------- Start of local definitions -------- */
|
||||
/** The TCP reading or writing query timeout in seconds */
|
||||
|
Loading…
Reference in New Issue
Block a user