From fc1292ea4b9306d8f52b6fe985e303695567c677 Mon Sep 17 00:00:00 2001 From: nekobit Date: Thu, 23 Jun 2022 21:45:33 +0000 Subject: [PATCH] Refactor FossilOrigin-Name: 149127123e9ac46c8ea98c76335f9c288f339a69769317c4dee3ea560f7bbca6 --- include/mastodont.h | 3 +- include/mastodont_account.h | 24 +++++++---- include/mastodont_application.h | 27 ++++++++++--- include/mastodont_attachment.h | 3 +- include/mastodont_list.h | 24 +++++++---- include/mastodont_notification.h | 4 +- include/mastodont_scrobbles.h | 3 +- include/mastodont_search.h | 3 +- include/mastodont_static.h | 6 ++- include/mastodont_status.h | 52 +++++++++++++++++------- include/mastodont_timeline.h | 15 ++++--- src/account.c | 36 ++++++++++------- src/application.c | 14 ++++--- src/attachment.c | 5 ++- src/list.c | 35 +++++++++------- src/mastodont.c | 2 +- src/nodeinfo.c | 5 ++- src/notification.c | 5 ++- src/request.c | 4 +- src/scrobbles.c | 5 ++- src/search.c | 5 ++- src/static.c | 20 +++++++-- src/status.c | 69 +++++++++++++++++++------------- src/timeline.c | 25 +++++++----- 24 files changed, 255 insertions(+), 139 deletions(-) diff --git a/include/mastodont.h b/include/mastodont.h index 058e906..aad5e0d 100644 --- a/include/mastodont.h +++ b/include/mastodont.h @@ -32,8 +32,7 @@ void mastodont_global_curl_init(); void mastodont_global_curl_cleanup(); -int mastodont_init(mastodont_t* data, uint16_t flags); -int mastodont_set_token(mastodont_t* data, char* token); +int mastodont_init(mastodont_t* data); void mastodont_cleanup(mastodont_t* data); void mastodont_free(void*); diff --git a/include/mastodont_account.h b/include/mastodont_account.h index d0ab056..c9dd966 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -76,7 +76,8 @@ struct mstdnt_account_args int with_relationships; // mastodont_get_mutes }; -int mstdnt_account_action(mastodont_t* data, struct mstdnt_args* args, +int mstdnt_account_action(mastodont_t* data, + struct mstdnt_args* args, char* id, struct mstdnt_storage* storage, struct mstdnt_relationship* rel, @@ -88,7 +89,7 @@ int mstdnt_accounts_json(struct mstdnt_account* accounts[], #define MSTDNT_ACCOUNT_ACTION_DECL(type) int mastodont_##type##_account(mastodont_t* data, struct mstdnt_args* args, char* id, struct mstdnt_storage* storage, struct mstdnt_relationship* relationship) #define MSTDNT_ACCOUNT_ACTION_FUNC_URL(action) { \ - return mstdnt_account_action(data, id, storage, relationship, "api/v1/accounts/%s/" action); \ + return mstdnt_account_action(data, args, id, storage, relationship, "api/v1/accounts/%s/" action); \ } MSTDNT_ACCOUNT_ACTION_DECL(follow); @@ -100,35 +101,42 @@ MSTDNT_ACCOUNT_ACTION_DECL(unblock); MSTDNT_ACCOUNT_ACTION_DECL(subscribe); MSTDNT_ACCOUNT_ACTION_DECL(unsubscribe); -int mastodont_verify_credentials(mastodont_t* data, struct mstdnt_args* args, +int mastodont_verify_credentials(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_account* acct, struct mstdnt_storage* storage); -int mastodont_get_account(mastodont_t* data, struct mstdnt_args* args, + +int mastodont_get_account(mastodont_t* data, + struct mstdnt_args* m_args, int lookup_type, char* id, struct mstdnt_account* acct, struct mstdnt_storage* storage); -int mastodont_get_blocks(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_blocks(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_account_args* args, struct mstdnt_storage* storage, struct mstdnt_account* accts[], size_t* accts_len); -int mastodont_get_mutes(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_mutes(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_account_args* args, struct mstdnt_storage* storage, struct mstdnt_account* accts[], size_t* accts_len); -int mastodont_get_followers(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_followers(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_args* args, struct mstdnt_storage* storage, struct mstdnt_account* accts[], size_t* accts_len); -int mastodont_get_following(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_following(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_args* args, struct mstdnt_storage* storage, diff --git a/include/mastodont_application.h b/include/mastodont_application.h index cd80923..b77ab05 100644 --- a/include/mastodont_application.h +++ b/include/mastodont_application.h @@ -16,7 +16,6 @@ #ifndef MASTODONT_APPLICATION #define MASTODONT_APPLICATION #include "mastodont_types.h" -#include "mastodont_args.h" #include "mastodont_fetch.h" #include @@ -48,13 +47,31 @@ struct mstdnt_oauth_token time_t time; }; -int mastodont_register_app(mastodont_t* data, struct mstdnt_args* args, - struct mstdnt_args* args, +struct mstdnt_application_args +{ + char* grant_type; + char* client_id; + char* client_secret; + char* redirect_uri; + char* scope; + char* code; + char* username; + char* password; + char* client_name; + char* redirect_uris; + char* scopes; + char* website; +}; + +int mastodont_register_app(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_application_args* args, struct mstdnt_storage* storage, struct mstdnt_app* app); -int mastodont_obtain_oauth_token(mastodont_t* data, struct mstdnt_args* args, - struct mstdnt_args* args, +int mastodont_obtain_oauth_token(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_application_args* args, struct mstdnt_storage* storage, struct mstdnt_oauth_token* app); diff --git a/include/mastodont_attachment.h b/include/mastodont_attachment.h index ec0a9cf..7e62474 100644 --- a/include/mastodont_attachment.h +++ b/include/mastodont_attachment.h @@ -51,7 +51,8 @@ int mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att); void _mstdnt_val_attachments_call(cJSON* v, void* _type); -int mastodont_upload_media(mastodont_t* api, struct mstdnt_args* args, +int mastodont_upload_media(mastodont_t* api, + struct mstdnt_args* m_args, struct mstdnt_upload_media_args* args, struct mstdnt_storage* storage, struct mstdnt_attachment* attachment); diff --git a/include/mastodont_list.h b/include/mastodont_list.h index b20bb75..35d866d 100644 --- a/include/mastodont_list.h +++ b/include/mastodont_list.h @@ -49,45 +49,53 @@ int mstdnt_lists_json(struct mstdnt_list* lists[], size_t* size, cJSON* json); -int mastodont_get_lists(mastodont_t* api, struct mstdnt_args* args, +int mastodont_get_lists(mastodont_t* api, + struct mstdnt_args* m_args, struct mstdnt_storage* storage, struct mstdnt_list* lists[], size_t* size); -int mastodont_get_list(mastodont_t* api, struct mstdnt_args* args, +int mastodont_get_list(mastodont_t* api, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_list* lists); -int mastodont_create_list(mastodont_t* api, struct mstdnt_args* args, +int mastodont_create_list(mastodont_t* api, + struct mstdnt_args* m_args, struct mstdnt_list_args* args, struct mstdnt_storage* storage, struct mstdnt_list* list); -int mastodont_update_list(mastodont_t* api, struct mstdnt_args* args, +int mastodont_update_list(mastodont_t* api, + struct mstdnt_args* m_args, char* id, struct mstdnt_list_args* args, struct mstdnt_storage* storage, struct mstdnt_list* list); -int mastodont_delete_list(mastodont_t* api, struct mstdnt_args* args, +int mastodont_delete_list(mastodont_t* api, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage); -int mastodont_list_get_accounts(mastodont_t* data, struct mstdnt_args* args, +int mastodont_list_get_accounts(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_args* args, struct mstdnt_storage* storage, struct mstdnt_account* accts[], size_t* accts_len); -int mastodont_list_add_accounts(mastodont_t* api, struct mstdnt_args* args, +int mastodont_list_add_accounts(mastodont_t* api, + struct mstdnt_args* m_args, char* id, char** account_ids, size_t account_ids_len, struct mstdnt_storage* storage); -int mastodont_list_remove_accounts(mastodont_t* api, struct mstdnt_args* args, +int mastodont_list_remove_accounts(mastodont_t* api, + struct mstdnt_args* m_args, char* id, char** account_ids, size_t account_ids_len, diff --git a/include/mastodont_notification.h b/include/mastodont_notification.h index bceb3d2..0c60673 100644 --- a/include/mastodont_notification.h +++ b/include/mastodont_notification.h @@ -18,7 +18,6 @@ #include "mastodont_types.h" #include "mastodont_account.h" #include "mastodont_status.h" -#include "mastodont_args.h" #include "mastodont_notif_types.h" #include "mastodont_visibility_types.h" #include @@ -57,7 +56,8 @@ struct _mstdnt_notifications_result_cb_args int mstdnt_notifications_json_callback(cJSON* json, void* _args); -int mastodont_get_notifications(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_notifications(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_get_notifications_args* args, struct mstdnt_storage* storage, struct mstdnt_notification** notifs, diff --git a/include/mastodont_scrobbles.h b/include/mastodont_scrobbles.h index 695f997..536bd7a 100644 --- a/include/mastodont_scrobbles.h +++ b/include/mastodont_scrobbles.h @@ -46,7 +46,8 @@ struct _mstdnt_scrobbles_cb_args size_t* size; }; -int mastodont_get_scrobbles(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_scrobbles(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_get_scrobbles_args* args, struct mstdnt_storage* storage, diff --git a/include/mastodont_search.h b/include/mastodont_search.h index db3323f..82cff14 100644 --- a/include/mastodont_search.h +++ b/include/mastodont_search.h @@ -54,7 +54,8 @@ int mstdnt_search_json_callback(cJSON* json, void* _args); int mstdnt_search_json(struct mstdnt_search_results* search_results, cJSON* json); -int mastodont_search(mastodont_t* data, struct mstdnt_args* args, +int mastodont_search(mastodont_t* data, + struct mstdnt_args* m_args, char* query, struct mstdnt_storage* storage, struct mstdnt_search_args* args, diff --git a/include/mastodont_static.h b/include/mastodont_static.h index f8667d7..eaf66ec 100644 --- a/include/mastodont_static.h +++ b/include/mastodont_static.h @@ -18,10 +18,12 @@ #include "mastodont_types.h" #include "mastodont_fetch.h" -int mastodont_instance_panel(mastodont_t* api, struct mstdnt_args* args, +int mastodont_instance_panel(mastodont_t* api, + struct mstdnt_args* args, struct mstdnt_fetch_results* html); -int mastodont_terms_of_service(mastodont_t* api, struct mstdnt_args* args, +int mastodont_terms_of_service(mastodont_t* api, + struct mstdnt_args* args, struct mstdnt_fetch_results* html); #endif /* MSTDNT_STATIC_H */ diff --git a/include/mastodont_status.h b/include/mastodont_status.h index 3a87b4a..3f20a52 100644 --- a/include/mastodont_status.h +++ b/include/mastodont_status.h @@ -19,7 +19,6 @@ #include #include "mastodont_pleroma.h" #include "mastodont_types.h" -#include "mastodont_args.h" #include "mastodont_fetch.h" #include "mastodont_attachment.h" #include "mastodont_application.h" @@ -91,13 +90,27 @@ struct mstdnt_account_statuses_args int limit; }; +struct mstdnt_status_args +{ + char* in_reply_to_id; + char* content_type; + char* status; + char* visibility; + char** media_ids; + int media_ids_len; +}; + // Cleanup void mstdnt_cleanup_statuses(struct mstdnt_status* statuses, size_t s); void mstdnt_cleanup_status(struct mstdnt_status* status); int mstdnt_status_json(struct mstdnt_status* status, cJSON* js); -int mastodont_status_emoji_react(mastodont_t* api, struct mstdnt_args* args, char* id, char* emoji, - struct mstdnt_storage* storage, struct mstdnt_status* status); +int mastodont_status_emoji_react(mastodont_t* api, + struct mstdnt_args* m_args, + char* id, + char* emoji, + struct mstdnt_storage* storage, + struct mstdnt_status* status); // Generated function int mstdnt_statuses_json(struct mstdnt_status* statuses[], @@ -113,19 +126,22 @@ int mstdnt_status_context_json(struct mstdnt_status* statuses_before[], size_t* size_after, cJSON* js); -int mastodont_get_account_statuses(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_account_statuses(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_statuses_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* size); -int mastodont_get_status(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_status(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status); -int mastodont_get_status_context(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_status_context(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* statuses_before[], @@ -139,20 +155,22 @@ int mastodont_status_favourited_by(mastodont_t* data, struct mstdnt_args* args, struct mstdnt_account* accounts[], size_t* accts); -int mastodont_status_reblogged_by(mastodont_t* data, struct mstdnt_args* args, +int mastodont_status_reblogged_by(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_account* accounts[], size_t* accts); -int mastodont_create_status(mastodont_t* data, struct mstdnt_args* args, - struct mstdnt_args* args, +int mastodont_create_status(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_status_args* args, struct mstdnt_storage* storage); /* Generates do and undo functions */ -#define MSTDNT_STATUS_ACTION_DECL(type) int mastodont_##type##_status(mastodont_t* data, struct mstdnt_args* args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status) +#define MSTDNT_STATUS_ACTION_DECL(type) int mastodont_##type##_status(mastodont_t* data, struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status) #define MSTDNT_STATUS_ACTION_FUNC_URL(action) { \ - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/" action); \ + return mstdnt_status_action(data, m_args, id, storage, status, "api/v1/statuses/%s/" action); \ } MSTDNT_STATUS_ACTION_DECL(favourite); @@ -165,12 +183,14 @@ MSTDNT_STATUS_ACTION_DECL(bookmark); MSTDNT_STATUS_ACTION_DECL(unbookmark); MSTDNT_STATUS_ACTION_DECL(delete); -int mastodont_mute_conversation(mastodont_t* data, struct mstdnt_args* args, +int mastodont_mute_conversation(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status); -int mastodont_unmute_conversation(mastodont_t* data, struct mstdnt_args* args, +int mastodont_unmute_conversation(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status); @@ -205,13 +225,15 @@ struct mstdnt_favourites_args int limit; }; -int mastodont_get_bookmarks(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_bookmarks(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_bookmarks_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* size); -int mastodont_get_favourites(mastodont_t* data, struct mstdnt_args* args, +int mastodont_get_favourites(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_favourites_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], diff --git a/include/mastodont_timeline.h b/include/mastodont_timeline.h index 6663322..c998b91 100644 --- a/include/mastodont_timeline.h +++ b/include/mastodont_timeline.h @@ -40,32 +40,37 @@ struct mstdnt_timeline_args int with_muted; }; -int mastodont_timeline_home(mastodont_t* data, struct mstdnt_args* args, +int mastodont_timeline_home(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* size); -int mastodont_timeline_list(mastodont_t* data, struct mstdnt_args* args, +int mastodont_timeline_list(mastodont_t* data, + struct mstdnt_args* m_args, char* list_id, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* size); -int mastodont_timeline_public(mastodont_t* data, struct mstdnt_args* args, +int mastodont_timeline_public(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* statuses_size); -int mastodont_timeline_direct(mastodont_t* data, struct mstdnt_args* args, +int mastodont_timeline_direct(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], size_t* statuses_size); -int mastodont_timeline_tag(mastodont_t* data, struct mstdnt_args* args, +int mastodont_timeline_tag(mastodont_t* data, + struct mstdnt_args* m_args, char* hashtag, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, diff --git a/src/account.c b/src/account.c index a87666d..9b44909 100644 --- a/src/account.c +++ b/src/account.c @@ -54,7 +54,8 @@ int mstdnt_accounts_json_callback(cJSON* json, void* _args) } static int mastodont_get_accounts_query(char* url, - mastodont_t* data, struct mstdnt_args* args, + mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_account_args* args, struct mstdnt_storage* storage, struct mstdnt_account* accts[], @@ -85,10 +86,11 @@ static int mastodont_get_accounts_query(char* url, mstdnt_accounts_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_get_followers(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_followers(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_args* args, struct mstdnt_storage* storage, @@ -97,10 +99,11 @@ int mastodont_get_followers(mastodont_t* data, struct mstdnt_args* m_args, { char url[MSTDNT_URLSIZE]; snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/followers", id); - return mastodont_get_accounts_query(url, data, args, storage, accts, accts_len); + return mastodont_get_accounts_query(url, data, m_args, args, storage, accts, accts_len); } -int mastodont_get_following(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_following(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_args* args, struct mstdnt_storage* storage, @@ -109,7 +112,7 @@ int mastodont_get_following(mastodont_t* data, struct mstdnt_args* m_args, { char url[MSTDNT_URLSIZE]; snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/following", id); - return mastodont_get_accounts_query(url, data, args, storage, accts, accts_len); + return mastodont_get_accounts_query(url, data, m_args, args, storage, accts, accts_len); } int mastodont_get_blocks(mastodont_t* data, struct mstdnt_args* m_args, @@ -118,7 +121,7 @@ int mastodont_get_blocks(mastodont_t* data, struct mstdnt_args* m_args, struct mstdnt_account* accts[], size_t* accts_len) { - return mastodont_get_accounts_query("api/v1/blocks", data, args, storage, accts, accts_len); + return mastodont_get_accounts_query("api/v1/blocks", data, m_args, args, storage, accts, accts_len); } int mastodont_get_mutes(mastodont_t* data, struct mstdnt_args* m_args, @@ -127,11 +130,12 @@ int mastodont_get_mutes(mastodont_t* data, struct mstdnt_args* m_args, struct mstdnt_account* accts[], size_t* accts_len) { - return mastodont_get_accounts_query("api/v1/mutes", data, args, storage, accts, accts_len); + return mastodont_get_accounts_query("api/v1/mutes", data, m_args, args, storage, accts, accts_len); } -int mastodont_get_account(mastodont_t* data, struct mstdnt_args* m_args, - int lookup, /* TODO move into separate function for consistancy */ +int mastodont_get_account(mastodont_t* data, + struct mstdnt_args* m_args, + int lookup, /* TODO move into separate function for consistancy? */ char* id, struct mstdnt_account* acct, struct mstdnt_storage* storage) @@ -153,10 +157,11 @@ int mastodont_get_account(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_account_json_callback, /* callback */ }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_verify_credentials(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_verify_credentials(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_account* acct, struct mstdnt_storage* storage) { @@ -171,7 +176,7 @@ int mastodont_verify_credentials(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_account_json_callback, /* callback */ }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js) @@ -217,7 +222,8 @@ int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js) } -int mstdnt_account_action(mastodont_t* data, struct mstdnt_args* m_args, +int mstdnt_account_action(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_relationship* rel, @@ -237,7 +243,7 @@ int mstdnt_account_action(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_relationship_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } /* These are all the same */ diff --git a/src/application.c b/src/application.c index 973d658..1f59584 100644 --- a/src/application.c +++ b/src/application.c @@ -69,8 +69,9 @@ static int mstdnt_token_json_callback(cJSON* json, void* args) return mstdnt_token_json(json, args); } -int mastodont_register_app(mastodont_t* data, struct mstdnt_args* m_args, - struct mstdnt_args* args, +int mastodont_register_app(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_application_args* args, struct mstdnt_storage* storage, struct mstdnt_app* app) { @@ -92,12 +93,13 @@ int mastodont_register_app(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_app_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_obtain_oauth_token(mastodont_t* data, struct mstdnt_args* m_args, - struct mstdnt_args* args, +int mastodont_obtain_oauth_token(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_application_args* args, struct mstdnt_storage* storage, struct mstdnt_oauth_token* token) { @@ -125,6 +127,6 @@ int mastodont_obtain_oauth_token(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_token_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } diff --git a/src/attachment.c b/src/attachment.c index e3568ad..6f2a6cf 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -98,7 +98,8 @@ static int mstdnt_attachment_json_callback(cJSON* json, void* _args) return mstdnt_attachment_json(json, _args); } -int mastodont_upload_media(mastodont_t* api, struct mstdnt_args* args, +int mastodont_upload_media(mastodont_t* api, + struct mstdnt_args* m_args, struct mstdnt_upload_media_args* args, struct mstdnt_storage* storage, struct mstdnt_attachment* attachment) @@ -119,7 +120,7 @@ int mastodont_upload_media(mastodont_t* api, struct mstdnt_args* args, mstdnt_attachment_json_callback, }; - return mastodont_request(api, &req_args); + return mastodont_request(api, m_args, &req_args); } void mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment) diff --git a/src/list.c b/src/list.c index e5d39f3..3a8f47d 100644 --- a/src/list.c +++ b/src/list.c @@ -72,7 +72,8 @@ static int mstdnt_lists_json_callback(cJSON* json, void* _args) return mstdnt_lists_json(args->lists, args->size, json); } -int mastodont_get_lists(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_lists(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_storage* storage, struct mstdnt_list* lists[], size_t* size) @@ -93,10 +94,11 @@ int mastodont_get_lists(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_lists_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_get_list(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_list(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_list* list) @@ -115,7 +117,7 @@ int mastodont_get_list(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_list_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } static const char* replies_policy_str(enum mstdnt_list_replies_policy pol) @@ -156,7 +158,8 @@ int mastodont_create_list(mastodont_t* data, struct mstdnt_args* m_args, return mastodont_request(data, m_args,&req_args); } -int mastodont_update_list(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_update_list(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_list_args* args, struct mstdnt_storage* storage, @@ -181,10 +184,11 @@ int mastodont_update_list(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_list_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_delete_list(mastodont_t* api, struct mstdnt_args* args, +int mastodont_delete_list(mastodont_t* api, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage) { @@ -202,10 +206,11 @@ int mastodont_delete_list(mastodont_t* api, struct mstdnt_args* args, NULL, }; - return mastodont_request(api, &req_args); + return mastodont_request(api, m_args, &req_args); } -int mastodont_list_add_accounts(mastodont_t* api, struct mstdnt_args* args, +int mastodont_list_add_accounts(mastodont_t* api, + struct mstdnt_args* m_args, char* id, char** account_ids, size_t account_ids_len, @@ -234,10 +239,11 @@ int mastodont_list_add_accounts(mastodont_t* api, struct mstdnt_args* args, NULL, }; - return mastodont_request(api, &req_args); + return mastodont_request(api, m_args, &req_args); } -int mastodont_list_remove_accounts(mastodont_t* api, struct mstdnt_args* args, +int mastodont_list_remove_accounts(mastodont_t* api, + struct mstdnt_args* m_args, char* id, char** account_ids, size_t account_ids_len, @@ -266,10 +272,11 @@ int mastodont_list_remove_accounts(mastodont_t* api, struct mstdnt_args* args, NULL, }; - return mastodont_request(api, &req_args); + return mastodont_request(api, m_args, &req_args); } -int mastodont_list_get_accounts(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_list_get_accounts(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_args* args, struct mstdnt_storage* storage, @@ -303,7 +310,7 @@ int mastodont_list_get_accounts(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_accounts_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } void mstdnt_cleanup_lists(struct mstdnt_list* lists) diff --git a/src/mastodont.c b/src/mastodont.c index 45e1af4..1d535f4 100644 --- a/src/mastodont.c +++ b/src/mastodont.c @@ -13,7 +13,7 @@ void mastodont_global_curl_cleanup() curl_global_cleanup(); } -int mastodont_init(mastodont_t* data, struct mstdnt_args* m_args, uint16_t flags) +int mastodont_init(mastodont_t* data) { data->curl = curl_easy_init(); return data->curl == NULL; diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 60a0c8a..d55dc68 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -94,7 +94,8 @@ int mstdnt_nodeinfo_json_callback(cJSON* json, void* nodeinfo) return mstdnt_nodeinfo_json(nodeinfo, json); } -int mastodont_get_nodeinfo(mastodont_t* api, struct mstdnt_args* args, +int mastodont_get_nodeinfo(mastodont_t* api, + struct mstdnt_args* m_args, char* version, struct mstdnt_storage* storage, struct mstdnt_nodeinfo* nodeinfo) @@ -113,7 +114,7 @@ int mastodont_get_nodeinfo(mastodont_t* api, struct mstdnt_args* args, mstdnt_nodeinfo_json_callback }; - return mastodont_request(api, &req_args); + return mastodont_request(api, m_args, &req_args); } void mstdnt_cleanup_nodeinfo(struct mstdnt_nodeinfo* nodeinfo) diff --git a/src/notification.c b/src/notification.c index 6486369..773cb90 100644 --- a/src/notification.c +++ b/src/notification.c @@ -75,7 +75,8 @@ int mstdnt_notifications_json_callback(cJSON* json, void* _args) return mstdnt_notifications_json(args->notif, args->size, json); } -int mastodont_get_notifications(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_notifications(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_get_notifications_args* args, struct mstdnt_storage* storage, struct mstdnt_notification** notifs, @@ -116,7 +117,7 @@ int mastodont_get_notifications(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_notifications_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } void mstdnt_cleanup_notifications(struct mstdnt_notification* notifs, size_t notifs_len) diff --git a/src/request.c b/src/request.c index 38a8130..32d2ac7 100644 --- a/src/request.c +++ b/src/request.c @@ -82,7 +82,7 @@ int mastodont_request(mastodont_t* data, char* post; // TODO debug me char* url_query = args->params_query ? - _mstdnt_query_string(data, args->url, args->params_query, args->params_query_len) : + _mstdnt_query_string(data, m_args, args->url, args->params_query, args->params_query_len) : args->url; /* Zero out */ @@ -93,7 +93,7 @@ int mastodont_request(mastodont_t* data, (args->request_type == CURLOPT_POST || args->request_type == CURLOPT_CUSTOMREQUEST)) { - post = _mstdnt_query_string(data, NULL, args->params_post, args->params_post_len); + post = _mstdnt_query_string(data, m_args, NULL, args->params_post, args->params_post_len); curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, post); } else if (args->params_post && args->request_type == CURLOPT_MIMEPOST) diff --git a/src/scrobbles.c b/src/scrobbles.c index 3ce7d71..82db849 100644 --- a/src/scrobbles.c +++ b/src/scrobbles.c @@ -52,7 +52,8 @@ int mstdnt_scrobbles_json_callback(cJSON* json, void* _args) return mstdnt_scrobbles_json(args->scrobbles, args->size, json); } -int mastodont_get_scrobbles(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_scrobbles(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_get_scrobbles_args* args, struct mstdnt_storage* storage, @@ -82,6 +83,6 @@ int mastodont_get_scrobbles(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_scrobbles_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } diff --git a/src/search.c b/src/search.c index 515adb4..08bb452 100644 --- a/src/search.c +++ b/src/search.c @@ -61,7 +61,8 @@ int mstdnt_search_json_callback(cJSON* json, void* _args) return mstdnt_search_json(_args, json); } -int mastodont_search(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_search(mastodont_t* data, + struct mstdnt_args* m_args, char* query, struct mstdnt_storage* storage, struct mstdnt_search_args* args, @@ -92,7 +93,7 @@ int mastodont_search(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_search_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } void mstdnt_cleanup_search_results(struct mstdnt_search_results* res) diff --git a/src/static.c b/src/static.c index ed81934..8c5ff83 100644 --- a/src/static.c +++ b/src/static.c @@ -16,14 +16,26 @@ #include #include -int mastodont_instance_panel(mastodont_t* api, struct mstdnt_args* args, +int mastodont_instance_panel(mastodont_t* api, + struct mstdnt_args* m_args, struct mstdnt_fetch_results* html) { - return mastodont_fetch_curl(api, "instance/panel.html", html, CURLOPT_HTTPGET, NULL); + return mastodont_fetch_curl(api, + m_args, + "instance/panel.html", + html, + CURLOPT_HTTPGET, + NULL); } -int mastodont_terms_of_service(mastodont_t* api, struct mstdnt_args* args, +int mastodont_terms_of_service(mastodont_t* api, + struct mstdnt_args* m_args, struct mstdnt_fetch_results* html) { - return mastodont_fetch_curl(api, "static/terms-of-service.html", html, CURLOPT_HTTPGET, NULL); + return mastodont_fetch_curl(api, + m_args, + "static/terms-of-service.html", + html, + CURLOPT_HTTPGET, + NULL); } diff --git a/src/status.c b/src/status.c index e2db89b..a4c8c4e 100644 --- a/src/status.c +++ b/src/status.c @@ -143,7 +143,8 @@ int mstdnt_statuses_json_callback(cJSON* json, void* _args) return mstdnt_statuses_json(args->statuses, args->size, json); } -int mastodont_get_account_statuses(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_account_statuses(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_account_statuses_args* args, struct mstdnt_storage* storage, @@ -179,12 +180,13 @@ int mastodont_get_account_statuses(mastodont_t* data, struct mstdnt_args* m_args mstdnt_statuses_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } /* TODO Populate the arguments! */ -int mastodont_create_status(mastodont_t* data, struct mstdnt_args* m_args, - struct mstdnt_args* args, +int mastodont_create_status(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_status_args* args, struct mstdnt_storage* storage) { struct _mstdnt_query_param params[] = { @@ -212,10 +214,11 @@ int mastodont_create_status(mastodont_t* data, struct mstdnt_args* m_args, * (not sure if the api returns it or not) */ }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -static int mstdnt_status_action(mastodont_t* data, struct mstdnt_args* m_args, +static int mstdnt_status_action(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status, @@ -235,7 +238,7 @@ static int mstdnt_status_action(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_status_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } /* These are all the same */ @@ -280,27 +283,30 @@ MSTDNT_STATUS_ACTION_DECL(delete) mstdnt_status_json_callback }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } /* TODO Mutes can be timed */ -int mastodont_mute_conversation(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_mute_conversation(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status) { - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/mute"); + return mstdnt_status_action(data, m_args, id, storage, status, "api/v1/statuses/%s/mute"); } -int mastodont_unmute_conversation(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_unmute_conversation(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status) { - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/unmute"); + return mstdnt_status_action(data, m_args, id, storage, status, "api/v1/statuses/%s/unmute"); } -int mastodont_get_status(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_status(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status) @@ -319,7 +325,7 @@ int mastodont_get_status(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_status_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } int mstdnt_status_context_json(struct mstdnt_status* statuses_before[], @@ -381,7 +387,8 @@ int mstdnt_status_context_json_callback(cJSON* json, void* _args) json); } -int mastodont_get_status_context(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_status_context(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* statuses_before[], @@ -409,10 +416,11 @@ int mastodont_get_status_context(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_status_context_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_status_favourited_by(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_status_favourited_by(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_account* accounts[], @@ -436,10 +444,11 @@ int mastodont_status_favourited_by(mastodont_t* data, struct mstdnt_args* m_args mstdnt_accounts_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_status_reblogged_by(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_status_reblogged_by(mastodont_t* data, + struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_account* accounts[], @@ -463,11 +472,12 @@ int mastodont_status_reblogged_by(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_accounts_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_get_bookmarks(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_bookmarks(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_bookmarks_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], @@ -493,10 +503,11 @@ int mastodont_get_bookmarks(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_get_favourites(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_get_favourites(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_favourites_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], @@ -521,11 +532,15 @@ int mastodont_get_favourites(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_status_emoji_react(mastodont_t* api, struct mstdnt_args* args, char* id, char* emoji, - struct mstdnt_storage* storage, struct mstdnt_status* status) +int mastodont_status_emoji_react(mastodont_t* api, + struct mstdnt_args* m_args, + char* id, + char* emoji, + struct mstdnt_storage* storage, + struct mstdnt_status* status) { char url[MSTDNT_URLSIZE]; snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/statuses/%s/reactions/%s", id, emoji); @@ -541,7 +556,7 @@ int mastodont_status_emoji_react(mastodont_t* api, struct mstdnt_args* args, cha mstdnt_status_json_callback }; - return mastodont_request(api, &req_args); + return mastodont_request(api, m_args, &req_args); } void mstdnt_cleanup_status(struct mstdnt_status* status) diff --git a/src/timeline.c b/src/timeline.c index 45380ea..e14c06c 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -20,7 +20,8 @@ #include #include -int mastodont_timeline_list(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_timeline_list(mastodont_t* data, + struct mstdnt_args* m_args, char* list_id, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, @@ -55,10 +56,11 @@ int mastodont_timeline_list(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_timeline_tag(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_timeline_tag(mastodont_t* data, + struct mstdnt_args* m_args, char* hashtag, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, @@ -96,7 +98,7 @@ int mastodont_timeline_tag(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } static const char* reply_visibility_str(enum mstdnt_reply_visibility vis) @@ -113,7 +115,8 @@ static const char* reply_visibility_str(enum mstdnt_reply_visibility vis) } } -int mastodont_timeline_public(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_timeline_public(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], @@ -145,11 +148,12 @@ int mastodont_timeline_public(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_timeline_direct(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_timeline_direct(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], @@ -177,11 +181,12 @@ int mastodont_timeline_direct(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); } -int mastodont_timeline_home(mastodont_t* data, struct mstdnt_args* m_args, +int mastodont_timeline_home(mastodont_t* data, + struct mstdnt_args* m_args, struct mstdnt_timeline_args* args, struct mstdnt_storage* storage, struct mstdnt_status* statuses[], @@ -214,6 +219,6 @@ int mastodont_timeline_home(mastodont_t* data, struct mstdnt_args* m_args, mstdnt_statuses_json_callback, }; - return mastodont_request(data, m_args,&req_args); + return mastodont_request(data, m_args, &req_args); }