Module: kamailio
Branch: 5.0
Commit: 40d26eae8c678e7623478b5b624e401e9bb94434
URL:
https://github.com/kamailio/kamailio/commit/40d26eae8c678e7623478b5b624e401…
Author: Ovidiu Sas <osas(a)voipembedded.com>
Committer: Ovidiu Sas <osas(a)voipembedded.com>
Date: 2017-05-10T13:03:29-04:00
xhttp_rpc: fix rpc_struct_printf
(cherry picked from commit 8f87e7c4c3ba925a20bd0ab69e1fc885a559d262)
---
Modified: src/modules/xhttp_rpc/xhttp_rpc.c
---
Diff:
https://github.com/kamailio/kamailio/commit/40d26eae8c678e7623478b5b624e401…
Patch:
https://github.com/kamailio/kamailio/commit/40d26eae8c678e7623478b5b624e401…
---
diff --git a/src/modules/xhttp_rpc/xhttp_rpc.c b/src/modules/xhttp_rpc/xhttp_rpc.c
index 7e50035..6e27409 100644
--- a/src/modules/xhttp_rpc/xhttp_rpc.c
+++ b/src/modules/xhttp_rpc/xhttp_rpc.c
@@ -562,7 +562,7 @@ static int rpc_struct_add(struct rpc_data_struct* rpc_s, char* fmt,
...)
}
-static int rpc_struct_scan(void* s, char* fmt, ...)
+static int rpc_struct_scan(struct rpc_data_struct* rpc_s, char* fmt, ...)
{
LM_ERR("Not implemented\n");
return -1;
@@ -571,10 +571,34 @@ static int rpc_struct_scan(void* s, char* fmt, ...)
/** Create a new member from formatting string and add it to a structure.
*/
-static int rpc_struct_printf(void* s, char* member_name, char* fmt, ...)
+static int rpc_struct_printf(struct rpc_data_struct* rpc_s, char* member_name, char* fmt,
...)
{
- LM_ERR("Not implemented\n");
- return -1;
+ va_list ap;
+ char buf[PRINT_VALUE_BUF_LEN];
+ int len;
+ str _name,_body;
+ rpc_ctx_t *ctx = rpc_s->ctx;
+
+ if (!ctx) {
+ LM_ERR("Invalid context\n");
+ return -1;
+ }
+
+ va_start(ap, fmt);
+ len=vsnprintf(buf, PRINT_VALUE_BUF_LEN, fmt, ap);
+ va_end(ap);
+ if ((len<0) || (len>PRINT_VALUE_BUF_LEN)){
+ LM_ERR("buffer size exceeded [%d]\n", PRINT_VALUE_BUF_LEN);
+ return -1;
+ }
+
+ _name.s = member_name;
+ _name.len = strlen(member_name);
+ _body.s = buf;
+ _body.len = len;
+ if (0!=xhttp_rpc_build_content(ctx, &_body, &_name)) return -1;
+
+ return 0;
}