Mercurial > hg > freeDiameter
comparison freeDiameter/fdd.y @ 8:3e143f047f78
Backup for the week-end
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Fri, 18 Sep 2009 18:54:07 +0900 |
parents | |
children | c5c99c73c2bf |
comparison
equal
deleted
inserted
replaced
7:e5af94b04946 | 8:3e143f047f78 |
---|---|
1 /********************************************************************************************************* | |
2 * Software License Agreement (BSD License) * | |
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * | |
4 * * | |
5 * Copyright (c) 2009, WIDE Project and NICT * | |
6 * All rights reserved. * | |
7 * * | |
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * | |
9 * permitted provided that the following conditions are met: * | |
10 * * | |
11 * * Redistributions of source code must retain the above * | |
12 * copyright notice, this list of conditions and the * | |
13 * following disclaimer. * | |
14 * * | |
15 * * Redistributions in binary form must reproduce the above * | |
16 * copyright notice, this list of conditions and the * | |
17 * following disclaimer in the documentation and/or other * | |
18 * materials provided with the distribution. * | |
19 * * | |
20 * * Neither the name of the WIDE Project or NICT nor the * | |
21 * names of its contributors may be used to endorse or * | |
22 * promote products derived from this software without * | |
23 * specific prior written permission of WIDE Project and * | |
24 * NICT. * | |
25 * * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * | |
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * | |
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * | |
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * | |
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * | |
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * | |
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * | |
34 *********************************************************************************************************/ | |
35 | |
36 /* Yacc configuration parser. | |
37 * | |
38 * This file defines the grammar of the configuration file. | |
39 * Note that each extension has a separate independant configuration file. | |
40 * | |
41 * Note : This module is NOT thread-safe. All processing must be done from one thread only. | |
42 */ | |
43 | |
44 /* For development only : */ | |
45 %debug | |
46 %error-verbose | |
47 | |
48 %parse-param {struct fd_config * conf} | |
49 | |
50 /* Keep track of location */ | |
51 %locations | |
52 %pure-parser | |
53 | |
54 %{ | |
55 #include "fD.h" | |
56 #include "fdd.tab.h" /* bug : bison does not define the YYLTYPE before including this bloc, so... */ | |
57 | |
58 /* The Lex parser prototype */ | |
59 int fddlex(YYSTYPE *lvalp, YYLTYPE *llocp); | |
60 | |
61 /* Function to report error */ | |
62 void yyerror (YYLTYPE *ploc, struct fd_config * conf, char const *s) | |
63 { | |
64 if (ploc->first_line != ploc->last_line) | |
65 fprintf(stderr, "%s:%d.%d-%d.%d : %s\n", conf->conf_file, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); | |
66 else if (ploc->first_column != ploc->last_column) | |
67 fprintf(stderr, "%s:%d.%d-%d : %s\n", conf->conf_file, ploc->first_line, ploc->first_column, ploc->last_column, s); | |
68 else | |
69 fprintf(stderr, "%s:%d.%d : %s\n", conf->conf_file, ploc->first_line, ploc->first_column, s); | |
70 } | |
71 | |
72 %} | |
73 | |
74 /* Values returned by lex for token */ | |
75 %union { | |
76 char *string; /* The string is allocated by strdup in lex.*/ | |
77 int integer; /* Store integer values */ | |
78 } | |
79 | |
80 /* In case of error in the lexical analysis */ | |
81 %token LEX_ERROR | |
82 | |
83 %token <string> QSTRING | |
84 %token <integer> INTEGER | |
85 | |
86 %type <string> extconf | |
87 | |
88 %token LOCALIDENTITY | |
89 %token LOCALREALM | |
90 %token LOCALPORT | |
91 %token LOCALSECPORT | |
92 %token NOIP | |
93 %token NOIP6 | |
94 %token NOTCP | |
95 %token NOSCTP | |
96 %token PREFERTCP | |
97 %token OLDTLS | |
98 %token SCTPSTREAMS | |
99 %token LISTENON | |
100 %token TCTIMER | |
101 %token TWTIMER | |
102 %token NORELAY | |
103 %token LOADEXT | |
104 | |
105 | |
106 /* -------------------------------------- */ | |
107 %% | |
108 | |
109 /* The grammar definition - Sections blocs. */ | |
110 conffile: /* Empty is OK */ | |
111 | conffile localidentity | |
112 | conffile localrealm | |
113 | conffile localport | |
114 | conffile localsecport | |
115 | conffile noip | |
116 | conffile noip6 | |
117 | conffile notcp | |
118 | conffile nosctp | |
119 | conffile prefertcp | |
120 | conffile oldtls | |
121 | conffile sctpstreams | |
122 | conffile listenon | |
123 | conffile tctimer | |
124 | conffile twtimer | |
125 | conffile norelay | |
126 | conffile loadext | |
127 ; | |
128 | |
129 localidentity: LOCALIDENTITY '=' QSTRING ';' | |
130 { | |
131 conf->diam_id = $3; | |
132 } | |
133 ; | |
134 | |
135 localrealm: LOCALREALM '=' QSTRING ';' | |
136 { | |
137 conf->diam_realm = $3; | |
138 } | |
139 ; | |
140 | |
141 localport: LOCALPORT '=' INTEGER ';' | |
142 { | |
143 CHECK_PARAMS_DO( ($3 > 0) && ($3 < 1<<16), | |
144 { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } ); | |
145 conf->loc_port = (uint16_t)$3; | |
146 } | |
147 ; | |
148 | |
149 localsecport: LOCALSECPORT '=' INTEGER ';' | |
150 { | |
151 CHECK_PARAMS_DO( ($3 > 0) && ($3 < 1<<16), | |
152 { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } ); | |
153 conf->loc_port_tls = (uint16_t)$3; | |
154 } | |
155 ; | |
156 | |
157 noip: NOIP ';' | |
158 { | |
159 conf->flags.no_ip4 = 1; | |
160 } | |
161 ; | |
162 | |
163 noip6: NOIP6 ';' | |
164 { | |
165 conf->flags.no_ip6 = 1; | |
166 } | |
167 ; | |
168 | |
169 notcp: NOTCP ';' | |
170 { | |
171 conf->flags.no_tcp = 1; | |
172 } | |
173 ; | |
174 | |
175 nosctp: NOSCTP ';' | |
176 { | |
177 conf->flags.no_sctp = 1; | |
178 } | |
179 ; | |
180 | |
181 prefertcp: PREFERTCP ';' | |
182 { | |
183 conf->flags.pr_tcp = 1; | |
184 } | |
185 ; | |
186 | |
187 oldtls: OLDTLS ';' | |
188 { | |
189 conf->flags.tls_alg = 1; | |
190 } | |
191 ; | |
192 | |
193 sctpstreams: SCTPSTREAMS '=' INTEGER ';' | |
194 { | |
195 CHECK_PARAMS_DO( ($3 > 0) && ($3 < 1<<16), | |
196 { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } ); | |
197 conf->loc_sctp_str = (uint16_t)$3; | |
198 } | |
199 ; | |
200 | |
201 listenon: LISTENON '=' QSTRING ';' | |
202 { | |
203 struct fd_endpoint * ep; | |
204 struct addrinfo hints, *ai; | |
205 int ret; | |
206 | |
207 CHECK_MALLOC_DO( ep = malloc(sizeof(struct fd_endpoint)), | |
208 { yyerror (&yylloc, conf, "Out of memory"); YYERROR; } ); | |
209 memset(ep, 0, sizeof(struct fd_endpoint)); | |
210 fd_list_init(&ep->chain, NULL); | |
211 | |
212 memset(&hints, 0, sizeof(hints)); | |
213 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; | |
214 ret = getaddrinfo($3, NULL, &hints, &ai); | |
215 if (ret) { yyerror (&yylloc, conf, gai_strerror(ret)); YYERROR; } | |
216 | |
217 memcpy(&ep->ss, ai->ai_addr, ai->ai_addrlen); | |
218 free($3); | |
219 freeaddrinfo(ai); | |
220 fd_list_insert_before(&conf->loc_endpoints, &ep->chain); | |
221 } | |
222 ; | |
223 | |
224 tctimer: TCTIMER '=' INTEGER ';' | |
225 { | |
226 CHECK_PARAMS_DO( ($3 > 0), | |
227 { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } ); | |
228 conf->timer_tc = (unsigned int)$3; | |
229 } | |
230 ; | |
231 | |
232 twtimer: TWTIMER '=' INTEGER ';' | |
233 { | |
234 CHECK_PARAMS_DO( ($3 > 5), | |
235 { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } ); | |
236 conf->timer_tw = (unsigned int)$3; | |
237 } | |
238 ; | |
239 | |
240 norelay: NORELAY ';' | |
241 { | |
242 conf->flags.no_fwd = 1; | |
243 } | |
244 ; | |
245 | |
246 loadext: LOADEXT '=' QSTRING extconf ';' | |
247 { | |
248 CHECK_FCT_DO( fd_ext_add( $3, $4 ), | |
249 { yyerror (&yylloc, conf, "Error adding extension"); YYERROR; } ); | |
250 } | |
251 ; | |
252 | |
253 extconf: /* empty */ | |
254 { | |
255 $$ = NULL; | |
256 } | |
257 | ':' QSTRING | |
258 { | |
259 $$ = $2; | |
260 } | |
261 ; |