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

Freeswitch SVN cparker at freeswitch.org
Fri Feb 23 16:14:16 EST 2007


Author: cparker
Date: Fri Feb 23 16:14:15 2007
New Revision: 4380

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

Log:
Initital standalone radius_cdr event handler

Added: freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
==============================================================================
--- (empty file)
+++ freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c	Fri Feb 23 16:14:15 2007
@@ -0,0 +1,207 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.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
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Chris Parker <cparker at segv.org>
+ *
+ *
+ * mod_radius_cdr.c -- RADIUS CDR Module
+ *
+ */
+#include <sys/stat.h>
+#include <switch.h>
+#include <freeradius-client.h>
+
+static const char modname[] = "mod_radius_cdr";
+
+static rc_handle 	*rad_config;
+
+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) {
+
+	} 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;
+	int	*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;
+        }
+
+	rh = rc_new();
+	if (rh == 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 ((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 < MAX_SERVERS) {
+					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", MAX_SERVERS);
+				}
+			}
+                        if (!strcmp(var, "dictionary")) {
+				strncpy(dictionary,val,PATH_MAX-1);
+			}
+			if (!strcmp(var, "radius_timeout")) {
+				timeout = strdup(val);
+			}
+			if (!strcmp(var, "radius_retries")) {
+				retries = strdup(val);
+			}
+		}
+	}
+
+	switch_xml_free(xml);
+
+	if(num_servers > 0) {
+
+		if (rc_add_config(rad_config, "dictionary", dictionary, cf, 0) != 0) {
+	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
+					"failed setting dictionary = %s failed\n", dictionary);
+			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);
+			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) {
+	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
+					"failed setting auth_order = radius failed\n");
+			rc_destroy(rad_config);
+	                return SWITCH_STATUS_TERM;
+		}
+		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 seqfile =  /var/run/radius.seq\n");
+			rc_destroy(rad_config);
+	                return SWITCH_STATUS_TERM;
+		}
+
+		/* Read the dictionary file(s) */
+		if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
+	                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
+					"failed reading dictionary file(s): %s\n", dictionary);
+			rc_destroy(rad_config);
+	                return SWITCH_STATUS_TERM;
+		}
+
+	} else {
+		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;
+	}
+
+	/* If we made it this far, we succeeded */
+	return SWITCH_STATUS_SUCCESS
+}
+
+static const switch_state_handler_table_t state_handlers = {
+	/*.on_init */ NULL,
+	/*.on_ring */ NULL,
+	/*.on_execute */ NULL,
+	/*.on_hangup */ my_on_hangup,
+	/*.on_loopback */ NULL,
+	/*.on_transmit */ NULL
+};
+
+
+static const switch_loadable_module_interface_t mod_radius_cdr_module_interface = {
+	/*.module_name = */ modname,
+	/*.endpoint_interface = */ NULL,
+	/*.timer_interface = */ NULL,
+	/*.dialplan_interface = */ NULL,
+	/*.codec_interface = */ NULL,
+	/*.application_interface */ NULL
+};
+
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
+{
+	if (load_config() != SWITCH_STATUS_SUCCESS) {
+                return SWITCH_STATUS_TERM;
+        }
+
+	/* test global state handlers */
+	switch_core_add_state_handler(&state_handlers);
+
+	*module_interface = &mod_radius_cdr_module_interface;
+
+	/* indicate that the module should continue to be loaded */
+	return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
+ */



More information about the Freeswitch-branches mailing list