FossilOrigin-Name: 354ea893739bc2cb61c37379b8e5a76e63343173b004f416388a66e319bbfbac
This commit is contained in:
nekobit 2022-11-04 18:11:59 +00:00
parent 9f82057f99
commit 38de5f2392
4 changed files with 19 additions and 12 deletions

View file

@ -25,8 +25,6 @@ struct mstdnt_fetch_data
char* response;
size_t size;
struct mstdnt_storage storage;
// Callback from user
mstdnt_request_cb_t callback;
void* callback_args;

View file

@ -290,7 +290,7 @@ int mstdnt_get_favourites(mastodont_t* data,
size_t* size);
int mstdnt_statuses_json_callback(cJSON* json, void** _args);
int mstdnt_status_json_callback(cJSON* json, void** status);
int mstdnt_status_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* results);
int mstdnt_status_context_json_callback(cJSON* json, void** _args);
#endif /* MASTODONT_STATUS */

View file

@ -155,7 +155,7 @@ int mstdnt_await(mastodont_t* mstdnt,
struct mstdnt_fetch_data* data;
cJSON* root;
struct mstdnt_storage storage = { 0 };
struct mstdnt_fetch_data* results;
mstdnt_request_cb_data results = { 0 };
int numfds;
int running = 1;
@ -172,9 +172,9 @@ int mstdnt_await(mastodont_t* mstdnt,
{
// Get easy info
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &data);
/* Zero out */
memset(&(data->storage), 0, sizeof(struct mstdnt_storage));
data->storage.needs_cleanup = 0;
// Setup
storage.needs_cleanup = 0;
// Fill in results
// Get json
if (_mstdnt_json_init(&root, data, &storage))
@ -183,9 +183,12 @@ int mstdnt_await(mastodont_t* mstdnt,
goto cleanup_res;
}
void** json_cb_res;
// Setup callback results
results.storage = &storage;
// Yeah, it's like that sometimes... :')
if (data->json_cb)
res = data->json_cb(storage.root, data->json_args);
res = data->json_cb(storage.root, data->json_args, &results);
data->callback(NULL, data->callback_args);
@ -201,6 +204,11 @@ int mstdnt_await(mastodont_t* mstdnt,
}
while (/* opt == MSTDNT_AWAIT_ALL && msgs_left */ running);
// Put revents back for callee
if (extra_fds)
for (int i = 0; i < nfds; ++i)
extra_fds[i].revents = fds[i].revents;
free(fds);
return res;

View file

@ -132,10 +132,11 @@ int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
return 0;
}
int mstdnt_status_json_callback(cJSON* json, void** _args)
int mstdnt_status_json_callback(cJSON* json, void* args, mstdnt_request_cb_data data)
{
// No arguments passed for statuses
(void)_args;
struct mstdnt_status* status = malloc(sizeof(struct mstdnt_status));
*_args = status;
return mstdnt_status_json(status, json->child);
}
@ -145,7 +146,7 @@ GENERATE_JSON_ARRAY_FUNC(mstdnt_statuses_json, struct mstdnt_status, mstdnt_stat
int mstdnt_statuses_json_callback(cJSON* json, void** _args)
{
struct mstdnt_statuses* statuses = malloc(sizeof(struct mstdnt_statuses));
*_args = statuses;
*_args = (void*)statuses;
return mstdnt_statuses_json(&(statuses->statuses), &(statuses->len), json);
}