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
49 %token TCHROOT TUSER TSERVER
50 %token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
51 %token TERR
53 %token <str> TSTRING
54 %token <num> TNUM
55 %token <num> TBOOL
57 %%
59 conf : options vhosts ;
61 options : /* empty */
62 | options option
63 ;
65 option : TDAEMON TBOOL { conf.foreground = !$2; }
66 | TIPV6 TBOOL { conf.ipv6 = $2; }
67 | TPORT TNUM { conf.port = $2; }
68 | TPROTOCOLS TSTRING {
69 if (tls_config_parse_protocols(&conf.protos, $2) == -1)
70 errx(1, "invalid protocols string \"%s\"", $2);
71 }
72 | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
73 | TCHROOT TSTRING { conf.chroot = $2; }
74 | TUSER TSTRING { conf.user = $2; }
75 ;
77 vhosts : /* empty */
78 | vhosts vhost
79 ;
81 vhost : TSERVER TSTRING '{' servopts locations '}' {
82 host->locations[0].match = (char*)"*";
83 host->domain = $2;
85 if (host->cert == NULL || host->key == NULL ||
86 host->dir == NULL)
87 errx(1, "invalid vhost definition: %s", $2);
89 if (++ihost == HOSTSLEN)
90 errx(1, "too much vhosts defined");
92 host++;
93 loc = &host->locations[0];
94 iloc = 0;
95 }
96 | error '}' { yyerror("error in server directive"); }
97 ;
99 servopts : /* empty */
100 | servopts servopt
103 servopt : TCERT TSTRING { host->cert = $2; }
104 | TKEY TSTRING { host->key = $2; }
105 | TROOT TSTRING { host->dir = $2; }
106 | TCGI TSTRING {
107 host->cgi = $2;
108 /* drop the starting '/', if any */
109 if (*host->cgi == '/')
110 host->cgi++;
112 | locopt
115 locations : /* empty */
116 | locations location
119 location : TLOCATION TSTRING '{' locopts '}' {
120 loc->match = $2;
121 if (++iloc == LOCLEN)
122 errx(1, "too much location rules defined");
123 loc++;
125 | error '}'
128 locopts : /* empty */
129 | locopts locopt
132 locopt : TDEFAULT TTYPE TSTRING {
133 free(loc->default_mime);
134 loc->default_mime = $3;
136 | TLANG TSTRING {
137 free(loc->lang);
138 loc->lang = $2;
140 | TINDEX TSTRING {
141 free(loc->index);
142 loc->index = $2;
144 | TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }