mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
refactor: removed depencency to libjansson of credentials
This commit is contained in:
parent
e0b01cfe19
commit
7542f0bbc0
@ -4,18 +4,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WFP_IMPL_CREDENTIALS_DEFAULT_SIZE 8
|
||||
|
||||
void wfp_impl_credentials_init(
|
||||
struct wfp_credentials * credentials)
|
||||
{
|
||||
credentials->type = NULL;
|
||||
credentials->contents = json_object();
|
||||
credentials->size = 0;
|
||||
credentials->capacity = WFP_IMPL_CREDENTIALS_DEFAULT_SIZE;
|
||||
credentials->entries = malloc(sizeof(struct wfp_credentials_entry) * credentials->capacity);
|
||||
}
|
||||
|
||||
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);
|
||||
free(credentials->type);
|
||||
json_decref(credentials->contents);
|
||||
}
|
||||
|
||||
void wfp_impl_credentials_set_type(
|
||||
@ -31,7 +40,15 @@ void wfp_impl_credentials_add(
|
||||
char const * key,
|
||||
char const * value)
|
||||
{
|
||||
json_object_set_new(credentials->contents, key, json_string(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++;
|
||||
}
|
||||
|
||||
void
|
||||
@ -42,14 +59,12 @@ wfp_impl_credentials_write(
|
||||
struct wfp_credentials * credentials = (struct wfp_credentials *) data;
|
||||
|
||||
wfp_impl_json_writer_object_begin(writer);
|
||||
char const * key;
|
||||
json_t * value;
|
||||
json_t * contents = credentials->contents;
|
||||
json_object_foreach(contents, key, value)
|
||||
for(size_t i = 0; i < credentials->size; i++)
|
||||
{
|
||||
wfp_impl_json_writer_object_write_string(writer, key, json_string_value(value));
|
||||
wfp_impl_json_writer_object_write_string(writer,
|
||||
credentials->entries[i].key,
|
||||
credentials->entries[i].value);
|
||||
}
|
||||
|
||||
wfp_impl_json_writer_object_end(writer);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,12 @@
|
||||
|
||||
#include "webfuse_provider/credentials.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/proxy_intern.h"
|
||||
#include <jansson.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -12,10 +17,18 @@ extern "C"
|
||||
|
||||
struct wfp_json_writer;
|
||||
|
||||
struct wfp_credentials_entry
|
||||
{
|
||||
char * key;
|
||||
char * value;
|
||||
};
|
||||
|
||||
struct wfp_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * contents;
|
||||
struct wfp_credentials_entry * entries;
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
extern void wfp_impl_credentials_init(
|
||||
|
Loading…
Reference in New Issue
Block a user