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];
37 const char *config_path;
39 void yyerror(const char*);
40 int parse_portno(const char*);
41 void parse_conf(const char*);
46 /* %define parse.error verbose */
53 %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
54 %token TCHROOT TUSER TSERVER
55 %token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
64 conf : options vhosts ;
70 option : TIPV6 TBOOL { conf.ipv6 = $2; }
71 | TPORT TNUM { conf.port = $2; }
72 | TPROTOCOLS TSTRING {
73 if (tls_config_parse_protocols(&conf.protos, $2) == -1)
74 errx(1, "invalid protocols string \"%s\"", $2);
76 | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
77 | TCHROOT TSTRING { conf.chroot = $2; }
78 | TUSER TSTRING { conf.user = $2; }
85 vhost : TSERVER TSTRING '{' servopts locations '}' {
86 host->locations[0].match = (char*)"*";
89 if (host->cert == NULL || host->key == NULL ||
91 errx(1, "invalid vhost definition: %s", $2);
93 if (++ihost == HOSTSLEN)
94 errx(1, "too much vhosts defined");
97 loc = &host->locations[0];
100 | error '}' { yyerror("error in server directive"); }
103 servopts : /* empty */
107 servopt : TCERT TSTRING { host->cert = $2; }
108 | TKEY TSTRING { host->key = $2; }
109 | TROOT TSTRING { host->dir = $2; }
112 /* drop the starting '/', if any */
113 if (*host->cgi == '/')
119 locations : /* empty */
123 location : TLOCATION TSTRING '{' locopts '}' {
125 if (++iloc == LOCLEN)
126 errx(1, "too much location rules defined");
132 locopts : /* empty */
136 locopt : TDEFAULT TTYPE TSTRING {
137 if (loc->default_mime != NULL)
138 yyerror("`default type' specified more than once");
139 loc->default_mime = $3;
142 if (loc->lang != NULL)
143 yyerror("`lang' specified more than once");
147 if (loc->index != NULL)
148 yyerror("`index' specified more than once");
151 | TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }
157 yyerror(const char *msg)
160 fprintf(stderr, "%s:%d: %s\n", config_path, yylineno, msg);
164 parse_portno(const char *p)
169 n = strtonum(p, 0, UINT16_MAX, &errstr);
171 errx(1, "port number is %s: %s", errstr, p);
176 parse_conf(const char *path)
179 if ((yyin = fopen(path, "r")) == NULL)
180 fatal("cannot open config %s", path);