From dbe81551e66c82a4b0d1ceb19834cad9939f17fa Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Tue, 12 May 2020 13:24:13 +0200
Subject: [PATCH] Differentiate optional and non optional settings in
 config.inc

---
 inc/lektor/config.h   |  6 ++++--
 inc/lektor/config.inc |  4 ++--
 src/config.c          | 15 +++++++++++----
 src/reg.c             |  2 +-
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/inc/lektor/config.h b/inc/lektor/config.h
index afba36ba..7a2bf0fb 100644
--- a/inc/lektor/config.h
+++ b/inc/lektor/config.h
@@ -8,12 +8,14 @@
 /* Forward definition of the lkt_state structure */
 struct lkt_state;
 
-#define section(sct)    "\n[" sct "]\n"
-#define value(key, val) key " = " val "\n"
+#define section(sct)        "\n[" sct "]\n"
+#define value(key, val)     key " = " val "\n"
+#define value_opt(key, val) value(key, val)
 static const char *const lkt_default_config_file =
 #include <lektor/config.inc>
 ;
 #undef value
+#undef value_opt
 #undef section
 
 /* It is just an alias to the consecutive use of config_detect_file and
diff --git a/inc/lektor/config.inc b/inc/lektor/config.inc
index 35f4b1bf..fc0ba354 100644
--- a/inc/lektor/config.inc
+++ b/inc/lektor/config.inc
@@ -11,7 +11,7 @@ value("kara_dir",       "/home/kara")
 value("db_path",        "/home/kara/kara.db")
 
 section("repo")
-value("path",           "STATIC")
+value_opt("path",       "STATIC")
 value("load_function",  "load_repo_https")
 value("name",           "Kurisu")
 value("url",            "https://kurisu.iiens.net")
@@ -20,7 +20,7 @@ value("id_json",        "https://kurisu.iiens.net/api?id=%ld")
 value("id_kara",        "https://kurisu.iiens.net/download.php?id=%ld")
 
 section("player")
-value("path",           "STATIC")
+value_opt("path",       "STATIC")
 value("load_function",  "load_sdl2")
 value("autoclear",      "true")
 value("def_random",     "false")
diff --git a/src/config.c b/src/config.c
index 7fd1c905..4a59d05c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -139,9 +139,14 @@ load_module_by_name(struct lkt_state *srv, const char *name, void *mod)
 {
     char mod_path[PATH_MAX], mod_load[INI_MAX_LINE_LEN];
 
-    if (!database_config_get_text(srv->db, name, "path", mod_path, PATH_MAX) ||
-        !database_config_get_text(srv->db, name, "load_function", mod_load, INI_MAX_LINE_LEN)) {
-        LOG_ERROR("Module named %s is incomplete or is not defined in config file", name);
+    /* When, don't mind if its not here */
+    if (!database_config_get_text(srv->db, name, "path", mod_path, PATH_MAX)) {
+        LOG_WARN_SCT("CONFIG", "No setting 'path' in section '%s'", name);
+        mod_path[0] = '\0';
+    }
+
+    if (!database_config_get_text(srv->db, name, "load_function", mod_load, INI_MAX_LINE_LEN)) {
+        LOG_ERROR_SCT("CONFIG", "Module named %s is incomplete or is not defined in config file", name);
         return 1;
     }
 
@@ -152,7 +157,8 @@ inline static int
 validate_conf(volatile sqlite3 *db)
 {
     const char *section;
-#define section(_sct) section = _sct;
+#define section(_sct)   section = _sct;
+#define value_opt(name, value)
 #define value(name, value)                                                      \
     if (!database_config_exists(db, section, name)) {                           \
         LOG_ERROR_SCT("CONFIG", "Missing option \""name"\" in section \"%s\"",  \
@@ -162,6 +168,7 @@ validate_conf(volatile sqlite3 *db)
 #include <lektor/config.inc>
 #undef section
 #undef value
+#undef value_opt
 
     return 0;
 }
diff --git a/src/reg.c b/src/reg.c
index 69bc8afa..3a4546fd 100644
--- a/src/reg.c
+++ b/src/reg.c
@@ -17,7 +17,7 @@ reg_pick(const char *file, void **handle, const char *symbol)
         return NULL;
 
     /* Use the register instead of dlfcn? */
-    if (!file || STR_MATCH(file, "STATIC") || handle == NULL)
+    if (!file || file[0] == '\0' || STR_MATCH(file, "STATIC") || handle == NULL)
         goto use_reg;
 
     /* Use dlsym */
-- 
GitLab