Przeglądaj źródła

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
Daniel-Constantin Mierla 16 lat temu
rodzic
commit
13d7e923c4
2 zmienionych plików z 20 dodań i 5 usunięć
  1. 7 1
      modules_s/ctl/binrpc_run.c
  2. 13 4
      modules_s/ctl/fifo_server.c

+ 7 - 1
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));
 	/*

+ 13 - 4
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 */