From ac4529348dc2ad01bbabbd7de5059df569e88458 Mon Sep 17 00:00:00 2001 From: nekobit Date: Mon, 7 Nov 2022 01:59:05 +0000 Subject: [PATCH] Update statuses callback FossilOrigin-Name: 502e0482d2964dc8f934c2d5a1cbc2a9366af1691db18670c6d74db46ab2773e --- include/mastodont.h | 2 -- include/mastodont_fetch.h | 2 ++ src/fetch.c | 11 +++++++++++ src/mastodont.c | 7 ------- src/status.c | 2 ++ 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/mastodont.h b/include/mastodont.h index fe2b8e4..0836694 100644 --- a/include/mastodont.h +++ b/include/mastodont.h @@ -58,6 +58,4 @@ void mstdnt_cleanup(mastodont_t* data); */ void mstdnt_storage_cleanup(struct mstdnt_storage* storage); -void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data); - #endif /* MASTODONT_H */ diff --git a/include/mastodont_fetch.h b/include/mastodont_fetch.h index 0c4873d..cd7d915 100644 --- a/include/mastodont_fetch.h +++ b/include/mastodont_fetch.h @@ -95,4 +95,6 @@ int mstdnt_await(mastodont_t* mstdnt, struct mstdnt_fd extra_fds[], size_t nfds); +void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data); + #endif /* MASTODONT_FETCH_H */ diff --git a/src/fetch.c b/src/fetch.c index a6cd8c2..c70c3f9 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -87,6 +87,7 @@ int mstdnt_fetch_curl_async(mastodont_t* mstdnt, } results->callback = cb_request; results->callback_args = cb_args; + results->json_cb = json_cb; results->json_args = json_args; @@ -192,6 +193,7 @@ int mstdnt_await(mastodont_t* mstdnt, data->callback(&(results), data->callback_args); cleanup_res: + mstdnt_request_cb_cleanup(&results); // Cleanup mstdnt_fetch_data_cleanup(data); curl_multi_remove_handle(mstdnt->curl, msg->easy_handle); @@ -212,3 +214,12 @@ int mstdnt_await(mastodont_t* mstdnt, return res; } + +void mstdnt_storage_cleanup(struct mstdnt_storage* storage); + +void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data) +{ + mstdnt_storage_cleanup(data->storage); + //data->data_free_cb(data->data, 0); + /* free(data); */ +} diff --git a/src/mastodont.c b/src/mastodont.c index 81dbb03..74f55e0 100644 --- a/src/mastodont.c +++ b/src/mastodont.c @@ -33,10 +33,3 @@ void mstdnt_storage_cleanup(struct mstdnt_storage* storage) storage->needs_cleanup = 0; } } - -void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data) -{ - mstdnt_storage_cleanup(data->storage); - //data->data_free_cb(data->data, 0); - /* free(data); */ -} diff --git a/src/status.c b/src/status.c index e426fc8..f97ef8a 100644 --- a/src/status.c +++ b/src/status.c @@ -149,6 +149,8 @@ GENERATE_JSON_ARRAY_FUNC(mstdnt_statuses_json, struct mstdnt_status, mstdnt_stat int mstdnt_statuses_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* data) { struct mstdnt_statuses* statuses = malloc(sizeof(struct mstdnt_statuses)); + data->data = statuses; + data->data_free_cb = (data_free_cb_t)mstdnt_cleanup_statuses; return mstdnt_statuses_json(&(statuses->statuses), &(statuses->len), json); }