Browse code

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

Daniel-Constantin Mierla authored on 30/09/2013 13:47:30
Showing 2 changed files
... ...
@@ -787,4 +787,53 @@ sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list)
787 787
 	}
788 788
 	return NULL;
789 789
 }
790
+
791
+/**
792
+ * return child node of an xavp
793
+ * - $xavp(rname=>cname)
794
+ */
795
+sr_xavp_t* xavp_get_child(str *rname, str *cname)
796
+{
797
+	sr_xavp_t *ravp=NULL;
798
+
799
+	ravp = xavp_get(rname, NULL);
800
+	if(ravp==NULL || ravp->val.type!=SR_XTYPE_XAVP)
801
+		return NULL;
802
+
803
+	return xavp_get(cname, ravp->val.v.xavp);
804
+}
805
+
806
+
807
+/**
808
+ * return child node of an xavp if it has int value
809
+ * - $xavp(rname=>cname)
810
+ */
811
+sr_xavp_t* xavp_get_child_with_ival(str *rname, str *cname)
812
+{
813
+	sr_xavp_t *vavp=NULL;
814
+
815
+	vavp = xavp_get_child(rname, cname);
816
+
817
+	if(vavp==NULL || vavp->val.type!=SR_XTYPE_INT)
818
+		return NULL;
819
+
820
+	return vavp;
821
+}
822
+
823
+
824
+/**
825
+ * return child node of an xavp if it has string value
826
+ * - $xavp(rname=>cname)
827
+ */
828
+sr_xavp_t* xavp_get_child_with_sval(str *rname, str *cname)
829
+{
830
+	sr_xavp_t *vavp=NULL;
831
+
832
+	vavp = xavp_get_child(rname, cname);
833
+
834
+	if(vavp==NULL || vavp->val.type!=SR_XTYPE_STR)
835
+		return NULL;
836
+
837
+	return vavp;
838
+}
790 839
 #endif
... ...
@@ -104,6 +104,10 @@ sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list);
104 104
 void xavp_print_list(sr_xavp_t **head);
105 105
 
106 106
 sr_xavp_t *xavp_clone_level_nodata(sr_xavp_t *xold);
107
+
108
+sr_xavp_t* xavp_get_child(str *rname, str *cname);
109
+sr_xavp_t* xavp_get_child_with_ival(str *rname, str *cname);
110
+sr_xavp_t* xavp_get_child_with_sval(str *rname, str *cname);
107 111
 #endif
108 112
 
109 113
 #endif