summaryrefslogtreecommitdiff
path: root/browse.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2023-07-31 17:34:24 +0200
committerVincent Douillet <vincent@vdouillet.fr>2023-08-01 18:14:47 +0200
commit62b01654da4f1ae1a9aaeab106cea5e7bb9d77e3 (patch)
tree275b99f1fe4d12777f389045d6cd8411d5e6f324 /browse.c
parent89a76cdd3fa168902d83f4c043d2cc6629b40024 (diff)
handle kcgi errors
Diffstat (limited to 'browse.c')
-rw-r--r--browse.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/browse.c b/browse.c
index 65e3c5a..577183f 100644
--- a/browse.c
+++ b/browse.c
@@ -35,15 +35,16 @@
#include <string.h>
#include "browse.h"
+#include "cgi.h"
#include "config.h"
-#include "error.h"
#include "http.h"
#include "url.h"
#define URL_LENGTH_MAX 8192
/*
- * Checks that the path can be safely processed. Namely, it should not contain "..", which denotes an attempt to get out of the DATA_DIR root folder.
+ * Checks that the path can be safely processed. Namely, it should not contain
+ * "..", which denotes an attempt to get out of the DATA_DIR root folder.
*/
static bool
check_request_path(char *path)
@@ -105,20 +106,19 @@ browse(struct kreq * r)
}
http_open(r, KHTTP_200);
- if (KCGI_OK != khtml_open(&html, r, 0))
- return VAULT_CGI_ERROR;
+ K_OK(khtml_open(&html, r, 0));
/* build basic html page */
- khtml_elem(&html, KELEM_DOCTYPE);
- khtml_elem(&html, KELEM_HEAD);
- khtml_attr(&html, KELEM_META, KATTR_CHARSET, "utf-8", KATTR__MAX);
- khtml_elem(&html, KELEM_HTML);
- khtml_elem(&html, KELEM_BODY);
- khtml_elem(&html, KELEM_P);
- khtml_puts(&html, "/");
- khtml_closeelem(&html, 1);
+ K_OK(khtml_elem(&html, KELEM_DOCTYPE));
+ K_OK(khtml_elem(&html, KELEM_HEAD));
+ K_OK(khtml_attr(&html, KELEM_META, KATTR_CHARSET, "utf-8", KATTR__MAX));
+ K_OK(khtml_elem(&html, KELEM_HTML));
+ K_OK(khtml_elem(&html, KELEM_BODY));
+ K_OK(khtml_elem(&html, KELEM_P));
+ K_OK(khtml_puts(&html, "/"));
+ K_OK(khtml_closeelem(&html, 1));
- khtml_elem(&html, KELEM_UL);
+ K_OK(khtml_elem(&html, KELEM_UL));
while ((dir = readdir(data_dir)) != NULL) {
/* ignore special . and .. folders */
file_name = dir->d_name;
@@ -127,12 +127,12 @@ browse(struct kreq * r)
url_size = build_browse_url(r, url, URL_LENGTH_MAX, file_name);
if (url_size == 0 || url_size >= URL_LENGTH_MAX)
continue;
- khtml_elem(&html, KELEM_LI);
- khtml_attr(&html, KELEM_A, KATTR_HREF, url, KATTR__MAX);
- khtml_puts(&html, dir->d_name);
- khtml_closeelem(&html, 2);
+ K_OK(khtml_elem(&html, KELEM_LI));
+ K_OK(khtml_attr(&html, KELEM_A, KATTR_HREF, url, KATTR__MAX));
+ K_OK(khtml_puts(&html, dir->d_name));
+ K_OK(khtml_closeelem(&html, 2));
}
- khtml_close(&html);
+ K_OK(khtml_close(&html));
closedir(data_dir);
return VAULT_SUCCESS;