Mercurial > hg > freeDiameter
comparison extensions/rt_ereg/rtereg_conf.y @ 1387:d70f5f6cb306
rt_ereg: improve logging and locking
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Tue, 15 Oct 2019 16:25:47 +0200 |
parents | fedc9eea70bc |
children | 566bb46cc73f |
comparison
equal
deleted
inserted
replaced
1386:6e4737d332e7 | 1387:d70f5f6cb306 |
---|---|
59 int rtereg_conf_handle(char * conffile) | 59 int rtereg_conf_handle(char * conffile) |
60 { | 60 { |
61 extern FILE * rtereg_confin; | 61 extern FILE * rtereg_confin; |
62 int ret; | 62 int ret; |
63 | 63 |
64 TRACE_ENTRY("%p", conffile); | 64 LOG_D("[rt_ereg] parsing configuration file '%s'", conffile); |
65 | |
66 TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile); | |
67 | 65 |
68 rtereg_confin = fopen(conffile, "r"); | 66 rtereg_confin = fopen(conffile, "r"); |
69 if (rtereg_confin == NULL) { | 67 if (rtereg_confin == NULL) { |
70 ret = errno; | 68 ret = errno; |
71 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret)); | 69 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret)); |
72 TRACE_DEBUG (INFO, "rt_ereg: error occurred, message logged -- configuration file."); | 70 LOG_E("[rt_ereg] error occurred, message logged -- configuration file."); |
73 return ret; | 71 return ret; |
74 } | 72 } |
75 | 73 |
76 rtereg_confrestart(rtereg_confin); | 74 rtereg_confrestart(rtereg_confin); |
77 ret = yyparse(conffile); | 75 ret = yyparse(conffile); |
78 | 76 |
79 fclose(rtereg_confin); | 77 fclose(rtereg_confin); |
80 | 78 |
81 if (rtereg_conf[rtereg_conf_size-1].finished == 0) { | 79 if (rtereg_conf[rtereg_conf_size-1].finished == 0) { |
82 TRACE_DEBUG(INFO, "rt_ereg: configuration invalid, AVP ended without OCTETSTRING AVP"); | 80 LOG_E("[rt_ereg] configuration invalid, AVP ended without OCTETSTRING AVP"); |
83 return EINVAL; | 81 return EINVAL; |
84 } | 82 } |
85 | 83 |
86 if (ret != 0) { | 84 if (ret != 0) { |
87 TRACE_DEBUG(INFO, "rt_ereg: unable to parse the configuration file."); | 85 LOG_E("[rt_ereg] unable to parse the configuration file."); |
88 return EINVAL; | 86 return EINVAL; |
89 } else { | 87 } else { |
90 int i, sum = 0; | 88 int i, sum = 0; |
91 for (i=0; i<rtereg_conf_size; i++) { | 89 for (i=0; i<rtereg_conf_size; i++) { |
92 sum += rtereg_conf[i].rules_nb; | 90 sum += rtereg_conf[i].rules_nb; |
93 } | 91 } |
94 TRACE_DEBUG(FULL, "[rt-ereg] Added %d rules successfully.", sum); | 92 LOG_D("[rt-ereg] Added %d rules successfully.", sum); |
95 } | 93 } |
96 | 94 |
97 return 0; | 95 return 0; |
98 } | 96 } |
99 | 97 |
102 void *ret; | 100 void *ret; |
103 int level; | 101 int level; |
104 | 102 |
105 if (rtereg_conf[rtereg_conf_size-1].finished) { | 103 if (rtereg_conf[rtereg_conf_size-1].finished) { |
106 if ((ret = realloc(rtereg_conf, sizeof(*rtereg_conf)*(rtereg_conf_size+1))) == NULL) { | 104 if ((ret = realloc(rtereg_conf, sizeof(*rtereg_conf)*(rtereg_conf_size+1))) == NULL) { |
107 TRACE_DEBUG(INFO, "rt_ereg: realloc failed"); | 105 LOG_E("[rt_ereg] realloc failed"); |
108 return -1; | 106 return -1; |
109 } | 107 } |
110 rtereg_conf_size++; | 108 rtereg_conf_size++; |
111 rtereg_conf = ret; | 109 rtereg_conf = ret; |
112 memset(&rtereg_conf[rtereg_conf_size-1], 0, sizeof(*rtereg_conf)); | 110 memset(&rtereg_conf[rtereg_conf_size-1], 0, sizeof(*rtereg_conf)); |
113 TRACE_DEBUG(INFO, "rt_ereg: New AVP group found starting with %s", name); | 111 LOG_D("[rt_ereg] New AVP group found starting with %s", name); |
114 } | 112 } |
115 level = rtereg_conf[rtereg_conf_size-1].level + 1; | 113 level = rtereg_conf[rtereg_conf_size-1].level + 1; |
116 | 114 |
117 if ((ret = realloc(rtereg_conf[rtereg_conf_size-1].avps, sizeof(*rtereg_conf[rtereg_conf_size-1].avps)*level)) == NULL) { | 115 if ((ret = realloc(rtereg_conf[rtereg_conf_size-1].avps, sizeof(*rtereg_conf[rtereg_conf_size-1].avps)*level)) == NULL) { |
118 TRACE_DEBUG(INFO, "rt_ereg: realloc failed"); | 116 LOG_E("[rt_ereg] realloc failed"); |
119 return -1; | 117 return -1; |
120 } | 118 } |
121 rtereg_conf[rtereg_conf_size-1].avps = ret; | 119 rtereg_conf[rtereg_conf_size-1].avps = ret; |
122 | 120 |
123 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 ), | 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 ), |
124 { | 122 { |
125 TRACE_DEBUG(INFO, "rt_ereg: Unable to find '%s' AVP in the loaded dictionaries.", name); | 123 LOG_E("[rt_ereg] Unable to find '%s' AVP in the loaded dictionaries.", name); |
126 return -1; | 124 return -1; |
127 } ); | 125 } ); |
128 | 126 |
129 /* Now check the type */ | 127 /* Now check the type */ |
130 { | 128 { |
131 struct dict_avp_data data; | 129 struct dict_avp_data data; |
132 CHECK_FCT( fd_dict_getval( rtereg_conf[rtereg_conf_size-1].avps[level-1], &data) ); | 130 CHECK_FCT( fd_dict_getval( rtereg_conf[rtereg_conf_size-1].avps[level-1], &data) ); |
133 if (data.avp_basetype == AVP_TYPE_OCTETSTRING) { | 131 if (data.avp_basetype == AVP_TYPE_OCTETSTRING) { |
134 rtereg_conf[rtereg_conf_size-1].finished = 1; | 132 rtereg_conf[rtereg_conf_size-1].finished = 1; |
135 } else if (data.avp_basetype != AVP_TYPE_GROUPED) { | 133 } else if (data.avp_basetype != AVP_TYPE_GROUPED) { |
136 TRACE_DEBUG(INFO, "rt_ereg: '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype); | 134 LOG_E("[rt_ereg] '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype); |
137 return -1; | 135 return -1; |
138 } | 136 } |
139 } | 137 } |
140 rtereg_conf[rtereg_conf_size-1].level = level; | 138 rtereg_conf[rtereg_conf_size-1].level = level; |
141 return 0; | 139 return 0; |
145 int rtereg_conflex(YYSTYPE *lvalp, YYLTYPE *llocp); | 143 int rtereg_conflex(YYSTYPE *lvalp, YYLTYPE *llocp); |
146 | 144 |
147 /* Function to report the errors */ | 145 /* Function to report the errors */ |
148 void yyerror (YYLTYPE *ploc, char * conffile, char const *s) | 146 void yyerror (YYLTYPE *ploc, char * conffile, char const *s) |
149 { | 147 { |
150 TRACE_DEBUG(INFO, "rt_ereg: error in configuration parsing"); | 148 LOG_E("[rt_ereg] error in configuration parsing"); |
151 | 149 |
152 if (ploc->first_line != ploc->last_line) | 150 if (ploc->first_line != ploc->last_line) |
153 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); | 151 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); |
154 else if (ploc->first_column != ploc->last_column) | 152 else if (ploc->first_column != ploc->last_column) |
155 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s); | 153 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s); |
220 { | 218 { |
221 char * buf; | 219 char * buf; |
222 size_t bl; | 220 size_t bl; |
223 | 221 |
224 /* Error while compiling the regex */ | 222 /* Error while compiling the regex */ |
225 TRACE_DEBUG(INFO, "rt_ereg: error while compiling the regular expression '%s':", new->pattern); | 223 LOG_E("[rt_ereg] error while compiling the regular expression '%s':", new->pattern); |
226 | 224 |
227 /* Get the error message size */ | 225 /* Get the error message size */ |
228 bl = regerror(err, &new->preg, NULL, 0); | 226 bl = regerror(err, &new->preg, NULL, 0); |
229 | 227 |
230 /* Alloc the buffer for error message */ | 228 /* Alloc the buffer for error message */ |
231 CHECK_MALLOC( buf = malloc(bl) ); | 229 CHECK_MALLOC( buf = malloc(bl) ); |
232 | 230 |
233 /* Get the error message content */ | 231 /* Get the error message content */ |
234 regerror(err, &new->preg, buf, bl); | 232 regerror(err, &new->preg, buf, bl); |
235 TRACE_DEBUG(INFO, "\t%s", buf); | 233 LOG_E("\t%s", buf); |
236 | 234 |
237 /* Free the buffer, return the error */ | 235 /* Free the buffer, return the error */ |
238 free(buf); | 236 free(buf); |
239 | 237 |
240 yyerror (&yylloc, conffile, "Invalid regular expression."); | 238 yyerror (&yylloc, conffile, "Invalid regular expression."); |