2 * Copyright (c) 2019 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 * http://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
37 * Gets command as a C string from XPC message.
43 * Command, if present. Otherwise, NULL.
45 const char * _Nullable
46 dnssd_xpc_message_get_command(xpc_object_t msg
);
50 * Gets error code from XPC message.
56 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
59 * Error code, if present. Otherwise, 0.
62 dnssd_xpc_message_get_error(xpc_object_t msg
, bool * _Nullable out_valid
);
66 * Gets command instance ID from XPC message.
72 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
75 * ID, if present. Otherwise, 0.
78 dnssd_xpc_message_get_id(xpc_object_t msg
, bool * _Nullable out_valid
);
82 * Gets command parameter dictionary from XPC message.
88 * Command parameter dictionary, if present. Otherwise, NULL.
90 xpc_object_t _Nullable
91 dnssd_xpc_message_get_parameters(xpc_object_t msg
);
95 * Gets result array from XPC message.
101 * Result array, if present. Otherwise, NULL.
103 xpc_object_t _Nullable
104 dnssd_xpc_message_get_results(xpc_object_t msg
);
108 * Sets command in XPC message.
114 * Command as a C string.
117 dnssd_xpc_message_set_command(xpc_object_t msg
, const char *command
);
121 * Sets error code in XPC message.
130 dnssd_xpc_message_set_error(xpc_object_t msg
, DNSServiceErrorType error
);
134 * Sets command instance ID in XPC message.
140 * Command instance ID.
143 dnssd_xpc_message_set_id(xpc_object_t msg
, uint64_t ident
);
147 * Sets command parameters dictionary in XPC message.
153 * Command parameters dictionary.
156 dnssd_xpc_message_set_parameters(xpc_object_t msg
, xpc_object_t params
);
160 * Sets command result array in XPC message.
166 * Command result array.
169 dnssd_xpc_message_set_results(xpc_object_t msg
, xpc_object_t results
);
173 * Gets delegate ID as a PID from a command parameters dictionary.
176 * Command parameters dictionary.
179 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
182 * Delegate ID as PID, if present. Otherwise, 0.
185 dnssd_xpc_parameters_get_delegate_pid(xpc_object_t params
, bool * _Nullable out_valid
);
189 * Gets delegate ID as a UUID from a command parameters dictionary.
192 * Command parameters dictionary.
195 * Delegate ID as UUID, if present. Otherwise, NULL.
197 const uint8_t * _Nullable
198 dnssd_xpc_parameters_get_delegate_uuid(xpc_object_t params
);
202 * Gets flags from a command parameters dictionary.
205 * Command parameters dictionary.
208 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
211 * Flags, if present. Otherwise, 0.
214 dnssd_xpc_parameters_get_flags(xpc_object_t params
, bool * _Nullable out_valid
);
218 * Gets hostname from a command parameters dictionary.
221 * Command parameters dictionary.
224 * Hostname, if present, as an XPC string object. Otherwise, NULL.
226 xpc_object_t _Nullable
227 dnssd_xpc_parameters_get_hostname_object(xpc_object_t params
);
231 * Gets interface index from a command parameters dictionary.
234 * Command parameters dictionary.
237 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
240 * Interface index, if present. Otherwise, 0.
243 dnssd_xpc_parameters_get_interface_index(xpc_object_t params
, bool * _Nullable out_valid
);
247 * Gets need_auth_tags boolean value from a command parameters dictionary.
250 * Command parameters dictionary.
256 dnssd_xpc_parameters_get_need_authentication_tags(xpc_object_t params
);
260 * Gets protocols from a command parameters dictionary.
263 * Command parameters dictionary.
266 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
269 * Protocols, if present. Otherwise, 0.
272 dnssd_xpc_parameters_get_protocols(xpc_object_t params
, bool * _Nullable out_valid
);
276 * Sets delegate ID as a PID in a command parameters dictionary.
279 * Command parameters dictionary.
285 dnssd_xpc_parameters_set_delegate_pid(xpc_object_t params
, pid_t pid
);
289 * Sets delegate ID as a UUID in a command parameters dictionary.
292 * Command parameters dictionary.
298 dnssd_xpc_parameters_set_delegate_uuid(xpc_object_t params
, uuid_t _Nonnull uuid
);
302 * Sets flags in a command parameters dictionary.
305 * Command parameters dictionary.
311 dnssd_xpc_parameters_set_flags(xpc_object_t params
, DNSServiceFlags flags
);
315 * Sets hostname in a command parameters dictionary.
318 * Command parameters dictionary.
324 dnssd_xpc_parameters_set_hostname(xpc_object_t params
, const char *hostname
);
328 * Sets interface index in a command parameters dictionary.
331 * Command parameters dictionary.
333 * @param interface_index
337 dnssd_xpc_parameters_set_interface_index(xpc_object_t params
, uint32_t interface_index
);
341 * Sets whether mDNSResponder should include an authentication tag for each hostname resolution.
344 * Command parameters dictionary.
347 * Pass <code>true</code> to enable this behavior. Pass <code>false</code> to disable it.
350 dnssd_xpc_parameters_set_need_authentication_tags(xpc_object_t params
, bool need
);
354 * Sets protocols in a command parameters dictionary.
357 * Command parameters dictionary.
363 dnssd_xpc_parameters_set_protocols(xpc_object_t params
, DNSServiceProtocol protocols
);
367 * Gets authentication tag from a command result dictionary.
370 * The command result dictionary.
373 * Authentication tag, if present, as an XPC data object. Otherwise, NULL.
375 xpc_object_t _Nullable
376 dnssd_xpc_result_get_authentication_tag_object(xpc_object_t result
);
380 * Gets error code from a command result dictionary.
383 * The command result dictionary.
386 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
389 * Error code, if present. Otherwise, 0.
392 dnssd_xpc_result_get_error(xpc_object_t result
, bool * _Nullable out_valid
);
396 * Gets flags from a command result dictionary.
399 * The command result dictionary.
402 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
405 * Flags, if present. Otherwise, 0.
408 dnssd_xpc_result_get_flags(xpc_object_t result
, bool * _Nullable out_valid
);
412 * Gets interface index from a command result dictionary.
415 * The command result dictionary.
418 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
421 * Interface index, if present. Otherwise, 0.
424 dnssd_xpc_result_get_interface_index(xpc_object_t result
, bool * _Nullable out_valid
);
428 * Gets record class from a command result dictionary.
431 * The command result dictionary.
434 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
437 * Record class, if present. Otherwise, 0.
440 dnssd_xpc_result_get_record_class(xpc_object_t result
, bool * _Nullable out_valid
);
444 * Gets record data from a command result dictionary.
447 * The command result dictionary.
450 * Record data, if present, as an XPC data object. Otherwise, NULL.
452 xpc_object_t _Nullable
453 dnssd_xpc_result_get_record_data_object(xpc_object_t result
);
457 * Gets record name from a command result dictionary.
460 * The command result dictionary.
463 * Record name, if present, as an XPC string object. Otherwise, NULL.
465 xpc_object_t _Nullable
466 dnssd_xpc_result_get_record_name_object(xpc_object_t result
);
470 * Gets record type from a command result dictionary.
473 * The command result dictionary.
476 * If non-NULL, set to true if value is present and of correct type, otherwise, set to false.
479 * Record type, if present. Otherwise, 0.
482 dnssd_xpc_result_get_record_type(xpc_object_t result
, bool * _Nullable out_valid
);
486 * Sets the authentication tag in a command result dictionary.
489 * The command result dictionary.
491 * @param auth_tag_ptr
492 * Pointer to the authentication tag.
494 * @param auth_tag_len
495 * Length of the authentication tag.
498 dnssd_xpc_result_set_authentication_tag(xpc_object_t result
, const void *auth_tag_ptr
, size_t auth_tag_len
);
502 * Sets the error code in a command result dictionary.
505 * The command result dictionary.
511 dnssd_xpc_result_set_error(xpc_object_t result
, DNSServiceErrorType error
);
515 * Sets flags in a command result dictionary.
518 * The command result dictionary.
524 dnssd_xpc_result_set_flags(xpc_object_t result
, DNSServiceFlags flags
);
528 * Sets interface index in a command result dictionary.
531 * The command result dictionary.
533 * @param interface_index
537 dnssd_xpc_result_set_interface_index(xpc_object_t result
, uint32_t interface_index
);
541 * Sets record class in a command result dictionary.
544 * The command result dictionary.
550 dnssd_xpc_result_set_record_class(xpc_object_t result
, uint16_t class);
554 * Sets the record data in a command result dictionary.
557 * The command result dictionary.
560 * Pointer to the record data.
563 * Length of the record data.
566 dnssd_xpc_result_set_record_data(xpc_object_t result
, const void * _Nullable data_ptr
, size_t data_len
);
570 * Sets record name in a command result dictionary.
573 * The command result dictionary.
579 dnssd_xpc_result_set_record_name(xpc_object_t result
, const char *name
);
583 * Sets record type in a command result dictionary.
586 * The command result dictionary.
592 dnssd_xpc_result_set_record_type(xpc_object_t result
, uint16_t type
);
598 CU_ASSUME_NONNULL_END
600 #endif // __DNSSD_XPC_H__