summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-02-25 13:59:43 -0500
committerDmitri Pal <dpal@redhat.com>2009-02-25 13:59:43 -0500
commitacb92e98ab01d5582d52737a7ad89919a00458aa (patch)
tree7c8bde4029ebe11027e69d9d90d09924dbed2a81
parent8c83881017e3815534f9d880c58b78a56ca4f971 (diff)
downloadelapi_draft-acb92e98ab01d5582d52737a7ad89919a00458aa.tar.gz
elapi_draft-acb92e98ab01d5582d52737a7ad89919a00458aa.tar.xz
elapi_draft-acb92e98ab01d5582d52737a7ad89919a00458aa.zip
Adding copyrights and a new sink. Interim commit.
-rw-r--r--collection/elapi_collection.c19
-rw-r--r--collection/elapi_collection.h19
-rw-r--r--collection/elapi_collection_ut.c20
-rw-r--r--collection/elapi_debug.h19
-rw-r--r--collection/elapi_tools.c20
-rw-r--r--collection/elapi_tools.h20
-rw-r--r--collection/elapi_util.c22
-rw-r--r--collection/elapi_util.h20
-rw-r--r--dispatcher/elapi_dispatcher.c19
-rw-r--r--dispatcher/elapi_dispatcher.h19
-rw-r--r--dispatcher/elapi_dispatcher_ut.c20
-rw-r--r--ini/elapi_ini.c21
-rw-r--r--ini/elapi_ini.h21
-rw-r--r--ini/elapi_ini_ut.c19
-rw-r--r--sinks/elapi_sink.h19
-rw-r--r--sinks/file/Makefile.am9
-rw-r--r--sinks/file/elapi_sink_file.c496
-rw-r--r--sinks/stderr/elapi_sink_stderr.c20
-rw-r--r--sinks/syslog/elapi_sink_syslog.c20
19 files changed, 607 insertions, 235 deletions
diff --git a/collection/elapi_collection.c b/collection/elapi_collection.c
index f2614a6..50809ae 100644
--- a/collection/elapi_collection.c
+++ b/collection/elapi_collection.c
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Implemenation of the collection interface.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#define _GNU_SOURCE
#include <string.h>
diff --git a/collection/elapi_collection.h b/collection/elapi_collection.h
index 9b9e8c3..361c0c6 100644
--- a/collection/elapi_collection.h
+++ b/collection/elapi_collection.h
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Header file for collection interface.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifndef ELAPI_COLLECTION_H
#define ELAPI_COLLECTION_H
diff --git a/collection/elapi_collection_ut.c b/collection/elapi_collection_ut.c
index a7f55d5..242d1e2 100644
--- a/collection/elapi_collection_ut.c
+++ b/collection/elapi_collection_ut.c
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Collection unit test.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <string.h>
diff --git a/collection/elapi_debug.h b/collection/elapi_debug.h
index 5f2c174..5515a92 100644
--- a/collection/elapi_debug.h
+++ b/collection/elapi_debug.h
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Internal debugging header file.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifndef ELAPI_DEBUG_H
#define ELAPI_DEBUG_H
diff --git a/collection/elapi_tools.c b/collection/elapi_tools.c
index d1d00c0..879d694 100644
--- a/collection/elapi_tools.c
+++ b/collection/elapi_tools.c
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Additional functions for printing and debugging collections.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <malloc.h>
diff --git a/collection/elapi_tools.h b/collection/elapi_tools.h
index fd9bf63..9a5b39e 100644
--- a/collection/elapi_tools.h
+++ b/collection/elapi_tools.h
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Header file for supplementary functions that provide
+ printing and debugging collections.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifndef ELAPI_TOOLS_H
#define ELAPI_TOOLS_H
diff --git a/collection/elapi_util.c b/collection/elapi_util.c
index 1224c25..e275703 100644
--- a/collection/elapi_util.c
+++ b/collection/elapi_util.c
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Different serialization methods of the collection.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <string.h>
@@ -12,7 +30,7 @@
const char *get_type(int type)
{
switch(type) {
- case ELAPI_TYPE_STRING: return ELAPI_TYPE_NAME_STRING;
+ case ELAPI_TYPE_STRING: return ELAPI_TYPE_NAME_STRING;
case ELAPI_TYPE_INTEGER: return ELAPI_TYPE_NAME_INTEGER;
case ELAPI_TYPE_UNSIGNED: return ELAPI_TYPE_NAME_UNSIGNED;
case ELAPI_TYPE_LONG: return ELAPI_TYPE_NAME_LONG;
diff --git a/collection/elapi_util.h b/collection/elapi_util.h
index f701e5c..a379ec3 100644
--- a/collection/elapi_util.h
+++ b/collection/elapi_util.h
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Header files with serialization methods of the collection.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#ifndef ELAPI_UTIL_H
#define ELAPI_UTIL_H
diff --git a/dispatcher/elapi_dispatcher.c b/dispatcher/elapi_dispatcher.c
index ff1a275..3995310 100644
--- a/dispatcher/elapi_dispatcher.c
+++ b/dispatcher/elapi_dispatcher.c
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Audit log dispatcher interface implementation.
+
+ Copyright (C) Dmitri Pal <dpal@redhar.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <stdio.h>
#include <string.h>
diff --git a/dispatcher/elapi_dispatcher.h b/dispatcher/elapi_dispatcher.h
index 909505a..c7a582e 100644
--- a/dispatcher/elapi_dispatcher.h
+++ b/dispatcher/elapi_dispatcher.h
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Header file for the dispatcher interface.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifndef ELAPI_DISPATCHER_H
#define ELAPI_DISPATCHER_H
diff --git a/dispatcher/elapi_dispatcher_ut.c b/dispatcher/elapi_dispatcher_ut.c
index bb848fa..e860096 100644
--- a/dispatcher/elapi_dispatcher_ut.c
+++ b/dispatcher/elapi_dispatcher_ut.c
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Unit test for dispatcher.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <malloc.h>
diff --git a/ini/elapi_ini.c b/ini/elapi_ini.c
index 52af8dc..524626a 100644
--- a/ini/elapi_ini.c
+++ b/ini/elapi_ini.c
@@ -1,4 +1,23 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Reading configuration from INI file
+ and storing as collection.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <errno.h>
diff --git a/ini/elapi_ini.h b/ini/elapi_ini.h
index 10460f7..4a3e973 100644
--- a/ini/elapi_ini.h
+++ b/ini/elapi_ini.h
@@ -1,4 +1,23 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Header file for reading configuration from INI file
+ and storing as collection.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#ifndef ELAPI_INI_H
#define ELAPI_INI_H
diff --git a/ini/elapi_ini_ut.c b/ini/elapi_ini_ut.c
index 7b783dc..968f6b2 100644
--- a/ini/elapi_ini_ut.c
+++ b/ini/elapi_ini_ut.c
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Unit test for configuration reading interface.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <stdio.h>
#include "elapi_ini.h"
diff --git a/sinks/elapi_sink.h b/sinks/elapi_sink.h
index 64ce235..74b7622 100644
--- a/sinks/elapi_sink.h
+++ b/sinks/elapi_sink.h
@@ -1,4 +1,21 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Common sink interface header.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifndef ELAPI_SINK_H
#define ELAPI_SINK_H
diff --git a/sinks/file/Makefile.am b/sinks/file/Makefile.am
new file mode 100644
index 0000000..67b3ca2
--- /dev/null
+++ b/sinks/file/Makefile.am
@@ -0,0 +1,9 @@
+topdir=../..
+DEBUG_FLAGS=@DEBUG_VAR@
+AM_CPPFLAGS = -I$(srcdir)/.. -I$(srcdir)/../../collection -I$(srcdir)/../../ini -I/usr/include/libxml2 $(DEBUG_FLAGS)
+
+
+lib_LTLIBRARIES = libelapi_sink_syslog.la
+libelapi_sink_syslog_la_SOURCES = elapi_sink_syslog.c $(topdir)/ini/elapi_ini.c
+
+include_HEADERS = ../elapi_sink.h
diff --git a/sinks/file/elapi_sink_file.c b/sinks/file/elapi_sink_file.c
index 8358854..057bb34 100644
--- a/sinks/file/elapi_sink_file.c
+++ b/sinks/file/elapi_sink_file.c
@@ -1,268 +1,330 @@
-/* Copyright */
-
-#include <string.h>
-#include <stdlib.h>
+/*
+ ELAPI
+
+ Implemenation of the file sink.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
#include <errno.h>
-#include "log_file_facility.h"
-#include "log_util.h"
-#include "log_debug.h"
-
-/******************** MAIN MODULE FUNCTIONS ****************************/
-/* Function to fill in the facility configuration */
-int create_file_facility_config(struct file_config **config, char *path, int mode)
+#include <malloc.h>
+#include <syslog.h>
+#include "elapi_sink.h"
+#include "elapi_collection.h"
+#include "elapi_debug.h"
+#include "elapi_util.h"
+#include "elapi_ini.h"
+
+/* Global variable - instance */
+static int instance = 0;
+
+/* FIXME - this should be taken from the config.h generated by autotools */
+#define FILE_RETRY 60
+/*
+#define FILE_AUDIT_CONFIG "/etc/elapi/syslog_defaults.conf"
+#define FILE_AUDIT_DIR "/etc/elapi/syslog_defaults.d"
+*/
+#define FILE_AUDIT_CONFIG "/home/dpal/IPA/Code/elapi/etc/syslog_defaults.conf"
+#define FILE_AUDIT_DIR "/home/dpal/IPA/Code/elapi/etc/syslog_defaults.d"
+
+
+/* FIXME there is currently no code
+ * to make sure we do not call syslog functions from multiple dispatchers.
+ * We probably should create a mutex at the load of the library and
+ * set a flag when the init function is called the first time
+ * and not call the openlog any more times.
+ * But I guess syslog can deal with this internally.
+ */
+
+
+struct syslog_event {
+ struct serial_data sd;
+ int priority;
+};
+
+
+/* Default conmfiguration for syslog */
+struct syslog_conf {
+ int option;
+ int facility;
+ int level;
+ char *ident;
+};
+
+/* Internal function to intialize configuration */
+static int init_config(struct data_descriptor *dblock)
{
- struct file_config *cfg = (struct file_config *)(NULL);
-
- DEBUG_STRING("create_file_facility_config","Entry point");
-
- errno = 0;
-
- /* Allocate memory for the structure */
- cfg = (struct file_config *)(malloc(sizeof(struct file_config)));
+ struct syslog_conf *conf_data;
+ struct collection_item *file_config = (struct collection_item *)(NULL);
+ int found = 0;
+ int *option_cfg = (int *)(NULL);
+ int *facility_cfg = (int *)(NULL);
+ int *level_cfg = (int *)(NULL);
+ char *ident_cfg = NULL;
+ int error;
+
+ DEBUG_STRING("init_config","Entry");
+
+ /* Allocate configuration data */
+ conf_data = (struct syslog_conf *)(malloc(sizeof(struct syslog_conf)));
+ 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);
+
+ conf_data->option = LOG_ODELAY;
+ conf_data->facility = LOG_USER;
+ conf_data->level = LOG_INFO;
+ conf_data->ident = NULL;
+
+ DEBUG_NUMBER("Option",conf_data->option);
+ DEBUG_NUMBER("Facility",conf_data->facility);
+ DEBUG_NUMBER("Level",conf_data->level);
+ 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);
+ if(error != EOK) {
+ /* There is fundamentally something wrong */
+ DEBUG_NUMBER("Attempt to get option returned error",error);
+ return error;
+ }
- if(cfg == (struct file_config *)(NULL)) return errno;
+ /* Get the value */
+ if(option_cfg != (int *)(NULL)) {
+ conf_data->option = *option_cfg;
+ free((void *)(option_cfg));
+ }
+
+ error = get_value_from_config((void *)(&facility_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"facility",file_config);
+ if(error != EOK) {
+ /* There is fundamentally something wrong */
+ DEBUG_NUMBER("Attempt to get option returned error",error);
+ return error;
+ }
- /* Initialize. */
- if(path != NULL) {
- cfg->path = strdup(path);
- if(cfg->path == NULL) {
- free(cfg);
- return errno;
- }
+ /* Get the value */
+ if(facility_cfg != (int *)(NULL)) {
+ conf_data->facility = *facility_cfg;
+ free((void *)(facility_cfg));
+ }
+
+ error = get_value_from_config((void *)(&level_cfg),ELAPI_TYPE_INTEGER, INI_DEFAULT_SECTION,"level",file_config);
+ if(error != EOK) {
+ /* There is fundamentally something wrong */
+ DEBUG_NUMBER("Attempt to get option returned error",error);
+ return error;
}
- else cfg->path = NULL;
- cfg->mode = mode;
- cfg->ff = NULL;
+ /* Get the value */
+ if(level_cfg != (int *)(NULL)) {
+ conf_data->level = *level_cfg;
+ free((void *)(level_cfg));
+ }
+
+ error = get_value_from_config((void *)(&ident_cfg),ELAPI_TYPE_STRING, INI_DEFAULT_SECTION,"identity",file_config);
+ if(error != EOK) {
+ /* There is fundamentally something wrong */
+ DEBUG_NUMBER("Attempt to get option returned error",error);
+ return error;
+ }
- *config = cfg;
+ /* Get the value */
+ if(ident_cfg != (char *)(NULL)) {
+ conf_data->ident = ident_cfg;
+ }
- DEBUG_STRING("create_file_facility_config","Exit point");
- return 0;
+ DEBUG_NUMBER("Option (after conf file):",conf_data->option);
+ DEBUG_NUMBER("Facility (after conf file):",conf_data->facility);
+ DEBUG_NUMBER("Level (after conf file):",conf_data->level);
+ DEBUG_STRING("Identity (after conf file):",conf_data->ident);
-}
+ dblock->config = (void *)(conf_data);
-/* Function cleans the config */
-void clean_file_facility_config(struct file_config **config)
-{
- DEBUG_STRING("clean_file_facility_config","Entry point");
+ openlog(conf_data->ident,conf_data->option,conf_data->facility);
+ instance++;
+ DEBUG_NUMBER("syslog instance",instance);
- if(config == (struct file_config **)(NULL)) return;
-
- if(*config != (struct file_config *)(NULL)) {
- if((*config)->path != NULL) free((*config)->path);
- free(*config);
- }
-
- DEBUG_STRING("clean_file_facility_config","Exit point");
+ DEBUG_STRING("init_config","Entry");
+ return EOK;
}
/***** Standard functions each facility has to provide *****/
/* Initialize facility - open files, establish connnectons, etc... */
-int file_facility_init(struct data_descriptor *dblock)
+static int syslog_sink_init(struct data_descriptor *dblock)
{
- struct file_config *cfg;
- struct file_event_data *event_data;
+ struct syslog_event *event_storage;
+ int error;
- DEBUG_STRING("file_facility_init","Entry point");
+ DEBUG_STRING("syslog_sink_init","Entry");
/* Prepare the block where the format function will store its data */
errno = 0;
- event_data = malloc(sizeof(struct file_event_data));
- if(event_data == NULL) return errno;
- dblock->event_data = event_data;
-
- /* Deal with file */
- errno = 0;
- cfg = (struct file_config *)(dblock->config);
-
- /* If we have "path" open file and trancate if needed */
- if(cfg->path != NULL) {
- if(cfg->mode & EL_FILE_TRUNCATE) {
- cfg->ff = fopen(cfg->path,"w");
- if(cfg->ff == (FILE *)(NULL)) return errno;
- if(cfg->mode & EL_FILE_OPEN_PER_CMD) {
- fclose(cfg->ff);
- cfg->ff = NULL;
- }
- }
- }
- else {
- cfg->ff=stderr;
- cfg->mode = EL_FILE_KEEP_OPEN;
+ dblock->internal_data = NULL;
+ event_storage = (struct syslog_event *)(malloc(sizeof(struct syslog_event)));
+ if(event_storage == (struct syslog_event *)(NULL)) return errno;
+
+ event_storage->sd.buffer = NULL;
+ event_storage->sd.size = 0;
+ event_storage->sd.length = 0;
+ event_storage->sd.nest_level = 0;
+
+ dblock->internal_data = (void *)(event_storage);
+
+ /* Prepare the configuration data block */
+ if((error = init_config(dblock))) {
+ DEBUG_NUMBER("Failed to init config",error);
+ free(dblock->internal_data);
+ dblock->internal_data = NULL;
+ return error;
}
- DEBUG_STRING("file_facility_init","Exit point");
- return 0;
+ DEBUG_NUMBER("DBLOCK in init",dblock);
+ DEBUG_NUMBER("internal data in init",dblock->internal_data);
+
+ DEBUG_STRING("syslog_sink_init","Exit");
+ return EOK;
}
+
/* Formatting calback */
-int file_facility_format(struct data_descriptor *dblock,struct event_handle *event)
+static int syslog_sink_format(struct data_descriptor *dblock,struct collection_item *event)
{
- struct file_event_data *event_data;
- struct event_item *item = NULL;
- int length = 0;
- int size = EL_FILE_BLOCK_SIZE;
- int item_len = 0;
- int property_len = 0;
- int nest_level = 0;
- int cnt = 0;
- int first = 1;
-
- DEBUG_STRING("file_facility_format","Entry point");
-
- event_data = dblock->event_data;
-
- /* Prepare momory */
- errno = 0;
- event_data->buffer = malloc(size);
- if(event_data->buffer == NULL) return errno;
-
- /* Loop and add data */
- start_iterate_event(event);
- while((item = iterate_event(event)) != (struct event_item *)(NULL)) {
-
- DEBUG_STRING("file_facility_format","Top of the item processing loop");
-
- /* Check the size and increase memory if needed */
- /* Expect more than one byte to express nesting */
- item_len = util_get_item_len(item) + 2 * abs(item->nest_level - nest_level) + 2 * nest_level + 1;
-
- DEBUG_NUMBER("expected item length",item_len);
-
- if(item_len+length >= size) {
- size+=EL_FILE_BLOCK_SIZE;
- DEBUG_NUMBER("expanding data to the given size",size);
- event_data->buffer = realloc(event_data->buffer,size);
- if(event_data->buffer == NULL) return errno;
- }
-
- DEBUG_NUMBER("current nesting",nest_level);
- DEBUG_NUMBER("item nesting",item->nest_level);
-
- /* Add nesting closing parenteces */
- cnt = 0;
- while((item->nest_level + cnt) < nest_level) {
- *(event_data->buffer+length)=')';
- cnt++;
- length++;
- }
-
- /* Add nesting open parenteces */
- if(item->nest_level > nest_level) {
- *(event_data->buffer+length)=' ';
- length++;
- *(event_data->buffer+length)='(';
- length++;
- first = 0;
- }
- else {
- /* Add comma between items */
- if(first) first = 0;
- else {
- *(event_data->buffer+length)=',';
- length++;
- }
- }
-
- /* Add property data pair */
- util_add_data(event_data->buffer, &length, item);
-
-#ifdef ELAPI_LOG_DEBUG
- *(event_data->buffer+length)='\0';
-#endif
- DEBUG_STRING("Output",event_data->buffer);
-
-
- nest_level = item->nest_level;
+ struct syslog_event *event_storage;
+ struct syslog_conf *config;
+ struct collection_item *item;
+ int error = EOK;
+
+ DEBUG_STRING("syslog_sink_format","Entry");
+ DEBUG_NUMBER("DBLOCK in format",dblock);
+ DEBUG_NUMBER("internal data in format",dblock->internal_data);
+
+ event_storage = (struct syslog_event *)(dblock->internal_data);
+ config = (struct syslog_conf *)(dblock->config);
+
+ event_storage->priority = config->level | config->facility;
+
+ /* Get Priority */
+ error = get_item(event,"priority",ELAPI_TYPE_INTEGER,ELAPI_TRAVERSE_ONELEVEL, &item);
+ if(error) {
+ DEBUG_NUMBER("Failed to get item from collection",error);
+ /* Fall through */
+ } else if((item != (struct collection_item *)(NULL)) &&
+ (item->type == ELAPI_TYPE_INTEGER))
+ 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(error) {
+ DEBUG_NUMBER("traverse_collection returned error",error);
+ return error;
}
- /* Add nesting closing parenteces */
- cnt = 0;
- while(cnt < nest_level) {
- *(event_data->buffer+length)=')';
- cnt++;
- length++;
- }
-
- DEBUG_STRING("file_facility_format","Exit point");
-
- return 0;
+ DEBUG_STRING("syslog_sink_format","Exit");
+ return EOK;
}
-/* Cleanup per event internal data */
-void file_facility_cleanup(struct data_descriptor *dblock)
-{
- struct file_event_data *event_data;
-
- DEBUG_STRING("file_facility_cleanup","Entry point");
- if(dblock->event_data != NULL) {
- event_data = (struct file_event_data *)(dblock->event_data);
- if(event_data->buffer != NULL) {
- free(event_data->buffer);
- event_data->buffer = NULL;
- }
- }
- DEBUG_STRING("file_facility_cleanup","Exit point");
-}
-
-/* Logging calback */
-int file_facility_log(struct data_descriptor *dblock)
+/* Cleanup per event internal data after a failure */
+static void syslog_sink_cleanup(struct data_descriptor *dblock)
{
- struct file_event_data *event_data;
- struct file_config *cfg;
+ struct syslog_event *event_storage;
+ struct syslog_conf *config;
- DEBUG_STRING("file_facility_log","Entry point");
-
- errno = 0;
+ DEBUG_STRING("syslog_sink_cleanup","Entry");
- cfg = (struct file_config *)(dblock->config);
+ event_storage = (struct syslog_event *)(dblock->internal_data);
+ config = (struct syslog_conf *)(dblock->config);
- /* Open file if needed */
- if((cfg->path != NULL) && (cfg->mode & EL_FILE_OPEN_PER_CMD)) {
- cfg->ff = fopen(cfg->path,"a");
- if(cfg->ff == (FILE *)(NULL)) return errno;
+ if(event_storage->sd.buffer != NULL) {
+ free(event_storage->sd.buffer);
+ event_storage->sd.buffer = NULL;
+ event_storage->sd.size = 0;
+ event_storage->sd.length = 0;
+ event_storage->sd.nest_level = 0;
+ event_storage->priority = config->level | config->facility;
}
- event_data = (struct file_event_data *)(dblock->event_data);
- fprintf(cfg->ff,"%s\n",event_data->buffer);
+ DEBUG_STRING("syslog_sink_cleanup","Exit");
+}
- /* Close file if needed */
- if((cfg->path != NULL) && (cfg->mode & EL_FILE_OPEN_PER_CMD)) {
- fclose(cfg->ff);
- cfg->ff = (FILE *)(NULL);
+/* Close facility */
+static void syslog_sink_close(struct data_descriptor *dblock)
+{
+ struct syslog_conf *config;
+
+ DEBUG_STRING("syslog_sink_close","Entry");
+
+ if(dblock->internal_data != NULL) {
+ syslog_sink_cleanup(dblock);
+ free(dblock->internal_data);
+ config = (struct syslog_conf *)(dblock->config);
+ if(config->ident != NULL) free(config->ident);
+ free(dblock->config);
+ dblock->internal_data=NULL;
+ dblock->config=NULL;
}
- DEBUG_STRING("file_facility_log","Exit point");
- return 0;
+ closelog();
+ DEBUG_STRING("Closed syslog","");
+ if(instance) instance--;
+ DEBUG_NUMBER("syslog instance",instance);
+ DEBUG_STRING("syslog_sink_close","Exit");
}
-/* Close facility */
-void file_facility_close(struct data_descriptor *dblock)
+
+/* Logging calback */
+static int syslog_sink_submit(struct data_descriptor *dblock)
{
- struct file_config *cfg;
- struct file_event_data *event_data;
+ struct syslog_event *event_storage;
- DEBUG_STRING("file_facility_close","Entry point");
+ DEBUG_STRING("syslog_sink_submit","Entry");
+ DEBUG_NUMBER("DBLOCK in submit",dblock);
+ DEBUG_NUMBER("internal data in submit",dblock->internal_data);
- /* Close file if needed */
- cfg = (struct file_config *)(dblock->config);
- if((cfg->path != NULL) && (cfg->ff != (FILE *)(NULL))) {
- fclose(cfg->ff);
- cfg->ff = (FILE *)(NULL);
- }
+ event_storage = (struct syslog_event *)(dblock->internal_data);
+
+ DEBUG_STRING("OUTPUT:",event_storage->sd.buffer);
- /* Clean internal data storage */
- if(dblock->event_data != NULL) {
- event_data = (struct file_event_data *)(dblock->event_data);
- if(event_data->buffer != NULL) free(event_data->buffer);
- free(event_data);
- dblock->event_data = NULL;
- }
+ syslog(event_storage->priority, "%s", event_storage->sd.buffer);
+
+ syslog_sink_cleanup(dblock);
- DEBUG_STRING("file_facility_close","Exit point");
+ DEBUG_STRING("syslog_sink_submit","Exit");
+ return EOK;
}
+/* Return a filled in structure */
+void get_sink_info(struct sink_capability *sink_cpb_block)
+{
+ DEBUG_STRING("get_sink_info","Entry");
+
+ sink_cpb_block->retry_interval = SYSLOG_RETRY;
+ sink_cpb_block->flags = SINK_FLAG_LOAD_SINGLE;
+ sink_cpb_block->instance = instance;
+ sink_cpb_block->init_cb = syslog_sink_init;
+ sink_cpb_block->cleanup_cb = syslog_sink_cleanup;
+ sink_cpb_block->format_cb = syslog_sink_format;
+ sink_cpb_block->submit_cb = syslog_sink_submit;
+ sink_cpb_block->close_cb = syslog_sink_close;
+
+ DEBUG_STRING("get_sink_info","Exit");
+}
diff --git a/sinks/stderr/elapi_sink_stderr.c b/sinks/stderr/elapi_sink_stderr.c
index 5f5555c..7bd5bf8 100644
--- a/sinks/stderr/elapi_sink_stderr.c
+++ b/sinks/stderr/elapi_sink_stderr.c
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Implemenation of the stderr sink.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <errno.h>
diff --git a/sinks/syslog/elapi_sink_syslog.c b/sinks/syslog/elapi_sink_syslog.c
index 4d39838..e1500b5 100644
--- a/sinks/syslog/elapi_sink_syslog.c
+++ b/sinks/syslog/elapi_sink_syslog.c
@@ -1,4 +1,22 @@
-/* Copyright */
+/*
+ ELAPI
+
+ Implemenation of the syslog sink.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdio.h>
#include <errno.h>