diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | gmid.1 | 5 | ||||
-rw-r--r-- | gmid.h | 1 | ||||
-rw-r--r-- | lex.l | 1 | ||||
-rw-r--r-- | parse.y | 8 | ||||
-rw-r--r-- | sample.conf | 7 | ||||
-rw-r--r-- | server.c | 11 |
7 files changed, 29 insertions, 6 deletions
@@ -1,5 +1,7 @@ 2021-01-19 Omar Polo <op@omarpolo.com> + * parse.y (servopt): add "lang" server option + * Dockerfile: add a dockerfile 2021-01-18 Omar Polo <op@omarpolo.com> @@ -168,6 +168,11 @@ Enable the execution of CGI scripts if is a prefix of the user request string. An empty path "" will effectively enable the execution of any file with the executable bit set inside the root directory. +.It Ic lang Ar string +Specify the language tag for the text/gemini content served. +If not specified, no +.Dq lang +parameter will be added in the response. .El .Sh CGI When CGI scripts are enabled for a directory, a request for an @@ -59,6 +59,7 @@ struct vhost { const char *key; const char *dir; const char *cgi; + char *lang; int dirfd; }; @@ -58,6 +58,7 @@ protocols return TPROTOCOLS; mime return TMIME; default return TDEFAULT; type return TTYPE; +lang return TLANG; server return TSERVER; cert return TCERT; @@ -43,7 +43,7 @@ extern void yyerror(const char*); } %token TDAEMON TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE TSERVER -%token TCERT TKEY TROOT TCGI +%token TCERT TKEY TROOT TCGI TLANG %token TERR %token <str> TSTRING @@ -98,6 +98,10 @@ servopt : TCERT TSTRING { host->cert = $2; } /* drop the starting '/', if any */ if (*host->cgi == '/') host->cgi++; -} + } + | TLANG TSTRING { + free(host->lang); + host->lang = $2; + } ; diff --git a/sample.conf b/sample.conf index 08d6541..d9bf46f 100644 --- a/sample.conf +++ b/sample.conf @@ -14,11 +14,14 @@ server "example.com" { root "/var/gemini/example.com" } -# another example server, this time with CGI enabled for scripts in -# /cgi-bin/ server "it.example.com" { cert "/path/to/cert.pem" key "/path/to/key.pem" root "/var/gemini/example.com" + + # enable CGI scripts in /cgi-bin/ cgi "/cgi-bin/" + + # optional + lang "it" } @@ -249,14 +249,21 @@ handle_open_conn(struct pollfd *fds, struct client *c) int start_reply(struct pollfd *pfd, struct client *client, int code, const char *reason) { - char buf[1030]; /* status + ' ' + max reply len + \r\n\0 */ + char buf[1030]; /* status + ' ' + max reply len + \r\n\0 */ int len; client->code = code; client->meta = reason; client->state = S_INITIALIZING; - len = snprintf(buf, sizeof(buf), "%d %s\r\n", code, reason); + snprintf(buf, sizeof(buf), "%d ", code); + strlcat(buf, reason, sizeof(buf)); + if (!strcmp(reason, "text/gemini") && client->host->lang != NULL) { + strlcat(buf, "; lang=", sizeof(buf)); + strlcat(buf, client->host->lang, sizeof(buf)); + } + + len = strlcat(buf, "\r\n", sizeof(buf)); assert(len < (int)sizeof(buf)); switch (tls_write(client->ctx, buf, len)) { |