Blame


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