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

98 lines
2.3 KiB
C
Raw Normal View History

2019-02-24 17:03:22 +00:00
#include "wsfsp/provider_intern.h"
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
#include <stdbool.h>
#include <string.h>
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
#include "wsfsp/request.h"
#include "wsfsp/operation/lookup_intern.h"
#include "wsfsp/operation/getattr_intern.h"
#include "wsfsp/operation/readdir_intern.h"
#include "wsfsp/operation/open_intern.h"
#include "wsfsp/operation/close_intern.h"
#include "wsfsp/operation/read_intern.h"
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
typedef void wsfsp_invoke_fn(
struct wsfsp_invokation_context * context,
json_t * params,
int id);
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
struct wsfsp_method
2019-02-17 13:31:04 +00:00
{
2019-02-24 17:03:22 +00:00
char const * name;
wsfsp_invoke_fn * invoke;
bool is_notification;
};
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
static void wsfsp_provider_invoke_method(
struct wsfsp_invokation_context * context,
char const * method_name,
json_t * params,
int id)
2019-02-17 13:31:04 +00:00
{
2019-02-24 17:03:22 +00:00
static struct wsfsp_method const methods[] =
{
{"lookup", &wsfsp_lookup, false},
{"getattr", &wsfsp_getattr, false},
{"readdir", &wsfsp_readdir, false},
{"open", &wsfsp_open, false},
{"close", &wsfsp_close, true},
{"read", &wsfsp_read, false}
};
static size_t const count = sizeof(methods) / sizeof(methods[0]);
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
for (size_t i = 0; i < count; i++)
{
struct wsfsp_method const * method = &methods[i];
if (0 == strcmp(method_name, method->name))
{
if ((0 < id) || (method->is_notification))
{
method->invoke(context, params, id);
}
break;
}
}
2019-02-17 13:31:04 +00:00
}
2019-02-24 17:03:22 +00:00
void wsfsp_provider_invoke(
struct wsfsp_invokation_context * context,
json_t * request)
2019-02-17 13:31:04 +00:00
{
2019-02-24 17:03:22 +00:00
json_t * method_holder = json_object_get(request, "method");
json_t * params = json_object_get(request, "params");
json_t * id_holder = json_object_get(request, "id");
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
if ((NULL != method_holder) && (json_is_string(method_holder)) &&
(NULL != params) && (json_is_array(params)))
{
char const * method = json_string_value(method_holder);
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
2019-02-17 13:31:04 +00:00
2019-02-24 17:03:22 +00:00
wsfsp_provider_invoke_method(context, method, params, id);
}
}
void wsfsp_connected_default(
void * user_data)
{
(void) user_data;
// empty
}
void wsfsp_disconnected_default(
void * user_data)
{
(void) user_data;
// empty
}
void wsfsp_ontimer_default(
void * user_data)
{
(void) user_data;
// empty
2019-02-24 17:03:22 +00:00
}