Browse Source

xmlrpc: scan resets the error code

This way, the scan can be retried, and RPC functions
with multi-type parameters can be supported:

if (rpc->scan(c, "d",&i) == 1)
	/* int parameter */
else if (rpc->scan(c, "s",&ch) == 1)
	/* char* parameter */
else
	return /* error */
Miklos Tirpak 15 years ago
parent
commit
ef18280cf6
1 changed files with 14 additions and 0 deletions
  1. 14 0
      modules/xmlrpc/xmlrpc.c

+ 14 - 0
modules/xmlrpc/xmlrpc.c

@@ -634,6 +634,15 @@ static int init_xmlrpc_reply(struct xmlrpc_reply* reply)
 	return 0;
 }
 
+/** Clear the XML-RPC reply code and sets it back to a success reply.
+ *
+ * @param reply XML-RPC reply structure to be cleared.
+ */
+static void clear_xmlrpc_reply(struct xmlrpc_reply* reply)
+{
+	reply->code = 200;
+	reply->reason = "OK";
+}
 
 
 /* if this a delayed reply context, and it's never been use before, fix it */
@@ -1445,6 +1454,9 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
 	va_list ap;
 
 	reply = &ctx->reply;
+	/* clear the previously saved error code */
+	clear_xmlrpc_reply(reply);
+
 	fmt_len = strlen(fmt);
 	va_start(ap, fmt);
 	modifiers=0;
@@ -1768,6 +1780,8 @@ static int rpc_struct_scan(struct rpc_struct* s, char* fmt, ...)
 	while(*fmt) {
 		member_name = va_arg(ap, char*);
 		reply = s->reply;
+		/* clear the previously saved error code */
+		clear_xmlrpc_reply(reply);
 		ret = find_member(&value, s->doc, s->struct_in, reply, member_name);
 		if (ret != 0) goto error;