restore code removed in b5f0780096f443734de8fc503ca92bf737e2a7b2 and complete code so sub directories work in gotweb This was pointed out by uwerler in IRC. ok stsp
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index e0c4b29..6ea20ef 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -2192,7 +2192,31 @@ gw_template(size_t key, void *arg)
const struct got_error *error = NULL;
enum kcgi_err kerr = KCGI_OK;
struct gw_trans *gw_trans = arg;
- char *img_src = NULL;
+ char *ati = NULL, *fic32 = NULL, *fic16 = NULL;
+ char *swm = NULL, *spt = NULL, *css = NULL, *logo = NULL;
+
+ if (asprintf(&ati, "%s%s", gw_trans->gw_conf->got_www_path,
+ "/apple-touch-icon.png") == -1)
+ goto err;
+ if (asprintf(&fic32, "%s%s", gw_trans->gw_conf->got_www_path,
+ "/favicon-32x32.png") == -1)
+ goto err;
+ if (asprintf(&fic16, "%s%s", gw_trans->gw_conf->got_www_path,
+ "/favicon-16x16.png") == -1)
+ goto err;
+ if (asprintf(&swm, "%s%s", gw_trans->gw_conf->got_www_path,
+ "/site.webmanifest") == -1)
+ goto err;
+ if (asprintf(&spt, "%s%s", gw_trans->gw_conf->got_www_path,
+ "/safari-pinned-tab.svg") == -1)
+ goto err;
+ if (asprintf(&css, "%s%s", gw_trans->gw_conf->got_www_path,
+ "/gotweb.css") == -1)
+ goto err;
+ if (asprintf(&logo, "%s%s%s", gw_trans->gw_conf->got_www_path,
+ gw_trans->gw_conf->got_www_path ? "/" : "",
+ gw_trans->gw_conf->got_logo) == -1)
+ goto err;
switch (key) {
case (TEMPL_HEAD):
@@ -2231,7 +2255,7 @@ gw_template(size_t key, void *arg)
return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
KATTR_REL, "apple-touch-icon", KATTR_SIZES, "180x180",
- KATTR_HREF, "/apple-touch-icon.png", KATTR__MAX);
+ KATTR_HREF, ati, KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
@@ -2239,7 +2263,7 @@ gw_template(size_t key, void *arg)
return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
- "32x32", KATTR_HREF, "/favicon-32x32.png", KATTR__MAX);
+ "32x32", KATTR_HREF, fic32, KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
@@ -2247,14 +2271,14 @@ gw_template(size_t key, void *arg)
return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
- "16x16", KATTR_HREF, "/favicon-16x16.png", KATTR__MAX);
+ "16x16", KATTR_HREF, fic16, KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
if (kerr != KCGI_OK)
return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
- KATTR_REL, "manifest", KATTR_HREF, "/site.webmanifest",
+ KATTR_REL, "manifest", KATTR_HREF, swm,
KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
@@ -2263,7 +2287,7 @@ gw_template(size_t key, void *arg)
return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
KATTR_REL, "mask-icon", KATTR_HREF,
- "/safari-pinned-tab.svg", KATTR__MAX);
+ spt, KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
@@ -2271,7 +2295,7 @@ gw_template(size_t key, void *arg)
return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
KATTR_REL, "stylesheet", KATTR_TYPE, "text/css",
- KATTR_HREF, "/gotweb.css", KATTR__MAX);
+ KATTR_HREF, css, KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
@@ -2288,20 +2312,13 @@ gw_template(size_t key, void *arg)
KATTR_TARGET, "_sotd", KATTR__MAX);
if (kerr != KCGI_OK)
return 0;
- if (asprintf(&img_src, "/%s",
- gw_trans->gw_conf->got_logo) == -1)
- return 0;
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_IMG,
- KATTR_SRC, img_src, KATTR__MAX);
- if (kerr != KCGI_OK) {
- free(img_src);
+ KATTR_SRC, logo, KATTR__MAX);
+ if (kerr != KCGI_OK)
return 0;
- }
kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
- if (kerr != KCGI_OK) {
- free(img_src);
+ if (kerr != KCGI_OK)
return 0;
- }
break;
case (TEMPL_SITEPATH):
error = gw_output_site_link(gw_trans);
@@ -2379,7 +2396,23 @@ gw_template(size_t key, void *arg)
default:
return 0;
}
+ free(ati);
+ free(fic32);
+ free(fic16);
+ free(swm);
+ free(spt);
+ free(css);
+ free(logo);
return 1;
+err:
+ free(ati);
+ free(fic32);
+ free(fic16);
+ free(swm);
+ free(spt);
+ free(css);
+ free(logo);
+ return 0;
}
static const struct got_error *
@@ -4701,6 +4734,7 @@ main(int argc, char *argv[])
done:
if (gw_malloc) {
free(gw_trans->gw_conf->got_repos_path);
+ free(gw_trans->gw_conf->got_www_path);
free(gw_trans->gw_conf->got_site_name);
free(gw_trans->gw_conf->got_site_owner);
free(gw_trans->gw_conf->got_site_link);
diff --git a/gotweb/gotweb.conf.5 b/gotweb/gotweb.conf.5
index 62d2057..d1056ee 100644
--- a/gotweb/gotweb.conf.5
+++ b/gotweb/gotweb.conf.5
@@ -88,6 +88,8 @@ Set the displayed site name title.
Set the displayed site owner.
.It Ic got_show_site_owner Ar on | off
Toggle display of the site owner.
+.It Ic got_www_path Ar string
+Set the public gotweb httpd path.
.El
.Sh EXAMPLES
These are the currently configurable items for
@@ -101,6 +103,7 @@ with their default values.
#
got_repos_path "/got/public"
+got_www_path "/gotweb"
#got_max_repos 100
#got_max_repos_display 25
diff --git a/gotweb/gotweb.h b/gotweb/gotweb.h
index c2c8f70..0f7fca0 100644
--- a/gotweb/gotweb.h
+++ b/gotweb/gotweb.h
@@ -27,6 +27,7 @@
#define GOTWEB_GOT_DIR ".got"
#define GOTWEB_GIT_DIR ".git"
+#define D_GOTWWW ""
#define D_GOTPATH "/got/public"
#define D_SITENAME "Gotweb"
#define D_SITEOWNER "Got Owner"
@@ -48,6 +49,7 @@
struct gotweb_config {
char *got_repos_path;
+ char *got_www_path;
char *got_site_name;
char *got_site_owner;
char *got_site_link;
diff --git a/gotweb/parse.y b/gotweb/parse.y
index 93c6e03..c662466 100644
--- a/gotweb/parse.y
+++ b/gotweb/parse.y
@@ -130,7 +130,16 @@ boolean : STRING {
;
main : GOT_REPOS_PATH STRING {
gw_conf->got_repos_path = strdup($2);
- if (gw_conf->got_repos_path== NULL) {
+ if (gw_conf->got_repos_path == NULL) {
+ free($2);
+ yyerror("strdup");
+ YYERROR;
+ }
+ free($2);
+ }
+ | GOT_WWW_PATH STRING {
+ gw_conf->got_www_path = strdup($2);
+ if (gw_conf->got_www_path == NULL) {
free($2);
yyerror("strdup");
YYERROR;
@@ -265,6 +274,7 @@ lookup(char *s)
{ "got_site_link", GOT_SITE_LINK },
{ "got_site_name", GOT_SITE_NAME },
{ "got_site_owner", GOT_SITE_OWNER },
+ { "got_www_path", GOT_WWW_PATH },
};
const struct keywords *p;
@@ -597,6 +607,11 @@ parse_gotweb_config(struct gotweb_config **gconf, const char *filename)
gerror = got_error_from_errno("strdup");
goto done;
}
+ gw_conf->got_www_path = strdup(D_GOTWWW);
+ if (gw_conf->got_www_path == NULL) {
+ gerror = got_error_from_errno("strdup");
+ goto done;
+ }
gw_conf->got_site_name = strdup(D_SITENAME);
if (gw_conf->got_site_name == NULL) {
gerror = got_error_from_errno("strdup");