summaryrefslogtreecommitdiff
path: root/cel
diff options
context:
space:
mode:
Diffstat (limited to 'cel')
-rw-r--r--cel/cel_custom.c15
-rw-r--r--cel/cel_manager.c17
-rw-r--r--cel/cel_odbc.c23
-rw-r--r--cel/cel_pgsql.c14
-rw-r--r--cel/cel_radius.c12
-rw-r--r--cel/cel_sqlite3_custom.c12
-rw-r--r--cel/cel_tds.c13
7 files changed, 41 insertions, 65 deletions
diff --git a/cel/cel_custom.c b/cel/cel_custom.c
index 871408716..0f72bd6ce 100644
--- a/cel/cel_custom.c
+++ b/cel/cel_custom.c
@@ -64,7 +64,7 @@ struct cel_config {
AST_RWLIST_ENTRY(cel_config) list;
};
-static struct ast_event_sub *event_sub = NULL;
+#define CUSTOM_BACKEND_NAME "CEL Custom CSV Logging"
static AST_RWLIST_HEAD_STATIC(sinks, cel_config);
@@ -116,7 +116,7 @@ static int load_config(void)
return res;
}
-static void custom_log(const struct ast_event *event, void *userdata)
+static void custom_log(struct ast_event *event)
{
struct ast_channel *dummy;
struct ast_str *str;
@@ -167,19 +167,15 @@ static void custom_log(const struct ast_event *event, void *userdata)
static int unload_module(void)
{
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
if (AST_RWLIST_WRLOCK(&sinks)) {
- event_sub = ast_event_subscribe(AST_EVENT_CEL, custom_log, "CEL Custom CSV Logging",
- NULL, AST_EVENT_IE_END);
ast_log(LOG_ERROR, "Unable to lock sink list. Unload failed.\n");
return -1;
}
free_config();
AST_RWLIST_UNLOCK(&sinks);
+ ast_cel_backend_unregister(CUSTOM_BACKEND_NAME);
return 0;
}
@@ -193,8 +189,9 @@ static enum ast_module_load_result load_module(void)
load_config();
AST_RWLIST_UNLOCK(&sinks);
- event_sub = ast_event_subscribe(AST_EVENT_CEL, custom_log, "CEL Custom CSV Logging",
- NULL, AST_EVENT_IE_END);
+ if (ast_cel_backend_register(CUSTOM_BACKEND_NAME, custom_log)) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
return AST_MODULE_LOAD_SUCCESS;
}
diff --git a/cel/cel_manager.c b/cel/cel_manager.c
index 245c7800d..2fc001fe1 100644
--- a/cel/cel_manager.c
+++ b/cel/cel_manager.c
@@ -57,12 +57,12 @@ static int enablecel;
/*! \brief show_user_def is off by default */
#define CEL_SHOW_USERDEF_DEFAULT 0
+#define MANAGER_BACKEND_NAME "Manager Event Logging"
+
/*! TRUE if we should set the EventName header to USER_DEFINED on user events. */
static unsigned char cel_show_user_def;
-static struct ast_event_sub *event_sub;
-
-static void manager_log(const struct ast_event *event, void *userdata)
+static void manager_log(struct ast_event *event)
{
struct ast_tm timeresult;
char start_time[80] = "";
@@ -180,12 +180,9 @@ static int load_config(int reload)
cel_show_user_def = new_cel_show_user_def;
if (enablecel && !newenablecel) {
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
+ ast_cel_backend_unregister(MANAGER_BACKEND_NAME);
} else if (!enablecel && newenablecel) {
- event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, "Manager Event Logging", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
+ if (ast_cel_backend_register(MANAGER_BACKEND_NAME, manager_log)) {
ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
}
}
@@ -196,9 +193,7 @@ static int load_config(int reload)
static int unload_module(void)
{
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
+ ast_cel_backend_unregister(MANAGER_BACKEND_NAME);
return 0;
}
diff --git a/cel/cel_odbc.c b/cel/cel_odbc.c
index 933d9e344..69066c162 100644
--- a/cel/cel_odbc.c
+++ b/cel/cel_odbc.c
@@ -51,7 +51,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#define CONFIG "cel_odbc.conf"
-static struct ast_event_sub *event_sub = NULL;
+
+#define ODBC_BACKEND_NAME "ODBC CEL backend"
/*! \brief show_user_def is off by default */
#define CEL_SHOW_USERDEF_DEFAULT 0
@@ -367,7 +368,7 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
} \
} while (0)
-static void odbc_log(const struct ast_event *event, void *userdata)
+static void odbc_log(struct ast_event *event)
{
struct tables *tableptr;
struct columns *entry;
@@ -789,18 +790,12 @@ early_release:
static int unload_module(void)
{
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
if (AST_RWLIST_WRLOCK(&odbc_tables)) {
- event_sub = ast_event_subscribe(AST_EVENT_CEL, odbc_log, "ODBC CEL backend", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
- ast_log(LOG_ERROR, "Unable to subscribe to CEL events\n");
- }
ast_log(LOG_ERROR, "Unable to lock column list. Unload failed.\n");
return -1;
}
+ ast_cel_backend_unregister(ODBC_BACKEND_NAME);
free_config();
AST_RWLIST_UNLOCK(&odbc_tables);
AST_RWLIST_HEAD_DESTROY(&odbc_tables);
@@ -814,13 +809,13 @@ static int load_module(void)
if (AST_RWLIST_WRLOCK(&odbc_tables)) {
ast_log(LOG_ERROR, "Unable to lock column list. Load failed.\n");
- return 0;
+ return AST_MODULE_LOAD_FAILURE;
}
load_config();
AST_RWLIST_UNLOCK(&odbc_tables);
- event_sub = ast_event_subscribe(AST_EVENT_CEL, odbc_log, "ODBC CEL backend", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
+ if (ast_cel_backend_register(ODBC_BACKEND_NAME, odbc_log)) {
ast_log(LOG_ERROR, "Unable to subscribe to CEL events\n");
+ return AST_MODULE_LOAD_FAILURE;
}
return AST_MODULE_LOAD_SUCCESS;
}
@@ -829,7 +824,7 @@ static int reload(void)
{
if (AST_RWLIST_WRLOCK(&odbc_tables)) {
ast_log(LOG_ERROR, "Unable to lock column list. Reload failed.\n");
- return -1;
+ return AST_MODULE_LOAD_FAILURE;
}
free_config();
@@ -838,7 +833,7 @@ static int reload(void)
return AST_MODULE_LOAD_SUCCESS;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "ODBC CEL backend",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, ODBC_BACKEND_NAME,
.load = load_module,
.unload = unload_module,
.reload = reload,
diff --git a/cel/cel_pgsql.c b/cel/cel_pgsql.c
index 0a393a6ca..5ba5b9972 100644
--- a/cel/cel_pgsql.c
+++ b/cel/cel_pgsql.c
@@ -58,6 +58,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define DATE_FORMAT "%Y-%m-%d %T.%6q"
+#define PGSQL_BACKEND_NAME "CEL PGSQL backend"
+
static char *config = "cel_pgsql.conf";
static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL;
static int connected = 0;
@@ -73,7 +75,6 @@ AST_MUTEX_DEFINE_STATIC(pgsql_lock);
static PGconn *conn = NULL;
static PGresult *result = NULL;
-static struct ast_event_sub *event_sub = NULL;
struct columns {
char *name;
@@ -113,7 +114,7 @@ static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
} \
} while (0)
-static void pgsql_log(const struct ast_event *event, void *userdata)
+static void pgsql_log(struct ast_event *event)
{
struct ast_tm tm;
char timestr[128];
@@ -346,10 +347,7 @@ static int my_unload_module(void)
{
struct columns *current;
AST_RWLIST_WRLOCK(&psql_columns);
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- event_sub = NULL;
- }
+ ast_cel_backend_unregister(PGSQL_BACKEND_NAME);
if (conn) {
PQfinish(conn);
conn = NULL;
@@ -561,9 +559,7 @@ static int my_load_module(int reload)
process_my_load_module(cfg);
ast_config_destroy(cfg);
- event_sub = ast_event_subscribe(AST_EVENT_CEL, pgsql_log, "CEL PGSQL backend", NULL, AST_EVENT_IE_END);
-
- if (!event_sub) {
+ if (ast_cel_backend_register(PGSQL_BACKEND_NAME, pgsql_log)) {
ast_log(LOG_WARNING, "Unable to subscribe to CEL events for pgsql\n");
return AST_MODULE_LOAD_DECLINE;
}
diff --git a/cel/cel_radius.c b/cel/cel_radius.c
index 9067a0491..be5a9e66f 100644
--- a/cel/cel_radius.c
+++ b/cel/cel_radius.c
@@ -84,7 +84,8 @@ static char radiuscfg[PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf";
static struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD };
static rc_handle *rh = NULL;
-static struct ast_event_sub *event_sub = NULL;
+
+#define RADIUS_BACKEND_NAME "CEL Radius Logging"
#define ADD_VENDOR_CODE(x,y) (rc_avpair_add(rh, send, x, &y, strlen(y), VENDOR_CODE))
@@ -174,7 +175,7 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cel_event_record *r
return 0;
}
-static void radius_log(const struct ast_event *event, void *userdata)
+static void radius_log(struct ast_event *event)
{
int result = ERROR_RC;
VALUE_PAIR *send = NULL;
@@ -204,9 +205,7 @@ return_cleanup:
static int unload_module(void)
{
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
+ ast_cel_backend_unregister(RADIUS_BACKEND_NAME);
if (rh) {
rc_destroy(rh);
rh = NULL;
@@ -256,8 +255,7 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
- event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
+ if (ast_cel_backend_register(RADIUS_BACKEND_NAME, radius_log)) {
rc_destroy(rh);
rh = NULL;
return AST_MODULE_LOAD_DECLINE;
diff --git a/cel/cel_sqlite3_custom.c b/cel/cel_sqlite3_custom.c
index 6c4a82226..8ff3bd702 100644
--- a/cel/cel_sqlite3_custom.c
+++ b/cel/cel_sqlite3_custom.c
@@ -57,6 +57,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/options.h"
#include "asterisk/stringfields.h"
+#define SQLITE_BACKEND_NAME "CEL sqlite3 custom backend"
+
AST_MUTEX_DEFINE_STATIC(lock);
static const char config_file[] = "cel_sqlite3_custom.conf";
@@ -69,7 +71,6 @@ static char table[80];
* \bug Handling of this var is crash prone on reloads
*/
static char *columns;
-static struct ast_event_sub *event_sub = NULL;
struct values {
char *expression;
@@ -229,7 +230,7 @@ static void free_config(void)
}
}
-static void write_cel(const struct ast_event *event, void *userdata)
+static void write_cel(struct ast_event *event)
{
char *error = NULL;
char *sql = NULL;
@@ -293,9 +294,7 @@ static void write_cel(const struct ast_event *event, void *userdata)
static int unload_module(void)
{
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
+ ast_cel_backend_unregister(SQLITE_BACKEND_NAME);
free_config();
@@ -339,8 +338,7 @@ static int load_module(void)
}
}
- event_sub = ast_event_subscribe(AST_EVENT_CEL, write_cel, "CEL sqlite3 custom backend", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
+ if (ast_cel_backend_register(SQLITE_BACKEND_NAME, write_cel)) {
ast_log(LOG_ERROR, "Unable to register custom SQLite3 CEL handling\n");
free_config();
return AST_MODULE_LOAD_DECLINE;
diff --git a/cel/cel_tds.c b/cel/cel_tds.c
index 1bb4d517e..0f8c8ad9a 100644
--- a/cel/cel_tds.c
+++ b/cel/cel_tds.c
@@ -81,9 +81,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define DATE_FORMAT "%Y/%m/%d %T"
-static char *config = "cel_tds.conf";
+#define TDS_BACKEND_NAME "CEL TDS logging backend"
-static struct ast_event_sub *event_sub = NULL;
+static char *config = "cel_tds.conf";
struct cel_tds_config {
AST_DECLARE_STRING_FIELDS(
@@ -112,7 +112,7 @@ static int execute_and_consume(DBPROCESS *dbproc, const char *fmt, ...)
static int mssql_connect(void);
static int mssql_disconnect(void);
-static void tds_log(const struct ast_event *event, void *userdata)
+static void tds_log(struct ast_event *event)
{
char start[80];
char *accountcode_ai, *clidnum_ai, *exten_ai, *context_ai, *clid_ai, *channel_ai, *app_ai, *appdata_ai, *uniqueid_ai, *linkedid_ai, *cidani_ai, *cidrdnis_ai, *ciddnid_ai, *peer_ai, *userfield_ai;
@@ -397,9 +397,7 @@ failed:
static int tds_unload_module(void)
{
- if (event_sub) {
- event_sub = ast_event_unsubscribe(event_sub);
- }
+ ast_cel_backend_unregister(TDS_BACKEND_NAME);
if (settings) {
ast_mutex_lock(&tds_lock);
@@ -561,8 +559,7 @@ static int load_module(void)
}
/* Register MSSQL CEL handler */
- event_sub = ast_event_subscribe(AST_EVENT_CEL, tds_log, "CEL TDS logging backend", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
+ if (ast_cel_backend_register(TDS_BACKEND_NAME, tds_log)) {
ast_log(LOG_ERROR, "Unable to register MSSQL CEL handling\n");
ast_string_field_free_memory(settings);
ast_free(settings);