#define _XOPEN_SOURCE 700 #include #include #include #include "blog.h" 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")); printf("Status: 200 OK\r\n"); printf("Content-Type: text/plain\r\n\r\n"); read_post_data(); if (!verify_creds(find_post_data("username"), find_post_data("password"))) { // handle invalid login } for (char **e = environ; e && *e; e++) { puts(*e); } 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(""); puts(""); puts(""); return 0; }