mirror of https://github.com/omar-polo/gmid.git
added index option
This commit is contained in:
parent
9adde3d8b2
commit
e7a2a99b5a
4
gmid.1
4
gmid.1
|
@ -177,6 +177,10 @@ Specify the language tag for the text/gemini content served.
|
|||
If not specified, no
|
||||
.Dq lang
|
||||
parameter will be added in the response.
|
||||
.It Ic index Ar string
|
||||
Set the directory index file.
|
||||
If not specified, it defaults to
|
||||
.Pa index.gmi
|
||||
.El
|
||||
.Sh CGI
|
||||
When CGI scripts are enabled for a directory, a request for an
|
||||
|
|
1
gmid.h
1
gmid.h
|
@ -65,6 +65,7 @@ struct vhost {
|
|||
char *lang;
|
||||
int dirfd;
|
||||
char *default_mime;
|
||||
char *index;
|
||||
};
|
||||
|
||||
extern struct vhost hosts[HOSTSLEN];
|
||||
|
|
3
lex.l
3
lex.l
|
@ -58,13 +58,14 @@ protocols return TPROTOCOLS;
|
|||
mime return TMIME;
|
||||
default return TDEFAULT;
|
||||
type return TTYPE;
|
||||
lang return TLANG;
|
||||
server return TSERVER;
|
||||
|
||||
cert return TCERT;
|
||||
key return TKEY;
|
||||
root return TROOT;
|
||||
cgi return TCGI;
|
||||
lang return TLANG;
|
||||
index return TINDEX;
|
||||
|
||||
[{}] return *yytext;
|
||||
|
||||
|
|
4
parse.y
4
parse.y
|
@ -106,4 +106,8 @@ servopt : TCERT TSTRING { host->cert = $2; }
|
|||
free(host->lang);
|
||||
host->lang = $2;
|
||||
}
|
||||
| TINDEX TSTRING {
|
||||
free(host->index);
|
||||
host->index = $2;
|
||||
}
|
||||
;
|
||||
|
|
|
@ -173,3 +173,14 @@ echo OK GET /invalid with cgi
|
|||
|
||||
check "should be running"
|
||||
quit
|
||||
|
||||
config '' 'index "foo.gmi"'
|
||||
checkconf
|
||||
run
|
||||
|
||||
eq "$(head /dir/)" "20 text/gemini" "Unexpected head for /"
|
||||
eq "$(get /dir/)" "# hello world$ln" "Unexpected body for error"
|
||||
echo OK GET /dir/ with custom index
|
||||
|
||||
check "should be running"
|
||||
quit
|
||||
|
|
19
server.c
19
server.c
|
@ -371,19 +371,14 @@ void
|
|||
send_dir(struct pollfd *fds, struct client *c)
|
||||
{
|
||||
size_t len;
|
||||
const char *index = "index.gmi";
|
||||
|
||||
/* guard against a re-entrant call:
|
||||
*
|
||||
* open_file -> send_dir -> open_file -> send_dir
|
||||
*
|
||||
* this can happen only if:
|
||||
/* guard against a re-entrant call: open_file -> send_dir ->
|
||||
* open_file -> send_dir. This can happen only if:
|
||||
*
|
||||
* - user requested a dir, say foo/
|
||||
* - we try to serve foo/index.gmi
|
||||
* - foo/index.gmi is a directory.
|
||||
*
|
||||
* It's an unlikely case, but can happen. We then redirect
|
||||
* to foo/index.gmi
|
||||
* - we try to serve foo/$INDEX
|
||||
* - foo/$INDEX is a directory.
|
||||
*/
|
||||
if (c->iri.path == c->sbuf) {
|
||||
goodbye(fds, c, TEMP_REDIRECT, c->sbuf);
|
||||
|
@ -406,7 +401,9 @@ send_dir(struct pollfd *fds, struct client *c)
|
|||
if (!ends_with(c->sbuf, "/"))
|
||||
strlcat(c->sbuf, "/", sizeof(c->sbuf));
|
||||
|
||||
len = strlcat(c->sbuf, "index.gmi", sizeof(c->sbuf));
|
||||
if (c->host->index != NULL)
|
||||
index = c->host->index;
|
||||
len = strlcat(c->sbuf, index, sizeof(c->sbuf));
|
||||
|
||||
if (len >= sizeof(c->sbuf)) {
|
||||
goodbye(fds, c, TEMP_FAILURE, "internal server error");
|
||||
|
|
Loading…
Reference in New Issue