[asterisk-commits] seanbright: branch seanbright/NoLossCDR-Redux r104068 - in /team/seanbright/N...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Feb 23 15:08:36 CST 2008


Author: seanbright
Date: Sat Feb 23 15:08:35 2008
New Revision: 104068

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104068
Log:
Add a second argument to write_cdr that allows the CDR system to pass sink
configuration information in at log time.  Update the CDR modules to accept this
second argument.

Removed the default sink creation that we were doing when registering the
backend and delegate this responsibilty to the CDR modules.  CSV is the only one
to create a sink at this point.

Modified:
    team/seanbright/NoLossCDR-Redux/cdr/cdr_adaptive_odbc.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_csv.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_custom.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_manager.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_odbc.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_pgsql.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite3_custom.c
    team/seanbright/NoLossCDR-Redux/cdr/cdr_tds.c
    team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h
    team/seanbright/NoLossCDR-Redux/main/cdr.c
    team/seanbright/NoLossCDR-Redux/res/res_config_sqlite.c

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_adaptive_odbc.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_adaptive_odbc.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_adaptive_odbc.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_adaptive_odbc.c Sat Feb 23 15:08:35 2008
@@ -323,7 +323,7 @@
 				}																\
 			} while (0)
 
-static int odbc_log(struct ast_cdr *cdr)
+static int odbc_log(struct ast_cdr *cdr, void *configuration)
 {
 	struct tables *tableptr;
 	struct columns *entry;

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_csv.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_csv.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_csv.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_csv.c Sat Feb 23 15:08:35 2008
@@ -258,7 +258,7 @@
 		return -1;
 	}
 
-	snprintf(tmp, sizeof(tmp), "%s/%s/%s.csv", ast_config_AST_LOG_DIR,CSV_LOG_DIR, acc);
+	snprintf(tmp, sizeof(tmp), "%s/%s/%s.csv", ast_config_AST_LOG_DIR, CSV_LOG_DIR, acc);
 
 	ast_mutex_lock(&acf_lock);
 	if (!(f = fopen(tmp, "a"))) {
@@ -274,8 +274,7 @@
 	return 0;
 }
 
-
-static int csv_log(struct ast_cdr *cdr)
+static int csv_log(struct ast_cdr *cdr, void *configuration)
 {
 	FILE *mf = NULL;
 	/* Make sure we have a big enough buf */
@@ -323,10 +322,13 @@
 {
 	int res;
 	
-	if(!load_config(0))
+	if (!load_config(0))
 		return AST_MODULE_LOAD_DECLINE;
 
 	if ((res = ast_cdr_register(name, ast_module_info->description, csv_log, NULL)))
+		ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n");
+
+	if ((res = ast_cdr_register_sink(name, "Master.csv", NULL)))
 		ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n");
 
 	return res;

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_custom.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_custom.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_custom.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_custom.c Sat Feb 23 15:08:35 2008
@@ -100,9 +100,7 @@
 	return res;
 }
 
-
-
-static int custom_log(struct ast_cdr *cdr)
+static int custom_log(struct ast_cdr *cdr, void *configuration)
 {
 	/* Make sure we have a big enough buf */
 	char buf[2048];

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_manager.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_manager.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_manager.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_manager.c Sat Feb 23 15:08:35 2008
@@ -48,7 +48,7 @@
 static int enablecdr = 0;
 struct ast_str *customfields;
 
-static int manager_log(struct ast_cdr *cdr);
+static int manager_log(struct ast_cdr *cdr, void *configuration);
 
 static int load_config(int reload)
 {
@@ -115,7 +115,7 @@
 	return 1;
 }
 
-static int manager_log(struct ast_cdr *cdr)
+static int manager_log(struct ast_cdr *cdr, void *configuration)
 {
 	struct ast_tm timeresult;
 	char strStartTime[80] = "";

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_odbc.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_odbc.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_odbc.c Sat Feb 23 15:08:35 2008
@@ -123,8 +123,7 @@
 	return stmt;
 }
 
-
-static int odbc_log(struct ast_cdr *cdr)
+static int odbc_log(struct ast_cdr *cdr, void *configuration)
 {
 	struct odbc_obj *obj = ast_odbc_request_obj(dsn, 0);
 	SQLHSTMT stmt;

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_pgsql.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_pgsql.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_pgsql.c Sat Feb 23 15:08:35 2008
@@ -61,7 +61,7 @@
 
 static PGconn	*conn = NULL;
 
-static int pgsql_log(struct ast_cdr *cdr)
+static int pgsql_log(struct ast_cdr *cdr, void *configuration)
 {
 	struct ast_tm tm;
 	char sqlcmd[2048] = "", timestr[128];

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite.c Sat Feb 23 15:08:35 2008
@@ -87,7 +87,7 @@
 #endif
 ");";
 
-static int sqlite_log(struct ast_cdr *cdr)
+static int sqlite_log(struct ast_cdr *cdr, void *configuration)
 {
 	int res = 0;
 	char *zErr = 0;

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite3_custom.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite3_custom.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite3_custom.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_sqlite3_custom.c Sat Feb 23 15:08:35 2008
@@ -238,7 +238,7 @@
 	return 0;
 }
 
-static int sqlite3_log(struct ast_cdr *cdr)
+static int sqlite3_log(struct ast_cdr *cdr, void *configuration)
 {
 	int res = 0;
 	char *error = NULL;

Modified: team/seanbright/NoLossCDR-Redux/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/cdr/cdr_tds.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/cdr/cdr_tds.c (original)
+++ team/seanbright/NoLossCDR-Redux/cdr/cdr_tds.c Sat Feb 23 15:08:35 2008
@@ -101,7 +101,7 @@
 static int mssql_connect(void);
 static int mssql_disconnect(void);
 
-static int tds_log(struct ast_cdr *cdr)
+static int tds_log(struct ast_cdr *cdr, void *configuration)
 {
 	char sqlcmd[2048], start[80], answer[80], end[80];
 	char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid;

Modified: team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h (original)
+++ team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h Sat Feb 23 15:08:35 2008
@@ -107,7 +107,7 @@
 int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
 int ast_cdr_log_unanswered(void);
 
-typedef int (*ast_cdr_backend_func)(struct ast_cdr *cdr);
+typedef int (*ast_cdr_backend_func)(struct ast_cdr *cdr, void *sink_config);
 typedef void (*ast_cdr_backend_cleanup_func)(void *sink_config);
 
 /*! \brief Return TRUE if CDR subsystem is enabled */

Modified: team/seanbright/NoLossCDR-Redux/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/main/cdr.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/main/cdr.c (original)
+++ team/seanbright/NoLossCDR-Redux/main/cdr.c Sat Feb 23 15:08:35 2008
@@ -63,7 +63,7 @@
 
 struct ast_cdr_backend {
 	char name[20];
-	char desc[80];
+	char description[80];
 	ast_cdr_backend_func write_cdr;
 	ast_cdr_backend_cleanup_func cleanup;
 
@@ -120,7 +120,7 @@
 /*! Register a CDR driver. Each registered CDR driver generates a CDR 
 	\return 0 on success, -1 on failure 
 */
-int ast_cdr_register(const char *name, const char *desc, ast_cdr_backend_func backend_func, ast_cdr_backend_cleanup_func cleanup_func)
+int ast_cdr_register(const char *name, const char *description, ast_cdr_backend_func backend_func, ast_cdr_backend_cleanup_func cleanup_func)
 {
 	struct ast_cdr_backend *backend = NULL;
 
@@ -150,16 +150,13 @@
 	backend->cleanup = cleanup_func;
 
 	ast_copy_string(backend->name, name, sizeof(backend->name));
-	ast_copy_string(backend->desc, desc, sizeof(backend->desc));
+	ast_copy_string(backend->description, description, sizeof(backend->description));
 
 	/* Initialize our sink list */
 	AST_LIST_HEAD_INIT_NOLOCK(&backend->sinks);
 
 	AST_RWLIST_INSERT_HEAD(&backends, backend, list);
 	AST_RWLIST_UNLOCK(&backends);
-
-	/* Create a default sink */
-	ast_cdr_register_sink(backend->name, "(default)", NULL);
 
 	return 0;
 }
@@ -347,7 +344,7 @@
 }
 
 /* readonly cdr variables */
-static	const char *cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel",
+static const char *cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel",
 				    "lastapp", "lastdata", "start", "answer", "end", "duration",
 				    "billsec", "disposition", "amaflags", "accountcode", "uniqueid",
 				    "userfield", NULL };
@@ -1069,7 +1066,7 @@
 		AST_RWLIST_RDLOCK(&backends);
 		AST_RWLIST_TRAVERSE(&backends, backend, list) {
 			AST_LIST_TRAVERSE(&backend->sinks, sink, list) {
-				backend->write_cdr(cdr);
+				backend->write_cdr(cdr, sink->configuration);
 			}
 		}
 		AST_RWLIST_UNLOCK(&backends);
@@ -1301,6 +1298,7 @@
 static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_cdr_backend *backend = NULL;
+	struct ast_cdr_backend_sink *sink = NULL;
 	int cnt = 0;
 	long nextbatchtime = 0;
 
@@ -1334,11 +1332,21 @@
 			ast_cli(a->fd, "CDR maximum batch time: %d second%s\n", batchtime, ESS(batchtime));
 			ast_cli(a->fd, "CDR next scheduled batch processing time: %ld second%s\n", nextbatchtime, ESS(nextbatchtime));
 		}
+		ast_cli(a->fd, "\n");
+		ast_cli(a->fd, "Registered Backends\n");
+		ast_cli(a->fd, "-------------------\n");
 		AST_RWLIST_RDLOCK(&backends);
-		AST_RWLIST_TRAVERSE(&backends, backend, list) {
-			ast_cli(a->fd, "CDR registered backend: %s\n", backend->name);
+		if (AST_RWLIST_EMPTY(&backends)) {
+		} else {
+			AST_RWLIST_TRAVERSE(&backends, backend, list) {
+				ast_cli(a->fd, "  %s (%s)\n", backend->description, backend->name);
+				AST_LIST_TRAVERSE(&backend->sinks, sink, list) {
+					ast_cli(a->fd, "    Sink: %s\n", sink->name);
+				}
+			}
 		}
 		AST_RWLIST_UNLOCK(&backends);
+		ast_cli(a->fd, "\n");
 	}
 
 	return CLI_SUCCESS;

Modified: team/seanbright/NoLossCDR-Redux/res/res_config_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/NoLossCDR-Redux/res/res_config_sqlite.c?view=diff&rev=104068&r1=104067&r2=104068
==============================================================================
--- team/seanbright/NoLossCDR-Redux/res/res_config_sqlite.c (original)
+++ team/seanbright/NoLossCDR-Redux/res/res_config_sqlite.c Sat Feb 23 15:08:35 2008
@@ -239,7 +239,7 @@
  * \retval 0 on success
  * \retval 1 if an error occurred
  */
-static int cdr_handler(struct ast_cdr *cdr);
+static int cdr_handler(struct ast_cdr *cdr, void *configuration);
 
 /*!
  * \brief SQLite callback function for static configuration.
@@ -654,7 +654,7 @@
 	cdr_table = NULL;
 }
 
-static int cdr_handler(struct ast_cdr *cdr)
+static int cdr_handler(struct ast_cdr *cdr, void *configuration)
 {
 	char *query, *errormsg;
 	int error;




More information about the asterisk-commits mailing list