From d4041fc030f02684f0687c2625608cd3c75a0fce Mon Sep 17 00:00:00 2001 From: nekobit Date: Thu, 10 Nov 2022 17:56:59 +0000 Subject: [PATCH] Don't cleanup request if callback returns MSTDNT_REQUEST_DATA_NOCLEANUP FossilOrigin-Name: 81eb1de23d8b624fff721958ccc7506ca427bfc92214ea8f3ce388d3c5221b2e --- include/mastodont_account.h | 8 ++++---- include/mastodont_types.h | 13 +++++++++++-- src/fetch.c | 11 +++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/mastodont_account.h b/include/mastodont_account.h index 497b67a..5fc920c 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -31,13 +31,13 @@ struct _mstdnt_accounts_args size_t* size; }; -struct mstdnt_accounts +typedef struct mstdnt_accounts { struct mstdnt_account* accts; size_t len; -}; +} mstdnt_accounts; -struct mstdnt_account +typedef struct mstdnt_account { char* id; char* username; @@ -71,7 +71,7 @@ struct mstdnt_account /* struct mstdnt_source* source */ mstdnt_bool suspended; char* mute_expires_at; -}; +} mstdnt_account; struct mstdnt_account_args { diff --git a/include/mastodont_types.h b/include/mastodont_types.h index da9c4bc..0c8a9ac 100644 --- a/include/mastodont_types.h +++ b/include/mastodont_types.h @@ -30,15 +30,24 @@ typedef int8_t mstdnt_bool; struct mstdnt_storage; -// Only god knows typedef void (*mstdnt_data_free_cb_t)(void*, size_t); -typedef void (*mstdnt_request_cb_t)(void* data, void* args); + typedef struct mstdnt_request_cb_data { struct mstdnt_storage* storage; void* data; mstdnt_data_free_cb_t data_free_cb; } mstdnt_request_cb_data; +typedef void (*mstdnt_request_cb_t)(mstdnt_request_cb_data* data, void* args); + +// Return types for mstdnt_request_cb_t, specifies +// what we want to do with the data +typedef enum mstdnt_enum_req +{ + MSTDNT_REQUEST_DONE = 0, + MSTDNT_REQUEST_DATA_NOCLEANUP = 1, +} mstdnt_enum_req; + #define MSTDNT_CB_DATA(_data) (_data->data) #define MSTDNT_FLAG_NO_URI_SANITIZE (1<<0) #define MSTDNT_FLAG_SSL_UNVERIFIED (1<<1) diff --git a/src/fetch.c b/src/fetch.c index c70c3f9..10a4973 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -190,12 +190,15 @@ int mstdnt_await(mastodont_t* mstdnt, if (data->json_cb) res = data->json_cb(storage.root, data->json_args, &results); - data->callback(&(results), data->callback_args); + res = data->callback(&(results), data->callback_args); cleanup_res: - mstdnt_request_cb_cleanup(&results); - // Cleanup - mstdnt_fetch_data_cleanup(data); + if (res != MSTDNT_REQUEST_DATA_NOCLEANUP) + { + mstdnt_request_cb_cleanup(&results); + // Cleanup + mstdnt_fetch_data_cleanup(data); + } curl_multi_remove_handle(mstdnt->curl, msg->easy_handle); curl_easy_cleanup(msg->easy_handle); }