Better logging during channel configuration.
[umurmur.git] / src / conf.c
index e3d417c262b6c5004720d5c66ac5a4b18d1b2e4a..2a83e53e0712025f072a3587f4d29d3bb8ff86a1 100644 (file)
@@ -40,7 +40,6 @@
 
 static config_t configuration;
 
-#define DEFAULT_CONFIG "/etc/umurmur.conf"
 #define DEFAULT_WELCOME "Welcome to uMurmur!"
 #define DEFAULT_MAX_CLIENTS 10
 #define DEFAULT_MAX_BANDWIDTH 48000
@@ -59,6 +58,21 @@ void Conf_init(const char *conffile)
        }
 }
 
+bool_t Conf_ok(const char *conffile)
+{
+       bool_t rc = true;
+       config_init(&configuration);
+       if (conffile == NULL)
+               conffile = defaultconfig;
+       if (config_read_file(&configuration, conffile) != CONFIG_TRUE) {
+               fprintf(stderr, "Error in config file %s line %d: %s\n", conffile,
+                       config_error_line(&configuration), config_error_text(&configuration));
+               rc = false;
+       }
+       config_destroy(&configuration);
+       return rc;
+}
+
 void Conf_deinit()
 {
        config_destroy(&configuration);
@@ -235,6 +249,13 @@ int Conf_getNextChannel(conf_channel_t *chdesc, int index)
        else
                chdesc->description = config_setting_get_string(setting);
        
+       ret = snprintf(configstr, maxconfig, "channels.[%d].password", index);
+       setting = config_lookup(&configuration, configstr);
+       if (ret >= maxconfig || ret < 0 || setting == NULL) /* Optional */
+               chdesc->password = NULL;
+       else
+               chdesc->password = config_setting_get_string(setting);
+       
        ret = snprintf(configstr, maxconfig, "channels.[%d].noenter", index);
        setting = config_lookup(&configuration, configstr);
        if (ret >= maxconfig || ret < 0 || setting == NULL) /* Optional */