annotate extensions/rt_ereg/rtereg_conf.y @ 1554:566bb46cc73f

Updated copyright information
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 06 Oct 2020 21:34:53 +0800
parents d70f5f6cb306
children
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 * *
1554
566bb46cc73f Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1387
diff changeset
5 * Copyright (c) 2019, 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
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
64 LOG_D("[rt_ereg] 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
65
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 rtereg_confin = fopen(conffile, "r");
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 if (rtereg_confin == NULL) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 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
69 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
70 LOG_E("[rt_ereg] error occurred, message logged -- configuration file.");
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 return ret;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
74 rtereg_confrestart(rtereg_confin);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 ret = yyparse(conffile);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 fclose(rtereg_confin);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
79 if (rtereg_conf[rtereg_conf_size-1].finished == 0) {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
80 LOG_E("[rt_ereg] configuration invalid, AVP ended without OCTETSTRING AVP");
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 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
82 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
83
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 if (ret != 0) {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
85 LOG_E("[rt_ereg] unable to parse the configuration file.");
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 return EINVAL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 } 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
88 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
89 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
90 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
91 }
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
92 LOG_D("[rt-ereg] Added %d rules successfully.", sum);
1338
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
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
95 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
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
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
98 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
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 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
101 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
102
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
103 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
104 if ((ret = realloc(rtereg_conf, sizeof(*rtereg_conf)*(rtereg_conf_size+1))) == NULL) {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
105 LOG_E("[rt_ereg] realloc failed");
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
106 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
107 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
108 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
109 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
110 memset(&rtereg_conf[rtereg_conf_size-1], 0, sizeof(*rtereg_conf));
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
111 LOG_D("[rt_ereg] New AVP group found starting with %s", name);
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 }
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
113 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
114
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
115 if ((ret = realloc(rtereg_conf[rtereg_conf_size-1].avps, sizeof(*rtereg_conf[rtereg_conf_size-1].avps)*level)) == NULL) {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
116 LOG_E("[rt_ereg] realloc failed");
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
117 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
118 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
119 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
120
1342
fedc9eea70bc rt_ereg: allow AVPs from all vendors
Thomas Klausner <tk@giga.or.at>
parents: 1338
diff changeset
121 CHECK_FCT_DO( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_ALL_VENDORS, name, &rtereg_conf[rtereg_conf_size-1].avps[level-1], ENOENT ),
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
122 {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
123 LOG_E("[rt_ereg] Unable to find '%s' AVP in the loaded dictionaries.", name);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
124 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
125 } );
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
126
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
127 /* 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
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 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
130 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
131 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
132 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
133 } else if (data.avp_basetype != AVP_TYPE_GROUPED) {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
134 LOG_E("[rt_ereg] '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype);
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
135 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
136 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
137 }
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
138 rtereg_conf[rtereg_conf_size-1].level = level;
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 return 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 /* The Lex parser prototype */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 int rtereg_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 /* Function to report the errors */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147 {
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
148 LOG_E("[rt_ereg] error in configuration parsing");
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
149
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 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
151 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
152 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
153 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
154 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
155 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
156 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157
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 /* Values returned by lex for token */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 %union {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 char *string; /* The string is allocated by strdup in lex.*/
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 int integer;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 /* In case of error in the lexical analysis */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 %token LEX_ERROR
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 /* 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
170 %token <string> QSTRING
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 %token <integer> INTEGER
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 /* Tokens */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174 %token AVP
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176
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 /* 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
181 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
182 | conffile avp rules
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 ;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
184
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 /* 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
186 avp: AVP '=' avp_part ';'
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 ;
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
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
189 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
190 | 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
191 ;
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
192
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 rules: /* empty OK */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 | rules rule
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 ;
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
196
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 rule: QSTRING ':' QSTRING '+' '=' INTEGER ';'
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 struct rtereg_rule * new;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 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
201
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 /* 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
203 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
204 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
205 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 yyerror (&yylloc, conffile, "Not enough memory to store the configuration...");
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 YYERROR;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 } );
1338
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
209
f1b65381c1e7 rt_ereg: Support config reload. Support grouped AVPs. Support multiple separate AVPs.
Thomas Klausner <tk@giga.or.at>
parents: 1127
diff changeset
210 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
211
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 new->pattern = $1;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 new->server = $3;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214 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
215
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216 /* Attempt to compile the regex */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 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
218 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 char * buf;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220 size_t bl;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 /* Error while compiling the regex */
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
223 LOG_E("[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
224
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 /* Get the error message size */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 bl = regerror(err, &new->preg, NULL, 0);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 /* Alloc the buffer for error message */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229 CHECK_MALLOC( buf = malloc(bl) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 /* Get the error message content */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232 regerror(err, &new->preg, buf, bl);
1387
d70f5f6cb306 rt_ereg: improve logging and locking
Thomas Klausner <tk@giga.or.at>
parents: 1342
diff changeset
233 LOG_E("\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
234
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235 /* Free the buffer, return the error */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236 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
237
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
238 yyerror (&yylloc, conffile, "Invalid regular expression.");
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
239 YYERROR;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
240 } );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
242 ;
"Welcome to our mercurial repository"