Freeciv-3.3
Loading...
Searching...
No Matches
fcdb.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2005 - M.C. Kaufman
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22/* utility */
23#include "fcintl.h"
24#include "log.h"
25#include "md5.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "connection.h"
31#include "packets.h"
32
33/* server */
34#include "connecthand.h"
35#include "notify.h"
36#include "sernet.h"
37#include "srv_main.h"
38
39/* server/scripting */
40#ifdef HAVE_FCDB
41#include "script_fcdb.h"
42#endif /* HAVE_FCDB */
43
44#include "fcdb.h"
45
46/* If HAVE_FCDB is set, the freeciv database module is compiled. Else only
47 * some dummy functions are defiend. */
48#ifdef HAVE_FCDB
49
51 AOS_DEFAULT, /* Internal default, currently not used */
52 AOS_FILE, /* Read from config file */
53 AOS_SET /* Set, currently not used */
54};
55
56struct fcdb_option {
58 char *value;
59};
60
61#define SPECHASH_TAG fcdb_option
62#define SPECHASH_ASTR_KEY_TYPE
63#define SPECHASH_IDATA_TYPE struct fcdb_option *
64#include "spechash.h"
65#define fcdb_option_hash_data_iterate(phash, data) \
66 TYPED_HASH_DATA_ITERATE(struct fcdb_option *, phash, data)
67#define fcdb_option_hash_data_iterate_end HASH_DATA_ITERATE_END
68#define fcdb_option_hash_keys_iterate(phash, key) \
69 TYPED_HASH_KEYS_ITERATE(char *, phash, key)
70#define fcdb_option_hash_keys_iterate_end HASH_KEYS_ITERATE_END
71#define fcdb_option_hash_iterate(phash, key, data) \
72 TYPED_HASH_ITERATE(char *, struct fcdb_option *, phash, key, data)
73#define fcdb_option_hash_iterate_end HASH_ITERATE_END
74
76
77char *fcdb_script = NULL;
78
79static bool fcdb_set_option(const char *key, const char *value,
81static bool fcdb_load_config(const char *filename);
82
83
84/************************************************************************/
88static bool fcdb_set_option(const char *key, const char *value,
90{
91 struct fcdb_option *oldopt = NULL;
92 bool removed;
93
94 if (value != NULL) {
95 struct fcdb_option *newopt = fc_malloc(sizeof(*newopt));
96
97 newopt->value = fc_strdup(value);
98 newopt->source = source;
100 NULL, &oldopt);
101 } else {
103 }
104
105 if (removed) {
106 /* Overwritten/removed an existing value */
108 FC_FREE(oldopt->value);
110 }
111
112 return TRUE;
113}
114
115/************************************************************************/
120static bool fcdb_load_config(const char *filename)
121{
122 struct section_file *secfile;
123 const char *val;
124
125 fc_assert_ret_val(NULL != filename, FALSE);
126
127 if (!(secfile = secfile_load(filename, FALSE))) {
128 log_error(_("Cannot load fcdb config file '%s':\n%s"), filename,
129 secfile_error());
130 return FALSE;
131 }
132
133 val = secfile_lookup_str_default(secfile, NULL, "meta.lua");
134 if (val != NULL) {
135 fcdb_script = fc_strdup(val);
136 }
137
139 "fcdb")),
140 pentry) {
142 const char *value;
143#ifndef FREECIV_NDEBUG
145#endif /* FREECIV_NDEBUG */
146 entry_str_get(pentry, &value);
147
149
151 } else {
152 log_error("Value for '%s' in '%s' is not of string type, ignoring",
153 entry_name(pentry), filename);
154 }
156
157 /* FIXME: we could arrange to call secfile_check_unused() and have it
158 * complain about unused entries (e.g. those not in [fcdb]). */
159 secfile_destroy(secfile);
160
161 return TRUE;
162}
163
164/************************************************************************/
167bool fcdb_init(const char *conf_file)
168{
171
172 if (conf_file && strcmp(conf_file, "-")) {
174 return FALSE;
175 }
176 } else {
177 log_debug("No fcdb config file.");
178 }
179
181}
182
183/************************************************************************/
186const char *fcdb_option_get(const char *type)
187{
188 struct fcdb_option *opt;
189
191 return opt->value;
192 } else {
193 return NULL;
194 }
195}
196
197/************************************************************************/
200void fcdb_free(void)
201{
203
205 FC_FREE(popt->value);
206 FC_FREE(popt);
208
211}
212
213#else /* HAVE_FCDB */
214
215/************************************************************************/
218bool fcdb_init(const char *conf_file)
219{
220 return TRUE;
221}
222
223/************************************************************************/
226const char *fcdb_option_get(const char *type)
227{
228 return NULL;
229}
230
231/************************************************************************/
234void fcdb_free(void)
235{
236 return;
237}
238#endif /* HAVE_FCDB */
char * incite_cost
Definition comments.c:76
void fcdb_free(void)
Definition fcdb.c:234
bool fcdb_init(const char *conf_file)
Definition fcdb.c:218
const char * fcdb_option_get(const char *type)
Definition fcdb.c:226
#define _(String)
Definition fcintl.h:67
static GtkWidget * source
Definition gotodlg.c:58
GType type
Definition repodlgs.c:1313
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_debug(message,...)
Definition log.h:116
#define log_error(message,...)
Definition log.h:104
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:51
const char * secfile_error(void)
void secfile_destroy(struct section_file *secfile)
const struct entry_list * section_entries(const struct section *psection)
const char * entry_name(const struct entry *pentry)
bool entry_str_get(const struct entry *pentry, const char **value)
struct section * secfile_section_by_name(const struct section_file *secfile, const char *name)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
enum entry_type entry_type_get(const struct entry *pentry)
@ ENTRY_STR
#define entry_list_iterate_end
#define entry_list_iterate(entlist, pentry)
void script_fcdb_free(void)
bool script_fcdb_init(const char *fcdb_luafile)
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47