#include <stdlib.h>
#include <string.h>
-#ifdef WRT_TARGET
-#include <libconfig/libconfig.h>
-#else
#include <libconfig.h>
-#endif
#include "types.h"
#include "conf.h"
const char defaultconfig[] = DEFAULT_CONFIG;
-int Conf_init(const char *conffile)
+void Conf_init(const char *conffile)
{
- const char *conf;
-
config_init(&configuration);
if (conffile == NULL)
- conf = defaultconfig;
- else
- conf = conffile;
- if (config_read_file(&configuration, conf) != CONFIG_TRUE) {
- fprintf(stderr, "Error in config file %s: %s at line %d\n", conffile,
- config_error_text(&configuration), config_error_line(&configuration));
- exit(1);
+ conffile = defaultconfig;
+ if (config_read_file(&configuration, conffile) != CONFIG_TRUE) {
+ Log_fatal("Error in config file %s line %d: %s", conffile,
+ config_error_line(&configuration), config_error_text(&configuration));
}
- return 0;
}
void Conf_deinit()
return DEFAULT_WELCOME;
}
break;
- case DEAFULT_CHANNEL:
+ case DEFAULT_CHANNEL:
setting = config_lookup(&configuration, "default_channel");
if (!setting)
return "";
return "";
}
break;
+ case USERNAME:
+ setting = config_lookup(&configuration, "username");
+ if (!setting)
+ return "";
+ else {
+ if ((strsetting = config_setting_get_string(setting)) != NULL)
+ return strsetting;
+ else
+ return "";
+ }
+ break;
+ case GROUPNAME:
+ setting = config_lookup(&configuration, "groupname");
+ if (!setting)
+ return "";
+ else {
+ if ((strsetting = config_setting_get_string(setting)) != NULL)
+ return strsetting;
+ else
+ return "";
+ }
+ break;
default:
doAssert(false);
break;
int Conf_getNextChannel(conf_channel_t *chdesc, int index)
{
config_setting_t *setting = NULL;
- char configstr[64];
+ int maxconfig = 64, ret = 0;
+ char configstr[maxconfig];
- sprintf(configstr, "channels.[%d].name", index);
+ ret = snprintf(configstr, maxconfig, "channels.[%d].name", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL)
+ if (ret >= maxconfig || ret < 0 || setting == NULL)
return -1; /* Required */
- strncpy(chdesc->name, config_setting_get_string(setting), MAX_TEXT);
+ chdesc->name = config_setting_get_string(setting);
- sprintf(configstr, "channels.[%d].parent", index);
+ ret = snprintf(configstr, maxconfig, "channels.[%d].parent", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL)
+ if (ret >= maxconfig || ret < 0 || setting == NULL)
return -1; /* Required */
- strncpy(chdesc->parent, config_setting_get_string(setting), MAX_TEXT);
+ chdesc->parent = config_setting_get_string(setting);
- sprintf(configstr, "channels.[%d].description", index);
+ ret = snprintf(configstr, maxconfig, "channels.[%d].description", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL) /* Optional */
- strncpy(chdesc->description, "", MAX_TEXT);
+ if (ret >= maxconfig || ret < 0 || setting == NULL) /* Optional */
+ chdesc->description = NULL;
else
- strncpy(chdesc->description, config_setting_get_string(setting), MAX_TEXT);
+ chdesc->description = config_setting_get_string(setting);
- sprintf(configstr, "channels.[%d].noenter", index);
+ ret = snprintf(configstr, maxconfig, "channels.[%d].noenter", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL) /* Optional */
+ if (ret >= maxconfig || ret < 0 || setting == NULL) /* Optional */
chdesc->noenter = false;
else
chdesc->noenter = config_setting_get_bool(setting);
int Conf_getNextChannelLink(conf_channel_link_t *chlink, int index)
{
config_setting_t *setting = NULL;
- char configstr[64];
+ int maxconfig = 64, ret = 0;
+ char configstr[maxconfig];
- sprintf(configstr, "channel_links.[%d].source", index);
+ ret = snprintf(configstr, maxconfig, "channel_links.[%d].source", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL)
+ if (ret >= maxconfig || ret < 0 || setting == NULL)
return -1;
- strncpy(chlink->source, config_setting_get_string(setting), MAX_TEXT);
+ chlink->source = config_setting_get_string(setting);
- sprintf(configstr, "channel_links.[%d].destination", index);
+ ret = snprintf(configstr, maxconfig, "channel_links.[%d].destination", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL)
+ if (ret >= maxconfig || ret < 0 || setting == NULL)
return -1;
- strncpy(chlink->destination, config_setting_get_string(setting), MAX_TEXT);
+ chlink->destination = config_setting_get_string(setting);
return 0;
}