提交 ab285ace authored 作者: Stefan Knoblich's avatar Stefan Knoblich

FreeTDM: Improve error checking and logging in load_config(), add FTDM_SPAN_IS_DIGITAL() helper.

Output the current trunk_type in "add X-channel vs. trunk_type" error messages and
check this for B-/D-channels too.

ISDN (= digital) spans need to have a trunk_type set before adding channels,
bail out early with an error message (actually two) if this is not the case.

(Adding channels should really be moved out of the parsing loop, to catch
 certain types of errors easier.)
Signed-off-by: 's avatarStefan Knoblich <stkn@openisdn.net>
上级 eb7e640b
...@@ -4764,7 +4764,7 @@ static ftdm_status_t load_config(void) ...@@ -4764,7 +4764,7 @@ static ftdm_status_t load_config(void)
configured += chans_configured; configured += chans_configured;
} }
} else { } else {
ftdm_log(FTDM_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); ftdm_log(FTDM_LOG_WARNING, "Cannot add FXO channels to a %s trunk!\n", ftdm_trunk_type2str(span->trunk_type));
} }
} else if (!strcasecmp(var, "fxs-channel")) { } else if (!strcasecmp(var, "fxs-channel")) {
if (span->trunk_type == FTDM_TRUNK_NONE) { if (span->trunk_type == FTDM_TRUNK_NONE) {
...@@ -4780,7 +4780,7 @@ static ftdm_status_t load_config(void) ...@@ -4780,7 +4780,7 @@ static ftdm_status_t load_config(void)
configured += chans_configured; configured += chans_configured;
} }
} else { } else {
ftdm_log(FTDM_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); ftdm_log(FTDM_LOG_WARNING, "Cannot add FXS channels to a %s trunk!\n", ftdm_trunk_type2str(span->trunk_type));
} }
} else if (!strcasecmp(var, "em-channel")) { } else if (!strcasecmp(var, "em-channel")) {
if (span->trunk_type == FTDM_TRUNK_NONE) { if (span->trunk_type == FTDM_TRUNK_NONE) {
...@@ -4796,19 +4796,33 @@ static ftdm_status_t load_config(void) ...@@ -4796,19 +4796,33 @@ static ftdm_status_t load_config(void)
configured += chans_configured; configured += chans_configured;
} }
} else { } else {
ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a %s trunk!\n", ftdm_trunk_type2str(span->trunk_type));
} }
} else if (!strcasecmp(var, "b-channel")) { } else if (!strcasecmp(var, "b-channel")) {
unsigned chans_configured = 0; if (span->trunk_type == FTDM_TRUNK_NONE) {
chan_config.type = FTDM_CHAN_TYPE_B; ftdm_log(FTDM_LOG_ERROR, "No trunk type specified in configuration file\n");
if (ftdm_configure_span_channels(span, val, &chan_config, &chans_configured) == FTDM_SUCCESS) { break;
configured += chans_configured;
} }
} else if (!strcasecmp(var, "d-channel")) { if (FTDM_SPAN_IS_DIGITAL(span)) {
if (d) { unsigned chans_configured = 0;
ftdm_log(FTDM_LOG_WARNING, "ignoring extra d-channel\n"); chan_config.type = FTDM_CHAN_TYPE_B;
if (ftdm_configure_span_channels(span, val, &chan_config, &chans_configured) == FTDM_SUCCESS) {
configured += chans_configured;
}
} else { } else {
ftdm_log(FTDM_LOG_WARNING, "Cannot add B channels to a %s trunk!\n", ftdm_trunk_type2str(span->trunk_type));
}
} else if (!strcasecmp(var, "d-channel")) {
if (span->trunk_type == FTDM_TRUNK_NONE) {
ftdm_log(FTDM_LOG_ERROR, "No trunk type specified in configuration file\n");
break;
}
if (FTDM_SPAN_IS_DIGITAL(span)) {
unsigned chans_configured = 0; unsigned chans_configured = 0;
if (d) {
ftdm_log(FTDM_LOG_WARNING, "ignoring extra d-channel\n");
continue;
}
if (!strncasecmp(val, "lapd:", 5)) { if (!strncasecmp(val, "lapd:", 5)) {
chan_config.type = FTDM_CHAN_TYPE_DQ931; chan_config.type = FTDM_CHAN_TYPE_DQ931;
val += 5; val += 5;
...@@ -4819,6 +4833,8 @@ static ftdm_status_t load_config(void) ...@@ -4819,6 +4833,8 @@ static ftdm_status_t load_config(void)
configured += chans_configured; configured += chans_configured;
} }
d++; d++;
} else {
ftdm_log(FTDM_LOG_WARNING, "Cannot add D channels to a %s trunk!\n", ftdm_trunk_type2str(span->trunk_type));
} }
} else if (!strcasecmp(var, "cas-channel")) { } else if (!strcasecmp(var, "cas-channel")) {
unsigned chans_configured = 0; unsigned chans_configured = 0;
......
...@@ -204,6 +204,15 @@ FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t) ...@@ -204,6 +204,15 @@ FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t)
(fchan)->span->trunk_type == FTDM_TRUNK_BRI || \ (fchan)->span->trunk_type == FTDM_TRUNK_BRI || \
(fchan)->span->trunk_type == FTDM_TRUNK_BRI_PTMP) (fchan)->span->trunk_type == FTDM_TRUNK_BRI_PTMP)
/*! \brief Test if a span is digital */
#define FTDM_SPAN_IS_DIGITAL(span) \
((span)->trunk_type == FTDM_TRUNK_E1 || \
(span)->trunk_type == FTDM_TRUNK_T1 || \
(span)->trunk_type == FTDM_TRUNK_J1 || \
(span)->trunk_type == FTDM_TRUNK_BRI || \
(span)->trunk_type == FTDM_TRUNK_BRI_PTMP)
/*! \brief Logging function prototype to be used for all FreeTDM logs /*! \brief Logging function prototype to be used for all FreeTDM logs
* you should use ftdm_global_set_logger to set your own logger * you should use ftdm_global_set_logger to set your own logger
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论