[Freeswitch-branches] [commit] r5116 - freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr
Freeswitch SVN
cparker at freeswitch.org
Wed May 9 16:46:31 EDT 2007
Author: cparker
Date: Wed May 9 16:46:31 2007
New Revision: 5116
Added:
freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/Makefile.am
freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.h
Removed:
freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/Makefile
Modified:
freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
Log:
Updated build params, and initial compilation fixes
Added: freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/Makefile.am
==============================================================================
--- (empty file)
+++ freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/Makefile.am Wed May 9 16:46:31 2007
@@ -0,0 +1,33 @@
+AM_CFLAGS = $(SWITCH_AM_CFLAGS)
+AM_CPPFLAGS = $(SWITCH_AM_CXXFLAGS)
+AM_LDFLAGS = $(SWITCH_AM_LDFLAGS)
+#we should set all these vars from configure, no reason to have these in each Makefile.am
+LIBTOOL = echo "`link=\`echo $@|grep .la;echo $@|grep .so;echo $@|grep .dll\`;if test -n "$$link"; then echo Creating $@;fi`";`if test -z "$(VERBOSE)" ; \
+then echo $(SHELL) $(switch_builddir)/quiet_libtool ;else echo $(SHELL) $(switch_builddir)/libtool; fi`
+AM_MAKEFLAGS=`test -n "$(VERBOSE)" || echo -s`
+# Dirty trick to override the link output
+LIBS+=> $(MODNAME).log || error="yes";if test -n "$(VERBOSE)" -o "$$error" = "yes";then cat $(MODNAME).log;fi;if test "$$error" = "yes";then exit 1;fi
+
+moddir=$(prefix)/mod
+
+MODNAME=mod_radius_cdr
+mod_LTLIBRARIES = mod_radius_cdr.la
+mod_radius_cdr_la_SOURCES = mod_radius_cdr.c
+mod_radius_cdr_la_CFLAGS = $(AM_CFLAGS) -l
+mod_radius_cdr_la_CPPFLAGS = $(AM_CPPFLAGS)
+mod_radius_cdr_la_LIBADD=$(switch_builddir)/libfreeswitch.la
+mod_radius_cdr_la_LDFLAGS=-module -avoid-version -no-undefined -export-symbols-regex ^switch_module_.*$ -rpath $(PREFIX)/$(libdir)
+
+mod_radius_cdr_la_LDFLAGS += -lfreeradius-client
+
+#Override the linstall target so we just install the .so/.dylib
+
+install-data-am: $(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN)
+
+$(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).la
+ @echo installing $(MODNAME).$(DYNAMIC_LIB_EXTEN)
+ @if [ -f .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) ] ; then \
+ $(LIBTOOL) --mode=install $(INSTALL) .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
+ else \
+ $(LIBTOOL) --mode=install $(INSTALL) $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
+ fi
Modified: freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
==============================================================================
--- freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c (original)
+++ freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c Wed May 9 16:46:31 2007
@@ -32,82 +32,47 @@
#include <sys/stat.h>
#include <switch.h>
#include <freeradius-client.h>
+#include "mod_radius_cdr.h"
static const char modname[] = "mod_radius_cdr";
static rc_handle *rad_config;
+static char cf[] = "mod_radius_cdr.conf";
+static char dictionary[PATH_MAX];
+static char * timeout; /* 5 */
+static char * retries; /* 3 */
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_xml_t cdr;
-
- if (switch_ivr_generate_radius_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
+ int retval = 0;
+ VALUE_PAIR *send = NULL;
+ UINT4 client_port = 0;
+ UINT4 status_type = PW_STATUS_STOP;
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
- }
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t load_config(void)
-{
- switch_status_t status = SWITCH_STATUS_SUCCESS;
- switch_xml_t cfg, xml, settings, param;
- char *cf = "radius_cdr.conf.xml";
- /* Config Variables and Defaults */
- char dictionary[PATH_MAX] = "/usr/local/freeswitch/conf/radius/dictionary";
- int num_servers = 0;
- char *timeout = NULL;
- char *retries = NULL;
-
- if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
- return SWITCH_STATUS_TERM;
- }
+ char src[] = "8475551212";
+ char *uuid_str;
- rad_config = rc_new();
- if (rad_config == NULL) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "initialization of radius_cdr_config structure failed\n");
- return SWITCH_STATUS_TERM;
- }
- timeout = "5";
- retries = "3";
+ if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
+ /*switch_channel_t *channel = switch_core_session_get_channel(session);*/
+ uuid_str = switch_core_session_get_uuid(session);
- if ((settings = switch_xml_child(cfg, "settings"))) {
- for (param = switch_xml_child(settings, "param"); param; param = param->next) {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
+ rad_config = rc_new();
- if (!strcmp(var, "acctserver")) {
- if (num_servers < SERVER_MAX) {
- if (rc_add_config(rad_config, var, val, cf, 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed setting %s = %s failed\n", var, val);
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
- }
- num_servers++;
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "you can only specify %d radius servers, ignoring excess server entry\n", SERVER_MAX);
- }
- }
- else if (!strcmp(var, "dictionary")) {
- strncpy(dictionary,val,PATH_MAX-1);
- }
- else if (!strcmp(var, "radius_timeout")) {
- timeout = strdup(val);
- }
- else if (!strcmp(var, "radius_retries")) {
- retries = strdup(val);
- }
+ if (rad_config == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing rc_handle!\n");
+ return SWITCH_STATUS_TERM;
+ switch_xml_free(cdr);
}
- }
- switch_xml_free(xml);
+ rad_config = rc_config_init(rad_config);
- if(num_servers > 0) {
+ if (rad_config == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius config!\n");
+ rc_destroy(rad_config);
+ switch_xml_free(cdr);
+ return SWITCH_STATUS_TERM;
+ }
if (rc_add_config(rad_config, "dictionary", dictionary, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
@@ -115,12 +80,14 @@
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
+
if (rc_add_config(rad_config, "radius_timeout", timeout, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed setting radius_timeout = %s failed\n", timeout);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
+
if (rc_add_config(rad_config, "radius_timeout", timeout, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed setting radius_retries = %s failed\n", retries);
@@ -151,9 +118,100 @@
}
} else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
+ return SWITCH_STATUS_TERM;
+ }
+
+ /* Create the radius packet */
+
+ /* Set Status Type */
+ if (rc_avpair_add(rad_config, &send, PW_ACCT_STATUS_TYPE, &status_type, -1, 0) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+
+ if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+
+ /* Add VSA */
+ if (rc_avpair_add(rad_config, &send, PW_FS_SRC, src, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", src);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+
+ if(rc_acct(rad_config, client_port, send) == OK_RC) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RADIUS Accounting OK\n");
+ retval = SWITCH_STATUS_SUCCESS;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RADIUS Accounting Failed\n");
+ retval = SWITCH_STATUS_TERM;
+ }
+ rc_avpair_free(send);
+
+ return(retval);
+}
+
+static switch_status_t load_config(void)
+{
+ switch_xml_t cfg, xml, settings, param;
+
+ /* Config Variables and Defaults */
+ /*char *cf = "radius_cdr.conf.xml";*/
+ /*char dictionary[PATH_MAX] = "/usr/local/freeswitch/conf/radius/dictionary";*/
+ /*char *timeout = NULL;*/
+ /*char *retries = NULL;*/
+
+ int num_servers = 0;
+
+ timeout = "5";
+ retries = "3";
+
+ if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+ return SWITCH_STATUS_TERM;
+ }
+
+ if ((settings = switch_xml_child(cfg, "settings"))) {
+ for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+
+ if (!strcmp(var, "acctserver")) {
+ if (num_servers < SERVER_MAX) {
+ if (rc_add_config(rad_config, var, val, cf, 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed setting %s = %s failed\n", var, val);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+ num_servers++;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "you can only specify %d radius servers, ignoring excess server entry\n", SERVER_MAX);
+ }
+ }
+ else if (!strcmp(var, "dictionary")) {
+ strncpy(dictionary,val,PATH_MAX-1);
+ }
+ else if (!strcmp(var, "radius_timeout")) {
+ timeout = strdup(val);
+ }
+ else if (!strcmp(var, "radius_retries")) {
+ retries = strdup(val);
+ }
+ }
+ }
+
+ switch_xml_free(xml);
+
+ if(num_servers < 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"you must specify at least 1 radius server\n");
- rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
Added: freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.h
==============================================================================
--- (empty file)
+++ freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.h Wed May 9 16:46:31 2007
@@ -0,0 +1,59 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
+ * Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
+ *
+ * The Initial Developer of the Original Code is
+ * Chris Parker <cparker AT segv.org>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Chris Parker <cparker AT segv.org>
+ *
+ * Description: Contains definitions and structs used by the radius cdr module.
+ *
+ * mod_radius_cdr.h
+ *
+ */
+
+#ifndef MODRADIUSCDR
+#define MODRADIUSCDR
+
+#define PW_FS_PEC 27880
+
+#define PW_FS_AVPAIR 1
+#define PW_FS_CLID 2
+#define PW_FS_DIALPLAN 3
+#define PW_FS_SRC 4
+#define PW_FS_DST 5
+#define PW_FS_SRC_CHANNEL 6
+#define PW_FS_DST_CHANNEL 7
+#define PW_FS_ANI 8
+#define PW_FS_ANIII 9
+#define PW_FS_LASTAPP 10
+#define PW_FS_LASTDATA 11
+#define PW_FS_DISPOSITION 12
+#define PW_FS_HANGUPCAUSE 13
+#define PW_FS_BILLUSEC 15
+#define PW_FS_AMAFLAGS 16
+#define PW_FS_CALLSTARTDATE 20
+#define PW_FS_CALLANSWERDATE 21
+#define PW_FS_CALLTRANSFERDATE 22
+#define PW_FS_CALLENDDATE 23
+
+#endif
More information about the Freeswitch-branches
mailing list