1 /* -*-pgsql-c-*- */
2 /*
3  *
4  * $Header$
5  *
6  * pgpool: a language independent connection pool server for PostgreSQL
7  * written by Tatsuo Ishii
8  *
9  * Copyright (c) 2003-2016	PgPool Global Development Group
10  *
11  * Permission to use, copy, modify, and distribute this software and
12  * its documentation for any purpose and without fee is hereby
13  * granted, provided that the above copyright notice appear in all
14  * copies and that both that copyright notice and this permission
15  * notice appear in supporting documentation, and that the name of the
16  * author not be used in advertising or publicity pertaining to
17  * distribution of the software without specific, written prior
18  * permission. The author makes no representations about the
19  * suitability of this software for any purpose.  It is provided "as
20  * is" without express or implied warranty.
21  *
22  * pool_config_variables.h.
23  *
24  */
25 
26 #ifndef POOL_CONFIG_VARIABLES_H
27 #define POOL_CONFIG_VARIABLES_H
28 
29 
30 typedef enum
31 {
32 	CONNECTION_CONFIG,
33 	CONNECTION_POOL_CONFIG,
34 	LOGING_CONFIG,
35 	HEALTH_CHECK_CONFIG,
36 	FILE_LOCATION_CONFIG,
37 	LOAD_BALANCE_CONFIG,
38 	REPLICATION_CONFIG,
39 	STREAMING_REPLICATION_CONFIG,
40 	MASTER_SLAVE_CONFIG,
41 	WATCHDOG_CONFIG,
42 	SSL_CONFIG,
43 	FAILOVER_CONFIG,
44 	RECOVERY_CONFIG,
45 	WATCHDOG_LIFECHECK,
46 	GENERAL_CONFIG,
47 	CACHE_CONFIG
48 } config_group;
49 
50 typedef enum
51 {
52 	CONFIG_VAR_TYPE_BOOL,
53 	CONFIG_VAR_TYPE_INT,
54 	CONFIG_VAR_TYPE_LONG,
55 	CONFIG_VAR_TYPE_DOUBLE,
56 	CONFIG_VAR_TYPE_STRING,
57 	CONFIG_VAR_TYPE_STRING_LIST,
58 	CONFIG_VAR_TYPE_ENUM,
59 	CONFIG_VAR_TYPE_INT_ARRAY,
60 	CONFIG_VAR_TYPE_DOUBLE_ARRAY,
61 	CONFIG_VAR_TYPE_STRING_ARRAY,
62 	CONFIG_VAR_TYPE_GROUP
63 }config_type;
64 
65 /*
66  * The possible values of an enum variable are specified by an array of
67  * name-value pairs.  The "hidden" flag means the value is accepted but
68  * won't be displayed when guc.c is asked for a list of acceptable values.
69  */
70 struct config_enum_entry
71 {
72 	const char *name;
73 	int			val;
74 	bool		hidden;
75 };
76 
77 typedef enum
78 {
79 	PGC_S_DEFAULT,				/* hard-wired default ("boot_val") */
80 	PGC_S_FILE,					/* pgpool.conf */
81 	PGC_S_ARGV,					/* command line */
82 	PGC_S_CLIENT,				/* from client connection request */
83 	PGC_S_SESSION				/* SET command */
84 } GucSource;
85 
86 
87 /* Config variable flags bit values */
88 #define VAR_PART_OF_GROUP			0x0001
89 #define VAR_HIDDEN_VALUE			0x0002	/* for password type variables */
90 #define VAR_HIDDEN_IN_SHOW_ALL		0x0004	/* for variables hidden in show all*/
91 #define VAR_NO_RESET_ALL			0x0008	/* for variables not to be reset with reset all*/
92 
93 /*
94  * Signatures for per-variable check/assign/show  functions
95  */
96 
97 typedef const char *(*VarShowHook) (void);
98 typedef const char *(*IndexedVarShowHook) (int index);
99 typedef bool (*IndexedVarEmptySlotCheck) (int index);
100 
101 typedef bool (*ConfigBoolAssignFunc) (ConfigContext scontext, bool newval, int elevel);
102 typedef bool (*ConfigEnumAssignFunc) (ConfigContext scontext, int newval, int elevel);
103 
104 typedef bool (*ConfigStringListAssignFunc) (ConfigContext scontext, char* newval, int index);
105 
106 typedef bool (*ConfigInt64AssignFunc)  (ConfigContext scontext, int64 newval, int elevel);
107 
108 typedef bool (*ConfigStringAssignFunc) (ConfigContext scontext, char* newval, int elevel);
109 typedef bool (*ConfigStringArrayAssignFunc) (ConfigContext scontext, char* newval, int index, int elevel);
110 
111 typedef bool (*ConfigIntAssignFunc)	(ConfigContext scontext, int newval, int elevel);
112 typedef bool (*ConfigIntArrayAssignFunc) (ConfigContext scontext, int newval, int index, int elevel);
113 
114 typedef bool (*ConfigDoubleAssignFunc) (ConfigContext scontext, double newval, int elevel);
115 typedef bool (*ConfigDoubleArrayAssignFunc) (ConfigContext scontext, double newval, int index, int elevel);
116 
117 typedef bool (*ConfigStringProcessingFunc) (char* newval,int elevel);
118 typedef bool (*ConfigEnumProcessingFunc) (int newval,int elevel);
119 
120 
121 struct config_generic
122 {
123 	/* constant fields, must be set correctly in initial value: */
124 	const char		*name;			/* name of variable - MUST BE FIRST */
125 	ConfigContext	context;		/* context required to set the variable */
126 	config_group	group;			/* to help organize variables by function */
127 	const char		*description;	/* short desc. of this variable's purpose */
128 	config_type		vartype;		/* type of variable (set only at startup) */
129 	bool			dynamic_array_var;	/* true if the variable name contains index postfix */
130 	int				flags;			/* flags */
131 	int				status;			/* status bits, see below */
132 	GucSource		source;			/* source of the current actual value */
133 	ConfigContext	scontext;		/* context that set the current value */
134 	int				sourceline;		/* line in source file */
135 };
136 
137 /* GUC records for specific variable types */
138 
139 struct config_bool
140 {
141 	struct config_generic gen;
142 	/* constant fields, must be set correctly in initial value: */
143 	bool	   *variable;
144 	bool		boot_val;
145 	ConfigBoolAssignFunc assign_func;
146 	ConfigBoolAssignFunc check_func;
147 	VarShowHook show_hook;
148 	bool		reset_val;
149 };
150 
151 struct config_int
152 {
153 	struct config_generic gen;
154 	/* constant fields, must be set correctly in initial value: */
155 	int		   *variable;
156 	int			boot_val;
157 	int			min;
158 	int			max;
159 	ConfigIntAssignFunc assign_func;
160 	ConfigIntAssignFunc check_func;
161 	VarShowHook show_hook;
162 	int		reset_val;
163 };
164 
165 struct config_int_array
166 {
167 	struct config_generic gen;
168 	/* constant fields, must be set correctly in initial value: */
169 	int		   **variable;
170 	int			boot_val;
171 	int			min;
172 	int			max;
173 	int			max_elements;
174 	ConfigIntArrayAssignFunc assign_func;
175 	ConfigIntArrayAssignFunc check_func;
176 	IndexedVarShowHook show_hook;
177 	IndexedVarEmptySlotCheck	empty_slot_check_func;
178 	int			*reset_vals; /* Array of reset values */
179 };
180 
181 
182 struct config_double
183 {
184 	struct config_generic gen;
185 	/* constant fields, must be set correctly in initial value: */
186 	double		*variable;
187 	double		boot_val;
188 	double		min;
189 	double		max;
190 	ConfigDoubleAssignFunc assign_func;
191 	ConfigDoubleAssignFunc check_func;
192 	VarShowHook show_hook;
193 	double		reset_val;
194 };
195 
196 struct config_double_array
197 {
198 	struct config_generic gen;
199 	/* constant fields, must be set correctly in initial value: */
200 	double		**variable;
201 	double		boot_val;
202 	double		min;
203 	double		max;
204 	int			max_elements;
205 	ConfigDoubleArrayAssignFunc assign_func;
206 	ConfigDoubleArrayAssignFunc check_func;
207 	IndexedVarShowHook show_hook;
208 	IndexedVarEmptySlotCheck	empty_slot_check_func;
209 	double		*reset_vals;
210 };
211 
212 struct config_long
213 {
214 	struct config_generic gen;
215 	/* constant fields, must be set correctly in initial value: */
216 	int64		*variable;
217 	int64		boot_val;
218 	int64		min;
219 	int64		max;
220 	ConfigInt64AssignFunc assign_func;
221 	ConfigInt64AssignFunc check_func;
222 	VarShowHook show_hook;
223 	int64		reset_val;
224 };
225 
226 struct config_string
227 {
228 	struct config_generic gen;
229 	/* constant fields, must be set correctly in initial value: */
230 	char	  **variable;
231 	const char *boot_val;
232 	ConfigStringAssignFunc assign_func;
233 	ConfigStringAssignFunc check_func;
234 	ConfigStringProcessingFunc process_func;
235 	VarShowHook show_hook;
236 	char*		reset_val;
237 };
238 
239 struct config_string_array
240 {
241 	struct config_generic gen;
242 	/* constant fields, must be set correctly in initial value: */
243 	char		***variable;
244 	const char	*boot_val;
245 	int			max_elements;
246 	ConfigStringArrayAssignFunc assign_func;
247 	ConfigStringArrayAssignFunc check_func;
248 	IndexedVarShowHook show_hook;
249 	IndexedVarEmptySlotCheck	empty_slot_check_func;
250 	char		**reset_vals;
251 };
252 
253 struct config_string_list
254 {
255 	struct config_generic gen;
256 	/* constant fields, must be set correctly in initial value: */
257 	char		***variable;
258 	int			*list_elements_count;
259 	const char	*boot_val;
260 	const char	*seperator;
261 	bool		compute_regex;
262 	ConfigStringListAssignFunc assign_func;
263 	ConfigStringListAssignFunc check_func;
264 	VarShowHook show_hook;
265 	char		*reset_val;
266 	char		*current_val;
267 };
268 
269 struct config_enum
270 {
271 	struct config_generic gen;
272 	/* constant fields, must be set correctly in initial value: */
273 	int		   *variable;
274 	int			boot_val;
275 	const struct config_enum_entry *options;
276 	ConfigEnumAssignFunc assign_func;
277 	ConfigEnumAssignFunc check_func;
278 	ConfigEnumProcessingFunc process_func;
279 	VarShowHook show_hook;
280 	int		reset_val;
281 };
282 
283 struct config_grouped_array_var
284 {
285 	struct config_generic gen;
286 	int var_count;
287 	struct config_generic **var_list;
288 };
289 
290 extern void InitializeConfigOptions(void);
291 extern bool set_one_config_option(const char *name, const char *value,
292 						   ConfigContext context, GucSource source, int elevel);
293 
294 extern bool set_config_options(ConfigVariable *head_p,
295 							   ConfigContext context, GucSource source, int elevel);
296 extern bool assign_variable_to_int_array_config_var(const char* name, int** variable);
297 
298 
299 #ifndef POOL_PRIVATE
300 extern bool report_config_variable(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const char* var_name);
301 extern bool report_all_variables(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
302 extern bool set_config_option_for_session(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const char *name, const char *value);
303 bool reset_all_variables(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
304 #endif
305 
306 #endif /* POOL_CONFIG_VARIABLES_H */
307