aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--gmid.15
-rw-r--r--gmid.h1
-rw-r--r--lex.l1
-rw-r--r--parse.y8
-rw-r--r--sample.conf7
-rw-r--r--server.c11
7 files changed, 29 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 30ca1cf..76dbe3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
diff --git a/gmid.1 b/gmid.1
index 6905b40..7f70c2b 100644
--- a/gmid.1
+++ b/gmid.1
@@ -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
diff --git a/gmid.h b/gmid.h
index 5d4b5f8..892399c 100644
--- a/gmid.h
+++ b/gmid.h
@@ -59,6 +59,7 @@ struct vhost {
const char *key;
const char *dir;
const char *cgi;
+ char *lang;
int dirfd;
};
diff --git a/lex.l b/lex.l
index cb6326a..154fa69 100644
--- a/lex.l
+++ b/lex.l
@@ -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;
diff --git a/parse.y b/parse.y
index 286969a..36c3eac 100644
--- a/parse.y
+++ b/parse.y
@@ -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"
}
diff --git a/server.c b/server.c
index 0ce28d7..49d71f0 100644
--- a/server.c
+++ b/server.c
@@ -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)) {