mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added first impression of adapter client API
This commit is contained in:
parent
adc7fa9120
commit
16996e1f9a
80
include/webfuse/adapter/client.h
Normal file
80
include/webfuse/adapter/client.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \file adapter/client.h
|
||||||
|
/// \brief Adapter client.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef WF_ADAPTER_CLIENT_H
|
||||||
|
#define WF_ADAPTER_CLIENT_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define WF_CLIENT_CREATED 0x0001
|
||||||
|
#define WF_CLIENT_DISPOSING 0x0002
|
||||||
|
|
||||||
|
#define WF_CLIENT_CONNECTED 0x0011
|
||||||
|
#define WF_CLIENT_DISCONNECTED 0x0012
|
||||||
|
|
||||||
|
#define WF_CLIENT_AUTHENTICATED 0x0021
|
||||||
|
#define WF_CLIENT_AUTHENTICATION_FAILED 0x0022
|
||||||
|
#define WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS 0x0023
|
||||||
|
|
||||||
|
#define WF_CLIENT_FILESYSTEM_ADDED 0x0031
|
||||||
|
#define WF_CLIENT_FILESYSTEM_ADD_FAILED 0x0032
|
||||||
|
|
||||||
|
struct wf_client;
|
||||||
|
|
||||||
|
typedef void wf_client_callback_fn(
|
||||||
|
struct wf_client * client,
|
||||||
|
int reason,
|
||||||
|
void * args);
|
||||||
|
|
||||||
|
extern WF_API struct wf_client *
|
||||||
|
wf_client_create(
|
||||||
|
wf_client_callback_fn * callback,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_dispose(
|
||||||
|
struct wf_client * client);
|
||||||
|
|
||||||
|
extern WF_API void *
|
||||||
|
wf_client_get_userdata(
|
||||||
|
struct wf_client * client);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_service(
|
||||||
|
struct wf_client * client);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_interrupt(
|
||||||
|
struct wf_client * client);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_connect(
|
||||||
|
struct wf_client * client,
|
||||||
|
char const * url);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_disconnect(
|
||||||
|
struct wf_client * client);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_authenticate(
|
||||||
|
struct wf_client * client);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_add_filesystem(
|
||||||
|
struct wf_client * client,
|
||||||
|
char const * local_path,
|
||||||
|
char const * name);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
28
include/webfuse/adapter/client_credentials.h
Normal file
28
include/webfuse/adapter/client_credentials.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef WF_ADAPTER_CLIENT_CREDENTIALS_H
|
||||||
|
#define WF_ADAPTER_CLIENT_CREDENTIALS_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_client_credentials;
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_credentials_set_type(
|
||||||
|
struct wf_client_credentials * credentials,
|
||||||
|
char const * type);
|
||||||
|
|
||||||
|
extern WF_API void
|
||||||
|
wf_client_credentials_add(
|
||||||
|
struct wf_client_credentials * credentials,
|
||||||
|
char const * key,
|
||||||
|
char const * value);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -17,4 +17,8 @@
|
|||||||
#include <webfuse/adapter/credentials.h>
|
#include <webfuse/adapter/credentials.h>
|
||||||
#include <webfuse/adapter/mountpoint.h>
|
#include <webfuse/adapter/mountpoint.h>
|
||||||
|
|
||||||
|
#include <webfuse/adapter/client.h>
|
||||||
|
#include <webfuse/adapter/client_credentials.h>
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -178,3 +178,101 @@ wf_mountpoint_set_userdata(
|
|||||||
{
|
{
|
||||||
wf_impl_mountpoint_set_userdata(mountpoint, user_data, dispose);
|
wf_impl_mountpoint_set_userdata(mountpoint, user_data, dispose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// client
|
||||||
|
|
||||||
|
struct wf_client *
|
||||||
|
wf_client_create(
|
||||||
|
wf_client_callback_fn * callback,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
(void) callback;
|
||||||
|
(void) user_data;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_dispose(
|
||||||
|
struct wf_client * client)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
wf_client_get_userdata(
|
||||||
|
struct wf_client * client)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_service(
|
||||||
|
struct wf_client * client)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_interrupt(
|
||||||
|
struct wf_client * client)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_connect(
|
||||||
|
struct wf_client * client,
|
||||||
|
char const * url)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
(void) url;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_disconnect(
|
||||||
|
struct wf_client * client)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_authenticate(
|
||||||
|
struct wf_client * client)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_add_filesystem(
|
||||||
|
struct wf_client * client,
|
||||||
|
char const * local_path,
|
||||||
|
char const * name)
|
||||||
|
{
|
||||||
|
(void) client;
|
||||||
|
(void) local_path;
|
||||||
|
(void) name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// client credentials
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_credentials_set_type(
|
||||||
|
struct wf_client_credentials * credentials,
|
||||||
|
char const * type)
|
||||||
|
{
|
||||||
|
(void) credentials;
|
||||||
|
(void) type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_client_credentials_add(
|
||||||
|
struct wf_client_credentials * credentials,
|
||||||
|
char const * key,
|
||||||
|
char const * value)
|
||||||
|
{
|
||||||
|
(void) credentials;
|
||||||
|
(void) key;
|
||||||
|
(void) value;
|
||||||
|
}
|
@ -250,6 +250,7 @@ alltests = executable('alltests',
|
|||||||
'test/webfuse/tests/integration/file.cc',
|
'test/webfuse/tests/integration/file.cc',
|
||||||
'test/webfuse/tests/integration/server.cc',
|
'test/webfuse/tests/integration/server.cc',
|
||||||
'test/webfuse/tests/integration/provider.cc',
|
'test/webfuse/tests/integration/provider.cc',
|
||||||
|
'test/webfuse/tests/adapter/test_client.cc',
|
||||||
link_args: [
|
link_args: [
|
||||||
'-Wl,--wrap=wf_timer_manager_create',
|
'-Wl,--wrap=wf_timer_manager_create',
|
||||||
'-Wl,--wrap=wf_timer_manager_dispose',
|
'-Wl,--wrap=wf_timer_manager_dispose',
|
||||||
|
85
test/webfuse/tests/adapter/test_client.cc
Normal file
85
test/webfuse/tests/adapter/test_client.cc
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfuse/adapter/client.h"
|
||||||
|
#include "webfuse/adapter/client_credentials.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
enum class connection_state
|
||||||
|
{
|
||||||
|
disconnected,
|
||||||
|
connected,
|
||||||
|
connecting
|
||||||
|
};
|
||||||
|
|
||||||
|
struct context
|
||||||
|
{
|
||||||
|
connection_state state;
|
||||||
|
};
|
||||||
|
|
||||||
|
void callback(
|
||||||
|
wf_client * client,
|
||||||
|
int reason,
|
||||||
|
void * args)
|
||||||
|
{
|
||||||
|
auto * ctx = reinterpret_cast<context*>(wf_client_get_userdata(client));
|
||||||
|
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case WF_CLIENT_CREATED:
|
||||||
|
ctx->state = connection_state::connecting;
|
||||||
|
wf_client_connect(client, "ws://dummy-server/");
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_CONNECTED:
|
||||||
|
ctx->state = connection_state::connected;
|
||||||
|
wf_client_authenticate(client);
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_AUTHENTICATED:
|
||||||
|
wf_client_add_filesystem(client, ".", "test");
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_AUTHENTICATION_FAILED:
|
||||||
|
wf_client_disconnect(client);
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS:
|
||||||
|
{
|
||||||
|
auto * credentials = reinterpret_cast<wf_client_credentials*>(args);
|
||||||
|
wf_client_credentials_set_type(credentials, "username");
|
||||||
|
wf_client_credentials_add(credentials, "user", "bob");
|
||||||
|
wf_client_credentials_add(credentials, "password", "secret");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_FILESYSTEM_ADDED:
|
||||||
|
// operational
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_FILESYSTEM_ADD_FAILED:
|
||||||
|
wf_client_disconnect(client);
|
||||||
|
break;
|
||||||
|
case WF_CLIENT_DISCONNECTED:
|
||||||
|
ctx->state = connection_state::disconnected;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(client, general_usage)
|
||||||
|
{
|
||||||
|
context ctx;
|
||||||
|
ctx.state = connection_state::connecting;
|
||||||
|
|
||||||
|
wf_client * client = wf_client_create(
|
||||||
|
&callback, reinterpret_cast<void*>(&ctx));
|
||||||
|
|
||||||
|
if (nullptr != client)
|
||||||
|
{
|
||||||
|
while (ctx.state != connection_state::disconnected)
|
||||||
|
{
|
||||||
|
wf_client_service(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
wf_client_dispose(client);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user