annotate extensions/rt_ereg/rtereg_conf.y @ 1338:f1b65381c1e7

rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs. Written for Effortel Technologies SA, published with their consent.
author Thomas Klausner <tk@giga.or.at>
date Tue, 09 Apr 2019 15:48:45 +0200
parents 1af09cc156d6
children fedc9eea70bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 525
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1127
1af09cc156d6 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* Yacc extension's configuration parser.
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 /* For development only : */
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
40 %debug
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 %error-verbose
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 /* The parser receives the configuration file filename as parameter */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 %parse-param {char * conffile}
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 /* Keep track of location */
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
47 %locations
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 %pure-parser
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 %{
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 #include "rtereg.h"
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 #include "rtereg_conf.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 /* Forward declaration */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 int yyparse(char * conffile);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
56 void rtereg_confrestart(FILE *input_file);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 /* Parse the configuration file */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 int rtereg_conf_handle(char * conffile)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 extern FILE * rtereg_confin;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 int ret;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
63
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 TRACE_ENTRY("%p", conffile);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
65
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
67
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 rtereg_confin = fopen(conffile, "r");
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 if (rtereg_confin == NULL) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 ret = errno;
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 741
diff changeset
71 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
72 TRACE_DEBUG (INFO, "rt_ereg: error occurred, message logged -- configuration file.");
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 return ret;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
76 rtereg_confrestart(rtereg_confin);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 ret = yyparse(conffile);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 fclose(rtereg_confin);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
81 if (rtereg_conf[rtereg_conf_size-1].finished == 0) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
82 TRACE_DEBUG(INFO, "rt_ereg: configuration invalid, AVP ended without OCTETSTRING AVP");
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
83 return EINVAL;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
84 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
85
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 if (ret != 0) {
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
87 TRACE_DEBUG(INFO, "rt_ereg: unable to parse the configuration file.");
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 return EINVAL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 } else {
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
90 int i, sum = 0;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
91 for (i=0; i<rtereg_conf_size; i++) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
92 sum += rtereg_conf[i].rules_nb;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
93 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
94 TRACE_DEBUG(FULL, "[rt-ereg] Added %d rules successfully.", sum);
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
95 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
96
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
97 return 0;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
98 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
99
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
100 int avp_add(const char *name)
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
101 {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
102 void *ret;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
103 int level;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
104
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
105 if (rtereg_conf[rtereg_conf_size-1].finished) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
106 if ((ret = realloc(rtereg_conf, sizeof(*rtereg_conf)*(rtereg_conf_size+1))) == NULL) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
107 TRACE_DEBUG(INFO, "rt_ereg: realloc failed");
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
108 return -1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
109 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
110 rtereg_conf_size++;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
111 rtereg_conf = ret;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
112 memset(&rtereg_conf[rtereg_conf_size-1], 0, sizeof(*rtereg_conf));
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
113 TRACE_DEBUG(INFO, "rt_ereg: New AVP group found starting with %s", name);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 }
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
115 level = rtereg_conf[rtereg_conf_size-1].level + 1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
116
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
117 if ((ret = realloc(rtereg_conf[rtereg_conf_size-1].avps, sizeof(*rtereg_conf[rtereg_conf_size-1].avps)*level)) == NULL) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
118 TRACE_DEBUG(INFO, "rt_ereg: realloc failed");
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
119 return -1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
120 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
121 rtereg_conf[rtereg_conf_size-1].avps = ret;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
122
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
123 CHECK_FCT_DO( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, name, &rtereg_conf[rtereg_conf_size-1].avps[level-1], ENOENT ),
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
124 {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
125 TRACE_DEBUG(INFO, "rt_ereg: Unable to find '%s' AVP in the loaded dictionaries.", name);
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
126 return -1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
127 } );
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
128
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
129 /* Now check the type */
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
130 {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
131 struct dict_avp_data data;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
132 CHECK_FCT( fd_dict_getval( rtereg_conf[rtereg_conf_size-1].avps[level-1], &data) );
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
133 if (data.avp_basetype == AVP_TYPE_OCTETSTRING) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
134 rtereg_conf[rtereg_conf_size-1].finished = 1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
135 } else if (data.avp_basetype != AVP_TYPE_GROUPED) {
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
136 TRACE_DEBUG(INFO, "rt_ereg: '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype);
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
137 return -1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
138 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
139 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
140 rtereg_conf[rtereg_conf_size-1].level = level;
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 return 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 /* The Lex parser prototype */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 int rtereg_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147 /* Function to report the errors */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 {
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
150 TRACE_DEBUG(INFO, "rt_ereg: error in configuration parsing");
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
151
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152 if (ploc->first_line != ploc->last_line)
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 741
diff changeset
153 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 else if (ploc->first_column != ploc->last_column)
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 741
diff changeset
155 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156 else
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 741
diff changeset
157 fd_log_debug("%s:%d.%d : %s", conffile, ploc->first_line, ploc->first_column, s);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 %}
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 /* Values returned by lex for token */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 %union {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 char *string; /* The string is allocated by strdup in lex.*/
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 int integer;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 /* In case of error in the lexical analysis */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 %token LEX_ERROR
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 /* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 %token <string> QSTRING
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 %token <integer> INTEGER
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175 /* Tokens */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 %token AVP
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 /* -------------------------------------- */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 %%
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 /* The grammar definition */
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
183 conffile: avp rules
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
184 | conffile avp rules
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 ;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
186
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 /* a server entry */
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
188 avp: AVP '=' avp_part ';'
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 ;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
190
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
191 avp_part: avp_part ':' QSTRING { if (avp_add($3) < 0) { YYERROR; } }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
192 | QSTRING { if (avp_add($1) < 0) { YYERROR; } }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
193 ;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
194
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 rules: /* empty OK */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 | rules rule
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 ;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
198
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 rule: QSTRING ':' QSTRING '+' '=' INTEGER ';'
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 struct rtereg_rule * new;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 int err;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
203
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
204 /* Add new rule in the array */
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
205 rtereg_conf[rtereg_conf_size-1].rules_nb += 1;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
206 CHECK_MALLOC_DO(rtereg_conf[rtereg_conf_size-1].rules = realloc(rtereg_conf[rtereg_conf_size-1].rules, rtereg_conf[rtereg_conf_size-1].rules_nb * sizeof(struct rtereg_rule)),
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 yyerror (&yylloc, conffile, "Not enough memory to store the configuration...");
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 YYERROR;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 } );
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
211
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
212 new = &rtereg_conf[rtereg_conf_size-1].rules[rtereg_conf[rtereg_conf_size-1].rules_nb - 1];
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
213
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214 new->pattern = $1;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 new->server = $3;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216 new->score = $6;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
217
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218 /* Attempt to compile the regex */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 CHECK_FCT_DO( err=regcomp(&new->preg, new->pattern, REG_EXTENDED | REG_NOSUB),
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 char * buf;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 size_t bl;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 /* Error while compiling the regex */
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
225 TRACE_DEBUG(INFO, "rt_ereg: error while compiling the regular expression '%s':", new->pattern);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 /* Get the error message size */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 bl = regerror(err, &new->preg, NULL, 0);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230 /* Alloc the buffer for error message */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 CHECK_MALLOC( buf = malloc(bl) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 /* Get the error message content */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234 regerror(err, &new->preg, buf, bl);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235 TRACE_DEBUG(INFO, "\t%s", buf);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
236
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237 /* Free the buffer, return the error */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
238 free(buf);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
239
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
240 yyerror (&yylloc, conffile, "Invalid regular expression.");
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241 YYERROR;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
242 } );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
243 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
244 ;
"Welcome to our mercurial repository"