summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 9f6c383..6ed3835 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -240,8 +240,10 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
240 char *i_ctype = xs_dict_get(req, "content-type"); 240 char *i_ctype = xs_dict_get(req, "content-type");
241 xs *args = NULL; 241 xs *args = NULL;
242 242
243 if (i_ctype && xs_startswith(i_ctype, "application/json")) 243 if (i_ctype && xs_startswith(i_ctype, "application/json")) {
244 args = xs_json_loads(payload); 244 if (!xs_is_null(payload))
245 args = xs_json_loads(payload);
246 }
245 else 247 else
246 if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded") && payload) { 248 if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded") && payload) {
247 xs *upl = xs_url_dec(payload); 249 xs *upl = xs_url_dec(payload);
@@ -250,6 +252,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
250 else 252 else
251 args = xs_dup(xs_dict_get(req, "p_vars")); 253 args = xs_dup(xs_dict_get(req, "p_vars"));
252 254
255 if (args == NULL)
256 return 400;
257
253 xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); 258 xs *cmd = xs_replace_n(q_path, "/oauth", "", 1);
254 259
255 srv_debug(1, xs_fmt("oauth_post_handler %s", q_path)); 260 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,
354 } 359 }
355 } 360 }
356 361
362 /* no code?
363 I'm not sure of the impacts of this right now, but Subway Tooter does not
364 provide a code so one must be generated */
365 if (xs_is_null(code)){
366 code = random_str();
367 }
357 if (gtype && code && cid && csec && ruri) { 368 if (gtype && code && cid && csec && ruri) {
358 xs *app = app_get(cid); 369 xs *app = app_get(cid);
359 370
@@ -1403,7 +1414,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1403 const char *type = xs_dict_get(msg, "type"); 1414 const char *type = xs_dict_get(msg, "type");
1404 if (!xs_match(type, "Note|Question|Page|Article")) 1415 if (!xs_match(type, "Note|Question|Page|Article"))
1405 continue; 1416 continue;
1406
1407 const char *from = NULL; 1417 const char *from = NULL;
1408 if (strcmp(type, "Page") == 0) 1418 if (strcmp(type, "Page") == 0)
1409 from = xs_dict_get(msg, "audience"); 1419 from = xs_dict_get(msg, "audience");
@@ -1617,6 +1627,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1617 status = 200; 1627 status = 200;
1618 } 1628 }
1619 else 1629 else
1630 if (strcmp(cmd, "/v2/filters") == 0) { /** **/
1631 /* snac will never have filters
1632 * but still, without a v2 endpoint a short delay is introduced
1633 * in some apps */
1634 *body = xs_dup("[]");
1635 *ctype = "application/json";
1636 status = 200;
1637 }
1638 else
1620 if (strcmp(cmd, "/v1/favourites") == 0) { /** **/ 1639 if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
1621 /* snac will never support a list of favourites */ 1640 /* snac will never support a list of favourites */
1622 *body = xs_dup("[]"); 1641 *body = xs_dup("[]");
@@ -1981,8 +2000,18 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1981 xs *args = NULL; 2000 xs *args = NULL;
1982 char *i_ctype = xs_dict_get(req, "content-type"); 2001 char *i_ctype = xs_dict_get(req, "content-type");
1983 2002
1984 if (i_ctype && xs_startswith(i_ctype, "application/json")) 2003 if (i_ctype && xs_startswith(i_ctype, "application/json")) {
1985 args = xs_json_loads(payload); 2004 if (!xs_is_null(payload))
2005 args = xs_json_loads(payload);
2006 }
2007 else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded"))
2008 {
2009 // Some apps send form data instead of json so we should cater for those
2010 if (!xs_is_null(payload)) {
2011 xs *upl = xs_url_dec(payload);
2012 args = xs_url_vars(upl);
2013 }
2014 }
1986 else 2015 else
1987 args = xs_dup(xs_dict_get(req, "p_vars")); 2016 args = xs_dup(xs_dict_get(req, "p_vars"));
1988 2017
@@ -2504,8 +2533,10 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
2504 xs *args = NULL; 2533 xs *args = NULL;
2505 char *i_ctype = xs_dict_get(req, "content-type"); 2534 char *i_ctype = xs_dict_get(req, "content-type");
2506 2535
2507 if (i_ctype && xs_startswith(i_ctype, "application/json")) 2536 if (i_ctype && xs_startswith(i_ctype, "application/json")) {
2508 args = xs_json_loads(payload); 2537 if (!xs_is_null(payload))
2538 args = xs_json_loads(payload);
2539 }
2509 else 2540 else
2510 args = xs_dup(xs_dict_get(req, "p_vars")); 2541 args = xs_dup(xs_dict_get(req, "p_vars"));
2511 2542