Blame lib/parser.h

Packit c22fc9
/*
Packit c22fc9
 * Soft:        Keepalived is a failover program for the LVS project
Packit c22fc9
 *              <www.linuxvirtualserver.org>. It monitor & manipulate
Packit c22fc9
 *              a loadbalanced server pool using multi-layer checks.
Packit c22fc9
 *
Packit c22fc9
 * Part:        cfreader.c include file.
Packit c22fc9
 *
Packit c22fc9
 * Author:      Alexandre Cassen, <acassen@linux-vs.org>
Packit c22fc9
 *
Packit c22fc9
 *              This program is distributed in the hope that it will be useful,
Packit c22fc9
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c22fc9
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit c22fc9
 *              See the GNU General Public License for more details.
Packit c22fc9
 *
Packit c22fc9
 *              This program is free software; you can redistribute it and/or
Packit c22fc9
 *              modify it under the terms of the GNU General Public License
Packit c22fc9
 *              as published by the Free Software Foundation; either version
Packit c22fc9
 *              2 of the License, or (at your option) any later version.
Packit c22fc9
 *
Packit c22fc9
 * Copyright (C) 2001-2017 Alexandre Cassen, <acassen@gmail.com>
Packit c22fc9
 */
Packit c22fc9
Packit c22fc9
#ifndef _PARSER_H
Packit c22fc9
#define _PARSER_H
Packit c22fc9
Packit c22fc9
/* system includes */
Packit c22fc9
#include <sys/types.h>
Packit c22fc9
#include <stdbool.h>
Packit c22fc9
#include <stdint.h>
Packit c22fc9
Packit c22fc9
/* local includes */
Packit c22fc9
#include "vector.h"
Packit c22fc9
Packit c22fc9
/* Global definitions */
Packit c22fc9
#define KEEPALIVED_CONFIG_FILE	DEFAULT_CONFIG_FILE
Packit c22fc9
Packit c22fc9
/* Maximum config line length */
Packit c22fc9
#define MAXBUF	1024
Packit c22fc9
Packit c22fc9
/* Maximum time read_timer can return */
Packit c22fc9
#define TIMER_MAX (ULONG_MAX / TIMER_HZ)
Packit c22fc9
Packit c22fc9
/* Configuration test errors. These should be in decreasing order of severity */
Packit c22fc9
typedef enum {
Packit c22fc9
	CONFIG_OK,
Packit c22fc9
Packit c22fc9
	/* The following mean keepalived cannot run the config */
Packit c22fc9
	CONFIG_FILE_NOT_FOUND,
Packit c22fc9
	CONFIG_BAD_IF,
Packit c22fc9
	CONFIG_FATAL,
Packit c22fc9
Packit c22fc9
	/* The following are configuration errors, but keepalived will still run */
Packit c22fc9
	CONFIG_MULTIPLE_FILES,
Packit c22fc9
	CONFIG_UNKNOWN_KEYWORD,
Packit c22fc9
	CONFIG_UNEXPECTED_BOB,	/* '{' */
Packit c22fc9
	CONFIG_MISSING_BOB,	/* '{' */
Packit c22fc9
	CONFIG_UNEXPECTED_EOB,	/* '}' */
Packit c22fc9
	CONFIG_MISSING_EOB,	/* '}' */
Packit c22fc9
	CONFIG_UNMATCHED_QUOTE,
Packit c22fc9
	CONFIG_MISSING_PARAMETER,
Packit c22fc9
	CONFIG_INVALID_NUMBER,
Packit c22fc9
	CONFIG_GENERAL_ERROR,
Packit c22fc9
Packit c22fc9
	/* The following is for script security not enabled when needed */
Packit c22fc9
	CONFIG_SECURITY_ERROR,
Packit c22fc9
} config_err_t;
Packit c22fc9
Packit c22fc9
/* keyword definition */
Packit c22fc9
typedef struct _keyword {
Packit c22fc9
	const char *string;
Packit c22fc9
	void (*handler) (vector_t *);
Packit c22fc9
	vector_t *sub;
Packit c22fc9
	void (*sub_close_handler) (void);
Packit c22fc9
	bool active;
Packit c22fc9
} keyword_t;
Packit c22fc9
Packit c22fc9
/* global vars exported */
Packit c22fc9
extern vector_t *keywords;
Packit c22fc9
extern char *config_id;
Packit c22fc9
extern const char *WHITE_SPACE;
Packit c22fc9
Packit c22fc9
#ifdef _MEM_CHECK_
Packit c22fc9
#define alloc_strvec(str)	(memcheck_log("alloc_strvec", str, (__FILE__), (char *)(__FUNCTION__), (__LINE__)), \
Packit c22fc9
                                 alloc_strvec_r(str))
Packit c22fc9
#else
Packit c22fc9
#define alloc_strvec(str)	(alloc_strvec_r(str))
Packit c22fc9
#endif
Packit c22fc9
Packit c22fc9
/* Prototypes */
Packit c22fc9
extern void report_config_error(config_err_t, const char *format, ...)
Packit c22fc9
	__attribute__((format (printf, 2, 3)));
Packit c22fc9
extern config_err_t get_config_status(void);
Packit c22fc9
extern bool read_int(const char *, int *, int, int, bool);
Packit c22fc9
extern bool read_unsigned(const char *, unsigned *, unsigned, unsigned, bool);
Packit c22fc9
extern bool read_unsigned64(const char *, uint64_t *, uint64_t, uint64_t, bool);
Packit c22fc9
extern bool read_double(const char *, double *, double, double, bool);
Packit c22fc9
extern bool read_int_strvec(const vector_t *, size_t, int *, int, int, bool);
Packit c22fc9
extern bool read_unsigned_strvec(const vector_t *, size_t, unsigned *, unsigned, unsigned, bool);
Packit c22fc9
extern bool read_unsigned64_strvec(const vector_t *, size_t, uint64_t *, uint64_t, uint64_t, bool);
Packit c22fc9
extern bool read_unsigned_base_strvec(const vector_t *, size_t, int, unsigned *, unsigned, unsigned, bool);
Packit c22fc9
extern bool read_double_strvec(const vector_t *, size_t, double *, double, double, bool);
Packit c22fc9
extern void install_keyword_root(const char *, void (*handler) (vector_t *), bool);
Packit c22fc9
extern void install_root_end_handler(void (*handler) (void));
Packit c22fc9
extern void install_sublevel(void);
Packit c22fc9
extern void install_sublevel_end(void);
Packit c22fc9
extern void install_sublevel_end_handler(void (*handler) (void));
Packit c22fc9
extern void install_keyword(const char *, void (*handler) (vector_t *));
Packit c22fc9
extern vector_t *alloc_strvec_quoted_escaped(char *);
Packit c22fc9
extern vector_t *alloc_strvec_r(char *);
Packit c22fc9
extern bool check_conf_file(const char*);
Packit c22fc9
extern vector_t *read_value_block(vector_t *);
Packit c22fc9
extern void alloc_value_block(void (*alloc_func) (vector_t *), const char *);
Packit c22fc9
extern void *set_value(vector_t *);
Packit c22fc9
extern bool read_timer(vector_t *, size_t, unsigned long *, unsigned long, unsigned long, bool);
Packit c22fc9
extern int check_true_false(char *);
Packit c22fc9
extern void skip_block(bool);
Packit c22fc9
extern void init_data(const char *, vector_t * (*init_keywords) (void));
Packit c22fc9
Packit c22fc9
#endif