refactor to avoid some potential issues with channels that are hungup instantly after being answered

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4926 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-04-13 22:15:58 +00:00
parent ff44ce11cc
commit eb2124ae32
16 changed files with 1524 additions and 1606 deletions

View File

@ -283,6 +283,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
\param cid_num_override override the caller id number \param cid_num_override override the caller id number
\param caller_profile_override override the entire calling caller profile \param caller_profile_override override the entire calling caller profile
\return SWITCH_STATUS_SUCCESS if bleg is a running session. \return SWITCH_STATUS_SUCCESS if bleg is a running session.
\note bleg will be read locked which must be unlocked with switch_core_session_rwunlock() before losing scope
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session,
switch_core_session_t **bleg, switch_core_session_t **bleg,

View File

@ -39,7 +39,7 @@ static const char modname[] = "mod_bridgecall";
static void audio_bridge_function(switch_core_session_t *session, char *data) static void audio_bridge_function(switch_core_session_t *session, char *data)
{ {
switch_channel_t *caller_channel; switch_channel_t *caller_channel;
switch_core_session_t *peer_session; switch_core_session_t *peer_session = NULL;
unsigned int timelimit = 60; unsigned int timelimit = 60;
char *var; char *var;
uint8_t no_media_bridge = 0; uint8_t no_media_bridge = 0;
@ -98,7 +98,7 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
if (bad) { if (bad) {
switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return; goto end;
} }
} }
@ -113,6 +113,10 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
} }
} }
end:
if (peer_session) {
switch_core_session_rwunlock(peer_session);
}
} }
} }

View File

@ -590,7 +590,7 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession
static switch_status_t originate_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream) static switch_status_t originate_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{ {
switch_channel_t *caller_channel; switch_channel_t *caller_channel;
switch_core_session_t *caller_session; switch_core_session_t *caller_session = NULL;
char *argv[7] = { 0 }; char *argv[7] = { 0 };
int i = 0, x, argc = 0; int i = 0, x, argc = 0;
char *aleg, *exten, *dp, *context, *cid_name, *cid_num; char *aleg, *exten, *dp, *context, *cid_name, *cid_num;
@ -684,6 +684,10 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
stream->write_function(stream, "Created Session: %s\n", switch_core_session_get_uuid(caller_session)); stream->write_function(stream, "Created Session: %s\n", switch_core_session_get_uuid(caller_session));
} }
if (caller_session) {
switch_core_session_rwunlock(caller_session);
}
return SWITCH_STATUS_SUCCESS;; return SWITCH_STATUS_SUCCESS;;
} }

View File

@ -3476,12 +3476,12 @@ static switch_status_t conference_outcall(conference_obj_t * conference,
switch_core_session_t *session, switch_core_session_t *session,
char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num, switch_call_cause_t *cause) char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num, switch_call_cause_t *cause)
{ {
switch_core_session_t *peer_session; switch_core_session_t *peer_session = NULL;
switch_channel_t *peer_channel; switch_channel_t *peer_channel;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *caller_channel = NULL; switch_channel_t *caller_channel = NULL;
char appdata[512]; char appdata[512];
int rdlock = 0;
*cause = SWITCH_CAUSE_NORMAL_CLEARING; *cause = SWITCH_CAUSE_NORMAL_CLEARING;
@ -3498,7 +3498,7 @@ static switch_status_t conference_outcall(conference_obj_t * conference,
peer_channel = switch_core_session_get_channel(peer_session); peer_channel = switch_core_session_get_channel(peer_session);
assert(peer_channel != NULL); assert(peer_channel != NULL);
rdlock = 1;
goto callup; goto callup;
} }
@ -3534,7 +3534,7 @@ static switch_status_t conference_outcall(conference_obj_t * conference,
goto done; goto done;
} }
rdlock = 1;
peer_channel = switch_core_session_get_channel(peer_session); peer_channel = switch_core_session_get_channel(peer_session);
assert(peer_channel != NULL); assert(peer_channel != NULL);
@ -3585,6 +3585,10 @@ static switch_status_t conference_outcall(conference_obj_t * conference,
if (conference) { if (conference) {
switch_thread_rwlock_unlock(conference->rwlock); switch_thread_rwlock_unlock(conference->rwlock);
} }
if (rdlock && peer_session) {
switch_core_session_rwunlock(peer_session);
}
return status; return status;
} }

View File

@ -242,11 +242,6 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_IO);
if (tech_pvt->home) {
su_home_unref(tech_pvt->home);
tech_pvt->home = NULL;
}
if (tech_pvt->sofia_private) { if (tech_pvt->sofia_private) {
*tech_pvt->sofia_private->uuid = '\0'; *tech_pvt->sofia_private->uuid = '\0';
} }
@ -847,6 +842,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
goto done; goto done;
} }
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession));
data = switch_core_session_strdup(nsession, outbound_profile->destination_number); data = switch_core_session_strdup(nsession, outbound_profile->destination_number);
profile_name = data; profile_name = data;

View File

@ -54,11 +54,6 @@ struct sofia_profile;
typedef struct sofia_profile sofia_profile_t; typedef struct sofia_profile sofia_profile_t;
#define NUA_MAGIC_T sofia_profile_t #define NUA_MAGIC_T sofia_profile_t
struct sofia_private {
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
outbound_reg_t *gateway;
};
typedef struct sofia_private sofia_private_t; typedef struct sofia_private sofia_private_t;
struct private_object; struct private_object;
@ -85,6 +80,13 @@ typedef struct private_object private_object_t;
#include <sofia-sip/nea.h> #include <sofia-sip/nea.h>
#include <sofia-sip/msg_addr.h> #include <sofia-sip/msg_addr.h>
struct sofia_private {
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
outbound_reg_t *gateway;
su_home_t *home;
};
#define set_param(ptr,val) if (ptr) {free(ptr) ; ptr = NULL;} if (val) {ptr = strdup(val);} #define set_param(ptr,val) if (ptr) {free(ptr) ; ptr = NULL;} if (val) {ptr = strdup(val);}
#define set_anchor(t,m) if (t->Anchor) {delete t->Anchor;} t->Anchor = new SipMessage(m); #define set_anchor(t,m) if (t->Anchor) {delete t->Anchor;} t->Anchor = new SipMessage(m);
@ -305,7 +307,6 @@ struct private_object {
switch_payload_t bcng_pt; switch_payload_t bcng_pt;
nua_handle_t *nh; nua_handle_t *nh;
nua_handle_t *nh2; nua_handle_t *nh2;
su_home_t *home;
sip_contact_t *contact; sip_contact_t *contact;
}; };

View File

@ -839,6 +839,8 @@ void sofia_handle_sip_i_state(int status,
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
assert(tech_pvt->nh != NULL); assert(tech_pvt->nh != NULL);
if (switch_channel_test_flag(channel, CF_NOMEDIA)) { if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
switch_set_flag(tech_pvt, TFLAG_NOMEDIA); switch_set_flag(tech_pvt, TFLAG_NOMEDIA);
} }
@ -935,7 +937,7 @@ void sofia_handle_sip_i_state(int status,
switch_core_session_thread_launch(session); switch_core_session_thread_launch(session);
goto done; goto done;
} else { } else {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->sofia_private->home, r_sdp, (int) strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
@ -958,7 +960,7 @@ void sofia_handle_sip_i_state(int status,
switch_core_session_thread_launch(session); switch_core_session_thread_launch(session);
if (replaces_str && (replaces = sip_replaces_make(tech_pvt->home, replaces_str)) if (replaces_str && (replaces = sip_replaces_make(tech_pvt->sofia_private->home, replaces_str))
&& (bnh = nua_handle_by_replaces(nua, replaces))) { && (bnh = nua_handle_by_replaces(nua, replaces))) {
sofia_private_t *b_private; sofia_private_t *b_private;
@ -1016,7 +1018,7 @@ void sofia_handle_sip_i_state(int status,
if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
goto done; goto done;
} else { } else {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->sofia_private->home, r_sdp, (int) strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
@ -1084,7 +1086,7 @@ void sofia_handle_sip_i_state(int status,
} }
goto done; goto done;
} else { } else {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->sofia_private->home, r_sdp, (int) strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
@ -1133,11 +1135,17 @@ void sofia_handle_sip_i_state(int status,
} }
if (tech_pvt->sofia_private) { if (tech_pvt->sofia_private) {
if (sofia_private->home) {
su_home_unref(sofia_private->home);
}
free(tech_pvt->sofia_private); free(tech_pvt->sofia_private);
tech_pvt->sofia_private = NULL; tech_pvt->sofia_private = NULL;
} }
tech_pvt->nh = NULL; tech_pvt->nh = NULL;
} else if (sofia_private) { } else if (sofia_private) {
if (sofia_private->home) {
su_home_unref(sofia_private->home);
}
free(sofia_private); free(sofia_private);
} }
@ -1213,7 +1221,7 @@ void sofia_handle_sip_i_refer(nua_t * nua, sofia_profile_t * profile, nua_handle
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
goto done; goto done;
} }
if ((replaces = sip_replaces_make(tech_pvt->home, rep)) if ((replaces = sip_replaces_make(tech_pvt->sofia_private->home, rep))
&& (bnh = nua_handle_by_replaces(nua, replaces))) { && (bnh = nua_handle_by_replaces(nua, replaces))) {
sofia_private_t *b_private = NULL; sofia_private_t *b_private = NULL;
private_object_t *b_tech_pvt = NULL; private_object_t *b_tech_pvt = NULL;
@ -1319,6 +1327,7 @@ void sofia_handle_sip_i_refer(nua_t * nua, sofia_profile_t * profile, nua_handle
switch_set_flag_locked(tech_pvt, TFLAG_BYE); switch_set_flag_locked(tech_pvt, TFLAG_BYE);
nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END()); NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
switch_core_session_rwunlock(tsession);
} else { } else {
goto error; goto error;
} }
@ -1575,6 +1584,7 @@ void sofia_handle_sip_i_invite(nua_t * nua, sofia_profile_t * profile, nua_handl
sofia_glue_terminate_session(&session, SWITCH_CAUSE_SWITCH_CONGESTION, __LINE__); sofia_glue_terminate_session(&session, SWITCH_CAUSE_SWITCH_CONGESTION, __LINE__);
return; return;
} }
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
if (!switch_strlen_zero(key)) { if (!switch_strlen_zero(key)) {
tech_pvt->key = switch_core_session_strdup(session, key); tech_pvt->key = switch_core_session_strdup(session, key);
@ -1723,6 +1733,8 @@ void sofia_handle_sip_i_invite(nua_t * nua, sofia_profile_t * profile, nua_handl
abort(); abort();
} }
memset(tech_pvt->sofia_private, 0, sizeof(*tech_pvt->sofia_private)); memset(tech_pvt->sofia_private, 0, sizeof(*tech_pvt->sofia_private));
tech_pvt->sofia_private->home = su_home_new(sizeof(*tech_pvt->sofia_private->home));
switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid)); switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid));
nua_handle_bind(nh, tech_pvt->sofia_private); nua_handle_bind(nh, tech_pvt->sofia_private);
tech_pvt->nh = nh; tech_pvt->nh = nh;

View File

@ -209,7 +209,7 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
//switch_channel_set_flag(channel, CF_ACCEPT_CNG); //switch_channel_set_flag(channel, CF_ACCEPT_CNG);
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_lock(tech_pvt->flag_mutex); switch_mutex_lock(tech_pvt->flag_mutex);
tech_pvt->flags = profile->flags; tech_pvt->flags = profile->flags;
switch_mutex_unlock(tech_pvt->flag_mutex); switch_mutex_unlock(tech_pvt->flag_mutex);
@ -227,8 +227,6 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
} }
tech_pvt->session = session; tech_pvt->session = session;
tech_pvt->home = su_home_new(sizeof(*tech_pvt->home));
switch_core_session_set_private(session, tech_pvt); switch_core_session_set_private(session, tech_pvt);
@ -428,6 +426,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
abort(); abort();
} }
memset(tech_pvt->sofia_private, 0, sizeof(*tech_pvt->sofia_private)); memset(tech_pvt->sofia_private, 0, sizeof(*tech_pvt->sofia_private));
tech_pvt->sofia_private->home = su_home_new(sizeof(*tech_pvt->sofia_private->home));
switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid)); switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid));
nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private); nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private);
@ -544,7 +543,7 @@ void sofia_glue_tech_absorb_sdp(private_object_t * tech_pvt)
sdp_media_t *m; sdp_media_t *m;
sdp_connection_t *connection; sdp_connection_t *connection;
if ((parser = sdp_parse(tech_pvt->home, sdp_str, (int) strlen(sdp_str), 0))) { if ((parser = sdp_parse(tech_pvt->sofia_private->home, sdp_str, (int) strlen(sdp_str), 0))) {
if ((sdp = sdp_session(parser))) { if ((sdp = sdp_session(parser))) {
for (m = sdp->sdp_media; m; m = m->m_next) { for (m = sdp->sdp_media; m; m = m->m_next) {
if (m->m_type != sdp_media_audio) { if (m->m_type != sdp_media_audio) {
@ -775,7 +774,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t * tech_pvt)
switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, char *r_sdp) switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, char *r_sdp)
{ {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->sofia_private->home, r_sdp, (int) strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session); switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session);

View File

@ -1038,7 +1038,7 @@ void sofia_presence_set_chat_hash(private_object_t * tech_pvt, sip_t const *sip)
} }
if (sofia_reg_find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) { if (sofia_reg_find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) {
tech_pvt->chat_from = sip_header_as_string(tech_pvt->home, (const sip_header_t *) sip->sip_to); tech_pvt->chat_from = sip_header_as_string(tech_pvt->sofia_private->home, (const sip_header_t *) sip->sip_to);
tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf); tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip); sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
} else { } else {

View File

@ -76,4 +76,8 @@ package fs_perl;
package fs_perl; package fs_perl;
*FREESWITCH_PEN = *fs_perlc::FREESWITCH_PEN;
*FREESWITCH_OID_PREFIX = *fs_perlc::FREESWITCH_OID_PREFIX;
*FREESWITCH_ITAD = *fs_perlc::FREESWITCH_ITAD;
*__EXTENSIONS__ = *fs_perlc::__EXTENSIONS__;
1; 1;

View File

@ -15,8 +15,7 @@
* clashes if multiple interpreters are included * clashes if multiple interpreters are included
* *
************************************************************************/ ************************************************************************/
#include <switch.h> #include "switch.h"
#define SWIG_TypeRegister SWIG_Perl_TypeRegister #define SWIG_TypeRegister SWIG_Perl_TypeRegister
#define SWIG_TypeCheck SWIG_Perl_TypeCheck #define SWIG_TypeCheck SWIG_Perl_TypeCheck
#define SWIG_TypeCast SWIG_Perl_TypeCast #define SWIG_TypeCast SWIG_Perl_TypeCast
@ -116,8 +115,7 @@ extern "C" {
while (tc) { while (tc) {
if (strcmp(tc->name, ti->name) == 0) { if (strcmp(tc->name, ti->name) == 0) {
/* Already exists in the table. Just add additional types to the list */ /* Already exists in the table. Just add additional types to the list */
if (tc->clientdata) if (tc->clientdata) ti->clientdata = tc->clientdata;
ti->clientdata = tc->clientdata;
head = tc; head = tc;
next = tc->next; next = tc->next;
goto l1; goto l1;
@ -142,8 +140,7 @@ extern "C" {
head = tc; head = tc;
tc++; tc++;
} }
if (next) if (next) next->prev = head;
next->prev = head;
head->next = next; head->next = next;
return ret; return ret;
} }
@ -152,13 +149,11 @@ extern "C" {
SWIGRUNTIME(swig_type_info *) SWIGRUNTIME(swig_type_info *)
SWIG_TypeCheck(char *c, swig_type_info *ty) { SWIG_TypeCheck(char *c, swig_type_info *ty) {
swig_type_info *s; swig_type_info *s;
if (!ty) if (!ty) return 0; /* Void pointer */
return 0; /* Void pointer */
s = ty->next; /* First element always just a name */ s = ty->next; /* First element always just a name */
do { do {
if (strcmp(s->name,c) == 0) { if (strcmp(s->name,c) == 0) {
if (s == ty->next) if (s == ty->next) return s;
return s;
/* Move s to the top of the linked list */ /* Move s to the top of the linked list */
s->prev->next = s->next; s->prev->next = s->next;
if (s->next) { if (s->next) {
@ -166,8 +161,7 @@ extern "C" {
} }
/* Insert s as second element in the list */ /* Insert s as second element in the list */
s->next = ty->next; s->next = ty->next;
if (ty->next) if (ty->next) ty->next->prev = s;
ty->next->prev = s;
ty->next = s; ty->next = s;
s->prev = ty; s->prev = ty;
return s; return s;
@ -180,8 +174,7 @@ extern "C" {
/* Cast a pointer up an inheritance hierarchy */ /* Cast a pointer up an inheritance hierarchy */
SWIGRUNTIME(void *) SWIGRUNTIME(void *)
SWIG_TypeCast(swig_type_info *ty, void *ptr) { SWIG_TypeCast(swig_type_info *ty, void *ptr) {
if ((!ty) || (!ty->converter)) if ((!ty) || (!ty->converter)) return ptr;
return ptr;
return (*ty->converter)(ptr); return (*ty->converter)(ptr);
} }
@ -189,12 +182,10 @@ extern "C" {
SWIGRUNTIME(swig_type_info *) SWIGRUNTIME(swig_type_info *)
SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
swig_type_info *lastty = ty; swig_type_info *lastty = ty;
if (!ty || !ty->dcast) if (!ty || !ty->dcast) return ty;
return ty;
while (ty && (ty->dcast)) { while (ty && (ty->dcast)) {
ty = (*ty->dcast)(ptr); ty = (*ty->dcast)(ptr);
if (ty) if (ty) lastty = ty;
lastty = ty;
} }
return lastty; return lastty;
} }
@ -210,10 +201,8 @@ extern "C" {
SWIG_TypeQuery(const char *name) { SWIG_TypeQuery(const char *name) {
swig_type_info *ty = swig_type_list; swig_type_info *ty = swig_type_list;
while (ty) { while (ty) {
if (ty->str && (strcmp(name, ty->str) == 0)) if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
return ty; if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
if (ty->name && (strcmp(name, ty->name) == 0))
return ty;
ty = ty->prev; ty = ty->prev;
} }
return 0; return 0;
@ -223,8 +212,7 @@ extern "C" {
SWIGRUNTIME(void) SWIGRUNTIME(void)
SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
swig_type_info *tc, *equiv; swig_type_info *tc, *equiv;
if (ti->clientdata == clientdata) if (ti->clientdata == clientdata) return;
return;
ti->clientdata = clientdata; ti->clientdata = clientdata;
equiv = ti->next; equiv = ti->next;
while (equiv) { while (equiv) {
@ -315,7 +303,9 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/* Macro to call an XS function */ /* Macro to call an XS function */
#ifdef PERL_OBJECT #ifdef PERL_OBJECT
# define SWIG_CALLXS(_name) _name(cv,pPerl) # define SWIG_CALLXS(_name) _name(cv,pPerl)
#else #else
@ -325,9 +315,13 @@ extern "C" {
# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) # define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv)
# endif # endif
#endif #endif
/* Contract support */ /* Contract support */
#define SWIG_contract_assert(expr,msg) if (!(expr)) { SWIG_croak(msg); } else #define SWIG_contract_assert(expr,msg) if (!(expr)) { SWIG_croak(msg); } else
/* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */ /* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */
#ifdef PERL_OBJECT #ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this; #define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *); typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *);
@ -339,6 +333,7 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
#define SWIGCLASS_STATIC #define SWIGCLASS_STATIC
#else #else
@ -355,6 +350,8 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#else #else
#define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b) #define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b)
typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *); typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
@ -365,12 +362,16 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif
#endif #endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE) #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh) #define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif #endif
/* Modifications for newer Perl 5.005 releases */ /* Modifications for newer Perl 5.005 releases */
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50)))) #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
# ifndef PL_sv_yes # ifndef PL_sv_yes
# define PL_sv_yes sv_yes # define PL_sv_yes sv_yes
@ -382,7 +383,9 @@ extern "C" {
# define PL_na na # define PL_na na
# endif # endif
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -456,13 +459,11 @@ extern "C" {
SWIGRUNTIME(swig_type_info *) SWIGRUNTIME(swig_type_info *)
SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) { SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) {
swig_type_info *s; swig_type_info *s;
if (!ty) if (!ty) return 0; /* Void pointer */
return 0; /* Void pointer */
s = ty->next; /* First element always just a name */ s = ty->next; /* First element always just a name */
do { do {
if (sv_derived_from(rv, (char *) s->name)) { if (sv_derived_from(rv, (char *) s->name)) {
if (s == ty->next) if (s == ty->next) return s;
return s;
/* Move s to the top of the linked list */ /* Move s to the top of the linked list */
s->prev->next = s->next; s->prev->next = s->next;
if (s->next) { if (s->next) {
@ -470,8 +471,7 @@ extern "C" {
} }
/* Insert s as second element in the list */ /* Insert s as second element in the list */
s->next = ty->next; s->next = ty->next;
if (ty->next) if (ty->next) ty->next->prev = s;
ty->next->prev = s;
ty->next = s; ty->next = s;
s->prev = ty; s->prev = ty;
return s; return s;
@ -567,7 +567,8 @@ extern "C" {
sv_setsv(sv, self); sv_setsv(sv, self);
SvREFCNT_dec((SV *)self); SvREFCNT_dec((SV *)self);
sv_bless(sv, stash); sv_bless(sv, stash);
} else { }
else {
sv_setref_pv(sv, (char *) t->name, ptr); sv_setref_pv(sv, (char *) t->name, ptr);
} }
} }
@ -583,8 +584,7 @@ extern "C" {
SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) { SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) {
char result[1024]; char result[1024];
char *r = result; char *r = result;
if ((2 * sz + 1 + strlen(type->name)) > 1000) if ((2*sz + 1 + strlen(type->name)) > 1000) return;
return;
*(r++) = '_'; *(r++) = '_';
r = SWIG_PackData(r,ptr,sz); r = SWIG_PackData(r,ptr,sz);
strcpy(r,type->name); strcpy(r,type->name);
@ -597,32 +597,27 @@ extern "C" {
swig_type_info *tc; swig_type_info *tc;
char *c = 0; char *c = 0;
if ((!obj) || (!SvOK(obj))) if ((!obj) || (!SvOK(obj))) return -1;
return -1;
c = SvPV(obj, PL_na); c = SvPV(obj, PL_na);
/* Pointer values must start with leading underscore */ /* Pointer values must start with leading underscore */
if (*c != '_') if (*c != '_') return -1;
return -1;
c++; c++;
c = SWIG_UnpackData(c,ptr,sz); c = SWIG_UnpackData(c,ptr,sz);
if (ty) { if (ty) {
tc = SWIG_TypeCheck(c,ty); tc = SWIG_TypeCheck(c,ty);
if (!tc) if (!tc) return -1;
return -1;
} }
return 0; return 0;
} }
SWIGRUNTIME(void) SWIGRUNTIME(void)
SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) { SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) {
if (error) if (error) sv_setpv(perl_get_sv("@", TRUE), error);
sv_setpv(perl_get_sv("@", TRUE), error);
} }
SWIGRUNTIME(void) SWIGRUNTIME(void)
SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) { SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) {
if (error) if (error) sv_setsv(perl_get_sv("@", TRUE), error);
sv_setsv(perl_get_sv("@", TRUE), error);
} }
SWIGRUNTIME(void) SWIGRUNTIME(void)
@ -686,16 +681,13 @@ typedef struct {
#ifndef PERL_OBJECT #ifndef PERL_OBJECT
#define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c) #define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c)
#ifndef MULTIPLICITY #ifndef MULTIPLICITY
static void _swig_create_magic(SV * sv, char *name, int (*set) (SV *, MAGIC *), int (*get) (SV *, MAGIC *)) static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) {
{
#else #else
static void _swig_create_magic(SV * sv, char *name, int (*set) (struct interpreter *, SV *, MAGIC *), int (*get) (struct interpreter *, SV *, MAGIC *)) static void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) {
{
#endif #endif
#else #else
# define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c) # define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c)
static void _swig_create_magic(CPerlObj * pPerl, SV * sv, const char *name, int (CPerlObj::*set) (SV *, MAGIC *), int (CPerlObj::*get) (SV *, MAGIC *)) static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) {
{
#endif #endif
MAGIC *mg; MAGIC *mg;
sv_magic(sv,sv,'U',(char *) name,strlen(name)); sv_magic(sv,sv,'U',(char *) name,strlen(name));
@ -776,7 +768,7 @@ static void _swig_create_magic(CPerlObj * pPerl, SV * sv, const char *name, int
#define SWIGTYPE_p_switch_core_session_t swig_types[2] #define SWIGTYPE_p_switch_core_session_t swig_types[2]
#define SWIGTYPE_p_p_switch_core_session_t swig_types[3] #define SWIGTYPE_p_p_switch_core_session_t swig_types[3]
#define SWIGTYPE_p_uint32_t swig_types[4] #define SWIGTYPE_p_uint32_t swig_types[4]
#define SWIGTYPE_p_switch_input_callback_function_t swig_types[5] #define SWIGTYPE_p_switch_input_args_t swig_types[5]
static swig_type_info *swig_types[7]; static swig_type_info *swig_types[7];
/* -------- TYPES TABLE (END) -------- */ /* -------- TYPES TABLE (END) -------- */
@ -814,12 +806,11 @@ SWIGEXPORT(void) SWIG_init(CV * cv, CPerlObj *);
extern void fs_channel_set_variable(switch_core_session_t *,char *,char *); extern void fs_channel_set_variable(switch_core_session_t *,char *,char *);
extern void fs_channel_get_variable(switch_core_session_t *,char *); extern void fs_channel_get_variable(switch_core_session_t *,char *);
extern void fs_channel_set_state(switch_core_session_t *,char *); extern void fs_channel_set_state(switch_core_session_t *,char *);
extern int fs_ivr_play_file(switch_core_session_t *, char *); extern int fs_ivr_play_file(switch_core_session_t *,switch_file_handle_t *,char *,switch_input_args_t *);
extern int fs_switch_ivr_record_file(switch_core_session_t *, switch_file_handle_t *, char *, extern int fs_switch_ivr_record_file(switch_core_session_t *,switch_file_handle_t *,char *,switch_input_args_t *,unsigned int);
switch_input_callback_function_t, void *, unsigned int, unsigned int);
extern int fs_switch_ivr_sleep(switch_core_session_t *,uint32_t); extern int fs_switch_ivr_sleep(switch_core_session_t *,uint32_t);
extern int fs_ivr_play_file2(switch_core_session_t *,char *); extern int fs_ivr_play_file2(switch_core_session_t *,char *);
extern int fs_switch_ivr_collect_digits_callback(switch_core_session_t *, switch_input_callback_function_t, void *, unsigned int, unsigned int); extern int fs_switch_ivr_collect_digits_callback(switch_core_session_t *,switch_input_args_t *,unsigned int);
extern int fs_switch_ivr_collect_digits_count(switch_core_session_t *,char *,unsigned int,unsigned int,char const *,char *,unsigned int); extern int fs_switch_ivr_collect_digits_count(switch_core_session_t *,char *,unsigned int,unsigned int,char const *,char *,unsigned int);
extern int fs_switch_ivr_originate(switch_core_session_t *,switch_core_session_t **,char *,uint32_t); extern int fs_switch_ivr_originate(switch_core_session_t *,switch_core_session_t **,char *,uint32_t);
extern int fs_switch_ivr_session_transfer(switch_core_session_t *,char *,char *,char *); extern int fs_switch_ivr_session_transfer(switch_core_session_t *,char *,char *,char *);
@ -827,7 +818,7 @@ SWIGEXPORT(void) SWIG_init(CV * cv, CPerlObj *);
extern char *fs_switch_channel_get_variable(switch_channel_t *,char *); extern char *fs_switch_channel_get_variable(switch_channel_t *,char *);
extern int fs_switch_channel_set_variable(switch_channel_t *,char *,char *); extern int fs_switch_channel_set_variable(switch_channel_t *,char *,char *);
#include "switch.h"
#ifdef PERL_OBJECT #ifdef PERL_OBJECT
#define MAGIC_CLASS _wrap_fs_perl_var:: #define MAGIC_CLASS _wrap_fs_perl_var::
@ -836,10 +827,9 @@ SWIGEXPORT(void) SWIG_init(CV * cv, CPerlObj *);
#else #else
#define MAGIC_CLASS #define MAGIC_CLASS
#endif #endif
SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV * sv, MAGIC * mg) SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *sv, MAGIC *mg) {
{ MAGIC_PPERL
MAGIC_PPERL sv = sv; sv = sv; mg = mg;
mg = mg;
croak("Value is read-only."); croak("Value is read-only.");
return 0; return 0;
} }
@ -881,10 +871,8 @@ extern "C" {
if ((items < 1) || (items > 1)) { if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: fs_core_init(path);"); SWIG_croak("Usage: fs_core_init(path);");
} }
if (!SvOK((SV *) ST(0))) if (!SvOK((SV*) ST(0))) arg1 = 0;
arg1 = 0; else arg1 = (char *) SvPV(ST(0), PL_na);
else
arg1 = (char *) SvPV(ST(0), PL_na);
result = (int)fs_core_init(arg1); result = (int)fs_core_init(arg1);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -991,14 +979,10 @@ extern "C" {
if ((items < 2) || (items > 2)) { if ((items < 2) || (items > 2)) {
SWIG_croak("Usage: fs_consol_log(level_str,msg);"); SWIG_croak("Usage: fs_consol_log(level_str,msg);");
} }
if (!SvOK((SV *) ST(0))) if (!SvOK((SV*) ST(0))) arg1 = 0;
arg1 = 0; else arg1 = (char *) SvPV(ST(0), PL_na);
else if (!SvOK((SV*) ST(1))) arg2 = 0;
arg1 = (char *) SvPV(ST(0), PL_na); else arg2 = (char *) SvPV(ST(1), PL_na);
if (!SvOK((SV *) ST(1)))
arg2 = 0;
else
arg2 = (char *) SvPV(ST(1), PL_na);
fs_consol_log(arg1,arg2); fs_consol_log(arg1,arg2);
@ -1019,10 +1003,8 @@ extern "C" {
if ((items < 1) || (items > 1)) { if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: fs_consol_clean(msg);"); SWIG_croak("Usage: fs_consol_clean(msg);");
} }
if (!SvOK((SV *) ST(0))) if (!SvOK((SV*) ST(0))) arg1 = 0;
arg1 = 0; else arg1 = (char *) SvPV(ST(0), PL_na);
else
arg1 = (char *) SvPV(ST(0), PL_na);
fs_consol_clean(arg1); fs_consol_clean(arg1);
@ -1044,10 +1026,8 @@ extern "C" {
if ((items < 1) || (items > 1)) { if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: fs_core_session_locate(uuid);"); SWIG_croak("Usage: fs_core_session_locate(uuid);");
} }
if (!SvOK((SV *) ST(0))) if (!SvOK((SV*) ST(0))) arg1 = 0;
arg1 = 0; else arg1 = (char *) SvPV(ST(0), PL_na);
else
arg1 = (char *) SvPV(ST(0), PL_na);
result = (switch_core_session_t *)fs_core_session_locate(arg1); result = (switch_core_session_t *)fs_core_session_locate(arg1);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -1125,10 +1105,8 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_channel_hangup. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_channel_hangup. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else
arg2 = (char *) SvPV(ST(1), PL_na);
fs_channel_hangup(arg1,arg2); fs_channel_hangup(arg1,arg2);
@ -1156,14 +1134,10 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_channel_set_variable. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_channel_set_variable. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else if (!SvOK((SV*) ST(2))) arg3 = 0;
arg2 = (char *) SvPV(ST(1), PL_na); else arg3 = (char *) SvPV(ST(2), PL_na);
if (!SvOK((SV *) ST(2)))
arg3 = 0;
else
arg3 = (char *) SvPV(ST(2), PL_na);
fs_channel_set_variable(arg1,arg2,arg3); fs_channel_set_variable(arg1,arg2,arg3);
@ -1190,10 +1164,8 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_channel_get_variable. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_channel_get_variable. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else
arg2 = (char *) SvPV(ST(1), PL_na);
fs_channel_get_variable(arg1,arg2); fs_channel_get_variable(arg1,arg2);
@ -1220,10 +1192,8 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_channel_set_state. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_channel_set_state. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else
arg2 = (char *) SvPV(ST(1), PL_na);
fs_channel_set_state(arg1,arg2); fs_channel_set_state(arg1,arg2);
@ -1238,24 +1208,34 @@ extern "C" {
XS(_wrap_fs_ivr_play_file) { XS(_wrap_fs_ivr_play_file) {
{ {
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
char *arg2; switch_file_handle_t *arg2 = (switch_file_handle_t *) 0 ;
char *arg3 ;
switch_input_args_t *arg4 = (switch_input_args_t *) 0 ;
int result; int result;
int argvi = 0; int argvi = 0;
dXSARGS; dXSARGS;
if ((items < 2) || (items > 2)) { if ((items < 4) || (items > 4)) {
SWIG_croak("Usage: fs_ivr_play_file(session,file);"); SWIG_croak("Usage: fs_ivr_play_file(session,fh,file,args);");
} }
{ {
if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) { if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
SWIG_croak("Type error in argument 1 of fs_ivr_play_file. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_ivr_play_file. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) {
arg2 = 0; if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_switch_file_handle_t,0) < 0) {
else SWIG_croak("Type error in argument 2 of fs_ivr_play_file. Expected _p_switch_file_handle_t");
arg2 = (char *) SvPV(ST(1), PL_na); }
result = (int) fs_ivr_play_file(arg1, arg2); }
if (!SvOK((SV*) ST(2))) arg3 = 0;
else arg3 = (char *) SvPV(ST(2), PL_na);
{
if (SWIG_ConvertPtr(ST(3), (void **) &arg4, SWIGTYPE_p_switch_input_args_t,0) < 0) {
SWIG_croak("Type error in argument 4 of fs_ivr_play_file. Expected _p_switch_input_args_t");
}
}
result = (int)fs_ivr_play_file(arg1,arg2,arg3,arg4);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
sv_setiv(ST(argvi++), (IV) result); sv_setiv(ST(argvi++), (IV) result);
@ -1272,16 +1252,14 @@ extern "C" {
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
switch_file_handle_t *arg2 = (switch_file_handle_t *) 0 ; switch_file_handle_t *arg2 = (switch_file_handle_t *) 0 ;
char *arg3 ; char *arg3 ;
switch_input_callback_function_t arg4; switch_input_args_t *arg4 = (switch_input_args_t *) 0 ;
void *arg5 = (void *) 0; unsigned int arg5 ;
unsigned int arg6;
unsigned int arg7;
int result; int result;
int argvi = 0; int argvi = 0;
dXSARGS; dXSARGS;
if ((items < 7) || (items > 7)) { if ((items < 5) || (items > 5)) {
SWIG_croak("Usage: fs_switch_ivr_record_file(session,fh,file,dtmf_callback,buf,buflen,limit);"); SWIG_croak("Usage: fs_switch_ivr_record_file(session,fh,file,args,limit);");
} }
{ {
if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) { if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
@ -1293,25 +1271,15 @@ extern "C" {
SWIG_croak("Type error in argument 2 of fs_switch_ivr_record_file. Expected _p_switch_file_handle_t"); SWIG_croak("Type error in argument 2 of fs_switch_ivr_record_file. Expected _p_switch_file_handle_t");
} }
} }
if (!SvOK((SV *) ST(2))) if (!SvOK((SV*) ST(2))) arg3 = 0;
arg3 = 0; else arg3 = (char *) SvPV(ST(2), PL_na);
else
arg3 = (char *) SvPV(ST(2), PL_na);
{ {
switch_input_callback_function_t *argp; if (SWIG_ConvertPtr(ST(3), (void **) &arg4, SWIGTYPE_p_switch_input_args_t,0) < 0) {
if (SWIG_ConvertPtr(ST(3), (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, 0) < 0) { SWIG_croak("Type error in argument 4 of fs_switch_ivr_record_file. Expected _p_switch_input_args_t");
SWIG_croak("Type error in argument 4 of fs_switch_ivr_record_file. Expected _p_switch_input_callback_function_t");
}
arg4 = *argp;
}
{
if (SWIG_ConvertPtr(ST(4), (void **) &arg5, 0, 0) < 0) {
SWIG_croak("Type error in argument 5 of fs_switch_ivr_record_file. Expected _p_void");
} }
} }
arg6 = (unsigned int) SvUV(ST(5)); arg5 = (unsigned int) SvUV(ST(4));
arg7 = (unsigned int) SvUV(ST(6)); result = (int)fs_switch_ivr_record_file(arg1,arg2,arg3,arg4,arg5);
result = (int) fs_switch_ivr_record_file(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
sv_setiv(ST(argvi++), (IV) result); sv_setiv(ST(argvi++), (IV) result);
@ -1374,10 +1342,8 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_ivr_play_file2. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_ivr_play_file2. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else
arg2 = (char *) SvPV(ST(1), PL_na);
result = (int)fs_ivr_play_file2(arg1,arg2); result = (int)fs_ivr_play_file2(arg1,arg2);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -1393,16 +1359,14 @@ extern "C" {
XS(_wrap_fs_switch_ivr_collect_digits_callback) { XS(_wrap_fs_switch_ivr_collect_digits_callback) {
{ {
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
switch_input_callback_function_t arg2; switch_input_args_t *arg2 = (switch_input_args_t *) 0 ;
void *arg3 = (void *) 0; unsigned int arg3 ;
unsigned int arg4;
unsigned int arg5;
int result; int result;
int argvi = 0; int argvi = 0;
dXSARGS; dXSARGS;
if ((items < 5) || (items > 5)) { if ((items < 3) || (items > 3)) {
SWIG_croak("Usage: fs_switch_ivr_collect_digits_callback(session,dtmf_callback,buf,buflen,timeout);"); SWIG_croak("Usage: fs_switch_ivr_collect_digits_callback(session,args,timeout);");
} }
{ {
if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) { if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
@ -1410,20 +1374,12 @@ extern "C" {
} }
} }
{ {
switch_input_callback_function_t *argp; if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_switch_input_args_t,0) < 0) {
if (SWIG_ConvertPtr(ST(1), (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, 0) < 0) { SWIG_croak("Type error in argument 2 of fs_switch_ivr_collect_digits_callback. Expected _p_switch_input_args_t");
SWIG_croak("Type error in argument 2 of fs_switch_ivr_collect_digits_callback. Expected _p_switch_input_callback_function_t");
}
arg2 = *argp;
}
{
if (SWIG_ConvertPtr(ST(2), (void **) &arg3, 0, 0) < 0) {
SWIG_croak("Type error in argument 3 of fs_switch_ivr_collect_digits_callback. Expected _p_void");
} }
} }
arg4 = (unsigned int) SvUV(ST(3)); arg3 = (unsigned int) SvUV(ST(2));
arg5 = (unsigned int) SvUV(ST(4)); result = (int)fs_switch_ivr_collect_digits_callback(arg1,arg2,arg3);
result = (int) fs_switch_ivr_collect_digits_callback(arg1, arg2, arg3, arg4, arg5);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
sv_setiv(ST(argvi++), (IV) result); sv_setiv(ST(argvi++), (IV) result);
@ -1456,20 +1412,14 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_switch_ivr_collect_digits_count. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_switch_ivr_collect_digits_count. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else
arg2 = (char *) SvPV(ST(1), PL_na);
arg3 = (unsigned int) SvUV(ST(2)); arg3 = (unsigned int) SvUV(ST(2));
arg4 = (unsigned int) SvUV(ST(3)); arg4 = (unsigned int) SvUV(ST(3));
if (!SvOK((SV *) ST(4))) if (!SvOK((SV*) ST(4))) arg5 = 0;
arg5 = 0; else arg5 = (char *) SvPV(ST(4), PL_na);
else if (!SvOK((SV*) ST(5))) arg6 = 0;
arg5 = (char *) SvPV(ST(4), PL_na); else arg6 = (char *) SvPV(ST(5), PL_na);
if (!SvOK((SV *) ST(5)))
arg6 = 0;
else
arg6 = (char *) SvPV(ST(5), PL_na);
arg7 = (unsigned int) SvUV(ST(6)); arg7 = (unsigned int) SvUV(ST(6));
result = (int)fs_switch_ivr_collect_digits_count(arg1,arg2,arg3,arg4,(char const *)arg5,arg6,arg7); result = (int)fs_switch_ivr_collect_digits_count(arg1,arg2,arg3,arg4,(char const *)arg5,arg6,arg7);
@ -1506,10 +1456,8 @@ extern "C" {
SWIG_croak("Type error in argument 2 of fs_switch_ivr_originate. Expected _p_p_switch_core_session_t"); SWIG_croak("Type error in argument 2 of fs_switch_ivr_originate. Expected _p_p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(2))) if (!SvOK((SV*) ST(2))) arg3 = 0;
arg3 = 0; else arg3 = (char *) SvPV(ST(2), PL_na);
else
arg3 = (char *) SvPV(ST(2), PL_na);
{ {
uint32_t * argp; uint32_t * argp;
if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) { if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) {
@ -1547,18 +1495,12 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_switch_ivr_session_transfer. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_switch_ivr_session_transfer. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else if (!SvOK((SV*) ST(2))) arg3 = 0;
arg2 = (char *) SvPV(ST(1), PL_na); else arg3 = (char *) SvPV(ST(2), PL_na);
if (!SvOK((SV *) ST(2))) if (!SvOK((SV*) ST(3))) arg4 = 0;
arg3 = 0; else arg4 = (char *) SvPV(ST(3), PL_na);
else
arg3 = (char *) SvPV(ST(2), PL_na);
if (!SvOK((SV *) ST(3)))
arg4 = 0;
else
arg4 = (char *) SvPV(ST(3), PL_na);
result = (int)fs_switch_ivr_session_transfer(arg1,arg2,arg3,arg4); result = (int)fs_switch_ivr_session_transfer(arg1,arg2,arg3,arg4);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -1590,14 +1532,10 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_switch_ivr_speak_text. Expected _p_switch_core_session_t"); SWIG_croak("Type error in argument 1 of fs_switch_ivr_speak_text. Expected _p_switch_core_session_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else if (!SvOK((SV*) ST(2))) arg3 = 0;
arg2 = (char *) SvPV(ST(1), PL_na); else arg3 = (char *) SvPV(ST(2), PL_na);
if (!SvOK((SV *) ST(2)))
arg3 = 0;
else
arg3 = (char *) SvPV(ST(2), PL_na);
{ {
uint32_t * argp; uint32_t * argp;
if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) { if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) {
@ -1605,10 +1543,8 @@ extern "C" {
} }
arg4 = *argp; arg4 = *argp;
} }
if (!SvOK((SV *) ST(4))) if (!SvOK((SV*) ST(4))) arg5 = 0;
arg5 = 0; else arg5 = (char *) SvPV(ST(4), PL_na);
else
arg5 = (char *) SvPV(ST(4), PL_na);
result = (int)fs_switch_ivr_speak_text(arg1,arg2,arg3,arg4,arg5); result = (int)fs_switch_ivr_speak_text(arg1,arg2,arg3,arg4,arg5);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -1637,10 +1573,8 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_switch_channel_get_variable. Expected _p_switch_channel_t"); SWIG_croak("Type error in argument 1 of fs_switch_channel_get_variable. Expected _p_switch_channel_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else
arg2 = (char *) SvPV(ST(1), PL_na);
result = (char *)fs_switch_channel_get_variable(arg1,arg2); result = (char *)fs_switch_channel_get_variable(arg1,arg2);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -1674,14 +1608,10 @@ extern "C" {
SWIG_croak("Type error in argument 1 of fs_switch_channel_set_variable. Expected _p_switch_channel_t"); SWIG_croak("Type error in argument 1 of fs_switch_channel_set_variable. Expected _p_switch_channel_t");
} }
} }
if (!SvOK((SV *) ST(1))) if (!SvOK((SV*) ST(1))) arg2 = 0;
arg2 = 0; else arg2 = (char *) SvPV(ST(1), PL_na);
else if (!SvOK((SV*) ST(2))) arg3 = 0;
arg2 = (char *) SvPV(ST(1), PL_na); else arg3 = (char *) SvPV(ST(2), PL_na);
if (!SvOK((SV *) ST(2)))
arg3 = 0;
else
arg3 = (char *) SvPV(ST(2), PL_na);
result = (int)fs_switch_channel_set_variable(arg1,arg2,arg3); result = (int)fs_switch_channel_set_variable(arg1,arg2,arg3);
ST(argvi) = sv_newmortal(); ST(argvi) = sv_newmortal();
@ -1698,17 +1628,11 @@ extern "C" {
/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
static swig_type_info _swigt__p_switch_channel_t[] = {{"_p_switch_channel_t", 0, "switch_channel_t *", 0},{"_p_switch_channel_t"},{0}}; static swig_type_info _swigt__p_switch_channel_t[] = {{"_p_switch_channel_t", 0, "switch_channel_t *", 0},{"_p_switch_channel_t"},{0}};
static swig_type_info _swigt__p_switch_file_handle_t[] = static swig_type_info _swigt__p_switch_file_handle_t[] = {{"_p_switch_file_handle_t", 0, "switch_file_handle_t *", 0},{"_p_switch_file_handle_t"},{0}};
{ {"_p_switch_file_handle_t", 0, "switch_file_handle_t *", 0}, {"_p_switch_file_handle_t"}, {0} }; static swig_type_info _swigt__p_switch_core_session_t[] = {{"_p_switch_core_session_t", 0, "switch_core_session_t *", 0},{"_p_switch_core_session_t"},{0}};
static swig_type_info _swigt__p_switch_core_session_t[] = static swig_type_info _swigt__p_p_switch_core_session_t[] = {{"_p_p_switch_core_session_t", 0, "switch_core_session_t **", 0},{"_p_p_switch_core_session_t"},{0}};
{ {"_p_switch_core_session_t", 0, "switch_core_session_t *", 0}, {"_p_switch_core_session_t"}, {0} };
static swig_type_info _swigt__p_p_switch_core_session_t[] =
{ {"_p_p_switch_core_session_t", 0, "switch_core_session_t **", 0}, {"_p_p_switch_core_session_t"}, {0} };
static swig_type_info _swigt__p_uint32_t[] = {{"_p_uint32_t", 0, "uint32_t *", 0},{"_p_uint32_t"},{0}}; static swig_type_info _swigt__p_uint32_t[] = {{"_p_uint32_t", 0, "uint32_t *", 0},{"_p_uint32_t"},{0}};
static swig_type_info _swigt__p_switch_input_callback_function_t[] = static swig_type_info _swigt__p_switch_input_args_t[] = {{"_p_switch_input_args_t", 0, "switch_input_args_t *", 0},{"_p_switch_input_args_t"},{0}};
{ {"_p_switch_input_callback_function_t", 0, "switch_input_callback_function_t *", 0},
{"_p_switch_input_callback_function_t"}, {0}
};
static swig_type_info *swig_types_initial[] = { static swig_type_info *swig_types_initial[] = {
_swigt__p_switch_channel_t, _swigt__p_switch_channel_t,
@ -1716,7 +1640,7 @@ extern "C" {
_swigt__p_switch_core_session_t, _swigt__p_switch_core_session_t,
_swigt__p_p_switch_core_session_t, _swigt__p_p_switch_core_session_t,
_swigt__p_uint32_t, _swigt__p_uint32_t,
_swigt__p_switch_input_callback_function_t, _swigt__p_switch_input_args_t,
0 0
}; };
@ -1724,6 +1648,10 @@ extern "C" {
/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
static swig_constant_info swig_constants[] = { static swig_constant_info swig_constants[] = {
{ SWIG_STRING, (char *) SWIG_prefix "FREESWITCH_PEN", 0, 0, (void *)"27880", 0},
{ SWIG_STRING, (char *) SWIG_prefix "FREESWITCH_OID_PREFIX", 0, 0, (void *)".1.3.6.1.4.1.27880", 0},
{ SWIG_STRING, (char *) SWIG_prefix "FREESWITCH_ITAD", 0, 0, (void *)"543", 0},
{ SWIG_INT, (char *) SWIG_prefix "__EXTENSIONS__", (long) 1, 0, 0, 0},
{0} {0}
}; };
#ifdef __cplusplus #ifdef __cplusplus
@ -1765,8 +1693,8 @@ static swig_command_info swig_commands[] = {
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
#endif #endif
XS(SWIG_init)
{ XS(SWIG_init) {
dXSARGS; dXSARGS;
int i; int i;
static int _init = 0; static int _init = 0;
@ -1823,3 +1751,4 @@ XS(SWIG_init)
ST(0) = &PL_sv_yes; ST(0) = &PL_sv_yes;
XSRETURN(1); XSRETURN(1);
} }

View File

@ -81,7 +81,8 @@ typedef struct sm_loadable_module sm_loadable_module_t;
typedef enum { typedef enum {
S_HUP = (1 << 0), S_HUP = (1 << 0),
S_FREE = (1 << 1) S_FREE = (1 << 1),
S_RDLOCK = (1 << 2)
} session_flag_t; } session_flag_t;
struct input_callback_state { struct input_callback_state {
@ -2146,7 +2147,7 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
} }
jss->session = peer_session; jss->session = peer_session;
jss->flags = 0; jss->flags = S_RDLOCK;
*rval = BOOLEAN_TO_JSVAL(JS_TRUE); *rval = BOOLEAN_TO_JSVAL(JS_TRUE);
@ -2177,6 +2178,10 @@ static void session_destroy(JSContext * cx, JSObject * obj)
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
} }
if (jss->session && switch_test_flag(jss, S_RDLOCK)) {
switch_core_session_rwunlock(jss->session);
}
if (switch_test_flag(jss, S_FREE)) { if (switch_test_flag(jss, S_FREE)) {
free(jss); free(jss);
} }

View File

@ -745,12 +745,12 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", "%s", switch_channel_get_name(channel)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", "%s", switch_channel_get_name(channel));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", "%s", switch_core_session_get_uuid(channel->session)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", "%s", switch_core_session_get_uuid(channel->session));
if ((codec = switch_core_session_get_read_codec(channel->session))) { if ((codec = switch_core_session_get_read_codec(channel->session)) && codec->implementation) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", "%s", switch_str_nil(codec->implementation->iananame)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", "%s", switch_str_nil(codec->implementation->iananame));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", codec->implementation->samples_per_second); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", codec->implementation->samples_per_second);
} }
if ((codec = switch_core_session_get_write_codec(channel->session))) { if ((codec = switch_core_session_get_write_codec(channel->session)) && codec->implementation) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", "%s", switch_str_nil(codec->implementation->iananame)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", "%s", switch_str_nil(codec->implementation->iananame));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", codec->implementation->samples_per_second); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", codec->implementation->samples_per_second);
} }

View File

@ -34,16 +34,20 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers;
/* Bridge Related Stuff*/ /* Bridge Related Stuff*/
/*********************************************************************************/ /*********************************************************************************/
struct audio_bridge_data { struct switch_ivr_bridge_data {
switch_core_session_t *session_a; switch_core_session_t *session;
switch_core_session_t *session_b; char *b_uuid;
int running; int stream_id;
switch_input_callback_function_t input_callback;
void *session_data;
}; };
typedef struct switch_ivr_bridge_data switch_ivr_bridge_data_t;
static void *audio_bridge_thread(switch_thread_t * thread, void *obj) static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
{ {
switch_core_thread_session_t *his_thread, *data = obj; switch_ivr_bridge_data_t *data = obj;
int *stream_id_p;
int stream_id = 0, pre_b = 0, ans_a = 0, ans_b = 0, originator = 0; int stream_id = 0, pre_b = 0, ans_a = 0, ans_b = 0, originator = 0;
switch_input_callback_function_t input_callback; switch_input_callback_function_t input_callback;
switch_core_session_message_t *message, msg = { 0 }; switch_core_session_message_t *message, msg = { 0 };
@ -53,20 +57,15 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
switch_frame_t *read_frame; switch_frame_t *read_frame;
switch_core_session_t *session_a, *session_b; switch_core_session_t *session_a, *session_b;
assert(!thread || thread); session_a = data->session;
if (!(session_b = switch_core_session_locate(data->b_uuid))) {
session_a = data->objs[0]; return NULL;
session_b = data->objs[1];
stream_id_p = data->objs[2];
input_callback = data->input_callback;
user_data = data->objs[4];
his_thread = data->objs[5];
if (stream_id_p) {
stream_id = *stream_id_p;
} }
input_callback = data->input_callback;
user_data = data->session_data;
stream_id = data->stream_id;
chan_a = switch_core_session_get_channel(session_a); chan_a = switch_core_session_get_channel(session_a);
chan_b = switch_core_session_get_channel(session_b); chan_b = switch_core_session_get_channel(session_b);
@ -75,8 +74,6 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
pre_b = switch_channel_test_flag(chan_a, CF_EARLY_MEDIA); pre_b = switch_channel_test_flag(chan_a, CF_EARLY_MEDIA);
ans_b = switch_channel_test_flag(chan_b, CF_ANSWERED); ans_b = switch_channel_test_flag(chan_b, CF_ANSWERED);
} }
switch_core_session_read_lock(session_a);
switch_core_session_read_lock(session_b);
switch_channel_set_flag(chan_a, CF_BRIDGED); switch_channel_set_flag(chan_a, CF_BRIDGED);
@ -85,10 +82,6 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
switch_status_t status; switch_status_t status;
switch_event_t *event; switch_event_t *event;
if (!(data->running > 0 && his_thread->running > 0)) {
break;
}
/* if you really want to make sure it's not ready, test it twice because it might be just a break */ /* if you really want to make sure it's not ready, test it twice because it might be just a break */
if (!switch_channel_ready(chan_a) && !switch_channel_ready(chan_a)) { if (!switch_channel_ready(chan_a) && !switch_channel_ready(chan_a)) {
break; break;
@ -99,10 +92,6 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
switch (b_state) { switch (b_state) {
case CS_HANGUP: case CS_HANGUP:
case CS_DONE: case CS_DONE:
switch_mutex_lock(data->mutex);
data->running = -1;
switch_mutex_unlock(data->mutex);
continue;
default: default:
break; break;
} }
@ -129,9 +118,6 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
if (input_callback) { if (input_callback) {
if (input_callback(session_a, dtmf, SWITCH_INPUT_TYPE_DTMF, user_data, 0) != SWITCH_STATUS_SUCCESS) { if (input_callback(session_a, dtmf, SWITCH_INPUT_TYPE_DTMF, user_data, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s ended call via DTMF\n", switch_channel_get_name(chan_a)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s ended call via DTMF\n", switch_channel_get_name(chan_a));
switch_mutex_lock(data->mutex);
data->running = -1;
switch_mutex_unlock(data->mutex);
break; break;
} }
} }
@ -186,49 +172,40 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) { if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write: %s Bad Frame....[%u] Bubye!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write: %s Bad Frame....[%u] Bubye!\n",
switch_channel_get_name(chan_b), read_frame->datalen); switch_channel_get_name(chan_b), read_frame->datalen);
switch_mutex_lock(data->mutex); break;
data->running = -1;
switch_mutex_unlock(data->mutex);
} }
} }
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "read: %s Bad Frame.... Bubye!\n", switch_channel_get_name(chan_a)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "read: %s Bad Frame.... Bubye!\n", switch_channel_get_name(chan_a));
switch_mutex_lock(data->mutex); break;
data->running = -1;
switch_mutex_unlock(data->mutex);
} }
} }
switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK); switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK);
msg.string_arg = data->b_uuid;
msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
msg.from = __FILE__; msg.from = __FILE__;
switch_core_session_receive_message(session_a, &msg); switch_core_session_receive_message(session_a, &msg);
switch_channel_set_variable(chan_a, SWITCH_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(chan_a, SWITCH_BRIDGE_VARIABLE, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "BRIDGE THREAD DONE [%s]\n", switch_channel_get_name(chan_a)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "BRIDGE THREAD DONE [%s]\n", switch_channel_get_name(chan_a));
switch_channel_clear_flag(chan_a, CF_BRIDGED); switch_channel_clear_flag(chan_a, CF_BRIDGED);
switch_mutex_lock(data->mutex);
data->running = 0;
switch_mutex_unlock(data->mutex);
switch_core_session_rwunlock(session_a);
switch_core_session_rwunlock(session_b); switch_core_session_rwunlock(session_b);
return NULL; return NULL;
} }
static switch_status_t audio_bridge_on_loopback(switch_core_session_t *session) static switch_status_t audio_bridge_on_loopback(switch_core_session_t *session)
{ {
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
void *arg; switch_ivr_bridge_data_t *bd;
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
assert(channel != NULL); assert(channel != NULL);
if ((arg = switch_channel_get_private(channel, "_bridge_"))) { if ((bd = (switch_ivr_bridge_data_t *) switch_channel_get_private(channel, "_bridge_"))) {
switch_channel_set_private(channel, "_bridge_", NULL); switch_channel_set_private(channel, "_bridge_", NULL);
audio_bridge_thread(NULL, (void *) arg); audio_bridge_thread(NULL, (void *) bd);
} else { } else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
} }
@ -516,13 +493,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session,
switch_core_session_t *peer_session, switch_core_session_t *peer_session,
switch_input_callback_function_t input_callback, void *session_data, switch_input_callback_function_t input_callback, void *session_data,
void *peer_session_data) void *peer_session_data)
{ {
switch_core_thread_session_t *this_audio_thread, *other_audio_thread; switch_ivr_bridge_data_t *a_leg, *b_leg;
switch_channel_t *caller_channel, *peer_channel; switch_channel_t *caller_channel, *peer_channel;
int stream_id = 0; int stream_id = 0;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
@ -535,26 +511,20 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
peer_channel = switch_core_session_get_channel(peer_session); peer_channel = switch_core_session_get_channel(peer_session);
assert(peer_channel != NULL); assert(peer_channel != NULL);
other_audio_thread = switch_core_session_alloc(peer_session, sizeof(switch_core_thread_session_t)); a_leg = switch_core_session_alloc(session, sizeof(*a_leg));
this_audio_thread = switch_core_session_alloc(peer_session, sizeof(switch_core_thread_session_t)); b_leg = switch_core_session_alloc(peer_session, sizeof(*b_leg));
other_audio_thread->objs[0] = session; b_leg->session = peer_session;
other_audio_thread->objs[1] = peer_session; b_leg->b_uuid = switch_core_session_strdup(peer_session, switch_core_session_get_uuid(session));
other_audio_thread->objs[2] = &stream_id; b_leg->stream_id = stream_id;
other_audio_thread->input_callback = input_callback; b_leg->input_callback = input_callback;
other_audio_thread->objs[4] = session_data; b_leg->session_data = session_data;
other_audio_thread->objs[5] = this_audio_thread;
other_audio_thread->running = 5;
switch_mutex_init(&other_audio_thread->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
this_audio_thread->objs[0] = peer_session; a_leg->session = session;
this_audio_thread->objs[1] = session; a_leg->b_uuid = switch_core_session_strdup(session, switch_core_session_get_uuid(peer_session));
this_audio_thread->objs[2] = &stream_id; b_leg->stream_id = stream_id;
this_audio_thread->input_callback = input_callback; b_leg->input_callback = input_callback;
this_audio_thread->objs[4] = peer_session_data; b_leg->session_data = peer_session_data;
this_audio_thread->objs[5] = other_audio_thread;
this_audio_thread->running = 2;
switch_mutex_init(&this_audio_thread->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(peer_session));
switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers); switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
@ -579,55 +549,35 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
msg.from = __FILE__; msg.from = __FILE__;
msg.pointer_arg = session; msg.string_arg = switch_core_session_strdup(peer_session, switch_core_session_get_uuid(session));
switch_core_session_receive_message(peer_session, &msg); if (switch_core_session_receive_message(peer_session, &msg) != SWITCH_STATUS_SUCCESS) {
if (!msg.pointer_arg) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
switch_core_session_rwunlock(peer_session); switch_core_session_rwunlock(peer_session);
goto done; goto done;
} }
msg.pointer_arg = peer_session; msg.string_arg = switch_core_session_strdup(session, switch_core_session_get_uuid(peer_session));
switch_core_session_receive_message(session, &msg); if (switch_core_session_receive_message(session, &msg) != SWITCH_STATUS_SUCCESS) {
if (!msg.pointer_arg) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
switch_core_session_rwunlock(peer_session); switch_core_session_rwunlock(peer_session);
goto done; goto done;
} }
switch_channel_set_private(peer_channel, "_bridge_", other_audio_thread); switch_channel_set_private(peer_channel, "_bridge_", b_leg);
switch_channel_set_state(peer_channel, CS_LOOPBACK); switch_channel_set_state(peer_channel, CS_LOOPBACK);
audio_bridge_thread(NULL, (void *) this_audio_thread); audio_bridge_thread(NULL, (void *) a_leg);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(caller_channel, event); switch_channel_event_set_data(caller_channel, event);
switch_event_fire(&event); switch_event_fire(&event);
} }
this_audio_thread->objs[0] = NULL;
this_audio_thread->objs[1] = NULL;
this_audio_thread->objs[2] = NULL;
this_audio_thread->input_callback = NULL;
this_audio_thread->objs[4] = NULL;
this_audio_thread->objs[5] = NULL;
switch_mutex_lock(this_audio_thread->mutex);
this_audio_thread->running = 0;
switch_mutex_unlock(this_audio_thread->mutex);
switch_channel_clear_flag(caller_channel, CF_ORIGINATOR); switch_channel_clear_flag(caller_channel, CF_ORIGINATOR);
while (switch_channel_get_state(peer_channel) == CS_LOOPBACK) {
if (other_audio_thread->running > 0) {
switch_mutex_lock(other_audio_thread->mutex);
other_audio_thread->running = -1;
switch_mutex_unlock(other_audio_thread->mutex);
while (other_audio_thread->running) {
switch_yield(1000); switch_yield(1000);
} }
}
switch_core_session_rwunlock(peer_session); switch_core_session_rwunlock(peer_session);

View File

@ -901,6 +901,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (!peer_channels[i]) { if (!peer_channels[i]) {
continue; continue;
} }
if (status == SWITCH_STATUS_SUCCESS && bleg && *bleg && *bleg == peer_sessions[i]) {
continue;
}
switch_core_session_rwunlock(peer_sessions[i]); switch_core_session_rwunlock(peer_sessions[i]);
} }
@ -912,5 +915,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
outer_for: outer_for:
switch_safe_free(loop_data); switch_safe_free(loop_data);
switch_safe_free(odata); switch_safe_free(odata);
if (bleg && status != SWITCH_STATUS_SUCCESS) {
*bleg = NULL;
}
return status; return status;
} }

View File

@ -246,6 +246,7 @@ int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_
return; return;
} else { } else {
switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
switch_core_session_rwunlock(peer_session);
} }