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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Feb 23 14:25:37 CST 2008


Author: seanbright
Date: Sat Feb 23 14:25:37 2008
New Revision: 104067

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104067
Log:
Add new function ast_cdr_register_sink to register a new CDR sink and document
it.  Fixed up the ast_cdr_register documentation.  Removed the stub
create_default_sink function.

Modified:
    team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h
    team/seanbright/NoLossCDR-Redux/main/cdr.c

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=104067&r1=104066&r2=104067
==============================================================================
--- team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h (original)
+++ team/seanbright/NoLossCDR-Redux/include/asterisk/cdr.h Sat Feb 23 14:25:37 2008
@@ -162,13 +162,25 @@
 /*! 
  * \brief Register a CDR handling engine 
  * \param name name associated with the particular CDR handler
- * \param desc description of the CDR handler
- * \param be function pointer to a CDR handler
+ * \param description description of the CDR handler
+ * \param backend_func function pointer to a CDR handler
+ * \param cleanup_func function pointer to a cleanup handler
  * Used to register a Call Detail Record handler.
  * \retval 0 on success.
  * \retval -1 on error
  */
-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);
+
+/*!
+ * \brief Register a CDR handling engine sink
+ * \param backend_name CDR backend this sink will belong to
+ * \param sink_name name associated with the particular CDR backend sink
+ * \param configuration pointer to the configuration data for this sink
+ * Used to register a Call Detail Record logging sink
+ * \retval 0 on success
+ * \retval -1 on error
+ */
+int ast_cdr_register_sink(const char *backend_name, const char *sink_name, void *configuration);
 
 /*! 
  * \brief Unregister a CDR handling engine 

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=104067&r1=104066&r2=104067
==============================================================================
--- team/seanbright/NoLossCDR-Redux/main/cdr.c (original)
+++ team/seanbright/NoLossCDR-Redux/main/cdr.c Sat Feb 23 14:25:37 2008
@@ -117,8 +117,6 @@
 	return unanswered;
 }
 
-static void create_default_sink(struct ast_cdr_backend *backend);
-
 /*! Register a CDR driver. Each registered CDR driver generates a CDR 
 	\return 0 on success, -1 on failure 
 */
@@ -157,29 +155,50 @@
 	/* Initialize our sink list */
 	AST_LIST_HEAD_INIT_NOLOCK(&backend->sinks);
 
-	/* Create a default sink */
-	create_default_sink(backend);
-
 	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;
 }
 
-static void create_default_sink(struct ast_cdr_backend *backend)
-{
+int ast_cdr_register_sink(const char *backend_name, const char *sink_name, void *configuration)
+{
+	struct ast_cdr_backend *backend = NULL;
 	struct ast_cdr_backend_sink *sink = NULL;
 
-	sink = ast_calloc(1, sizeof(*sink));
-	if (!sink) {
-		return;
-	}
-
-	ast_copy_string(sink->name, "(default)", sizeof(sink->name));
-
+	AST_RWLIST_WRLOCK(&backends);
+
+	/* First we try to find our backend */
+	AST_RWLIST_TRAVERSE(&backends, backend, list) {
+		if (!strcasecmp(backend_name, backend->name))
+			break;
+	}
+	if (!backend) {
+		ast_log(LOG_WARNING, "Cannot find CDR backend named: %s\n", backend_name);
+		AST_RWLIST_UNLOCK(&backends);
+		return -1;
+	}
+	/* Then see if we already have this sink registered */
+	AST_LIST_TRAVERSE(&backend->sinks, sink, list) {
+		if (!strcasecmp(sink_name, sink->name)) {
+			ast_log(LOG_WARNING, "The CDR sink named '%s' is already registered\n", sink_name);
+			AST_RWLIST_UNLOCK(&backends);
+			return -1;
+		}
+	}
+	/* Not registered yet, so we go ahead and do that */
+	if (!(sink = ast_calloc(1, sizeof(*sink)))) {
+		AST_RWLIST_UNLOCK(&backends);
+		return -1;
+	}
+	ast_copy_string(sink->name, sink_name, sizeof(sink->name));
 	AST_LIST_INSERT_TAIL(&backend->sinks, sink, list);
-
-	return;
+	AST_RWLIST_UNLOCK(&backends);
+
+	return 0;
 }
 
 /*! unregister a CDR driver */




More information about the asterisk-commits mailing list