From 854f901f491ccda79aee11edc3d59109cb229d28 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Oct 2005 21:27:40 +0000 Subject: * avahi-utils: replace python avahi-browse with a version written in C. * remove -Wunused from GCC command line and use "unused" attribute instead * remove AVAHI_CLIENT_S_FAILURE and AVAHI_CLIENT_S_INVALID since these event's are never forwarded to the client anyway * make use of AVAHI_GCC_NORETURN * really send eror code with StateChange DBUS signals * ignore EINTR in avahi_simple_poll_loop() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@879 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-utils/Makefile.am | 16 +++-- avahi-utils/avahi-browse.in | 166 -------------------------------------------- 2 files changed, 10 insertions(+), 172 deletions(-) delete mode 100755 avahi-utils/avahi-browse.in (limited to 'avahi-utils') diff --git a/avahi-utils/Makefile.am b/avahi-utils/Makefile.am index 1e10f25..0c5b711 100644 --- a/avahi-utils/Makefile.am +++ b/avahi-utils/Makefile.am @@ -20,7 +20,6 @@ EXTRA_DIST = \ avahi-publish-address.in \ avahi-publish-service.in \ - avahi-browse.in \ avahi-bookmarks.in \ avahi-resolve-host-name.in \ avahi-resolve-address.in \ @@ -36,7 +35,6 @@ if HAVE_PYGTK pythonscripts = \ avahi-publish-address \ avahi-publish-service \ - avahi-browse \ avahi-bookmarks \ avahi-resolve-host-name \ avahi-resolve-address \ @@ -62,10 +60,6 @@ avahi-publish-service: avahi-publish-service.in sed -e 's,@PYTHON\@,$(PYTHON),g' $< > $@ chmod +x $@ -avahi-browse: avahi-browse.in - sed -e 's,@PYTHON\@,$(PYTHON),g' $< > $@ - chmod +x $@ - avahi-bookmarks: avahi-bookmarks.in sed -e 's,@PYTHON\@,$(PYTHON),g' $< > $@ chmod +x $@ @@ -84,3 +78,13 @@ CLEANFILES = $(pythonscripts) $(desktop_DATA) endif endif endif + +if HAVE_DBUS + +bin_PROGRAMS = avahi-browse + +avahi_browse_SOURCES = avahi-browse.c sigint.c +avahi_browse_CFLAGS = $(AM_CFLAGS) +avahi_browse_LDADD = $(AM_LDADD) ../avahi-client/libavahi-client.la ../avahi-common/libavahi-common.la + +endif diff --git a/avahi-utils/avahi-browse.in b/avahi-utils/avahi-browse.in deleted file mode 100755 index 1dd3376..0000000 --- a/avahi-utils/avahi-browse.in +++ /dev/null @@ -1,166 +0,0 @@ -#!@PYTHON@ -# -*-python-*- -# $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 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 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. - -import sys, getopt - -try: - import avahi, gobject, dbus, avahi.ServiceTypeDatabase -except ImportError: - print "Sorry, to use this tool you need to install Avahi, pygtk and python-dbus." - sys.exit(1) - -try: - import dbus.glib -except ImportError, e: - pass - -def usage(retval = 0): - print "%s [options] \n" % sys.argv[0] - print " -h --help Show this help" - print " -d --domain The domain to browse" - print " -a --all Show all services, regardless of the type" - sys.exit(retval) - -try: - opts, args = getopt.getopt(sys.argv[1:], "hd:a", ["help", "domain=", "all"]) -except getopt.GetoptError: - usage(2) - -domain = None -stype = None -show_all = False - -for o, a in opts: - if o in ("-h", "--help"): - usage() - - if o in ("-d", "--domain"): - domain = a - - if o in ("-a", "--all"): - show_all = True - -if len(args) > 1: - usage(2) - -if len(args) >= 1: - stype = args[0]; - -if stype is None and not show_all: - usage(2) - -service_type_browsers = {} -service_browsers = {} - -service_type_db = avahi.ServiceTypeDatabase.ServiceTypeDatabase() - -def siocgifname(interface): - global server - - if interface <= 0: - return "any" - else: - return server.GetNetworkInterfaceNameByIndex(interface) - -def lookup_service_type(stype): - global service_type_db - - try: - return service_type_db[stype] - except KeyError: - return "n/a" - -def service_resolved(interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): - print "Service data for service '%s' of type '%s' (%s) in domain '%s' on %s.%i:" % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol) - 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) - -def new_service(interface, protocol, name, stype, domain, flags): - global server - - print "Found service '%s' of type '%s' (%s) in domain '%s' on %s.%i." % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol) - - # Asynchronous resolving - server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), reply_handler=service_resolved, error_handler=print_error) - -def remove_service(interface, protocol, name, stype, domain, flags): - print "Service '%s' of type '%s' (%s) in domain '%s' on %s.%i disappeared." % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol) - -def new_service_type(interface, protocol, stype, domain, flags): - global server, service_browsers - - # Are we already browsing this domain for this type? - if service_browsers.has_key((interface, protocol, stype, domain)): - return - - print "Browsing for services of type '%s' (%s) in domain '%s' on %s.%i ..." % (stype, lookup_service_type(stype), domain, siocgifname(interface), protocol) - - b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, stype, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER) - b.connect_to_signal('ItemNew', new_service) - b.connect_to_signal('ItemRemove', remove_service) - - service_browsers[(interface, protocol, stype, domain)] = b - -def browse_domain(interface, protocol, domain): - global server, service_type_browsers, stype - - # Are we already browsing this domain? - if service_type_browsers.has_key((interface, protocol, domain)): - return - - if stype is None: - print "Browsing domain '%s' on %s.%i ..." % (domain, siocgifname(interface), protocol) - - b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER) - b.connect_to_signal('ItemNew', new_service_type) - - service_type_browsers[(interface, protocol, domain)] = b - else: - new_service_type(interface, protocol, stype, domain, dbus.UInt32(0)) - -def new_domain(interface, protocol, domain, flags): - - # We browse for .local anyway... - if domain != "local": - browse_domain(interface, protocol, domain) - - -bus = dbus.SystemBus() -server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) - -if domain is None: - # Explicitly browse .local - browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local") - - # Browse for other browsable domains - db = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, dbus.UInt32(0))), avahi.DBUS_INTERFACE_DOMAIN_BROWSER) - db.connect_to_signal('ItemNew', new_domain) - -else: - # Just browse the domain the user wants us to browse - browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain) - -try: - gobject.MainLoop().run() -except KeyboardInterrupt, k: - pass -- cgit