Module: sip-router
Branch: master
Commit: b25e31aaab556941d4f3057d7f6b106b2ed749bb
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b25e31a…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Mon Jul 6 12:26:19 2009 +0200
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
---
sr_module.c | 34 +++++++++++++++++++---------------
sr_module.h | 26 +++++++++++++++-----------
2 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/sr_module.c b/sr_module.c
index 3641df3..5414529 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -54,6 +54,7 @@
#include "trim.h"
#include "globals.h"
#include "rpc_lookup.h"
+#include "sr_compat.h"
#include <sys/stat.h>
#include <regex.h>
@@ -1052,7 +1053,7 @@ int fix_param(int type, void** param)
goto error;
case FPARAM_STRING:
p->v.asciiz = *param;
-
+ /* no break */
case FPARAM_STR:
p->v.str.s = (char*)*param;
p->v.str.len = strlen(p->v.str.s);
@@ -1080,8 +1081,8 @@ int fix_param(int type, void** param)
REG_EXTENDED|REG_ICASE|REG_NEWLINE)) {
pkg_free(p->v.regex);
p->v.regex=0;
- ERR("Bad regular expression '%s'\n", (char*)*param);
- goto error;
+ /* not a valid regex */
+ goto no_match;
}
p->fixed = p->v.regex;
break;
@@ -1091,14 +1092,13 @@ int fix_param(int type, void** param)
trim(&name);
if (!name.len || name.s[0] != '$') {
/* Not an AVP identifier */
- pkg_free(p);
- return 1;
+ goto no_match;
}
name.s++;
name.len--;
if (parse_avp_ident(&name, &p->v.avp) < 0) {
- ERR("Error while parsing attribute name\n");
- goto error;
+ /* invalid avp identifier (=> no match) */
+ goto no_match;
}
p->fixed = &p->v;
break;
@@ -1108,8 +1108,7 @@ int fix_param(int type, void** param)
trim(&name);
if (!name.len || name.s[0] != '@') {
/* Not a select identifier */
- pkg_free(p);
- return 1;
+ goto no_match;
}
if (parse_select(&name.s, &p->v.select) < 0) {
ERR("Error while parsing select identifier\n");
@@ -1133,20 +1132,18 @@ int fix_param(int type, void** param)
trim(&name);
if (!name.len || name.s[0] != '$'){
/* not a pvs identifier */
- pkg_free(p);
- return 1;
+ goto no_match;
}
p->v.pvs=pkg_malloc(sizeof(pv_spec_t));
if (p->v.pvs==0){
ERR("out of memory while parsing pv_spec_t\n");
goto error;
}
- if (pv_parse_spec(&name, p->v.pvs)==0){
- ERR("unsupported user field indentifier \"%.*s\"\n",
- name.len, name.s);
+ if (pv_parse_spec2(&name, p->v.pvs, 1)==0){
+ /* not a valid pvs identifier (but it might be an avp) */
pkg_free(p->v.pvs);
p->v.pvs=0;
- goto error;
+ goto no_match;
}
p->fixed = p->v.pvs;
break;
@@ -1165,6 +1162,9 @@ int fix_param(int type, void** param)
*param = (void*)p;
return 0;
+no_match:
+ pkg_free(p);
+ return 1;
error:
pkg_free(p);
return E_UNSPEC;
@@ -1261,6 +1261,8 @@ int fix_param_types(int types, void** param)
int fixup_var_str_12(void** param, int param_no)
{
int ret;
+ if ((sr_cfg_compat!=SR_COMPAT_SER) &&
+ ((ret = fix_param(FPARAM_PVS, param)) <= 0)) return ret;
if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
@@ -1296,6 +1298,8 @@ int fixup_var_str_2(void** param, int param_no)
int fixup_var_int_12(void** param, int param_no)
{
int ret;
+ if ((sr_cfg_compat!=SR_COMPAT_SER) &&
+ ((ret = fix_param(FPARAM_PVS, param)) <= 0)) return ret;
if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
if ((ret = fix_param(FPARAM_INT, param)) <= 0) return ret;
diff --git a/sr_module.h b/sr_module.h
index 0b1d74b..426729c 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -231,21 +231,25 @@ struct param_export_ {
/** allowed parameter types.
- * the types that cannot be deduced from the string, should
- * be at the end (e.g. FPARAM_STR), to allow fallback
- * (e.g. fix_param_types(FPARAM_AVP|FPARAM_SELECT|FPARAM_STR, param))
+ * the types _must_ be in "fallback" order,
+ * e.g. FPARAM_STR should be the last to allow fallback to it,
+ * F_PARAM_PVS should be in front of F_PARAM_AVP (so that
+ * for fix_param_types(FPARAM_AVP|FPARAM_PVS|FPARAM_STR, param) and $foo
+ * the pvars will be checked first and only if no pvar is found the
+ * param will be resolved to an avp)
*/
enum {
FPARAM_UNSPEC = 0,
FPARAM_INT = (1 << 0),
- FPARAM_REGEX = (1 << 1),
- FPARAM_AVP = (1 << 2),
- FPARAM_SELECT = (1 << 3),
- FPARAM_SUBST = (1 << 4),
- FPARAM_PVS = (1 << 5),
- FPARAM_PVE = (1 << 6),
- FPARAM_STRING = (1 << 7),
- FPARAM_STR = (1 << 8)
+ FPARAM_SELECT = (1 << 1),
+ FPARAM_PVS = (1 << 2),
+ FPARAM_AVP = (1 << 3),
+ FPARAM_STRING = (1 << 4),
+ FPARAM_STR = (1 << 5),
+ /* special types: no fallback between them possible */
+ FPARAM_REGEX = (1 << 6),
+ FPARAM_SUBST = (1 << 7),
+ FPARAM_PVE = (1 << 8)
};
/*