From 1fa14898b0bf84ed1ad67893001c9fcdbfbf7a66 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 3 Mar 2022 15:49:59 +0000 Subject: [PATCH] Cleanup arguments FossilOrigin-Name: e3a7340b33ff1af23c7f161ea5b1ca10c161e1522e9989bcb355006f38206a04 --- include/mastodont_args.h | 8 ++++++- include/mastodont_notif_types.h | 33 +++++++++++++++++++++++++++ include/mastodont_notification.h | 16 +------------- src/application.c | 26 ++-------------------- src/notification.c | 36 ++++++++++++++++++------------ src/status.c | 38 ++------------------------------ 6 files changed, 67 insertions(+), 90 deletions(-) create mode 100644 include/mastodont_notif_types.h diff --git a/include/mastodont_args.h b/include/mastodont_args.h index c9fb2eb..6318dbc 100644 --- a/include/mastodont_args.h +++ b/include/mastodont_args.h @@ -15,7 +15,7 @@ #ifndef MASTODONT_ARGUMENTS_H #define MASTODONT_ARGUMENTS_H - +#include "mastodont_notif_types.h" /* * Originally, when the arguments were being designed for each function, * I found that many REST operations tended to result similar variable names @@ -65,6 +65,12 @@ struct mstdnt_args char* visibility; int remote; int local; + char** exclude_types; + size_t exclude_types_len; + char* account_id; + char** exclude_visibilities; + size_t exclude_visibilities_len; + enum mstdnt_notification_type* include_types; }; #endif /* MASTODONT_ARGUMENTS_H */ diff --git a/include/mastodont_notif_types.h b/include/mastodont_notif_types.h new file mode 100644 index 0000000..7c16c25 --- /dev/null +++ b/include/mastodont_notif_types.h @@ -0,0 +1,33 @@ +/* + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MASTODONT_NOTIF_TYPES +#define MASTODONT_NOTIF_TYPES + +enum mstdnt_notification_type +{ + MSTDNT_NOTIFICATION_FOLLOW, + MSTDNT_NOTIFICATION_FOLLOW_REQUEST, + MSTDNT_NOTIFICATION_MENTION, + MSTDNT_NOTIFICATION_REBLOG, + MSTDNT_NOTIFICATION_FAVOURITE, + MSTDNT_NOTIFICATION_POLL, + MSTDNT_NOTIFICATION_STATUS, + MSTDNT_NOTIFICATION_EMOJI_REACT, + MSTDNT_NOTIFICATION_CHAT_MENTION, + MSTDNT_NOTIFICATION_REPORT +}; + +#endif /* MASTODONT_NOTIF_TYPES */ diff --git a/include/mastodont_notification.h b/include/mastodont_notification.h index 24fbd7d..8f09a50 100644 --- a/include/mastodont_notification.h +++ b/include/mastodont_notification.h @@ -20,20 +20,6 @@ #include "mastodont_status.h" #include -enum mstdnt_notification_type -{ - MSTDNT_NOTIFICATION_FOLLOW, - MSTDNT_NOTIFICATION_FOLLOW_REQUEST, - MSTDNT_NOTIFICATION_MENTION, - MSTDNT_NOTIFICATION_REBLOG, - MSTDNT_NOTIFICATION_FAVOURITE, - MSTDNT_NOTIFICATION_POLL, - MSTDNT_NOTIFICATION_STATUS, - MSTDNT_NOTIFICATION_EMOJI_REACT, - MSTDNT_NOTIFICATION_CHAT_MENTION, - MSTDNT_NOTIFICATION_REPORT -}; - struct mstdnt_notification { char* id; @@ -65,7 +51,7 @@ int mastodont_get_notifications(mastodont_t* data, struct mstdnt_notification** notifs, size_t* size); -int mstdnt_load_account_from_json(struct mstdnt_notification* notif, cJSON* js); +int mstdnt_load_notification_from_json(struct mstdnt_notification* notif, cJSON* js); void mstdnt_cleanup_notifications(struct mstdnt_notification* notif, size_t notif_len); void mstdnt_cleanup_notification(struct mstdnt_notification* notif); diff --git a/src/application.c b/src/application.c index 35eaefc..c8af4a1 100644 --- a/src/application.c +++ b/src/application.c @@ -76,7 +76,7 @@ static int mstdnt_read_token_result(struct mstdnt_storage* storage, int mastodont_register_app(mastodont_t* data, - struct mstdnt_app_register_args* args, + struct mstdnt_args* args, struct mstdnt_storage* storage, struct mstdnt_app* app) { @@ -84,15 +84,6 @@ int mastodont_register_app(mastodont_t* data, struct mstdnt_fetch_results results = { 0 }; /* Default args */ - struct mstdnt_app_register_args _args; - if (args == NULL) - { - _args.client_name = "mastodont-c"; /* Defaults to false */ - _args.redirect_uris = NULL; - _args.scopes = NULL; - _args.website = NULL; - args = &_args; - } storage->needs_cleanup = 0; union param_value u_client_name, u_redirect_uris, @@ -137,7 +128,7 @@ cleanup: int mastodont_obtain_oauth_token(mastodont_t* data, - struct mstdnt_oauth_token_args* args, + struct mstdnt_args* args, struct mstdnt_storage* storage, struct mstdnt_oauth_token* token) { @@ -145,19 +136,6 @@ int mastodont_obtain_oauth_token(mastodont_t* data, struct mstdnt_fetch_results results = { 0 }; /* Default args */ - struct mstdnt_oauth_token_args _args; - if (args == NULL) - { - _args.grant_type = NULL; - _args.client_id = NULL; - _args.client_secret = NULL; - _args.redirect_uri = NULL; - _args.scope = NULL; - _args.code = NULL; - _args.username = NULL; - _args.password = NULL; - args = &_args; - } storage->needs_cleanup = 0; union param_value u_grant_type, u_client_id, diff --git a/src/notification.c b/src/notification.c index b42e7e4..231a2cc 100644 --- a/src/notification.c +++ b/src/notification.c @@ -13,7 +13,11 @@ * along with this program. If not, see . */ +#include #include +#include +#include +#include int mastodont_get_notifications(mastodont_t* data, struct mstdnt_get_notifications_args* args, @@ -27,20 +31,24 @@ int mastodont_get_notifications(mastodont_t* data, /* Default args */ storage->needs_cleanup = 0; - union param_value - u_account_id = args->account_id, - u_with_muted = args->with_muted, - u_max_id = args->max_id, - u_min_id = args->min_id, - u_since_id = args->since_id, - u_offset = args->offset, - u_limit = args->limit; + union param_value u_account_id, u_with_muted, u_max_id, + u_min_id, u_since_id, u_offset, u_limit; + u_account_id.s = args->account_id; + u_with_muted.i = args->with_muted; + u_max_id.s = args->max_id; + u_min_id.s = args->min_id; + u_since_id.s = args->since_id; + u_offset.i = args->offset; + u_limit.i = args->limit; struct _mstdnt_query_param params[] = { - { _MSTDNT_QUERY_STRING, "client_name", u_client_name }, - { _MSTDNT_QUERY_STRING, "redirect_uris", u_redirect_uris }, - { _MSTDNT_QUERY_STRING, "scopes", u_scopes }, - { _MSTDNT_QUERY_STRING, "website", u_website }, + { _MSTDNT_QUERY_STRING, "account_id", u_account_id }, + { _MSTDNT_QUERY_INT, "with_muted", u_with_muted }, + { _MSTDNT_QUERY_STRING, "max_id", u_max_id }, + { _MSTDNT_QUERY_STRING, "min_id", u_min_id }, + { _MSTDNT_QUERY_STRING, "since_id", u_since_id }, + { _MSTDNT_QUERY_INT, "offset", u_offset }, + { _MSTDNT_QUERY_INT, "limit", u_limit }, }; char* post = _mstdnt_query_string(NULL, params, _mstdnt_arr_len(params)); @@ -60,7 +68,7 @@ int mastodont_get_notifications(mastodont_t* data, } */ - res = mstdnt_read_app_result(storage, &results, app); +/* res = mstdnt_read_app_result(storage, &results, app);*/ cleanup_fetch: mastodont_fetch_results_cleanup(&results); @@ -69,7 +77,7 @@ cleanup: return res; } -int mstdnt_load_account_from_json(struct mstdnt_notification* notif, cJSON* js) +int mstdnt_load_notification_from_json(struct mstdnt_notification* notif, cJSON* js) { } diff --git a/src/status.c b/src/status.c index 3296a9e..a6b8756 100644 --- a/src/status.c +++ b/src/status.c @@ -110,7 +110,7 @@ int mstdnt_load_statuses_from_result(struct mstdnt_status* statuses[], int mastodont_account_statuses(mastodont_t* data, char* id, - struct mstdnt_account_statuses_args* args, + struct mstdnt_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* size) @@ -121,22 +121,6 @@ int mastodont_account_statuses(mastodont_t* data, snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/statuses", id); /* Default args */ - struct mstdnt_account_statuses_args _args; - if (args == NULL) - { - _args.pinned = 0; - _args.tagged = NULL; - _args.with_muted = 1; - _args.offset = 0; - _args.exclude_reblogs = 0; - _args.exclude_replies = 0; - _args.only_media = 0; - _args.max_id = NULL; - _args.since_id = NULL; - _args.min_id = NULL; - _args.limit = 20; - args = &_args; - } storage->needs_cleanup = 0; if (mastodont_fetch_curl(data, url, &results, CURLOPT_HTTPGET) != CURLE_OK) @@ -150,7 +134,7 @@ int mastodont_account_statuses(mastodont_t* data, } int mastodont_create_status(mastodont_t* data, - struct mstdnt_create_status_args* args, + struct mstdnt_args* args, struct mstdnt_storage* storage) { int res = 0; @@ -158,24 +142,6 @@ int mastodont_create_status(mastodont_t* data, struct mstdnt_fetch_results results = { 0 }; /* Default args */ - struct mstdnt_create_status_args _args; - if (args == NULL) - { - _args.content_type = "html"; /* TODO */ - _args.expires_in = 0; - _args.in_reply_to_conversation_id = NULL; - _args.in_reply_to_id = NULL; - _args.language = NULL; - _args.media_ids = NULL; - _args.poll = NULL; - _args.preview = 0; - _args.scheduled_at = NULL; - _args.sensitive = 0; - _args.spoiler_text = NULL; - _args.status = NULL; - _args.visibility = "public"; - args = &_args; - } storage->needs_cleanup = 0; union param_value u_content_type, u_expires_in,