summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-01-20 22:56:11 +0000
committerLennart Poettering <lennart@poettering.net>2006-01-20 22:56:11 +0000
commite614891d38cae63957d0bfc00d34ecdbad4f8322 (patch)
tree55336f0efd0999e0ed17bec823470844587fe65c
parent7d59b3ba820c19488b0637b5dd9798deb68fb0dc (diff)
* add new API function avahi_nss_support()
* add new DBUS method Server.IsNSSSupportAvailable() * add support for IsNSSSupportAvailabke() to avahi-bookmarks git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1092 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--avahi-client/Makefile.am13
-rw-r--r--avahi-client/check-nss-test.c32
-rw-r--r--avahi-client/check-nss.c57
-rw-r--r--avahi-client/client.h3
-rw-r--r--avahi-daemon/Makefile.am9
-rw-r--r--avahi-daemon/Server.introspect4
-rw-r--r--avahi-daemon/dbus-protocol.c8
-rw-r--r--avahi-daemon/main.c6
-rw-r--r--avahi-daemon/main.h2
-rwxr-xr-xavahi-python/avahi-bookmarks.in28
-rw-r--r--configure.ac6
11 files changed, 157 insertions, 11 deletions
diff --git a/avahi-client/Makefile.am b/avahi-client/Makefile.am
index 3a03392..f45f58d 100644
--- a/avahi-client/Makefile.am
+++ b/avahi-client/Makefile.am
@@ -35,7 +35,8 @@ noinst_PROGRAMS = \
client-test \
srv-test \
xdg-config-test \
- rr-test
+ rr-test \
+ check-nss-test
endif
@@ -48,6 +49,7 @@ libavahi_client_la_SOURCES = \
resolver.c \
publish.h lookup.h \
xdg-config.c xdg-config.h \
+ check-nss.c \
../avahi-common/dbus.c ../avahi-common/dbus.h \
../avahi-common/dbus-watch-glue.c ../avahi-common/dbus-watch-glue.h
@@ -71,4 +73,13 @@ xdg_config_test_SOURCES = xdg-config-test.c xdg-config.c xdg-config.h
xdg_config_test_CFLAGS = $(AM_CFLAGS)
xdg_config_test_LDADD = $(AM_LDADD)
+check_nss_test_SOURCES = check-nss.c check-nss-test.c client.h
+check_nss_test_CFLAGS = $(AM_CFLAGS)
+check_nss_test_LDADD = $(AM_LDADD)
+
+if HAVE_DLOPEN
+check_nss_test_LDADD += -ldl
+libavahi_client_la_LIBADD += -ldl
+endif
+
endif
diff --git a/avahi-client/check-nss-test.c b/avahi-client/check-nss-test.c
new file mode 100644
index 0000000..172b4fa
--- /dev/null
+++ b/avahi-client/check-nss-test.c
@@ -0,0 +1,32 @@
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <avahi-client/client.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ printf("NSS Support available: %s\n", avahi_nss_support() ? "yes" : "no");
+}
diff --git a/avahi-client/check-nss.c b/avahi-client/check-nss.c
new file mode 100644
index 0000000..0a933fa
--- /dev/null
+++ b/avahi-client/check-nss.c
@@ -0,0 +1,57 @@
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_DLOPEN
+#include <dlfcn.h>
+#endif
+#include <stdlib.h>
+
+#include "client.h"
+
+int avahi_nss_support(void) {
+ int b = 0;
+
+#ifdef HAVE_DLOPEN
+ static const char * const libs[] = {
+ "libnss_mdns.so.2",
+ "libnss_mdns4.so.2",
+ "libnss_mdns6.so.2",
+ NULL };
+
+ const char * const *l;
+
+ for (l = libs; *l; l++) {
+ void *dl;
+
+ if ((dl = dlopen(*l, RTLD_LAZY))) {
+ b = 1;
+ dlclose(dl);
+ break;
+ }
+ }
+#endif
+
+ return b;
+}
diff --git a/avahi-client/client.h b/avahi-client/client.h
index 9d73778..098d568 100644
--- a/avahi-client/client.h
+++ b/avahi-client/client.h
@@ -85,6 +85,9 @@ int avahi_client_errno (AvahiClient*);
/** Return the local service cookie. returns AVAHI_SERVICE_COOKIE_INVALID on failure. */
uint32_t avahi_client_get_local_service_cookie(AvahiClient *client);
+/** Return 1 if gethostbyname() supports mDNS lookups, 0 otherwise */
+int avahi_nss_support(void);
+
AVAHI_C_DECL_END
#endif
diff --git a/avahi-daemon/Makefile.am b/avahi-daemon/Makefile.am
index ffcfa58..e1d64a4 100644
--- a/avahi-daemon/Makefile.am
+++ b/avahi-daemon/Makefile.am
@@ -100,12 +100,17 @@ avahi_daemon_SOURCES += \
dbus-sync-host-name-resolver.c \
dbus-sync-service-resolver.c \
dbus-record-browser.c \
- ../avahi-common/dbus.c ../avahi-common/dbus.h \
- ../avahi-common/dbus-watch-glue.c ../avahi-common/dbus-watch-glue.h
+ ../avahi-common/dbus.c ../avahi-common/dbus.h \
+ ../avahi-common/dbus-watch-glue.c ../avahi-common/dbus-watch-glue.h \
+ ../avahi-client/check-nss.c
avahi_daemon_LDADD += \
$(DBUS_LIBS)
+if HAVE_DLOPEN
+avahi_daemon_LDADD += -ldl
+endif
+
avahi_daemon_CFLAGS += $(DBUS_CFLAGS)
dbusservice_DATA = avahi-dbus.conf
diff --git a/avahi-daemon/Server.introspect b/avahi-daemon/Server.introspect
index 5a3f88b..6635618 100644
--- a/avahi-daemon/Server.introspect
+++ b/avahi-daemon/Server.introspect
@@ -51,6 +51,10 @@
<arg name="name" type="s" direction="out"/>
</method>
+ <method name="IsNSSSupportAvailable">
+ <arg name="yes" type="b" direction="out"/>
+ </method>
+
<method name="GetState">
<arg name="state" type="i" direction="out"/>
</method>
diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c
index f14e746..2e3fd2f 100644
--- a/avahi-daemon/dbus-protocol.c
+++ b/avahi-daemon/dbus-protocol.c
@@ -251,6 +251,14 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH
return avahi_dbus_respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server));
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "IsNSSSupportAvailable")) {
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::IsNSSSupportAvailable message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_boolean(c, m, nss_support);
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) {
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c
index da19868..8327200 100644
--- a/avahi-daemon/main.c
+++ b/avahi-daemon/main.c
@@ -75,6 +75,7 @@
AvahiServer *avahi_server = NULL;
AvahiSimplePoll *simple_poll_api = NULL;
static char *argv0 = NULL;
+int nss_support = 0;
typedef enum {
DAEMON_RUN,
@@ -697,6 +698,8 @@ static void signal_callback(AvahiWatch *watch, AVAHI_GCC_UNUSED int fd, AVAHI_GC
}
}
+/* Imported from ../avahi-client/nss-check.c */
+int avahi_nss_support(void);
static int run_server(DaemonConfig *c) {
int r = -1;
@@ -707,6 +710,9 @@ static int run_server(DaemonConfig *c) {
assert(c);
+ if (!(nss_support = avahi_nss_support()))
+ avahi_log_warn("WARNING: No NSS support for mDNS detected, consider installing nss-mdns!");
+
if (!(simple_poll_api = avahi_simple_poll_new())) {
avahi_log_error("Failed to create main loop object.");
goto finish;
diff --git a/avahi-daemon/main.h b/avahi-daemon/main.h
index 951b5f6..77af0d0 100644
--- a/avahi-daemon/main.h
+++ b/avahi-daemon/main.h
@@ -28,4 +28,6 @@
extern AvahiServer *avahi_server;
extern AvahiSimplePoll *simple_poll_api;
+extern int nss_support;
+
#endif
diff --git a/avahi-python/avahi-bookmarks.in b/avahi-python/avahi-bookmarks.in
index 74037bb..a31533e 100755
--- a/avahi-python/avahi-bookmarks.in
+++ b/avahi-python/avahi-bookmarks.in
@@ -45,7 +45,7 @@ urlproto = { "_http._tcp" : "http", "_https._tcp" : "https", "_ftp._tcp" : "ftp
port = 8080
address = "127.0.0.1"
-use_host_names = False
+use_host_names = None
domain = "local"
class AvahiBookmarks(resource.Resource):
@@ -53,7 +53,7 @@ class AvahiBookmarks(resource.Resource):
services = {}
- def __init__(self):
+ def __init__(self, use_host_names):
resource.Resource.__init__(self)
self.bus = dbus.SystemBus()
@@ -65,6 +65,14 @@ class AvahiBookmarks(resource.Resource):
self.browse_service_type("_https._tcp")
self.browse_service_type("_ftp._tcp")
+ if use_host_names is None:
+ try:
+ self.use_host_names = self.server.IsNSSSupportAvailable()
+ except:
+ self.use_host_names = False
+ else:
+ self.use_host_names = use_host_names
+
def browse_service_type(self, stype):
global domain
@@ -109,14 +117,14 @@ class AvahiBookmarks(resource.Resource):
t += '<hr noshade/><p style="font-size: 8; font-family: sans-serif">Served by %s</p></body></html>' % self.version_string
- return t
+ return str(t)
def new_service(self, interface, protocol, name, type, domain, flags):
interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0))
- if use_host_names:
+ if self.use_host_names:
h = host
else:
if aprotocol == avahi.PROTO_INET6:
@@ -135,12 +143,13 @@ def usage(retval = 0):
print " -h --help Show this help"
print " -p --port PORT Specify the port to use (default %u)" % port
print " -a --address ADDRESS Specify the address to bind to (default %s)" % address
- print " -H --host-names Show all services, regardless of the type"
+ print " -H --host-names Show links with real hostnames"
+ print " -A --addresses Show links with numeric IP addresses"
print " -d --domain DOMAIN Specify the domain to browse"
sys.exit(retval)
try:
- opts, args = getopt.getopt(sys.argv[1:], "hp:a:Hd:", ["help", "port=", "address=", "host-names", "domain="])
+ opts, args = getopt.getopt(sys.argv[1:], "hp:a:HAd:", ["help", "port=", "address=", "host-names", "addresses", "domain="])
except getopt.GetoptError:
usage(2)
@@ -157,10 +166,13 @@ for o, a in opts:
if o in ("-H", "--host-names"):
use_host_names = True
+ if o in ("-A", "--addresses"):
+ use_host_names = False
+
if o in ("-d", "--domain"):
domain = a
-
-site = server.Site(AvahiBookmarks())
+
+site = server.Site(AvahiBookmarks(use_host_names))
reactor.listenTCP(port, site, interface=address)
print "Now point your web browser to http://%s:%u/!" % (address, port)
diff --git a/configure.ac b/configure.ac
index e412a2f..efa0d5e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,6 +235,12 @@ if test "x$enable_chroot" = "xyes" ; then
AC_DEFINE([ENABLE_CHROOT], 1, [Enable chroot() usage])
fi
+AC_CHECK_LIB(dl, dlopen, [ AC_CHECK_HEADERS(dlfcn.h, HAVE_DLOPEN=yes, HAVE_DLOPEN=no) ], HAVE_DLOPEN=no)
+if test "x$HAVE_DLOPEN" = "xyes" ; then
+ AC_DEFINE([HAVE_DLOPEN],1,[Have dlopen()])
+fi
+AM_CONDITIONAL(HAVE_DLOPEN, test "x$HAVE_DLOPEN" = "xyes")
+
# Check for pkg-config manually first, as if its not installed the
# PKG_PROG_PKG_CONFIG macro won't be defined.
AC_CHECK_PROG(have_pkg_config, pkg-config, yes, no)