summaryrefslogtreecommitdiff
path: root/src/common/conf.h
blob: 49257835df375909c18c2f39fd4b0fc1be473941 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams

#ifndef COMMON_CONF_H
#define COMMON_CONF_H

#include "common/cbasetypes.h"

#include <libconfig/libconfig.h>

/**
 * 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);
	/* */
	void (*set_auto_convert) (config_t *config, int flag);
	int (*get_auto_convert) (const 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);

	/* 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);
};

struct libconfig_interface *libconfig;

#ifdef HERCULES_CORE
void libconfig_defaults(void);
#endif // HERCULES_CORE

#endif // COMMON_CONF_H