COMMAND_BROWSE_SERVICES,
COMMAND_BROWSE_ALL_SERVICES,
COMMAND_BROWSE_DOMAINS
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
+ , COMMAND_DUMP_STDB
+#endif
} Command;
typedef struct Config {
fprintf(f,
"%s [options] <service type>\n"
"%s [options] -a\n"
- "%s [options] -D\n\n",
+ "%s [options] -D\n"
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
+ "%s [options] -b\n",
+#endif
+ "\n",
argv0, argv0, argv0);
fprintf(f,
" -f --no-fail Don't fail if the daemon is not available\n"
#if defined(HAVE_GDBM) || defined(HAVE_DBM)
" -k --no-db-lookup Don't lookup service types\n"
+ " -b --dump-db Dump service type database\n"
#endif
);
}
{ "no-fail", no_argument, NULL, 'f' },
#if defined(HAVE_GDBM) || defined(HAVE_DBM)
{ "no-db-lookup", no_argument, NULL, 'k' },
+ { "dump-db", no_argument, NULL, 'b' },
#endif
{ NULL, 0, NULL, 0 }
};
opterr = 0;
while ((o = getopt_long(argc, argv, "hVd:avtclrDf"
#if defined(HAVE_GDBM) || defined(HAVE_DBM)
- "k"
+ "kb"
#endif
, long_options, NULL)) >= 0) {
case 'k':
c->no_db_lookup = 1;
break;
+ case 'b':
+ c->command = COMMAND_DUMP_STDB;
+ break;
#endif
default:
fprintf(stderr, "Invalid command line argument: %s\n", argv[optind-1]);
avahi_simple_poll_loop(simple_poll);
ret = 0;
break;
+
+#if defined(HAVE_GDBM) || defined(HAVE_DBM)
+ case COMMAND_DUMP_STDB: {
+ char *t;
+ stdb_setent();
+
+ while ((t = stdb_getent())) {
+ if (config.no_db_lookup)
+ printf("%s\n", t);
+ else
+ printf("%s\n", stdb_lookup(t));
+ }
+
+ ret = 0;
+ break;
+ }
+#endif
}
static DBM *dbm_file = NULL;
#endif
static char *buffer = NULL;
+static char *enum_key = NULL;
static int init(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;
}
<cmd>avahi-browse [<arg>options</arg>] <arg>service-type</arg></cmd>
<cmd>avahi-browse [<arg>options</arg>] <opt>--all</opt></cmd>
<cmd>avahi-browse [<arg>options</arg>] <opt>--browse-domains</opt></cmd>
+ <cmd>avahi-browse [<arg>options</arg>] <opt>--dump-db</opt></cmd>
<cmd>avahi-browse-domains [<arg>options</arg>]</cmd>
</synopsis>
<optdesc><p>Don't lookup services types in service type database.</p></optdesc>
</option>
+ <option>
+ <p><opt>-b | --dump-db</opt></p>
+ <optdesc><p>Dump the service type database (may be combined with -k)</p></optdesc>
+ </option>
+
<option>
<p><opt>-h | --help</opt></p>
<optdesc><p>Show help.</p></optdesc>