struct zap_io_interface {
const char *name;
+ zio_configure_span_t configure_span;
zio_configure_t configure;
zio_open_t open;
zio_close_t close;
#define ZIO_SIGNAL_CB_ARGS (zap_sigmsg_t *sigmsg)
#define ZIO_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event)
#define ZIO_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen)
-#define ZIO_CONFIGURE_ARGS (struct zap_io_interface *zio)
+#define ZIO_CONFIGURE_SPAN_ARGS (zap_span_t *span, const char *str, zap_chan_type_t type, char *name, char *number)
+#define ZIO_CONFIGURE_ARGS (const char *category, const char *var, const char *val, int lineno)
#define ZIO_OPEN_ARGS (zap_channel_t *zchan)
#define ZIO_CLOSE_ARGS (zap_channel_t *zchan)
#define ZIO_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj)
typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ;
typedef zap_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ;
typedef zap_status_t (*zio_codec_t) ZIO_CODEC_ARGS ;
+typedef zap_status_t (*zio_configure_span_t) ZIO_CONFIGURE_SPAN_ARGS ;
typedef zap_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ;
typedef zap_status_t (*zio_open_t) ZIO_OPEN_ARGS ;
typedef zap_status_t (*zio_close_t) ZIO_CLOSE_ARGS ;
#define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS
#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS
#define ZIO_CODEC_FUNCTION(name) zap_status_t name ZIO_CODEC_ARGS
+#define ZIO_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_ARGS
#define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS
#define ZIO_OPEN_FUNCTION(name) zap_status_t name ZIO_OPEN_ARGS
#define ZIO_CLOSE_FUNCTION(name) zap_status_t name ZIO_CLOSE_ARGS
#define ZIO_READ_FUNCTION(name) zap_status_t name ZIO_READ_ARGS
#define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS
-#define ZIO_CONFIGURE_MUZZLE assert(zio != NULL)
+#define ZIO_CONFIGURE_SPAN_MUZZLE assert(zio != NULL)
#define ZIO_OPEN_MUZZLE assert(zchan != NULL)
#define ZIO_CLOSE_MUZZLE assert(zchan != NULL)
#define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL)
}
}
-
void zap_config_close_file(zap_config_t *cfg)
{
zap_io_interface_t *zt_interface;
} interfaces;
+
+static uint32_t load_config(zap_io_interface_t *zio)
+{
+ char cfg_name[256];
+ zap_config_t cfg;
+ char *var, *val;
+ int catno = -1;
+ zap_span_t *span = NULL;
+ int new_span = 0;
+ unsigned configured = 0, d = 0;
+ char name[80] = "";
+ char number[25] = "";
+
+ assert(zio != NULL);
+ snprintf(cfg_name, sizeof(cfg_name), "%s.conf", zio->name);
+
+ zap_log(ZAP_LOG_DEBUG, "configuring %s\n", zio->name);
+
+ if (!zap_config_open_file(&cfg, cfg_name)) {
+ return ZAP_FAIL;
+ }
+
+ while (zap_config_next_pair(&cfg, &var, &val)) {
+ if (!strcasecmp(cfg.category, "span")) {
+ if (cfg.catno != catno) {
+ zap_log(ZAP_LOG_DEBUG, "found config for span\n");
+ catno = cfg.catno;
+ new_span = 1;
+ span = NULL;
+ }
+
+ if (new_span) {
+ if (!strcasecmp(var, "enabled") && ! zap_true(val)) {
+ zap_log(ZAP_LOG_DEBUG, "span (disabled)\n");
+ } else {
+ if (zap_span_create(zio, &span) == ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id);
+ } else {
+ zap_log(ZAP_LOG_CRIT, "failure creating span\n");
+ span = NULL;
+ }
+ }
+ new_span = 0;
+ continue;
+ }
+
+ if (!span) {
+ continue;
+ }
+
+ zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val);
+
+ if (!strcasecmp(var, "enabled")) {
+ zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n");
+ } else if (!strcasecmp(var, "trunk_type")) {
+ span->trunk_type = zap_str2zap_trunk_type(val);
+ zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
+ } else if (!strcasecmp(var, "name")) {
+ if (!strcasecmp(val, "undef")) {
+ *name = '\0';
+ } else {
+ zap_copy_string(name, val, sizeof(name));
+ }
+ } else if (!strcasecmp(var, "number")) {
+ if (!strcasecmp(val, "undef")) {
+ *number = '\0';
+ } else {
+ zap_copy_string(number, val, sizeof(number));
+ }
+ } else if (!strcasecmp(var, "fxo-channel")) {
+ if (span->trunk_type == ZAP_TRUNK_NONE) {
+ span->trunk_type = ZAP_TRUNK_FXO;
+ zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
+ }
+ if (span->trunk_type == ZAP_TRUNK_FXO) {
+ configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number);
+ } else {
+ zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n");
+ }
+ } else if (!strcasecmp(var, "fxs-channel")) {
+ if (span->trunk_type == ZAP_TRUNK_NONE) {
+ span->trunk_type = ZAP_TRUNK_FXS;
+ zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
+ }
+ if (span->trunk_type == ZAP_TRUNK_FXS) {
+ configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number);
+ } else {
+ zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n");
+ }
+ } else if (!strcasecmp(var, "b-channel")) {
+ configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number);
+ } else if (!strcasecmp(var, "d-channel")) {
+ if (d) {
+ zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n");
+ } else {
+ zap_chan_type_t qtype;
+ if (!strncasecmp(val, "lapd:", 5)) {
+ qtype = ZAP_CHAN_TYPE_DQ931;
+ val += 5;
+ } else {
+ qtype = ZAP_CHAN_TYPE_DQ921;
+ }
+ configured += zio->configure_span(span, val, qtype, name, number);
+ d++;
+ }
+ }
+ } else if (zio->configure) {
+ zio->configure(cfg.category, var, val, cfg.lineno);
+ } else {
+ zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val);
+ }
+ }
+ zap_config_close_file(&cfg);
+
+ zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured);
+
+ return configured;
+}
+
zap_status_t zap_global_init(void)
{
zap_config_t cfg;
zap_mutex_unlock(globals.mutex);
if (zio) {
- if (zio->configure(zio) == ZAP_SUCCESS) {
- configured++;
- }
+ configured += load_config(zio);
} else {
zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val);
}
return configured;
}
-static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type, char *name, char *number)
+static ZIO_CONFIGURE_FUNCTION(wanpipe_configure)
+{
+ if (!strcasecmp(category, "defaults")) {
+ if (!strcasecmp(var, "codec_ms")) {
+ unsigned codec_ms = atoi(val);
+ if (codec_ms < 10 || codec_ms > 60) {
+ zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno);
+ } else {
+ wp_globals.codec_ms = codec_ms;
+ }
+ }
+ }
+
+ return ZAP_SUCCESS;
+}
+
+static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span)
{
int items, i;
char *mydata, *item_list[10];
}
if (!(sp && ch)) {
- zap_log(ZAP_LOG_ERROR, "Invalid input on line %d\n", cfg->lineno);
+ zap_log(ZAP_LOG_ERROR, "Invalid input\n");
continue;
}
return configured;
}
-static ZIO_CONFIGURE_FUNCTION(wanpipe_configure)
-{
- zap_config_t cfg;
- char *var, *val;
- int catno = -1;
- zap_span_t *span = NULL;
- int new_span = 0;
- unsigned configured = 0, d = 0;
- char name[80] = "";
- char number[25] = "";
-
- ZIO_CONFIGURE_MUZZLE;
-
- zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n");
- if (!zap_config_open_file(&cfg, "wanpipe.conf")) {
- return ZAP_FAIL;
- }
-
- while (zap_config_next_pair(&cfg, &var, &val)) {
- if (!strcasecmp(cfg.category, "defaults")) {
- if (!strcasecmp(var, "codec_ms")) {
- unsigned codec_ms = atoi(val);
- if (codec_ms < 10 || codec_ms > 60) {
- zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", cfg.lineno);
- } else {
- wp_globals.codec_ms = codec_ms;
- }
- }
- } else if (!strcasecmp(cfg.category, "span")) {
- if (cfg.catno != catno) {
- zap_log(ZAP_LOG_DEBUG, "found config for span\n");
- catno = cfg.catno;
- new_span = 1;
- span = NULL;
- }
-
- if (new_span) {
- if (!strcasecmp(var, "enabled") && ! zap_true(val)) {
- zap_log(ZAP_LOG_DEBUG, "span (disabled)\n");
- } else {
- if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) {
- zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id);
- } else {
- zap_log(ZAP_LOG_CRIT, "failure creating span\n");
- span = NULL;
- }
- }
- new_span = 0;
- continue;
- }
-
- if (!span) {
- continue;
- }
-
- zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val);
-
- if (!strcasecmp(var, "enabled")) {
- zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n");
- } else if (!strcasecmp(var, "trunk_type")) {
- span->trunk_type = zap_str2zap_trunk_type(val);
- zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
- } else if (!strcasecmp(var, "name")) {
- if (!strcasecmp(val, "undef")) {
- *name = '\0';
- } else {
- zap_copy_string(name, val, sizeof(name));
- }
- } else if (!strcasecmp(var, "number")) {
- if (!strcasecmp(val, "undef")) {
- *number = '\0';
- } else {
- zap_copy_string(number, val, sizeof(number));
- }
- } else if (!strcasecmp(var, "fxo-channel")) {
- if (span->trunk_type == ZAP_TRUNK_NONE) {
- span->trunk_type = ZAP_TRUNK_FXO;
- zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
- }
- if (span->trunk_type == ZAP_TRUNK_FXO) {
- configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO, name, number);
- } else {
- zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n");
- }
- } else if (!strcasecmp(var, "fxs-channel")) {
- if (span->trunk_type == ZAP_TRUNK_NONE) {
- span->trunk_type = ZAP_TRUNK_FXS;
- zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
- }
- if (span->trunk_type == ZAP_TRUNK_FXS) {
- configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS, name, number);
- } else {
- zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n");
- }
- } else if (!strcasecmp(var, "b-channel")) {
- configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B, name, number);
- } else if (!strcasecmp(var, "d-channel")) {
- if (d) {
- zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n");
- } else {
- zap_chan_type_t qtype;
- if (!strncasecmp(val, "lapd:", 5)) {
- qtype = ZAP_CHAN_TYPE_DQ931;
- val += 5;
- } else {
- qtype = ZAP_CHAN_TYPE_DQ921;
- }
- configured += wp_configure_channel(&cfg, val, span, qtype, name, number);
- d++;
- }
- }
- }
- }
- zap_config_close_file(&cfg);
-
- zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured);
-
- return configured ? ZAP_SUCCESS : ZAP_FAIL;
-}
-
static ZIO_OPEN_FUNCTION(wanpipe_open)
{
wp_globals.wink_ms = 150;
wp_globals.flash_ms = 750;
wanpipe_interface.name = "wanpipe";
- wanpipe_interface.configure = wanpipe_configure;
+ wanpipe_interface.configure_span = wanpipe_configure_span;
+ wanpipe_interface.configure = wanpipe_configure;
wanpipe_interface.open = wanpipe_open;
wanpipe_interface.close = wanpipe_close;
wanpipe_interface.command = wanpipe_command;