mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-27 06:33:21 -05:00
more gdbm
This commit is contained in:
parent
26a235672b
commit
ad0455d09a
@ -36,6 +36,7 @@
|
||||
#include "err.h"
|
||||
#include "mp3-scanner.h"
|
||||
#include "redblack.h"
|
||||
#include "db-generic.h"
|
||||
#include "db-gdbm.h"
|
||||
|
||||
#ifndef GDBM_SYNC
|
||||
@ -89,6 +90,7 @@ void _gdbm_unlock(void) {
|
||||
*/
|
||||
int db_gdbm_open(char **pe, char *parameters) {
|
||||
char db_path[PATH_MAX + 1];
|
||||
int result = DB_E_SUCCESS;
|
||||
|
||||
snprintf(db_path,sizeof(db_path),"%s/%s",parameters,"songs.gdb");
|
||||
|
||||
@ -103,16 +105,14 @@ int db_gdbm_open(char **pe, char *parameters) {
|
||||
0600,NULL);
|
||||
}
|
||||
|
||||
_gdbm_unlock();
|
||||
if(!_gdbm_songs) {
|
||||
DPRINTF(E_FATAL,L_DB,"Could not open songs database (%s): %s\n",
|
||||
db_path,strerror(errno));
|
||||
return FALSE;
|
||||
db_get_error(pe,DB_E_DB_ERROR,gdbm_strerror(gdbm_errno));
|
||||
result = DB_E_DB_ERROR;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
||||
_gdbm_unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,3 +132,75 @@ int db_gdbm_deinit(void) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* given an id, fetch the associated MP3FILE
|
||||
*
|
||||
* @param pe error buffer
|
||||
* @param id id of item to fetch
|
||||
* @returns pointer to MP3FILE. Must be disposed of with db_dispose
|
||||
*/
|
||||
PACKED_MP3FILE *db_gdbm_fetch_item(char **pe, int id) {
|
||||
datum key, content;
|
||||
int content_size;
|
||||
PACKED_MP3FILE *ppmp3;
|
||||
char **char_array;
|
||||
char *element_ptr;
|
||||
int done=0;
|
||||
|
||||
/* pull a row that looks like a sql row out of the table */
|
||||
key.dptr = (void*)&id;
|
||||
key.dsize = sizeof(unsigned int);
|
||||
|
||||
_gdbm_lock();
|
||||
content = gdbm_fetch(_gdbm_songs,key);
|
||||
_gdbm_unlock();
|
||||
|
||||
if(content.dptr) {
|
||||
/* have a "packed" row.... let's unpack it */
|
||||
ppmp3=(PACKED_MP3FILE*)malloc(sizeof(PACKED_MP3FILE));
|
||||
if(!ppmp3) {
|
||||
DPRINTF(E_FATAL,L_DB,"db_gdbm_fetch_item: malloc\n");
|
||||
return NULL; /* lol */
|
||||
}
|
||||
memset(ppmp3,0x0,sizeof(PACKED_MP3FILE));
|
||||
content_size = content.dsize;
|
||||
element_ptr = content.dptr;
|
||||
char_array = (char**)(ppmp3);
|
||||
|
||||
/* walk through and set each element */
|
||||
while(!done) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/**
|
||||
* start a full scan through the database
|
||||
*
|
||||
* @parm pe error buffer
|
||||
* @returns DB_E_SUCCESS or DB_E* on failure
|
||||
*/
|
||||
int db_gdbm_enum_start(char **pe) {
|
||||
return DB_E_DB_ERROR;
|
||||
}
|
||||
|
||||
PACKED_MP3FILE *db_gdbm_enum_fetch(char **pe) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int db_gdbm_enum_end(char **pe) {
|
||||
return DB_E_DB_ERROR;
|
||||
}
|
||||
|
||||
/* Required for read-write (fs scanning) support */
|
||||
int db_gdbm_add(char **pe, MP3FILE *pmp3) {
|
||||
return DB_E_DB_ERROR;
|
||||
}
|
||||
|
||||
extern int db_gdbm_delete(char **pe, int id) {
|
||||
return DB_E_DB_ERROR;
|
||||
}
|
||||
|
||||
|
@ -14,22 +14,20 @@
|
||||
|
||||
#include "mp3-scanner.h"
|
||||
|
||||
|
||||
/* Always required */
|
||||
extern int db_gdbm_open(char **pe, char *parameters);
|
||||
extern int db_gdbm_init(int reload);
|
||||
extern int db_gdbm_deinit(void);
|
||||
|
||||
/* Required for read-only support */
|
||||
extern MP3FILE *db_gdbm_fetch_item(char **pe, int id);
|
||||
extern PACKED_MP3FILE *db_gdbm_fetch_item(char **pe, int id);
|
||||
extern int db_gdbm_enum_start(char **pe);
|
||||
extern MP3FILE db_gebm_enum_fetch(char **pe);
|
||||
extern PACKED_MP3FILE *db_gdbm_enum_fetch(char **pe);
|
||||
extern int db_gdbm_enum_end(char **pe);
|
||||
|
||||
/* Required for read-write (fs scanning) support */
|
||||
extern int db_gdbm_add(char **pe, MP3FILE *pmp3);
|
||||
extern int db_gdbm_delete(char **pe, int id);
|
||||
|
||||
|
||||
#endif /* _DB_GDBM_H_ */
|
||||
|
||||
|
@ -239,10 +239,10 @@ DAAP_ITEMS taglist[] = {
|
||||
/* iTunes 5.0+ */
|
||||
{ 0x01, "ascr", "daap.songcontentrating" },
|
||||
{ 0x01, "f" "\x8d" "ch", "dmap.haschildcontainers" },
|
||||
|
||||
|
||||
/* iTunes 6.0.2+ */
|
||||
{ 0x01, "aeHV", "com.apple.itunes.has-video" },
|
||||
|
||||
|
||||
/* iTunes 6.0.4+ */
|
||||
{ 0x05, "msas", "dmap.authenticationschemes" },
|
||||
{ 0x09, "asct", "daap.songcategory" },
|
||||
@ -259,7 +259,7 @@ DAAP_ITEMS taglist[] = {
|
||||
{ 0x09, "aeEN", "com.apple.itunes.episode-num-str" },
|
||||
{ 0x05, "aeES", "com.apple.itunes.episode-sort" },
|
||||
{ 0x05, "aeSU", "com.apple.itunes.season-num" },
|
||||
|
||||
|
||||
/* mt-daapd specific */
|
||||
{ 0x09, "MSPS", "org.mt-daapd.smart-playlist-spec" },
|
||||
{ 0x01, "MPTY", "org.mt-daapd.playlist-type" },
|
||||
@ -322,11 +322,11 @@ static METAMAP db_metamap[] = {
|
||||
{ "com.apple.itunes.itms-genreid", metaItmsGenreId },
|
||||
{ "com.apple.itunes.itms-storefrontid",metaItmsStorefrontId },
|
||||
{ "com.apple.itunes.smart-playlist", metaItunesSmartPlaylist },
|
||||
|
||||
|
||||
/* iTunes 5.0+ */
|
||||
{ "daap.songcontentrating", metaSongContentRating },
|
||||
{ "dmap.haschildcontainers", metaHasChildContainers },
|
||||
|
||||
|
||||
/* iTunes 6.0.2+ */
|
||||
{ "com.apple.itunes.has-video", metaItunesHasVideo },
|
||||
|
||||
@ -350,7 +350,8 @@ char *db_error_list[] = {
|
||||
"No backend database support for type: %s",
|
||||
"Could not initialize thread pool",
|
||||
"Passed buffer too small for result",
|
||||
"Wrong db schema. Use mtd-update to upgrade the db."
|
||||
"Wrong db schema. Use mtd-update to upgrade the db.",
|
||||
"Database error: %s"
|
||||
};
|
||||
|
||||
/* Globals */
|
||||
@ -673,11 +674,11 @@ int db_edit_playlist(char **pe, int id, char *name, char *clause) {
|
||||
*/
|
||||
int db_playcount_increment(char **pe, int id) {
|
||||
int retval;
|
||||
|
||||
|
||||
db_writelock();
|
||||
retval = db_current->dbs_playcount_increment(pe, id);
|
||||
db_unlock();
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -938,7 +939,7 @@ int db_dmap_add_string(unsigned char *where, char *tag, char *value) {
|
||||
where[6]=(len >> 8) & 0xFF;
|
||||
where[7]=len & 0xFF;
|
||||
|
||||
if(len)
|
||||
if(len)
|
||||
strncpy((char*)where+8,value,len);
|
||||
return 8 + len;
|
||||
}
|
||||
|
@ -213,6 +213,7 @@ extern void db_dispose_playlist(M3UFILE *pm3u);
|
||||
#define DB_E_PROC 0x0A /**< could not start threadpool */
|
||||
#define DB_E_SIZE 0x0B /**< passed buffer too small */
|
||||
#define DB_E_WRONGVERSION 0x0C /**< must upgrade db */
|
||||
#define DB_E_DB_ERROR 0x0D /**< gdbm error */
|
||||
|
||||
/* describes the individual database handlers */
|
||||
typedef struct tag_dbinfo {
|
||||
|
@ -45,7 +45,7 @@ typedef struct tag_mp3file {
|
||||
int song_length;
|
||||
int file_size;
|
||||
int year; /* TDRC */
|
||||
|
||||
|
||||
int track; /* TRCK */
|
||||
int total_tracks;
|
||||
|
||||
@ -71,10 +71,10 @@ typedef struct tag_mp3file {
|
||||
int force_update;
|
||||
int sample_count;
|
||||
char compilation;
|
||||
|
||||
|
||||
/* iTunes 5+ */
|
||||
int contentrating;
|
||||
|
||||
|
||||
/* iTunes 6.0.2 */
|
||||
int has_video;
|
||||
} MP3FILE;
|
||||
@ -90,6 +90,50 @@ typedef struct tag_m3ufile {
|
||||
int index; /**< index of playlist for paths with multiple playlists */
|
||||
} M3UFILE;
|
||||
|
||||
typedef struct tag_packed_mp3file {
|
||||
char *id;
|
||||
char *path;
|
||||
char *fname;
|
||||
char *title;
|
||||
char *artist;
|
||||
char *album;
|
||||
char *genre;
|
||||
char *comment;
|
||||
char *type;
|
||||
char *composer;
|
||||
char *orchestra;
|
||||
char *conductor;
|
||||
char *grouping;
|
||||
char *url;
|
||||
char *bitrate;
|
||||
char *samplerate;
|
||||
char *song_length;
|
||||
char *file_size;
|
||||
char *year;
|
||||
char *track;
|
||||
char *total_tracks;
|
||||
char *disc;
|
||||
char *total_discs;
|
||||
char *bpm;
|
||||
char *compilation;
|
||||
char *rating;
|
||||
char *play_count;
|
||||
char *data_kind;
|
||||
char *item_kind;
|
||||
char *description;
|
||||
char *time_added;
|
||||
char *time_modified;
|
||||
char *time_played;
|
||||
char *db_timestamp;
|
||||
char *disabled;
|
||||
char *sample_count;
|
||||
char *force_update;
|
||||
char *codectype;
|
||||
char *idx;
|
||||
char *has_video;
|
||||
char *contentrating;
|
||||
} PACKED_MP3FILE;
|
||||
|
||||
#define PL_STATICWEB 0
|
||||
#define PL_SMART 1
|
||||
#define PL_STATICFILE 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user