freetdm: core - moved validation of sigstatus from implementation to core, on sigstatus getters/setters

core - locking the channel on ftdm_channel_get_sig_status() and ftdm_channel_set_sig_status(),
                but not on ftdm_span_get_sig_status() nor ftdm_span_set_sig_status()
         ftmod_r2 - locking channels on ftdm_r2_get_span_sig_status() and ftdm_r2_set_span_sig_status()
This commit is contained in:
Arnaldo Pereira 2010-12-17 18:28:57 -02:00
parent d3a24be0ba
commit 6b52208957
2 changed files with 26 additions and 11 deletions

View File

@ -2488,9 +2488,18 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_set_sig_status(ftdm_channel_t *ftdmchan,
{
ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "Null channel\n");
ftdm_assert_return(ftdmchan->span != NULL, FTDM_FAIL, "Null span\n");
if (sigstatus == FTDM_SIG_STATE_DOWN) {
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "The user is not allowed to set the signaling status to DOWN, valid states are UP or SUSPENDED\n");
return FTDM_FAIL;
}
if (ftdmchan->span->set_channel_sig_status) {
return ftdmchan->span->set_channel_sig_status(ftdmchan, sigstatus);
ftdm_status_t res;
ftdm_channel_lock(ftdmchan);
res = ftdmchan->span->set_channel_sig_status(ftdmchan, sigstatus);
ftdm_channel_unlock(ftdmchan);
return res;
} else {
ftdm_log(FTDM_LOG_ERROR, "set_channel_sig_status method not implemented!\n");
return FTDM_FAIL;
@ -2504,7 +2513,11 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_get_sig_status(ftdm_channel_t *ftdmchan,
ftdm_assert_return(sigstatus != NULL, FTDM_FAIL, "Null sig status parameter\n");
if (ftdmchan->span->get_channel_sig_status) {
return ftdmchan->span->get_channel_sig_status(ftdmchan, sigstatus);
ftdm_status_t res;
ftdm_channel_lock(ftdmchan);
res = ftdmchan->span->get_channel_sig_status(ftdmchan, sigstatus);
ftdm_channel_unlock(ftdmchan);
return res;
} else {
/* don't log error here, it can be called just to test if its supported */
return FTDM_NOTIMPL;
@ -2515,6 +2528,11 @@ FT_DECLARE(ftdm_status_t) ftdm_span_set_sig_status(ftdm_span_t *span, ftdm_signa
{
ftdm_assert_return(span != NULL, FTDM_FAIL, "Null span\n");
if (sigstatus == FTDM_SIG_STATE_DOWN) {
ftdm_log(FTDM_LOG_WARNING, "The user is not allowed to set the signaling status to DOWN, valid states are UP or SUSPENDED\n");
return FTDM_FAIL;
}
if (span->set_span_sig_status) {
return span->set_span_sig_status(span, sigstatus);
} else {

View File

@ -486,9 +486,6 @@ static FIO_CHANNEL_SET_SIG_STATUS_FUNCTION(ftdm_r2_set_channel_sig_status)
ftdm_r2_set_chan_sig_status(ftdmchan, status);
}
break;
case FTDM_SIG_STATE_DOWN:
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "The user is not allowed to set signaling status to DOWN\n");
return FTDM_FAIL;
default:
ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Cannot set signaling status to unknown value '%d'\n", status);
return FTDM_FAIL;
@ -508,10 +505,13 @@ static FIO_SPAN_GET_SIG_STATUS_FUNCTION(ftdm_r2_get_span_sig_status)
*status = FTDM_SIG_STATE_SUSPENDED;
for (citer = chaniter; citer; citer = ftdm_iterator_next(citer)) {
ftdm_channel_t *fchan = ftdm_iterator_current(citer);
ftdm_channel_lock(fchan);
if (ftdm_test_flag(fchan, FTDM_CHANNEL_SIG_UP)) {
*status = FTDM_SIG_STATE_UP;
ftdm_channel_unlock(fchan);
break;
}
ftdm_channel_unlock(fchan);
}
ftdm_iterator_free(chaniter);
return FTDM_SUCCESS;
@ -522,11 +522,6 @@ static FIO_SPAN_SET_SIG_STATUS_FUNCTION(ftdm_r2_set_span_sig_status)
ftdm_iterator_t *chaniter = NULL;
ftdm_iterator_t *citer = NULL;
if (status == FTDM_SIG_STATE_DOWN) {
ftdm_log(FTDM_LOG_WARNING, "The user is not allowed to set the span signaling status to DOWN\n");
return FTDM_FAIL;
}
chaniter = ftdm_span_get_chan_iterator(span, NULL);
if (!chaniter) {
ftdm_log(FTDM_LOG_CRIT, "Failed to allocate channel iterator for span %s!\n", span->name);
@ -537,9 +532,11 @@ static FIO_SPAN_SET_SIG_STATUS_FUNCTION(ftdm_r2_set_span_sig_status)
ftdm_channel_t *fchan = ftdm_iterator_current(citer);
/* we set channel's state through ftdm_r2_set_channel_sig_status(), since it already takes
* care of notifying the user when appropriate */
ftdm_channel_lock(fchan);
if ((ftdm_r2_set_channel_sig_status(fchan, status)) != FTDM_SUCCESS) {
ftdm_log_chan(fchan, FTDM_LOG_ERROR, "Failed to set signaling status to %s\n", ftdm_signaling_status2str(status));
}
ftdm_channel_unlock(fchan);
}
ftdm_iterator_free(chaniter);
return FTDM_SUCCESS;