cleanup, null checks. etc.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6735 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-12-13 04:01:29 +00:00
parent 1e0afe2b9d
commit 750af968ec
5 changed files with 59 additions and 52 deletions

View File

@ -554,6 +554,10 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
}
}
if (!tech_pvt->read_codec.implementation) {
return SWITCH_STATUS_GENERR;
}
if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
return SWITCH_STATUS_FALSE;
}
@ -1371,7 +1375,7 @@ SWITCH_STANDARD_API(sofia_function)
goto done;
}
if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
stream->write_function(stream, "%s", usage_string);
goto done;
}

View File

@ -345,7 +345,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
uint32_t ireg_loops = 0;
uint32_t gateway_loops = 0;
switch_event_t *s_event;
int tport_log = 0;
int tportlog = 0;
switch_mutex_lock(mod_sofia_globals.mutex);
mod_sofia_globals.threads++;
@ -363,13 +363,13 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
}
if (switch_test_flag(profile, TFLAG_TPORT_LOG)) {
tport_log = 1;
tportlog = 1;
}
profile->nua = nua_create(profile->s_root, /* Event loop */
sofia_event_callback, /* Callback for processing events */
profile, /* Additional data to pass to callback */
NUTAG_URL(profile->bindurl), NTATAG_UDP_MTU(65536), TAG_IF(tport_log,TPTAG_LOG(1)), TAG_END()); /* Last tag should always finish the sequence */
NUTAG_URL(profile->bindurl), NTATAG_UDP_MTU(65536), TAG_IF(tportlog,TPTAG_LOG(1)), TAG_END()); /* Last tag should always finish the sequence */
if (!profile->nua) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Creating SIP UA for profile: %s\n", profile->name);
@ -1046,8 +1046,8 @@ switch_status_t config_sofia(int reload, char *profile_name)
}
if (profile->bind_params) {
char *url = profile->bindurl;
profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", url, profile->bind_params);
char *bindurl = profile->bindurl;
profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", bindurl, profile->bind_params);
}
}

View File

@ -867,6 +867,7 @@ switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int
switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
{
int ms;
if (tech_pvt->read_codec.implementation) {
if (!force) {
@ -901,32 +902,38 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
tech_pvt->iananame,
tech_pvt->rm_fmtp,
tech_pvt->rm_rate,
tech_pvt->codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
} else {
int ms;
tech_pvt->read_frame.rate = tech_pvt->rm_rate;
ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples\n",
switch_channel_get_name(tech_pvt->channel), tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
tech_pvt->read_codec.implementation->samples_per_frame
);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
}
}
if (switch_core_codec_init(&tech_pvt->write_codec,
tech_pvt->iananame,
tech_pvt->rm_fmtp,
tech_pvt->rm_rate,
tech_pvt->codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
}
tech_pvt->read_frame.rate = tech_pvt->rm_rate;
ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
if (!tech_pvt->read_codec.implementation) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples\n",
switch_channel_get_name(tech_pvt->channel), tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
tech_pvt->read_codec.implementation->samples_per_frame
);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
return SWITCH_STATUS_SUCCESS;
}

View File

@ -341,23 +341,23 @@ void sofia_presence_event_handler(switch_event_t *event)
case SWITCH_EVENT_PRESENCE_PROBE:
if (proto) {
char *to = switch_event_get_header(event, "to");
char *user, *euser, *host, *p;
char *probe_user, *probe_euser, *probe_host, *p;
if (!to || !(user = strdup(to))) {
if (!to || !(probe_user = strdup(to))) {
return;
}
if ((host = strchr(user, '@'))) {
*host++ = '\0';
if ((probe_host = strchr(probe_user, '@'))) {
*probe_host++ = '\0';
}
euser = user;
if ((p = strchr(euser, '+'))) {
euser = (p + 1);
probe_euser = probe_user;
if ((p = strchr(probe_euser, '+'))) {
probe_euser = (p + 1);
}
if (euser && host &&
if (probe_euser && probe_host &&
(sql = switch_mprintf("select sip_user,sip_host,status,rpid,'' from sip_registrations where sip_user='%q' and sip_host='%q'",
euser, host)) && (profile = sofia_glue_find_profile(host))) {
probe_euser, probe_host)) && (profile = sofia_glue_find_profile(probe_host))) {
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
@ -725,17 +725,17 @@ void sofia_presence_handle_sip_i_subscribe(int status,
from_host = "n/a";
}
if (strstr(to_user, "ext+") || strstr(to_user, "user+")) {
char proto[80];
if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
char protocol[80];
char *p;
switch_copy_string(proto, to_user, sizeof(proto));
if ((p = strchr(proto, '+'))) {
switch_copy_string(protocol, to_user, sizeof(protocol));
if ((p = strchr(protocol, '+'))) {
*p = '\0';
}
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", proto);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
@ -754,7 +754,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
}
}
if (strchr(to_user, '+')) {
if (to_user && strchr(to_user, '+')) {
char *h;
if ((proto = (d_user = strdup(to_user)))) {
if ((my_to_user = strchr(d_user, '+'))) {

View File

@ -89,9 +89,8 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
if (!(gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)))) {
abort();
}
gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
switch_assert(gateway_ptr->sofia_private);
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
gateway_ptr->sofia_private->gateway = gateway_ptr;
@ -881,9 +880,6 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
}
if (!a1_hash) {
su_md5_t ctx;
char *input;
input = switch_mprintf("%s:%s:%s", username, realm, passwd);
su_md5_init(&ctx);
su_md5_strupdate(&ctx, input);