From 680b895807cf21101fec569ab1e3566c70c5aa23 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 2 Mar 2022 15:41:35 +0000 Subject: [PATCH] Cleanup functions FossilOrigin-Name: ca5cc102d373cfc3a4eca86db921e45091dd1f2fe733020910ec703e39177143 --- include/mastodont_attachment.h | 1 + include/mastodont_emoji.h | 2 ++ include/mastodont_notification.h | 5 +++-- include/mastodont_pleroma.h | 1 + include/mastodont_status.h | 2 ++ src/attachment.c | 5 +++++ src/emoji.c | 10 ++++++++++ src/pleroma.c | 6 ++++++ src/status.c | 6 ++++++ 9 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/mastodont_attachment.h b/include/mastodont_attachment.h index eee3671..1a6641e 100644 --- a/include/mastodont_attachment.h +++ b/include/mastodont_attachment.h @@ -39,6 +39,7 @@ struct mstdnt_attachment char* blurhash; }; +void cleanup_attachments(struct mstdnt_attachment* attachment); void _mstdnt_val_attachments_call(cJSON* v, void* _type); #endif /* MASTODONT_ATTACHMENT */ diff --git a/include/mastodont_emoji.h b/include/mastodont_emoji.h index c70267f..096e80b 100644 --- a/include/mastodont_emoji.h +++ b/include/mastodont_emoji.h @@ -37,6 +37,8 @@ struct mstdnt_emoji_reaction /* TODO Accounts */ }; +void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reactions); +void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions); void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type); #endif /* MASTODONT_EMOJI */ diff --git a/include/mastodont_notification.h b/include/mastodont_notification.h index 8108b82..2d05ca0 100644 --- a/include/mastodont_notification.h +++ b/include/mastodont_notification.h @@ -16,6 +16,7 @@ #ifndef MASTODONT_NOTIFICATION #define MASTODONT_NOTIFICATION #include "mastodont_types.h" +#include enum mstdnt_notification_type { @@ -39,10 +40,10 @@ struct mstdnt_notification int mastodont_notifications(mastodont_t* data, struct mstdnt_notification** notifs, - stuct mstdnt_storage* storage, + struct mstdnt_storage* storage, size_t* size); int mstdnt_load_account_from_json(struct mstdnt_notification* notif, cJSON* js); void _mstdnt_val_notifications_call(cJSON* v, void* _type); -#endif // MASTODONT_NOTIFICATION +#endif /* MASTODONT_NOTIFICATION */ diff --git a/include/mastodont_pleroma.h b/include/mastodont_pleroma.h index dd8b46a..7c95445 100644 --- a/include/mastodont_pleroma.h +++ b/include/mastodont_pleroma.h @@ -34,6 +34,7 @@ struct mstdnt_status_pleroma int thread_muted; }; +void cleanup_status_pleroma(struct mstdnt_status_pleroma* pleroma); int mstdnt_load_status_pleroma_from_json(struct mstdnt_status_pleroma* pleroma, cJSON* js); void _mstdnt_val_status_pleroma_call(cJSON* v, void* _type); diff --git a/include/mastodont_status.h b/include/mastodont_status.h index d27a7cc..22ddb48 100644 --- a/include/mastodont_status.h +++ b/include/mastodont_status.h @@ -114,6 +114,8 @@ struct mstdnt_create_status_args char* visibility; }; +void cleanup_status(struct mstdnt_status* status); + int mstdnt_load_statuses_from_result(struct mstdnt_status* status[], struct mstdnt_storage* storage, struct mstdnt_fetch_results* results, diff --git a/src/attachment.c b/src/attachment.c index 3dc2a8f..d5b8cd4 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -64,3 +64,8 @@ void _mstdnt_val_attachments_call(cJSON* v, void* _type) load_attachment_from_json((*attachments) + i, it->child); } } + +void cleanup_attachments(struct mstdnt_attachment* attachment) +{ + if (attachment) free(attachment); +} diff --git a/src/emoji.c b/src/emoji.c index 8d4c847..2e5e345 100644 --- a/src/emoji.c +++ b/src/emoji.c @@ -60,3 +60,13 @@ void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type) } } +void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reactions) +{ + /* NOP for compatibility purposes */ + return; +} + +void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions) +{ + if (reactions) free(reactions); +} diff --git a/src/pleroma.c b/src/pleroma.c index 5a07beb..b278149 100644 --- a/src/pleroma.c +++ b/src/pleroma.c @@ -47,3 +47,9 @@ void _mstdnt_val_status_pleroma_call(cJSON* v, void* _type) mstdnt_load_status_pleroma_from_json(type, v->child); } + +void cleanup_status_pleroma(struct mstdnt_status_pleroma* pleroma) +{ + cleanup_emoji_reactions(pleroma->emoji_reactions); +} + diff --git a/src/status.c b/src/status.c index de7daf2..621d93f 100644 --- a/src/status.c +++ b/src/status.c @@ -339,3 +339,9 @@ cleanup: return res; } + +void cleanup_status(struct mstdnt_status* status) +{ + cleanup_attachments(status->media_attachments); + cleanup_status_pleroma(&(status->pleroma)); +}