2 * Copyright (c) 2019-2020 Apple Inc. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * https://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __DNSSD_XPC_H__
18 #define __DNSSD_XPC_H__
20 #include <CoreUtils/CommonServices.h>
24 #define DNSSD_MACH_SERVICE_NAME "com.apple.dnssd.service"
26 #define DNSSD_COMMAND_GETADDRINFO "getaddrinfo"
27 #define DNSSD_COMMAND_STOP "stop"
29 CU_ASSUME_NONNULL_BEGIN
35 * Gets command as a C string from XPC message.
41 * Command, if present. Otherwise, NULL.
43 const char * _Nullable
44 dnssd_xpc_message_get_command(xpc_object_t msg
);
48 * Gets error code from XPC message.
54 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
57 * Error code, if present. Otherwise, 0.
60 dnssd_xpc_message_get_error(xpc_object_t msg
, bool * _Nullable out_valid
);
64 * Gets command instance ID from XPC message.
70 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
73 * ID, if present. Otherwise, 0.
76 dnssd_xpc_message_get_id(xpc_object_t msg
, bool * _Nullable out_valid
);
80 * Gets command parameter dictionary from XPC message.
86 * Command parameter dictionary, if present. Otherwise, NULL.
88 xpc_object_t _Nullable
89 dnssd_xpc_message_get_parameters(xpc_object_t msg
);
93 * Gets result array from XPC message.
99 * Result array, if present. Otherwise, NULL.
101 xpc_object_t _Nullable
102 dnssd_xpc_message_get_results(xpc_object_t msg
);
106 * Sets command in XPC message.
112 * Command as a C string.
115 dnssd_xpc_message_set_command(xpc_object_t msg
, const char *command
);
119 * Sets error code in XPC message.
128 dnssd_xpc_message_set_error(xpc_object_t msg
, DNSServiceErrorType error
);
132 * Sets command instance ID in XPC message.
138 * Command instance ID.
141 dnssd_xpc_message_set_id(xpc_object_t msg
, uint64_t ident
);
145 * Sets command parameters dictionary in XPC message.
151 * Command parameters dictionary.
154 dnssd_xpc_message_set_parameters(xpc_object_t msg
, xpc_object_t params
);
158 * Sets command result array in XPC message.
164 * Command result array.
167 dnssd_xpc_message_set_results(xpc_object_t msg
, xpc_object_t results
);
171 * Gets delegate ID as a PID from a command parameters dictionary.
174 * Command parameters dictionary.
177 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
180 * Delegate ID as PID, if present. Otherwise, 0.
183 dnssd_xpc_parameters_get_delegate_pid(xpc_object_t params
, bool * _Nullable out_valid
);
187 * Gets delegate ID as a UUID from a command parameters dictionary.
190 * Command parameters dictionary.
193 * Delegate ID as UUID, if present. Otherwise, NULL.
195 const uint8_t * _Nullable
196 dnssd_xpc_parameters_get_delegate_uuid(xpc_object_t params
);
200 * Gets a delegate audit token from a command parameters dictionary.
203 * Command parameters dictionary.
205 * @param audit_token_storage
206 * Pointer to an audit token to overwrite with parameters dictionary's delegate audit token data.
209 * If the parameters dictionary contains a delegate audit token, this function copies it to
210 * audit_token_storage and returns audit_token_storage. Otherwise, it returns NULL.
212 audit_token_t
* _Nullable
213 dnssd_xpc_parameters_get_delegate_audit_token(xpc_object_t params
, audit_token_t
*audit_token_storage
);
217 * Gets flags from a command parameters dictionary.
220 * Command parameters dictionary.
223 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
226 * Flags, if present. Otherwise, 0.
229 dnssd_xpc_parameters_get_flags(xpc_object_t params
, bool * _Nullable out_valid
);
233 * Gets account id from a command parameters dictionary.
236 * Command parameters dictionary.
239 * Account, if present, as a const char *. Otherwise, NULL.
241 const char * _Nullable
242 dnssd_xpc_parameters_get_account_id(xpc_object_t params
);
246 * Gets hostname from a command parameters dictionary.
249 * Command parameters dictionary.
252 * Hostname, if present, as an XPC string object. Otherwise, NULL.
254 xpc_object_t _Nullable
255 dnssd_xpc_parameters_get_hostname_object(xpc_object_t params
);
259 * Gets interface index from a command parameters dictionary.
262 * Command parameters dictionary.
265 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
268 * Interface index, if present. Otherwise, 0.
271 dnssd_xpc_parameters_get_interface_index(xpc_object_t params
, bool * _Nullable out_valid
);
275 * Gets need_auth_tags boolean value from a command parameters dictionary.
278 * Command parameters dictionary.
284 dnssd_xpc_parameters_get_need_authentication_tags(xpc_object_t params
);
288 * Gets need encryption boolean value from a command parameters dictionary.
291 * Command parameters dictionary.
297 dnssd_xpc_parameters_get_need_encrypted_query(xpc_object_t params
);
301 * Gets fallback resolver configuration dictionary from a command parameters dictionary.
304 * Command parameters dictionary.
307 * A dictionary containing resolver configuration to use in the absence of encrypted resolvers, or NULL.
309 xpc_object_t _Nullable
310 dnssd_xpc_parameters_get_fallback_config(xpc_object_t params
);
314 * Gets resolver UUID array from a command parameters dictionary.
317 * Command parameters dictionary.
320 * An array of UUIDs, or NULL.
322 xpc_object_t _Nullable
323 dnssd_xpc_parameters_get_resolver_uuid_array(xpc_object_t params
);
327 * Gets protocols from a command parameters dictionary.
330 * Command parameters dictionary.
333 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
336 * Protocols, if present. Otherwise, 0.
339 dnssd_xpc_parameters_get_protocols(xpc_object_t params
, bool * _Nullable out_valid
);
343 * Gets the service scheme from a command parameters dictionary.
346 * Command parameters dictionary.
349 * A string containing service scheme for the query, or NULL.
351 const char * _Nullable
352 dnssd_xpc_parameters_get_service_scheme(xpc_object_t params
);
356 * Sets delegate ID as a PID in a command parameters dictionary.
359 * Command parameters dictionary.
365 dnssd_xpc_parameters_set_delegate_pid(xpc_object_t params
, pid_t pid
);
369 * Sets delegate ID as a UUID in a command parameters dictionary.
372 * Command parameters dictionary.
378 dnssd_xpc_parameters_set_delegate_uuid(xpc_object_t params
, uuid_t _Nonnull uuid
);
382 * Sets the delegate audit token in a command parameters dictionary.
385 * Command parameters dictionary.
388 * The delegate audit token.
391 dnssd_xpc_parameters_set_delegate_audit_token(xpc_object_t params
, const audit_token_t
*audit_token
);
395 * Sets flags in a command parameters dictionary.
398 * Command parameters dictionary.
404 dnssd_xpc_parameters_set_flags(xpc_object_t params
, DNSServiceFlags flags
);
408 * Sets account id in a command parameters dictionary.
411 * Command parameters dictionary.
417 dnssd_xpc_parameters_set_account_id(xpc_object_t params
, const char *account_id
);
421 * Sets hostname in a command parameters dictionary.
424 * Command parameters dictionary.
430 dnssd_xpc_parameters_set_hostname(xpc_object_t params
, const char *hostname
);
434 * Sets interface index in a command parameters dictionary.
437 * Command parameters dictionary.
439 * @param interface_index
443 dnssd_xpc_parameters_set_interface_index(xpc_object_t params
, uint32_t interface_index
);
447 * Sets whether mDNSResponder should include an authentication tag for each hostname resolution.
450 * Command parameters dictionary.
453 * Pass <code>true</code> to enable this behavior. Pass <code>false</code> to disable it.
456 dnssd_xpc_parameters_set_need_authentication_tags(xpc_object_t params
, bool need
);
460 * Specifies whether or not queries must use encrypted transports to the next DNS server.
463 * Command parameters dictionary.
466 * Pass <code>true</code> if encrypted queries are required, otherwise, pass <code>false</code>.
468 * @param fallback_config
469 * If not NULL, specify a custom resolver configuration to use if no encrypted resolver configuation is otherwise
473 dnssd_xpc_parameters_set_need_encrypted_query(xpc_object_t params
, bool need
, _Nullable xpc_object_t fallback_config
);
477 * Add a resolver UUID that represents a resolver configuration registered with the system that should
478 * be applied to this resolution. Multiple UUIDs can be set.
481 * Command parameters dictionary.
484 * UUID of a resolver configuration registered with the system.
487 dnssd_xpc_parameters_add_resolver_uuid(xpc_object_t params
, uuid_t _Nonnull uuid
);
491 * Sets a service scheme in a command parameters dictionary.
494 * Command parameters dictionary.
496 * @param service_scheme
500 dnssd_xpc_parameters_set_service_scheme(xpc_object_t params
, const char *service_scheme
);
504 * Sets protocols in a command parameters dictionary.
507 * Command parameters dictionary.
513 dnssd_xpc_parameters_set_protocols(xpc_object_t params
, DNSServiceProtocol protocols
);
517 * Gets authentication tag from a command result dictionary.
520 * The command result dictionary.
523 * Authentication tag, if present, as an XPC data object. Otherwise, NULL.
525 xpc_object_t _Nullable
526 dnssd_xpc_result_get_authentication_tag_object(xpc_object_t result
);
530 * Gets error code from a command result dictionary.
533 * The command result dictionary.
536 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
539 * Error code, if present. Otherwise, 0.
542 dnssd_xpc_result_get_error(xpc_object_t result
, bool * _Nullable out_valid
);
546 * Gets flags from a command result dictionary.
549 * The command result dictionary.
552 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
555 * Flags, if present. Otherwise, 0.
558 dnssd_xpc_result_get_flags(xpc_object_t result
, bool * _Nullable out_valid
);
562 * Gets interface index from a command result dictionary.
565 * The command result dictionary.
568 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
571 * Interface index, if present. Otherwise, 0.
574 dnssd_xpc_result_get_interface_index(xpc_object_t result
, bool * _Nullable out_valid
);
578 * Gets record class from a command result dictionary.
581 * The command result dictionary.
584 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
587 * Record class, if present. Otherwise, 0.
590 dnssd_xpc_result_get_record_class(xpc_object_t result
, bool * _Nullable out_valid
);
594 * Gets record data from a command result dictionary.
597 * The command result dictionary.
600 * Record data, if present, as an XPC data object. Otherwise, NULL.
602 xpc_object_t _Nullable
603 dnssd_xpc_result_get_record_data_object(xpc_object_t result
);
607 * Gets record name from a command result dictionary.
610 * The command result dictionary.
613 * Record name, if present, as an XPC string object. Otherwise, NULL.
615 xpc_object_t _Nullable
616 dnssd_xpc_result_get_record_name_object(xpc_object_t result
);
620 * Gets record canonical name from a command result dictionary.
623 * The command result dictionary.
626 * Record canonical name, if present, as an XPC string object. Otherwise, NULL.
628 xpc_object_t _Nullable
629 dnssd_xpc_result_get_record_cname_object(xpc_object_t result
);
633 * Gets record type from a command result dictionary.
636 * The command result dictionary.
639 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
642 * Record type, if present. Otherwise, 0.
645 dnssd_xpc_result_get_record_type(xpc_object_t result
, bool * _Nullable out_valid
);
649 * Gets used record protocol from a command result dictionary.
652 * The command result dictionary.
655 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
658 * Used record protocol, if present. Otherwise, 0.
661 dnssd_xpc_result_get_record_protocol(xpc_object_t result
, bool * _Nullable out_valid
);
665 * Gets provider name from a command result dictionary.
668 * The command result dictionary.
671 * Provider name, if present, as an XPC string object. Otherwise, NULL.
673 xpc_object_t _Nullable
674 dnssd_xpc_result_get_provider_name_object(xpc_object_t result
);
678 * Gets canonical name updates from a command result dictionary.
681 * The command result dictionary.
684 * The canonical name update, if present, as an XPC array object. Otherwise, NULL.
686 xpc_object_t _Nullable
687 dnssd_xpc_result_get_cname_update(xpc_object_t result
);
691 * Sets the authentication tag in a command result dictionary.
694 * The command result dictionary.
696 * @param auth_tag_ptr
697 * Pointer to the authentication tag.
699 * @param auth_tag_len
700 * Length of the authentication tag.
703 dnssd_xpc_result_set_authentication_tag(xpc_object_t result
, const void *auth_tag_ptr
, size_t auth_tag_len
);
707 * Sets the error code in a command result dictionary.
710 * The command result dictionary.
716 dnssd_xpc_result_set_error(xpc_object_t result
, DNSServiceErrorType error
);
720 * Sets flags in a command result dictionary.
723 * The command result dictionary.
729 dnssd_xpc_result_set_flags(xpc_object_t result
, DNSServiceFlags flags
);
733 * Sets interface index in a command result dictionary.
736 * The command result dictionary.
738 * @param interface_index
742 dnssd_xpc_result_set_interface_index(xpc_object_t result
, uint32_t interface_index
);
746 * Sets record class in a command result dictionary.
749 * The command result dictionary.
755 dnssd_xpc_result_set_record_class(xpc_object_t result
, uint16_t class);
759 * Sets the record data in a command result dictionary.
762 * The command result dictionary.
765 * Pointer to the record data.
768 * Length of the record data.
771 dnssd_xpc_result_set_record_data(xpc_object_t result
, const void * _Nullable data_ptr
, size_t data_len
);
775 * Sets record name in a command result dictionary.
778 * The command result dictionary.
784 dnssd_xpc_result_set_record_name(xpc_object_t result
, const char *name
);
788 * Sets record canonical name in a command result dictionary.
791 * The command result dictionary.
794 * Record canonical name.
797 dnssd_xpc_result_set_record_cname(xpc_object_t result
, const char *cname
);
801 * Sets record type in a command result dictionary.
804 * The command result dictionary.
810 dnssd_xpc_result_set_record_type(xpc_object_t result
, uint16_t type
);
814 * Sets record protocol in a command result dictionary.
817 * The command result dictionary.
823 dnssd_xpc_result_set_record_protocol(xpc_object_t result
, uint16_t protocol
);
827 * Sets the DNS provider name in a command result dictionary.
830 * The command result dictionary.
832 * @param provider_name
836 dnssd_xpc_result_set_provider_name(xpc_object_t result
, const char *provider_name
);
840 * Sets a canonical name update in a command result dictionary.
843 * The command result dictionary.
845 * @param cname_update
846 * The canonical name update as an array of canonical names as strings.
849 dnssd_xpc_result_set_cname_update(xpc_object_t result
, xpc_object_t cname_update
);
853 CU_ASSUME_NONNULL_END
855 #endif // __DNSSD_XPC_H__