LIST_ENTRY (module_opt) next;
};
+/**
+ * Statfile section definition
+ */
+struct statfile_section {
+ uint32_t code; /**< section's code */
+ uint64_t size; /**< size of section */
+ double weight; /**< weight coefficient for section */
+};
+
/**
* Statfile config definition
*/
char *metric; /**< metric name */
size_t size; /**< size of statfile */
struct tokenizer *tokenizer; /**< tokenizer used for statfile */
+ GList *sections; /**< list of sections in statfile */
};
/**
LIST_HEAD (moduleoptq, module_opt) *cur_module_opt = NULL;
struct metric *cur_metric = NULL;
struct statfile *cur_statfile = NULL;
+struct statfile_section *cur_section = NULL;
%}
%token LOGGING LOG_TYPE LOG_TYPE_CONSOLE LOG_TYPE_SYSLOG LOG_TYPE_FILE
%token LOG_LEVEL LOG_LEVEL_DEBUG LOG_LEVEL_INFO LOG_LEVEL_WARNING LOG_LEVEL_ERROR LOG_FACILITY LOG_FILENAME
%token STATFILE ALIAS PATTERN WEIGHT STATFILE_POOL_SIZE SIZE TOKENIZER CLASSIFIER
-%token DELIVERY LMTP ENABLED AGENT
+%token DELIVERY LMTP ENABLED AGENT SECTION
%type <string> STRING
%type <string> VARIABLE
mopt->value = $3;
LIST_INSERT_HEAD (cur_module_opt, mopt, next);
}
+ | VARIABLE EQSIGN QUOTEDSTRING {
+ g_hash_table_insert (cfg->variables, $1, $3);
+ }
;
variable:
| statfilesize
| statfilemetric
| statfiletokenizer
+ | statfilesection
;
statfilealias:
}
;
+statfilesection:
+ SECTION OBRACE sectionbody EBRACE {
+ if (cur_statfile == NULL) {
+ cur_statfile = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile));
+ }
+ if (cur_section == NULL || cur_section->code == 0) {
+ yyerror ("yyparse: error in section definition");
+ YYERROR;
+ }
+ cur_statfile->sections = g_list_prepend (cur_statfile->sections, cur_section);
+ cur_section = NULL;
+ }
+ ;
+sectionbody:
+ sectioncmd SEMICOLON
+ | sectionbody sectioncmd SEMICOLON
+ ;
+
+sectioncmd:
+ sectionname
+ | sectionsize
+ | sectionweight
+ ;
+
+sectionname:
+ NAME EQSIGN QUOTEDSTRING {
+ if (cur_section == NULL) {
+ cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+ }
+ cur_section->code = statfile_get_section_by_name ($3);
+ }
+ ;
+
+sectionsize:
+ SIZE EQSIGN NUMBER {
+ if (cur_section == NULL) {
+ cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+ }
+ cur_section->size = $3;
+ }
+ | SIZE EQSIGN SIZELIMIT {
+ if (cur_section == NULL) {
+ cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+ }
+ cur_section->size = $3;
+ }
+ ;
+
+sectionweight:
+ WEIGHT EQSIGN NUMBER {
+ if (cur_section == NULL) {
+ cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+ }
+ cur_section->weight = $3;
+ }
+ | WEIGHT EQSIGN FRACT {
+ if (cur_section == NULL) {
+ cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+ }
+ cur_section->weight = $3;
+ }
+ ;
statfile_pool_size:
STATFILE_POOL_SIZE EQSIGN SIZELIMIT {
return TRUE;
}
+
+uint32_t
+statfile_get_section_by_name (const char *name)
+{
+ if (g_ascii_strcasecmp (name, "common") == 0) {
+ return STATFILE_SECTION_COMMON;
+ }
+ else if (g_ascii_strcasecmp (name, "header") == 0) {
+ return STATFILE_SECTION_HEADERS;
+ }
+ else if (g_ascii_strcasecmp (name, "url") == 0) {
+ return STATFILE_SECTION_URLS;
+ }
+
+ return 0;
+}
/* Section types */
#define STATFILE_SECTION_COMMON 1
+#define STATFILE_SECTION_HEADERS 2
+#define STATFILE_SECTION_URLS 3
/**
* Common statfile header
*/
gboolean statfile_pool_add_section (statfile_pool_t *pool, char *filename, uint32_t code, uint64_t length);
+
+/**
+ * Return code of section identified by name
+ * @param name name of section
+ * @return code of section or 0 if name of section is unknown
+ */
+uint32_t statfile_get_section_by_name (const char *name);
+
#endif