commit 07be372

default  ·  2023-08-12 19:46:54 +0000 UTC
parent 94149d2
Some mastoapi tweaks to support the semaphore.social web client.
2 files changed,  +18, -6
+8, -4
 1@@ -153,7 +153,7 @@ void httpd_connection(FILE *f)
 2     d_char *body = NULL;
 3     int b_size   = 0;
 4     char *ctype  = NULL;
 5-    xs *headers  = NULL;
 6+    xs *headers  = xs_dict_new();
 7     xs *q_path   = NULL;
 8     xs *payload  = NULL;
 9     xs *etag     = NULL;
10@@ -232,9 +232,10 @@ void httpd_connection(FILE *f)
11 #endif
12 
13     }
14-
15-    /* let's go */
16-    headers = xs_dict_new();
17+    else
18+    if (strcmp(method, "OPTIONS") == 0) {
19+        status = 200;
20+    }
21 
22     /* unattended? it's an error */
23     if (status == 0) {
24@@ -275,6 +276,9 @@ void httpd_connection(FILE *f)
25     if (strcmp(method, "HEAD") == 0)
26         body = xs_free(body);
27 
28+    headers = xs_dict_append(headers, "access-control-allow-origin", "*");
29+    headers = xs_dict_append(headers, "access-control-allow-headers", "*");
30+
31     xs_httpd_response(f, status, headers, body, b_size);
32 
33     fclose(f);
+10, -2
 1@@ -11,6 +11,7 @@
 2 #include "xs_glob.h"
 3 #include "xs_set.h"
 4 #include "xs_random.h"
 5+#include "xs_httpd.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -233,6 +234,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
10 
11     if (i_ctype && xs_startswith(i_ctype, "application/json"))
12         args = xs_json_loads(payload);
13+    else
14+    if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded") && payload) {
15+        xs *upl = xs_url_dec(payload);
16+        args    = xs_url_vars(upl);
17+    }
18     else
19         args = xs_dup(xs_dict_get(req, "p_vars"));
20 
21@@ -954,6 +960,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
22             acct = xs_dict_append(acct, "url",          snac1.actor);
23             acct = xs_dict_append(acct, "header",       "");
24 
25+            xs *src = xs_json_loads("{\"privacy\":\"public\","
26+                    "\"sensitive\":false,\"fields\":[],\"note\":\"\"}");
27+            acct = xs_dict_append(acct, "source", src);
28+
29             xs *avatar = NULL;
30             char *av   = xs_dict_get(snac1.config, "avatar");
31 
32@@ -1458,8 +1468,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
33         ins = xs_dict_append(ins, "languages", l1);
34 
35         xs *d1 = xs_dict_new();
36-        xs *wss = xs_replace(srv_baseurl, "https:", "wss:");
37-        d1 = xs_dict_append(d1, "streaming_api", wss);
38         ins = xs_dict_append(ins, "urls", d1);
39 
40         xs *z = xs_number_new(0);