Browse code

core: pvars support in ser *var fixups

- 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

Andrei Pelinescu-Onciul authored on 06/07/2009 10:26:19
Showing 2 changed files
... ...
@@ -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 1052
 			goto error;
1053 1053
 		case FPARAM_STRING:
1054 1054
 			p->v.asciiz = *param;
1055
-		
1055
+			/* no break */
1056 1056
 		case FPARAM_STR:
1057 1057
 			p->v.str.s = (char*)*param;
1058 1058
 			p->v.str.len = strlen(p->v.str.s);
... ...
@@ -1080,8 +1081,8 @@ int fix_param(int type, void** param)
1080 1080
 						REG_EXTENDED|REG_ICASE|REG_NEWLINE)) {
1081 1081
 				pkg_free(p->v.regex);
1082 1082
 				p->v.regex=0;
1083
-				ERR("Bad regular expression '%s'\n", (char*)*param);
1084
-				goto error;
1083
+				/* not a valid regex */
1084
+				goto no_match;
1085 1085
 			}
1086 1086
 			p->fixed = p->v.regex;
1087 1087
 			break;
... ...
@@ -1091,14 +1092,13 @@ int fix_param(int type, void** param)
1091 1091
 			trim(&name);
1092 1092
 			if (!name.len || name.s[0] != '$') {
1093 1093
 				/* Not an AVP identifier */
1094
-				pkg_free(p);
1095
-				return 1;
1094
+				goto no_match;
1096 1095
 			}
1097 1096
 			name.s++;
1098 1097
 			name.len--;
1099 1098
 			if (parse_avp_ident(&name, &p->v.avp) < 0) {
1100
-				ERR("Error while parsing attribute name\n");
1101
-				goto error;
1099
+				/* invalid avp identifier (=> no match) */
1100
+				goto no_match;
1102 1101
 			}
1103 1102
 			p->fixed = &p->v;
1104 1103
 			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 1133
 			trim(&name);
1134 1134
 			if (!name.len || name.s[0] != '$'){
1135 1135
 				/* not a pvs identifier */
1136
-				pkg_free(p);
1137
-				return 1;
1136
+				goto no_match;
1138 1137
 			}
1139 1138
 			p->v.pvs=pkg_malloc(sizeof(pv_spec_t));
1140 1139
 			if (p->v.pvs==0){
1141 1140
 				ERR("out of memory while parsing pv_spec_t\n");
1142 1141
 				goto error;
1143 1142
 			}
1144
-			if (pv_parse_spec(&name, p->v.pvs)==0){
1145
-				ERR("unsupported user field indentifier \"%.*s\"\n",
1146
-						name.len, name.s);
1143
+			if (pv_parse_spec2(&name, p->v.pvs, 1)==0){
1144
+				/* not a valid pvs identifier (but it might be an avp) */
1147 1145
 				pkg_free(p->v.pvs);
1148 1146
 				p->v.pvs=0;
1149
-				goto error;
1147
+				goto no_match;
1150 1148
 			}
1151 1149
 			p->fixed = p->v.pvs;
1152 1150
 			break;
... ...
@@ -1165,6 +1162,9 @@ int fix_param(int type, void** param)
1165 1165
 	*param = (void*)p;
1166 1166
 	return 0;
1167 1167
 	
1168
+no_match:
1169
+	pkg_free(p);
1170
+	return 1;
1168 1171
 error:
1169 1172
 	pkg_free(p);
1170 1173
 	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 1296
 int fixup_var_int_12(void** param, int param_no)
1297 1297
 {
1298 1298
 	int ret;
1299
+	if ((sr_cfg_compat!=SR_COMPAT_SER) &&
1300
+		((ret = fix_param(FPARAM_PVS, param)) <= 0)) return ret;
1299 1301
 	if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
1300 1302
 	if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
1301 1303
 	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
 /*