1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

changed credentials API

This commit is contained in:
Falk Werner
2020-02-25 22:05:48 +01:00
parent 767bafcd01
commit c6ca2e14bd
12 changed files with 140 additions and 66 deletions

View File

@@ -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);
}

View File

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

View File

@@ -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
}

View File

@@ -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));
}

View File

@@ -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

View File

@@ -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(

View File

@@ -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