Compare commits

...

2 Commits

Author SHA1 Message Date
nekobit 536226e3ab Error reports
FossilOrigin-Name: 3894e3250544d5d0ec16f31e9d84cfd18df0b06373d4f2ac1c909a2718a2451a
2023-06-01 03:20:06 +00:00
nekobit cc06a401a4 Fix some sneaky bugs
FossilOrigin-Name: e1e0b85a0cc3cf2911454972747f33d5e9b09fdcd3e8d0fc324440f47ea082b7
2023-06-01 02:45:56 +00:00
1 changed files with 20 additions and 11 deletions

View File

@ -10,6 +10,7 @@
#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)
@ -161,7 +162,6 @@ 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)
if (running || nfds)
res = curl_multi_poll(mstdnt->curl, fds, nfds, 1000, &numfds);
if (res) break;
@ -184,6 +184,8 @@ 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;
@ -195,15 +197,21 @@ 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);
}
// 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);
// Call the actual callback, regardless of error
if (data->callback)
res = data->callback(results, data->callback_args);
else
res = MSTDNT_REQUEST_DONE;
cleanup_res:
/* The response of the callback is important!
@ -243,7 +251,8 @@ void
mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data)
{
mstdnt_storage_cleanup(&(data->storage));
data->data_free_cb(data->data);
if (data->data_free_cb)
data->data_free_cb(data->data);
// Cleanup
mstdnt_fetch_data_cleanup(data->fetch_data);
// Free ourself