]> git.8kb.co.uk Git - pgpool-ii/pgpool-ii_2.2.5/blob - pool_config.c
Attempt to send a proper failure message to frontend when authentication
[pgpool-ii/pgpool-ii_2.2.5] / pool_config.c
1 /* A lexical scanner generated by flex */
2
3 /* Scanner skeleton version:
4  * $Header: /cvsroot/pgpool/pgpool-II/pool_config.c,v 1.27.2.1 2009/08/22 04:19:49 t-ishii Exp $
5  */
6
7 #define FLEX_SCANNER
8 #define YY_FLEX_MAJOR_VERSION 2
9 #define YY_FLEX_MINOR_VERSION 5
10
11 #include <stdio.h>
12 #include <unistd.h>
13
14
15 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
16 #ifdef c_plusplus
17 #ifndef __cplusplus
18 #define __cplusplus
19 #endif
20 #endif
21
22
23 #ifdef __cplusplus
24
25 #include <stdlib.h>
26
27 /* Use prototypes in function declarations. */
28 #define YY_USE_PROTOS
29
30 /* The "const" storage-class-modifier is valid. */
31 #define YY_USE_CONST
32
33 #else   /* ! __cplusplus */
34
35 #if __STDC__
36
37 #define YY_USE_PROTOS
38 #define YY_USE_CONST
39
40 #endif  /* __STDC__ */
41 #endif  /* ! __cplusplus */
42
43 #ifdef __TURBOC__
44  #pragma warn -rch
45  #pragma warn -use
46 #include <io.h>
47 #include <stdlib.h>
48 #define YY_USE_CONST
49 #define YY_USE_PROTOS
50 #endif
51
52 #ifdef YY_USE_CONST
53 #define yyconst const
54 #else
55 #define yyconst
56 #endif
57
58
59 #ifdef YY_USE_PROTOS
60 #define YY_PROTO(proto) proto
61 #else
62 #define YY_PROTO(proto) ()
63 #endif
64
65 /* Returned upon end-of-file. */
66 #define YY_NULL 0
67
68 /* Promotes a possibly negative, possibly signed char to an unsigned
69  * integer for use as an array index.  If the signed char is negative,
70  * we want to instead treat it as an 8-bit unsigned char, hence the
71  * double cast.
72  */
73 #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
74
75 /* Enter a start condition.  This macro really ought to take a parameter,
76  * but we do it the disgusting crufty way forced on us by the ()-less
77  * definition of BEGIN.
78  */
79 #define BEGIN yy_start = 1 + 2 *
80
81 /* Translate the current start state into a value that can be later handed
82  * to BEGIN to return to the state.  The YYSTATE alias is for lex
83  * compatibility.
84  */
85 #define YY_START ((yy_start - 1) / 2)
86 #define YYSTATE YY_START
87
88 /* Action number for EOF rule of a given start state. */
89 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
90
91 /* Special action meaning "start processing a new file". */
92 #define YY_NEW_FILE yyrestart( yyin )
93
94 #define YY_END_OF_BUFFER_CHAR 0
95
96 /* Size of default input buffer. */
97 #define YY_BUF_SIZE 16384
98
99 typedef struct yy_buffer_state *YY_BUFFER_STATE;
100
101 extern int yyleng;
102 extern FILE *yyin, *yyout;
103
104 #define EOB_ACT_CONTINUE_SCAN 0
105 #define EOB_ACT_END_OF_FILE 1
106 #define EOB_ACT_LAST_MATCH 2
107
108 /* The funky do-while in the following #define is used to turn the definition
109  * int a single C statement (which needs a semi-colon terminator).  This
110  * avoids problems with code like:
111  *
112  *      if ( condition_holds )
113  *              yyless( 5 );
114  *      else
115  *              do_something_else();
116  *
117  * Prior to using the do-while the compiler would get upset at the
118  * "else" because it interpreted the "if" statement as being all
119  * done when it reached the ';' after the yyless() call.
120  */
121
122 /* Return all but the first 'n' matched characters back to the input stream. */
123
124 #define yyless(n) \
125         do \
126                 { \
127                 /* Undo effects of setting up yytext. */ \
128                 *yy_cp = yy_hold_char; \
129                 YY_RESTORE_YY_MORE_OFFSET \
130                 yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
131                 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
132                 } \
133         while ( 0 )
134
135 #define unput(c) yyunput( c, yytext_ptr )
136
137 /* The following is because we cannot portably get our hands on size_t
138  * (without autoconf's help, which isn't available because we want
139  * flex-generated scanners to compile on their own).
140  */
141 typedef unsigned int yy_size_t;
142
143
144 struct yy_buffer_state
145         {
146         FILE *yy_input_file;
147
148         char *yy_ch_buf;                /* input buffer */
149         char *yy_buf_pos;               /* current position in input buffer */
150
151         /* Size of input buffer in bytes, not including room for EOB
152          * characters.
153          */
154         yy_size_t yy_buf_size;
155
156         /* Number of characters read into yy_ch_buf, not including EOB
157          * characters.
158          */
159         int yy_n_chars;
160
161         /* Whether we "own" the buffer - i.e., we know we created it,
162          * and can realloc() it to grow it, and should free() it to
163          * delete it.
164          */
165         int yy_is_our_buffer;
166
167         /* Whether this is an "interactive" input source; if so, and
168          * if we're using stdio for input, then we want to use getc()
169          * instead of fread(), to make sure we stop fetching input after
170          * each newline.
171          */
172         int yy_is_interactive;
173
174         /* Whether we're considered to be at the beginning of a line.
175          * If so, '^' rules will be active on the next match, otherwise
176          * not.
177          */
178         int yy_at_bol;
179
180         /* Whether to try to fill the input buffer when we reach the
181          * end of it.
182          */
183         int yy_fill_buffer;
184
185         int yy_buffer_status;
186 #define YY_BUFFER_NEW 0
187 #define YY_BUFFER_NORMAL 1
188         /* When an EOF's been seen but there's still some text to process
189          * then we mark the buffer as YY_EOF_PENDING, to indicate that we
190          * shouldn't try reading from the input source any more.  We might
191          * still have a bunch of tokens to match, though, because of
192          * possible backing-up.
193          *
194          * When we actually see the EOF, we change the status to "new"
195          * (via yyrestart()), so that the user can continue scanning by
196          * just pointing yyin at a new input file.
197          */
198 #define YY_BUFFER_EOF_PENDING 2
199         };
200
201 static YY_BUFFER_STATE yy_current_buffer = 0;
202
203 /* We provide macros for accessing buffer states in case in the
204  * future we want to put the buffer states in a more general
205  * "scanner state".
206  */
207 #define YY_CURRENT_BUFFER yy_current_buffer
208
209
210 /* yy_hold_char holds the character lost when yytext is formed. */
211 static char yy_hold_char;
212
213 static int yy_n_chars;          /* number of characters read into yy_ch_buf */
214
215
216 int yyleng;
217
218 /* Points to current character in buffer. */
219 static char *yy_c_buf_p = (char *) 0;
220 static int yy_init = 1;         /* whether we need to initialize */
221 static int yy_start = 0;        /* start state number */
222
223 /* Flag which is used to allow yywrap()'s to do buffer switches
224  * instead of setting up a fresh yyin.  A bit of a hack ...
225  */
226 static int yy_did_buffer_switch_on_eof;
227
228 void yyrestart YY_PROTO(( FILE *input_file ));
229
230 void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
231 void yy_load_buffer_state YY_PROTO(( void ));
232 YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
233 void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
234 void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
235 void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
236 #define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
237
238 YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
239 YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
240 YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
241
242 static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
243 static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
244 static void yy_flex_free YY_PROTO(( void * ));
245
246 #define yy_new_buffer yy_create_buffer
247
248 #define yy_set_interactive(is_interactive) \
249         { \
250         if ( ! yy_current_buffer ) \
251                 yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
252         yy_current_buffer->yy_is_interactive = is_interactive; \
253         }
254
255 #define yy_set_bol(at_bol) \
256         { \
257         if ( ! yy_current_buffer ) \
258                 yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
259         yy_current_buffer->yy_at_bol = at_bol; \
260         }
261
262 #define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
263
264
265 #define yywrap() 1
266 #define YY_SKIP_YYWRAP
267 typedef unsigned char YY_CHAR;
268 FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
269 typedef int yy_state_type;
270 extern char *yytext;
271 #define yytext_ptr yytext
272
273 static yy_state_type yy_get_previous_state YY_PROTO(( void ));
274 static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
275 static int yy_get_next_buffer YY_PROTO(( void ));
276 static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
277
278 /* Done after the current pattern has been matched and before the
279  * corresponding action - sets up yytext.
280  */
281 #define YY_DO_BEFORE_ACTION \
282         yytext_ptr = yy_bp; \
283         yyleng = (int) (yy_cp - yy_bp); \
284         yy_hold_char = *yy_cp; \
285         *yy_cp = '\0'; \
286         yy_c_buf_p = yy_cp;
287
288 #define YY_NUM_RULES 11
289 #define YY_END_OF_BUFFER 12
290 static yyconst short int yy_accept[38] =
291     {   0,
292         0,    0,   12,   10,    2,    1,   10,   10,   10,    8,
293         7,    7,    9,    4,    2,    0,    3,    0,    5,    0,
294         8,    7,    7,    8,    0,    0,    6,    4,    4,    0,
295         5,    0,    0,    8,    7,    6,    0
296     } ;
297
298 static yyconst int yy_ec[256] =
299     {   0,
300         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
301         1,    1,    2,    1,    1,    1,    1,    1,    1,    1,
302         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
303         1,    2,    1,    1,    4,    1,    1,    1,    5,    1,
304         1,    1,    6,    1,    7,    8,    9,   10,   11,   11,
305        11,   11,   11,   11,   11,   11,   11,    9,    1,    1,
306        12,    1,    1,    1,   13,   13,   13,   13,   14,   13,
307        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
308        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
309         1,   16,    1,    1,   17,    1,   13,   13,   13,   13,
310
311        14,   13,   15,   15,   15,   15,   15,   15,   15,   15,
312        15,   15,   15,   15,   15,   15,   15,   15,   15,   18,
313        15,   15,    1,    1,    1,    1,    1,   15,   15,   15,
314        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
315        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
316        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
317        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
318        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
319        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
320        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
321
322        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
323        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
324        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
325        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
326        15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
327        15,   15,   15,   15,   15
328     } ;
329
330 static yyconst int yy_meta[19] =
331     {   0,
332         1,    1,    2,    1,    1,    1,    3,    3,    3,    4,
333         4,    1,    5,    4,    3,    1,    3,    3
334     } ;
335
336 static yyconst short int yy_base[45] =
337     {   0,
338         0,    0,   61,   86,   58,   86,   55,   14,   23,   43,
339        10,   46,   86,   28,   47,   40,   86,   16,   86,   22,
340        28,    0,    0,    0,   40,    0,   24,   45,    0,   24,
341        39,   43,   12,   14,    0,   22,   86,   62,   67,   22,
342        70,   75,   77,   80
343     } ;
344
345 static yyconst short int yy_def[45] =
346     {   0,
347        37,    1,   37,   37,   37,   37,   38,   39,   37,   40,
348         9,    9,   37,   41,   37,   38,   37,   39,   37,   42,
349        40,   11,   12,   21,   37,   43,   44,   41,   28,   39,
350        39,   42,   37,   37,   43,   44,    0,   37,   37,   37,
351        37,   37,   37,   37
352     } ;
353
354 static yyconst short int yy_nxt[105] =
355     {   0,
356         4,    5,    6,    7,    8,    9,    9,   10,    4,   11,
357        12,   13,   14,   14,   14,    4,   14,   14,   19,   23,
358        19,   34,   34,   34,   34,   24,   31,   26,   19,   20,
359        21,   20,   22,   23,   27,   27,   27,   32,   36,   20,
360        36,   25,   17,   19,   29,   33,   33,   31,   15,   34,
361        34,   27,   27,   27,   20,   23,   25,   17,   32,   15,
362        37,   29,   16,   16,   16,   16,   16,   18,   37,   18,
363        18,   18,   28,   28,   28,   30,   37,   30,   30,   30,
364        35,   35,   27,   27,   27,    3,   37,   37,   37,   37,
365        37,   37,   37,   37,   37,   37,   37,   37,   37,   37,
366
367        37,   37,   37,   37
368     } ;
369
370 static yyconst short int yy_chk[105] =
371     {   0,
372         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
373         1,    1,    1,    1,    1,    1,    1,    1,    8,   11,
374        18,   33,   33,   34,   34,   40,   20,   11,   30,    8,
375         9,   18,    9,    9,   14,   14,   14,   20,   36,   30,
376        27,   21,   16,   31,   14,   25,   25,   32,   15,   25,
377        25,   28,   28,   28,   31,   12,   10,    7,   32,    5,
378         3,   28,   38,   38,   38,   38,   38,   39,    0,   39,
379        39,   39,   41,   41,   41,   42,    0,   42,   42,   42,
380        43,   43,   44,   44,   44,   37,   37,   37,   37,   37,
381        37,   37,   37,   37,   37,   37,   37,   37,   37,   37,
382
383        37,   37,   37,   37
384     } ;
385
386 static yy_state_type yy_last_accepting_state;
387 static char *yy_last_accepting_cpos;
388
389 /* The intent behind this definition is that it'll catch
390  * any uses of REJECT which flex missed.
391  */
392 #define REJECT reject_used_but_not_detected
393 #define yymore() yymore_used_but_not_detected
394 #define YY_MORE_ADJ 0
395 #define YY_RESTORE_YY_MORE_OFFSET
396 char *yytext;
397 #line 1 "pool_config.l"
398 #define INITIAL 0
399 /* -*-pgsql-c-*- */
400 /*
401  *
402  * $Header: /cvsroot/pgpool/pgpool-II/pool_config.c,v 1.27.2.1 2009/08/22 04:19:49 t-ishii Exp $
403  *
404  * pgpool: a language independent connection pool server for PostgreSQL
405  * written by Tatsuo Ishii
406  *
407  * Copyright (c) 2003-2009      PgPool Global Development Group
408  *
409  * Permission to use, copy, modify, and distribute this software and
410  * its documentation for any purpose and without fee is hereby
411  * granted, provided that the above copyright notice appear in all
412  * copies and that both that copyright notice and this permission
413  * notice appear in supporting documentation, and that the name of the
414  * author not be used in advertising or publicity pertaining to
415  * distribution of the software without specific, written prior
416  * permission. The author makes no representations about the
417  * suitability of this software for any purpose.  It is provided "as
418  * is" without express or implied warranty.
419  *
420  * pool_config.l: read configuration file
421  *
422  */
423 #line 27 "pool_config.l"
424
425 #include "pool.h"
426
427 #include <stdio.h>
428 #include <stdlib.h>
429 #include <string.h>
430
431 #define CHECK_CONTEXT(mask, context) ((mask) & (context))
432
433 /* to shut off compiler warnings */
434 int yylex(void);
435
436 POOL_CONFIG *pool_config;       /* configuration values */
437 POOL_SYSTEMDB_CONNECTION_POOL *system_db_info;
438 static unsigned Lineno;
439 static char *default_reset_query_list[] = {"ABORT", "RESET ALL", "SET SESSION AUTHORIZATION DEFAULT"};
440
441 typedef enum {
442   POOL_KEY = 1,
443   POOL_INTEGER,
444   POOL_REAL,
445   POOL_STRING,
446   POOL_UNQUOTED_STRING,
447   POOL_EQUALS,
448   POOL_EOL,
449   POOL_PARSE_ERROR
450 } POOL_TOKEN;
451
452 static char *extract_string(char *value, POOL_TOKEN token);
453 static char **extract_string_tokens(char *str, char *delim, int *n);
454 static int eval_logical(char *str);
455 static void clear_host_entry(int slot);
456
457 #define YY_NEVER_INTERACTIVE 1
458 #define YY_NO_UNPUT 1
459 #line 460 "pool_config.c"
460
461 /* Macros after this point can all be overridden by user definitions in
462  * section 1.
463  */
464
465 #ifndef YY_SKIP_YYWRAP
466 #ifdef __cplusplus
467 extern "C" int yywrap YY_PROTO(( void ));
468 #else
469 extern int yywrap YY_PROTO(( void ));
470 #endif
471 #endif
472
473 #ifndef YY_NO_UNPUT
474 static void yyunput YY_PROTO(( int c, char *buf_ptr ));
475 #endif
476
477 #ifndef yytext_ptr
478 static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
479 #endif
480
481 #ifdef YY_NEED_STRLEN
482 static int yy_flex_strlen YY_PROTO(( yyconst char * ));
483 #endif
484
485 #ifndef YY_NO_INPUT
486 #ifdef __cplusplus
487 static int yyinput YY_PROTO(( void ));
488 #else
489 static int input YY_PROTO(( void ));
490 #endif
491 #endif
492
493 #if YY_STACK_USED
494 static int yy_start_stack_ptr = 0;
495 static int yy_start_stack_depth = 0;
496 static int *yy_start_stack = 0;
497 #ifndef YY_NO_PUSH_STATE
498 static void yy_push_state YY_PROTO(( int new_state ));
499 #endif
500 #ifndef YY_NO_POP_STATE
501 static void yy_pop_state YY_PROTO(( void ));
502 #endif
503 #ifndef YY_NO_TOP_STATE
504 static int yy_top_state YY_PROTO(( void ));
505 #endif
506
507 #else
508 #define YY_NO_PUSH_STATE 1
509 #define YY_NO_POP_STATE 1
510 #define YY_NO_TOP_STATE 1
511 #endif
512
513 #ifdef YY_MALLOC_DECL
514 YY_MALLOC_DECL
515 #else
516 #if __STDC__
517 #ifndef __cplusplus
518 #include <stdlib.h>
519 #endif
520 #else
521 /* Just try to get by without declaring the routines.  This will fail
522  * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
523  * or sizeof(void*) != sizeof(int).
524  */
525 #endif
526 #endif
527
528 /* Amount of stuff to slurp up with each read. */
529 #ifndef YY_READ_BUF_SIZE
530 #define YY_READ_BUF_SIZE 8192
531 #endif
532
533 /* Copy whatever the last rule matched to the standard output. */
534
535 #ifndef ECHO
536 /* This used to be an fputs(), but since the string might contain NUL's,
537  * we now use fwrite().
538  */
539 #define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
540 #endif
541
542 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
543  * is returned in "result".
544  */
545 #ifndef YY_INPUT
546 #define YY_INPUT(buf,result,max_size) \
547         if ( yy_current_buffer->yy_is_interactive ) \
548                 { \
549                 int c = '*', n; \
550                 for ( n = 0; n < max_size && \
551                              (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
552                         buf[n] = (char) c; \
553                 if ( c == '\n' ) \
554                         buf[n++] = (char) c; \
555                 if ( c == EOF && ferror( yyin ) ) \
556                         YY_FATAL_ERROR( "input in flex scanner failed" ); \
557                 result = n; \
558                 } \
559         else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
560                   && ferror( yyin ) ) \
561                 YY_FATAL_ERROR( "input in flex scanner failed" );
562 #endif
563
564 /* No semi-colon after return; correct usage is to write "yyterminate();" -
565  * we don't want an extra ';' after the "return" because that will cause
566  * some compilers to complain about unreachable statements.
567  */
568 #ifndef yyterminate
569 #define yyterminate() return YY_NULL
570 #endif
571
572 /* Number of entries by which start-condition stack grows. */
573 #ifndef YY_START_STACK_INCR
574 #define YY_START_STACK_INCR 25
575 #endif
576
577 /* Report a fatal error. */
578 #ifndef YY_FATAL_ERROR
579 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
580 #endif
581
582 /* Default declaration of generated scanner - a define so the user can
583  * easily add parameters.
584  */
585 #ifndef YY_DECL
586 #define YY_DECL int yylex YY_PROTO(( void ))
587 #endif
588
589 /* Code executed at the beginning of each rule, after yytext and yyleng
590  * have been set up.
591  */
592 #ifndef YY_USER_ACTION
593 #define YY_USER_ACTION
594 #endif
595
596 /* Code executed at the end of each rule. */
597 #ifndef YY_BREAK
598 #define YY_BREAK break;
599 #endif
600
601 #define YY_RULE_SETUP \
602         YY_USER_ACTION
603
604 YY_DECL
605         {
606         register yy_state_type yy_current_state;
607         register char *yy_cp = NULL, *yy_bp = NULL;
608         register int yy_act;
609
610 #line 84 "pool_config.l"
611
612
613 #line 614 "pool_config.c"
614
615         if ( yy_init )
616                 {
617                 yy_init = 0;
618
619 #ifdef YY_USER_INIT
620                 YY_USER_INIT;
621 #endif
622
623                 if ( ! yy_start )
624                         yy_start = 1;   /* first start state */
625
626                 if ( ! yyin )
627                         yyin = stdin;
628
629                 if ( ! yyout )
630                         yyout = stdout;
631
632                 if ( ! yy_current_buffer )
633                         yy_current_buffer =
634                                 yy_create_buffer( yyin, YY_BUF_SIZE );
635
636                 yy_load_buffer_state();
637                 }
638
639         while ( 1 )             /* loops until end-of-file is reached */
640                 {
641                 yy_cp = yy_c_buf_p;
642
643                 /* Support of yytext. */
644                 *yy_cp = yy_hold_char;
645
646                 /* yy_bp points to the position in yy_ch_buf of the start of
647                  * the current run.
648                  */
649                 yy_bp = yy_cp;
650
651                 yy_current_state = yy_start;
652 yy_match:
653                 do
654                         {
655                         register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
656                         if ( yy_accept[yy_current_state] )
657                                 {
658                                 yy_last_accepting_state = yy_current_state;
659                                 yy_last_accepting_cpos = yy_cp;
660                                 }
661                         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
662                                 {
663                                 yy_current_state = (int) yy_def[yy_current_state];
664                                 if ( yy_current_state >= 38 )
665                                         yy_c = yy_meta[(unsigned int) yy_c];
666                                 }
667                         yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
668                         ++yy_cp;
669                         }
670                 while ( yy_base[yy_current_state] != 86 );
671
672 yy_find_action:
673                 yy_act = yy_accept[yy_current_state];
674                 if ( yy_act == 0 )
675                         { /* have to back up */
676                         yy_cp = yy_last_accepting_cpos;
677                         yy_current_state = yy_last_accepting_state;
678                         yy_act = yy_accept[yy_current_state];
679                         }
680
681                 YY_DO_BEFORE_ACTION;
682
683
684 do_action:      /* This label is used only to access EOF actions. */
685
686
687                 switch ( yy_act )
688         { /* beginning of action switch */
689                         case 0: /* must back up */
690                         /* undo the effects of YY_DO_BEFORE_ACTION */
691                         *yy_cp = yy_hold_char;
692                         yy_cp = yy_last_accepting_cpos;
693                         yy_current_state = yy_last_accepting_state;
694                         goto yy_find_action;
695
696 case 1:
697 YY_RULE_SETUP
698 #line 86 "pool_config.l"
699 Lineno++; return POOL_EOL;
700         YY_BREAK
701 case 2:
702 YY_RULE_SETUP
703 #line 87 "pool_config.l"
704 /* eat whitespace */
705         YY_BREAK
706 case 3:
707 *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
708 yy_c_buf_p = yy_cp -= 1;
709 YY_DO_BEFORE_ACTION; /* set up yytext again */
710 YY_RULE_SETUP
711 #line 88 "pool_config.l"
712 /* eat comment */
713         YY_BREAK
714 case 4:
715 YY_RULE_SETUP
716 #line 90 "pool_config.l"
717 return POOL_KEY;
718         YY_BREAK
719 case 5:
720 YY_RULE_SETUP
721 #line 91 "pool_config.l"
722 return POOL_STRING;
723         YY_BREAK
724 case 6:
725 YY_RULE_SETUP
726 #line 92 "pool_config.l"
727 return POOL_UNQUOTED_STRING;
728         YY_BREAK
729 case 7:
730 YY_RULE_SETUP
731 #line 93 "pool_config.l"
732 return POOL_INTEGER;
733         YY_BREAK
734 case 8:
735 YY_RULE_SETUP
736 #line 94 "pool_config.l"
737 return POOL_REAL;
738         YY_BREAK
739 case 9:
740 YY_RULE_SETUP
741 #line 95 "pool_config.l"
742 return POOL_EQUALS;
743         YY_BREAK
744 case 10:
745 YY_RULE_SETUP
746 #line 97 "pool_config.l"
747 return POOL_PARSE_ERROR;
748         YY_BREAK
749 case 11:
750 YY_RULE_SETUP
751 #line 99 "pool_config.l"
752 ECHO;
753         YY_BREAK
754 #line 755 "pool_config.c"
755 case YY_STATE_EOF(INITIAL):
756         yyterminate();
757
758         case YY_END_OF_BUFFER:
759                 {
760                 /* Amount of text matched not including the EOB char. */
761                 int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
762
763                 /* Undo the effects of YY_DO_BEFORE_ACTION. */
764                 *yy_cp = yy_hold_char;
765                 YY_RESTORE_YY_MORE_OFFSET
766
767                 if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
768                         {
769                         /* We're scanning a new file or input source.  It's
770                          * possible that this happened because the user
771                          * just pointed yyin at a new source and called
772                          * yylex().  If so, then we have to assure
773                          * consistency between yy_current_buffer and our
774                          * globals.  Here is the right place to do so, because
775                          * this is the first action (other than possibly a
776                          * back-up) that will match for the new input source.
777                          */
778                         yy_n_chars = yy_current_buffer->yy_n_chars;
779                         yy_current_buffer->yy_input_file = yyin;
780                         yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
781                         }
782
783                 /* Note that here we test for yy_c_buf_p "<=" to the position
784                  * of the first EOB in the buffer, since yy_c_buf_p will
785                  * already have been incremented past the NUL character
786                  * (since all states make transitions on EOB to the
787                  * end-of-buffer state).  Contrast this with the test
788                  * in input().
789                  */
790                 if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
791                         { /* This was really a NUL. */
792                         yy_state_type yy_next_state;
793
794                         yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
795
796                         yy_current_state = yy_get_previous_state();
797
798                         /* Okay, we're now positioned to make the NUL
799                          * transition.  We couldn't have
800                          * yy_get_previous_state() go ahead and do it
801                          * for us because it doesn't know how to deal
802                          * with the possibility of jamming (and we don't
803                          * want to build jamming into it because then it
804                          * will run more slowly).
805                          */
806
807                         yy_next_state = yy_try_NUL_trans( yy_current_state );
808
809                         yy_bp = yytext_ptr + YY_MORE_ADJ;
810
811                         if ( yy_next_state )
812                                 {
813                                 /* Consume the NUL. */
814                                 yy_cp = ++yy_c_buf_p;
815                                 yy_current_state = yy_next_state;
816                                 goto yy_match;
817                                 }
818
819                         else
820                                 {
821                                 yy_cp = yy_c_buf_p;
822                                 goto yy_find_action;
823                                 }
824                         }
825
826                 else switch ( yy_get_next_buffer() )
827                         {
828                         case EOB_ACT_END_OF_FILE:
829                                 {
830                                 yy_did_buffer_switch_on_eof = 0;
831
832                                 if ( yywrap() )
833                                         {
834                                         /* Note: because we've taken care in
835                                          * yy_get_next_buffer() to have set up
836                                          * yytext, we can now set up
837                                          * yy_c_buf_p so that if some total
838                                          * hoser (like flex itself) wants to
839                                          * call the scanner after we return the
840                                          * YY_NULL, it'll still work - another
841                                          * YY_NULL will get returned.
842                                          */
843                                         yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
844
845                                         yy_act = YY_STATE_EOF(YY_START);
846                                         goto do_action;
847                                         }
848
849                                 else
850                                         {
851                                         if ( ! yy_did_buffer_switch_on_eof )
852                                                 YY_NEW_FILE;
853                                         }
854                                 break;
855                                 }
856
857                         case EOB_ACT_CONTINUE_SCAN:
858                                 yy_c_buf_p =
859                                         yytext_ptr + yy_amount_of_matched_text;
860
861                                 yy_current_state = yy_get_previous_state();
862
863                                 yy_cp = yy_c_buf_p;
864                                 yy_bp = yytext_ptr + YY_MORE_ADJ;
865                                 goto yy_match;
866
867                         case EOB_ACT_LAST_MATCH:
868                                 yy_c_buf_p =
869                                 &yy_current_buffer->yy_ch_buf[yy_n_chars];
870
871                                 yy_current_state = yy_get_previous_state();
872
873                                 yy_cp = yy_c_buf_p;
874                                 yy_bp = yytext_ptr + YY_MORE_ADJ;
875                                 goto yy_find_action;
876                         }
877                 break;
878                 }
879
880         default:
881                 YY_FATAL_ERROR(
882                         "fatal flex scanner internal error--no action found" );
883         } /* end of action switch */
884                 } /* end of scanning one token */
885         } /* end of yylex */
886
887
888 /* yy_get_next_buffer - try to read in a new buffer
889  *
890  * Returns a code representing an action:
891  *      EOB_ACT_LAST_MATCH -
892  *      EOB_ACT_CONTINUE_SCAN - continue scanning from current position
893  *      EOB_ACT_END_OF_FILE - end of file
894  */
895
896 static int yy_get_next_buffer()
897         {
898         register char *dest = yy_current_buffer->yy_ch_buf;
899         register char *source = yytext_ptr;
900         register int number_to_move, i;
901         int ret_val;
902
903         if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
904                 YY_FATAL_ERROR(
905                 "fatal flex scanner internal error--end of buffer missed" );
906
907         if ( yy_current_buffer->yy_fill_buffer == 0 )
908                 { /* Don't try to fill the buffer, so this is an EOF. */
909                 if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
910                         {
911                         /* We matched a single character, the EOB, so
912                          * treat this as a final EOF.
913                          */
914                         return EOB_ACT_END_OF_FILE;
915                         }
916
917                 else
918                         {
919                         /* We matched some text prior to the EOB, first
920                          * process it.
921                          */
922                         return EOB_ACT_LAST_MATCH;
923                         }
924                 }
925
926         /* Try to read more data. */
927
928         /* First move last chars to start of buffer. */
929         number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
930
931         for ( i = 0; i < number_to_move; ++i )
932                 *(dest++) = *(source++);
933
934         if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
935                 /* don't do the read, it's not guaranteed to return an EOF,
936                  * just force an EOF
937                  */
938                 yy_current_buffer->yy_n_chars = yy_n_chars = 0;
939
940         else
941                 {
942                 int num_to_read =
943                         yy_current_buffer->yy_buf_size - number_to_move - 1;
944
945                 while ( num_to_read <= 0 )
946                         { /* Not enough room in the buffer - grow it. */
947 #ifdef YY_USES_REJECT
948                         YY_FATAL_ERROR(
949 "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
950 #else
951
952                         /* just a shorter name for the current buffer */
953                         YY_BUFFER_STATE b = yy_current_buffer;
954
955                         int yy_c_buf_p_offset =
956                                 (int) (yy_c_buf_p - b->yy_ch_buf);
957
958                         if ( b->yy_is_our_buffer )
959                                 {
960                                 int new_size = b->yy_buf_size * 2;
961
962                                 if ( new_size <= 0 )
963                                         b->yy_buf_size += b->yy_buf_size / 8;
964                                 else
965                                         b->yy_buf_size *= 2;
966
967                                 b->yy_ch_buf = (char *)
968                                         /* Include room in for 2 EOB chars. */
969                                         yy_flex_realloc( (void *) b->yy_ch_buf,
970                                                          b->yy_buf_size + 2 );
971                                 }
972                         else
973                                 /* Can't grow it, we don't own it. */
974                                 b->yy_ch_buf = 0;
975
976                         if ( ! b->yy_ch_buf )
977                                 YY_FATAL_ERROR(
978                                 "fatal error - scanner input buffer overflow" );
979
980                         yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
981
982                         num_to_read = yy_current_buffer->yy_buf_size -
983                                                 number_to_move - 1;
984 #endif
985                         }
986
987                 if ( num_to_read > YY_READ_BUF_SIZE )
988                         num_to_read = YY_READ_BUF_SIZE;
989
990                 /* Read in more data. */
991                 YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
992                         yy_n_chars, num_to_read );
993
994                 yy_current_buffer->yy_n_chars = yy_n_chars;
995                 }
996
997         if ( yy_n_chars == 0 )
998                 {
999                 if ( number_to_move == YY_MORE_ADJ )
1000                         {
1001                         ret_val = EOB_ACT_END_OF_FILE;
1002                         yyrestart( yyin );
1003                         }
1004
1005                 else
1006                         {
1007                         ret_val = EOB_ACT_LAST_MATCH;
1008                         yy_current_buffer->yy_buffer_status =
1009                                 YY_BUFFER_EOF_PENDING;
1010                         }
1011                 }
1012
1013         else
1014                 ret_val = EOB_ACT_CONTINUE_SCAN;
1015
1016         yy_n_chars += number_to_move;
1017         yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1018         yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1019
1020         yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
1021
1022         return ret_val;
1023         }
1024
1025
1026 /* yy_get_previous_state - get the state just before the EOB char was reached */
1027
1028 static yy_state_type yy_get_previous_state()
1029         {
1030         register yy_state_type yy_current_state;
1031         register char *yy_cp;
1032
1033         yy_current_state = yy_start;
1034
1035         for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
1036                 {
1037                 register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1038                 if ( yy_accept[yy_current_state] )
1039                         {
1040                         yy_last_accepting_state = yy_current_state;
1041                         yy_last_accepting_cpos = yy_cp;
1042                         }
1043                 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1044                         {
1045                         yy_current_state = (int) yy_def[yy_current_state];
1046                         if ( yy_current_state >= 38 )
1047                                 yy_c = yy_meta[(unsigned int) yy_c];
1048                         }
1049                 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1050                 }
1051
1052         return yy_current_state;
1053         }
1054
1055
1056 /* yy_try_NUL_trans - try to make a transition on the NUL character
1057  *
1058  * synopsis
1059  *      next_state = yy_try_NUL_trans( current_state );
1060  */
1061
1062 #ifdef YY_USE_PROTOS
1063 static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
1064 #else
1065 static yy_state_type yy_try_NUL_trans( yy_current_state )
1066 yy_state_type yy_current_state;
1067 #endif
1068         {
1069         register int yy_is_jam;
1070         register char *yy_cp = yy_c_buf_p;
1071
1072         register YY_CHAR yy_c = 1;
1073         if ( yy_accept[yy_current_state] )
1074                 {
1075                 yy_last_accepting_state = yy_current_state;
1076                 yy_last_accepting_cpos = yy_cp;
1077                 }
1078         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1079                 {
1080                 yy_current_state = (int) yy_def[yy_current_state];
1081                 if ( yy_current_state >= 38 )
1082                         yy_c = yy_meta[(unsigned int) yy_c];
1083                 }
1084         yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1085         yy_is_jam = (yy_current_state == 37);
1086
1087         return yy_is_jam ? 0 : yy_current_state;
1088         }
1089
1090
1091 #ifndef YY_NO_UNPUT
1092 #ifdef YY_USE_PROTOS
1093 static void yyunput( int c, register char *yy_bp )
1094 #else
1095 static void yyunput( c, yy_bp )
1096 int c;
1097 register char *yy_bp;
1098 #endif
1099         {
1100         register char *yy_cp = yy_c_buf_p;
1101
1102         /* undo effects of setting up yytext */
1103         *yy_cp = yy_hold_char;
1104
1105         if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
1106                 { /* need to shift things up to make room */
1107                 /* +2 for EOB chars. */
1108                 register int number_to_move = yy_n_chars + 2;
1109                 register char *dest = &yy_current_buffer->yy_ch_buf[
1110                                         yy_current_buffer->yy_buf_size + 2];
1111                 register char *source =
1112                                 &yy_current_buffer->yy_ch_buf[number_to_move];
1113
1114                 while ( source > yy_current_buffer->yy_ch_buf )
1115                         *--dest = *--source;
1116
1117                 yy_cp += (int) (dest - source);
1118                 yy_bp += (int) (dest - source);
1119                 yy_current_buffer->yy_n_chars =
1120                         yy_n_chars = yy_current_buffer->yy_buf_size;
1121
1122                 if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
1123                         YY_FATAL_ERROR( "flex scanner push-back overflow" );
1124                 }
1125
1126         *--yy_cp = (char) c;
1127
1128
1129         yytext_ptr = yy_bp;
1130         yy_hold_char = *yy_cp;
1131         yy_c_buf_p = yy_cp;
1132         }
1133 #endif  /* ifndef YY_NO_UNPUT */
1134
1135
1136 #ifndef YY_NO_INPUT
1137 #ifdef __cplusplus
1138 static int yyinput()
1139 #else
1140 static int input()
1141 #endif
1142         {
1143         int c;
1144
1145         *yy_c_buf_p = yy_hold_char;
1146
1147         if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1148                 {
1149                 /* yy_c_buf_p now points to the character we want to return.
1150                  * If this occurs *before* the EOB characters, then it's a
1151                  * valid NUL; if not, then we've hit the end of the buffer.
1152                  */
1153                 if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
1154                         /* This was really a NUL. */
1155                         *yy_c_buf_p = '\0';
1156
1157                 else
1158                         { /* need more input */
1159                         int offset = yy_c_buf_p - yytext_ptr;
1160                         ++yy_c_buf_p;
1161
1162                         switch ( yy_get_next_buffer() )
1163                                 {
1164                                 case EOB_ACT_LAST_MATCH:
1165                                         /* This happens because yy_g_n_b()
1166                                          * sees that we've accumulated a
1167                                          * token and flags that we need to
1168                                          * try matching the token before
1169                                          * proceeding.  But for input(),
1170                                          * there's no matching to consider.
1171                                          * So convert the EOB_ACT_LAST_MATCH
1172                                          * to EOB_ACT_END_OF_FILE.
1173                                          */
1174
1175                                         /* Reset buffer status. */
1176                                         yyrestart( yyin );
1177
1178                                         /* fall through */
1179
1180                                 case EOB_ACT_END_OF_FILE:
1181                                         {
1182                                         if ( yywrap() )
1183                                                 return EOF;
1184
1185                                         if ( ! yy_did_buffer_switch_on_eof )
1186                                                 YY_NEW_FILE;
1187 #ifdef __cplusplus
1188                                         return yyinput();
1189 #else
1190                                         return input();
1191 #endif
1192                                         }
1193
1194                                 case EOB_ACT_CONTINUE_SCAN:
1195                                         yy_c_buf_p = yytext_ptr + offset;
1196                                         break;
1197                                 }
1198                         }
1199                 }
1200
1201         c = *(unsigned char *) yy_c_buf_p;      /* cast for 8-bit char's */
1202         *yy_c_buf_p = '\0';     /* preserve yytext */
1203         yy_hold_char = *++yy_c_buf_p;
1204
1205
1206         return c;
1207         }
1208 #endif /* YY_NO_INPUT */
1209
1210 #ifdef YY_USE_PROTOS
1211 void yyrestart( FILE *input_file )
1212 #else
1213 void yyrestart( input_file )
1214 FILE *input_file;
1215 #endif
1216         {
1217         if ( ! yy_current_buffer )
1218                 yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
1219
1220         yy_init_buffer( yy_current_buffer, input_file );
1221         yy_load_buffer_state();
1222         }
1223
1224
1225 #ifdef YY_USE_PROTOS
1226 void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
1227 #else
1228 void yy_switch_to_buffer( new_buffer )
1229 YY_BUFFER_STATE new_buffer;
1230 #endif
1231         {
1232         if ( yy_current_buffer == new_buffer )
1233                 return;
1234
1235         if ( yy_current_buffer )
1236                 {
1237                 /* Flush out information for old buffer. */
1238                 *yy_c_buf_p = yy_hold_char;
1239                 yy_current_buffer->yy_buf_pos = yy_c_buf_p;
1240                 yy_current_buffer->yy_n_chars = yy_n_chars;
1241                 }
1242
1243         yy_current_buffer = new_buffer;
1244         yy_load_buffer_state();
1245
1246         /* We don't actually know whether we did this switch during
1247          * EOF (yywrap()) processing, but the only time this flag
1248          * is looked at is after yywrap() is called, so it's safe
1249          * to go ahead and always set it.
1250          */
1251         yy_did_buffer_switch_on_eof = 1;
1252         }
1253
1254
1255 #ifdef YY_USE_PROTOS
1256 void yy_load_buffer_state( void )
1257 #else
1258 void yy_load_buffer_state()
1259 #endif
1260         {
1261         yy_n_chars = yy_current_buffer->yy_n_chars;
1262         yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
1263         yyin = yy_current_buffer->yy_input_file;
1264         yy_hold_char = *yy_c_buf_p;
1265         }
1266
1267
1268 #ifdef YY_USE_PROTOS
1269 YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
1270 #else
1271 YY_BUFFER_STATE yy_create_buffer( file, size )
1272 FILE *file;
1273 int size;
1274 #endif
1275         {
1276         YY_BUFFER_STATE b;
1277
1278         b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
1279         if ( ! b )
1280                 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1281
1282         b->yy_buf_size = size;
1283
1284         /* yy_ch_buf has to be 2 characters longer than the size given because
1285          * we need to put in 2 end-of-buffer characters.
1286          */
1287         b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
1288         if ( ! b->yy_ch_buf )
1289                 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1290
1291         b->yy_is_our_buffer = 1;
1292
1293         yy_init_buffer( b, file );
1294
1295         return b;
1296         }
1297
1298
1299 #ifdef YY_USE_PROTOS
1300 void yy_delete_buffer( YY_BUFFER_STATE b )
1301 #else
1302 void yy_delete_buffer( b )
1303 YY_BUFFER_STATE b;
1304 #endif
1305         {
1306         if ( ! b )
1307                 return;
1308
1309         if ( b == yy_current_buffer )
1310                 yy_current_buffer = (YY_BUFFER_STATE) 0;
1311
1312         if ( b->yy_is_our_buffer )
1313                 yy_flex_free( (void *) b->yy_ch_buf );
1314
1315         yy_flex_free( (void *) b );
1316         }
1317
1318
1319
1320 #ifdef YY_USE_PROTOS
1321 void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
1322 #else
1323 void yy_init_buffer( b, file )
1324 YY_BUFFER_STATE b;
1325 FILE *file;
1326 #endif
1327
1328
1329         {
1330         yy_flush_buffer( b );
1331
1332         b->yy_input_file = file;
1333         b->yy_fill_buffer = 1;
1334
1335 #if YY_ALWAYS_INTERACTIVE
1336         b->yy_is_interactive = 1;
1337 #else
1338 #if YY_NEVER_INTERACTIVE
1339         b->yy_is_interactive = 0;
1340 #else
1341         b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
1342 #endif
1343 #endif
1344         }
1345
1346
1347 #ifdef YY_USE_PROTOS
1348 void yy_flush_buffer( YY_BUFFER_STATE b )
1349 #else
1350 void yy_flush_buffer( b )
1351 YY_BUFFER_STATE b;
1352 #endif
1353
1354         {
1355         if ( ! b )
1356                 return;
1357
1358         b->yy_n_chars = 0;
1359
1360         /* We always need two end-of-buffer characters.  The first causes
1361          * a transition to the end-of-buffer state.  The second causes
1362          * a jam in that state.
1363          */
1364         b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1365         b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1366
1367         b->yy_buf_pos = &b->yy_ch_buf[0];
1368
1369         b->yy_at_bol = 1;
1370         b->yy_buffer_status = YY_BUFFER_NEW;
1371
1372         if ( b == yy_current_buffer )
1373                 yy_load_buffer_state();
1374         }
1375
1376
1377 #ifndef YY_NO_SCAN_BUFFER
1378 #ifdef YY_USE_PROTOS
1379 YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
1380 #else
1381 YY_BUFFER_STATE yy_scan_buffer( base, size )
1382 char *base;
1383 yy_size_t size;
1384 #endif
1385         {
1386         YY_BUFFER_STATE b;
1387
1388         if ( size < 2 ||
1389              base[size-2] != YY_END_OF_BUFFER_CHAR ||
1390              base[size-1] != YY_END_OF_BUFFER_CHAR )
1391                 /* They forgot to leave room for the EOB's. */
1392                 return 0;
1393
1394         b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
1395         if ( ! b )
1396                 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
1397
1398         b->yy_buf_size = size - 2;      /* "- 2" to take care of EOB's */
1399         b->yy_buf_pos = b->yy_ch_buf = base;
1400         b->yy_is_our_buffer = 0;
1401         b->yy_input_file = 0;
1402         b->yy_n_chars = b->yy_buf_size;
1403         b->yy_is_interactive = 0;
1404         b->yy_at_bol = 1;
1405         b->yy_fill_buffer = 0;
1406         b->yy_buffer_status = YY_BUFFER_NEW;
1407
1408         yy_switch_to_buffer( b );
1409
1410         return b;
1411         }
1412 #endif
1413
1414
1415 #ifndef YY_NO_SCAN_STRING
1416 #ifdef YY_USE_PROTOS
1417 YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
1418 #else
1419 YY_BUFFER_STATE yy_scan_string( yy_str )
1420 yyconst char *yy_str;
1421 #endif
1422         {
1423         int len;
1424         for ( len = 0; yy_str[len]; ++len )
1425                 ;
1426
1427         return yy_scan_bytes( yy_str, len );
1428         }
1429 #endif
1430
1431
1432 #ifndef YY_NO_SCAN_BYTES
1433 #ifdef YY_USE_PROTOS
1434 YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
1435 #else
1436 YY_BUFFER_STATE yy_scan_bytes( bytes, len )
1437 yyconst char *bytes;
1438 int len;
1439 #endif
1440         {
1441         YY_BUFFER_STATE b;
1442         char *buf;
1443         yy_size_t n;
1444         int i;
1445
1446         /* Get memory for full buffer, including space for trailing EOB's. */
1447         n = len + 2;
1448         buf = (char *) yy_flex_alloc( n );
1449         if ( ! buf )
1450                 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1451
1452         for ( i = 0; i < len; ++i )
1453                 buf[i] = bytes[i];
1454
1455         buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
1456
1457         b = yy_scan_buffer( buf, n );
1458         if ( ! b )
1459                 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
1460
1461         /* It's okay to grow etc. this buffer, and we should throw it
1462          * away when we're done.
1463          */
1464         b->yy_is_our_buffer = 1;
1465
1466         return b;
1467         }
1468 #endif
1469
1470
1471 #ifndef YY_NO_PUSH_STATE
1472 #ifdef YY_USE_PROTOS
1473 static void yy_push_state( int new_state )
1474 #else
1475 static void yy_push_state( new_state )
1476 int new_state;
1477 #endif
1478         {
1479         if ( yy_start_stack_ptr >= yy_start_stack_depth )
1480                 {
1481                 yy_size_t new_size;
1482
1483                 yy_start_stack_depth += YY_START_STACK_INCR;
1484                 new_size = yy_start_stack_depth * sizeof( int );
1485
1486                 if ( ! yy_start_stack )
1487                         yy_start_stack = (int *) yy_flex_alloc( new_size );
1488
1489                 else
1490                         yy_start_stack = (int *) yy_flex_realloc(
1491                                         (void *) yy_start_stack, new_size );
1492
1493                 if ( ! yy_start_stack )
1494                         YY_FATAL_ERROR(
1495                         "out of memory expanding start-condition stack" );
1496                 }
1497
1498         yy_start_stack[yy_start_stack_ptr++] = YY_START;
1499
1500         BEGIN(new_state);
1501         }
1502 #endif
1503
1504
1505 #ifndef YY_NO_POP_STATE
1506 static void yy_pop_state()
1507         {
1508         if ( --yy_start_stack_ptr < 0 )
1509                 YY_FATAL_ERROR( "start-condition stack underflow" );
1510
1511         BEGIN(yy_start_stack[yy_start_stack_ptr]);
1512         }
1513 #endif
1514
1515
1516 #ifndef YY_NO_TOP_STATE
1517 static int yy_top_state()
1518         {
1519         return yy_start_stack[yy_start_stack_ptr - 1];
1520         }
1521 #endif
1522
1523 #ifndef YY_EXIT_FAILURE
1524 #define YY_EXIT_FAILURE 2
1525 #endif
1526
1527 #ifdef YY_USE_PROTOS
1528 static void yy_fatal_error( yyconst char msg[] )
1529 #else
1530 static void yy_fatal_error( msg )
1531 char msg[];
1532 #endif
1533         {
1534         (void) fprintf( stderr, "%s\n", msg );
1535         exit( YY_EXIT_FAILURE );
1536         }
1537
1538
1539
1540 /* Redefine yyless() so it works in section 3 code. */
1541
1542 #undef yyless
1543 #define yyless(n) \
1544         do \
1545                 { \
1546                 /* Undo effects of setting up yytext. */ \
1547                 yytext[yyleng] = yy_hold_char; \
1548                 yy_c_buf_p = yytext + n; \
1549                 yy_hold_char = *yy_c_buf_p; \
1550                 *yy_c_buf_p = '\0'; \
1551                 yyleng = n; \
1552                 } \
1553         while ( 0 )
1554
1555
1556 /* Internal utility routines. */
1557
1558 #ifndef yytext_ptr
1559 #ifdef YY_USE_PROTOS
1560 static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
1561 #else
1562 static void yy_flex_strncpy( s1, s2, n )
1563 char *s1;
1564 yyconst char *s2;
1565 int n;
1566 #endif
1567         {
1568         register int i;
1569         for ( i = 0; i < n; ++i )
1570                 s1[i] = s2[i];
1571         }
1572 #endif
1573
1574 #ifdef YY_NEED_STRLEN
1575 #ifdef YY_USE_PROTOS
1576 static int yy_flex_strlen( yyconst char *s )
1577 #else
1578 static int yy_flex_strlen( s )
1579 yyconst char *s;
1580 #endif
1581         {
1582         register int n;
1583         for ( n = 0; s[n]; ++n )
1584                 ;
1585
1586         return n;
1587         }
1588 #endif
1589
1590
1591 #ifdef YY_USE_PROTOS
1592 static void *yy_flex_alloc( yy_size_t size )
1593 #else
1594 static void *yy_flex_alloc( size )
1595 yy_size_t size;
1596 #endif
1597         {
1598         return (void *) malloc( size );
1599         }
1600
1601 #ifdef YY_USE_PROTOS
1602 static void *yy_flex_realloc( void *ptr, yy_size_t size )
1603 #else
1604 static void *yy_flex_realloc( ptr, size )
1605 void *ptr;
1606 yy_size_t size;
1607 #endif
1608         {
1609         /* The cast to (char *) in the following accommodates both
1610          * implementations that use char* generic pointers, and those
1611          * that use void* generic pointers.  It works with the latter
1612          * because both ANSI C and C++ allow castless assignment from
1613          * any pointer type to void*, and deal with argument conversions
1614          * as though doing an assignment.
1615          */
1616         return (void *) realloc( (char *) ptr, size );
1617         }
1618
1619 #ifdef YY_USE_PROTOS
1620 static void yy_flex_free( void *ptr )
1621 #else
1622 static void yy_flex_free( ptr )
1623 void *ptr;
1624 #endif
1625         {
1626         free( ptr );
1627         }
1628
1629 #if YY_MAIN
1630 int main()
1631         {
1632         yylex();
1633         return 0;
1634         }
1635 #endif
1636 #line 99 "pool_config.l"
1637
1638
1639 int pool_init_config(void)
1640 {
1641         int res;
1642         static char localhostname[256];
1643         int i;
1644
1645         pool_config = malloc(sizeof(POOL_CONFIG));
1646         if (pool_config == NULL)
1647         {
1648                 pool_error("failed to allocate pool_config");
1649                 return(-1);
1650         }
1651
1652         memset(pool_config, 0, sizeof(POOL_CONFIG));
1653
1654         pool_config->backend_desc = pool_shared_memory_create(sizeof(BackendDesc));
1655         if (pool_config->backend_desc == NULL)
1656         {
1657                 pool_error("failed to allocate pool_config->backend_desc");
1658                 return -1;
1659         }
1660
1661         /* set hardcoded default values */
1662         pool_config->listen_addresses = "localhost";
1663         pool_config->port = 9999;
1664         pool_config->pcp_port = 9898;
1665         pool_config->socket_dir = DEFAULT_SOCKET_DIR;
1666         pool_config->pcp_socket_dir = DEFAULT_SOCKET_DIR;
1667         pool_config->backend_socket_dir = DEFAULT_SOCKET_DIR;
1668         pool_config->pcp_timeout = 10;
1669         pool_config->num_init_children = 32;
1670         pool_config->max_pool = 4;
1671         pool_config->child_life_time = 300;
1672         pool_config->client_idle_limit = 0;
1673         pool_config->connection_life_time = 0;
1674         pool_config->child_max_connections = 0;
1675         pool_config->authentication_timeout = 60;
1676         pool_config->logdir = DEFAULT_LOGDIR;
1677         pool_config->pid_file_name = DEFAULT_PID_FILE_NAME;
1678         pool_config->log_statement = 0;
1679         pool_config->log_connections = 0;
1680         pool_config->log_hostname = 0;
1681         pool_config->enable_pool_hba = 0;
1682
1683         pool_config->replication_mode = 0;
1684         pool_config->load_balance_mode = 0;
1685         pool_config->replication_stop_on_mismatch = 0;
1686         pool_config->replicate_select = 0;
1687         pool_config->reset_query_list = default_reset_query_list;
1688         pool_config->num_reset_queries = sizeof(default_reset_query_list)/sizeof(char *);
1689         pool_config->reset_query_list = default_reset_query_list;
1690         pool_config->print_timestamp = 1;
1691         pool_config->master_slave_mode = 0;
1692         pool_config->connection_cache = 1;
1693         pool_config->health_check_timeout = 20;
1694         pool_config->health_check_period = 0;
1695         pool_config->health_check_user = "nobody";
1696         pool_config->failover_command = "";
1697         pool_config->failback_command = "";
1698         pool_config->insert_lock = 1;
1699         pool_config->ignore_leading_white_space = 1;
1700         pool_config->parallel_mode = 0;
1701         pool_config->enable_query_cache = 0;
1702         pool_config->system_db_hostname = "localhost";
1703         pool_config->system_db_port = 5432;
1704         pool_config->system_db_dbname = "pgpool";
1705         pool_config->system_db_schema = "pgpool_catalog";
1706         pool_config->system_db_user = "pgpool";
1707         pool_config->system_db_password = "";
1708         pool_config->backend_desc->num_backends = 0;
1709     pool_config->recovery_user = "";
1710     pool_config->recovery_password = "";
1711     pool_config->recovery_1st_stage_command = "";
1712     pool_config->recovery_2nd_stage_command = "";
1713         pool_config->recovery_timeout = 90;
1714         pool_config->client_idle_limit_in_recovery = 0;
1715
1716         res = gethostname(localhostname,sizeof(localhostname));
1717         if(res !=0 )
1718         {
1719                 pool_debug("faild to get this hostname");
1720         }
1721         pool_config->pgpool2_hostname = localhostname;
1722
1723         for (i=0;i<MAX_CONNECTION_SLOTS;i++)
1724         {
1725                 clear_host_entry(i);
1726         }
1727         return 0;
1728 }
1729
1730 int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
1731 {
1732         FILE *fd;
1733         int token;
1734         char key[1024];
1735         double total_weight;
1736         int i;
1737
1738 #define PARSE_ERROR()           pool_error("pool_config: parse error at line %d '%s'", Lineno, yytext)
1739
1740         /* open config file */
1741         fd = fopen(confpath, "r");
1742         if (!fd)
1743         {
1744                 fprintf(stderr, "pool_config: could not open configuration file (%s)\n",
1745                                 POOL_CONF_FILE_NAME);
1746                 fprintf(stderr, "pool_config: using default values...\n");
1747                 return 0;
1748         }
1749
1750         yyin = fd;
1751         Lineno = 1;
1752
1753         while ((token = yylex()))
1754         {
1755                 if (token == POOL_PARSE_ERROR)
1756                 {
1757                         PARSE_ERROR();
1758                         fclose(fd);
1759                         return(-1);
1760                 }
1761                 if (token == POOL_EOL)
1762                         continue;
1763
1764                 if (token != POOL_KEY)
1765                 {
1766                         PARSE_ERROR();
1767                         fclose(fd);
1768                         return(-1);
1769                 }
1770
1771                 strncpy(key, yytext, sizeof(key));
1772
1773                 pool_debug("key: %s", key);
1774
1775                 token = yylex();
1776
1777                 if (token == POOL_EQUALS)
1778                         token = yylex();
1779
1780                 pool_debug("value: %s kind: %d", yytext, token);
1781
1782                 if (!strcmp(key, "allow_inet_domain_socket") && CHECK_CONTEXT(INIT_CONFIG, context))
1783                 {
1784                         /* for backward compatibility */
1785                         int v = eval_logical(yytext);
1786
1787                         if (v < 0)
1788                         {
1789                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
1790                                 fclose(fd);
1791                                 return(-1);
1792                         }
1793                         if (v)
1794                                 pool_config->listen_addresses = strdup("*");
1795                         else
1796                                 pool_config->listen_addresses = strdup("");
1797                 }
1798                 else if (!strcmp(key, "listen_addresses") && CHECK_CONTEXT(INIT_CONFIG, context))
1799                 {
1800                         char *str;
1801
1802                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
1803                         {
1804                                 PARSE_ERROR();
1805                                 fclose(fd);
1806                                 return(-1);
1807                         }
1808                         str = extract_string(yytext, token);
1809                         if (str == NULL)
1810                         {
1811                                 fclose(fd);
1812                                 return(-1);
1813                         }
1814                         pool_config->listen_addresses = str;
1815                 }
1816
1817                 else if (!strcmp(key, "port") && CHECK_CONTEXT(INIT_CONFIG, context))
1818                 {
1819                         int v = atoi(yytext);
1820
1821                         if (token != POOL_INTEGER || v < 1024)
1822                         {
1823                                 pool_error("pool_config: %s must be 1024 or higher numeric value", key);
1824                                 fclose(fd);
1825                                 return(-1);
1826                         }
1827                         pool_config->port = v;
1828                 }
1829                 else if (!strcmp(key, "pcp_port") && CHECK_CONTEXT(INIT_CONFIG, context))
1830                 {
1831                         int v = atoi(yytext);
1832
1833                         if (token != POOL_INTEGER || v < 1024)
1834                         {
1835                                 pool_error("pool_config: %s must be 1024 or higher numeric value", key);
1836                                 fclose(fd);
1837                                 return(-1);
1838                         }
1839                         pool_config->pcp_port = v;
1840                 }
1841                 else if (!strcmp(key, "socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
1842                 {
1843                         char *str;
1844
1845                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
1846                         {
1847                                 PARSE_ERROR();
1848                                 fclose(fd);
1849                                 return(-1);
1850                         }
1851                         str = extract_string(yytext, token);
1852                         if (str == NULL)
1853                         {
1854                                 fclose(fd);
1855                                 return(-1);
1856                         }
1857                         pool_config->socket_dir = str;
1858                 }
1859                 else if (!strcmp(key, "pcp_socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
1860                 {
1861                         char *str;
1862
1863                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
1864                         {
1865                                 PARSE_ERROR();
1866                                 fclose(fd);
1867                                 return(-1);
1868                         }
1869                         str = extract_string(yytext, token);
1870                         if (str == NULL)
1871                         {
1872                                 fclose(fd);
1873                                 return(-1);
1874                         }
1875                         pool_config->pcp_socket_dir = str;
1876                 }
1877                 else if (!strcmp(key, "pcp_timeout") &&
1878                          CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
1879                 {
1880                         int v = atoi(yytext);
1881
1882                         if (token != POOL_INTEGER || v < 0)
1883                         {
1884                                 pool_error("pool_config: %s must be equal or greater or equal to 0 numeric value", key);
1885                                 fclose(fd);
1886                                 return(-1);
1887                         }
1888                         pool_config->pcp_timeout = v;
1889                 }
1890                 else if (!strcmp(key, "num_init_children") && CHECK_CONTEXT(INIT_CONFIG, context))
1891                 {
1892                         int v = atoi(yytext);
1893
1894                         if (token != POOL_INTEGER || v < 1)
1895                         {
1896                                 pool_error("pool_config: %s must be higher than 1 numeric value", key);
1897                                 fclose(fd);
1898                                 return(-1);
1899                         }
1900                         pool_config->num_init_children = v;
1901                 }
1902                 else if (!strcmp(key, "child_life_time") &&
1903                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
1904                 {
1905                         int v = atoi(yytext);
1906
1907                         if (token != POOL_INTEGER || v < 0)
1908                         {
1909                                 pool_error("pool_config: %s must be greater or equal to 0 numeric value", key);
1910                                 fclose(fd);
1911                                 return(-1);
1912                         }
1913                         pool_config->child_life_time = v;
1914                 }
1915                 else if (!strcmp(key, "client_idle_limit") &&
1916                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
1917                 {
1918                         int v = atoi(yytext);
1919
1920                         if (token != POOL_INTEGER || v < 0)
1921                         {
1922                                 pool_error("pool_config: %s must be greater or equal to 0 numeric value", key);
1923                                 fclose(fd);
1924                                 return(-1);
1925                         }
1926                         pool_config->client_idle_limit = v;
1927                 }
1928                 else if (!strcmp(key, "connection_life_time") &&
1929                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
1930                 {
1931                         int v = atoi(yytext);
1932
1933                         if (token != POOL_INTEGER || v < 0)
1934                         {
1935                                 pool_error("pool_config: %s must be greater or equal to 0 numeric value", key);
1936                                 fclose(fd);
1937                                 return(-1);
1938                         }
1939                         pool_config->connection_life_time = v;
1940                 }
1941                 else if (!strcmp(key, "child_max_connections") &&
1942                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
1943                 {
1944                         int v = atoi(yytext);
1945
1946                         if (token != POOL_INTEGER || v < 0)
1947                         {
1948                                 pool_error("pool_config: %s must be greater or equal to 0 numeric value", key);
1949                                 fclose(fd);
1950                                 return(-1);
1951                         }
1952                         pool_config->child_max_connections = v;
1953                 }
1954                 else if (!strcmp(key, "authentication_timeout") &&
1955                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
1956                 {
1957                         int v = atoi(yytext);
1958
1959                         if (token != POOL_INTEGER || v < 0)
1960                         {
1961                                 pool_error("pool_config: %s must be higher than 0 numeric value", key);
1962                                 fclose(fd);
1963                                 return(-1);
1964                         }
1965                         pool_config->authentication_timeout = v;
1966                 }
1967                 else if (!strcmp(key, "max_pool") && CHECK_CONTEXT(INIT_CONFIG, context))
1968                 {
1969                         int v = atoi(yytext);
1970
1971                         if (token != POOL_INTEGER || v < 0)
1972                         {
1973                                 pool_error("pool_config: %s must be greater or equal to 0 numeric value", key);
1974                                 fclose(fd);
1975                                 return(-1);
1976                         }
1977                         pool_config->max_pool = v;
1978                 }
1979                 else if (!strcmp(key, "logdir") && CHECK_CONTEXT(INIT_CONFIG, context))
1980                 {
1981                         char *str;
1982
1983                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
1984                         {
1985                                 PARSE_ERROR();
1986                                 fclose(fd);
1987                                 return(-1);
1988                         }
1989                         str = extract_string(yytext, token);
1990                         if (str == NULL)
1991                         {
1992                                 fclose(fd);
1993                                 return(-1);
1994                         }
1995                         pool_config->logdir = str;
1996                 }
1997                 else if (!strcmp(key, "pid_file_name") && CHECK_CONTEXT(INIT_CONFIG, context))
1998                 {
1999                         char *str;
2000
2001                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2002                         {
2003                                 PARSE_ERROR();
2004                                 fclose(fd);
2005                                 return(-1);
2006                         }
2007                         str = extract_string(yytext, token);
2008                         if (str == NULL)
2009                         {
2010                                 fclose(fd);
2011                                 return(-1);
2012                         }
2013                         pool_config->pid_file_name = str;
2014                 }
2015         else if (!strcmp(key, "log_connections") &&
2016                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2017                 {
2018                         int v = eval_logical(yytext);
2019
2020                         if (v < 0)
2021                         {
2022                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2023                                 fclose(fd);
2024                                 return(-1);
2025                         }
2026                         pool_config->log_connections = v;
2027                 }
2028         else if (!strcmp(key, "log_hostname") &&
2029                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2030                 {
2031                         int v = eval_logical(yytext);
2032
2033                         if (v < 0)
2034                         {
2035                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2036                                 fclose(fd);
2037                                 return(-1);
2038                         }
2039                         pool_config->log_hostname = v;
2040                 }
2041         else if (!strcmp(key, "enable_pool_hba") &&
2042                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2043                 {
2044                         int v = eval_logical(yytext);
2045
2046                         if (v < 0)
2047                         {
2048                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2049                                 fclose(fd);
2050                                 return(-1);
2051                         }
2052                         pool_config->enable_pool_hba = v;
2053                 }
2054                 else if (!strcmp(key, "backend_socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
2055                 {
2056                         char *str;
2057
2058                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2059                         {
2060                                 PARSE_ERROR();
2061                                 fclose(fd);
2062                                 return(-1);
2063                         }
2064                         str = extract_string(yytext, token);
2065                         if (str == NULL)
2066                         {
2067                                 fclose(fd);
2068                                 return(-1);
2069                         }
2070                         pool_config->backend_socket_dir = str;
2071                 }
2072                 else if (!strcmp(key, "replication_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
2073                 {
2074                         int v = eval_logical(yytext);
2075
2076                         if (v < 0)
2077                         {
2078                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2079                                 fclose(fd);
2080                                 return(-1);
2081                         }
2082                         pool_config->replication_mode = pool_config->replication_enabled = v;
2083
2084                         if (pool_config->master_slave_enabled && pool_config->replication_enabled)
2085                         {
2086                                 pool_error("pool_config: replication_mode and master_slave_mode cannot be enabled at the same time");
2087                                 fclose(fd);
2088                                 return(-1);
2089                         }
2090
2091                 }
2092                 else if (!strcmp(key, "load_balance_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
2093                 {
2094                         int v = eval_logical(yytext);
2095
2096                         if (v < 0)
2097                         {
2098                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2099                                 fclose(fd);
2100                                 return(-1);
2101                         }
2102                         pool_config->load_balance_mode = v;
2103                 }
2104                 else if (!strcmp(key, "replication_stop_on_mismatch") &&
2105                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2106                 {
2107                         int v = eval_logical(yytext);
2108
2109                         if (v < 0)
2110                         {
2111                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2112                                 fclose(fd);
2113                                 return(-1);
2114                         }
2115                         pool_debug("replication_stop_on_mismatch: %d", v);
2116                         pool_config->replication_stop_on_mismatch = v;
2117                 }
2118                 else if (!strcmp(key, "replicate_select") &&
2119                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2120                 {
2121                         int v = eval_logical(yytext);
2122
2123                         if (v < 0)
2124                         {
2125                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2126                                 fclose(fd);
2127                                 return(-1);
2128                         }
2129                         pool_debug("replicate_select: %d", v);
2130                         pool_config->replicate_select = v;
2131                 }
2132                 else if (!strcmp(key, "reset_query_list") &&
2133                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2134                 {
2135                         char *str;
2136
2137                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2138                         {
2139                                 PARSE_ERROR();
2140                                 fclose(fd);
2141                                 return(-1);
2142                         }
2143                         str = extract_string(yytext, token);
2144                         if (str == NULL)
2145                         {
2146                                 fclose(fd);
2147                                 return(-1);
2148                         }
2149                         pool_config->reset_query_list = extract_string_tokens(str, ";", &pool_config->num_reset_queries);
2150                         if (pool_config->reset_query_list == NULL)
2151                         {
2152                                 fclose(fd);
2153                                 return(-1);
2154                         }
2155                 }
2156
2157                 else if (!strcmp(key, "print_timestamp") && CHECK_CONTEXT(INIT_CONFIG, context))
2158                 {
2159                         int v = eval_logical(yytext);
2160
2161                         if (v < 0)
2162                         {
2163                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2164                                 fclose(fd);
2165                                 return(-1);
2166                         }
2167                         pool_config->print_timestamp = v;
2168                 }
2169
2170                 else if (!strcmp(key, "master_slave_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
2171                 {
2172                         int v = eval_logical(yytext);
2173
2174                         if (v < 0)
2175                         {
2176                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2177                                 fclose(fd);
2178                                 return(-1);
2179                         }
2180                         pool_config->master_slave_mode = pool_config->master_slave_enabled = v;
2181
2182                         if (pool_config->master_slave_enabled && pool_config->replication_enabled)
2183                         {
2184                                 pool_error("pool_config: replication_mode and master_slave_mode cannot be enabled at the same time");
2185                                 fclose(fd);
2186                                 return(-1);
2187                         }
2188                 }
2189
2190                 else if (!strcmp(key, "connection_cache") && CHECK_CONTEXT(INIT_CONFIG, context))
2191                 {
2192                         int v = eval_logical(yytext);
2193
2194                         if (v < 0)
2195                         {
2196                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2197                                 fclose(fd);
2198                                 return(-1);
2199                         }
2200                         pool_config->connection_cache = v;
2201                 }
2202
2203                 else if (!strcmp(key, "health_check_timeout") &&
2204                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2205                 {
2206                         int v = atoi(yytext);
2207
2208                         if (token != POOL_INTEGER || v < 0)
2209                         {
2210                                 pool_error("pool_config: %s must be equal or higher than 0 numeric value", key);
2211                                 fclose(fd);
2212                                 return(-1);
2213                         }
2214                         pool_config->health_check_timeout = v;
2215                 }
2216
2217                 else if (!strcmp(key, "health_check_period") &&
2218                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2219                 {
2220                         int v = atoi(yytext);
2221
2222                         if (token != POOL_INTEGER || v < 0)
2223                         {
2224                                 pool_error("pool_config: %s must be equal or higher than 0 numeric value", key);
2225                                 fclose(fd);
2226                                 return(-1);
2227                         }
2228                         pool_config->health_check_period = v;
2229                 }
2230
2231                 else if (!strcmp(key, "health_check_user") &&
2232                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2233                 {
2234                         char *str;
2235
2236                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2237                         {
2238                                 PARSE_ERROR();
2239                                 fclose(fd);
2240                                 return(-1);
2241                         }
2242                         str = extract_string(yytext, token);
2243                         if (str == NULL)
2244                         {
2245                                 fclose(fd);
2246                                 return(-1);
2247                         }
2248                         pool_config->health_check_user = str;
2249                 }
2250
2251                 else if (!strcmp(key, "failover_command") &&
2252                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2253                 {
2254                         char *str;
2255
2256                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2257                         {
2258                                 PARSE_ERROR();
2259                                 fclose(fd);
2260                                 return(-1);
2261                         }
2262                         str = extract_string(yytext, token);
2263                         if (str == NULL)
2264                         {
2265                                 fclose(fd);
2266                                 return(-1);
2267                         }
2268                         pool_config->failover_command = str;
2269                 }
2270
2271                 else if (!strcmp(key, "failback_command") &&
2272                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2273                 {
2274                         char *str;
2275
2276                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2277                         {
2278                                 PARSE_ERROR();
2279                                 fclose(fd);
2280                                 return(-1);
2281                         }
2282                         str = extract_string(yytext, token);
2283                         if (str == NULL)
2284                         {
2285                                 fclose(fd);
2286                                 return(-1);
2287                         }
2288                         pool_config->failback_command = str;
2289                 }
2290
2291                 else if (!strcmp(key, "recovery_user") &&
2292                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2293                 {
2294                         char *str;
2295
2296                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2297                         {
2298                                 PARSE_ERROR();
2299                                 fclose(fd);
2300                                 return(-1);
2301                         }
2302                         str = extract_string(yytext, token);
2303                         if (str == NULL)
2304                         {
2305                                 fclose(fd);
2306                                 return(-1);
2307                         }
2308                         pool_config->recovery_user = str;
2309                 }
2310
2311                 else if (!strcmp(key, "recovery_password") &&
2312                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2313                 {
2314                         char *str;
2315
2316                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2317                         {
2318                                 PARSE_ERROR();
2319                                 fclose(fd);
2320                                 return(-1);
2321                         }
2322                         str = extract_string(yytext, token);
2323                         if (str == NULL)
2324                         {
2325                                 fclose(fd);
2326                                 return(-1);
2327                         }
2328                         pool_config->recovery_password = str;
2329                 }
2330
2331                 else if (!strcmp(key, "recovery_1st_stage_command") &&
2332                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2333                 {
2334                         char *str;
2335
2336                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2337                         {
2338                                 PARSE_ERROR();
2339                                 fclose(fd);
2340                                 return(-1);
2341                         }
2342                         str = extract_string(yytext, token);
2343                         if (str == NULL)
2344                         {
2345                                 fclose(fd);
2346                                 return(-1);
2347                         }
2348                         pool_config->recovery_1st_stage_command = str;
2349                 }
2350
2351                 else if (!strcmp(key, "recovery_2nd_stage_command") &&
2352                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2353                 {
2354                         char *str;
2355
2356                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2357                         {
2358                                 PARSE_ERROR();
2359                                 fclose(fd);
2360                                 return(-1);
2361                         }
2362                         str = extract_string(yytext, token);
2363                         if (str == NULL)
2364                         {
2365                                 fclose(fd);
2366                                 return(-1);
2367                         }
2368                         pool_config->recovery_2nd_stage_command = str;
2369                 }
2370
2371                 else if (!strcmp(key, "recovery_timeout") &&
2372                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2373                 {
2374                         int v = atoi(yytext);
2375
2376                         if (token != POOL_INTEGER || v < 0)
2377                         {
2378                                 pool_error("pool_config: %s must be equal or higher than 0 numeric value", key);
2379                                 fclose(fd);
2380                                 return(-1);
2381                         }
2382                         pool_config->recovery_timeout = v;
2383                 }
2384
2385                 else if (!strcmp(key, "client_idle_limit_in_recovery") &&
2386                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2387                 {
2388                         int v = atoi(yytext);
2389
2390                         if (token != POOL_INTEGER || v < 0)
2391                         {
2392                                 pool_error("pool_config: %s must be greater or equal to 0 numeric value", key);
2393                                 fclose(fd);
2394                                 return(-1);
2395                         }
2396                         pool_config->client_idle_limit_in_recovery = v;
2397                 }
2398
2399                 else if (!strcmp(key, "insert_lock") &&
2400                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2401                 {
2402                         int v = eval_logical(yytext);
2403
2404                         if (v < 0)
2405                         {
2406                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2407                                 fclose(fd);
2408                                 return(-1);
2409                         }
2410                         pool_config->insert_lock = v;
2411                 }
2412
2413                 else if (!strcmp(key, "ignore_leading_white_space") &&
2414                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2415                 {
2416                         int v = eval_logical(yytext);
2417
2418                         if (v < 0)
2419                         {
2420                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2421                                 fclose(fd);
2422                                 return(-1);
2423                         }
2424                         pool_config->ignore_leading_white_space = v;
2425                 }
2426
2427                 else if (!strcmp(key, "parallel_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
2428                 {
2429                         int v = eval_logical(yytext);
2430
2431                         if (v < 0)
2432                         {
2433                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2434                                 fclose(fd);
2435                                 return(-1);
2436                         }
2437                         pool_config->parallel_mode = v;
2438                 }
2439
2440                 else if (!strcmp(key, "enable_query_cache") && CHECK_CONTEXT(INIT_CONFIG, context))
2441                 {
2442                         int v = eval_logical(yytext);
2443
2444                         if (v < 0)
2445                         {
2446                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2447                                 fclose(fd);
2448                                 return(-1);
2449                         }
2450                         pool_config->enable_query_cache = v;
2451                 }
2452
2453                 else if (!strcmp(key, "pgpool2_hostname") && CHECK_CONTEXT(INIT_CONFIG, context))
2454                 {
2455                         char *str;
2456
2457                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2458                         {
2459                                 PARSE_ERROR();
2460                                 fclose(fd);
2461                                 return(-1);
2462                         }
2463                         str = extract_string(yytext, token);
2464                         if (str == NULL)
2465                         {
2466                                 fclose(fd);
2467                                 return(-1);
2468                         }
2469                         if(strlen(str))
2470                                 pool_config->pgpool2_hostname = str;
2471                 }
2472
2473                 else if (!strcmp(key, "system_db_hostname") && CHECK_CONTEXT(INIT_CONFIG, context))
2474                 {
2475                         char *str;
2476
2477                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2478                         {
2479                                 PARSE_ERROR();
2480                                 fclose(fd);
2481                                 return(-1);
2482                         }
2483                         str = extract_string(yytext, token);
2484                         if (str == NULL)
2485                         {
2486                                 fclose(fd);
2487                                 return(-1);
2488                         }
2489                         pool_config->system_db_hostname = str;
2490                 }
2491
2492                 else if (!strcmp(key, "system_db_port") && CHECK_CONTEXT(INIT_CONFIG, context))
2493                 {
2494                         int v = atoi(yytext);
2495
2496                         if (token != POOL_INTEGER || v < 0)
2497                         {
2498                                 pool_error("pool_config: %s must be equal or higher than 0 numeric value", key);
2499                                 fclose(fd);
2500                                 return(-1);
2501                         }
2502                         pool_config->system_db_port = v;
2503                 }
2504
2505                 else if (!strcmp(key, "system_db_dbname") && CHECK_CONTEXT(INIT_CONFIG, context))
2506                 {
2507                         char *str;
2508
2509                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2510                         {
2511                                 PARSE_ERROR();
2512                                 fclose(fd);
2513                                 return(-1);
2514                         }
2515                         str = extract_string(yytext, token);
2516                         if (str == NULL)
2517                         {
2518                                 fclose(fd);
2519                                 return(-1);
2520                         }
2521                         pool_config->system_db_dbname = str;
2522                 }
2523
2524                 else if (!strcmp(key, "system_db_schema") && CHECK_CONTEXT(INIT_CONFIG, context))
2525                 {
2526                         char *str;
2527
2528                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2529                         {
2530                                 PARSE_ERROR();
2531                                 fclose(fd);
2532                                 return(-1);
2533                         }
2534                         str = extract_string(yytext, token);
2535                         if (str == NULL)
2536                         {
2537                                 fclose(fd);
2538                                 return(-1);
2539                         }
2540                         pool_config->system_db_schema = str;
2541                 }
2542
2543                 else if (!strcmp(key, "system_db_user") && CHECK_CONTEXT(INIT_CONFIG, context))
2544                 {
2545                         char *str;
2546
2547                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2548                         {
2549                                 PARSE_ERROR();
2550                                 fclose(fd);
2551                                 return(-1);
2552                         }
2553                         str = extract_string(yytext, token);
2554                         if (str == NULL)
2555                         {
2556                                 fclose(fd);
2557                                 return(-1);
2558                         }
2559                         pool_config->system_db_user = str;
2560                 }
2561
2562                 else if (!strcmp(key, "system_db_password") && CHECK_CONTEXT(INIT_CONFIG, context))
2563                 {
2564                         char *str;
2565
2566                         if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
2567                         {
2568                                 PARSE_ERROR();
2569                                 fclose(fd);
2570                                 return(-1);
2571                         }
2572                         str = extract_string(yytext, token);
2573                         if (str == NULL)
2574                         {
2575                                 fclose(fd);
2576                                 return(-1);
2577                         }
2578                         pool_config->system_db_password = str;
2579                 }
2580
2581                 else if (!strncmp(key, "backend_hostname", 16) &&
2582                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
2583                                  mypid == getpid()) /* this parameter must be modified by parent pid */
2584                 {
2585                         int slot;
2586                         char *str;
2587
2588                         slot = atoi(key + 16);
2589                         if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
2590                         {
2591                                 pool_error("pool_config: backend number %s for backend_hostname out of range", key);
2592                                 fclose(fd);
2593                                 return(-1);
2594                         }
2595
2596                         str = extract_string(yytext, token);
2597                         if (str == NULL)
2598                         {
2599                                 fclose(fd);
2600                                 return(-1);
2601                         }
2602                         if (context == INIT_CONFIG ||
2603                                 (context == RELOAD_CONFIG && BACKEND_INFO(slot).backend_status == CON_UNUSED))
2604                                 strncpy(BACKEND_INFO(slot).backend_hostname, str, MAX_DB_HOST_NAMELEN);
2605                 }
2606
2607                 else if (!strncmp(key, "backend_port", 12) &&
2608                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
2609                                  mypid == getpid()) /* this parameter must be modified by parent pid */
2610                 {
2611                         int slot;
2612
2613                         slot = atoi(key + 12);
2614                         if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
2615                         {
2616                                 pool_error("pool_config: host number %s for port number out of range", key);
2617                                 fclose(fd);
2618                                 return(-1);
2619                         }
2620                         pool_debug("pool_config: port slot number %d ", slot);
2621                         if (context == INIT_CONFIG)
2622                         {
2623                                 BACKEND_INFO(slot).backend_port = atoi(yytext);
2624                                 BACKEND_INFO(slot).backend_status = CON_CONNECT_WAIT;
2625                         }
2626                         else if (context == RELOAD_CONFIG && BACKEND_INFO(slot).backend_status == CON_UNUSED)
2627                         {
2628                                 BACKEND_INFO(slot).backend_port = atoi(yytext);
2629                                 BACKEND_INFO(slot).backend_status = CON_DOWN;
2630                         }
2631                 }
2632
2633                 else if (!strncmp(key, "backend_weight", 14) &&
2634                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
2635                                  mypid == getpid()) /* this parameter must be modified by parent pid */
2636                 {
2637                         int slot;
2638                         double v;
2639                         BACKEND_STATUS status;
2640
2641                         slot = atoi(key + 14);
2642                         if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
2643                         {
2644                                 pool_error("pool_config: weight number %s for port number out of range", key);
2645                                 fclose(fd);
2646                                 return(-1);
2647                         }
2648
2649                         v = atof(yytext);
2650
2651                         if (v < 0.0)
2652                         {
2653                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2654                                 fclose(fd);
2655                                 return(-1);
2656                         }
2657
2658                         pool_debug("pool_config: weight slot number %d weight: %f", slot, v);
2659                         status = BACKEND_INFO(slot).backend_status;
2660                         if (context == INIT_CONFIG ||
2661                                 (context == RELOAD_CONFIG && (context == RELOAD_CONFIG && (status == CON_UNUSED || status == CON_DOWN))))
2662                         {
2663                                 pool_config->backend_desc->backend_info[slot].unnormalized_weight = v;
2664                         }
2665                 }
2666                 else if (!strncmp(key, "backend_data_directory", 22) &&
2667                                  CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
2668                                  mypid == getpid()) /* this parameter must be modified by parent pid */
2669                 {
2670                         int slot;
2671                         char *str;
2672                         BACKEND_STATUS status;
2673
2674                         slot = atoi(key + 22);
2675                         if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
2676                         {
2677                                 pool_error("pool_config: backend number %s for backend_data_directory out of range", key);
2678                                 fclose(fd);
2679                                 return(-1);
2680                         }
2681
2682                         str = extract_string(yytext, token);
2683                         if (str == NULL)
2684                         {
2685                                 fclose(fd);
2686                                 return(-1);
2687                         }
2688                         status = BACKEND_INFO(slot).backend_status;
2689                         if (context == INIT_CONFIG ||
2690                                 (context == RELOAD_CONFIG && (status == CON_UNUSED || status == CON_DOWN)))
2691                                 strncpy(BACKEND_INFO(slot).backend_data_directory, str, MAX_PATH_LENGTH);
2692                 }
2693         else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2694                 {
2695                         int v = eval_logical(yytext);
2696
2697                         if (v < 0)
2698                         {
2699                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2700                                 return(-1);
2701                         }
2702                         pool_config->log_statement = v;
2703                 }
2704         else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
2705                 {
2706                         int v = eval_logical(yytext);
2707
2708                         if (v < 0)
2709                         {
2710                                 pool_error("pool_config: invalid value %s for %s", yytext, key);
2711                                 return(-1);
2712                         }
2713                         pool_config->log_statement = v;
2714                 }
2715         }
2716
2717         fclose(fd);
2718
2719         pool_config->backend_desc->num_backends = 0;
2720         total_weight = 0.0;
2721
2722         for (i=0;i<MAX_CONNECTION_SLOTS;i++)
2723         {
2724                 /* port number == 0 indicates that this server is out of use */
2725                 if (BACKEND_INFO(i).backend_port == 0)
2726                 {
2727                         clear_host_entry(i);
2728                 }
2729
2730                 else
2731                 {
2732                         total_weight += BACKEND_INFO(i).unnormalized_weight;
2733                         pool_config->backend_desc->num_backends = i+1;
2734                 }
2735         }
2736
2737         pool_debug("num_backends: %d num_backends: %d total_weight: %f",
2738                            pool_config->backend_desc->num_backends, pool_config->backend_desc->num_backends, total_weight);
2739         /*
2740          * Normalize load balacing weights. What we are doing here is,
2741          * assign 0 to RAND_MAX to each backend's weight according to the
2742          * value weightN.  For example, if two backends are assigned 1.0,
2743          * then each backend will get RAND_MAX/2 normalized weight.
2744          */
2745         for (i=0;i<MAX_CONNECTION_SLOTS;i++)
2746         {
2747 #ifdef DEBUG
2748                 print_host_entry(i);
2749 #endif
2750
2751                 if (pool_config->backend_desc->backend_info[i].backend_port != 0)
2752                 {
2753                         pool_config->backend_desc->backend_info[i].backend_weight =
2754                                 (RAND_MAX) * pool_config->backend_desc->backend_info[i].unnormalized_weight / total_weight;
2755                         pool_debug("backend %d weight: %f", i, pool_config->backend_desc->backend_info[i].backend_weight);
2756                 }
2757         }
2758
2759         if (pool_config->parallel_mode || pool_config->enable_query_cache)
2760         {
2761                 int dist_num;
2762                 SystemDBInfo *info;
2763
2764                 system_db_info = malloc(sizeof(POOL_SYSTEMDB_CONNECTION_POOL));
2765                 if (system_db_info == NULL)
2766                 {
2767                         pool_error("failed to allocate sytem_db_info");
2768                         return -1;
2769                 }
2770                 memset(system_db_info, 0, sizeof(*system_db_info));
2771
2772                 system_db_info->system_db_status = pool_shared_memory_create(sizeof(BACKEND_STATUS));
2773                 if (system_db_info->system_db_status == NULL)
2774                 {
2775                         pool_error("failed to allocate system_db_info->system_db_status");
2776                         return -1;
2777                 }
2778                 *system_db_info->system_db_status = CON_CONNECT_WAIT;   /* which is the same as SYSDB_STATUS = CON_CONNECT_WAIT */
2779
2780                 info = malloc(sizeof(SystemDBInfo));
2781                 if (info == NULL)
2782                 {
2783                         pool_error("failed to allocate info");
2784                         return -1;
2785                 }
2786
2787                 system_db_info->info = info;
2788                 info->hostname = pool_config->system_db_hostname;
2789                 info->port = pool_config->system_db_port;
2790                 info->user = pool_config->system_db_user;
2791                 info->password = pool_config->system_db_password;
2792                 info->database_name = pool_config->system_db_dbname;
2793                 info->schema_name = pool_config->system_db_schema;
2794                 info->dist_def_num = 0;
2795                 info->dist_def_slot = NULL;
2796
2797                 if (pool_config->parallel_mode)
2798                 {
2799                         dist_num = pool_memset_system_db_info(info);
2800                         if(dist_num < 0)
2801                         {
2802                                 pool_error("failed to get systemdb info");
2803                                 return(-1);
2804                         }
2805                 }
2806                 if (pool_config->enable_query_cache)
2807                 {
2808                         info->query_cache_table_info.register_prepared_statement = NULL;
2809                         if (! pool_query_cache_table_exists())
2810                         {
2811                                 pool_error("failed to locate query_cache table. perhaps it's not defined?");
2812                                 return -1;
2813                         }
2814                 }
2815                 SYSDB_STATUS = CON_UP;
2816         }
2817
2818         return 0;
2819 }
2820
2821 static char *extract_string(char *value, POOL_TOKEN token)
2822 {
2823         char *ret;
2824
2825         ret = strdup(value);
2826         if (!ret)
2827         {
2828                 pool_error("extract_string: out of memory");
2829                 return NULL;
2830         }
2831
2832         if (token == POOL_STRING)
2833         {
2834                 ret[strlen(ret)-1] = '\0';
2835                 return (ret+1);
2836         }
2837         return ret;
2838 }
2839
2840 static int eval_logical(char *str)
2841 {
2842         int ret;
2843
2844         if (!strcasecmp(str, "true"))
2845                 ret = 1;
2846         else if (!strcasecmp(str, "false"))
2847                 ret = 0;
2848         else if (!strcmp(str, "1"))
2849                 ret = 1;
2850         else if (!strcmp(str, "0"))
2851                 ret = 0;
2852         else
2853                 ret = -1;
2854
2855         return ret;
2856 }
2857
2858 /*
2859  * extract tokens separated by delimi from str. return value is an
2860  * array of pointers to malloced strings. number of tokens is set to
2861  * n; note that str will be destroyed by strtok(). Also return value
2862  * points to static data, that means subsequent call will change the
2863  * return value.
2864  */
2865 #define MAXTOKENS 1024
2866 static char **extract_string_tokens(char *str, char *delimi, int *n)
2867 {
2868         char *token;
2869         static char *tokens[MAXTOKENS];
2870
2871         *n = 0;
2872
2873         for (token = strtok(str, delimi); token != NULL && *n < MAXTOKENS; token = strtok(NULL, delimi))
2874         {
2875                 tokens[*n] = strdup(token);
2876                 if (tokens[*n] == NULL)
2877                 {
2878                         pool_error("extract_string_tokens: out of memory");
2879                         return NULL;
2880                 }
2881                 pool_debug("extract_string_tokens: token: %s", tokens[*n]);
2882                 (*n)++;
2883         }
2884         return tokens;
2885 }
2886
2887 static void clear_host_entry(int slot)
2888 {
2889         *pool_config->backend_desc->backend_info[slot].backend_hostname = '\0';
2890         pool_config->backend_desc->backend_info[slot].backend_port = 0;
2891         pool_config->backend_desc->backend_info[slot].backend_status = CON_UNUSED;
2892         pool_config->backend_desc->backend_info[slot].backend_weight = 0.0;
2893 }
2894
2895 #ifdef DEBUG
2896 static void print_host_entry(int slot)
2897 {
2898         pool_debug("slot: %d host: %s port: %d status: %d weight: %f",
2899                            slot,
2900                            pool_config->server_hostnames[slot],
2901                            pool_config->server_ports[slot],
2902                            pool_config->server_status[slot],
2903                            pool_config->server_weights[slot]);
2904 }
2905 #endif
2906