- all ser generic fixups (fixup_var_{int,str}_*) work with pvars
(e.g. the fallback order for str is: pvar->avp->select->str).
- fixed FPARAM_* definitions to allow better fallback for
fix_param_types (int->select->pvar->avp->str)
- fix_param() does not print anymore error messages for invalid
pvars or avps, to allow fallback
... | ... |
@@ -54,6 +54,7 @@ |
54 | 54 |
#include "trim.h" |
55 | 55 |
#include "globals.h" |
56 | 56 |
#include "rpc_lookup.h" |
57 |
+#include "sr_compat.h" |
|
57 | 58 |
|
58 | 59 |
#include <sys/stat.h> |
59 | 60 |
#include <regex.h> |
... | ... |
@@ -1052,7 +1053,7 @@ int fix_param(int type, void** param) |
1052 | 1053 |
goto error; |
1053 | 1054 |
case FPARAM_STRING: |
1054 | 1055 |
p->v.asciiz = *param; |
1055 |
- |
|
1056 |
+ /* no break */ |
|
1056 | 1057 |
case FPARAM_STR: |
1057 | 1058 |
p->v.str.s = (char*)*param; |
1058 | 1059 |
p->v.str.len = strlen(p->v.str.s); |
... | ... |
@@ -1080,8 +1081,8 @@ int fix_param(int type, void** param) |
1080 | 1081 |
REG_EXTENDED|REG_ICASE|REG_NEWLINE)) { |
1081 | 1082 |
pkg_free(p->v.regex); |
1082 | 1083 |
p->v.regex=0; |
1083 |
- ERR("Bad regular expression '%s'\n", (char*)*param); |
|
1084 |
- goto error; |
|
1084 |
+ /* not a valid regex */ |
|
1085 |
+ goto no_match; |
|
1085 | 1086 |
} |
1086 | 1087 |
p->fixed = p->v.regex; |
1087 | 1088 |
break; |
... | ... |
@@ -1091,14 +1092,13 @@ int fix_param(int type, void** param) |
1091 | 1092 |
trim(&name); |
1092 | 1093 |
if (!name.len || name.s[0] != '$') { |
1093 | 1094 |
/* Not an AVP identifier */ |
1094 |
- pkg_free(p); |
|
1095 |
- return 1; |
|
1095 |
+ goto no_match; |
|
1096 | 1096 |
} |
1097 | 1097 |
name.s++; |
1098 | 1098 |
name.len--; |
1099 | 1099 |
if (parse_avp_ident(&name, &p->v.avp) < 0) { |
1100 |
- ERR("Error while parsing attribute name\n"); |
|
1101 |
- goto error; |
|
1100 |
+ /* invalid avp identifier (=> no match) */ |
|
1101 |
+ goto no_match; |
|
1102 | 1102 |
} |
1103 | 1103 |
p->fixed = &p->v; |
1104 | 1104 |
break; |
... | ... |
@@ -1108,8 +1108,7 @@ int fix_param(int type, void** param) |
1108 | 1108 |
trim(&name); |
1109 | 1109 |
if (!name.len || name.s[0] != '@') { |
1110 | 1110 |
/* Not a select identifier */ |
1111 |
- pkg_free(p); |
|
1112 |
- return 1; |
|
1111 |
+ goto no_match; |
|
1113 | 1112 |
} |
1114 | 1113 |
if (parse_select(&name.s, &p->v.select) < 0) { |
1115 | 1114 |
ERR("Error while parsing select identifier\n"); |
... | ... |
@@ -1133,20 +1132,18 @@ int fix_param(int type, void** param) |
1133 | 1132 |
trim(&name); |
1134 | 1133 |
if (!name.len || name.s[0] != '$'){ |
1135 | 1134 |
/* not a pvs identifier */ |
1136 |
- pkg_free(p); |
|
1137 |
- return 1; |
|
1135 |
+ goto no_match; |
|
1138 | 1136 |
} |
1139 | 1137 |
p->v.pvs=pkg_malloc(sizeof(pv_spec_t)); |
1140 | 1138 |
if (p->v.pvs==0){ |
1141 | 1139 |
ERR("out of memory while parsing pv_spec_t\n"); |
1142 | 1140 |
goto error; |
1143 | 1141 |
} |
1144 |
- if (pv_parse_spec(&name, p->v.pvs)==0){ |
|
1145 |
- ERR("unsupported user field indentifier \"%.*s\"\n", |
|
1146 |
- name.len, name.s); |
|
1142 |
+ if (pv_parse_spec2(&name, p->v.pvs, 1)==0){ |
|
1143 |
+ /* not a valid pvs identifier (but it might be an avp) */ |
|
1147 | 1144 |
pkg_free(p->v.pvs); |
1148 | 1145 |
p->v.pvs=0; |
1149 |
- goto error; |
|
1146 |
+ goto no_match; |
|
1150 | 1147 |
} |
1151 | 1148 |
p->fixed = p->v.pvs; |
1152 | 1149 |
break; |
... | ... |
@@ -1165,6 +1162,9 @@ int fix_param(int type, void** param) |
1165 | 1162 |
*param = (void*)p; |
1166 | 1163 |
return 0; |
1167 | 1164 |
|
1165 |
+no_match: |
|
1166 |
+ pkg_free(p); |
|
1167 |
+ return 1; |
|
1168 | 1168 |
error: |
1169 | 1169 |
pkg_free(p); |
1170 | 1170 |
return E_UNSPEC; |
... | ... |
@@ -1261,6 +1261,8 @@ int fix_param_types(int types, void** param) |
1261 | 1261 |
int fixup_var_str_12(void** param, int param_no) |
1262 | 1262 |
{ |
1263 | 1263 |
int ret; |
1264 |
+ if ((sr_cfg_compat!=SR_COMPAT_SER) && |
|
1265 |
+ ((ret = fix_param(FPARAM_PVS, param)) <= 0)) return ret; |
|
1264 | 1266 |
if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret; |
1265 | 1267 |
if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret; |
1266 | 1268 |
if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret; |
... | ... |
@@ -1296,6 +1298,8 @@ int fixup_var_str_2(void** param, int param_no) |
1296 | 1298 |
int fixup_var_int_12(void** param, int param_no) |
1297 | 1299 |
{ |
1298 | 1300 |
int ret; |
1301 |
+ if ((sr_cfg_compat!=SR_COMPAT_SER) && |
|
1302 |
+ ((ret = fix_param(FPARAM_PVS, param)) <= 0)) return ret; |
|
1299 | 1303 |
if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret; |
1300 | 1304 |
if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret; |
1301 | 1305 |
if ((ret = fix_param(FPARAM_INT, param)) <= 0) return ret; |
... | ... |
@@ -231,21 +231,25 @@ struct param_export_ { |
231 | 231 |
|
232 | 232 |
|
233 | 233 |
/** allowed parameter types. |
234 |
- * the types that cannot be deduced from the string, should |
|
235 |
- * be at the end (e.g. FPARAM_STR), to allow fallback |
|
236 |
- * (e.g. fix_param_types(FPARAM_AVP|FPARAM_SELECT|FPARAM_STR, param)) |
|
234 |
+ * the types _must_ be in "fallback" order, |
|
235 |
+ * e.g. FPARAM_STR should be the last to allow fallback to it, |
|
236 |
+ * F_PARAM_PVS should be in front of F_PARAM_AVP (so that |
|
237 |
+ * for fix_param_types(FPARAM_AVP|FPARAM_PVS|FPARAM_STR, param) and $foo |
|
238 |
+ * the pvars will be checked first and only if no pvar is found the |
|
239 |
+ * param will be resolved to an avp) |
|
237 | 240 |
*/ |
238 | 241 |
enum { |
239 | 242 |
FPARAM_UNSPEC = 0, |
240 | 243 |
FPARAM_INT = (1 << 0), |
241 |
- FPARAM_REGEX = (1 << 1), |
|
242 |
- FPARAM_AVP = (1 << 2), |
|
243 |
- FPARAM_SELECT = (1 << 3), |
|
244 |
- FPARAM_SUBST = (1 << 4), |
|
245 |
- FPARAM_PVS = (1 << 5), |
|
246 |
- FPARAM_PVE = (1 << 6), |
|
247 |
- FPARAM_STRING = (1 << 7), |
|
248 |
- FPARAM_STR = (1 << 8) |
|
244 |
+ FPARAM_SELECT = (1 << 1), |
|
245 |
+ FPARAM_PVS = (1 << 2), |
|
246 |
+ FPARAM_AVP = (1 << 3), |
|
247 |
+ FPARAM_STRING = (1 << 4), |
|
248 |
+ FPARAM_STR = (1 << 5), |
|
249 |
+ /* special types: no fallback between them possible */ |
|
250 |
+ FPARAM_REGEX = (1 << 6), |
|
251 |
+ FPARAM_SUBST = (1 << 7), |
|
252 |
+ FPARAM_PVE = (1 << 8) |
|
249 | 253 |
}; |
250 | 254 |
|
251 | 255 |
/* |