diff --git a/zet.dpi.c b/zet.dpi.c index e18e65f..fa13a1d 100644 --- a/zet.dpi.c +++ b/zet.dpi.c @@ -54,19 +54,20 @@ struct http_request { struct zet_search { DIR *dir; - char *id; + const char *id; char *query; }; enum page { PAGE_NEW, PAGE_ALL, + PAGE_HEADS, PAGE_ZET, PAGE_SEARCH, }; static int count_lines_in(const char *str) { - int count = 0; + int count = 1; char c; int col = 0; while ((c = *str++)) { @@ -79,7 +80,7 @@ static int count_lines_in(const char *str) { } static int count_lines(int fd) { - int count = 0; + int count = 1; do { unsigned char buf[4096]; size_t len = sizeof(buf)-1; @@ -124,8 +125,13 @@ static int write_html(int fd, const char *buf, size_t len) { static int write_topbar(int fd, enum page page, const char *id, const char *title) { int rc = write_buf(fd, "
"); + if (page == PAGE_HEADS) rc |= write_buf(fd, ""); + rc |= write_buf(fd, "Heads"); + if (page == PAGE_HEADS) rc |= write_buf(fd, ""); + + rc |= write_buf(fd, " "); if (page == PAGE_ALL) rc |= write_buf(fd, ""); - rc |= write_buf(fd, "All"); + rc |= write_buf(fd, "All"); if (page == PAGE_ALL) rc |= write_buf(fd, ""); rc |= write_buf(fd, " "); @@ -274,7 +280,7 @@ static int zet_matches_query(const char *id, const char *query) { return found ? 1 : 0; } -static int zet_search_start(struct zet_search *zs, char *id, char *query) { +static int zet_search_start(struct zet_search *zs, const char *id, char *query) { zs->dir = opendir(zet_dir); if (zs->dir == NULL) return -1; zs->id = id; @@ -286,8 +292,8 @@ static int zet_search_next(struct zet_search *zs, const char **idp) { int rc; struct dirent *ent; const char *id; - char *const dest_id = zs->id; - char *const query = zs->query; + const char *dest_id = zs->id; + const char *query = zs->query; while (1) { errno = 0; ent = readdir(zs->dir); @@ -319,7 +325,7 @@ static int zet_search_close(struct zet_search *sz) { return closedir(sz->dir); } -static int dpi_serve_zet_index(int fd) { +static int dpi_serve_zet_all(int fd) { int rc; struct zet_search zs; rc = zet_search_start(&zs, NULL, NULL); @@ -328,7 +334,7 @@ static int dpi_serve_zet_index(int fd) { if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; } rc = dprintf(fd, "" - "Notes" + "Notes - All" "" "" ""); @@ -369,6 +375,72 @@ static int dpi_serve_zet_index(int fd) { return 0; } +static int dpi_serve_zet_heads(int fd) { + int rc; + struct zet_search zs; + rc = zet_search_start(&zs, NULL, NULL); + if (rc < 0) return dpi_respond_err(fd, "Unable to list"); + rc = dpi_send_header(fd, "text/html"); + if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; } + rc = dprintf(fd, + "" + "Notes - Heads" + "" + "" + ""); + rc |= write_topbar(fd, PAGE_HEADS, NULL, NULL); + rc |= write_buf(fd, ""); + if (rc < 0) { warn("dprintf"); close(fd); return 0; } + rc = zet_search_close(&zs); + if (rc < 0) warn("closedir"); + close(fd); + return 0; +} + + static void unescape(char *buf, size_t len, const char *str) { struct buf *ob = bufnew(1024); houdini_unescape_url(ob, str, strlen(str)); @@ -620,7 +692,8 @@ static int dpi_serve_zet(int fd, char *path) { char *hash, *query; parse_req_uri(path, &hash, &query); - if (!strcmp(path, "/")) return dpi_serve_zet_index(fd); + if (!strcmp(path, "/")) return dpi_serve_zet_heads(fd); + if (!strcmp(path, "/all")) return dpi_serve_zet_all(fd); if (!strcmp(path, "/search")) return dpi_serve_zet_search(fd, query); if (!strcmp(path, "/new")) return dpi_serve_zet_new(fd);