mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
refactor: renamed json_parse to json_doc
This commit is contained in:
parent
2979904514
commit
bf8ba05863
@ -20,7 +20,7 @@
|
|||||||
#include "webfuse_provider/impl/jsonrpc/response.h"
|
#include "webfuse_provider/impl/jsonrpc/response.h"
|
||||||
#include "webfuse_provider/impl/jsonrpc/request.h"
|
#include "webfuse_provider/impl/jsonrpc/request.h"
|
||||||
#include "webfuse_provider/impl/jsonrpc/proxy.h"
|
#include "webfuse_provider/impl/jsonrpc/proxy.h"
|
||||||
#include "webfuse_provider/impl/json/parser.h"
|
#include "webfuse_provider/impl/json/doc.h"
|
||||||
|
|
||||||
#define WFP_DEFAULT_TIMEOUT (10 * 1000)
|
#define WFP_DEFAULT_TIMEOUT (10 * 1000)
|
||||||
|
|
||||||
@ -39,10 +39,10 @@ static void wfp_impl_client_protocol_process(
|
|||||||
char * data,
|
char * data,
|
||||||
size_t length)
|
size_t length)
|
||||||
{
|
{
|
||||||
struct wfp_json_doc * doc = wfp_impl_json_parse_buffer(data, length);
|
struct wfp_json_doc * doc = wfp_impl_json_doc_loadb(data, length);
|
||||||
if (NULL != doc)
|
if (NULL != doc)
|
||||||
{
|
{
|
||||||
struct wfp_json const * message = wfp_impl_json_root(doc);
|
struct wfp_json const * message = wfp_impl_json_doc_root(doc);
|
||||||
if (wfp_jsonrpc_is_response(message))
|
if (wfp_jsonrpc_is_response(message))
|
||||||
{
|
{
|
||||||
wfp_jsonrpc_proxy_onresult(protocol->proxy, message);
|
wfp_jsonrpc_proxy_onresult(protocol->proxy, message);
|
||||||
@ -60,7 +60,7 @@ static void wfp_impl_client_protocol_process(
|
|||||||
wfp_impl_provider_invoke(&context, message);
|
wfp_impl_provider_invoke(&context, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#include "webfuse_provider/impl/json/parser.h"
|
#include "webfuse_provider/impl/json/doc.h"
|
||||||
#include "webfuse_provider/impl/json/node_intern.h"
|
#include "webfuse_provider/impl/json/node_intern.h"
|
||||||
#include "webfuse_provider/impl/json/reader.h"
|
#include "webfuse_provider/impl/json/reader.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define WFP_IMPL_JSON_DEFAULT_CAPACITY 4
|
#define WFP_IMPL_JSON_DEFAULT_CAPACITY 4
|
||||||
|
|
||||||
@ -49,15 +48,9 @@ wfp_impl_json_parse_object(
|
|||||||
struct wfp_json * json);
|
struct wfp_json * json);
|
||||||
|
|
||||||
|
|
||||||
extern struct wfp_json_doc *
|
|
||||||
wfp_impl_json_parse(
|
|
||||||
char * data)
|
|
||||||
{
|
|
||||||
return wfp_impl_json_parse_buffer(data, strlen(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wfp_json_doc *
|
struct wfp_json_doc *
|
||||||
wfp_impl_json_parse_buffer(
|
wfp_impl_json_doc_loadb(
|
||||||
char * data,
|
char * data,
|
||||||
size_t length)
|
size_t length)
|
||||||
{
|
{
|
||||||
@ -75,7 +68,7 @@ wfp_impl_json_parse_buffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wfp_impl_json_dispose(
|
wfp_impl_json_doc_dispose(
|
||||||
struct wfp_json_doc * doc)
|
struct wfp_json_doc * doc)
|
||||||
{
|
{
|
||||||
wfp_impl_json_cleanup(&doc->root);
|
wfp_impl_json_cleanup(&doc->root);
|
||||||
@ -83,7 +76,7 @@ wfp_impl_json_dispose(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct wfp_json const *
|
struct wfp_json const *
|
||||||
wfp_impl_json_root(
|
wfp_impl_json_doc_root(
|
||||||
struct wfp_json_doc * doc)
|
struct wfp_json_doc * doc)
|
||||||
{
|
{
|
||||||
return &(doc->root);
|
return &(doc->root);
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef WFP_IMPL_JSON_PARSER_H
|
#ifndef WFP_IMPL_JSON_DOC_H
|
||||||
#define WFP_IMPL_JSON_PARSER_H
|
#define WFP_IMPL_JSON_DOC_H
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -16,20 +16,16 @@ struct wfp_json;
|
|||||||
struct wfp_json_doc;
|
struct wfp_json_doc;
|
||||||
|
|
||||||
extern struct wfp_json_doc *
|
extern struct wfp_json_doc *
|
||||||
wfp_impl_json_parse(
|
wfp_impl_json_doc_loadb(
|
||||||
char * data);
|
|
||||||
|
|
||||||
extern struct wfp_json_doc *
|
|
||||||
wfp_impl_json_parse_buffer(
|
|
||||||
char * data,
|
char * data,
|
||||||
size_t length);
|
size_t length);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
wfp_impl_json_dispose(
|
wfp_impl_json_doc_dispose(
|
||||||
struct wfp_json_doc * doc);
|
struct wfp_json_doc * doc);
|
||||||
|
|
||||||
extern struct wfp_json const *
|
extern struct wfp_json const *
|
||||||
wfp_impl_json_root(
|
wfp_impl_json_doc_root(
|
||||||
struct wfp_json_doc * doc);
|
struct wfp_json_doc * doc);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -29,7 +29,7 @@ webfuse_provider_static = static_library('webfuse_provider',
|
|||||||
'lib/webfuse_provider/impl/json/writer.c',
|
'lib/webfuse_provider/impl/json/writer.c',
|
||||||
'lib/webfuse_provider/impl/json/node.c',
|
'lib/webfuse_provider/impl/json/node.c',
|
||||||
'lib/webfuse_provider/impl/json/reader.c',
|
'lib/webfuse_provider/impl/json/reader.c',
|
||||||
'lib/webfuse_provider/impl/json/parser.c',
|
'lib/webfuse_provider/impl/json/doc.c',
|
||||||
'lib/webfuse_provider/impl/jsonrpc/proxy.c',
|
'lib/webfuse_provider/impl/jsonrpc/proxy.c',
|
||||||
'lib/webfuse_provider/impl/jsonrpc/proxy_variadic.c',
|
'lib/webfuse_provider/impl/jsonrpc/proxy_variadic.c',
|
||||||
'lib/webfuse_provider/impl/jsonrpc/request.c',
|
'lib/webfuse_provider/impl/jsonrpc/request.c',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "webfuse_provider/impl/json/parser.h"
|
#include "webfuse_provider/impl/json/doc.h"
|
||||||
#include "webfuse_provider/impl/json/node.h"
|
#include "webfuse_provider/impl/json/node.h"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -7,7 +7,7 @@ namespace
|
|||||||
{
|
{
|
||||||
wfp_json_doc * parse_json(char * text)
|
wfp_json_doc * parse_json(char * text)
|
||||||
{
|
{
|
||||||
return wfp_impl_json_parse_buffer(text, strlen(text));
|
return wfp_impl_json_doc_loadb(text, strlen(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,11 +16,11 @@ TEST(json_parser, parse_true)
|
|||||||
char text[] = "true";
|
char text[] = "true";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_bool(root));
|
ASSERT_TRUE(wfp_impl_json_is_bool(root));
|
||||||
ASSERT_TRUE(wfp_impl_json_get_bool(root));
|
ASSERT_TRUE(wfp_impl_json_get_bool(root));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_false)
|
TEST(json_parser, parse_false)
|
||||||
@ -28,11 +28,11 @@ TEST(json_parser, parse_false)
|
|||||||
char text[] = "false";
|
char text[] = "false";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_bool(root));
|
ASSERT_TRUE(wfp_impl_json_is_bool(root));
|
||||||
ASSERT_FALSE(wfp_impl_json_get_bool(root));
|
ASSERT_FALSE(wfp_impl_json_get_bool(root));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_int)
|
TEST(json_parser, parse_int)
|
||||||
@ -40,11 +40,11 @@ TEST(json_parser, parse_int)
|
|||||||
char text[] = "42";
|
char text[] = "42";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_int(root));
|
ASSERT_TRUE(wfp_impl_json_is_int(root));
|
||||||
ASSERT_EQ(42, wfp_impl_json_get_int(root));
|
ASSERT_EQ(42, wfp_impl_json_get_int(root));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_negative_int)
|
TEST(json_parser, parse_negative_int)
|
||||||
@ -52,11 +52,11 @@ TEST(json_parser, parse_negative_int)
|
|||||||
char text[] = "-1234";
|
char text[] = "-1234";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_int(root));
|
ASSERT_TRUE(wfp_impl_json_is_int(root));
|
||||||
ASSERT_EQ(-1234, wfp_impl_json_get_int(root));
|
ASSERT_EQ(-1234, wfp_impl_json_get_int(root));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_string)
|
TEST(json_parser, parse_string)
|
||||||
@ -64,11 +64,11 @@ TEST(json_parser, parse_string)
|
|||||||
char text[] = "\"brummni\"";
|
char text[] = "\"brummni\"";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_string(root));
|
ASSERT_TRUE(wfp_impl_json_is_string(root));
|
||||||
ASSERT_STREQ("brummni", wfp_impl_json_get_string(root));
|
ASSERT_STREQ("brummni", wfp_impl_json_get_string(root));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_array)
|
TEST(json_parser, parse_array)
|
||||||
@ -76,7 +76,7 @@ TEST(json_parser, parse_array)
|
|||||||
char text[] = "[true,1,\"foo\",[42]]";
|
char text[] = "[true,1,\"foo\",[42]]";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_array(root));
|
ASSERT_TRUE(wfp_impl_json_is_array(root));
|
||||||
ASSERT_EQ(4, wfp_impl_json_array_size(root));
|
ASSERT_EQ(4, wfp_impl_json_array_size(root));
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ TEST(json_parser, parse_array)
|
|||||||
ASSERT_TRUE(wfp_impl_json_is_string(wfp_impl_json_array_get(root, 2)));
|
ASSERT_TRUE(wfp_impl_json_is_string(wfp_impl_json_array_get(root, 2)));
|
||||||
ASSERT_TRUE(wfp_impl_json_is_array(wfp_impl_json_array_get(root, 3)));
|
ASSERT_TRUE(wfp_impl_json_is_array(wfp_impl_json_array_get(root, 3)));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_object)
|
TEST(json_parser, parse_object)
|
||||||
@ -93,7 +93,7 @@ TEST(json_parser, parse_object)
|
|||||||
char text[] = "{\"method\":\"add\",\"params\":[1,2],\"id\":42}";
|
char text[] = "{\"method\":\"add\",\"params\":[1,2],\"id\":42}";
|
||||||
wfp_json_doc * doc = parse_json(text);
|
wfp_json_doc * doc = parse_json(text);
|
||||||
ASSERT_NE(nullptr, doc);
|
ASSERT_NE(nullptr, doc);
|
||||||
wfp_json const * root = wfp_impl_json_root(doc);
|
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||||
ASSERT_TRUE(wfp_impl_json_is_object(root));
|
ASSERT_TRUE(wfp_impl_json_is_object(root));
|
||||||
ASSERT_EQ(3, wfp_impl_json_object_size(root));
|
ASSERT_EQ(3, wfp_impl_json_object_size(root));
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ TEST(json_parser, parse_object)
|
|||||||
ASSERT_STREQ("params", wfp_impl_json_object_key(root, 1));
|
ASSERT_STREQ("params", wfp_impl_json_object_key(root, 1));
|
||||||
ASSERT_STREQ("id", wfp_impl_json_object_key(root, 2));
|
ASSERT_STREQ("id", wfp_impl_json_object_key(root, 2));
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(json_parser, parse_fail_invalid_json)
|
TEST(json_parser, parse_fail_invalid_json)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "webfuse_provider/mocks/mock_request.hpp"
|
#include "webfuse_provider/mocks/mock_request.hpp"
|
||||||
#include "webfuse_provider/impl/json/parser.h"
|
#include "webfuse_provider/impl/json/doc.h"
|
||||||
#include "webfuse_provider/impl/message.h"
|
#include "webfuse_provider/impl/message.h"
|
||||||
#include "webfuse_provider/impl/message_writer.h"
|
#include "webfuse_provider/impl/message_writer.h"
|
||||||
#include "webfuse_provider/status.h"
|
#include "webfuse_provider/status.h"
|
||||||
@ -16,10 +16,10 @@ static void webfuse_test_MockRequest_respond(
|
|||||||
int error_code = WFP_BAD;
|
int error_code = WFP_BAD;
|
||||||
int id = -1;
|
int id = -1;
|
||||||
|
|
||||||
wfp_json_doc * doc = wfp_impl_json_parse_buffer(response->data, response->length);
|
wfp_json_doc * doc = wfp_impl_json_doc_loadb(response->data, response->length);
|
||||||
if (NULL != doc)
|
if (NULL != doc)
|
||||||
{
|
{
|
||||||
wfp_json const * response = wfp_impl_json_root(doc);
|
wfp_json const * response = wfp_impl_json_doc_root(doc);
|
||||||
wfp_json const * result = wfp_impl_json_object_get(response, "result");
|
wfp_json const * result = wfp_impl_json_object_get(response, "result");
|
||||||
wfp_json const * id_holder = wfp_impl_json_object_get(response, "id");
|
wfp_json const * id_holder = wfp_impl_json_object_get(response, "id");
|
||||||
if (wfp_impl_json_is_int(id_holder))
|
if (wfp_impl_json_is_int(id_holder))
|
||||||
@ -46,7 +46,7 @@ static void webfuse_test_MockRequest_respond(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,17 +6,17 @@ namespace webfuse_test
|
|||||||
JsonDoc::JsonDoc(std::string const & json)
|
JsonDoc::JsonDoc(std::string const & json)
|
||||||
: contents(json)
|
: contents(json)
|
||||||
{
|
{
|
||||||
doc = wfp_impl_json_parse(const_cast<char*>(contents.data()));
|
doc = wfp_impl_json_doc_loadb(const_cast<char*>(contents.data()), json.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonDoc::~JsonDoc()
|
JsonDoc::~JsonDoc()
|
||||||
{
|
{
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
wfp_json const * JsonDoc::root()
|
wfp_json const * JsonDoc::root()
|
||||||
{
|
{
|
||||||
return wfp_impl_json_root(doc);
|
return wfp_impl_json_doc_root(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef WFP_TEST_UTIL_JSON_DOC_HPP
|
#ifndef WFP_TEST_UTIL_JSON_DOC_HPP
|
||||||
#define WFP_TEST_UTIL_JSON_DOC_HPP
|
#define WFP_TEST_UTIL_JSON_DOC_HPP
|
||||||
|
|
||||||
#include "webfuse_provider/impl/json/parser.h"
|
#include "webfuse_provider/impl/json/doc.h"
|
||||||
#include "webfuse_provider/impl/json/node.h"
|
#include "webfuse_provider/impl/json/node.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "webfuse_provider/test_util/webfuse_server.hpp"
|
#include "webfuse_provider/test_util/webfuse_server.hpp"
|
||||||
#include "webfuse_provider/impl/util/lws_log.h"
|
#include "webfuse_provider/impl/util/lws_log.h"
|
||||||
#include "webfuse_provider/protocol_names.h"
|
#include "webfuse_provider/protocol_names.h"
|
||||||
#include "webfuse_provider/impl/json/parser.h"
|
#include "webfuse_provider/impl/json/doc.h"
|
||||||
#include "webfuse_provider/impl/json/node.h"
|
#include "webfuse_provider/impl/json/node.h"
|
||||||
|
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
@ -198,10 +198,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wfp_json_doc * doc = wfp_impl_json_parse_buffer(data, length);
|
wfp_json_doc * doc = wfp_impl_json_doc_loadb(data, length);
|
||||||
if (doc)
|
if (doc)
|
||||||
{
|
{
|
||||||
wfp_json const * message = wfp_impl_json_root(doc);
|
wfp_json const * message = wfp_impl_json_doc_root(doc);
|
||||||
wfp_json const * method = wfp_impl_json_object_get(message, "method");
|
wfp_json const * method = wfp_impl_json_object_get(message, "method");
|
||||||
if (wfp_impl_json_is_string(method))
|
if (wfp_impl_json_is_string(method))
|
||||||
{
|
{
|
||||||
@ -221,7 +221,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wfp_impl_json_dispose(doc);
|
wfp_impl_json_doc_dispose(doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user