X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fconf.c;h=185e508a0b97bff9101f135df38514da1e8ffdd6;hb=3fbab274e9932e10d257e70fad310e00a4260d43;hp=4d9a0e695a3abb20bb01ff84d0eddd3352830444;hpb=5191e1cb38d24ebf5c180ac7911893ca8bc4031f;p=umurmur.git diff --git a/src/conf.c b/src/conf.c index 4d9a0e6..185e508 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010, Martin Johansson +/* Copyright (C) 2009-2010, Martin Johansson Copyright (C) 2005-2010, Thorvald Natvig All rights reserved. @@ -32,11 +32,7 @@ #include #include -#ifdef WRT_TARGET -#include -#else #include -#endif #include "types.h" #include "conf.h" @@ -47,21 +43,17 @@ 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 5000 +#define DEFAULT_MAX_BANDWIDTH 48000 #define DEFAULT_BINDPORT 64738 const char defaultconfig[] = DEFAULT_CONFIG; int 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) { + conffile = defaultconfig; + if (config_read_file(&configuration, conffile) != 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); @@ -135,7 +127,7 @@ const char *getStrConf(param_t param) return DEFAULT_WELCOME; } break; - case DEAFULT_CHANNEL: + case DEFAULT_CHANNEL: setting = config_lookup(&configuration, "default_channel"); if (!setting) return ""; @@ -190,25 +182,34 @@ int getIntConf(param_t param) 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) - return -1; - strncpy(chdesc->name, config_setting_get_string(setting), MAX_TEXT); + if (ret >= maxconfig || ret < 0 || setting == NULL) + return -1; /* Required */ + 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) - return -1; - strncpy(chdesc->parent, config_setting_get_string(setting), MAX_TEXT); + if (ret >= maxconfig || ret < 0 || setting == NULL) + return -1; /* Required */ + 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) - return -1; - strncpy(chdesc->description, config_setting_get_string(setting), MAX_TEXT); + if (ret >= maxconfig || ret < 0 || setting == NULL) /* Optional */ + chdesc->description = NULL; + else + chdesc->description = 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 */ + chdesc->noenter = false; + else + chdesc->noenter = config_setting_get_bool(setting); return 0; } @@ -216,19 +217,20 @@ int Conf_getNextChannel(conf_channel_t *chdesc, int index) 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; }