added implementation of wf_client_add_filesystem

pull/77/head
Falk Werner 4 years ago
parent 0c702ff25f
commit 081304dee6

@ -31,7 +31,7 @@ wf_impl_client_create(
wf_impl_client_tlsconfig_init(&client->tls); wf_impl_client_tlsconfig_init(&client->tls);
client->user_data = user_data; client->user_data = user_data;
wf_impl_client_protocol_init(&client->protocol, wf_impl_client_protocol_init(&client->protocol,
(wf_client_callback_fn*) callback, (void*) client); (wf_client_protocol_callback_fn*) callback, (void*) client);
memset(client->protocols, 0, sizeof(struct lws_protocols) * WF_CLIENT_PROTOCOL_COUNT); memset(client->protocols, 0, sizeof(struct lws_protocols) * WF_CLIENT_PROTOCOL_COUNT);
wf_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); wf_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
@ -123,8 +123,5 @@ wf_impl_client_add_filesystem(
char const * local_path, char const * local_path,
char const * name) char const * name)
{ {
(void) local_path; wf_impl_client_protocol_add_filesystem(&client->protocol, local_path, name);
(void) name;
wf_impl_client_protocol_callback(&client->protocol, WF_CLIENT_FILESYSTEM_ADD_FAILED, NULL);
} }

@ -1,6 +1,8 @@
#include "webfuse/adapter/impl/client_protocol.h" #include "webfuse/adapter/impl/client_protocol.h"
#include "webfuse/adapter/client_callback.h" #include "webfuse/adapter/client_callback.h"
#include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/credentials.h"
#include "webfuse/adapter/impl/filesystem.h"
#include "webfuse/adapter/impl/mountpoint.h"
#include "webfuse/core/protocol_names.h" #include "webfuse/core/protocol_names.h"
#include "webfuse/core/url.h" #include "webfuse/core/url.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
@ -18,6 +20,12 @@
#define WF_DEFAULT_TIMEOUT (10 * 1000) #define WF_DEFAULT_TIMEOUT (10 * 1000)
struct wf_impl_client_protocol_add_filesystem_context
{
struct wf_client_protocol * protocol;
char * local_path;
};
static void static void
wf_impl_client_protocol_process( wf_impl_client_protocol_process(
struct wf_client_protocol * protocol, struct wf_client_protocol * protocol,
@ -68,6 +76,40 @@ wf_impl_client_protocol_on_authenticate_finished(
protocol->callback(protocol->user_data, reason, NULL); protocol->callback(protocol->user_data, reason, NULL);
} }
static void
wf_impl_client_protocol_on_add_filesystem_finished(
void * user_data,
json_t const * result,
json_t const * WF_UNUSED_PARAM(error))
{
struct wf_impl_client_protocol_add_filesystem_context * context = user_data;
struct wf_client_protocol * protocol = context->protocol;
int reason = WF_CLIENT_FILESYSTEM_ADD_FAILED;
if (NULL == protocol->filesystem)
{
json_t * id = json_object_get(result, "id");
if (json_is_string(id))
{
char const * name = json_string_value(id);
struct wf_mountpoint * mountpoint = wf_mountpoint_create(context->local_path);
protocol->filesystem = wf_impl_filesystem_create(protocol->wsi,protocol->proxy, name, mountpoint);
if (NULL != protocol->filesystem)
{
reason = WF_CLIENT_FILESYSTEM_ADDED;
}
else
{
wf_mountpoint_dispose(mountpoint);
}
}
}
free(context->local_path);
free(context);
protocol->callback(protocol->user_data, reason, NULL);
}
static int wf_impl_client_protocol_lws_callback( static int wf_impl_client_protocol_lws_callback(
struct lws * wsi, struct lws * wsi,
enum lws_callback_reasons reason, enum lws_callback_reasons reason,
@ -133,7 +175,7 @@ static int wf_impl_client_protocol_lws_callback(
void void
wf_impl_client_protocol_init( wf_impl_client_protocol_init(
struct wf_client_protocol * protocol, struct wf_client_protocol * protocol,
wf_client_callback_fn * callback, wf_client_protocol_callback_fn * callback,
void * user_data) void * user_data)
{ {
protocol->is_connected = false, protocol->is_connected = false,
@ -141,18 +183,24 @@ wf_impl_client_protocol_init(
protocol->wsi = NULL; protocol->wsi = NULL;
protocol->callback = callback; protocol->callback = callback;
protocol->user_data = user_data; protocol->user_data = user_data;
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL); protocol->filesystem = NULL;
wf_slist_init(&protocol->messages); wf_slist_init(&protocol->messages);
protocol->timer_manager = wf_timer_manager_create(); 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); protocol->proxy = wf_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_client_protocol_send, protocol);
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL);
} }
void void
wf_impl_client_protocol_cleanup( wf_impl_client_protocol_cleanup(
struct wf_client_protocol * protocol) struct wf_client_protocol * protocol)
{ {
if (NULL != protocol->filesystem)
{
wf_impl_filesystem_dispose(protocol->filesystem);
}
protocol->callback(protocol->user_data, WF_CLIENT_CLEANUP, NULL); protocol->callback(protocol->user_data, WF_CLIENT_CLEANUP, NULL);
wf_jsonrpc_proxy_dispose(protocol->proxy); wf_jsonrpc_proxy_dispose(protocol->proxy);
wf_timer_manager_dispose(protocol->timer_manager); wf_timer_manager_dispose(protocol->timer_manager);
@ -246,3 +294,30 @@ wf_impl_client_protocol_authenticate(
wf_impl_credentials_cleanup(&creds); wf_impl_credentials_cleanup(&creds);
} }
void
wf_impl_client_protocol_add_filesystem(
struct wf_client_protocol * protocol,
char const * local_path,
char const * name)
{
if (NULL == protocol->filesystem)
{
struct wf_impl_client_protocol_add_filesystem_context * context = malloc(sizeof(struct wf_impl_client_protocol_add_filesystem_context));
context->protocol = protocol;
context->local_path = strdup(local_path);
wf_jsonrpc_proxy_invoke(
protocol->proxy,
&wf_impl_client_protocol_on_add_filesystem_finished,
context,
"add_filesystem",
"s",
name);
}
else
{
protocol->callback(protocol->user_data, WF_CLIENT_FILESYSTEM_ADD_FAILED, NULL);
}
}

@ -16,6 +16,7 @@ extern "C"
struct lws_protocols; struct lws_protocols;
struct lws_context; struct lws_context;
struct wf_impl_filesystem;
struct wf_jsonrpc_proxy; struct wf_jsonrpc_proxy;
struct wf_timer_manager; struct wf_timer_manager;
@ -30,7 +31,8 @@ struct wf_client_protocol
bool is_connected; bool is_connected;
bool is_shutdown_requested; bool is_shutdown_requested;
struct lws * wsi; struct lws * wsi;
wf_client_callback_fn * callback; wf_client_protocol_callback_fn * callback;
struct wf_impl_filesystem * filesystem;
void * user_data; void * user_data;
struct wf_timer_manager * timer_manager; struct wf_timer_manager * timer_manager;
struct wf_jsonrpc_proxy * proxy; struct wf_jsonrpc_proxy * proxy;
@ -40,7 +42,7 @@ struct wf_client_protocol
extern void extern void
wf_impl_client_protocol_init( wf_impl_client_protocol_init(
struct wf_client_protocol * protocol, struct wf_client_protocol * protocol,
wf_client_callback_fn * callback, wf_client_protocol_callback_fn * callback,
void * user_data); void * user_data);
extern void extern void
@ -72,6 +74,12 @@ extern void
wf_impl_client_protocol_authenticate( wf_impl_client_protocol_authenticate(
struct wf_client_protocol * protocol); struct wf_client_protocol * protocol);
extern void
wf_impl_client_protocol_add_filesystem(
struct wf_client_protocol * protocol,
char const * local_path,
char const * name);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

Loading…
Cancel
Save