[Freeswitch-svn] [commit] r5132 - freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr

Freeswitch SVN cparker at freeswitch.org
Thu May 10 15:28:39 EDT 2007


Author: cparker
Date: Thu May 10 15:28:39 2007
New Revision: 5132

Modified:
   freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c

Log:
make it actually work

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	Thu May 10 15:28:39 2007
@@ -29,22 +29,26 @@
  * mod_radius_cdr.c -- RADIUS CDR Module
  *
  */
-#include <sys/stat.h>
+
+#define _BSD_SOURCE 1
+
 #include <switch.h>
+#include <sys/stat.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 char		my_dictionary[PATH_MAX];
+static char *		my_timeout; /* 5 */
+static char *		my_retries; /* 3 */
+static char		my_servers[SERVER_MAX][255];
 
 static switch_status_t my_on_hangup(switch_core_session_t *session)
 {
-	switch_xml_t cdr;
+	switch_xml_t 	cdr;
+	rc_handle 	*rad_config;
 	int             retval = 0;
 	VALUE_PAIR      *send = NULL;
 	UINT4           client_port = 0;
@@ -53,58 +57,70 @@
 	char		src[] = "8475551212";
 	char 		*uuid_str;
 
-	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);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Entering my_on_hangup\n");
 
-		rad_config = rc_new();
+	rad_config = rc_new();
 
-		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);
-		}
+	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;
+	}
 
-		rad_config = rc_config_init(rad_config);
+	rad_config = rc_config_init(rad_config);
 
-		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 (rad_config == NULL) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius config!\n");
+		rc_destroy(rad_config);
+		return SWITCH_STATUS_TERM;
+	}	
 
-		if (rc_add_config(rad_config, "dictionary", dictionary, cf, 0) != 0) {
+	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);
+
+		/* Some hardcoded ( for now ) defaults needed to initialize radius */
+		if (rc_add_config(rad_config, "auth_order", "radius", "internal radius config", 0) != 0) {
 	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-					"failed setting dictionary = %s failed\n", dictionary);
+					"failed setting auth_order = radius failed\n");
 			rc_destroy(rad_config);
 	                return SWITCH_STATUS_TERM;
 		}
 
-		if (rc_add_config(rad_config, "radius_timeout", timeout, cf, 0) != 0) {
+		if (rc_add_config(rad_config, "seqfile", "/var/run/radius.seq", "internal radius config", 0) != 0) {
 	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-					"failed setting radius_timeout = %s failed\n", timeout);
+					"failed setting seqfile =  /var/run/radius.seq\n");
 			rc_destroy(rad_config);
 	                return SWITCH_STATUS_TERM;
 		}
 
-		if (rc_add_config(rad_config, "radius_timeout", timeout, cf, 0) != 0) {
+
+		/* Add the module configs to initialize rad_config */
+
+		for (int i = 0; i < SERVER_MAX && my_servers[i][0] != '\0'; i++) {
+			if (rc_add_config(rad_config, "acctserver", my_servers[i], cf, 0) != 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting acctserver = %s failed\n", my_servers[i]);
+				rc_destroy(rad_config);
+				return SWITCH_STATUS_TERM;
+			}
+		}
+
+		if (rc_add_config(rad_config, "dictionary", my_dictionary, cf, 0) != 0) {
 	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-					"failed setting radius_retries = %s failed\n", retries);
+					"failed setting dictionary = %s failed\n", my_dictionary);
 			rc_destroy(rad_config);
 	                return SWITCH_STATUS_TERM;
 		}
 
-		/* Some hardcoded ( for now ) defaults needed to initialize radius */
-		if (rc_add_config(rad_config, "auth_order", "radius", "internal radius config", 0) != 0) {
+		if (rc_add_config(rad_config, "radius_timeout", my_timeout, cf, 0) != 0) {
 	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-					"failed setting auth_order = radius failed\n");
+					"failed setting radius_timeout = %s failed\n", my_timeout);
 			rc_destroy(rad_config);
 	                return SWITCH_STATUS_TERM;
 		}
-		if (rc_add_config(rad_config, "seqfile", "/var/run/radius.seq", "internal radius config", 0) != 0) {
+
+		if (rc_add_config(rad_config, "radius_retries", my_retries, cf, 0) != 0) {
 	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-					"failed setting seqfile =  /var/run/radius.seq\n");
+					"failed setting radius_retries = %s failed\n", my_retries);
 			rc_destroy(rad_config);
 	                return SWITCH_STATUS_TERM;
 		}
@@ -112,7 +128,7 @@
 		/* Read the dictionary file(s) */
 		if (rc_read_dictionary(rad_config, rc_conf_str(rad_config, "dictionary")) != 0) {
 	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-					"failed reading dictionary file(s): %s\n", dictionary);
+					"failed reading dictionary file(s): %s\n", my_dictionary);
 			rc_destroy(rad_config);
 	                return SWITCH_STATUS_TERM;
 		}
@@ -160,16 +176,14 @@
 {
         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";
+	my_timeout = "5";
+	my_retries = "3";
+
+	for( int i = 0; i < SERVER_MAX; i++ ) {
+		my_servers[i][0] = '\0';
+	}
 
         if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@@ -183,12 +197,7 @@
 
                         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;
-					}
+					strncpy(my_servers[num_servers],val,255-1);
 					num_servers++;
 				} else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
@@ -196,13 +205,13 @@
 				}
 			}
                         else if (!strcmp(var, "dictionary")) {
-				strncpy(dictionary,val,PATH_MAX-1);
+				strncpy(my_dictionary,val,PATH_MAX-1);
 			}
 			else if (!strcmp(var, "radius_timeout")) {
-				timeout = strdup(val);
+				my_timeout = strdup(val);
 			}
 			else if (!strcmp(var, "radius_retries")) {
-				retries = strdup(val);
+				my_retries = strdup(val);
 			}
 		}
 	}



More information about the Freeswitch-svn mailing list