1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

refactor: integrated former core code into impl

This commit is contained in:
Falk Werner 2020-06-28 19:43:08 +02:00
parent 8f33258fae
commit a30d21fec8
100 changed files with 898 additions and 901 deletions

View File

@ -6,7 +6,7 @@
#include "webfuse/impl/credentials.h"
#include "webfuse/impl/mountpoint.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/impl/client.h"
#include "webfuse/impl/client_tlsconfig.h"

View File

@ -1,18 +0,0 @@
#include "webfuse/core/lws_log.h"
#include <stdbool.h>
#include <libwebsockets.h>
#define WF_LWSLOG_DISABLE 0
static bool wf_lwslog_is_diabled = false;
void wf_lwslog_disable(void)
{
if (!wf_lwslog_is_diabled)
{
lws_set_log_level(WF_LWSLOG_DISABLE, NULL);
wf_lwslog_is_diabled = true;
}
}

View File

@ -1,15 +0,0 @@
#ifndef WF_LWS_LOG_H
#define WF_LWS_LOG_H
#ifdef __cplusplus
extern "C"
{
#endif
extern void wf_lwslog_disable(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,17 +0,0 @@
#include "webfuse/core/message_queue.h"
#include "webfuse/core/message.h"
#include "webfuse/core/container_of.h"
void wf_message_queue_cleanup(
struct wf_slist * queue)
{
struct wf_slist_item * item = wf_slist_first(queue);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
struct wf_message * message = wf_container_of(item, struct wf_message, item);
wf_message_dispose(message);
item = next;
}
wf_slist_init(queue);
}

View File

@ -1,19 +0,0 @@
#ifndef WF_STATUS_INTERN_H
#define WF_STATUS_INTERN_H
#include "webfuse/status.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int wf_status_to_rc(wf_status status);
extern char const * wf_status_tostring(wf_status status);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,31 +0,0 @@
#include "webfuse/core/timer/timepoint.h"
#include <time.h>
#define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000)
#define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000)
wf_timer_timepoint wf_timer_timepoint_now(void)
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
wf_timer_timepoint const now = (tp.tv_sec * WF_TIMER_MSEC_PER_SEC) + (tp.tv_nsec / WF_TIMER_NSEC_PER_MSEC);
return now;
}
wf_timer_timepoint wf_timer_timepoint_in_msec(wf_timer_timediff value)
{
wf_timer_timepoint const now = wf_timer_timepoint_now();
wf_timer_timepoint result = now + ((wf_timer_timepoint) value);
return result;
}
bool wf_timer_timepoint_is_elapsed(wf_timer_timepoint tp)
{
wf_timer_timepoint const now = wf_timer_timepoint_now();
wf_timer_timediff const diff = (wf_timer_timediff) (tp - now);
return (0 > diff);
}

View File

@ -1,7 +1,7 @@
#include "webfuse/impl/client.h"
#include "webfuse/impl/client_protocol.h"
#include "webfuse/impl/client_tlsconfig.h"
#include "webfuse/core/lws_log.h"
#include "webfuse/impl/util/lws_log.h"
#include <libwebsockets.h>
@ -25,7 +25,7 @@ wf_impl_client_create(
wf_client_callback_fn * callback,
void * user_data)
{
wf_lwslog_disable();
wf_impl_lwslog_disable();
struct wf_client * client = malloc(sizeof(struct wf_client));
wf_impl_client_tlsconfig_init(&client->tls);

View File

@ -4,15 +4,15 @@
#include "webfuse/impl/filesystem.h"
#include "webfuse/impl/mountpoint.h"
#include "webfuse/protocol_names.h"
#include "webfuse/core/url.h"
#include "webfuse/core/util.h"
#include "webfuse/core/timer/manager.h"
#include "webfuse/core/jsonrpc/response.h"
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/impl/util/url.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/impl/timer/manager.h"
#include "webfuse/impl/jsonrpc/response.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/core/message.h"
#include "webfuse/core/message_queue.h"
#include "webfuse/core/container_of.h"
#include "webfuse/impl/message.h"
#include "webfuse/impl/message_queue.h"
#include "webfuse/impl/util/container_of.h"
#include <stddef.h>
@ -35,9 +35,9 @@ wf_impl_client_protocol_process(
json_t * message = json_loadb(data, length, 0, NULL);
if (NULL != message)
{
if (wf_jsonrpc_is_response(message))
if (wf_impl_jsonrpc_is_response(message))
{
wf_jsonrpc_proxy_onresult(protocol->proxy, message);
wf_impl_jsonrpc_proxy_onresult(protocol->proxy, message);
}
json_decref(message);
@ -54,10 +54,10 @@ wf_impl_client_protocol_send(
if (NULL != protocol->wsi)
{
struct wf_message * message = wf_message_create(request);
struct wf_message * message = wf_impl_message_create(request);
if (NULL != message)
{
wf_slist_append(&protocol->messages, &message->item);
wf_impl_slist_append(&protocol->messages, &message->item);
lws_callback_on_writable(protocol->wsi);
result = true;
}
@ -95,7 +95,7 @@ wf_impl_client_protocol_on_add_filesystem_finished(
if (json_is_string(id))
{
char const * name = json_string_value(id);
struct wf_mountpoint * mountpoint = wf_mountpoint_create(context->local_path);
struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(context->local_path);
protocol->filesystem = wf_impl_filesystem_create(protocol->wsi,protocol->proxy, name, mountpoint);
if (NULL != protocol->filesystem)
{
@ -103,7 +103,7 @@ wf_impl_client_protocol_on_add_filesystem_finished(
}
else
{
wf_mountpoint_dispose(mountpoint);
wf_impl_mountpoint_dispose(mountpoint);
}
}
}
@ -126,7 +126,7 @@ static int wf_impl_client_protocol_lws_callback(
if (NULL != protocol)
{
wf_timer_manager_check(protocol->timer_manager);
wf_impl_timer_manager_check(protocol->timer_manager);
switch (reason)
{
@ -156,14 +156,14 @@ static int wf_impl_client_protocol_lws_callback(
{
result = 1;
}
else if (!wf_slist_empty(&protocol->messages))
else if (!wf_impl_slist_empty(&protocol->messages))
{
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
struct wf_slist_item * item = wf_impl_slist_remove_first(&protocol->messages);
struct wf_message * message = wf_container_of(item, struct wf_message, item);
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
wf_message_dispose(message);
wf_impl_message_dispose(message);
if (!wf_slist_empty(&protocol->messages))
if (!wf_impl_slist_empty(&protocol->messages))
{
lws_callback_on_writable(wsi);
}
@ -196,9 +196,9 @@ wf_impl_client_protocol_init(
protocol->user_data = user_data;
protocol->filesystem = NULL;
wf_slist_init(&protocol->messages);
protocol->timer_manager = wf_timer_manager_create();
protocol->proxy = wf_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_client_protocol_send, protocol);
wf_impl_slist_init(&protocol->messages);
protocol->timer_manager = wf_impl_timer_manager_create();
protocol->proxy = wf_impl_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_client_protocol_send, protocol);
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL);
}
@ -209,9 +209,9 @@ wf_impl_client_protocol_cleanup(
{
protocol->callback(protocol->user_data, WF_CLIENT_CLEANUP, NULL);
wf_jsonrpc_proxy_dispose(protocol->proxy);
wf_timer_manager_dispose(protocol->timer_manager);
wf_message_queue_cleanup(&protocol->messages);
wf_impl_jsonrpc_proxy_dispose(protocol->proxy);
wf_impl_timer_manager_dispose(protocol->timer_manager);
wf_impl_message_queue_cleanup(&protocol->messages);
if (NULL != protocol->filesystem)
{
@ -247,7 +247,7 @@ wf_impl_client_protocol_connect(
char const * url)
{
struct wf_url url_data;
bool const success = wf_url_init(&url_data, url);
bool const success = wf_impl_url_init(&url_data, url);
if (success)
{
struct lws_client_connect_info info;
@ -264,7 +264,7 @@ wf_impl_client_protocol_connect(
info.pwsi = &protocol->wsi;
lws_client_connect_via_info(&info);
wf_url_cleanup(&url_data);
wf_impl_url_cleanup(&url_data);
}
else
{
@ -297,7 +297,7 @@ wf_impl_client_protocol_authenticate(
protocol->callback(protocol->user_data, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, &creds);
json_incref(creds.data);
wf_jsonrpc_proxy_invoke(
wf_impl_jsonrpc_proxy_invoke(
protocol->proxy,
&wf_impl_client_protocol_on_authenticate_finished,
protocol,
@ -320,7 +320,7 @@ wf_impl_client_protocol_add_filesystem(
context->protocol = protocol;
context->local_path = strdup(local_path);
wf_jsonrpc_proxy_invoke(
wf_impl_jsonrpc_proxy_invoke(
protocol->proxy,
&wf_impl_client_protocol_on_add_filesystem_finished,
context,

View File

@ -2,7 +2,7 @@
#define WF_ADAPTER_IMPL_CLIENT_PROTOCOL_H
#include "webfuse/client_callback.h"
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -7,7 +7,7 @@
#include "webfuse/impl/fuse_wrapper.h"
#include "webfuse/impl/operation/context.h"
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
#ifdef __cplusplus
extern "C"

View File

@ -1,7 +1,7 @@
#include "webfuse/core/jsonrpc/error.h"
#include "webfuse/impl/jsonrpc/error.h"
json_t *
wf_jsonrpc_error(
wf_impl_jsonrpc_error(
int code,
char const * message)
{
@ -13,13 +13,13 @@ wf_jsonrpc_error(
}
void
wf_jsonrpc_propate_error(
wf_impl_jsonrpc_propate_error(
wf_jsonrpc_proxy_finished_fn * finised,
void * user_data,
int code,
char const * message)
{
json_t * error = wf_jsonrpc_error(code, message);
json_t * error = wf_impl_jsonrpc_error(code, message);
finised(user_data, NULL, error);
json_decref(error);

View File

@ -1,8 +1,8 @@
#ifndef WF_JSONRPC_ERROR_H
#define WF_JSONRPC_ERROR_H
#ifndef WF_IMPL_JSONRPC_ERROR_H
#define WF_IMPL_JSONRPC_ERROR_H
#include <jansson.h>
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
#include "webfuse/impl/jsonrpc/proxy_finished_fn.h"
#ifdef __cplusplus
extern "C"
@ -10,12 +10,12 @@ extern "C"
#endif
extern json_t *
wf_jsonrpc_error(
wf_impl_jsonrpc_error(
int code,
char const * message);
extern void
wf_jsonrpc_propate_error(
wf_impl_jsonrpc_propate_error(
wf_jsonrpc_proxy_finished_fn * finised,
void * user_data,
int code,

View File

@ -1,8 +1,8 @@
#include "webfuse/core/jsonrpc/method.h"
#include "webfuse/impl/jsonrpc/method.h"
#include <stdlib.h>
#include <string.h>
struct wf_jsonrpc_method * wf_jsonrpc_method_create(
struct wf_jsonrpc_method * wf_impl_jsonrpc_method_create(
char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke,
void * user_data)
@ -16,7 +16,7 @@ struct wf_jsonrpc_method * wf_jsonrpc_method_create(
return method;
}
void wf_jsonrpc_method_dispose(
void wf_impl_jsonrpc_method_dispose(
struct wf_jsonrpc_method * method)
{
free(method->name);

View File

@ -1,7 +1,7 @@
#ifndef WF_JSONRPC_METHOD_H
#define WF_JSONRPC_METHOD_H
#ifndef WF_IMPL_JSONRPC_METHOD_H
#define WF_IMPL_JSONRPC_METHOD_H
#include "webfuse/core/jsonrpc/method_invoke_fn.h"
#include "webfuse/impl/jsonrpc/method_invoke_fn.h"
#ifdef __cplusplus
extern "C"
@ -17,13 +17,13 @@ struct wf_jsonrpc_method
};
extern struct wf_jsonrpc_method *
wf_jsonrpc_method_create(
wf_impl_jsonrpc_method_create(
char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke,
void * user_data);
extern void
wf_jsonrpc_method_dispose(
wf_impl_jsonrpc_method_dispose(
struct wf_jsonrpc_method * method);
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_METHOD_INVOKE_FN_H
#define WF_JSONRPC_METHOD_INVOKE_FN_H
#ifndef WF_IMPL_JSONRPC_METHOD_INVOKE_FN_H
#define WF_IMPL_JSONRPC_METHOD_INVOKE_FN_H
#include <jansson.h>

View File

@ -1,34 +1,34 @@
#include "webfuse/core/jsonrpc/proxy_intern.h"
#include "webfuse/core/jsonrpc/response_intern.h"
#include "webfuse/core/jsonrpc/error.h"
#include "webfuse/impl/jsonrpc/proxy_intern.h"
#include "webfuse/impl/jsonrpc/response_intern.h"
#include "webfuse/impl/jsonrpc/error.h"
#include "webfuse/status.h"
#include "webfuse/core/timer/timer.h"
#include "webfuse/impl/timer/timer.h"
#include <stdlib.h>
#include <string.h>
struct wf_jsonrpc_proxy *
wf_jsonrpc_proxy_create(
wf_impl_jsonrpc_proxy_create(
struct wf_timer_manager * manager,
int timeout,
wf_jsonrpc_send_fn * send,
void * user_data)
{
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
wf_jsonrpc_proxy_init(proxy, manager, timeout, send, user_data);
wf_impl_jsonrpc_proxy_init(proxy, manager, timeout, send, user_data);
return proxy;
}
void wf_jsonrpc_proxy_dispose(
void wf_impl_jsonrpc_proxy_dispose(
struct wf_jsonrpc_proxy * proxy)
{
wf_jsonrpc_proxy_cleanup(proxy);
wf_impl_jsonrpc_proxy_cleanup(proxy);
free(proxy);
}
static void wf_jsonrpc_proxy_on_timeout(
static void wf_impl_jsonrpc_proxy_on_timeout(
struct wf_timer * timer, void * proxy_ptr)
{
struct wf_jsonrpc_proxy * proxy = proxy_ptr;
@ -42,13 +42,13 @@ static void wf_jsonrpc_proxy_on_timeout(
proxy->request.id = 0;
proxy->request.user_data = NULL;
proxy->request.finished = NULL;
wf_timer_cancel(timer);
wf_impl_timer_cancel(timer);
wf_jsonrpc_propate_error(finished, user_data, WF_BAD_TIMEOUT, "Timeout");
wf_impl_jsonrpc_propate_error(finished, user_data, WF_BAD_TIMEOUT, "Timeout");
}
}
static json_t * wf_jsonrpc_request_create(
static json_t * wf_impl_jsonrpc_request_create(
char const * method,
int id,
char const * param_info,
@ -98,7 +98,7 @@ static json_t * wf_jsonrpc_request_create(
return request;
}
void wf_jsonrpc_proxy_init(
void wf_impl_jsonrpc_proxy_init(
struct wf_jsonrpc_proxy * proxy,
struct wf_timer_manager * timeout_manager,
int timeout,
@ -109,11 +109,11 @@ void wf_jsonrpc_proxy_init(
proxy->timeout = timeout;
proxy->user_data = user_data;
proxy->request.is_pending = false;
proxy->request.timer = wf_timer_create(timeout_manager,
&wf_jsonrpc_proxy_on_timeout, proxy);
proxy->request.timer = wf_impl_timer_create(timeout_manager,
&wf_impl_jsonrpc_proxy_on_timeout, proxy);
}
void wf_jsonrpc_proxy_cleanup(
void wf_impl_jsonrpc_proxy_cleanup(
struct wf_jsonrpc_proxy * proxy)
{
if (proxy->request.is_pending)
@ -125,15 +125,15 @@ void wf_jsonrpc_proxy_cleanup(
proxy->request.finished = NULL;
proxy->request.user_data = NULL;
proxy->request.id = 0;
wf_timer_cancel(proxy->request.timer);
wf_impl_timer_cancel(proxy->request.timer);
wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: cancelled pending request during shutdown");
wf_impl_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: cancelled pending request during shutdown");
}
wf_timer_dispose(proxy->request.timer);
wf_impl_timer_dispose(proxy->request.timer);
}
void wf_jsonrpc_proxy_vinvoke(
void wf_impl_jsonrpc_proxy_vinvoke(
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
@ -147,9 +147,9 @@ void wf_jsonrpc_proxy_vinvoke(
proxy->request.finished = finished;
proxy->request.user_data = user_data;
proxy->request.id = 42;
wf_timer_start(proxy->request.timer, proxy->timeout);
wf_impl_timer_start(proxy->request.timer, proxy->timeout);
json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
json_t * request = wf_impl_jsonrpc_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)
@ -158,9 +158,9 @@ void wf_jsonrpc_proxy_vinvoke(
proxy->request.finished = NULL;
proxy->request.user_data = NULL;
proxy->request.id = 0;
wf_timer_cancel(proxy->request.timer);
wf_impl_timer_cancel(proxy->request.timer);
wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: requenst is not sent");
wf_impl_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: requenst is not sent");
}
if (NULL != request)
@ -170,17 +170,17 @@ void wf_jsonrpc_proxy_vinvoke(
}
else
{
wf_jsonrpc_propate_error(finished, user_data, WF_BAD_BUSY, "Busy");
wf_impl_jsonrpc_propate_error(finished, user_data, WF_BAD_BUSY, "Busy");
}
}
extern void wf_jsonrpc_proxy_vnotify(
extern void wf_impl_jsonrpc_proxy_vnotify(
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info,
va_list args)
{
json_t * request = wf_jsonrpc_request_create(method_name, 0, param_info, args);
json_t * request = wf_impl_jsonrpc_request_create(method_name, 0, param_info, args);
if (NULL != request)
{
@ -190,12 +190,12 @@ extern void wf_jsonrpc_proxy_vnotify(
}
void wf_jsonrpc_proxy_onresult(
void wf_impl_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy,
json_t * message)
{
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
if ((proxy->request.is_pending) && (response.id == proxy->request.id))
{
@ -206,11 +206,10 @@ void wf_jsonrpc_proxy_onresult(
proxy->request.id = 0;
proxy->request.user_data = NULL;
proxy->request.finished = NULL;
wf_timer_cancel(proxy->request.timer);
wf_impl_timer_cancel(proxy->request.timer);
finished(user_data, response.result, response.error);
}
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
}

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_PROXY_H
#define WF_JSONRPC_PROXY_H
#ifndef WF_IMPL_JSONRPC_PROXY_H
#define WF_IMPL_JSONRPC_PROXY_H
#ifndef __cplusplus
#include <stdarg.h>
@ -12,8 +12,8 @@ using std::size_t;
#endif
#include <jansson.h>
#include "webfuse/core/jsonrpc/send_fn.h"
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
#include "webfuse/impl/jsonrpc/send_fn.h"
#include "webfuse/impl/jsonrpc/proxy_finished_fn.h"
#ifdef __cplusplus
extern "C" {
@ -23,13 +23,13 @@ struct wf_jsonrpc_proxy;
struct wf_timer_manager;
extern struct wf_jsonrpc_proxy *
wf_jsonrpc_proxy_create(
wf_impl_jsonrpc_proxy_create(
struct wf_timer_manager * manager,
int timeout,
wf_jsonrpc_send_fn * send,
void * user_data);
extern void wf_jsonrpc_proxy_dispose(
extern void wf_impl_jsonrpc_proxy_dispose(
struct wf_jsonrpc_proxy * proxy);
//------------------------------------------------------------------------------
@ -46,7 +46,7 @@ extern void wf_jsonrpc_proxy_dispose(
/// \param param_info types of the param (s = string, i = integer, j = json)
/// \param ... params
//------------------------------------------------------------------------------
extern void wf_jsonrpc_proxy_invoke(
extern void wf_impl_jsonrpc_proxy_invoke(
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
@ -55,14 +55,14 @@ extern void wf_jsonrpc_proxy_invoke(
...
);
extern void wf_jsonrpc_proxy_notify(
extern void wf_impl_jsonrpc_proxy_notify(
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info,
...
);
extern void wf_jsonrpc_proxy_onresult(
extern void wf_impl_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy,
json_t * message);

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_PROXY_FINISHED_FN_H
#define WF_JSONRPC_PROXY_FINISHED_FN_H
#ifndef WF_IMPL_JSONRPC_PROXY_FINISHED_FN_H
#define WF_IMPL_JSONRPC_PROXY_FINISHED_FN_H
#include <jansson.h>

View File

@ -1,9 +1,9 @@
#ifndef WF_JSONRPC_PROXY_INTERN_H
#define WF_JSONRPC_PROXY_INTERN_H
#ifndef WF_IMPL_JSONRPC_PROXY_INTERN_H
#define WF_IMPL_JSONRPC_PROXY_INTERN_H
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
#include "webfuse/core/jsonrpc/send_fn.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/jsonrpc/proxy_finished_fn.h"
#include "webfuse/impl/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
@ -30,7 +30,7 @@ struct wf_jsonrpc_proxy
};
extern void
wf_jsonrpc_proxy_init(
wf_impl_jsonrpc_proxy_init(
struct wf_jsonrpc_proxy * proxy,
struct wf_timer_manager * manager,
int timeout,
@ -38,10 +38,10 @@ wf_jsonrpc_proxy_init(
void * user_data);
extern void
wf_jsonrpc_proxy_cleanup(
wf_impl_jsonrpc_proxy_cleanup(
struct wf_jsonrpc_proxy * proxy);
extern void wf_jsonrpc_proxy_vinvoke(
extern void wf_impl_jsonrpc_proxy_vinvoke(
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
@ -49,7 +49,7 @@ extern void wf_jsonrpc_proxy_vinvoke(
char const * param_info,
va_list args);
extern void wf_jsonrpc_proxy_vnotify(
extern void wf_impl_jsonrpc_proxy_vnotify(
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info,

View File

@ -1,6 +1,6 @@
#include "webfuse/core/jsonrpc/proxy_intern.h"
#include "webfuse/impl/jsonrpc/proxy_intern.h"
void wf_jsonrpc_proxy_invoke(
void wf_impl_jsonrpc_proxy_invoke(
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
@ -10,11 +10,11 @@ void wf_jsonrpc_proxy_invoke(
{
va_list args;
va_start(args, param_info);
wf_jsonrpc_proxy_vinvoke(proxy, finished, user_data, method_name, param_info, args);
wf_impl_jsonrpc_proxy_vinvoke(proxy, finished, user_data, method_name, param_info, args);
va_end(args);
}
extern void wf_jsonrpc_proxy_notify(
extern void wf_impl_jsonrpc_proxy_notify(
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info,
@ -23,6 +23,6 @@ extern void wf_jsonrpc_proxy_notify(
{
va_list args;
va_start(args, param_info);
wf_jsonrpc_proxy_vnotify(proxy, method_name, param_info, args);
wf_impl_jsonrpc_proxy_vnotify(proxy, method_name, param_info, args);
va_end(args);
}

View File

@ -1,5 +1,5 @@
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/core/jsonrpc/error.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/error.h"
#include <stdlib.h>
struct wf_jsonrpc_request
@ -10,7 +10,7 @@ struct wf_jsonrpc_request
};
bool
wf_jsonrpc_is_request(
wf_impl_jsonrpc_is_request(
json_t * message)
{
json_t * id = json_object_get(message, "id");
@ -23,7 +23,7 @@ wf_jsonrpc_is_request(
struct wf_jsonrpc_request *
wf_jsonrpc_request_create(
wf_impl_jsonrpc_request_create(
int id,
wf_jsonrpc_send_fn * send,
void * user_data)
@ -37,14 +37,14 @@ wf_jsonrpc_request_create(
}
void
wf_jsonrpc_request_dispose(
wf_impl_jsonrpc_request_dispose(
struct wf_jsonrpc_request * request)
{
free(request);
}
void *
wf_jsonrpc_request_get_userdata(
wf_impl_jsonrpc_request_get_userdata(
struct wf_jsonrpc_request * request)
{
return request->user_data;
@ -52,7 +52,7 @@ wf_jsonrpc_request_get_userdata(
void
wf_jsonrpc_respond(
wf_impl_jsonrpc_respond(
struct wf_jsonrpc_request * request,
json_t * result)
{
@ -62,20 +62,19 @@ wf_jsonrpc_respond(
request->send(response, request->user_data);
json_decref(response);
wf_jsonrpc_request_dispose(request);
wf_impl_jsonrpc_request_dispose(request);
}
void wf_jsonrpc_respond_error(
void wf_impl_jsonrpc_respond_error(
struct wf_jsonrpc_request * request,
int code,
char const * message)
{
json_t * response = json_object();
json_object_set_new(response, "error", wf_jsonrpc_error(code, message));
json_object_set_new(response, "error", wf_impl_jsonrpc_error(code, message));
json_object_set_new(response, "id", json_integer(request->id));
request->send(response, request->user_data);
json_decref(response);
wf_jsonrpc_request_dispose(request);
wf_impl_jsonrpc_request_dispose(request);
}

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_REQUEST_H
#define WF_JSONRPC_REQUEST_H
#ifndef WF_IMPL_JSONRPC_REQUEST_H
#define WF_IMPL_JSONRPC_REQUEST_H
#ifndef __cplusplus
#include <stdarg.h>
@ -12,7 +12,7 @@ using std::size_t;
#endif
#include <jansson.h>
#include "webfuse/core/jsonrpc/send_fn.h"
#include "webfuse/impl/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
@ -21,26 +21,26 @@ extern "C"
struct wf_jsonrpc_request;
extern bool wf_jsonrpc_is_request(
extern bool wf_impl_jsonrpc_is_request(
json_t * message);
extern struct wf_jsonrpc_request *
wf_jsonrpc_request_create(
wf_impl_jsonrpc_request_create(
int id,
wf_jsonrpc_send_fn * send,
void * user_data);
extern void wf_jsonrpc_request_dispose(
extern void wf_impl_jsonrpc_request_dispose(
struct wf_jsonrpc_request * request);
extern void * wf_jsonrpc_request_get_userdata(
extern void * wf_impl_jsonrpc_request_get_userdata(
struct wf_jsonrpc_request * request);
extern void wf_jsonrpc_respond(
extern void wf_impl_jsonrpc_respond(
struct wf_jsonrpc_request * request,
json_t * result);
extern void wf_jsonrpc_respond_error(
extern void wf_impl_jsonrpc_respond_error(
struct wf_jsonrpc_request * request,
int code,
char const * message);

View File

@ -1,9 +1,9 @@
#include "webfuse/core/jsonrpc/response_intern.h"
#include "webfuse/core/jsonrpc/error.h"
#include "webfuse/impl/jsonrpc/response_intern.h"
#include "webfuse/impl/jsonrpc/error.h"
#include "webfuse/status.h"
bool
wf_jsonrpc_is_response(
wf_impl_jsonrpc_is_response(
json_t * message)
{
json_t * id = json_object_get(message, "id");
@ -16,7 +16,7 @@ wf_jsonrpc_is_response(
void
wf_jsonrpc_response_init(
wf_impl_jsonrpc_response_init(
struct wf_jsonrpc_response * result,
json_t * response)
{
@ -27,7 +27,7 @@ wf_jsonrpc_response_init(
json_t * id_holder = json_object_get(response, "id");
if (!json_is_integer(id_holder))
{
result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id");
result->error = wf_impl_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id");
return;
}
@ -47,13 +47,13 @@ wf_jsonrpc_response_init(
}
else
{
result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: invalid error object");
result->error = wf_impl_jsonrpc_error(WF_BAD_FORMAT, "invalid format: invalid error object");
}
}
}
void
wf_jsonrpc_response_cleanup(
wf_impl_jsonrpc_response_cleanup(
struct wf_jsonrpc_response * response)
{
if (NULL != response->result)

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_RESPONSE_H
#define WF_JSONRPC_RESPONSE_H
#ifndef WF_IMPL_JSONRPC_RESPONSE_H
#define WF_IMPL_JSONRPC_RESPONSE_H
#ifndef __cplusplus
#include <stdbool.h>
@ -12,7 +12,7 @@ extern "C"
{
#endif
extern bool wf_jsonrpc_is_response(
extern bool wf_impl_jsonrpc_is_response(
json_t * message);
#ifdef __cplusplus

View File

@ -1,7 +1,7 @@
#ifndef WF_JSONRPC_RESPONSE_INTERN_H
#define WF_JSONRPC_RESPONSE_INTERN_H
#ifndef WF_IMPL_JSONRPC_RESPONSE_INTERN_H
#define WF_IMPL_JSONRPC_RESPONSE_INTERN_H
#include "webfuse/core/jsonrpc/response.h"
#include "webfuse/impl/jsonrpc/response.h"
#ifndef __cplusplus
#include <stddef.h>
@ -21,11 +21,11 @@ struct wf_jsonrpc_response
int id;
};
extern void wf_jsonrpc_response_init(
extern void wf_impl_jsonrpc_response_init(
struct wf_jsonrpc_response * response,
json_t * message);
extern void wf_jsonrpc_response_cleanup(
extern void wf_impl_jsonrpc_response_cleanup(
struct wf_jsonrpc_response * response);
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_SEND_FN_H
#define WF_JSONRPC_SEND_FN_H
#ifndef WF_IMPL_JSONRPC_SEND_FN_H
#define WF_IMPL_JSONRPC_SEND_FN_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,8 +1,8 @@
#include "webfuse/core/jsonrpc/server.h"
#include "webfuse/core/jsonrpc/method.h"
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/server.h"
#include "webfuse/impl/jsonrpc/method.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/status.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/util/util.h"
#include <stdlib.h>
#include <string.h>
@ -13,79 +13,79 @@ struct wf_jsonrpc_server
};
static void
wf_jsonrpc_server_init(
wf_impl_jsonrpc_server_init(
struct wf_jsonrpc_server * server);
static void
wf_jsonrpc_server_cleanup(
wf_impl_jsonrpc_server_cleanup(
struct wf_jsonrpc_server * server);
struct wf_jsonrpc_server *
wf_jsonrpc_server_create(void)
wf_impl_jsonrpc_server_create(void)
{
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
wf_jsonrpc_server_init(server);
wf_impl_jsonrpc_server_init(server);
return server;
}
void
wf_jsonrpc_server_dispose(
wf_impl_jsonrpc_server_dispose(
struct wf_jsonrpc_server * server)
{
wf_jsonrpc_server_cleanup(server);
wf_impl_jsonrpc_server_cleanup(server);
free(server);
}
static void wf_jsonrpc_server_init(
static void wf_impl_jsonrpc_server_init(
struct wf_jsonrpc_server * server)
{
server->methods = NULL;
}
static void wf_jsonrpc_server_cleanup(
static void wf_impl_jsonrpc_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_method_dispose(current);
wf_impl_jsonrpc_method_dispose(current);
current = next;
}
server->methods = NULL;
}
void wf_jsonrpc_server_add(
void wf_impl_jsonrpc_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_method_create(method_name, invoke, user_data);
struct wf_jsonrpc_method * method = wf_impl_jsonrpc_method_create(method_name, invoke, user_data);
method->next = server->methods;
server->methods = method;
}
static void wf_jsonrpc_server_invalid_method_invoke(
static void wf_impl_jsonrpc_server_invalid_method_invoke(
struct wf_jsonrpc_request * request,
char const * WF_UNUSED_PARAM(method_name),
json_t * WF_UNUSED_PARAM(params),
void * WF_UNUSED_PARAM(user_data))
{
wf_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented");
wf_impl_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented");
}
static struct wf_jsonrpc_method const wf_jsonrpc_server_invalid_method =
static struct wf_jsonrpc_method const wf_impl_jsonrpc_server_invalid_method =
{
.next = NULL,
.name = "<invalid>",
.invoke = &wf_jsonrpc_server_invalid_method_invoke,
.invoke = &wf_impl_jsonrpc_server_invalid_method_invoke,
.user_data = NULL
};
static struct wf_jsonrpc_method const *
wf_jsonrpc_server_get_method(
wf_impl_jsonrpc_server_get_method(
struct wf_jsonrpc_server * server,
char const * method_name)
{
@ -100,10 +100,10 @@ wf_jsonrpc_server_get_method(
current = current->next;
}
return &wf_jsonrpc_server_invalid_method;
return &wf_impl_jsonrpc_server_invalid_method;
}
void wf_jsonrpc_server_process(
void wf_impl_jsonrpc_server_process(
struct wf_jsonrpc_server * server,
json_t * request_data,
wf_jsonrpc_send_fn * send,
@ -119,8 +119,8 @@ void wf_jsonrpc_server_process(
{
char const * method_name = json_string_value(method_holder);
int id = json_integer_value(id_holder);
struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(id, send, user_data);
struct wf_jsonrpc_method const * method = wf_jsonrpc_server_get_method(server, method_name);
struct wf_jsonrpc_request * request = wf_impl_jsonrpc_request_create(id, send, user_data);
struct wf_jsonrpc_method const * method = wf_impl_jsonrpc_server_get_method(server, method_name);
method->invoke(request, method_name, params, method->user_data);
}

View File

@ -1,5 +1,5 @@
#ifndef WF_JSONRPC_SERVER_H
#define WF_JSONRPC_SERVER_H
#ifndef WF_IMPL_JSONRPC_SERVER_H
#define WF_IMPL_JSONRPC_SERVER_H
#ifndef __cplusplus
#include <stdarg.h>
@ -9,8 +9,8 @@
#endif
#include <jansson.h>
#include "webfuse/core/jsonrpc/method_invoke_fn.h"
#include "webfuse/core/jsonrpc/send_fn.h"
#include "webfuse/impl/jsonrpc/method_invoke_fn.h"
#include "webfuse/impl/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
@ -20,19 +20,19 @@ extern "C"
struct wf_jsonrpc_server;
extern struct wf_jsonrpc_server *
wf_jsonrpc_server_create(void);
wf_impl_jsonrpc_server_create(void);
extern void
wf_jsonrpc_server_dispose(
wf_impl_jsonrpc_server_dispose(
struct wf_jsonrpc_server * server);
extern void wf_jsonrpc_server_add(
extern void wf_impl_jsonrpc_server_add(
struct wf_jsonrpc_server * server,
char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke,
void * user_data);
extern void wf_jsonrpc_server_process(
extern void wf_impl_jsonrpc_server_process(
struct wf_jsonrpc_server * server,
json_t * request,
wf_jsonrpc_send_fn * send,

View File

@ -1,9 +1,9 @@
#include "webfuse/core/message.h"
#include "webfuse/impl/message.h"
#include <stdlib.h>
#include <libwebsockets.h>
extern struct wf_message * wf_message_create(json_t const * value)
extern struct wf_message * wf_impl_message_create(json_t const * value)
{
struct wf_message * message = NULL;
size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT);
@ -21,7 +21,7 @@ extern struct wf_message * wf_message_create(json_t const * value)
return message;
}
void wf_message_dispose(
void wf_impl_message_dispose(
struct wf_message * message)
{
free(message);

View File

@ -1,5 +1,5 @@
#ifndef WF_MESSAGE_H
#define WF_MESSAGE_H
#ifndef WF_IMPL_MESSAGE_H
#define WF_IMPL_MESSAGE_H
#ifndef __cplusplus
#include <stddef.h>
@ -9,7 +9,7 @@ using std::size_t;
#endif
#include <jansson.h>
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
struct wf_message
{
@ -23,10 +23,10 @@ extern "C"
{
#endif
extern struct wf_message * wf_message_create(
extern struct wf_message * wf_impl_message_create(
json_t const * value);
extern void wf_message_dispose(
extern void wf_impl_message_dispose(
struct wf_message * message);
#ifdef __cplusplus

View File

@ -0,0 +1,17 @@
#include "webfuse/impl/message_queue.h"
#include "webfuse/impl/message.h"
#include "webfuse/impl/util/container_of.h"
void wf_impl_message_queue_cleanup(
struct wf_slist * queue)
{
struct wf_slist_item * item = wf_impl_slist_first(queue);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
struct wf_message * message = wf_container_of(item, struct wf_message, item);
wf_impl_message_dispose(message);
item = next;
}
wf_impl_slist_init(queue);
}

View File

@ -1,5 +1,5 @@
#ifndef WF_MESSAGE_QUEUE_H
#define WF_MESSAGE_QUEUE_H
#ifndef WF_IMPL_MESSAGE_QUEUE_H
#define WF_IMPL_MESSAGE_QUEUE_H
#ifdef __cplusplus
extern "C"
@ -8,7 +8,7 @@ extern "C"
struct wf_slist;
extern void wf_message_queue_cleanup(
extern void wf_impl_message_queue_cleanup(
struct wf_slist * queue);

View File

@ -5,8 +5,7 @@
#include <errno.h>
#include <jansson.h>
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/jsonrpc/proxy.h"
void wf_impl_operation_close(
fuse_req_t request,
@ -19,7 +18,7 @@ void wf_impl_operation_close(
if (NULL != rpc)
{
int handle = (int) (file_info->fh & INT_MAX);
wf_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
wf_impl_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
}
fuse_reply_err(request, 0);

View File

@ -8,9 +8,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/json_util.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/util/json_util.h"
#include "webfuse/impl/util/util.h"
void wf_impl_operation_getattr_finished(
void * user_data,
@ -85,7 +85,7 @@ void wf_impl_operation_getattr (
getattr_context->gid = context->gid;
getattr_context->timeout = user_data->timeout;
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
}
else
{

View File

@ -11,9 +11,9 @@
#include <stdlib.h>
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/json_util.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/util/json_util.h"
#include "webfuse/impl/util/util.h"
void wf_impl_operation_lookup_finished(
void * user_data,
@ -95,7 +95,7 @@ void wf_impl_operation_lookup (
lookup_context->gid = context->gid;
lookup_context->timeout = user_data->timeout;
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
}
else
{

View File

@ -1,10 +1,10 @@
#include "webfuse/impl/operation/open.h"
#include "webfuse/impl/operation/context.h"
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/status.h"
#include "webfuse/core/json_util.h"
#include "webfuse/impl/util/json_util.h"
#include <string.h>
#include <errno.h>
@ -53,7 +53,7 @@ void wf_impl_operation_open(
if (NULL != rpc)
{
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
}
else
{

View File

@ -6,9 +6,9 @@
#include <limits.h>
#include <jansson.h>
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/base64.h"
#include "webfuse/core/json_util.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/util/base64.h"
#include "webfuse/impl/util/json_util.h"
#define WF_MAX_READ_LENGTH 4096
@ -37,7 +37,7 @@ char * wf_impl_fill_buffer(
}
else if (0 == strcmp("base64", format))
{
size_t result = wf_base64_decode(data, data_size, (uint8_t *) buffer, count);
size_t result = wf_impl_base64_decode(data, data_size, (uint8_t *) buffer, count);
if (result != count)
{
*status = WF_BAD;
@ -118,7 +118,7 @@ void wf_impl_operation_read(
{
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
int handle = (file_info->fh & INT_MAX);
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
}
else
{

View File

@ -9,9 +9,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/util.h"
#include "webfuse/core/json_util.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/impl/util/json_util.h"
#define WF_DIRBUFFER_INITIAL_SIZE 1024
@ -151,7 +151,7 @@ void wf_impl_operation_readdir (
readdir_context->size = size;
readdir_context->offset = offset;
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
}
else
{

View File

@ -10,7 +10,7 @@
#include "webfuse/impl/server_config.h"
#include "webfuse/impl/server_protocol.h"
#include "webfuse/core/lws_log.h"
#include "webfuse/impl/util/lws_log.h"
#define WF_SERVER_PROTOCOL_COUNT 3
@ -34,7 +34,7 @@ static bool wf_impl_server_tls_enabled(
static struct lws_context * wf_impl_server_context_create(
struct wf_server * server)
{
wf_lwslog_disable();
wf_impl_lwslog_disable();
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
server->ws_protocols[0].name = "http";

View File

@ -4,16 +4,16 @@
#include <ctype.h>
#include <libwebsockets.h>
#include "webfuse/core/message.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/message.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/protocol_names.h"
#include "webfuse/impl/credentials.h"
#include "webfuse/core/status_intern.h"
#include "webfuse/impl/status.h"
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/core/timer/manager.h"
#include "webfuse/core/timer/timer.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/timer/manager.h"
#include "webfuse/impl/timer/timer.h"
static int wf_impl_server_protocol_callback(
struct lws * wsi,
@ -27,7 +27,7 @@ static int wf_impl_server_protocol_callback(
if (ws_protocol->callback != &wf_impl_server_protocol_callback) { return 0; }
struct wf_server_protocol * protocol = ws_protocol->user;
wf_timer_manager_check(protocol->timer_manager);
wf_impl_timer_manager_check(protocol->timer_manager);
struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi);
switch (reason)
@ -127,7 +127,7 @@ static void wf_impl_server_protocol_authenticate(
struct wf_credentials creds;
wf_impl_credentials_init(&creds, type, creds_holder);
struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request);
struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request);
result = wf_impl_session_authenticate(session, &creds);
wf_impl_credentials_cleanup(&creds);
@ -137,11 +137,11 @@ static void wf_impl_server_protocol_authenticate(
if (result)
{
json_t * result = json_object();
wf_jsonrpc_respond(request, result);
wf_impl_jsonrpc_respond(request, result);
}
else
{
wf_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED));
wf_impl_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_impl_status_tostring(WF_BAD_ACCESS_DENIED));
}
}
@ -166,7 +166,7 @@ static void wf_impl_server_protocol_add_filesystem(
json_t * params,
void * WF_UNUSED_PARAM(user_data))
{
struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request);
struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request);
wf_status status = (session->is_authenticated) ? WF_GOOD : WF_BAD_ACCESS_DENIED;
char const * name = NULL;
@ -200,11 +200,11 @@ static void wf_impl_server_protocol_add_filesystem(
{
json_t * result = json_object();
json_object_set_new(result, "id", json_string(name));
wf_jsonrpc_respond(request, result);
wf_impl_jsonrpc_respond(request, result);
}
else
{
wf_jsonrpc_respond_error(request, status, wf_status_tostring(status));
wf_impl_jsonrpc_respond_error(request, status, wf_impl_status_tostring(status));
}
@ -218,13 +218,13 @@ void wf_impl_server_protocol_init(
wf_impl_mountpoint_factory_clone(mountpoint_factory, &protocol->mountpoint_factory);
protocol->timer_manager = wf_timer_manager_create();
protocol->timer_manager = wf_impl_timer_manager_create();
wf_impl_session_manager_init(&protocol->session_manager);
wf_impl_authenticators_init(&protocol->authenticators);
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);
protocol->server = wf_impl_jsonrpc_server_create();
wf_impl_jsonrpc_server_add(protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol);
wf_impl_jsonrpc_server_add(protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol);
}
void wf_impl_server_protocol_cleanup(
@ -232,8 +232,8 @@ void wf_impl_server_protocol_cleanup(
{
protocol->is_operational = false;
wf_jsonrpc_server_dispose(protocol->server);
wf_timer_manager_dispose(protocol->timer_manager);
wf_impl_jsonrpc_server_dispose(protocol->server);
wf_impl_timer_manager_dispose(protocol->timer_manager);
wf_impl_authenticators_cleanup(&protocol->authenticators);
wf_impl_session_manager_cleanup(&protocol->session_manager);
wf_impl_mountpoint_factory_cleanup(&protocol->mountpoint_factory);

View File

@ -4,8 +4,8 @@
#include "webfuse/impl/authenticators.h"
#include "webfuse/impl/mountpoint_factory.h"
#include "webfuse/impl/session_manager.h"
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/jsonrpc/server.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/jsonrpc/server.h"
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,16 +1,16 @@
#include "webfuse/impl/session.h"
#include "webfuse/impl/authenticators.h"
#include "webfuse/core/message_queue.h"
#include "webfuse/core/message.h"
#include "webfuse/impl/message_queue.h"
#include "webfuse/impl/message.h"
#include "webfuse/impl/mountpoint_factory.h"
#include "webfuse/impl/mountpoint.h"
#include "webfuse/core/container_of.h"
#include "webfuse/core/util.h"
#include "webfuse/impl/util/container_of.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/core/jsonrpc/response.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/response.h"
#include <libwebsockets.h>
#include <stddef.h>
@ -23,20 +23,20 @@ static bool wf_impl_session_send(
void * user_data)
{
struct wf_impl_session * session = user_data;
struct wf_message * message = wf_message_create(request);
struct wf_message * message = wf_impl_message_create(request);
bool result = (session->is_authenticated || wf_jsonrpc_is_response(request)) && (NULL != session->wsi);
bool result = (session->is_authenticated || wf_impl_jsonrpc_is_response(request)) && (NULL != session->wsi);
if (result)
{
wf_slist_append(&session->messages, &message->item);
wf_impl_slist_append(&session->messages, &message->item);
lws_callback_on_writable(session->wsi);
result = true;
}
else
{
wf_message_dispose(message);
wf_impl_message_dispose(message);
}
return result;
@ -51,15 +51,15 @@ struct wf_impl_session * wf_impl_session_create(
{
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
wf_slist_init(&session->filesystems);
wf_impl_slist_init(&session->filesystems);
session->wsi = wsi;
session->is_authenticated = false;
session->authenticators = authenticators;
session->server = server;
session->mountpoint_factory = mountpoint_factory;
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
wf_slist_init(&session->messages);
session->rpc = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
wf_impl_slist_init(&session->messages);
return session;
}
@ -67,7 +67,7 @@ struct wf_impl_session * wf_impl_session_create(
static void wf_impl_session_dispose_filesystems(
struct wf_slist * filesystems)
{
struct wf_slist_item * item = wf_slist_first(filesystems);
struct wf_slist_item * item = wf_impl_slist_first(filesystems);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
@ -81,8 +81,8 @@ static void wf_impl_session_dispose_filesystems(
void wf_impl_session_dispose(
struct wf_impl_session * session)
{
wf_jsonrpc_proxy_dispose(session->rpc);
wf_message_queue_cleanup(&session->messages);
wf_impl_jsonrpc_proxy_dispose(session->rpc);
wf_impl_message_queue_cleanup(&session->messages);
wf_impl_session_dispose_filesystems(&session->filesystems);
free(session);
@ -112,7 +112,7 @@ bool wf_impl_session_add_filesystem(
result = (NULL != filesystem);
if (result)
{
wf_slist_append(&session->filesystems, &filesystem->item);
wf_impl_slist_append(&session->filesystems, &filesystem->item);
}
}
@ -132,14 +132,14 @@ bool wf_impl_session_add_filesystem(
void wf_impl_session_onwritable(
struct wf_impl_session * session)
{
if (!wf_slist_empty(&session->messages))
if (!wf_impl_slist_empty(&session->messages))
{
struct wf_slist_item * item = wf_slist_remove_first(&session->messages);
struct wf_slist_item * item = wf_impl_slist_remove_first(&session->messages);
struct wf_message * message = wf_container_of(item, struct wf_message, item);
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
wf_message_dispose(message);
wf_impl_message_dispose(message);
if (!wf_slist_empty(&session->messages))
if (!wf_impl_slist_empty(&session->messages))
{
lws_callback_on_writable(session->wsi);
}
@ -155,13 +155,13 @@ void wf_impl_session_receive(
json_t * message = json_loadb(data, length, 0, NULL);
if (NULL != message)
{
if (wf_jsonrpc_is_response(message))
if (wf_impl_jsonrpc_is_response(message))
{
wf_jsonrpc_proxy_onresult(session->rpc, message);
wf_impl_jsonrpc_proxy_onresult(session->rpc, message);
}
else if (wf_jsonrpc_is_request(message))
else if (wf_impl_jsonrpc_is_request(message))
{
wf_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
wf_impl_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
}
json_decref(message);
@ -175,7 +175,7 @@ static struct wf_impl_filesystem * wf_impl_session_get_filesystem(
{
struct wf_impl_filesystem * result = NULL;
struct wf_slist_item * item = wf_slist_first(&session->filesystems);
struct wf_slist_item * item = wf_impl_slist_first(&session->filesystems);
while (NULL != item)
{
struct wf_slist_item * next = item->next;

View File

@ -9,12 +9,12 @@
using std::size_t;
#endif
#include "webfuse/core/message_queue.h"
#include "webfuse/impl/message_queue.h"
#include "webfuse/impl/filesystem.h"
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/jsonrpc/server.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/jsonrpc/server.h"
#ifdef __cplusplus
extern "C"

View File

@ -1,18 +1,18 @@
#include "webfuse/impl/session_manager.h"
#include "webfuse/core/util.h"
#include "webfuse/core/container_of.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/impl/util/container_of.h"
#include <stddef.h>
void wf_impl_session_manager_init(
struct wf_impl_session_manager * manager)
{
wf_slist_init(&manager->sessions);
wf_impl_slist_init(&manager->sessions);
}
void wf_impl_session_manager_cleanup(
struct wf_impl_session_manager * manager)
{
struct wf_slist_item * item = wf_slist_first(&manager->sessions);
struct wf_slist_item * item = wf_impl_slist_first(&manager->sessions);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
@ -33,7 +33,7 @@ struct wf_impl_session * wf_impl_session_manager_add(
{
struct wf_impl_session * session = wf_impl_session_create(
wsi, authenticators, timer_manager, server, mountpoint_factory);
wf_slist_append(&manager->sessions, &session->item);
wf_impl_slist_append(&manager->sessions, &session->item);
return session;
}
@ -44,7 +44,7 @@ struct wf_impl_session * wf_impl_session_manager_get(
{
struct wf_impl_session * session = NULL;
struct wf_slist_item * item = wf_slist_first(&manager->sessions);
struct wf_slist_item * item = wf_impl_slist_first(&manager->sessions);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
@ -72,7 +72,7 @@ void wf_impl_session_manager_remove(
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
if (wsi == session->wsi)
{
wf_slist_remove_after(&manager->sessions, prev);
wf_impl_slist_remove_after(&manager->sessions, prev);
wf_impl_session_dispose(session);
break;
}

View File

@ -7,7 +7,7 @@
#include "webfuse/impl/session.h"
#include "webfuse/impl/fuse_wrapper.h"
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
#ifdef __cplusplus
extern "C"

View File

@ -1,8 +1,8 @@
#include "webfuse/core/status_intern.h"
#include "webfuse/impl/status.h"
#include <errno.h>
int wf_status_to_rc(wf_status status)
int wf_impl_status_to_rc(wf_status status)
{
switch(status)
{
@ -17,7 +17,7 @@
}
}
char const * wf_status_tostring(wf_status status)
char const * wf_impl_status_tostring(wf_status status)
{
switch(status)
{

19
lib/webfuse/impl/status.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef WF_IMPL_STATUS_H
#define WF_IMPL_STATUS_H
#include "webfuse/status.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int wf_impl_status_to_rc(wf_status status);
extern char const * wf_impl_status_tostring(wf_status status);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,6 @@
#include "webfuse/core/timer/manager_intern.h"
#include "webfuse/core/timer/timer_intern.h"
#include "webfuse/core/timer/timepoint.h"
#include "webfuse/impl/timer/manager_intern.h"
#include "webfuse/impl/timer/timer_intern.h"
#include "webfuse/impl/timer/timepoint.h"
#include <stddef.h>
#include <stdlib.h>
@ -11,7 +11,7 @@ struct wf_timer_manager
};
struct wf_timer_manager *
wf_timer_manager_create(void)
wf_impl_timer_manager_create(void)
{
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
manager->timers = NULL;
@ -20,7 +20,7 @@ wf_timer_manager_create(void)
}
void
wf_timer_manager_dispose(
wf_impl_timer_manager_dispose(
struct wf_timer_manager * manager)
{
struct wf_timer * timer = manager->timers;
@ -28,7 +28,7 @@ wf_timer_manager_dispose(
{
struct wf_timer * next = timer->next;
wf_timer_trigger(timer);
wf_impl_timer_trigger(timer);
timer = next;
}
@ -36,7 +36,7 @@ wf_timer_manager_dispose(
}
void wf_timer_manager_check(
void wf_impl_timer_manager_check(
struct wf_timer_manager * manager)
{
struct wf_timer * timer = manager->timers;
@ -44,17 +44,17 @@ void wf_timer_manager_check(
{
struct wf_timer * next = timer->next;
if (wf_timer_is_timeout(timer))
if (wf_impl_timer_is_timeout(timer))
{
wf_timer_manager_removetimer(manager, timer);
wf_timer_trigger(timer);
wf_impl_timer_manager_removetimer(manager, timer);
wf_impl_timer_trigger(timer);
}
timer = next;
}
}
void wf_timer_manager_addtimer(
void wf_impl_timer_manager_addtimer(
struct wf_timer_manager * manager,
struct wf_timer * timer)
{
@ -68,7 +68,7 @@ void wf_timer_manager_addtimer(
manager->timers = timer;
}
void wf_timer_manager_removetimer(
void wf_impl_timer_manager_removetimer(
struct wf_timer_manager * manager,
struct wf_timer * timer)
{

View File

@ -1,5 +1,5 @@
#ifndef WF_TIMER_MANAGER_H
#define WF_TIMER_MANAGER_H
#ifndef WF_IMPL_TIMER_MANAGER_H
#define WF_IMPL_TIMER_MANAGER_H
#ifdef __cplusplus
extern "C"
@ -9,14 +9,14 @@ extern "C"
struct wf_timer_manager;
extern struct wf_timer_manager *
wf_timer_manager_create(void);
wf_impl_timer_manager_create(void);
extern void
wf_timer_manager_dispose(
wf_impl_timer_manager_dispose(
struct wf_timer_manager * manager);
extern void
wf_timer_manager_check(
wf_impl_timer_manager_check(
struct wf_timer_manager * manager);
#ifdef __cplusplus

View File

@ -1,7 +1,7 @@
#ifndef WF_TIMER_MANAGER_INTERN_H
#define WF_TIMER_MANAGER_INTERN_H
#ifndef WF_IMPL_TIMER_MANAGER_INTERN_H
#define WF_IMPL_TIMER_MANAGER_INTERN_H
#include "webfuse/core/timer/manager.h"
#include "webfuse/impl/timer/manager.h"
#ifdef __cplusplus
extern "C"
@ -10,11 +10,11 @@ extern "C"
struct wf_timer;
extern void wf_timer_manager_addtimer(
extern void wf_impl_timer_manager_addtimer(
struct wf_timer_manager * manager,
struct wf_timer * timer);
extern void wf_timer_manager_removetimer(
extern void wf_impl_timer_manager_removetimer(
struct wf_timer_manager * manager,
struct wf_timer * timer);

View File

@ -1,5 +1,5 @@
#ifndef WF_TIMER_ON_TIMER_FN_H
#define WF_TIMER_ON_TIMER_FN_H
#ifndef WF_IMPL_TIMER_ON_TIMER_FN_H
#define WF_IMPL_TIMER_ON_TIMER_FN_H
#ifdef __cplusplus
extern "C"

View File

@ -0,0 +1,31 @@
#include "webfuse/impl/timer/timepoint.h"
#include <time.h>
#define WF_IMPL_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000)
#define WF_IMPL_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000)
wf_timer_timepoint wf_impl_timer_timepoint_now(void)
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
wf_timer_timepoint const now = (tp.tv_sec * WF_IMPL_TIMER_MSEC_PER_SEC) + (tp.tv_nsec / WF_IMPL_TIMER_NSEC_PER_MSEC);
return now;
}
wf_timer_timepoint wf_impl_timer_timepoint_in_msec(wf_timer_timediff value)
{
wf_timer_timepoint const now = wf_impl_timer_timepoint_now();
wf_timer_timepoint result = now + ((wf_timer_timepoint) value);
return result;
}
bool wf_impl_timer_timepoint_is_elapsed(wf_timer_timepoint tp)
{
wf_timer_timepoint const now = wf_impl_timer_timepoint_now();
wf_timer_timediff const diff = (wf_timer_timediff) (tp - now);
return (0 > diff);
}

View File

@ -1,5 +1,5 @@
#ifndef WF_TIMER_TIMEPOINT_H
#define WF_TIMER_TIMEPOINT_H
#ifndef WF_IMPL_TIMER_TIMEPOINT_H
#define WF_IMPL_TIMER_TIMEPOINT_H
#ifndef __cplusplus
#include <stdbool.h>
@ -16,12 +16,12 @@ extern "C"
typedef uint64_t wf_timer_timepoint;
typedef int64_t wf_timer_timediff;
extern wf_timer_timepoint wf_timer_timepoint_now(void);
extern wf_timer_timepoint wf_impl_timer_timepoint_now(void);
extern wf_timer_timepoint wf_timer_timepoint_in_msec(
extern wf_timer_timepoint wf_impl_timer_timepoint_in_msec(
wf_timer_timediff value);
extern bool wf_timer_timepoint_is_elapsed(
extern bool wf_impl_timer_timepoint_is_elapsed(
wf_timer_timepoint timepoint);
#ifdef __cplusplus

View File

@ -1,13 +1,13 @@
#include "webfuse/core/timer/timer_intern.h"
#include "webfuse/core/timer/manager_intern.h"
#include "webfuse/core/timer/timepoint.h"
#include "webfuse/impl/timer/timer_intern.h"
#include "webfuse/impl/timer/manager_intern.h"
#include "webfuse/impl/timer/timepoint.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
struct wf_timer *
wf_timer_create(
wf_impl_timer_create(
struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data)
@ -24,37 +24,37 @@ wf_timer_create(
}
void
wf_timer_dispose(
wf_impl_timer_dispose(
struct wf_timer * timer)
{
free(timer);
}
void wf_timer_start(
void wf_impl_timer_start(
struct wf_timer * timer,
int timeout_ms)
{
timer->timeout = wf_timer_timepoint_in_msec(timeout_ms);
timer->timeout = wf_impl_timer_timepoint_in_msec(timeout_ms);
wf_timer_manager_addtimer(timer->manager, timer);
wf_impl_timer_manager_addtimer(timer->manager, timer);
}
void wf_timer_cancel(
void wf_impl_timer_cancel(
struct wf_timer * timer)
{
wf_timer_manager_removetimer(timer->manager, timer);
wf_impl_timer_manager_removetimer(timer->manager, timer);
timer->timeout = 0;
}
bool wf_timer_is_timeout(
bool wf_impl_timer_is_timeout(
struct wf_timer * timer)
{
return wf_timer_timepoint_is_elapsed(timer->timeout);
return wf_impl_timer_timepoint_is_elapsed(timer->timeout);
}
void wf_timer_trigger(
void wf_impl_timer_trigger(
struct wf_timer * timer)
{
if (0 != timer->on_timer)

View File

@ -1,7 +1,7 @@
#ifndef WF_TIMER_TIMER_H
#define WF_TIMER_TIMER_H
#ifndef WF_IMPL_TIMER_TIMER_H
#define WF_IMPL_TIMER_TIMER_H
#include "webfuse/core/timer/on_timer_fn.h"
#include "webfuse/impl/timer/on_timer_fn.h"
#ifdef __cplusplus
extern "C"
@ -12,22 +12,22 @@ struct wf_timer;
struct wf_timer_manager;
extern struct wf_timer *
wf_timer_create(
wf_impl_timer_create(
struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data);
extern void
wf_timer_dispose(
wf_impl_timer_dispose(
struct wf_timer * timer);
extern void
wf_timer_start(
wf_impl_timer_start(
struct wf_timer * timer,
int timeout_ms);
extern void
wf_timer_cancel(
wf_impl_timer_cancel(
struct wf_timer * timer);
#ifdef __cplusplus

View File

@ -1,9 +1,9 @@
#ifndef WF_TIMER_TIMER_H
#define WF_TIMER_TIMER_H
#ifndef WF_IMPL_TIMER_TIMER_H
#define WF_IMPL_TIMER_TIMER_H
#include "webfuse/core/timer/timer.h"
#include "webfuse/core/timer/on_timer_fn.h"
#include "webfuse/core/timer/timepoint.h"
#include "webfuse/impl/timer/timer.h"
#include "webfuse/impl/timer/on_timer_fn.h"
#include "webfuse/impl/timer/timepoint.h"
#ifndef __cplusplus
#include <stdbool.h>
@ -24,10 +24,10 @@ struct wf_timer
struct wf_timer * prev;
};
extern bool wf_timer_is_timeout(
extern bool wf_impl_timer_is_timeout(
struct wf_timer * timer);
extern void wf_timer_trigger(
extern void wf_impl_timer_trigger(
struct wf_timer * timer);

View File

@ -1,6 +1,6 @@
#include "webfuse/core/base64.h"
#include "webfuse/impl/util/base64.h"
static const uint8_t wf_base64_decode_table[256] = {
static const uint8_t wf_impl_base64_decode_table[256] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 1
@ -22,12 +22,12 @@ static const uint8_t wf_base64_decode_table[256] = {
size_t wf_base64_encoded_size(size_t length)
size_t wf_impl_base64_encoded_size(size_t length)
{
return ((length + 2) / 3) * 4;
}
size_t wf_base64_encode(
size_t wf_impl_base64_encode(
uint8_t const * data,
size_t length,
char * buffer,
@ -36,7 +36,7 @@ size_t wf_base64_encode(
// 0 1 2 3 4 5 6
// 0123456789012345678901234567890123456789012345678901234567890123
static char const table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
size_t const length_needed = wf_base64_encoded_size(length);
size_t const length_needed = wf_impl_base64_encoded_size(length);
if (buffer_size < length_needed)
{
return 0;
@ -78,7 +78,7 @@ size_t wf_base64_encode(
return out_pos;
}
size_t wf_base64_decoded_size(char const * data, size_t length)
size_t wf_impl_base64_decoded_size(char const * data, size_t length)
{
size_t result = 0;
if ((length > 0) && ((length % 4) == 0))
@ -98,14 +98,14 @@ size_t wf_base64_decoded_size(char const * data, size_t length)
return result;
}
size_t wf_base64_decode(
size_t wf_impl_base64_decode(
char const * data,
size_t length,
uint8_t * buffer,
size_t buffer_size)
{
uint8_t const * table = wf_base64_decode_table;
size_t needed_size = wf_base64_decoded_size(data, length);
uint8_t const * table = wf_impl_base64_decode_table;
size_t needed_size = wf_impl_base64_decoded_size(data, length);
if ((0 == needed_size) || (buffer_size < needed_size))
{
return 0;
@ -146,9 +146,9 @@ size_t wf_base64_decode(
return out_pos;
}
extern bool wf_base64_isvalid(char const * data, size_t length)
extern bool wf_impl_base64_isvalid(char const * data, size_t length)
{
uint8_t const * table = wf_base64_decode_table;
uint8_t const * table = wf_impl_base64_decode_table;
if ((length == 0) || ((length % 4) != 0))
{

View File

@ -1,5 +1,5 @@
#ifndef WF_BASE64_H
#define WF_BASE64_H
#ifndef WF_IMPL_UTIL_BASE64_H
#define WF_IMPL_UTIL_BASE64_H
#ifndef __cplusplus
#include <inttypes.h>
@ -15,23 +15,23 @@ extern "C"
{
#endif
extern size_t wf_base64_encoded_size(size_t length);
extern size_t wf_impl_base64_encoded_size(size_t length);
extern size_t wf_base64_encode(
extern size_t wf_impl_base64_encode(
uint8_t const * data,
size_t length,
char * buffer,
size_t buffer_size);
extern size_t wf_base64_decoded_size(char const * data, size_t length);
extern size_t wf_impl_base64_decoded_size(char const * data, size_t length);
extern size_t wf_base64_decode(
extern size_t wf_impl_base64_decode(
char const * data,
size_t length,
uint8_t * buffer,
size_t buffer_size);
extern bool wf_base64_isvalid(char const * data, size_t length);
extern bool wf_impl_base64_isvalid(char const * data, size_t length);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
#ifndef WF_CONTAINER_OF_H
#define WF_CONTAINER_OF_H
#ifndef WF_IMPL_UTIL_CONTAINER_OF_H
#define WF_IMPL_UTIL_CONTAINER_OF_H
#ifndef __cplusplus
#include <stddef.h>

View File

@ -1,4 +1,4 @@
#include "webfuse/core/json_util.h"
#include "webfuse/impl/util/json_util.h"
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
{

View File

@ -1,5 +1,5 @@
#ifndef WF_JSON_UTIL_H
#define WF_JSON_UTIL_H
#ifndef WF_IMPL_UTIL_JSON_UTIL_H
#define WF_IMPL_UTIL_JSON_UTIL_H
#include <jansson.h>
#include "webfuse/status.h"

View File

@ -0,0 +1,18 @@
#include "webfuse/impl/util/lws_log.h"
#include <stdbool.h>
#include <libwebsockets.h>
#define WF_LWSLOG_DISABLE 0
static bool wf_impl_lwslog_is_diabled = false;
void wf_impl_lwslog_disable(void)
{
if (!wf_impl_lwslog_is_diabled)
{
lws_set_log_level(WF_LWSLOG_DISABLE, NULL);
wf_impl_lwslog_is_diabled = true;
}
}

View File

@ -0,0 +1,15 @@
#ifndef WF_IMPL_UTIL_LWS_LOG_H
#define WF_IMPL_UTIL_LWS_LOG_H
#ifdef __cplusplus
extern "C"
{
#endif
extern void wf_impl_lwslog_disable(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,26 +1,26 @@
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
#include <stddef.h>
void wf_slist_init(
void wf_impl_slist_init(
struct wf_slist * list)
{
list->head.next = NULL;
list->last = &list->head;
}
bool wf_slist_empty(
bool wf_impl_slist_empty(
struct wf_slist * list)
{
return (list->last == &list->head);
}
struct wf_slist_item * wf_slist_first(
struct wf_slist_item * wf_impl_slist_first(
struct wf_slist * list)
{
return list->head.next;
}
void wf_slist_append(
void wf_impl_slist_append(
struct wf_slist * list,
struct wf_slist_item * item)
{
@ -29,13 +29,13 @@ void wf_slist_append(
list->last = item;
}
struct wf_slist_item * wf_slist_remove_first(
struct wf_slist_item * wf_impl_slist_remove_first(
struct wf_slist * list)
{
return wf_slist_remove_after(list, &list->head);
return wf_impl_slist_remove_after(list, &list->head);
}
struct wf_slist_item * wf_slist_remove_after(
struct wf_slist_item * wf_impl_slist_remove_after(
struct wf_slist * list,
struct wf_slist_item * prev)
{

View File

@ -1,5 +1,5 @@
#ifndef WF_SLIST_H
#define WF_SLIST_H
#ifndef WF_IMPL_UTIL_SLIST_H
#define WF_IMPL_UTIL_SLIST_H
#ifndef __cplusplus
#include <stdbool.h>
@ -21,23 +21,23 @@ struct wf_slist
struct wf_slist_item * last;
};
extern void wf_slist_init(
extern void wf_impl_slist_init(
struct wf_slist * list);
extern bool wf_slist_empty(
extern bool wf_impl_slist_empty(
struct wf_slist * list);
extern struct wf_slist_item * wf_slist_first(
extern struct wf_slist_item * wf_impl_slist_first(
struct wf_slist * list);
extern void wf_slist_append(
extern void wf_impl_slist_append(
struct wf_slist * list,
struct wf_slist_item * item);
extern struct wf_slist_item * wf_slist_remove_first(
extern struct wf_slist_item * wf_impl_slist_remove_first(
struct wf_slist * list);
extern struct wf_slist_item * wf_slist_remove_after(
extern struct wf_slist_item * wf_impl_slist_remove_after(
struct wf_slist * list,
struct wf_slist_item * prev);

View File

@ -1,4 +1,4 @@
#include "webfuse/core/url.h"
#include "webfuse/impl/util/url.h"
#include <stdlib.h>
#include <string.h>
@ -11,7 +11,7 @@ struct wf_url_protocol
bool use_tls;
};
static bool wf_url_readprotocol(
static bool wf_impl_url_readprotocol(
struct wf_url * url,
char const * * data)
{
@ -38,7 +38,7 @@ static bool wf_url_readprotocol(
return found;
}
static bool wf_url_readhost(
static bool wf_impl_url_readhost(
struct wf_url * url,
char const * * data)
{
@ -55,7 +55,7 @@ static bool wf_url_readhost(
return result;
}
static bool wf_url_readport(
static bool wf_impl_url_readport(
struct wf_url * url,
char const * * data)
{
@ -81,7 +81,7 @@ static bool wf_url_readport(
return result;
}
static bool wf_url_readpath(
static bool wf_impl_url_readpath(
struct wf_url * url,
char const * * data)
{
@ -93,7 +93,7 @@ static bool wf_url_readpath(
}
bool wf_url_init(
bool wf_impl_url_init(
struct wf_url * url,
char const * value)
{
@ -101,21 +101,21 @@ bool wf_url_init(
char const * data = value;
bool const result =
wf_url_readprotocol(url, &data) &&
wf_url_readhost(url, &data) &&
wf_url_readport(url, &data) &&
wf_url_readpath(url, &data)
wf_impl_url_readprotocol(url, &data) &&
wf_impl_url_readhost(url, &data) &&
wf_impl_url_readport(url, &data) &&
wf_impl_url_readpath(url, &data)
;
if (!result)
{
wf_url_cleanup(url);
wf_impl_url_cleanup(url);
}
return result;
}
void wf_url_cleanup(
void wf_impl_url_cleanup(
struct wf_url * url)
{
free(url->host);

View File

@ -1,5 +1,5 @@
#ifndef WF_URL_H
#define WF_URL_H
#ifndef WF_IMPL_UTIL_URL_H
#define WF_IMPL_UTIL_URL_H
#ifndef __cplusplus
#include <stdbool.h>
@ -17,11 +17,11 @@ struct wf_url
bool use_tls;
};
extern bool wf_url_init(
extern bool wf_impl_url_init(
struct wf_url * url,
char const * value);
extern void wf_url_cleanup(
extern void wf_impl_url_cleanup(
struct wf_url * url);

View File

@ -1,5 +1,5 @@
#ifndef WF_UTIL_H
#define WF_UTIL_H
#ifndef WF_IMPL_UTIL_UTIL_H
#define WF_IMPL_UTIL_UTIL_H
#ifdef __GNUC__
#define WF_UNUSED_PARAM(param) param __attribute__((unused))

View File

@ -18,25 +18,25 @@ inc_dir = include_directories('include')
private_inc_dir = include_directories('include', 'lib')
webfuse_static = static_library('webfuse',
'lib/webfuse/core/slist.c',
'lib/webfuse/core/message.c',
'lib/webfuse/core/message_queue.c',
'lib/webfuse/core/status.c',
'lib/webfuse/core/base64.c',
'lib/webfuse/core/lws_log.c',
'lib/webfuse/core/json_util.c',
'lib/webfuse/core/url.c',
'lib/webfuse/core/timer/manager.c',
'lib/webfuse/core/timer/timepoint.c',
'lib/webfuse/core/timer/timer.c',
'lib/webfuse/core/jsonrpc/proxy.c',
'lib/webfuse/core/jsonrpc/proxy_variadic.c',
'lib/webfuse/core/jsonrpc/server.c',
'lib/webfuse/core/jsonrpc/method.c',
'lib/webfuse/core/jsonrpc/request.c',
'lib/webfuse/core/jsonrpc/response.c',
'lib/webfuse/core/jsonrpc/error.c',
'lib/webfuse/api.c',
'lib/webfuse/impl/util/slist.c',
'lib/webfuse/impl/util/base64.c',
'lib/webfuse/impl/util/lws_log.c',
'lib/webfuse/impl/util/json_util.c',
'lib/webfuse/impl/util/url.c',
'lib/webfuse/impl/timer/manager.c',
'lib/webfuse/impl/timer/timepoint.c',
'lib/webfuse/impl/timer/timer.c',
'lib/webfuse/impl/jsonrpc/proxy.c',
'lib/webfuse/impl/jsonrpc/proxy_variadic.c',
'lib/webfuse/impl/jsonrpc/server.c',
'lib/webfuse/impl/jsonrpc/method.c',
'lib/webfuse/impl/jsonrpc/request.c',
'lib/webfuse/impl/jsonrpc/response.c',
'lib/webfuse/impl/jsonrpc/error.c',
'lib/webfuse/impl/message.c',
'lib/webfuse/impl/message_queue.c',
'lib/webfuse/impl/status.c',
'lib/webfuse/impl/filesystem.c',
'lib/webfuse/impl/server.c',
'lib/webfuse/impl/server_config.c',
@ -162,16 +162,16 @@ alltests = executable('alltests',
'test/webfuse/tests/adapter/test_client.cc',
'test/webfuse/tests/adapter/test_client_tlsconfig.cc',
link_args: [
'-Wl,--wrap=wf_timer_manager_create',
'-Wl,--wrap=wf_timer_manager_dispose',
'-Wl,--wrap=wf_timer_manager_check',
'-Wl,--wrap=wf_timer_create',
'-Wl,--wrap=wf_timer_dispose',
'-Wl,--wrap=wf_timer_start',
'-Wl,--wrap=wf_timer_cancel',
'-Wl,--wrap=wf_impl_timer_manager_create',
'-Wl,--wrap=wf_impl_timer_manager_dispose',
'-Wl,--wrap=wf_impl_timer_manager_check',
'-Wl,--wrap=wf_impl_timer_create',
'-Wl,--wrap=wf_impl_timer_dispose',
'-Wl,--wrap=wf_impl_timer_start',
'-Wl,--wrap=wf_impl_timer_cancel',
'-Wl,--wrap=wf_impl_operation_context_get_proxy',
'-Wl,--wrap=wf_jsonrpc_proxy_vinvoke',
'-Wl,--wrap=wf_jsonrpc_proxy_vnotify',
'-Wl,--wrap=wf_impl_jsonrpc_proxy_vinvoke',
'-Wl,--wrap=wf_impl_jsonrpc_proxy_vnotify',
'-Wl,--wrap=fuse_req_userdata',
'-Wl,--wrap=fuse_reply_open',
'-Wl,--wrap=fuse_reply_err',

View File

@ -5,14 +5,14 @@ extern "C"
{
static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr;
WF_WRAP_VFUNC5(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke,
WF_WRAP_VFUNC5(webfuse_test_MockJsonRpcProxy, void, wf_impl_jsonrpc_proxy_vinvoke,
struct wf_jsonrpc_proxy *,
wf_jsonrpc_proxy_finished_fn *,
void *,
char const *,
char const *);
WF_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify,
WF_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wf_impl_jsonrpc_proxy_vnotify,
struct wf_jsonrpc_proxy *,
char const *,
char const *);

View File

@ -1,7 +1,7 @@
#ifndef MOCK_JSONRPC_PROXY_HPP
#define MOCK_JSONRPC_PROXY_HPP
#include "webfuse/core/jsonrpc/proxy_intern.h"
#include "webfuse/impl/jsonrpc/proxy_intern.h"
#include <gmock/gmock.h>
namespace webfuse_test
@ -12,13 +12,13 @@ class MockJsonRpcProxy
public:
MockJsonRpcProxy();
virtual ~MockJsonRpcProxy();
MOCK_METHOD5(wf_jsonrpc_proxy_vinvoke, void (
MOCK_METHOD5(wf_impl_jsonrpc_proxy_vinvoke, void (
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info));
MOCK_METHOD3(wf_jsonrpc_proxy_vnotify, void (
MOCK_METHOD3(wf_impl_jsonrpc_proxy_vnotify, void (
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info));

View File

@ -17,7 +17,7 @@ using testing::StrEq;
TEST(wf_impl_operation_close, notify_proxy)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"))).Times(1);
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"))).Times(1);
MockOperationContext context;
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
@ -39,7 +39,7 @@ TEST(wf_impl_operation_close, notify_proxy)
TEST(wf_impl_operation_close, fail_rpc_null)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_)).Times(0);
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vnotify(_,_,_)).Times(0);
MockOperationContext context;
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)

View File

@ -34,7 +34,7 @@ void free_context(
TEST(wf_impl_operation_getattr, invoke_proxy)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1)
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1)
.WillOnce(Invoke(free_context));
MockOperationContext context;

View File

@ -34,7 +34,7 @@ void free_context(
TEST(wf_impl_operation_lookup, invoke_proxy)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1)
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1)
.WillOnce(Invoke(free_context));
MockOperationContext context;

View File

@ -18,7 +18,7 @@ using testing::StrEq;
TEST(wf_impl_operation_open, invoke_proxy)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1);
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1);
MockOperationContext context;
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)

View File

@ -16,7 +16,7 @@ using testing::StrEq;
TEST(wf_impl_operation_read, invoke_proxy)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1);
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1);
MockOperationContext context;
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
@ -39,7 +39,7 @@ TEST(wf_impl_operation_read, invoke_proxy)
TEST(wf_impl_operation_read, invoke_proxy_limit_size)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1);
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1);
MockOperationContext context;
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)

View File

@ -34,7 +34,7 @@ void free_context(
TEST(wf_impl_operation_readdir, invoke_proxy)
{
MockJsonRpcProxy proxy;
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si")))
EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si")))
.Times(1).WillOnce(Invoke(free_context));
MockOperationContext context;

View File

@ -5,14 +5,14 @@ extern "C"
{
static wf_jsonrpc_test::ITimer * wf_jsonrpc_MockTimer = nullptr;
WF_WRAP_FUNC0(wf_jsonrpc_MockTimer, wf_timer_manager *, wf_timer_manager_create);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_dispose, wf_timer_manager *);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_check, wf_timer_manager *);
WF_WRAP_FUNC0(wf_jsonrpc_MockTimer, wf_timer_manager *, wf_impl_timer_manager_create);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_impl_timer_manager_dispose, wf_timer_manager *);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_impl_timer_manager_check, wf_timer_manager *);
WF_WRAP_FUNC3(wf_jsonrpc_MockTimer, wf_timer *, wf_timer_create, wf_timer_manager *, wf_timer_on_timer_fn *, void *);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_dispose, wf_timer *);
WF_WRAP_FUNC2(wf_jsonrpc_MockTimer, void, wf_timer_start, wf_timer *, int);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_cancel, wf_timer *);
WF_WRAP_FUNC3(wf_jsonrpc_MockTimer, wf_timer *, wf_impl_timer_create, wf_timer_manager *, wf_timer_on_timer_fn *, void *);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_impl_timer_dispose, wf_timer *);
WF_WRAP_FUNC2(wf_jsonrpc_MockTimer, void, wf_impl_timer_start, wf_timer *, int);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_impl_timer_cancel, wf_timer *);
}

View File

@ -1,8 +1,8 @@
#ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP
#define WF_JSONRPC_MOCK_TIMERMANAGER_HPP
#include "webfuse/core/timer/timer.h"
#include "webfuse/core/timer/manager.h"
#include "webfuse/impl/timer/timer.h"
#include "webfuse/impl/timer/manager.h"
#include <gmock/gmock.h>
namespace wf_jsonrpc_test
@ -12,16 +12,16 @@ class ITimer
{
public:
virtual ~ITimer() = default;
virtual wf_timer_manager * wf_timer_manager_create() = 0;
virtual void wf_timer_manager_dispose(wf_timer_manager * manager) = 0;
virtual void wf_timer_manager_check(wf_timer_manager * manager) = 0;
virtual wf_timer * wf_timer_create(
virtual wf_timer_manager * wf_impl_timer_manager_create() = 0;
virtual void wf_impl_timer_manager_dispose(wf_timer_manager * manager) = 0;
virtual void wf_impl_timer_manager_check(wf_timer_manager * manager) = 0;
virtual wf_timer * wf_impl_timer_create(
wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data) = 0;
virtual void wf_timer_dispose(wf_timer * timer) = 0;
virtual void wf_timer_start(wf_timer * timer, int timeout_ms) = 0;
virtual void wf_timer_cancel(wf_timer * timer) = 0;
virtual void wf_impl_timer_dispose(wf_timer * timer) = 0;
virtual void wf_impl_timer_start(wf_timer * timer, int timeout_ms) = 0;
virtual void wf_impl_timer_cancel(wf_timer * timer) = 0;
};
class MockTimer: public ITimer
@ -29,16 +29,16 @@ class MockTimer: public ITimer
public:
MockTimer();
~MockTimer() override;
MOCK_METHOD0(wf_timer_manager_create, wf_timer_manager * ());
MOCK_METHOD1(wf_timer_manager_dispose, void(wf_timer_manager * manager));
MOCK_METHOD1(wf_timer_manager_check, void (wf_timer_manager * manager));
MOCK_METHOD3(wf_timer_create, wf_timer *(
MOCK_METHOD0(wf_impl_timer_manager_create, wf_timer_manager * ());
MOCK_METHOD1(wf_impl_timer_manager_dispose, void(wf_timer_manager * manager));
MOCK_METHOD1(wf_impl_timer_manager_check, void (wf_timer_manager * manager));
MOCK_METHOD3(wf_impl_timer_create, wf_timer *(
wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data));
MOCK_METHOD1(wf_timer_dispose, void (wf_timer * timer));
MOCK_METHOD2(wf_timer_start, void (wf_timer * timer, int timeout_ms));
MOCK_METHOD1(wf_timer_cancel, void (wf_timer * timer));
MOCK_METHOD1(wf_impl_timer_dispose, void (wf_timer * timer));
MOCK_METHOD2(wf_impl_timer_start, void (wf_timer * timer, int timeout_ms));
MOCK_METHOD1(wf_impl_timer_cancel, void (wf_timer * timer));
};

View File

@ -1,7 +1,7 @@
#ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP
#define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP
#include "webfuse/core/timer/on_timer_fn.h"
#include "webfuse/impl/timer/on_timer_fn.h"
#include <gmock/gmock.h>
namespace wf_jsonrpc_test

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/request.h"
TEST(wf_jsonrpc_is_request, request_with_object_params)
{
@ -8,7 +8,7 @@ TEST(wf_jsonrpc_is_request, request_with_object_params)
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_request(request));
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -20,14 +20,14 @@ TEST(wf_jsonrpc_is_request, request_with_array_params)
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_request(request));
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, null_request)
{
ASSERT_FALSE(wf_jsonrpc_is_request(nullptr));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(nullptr));
}
TEST(wf_jsonrpc_is_request, invalid_request)
@ -37,7 +37,7 @@ TEST(wf_jsonrpc_is_request, invalid_request)
json_array_append_new(request, json_object());
json_array_append_new(request, json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -48,7 +48,7 @@ TEST(wf_jsonrpc_is_request, invalid_request_without_id)
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "params", json_object());
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -60,7 +60,7 @@ TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_id)
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_string("42"));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -71,7 +71,7 @@ TEST(wf_jsonrpc_is_request, invalid_request_without_method)
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -83,7 +83,7 @@ TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_method)
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -94,7 +94,7 @@ TEST(wf_jsonrpc_is_request, invalid_request_without_params)
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -106,7 +106,7 @@ TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_params)
json_object_set_new(request, "params", json_string("params"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/response.h"
#include "webfuse/impl/jsonrpc/response.h"
TEST(wf_jsonrpc_is_response, valid_result)
{
@ -7,7 +7,7 @@ TEST(wf_jsonrpc_is_response, valid_result)
json_object_set_new(message, "result", json_object());
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_response(message));
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
@ -18,7 +18,7 @@ TEST(wf_jsonrpc_is_response, valid_result_string)
json_object_set_new(message, "result", json_string("also valid"));
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_response(message));
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
@ -29,14 +29,14 @@ TEST(wf_jsonrpc_is_response, valid_error)
json_object_set_new(message, "error", json_object());
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_response(message));
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, invalid_null)
{
ASSERT_FALSE(wf_jsonrpc_is_response(nullptr));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(nullptr));
}
TEST(wf_jsonrpc_is_response, invalid_message)
@ -45,7 +45,7 @@ TEST(wf_jsonrpc_is_response, invalid_message)
json_array_append_new(message, json_object());
json_array_append_new(message, json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
@ -55,7 +55,7 @@ TEST(wf_jsonrpc_is_response, invalid_missing_id)
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
@ -66,7 +66,7 @@ TEST(wf_jsonrpc_is_response, invalid_id_wrong_type)
json_object_set_new(message, "result", json_object());
json_object_set_new(message, "id", json_string("42"));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
@ -77,7 +77,7 @@ 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(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
@ -88,7 +88,7 @@ TEST(wf_jsonrpc_is_response, invalid_error_wrong_type)
json_object_set_new(message, "error", json_array());
json_object_set_new(message, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/status.h"
#include "webfuse/core/timer/manager.h"
#include "webfuse/impl/timer/manager.h"
#include "webfuse/tests/core/jsonrpc/mock_timer.hpp"
@ -101,29 +101,29 @@ namespace
TEST(wf_jsonrpc_proxy, init)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext context;
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
ASSERT_FALSE(context.is_called);
}
TEST(wf_jsonrpc_proxy, invoke)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_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));
@ -145,8 +145,8 @@ TEST(wf_jsonrpc_proxy, invoke)
ASSERT_FALSE(finished_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
ASSERT_TRUE(finished_context.is_called);
ASSERT_FALSE(nullptr == finished_context.error);
@ -154,15 +154,15 @@ TEST(wf_jsonrpc_proxy, invoke)
TEST(wf_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context(false);
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_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));
@ -170,25 +170,25 @@ TEST(wf_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
ASSERT_TRUE(finished_context.is_called);
ASSERT_FALSE(nullptr == finished_context.error);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
FinishedContext finished_context2;
void * finished_data2 = reinterpret_cast<void*>(&finished_context2);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", "");
wf_impl_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", "");
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@ -198,42 +198,42 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
ASSERT_TRUE(finished_context2.is_called);
ASSERT_EQ(WF_BAD_BUSY, jsonrpc_get_status(finished_context2.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
wf_impl_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, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, on_result)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_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));
@ -245,7 +245,7 @@ TEST(wf_jsonrpc_proxy, on_result)
json_object_set_new(response, "result", json_string("okay"));
json_object_set(response, "id", id);
wf_jsonrpc_proxy_onresult(proxy, response);
wf_impl_jsonrpc_proxy_onresult(proxy, response);
json_decref(response);
ASSERT_TRUE(finished_context.is_called);
@ -253,21 +253,21 @@ TEST(wf_jsonrpc_proxy, on_result)
ASSERT_TRUE(json_is_string(finished_context.result));
ASSERT_STREQ("okay", json_string_value(finished_context.result));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_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));
@ -279,75 +279,75 @@ TEST(wf_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
json_object_set_new(response, "result", json_string("okay"));
json_object_set_new(response, "id", json_integer(1 + json_integer_value(id)));
wf_jsonrpc_proxy_onresult(proxy, response);
wf_impl_jsonrpc_proxy_onresult(proxy, response);
json_decref(response);
ASSERT_FALSE(finished_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, timeout)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_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));
std::this_thread::sleep_for(10ms);
wf_timer_manager_check(timer_manager);
wf_impl_timer_manager_check(timer_manager);
ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, cleanup_pending_request)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wf_impl_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);
wf_jsonrpc_proxy_dispose(proxy);
wf_impl_jsonrpc_proxy_dispose(proxy);
ASSERT_TRUE(finished_context.is_called);
wf_timer_manager_dispose(timer_manager);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, notify)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
wf_jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42);
wf_impl_jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@ -367,24 +367,24 @@ TEST(wf_jsonrpc_proxy, notify)
json_t * id = json_object_get(send_context.response, "id");
ASSERT_EQ(nullptr, id);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, notify_dont_send_invalid_request)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
wf_jsonrpc_proxy_notify(proxy, "foo", "?");
wf_impl_jsonrpc_proxy_notify(proxy, "foo", "?");
ASSERT_FALSE(send_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending)
@ -393,38 +393,38 @@ TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending)
wf_timer_on_timer_fn * on_timer = nullptr;
void * timer_context = nullptr;
EXPECT_CALL(timer_api, wf_timer_create(_, _, _))
EXPECT_CALL(timer_api, wf_impl_timer_create(_, _, _))
.Times(1)
.WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr)));
EXPECT_CALL(timer_api, wf_timer_dispose(_)).Times(1);
EXPECT_CALL(timer_api, wf_impl_timer_dispose(_)).Times(1);
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(nullptr, 1, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(nullptr, 1, &jsonrpc_send, send_data);
on_timer(nullptr, timer_context);
ASSERT_FALSE(send_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_impl_jsonrpc_proxy_dispose(proxy);
}
TEST(wf_jsonrpc_proxy, on_result_swallow_if_no_request_pending)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wf_timer_manager * timer_manager = wf_impl_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wf_jsonrpc_proxy * proxy = wf_impl_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
json_t * response = json_object();
json_object_set_new(response, "result", json_string("okay"));
json_object_set_new(response, "id", json_integer(42));
wf_jsonrpc_proxy_onresult(proxy, response);
wf_impl_jsonrpc_proxy_onresult(proxy, response);
json_decref(response);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wf_impl_jsonrpc_proxy_dispose(proxy);
wf_impl_timer_manager_dispose(timer_manager);
}

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/status.h"
namespace
@ -29,12 +29,12 @@ TEST(wf_jsonrpc_request, create_dispose)
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
ASSERT_NE(nullptr, request);
ASSERT_EQ(user_data, wf_jsonrpc_request_get_userdata(request));
ASSERT_EQ(user_data, wf_impl_jsonrpc_request_get_userdata(request));
wf_jsonrpc_request_dispose(request);
wf_impl_jsonrpc_request_dispose(request);
}
TEST(wf_jsonrpc_request, respond)
@ -43,9 +43,9 @@ TEST(wf_jsonrpc_request, respond)
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_jsonrpc_respond(request, json_string("okay"));
wf_impl_jsonrpc_respond(request, json_string("okay"));
ASSERT_NE(nullptr, context.response);
@ -72,9 +72,9 @@ TEST(wf_jsonrpc_request, respond_error)
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_jsonrpc_respond_error(request, WF_BAD, "Bad");
wf_impl_jsonrpc_respond_error(request, WF_BAD, "Bad");
ASSERT_NE(nullptr, context.response);
@ -109,7 +109,7 @@ TEST(wf_jsonrpc_request, is_request_object_params)
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_request(request));
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -120,7 +120,7 @@ TEST(wf_jsonrpc_request, is_request_fail_missing_params)
json_object_set_new(request, "method", json_string("some_method"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}
@ -132,7 +132,7 @@ TEST(wf_jsonrpc_request, is_request_fail_params_wrong_type)
json_object_set_new(request, "params", json_string("invalid_params"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
json_decref(request);
}

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/response_intern.h"
#include "webfuse/impl/jsonrpc/response_intern.h"
#include "webfuse/status.h"
TEST(wf_json_response, init_result)
@ -9,14 +9,14 @@ TEST(wf_json_response, init_result)
json_object_set_new(message, "id", json_integer(11));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_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);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -30,14 +30,14 @@ TEST(wf_json_response, init_error)
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -47,13 +47,13 @@ TEST(wf_json_response, init_fail_missing_result_and_error)
json_object_set_new(message, "id", json_integer(12));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(12, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -63,13 +63,13 @@ TEST(wf_json_response, init_fail_missing_id)
json_object_set_new(message, "result", json_integer(47));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -80,13 +80,13 @@ TEST(wf_json_response, init_fail_wrong_id_type)
json_object_set_new(message, "id", json_string("42"));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -99,13 +99,13 @@ TEST(wf_json_response, init_fail_error_missing_code)
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -119,13 +119,13 @@ TEST(wf_json_response, init_fail_error_wrong_code_type)
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}
@ -136,12 +136,12 @@ TEST(wf_json_response, init_fail_error_wrong_type)
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
wf_impl_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
json_decref(message);
}

View File

@ -1,7 +1,7 @@
#include <string>
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/response_intern.h"
#include "webfuse/impl/jsonrpc/response_intern.h"
static void response_parse_str(
@ -11,7 +11,7 @@ static void response_parse_str(
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
if (nullptr != message)
{
wf_jsonrpc_response_init(response, message);
wf_impl_jsonrpc_response_init(response, message);
json_decref(message);
}
}
@ -25,21 +25,21 @@ TEST(response_parser, test)
ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
// empty
response_parse_str("{}", &response);
ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_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);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
// custom error code
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
@ -47,12 +47,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);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
// valid response
response_parse_str("{\"result\": true, \"id\": 42}", &response);
ASSERT_EQ(nullptr, response.error);
ASSERT_EQ(42, response.id);
ASSERT_NE(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wf_impl_jsonrpc_response_cleanup(&response);
}

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include "webfuse/core/jsonrpc/server.h"
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/server.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/status.h"
namespace
@ -34,15 +34,15 @@ namespace
(void) user_data;
json_t * result = json_string("Hello");
wf_jsonrpc_respond(request, result);
wf_impl_jsonrpc_respond(request, result);
}
}
TEST(wf_jsonrpc_server, process_request)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
wf_impl_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@ -50,7 +50,7 @@ TEST(wf_jsonrpc_server, process_request)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(23));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_TRUE(context.is_called);
ASSERT_NE(nullptr, context.response);
@ -66,13 +66,13 @@ TEST(wf_jsonrpc_server, process_request)
json_decref(context.response);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, process_request_with_oject_params)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
wf_impl_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@ -80,7 +80,7 @@ TEST(wf_jsonrpc_server, process_request_with_oject_params)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(23));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_TRUE(context.is_called);
ASSERT_NE(nullptr, context.response);
@ -96,13 +96,13 @@ TEST(wf_jsonrpc_server, process_request_with_oject_params)
json_decref(context.response);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, invoke_unknown_method)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
wf_impl_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@ -110,7 +110,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method)
json_object_set_new(request, "method", json_string("greet"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_TRUE(context.is_called);
ASSERT_NE(nullptr, context.response);
@ -132,29 +132,29 @@ TEST(wf_jsonrpc_server, invoke_unknown_method)
json_decref(context.response);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_missing_id)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wf_jsonrpc_server * server = wf_impl_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());
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_wrong_id_type)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@ -162,34 +162,34 @@ TEST(wf_jsonrpc_server, skip_invalid_request_wrong_id_type)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_string("42"));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_missing_params)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wf_jsonrpc_server * server = wf_impl_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, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_wrong_params_type)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@ -197,34 +197,34 @@ TEST(wf_jsonrpc_server, skip_invalid_request_wrong_params_type)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_string("invalid"));
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_missing_method)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
json_t * request = json_object();
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_wront_method_type)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wf_jsonrpc_server * server = wf_impl_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@ -232,10 +232,10 @@ TEST(wf_jsonrpc_server, skip_invalid_request_wront_method_type)
json_object_set_new(request, "method", json_integer(42));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wf_impl_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wf_impl_jsonrpc_server_dispose(server);
}

View File

@ -1,17 +1,17 @@
#include <gtest/gtest.h>
#include "webfuse/core/base64.h"
#include "webfuse/impl/util/base64.h"
TEST(Base64, EncodedSize)
{
ASSERT_EQ(4, wf_base64_encoded_size(1));
ASSERT_EQ(4, wf_base64_encoded_size(2));
ASSERT_EQ(4, wf_base64_encoded_size(3));
ASSERT_EQ(4, wf_impl_base64_encoded_size(1));
ASSERT_EQ(4, wf_impl_base64_encoded_size(2));
ASSERT_EQ(4, wf_impl_base64_encoded_size(3));
ASSERT_EQ(8, wf_base64_encoded_size(4));
ASSERT_EQ(8, wf_base64_encoded_size(5));
ASSERT_EQ(8, wf_base64_encoded_size(6));
ASSERT_EQ(8, wf_impl_base64_encoded_size(4));
ASSERT_EQ(8, wf_impl_base64_encoded_size(5));
ASSERT_EQ(8, wf_impl_base64_encoded_size(6));
ASSERT_EQ(120, wf_base64_encoded_size(90));
ASSERT_EQ(120, wf_impl_base64_encoded_size(90));
}
TEST(Base64, Encode)
@ -19,17 +19,17 @@ TEST(Base64, Encode)
char buffer[42];
std::string in = "Hello";
size_t length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
size_t length = wf_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
ASSERT_EQ(8, length);
ASSERT_STREQ("SGVsbG8=", buffer);
in = "Hello\n";
length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
length = wf_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
ASSERT_EQ(8, length);
ASSERT_STREQ("SGVsbG8K", buffer);
in = "Blue";
length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
length = wf_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
ASSERT_EQ(8, length);
ASSERT_STREQ("Qmx1ZQ==", buffer);
}
@ -39,53 +39,53 @@ TEST(Base64, FailedToEncodeBufferTooSmall)
char buffer[1];
std::string in = "Hello";
size_t length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1);
size_t length = wf_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1);
ASSERT_EQ(0, length);
}
TEST(Base64, DecodedSize)
{
std::string in = "SGVsbG8="; // Hello
size_t length = wf_base64_decoded_size(in.c_str(), in.size());
size_t length = wf_impl_base64_decoded_size(in.c_str(), in.size());
ASSERT_EQ(5, length);
in = "SGVsbG8K"; // Hello\n
length = wf_base64_decoded_size(in.c_str(), in.size());
length = wf_impl_base64_decoded_size(in.c_str(), in.size());
ASSERT_EQ(6, length);
in = "Qmx1ZQ=="; // Blue
length = wf_base64_decoded_size(in.c_str(), in.size());
length = wf_impl_base64_decoded_size(in.c_str(), in.size());
ASSERT_EQ(4, length);
}
TEST(Base64, IsValid)
{
std::string in = "SGVsbG8="; // Hello
ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_TRUE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "SGVsbG8K"; // Hello\n
ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_TRUE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ=="; // Blue
ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_TRUE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ=a";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ=";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1Z===";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ?=";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wf_impl_base64_isvalid(in.c_str(), in.size()));
in = "Qm?1ZQ==";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wf_impl_base64_isvalid(in.c_str(), in.size()));
}
TEST(Base64, Decode)
@ -93,19 +93,19 @@ TEST(Base64, Decode)
char buffer[42];
std::string in = "SGVsbG8="; // Hello
size_t length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
size_t length = wf_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
ASSERT_EQ(5, length);
buffer[length] = '\0';
ASSERT_STREQ("Hello", buffer);
in = "SGVsbG8K"; // Hello\n
length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
length = wf_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
ASSERT_EQ(6, length);
buffer[length] = '\0';
ASSERT_STREQ("Hello\n", buffer);
in = "Qmx1ZQ=="; // Blue
length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
length = wf_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
ASSERT_EQ(4, length);
buffer[length] = '\0';
ASSERT_STREQ("Blue", buffer);
@ -116,7 +116,7 @@ TEST(Base64, FailToDecodeBufferTooSmall)
char buffer[1];
std::string in = "SGVsbG8="; // Hello
size_t length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1);
size_t length = wf_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1);
ASSERT_EQ(0, length);
}

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "webfuse/core/container_of.h"
#include "webfuse/impl/util/container_of.h"
namespace
{

View File

@ -1,22 +1,22 @@
#include <gtest/gtest.h>
#include <cstring>
#include "webfuse/core/message.h"
#include "webfuse/impl/message.h"
TEST(wf_message, create)
{
json_t * value = json_object();
struct wf_message * message = wf_message_create(value);
struct wf_message * message = wf_impl_message_create(value);
ASSERT_NE(nullptr, message);
ASSERT_EQ(2, message->length);
ASSERT_TRUE(0 == strncmp("{}", message->data, 2));
wf_message_dispose(message);
wf_impl_message_dispose(message);
json_decref(value);
}
TEST(wf_message, fail_to_create)
{
struct wf_message * message = wf_message_create(nullptr);
struct wf_message * message = wf_impl_message_create(nullptr);
ASSERT_EQ(nullptr, message);
}

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "webfuse/core/message_queue.h"
#include "webfuse/core/message.h"
#include "webfuse/core/slist.h"
#include "webfuse/impl/message_queue.h"
#include "webfuse/impl/message.h"
#include "webfuse/impl/util/slist.h"
namespace
{
@ -10,7 +10,7 @@ namespace
{
json_t * value = json_object();
json_object_set_new(value, "content", json_string(content));
struct wf_message * message = wf_message_create(value);
struct wf_message * message = wf_impl_message_create(value);
json_decref(value);
return &message->item;
@ -21,32 +21,32 @@ namespace
TEST(wf_message_queue, cleanup_empty_list)
{
struct wf_slist queue;
wf_slist_init(&queue);
wf_impl_slist_init(&queue);
wf_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_slist_empty(&queue));
wf_impl_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_impl_slist_empty(&queue));
}
TEST(wf_message_queue, cleanup_one_element)
{
struct wf_slist queue;
wf_slist_init(&queue);
wf_impl_slist_init(&queue);
wf_slist_append(&queue, create_message("Hello"));
wf_impl_slist_append(&queue, create_message("Hello"));
wf_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_slist_empty(&queue));
wf_impl_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_impl_slist_empty(&queue));
}
TEST(wf_message_queue, cleanup_multiple_element)
{
struct wf_slist queue;
wf_slist_init(&queue);
wf_impl_slist_init(&queue);
wf_slist_append(&queue, create_message("Hello"));
wf_slist_append(&queue, create_message("World"));
wf_slist_append(&queue, create_message("!"));
wf_impl_slist_append(&queue, create_message("Hello"));
wf_impl_slist_append(&queue, create_message("World"));
wf_impl_slist_append(&queue, create_message("!"));
wf_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_slist_empty(&queue));
wf_impl_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_impl_slist_empty(&queue));
}

View File

@ -1,16 +1,16 @@
#include <gtest/gtest.h>
#include "webfuse/core/slist.h"
#include "webfuse/impl/util/slist.h"
TEST(wf_slist, init)
{
struct wf_slist list;
wf_slist_init(&list);
wf_impl_slist_init(&list);
ASSERT_EQ(nullptr, list.head.next);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&list.head, list.last);
ASSERT_TRUE(wf_slist_empty(&list));
ASSERT_EQ(nullptr, wf_slist_first(&list));
ASSERT_TRUE(wf_impl_slist_empty(&list));
ASSERT_EQ(nullptr, wf_impl_slist_first(&list));
}
TEST(wf_slist, append)
@ -18,32 +18,32 @@ TEST(wf_slist, append)
struct wf_slist list;
struct wf_slist_item item[3];
wf_slist_init(&list);
ASSERT_TRUE(wf_slist_empty(&list));
wf_impl_slist_init(&list);
ASSERT_TRUE(wf_impl_slist_empty(&list));
wf_slist_append(&list, &item[0]);
wf_impl_slist_append(&list, &item[0]);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[0], wf_impl_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[0], list.last);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(nullptr, item[0].next);
wf_slist_append(&list, &item[1]);
wf_impl_slist_append(&list, &item[1]);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[0], wf_impl_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[1], list.last);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&item[1], item[0].next);
ASSERT_EQ(nullptr, item[1].next);
wf_slist_append(&list, &item[2]);
wf_impl_slist_append(&list, &item[2]);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[0], wf_impl_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[2], list.last);
ASSERT_EQ(nullptr, list.last->next);
@ -57,29 +57,29 @@ TEST(wf_slist_remove_after, remove_first)
struct wf_slist list;
struct wf_slist_item item[3];
wf_slist_init(&list);
wf_slist_append(&list, &item[0]);
wf_slist_append(&list, &item[1]);
wf_slist_append(&list, &item[2]);
wf_impl_slist_init(&list);
wf_impl_slist_append(&list, &item[0]);
wf_impl_slist_append(&list, &item[1]);
wf_impl_slist_append(&list, &item[2]);
wf_slist_item * removed;
removed = wf_slist_remove_first(&list);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_first(&list);
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[0], removed);
removed = wf_slist_remove_first(&list);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_first(&list);
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[1], removed);
removed = wf_slist_remove_first(&list);
ASSERT_TRUE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_first(&list);
ASSERT_TRUE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[2], removed);
ASSERT_EQ(nullptr, list.head.next);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&list.head, list.last);
ASSERT_EQ(nullptr, wf_slist_first(&list));
ASSERT_EQ(nullptr, wf_impl_slist_first(&list));
}
TEST(wf_slist_remove_after, remove_last)
@ -87,29 +87,29 @@ TEST(wf_slist_remove_after, remove_last)
struct wf_slist list;
struct wf_slist_item item[3];
wf_slist_init(&list);
wf_slist_append(&list, &item[0]);
wf_slist_append(&list, &item[1]);
wf_slist_append(&list, &item[2]);
wf_impl_slist_init(&list);
wf_impl_slist_append(&list, &item[0]);
wf_impl_slist_append(&list, &item[1]);
wf_impl_slist_append(&list, &item[2]);
wf_slist_item * removed;
removed = wf_slist_remove_after(&list, &item[1]);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_after(&list, &item[1]);
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[2], removed);
removed = wf_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[1], removed);
removed = wf_slist_remove_after(&list, &list.head);
ASSERT_TRUE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_after(&list, &list.head);
ASSERT_TRUE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[0], removed);
ASSERT_EQ(nullptr, list.head.next);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&list.head, list.last);
ASSERT_EQ(nullptr, wf_slist_first(&list));
ASSERT_EQ(nullptr, wf_impl_slist_first(&list));
}
TEST(wf_slist_remove_after, remove_after)
@ -117,20 +117,20 @@ TEST(wf_slist_remove_after, remove_after)
struct wf_slist list;
struct wf_slist_item item[3];
wf_slist_init(&list);
wf_slist_append(&list, &item[0]);
wf_slist_append(&list, &item[1]);
wf_slist_append(&list, &item[2]);
wf_impl_slist_init(&list);
wf_impl_slist_append(&list, &item[0]);
wf_impl_slist_append(&list, &item[1]);
wf_impl_slist_append(&list, &item[2]);
wf_slist_item * removed;
removed = wf_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wf_impl_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[1], removed);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wf_impl_slist_empty(&list));
ASSERT_EQ(&item[0], wf_impl_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[2], list.last);
ASSERT_EQ(nullptr, list.last->next);

View File

@ -1,30 +1,30 @@
#include <gtest/gtest.h>
#include "webfuse/core/status_intern.h"
#include "webfuse/impl/status.h"
TEST(wf_status, tostring)
{
ASSERT_STREQ("Good", wf_status_tostring(WF_GOOD));
ASSERT_STREQ("Bad", wf_status_tostring(WF_BAD));
ASSERT_STREQ("Bad (not implemented)", wf_status_tostring(WF_BAD_NOTIMPLEMENTED));
ASSERT_STREQ("Bad (busy)", wf_status_tostring(WF_BAD_BUSY));
ASSERT_STREQ("Bad (timeout)", wf_status_tostring(WF_BAD_TIMEOUT));
ASSERT_STREQ("Bad (format)", wf_status_tostring(WF_BAD_FORMAT));
ASSERT_STREQ("Bad (no entry)", wf_status_tostring(WF_BAD_NOENTRY));
ASSERT_STREQ("Bad (access denied)", wf_status_tostring(WF_BAD_ACCESS_DENIED));
ASSERT_STREQ("Good", wf_impl_status_tostring(WF_GOOD));
ASSERT_STREQ("Bad", wf_impl_status_tostring(WF_BAD));
ASSERT_STREQ("Bad (not implemented)", wf_impl_status_tostring(WF_BAD_NOTIMPLEMENTED));
ASSERT_STREQ("Bad (busy)", wf_impl_status_tostring(WF_BAD_BUSY));
ASSERT_STREQ("Bad (timeout)", wf_impl_status_tostring(WF_BAD_TIMEOUT));
ASSERT_STREQ("Bad (format)", wf_impl_status_tostring(WF_BAD_FORMAT));
ASSERT_STREQ("Bad (no entry)", wf_impl_status_tostring(WF_BAD_NOENTRY));
ASSERT_STREQ("Bad (access denied)", wf_impl_status_tostring(WF_BAD_ACCESS_DENIED));
ASSERT_STREQ("Bad (unknown)", wf_status_tostring(-1));
ASSERT_STREQ("Bad (unknown)", wf_impl_status_tostring(-1));
}
TEST(wf_status, to_rc)
{
ASSERT_EQ(0, wf_status_to_rc(WF_GOOD));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD));
ASSERT_EQ(-ENOSYS, wf_status_to_rc(WF_BAD_NOTIMPLEMENTED));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD_BUSY));
ASSERT_EQ(-ETIMEDOUT, wf_status_to_rc(WF_BAD_TIMEOUT));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD_FORMAT));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD_NOENTRY));
ASSERT_EQ(-EACCES, wf_status_to_rc(WF_BAD_ACCESS_DENIED));
ASSERT_EQ(0, wf_impl_status_to_rc(WF_GOOD));
ASSERT_EQ(-ENOENT, wf_impl_status_to_rc(WF_BAD));
ASSERT_EQ(-ENOSYS, wf_impl_status_to_rc(WF_BAD_NOTIMPLEMENTED));
ASSERT_EQ(-ENOENT, wf_impl_status_to_rc(WF_BAD_BUSY));
ASSERT_EQ(-ETIMEDOUT, wf_impl_status_to_rc(WF_BAD_TIMEOUT));
ASSERT_EQ(-ENOENT, wf_impl_status_to_rc(WF_BAD_FORMAT));
ASSERT_EQ(-ENOENT, wf_impl_status_to_rc(WF_BAD_NOENTRY));
ASSERT_EQ(-EACCES, wf_impl_status_to_rc(WF_BAD_ACCESS_DENIED));
ASSERT_EQ(-ENOENT, wf_status_to_rc(-1));
ASSERT_EQ(-ENOENT, wf_impl_status_to_rc(-1));
}

View File

@ -1,69 +1,69 @@
#include <gtest/gtest.h>
#include "webfuse/core/url.h"
#include "webfuse/impl/util/url.h"
TEST(url, ParseWs)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost/");
bool result = wf_impl_url_init(&url, "ws://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_FALSE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
wf_url_cleanup(&url);
wf_impl_url_cleanup(&url);
}
TEST(url, ParswWss)
{
struct wf_url url;
bool result = wf_url_init(&url, "wss://localhost/");
bool result = wf_impl_url_init(&url, "wss://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(443, url.port);
ASSERT_TRUE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
wf_url_cleanup(&url);
wf_impl_url_cleanup(&url);
}
TEST(url, ParseIPAdress)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://127.0.0.1/");
bool result = wf_impl_url_init(&url, "ws://127.0.0.1/");
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_STREQ("127.0.0.1", url.host);
ASSERT_STREQ("/", url.path);
wf_url_cleanup(&url);
wf_impl_url_cleanup(&url);
}
TEST(url, ParsePort)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost:54321/");
bool result = wf_impl_url_init(&url, "ws://localhost:54321/");
ASSERT_TRUE(result);
ASSERT_EQ(54321, url.port);
wf_url_cleanup(&url);
wf_impl_url_cleanup(&url);
}
TEST(url, ParseNonEmptyPath)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost/some_path?query");
bool result = wf_impl_url_init(&url, "ws://localhost/some_path?query");
ASSERT_TRUE(result);
ASSERT_STREQ("/some_path?query", url.path);
wf_url_cleanup(&url);
wf_impl_url_cleanup(&url);
}
TEST(url, FailToParseUnknownProtocol)
{
struct wf_url url;
bool result = wf_url_init(&url, "unknown://localhost/");
bool result = wf_impl_url_init(&url, "unknown://localhost/");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);
@ -73,7 +73,7 @@ TEST(url, FailToParseUnknownProtocol)
TEST(url, FailToParseMissingProtocol)
{
struct wf_url url;
bool result = wf_url_init(&url, "unknown");
bool result = wf_impl_url_init(&url, "unknown");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);
@ -83,7 +83,7 @@ TEST(url, FailToParseMissingProtocol)
TEST(url, FailToParseMissingPath)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost");
bool result = wf_impl_url_init(&url, "ws://localhost");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "webfuse/core/json_util.h"
#include "webfuse/impl/util/json_util.h"
TEST(jsonrpc_util, get_int)
{

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include "webfuse/core/timer/timepoint.h"
#include "webfuse/impl/timer/timepoint.h"
#include <thread>
#include <chrono>
@ -9,9 +9,9 @@ using namespace std::chrono_literals;
TEST(wf_timer_timepoint, now)
{
wf_timer_timepoint start = wf_timer_timepoint_now();
wf_timer_timepoint start = wf_impl_timer_timepoint_now();
std::this_thread::sleep_for(42ms);
wf_timer_timepoint end = wf_timer_timepoint_now();
wf_timer_timepoint end = wf_impl_timer_timepoint_now();
ASSERT_LT(start, end);
ASSERT_LT(end, start + 500);
@ -19,8 +19,8 @@ TEST(wf_timer_timepoint, now)
TEST(wf_timer_timepoint, in_msec)
{
wf_timer_timepoint now = wf_timer_timepoint_now();
wf_timer_timepoint later = wf_timer_timepoint_in_msec(42);
wf_timer_timepoint now = wf_impl_timer_timepoint_now();
wf_timer_timepoint later = wf_impl_timer_timepoint_in_msec(42);
ASSERT_LT(now, later);
ASSERT_LT(later, now + 500);
@ -30,9 +30,9 @@ TEST(wf_timer_timepoint, elapsed)
{
wf_timer_timepoint now;
now = wf_timer_timepoint_now();
ASSERT_TRUE(wf_timer_timepoint_is_elapsed(now - 1));
now = wf_impl_timer_timepoint_now();
ASSERT_TRUE(wf_impl_timer_timepoint_is_elapsed(now - 1));
now = wf_timer_timepoint_now();
ASSERT_FALSE(wf_timer_timepoint_is_elapsed(now + 500));
now = wf_impl_timer_timepoint_now();
ASSERT_FALSE(wf_impl_timer_timepoint_is_elapsed(now + 500));
}

View File

@ -4,8 +4,8 @@
#include <chrono>
#include <thread>
#include "webfuse/core/timer/timer.h"
#include "webfuse/core/timer/manager.h"
#include "webfuse/impl/timer/timer.h"
#include "webfuse/impl/timer/manager.h"
using std::size_t;
using namespace std::chrono_literals;
@ -24,125 +24,125 @@ extern "C"
TEST(wf_timer, init)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer = wf_impl_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wf_impl_timer_dispose(timer);
wf_impl_timer_manager_dispose(manager);
}
TEST(wf_timer, trigger)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer = wf_impl_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer, -1);
wf_timer_manager_check(manager);
wf_impl_timer_start(timer, -1);
wf_impl_timer_manager_check(manager);
ASSERT_TRUE(triggered);
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wf_impl_timer_dispose(timer);
wf_impl_timer_manager_dispose(manager);
}
TEST(wf_timer, trigger_on_dispose)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer = wf_impl_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer, (5 * 60 * 1000));
wf_impl_timer_start(timer, (5 * 60 * 1000));
wf_timer_manager_dispose(manager);
wf_impl_timer_manager_dispose(manager);
ASSERT_TRUE(triggered);
wf_timer_dispose(timer);
wf_impl_timer_dispose(timer);
}
TEST(wf_timer, cancel)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer = wf_impl_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer, 250);
wf_impl_timer_start(timer, 250);
std::this_thread::sleep_for(500ms);
wf_timer_cancel(timer);
wf_timer_manager_check(manager);
wf_impl_timer_cancel(timer);
wf_impl_timer_manager_check(manager);
ASSERT_FALSE(triggered);
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wf_impl_timer_dispose(timer);
wf_impl_timer_manager_dispose(manager);
}
TEST(wf_timer, cancel_multiple_timers)
{
static size_t const count = 5;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer[count];
bool triggered = false;
for(size_t i = 0; i < count; i++)
{
timer[i] = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer[i], 0);
timer[i] = wf_impl_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_impl_timer_start(timer[i], 0);
}
std::this_thread::sleep_for(10ms);
for(size_t i = 0; i < count; i++)
{
wf_timer_cancel(timer[i]);
wf_impl_timer_cancel(timer[i]);
}
wf_timer_manager_check(manager);
wf_impl_timer_manager_check(manager);
ASSERT_FALSE(triggered);
for(size_t i = 0; i < count; i++)
{
wf_timer_dispose(timer[i]);
wf_impl_timer_dispose(timer[i]);
}
wf_timer_manager_dispose(manager);
wf_impl_timer_manager_dispose(manager);
}
TEST(wf_timer, multiple_timers)
{
static size_t const count = 5;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer[count];
bool triggered[count];
for(size_t i = 0; i < count; i++)
{
timer[i] = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered[i]));
timer[i] = wf_impl_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered[i]));
triggered[i] = false;
wf_timer_start(timer[i], (300 - (50 * i)));
wf_impl_timer_start(timer[i], (300 - (50 * i)));
}
for(size_t i = 0; i < count; i++)
{
std::this_thread::sleep_for(100ms);
wf_timer_manager_check(manager);
wf_impl_timer_manager_check(manager);
}
for(size_t i = 0; i < count; i++)
{
ASSERT_TRUE(triggered[i]);
wf_timer_dispose(timer[i]);
wf_impl_timer_dispose(timer[i]);
}
wf_timer_manager_dispose(manager);
wf_impl_timer_manager_dispose(manager);
}
TEST(wf_timer, dont_trigger_null_callback)
{
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, nullptr, nullptr);
struct wf_timer_manager * manager = wf_impl_timer_manager_create();
struct wf_timer * timer = wf_impl_timer_create(manager, nullptr, nullptr);
wf_timer_start(timer, -1);
wf_timer_manager_check(manager);
wf_impl_timer_start(timer, -1);
wf_impl_timer_manager_check(manager);
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wf_impl_timer_dispose(timer);
wf_impl_timer_manager_dispose(manager);
}

View File

@ -15,7 +15,7 @@
#include <dirent.h>
#include <jansson.h>
#include "webfuse/core/lws_log.h"
#include "webfuse/impl/lws_log.h"
using webfuse_test::Server;
using webfuse_test::Provider;

View File

@ -1,5 +1,5 @@
#include "webfuse/utils/ws_server.h"
#include "webfuse/core/lws_log.h"
#include "webfuse/impl/util/lws_log.h"
#include <libwebsockets.h>
#include <thread>
@ -146,7 +146,7 @@ WsServer::Private::Private(std::string const & protocol, int port)
, is_shutdown_requested(false)
, wsi_(nullptr)
{
wf_lwslog_disable();
wf_impl_lwslog_disable();
IServer * server = this;
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2 );

View File

@ -1,5 +1,5 @@
#include "webfuse/utils/ws_server2.hpp"
#include "webfuse/core/lws_log.h"
#include "webfuse/impl/util/lws_log.h"
#include <libwebsockets.h>
#include <thread>
@ -150,7 +150,7 @@ WsServer2::Private::Private(
, is_shutdown_requested(false)
, wsi_(nullptr)
{
wf_lwslog_disable();
wf_impl_lwslog_disable();
IServer * server = this;
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2 );