Browse code

core: $xavu() helper functions to get child values

- like for xavp and xavi

Daniel-Constantin Mierla authored on 01/04/2021 05:56:30
Showing 2 changed files
... ...
@@ -1448,6 +1448,56 @@ sr_xavp_t *xavu_set_child_sval(str *rname, str *cname, str *sval)
1448 1448
 	return xavu_set_child_xval(rname, cname, &xval);
1449 1449
 }
1450 1450
 
1451
+/**
1452
+ * return child node of an xavp
1453
+ * - $xavu(rname=>cname)
1454
+ */
1455
+sr_xavp_t* xavu_get_child(str *rname, str *cname)
1456
+{
1457
+	sr_xavp_t *ravp=NULL;
1458
+
1459
+	ravp = xavu_get(rname, NULL);
1460
+	if(ravp==NULL || ravp->val.type!=SR_XTYPE_XAVP)
1461
+		return NULL;
1462
+
1463
+	return xavu_get(cname, ravp->val.v.xavp);
1464
+}
1465
+
1466
+
1467
+/**
1468
+ * return child node of an xavp if it has int value
1469
+ * - $xavu(rname=>cname)
1470
+ */
1471
+sr_xavp_t* xavu_get_child_with_ival(str *rname, str *cname)
1472
+{
1473
+	sr_xavp_t *vavp=NULL;
1474
+
1475
+	vavp = xavu_get_child(rname, cname);
1476
+
1477
+	if(vavp==NULL || vavp->val.type!=SR_XTYPE_INT)
1478
+		return NULL;
1479
+
1480
+	return vavp;
1481
+}
1482
+
1483
+
1484
+/**
1485
+ * return child node of an xavp if it has string value
1486
+ * - $xavu(rname=>cname)
1487
+ */
1488
+sr_xavp_t* xavu_get_child_with_sval(str *rname, str *cname)
1489
+{
1490
+	sr_xavp_t *vavp=NULL;
1491
+
1492
+	vavp = xavu_get_child(rname, cname);
1493
+
1494
+	if(vavp==NULL || vavp->val.type!=SR_XTYPE_STR)
1495
+		return NULL;
1496
+
1497
+	return vavp;
1498
+}
1499
+
1500
+
1451 1501
 /**
1452 1502
  * serialize the values in subfields of an xavu in name=value; format
1453 1503
  * - rname - name of the root list xavu
... ...
@@ -131,6 +131,10 @@ sr_xavp_t *xavu_set_sval(str *rname, str *sval);
131 131
 sr_xavp_t *xavu_set_child_xval(str *rname, str *cname, sr_xval_t *xval);
132 132
 sr_xavp_t *xavu_set_child_ival(str *rname, str *cname, int ival);
133 133
 sr_xavp_t *xavu_set_child_sval(str *rname, str *cname, str *sval);
134
+sr_xavp_t* xavu_get_child(str *rname, str *cname);
135
+sr_xavp_t* xavu_get_child_with_ival(str *rname, str *cname);
136
+sr_xavp_t* xavu_get_child_with_sval(str *rname, str *cname);
137
+
134 138
 int xavu_serialize_fields(str *rname, char *obuf, int olen);
135 139
 
136 140
 /** xavi api */