blob: d7853277114c9707cc0fc5c995fd4175ace7688d [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau0a3dd742012-05-08 19:47:01 +02002 * include/common/cfgparse.h
3 * Configuration parsing functions.
4 *
5 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020021
Willy Tarreau2dd0d472006-06-29 17:53:05 +020022#ifndef _COMMON_CFGPARSE_H
23#define _COMMON_CFGPARSE_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreau5b2c3362008-07-09 19:39:06 +020025#include <common/compat.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020026#include <common/config.h>
Willy Tarreau5b2c3362008-07-09 19:39:06 +020027#include <common/mini-clist.h>
28
Willy Tarreau272adea2014-03-31 10:39:59 +020029#include <proto/log.h>
30#include <proto/proxy.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020031
Willy Tarreaubaaee002006-06-26 02:48:02 +020032/* configuration sections */
33#define CFG_NONE 0
34#define CFG_GLOBAL 1
35#define CFG_LISTEN 2
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +010036#define CFG_USERLIST 3
Emeric Brun32da3c42010-09-23 18:39:19 +020037#define CFG_PEERS 4
Willy Tarreaubaaee002006-06-26 02:48:02 +020038
Willy Tarreau5b2c3362008-07-09 19:39:06 +020039struct cfg_keyword {
40 int section; /* section type for this keyword */
41 const char *kw; /* the keyword itself */
Willy Tarreau39f23b62008-07-09 20:22:56 +020042 int (*parse)( /* 0=OK, <0=Alert, >0=Warning */
43 char **args, /* command line and arguments */
Willy Tarreau5b2c3362008-07-09 19:39:06 +020044 int section_type, /* current section CFG_{GLOBAL|LISTEN} */
45 struct proxy *curpx, /* current proxy (NULL in GLOBAL) */
46 struct proxy *defpx, /* default proxy (NULL in GLOBAL) */
Willy Tarreau28a47d62012-09-18 20:02:48 +020047 const char *file, /* config file name */
48 int line, /* config file line number */
Willy Tarreau0a3dd742012-05-08 19:47:01 +020049 char **err); /* error or warning message output pointer */
Willy Tarreau5b2c3362008-07-09 19:39:06 +020050};
51
52/* A keyword list. It is a NULL-terminated array of keywords. It embeds a
53 * struct list in order to be linked to other lists, allowing it to easily
54 * be declared where it is needed, and linked without duplicating data nor
55 * allocating memory.
56 */
57struct cfg_kw_list {
58 struct list list;
59 struct cfg_keyword kw[VAR_ARRAY];
60};
61
62
Willy Tarreaubaaee002006-06-26 02:48:02 +020063extern int cfg_maxpconn;
64extern int cfg_maxconn;
65
Krzysztof Oledzki336d4752007-12-25 02:40:22 +010066int cfg_parse_global(const char *file, int linenum, char **args, int inv);
67int cfg_parse_listen(const char *file, int linenum, char **args, int inv);
Willy Tarreaub17916e2006-10-15 15:17:57 +020068int readcfgfile(const char *file);
Willy Tarreau5b2c3362008-07-09 19:39:06 +020069void cfg_register_keywords(struct cfg_kw_list *kwl);
70void cfg_unregister_keywords(struct cfg_kw_list *kwl);
Willy Tarreau915e1eb2009-06-22 15:48:36 +020071void init_default_instance();
72int check_config_validity();
Willy Tarreau4fbb2282012-09-20 20:01:39 +020073int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +010074int cfg_register_section(char *section_name,
75 int (*section_parser)(const char *, int, char **, int));
David Carlier845efb52015-09-25 11:49:18 +010076void cfg_unregister_sections(void);
Willy Tarreau3986b9c2014-09-16 15:39:51 +020077int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg);
78int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg);
Willy Tarreaubaaee002006-06-26 02:48:02 +020079
Willy Tarreau272adea2014-03-31 10:39:59 +020080/*
81 * Sends a warning if proxy <proxy> does not have at least one of the
82 * capabilities in <cap>. An optionnal <hint> may be added at the end
83 * of the warning to help the user. Returns 1 if a warning was emitted
84 * or 0 if the condition is valid.
85 */
86static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint)
87{
88 char *msg;
89
90 switch (cap) {
91 case PR_CAP_BE: msg = "no backend"; break;
92 case PR_CAP_FE: msg = "no frontend"; break;
93 case PR_CAP_RS: msg = "no ruleset"; break;
94 case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break;
95 default: msg = "not enough"; break;
96 }
97
98 if (!(proxy->cap & cap)) {
99 Warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n",
100 file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : "");
101 return 1;
102 }
103 return 0;
104}
105
Willy Tarreau2dd0d472006-06-29 17:53:05 +0200106#endif /* _COMMON_CFGPARSE_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200107
108/*
109 * Local variables:
110 * c-indent-level: 8
111 * c-basic-offset: 8
112 * End:
113 */