/* * 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 #include #include #include #include #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 STRING %token VAR_SERVER VAR_VERBOSITY VAR_NUM_THREADS VAR_PORT %token VAR_OUTGOING_PORT VAR_OUTGOING_RANGE %token VAR_DO_IP4 VAR_DO_IP6 VAR_DO_UDP VAR_DO_TCP %token VAR_FORWARD_TO VAR_FORWARD_TO_PORT %% 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_port | server_outgoing_port | server_outgoing_range | server_do_ip4 | server_do_ip6 | server_do_udp | server_do_tcp | server_forward_to | server_forward_to_port; 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); } ; server_port: VAR_PORT STRING { OUTYY(("P(server_port:%s)\n", $2)); if(atoi($2) == 0) yyerror("port number expected"); else cfg_parser->cfg->port = atoi($2); free($2); } ; server_outgoing_port: VAR_OUTGOING_PORT STRING { OUTYY(("P(server_outgoing_port:%s)\n", $2)); if(atoi($2) == 0) yyerror("port number expected"); else cfg_parser->cfg->outgoing_base_port = atoi($2); free($2); } ; server_outgoing_range: VAR_OUTGOING_RANGE STRING { OUTYY(("P(server_outgoing_range:%s)\n", $2)); if(atoi($2) == 0) yyerror("number expected"); else cfg_parser->cfg->outgoing_num_ports = atoi($2); free($2); } ; server_do_ip4: VAR_DO_IP4 STRING { OUTYY(("P(server_do_ip4:%s)\n", $2)); if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0) yyerror("expected yes or no."); else cfg_parser->cfg->do_ip4 = (strcmp($2, "yes")==0); free($2); } ; server_do_ip6: VAR_DO_IP6 STRING { OUTYY(("P(server_do_ip6:%s)\n", $2)); if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0) yyerror("expected yes or no."); else cfg_parser->cfg->do_ip6 = (strcmp($2, "yes")==0); free($2); } ; server_do_udp: VAR_DO_UDP STRING { OUTYY(("P(server_do_udp:%s)\n", $2)); if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0) yyerror("expected yes or no."); else cfg_parser->cfg->do_udp = (strcmp($2, "yes")==0); free($2); } ; server_do_tcp: VAR_DO_TCP STRING { OUTYY(("P(server_do_tcp:%s)\n", $2)); if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0) yyerror("expected yes or no."); else cfg_parser->cfg->do_tcp = (strcmp($2, "yes")==0); free($2); } ; server_forward_to: VAR_FORWARD_TO STRING { OUTYY(("P(server_forward_to:%s)\n", $2)); free(cfg_parser->cfg->fwd_address); cfg_parser->cfg->fwd_address = $2; } ; server_forward_to_port: VAR_FORWARD_TO_PORT STRING { OUTYY(("P(server_forward_to_port:%s)\n", $2)); if(atoi($2) == 0) yyerror("number expected"); else cfg_parser->cfg->fwd_port = atoi($2); free($2); } ; %% /* parse helper routines could be here */