You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
falk-werner_webfuse/lib/wsfs/adapter/authenticators.c

101 lines
2.6 KiB

#include "wsfs/adapter/authenticators.h"
#include <stddef.h>
#include <string.h>
#include "wsfs/adapter/authenticator.h"
#include "wsfs/adapter/credentials_intern.h"
static struct wsfs_authenticator * wsfs_authenticators_find(
struct wsfs_authenticators * authenticators,
char const * type)
{
struct wsfs_authenticator * result = NULL;
struct wsfs_authenticator * actual = authenticators->first;
while ((NULL == result) && (NULL != actual))
{
struct wsfs_authenticator * next = actual->next;
if (0 == strcmp(type, actual->type))
{
result = actual;
}
actual = next;
}
return result;
}
void wsfs_authenticators_init(
struct wsfs_authenticators * authenticators)
{
authenticators->first = NULL;
}
void wsfs_authenticators_cleanup(
struct wsfs_authenticators * authenticators)
{
struct wsfs_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_authenticator * next = actual->next;
wsfs_authenticator_dispose(actual);
actual = next;
}
authenticators->first = NULL;
}
void wsfs_authenticators_clone(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other)
{
wsfs_authenticators_init(other);
struct wsfs_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_authenticator * next = actual->next;
wsfs_authenticators_add(other,
actual->type, actual->authenticate, actual->user_data);
actual = next;
}
}
extern void wsfs_authenticators_move(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other)
{
other->first = authenticators->first;
authenticators->first = NULL;
}
void wsfs_authenticators_add(
struct wsfs_authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(type, authenticate, user_data);
authenticator->next = authenticators->first;
authenticators->first = authenticator;
}
bool wsfs_authenticators_authenticate(
struct wsfs_authenticators * authenticators,
struct wsfs_credentials * credentials)
{
bool result = (NULL == authenticators->first);
if (NULL != credentials)
{
struct wsfs_authenticator * authenticator = wsfs_authenticators_find(authenticators, credentials->type);
if (NULL != authenticator)
{
result = wsfs_authenticator_autenticate(authenticator, credentials);
}
}
return result;
}