introduce gw_display_error so gw_display_index doesn't have double-duty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 8e8c6ac..5e0028e 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -188,7 +188,8 @@ static char *gw_gen_tree_header(char *);
static void gw_free_headers(struct gw_header *);
static const struct got_error* gw_display_open(struct gw_trans *, enum khttp,
enum kmime);
-static const struct got_error* gw_display_index(struct gw_trans *,
+static const struct got_error* gw_display_index(struct gw_trans *);
+static void gw_display_error(struct gw_trans *,
const struct got_error *);
static int gw_template(size_t, void *);
@@ -1183,18 +1184,17 @@ gw_display_open(struct gw_trans *gw_trans, enum khttp code, enum kmime mime)
}
static const struct got_error *
-gw_display_index(struct gw_trans *gw_trans, const struct got_error *err)
+gw_display_index(struct gw_trans *gw_trans)
{
enum kcgi_err kerr;
gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
kerr = khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
+ if (kerr)
+ return gw_kcgi_error(kerr);
- if (err)
- kerr = khttp_puts(gw_trans->gw_req, err->msg);
- else
- kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
- gw_query_funcs[gw_trans->action].template);
+ kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
+ gw_query_funcs[gw_trans->action].template);
if (kerr != KCGI_OK) {
khtml_close(gw_trans->gw_html_req);
return gw_kcgi_error(kerr);
@@ -1203,6 +1203,19 @@ gw_display_index(struct gw_trans *gw_trans, const struct got_error *err)
return gw_kcgi_error(khtml_close(gw_trans->gw_html_req));
}
+static void
+gw_display_error(struct gw_trans *gw_trans, const struct got_error *err)
+{
+ if (gw_display_open(gw_trans, KHTTP_200, gw_trans->mime) != NULL)
+ return;
+
+ if (khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0) != KCGI_OK)
+ return;
+
+ khttp_puts(gw_trans->gw_req, err->msg);
+ khtml_close(gw_trans->gw_html_req);
+}
+
static int
gw_template(size_t key, void *arg)
{
@@ -2882,12 +2895,12 @@ main(int argc, char *argv[])
if (error)
goto done;
- error = gw_display_index(gw_trans, error);
+ error = gw_display_index(gw_trans);
done:
if (error) {
gw_trans->mime = KMIME_TEXT_PLAIN;
gw_trans->action = GW_ERR;
- gw_display_index(gw_trans, error);
+ gw_display_error(gw_trans, error);
}
if (gw_malloc) {
free(gw_trans->gw_conf->got_repos_path);