[svn-commits] murf: branch murf/newcdr r62091 - /team/murf/newcdr/cel/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Apr 26 15:06:54 MST 2007


Author: murf
Date: Thu Apr 26 17:06:53 2007
New Revision: 62091

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62091
Log:
step 1: adjust all the backends to do event stuff; next step, redo all the vars

Modified:
    team/murf/newcdr/cel/Makefile
    team/murf/newcdr/cel/cel_csv.c
    team/murf/newcdr/cel/cel_custom.c
    team/murf/newcdr/cel/cel_manager.c
    team/murf/newcdr/cel/cel_odbc.c
    team/murf/newcdr/cel/cel_pgsql.c
    team/murf/newcdr/cel/cel_radius.c
    team/murf/newcdr/cel/cel_sqlite.c
    team/murf/newcdr/cel/cel_sqlite3_custom.c
    team/murf/newcdr/cel/cel_tds.c

Modified: team/murf/newcdr/cel/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/Makefile?view=diff&rev=62091&r1=62090&r2=62091
==============================================================================
--- team/murf/newcdr/cel/Makefile (original)
+++ team/murf/newcdr/cel/Makefile Thu Apr 26 17:06:53 2007
@@ -1,7 +1,7 @@
 #
 # Asterisk -- A telephony toolkit for Linux.
 # 
-# Makefile for CDR backends
+# Makefile for CEL backends
 #
 # Copyright (C) 1999-2006, Digium, Inc.
 #
@@ -11,8 +11,8 @@
 
 -include ../menuselect.makeopts ../menuselect.makedeps
 
-C_MODS:=$(filter-out $(MENUSELECT_CDR),$(patsubst %.c,%,$(wildcard cel_*.c)))
-CC_MODS:=$(filter-out $(MENUSELECT_CDR),$(patsubst %.cc,%,$(wildcard cel_*.cc)))
+C_MODS:=$(filter-out $(MENUSELECT_CEL),$(patsubst %.c,%,$(wildcard cel_*.c)))
+CC_MODS:=$(filter-out $(MENUSELECT_CEL),$(patsubst %.cc,%,$(wildcard cel_*.cc)))
 
 LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
 

Modified: team/murf/newcdr/cel/cel_csv.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_csv.c?view=diff&rev=62091&r1=62090&r2=62091
==============================================================================
--- team/murf/newcdr/cel/cel_csv.c (original)
+++ team/murf/newcdr/cel/cel_csv.c Thu Apr 26 17:06:53 2007
@@ -21,6 +21,7 @@
  * \brief Comma Separated Value CEL records.
  *
  * \author Steve Murphy <murf at digium.com>
+ * much borrowed from cdr code, author Mark Spencer
  * 
  * \arg See also \ref AstCEL
  * \ingroup cel_drivers
@@ -304,17 +305,16 @@
 {
 	if (mf)
 		fclose(mf);
-	if (event_subsc)
+	if (event_sub)
 		ast_event_unsubscribe(event_sub);
-	
-	ast_cel_unregister(name);
+	event_sub = 0;
+	
 	return 0;
 }
 
 static int load_module(void)
 {
 	int res;
-	struct ast_event_sub *subsc;
 	
 	if(!load_config())
 		return AST_MODULE_LOAD_DECLINE;

Modified: team/murf/newcdr/cel/cel_custom.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_custom.c?view=diff&rev=62091&r1=62090&r2=62091
==============================================================================
--- team/murf/newcdr/cel/cel_custom.c (original)
+++ team/murf/newcdr/cel/cel_custom.c Thu Apr 26 17:06:53 2007
@@ -1,11 +1,10 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 2007, Digium, Inc.
  *
- * Mark Spencer <markster at digium.com>
- *
- * Includes code and algorithms from the Zapata library.
+ * Steve Murphy <murf at digium.com>
+ * much borrowed from cdr code, author Mark Spencer
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -20,14 +19,14 @@
 
 /*! \file
  *
- * \brief Custom Comma Separated Value CDR records.
+ * \brief Custom Comma Separated Value CEL records.
  *
- * \author Mark Spencer <markster at digium.com>
+ * \author Steve Murphy <murf at digium.com>
  *
- * \arg See also \ref AstCDR
+ * \arg See also \ref AstCEL
  *
- * Logs in LOG_DIR/cdr_custom
- * \ingroup cdr_drivers
+ * Logs in LOG_DIR/cel_custom
+ * \ingroup cel_drivers
  */
 
 #include "asterisk.h"
@@ -44,25 +43,26 @@
 #include <time.h>
 
 #include "asterisk/channel.h"
-#include "asterisk/cdr.h"
+#include "asterisk/cel.h"
 #include "asterisk/module.h"
 #include "asterisk/config.h"
 #include "asterisk/pbx.h"
 #include "asterisk/logger.h"
 #include "asterisk/utils.h"
 
-#define CUSTOM_LOG_DIR "/cdr_custom"
+#define CUSTOM_LOG_DIR "/cel_custom"
 
 #define DATE_FORMAT "%Y-%m-%d %T"
 
 AST_MUTEX_DEFINE_STATIC(lock);
 
-static char *name = "cdr-custom";
+static char *name = "cel-custom";
 
 static FILE *mf = NULL;
 
 static char master[PATH_MAX];
 static char format[1024]="";
+static struct ast_event_sub event_sub = 0;
 
 static int load_config(int reload) 
 {
@@ -72,7 +72,7 @@
 
 	strcpy(format, "");
 	strcpy(master, "");
-	if((cfg = ast_config_load("cdr_custom.conf"))) {
+	if((cfg = ast_config_load("cel_custom.conf"))) {
 		var = ast_variable_browse(cfg, "mappings");
 		while(var) {
 			ast_mutex_lock(&lock);
@@ -103,20 +103,23 @@
 
 
 
-static int custom_log(struct ast_cdr *cdr)
+static void custom_log(const struct ast_event *event, void *userdata)
 {
 	/* Make sure we have a big enough buf */
 	char buf[2048];
 	struct ast_channel dummy;
+	struct ast_cel *cel;
 
 	/* Abort if no master file is specified */
 	if (ast_strlen_zero(master))
 		return 0;
 
+	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
 	memset(buf, 0 , sizeof(buf));
 	/* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */
+	/* fix this code */
 	memset(&dummy, 0, sizeof(dummy));
-	dummy.cdr = cdr;
+	dummy.cdr = cel;
 	pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1);
 
 	/* because of the absolutely unconditional need for the
@@ -139,21 +142,25 @@
 {
 	if (mf)
 		fclose(mf);
-	ast_cdr_unregister(name);
+	if (event_sub)
+		ast_event_unsubscribe(event_sub);
+	event_sub = 0;
 	return 0;
 }
 
 static int load_module(void)
 {
-	int res = 0;
 
 	if (!load_config(0)) {
-		res = ast_cdr_register(name, ast_module_info->description, custom_log);
-		if (res)
-			ast_log(LOG_ERROR, "Unable to register custom CDR handling\n");
+		event_sub = ast_event_subscribe(AST_EVENT_CEL, custom_log, NULL, AST_EVENT_IE_END);
+
+		if (!event_sub)
+			ast_log(LOG_ERROR, "Unable to register custom CEL handling\n");
 		if (mf)
 			fclose(mf);
-		return res;
+		if (!event_sub)
+			return AST_MODULE_LOAD_DECLINE;
+		return 0;
 	} else 
 		return AST_MODULE_LOAD_DECLINE;
 }
@@ -163,7 +170,7 @@
 	return load_config(1);
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Customizable Comma Separated Values CDR Backend",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Customizable Comma Separated Values CEL Backend",
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,

Modified: team/murf/newcdr/cel/cel_manager.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_manager.c?view=diff&rev=62091&r1=62090&r2=62091
==============================================================================
--- team/murf/newcdr/cel/cel_manager.c (original)
+++ team/murf/newcdr/cel/cel_manager.c Thu Apr 26 17:06:53 2007
@@ -1,7 +1,10 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2004 - 2005
+ * Copyright (C) 2007 Digium, Inc
+ *
+ * Steve Murphy <murf at digium.com>
+ * who freely borrowed code from the cdr equivalents
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -16,13 +19,13 @@
 
 /*! \file
  *
- * \brief Asterisk Call Manager CDR records.
+ * \brief Asterisk Channel Event records.
  * 
  * See also
  * \arg \ref AstCDR
  * \arg \ref AstAMI
  * \arg \ref Config_ami
- * \ingroup cdr_drivers
+ * \ingroup cel_drivers
  */
 
 #include "asterisk.h"
@@ -35,7 +38,7 @@
 #include <time.h>
 
 #include "asterisk/channel.h"
-#include "asterisk/cdr.h"
+#include "asterisk/cel.h"
 #include "asterisk/module.h"
 #include "asterisk/logger.h"
 #include "asterisk/utils.h"
@@ -43,11 +46,12 @@
 #include "asterisk/config.h"
 
 #define DATE_FORMAT 	"%Y-%m-%d %T"
-#define CONF_FILE	"cdr_manager.conf"
+#define CONF_FILE	"cel_manager.conf"
 
-static char *name = "cdr_manager";
+static char *name = "cel_manager";
 
-static int enablecdr = 0;
+static int enablecel = 0;
+static struct ast_event_sub event_sub = 0;
 
 static int loadconfigurationfile(void)
 {
@@ -58,7 +62,7 @@
 	cfg = ast_config_load(CONF_FILE);
 	if (!cfg) {
 		/* Standard configuration */
-		enablecdr = 0;
+		enablecel = 0;
 		return 0;
 	}
 	
@@ -68,7 +72,7 @@
 			v = ast_variable_browse(cfg, cat);
 			while (v) {
 				if (!strcasecmp(v->name, "enabled")) {
-					enablecdr = ast_true(v->value);
+					enablecel = ast_true(v->value);
 				}
 				
 				v = v->next;
@@ -83,28 +87,30 @@
 	return 1;
 }
 
-static int manager_log(struct ast_cdr *cdr)
+static void manager_log(const struct ast_event *event, void *userdata)
 {
 	time_t t;
 	struct tm timeresult;
 	char strStartTime[80] = "";
 	char strAnswerTime[80] = "";
 	char strEndTime[80] = "";
+	struct ast_cel *cel = 0;
 	
-	if (!enablecdr)
+	if (!enablecel)
 		return 0;
 
-	t = cdr->start.tv_sec;
+	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	t = cel->start.tv_sec;
 	localtime_r(&t, &timeresult);
 	strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
 	
-	if (cdr->answer.tv_sec)	{
-    		t = cdr->answer.tv_sec;
+	if (cel->answer.tv_sec)	{
+    		t = cel->answer.tv_sec;
     		localtime_r(&t, &timeresult);
 		strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
 	}
 
-	t = cdr->end.tv_sec;
+	t = cel->end.tv_sec;
 	localtime_r(&t, &timeresult);
 	strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
 
@@ -127,17 +133,19 @@
 	    "AMAFlags: %s\r\n"
 	    "UniqueID: %s\r\n"
 	    "UserField: %s\r\n",
-	    cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
-	    cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
-	    cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), 
-	    ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield);
+	    cel->accountcode, cel->src, cel->dst, cel->dcontext, cel->clid, cel->channel,
+	    cel->dstchannel, cel->lastapp, cel->lastdata, strStartTime, strAnswerTime, strEndTime,
+	    cel->duration, cel->billsec, ast_cel_disp2str(cel->disposition), 
+	    ast_cel_flags2str(cel->amaflags), cel->uniqueid, cel->userfield);
 	    	
 	return 0;
 }
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (event_sub)
+		ast_event_unsubscribe(event_sub);
+	event_sub = 0;
 	return 0;
 }
 
@@ -149,12 +157,14 @@
 	if (!loadconfigurationfile())
 		return AST_MODULE_LOAD_DECLINE;
 	
-	res = ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
-	if (res) {
-		ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
+	event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, NULL, AST_EVENT_IE_END);
+	if (!event_sub) {
+		ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
 	}
-	
-	return res;
+	if (!event_sub)
+		return AST_MODULE_LOAD_DECLINE;
+	else
+		return 0;
 }
 
 static int reload(void)
@@ -163,7 +173,7 @@
 	return 0;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk Manager Interface CDR Backend",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk Manager Interface CEL Backend",
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,

Modified: team/murf/newcdr/cel/cel_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_odbc.c?view=diff&rev=62091&r1=62090&r2=62091
==============================================================================
--- team/murf/newcdr/cel/cel_odbc.c (original)
+++ team/murf/newcdr/cel/cel_odbc.c Thu Apr 26 17:06:53 2007
@@ -1,9 +1,10 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2003-2005, Digium, Inc.
- *
- * Brian K. West <brian at bkw.org>
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Brian K. West <brian at bkw.org> original CDR version
+ * Steve Murphy <murf at digium.com> Adaptation to CEL
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -18,14 +19,14 @@
 
 /*! \file
  *
- * \brief ODBC CDR Backend
+ * \brief ODBC CEL Backend
  * 
  * \author Brian K. West <brian at bkw.org>
  *
  * See also:
  * \arg http://www.unixodbc.org
- * \arg \ref Config_cdr
- * \ingroup cdr_drivers
+ * \arg \ref Config_cel
+ * \ingroup cel_drivers
  */
 
 /*** MODULEINFO
@@ -58,14 +59,14 @@
 #include "asterisk/config.h"
 #include "asterisk/options.h"
 #include "asterisk/channel.h"
-#include "asterisk/cdr.h"
+#include "asterisk/cel.h"
 #include "asterisk/module.h"
 #include "asterisk/logger.h"
 
 #define DATE_FORMAT "%Y-%m-%d %T"
 
 static char *name = "ODBC";
-static char *config = "cdr_odbc.conf";
+static char *config = "cel_odbc.conf";
 static char *dsn = NULL, *username = NULL, *password = NULL, *table = NULL;
 static int loguniqueid = 0;
 static int usegmtime = 0;
@@ -80,6 +81,7 @@
 static SQLHENV	ODBC_env = SQL_NULL_HANDLE;	/* global ODBC Environment */
 static SQLHDBC	ODBC_con;			/* global ODBC Connection Handle */
 static SQLHSTMT	ODBC_stmt;			/* global ODBC Statement Handle */
+static struct ast_event_sub event_sub = 0;
 
 static void odbc_disconnect(void)
 {
@@ -89,17 +91,19 @@
 	connected = 0;
 }
 
-static int odbc_log(struct ast_cdr *cdr)
+static void odbc_log(const struct ast_event *event, void *userdata)
 {
 	int ODBC_res;
 	char sqlcmd[2048] = "", timestr[128];
 	int res = 0;
 	struct tm tm;
-
+	struct ast_cel *cel = 0;
+
+	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
 	if (usegmtime) 
-		gmtime_r(&cdr->start.tv_sec,&tm);
+		gmtime_r(&cel->start.tv_sec,&tm);
 	else
-		localtime_r(&cdr->start.tv_sec,&tm);
+		localtime_r(&cel->start.tv_sec,&tm);
 
 	ast_mutex_lock(&odbc_lock);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
@@ -129,7 +133,7 @@
 
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Failure in AllocStatement %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 		odbc_disconnect();
 		ast_mutex_unlock(&odbc_lock);
@@ -144,7 +148,7 @@
 	
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in PREPARE %d\n", ODBC_res);
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Error in PREPARE %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 		odbc_disconnect();
 		ast_mutex_unlock(&odbc_lock);
@@ -152,54 +156,54 @@
 	}
 
 	SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, &timestr, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->clid), 0, cdr->clid, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->src), 0, cdr->src, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dst), 0, cdr->dst, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dcontext), 0, cdr->dcontext, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->channel), 0, cdr->channel, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dstchannel), 0, cdr->dstchannel, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastapp), 0, cdr->lastapp, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastdata), 0, cdr->lastdata, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->duration, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->billsec, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->clid), 0, cel->clid, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->src), 0, cel->src, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->dst), 0, cel->dst, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->dcontext), 0, cel->dcontext, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->channel), 0, cel->channel, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->dstchannel), 0, cel->dstchannel, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->lastapp), 0, cel->lastapp, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->lastdata), 0, cel->lastdata, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cel->duration, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cel->billsec, 0, NULL);
 	if (dispositionstring)
-		SQLBindParameter(ODBC_stmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ast_cdr_disp2str(cdr->disposition)) + 1, 0, ast_cdr_disp2str(cdr->disposition), 0, NULL);
+		SQLBindParameter(ODBC_stmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ast_cel_disp2str(cel->disposition)) + 1, 0, ast_cel_disp2str(cel->disposition), 0, NULL);
 	else
-		SQLBindParameter(ODBC_stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->disposition, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 13, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->amaflags, 0, NULL);
-	SQLBindParameter(ODBC_stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->accountcode), 0, cdr->accountcode, 0, NULL);
+		SQLBindParameter(ODBC_stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cel->disposition, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 13, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cel->amaflags, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->accountcode), 0, cel->accountcode, 0, NULL);
 
 	if (loguniqueid) {
-		SQLBindParameter(ODBC_stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL);
-		SQLBindParameter(ODBC_stmt, 16, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL);
+		SQLBindParameter(ODBC_stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->uniqueid), 0, cel->uniqueid, 0, NULL);
+		SQLBindParameter(ODBC_stmt, 16, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cel->userfield), 0, cel->userfield, 0, NULL);
 	}
 
 	if (connected) {
 		res = odbc_do_query();
 		if (res < 0) {
 			if (option_verbose > 10)		
-				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
+				ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Query FAILED Call not logged!\n");
 			if (option_verbose > 10)
-				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
+				ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Reconnecting to dsn %s\n", dsn);
 			SQLDisconnect(ODBC_con);
 			res = odbc_init();
 			if (res < 0) {
 				if (option_verbose > 10)
-					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: %s has gone away!\n", dsn);
+					ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: %s has gone away!\n", dsn);
 				odbc_disconnect();
 			} else {
 				if (option_verbose > 10)
-					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
+					ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Trying Query again!\n");
 				res = odbc_do_query();
 				if (res < 0) {
 					if (option_verbose > 10)
-						ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
+						ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Query FAILED Call not logged!\n");
 				}
 			}
 		}
 	} else {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Query FAILED Call not logged!\n");
 	}
 	SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 	ast_mutex_unlock(&odbc_lock);
@@ -211,32 +215,34 @@
 	ast_mutex_lock(&odbc_lock);
 	if (connected) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Disconnecting from %s\n", dsn);
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Disconnecting from %s\n", dsn);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 		odbc_disconnect();
 	}
 	if (dsn) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free dsn\n");
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: free dsn\n");
 		free(dsn);
 	}
 	if (username) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free username\n");
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: free username\n");
 		free(username);
 	}
 	if (password) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free password\n");
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: free password\n");
 		free(password);
 	}
 	if (table) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free table\n");
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: free table\n");
 		free(table);
 	}
 
-	ast_cdr_unregister(name);
+	if (event_sub)
+		ast_event_unsubscribe(event_sub);
+	event_sub = 0;
 	ast_mutex_unlock(&odbc_lock);
 	return 0;
 }
@@ -252,7 +258,7 @@
 
 	cfg = ast_config_load(config);
 	if (!cfg) {
-		ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config);
+		ast_log(LOG_WARNING, "cel_odbc: Unable to load config for ODBC CEL's: %s\n", config);
 		res = AST_MODULE_LOAD_DECLINE;
 		goto out;
 	}
@@ -265,12 +271,12 @@
 
 	tmp = ast_variable_retrieve(cfg,"global","dsn");
 	if (tmp == NULL) {
-		ast_log(LOG_WARNING,"cdr_odbc: dsn not specified.  Assuming asteriskdb\n");
+		ast_log(LOG_WARNING,"cel_odbc: dsn not specified.  Assuming asteriskdb\n");
 		tmp = "asteriskdb";
 	}
 	dsn = strdup(tmp);
 	if (dsn == NULL) {
-		ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
+		ast_log(LOG_ERROR,"cel_odbc: Out of memory error.\n");
 		res = -1;
 		goto out;
 	}
@@ -286,7 +292,7 @@
 	if (tmp) {
 		username = strdup(tmp);
 		if (username == NULL) {
-			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
+			ast_log(LOG_ERROR,"cel_odbc: Out of memory error.\n");
 			res = -1;
 			goto out;
 		}
@@ -296,7 +302,7 @@
 	if (tmp) {
 		password = strdup(tmp);
 		if (password == NULL) {
-			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
+			ast_log(LOG_ERROR,"cel_odbc: Out of memory error.\n");
 			res = -1;
 			goto out;
 		}
@@ -307,14 +313,14 @@
 		loguniqueid = ast_true(tmp);
 		if (loguniqueid) {
 			if (option_debug)
-				ast_log(LOG_DEBUG,"cdr_odbc: Logging uniqueid\n");
+				ast_log(LOG_DEBUG,"cel_odbc: Logging uniqueid\n");
 		} else {
 			if (option_debug)
-				ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
+				ast_log(LOG_DEBUG,"cel_odbc: Not logging uniqueid\n");
 		}
 	} else {
 		if (option_debug)
-			ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
+			ast_log(LOG_DEBUG,"cel_odbc: Not logging uniqueid\n");
 		loguniqueid = 0;
 	}
 
@@ -323,57 +329,60 @@
 		usegmtime = ast_true(tmp);
 		if (usegmtime) {
 			if (option_debug)
-				ast_log(LOG_DEBUG,"cdr_odbc: Logging in GMT\n");
+				ast_log(LOG_DEBUG,"cel_odbc: Logging in GMT\n");
 		} else {
 			if (option_debug)
-				ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
+				ast_log(LOG_DEBUG,"cel_odbc: Not logging in GMT\n");
 		}
 	} else {
 		if (option_debug)
-			ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
+			ast_log(LOG_DEBUG,"cel_odbc: Not logging in GMT\n");
 		usegmtime = 0;
 	}
 
 	tmp = ast_variable_retrieve(cfg,"global","table");
 	if (tmp == NULL) {
-		ast_log(LOG_WARNING,"cdr_odbc: table not specified.  Assuming cdr\n");
-		tmp = "cdr";
+		ast_log(LOG_WARNING,"cel_odbc: table not specified.  Assuming cel\n");
+		tmp = "cel";
 	}
 	table = strdup(tmp);
 	if (table == NULL) {
-		ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
+		ast_log(LOG_ERROR,"cel_odbc: Out of memory error.\n");
 		res = -1;
 		goto out;
 	}
 
 	if (option_verbose > 2) {
-		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn);
+		ast_verbose( VERBOSE_PREFIX_3 "cel_odbc: dsn is %s\n",dsn);
 		if (username)
 		{
-			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username);
-			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: password is [secret]\n");
+			ast_verbose( VERBOSE_PREFIX_3 "cel_odbc: username is %s\n",username);
+			ast_verbose( VERBOSE_PREFIX_3 "cel_odbc: password is [secret]\n");
 		}
 		else
-			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: retreiving username and password from odbc config\n");
-		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: table is %s\n",table);
+			ast_verbose( VERBOSE_PREFIX_3 "cel_odbc: retreiving username and password from odbc config\n");
+		ast_verbose( VERBOSE_PREFIX_3 "cel_odbc: table is %s\n",table);
 	}
 	
 	res = odbc_init();
 	if (res < 0) {
-		ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
+		ast_log(LOG_ERROR, "cel_odbc: Unable to connect to datasource: %s\n", dsn);
 		if (option_verbose > 2) {
-			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
-		}
-	}
-	res = ast_cdr_register(name, ast_module_info->description, odbc_log);
-	if (res) {
-		ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n");
+			ast_verbose( VERBOSE_PREFIX_3 "cel_odbc: Unable to connect to datasource: %s\n", dsn);
+		}
+	}
+	event_sub = ast_event_subscribe(AST_EVENT_CEL, odbc_log, NULL, AST_EVENT_IE_END);
+	if (!event_sub) {
+		ast_log(LOG_ERROR, "cel_odbc: Unable to register ODBC CEL handling\n");
 	}
 out:
 	if (cfg)
 		ast_config_destroy(cfg);
 	ast_mutex_unlock(&odbc_lock);
-	return res;
+	if (event_sub)
+		return 0;
+	else
+		return AST_MODULE_LOAD_DECLINE;
 }
 
 static int odbc_do_query(void)
@@ -384,13 +393,13 @@
 	
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Error in Query %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 		odbc_disconnect();
 		return -1;
 	} else {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query Successful!\n");
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Query Successful!\n");
 		connected = 1;
 	}
 	return 0;
@@ -404,7 +413,7 @@
 		ODBC_res = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ODBC_env);
 		if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 			if (option_verbose > 10)
-				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error AllocHandle\n");
+				ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Error AllocHandle\n");
 			connected = 0;
 			return -1;
 		}
@@ -413,7 +422,7 @@
 
 		if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 			if (option_verbose > 10)
-				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SetEnv\n");
+				ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Error SetEnv\n");
 			SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
 			connected = 0;
 			return -1;
@@ -423,7 +432,7 @@
 
 		if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 			if (option_verbose > 10)
-				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error AllocHDB %d\n", ODBC_res);
+				ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Error AllocHDB %d\n", ODBC_res);
 			SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
 			connected = 0;
 			return -1;
@@ -437,14 +446,14 @@
 
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SQLConnect %d\n", ODBC_res);
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Error SQLConnect %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
 		SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
 		connected = 0;
 		return -1;
 	} else {
 		if (option_verbose > 10)
-			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Connected to %s\n", dsn);
+			ast_verbose( VERBOSE_PREFIX_4 "cel_odbc: Connected to %s\n", dsn);
 		connected = 1;
 	}
 	return 0;
@@ -466,7 +475,7 @@
 	return odbc_load_module();
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ODBC CDR Backend",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ODBC CEL Backend",
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,

Modified: team/murf/newcdr/cel/cel_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_pgsql.c?view=diff&rev=62091&r1=62090&r2=62091
==============================================================================
--- team/murf/newcdr/cel/cel_pgsql.c (original)
+++ team/murf/newcdr/cel/cel_pgsql.c Thu Apr 26 17:06:53 2007
@@ -1,11 +1,15 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2003 - 2006
- *
+ * Copyright (C) 2007
+ *
+ * Steve Murphy - adapted to CEL, from:
  * Matthew D. Hardeman <mhardemn at papersoft.com> 
  * Adapted from the MySQL CDR logger originally by James Sharp 
  *
+ * Modified April, 2007
+ * Steve Murphy <murf at digium.com>
+
  * Modified September 2003
  * Matthew D. Hardeman <mhardemn at papersoft.com>
  *
@@ -22,15 +26,15 @@
 
 /*! \file
  *
- * \brief PostgreSQL CDR logger 
+ * \brief PostgreSQL CEL logger 
  * 
- * \author Matthew D. Hardeman <mhardemn at papersoft.com> 
+ * \author Steve Murphy <murf at digium.com>
  * \extref PostgreSQL http://www.postgresql.org/
  *
  * See also
- * \arg \ref Config_cdr
+ * \arg \ref Config_cel
  * \arg http://www.postgresql.org/
- * \ingroup cdr_drivers
+ * \ingroup cel_drivers
  */
 
 /*** MODULEINFO
@@ -53,7 +57,7 @@
 #include "asterisk/config.h"
 #include "asterisk/options.h"
 #include "asterisk/channel.h"
-#include "asterisk/cdr.h"
+#include "asterisk/cel.h"
 #include "asterisk/module.h"
 #include "asterisk/logger.h"
 #include "asterisk.h"
@@ -61,7 +65,7 @@
 #define DATE_FORMAT "%Y-%m-%d %T"
 
 static char *name = "pgsql";
-static char *config = "cdr_pgsql.conf";
+static char *config = "cel_pgsql.conf";
 static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL;
 static int connected = 0;
 
@@ -69,16 +73,19 @@
 
 static PGconn	*conn = NULL;
 static PGresult	*result = NULL;
-
-static int pgsql_log(struct ast_cdr *cdr)
+static struct ast_event_sub event_sub = 0;
+
+static int pgsql_log(const struct ast_event *event, void *userdata)
 {
 	struct tm tm;
 	char sqlcmd[2048] = "", timestr[128];
 	char *pgerror;
-
+	struct ast_cel *cel = 0;
+	
+	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
 	ast_mutex_lock(&pgsql_lock);
 
-	localtime_r(&cdr->start.tv_sec,&tm);
+	localtime_r(&cel->start.tv_sec,&tm);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
 	if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
@@ -87,8 +94,8 @@
 			connected = 1;
 		} else {
 			pgerror = PQerrorMessage(conn);
-			ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s.  Calls will not be logged!\n", pghostname);
-                        ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
+			ast_log(LOG_ERROR, "cel_pgsql: Unable to connect to database server %s.  Calls will not be logged!\n", pghostname);
+                        ast_log(LOG_ERROR, "cel_pgsql: Reason: %s\n", pgerror);
 		}
 	}
 
@@ -97,41 +104,41 @@
 		char *uniqueid=NULL, *userfield=NULL;
 
 		/* Maximum space needed would be if all characters needed to be escaped, plus a trailing NULL */
-		if ((clid = alloca(strlen(cdr->clid) * 2 + 1)) != NULL)
-			PQescapeString(clid, cdr->clid, strlen(cdr->clid));
-		if ((dcontext = alloca(strlen(cdr->dcontext) * 2 + 1)) != NULL)
-			PQescapeString(dcontext, cdr->dcontext, strlen(cdr->dcontext));
-		if ((channel = alloca(strlen(cdr->channel) * 2 + 1)) != NULL)
-			PQescapeString(channel, cdr->channel, strlen(cdr->channel));
-		if ((dstchannel = alloca(strlen(cdr->dstchannel) * 2 + 1)) != NULL)
-			PQescapeString(dstchannel, cdr->dstchannel, strlen(cdr->dstchannel));
-		if ((lastapp = alloca(strlen(cdr->lastapp) * 2 + 1)) != NULL)
-			PQescapeString(lastapp, cdr->lastapp, strlen(cdr->lastapp));
-		if ((lastdata = alloca(strlen(cdr->lastdata) * 2 + 1)) != NULL)
-			PQescapeString(lastdata, cdr->lastdata, strlen(cdr->lastdata));
-		if ((uniqueid = alloca(strlen(cdr->uniqueid) * 2 + 1)) != NULL)
-			PQescapeString(uniqueid, cdr->uniqueid, strlen(cdr->uniqueid));
-		if ((userfield = alloca(strlen(cdr->userfield) * 2 + 1)) != NULL)
-			PQescapeString(userfield, cdr->userfield, strlen(cdr->userfield));
+		if ((clid = alloca(strlen(cel->clid) * 2 + 1)) != NULL)
+			PQescapeString(clid, cel->clid, strlen(cel->clid));
+		if ((dcontext = alloca(strlen(cel->dcontext) * 2 + 1)) != NULL)
+			PQescapeString(dcontext, cel->dcontext, strlen(cel->dcontext));
+		if ((channel = alloca(strlen(cel->channel) * 2 + 1)) != NULL)
+			PQescapeString(channel, cel->channel, strlen(cel->channel));
+		if ((dstchannel = alloca(strlen(cel->dstchannel) * 2 + 1)) != NULL)
+			PQescapeString(dstchannel, cel->dstchannel, strlen(cel->dstchannel));
+		if ((lastapp = alloca(strlen(cel->lastapp) * 2 + 1)) != NULL)
+			PQescapeString(lastapp, cel->lastapp, strlen(cel->lastapp));
+		if ((lastdata = alloca(strlen(cel->lastdata) * 2 + 1)) != NULL)
+			PQescapeString(lastdata, cel->lastdata, strlen(cel->lastdata));
+		if ((uniqueid = alloca(strlen(cel->uniqueid) * 2 + 1)) != NULL)
+			PQescapeString(uniqueid, cel->uniqueid, strlen(cel->uniqueid));
+		if ((userfield = alloca(strlen(cel->userfield) * 2 + 1)) != NULL)
+			PQescapeString(userfield, cel->userfield, strlen(cel->userfield));
 
 		/* Check for all alloca failures above at once */
 		if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata) || (!uniqueid) || (!userfield)) {
-			ast_log(LOG_ERROR, "cdr_pgsql:  Out of memory error (insert fails)\n");
+			ast_log(LOG_ERROR, "cel_pgsql:  Out of memory error (insert fails)\n");
 			ast_mutex_unlock(&pgsql_lock);
 			return -1;
 		}
 
 		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "cdr_pgsql: inserting a CDR record.\n");
+			ast_log(LOG_DEBUG, "cel_pgsql: inserting a CEL record.\n");
 
 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,"
 				 "lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES"
 				 " ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s','%s')",
-				 table,timestr,clid,cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata,
-				 cdr->duration,cdr->billsec,ast_cdr_disp2str(cdr->disposition),cdr->amaflags, cdr->accountcode, uniqueid, userfield);
+				 table,timestr,clid,cel->src, cel->dst, dcontext,channel, dstchannel, lastapp, lastdata,
+				 cel->duration,cel->billsec,ast_cel_disp2str(cel->disposition),cel->amaflags, cel->accountcode, uniqueid, userfield);
 		
 		if (option_debug > 2)
-			ast_log(LOG_DEBUG, "cdr_pgsql: SQL command executed:  %s\n",sqlcmd);
+			ast_log(LOG_DEBUG, "cel_pgsql: SQL command executed:  %s\n",sqlcmd);
 		
 		/* Test to be sure we're still connected... */
 		/* If we're connected, and connection is working, good. */
@@ -139,15 +146,15 @@
 		if (PQstatus(conn) == CONNECTION_OK) {
 			connected = 1;
 		} else {
-			ast_log(LOG_ERROR, "cdr_pgsql: Connection was lost... attempting to reconnect.\n");
+			ast_log(LOG_ERROR, "cel_pgsql: Connection was lost... attempting to reconnect.\n");
 			PQreset(conn);
 			if (PQstatus(conn) == CONNECTION_OK) {
-				ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
+				ast_log(LOG_ERROR, "cel_pgsql: Connection reestablished.\n");
 				connected = 1;
 			} else {
 				pgerror = PQerrorMessage(conn);
-				ast_log(LOG_ERROR, "cdr_pgsql: Unable to reconnect to database server %s. Calls will not be logged!\n", pghostname);
-				ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
+				ast_log(LOG_ERROR, "cel_pgsql: Unable to reconnect to database server %s. Calls will not be logged!\n", pghostname);
+				ast_log(LOG_ERROR, "cel_pgsql: Reason: %s\n", pgerror);
 				connected = 0;
 				ast_mutex_unlock(&pgsql_lock);
 				return -1;
@@ -156,19 +163,19 @@
 		result = PQexec(conn, sqlcmd);
 		if ( PQresultStatus(result) != PGRES_COMMAND_OK) {
                         pgerror = PQresultErrorMessage(result);
-			ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
-                        ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
-			ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
+			ast_log(LOG_ERROR,"cel_pgsql: Failed to insert call detail record into database!\n");
+                        ast_log(LOG_ERROR,"cel_pgsql: Reason: %s\n", pgerror);
+			ast_log(LOG_ERROR,"cel_pgsql: Connection may have been lost... attempting to reconnect.\n");
 			PQreset(conn);
 			if (PQstatus(conn) == CONNECTION_OK) {
-				ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
+				ast_log(LOG_ERROR, "cel_pgsql: Connection reestablished.\n");
 				connected = 1;
 				result = PQexec(conn, sqlcmd);
 				if ( PQresultStatus(result) != PGRES_COMMAND_OK)
 				{
 					pgerror = PQresultErrorMessage(result);
-					ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!\n");
-					ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
+					ast_log(LOG_ERROR,"cel_pgsql: HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!\n");
+					ast_log(LOG_ERROR,"cel_pgsql: Reason: %s\n", pgerror);
 				}
 			}
 			ast_mutex_unlock(&pgsql_lock);
@@ -195,7 +202,9 @@
 		free(pgdbport);
 	if (table)
 		free(table);
-	ast_cdr_unregister(name);
+	if (event_sub)
+		ast_event_unsubscribe(event_sub);
+	event_sub = 0;
 	return 0;
 }
 
@@ -218,7 +227,7 @@
 
 	if (!(tmp = ast_variable_retrieve(cfg, "global", "dbname"))) {
 		ast_log(LOG_WARNING,"PostgreSQL database not specified.  Assuming asterisk\n");
-		tmp = "asteriskcdrdb";
+		tmp = "asteriskceldb";
 	}
 
 	if (!(pgdbname = ast_strdup(tmp)))
@@ -249,8 +258,8 @@
 		return -1;
 
 	if (!(tmp = ast_variable_retrieve(cfg, "global", "table"))) {
-		ast_log(LOG_WARNING,"CDR table not specified.  Assuming cdr\n");
-		tmp = "cdr";
+		ast_log(LOG_WARNING,"CEL table not specified.  Assuming cel\n");
+		tmp = "cel";
 	}
 
 	if (!(table = ast_strdup(tmp)))
@@ -258,14 +267,14 @@
 
 	if (option_debug) {
 	    	if (ast_strlen_zero(pghostname))
-			ast_log(LOG_DEBUG, "cdr_pgsql: using default unix socket\n");
+			ast_log(LOG_DEBUG, "cel_pgsql: using default unix socket\n");
 		else
-			ast_log(LOG_DEBUG, "cdr_pgsql: got hostname of %s\n", pghostname);
-		ast_log(LOG_DEBUG, "cdr_pgsql: got port of %s\n", pgdbport);
-		ast_log(LOG_DEBUG, "cdr_pgsql: got user of %s\n", pgdbuser);
-		ast_log(LOG_DEBUG, "cdr_pgsql: got dbname of %s\n", pgdbname);
-		ast_log(LOG_DEBUG, "cdr_pgsql: got password of %s\n", pgpassword);
-		ast_log(LOG_DEBUG, "cdr_pgsql: got sql table name of %s\n", table);
+			ast_log(LOG_DEBUG, "cel_pgsql: got hostname of %s\n", pghostname);
+		ast_log(LOG_DEBUG, "cel_pgsql: got port of %s\n", pgdbport);
+		ast_log(LOG_DEBUG, "cel_pgsql: got user of %s\n", pgdbuser);
+		ast_log(LOG_DEBUG, "cel_pgsql: got dbname of %s\n", pgdbname);
+		ast_log(LOG_DEBUG, "cel_pgsql: got password of %s\n", pgpassword);
+		ast_log(LOG_DEBUG, "cel_pgsql: got sql table name of %s\n", table);
 	}
 	
 	conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
@@ -275,12 +284,17 @@
 		connected = 1;
 	} else {
                 pgerror = PQerrorMessage(conn);
-		ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
-                ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
+		ast_log(LOG_ERROR, "cel_pgsql: Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
+                ast_log(LOG_ERROR, "cel_pgsql: Reason: %s\n", pgerror);
 		connected = 0;
 	}
 

[... 832 lines stripped ...]


More information about the svn-commits mailing list