Set CURLOPT_POST/HTTPGET option to fetch

FossilOrigin-Name: 45857bed0cfcc4fa71043e75c5b193b06544bd9bbb99e4bfadb78ba07a030329
This commit is contained in:
me@ow.nekobit.net 2022-02-21 04:27:56 +00:00
parent e51a10ffc3
commit 024a584f16
6 changed files with 14 additions and 11 deletions

View file

@ -17,6 +17,7 @@
#define MASTODONT_FETCH_H
#include <cjson/cJSON.h>
#include <mastodont_types.h>
#include <curl/curl.h>
struct mstdnt_fetch_results
{
@ -27,6 +28,7 @@ struct mstdnt_fetch_results
void mastodont_fetch_results_cleanup(struct mstdnt_fetch_results* res);
int mastodont_fetch_curl(mastodont_t* mstdnt,
char* url,
struct mstdnt_fetch_results* results);
struct mstdnt_fetch_results* results,
CURLoption request_t);
#endif /* MASTODONT_FETCH_H */

View file

@ -34,7 +34,7 @@ int mastodont_account(mastodont_t* data,
id);
storage->needs_cleanup = 0;
if (mastodont_fetch_curl(data, url, &results) != CURLE_OK)
if (mastodont_fetch_curl(data, url, &results, CURLOPT_HTTPGET) != CURLE_OK)
{
return 1;
}

View file

@ -115,7 +115,7 @@ int mastodont_register_app(mastodont_t* data,
curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, post);
if (mastodont_fetch_curl(data, "api/v1/apps", &results) != CURLE_OK)
if (mastodont_fetch_curl(data, "api/v1/apps", &results, CURLOPT_HTTPGET) != CURLE_OK)
{
res = 1;
goto cleanup;
@ -183,7 +183,7 @@ int mastodont_obtain_oauth_token(mastodont_t* data,
curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, post);
if (mastodont_fetch_curl(data, "oauth/token", &results) != CURLE_OK)
if (mastodont_fetch_curl(data, "oauth/token", &results, CURLOPT_HTTPGET) != CURLE_OK)
{
res = 1;
goto cleanup;

View file

@ -47,7 +47,8 @@ void mastodont_fetch_results_cleanup(struct mstdnt_fetch_results* res)
#define TOKEN_STR_SIZE 512
int mastodont_fetch_curl(mastodont_t* mstdnt,
char* _url,
struct mstdnt_fetch_results* results)
struct mstdnt_fetch_results* results,
CURLoption request_t)
{
int res;
char token[TOKEN_STR_SIZE] = { 0 };
@ -71,6 +72,8 @@ int mastodont_fetch_curl(mastodont_t* mstdnt,
curl_easy_setopt(mstdnt->curl, CURLOPT_URL, url);
curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEDATA, results);
/* PUT, POST, GET */
curl_easy_setopt(mstdnt->curl, request_t, 1);
res = curl_easy_perform(mstdnt->curl);

View file

@ -117,7 +117,7 @@ int mastodont_account_statuses(mastodont_t* data,
}
storage->needs_cleanup = 0;
if (mastodont_fetch_curl(data, url, &results) != CURLE_OK)
if (mastodont_fetch_curl(data, url, &results, CURLOPT_HTTPGET) != CURLE_OK)
return 1;
res = mstdnt_load_statuses_from_result(statuses, storage, &results, size);
@ -184,7 +184,7 @@ int mastodont_create_status(mastodont_t* data,
curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, post);
if (mastodont_fetch_curl(data, "api/v1/statuses", &results) != CURLE_OK)
if (mastodont_fetch_curl(data, "api/v1/statuses", &results, CURLOPT_HTTPGET) != CURLE_OK)
return 1;
mastodont_fetch_results_cleanup(&results);
@ -202,11 +202,9 @@ int mastodont_favourite_status(mastodont_t* data,
storage->needs_cleanup = 0;
if (mastodont_fetch_curl(data, url, &results) != CURLE_OK)
if (mastodont_fetch_curl(data, url, &results, CURLOPT_POST) != CURLE_OK)
return 1;
/* TODO Handle errors */
mastodont_fetch_results_cleanup(&results);
return 0;
}

View file

@ -65,7 +65,7 @@ int mastodont_timeline_public(mastodont_t* data,
char* url = _mstdnt_query_string("api/v1/timelines/public", params, _mstdnt_arr_len(params));
if (mastodont_fetch_curl(data, url, &results) != CURLE_OK)
if (mastodont_fetch_curl(data, url, &results, CURLOPT_HTTPGET) != CURLE_OK)
{
res = 1;
goto cleanup;