starting simple gdbm backend

This commit is contained in:
Ron Pedde 2006-03-27 01:48:43 +00:00
parent 96753e59ca
commit 476ee42faf
4 changed files with 208 additions and 3 deletions

View File

@ -78,6 +78,11 @@ AC_ARG_ENABLE(musepack,[ --enable-musepack Enable Musepack support],
use_musepack=true;
CPPFLAGS="${CPPFLAGS} -DMUSEPACK")
AC_ARG_ENABLE(gdbm,[ --enable-gdbm Enable gdbm support],
use_gdbm=true;
CPPFLAGS="${CPPFLAGS} -DGDBM")
AM_CONDITIONAL(COND_REND_HOWL, test x$rend_howl = xtrue)
AM_CONDITIONAL(COND_REND_POSIX, test x$rend_posix = xtrue)
AM_CONDITIONAL(COND_OGGVORBIS, test x$use_oggvorbis = xtrue)
@ -85,6 +90,7 @@ AM_CONDITIONAL(COND_FLAC, test x$use_flac = xtrue)
AM_CONDITIONAL(COND_MUSEPACK, test x$use_musepack = xtrue)
AM_CONDITIONAL(COND_SQLITE,test x$db_sqlite = xtrue)
AM_CONDITIONAL(COND_SQLITE3,test x$db_sqlite3 = xtrue)
AM_CONDITIONAL(COND_GDBM,test x$use_gdbm = xtrue)
AM_CONDITIONAL(COND_NEED_STRCASESTR,false)
AM_CONDITIONAL(COND_NEED_STRSEP,false)
@ -156,6 +162,22 @@ AC_ARG_WITH(howl-libs,
fi
])
AC_ARG_WITH(gdbm-includes,
[--with-gdbm-includes[[=DIR]] use gdbm include files in DIR],[
if test "$withval" != "no" -a "$withval" != "yes"; then
Z_DIR=$withval
CPPFLAGS="${CPPFLAGS} -I$withval"
fi
])
AC_ARG_WITH(gdbm-libs,
[--with-gdbm-libs[[=DIR]] use gdbm lib files in DIR],[
if test "$withval" != "no" -a "$withval" != "yes"; then
Z_DIR=$withval
LDFLAGS="${LDFLAGS} -L$withval"
fi
])
AC_ARG_WITH(id3tag,
[--with-id3tag[[=DIR]] use id3tag in DIR],[
if test "$withval" != "no" -a "$withval" != "yes"; then
@ -182,6 +204,18 @@ else
fi
CFLAGS=$oldcflags
if test x$use_gdbm = xtrue; then
AC_CHECK_HEADERS(gdbm.h,, [
AC_MSG_ERROR([gdbm.h not found... Must have gdbm headers installed])])
AC_CHECK_LIB(gdbm,gdbm_open,,echo "Must have gdbm libraries installed";exit)
if test x"$STATIC_LIBS" != x"no"; then
LIBS="${LIBS} ${STATIC_LIBS}/libgdbm.a"
else
LIBS="${LIBS} -lgdbm"
fi
fi
if test x$db_sqlite = xtrue; then
AC_CHECK_HEADERS(sqlite.h,, [
AC_MSG_ERROR([sqlite.h not found... Must have sqlite headers installed])])

View File

@ -41,6 +41,9 @@ if COND_SQL
SQLDB=db-sql.c db-sql.h
endif
if COND_GDBM
GDBM=db-gdbm.c db-gdbm.h
endif
wavstreamer_SOURCES = wavstreamer.c
@ -55,7 +58,7 @@ mt_daapd_SOURCES = main.c daapd.h rend.h uici.c uici.h webserver.c \
os.h strptime.c strptime.h ll.c ll.h conf.c conf.h \
strtok_r.c strtok_r.h os-unix.h os-unix.c os.h \
$(PRENDSRC) $(ORENDSRC) $(HRENDSRC) $(OGGVORBISSRC) $(FLACSRC) \
$(MUSEPACKSRC) $(SQLITEDB) $(SQLITE3DB) $(SQLDB)
$(MUSEPACKSRC) $(SQLITEDB) $(SQLITE3DB) $(SQLDB) $(GDBM)
EXTRA_DIST = mDNS.c mDNSClientAPI.h mDNSDebug.h mDNSPosix.c \
mDNSUNP.c mDNSPlatformFunctions.h mDNSPosix.h mDNSUNP.h \
@ -64,5 +67,4 @@ EXTRA_DIST = mDNS.c mDNSClientAPI.h mDNSDebug.h mDNSPosix.c \
db-sql-sqlite2.h db-sql-sqlite2.c \
db-sql-sqlite3.h db-sql-sqlite3.c \
w32-eventlog.c w32-eventlog.h w32-service.c w32-service.h \
os-win32.h os-win32.c win32.h
os-win32.h os-win32.c win32.h db-gdbm.c db-gdbm.h

134
src/db-gdbm.c Normal file
View File

@ -0,0 +1,134 @@
/*
* $Id: $
* simple gdbm database implementation
*
* Copyright (C) 2003-2006 Ron Pedde (rpedde@sourceforge.net)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <gdbm.h>
#include <limits.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "err.h"
#include "mp3-scanner.h"
#include "redblack.h"
#include "db-gdbm.h"
#ifndef GDBM_SYNC
# define GDBM_SYNC 0
#endif
#ifndef GDBM_NOLOCK
# define GDBM_NOLOCK 0
#endif
/* Typedefs */
/* Globals */
static pthread_mutex_t _gdbm_mutex = PTHREAD_MUTEX_INITIALIZER; /**< gdbm not reentrant */
static GDBM_FILE _gdbm_songs;
/* Forwards */
void _gdbm_lock(void);
void _gdbm_unlock(void);
/**
* lock the db_mutex
*/
void _gdbm_lock(void) {
int err;
if((err=pthread_mutex_lock(&_gdbm_mutex))) {
DPRINTF(E_FATAL,L_DB,"cannot lock gdbm lock: %s\n",strerror(err));
}
}
/**
* unlock the db_mutex
*/
void _gdbm_unlock(void) {
int err;
if((err=pthread_mutex_unlock(&_gdbm_mutex))) {
DPRINTF(E_FATAL,L_DB,"cannot unlock gdbm lock: %s\n",strerror(err));
}
}
/**
* open the gdbm database
*
* @param pe error buffer
* @param parameters db-specific parameter. In this case,
* the path to use
* @returns DB_E_SUCCESS on success, DB_E_* otherwise.
*/
int db_gdbm_open(char **pe, char *parameters) {
char db_path[PATH_MAX + 1];
snprintf(db_path,sizeof(db_path),"%s/%s",parameters,"songs.gdb");
// reload = reload ? GDBM_NEWDB : GDBM_WRCREAT;
_gdbm_lock();
_gdbm_songs = gdbm_open(db_path, 0, GDBM_WRCREAT | GDBM_SYNC | GDBM_NOLOCK,
0600,NULL);
if(!_gdbm_songs) {
/* let's try creating it! */
_gdbm_songs = gdbm_open(db_path,0,GDBM_NEWDB | GDBM_SYNC | GDBM_NOLOCK,
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;
}
return TRUE;
}
/**
* Don't really have a db initialization separate from opening.
*/
int db_gdbm_init(int reload) {
return TRUE;
}
/**
* Close the database
*/
int db_gdbm_deinit(void) {
_gdbm_lock();
gdbm_close(_gdbm_songs);
_gdbm_unlock();
return TRUE;
}

35
src/db-gdbm.h Normal file
View File

@ -0,0 +1,35 @@
/*
* $Id: $
* implement gdbm backend. This will be an implementation based on the
* absolute minimum API. This will be used as a template for the "worst-case"
* backend. Writing a full backend might be faster, but this will be guaranteed
* to work.
*
* To use a separate database as authoritative, you'll only need to implement the
* read-only functions
*/
#ifndef _DB_GDBM_H_
#define _DB_GDBM_H_
#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 int db_gdbm_enum_start(char **pe);
extern MP3FILE db_gebm_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_ */