From b7d566fc3ec60c0fbbca22af273bc67fdc1372fa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 6 Aug 2006 11:54:31 +0000 Subject: 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 --- avahi-utils/Makefile.am | 5 +++++ avahi-utils/avahi-browse.c | 18 ++++++++--------- avahi-utils/avahi-resolve.c | 2 +- avahi-utils/stdb.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 10 deletions(-) (limited to 'avahi-utils') 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); } -- cgit