mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
refactor: made jsonrpc an independent library
This commit is contained in:
parent
c6ca2e14bd
commit
e3a3427ca8
@ -37,6 +37,7 @@ add_compile_options(
|
||||
"-pthread"
|
||||
)
|
||||
|
||||
include(jsonrpc)
|
||||
include(webfuse_core)
|
||||
include(webfuse_adapter)
|
||||
include(webfuse_provider)
|
||||
|
13
cmake/jsonrpc.cmake
Normal file
13
cmake/jsonrpc.cmake
Normal file
@ -0,0 +1,13 @@
|
||||
# jsonrpc
|
||||
|
||||
add_library(jsonrpc STATIC
|
||||
lib/jsonrpc/proxy.c
|
||||
lib/jsonrpc/server.c
|
||||
lib/jsonrpc/method.c
|
||||
lib/jsonrpc/request.c
|
||||
lib/jsonrpc/response.c
|
||||
lib/jsonrpc/error.c
|
||||
)
|
||||
|
||||
target_include_directories(jsonrpc PUBLIC lib)
|
||||
set_target_properties(jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden)
|
@ -7,6 +7,13 @@ include(GoogleTest)
|
||||
pkg_check_modules(GMOCK gmock)
|
||||
|
||||
add_executable(alltests
|
||||
test/jsonrpc/test_util.cc
|
||||
test/jsonrpc/test_is_request.cc
|
||||
test/jsonrpc/test_request.cc
|
||||
test/jsonrpc/test_is_response.cc
|
||||
test/jsonrpc/test_response.cc
|
||||
test/jsonrpc/test_server.cc
|
||||
test/jsonrpc/test_proxy.cc
|
||||
test/webfuse/utils/tempdir.cc
|
||||
test/webfuse/utils/file_utils.cc
|
||||
test/webfuse/utils/msleep.cc
|
||||
@ -37,13 +44,6 @@ add_executable(alltests
|
||||
test/webfuse/tests/adapter/test_uuid_mountpoint.cc
|
||||
test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc
|
||||
test/webfuse/tests/adapter/test_fuse_req.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_util.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_is_request.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_request.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_is_response.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_response.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_server.cc
|
||||
test/webfuse/tests/adapter/jsonrpc/test_proxy.cc
|
||||
test/webfuse/tests/provider/test_url.cc
|
||||
test/webfuse/tests/provider/test_client_protocol.cc
|
||||
test/webfuse/tests/integration/test_integration.cc
|
||||
@ -65,6 +65,7 @@ target_link_libraries(alltests PUBLIC
|
||||
webfuse-adapter-static
|
||||
webfuse-provider-static
|
||||
webfuse-core
|
||||
jsonrpc
|
||||
${FUSE3_LIBRARIES}
|
||||
${LWS_LIBRARIES}
|
||||
${JANSSON_LIBRARIES}
|
||||
|
@ -28,12 +28,6 @@ add_library(webfuse-adapter-static STATIC
|
||||
lib/webfuse/adapter/impl/operation/open.c
|
||||
lib/webfuse/adapter/impl/operation/close.c
|
||||
lib/webfuse/adapter/impl/operation/read.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/proxy.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/server.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/method.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/request.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/response.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/util.c
|
||||
)
|
||||
|
||||
target_include_directories(webfuse-adapter-static PRIVATE
|
||||
@ -70,7 +64,7 @@ set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0)
|
||||
set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden)
|
||||
set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT")
|
||||
|
||||
target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core)
|
||||
target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core jsonrpc)
|
||||
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc"
|
||||
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
||||
|
@ -8,6 +8,7 @@ add_library(webfuse-core STATIC
|
||||
lib/webfuse/core/string.c
|
||||
lib/webfuse/core/base64.c
|
||||
lib/webfuse/core/lws_log.c
|
||||
lib/webfuse/core/json_util.c
|
||||
)
|
||||
|
||||
set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core)
|
||||
|
40
include/jsonrpc/method.h
Normal file
40
include/jsonrpc/method.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef JSONRPC_METHOD_H
|
||||
#define JSONRPC_METHOD_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
typedef void jsonrpc_method_invoke_fn(
|
||||
struct jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data);
|
||||
|
||||
struct jsonrpc_method
|
||||
{
|
||||
struct jsonrpc_method * next;
|
||||
char * name;
|
||||
jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct jsonrpc_method * jsonrpc_method_create(
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_method_dispose(
|
||||
struct jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
81
include/jsonrpc/proxy.h
Normal file
81
include/jsonrpc/proxy.h
Normal file
@ -0,0 +1,81 @@
|
||||
#ifndef JSONRPC_PROXY_H
|
||||
#define JSONRPC_PROXY_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void jsonrpc_proxy_finished_fn(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
|
||||
struct jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
jsonrpc_proxy_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_impl_timer timer;
|
||||
};
|
||||
|
||||
struct jsonrpc_proxy
|
||||
{
|
||||
struct jsonrpc_request request;
|
||||
int timeout;
|
||||
jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void jsonrpc_proxy_init(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_proxy_cleanup(
|
||||
struct jsonrpc_proxy * proxy);
|
||||
|
||||
extern void jsonrpc_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void jsonrpc_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void jsonrpc_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
52
include/jsonrpc/request.h
Normal file
52
include/jsonrpc/request.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef JSONRPC_REQUEST_H
|
||||
#define JSONRPC_REQUEST_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
#include "jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
extern bool jsonrpc_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern struct jsonrpc_request * jsonrpc_request_create(
|
||||
int id,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_request_dispose(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern void * jsonrpc_request_get_userdata(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern void jsonrpc_respond(
|
||||
struct jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern void jsonrpc_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
wf_status status);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
40
include/jsonrpc/response.h
Normal file
40
include/jsonrpc/response.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef WF_JSONRPC_RESPONSE_H
|
||||
#define WF_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct jsonrpc_response
|
||||
{
|
||||
json_t * result;
|
||||
json_t * error;
|
||||
int id;
|
||||
};
|
||||
|
||||
extern bool jsonrpc_is_response(
|
||||
json_t * message);
|
||||
|
||||
extern void jsonrpc_response_init(
|
||||
struct jsonrpc_response * response,
|
||||
json_t * message);
|
||||
|
||||
extern void jsonrpc_response_cleanup(
|
||||
struct jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_SEND_FN_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_SEND_FN_H
|
||||
#ifndef JSONRPC_SEND_FN_H
|
||||
#define JSONRPC_SEND_FN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
@ -12,7 +12,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef bool wf_impl_jsonrpc_send_fn(
|
||||
typedef bool jsonrpc_send_fn(
|
||||
json_t * request,
|
||||
void * user_data);
|
||||
|
47
include/jsonrpc/server.h
Normal file
47
include/jsonrpc/server.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef JSONRPC_SERVER_H
|
||||
#define JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
#include "jsonrpc/method.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_server
|
||||
{
|
||||
struct jsonrpc_method * methods;
|
||||
};
|
||||
|
||||
extern void jsonrpc_server_init(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern void jsonrpc_server_cleanup(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern void jsonrpc_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_server_process(
|
||||
struct jsonrpc_server * server,
|
||||
json_t * request,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
10
include/jsonrpc/status.h
Normal file
10
include/jsonrpc/status.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef JSONRPC_STATUS_H
|
||||
#define JSONRPC_STATUS_H
|
||||
|
||||
#define JSONRPC_GOOD 0
|
||||
#define JSONRPC_BAD -1
|
||||
#define JSONRPC_BAD_TIMEOUT -3
|
||||
#define JSONRPC_BAD_BUSY -4
|
||||
#define JSONRPC_BAD_FORMAT -5
|
||||
|
||||
#endif
|
27
lib/jsonrpc/error.c
Normal file
27
lib/jsonrpc/error.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "jsonrpc/error.h"
|
||||
|
||||
json_t *
|
||||
jsonrpc_error(
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(code));
|
||||
json_object_set_new(error, "message", json_string(message));
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void
|
||||
jsonrpc_propate_error(
|
||||
jsonrpc_proxy_finished_fn * finised,
|
||||
void * user_data,
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
json_t * error = jsonrpc_error(code, message);
|
||||
finised(user_data, NULL, error);
|
||||
|
||||
json_decref(error);
|
||||
}
|
||||
|
29
lib/jsonrpc/error.h
Normal file
29
lib/jsonrpc/error.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef JSONRPC_ERROR_H
|
||||
#define JSONRPC_ERROR_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/proxy.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern json_t *
|
||||
jsonrpc_error(
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
extern void
|
||||
jsonrpc_propate_error(
|
||||
jsonrpc_proxy_finished_fn * finised,
|
||||
void * user_data,
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,13 +1,13 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/method.h"
|
||||
#include "jsonrpc/method.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create(
|
||||
struct jsonrpc_method * jsonrpc_method_create(
|
||||
char const * method_name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * method = malloc(sizeof(struct wf_impl_jsonrpc_method));
|
||||
struct jsonrpc_method * method = malloc(sizeof(struct jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
@ -19,8 +19,8 @@ struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create(
|
||||
return method;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_method_dispose(
|
||||
struct wf_impl_jsonrpc_method * method)
|
||||
void jsonrpc_method_dispose(
|
||||
struct jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
@ -1,16 +1,18 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "jsonrpc/response.h"
|
||||
#include "jsonrpc/error.h"
|
||||
#include "jsonrpc/status.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
static void wf_impl_jsonrpc_proxy_timeout(
|
||||
static void jsonrpc_proxy_timeout(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
struct wf_impl_jsonrpc_proxy * proxy = timer->user_data;
|
||||
struct jsonrpc_proxy * proxy = timer->user_data;
|
||||
|
||||
if (proxy->request.is_pending)
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
void * user_data = proxy->request.user_data;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
@ -19,11 +21,11 @@ static void wf_impl_jsonrpc_proxy_timeout(
|
||||
proxy->request.finished = NULL;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD_TIMEOUT, NULL);
|
||||
jsonrpc_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout");
|
||||
}
|
||||
}
|
||||
|
||||
static json_t * wf_impl_jsonrpc_request_create(
|
||||
static json_t * jsonrpc_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
||||
@ -67,11 +69,11 @@ static json_t * wf_impl_jsonrpc_request_create(
|
||||
return request;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_proxy_init(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
void jsonrpc_proxy_init(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
int timeout,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
proxy->send = send;
|
||||
@ -82,13 +84,13 @@ void wf_impl_jsonrpc_proxy_init(
|
||||
wf_impl_timer_init(&proxy->request.timer, timeout_manager);
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_proxy_cleanup(
|
||||
struct wf_impl_jsonrpc_proxy * proxy)
|
||||
void jsonrpc_proxy_cleanup(
|
||||
struct jsonrpc_proxy * proxy)
|
||||
{
|
||||
if (proxy->request.is_pending)
|
||||
{
|
||||
void * user_data = proxy->request.user_data;
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
proxy->request.finished = NULL;
|
||||
@ -96,15 +98,15 @@ void wf_impl_jsonrpc_proxy_cleanup(
|
||||
proxy->request.id = 0;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
jsonrpc_propate_error(finished, user_data, JSONRPC_BAD, "Bad");
|
||||
}
|
||||
|
||||
wf_impl_timer_cleanup(&proxy->request.timer);
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_proxy_invoke(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished,
|
||||
void jsonrpc_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
@ -118,11 +120,11 @@ void wf_impl_jsonrpc_proxy_invoke(
|
||||
proxy->request.user_data = user_data;
|
||||
proxy->request.id = 42;
|
||||
wf_impl_timer_start(&proxy->request.timer, wf_impl_timepoint_in_msec(proxy->timeout),
|
||||
&wf_impl_jsonrpc_proxy_timeout, proxy);
|
||||
&jsonrpc_proxy_timeout, proxy);
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
|
||||
json_t * request = jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
|
||||
va_end(args);
|
||||
|
||||
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
|
||||
@ -134,8 +136,7 @@ void wf_impl_jsonrpc_proxy_invoke(
|
||||
proxy->request.id = 0;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
|
||||
jsonrpc_propate_error(finished, user_data, JSONRPC_BAD, "Bad");
|
||||
}
|
||||
|
||||
if (NULL != request)
|
||||
@ -145,12 +146,12 @@ void wf_impl_jsonrpc_proxy_invoke(
|
||||
}
|
||||
else
|
||||
{
|
||||
finished(user_data, WF_BAD_BUSY, NULL);
|
||||
jsonrpc_propate_error(finished, user_data, JSONRPC_BAD_BUSY, "Busy");
|
||||
}
|
||||
}
|
||||
|
||||
extern void wf_impl_jsonrpc_proxy_notify(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
extern void jsonrpc_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
@ -158,7 +159,7 @@ extern void wf_impl_jsonrpc_proxy_notify(
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, 0, param_info, args);
|
||||
json_t * request = jsonrpc_request_create(method_name, 0, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
{
|
||||
@ -168,16 +169,16 @@ extern void wf_impl_jsonrpc_proxy_notify(
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_jsonrpc_proxy_onresult(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
void jsonrpc_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
json_t * message)
|
||||
{
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
wf_impl_jsonrpc_response_init(&response, message);
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_response_init(&response, message);
|
||||
|
||||
if ((proxy->request.is_pending) && (response.id == proxy->request.id))
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
void * user_data = proxy->request.user_data;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
@ -186,9 +187,9 @@ void wf_impl_jsonrpc_proxy_onresult(
|
||||
proxy->request.finished = NULL;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, response.status, response.result);
|
||||
finished(user_data, response.result, response.error);
|
||||
}
|
||||
|
||||
wf_impl_jsonrpc_response_cleanup(&response);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "webfuse/core/status_intern.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct wf_impl_jsonrpc_request
|
||||
struct jsonrpc_request
|
||||
{
|
||||
int id;
|
||||
wf_impl_jsonrpc_send_fn * send;
|
||||
jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
bool wf_impl_jsonrpc_is_request(
|
||||
bool jsonrpc_is_request(
|
||||
json_t * message)
|
||||
{
|
||||
json_t * id = json_object_get(message, "id");
|
||||
@ -21,12 +21,12 @@ bool wf_impl_jsonrpc_is_request(
|
||||
}
|
||||
|
||||
|
||||
struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
||||
struct jsonrpc_request * jsonrpc_request_create(
|
||||
int id,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_jsonrpc_request * request = malloc(sizeof(struct wf_impl_jsonrpc_request));
|
||||
struct jsonrpc_request * request = malloc(sizeof(struct jsonrpc_request));
|
||||
if (NULL != request)
|
||||
{
|
||||
request->id = id;
|
||||
@ -37,21 +37,21 @@ struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
||||
return request;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_request_dispose(
|
||||
struct wf_impl_jsonrpc_request * request)
|
||||
void jsonrpc_request_dispose(
|
||||
struct jsonrpc_request * request)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
void * wf_impl_jsonrpc_request_get_userdata(
|
||||
struct wf_impl_jsonrpc_request * request)
|
||||
void * jsonrpc_request_get_userdata(
|
||||
struct jsonrpc_request * request)
|
||||
{
|
||||
return request->user_data;
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_jsonrpc_respond(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
void jsonrpc_respond(
|
||||
struct jsonrpc_request * request,
|
||||
json_t * result)
|
||||
{
|
||||
json_t * response = json_object();
|
||||
@ -60,11 +60,11 @@ void wf_impl_jsonrpc_respond(
|
||||
|
||||
request->send(response, request->user_data);
|
||||
json_decref(response);
|
||||
wf_impl_jsonrpc_request_dispose(request);
|
||||
jsonrpc_request_dispose(request);
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_respond_error(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
void jsonrpc_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
wf_status status)
|
||||
{
|
||||
json_t * err = json_object();
|
||||
@ -77,6 +77,6 @@ void wf_impl_jsonrpc_respond_error(
|
||||
|
||||
request->send(response, request->user_data);
|
||||
json_decref(response);
|
||||
wf_impl_jsonrpc_request_dispose(request);
|
||||
jsonrpc_request_dispose(request);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
#include "jsonrpc/response.h"
|
||||
#include "jsonrpc/error.h"
|
||||
#include "jsonrpc/status.h"
|
||||
|
||||
extern bool wf_impl_jsonrpc_is_response(
|
||||
extern bool jsonrpc_is_response(
|
||||
json_t * message)
|
||||
{
|
||||
json_t * id = json_object_get(message, "id");
|
||||
@ -12,22 +14,21 @@ extern bool wf_impl_jsonrpc_is_response(
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_jsonrpc_response_init(
|
||||
struct wf_impl_jsonrpc_response * result,
|
||||
void jsonrpc_response_init(
|
||||
struct jsonrpc_response * result,
|
||||
json_t * response)
|
||||
{
|
||||
result->status = WF_BAD;
|
||||
result->id = -1;
|
||||
result->result = NULL;
|
||||
result->error = NULL;
|
||||
|
||||
json_t * id_holder = json_object_get(response, "id");
|
||||
if ((NULL == id_holder) || (!json_is_integer(id_holder)))
|
||||
{
|
||||
result->status = WF_BAD_FORMAT;
|
||||
result->error = jsonrpc_error(JSONRPC_BAD_FORMAT, "invalid format: missing id");
|
||||
return;
|
||||
}
|
||||
|
||||
result->status = WF_GOOD;
|
||||
result->id = json_integer_value(id_holder);
|
||||
result->result = json_object_get(response, "result");
|
||||
if (NULL != result->result)
|
||||
@ -36,25 +37,29 @@ void wf_impl_jsonrpc_response_init(
|
||||
}
|
||||
else
|
||||
{
|
||||
result->status = WF_BAD_FORMAT;
|
||||
|
||||
json_t * error = json_object_get(response, "error");
|
||||
if (NULL != error)
|
||||
if ((json_is_object(error)) && (json_is_integer(json_object_get(error, "code"))))
|
||||
{
|
||||
json_t * error_code = json_object_get(error, "code");
|
||||
if ((NULL != error_code) && (json_is_integer(error_code)))
|
||||
{
|
||||
result->status = json_integer_value(error_code);
|
||||
}
|
||||
result->error = error;
|
||||
json_incref(result->error);
|
||||
}
|
||||
else
|
||||
{
|
||||
result->error = jsonrpc_error(JSONRPC_BAD_FORMAT, "invalid format: invalid error object");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_response_cleanup(
|
||||
struct wf_impl_jsonrpc_response * response)
|
||||
void jsonrpc_response_cleanup(
|
||||
struct jsonrpc_response * response)
|
||||
{
|
||||
if (NULL != response->result)
|
||||
{
|
||||
json_decref(response->result);
|
||||
}
|
||||
|
||||
if (NULL != response->error)
|
||||
{
|
||||
json_decref(response->error);
|
||||
}
|
||||
}
|
95
lib/jsonrpc/server.c
Normal file
95
lib/jsonrpc/server.c
Normal file
@ -0,0 +1,95 @@
|
||||
#include "jsonrpc/server.h"
|
||||
#include "jsonrpc/method.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void jsonrpc_server_init(
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void jsonrpc_server_cleanup(
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
struct jsonrpc_method * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
struct jsonrpc_method * next = current->next;
|
||||
jsonrpc_method_dispose(current);
|
||||
current = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void jsonrpc_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct jsonrpc_method * method = jsonrpc_method_create(method_name, invoke, user_data);
|
||||
method->next = server->methods;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
static void jsonrpc_server_invalid_method_invoke(
|
||||
struct jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * WF_UNUSED_PARAM(params),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
static struct jsonrpc_method const jsonrpc_server_invalid_method =
|
||||
{
|
||||
.next = NULL,
|
||||
.name = "<invalid>",
|
||||
.invoke = &jsonrpc_server_invalid_method_invoke,
|
||||
.user_data = NULL
|
||||
};
|
||||
|
||||
static struct jsonrpc_method const * jsonrpc_server_get_method(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name)
|
||||
{
|
||||
struct jsonrpc_method const * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
if (0 == strcmp(method_name, current->name))
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return &jsonrpc_server_invalid_method;
|
||||
}
|
||||
|
||||
void jsonrpc_server_process(
|
||||
struct jsonrpc_server * server,
|
||||
json_t * request_data,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
json_t * method_holder = json_object_get(request_data, "method");
|
||||
json_t * params = json_object_get(request_data, "params");
|
||||
json_t * id_holder = json_object_get(request_data, "id");
|
||||
|
||||
if (json_is_string(method_holder) &&
|
||||
(json_is_array(params) || (json_is_object(params))) &&
|
||||
json_is_integer(id_holder))
|
||||
{
|
||||
char const * method_name = json_string_value(method_holder);
|
||||
int id = json_integer_value(id_holder);
|
||||
struct jsonrpc_request * request = jsonrpc_request_create(id, send, user_data);
|
||||
struct jsonrpc_method const * method = jsonrpc_server_get_method(server, method_name);
|
||||
|
||||
method->invoke(request, method_name, params, method->user_data);
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_request;
|
||||
|
||||
typedef void wf_impl_jsonrpc_method_invoke_fn(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data);
|
||||
|
||||
struct wf_impl_jsonrpc_method
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * next;
|
||||
char * name;
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create(
|
||||
char const * method_name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_jsonrpc_method_dispose(
|
||||
struct wf_impl_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,82 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_PROXY_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_PROXY_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/send_fn.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void wf_impl_jsonrpc_proxy_finished_fn(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
|
||||
struct wf_impl_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_impl_timer timer;
|
||||
};
|
||||
|
||||
struct wf_impl_jsonrpc_proxy
|
||||
{
|
||||
struct wf_impl_jsonrpc_request request;
|
||||
int timeout;
|
||||
wf_impl_jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void wf_impl_jsonrpc_proxy_init(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
int timeout,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_jsonrpc_proxy_cleanup(
|
||||
struct wf_impl_jsonrpc_proxy * proxy);
|
||||
|
||||
extern void wf_impl_jsonrpc_proxy_invoke(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wf_impl_jsonrpc_proxy_notify(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wf_impl_jsonrpc_proxy_onresult(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,52 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_request;
|
||||
|
||||
extern bool wf_impl_jsonrpc_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
||||
int id,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_jsonrpc_request_dispose(
|
||||
struct wf_impl_jsonrpc_request * request);
|
||||
|
||||
extern void * wf_impl_jsonrpc_request_get_userdata(
|
||||
struct wf_impl_jsonrpc_request * request);
|
||||
|
||||
extern void wf_impl_jsonrpc_respond(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern void wf_impl_jsonrpc_respond_error(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
wf_status status);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,41 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_response
|
||||
{
|
||||
wf_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
extern bool wf_impl_jsonrpc_is_response(
|
||||
json_t * message);
|
||||
|
||||
extern void wf_impl_jsonrpc_response_init(
|
||||
struct wf_impl_jsonrpc_response * response,
|
||||
json_t * message);
|
||||
|
||||
extern void wf_impl_jsonrpc_response_cleanup(
|
||||
struct wf_impl_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,95 +0,0 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/method.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void wf_impl_jsonrpc_server_init(
|
||||
struct wf_impl_jsonrpc_server * server)
|
||||
{
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_cleanup(
|
||||
struct wf_impl_jsonrpc_server * server)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * next = current->next;
|
||||
wf_impl_jsonrpc_method_dispose(current);
|
||||
current = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_add(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * method = wf_impl_jsonrpc_method_create(method_name, invoke, user_data);
|
||||
method->next = server->methods;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
static void wf_impl_jsonrpc_server_invalid_method_invoke(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * WF_UNUSED_PARAM(params),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wf_impl_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
static struct wf_impl_jsonrpc_method const wf_impl_jsonrpc_server_invalid_method =
|
||||
{
|
||||
.next = NULL,
|
||||
.name = "<invalid>",
|
||||
.invoke = &wf_impl_jsonrpc_server_invalid_method_invoke,
|
||||
.user_data = NULL
|
||||
};
|
||||
|
||||
static struct wf_impl_jsonrpc_method const * wf_impl_jsonrpc_server_get_method(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * method_name)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method const * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
if (0 == strcmp(method_name, current->name))
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return &wf_impl_jsonrpc_server_invalid_method;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_process(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
json_t * request_data,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
json_t * method_holder = json_object_get(request_data, "method");
|
||||
json_t * params = json_object_get(request_data, "params");
|
||||
json_t * id_holder = json_object_get(request_data, "id");
|
||||
|
||||
if (json_is_string(method_holder) &&
|
||||
(json_is_array(params) || (json_is_object(params))) &&
|
||||
json_is_integer(id_holder))
|
||||
{
|
||||
char const * method_name = json_string_value(method_holder);
|
||||
int id = json_integer_value(id_holder);
|
||||
struct wf_impl_jsonrpc_request * request = wf_impl_jsonrpc_request_create(id, send, user_data);
|
||||
struct wf_impl_jsonrpc_method const * method = wf_impl_jsonrpc_server_get_method(server, method_name);
|
||||
|
||||
method->invoke(request, method_name, params, method->user_data);
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/send_fn.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/method.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_server
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * methods;
|
||||
};
|
||||
|
||||
extern void wf_impl_jsonrpc_server_init(
|
||||
struct wf_impl_jsonrpc_server * server);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_cleanup(
|
||||
struct wf_impl_jsonrpc_server * server);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_add(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_process(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
json_t * request,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
|
||||
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
{
|
||||
int result = default_value;
|
||||
|
||||
json_t * holder = json_object_get(object, key);
|
||||
if ((NULL != holder) && (json_is_integer(holder)))
|
||||
{
|
||||
result = json_integer_value(holder);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSON_UTIL_H
|
||||
#define WF_ADAPTER_IMPL_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wf_impl_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wf_impl_operation_close(
|
||||
@ -13,12 +13,12 @@ void wf_impl_operation_close(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
}
|
||||
|
||||
fuse_reply_err(request, 0);
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wf_impl_operation_getattr_context
|
||||
@ -22,16 +22,17 @@ struct wf_impl_operation_getattr_context
|
||||
|
||||
static void wf_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * data)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_getattr_context * context = user_data;
|
||||
|
||||
struct stat buffer;
|
||||
if (NULL != data)
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * mode_holder = json_object_get(data, "mode");
|
||||
json_t * type_holder = json_object_get(data, "type");
|
||||
json_t * mode_holder = json_object_get(result, "mode");
|
||||
json_t * type_holder = json_object_get(result, "type");
|
||||
if ((NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
||||
{
|
||||
@ -52,10 +53,10 @@ static void wf_impl_operation_getattr_finished(
|
||||
buffer.st_uid = context->uid;
|
||||
buffer.st_gid = context->gid;
|
||||
buffer.st_nlink = 1;
|
||||
buffer.st_size = wf_impl_json_get_int(data, "size", 0);
|
||||
buffer.st_atime = wf_impl_json_get_int(data, "atime", 0);
|
||||
buffer.st_mtime = wf_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.st_ctime = wf_impl_json_get_int(data, "ctime", 0);
|
||||
buffer.st_size = wf_impl_json_get_int(result, "size", 0);
|
||||
buffer.st_atime = wf_impl_json_get_int(result, "atime", 0);
|
||||
buffer.st_mtime = wf_impl_json_get_int(result, "mtime", 0);
|
||||
buffer.st_ctime = wf_impl_json_get_int(result, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -82,7 +83,7 @@ void wf_impl_operation_getattr (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@ -93,7 +94,7 @@ void wf_impl_operation_getattr (
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wf_impl_operation_lookup_context
|
||||
@ -24,18 +24,19 @@ struct wf_impl_operation_lookup_context
|
||||
|
||||
static void wf_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * data
|
||||
json_t const * result,
|
||||
json_t const * error
|
||||
)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_lookup_context * context = user_data;
|
||||
struct fuse_entry_param buffer;
|
||||
|
||||
if (NULL != data)
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * inode_holder = json_object_get(data, "inode");
|
||||
json_t * mode_holder = json_object_get(data, "mode");
|
||||
json_t * type_holder = json_object_get(data, "type");
|
||||
json_t * inode_holder = json_object_get(result, "inode");
|
||||
json_t * mode_holder = json_object_get(result, "mode");
|
||||
json_t * type_holder = json_object_get(result, "type");
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)) &&
|
||||
(NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
||||
@ -61,10 +62,10 @@ static void wf_impl_operation_lookup_finished(
|
||||
buffer.attr.st_uid = context->uid;
|
||||
buffer.attr.st_gid = context->gid;
|
||||
buffer.attr.st_nlink = 1;
|
||||
buffer.attr.st_size = wf_impl_json_get_int(data, "size", 0);
|
||||
buffer.attr.st_atime = wf_impl_json_get_int(data, "atime", 0);
|
||||
buffer.attr.st_mtime = wf_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.attr.st_ctime = wf_impl_json_get_int(data, "ctime", 0);
|
||||
buffer.attr.st_size = wf_impl_json_get_int(result, "size", 0);
|
||||
buffer.attr.st_atime = wf_impl_json_get_int(result, "atime", 0);
|
||||
buffer.attr.st_mtime = wf_impl_json_get_int(result, "mtime", 0);
|
||||
buffer.attr.st_ctime = wf_impl_json_get_int(result, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -91,7 +92,7 @@ void wf_impl_operation_lookup (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@ -101,7 +102,7 @@ void wf_impl_operation_lookup (
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4,15 +4,17 @@
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
static void wf_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
fuse_req_t request = user_data;
|
||||
struct fuse_file_info file_info;
|
||||
memset(&file_info, 0, sizeof(struct fuse_file_info));
|
||||
@ -47,11 +49,11 @@ void wf_impl_operation_open(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5,8 +5,9 @@
|
||||
#include <limits.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/base64.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
#define WF_MAX_READ_LENGTH 4096
|
||||
|
||||
@ -38,17 +39,21 @@ static char * wf_impl_fill_buffer(
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void wf_impl_operation_read_finished(void * user_data, wf_status status, json_t const * data)
|
||||
static void wf_impl_operation_read_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
fuse_req_t request = user_data;
|
||||
|
||||
char * buffer = NULL;
|
||||
size_t length = 0;
|
||||
if (NULL != data)
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * data_holder = json_object_get(data, "data");
|
||||
json_t * format_holder = json_object_get(data, "format");
|
||||
json_t * count_holder = json_object_get(data, "count");
|
||||
json_t * data_holder = json_object_get(result, "data");
|
||||
json_t * format_holder = json_object_get(result, "format");
|
||||
json_t * count_holder = json_object_get(result, "count");
|
||||
|
||||
if (json_is_string(data_holder) &&
|
||||
json_is_string(format_holder) &&
|
||||
@ -87,13 +92,13 @@ void wf_impl_operation_read(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -8,8 +8,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
|
||||
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
||||
@ -73,9 +74,10 @@ static size_t wf_impl_min(size_t a, size_t b)
|
||||
|
||||
static void wf_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_readdir_context * context = user_data;
|
||||
|
||||
struct wf_impl_dirbuffer buffer;
|
||||
@ -137,7 +139,7 @@ void wf_impl_operation_readdir (
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@ -146,7 +148,7 @@ void wf_impl_operation_readdir (
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include <stddef.h>
|
||||
|
||||
struct wf_impl_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context)
|
||||
{
|
||||
struct wf_impl_jsonrpc_proxy * proxy = NULL;
|
||||
struct jsonrpc_proxy * proxy = NULL;
|
||||
|
||||
struct wf_impl_session * session = context->session;
|
||||
if (NULL != session)
|
||||
|
@ -8,7 +8,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_impl_session;
|
||||
struct wf_impl_jsonrpc_proxy;
|
||||
struct jsonrpc_proxy;
|
||||
|
||||
struct wf_impl_operations_context
|
||||
{
|
||||
@ -49,7 +49,7 @@ extern void wf_impl_operation_read(
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
extern struct wf_impl_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
extern struct jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||
|
||||
static int wf_impl_server_protocol_callback(
|
||||
@ -129,7 +129,7 @@ void wf_impl_server_protocol_init_lws(
|
||||
}
|
||||
|
||||
static void wf_impl_server_protocol_authenticate(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
struct jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * params,
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
@ -145,7 +145,7 @@ static void wf_impl_server_protocol_authenticate(
|
||||
struct wf_credentials creds;
|
||||
|
||||
wf_impl_credentials_init(&creds, type, creds_holder);
|
||||
struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request);
|
||||
struct wf_impl_session * session = jsonrpc_request_get_userdata(request);
|
||||
result = wf_impl_session_authenticate(session, &creds);
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
@ -155,11 +155,11 @@ static void wf_impl_server_protocol_authenticate(
|
||||
if (result)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
wf_impl_jsonrpc_respond(request, result);
|
||||
jsonrpc_respond(request, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_impl_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED);
|
||||
jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,12 +179,12 @@ static bool wf_impl_server_protocol_check_name(char const * value)
|
||||
}
|
||||
|
||||
static void wf_impl_server_protocol_add_filesystem(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
struct jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * params,
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request);
|
||||
struct wf_impl_session * session = jsonrpc_request_get_userdata(request);
|
||||
wf_status status = (session->is_authenticated) ? WF_GOOD : WF_BAD_ACCESS_DENIED;
|
||||
|
||||
char const * name = NULL;
|
||||
@ -218,11 +218,11 @@ static void wf_impl_server_protocol_add_filesystem(
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "id", json_string(name));
|
||||
wf_impl_jsonrpc_respond(request, result);
|
||||
jsonrpc_respond(request, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_impl_jsonrpc_respond_error(request, status);
|
||||
jsonrpc_respond_error(request, status);
|
||||
}
|
||||
|
||||
|
||||
@ -240,9 +240,9 @@ void wf_impl_server_protocol_init(
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
wf_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wf_impl_jsonrpc_server_init(&protocol->server);
|
||||
wf_impl_jsonrpc_server_add(&protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol);
|
||||
wf_impl_jsonrpc_server_add(&protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol);
|
||||
jsonrpc_server_init(&protocol->server);
|
||||
jsonrpc_server_add(&protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol);
|
||||
jsonrpc_server_add(&protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_cleanup(
|
||||
@ -250,7 +250,7 @@ void wf_impl_server_protocol_cleanup(
|
||||
{
|
||||
protocol->is_operational = false;
|
||||
|
||||
wf_impl_jsonrpc_server_cleanup(&protocol->server);
|
||||
jsonrpc_server_cleanup(&protocol->server);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
|
@ -1,12 +1,12 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "jsonrpc/server.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
@ -25,7 +25,7 @@ struct wf_server_protocol
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_mountpoint_factory mountpoint_factory;
|
||||
struct wf_impl_session_manager session_manager;
|
||||
struct wf_impl_jsonrpc_server server;
|
||||
struct jsonrpc_server server;
|
||||
bool is_operational;
|
||||
};
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "jsonrpc/response.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
@ -24,7 +24,7 @@ static bool wf_impl_session_send(
|
||||
struct wf_impl_session * session = user_data;
|
||||
struct wf_message * message = wf_message_create(request);
|
||||
|
||||
bool result = (session->is_authenticated || wf_impl_jsonrpc_is_response(request)) && (NULL != session->wsi);
|
||||
bool result = (session->is_authenticated || jsonrpc_is_response(request)) && (NULL != session->wsi);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@ -45,7 +45,7 @@ struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
struct jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory)
|
||||
{
|
||||
|
||||
@ -59,7 +59,7 @@ struct wf_impl_session * wf_impl_session_create(
|
||||
session->authenticators = authenticators;
|
||||
session->server = server;
|
||||
session->mountpoint_factory = mountpoint_factory;
|
||||
wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
wf_slist_init(&session->messages);
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ static void wf_impl_session_dispose_filesystems(
|
||||
void wf_impl_session_dispose(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_cleanup(&session->rpc);
|
||||
jsonrpc_proxy_cleanup(&session->rpc);
|
||||
wf_message_queue_cleanup(&session->messages);
|
||||
|
||||
wf_impl_session_dispose_filesystems(&session->filesystems);
|
||||
@ -159,13 +159,13 @@ void wf_impl_session_receive(
|
||||
json_t * message = json_loadb(data, length, 0, NULL);
|
||||
if (NULL != message)
|
||||
{
|
||||
if (wf_impl_jsonrpc_is_response(message))
|
||||
if (jsonrpc_is_response(message))
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_onresult(&session->rpc, message);
|
||||
jsonrpc_proxy_onresult(&session->rpc, message);
|
||||
}
|
||||
else if (wf_impl_jsonrpc_is_request(message))
|
||||
else if (jsonrpc_is_request(message))
|
||||
{
|
||||
wf_impl_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
|
||||
jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
|
||||
}
|
||||
|
||||
json_decref(message);
|
||||
|
@ -10,8 +10,8 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/core/slist.h"
|
||||
|
||||
@ -35,8 +35,8 @@ struct wf_impl_session
|
||||
struct wf_slist messages;
|
||||
struct wf_impl_authenticators * authenticators;
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory;
|
||||
struct wf_impl_jsonrpc_server * server;
|
||||
struct wf_impl_jsonrpc_proxy rpc;
|
||||
struct jsonrpc_server * server;
|
||||
struct jsonrpc_proxy rpc;
|
||||
struct wf_slist filesystems;
|
||||
};
|
||||
|
||||
@ -44,7 +44,7 @@ extern struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
struct jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory);
|
||||
|
||||
extern void wf_impl_session_dispose(
|
||||
|
@ -29,7 +29,7 @@ struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server)
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
struct wf_impl_session * session = wf_impl_session_create(
|
||||
wsi, authenticators, timeout_manager, server, mountpoint_factory);
|
||||
|
@ -16,7 +16,7 @@ extern "C"
|
||||
|
||||
struct lws;
|
||||
struct wf_impl_timeout_manager;
|
||||
struct wf_impl_jsonrpc_server;
|
||||
struct jsonrpc_server;
|
||||
|
||||
struct wf_impl_session_manager
|
||||
{
|
||||
@ -35,7 +35,7 @@ extern struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server);
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
|
48
lib/webfuse/core/json_util.c
Normal file
48
lib/webfuse/core/json_util.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "jsonrpc/status.h"
|
||||
|
||||
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
{
|
||||
int result = default_value;
|
||||
|
||||
json_t * holder = json_object_get(object, key);
|
||||
if ((NULL != holder) && (json_is_integer(holder)))
|
||||
{
|
||||
result = json_integer_value(holder);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static wf_status wf_impl_jsonrc_code_to_status(int code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case JSONRPC_GOOD:
|
||||
return WF_GOOD;
|
||||
case JSONRPC_BAD:
|
||||
return WF_BAD;
|
||||
case JSONRPC_BAD_BUSY:
|
||||
return WF_BAD_BUSY;
|
||||
case JSONRPC_BAD_TIMEOUT:
|
||||
return WF_BAD_TIMEOUT;
|
||||
case JSONRPC_BAD_FORMAT:
|
||||
return WF_BAD_FORMAT;
|
||||
default:
|
||||
return (wf_status) code;
|
||||
}
|
||||
}
|
||||
|
||||
wf_status
|
||||
wf_impl_jsonrpc_get_status(
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = WF_GOOD;
|
||||
if (NULL != error)
|
||||
{
|
||||
int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT);
|
||||
status = wf_impl_jsonrc_code_to_status(code);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
26
lib/webfuse/core/json_util.h
Normal file
26
lib/webfuse/core/json_util.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef WF_JSON_UTIL_H
|
||||
#define WF_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int
|
||||
wf_impl_json_get_int(
|
||||
json_t const * object,
|
||||
char const * key,
|
||||
int default_value);
|
||||
|
||||
extern wf_status
|
||||
wf_impl_jsonrpc_get_status(
|
||||
json_t const * error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "jsonrpc/request.h"
|
||||
|
||||
TEST(jsonrpc_is_request, request_with_object_params)
|
||||
{
|
||||
@ -8,7 +8,7 @@ TEST(jsonrpc_is_request, request_with_object_params)
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_TRUE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -20,14 +20,14 @@ TEST(jsonrpc_is_request, request_with_array_params)
|
||||
json_object_set_new(request, "params", json_array());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_TRUE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, null_request)
|
||||
{
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(nullptr));
|
||||
ASSERT_FALSE(jsonrpc_is_request(nullptr));
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request)
|
||||
@ -37,7 +37,7 @@ TEST(jsonrpc_is_request, invalid_request)
|
||||
json_array_append_new(request, json_object());
|
||||
json_array_append_new(request, json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -48,7 +48,7 @@ TEST(jsonrpc_is_request, invalid_request_without_id)
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "params", json_object());
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -60,7 +60,7 @@ TEST(jsonrpc_is_request, invalid_request_due_to_invalid_id)
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_string("42"));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -71,7 +71,7 @@ TEST(jsonrpc_is_request, invalid_request_without_method)
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -83,7 +83,7 @@ TEST(jsonrpc_is_request, invalid_request_due_to_invalid_method)
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -94,7 +94,7 @@ TEST(jsonrpc_is_request, invalid_request_without_params)
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
@ -106,7 +106,7 @@ TEST(jsonrpc_is_request, invalid_request_due_to_invalid_params)
|
||||
json_object_set_new(request, "params", json_string("params"));
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
#include "jsonrpc/response.h"
|
||||
|
||||
TEST(jsonrpc_is_response, valid_result)
|
||||
{
|
||||
@ -7,7 +7,7 @@ TEST(jsonrpc_is_response, valid_result)
|
||||
json_object_set_new(message, "result", json_object());
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_TRUE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
@ -18,7 +18,7 @@ TEST(jsonrpc_is_response, valid_result_string)
|
||||
json_object_set_new(message, "result", json_string("also valid"));
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_TRUE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
@ -29,14 +29,14 @@ TEST(jsonrpc_is_response, valid_error)
|
||||
json_object_set_new(message, "error", json_object());
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_TRUE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_null)
|
||||
{
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_response(nullptr));
|
||||
ASSERT_FALSE(jsonrpc_is_response(nullptr));
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_message)
|
||||
@ -45,7 +45,7 @@ TEST(jsonrpc_is_response, invalid_message)
|
||||
json_array_append_new(message, json_object());
|
||||
json_array_append_new(message, json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
@ -55,7 +55,7 @@ TEST(jsonrpc_is_response, invalid_missing_id)
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "result", json_object());
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
@ -66,7 +66,7 @@ TEST(jsonrpc_is_response, invalid_id_wrong_type)
|
||||
json_object_set_new(message, "result", json_object());
|
||||
json_object_set_new(message, "id", json_string("42"));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
@ -77,7 +77,7 @@ TEST(jsonrpc_is_response, invalid_missing_result_and_error)
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
@ -88,7 +88,7 @@ TEST(jsonrpc_is_response, invalid_error_wrong_type)
|
||||
json_object_set_new(message, "error", json_array());
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/utils/msleep.hpp"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
using webfuse_test::msleep;
|
||||
|
||||
@ -47,13 +48,13 @@ namespace
|
||||
struct FinishedContext
|
||||
{
|
||||
bool is_called;
|
||||
wf_status status;
|
||||
json_t * result;
|
||||
json_t * error;
|
||||
|
||||
FinishedContext()
|
||||
: is_called(false)
|
||||
, status(WF_BAD)
|
||||
, result(nullptr)
|
||||
, error(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
@ -64,18 +65,23 @@ namespace
|
||||
{
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
if (nullptr != error)
|
||||
{
|
||||
json_decref(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void jsonrpc_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
struct json_t const * result)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
FinishedContext * context = reinterpret_cast<FinishedContext*>(user_data);
|
||||
context->is_called = true;
|
||||
context->status = status;
|
||||
context->result = json_deep_copy(result);
|
||||
context->error = json_deep_copy(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,10 +92,10 @@ TEST(jsonrpc_proxy, init)
|
||||
|
||||
SendContext context;
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
|
||||
ASSERT_FALSE(context.is_called);
|
||||
@ -102,12 +108,12 @@ TEST(jsonrpc_proxy, invoke)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -129,11 +135,11 @@ TEST(jsonrpc_proxy, invoke)
|
||||
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_FALSE(WF_GOOD == finished_context.status);
|
||||
ASSERT_FALSE(nullptr == finished_context.error);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails)
|
||||
@ -143,20 +149,20 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails)
|
||||
|
||||
SendContext send_context(false);
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_FALSE(WF_GOOD == finished_context.status);
|
||||
ASSERT_FALSE(nullptr == finished_context.error);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -167,16 +173,16 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
FinishedContext finished_context2;
|
||||
void * finished_data2 = reinterpret_cast<void*>(&finished_context2);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data2, "foo", "");
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data2, "foo", "");
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -184,9 +190,9 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
|
||||
ASSERT_TRUE(finished_context2.is_called);
|
||||
ASSERT_EQ(WF_BAD_BUSY, finished_context2.status);
|
||||
ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error));
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -197,19 +203,19 @@ TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
|
||||
|
||||
ASSERT_FALSE(send_context.is_called);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_EQ(WF_BAD, finished_context.status);
|
||||
ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error));
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -220,12 +226,12 @@ TEST(jsonrpc_proxy, on_result)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -237,15 +243,15 @@ TEST(jsonrpc_proxy, on_result)
|
||||
json_object_set_new(response, "result", json_string("okay"));
|
||||
json_object_set(response, "id", id);
|
||||
|
||||
wf_impl_jsonrpc_proxy_onresult(&proxy, response);
|
||||
jsonrpc_proxy_onresult(&proxy, response);
|
||||
json_decref(response);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_EQ(WF_GOOD, finished_context.status);
|
||||
ASSERT_EQ(nullptr, finished_context.error);
|
||||
ASSERT_TRUE(json_is_string(finished_context.result));
|
||||
ASSERT_STREQ("okay", json_string_value(finished_context.result));
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -256,12 +262,12 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -273,12 +279,12 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id)
|
||||
json_object_set_new(response, "result", json_string("okay"));
|
||||
json_object_set_new(response, "id", json_integer(1 + json_integer_value(id)));
|
||||
|
||||
wf_impl_jsonrpc_proxy_onresult(&proxy, response);
|
||||
jsonrpc_proxy_onresult(&proxy, response);
|
||||
json_decref(response);
|
||||
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -289,12 +295,12 @@ TEST(jsonrpc_proxy, timeout)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, 0, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, 0, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -303,9 +309,9 @@ TEST(jsonrpc_proxy, timeout)
|
||||
wf_impl_timeout_manager_check(&timeout_manager);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_EQ(WF_BAD_TIMEOUT, finished_context.status);
|
||||
ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error));
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -316,12 +322,12 @@ TEST(jsonrpc_proxy, cleanup_pending_request)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, 10, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, 10, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -329,7 +335,7 @@ TEST(jsonrpc_proxy, cleanup_pending_request)
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
ASSERT_NE(nullptr, timeout_manager.timers);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_EQ(nullptr, timeout_manager.timers);
|
||||
@ -346,10 +352,10 @@ TEST(jsonrpc_proxy, notify)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
wf_impl_jsonrpc_proxy_notify(&proxy, "foo", "si", "bar", 42);
|
||||
jsonrpc_proxy_notify(&proxy, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -370,7 +376,7 @@ TEST(jsonrpc_proxy, notify)
|
||||
ASSERT_EQ(nullptr, id);
|
||||
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
||||
|
||||
@ -381,13 +387,13 @@ TEST(jsonrpc_proxy, notify_dont_send_invalid_request)
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wf_impl_jsonrpc_proxy proxy;
|
||||
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct jsonrpc_proxy proxy;
|
||||
jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
wf_impl_jsonrpc_proxy_notify(&proxy, "foo", "?");
|
||||
jsonrpc_proxy_notify(&proxy, "foo", "?");
|
||||
|
||||
ASSERT_FALSE(send_context.is_called);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||
jsonrpc_proxy_cleanup(&proxy);
|
||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "jsonrpc/request.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -27,13 +27,13 @@ TEST(jsonrpc_request, create_dispose)
|
||||
Context context{nullptr};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
|
||||
struct wf_impl_jsonrpc_request * request =
|
||||
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
struct jsonrpc_request * request =
|
||||
jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_NE(nullptr, request);
|
||||
ASSERT_EQ(user_data, wf_impl_jsonrpc_request_get_userdata(request));
|
||||
ASSERT_EQ(user_data, jsonrpc_request_get_userdata(request));
|
||||
|
||||
wf_impl_jsonrpc_request_dispose(request);
|
||||
jsonrpc_request_dispose(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_request, respond)
|
||||
@ -41,10 +41,10 @@ TEST(jsonrpc_request, respond)
|
||||
Context context{nullptr};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
|
||||
struct wf_impl_jsonrpc_request * request =
|
||||
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
struct jsonrpc_request * request =
|
||||
jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
|
||||
wf_impl_jsonrpc_respond(request, json_string("okay"));
|
||||
jsonrpc_respond(request, json_string("okay"));
|
||||
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
|
||||
@ -70,10 +70,10 @@ TEST(jsonrpc_request, respond_error)
|
||||
Context context{nullptr};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
|
||||
struct wf_impl_jsonrpc_request * request =
|
||||
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
struct jsonrpc_request * request =
|
||||
jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
|
||||
wf_impl_jsonrpc_respond_error(request, WF_BAD);
|
||||
jsonrpc_respond_error(request, WF_BAD);
|
||||
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
#include "jsonrpc/response.h"
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
TEST(json_response, init_result)
|
||||
{
|
||||
@ -7,15 +9,15 @@ TEST(json_response, init_result)
|
||||
json_object_set_new(message, "result", json_integer(47));
|
||||
json_object_set_new(message, "id", json_integer(11));
|
||||
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
wf_impl_jsonrpc_response_init(&response, message);
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_response_init(&response, message);
|
||||
|
||||
ASSERT_EQ(WF_GOOD, response.status);
|
||||
ASSERT_EQ(nullptr, response.error);
|
||||
ASSERT_TRUE(json_is_integer(response.result));
|
||||
ASSERT_EQ(47, json_integer_value(response.result));
|
||||
ASSERT_EQ(11, response.id);
|
||||
|
||||
wf_impl_jsonrpc_response_cleanup(&response);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
@ -28,14 +30,14 @@ TEST(json_response, init_error)
|
||||
json_object_set_new(message, "error", err);
|
||||
json_object_set_new(message, "id", json_integer(23));
|
||||
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
wf_impl_jsonrpc_response_init(&response, message);
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_response_init(&response, message);
|
||||
|
||||
ASSERT_EQ(WF_BAD_ACCESS_DENIED, response.status);
|
||||
ASSERT_EQ(WF_BAD_ACCESS_DENIED, wf_impl_jsonrpc_get_status(response.error)) << json_string_value(json_object_get(response.error, "message"));
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(23, response.id);
|
||||
|
||||
wf_impl_jsonrpc_response_cleanup(&response);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
@ -44,13 +46,13 @@ TEST(json_response, init_format_error)
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "id", json_integer(12));
|
||||
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
wf_impl_jsonrpc_response_init(&response, message);
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_response_init(&response, message);
|
||||
|
||||
ASSERT_EQ(WF_BAD_FORMAT, response.status);
|
||||
ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error));
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(12, response.id);
|
||||
|
||||
wf_impl_jsonrpc_response_cleanup(&response);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
json_decref(message);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "jsonrpc/server.h"
|
||||
#include "jsonrpc/request.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -23,7 +23,7 @@ namespace
|
||||
}
|
||||
|
||||
void sayHello(
|
||||
struct wf_impl_jsonrpc_request * request,
|
||||
struct jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data)
|
||||
@ -33,16 +33,16 @@ namespace
|
||||
(void) user_data;
|
||||
|
||||
json_t * result = json_string("Hello");
|
||||
wf_impl_jsonrpc_respond(request, result);
|
||||
jsonrpc_respond(request, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(jsonrpc_server, process_request)
|
||||
{
|
||||
struct wf_impl_jsonrpc_server server;
|
||||
wf_impl_jsonrpc_server_init(&server);
|
||||
wf_impl_jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr);
|
||||
struct jsonrpc_server server;
|
||||
jsonrpc_server_init(&server);
|
||||
jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr);
|
||||
|
||||
Context context{nullptr, false};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
@ -50,7 +50,7 @@ TEST(jsonrpc_server, process_request)
|
||||
json_object_set_new(request, "method", json_string("sayHello"));
|
||||
json_object_set_new(request, "params", json_array());
|
||||
json_object_set_new(request, "id", json_integer(23));
|
||||
wf_impl_jsonrpc_server_process(&server, request, &jsonrpc_send, user_data);
|
||||
jsonrpc_server_process(&server, request, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_TRUE(context.is_called);
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
@ -66,14 +66,14 @@ TEST(jsonrpc_server, process_request)
|
||||
|
||||
json_decref(context.response);
|
||||
json_decref(request);
|
||||
wf_impl_jsonrpc_server_cleanup(&server);
|
||||
jsonrpc_server_cleanup(&server);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_server, invoke_unknown_method)
|
||||
{
|
||||
struct wf_impl_jsonrpc_server server;
|
||||
wf_impl_jsonrpc_server_init(&server);
|
||||
wf_impl_jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr);
|
||||
struct jsonrpc_server server;
|
||||
jsonrpc_server_init(&server);
|
||||
jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr);
|
||||
|
||||
Context context{nullptr, false};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
@ -81,7 +81,7 @@ TEST(jsonrpc_server, invoke_unknown_method)
|
||||
json_object_set_new(request, "method", json_string("greet"));
|
||||
json_object_set_new(request, "params", json_array());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
wf_impl_jsonrpc_server_process(&server, request, &jsonrpc_send, user_data);
|
||||
jsonrpc_server_process(&server, request, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_TRUE(context.is_called);
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
@ -103,23 +103,23 @@ TEST(jsonrpc_server, invoke_unknown_method)
|
||||
|
||||
json_decref(context.response);
|
||||
json_decref(request);
|
||||
wf_impl_jsonrpc_server_cleanup(&server);
|
||||
jsonrpc_server_cleanup(&server);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_server, skip_invalid_request)
|
||||
{
|
||||
struct wf_impl_jsonrpc_server server;
|
||||
wf_impl_jsonrpc_server_init(&server);
|
||||
struct jsonrpc_server server;
|
||||
jsonrpc_server_init(&server);
|
||||
|
||||
Context context{nullptr, false};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("sayHello"));
|
||||
json_object_set_new(request, "params", json_array());
|
||||
wf_impl_jsonrpc_server_process(&server, request, &jsonrpc_send, user_data);
|
||||
jsonrpc_server_process(&server, request, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_FALSE(context.is_called);
|
||||
|
||||
json_decref(request);
|
||||
wf_impl_jsonrpc_server_cleanup(&server);
|
||||
jsonrpc_server_cleanup(&server);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
TEST(jsonrpc_util, get_int)
|
||||
{
|
@ -167,6 +167,22 @@ static void webfuse_test_iproviderclient_onread(
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
static void webfuse_test_iproviderclient_get_credentials(
|
||||
wfp_credentials * credentials,
|
||||
void * user_data)
|
||||
{
|
||||
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||
|
||||
try
|
||||
{
|
||||
self->GetCredentials(credentials);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// swallow
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace webfuse_test
|
||||
@ -185,7 +201,7 @@ wf_status ProviderClientException::GetErrorCode()
|
||||
}
|
||||
|
||||
|
||||
void IProviderClient::AttachTo(wfp_client_config * config)
|
||||
void IProviderClient::AttachTo(wfp_client_config * config, bool enableAuthentication)
|
||||
{
|
||||
void * self = reinterpret_cast<void *>(this);
|
||||
wfp_client_config_set_userdata(config, self);
|
||||
@ -199,6 +215,11 @@ void IProviderClient::AttachTo(wfp_client_config * config)
|
||||
wfp_client_config_set_onopen(config, &webfuse_test_iproviderclient_onopen);
|
||||
wfp_client_config_set_onclose(config, &webfuse_test_iproviderclient_onclose);
|
||||
wfp_client_config_set_onread(config, &webfuse_test_iproviderclient_onread);
|
||||
|
||||
if (enableAuthentication)
|
||||
{
|
||||
wfp_client_config_enable_authentication(config, &webfuse_test_iproviderclient_get_credentials);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -16,8 +16,6 @@ namespace webfuse_test
|
||||
private:
|
||||
wf_status error_code_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class IProviderClient
|
||||
{
|
||||
@ -32,8 +30,9 @@ namespace webfuse_test
|
||||
virtual void Open(ino_t inode, int flags, uint32_t * handle) = 0;
|
||||
virtual void Close(ino_t inode, uint32_t handle, int flags) = 0;
|
||||
virtual void Read(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read) = 0;
|
||||
virtual void GetCredentials(wfp_credentials * credentials) = 0;
|
||||
|
||||
void AttachTo(wfp_client_config * config);
|
||||
void AttachTo(wfp_client_config * config, bool enableAuthentication = false);
|
||||
};
|
||||
|
||||
class MockProviderClient: public IProviderClient
|
||||
@ -49,6 +48,7 @@ namespace webfuse_test
|
||||
MOCK_METHOD3( Open, void(ino_t inode, int flags, uint32_t * handle));
|
||||
MOCK_METHOD3( Close, void(ino_t inode, uint32_t handle, int flags));
|
||||
MOCK_METHOD6( Read, void(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read));
|
||||
MOCK_METHOD1( GetCredentials, void (wfp_credentials * credentials));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,54 +1,59 @@
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
#include "jsonrpc/response.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
|
||||
static void response_parse_str(
|
||||
std::string const & buffer,
|
||||
struct wf_impl_jsonrpc_response * response)
|
||||
struct jsonrpc_response * response)
|
||||
{
|
||||
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
|
||||
if (nullptr != message)
|
||||
{
|
||||
wf_impl_jsonrpc_response_init(response, message);
|
||||
jsonrpc_response_init(response, message);
|
||||
json_decref(message);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(response_parser, test)
|
||||
{
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
struct jsonrpc_response response;
|
||||
|
||||
// no object
|
||||
response_parse_str("[]", &response);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
|
||||
// empty
|
||||
response_parse_str("{}", &response);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
|
||||
// no data
|
||||
response_parse_str("{\"id\":42}", &response);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
|
||||
// custom error code
|
||||
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.status);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
|
||||
// valid response
|
||||
response_parse_str("{\"result\": true, \"id\": 42}", &response);
|
||||
ASSERT_EQ(WF_GOOD, response.status);
|
||||
ASSERT_EQ(WF_GOOD, response.error);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
json_decref(response.result);
|
||||
jsonrpc_response_cleanup(&response);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ using webfuse_test::MockProviderClient;
|
||||
using webfuse_test::IProviderClient;
|
||||
using testing::_;
|
||||
using testing::AtMost;
|
||||
using testing::Invoke;
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -24,10 +25,10 @@ class ClientProtocolFixture
|
||||
ClientProtocolFixture(ClientProtocolFixture const &) = delete;
|
||||
ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete;
|
||||
public:
|
||||
explicit ClientProtocolFixture(IProviderClient& client)
|
||||
explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false)
|
||||
{
|
||||
config = wfp_client_config_create();
|
||||
client.AttachTo(config);
|
||||
client.AttachTo(config, enableAuthentication);
|
||||
|
||||
protocol = wfp_client_protocol_create(config);
|
||||
|
||||
@ -140,6 +141,13 @@ private:
|
||||
wfp_client_protocol * protocol;
|
||||
};
|
||||
|
||||
void GetCredentials(wfp_credentials * credentials)
|
||||
{
|
||||
wfp_credentials_set_type(credentials, "username");
|
||||
wfp_credentials_add(credentials, "username", "bob");
|
||||
wfp_credentials_add(credentials, "password", "secret");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(client_protocol, connect)
|
||||
@ -161,11 +169,11 @@ TEST(client_protocol, connect)
|
||||
TEST(client_protocol, connect_with_username_authentication)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
ClientProtocolFixture fixture(provider);
|
||||
// ToDo: enable authentication
|
||||
ClientProtocolFixture fixture(provider, true);
|
||||
|
||||
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
|
||||
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||
EXPECT_CALL(provider, GetCredentials(_)).WillOnce(Invoke(GetCredentials)).Times(1);
|
||||
|
||||
fixture.Connect();
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
Loading…
Reference in New Issue
Block a user