[Freeswitch-trunk] [commit] r6542 - in freeswitch/trunk: build conf/autoload_configs src src/include src/mod/applications/mod_voicemail src/mod/event_handlers/mod_cdr_csv src/mod/loggers/mod_logfile
Freeswitch SVN
anthm at freeswitch.org
Thu Dec 6 14:51:55 EST 2007
Author: anthm
Date: Thu Dec 6 14:51:55 2007
New Revision: 6542
Added:
freeswitch/trunk/conf/autoload_configs/cdr_csv.conf.xml
freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/
freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/Makefile
freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.vcproj
Modified:
freeswitch/trunk/build/modules.conf.in
freeswitch/trunk/conf/autoload_configs/modules.conf.xml
freeswitch/trunk/src/include/switch_types.h
freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c
freeswitch/trunk/src/switch_caller.c
freeswitch/trunk/src/switch_channel.c
freeswitch/trunk/src/switch_core.c
Log:
add mod_cdr_csv
Modified: freeswitch/trunk/build/modules.conf.in
==============================================================================
--- freeswitch/trunk/build/modules.conf.in (original)
+++ freeswitch/trunk/build/modules.conf.in Thu Dec 6 14:51:55 2007
@@ -40,6 +40,7 @@
#../../libs/openzap/mod_openzap
#event_handlers/mod_event_multicast
event_handlers/mod_event_socket
+event_handlers/mod_cdr_csv
#event_handlers/mod_radius_cdr
formats/mod_native_file
formats/mod_sndfile
Added: freeswitch/trunk/conf/autoload_configs/cdr_csv.conf.xml
==============================================================================
--- (empty file)
+++ freeswitch/trunk/conf/autoload_configs/cdr_csv.conf.xml Thu Dec 6 14:51:55 2007
@@ -0,0 +1,12 @@
+<configuration name="cdr_csv.conf" description="CDR CSV Format">
+ <settings>
+ <!-- 'cdr-csv' will always be appended to log-base -->
+ <!--<param name="log-base" value="/var/log"/>-->
+ <param name="default-template" value="example"/>
+ <param name="rotate-on-hup" value="true"/>
+ </settings>
+ <templates>
+ <template name="example">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}", "${accountcode}"</template>
+ <template name="asterisk">"${accountcode}","${caller_id_number}","${destination_number}","${context}","${caller_id}","${channel_name}","${bridge_channel}","${last_app}","${last_arg}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${amaflags}","${uuid}","${userfield}"</template>
+ </templates>
+</configuration>
Modified: freeswitch/trunk/conf/autoload_configs/modules.conf.xml
==============================================================================
--- freeswitch/trunk/conf/autoload_configs/modules.conf.xml (original)
+++ freeswitch/trunk/conf/autoload_configs/modules.conf.xml Thu Dec 6 14:51:55 2007
@@ -15,7 +15,7 @@
<!-- <load module="mod_xml_cdr"/> -->
<!-- Event Handlers -->
- <!-- <load module="mod_cdr"/> -->
+ <load module="mod_cdr_csv"/>
<!-- <load module="mod_event_multicast"/> -->
<!-- <load module="mod_event_socket"/> -->
<!-- <load module="mod_xmpp_event"/> -->
Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h (original)
+++ freeswitch/trunk/src/include/switch_types.h Thu Dec 6 14:51:55 2007
@@ -91,6 +91,10 @@
#define SWITCH_SEQ_CLEARLINE SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINE_CHAR_STR
#define SWITCH_SEQ_CLEARLINEEND SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINEEND_CHAR
#define SWITCH_SEQ_CLEARSCR SWITCH_SEQ_ESC SWITCH_SEQ_CLEARSCR_CHAR SWITCH_SEQ_HOME
+
+
+#define SWITCH_DEFAULT_DIR_PERMS SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE | SWITCH_FPROT_UEXECUTE | SWITCH_FPROT_GREAD | SWITCH_FPROT_GEXECUTE
+
#ifdef WIN32
#define SWITCH_PATH_SEPARATOR "\\"
#else
@@ -98,6 +102,7 @@
#endif
#define SWITCH_URL_SEPARATOR "://"
#define SWITCH_BRIDGE_CHANNEL_VARIABLE "bridge_channel"
+#define SWITCH_CHANNEL_NAME_VARIABLE "channel_name"
#define SWITCH_BRIDGE_UUID_VARIABLE "bridge_uuid"
#define SWITCH_PLAYBACK_TERMINATORS_VARIABLE "playback_terminators"
#define SWITCH_CACHE_SPEECH_HANDLES_VARIABLE "cache_speech_handles"
Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c Thu Dec 6 14:51:55 2007
@@ -875,8 +875,6 @@
MSG_SAVED
} msg_type_t;
-static uint32_t DEFAULT_DIR_PERMS = SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE | SWITCH_FPROT_UEXECUTE | SWITCH_FPROT_GREAD | SWITCH_FPROT_GEXECUTE;
-
static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile, char *macro_name, char *file_path, switch_size_t *message_len)
{
@@ -1640,7 +1638,7 @@
}
- if (switch_dir_make_recursive(dir_path, DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ if (switch_dir_make_recursive(dir_path, 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", dir_path);
return;
}
@@ -1739,7 +1737,7 @@
id);
}
- if (switch_dir_make_recursive(dir_path, DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ if (switch_dir_make_recursive(dir_path, 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", dir_path);
goto end;
}
@@ -2069,7 +2067,7 @@
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
- if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_dir, DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_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", SWITCH_GLOBAL_dirs.storage_dir);
return;
}
Added: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/Makefile
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/Makefile Thu Dec 6 14:51:55 2007
@@ -0,0 +1 @@
+include ../../../../build/modmake.rules
Added: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c Thu Dec 6 14:51:55 2007
@@ -0,0 +1,435 @@
+/*
+ * 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):
+ *
+ * mod_cdr_csv.c -- Asterisk Compatible CDR Module
+ *
+ */
+#include <sys/stat.h>
+#include <switch.h>
+
+struct cdr_fd {
+ int fd;
+ char *path;
+ int64_t bytes;
+ switch_mutex_t *mutex;
+};
+typedef struct cdr_fd cdr_fd_t;
+
+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}\"";
+
+static struct {
+ switch_memory_pool_t *pool;
+ switch_hash_t *fd_hash;
+ switch_hash_t *template_hash;
+ char *log_dir;
+ char *default_template;
+ int shutdown;
+ int rotate;
+} globals;
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown);
+SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, NULL, NULL);
+
+static off_t fd_size(int fd)
+{
+ struct stat s = {0};
+ fstat(fd, &s);
+ return s.st_size;
+}
+
+static void do_reopen(cdr_fd_t *fd)
+{
+
+ if (fd->fd > -1) {
+ close(fd->fd);
+ fd->fd = -1;
+ }
+
+ if ((fd->fd = open(fd->path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) > -1) {
+ fd->bytes = fd_size(fd->fd);
+ }
+}
+
+static void do_rotate(cdr_fd_t *fd)
+{
+ switch_time_exp_t tm;
+ char date[80] = "";
+ switch_size_t retsize;
+ char *p;
+ size_t len;
+
+ close(fd->fd);
+
+ if (globals.rotate) {
+ switch_time_exp_lt(&tm, switch_time_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);
+ switch_file_rename(fd->path, p, globals.pool);
+ free(p);
+ }
+
+ do_reopen(fd);
+
+ if (fd->fd < 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", fd->path);
+ } 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;
+
+ if ((fd = switch_core_hash_find(globals.fd_hash, path))) {
+ switch_mutex_lock(fd->mutex);
+ } else {
+ int lfd = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
+
+ if (lfd > -1) {
+ fd = switch_core_alloc(globals.pool, sizeof(*fd));
+ switch_mutex_init(&fd->mutex, SWITCH_MUTEX_NESTED, globals.pool);
+ fd->fd = lfd;
+ switch_mutex_lock(fd->mutex);
+ fd->path = switch_core_strdup(globals.pool, path);
+ fd->bytes = fd_size(fd->fd);
+ switch_core_hash_insert(globals.fd_hash, path, fd);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
+ }
+ }
+
+ if (fd) {
+ size_t bytes_in, bytes_out;
+ bytes_out = strlen(log_line);
+
+ if (fd->bytes + bytes_out > UINT_MAX) {
+ do_rotate(fd);
+ }
+
+ if (fd->fd < 0) {
+ do_reopen(fd);
+ if (fd->fd < 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
+ return;
+ }
+ }
+
+ 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\n", path);
+ }
+ fd->bytes += bytes_in;
+ switch_mutex_unlock(fd->mutex);
+ }
+
+}
+
+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_FALSE;
+ const char *log_dir = NULL, *accountcode = NULL, *cid_buf = NULL, *template = NULL, *template_str = NULL;
+ char *log_line, *path = NULL;
+ switch_caller_profile_t *caller_profile, *ocp;
+
+ switch_app_log_t *app_log, *ap;
+ char *last_app = NULL, *last_arg = NULL;
+ char start[80] = "", answer[80] = "", end[80] = "", tmp[30] = "";
+ int32_t duration = 0, billsec = 0;
+
+ if (switch_channel_get_originator_caller_profile(channel)) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ 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;
+ }
+
+ caller_profile = switch_channel_get_caller_profile(channel);
+ ocp = switch_channel_get_originatee_caller_profile(channel);
+
+ if (!switch_strlen_zero(caller_profile->caller_id_name)) {
+ cid_buf = switch_core_session_sprintf(session, "\"%s\" <%s>", caller_profile->caller_id_name,
+ switch_str_nil(caller_profile->caller_id_number));
+ } else {
+ cid_buf = caller_profile->caller_id_number;
+ }
+
+ if ((app_log = switch_core_session_get_app_log(session))) {
+ for (ap = app_log; ap && ap->next; ap = ap->next);
+ last_app = ap->app;
+ last_arg = ap->arg;
+ }
+
+ if (caller_profile->times) {
+ switch_time_exp_t tm;
+ switch_size_t retsize;
+ const char *fmt = "%Y-%m-%d %T";
+
+ switch_time_exp_lt(&tm, caller_profile->times->created);
+ switch_strftime(start, &retsize, sizeof(start), fmt, &tm);
+
+ switch_time_exp_lt(&tm, caller_profile->times->answered);
+ switch_strftime(answer, &retsize, sizeof(answer), fmt, &tm);
+
+ switch_time_exp_lt(&tm, caller_profile->times->hungup);
+ switch_strftime(end, &retsize, sizeof(end), fmt, &tm);
+
+ duration = ((int32_t) caller_profile->times->hungup / 1000000) - ((int32_t) caller_profile->times->created / 1000000);
+ if (duration < 0) {
+ duration = 0;
+ }
+
+ billsec = ((int32_t) caller_profile->times->hungup / 1000000) - ((int32_t) caller_profile->times->answered / 1000000);
+ if (billsec < 0) {
+ billsec = 0;
+ }
+
+ }
+
+ switch_channel_set_variable(channel, "start_stamp", start);
+ switch_channel_set_variable(channel, "answer_stamp", answer);
+ switch_channel_set_variable(channel, "end_stamp", end);
+ switch_channel_set_variable(channel, "last_app", last_app);
+ switch_channel_set_variable(channel, "last_arg", last_arg);
+ switch_channel_set_variable(channel, "caller_id", cid_buf);
+
+ snprintf(tmp, sizeof(tmp), "%d", duration);
+ switch_channel_set_variable(channel, "duration", tmp);
+
+ snprintf(tmp, sizeof(tmp), "%d", billsec);
+ switch_channel_set_variable(channel, "billsec", tmp);
+
+
+ if (!(template = switch_channel_get_variable(channel, "cdr_template"))) {
+ template = globals.default_template;
+ }
+
+ if (!(template_str = (const char *) switch_core_hash_find(globals.template_hash, template))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error finding template %s substituting default\n", template);
+ template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);
+ }
+
+
+
+ log_line = switch_channel_expand_variables(channel, template_str);
+#if 0
+ log_line = switch_core_session_sprintf(session,
+ "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\","
+ "\"%s\",\"%s\",\"%d\",\"%d\",\"%s\",\"%s\",\"%s\",\"%s\"\n",
+ switch_str_nil(accountcode),
+ switch_str_nil(caller_profile->caller_id_number),
+ switch_str_nil(caller_profile->destination_number),
+ switch_str_nil(caller_profile->context),
+ cid_buf,
+ switch_channel_get_name(channel),
+ switch_str_nil(switch_channel_get_variable(channel, SWITCH_BRIDGE_CHANNEL_VARIABLE)),
+ switch_str_nil(last_app),
+ switch_str_nil(last_arg),
+ start,
+ answer,
+ end,
+ duration,
+ billsec,
+ switch_str_nil(switch_channel_cause2str(switch_channel_get_cause(channel))),
+ switch_str_nil(switch_channel_get_variable(channel, "AMAFLAGS")),
+ switch_str_nil(caller_profile->uuid),
+ switch_str_nil(switch_channel_get_variable(channel, "USERFIELD"))
+ );
+
+#endif
+
+
+
+
+
+ if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) {
+ path = switch_mprintf("%s%s%s.csv", log_dir, SWITCH_PATH_SEPARATOR, accountcode);
+ assert(path);
+ write_cdr(path, log_line);
+ free(path);
+ }
+
+ 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 != template_str) {
+ free(log_line);
+ }
+
+ return status;
+}
+
+
+static void event_handler(switch_event_t *event)
+{
+ const char *sig = switch_event_get_header(event, "Trapped-Signal");
+ switch_hash_index_t *hi;
+ void *val;
+ cdr_fd_t *fd;
+
+ if (sig && !strcmp(sig, "HUP")) {
+ for (hi = switch_hash_first(NULL, globals.fd_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, NULL, NULL, &val);
+ fd = (cdr_fd_t *) val;
+ do_rotate(fd);
+ }
+ }
+}
+
+
+static 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 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));
+ 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");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+
+ if (!strcasecmp(var, "log-base")) {
+ globals.log_dir = switch_core_sprintf(pool, "%s%scdr-csv", val, SWITCH_PATH_SEPARATOR);
+ } else if (!strcasecmp(var, "rotate-on-hup")) {
+ globals.rotate = switch_true(val);
+ } else if (!strcasecmp(var, "default-template")) {
+ globals.default_template = switch_core_strdup(pool, val);
+ }
+ }
+ }
+
+ if ((settings = switch_xml_child(cfg, "templates"))) {
+ for (param = switch_xml_child(settings, "template"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr(param, "name");
+ if (var) {
+ char *tpl;
+ size_t len = strlen(param->txt) + 2;
+ if (end_of(param->txt) != '\n') {
+ tpl = switch_core_alloc(pool, len);
+ snprintf(tpl, len, "%s\n", param->txt);
+ } else {
+ tpl = switch_core_strdup(pool, param->txt);
+ }
+
+ switch_core_hash_insert(globals.template_hash, var, tpl);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding template %s.\n", var);
+ }
+ }
+ }
+ switch_xml_free(xml);
+ }
+
+
+ if (switch_strlen_zero(globals.default_template)) {
+ globals.default_template = switch_core_strdup(pool, "default");
+ }
+
+ if (!globals.log_dir) {
+ globals.log_dir = switch_core_sprintf(pool, "%s%scdr-csv", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
+ }
+
+ return status;
+}
+
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load)
+{
+ switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+ if (switch_event_bind((char *) modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+ return SWITCH_STATUS_GENERR;
+ }
+
+ switch_core_add_state_handler(&state_handlers);
+ *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;
+}
+
+
+
+/* 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:
+ */
Added: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.vcproj
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.vcproj Thu Dec 6 14:51:55 2007
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="mod_cdr_csv"
+ ProjectGUID="{08DAD348-9E0A-4A2E-97F1-F1E7E24A7836}"
+ RootNamespace="mod_cdr_csv"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops;..\..\..\..\w32\curl.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops;..\..\..\..\w32\curl.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalLibraryDirectories=""
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\mod_cdr_csv.c"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Modified: freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c
==============================================================================
--- freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c (original)
+++ freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c Thu Dec 6 14:51:55 2007
@@ -356,7 +356,7 @@
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, "rotate")) {
+ if (!strcmp(var, "rotate-on-hup")) {
globals.rotate = switch_true(val);
}
}
Modified: freeswitch/trunk/src/switch_caller.c
==============================================================================
--- freeswitch/trunk/src/switch_caller.c (original)
+++ freeswitch/trunk/src/switch_caller.c Thu Dec 6 14:51:55 2007
@@ -21,7 +21,7 @@
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
- * Contributor(s):
+
*
* Anthony Minessale II <anthmct at yahoo.com>
*
Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c (original)
+++ freeswitch/trunk/src/switch_channel.c Thu Dec 6 14:51:55 2007
@@ -327,13 +327,21 @@
switch_mutex_lock(channel->profile_mutex);
if (!(v = switch_event_get_header(channel->variables, (char*)varname))) {
- if (!channel->caller_profile || !(v = switch_caller_get_field_by_name(channel->caller_profile, varname))) {
- if (!strcmp(varname, "base_dir")) {
- v = SWITCH_GLOBAL_dirs.base_dir;
- } else {
- v = switch_core_get_variable(varname);
+ switch_caller_profile_t *cp = channel->caller_profile;
+
+ if (cp) {
+ if (!strncmp(varname, "aleg_", 5)) {
+ cp = cp->originator_caller_profile;
+ varname += 5;
+ } else if (!strncmp(varname, "bleg_", 5)) {
+ cp = cp->originatee_caller_profile;
+ varname += 5;
}
}
+
+ if (!cp || !(v = switch_caller_get_field_by_name(cp, varname))) {
+ v = switch_core_get_variable(varname);
+ }
}
switch_mutex_unlock(channel->profile_mutex);
@@ -389,6 +397,7 @@
if (name) {
char *uuid = switch_core_session_get_uuid(channel->session);
channel->name = switch_core_session_strdup(channel->session, name);
+ switch_channel_set_variable(channel, SWITCH_CHANNEL_NAME_VARIABLE, name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Chan %s [%s]\n", name, uuid);
}
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c (original)
+++ freeswitch/trunk/src/switch_core.c Thu Dec 6 14:51:55 2007
@@ -678,6 +678,7 @@
switch_core_set_variable("local_ip_v4", guess_ip);
switch_find_local_ip(guess_ip, sizeof(guess_ip), AF_INET6);
switch_core_set_variable("local_ip_v6", guess_ip);
+ switch_core_set_variable("base_dir", SWITCH_GLOBAL_dirs.base_dir);
if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) {
@@ -810,6 +811,20 @@
if (sig);
return;
}
+
+static void handle_SIGHUP(int sig)
+{
+ if (sig) {
+ switch_event_t *event;
+
+ if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Trapped-Signal", "HUP");
+ switch_event_fire(&event);
+ }
+ }
+ return;
+}
+
SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t flags, switch_bool_t console, const char **err)
{
switch_event_t *event;
@@ -832,6 +847,8 @@
signal(SIGBUS, handle_SIGBUS);
#endif
+ signal(SIGHUP, handle_SIGHUP);
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Loading Modules.\n");
if (switch_loadable_module_init() != SWITCH_STATUS_SUCCESS) {
More information about the Freeswitch-trunk
mailing list