annotate lisp/net/zeroconf.el @ 103480:7d47110e2e71

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Fri, 19 Jun 2009 00:45:43 +0000
parents a9dc0e7c3f2b
children e29040dd9586
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
1 ;;; zeroconf.el --- Service browser using Avahi.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
2
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94677
diff changeset
3 ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
4
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
6 ;; Keywords: comm, hardware
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
7
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
9
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94624
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94624
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94624
diff changeset
13 ;; (at your option) any later version.
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
14
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
18 ;; GNU General Public License for more details.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
19
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94624
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
22
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
23 ;;; Commentary:
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
24
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
25 ;; This package provides an interface to the Avahi, the zeroconf
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
26 ;; daemon under GNU/Linux. The communication mean with Avahi is
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
27 ;; D-Bus.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
28
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
29 ;; In order to activate this package, you must add the following code
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
30 ;; into your .emacs:
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
31
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
32 ;; (require 'zeroconf)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
33 ;; (zeroconf-init "dns-sd.org")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
34
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
35 ;; "dns-sd.org" is an example the domain you wish to resolve services
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
36 ;; for. It can also be nil or "", which means the default local
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
37 ;; domain "local".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
38
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
39 ;; The `zeroconf-init' function installs several handlers, which are
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
40 ;; activated by D-Bus signals sent from the Avahi daemon.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
41 ;; Immediately, when a service is added or removed in the domain, a
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
42 ;; corresponding handler in Emacs is called.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
43
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
44 ;; Service Discovery
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
45 ;; -----------------
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
46
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
47 ;; The main purpose of zeroconf is service discovery. This means,
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
48 ;; that services are detected as soon as they appear or disappear in a
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
49 ;; given domain. A service is offered by a network device. It is
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
50 ;; assigned to a service type.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
51
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
52 ;; In order to see all offered service types of the initialized
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
53 ;; domain, you can call
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
54
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
55 ;; (zeroconf-list-service-types)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
56
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
57 ;; Service types are described at <http://www.dns-sd.org/ServiceTypes.html>.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
58 ;; Detected services for a given service type, let's say "_ipp._tcp",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
59 ;; are listed by
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
60
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
61 ;; (zeroconf-list-services "_ipp._tcp")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
62
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
63 ;; It is possible to register an own handler (function) to be called
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
64 ;; when a service has been added or removed in the domain. The
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
65 ;; service type "_ipp._tcp" is used for printer services supporting
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
66 ;; the Internet Printing Protocol.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
67
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
68 ;; (defun my-add-printer (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
69 ;; (message "Printer `%s' detected" (zeroconf-service-name service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
70
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
71 ;; (defun my-remove-printer (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
72 ;; (message "Printer `%s' removed" (zeroconf-service-name service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
73
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
74 ;; (zeroconf-service-add-hook "_ipp._tcp" :new 'my-add-printer)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
75 ;; (zeroconf-service-add-hook "_ipp._tcp" :removed 'my-remove-printer)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
76
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
77 ;; There are several functions returning information about a service,
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
78 ;; see the doc string of `zeroconf-service-add-hook'.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
79
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
80 ;; Service Publishing
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
81 ;; ------------------
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
82
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
83 ;; The function `zeroconf-publish-service' publishes a new service to
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
84 ;; the Avahi daemon. Although the domain, where to the service is
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
85 ;; published, can be specified by this function, it is usally the
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
86 ;; default domain "local" (also written as nil or "").
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
87
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
88 ;; (zeroconf-publish-service
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
89 ;; "Example service" ;; Service name.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
90 ;; "_example._tcp" ;; Service type.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
91 ;; nil ;; Default domain ("local").
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
92 ;; nil ;; Default host (concat (getenv "HOST") ".local").
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
93 ;; 111 ;; Port number of the host, the service is offered.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
94 ;; "1.2.3.4" ;; IPv4 address of the host.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
95 ;; '("version=1.0" ;; TXT fields describing the service.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
96 ;; "abc=456"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
97
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
98 ;; The lifetime of a published service is the lifetime of Emacs.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
99
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
100 ;;; Code:
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
101
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
102 ;; Pacify byte-compiler. D-Bus support in the Emacs core can be
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
103 ;; disabled with configuration option "--without-dbus". Declare used
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
104 ;; subroutines and variables of `dbus' therefore.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
105 (eval-when-compile
94624
c199ac3029ed (dbus-call-method, dbus-register-signal)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94144
diff changeset
106 (require 'cl))
c199ac3029ed (dbus-call-method, dbus-register-signal)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94144
diff changeset
107
c199ac3029ed (dbus-call-method, dbus-register-signal)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94144
diff changeset
108 (declare-function dbus-call-method "dbusbind.c")
c199ac3029ed (dbus-call-method, dbus-register-signal)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94144
diff changeset
109 (declare-function dbus-register-signal "dbusbind.c")
c199ac3029ed (dbus-call-method, dbus-register-signal)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94144
diff changeset
110 (defvar dbus-debug)
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
111
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
112 (require 'dbus)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
113
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
114 (defvar zeroconf-debug nil
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
115 "Write messages during service discovery")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
116
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
117 (defconst zeroconf-service-avahi "org.freedesktop.Avahi"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
118 "The D-Bus name used to talk to Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
119
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
120 (defconst zeroconf-path-avahi "/"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
121 "The D-Bus root object path used to talk to Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
122
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
123 (defvar zeroconf-path-avahi-service-type-browser nil
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
124 "The D-Bus object path used to talk to the Avahi service type browser.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
125
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
126 (defvar zeroconf-path-avahi-service-browser-hash (make-hash-table :test 'equal)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
127 "The D-Bus object paths used to talk to the Avahi service browser.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
128
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
129 (defvar zeroconf-path-avahi-service-resolver-hash (make-hash-table :test 'equal)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
130 "The D-Bus object paths used to talk to the Avahi service resolver.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
131
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
132 ;; Methods: "Free", "Commit", "Reset", "GetState", "IsEmpty",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
133 ;; "AddService", "AddServiceSubtype", "UpdateServiceTxt", "AddAddress"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
134 ;; and "AddRecord".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
135 ;; Signals: "StateChanged".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
136 (defconst zeroconf-interface-avahi-entry-group
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
137 (concat zeroconf-service-avahi ".EntryGroup")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
138 "The D-Bus entry group interface exported by Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
139
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
140 ;; Methods: "GetVersionString", "GetAPIVersion", "GetHostName",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
141 ;; "SetHostName", "GetHostNameFqdn", "GetDomainName",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
142 ;; "IsNSSSupportAvailable", "GetState", "GetLocalServiceCookie",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
143 ;; "GetAlternativeHostName", "GetAlternativeServiceName",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
144 ;; "GetNetworkInterfaceNameByIndex", "GetNetworkInterfaceIndexByName",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
145 ;; "ResolveHostName", "ResolveAddress", "ResolveService",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
146 ;; "EntryGroupNew", "DomainBrowserNew", "ServiceTypeBrowserNew",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
147 ;; "ServiceBrowserNew", "ServiceResolverNew", "HostNameResolverNew",
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
148 ;; "AddressResolverNew" and "RecordBrowserNew".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
149 ;; Signals: "StateChanged".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
150 (defconst zeroconf-interface-avahi-server
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
151 (concat zeroconf-service-avahi ".Server")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
152 "The D-Bus server interface exported by Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
153
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
154 ;; Methods: "Free".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
155 ;; Signals: "ItemNew", "ItemRemove", "CacheExhausted", "AllForNow" and
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
156 ;; "Failure".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
157 (defconst zeroconf-interface-avahi-service-type-browser
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
158 (concat zeroconf-service-avahi ".ServiceTypeBrowser")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
159 "The D-Bus service type browser interface exported by Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
160
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
161 ;; Methods: "Free".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
162 ;; Signals: "ItemNew", "ItemRemove", "CacheExhausted", "AllForNow" and
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
163 ;; "Failure".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
164 (defconst zeroconf-interface-avahi-service-browser
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
165 (concat zeroconf-service-avahi ".ServiceBrowser")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
166 "The D-Bus service browser interface exported by Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
167
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
168 ;; Methods: "Free".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
169 ;; Available signals are "Found" and "Failure".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
170 (defconst zeroconf-interface-avahi-service-resolver
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
171 (concat zeroconf-service-avahi ".ServiceResolver")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
172 "The D-Bus service resolver interface exported by Avahi.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
173
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
174 (defconst zeroconf-avahi-interface-unspec -1
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
175 "Wildcard Avahi interface spec.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
176
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
177 (defconst zeroconf-avahi-protocol-unspec -1
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
178 "Wildcard Avahi protocol spec.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
179
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
180 (defconst zeroconf-avahi-protocol-inet4 0
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
181 "Avahi INET4 address protocol family.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
182
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
183 (defconst zeroconf-avahi-protocol-inet6 1
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
184 "Avahi INET6 address protocol family.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
185
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
186 (defconst zeroconf-avahi-domain-unspec ""
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
187 "Empty Avahi domain.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
188
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
189 (defvar zeroconf-avahi-current-domain zeroconf-avahi-domain-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
190 "Domain name services are resolved for.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
191
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
192 (defconst zeroconf-avahi-flags-unspec 0
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
193 "No Avahi flags.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
194
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
195
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
196 ;;; Services retrieval.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
197
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
198 (defvar zeroconf-services-hash (make-hash-table :test 'equal)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
199 "Hash table of discovered Avahi services.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
200
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
201 The key of an entry is the concatenation of the service name and
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
202 service type of a discovered service. The value is the service
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
203 itself. The format of a service is
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
204
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
205 \(INTERFACE PROTOCOL NAME TYPE DOMAIN FLAGS\)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
206
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
207 The INTERFACE is a number, which represents the network interface
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
208 the service is located at. The corresponding network interface
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
209 name, like \"eth0\", can be retrieved with the function
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
210 `zeroconf-get-interface-name'.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
211
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
212 PROTOCOL describes the used network protocol family the service
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
213 can be accessed. `zeroconf-avahi-protocol-inet4' means INET4,
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
214 `zeroconf-avahi-protocol-inet6' means INET6. An unspecified
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
215 protocol family is coded with `zeroconf-avahi-protocol-unspec'.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
216
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
217 NAME is the string the service is known at Avahi. A service can
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
218 be known under the same name for different service types.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
219
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
220 Each TYPE stands for a discovered service type of Avahi. The
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
221 format is described in RFC 2782. It is of the form
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
222
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
223 \"_APPLICATION-PROTOCOL._TRANSPORT-PROTOCOL\".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
224
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
225 TRANSPORT-PROTOCOL must be either \"tcp\" or \"udp\".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
226 APPLICATION-PROTOCOL must be a protocol name as specified in URL
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
227 `http://www.dns-sd.org/ServiceTypes.html'. Typical service types
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
228 are \"_workstation._tcp\" or \"_printer._tcp\".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
229
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
230 DOMAIN is the domain name the service is registered in, like \"local\".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
231
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
232 FLAGS, an integer, is used inside Avahi. When publishing a
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
233 service (see `zeroconf-publish-service', the flag 0 is used.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
234
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
235 (defvar zeroconf-resolved-services-hash (make-hash-table :test 'equal)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
236 "Hash table of resolved Avahi services.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
237 The key of an entry is the concatenation of the service name and
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
238 service type of a resolved service. The value is the service
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
239 itself. The format of a service is
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
240
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
241 \(INTERFACE PROTOCOL NAME TYPE DOMAIN HOST APROTOCOL ADDRESS PORT TXT FLAGS\)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
242
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
243 INTERFACE, PROTOCOL, NAME, TYPE, DOMAIN and FLAGS have the same
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
244 meaning as in `zeroconf-services-hash'.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
245
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
246 HOST is the host name the service is registered. It is a fully
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
247 qualified name, i.e., it contains DOMAIN.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
248
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
249 APROTOCOL stands for the network protocol family ADDRESS is
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
250 encoded (`zeroconf-avahi-protocol-inet4' means INET4,
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
251 `zeroconf-avahi-protocol-inet6' means INET6). It can be
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
252 different from PROTOCOL, when an adrress resolution has been
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
253 requested for another protocol family but the default one.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
254
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
255 ADDRESS is the service address, encoded according to the
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
256 APROTOCOL network protocol family. PORT is the corresponding
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
257 port the service can be reached on ADDRESS.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
258
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
259 TXT is an array of strings, describing additional attributes of
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
260 the service. Usually, every string is a key=value pair. The
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
261 supported keys depend on the service type.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
262
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
263 (defun zeroconf-list-service-names ()
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
264 "Returns all discovered Avahi service names as list."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
265 (let (result)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
266 (maphash
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
267 (lambda (key value) (add-to-list 'result (zeroconf-service-name value)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
268 zeroconf-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
269 result))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
270
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
271 (defun zeroconf-list-service-types ()
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
272 "Returns all discovered Avahi service types as list."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
273 (let (result)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
274 (maphash
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
275 (lambda (key value) (add-to-list 'result (zeroconf-service-type value)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
276 zeroconf-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
277 result))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
278
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
279 (defun zeroconf-list-services (type)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
280 "Returns all discovered Avahi services for a given service type TYPE.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
281 The service type is one of the returned values of
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
282 `zeroconf-list-service-types'. The return value is a list
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
283 \(SERVICE1 SERVICE2 ...\). See `zeroconf-services-hash' for the
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
284 format of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
285 (let (result)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
286 (maphash
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
287 (lambda (key value)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
288 (when (equal type (zeroconf-service-type value))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
289 (add-to-list 'result value)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
290 zeroconf-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
291 result))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
292
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
293 (defvar zeroconf-service-added-hooks-hash (make-hash-table :test 'equal)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
294 "Hash table of hooks for newly added services.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
295 The key of an entry is a service type.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
296
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
297 (defvar zeroconf-service-removed-hooks-hash (make-hash-table :test 'equal)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
298 "Hash table of hooks for removed services.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
299 The key of an entry is a service type.")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
300
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
301 (defun zeroconf-service-add-hook (type event function)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
302 "Add FUNCTION to the hook of service type TYPE.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
303
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
304 EVENT must be either :new or :removed, indicating whether
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
305 FUNCTION shall be called when a new service has been newly
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
306 detected, or removed.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
307
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
308 FUNCTION must accept one argument SERVICE, which identifies the
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
309 new service. Initially, when EVENT is :new, FUNCTION is called
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
310 for all already detected services of service type TYPE.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
311
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
312 The attributes of SERVICE can be retrieved via the functions
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
313
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
314 `zeroconf-service-interface'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
315 `zeroconf-service-protocol'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
316 `zeroconf-service-name'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
317 `zeroconf-service-type'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
318 `zeroconf-service-domain'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
319 `zeroconf-service-flags'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
320 `zeroconf-service-host'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
321 `zeroconf-service-aprotocol'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
322 `zeroconf-service-address'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
323 `zeroconf-service-port'
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
324 `zeroconf-service-txt'"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
325
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
326 (cond
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
327 ((equal event :new)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
328 (let ((l-hook (gethash type zeroconf-service-added-hooks-hash nil)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
329 (add-hook 'l-hook function)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
330 (puthash type l-hook zeroconf-service-added-hooks-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
331 (dolist (service (zeroconf-list-services type))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
332 (funcall function service))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
333 ((equal event :removed)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
334 (let ((l-hook (gethash type zeroconf-service-removed-hooks-hash nil)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
335 (add-hook 'l-hook function)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
336 (puthash type l-hook zeroconf-service-removed-hooks-hash)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
337 (t (error "EVENT must be either `:new' or `:removed'."))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
338
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
339 (defun zeroconf-get-host ()
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
340 "Returns the local host name as string."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
341 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
342 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
343 zeroconf-interface-avahi-server "GetHostName"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
344
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
345 (defun zeroconf-get-domain ()
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
346 "Returns the domain name as string."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
347 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
348 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
349 zeroconf-interface-avahi-server "GetDomainName"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
350
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
351 (defun zeroconf-get-host-domain ()
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
352 "Returns the local host name FQDN as string."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
353 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
354 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
355 zeroconf-interface-avahi-server "GetHostNameFqdn"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
356
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
357 (defun zeroconf-get-interface-name (number)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
358 "Return the interface name of internal interface NUMBER."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
359 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
360 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
361 zeroconf-interface-avahi-server "GetNetworkInterfaceNameByIndex"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
362 :int32 number))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
363
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
364 (defun zeroconf-get-interface-number (name)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
365 "Return the internal interface number of interface NAME."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
366 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
367 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
368 zeroconf-interface-avahi-server "GetNetworkInterfaceIndexByName"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
369 name))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
370
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
371 (defun zeroconf-get-service (name type)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
372 "Return the service description of service NAME as list.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
373 NAME must be a string. The service must be of service type
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
374 TYPE. The resulting list has the format
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
375
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
376 \(INTERFACE PROTOCOL NAME TYPE DOMAIN FLAGS\)."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
377 ;; Due to the service browser, all known services are kept in
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
378 ;; `zeroconf-services-hash'.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
379 (gethash (concat name "/" type) zeroconf-services-hash nil))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
380
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
381 (defun zeroconf-resolve-service (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
382 "Return all service attributes SERVICE as list.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
383 NAME must be a string. The service must be of service type
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
384 TYPE. The resulting list has the format
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
385
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
386 \(INTERFACE PROTOCOL NAME TYPE DOMAIN HOST APROTOCOL ADDRESS PORT TXT FLAGS\)."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
387 (let* ((name (zeroconf-service-name service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
388 (type (zeroconf-service-type service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
389 (key (concat name "/" type)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
390
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
391 (or
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
392 ;; Check whether we know this service already.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
393 (gethash key zeroconf-resolved-services-hash nil)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
394
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
395 ;; Resolve the service. We don't propagate D-Bus errors.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
396 (dbus-ignore-errors
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
397 (let* ((result
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
398 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
399 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
400 zeroconf-interface-avahi-server "ResolveService"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
401 zeroconf-avahi-interface-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
402 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
403 name type
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
404 zeroconf-avahi-current-domain
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
405 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
406 zeroconf-avahi-flags-unspec))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
407 (elt (nth 9 result))) ;; TXT.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
408 ;; The TXT field has the signature "aay". Transform to "as".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
409 (while elt
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
410 (setcar elt (apply 'string (car elt)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
411 (setq elt (cdr elt)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
412
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
413 (when nil ;; We discard it, no use so far.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
414 ;; Register a service resolver.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
415 (let ((object-path (zeroconf-register-service-resolver name type)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
416 ;; Register the signals.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
417 (dolist (member '("Found" "Failure"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
418 (dbus-register-signal
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
419 :system zeroconf-service-avahi object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
420 zeroconf-interface-avahi-service-resolver member
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
421 'zeroconf-service-resolver-handler)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
422 )
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
423
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
424 ;; Return the resolved service.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
425 (puthash key result zeroconf-resolved-services-hash))))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
426
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
427 (defun zeroconf-service-interface (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
428 "Return the internal interface number of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
429 (nth 0 service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
430
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
431 (defun zeroconf-service-protocol (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
432 "Return the protocol number of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
433 (nth 1 service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
434
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
435 (defun zeroconf-service-name (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
436 "Return the service name of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
437 (nth 2 service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
438
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
439 (defun zeroconf-service-type (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
440 "Return the type name of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
441 (nth 3 service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
442
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
443 (defun zeroconf-service-domain (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
444 "Return the domain name of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
445 (nth 4 service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
446
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
447 (defun zeroconf-service-flags (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
448 "Return the flags of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
449 (nth 5 service))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
450
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
451 (defun zeroconf-service-host (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
452 "Return the host name of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
453 (nth 5 (zeroconf-resolve-service service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
454
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
455 (defun zeroconf-service-aprotocol (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
456 "Return the aprotocol number of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
457 (nth 6 (zeroconf-resolve-service service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
458
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
459 (defun zeroconf-service-address (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
460 "Return the IP address of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
461 (nth 7 (zeroconf-resolve-service service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
462
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
463 (defun zeroconf-service-port (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
464 "Return the port number of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
465 (nth 8 (zeroconf-resolve-service service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
466
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
467 (defun zeroconf-service-txt (service)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
468 "Return the text strings of SERVICE."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
469 (nth 9 (zeroconf-resolve-service service)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
470
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
471
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
472 ;;; Services signalling.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
473
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
474 ;; Register for the service type browser. Service registrations will
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
475 ;; happen in `zeroconf-service-type-browser-handler', when there is an
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
476 ;; "ItemNew" signal from the service type browser.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
477 (defun zeroconf-init (&optional domain)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
478 "Instantiate an Avahi service type browser for domain DOMAIN.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
479 DOMAIN is a string, like \"dns-sd.org\" or \"local\". When
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
480 DOMAIN is nil, the local domain is used."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
481 (when (and (or (null domain) (stringp domain))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
482 (dbus-ping :system zeroconf-service-avahi)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
483 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
484 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
485 zeroconf-interface-avahi-server "IsNSSSupportAvailable"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
486
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
487 ;; Reset all stored values.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
488 (setq zeroconf-path-avahi-service-type-browser nil
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
489 zeroconf-avahi-current-domain (or domain
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
490 zeroconf-avahi-domain-unspec))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
491 (clrhash zeroconf-path-avahi-service-browser-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
492 (clrhash zeroconf-path-avahi-service-resolver-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
493 (clrhash zeroconf-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
494 (clrhash zeroconf-resolved-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
495 (clrhash zeroconf-service-added-hooks-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
496 (clrhash zeroconf-service-removed-hooks-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
497
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
498 ;; Register a service type browser.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
499 (let ((object-path (zeroconf-register-service-type-browser)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
500 ;; Register the signals.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
501 (dolist (member '("ItemNew" "ItemRemove" "Failure"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
502 (dbus-register-signal
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
503 :system zeroconf-service-avahi object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
504 zeroconf-interface-avahi-service-type-browser member
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
505 'zeroconf-service-type-browser-handler)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
506
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
507 ;; Register state changed signal.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
508 (dbus-register-signal
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
509 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
510 zeroconf-interface-avahi-service-type-browser "StateChanged"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
511 'zeroconf-service-type-browser-handler)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
512
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
513 (defun zeroconf-register-service-type-browser ()
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
514 "Register a service type browser at the Avahi daemon."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
515 (or zeroconf-path-avahi-service-type-browser
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
516 (setq zeroconf-path-avahi-service-type-browser
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
517 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
518 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
519 zeroconf-interface-avahi-server "ServiceTypeBrowserNew"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
520 zeroconf-avahi-interface-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
521 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
522 zeroconf-avahi-current-domain
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
523 zeroconf-avahi-flags-unspec))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
524
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
525 (defun zeroconf-service-type-browser-handler (&rest val)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
526 "Registered service type browser handler at the Avahi daemon."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
527 (when zeroconf-debug
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
528 (message "zeroconf-service-type-browser-handler: %s %S"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
529 (dbus-event-member-name last-input-event) val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
530 (cond
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
531 ((string-equal (dbus-event-member-name last-input-event) "ItemNew")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
532 ;; Parameters: (interface protocol type domain flags)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
533 ;; Register a service browser.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
534 (let ((object-path (zeroconf-register-service-browser (nth-value 2 val))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
535 ;; Register the signals.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
536 (dolist (member '("ItemNew" "ItemRemove" "Failure"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
537 (dbus-register-signal
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
538 :system zeroconf-service-avahi object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
539 zeroconf-interface-avahi-service-browser member
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
540 'zeroconf-service-browser-handler))))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
541
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
542 (defun zeroconf-register-service-browser (type)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
543 "Register a service browser at the Avahi daemon."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
544 (or (gethash type zeroconf-path-avahi-service-browser-hash nil)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
545 (puthash type
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
546 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
547 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
548 zeroconf-interface-avahi-server "ServiceBrowserNew"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
549 zeroconf-avahi-interface-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
550 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
551 type
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
552 zeroconf-avahi-current-domain
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
553 zeroconf-avahi-flags-unspec)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
554 zeroconf-path-avahi-service-browser-hash)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
555
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
556 (defun zeroconf-service-browser-handler (&rest val)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
557 "Registered service browser handler at the Avahi daemon."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
558 ;; Parameters: (interface protocol name type domain flags)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
559 (when zeroconf-debug
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
560 (message "zeroconf-service-browser-handler: %s %S"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
561 (dbus-event-member-name last-input-event) val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
562 (let* ((name (zeroconf-service-name val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
563 (type (zeroconf-service-type val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
564 (key (concat name "/" type))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
565 (ahook (gethash type zeroconf-service-added-hooks-hash nil))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
566 (rhook (gethash type zeroconf-service-removed-hooks-hash nil)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
567 (cond
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
568 ((string-equal (dbus-event-member-name last-input-event) "ItemNew")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
569 ;; Add new service.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
570 (puthash key val zeroconf-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
571 (run-hook-with-args 'ahook val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
572
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
573 ((string-equal (dbus-event-member-name last-input-event) "ItemRemove")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
574 ;; Remove the service.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
575 (remhash key zeroconf-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
576 (remhash key zeroconf-resolved-services-hash)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
577 (run-hook-with-args 'rhook val)))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
578
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
579 (defun zeroconf-register-service-resolver (name type)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
580 "Register a service resolver at the Avahi daemon."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
581 (let ((key (concat name "/" type)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
582 (or (gethash key zeroconf-path-avahi-service-resolver-hash nil)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
583 (puthash key
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
584 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
585 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
586 zeroconf-interface-avahi-server "ServiceResolverNew"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
587 zeroconf-avahi-interface-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
588 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
589 name type
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
590 zeroconf-avahi-current-domain
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
591 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
592 zeroconf-avahi-flags-unspec)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
593 zeroconf-resolved-services-hash))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
594
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
595 (defun zeroconf-service-resolver-handler (&rest val)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
596 "Registered service resolver handler at the Avahi daemon."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
597 ;; Parameters: (interface protocol name type domain host aprotocol
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
598 ;; address port txt flags)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
599 ;; The "TXT" field has the signature "aay". Transform to "as".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
600 (let ((elt (nth 9 val)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
601 (while elt
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
602 (setcar elt (apply 'string (car elt)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
603 (setq elt (cdr elt))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
604 (when zeroconf-debug
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
605 (message "zeroconf-service-resolver-handler: %s %S"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
606 (dbus-event-member-name last-input-event) val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
607 (cond
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
608 ;; A new service has been detected. Add it to
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
609 ;; `zeroconf-resolved-services-hash'.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
610 ((string-equal (dbus-event-member-name last-input-event) "Found")
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
611 (puthash
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
612 (concat (zeroconf-service-name val) "/" (zeroconf-service-type val))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
613 val zeroconf-resolved-services-hash))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
614
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
615
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
616 ;;; Services publishing.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
617
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
618 (defun zeroconf-publish-service (name type domain host port address txt)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
619 "Publish a service at the Avahi daemon.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
620 For the description of arguments, see `zeroconf-resolved-services-hash'."
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
621 ;; NAME and TYPE must not be empty.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
622 (when (zerop (length name))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
623 (error "Invalid argument NAME: %s" name))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
624 (when (zerop (length type))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
625 (error "Invalid argument TYPE: %s" type))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
626
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
627 ;; Set default values for DOMAIN, HOST and PORT.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
628 (when (zerop (length domain))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
629 (setq domain (zeroconf-get-domain)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
630 (when (zerop (length host))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
631 (setq host (zeroconf-get-host-domain)))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
632 (when (null port)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
633 (setq port 0))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
634
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
635 ;; Create an entry in the daemon.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
636 (let ((object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
637 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
638 :system zeroconf-service-avahi zeroconf-path-avahi
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
639 zeroconf-interface-avahi-server "EntryGroupNew"))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
640 result)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
641
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
642 ;; The TXT field has the signature "as". Transform to "aay".
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
643 (dolist (elt txt)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
644 (let (args)
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
645 (add-to-list
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
646 'result
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
647 (dolist (elt1 (string-to-list elt) (append '(:array) args))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
648 (setq args (append args (list :byte elt1)))))))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
649
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
650 ;; Add the service.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
651 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
652 :system zeroconf-service-avahi object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
653 zeroconf-interface-avahi-entry-group "AddService"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
654 zeroconf-avahi-interface-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
655 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
656 zeroconf-avahi-flags-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
657 name type domain host :uint16 port (append '(:array) result))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
658
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
659 ;; Add the address.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
660 (unless (zerop (length address))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
661 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
662 :system zeroconf-service-avahi object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
663 zeroconf-interface-avahi-entry-group "AddAddress"
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
664 zeroconf-avahi-interface-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
665 zeroconf-avahi-protocol-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
666 zeroconf-avahi-flags-unspec
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
667 host address))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
668
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
669 ;; Make it persistent in the daemon.
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
670 (dbus-call-method
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
671 :system zeroconf-service-avahi object-path
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
672 zeroconf-interface-avahi-entry-group "Commit")))
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
673
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
674 (provide 'zeroconf)
94144
40901fec25aa Add arch tagline
Miles Bader <miles@gnu.org>
parents: 93874
diff changeset
675
40901fec25aa Add arch tagline
Miles Bader <miles@gnu.org>
parents: 93874
diff changeset
676 ;; arch-tag: ea578165-7fa8-44f4-90f0-de3940aec69f
93874
ca56553dfa9b * net/zeroconf.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
677 ;;; zeroconf.el ends here