From: Lennart Poettering Date: Sun, 6 Aug 2006 11:54:31 +0000 (+0000) Subject: Allow storing the service type database as Solaris DBM file, alternatively to gdbm... X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=b7d566fc3ec60c0fbbca22af273bc67fdc1372fa;p=catta Allow storing the service type database as Solaris DBM file, alternatively to gdbm. The latter is still recommended. (Patch from Padraig O'Briain) git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1245 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-python/avahi/Makefile.am b/avahi-python/avahi/Makefile.am index b1ebe22..5673d5e 100644 --- a/avahi-python/avahi/Makefile.am +++ b/avahi-python/avahi/Makefile.am @@ -25,10 +25,27 @@ avahidir = $(pythondir)/avahi avahi_SCRIPTS = ServiceTypeDatabase.py +if HAVE_GDBM ServiceTypeDatabase.py: ServiceTypeDatabase.py.in sed -e 's,@PYTHON\@,$(PYTHON),g' \ + -e 's,@DBM\@,gdbm,g' \ + -e 's,@FIRST_KEY\@,key = self.db.firstkey(),g' \ + -e 's,@CHECK_KEY\@,while key is not None:,g' \ + -e 's,@NEXT_KEY\@,key = self.db.nextkey(),g' \ -e 's,@pkgdatadir\@,$(pkgdatadir),g' $< > $@ chmod +x $@ +endif + +if HAVE_DBM +ServiceTypeDatabase.py: ServiceTypeDatabase.py.in + sed -e 's,@PYTHON\@,$(PYTHON),g' \ + -e 's,@DBM\@,dbm,g' \ + -e 's,@FIRST_KEY\@,keys = self.db.keys(),g' \ + -e 's,@CHECK_KEY\@,for key in keys:,g' \ + -e 's,@NEXT_KEY\@,,g' \ + -e 's,@pkgdatadir\@,$(pkgdatadir),g' $< > $@ + chmod +x $@ +endif if HAVE_PYGTK if HAVE_PYTHON_DBUS diff --git a/avahi-python/avahi/ServiceTypeDatabase.py.in b/avahi-python/avahi/ServiceTypeDatabase.py.in index 25807f3..95c03a4 100644 --- a/avahi-python/avahi/ServiceTypeDatabase.py.in +++ b/avahi-python/avahi/ServiceTypeDatabase.py.in @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. -import gdbm +import @DBM@ import locale import re @@ -29,7 +29,7 @@ class ServiceTypeDatabase: def __init__(self, filename = "@pkgdatadir@/service-types.db"): - self.db = gdbm.open(filename, "r") + self.db = @DBM@.open(filename, "r") l = locale.getlocale(locale.LC_MESSAGES) @@ -69,12 +69,12 @@ class ServiceTypeDatabase: def items(self): items = [] - key = self.db.firstkey() - while key is not None: + @FIRST_KEY@ + @CHECK_KEY@ if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key) and not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key): localized_service_name = self[key] items.append((key, localized_service_name)) - key = self.db.nextkey(key) + @NEXT_KEY@ return items def has_key(self, key): diff --git a/avahi-utils/Makefile.am b/avahi-utils/Makefile.am index 61268d3..d684be1 100644 --- a/avahi-utils/Makefile.am +++ b/avahi-utils/Makefile.am @@ -36,6 +36,11 @@ avahi_browse_CFLAGS += -DDATABASE_FILE=\"$(pkgdatadir)/service-types.db\" avahi_browse_LDADD += -lgdbm endif +if HAVE_DBM +avahi_browse_SOURCES += stdb.h stdb.c +avahi_browse_CFLAGS += -DDATABASE_FILE=\"$(pkgdatadir)/service-types.db\" +endif + avahi_resolve_SOURCES = avahi-resolve.c sigint.c sigint.h avahi_resolve_CFLAGS = $(AM_CFLAGS) avahi_resolve_LDADD = $(AM_LDADD) ../avahi-client/libavahi-client.la ../avahi-common/libavahi-common.la diff --git a/avahi-utils/avahi-browse.c b/avahi-utils/avahi-browse.c index 9fd9927..248b651 100644 --- a/avahi-utils/avahi-browse.c +++ b/avahi-utils/avahi-browse.c @@ -43,7 +43,7 @@ #include "sigint.h" -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) #include "stdb.h" #endif @@ -65,7 +65,7 @@ typedef struct Config { Command command; int resolve; int no_fail; -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) int no_db_lookup; #endif } Config; @@ -138,7 +138,7 @@ static ServiceInfo *find_service(AvahiIfIndex interface, AvahiProtocol protocol, static void print_service_line(Config *config, char c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain) { char ifname[IF_NAMESIZE]; -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) if (!config->no_db_lookup) type = stdb_lookup(type); #endif @@ -596,7 +596,7 @@ static void help(FILE *f, const char *argv0) { " -l --ignore-local Ignore local services\n" " -r --resolve Resolve services found\n" " -f --no-fail Don't fail if the daemon is not available\n" -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) " -k --no-db-lookup Don't lookup service types\n" #endif ); @@ -617,7 +617,7 @@ static int parse_command_line(Config *c, const char *argv0, int argc, char *argv { "ignore-local", no_argument, NULL, 'l' }, { "resolve", no_argument, NULL, 'r' }, { "no-fail", no_argument, NULL, 'f' }, -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) { "no-db-lookup", no_argument, NULL, 'k' }, #endif { NULL, 0, NULL, 0 } @@ -634,13 +634,13 @@ static int parse_command_line(Config *c, const char *argv0, int argc, char *argv c->no_fail = 0; c->domain = c->stype = NULL; -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) c->no_db_lookup = 0; #endif opterr = 0; while ((o = getopt_long(argc, argv, "hVd:avtclrDf" -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) "k" #endif , long_options, NULL)) >= 0) { @@ -680,7 +680,7 @@ static int parse_command_line(Config *c, const char *argv0, int argc, char *argv case 'f': c->no_fail = 1; break; -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) case 'k': c->no_db_lookup = 1; break; @@ -783,7 +783,7 @@ fail: avahi_string_list_free(browsed_types); -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) stdb_shutdown(); #endif diff --git a/avahi-utils/avahi-resolve.c b/avahi-utils/avahi-resolve.c index 2dafbf0..cb7ef9f 100644 --- a/avahi-utils/avahi-resolve.c +++ b/avahi-utils/avahi-resolve.c @@ -43,7 +43,7 @@ #include "sigint.h" -#ifdef HAVE_GDBM +#if defined(HAVE_GDBM) || defined(HAVE_DBM) #include "stdb.h" #endif diff --git a/avahi-utils/stdb.c b/avahi-utils/stdb.c index 53be776..388bf6b 100644 --- a/avahi-utils/stdb.c +++ b/avahi-utils/stdb.c @@ -19,7 +19,14 @@ USA. ***/ +#include +#ifdef HAVE_GDBM #include +#endif +#ifdef HAVE_DBM +#include +#include +#endif #include #include #include @@ -29,16 +36,30 @@ #include "stdb.h" +#ifdef HAVE_GDBM static GDBM_FILE gdbm_file = NULL; +#endif +#ifdef HAVE_DBM +static DBM *dbm_file = NULL; +#endif static char *buffer = NULL; static int init(void) { +#ifdef HAVE_GDBM if (gdbm_file) return 0; if (!(gdbm_file = gdbm_open((char*) DATABASE_FILE, 0, GDBM_READER, 0, NULL))) return -1; +#endif +#ifdef HAVE_DBM + if (dbm_file) + return 0; + + if (!(dbm_file = dbm_open((char*) DATABASE_FILE, O_RDONLY, 0))) + return -1; +#endif return 0; } @@ -59,7 +80,12 @@ const char* stdb_lookup(const char *name) { snprintf(k, sizeof(k), "%s[%s]", name, loc); key.dptr = k; key.dsize = strlen(k); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif if (!data.dptr) { char l[32], *e; @@ -70,7 +96,12 @@ const char* stdb_lookup(const char *name) { snprintf(k, sizeof(k), "%s[%s]", name, l); key.dptr = k; key.dsize = strlen(k); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif } if (!data.dptr) { @@ -79,7 +110,12 @@ const char* stdb_lookup(const char *name) { snprintf(k, sizeof(k), "%s[%s]", name, l); key.dptr = k; key.dsize = strlen(k); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif } } } @@ -88,7 +124,12 @@ const char* stdb_lookup(const char *name) { if (!data.dptr) { key.dptr = (char*) name; key.dsize = strlen(name); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif } if (!data.dptr) @@ -106,8 +147,14 @@ fail: } void stdb_shutdown(void) { +#ifdef HAVE_GDBM if (gdbm_file) gdbm_close(gdbm_file); +#endif +#ifdef HAVE_DBM + if (dbm_file) + dbm_close(dbm_file); +#endif avahi_free(buffer); } diff --git a/configure.ac b/configure.ac index 461dbd3..ae38e5b 100644 --- a/configure.ac +++ b/configure.ac @@ -481,24 +481,49 @@ AM_CONDITIONAL(HAVE_EXPAT, test "x$HAVE_EXPAT" = "xyes") # # GDBM # +# +# Check for dbm +# +AC_ARG_ENABLE(dbm, + AS_HELP_STRING([--enable-dbm],[Enable use of DBM]), + [case "${enableval}" in + yes) HAVE_DBM=yes ;; + no) HAVE_DBM=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-dbm) ;; + esac], + [HAVE_DBM=no]) + AC_ARG_ENABLE(gdbm, AS_HELP_STRING([--disable-gdbm],[Disable use of GDBM]), [case "${enableval}" in yes) HAVE_GDBM=yes ;; no) HAVE_GDBM=no ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-gdbm) ;; + *) AC_MSG_ERROR(bad value ${enableval} for --disable-gdbm) ;; esac], [HAVE_GDBM=yes]) if test "x$HAVE_GDBM" = "xyes" ; then + if test "x$HAVE_DBM" = "xyes" ; then + AC_MSG_ERROR([*** --enable-gdbm and --enable-dbm both specified ***]) + fi AC_CHECK_LIB(gdbm, gdbm_open, [ AC_CHECK_HEADERS(gdbm.h, have_gdbm=true, have_gdbm=false) ], have_gdbm=false) if ! $have_gdbm ; then AC_MSG_ERROR([*** libgdbm not found ***]) fi AC_DEFINE([HAVE_GDBM],[],[Support for GDBM]) +else + if test "x$HAVE_DBM" = "xyes" ; then + AC_CHECK_HEADERS(ndbm.h, have_dbm=true, have_dbm=false) + + if ! $have_dbm ; then + AC_MSG_ERROR([*** dbm not found ***]) + fi + AC_DEFINE([HAVE_DBM],[],[Support for DBM]) + fi fi AM_CONDITIONAL(HAVE_GDBM, test "x$HAVE_GDBM" = "xyes") +AM_CONDITIONAL(HAVE_DBM, test "x$HAVE_DBM" = "xyes") # # libdaemon @@ -568,6 +593,9 @@ if test "x$HAVE_PYTHON" = "xyes" ; then if test "x$HAVE_GDBM" = "xyes"; then AM_CHECK_PYMOD(gdbm,,,[AC_MSG_ERROR(Could not find Python module gdbm)]) fi + if test "x$HAVE_DBM" = "xyes"; then + AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)]) + fi fi fi AM_CONDITIONAL(HAVE_PYTHON, [test "x$HAVE_PYTHON" = "xyes" ]) @@ -818,6 +846,7 @@ echo " Enable D-BUS: ${HAVE_DBUS} Enable Expat: ${HAVE_EXPAT} Enable GDBM: ${HAVE_GDBM} + Enable DBM: ${HAVE_DBM} Enable libdaemon: ${HAVE_LIBDAEMON} Enable Python: ${HAVE_PYTHON} Enable pygtk: ${HAVE_PYGTK} diff --git a/service-type-database/Makefile.am b/service-type-database/Makefile.am index 3250e94..1692a0b 100644 --- a/service-type-database/Makefile.am +++ b/service-type-database/Makefile.am @@ -28,7 +28,8 @@ noinst_SCRIPTS=build-db pkgdata_DATA+=service-types.db build-db: build-db.in - sed -e 's,@PYTHON\@,$(PYTHON),g' $< > $@ + sed -e 's,@PYTHON\@,$(PYTHON),g' \ + -e 's,@DBM\@,gdbm,g' $< > $@ chmod +x $@ service-types.db: service-types build-db @@ -36,5 +37,21 @@ service-types.db: service-types build-db CLEANFILES = service-types.db build-db +endif +if HAVE_DBM + +noinst_SCRIPTS=build-db +pkgdata_DATA+=service-types.db.* + +build-db: build-db.in + sed -e 's,@PYTHON\@,$(PYTHON),g' \ + -e 's,@DBM\@,dbm,g' $< > $@ + chmod +x $@ + +service-types.db: service-types build-db + $(PYTHON) build-db $(srcdir)/$< $@ + +CLEANFILES = service-types.db* build-db + endif endif diff --git a/service-type-database/build-db.in b/service-type-database/build-db.in index 21d057d..44f6068 100755 --- a/service-type-database/build-db.in +++ b/service-type-database/build-db.in @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. -import gdbm, sys +import @DBM@, sys if len(sys.argv) > 1: infn = sys.argv[1] @@ -31,7 +31,7 @@ if len(sys.argv) > 2: else: outfn = infn + ".db" -db = gdbm.open(outfn, "n") +db = @DBM@.open(outfn, "n") for ln in file(infn, "r"): ln = ln.strip(" \r\n\t")