1 /* -*- mode: fundamental; indent-tabs-mode: t; -*- */
5 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
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.
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.
30 struct vhost *host = &hosts[0];
33 struct location *loc = &hosts[0].locations[0];
36 extern void yyerror(const char*);
41 /* %define parse.error verbose */
48 %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
49 %token TCHROOT TUSER TSERVER
50 %token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
59 conf : options vhosts ;
65 option : 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);
71 | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
72 | TCHROOT TSTRING { conf.chroot = $2; }
73 | TUSER TSTRING { conf.user = $2; }
80 vhost : TSERVER TSTRING '{' servopts locations '}' {
81 host->locations[0].match = (char*)"*";
84 if (host->cert == NULL || host->key == NULL ||
86 errx(1, "invalid vhost definition: %s", $2);
88 if (++ihost == HOSTSLEN)
89 errx(1, "too much vhosts defined");
92 loc = &host->locations[0];
95 | error '}' { yyerror("error in server directive"); }
98 servopts : /* empty */
102 servopt : TCERT TSTRING { host->cert = $2; }
103 | TKEY TSTRING { host->key = $2; }
104 | TROOT TSTRING { host->dir = $2; }
107 /* drop the starting '/', if any */
108 if (*host->cgi == '/')
114 locations : /* empty */
118 location : TLOCATION TSTRING '{' locopts '}' {
120 if (++iloc == LOCLEN)
121 errx(1, "too much location rules defined");
127 locopts : /* empty */
131 locopt : TDEFAULT TTYPE TSTRING {
132 free(loc->default_mime);
133 loc->default_mime = $3;
143 | TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }