]> code.delx.au - gnu-emacs/blobdiff - lisp/net/zeroconf.el
* net/ange-ftp.el (ange-ftp-get-passwd): Bind
[gnu-emacs] / lisp / net / zeroconf.el
index b3db605403c57395c2a7bb61868a30bfb5217a61..b994cdeaa685510ec5e58c769dff15abbd476df7 100644 (file)
@@ -1,16 +1,16 @@
 ;;; zeroconf.el --- Service browser using Avahi.
 
-;; Copyright (C) 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
 
 ;; Author: Michael Albinus <michael.albinus@gmx.de>
 ;; Keywords: comm, hardware
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,8 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, see
-;; <http://www.gnu.org/licenses/>.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -83,7 +82,7 @@
 
 ;; The function `zeroconf-publish-service' publishes a new service to
 ;; the Avahi daemon.  Although the domain, where to the service is
-;; published, can be specified by this function, it is usally the
+;; published, can be specified by this function, it is usually the
 ;; default domain "local" (also written as nil or "").
 
 ;;   (zeroconf-publish-service
@@ -250,7 +249,7 @@ qualified name, i.e., it contains DOMAIN.
 APROTOCOL stands for the network protocol family ADDRESS is
 encoded (`zeroconf-avahi-protocol-inet4' means INET4,
 `zeroconf-avahi-protocol-inet6' means INET6).  It can be
-different from PROTOCOL, when an adrress resolution has been
+different from PROTOCOL, when an address resolution has been
 requested for another protocol family but the default one.
 
 ADDRESS is the service address, encoded according to the
@@ -335,7 +334,24 @@ The attributes of SERVICE can be retrieved via the functions
     (let ((l-hook (gethash type zeroconf-service-removed-hooks-hash nil)))
       (add-hook 'l-hook function)
       (puthash type l-hook zeroconf-service-removed-hooks-hash)))
-   (t (error "EVENT must be either `:new' or `:removed'."))))
+   (t (error "EVENT must be either `:new' or `:removed'"))))
+
+(defun zeroconf-service-remove-hook (type event function)
+  "Remove FUNCTION from the hook of service type TYPE.
+
+EVENT must be either :new or :removed and has to match the event
+type used when registering FUNCTION."
+  (let* ((table (cond
+                ((equal event :new)
+                 zeroconf-service-added-hooks-hash)
+                ((equal event :removed)
+                 zeroconf-service-removed-hooks-hash)
+                (t (error "EVENT must be either `:new' or `:removed'"))))
+        (l-hook (gethash type table nil)))
+    (remove-hook 'l-hook function)
+    (if l-hook
+       (puthash type l-hook table)
+      (remhash type table))))
 
 (defun zeroconf-get-host ()
   "Returns the local host name as string."
@@ -408,7 +424,7 @@ TYPE. The resulting list has the format
              (elt (nth 9 result))) ;; TXT.
         ;; The TXT field has the signature "aay".  Transform to "as".
         (while elt
-          (setcar elt (apply 'string (car elt)))
+          (setcar elt (dbus-byte-array-to-string (car elt)))
           (setq elt (cdr elt)))
 
         (when nil ;; We discard it, no use so far.
@@ -470,7 +486,7 @@ TYPE. The resulting list has the format
   (nth 9 (zeroconf-resolve-service service)))
 
 \f
-;;; Services signalling.
+;;; Services signaling.
 
 ;; Register for the service type browser.  Service registrations will
 ;; happen in `zeroconf-service-type-browser-handler', when there is an
@@ -483,7 +499,7 @@ DOMAIN is nil, the local domain is used."
             (dbus-ping :system zeroconf-service-avahi)
             (dbus-call-method
              :system zeroconf-service-avahi zeroconf-path-avahi
-             zeroconf-interface-avahi-server "IsNSSSupportAvailable"))
+             zeroconf-interface-avahi-server "GetVersionString"))
 
     ;; Reset all stored values.
     (setq zeroconf-path-avahi-service-type-browser nil
@@ -600,7 +616,7 @@ DOMAIN is nil, the local domain is used."
   ;; The "TXT" field has the signature "aay".  Transform to "as".
   (let ((elt (nth 9 val)))
     (while elt
-      (setcar elt (apply 'string (car elt)))
+      (setcar elt (dbus-byte-array-to-string (car elt)))
       (setq elt (cdr elt))))
   (when zeroconf-debug
     (message "zeroconf-service-resolver-handler: %s %S"
@@ -642,11 +658,7 @@ For the description of arguments, see `zeroconf-resolved-services-hash'."
 
     ;; The TXT field has the signature "as".  Transform to "aay".
     (dolist (elt txt)
-      (let (args)
-       (add-to-list
-        'result
-        (dolist (elt1 (string-to-list elt) (append '(:array) args))
-          (setq args (append args (list :byte elt1)))))))
+      (add-to-list 'result (dbus-string-to-byte-array elt)))
 
     ;; Add the service.
     (dbus-call-method
@@ -674,5 +686,4 @@ For the description of arguments, see `zeroconf-resolved-services-hash'."
 
 (provide 'zeroconf)
 
-;; arch-tag: ea578165-7fa8-44f4-90f0-de3940aec69f
 ;;; zeroconf.el ends here