skypopen: fixing bug from Anton VG, adding some guards against NULL sessions and channels

This commit is contained in:
Giovanni Maruzzelli 2011-05-21 02:36:51 -05:00
parent 3ad0d5d624
commit 7fa3f7f3dd

View File

@ -938,16 +938,21 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
char *p = digit_str;
switch_channel_t *channel = switch_core_session_get_channel(session);
while (p && *p) {
switch_dtmf_t dtmf;
dtmf.digit = *p;
dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
switch_channel_queue_dtmf(channel, &dtmf);
p++;
if(channel){
while (p && *p) {
switch_dtmf_t dtmf;
dtmf.digit = *p;
dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
switch_channel_queue_dtmf(channel, &dtmf);
p++;
}
NOTICA("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", SKYPOPEN_P_LOG, digit_str, (unsigned int) new_dtmf_timestamp,
(unsigned int) (new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp));
tech_pvt->old_dtmf_timestamp = new_dtmf_timestamp;
}else{
WARNINGA("NO CHANNEL ?\n", SKYPOPEN_P_LOG);
}
NOTICA("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", SKYPOPEN_P_LOG, digit_str, (unsigned int) new_dtmf_timestamp,
(unsigned int) (new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp));
tech_pvt->old_dtmf_timestamp = new_dtmf_timestamp;
}
}
}
@ -2138,33 +2143,37 @@ int dtmf_received(private_t *tech_pvt, char *value)
switch_channel_t *channel = NULL;
session = switch_core_session_locate(tech_pvt->session_uuid_str);
channel = switch_core_session_get_channel(session);
if (session) {
channel = switch_core_session_get_channel(session);
if (channel) {
if (channel) {
if (switch_channel_test_flag(channel, CF_BRIDGED)
&& !switch_true(switch_channel_get_variable(channel, "skype_add_outband_dtmf_also_when_bridged"))) {
if (switch_channel_test_flag(channel, CF_BRIDGED)
&& !switch_true(switch_channel_get_variable(channel, "skype_add_outband_dtmf_also_when_bridged"))) {
NOTICA
("received DTMF '%c' on channel %s, but we're BRIDGED, so we DO NOT relay it out of band. If you DO want to relay it out of band when bridged too, on top of audio DTMF, set the channel variable 'skype_add_outband_dtmf_also_when_bridged=true' \n",
SKYPOPEN_P_LOG, value[0], switch_channel_get_name(channel));
NOTICA
("received DTMF '%c' on channel %s, but we're BRIDGED, so we DO NOT relay it out of band. If you DO want to relay it out of band when bridged too, on top of audio DTMF, set the channel variable 'skype_add_outband_dtmf_also_when_bridged=true' \n",
SKYPOPEN_P_LOG, value[0], switch_channel_get_name(channel));
} else {
switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
DEBUGA_SKYPE("received DTMF %c on channel %s\n", SKYPOPEN_P_LOG, dtmf.digit, switch_channel_get_name(channel));
switch_mutex_lock(tech_pvt->flag_mutex);
switch_channel_queue_dtmf(channel, &dtmf);
switch_set_flag(tech_pvt, TFLAG_DTMF);
switch_mutex_unlock(tech_pvt->flag_mutex);
}
} else {
switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
DEBUGA_SKYPE("received DTMF %c on channel %s\n", SKYPOPEN_P_LOG, dtmf.digit, switch_channel_get_name(channel));
switch_mutex_lock(tech_pvt->flag_mutex);
switch_channel_queue_dtmf(channel, &dtmf);
switch_set_flag(tech_pvt, TFLAG_DTMF);
switch_mutex_unlock(tech_pvt->flag_mutex);
WARNINGA("received %c DTMF, but no channel?\n", SKYPOPEN_P_LOG, value[0]);
}
} else {
WARNINGA("received %c DTMF, but no channel?\n", SKYPOPEN_P_LOG, value[0]);
switch_core_session_rwunlock(session);
}else{
WARNINGA("received %c DTMF, but no session?\n", SKYPOPEN_P_LOG, value[0]);
}
switch_core_session_rwunlock(session);
return 0;
}