summaryrefslogtreecommitdiffstats
path: root/utility/logparse.c
diff options
context:
space:
mode:
authorGravatar Edward Rudd 2008-10-24 13:55:48 +0000
committerGravatar Edward Rudd 2008-10-24 13:55:48 +0000
commit19bbdd68a491721dd4aeff7cacea51148ce3a9b9 (patch)
tree4e143a77f879f7baf65797c08a4e3a489b4ac755 /utility/logparse.c
parent50af087b9f3831285869dc8d8bf91cc3e6d5169a (diff)
add logging function
added @todo tags for what needs to be finished
Diffstat (limited to 'utility/logparse.c')
-rw-r--r--utility/logparse.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/utility/logparse.c b/utility/logparse.c
index dfe2e9b..4b5ab40 100644
--- a/utility/logparse.c
+++ b/utility/logparse.c
@@ -15,7 +15,7 @@
15apr_hash_t *g_parser_funcs; 15apr_hash_t *g_parser_funcs;
16 16
17static apr_status_t parser_func_regexmatch(apr_pool_t *p, config_t *cfg, 17static apr_status_t parser_func_regexmatch(apr_pool_t *p, config_t *cfg,
18 config_output_field_t *field, const char *value, char **ret) 18 config_output_field_t *field, const char *value, const char **ret)
19{ 19{
20 struct { 20 struct {
21 ap_regex_t *rx; 21 ap_regex_t *rx;
@@ -48,7 +48,7 @@ static apr_status_t parser_func_regexmatch(apr_pool_t *p, config_t *cfg,
48} 48}
49 49
50static apr_status_t parser_func_totimestamp(apr_pool_t *p, config_t *cfg, 50static apr_status_t parser_func_totimestamp(apr_pool_t *p, config_t *cfg,
51 config_output_field_t *field, const char *value, char **ret) 51 config_output_field_t *field, const char *value, const char **ret)
52{ 52{
53 time_t time; 53 time_t time;
54 struct tm ts; 54 struct tm ts;
@@ -63,12 +63,18 @@ static apr_status_t parser_func_totimestamp(apr_pool_t *p, config_t *cfg,
63} 63}
64 64
65static apr_status_t parser_func_machineid(apr_pool_t *p, config_t *cfg, 65static apr_status_t parser_func_machineid(apr_pool_t *p, config_t *cfg,
66 config_output_field_t *field, const char *value, char **ret) 66 config_output_field_t *field, const char *value, const char **ret)
67{ 67{
68 *ret = apr_pstrdup(p,cfg->machineid); 68 if (cfg->machineid) {
69 *ret = apr_pstrdup(p,cfg->machineid);
70 } else {
71 *ret = field->def;
72 }
69 return APR_SUCCESS; 73 return APR_SUCCESS;
70} 74}
71 75
76/** @todo Implement Query arg ripping function */
77
72parser_func_t parser_get_func(const char *name) 78parser_func_t parser_get_func(const char *name)
73{ 79{
74 return apr_hash_get(g_parser_funcs, name, APR_HASH_KEY_STRING); 80 return apr_hash_get(g_parser_funcs, name, APR_HASH_KEY_STRING);
@@ -258,6 +264,7 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename)
258 rv = apr_file_open(&file, filename, APR_FOPEN_READ | APR_BUFFERED, 264 rv = apr_file_open(&file, filename, APR_FOPEN_READ | APR_BUFFERED,
259 APR_OS_DEFAULT, tp); 265 APR_OS_DEFAULT, tp);
260 if (rv != APR_SUCCESS) { 266 if (rv != APR_SUCCESS) {
267 logging_log(cfg, LOGLEVEL_ERROR, "Could not open %s",filename);
261 printf("Could not open %s\n", filename); 268 printf("Could not open %s\n", filename);
262 return rv; 269 return rv;
263 } 270 }
@@ -298,7 +305,7 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, char **argv, in
298 config_output_field_t *ofields; 305 config_output_field_t *ofields;
299 apr_table_t *datain; 306 apr_table_t *datain;
300 apr_table_t *dataout; 307 apr_table_t *dataout;
301 apr_status_t rv; 308 apr_status_t rv = APR_SUCCESS;
302 int i; 309 int i;
303 310
304 fmt = apr_hash_get(cfg->log_formats, cfg->logformat, APR_HASH_KEY_STRING); 311 fmt = apr_hash_get(cfg->log_formats, cfg->logformat, APR_HASH_KEY_STRING);
@@ -326,21 +333,20 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, char **argv, in
326 } 333 }
327 if (!ofields[i].func) { 334 if (!ofields[i].func) {
328 apr_table_setn(dataout,ofields[i].field, val); 335 apr_table_setn(dataout,ofields[i].field, val);
329 //printf("S: %s = %s\n",ofields[i].field, val);
330 } else { 336 } else {
331 char *ret = NULL; 337 const char *ret = NULL;
332 rv = ((parser_func_t)ofields[i].func)(ptemp, cfg, &ofields[i], val, 338 rv = ((parser_func_t)ofields[i].func)(ptemp, cfg, &ofields[i], val,
333 &ret); 339 &ret);
334 if (rv) return rv; 340 if (rv) return rv;
335 apr_table_setn(dataout, ofields[i].field, ret); 341 apr_table_setn(dataout, ofields[i].field, ret);
336 //printf("S: %s = %s\n",ofields[i].field, ret);
337 } 342 }
338 } 343 }
339 344
340 /** @todo Run Post Filters here */ 345 /** @todo Run Post Filters here */
341 346
342 // Process DB Query 347 // Process DB Query
343 rv = database_insert(cfg, ptemp, dataout); 348 if (!cfg->dryrun) {
344 if (rv) return rv; 349 rv = database_insert(cfg, ptemp, dataout);
345 return APR_SUCCESS; 350 }
351 return rv;
346} 352}