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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMON_CONF_H
#define COMMON_CONF_H
#include "common/hercules.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) (struct config_t *config, FILE *stream);
void (*write) (const struct config_t *config, FILE *stream);
/* */
void (*set_options) (struct config_t *config, int options);
int (*get_options) (const struct config_t *config);
/* */
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 (*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
void libconfig_defaults(void);
#endif // HERCULES_CORE
HPShared struct libconfig_interface *libconfig;
#endif // COMMON_CONF_H
|