From 39b9c4fc339ae5e5f7fb3ff00bb891306ab4a90b Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Wed, 20 Aug 2014 23:09:23 +0200 Subject: [PATCH] Make DAAP cache use and location configurable --- forked-daapd.conf | 2 ++ src/conffile.c | 1 + src/daap_cache.c | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/forked-daapd.conf b/forked-daapd.conf index 9260074b..3ec1c42d 100644 --- a/forked-daapd.conf +++ b/forked-daapd.conf @@ -11,6 +11,8 @@ general { admin_password = "unused" # Enable/disable IPv6 ipv6 = no + # Location of DAAP cache (comment the line to disable caching) + daapcache_path = "/var/cache/forked-daapd/daapcache.db" } # Library configuration diff --git a/src/conffile.c b/src/conffile.c index aa0b039f..7fc257b9 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -53,6 +53,7 @@ static cfg_opt_t sec_general[] = CFG_INT("db_pragma_synchronous", -1, CFGF_NONE), CFG_INT_CB("loglevel", E_LOG, CFGF_NONE, &cb_loglevel), CFG_BOOL("ipv6", cfg_false, CFGF_NONE), + CFG_STR("daapcache_path", NULL, CFGF_NONE), CFG_END() }; diff --git a/src/daap_cache.c b/src/daap_cache.c index c11c6685..3dedafe2 100644 --- a/src/daap_cache.c +++ b/src/daap_cache.c @@ -31,6 +31,7 @@ #include #include +#include "conffile.h" #include "logger.h" #include "httpd_daap.h" #include "db.h" @@ -74,7 +75,7 @@ static int g_initialized; // Global cache database handle static sqlite3 *g_db_hdl; -static char *g_db_path = "/home/espen/daapcache.db"; +static char *g_db_path; // After being triggered wait 5 seconds before rebuilding daapcache static struct timeval g_wait = { 5, 0 }; @@ -490,6 +491,9 @@ daapcache_trigger(void) { struct daapcache_command *cmd; + if (!g_initialized) + return; + cmd = (struct daapcache_command *)malloc(sizeof(struct daapcache_command)); if (!cmd) { @@ -513,6 +517,9 @@ daapcache_get(const char *query) struct evbuffer *evbuf; int ret; + if (!g_initialized) + return NULL; + command_init(&cmd); cmd.func = daapcache_query_get; @@ -532,6 +539,14 @@ daapcache_init(void) { int ret; + g_db_path = cfg_getstr(cfg_getsec(cfg, "general"), "daapcache_path"); + if (!g_db_path) + { + DPRINTF(E_LOG, L_DCACHE, "Cache disabled\n"); + g_initialized = 0; + return 0; + } + # if defined(__linux__) ret = pipe2(g_exit_pipe, O_CLOEXEC); # else