1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/lib/webfuse_provider/impl/credentials.c

77 lines
2.0 KiB
C
Raw Normal View History

2020-06-16 21:39:45 +00:00
#include "webfuse_provider/impl/credentials.h"
2020-07-10 21:12:35 +00:00
#include "webfuse_provider/impl/json/writer.h"
2020-02-25 21:05:48 +00:00
#include <stdlib.h>
#include <string.h>
#define WFP_IMPL_CREDENTIALS_DEFAULT_SIZE 8
2020-02-25 21:05:48 +00:00
void wfp_impl_credentials_init(
struct wfp_credentials * credentials)
{
credentials->type = NULL;
credentials->size = 0;
credentials->capacity = WFP_IMPL_CREDENTIALS_DEFAULT_SIZE;
credentials->entries = malloc(sizeof(struct wfp_credentials_entry) * credentials->capacity);
2020-02-25 21:05:48 +00:00
}
void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials)
{
for(size_t i = 0; i < credentials->size; i++)
{
free(credentials->entries[i].key);
free(credentials->entries[i].value);
}
free(credentials->entries);
2020-02-25 21:05:48 +00:00
free(credentials->type);
}
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)
{
if (credentials->size >= credentials->capacity)
{
credentials->capacity *= 2;
credentials->entries = realloc(credentials->entries, sizeof(struct wfp_credentials_entry) * credentials->capacity);
}
credentials->entries[credentials->size].key = strdup(key);
credentials->entries[credentials->size].value = strdup(value);
credentials->size++;
2020-02-25 21:05:48 +00:00
}
2020-03-01 12:42:46 +00:00
2020-07-10 21:12:35 +00:00
void
wfp_impl_credentials_write(
struct wfp_json_writer * writer,
void * data)
2020-03-01 12:42:46 +00:00
{
2020-07-10 21:12:35 +00:00
struct wfp_credentials * credentials = (struct wfp_credentials *) data;
wfp_impl_json_writer_object_begin(writer);
for(size_t i = 0; i < credentials->size; i++)
2020-07-10 21:12:35 +00:00
{
wfp_impl_json_writer_object_write_string(writer,
credentials->entries[i].key,
credentials->entries[i].value);
2020-07-10 21:12:35 +00:00
}
wfp_impl_json_writer_object_end(writer);
2020-03-01 12:42:46 +00:00
}
2020-07-10 21:12:35 +00:00
char const * wfp_impl_credentials_get_type(
2020-03-01 12:42:46 +00:00
struct wfp_credentials * credentials)
{
2020-07-10 21:12:35 +00:00
return credentials->type;
2020-03-01 12:42:46 +00:00
}
2020-07-10 21:12:35 +00:00