Remove provisions for multi-library support

It is now clear that multi-library support will not happen, so remove whatever
provisions were in the code for that.

It comes with a small change to the configuration file, too.

With this, DB schema version went to 9.
This commit is contained in:
Julien BLACHE 2010-03-19 19:06:47 +01:00
parent d6285eef40
commit 19b6780a3c
12 changed files with 63 additions and 145 deletions

View File

@ -10,10 +10,10 @@ general {
} }
# Library configuration # Library configuration
library "My Music" { library {
# Name of the library as displayed by the clients # Name of the library as displayed by the clients
# %l: library name ("My Music"), %h: hostname, %v: version # %h: hostname, %v: version
name = "%l on %h" name = "My Music on %h"
# TCP port to listen on. Default port is 3689 (daap) # TCP port to listen on. Default port is 3689 (daap)
port = 3689 port = 3689
# Password for the library. Optional. # Password for the library. Optional.

View File

@ -50,7 +50,7 @@ static cfg_opt_t sec_general[] =
/* library section structure */ /* library section structure */
static cfg_opt_t sec_library[] = static cfg_opt_t sec_library[] =
{ {
CFG_STR("name", "%l on %h", CFGF_NONE), CFG_STR("name", "My Music on %h", CFGF_NONE),
CFG_INT("port", 3689, CFGF_NONE), CFG_INT("port", 3689, CFGF_NONE),
CFG_STR("password", NULL, CFGF_NONE), CFG_STR("password", NULL, CFGF_NONE),
CFG_STR_LIST("directories", NULL, CFGF_NONE), CFG_STR_LIST("directories", NULL, CFGF_NONE),
@ -65,7 +65,7 @@ static cfg_opt_t sec_library[] =
static cfg_opt_t toplvl_cfg[] = static cfg_opt_t toplvl_cfg[] =
{ {
CFG_SEC("general", sec_general, CFGF_NONE), CFG_SEC("general", sec_general, CFGF_NONE),
CFG_SEC("library", sec_library, CFGF_MULTI | CFGF_TITLE), CFG_SEC("library", sec_library, CFGF_NONE),
CFG_END() CFG_END()
}; };
@ -101,7 +101,6 @@ static int
conffile_expand_libname(cfg_t *lib) conffile_expand_libname(cfg_t *lib)
{ {
char *libname; char *libname;
const char *title;
char *hostname; char *hostname;
char *s; char *s;
char *d; char *d;
@ -109,7 +108,6 @@ conffile_expand_libname(cfg_t *lib)
struct utsname sysinfo; struct utsname sysinfo;
size_t len; size_t len;
size_t olen; size_t olen;
size_t titlelen;
size_t hostlen; size_t hostlen;
size_t verlen; size_t verlen;
int ret; int ret;
@ -122,8 +120,6 @@ conffile_expand_libname(cfg_t *lib)
return 0; return 0;
/* Grab what we need */ /* Grab what we need */
title = cfg_title(lib);
ret = uname(&sysinfo); ret = uname(&sysinfo);
if (ret != 0) if (ret != 0)
{ {
@ -133,7 +129,6 @@ conffile_expand_libname(cfg_t *lib)
else else
hostname = sysinfo.nodename; hostname = sysinfo.nodename;
titlelen = strlen(title);
hostlen = strlen(hostname); hostlen = strlen(hostname);
verlen = strlen(VERSION); verlen = strlen(VERSION);
@ -154,10 +149,6 @@ conffile_expand_libname(cfg_t *lib)
len += hostlen; len += hostlen;
break; break;
case 'l':
len += titlelen;
break;
case 'v': case 'v':
len += verlen; len += verlen;
break; break;
@ -191,11 +182,6 @@ conffile_expand_libname(cfg_t *lib)
d += hostlen; d += hostlen;
break; break;
case 'l':
strcat(d, title);
d += titlelen;
break;
case 'v': case 'v':
strcat(d, VERSION); strcat(d, VERSION);
d += verlen; d += verlen;
@ -225,12 +211,6 @@ int
conffile_load(char *file) conffile_load(char *file)
{ {
cfg_t *lib; cfg_t *lib;
int nlib;
int *libports;
int libport;
int error;
int i;
int j;
int ret; int ret;
cfg = cfg_init(toplvl_cfg, CFGF_NONE); cfg = cfg_init(toplvl_cfg, CFGF_NONE);
@ -241,89 +221,39 @@ conffile_load(char *file)
{ {
DPRINTF(E_FATAL, L_CONF, "Could not open config file %s\n", file); DPRINTF(E_FATAL, L_CONF, "Could not open config file %s\n", file);
cfg_free(cfg); goto out_fail;
return -1;
} }
else if (ret == CFG_PARSE_ERROR) else if (ret == CFG_PARSE_ERROR)
{ {
DPRINTF(E_FATAL, L_CONF, "Parse error in config file %s\n", file); DPRINTF(E_FATAL, L_CONF, "Parse error in config file %s\n", file);
cfg_free(cfg); goto out_fail;
return -1;
} }
nlib = cfg_size(cfg, "library"); lib = cfg_getsec(cfg, "library");
DPRINTF(E_INFO, L_CONF, "%d music libraries configured\n", nlib); if (cfg_size(lib, "directories") == 0)
libports = (int *)malloc(nlib * sizeof(int));
memset(libports, 0, (nlib * sizeof(int)));
error = 0;
for (i = 0; i < nlib; i++)
{ {
lib = cfg_getnsec(cfg, "library", i); DPRINTF(E_FATAL, L_CONF, "No directories specified for library\n");
libport = cfg_getint(lib, "port");
error = ((libport > 65535) || (libport < 1024)); goto out_fail;
if (error)
{
DPRINTF(E_FATAL, L_CONF, "Invalid port number for library '%s', must be between 1024 and 65535\n",
cfg_title(lib));
break;
}
/* Check libraries ports */
for (j = 0; j < i; j++)
{
error = (libports[j] == libport);
if (error)
break;
}
if (error)
{
DPRINTF(E_FATAL, L_CONF, "Port collision for library '%s' and library '%s'\n",
cfg_title(cfg_getnsec(cfg, "library", j)), cfg_title(lib));
DPRINTF(E_FATAL, L_CONF, "Port numbers must be unique accross all libraries\n");
break;
}
libports[i] = libport;
error = (cfg_size(lib, "directories") == 0);
if (error)
{
DPRINTF(E_FATAL, L_CONF, "No directories specified for library '%s'\n",
cfg_title(lib));
break;
}
/* Do keyword expansion on library names */
ret = conffile_expand_libname(lib);
if (ret != 0)
{
DPRINTF(E_FATAL, L_CONF, "Could not expand library name\n");
free(libports);
cfg_free(cfg);
return -1;
}
} }
free(libports); /* Do keyword expansion on library names */
ret = conffile_expand_libname(lib);
if (error) if (ret != 0)
{ {
cfg_free(cfg); DPRINTF(E_FATAL, L_CONF, "Could not expand library name\n");
return -1; goto out_fail;
} }
return 0; return 0;
out_fail:
cfg_free(cfg);
return -1;
} }
void void

View File

@ -230,7 +230,6 @@ static struct col_type_map wi_cols_map[] =
{ wi_offsetof(wd), DB_TYPE_INT }, { wi_offsetof(wd), DB_TYPE_INT },
{ wi_offsetof(cookie), DB_TYPE_INT }, { wi_offsetof(cookie), DB_TYPE_INT },
{ wi_offsetof(path), DB_TYPE_STRING }, { wi_offsetof(path), DB_TYPE_STRING },
{ wi_offsetof(libidx), DB_TYPE_INT },
}; };
static __thread sqlite3 *hdl; static __thread sqlite3 *hdl;
@ -2842,12 +2841,12 @@ db_watch_clear(void)
int int
db_watch_add(struct watch_info *wi) db_watch_add(struct watch_info *wi)
{ {
#define Q_TMPL "INSERT INTO inotify (wd, cookie, path, libidx) VALUES (%d, 0, '%q', %d);" #define Q_TMPL "INSERT INTO inotify (wd, cookie, path) VALUES (%d, 0, '%q');"
char *query; char *query;
char *errmsg; char *errmsg;
int ret; int ret;
query = sqlite3_mprintf(Q_TMPL, wi->wd, wi->path, wi->libidx); query = sqlite3_mprintf(Q_TMPL, wi->wd, wi->path);
if (!query) if (!query)
{ {
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n"); DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
@ -3479,8 +3478,7 @@ db_perthread_deinit(void)
"CREATE TABLE IF NOT EXISTS inotify (" \ "CREATE TABLE IF NOT EXISTS inotify (" \
" wd INTEGER PRIMARY KEY NOT NULL," \ " wd INTEGER PRIMARY KEY NOT NULL," \
" cookie INTEGER NOT NULL," \ " cookie INTEGER NOT NULL," \
" path VARCHAR(4096) NOT NULL," \ " path VARCHAR(4096) NOT NULL" \
" libidx INTEGER NOT NULL" \
");" ");"
#define I_PATH \ #define I_PATH \
@ -3532,9 +3530,9 @@ db_perthread_deinit(void)
*/ */
#define SCHEMA_VERSION 8 #define SCHEMA_VERSION 9
#define Q_SCVER \ #define Q_SCVER \
"INSERT INTO admin (key, value) VALUES ('schema_version', '8');" "INSERT INTO admin (key, value) VALUES ('schema_version', '9');"
struct db_init_query { struct db_init_query {
char *query; char *query;

View File

@ -239,7 +239,6 @@ struct watch_info {
int wd; int wd;
char *path; char *path;
uint32_t cookie; uint32_t cookie;
int libidx;
}; };
#define wi_offsetof(field) offsetof(struct watch_info, field) #define wi_offsetof(field) offsetof(struct watch_info, field)

View File

@ -400,13 +400,13 @@ process_file(char *file, time_t mtime, off_t size, int compilation, int flags)
/* Thread: scan */ /* Thread: scan */
static int static int
check_compilation(int libidx, char *path) check_compilation(char *path)
{ {
cfg_t *lib; cfg_t *lib;
int ndirs; int ndirs;
int i; int i;
lib = cfg_getnsec(cfg, "library", libidx); lib = cfg_getsec(cfg, "library");
ndirs = cfg_size(lib, "compilations"); ndirs = cfg_size(lib, "compilations");
for (i = 0; i < ndirs; i++) for (i = 0; i < ndirs; i++)
@ -420,7 +420,7 @@ check_compilation(int libidx, char *path)
/* Thread: scan */ /* Thread: scan */
static void static void
process_directory(int libidx, char *path, int flags) process_directory(char *path, int flags)
{ {
struct stacked_dir *bulkstack; struct stacked_dir *bulkstack;
cfg_t *lib; cfg_t *lib;
@ -437,7 +437,7 @@ process_directory(int libidx, char *path, int flags)
int compilation; int compilation;
int ret; int ret;
lib = cfg_getnsec(cfg, "library", libidx); lib = cfg_getsec(cfg, "library");
if (flags & F_SCAN_BULK) if (flags & F_SCAN_BULK)
{ {
@ -468,7 +468,7 @@ process_directory(int libidx, char *path, int flags)
} }
/* Check for a compilation directory */ /* Check for a compilation directory */
compilation = check_compilation(libidx, path); compilation = check_compilation(path);
for (;;) for (;;)
{ {
@ -555,7 +555,6 @@ process_directory(int libidx, char *path, int flags)
if (!(flags & F_SCAN_RESCAN)) if (!(flags & F_SCAN_RESCAN))
{ {
wi.libidx = libidx;
wi.cookie = 0; wi.cookie = 0;
wi.path = path; wi.path = path;
@ -585,7 +584,6 @@ process_directory(int libidx, char *path, int flags)
return; return;
} }
wi.libidx = libidx;
wi.cookie = 0; wi.cookie = 0;
wi.path = path; wi.path = path;
@ -595,18 +593,18 @@ process_directory(int libidx, char *path, int flags)
/* Thread: scan */ /* Thread: scan */
static void static void
process_directories(int libidx, char *root, int flags) process_directories(char *root, int flags)
{ {
char *path; char *path;
process_directory(libidx, root, flags); process_directory(root, flags);
if (scan_exit) if (scan_exit)
return; return;
while ((path = pop_dir(&dirstack))) while ((path = pop_dir(&dirstack)))
{ {
process_directory(libidx, path, flags); process_directory(path, flags);
free(path); free(path);
@ -621,44 +619,38 @@ static void
bulk_scan(void) bulk_scan(void)
{ {
cfg_t *lib; cfg_t *lib;
int nlib;
int ndirs; int ndirs;
char *path; char *path;
char *deref; char *deref;
time_t start; time_t start;
int i; int i;
int j;
start = time(NULL); start = time(NULL);
playlists = NULL; playlists = NULL;
dirstack = NULL; dirstack = NULL;
nlib = cfg_size(cfg, "library"); lib = cfg_getsec(cfg, "library");
for (i = 0; i < nlib; i++)
ndirs = cfg_size(lib, "directories");
for (i = 0; i < ndirs; i++)
{ {
lib = cfg_getnsec(cfg, "library", i); path = cfg_getnstr(lib, "directories", i);
ndirs = cfg_size(lib, "directories"); deref = m_realpath(path);
for (j = 0; j < ndirs; j++) if (!deref)
{ {
path = cfg_getnstr(lib, "directories", j); DPRINTF(E_LOG, L_SCAN, "Skipping library directory %s, could not dereference: %s\n", path, strerror(errno));
deref = m_realpath(path); continue;
if (!deref)
{
DPRINTF(E_LOG, L_SCAN, "Skipping library directory %s, could not dereference: %s\n", path, strerror(errno));
continue;
}
process_directories(i, deref, F_SCAN_BULK);
free(deref);
if (scan_exit)
return;
} }
process_directories(deref, F_SCAN_BULK);
free(deref);
if (scan_exit)
return;
} }
if (playlists) if (playlists)
@ -835,7 +827,7 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
if (ie->mask & IN_CREATE) if (ie->mask & IN_CREATE)
{ {
process_directories(wi->libidx, path, flags); process_directories(path, flags);
if (dirstack) if (dirstack)
DPRINTF(E_LOG, L_SCAN, "WARNING: unhandled leftover directories\n"); DPRINTF(E_LOG, L_SCAN, "WARNING: unhandled leftover directories\n");
@ -922,7 +914,7 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie
} }
} }
compilation = check_compilation(wi->libidx, path); compilation = check_compilation(path);
process_file(file, sb.st_mtime, sb.st_size, compilation, 0); process_file(file, sb.st_mtime, sb.st_size, compilation, 0);
@ -1214,8 +1206,7 @@ kqueue_cb(int fd, short event, void *arg)
while ((path = pop_dir(&rescan))) while ((path = pop_dir(&rescan)))
{ {
/* FIXME: libidx for multi-library support */ process_directories(path, 0);
process_directories(0, path, 0);
free(path); free(path);

View File

@ -363,7 +363,7 @@ process_track_file(plist_t trk, char *base)
free(location); free(location);
if (!cfg_getbool(cfg_getnsec(cfg, "library", 0), "itunes_overrides")) if (!cfg_getbool(cfg_getsec(cfg, "library"), "itunes_overrides"))
return mfi_id; return mfi_id;
/* Override our metadata with what's provided by iTunes */ /* Override our metadata with what's provided by iTunes */

View File

@ -1157,7 +1157,7 @@ httpd_init(void)
goto evhttp_fail; goto evhttp_fail;
} }
port = cfg_getint(cfg_getnsec(cfg, "library", 0), "port"); port = cfg_getint(cfg_getsec(cfg, "library"), "port");
/* evhttp doesn't support IPv6 yet, so this is expected to fail */ /* evhttp doesn't support IPv6 yet, so this is expected to fail */
bindv6 = evhttp_bind_socket(evhttpd, "::", port); bindv6 = evhttp_bind_socket(evhttpd, "::", port);

View File

@ -980,7 +980,7 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
/* We don't support updates atm */ /* We don't support updates atm */
supports_update = 0; supports_update = 0;
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
passwd = cfg_getstr(lib, "password"); passwd = cfg_getstr(lib, "password");
name = cfg_getstr(lib, "name"); name = cfg_getstr(lib, "name");
@ -1260,7 +1260,7 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
if (!s) if (!s)
return; return;
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
name = cfg_getstr(lib, "name"); name = cfg_getstr(lib, "name");
namelen = strlen(name); namelen = strlen(name);
@ -2652,7 +2652,7 @@ daap_request(struct evhttp_request *req)
} }
/* Check authentication */ /* Check authentication */
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
passwd = cfg_getstr(lib, "password"); passwd = cfg_getstr(lib, "password");
/* No authentication for these URIs */ /* No authentication for these URIs */

View File

@ -276,7 +276,7 @@ rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
songcount = db_files_get_count(); songcount = db_files_get_count();
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
library = cfg_getstr(lib, "name"); library = cfg_getstr(lib, "name");
/* We'd use mxmlNewXML(), but then we can't put any attributes /* We'd use mxmlNewXML(), but then we can't put any attributes
@ -872,7 +872,7 @@ rsp_request(struct evhttp_request *req)
} }
/* Check authentication */ /* Check authentication */
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
passwd = cfg_getstr(lib, "password"); passwd = cfg_getstr(lib, "password");
if (passwd) if (passwd)
{ {

View File

@ -242,7 +242,7 @@ register_services(char *ffid, int no_rsp, int no_daap)
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
libname = cfg_getstr(lib, "name"); libname = cfg_getstr(lib, "name");
hash = djb_hash(libname, strlen(libname)); hash = djb_hash(libname, strlen(libname));

View File

@ -820,7 +820,7 @@ remote_pairing_init(void)
goto mdns_browse_fail; goto mdns_browse_fail;
} }
libname = cfg_getstr(cfg_getnsec(cfg, "library", 0), "name"); libname = cfg_getstr(cfg_getsec(cfg, "library"), "name");
libhash = murmur_hash64(libname, strlen(libname), 0); libhash = murmur_hash64(libname, strlen(libname), 0);
#ifdef USE_EVENTFD #ifdef USE_EVENTFD

View File

@ -531,7 +531,7 @@ transcode_needed(struct evkeyvalq *headers, char *file_codectype)
DPRINTF(E_DBG, L_XCODE, "Determining transcoding status for codectype %s\n", file_codectype); DPRINTF(E_DBG, L_XCODE, "Determining transcoding status for codectype %s\n", file_codectype);
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getsec(cfg, "library");
size = cfg_size(lib, "no_transcode"); size = cfg_size(lib, "no_transcode");
if (size > 0) if (size > 0)