Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 2 | * 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 Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 22 | #ifndef _COMMON_CFGPARSE_H |
| 23 | #define _COMMON_CFGPARSE_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 25 | #include <common/compat.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 26 | #include <common/config.h> |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 27 | #include <common/mini-clist.h> |
| 28 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 29 | #include <proto/log.h> |
| 30 | #include <proto/proxy.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 32 | /* configuration sections */ |
| 33 | #define CFG_NONE 0 |
| 34 | #define CFG_GLOBAL 1 |
| 35 | #define CFG_LISTEN 2 |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 36 | #define CFG_USERLIST 3 |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 37 | #define CFG_PEERS 4 |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 39 | struct cfg_keyword { |
| 40 | int section; /* section type for this keyword */ |
| 41 | const char *kw; /* the keyword itself */ |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 42 | int (*parse)( /* 0=OK, <0=Alert, >0=Warning */ |
| 43 | char **args, /* command line and arguments */ |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 44 | 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 Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 47 | const char *file, /* config file name */ |
| 48 | int line, /* config file line number */ |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 49 | char **err); /* error or warning message output pointer */ |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 50 | }; |
| 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 | */ |
| 57 | struct cfg_kw_list { |
| 58 | struct list list; |
| 59 | struct cfg_keyword kw[VAR_ARRAY]; |
| 60 | }; |
| 61 | |
| 62 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 63 | extern int cfg_maxpconn; |
| 64 | extern int cfg_maxconn; |
| 65 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 66 | int cfg_parse_global(const char *file, int linenum, char **args, int inv); |
| 67 | int cfg_parse_listen(const char *file, int linenum, char **args, int inv); |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 68 | int readcfgfile(const char *file); |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 69 | void cfg_register_keywords(struct cfg_kw_list *kwl); |
| 70 | void cfg_unregister_keywords(struct cfg_kw_list *kwl); |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 71 | void init_default_instance(); |
| 72 | int check_config_validity(); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 73 | int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 74 | int cfg_register_section(char *section_name, |
| 75 | int (*section_parser)(const char *, int, char **, int)); |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 76 | void cfg_unregister_sections(void); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 77 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 78 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 79 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 80 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 81 | /* |
| 82 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 83 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 84 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 85 | * or 0 if the condition is valid. |
| 86 | */ |
| 87 | static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
| 88 | { |
| 89 | char *msg; |
| 90 | |
| 91 | switch (cap) { |
| 92 | case PR_CAP_BE: msg = "no backend"; break; |
| 93 | case PR_CAP_FE: msg = "no frontend"; break; |
| 94 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 95 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 96 | default: msg = "not enough"; break; |
| 97 | } |
| 98 | |
| 99 | if (!(proxy->cap & cap)) { |
| 100 | Warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", |
| 101 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
| 102 | return 1; |
| 103 | } |
| 104 | return 0; |
| 105 | } |
| 106 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 107 | #endif /* _COMMON_CFGPARSE_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Local variables: |
| 111 | * c-indent-level: 8 |
| 112 | * c-basic-offset: 8 |
| 113 | * End: |
| 114 | */ |