diff --git a/include/webfuse/adapter/client_credentials.h b/include/webfuse/adapter/client_credentials.h deleted file mode 100644 index f673317..0000000 --- a/include/webfuse/adapter/client_credentials.h +++ /dev/null @@ -1,28 +0,0 @@ -#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 diff --git a/include/webfuse/adapter/credentials.h b/include/webfuse/adapter/credentials.h index e3e65fc..ca404f7 100644 --- a/include/webfuse/adapter/credentials.h +++ b/include/webfuse/adapter/credentials.h @@ -65,6 +65,28 @@ extern WF_API char const * wf_credentials_get( struct wf_credentials const * credentials, char const * key); +//------------------------------------------------------------------------------ +/// \brief Sets the type of the credentials. +/// +/// \param credentials Pointer to credentials object. +/// \param type Type of credentials. +//------------------------------------------------------------------------------ +extern WF_API void wf_credentials_set_type( + struct wf_credentials * credentials, + char const * type); + +//------------------------------------------------------------------------------ +/// \brief Adds an item to credentials +/// +/// \param credentials Pointer to credentials object. +/// \param key String to identify the item. +/// \param key Value of the item. +//------------------------------------------------------------------------------ +extern WF_API void wf_credentials_add( + struct wf_credentials * credentials, + char const * key, + char const * value); + #ifdef __cplusplus } #endif diff --git a/include/webfuse_adapter.h b/include/webfuse_adapter.h index da9533c..954f988 100644 --- a/include/webfuse_adapter.h +++ b/include/webfuse_adapter.h @@ -18,7 +18,6 @@ #include #include -#include #endif diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 66288e6..613aaf7 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -147,6 +147,21 @@ char const * wf_credentials_get( return wf_impl_credentials_get(credentials, key); } +void wf_credentials_set_type( + struct wf_credentials * credentials, + char const * type) +{ + wf_impl_credentials_set_type(credentials, type); +} + +void wf_credentials_add( + struct wf_credentials * credentials, + char const * key, + char const * value) +{ + wf_impl_credentials_add(credentials, key, value); +} + // mountpoint struct wf_mountpoint * @@ -255,24 +270,3 @@ wf_client_add_filesystem( (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; -} \ No newline at end of file diff --git a/lib/webfuse/adapter/impl/credentials.c b/lib/webfuse/adapter/impl/credentials.c index 040638a..d4c9461 100644 --- a/lib/webfuse/adapter/impl/credentials.c +++ b/lib/webfuse/adapter/impl/credentials.c @@ -1,6 +1,13 @@ #include "webfuse/adapter/impl/credentials.h" #include +void wf_impl_credentials_init_default( + struct wf_credentials * credentials) +{ + credentials->type = NULL; + credentials->data = json_object(); +} + void wf_impl_credentials_init( struct wf_credentials * credentials, char const * type, @@ -38,3 +45,20 @@ char const * wf_impl_credentials_get( return result; } + +void wf_impl_credentials_set_type( + struct wf_credentials * credentials, + char const * type) +{ + free(credentials->type); + credentials->type = strdup(type); +} + +void wf_impl_credentials_add( + struct wf_credentials * credentials, + char const * key, + char const * value) +{ + json_object_set_new(credentials->data, key, json_string(value)); +} + diff --git a/lib/webfuse/adapter/impl/credentials.h b/lib/webfuse/adapter/impl/credentials.h index a2cd647..59b4c0c 100644 --- a/lib/webfuse/adapter/impl/credentials.h +++ b/lib/webfuse/adapter/impl/credentials.h @@ -19,6 +19,9 @@ extern void wf_impl_credentials_init( char const * type, json_t * data); +extern void wf_impl_credentials_init_default( + struct wf_credentials * credentials); + extern void wf_impl_credentials_cleanup( struct wf_credentials * credentials); @@ -29,6 +32,15 @@ extern char const * wf_impl_credentials_get( struct wf_credentials const * credentials, char const * key); +extern void wf_impl_credentials_set_type( + struct wf_credentials * credentials, + char const * type); + +extern void wf_impl_credentials_add( + struct wf_credentials * credentials, + char const * key, + char const * value); + #ifdef __cplusplus } #endif diff --git a/test/webfuse/tests/adapter/test_client.cc b/test/webfuse/tests/adapter/test_client.cc index d972447..d64e57b 100644 --- a/test/webfuse/tests/adapter/test_client.cc +++ b/test/webfuse/tests/adapter/test_client.cc @@ -1,7 +1,7 @@ #include #include "webfuse/adapter/client.h" -#include "webfuse/adapter/client_credentials.h" +#include "webfuse/adapter/credentials.h" namespace { @@ -43,10 +43,10 @@ void callback( break; case WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS: { - auto * credentials = reinterpret_cast(args); - wf_client_credentials_set_type(credentials, "username"); - wf_client_credentials_add(credentials, "user", "bob"); - wf_client_credentials_add(credentials, "password", "secret"); + auto * credentials = reinterpret_cast(args); + wf_credentials_set_type(credentials, "username"); + wf_credentials_add(credentials, "user", "bob"); + wf_credentials_add(credentials, "password", "secret"); } break; case WF_CLIENT_FILESYSTEM_ADDED: diff --git a/test/webfuse/tests/adapter/test_credentials.cc b/test/webfuse/tests/adapter/test_credentials.cc index 88e2552..2e11a79 100644 --- a/test/webfuse/tests/adapter/test_credentials.cc +++ b/test/webfuse/tests/adapter/test_credentials.cc @@ -83,3 +83,31 @@ TEST(Credentials, FailedToGetWrongElementDataType) wf_impl_credentials_cleanup(&creds); json_decref(data); } + +TEST(Credentials, SetType) +{ + struct wf_credentials creds; + wf_impl_credentials_init_default(&creds); + + wf_credentials_set_type(&creds, "username"); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + + wf_impl_credentials_cleanup(&creds); +} + +TEST(Credentials, Add) +{ + struct wf_credentials creds; + wf_impl_credentials_init_default(&creds); + + wf_credentials_add(&creds, "a.value", "a"); + ASSERT_STREQ("a", wf_credentials_get(&creds, "a.value")); + + wf_credentials_add(&creds, "b.value", "b"); + ASSERT_STREQ("b", wf_credentials_get(&creds, "b.value")); + + wf_credentials_add(&creds, "a.value", "A"); + ASSERT_STREQ("A", wf_credentials_get(&creds, "a.value")); + + wf_impl_credentials_cleanup(&creds); +}