X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-utils%2Favahi-bookmarks.in;h=df36f49a254f2464f6bdedff18526b184dd399b2;hb=bb14e0a8aa3173c8a6d80b1a9c8b300a452ee9f1;hp=39c1d8c02aeb9dfdbafcdf1fe30aad9c89df87f3;hpb=be10803e4dee7cb430423248f12685353c1ea166;p=catta diff --git a/avahi-utils/avahi-bookmarks.in b/avahi-utils/avahi-bookmarks.in index 39c1d8c..df36f49 100755 --- a/avahi-utils/avahi-bookmarks.in +++ b/avahi-utils/avahi-bookmarks.in @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. -import sys +import sys, getopt try: import avahi, gobject, dbus @@ -43,6 +43,11 @@ except ImportError: urlproto = { "_http._tcp" : "http", "_https._tcp" : "https", "_ftp._tcp" : "ftp" } +port = 8080 +address = "127.0.0.1" +use_host_names = False +domain = "local" + class AvahiBookmarks(resource.Resource): isLeaf = True @@ -64,7 +69,9 @@ class AvahiBookmarks(resource.Resource): def browse_service_type(self, stype): - browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, "local")), avahi.DBUS_INTERFACE_SERVICE_BROWSER) + global domain + + browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_BROWSER) browser.connect_to_signal('ItemNew', self.new_service) browser.connect_to_signal('ItemRemove', self.remove_service) @@ -74,7 +81,10 @@ class AvahiBookmarks(resource.Resource): for k in l: if k[:5] == "path=": - return k[5:] + if k[5:].startswith("/"): + return k[5:] + else: + return "/" + k[5:] return "/" @@ -95,13 +105,7 @@ class AvahiBookmarks(resource.Resource): port = ':%i' % v[3] path = self.find_path(v[4]) - - if v[1] == avahi.PROTO_INET6: - ip = "[" + v[2] + "]" - else: - ip = v[2] - - t += '
  • %s
  • ' % (urlproto[k[3]], ip, port, path, k[2]) + t += '
  • %s
  • ' % (urlproto[k[3]], v[2], port, path, k[2]) t += '' @@ -110,25 +114,60 @@ class AvahiBookmarks(resource.Resource): return t - def new_service(self, interface, protocol, name, type, domain): + def new_service(self, interface, protocol, name, type, domain, flags): - interface, protocol, name, type, domain, host, aprotocol, address, port, txt = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC) + interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, 0) + + if use_host_names: + h = host + else: + if aprotocol == avahi.PROTO_INET6: + h = "[" + address + "]" + else: + h = address - self.services[(interface, protocol, name, type, domain)] = (host, aprotocol, address, port, txt) + self.services[(interface, protocol, name, type, domain)] = (host, aprotocol, h, port, txt) def remove_service(self, interface, protocol, name, type, domain): del self.services[(interface, protocol, name, type, domain)] -port = 8080 +def usage(retval = 0): + print "%s [options]\n" % sys.argv[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 " -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="]) +except getopt.GetoptError: + usage(2) + +for o, a in opts: + if o in ("-h", "--help"): + usage() + + if o in ("-p", "--port"): + port = int(a) -if __name__ == '__main__': - site = server.Site(AvahiBookmarks()) - reactor.listenTCP(port, site, interface="127.0.0.1") + if o in ("-a", "--address"): + address = a - print "Now point your web browser to http://localhost:%u/!" % port + if o in ("-H", "--host-names"): + use_host_names = True - try: - reactor.run() - except KeyboardInterrupt, k: - pass + if o in ("-d", "--domain"): + domain = a + +site = server.Site(AvahiBookmarks()) +reactor.listenTCP(port, site, interface=address) + +print "Now point your web browser to http://%s:%u/!" % (address, port) + +try: + reactor.run() +except KeyboardInterrupt, k: + pass