CID:1174726 Dereference before null check, CID:1214199 Dereference null return value; refactor channel_outgoing_channel to have failure conditions first to reduce indenting level
This commit is contained in:
parent
0d7b1ff42a
commit
6092524f17
|
@ -2451,10 +2451,9 @@ switch_io_routines_t dingaling_io_routines = {
|
|||
*/
|
||||
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
|
||||
switch_caller_profile_t *outbound_profile,
|
||||
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
|
||||
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t oflags,
|
||||
switch_call_cause_t *cancel_cause)
|
||||
{
|
||||
if ((*new_session = switch_core_session_request(dingaling_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, flags, pool)) != 0) {
|
||||
struct private_object *tech_pvt;
|
||||
switch_channel_t *channel;
|
||||
switch_caller_profile_t *caller_profile = NULL;
|
||||
|
@ -2471,6 +2470,19 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
const char *cid_msg = NULL;
|
||||
ldl_user_flag_t flags = LDL_FLAG_OUTBOUND;
|
||||
const char *var;
|
||||
char name[128];
|
||||
|
||||
*new_session = switch_core_session_request(dingaling_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, oflags, pool);
|
||||
|
||||
if (!*new_session) {
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
if (!outbound_profile) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Doh! no caller profile\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
switch_copy_string(workspace, outbound_profile->destination_number, sizeof(workspace));
|
||||
profile_name = workspace;
|
||||
|
@ -2499,7 +2511,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
user = ubuf;
|
||||
}
|
||||
|
||||
if ((mdl_profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
|
||||
mdl_profile = switch_core_hash_find(globals.profile_hash, profile_name);
|
||||
|
||||
if (!mdl_profile) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Unknown Profile!\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
if (!(mdl_profile->user_flags & LDL_FLAG_COMPONENT)) {
|
||||
user = ldl_handle_get_login(mdl_profile->handle);
|
||||
} else {
|
||||
|
@ -2535,9 +2554,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!ldl_handle_ready(mdl_profile->handle)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
|
@ -2551,15 +2567,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NO_USER_RESPONSE);
|
||||
return SWITCH_CAUSE_NO_USER_RESPONSE;
|
||||
}
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Unknown Profile!\n");
|
||||
|
||||
switch_core_session_add_stream(*new_session, NULL);
|
||||
tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object));
|
||||
|
||||
if (!tech_pvt) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
|
||||
switch_core_session_add_stream(*new_session, NULL);
|
||||
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||
tech_pvt->profile = mdl_profile;
|
||||
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
||||
|
@ -2576,8 +2593,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
mdl_build_crypto(tech_pvt, LDL_TPORT_RTP, 1, AES_CM_128_HMAC_SHA1_80, SWITCH_RTP_CRYPTO_SEND);
|
||||
mdl_build_crypto(tech_pvt, LDL_TPORT_VIDEO_RTP, 1, AES_CM_128_HMAC_SHA1_80, SWITCH_RTP_CRYPTO_SEND);
|
||||
|
||||
|
||||
|
||||
if (!(tech_pvt->transports[LDL_TPORT_RTP].local_port = switch_rtp_request_port(mdl_profile->ip))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "No RTP port available!\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
|
@ -2593,20 +2608,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
tech_pvt->transports[LDL_TPORT_VIDEO_RTP].adv_local_port = tech_pvt->transports[LDL_TPORT_VIDEO_RTP].local_port;
|
||||
tech_pvt->transports[LDL_TPORT_VIDEO_RTCP].adv_local_port = tech_pvt->transports[LDL_TPORT_VIDEO_RTP].local_port + 1;
|
||||
|
||||
|
||||
|
||||
tech_pvt->recip = switch_core_session_strdup(*new_session, full_id);
|
||||
if (dnis) {
|
||||
tech_pvt->dnis = switch_core_session_strdup(*new_session, dnis);
|
||||
}
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
if (outbound_profile) {
|
||||
char name[128];
|
||||
|
||||
switch_snprintf(name, sizeof(name), "dingaling/%s", outbound_profile->destination_number);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
@ -2614,11 +2619,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
|
||||
switch_channel_set_caller_profile(channel, caller_profile);
|
||||
tech_pvt->caller_profile = caller_profile;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Doh! no caller profile\n");
|
||||
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
||||
|
||||
|
@ -2655,7 +2655,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
}
|
||||
switch_safe_free(f_cid_msg);
|
||||
|
||||
|
||||
ldl_session_set_private(dlsession, *new_session);
|
||||
ldl_session_set_value(dlsession, "dnis", dnis);
|
||||
ldl_session_set_value(dlsession, "caller_id_name", outbound_profile->caller_id_name);
|
||||
|
@ -2672,11 +2671,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
}
|
||||
switch_channel_set_state(channel, CS_INIT);
|
||||
return SWITCH_CAUSE_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t list_profiles(const char *line, const char *cursor, switch_console_callback_match_t **matches)
|
||||
|
@ -4360,8 +4354,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
|||
char *hint = NULL, *p, *freeme = NULL;
|
||||
|
||||
hint = from;
|
||||
if (strchr(from, '/')) {
|
||||
freeme = strdup(from);
|
||||
if (strchr(from, '/') && (freeme = strdup(from))) {
|
||||
p = strchr(freeme, '/');
|
||||
*p = '\0';
|
||||
from = freeme;
|
||||
|
|
Loading…
Reference in New Issue