summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mastoapi.c24
-rw-r--r--xs_formdata.h27
2 files changed, 50 insertions, 1 deletions
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,
359 } 359 }
360 } 360 }
361 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 }
362 if (gtype && code && cid && csec && ruri) { 368 if (gtype && code && cid && csec && ruri) {
363 xs *app = app_get(cid); 369 xs *app = app_get(cid);
364 370
@@ -1408,7 +1414,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1408 const char *type = xs_dict_get(msg, "type"); 1414 const char *type = xs_dict_get(msg, "type");
1409 if (!xs_match(type, "Note|Question|Page|Article")) 1415 if (!xs_match(type, "Note|Question|Page|Article"))
1410 continue; 1416 continue;
1411
1412 const char *from = NULL; 1417 const char *from = NULL;
1413 if (strcmp(type, "Page") == 0) 1418 if (strcmp(type, "Page") == 0)
1414 from = xs_dict_get(msg, "audience"); 1419 from = xs_dict_get(msg, "audience");
@@ -1622,6 +1627,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1622 status = 200; 1627 status = 200;
1623 } 1628 }
1624 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
1625 if (strcmp(cmd, "/v1/favourites") == 0) { /** **/ 1639 if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
1626 /* snac will never support a list of favourites */ 1640 /* snac will never support a list of favourites */
1627 *body = xs_dup("[]"); 1641 *body = xs_dup("[]");
@@ -1990,6 +2004,14 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1990 if (!xs_is_null(payload)) 2004 if (!xs_is_null(payload))
1991 args = xs_json_loads(payload); 2005 args = xs_json_loads(payload);
1992 } 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 }
1993 else 2015 else
1994 args = xs_dup(xs_dict_get(req, "p_vars")); 2016 args = xs_dup(xs_dict_get(req, "p_vars"));
1995 2017
diff --git a/xs_formdata.h b/xs_formdata.h
new file mode 100644
index 0000000..213bd3e
--- /dev/null
+++ b/xs_formdata.h
@@ -0,0 +1,27 @@
1/* copyright (c) 2022 - 2024 grunfink et al. / MIT license */
2#include "xs.h"
3
4#ifndef _XS_FORMDATA_H
5
6#define _XS_FORMDATA_H
7
8xs_val *xs_formdata_loads(const xs_str *formdata);
9
10#ifdef XS_IMPLEMENTATION
11
12/** IMPLEMENTATION **/
13
14xs_val *xs_formdata_loads(const xs_str *formdata)
15/* loads a string in formdata format and converts to a multiple data */
16{
17 xs_val *v = NULL;
18 xs_list *args = xs_split(formdata, "&");
19 int i = 0;
20 while (){}
21 printf("args: %s\r\n", args); fflush(stdout);
22 printf("data: %s\r\n", formdata); fflush(stdout);
23}
24
25#endif /* XS_IMPLEMENTATION */
26
27#endif /* _XS_FORMDATA_H */