json: Move from lib to include/openvswitch.
[cascardo/ovs.git] / lib / jsonrpc.c
index b48e247..1841568 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <errno.h>
 
 #include "byteq.h"
-#include "dynamic-string.h"
+#include "openvswitch/dynamic-string.h"
 #include "fatal-signal.h"
-#include "json.h"
-#include "list.h"
-#include "ofpbuf.h"
+#include "openvswitch/json.h"
+#include "openvswitch/list.h"
+#include "openvswitch/ofpbuf.h"
 #include "ovs-thread.h"
 #include "poll-loop.h"
 #include "reconnect.h"
@@ -87,7 +87,7 @@ jsonrpc_open(struct stream *stream)
     rpc->name = xstrdup(stream_get_name(stream));
     rpc->stream = stream;
     byteq_init(&rpc->input, rpc->input_buffer, sizeof rpc->input_buffer);
-    list_init(&rpc->output);
+    ovs_list_init(&rpc->output);
 
     return rpc;
 }
@@ -113,7 +113,7 @@ jsonrpc_run(struct jsonrpc *rpc)
     }
 
     stream_run(rpc->stream);
-    while (!list_is_empty(&rpc->output)) {
+    while (!ovs_list_is_empty(&rpc->output)) {
         struct ofpbuf *buf = ofpbuf_from_list(rpc->output.next);
         int retval;
 
@@ -122,7 +122,7 @@ jsonrpc_run(struct jsonrpc *rpc)
             rpc->backlog -= retval;
             ofpbuf_pull(buf, retval);
             if (!buf->size) {
-                list_remove(&buf->list_node);
+                ovs_list_remove(&buf->list_node);
                 rpc->output_count--;
                 ofpbuf_delete(buf);
             }
@@ -144,7 +144,7 @@ jsonrpc_wait(struct jsonrpc *rpc)
 {
     if (!rpc->status) {
         stream_run_wait(rpc->stream);
-        if (!list_is_empty(&rpc->output)) {
+        if (!ovs_list_is_empty(&rpc->output)) {
             stream_send_wait(rpc->stream);
         }
     }
@@ -240,7 +240,6 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
     struct json *json;
     struct ds ds = DS_EMPTY_INITIALIZER;
     size_t length;
-    char *s;
 
     if (rpc->status) {
         jsonrpc_msg_destroy(msg);
@@ -252,13 +251,11 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
     json = jsonrpc_msg_to_json(msg);
     json_to_ds(json, 0, &ds);
     length = ds.length;
-    s = ds_steal_cstr(&ds);
     json_destroy(json);
 
     buf = xmalloc(sizeof *buf);
-    ofpbuf_use(buf, s, length);
-    buf->size = length;
-    list_push_back(&rpc->output, &buf->list_node);
+    ofpbuf_use_ds(buf, &ds);
+    ovs_list_push_back(&rpc->output, &buf->list_node);
     rpc->output_count++;
     rpc->backlog += length;
 
@@ -346,7 +343,7 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
                 const struct byteq *q = &rpc->input;
                 if (q->head <= q->size) {
                     stream_report_content(q->buffer, q->head, STREAM_JSONRPC,
-                                          THIS_MODULE, rpc->name);
+                                          &this_module, rpc->name);
                 }
                 return rpc->status;
             }
@@ -387,7 +384,7 @@ jsonrpc_send_block(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
 
     for (;;) {
         jsonrpc_run(rpc);
-        if (list_is_empty(&rpc->output) || rpc->status) {
+        if (ovs_list_is_empty(&rpc->output) || rpc->status) {
             return rpc->status;
         }
         jsonrpc_wait(rpc);
@@ -515,7 +512,7 @@ jsonrpc_create(enum jsonrpc_msg_type type, const char *method,
 {
     struct jsonrpc_msg *msg = xmalloc(sizeof *msg);
     msg->type = type;
-    msg->method = method ? xstrdup(method) : NULL;
+    msg->method = nullable_xstrdup(method);
     msg->params = params;
     msg->result = result;
     msg->error = error;