瀏覽代碼

xhttp_rpc: fix rpc_struct_printf

Ovidiu Sas 8 年之前
父節點
當前提交
8f87e7c4c3
共有 1 個文件被更改,包括 28 次插入4 次删除
  1. 28 4
      src/modules/xhttp_rpc/xhttp_rpc.c

+ 28 - 4
src/modules/xhttp_rpc/xhttp_rpc.c

@@ -562,7 +562,7 @@ err:
 }
 }
 
 
 
 
-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");
 	LM_ERR("Not implemented\n");
 	return -1;
 	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.
 /** 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;
 }
 }