fixup initial action querystring error and use the err.tmpl finally
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/gotweb/files/cgi-bin/gw_tmpl/err.tmpl b/gotweb/files/cgi-bin/gw_tmpl/err.tmpl
index 1281926..52b2cb6 100644
--- a/gotweb/files/cgi-bin/gw_tmpl/err.tmpl
+++ b/gotweb/files/cgi-bin/gw_tmpl/err.tmpl
@@ -14,7 +14,12 @@
@@search@@
</div>
<div id="content">
- @@content@@
+ <div id='err_title_wrapper'>
+ <div id='err_title'>Error</div>
+ </div>
+ <div id='err_content'>
+ @@content@@
+ </div>
</div>
@@siteowner@@
</div>
diff --git a/gotweb/files/htdocs/gotweb/gotweb.css b/gotweb/files/htdocs/gotweb/gotweb.css
index dd8d35a..33a8c27 100644
--- a/gotweb/files/htdocs/gotweb/gotweb.css
+++ b/gotweb/files/htdocs/gotweb/gotweb.css
@@ -363,6 +363,29 @@ body {
padding-bottom: 5px;
}
+/* err.tmpl */
+
+#err_title_wrapper {
+ clear: left;
+ float: left;
+ width: 100%;
+ background-color: LightSlateGray;
+ color: #ffffff;
+}
+#err_title {
+ padding-left: 10px;
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+#err_content {
+ clear: left;
+ float: left;
+ width: 100%;
+ padding-left: 20px;
+ padding-top: 20px;
+ padding-bottom: 20px;
+}
+
/* briefs.tmpl */
#briefs_title_wrapper {
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 97d12fc..4db052d 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -60,6 +60,7 @@ struct gw_trans {
struct ktemplate *gw_tmpl;
struct khtmlreq *gw_html_req;
struct kreq *gw_req;
+ const struct got_error *error;
const char *repo_name;
char *repo_path;
char *commit;
@@ -152,15 +153,14 @@ static const struct kvalid gw_keys[KEY__ZMAX] = {
{ kvalid_stringne, "path" },
};
-static const struct got_error *gw_init_gw_dir(struct gw_dir **, const char *);
static struct gw_header *gw_init_header(void);
static void gw_free_headers(struct gw_header *);
-static void gw_display_error(struct gw_trans *,
- const struct got_error *);
static int gw_template(size_t, void *);
+static const struct got_error *gw_error(struct gw_trans *);
+static const struct got_error *gw_init_gw_dir(struct gw_dir **, const char *);
static const struct got_error *gw_get_repo_description(char **,
struct gw_trans *, char *);
static const struct got_error *gw_get_repo_owner(char **, struct gw_trans *,
@@ -246,7 +246,7 @@ static struct gw_query_action gw_query_funcs[] = {
{ GW_BRIEFS, "briefs", gw_briefs, "gw_tmpl/briefs.tmpl" },
{ GW_COMMITS, "commits", gw_commits, "gw_tmpl/commit.tmpl" },
{ GW_DIFF, "diff", gw_diff, "gw_tmpl/diff.tmpl" },
- { GW_ERR, NULL, NULL, "gw_tmpl/err.tmpl" },
+ { GW_ERR, "error", gw_error, "gw_tmpl/err.tmpl" },
{ GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
{ GW_SUMMARY, "summary", gw_summary, "gw_tmpl/summry.tmpl" },
{ GW_TAG, "tag", gw_tag, "gw_tmpl/tag.tmpl" },
@@ -1637,16 +1637,22 @@ gw_parse_querystring(struct gw_trans *gw_trans)
return got_error_from_errno("asprintf");
/* get action and set function */
- if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION]))
+ if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION])) {
for (i = 0; i < nitems(gw_query_funcs); i++) {
action = &gw_query_funcs[i];
- if (action->func_name == NULL ||
- strcmp(action->func_name, p->parsed.s))
+ if (action->func_name == NULL)
continue;
-
- gw_trans->action = i;
- break;
+ if (strcmp(action->func_name,
+ p->parsed.s) == 0) {
+ gw_trans->action = i;
+ break;
+ }
}
+ if (gw_trans->action == -1) {
+ gw_trans->action = GW_ERR;
+ gw_trans->error = got_error_from_errno("bad action");
+ }
+ }
if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID])) {
if (asprintf(&gw_trans->commit, "%s",
@@ -1669,10 +1675,6 @@ gw_parse_querystring(struct gw_trans *gw_trans)
return got_error_from_errno("asprintf");
}
- if (action == NULL) {
- error = got_error_from_errno("invalid action");
- return error;
- }
error = gw_init_gw_dir(&gw_trans->gw_dir, gw_trans->repo_name);
if (error)
return error;
@@ -1775,16 +1777,14 @@ gw_display_index(struct gw_trans *gw_trans)
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)
+static const struct got_error *
+gw_error(struct gw_trans *gw_trans)
{
- if (gw_display_open(gw_trans, KHTTP_200, gw_trans->mime) != NULL)
- return;
+ enum kcgi_err kerr;
+
+ kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->error->msg);
- if (khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0) != KCGI_OK)
- return;
- khtml_puts(gw_trans->gw_html_req, err->msg);
- khtml_close(gw_trans->gw_html_req);
+ return gw_kcgi_error(kerr);
}
static int
@@ -3108,6 +3108,8 @@ gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header)
free(s);
}
+ free(refs_str);
+
error = got_object_id_str(&header->commit_id, header->id);
if (error)
return error;
@@ -4246,6 +4248,7 @@ main(int argc, char *argv[])
TAILQ_INIT(&gw_trans->gw_dirs);
TAILQ_INIT(&gw_trans->gw_headers);
+ gw_trans->action = -1;
gw_trans->page = 0;
gw_trans->repos_total = 0;
gw_trans->repo_path = NULL;
@@ -4273,11 +4276,6 @@ main(int argc, char *argv[])
else
error = gw_display_index(gw_trans);
done:
- if (error) {
- gw_trans->mime = KMIME_TEXT_PLAIN;
- gw_trans->action = GW_ERR;
- gw_display_error(gw_trans, error);
- }
if (gw_malloc) {
free(gw_trans->gw_conf->got_repos_path);
free(gw_trans->gw_conf->got_site_name);