mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-28 15:06:02 -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_ */
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 {
|
||||
|
@ -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