Modify Originate input syntax

This adds the | to the originate syntax 
making it possible to put a list of urls to call and attempt
to call them one at a time until one of them is successful or there
are none of them left

The original & delimited list is valid for each step in the | separated
list

Example
sofia/test-int/3920@10.3.3.104|sofia/test-int/3910@10.3.3.104&sofia/test-int/3920@10.3.3.104

first call 1 location and if that results in a failure, try 2 at once on the next go



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2996 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-10-07 22:19:24 +00:00
parent b9a350a40d
commit bc7a378c4e
3 changed files with 278 additions and 255 deletions

View File

@ -151,7 +151,7 @@ switch_mutex_unlock(obj->flag_mutex);
/*!
\brief Free a pointer and set it to NULL unles it already is NULL
\brief Free a pointer and set it to NULL unless it already is NULL
\param it the pointer
*/
#define switch_safe_free(it) if (it) {free(it);it=NULL;}

View File

@ -1676,7 +1676,6 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
sofia_profile_t *profile;
switch_caller_profile_t *caller_profile = NULL;
private_object_t *tech_pvt = NULL;
switch_channel_t *channel;
switch_channel_t *nchannel;
char *host;
@ -1725,7 +1724,7 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
snprintf(tech_pvt->dest, strlen(dest) + 5, "sip:%s", dest);
}
attach_private(nsession, profile, tech_pvt, dest);
channel = switch_core_session_get_channel(session);
nchannel = switch_core_session_get_channel(nsession);
caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
switch_channel_set_caller_profile(nchannel, caller_profile);
@ -1737,6 +1736,7 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
status = SWITCH_STATUS_SUCCESS;
if (session) {
char *val;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_ivr_transfer_variable(session, nsession, SOFIA_REPLACES_HEADER);
if (switch_channel_test_flag(channel, CF_NOMEDIA) && (val = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE))) {

View File

@ -1698,6 +1698,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
)
{
char *pipe_names[MAX_PEERS] = {0};
char *data = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *caller_channel = NULL;
char *peer_names[MAX_PEERS] = {0};
switch_core_session_t *peer_session, *peer_sessions[MAX_PEERS] = {0};
switch_caller_profile_t *caller_profiles[MAX_PEERS] = {0}, *caller_caller_profile;
@ -1705,11 +1709,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_channel_t *peer_channel = NULL, *peer_channels[MAX_PEERS] = {0};
time_t start;
switch_frame_t *read_frame = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *caller_channel = NULL;
switch_memory_pool_t *pool = NULL;
char *data = NULL;
int i, argc = 0;
int r = 0, i, and_argc = 0, or_argc = 0;
int32_t idx = -1;
switch_codec_t write_codec = {0};
switch_frame_t write_frame = {0};
@ -1762,9 +1763,28 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
file = NULL;
}
argc = switch_separate_string(data, '&', peer_names, (sizeof(peer_names) / sizeof(peer_names[0])));
or_argc = switch_separate_string(data, '|', pipe_names, (sizeof(pipe_names) / sizeof(pipe_names[0])));
for (i = 0; i < argc; i++) {
for (r = 0; r < or_argc; r++) {
memset(peer_names, 0, sizeof(peer_names));
peer_session = NULL;
memset(peer_sessions, 0, sizeof(peer_sessions));
memset(peer_channels, 0, sizeof(peer_channels));
memset(caller_profiles, 0, sizeof(caller_profiles));
chan_type = NULL;
chan_data = NULL;
peer_channel = NULL;
start = 0;
read_frame = NULL;
pool = NULL;
pass = 0;
file = NULL;
key = NULL;
var = NULL;
and_argc = switch_separate_string(pipe_names[r], '&', peer_names, (sizeof(peer_names) / sizeof(peer_names[0])));
for (i = 0; i < and_argc; i++) {
chan_type = peer_names[i];
if ((chan_data = strchr(chan_type, '/')) != 0) {
@ -1881,7 +1901,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
for (;;) {
uint32_t valid_channels = 0;
for (i = 0; i < argc; i++) {
for (i = 0; i < and_argc; i++) {
int state;
if (!peer_channels[i]) {
@ -1943,7 +1963,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
}
while ((!caller_channel || switch_channel_ready(caller_channel)) &&
check_channel_status(peer_channels, peer_sessions, argc, &idx, file, key) && ((time(NULL) - start) < (time_t)timelimit_sec)) {
check_channel_status(peer_channels, peer_sessions, and_argc, &idx, file, key) && ((time(NULL) - start) < (time_t)timelimit_sec)) {
/* read from the channel while we wait if the audio is up on it */
if (session && !switch_channel_test_flag(caller_channel, CF_NOMEDIA) &&
@ -1969,7 +1989,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_core_session_reset(session);
}
for (i = 0; i < argc; i++) {
for (i = 0; i < and_argc; i++) {
if (!peer_channels[i]) {
continue;
}
@ -2015,7 +2035,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (peer_channel) {
*cause = switch_channel_get_cause(peer_channel);
} else {
for (i = 0; i < argc; i++) {
for (i = 0; i < and_argc; i++) {
if (!peer_channels[i]) {
continue;
}
@ -2030,20 +2050,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Error Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause));
}
if (odata) {
free(odata);
}
if (!pass && write_codec.implementation) {
switch_core_codec_destroy(&write_codec);
}
for (i = 0; i < argc; i++) {
for (i = 0; i < and_argc; i++) {
if (!peer_channels[i]) {
continue;
}
switch_core_session_rwunlock(peer_sessions[i]);
}
if (status == SWITCH_STATUS_SUCCESS) {
break;
}
}
switch_safe_free(odata);
return status;
}