From 38de5f239246183d54f21df457e9c99dd200d0f4 Mon Sep 17 00:00:00 2001 From: nekobit Date: Fri, 4 Nov 2022 18:11:59 +0000 Subject: [PATCH] Progress FossilOrigin-Name: 354ea893739bc2cb61c37379b8e5a76e63343173b004f416388a66e319bbfbac --- include/mastodont_fetch.h | 2 -- include/mastodont_status.h | 2 +- src/fetch.c | 20 ++++++++++++++------ src/status.c | 7 ++++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/mastodont_fetch.h b/include/mastodont_fetch.h index b1c4fd7..2de0dff 100644 --- a/include/mastodont_fetch.h +++ b/include/mastodont_fetch.h @@ -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; diff --git a/include/mastodont_status.h b/include/mastodont_status.h index e0ffa7b..09390f3 100644 --- a/include/mastodont_status.h +++ b/include/mastodont_status.h @@ -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 */ diff --git a/src/fetch.c b/src/fetch.c index 0d1adb2..7d73ea3 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -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; diff --git a/src/status.c b/src/status.c index efdd9c3..c87eda1 100644 --- a/src/status.c +++ b/src/status.c @@ -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); }