Debian Codegraph @

lib/freeDiameter-1.2.1/extensions/acl_wl/aw_conf.y

raw
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Sebastien Decugis <[email protected]> *
4 * *
5 * Copyright (c) 2013, 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 extension's configuration parser.
37 * See doc/acl_wl.conf.sample for configuration file format
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 "acl_wl.h"
53 #include "aw_conf.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 static int fqdn_added = 0;
62
63 /* Parse the configuration file */
64 int aw_conf_handle(char * conffile)
65 {
66 extern FILE * aw_confin;
67 int ret;
68
69 TRACE_ENTRY("%p", conffile);
70
71 TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
72
73 aw_confin = fopen(conffile, "r");
74 if (aw_confin == NULL) {
75 ret = errno;
76 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
77 TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
78 return ret;
79 }
80
81 ret = yyparse(conffile);
82
83 fclose(aw_confin);
84
85 if (ret != 0) {
86 TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
87 return EINVAL;
88 } else {
89 TRACE_DEBUG(FULL, "Read %d FQDN entries successfully.", fqdn_added);
90 }
91
92 return 0;
93 }
94
95 /* The Lex parser prototype */
96 int aw_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
97
98 /* Function to report the errors */
99 void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
100 {
101 TRACE_DEBUG(INFO, "Error in configuration parsing");
102
103 if (ploc->first_line != ploc->last_line)
104 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
105 else if (ploc->first_column != ploc->last_column)
106 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
107 else
108 fd_log_debug("%s:%d.%d : %s", conffile, ploc->first_line, ploc->first_column, s);
109 }
110
111 %}
112
113 /* Values returned by lex for token */
114 %union {
115 char *string;
116 }
117
118 /* In case of error in the lexical analysis */
119 %token LEX_ERROR
120
121 /* Key words */
122 %token <string> FQDN
123
124
125 /* -------------------------------------- */
126 %%
127
128 /* The grammar definition */
129 conffile: /* empty grammar is OK */
130 | conffile FQDN
131 {
132 fqdn_added++;
133 TRACE_DEBUG(FULL, "Added FQDN: %s", $2);
134 }
135 | conffile LEX_ERROR
136 {
137 yyerror(&yylloc, conffile, "An error occurred while parsing the configuration file");
138 return EINVAL;
139 }
140 ;
141