Blob


1 /* -*- mode: fundamental; indent-tabs-mode: t; -*- */
2 %{
4 /*
5 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
20 #include <err.h>
21 #include <stdio.h>
23 #include "gmid.h"
25 /*
26 * #define YYDEBUG 1
27 * int yydebug = 1;
28 */
30 struct vhost *host = &hosts[0];
31 size_t ihost = 0;
33 extern void yyerror(const char*);
35 %}
37 /* for bison: */
38 /* %define parse.error verbose */
40 %union {
41 char *str;
42 int num;
43 }
45 %token TDAEMON TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE TSERVER
46 %token TCERT TKEY TROOT TCGI
47 %token TERR
49 %token <str> TSTRING
50 %token <num> TNUM
51 %token <num> TBOOL
53 %%
55 conf : options vhosts ;
57 options : /* empty */
58 | options option
59 ;
61 option : TDAEMON TBOOL { conf.foreground = !$2; }
62 | TIPV6 TBOOL { conf.ipv6 = $2; }
63 | TPORT TNUM { conf.port = $2; }
64 | TPROTOCOLS TSTRING {
65 if (tls_config_parse_protocols(&conf.protos, $2) == -1)
66 errx(1, "invalid protocols string \"%s\"", $2);
67 }
68 | TMIME TSTRING TSTRING { add_mime($2, $3); }
69 | TDEFAULT TTYPE TSTRING { set_default_mime($3); }
70 ;
72 vhosts : /* empty */
73 | vhosts vhost
74 ;
76 vhost : TSERVER TSTRING '{' servopts '}' {
77 host->domain = $2;
79 if (host->cert == NULL || host->key == NULL ||
80 host->dir == NULL)
81 errx(1, "invalid vhost definition: %s", $2);
82 if (++ihost == HOSTSLEN)
83 errx(1, "too much vhosts defined");
84 host++;
85 }
86 | error '}' { yyerror("error in server directive"); }
87 ;
89 servopts : /* empty */
90 | servopts servopt
91 ;
93 servopt : TCERT TSTRING { host->cert = $2; }
94 | TKEY TSTRING { host->key = $2; }
95 | TROOT TSTRING { host->dir = $2; }
96 | TCGI TSTRING {
97 host->cgi = $2;
98 /* drop the starting '/', if any */
99 if (*host->cgi == '/')
100 host->cgi++;