indent pass 2

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2008-05-27 04:54:52 +00:00
1 parent 9bbcabbbdd
commit f930eaeec7
101 files changed
+31644 -31458

No files matched your search

@@ -37,7 +37,7 @@ struct cdr_fd {
};
typedef struct cdr_fd cdr_fd_t;
const char *default_template =
const char *default_template =
"\"${caller_id_name}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${start_stamp}\","
"\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${uuid}\",\"${bleg_uuid}\", \"${accountcode}\"\n";
@@ -58,12 +58,12 @@ SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, NULL, NULL);
static off_t fd_size(int fd)
{
struct stat s = {0};
struct stat s = { 0 };
fstat(fd, &s);
return s.st_size;
}
static void do_reopen(cdr_fd_t *fd)
static void do_reopen(cdr_fd_t *fd)
{
int x = 0;
@@ -72,7 +72,7 @@ static void do_reopen(cdr_fd_t *fd)
fd->fd = -1;
}
for (x = 0 ; x < 10; x++) {
for (x = 0; x < 10; x++) {
if ((fd->fd = open(fd->path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) > -1) {
fd->bytes = fd_size(fd->fd);
break;
@@ -95,7 +95,7 @@ static void do_rotate(cdr_fd_t *fd)
if (globals.rotate) {
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
len = strlen(fd->path) + strlen(date) + 2;
p = switch_mprintf("%s.%s", fd->path, date);
assert(p);
@@ -104,7 +104,7 @@ static void do_rotate(cdr_fd_t *fd)
}
do_reopen(fd);
if (fd->fd < 0) {
switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening %s\n", fd->path);
@@ -115,14 +115,14 @@ static void do_rotate(cdr_fd_t *fd)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s CDR logfile %s\n", globals.rotate ? "Rotated" : "Re-opened", fd->path);
}
}
static void write_cdr(const char *path, const char *log_line)
{
cdr_fd_t *fd = NULL;
unsigned int bytes_in, bytes_out;
if (!(fd = switch_core_hash_find(globals.fd_hash, path))) {
fd = switch_core_alloc(globals.pool, sizeof(*fd));
switch_assert(fd);
@@ -132,10 +132,10 @@ static void write_cdr(const char *path, const char *log_line)
fd->path = switch_core_strdup(globals.pool, path);
switch_core_hash_insert(globals.fd_hash, path, fd);
}
switch_mutex_lock(fd->mutex);
bytes_out = (unsigned)strlen(log_line);
bytes_out = (unsigned) strlen(log_line);
if (fd->fd < 0) {
do_reopen(fd);
if (fd->fd < 0) {
@@ -143,18 +143,18 @@ static void write_cdr(const char *path, const char *log_line)
goto end;
}
}
if (fd->bytes + bytes_out > UINT_MAX) {
do_rotate(fd);
}
if ((bytes_in = write(fd->fd, log_line, bytes_out)) != bytes_out) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d\n", path, (int)bytes_in, (int)bytes_out);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d\n", path, (int) bytes_in, (int) bytes_out);
}
fd->bytes += bytes_in;
end:
end:
switch_mutex_unlock(fd->mutex);
}
@@ -164,7 +164,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL;
char *log_line, *path = NULL;
char *log_line, *path = NULL;
if (switch_channel_get_originator_caller_profile(channel)) {
return SWITCH_STATUS_SUCCESS;
@@ -173,7 +173,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (!(log_dir = switch_channel_get_variable(channel, "cdr_csv_base"))) {
log_dir = globals.log_dir;
}
if (switch_dir_make_recursive(log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", log_dir);
return SWITCH_STATUS_FALSE;
@@ -193,15 +193,15 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
}
g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);
if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) {
a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode);
}
if (!a_template_str) {
a_template_str = g_template_str;
}
log_line = switch_channel_expand_variables(channel, a_template_str);
if (accountcode) {
@@ -210,21 +210,21 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
write_cdr(path, log_line);
free(path);
}
if (g_template_str != a_template_str) {
if (log_line && log_line != a_template_str) {
switch_safe_free(log_line);
}
log_line = switch_channel_expand_variables(channel, g_template_str);
}
path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR);
assert(path);
write_cdr(path, log_line);
free(path);
if (log_line && log_line != g_template_str) {
free(log_line);
@@ -237,7 +237,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
static void event_handler(switch_event_t *event)
{
const char *sig = switch_event_get_header(event, "Trapped-Signal");
switch_hash_index_t *hi;
switch_hash_index_t *hi;
void *val;
cdr_fd_t *fd;
@@ -269,18 +269,18 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
char *cf = "cdr_csv.conf";
switch_xml_t cfg, xml, settings, param;
switch_status_t status = SWITCH_STATUS_SUCCESS;
memset(&globals,0,sizeof(globals));
memset(&globals, 0, sizeof(globals));
switch_core_hash_init(&globals.fd_hash, pool);
switch_core_hash_init(&globals.template_hash, pool);
globals.pool = pool;
switch_core_hash_insert(globals.template_hash, "default", default_template);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding default template.\n");
if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
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");
@@ -317,7 +317,7 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
}
switch_xml_free(xml);
}
if (switch_strlen_zero(globals.default_template)) {
globals.default_template = switch_core_strdup(pool, "default");
@@ -326,7 +326,7 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
if (!globals.log_dir) {
globals.log_dir = switch_core_sprintf(pool, "%s%scdr-csv", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
}
return status;
}
@@ -344,20 +344,20 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
load_config(pool);
if ((status = switch_dir_make_recursive(globals.log_dir, SWITCH_DEFAULT_DIR_PERMS, pool)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", globals.log_dir);
}
return status;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown)
{
globals.shutdown=1;
return SWITCH_STATUS_SUCCESS;
globals.shutdown = 1;
return SWITCH_STATUS_SUCCESS;
}
@@ -283,10 +283,10 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
uint64_t host_hash = 0;
switch_status_t status;
memset(buf, 0, len);
switch_sockaddr_ip_get(&myaddr, globals.addr);
status = switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len);
if (!len) {
if (SWITCH_STATUS_IS_BREAK(status)) {
switch_yield(100000);
@@ -334,7 +334,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
switch_event_fire(&local_event);
}
}
globals.running = 0;
@@ -103,8 +103,8 @@ static struct {
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, prefs.ip);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_pass, prefs.password);
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj);
static void launch_listener_thread(listener_t * listener);
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
static void launch_listener_thread(listener_t *listener);
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
{
@@ -117,7 +117,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
if (data) {
if (switch_queue_trypush(l->log_queue, data) == SWITCH_STATUS_SUCCESS) {
if (l->lost_logs) {
int ll = l->lost_logs;
int ll = l->lost_logs;
switch_event_t *event;
l->lost_logs = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Lost %d log lines!\n", ll);
@@ -158,7 +158,7 @@ static void event_handler(switch_event_t *event)
if (!switch_test_flag(l, LFLAG_EVENTS)) {
continue;
}
if (l->event_list[SWITCH_EVENT_ALL]) {
send = 1;
} else if ((l->event_list[event->event_id])) {
@@ -300,7 +300,7 @@ SWITCH_STANDARD_APP(socket_function)
}
static void close_socket(switch_socket_t ** sock)
static void close_socket(switch_socket_t **sock)
{
switch_mutex_lock(listen_list.sock_mutex);
if (*sock) {
@@ -320,7 +320,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_socket_shutdown)
close_socket(&listen_list.sock);
while(prefs.threads) {
while (prefs.threads) {
switch_yield(10000);
if (++sanity == 1000) {
break;
@@ -350,7 +350,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_socket_load)
return SWITCH_STATUS_SUCCESS;
}
static void add_listener(listener_t * listener)
static void add_listener(listener_t *listener)
{
/* add me to the listeners so I get events */
switch_mutex_lock(listen_list.mutex);
@@ -359,7 +359,7 @@ static void add_listener(listener_t * listener)
switch_mutex_unlock(listen_list.mutex);
}
static void remove_listener(listener_t * listener)
static void remove_listener(listener_t *listener)
{
listener_t *l, *last = NULL;
@@ -385,7 +385,7 @@ static void strip_cr(char *s)
}
}
static switch_status_t read_packet(listener_t * listener, switch_event_t **event, uint32_t timeout)
static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout)
{
switch_size_t mlen, bytes = 0;
char mbuf[2048] = "";
@@ -543,8 +543,8 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
switch_socket_send(listener->sock, listener->ebuf, &len);
switch_safe_free(listener->ebuf);
endloop:
endloop:
switch_event_destroy(&pevent);
}
}
@@ -569,7 +569,7 @@ struct api_command_struct {
switch_memory_pool_t *pool;
};
static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
{
struct api_command_struct *acs = (struct api_command_struct *) obj;
@@ -630,7 +630,7 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
switch_thread_rwlock_unlock(acs->listener->rwlock);
}
done:
done:
if (acs && acs->bg) {
switch_memory_pool_t *pool = acs->pool;
acs = NULL;
@@ -640,7 +640,7 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
return NULL;
}
static switch_status_t parse_command(listener_t * listener, switch_event_t *event, char *reply, uint32_t reply_len)
static switch_status_t parse_command(listener_t *listener, switch_event_t *event, char *reply, uint32_t reply_len)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *cmd = switch_event_get_header(event, "command");
@@ -866,7 +866,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
switch_snprintf(reply, reply_len, "+OK Job-UUID: %s", acs->uuid_str);
switch_thread_create(&thread, thd_attr, api_exec, acs, acs->pool);
return SWITCH_STATUS_SUCCESS;
} else if (!strncasecmp(cmd, "log", 3)) {
@@ -950,7 +950,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
}
}
end:
end:
cur = next;
}
}
@@ -1039,7 +1039,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
}
}
done:
done:
if (event) {
switch_event_destroy(&event);
}
@@ -1051,7 +1051,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
return status;
}
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj)
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
{
listener_t *listener = (listener_t *) obj;
char buf[1024];
@@ -1071,13 +1071,13 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
if (prefs.acl_count && listener->sa && !switch_strlen_zero(listener->remote_ip)) {
uint32_t x = 0;
for (x = 0 ; x < prefs.acl_count; x++) {
for (x = 0; x < prefs.acl_count; x++) {
if (!switch_check_network_list_ip(listener->remote_ip, prefs.acl[x])) {
const char message[] = "Access Denied, go away.\n";
int mlen = strlen(message);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", listener->remote_ip, prefs.acl[x]);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", listener->remote_ip, prefs.acl[x]);
switch_snprintf(buf, sizeof(buf), "Content-Type: rude/rejection\nContent-Length %d\n\n", mlen);
len = strlen(buf);
@@ -1203,7 +1203,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
}
done:
done:
remove_listener(listener);
@@ -1234,7 +1234,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
/* Create a thread for the socket and launch it */
static void launch_listener_thread(listener_t * listener)
static void launch_listener_thread(listener_t *listener)
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
@@ -1333,7 +1333,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
goto sock_fail;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
break;
sock_fail:
sock_fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error! Could not listen on %s:%u\n", prefs.ip, prefs.port);
switch_yield(100000);
}
@@ -1348,7 +1348,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG);
for(;;) {
for (;;) {
if (switch_core_new_memory_pool(&listener_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
goto fail;
@@ -1396,11 +1396,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
}
for (x = 0 ; x < prefs.acl_count; x++) {
for (x = 0; x < prefs.acl_count; x++) {
switch_safe_free(prefs.acl[x]);
}
fail:
fail:
return SWITCH_STATUS_TERM;
}
@@ -77,7 +77,7 @@ static void event_handler(switch_event_t *event)
#define TTHREADS 500
static int THREADS = 0;
static void *torture_thread(switch_thread_t * thread, void *obj)
static void *torture_thread(switch_thread_t *thread, void *obj)
{
int y = 0;
int z = 0;
@@ -38,17 +38,17 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load);
SWITCH_MODULE_DEFINITION(mod_radius_cdr, mod_radius_cdr_load, NULL, NULL);
static char cf[] = "mod_radius_cdr.conf";
static char my_dictionary[PATH_MAX];
static char my_seqfile[PATH_MAX];
static char * my_deadtime; /* 0 */
static char * my_timeout; /* 5 */
static char * my_retries; /* 3 */
static char my_servers[SERVER_MAX][255];
static char cf[] = "mod_radius_cdr.conf";
static char my_dictionary[PATH_MAX];
static char my_seqfile[PATH_MAX];
static char *my_deadtime; /* 0 */
static char *my_timeout; /* 5 */
static char *my_retries; /* 3 */
static char my_servers[SERVER_MAX][255];
static rc_handle * my_radius_init(void)
static rc_handle *my_radius_init(void)
{
rc_handle *rad_config;
rc_handle *rad_config;
rad_config = rc_new();
@@ -63,19 +63,17 @@ static rc_handle * my_radius_init(void)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error initializing radius config!\n");
rc_destroy(rad_config);
return NULL;
}
}
/* Some hardcoded ( for now ) defaults needed to initialize radius */
if (rc_add_config(rad_config, "auth_order", "radius", "mod_radius_cdr.c", 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting auth_order = radius failed\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting auth_order = radius failed\n");
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "seqfile", my_seqfile, "mod_radius_cdr.c", 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting seqfile = %s failed\n", my_seqfile);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting seqfile = %s failed\n", my_seqfile);
rc_destroy(rad_config);
return NULL;
}
@@ -92,37 +90,32 @@ static rc_handle * my_radius_init(void)
}
if (rc_add_config(rad_config, "dictionary", my_dictionary, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed setting dictionary = %s failed\n", my_dictionary);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed setting dictionary = %s failed\n", my_dictionary);
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "radius_deadtime", my_deadtime, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting radius_deadtime = %s failed\n", my_deadtime);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_deadtime = %s failed\n", my_deadtime);
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "radius_timeout", my_timeout, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting radius_timeout = %s failed\n", my_timeout);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_timeout = %s failed\n", my_timeout);
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "radius_retries", my_retries, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting radius_retries = %s failed\n", my_retries);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_retries = %s failed\n", my_retries);
rc_destroy(rad_config);
return NULL;
return NULL;
}
/* 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,
"reading dictionary file(s): %s\n", my_dictionary);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "reading dictionary file(s): %s\n", my_dictionary);
rc_destroy(rad_config);
return NULL;
}
@@ -132,20 +125,20 @@ static rc_handle * my_radius_init(void)
static switch_status_t my_on_routing(switch_core_session_t *session)
{
switch_xml_t cdr;
switch_xml_t cdr;
switch_channel_t *channel = switch_core_session_get_channel(session);
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_START;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_START;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
char *uuid_str;
char *uuid_str;
switch_time_exp_t tm;
char buffer[32];
@@ -162,7 +155,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
uuid_str = switch_core_session_get_uuid(session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
return SWITCH_STATUS_TERM;
return SWITCH_STATUS_TERM;
}
/* Create the radius packet */
@@ -172,135 +165,122 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed setting Acct-Status-Type: Start\n");
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, "[mod_radius_cdr] Failed adding Acct-Session-ID: %s\n", uuid_str);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
/* Add VSAs */
if (channel) {
/*switch_call_cause_t cause;*/
switch_caller_profile_t *profile;
/*switch_call_cause_t cause; */
switch_caller_profile_t *profile;
/*
cause = switch_channel_get_cause(channel);
if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
*/
cause = switch_channel_get_cause(channel);
if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
*/
profile = switch_channel_get_caller_profile(channel);
if (profile) {
callstartdate = profile->times->created;
callanswerdate = profile->times->answered;
calltransferdate = profile->times->transferred;
callenddate = profile->times->hungup;
if (profile->username) {
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *)profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding User-Name: %s\n", profile->username);
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *)profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *)profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->destination_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *)profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dst: %s\n", profile->destination_number);
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->dialplan) {
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *)profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->network_addr) {
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *)profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Framed-IP-Address: %s\n", profile->network_addr);
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *) profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->rdnis) {
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *)profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->context) {
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *)profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Context: %s\n", profile->context);
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->ani) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *)profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANI: %s\n", profile->ani);
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->aniii) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *)profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANIII: %s\n", profile->aniii);
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->source) {
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *)profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Source: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (callstartdate > 0) {
switch_time_exp_lt(&tm, callstartdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callstartdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -309,12 +289,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
if (callanswerdate > 0) {
switch_time_exp_lt(&tm, callanswerdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callanswerdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -323,12 +301,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
if (calltransferdate > 0) {
switch_time_exp_lt(&tm, calltransferdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Calltransferdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -337,26 +313,23 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
if (callenddate > 0) {
switch_time_exp_lt(&tm, callenddate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callenddate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
if (profile->caller_extension && profile->caller_extension->last_application->application_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *)profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Lastapp: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
}
@@ -371,27 +344,27 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
}
rc_avpair_free(send);
return(retval);
return (retval);
}
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_xml_t cdr;
switch_xml_t cdr;
switch_channel_t *channel = switch_core_session_get_channel(session);
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_STOP;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
switch_time_t billusec = 0;
uint32_t billsec = 0;
char *uuid_str;
switch_time_exp_t tm;
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_STOP;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
switch_time_t billusec = 0;
uint32_t billsec = 0;
char *uuid_str;
switch_time_exp_t tm;
char buffer[32] = "";
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[mod_radius_cdr] Entering my_on_hangup\n");
@@ -407,7 +380,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
uuid_str = switch_core_session_get_uuid(session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
return SWITCH_STATUS_TERM;
return SWITCH_STATUS_TERM;
}
/* Create the radius packet */
@@ -417,19 +390,19 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
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 VSAs */
if (channel) {
switch_call_cause_t cause;
switch_caller_profile_t *profile;
switch_call_cause_t cause;
switch_caller_profile_t *profile;
cause = switch_channel_get_cause(channel);
if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
@@ -437,7 +410,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
profile = switch_channel_get_caller_profile(channel);
if (profile) {
@@ -449,16 +422,15 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
callanswerdate = profile->times->answered;
calltransferdate = profile->times->transferred;
callenddate = profile->times->hungup;
if (switch_channel_test_flag(channel,CF_ANSWERED)) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
if (callstartdate && callanswerdate) {
if (callenddate)
billusec = callenddate - callanswerdate;
else if (calltransferdate)
billusec = calltransferdate - callanswerdate;
}
}
else if (switch_channel_test_flag(channel,CF_TRANSFER)) {
} else if (switch_channel_test_flag(channel, CF_TRANSFER)) {
if (callanswerdate && calltransferdate)
billusec = calltransferdate - callanswerdate;
}
@@ -467,105 +439,92 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[mod_radius_cdr] Finished calculating billable time\n");
if (profile->username) {
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *)profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding User-Name: %s\n", profile->username);
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *)profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *)profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->destination_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *)profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dst: %s\n", profile->destination_number);
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->dialplan) {
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *)profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->network_addr) {
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *)profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Framed-IP-Address: %s\n", profile->network_addr);
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *) profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->rdnis) {
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *)profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->context) {
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *)profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Context: %s\n", profile->context);
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->ani) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *)profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANI: %s\n", profile->ani);
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->aniii) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *)profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANIII: %s\n", profile->aniii);
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->source) {
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *)profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Source: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_extension && profile->caller_extension->last_application->application_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *)profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Lastapp: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (rc_avpair_add(rad_config, &send, PW_FS_BILLUSEC, &billusec, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Billusec: %u\n", (uint32_t)billusec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Billusec: %u\n", (uint32_t) billusec);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -573,12 +532,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (callstartdate > 0) {
switch_time_exp_lt(&tm, callstartdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callstartdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -587,12 +544,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (callanswerdate > 0) {
switch_time_exp_lt(&tm, callanswerdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callanswerdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -601,12 +556,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (calltransferdate > 0) {
switch_time_exp_lt(&tm, calltransferdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Calltransferdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -615,25 +568,22 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (callenddate > 0) {
switch_time_exp_lt(&tm, callenddate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callenddate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_TIME, &billsec, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Acct-Session-Time: %u\n", billsec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-Time: %u\n", billsec);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
} else { /* no profile, can't create data to send */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
} else { /* no profile, can't create data to send */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
}
}
@@ -646,57 +596,52 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
}
rc_avpair_free(send);
return(retval);
return (retval);
}
static switch_status_t load_config(void)
{
switch_xml_t cfg, xml, settings, param;
switch_xml_t cfg, xml, settings, param;
int num_servers = 0;
my_timeout = "5";
my_retries = "3";
my_deadtime = "0";
strncpy(my_seqfile, "/var/run/radius.seq", PATH_MAX-1);
strncpy(my_dictionary, "/usr/local/freeswitch/conf/radius/dictionary", PATH_MAX-1);
strncpy(my_seqfile, "/var/run/radius.seq", PATH_MAX - 1);
strncpy(my_dictionary, "/usr/local/freeswitch/conf/radius/dictionary", PATH_MAX - 1);
for( int i = 0; i < SERVER_MAX; i++ ) {
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);
return SWITCH_STATUS_TERM;
}
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) {
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) {
strncpy(my_servers[num_servers],val,255-1);
strncpy(my_servers[num_servers], val, 255 - 1);
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);
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(my_dictionary,val,PATH_MAX-1);
}
else if (!strcmp(var, "seqfile")) {
strncpy(my_seqfile,val,PATH_MAX-1);
}
else if (!strcmp(var, "radius_timeout")) {
} else if (!strcmp(var, "dictionary")) {
strncpy(my_dictionary, val, PATH_MAX - 1);
} else if (!strcmp(var, "seqfile")) {
strncpy(my_seqfile, val, PATH_MAX - 1);
} else if (!strcmp(var, "radius_timeout")) {
my_timeout = strdup(val);
}
else if (!strcmp(var, "radius_retries")) {
} else if (!strcmp(var, "radius_retries")) {
my_retries = strdup(val);
}
else if (!strcmp(var, "radius_deadtime")) {
} else if (!strcmp(var, "radius_deadtime")) {
my_deadtime = strdup(val);
}
}
@@ -705,8 +650,7 @@ static switch_status_t load_config(void)
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");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "you must specify at least 1 radius server\n");
return SWITCH_STATUS_TERM;
}
@@ -726,8 +670,8 @@ static const switch_state_handler_table_t state_handlers = {
SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load)
{
if (load_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
return SWITCH_STATUS_TERM;
}
/* test global state handlers */
switch_core_add_state_handler(&state_handlers);