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 struct location *loc = &hosts[0].locations[0];
34 size_t iloc = 0;
36 extern void yyerror(const char*);
38 %}
40 /* for bison: */
41 /* %define parse.error verbose */
43 %union {
44 char *str;
45 int num;
46 }
48 %token TDAEMON TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE TSERVER
49 %token TLOCATION TCERT TKEY TROOT TCGI TLANG
50 %token TERR
52 %token <str> TSTRING
53 %token <num> TNUM
54 %token <num> TBOOL
56 %%
58 conf : options vhosts ;
60 options : /* empty */
61 | options option
62 ;
64 option : TDAEMON TBOOL { conf.foreground = !$2; }
65 | TIPV6 TBOOL { conf.ipv6 = $2; }
66 | TPORT TNUM { conf.port = $2; }
67 | TPROTOCOLS TSTRING {
68 if (tls_config_parse_protocols(&conf.protos, $2) == -1)
69 errx(1, "invalid protocols string \"%s\"", $2);
70 }
71 | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
72 ;
74 vhosts : /* empty */
75 | vhosts vhost
76 ;
78 vhost : TSERVER TSTRING '{' servopts locations '}' {
79 host->locations[0].match = (char*)"*";
80 host->domain = $2;
82 if (host->cert == NULL || host->key == NULL ||
83 host->dir == NULL)
84 errx(1, "invalid vhost definition: %s", $2);
86 if (++ihost == HOSTSLEN)
87 errx(1, "too much vhosts defined");
89 host++;
90 loc = &host->locations[0];
91 iloc = 0;
92 }
93 | error '}' { yyerror("error in server directive"); }
94 ;
96 servopts : /* empty */
97 | servopts servopt
98 ;
100 servopt : TCERT TSTRING { host->cert = $2; }
101 | TKEY TSTRING { host->key = $2; }
102 | TROOT TSTRING { host->dir = $2; }
103 | TCGI TSTRING {
104 host->cgi = $2;
105 /* drop the starting '/', if any */
106 if (*host->cgi == '/')
107 host->cgi++;
109 | locopt
112 locations : /* empty */
113 | locations location
116 location : TLOCATION TSTRING '{' locopts '}' {
117 loc->match = $2;
118 if (++iloc == LOCLEN)
119 errx(1, "too much location rules defined");
120 loc++;
122 | error '}'
125 locopts : /* empty */
126 | locopts locopt
129 locopt : TDEFAULT TTYPE TSTRING {
130 free(loc->default_mime);
131 loc->default_mime = $3;
133 | TLANG TSTRING {
134 free(loc->lang);
135 loc->lang = $2;
137 | TINDEX TSTRING {
138 free(loc->index);
139 loc->index = $2;