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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
-import gdbm
+import @DBM@
import locale
import re
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)
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):
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
#include "sigint.h"
-#ifdef HAVE_GDBM
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
#include "stdb.h"
#endif
Command command;
int resolve;
int no_fail;
-#ifdef HAVE_GDBM
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
int no_db_lookup;
#endif
} Config;
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
" -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
);
{ "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 }
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) {
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;
avahi_string_list_free(browsed_types);
-#ifdef HAVE_GDBM
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
stdb_shutdown();
#endif
#include "sigint.h"
-#ifdef HAVE_GDBM
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
#include "stdb.h"
#endif
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;
}
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;
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) {
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) {
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)
}
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);
}
#
# 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
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" ])
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}
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
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
# 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]
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")