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 TDAEMON 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 : 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);
72 | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
73 | TCHROOT TSTRING { conf.chroot = $2; }
74 | TUSER TSTRING { conf.user = $2; }
81 vhost : TSERVER TSTRING '{' servopts locations '}' {
82 host->locations[0].match = (char*)"*";
85 if (host->cert == NULL || host->key == NULL ||
87 errx(1, "invalid vhost definition: %s", $2);
89 if (++ihost == HOSTSLEN)
90 errx(1, "too much vhosts defined");
93 loc = &host->locations[0];
96 | error '}' { yyerror("error in server directive"); }
99 servopts : /* empty */
103 servopt : TCERT TSTRING { host->cert = $2; }
104 | TKEY TSTRING { host->key = $2; }
105 | TROOT TSTRING { host->dir = $2; }
108 /* drop the starting '/', if any */
109 if (*host->cgi == '/')
115 locations : /* empty */
119 location : TLOCATION TSTRING '{' locopts '}' {
121 if (++iloc == LOCLEN)
122 errx(1, "too much location rules defined");
128 locopts : /* empty */
132 locopt : TDEFAULT TTYPE TSTRING {
133 free(loc->default_mime);
134 loc->default_mime = $3;
144 | TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }