summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-08 06:09:05 +0200
committerGravatar default2023-04-08 06:09:05 +0200
commit353e393f4de68a209f2d454ca62516e180a3f54a (patch)
tree39c03f8abc377244aa06dc11d18d80b374f224a6
parentUpdated RELEASE_NOTES. (diff)
downloadsnac2-353e393f4de68a209f2d454ca62516e180a3f54a.tar.gz
snac2-353e393f4de68a209f2d454ca62516e180a3f54a.tar.xz
snac2-353e393f4de68a209f2d454ca62516e180a3f54a.zip
New file mastoapi.c.
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--httpd.c4
-rw-r--r--mastoapi.c24
-rw-r--r--snac.h3
4 files changed, 32 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3583001..05ddfc7 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS?=-g -Wall
5all: snac 5all: snac
6 6
7snac: snac.o main.o data.o http.o httpd.o webfinger.o \ 7snac: snac.o main.o data.o http.o httpd.o webfinger.o \
8 activitypub.o html.o utils.o format.o upgrade.o 8 activitypub.o html.o utils.o format.o upgrade.o mastoapi.o
9 $(CC) $(CFLAGS) -L/usr/local/lib *.o -lcurl -lcrypto -pthread $(LDFLAGS) -o $@ 9 $(CC) $(CFLAGS) -L/usr/local/lib *.o -lcurl -lcrypto -pthread $(LDFLAGS) -o $@
10 10
11.c.o: 11.c.o:
diff --git a/httpd.c b/httpd.c
index ec7a79f..183e194 100644
--- a/httpd.c
+++ b/httpd.c
@@ -186,6 +186,10 @@ void httpd_connection(FILE *f)
186 payload, p_size, &body, &b_size, &ctype); 186 payload, p_size, &body, &b_size, &ctype);
187 187
188 if (status == 0) 188 if (status == 0)
189 status = mastoapi_post_handler(req, q_path,
190 payload, p_size, &body, &b_size, &ctype);
191
192 if (status == 0)
189 status = html_post_handler(req, q_path, 193 status = html_post_handler(req, q_path,
190 payload, p_size, &body, &b_size, &ctype); 194 payload, p_size, &body, &b_size, &ctype);
191 } 195 }
diff --git a/mastoapi.c b/mastoapi.c
new file mode 100644
index 0000000..1e4e309
--- /dev/null
+++ b/mastoapi.c
@@ -0,0 +1,24 @@
1/* snac - A simple, minimalistic ActivityPub instance */
2/* copyright (c) 2022 - 2023 grunfink / MIT license */
3
4#include "xs.h"
5#include "xs_encdec.h"
6#include "xs_json.h"
7#include "xs_time.h"
8
9#include "snac.h"
10
11int mastoapi_post_handler(xs_dict *req, char *q_path, char *payload, int p_size,
12 char **body, int *b_size, char **ctype)
13{
14 int status = 404;
15
16 if (!xs_startswith(q_path, "/api/v1/"))
17 return 0;
18
19 xs *j = xs_json_dumps_pp(req, 4);
20 printf("%s\n", j);
21 printf("%s\n", payload);
22
23 return status;
24}
diff --git a/snac.h b/snac.h
index 6477040..b0ff33c 100644
--- a/snac.h
+++ b/snac.h
@@ -223,3 +223,6 @@ int resetpwd(snac *snac);
223int job_fifo_ready(void); 223int job_fifo_ready(void);
224void job_post(const xs_val *job, int urgent); 224void job_post(const xs_val *job, int urgent);
225void job_wait(xs_val **job); 225void job_wait(xs_val **job);
226
227int mastoapi_post_handler(xs_dict *req, char *q_path, char *payload, int p_size,
228 char **body, int *b_size, char **ctype);