From df52f1b753bd15edc8db51713ca0b5e9505beeca Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 12 Jul 2020 11:09:50 +0200 Subject: [PATCH] removed dependency to jansson --- test/webfuse_provider/provider/test_client.cc | 92 +++++++------ .../provider/test_client_protocol.cc | 121 +++++++++--------- .../test_util/webfuse_server.cc | 113 +++++++--------- .../test_util/webfuse_server.hpp | 12 +- test/webfuse_provider/test_util/ws_server.cc | 24 ++-- test/webfuse_provider/test_util/ws_server.h | 5 +- 6 files changed, 174 insertions(+), 193 deletions(-) diff --git a/test/webfuse_provider/provider/test_client.cc b/test/webfuse_provider/provider/test_client.cc index 32843c9..1770cc3 100644 --- a/test/webfuse_provider/provider/test_client.cc +++ b/test/webfuse_provider/provider/test_client.cc @@ -2,6 +2,8 @@ #include "webfuse_provider/test_util/webfuse_server.hpp" #include "webfuse_provider/mocks/mock_provider_client.hpp" #include "webfuse_provider/test_util/client.hpp" +#include "webfuse_provider/impl/json/parser.h" +#include "webfuse_provider/impl/json/node.h" #include #include @@ -146,20 +148,22 @@ TEST(Client, Lookup) ASSERT_EQ(std::future_status::ready, connected.get_future().wait_for(TIMEOUT)); - json_t * response = server.Lookup(1, "foo"); - ASSERT_TRUE(json_is_object(response)); - json_t * result = json_object_get(response, "result"); + std::string response_text = server.Lookup(1, "foo"); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(response_text.data())); + wfp_json const * response = wfp_impl_json_root(doc); + ASSERT_TRUE(wfp_impl_json_is_object(response)); + wfp_json const * result = wfp_impl_json_object_get(response, "result"); - json_t * inode = json_object_get(result, "inode"); - ASSERT_EQ(42, json_integer_value(inode)); + wfp_json const * inode = wfp_impl_json_object_get(result, "inode"); + ASSERT_EQ(42, wfp_impl_json_get_int(inode)); - json_t * mode = json_object_get(result, "mode"); - ASSERT_EQ(0644, json_integer_value(mode)); + wfp_json const * mode = wfp_impl_json_object_get(result, "mode"); + ASSERT_EQ(0644, wfp_impl_json_get_int(mode)); - json_t * type = json_object_get(result, "type"); - ASSERT_STREQ("file", json_string_value(type)); + wfp_json const * type = wfp_impl_json_object_get(result, "type"); + ASSERT_STREQ("file", wfp_impl_json_get_string(type)); - json_decref(response); + wfp_impl_json_dispose(doc); client.Disconnect(); ASSERT_EQ(std::future_status::ready, disconnected.get_future().wait_for(TIMEOUT)); @@ -194,14 +198,17 @@ TEST(Client, LookupFail) ASSERT_EQ(std::future_status::ready, connected.get_future().wait_for(TIMEOUT)); - json_t * response = server.Lookup(1, "foo"); - ASSERT_TRUE(json_is_object(response)); - json_t * error = json_object_get(response, "error"); + std::string response_text = server.Lookup(1, "foo"); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(response_text.data())); + wfp_json const * response = wfp_impl_json_root(doc); - json_t * code = json_object_get(error, "code"); - ASSERT_NE(0, json_integer_value(code)); + ASSERT_TRUE(wfp_impl_json_is_object(response)); + wfp_json const * error = wfp_impl_json_object_get(response, "error"); - json_decref(response); + wfp_json const * code = wfp_impl_json_object_get(error, "code"); + ASSERT_NE(0, wfp_impl_json_get_int(code)); + + wfp_impl_json_dispose(doc); client.Disconnect(); ASSERT_EQ(std::future_status::ready, disconnected.get_future().wait_for(TIMEOUT)); @@ -236,14 +243,17 @@ TEST(Client, Open) ASSERT_EQ(std::future_status::ready, connected.get_future().wait_for(TIMEOUT)); - json_t * response = server.Open(1, 0); - ASSERT_TRUE(json_is_object(response)); - json_t * result = json_object_get(response, "result"); + std::string response_text = server.Open(1, 0); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(response_text.data())); + wfp_json const * response = wfp_impl_json_root(doc); - json_t * handle = json_object_get(result, "handle"); - ASSERT_EQ(4711, json_integer_value(handle)); + ASSERT_TRUE(wfp_impl_json_is_object(response)); + wfp_json const * result = wfp_impl_json_object_get(response, "result"); - json_decref(response); + wfp_json const * handle = wfp_impl_json_object_get(result, "handle"); + ASSERT_EQ(4711, wfp_impl_json_get_int(handle)); + + wfp_impl_json_dispose(doc); client.Disconnect(); ASSERT_EQ(std::future_status::ready, disconnected.get_future().wait_for(TIMEOUT)); @@ -279,20 +289,23 @@ TEST(Client, Read) ASSERT_EQ(std::future_status::ready, connected.get_future().wait_for(TIMEOUT)); - json_t * response = server.Read(42, 5, 0, 1); - ASSERT_TRUE(json_is_object(response)); - json_t * result = json_object_get(response, "result"); + std::string response_text = server.Read(42, 5, 0, 1); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(response_text.data())); + wfp_json const * response = wfp_impl_json_root(doc); - json_t * format = json_object_get(result, "format"); - ASSERT_STREQ("base64", json_string_value(format)); + ASSERT_TRUE(wfp_impl_json_is_object(response)); + wfp_json const * result = wfp_impl_json_object_get(response, "result"); - json_t * count = json_object_get(result, "count"); - ASSERT_EQ(1, json_integer_value(count)); + wfp_json const * format = wfp_impl_json_object_get(result, "format"); + ASSERT_STREQ("base64", wfp_impl_json_get_string(format)); - json_t * data = json_object_get(result, "data"); - ASSERT_STREQ("Kg==", json_string_value(data)); + wfp_json const * count = wfp_impl_json_object_get(result, "count"); + ASSERT_EQ(1, wfp_impl_json_get_int(count)); - json_decref(response); + wfp_json const * data = wfp_impl_json_object_get(result, "data"); + ASSERT_STREQ("Kg==", wfp_impl_json_get_string(data)); + + wfp_impl_json_dispose(doc); client.Disconnect(); ASSERT_EQ(std::future_status::ready, disconnected.get_future().wait_for(TIMEOUT)); @@ -329,14 +342,17 @@ TEST(Client, ReadDir) ASSERT_EQ(std::future_status::ready, connected.get_future().wait_for(TIMEOUT)); - json_t * response = server.ReadDir(42); - ASSERT_TRUE(json_is_object(response)); - json_t * result = json_object_get(response, "result"); + std::string response_text = server.ReadDir(42); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(response_text.data())); + wfp_json const * response = wfp_impl_json_root(doc); - ASSERT_TRUE(json_is_array(result)); - ASSERT_EQ(3, json_array_size(result)); + ASSERT_TRUE(wfp_impl_json_is_object(response)); + wfp_json const * result = wfp_impl_json_object_get(response, "result"); - json_decref(response); + ASSERT_TRUE(wfp_impl_json_is_array(result)); + ASSERT_EQ(3, wfp_impl_json_array_size(result)); + + wfp_impl_json_dispose(doc); client.Disconnect(); ASSERT_EQ(std::future_status::ready, disconnected.get_future().wait_for(TIMEOUT)); diff --git a/test/webfuse_provider/provider/test_client_protocol.cc b/test/webfuse_provider/provider/test_client_protocol.cc index 318b832..1a796c9 100644 --- a/test/webfuse_provider/provider/test_client_protocol.cc +++ b/test/webfuse_provider/provider/test_client_protocol.cc @@ -7,12 +7,14 @@ #include "webfuse_provider/mocks/mock_provider_client.hpp" #include "webfuse_provider/protocol_names.h" #include "webfuse_provider/test_util/timeout_watcher.hpp" +#include "webfuse_provider/impl/json/parser.h" +#include "webfuse_provider/impl/json/node.h" #include #include +#include #include -#include using webfuse_test::WsServer; using webfuse_test::MockProviderClient; @@ -77,16 +79,16 @@ public: wfp_client_protocol_disconnect(protocol); } - void SendToClient(json_t * request) + void SendToClient(std::string const & request) { server->SendMessage(request); } - json_t * ReceiveMessageFromClient() + std::string ReceiveMessageFromClient() { TimeoutWatcher watcher(DEFAULT_TIMEOUT); - json_t * result = server->ReceiveMessage(); - while (nullptr == result) + std::string result = server->ReceiveMessage(); + while (result.empty()) { watcher.check(); lws_service(context, 0); @@ -100,73 +102,71 @@ public: std::string const & expected_username, std::string const & expected_password) { - json_t * request = ReceiveMessageFromClient(); - ASSERT_TRUE(json_is_object(request)); + std::string request_text = ReceiveMessageFromClient(); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(request_text.data())); + wfp_json const * request = wfp_impl_json_root(doc); + ASSERT_TRUE(wfp_impl_json_is_object(request)); - json_t * method = json_object_get(request, "method"); - ASSERT_TRUE(json_is_string(method)); - ASSERT_STREQ("authenticate", json_string_value(method)); + wfp_json const * method = wfp_impl_json_object_get(request, "method"); + ASSERT_TRUE(wfp_impl_json_is_string(method)); + ASSERT_STREQ("authenticate", wfp_impl_json_get_string(method)); - json_t * id = json_object_get(request, "id"); - ASSERT_TRUE(json_is_integer(id)); + wfp_json const * id = wfp_impl_json_object_get(request, "id"); + ASSERT_TRUE(wfp_impl_json_is_int(id)); - json_t * params = json_object_get(request, "params"); - ASSERT_TRUE(json_is_array(params)); - ASSERT_EQ(2, json_array_size(params)); + wfp_json const * params = wfp_impl_json_object_get(request, "params"); + ASSERT_TRUE(wfp_impl_json_is_array(params)); + ASSERT_EQ(2, wfp_impl_json_array_size(params)); - json_t * type = json_array_get(params, 0); - ASSERT_TRUE(json_is_string(type)); - ASSERT_STREQ("username", json_string_value(type)); + wfp_json const * type = wfp_impl_json_array_get(params, 0); + ASSERT_TRUE(wfp_impl_json_is_string(type)); + ASSERT_STREQ("username", wfp_impl_json_get_string(type)); - json_t * credentials = json_array_get(params, 1); - ASSERT_TRUE(json_is_object(credentials)); + wfp_json const * credentials = wfp_impl_json_array_get(params, 1); + ASSERT_TRUE(wfp_impl_json_is_object(credentials)); - json_t * username = json_object_get(credentials, "username"); - ASSERT_TRUE(json_is_string(username)); - ASSERT_STREQ(expected_username.c_str(), json_string_value(username)); + wfp_json const * username = wfp_impl_json_object_get(credentials, "username"); + ASSERT_TRUE(wfp_impl_json_is_string(username)); + ASSERT_STREQ(expected_username.c_str(), wfp_impl_json_get_string(username)); - json_t * password = json_object_get(credentials, "password"); - ASSERT_TRUE(json_is_string(password)); - ASSERT_STREQ(expected_password.c_str(), json_string_value(password)); + wfp_json const * password = wfp_impl_json_object_get(credentials, "password"); + ASSERT_TRUE(wfp_impl_json_is_string(password)); + ASSERT_STREQ(expected_password.c_str(), wfp_impl_json_get_string(password)); - json_t * response = json_object(); - json_object_set_new(response, "result", json_object()); - json_object_set(response, "id", id); - SendToClient(response); + std::ostringstream response; + response << "{\"result\": {}, \"id\": " << wfp_impl_json_get_int(id) << "}"; + SendToClient(response.str()); - json_decref(request); + wfp_impl_json_dispose(doc); } void AwaitAddFilesystem(std::string& filesystemName) { - json_t * addFilesystemRequest = ReceiveMessageFromClient(); - ASSERT_NE(nullptr, addFilesystemRequest); - ASSERT_TRUE(json_is_object(addFilesystemRequest)); + std::string request_text = ReceiveMessageFromClient(); + wfp_json_doc * doc = wfp_impl_json_parse(const_cast(request_text.data())); + wfp_json const * request = wfp_impl_json_root(doc); + ASSERT_TRUE(wfp_impl_json_is_object(request)); - json_t * method = json_object_get(addFilesystemRequest, "method"); - ASSERT_TRUE(json_is_string(method)); - ASSERT_STREQ("add_filesystem", json_string_value(method)); + wfp_json const * method = wfp_impl_json_object_get(request, "method"); + ASSERT_TRUE(wfp_impl_json_is_string(method)); + ASSERT_STREQ("add_filesystem", wfp_impl_json_get_string(method)); - json_t * params = json_object_get(addFilesystemRequest, "params"); - ASSERT_TRUE(json_is_array(params)); - ASSERT_EQ(1, json_array_size(params)); + wfp_json const * params = wfp_impl_json_object_get(request, "params"); + ASSERT_TRUE(wfp_impl_json_is_array(params)); + ASSERT_EQ(1, wfp_impl_json_array_size(params)); - json_t * filesystem = json_array_get(params, 0); - ASSERT_TRUE(json_is_string(filesystem)); - filesystemName = json_string_value(filesystem); + wfp_json const * filesystem = wfp_impl_json_array_get(params, 0); + ASSERT_TRUE(wfp_impl_json_is_string(filesystem)); - json_t * id = json_object_get(addFilesystemRequest, "id"); - ASSERT_TRUE(json_is_integer(id)); + wfp_json const * id = wfp_impl_json_object_get(request, "id"); + ASSERT_TRUE(wfp_impl_json_is_int(id)); - json_t * response = json_object(); - json_t * result = json_object(); - json_object_set(result, "id", filesystem); - json_object_set_new(response, "result", result); - json_object_set(response, "id", id); + std::ostringstream response; + response << "{\"result\": {\"id\": \"" << wfp_impl_json_get_string(filesystem) << "\"}, \"id\": " << wfp_impl_json_get_int(id) << "}"; - SendToClient(response); + SendToClient(response.str()); - json_decref(addFilesystemRequest); + wfp_impl_json_dispose(doc); } private: @@ -250,19 +250,12 @@ TEST(client_protocol, getattr) fixture.AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } - json_t * params = json_array(); - json_array_append_new(params, json_string(filesystem.c_str())); - json_array_append_new(params, json_integer(1)); - json_t * request = json_object(); - json_object_set_new(request, "method", json_string("getattr")); - json_object_set_new(request, "params", params); - json_object_set_new(request, "id", json_integer(42)); + std::ostringstream request; + request << "{\"method\": \"getattr\", \"params\": [\"" << filesystem << "\", 1], \"id\": 42}"; - fixture.SendToClient(request); - json_t * response = fixture.ReceiveMessageFromClient(); - ASSERT_TRUE(json_is_object(response)); - - json_decref(response); + fixture.SendToClient(request.str()); + std::string response = fixture.ReceiveMessageFromClient(); + ASSERT_FALSE(response.empty()); fixture.Disconnect(); } \ No newline at end of file diff --git a/test/webfuse_provider/test_util/webfuse_server.cc b/test/webfuse_provider/test_util/webfuse_server.cc index 6e4527a..1a7f474 100644 --- a/test/webfuse_provider/test_util/webfuse_server.cc +++ b/test/webfuse_provider/test_util/webfuse_server.cc @@ -1,6 +1,8 @@ #include "webfuse_provider/test_util/webfuse_server.hpp" #include "webfuse_provider/impl/util/lws_log.h" #include "webfuse_provider/protocol_names.h" +#include "webfuse_provider/impl/json/parser.h" +#include "webfuse_provider/impl/json/node.h" #include #include @@ -10,6 +12,7 @@ #include #include #include +#include #define TIMEOUT (std::chrono::seconds(10)) @@ -22,7 +25,7 @@ public: virtual ~IServer() = default; virtual void OnConnected(lws * wsi) = 0; virtual void OnConnectionClosed(lws * wsi) = 0; - virtual void OnMessageReceived(lws * wsi, char const * data, size_t length) = 0; + virtual void OnMessageReceived(lws * wsi, char * data, size_t length) = 0; virtual void OnWritable(lws * wsi) = 0; }; @@ -54,7 +57,7 @@ static int wfp_test_utils_webfuse_server_callback( break; case LWS_CALLBACK_RECEIVE: { - auto * data = reinterpret_cast(in); + auto * data = reinterpret_cast(in); server->OnMessageReceived(wsi, data, len); } break; @@ -143,7 +146,7 @@ public: return filesystem; } - json_t * Invoke(std::string const & method, json_t * params) + std::string Invoke(std::string const & method, std::string const & params) { std::promise response; { @@ -151,27 +154,23 @@ public: message = &response; id++; - json_t * request = json_object(); - json_object_set_new(request, "method", json_string(method.c_str())); - json_object_set_new(request, "params", params); - json_object_set_new(request, "id", json_integer(id)); + std::ostringstream request; + request << "{" + << "\"method\": \"" << method << "\"," + << "\"params\": " << params << "," + << "\"id\": " << id + << "}"; - char * request_text = json_dumps(request, 0); - write_queue.push(request_text); - free(request_text); - json_decref(request); + write_queue.push(request.str()); } lws_callback_on_writable(client); - json_t * result = nullptr; + std::string result; auto future = response.get_future(); auto state = future.wait_for(TIMEOUT); if (std::future_status::ready == state) { - std::string response_text = future.get(); - result = json_loadb(response_text.c_str(), response_text.size(), 0, nullptr); - std::unique_lock lock(mutex); - message = nullptr; + result = future.get(); } return result; @@ -189,7 +188,7 @@ public: client = nullptr; } - void OnMessageReceived(lws * wsi, char const * data, size_t length) override + void OnMessageReceived(lws * wsi, char * data, size_t length) override { { std::unique_lock lock(mutex); @@ -199,35 +198,30 @@ public: } } - json_t * message = json_loadb(data, length, 0, nullptr); - if (message) + wfp_json_doc * doc = wfp_impl_json_parse_buffer(data, length); + if (doc) { - json_t * method = json_object_get(message, "method"); - if (json_is_string(method)) + wfp_json const * message = wfp_impl_json_root(doc); + wfp_json const * method = wfp_impl_json_object_get(message, "method"); + if (wfp_impl_json_is_string(method)) { - if (0 == strcmp("add_filesystem", json_string_value(method))) + if (0 == strcmp("add_filesystem", wfp_impl_json_get_string(method))) { - json_t * id = json_object_get(message, "id"); + wfp_json const * id = wfp_impl_json_object_get(message, "id"); - json_t * response = json_object(); - json_t * result = json_object(); - json_object_set_new(result, "id", json_string(GetFilesystem().c_str())); - json_object_set_new(response, "result", result); - json_object_set(response, "id", id); - - char * response_text = json_dumps(response, 0); + std::ostringstream response; + response << "{\"result\": {\"id\": \"" << GetFilesystem() << "\"}, " + << "\"id\": " << wfp_impl_json_get_int(id) << "}"; { std::unique_lock lock(mutex); - write_queue.push(response_text); + write_queue.push(response.str()); } - free(response_text); - json_decref(response); lws_callback_on_writable(wsi); } } - json_decref(message); + wfp_impl_json_dispose(doc); } } @@ -306,56 +300,41 @@ std::string const & WebfuseServer::GetUrl() return d->GetUrl(); } -json_t * WebfuseServer::Invoke(std::string const & method, json_t * params) +std::string WebfuseServer::Invoke(std::string const & method, std::string const & params) { return d->Invoke(method, params); } -json_t * WebfuseServer::Invoke(std::string const & method, std::string const & params) +std::string WebfuseServer::Lookup(int parent, std::string const & name) { - json_t * params_json = json_loads(params.c_str(), 0, nullptr); - return d->Invoke(method, params_json); + std::ostringstream params; + params << "[\"" << d->GetFilesystem() << "\", " << parent << ", \"" << name << "\"]"; + + return d->Invoke("lookup", params.str()); } -json_t * WebfuseServer::Lookup(int parent, std::string const & name) +std::string WebfuseServer::Open(int inode, int flags) { - json_t * params = json_array(); - json_array_append_new(params, json_string(d->GetFilesystem().c_str())); - json_array_append_new(params, json_integer(parent)); - json_array_append_new(params, json_string(name.c_str())); + std::ostringstream params; + params << "[\"" << d->GetFilesystem() << "\", " << inode << ", " << flags << "]"; - return d->Invoke("lookup", params); + return d->Invoke("open", params.str()); } -json_t * WebfuseServer::Open(int inode, int flags) +std::string WebfuseServer::Read(int inode, int handle, int offset, int length) { - json_t * params = json_array(); - json_array_append_new(params, json_string(d->GetFilesystem().c_str())); - json_array_append_new(params, json_integer(inode)); - json_array_append_new(params, json_integer(flags)); + std::ostringstream params; + params << "[\"" << d->GetFilesystem() << "\", " << inode << ", " << handle << ", " << offset << ", " << length << "]"; - return d->Invoke("open", params); + return d->Invoke("read", params.str()); } -json_t * WebfuseServer::Read(int inode, int handle, int offset, int length) +std::string WebfuseServer::ReadDir(int inode) { - json_t * params = json_array(); - json_array_append_new(params, json_string(d->GetFilesystem().c_str())); - json_array_append_new(params, json_integer(inode)); - json_array_append_new(params, json_integer(handle)); - json_array_append_new(params, json_integer(offset)); - json_array_append_new(params, json_integer(length)); + std::ostringstream params; + params << "[\"" << d->GetFilesystem() << "\", " << inode << "]"; - return d->Invoke("read", params); -} - -json_t * WebfuseServer::ReadDir(int inode) -{ - json_t * params = json_array(); - json_array_append_new(params, json_string(d->GetFilesystem().c_str())); - json_array_append_new(params, json_integer(inode)); - - return d->Invoke("readdir", params); + return d->Invoke("readdir", params.str()); } } \ No newline at end of file diff --git a/test/webfuse_provider/test_util/webfuse_server.hpp b/test/webfuse_provider/test_util/webfuse_server.hpp index ec16dc4..88ef2bc 100644 --- a/test/webfuse_provider/test_util/webfuse_server.hpp +++ b/test/webfuse_provider/test_util/webfuse_server.hpp @@ -2,7 +2,6 @@ #define WFP_TEST_UTIL_WEBFUSE_SERVER_HPP #include -#include namespace webfuse_test { @@ -15,12 +14,11 @@ public: WebfuseServer(bool use_tls = false); ~WebfuseServer(); std::string const & GetUrl(); - json_t * Invoke(std::string const & method, json_t * params); - json_t * Invoke(std::string const & method, std::string const & params); - json_t * Lookup(int parent, std::string const & name); - json_t * Open(int inode, int flags); - json_t * Read(int inode, int handle, int offset, int length); - json_t * ReadDir(int inode); + std::string Invoke(std::string const & method, std::string const & params); + std::string Lookup(int parent, std::string const & name); + std::string Open(int inode, int flags); + std::string Read(int inode, int handle, int offset, int length); + std::string ReadDir(int inode); private: class Private; Private * d; diff --git a/test/webfuse_provider/test_util/ws_server.cc b/test/webfuse_provider/test_util/ws_server.cc index 2386894..865a5f8 100644 --- a/test/webfuse_provider/test_util/ws_server.cc +++ b/test/webfuse_provider/test_util/ws_server.cc @@ -35,8 +35,8 @@ public: ~Private(); bool IsConnected(); std::string GetUrl() const; - void SendMessage(json_t * message); - json_t * ReceiveMessage(); + void SendMessage(std::string const & message); + std::string ReceiveMessage(); void OnConnected(lws * wsi) override; void OnConnectionClosed(lws * wsi) override; void OnMessageReceived(struct lws * wsi, char const * data, size_t length) override; @@ -123,12 +123,12 @@ bool WsServer::IsConnected() return d->IsConnected(); } -void WsServer::SendMessage(json_t * message) +void WsServer::SendMessage(std::string const & message) { d->SendMessage(message); } -json_t * WsServer::ReceiveMessage() +std::string WsServer::ReceiveMessage() { return d->ReceiveMessage(); } @@ -248,7 +248,7 @@ void WsServer::Private::OnWritable(struct lws * wsi) } -void WsServer::Private::SendMessage(json_t * message) +void WsServer::Private::SendMessage(std::string const & message) { lws * wsi = nullptr; @@ -257,10 +257,7 @@ void WsServer::Private::SendMessage(json_t * message) if (nullptr != wsi_) { - char* message_text = json_dumps(message, JSON_COMPACT); - writeQueue.push(message_text); - json_decref(message); - free(message_text); + writeQueue.push(message); wsi = wsi_; } } @@ -280,19 +277,18 @@ void WsServer::Private::OnMessageReceived(struct lws * wsi, char const * data, s } } -json_t * WsServer::Private::ReceiveMessage() +std::string WsServer::Private::ReceiveMessage() { std::unique_lock lock(mutex); - json_t * result = nullptr; + std::string message; if (!recvQueue.empty()) { - std::string const & message_text = recvQueue.front(); - result = json_loads(message_text.c_str(), JSON_DECODE_ANY, nullptr); + message = recvQueue.front(); recvQueue.pop(); } - return result; + return message; } std::string WsServer::Private::GetUrl() const diff --git a/test/webfuse_provider/test_util/ws_server.h b/test/webfuse_provider/test_util/ws_server.h index 8c28005..94a62f2 100644 --- a/test/webfuse_provider/test_util/ws_server.h +++ b/test/webfuse_provider/test_util/ws_server.h @@ -1,7 +1,6 @@ #ifndef WFP_TEST_UTILS_WS_SERVER_HPP #define WFP_TEST_UTILS_WS_SERVER_HPP -#include #include namespace webfuse_test @@ -16,8 +15,8 @@ public: ~WsServer(); bool IsConnected(); std::string GetUrl() const; - void SendMessage(json_t * message); - json_t * ReceiveMessage(); + void SendMessage(std::string const & message); + std::string ReceiveMessage(); private: class Private; Private * d;