]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
change config engine to be more modular
authorAnthony Minessale <anthony.minessale@gmail.com>
Sat, 26 May 2007 04:09:46 +0000 (04:09 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Sat, 26 May 2007 04:09:46 +0000 (04:09 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@156 a93c3328-9c30-0410-af19-c9cd2b2d52af

libs/freetdm/src/include/openzap.h
libs/freetdm/src/include/zap_types.h
libs/freetdm/src/zap_config.c
libs/freetdm/src/zap_io.c
libs/freetdm/src/zap_wanpipe.c

index b3e0f51a4a071a58b6c84f7c506e65e57ee4c02e..db2c3ba5d422aaa7bdb3d8cbd309d7ca0d6b2cb3 100644 (file)
@@ -306,6 +306,7 @@ extern zap_logger_t zap_log;
 
 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;
index 38010121053318acf33aabe9973bed42aef62dcb..cf1b25cf7697ab0adee40fb9c63f620f04055006 100644 (file)
@@ -229,7 +229,8 @@ typedef struct zap_span zap_span_t;
 #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)
@@ -242,6 +243,7 @@ typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ;
 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 ;
@@ -255,6 +257,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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
@@ -263,7 +266,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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)
index eb65fb380970d3b71dfe838745d6719175e512d3..e4d4116244e5b3d93d07180a93d9753835f6c168 100644 (file)
@@ -91,7 +91,6 @@ int zap_config_open_file(zap_config_t *cfg, char *file_path)
        }
 }
 
-
 void zap_config_close_file(zap_config_t *cfg)
 {
 
index 6041844a0e6ebedaa50edbe7b6ca2d812f3eb14d..eff007f119cbae94d9be11f457387a7657eea2d7 100644 (file)
@@ -1228,6 +1228,125 @@ static struct {
        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;
@@ -1285,9 +1404,7 @@ zap_status_t zap_global_init(void)
                                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);
                                }
index 65385c11e4487ac628f685a3fc11994e270fbafe..fc14f0ad8f05da7cd95f9c44b04a04e3e44b78f0 100644 (file)
@@ -106,7 +106,23 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start,
        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];
@@ -132,7 +148,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa
                }
 
                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;
                }
 
@@ -173,126 +189,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa
        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) 
 {
 
@@ -592,7 +488,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio)
        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;