Rewrite for C99
FossilOrigin-Name: 367f50c7b7bb529c59c097e5aa08cf8eaddb4a50ca94da861efd4682c2c75108
This commit is contained in:
parent
37766a8bd7
commit
d9345d7c05
7 changed files with 78 additions and 189 deletions
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
CC ?= cc
|
||||
CFLAGS = -g -ansi -Wall -Werror=implicit-function-declaration -Wno-unused-variable -I ./include/ `pkg-config --cflags libcjson`
|
||||
CFLAGS = -g -std=c99 -Wall -Werror=implicit-function-declaration -Wno-unused-variable -I ./include/ `pkg-config --cflags libcjson`
|
||||
SRC = $(wildcard src/*.c)
|
||||
OBJ = $(patsubst %.c,%.o,$(SRC))
|
||||
TARGET = libmastodont.a # shared
|
||||
|
|
|
@ -99,18 +99,11 @@ int mastodont_register_app(mastodont_t* data,
|
|||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_app* app)
|
||||
{
|
||||
union param_value u_client_name, u_redirect_uris,
|
||||
u_scopes, u_website;
|
||||
u_client_name.s = args->client_name;
|
||||
u_redirect_uris.s = args->redirect_uris;
|
||||
u_scopes.s = args->scopes;
|
||||
u_website.s = args->website;
|
||||
|
||||
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, "client_name", { .s = args->client_name } },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uris", { .s = args->redirect_uris } },
|
||||
{ _MSTDNT_QUERY_STRING, "scopes", { .s = args->scopes } },
|
||||
{ _MSTDNT_QUERY_STRING, "website", { .s = args->website } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -132,27 +125,15 @@ int mastodont_obtain_oauth_token(mastodont_t* data,
|
|||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_oauth_token* token)
|
||||
{
|
||||
union param_value u_grant_type, u_client_id,
|
||||
u_client_secret, u_redirect_uri,
|
||||
u_scope, u_code, u_username, u_password;
|
||||
u_grant_type.s = args->grant_type;
|
||||
u_client_id.s = args->client_id;
|
||||
u_client_secret.s = args->client_secret;
|
||||
u_redirect_uri.s = args->redirect_uri;
|
||||
u_scope.s = args->scope;
|
||||
u_code.s = args->code;
|
||||
u_username.s = args->username;
|
||||
u_password.s = args->password;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "grant_type", u_grant_type },
|
||||
{ _MSTDNT_QUERY_STRING, "client_id", u_client_id },
|
||||
{ _MSTDNT_QUERY_STRING, "client_secret", u_client_secret },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uri", u_redirect_uri },
|
||||
{ _MSTDNT_QUERY_STRING, "scope", u_scope },
|
||||
{ _MSTDNT_QUERY_STRING, "code", u_code },
|
||||
{ _MSTDNT_QUERY_STRING, "username", u_username },
|
||||
{ _MSTDNT_QUERY_STRING, "password", u_password },
|
||||
{ _MSTDNT_QUERY_STRING, "grant_type", { .s = args->grant_type } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_id", { .s = args->client_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_secret", { .s = args->client_secret } },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uri", { .s = args->redirect_uri } },
|
||||
{ _MSTDNT_QUERY_STRING, "scope", { .s = args->scope } },
|
||||
{ _MSTDNT_QUERY_STRING, "code", { .s = args->code } },
|
||||
{ _MSTDNT_QUERY_STRING, "username", { .s = args->username } },
|
||||
{ _MSTDNT_QUERY_STRING, "password", { .s = args->password } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
|
@ -100,14 +100,9 @@ int mastodont_upload_media(mastodont_t* api,
|
|||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_attachment* attachment)
|
||||
{
|
||||
union param_value u_file, u_thumbnail, u_description;
|
||||
u_file.f = &(args->file);
|
||||
u_thumbnail.f = args->thumbnail;
|
||||
u_description.s = args->description;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_FILE, "file", u_file },
|
||||
{ _MSTDNT_QUERY_FILE, "thumbnail", u_thumbnail }
|
||||
{ _MSTDNT_QUERY_FILE, "file", { .f = &(args->file) } },
|
||||
{ _MSTDNT_QUERY_FILE, "thumbnail", { .f = args->thumbnail } }
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
|
@ -142,15 +142,14 @@ int mastodont_get_relationships(mastodont_t* data,
|
|||
struct mstdnt_relationship* relationships[],
|
||||
size_t* size)
|
||||
{
|
||||
/* struct _mstdnt_query_param params[] = { 0 }; */
|
||||
struct _mstdnt_relationships_cb_args cb_args = { relationships, size };
|
||||
|
||||
union param_value u_ids;
|
||||
u_ids.a.arr = ids;
|
||||
u_ids.a.arr_len = ids_len;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_ARRAY, "id", u_ids }
|
||||
{ _MSTDNT_QUERY_ARRAY, "id",
|
||||
{
|
||||
.a.arr = ids,
|
||||
.a.arr_len = ids_len
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
|
@ -93,21 +93,13 @@ int mastodont_get_scrobbles(mastodont_t* data,
|
|||
struct _mstdnt_scrobbles_cb_args cb_args = { scrobbles, size };
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/accounts/%s/scrobbles", id);
|
||||
|
||||
union param_value u_max_id, u_min_id,
|
||||
u_since_id, u_offset, u_limit;
|
||||
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, "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 },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
97
src/status.c
97
src/status.c
|
@ -167,34 +167,18 @@ int mastodont_get_account_statuses(mastodont_t* data,
|
|||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/statuses", id);
|
||||
|
||||
union param_value u_pinned, u_tagged, u_only_media,
|
||||
u_with_muted, u_exclude_reblogs, u_exclude_replies,
|
||||
u_exclude_visibilities, u_max_id, u_min_id,
|
||||
u_since_id, u_offset, u_limit;
|
||||
u_pinned.i = args->pinned;
|
||||
u_only_media.i = args->only_media;
|
||||
u_with_muted.i = args->with_muted;
|
||||
u_exclude_reblogs.i = args->exclude_reblogs;
|
||||
u_exclude_replies.i = args->exclude_replies;
|
||||
u_tagged.s = args->tagged;
|
||||
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_INT, "pinned", u_pinned },
|
||||
{ _MSTDNT_QUERY_STRING, "tagged", u_tagged },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", u_only_media },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", u_with_muted },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_reblogs", u_exclude_reblogs },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_replies", u_exclude_replies },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_INT, "offset", u_offset },
|
||||
{ _MSTDNT_QUERY_INT, "pinned", { .i = args->pinned } },
|
||||
{ _MSTDNT_QUERY_STRING, "tagged", { .s = args->tagged } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args->only_media } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_reblogs", { .i = args->exclude_reblogs } },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_replies", { .i = args->exclude_replies } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -215,31 +199,17 @@ int mastodont_create_status(mastodont_t* data,
|
|||
struct mstdnt_args* args,
|
||||
struct mstdnt_storage* storage)
|
||||
{
|
||||
union param_value u_content_type, u_expires_in,
|
||||
u_in_reply_to_conversation_id, u_in_reply_to_id,
|
||||
u_language, u_media_ids, u_poll, u_preview, u_scheduled_at,
|
||||
u_sensitive, u_spoiler_text, u_status, u_visibility;
|
||||
u_content_type.s = args->content_type;
|
||||
u_expires_in.i = args->expires_in;
|
||||
u_in_reply_to_conversation_id.s = args->in_reply_to_conversation_id;
|
||||
u_in_reply_to_id.s = args->in_reply_to_id;
|
||||
u_language.s = args->language;
|
||||
u_media_ids.a.arr = args->media_ids;
|
||||
u_media_ids.a.arr_len = args->media_ids_len;
|
||||
/* poll */
|
||||
u_preview.i = args->preview;
|
||||
u_scheduled_at.s = args->scheduled_at;
|
||||
u_sensitive.i = args->sensitive;
|
||||
u_spoiler_text.s = args->spoiler_text;
|
||||
u_status.s = args->status;
|
||||
u_visibility.s = args->visibility;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "in_reply_to_id", u_in_reply_to_id },
|
||||
{ _MSTDNT_QUERY_STRING, "content_type", u_content_type },
|
||||
{ _MSTDNT_QUERY_STRING, "status", u_status },
|
||||
{ _MSTDNT_QUERY_STRING, "visibility", u_visibility },
|
||||
{ _MSTDNT_QUERY_ARRAY, "media_ids", u_media_ids },
|
||||
{ _MSTDNT_QUERY_STRING, "in_reply_to_id", { .s = args->in_reply_to_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "content_type", { .s = args->content_type } },
|
||||
{ _MSTDNT_QUERY_STRING, "status", { .s = args->status } },
|
||||
{ _MSTDNT_QUERY_STRING, "visibility", { .s = args->visibility } },
|
||||
{ _MSTDNT_QUERY_ARRAY, "media_ids",
|
||||
{
|
||||
.a.arr = args->media_ids,
|
||||
.a.arr_len = args->media_ids_len
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -524,18 +494,12 @@ int mastodont_get_bookmarks(mastodont_t* data,
|
|||
size_t* size)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
union param_value u_max_id, u_since_id, u_min_id, u_limit;
|
||||
u_max_id.s = args->max_id;
|
||||
u_since_id.s = args->since_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_limit.i = args->limit;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -558,16 +522,11 @@ int mastodont_get_favourites(mastodont_t* data,
|
|||
size_t* size)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
union param_value u_max_id, u_min_id, u_limit;
|
||||
u_max_id.s = args->max_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_limit.i = args->limit;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
|
@ -30,19 +30,12 @@ int mastodont_timeline_list(mastodont_t* data,
|
|||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/timelines/list/%s", list_id);
|
||||
|
||||
union param_value u_local, u_remote, u_only_media,
|
||||
u_max_id, u_since_id, u_min_id, u_limit;
|
||||
u_max_id.s = args->max_id;
|
||||
u_since_id.s = args->since_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_limit.i = args->limit;
|
||||
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -65,25 +58,14 @@ int mastodont_timeline_public(mastodont_t* data,
|
|||
size_t* size)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
union param_value u_local, u_remote, u_only_media,
|
||||
u_max_id, u_since_id, u_min_id, u_limit;
|
||||
u_local.i = args->local;
|
||||
u_remote.i = args->remote;
|
||||
u_only_media.i = args->only_media;
|
||||
u_max_id.s = args->max_id;
|
||||
u_since_id.s = args->since_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_limit.i = args->limit;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_INT, "local", u_local },
|
||||
{ _MSTDNT_QUERY_INT, "remote", u_remote },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", u_only_media },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_INT, "local", { .i = args->local } },
|
||||
{ _MSTDNT_QUERY_INT, "remote", { .i = args->remote } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args->only_media } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -107,25 +89,15 @@ int mastodont_timeline_direct(mastodont_t* data,
|
|||
size_t* size)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
union param_value u_max_id, u_since_id, u_min_id,
|
||||
u_limit, u_local, u_offset, u_with_muted;
|
||||
u_max_id.s = args->max_id;
|
||||
u_since_id.s = args->since_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_limit.i = args->limit;
|
||||
u_offset.i = args->offset;
|
||||
u_local.i = args->local;
|
||||
u_with_muted.i = args->with_muted;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_INT, "offset", u_offset },
|
||||
{ _MSTDNT_QUERY_INT, "local", u_local },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", u_with_muted },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "local", { .i = args->local } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args->with_muted } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
@ -149,22 +121,13 @@ int mastodont_timeline_home(mastodont_t* data,
|
|||
size_t* size)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
union param_value u_max_id, u_since_id, u_min_id,
|
||||
u_limit, u_local, u_offset;
|
||||
u_max_id.s = args->max_id;
|
||||
u_since_id.s = args->since_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_limit.i = args->limit;
|
||||
u_local.i = args->local;
|
||||
u_offset.i = args->offset;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_INT, "offset", u_offset },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
Loading…
Reference in a new issue