提交 6092524f authored 作者: Michael Jerris's avatar Michael Jerris

CID:1174726 Dereference before null check, CID:1214199 Dereference null return…

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
上级 0d7b1ff4
...@@ -2451,232 +2451,226 @@ switch_io_routines_t dingaling_io_routines = { ...@@ -2451,232 +2451,226 @@ 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, 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_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) 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;
struct private_object *tech_pvt; switch_channel_t *channel;
switch_channel_t *channel; switch_caller_profile_t *caller_profile = NULL;
switch_caller_profile_t *caller_profile = NULL; mdl_profile_t *mdl_profile = NULL;
mdl_profile_t *mdl_profile = NULL; ldl_session_t *dlsession = NULL;
ldl_session_t *dlsession = NULL; char *profile_name;
char *profile_name; char *callto;
char *callto; char idbuf[1024];
char idbuf[1024]; char *full_id = NULL;
char *full_id = NULL; char sess_id[11] = "";
char sess_id[11] = ""; char *dnis = NULL;
char *dnis = NULL; char workspace[1024] = "";
char workspace[1024] = ""; char *p, *u, ubuf[512] = "", *user = NULL, *f_cid_msg = NULL;
char *p, *u, ubuf[512] = "", *user = NULL, *f_cid_msg = NULL; const char *cid_msg = NULL;
const char *cid_msg = NULL; ldl_user_flag_t flags = LDL_FLAG_OUTBOUND;
ldl_user_flag_t flags = LDL_FLAG_OUTBOUND; const char *var;
const char *var; char name[128];
switch_copy_string(workspace, outbound_profile->destination_number, sizeof(workspace));
profile_name = workspace;
if ((callto = strchr(profile_name, '/'))) {
*callto++ = '\0';
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Invalid URL!\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
}
if ((dnis = strchr(callto, ':'))) { *new_session = switch_core_session_request(dingaling_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, oflags, pool);
*dnis++ = '\0';
}
for (p = callto; p && *p; p++) { if (!*new_session) {
*p = (char) tolower(*p); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if ((p = strchr(profile_name, '@'))) { if (!outbound_profile) {
*p++ = '\0'; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Doh! no caller profile\n");
u = profile_name; terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
profile_name = p; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
switch_snprintf(ubuf, sizeof(ubuf), "%s@%s/talk", u, profile_name); }
user = ubuf;
}
if ((mdl_profile = switch_core_hash_find(globals.profile_hash, profile_name))) { switch_copy_string(workspace, outbound_profile->destination_number, sizeof(workspace));
if (!(mdl_profile->user_flags & LDL_FLAG_COMPONENT)) { profile_name = workspace;
user = ldl_handle_get_login(mdl_profile->handle);
} else {
if (!user) {
const char *id_num;
if (!(id_num = outbound_profile->caller_id_number)) { if ((callto = strchr(profile_name, '/'))) {
if (!(id_num = outbound_profile->caller_id_name)) { *callto++ = '\0';
id_num = "nobody"; } else {
} switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Invalid URL!\n");
} terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
}
if (strchr(id_num, '@')) { if ((dnis = strchr(callto, ':'))) {
switch_snprintf(ubuf, sizeof(ubuf), "%s/talk", id_num); *dnis++ = '\0';
user = ubuf; }
} else {
switch_snprintf(ubuf, sizeof(ubuf), "%s@%s/talk", id_num, profile_name);
user = ubuf;
}
}
}
if (mdl_profile->purge) { for (p = callto; p && *p; p++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile '%s' is marked for deletion, disallowing outgoing call\n", *p = (char) tolower(*p);
mdl_profile->name); }
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NORMAL_UNSPECIFIED);
return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
}
if (switch_thread_rwlock_tryrdlock(mdl_profile->rwlock) != SWITCH_STATUS_SUCCESS) { if ((p = strchr(profile_name, '@'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't do read lock on profile '%s'\n", mdl_profile->name); *p++ = '\0';
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NORMAL_UNSPECIFIED); u = profile_name;
return SWITCH_CAUSE_NORMAL_UNSPECIFIED; profile_name = p;
} switch_snprintf(ubuf, sizeof(ubuf), "%s@%s/talk", u, profile_name);
user = ubuf;
}
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 {
if (!user) {
const char *id_num;
if (!ldl_handle_ready(mdl_profile->handle)) { if (!(id_num = outbound_profile->caller_id_number)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n"); if (!(id_num = outbound_profile->caller_id_name)) {
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); id_num = "nobody";
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; }
} }
if (switch_stristr("voice.google.com", callto)) {
full_id = callto; if (strchr(id_num, '@')) {
flags |= LDL_FLAG_GATEWAY; switch_snprintf(ubuf, sizeof(ubuf), "%s/talk", id_num);
} else if (!(full_id = ldl_handle_probe(mdl_profile->handle, callto, user, idbuf, sizeof(idbuf)))) { user = ubuf;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Unknown Recipient!\n"); } else {
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NO_USER_RESPONSE); switch_snprintf(ubuf, sizeof(ubuf), "%s@%s/talk", id_num, profile_name);
return SWITCH_CAUSE_NO_USER_RESPONSE; user = ubuf;
} }
} else {
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->purge) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile '%s' is marked for deletion, disallowing outgoing call\n",
mdl_profile->name);
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NORMAL_UNSPECIFIED);
return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
}
switch_core_session_add_stream(*new_session, NULL); if (switch_thread_rwlock_tryrdlock(mdl_profile->rwlock) != SWITCH_STATUS_SUCCESS) {
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't do read lock on profile '%s'\n", mdl_profile->name);
memset(tech_pvt, 0, sizeof(*tech_pvt)); terminate_session(new_session, __LINE__, SWITCH_CAUSE_NORMAL_UNSPECIFIED);
tech_pvt->profile = mdl_profile; return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session)); }
tech_pvt->flags |= globals.flags;
tech_pvt->flags |= mdl_profile->flags;
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session;
tech_pvt->channel = switch_core_session_get_channel(tech_pvt->session);
tech_pvt->transports[LDL_TPORT_RTP].codec_index = -1;
tech_pvt->transports[LDL_TPORT_VIDEO_RTP].codec_index = -1;
switch_set_flag(tech_pvt, TFLAG_SECURE); if (!ldl_handle_ready(mdl_profile->handle)) {
mdl_build_crypto(tech_pvt, LDL_TPORT_RTP, 1, AES_CM_128_HMAC_SHA1_80, SWITCH_RTP_CRYPTO_SEND); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n");
mdl_build_crypto(tech_pvt, LDL_TPORT_VIDEO_RTP, 1, AES_CM_128_HMAC_SHA1_80, SWITCH_RTP_CRYPTO_SEND); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
if (switch_stristr("voice.google.com", callto)) {
full_id = callto;
flags |= LDL_FLAG_GATEWAY;
} else if (!(full_id = ldl_handle_probe(mdl_profile->handle, callto, user, idbuf, sizeof(idbuf)))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "Unknown Recipient!\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NO_USER_RESPONSE);
return SWITCH_CAUSE_NO_USER_RESPONSE;
}
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;
}
if (!(tech_pvt->transports[LDL_TPORT_RTP].local_port = switch_rtp_request_port(mdl_profile->ip))) { memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "No RTP port available!\n"); tech_pvt->profile = mdl_profile;
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; tech_pvt->flags |= globals.flags;
} tech_pvt->flags |= mdl_profile->flags;
tech_pvt->transports[LDL_TPORT_RTP].adv_local_port = tech_pvt->transports[LDL_TPORT_RTP].local_port; channel = switch_core_session_get_channel(*new_session);
tech_pvt->transports[LDL_TPORT_RTCP].adv_local_port = tech_pvt->transports[LDL_TPORT_RTP].local_port + 1; switch_core_session_set_private(*new_session, tech_pvt);
if (!(tech_pvt->transports[LDL_TPORT_VIDEO_RTP].local_port = switch_rtp_request_port(mdl_profile->ip))) { tech_pvt->session = *new_session;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "No RTP port available!\n"); tech_pvt->channel = switch_core_session_get_channel(tech_pvt->session);
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); tech_pvt->transports[LDL_TPORT_RTP].codec_index = -1;
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; tech_pvt->transports[LDL_TPORT_VIDEO_RTP].codec_index = -1;
}
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;
switch_set_flag(tech_pvt, TFLAG_SECURE);
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);
tech_pvt->recip = switch_core_session_strdup(*new_session, full_id); if (!(tech_pvt->transports[LDL_TPORT_RTP].local_port = switch_rtp_request_port(mdl_profile->ip))) {
if (dnis) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "No RTP port available!\n");
tech_pvt->dnis = switch_core_session_strdup(*new_session, dnis); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
} return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} else { }
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); tech_pvt->transports[LDL_TPORT_RTP].adv_local_port = tech_pvt->transports[LDL_TPORT_RTP].local_port;
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); tech_pvt->transports[LDL_TPORT_RTCP].adv_local_port = tech_pvt->transports[LDL_TPORT_RTP].local_port + 1;
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; if (!(tech_pvt->transports[LDL_TPORT_VIDEO_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);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
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;
if (outbound_profile) { tech_pvt->recip = switch_core_session_strdup(*new_session, full_id);
char name[128]; if (dnis) {
tech_pvt->dnis = switch_core_session_strdup(*new_session, dnis);
}
switch_snprintf(name, sizeof(name), "dingaling/%s", outbound_profile->destination_number); switch_snprintf(name, sizeof(name), "dingaling/%s", outbound_profile->destination_number);
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
switch_channel_set_caller_profile(channel, caller_profile); switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = 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); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_stun_random_string(sess_id, 10, "0123456789"); switch_stun_random_string(sess_id, 10, "0123456789");
tech_pvt->us = switch_core_session_strdup(*new_session, user); tech_pvt->us = switch_core_session_strdup(*new_session, user);
tech_pvt->them = switch_core_session_strdup(*new_session, full_id); tech_pvt->them = switch_core_session_strdup(*new_session, full_id);
ldl_session_create(&dlsession, mdl_profile->handle, sess_id, full_id, user, flags); ldl_session_create(&dlsession, mdl_profile->handle, sess_id, full_id, user, flags);
if (session) { if (session) {
switch_channel_t *calling_channel = switch_core_session_get_channel(session); switch_channel_t *calling_channel = switch_core_session_get_channel(session);
cid_msg = switch_channel_get_variable(calling_channel, "dl_cid_msg"); cid_msg = switch_channel_get_variable(calling_channel, "dl_cid_msg");
} }
if (!cid_msg) { if (!cid_msg) {
f_cid_msg = switch_mprintf("Incoming Call From %s %s\n", outbound_profile->caller_id_name, outbound_profile->caller_id_number); f_cid_msg = switch_mprintf("Incoming Call From %s %s\n", outbound_profile->caller_id_name, outbound_profile->caller_id_number);
cid_msg = f_cid_msg; cid_msg = f_cid_msg;
} }
if ((flags & LDL_FLAG_GATEWAY)) { if ((flags & LDL_FLAG_GATEWAY)) {
cid_msg = NULL; cid_msg = NULL;
} }
if (cid_msg) { if (cid_msg) {
char *them; char *them;
them = strdup(tech_pvt->them); them = strdup(tech_pvt->them);
if (them) { if (them) {
char *ptr; char *ptr;
if ((ptr = strchr(them, '/'))) { if ((ptr = strchr(them, '/'))) {
*ptr = '\0'; *ptr = '\0';
}
ldl_handle_send_msg(mdl_profile->handle, tech_pvt->us, them, "", switch_str_nil(cid_msg));
} }
switch_safe_free(them); ldl_handle_send_msg(mdl_profile->handle, tech_pvt->us, them, "", switch_str_nil(cid_msg));
}
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);
ldl_session_set_value(dlsession, "caller_id_number", outbound_profile->caller_id_number);
tech_pvt->dlsession = dlsession;
if ((var = switch_event_get_header(var_event, "absolute_codec_string"))) {
switch_channel_set_variable(channel, "absolute_codec_string", var);
} }
switch_safe_free(them);
}
switch_safe_free(f_cid_msg);
if (!get_codecs(tech_pvt)) { ldl_session_set_private(dlsession, *new_session);
terminate_session(new_session, __LINE__, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL); ldl_session_set_value(dlsession, "dnis", dnis);
return SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL; ldl_session_set_value(dlsession, "caller_id_name", outbound_profile->caller_id_name);
} ldl_session_set_value(dlsession, "caller_id_number", outbound_profile->caller_id_number);
switch_channel_set_state(channel, CS_INIT); tech_pvt->dlsession = dlsession;
return SWITCH_CAUSE_SUCCESS;
if ((var = switch_event_get_header(var_event, "absolute_codec_string"))) {
switch_channel_set_variable(channel, "absolute_codec_string", var);
} }
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; if (!get_codecs(tech_pvt)) {
terminate_session(new_session, __LINE__, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL);
return SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL;
}
switch_channel_set_state(channel, CS_INIT);
return SWITCH_CAUSE_SUCCESS;
} }
static switch_status_t list_profiles(const char *line, const char *cursor, switch_console_callback_match_t **matches) 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 ...@@ -4360,8 +4354,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
char *hint = NULL, *p, *freeme = NULL; char *hint = NULL, *p, *freeme = NULL;
hint = from; hint = from;
if (strchr(from, '/')) { if (strchr(from, '/') && (freeme = strdup(from))) {
freeme = strdup(from);
p = strchr(freeme, '/'); p = strchr(freeme, '/');
*p = '\0'; *p = '\0';
from = freeme; from = freeme;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论