summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-07-18 18:21:35 -0400
committerJakob Kaivo <jkk@ung.org>2019-07-18 18:21:35 -0400
commit1936b3a5d438fb7ab38f62978c9fd58c75e337f5 (patch)
treef63e35265372566226910a95e0aeaf071fe17e89
parent50676e311e268262d92016c7eefd35952ab2d539 (diff)
make blog entries actually html
-rw-r--r--blog.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/blog.c b/blog.c
index 026017d..950ad5e 100644
--- a/blog.c
+++ b/blog.c
@@ -10,10 +10,24 @@
#include <errno.h>
+#define DOCTYPE "<!DOCTYPE html>\n"
+#define HTML "<html lang=\"en\">\n"
+#define META "<meta charset=\"utf-8\">\n"
+#define TITLE "<title>%s</title>\n"
+#define ICON "<link type=\"shortcut icon\" href=\"/icon.png\">\n"
+#define STYLE "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\">\n"
+#define BODY "</html>\n<body>\n"
+
+#define HTML_HEAD DOCTYPE HTML META TITLE ICON STYLE BODY
+
+#define HTML_TAIL "</body>\n</html>\n"
+
int handle_post(void)
{
+ /*
printf("Status: 200 OK\r\n");
printf("Content-Type: text/plain\r\n\r\n");
+ */
read_post_data();
if (!authenticate(find_post_data("username"), find_post_data("password"))) {
@@ -54,13 +68,15 @@ int handle_post(void)
char *body = find_post_data("body");
if (body == NULL) {
- puts("body is null?!");
+ return 1;
}
+ dprintf(newpost, HTML_HEAD, title);
if (write(newpost, body, strlen(body)) != strlen(body)) {
printf("write: %s\n", strerror(errno));
return 0;
}
+ dprintf(newpost, HTML_TAIL);
close(newpost);
close(blogdir);
@@ -80,14 +96,8 @@ int main(void)
printf("Status: 200 OK\r\n");
printf("Content-Type: text/html\r\n\r\n");
- puts("<!DOCTYPE html>");
- puts("<html lang=\"en\">");
- puts("<meta charset=\"utf-8\">");
- puts("<title>Jakob Kaivo/blog</title>");
- puts("<link type=\"shortcut icon\" href=\"/icon.png\">");
- puts("<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\">");
- puts("</head>");
- puts("<body>");
+ printf(HTML_HEAD, "new blog entry");
+
printf("<form method=\"POST\" action=\"%s\">\n", getenv("DOCUMENT_URI"));
puts("<input type=\"text\" name=\"username\" placeholder=\"username\" size=\"80\"><br>");
puts("<input type=\"password\" name=\"password\" placeholder=\"password\" size=\"80\"><br>");
@@ -95,8 +105,8 @@ int main(void)
puts("<textarea name=\"body\" cols=\"80\" rows=\"24\"></textarea><br>");
puts("<input type=\"submit\">");
puts("</form>");
- puts("</body>");
- puts("</html>");
+
+ printf(HTML_TAIL);
return 0;
}