diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-04-12 22:14:40 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-04-12 22:14:40 +0000 |
commit | bc24853c6421b9374eb4825ae40178d14e0c0575 (patch) | |
tree | e2044a12745382d978ed5200c94d68ea4c55e359 /avahi-utils/stdb.c | |
parent | 7b2cfb7ec3c22b16615d4dfb37bdf08f85f31bad (diff) |
add the ability to dump the service type database to avahi-browse
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1414 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-utils/stdb.c')
-rw-r--r-- | avahi-utils/stdb.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/avahi-utils/stdb.c b/avahi-utils/stdb.c index 388bf6b..a420364 100644 --- a/avahi-utils/stdb.c +++ b/avahi-utils/stdb.c @@ -43,6 +43,7 @@ static GDBM_FILE gdbm_file = NULL; static DBM *dbm_file = NULL; #endif static char *buffer = NULL; +static char *enum_key = NULL; static int init(void) { @@ -150,11 +151,64 @@ void stdb_shutdown(void) { #ifdef HAVE_GDBM if (gdbm_file) gdbm_close(gdbm_file); + + gdbm_file = NULL; #endif #ifdef HAVE_DBM if (dbm_file) dbm_close(dbm_file); + + dbm_file = NULL; #endif avahi_free(buffer); + avahi_free(enum_key); + + buffer = enum_key = NULL; +} + +char *stdb_getent(void) { + datum key; + + if (init() < 0) + return NULL; + + for (;;) { + + if (!enum_key) { +#ifdef HAVE_GDBM + key = gdbm_firstkey(gdbm_file); +#endif +#ifdef HAVE_DBM + key = dbm_firstkey(dbm_file); +#endif + } else { + key.dptr = enum_key; + key.dsize = strlen(enum_key); + +#ifdef HAVE_GDBM + key = gdbm_nextkey(gdbm_file, key); +#endif +#ifdef HAVE_DBM + key = dbm_nextkey(dbm_file, key); +#endif + } + + avahi_free(enum_key); + enum_key = NULL; + + if (!key.dptr) + return NULL; + + enum_key = avahi_strndup(key.dptr, key.dsize); + free(key.dptr); + + if (!strchr(enum_key, '[')) + return enum_key; + } +} + +void stdb_setent(void) { + avahi_free(enum_key); + enum_key = NULL; } |