[asterisk-commits] branch oej/test-this-branch r11690 - in /team/oej/test-this-branch: ./ cdr/ d...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Mar 3 03:59:39 MST 2006


Author: oej
Date: Fri Mar  3 04:59:35 2006
New Revision: 11690

URL: http://svn.digium.com/view/asterisk?rev=11690&view=rev
Log:
Adding CDR radius support

Added:
    team/oej/test-this-branch/cdr/cdr_radius.c   (with props)
Modified:
    team/oej/test-this-branch/README.test-this-branch
    team/oej/test-this-branch/cdr/Makefile
    team/oej/test-this-branch/doc/cdrdriver.txt
    team/oej/test-this-branch/res/Makefile

Modified: team/oej/test-this-branch/README.test-this-branch
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/README.test-this-branch?rev=11690&r1=11689&r2=11690&view=diff
==============================================================================
--- team/oej/test-this-branch/README.test-this-branch (original)
+++ team/oej/test-this-branch/README.test-this-branch Fri Mar  3 04:59:35 2006
@@ -23,6 +23,7 @@
 - subscribemwi: Support for SIP subscription of MWI notification (oej #6390)
 - iptos: New IPtos support, separate audio and signalling (#6355)
 - multiparking: Multiple parking lots (#6113)
+- cdr_radius: CDR support for Radius (#6639, phsultan). See doc/cdrdriver.txt
 
 And the following stand-alone patches
 - New CLI commands for global variables (oej, #6506)

Modified: team/oej/test-this-branch/cdr/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/cdr/Makefile?rev=11690&r1=11689&r2=11690&view=diff
==============================================================================
--- team/oej/test-this-branch/cdr/Makefile (original)
+++ team/oej/test-this-branch/cdr/Makefile Fri Mar  3 04:59:35 2006
@@ -28,6 +28,10 @@
 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/tds.h $(CROSS_COMPILE_TARGET)/usr/local/include/tds.h $(CROSS_COMPILE_TARGET)/usr/include/freetds/tds.h),)
   MODS:=$(filter-out cdr_tds.so,$(MODS))
   NOTDS=1
+endif
+
+ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/radiusclient-ng.h $(CROSS_COMPILE_TARGET)/usr/local/include/radiusclient-ng.h),)
+  MODS:=$(filter-out cdr_radius.so,$(MODS))
 endif
 
 ifeq (${OSARCH},CYGWIN)
@@ -131,6 +135,9 @@
 cdr_sqlite.so: cdr_sqlite.o
 	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
 
+cdr_radius.so: cdr_radius.o
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lradiusclient-ng $(MLFLAGS)
+
 depend: .depend
 
 .depend:

Added: team/oej/test-this-branch/cdr/cdr_radius.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/cdr/cdr_radius.c?rev=11690&view=auto
==============================================================================
--- team/oej/test-this-branch/cdr/cdr_radius.c (added)
+++ team/oej/test-this-branch/cdr/cdr_radius.c Fri Mar  3 04:59:35 2006
@@ -1,0 +1,211 @@
+/*
+ * 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 RADIUS CDR Support
+ * \author Philippe Sultan
+ * 
+ * \arg See also \ref AstCDR
+ * \ingroup cdr_drivers
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <radiusclient-ng.h>
+
+#define RC_CONFIG_FILE "/usr/local/etc/radiusclient-ng/radiusclient.conf"
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Rev$")
+
+#include "asterisk/channel.h"
+#include "asterisk/cdr.h"
+#include "asterisk/module.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+
+#define DATE_FORMAT "%Y-%m-%d %T"
+
+static char *desc = "RADIUS CDR Backend";
+
+static char *name = "radius";
+
+AST_MUTEX_DEFINE_STATIC(rc_lock);
+
+static rc_handle  *rh = NULL;
+
+
+static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
+{
+
+	int aux;
+	char buf[253];
+
+
+	aux = PW_STATUS_STOP;
+	if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &aux, 0, 0)) {
+		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
+		return -1;
+	}
+
+
+/* 	/\* Account code *\/ */
+/* 	append_string(buf, cdr->accountcode, bufsize); */
+ 	/* Source */
+	ast_copy_string(buf, cdr->src, sizeof(buf));
+	if (!rc_avpair_add(rh, send, PW_CALLING_STATION_ID, &buf, strlen(buf), 0)) {
+		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
+		return -1;
+	}
+
+ 	/* Destination */
+	ast_copy_string(buf, cdr->dst, sizeof(buf));
+	if (!rc_avpair_add(rh, send, PW_CALLED_STATION_ID, &buf, strlen(buf), 0)) {
+		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
+		return -1;
+	}
+
+/* 	/\* Destination context *\/ */
+/* 	append_string(buf, cdr->dcontext, bufsize); */
+/* 	/\* Caller*ID *\/ */
+/* 	append_string(buf, cdr->clid, bufsize); */
+/* 	/\* Channel *\/ */
+/* 	append_string(buf, cdr->channel, bufsize); */
+/* 	/\* Destination Channel *\/ */
+/* 	append_string(buf, cdr->dstchannel, bufsize); */
+/* 	/\* Last Application *\/ */
+/* 	append_string(buf, cdr->lastapp, bufsize); */
+/* 	/\* Last Data *\/ */
+/* 	append_string(buf, cdr->lastdata, bufsize); */
+/* 	/\* Start Time *\/ */
+/* 	append_date(buf, cdr->start, bufsize); */
+/* 	/\* Answer Time *\/ */
+/* 	append_date(buf, cdr->answer, bufsize); */
+/* 	/\* End Time *\/ */
+/* 	append_date(buf, cdr->end, bufsize); */
+
+ 	/* Duration */ 
+	aux = cdr->duration;
+	if (!rc_avpair_add(rh, send, PW_ACCT_SESSION_TIME, &cdr->duration, 0, 0)) {
+		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
+		return -1;
+	}
+
+/* 	/\* Billable seconds *\/ */
+/* 	append_int(buf, cdr->billsec, bufsize); */
+/* 	/\* Disposition *\/ */
+/* 	append_string(buf, ast_cdr_disp2str(cdr->disposition), bufsize); */
+/* 	/\* AMA Flags *\/ */
+/* 	append_string(buf, ast_cdr_flags2str(cdr->amaflags), bufsize); */
+
+/* #ifdef CSV_LOGUNIQUEID */
+/* 	/\* Unique ID *\/ */
+/* 	append_string(buf, cdr->uniqueid, bufsize); */
+/* #endif */
+/* #ifdef CSV_LOGUSERFIELD */
+/* 	/\* append the user field *\/ */
+/* 	append_string(buf, cdr->userfield,bufsize);	 */
+/* #endif */
+	return 1;
+}
+
+static int radius_log(struct ast_cdr *cdr)
+{
+	int result = ERROR_RC;
+	VALUE_PAIR *send = NULL;
+
+	ast_mutex_lock(&rc_lock);	
+	
+	if (!build_radius_record(&send, cdr)) {
+		ast_log(LOG_WARNING, "Unable to create RADIUS record. CDR not recorded!\n");
+	}
+	
+	result = rc_acct(rh, 0, send);
+	if (result == OK_RC) {
+		ast_log(LOG_NOTICE, "RADIUS CDR recorded.\n");
+	}
+	else {
+		ast_log(LOG_NOTICE, "Failed to record CDR.\n");
+	}
+
+	ast_mutex_unlock(&rc_lock);
+
+	return result;
+}
+
+char *description(void)
+{
+	return desc;
+}
+
+int unload_module(void)
+{
+	ast_cdr_unregister(name);
+	return 0;
+}
+
+int load_module(void)
+{
+	int res;
+
+	/* start logging */
+	rc_openlog("asterisk");
+
+	/* read radiusclient-ng config file */
+	if ((rh = rc_read_config(RC_CONFIG_FILE)) == NULL) {
+		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", RC_CONFIG_FILE);
+		return -1;
+	}
+
+	/* read radiusclient-ng dictionaries */
+	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
+		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
+		return -1;
+	}
+
+	res = ast_cdr_register(name, desc, radius_log);
+	if (res) {
+		ast_log(LOG_ERROR, "Unable to register RADIUS CDR handling\n");
+	}
+	return res;
+}
+
+int reload(void)
+{
+	return 0;
+}
+
+int usecount(void)
+{
+	return 0;
+}
+
+char *key()
+{
+	return ASTERISK_GPL_KEY;
+}

Propchange: team/oej/test-this-branch/cdr/cdr_radius.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/test-this-branch/cdr/cdr_radius.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/test-this-branch/cdr/cdr_radius.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/oej/test-this-branch/doc/cdrdriver.txt
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/doc/cdrdriver.txt?rev=11690&r1=11689&r2=11690&view=diff
==============================================================================
--- team/oej/test-this-branch/doc/cdrdriver.txt (original)
+++ team/oej/test-this-branch/doc/cdrdriver.txt Fri Mar  3 04:59:35 2006
@@ -166,6 +166,24 @@
 
 SQLLITE:
 
+RADIUS:		The Radius CDR driver builds upon the radiusclient-ng library
+		available at http://developer.berlios.de/projects/radiusclient-ng/
+		The CDR driver produces only 'stop' records.
+
+		Here is an example of a record, taken from a FreeRADIUS server
+		'detail' file, and running on the same computer :
+
+ 		Fri Mar 3 00:03:13 2006
+		        Acct-Status-Type = Stop
+        		Calling-Station-Id = "7899"
+        		Called-Station-Id = "0123456789"
+        		Acct-Session-Time = 57
+        		NAS-Port = 0
+        		Acct-Delay-Time = 0
+        		NAS-IP-Address = 127.0.0.1
+        		Acct-Unique-Session-Id = "bd030dd14f5ecbc5"
+        		Timestamp = 1141340593
+
 -------------------------------------------------------------------------------
 
 08/02/2004 : Duane Cox <dcox at illicom.net> - added mssql information

Modified: team/oej/test-this-branch/res/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/res/Makefile?rev=11690&r1=11689&r2=11690&view=diff
==============================================================================
--- team/oej/test-this-branch/res/Makefile (original)
+++ team/oej/test-this-branch/res/Makefile Fri Mar  3 04:59:35 2006
@@ -30,6 +30,15 @@
 OSPLIB:=$(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libosptk.a $(CROSS_COMPILE_TARGET)/usr/local/lib/libosptk.a)
 ifeq (${OSPLIB},)
   MODS:=$(filter-out res_osp.so,$(MODS))
+endif
+
+# NetSNMP is incompatible with the BSDs, until the loader changes are complete (conflict with unload_module())
+ifeq ($(OSARCH),Darwin)
+  MODS:=$(filter-out res_snmp.so,$(MODS))
+else
+  ifeq ($(findstring BSD,$(OSARCH)),BSD)
+    MODS:=$(filter-out res_snmp.so,$(MODS))
+  endif
 endif
 
 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/net-snmp/net-snmp-config.h),)



More information about the asterisk-commits mailing list