commit 253e627
Paul Wilde
·
2024-01-28 20:55:43 +0000 UTC
parent d86b96b
make compatible with subway tooter app
2 files changed,
+50,
-1
+23,
-1
1@@ -359,6 +359,12 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
2 }
3 }
4
5+ /* no code?
6+ I'm not sure of the impacts of this right now, but Subway Tooter does not
7+ provide a code so one must be generated */
8+ if (xs_is_null(code)){
9+ code = random_str();
10+ }
11 if (gtype && code && cid && csec && ruri) {
12 xs *app = app_get(cid);
13
14@@ -1408,7 +1414,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
15 const char *type = xs_dict_get(msg, "type");
16 if (!xs_match(type, "Note|Question|Page|Article"))
17 continue;
18-
19 const char *from = NULL;
20 if (strcmp(type, "Page") == 0)
21 from = xs_dict_get(msg, "audience");
22@@ -1622,6 +1627,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
23 status = 200;
24 }
25 else
26+ if (strcmp(cmd, "/v2/filters") == 0) { /** **/
27+ /* snac will never have filters
28+ * but still, without a v2 endpoint a short delay is introduced
29+ * in some apps */
30+ *body = xs_dup("[]");
31+ *ctype = "application/json";
32+ status = 200;
33+ }
34+ else
35 if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
36 /* snac will never support a list of favourites */
37 *body = xs_dup("[]");
38@@ -1990,6 +2004,14 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
39 if (!xs_is_null(payload))
40 args = xs_json_loads(payload);
41 }
42+ else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded"))
43+ {
44+ // Some apps send form data instead of json so we should cater for those
45+ if (!xs_is_null(payload)) {
46+ xs *upl = xs_url_dec(payload);
47+ args = xs_url_vars(upl);
48+ }
49+ }
50 else
51 args = xs_dup(xs_dict_get(req, "p_vars"));
52
+27,
-0
1@@ -0,0 +1,27 @@
2+/* copyright (c) 2022 - 2024 grunfink et al. / MIT license */
3+#include "xs.h"
4+
5+#ifndef _XS_FORMDATA_H
6+
7+#define _XS_FORMDATA_H
8+
9+xs_val *xs_formdata_loads(const xs_str *formdata);
10+
11+#ifdef XS_IMPLEMENTATION
12+
13+/** IMPLEMENTATION **/
14+
15+xs_val *xs_formdata_loads(const xs_str *formdata)
16+/* loads a string in formdata format and converts to a multiple data */
17+{
18+ xs_val *v = NULL;
19+ xs_list *args = xs_split(formdata, "&");
20+ int i = 0;
21+ while (){}
22+ printf("args: %s\r\n", args); fflush(stdout);
23+ printf("data: %s\r\n", formdata); fflush(stdout);
24+}
25+
26+#endif /* XS_IMPLEMENTATION */
27+
28+#endif /* _XS_FORMDATA_H */