diff options
Diffstat (limited to 'mastoapi.c')
-rw-r--r-- | mastoapi.c | 45 |
1 files changed, 38 insertions, 7 deletions
@@ -240,8 +240,10 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, char *i_ctype = xs_dict_get(req, "content-type"); xs *args = NULL; - if (i_ctype && xs_startswith(i_ctype, "application/json")) - args = xs_json_loads(payload); + if (i_ctype && xs_startswith(i_ctype, "application/json")) { + if (!xs_is_null(payload)) + args = xs_json_loads(payload); + } else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded") && payload) { xs *upl = xs_url_dec(payload); @@ -250,6 +252,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, else args = xs_dup(xs_dict_get(req, "p_vars")); + if (args == NULL) + return 400; + xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); srv_debug(1, xs_fmt("oauth_post_handler %s", q_path)); @@ -354,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); @@ -1403,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"); @@ -1617,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("[]"); @@ -1981,8 +2000,18 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, xs *args = NULL; char *i_ctype = xs_dict_get(req, "content-type"); - if (i_ctype && xs_startswith(i_ctype, "application/json")) - args = xs_json_loads(payload); + if (i_ctype && xs_startswith(i_ctype, "application/json")) { + 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")); @@ -2504,8 +2533,10 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, xs *args = NULL; char *i_ctype = xs_dict_get(req, "content-type"); - if (i_ctype && xs_startswith(i_ctype, "application/json")) - args = xs_json_loads(payload); + if (i_ctype && xs_startswith(i_ctype, "application/json")) { + if (!xs_is_null(payload)) + args = xs_json_loads(payload); + } else args = xs_dup(xs_dict_get(req, "p_vars")); |