mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
chore: prefixed jsonrpc by wf_
This commit is contained in:
parent
8a40919296
commit
1a29b44ad6
@ -38,7 +38,7 @@ add_compile_options(
|
||||
)
|
||||
|
||||
include(wf_timer)
|
||||
include(jsonrpc)
|
||||
include(wf_jsonrpc)
|
||||
include(webfuse_core)
|
||||
include(webfuse_adapter)
|
||||
include(webfuse_provider)
|
||||
|
@ -1,24 +0,0 @@
|
||||
# jsonrpc
|
||||
|
||||
add_library(jsonrpc STATIC
|
||||
lib/jsonrpc/src/jsonrpc/api.c
|
||||
lib/jsonrpc/src/jsonrpc/impl/proxy.c
|
||||
lib/jsonrpc/src/jsonrpc/impl/server.c
|
||||
lib/jsonrpc/src/jsonrpc/impl/method.c
|
||||
lib/jsonrpc/src/jsonrpc/impl/request.c
|
||||
lib/jsonrpc/src/jsonrpc/impl/response.c
|
||||
lib/jsonrpc/src/jsonrpc/impl/error.c
|
||||
)
|
||||
|
||||
target_link_libraries(jsonrpc PUBLIC wf_timer)
|
||||
|
||||
target_include_directories(jsonrpc PRIVATE
|
||||
lib/wf/timer/include
|
||||
lib/jsonrpc/src
|
||||
)
|
||||
|
||||
target_include_directories(jsonrpc PUBLIC
|
||||
lib/jsonrpc/include
|
||||
)
|
||||
|
||||
set_target_properties(jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden)
|
@ -7,14 +7,13 @@ include(GoogleTest)
|
||||
pkg_check_modules(GMOCK gmock)
|
||||
|
||||
add_executable(alltests
|
||||
lib/jsonrpc/test/jsonrpc/test_util.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_is_request.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_request.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_is_response.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_response.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_server.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_proxy.cc
|
||||
lib/jsonrpc/test/jsonrpc/test_response_parser.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc
|
||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc
|
||||
lib/wf/timer/test/wf/timer/test_timepoint.cc
|
||||
lib/wf/timer/test/wf/timer/test_timer.cc
|
||||
test/webfuse/utils/tempdir.cc
|
||||
@ -28,6 +27,7 @@ add_executable(alltests
|
||||
test/webfuse/mocks/mock_authenticator.cc
|
||||
test/webfuse/mocks/mock_request.cc
|
||||
test/webfuse/mocks/mock_provider_client.cc
|
||||
test/webfuse//tests/core/test_util.cc
|
||||
test/webfuse/tests/core/test_container_of.cc
|
||||
test/webfuse/tests/core/test_string.cc
|
||||
test/webfuse/tests/core/test_slist.cc
|
||||
@ -52,8 +52,8 @@ add_executable(alltests
|
||||
)
|
||||
|
||||
target_include_directories(alltests PRIVATE
|
||||
lib/jsonrpc/include
|
||||
lib/jsonrpc/src
|
||||
lib/wf/jsonrpc/include
|
||||
lib/wf/jsonrpc/src
|
||||
lib/wf/timer/include
|
||||
lib/wf/timer/src
|
||||
${FUSE3_INCLUDE_DIRS}
|
||||
@ -69,7 +69,7 @@ target_link_libraries(alltests PUBLIC
|
||||
webfuse-adapter-static
|
||||
webfuse-provider-static
|
||||
webfuse-core
|
||||
jsonrpc
|
||||
wf_jsonrpc
|
||||
wf_timer
|
||||
${FUSE3_LIBRARIES}
|
||||
${LWS_LIBRARIES}
|
||||
|
@ -30,7 +30,7 @@ add_library(webfuse-adapter-static STATIC
|
||||
target_include_directories(webfuse-adapter-static PRIVATE
|
||||
lib
|
||||
lib/wf/timer/include
|
||||
lib/jsonrpc/include
|
||||
lib/wf/jsonrpc/include
|
||||
${FUSE3_INCLUDE_DIRS}
|
||||
${UUID_INCLUDE_DIRS}
|
||||
)
|
||||
@ -63,7 +63,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 jsonrpc wf_timer)
|
||||
target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core wf_jsonrpc wf_timer)
|
||||
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc"
|
||||
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
||||
|
@ -12,7 +12,7 @@ add_library(webfuse-core STATIC
|
||||
)
|
||||
|
||||
set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core)
|
||||
target_include_directories(webfuse-core PUBLIC lib lib/jsonrpc/include)
|
||||
target_include_directories(webfuse-core PUBLIC lib lib/wf/jsonrpc/include)
|
||||
set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden)
|
||||
|
||||
install(DIRECTORY include/webfuse/core DESTINATION include/webfuse COMPONENT headers)
|
||||
|
@ -23,7 +23,7 @@ set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hid
|
||||
target_include_directories(webfuse-provider-static PUBLIC
|
||||
lib
|
||||
lib/wf/timer/include
|
||||
lib/jsonrpc/include
|
||||
lib/wf/jsonrpc/include
|
||||
)
|
||||
|
||||
add_library(webfuse-provider SHARED
|
||||
|
24
cmake/wf_jsonrpc.cmake
Normal file
24
cmake/wf_jsonrpc.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
# wf_jsonrpc
|
||||
|
||||
add_library(wf_jsonrpc STATIC
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/api.c
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c
|
||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c
|
||||
)
|
||||
|
||||
target_link_libraries(wf_jsonrpc PUBLIC wf_timer)
|
||||
|
||||
target_include_directories(wf_jsonrpc PRIVATE
|
||||
lib/wf/timer/include
|
||||
lib/wf/jsonrpc/src
|
||||
)
|
||||
|
||||
target_include_directories(wf_jsonrpc PUBLIC
|
||||
lib/wf/jsonrpc/include
|
||||
)
|
||||
|
||||
set_target_properties(wf_jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden)
|
@ -1,14 +0,0 @@
|
||||
#ifndef JSONRPC_H
|
||||
#define JSONRPC_H
|
||||
|
||||
#include <jsonrpc/api.h>
|
||||
#include <jsonrpc/method_invoke_fn.h>
|
||||
#include <jsonrpc/proxy.h>
|
||||
#include <jsonrpc/proxy_finished_fn.h>
|
||||
#include <jsonrpc/request.h>
|
||||
#include <jsonrpc/response.h>
|
||||
#include <jsonrpc/send_fn.h>
|
||||
#include <jsonrpc/server.h>
|
||||
#include <jsonrpc/status.h>
|
||||
|
||||
#endif
|
@ -1,8 +0,0 @@
|
||||
#ifndef JSONRPC_API_H
|
||||
#define JSONRPC_API_H
|
||||
|
||||
#ifndef JSONRPC_API
|
||||
#define JSONRPC_API
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
#ifndef JSONRPC_METHOD_INVOKE_FN_H
|
||||
#define JSONRPC_METHOD_INVOKE_FN_H
|
||||
|
||||
#include <jsonrpc/api.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);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,53 +0,0 @@
|
||||
#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 <jsonrpc/api.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
extern JSONRPC_API bool jsonrpc_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern JSONRPC_API struct jsonrpc_request * jsonrpc_request_create(
|
||||
int id,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_request_dispose(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern JSONRPC_API void * jsonrpc_request_get_userdata(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_respond(
|
||||
struct jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
#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/api.h>
|
||||
#include <jsonrpc/send_fn.h>
|
||||
#include <jsonrpc/method_invoke_fn.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_server;
|
||||
|
||||
extern JSONRPC_API struct jsonrpc_server *
|
||||
jsonrpc_server_create(void);
|
||||
|
||||
extern JSONRPC_API void
|
||||
jsonrpc_server_dispose(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_server_process(
|
||||
struct jsonrpc_server * server,
|
||||
json_t * request,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,11 +0,0 @@
|
||||
#ifndef JSONRPC_STATUS_H
|
||||
#define JSONRPC_STATUS_H
|
||||
|
||||
#define JSONRPC_GOOD 0
|
||||
#define JSONRPC_BAD -1
|
||||
#define JSONRPC_BAD_NOTIMPLEMENTED -2
|
||||
#define JSONRPC_BAD_TIMEOUT -3
|
||||
#define JSONRPC_BAD_BUSY -4
|
||||
#define JSONRPC_BAD_FORMAT -5
|
||||
|
||||
#endif
|
@ -1,144 +0,0 @@
|
||||
#include "jsonrpc.h"
|
||||
|
||||
#include "jsonrpc/impl/proxy.h"
|
||||
#include "jsonrpc/impl/request.h"
|
||||
#include "jsonrpc/impl/response.h"
|
||||
#include "jsonrpc/impl/server.h"
|
||||
|
||||
// proxy
|
||||
|
||||
struct jsonrpc_proxy *
|
||||
jsonrpc_proxy_create(
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
return jsonrpc_impl_proxy_create(manager, timeout, send, user_data);
|
||||
}
|
||||
|
||||
void jsonrpc_proxy_dispose(
|
||||
struct jsonrpc_proxy * proxy)
|
||||
{
|
||||
jsonrpc_impl_proxy_dispose(proxy);
|
||||
}
|
||||
|
||||
void jsonrpc_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void jsonrpc_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
jsonrpc_impl_proxy_notify(proxy, method_name, param_info, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void jsonrpc_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
json_t * message)
|
||||
{
|
||||
jsonrpc_impl_proxy_onresult(proxy, message);
|
||||
}
|
||||
|
||||
|
||||
// request
|
||||
|
||||
bool jsonrpc_is_request(
|
||||
json_t * message)
|
||||
{
|
||||
return jsonrpc_impl_is_request(message);
|
||||
}
|
||||
|
||||
struct jsonrpc_request * jsonrpc_request_create(
|
||||
int id,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
return jsonrpc_impl_request_create(id, send, user_data);
|
||||
}
|
||||
|
||||
void jsonrpc_request_dispose(
|
||||
struct jsonrpc_request * request)
|
||||
{
|
||||
jsonrpc_impl_request_dispose(request);
|
||||
}
|
||||
|
||||
void * jsonrpc_request_get_userdata(
|
||||
struct jsonrpc_request * request)
|
||||
{
|
||||
return jsonrpc_impl_request_get_userdata(request);
|
||||
}
|
||||
|
||||
void jsonrpc_respond(
|
||||
struct jsonrpc_request * request,
|
||||
json_t * result)
|
||||
{
|
||||
jsonrpc_impl_respond(request, result);
|
||||
}
|
||||
|
||||
void jsonrpc_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
jsonrpc_impl_respond_error(request, code, message);
|
||||
}
|
||||
|
||||
// response
|
||||
|
||||
bool jsonrpc_is_response(
|
||||
json_t * message)
|
||||
{
|
||||
return jsonrpc_impl_is_response(message);
|
||||
}
|
||||
|
||||
// server
|
||||
|
||||
struct jsonrpc_server *
|
||||
jsonrpc_server_create(void)
|
||||
{
|
||||
return jsonrpc_impl_server_create();
|
||||
}
|
||||
|
||||
void
|
||||
jsonrpc_server_dispose(
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
jsonrpc_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void jsonrpc_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
jsonrpc_impl_server_add(server, method_name, invoke, user_data);
|
||||
}
|
||||
|
||||
void jsonrpc_server_process(
|
||||
struct jsonrpc_server * server,
|
||||
json_t * request,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
jsonrpc_impl_server_process(server, request, send, user_data);
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#ifndef JSONRPC_IMPL_METHOD_H
|
||||
#define JSONRPC_IMPL_METHOD_H
|
||||
|
||||
#include "jsonrpc/method_invoke_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_method
|
||||
{
|
||||
struct jsonrpc_method * next;
|
||||
char * name;
|
||||
jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct jsonrpc_method *
|
||||
jsonrpc_impl_method_create(
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_method_dispose(
|
||||
struct jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,84 +0,0 @@
|
||||
#ifndef JSONRPC_IMPL_PROXY_H
|
||||
#define JSONRPC_IMPL_PROXY_H
|
||||
|
||||
#include "jsonrpc/proxy_finished_fn.h"
|
||||
#include "jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_timer_manager;
|
||||
struct wf_timer;
|
||||
|
||||
struct jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
jsonrpc_proxy_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_timer * timer;
|
||||
};
|
||||
|
||||
struct jsonrpc_proxy
|
||||
{
|
||||
struct jsonrpc_request request;
|
||||
int timeout;
|
||||
jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_proxy_init(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_proxy_cleanup(
|
||||
struct jsonrpc_proxy * proxy);
|
||||
|
||||
extern struct jsonrpc_proxy *
|
||||
jsonrpc_impl_proxy_create(
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_proxy_dispose(
|
||||
struct jsonrpc_proxy * proxy);
|
||||
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
va_list args
|
||||
);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
va_list args
|
||||
);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,53 +0,0 @@
|
||||
#ifndef JSONRPC_IMPL_REQUEST_H
|
||||
#define JSONRPC_IMPL_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 <jsonrpc/api.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
extern bool jsonrpc_impl_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern struct jsonrpc_request * jsonrpc_impl_request_create(
|
||||
int id,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_impl_request_dispose(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern void * jsonrpc_impl_request_get_userdata(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern void jsonrpc_impl_respond(
|
||||
struct jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern void jsonrpc_impl_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,132 +0,0 @@
|
||||
#include "jsonrpc/impl/server.h"
|
||||
#include "jsonrpc/impl/method.h"
|
||||
#include "jsonrpc/impl/request.h"
|
||||
#include "jsonrpc/impl/unused_param.h"
|
||||
#include "jsonrpc/status.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct jsonrpc_server
|
||||
{
|
||||
struct jsonrpc_method * methods;
|
||||
};
|
||||
|
||||
static void
|
||||
jsonrpc_impl_server_init(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
static void
|
||||
jsonrpc_impl_server_cleanup(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
struct jsonrpc_server *
|
||||
jsonrpc_impl_server_create(void)
|
||||
{
|
||||
struct jsonrpc_server * server = malloc(sizeof(struct jsonrpc_server));
|
||||
if (NULL != server)
|
||||
{
|
||||
jsonrpc_impl_server_init(server);
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
void
|
||||
jsonrpc_impl_server_dispose(
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
jsonrpc_impl_server_cleanup(server);
|
||||
free(server);
|
||||
}
|
||||
|
||||
|
||||
static void jsonrpc_impl_server_init(
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
static void jsonrpc_impl_server_cleanup(
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
struct jsonrpc_method * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
struct jsonrpc_method * next = current->next;
|
||||
jsonrpc_impl_method_dispose(current);
|
||||
current = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void jsonrpc_impl_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct jsonrpc_method * method = jsonrpc_impl_method_create(method_name, invoke, user_data);
|
||||
method->next = server->methods;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
static void jsonrpc_impl_server_invalid_method_invoke(
|
||||
struct jsonrpc_request * request,
|
||||
char const * JSONRPC_UNUSED_PARAM(method_name),
|
||||
json_t * JSONRPC_UNUSED_PARAM(params),
|
||||
void * JSONRPC_UNUSED_PARAM(user_data))
|
||||
{
|
||||
jsonrpc_impl_respond_error(request, JSONRPC_BAD_NOTIMPLEMENTED, "not implemented");
|
||||
}
|
||||
|
||||
static struct jsonrpc_method const jsonrpc_impl_server_invalid_method =
|
||||
{
|
||||
.next = NULL,
|
||||
.name = "<invalid>",
|
||||
.invoke = &jsonrpc_impl_server_invalid_method_invoke,
|
||||
.user_data = NULL
|
||||
};
|
||||
|
||||
static struct jsonrpc_method const *
|
||||
jsonrpc_impl_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_impl_server_invalid_method;
|
||||
}
|
||||
|
||||
void jsonrpc_impl_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_impl_request_create(id, send, user_data);
|
||||
struct jsonrpc_method const * method = jsonrpc_impl_server_get_method(server, method_name);
|
||||
|
||||
method->invoke(request, method_name, params, method->user_data);
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
#ifndef JSONRPC_IMPL_SERVER_H
|
||||
#define JSONRPC_IMPL_SERVER_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/method_invoke_fn.h"
|
||||
#include "jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_server;
|
||||
|
||||
extern struct jsonrpc_server *
|
||||
jsonrpc_impl_server_create(void);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_server_dispose(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_server_process(
|
||||
struct jsonrpc_server * server,
|
||||
json_t * request,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,10 +0,0 @@
|
||||
#ifndef JSONRPC_UTIL_H
|
||||
#define JSONRPC_UTIL_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define JSONRPC_UNUSED_PARAM(param) param __attribute__((unused))
|
||||
#else
|
||||
#define JSONRPC_UNUSED_PARAM(param)
|
||||
#endif
|
||||
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/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 jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
wf_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
}
|
||||
|
||||
fuse_reply_err(request, 0);
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
@ -83,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 jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@ -94,7 +94,7 @@ void wf_impl_operation_getattr (
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
@ -92,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 jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@ -102,7 +102,7 @@ void wf_impl_operation_lookup (
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
@ -49,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 jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <limits.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/base64.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
@ -92,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 jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct wf_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);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
@ -139,16 +139,16 @@ 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 jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context));
|
||||
readdir_context->request = request;
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context));
|
||||
readdir_context->request = request;
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
|
||||
wf_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 jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context)
|
||||
{
|
||||
struct jsonrpc_proxy * proxy = NULL;
|
||||
struct wf_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 jsonrpc_proxy;
|
||||
struct wf_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 jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -9,10 +9,10 @@
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||
#include "webfuse/core/status_intern.h"
|
||||
|
||||
#include "wf/jsonrpc/request.h"
|
||||
#include "wf/timer/manager.h"
|
||||
#include "wf/timer/timer.h"
|
||||
|
||||
@ -133,7 +133,7 @@ void wf_impl_server_protocol_init_lws(
|
||||
}
|
||||
|
||||
static void wf_impl_server_protocol_authenticate(
|
||||
struct jsonrpc_request * request,
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * params,
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
@ -149,7 +149,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 = jsonrpc_request_get_userdata(request);
|
||||
struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request);
|
||||
result = wf_impl_session_authenticate(session, &creds);
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
@ -159,11 +159,11 @@ static void wf_impl_server_protocol_authenticate(
|
||||
if (result)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
jsonrpc_respond(request, result);
|
||||
wf_jsonrpc_respond(request, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED));
|
||||
wf_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED));
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,12 +183,12 @@ static bool wf_impl_server_protocol_check_name(char const * value)
|
||||
}
|
||||
|
||||
static void wf_impl_server_protocol_add_filesystem(
|
||||
struct jsonrpc_request * request,
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * params,
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
struct wf_impl_session * session = jsonrpc_request_get_userdata(request);
|
||||
struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request);
|
||||
wf_status status = (session->is_authenticated) ? WF_GOOD : WF_BAD_ACCESS_DENIED;
|
||||
|
||||
char const * name = NULL;
|
||||
@ -222,11 +222,11 @@ static void wf_impl_server_protocol_add_filesystem(
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "id", json_string(name));
|
||||
jsonrpc_respond(request, result);
|
||||
wf_jsonrpc_respond(request, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonrpc_respond_error(request, status, wf_status_tostring(status));
|
||||
wf_jsonrpc_respond_error(request, status, wf_status_tostring(status));
|
||||
}
|
||||
|
||||
|
||||
@ -244,9 +244,9 @@ void wf_impl_server_protocol_init(
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
wf_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
protocol->server = jsonrpc_server_create();
|
||||
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);
|
||||
protocol->server = wf_jsonrpc_server_create();
|
||||
wf_jsonrpc_server_add(protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol);
|
||||
wf_jsonrpc_server_add(protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_cleanup(
|
||||
@ -254,7 +254,7 @@ void wf_impl_server_protocol_cleanup(
|
||||
{
|
||||
protocol->is_operational = false;
|
||||
|
||||
jsonrpc_server_dispose(protocol->server);
|
||||
wf_jsonrpc_server_dispose(protocol->server);
|
||||
wf_timer_manager_dispose(protocol->timer_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "jsonrpc/server.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/server.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
@ -24,7 +24,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 jsonrpc_server * server;
|
||||
struct wf_jsonrpc_server * server;
|
||||
struct wf_timer_manager * timer_manager;
|
||||
bool is_operational;
|
||||
};
|
||||
|
@ -2,15 +2,16 @@
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/message.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"
|
||||
|
||||
#include "webfuse/core/container_of.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/request.h"
|
||||
#include "wf/jsonrpc/response.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
@ -24,7 +25,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 || jsonrpc_is_response(request)) && (NULL != session->wsi);
|
||||
bool result = (session->is_authenticated || wf_jsonrpc_is_response(request)) && (NULL != session->wsi);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@ -45,7 +46,7 @@ struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server,
|
||||
struct wf_jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory)
|
||||
{
|
||||
|
||||
@ -59,7 +60,7 @@ struct wf_impl_session * wf_impl_session_create(
|
||||
session->authenticators = authenticators;
|
||||
session->server = server;
|
||||
session->mountpoint_factory = mountpoint_factory;
|
||||
session->rpc = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
wf_slist_init(&session->messages);
|
||||
}
|
||||
|
||||
@ -83,7 +84,7 @@ static void wf_impl_session_dispose_filesystems(
|
||||
void wf_impl_session_dispose(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
jsonrpc_proxy_dispose(session->rpc);
|
||||
wf_jsonrpc_proxy_dispose(session->rpc);
|
||||
wf_message_queue_cleanup(&session->messages);
|
||||
|
||||
wf_impl_session_dispose_filesystems(&session->filesystems);
|
||||
@ -154,13 +155,13 @@ void wf_impl_session_receive(
|
||||
json_t * message = json_loadb(data, length, 0, NULL);
|
||||
if (NULL != message)
|
||||
{
|
||||
if (jsonrpc_is_response(message))
|
||||
if (wf_jsonrpc_is_response(message))
|
||||
{
|
||||
jsonrpc_proxy_onresult(session->rpc, message);
|
||||
wf_jsonrpc_proxy_onresult(session->rpc, message);
|
||||
}
|
||||
else if (jsonrpc_is_request(message))
|
||||
else if (wf_jsonrpc_is_request(message))
|
||||
{
|
||||
jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
|
||||
wf_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
|
||||
}
|
||||
|
||||
json_decref(message);
|
||||
|
@ -10,11 +10,12 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/core/slist.h"
|
||||
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@ -25,7 +26,6 @@ struct wf_message;
|
||||
struct wf_credentials;
|
||||
struct wf_impl_authenticators;
|
||||
struct wf_impl_mountpoint_factory;
|
||||
struct timer_manager;
|
||||
|
||||
struct wf_impl_session
|
||||
{
|
||||
@ -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 jsonrpc_server * server;
|
||||
struct jsonrpc_proxy * rpc;
|
||||
struct wf_jsonrpc_server * server;
|
||||
struct wf_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_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server,
|
||||
struct wf_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_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server)
|
||||
struct wf_jsonrpc_server * server)
|
||||
{
|
||||
struct wf_impl_session * session = wf_impl_session_create(
|
||||
wsi, authenticators, timer_manager, server, mountpoint_factory);
|
||||
|
@ -16,7 +16,7 @@ extern "C"
|
||||
|
||||
struct lws;
|
||||
struct wf_timer_manager;
|
||||
struct jsonrpc_server;
|
||||
struct wf_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_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server);
|
||||
struct wf_jsonrpc_server * server);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "jsonrpc/status.h"
|
||||
#include "wf/jsonrpc/status.h"
|
||||
|
||||
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
{
|
||||
@ -18,15 +18,15 @@ static wf_status wf_impl_jsonrc_code_to_status(int code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case JSONRPC_GOOD:
|
||||
case WF_JSONRPC_GOOD:
|
||||
return WF_GOOD;
|
||||
case JSONRPC_BAD:
|
||||
case WF_JSONRPC_BAD:
|
||||
return WF_BAD;
|
||||
case JSONRPC_BAD_BUSY:
|
||||
case WF_JSONRPC_BAD_BUSY:
|
||||
return WF_BAD_BUSY;
|
||||
case JSONRPC_BAD_TIMEOUT:
|
||||
case WF_JSONRPC_BAD_TIMEOUT:
|
||||
return WF_BAD_TIMEOUT;
|
||||
case JSONRPC_BAD_FORMAT:
|
||||
case WF_JSONRPC_BAD_FORMAT:
|
||||
return WF_BAD_FORMAT;
|
||||
default:
|
||||
return (wf_status) code;
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
#include "wf/timer/manager.h"
|
||||
|
||||
#include "jsonrpc/response.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/response.h"
|
||||
#include "wf/jsonrpc/request.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
@ -46,12 +46,12 @@ static void wfp_impl_client_protocol_process(
|
||||
json_t * message = json_loadb(data, length, 0, NULL);
|
||||
if (NULL != message)
|
||||
{
|
||||
if (jsonrpc_is_response(message))
|
||||
if (wf_jsonrpc_is_response(message))
|
||||
{
|
||||
jsonrpc_proxy_onresult(protocol->proxy, message);
|
||||
wf_jsonrpc_proxy_onresult(protocol->proxy, message);
|
||||
}
|
||||
|
||||
if (jsonrpc_is_request(message))
|
||||
if (wf_jsonrpc_is_request(message))
|
||||
{
|
||||
struct wfp_impl_invokation_context context =
|
||||
{
|
||||
@ -91,7 +91,7 @@ wfp_impl_client_protocol_on_add_filesystem_finished(
|
||||
static void wfp_impl_client_protocol_add_filesystem(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
jsonrpc_proxy_invoke(
|
||||
wf_jsonrpc_proxy_invoke(
|
||||
protocol->proxy,
|
||||
&wfp_impl_client_protocol_on_add_filesystem_finished,
|
||||
protocol,
|
||||
@ -132,7 +132,7 @@ static void wfp_impl_client_protocol_authenticate(
|
||||
json_t * creds = wfp_impl_credentials_get(&credentials);
|
||||
json_incref(creds);
|
||||
|
||||
jsonrpc_proxy_invoke(
|
||||
wf_jsonrpc_proxy_invoke(
|
||||
protocol->proxy,
|
||||
&wfp_impl_client_protocol_on_authenticate_finished,
|
||||
protocol,
|
||||
@ -252,7 +252,7 @@ void wfp_impl_client_protocol_init(
|
||||
protocol->request.user_data = protocol;
|
||||
|
||||
protocol->timer_manager = wf_timer_manager_create();
|
||||
protocol->proxy = jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol);
|
||||
protocol->proxy = wf_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol);
|
||||
|
||||
protocol->user_data = user_data;
|
||||
wfp_impl_provider_init_from_prototype(&protocol->provider, provider);
|
||||
@ -261,7 +261,7 @@ void wfp_impl_client_protocol_init(
|
||||
void wfp_impl_client_protocol_cleanup(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
jsonrpc_proxy_dispose(protocol->proxy);
|
||||
wf_jsonrpc_proxy_dispose(protocol->proxy);
|
||||
wf_timer_manager_dispose(protocol->timer_manager);
|
||||
wf_message_queue_cleanup(&protocol->messages);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ extern "C"
|
||||
struct wfp_client_config;
|
||||
struct lws_protocols;
|
||||
struct lws_context;
|
||||
struct jsonrpc_proxy;
|
||||
struct wf_jsonrpc_proxy;
|
||||
struct wf_timer_manager;
|
||||
|
||||
struct wfp_client_protocol
|
||||
@ -26,7 +26,7 @@ struct wfp_client_protocol
|
||||
void * user_data;
|
||||
struct lws * wsi;
|
||||
struct wf_timer_manager * timer_manager;
|
||||
struct jsonrpc_proxy * proxy;
|
||||
struct wf_jsonrpc_proxy * proxy;
|
||||
struct wf_slist messages;
|
||||
};
|
||||
|
||||
|
14
lib/wf/jsonrpc/include/wf/jsonrpc.h
Normal file
14
lib/wf/jsonrpc/include/wf/jsonrpc.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef WF_JSONRPC_H
|
||||
#define WF_JSONRPC_H
|
||||
|
||||
#include <wf/jsonrpc/api.h>
|
||||
#include <wf/jsonrpc/method_invoke_fn.h>
|
||||
#include <wf/jsonrpc/proxy.h>
|
||||
#include <wf/jsonrpc/proxy_finished_fn.h>
|
||||
#include <wf/jsonrpc/request.h>
|
||||
#include <wf/jsonrpc/response.h>
|
||||
#include <wf/jsonrpc/send_fn.h>
|
||||
#include <wf/jsonrpc/server.h>
|
||||
#include <wf/jsonrpc/status.h>
|
||||
|
||||
#endif
|
8
lib/wf/jsonrpc/include/wf/jsonrpc/api.h
Normal file
8
lib/wf/jsonrpc/include/wf/jsonrpc/api.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef WF_JSONRPC_API_H
|
||||
#define WF_JSONRPC_API_H
|
||||
|
||||
#ifndef WF_JSONRPC_API
|
||||
#define WF_JSONRPC_API
|
||||
#endif
|
||||
|
||||
#endif
|
26
lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h
Normal file
26
lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef WF_JSONRPC_METHOD_INVOKE_FN_H
|
||||
#define WF_JSONRPC_METHOD_INVOKE_FN_H
|
||||
|
||||
#include <wf/jsonrpc/api.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_request;
|
||||
|
||||
typedef void wf_jsonrpc_method_invoke_fn(
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#ifndef JSONRPC_PROXY_H
|
||||
#define JSONRPC_PROXY_H
|
||||
#ifndef WF_JSONRPC_PROXY_H
|
||||
#define WF_JSONRPC_PROXY_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
@ -12,26 +12,26 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include <jsonrpc/api.h>
|
||||
#include <jsonrpc/send_fn.h>
|
||||
#include <jsonrpc/proxy_finished_fn.h>
|
||||
#include <wf/jsonrpc/api.h>
|
||||
#include <wf/jsonrpc/send_fn.h>
|
||||
#include <wf/jsonrpc/proxy_finished_fn.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct jsonrpc_proxy;
|
||||
struct wf_jsonrpc_proxy;
|
||||
struct wf_timer_manager;
|
||||
|
||||
extern JSONRPC_API struct jsonrpc_proxy *
|
||||
jsonrpc_proxy_create(
|
||||
extern WF_JSONRPC_API struct wf_jsonrpc_proxy *
|
||||
wf_jsonrpc_proxy_create(
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_proxy_dispose(
|
||||
struct jsonrpc_proxy * proxy);
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose(
|
||||
struct wf_jsonrpc_proxy * proxy);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief Invokes a method.
|
||||
@ -47,24 +47,24 @@ extern JSONRPC_API void jsonrpc_proxy_dispose(
|
||||
/// \param param_info types of the param (s = string, i = integer, j = json)
|
||||
/// \param ... params
|
||||
//------------------------------------------------------------------------------
|
||||
extern JSONRPC_API void jsonrpc_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
wf_jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_notify(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern JSONRPC_API void jsonrpc_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
|
||||
#ifdef __cplusplus
|
@ -1,5 +1,5 @@
|
||||
#ifndef JSONRPC_PROXY_FINISHED_FN_H
|
||||
#define JSONRPC_PROXY_FINISHED_FN_H
|
||||
#ifndef WF_JSONRPC_PROXY_FINISHED_FN_H
|
||||
#define WF_JSONRPC_PROXY_FINISHED_FN_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
@ -8,7 +8,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void jsonrpc_proxy_finished_fn(
|
||||
typedef void wf_jsonrpc_proxy_finished_fn(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
54
lib/wf/jsonrpc/include/wf/jsonrpc/request.h
Normal file
54
lib/wf/jsonrpc/include/wf/jsonrpc/request.h
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef WF_JSONRPC_REQUEST_H
|
||||
#define WF_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 <wf/jsonrpc/api.h>
|
||||
#include "wf/jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_request;
|
||||
|
||||
extern WF_JSONRPC_API bool wf_jsonrpc_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern WF_JSONRPC_API struct wf_jsonrpc_request *
|
||||
wf_jsonrpc_request_create(
|
||||
int id,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_request_dispose(
|
||||
struct wf_jsonrpc_request * request);
|
||||
|
||||
extern WF_JSONRPC_API void * wf_jsonrpc_request_get_userdata(
|
||||
struct wf_jsonrpc_request * request);
|
||||
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_respond(
|
||||
struct wf_jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_respond_error(
|
||||
struct wf_jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,19 +1,19 @@
|
||||
#ifndef JSONRPC_RESPONSE_H
|
||||
#define JSONRPC_RESPONSE_H
|
||||
#ifndef WF_JSONRPC_RESPONSE_H
|
||||
#define WF_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include <jsonrpc/api.h>
|
||||
#include <wf/jsonrpc/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern JSONRPC_API bool jsonrpc_is_response(
|
||||
extern WF_JSONRPC_API bool wf_jsonrpc_is_response(
|
||||
json_t * message);
|
||||
|
||||
#ifdef __cplusplus
|
@ -1,19 +1,19 @@
|
||||
#ifndef JSONRPC_SEND_FN_H
|
||||
#define JSONRPC_SEND_FN_H
|
||||
#ifndef WF_JSONRPC_SEND_FN_H
|
||||
#define WF_JSONRPC_SEND_FN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include <jsonrpc/api.h>
|
||||
#include <wf/jsonrpc/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef bool jsonrpc_send_fn(
|
||||
typedef bool wf_jsonrpc_send_fn(
|
||||
json_t * request,
|
||||
void * user_data);
|
||||
|
46
lib/wf/jsonrpc/include/wf/jsonrpc/server.h
Normal file
46
lib/wf/jsonrpc/include/wf/jsonrpc/server.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef WF_JSONRPC_SERVER_H
|
||||
#define WF_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include <wf/jsonrpc/api.h>
|
||||
#include <wf/jsonrpc/send_fn.h>
|
||||
#include <wf/jsonrpc/method_invoke_fn.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_server;
|
||||
|
||||
extern WF_JSONRPC_API struct wf_jsonrpc_server *
|
||||
wf_jsonrpc_server_create(void);
|
||||
|
||||
extern WF_JSONRPC_API void
|
||||
wf_jsonrpc_server_dispose(
|
||||
struct wf_jsonrpc_server * server);
|
||||
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_server_add(
|
||||
struct wf_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
wf_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern WF_JSONRPC_API void wf_jsonrpc_server_process(
|
||||
struct wf_jsonrpc_server * server,
|
||||
json_t * request,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
11
lib/wf/jsonrpc/include/wf/jsonrpc/status.h
Normal file
11
lib/wf/jsonrpc/include/wf/jsonrpc/status.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef WF_JSONRPC_STATUS_H
|
||||
#define WF_JSONRPC_STATUS_H
|
||||
|
||||
#define WF_JSONRPC_GOOD 0
|
||||
#define WF_JSONRPC_BAD -1
|
||||
#define WF_JSONRPC_BAD_NOTIMPLEMENTED -2
|
||||
#define WF_JSONRPC_BAD_TIMEOUT -3
|
||||
#define WF_JSONRPC_BAD_BUSY -4
|
||||
#define WF_JSONRPC_BAD_FORMAT -5
|
||||
|
||||
#endif
|
144
lib/wf/jsonrpc/src/wf/jsonrpc/api.c
Normal file
144
lib/wf/jsonrpc/src/wf/jsonrpc/api.c
Normal file
@ -0,0 +1,144 @@
|
||||
#include "wf/jsonrpc.h"
|
||||
|
||||
#include "wf/jsonrpc/impl/proxy.h"
|
||||
#include "wf/jsonrpc/impl/request.h"
|
||||
#include "wf/jsonrpc/impl/response.h"
|
||||
#include "wf/jsonrpc/impl/server.h"
|
||||
|
||||
// proxy
|
||||
|
||||
struct wf_jsonrpc_proxy *
|
||||
wf_jsonrpc_proxy_create(
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
return wf_jsonrpc_impl_proxy_create(manager, timeout, send, user_data);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_proxy_dispose(
|
||||
struct wf_jsonrpc_proxy * proxy)
|
||||
{
|
||||
wf_jsonrpc_impl_proxy_dispose(proxy);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_proxy_invoke(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
wf_jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
wf_jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_proxy_notify(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
wf_jsonrpc_impl_proxy_notify(proxy, method_name, param_info, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_proxy_onresult(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
json_t * message)
|
||||
{
|
||||
wf_jsonrpc_impl_proxy_onresult(proxy, message);
|
||||
}
|
||||
|
||||
|
||||
// request
|
||||
|
||||
bool wf_jsonrpc_is_request(
|
||||
json_t * message)
|
||||
{
|
||||
return wf_jsonrpc_impl_is_request(message);
|
||||
}
|
||||
|
||||
struct wf_jsonrpc_request * wf_jsonrpc_request_create(
|
||||
int id,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
return wf_jsonrpc_impl_request_create(id, send, user_data);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_request_dispose(
|
||||
struct wf_jsonrpc_request * request)
|
||||
{
|
||||
wf_jsonrpc_impl_request_dispose(request);
|
||||
}
|
||||
|
||||
void * wf_jsonrpc_request_get_userdata(
|
||||
struct wf_jsonrpc_request * request)
|
||||
{
|
||||
return wf_jsonrpc_impl_request_get_userdata(request);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_respond(
|
||||
struct wf_jsonrpc_request * request,
|
||||
json_t * result)
|
||||
{
|
||||
wf_jsonrpc_impl_respond(request, result);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_respond_error(
|
||||
struct wf_jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
wf_jsonrpc_impl_respond_error(request, code, message);
|
||||
}
|
||||
|
||||
// response
|
||||
|
||||
bool wf_jsonrpc_is_response(
|
||||
json_t * message)
|
||||
{
|
||||
return wf_jsonrpc_impl_is_response(message);
|
||||
}
|
||||
|
||||
// server
|
||||
|
||||
struct wf_jsonrpc_server *
|
||||
wf_jsonrpc_server_create(void)
|
||||
{
|
||||
return wf_jsonrpc_impl_server_create();
|
||||
}
|
||||
|
||||
void
|
||||
wf_jsonrpc_server_dispose(
|
||||
struct wf_jsonrpc_server * server)
|
||||
{
|
||||
wf_jsonrpc_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_server_add(
|
||||
struct wf_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
wf_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
wf_jsonrpc_impl_server_add(server, method_name, invoke, user_data);
|
||||
}
|
||||
|
||||
void wf_jsonrpc_server_process(
|
||||
struct wf_jsonrpc_server * server,
|
||||
json_t * request,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
wf_jsonrpc_impl_server_process(server, request, send, user_data);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include "jsonrpc/impl/error.h"
|
||||
#include "wf/jsonrpc/impl/error.h"
|
||||
|
||||
json_t *
|
||||
jsonrpc_impl_error(
|
||||
wf_jsonrpc_impl_error(
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
@ -13,13 +13,13 @@ jsonrpc_impl_error(
|
||||
}
|
||||
|
||||
void
|
||||
jsonrpc_impl_propate_error(
|
||||
jsonrpc_proxy_finished_fn * finised,
|
||||
wf_jsonrpc_impl_propate_error(
|
||||
wf_jsonrpc_proxy_finished_fn * finised,
|
||||
void * user_data,
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
json_t * error = jsonrpc_impl_error(code, message);
|
||||
json_t * error = wf_jsonrpc_impl_error(code, message);
|
||||
finised(user_data, NULL, error);
|
||||
|
||||
json_decref(error);
|
@ -1,8 +1,8 @@
|
||||
#ifndef JSONRPC_IMPL_ERROR_H
|
||||
#define JSONRPC_IMPL_ERROR_H
|
||||
#ifndef WF_JSONRPC_IMPL_ERROR_H
|
||||
#define WF_JSONRPC_IMPL_ERROR_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/proxy_finished_fn.h"
|
||||
#include "wf/jsonrpc/proxy_finished_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -10,13 +10,13 @@ extern "C"
|
||||
#endif
|
||||
|
||||
extern json_t *
|
||||
jsonrpc_impl_error(
|
||||
wf_jsonrpc_impl_error(
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
extern void
|
||||
jsonrpc_impl_propate_error(
|
||||
jsonrpc_proxy_finished_fn * finised,
|
||||
wf_jsonrpc_impl_propate_error(
|
||||
wf_jsonrpc_proxy_finished_fn * finised,
|
||||
void * user_data,
|
||||
int code,
|
||||
char const * message);
|
@ -1,13 +1,13 @@
|
||||
#include "jsonrpc/impl/method.h"
|
||||
#include "wf/jsonrpc/impl/method.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct jsonrpc_method * jsonrpc_impl_method_create(
|
||||
struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create(
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
wf_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct jsonrpc_method * method = malloc(sizeof(struct jsonrpc_method));
|
||||
struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
@ -19,8 +19,8 @@ struct jsonrpc_method * jsonrpc_impl_method_create(
|
||||
return method;
|
||||
}
|
||||
|
||||
void jsonrpc_impl_method_dispose(
|
||||
struct jsonrpc_method * method)
|
||||
void wf_jsonrpc_impl_method_dispose(
|
||||
struct wf_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
34
lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h
Normal file
34
lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef WF_JSONRPC_IMPL_METHOD_H
|
||||
#define WF_JSONRPC_IMPL_METHOD_H
|
||||
|
||||
#include "wf/jsonrpc/method_invoke_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_method
|
||||
{
|
||||
struct wf_jsonrpc_method * next;
|
||||
char * name;
|
||||
wf_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct wf_jsonrpc_method *
|
||||
wf_jsonrpc_impl_method_create(
|
||||
char const * method_name,
|
||||
wf_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_method_dispose(
|
||||
struct wf_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,44 +1,44 @@
|
||||
#include "jsonrpc/impl/proxy.h"
|
||||
#include "jsonrpc/impl/response.h"
|
||||
#include "jsonrpc/impl/error.h"
|
||||
#include "jsonrpc/status.h"
|
||||
#include "wf/jsonrpc/impl/proxy.h"
|
||||
#include "wf/jsonrpc/impl/response.h"
|
||||
#include "wf/jsonrpc/impl/error.h"
|
||||
#include "wf/jsonrpc/status.h"
|
||||
|
||||
#include <wf/timer/timer.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct jsonrpc_proxy *
|
||||
jsonrpc_impl_proxy_create(
|
||||
struct wf_jsonrpc_proxy *
|
||||
wf_jsonrpc_impl_proxy_create(
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
struct jsonrpc_proxy * proxy = malloc(sizeof(struct jsonrpc_proxy));
|
||||
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
|
||||
if (NULL != proxy)
|
||||
{
|
||||
jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data);
|
||||
wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data);
|
||||
}
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
void jsonrpc_impl_proxy_dispose(
|
||||
struct jsonrpc_proxy * proxy)
|
||||
void wf_jsonrpc_impl_proxy_dispose(
|
||||
struct wf_jsonrpc_proxy * proxy)
|
||||
{
|
||||
jsonrpc_impl_proxy_cleanup(proxy);
|
||||
wf_jsonrpc_impl_proxy_cleanup(proxy);
|
||||
free(proxy);
|
||||
}
|
||||
|
||||
static void jsonrpc_impl_proxy_on_timeout(
|
||||
static void wf_jsonrpc_impl_proxy_on_timeout(
|
||||
struct wf_timer * timer, void * proxy_ptr)
|
||||
{
|
||||
struct jsonrpc_proxy * proxy = proxy_ptr;
|
||||
struct wf_jsonrpc_proxy * proxy = proxy_ptr;
|
||||
|
||||
if (proxy->request.is_pending)
|
||||
{
|
||||
jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
wf_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
void * user_data = proxy->request.user_data;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
@ -47,11 +47,11 @@ static void jsonrpc_impl_proxy_on_timeout(
|
||||
proxy->request.finished = NULL;
|
||||
wf_timer_cancel(timer);
|
||||
|
||||
jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout");
|
||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_TIMEOUT, "Timeout");
|
||||
}
|
||||
}
|
||||
|
||||
static json_t * jsonrpc_impl_request_create(
|
||||
static json_t * wf_jsonrpc_impl_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
||||
@ -101,11 +101,11 @@ static json_t * jsonrpc_impl_request_create(
|
||||
return request;
|
||||
}
|
||||
|
||||
void jsonrpc_impl_proxy_init(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
void wf_jsonrpc_impl_proxy_init(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
struct wf_timer_manager * timeout_manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
proxy->send = send;
|
||||
@ -113,16 +113,16 @@ void jsonrpc_impl_proxy_init(
|
||||
proxy->user_data = user_data;
|
||||
proxy->request.is_pending = false;
|
||||
proxy->request.timer = wf_timer_create(timeout_manager,
|
||||
&jsonrpc_impl_proxy_on_timeout, proxy);
|
||||
&wf_jsonrpc_impl_proxy_on_timeout, proxy);
|
||||
}
|
||||
|
||||
void jsonrpc_impl_proxy_cleanup(
|
||||
struct jsonrpc_proxy * proxy)
|
||||
void wf_jsonrpc_impl_proxy_cleanup(
|
||||
struct wf_jsonrpc_proxy * proxy)
|
||||
{
|
||||
if (proxy->request.is_pending)
|
||||
{
|
||||
void * user_data = proxy->request.user_data;
|
||||
jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
wf_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
proxy->request.finished = NULL;
|
||||
@ -130,15 +130,15 @@ void jsonrpc_impl_proxy_cleanup(
|
||||
proxy->request.id = 0;
|
||||
wf_timer_cancel(proxy->request.timer);
|
||||
|
||||
jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad: cancelled pending request during shutdown");
|
||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: cancelled pending request during shutdown");
|
||||
}
|
||||
|
||||
wf_timer_dispose(proxy->request.timer);
|
||||
}
|
||||
|
||||
void jsonrpc_impl_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
void wf_jsonrpc_impl_proxy_invoke(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
wf_jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
@ -153,7 +153,7 @@ void jsonrpc_impl_proxy_invoke(
|
||||
proxy->request.id = 42;
|
||||
wf_timer_start(proxy->request.timer, proxy->timeout);
|
||||
|
||||
json_t * request = jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args);
|
||||
json_t * request = wf_jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args);
|
||||
|
||||
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
|
||||
if (!is_send)
|
||||
@ -164,7 +164,7 @@ void jsonrpc_impl_proxy_invoke(
|
||||
proxy->request.id = 0;
|
||||
wf_timer_cancel(proxy->request.timer);
|
||||
|
||||
jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad: requenst is not sent");
|
||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: requenst is not sent");
|
||||
}
|
||||
|
||||
if (NULL != request)
|
||||
@ -174,18 +174,18 @@ void jsonrpc_impl_proxy_invoke(
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_BUSY, "Busy");
|
||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_BUSY, "Busy");
|
||||
}
|
||||
}
|
||||
|
||||
extern void jsonrpc_impl_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
extern void wf_jsonrpc_impl_proxy_notify(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
va_list args
|
||||
)
|
||||
{
|
||||
json_t * request = jsonrpc_impl_request_create(method_name, 0, param_info, args);
|
||||
json_t * request = wf_jsonrpc_impl_request_create(method_name, 0, param_info, args);
|
||||
if (NULL != request)
|
||||
{
|
||||
proxy->send(request, proxy->user_data);
|
||||
@ -194,16 +194,16 @@ extern void jsonrpc_impl_proxy_notify(
|
||||
}
|
||||
|
||||
|
||||
void jsonrpc_impl_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
void wf_jsonrpc_impl_proxy_onresult(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
json_t * message)
|
||||
{
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_impl_response_init(&response, message);
|
||||
struct wf_jsonrpc_response response;
|
||||
wf_jsonrpc_impl_response_init(&response, message);
|
||||
|
||||
if ((proxy->request.is_pending) && (response.id == proxy->request.id))
|
||||
{
|
||||
jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
wf_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
void * user_data = proxy->request.user_data;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
@ -215,6 +215,6 @@ void jsonrpc_impl_proxy_onresult(
|
||||
finished(user_data, response.result, response.error);
|
||||
}
|
||||
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
}
|
||||
|
84
lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h
Normal file
84
lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h
Normal file
@ -0,0 +1,84 @@
|
||||
#ifndef WF_JSONRPC_IMPL_PROXY_H
|
||||
#define WF_JSONRPC_IMPL_PROXY_H
|
||||
|
||||
#include "wf/jsonrpc/proxy_finished_fn.h"
|
||||
#include "wf/jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_timer_manager;
|
||||
struct wf_timer;
|
||||
|
||||
struct wf_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wf_jsonrpc_proxy_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_timer * timer;
|
||||
};
|
||||
|
||||
struct wf_jsonrpc_proxy
|
||||
{
|
||||
struct wf_jsonrpc_request request;
|
||||
int timeout;
|
||||
wf_jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_proxy_init(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_proxy_cleanup(
|
||||
struct wf_jsonrpc_proxy * proxy);
|
||||
|
||||
extern struct wf_jsonrpc_proxy *
|
||||
wf_jsonrpc_impl_proxy_create(
|
||||
struct wf_timer_manager * manager,
|
||||
int timeout,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_proxy_dispose(
|
||||
struct wf_jsonrpc_proxy * proxy);
|
||||
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_proxy_invoke(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
wf_jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
va_list args
|
||||
);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_proxy_notify(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
va_list args
|
||||
);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_proxy_onresult(
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,16 +1,16 @@
|
||||
#include "jsonrpc/impl/request.h"
|
||||
#include "jsonrpc/impl/error.h"
|
||||
#include "wf/jsonrpc/impl/request.h"
|
||||
#include "wf/jsonrpc/impl/error.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct jsonrpc_request
|
||||
struct wf_jsonrpc_request
|
||||
{
|
||||
int id;
|
||||
jsonrpc_send_fn * send;
|
||||
wf_jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
bool
|
||||
jsonrpc_impl_is_request(
|
||||
wf_jsonrpc_impl_is_request(
|
||||
json_t * message)
|
||||
{
|
||||
json_t * id = json_object_get(message, "id");
|
||||
@ -22,13 +22,13 @@ jsonrpc_impl_is_request(
|
||||
}
|
||||
|
||||
|
||||
struct jsonrpc_request *
|
||||
jsonrpc_impl_request_create(
|
||||
struct wf_jsonrpc_request *
|
||||
wf_jsonrpc_impl_request_create(
|
||||
int id,
|
||||
jsonrpc_send_fn * send,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
struct jsonrpc_request * request = malloc(sizeof(struct jsonrpc_request));
|
||||
struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request));
|
||||
if (NULL != request)
|
||||
{
|
||||
request->id = id;
|
||||
@ -40,23 +40,23 @@ jsonrpc_impl_request_create(
|
||||
}
|
||||
|
||||
void
|
||||
jsonrpc_impl_request_dispose(
|
||||
struct jsonrpc_request * request)
|
||||
wf_jsonrpc_impl_request_dispose(
|
||||
struct wf_jsonrpc_request * request)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
void *
|
||||
jsonrpc_impl_request_get_userdata(
|
||||
struct jsonrpc_request * request)
|
||||
wf_jsonrpc_impl_request_get_userdata(
|
||||
struct wf_jsonrpc_request * request)
|
||||
{
|
||||
return request->user_data;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
jsonrpc_impl_respond(
|
||||
struct jsonrpc_request * request,
|
||||
wf_jsonrpc_impl_respond(
|
||||
struct wf_jsonrpc_request * request,
|
||||
json_t * result)
|
||||
{
|
||||
json_t * response = json_object();
|
||||
@ -65,20 +65,20 @@ jsonrpc_impl_respond(
|
||||
|
||||
request->send(response, request->user_data);
|
||||
json_decref(response);
|
||||
jsonrpc_impl_request_dispose(request);
|
||||
wf_jsonrpc_impl_request_dispose(request);
|
||||
}
|
||||
|
||||
void jsonrpc_impl_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
void wf_jsonrpc_impl_respond_error(
|
||||
struct wf_jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
json_t * response = json_object();
|
||||
json_object_set_new(response, "error", jsonrpc_impl_error(code, message));
|
||||
json_object_set_new(response, "error", wf_jsonrpc_impl_error(code, message));
|
||||
json_object_set_new(response, "id", json_integer(request->id));
|
||||
|
||||
request->send(response, request->user_data);
|
||||
json_decref(response);
|
||||
jsonrpc_impl_request_dispose(request);
|
||||
wf_jsonrpc_impl_request_dispose(request);
|
||||
}
|
||||
|
53
lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h
Normal file
53
lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef WF_JSONRPC_IMPL_REQUEST_H
|
||||
#define WF_JSONRPC_IMPL_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 <wf/jsonrpc/api.h>
|
||||
#include "wf/jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_request;
|
||||
|
||||
extern bool wf_jsonrpc_impl_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern struct wf_jsonrpc_request * wf_jsonrpc_impl_request_create(
|
||||
int id,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_jsonrpc_impl_request_dispose(
|
||||
struct wf_jsonrpc_request * request);
|
||||
|
||||
extern void * wf_jsonrpc_impl_request_get_userdata(
|
||||
struct wf_jsonrpc_request * request);
|
||||
|
||||
extern void wf_jsonrpc_impl_respond(
|
||||
struct wf_jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern void wf_jsonrpc_impl_respond_error(
|
||||
struct wf_jsonrpc_request * request,
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#include "jsonrpc/impl/response.h"
|
||||
#include "jsonrpc/impl/error.h"
|
||||
#include "jsonrpc/status.h"
|
||||
#include "wf/jsonrpc/impl/response.h"
|
||||
#include "wf/jsonrpc/impl/error.h"
|
||||
#include "wf/jsonrpc/status.h"
|
||||
|
||||
bool
|
||||
jsonrpc_impl_is_response(
|
||||
wf_jsonrpc_impl_is_response(
|
||||
json_t * message)
|
||||
{
|
||||
json_t * id = json_object_get(message, "id");
|
||||
@ -16,8 +16,8 @@ jsonrpc_impl_is_response(
|
||||
|
||||
|
||||
void
|
||||
jsonrpc_impl_response_init(
|
||||
struct jsonrpc_response * result,
|
||||
wf_jsonrpc_impl_response_init(
|
||||
struct wf_jsonrpc_response * result,
|
||||
json_t * response)
|
||||
{
|
||||
result->id = -1;
|
||||
@ -27,7 +27,7 @@ jsonrpc_impl_response_init(
|
||||
json_t * id_holder = json_object_get(response, "id");
|
||||
if ((NULL == id_holder) || (!json_is_integer(id_holder)))
|
||||
{
|
||||
result->error = jsonrpc_impl_error(JSONRPC_BAD_FORMAT, "invalid format: missing id");
|
||||
result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: missing id");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -47,14 +47,14 @@ jsonrpc_impl_response_init(
|
||||
}
|
||||
else
|
||||
{
|
||||
result->error = jsonrpc_impl_error(JSONRPC_BAD_FORMAT, "invalid format: invalid error object");
|
||||
result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: invalid error object");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
jsonrpc_impl_response_cleanup(
|
||||
struct jsonrpc_response * response)
|
||||
wf_jsonrpc_impl_response_cleanup(
|
||||
struct wf_jsonrpc_response * response)
|
||||
{
|
||||
if (NULL != response->result)
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
#ifndef JSONRPC_IMPL_RESPONSE_H
|
||||
#define JSONRPC_IMPL_RESPONSE_H
|
||||
#ifndef WF_JSONRPC_IMPL_RESPONSE_H
|
||||
#define WF_JSONRPC_IMPL_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
@ -15,22 +15,22 @@ using std::size_t;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct jsonrpc_response
|
||||
struct wf_jsonrpc_response
|
||||
{
|
||||
json_t * result;
|
||||
json_t * error;
|
||||
int id;
|
||||
};
|
||||
|
||||
extern bool jsonrpc_impl_is_response(
|
||||
extern bool wf_jsonrpc_impl_is_response(
|
||||
json_t * message);
|
||||
|
||||
extern void jsonrpc_impl_response_init(
|
||||
struct jsonrpc_response * response,
|
||||
extern void wf_jsonrpc_impl_response_init(
|
||||
struct wf_jsonrpc_response * response,
|
||||
json_t * message);
|
||||
|
||||
extern void jsonrpc_impl_response_cleanup(
|
||||
struct jsonrpc_response * response);
|
||||
extern void wf_jsonrpc_impl_response_cleanup(
|
||||
struct wf_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
132
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c
Normal file
132
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c
Normal file
@ -0,0 +1,132 @@
|
||||
#include "wf/jsonrpc/impl/server.h"
|
||||
#include "wf/jsonrpc/impl/method.h"
|
||||
#include "wf/jsonrpc/impl/request.h"
|
||||
#include "wf/jsonrpc/impl/unused_param.h"
|
||||
#include "wf/jsonrpc/status.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wf_jsonrpc_server
|
||||
{
|
||||
struct wf_jsonrpc_method * methods;
|
||||
};
|
||||
|
||||
static void
|
||||
wf_jsonrpc_impl_server_init(
|
||||
struct wf_jsonrpc_server * server);
|
||||
|
||||
static void
|
||||
wf_jsonrpc_impl_server_cleanup(
|
||||
struct wf_jsonrpc_server * server);
|
||||
|
||||
struct wf_jsonrpc_server *
|
||||
wf_jsonrpc_impl_server_create(void)
|
||||
{
|
||||
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
|
||||
if (NULL != server)
|
||||
{
|
||||
wf_jsonrpc_impl_server_init(server);
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
void
|
||||
wf_jsonrpc_impl_server_dispose(
|
||||
struct wf_jsonrpc_server * server)
|
||||
{
|
||||
wf_jsonrpc_impl_server_cleanup(server);
|
||||
free(server);
|
||||
}
|
||||
|
||||
|
||||
static void wf_jsonrpc_impl_server_init(
|
||||
struct wf_jsonrpc_server * server)
|
||||
{
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
static void wf_jsonrpc_impl_server_cleanup(
|
||||
struct wf_jsonrpc_server * server)
|
||||
{
|
||||
struct wf_jsonrpc_method * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
struct wf_jsonrpc_method * next = current->next;
|
||||
wf_jsonrpc_impl_method_dispose(current);
|
||||
current = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void wf_jsonrpc_impl_server_add(
|
||||
struct wf_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
wf_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_jsonrpc_method * method = wf_jsonrpc_impl_method_create(method_name, invoke, user_data);
|
||||
method->next = server->methods;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
static void wf_jsonrpc_impl_server_invalid_method_invoke(
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * WF_JSONRPC_UNUSED_PARAM(method_name),
|
||||
json_t * WF_JSONRPC_UNUSED_PARAM(params),
|
||||
void * WF_JSONRPC_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wf_jsonrpc_impl_respond_error(request, WF_JSONRPC_BAD_NOTIMPLEMENTED, "not implemented");
|
||||
}
|
||||
|
||||
static struct wf_jsonrpc_method const wf_jsonrpc_impl_server_invalid_method =
|
||||
{
|
||||
.next = NULL,
|
||||
.name = "<invalid>",
|
||||
.invoke = &wf_jsonrpc_impl_server_invalid_method_invoke,
|
||||
.user_data = NULL
|
||||
};
|
||||
|
||||
static struct wf_jsonrpc_method const *
|
||||
wf_jsonrpc_impl_server_get_method(
|
||||
struct wf_jsonrpc_server * server,
|
||||
char const * method_name)
|
||||
{
|
||||
struct wf_jsonrpc_method const * current = server->methods;
|
||||
while (NULL != current)
|
||||
{
|
||||
if (0 == strcmp(method_name, current->name))
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return &wf_jsonrpc_impl_server_invalid_method;
|
||||
}
|
||||
|
||||
void wf_jsonrpc_impl_server_process(
|
||||
struct wf_jsonrpc_server * server,
|
||||
json_t * request_data,
|
||||
wf_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_jsonrpc_request * request = wf_jsonrpc_impl_request_create(id, send, user_data);
|
||||
struct wf_jsonrpc_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name);
|
||||
|
||||
method->invoke(request, method_name, params, method->user_data);
|
||||
}
|
||||
}
|
||||
|
41
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h
Normal file
41
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef WF_JSONRPC_IMPL_SERVER_H
|
||||
#define WF_JSONRPC_IMPL_SERVER_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wf/jsonrpc/method_invoke_fn.h"
|
||||
#include "wf/jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_server;
|
||||
|
||||
extern struct wf_jsonrpc_server *
|
||||
wf_jsonrpc_impl_server_create(void);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_server_dispose(
|
||||
struct wf_jsonrpc_server * server);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_server_add(
|
||||
struct wf_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
wf_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_jsonrpc_impl_server_process(
|
||||
struct wf_jsonrpc_server * server,
|
||||
json_t * request,
|
||||
wf_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
10
lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h
Normal file
10
lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef WF_JSONRPC_UTIL_H
|
||||
#define WF_JSONRPC_UTIL_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define WF_JSONRPC_UNUSED_PARAM(param) param __attribute__((unused))
|
||||
#else
|
||||
#define WF_JSONRPC_UNUSED_PARAM(param)
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,112 +1,112 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jsonrpc/request.h"
|
||||
#include "wf/jsonrpc/request.h"
|
||||
|
||||
TEST(jsonrpc_is_request, request_with_object_params)
|
||||
TEST(wf_jsonrpc_is_request, request_with_object_params)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(jsonrpc_is_request(request));
|
||||
ASSERT_TRUE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, request_with_array_params)
|
||||
TEST(wf_jsonrpc_is_request, request_with_array_params)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "params", json_array());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(jsonrpc_is_request(request));
|
||||
ASSERT_TRUE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, null_request)
|
||||
TEST(wf_jsonrpc_is_request, null_request)
|
||||
{
|
||||
ASSERT_FALSE(jsonrpc_is_request(nullptr));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(nullptr));
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request)
|
||||
{
|
||||
json_t * request = json_array();
|
||||
json_array_append_new(request, json_string("method"));
|
||||
json_array_append_new(request, json_object());
|
||||
json_array_append_new(request, json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request_without_id)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request_without_id)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "params", json_object());
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request_due_to_invalid_id)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_id)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_string("42"));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request_without_method)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request_without_method)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request_due_to_invalid_method)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_method)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_integer(42));
|
||||
json_object_set_new(request, "params", json_object());
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request_without_params)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request_without_params)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("method"));
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_request, invalid_request_due_to_invalid_params)
|
||||
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_params)
|
||||
{
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "methdo", json_string("method"));
|
||||
json_object_set_new(request, "params", json_string("params"));
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_request(request));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_request(request));
|
||||
|
||||
json_decref(request);
|
||||
}
|
@ -1,94 +1,94 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jsonrpc/response.h"
|
||||
#include "wf/jsonrpc/response.h"
|
||||
|
||||
TEST(jsonrpc_is_response, valid_result)
|
||||
TEST(wf_jsonrpc_is_response, valid_result)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "result", json_object());
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(jsonrpc_is_response(message));
|
||||
ASSERT_TRUE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, valid_result_string)
|
||||
TEST(wf_jsonrpc_is_response, valid_result_string)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "result", json_string("also valid"));
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(jsonrpc_is_response(message));
|
||||
ASSERT_TRUE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, valid_error)
|
||||
TEST(wf_jsonrpc_is_response, valid_error)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "error", json_object());
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_TRUE(jsonrpc_is_response(message));
|
||||
ASSERT_TRUE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_null)
|
||||
TEST(wf_jsonrpc_is_response, invalid_null)
|
||||
{
|
||||
ASSERT_FALSE(jsonrpc_is_response(nullptr));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_response(nullptr));
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_message)
|
||||
TEST(wf_jsonrpc_is_response, invalid_message)
|
||||
{
|
||||
json_t * message = json_array();
|
||||
json_array_append_new(message, json_object());
|
||||
json_array_append_new(message, json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_missing_id)
|
||||
TEST(wf_jsonrpc_is_response, invalid_missing_id)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "result", json_object());
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_id_wrong_type)
|
||||
TEST(wf_jsonrpc_is_response, invalid_id_wrong_type)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "result", json_object());
|
||||
json_object_set_new(message, "id", json_string("42"));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_missing_result_and_error)
|
||||
TEST(wf_jsonrpc_is_response, invalid_missing_result_and_error)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_is_response, invalid_error_wrong_type)
|
||||
TEST(wf_jsonrpc_is_response, invalid_error_wrong_type)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "error", json_array());
|
||||
json_object_set_new(message, "id", json_integer(42));
|
||||
|
||||
ASSERT_FALSE(jsonrpc_is_response(message));
|
||||
ASSERT_FALSE(wf_jsonrpc_is_response(message));
|
||||
|
||||
json_decref(message);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "wf/jsonrpc/proxy.h"
|
||||
#include "wf/timer/manager.h"
|
||||
#include "webfuse/utils/msleep.hpp"
|
||||
#include "webfuse/core/json_util.h"
|
||||
@ -85,31 +85,31 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, init)
|
||||
TEST(wf_jsonrpc_proxy, init)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext context;
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
|
||||
ASSERT_FALSE(context.is_called);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, invoke)
|
||||
TEST(wf_jsonrpc_proxy, invoke)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_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));
|
||||
@ -131,24 +131,24 @@ TEST(jsonrpc_proxy, invoke)
|
||||
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_FALSE(nullptr == finished_context.error);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails)
|
||||
TEST(wf_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context(false);
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_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));
|
||||
@ -156,25 +156,25 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails)
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_FALSE(nullptr == finished_context.error);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
||||
TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
|
||||
FinishedContext finished_context2;
|
||||
void * finished_data2 = reinterpret_cast<void*>(&finished_context2);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", "");
|
||||
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", "");
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -184,42 +184,42 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
||||
ASSERT_TRUE(finished_context2.is_called);
|
||||
ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error));
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid)
|
||||
TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
|
||||
wf_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, wf_impl_jsonrpc_get_status(finished_context.error));
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, on_result)
|
||||
TEST(wf_jsonrpc_proxy, on_result)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_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));
|
||||
@ -231,7 +231,7 @@ TEST(jsonrpc_proxy, on_result)
|
||||
json_object_set_new(response, "result", json_string("okay"));
|
||||
json_object_set(response, "id", id);
|
||||
|
||||
jsonrpc_proxy_onresult(proxy, response);
|
||||
wf_jsonrpc_proxy_onresult(proxy, response);
|
||||
json_decref(response);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
@ -239,21 +239,21 @@ TEST(jsonrpc_proxy, on_result)
|
||||
ASSERT_TRUE(json_is_string(finished_context.result));
|
||||
ASSERT_STREQ("okay", json_string_value(finished_context.result));
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id)
|
||||
TEST(wf_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_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));
|
||||
@ -265,26 +265,26 @@ 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)));
|
||||
|
||||
jsonrpc_proxy_onresult(proxy, response);
|
||||
wf_jsonrpc_proxy_onresult(proxy, response);
|
||||
json_decref(response);
|
||||
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, timeout)
|
||||
TEST(wf_jsonrpc_proxy, timeout)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_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));
|
||||
@ -295,28 +295,28 @@ TEST(jsonrpc_proxy, timeout)
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error));
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, cleanup_pending_request)
|
||||
TEST(wf_jsonrpc_proxy, cleanup_pending_request)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data);
|
||||
|
||||
FinishedContext finished_context;
|
||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||
jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||
wf_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_FALSE(finished_context.is_called);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
|
||||
@ -325,15 +325,15 @@ TEST(jsonrpc_proxy, cleanup_pending_request)
|
||||
|
||||
|
||||
|
||||
TEST(jsonrpc_proxy, notify)
|
||||
TEST(wf_jsonrpc_proxy, notify)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42);
|
||||
wf_jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42);
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
ASSERT_TRUE(json_is_object(send_context.response));
|
||||
@ -353,22 +353,22 @@ TEST(jsonrpc_proxy, notify)
|
||||
json_t * id = json_object_get(send_context.response, "id");
|
||||
ASSERT_EQ(nullptr, id);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_proxy, notify_dont_send_invalid_request)
|
||||
TEST(wf_jsonrpc_proxy, notify_dont_send_invalid_request)
|
||||
{
|
||||
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
|
||||
|
||||
SendContext send_context;
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
jsonrpc_proxy_notify(proxy, "foo", "?");
|
||||
wf_jsonrpc_proxy_notify(proxy, "foo", "?");
|
||||
|
||||
ASSERT_FALSE(send_context.is_called);
|
||||
|
||||
jsonrpc_proxy_dispose(proxy);
|
||||
wf_jsonrpc_proxy_dispose(proxy);
|
||||
wf_timer_manager_dispose(timer_manager);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jsonrpc/request.h"
|
||||
#include "jsonrpc/status.h"
|
||||
#include "wf/jsonrpc/request.h"
|
||||
#include "wf/jsonrpc/status.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -23,29 +23,29 @@ bool jsonrpc_send(
|
||||
|
||||
}
|
||||
|
||||
TEST(jsonrpc_request, create_dispose)
|
||||
TEST(wf_jsonrpc_request, create_dispose)
|
||||
{
|
||||
Context context{nullptr};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
|
||||
struct jsonrpc_request * request =
|
||||
jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
struct wf_jsonrpc_request * request =
|
||||
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_NE(nullptr, request);
|
||||
ASSERT_EQ(user_data, jsonrpc_request_get_userdata(request));
|
||||
ASSERT_EQ(user_data, wf_jsonrpc_request_get_userdata(request));
|
||||
|
||||
jsonrpc_request_dispose(request);
|
||||
wf_jsonrpc_request_dispose(request);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_request, respond)
|
||||
TEST(wf_jsonrpc_request, respond)
|
||||
{
|
||||
Context context{nullptr};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
|
||||
struct jsonrpc_request * request =
|
||||
jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
struct wf_jsonrpc_request * request =
|
||||
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
|
||||
jsonrpc_respond(request, json_string("okay"));
|
||||
wf_jsonrpc_respond(request, json_string("okay"));
|
||||
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
|
||||
@ -66,15 +66,15 @@ TEST(jsonrpc_request, respond)
|
||||
json_decref(response);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_request, respond_error)
|
||||
TEST(wf_jsonrpc_request, respond_error)
|
||||
{
|
||||
Context context{nullptr};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
|
||||
struct jsonrpc_request * request =
|
||||
jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
struct wf_jsonrpc_request * request =
|
||||
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
||||
|
||||
jsonrpc_respond_error(request, JSONRPC_BAD, "Bad");
|
||||
wf_jsonrpc_respond_error(request, WF_JSONRPC_BAD, "Bad");
|
||||
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
|
||||
@ -93,7 +93,7 @@ TEST(jsonrpc_request, respond_error)
|
||||
|
||||
json_t * err_code = json_object_get(err, "code");
|
||||
ASSERT_TRUE(json_is_integer(err_code));
|
||||
ASSERT_EQ(JSONRPC_BAD, json_integer_value(err_code));
|
||||
ASSERT_EQ(WF_JSONRPC_BAD, json_integer_value(err_code));
|
||||
|
||||
json_t * err_message = json_object_get(err, "message");
|
||||
ASSERT_TRUE(json_is_string(err_message));
|
@ -1,27 +1,27 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jsonrpc/impl/response.h"
|
||||
#include "wf/jsonrpc/impl/response.h"
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
TEST(json_response, init_result)
|
||||
TEST(wf_json_response, init_result)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "result", json_integer(47));
|
||||
json_object_set_new(message, "id", json_integer(11));
|
||||
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_impl_response_init(&response, message);
|
||||
struct wf_jsonrpc_response response;
|
||||
wf_jsonrpc_impl_response_init(&response, message);
|
||||
|
||||
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);
|
||||
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(json_response, init_error)
|
||||
TEST(wf_json_response, init_error)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_t * err = json_object();
|
||||
@ -30,29 +30,29 @@ TEST(json_response, init_error)
|
||||
json_object_set_new(message, "error", err);
|
||||
json_object_set_new(message, "id", json_integer(23));
|
||||
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_impl_response_init(&response, message);
|
||||
struct wf_jsonrpc_response response;
|
||||
wf_jsonrpc_impl_response_init(&response, message);
|
||||
|
||||
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);
|
||||
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
TEST(json_response, init_format_error)
|
||||
TEST(wf_json_response, init_format_error)
|
||||
{
|
||||
json_t * message = json_object();
|
||||
json_object_set_new(message, "id", json_integer(12));
|
||||
|
||||
struct jsonrpc_response response;
|
||||
jsonrpc_impl_response_init(&response, message);
|
||||
struct wf_jsonrpc_response response;
|
||||
wf_jsonrpc_impl_response_init(&response, message);
|
||||
|
||||
ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error));
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(12, response.id);
|
||||
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
json_decref(message);
|
||||
}
|
@ -1,46 +1,46 @@
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "jsonrpc/impl/response.h"
|
||||
#include "wf/jsonrpc/impl/response.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
|
||||
static void response_parse_str(
|
||||
std::string const & buffer,
|
||||
struct jsonrpc_response * response)
|
||||
struct wf_jsonrpc_response * response)
|
||||
{
|
||||
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
|
||||
if (nullptr != message)
|
||||
{
|
||||
jsonrpc_impl_response_init(response, message);
|
||||
wf_jsonrpc_impl_response_init(response, message);
|
||||
json_decref(message);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(response_parser, test)
|
||||
{
|
||||
struct jsonrpc_response response;
|
||||
struct wf_jsonrpc_response response;
|
||||
|
||||
// no object
|
||||
response_parse_str("[]", &response);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
|
||||
// empty
|
||||
response_parse_str("{}", &response);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
|
||||
// no data
|
||||
response_parse_str("{\"id\":42}", &response);
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
|
||||
// custom error code
|
||||
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
|
||||
@ -48,12 +48,12 @@ TEST(response_parser, test)
|
||||
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
|
||||
// valid response
|
||||
response_parse_str("{\"result\": true, \"id\": 42}", &response);
|
||||
ASSERT_EQ(WF_GOOD, response.error);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
jsonrpc_impl_response_cleanup(&response);
|
||||
wf_jsonrpc_impl_response_cleanup(&response);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jsonrpc/server.h"
|
||||
#include "jsonrpc/request.h"
|
||||
#include "jsonrpc/status.h"
|
||||
#include "wf/jsonrpc/server.h"
|
||||
#include "wf/jsonrpc/request.h"
|
||||
#include "wf/jsonrpc/status.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -24,7 +24,7 @@ namespace
|
||||
}
|
||||
|
||||
void sayHello(
|
||||
struct jsonrpc_request * request,
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data)
|
||||
@ -34,15 +34,15 @@ namespace
|
||||
(void) user_data;
|
||||
|
||||
json_t * result = json_string("Hello");
|
||||
jsonrpc_respond(request, result);
|
||||
wf_jsonrpc_respond(request, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(jsonrpc_server, process_request)
|
||||
TEST(wf_jsonrpc_server, process_request)
|
||||
{
|
||||
struct jsonrpc_server * server = jsonrpc_server_create();
|
||||
jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
|
||||
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
|
||||
wf_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));
|
||||
jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
||||
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_TRUE(context.is_called);
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
@ -66,13 +66,13 @@ TEST(jsonrpc_server, process_request)
|
||||
|
||||
json_decref(context.response);
|
||||
json_decref(request);
|
||||
jsonrpc_server_dispose(server);
|
||||
wf_jsonrpc_server_dispose(server);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_server, invoke_unknown_method)
|
||||
TEST(wf_jsonrpc_server, invoke_unknown_method)
|
||||
{
|
||||
struct jsonrpc_server * server = jsonrpc_server_create();
|
||||
jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
|
||||
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
|
||||
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
|
||||
|
||||
Context context{nullptr, false};
|
||||
void * user_data = reinterpret_cast<void*>(&context);
|
||||
@ -80,7 +80,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));
|
||||
jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
||||
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_TRUE(context.is_called);
|
||||
ASSERT_NE(nullptr, context.response);
|
||||
@ -95,29 +95,29 @@ TEST(jsonrpc_server, invoke_unknown_method)
|
||||
|
||||
json_t * err_code = json_object_get(err, "code");
|
||||
ASSERT_TRUE(json_is_integer(err_code));
|
||||
ASSERT_EQ(JSONRPC_BAD_NOTIMPLEMENTED, json_integer_value(err_code));
|
||||
ASSERT_EQ(WF_JSONRPC_BAD_NOTIMPLEMENTED, json_integer_value(err_code));
|
||||
|
||||
json_t * err_message = json_object_get(err, "message");
|
||||
ASSERT_TRUE(json_is_string(err_message));
|
||||
|
||||
json_decref(context.response);
|
||||
json_decref(request);
|
||||
jsonrpc_server_dispose(server);
|
||||
wf_jsonrpc_server_dispose(server);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_server, skip_invalid_request)
|
||||
TEST(wf_jsonrpc_server, skip_invalid_request)
|
||||
{
|
||||
struct jsonrpc_server * server = jsonrpc_server_create();
|
||||
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
|
||||
|
||||
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());
|
||||
jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
||||
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
||||
|
||||
ASSERT_FALSE(context.is_called);
|
||||
|
||||
json_decref(request);
|
||||
jsonrpc_server_dispose(server);
|
||||
wf_jsonrpc_server_dispose(server);
|
||||
}
|
Loading…
Reference in New Issue
Block a user