summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-02-24 17:49:02 -0500
committerDmitri Pal <dpal@redhat.com>2009-02-24 17:49:02 -0500
commit78c5ff376dd37462fad9a2194e4ee4931dcbc473 (patch)
treecc99f4c16be76362f0b934cea688fd5a21d0a6de
parent27d15caafe401160fcc62829a3460a52cd45d429 (diff)
downloadelapi_draft-78c5ff376dd37462fad9a2194e4ee4931dcbc473.tar.gz
elapi_draft-78c5ff376dd37462fad9a2194e4ee4931dcbc473.tar.xz
elapi_draft-78c5ff376dd37462fad9a2194e4ee4931dcbc473.zip
Fixing unittest. Fininshing with submit to syslog.
-rw-r--r--collection/elapi_collection.c25
-rw-r--r--collection/elapi_collection.h12
-rw-r--r--collection/elapi_debug.h9
-rw-r--r--dispatcher/elapi_dispatcher_ut.c30
-rw-r--r--ini/elapi_ini.c13
-rw-r--r--sinks/syslog/elapi_sink_syslog.c31
6 files changed, 102 insertions, 18 deletions
diff --git a/collection/elapi_collection.c b/collection/elapi_collection.c
index 2654edd..f2614a6 100644
--- a/collection/elapi_collection.c
+++ b/collection/elapi_collection.c
@@ -12,6 +12,7 @@
#define ELAPI_ACTION_FIND 1
#define ELAPI_ACTION_DEL 2
#define ELAPI_ACTION_UPDATE 3
+#define ELAPI_ACTION_GET 4
/* Special internal error code to indicate that collection search was interrupted */
@@ -862,6 +863,10 @@ static int act_traverse_handler(struct collection_item *head,
}
break;
+ case ELAPI_ACTION_GET:
+ DEBUG_STRING("It is a get action.","");
+ if(custom_data != NULL) *((struct collection_item **)(custom_data)) = current;
+ break;
case ELAPI_ACTION_DEL:
DEBUG_STRING("It is a delete action.","");
/* Make sure we tell the caller we found a match */
@@ -1237,7 +1242,6 @@ int get_collection_reference(struct collection_item *ci, /* High level
}
-
/* ADDITION */
/* Add collection to collection */
@@ -1430,6 +1434,25 @@ int get_item_and_do(struct collection_item *ci, /* Collection to find thin
return error;
}
+
+/* Get raw item */
+int get_item(struct collection_item *ci, /* Collection to find things in */
+ char *property_to_find, /* Name to match */
+ int type, /* Type filter */
+ int mode_flags, /* How to traverse the collection */
+ struct collection_item **item) /* Found item */
+{
+
+ int error = EOK;
+
+ DEBUG_STRING("get_item","Entry.");
+
+ error = find_item_and_do(ci,property_to_find,type,mode_flags,NULL,(void *)(item),ELAPI_ACTION_GET);
+
+ DEBUG_NUMBER("get_item returning",error);
+ return error;
+}
+
/* DELETE */
/* Delete property from the collection */
int delete_property(struct collection_item *ci, /* Collection to find things in */
diff --git a/collection/elapi_collection.h b/collection/elapi_collection.h
index 129b83a..9b9e8c3 100644
--- a/collection/elapi_collection.h
+++ b/collection/elapi_collection.h
@@ -172,6 +172,18 @@ int get_item_and_do(struct collection_item *ci, /* Collection to find thin
item_fn item_handler, /* Function to call when the item is found */
void *custom_data); /* Custom data passed around */
+/* Convenience function to get individual item */
+/* Caller should be aware that this is not a copy of the item
+ * but the pointer to actual item stored in the collection.
+ * The retuned pointer should never be altered or freed by caller of the function.
+ * The caller should be sure that the collection does not go out of scope
+ * while the pointer to its data is in use. */
+int get_item(struct collection_item *ci, /* Collection to find things in */
+ char *property_to_find, /* Name to match */
+ int type, /* Type filter */
+ int mode_flags, /* How to traverse the collection */
+ struct collection_item **item); /* Found item */
+
/* Delete property from the collection */
int delete_property(struct collection_item *ci, /* Collection to find things in */
char *property_to_find, /* Name to match */
diff --git a/collection/elapi_debug.h b/collection/elapi_debug.h
index 3da0685..5f2c174 100644
--- a/collection/elapi_debug.h
+++ b/collection/elapi_debug.h
@@ -31,5 +31,14 @@
#define DEBUG_ASSERT(expression) ;
#endif
+#ifdef ELAPI_LOG_DEBUG
+#ifdef ELAPI_TOOLS_H
+#define DEBUG_COLLECTION(collection) debug_collection(collection,ELAPI_TRAVERSE_DEFAULT);
+#else
+#define DEBUG_COLLECTION(collection) ;
+#endif
+#else
+#define DEBUG_COLLECTION(collection) ;
+#endif
#endif
diff --git a/dispatcher/elapi_dispatcher_ut.c b/dispatcher/elapi_dispatcher_ut.c
index 119d40a..eec045b 100644
--- a/dispatcher/elapi_dispatcher_ut.c
+++ b/dispatcher/elapi_dispatcher_ut.c
@@ -164,27 +164,47 @@ int main()
else printf("Expected failure. Error : %d\n",error);
/* Adding new */
- error = alter_audit_dispatcher(dispatcher,"far2",ELAPI_SINK_ACTION_ADD);
+ error = alter_audit_dispatcher(dispatcher,"syslog",ELAPI_SINK_ACTION_ADD);
+ if(error != 0) printf("Expected success got failure %d\n",error);
+ else printf("Success : %d\n",error);
+
+ /* Delete */
+ error = alter_audit_dispatcher(dispatcher,"stderr",ELAPI_SINK_ACTION_DELETE);
if(error != 0) printf("Expected success got failure %d\n",error);
else printf("Success : %d\n",error);
/* Enable */
- error = alter_audit_dispatcher(dispatcher,"far2",ELAPI_SINK_ACTION_ENABLE);
+ error = alter_audit_dispatcher(dispatcher,"syslog",ELAPI_SINK_ACTION_ENABLE);
if(error != 0) printf("Expected success got failure %d\n",error);
else printf("Success : %d\n",error);
+ /* Log event into syslog */
+ printf("%s","=================\nLogging peer - expect success\n");
+ print_collection(peer);
+ log_audit_event(dispatcher, peer);
+ printf("%s","=================\nLogging host - expect success\n");
+ print_collection(host);
+ log_audit_event(dispatcher, host);
+ printf("%s","=================\nLogging socket - expect success\n");
+ print_collection(socket);
+ log_audit_event(dispatcher, socket);
+ printf("%s","=================\nLogging event - expect success\n");
+ print_collection(event);
+ log_audit_event(dispatcher, event);
+
+
/* Pulse */
- error = alter_audit_dispatcher(dispatcher,"far2",ELAPI_SINK_ACTION_PULSE);
+ error = alter_audit_dispatcher(dispatcher,"syslog",ELAPI_SINK_ACTION_PULSE);
if(error != 0) printf("Expected success got failure %d\n",error);
else printf("Success : %d\n",error);
/* Disable */
- error = alter_audit_dispatcher(dispatcher,"far2",ELAPI_SINK_ACTION_DISABLE);
+ error = alter_audit_dispatcher(dispatcher,"syslog",ELAPI_SINK_ACTION_DISABLE);
if(error != 0) printf("Expected success got failure %d\n",error);
else printf("Success : %d\n",error);
/* Delete */
- error = alter_audit_dispatcher(dispatcher,"far2",ELAPI_SINK_ACTION_DELETE);
+ error = alter_audit_dispatcher(dispatcher,"syslog",ELAPI_SINK_ACTION_DELETE);
if(error != 0) printf("Expected success got failure %d\n",error);
else printf("Success : %d\n",error);
diff --git a/ini/elapi_ini.c b/ini/elapi_ini.c
index ed6b4c7..52af8dc 100644
--- a/ini/elapi_ini.c
+++ b/ini/elapi_ini.c
@@ -6,8 +6,9 @@
#include <ctype.h>
#include <stdlib.h>
#include "elapi_collection.h"
-#include "elapi_debug.h"
#include "elapi_ini.h"
+#include "elapi_tools.h"
+#include "elapi_debug.h"
/* STATIC INTERNAL FUNCTIONS */
@@ -526,7 +527,12 @@ int ini_to_collection(char *filename, struct collection_item *ini_config)
/* Close file */
fclose(file);
+
+ DEBUG_COLLECTION(ini_config);
+
destroy_collection(current_section);
+
+ DEBUG_COLLECTION(ini_config);
DEBUG_STRING("ini_to_collection", "Success Exit");
@@ -602,6 +608,9 @@ int get_value_from_config(void *value,
if(section == NULL) to_find = default_section;
else to_find = section;
+ DEBUG_STRING("Getting Name:", name);
+ DEBUG_STRING("In Section:", section);
+
/* Get Subcollection */
error = get_collection_reference(ini_config,&section_handle,to_find);
if(section_handle == (struct collection_item *)(NULL)) {
@@ -611,7 +620,7 @@ int get_value_from_config(void *value,
}
/* If we have the section then get the data */
- error = get_item_and_do(ini_config, name,type, ELAPI_TRAVERSE_ONELEVEL, value_extractor, value);
+ error = get_item_and_do(section_handle, name,type, ELAPI_TRAVERSE_ONELEVEL, value_extractor, value);
DEBUG_STRING("get_value_from_config", "Exit");
return error;
diff --git a/sinks/syslog/elapi_sink_syslog.c b/sinks/syslog/elapi_sink_syslog.c
index cd20597..c9931a8 100644
--- a/sinks/syslog/elapi_sink_syslog.c
+++ b/sinks/syslog/elapi_sink_syslog.c
@@ -12,8 +12,13 @@
/* FIXME - this should be taken from the config.h generated by autotools */
#define SYSLOG_RETRY 60
-#define syslog_audit_config "/etc/elapi/syslog_defaults.conf"
-#define syslog_audit_dir "/etc/elapi/syslog_defaults.d"
+/*
+#define SYSLOG_AUDIT_CONFIG "/etc/elapi/syslog_defaults.conf"
+#define SYSLOG_AUDIT_DIR "/etc/elapi/syslog_defaults.d"
+*/
+#define SYSLOG_AUDIT_CONFIG "/home/dpal/IPA/Code/elapi/etc/syslog_defaults.conf"
+#define SYSLOG_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.
@@ -57,7 +62,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, &file_config);
conf_data->option = LOG_ODELAY;
conf_data->facility = LOG_USER;
@@ -178,7 +183,7 @@ static int syslog_sink_format(struct data_descriptor *dblock,struct collection_i
{
struct syslog_event *event_storage;
struct syslog_conf *config;
-
+ struct collection_item *item;
int error = EOK;
DEBUG_STRING("syslog_sink_format","Entry");
@@ -190,9 +195,17 @@ static int syslog_sink_format(struct data_descriptor *dblock,struct collection_i
event_storage->priority = config->level | config->facility;
- /* FIXME form priority here */
+ /* 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 */
@@ -256,18 +269,16 @@ static void syslog_sink_close(struct data_descriptor *dblock)
static int syslog_sink_submit(struct data_descriptor *dblock)
{
struct syslog_event *event_storage;
- struct syslog_conf *config;
DEBUG_STRING("syslog_sink_submit","Entry");
DEBUG_NUMBER("DBLOCK in submit",dblock);
DEBUG_NUMBER("internal data in submit",dblock->internal_data);
event_storage = (struct syslog_event *)(dblock->internal_data);
- config = (struct syslog_conf *)(dblock->config);
-
+
DEBUG_STRING("OUTPUT:",event_storage->sd.buffer);
- fprintf(stderr,"%s %d %s\n",config->ident, event_storage->priority, event_storage->sd.buffer);
+ syslog(event_storage->priority, "%s", event_storage->sd.buffer);
syslog_sink_cleanup(dblock);