From c20626a18afc1545f1fbc58907529ba743bb0843 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Thu, 26 Feb 2009 16:36:49 -0500 Subject: Added missing files and removed dups. --- dispatcher/elapi_api.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 dispatcher/elapi_api.c (limited to 'dispatcher/elapi_api.c') diff --git a/dispatcher/elapi_api.c b/dispatcher/elapi_api.c new file mode 100644 index 0000000..b89ac7d --- /dev/null +++ b/dispatcher/elapi_api.c @@ -0,0 +1,115 @@ +/* + ELAPI + + Module implements high level API for logging events + + Copyright (C) Dmitri Pal 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 . +*/ + + +#include +#include +#include +#include +#include +#include +#include "elapi_debug.h" +#include "elapi_dispatcher.h" +#include "elapi_collection.h" +#include "elapi_sink.h" + +const char event_name[] = "event"; + +/* Pointer to default global dispatcher */ +struct dispatcher_handle *global_dispatcher = (struct dispatcher_handle *)(NULL); + + +/* Function to open audit using default routing functions */ +/* If appname is NULL - uses module name */ +int open_audit(const char *appname, char **desired_sinks) +{ + int error; + + DEBUG_STRING("open_audit","Entry"); + + error = create_audit_dispatcher(&global_dispatcher,appname,desired_sinks,NULL,NULL); + + DEBUG_NUMBER("open_audit Exit:",error); + return error; +} + +/* Function to open audit using custom routing function */ +int open_audit_with_router(const char *appname, + char **desired_sinks, + event_router_fn desired_router, + void *custom_data) +{ + int error; + + DEBUG_STRING("open_audit_with_router","Entry"); + + error = create_audit_dispatcher(&global_dispatcher,appname,desired_sinks,desired_router,custom_data); + + DEBUG_NUMBER("open_audit_with_router Exit:",error); + return error; +} + + +/* Get dispatcher if you want to add sink to a default deispatcher or do some advaced operations */ +struct dispatcher_handle *get_dispatcher(void) +{ + DEBUG_STRING("get_dispatcher was called.","Returning default dispatcher."); + return global_dispatcher; +} + +/* Close audit */ +void close_audit(void) +{ + DEBUG_STRING("close_audit","Entry"); + + destroy_audit_dispatcher(global_dispatcher); + + DEBUG_STRING("close_audit","Exit"); +} + +/* Creates collection with the timestamp already prepopulated */ +int create_event(struct collection_item **event,char *name) +{ + int error; + char *nm; + + DEBUG_STRING("create_event","Entry"); + + if(name == NULL) nm = event_name; + else nm = name; + + /* Construct collection and add timestamp */ + if(((error = create_collection(event,nm)) != 0) || + ((error = set_timestamp(*event,NULL,NULL)) !=0 )) { + DEBUG_NUMBER("Failed to create event:",error); + return error; + } + + DEBUG_STRING("create_event Exit:",""); + return EOK; + +} + +/* Log event */ +void log_event(char *format_string,struct collection_item *event) +{ + DEBUG_STRING("log_event","Entry"); + log_audit_event(global_dispatcher, event, format_string); + DEBUG_STRING("log_event","Entry"); +} -- cgit