Mercurial > hg > waaad
view extensions/sec_nosec/sns_conf.y @ 315:3cebe1c677ab
Change build system to CMake (lots of changes)
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 25 Feb 2009 16:49:16 +0900 |
parents | extensions/sec_nosec/sns_gram.y@14665eb59b34 |
children | 25d722e650d4 |
line wrap: on
line source
/********************************************************************************************************* * Software License Agreement (BSD License) * * Author: Sebastien Decugis <sdecugis@nict.go.jp> * * * * Copyright (c) 2008, WIDE Project and NICT * * All rights reserved. * * * * Redistribution and use of this software 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 WIDE Project or NICT nor the * * names of its contributors may be used to endorse or * * promote products derived from this software without * * specific prior written permission of WIDE Project and * * NICT. * * * * 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 COPYRIGHT OWNER 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. * *********************************************************************************************************/ /* Yacc sec_nosec extension's configuration parser. */ /* For development only : */ %debug %error-verbose /* The parser receives the configuration file filename as parameter */ %parse-param {char * conffile} /* Keep track of location */ %locations %pure-parser %{ #include "sec_nosec.h" #include "sns_conf.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */ #include <string.h> #include <errno.h> /* The Lex parser prototype */ int sns_conflex(YYSTYPE *lvalp, YYLTYPE *llocp); /* This function checks a string value can be a DiameterId (== a fqdn) */ static int is_valid_fqdn( char * candidate ) { /* We first search for a '.' */ if (!strchr(candidate, '.')) { log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate); return 0; } /* We may do additional checking here */ /* Ok this candidate is valid */ return 1; } /* Function to report the errors */ void yyerror (YYLTYPE *ploc, char * conffile, char const *s) { TRACE_DEBUG(INFO, "Error in configuration parsing"); if (ploc->first_line != ploc->last_line) log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); else if (ploc->first_column != ploc->last_column) log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s); else log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s); } /* Global variable to store the default priority */ static int def_prio = 1; %} /* Values returned by lex for token */ %union { char *string; /* The string is allocated by strdup in lex.*/ int integer; /* Store integer values */ } /* In case of error in the lexical analysis */ %token LEX_ERROR /* A string (malloc'd in lex parser; it must be freed after use) */ %token <string> STRING /* Strings subtypes */ %type <string> FQDN /* This is a fqdn. We check that the syntax is correct. */ /* An integer value */ %token <integer> INTEGER /* The default priority token */ %token DEF_PRIO /* The debug level token */ %token VERBOSITY /* -------------------------------------- */ %% /* The grammar definition */ conffile: /* empty grammar is OK */ | conffile verbosity | conffile def_prio | conffile peer ; /* Defining the extension debug verbosity level */ verbosity: VERBOSITY '=' INTEGER ';' { verbosity = $3; } ; /* Defining the default peers priority */ def_prio: DEF_PRIO '=' INTEGER ';' { def_prio = $3; } ; /* Validating a FQDN: */ FQDN: STRING { /* Verify this is a valid FQDN */ if (!is_valid_fqdn($1)) { yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting..."); YYERROR; } $$ = $1; } ; /* A peer definition */ peer: FQDN ';' { int ret = 0; ret = sns_addpeer( $1, def_prio ); if (ret != 0) { log_error("An error occurred while saving peer '%s': %s\n", $1, strerror(ret)); YYERROR; } free( $1 ); } | FQDN ',' INTEGER ';' { int ret = 0; ret = sns_addpeer( $1, $3 ); if (ret != 0) { log_error("An error occurred while saving peer '%s': %s\n", $1, strerror(ret)); YYERROR; } free( $1 ); } ;