summaryrefslogtreecommitdiffstatsabout
path: root/utility/config.h
diff options
context:
space:
mode:
Diffstat (limited to 'utility/config.h')
-rw-r--r--utility/config.h190
1 files changed, 190 insertions, 0 deletions
diff --git a/utility/config.h b/utility/config.h
new file mode 100644
index 0000000..a9bd1b5
--- /dev/null
+++ b/utility/config.h
@@ -0,0 +1,190 @@
1#ifndef CONFIG_H_
2#define CONFIG_H_
3
4#include "apr_tables.h"
5#include "apr_hash.h"
6#include "apr_file_io.h"
7#include "ap_pcre.h"
8
9typedef enum {
10 LOGLEVEL_NOISE = 0,
11 LOGLEVEL_NONE,
12 LOGLEVEL_ERROR,
13 LOGLEVEL_NOTICE,
14 LOGLEVEL_DEBUG,
15} loglevel_e;
16
17typedef struct config_dbd_t config_dbd_t;
18typedef struct config_t config_t;
19struct config_t {
20 /** the structures pool (to ease function arguments) */
21 apr_pool_t *pool;
22
23 /** error log file */
24 const char *errorlog;
25 /** log level */
26 loglevel_e loglevel;
27 /** error_log */
28 apr_file_t *errorlog_fp;
29 apr_file_t *errorlog_fperr;
30 apr_pool_t *errorlog_p;
31
32 const char *badlinefile;
33 const char *badlastfile;
34 apr_file_t *badline_fp;
35 int badline_count;
36 int badlinemax;
37
38
39 /** input directory of log files */
40 const char *input_dir;
41 /** list of files to scan */
42 apr_array_header_t *input_files;
43
44 /** split the input file before processing */
45 int split_enabled;
46 /** the number of files to split each input file into */
47 int split_count;
48 /** the minimum number of lines for each piece */
49 int split_minimum;
50 /** the maximum number of lines for each piece */
51 int split_maximum;
52 /** directory to put ouput split files */
53 const char *split_dir;
54
55 /** the number of threads to run the import in */
56 int thread_count;
57
58 /** db connection configuration */
59 const char *dbdriver;
60 const char *dbparams;
61
62 /** Logging table */
63 const char *table;
64 /** Use transactons */
65 int transactions;
66 /** Machine ID */
67 const char *machineid;
68
69 /** Log file formats */
70 apr_hash_t *log_formats;
71 /** format to use to parse files */
72 const char *logformat;
73
74 /** output fields */
75 apr_array_header_t *output_fields;
76
77 /** filter configuration */
78 apr_array_header_t *linefilters;
79 apr_array_header_t *prefilters;
80 apr_array_header_t *postfilters;
81
82 /** Dry Run */
83 int dryrun;
84 /** dump configuration only */
85 int dump;
86
87 /* Show the summary */
88 int summary;
89};
90
91typedef struct config_filestat_t config_filestat_t;
92struct config_filestat_t {
93 const char *fname;
94 apr_size_t linesparsed;
95 apr_size_t lineskipped;
96 apr_size_t linesbad;
97 const char *result;
98 apr_time_t start;
99 apr_time_t stop;
100};
101
102typedef struct config_logformat_t config_logformat_t;
103struct config_logformat_t {
104 const char *name;
105 apr_array_header_t *fields;
106};
107
108typedef struct config_logformat_field_t config_logformat_field_t;
109struct config_logformat_field_t {
110 const char *name;
111 const char *datatype;
112};
113
114typedef struct config_opt_t config_opt_t;
115typedef apr_status_t (*config_func_t)(config_t *cfg, config_opt_t *opt,
116 int argc, const char **argv);
117struct config_opt_t {
118 const char *name;
119 const char *help;
120 config_func_t func;
121 void *data;
122};
123
124typedef struct config_filter_t config_filter_t;
125struct config_filter_t {
126 const char *field;
127 const char *filter;
128 int negative;
129 ap_regex_t *regex;
130};
131
132typedef enum {
133 LOGSQL_DATATYPE_INT = 0,
134 LOGSQL_DATATYPE_SMALLINT,
135 LOGSQL_DATATYPE_VARCHAR,
136 LOGSQL_DATATYPE_CHAR,
137 LOGSQL_DATATYPE_BIGINT
138} logsql_field_datatype;
139#define logsql_field_datatyeName(x) \
140 (x == LOGSQL_DATATYPE_INT ? "INT" \
141 : (x == LOGSQL_DATATYPE_SMALLINT ? "SMALLINT" \
142 : (x == LOGSQL_DATATYPE_VARCHAR ? "VARCHAR" \
143 : (x == LOGSQL_DATATYPE_CHAR ? "CHAR" \
144 : (x == LOGSQL_DATATYPE_BIGINT ? "BIGINT" : "ERR")))))
145
146typedef struct config_output_field_t config_output_field_t;
147
148typedef struct parser_func_t parser_func_t;
149
150struct config_output_field_t {
151 const char *field;
152 logsql_field_datatype datatype;
153 apr_size_t size;
154 const char *def;
155 const char *source;
156 const char *fname;
157 parser_func_t *func;
158 const char **args;
159 void *data;
160};
161
162#define CHECK_YESNO(c) ((!strcasecmp(c,"on") || !strcasecmp(c,"yes")) ? 1 : 0)
163
164/**
165 * Initialize the config parser
166 */
167void config_init(apr_pool_t *p);
168
169/**
170 * Dump the configuration to stdout
171 */
172void config_dump(config_t *cfg);
173
174/**
175 * Checks the configuration to ensure all the required settings are set
176 */
177apr_status_t config_check(config_t *cfg);
178
179/**
180 * Creates the default configuration
181 */
182config_t *config_create(apr_pool_t *p);
183
184/**
185 * Read in a configuration file
186 */
187apr_status_t config_read(config_t *cfg, const char *filename,
188 apr_table_t *merge);
189
190#endif /*CONFIG_H_*/