blob: 6c288a4da680319b30dad20f376b5933d4eba061 [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*********************************************************************************************************
2* Software License Agreement (BSD License) *
3* Author: Alexandre Westfahl <awestfahl@freediameter.net> *
4* *
5* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. *
6* *
7* All rights reserved. *
8* Based on ta_conf.y (Sebastien Decugis <sdecugis@freediameter.net>) *
9* *
10* Redistribution and use of this software in source and binary forms, with or without modification, are *
11* permitted provided that the following conditions are met: *
12* *
13* * Redistributions of source code must retain the above *
14* copyright notice, this list of conditions and the *
15* following disclaimer. *
16* *
17* * Redistributions in binary form must reproduce the above *
18* copyright notice, this list of conditions and the *
19* following disclaimer in the documentation and/or other *
20* materials provided with the distribution. *
21* *
22* * Neither the name of the Teraoka Laboratory nor the *
23* names of its contributors may be used to endorse or *
24* promote products derived from this software without *
25* specific prior written permission of Teraoka Laboratory *
26* *
27* *
28* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
29* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
30* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
31* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
32* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
33* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
34* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
35* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
36*********************************************************************************************************/
37
38
39
40/* For development only : */
41%debug
42%error-verbose
43
44/* The parser receives the configuration file filename as parameter */
45%parse-param {char * conffile}
46
47/* Keep track of location */
48%locations
49%pure-parser
50
51%{
52#include "app_sip.h"
53#include "app_sip.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */
54
55#include <string.h>
56#include <errno.h>
57
58/* Forward declaration */
59int yyparse(char * conffile);
60
61/* Parse the configuration file */
62int as_conf_handle(char * conffile)
63{
64 extern FILE * app_sipin;
65 int ret;
66
67 TRACE_ENTRY("%p", conffile);
68
69 TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
70
71 app_sipin = fopen(conffile, "r");
72 if (app_sipin == NULL) {
73 ret = errno;
74 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
75 TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
76 return ret;
77 }
78
79 ret = yyparse(conffile);
80
81 fclose(app_sipin);
82
83 if (ret != 0) {
84 TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
85 return EINVAL;
86 }
87
88 return 0;
89}
90
91/* The Lex parser prototype */
92int app_siplex(YYSTYPE *lvalp, YYLTYPE *llocp);
93
94/* Function to report the errors */
95void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
96{
97 TRACE_DEBUG(INFO, "Error in configuration parsing");
98
99 if (ploc->first_line != ploc->last_line)
100 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
101 else if (ploc->first_column != ploc->last_column)
102 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
103 else
104 fd_log_debug("%s:%d.%d : %s", conffile, ploc->first_line, ploc->first_column, s);
105}
106
107%}
108
109/* Values returned by lex for token */
110%union {
111 char *string; /* The string is allocated by strdup in lex.*/
112 int integer; /* Store integer values */
113}
114
115/* In case of error in the lexical analysis */
116%token LEX_ERROR
117
118/* Key words */
119%token MODE
120%token DATASOURCE
121%token ASMYSQL_LOGIN
122%token ASMYSQL_PASSWORD
123%token ASMYSQL_DATABASE
124%token ASMYSQL_SERVER
125%token ASMYSQL_PORT
126%token RTR_PORT
127%token PPR_PORT
128
129/* Tokens and types for routing table definition */
130/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
131%token <string> QSTRING
132
133/* An integer value */
134%token <integer> INTEGER
135
136
137
138/* -------------------------------------- */
139%%
140
141 /* The grammar definition */
142conffile: /* empty grammar is OK */
143 | conffile mode
144 | conffile datasource
145 | conffile mysql_login
146 | conffile mysql_password
147 | conffile mysql_database
148 | conffile mysql_server
149 | conffile mysql_port
150 | conffile rtr_port
151 | conffile ppr_port
152 ;
153
154mode: MODE '=' INTEGER ';'
155 {
156 as_conf->mode = $3;
157 }
158 ;
159
160datasource: DATASOURCE '=' INTEGER ';'
161 {
162 as_conf->datasource = $3;
163 }
164 ;
165
166mysql_login: ASMYSQL_LOGIN '=' QSTRING ';'
167 {
168 free(as_conf->mysql_login);
169 as_conf->mysql_login = $3;
170 }
171 ;
172
173mysql_password: ASMYSQL_PASSWORD '=' QSTRING ';'
174 {
175 free(as_conf->mysql_password);
176 as_conf->mysql_password = $3;
177 }
178 ;
179
180mysql_database: ASMYSQL_DATABASE '=' QSTRING ';'
181 {
182 free(as_conf->mysql_database);
183 as_conf->mysql_database = $3;
184 }
185 ;
186
187mysql_server: ASMYSQL_SERVER '=' QSTRING ';'
188 {
189 free(as_conf->mysql_server);
190 as_conf->mysql_server = $3;
191 }
192 ;
193
194mysql_port: ASMYSQL_PORT '=' INTEGER ';'
195 {
196 as_conf->mysql_port = (uint16_t)$3;
197 }
198 ;
199rtr_port: RTR_PORT '=' INTEGER ';'
200 {
201 as_conf->rtr_port = (uint16_t)$3;
202 }
203 ;
204ppr_port: PPR_PORT '=' INTEGER ';'
205 {
206 as_conf->ppr_port = (uint16_t)$3;
207 }
208 ;