summaryrefslogtreecommitdiffstats
path: root/avahi-utils
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-09 00:32:32 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-09 00:32:32 +0000
commitaa458a0a13d18882354f33c07b0a4e8e82e7a424 (patch)
treefe2798a3f057d2ef9e177a183afec43e973c28a5 /avahi-utils
parent707e763398063186c20d8aba3abdef20e3d39253 (diff)
* Update HACKING
* Change DBUS API: txt record lists are now coded as "aay" instead of "as". Unfortunately this triggers this bug: https://bugs.freedesktop.org/show_bug.cgi?id=4023 If you want to use avahi-publish-service you need to apply the included patch. * change avahi-bookmarks to listen on 127.0.0.1 only * add ftp and https browsing support to avahi-bookmarks, but disable it due to python-dbus bugs * update avahi module for python to provide functions to convert between tring lists and lists of lists of bytes * add avahi_strlst_add_anonymous() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@281 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-utils')
-rwxr-xr-xavahi-utils/avahi-bookmarks.in25
-rwxr-xr-xavahi-utils/avahi-browse.in2
-rwxr-xr-xavahi-utils/avahi-discover.in4
-rwxr-xr-xavahi-utils/avahi-publish-service.in3
-rw-r--r--avahi-utils/avahi/__init__.py39
5 files changed, 60 insertions, 13 deletions
diff --git a/avahi-utils/avahi-bookmarks.in b/avahi-utils/avahi-bookmarks.in
index 72f8e44..953020a 100755
--- a/avahi-utils/avahi-bookmarks.in
+++ b/avahi-utils/avahi-bookmarks.in
@@ -41,6 +41,8 @@ except ImportError:
print "Sorry, to use this tool you need to install twisted."
sys.exit(1)
+urlproto = { "_http._tcp" : "http", "_https._tcp" : "https", "_ftp._tcp" : "ftp" }
+
class AvahiBookmarks(resource.Resource):
isLeaf = True
@@ -49,20 +51,28 @@ class AvahiBookmarks(resource.Resource):
def __init__(self):
resource.Resource.__init__(self)
-
self.bus = dbus.SystemBus()
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
self.version_string = self.server.GetVersionString()
- self.browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "_http._tcp", "local")), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+ self.browse_service_type("_http._tcp")
+
+ # Hurrah! if I enable one of the following lines, python segfaults.
+ #self.browse_service_type("_shttp._tcp")
+ #self.browse_service_type("_ftp._tcp")
- self.browser.connect_to_signal('ItemNew', self.new_service)
- self.browser.connect_to_signal('ItemRemove', self.remove_service)
+ 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)
+ browser.connect_to_signal('ItemNew', self.new_service)
+ browser.connect_to_signal('ItemRemove', self.remove_service)
def find_path(self, txt):
- for k in txt:
+ l = avahi.txt_array_to_string_array(txt)
+
+ for k in l:
if k[:5] == "path=":
return k[5:]
@@ -86,8 +96,7 @@ class AvahiBookmarks(resource.Resource):
path = self.find_path(v[4])
-
- t += '<li><a href="http://%s%s%s">%s</a></li>' % (v[2], port, path, k[2])
+ t += '<li><a href="%s://%s%s%s">%s</a></li>' % (urlproto[k[3]], v[2], port, path, k[2])
t += '</ul>'
@@ -110,7 +119,7 @@ port = 8080
if __name__ == '__main__':
site = server.Site(AvahiBookmarks())
- reactor.listenTCP(port, site)
+ reactor.listenTCP(port, site, interface="127.0.0.1")
print "Now point your web browser to http://localhost:%u/!" % port
diff --git a/avahi-utils/avahi-browse.in b/avahi-utils/avahi-browse.in
index 69a8bfd..3507b41 100755
--- a/avahi-utils/avahi-browse.in
+++ b/avahi-utils/avahi-browse.in
@@ -80,7 +80,7 @@ def siocgifname(interface):
def service_resolved(interface, protocol, name, type, domain, host, aprotocol, address, port, txt):
print "Service data for service '%s' of type '%s' in domain '%s' on %s.%i:" % (name, type, domain, siocgifname(interface), protocol)
- print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(txt))
+ print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
def print_error(err):
print "Error:", str(err)
diff --git a/avahi-utils/avahi-discover.in b/avahi-utils/avahi-discover.in
index 6c78c51..d869761 100755
--- a/avahi-utils/avahi-discover.in
+++ b/avahi-utils/avahi-discover.in
@@ -68,8 +68,8 @@ class Main_window(SimpleGladeApp):
def service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt):
print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, type, domain, interface, protocol)
- print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(txt))
- self.update_label(interface, protocol, name, type, domain, host, aprotocol, address, port, str(txt))
+ print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
+ self.update_label(interface, protocol, name, type, domain, host, aprotocol, address, port, str(avahi.txt_array_to_string_array(txt)))
def print_error(err):
print "Error:", str(err)
diff --git a/avahi-utils/avahi-publish-service.in b/avahi-utils/avahi-publish-service.in
index 50b1908..0f278eb 100755
--- a/avahi-utils/avahi-publish-service.in
+++ b/avahi-utils/avahi-publish-service.in
@@ -88,7 +88,8 @@ def add_service():
print "Adding service '%s' of type '%s' ..." % (name, stype)
group.connect_to_signal('StateChanged', entry_group_state_changed)
- group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, stype, domain, host, dbus.UInt16(port), txt)
+
+ group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, stype, domain, host, dbus.UInt16(port), avahi.string_array_to_txt_array(txt))
group.Commit()
def entry_group_state_changed(state):
diff --git a/avahi-utils/avahi/__init__.py b/avahi-utils/avahi/__init__.py
index c68e177..90d2b76 100644
--- a/avahi-utils/avahi/__init__.py
+++ b/avahi-utils/avahi/__init__.py
@@ -18,7 +18,7 @@
# USA.
# Some definitions matching those in core.h
-import socket
+import socket, dbus
SERVER_INVALID, SERVER_REGISTERING, SERVER_RUNNING, SERVER_COLLISION = range(-1, 3)
@@ -37,3 +37,40 @@ DBUS_INTERFACE_ENTRY_GROUP = DBUS_NAME + ".EntryGroup"
DBUS_INTERFACE_DOMAIN_BROWSER = DBUS_NAME + ".DomainBrowser"
DBUS_INTERFACE_SERVICE_TYPE_BROWSER = DBUS_NAME + ".ServiceTypeBrowser"
DBUS_INTERFACE_SERVICE_BROWSER = DBUS_NAME + ".ServiceBrowser"
+
+def byte_array_to_string(s):
+ r = ""
+
+ for c in s:
+
+ if c >= 32 and c < 127:
+ r += "%c" % c
+ else:
+ r += "."
+
+ return r
+
+def txt_array_to_string_array(t):
+ l = []
+
+ for s in t:
+ l.append(byte_array_to_string(s))
+
+ return l
+
+
+def string_to_byte_array(s):
+ r = []
+
+ for c in s:
+ r.append(dbus.Byte(ord(c)))
+
+ return r
+
+def string_array_to_txt_array(t):
+ l = []
+
+ for s in t:
+ l.append(string_to_byte_array(s))
+
+ return l