freetdm: more iterator fixes

This commit is contained in:
Moises Silva 2010-09-10 14:46:51 -04:00
parent 507b73070b
commit 8370f0c233
2 changed files with 14 additions and 12 deletions

View File

@ -3597,6 +3597,8 @@ SWITCH_STANDARD_API(ft_function)
{
char *mycmd = NULL, *argv[10] = { 0 };
int argc = 0;
ftdm_iterator_t *chaniter = NULL;
ftdm_iterator_t *curr = NULL;
if (!zstr(cmd) && (mycmd = strdup(cmd))) {
argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
@ -3642,11 +3644,11 @@ SWITCH_STANDARD_API(ft_function)
dump_chan_xml(span, chan_id, stream);
}
} else {
uint32_t j;
uint32_t ccount = ftdm_span_get_chan_count(span);
for (j = 1; j <= ccount; j++) {
dump_chan_xml(span, j, stream);
chaniter = ftdm_span_get_chan_iterator(span, NULL);
for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) {
dump_chan_xml(span, ftdm_channel_get_id(ftdm_iterator_current(curr)), stream);
}
ftdm_iterator_free(chaniter);
}
}
@ -3662,12 +3664,12 @@ SWITCH_STANDARD_API(ft_function)
dump_chan(span, chan_id, stream);
}
} else {
uint32_t j;
uint32_t ccount = ftdm_span_get_chan_count(span);
stream->write_function(stream, "+OK\n");
for (j = 1; j <= ccount; j++) {
dump_chan(span, j, stream);
chaniter = ftdm_span_get_chan_iterator(span, NULL);
for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) {
dump_chan(span, ftdm_channel_get_id(ftdm_iterator_current(curr)), stream);
}
ftdm_iterator_free(chaniter);
}
}

View File

@ -3602,9 +3602,8 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter)
}
return iter;
case FTDM_ITERATOR_CHANS:
if (iter->pvt.chaniter.index == iter->pvt.chaniter.span->chan_count) {
return NULL;
}
ftdm_assert_return(iter->pvt.chaniter.index, NULL, "channel iterator index cannot be zero!\n");
ftdm_assert_return(iter->pvt.chaniter.index <= iter->pvt.chaniter.span->chan_count, NULL, "channel iterator index bigger than span chan count!\n");
iter->pvt.chaniter.index++;
return iter;
default:
@ -3629,7 +3628,7 @@ FT_DECLARE(void *) ftdm_iterator_current(ftdm_iterator_t *iter)
return (void *)key;
case FTDM_ITERATOR_CHANS:
ftdm_assert_return(iter->pvt.chaniter.index, NULL, "channel iterator index cannot be zero!\n");
ftdm_assert_return(iter->pvt.chaniter.index > iter->pvt.chaniter.span->chan_count, NULL, "channel iterator index bigger than span chan count!\n");
ftdm_assert_return(iter->pvt.chaniter.index <= iter->pvt.chaniter.span->chan_count, NULL, "channel iterator index bigger than span chan count!\n");
return iter->pvt.chaniter.span->channels[iter->pvt.chaniter.index];
default:
break;
@ -3652,6 +3651,7 @@ FT_DECLARE(ftdm_status_t) ftdm_iterator_free(ftdm_iterator_t *iter)
}
ftdm_assert_return(iter->type, FTDM_FAIL, "Cannot free invalid iterator\n");
ftdm_log(FTDM_LOG_DEBUG, "Freeing iterator %p\n", iter);
ftdm_safe_free(iter);
return FTDM_SUCCESS;