core: helper functions to get xavp child nodes
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 30 Sep 2013 13:47:30 +0000 (15:47 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 30 Sep 2013 13:47:30 +0000 (15:47 +0200)
- 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
xavp.h

diff --git a/xavp.c b/xavp.c
index ceb405d..5f51731 100644 (file)
--- 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 (file)
--- 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