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 TBOOL TSTRING TNUM
46 %token TDAEMON TIPV6 TPORT TPROTOCOLS TSERVER
47 %token TCERT TKEY TROOT TCGI
48 %token TERR
50 %token <str> TSTRING
51 %token <num> TNUM
52 %token <num> TBOOL
54 %%
56 conf : options vhosts ;
58 options : /* empty */
59 | options option
60 ;
62 option : TDAEMON TBOOL { conf.foreground = !$2; }
63 | TIPV6 TBOOL { conf.ipv6 = $2; }
64 | TPORT TNUM { conf.port = $2; }
65 | TPROTOCOLS TSTRING {
66 if (tls_config_parse_protocols(&conf.protos, $2) == -1)
67 errx(1, "invalid protocols string \"%s\"", $2);
68 }
69 ;
71 vhosts : /* empty */
72 | vhosts vhost
73 ;
75 vhost : TSERVER TSTRING '{' servopts '}' {
76 host->domain = $2;
78 if (host->cert == NULL || host->key == NULL ||
79 host->dir == NULL)
80 errx(1, "invalid vhost definition: %s", $2);
81 if (++ihost == HOSTSLEN)
82 errx(1, "too much vhosts defined");
83 host++;
84 }
85 | error '}' { yyerror("error in server directive"); }
86 ;
88 servopts : /* empty */
89 | servopts servopt
90 ;
92 servopt : TCERT TSTRING { host->cert = $2; }
93 | TKEY TSTRING { host->key = $2; }
94 | TROOT TSTRING { host->dir = $2; }
95 | TCGI TSTRING {
96 host->cgi = $2;
97 /* drop the starting '/', if any */
98 if (*host->cgi == '/')
99 host->cgi++;