fix for FSCORE-97 and add set_name app to rename channel

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7752 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-02-26 23:29:58 +00:00
parent eb3dc7f2bb
commit bc2fd445ca
5 changed files with 44 additions and 5 deletions

View File

@ -93,6 +93,8 @@ SWITCH_BEGIN_EXTERN_C
char *uuid;
/*! context */
const char *context;
/*! profile index */
const char *profile_index;
/*! flags */
switch_caller_profile_flag_t flags;
struct switch_caller_profile *originator_caller_profile;

View File

@ -345,6 +345,14 @@ SWITCH_STANDARD_APP(hangup_function)
switch_channel_hangup(switch_core_session_get_channel(session), cause);
}
SWITCH_STANDARD_APP(set_name_function)
{
if (!switch_strlen_zero(data)) {
switch_channel_set_name(switch_core_session_get_channel(session), (char *) data);
}
}
SWITCH_STANDARD_APP(answer_function)
{
switch_channel_answer(switch_core_session_get_channel(session));
@ -1502,6 +1510,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_APP(app_interface, "pre_answer", "Pre-Answer the call", "Pre-Answer the call for a channel.", pre_answer_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "answer", "Answer the call", "Answer the call for a channel.", answer_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "hangup", "Hangup the call", "Hangup the call for a channel.", hangup_function, "[<cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set_name", "Name the channel", "Name the channel", set_name_function, "<name>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "log", "Logs a channel variable", LOG_LONG_DESC, log_function, "<varname>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "info", "Display Call Info", "Display Call Info", info_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA);

View File

@ -159,9 +159,15 @@ SWITCH_DECLARE(const char *) switch_caller_get_field_by_name(switch_caller_profi
if (!strcasecmp(name, "context")) {
return caller_profile->context;
}
if (!strcasecmp(name, "chan_name")) {
return caller_profile->chan_name;
}
if (!strcasecmp(name, "profile_index")) {
return caller_profile->profile_index;
}
if (!strcasecmp(name, "caller_ton")) {
return switch_core_sprintf(caller_profile->pool, "%u", caller_profile->caller_ton);
}
@ -245,6 +251,10 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_
switch_snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name);
}
if (!switch_strlen_zero(caller_profile->profile_index)) {
switch_snprintf(header_name, sizeof(header_name), "%s-Profile-Index", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->profile_index);
}
if (caller_profile->times) {
switch_snprintf(header_name, sizeof(header_name), "%s-Channel-Created-Time", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->created);

View File

@ -122,6 +122,7 @@ struct switch_channel {
switch_call_cause_t hangup_cause;
int vi;
int event_count;
int profile_index;
};
SWITCH_DECLARE(const char *) switch_channel_cause2str(switch_call_cause_t cause)
@ -190,7 +191,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel,
switch_mutex_init(&(*channel)->flag_mutex, SWITCH_MUTEX_NESTED, pool);
switch_mutex_init(&(*channel)->profile_mutex, SWITCH_MUTEX_NESTED, pool);
(*channel)->hangup_cause = SWITCH_CAUSE_UNALLOCATED;
(*channel)->name = "N/A";
(*channel)->name = "";
return SWITCH_STATUS_SUCCESS;
}
@ -513,13 +514,22 @@ SWITCH_DECLARE(void *) switch_channel_get_private(switch_channel_t *channel, con
SWITCH_DECLARE(switch_status_t) switch_channel_set_name(switch_channel_t *channel, const char *name)
{
const char *old = NULL;
switch_assert(channel != NULL);
if (!switch_strlen_zero(channel->name)) {
old = channel->name;
}
channel->name = NULL;
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);
if (old) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Rename Channel %s->%s [%s]\n", old, name, uuid);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Channel %s [%s]\n", name, uuid);
}
}
return SWITCH_STATUS_SUCCESS;
}
@ -527,7 +537,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_name(switch_channel_t *channe
SWITCH_DECLARE(char *) switch_channel_get_name(switch_channel_t *channel)
{
switch_assert(channel != NULL);
return channel->name ? channel->name : "N/A";
return (!switch_strlen_zero(channel->name)) ? channel->name : "N/A";
}
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *channel, const char *varname, const char *value)
@ -1138,7 +1148,8 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel
caller_profile->next = channel->caller_profile;
channel->caller_profile = caller_profile;
caller_profile->profile_index = switch_core_sprintf(caller_profile->pool, "%d", ++channel->profile_index);
switch_mutex_unlock(channel->profile_mutex);
}

View File

@ -1341,7 +1341,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
goto error;
}
switch_xml_set_attr_d(x_callflow, "dialplan", caller_profile->dialplan);
if (!switch_strlen_zero(caller_profile->dialplan)) {
switch_xml_set_attr_d(x_callflow, "dialplan", caller_profile->dialplan);
}
if (!switch_strlen_zero(caller_profile->profile_index)) {
switch_xml_set_attr_d(x_callflow, "profile_index", caller_profile->profile_index);
}
if (caller_profile->caller_extension) {
switch_caller_application_t *ap;