Blame


1 15902770 2021-01-15 op /* -*- mode: fundamental; indent-tabs-mode: t; -*- */
2 15902770 2021-01-15 op %{
3 15902770 2021-01-15 op
4 15902770 2021-01-15 op /*
5 15902770 2021-01-15 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
6 15902770 2021-01-15 op *
7 15902770 2021-01-15 op * Permission to use, copy, modify, and distribute this software for any
8 15902770 2021-01-15 op * purpose with or without fee is hereby granted, provided that the above
9 15902770 2021-01-15 op * copyright notice and this permission notice appear in all copies.
10 15902770 2021-01-15 op *
11 15902770 2021-01-15 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 15902770 2021-01-15 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 15902770 2021-01-15 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 15902770 2021-01-15 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 15902770 2021-01-15 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 15902770 2021-01-15 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 15902770 2021-01-15 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 15902770 2021-01-15 op */
19 15902770 2021-01-15 op
20 15902770 2021-01-15 op #include <err.h>
21 15902770 2021-01-15 op #include <stdio.h>
22 15902770 2021-01-15 op
23 15902770 2021-01-15 op #include "gmid.h"
24 15902770 2021-01-15 op
25 15902770 2021-01-15 op /*
26 15902770 2021-01-15 op * #define YYDEBUG 1
27 15902770 2021-01-15 op * int yydebug = 1;
28 15902770 2021-01-15 op */
29 15902770 2021-01-15 op
30 15902770 2021-01-15 op struct vhost *host = &hosts[0];
31 15902770 2021-01-15 op size_t ihost = 0;
32 15902770 2021-01-15 op
33 c8b74339 2021-01-24 op struct location *loc = &hosts[0].locations[0];
34 c8b74339 2021-01-24 op size_t iloc = 0;
35 c8b74339 2021-01-24 op
36 15902770 2021-01-15 op extern void yyerror(const char*);
37 15902770 2021-01-15 op
38 15902770 2021-01-15 op %}
39 15902770 2021-01-15 op
40 15902770 2021-01-15 op /* for bison: */
41 15902770 2021-01-15 op /* %define parse.error verbose */
42 15902770 2021-01-15 op
43 15902770 2021-01-15 op %union {
44 15902770 2021-01-15 op char *str;
45 15902770 2021-01-15 op int num;
46 15902770 2021-01-15 op }
47 15902770 2021-01-15 op
48 ae08ec7d 2021-01-25 op %token TDAEMON TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
49 ae08ec7d 2021-01-25 op %token TCHROOT TUSER TSERVER
50 252908e6 2021-01-24 op %token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
51 15902770 2021-01-15 op %token TERR
52 15902770 2021-01-15 op
53 15902770 2021-01-15 op %token <str> TSTRING
54 15902770 2021-01-15 op %token <num> TNUM
55 15902770 2021-01-15 op %token <num> TBOOL
56 15902770 2021-01-15 op
57 15902770 2021-01-15 op %%
58 15902770 2021-01-15 op
59 15902770 2021-01-15 op conf : options vhosts ;
60 15902770 2021-01-15 op
61 15902770 2021-01-15 op options : /* empty */
62 15902770 2021-01-15 op | options option
63 15902770 2021-01-15 op ;
64 15902770 2021-01-15 op
65 15902770 2021-01-15 op option : TDAEMON TBOOL { conf.foreground = !$2; }
66 15902770 2021-01-15 op | TIPV6 TBOOL { conf.ipv6 = $2; }
67 15902770 2021-01-15 op | TPORT TNUM { conf.port = $2; }
68 5bc3c98e 2021-01-15 op | TPROTOCOLS TSTRING {
69 5bc3c98e 2021-01-15 op if (tls_config_parse_protocols(&conf.protos, $2) == -1)
70 5bc3c98e 2021-01-15 op errx(1, "invalid protocols string \"%s\"", $2);
71 5bc3c98e 2021-01-15 op }
72 b2a6b613 2021-01-21 op | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
73 ae08ec7d 2021-01-25 op | TCHROOT TSTRING { conf.chroot = $2; }
74 ae08ec7d 2021-01-25 op | TUSER TSTRING { conf.user = $2; }
75 15902770 2021-01-15 op ;
76 15902770 2021-01-15 op
77 15902770 2021-01-15 op vhosts : /* empty */
78 15902770 2021-01-15 op | vhosts vhost
79 15902770 2021-01-15 op ;
80 15902770 2021-01-15 op
81 c8b74339 2021-01-24 op vhost : TSERVER TSTRING '{' servopts locations '}' {
82 c8b74339 2021-01-24 op host->locations[0].match = (char*)"*";
83 15902770 2021-01-15 op host->domain = $2;
84 15902770 2021-01-15 op
85 15902770 2021-01-15 op if (host->cert == NULL || host->key == NULL ||
86 15902770 2021-01-15 op host->dir == NULL)
87 15902770 2021-01-15 op errx(1, "invalid vhost definition: %s", $2);
88 c8b74339 2021-01-24 op
89 15902770 2021-01-15 op if (++ihost == HOSTSLEN)
90 15902770 2021-01-15 op errx(1, "too much vhosts defined");
91 c8b74339 2021-01-24 op
92 c8b74339 2021-01-24 op host++;
93 c8b74339 2021-01-24 op loc = &host->locations[0];
94 c8b74339 2021-01-24 op iloc = 0;
95 15902770 2021-01-15 op }
96 15902770 2021-01-15 op | error '}' { yyerror("error in server directive"); }
97 15902770 2021-01-15 op ;
98 15902770 2021-01-15 op
99 15902770 2021-01-15 op servopts : /* empty */
100 15902770 2021-01-15 op | servopts servopt
101 15902770 2021-01-15 op ;
102 15902770 2021-01-15 op
103 15902770 2021-01-15 op servopt : TCERT TSTRING { host->cert = $2; }
104 15902770 2021-01-15 op | TKEY TSTRING { host->key = $2; }
105 15902770 2021-01-15 op | TROOT TSTRING { host->dir = $2; }
106 15902770 2021-01-15 op | TCGI TSTRING {
107 15902770 2021-01-15 op host->cgi = $2;
108 15902770 2021-01-15 op /* drop the starting '/', if any */
109 15902770 2021-01-15 op if (*host->cgi == '/')
110 15902770 2021-01-15 op host->cgi++;
111 05c23a54 2021-01-19 op }
112 c8b74339 2021-01-24 op | locopt
113 c8b74339 2021-01-24 op ;
114 c8b74339 2021-01-24 op
115 c8b74339 2021-01-24 op locations : /* empty */
116 c8b74339 2021-01-24 op | locations location
117 c8b74339 2021-01-24 op ;
118 c8b74339 2021-01-24 op
119 c8b74339 2021-01-24 op location : TLOCATION TSTRING '{' locopts '}' {
120 c8b74339 2021-01-24 op loc->match = $2;
121 c8b74339 2021-01-24 op if (++iloc == LOCLEN)
122 c8b74339 2021-01-24 op errx(1, "too much location rules defined");
123 c8b74339 2021-01-24 op loc++;
124 6119e13e 2021-01-19 op }
125 c8b74339 2021-01-24 op | error '}'
126 c8b74339 2021-01-24 op ;
127 c8b74339 2021-01-24 op
128 c8b74339 2021-01-24 op locopts : /* empty */
129 c8b74339 2021-01-24 op | locopts locopt
130 c8b74339 2021-01-24 op ;
131 c8b74339 2021-01-24 op
132 c8b74339 2021-01-24 op locopt : TDEFAULT TTYPE TSTRING {
133 c8b74339 2021-01-24 op free(loc->default_mime);
134 c8b74339 2021-01-24 op loc->default_mime = $3;
135 c8b74339 2021-01-24 op }
136 05c23a54 2021-01-19 op | TLANG TSTRING {
137 c8b74339 2021-01-24 op free(loc->lang);
138 c8b74339 2021-01-24 op loc->lang = $2;
139 05c23a54 2021-01-19 op }
140 e7a2a99b 2021-01-24 op | TINDEX TSTRING {
141 c8b74339 2021-01-24 op free(loc->index);
142 c8b74339 2021-01-24 op loc->index = $2;
143 e7a2a99b 2021-01-24 op }
144 252908e6 2021-01-24 op | TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }
145 15902770 2021-01-15 op ;