1 /*
2  *  Copyright (c) 2020, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * @brief
32  *  This file defines the API for server of the Service Registration Protocol (SRP).
33  */
34 
35 #ifndef OPENTHREAD_SRP_SERVER_H_
36 #define OPENTHREAD_SRP_SERVER_H_
37 
38 #include <stdint.h>
39 
40 #include <openthread/dns.h>
41 #include <openthread/instance.h>
42 #include <openthread/ip6.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @addtogroup api-srp
50  *
51  * @brief
52  *  This module includes functions of the Service Registration Protocol.
53  *
54  * @{
55  *
56  */
57 
58 /**
59  * This opaque type represents a SRP service host.
60  *
61  */
62 typedef struct otSrpServerHost otSrpServerHost;
63 
64 /**
65  * This opaque type represents a SRP service.
66  *
67  */
68 typedef struct otSrpServerService otSrpServerService;
69 
70 /**
71  * The ID of a SRP service update transaction on the SRP Server.
72  *
73  */
74 typedef uint32_t otSrpServerServiceUpdateId;
75 
76 /**
77  * Represents the state of the SRP server.
78  *
79  */
80 typedef enum
81 {
82     OT_SRP_SERVER_STATE_DISABLED = 0, ///< The SRP server is disabled.
83     OT_SRP_SERVER_STATE_RUNNING  = 1, ///< The SRP server is enabled and running.
84     OT_SRP_SERVER_STATE_STOPPED  = 2, ///< The SRP server is enabled but stopped.
85 } otSrpServerState;
86 
87 /**
88  * Represents the address mode used by the SRP server.
89  *
90  * Address mode specifies how the address and port number are determined by the SRP server and how this info is
91  * published in the Thread Network Data.
92  *
93  */
94 typedef enum otSrpServerAddressMode
95 {
96     OT_SRP_SERVER_ADDRESS_MODE_UNICAST = 0, ///< Unicast address mode.
97     OT_SRP_SERVER_ADDRESS_MODE_ANYCAST = 1, ///< Anycast address mode.
98 } otSrpServerAddressMode;
99 
100 /**
101  * Includes SRP server TTL configurations.
102  *
103  */
104 typedef struct otSrpServerTtlConfig
105 {
106     uint32_t mMinTtl; ///< The minimum TTL in seconds.
107     uint32_t mMaxTtl; ///< The maximum TTL in seconds.
108 } otSrpServerTtlConfig;
109 
110 /**
111  * Includes SRP server LEASE and KEY-LEASE configurations.
112  *
113  */
114 typedef struct otSrpServerLeaseConfig
115 {
116     uint32_t mMinLease;    ///< The minimum LEASE interval in seconds.
117     uint32_t mMaxLease;    ///< The maximum LEASE interval in seconds.
118     uint32_t mMinKeyLease; ///< The minimum KEY-LEASE interval in seconds.
119     uint32_t mMaxKeyLease; ///< The maximum KEY-LEASE interval in seconds.
120 } otSrpServerLeaseConfig;
121 
122 /**
123  * Includes SRP server lease information of a host/service.
124  *
125  */
126 typedef struct otSrpServerLeaseInfo
127 {
128     uint32_t mLease;             ///< The lease time of a host/service in milliseconds.
129     uint32_t mKeyLease;          ///< The key lease time of a host/service in milliseconds.
130     uint32_t mRemainingLease;    ///< The remaining lease time of the host/service in milliseconds.
131     uint32_t mRemainingKeyLease; ///< The remaining key lease time of a host/service in milliseconds.
132 } otSrpServerLeaseInfo;
133 
134 /**
135  * Includes the statistics of SRP server responses.
136  *
137  */
138 typedef struct otSrpServerResponseCounters
139 {
140     uint32_t mSuccess;       ///< The number of successful responses.
141     uint32_t mServerFailure; ///< The number of server failure responses.
142     uint32_t mFormatError;   ///< The number of format error responses.
143     uint32_t mNameExists;    ///< The number of 'name exists' responses.
144     uint32_t mRefused;       ///< The number of refused responses.
145     uint32_t mOther;         ///< The number of other responses.
146 } otSrpServerResponseCounters;
147 
148 /**
149  * Returns the domain authorized to the SRP server.
150  *
151  * If the domain if not set by SetDomain, "default.service.arpa." will be returned.
152  * A trailing dot is always appended even if the domain is set without it.
153  *
154  * @param[in]  aInstance  A pointer to an OpenThread instance.
155  *
156  * @returns A pointer to the dot-joined domain string.
157  *
158  */
159 const char *otSrpServerGetDomain(otInstance *aInstance);
160 
161 /**
162  * Sets the domain on the SRP server.
163  *
164  * A trailing dot will be appended to @p aDomain if it is not already there.
165  * Should only be called before the SRP server is enabled.
166  *
167  * @param[in]  aInstance  A pointer to an OpenThread instance.
168  * @param[in]  aDomain    The domain to be set. MUST NOT be NULL.
169  *
170  * @retval  OT_ERROR_NONE           Successfully set the domain to @p aDomain.
171  * @retval  OT_ERROR_INVALID_STATE  The SRP server is already enabled and the Domain cannot be changed.
172  * @retval  OT_ERROR_INVALID_ARGS   The argument @p aDomain is not a valid DNS domain name.
173  * @retval  OT_ERROR_NO_BUFS        There is no memory to store content of @p aDomain.
174  *
175  */
176 otError otSrpServerSetDomain(otInstance *aInstance, const char *aDomain);
177 
178 /**
179  * Returns the state of the SRP server.
180  *
181  * @param[in]  aInstance  A pointer to an OpenThread instance.
182  *
183  * @returns The current state of the SRP server.
184  *
185  */
186 otSrpServerState otSrpServerGetState(otInstance *aInstance);
187 
188 /**
189  * Returns the port the SRP server is listening to.
190  *
191  * @param[in]  aInstance  A pointer to an OpenThread instance.
192  *
193  * @returns  The port of the SRP server. It returns 0 if the server is not running.
194  *
195  */
196 uint16_t otSrpServerGetPort(otInstance *aInstance);
197 
198 /**
199  * Returns the address mode being used by the SRP server.
200  *
201  * @param[in] aInstance  A pointer to an OpenThread instance.
202  *
203  * @returns The SRP server's address mode.
204  *
205  */
206 otSrpServerAddressMode otSrpServerGetAddressMode(otInstance *aInstance);
207 
208 /**
209  * Sets the address mode to be used by the SRP server.
210  *
211  * @param[in] aInstance  A pointer to an OpenThread instance.
212  * @param[in] aMode      The address mode to use.
213  *
214  * @retval OT_ERROR_NONE           Successfully set the address mode.
215  * @retval OT_ERROR_INVALID_STATE  The SRP server is enabled and the address mode cannot be changed.
216  *
217  */
218 otError otSrpServerSetAddressMode(otInstance *aInstance, otSrpServerAddressMode aMode);
219 
220 /**
221  * Returns the sequence number used with anycast address mode.
222  *
223  * The sequence number is included in "DNS/SRP Service Anycast Address" entry published in the Network Data.
224  *
225  * @param[in] aInstance  A pointer to an OpenThread instance.
226  *
227  * @returns The anycast sequence number.
228  *
229  */
230 uint8_t otSrpServerGetAnycastModeSequenceNumber(otInstance *aInstance);
231 
232 /**
233  * Sets the sequence number used with anycast address mode.
234  *
235  * @param[in] aInstance        A pointer to an OpenThread instance.
236  * @param[in] aSequenceNumber  The sequence number to use.
237  *
238  * @retval OT_ERROR_NONE            Successfully set the address mode.
239  * @retval OT_ERROR_INVALID_STATE   The SRP server is enabled and the sequence number cannot be changed.
240  *
241  */
242 otError otSrpServerSetAnycastModeSequenceNumber(otInstance *aInstance, uint8_t aSequenceNumber);
243 
244 /**
245  * Enables/disables the SRP server.
246  *
247  * On a Border Router, it is recommended to use `otSrpServerSetAutoEnableMode()` instead.
248  *
249  * @param[in]  aInstance  A pointer to an OpenThread instance.
250  * @param[in]  aEnabled   A boolean to enable/disable the SRP server.
251  *
252  */
253 void otSrpServerSetEnabled(otInstance *aInstance, bool aEnabled);
254 
255 /**
256  * Enables/disables the auto-enable mode on SRP server.
257  *
258  * Requires `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` feature.
259  *
260  * When this mode is enabled, the Border Routing Manager controls if/when to enable or disable the SRP server.
261  * SRP sever is auto-enabled if/when Border Routing is started and it is done with the initial prefix and route
262  * configurations (when the OMR and on-link prefixes are determined, advertised in emitted Router Advertisement message
263  * on infrastructure side and published in the Thread Network Data). The SRP server is auto-disabled if/when BR is
264  * stopped (e.g., if the infrastructure network interface is brought down or if BR gets detached).
265  *
266  * This mode can be disabled by a `otSrpServerSetAutoEnableMode()` call with @p aEnabled set to `false` or if the SRP
267  * server is explicitly enabled or disabled by a call to `otSrpServerSetEnabled()` function. Disabling auto-enable mode
268  * using `otSrpServerSetAutoEnableMode(false)` will not change the current state of SRP sever (e.g., if it is enabled
269  * it stays enabled).
270  *
271  * @param[in] aInstance   A pointer to an OpenThread instance.
272  * @param[in] aEnabled    A boolean to enable/disable the auto-enable mode.
273  *
274  */
275 void otSrpServerSetAutoEnableMode(otInstance *aInstance, bool aEnabled);
276 
277 /**
278  * Indicates whether the auto-enable mode is enabled or disabled.
279  *
280  * Requires `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` feature.
281  *
282  * @param[in]  aInstance  A pointer to an OpenThread instance.
283  *
284  * @retval TRUE   The auto-enable mode is enabled.
285  * @retval FALSE  The auto-enable mode is disabled.
286  *
287  */
288 bool otSrpServerIsAutoEnableMode(otInstance *aInstance);
289 
290 /**
291  * Returns SRP server TTL configuration.
292  *
293  * @param[in]   aInstance   A pointer to an OpenThread instance.
294  * @param[out]  aTtlConfig  A pointer to an `otSrpServerTtlConfig` instance.
295  *
296  */
297 void otSrpServerGetTtlConfig(otInstance *aInstance, otSrpServerTtlConfig *aTtlConfig);
298 
299 /**
300  * Sets SRP server TTL configuration.
301  *
302  * The granted TTL will always be no greater than the max lease interval configured via `otSrpServerSetLeaseConfig()`,
303  * regardless of the minimum and maximum TTL configuration.
304  *
305  * @param[in]  aInstance   A pointer to an OpenThread instance.
306  * @param[in]  aTtlConfig  A pointer to an `otSrpServerTtlConfig` instance.
307  *
308  * @retval  OT_ERROR_NONE          Successfully set the TTL configuration.
309  * @retval  OT_ERROR_INVALID_ARGS  The TTL configuration is not valid.
310  *
311  */
312 otError otSrpServerSetTtlConfig(otInstance *aInstance, const otSrpServerTtlConfig *aTtlConfig);
313 
314 /**
315  * Returns SRP server LEASE and KEY-LEASE configurations.
316  *
317  * @param[in]   aInstance     A pointer to an OpenThread instance.
318  * @param[out]  aLeaseConfig  A pointer to an `otSrpServerLeaseConfig` instance.
319  *
320  */
321 void otSrpServerGetLeaseConfig(otInstance *aInstance, otSrpServerLeaseConfig *aLeaseConfig);
322 
323 /**
324  * Sets SRP server LEASE and KEY-LEASE configurations.
325  *
326  * When a non-zero LEASE time is requested from a client, the granted value will be
327  * limited in range [aMinLease, aMaxLease]; and a non-zero KEY-LEASE will be granted
328  * in range [aMinKeyLease, aMaxKeyLease]. For zero LEASE or KEY-LEASE time, zero will
329  * be granted.
330  *
331  * @param[in]  aInstance     A pointer to an OpenThread instance.
332  * @param[in]  aLeaseConfig  A pointer to an `otSrpServerLeaseConfig` instance.
333  *
334  * @retval  OT_ERROR_NONE          Successfully set the LEASE and KEY-LEASE ranges.
335  * @retval  OT_ERROR_INVALID_ARGS  The LEASE or KEY-LEASE range is not valid.
336  *
337  */
338 otError otSrpServerSetLeaseConfig(otInstance *aInstance, const otSrpServerLeaseConfig *aLeaseConfig);
339 
340 /**
341  * Handles SRP service updates.
342  *
343  * Is called by the SRP server to notify that a SRP host and possibly SRP services
344  * are being updated. It is important that the SRP updates are not committed until the handler
345  * returns the result by calling otSrpServerHandleServiceUpdateResult or times out after @p aTimeout.
346  *
347  * A SRP service observer should always call otSrpServerHandleServiceUpdateResult with error code
348  * OT_ERROR_NONE immediately after receiving the update events.
349  *
350  * A more generic handler may perform validations on the SRP host/services and rejects the SRP updates
351  * if any validation fails. For example, an Advertising Proxy should advertise (or remove) the host and
352  * services on a multicast-capable link and returns specific error code if any failure occurs.
353  *
354  * @param[in]  aId       The service update transaction ID. This ID must be passed back with
355  *                       `otSrpServerHandleServiceUpdateResult`.
356  * @param[in]  aHost     A pointer to the otSrpServerHost object which contains the SRP updates. The
357  *                       handler should publish/un-publish the host and each service points to this
358  *                       host with below rules:
359  *                         1. If the host is not deleted (indicated by `otSrpServerHostIsDeleted`),
360  *                            then it should be published or updated with mDNS. Otherwise, the host
361  *                            should be un-published (remove AAAA RRs).
362  *                         2. For each service points to this host, it must be un-published if the host
363  *                            is to be un-published. Otherwise, the handler should publish or update the
364  *                            service when it is not deleted (indicated by `otSrpServerServiceIsDeleted`)
365  *                            and un-publish it when deleted.
366  * @param[in]  aTimeout  The maximum time in milliseconds for the handler to process the service event.
367  * @param[in]  aContext  A pointer to application-specific context.
368  *
369  * @sa otSrpServerSetServiceUpdateHandler
370  * @sa otSrpServerHandleServiceUpdateResult
371  *
372  */
373 typedef void (*otSrpServerServiceUpdateHandler)(otSrpServerServiceUpdateId aId,
374                                                 const otSrpServerHost     *aHost,
375                                                 uint32_t                   aTimeout,
376                                                 void                      *aContext);
377 
378 /**
379  * Sets the SRP service updates handler on SRP server.
380  *
381  * @param[in]  aInstance        A pointer to an OpenThread instance.
382  * @param[in]  aServiceHandler  A pointer to a service handler. Use NULL to remove the handler.
383  * @param[in]  aContext         A pointer to arbitrary context information.
384  *                              May be NULL if not used.
385  *
386  */
387 void otSrpServerSetServiceUpdateHandler(otInstance                     *aInstance,
388                                         otSrpServerServiceUpdateHandler aServiceHandler,
389                                         void                           *aContext);
390 
391 /**
392  * Reports the result of processing a SRP update to the SRP server.
393  *
394  * The Service Update Handler should call this function to return the result of its
395  * processing of a SRP update.
396  *
397  * @param[in]  aInstance  A pointer to an OpenThread instance.
398  * @param[in]  aId        The service update transaction ID. This should be the same ID
399  *                        provided via `otSrpServerServiceUpdateHandler`.
400  * @param[in]  aError     An error to be returned to the SRP server. Use OT_ERROR_DUPLICATED
401  *                        to represent DNS name conflicts.
402  *
403  */
404 void otSrpServerHandleServiceUpdateResult(otInstance *aInstance, otSrpServerServiceUpdateId aId, otError aError);
405 
406 /**
407  * Returns the next registered host on the SRP server.
408  *
409  * @param[in]  aInstance  A pointer to an OpenThread instance.
410  * @param[in]  aHost      A pointer to current host; use NULL to get the first host.
411  *
412  * @returns  A pointer to the registered host. NULL, if no more hosts can be found.
413  *
414  */
415 const otSrpServerHost *otSrpServerGetNextHost(otInstance *aInstance, const otSrpServerHost *aHost);
416 
417 /**
418  * Returns the response counters of the SRP server.
419  *
420  * @param[in]  aInstance  A pointer to an OpenThread instance.
421  *
422  * @returns  A pointer to the response counters of the SRP server.
423  *
424  */
425 const otSrpServerResponseCounters *otSrpServerGetResponseCounters(otInstance *aInstance);
426 
427 /**
428  * Tells if the SRP service host has been deleted.
429  *
430  * A SRP service host can be deleted but retains its name for future uses.
431  * In this case, the host instance is not removed from the SRP server/registry.
432  *
433  * @param[in]  aHost  A pointer to the SRP service host.
434  *
435  * @returns  TRUE if the host has been deleted, FALSE if not.
436  *
437  */
438 bool otSrpServerHostIsDeleted(const otSrpServerHost *aHost);
439 
440 /**
441  * Returns the full name of the host.
442  *
443  * @param[in]  aHost  A pointer to the SRP service host.
444  *
445  * @returns  A pointer to the null-terminated host name string.
446  *
447  */
448 const char *otSrpServerHostGetFullName(const otSrpServerHost *aHost);
449 
450 /**
451  * Indicates whether the host matches a given host name.
452  *
453  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
454  * be the same).
455  *
456  * @param[in]  aHost       A pointer to the SRP service host.
457  * @param[in]  aFullName   A full host name.
458  *
459  * @retval  TRUE   If host matches the host name.
460  * @retval  FALSE  If host does not match the host name.
461  *
462  */
463 bool otSrpServerHostMatchesFullName(const otSrpServerHost *aHost, const char *aFullName);
464 
465 /**
466  * Returns the addresses of given host.
467  *
468  * @param[in]   aHost          A pointer to the SRP service host.
469  * @param[out]  aAddressesNum  A pointer to where we should output the number of the addresses to.
470  *
471  * @returns  A pointer to the array of IPv6 Address.
472  *
473  */
474 const otIp6Address *otSrpServerHostGetAddresses(const otSrpServerHost *aHost, uint8_t *aAddressesNum);
475 
476 /**
477  * Returns the LEASE and KEY-LEASE information of a given host.
478  *
479  * @param[in]   aHost       A pointer to the SRP server host.
480  * @param[out]  aLeaseInfo  A pointer to where to output the LEASE and KEY-LEASE information.
481  *
482  */
483 void otSrpServerHostGetLeaseInfo(const otSrpServerHost *aHost, otSrpServerLeaseInfo *aLeaseInfo);
484 
485 /**
486  * Returns the next service of given host.
487  *
488  * @param[in]  aHost     A pointer to the SRP service host.
489  * @param[in]  aService  A pointer to current SRP service instance; use NULL to get the first service.
490  *
491  * @returns  A pointer to the next service or NULL if there is no more services.
492  *
493  */
494 const otSrpServerService *otSrpServerHostGetNextService(const otSrpServerHost    *aHost,
495                                                         const otSrpServerService *aService);
496 
497 /**
498  * Indicates whether or not the SRP service has been deleted.
499  *
500  * A SRP service can be deleted but retains its name for future uses.
501  * In this case, the service instance is not removed from the SRP server/registry.
502  * It is guaranteed that all services are deleted if the host is deleted.
503  *
504  * @param[in]  aService  A pointer to the SRP service.
505  *
506  * @returns  TRUE if the service has been deleted, FALSE if not.
507  *
508  */
509 bool otSrpServerServiceIsDeleted(const otSrpServerService *aService);
510 
511 /**
512  * Returns the full service instance name of the service.
513  *
514  * @param[in]  aService  A pointer to the SRP service.
515  *
516  * @returns  A pointer to the null-terminated service instance name string.
517  *
518  */
519 const char *otSrpServerServiceGetInstanceName(const otSrpServerService *aService);
520 
521 /**
522  * Indicates whether this service matches a given service instance name.
523  *
524  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
525  * be the same).
526  *
527  * @param[in]  aService       A pointer to the SRP service.
528  * @param[in]  aInstanceName  The service instance name.
529  *
530  * @retval  TRUE   If service matches the service instance name.
531  * @retval  FALSE  If service does not match the service instance name.
532  *
533  */
534 bool otSrpServerServiceMatchesInstanceName(const otSrpServerService *aService, const char *aInstanceName);
535 
536 /**
537  * Returns the service instance label (first label in instance name) of the service.
538  *
539  * @param[in]  aService  A pointer to the SRP service.
540  *
541  * @returns  A pointer to the null-terminated service instance label string..
542  *
543  */
544 const char *otSrpServerServiceGetInstanceLabel(const otSrpServerService *aService);
545 
546 /**
547  * Returns the full service name of the service.
548  *
549  * @param[in]  aService  A pointer to the SRP service.
550  *
551  * @returns  A pointer to the null-terminated service name string.
552  *
553  */
554 const char *otSrpServerServiceGetServiceName(const otSrpServerService *aService);
555 
556 /**
557  * Indicates whether this service matches a given service name.
558  *
559  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
560  * be the same).
561  *
562  * @param[in]  aService       A pointer to the SRP service.
563  * @param[in]  aServiceName  The service  name.
564  *
565  * @retval  TRUE   If service matches the service name.
566  * @retval  FALSE  If service does not match the service name.
567  *
568  */
569 bool otSrpServerServiceMatchesServiceName(const otSrpServerService *aService, const char *aServiceName);
570 
571 /**
572  * Gets the number of sub-types of the service.
573  *
574  * @param[in]  aService  A pointer to the SRP service.
575  *
576  * @returns The number of sub-types of @p aService.
577  *
578  */
579 uint16_t otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService *aService);
580 
581 /**
582  * Gets the sub-type service name (full name) of the service at a given index
583  *
584  * The full service name for a sub-type service follows "<sub-label>._sub.<service-labels>.<domain>.".
585  *
586  * @param[in]  aService  A pointer to the SRP service.
587  * @param[in] aIndex     The index to get.
588  *
589  * @returns A pointer to sub-type service name at @p aIndex, or `NULL` if no sub-type at this index.
590  *
591  */
592 const char *otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService *aService, uint16_t aIndex);
593 
594 /**
595  * Indicates whether or not the service has a given sub-type.
596  *
597  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
598  * be the same).
599  *
600  * @param[in] aService             A pointer to the SRP service.
601  * @param[in] aSubTypeServiceName  The sub-type service name (full name) to check.
602  *
603  * @retval TRUE   Service contains the sub-type @p aSubTypeServiceName.
604  * @retval FALSE  Service does not contain the sub-type @p aSubTypeServiceName.
605  *
606  */
607 bool otSrpServerServiceHasSubTypeServiceName(const otSrpServerService *aService, const char *aSubTypeServiceName);
608 
609 /**
610  * Parses a sub-type service name (full name) and extracts the sub-type label.
611  *
612  * The full service name for a sub-type service follows "<sub-label>._sub.<service-labels>.<domain>.".
613  *
614  * @param[in]  aSubTypeServiceName  A sub-type service name (full name).
615  * @param[out] aLabel               A pointer to a buffer to copy the extracted sub-type label.
616  * @param[in]  aLabelSize           Maximum size of @p aLabel buffer.
617  *
618  * @retval OT_ERROR_NONE          Name was successfully parsed and @p aLabel was updated.
619  * @retval OT_ERROR_NO_BUFS       The sub-type label could not fit in @p aLabel buffer (number of chars from label
620  *                                that could fit are copied in @p aLabel ensuring it is null-terminated).
621  * @retval OT_ERROR_INVALID_ARGS  @p aSubTypeServiceName is not a valid sub-type format.
622  *
623  */
624 otError otSrpServerParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize);
625 
626 /**
627  * Returns the port of the service instance.
628  *
629  * @param[in]  aService  A pointer to the SRP service.
630  *
631  * @returns  The port of the service.
632  *
633  */
634 uint16_t otSrpServerServiceGetPort(const otSrpServerService *aService);
635 
636 /**
637  * Returns the weight of the service instance.
638  *
639  * @param[in]  aService  A pointer to the SRP service.
640  *
641  * @returns  The weight of the service.
642  *
643  */
644 uint16_t otSrpServerServiceGetWeight(const otSrpServerService *aService);
645 
646 /**
647  * Returns the priority of the service instance.
648  *
649  * @param[in]  aService  A pointer to the SRP service.
650  *
651  * @returns  The priority of the service.
652  *
653  */
654 uint16_t otSrpServerServiceGetPriority(const otSrpServerService *aService);
655 
656 /**
657  * Returns the TTL of the service instance.
658  *
659  * @param[in]  aService  A pointer to the SRP service.
660  *
661  * @returns  The TTL of the service instance..
662  *
663  */
664 uint32_t otSrpServerServiceGetTtl(const otSrpServerService *aService);
665 
666 /**
667  * Returns the TXT record data of the service instance.
668  *
669  * @param[in]  aService        A pointer to the SRP service.
670  * @param[out] aDataLength     A pointer to return the TXT record data length. MUST NOT be NULL.
671  *
672  * @returns A pointer to the buffer containing the TXT record data (the TXT data length is returned in @p aDataLength).
673  *
674  */
675 const uint8_t *otSrpServerServiceGetTxtData(const otSrpServerService *aService, uint16_t *aDataLength);
676 
677 /**
678  * Returns the host which the service instance reside on.
679  *
680  * @param[in]  aService  A pointer to the SRP service.
681  *
682  * @returns  A pointer to the host instance.
683  *
684  */
685 const otSrpServerHost *otSrpServerServiceGetHost(const otSrpServerService *aService);
686 
687 /**
688  * Returns the LEASE and KEY-LEASE information of a given service.
689  *
690  * @param[in]   aService    A pointer to the SRP server service.
691  * @param[out]  aLeaseInfo  A pointer to where to output the LEASE and KEY-LEASE information.
692  *
693  */
694 void otSrpServerServiceGetLeaseInfo(const otSrpServerService *aService, otSrpServerLeaseInfo *aLeaseInfo);
695 /**
696  * @}
697  *
698  */
699 
700 #ifdef __cplusplus
701 } // extern "C"
702 #endif
703 
704 #endif // OPENTHREAD_SRP_SERVER_H_
705