summaryrefslogtreecommitdiffstatsabout
path: root/utility/logparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility/logparse.c')
-rw-r--r--utility/logparse.c93
1 files changed, 82 insertions, 11 deletions
diff --git a/utility/logparse.c b/utility/logparse.c
index 2940534..4d823ce 100644
--- a/utility/logparse.c
+++ b/utility/logparse.c
@@ -3,7 +3,35 @@
3#include "apr_file_io.h" 3#include "apr_file_io.h"
4#include "apr_strings.h" 4#include "apr_strings.h"
5 5
6void find_log_files(config_t *cfg) 6#include "util.h"
7
8apr_hash_t *g_parser_funcs;
9
10static apr_status_t parser_func_regexmatch(config_t *cfg, const char *data,
11 int argc, const char **argv)
12{
13 return APR_SUCCESS;
14}
15parser_func_t parser_get_func(const char *name)
16{
17 return apr_hash_get(g_parser_funcs, name, APR_HASH_KEY_STRING);
18}
19
20static void parser_add_func(apr_pool_t *p, const char *const name,
21 parser_func_t func)
22{
23 if (!g_parser_funcs) {
24 g_parser_funcs = apr_hash_make(p);
25 }
26 apr_hash_set(g_parser_funcs, lowerstr(p, name), APR_HASH_KEY_STRING, func);
27}
28
29void parser_init(apr_pool_t *p)
30{
31 parser_add_func(p, "regexmatch", parser_func_regexmatch);
32}
33
34void parser_find_logs(config_t *cfg)
7{ 35{
8 apr_pool_t *tp; 36 apr_pool_t *tp;
9 apr_dir_t *dir; 37 apr_dir_t *dir;
@@ -39,7 +67,7 @@ void find_log_files(config_t *cfg)
39 * found during parsing of the arg_str. 67 * found during parsing of the arg_str.
40 * keepquotes: Keep the quotes instead of stripping them 68 * keepquotes: Keep the quotes instead of stripping them
41 */ 69 */
42apr_status_t tokenize_logline(const char *arg_str, char ***argv_out, 70static apr_status_t tokenize_logline(const char *arg_str, char ***argv_out,
43 apr_pool_t *token_context, int keepquotes) 71 apr_pool_t *token_context, int keepquotes)
44{ 72{
45 const char *cp; 73 const char *cp;
@@ -157,7 +185,7 @@ apr_status_t tokenize_logline(const char *arg_str, char ***argv_out,
157 185
158apr_status_t parse_logfile(config_t *cfg, const char *filename) 186apr_status_t parse_logfile(config_t *cfg, const char *filename)
159{ 187{
160 apr_pool_t *tp, *argp; 188 apr_pool_t *tp, *targp;
161 apr_file_t *file; 189 apr_file_t *file;
162 apr_status_t rv; 190 apr_status_t rv;
163 char buff[2048]; 191 char buff[2048];
@@ -166,7 +194,7 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename)
166 int line; 194 int line;
167 195
168 apr_pool_create(&tp, cfg->pool); 196 apr_pool_create(&tp, cfg->pool);
169 apr_pool_create(&argp, tp); 197 apr_pool_create(&targp, tp);
170 198
171 rv = apr_file_open(&file, filename, APR_FOPEN_READ | APR_BUFFERED, 199 rv = apr_file_open(&file, filename, APR_FOPEN_READ | APR_BUFFERED,
172 APR_OS_DEFAULT, tp); 200 APR_OS_DEFAULT, tp);
@@ -180,16 +208,16 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename)
180 rv = apr_file_gets(buff, 1024, file); 208 rv = apr_file_gets(buff, 1024, file);
181 if (rv == APR_SUCCESS) { 209 if (rv == APR_SUCCESS) {
182 line++; 210 line++;
183 char *ptr;
184 // chomp off newline 211 // chomp off newline
185 for (ptr = buff + strlen(buff); *ptr != '\r' && *ptr != '\n'; ptr--) 212 line_chomp(buff);
186 ; 213
187 *ptr = '\0'; 214 apr_pool_clear(targp);
188 apr_pool_clear(argp); 215 tokenize_logline(buff, &targv, targp, 1);
189 tokenize_logline(buff, &targv, argp, 1);
190 targc = 0; 216 targc = 0;
191 while (targv[targc]) targc++; 217 while (targv[targc]) targc++;
192 if (targc != 9) { 218 /** @todo Run Line Filters here */
219 rv = parse_processline(targp, cfg, targv, targc);
220 if (rv != APR_SUCCESS) {
193 int i; 221 int i;
194 printf("Line %d(%d): %s\n",line, targc, buff); 222 printf("Line %d(%d): %s\n",line, targc, buff);
195 for (i = 0; targv[i]; i++) { 223 for (i = 0; targv[i]; i++) {
@@ -203,3 +231,46 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename)
203 apr_pool_destroy(tp); 231 apr_pool_destroy(tp);
204 return APR_SUCCESS; 232 return APR_SUCCESS;
205} 233}
234
235apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, char **argv, int argc)
236{
237 config_logformat_t *fmt;
238 config_logformat_field_t *ifields;
239 config_output_field_t *ofields;
240 apr_table_t *datain;
241 apr_table_t *dataout;
242 int i;
243
244 fmt = apr_hash_get(cfg->log_formats, cfg->logformat, APR_HASH_KEY_STRING);
245 if (!fmt) return APR_EINVAL;
246 if (fmt->fields->nelts != argc) return APR_EINVAL;
247
248 datain = apr_table_make(ptemp, fmt->fields->nelts);
249 dataout = apr_table_make(ptemp, cfg->output_fields->nelts);
250
251 ifields = (config_logformat_field_t *)fmt->fields->elts;
252 for (i=0; i<fmt->fields->nelts; i++) {
253 apr_table_setn(datain,ifields[i].name,argv[i]);
254 }
255 /** @todo Run Pre Filters here */
256
257 // Convert input fields to output fields
258 ofields = (config_output_field_t *)cfg->output_fields->elts;
259 for (i=0; i<cfg->output_fields->nelts; i++) {
260 const char *t;
261 if (!ofields[i].func) {
262 t = apr_table_get(datain, ofields[i].source);
263 if (!t) {
264 return APR_EINVAL;
265 }
266 apr_table_setn(dataout,ofields[i].field, t);
267 printf("S: %s = %s\n",ofields[i].source, t);
268 } else {
269 printf("S: %s, F: %p\n",ofields[i].source, ofields[i].func);
270 }
271 }
272
273 /** @todo Run Post Filters here */
274
275 return APR_SUCCESS;
276}