mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added implementation of wf_client_add_filesystem
This commit is contained in:
parent
0c702ff25f
commit
081304dee6
@ -31,7 +31,7 @@ wf_impl_client_create(
|
||||
wf_impl_client_tlsconfig_init(&client->tls);
|
||||
client->user_data = user_data;
|
||||
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);
|
||||
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 * name)
|
||||
{
|
||||
(void) local_path;
|
||||
(void) name;
|
||||
|
||||
wf_impl_client_protocol_callback(&client->protocol, WF_CLIENT_FILESYSTEM_ADD_FAILED, NULL);
|
||||
wf_impl_client_protocol_add_filesystem(&client->protocol, local_path, name);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "webfuse/adapter/impl/client_protocol.h"
|
||||
#include "webfuse/adapter/client_callback.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/url.h"
|
||||
#include "webfuse/core/util.h"
|
||||
@ -18,6 +20,12 @@
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
struct wf_impl_client_protocol_add_filesystem_context
|
||||
{
|
||||
struct wf_client_protocol * protocol;
|
||||
char * local_path;
|
||||
};
|
||||
|
||||
static void
|
||||
wf_impl_client_protocol_process(
|
||||
struct wf_client_protocol * protocol,
|
||||
@ -68,6 +76,40 @@ wf_impl_client_protocol_on_authenticate_finished(
|
||||
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(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
@ -133,7 +175,7 @@ static int wf_impl_client_protocol_lws_callback(
|
||||
void
|
||||
wf_impl_client_protocol_init(
|
||||
struct wf_client_protocol * protocol,
|
||||
wf_client_callback_fn * callback,
|
||||
wf_client_protocol_callback_fn * callback,
|
||||
void * user_data)
|
||||
{
|
||||
protocol->is_connected = false,
|
||||
@ -141,18 +183,24 @@ wf_impl_client_protocol_init(
|
||||
protocol->wsi = NULL;
|
||||
protocol->callback = callback;
|
||||
protocol->user_data = user_data;
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL);
|
||||
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);
|
||||
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_cleanup(
|
||||
struct wf_client_protocol * protocol)
|
||||
{
|
||||
if (NULL != protocol->filesystem)
|
||||
{
|
||||
wf_impl_filesystem_dispose(protocol->filesystem);
|
||||
}
|
||||
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_CLEANUP, NULL);
|
||||
wf_jsonrpc_proxy_dispose(protocol->proxy);
|
||||
wf_timer_manager_dispose(protocol->timer_manager);
|
||||
@ -246,3 +294,30 @@ wf_impl_client_protocol_authenticate(
|
||||
|
||||
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_context;
|
||||
|
||||
struct wf_impl_filesystem;
|
||||
struct wf_jsonrpc_proxy;
|
||||
struct wf_timer_manager;
|
||||
|
||||
@ -30,7 +31,8 @@ struct wf_client_protocol
|
||||
bool is_connected;
|
||||
bool is_shutdown_requested;
|
||||
struct lws * wsi;
|
||||
wf_client_callback_fn * callback;
|
||||
wf_client_protocol_callback_fn * callback;
|
||||
struct wf_impl_filesystem * filesystem;
|
||||
void * user_data;
|
||||
struct wf_timer_manager * timer_manager;
|
||||
struct wf_jsonrpc_proxy * proxy;
|
||||
@ -40,7 +42,7 @@ struct wf_client_protocol
|
||||
extern void
|
||||
wf_impl_client_protocol_init(
|
||||
struct wf_client_protocol * protocol,
|
||||
wf_client_callback_fn * callback,
|
||||
wf_client_protocol_callback_fn * callback,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
@ -72,6 +74,12 @@ extern void
|
||||
wf_impl_client_protocol_authenticate(
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user