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 __MDNS_TRUST_H__
18 #define __MDNS_TRUST_H__
20 #include "mdns_base.h"
21 #include <dispatch/dispatch.h>
25 OS_CLOSED_ENUM(mdns_trust_status
, int,
26 mdns_trust_status_denied
= 0,
27 /*! @const mdns_trust_status_deny The requested trust is denied. */
28 mdns_trust_status_granted
= 1,
29 /*! @const mdns_trust_status_granted The requested trust is granted. */
30 mdns_trust_status_pending
= 2,
31 /*! @const mdns_trust_status_pending The requested trust is pending user interaction. */
32 mdns_trust_status_no_entitlement
= 3
33 /*! @const mdns_trust_status_no_entitlement The requested trust did not have a proper entitlement. */
36 OS_CLOSED_OPTIONS(mdns_trust_flags
, uint32_t,
37 mdns_trust_flags_none
= 0,
38 mdns_trust_flags_entitlement
= (1U << 0),
39 /*! @const mdns_trust_flags_entitlement The app has a valid catch-all entitlement. */
42 MDNS_ASSUME_NONNULL_BEGIN
44 static inline const char *
45 mdns_trust_status_to_string(mdns_trust_status_t result
)
48 case mdns_trust_status_denied
: return "denied";
49 case mdns_trust_status_granted
: return "granted";
50 case mdns_trust_status_pending
: return "pending";
51 case mdns_trust_status_no_entitlement
: return "no_entitlement";
52 default: return "<INVALID RESULT>";
56 //======================================================================================================================
57 // MARK: - mdns_trust Initialization
60 mdns_trust_init(void);
62 //======================================================================================================================
63 // MARK: - mdns_trust Direct checks
66 mdns_trust_check_bonjour(audit_token_t audit_token
, const char * _Nullable service
, mdns_trust_flags_t
* _Nullable flags
);
69 mdns_trust_check_register_service(audit_token_t audit_token
, const char * _Nullable service
, mdns_trust_flags_t
* _Nullable flags
);
72 mdns_trust_check_query(audit_token_t audit_token
, const char * qname
, const char * _Nullable service
, uint16_t qtype
, bool force_multicast
, mdns_trust_flags_t
* _Nullable flags
);
75 mdns_trust_check_getaddrinfo(audit_token_t audit_token
, const char * hostname
, mdns_trust_flags_t
* _Nullable flags
);
77 //======================================================================================================================
78 // MARK: - mdns_trust Object to receive status updates
80 MDNS_RETURNS_RETAINED mdns_trust_t _Nullable
81 mdns_trust_create(audit_token_t audit_token
, const char *_Nullable query
, mdns_trust_flags_t flags
);
84 mdns_trust_set_context(mdns_trust_t trust
, void *_Nullable context
);
87 mdns_trust_get_context(mdns_trust_t trust
);
90 mdns_trust_activate(mdns_trust_t trust
);
93 mdns_trust_invalidate(mdns_trust_t trust
);
96 mdns_trust_set_queue(mdns_trust_t trust
, dispatch_queue_t queue
);
98 OS_CLOSED_ENUM(mdns_trust_event
, int,
99 mdns_trust_event_result
= 0,
100 mdns_trust_event_invalidated
= 1
103 static inline const char *
104 mdns_trust_event_to_string(const mdns_trust_event_t event
)
107 case mdns_trust_event_result
: return "result";
108 case mdns_trust_event_invalidated
: return "invalidated";
109 default: return "<invalid event value>";
114 (^mdns_trust_event_handler_t
)(mdns_trust_event_t event
, mdns_trust_status_t status
);
117 mdns_trust_set_event_handler(mdns_trust_t trust
, mdns_trust_event_handler_t handler
);
119 #define mdns_trust_forget(X) mdns_forget_with_invalidation(X, trust)
121 MDNS_ASSUME_NONNULL_END
123 #endif // __MDNS_TRUST_H__