Module: sip-router
Branch: master
Commit: eb367fc968ca3e9644e3fdfaf25ff13d776c4777
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=eb367fc…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Mon Jun 29 20:46:47 2009 +0200
ctl: fix rpc_scan return when "*" is used
- the rpc_scan function (both for binrpc and fifo) did return the
wrong number of parameters when the newly introduced "*"
modifier was used.
- for binrpcs, "*" switches to "nofault" mode only if the error is
E_BINRPC_MORE_DATA or E_BINRPC_EOP (meaning no more data to read
parameters from). All the other errors will generate faults,
even with "*" in the format strings (e.g. parameter type
mismatch, invalid value a.s.o.).
---
modules_s/ctl/binrpc_run.c | 9 ++++++---
modules_s/ctl/fifo_server.c | 7 +++++--
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/modules_s/ctl/binrpc_run.c b/modules_s/ctl/binrpc_run.c
index fa371ef..0fac504 100644
--- a/modules_s/ctl/binrpc_run.c
+++ b/modules_s/ctl/binrpc_run.c
@@ -594,14 +594,17 @@ static int rpc_scan(struct binrpc_ctx* ctx, char* fmt, ...)
int err;
char* orig_fmt;
int nofault;
+ int modifiers;
va_start(ap, fmt);
orig_fmt=fmt;
nofault = 0;
+ modifiers=0;
for (;*fmt; fmt++){
switch(*fmt){
case '*': /* start of optional parameters */
nofault = 1;
+ modifiers++;
break;
case 'b': /* bool */
case 't': /* time */
@@ -652,9 +655,9 @@ static int rpc_scan(struct binrpc_ctx* ctx, char* fmt, ...)
ctx->in.record_no++;
}
va_end(ap);
- return (int)(fmt-orig_fmt);
+ return (int)(fmt-orig_fmt)-modifiers;
error_read:
- if(nofault==0)
+ if(nofault==0 || ((err!=E_BINRPC_MORE_DATA) && (err!=E_BINRPC_EOP)))
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));
@@ -675,7 +678,7 @@ error_inv_param:
*fmt);
error_ret:
va_end(ap);
- return -(int)(fmt-orig_fmt);
+ return -((int)(fmt-orig_fmt)-modifiers);
}
diff --git a/modules_s/ctl/fifo_server.c b/modules_s/ctl/fifo_server.c
index 9ad267a..a701765 100644
--- a/modules_s/ctl/fifo_server.c
+++ b/modules_s/ctl/fifo_server.c
@@ -1347,12 +1347,14 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
int read;
str line;
int nofault;
+ int modifiers;
va_list ap;
va_start(ap, fmt);
nofault = 0;
read = 0;
+ modifiers=0;
while(*fmt) {
if (read_line(&line.s, &line.len, &ctx->read_h) < 0) {
va_end(ap);
@@ -1363,6 +1365,7 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
switch(*fmt) {
case '*': /* start of optional parameters */
nofault = 1;
+ modifiers++;
break;
case 'b': /* Bool */
case 't': /* Date and time */
@@ -1429,11 +1432,11 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
read++;
}
va_end(ap);
- return read;
+ return read-modifiers;
error:
va_end(ap);
- return -read;
+ return -(read-modifiers);
}