From 40d26eae8c678e7623478b5b624e401e9bb94434 Mon Sep 17 00:00:00 2001 From: Ovidiu Sas Date: Wed, 10 May 2017 13:00:57 -0400 Subject: [PATCH] xhttp_rpc: fix rpc_struct_printf (cherry picked from commit 8f87e7c4c3ba925a20bd0ab69e1fc885a559d262) --- src/modules/xhttp_rpc/xhttp_rpc.c | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/modules/xhttp_rpc/xhttp_rpc.c b/src/modules/xhttp_rpc/xhttp_rpc.c index 7e5003562f6..6e27409435b 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; }