]> git.meshlink.io Git - catta/commitdiff
Allow storing the service type database as Solaris DBM file, alternatively to gdbm...
authorLennart Poettering <lennart@poettering.net>
Sun, 6 Aug 2006 11:54:31 +0000 (11:54 +0000)
committerLennart Poettering <lennart@poettering.net>
Sun, 6 Aug 2006 11:54:31 +0000 (11:54 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1245 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-python/avahi/Makefile.am
avahi-python/avahi/ServiceTypeDatabase.py.in
avahi-utils/Makefile.am
avahi-utils/avahi-browse.c
avahi-utils/avahi-resolve.c
avahi-utils/stdb.c
configure.ac
service-type-database/Makefile.am
service-type-database/build-db.in

index b1ebe22a69567a10eae8cab2019ae483c7f05c15..5673d5ea0adfa6a4be18d75508de48c2096bb212 100644 (file)
@@ -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
index 25807f36c7e6e22ab5737d2e8fe6e0f626c82ed3..95c03a47cff097181000947feb966b3972599db6 100644 (file)
@@ -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):
index 61268d32cf49eb50c2bcb8637b65bbd7d5dba110..d684be1bbdfa77a653dba72761ca40ceeac18ef3 100644 (file)
@@ -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
index 9fd99270958d0edca6f09b35cd0e761b8c298ef8..248b6518b28b5af36420f2177791f858beaa2a7b 100644 (file)
@@ -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    
 
index 2dafbf07e796c4d0ad8402063074e3637effd7d1..cb7ef9f12d26c0476d9cf5dd488d8cfd45ce7032 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "sigint.h"
 
-#ifdef HAVE_GDBM
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
 #include "stdb.h"
 #endif
 
index 53be7766cb5c7959d5ca7327ba7bd756dff0e382..388bf6b508860a0dd597e4405fd775c475ff637b 100644 (file)
   USA.
 ***/
 
+#include <config.h>
+#ifdef HAVE_GDBM
 #include <gdbm.h>
+#endif
+#ifdef HAVE_DBM
+#include <ndbm.h>
+#include <fcntl.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include <locale.h>
 
 #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);
 }
index 461dbd311f59bcc595dc1f9b6e30256afaac4538..ae38e5b6d1ac849d33c6cfaa86168e5a74294282 100644 (file)
@@ -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}
index 3250e9485feb8546ccf1a9f31a4479fd1c698b14..1692a0b11e2ecf796a74ebd89f03391837983e33 100644 (file)
@@ -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
index 21d057d45e86755eb0abec3f4f2776ddde90c830..44f606894092e17314bab47c3045c2538a1c8955 100755 (executable)
@@ -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")