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