[SR-Dev] git:andrei/fixups: fixups: generic fixups work now on kamailio pvars

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Nov 27 02:49:57 CET 2008


Module: sip-router
Branch: andrei/fixups
Commit: ad4f08c9cf437d8280c07f3673cb050dc3fd714a
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ad4f08c9cf437d8280c07f3673cb050dc3fd714a

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Nov 27 01:30:26 2008 +0100

fixups: generic fixups work now on kamailio pvars

- fix_param() supports now FPARAM_PVS and FPARAM_PVE
  (kamailio GPARAM_TYPE_PVS and GPARAM_TYPE_PVE)
- added fparam_free_contents() which frees the contents of a fparam_t

---

 sr_module.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 sr_module.h |    5 ++-
 2 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/sr_module.c b/sr_module.c
index 919bde5..114f0d2 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -1031,6 +1031,7 @@ int fix_param(int type, void** param)
 			if (regcomp(p->v.regex, *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;
 			}
@@ -1058,7 +1059,7 @@ int fix_param(int type, void** param)
 			if (!name.len || name.s[0] != '@') {
 				/* Not a select identifier */
 				pkg_free(p);
-			return 1;
+				return 1;
 			}
 			if (parse_select(&name.s, &p->v.select) < 0) {
 				ERR("Error while parsing select identifier\n");
@@ -1071,7 +1072,37 @@ int fix_param(int type, void** param)
 			p->v.subst = subst_parser(&s);
 			if (!p->v.subst) {
 				ERR("Error while parsing regex substitution\n");
-			goto error;
+				goto error;
+			}
+			break;
+		case FPARAM_PVS:
+			name.s = (char*)*param;
+			name.len = strlen(name.s);
+			trim(&name);
+			if (!name.len || name.s[0] != '$'){
+				/* not a pvs identifier */
+				pkg_free(p);
+				return 1;
+			}
+			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);
+				pkg_free(p->v.pvs);
+				p->v.pvs=0;
+				goto error;
+			}
+			break;
+		case FPARAM_PVE:
+			name.s = (char*)*param;
+			name.len = strlen(name.s);
+			if (pv_parse_format(&name, &p->v.pve)<0){
+				ERR("bad PVE format: \"%.*s\"\n", name.len, name.s);
+				goto error;
 			}
 			break;
 	}
@@ -1086,6 +1117,63 @@ error:
 }
 
 
+
+/** fparam_t free function.
+ *  Frees the "content" of a fparam, but not the fparam itself.
+ *  Assumes pkg_malloc'ed content.
+ *  @param fp -  fparam to be freed
+ *
+ */
+void fparam_free_contents(fparam_t* fp)
+{
+
+	if (fp==0)
+		return;
+	switch(fp->type) {
+		case FPARAM_UNSPEC:
+		case FPARAM_STRING: /* asciiz string, not str */
+		case FPARAM_INT:
+		case FPARAM_STR:
+			/* nothing to do */
+			return;
+		case FPARAM_REGEX:
+			if (fp->v.regex){
+				regfree(fp->v.regex);
+				pkg_free(fp->v.regex);
+				fp->v.regex=0;
+			}
+			break;
+		case FPARAM_AVP:
+			free_avp_name(&fp->v.avp.flags, &fp->v.avp.name);
+			break;
+		case FPARAM_SELECT:
+			if (fp->v.select){
+				free_select(fp->v.select);
+				fp->v.select=0;
+			}
+			break;
+		case FPARAM_SUBST:
+			if (fp->v.subst){
+				subst_expr_free(fp->v.subst);
+				fp->v.subst=0;
+			}
+			break;
+		case FPARAM_PVS:
+			if (fp->v.pvs){
+				pv_spec_free(fp->v.pvs);
+				fp->v.pvs=0;
+			}
+			break;
+		case FPARAM_PVE:
+			if (fp->v.pve){
+				pv_elem_free_all(fp->v.pve);
+				fp->v.pve=0;
+			}
+			break;
+	}
+}
+
+
 /*
  * Fixup variable string, the parameter can be
  * AVP, SELECT, or ordinary string. AVP and select
diff --git a/sr_module.h b/sr_module.h
index 69d476f..1af0ea4 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -261,8 +261,8 @@ typedef struct fparam {
 		avp_ident_t avp;          /* AVP identifier */
 		select_t* select;         /* select structure */ 
 		struct subst_expr* subst; /* Regex substitution */
-		struct pv_spec_t* pvs;    /* kamailo pseudo-vars */
-		struct pv_elem_t* pve;    /* kamailo pseudo-vars */
+		pv_spec_t* pvs;    /* kamailo pseudo-vars */
+		pv_elem_t* pve;    /* kamailo pseudo-vars in a string */
 	} v;
 } fparam_t;
 
@@ -417,6 +417,7 @@ int fix_flag( modparam_t type, void* val,
  * parameter types
  */
 int fix_param(int type, void** param);
+void fparam_free_contents(fparam_t* fp);
 
 /*
  * Fixup variable string, the parameter can be




More information about the sr-dev mailing list