commit 353e393
default
·
2023-04-08 04:09:05 +0000 UTC
parent 74817a4
New file mastoapi.c.
4 files changed,
+32,
-1
M
Makefile
+1,
-1
1@@ -5,7 +5,7 @@ CFLAGS?=-g -Wall
2 all: snac
3
4 snac: snac.o main.o data.o http.o httpd.o webfinger.o \
5- activitypub.o html.o utils.o format.o upgrade.o
6+ activitypub.o html.o utils.o format.o upgrade.o mastoapi.o
7 $(CC) $(CFLAGS) -L/usr/local/lib *.o -lcurl -lcrypto -pthread $(LDFLAGS) -o $@
8
9 .c.o:
M
httpd.c
+4,
-0
1@@ -185,6 +185,10 @@ void httpd_connection(FILE *f)
2 status = activitypub_post_handler(req, q_path,
3 payload, p_size, &body, &b_size, &ctype);
4
5+ if (status == 0)
6+ status = mastoapi_post_handler(req, q_path,
7+ payload, p_size, &body, &b_size, &ctype);
8+
9 if (status == 0)
10 status = html_post_handler(req, q_path,
11 payload, p_size, &body, &b_size, &ctype);
+24,
-0
1@@ -0,0 +1,24 @@
2+/* snac - A simple, minimalistic ActivityPub instance */
3+/* copyright (c) 2022 - 2023 grunfink / MIT license */
4+
5+#include "xs.h"
6+#include "xs_encdec.h"
7+#include "xs_json.h"
8+#include "xs_time.h"
9+
10+#include "snac.h"
11+
12+int mastoapi_post_handler(xs_dict *req, char *q_path, char *payload, int p_size,
13+ char **body, int *b_size, char **ctype)
14+{
15+ int status = 404;
16+
17+ if (!xs_startswith(q_path, "/api/v1/"))
18+ return 0;
19+
20+ xs *j = xs_json_dumps_pp(req, 4);
21+ printf("%s\n", j);
22+ printf("%s\n", payload);
23+
24+ return status;
25+}
M
snac.h
+3,
-0
1@@ -223,3 +223,6 @@ int resetpwd(snac *snac);
2 int job_fifo_ready(void);
3 void job_post(const xs_val *job, int urgent);
4 void job_wait(xs_val **job);
5+
6+int mastoapi_post_handler(xs_dict *req, char *q_path, char *payload, int p_size,
7+ char **body, int *b_size, char **ctype);