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 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 ;
67 vhosts : /* empty */
68 | vhosts vhost
69 ;
71 vhost : TSERVER TSTRING '{' servopts '}' {
72 host->domain = $2;
74 if (host->cert == NULL || host->key == NULL ||
75 host->dir == NULL)
76 errx(1, "invalid vhost definition: %s", $2);
77 if (++ihost == HOSTSLEN)
78 errx(1, "too much vhosts defined");
79 host++;
80 }
81 | error '}' { yyerror("error in server directive"); }
82 ;
84 servopts : /* empty */
85 | servopts servopt
86 ;
88 servopt : TCERT TSTRING { host->cert = $2; }
89 | TKEY TSTRING { host->key = $2; }
90 | TROOT TSTRING { host->dir = $2; }
91 | TCGI TSTRING {
92 host->cgi = $2;
93 /* drop the starting '/', if any */
94 if (*host->cgi == '/')
95 host->cgi++;
96 }
97 ;