From bfee6f077e333955487f5f01afac2ef69d6d39be Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Apr 2021 11:22:46 +0300 Subject: [PATCH 06/46] Make it possible to use custom database.lua See osdn #41880 Signed-off-by: Marko Lindqvist --- doc/README.fcdb | 6 ++++++ server/fcdb.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/README.fcdb b/doc/README.fcdb index 595e356f7f..9885e04ad2 100644 --- a/doc/README.fcdb +++ b/doc/README.fcdb @@ -158,6 +158,12 @@ The script lives in data/database.lua in the source tree, and is installed to 'sysconfdir'; depending on the options given to 'configure' at build time, this may be a location like /usr/local/etc/freeciv/database.lua. +To use custom database.lua, give name of the file with its full path +in the conf file entry "lua" in [meta] section, e.g.: + + [meta] + lua="/etc/freeciv/local_database.lua" + The supplied version supports basic authentication against a SQLite or MySQL database; it supports configuration as shown in the following example (for MySQL; SQLite does not need all of these options). diff --git a/server/fcdb.c b/server/fcdb.c index 0befbf3a6e..810a6ddfd6 100644 --- a/server/fcdb.c +++ b/server/fcdb.c @@ -74,6 +74,8 @@ struct fcdb_option { struct fcdb_option_hash *fcdb_config = NULL; +char *fcdb_script = NULL; + static bool fcdb_set_option(const char *key, const char *value, enum fcdb_option_source source); static bool fcdb_load_config(const char *filename); @@ -118,6 +120,7 @@ static bool fcdb_set_option(const char *key, const char *value, static bool fcdb_load_config(const char *filename) { struct section_file *secfile; + const char *val; fc_assert_ret_val(NULL != filename, FALSE); @@ -127,6 +130,11 @@ static bool fcdb_load_config(const char *filename) return FALSE; } + val = secfile_lookup_str_default(secfile, NULL, "meta.lua"); + if (val != NULL) { + fcdb_script = fc_strdup(val); + } + entry_list_iterate(section_entries(secfile_section_by_name(secfile, "fcdb")), pentry) { @@ -138,6 +146,7 @@ static bool fcdb_load_config(const char *filename) entry_str_get(pentry, &value); fc_assert(entry_str_get_success); + fcdb_set_option(entry_name(pentry), value, AOS_FILE); } else { log_error("Value for '%s' in '%s' is not of string type, ignoring", @@ -168,7 +177,7 @@ bool fcdb_init(const char *conf_file) log_debug("No fcdb config file."); } - return script_fcdb_init(NULL); + return script_fcdb_init(fcdb_script); } /************************************************************************//** -- 2.30.2