]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/mdns_objects/mdns_trust.h
mDNSResponder-1310.80.1.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / mdns_objects / mdns_trust.h
1 /*
2 * Copyright (c) 2019-2020 Apple Inc. All rights reserved.
3 *
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
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #ifndef __MDNS_TRUST_H__
18 #define __MDNS_TRUST_H__
19
20 #include "mdns_base.h"
21 #include <dispatch/dispatch.h>
22
23 MDNS_DECL(trust);
24
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. */
34 );
35
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. */
40 );
41
42 MDNS_ASSUME_NONNULL_BEGIN
43
44 static inline const char *
45 mdns_trust_status_to_string(mdns_trust_status_t result)
46 {
47 switch (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>";
53 }
54 }
55
56 //======================================================================================================================
57 // MARK: - mdns_trust Initialization
58
59 void
60 mdns_trust_init(void);
61
62 //======================================================================================================================
63 // MARK: - mdns_trust Direct checks
64
65 mdns_trust_status_t
66 mdns_trust_check_bonjour(audit_token_t audit_token, const char * _Nullable service, mdns_trust_flags_t * _Nullable flags);
67
68 mdns_trust_status_t
69 mdns_trust_check_register_service(audit_token_t audit_token, const char * _Nullable service, mdns_trust_flags_t * _Nullable flags);
70
71 mdns_trust_status_t
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);
73
74 mdns_trust_status_t
75 mdns_trust_check_getaddrinfo(audit_token_t audit_token, const char * hostname, mdns_trust_flags_t * _Nullable flags);
76
77 //======================================================================================================================
78 // MARK: - mdns_trust Object to receive status updates
79
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);
82
83 void
84 mdns_trust_set_context(mdns_trust_t trust, void *_Nullable context);
85
86 void *_Nullable
87 mdns_trust_get_context(mdns_trust_t trust);
88
89 void
90 mdns_trust_activate(mdns_trust_t trust);
91
92 void
93 mdns_trust_invalidate(mdns_trust_t trust);
94
95 void
96 mdns_trust_set_queue(mdns_trust_t trust, dispatch_queue_t queue);
97
98 OS_CLOSED_ENUM(mdns_trust_event, int,
99 mdns_trust_event_result = 0,
100 mdns_trust_event_invalidated = 1
101 );
102
103 static inline const char *
104 mdns_trust_event_to_string(const mdns_trust_event_t event)
105 {
106 switch (event) {
107 case mdns_trust_event_result: return "result";
108 case mdns_trust_event_invalidated: return "invalidated";
109 default: return "<invalid event value>";
110 }
111 }
112
113 typedef void
114 (^mdns_trust_event_handler_t)(mdns_trust_event_t event, mdns_trust_status_t status);
115
116 void
117 mdns_trust_set_event_handler(mdns_trust_t trust, mdns_trust_event_handler_t handler);
118
119 #define mdns_trust_forget(X) mdns_forget_with_invalidation(X, trust)
120
121 MDNS_ASSUME_NONNULL_END
122
123 #endif // __MDNS_TRUST_H__