commit 143e638fc66f14dae4403217e4c3ec7391a74f75
parent 194d9bd5c09a7085bff5a39f8982f1c8c7c1aee4
Author: William Casarin <jb55@jb55.com>
Date: Sat, 6 Mar 2021 17:18:34 -0800
outbox: initial stub
Diffstat:
6 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/Makefile b/Makefile
@@ -5,6 +5,7 @@ LDFLAGS = $(shell pkg-config --libs openssl libcurl)
OBJS = src/http.o \
src/base64.o \
src/inbox.o \
+ src/outbox.o \
src/json.o \
src/ubjson.o \
src/ap_json.o \
diff --git a/src/chibipub.c b/src/chibipub.c
@@ -15,6 +15,7 @@
#include "http.h"
#include "ap_json.h"
#include "inbox.h"
+#include "outbox.h"
#include "json.h"
#include "sigcheck.h"
@@ -98,25 +99,13 @@ static void init_test_webfinger(struct webfinger *finger)
);
}
-static inline void write_status(struct http_req *req, const char *status)
-{
- fprintf(req->client.socket_file, "HTTP/1.1 %s\r\n", status);
-}
-
-static inline void write_resp_header(struct http_req *req, const char *status)
-{
- write_status(req, status);
- fprintf(req->client.socket_file, "Connection: close\r\n");
- fprintf(req->client.socket_file, "\r\n");
-}
-
static int handle_webfinger(struct http_req *req)
{
struct webfinger finger;
init_test_webfinger(&finger);
- write_resp_header(req, "200 OK");
+ http_write_header(req, "200 OK");
fprintf(req->client.socket_file,
"{\"subject\": \"acct:%s\","
@@ -221,7 +210,7 @@ static int handle_inbox_request(struct http_req *req, struct cursor *arena)
fwrite("\n", 1, 1, out);
fclose(out);
- write_resp_header(req, "200 OK");
+ http_write_header(req, "200 OK");
return 1;
}
@@ -306,7 +295,7 @@ static int handle_self(struct http_req *req)
struct profile profile;
test_profile(&profile);
- write_resp_header(req, "200 OK");
+ http_write_header(req, "200 OK");
fprintf(req->client.socket_file,
"{"
@@ -357,6 +346,8 @@ static int handle_request(struct http_req *req, struct cursor *arena)
return handle_webfinger(req);
} else if (is_post(req) && patheq(req, "/inbox")) {
return handle_inbox_request(req, arena);
+ } else if (is_get(req) && patheq(req, "/outbox")) {
+ return handle_outbox_request(req);
} else if (is_get(req) &&
is_accept_activity(req) &&
streq(req->path, "/")) {
diff --git a/src/http.c b/src/http.c
@@ -155,3 +155,16 @@ int get_header(struct http_header *header, const char *match,
return 0;
}
+
+void http_write_status(struct http_req *req, const char *status)
+{
+ fprintf(req->client.socket_file, "HTTP/1.1 %s\r\n", status);
+}
+
+void http_write_header(struct http_req *req, const char *status)
+{
+ http_write_status(req, status);
+ fprintf(req->client.socket_file, "Connection: close\r\n");
+ fprintf(req->client.socket_file, "\r\n");
+}
+
diff --git a/src/http.h b/src/http.h
@@ -39,5 +39,7 @@ void init_http_req(struct http_req *req);
int get_header(struct http_header *header, const char *match, const char **result);
int parse_http_request(struct http_req *req, struct parser *p, int size);
void print_http_request(struct http_req *req);
+void http_write_status(struct http_req *req, const char *status);
+void http_write_header(struct http_req *req, const char *status);
#endif /* CHIBIPUB_HTTP */
diff --git a/src/outbox.c b/src/outbox.c
@@ -0,0 +1,8 @@
+
+#include "http.h"
+
+int handle_outbox_request(struct http_req *req)
+{
+ http_write_header(req, "501 Not Implemented");
+ return 1;
+}
diff --git a/src/outbox.h b/src/outbox.h
@@ -0,0 +1,9 @@
+
+#ifndef CHIBIPUB_OUTBOX
+#define CHIBIPUB_OUTBOX
+
+#include "http.h"
+
+int handle_outbox_request(struct http_req *);
+
+#endif /* CHIBIPUB_OUTBOX */