mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 05:02:10 +00:00
tear the hell out of everything and rip it up into itsy bitsy pieces and put it all back together
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5765 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -1360,6 +1360,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
if (!(tech_pvt = (struct private_object *) switch_core_session_alloc(nsession, sizeof(*tech_pvt)))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Creating Session\n");
|
||||
switch_core_session_destroy(&nsession);
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession));
|
||||
@@ -1375,6 +1376,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
||||
switch_core_session_destroy(&nsession);
|
||||
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -1384,6 +1386,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
||||
switch_core_session_destroy(&nsession);
|
||||
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -1393,6 +1396,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Gateway\n");
|
||||
switch_core_session_destroy(&nsession);
|
||||
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -1411,6 +1415,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
||||
switch_core_session_destroy(&nsession);
|
||||
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
*dest++ = '\0';
|
||||
@@ -1419,6 +1424,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
|
||||
switch_core_session_destroy(&nsession);
|
||||
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -1440,6 +1446,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, host);
|
||||
cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
|
||||
switch_core_session_destroy(&nsession);
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
} else if (!strchr(dest, '@')) {
|
||||
@@ -1452,6 +1459,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, profile_name);
|
||||
cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
|
||||
switch_core_session_destroy(&nsession);
|
||||
*pool = NULL;
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
@@ -1609,6 +1617,9 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
|
||||
|
||||
su_deinit();
|
||||
|
||||
switch_core_hash_destroy(&mod_sofia_globals.profile_hash);
|
||||
switch_core_hash_destroy(&mod_sofia_globals.gateway_hash);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@ typedef struct private_object private_object_t;
|
||||
struct sofia_private {
|
||||
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
||||
sofia_gateway_t *gateway;
|
||||
su_home_t *home;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -419,6 +419,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
|
||||
|
||||
|
||||
sofia_glue_del_profile(profile);
|
||||
switch_core_hash_destroy(&profile->chat_hash);
|
||||
|
||||
switch_thread_rwlock_unlock(profile->rwlock);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name);
|
||||
@@ -1146,38 +1147,46 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
|
||||
if (match) {
|
||||
nua_handle_t *bnh;
|
||||
sip_replaces_t *replaces;
|
||||
su_home_t *home = NULL;
|
||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED");
|
||||
switch_set_flag_locked(tech_pvt, TFLAG_READY);
|
||||
switch_channel_set_state(channel, CS_INIT);
|
||||
//switch_core_session_thread_launch(session);
|
||||
|
||||
if (replaces_str && (replaces = sip_replaces_make(tech_pvt->sofia_private->home, replaces_str))
|
||||
&& (bnh = nua_handle_by_replaces(nua, replaces))) {
|
||||
sofia_private_t *b_private;
|
||||
if (replaces_str) {
|
||||
home = su_home_new(sizeof(*home));
|
||||
assert(home != NULL);
|
||||
if ((replaces = sip_replaces_make(home, replaces_str))
|
||||
&& (bnh = nua_handle_by_replaces(nua, replaces))) {
|
||||
sofia_private_t *b_private;
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Processing Replaces Attended Transfer\n");
|
||||
while (switch_channel_get_state(channel) < CS_EXECUTE) {
|
||||
switch_yield(10000);
|
||||
}
|
||||
|
||||
if ((b_private = nua_handle_magic(bnh))) {
|
||||
char *br_b = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
|
||||
char *br_a = b_private->uuid;
|
||||
|
||||
if (br_b) {
|
||||
switch_ivr_uuid_bridge(br_a, br_b);
|
||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Processing Replaces Attended Transfer\n");
|
||||
while (switch_channel_get_state(channel) < CS_EXECUTE) {
|
||||
switch_yield(10000);
|
||||
}
|
||||
|
||||
if ((b_private = nua_handle_magic(bnh))) {
|
||||
char *br_b = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
|
||||
char *br_a = b_private->uuid;
|
||||
|
||||
if (br_b) {
|
||||
switch_ivr_uuid_bridge(br_a, br_b);
|
||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
|
||||
} else {
|
||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
}
|
||||
} else {
|
||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
}
|
||||
} else {
|
||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
nua_handle_unref(bnh);
|
||||
}
|
||||
nua_handle_unref(bnh);
|
||||
su_home_unref(home);
|
||||
home = NULL;
|
||||
}
|
||||
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -1351,9 +1360,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
|
||||
}
|
||||
|
||||
if (tech_pvt->sofia_private) {
|
||||
if (tech_pvt->sofia_private->home) {
|
||||
su_home_unref(tech_pvt->sofia_private->home);
|
||||
}
|
||||
free(tech_pvt->sofia_private);
|
||||
tech_pvt->sofia_private = NULL;
|
||||
}
|
||||
@@ -1362,9 +1368,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
|
||||
|
||||
|
||||
} else if (sofia_private) {
|
||||
if (sofia_private->home) {
|
||||
su_home_unref(sofia_private->home);
|
||||
}
|
||||
free(sofia_private);
|
||||
}
|
||||
|
||||
@@ -1391,6 +1394,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
|
||||
private_object_t *tech_pvt = NULL;
|
||||
char *etmp = NULL, *exten = NULL;
|
||||
switch_channel_t *channel_a = NULL, *channel_b = NULL;
|
||||
su_home_t *home = NULL;
|
||||
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
channel_a = switch_core_session_get_channel(session);
|
||||
@@ -1427,10 +1431,9 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
|
||||
if ((rep = strchr(refer_to->r_url->url_headers, '='))) {
|
||||
char *br_a = NULL, *br_b = NULL;
|
||||
char *buf;
|
||||
|
||||
rep++;
|
||||
|
||||
|
||||
|
||||
if ((buf = switch_core_session_alloc(session, strlen(rep) + 1))) {
|
||||
rep = url_unescape(buf, (const char *) rep);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Replaces: [%s]\n", rep);
|
||||
@@ -1438,7 +1441,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
|
||||
goto done;
|
||||
}
|
||||
if ((replaces = sip_replaces_make(tech_pvt->sofia_private->home, rep))
|
||||
|
||||
home = su_home_new(sizeof(*home));
|
||||
assert(home != NULL);
|
||||
|
||||
if ((replaces = sip_replaces_make(home, rep))
|
||||
&& (bnh = nua_handle_by_replaces(nua, replaces))) {
|
||||
sofia_private_t *b_private = NULL;
|
||||
private_object_t *b_tech_pvt = NULL;
|
||||
@@ -1612,6 +1619,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
|
||||
}
|
||||
|
||||
done:
|
||||
if (home) {
|
||||
su_home_unref(home);
|
||||
home = NULL;
|
||||
}
|
||||
|
||||
if (exten && strchr(exten, '@')) {
|
||||
switch_safe_free(exten);
|
||||
}
|
||||
@@ -1704,7 +1716,7 @@ const char *_url_set_chanvars(switch_core_session_t *session, url_t *url, const
|
||||
} else {
|
||||
uri = switch_core_session_sprintf(session, "%s:%s", host, port);
|
||||
}
|
||||
switch_channel_set_variable_nodup(channel, uri_var, uri);
|
||||
switch_channel_set_variable(channel, uri_var, uri);
|
||||
switch_channel_set_variable(channel, host_var, host);
|
||||
}
|
||||
|
||||
@@ -2024,8 +2036,10 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
abort();
|
||||
}
|
||||
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));
|
||||
sofia_presence_set_chat_hash(tech_pvt, sip);
|
||||
|
||||
if ((profile->pflags & PFLAG_PRESENCE)) {
|
||||
sofia_presence_set_chat_hash(tech_pvt, sip);
|
||||
}
|
||||
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);
|
||||
tech_pvt->nh = nh;
|
||||
|
||||
@@ -441,10 +441,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
|
||||
char *e_dest = NULL;
|
||||
const char *holdstr = "";
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
switch_hash_index_t *hi;
|
||||
void *vval;
|
||||
switch_event_header_t *hi;
|
||||
char *extra_headers = NULL;
|
||||
const void *vvar;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
char *rep;
|
||||
|
||||
@@ -541,7 +539,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
|
||||
}
|
||||
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));
|
||||
nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private);
|
||||
|
||||
@@ -575,17 +572,15 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
|
||||
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
if ((hi = switch_channel_variable_first(channel))) {
|
||||
for (; hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, &vvar, NULL, &vval);
|
||||
if (vvar && vval) {
|
||||
const char *name = vvar;
|
||||
char *value = (char *) vval;
|
||||
|
||||
if (!strncasecmp(name, SOFIA_SIP_HEADER_PREFIX, strlen(SOFIA_SIP_HEADER_PREFIX))) {
|
||||
const char *hname = name + strlen(SOFIA_SIP_HEADER_PREFIX);
|
||||
stream.write_function(&stream, "%s: %s\r\n", hname, value);
|
||||
}
|
||||
for (; hi; hi = hi = hi->next) {
|
||||
const char *name = (char *) hi->name;
|
||||
char *value = (char *) hi->value;
|
||||
|
||||
if (!strncasecmp(name, SOFIA_SIP_HEADER_PREFIX, strlen(SOFIA_SIP_HEADER_PREFIX))) {
|
||||
const char *hname = name + strlen(SOFIA_SIP_HEADER_PREFIX);
|
||||
stream.write_function(&stream, "%s: %s\r\n", hname, value);
|
||||
}
|
||||
|
||||
}
|
||||
switch_channel_variable_last(channel);
|
||||
}
|
||||
@@ -1532,31 +1527,14 @@ switch_status_t sofia_glue_add_profile(char *key, sofia_profile_t *profile)
|
||||
|
||||
void sofia_glue_del_profile(sofia_profile_t *profile)
|
||||
{
|
||||
switch_hash_index_t *hi;
|
||||
void *vval;
|
||||
const void *vvar;
|
||||
sofia_profile_t *this_profile;
|
||||
sofia_gateway_t *gp, *this_gateway;
|
||||
|
||||
sofia_gateway_t *gp;
|
||||
|
||||
switch_mutex_lock(mod_sofia_globals.hash_mutex);
|
||||
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, &vvar, NULL, &vval);
|
||||
this_profile = (sofia_profile_t *) vval;
|
||||
if (this_profile == profile) {
|
||||
switch_core_hash_delete(mod_sofia_globals.profile_hash, vvar);
|
||||
}
|
||||
switch_core_hash_delete(mod_sofia_globals.profile_hash, profile->name);
|
||||
for (gp = profile->gateways; gp; gp = gp->next) {
|
||||
switch_core_hash_delete(mod_sofia_globals.gateway_hash, gp->name);
|
||||
}
|
||||
for (hi = switch_hash_first(NULL, mod_sofia_globals.gateway_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, &vvar, NULL, &vval);
|
||||
this_gateway = (sofia_gateway_t *) vval;
|
||||
|
||||
for (gp = profile->gateways; gp; gp = gp->next) {
|
||||
if (gp == this_gateway) {
|
||||
switch_core_hash_delete(mod_sofia_globals.gateway_hash, vvar);
|
||||
}
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
|
||||
|
||||
}
|
||||
|
||||
@@ -1051,15 +1051,20 @@ void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
|
||||
{
|
||||
char hash_key[256] = "";
|
||||
char buf[512];
|
||||
su_home_t *home = NULL;
|
||||
|
||||
if (tech_pvt->hash_key || !sip || !sip->sip_from || !sip->sip_from->a_url || !sip->sip_from->a_url->url_user || !sip->sip_from->a_url->url_host) {
|
||||
return;
|
||||
}
|
||||
|
||||
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->sofia_private->home, (const sip_header_t *) sip->sip_to);
|
||||
home = su_home_new(sizeof(*home));
|
||||
assert(home != NULL);
|
||||
tech_pvt->chat_from = sip_header_as_string(home, (const sip_header_t *) sip->sip_to);
|
||||
tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
|
||||
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
|
||||
su_home_unref(home);
|
||||
home = NULL;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user