From 2bc5ce287a9f15af8e299138f85e2a286708313b Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 17 Jul 2019 20:50:31 -0400 Subject: initial skeleton --- blog.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 blog.c diff --git a/blog.c b/blog.c new file mode 100644 index 0000000..d3c8e49 --- /dev/null +++ b/blog.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +extern char **environ; + +int handle_post(void) +{ + printf("Status: 301 Found\r\n"); + printf("Location: http%s://%s%s\r\n\r\n", getenv("HTTPS") ? "s" : "", getenv("HTTP_HOST"), getenv("DOCUMENT_URI")); + return 0; +} + +int show_entry(const char *path) +{ + printf("Status: 200 OK\r\n"); + printf("Content-Type: text/plain\r\n\r\n"); + puts(path); + return 0; +} + +int main(void) +{ + char *method = getenv("REQUEST_METHOD"); + if (!strcmp(method, "POST")) { + return handle_post(); + } + + char *path_info = getenv("PATH_INFO"); + if (path_info && *path_info && strcmp(path_info, "/")) { + return show_entry(path_info); + } + + printf("Status: 200 OK\r\n"); + printf("Content-Type: text/html\r\n\r\n"); + + puts(""); + puts(""); + puts(""); + puts("Jakob Kaivo/blog"); + puts(""); + puts(""); + puts(""); + puts(""); + printf("
\n", getenv("DOCUMENT_URI")); + puts("Username:
"); + puts("Password:
"); + puts("Title:
"); + puts("
"); + puts(""); + puts("
"); + + puts("
");
+	for (char **e = environ; e && *e; e++) {
+		puts(*e);
+	}
+	puts("
"); + + puts(""); + puts(""); + + return 0; +} -- cgit v1.2.1