]> git.meshlink.io Git - catta/commitdiff
* add tool avahi-utils
authorLennart Poettering <lennart@poettering.net>
Fri, 29 Jul 2005 18:31:27 +0000 (18:31 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 Jul 2005 18:31:27 +0000 (18:31 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@191 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-utils/avahi-dump-all [new file with mode: 0755]
avahi-utils/avahi.py [new file with mode: 0644]
todo

diff --git a/avahi-utils/avahi-dump-all b/avahi-utils/avahi-dump-all
new file mode 100755 (executable)
index 0000000..acd922d
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/python2.4
+# -*-python-*-
+# $Id$ 
+
+import avahi, dbus, gobject
+
+try:
+    import dbus.glib
+except ImportError, e:
+    pass
+
+service_type_browsers = {}
+service_browsers = {}
+
+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 %i.%i:" % (name, type, domain, interface, protocol)
+    print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(txt))
+
+def print_error(err):
+    print "Error:", str(err)
+
+def new_service(interface, protocol, name, type, domain):
+    print "Found service '%s' of type '%s' in domain '%s' on %i.%i." % (name, type, domain, interface, protocol)
+
+    # Asynchronous resolving
+    server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, reply_handler=service_resolved, error_handler=print_error)
+
+def remove_service(interface, protocol, name, type, domain):
+    print "Service '%s' of type '%s' in domain '%s' on %i.%i disappeared." % (name, type, domain, interface, protocol)
+def new_service_type(interface, protocol, type, domain):
+
+    # Are we already browsing this domain for this type? 
+    if service_browsers.has_key((interface, protocol, type, domain)):
+        return
+
+    print "Browsing for services of type '%s' in domain '%s' on %i.%i ..." % (type, domain, interface, protocol)
+    
+    b = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceBrowserNew(interface, protocol, type, domain)), 'org.freedesktop.Avahi.ServiceBrowser')
+    b.connect_to_signal('ItemNew', new_service)
+    b.connect_to_signal('ItemRemove', remove_service)
+
+    service_browsers[(interface, protocol, type, domain)] = b
+
+def browse_domain(interface, protocol, domain):
+
+    # Are we already browsing this domain?
+    if service_type_browsers.has_key((interface, protocol, domain)):
+        return
+
+    print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
+    
+    b = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceTypeBrowserNew(interface, protocol, domain)), 'org.freedesktop.Avahi.ServiceTypeBrowser')
+    b.connect_to_signal('ItemNew', new_service_type)
+
+    service_type_browsers[(interface, protocol, domain)] = b
+
+def new_domain(interface, protocol, domain):
+
+    # We browse for .local anyway...
+    if domain != "local":
+        browse_domain(interface, protocol, domain)
+        
+bus = dbus.SystemBus()
+server = dbus.Interface(bus.get_object("org.freedesktop.Avahi", '/org/freedesktop/Avahi/Server'), 'org.freedesktop.Avahi.Server')
+
+# Explicitly browse .local
+browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
+
+# Browse for other browsable domains
+db = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE)), 'org.freedesktop.Avahi.DomainBrowser')
+db.connect_to_signal('ItemNew', new_domain)
+
+try:
+    gobject.MainLoop().run()
+except KeyboardInterrupt, k:
+    pass
diff --git a/avahi-utils/avahi.py b/avahi-utils/avahi.py
new file mode 100644 (file)
index 0000000..40e9fbf
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/python2.4
+# $Id$
+
+# Some definitions matching those in core.h
+import socket
+
+SERVER_INVALID, SERVER_REGISTERING, SERVER_RUNNING, SERVER_COLLISION, SERVER_SLEEPING = range(-1, 4)
+
+ENTRY_GROUP_UNCOMMITED, ENTRY_GROUP_REGISTERING, ENTRY_GROUP_ESTABLISHED, ENTRY_GROUP_COLLISION = range(-1, 3)
+
+DOMAIN_BROWSER_REGISTER, DOMAIN_BROWSER_REGISTER_DEFAULT, DOMAIN_BROWSER_BROWSE, DOMAIN_BROWSER_BROWSE_DEFAULT, DOMAIN_BROWSER_BROWSE_LEGACY = range(0, 5)
+
+PROTO_INET, PROTO_INET6, PROTO_UNSPEC = socket.AF_INET, socket.AF_INET6, socket.AF_UNSPEC
+
+IF_UNSPEC = -1
diff --git a/todo b/todo
index 4d21a939919b90634ae8bd37f43ff66a51246209..6860e94c5c310859ee04ab456643ebdecce4759b 100644 (file)
--- a/todo
+++ b/todo
@@ -1,6 +1,7 @@
 todo:
 * finish DBUS stuff:
        - introspection
+       - enforce limits
     - allow NUL bytes in TXT records
 * release!