[sr-dev] git:master: core: helper functions to get xavp child nodes

Daniel-Constantin Mierla miconda at gmail.com
Mon Sep 30 15:55:25 CEST 2013


Module: sip-router
Branch: master
Commit: 89bd52a84d5e0d75572caff61346d0c3750c868a
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=89bd52a84d5e0d75572caff61346d0c3750c868a

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Mon Sep 30 15:47:30 2013 +0200

core: helper functions to get xavp child nodes

- one function to get the $xavp(rootname=>childname) in code
- wrappers for child node, child node with int value and child node with str value

---

 xavp.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 xavp.h |    4 ++++
 2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/xavp.c b/xavp.c
index ceb405d..5f51731 100644
--- a/xavp.c
+++ b/xavp.c
@@ -787,4 +787,53 @@ sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list)
 	}
 	return NULL;
 }
+
+/**
+ * return child node of an xavp
+ * - $xavp(rname=>cname)
+ */
+sr_xavp_t* xavp_get_child(str *rname, str *cname)
+{
+	sr_xavp_t *ravp=NULL;
+
+	ravp = xavp_get(rname, NULL);
+	if(ravp==NULL || ravp->val.type!=SR_XTYPE_XAVP)
+		return NULL;
+
+	return xavp_get(cname, ravp->val.v.xavp);
+}
+
+
+/**
+ * return child node of an xavp if it has int value
+ * - $xavp(rname=>cname)
+ */
+sr_xavp_t* xavp_get_child_with_ival(str *rname, str *cname)
+{
+	sr_xavp_t *vavp=NULL;
+
+	vavp = xavp_get_child(rname, cname);
+
+	if(vavp==NULL || vavp->val.type!=SR_XTYPE_INT)
+		return NULL;
+
+	return vavp;
+}
+
+
+/**
+ * return child node of an xavp if it has string value
+ * - $xavp(rname=>cname)
+ */
+sr_xavp_t* xavp_get_child_with_sval(str *rname, str *cname)
+{
+	sr_xavp_t *vavp=NULL;
+
+	vavp = xavp_get_child(rname, cname);
+
+	if(vavp==NULL || vavp->val.type!=SR_XTYPE_STR)
+		return NULL;
+
+	return vavp;
+}
 #endif
diff --git a/xavp.h b/xavp.h
index 7d5d517..8332069 100644
--- a/xavp.h
+++ b/xavp.h
@@ -104,6 +104,10 @@ sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list);
 void xavp_print_list(sr_xavp_t **head);
 
 sr_xavp_t *xavp_clone_level_nodata(sr_xavp_t *xold);
+
+sr_xavp_t* xavp_get_child(str *rname, str *cname);
+sr_xavp_t* xavp_get_child_with_ival(str *rname, str *cname);
+sr_xavp_t* xavp_get_child_with_sval(str *rname, str *cname);
 #endif
 
 #endif




More information about the sr-dev mailing list