1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include "nsISupports.idl"
6
7interface nsICancelable;
8interface nsIPropertyBag2;
9
10/**
11 * Service information
12 */
13[scriptable, uuid(670ed0f9-2fa5-4544-bf1e-ea58ac179374)]
14interface nsIDNSServiceInfo : nsISupports
15{
16  /**
17   * The host name of the service. (E.g. "Android.local.")
18   * @throws NS_ERROR_NOT_INITIALIZED when getting unset value.
19   */
20  attribute AUTF8String host;
21
22  /**
23   * The IP address of the service.
24   * @throws NS_ERROR_NOT_INITIALIZED when getting unset value.
25   */
26  attribute AUTF8String address;
27
28  /**
29   * The port number of the service. (E.g. 80)
30   * @throws NS_ERROR_NOT_INITIALIZED when getting unset value.
31   */
32  attribute unsigned short port;
33
34  /**
35   * The service name of the service for display. (E.g. "My TV")
36   * @throws NS_ERROR_NOT_INITIALIZED when getting unset value.
37   */
38  attribute AUTF8String serviceName;
39
40  /**
41   * The type of the service. (E.g. "_http._tcp")
42   * @throws NS_ERROR_NOT_INITIALIZED when getting unset value.
43   */
44  attribute AUTF8String serviceType;
45
46  /**
47   * The domain name of the service. (E.g. "local.")
48   * @throws NS_ERROR_NOT_INITIALIZED when getting unset value.
49   */
50  attribute AUTF8String domainName;
51
52  /**
53   * The attributes of the service.
54   */
55  attribute nsIPropertyBag2 attributes;
56};
57
58/**
59 * The callback interface for service discovery
60 */
61[scriptable, uuid(3025b7f2-97bb-435b-b43d-26731b3f5fc4)]
62interface nsIDNSServiceDiscoveryListener : nsISupports
63{
64  /**
65   * Callback when the discovery begins.
66   * @param   aServiceType
67   *          the service type of |startDiscovery|.
68   */
69  void onDiscoveryStarted(in AUTF8String aServiceType);
70
71  /**
72   * Callback when the discovery ends.
73   * @param   aServiceType
74   *          the service type of |startDiscovery|.
75   */
76  void onDiscoveryStopped(in AUTF8String aServiceType);
77
78  /**
79   * Callback when the a service is found.
80   * @param   aServiceInfo
81   *          the info about the found service, where |serviceName|, |aServiceType|, and |domainName| are set.
82   */
83  void onServiceFound(in nsIDNSServiceInfo aServiceInfo);
84
85  /**
86   * Callback when the a service is lost.
87   * @param   aServiceInfo
88   *          the info about the lost service, where |serviceName|, |aServiceType|, and |domainName| are set.
89   */
90  void onServiceLost(in nsIDNSServiceInfo aServiceInfo);
91
92  /**
93   * Callback when the discovery cannot start.
94   * @param   aServiceType
95   *          the service type of |startDiscovery|.
96   * @param   aErrorCode
97   *          the error code.
98   */
99  void onStartDiscoveryFailed(in AUTF8String aServiceType, in long aErrorCode);
100
101  /**
102   * Callback when the discovery cannot stop.
103   * @param   aServiceType
104   *          the service type of |startDiscovery|.
105   * @param   aErrorCode
106   *          the error code.
107   */
108  void onStopDiscoveryFailed(in AUTF8String aServiceType, in long aErrorCode);
109};
110
111/**
112 * The callback interface for service registration
113 */
114[scriptable, uuid(e165e4be-abf4-4963-a66d-ed3ca116e5e4)]
115interface nsIDNSRegistrationListener : nsISupports
116{
117  const long ERROR_SERVICE_NOT_RUNNING = -65563;
118
119  /**
120   * Callback when the service is registered successfully.
121   * @param   aServiceInfo
122   *          the info about the registered service,
123   *          where |serviceName|, |aServiceType|, and |domainName| are set.
124   */
125  void onServiceRegistered(in nsIDNSServiceInfo aServiceInfo);
126
127  /**
128   * Callback when the service is unregistered successfully.
129   * @param   aServiceInfo
130   *          the info about the unregistered service.
131   */
132  void onServiceUnregistered(in nsIDNSServiceInfo aServiceInfo);
133
134  /**
135   * Callback when the service cannot be registered.
136   * @param   aServiceInfo
137   *          the info about the service to be registered.
138   * @param   aErrorCode
139   *          the error code.
140   */
141  void onRegistrationFailed(in nsIDNSServiceInfo aServiceInfo, in long aErrorCode);
142
143  /**
144   * Callback when the service cannot be unregistered.
145   * @param   aServiceInfo
146   *          the info about the registered service.
147   * @param   aErrorCode
148   *          the error code.
149   */
150  void onUnregistrationFailed(in nsIDNSServiceInfo aServiceInfo, in long aErrorCode);
151};
152
153/**
154 * The callback interface for service resolve
155 */
156[scriptable, uuid(24ee6408-648e-421d-accf-c6e5adeccf97)]
157interface nsIDNSServiceResolveListener : nsISupports
158{
159  /**
160   * Callback when the service is resolved successfully.
161   * @param   aServiceInfo
162   *          the info about the resolved service, where |host| and |port| are set.
163   */
164  void onServiceResolved(in nsIDNSServiceInfo aServiceInfo);
165
166  /**
167   * Callback when the service cannot be resolved.
168   * @param   aServiceInfo
169   *          the info about the service to be resolved.
170   * @param   aErrorCode
171   *          the error code.
172   */
173  void onResolveFailed(in nsIDNSServiceInfo aServiceInfo, in long aErrorCode);
174};
175
176/**
177 * The interface for DNS service discovery/registration/resolve
178 */
179[scriptable, uuid(6487899b-beb1-455a-ba65-e4fd465066d7)]
180interface nsIDNSServiceDiscovery : nsISupports
181{
182  /**
183   * Browse for instances of a service.
184   * @param   aServiceType
185   *          the service type to be discovered, E.g. "_http._tcp".
186   * @param   aListener
187   *          callback interface for discovery notifications.
188   * @return  An object that can be used to cancel the service discovery.
189   */
190  nsICancelable startDiscovery(in AUTF8String aServiceType, in nsIDNSServiceDiscoveryListener aListener);
191
192  /**
193   * Register a service that is discovered via |startDiscovery| and |resolveService| calls.
194   * @param   aServiceInfo
195   *          the service information to be registered.
196   *          |port| and |aServiceType| are required attributes.
197   * @param   aListener
198   *          callback interface for registration notifications.
199   * @return  An object that can be used to cancel the service registration.
200   */
201  nsICancelable registerService(in nsIDNSServiceInfo aServiceInfo, in nsIDNSRegistrationListener aListener);
202
203  /**
204   * Resolve a service name discovered via |startDiscovery| to a target host name, port number.
205   * @param   aServiceInfo
206   *          the service information to be registered.
207   *          |serviceName|, |aServiceType|, and |domainName| are required attributes as reported to the |onServiceFound| callback.
208   * @param   aListener
209   *          callback interface for registration notifications.
210   */
211  void resolveService(in nsIDNSServiceInfo aServiceInfo, in nsIDNSServiceResolveListener aListener);
212};
213
214%{ C++
215#define DNSSERVICEDISCOVERY_CONTRACT_ID \
216  "@mozilla.org/toolkit/components/mdnsresponder/dns-sd;1"
217#define DNSSERVICEINFO_CONTRACT_ID \
218  "@mozilla.org/toolkit/components/mdnsresponder/dns-info;1"
219%}
220