diff options
Diffstat (limited to 'utility/config.h')
| -rw-r--r-- | utility/config.h | 190 |
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 | |||
| 9 | typedef enum { | ||
| 10 | LOGLEVEL_NOISE = 0, | ||
| 11 | LOGLEVEL_NONE, | ||
| 12 | LOGLEVEL_ERROR, | ||
| 13 | LOGLEVEL_NOTICE, | ||
| 14 | LOGLEVEL_DEBUG, | ||
| 15 | } loglevel_e; | ||
| 16 | |||
| 17 | typedef struct config_dbd_t config_dbd_t; | ||
| 18 | typedef struct config_t config_t; | ||
| 19 | struct 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 | |||
| 91 | typedef struct config_filestat_t config_filestat_t; | ||
| 92 | struct 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 | |||
| 102 | typedef struct config_logformat_t config_logformat_t; | ||
| 103 | struct config_logformat_t { | ||
| 104 | const char *name; | ||
| 105 | apr_array_header_t *fields; | ||
| 106 | }; | ||
| 107 | |||
| 108 | typedef struct config_logformat_field_t config_logformat_field_t; | ||
| 109 | struct config_logformat_field_t { | ||
| 110 | const char *name; | ||
| 111 | const char *datatype; | ||
| 112 | }; | ||
| 113 | |||
| 114 | typedef struct config_opt_t config_opt_t; | ||
| 115 | typedef apr_status_t (*config_func_t)(config_t *cfg, config_opt_t *opt, | ||
| 116 | int argc, const char **argv); | ||
| 117 | struct config_opt_t { | ||
| 118 | const char *name; | ||
| 119 | const char *help; | ||
| 120 | config_func_t func; | ||
| 121 | void *data; | ||
| 122 | }; | ||
| 123 | |||
| 124 | typedef struct config_filter_t config_filter_t; | ||
| 125 | struct config_filter_t { | ||
| 126 | const char *field; | ||
| 127 | const char *filter; | ||
| 128 | int negative; | ||
| 129 | ap_regex_t *regex; | ||
| 130 | }; | ||
| 131 | |||
| 132 | typedef 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 | |||
| 146 | typedef struct config_output_field_t config_output_field_t; | ||
| 147 | |||
| 148 | typedef struct parser_func_t parser_func_t; | ||
| 149 | |||
| 150 | struct 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 | */ | ||
| 167 | void config_init(apr_pool_t *p); | ||
| 168 | |||
| 169 | /** | ||
| 170 | * Dump the configuration to stdout | ||
| 171 | */ | ||
| 172 | void config_dump(config_t *cfg); | ||
| 173 | |||
| 174 | /** | ||
| 175 | * Checks the configuration to ensure all the required settings are set | ||
| 176 | */ | ||
| 177 | apr_status_t config_check(config_t *cfg); | ||
| 178 | |||
| 179 | /** | ||
| 180 | * Creates the default configuration | ||
| 181 | */ | ||
| 182 | config_t *config_create(apr_pool_t *p); | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Read in a configuration file | ||
| 186 | */ | ||
| 187 | apr_status_t config_read(config_t *cfg, const char *filename, | ||
| 188 | apr_table_t *merge); | ||
| 189 | |||
| 190 | #endif /*CONFIG_H_*/ | ||
