Function: zeroconf-publish-service

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

Signature

(zeroconf-publish-service NAME TYPE DOMAIN HOST PORT ADDRESS TXT)

Documentation

Publish a service at the Avahi daemon.

For the description of arguments, see zeroconf-resolved-services-hash.

Source Code

;; Defined in /usr/src/emacs/lisp/net/zeroconf.el.gz
;;; Services publishing.

(defun zeroconf-publish-service (name type domain host port address txt)
  "Publish a service at the Avahi daemon.
For the description of arguments, see `zeroconf-resolved-services-hash'."
  ;; NAME and TYPE must not be empty.
  (when (zerop (length name))
    (error "Invalid argument NAME: %s" name))
  (when (zerop (length type))
    (error "Invalid argument TYPE: %s" type))

  ;; Set default values for DOMAIN, HOST and PORT.
  (when (zerop (length domain))
    (setq domain (zeroconf-get-domain)))
  (when (zerop (length host))
    (setq host (zeroconf-get-host-domain)))
  (when (null port)
    (setq port 0))

  ;; Create an entry in the daemon.
  (let ((object-path
	 (dbus-call-method
	  :system zeroconf-service-avahi zeroconf-path-avahi
	  zeroconf-interface-avahi-server "EntryGroupNew"))
	result)

    ;; The TXT field has the signature "as".  Transform to "aay".
    (dolist (elt txt)
      (cl-pushnew (dbus-string-to-byte-array elt) result :test #'equal))

    ;; Add the service.
    (dbus-call-method
     :system zeroconf-service-avahi object-path
     zeroconf-interface-avahi-entry-group "AddService"
     zeroconf-avahi-interface-unspec
     zeroconf-avahi-protocol-unspec
     zeroconf-avahi-flags-unspec
     name type domain host :uint16 port (append '(:array) result))

    ;; Add the address.
    (unless (zerop (length address))
      (dbus-call-method
       :system zeroconf-service-avahi object-path
       zeroconf-interface-avahi-entry-group "AddAddress"
       zeroconf-avahi-interface-unspec
       zeroconf-avahi-protocol-unspec
       zeroconf-avahi-flags-unspec
       host address))

    ;; Make it persistent in the daemon.
    (dbus-call-method
     :system zeroconf-service-avahi object-path
     zeroconf-interface-avahi-entry-group "Commit")))