Blob


1 %{
3 /*
4 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
5 * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
6 * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
7 * Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
8 * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
9 * Copyright (c) 2001 Markus Friedl. All rights reserved.
10 * Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
11 * Copyright (c) 2001 Theo de Raadt. All rights reserved.
12 *
13 * Permission to use, copy, modify, and distribute this software for any
14 * purpose with or without fee is hereby granted, provided that the above
15 * copyright notice and this permission notice appear in all copies.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 */
26 #include <ctype.h>
27 #include <errno.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #include "gmid.h"
35 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
36 static struct file {
37 TAILQ_ENTRY(file) entry;
38 FILE *stream;
39 char *name;
40 size_t ungetpos;
41 size_t ungetsize;
42 u_char *ungetbuf;
43 int eof_reached;
44 int lineno;
45 int errors;
46 } *file, *topfile;
48 struct file *pushfile(const char *, int);
49 int popfile(void);
50 int yyparse(void);
51 int yylex(void);
52 void yyerror(const char *, ...)
53 __attribute__((__format__ (printf, 1, 2)))
54 __attribute__((__nonnull__ (1)));
55 int kw_cmp(const void *, const void *);
56 int lookup(char *);
57 int igetc(void);
58 int lgetc(int);
59 void lungetc(int);
60 int findeol(void);
62 /*
63 * #define YYDEBUG 1
64 * int yydebug = 1;
65 */
67 TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
68 struct sym {
69 TAILQ_ENTRY(sym) entry;
70 int used;
71 int persist;
72 char *name;
73 char *val;
74 };
76 int symset(const char *, const char *, int);
77 char *symget(const char *);
79 struct vhost *new_vhost(void);
80 struct location *new_location(void);
81 char *ensure_absolute_path(char*);
82 int check_block_code(int);
83 char *check_block_fmt(char*);
84 int check_strip_no(int);
85 int check_port_num(int);
86 int check_prefork_num(int);
87 void advance_loc(void);
88 void only_once(const void*, const char*);
89 void only_oncei(int, const char*);
90 int fastcgi_conf(char *, char *, char *);
91 void add_param(char *, char *, int);
93 static struct vhost *host;
94 static struct location *loc;
95 static int errors;
97 typedef struct {
98 union {
99 char *string;
100 int number;
101 } v;
102 int lineno;
103 } YYSTYPE;
105 %}
107 /* for bison: */
108 /* %define parse.error verbose */
110 %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE TCHROOT TUSER TSERVER
111 %token TPREFORK TLOCATION TCERT TKEY TROOT TCGI TENV TLANG TLOG TINDEX TAUTO
112 %token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA TALIAS TTCP
113 %token TFASTCGI TSPAWN TPARAM TMAP TTOEXT INCLUDE TON TOFF
115 %token ERROR
117 %token <v.string> STRING
118 %token <v.number> NUM
120 %type <v.number> bool
121 %type <v.string> string
123 %%
125 conf : /* empty */
126 | conf include '\n'
127 | conf '\n'
128 | conf varset '\n'
129 | conf option '\n'
130 | conf vhost '\n'
131 | conf error '\n' { file->errors++; }
134 include : INCLUDE STRING {
135 struct file *nfile;
137 if ((nfile = pushfile($2, 0)) == NULL) {
138 yyerror("failed to include file %s", $2);
139 free($2);
140 YYERROR;
142 free($2);
144 file = nfile;
145 lungetc('\n');
149 bool : TON { $$ = 1; }
150 | TOFF { $$ = 0; }
153 string : string STRING {
154 if (asprintf(&$$, "%s%s", $1, $2) == -1) {
155 free($1);
156 free($2);
157 yyerror("string: asprintf: %s", strerror(errno));
158 YYERROR;
160 free($1);
161 free($2);
163 | STRING
166 varset : STRING '=' string {
167 char *s = $1;
168 while (*s++) {
169 if (isspace((unsigned char)*s)) {
170 yyerror("macro name cannot contain "
171 "whitespaces");
172 free($1);
173 free($3);
174 YYERROR;
177 symset($1, $3, 0);
178 free($1);
179 free($3);
183 option : TCHROOT string { conf.chroot = $2; }
184 | TIPV6 bool { conf.ipv6 = $2; }
185 | TMIME STRING string {
186 fprintf(stderr, "%s:%d: `mime MIME EXT' is deprecated and "
187 "will be removed in a future version, "
188 "please use the new syntax: `map MIME to-ext EXT'\n",
189 config_path, yylval.lineno+1);
190 add_mime(&conf.mime, $2, $3);
192 | TMAP string TTOEXT string { add_mime(&conf.mime, $2, $4); }
193 | TPORT NUM { conf.port = check_port_num($2); }
194 | TPREFORK NUM { conf.prefork = check_prefork_num($2); }
195 | TPROTOCOLS string {
196 if (tls_config_parse_protocols(&conf.protos, $2) == -1)
197 yyerror("invalid protocols string \"%s\"", $2);
199 | TUSER string { conf.user = $2; }
202 vhost : TSERVER string {
203 host = new_vhost();
204 TAILQ_INSERT_HEAD(&hosts, host, vhosts);
206 loc = new_location();
207 TAILQ_INSERT_HEAD(&host->locations, loc, locations);
209 loc->match = xstrdup("*");
210 host->domain = $2;
212 if (strstr($2, "xn--") != NULL) {
213 warnx("%s:%d \"%s\" looks like punycode: "
214 "you should use the decoded hostname.",
215 config_path, yylval.lineno+1, $2);
217 } '{' optnl servopts locations '}' {
218 if (host->cert == NULL || host->key == NULL)
219 yyerror("invalid vhost definition: %s", $2);
221 | error '}' { yyerror("error in server directive"); }
224 servopts : /* empty */
225 | servopts servopt optnl
228 servopt : TALIAS string {
229 struct alist *a;
231 a = xcalloc(1, sizeof(*a));
232 a->alias = $2;
233 if (TAILQ_EMPTY(&host->aliases))
234 TAILQ_INSERT_HEAD(&host->aliases, a, aliases);
235 else
236 TAILQ_INSERT_TAIL(&host->aliases, a, aliases);
238 | TCERT string {
239 only_once(host->cert, "cert");
240 host->cert = ensure_absolute_path($2);
242 | TCGI string {
243 only_once(host->cgi, "cgi");
244 /* drop the starting '/', if any */
245 if (*$2 == '/')
246 memmove($2, $2+1, strlen($2));
247 host->cgi = $2;
249 | TENTRYPOINT string {
250 only_once(host->entrypoint, "entrypoint");
251 while (*$2 == '/')
252 memmove($2, $2+1, strlen($2));
253 host->entrypoint = $2;
255 | TENV string '=' string {
256 add_param($2, $4, 1);
258 | TKEY string {
259 only_once(host->key, "key");
260 host->key = ensure_absolute_path($2);
262 | TPARAM string '=' string {
263 add_param($2, $4, 0);
265 | locopt
268 locations : /* empty */
269 | locations location optnl
272 location : TLOCATION { advance_loc(); } string '{' optnl locopts '}' {
273 /* drop the starting '/' if any */
274 if (*$3 == '/')
275 memmove($3, $3+1, strlen($3));
276 loc->match = $3;
278 | error '}'
281 locopts : /* empty */
282 | locopts locopt optnl
285 locopt : TAUTO TINDEX bool { loc->auto_index = $3 ? 1 : -1; }
286 | TBLOCK TRETURN NUM string {
287 only_once(loc->block_fmt, "block");
288 loc->block_fmt = check_block_fmt($4);
289 loc->block_code = check_block_code($3);
291 | TBLOCK TRETURN NUM {
292 only_once(loc->block_fmt, "block");
293 loc->block_fmt = xstrdup("temporary failure");
294 loc->block_code = check_block_code($3);
295 if ($3 >= 30 && $3 < 40)
296 yyerror("missing `meta' for block return %d", $3);
298 | TBLOCK {
299 only_once(loc->block_fmt, "block");
300 loc->block_fmt = xstrdup("temporary failure");
301 loc->block_code = 40;
303 | TDEFAULT TTYPE string {
304 only_once(loc->default_mime, "default type");
305 loc->default_mime = $3;
307 | TFASTCGI fastcgi
308 | TINDEX string {
309 only_once(loc->index, "index");
310 loc->index = $2;
312 | TLANG string {
313 only_once(loc->lang, "lang");
314 loc->lang = $2;
316 | TLOG bool { loc->disable_log = !$2; }
317 | TREQUIRE TCLIENT TCA string {
318 only_once(loc->reqca, "require client ca");
319 ensure_absolute_path($4);
320 if ((loc->reqca = load_ca($4)) == NULL)
321 yyerror("couldn't load ca cert: %s", $4);
322 free($4);
324 | TROOT string {
325 only_once(loc->dir, "root");
326 loc->dir = ensure_absolute_path($2);
328 | TSTRIP NUM { loc->strip = check_strip_no($2); }
331 fastcgi : TSPAWN string {
332 only_oncei(loc->fcgi, "fastcgi");
333 loc->fcgi = fastcgi_conf(NULL, NULL, $2);
335 | string {
336 only_oncei(loc->fcgi, "fastcgi");
337 loc->fcgi = fastcgi_conf($1, NULL, NULL);
339 | TTCP string TPORT NUM {
340 char *c;
341 if (asprintf(&c, "%d", $4) == -1)
342 err(1, "asprintf");
343 only_oncei(loc->fcgi, "fastcgi");
344 loc->fcgi = fastcgi_conf($2, c, NULL);
346 | TTCP string {
347 only_oncei(loc->fcgi, "fastcgi");
348 loc->fcgi = fastcgi_conf($2, xstrdup("9000"), NULL);
350 | TTCP string TPORT string {
351 only_oncei(loc->fcgi, "fastcgi");
352 loc->fcgi = fastcgi_conf($2, $4, NULL);
356 optnl : '\n' optnl /* zero or more newlines */
357 | ';' optnl /* semicolons too */
358 | /*empty*/
361 %%
363 static struct keyword {
364 const char *word;
365 int token;
366 } keywords[] = {
367 /* these MUST be sorted */
368 {"alias", TALIAS},
369 {"auto", TAUTO},
370 {"block", TBLOCK},
371 {"ca", TCA},
372 {"cert", TCERT},
373 {"cgi", TCGI},
374 {"chroot", TCHROOT},
375 {"client", TCLIENT},
376 {"default", TDEFAULT},
377 {"entrypoint", TENTRYPOINT},
378 {"env", TENV},
379 {"fastcgi", TFASTCGI},
380 {"index", TINDEX},
381 {"ipv6", TIPV6},
382 {"key", TKEY},
383 {"lang", TLANG},
384 {"location", TLOCATION},
385 {"log", TLOG},
386 {"map", TMAP},
387 {"mime", TMIME},
388 {"off", TOFF},
389 {"on", TON},
390 {"param", TPARAM},
391 {"port", TPORT},
392 {"prefork", TPREFORK},
393 {"protocols", TPROTOCOLS},
394 {"require", TREQUIRE},
395 {"return", TRETURN},
396 {"root", TROOT},
397 {"server", TSERVER},
398 {"spawn", TSPAWN},
399 {"strip", TSTRIP},
400 {"tcp", TTCP},
401 {"to-ext", TTOEXT},
402 {"type", TTYPE},
403 {"user", TUSER},
404 };
406 void
407 yyerror(const char *msg, ...)
409 va_list ap;
411 file->errors++;
413 va_start(ap, msg);
414 fprintf(stderr, "%s:%d: ", config_path, yylval.lineno);
415 vfprintf(stderr, msg, ap);
416 fprintf(stderr, "\n");
417 va_end(ap);
420 int
421 kw_cmp(const void *k, const void *e)
423 return strcmp(k, ((struct keyword *)e)->word);
426 int
427 lookup(char *s)
429 const struct keyword *p;
431 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
432 sizeof(keywords[0]), kw_cmp);
434 if (p)
435 return p->token;
436 else
437 return STRING;
440 #define START_EXPAND 1
441 #define DONE_EXPAND 2
443 static int expanding;
445 int
446 igetc(void)
448 int c;
450 while (1) {
451 if (file->ungetpos > 0)
452 c = file->ungetbuf[--file->ungetpos];
453 else
454 c = getc(file->stream);
456 if (c == START_EXPAND)
457 expanding = 1;
458 else if (c == DONE_EXPAND)
459 expanding = 0;
460 else
461 break;
463 return c;
466 int
467 lgetc(int quotec)
469 int c, next;
471 if (quotec) {
472 if ((c = igetc()) == EOF) {
473 yyerror("reached end of file while parsing "
474 "quoted string");
475 if (file == topfile || popfile() == EOF)
476 return EOF;
477 return quotec;
479 return c;
482 while ((c = igetc()) == '\\') {
483 next = igetc();
484 if (next != '\n') {
485 c = next;
486 break;
488 yylval.lineno = file->lineno;
489 file->lineno++;
492 if (c == EOF) {
493 /*
494 * Fake EOL when hit EOF for the first time. This gets line
495 * count right if last line in included file is syntactically
496 * invalid and has no newline.
497 */
498 if (file->eof_reached == 0) {
499 file->eof_reached = 1;
500 return '\n';
502 while (c == EOF) {
503 if (file == topfile || popfile() == EOF)
504 return EOF;
505 c = igetc();
508 return c;
511 void
512 lungetc(int c)
514 if (c == EOF)
515 return;
517 if (file->ungetpos >= file->ungetsize) {
518 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
519 if (p == NULL)
520 err(1, "lungetc");
521 file->ungetbuf = p;
522 file->ungetsize *= 2;
524 file->ungetbuf[file->ungetpos++] = c;
527 int
528 findeol(void)
530 int c;
532 /* Skip to either EOF or the first real EOL. */
533 while (1) {
534 c = lgetc(0);
535 if (c == '\n') {
536 file->lineno++;
537 break;
539 if (c == EOF)
540 break;
542 return ERROR;
545 int
546 yylex(void)
548 char buf[8096];
549 char *p, *val;
550 int quotec, next, c;
551 int token;
553 top:
554 p = buf;
555 while ((c = lgetc(0)) == ' ' || c == '\t')
556 ; /* nothing */
558 yylval.lineno = file->lineno;
559 if (c == '#')
560 while ((c = lgetc(0)) != '\n' && c != EOF)
561 ; /* nothing */
562 if (c == '$' && !expanding) {
563 while (1) {
564 if ((c = lgetc(0)) == EOF)
565 return 0;
566 if (p + 1 >= buf + sizeof(buf) -1) {
567 yyerror("string too long");
568 return findeol();
570 if (isalnum(c) || c == '_') {
571 *p++ = c;
572 continue;
574 *p = '\0';
575 lungetc(c);
576 break;
578 val = symget(buf);
579 if (val == NULL) {
580 yyerror("macro `%s' not defined", buf);
581 return findeol();
583 yylval.v.string = xstrdup(val);
584 return STRING;
586 if (c == '@' && !expanding) {
587 while (1) {
588 if ((c = lgetc(0)) == EOF)
589 return 0;
591 if (p + 1 >= buf + sizeof(buf) - 1) {
592 yyerror("string too long");
593 return findeol();
595 if (isalnum(c) || c == '_') {
596 *p++ = c;
597 continue;
599 *p = '\0';
600 lungetc(c);
601 break;
603 val = symget(buf);
604 if (val == NULL) {
605 yyerror("macro '%s' not defined", buf);
606 return findeol();
608 p = val + strlen(val) - 1;
609 lungetc(DONE_EXPAND);
610 while (p >= val) {
611 lungetc(*p);
612 p--;
614 lungetc(START_EXPAND);
615 goto top;
618 switch (c) {
619 case '\'':
620 case '"':
621 quotec = c;
622 while (1) {
623 if ((c = lgetc(quotec)) == EOF)
624 return 0;
625 if (c == '\n') {
626 file->lineno++;
627 continue;
628 } else if (c == '\\') {
629 if ((next = lgetc(quotec)) == EOF)
630 return (0);
631 if (next == quotec || next == ' ' ||
632 next == '\t')
633 c = next;
634 else if (next == '\n') {
635 file->lineno++;
636 continue;
637 } else
638 lungetc(next);
639 } else if (c == quotec) {
640 *p = '\0';
641 break;
642 } else if (c == '\0') {
643 yyerror("syntax error");
644 return findeol();
646 if (p + 1 >= buf + sizeof(buf) - 1) {
647 yyerror("string too long");
648 return findeol();
650 *p++ = c;
652 yylval.v.string = strdup(buf);
653 if (yylval.v.string == NULL)
654 err(1, "yylex: strdup");
655 return STRING;
658 #define allowed_to_end_number(x) \
659 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
661 if (c == '-' || isdigit(c)) {
662 do {
663 *p++ = c;
664 if ((size_t)(p-buf) >= sizeof(buf)) {
665 yyerror("string too long");
666 return findeol();
668 } while ((c = lgetc(0)) != EOF && isdigit(c));
669 lungetc(c);
670 if (p == buf + 1 && buf[0] == '-')
671 goto nodigits;
672 if (c == EOF || allowed_to_end_number(c)) {
673 const char *errstr = NULL;
675 *p = '\0';
676 yylval.v.number = strtonum(buf, LLONG_MIN,
677 LLONG_MAX, &errstr);
678 if (errstr) {
679 yyerror("\"%s\" invalid number: %s",
680 buf, errstr);
681 return findeol();
683 return NUM;
684 } else {
685 nodigits:
686 while (p > buf + 1)
687 lungetc(*--p);
688 c = *--p;
689 if (c == '-')
690 return c;
694 #define allowed_in_string(x) \
695 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
696 x != '{' && x != '}' && \
697 x != '!' && x != '=' && x != '#' && \
698 x != ',' && x != ';'))
700 if (isalnum(c) || c == ':' || c == '_') {
701 do {
702 *p++ = c;
703 if ((size_t)(p-buf) >= sizeof(buf)) {
704 yyerror("string too long");
705 return findeol();
707 } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
708 lungetc(c);
709 *p = '\0';
710 if ((token = lookup(buf)) == STRING)
711 yylval.v.string = xstrdup(buf);
712 return token;
714 if (c == '\n') {
715 yylval.lineno = file->lineno;
716 file->lineno++;
718 if (c == EOF)
719 return 0;
720 return c;
723 struct file *
724 pushfile(const char *name, int secret)
726 struct file *nfile;
728 nfile = xcalloc(1, sizeof(*nfile));
729 nfile->name = xstrdup(name);
730 if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
731 yyerror("can't open %s: %s", nfile->name,
732 strerror(errno));
733 free(nfile->name);
734 free(nfile);
735 return NULL;
737 nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
738 nfile->ungetsize = 16;
739 nfile->ungetbuf = xcalloc(1, nfile->ungetsize);
740 TAILQ_INSERT_TAIL(&files, nfile, entry);
741 return nfile;
744 int
745 popfile(void)
747 struct file *prev;
749 if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
750 prev->errors += file->errors;
752 TAILQ_REMOVE(&files, file, entry);
753 fclose(file->stream);
754 free(file->name);
755 free(file->ungetbuf);
756 free(file);
757 file = prev;
758 return file ? 0 : EOF;
761 void
762 parse_conf(const char *filename)
764 struct sym *sym, *next;
766 file = pushfile(filename, 0);
767 if (file == NULL)
768 return;
769 topfile = file;
771 yyparse();
772 errors = file->errors;
773 popfile();
775 /* Free macros and check which have not been used. */
776 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
777 /* TODO: warn if !sym->used */
778 if (!sym->persist) {
779 free(sym->name);
780 free(sym->val);
781 TAILQ_REMOVE(&symhead, sym, entry);
782 free(sym);
786 if (errors)
787 exit(1);
790 int
791 symset(const char *name, const char *val, int persist)
793 struct sym *sym;
795 TAILQ_FOREACH(sym, &symhead, entry) {
796 if (!strcmp(name, sym->name))
797 break;
800 if (sym != NULL) {
801 if (sym->persist)
802 return 0;
803 else {
804 free(sym->name);
805 free(sym->val);
806 TAILQ_REMOVE(&symhead, sym, entry);
807 free(sym);
811 sym = xcalloc(1, sizeof(*sym));
812 sym->name = xstrdup(name);
813 sym->val = xstrdup(val);
814 sym->used = 0;
815 sym->persist = persist;
817 TAILQ_INSERT_TAIL(&symhead, sym, entry);
818 return 0;
821 int
822 cmdline_symset(char *s)
824 char *sym, *val;
825 int ret;
827 if ((val = strrchr(s, '=')) == NULL)
828 return -1;
829 sym = xcalloc(1, val - s + 1);
830 memcpy(sym, s, val - s);
831 ret = symset(sym, val + 1, 1);
832 free(sym);
833 return ret;
836 char *
837 symget(const char *nam)
839 struct sym *sym;
841 TAILQ_FOREACH(sym, &symhead, entry) {
842 if (strcmp(nam, sym->name) == 0) {
843 sym->used = 1;
844 return sym->val;
847 return NULL;
850 struct vhost *
851 new_vhost(void)
853 return xcalloc(1, sizeof(struct vhost));
856 struct location *
857 new_location(void)
859 struct location *l;
861 l = xcalloc(1, sizeof(*l));
862 l->dirfd = -1;
863 l->fcgi = -1;
864 return l;
867 char *
868 ensure_absolute_path(char *path)
870 if (path == NULL || *path != '/')
871 yyerror("not an absolute path: %s", path);
872 return path;
875 int
876 check_block_code(int n)
878 if (n < 10 || n >= 70 || (n >= 20 && n <= 29))
879 yyerror("invalid block code %d", n);
880 return n;
883 char *
884 check_block_fmt(char *fmt)
886 char *s;
888 for (s = fmt; *s; ++s) {
889 if (*s != '%')
890 continue;
891 switch (*++s) {
892 case '%':
893 case 'p':
894 case 'q':
895 case 'P':
896 case 'N':
897 break;
898 default:
899 yyerror("invalid format specifier %%%c", *s);
903 return fmt;
906 int
907 check_strip_no(int n)
909 if (n <= 0)
910 yyerror("invalid strip number %d", n);
911 return n;
914 int
915 check_port_num(int n)
917 if (n <= 0 || n >= UINT16_MAX)
918 yyerror("port number is %s: %d",
919 n <= 0 ? "too small" : "too large",
920 n);
921 return n;
924 int
925 check_prefork_num(int n)
927 if (n <= 0 || n >= PROC_MAX)
928 yyerror("invalid prefork number %d", n);
929 return n;
932 void
933 advance_loc(void)
935 loc = new_location();
936 TAILQ_INSERT_TAIL(&host->locations, loc, locations);
939 void
940 only_once(const void *ptr, const char *name)
942 if (ptr != NULL)
943 yyerror("`%s' specified more than once", name);
946 void
947 only_oncei(int i, const char *name)
949 if (i != -1)
950 yyerror("`%s' specified more than once", name);
953 int
954 fastcgi_conf(char *path, char *port, char *prog)
956 struct fcgi *f;
957 int i;
959 for (i = 0; i < FCGI_MAX; ++i) {
960 f = &fcgi[i];
962 if (f->path == NULL) {
963 f->id = i;
964 f->path = path;
965 f->port = port;
966 f->prog = prog;
967 return i;
970 /* XXX: what to do with prog? */
971 if (!strcmp(f->path, path) &&
972 ((port == NULL && f->port == NULL) ||
973 !strcmp(f->port, port))) {
974 free(path);
975 free(port);
976 return i;
980 yyerror("too much `fastcgi' rules defined.");
981 return -1;
984 void
985 add_param(char *name, char *val, int env)
987 struct envlist *e;
988 struct envhead *h;
990 if (env)
991 h = &host->env;
992 else
993 h = &host->params;
995 e = xcalloc(1, sizeof(*e));
996 e->name = name;
997 e->value = val;
998 if (TAILQ_EMPTY(h))
999 TAILQ_INSERT_HEAD(h, e, envs);
1000 else
1001 TAILQ_INSERT_TAIL(h, e, envs);