Set token function

FossilOrigin-Name: 287b6cdff27bde882df7c58d26cf56878d6ac67bd78c5c9ceeec060a0269226a
This commit is contained in:
me@ow.nekobit.net 2022-02-18 19:26:10 +00:00
parent 700f676d5a
commit 607386746b
4 changed files with 18 additions and 1 deletions

View file

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

View file

@ -29,6 +29,7 @@ typedef struct mastodont
char* url;
CURL* curl;
char* token;
mstdnt_bool token_heap;
} mastodont_t;
struct mstdnt_storage

View file

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

View file

@ -1,3 +1,4 @@
#include <string.h>
#include <stdlib.h>
#include <mastodont.h>
#include <curl/curl.h>
@ -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)