diff --git a/include/mastodont_types.h b/include/mastodont_types.h index b0d5782..e266585 100644 --- a/include/mastodont_types.h +++ b/include/mastodont_types.h @@ -32,6 +32,7 @@ typedef void (*mstdnt_request_cb_t)(void* data, void* args); #define MSTDNT_FLAG_NO_URI_SANITIZE (1<<0) #define MSTDNT_FLAG_SSL_UNVERIFIED (1<<1) +#define MSTDNT_FLAG_SYNC (1<<2) #define MSTDNT_FLAG_ISSET(flags, flag) (((flags) & (flag)) == (flag)) #define MSTDNT_T_FLAG_ISSET(flag_ref, flag) (((flag_ref->flags) & (flag)) == (flag)) diff --git a/src/request.c b/src/request.c index afb17b4..9260370 100644 --- a/src/request.c +++ b/src/request.c @@ -71,6 +71,58 @@ static void mime_params_post(curl_mime* mime, } +static mstdnt_sync_request(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_request_args* args, + struct mstdnt_storage* storage, + mstdnt_request_cb_t cb_request, + void* cb_args, + CURL* curl, + char* url_query) +{ + + int res = 0, curlerror = 0; + cJSON* root; + struct mstdnt_fetch_results results = { 0 }; + curlerror = mstdnt_fetch_curl(data, + curl, + m_args, + url_query, + &results, + args->request_type, + args->request_type_custom); + + if (curlerror != CURLE_OK) + { + res = 1; + storage->error = (char*)curl_easy_strerror(curlerror); + goto cleanup; + } + + // Create json structure + if (_mstdnt_json_init(&root, &results, storage)) + { + res = 1; + goto cleanup_res; + } + + // Make sure there is no error + if (!mstdnt_check_error(storage)) + { + /* Call our callback and do the large work */ + if (args->callback) res = args->callback(storage->root, args->args); + } + else + res = 1; + +cleanup_res: + mstdnt_fetch_results_cleanup(&results); +cleanup: + // Note: the fetch removed the handle from our multi handle + curl_easy_cleanup(curl); + return res; +} + int mstdnt_request(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_request_cb_t cb_request,