Module: kamailio
Branch: master
Commit: 1e5d1e35fbebd25d3d4b81839e40dfbea841f7d2
URL:
https://github.com/kamailio/kamailio/commit/1e5d1e35fbebd25d3d4b81839e40dfb…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-09-07T08:39:41+02:00
core: xavp - helper function to set style when serializing
---
Modified: src/core/xavp.c
Modified: src/core/xavp.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1e5d1e35fbebd25d3d4b81839e40dfb…
Patch:
https://github.com/kamailio/kamailio/commit/1e5d1e35fbebd25d3d4b81839e40dfb…
---
diff --git a/src/core/xavp.c b/src/core/xavp.c
index 9a0e4ad600a..551a039ab80 100644
--- a/src/core/xavp.c
+++ b/src/core/xavp.c
@@ -1105,19 +1105,22 @@ int xavp_set_child_sval(str *rname, str *cname, str *sval)
}
/**
- * serialize the values in subfields of an xavp in name=value; format
+ * serialize the values in subfields of an xavp in name=value format styles
* - rname - name of the root list xavp
+ * - mode - 0 - style is 'name=value;', 1 - style is ';name=value'
* - obuf - buffer were to write the output
* - olen - the size of obuf
* return: 0 - not found; -1 - error; >0 - length of output
*/
-int xavp_serialize_fields(str *rname, char *obuf, int olen)
+int xavp_serialize_fields_style(str *rname, int mode, char *obuf, int olen)
{
sr_xavp_t *ravp = NULL;
sr_xavp_t *avp = NULL;
str ostr;
int rlen;
+ char *pr = "";
+ char *sf = "";
ravp = xavp_get(rname, NULL);
if(ravp == NULL || ravp->val.type != SR_XTYPE_XAVP) {
@@ -1125,6 +1128,14 @@ int xavp_serialize_fields(str *rname, char *obuf, int olen)
return 0;
}
+ if(mode & 1) {
+ pr = ";";
+ sf = "";
+ } else {
+ pr = "";
+ sf = ";";
+ }
+
rlen = 0;
ostr.s = obuf;
avp = ravp->val.v.xavp;
@@ -1132,9 +1143,9 @@ int xavp_serialize_fields(str *rname, char *obuf, int olen)
switch(avp->val.type) {
case SR_XTYPE_LONG:
LM_DBG(" XAVP long int value: %ld\n", avp->val.v.l);
- ostr.len = snprintf(ostr.s, olen - rlen, "%.*s=%lu;",
- avp->name.len, avp->name.s,
- (unsigned long)avp->val.v.l);
+ ostr.len = snprintf(ostr.s, olen - rlen, "%s%.*s=%lu%s",
+ pr, avp->name.len, avp->name.s,
+ (unsigned long)avp->val.v.l, sf);
if(ostr.len <= 0 || ostr.len >= olen - rlen) {
LM_ERR("failed to serialize int value (%d/%d\n", ostr.len,
olen - rlen);
@@ -1144,12 +1155,12 @@ int xavp_serialize_fields(str *rname, char *obuf, int olen)
case SR_XTYPE_STR:
LM_DBG(" XAVP str value: %s\n", avp->val.v.s.s);
if(avp->val.v.s.len == 0) {
- ostr.len = snprintf(ostr.s, olen - rlen, "%.*s;",
- avp->name.len, avp->name.s);
+ ostr.len = snprintf(ostr.s, olen - rlen, "%s%.*s%s",
+ pr, avp->name.len, avp->name.s, sf);
} else {
- ostr.len = snprintf(ostr.s, olen - rlen, "%.*s=%.*s;",
- avp->name.len, avp->name.s, avp->val.v.s.len,
- avp->val.v.s.s);
+ ostr.len = snprintf(ostr.s, olen - rlen, "%s%.*s=%.*s%s",
+ pr, avp->name.len, avp->name.s, avp->val.v.s.len,
+ avp->val.v.s.s, sf);
}
if(ostr.len <= 0 || ostr.len >= olen - rlen) {
LM_ERR("failed to serialize int value (%d/%d\n", ostr.len,
@@ -1170,6 +1181,19 @@ int xavp_serialize_fields(str *rname, char *obuf, int olen)
return rlen;
}
+/**
+ * serialize the values in subfields of an xavp in 'name=value;' format
+ * - rname - name of the root list xavp
+ * - obuf - buffer were to write the output
+ * - olen - the size of obuf
+ * return: 0 - not found; -1 - error; >0 - length of output
+ */
+
+int xavp_serialize_fields(str *rname, char *obuf, int olen)
+{
+ return xavp_serialize_fields_style(rname, 0, obuf, olen);
+}
+
/**
*
*/
diff --git a/src/core/xavp.h b/src/core/xavp.h
index c1aa7d8c651..4d5c30d989b 100644
--- a/src/core/xavp.h
+++ b/src/core/xavp.h
@@ -114,6 +114,7 @@ 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);
int xavp_serialize_fields(str *rname, char *obuf, int olen);
+int xavp_serialize_fields_style(str *rname, int mode, char *obuf, int olen);
int xavp_set_child_ival(str *rname, str *cname, long ival);
int xavp_set_child_sval(str *rname, str *cname, str *sval);