From 253e627ee067b1f2504dd11c7934ce51b0a2f5b2 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sun, 28 Jan 2024 20:55:43 +0000 Subject: make compatible with subway tooter app --- mastoapi.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index d8ec3b3..6ed3835 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -359,6 +359,12 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, } } + /* no code? + I'm not sure of the impacts of this right now, but Subway Tooter does not + provide a code so one must be generated */ + if (xs_is_null(code)){ + code = random_str(); + } if (gtype && code && cid && csec && ruri) { xs *app = app_get(cid); @@ -1408,7 +1414,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, const char *type = xs_dict_get(msg, "type"); if (!xs_match(type, "Note|Question|Page|Article")) continue; - const char *from = NULL; if (strcmp(type, "Page") == 0) from = xs_dict_get(msg, "audience"); @@ -1622,6 +1627,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, status = 200; } else + if (strcmp(cmd, "/v2/filters") == 0) { /** **/ + /* snac will never have filters + * but still, without a v2 endpoint a short delay is introduced + * in some apps */ + *body = xs_dup("[]"); + *ctype = "application/json"; + status = 200; + } + else if (strcmp(cmd, "/v1/favourites") == 0) { /** **/ /* snac will never support a list of favourites */ *body = xs_dup("[]"); @@ -1990,6 +2004,14 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (!xs_is_null(payload)) args = xs_json_loads(payload); } + else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded")) + { + // Some apps send form data instead of json so we should cater for those + if (!xs_is_null(payload)) { + xs *upl = xs_url_dec(payload); + args = xs_url_vars(upl); + } + } else args = xs_dup(xs_dict_get(req, "p_vars")); -- cgit v1.2.3 From 9568ec8bfede731d2ecdc5840e3a8a125fc31510 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sun, 28 Jan 2024 21:04:11 +0000 Subject: cleanup --- mastoapi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 6ed3835..8a48198 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1414,6 +1414,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, const char *type = xs_dict_get(msg, "type"); if (!xs_match(type, "Note|Question|Page|Article")) continue; + const char *from = NULL; if (strcmp(type, "Page") == 0) from = xs_dict_get(msg, "audience"); -- cgit v1.2.3 From ddfd8aaca9c3d3cb0dccf40580337a65f44413ed Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sun, 28 Jan 2024 21:06:36 +0000 Subject: cleanup --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 8a48198..4c39854 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -363,7 +363,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, I'm not sure of the impacts of this right now, but Subway Tooter does not provide a code so one must be generated */ if (xs_is_null(code)){ - code = random_str(); + code = random_str(); } if (gtype && code && cid && csec && ruri) { xs *app = app_get(cid); -- cgit v1.2.3 From f0c46a7c1f6a6ac8273197ec79617f6974a1bc7b Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sun, 28 Jan 2024 21:07:31 +0000 Subject: cleanup --- mastoapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 4c39854..abeea94 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2008,10 +2008,10 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded")) { // Some apps send form data instead of json so we should cater for those - if (!xs_is_null(payload)) { + if (!xs_is_null(payload)) { xs *upl = xs_url_dec(payload); args = xs_url_vars(upl); - } + } } else args = xs_dup(xs_dict_get(req, "p_vars")); -- cgit v1.2.3 From d7978621ed3756dd3d021631d7f735ef0d8f39d4 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sun, 28 Jan 2024 21:14:46 +0000 Subject: formatting --- mastoapi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index abeea94..efcdae8 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -362,9 +362,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, /* no code? I'm not sure of the impacts of this right now, but Subway Tooter does not provide a code so one must be generated */ - if (xs_is_null(code)){ - code = random_str(); - } + if (xs_is_null(code)){ + code = random_str(); + } if (gtype && code && cid && csec && ruri) { xs *app = app_get(cid); -- cgit v1.2.3