diff options
Diffstat (limited to 'sinks/syslog/elapi_sink_syslog.c')
-rw-r--r-- | sinks/syslog/elapi_sink_syslog.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/sinks/syslog/elapi_sink_syslog.c b/sinks/syslog/elapi_sink_syslog.c index e1500b5..eb1585e 100644 --- a/sinks/syslog/elapi_sink_syslog.c +++ b/sinks/syslog/elapi_sink_syslog.c @@ -68,7 +68,7 @@ struct syslog_conf { static int init_config(struct data_descriptor *dblock) { struct syslog_conf *conf_data; - struct collection_item *file_config = (struct collection_item *)(NULL); + struct collection_item *config_from_file = (struct collection_item *)(NULL); int found = 0; int *option_cfg = (int *)(NULL); int *facility_cfg = (int *)(NULL); @@ -83,7 +83,7 @@ static int init_config(struct data_descriptor *dblock) if(conf_data == (struct syslog_conf *)(NULL)) return errno; /* Read configuration from the configuration file if any */ - (void)config_to_collection(dblock->appname, SYSLOG_AUDIT_CONFIG, SYSLOG_AUDIT_DIR, &file_config); + (void)config_to_collection(dblock->appname, SYSLOG_AUDIT_CONFIG, SYSLOG_AUDIT_DIR, &config_from_file); conf_data->option = LOG_ODELAY; conf_data->facility = LOG_USER; @@ -96,10 +96,11 @@ static int init_config(struct data_descriptor *dblock) DEBUG_STRING("Identity",conf_data->ident); /* Update defaults with settings from the file */ - error = get_value_from_config((void *)(&option_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"option",file_config); + error = get_value_from_config((void *)(&option_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"option",config_from_file); if(error != EOK) { /* There is fundamentally something wrong */ - DEBUG_NUMBER("Attempt to get option returned error",error); + DEBUG_NUMBER("Attempt to get option returned error",error); + free((void *)(conf_data)); return error; } @@ -109,10 +110,11 @@ static int init_config(struct data_descriptor *dblock) free((void *)(option_cfg)); } - error = get_value_from_config((void *)(&facility_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"facility",file_config); + error = get_value_from_config((void *)(&facility_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"facility",config_from_file); if(error != EOK) { /* There is fundamentally something wrong */ DEBUG_NUMBER("Attempt to get option returned error",error); + free((void *)(conf_data)); return error; } @@ -122,10 +124,11 @@ static int init_config(struct data_descriptor *dblock) free((void *)(facility_cfg)); } - error = get_value_from_config((void *)(&level_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"level",file_config); + error = get_value_from_config((void *)(&level_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"level",config_from_file); if(error != EOK) { /* There is fundamentally something wrong */ DEBUG_NUMBER("Attempt to get option returned error",error); + free((void *)(conf_data)); return error; } @@ -135,10 +138,11 @@ static int init_config(struct data_descriptor *dblock) free((void *)(level_cfg)); } - error = get_value_from_config((void *)(&ident_cfg),ELAPI_TYPE_STRING, INI_DEFAULT_SECTION,"identity",file_config); + error = get_value_from_config((void *)(&ident_cfg),ELAPI_TYPE_STRING, INI_DEFAULT_SECTION,"identity",config_from_file); if(error != EOK) { /* There is fundamentally something wrong */ DEBUG_NUMBER("Attempt to get option returned error",error); + free((void *)(conf_data)); return error; } @@ -202,7 +206,9 @@ static int syslog_sink_init(struct data_descriptor *dblock) /* Formatting calback */ -static int syslog_sink_format(struct data_descriptor *dblock,struct collection_item *event) +static int syslog_sink_format(struct data_descriptor *dblock, + char *format_str, + struct collection_item *event) { struct syslog_event *event_storage; struct syslog_conf *config; @@ -228,13 +234,18 @@ static int syslog_sink_format(struct data_descriptor *dblock,struct collection_i event_storage->priority = *((int *)(item->data)); - /* FIXME */ - - - /* Traverse collection */ - error = traverse_collection(event,ELAPI_TRAVERSE_DEFAULT | ELAPI_TRAVERSE_END ,serialize,(void *)(&(event_storage->sd))); + if(format_str != NULL) { + /* Use format string */ + DEBUG_STRING("Using format:",format_str); + error = serialize_with_format(event,format_str,(void *)(&(event_storage->sd))); + } + else { + /* Traverse collection */ + DEBUG_STRING("Using default serialization callback",""); + error = traverse_collection(event,ELAPI_TRAVERSE_DEFAULT | ELAPI_TRAVERSE_END ,serialize,(void *)(&(event_storage->sd))); + } if(error) { - DEBUG_NUMBER("traverse_collection returned error",error); + DEBUG_NUMBER("Serialization returned error",error); return error; } @@ -276,10 +287,13 @@ static void syslog_sink_close(struct data_descriptor *dblock) if(dblock->internal_data != NULL) { syslog_sink_cleanup(dblock); free(dblock->internal_data); + dblock->internal_data=NULL; + } + + if(dblock->config != NULL) { config = (struct syslog_conf *)(dblock->config); if(config->ident != NULL) free(config->ident); free(dblock->config); - dblock->internal_data=NULL; dblock->config=NULL; } |