ovsdb: Fix use of non-array for JSON-RPC parameters.
authorBen Pfaff <blp@nicira.com>
Fri, 13 Nov 2009 23:05:19 +0000 (15:05 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 16 Nov 2009 17:20:40 +0000 (09:20 -0800)
JSON-RPC requires that "params" be an array, but we weren't observing this
properly in the ovsdb specifications or code.

Thanks to Jeremy Stribling for pointing out the problem.

ovsdb/SPECS
ovsdb/jsonrpc-server.c

index f0d7748ff732251fe6b98a6dfd1eb0e7a5b35609..ae4d649b664ee40c9a4b70d3b59184835578cd32 100644 (file)
@@ -32,6 +32,10 @@ values.  Additional notation is presented later.
     A JSON number with an integer value, within a certain range
     (currently -2**63...+2**63-1).
 
+<value>
+
+    Any JSON value.
+
 Schema Format
 -------------
 
@@ -255,7 +259,7 @@ cancel
 Request object members:
 
     "method": "cancel"                              required
-    "params": the "id" for an outstanding request   required
+    "params": [the "id" for an outstanding request] required
     "id": null                                      required
 
 Response object members:
@@ -283,8 +287,8 @@ echo
 Request object members:
 
     "method": "echo"                                required
-    "params": any JSON value                        required
-    "id": any JSON value                            required
+    "params": JSON array with any contents          required
+    "id": <value>                                   required
 
 Response object members:
 
index 7a33d77af4c52343f2af95036da2873e8325e4f5..cea5ddc726d70113468c5aa299b8e54ed041214c 100644 (file)
@@ -368,7 +368,7 @@ ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *s)
 
     case RECONNECT_PROBE:
         if (s->rpc) {
-            struct json *params = json_integer_create(0);
+            struct json *params = json_array_create_empty();
             jsonrpc_send(s->rpc, jsonrpc_create_request("echo", params));
         }
         break;
@@ -453,12 +453,15 @@ ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s,
 static void
 execute_cancel(struct ovsdb_jsonrpc_session *s, struct jsonrpc_msg *request)
 {
-    size_t hash = json_hash(request->id, 0);
-    struct ovsdb_jsonrpc_trigger *t;
+    if (json_array(request->params)->n == 1) {
+        struct ovsdb_jsonrpc_trigger *t;
+        struct json *id;
 
-    t = ovsdb_jsonrpc_trigger_find(s, request->params, hash);
-    if (t) {
-        ovsdb_jsonrpc_trigger_complete(t);
+        id = request->params->u.array.elems[0];
+        t = ovsdb_jsonrpc_trigger_find(s, id, json_hash(id, 0));
+        if (t) {
+            ovsdb_jsonrpc_trigger_complete(t);
+        }
     }
 }