comparison extensions/app_sip/app_sip.y @ 433:0d08a9ab2212

Corrected name mistakes on app_sip
author Alexandre Westfahl <awestfahl@freediameter.net>
date Wed, 28 Jul 2010 14:34:48 +0900
parents
children f38bff0bf3e9
comparison
equal deleted inserted replaced
432:533188d2e6cc 433:0d08a9ab2212
1 /*********************************************************************************************************
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@nict.go.jp>) *
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 */
59 int yyparse(char * conffile);
60
61 /* Parse the configuration file */
62 int 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\n", 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 */
92 int app_siplex(YYSTYPE *lvalp, YYLTYPE *llocp);
93
94 /* Function to report the errors */
95 void 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\n", 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\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
103 else
104 fd_log_debug("%s:%d.%d : %s\n", 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
127 /* Tokens and types for routing table definition */
128 /* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
129 %token <string> QSTRING
130
131 /* An integer value */
132 %token <integer> INTEGER
133
134
135
136 /* -------------------------------------- */
137 %%
138
139 /* The grammar definition */
140 conffile: /* empty grammar is OK */
141 | conffile mode
142 | conffile datasource
143 | conffile mysql_login
144 | conffile mysql_password
145 | conffile mysql_database
146 | conffile mysql_server
147 | conffile mysql_port
148 ;
149
150 mode: MODE '=' INTEGER ';'
151 {
152 as_conf->mode = $3;
153 }
154 ;
155
156 datasource: DATASOURCE '=' INTEGER ';'
157 {
158 as_conf->datasource = $3;
159 }
160 ;
161
162 mysql_login: ASMYSQL_LOGIN '=' QSTRING ';'
163 {
164 free(as_conf->mysql_login);
165 as_conf->mysql_login = $3;
166 }
167 ;
168
169 mysql_password: ASMYSQL_PASSWORD '=' QSTRING ';'
170 {
171 free(as_conf->mysql_password);
172 as_conf->mysql_password = $3;
173 }
174 ;
175
176 mysql_database: ASMYSQL_DATABASE '=' QSTRING ';'
177 {
178 free(as_conf->mysql_database);
179 as_conf->mysql_database = $3;
180 }
181 ;
182
183 mysql_server: ASMYSQL_SERVER '=' QSTRING ';'
184 {
185 free(as_conf->mysql_server);
186 as_conf->mysql_server = $3;
187 }
188 ;
189
190 mysql_port: ASMYSQL_PORT '=' INTEGER ';'
191 {
192 as_conf->mysql_port = (uint16_t)$3;
193 }
194 ;
"Welcome to our mercurial repository"