summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c8
-rw-r--r--src/common/conf.c288
-rw-r--r--src/common/conf.h154
-rw-r--r--src/common/showmsg.c7
-rw-r--r--src/common/showmsg.h7
-rw-r--r--src/common/socket.c7
-rw-r--r--src/common/socket.h5
-rw-r--r--src/common/sql.c1
8 files changed, 373 insertions, 104 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index d9c3262d7..f115c886e 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -616,8 +616,8 @@ CMDLINEARG(loadplugin)
* Reads the plugin configuration and loads the plugins as necessary.
*/
void hplugins_config_read(void) {
- config_t plugins_conf;
- config_setting_t *plist = NULL;
+ struct config_t plugins_conf;
+ struct config_setting_t *plist = NULL;
const char *config_filename = "conf/plugins.conf"; // FIXME hardcoded name
FILE *fp;
int i;
@@ -628,12 +628,12 @@ void hplugins_config_read(void) {
fclose(fp);
}
- if (libconfig->read_file(&plugins_conf, config_filename))
+ if (!libconfig->load_file(&plugins_conf, config_filename))
return;
plist = libconfig->lookup(&plugins_conf, "plugins_list");
for (i = 0; i < VECTOR_LENGTH(HPM->cmdline_load_plugins); i++) {
- config_setting_t *entry = libconfig->setting_add(plist, NULL, CONFIG_TYPE_STRING);
+ struct config_setting_t *entry = libconfig->setting_add(plist, NULL, CONFIG_TYPE_STRING);
config_setting_set_string(entry, VECTOR_INDEX(HPM->cmdline_load_plugins, i));
}
diff --git a/src/common/conf.c b/src/common/conf.c
index 3e8c08963..25f1013f5 100644
--- a/src/common/conf.c
+++ b/src/common/conf.c
@@ -23,6 +23,7 @@
#include "conf.h"
#include "common/showmsg.h" // ShowError
+#include "common/strlib.h" // safestrncpy
#include <libconfig/libconfig.h>
@@ -30,26 +31,39 @@
struct libconfig_interface libconfig_s;
struct libconfig_interface *libconfig;
-int conf_read_file(config_t *config, const char *config_filename) {
+/**
+ * Initializes 'config' and loads a configuration file.
+ *
+ * Shows error and destroys 'config' in case of failure.
+ * It is the caller's care to destroy 'config' in case of success.
+ *
+ * @param config The config file to initialize.
+ * @param config_filename The file to read.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_load_file(struct config_t *config, const char *config_filename)
+{
libconfig->init(config);
- if (!libconfig->read_file_src(config, config_filename)) {
+ if (libconfig->read_file_src(config, config_filename) != CONFIG_TRUE) {
ShowError("%s:%d - %s\n", config_error_file(config),
config_error_line(config), config_error_text(config));
libconfig->destroy(config);
- return 1;
+ return CONFIG_FALSE;
}
- return 0;
+ return CONFIG_TRUE;
}
//
// Functions to copy settings from libconfig/contrib
//
-void config_setting_copy_simple(config_setting_t *parent, const config_setting_t *src) {
+void config_setting_copy_simple(struct config_setting_t *parent, const struct config_setting_t *src)
+{
if (config_setting_is_aggregate(src)) {
libconfig->setting_copy_aggregate(parent, src);
- }
- else {
- config_setting_t *set;
+ } else {
+ struct config_setting_t *set;
if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL )
return;
@@ -73,8 +87,9 @@ void config_setting_copy_simple(config_setting_t *parent, const config_setting_t
}
}
-void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *src) {
- config_setting_t *set = NULL;
+void config_setting_copy_elem(struct config_setting_t *parent, const struct config_setting_t *src)
+{
+ struct config_setting_t *set = NULL;
if (config_setting_is_aggregate(src))
libconfig->setting_copy_aggregate(parent, src);
@@ -93,8 +108,9 @@ void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *
}
}
-void config_setting_copy_aggregate(config_setting_t *parent, const config_setting_t *src) {
- config_setting_t *newAgg;
+void config_setting_copy_aggregate(struct config_setting_t *parent, const struct config_setting_t *src)
+{
+ struct config_setting_t *newAgg;
int i, n;
if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL )
@@ -116,7 +132,8 @@ void config_setting_copy_aggregate(config_setting_t *parent, const config_settin
}
}
-int config_setting_copy(config_setting_t *parent, const config_setting_t *src) {
+int config_setting_copy(struct config_setting_t *parent, const struct config_setting_t *src)
+{
if (!config_setting_is_group(parent) && !config_setting_is_list(parent))
return CONFIG_FALSE;
@@ -128,14 +145,237 @@ int config_setting_copy(config_setting_t *parent, const config_setting_t *src) {
return CONFIG_TRUE;
}
+/**
+ * Converts the value of a setting that is type CONFIG_TYPE_BOOL to bool.
+ *
+ * @param setting The setting to read.
+ *
+ * @return The converted value.
+ * @retval false in case of failure.
+ */
+bool config_setting_get_bool_real(const struct config_setting_t *setting)
+{
+ if (setting == NULL || setting->type != CONFIG_TYPE_BOOL)
+ return false;
+
+ return setting->value.ival ? true : false;
+}
+
+/**
+ * Same as config_setting_lookup_bool, but uses bool instead of int.
+ *
+ * @param[in] setting The setting to read.
+ * @param[in] name The setting name to lookup.
+ * @param[out] value The output value.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_setting_lookup_bool_real(const struct config_setting_t *setting, const char *name, bool *value)
+{
+ struct config_setting_t *member = config_setting_get_member(setting, name);
+
+ if (!member)
+ return CONFIG_FALSE;
+
+ if (config_setting_type(member) != CONFIG_TYPE_BOOL)
+ return CONFIG_FALSE;
+
+ *value = config_setting_get_bool_real(member);
+
+ return CONFIG_TRUE;
+}
+
+/**
+ * Converts and returns a configuration that is CONFIG_TYPE_INT to unsigned int (uint32).
+ *
+ * @param setting The setting to read.
+ *
+ * @return The converted value.
+ * @retval 0 in case of failure.
+ */
+uint32 config_setting_get_uint32(const struct config_setting_t *setting)
+{
+ if (setting == NULL || setting->type != CONFIG_TYPE_INT)
+ return 0;
+
+ if (setting->value.ival < 0)
+ return 0;
+
+ return (uint32)setting->value.ival;
+}
+
+/**
+ * Looks up a configuration entry of type CONFIG_TYPE_INT and reads it as uint32.
+ *
+ * @param[in] setting The setting to read.
+ * @param[in] name The setting name to lookup.
+ * @param[out] value The output value.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_setting_lookup_uint32(const struct config_setting_t *setting, const char *name, uint32 *value)
+{
+ struct config_setting_t *member = config_setting_get_member(setting, name);
+
+ if (!member)
+ return CONFIG_FALSE;
+
+ if (config_setting_type(member) != CONFIG_TYPE_INT)
+ return CONFIG_FALSE;
+
+ *value = config_setting_get_uint32(member);
+
+ return CONFIG_TRUE;
+}
+
+/**
+ * Converts and returns a configuration that is CONFIG_TYPE_INT to uint16
+ *
+ * @param setting The setting to read.
+ *
+ * @return The converted value.
+ * @retval 0 in case of failure.
+ */
+uint16 config_setting_get_uint16(const struct config_setting_t *setting)
+{
+ if (setting == NULL || setting->type != CONFIG_TYPE_INT)
+ return 0;
+
+ if (setting->value.ival > UINT16_MAX)
+ return UINT16_MAX;
+ if (setting->value.ival < UINT16_MIN)
+ return UINT16_MIN;
+
+ return (uint16)setting->value.ival;
+}
+
+/**
+ * Looks up a configuration entry of type CONFIG_TYPE_INT and reads it as uint16.
+ *
+ * @param[in] setting The setting to read.
+ * @param[in] name The setting name to lookup.
+ * @param[out] value The output value.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_setting_lookup_uint16(const struct config_setting_t *setting, const char *name, uint16 *value)
+{
+ struct config_setting_t *member = config_setting_get_member(setting, name);
+
+ if (!member)
+ return CONFIG_FALSE;
+
+ if (config_setting_type(member) != CONFIG_TYPE_INT)
+ return CONFIG_FALSE;
+
+ *value = config_setting_get_uint16(member);
+
+ return CONFIG_TRUE;
+}
+
+/**
+ * Converts and returns a configuration that is CONFIG_TYPE_INT to int16
+ *
+ * @param setting The setting to read.
+ *
+ * @return The converted value.
+ * @retval 0 in case of failure.
+ */
+int16 config_setting_get_int16(const struct config_setting_t *setting)
+{
+ if (setting == NULL || setting->type != CONFIG_TYPE_INT)
+ return 0;
+
+ if (setting->value.ival > INT16_MAX)
+ return INT16_MAX;
+ if (setting->value.ival < INT16_MIN)
+ return INT16_MIN;
+
+ return (int16)setting->value.ival;
+}
+
+/**
+ * Looks up a configuration entry of type CONFIG_TYPE_INT and reads it as int16.
+ *
+ * @param[in] setting The setting to read.
+ * @param[in] name The setting name to lookup.
+ * @param[out] value The output value.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_setting_lookup_int16(const struct config_setting_t *setting, const char *name, int16 *value)
+{
+ struct config_setting_t *member = config_setting_get_member(setting, name);
+
+ if (!member)
+ return CONFIG_FALSE;
+
+ if (config_setting_type(member) != CONFIG_TYPE_INT)
+ return CONFIG_FALSE;
+
+ *value = config_setting_get_int16(member);
+
+ return CONFIG_TRUE;
+}
+
+/**
+ * Looks up a configuration entry of type CONFIG_TYPE_STRING inside a struct config_setting_t and copies it into a (non-const) char buffer.
+ *
+ * @param[in] setting The setting to read.
+ * @param[in] name The setting name to lookup.
+ * @param[out] out The output buffer.
+ * @param[in] out_size The size of the output buffer.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_setting_lookup_mutable_string(const struct config_setting_t *setting, const char *name, char *out, size_t out_size)
+{
+ const char *str = NULL;
+
+ if (libconfig->setting_lookup_string(setting, name, &str) == CONFIG_TRUE) {
+ safestrncpy(out, str, out_size);
+ return CONFIG_TRUE;
+ }
+
+ return CONFIG_FALSE;
+}
+
+/**
+ * Looks up a configuration entry of type CONFIG_TYPE_STRING inside a struct config_t and copies it into a (non-const) char buffer.
+ *
+ * @param[in] config The configuration to read.
+ * @param[in] name The setting name to lookup.
+ * @param[out] out The output buffer.
+ * @param[in] out_size The size of the output buffer.
+ *
+ * @retval CONFIG_TRUE in case of success.
+ * @retval CONFIG_FALSE in case of failure.
+ */
+int config_lookup_mutable_string(const struct config_t *config, const char *name, char *out, size_t out_size)
+{
+ const char *str = NULL;
+
+ if (libconfig->lookup_string(config, name, &str) == CONFIG_TRUE) {
+ safestrncpy(out, str, out_size);
+ return CONFIG_TRUE;
+ }
+
+ return CONFIG_FALSE;
+}
+
void libconfig_defaults(void) {
libconfig = &libconfig_s;
libconfig->read = config_read;
libconfig->write = config_write;
/* */
- libconfig->set_auto_convert = config_set_auto_convert;
- libconfig->get_auto_convert = config_get_auto_convert;
+ libconfig->set_options = config_set_options;
+ libconfig->get_options = config_get_options;
/* */
libconfig->read_string = config_read_string;
libconfig->read_file_src = config_read_file;
@@ -153,6 +393,7 @@ void libconfig_defaults(void) {
libconfig->setting_get_bool = config_setting_get_bool;
libconfig->setting_get_string = config_setting_get_string;
/* */
+ libconfig->setting_lookup = config_setting_lookup;
libconfig->setting_lookup_int = config_setting_lookup_int;
libconfig->setting_lookup_int64 = config_setting_lookup_int64;
libconfig->setting_lookup_float = config_setting_lookup_float;
@@ -193,7 +434,6 @@ void libconfig_defaults(void) {
libconfig->setting_set_hook = config_setting_set_hook;
/* */
libconfig->lookup = config_lookup;
- libconfig->lookup_from = config_lookup_from;
/* */
libconfig->lookup_int = config_lookup_int;
libconfig->lookup_int64 = config_lookup_int64;
@@ -201,9 +441,23 @@ void libconfig_defaults(void) {
libconfig->lookup_bool = config_lookup_bool;
libconfig->lookup_string = config_lookup_string;
/* those are custom and are from src/common/conf.c */
- libconfig->read_file = conf_read_file;
+ libconfig->load_file = config_load_file;
libconfig->setting_copy_simple = config_setting_copy_simple;
libconfig->setting_copy_elem = config_setting_copy_elem;
libconfig->setting_copy_aggregate = config_setting_copy_aggregate;
libconfig->setting_copy = config_setting_copy;
+
+ /* Functions to get different types */
+ libconfig->setting_get_bool_real = config_setting_get_bool_real;
+ libconfig->setting_get_uint32 = config_setting_get_uint32;
+ libconfig->setting_get_uint16 = config_setting_get_uint16;
+ libconfig->setting_get_int16 = config_setting_get_int16;
+
+ /* Functions to lookup different types */
+ libconfig->setting_lookup_int16 = config_setting_lookup_int16;
+ libconfig->setting_lookup_bool_real = config_setting_lookup_bool_real;
+ libconfig->setting_lookup_uint32 = config_setting_lookup_uint32;
+ libconfig->setting_lookup_uint16 = config_setting_lookup_uint16;
+ libconfig->setting_lookup_mutable_string = config_setting_lookup_mutable_string;
+ libconfig->lookup_mutable_string = config_lookup_mutable_string;
}
diff --git a/src/common/conf.h b/src/common/conf.h
index 19b13c51a..f2bfcac62 100644
--- a/src/common/conf.h
+++ b/src/common/conf.h
@@ -29,82 +29,94 @@
* The libconfig interface -- specially for plugins, but we enforce it throughout the core to be consistent
**/
struct libconfig_interface {
- int (*read) (config_t *config, FILE *stream);
- void (*write) (const config_t *config, FILE *stream);
+ int (*read) (struct config_t *config, FILE *stream);
+ void (*write) (const struct config_t *config, FILE *stream);
/* */
- void (*set_auto_convert) (config_t *config, int flag); // TODO: Replace with config_set_options
- int (*get_auto_convert) (const config_t *config); // TODO: Replace with config_get_options
+ void (*set_options) (struct config_t *config, int options);
+ int (*get_options) (const struct config_t *config);
/* */
- int (*read_string) (config_t *config, const char *str);
- int (*read_file_src) (config_t *config, const char *filename);
- int (*write_file) (config_t *config, const char *filename);
-
- void (*set_destructor) (config_t *config, void (*destructor)(void *));
- void (*set_include_dir) (config_t *config, const char *include_dir);
-
- void (*init) (config_t *config);
- void (*destroy) (config_t *config);
-
- int (*setting_get_int) (const config_setting_t *setting);
- long long (*setting_get_int64) (const config_setting_t *setting);
- double (*setting_get_float) (const config_setting_t *setting);
-
- int (*setting_get_bool) (const config_setting_t *setting);
-
- const char * (*setting_get_string) (const config_setting_t *setting);
-
- int (*setting_lookup_int) (const config_setting_t *setting, const char *name, int *value);
- int (*setting_lookup_int64) (const config_setting_t *setting, const char *name, long long *value);
- int (*setting_lookup_float) (const config_setting_t *setting, const char *name, double *value);
- int (*setting_lookup_bool) (const config_setting_t *setting, const char *name, int *value);
- int (*setting_lookup_string) (const config_setting_t *setting, const char *name, const char **value);
- int (*setting_set_int) (config_setting_t *setting ,int value);
- int (*setting_set_int64) (config_setting_t *setting, long long value);
- int (*setting_set_float) (config_setting_t *setting, double value);
- int (*setting_set_bool) (config_setting_t *setting, int value);
- int (*setting_set_string) (config_setting_t *setting, const char *value);
-
- int (*setting_set_format) (config_setting_t *setting, short format);
- short (*setting_get_format) (const config_setting_t *setting);
-
- int (*setting_get_int_elem) (const config_setting_t *setting, int idx);
- long long (*setting_get_int64_elem) (const config_setting_t *setting, int idx);
- double (*setting_get_float_elem) (const config_setting_t *setting, int idx);
- int (*setting_get_bool_elem) (const config_setting_t *setting, int idx);
- const char * (*setting_get_string_elem) (const config_setting_t *setting, int idx);
- config_setting_t * (*setting_set_int_elem) (config_setting_t *setting, int idx, int value);
- config_setting_t * (*setting_set_int64_elem) (config_setting_t *setting, int idx, long long value);
- config_setting_t * (*setting_set_float_elem) (config_setting_t *setting, int idx, double value);
- config_setting_t * (*setting_set_bool_elem) (config_setting_t *setting, int idx, int value);
- config_setting_t * (*setting_set_string_elem) (config_setting_t *setting, int idx, const char *value);
-
- int (*setting_index) (const config_setting_t *setting);
- int (*setting_length) (const config_setting_t *setting);
-
- config_setting_t * (*setting_get_elem) (const config_setting_t *setting, unsigned int idx);
- config_setting_t * (*setting_get_member) (const config_setting_t *setting, const char *name);
-
- config_setting_t * (*setting_add) (config_setting_t *parent, const char *name, int type);
- int (*setting_remove) (config_setting_t *parent, const char *name);
-
- int (*setting_remove_elem) (config_setting_t *parent, unsigned int idx);
- void (*setting_set_hook) (config_setting_t *setting, void *hook);
-
- config_setting_t * (*lookup) (const config_t *config, const char *filepath);
- config_setting_t * (*lookup_from) (config_setting_t *setting, const char *filepath);
- int (*lookup_int) (const config_t *config, const char *filepath, int *value);
- int (*lookup_int64) (const config_t *config, const char *filepath, long long *value);
- int (*lookup_float) (const config_t *config, const char *filepath, double *value);
- int (*lookup_bool) (const config_t *config, const char *filepath, int *value);
- int (*lookup_string) (const config_t *config, const char *filepath, const char **value);
+ int (*read_string) (struct config_t *config, const char *str);
+ int (*read_file_src) (struct config_t *config, const char *filename);
+ int (*write_file) (struct config_t *config, const char *filename);
+
+ void (*set_destructor) (struct config_t *config, void (*destructor)(void *));
+ void (*set_include_dir) (struct config_t *config, const char *include_dir);
+
+ void (*init) (struct config_t *config);
+ void (*destroy) (struct config_t *config);
+
+ int (*setting_get_int) (const struct config_setting_t *setting);
+ long long (*setting_get_int64) (const struct config_setting_t *setting);
+ double (*setting_get_float) (const struct config_setting_t *setting);
+
+ int (*setting_get_bool) (const struct config_setting_t *setting);
+
+ const char * (*setting_get_string) (const struct config_setting_t *setting);
+
+ struct config_setting_t * (*setting_lookup) (struct config_setting_t *setting, const char *name);
+ int (*setting_lookup_int) (const struct config_setting_t *setting, const char *name, int *value);
+ int (*setting_lookup_int64) (const struct config_setting_t *setting, const char *name, long long *value);
+ int (*setting_lookup_float) (const struct config_setting_t *setting, const char *name, double *value);
+ int (*setting_lookup_bool) (const struct config_setting_t *setting, const char *name, int *value);
+ int (*setting_lookup_string) (const struct config_setting_t *setting, const char *name, const char **value);
+ int (*setting_set_int) (struct config_setting_t *setting ,int value);
+ int (*setting_set_int64) (struct config_setting_t *setting, long long value);
+ int (*setting_set_float) (struct config_setting_t *setting, double value);
+ int (*setting_set_bool) (struct config_setting_t *setting, int value);
+ int (*setting_set_string) (struct config_setting_t *setting, const char *value);
+
+ int (*setting_set_format) (struct config_setting_t *setting, short format);
+ short (*setting_get_format) (const struct config_setting_t *setting);
+
+ int (*setting_get_int_elem) (const struct config_setting_t *setting, int idx);
+ long long (*setting_get_int64_elem) (const struct config_setting_t *setting, int idx);
+ double (*setting_get_float_elem) (const struct config_setting_t *setting, int idx);
+ int (*setting_get_bool_elem) (const struct config_setting_t *setting, int idx);
+ const char * (*setting_get_string_elem) (const struct config_setting_t *setting, int idx);
+ struct config_setting_t * (*setting_set_int_elem) (struct config_setting_t *setting, int idx, int value);
+ struct config_setting_t * (*setting_set_int64_elem) (struct config_setting_t *setting, int idx, long long value);
+ struct config_setting_t * (*setting_set_float_elem) (struct config_setting_t *setting, int idx, double value);
+ struct config_setting_t * (*setting_set_bool_elem) (struct config_setting_t *setting, int idx, int value);
+ struct config_setting_t * (*setting_set_string_elem) (struct config_setting_t *setting, int idx, const char *value);
+
+ int (*setting_index) (const struct config_setting_t *setting);
+ int (*setting_length) (const struct config_setting_t *setting);
+
+ struct config_setting_t * (*setting_get_elem) (const struct config_setting_t *setting, unsigned int idx);
+ struct config_setting_t * (*setting_get_member) (const struct config_setting_t *setting, const char *name);
+
+ struct config_setting_t * (*setting_add) (struct config_setting_t *parent, const char *name, int type);
+ int (*setting_remove) (struct config_setting_t *parent, const char *name);
+
+ int (*setting_remove_elem) (struct config_setting_t *parent, unsigned int idx);
+ void (*setting_set_hook) (struct config_setting_t *setting, void *hook);
+
+ struct config_setting_t * (*lookup) (const struct config_t *config, const char *filepath);
+ int (*lookup_int) (const struct config_t *config, const char *filepath, int *value);
+ int (*lookup_int64) (const struct config_t *config, const char *filepath, long long *value);
+ int (*lookup_float) (const struct config_t *config, const char *filepath, double *value);
+ int (*lookup_bool) (const struct config_t *config, const char *filepath, int *value);
+ int (*lookup_string) (const struct config_t *config, const char *filepath, const char **value);
/* those are custom and are from src/common/conf.c */
/* Functions to copy settings from libconfig/contrib */
- int (*read_file) (config_t *config, const char *config_filename);
- void (*setting_copy_simple) (config_setting_t *parent, const config_setting_t *src);
- void (*setting_copy_elem) (config_setting_t *parent, const config_setting_t *src);
- void (*setting_copy_aggregate) (config_setting_t *parent, const config_setting_t *src);
- int (*setting_copy) (config_setting_t *parent, const config_setting_t *src);
+ int (*load_file) (struct config_t *config, const char *config_filename);
+ void (*setting_copy_simple) (struct config_setting_t *parent, const struct config_setting_t *src);
+ void (*setting_copy_elem) (struct config_setting_t *parent, const struct config_setting_t *src);
+ void (*setting_copy_aggregate) (struct config_setting_t *parent, const struct config_setting_t *src);
+ int (*setting_copy) (struct config_setting_t *parent, const struct config_setting_t *src);
+ /* Functions to get other types */
+ bool (*setting_get_bool_real) (const struct config_setting_t *setting);
+ uint32 (*setting_get_uint32) (const struct config_setting_t *setting);
+ uint16 (*setting_get_uint16) (const struct config_setting_t *setting);
+ int16 (*setting_get_int16) (const struct config_setting_t *setting);
+
+ int (*setting_lookup_bool_real) (const struct config_setting_t *setting, const char *name, bool *value);
+ int (*setting_lookup_uint32) (const struct config_setting_t *setting, const char *name, uint32 *value);
+ int (*setting_lookup_uint16) (const struct config_setting_t *setting, const char *name, uint16 *value);
+ int (*setting_lookup_int16) (const struct config_setting_t *setting, const char *name, int16 *value);
+ int (*setting_lookup_mutable_string) (const struct config_setting_t *setting, const char *name, char *out, size_t out_size);
+ int (*lookup_mutable_string) (const struct config_t *config, const char *name, char *out, size_t out_size);
};
#ifdef HERCULES_CORE
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 956222a7d..4d4c72b42 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -23,11 +23,10 @@
#include "showmsg.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/core.h" //[Ind] - For SERVER_TYPE
#include "common/strlib.h" // StringBuf
-#include <libconfig/libconfig.h>
-
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> // atexit
@@ -799,8 +798,8 @@ void showmsg_showWarning(const char *string, ...)
vShowMessage_(MSG_WARNING, string, ap);
va_end(ap);
}
-void showmsg_showConfigWarning(config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3)));
-void showmsg_showConfigWarning(config_setting_t *config, const char *string, ...)
+void showmsg_showConfigWarning(struct config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3)));
+void showmsg_showConfigWarning(struct config_setting_t *config, const char *string, ...)
{
StringBuf buf;
va_list ap;
diff --git a/src/common/showmsg.h b/src/common/showmsg.h
index ed8776fb0..7b48d0df2 100644
--- a/src/common/showmsg.h
+++ b/src/common/showmsg.h
@@ -23,10 +23,11 @@
#include "common/hercules.h"
-#include <libconfig/libconfig.h>
-
#include <stdarg.h>
+/* Forward Declarations */
+struct config_setting_t;
+
// for help with the console colors look here:
// http://www.edoceo.com/liberum/?doc=printf-with-color
// some code explanation (used here):
@@ -118,7 +119,7 @@ struct showmsg_interface {
void (*showDebug) (const char *, ...) __attribute__((format(printf, 1, 2)));
void (*showError) (const char *, ...) __attribute__((format(printf, 1, 2)));
void (*showFatalError) (const char *, ...) __attribute__((format(printf, 1, 2)));
- void (*showConfigWarning) (config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3)));
+ void (*showConfigWarning) (struct config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3)));
};
/* the purpose of these macros is simply to not make calling them be an annoyance */
diff --git a/src/common/socket.c b/src/common/socket.c
index 740c07bdc..8b1ab3959 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -25,6 +25,7 @@
#include "common/HPM.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/db.h"
#include "common/memmgr.h"
#include "common/mmo.h"
@@ -1686,7 +1687,7 @@ bool socket_trusted_ip_check(uint32 ip)
* @param[in] groupname Current group name, for output/logging reasons.
* @return The amount of entries read, zero in case of errors.
*/
-int socket_net_config_read_sub(config_setting_t *t, struct s_subnet_vector *list, const char *filename, const char *groupname)
+int socket_net_config_read_sub(struct config_setting_t *t, struct s_subnet_vector *list, const char *filename, const char *groupname)
{
int i, len;
char ipbuf[64], maskbuf[64];
@@ -1722,11 +1723,11 @@ int socket_net_config_read_sub(config_setting_t *t, struct s_subnet_vector *list
*/
void socket_net_config_read(const char *filename)
{
- config_t network_config;
+ struct config_t network_config;
int i;
nullpo_retv(filename);
- if (libconfig->read_file(&network_config, filename)) {
+ if (!libconfig->load_file(&network_config, filename)) {
ShowError("LAN Support configuration file is not found: '%s'. This server won't be able to accept connections from any servers.\n", filename);
return;
}
diff --git a/src/common/socket.h b/src/common/socket.h
index e99278052..70fbc3492 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -22,7 +22,6 @@
#define COMMON_SOCKET_H
#include "common/hercules.h"
-#include "common/conf.h"
#include "common/db.h"
#ifdef WIN32
@@ -34,7 +33,9 @@
# include <sys/types.h>
#endif
+/* Forward Declarations */
struct hplugin_data_store;
+struct config_setting_t;
#define FIFOSIZE_SERVERLINK 256*1024
@@ -214,7 +215,7 @@ struct socket_interface {
uint32 (*lan_subnet_check) (uint32 ip, struct s_subnet *info);
bool (*allowed_ip_check) (uint32 ip);
bool (*trusted_ip_check) (uint32 ip);
- int (*net_config_read_sub) (config_setting_t *t, struct s_subnet_vector *list, const char *filename, const char *groupname);
+ int (*net_config_read_sub) (struct config_setting_t *t, struct s_subnet_vector *list, const char *filename, const char *groupname);
void (*net_config_read) (const char *filename);
};
diff --git a/src/common/sql.c b/src/common/sql.c
index f6280c436..b1e77e636 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -32,6 +32,7 @@
# include "common/winapi.h" // Needed before mysql.h
#endif
#include <mysql.h>
+#include <stdio.h>
#include <stdlib.h> // strtoul
void hercules_mysql_error_handler(unsigned int ecode);