changed credentials API

pull/2/head
Falk Werner 4 years ago
parent 767bafcd01
commit c6ca2e14bd

@ -9,6 +9,7 @@ add_library(webfuse-provider-static STATIC
lib/webfuse/provider/impl/provider.c
lib/webfuse/provider/impl/request.c
lib/webfuse/provider/impl/dirbuffer.c
lib/webfuse/provider/impl/credentials.c
lib/webfuse/provider/impl/operation/lookup.c
lib/webfuse/provider/impl/operation/getattr.c
lib/webfuse/provider/impl/operation/readdir.c

@ -14,6 +14,7 @@
#include <webfuse/provider/operation/open.h>
#include <webfuse/provider/operation/close.h>
#include <webfuse/provider/operation/read.h>
#include <webfuse/provider/credentials.h>
#ifdef __cplusplus
extern "C"
@ -228,25 +229,15 @@ extern WFP_API void wfp_client_config_set_onread(
wfp_read_fn * handler);
//------------------------------------------------------------------------------
/// \brief Enabled authentication with username and password.
///
/// Sets username and password for built-in username authentication.
/// \brief Enabled authentication.
///
/// \param config pointer to client configuration
/// \param username pointer to username
/// \param password pointer to password
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_username_credentials(
struct wfp_client_config * config,
char const * username,
char const * password);
//------------------------------------------------------------------------------
/// \param get_credentials pointer to function providing credentials when
// needed.
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_generic_credentials(
extern WFP_API void wfp_client_config_enable_authentication(
struct wfp_client_config * config,
char const * credentials_type,
char const * contents[]);
wfp_get_credentials_fn * get_credentials);
#ifdef __cplusplus
}

@ -0,0 +1,30 @@
#ifndef WF_PROVIDER_CREDENTIALS_H
#define WF_PROVIDER_CREDENTIALS_H
#include <webfuse/provider/api.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_credentials;
typedef void wfp_get_credentials_fn(
struct wfp_credentials * credentials,
void * user_data);
extern WFP_API void wfp_credentials_set_type(
struct wfp_credentials * credentials,
char const * type);
extern WFP_API void wfp_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif
#endif

@ -14,6 +14,7 @@
#include <webfuse/provider/client_config.h>
#include <webfuse/provider/client_protocol.h>
#include <webfuse/provider/dirbuffer.h>
#include <webfuse/provider/credentials.h>
#include <webfuse/provider/operation/error.h>
#include <webfuse/provider/operation/lookup.h>

@ -11,6 +11,7 @@
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/client.h"
#include "webfuse/provider/impl/dirbuffer.h"
#include "webfuse/provider/impl/credentials.h"
// respond
@ -155,23 +156,13 @@ void wfp_client_config_set_onread(
wfp_impl_client_config_set_onread(config, handler);
}
void wfp_client_config_set_username_credentials(
void wfp_client_config_enable_authentication(
struct wfp_client_config * config,
char const * username,
char const * password)
wfp_get_credentials_fn * get_credentials)
{
wfp_impl_client_config_set_username_credentials(config, username, password);
wfp_impl_client_config_enable_authentication(config, get_credentials);
}
void wfp_client_config_set_generic_credentials(
struct wfp_client_config * config,
char const * credentials_type,
char const * contents[])
{
wfp_impl_client_config_set_generic_credentials(config, credentials_type, contents);
}
// protocol
@ -257,3 +248,20 @@ void wfp_dirbuffer_add(
{
wfp_impl_dirbuffer_add(buffer, name, inode);
}
// credentials
void wfp_credentials_set_type(
struct wfp_credentials * credentials,
char const * type)
{
wfp_impl_credentials_set_type(credentials, type);
}
void wfp_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value)
{
wfp_impl_credentials_add(credentials, key, value);
}

@ -111,28 +111,9 @@ void wfp_impl_client_config_set_onread(
config->provider.read = handler;
}
void wfp_impl_client_config_set_username_credentials(
struct wfp_client_config * config,
char const * username,
char const * password)
{
(void) config;
(void) username;
(void) password;
// ToDo: implement me
}
void wfp_impl_client_config_set_generic_credentials(
void wfp_impl_client_config_enable_authentication(
struct wfp_client_config * config,
char const * credentials_type,
char const * contents[])
wfp_get_credentials_fn * get_credentials)
{
(void) config;
(void) credentials_type;
(void) contents;
// ToDo: implement me
config->provider.get_credentials = get_credentials;
}

@ -70,15 +70,9 @@ extern void wfp_impl_client_config_set_onread(
struct wfp_client_config * config,
wfp_read_fn * handler);
extern void wfp_impl_client_config_set_username_credentials(
extern void wfp_impl_client_config_enable_authentication(
struct wfp_client_config * config,
char const * username,
char const * password);
extern void wfp_impl_client_config_set_generic_credentials(
struct wfp_client_config * config,
char const * credentials_type,
char const * contents[]);
wfp_get_credentials_fn * get_credentials);
#ifdef __cplusplus
}

@ -0,0 +1,34 @@
#include "webfuse/provider/impl/credentials.h"
#include <stdlib.h>
#include <string.h>
void wfp_impl_credentials_init(
struct wfp_credentials * credentials)
{
credentials->type = NULL;
credentials->contents = json_object();
}
void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials)
{
free(credentials->type);
json_decref(credentials->contents);
}
void wfp_impl_credentials_set_type(
struct wfp_credentials * credentials,
char const * type)
{
free(credentials->type);
credentials->type = strdup(type);
}
void wfp_impl_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value)
{
json_object_set_new(credentials->contents, key, json_string(value));
}

@ -0,0 +1,38 @@
#ifndef WF_PROVIDER_IMPL_CREDENTIALS_H
#define WF_PROVIDER_IMPL_CREDENTIALS_H
#include "webfuse/provider/credentials.h"
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_credentials
{
char * type;
json_t * contents;
};
extern void wfp_impl_credentials_init(
struct wfp_credentials * credentials);
extern void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials);
extern void wfp_impl_credentials_set_type(
struct wfp_credentials * credentials,
char const * type);
extern void wfp_impl_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif
#endif

@ -67,6 +67,7 @@ void wfp_impl_provider_init(
provider->connected = &wfp_impl_connected_default;
provider->disconnected = &wfp_impl_disconnected_default;
provider->ontimer = &wfp_impl_ontimer_default;
provider->get_credentials = NULL;
}
void wfp_impl_provider_init_from_prototype(
@ -82,6 +83,7 @@ void wfp_impl_provider_init_from_prototype(
provider->connected = prototype->connected;
provider->disconnected = prototype->disconnected;
provider->ontimer = prototype->ontimer;
provider->get_credentials = prototype->get_credentials;
}
void wfp_impl_provider_invoke(

@ -20,6 +20,7 @@ struct wfp_provider
wfp_open_fn * open;
wfp_close_fn * close;
wfp_read_fn * read;
wfp_get_credentials_fn * get_credentials;
};
struct wfp_impl_invokation_context

@ -45,13 +45,6 @@ public:
wfp_client_config_dispose(config);
}
void SetUsernameCredentials(
std::string const & username,
std::string const & password)
{
wfp_client_config_set_username_credentials(config, username.c_str(), password.c_str());
}
void Connect()
{
wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/");
@ -169,7 +162,7 @@ TEST(client_protocol, connect_with_username_authentication)
{
MockProviderClient provider;
ClientProtocolFixture fixture(provider);
fixture.SetUsernameCredentials("bob", "secret");
// ToDo: enable authentication
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
EXPECT_CALL(provider, OnDisconnected()).Times(1);

Loading…
Cancel
Save