diff --git a/forked-daapd.conf b/forked-daapd.conf index 584edd64..e16edb21 100644 --- a/forked-daapd.conf +++ b/forked-daapd.conf @@ -10,10 +10,10 @@ general { } # Library configuration -library "My Music" { +library { # Name of the library as displayed by the clients - # %l: library name ("My Music"), %h: hostname, %v: version - name = "%l on %h" + # %h: hostname, %v: version + name = "My Music on %h" # TCP port to listen on. Default port is 3689 (daap) port = 3689 # Password for the library. Optional. diff --git a/src/conffile.c b/src/conffile.c index d4052164..6ba28948 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -50,7 +50,7 @@ static cfg_opt_t sec_general[] = /* library section structure */ 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_STR("password", 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[] = { 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() }; @@ -101,7 +101,6 @@ static int conffile_expand_libname(cfg_t *lib) { char *libname; - const char *title; char *hostname; char *s; char *d; @@ -109,7 +108,6 @@ conffile_expand_libname(cfg_t *lib) struct utsname sysinfo; size_t len; size_t olen; - size_t titlelen; size_t hostlen; size_t verlen; int ret; @@ -122,8 +120,6 @@ conffile_expand_libname(cfg_t *lib) return 0; /* Grab what we need */ - title = cfg_title(lib); - ret = uname(&sysinfo); if (ret != 0) { @@ -133,7 +129,6 @@ conffile_expand_libname(cfg_t *lib) else hostname = sysinfo.nodename; - titlelen = strlen(title); hostlen = strlen(hostname); verlen = strlen(VERSION); @@ -154,10 +149,6 @@ conffile_expand_libname(cfg_t *lib) len += hostlen; break; - case 'l': - len += titlelen; - break; - case 'v': len += verlen; break; @@ -191,11 +182,6 @@ conffile_expand_libname(cfg_t *lib) d += hostlen; break; - case 'l': - strcat(d, title); - d += titlelen; - break; - case 'v': strcat(d, VERSION); d += verlen; @@ -225,12 +211,6 @@ int conffile_load(char *file) { cfg_t *lib; - int nlib; - int *libports; - int libport; - int error; - int i; - int j; int ret; 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); - cfg_free(cfg); - return -1; + goto out_fail; } else if (ret == CFG_PARSE_ERROR) { DPRINTF(E_FATAL, L_CONF, "Parse error in config file %s\n", file); - cfg_free(cfg); - return -1; + goto out_fail; } - nlib = cfg_size(cfg, "library"); + lib = cfg_getsec(cfg, "library"); - DPRINTF(E_INFO, L_CONF, "%d music libraries configured\n", nlib); - - libports = (int *)malloc(nlib * sizeof(int)); - memset(libports, 0, (nlib * sizeof(int))); - - error = 0; - for (i = 0; i < nlib; i++) + if (cfg_size(lib, "directories") == 0) { - lib = cfg_getnsec(cfg, "library", i); - libport = cfg_getint(lib, "port"); + DPRINTF(E_FATAL, L_CONF, "No directories specified for library\n"); - error = ((libport > 65535) || (libport < 1024)); - 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; - } + goto out_fail; } - free(libports); - - if (error) + /* Do keyword expansion on library names */ + ret = conffile_expand_libname(lib); + if (ret != 0) { - cfg_free(cfg); + DPRINTF(E_FATAL, L_CONF, "Could not expand library name\n"); - return -1; + goto out_fail; } return 0; + + out_fail: + cfg_free(cfg); + + return -1; } void diff --git a/src/db.c b/src/db.c index b3a7e345..598a5ff4 100644 --- a/src/db.c +++ b/src/db.c @@ -230,7 +230,6 @@ static struct col_type_map wi_cols_map[] = { wi_offsetof(wd), DB_TYPE_INT }, { wi_offsetof(cookie), DB_TYPE_INT }, { wi_offsetof(path), DB_TYPE_STRING }, - { wi_offsetof(libidx), DB_TYPE_INT }, }; static __thread sqlite3 *hdl; @@ -2842,12 +2841,12 @@ db_watch_clear(void) int 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 *errmsg; int ret; - query = sqlite3_mprintf(Q_TMPL, wi->wd, wi->path, wi->libidx); + query = sqlite3_mprintf(Q_TMPL, wi->wd, wi->path); if (!query) { 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 (" \ " wd INTEGER PRIMARY KEY NOT NULL," \ " cookie INTEGER NOT NULL," \ - " path VARCHAR(4096) NOT NULL," \ - " libidx INTEGER NOT NULL" \ + " path VARCHAR(4096) NOT NULL" \ ");" #define I_PATH \ @@ -3532,9 +3530,9 @@ db_perthread_deinit(void) */ -#define SCHEMA_VERSION 8 +#define SCHEMA_VERSION 9 #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 { char *query; diff --git a/src/db.h b/src/db.h index ca9b61e7..3e211e11 100644 --- a/src/db.h +++ b/src/db.h @@ -239,7 +239,6 @@ struct watch_info { int wd; char *path; uint32_t cookie; - int libidx; }; #define wi_offsetof(field) offsetof(struct watch_info, field) diff --git a/src/filescanner.c b/src/filescanner.c index b733b90b..6aa91bfc 100644 --- a/src/filescanner.c +++ b/src/filescanner.c @@ -400,13 +400,13 @@ process_file(char *file, time_t mtime, off_t size, int compilation, int flags) /* Thread: scan */ static int -check_compilation(int libidx, char *path) +check_compilation(char *path) { cfg_t *lib; int ndirs; int i; - lib = cfg_getnsec(cfg, "library", libidx); + lib = cfg_getsec(cfg, "library"); ndirs = cfg_size(lib, "compilations"); for (i = 0; i < ndirs; i++) @@ -420,7 +420,7 @@ check_compilation(int libidx, char *path) /* Thread: scan */ static void -process_directory(int libidx, char *path, int flags) +process_directory(char *path, int flags) { struct stacked_dir *bulkstack; cfg_t *lib; @@ -437,7 +437,7 @@ process_directory(int libidx, char *path, int flags) int compilation; int ret; - lib = cfg_getnsec(cfg, "library", libidx); + lib = cfg_getsec(cfg, "library"); if (flags & F_SCAN_BULK) { @@ -468,7 +468,7 @@ process_directory(int libidx, char *path, int flags) } /* Check for a compilation directory */ - compilation = check_compilation(libidx, path); + compilation = check_compilation(path); for (;;) { @@ -555,7 +555,6 @@ process_directory(int libidx, char *path, int flags) if (!(flags & F_SCAN_RESCAN)) { - wi.libidx = libidx; wi.cookie = 0; wi.path = path; @@ -585,7 +584,6 @@ process_directory(int libidx, char *path, int flags) return; } - wi.libidx = libidx; wi.cookie = 0; wi.path = path; @@ -595,18 +593,18 @@ process_directory(int libidx, char *path, int flags) /* Thread: scan */ static void -process_directories(int libidx, char *root, int flags) +process_directories(char *root, int flags) { char *path; - process_directory(libidx, root, flags); + process_directory(root, flags); if (scan_exit) return; while ((path = pop_dir(&dirstack))) { - process_directory(libidx, path, flags); + process_directory(path, flags); free(path); @@ -621,44 +619,38 @@ static void bulk_scan(void) { cfg_t *lib; - int nlib; int ndirs; char *path; char *deref; time_t start; int i; - int j; start = time(NULL); playlists = NULL; dirstack = NULL; - nlib = cfg_size(cfg, "library"); - for (i = 0; i < nlib; i++) + lib = cfg_getsec(cfg, "library"); + + 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"); - for (j = 0; j < ndirs; j++) + deref = m_realpath(path); + 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); - 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; + continue; } + + process_directories(deref, F_SCAN_BULK); + + free(deref); + + if (scan_exit) + return; } if (playlists) @@ -835,7 +827,7 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie) if (ie->mask & IN_CREATE) { - process_directories(wi->libidx, path, flags); + process_directories(path, flags); if (dirstack) 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); @@ -1214,8 +1206,7 @@ kqueue_cb(int fd, short event, void *arg) while ((path = pop_dir(&rescan))) { - /* FIXME: libidx for multi-library support */ - process_directories(0, path, 0); + process_directories(path, 0); free(path); diff --git a/src/filescanner_itunes.c b/src/filescanner_itunes.c index adde4011..eb5be22a 100644 --- a/src/filescanner_itunes.c +++ b/src/filescanner_itunes.c @@ -363,7 +363,7 @@ process_track_file(plist_t trk, char *base) free(location); - if (!cfg_getbool(cfg_getnsec(cfg, "library", 0), "itunes_overrides")) + if (!cfg_getbool(cfg_getsec(cfg, "library"), "itunes_overrides")) return mfi_id; /* Override our metadata with what's provided by iTunes */ diff --git a/src/httpd.c b/src/httpd.c index 5f811c49..32b2fca3 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -1157,7 +1157,7 @@ httpd_init(void) 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 */ bindv6 = evhttp_bind_socket(evhttpd, "::", port); diff --git a/src/httpd_daap.c b/src/httpd_daap.c index c9acd3fb..521dd2bd 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -980,7 +980,7 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char /* We don't support updates atm */ supports_update = 0; - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); passwd = cfg_getstr(lib, "password"); name = cfg_getstr(lib, "name"); @@ -1260,7 +1260,7 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri if (!s) return; - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); name = cfg_getstr(lib, "name"); namelen = strlen(name); @@ -2652,7 +2652,7 @@ daap_request(struct evhttp_request *req) } /* Check authentication */ - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); passwd = cfg_getstr(lib, "password"); /* No authentication for these URIs */ diff --git a/src/httpd_rsp.c b/src/httpd_rsp.c index e1b01119..c3f8b15e 100644 --- a/src/httpd_rsp.c +++ b/src/httpd_rsp.c @@ -276,7 +276,7 @@ rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query) songcount = db_files_get_count(); - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); library = cfg_getstr(lib, "name"); /* We'd use mxmlNewXML(), but then we can't put any attributes @@ -872,7 +872,7 @@ rsp_request(struct evhttp_request *req) } /* Check authentication */ - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); passwd = cfg_getstr(lib, "password"); if (passwd) { diff --git a/src/main.c b/src/main.c index fbd8b369..36dd8360 100644 --- a/src/main.c +++ b/src/main.c @@ -242,7 +242,7 @@ register_services(char *ffid, int no_rsp, int no_daap) srand((unsigned int)time(NULL)); - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); libname = cfg_getstr(lib, "name"); hash = djb_hash(libname, strlen(libname)); diff --git a/src/remote_pairing.c b/src/remote_pairing.c index 25ef3a26..ebe1530f 100644 --- a/src/remote_pairing.c +++ b/src/remote_pairing.c @@ -820,7 +820,7 @@ remote_pairing_init(void) 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); #ifdef USE_EVENTFD diff --git a/src/transcode.c b/src/transcode.c index 9fec4d6d..1f95ce3f 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -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); - lib = cfg_getnsec(cfg, "library", 0); + lib = cfg_getsec(cfg, "library"); size = cfg_size(lib, "no_transcode"); if (size > 0)