Module: sip-router
Branch: master
Commit: 13d7e923c4bb9b9a58371deb81727d2a10d13ef8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=13d7e92…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Jun 28 12:28:41 2009 +0200
ctl: '*' optional scan modifier
- '*' can be used in rpc scan to mark the start of optional parameter
reading
- example: 'Sd*Sb' - mandatory str, mandatory int, optional str, optional
bool
- if optinal modifier is used, then scan does not call rpc_fault, so
execution of rpc command can continue
- to be used by rpc command 'mi' - execute K MI commands
---
modules_s/ctl/binrpc_run.c | 8 +++++++-
modules_s/ctl/fifo_server.c | 17 +++++++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/modules_s/ctl/binrpc_run.c b/modules_s/ctl/binrpc_run.c
index 13c41c4..fa371ef 100644
--- a/modules_s/ctl/binrpc_run.c
+++ b/modules_s/ctl/binrpc_run.c
@@ -593,11 +593,16 @@ static int rpc_scan(struct binrpc_ctx* ctx, char* fmt, ...)
struct binrpc_val v;
int err;
char* orig_fmt;
+ int nofault;
va_start(ap, fmt);
orig_fmt=fmt;
+ nofault = 0;
for (;*fmt; fmt++){
switch(*fmt){
+ case '*': /* start of optional parameters */
+ nofault = 1;
+ break;
case 'b': /* bool */
case 't': /* time */
case 'd': /* int */
@@ -649,7 +654,8 @@ static int rpc_scan(struct binrpc_ctx* ctx, char* fmt, ...)
va_end(ap);
return (int)(fmt-orig_fmt);
error_read:
- rpc_fault(ctx, 400, "error at parameter %d: expected %s type but"
+ if(nofault==0)
+ rpc_fault(ctx, 400, "error at parameter %d: expected %s type but"
" %s", ctx->in.record_no, rpc_type_name(v.type),
binrpc_error(err));
/*
diff --git a/modules_s/ctl/fifo_server.c b/modules_s/ctl/fifo_server.c
index b625313..9ad267a 100644
--- a/modules_s/ctl/fifo_server.c
+++ b/modules_s/ctl/fifo_server.c
@@ -1346,10 +1346,12 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
void** void_ptr;
int read;
str line;
+ int nofault;
va_list ap;
va_start(ap, fmt);
+ nofault = 0;
read = 0;
while(*fmt) {
if (read_line(&line.s, &line.len, &ctx->read_h) < 0) {
@@ -1359,11 +1361,15 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
ctx->line_no++;
switch(*fmt) {
+ case '*': /* start of optional parameters */
+ nofault = 1;
+ break;
case 'b': /* Bool */
case 't': /* Date and time */
case 'd': /* Integer */
if (!line.len) {
- rpc_fault(ctx, 400, "Invalid parameter value on line %d",
+ if(nofault==0)
+ rpc_fault(ctx, 400, "Invalid parameter value on line %d",
ctx->line_no);
goto error;
}
@@ -1373,7 +1379,8 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
case 'f': /* double */
if (!line.len) {
- rpc_fault(ctx, 400, "Invalid parameter value on line %d",
+ if(nofault==0)
+ rpc_fault(ctx, 400, "Invalid parameter value on line %d",
ctx->line_no);
goto error;
}
@@ -1385,8 +1392,10 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
case 'S': /* str structure */
l = new_chunk_unescape(&line);
if (!l) {
- rpc_fault(ctx, 500, "Internal Server Error");
- ERR("Not enough memory\n");
+ if(nofault==0) {
+ rpc_fault(ctx, 500, "Internal Server Error");
+ ERR("Not enough memory\n");
+ }
goto error;
}
/* Make sure it gets released at the end */