diff --git a/src/configfile.c b/src/configfile.c index 080a5e83..8acc3212 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -116,11 +116,9 @@ CONFIGELEMENT config_elements[] = { { 1,1,0,CONFIG_TYPE_INT,"port",(void*)&config.port,config_emit_int }, { 1,1,0,CONFIG_TYPE_STRING,"admin_pw",(void*)&config.adminpassword,config_emit_string }, { 1,1,0,CONFIG_TYPE_STRING,"mp3_dir",(void*)&config.mp3dir,config_emit_string }, -#ifdef WITH_GDBM - { 1,1,0,CONFIG_TYPE_STRING,"db_dir",(void*)&config.dbdir,config_emit_string }, -#else { 1,0,0,CONFIG_TYPE_STRING,"db_dir",(void*)&config.dbdir,config_emit_string }, -#endif + { 1,0,0,CONFIG_TYPE_STRING,"db_type",(void*)&config.dbtype,config_emit_string }, + { 1,0,0,CONFIG_TYPE_STRING,"db_parms",(void*)&config.dbparms,config_emit_string }, { 1,0,0,CONFIG_TYPE_INT,"debuglevel",(void*)&err_debuglevel,config_emit_int }, { 1,1,0,CONFIG_TYPE_STRING,"servername",(void*)&config.servername,config_emit_string }, { 1,0,0,CONFIG_TYPE_INT,"rescan_interval",(void*)&config.rescan_interval,config_emit_int }, diff --git a/src/daapd.h b/src/daapd.h index cd30e387..90f54696 100644 --- a/src/daapd.h +++ b/src/daapd.h @@ -39,7 +39,7 @@ typedef struct tag_stats { time_t start_time; /**< When the server was started */ int songs_served; /**< How many songs have been served */ - + unsigned int gb_served; /**< How many gigs of data have been served (unused) */ unsigned int bytes_served; /**< How many bytes of data served (unused) */ } STATS; @@ -73,9 +73,11 @@ typedef struct tag_config { char *artfilename; /**< What filename to merge coverart with */ char *logfile; /**< What file to use as a logfile */ char *compdirs; /**< Compilations directories */ + char *dbtype; /**< db backend type */ + char *dbparms; /**< parameters for the db backend */ char **complist; /**< list of compilation directories */ STATS stats; /**< Stats structure (see above) */ - WSHANDLE server; /**< webserver handle */ + WSHANDLE server; /**< webserver handle */ } CONFIG; extern CONFIG config; diff --git a/src/db-generic.c b/src/db-generic.c index 018a5886..c0f56518 100644 --- a/src/db-generic.c +++ b/src/db-generic.c @@ -276,7 +276,8 @@ char *db_error_list[] = { "No rows returned", "Invalid playlist id: %d", "Invalid song id: %d", - "Parse error" + "Parse error", + "No backend database support for type: %s" }; /* Globals */ @@ -406,34 +407,6 @@ void db_init_once(void) { pthread_rwlock_init(&db_rwlock,NULL); } - -/** - * Set the database backend. This should show a friendly error about - * what databse types are supported. - * - * \param type what database backend to use (by friendly name) - */ -extern int db_set_backend(char *type) { - DPRINTF(E_DBG,L_DB,"Setting backend database to %s\n",type); - - if(!db_functions[0].name) { - DPRINTF(E_FATAL,L_DB,"No database backends are available. Install sqlite!\n"); - } - - db_current=&db_functions[0]; - while((db_current->name) && (strcasecmp(db_current->name,type))) { - db_current++; - } - - if(!db_current->name) { - DPRINTF(E_WARN,L_DB,"Could not find db backend %s. Aborting.\n",type); - return -1; - } - - DPRINTF(E_DBG,L_DB,"Backend database set\n"); - return 0; -} - /** * Open the database. This is done before we drop privs, that * way if the database only has root perms, then it can still @@ -441,7 +414,7 @@ extern int db_set_backend(char *type) { * * \param parameters This is backend-specific (mysql, sqlite, etc) */ -int db_open(char **pe, char *parameters) { +int db_open(char **pe, char *type, char *parameters) { int result; DPRINTF(E_DBG,L_DB,"Opening database\n"); @@ -449,8 +422,22 @@ int db_open(char **pe, char *parameters) { if(pthread_once(&db_initlock,db_init_once)) return -1; + db_current = &db_functions[0]; + if(type) { + while((db_current->name) && (strcasecmp(db_current->name,type))) { + db_current++; + } + + if(!db_current->name) { + /* end of list -- no match */ + db_get_error(pe,DB_E_BADPROVIDER,type); + return DB_E_BADPROVIDER; + } + } + result=db_current->dbs_open(pe, parameters); + DPRINTF(E_DBG,L_DB,"Results: %d\n",result); return result; } diff --git a/src/db-generic.h b/src/db-generic.h index e06c7d82..331dbe1e 100644 --- a/src/db-generic.h +++ b/src/db-generic.h @@ -135,9 +135,7 @@ typedef struct tag_daap_items { extern DAAP_ITEMS taglist[]; -extern int db_set_backend(char *type); - -extern int db_open(char **pe, char *parameters); +extern int db_open(char **pe, char *type, char *parameters); extern int db_init(int reload); extern int db_deinit(void); @@ -200,6 +198,7 @@ extern void db_dispose_playlist(M3UFILE *pm3u); #define DB_E_INVALID_PLAYLIST 0x06 /**< bad playlist id */ #define DB_E_INVALID_SONGID 0x07 /**< bad song id */ #define DB_E_PARSE 0x08 /**< could not parse result */ +#define DB_E_BADPROVIDER 0x09 /**< requested db backend not there */ /* describes the individual database handlers */ typedef struct tag_dbinfo { diff --git a/src/main.c b/src/main.c index 42149239..56b43bc2 100644 --- a/src/main.c +++ b/src/main.c @@ -360,6 +360,7 @@ int main(int argc, char *argv[]) { int pid_fd; FILE *pid_fp=NULL; + int err; char *perr; config.use_mdns=1; @@ -483,7 +484,13 @@ int main(int argc, char *argv[]) { } /* this will require that the db be readable by the runas user */ - if(db_open(&perr,config.dbdir)) + if(config.dbtype) { + err=db_open(&perr,config.dbtype,config.dbparms); + } else { + err=db_open(&perr,NULL,config.dbdir); + } + + if(err) DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_open: %s\n",perr); /* Initialize the database before starting */