[svn-commits] murf: branch murf/newcdr r62082 - in /team/murf/newcdr: cel/ configs/ include...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Apr 26 10:50:10 MST 2007


Author: murf
Date: Thu Apr 26 12:50:09 2007
New Revision: 62082

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62082
Log:
1st rough draft. won't even compile, I'm sure, yet, but the basic files are here, might as well check them in. Still a lot of work to do.

Added:
    team/murf/newcdr/cel/
    team/murf/newcdr/cel/Makefile   (with props)
    team/murf/newcdr/cel/cel_csv.c   (with props)
    team/murf/newcdr/cel/cel_custom.c   (with props)
    team/murf/newcdr/cel/cel_manager.c   (with props)
    team/murf/newcdr/cel/cel_odbc.c   (with props)
    team/murf/newcdr/cel/cel_pgsql.c   (with props)
    team/murf/newcdr/cel/cel_radius.c   (with props)
    team/murf/newcdr/cel/cel_sqlite.c   (with props)
    team/murf/newcdr/cel/cel_sqlite3_custom.c   (with props)
    team/murf/newcdr/cel/cel_tds.c   (with props)
    team/murf/newcdr/configs/cel.conf.sample   (with props)
    team/murf/newcdr/configs/cel_custom.conf.sample   (with props)
    team/murf/newcdr/configs/cel_manager.conf.sample   (with props)
    team/murf/newcdr/configs/cel_odbc.conf.sample   (with props)
    team/murf/newcdr/configs/cel_pgsql.conf.sample   (with props)
    team/murf/newcdr/configs/cel_sqlite3_custom.conf.sample   (with props)
    team/murf/newcdr/configs/cel_tds.conf.sample   (with props)
    team/murf/newcdr/include/asterisk/cel.h   (with props)
    team/murf/newcdr/include/asterisk/event.h   (with props)
    team/murf/newcdr/include/asterisk/event_defs.h   (with props)
    team/murf/newcdr/main/cel.c   (with props)
    team/murf/newcdr/main/event.c   (with props)

Added: team/murf/newcdr/cel/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/Makefile?view=auto&rev=62082
==============================================================================
--- team/murf/newcdr/cel/Makefile (added)
+++ team/murf/newcdr/cel/Makefile Thu Apr 26 12:50:09 2007
@@ -1,0 +1,26 @@
+#
+# Asterisk -- A telephony toolkit for Linux.
+# 
+# Makefile for CDR backends
+#
+# Copyright (C) 1999-2006, Digium, Inc.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License
+#
+
+-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)))
+
+LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
+
+ifneq ($(findstring cel,$(MENUSELECT_EMBED)),)
+  EMBEDDED_MODS:=$(LOADABLE_MODS)
+  LOADABLE_MODS:=
+endif
+
+all: _all
+
+include $(ASTTOPDIR)/Makefile.moddir_rules

Propchange: team/murf/newcdr/cel/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/newcdr/cel/Makefile
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/newcdr/cel/Makefile
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/murf/newcdr/cel/cel_csv.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_csv.c?view=auto&rev=62082
==============================================================================
--- team/murf/newcdr/cel/cel_csv.c (added)
+++ team/murf/newcdr/cel/cel_csv.c Thu Apr 26 12:50:09 2007
@@ -1,0 +1,343 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Steve Murphy <murf at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Comma Separated Value CEL records.
+ *
+ * \author Steve Murphy <murf at digium.com>
+ * 
+ * \arg See also \ref AstCEL
+ * \ingroup cel_drivers
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "asterisk/config.h"
+#include "asterisk/channel.h"
+#include "asterisk/cel.h"
+#include "asterisk/event.h"
+#include "asterisk/module.h"
+#include "asterisk/options.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+
+#define CSV_LOG_DIR "/cel-csv"
+#define CSV_MASTER  "/Master.csv"
+
+#define DATE_FORMAT "%Y-%m-%d %T"
+
+static int usegmtime = 0;
+static int loguniqueid = 0;
+static int loguserfield = 0;
+static char *config = "cel.conf";
+static struct ast_event_sub event_sub = 0;
+
+/* #define CSV_LOGUNIQUEID 1 */
+/* #define CSV_LOGUSERFIELD 1 */
+
+/*----------------------------------------------------
+  The values are as follows:
+
+
+  "accountcode", 	accountcode is the account name of detail records, Master.csv contains all records *
+  			Detail records are configured on a channel basis, IAX and SIP are determined by user *
+			Zap is determined by channel in zaptel.conf 
+  "context", 
+  "exten", 
+  "calleridname",
+  "calleridnum",
+  "channel",
+  "application",	Last application run on the channel 
+  "app arguments",	argument to the last channel 
+  "event name",
+  "event time", 
+  "amaflags",       	DOCUMENTATION, BILL, IGNORE etc, specified on a per channel basis like accountcode. 
+  "uniqueid",           unique call identifier 
+  "userfield"		user field set via SetCDRUserField 
+----------------------------------------------------------*/
+
+static char *name = "csv";
+
+static FILE *mf = NULL;
+
+
+static int load_config(void)
+{
+	struct ast_config *cfg;
+	struct ast_variable *var;
+	const char *tmp;
+
+	usegmtime = 0;
+	loguniqueid = 0;
+	loguserfield = 0;
+	
+	cfg = ast_config_load(config);
+	
+	if (!cfg) {
+		ast_log(LOG_WARNING, "unable to load config: %s\n", config);
+		return 0;
+	}	
+	var = ast_variable_browse(cfg, "csv");
+	if (!var) {
+		ast_config_destroy(cfg);
+		return 0;
+	}
+	
+	tmp = ast_variable_retrieve(cfg, "csv", "usegmtime");
+	if (tmp) {
+		usegmtime = ast_true(tmp);
+		if (usegmtime) {
+			if (option_debug)
+				ast_log(LOG_DEBUG, "logging time in GMT\n");
+		}
+	}
+
+	tmp = ast_variable_retrieve(cfg, "csv", "loguniqueid");
+	if (tmp) {
+		loguniqueid = ast_true(tmp);
+		if (loguniqueid) {
+			if (option_debug)
+				ast_log(LOG_DEBUG, "logging CDR field UNIQUEID\n");
+		}
+	}
+
+	tmp = ast_variable_retrieve(cfg, "csv", "loguserfield");
+	if (tmp) {
+		loguserfield = ast_true(tmp);
+		if (loguserfield) {
+			if (option_debug)
+				ast_log(LOG_DEBUG, "logging CDR user-defined field\n");
+		}
+	}
+
+	ast_config_destroy(cfg);
+	return 1;
+}
+
+static int append_string(char *buf, char *s, size_t bufsize)
+{
+	int pos = strlen(buf);
+	int spos = 0;
+	int error = 0;
+	if (pos >= bufsize - 4)
+		return -1;
+	buf[pos++] = '\"';
+	error = -1;
+	while(pos < bufsize - 3) {
+		if (!s[spos]) {
+			error = 0;
+			break;
+		}
+		if (s[spos] == '\"')
+			buf[pos++] = '\"';
+		buf[pos++] = s[spos];
+		spos++;
+	}
+	buf[pos++] = '\"';
+	buf[pos++] = ',';
+	buf[pos++] = '\0';
+	return error;
+}
+
+static int append_int(char *buf, int s, size_t bufsize)
+{
+	char tmp[32];
+	int pos = strlen(buf);
+	snprintf(tmp, sizeof(tmp), "%d", s);
+	if (pos + strlen(tmp) > bufsize - 3)
+		return -1;
+	strncat(buf, tmp, bufsize - strlen(buf) - 1);
+	pos = strlen(buf);
+	buf[pos++] = ',';
+	buf[pos++] = '\0';
+	return 0;
+}
+
+static int append_date(char *buf, struct timeval tv, size_t bufsize)
+{
+	char tmp[80] = "";
+	struct tm tm;
+	time_t t;
+	t = tv.tv_sec;
+	if (strlen(buf) > bufsize - 3)
+		return -1;
+	if (ast_tvzero(tv)) {
+		strncat(buf, ",", bufsize - strlen(buf) - 1);
+		return 0;
+	}
+	if (usegmtime) {
+		gmtime_r(&t,&tm);
+	} else {
+		localtime_r(&t,&tm);
+	}
+	strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
+	return append_string(buf, tmp, bufsize);
+}
+
+static int build_csv_record(char *buf, size_t bufsize, struct ast_cel *cel)
+{
+
+	buf[0] = '\0';
+	/* Start Time */
+	append_date(buf, cel->eventtime, bufsize);
+	/* EventType */
+	append_string(buf, ast_cel_eventtype2str(cel->eventtype), bufsize);
+	/* UserEventName */
+	append_string(buf, cel->usereventname, bufsize);
+	/* Account code */
+	append_string(buf, cel->accountcode, bufsize);
+	/* CID number */
+	append_string(buf, cel->clidnum, bufsize);
+	/* Exten */
+	append_string(buf, cel->exten, bufsize);
+	/* Context */
+	append_string(buf, cel->context, bufsize);
+	/* Caller*ID */
+	append_string(buf, cel->clid, bufsize);
+	/* Channel Name */
+	append_string(buf, cel->channel, bufsize);
+	/* Application */
+	append_string(buf, cel->app, bufsize);
+	/* App Data/Args, whatever */
+	append_string(buf, cel->appdata, bufsize);
+	/* AMA Flags */
+	append_string(buf, ast_cel_flags2str(cel->amaflags), bufsize);
+	/* Unique ID */
+	if (loguniqueid)
+		append_string(buf, cel->uniqueid, bufsize);
+	/* append the user field */
+	if(loguserfield)
+		append_string(buf, cel->userfield,bufsize);	
+	/* If we hit the end of our buffer, log an error */
+	if (strlen(buf) < bufsize - 5) {
+		/* Trim off trailing comma */
+		buf[strlen(buf) - 1] = '\0';
+		strncat(buf, "\n", bufsize - strlen(buf) - 1);
+		return 0;
+	}
+	return -1;
+}
+
+static int writefile(char *s, char *acc)
+{
+	char tmp[PATH_MAX];
+	FILE *f;
+	if (strchr(acc, '/') || (acc[0] == '.')) {
+		ast_log(LOG_WARNING, "Account code '%s' insecure for writing file\n", acc);
+		return -1;
+	}
+	snprintf(tmp, sizeof(tmp), "%s/%s/%s.csv", (char *)ast_config_AST_LOG_DIR,CSV_LOG_DIR, acc);
+	f = fopen(tmp, "a");
+	if (!f)
+		return -1;
+	fputs(s, f);
+	fflush(f);
+	fclose(f);
+	return 0;
+}
+
+
+static void csv_log(const struct ast_event *event, void *userdata)
+{
+	/* Make sure we have a big enough buf */
+	char buf[1024];
+	char csvmaster[PATH_MAX];
+	struct ast_cel *cel;
+	
+	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	snprintf(csvmaster, sizeof(csvmaster),"%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER);
+#if 0
+	printf("[CDR] %s ('%s' -> '%s') Dur: %ds Bill: %ds Disp: %s Flags: %s Account: [%s]\n", cel->channel, cel->src, cel->dst, cel->duration, cel->billsec, ast_cel_disp2str(cel->disposition), ast_cel_flags2str(cel->amaflags), cel->accountcode);
+#endif
+	if (build_csv_record(buf, sizeof(buf), cel)) {
+		ast_log(LOG_WARNING, "Unable to create CSV record in %d bytes.  CDR not recorded!\n", (int)sizeof(buf));
+	} else {
+		/* because of the absolutely unconditional need for the
+		   highest reliability possible in writing billing records,
+		   we open write and close the log file each time */
+		mf = fopen(csvmaster, "a");
+		if (!mf) {
+			ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", csvmaster, strerror(errno));
+		}
+		if (mf) {
+			fputs(buf, mf);
+			fflush(mf); /* be particularly anal here */
+			fclose(mf);
+			mf = NULL;
+		}
+		if (!ast_strlen_zero(cel->accountcode)) {
+			if (writefile(buf, cel->accountcode))
+				ast_log(LOG_WARNING, "Unable to write CSV record to account file '%s' : %s\n", cel->accountcode, strerror(errno));
+		}
+	}
+	return;
+}
+
+static int unload_module(void)
+{
+	if (mf)
+		fclose(mf);
+	if (event_subsc)
+		ast_event_unsubscribe(event_sub);
+	
+	ast_cel_unregister(name);
+	return 0;
+}
+
+static int load_module(void)
+{
+	int res;
+	struct ast_event_sub *subsc;
+	
+	if(!load_config())
+		return AST_MODULE_LOAD_DECLINE;
+
+	event_sub = ast_event_subscribe(AST_EVENT_CEL, csv_log, NULL, AST_EVENT_IE_END);
+	
+	if (!event_sub) {
+		ast_log(LOG_ERROR, "Unable to register CSV CEL handling\n");
+		if (mf)
+			fclose(mf);
+	}
+	return 0;
+}
+
+static int reload(void)
+{
+	load_config();
+
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Comma Separated Values CDR Backend",
+		.load = load_module,
+		.unload = unload_module,
+		.reload = reload,
+	       );

Propchange: team/murf/newcdr/cel/cel_csv.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/newcdr/cel/cel_csv.c
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/newcdr/cel/cel_csv.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/murf/newcdr/cel/cel_custom.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_custom.c?view=auto&rev=62082
==============================================================================
--- team/murf/newcdr/cel/cel_custom.c (added)
+++ team/murf/newcdr/cel/cel_custom.c Thu Apr 26 12:50:09 2007
@@ -1,0 +1,171 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2005, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * Includes code and algorithms from the Zapata library.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Custom Comma Separated Value CDR records.
+ *
+ * \author Mark Spencer <markster at digium.com>
+ *
+ * \arg See also \ref AstCDR
+ *
+ * Logs in LOG_DIR/cdr_custom
+ * \ingroup cdr_drivers
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "asterisk/channel.h"
+#include "asterisk/cdr.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 DATE_FORMAT "%Y-%m-%d %T"
+
+AST_MUTEX_DEFINE_STATIC(lock);
+
+static char *name = "cdr-custom";
+
+static FILE *mf = NULL;
+
+static char master[PATH_MAX];
+static char format[1024]="";
+
+static int load_config(int reload) 
+{
+	struct ast_config *cfg;
+	struct ast_variable *var;
+	int res = -1;
+
+	strcpy(format, "");
+	strcpy(master, "");
+	if((cfg = ast_config_load("cdr_custom.conf"))) {
+		var = ast_variable_browse(cfg, "mappings");
+		while(var) {
+			ast_mutex_lock(&lock);
+			if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) {
+				if (strlen(var->value) > (sizeof(format) - 1))
+					ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno);
+				ast_copy_string(format, var->value, sizeof(format) - 1);
+				strcat(format,"\n");
+				snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name);
+				ast_mutex_unlock(&lock);
+			} else
+				ast_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno);
+			if (var->next)
+				ast_log(LOG_NOTICE, "Sorry, only one mapping is supported at this time, mapping '%s' will be ignored at line %d.\n", var->next->name, var->next->lineno); 
+			var = var->next;
+		}
+		ast_config_destroy(cfg);
+		res = 0;
+	} else {
+		if (reload)
+			ast_log(LOG_WARNING, "Failed to reload configuration file.\n");
+		else
+			ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
+	}
+	
+	return res;
+}
+
+
+
+static int custom_log(struct ast_cdr *cdr)
+{
+	/* Make sure we have a big enough buf */
+	char buf[2048];
+	struct ast_channel dummy;
+
+	/* Abort if no master file is specified */
+	if (ast_strlen_zero(master))
+		return 0;
+
+	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 */
+	memset(&dummy, 0, sizeof(dummy));
+	dummy.cdr = cdr;
+	pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1);
+
+	/* because of the absolutely unconditional need for the
+	   highest reliability possible in writing billing records,
+	   we open write and close the log file each time */
+	mf = fopen(master, "a");
+	if (!mf) {
+		ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno));
+	}
+	if (mf) {
+		fputs(buf, mf);
+		fflush(mf); /* be particularly anal here */
+		fclose(mf);
+		mf = NULL;
+	}
+	return 0;
+}
+
+static int unload_module(void)
+{
+	if (mf)
+		fclose(mf);
+	ast_cdr_unregister(name);
+	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");
+		if (mf)
+			fclose(mf);
+		return res;
+	} else 
+		return AST_MODULE_LOAD_DECLINE;
+}
+
+static int reload(void)
+{
+	return load_config(1);
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Customizable Comma Separated Values CDR Backend",
+		.load = load_module,
+		.unload = unload_module,
+		.reload = reload,
+	       );
+

Propchange: team/murf/newcdr/cel/cel_custom.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/newcdr/cel/cel_custom.c
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/newcdr/cel/cel_custom.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/murf/newcdr/cel/cel_manager.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_manager.c?view=auto&rev=62082
==============================================================================
--- team/murf/newcdr/cel/cel_manager.c (added)
+++ team/murf/newcdr/cel/cel_manager.c Thu Apr 26 12:50:09 2007
@@ -1,0 +1,170 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2004 - 2005
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Asterisk Call Manager CDR records.
+ * 
+ * See also
+ * \arg \ref AstCDR
+ * \arg \ref AstAMI
+ * \arg \ref Config_ami
+ * \ingroup cdr_drivers
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <sys/types.h>
+#include <strings.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "asterisk/channel.h"
+#include "asterisk/cdr.h"
+#include "asterisk/module.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/manager.h"
+#include "asterisk/config.h"
+
+#define DATE_FORMAT 	"%Y-%m-%d %T"
+#define CONF_FILE	"cdr_manager.conf"
+
+static char *name = "cdr_manager";
+
+static int enablecdr = 0;
+
+static int loadconfigurationfile(void)
+{
+	char *cat;
+	struct ast_config *cfg;
+	struct ast_variable *v;
+	
+	cfg = ast_config_load(CONF_FILE);
+	if (!cfg) {
+		/* Standard configuration */
+		enablecdr = 0;
+		return 0;
+	}
+	
+	cat = ast_category_browse(cfg, NULL);
+	while (cat) {
+		if (!strcasecmp(cat, "general")) {
+			v = ast_variable_browse(cfg, cat);
+			while (v) {
+				if (!strcasecmp(v->name, "enabled")) {
+					enablecdr = ast_true(v->value);
+				}
+				
+				v = v->next;
+			}
+		}
+	
+		/* Next category */
+		cat = ast_category_browse(cfg, cat);
+	}
+	
+	ast_config_destroy(cfg);
+	return 1;
+}
+
+static int manager_log(struct ast_cdr *cdr)
+{
+	time_t t;
+	struct tm timeresult;
+	char strStartTime[80] = "";
+	char strAnswerTime[80] = "";
+	char strEndTime[80] = "";
+	
+	if (!enablecdr)
+		return 0;
+
+	t = cdr->start.tv_sec;
+	localtime_r(&t, &timeresult);
+	strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
+	
+	if (cdr->answer.tv_sec)	{
+    		t = cdr->answer.tv_sec;
+    		localtime_r(&t, &timeresult);
+		strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
+	}
+
+	t = cdr->end.tv_sec;
+	localtime_r(&t, &timeresult);
+	strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
+
+	manager_event(EVENT_FLAG_CALL, "Cdr",
+	    "AccountCode: %s\r\n"
+	    "Source: %s\r\n"
+	    "Destination: %s\r\n"
+	    "DestinationContext: %s\r\n"
+	    "CallerID: %s\r\n"
+	    "Channel: %s\r\n"
+	    "DestinationChannel: %s\r\n"
+	    "LastApplication: %s\r\n"
+	    "LastData: %s\r\n"
+	    "StartTime: %s\r\n"
+	    "AnswerTime: %s\r\n"
+	    "EndTime: %s\r\n"
+	    "Duration: %ld\r\n"
+	    "BillableSeconds: %ld\r\n"
+	    "Disposition: %s\r\n"
+	    "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);
+	    	
+	return 0;
+}
+
+static int unload_module(void)
+{
+	ast_cdr_unregister(name);
+	return 0;
+}
+
+static int load_module(void)
+{
+	int res;
+
+	/* Configuration file */
+	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");
+	}
+	
+	return res;
+}
+
+static int reload(void)
+{
+	loadconfigurationfile();
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk Manager Interface CDR Backend",
+		.load = load_module,
+		.unload = unload_module,
+		.reload = reload,
+	       );

Propchange: team/murf/newcdr/cel/cel_manager.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/newcdr/cel/cel_manager.c
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/newcdr/cel/cel_manager.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/murf/newcdr/cel/cel_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_odbc.c?view=auto&rev=62082
==============================================================================
--- team/murf/newcdr/cel/cel_odbc.c (added)
+++ team/murf/newcdr/cel/cel_odbc.c Thu Apr 26 12:50:09 2007
@@ -1,0 +1,473 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2003-2005, Digium, Inc.
+ *
+ * Brian K. West <brian at bkw.org>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief ODBC CDR Backend
+ * 
+ * \author Brian K. West <brian at bkw.org>
+ *
+ * See also:
+ * \arg http://www.unixodbc.org
+ * \arg \ref Config_cdr
+ * \ingroup cdr_drivers
+ */
+
+/*** MODULEINFO
+	<depend>unixodbc</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+
+#ifndef __CYGWIN__
+#include <sql.h>
+#include <sqlext.h>
+#include <sqltypes.h>
+#else
+#include <windows.h>
+#include <w32api/sql.h>
+#include <w32api/sqlext.h>
+#include <w32api/sqltypes.h>
+#endif
+
+#include "asterisk/config.h"
+#include "asterisk/options.h"
+#include "asterisk/channel.h"
+#include "asterisk/cdr.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 *dsn = NULL, *username = NULL, *password = NULL, *table = NULL;
+static int loguniqueid = 0;
+static int usegmtime = 0;
+static int dispositionstring = 0;
+static int connected = 0;
+
+AST_MUTEX_DEFINE_STATIC(odbc_lock);
+
+static int odbc_do_query(void);
+static int odbc_init(void);
+
+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 void odbc_disconnect(void)
+{
+	SQLDisconnect(ODBC_con);
+	SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
+	SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+	connected = 0;
+}
+
+static int odbc_log(struct ast_cdr *cdr)
+{
+	int ODBC_res;
+	char sqlcmd[2048] = "", timestr[128];
+	int res = 0;
+	struct tm tm;
+
+	if (usegmtime) 
+		gmtime_r(&cdr->start.tv_sec,&tm);
+	else
+		localtime_r(&cdr->start.tv_sec,&tm);
+
+	ast_mutex_lock(&odbc_lock);
+	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+	memset(sqlcmd,0,2048);
+	if (loguniqueid) {
+		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
+		"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,"
+		"lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) "
+		"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
+	} else {
+		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
+		"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,"
+		"duration,billsec,disposition,amaflags,accountcode) "
+		"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
+	}
+
+	if (!connected) {
+		res = odbc_init();
+		if (res < 0) {
+			odbc_disconnect();
+			ast_mutex_unlock(&odbc_lock);
+			return 0;
+		}				
+	}
+
+	ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, ODBC_con, &ODBC_stmt);
+
+	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);
+		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+		odbc_disconnect();
+		ast_mutex_unlock(&odbc_lock);
+		return 0;
+	}
+
+	/* We really should only have to do this once.  But for some
+	   strange reason if I don't it blows holes in memory like
+	   like a shotgun.  So we just do this so its safe. */
+
+	ODBC_res = SQLPrepare(ODBC_stmt, (unsigned char *)sqlcmd, SQL_NTS);
+	
+	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);
+		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+		odbc_disconnect();
+		ast_mutex_unlock(&odbc_lock);
+		return 0;
+	}
+
+	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);
+	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);
+	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);
+
+	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);
+	}
+
+	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");
+			if (option_verbose > 10)
+				ast_verbose( VERBOSE_PREFIX_4 "cdr_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);
+				odbc_disconnect();
+			} else {
+				if (option_verbose > 10)
+					ast_verbose( VERBOSE_PREFIX_4 "cdr_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");
+				}
+			}
+		}
+	} else {
+		if (option_verbose > 10)
+			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
+	}
+	SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+	ast_mutex_unlock(&odbc_lock);
+	return 0;
+}
+
+static int odbc_unload_module(void)
+{
+	ast_mutex_lock(&odbc_lock);
+	if (connected) {
+		if (option_verbose > 10)
+			ast_verbose( VERBOSE_PREFIX_4 "cdr_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");
+		free(dsn);
+	}
+	if (username) {
+		if (option_verbose > 10)
+			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free username\n");
+		free(username);
+	}
+	if (password) {
+		if (option_verbose > 10)
+			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free password\n");
+		free(password);
+	}
+	if (table) {
+		if (option_verbose > 10)
+			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free table\n");
+		free(table);
+	}
+
+	ast_cdr_unregister(name);
+	ast_mutex_unlock(&odbc_lock);
+	return 0;
+}
+
+static int odbc_load_module(void)
+{
+	int res = 0;
+	struct ast_config *cfg;
+	struct ast_variable *var;
+	const char *tmp;
+
+	ast_mutex_lock(&odbc_lock);
+
+	cfg = ast_config_load(config);
+	if (!cfg) {
+		ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config);
+		res = AST_MODULE_LOAD_DECLINE;
+		goto out;
+	}
+	
+	var = ast_variable_browse(cfg, "global");
+	if (!var) {
+		/* nothing configured */
+		goto out;
+	}
+
+	tmp = ast_variable_retrieve(cfg,"global","dsn");
+	if (tmp == NULL) {
+		ast_log(LOG_WARNING,"cdr_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");
+		res = -1;
+		goto out;
+	}
+
+	tmp = ast_variable_retrieve(cfg,"global","dispositionstring");
+	if (tmp) {
+		dispositionstring = ast_true(tmp);
+	} else {
+		dispositionstring = 0;
+	}
+		
+	tmp = ast_variable_retrieve(cfg,"global","username");
+	if (tmp) {
+		username = strdup(tmp);
+		if (username == NULL) {
+			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
+			res = -1;
+			goto out;
+		}
+	}
+
+	tmp = ast_variable_retrieve(cfg,"global","password");
+	if (tmp) {
+		password = strdup(tmp);
+		if (password == NULL) {
+			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
+			res = -1;
+			goto out;
+		}
+	}
+
+	tmp = ast_variable_retrieve(cfg,"global","loguniqueid");
+	if (tmp) {
+		loguniqueid = ast_true(tmp);
+		if (loguniqueid) {
+			if (option_debug)
+				ast_log(LOG_DEBUG,"cdr_odbc: Logging uniqueid\n");
+		} else {
+			if (option_debug)
+				ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
+		}
+	} else {
+		if (option_debug)
+			ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
+		loguniqueid = 0;
+	}
+
+	tmp = ast_variable_retrieve(cfg,"global","usegmtime");
+	if (tmp) {
+		usegmtime = ast_true(tmp);
+		if (usegmtime) {
+			if (option_debug)
+				ast_log(LOG_DEBUG,"cdr_odbc: Logging in GMT\n");
+		} else {
+			if (option_debug)
+				ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
+		}
+	} else {
+		if (option_debug)
+			ast_log(LOG_DEBUG,"cdr_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";
+	}
+	table = strdup(tmp);
+	if (table == NULL) {
+		ast_log(LOG_ERROR,"cdr_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);
+		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");
+		}
+		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);
+	}
+	
+	res = odbc_init();
+	if (res < 0) {
+		ast_log(LOG_ERROR, "cdr_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");
+	}
+out:
+	if (cfg)
+		ast_config_destroy(cfg);
+	ast_mutex_unlock(&odbc_lock);
+	return res;
+}
+
+static int odbc_do_query(void)
+{
+	int ODBC_res;
+	
+	ODBC_res = SQLExecute(ODBC_stmt);
+	
+	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);
+		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");
+		connected = 1;
+	}
+	return 0;
+}
+
+static int odbc_init(void)
+{
+	int ODBC_res;
+
+	if (ODBC_env == SQL_NULL_HANDLE || connected == 0) {
+		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");
+			connected = 0;
+			return -1;
+		}
+
+		ODBC_res = SQLSetEnvAttr(ODBC_env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
+
+		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");
+			SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+			connected = 0;
+			return -1;
+		}
+
+		ODBC_res = SQLAllocHandle(SQL_HANDLE_DBC, ODBC_env, &ODBC_con);
+
+		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);
+			SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+			connected = 0;
+			return -1;
+		}
+		SQLSetConnectAttr(ODBC_con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)10, 0);	
+	}
+
+	/* Note that the username and password could be NULL here, but that is allowed in ODBC.
+           In this case, the default username and password will be used from odbc.conf */
+	ODBC_res = SQLConnect(ODBC_con, (SQLCHAR*)dsn, SQL_NTS, (SQLCHAR*)username, SQL_NTS, (SQLCHAR*)password, SQL_NTS);
+
+	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);
+		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);
+		connected = 1;
+	}
+	return 0;
+}
+
+static int load_module(void)
+{
+	return odbc_load_module();
+}
+
+static int unload_module(void)
+{
+	return odbc_unload_module();
+}
+
+static int reload(void)
+{
+	odbc_unload_module();
+	return odbc_load_module();
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ODBC CDR Backend",
+		.load = load_module,
+		.unload = unload_module,
+		.reload = reload,
+	       );

Propchange: team/murf/newcdr/cel/cel_odbc.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/newcdr/cel/cel_odbc.c
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/newcdr/cel/cel_odbc.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/murf/newcdr/cel/cel_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_pgsql.c?view=auto&rev=62082
==============================================================================
--- team/murf/newcdr/cel/cel_pgsql.c (added)
+++ team/murf/newcdr/cel/cel_pgsql.c Thu Apr 26 12:50:09 2007
@@ -1,0 +1,322 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2003 - 2006
+ *
+ * Matthew D. Hardeman <mhardemn at papersoft.com> 
+ * Adapted from the MySQL CDR logger originally by James Sharp 
+ *
+ * Modified September 2003
+ * Matthew D. Hardeman <mhardemn at papersoft.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief PostgreSQL CDR logger 
+ * 
+ * \author Matthew D. Hardeman <mhardemn at papersoft.com> 
+ * \extref PostgreSQL http://www.postgresql.org/
+ *
+ * See also
+ * \arg \ref Config_cdr
+ * \arg http://www.postgresql.org/
+ * \ingroup cdr_drivers
+ */
+
+/*** MODULEINFO
+	<depend>pgsql</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <libpq-fe.h>
+
+#include "asterisk/config.h"
+#include "asterisk/options.h"
+#include "asterisk/channel.h"
+#include "asterisk/cdr.h"
+#include "asterisk/module.h"
+#include "asterisk/logger.h"
+#include "asterisk.h"
+
+#define DATE_FORMAT "%Y-%m-%d %T"
+
+static char *name = "pgsql";
+static char *config = "cdr_pgsql.conf";
+static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL;
+static int connected = 0;
+

[... 3556 lines stripped ...]


More information about the svn-commits mailing list