mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 09:58:17 +00:00
merge r5393 from http://svn.freeswitch.org/svn/freeswitch/branches/greenlizard/
* implement originate() and bridge() methods in CoreSession. * api changes for originate() : no longer passes 11 arguments git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5410 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -7,7 +7,14 @@
|
||||
|
||||
#define sanity_check(x) do { if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
|
||||
#define sanity_check_noreturn do { if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
|
||||
#define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL;} while(0)
|
||||
#define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown"; caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = ""; caller_profile.username = ""; } while(0)
|
||||
|
||||
|
||||
|
||||
CoreSession::CoreSession()
|
||||
{
|
||||
init_vars();
|
||||
}
|
||||
|
||||
CoreSession::CoreSession(char *nuuid)
|
||||
{
|
||||
@@ -177,7 +184,9 @@ int CoreSession::transfer(char *extension, char *dialplan, char *context)
|
||||
{
|
||||
switch_status_t status;
|
||||
sanity_check(-1);
|
||||
begin_allow_threads();
|
||||
status = switch_ivr_session_transfer(session, extension, dialplan, context);
|
||||
end_allow_threads();
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -250,6 +259,83 @@ bool CoreSession::ready() {
|
||||
|
||||
}
|
||||
|
||||
int CoreSession::originate(CoreSession *aleg_session,
|
||||
char *dest,
|
||||
int timeout)
|
||||
{
|
||||
|
||||
switch_memory_pool_t *pool = NULL;
|
||||
switch_core_session_t *aleg_core_session = NULL;
|
||||
switch_call_cause_t cause;
|
||||
|
||||
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
|
||||
if (aleg_session != NULL) {
|
||||
aleg_core_session = aleg_session->session;
|
||||
}
|
||||
|
||||
begin_allow_threads();
|
||||
|
||||
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (switch_ivr_originate(aleg_core_session,
|
||||
&session,
|
||||
&cause,
|
||||
dest,
|
||||
timeout,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&caller_profile) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error Creating Outgoing Channel! [%s]\n", dest);
|
||||
goto failed;
|
||||
|
||||
}
|
||||
|
||||
end_allow_threads();
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
failed:
|
||||
end_allow_threads();
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
void CoreSession::setCallerData(char *var, char *val) {
|
||||
|
||||
if (strcmp(var, "dialplan") == 0) {
|
||||
caller_profile.dialplan = val;
|
||||
}
|
||||
if (strcmp(var, "context") == 0) {
|
||||
caller_profile.context = val;
|
||||
}
|
||||
if (strcmp(var, "caller_id_name") == 0) {
|
||||
caller_profile.caller_id_name = val;
|
||||
}
|
||||
if (strcmp(var, "caller_id_number") == 0) {
|
||||
caller_profile.caller_id_number = val;
|
||||
}
|
||||
if (strcmp(var, "network_addr") == 0) {
|
||||
caller_profile.network_addr = val;
|
||||
}
|
||||
if (strcmp(var, "ani") == 0) {
|
||||
caller_profile.ani = val;
|
||||
}
|
||||
if (strcmp(var, "aniii") == 0) {
|
||||
caller_profile.aniii = val;
|
||||
}
|
||||
if (strcmp(var, "rdnis") == 0) {
|
||||
caller_profile.rdnis = val;
|
||||
}
|
||||
if (strcmp(var, "username") == 0) {
|
||||
caller_profile.username = val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CoreSession::begin_allow_threads() {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CoreSession::begin_allow_threads() called and does nothing\n");
|
||||
}
|
||||
@@ -274,6 +360,147 @@ void CoreSession::store_file_handle(switch_file_handle_t *fh) {
|
||||
}
|
||||
|
||||
|
||||
/* ---- methods not bound to CoreSession instance ---- */
|
||||
|
||||
|
||||
void console_log(char *level_str, char *msg)
|
||||
{
|
||||
switch_log_level_t level = SWITCH_LOG_DEBUG;
|
||||
if (level_str) {
|
||||
level = switch_log_str2level(level_str);
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
|
||||
fflush(stdout); // TEMP ONLY!! SHOULD NOT BE CHECKED IN!!
|
||||
}
|
||||
|
||||
void console_clean_log(char *msg)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN,SWITCH_LOG_DEBUG, msg);
|
||||
}
|
||||
|
||||
|
||||
char *api_execute(char *cmd, char *arg)
|
||||
{
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
switch_api_execute(cmd, arg, NULL, &stream);
|
||||
return (char *) stream.data;
|
||||
}
|
||||
|
||||
void api_reply_delete(char *reply)
|
||||
{
|
||||
if (!switch_strlen_zero(reply)) {
|
||||
free(reply);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void bridge(CoreSession &session_a, CoreSession &session_b)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "bridge called, session_a uuid: %s\n", session_a.get_uuid());
|
||||
switch_input_callback_function_t dtmf_func = NULL;
|
||||
switch_input_args_t args;
|
||||
|
||||
session_a.begin_allow_threads();
|
||||
args = session_a.get_cb_args(); // get the cb_args data structure for session a
|
||||
dtmf_func = args.input_callback; // get the call back function
|
||||
switch_ivr_multi_threaded_bridge(session_a.session, session_b.session, dtmf_func, args.buf, args.buf);
|
||||
session_a.end_allow_threads();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch_status_t process_callback_result(char *ret,
|
||||
struct input_callback_state *cb_state,
|
||||
switch_core_session_t *session)
|
||||
{
|
||||
|
||||
switch_file_handle_t *fh = NULL;
|
||||
fh = (switch_file_handle_t *) cb_state->extra;
|
||||
|
||||
if (!fh) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (!strncasecmp(ret, "speed", 4)) {
|
||||
char *p;
|
||||
|
||||
if ((p = strchr(ret, ':'))) {
|
||||
p++;
|
||||
if (*p == '+' || *p == '-') {
|
||||
int step;
|
||||
if (!(step = atoi(p))) {
|
||||
step = 1;
|
||||
}
|
||||
fh->speed += step;
|
||||
} else {
|
||||
int speed = atoi(p);
|
||||
fh->speed = speed;
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
|
||||
} else if (!strcasecmp(ret, "pause")) {
|
||||
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
|
||||
switch_clear_flag(fh, SWITCH_FILE_PAUSE);
|
||||
} else {
|
||||
switch_set_flag(fh, SWITCH_FILE_PAUSE);
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
} else if (!strcasecmp(ret, "stop")) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
} else if (!strcasecmp(ret, "restart")) {
|
||||
unsigned int pos = 0;
|
||||
fh->speed = 0;
|
||||
switch_core_file_seek(fh, &pos, 0, SEEK_SET);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
} else if (!strncasecmp(ret, "seek", 4)) {
|
||||
switch_codec_t *codec;
|
||||
unsigned int samps = 0;
|
||||
unsigned int pos = 0;
|
||||
char *p;
|
||||
codec = switch_core_session_get_read_codec(session);
|
||||
|
||||
if ((p = strchr(ret, ':'))) {
|
||||
p++;
|
||||
if (*p == '+' || *p == '-') {
|
||||
int step;
|
||||
if (!(step = atoi(p))) {
|
||||
step = 1000;
|
||||
}
|
||||
if (step > 0) {
|
||||
samps = step * (codec->implementation->samples_per_second / 1000);
|
||||
switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
|
||||
} else {
|
||||
samps = step * (codec->implementation->samples_per_second / 1000);
|
||||
switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
|
||||
}
|
||||
} else {
|
||||
samps = atoi(p) * (codec->implementation->samples_per_second / 1000);
|
||||
switch_core_file_seek(fh, &pos, samps, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
Reference in New Issue
Block a user