*deep breath*

Ok,

This one adds a bunch of stuff on top of the framework restructuring from yesterday.

1) originate api function:
Usage: originate <call url> <exten> [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]

This will call the specified url then transfer the call to the specified extension

example: originate exosip/1000@somehost 1000 XML default

2) mutiple destinations in outbound calls:

This means any dialstring may contain an '&' separated list of call urls
When using mutiple urls in this manner it is possible to map a certian key as required
indication of an accepted call.  You may also supply a filename to play possibly instructing the 
call recipiant to press the desired key etc...

The example below will call 2 locations playing prompt.wav to any who answer and
completing the call to the first offhook recipiant to dial "4"



      <extension name="3002">
        <condition field="destination_number" expression="^3002$">
          <action application="set" data="call_timeout=60"/>
          <action application="set" data="group_confirm_file=/path/to/prompt.wav"/>
          <action application="set" data="group_confirm_key=4"/>
          <action application="bridge" data="iax/guest@somebox/1234&exosip/1000@somehost"/>
        </condition>
      </extension>

The following is the equivilant but the confirm data is passed vial the bridge parameters
(This is for situations where there is no originating channel to set variables to)

      <extension name="3002">
        <condition field="destination_number" expression="^3002$">
          <action application="bridge" data=/path/to/prompt.wav:4"confirm=iax/guest@somebox/1234&exosip/1000@somehost"/>
        </condition>
      </extension>

Omitting the file and key stuff will simply comeplete the call to whoever answers first. 
(this is similar to how other less fortunate software handles the situation with thier best effort.)

This logic should be permitted in anything that establishes an outgoing call with
switch_ivr_originate()

Yes! That means even in this new originate api command you can call mutiple targets and send
whoever answers first to an extension that calls more mutiple targets.  (better test it though!)


Oh, and you should be able to do the same in the mod_conference dial and dynamic conference features

please report any behaviour contrary to this account to me ASAP cos i would not be terribly
suprised if I forgot some scenerio that causes an explosion I did all this in 1 afternoon so it probably needs tuning still.





git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2311 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2006-08-17 00:53:09 +00:00
parent 286b2c791e
commit 78d060c6a7
9 changed files with 486 additions and 137 deletions
@@ -40,18 +40,23 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
{
switch_channel_t *caller_channel;
switch_core_session_t *peer_session;
unsigned int timelimit = 60; /* probably a useful option to pass in when there's time */
unsigned int timelimit = 60;
char *var;
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
if (switch_ivr_originate(session, &peer_session, data, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) {
timelimit = atoi(var);
}
if (switch_ivr_originate(session, &peer_session, data, timelimit, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
return;
} else {
/* peer channel is read locked now the bridge func will unlock it for us */
switch_ivr_multi_threaded_bridge(session, peer_session, timelimit, NULL, NULL, NULL);
switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
}
}
@@ -209,6 +209,72 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t originate_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
switch_channel_t *caller_channel;
switch_core_session_t *caller_session;
char *argv[7] = {0};
int x, argc = 0;
char *aleg, *exten, *dp, *context, *cid_name, *cid_num;
uint32_t timeout = 60;
if (isession) {
stream->write_function(stream, "Illegal Usage\n");
return SWITCH_STATUS_SUCCESS;
}
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "Usage: originate <call url> <exten> [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]\n");
return SWITCH_STATUS_SUCCESS;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
for(x = 0; x < argc; x++) {
if (!strcasecmp(argv[x], "undef")) {
argv[x] = NULL;
}
}
aleg = argv[0];
exten = argv[1];
dp = argv[2];
context = argv[3];
cid_name = argv[4];
cid_num = argv[5];
if (!dp) {
dp = "XML";
}
if (!context) {
context = "default";
}
if (argv[6]) {
timeout = atoi(argv[6]);
}
if (!aleg && exten) {
stream->write_function(stream, "Invalid Arguements\n");
return SWITCH_STATUS_SUCCESS;
}
if (switch_ivr_originate(NULL, &caller_session, aleg, timeout, NULL, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s]\n", aleg);
return SWITCH_STATUS_SUCCESS;
}
caller_channel = switch_core_session_get_channel(caller_session);
assert(caller_channel != NULL);
switch_channel_clear_state_handler(caller_channel, NULL);
switch_core_session_rwunlock(caller_session);
switch_ivr_session_transfer(caller_session, exten, dp, context);
return SWITCH_STATUS_SUCCESS;;
}
struct holder {
switch_stream_handle_t *stream;
char *http;
@@ -349,7 +415,7 @@ static switch_api_interface_t transfer_api_interface = {
static switch_api_interface_t load_api_interface = {
/*.interface_name */ "load",
/*.desc */ "Load Modile",
/*.desc */ "Load Module",
/*.function */ load_function,
/*.next */ &transfer_api_interface
};
@@ -369,6 +435,14 @@ static switch_api_interface_t commands_api_interface = {
/*.next */ &reload_api_interface
};
static switch_api_interface_t originate_api_interface = {
/*.interface_name */ "originate",
/*.desc */ "Originate a Call",
/*.function */ originate_function,
/*.next */ &commands_api_interface
};
static const switch_loadable_module_interface_t mod_commands_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
@@ -376,7 +450,7 @@ static const switch_loadable_module_interface_t mod_commands_module_interface =
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ &commands_api_interface
/*.api_interface */ &originate_api_interface
};
@@ -192,7 +192,12 @@ static switch_status_t conference_say(conference_obj_t *conference, char *text,
static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim);
static switch_status_t conf_function(char *buf, switch_core_session_t *session, switch_stream_handle_t *stream);
static switch_status_t audio_bridge_on_ring(switch_core_session_t *session);
static switch_status_t conference_outcall(conference_obj_t *conference, switch_core_session_t *session, char *bridgeto, char *cid_name, char *cid_num);
static switch_status_t conference_outcall(conference_obj_t *conference,
switch_core_session_t *session,
char *bridgeto,
uint32_t timeout,
char *cid_name,
char *cid_num);
static void conference_function(switch_core_session_t *session, char *data);
static void launch_conference_thread(conference_obj_t *conference);
static void *SWITCH_THREAD_FUNC input_thread_run(switch_thread_t *thread, void *obj);
@@ -1387,7 +1392,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session,
goto done;
} else if (!strcasecmp(argv[1], "dial")) {
if (argc > 2) {
conference_outcall(conference, NULL, argv[2], argv[3], argv[4]);
conference_outcall(conference, NULL, argv[2], 60, argv[3], argv[4]);
stream->write_function(stream, "OK\n");
goto done;
} else {
@@ -1971,7 +1976,12 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers = {
/*.on_hold */ NULL,
};
static switch_status_t conference_outcall(conference_obj_t *conference, switch_core_session_t *session, char *bridgeto, char *cid_name, char *cid_num)
static switch_status_t conference_outcall(conference_obj_t *conference,
switch_core_session_t *session,
char *bridgeto,
uint32_t timeout,
char *cid_name,
char *cid_num)
{
switch_core_session_t *peer_session;
switch_channel_t *peer_channel;
@@ -1979,7 +1989,7 @@ static switch_status_t conference_outcall(conference_obj_t *conference, switch_c
switch_channel_t *caller_channel = NULL;
if (switch_ivr_originate(session, &peer_session, bridgeto, &audio_bridge_peer_state_handlers, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) {
if (switch_ivr_originate(session, &peer_session, bridgeto, timeout, &audio_bridge_peer_state_handlers, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
if (session) {
caller_channel = switch_core_session_get_channel(session);
@@ -2172,7 +2182,11 @@ static void conference_function(switch_core_session_t *session, char *data)
if (strlen(pin) < strlen(conference->pin)) {
buf = pin + strlen(pin);
switch_ivr_collect_digits_count(session, buf, sizeof(pin) - (unsigned int)strlen(pin), (unsigned int)strlen(conference->pin) - (unsigned int)strlen(pin), "#", &term, 10000);
switch_ivr_collect_digits_count(session,
buf,
sizeof(pin) - (unsigned int)strlen(pin),
(unsigned int)strlen(conference->pin) - (unsigned int)strlen(pin),
"#", &term, 10000);
}
if (strcmp(pin, conference->pin)) {
@@ -2196,7 +2210,7 @@ static void conference_function(switch_core_session_t *session, char *data)
}
if (bridgeto) {
if (conference_outcall(conference, session, bridgeto, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
if (conference_outcall(conference, session, bridgeto, 60, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
goto done;
}
}
@@ -1903,7 +1903,7 @@ static JSBool js_bridge(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
return JS_FALSE;
}
switch_ivr_multi_threaded_bridge(jss_a->session, jss_b->session, timelimit, NULL, NULL, NULL);
switch_ivr_multi_threaded_bridge(jss_a->session, jss_b->session, NULL, NULL, NULL);
return JS_TRUE;
}