Function: zeroconf-resolve-service

zeroconf-resolve-service is a byte-compiled function defined in zeroconf.el.gz.

Signature

(zeroconf-resolve-service SERVICE)

Documentation

Return all service attributes SERVICE as list.

NAME must be a string. The service must be of service type TYPE. The resulting list has the format

  (INTERFACE PROTOCOL NAME TYPE DOMAIN HOST APROTOCOL ADDRESS PORT TXT FLAGS).

Source Code

;; Defined in /usr/src/emacs/lisp/net/zeroconf.el.gz
(defun zeroconf-resolve-service (service)
  "Return all service attributes SERVICE as list.
NAME must be a string.  The service must be of service type
TYPE.  The resulting list has the format

  (INTERFACE PROTOCOL NAME TYPE DOMAIN HOST APROTOCOL ADDRESS PORT TXT FLAGS)."
  (let* ((name (zeroconf-service-name service))
	 (type (zeroconf-service-type service))
	 (key (concat name "/" type)))

    (or
     ;; Check whether we know this service already.
     (gethash key zeroconf-resolved-services-hash nil)

     ;; Resolve the service.  We don't propagate D-Bus errors.
     (dbus-ignore-errors
       (let* ((result
	       (dbus-call-method
		:system zeroconf-service-avahi zeroconf-path-avahi
		zeroconf-interface-avahi-server "ResolveService"
		zeroconf-avahi-interface-unspec
		zeroconf-avahi-protocol-unspec
		name type
		zeroconf-avahi-current-domain
		zeroconf-avahi-protocol-unspec
		zeroconf-avahi-flags-unspec))
	      (elt (nth 9 result))) ;; TXT.
	 ;; The TXT field has the signature "aay".  Transform to "as".
	 (while elt
	   (setcar elt (dbus-byte-array-to-string (car elt)))
	   (setq elt (cdr elt)))

	 (when nil ;; We discard it, no use so far.
	 ;; Register a service resolver.
	 (let ((object-path (zeroconf-register-service-resolver name type)))
	   ;; Register the signals.
	   (dolist (member '("Found" "Failure"))
	     (dbus-register-signal
	      :system zeroconf-service-avahi object-path
	      zeroconf-interface-avahi-service-resolver member
	      'zeroconf-service-resolver-handler)))
	 )

	 ;; Return the resolved service.
	 (puthash key result zeroconf-resolved-services-hash))))))