diff --git a/src/daap.c b/src/daap.c index fb6b90f1..0d2805b5 100644 --- a/src/daap.c +++ b/src/daap.c @@ -435,6 +435,9 @@ DAAP_BLOCK *daap_response_playlists(char *name) { g = g && daap_add_long(mlit,"mper",0,playlistid); g = g && daap_add_string(mlit,"minm",db_get_playlist_name(playlistid)); g = g && daap_add_int(mlit,"mimc",db_get_playlist_entry_count(playlistid)); + if(db_get_playlist_is_smart(playlistid)) { + g = g && daap_add_char(mlit,"aeSP",0x1); + } } g = g && mlit; } diff --git a/src/db-gdbm.c b/src/db-gdbm.c index 768f991a..c9a4ff58 100644 --- a/src/db-gdbm.c +++ b/src/db-gdbm.c @@ -51,6 +51,7 @@ typedef struct tag_playlistentry { typedef struct tag_playlist { unsigned int id; int songs; + int is_smart; char *name; struct tag_playlistentry *nodes; struct tag_playlist *next; @@ -116,7 +117,7 @@ int db_init(char *parameters); int db_deinit(void); int db_version(void); int db_add(MP3FILE *mp3file); -int db_add_playlist(unsigned int playlistid, char *name); +int db_add_playlist(unsigned int playlistid, char *name, int is_smart); int db_add_playlist_song(unsigned int playlistid, unsigned int itemid); int db_unpackrecord(datum *pdatum, MP3FILE *pmp3); datum *db_packrecord(MP3FILE *pmp3); @@ -135,6 +136,7 @@ int db_playlist_items_enum_end(void); int db_get_song_count(void); int db_get_playlist_count(void); +int db_get_playlist_is_smart(int playlistid); int db_get_playlist_entry_count(int playlistid); char *db_get_playlist_name(int playlistid); @@ -164,6 +166,11 @@ int db_init(char *parameters) { datum tmp_key,tmp_nextkey,song_data; char db_path[PATH_MAX + 1]; + if(pthread_once(&db_initlock,db_init_once)) + return -1; + + pl_register(); + snprintf(db_path,sizeof(db_path),"%s/%s",parameters,"songs.gdb"); db_songs=gdbm_open(db_path,0,GDBM_WRCREAT | GDBM_SYNC | GDBM_NOLOCK, 0600,NULL); @@ -206,7 +213,7 @@ int db_init(char *parameters) { DPRINTF(ERR_DEBUG,"Loaded database... found %d songs\n",db_song_count); /* and the playlists */ - return pthread_once(&db_initlock,db_init_once); + return 0; } /* @@ -282,7 +289,7 @@ int db_is_empty(void) { * * Add a new playlist */ -int db_add_playlist(unsigned int playlistid, char *name) { +int db_add_playlist(unsigned int playlistid, char *name, int is_smart) { int err; DB_PLAYLIST *pnew; @@ -294,6 +301,7 @@ int db_add_playlist(unsigned int playlistid, char *name) { pnew->id=playlistid; pnew->nodes=NULL; pnew->songs=0; + pnew->is_smart=is_smart; if(!pnew->name) { free(pnew); @@ -859,6 +867,37 @@ int db_get_song_count(void) { return db_song_count; } + +/* + * db_get_playlist_is_smart + * + * return whether or not the playlist is a "smart" playlist + */ +int db_get_playlist_is_smart(int playlistid) { + DB_PLAYLIST *current; + int err; + int result; + + if((err=pthread_rwlock_rdlock(&db_rwlock))) { + log_err(0,"Cannot lock rwlock\n"); + errno=err; + return -1; + } + + current=db_playlists.next; + while(current && (current->id != playlistid)) + current=current->next; + + if(!current) { + result=0; + } else { + result=1; + } + + pthread_rwlock_unlock(&db_rwlock); + return result; +} + /* * db_get_playlist_entry_count * diff --git a/src/db-memory.c b/src/db-memory.c index b8f2c2ae..04c854ae 100644 --- a/src/db-memory.c +++ b/src/db-memory.c @@ -46,6 +46,7 @@ typedef struct tag_playlist { unsigned int id; int songs; char *name; + int is_smart; struct tag_playlistentry *nodes; struct tag_playlist *next; } DB_PLAYLIST; @@ -74,7 +75,7 @@ int db_init(char *parameters); int db_deinit(void); int db_version(void); int db_add(MP3FILE *mp3file); -int db_add_playlist(unsigned int playlistid, char *name); +int db_add_playlist(unsigned int playlistid, char *name, int is_smart); int db_add_playlist_song(unsigned int playlistid, unsigned int itemid); MP3RECORD *db_enum_begin(void); @@ -91,6 +92,7 @@ int db_playlist_items_enum_end(void); int db_get_song_count(void); int db_get_playlist_count(void); +int db_get_playlist_is_smart(int playlistid); int db_get_playlist_entry_count(int playlistid); char *db_get_playlist_name(int playlistid); @@ -119,7 +121,13 @@ int db_init(char *parameters) { db_version_no=1; db_song_count=0; db_playlists.next=NULL; - return pthread_once(&db_initlock,db_init_once); + + if(pthread_once(&db_initlock,db_init_once)) + return -1; + + pl_register(); + + return 0; } /* @@ -200,7 +208,7 @@ int db_is_empty(void) { * * Add a new playlist */ -int db_add_playlist(unsigned int playlistid, char *name) { +int db_add_playlist(unsigned int playlistid, char *name, int is_smart) { int err; DB_PLAYLIST *pnew; @@ -210,6 +218,7 @@ int db_add_playlist(unsigned int playlistid, char *name) { pnew->name=strdup(name); pnew->id=playlistid; + pnew->is_smart=is_smart; pnew->nodes=NULL; pnew->songs=0; @@ -572,6 +581,37 @@ int db_get_song_count(void) { return db_song_count; } +/* + * db_get_playlist_is_smart + * + * return whether or not the playlist is a "smart" playlist + */ +int db_get_playlist_is_smart(int playlistid) { + DB_PLAYLIST *current; + int err; + int result; + + if((err=pthread_rwlock_rdlock(&db_rwlock))) { + log_err(0,"Cannot lock rwlock\n"); + errno=err; + return -1; + } + + current=db_playlists.next; + while(current && (current->id != playlistid)) + current=current->next; + + if(!current) { + result=0; + } else { + result=1; + } + + pthread_rwlock_unlock(&db_rwlock); + return result; +} + + /* * db_get_playlist_entry_count * diff --git a/src/db-memory.h b/src/db-memory.h index f3db932f..28a347dd 100644 --- a/src/db-memory.h +++ b/src/db-memory.h @@ -33,7 +33,7 @@ extern int db_init(char *parameters); extern int db_deinit(void); extern int db_version(void); extern int db_add(MP3FILE *mp3file); -extern int db_add_playlist(unsigned int playlistid, char *name); +extern int db_add_playlist(unsigned int playlistid, char *name, int is_smart); extern int db_add_playlist_song(unsigned int playlistid, unsigned int itemid); extern ENUMHANDLE db_enum_begin(void); @@ -44,6 +44,7 @@ extern MP3FILE *db_find(int id); extern int db_get_song_count(void); extern int db_get_playlist_count(void); extern int db_get_playlist_entry_count(int playlistid); +extern int db_get_playlist_is_smart(int playlistid); extern ENUMHANDLE db_playlist_enum_begin(void); extern int db_playlist_enum(ENUMHANDLE *current); diff --git a/src/mp3-scanner.c b/src/mp3-scanner.c index a0042d41..503eb9be 100644 --- a/src/mp3-scanner.c +++ b/src/mp3-scanner.c @@ -47,7 +47,10 @@ #include "err.h" #include "mp3-scanner.h" #include "playlist.h" -#include "strcasestr.h" + +#ifdef NEED_STRCASESTR +# include "strcasestr.h" +#endif /* * Typedefs @@ -370,7 +373,7 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) { playlistid=psb->st_ino; fd=open(playlist_path,O_RDONLY); if(fd != -1) { - db_add_playlist(playlistid,m3u_path); + db_add_playlist(playlistid,m3u_path,0); while(readline(fd,linebuffer,sizeof(linebuffer)) > 0) { while((linebuffer[strlen(linebuffer)-1] == '\n') || diff --git a/src/playlist.c b/src/playlist.c index df28d513..f9cffeb9 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -158,7 +158,6 @@ void pl_dump_node(PL_NODE *pnode, int indent) { */ int pl_load(char *file) { FILE *fin; - SMART_PLAYLIST *pcurrent; int result; fin=fopen(file,"r"); @@ -174,16 +173,25 @@ int pl_load(char *file) { return -1; } + return 0; +} + +/* + * pl_register + * + * Register the playlists + */ +void pl_register(void) { + SMART_PLAYLIST *pcurrent; + /* register the playlists */ DPRINTF(ERR_INFO,"Finished loading smart playlists\n"); pcurrent=pl_smart.next; while(pcurrent) { DPRINTF(ERR_INFO,"Adding smart playlist %s as %d\n",pcurrent->name,pcurrent->id) - db_add_playlist(pcurrent->id, pcurrent->name); + db_add_playlist(pcurrent->id, pcurrent->name,1); pcurrent=pcurrent->next; } - - return 0; } /* diff --git a/src/playlist.h b/src/playlist.h index 3d5effc5..d69d18b5 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -54,6 +54,7 @@ extern int pl_error; extern void pl_dump(void); extern int pl_load(char *file); extern void pl_eval(MP3FILE *pmp3); +extern void pl_register(void); #endif /* _PL_H_ */