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 002a84a1 2021-02-10 op #include <errno.h>
21 6abda252 2021-02-06 op #include <stdarg.h>
22 15902770 2021-01-15 op #include <stdio.h>
23 32693ee6 2021-01-28 op #include <string.h>
24 15902770 2021-01-15 op
25 15902770 2021-01-15 op #include "gmid.h"
26 15902770 2021-01-15 op
27 15902770 2021-01-15 op /*
28 15902770 2021-01-15 op * #define YYDEBUG 1
29 15902770 2021-01-15 op * int yydebug = 1;
30 15902770 2021-01-15 op */
31 15902770 2021-01-15 op
32 ca21e100 2021-02-04 op struct vhost *host;
33 ca21e100 2021-02-04 op struct location *loc;
34 15902770 2021-01-15 op
35 13ed2fb6 2021-01-27 op int goterror = 0;
36 15902770 2021-01-15 op
37 b8e64ccd 2021-03-31 op static struct vhost *new_vhost(void);
38 b8e64ccd 2021-03-31 op static struct location *new_location(void);
39 b8e64ccd 2021-03-31 op
40 6abda252 2021-02-06 op void yyerror(const char*, ...);
41 13ed2fb6 2021-01-27 op int parse_portno(const char*);
42 13ed2fb6 2021-01-27 op void parse_conf(const char*);
43 e17642a7 2021-02-01 op char *ensure_absolute_path(char*);
44 6abda252 2021-02-06 op int check_block_code(int);
45 6abda252 2021-02-06 op char *check_block_fmt(char*);
46 6abda252 2021-02-06 op int check_strip_no(int);
47 a709ddf5 2021-02-07 op int check_prefork_num(int);
48 49b73ba1 2021-02-10 op void advance_loc(void);
49 c705ecb1 2021-05-03 op void only_once(const void*, const char*);
50 8ad1c570 2021-05-09 op void only_oncei(int, const char*);
51 8ad1c570 2021-05-09 op int fastcgi_conf(char *, char *, char *);
52 13ed2fb6 2021-01-27 op
53 15902770 2021-01-15 op %}
54 15902770 2021-01-15 op
55 15902770 2021-01-15 op /* for bison: */
56 15902770 2021-01-15 op /* %define parse.error verbose */
57 15902770 2021-01-15 op
58 15902770 2021-01-15 op %union {
59 15902770 2021-01-15 op char *str;
60 15902770 2021-01-15 op int num;
61 15902770 2021-01-15 op }
62 15902770 2021-01-15 op
63 d06d6f4b 2021-04-29 op %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE TCHROOT TUSER TSERVER
64 d06d6f4b 2021-04-29 op %token TPREFORK TLOCATION TCERT TKEY TROOT TCGI TENV TLANG TLOG TINDEX TAUTO
65 8ad1c570 2021-05-09 op %token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA TALIAS TTCP
66 8ad1c570 2021-05-09 op %token TFASTCGI TSPAWN
67 d06d6f4b 2021-04-29 op
68 15902770 2021-01-15 op %token TERR
69 15902770 2021-01-15 op
70 15902770 2021-01-15 op %token <str> TSTRING
71 15902770 2021-01-15 op %token <num> TNUM
72 15902770 2021-01-15 op %token <num> TBOOL
73 15902770 2021-01-15 op
74 15902770 2021-01-15 op %%
75 15902770 2021-01-15 op
76 15902770 2021-01-15 op conf : options vhosts ;
77 15902770 2021-01-15 op
78 15902770 2021-01-15 op options : /* empty */
79 15902770 2021-01-15 op | options option
80 15902770 2021-01-15 op ;
81 15902770 2021-01-15 op
82 eb59f87e 2021-02-09 op option : TCHROOT TSTRING { conf.chroot = $2; }
83 eb59f87e 2021-02-09 op | TIPV6 TBOOL { conf.ipv6 = $2; }
84 eb59f87e 2021-02-09 op | TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
85 15902770 2021-01-15 op | TPORT TNUM { conf.port = $2; }
86 eb59f87e 2021-02-09 op | TPREFORK TNUM { conf.prefork = check_prefork_num($2); }
87 5bc3c98e 2021-01-15 op | TPROTOCOLS TSTRING {
88 5bc3c98e 2021-01-15 op if (tls_config_parse_protocols(&conf.protos, $2) == -1)
89 002a84a1 2021-02-10 op yyerror("invalid protocols string \"%s\"", $2);
90 5bc3c98e 2021-01-15 op }
91 ae08ec7d 2021-01-25 op | TUSER TSTRING { conf.user = $2; }
92 15902770 2021-01-15 op ;
93 15902770 2021-01-15 op
94 15902770 2021-01-15 op vhosts : /* empty */
95 15902770 2021-01-15 op | vhosts vhost
96 15902770 2021-01-15 op ;
97 15902770 2021-01-15 op
98 b8e64ccd 2021-03-31 op vhost : TSERVER TSTRING {
99 b8e64ccd 2021-03-31 op host = new_vhost();
100 b8e64ccd 2021-03-31 op TAILQ_INSERT_HEAD(&hosts, host, vhosts);
101 b8e64ccd 2021-03-31 op
102 b8e64ccd 2021-03-31 op loc = new_location();
103 b8e64ccd 2021-03-31 op TAILQ_INSERT_HEAD(&host->locations, loc, locations);
104 b8e64ccd 2021-03-31 op
105 b8e64ccd 2021-03-31 op loc->match = xstrdup("*");
106 15902770 2021-01-15 op host->domain = $2;
107 15902770 2021-01-15 op
108 cbeee4ca 2021-01-28 op if (strstr($2, "xn--") != NULL) {
109 cbeee4ca 2021-01-28 op warnx("%s:%d \"%s\" looks like punycode: "
110 415ac7a2 2021-01-28 op "you should use the decoded hostname.",
111 415ac7a2 2021-01-28 op config_path, yylineno, $2);
112 cbeee4ca 2021-01-28 op }
113 b8e64ccd 2021-03-31 op } '{' servopts locations '}' {
114 cbeee4ca 2021-01-28 op
115 fdea6aa0 2021-04-30 op if (host->cert == NULL || host->key == NULL)
116 002a84a1 2021-02-10 op yyerror("invalid vhost definition: %s", $2);
117 15902770 2021-01-15 op }
118 15902770 2021-01-15 op | error '}' { yyerror("error in server directive"); }
119 15902770 2021-01-15 op ;
120 15902770 2021-01-15 op
121 15902770 2021-01-15 op servopts : /* empty */
122 15902770 2021-01-15 op | servopts servopt
123 15902770 2021-01-15 op ;
124 15902770 2021-01-15 op
125 cc8c2901 2021-04-29 op servopt : TALIAS TSTRING {
126 cc8c2901 2021-04-29 op struct alist *a;
127 cc8c2901 2021-04-29 op
128 cc8c2901 2021-04-29 op a = xcalloc(1, sizeof(*a));
129 cc8c2901 2021-04-29 op a->alias = $2;
130 cc8c2901 2021-04-29 op if (TAILQ_EMPTY(&host->aliases))
131 cc8c2901 2021-04-29 op TAILQ_INSERT_HEAD(&host->aliases, a, aliases);
132 cc8c2901 2021-04-29 op else
133 cc8c2901 2021-04-29 op TAILQ_INSERT_TAIL(&host->aliases, a, aliases);
134 cc8c2901 2021-04-29 op }
135 c705ecb1 2021-05-03 op | TCERT TSTRING {
136 c705ecb1 2021-05-03 op only_once(host->cert, "cert");
137 c705ecb1 2021-05-03 op host->cert = ensure_absolute_path($2);
138 c705ecb1 2021-05-03 op }
139 15902770 2021-01-15 op | TCGI TSTRING {
140 c705ecb1 2021-05-03 op only_once(host->cgi, "cgi");
141 15902770 2021-01-15 op /* drop the starting '/', if any */
142 709f4c94 2021-02-04 op if (*$2 == '/')
143 709f4c94 2021-02-04 op memmove($2, $2+1, strlen($2));
144 709f4c94 2021-02-04 op host->cgi = $2;
145 05c23a54 2021-01-19 op }
146 e3ddf390 2021-02-06 op | TENTRYPOINT TSTRING {
147 c705ecb1 2021-05-03 op only_once(host->entrypoint, "entrypoint");
148 e3ddf390 2021-02-06 op while (*$2 == '/')
149 e3ddf390 2021-02-06 op memmove($2, $2+1, strlen($2));
150 e3ddf390 2021-02-06 op host->entrypoint = $2;
151 e3ddf390 2021-02-06 op }
152 9cc630aa 2021-04-28 op | TENV TSTRING TSTRING {
153 9cc630aa 2021-04-28 op struct envlist *e;
154 9cc630aa 2021-04-28 op
155 9cc630aa 2021-04-28 op e = xcalloc(1, sizeof(*e));
156 9cc630aa 2021-04-28 op e->name = $2;
157 9cc630aa 2021-04-28 op e->value = $3;
158 9cc630aa 2021-04-28 op if (TAILQ_EMPTY(&host->env))
159 9cc630aa 2021-04-28 op TAILQ_INSERT_HEAD(&host->env, e, envs);
160 9cc630aa 2021-04-28 op else
161 9cc630aa 2021-04-28 op TAILQ_INSERT_TAIL(&host->env, e, envs);
162 9cc630aa 2021-04-28 op }
163 c705ecb1 2021-05-03 op | TKEY TSTRING {
164 c705ecb1 2021-05-03 op only_once(host->key, "key");
165 c705ecb1 2021-05-03 op host->key = ensure_absolute_path($2);
166 c705ecb1 2021-05-03 op }
167 c8b74339 2021-01-24 op | locopt
168 c8b74339 2021-01-24 op ;
169 c8b74339 2021-01-24 op
170 c8b74339 2021-01-24 op locations : /* empty */
171 c8b74339 2021-01-24 op | locations location
172 c8b74339 2021-01-24 op ;
173 c8b74339 2021-01-24 op
174 49b73ba1 2021-02-10 op location : TLOCATION { advance_loc(); } TSTRING '{' locopts '}' {
175 49b73ba1 2021-02-10 op /* drop the starting '/' if any */
176 49b73ba1 2021-02-10 op if (*$3 == '/')
177 49b73ba1 2021-02-10 op memmove($3, $3+1, strlen($3));
178 49b73ba1 2021-02-10 op loc->match = $3;
179 6119e13e 2021-01-19 op }
180 c8b74339 2021-01-24 op | error '}'
181 c8b74339 2021-01-24 op ;
182 c8b74339 2021-01-24 op
183 c8b74339 2021-01-24 op locopts : /* empty */
184 c8b74339 2021-01-24 op | locopts locopt
185 c8b74339 2021-01-24 op ;
186 c8b74339 2021-01-24 op
187 eb59f87e 2021-02-09 op locopt : TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }
188 6abda252 2021-02-06 op | TBLOCK TRETURN TNUM TSTRING {
189 c705ecb1 2021-05-03 op only_once(loc->block_fmt, "block");
190 6abda252 2021-02-06 op loc->block_fmt = check_block_fmt($4);
191 6abda252 2021-02-06 op loc->block_code = check_block_code($3);
192 6abda252 2021-02-06 op }
193 6abda252 2021-02-06 op | TBLOCK TRETURN TNUM {
194 c705ecb1 2021-05-03 op only_once(loc->block_fmt, "block");
195 6abda252 2021-02-06 op loc->block_fmt = xstrdup("temporary failure");
196 6abda252 2021-02-06 op loc->block_code = check_block_code($3);
197 6abda252 2021-02-06 op if ($3 >= 30 && $3 < 40)
198 6abda252 2021-02-06 op yyerror("missing `meta' for block return %d", $3);
199 6abda252 2021-02-06 op }
200 6abda252 2021-02-06 op | TBLOCK {
201 c705ecb1 2021-05-03 op only_once(loc->block_fmt, "block");
202 6abda252 2021-02-06 op loc->block_fmt = xstrdup("temporary failure");
203 6abda252 2021-02-06 op loc->block_code = 40;
204 6abda252 2021-02-06 op }
205 eb59f87e 2021-02-09 op | TDEFAULT TTYPE TSTRING {
206 c705ecb1 2021-05-03 op only_once(loc->default_mime, "default type");
207 eb59f87e 2021-02-09 op loc->default_mime = $3;
208 eb59f87e 2021-02-09 op }
209 0d047efc 2021-05-24 op | TFASTCGI fastcgi
210 eb59f87e 2021-02-09 op | TINDEX TSTRING {
211 c705ecb1 2021-05-03 op only_once(loc->index, "index");
212 eb59f87e 2021-02-09 op loc->index = $2;
213 eb59f87e 2021-02-09 op }
214 eb59f87e 2021-02-09 op | TLANG TSTRING {
215 c705ecb1 2021-05-03 op only_once(loc->lang, "lang");
216 eb59f87e 2021-02-09 op loc->lang = $2;
217 eb59f87e 2021-02-09 op }
218 793835cb 2021-02-23 op | TLOG TBOOL { loc->disable_log = !$2; }
219 02be96c6 2021-02-09 op | TREQUIRE TCLIENT TCA TSTRING {
220 c705ecb1 2021-05-03 op only_once(loc->reqca, "require client ca");
221 adbe6a64 2021-04-30 op ensure_absolute_path($4);
222 02be96c6 2021-02-09 op if ((loc->reqca = load_ca($4)) == NULL)
223 02be96c6 2021-02-09 op yyerror("couldn't load ca cert: %s", $4);
224 02be96c6 2021-02-09 op free($4);
225 fdea6aa0 2021-04-30 op }
226 fdea6aa0 2021-04-30 op | TROOT TSTRING {
227 c705ecb1 2021-05-03 op only_once(loc->dir, "root");
228 fdea6aa0 2021-04-30 op loc->dir = ensure_absolute_path($2);
229 02be96c6 2021-02-09 op }
230 eb59f87e 2021-02-09 op | TSTRIP TNUM { loc->strip = check_strip_no($2); }
231 15902770 2021-01-15 op ;
232 13ed2fb6 2021-01-27 op
233 0d047efc 2021-05-24 op fastcgi : TSPAWN TSTRING {
234 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
235 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf(NULL, NULL, $2);
236 0d047efc 2021-05-24 op }
237 0d047efc 2021-05-24 op | TSTRING {
238 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
239 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($1, NULL, NULL);
240 0d047efc 2021-05-24 op }
241 0d047efc 2021-05-24 op | TTCP TSTRING TNUM {
242 0d047efc 2021-05-24 op char *c;
243 0d047efc 2021-05-24 op if (asprintf(&c, "%d", $3) == -1)
244 0d047efc 2021-05-24 op err(1, "asprintf");
245 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
246 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($2, c, NULL);
247 0d047efc 2021-05-24 op }
248 0d047efc 2021-05-24 op | TTCP TSTRING {
249 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
250 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($2, xstrdup("9000"), NULL);
251 0d047efc 2021-05-24 op }
252 0d047efc 2021-05-24 op | TTCP TSTRING TSTRING {
253 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
254 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($2, $3, NULL);
255 0d047efc 2021-05-24 op }
256 0d047efc 2021-05-24 op ;
257 0d047efc 2021-05-24 op
258 13ed2fb6 2021-01-27 op %%
259 b8e64ccd 2021-03-31 op
260 b8e64ccd 2021-03-31 op static struct vhost *
261 b8e64ccd 2021-03-31 op new_vhost(void)
262 b8e64ccd 2021-03-31 op {
263 b8e64ccd 2021-03-31 op return xcalloc(1, sizeof(struct vhost));
264 b8e64ccd 2021-03-31 op }
265 13ed2fb6 2021-01-27 op
266 b8e64ccd 2021-03-31 op static struct location *
267 b8e64ccd 2021-03-31 op new_location(void)
268 b8e64ccd 2021-03-31 op {
269 fdea6aa0 2021-04-30 op struct location *l;
270 fdea6aa0 2021-04-30 op
271 fdea6aa0 2021-04-30 op l = xcalloc(1, sizeof(*l));
272 fdea6aa0 2021-04-30 op l->dirfd = -1;
273 8ad1c570 2021-05-09 op l->fcgi = -1;
274 fdea6aa0 2021-04-30 op return l;
275 b8e64ccd 2021-03-31 op }
276 b8e64ccd 2021-03-31 op
277 13ed2fb6 2021-01-27 op void
278 6abda252 2021-02-06 op yyerror(const char *msg, ...)
279 13ed2fb6 2021-01-27 op {
280 6abda252 2021-02-06 op va_list ap;
281 6abda252 2021-02-06 op
282 13ed2fb6 2021-01-27 op goterror = 1;
283 6abda252 2021-02-06 op
284 6abda252 2021-02-06 op va_start(ap, msg);
285 6abda252 2021-02-06 op fprintf(stderr, "%s:%d: ", config_path, yylineno);
286 6abda252 2021-02-06 op vfprintf(stderr, msg, ap);
287 a1373913 2021-02-07 op fprintf(stderr, "\n");
288 6abda252 2021-02-06 op va_end(ap);
289 13ed2fb6 2021-01-27 op }
290 13ed2fb6 2021-01-27 op
291 13ed2fb6 2021-01-27 op int
292 13ed2fb6 2021-01-27 op parse_portno(const char *p)
293 13ed2fb6 2021-01-27 op {
294 13ed2fb6 2021-01-27 op const char *errstr;
295 13ed2fb6 2021-01-27 op int n;
296 13ed2fb6 2021-01-27 op
297 13ed2fb6 2021-01-27 op n = strtonum(p, 0, UINT16_MAX, &errstr);
298 13ed2fb6 2021-01-27 op if (errstr != NULL)
299 2d34f732 2021-02-10 op yyerror("port number is %s: %s", errstr, p);
300 13ed2fb6 2021-01-27 op return n;
301 13ed2fb6 2021-01-27 op }
302 13ed2fb6 2021-01-27 op
303 13ed2fb6 2021-01-27 op void
304 13ed2fb6 2021-01-27 op parse_conf(const char *path)
305 13ed2fb6 2021-01-27 op {
306 13ed2fb6 2021-01-27 op config_path = path;
307 13ed2fb6 2021-01-27 op if ((yyin = fopen(path, "r")) == NULL)
308 48b69cb2 2021-04-28 op err(1, "cannot open config: %s", path);
309 13ed2fb6 2021-01-27 op yyparse();
310 13ed2fb6 2021-01-27 op fclose(yyin);
311 13ed2fb6 2021-01-27 op
312 13ed2fb6 2021-01-27 op if (goterror)
313 13ed2fb6 2021-01-27 op exit(1);
314 b8e64ccd 2021-03-31 op
315 b8e64ccd 2021-03-31 op if (TAILQ_FIRST(&hosts)->domain == NULL)
316 48b69cb2 2021-04-28 op errx(1, "no vhost defined in %s", path);
317 13ed2fb6 2021-01-27 op }
318 e17642a7 2021-02-01 op
319 e17642a7 2021-02-01 op char *
320 e17642a7 2021-02-01 op ensure_absolute_path(char *path)
321 e17642a7 2021-02-01 op {
322 e17642a7 2021-02-01 op if (path == NULL || *path != '/')
323 adbe6a64 2021-04-30 op yyerror("not an absolute path: %s", path);
324 e17642a7 2021-02-01 op return path;
325 e17642a7 2021-02-01 op }
326 6abda252 2021-02-06 op
327 6abda252 2021-02-06 op int
328 6abda252 2021-02-06 op check_block_code(int n)
329 6abda252 2021-02-06 op {
330 6abda252 2021-02-06 op if (n < 10 || n >= 70 || (n >= 20 && n <= 29))
331 6abda252 2021-02-06 op yyerror("invalid block code %d", n);
332 6abda252 2021-02-06 op return n;
333 6abda252 2021-02-06 op }
334 6abda252 2021-02-06 op
335 6abda252 2021-02-06 op char *
336 6abda252 2021-02-06 op check_block_fmt(char *fmt)
337 6abda252 2021-02-06 op {
338 6abda252 2021-02-06 op char *s;
339 6abda252 2021-02-06 op
340 6abda252 2021-02-06 op for (s = fmt; *s; ++s) {
341 6abda252 2021-02-06 op if (*s != '%')
342 6abda252 2021-02-06 op continue;
343 6abda252 2021-02-06 op switch (*++s) {
344 6abda252 2021-02-06 op case '%':
345 6abda252 2021-02-06 op case 'p':
346 6abda252 2021-02-06 op case 'q':
347 6abda252 2021-02-06 op case 'P':
348 6abda252 2021-02-06 op case 'N':
349 6abda252 2021-02-06 op break;
350 6abda252 2021-02-06 op default:
351 6abda252 2021-02-06 op yyerror("invalid format specifier %%%c", *s);
352 6abda252 2021-02-06 op }
353 6abda252 2021-02-06 op }
354 6abda252 2021-02-06 op
355 6abda252 2021-02-06 op return fmt;
356 6abda252 2021-02-06 op }
357 6abda252 2021-02-06 op
358 6abda252 2021-02-06 op int
359 6abda252 2021-02-06 op check_strip_no(int n)
360 6abda252 2021-02-06 op {
361 6abda252 2021-02-06 op if (n <= 0)
362 6abda252 2021-02-06 op yyerror("invalid strip number %d", n);
363 a709ddf5 2021-02-07 op return n;
364 a709ddf5 2021-02-07 op }
365 a709ddf5 2021-02-07 op
366 a709ddf5 2021-02-07 op int
367 a709ddf5 2021-02-07 op check_prefork_num(int n)
368 a709ddf5 2021-02-07 op {
369 2c3e53da 2021-03-03 op if (n <= 0 || n >= PROC_MAX)
370 a709ddf5 2021-02-07 op yyerror("invalid prefork number %d", n);
371 6abda252 2021-02-06 op return n;
372 6abda252 2021-02-06 op }
373 49b73ba1 2021-02-10 op
374 49b73ba1 2021-02-10 op void
375 49b73ba1 2021-02-10 op advance_loc(void)
376 49b73ba1 2021-02-10 op {
377 b8e64ccd 2021-03-31 op loc = new_location();
378 b8e64ccd 2021-03-31 op TAILQ_INSERT_TAIL(&host->locations, loc, locations);
379 49b73ba1 2021-02-10 op }
380 c705ecb1 2021-05-03 op
381 c705ecb1 2021-05-03 op void
382 c705ecb1 2021-05-03 op only_once(const void *ptr, const char *name)
383 c705ecb1 2021-05-03 op {
384 c705ecb1 2021-05-03 op if (ptr != NULL)
385 c705ecb1 2021-05-03 op yyerror("`%s' specified more than once", name);
386 c705ecb1 2021-05-03 op }
387 8ad1c570 2021-05-09 op
388 8ad1c570 2021-05-09 op void
389 8ad1c570 2021-05-09 op only_oncei(int i, const char *name)
390 8ad1c570 2021-05-09 op {
391 8ad1c570 2021-05-09 op if (i != -1)
392 8ad1c570 2021-05-09 op yyerror("`%s' specified more than once", name);
393 8ad1c570 2021-05-09 op }
394 8ad1c570 2021-05-09 op
395 8ad1c570 2021-05-09 op int
396 8ad1c570 2021-05-09 op fastcgi_conf(char *path, char *port, char *prog)
397 8ad1c570 2021-05-09 op {
398 8ad1c570 2021-05-09 op struct fcgi *f;
399 8ad1c570 2021-05-09 op int i;
400 8ad1c570 2021-05-09 op
401 8ad1c570 2021-05-09 op for (i = 0; i < FCGI_MAX; ++i) {
402 8ad1c570 2021-05-09 op f = &fcgi[i];
403 8ad1c570 2021-05-09 op
404 8ad1c570 2021-05-09 op if (f->path == NULL) {
405 8ad1c570 2021-05-09 op f->id = i;
406 8ad1c570 2021-05-09 op f->path = path;
407 8ad1c570 2021-05-09 op f->port = port;
408 8ad1c570 2021-05-09 op f->prog = prog;
409 8ad1c570 2021-05-09 op return i;
410 8ad1c570 2021-05-09 op }
411 8ad1c570 2021-05-09 op
412 8ad1c570 2021-05-09 op /* XXX: what to do with prog? */
413 8ad1c570 2021-05-09 op if (!strcmp(f->path, path) &&
414 8ad1c570 2021-05-09 op ((port == NULL && f->port == NULL) ||
415 8ad1c570 2021-05-09 op !strcmp(f->port, port))) {
416 8ad1c570 2021-05-09 op free(path);
417 8ad1c570 2021-05-09 op free(port);
418 8ad1c570 2021-05-09 op return i;
419 8ad1c570 2021-05-09 op }
420 8ad1c570 2021-05-09 op }
421 8ad1c570 2021-05-09 op
422 8ad1c570 2021-05-09 op yyerror("too much `fastcgi' rules defined.");
423 8ad1c570 2021-05-09 op return -1;
424 8ad1c570 2021-05-09 op }