|
|
@ -234,6 +234,20 @@ static int dpi_respond_err(int fd, const char *fmt, ...) {
|
|
|
|
return rc;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int html_error(int fd, const char *fmt, ...) {
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
int err = errno;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
rc = write_buf(fd, "\n<strong>Error</strong>:\n");
|
|
|
|
|
|
|
|
rc |= vdprintf(fd, fmt, ap);
|
|
|
|
|
|
|
|
if (err != 0) rc |= dprintf(fd, ": %s", strerror(err));
|
|
|
|
|
|
|
|
if (rc < 0) warn("dprintf");
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (close(fd) < 0) warn("close");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *zet_get_title_fd(int fd, char *buf, size_t len) {
|
|
|
|
static char *zet_get_title_fd(int fd, char *buf, size_t len) {
|
|
|
|
if (fd < 0) return NULL;
|
|
|
|
if (fd < 0) return NULL;
|
|
|
|
int rc = read_some(fd, (unsigned char *)buf, &len);
|
|
|
|
int rc = read_some(fd, (unsigned char *)buf, &len);
|
|
|
@ -383,8 +397,6 @@ static int zet_search_close(struct zet_search *sz) {
|
|
|
|
static int dpi_serve_zet_all(int fd) {
|
|
|
|
static int dpi_serve_zet_all(int fd) {
|
|
|
|
int rc;
|
|
|
|
int rc;
|
|
|
|
struct zet_search zs;
|
|
|
|
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");
|
|
|
|
rc = dpi_send_header(fd, "text/html");
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
|
|
|
|
rc = dprintf(fd,
|
|
|
|
rc = dprintf(fd,
|
|
|
@ -394,19 +406,15 @@ static int dpi_serve_zet_all(int fd) {
|
|
|
|
"</head>"
|
|
|
|
"</head>"
|
|
|
|
"<body style=\"margin:0\">");
|
|
|
|
"<body style=\"margin:0\">");
|
|
|
|
rc |= write_topbar(fd, PAGE_ALL, NULL, NULL);
|
|
|
|
rc |= write_topbar(fd, PAGE_ALL, NULL, NULL);
|
|
|
|
rc |= write_buf(fd, "<ul>");
|
|
|
|
if (rc < 0) { warn("write"); close(fd); return 0; }
|
|
|
|
|
|
|
|
rc = zet_search_start(&zs, NULL, NULL);
|
|
|
|
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to list");
|
|
|
|
|
|
|
|
rc = write_buf(fd, "<ul>");
|
|
|
|
if (rc < 0) { warn("write"); close(fd); return 0; }
|
|
|
|
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);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to search");
|
|
|
|
rc = dprintf(fd,
|
|
|
|
|
|
|
|
"\n<strong>Error</strong>: %s\n",
|
|
|
|
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
if (rc < 0) warnx("dprintf");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == NULL) break;
|
|
|
|
if (id == NULL) break;
|
|
|
|
char title_buf[128];
|
|
|
|
char title_buf[128];
|
|
|
|
char *title = zet_get_title(id, title_buf, sizeof(title_buf));
|
|
|
|
char *title = zet_get_title(id, title_buf, sizeof(title_buf));
|
|
|
@ -442,8 +450,6 @@ static int dpi_serve_zet_recent(int fd) {
|
|
|
|
int capacity = 0;
|
|
|
|
int capacity = 0;
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
struct zet_mtime *zets = NULL;
|
|
|
|
struct zet_mtime *zets = NULL;
|
|
|
|
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");
|
|
|
|
rc = dpi_send_header(fd, "text/html");
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); goto cleanup; }
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); goto cleanup; }
|
|
|
|
rc = dprintf(fd,
|
|
|
|
rc = dprintf(fd,
|
|
|
@ -453,6 +459,9 @@ static int dpi_serve_zet_recent(int fd) {
|
|
|
|
"</head>"
|
|
|
|
"</head>"
|
|
|
|
"<body style=\"margin:0\">");
|
|
|
|
"<body style=\"margin:0\">");
|
|
|
|
rc |= write_topbar(fd, PAGE_RECENT, NULL, NULL);
|
|
|
|
rc |= write_topbar(fd, PAGE_RECENT, NULL, NULL);
|
|
|
|
|
|
|
|
if (rc < 0) { warn("write"); goto cleanup; }
|
|
|
|
|
|
|
|
rc = zet_search_start(&zs, NULL, NULL);
|
|
|
|
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to list");
|
|
|
|
rc |= write_buf(fd, "<ul>");
|
|
|
|
rc |= write_buf(fd, "<ul>");
|
|
|
|
if (rc < 0) { warn("write"); goto cleanup; }
|
|
|
|
if (rc < 0) { warn("write"); goto cleanup; }
|
|
|
|
const char *id;
|
|
|
|
const char *id;
|
|
|
@ -541,9 +550,6 @@ static int dpi_serve_zet_search(int fd, char *qs) {
|
|
|
|
query = query_unescaped;
|
|
|
|
query = query_unescaped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rc = zet_search_start(&zs, NULL, query);
|
|
|
|
|
|
|
|
if (rc < 0) return dpi_respond_err(fd, "Unable to list");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rc = dpi_send_header(fd, "text/html");
|
|
|
|
rc = dpi_send_header(fd, "text/html");
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
|
|
|
|
rc = dprintf(fd,
|
|
|
|
rc = dprintf(fd,
|
|
|
@ -554,19 +560,15 @@ static int dpi_serve_zet_search(int fd, char *qs) {
|
|
|
|
"<body style=\"margin:0\">"
|
|
|
|
"<body style=\"margin:0\">"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
rc |= write_topbar(fd, PAGE_SEARCH, query, NULL);
|
|
|
|
rc |= write_topbar(fd, PAGE_SEARCH, query, NULL);
|
|
|
|
rc |= write_buf(fd, "<ul>");
|
|
|
|
if (rc < 0) { warn("write"); close(fd); return 0; }
|
|
|
|
|
|
|
|
rc = zet_search_start(&zs, NULL, query);
|
|
|
|
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to list");
|
|
|
|
|
|
|
|
rc = write_buf(fd, "<ul>");
|
|
|
|
if (rc < 0) { warn("write"); close(fd); return 0; }
|
|
|
|
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);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to search");
|
|
|
|
rc = dprintf(fd,
|
|
|
|
|
|
|
|
"\n<strong>Error</strong>: %s\n",
|
|
|
|
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
if (rc < 0) warnx("dprintf");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == NULL) break;
|
|
|
|
if (id == NULL) break;
|
|
|
|
char title_buf[128];
|
|
|
|
char title_buf[128];
|
|
|
|
char *title = zet_get_title(id, title_buf, sizeof(title_buf));
|
|
|
|
char *title = zet_get_title(id, title_buf, sizeof(title_buf));
|
|
|
@ -859,21 +861,13 @@ static int dpi_serve_zet(int fd, char *path) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
|
|
|
|
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
|
|
|
|
if (note_fd >= 0) rc = lseek(note_fd, 0, SEEK_SET);
|
|
|
|
if (note_fd >= 0) rc = lseek(note_fd, 0, SEEK_SET);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to read file");
|
|
|
|
rc = dprintf(fd, "\n<strong>Error</strong>: %s", strerror(errno));
|
|
|
|
|
|
|
|
if (rc < 0) warnx("dprintf");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rc |= write_buf(fd, "<body>");
|
|
|
|
rc |= write_buf(fd, "<body>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *text = note_fd >= 0 ? read_full(note_fd) : NULL;
|
|
|
|
char *text = note_fd >= 0 ? read_full(note_fd) : NULL;
|
|
|
|
if (text == NULL) {
|
|
|
|
if (text == NULL) return html_error(fd, "Unable to read file");
|
|
|
|
rc = dprintf(fd, "\n<strong>Error</strong>: %s", strerror(errno));
|
|
|
|
|
|
|
|
if (rc < 0) warnx("dprintf");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct sd_callbacks callbacks;
|
|
|
|
struct sd_callbacks callbacks;
|
|
|
|
struct zet_renderopt options;
|
|
|
|
struct zet_renderopt options;
|
|
|
@ -912,7 +906,7 @@ static int dpi_serve_zet(int fd, char *path) {
|
|
|
|
struct zet_search zs;
|
|
|
|
struct zet_search zs;
|
|
|
|
bool first = true;
|
|
|
|
bool first = true;
|
|
|
|
rc = zet_search_start(&zs, id, NULL);
|
|
|
|
rc = zet_search_start(&zs, id, NULL);
|
|
|
|
if (rc < 0) warn("zet_search_start");
|
|
|
|
if (rc < 0) return html_error(fd, "Unable to list");
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
const char *result_id;
|
|
|
|
const char *result_id;
|
|
|
|
rc = zet_search_next(&zs, &result_id);
|
|
|
|
rc = zet_search_next(&zs, &result_id);
|
|
|
|