From e614891d38cae63957d0bfc00d34ecdbad4f8322 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 20 Jan 2006 22:56:11 +0000 Subject: * 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 --- avahi-python/avahi-bookmarks.in | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'avahi-python') 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 += '

Served by %s

' % 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) -- cgit