Browse code

- ctl/binrpc modified not to complain if no reply was sent (happily send empty replies) and to parse empty messages/replies (until now an empty message was considered an error)

Andrei Pelinescu-Onciul authored on 03/11/2006 00:43:45
Showing 2 changed files
... ...
@@ -27,6 +27,7 @@
27 27
 /* History:
28 28
  * --------
29 29
  *  2006-02-08  created by andrei
30
+ *  2006-11-03  replies with no payload are allowed (andrei)
30 31
  */
31 32
 /* binrpc is  supposed to be a minimalist binary rpc implementation */
32 33
 
... ...
@@ -116,8 +117,8 @@
116 117
 #define BINRPC_MIN_HDR_SIZE	(BINRPC_FIXED_HDR_SIZE+2)
117 118
 #define BINRPC_MAX_HDR_SIZE	(BINRPC_FIXED_HDR_SIZE+4+4)
118 119
 #define BINRPC_MIN_RECORD_SIZE	1
119
-/* min pkt size: min header + min. len (1) + min. cookie (1) + min record */
120
-#define BINRPC_MIN_PKT_SIZE	(BINRPC_MIN_HDR_SIZE+BINRPC_MIN_RECORD_SIZE)
120
+/* min pkt size: min header + min. len (1) + min. cookie (1)*/
121
+#define BINRPC_MIN_PKT_SIZE	BINRPC_MIN_HDR_SIZE
121 122
 
122 123
 /* message types */
123 124
 #define BINRPC_REQ   0
... ...
@@ -590,10 +591,11 @@ static inline unsigned char* binrpc_parse_init(	struct binrpc_parse_ctx* ctx,
590 591
 	}
591 592
 	p=binrpc_read_int((int*)&ctx->tlen, len_len, &buf[BINRPC_TLEN_OFFSET],
592 593
 						&buf[len], err);
593
-	if (ctx->tlen==0){
594
+	/* empty packets (replies) are allowed
595
+	   if (ctx->tlen==0){
594 596
 		*err=E_BINRPC_BADPKT;
595 597
 		goto error;
596
-	}
598
+	} */
597 599
 	p=binrpc_read_int((int*)&ctx->cookie, c_len, p, &buf[len], err);
598 600
 	ctx->offset=0;
599 601
 	ctx->flags|=BINRPC_F_INIT;
... ...
@@ -527,13 +527,14 @@ int process_rpc_req(unsigned char* buf, int size, int* bytes_needed,
527 527
 	f_ctx.method=val.u.strval.s;
528 528
 	rpc_e->function(&binrpc_callbacks, &f_ctx);
529 529
 	if (f_ctx.replied==0){
530
-		if (binrpc_pkt_len(&f_ctx.out.pkt)==0){
530
+		/* to get an error reply if the rpc handlers hasn't replied
531
+		 *  uncomment the following code:
532
+		 * if (binrpc_pkt_len(&f_ctx.out.pkt)==0){
531 533
 			rpc_fault(&f_ctx, 500, "internal server error: no reply");
532 534
 			LOG(L_ERR, "ERROR: rpc method %s hasn't replied\n",
533 535
 					val.u.strval.s);
534
-		}else{
536
+		}else  */
535 537
 			rpc_send(&f_ctx);
536
-		}
537 538
 	}
538 539
 end:
539 540
 	*bytes_needed=0; /* full read */