blob: e699c2861e37126aadc3881de8487aa8608cf423 [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/* For development only : */
39%debug
40%error-verbose
41
42/* The parser receives the configuration file filename as parameter */
43%parse-param {char * conffile}
44
45/* Keep track of location */
46%locations
47%pure-parser
48
49%{
50#include "test_sip.h"
51#include "test_sip.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */
52
53#include <string.h>
54#include <errno.h>
55
56/* Forward declaration */
57int yyparse(char * conffile);
58
59/* Parse the configuration file */
60int ts_conf_handle(char * conffile)
61{
62 extern FILE * test_sipin;
63 int ret;
64
65 TRACE_ENTRY("%p", conffile);
66
67 TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
68
69 test_sipin = fopen(conffile, "r");
70 if (test_sipin == NULL) {
71 ret = errno;
72 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
73 TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
74 return ret;
75 }
76
77 ret = yyparse(conffile);
78
79 fclose(test_sipin);
80
81 if (ret != 0) {
82 TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
83 return EINVAL;
84 }
85
86 return 0;
87}
88
89/* The Lex parser prototype */
90int test_sipflex(YYSTYPE *lvalp, YYLTYPE *llocp);
91
92/* Function to report the errors */
93void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
94{
95 TRACE_DEBUG(INFO, "Error in configuration parsing");
96
97 if (ploc->first_line != ploc->last_line)
98 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
99 else if (ploc->first_column != ploc->last_column)
100 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
101 else
102 fd_log_debug("%s:%d.%d : %s", conffile, ploc->first_line, ploc->first_column, s);
103}
104
105%}
106
107/* Values returned by lex for token */
108%union {
109 char *string; /* The string is allocated by strdup in lex.*/
110 int integer; /* Store integer values */
111}
112
113/* In case of error in the lexical analysis */
114%token LEX_ERROR
115
116/* Key words */
117%token TESTSIP_DESTREALM
118%token TESTSIP_DESTSIP
119%token TESTSIP_PASSWORD
120%token TESTSIP_SIPAOR
121%token TESTSIP_USERNAME
122
123/* Tokens and types for routing table definition */
124/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
125%token <string> QSTRING
126
127/* An integer value */
128%token <integer> INTEGER
129
130/* -------------------------------------- */
131%%
132
133 /* The grammar definition */
134conffile: /* empty grammar is OK */
135 | conffile destination_realm
136 | conffile destination_sip
137 | conffile username
138 | conffile password
139 | conffile sip_aor
140 ;
141
142destination_realm: TESTSIP_DESTREALM '=' QSTRING ';'
143 {
144 free(ts_conf->destination_realm);
145 ts_conf->destination_realm = $3;
146 }
147 ;
148
149destination_sip: TESTSIP_DESTSIP '=' QSTRING ';'
150 {
151 free(ts_conf->destination_sip);
152 ts_conf->destination_sip = $3;
153 }
154 ;
155
156username: TESTSIP_USERNAME '=' QSTRING ';'
157 {
158 free(ts_conf->username);
159 ts_conf->username = $3;
160 }
161 ;
162
163password: TESTSIP_PASSWORD '=' QSTRING ';'
164 {
165 free(ts_conf->password);
166 ts_conf->password = $3;
167 }
168 ;
169
170sip_aor: TESTSIP_SIPAOR '=' QSTRING ';'
171 {
172 free(ts_conf->sip_aor);
173 ts_conf->sip_aor = $3;
174 }
175 ;