Compare commits

..

No commits in common. "536226e3ab5e041c8e2af9a2540174e2e8fbf4c9" and "61f9697250407eef6f12ab425fc54be1e9a1261f" have entirely different histories.

View file

@ -10,7 +10,6 @@
#include <mastodont_hooks.h>
#include <mastodont_fetch.h>
#include <mastodont_json_helper.h>
#include <mastodont_error.h>
/* For use with libcurl */
size_t mstdnt_curl_write_callback(char* ptr, size_t _size, size_t nmemb, void* _content)
@ -162,6 +161,7 @@ int mstdnt_await(mastodont_t* mstdnt,
// Data used with response, must keep it with request
struct mstdnt_fetch_data* data;
// Data that the user will work with
mstdnt_request_cb_data* results = calloc(1, sizeof(mstdnt_request_cb_data));
// Check if our socket is done
// BUG: Reusing data structures if multiple transfers in place
@ -170,7 +170,7 @@ int mstdnt_await(mastodont_t* mstdnt,
// TODO error check
res = curl_multi_perform(mstdnt->curl, &running);
if (running || nfds)
if (running)
res = curl_multi_poll(mstdnt->curl, fds, nfds, 1000, &numfds);
if (res) break;
@ -184,8 +184,6 @@ int mstdnt_await(mastodont_t* mstdnt,
// Get easy info
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &data);
// Setup
mstdnt_request_cb_data* results = calloc(1, sizeof(mstdnt_request_cb_data));
results->fetch_data = data; // So we can clean it up
results->storage.needs_cleanup = 0;
@ -197,21 +195,15 @@ int mstdnt_await(mastodont_t* mstdnt,
res = 1;
goto cleanup_res;
}
if (!mstdnt_check_error(&results->storage))
{
// Pass data to json callback, so it can store it's data
if (data->json_cb)
res = data->json_cb(results->storage.root,
data->json_args,
results);
}
// Call the actual callback, regardless of error
if (data->callback)
res = data->callback(results, data->callback_args);
else
res = MSTDNT_REQUEST_DONE;
// Pass data to json callback, so it can store it's data
if (data->json_cb)
res = data->json_cb(results->storage.root,
data->json_args,
results);
// Call the actual callback
res = data->callback(results, data->callback_args);
cleanup_res:
/* The response of the callback is important!
@ -251,8 +243,7 @@ void
mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data)
{
mstdnt_storage_cleanup(&(data->storage));
if (data->data_free_cb)
data->data_free_cb(data->data);
data->data_free_cb(data->data);
// Cleanup
mstdnt_fetch_data_cleanup(data->fetch_data);
// Free ourself