|
|
@ -22,14 +22,6 @@
|
|
|
|
#include "sundown/buffer.h"
|
|
|
|
#include "sundown/buffer.h"
|
|
|
|
#include "sundown/houdini.h"
|
|
|
|
#include "sundown/houdini.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define NAV_ALL "<a href=\".\">All</a>"
|
|
|
|
|
|
|
|
#define NAV_NEW "<a href=\"new\">New</a>"
|
|
|
|
|
|
|
|
#define STRONG(html) "<strong>" html "</strong>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TOPBAR_NAV NAV_ALL " " NAV_NEW " "
|
|
|
|
|
|
|
|
#define TOPBAR_NAV_ALL STRONG(NAV_ALL) " " NAV_NEW " "
|
|
|
|
|
|
|
|
#define TOPBAR_NAV_NEW NAV_ALL " " STRONG(NAV_NEW) " "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const size_t sigil_size = sizeof("§")-1;
|
|
|
|
static const size_t sigil_size = sizeof("§")-1;
|
|
|
|
static const int id_length = 16;
|
|
|
|
static const int id_length = 16;
|
|
|
|
|
|
|
|
|
|
|
@ -60,6 +52,12 @@ struct zet_search {
|
|
|
|
char *id;
|
|
|
|
char *id;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum page {
|
|
|
|
|
|
|
|
PAGE_NEW,
|
|
|
|
|
|
|
|
PAGE_ALL,
|
|
|
|
|
|
|
|
PAGE_ZET,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int count_lines_in(const char *str) {
|
|
|
|
static int count_lines_in(const char *str) {
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
char c;
|
|
|
|
char c;
|
|
|
@ -116,6 +114,25 @@ static int write_html(int fd, const char *buf, size_t len) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int write_topbar(int fd, enum page page, const char *id) {
|
|
|
|
|
|
|
|
int rc = write_buf(fd, "<div>");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (page == PAGE_ALL) rc |= write_buf(fd, "<strong>");
|
|
|
|
|
|
|
|
rc |= write_buf(fd, "<a href=\".\">All</a>");
|
|
|
|
|
|
|
|
if (page == PAGE_ALL) rc |= write_buf(fd, "</strong>");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rc |= write_buf(fd, " ");
|
|
|
|
|
|
|
|
if (page == PAGE_NEW) rc |= write_buf(fd, "<strong>");
|
|
|
|
|
|
|
|
rc |= write_buf(fd, "<a href=\"new\">New</a>");
|
|
|
|
|
|
|
|
if (page == PAGE_NEW) rc |= write_buf(fd, "</strong>");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (page == PAGE_ZET) {
|
|
|
|
|
|
|
|
rc |= dprintf(fd, " <strong><code><a href=\"%s\">§%s</a></code></strong>", id, id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rc |= write_buf(fd, "</div>");
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int passthrough_note_html(int fd, int note_fd) {
|
|
|
|
static int passthrough_note_html(int fd, int note_fd) {
|
|
|
|
int rc;
|
|
|
|
int rc;
|
|
|
|
do {
|
|
|
|
do {
|
|
|
@ -266,10 +283,10 @@ static int dpi_serve_zet_index(int fd) {
|
|
|
|
"<title>Notes</title>"
|
|
|
|
"<title>Notes</title>"
|
|
|
|
"<meta charset=utf-8>"
|
|
|
|
"<meta charset=utf-8>"
|
|
|
|
"</head>"
|
|
|
|
"</head>"
|
|
|
|
"<body>"
|
|
|
|
"<body>");
|
|
|
|
"<div>" TOPBAR_NAV_ALL "</div>"
|
|
|
|
rc |= write_topbar(fd, PAGE_ALL, NULL);
|
|
|
|
"<ul>"
|
|
|
|
rc |= write_buf(fd, "<ul>");
|
|
|
|
);
|
|
|
|
if (rc < 0) { warn("write"); close(fd); return 0; }
|
|
|
|
const char *id;
|
|
|
|
const char *id;
|
|
|
|
while (1) {
|
|
|
|
while (1) {
|
|
|
|
rc = zet_search_next(&zs, &id);
|
|
|
|
rc = zet_search_next(&zs, &id);
|
|
|
@ -320,8 +337,9 @@ static int dpi_serve_zet_new(int fd) {
|
|
|
|
"<title>New Note</title>"
|
|
|
|
"<title>New Note</title>"
|
|
|
|
"<meta charset=utf-8>"
|
|
|
|
"<meta charset=utf-8>"
|
|
|
|
"</head>"
|
|
|
|
"</head>"
|
|
|
|
"<body>"
|
|
|
|
"<body>");
|
|
|
|
"<div>" TOPBAR_NAV_NEW "</div>"
|
|
|
|
write_topbar(fd, PAGE_NEW, NULL);
|
|
|
|
|
|
|
|
dprintf(fd,
|
|
|
|
"<form method=post action=\"%snew\" enctype=\"multipart/form-data\">"
|
|
|
|
"<form method=post action=\"%snew\" enctype=\"multipart/form-data\">"
|
|
|
|
"<textarea name=text cols=64 style=\"width:50%%;height:80%%\"></textarea><br>"
|
|
|
|
"<textarea name=text cols=64 style=\"width:50%%;height:80%%\"></textarea><br>"
|
|
|
|
"<input type=submit value=\"Save\">"
|
|
|
|
"<input type=submit value=\"Save\">"
|
|
|
@ -466,12 +484,13 @@ static int dpi_serve_zet(int fd, char *path) {
|
|
|
|
"<!doctype html><head>"
|
|
|
|
"<!doctype html><head>"
|
|
|
|
"<title>§%s</title>"
|
|
|
|
"<title>§%s</title>"
|
|
|
|
"<meta charset=utf-8>"
|
|
|
|
"<meta charset=utf-8>"
|
|
|
|
"</head><body>"
|
|
|
|
"</head><body>", id);
|
|
|
|
"<div>" TOPBAR_NAV " <strong><code><a href=\"%s\">§%s</a></code></strong></div>"
|
|
|
|
rc |= write_topbar(fd, PAGE_ZET, id);
|
|
|
|
|
|
|
|
rc |= dprintf(fd,
|
|
|
|
"<table style=\"width:100%%; height:100%%\"><tr>"
|
|
|
|
"<table style=\"width:100%%; height:100%%\"><tr>"
|
|
|
|
"<td style=\"width:50%%\"><form method=post action=\"%s%s\" enctype=\"multipart/form-data\" style=\"height:100%%\">"
|
|
|
|
"<td style=\"width:50%%\"><form method=post action=\"%s%s\" enctype=\"multipart/form-data\" style=\"height:100%%\">"
|
|
|
|
"<textarea name=text cols=64 rows=%d style=\"width:100%%\">"
|
|
|
|
"<textarea name=text cols=64 rows=%d style=\"width:100%%\">"
|
|
|
|
, id, id, id, server_url, id, rows);
|
|
|
|
, server_url, id, rows);
|
|
|
|
rc = passthrough_note_html(fd, note_fd);
|
|
|
|
rc = passthrough_note_html(fd, note_fd);
|
|
|
|
if (rc < 0) { warnx("passthrough_note_html"); close(fd); return 0; }
|
|
|
|
if (rc < 0) { warnx("passthrough_note_html"); close(fd); return 0; }
|
|
|
|
rc = dprintf(fd, "</textarea><br>"
|
|
|
|
rc = dprintf(fd, "</textarea><br>"
|
|
|
|