Module: sip-router Branch: master Commit: fa9d76128f0e20384a800c7c741365680d6eb799 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fa9d7612...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Wed Apr 23 23:01:07 2014 +0200
ctl: fifo server implementation was lacking adding struct values
- specifier '{' was not handled for adding values - implemented adding array with '[' specifier - array_add aliased to rpc_struct_add for the moment
---
modules/ctl/fifo_server.c | 115 ++++++++++++++++++++++++--------------------- 1 files changed, 62 insertions(+), 53 deletions(-)
diff --git a/modules/ctl/fifo_server.c b/modules/ctl/fifo_server.c index d5f849f..a786c21 100644 --- a/modules/ctl/fifo_server.c +++ b/modules/ctl/fifo_server.c @@ -905,12 +905,15 @@ int init_fifo_fd(char* fifo, int fifo_mode, int fifo_uid, int fifo_gid,
int fifo_rpc_init() { + memset(&func_param, 0, sizeof(func_param)); func_param.send = (rpc_send_f)rpc_send; func_param.fault = (rpc_fault_f)rpc_fault; func_param.add = (rpc_add_f)rpc_add; func_param.scan = (rpc_scan_f)rpc_scan; func_param.printf = (rpc_printf_f)rpc_printf; func_param.struct_add = (rpc_struct_add_f)rpc_struct_add; + /* use rpc_struct_add for array_add */ + func_param.array_add = (rpc_array_add_f)rpc_struct_add; func_param.struct_scan = (rpc_struct_scan_f)rpc_struct_scan; func_param.struct_printf = (rpc_struct_printf_f)rpc_struct_printf; return 0; @@ -1185,7 +1188,7 @@ static int rpc_add(rpc_ctx_t* ctx, char* fmt, ...)
va_start(ap, fmt); while(*fmt) { - if (*fmt == '{') { + if (*fmt == '{' || *fmt == '[') { void_ptr = va_arg(ap, void**); l = new_chunk(&s); if (!l) { @@ -1441,11 +1444,11 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...) }
- static int rpc_struct_add(struct text_chunk* s, char* fmt, ...) { static char buf[MAX_LINE_BUFFER]; str st, *sp; + void** void_ptr; va_list ap; struct text_chunk* m, *c; rpc_ctx_t* ctx; @@ -1463,61 +1466,67 @@ static int rpc_struct_add(struct text_chunk* s, char* fmt, ...) } m->flags |= CHUNK_MEMBER_NAME; - switch(*fmt) { - case 'd': - case 't': - st.s = int2str(va_arg(ap, int), &st.len); - c = new_chunk(&st); - break; - - case 'f': - st.s = buf; - st.len = snprintf(buf, 256, "%f", va_arg(ap, double)); - if (st.len < 0) { - rpc_fault(ctx, 400, "Error While Converting double"); - ERR("Error while converting double\n"); + if(*fmt=='{' || *fmt=='[') { + void_ptr = va_arg(ap, void**); + m->ctx=ctx; + append_chunk(ctx, m); + *void_ptr = m; + } else { + switch(*fmt) { + case 'd': + case 't': + st.s = int2str(va_arg(ap, int), &st.len); + c = new_chunk(&st); + break; + + case 'f': + st.s = buf; + st.len = snprintf(buf, 256, "%f", va_arg(ap, double)); + if (st.len < 0) { + rpc_fault(ctx, 400, "Error While Converting double"); + ERR("Error while converting double\n"); + goto err; + } + c = new_chunk(&st); + break; + + case 'b': + st.len = 1; + st.s = ((va_arg(ap, int) == 0) ? "0" : "1"); + c = new_chunk(&st); + break; + + case 's': + st.s = va_arg(ap, char*); + st.len = strlen(st.s); + c = new_chunk_escape(&st, 1); + break; + + case 'S': + sp = va_arg(ap, str*); + c = new_chunk_escape(sp, 1); + break; + + default: + rpc_fault(ctx, 500, "Bug In SER (Invalid formatting character %c)", + *fmt); + ERR("Invalid formatting character\n"); goto err; } - c = new_chunk(&st); - break; - - case 'b': - st.len = 1; - st.s = ((va_arg(ap, int) == 0) ? "0" : "1"); - c = new_chunk(&st); - break; - - case 's': - st.s = va_arg(ap, char*); - st.len = strlen(st.s); - c = new_chunk_escape(&st, 1); - break; - - case 'S': - sp = va_arg(ap, str*); - c = new_chunk_escape(sp, 1); - break; - - default: - rpc_fault(ctx, 500, "Bug In SER (Invalid formatting character %c)", - *fmt); - ERR("Invalid formatting character\n"); - goto err; - }
- if (!c) { - rpc_fault(ctx, 500, "Internal Server Error"); - goto err; + if (!c) { + rpc_fault(ctx, 500, "Internal Server Error"); + goto err; + } + c->flags |= CHUNK_MEMBER_VALUE; + c->next = s->next; + s->next = c; + if (s == ctx->last) ctx->last = c; + + m->next = s->next; + s->next = m; + if (s == ctx->last) ctx->last = m; } - c->flags |= CHUNK_MEMBER_VALUE; - c->next = s->next; - s->next = c; - if (s == ctx->last) ctx->last = c; - - m->next = s->next; - s->next = m; - if (s == ctx->last) ctx->last = m; - fmt++; } va_end(ap);