]> git.meshlink.io Git - catta/commitdiff
* add new API function avahi_nss_support()
authorLennart Poettering <lennart@poettering.net>
Fri, 20 Jan 2006 22:56:11 +0000 (22:56 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Jan 2006 22:56:11 +0000 (22:56 +0000)
* 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

avahi-client/Makefile.am
avahi-client/check-nss-test.c [new file with mode: 0644]
avahi-client/check-nss.c [new file with mode: 0644]
avahi-client/client.h
avahi-daemon/Makefile.am
avahi-daemon/Server.introspect
avahi-daemon/dbus-protocol.c
avahi-daemon/main.c
avahi-daemon/main.h
avahi-python/avahi-bookmarks.in
configure.ac

index 3a033922e78b531f24bcd623bbbf167ad736638d..f45f58d28f79bc18580382797615238388e3a172 100644 (file)
@@ -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 (file)
index 0000000..172b4fa
--- /dev/null
@@ -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 (file)
index 0000000..0a933fa
--- /dev/null
@@ -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;
+}
index 9d737782958e25765062e3b2557c61b0cc36ce1b..098d568b5c6c9034120270f9def61743ff672f37 100644 (file)
@@ -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
index ffcfa584d54710218c5263a7e3fe18f148c81882..e1d64a4157a89b3387fa56cf56010a57d189e6f5 100644 (file)
@@ -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
index 5a3f88bbfa88b7a32f0d70aa2bf6288c70c5b9c5..663561848f7133d7bd241ee218d601c136a101bf 100644 (file)
       <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>
index f14e7461ddf5747c98e463eec17c819607bbff93..2e3fd2f2d594d8cf8a93fd1d7f6b5330912c36f9 100644 (file)
@@ -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))) {
index da198686b6c289db6f605e494e9d4550133d88f5..83272009a042463d8e8f9d8587ab17e340a5bf9c 100644 (file)
@@ -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;
index 951b5f683ff6a17aa427a861338d277119e8206a..77af0d06e2f27d0531999d9a7b085614d4dc9338 100644 (file)
@@ -28,4 +28,6 @@
 extern AvahiServer *avahi_server;
 extern AvahiSimplePoll *simple_poll_api;
 
+extern int nss_support;
+
 #endif
index 74037bbc2298adf4a83dd002f3420a75ac801bef..a31533e24f5a7803e9fc73b8a7b8e4d878a08a9a 100755 (executable)
@@ -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)
index e412a2f95fb63d41302833781f43167230d4d745..efa0d5ed320eecf481fab1b02adb5fa859acdcbc 100644 (file)
@@ -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)