diff --git a/include/mastodont.h b/include/mastodont.h index 7afb9f5..5e21e6e 100644 --- a/include/mastodont.h +++ b/include/mastodont.h @@ -23,6 +23,7 @@ void mastodont_global_curl_init(); void mastodont_global_curl_cleanup(); int mastodont_init(mastodont_t* data); +int mastodont_set_token(mastodont_t* data, char* token); void mastodont_free(mastodont_t* data); void mastodont_storage_cleanup(struct mstdnt_storage* storage); diff --git a/include/mastodont_types.h b/include/mastodont_types.h index 56ce1f5..c0d01db 100644 --- a/include/mastodont_types.h +++ b/include/mastodont_types.h @@ -29,6 +29,7 @@ typedef struct mastodont char* url; CURL* curl; char* token; + mstdnt_bool token_heap; } mastodont_t; struct mstdnt_storage diff --git a/src/json_helper.c b/src/json_helper.c index 24ab067..5208bb3 100644 --- a/src/json_helper.c +++ b/src/json_helper.c @@ -51,7 +51,7 @@ int _mstdnt_key_val_iter(cJSON* v, { if (strcmp(bools[i].key, v->string) == 0) { - *(bools[i].bool_ptr) = cJSON_IsTrue(v) ? cJSON_True : cJSON_False; + *(bools[i].bool_ptr) = cJSON_IsTrue(v); return 0; } } diff --git a/src/mastodont.c b/src/mastodont.c index 6eeb4da..7c1ea38 100644 --- a/src/mastodont.c +++ b/src/mastodont.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -16,12 +17,26 @@ int mastodont_init(mastodont_t* data) { data->curl = curl_easy_init(); data->token = NULL; + data->token_heap = 0; return data->curl == NULL; } +int mastodont_set_token(mastodont_t* data, char* token) +{ + char* mtoken = malloc(strlen(token)+1); + if (!mtoken) + return 1; + data->token_heap = 1; + strcpy(mtoken, token); + data->token = mtoken; + return 0; +} + void mastodont_free(mastodont_t* data) { curl_easy_cleanup(data->curl); + if (data->token_heap) + free(data->token); } void mastodont_storage_cleanup(struct mstdnt_storage* storage)