objc2-cf-network 0.3.2

Bindings to the CFNetwork framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/cfnetwork/cfhost?language=objc)
#[doc(alias = "CFHostRef")]
#[repr(C)]
pub struct CFHost {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl CFHost {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"__CFHost"> for CFHost {}
);

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/cfnetwork/kcfstreamerrordomainnetdb?language=objc)
    pub static kCFStreamErrorDomainNetDB: i32;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/cfnetwork/kcfstreamerrordomainsystemconfiguration?language=objc)
    pub static kCFStreamErrorDomainSystemConfiguration: i32;
}

/// [Apple's documentation](https://developer.apple.com/documentation/cfnetwork/cfhostinfotype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFHostInfoType(pub c_int);
impl CFHostInfoType {
    #[doc(alias = "kCFHostAddresses")]
    pub const Addresses: Self = Self(0);
    #[doc(alias = "kCFHostNames")]
    pub const Names: Self = Self(1);
    #[doc(alias = "kCFHostReachability")]
    pub const Reachability: Self = Self(2);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CFHostInfoType {
    const ENCODING: Encoding = c_int::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFHostInfoType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/cfnetwork/cfhostclientcontext?language=objc)
#[repr(C, packed(2))]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFHostClientContext {
    pub version: CFIndex,
    pub info: *mut c_void,
    pub retain: CFAllocatorRetainCallBack,
    pub release: CFAllocatorReleaseCallBack,
    pub copyDescription: CFAllocatorCopyDescriptionCallBack,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CFHostClientContext {
    const ENCODING: Encoding = Encoding::Struct(
        "CFHostClientContext",
        &[
            <CFIndex>::ENCODING,
            <*mut c_void>::ENCODING,
            <CFAllocatorRetainCallBack>::ENCODING,
            <CFAllocatorReleaseCallBack>::ENCODING,
            <CFAllocatorCopyDescriptionCallBack>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFHostClientContext {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/cfnetwork/cfhostclientcallback?language=objc)
pub type CFHostClientCallBack = Option<
    unsafe extern "C-unwind" fn(NonNull<CFHost>, CFHostInfoType, *const CFStreamError, *mut c_void),
>;

unsafe impl ConcreteType for CFHost {
    #[doc(alias = "CFHostGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn CFHostGetTypeID() -> CFTypeID;
        }
        unsafe { CFHostGetTypeID() }
    }
}

impl CFHost {
    #[doc(alias = "CFHostCreateWithName")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn with_name(
        allocator: Option<&CFAllocator>,
        hostname: &CFString,
    ) -> CFRetained<CFHost> {
        extern "C-unwind" {
            fn CFHostCreateWithName(
                allocator: Option<&CFAllocator>,
                hostname: &CFString,
            ) -> Option<NonNull<CFHost>>;
        }
        let ret = unsafe { CFHostCreateWithName(allocator, hostname) };
        let ret =
            ret.expect("function was marked as returning non-null, but actually returned NULL");
        unsafe { CFRetained::from_raw(ret) }
    }

    #[doc(alias = "CFHostCreateWithAddress")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn with_address(
        allocator: Option<&CFAllocator>,
        addr: &CFData,
    ) -> CFRetained<CFHost> {
        extern "C-unwind" {
            fn CFHostCreateWithAddress(
                allocator: Option<&CFAllocator>,
                addr: &CFData,
            ) -> Option<NonNull<CFHost>>;
        }
        let ret = unsafe { CFHostCreateWithAddress(allocator, addr) };
        let ret =
            ret.expect("function was marked as returning non-null, but actually returned NULL");
        unsafe { CFRetained::from_raw(ret) }
    }

    #[doc(alias = "CFHostCreateCopy")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn new_copy(alloc: Option<&CFAllocator>, host: &CFHost) -> CFRetained<CFHost> {
        extern "C-unwind" {
            fn CFHostCreateCopy(
                alloc: Option<&CFAllocator>,
                host: &CFHost,
            ) -> Option<NonNull<CFHost>>;
        }
        let ret = unsafe { CFHostCreateCopy(alloc, host) };
        let ret =
            ret.expect("function was marked as returning non-null, but actually returned NULL");
        unsafe { CFRetained::from_raw(ret) }
    }

    /// # Safety
    ///
    /// `error` must be a valid pointer or null.
    #[doc(alias = "CFHostStartInfoResolution")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn start_info_resolution(
        &self,
        info: CFHostInfoType,
        error: *mut CFStreamError,
    ) -> bool {
        extern "C-unwind" {
            fn CFHostStartInfoResolution(
                the_host: &CFHost,
                info: CFHostInfoType,
                error: *mut CFStreamError,
            ) -> Boolean;
        }
        let ret = unsafe { CFHostStartInfoResolution(self, info, error) };
        ret != 0
    }

    /// # Safety
    ///
    /// `has_been_resolved` must be a valid pointer or null.
    #[doc(alias = "CFHostGetAddressing")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn addressing(
        &self,
        has_been_resolved: *mut Boolean,
    ) -> Option<CFRetained<CFArray>> {
        extern "C-unwind" {
            fn CFHostGetAddressing(
                the_host: &CFHost,
                has_been_resolved: *mut Boolean,
            ) -> Option<NonNull<CFArray>>;
        }
        let ret = unsafe { CFHostGetAddressing(self, has_been_resolved) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// # Safety
    ///
    /// `has_been_resolved` must be a valid pointer or null.
    #[doc(alias = "CFHostGetNames")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn names(&self, has_been_resolved: *mut Boolean) -> Option<CFRetained<CFArray>> {
        extern "C-unwind" {
            fn CFHostGetNames(
                the_host: &CFHost,
                has_been_resolved: *mut Boolean,
            ) -> Option<NonNull<CFArray>>;
        }
        let ret = unsafe { CFHostGetNames(self, has_been_resolved) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// # Safety
    ///
    /// `has_been_resolved` must be a valid pointer or null.
    #[doc(alias = "CFHostGetReachability")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn reachability(
        &self,
        has_been_resolved: *mut Boolean,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn CFHostGetReachability(
                the_host: &CFHost,
                has_been_resolved: *mut Boolean,
            ) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { CFHostGetReachability(self, has_been_resolved) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    #[doc(alias = "CFHostCancelInfoResolution")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn cancel_info_resolution(&self, info: CFHostInfoType) {
        extern "C-unwind" {
            fn CFHostCancelInfoResolution(the_host: &CFHost, info: CFHostInfoType);
        }
        unsafe { CFHostCancelInfoResolution(self, info) }
    }

    /// # Safety
    ///
    /// - `client_cb` must be implemented correctly.
    /// - `client_context` must be a valid pointer or null.
    #[doc(alias = "CFHostSetClient")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn set_client(
        &self,
        client_cb: CFHostClientCallBack,
        client_context: *mut CFHostClientContext,
    ) -> bool {
        extern "C-unwind" {
            fn CFHostSetClient(
                the_host: &CFHost,
                client_cb: CFHostClientCallBack,
                client_context: *mut CFHostClientContext,
            ) -> Boolean;
        }
        let ret = unsafe { CFHostSetClient(self, client_cb, client_context) };
        ret != 0
    }

    /// # Safety
    ///
    /// `run_loop` possibly has additional threading requirements.
    #[doc(alias = "CFHostScheduleWithRunLoop")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn schedule_with_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) {
        extern "C-unwind" {
            fn CFHostScheduleWithRunLoop(
                the_host: &CFHost,
                run_loop: &CFRunLoop,
                run_loop_mode: &CFString,
            );
        }
        unsafe { CFHostScheduleWithRunLoop(self, run_loop, run_loop_mode) }
    }

    /// # Safety
    ///
    /// `run_loop` possibly has additional threading requirements.
    #[doc(alias = "CFHostUnscheduleFromRunLoop")]
    #[deprecated = "Use Network framework instead, see deprecation notice in <CFNetwork/CFHost.h>"]
    #[inline]
    pub unsafe fn unschedule_from_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) {
        extern "C-unwind" {
            fn CFHostUnscheduleFromRunLoop(
                the_host: &CFHost,
                run_loop: &CFRunLoop,
                run_loop_mode: &CFString,
            );
        }
        unsafe { CFHostUnscheduleFromRunLoop(self, run_loop, run_loop_mode) }
    }
}

#[deprecated = "renamed to `CFHost::with_name`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostCreateWithName(
    allocator: Option<&CFAllocator>,
    hostname: &CFString,
) -> CFRetained<CFHost> {
    extern "C-unwind" {
        fn CFHostCreateWithName(
            allocator: Option<&CFAllocator>,
            hostname: &CFString,
        ) -> Option<NonNull<CFHost>>;
    }
    let ret = unsafe { CFHostCreateWithName(allocator, hostname) };
    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
    unsafe { CFRetained::from_raw(ret) }
}

#[deprecated = "renamed to `CFHost::with_address`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostCreateWithAddress(
    allocator: Option<&CFAllocator>,
    addr: &CFData,
) -> CFRetained<CFHost> {
    extern "C-unwind" {
        fn CFHostCreateWithAddress(
            allocator: Option<&CFAllocator>,
            addr: &CFData,
        ) -> Option<NonNull<CFHost>>;
    }
    let ret = unsafe { CFHostCreateWithAddress(allocator, addr) };
    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
    unsafe { CFRetained::from_raw(ret) }
}

#[deprecated = "renamed to `CFHost::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostCreateCopy(
    alloc: Option<&CFAllocator>,
    host: &CFHost,
) -> CFRetained<CFHost> {
    extern "C-unwind" {
        fn CFHostCreateCopy(alloc: Option<&CFAllocator>, host: &CFHost) -> Option<NonNull<CFHost>>;
    }
    let ret = unsafe { CFHostCreateCopy(alloc, host) };
    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
    unsafe { CFRetained::from_raw(ret) }
}

#[deprecated = "renamed to `CFHost::start_info_resolution`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostStartInfoResolution(
    the_host: &CFHost,
    info: CFHostInfoType,
    error: *mut CFStreamError,
) -> bool {
    extern "C-unwind" {
        fn CFHostStartInfoResolution(
            the_host: &CFHost,
            info: CFHostInfoType,
            error: *mut CFStreamError,
        ) -> Boolean;
    }
    let ret = unsafe { CFHostStartInfoResolution(the_host, info, error) };
    ret != 0
}

#[deprecated = "renamed to `CFHost::addressing`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostGetAddressing(
    the_host: &CFHost,
    has_been_resolved: *mut Boolean,
) -> Option<CFRetained<CFArray>> {
    extern "C-unwind" {
        fn CFHostGetAddressing(
            the_host: &CFHost,
            has_been_resolved: *mut Boolean,
        ) -> Option<NonNull<CFArray>>;
    }
    let ret = unsafe { CFHostGetAddressing(the_host, has_been_resolved) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

#[deprecated = "renamed to `CFHost::names`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostGetNames(
    the_host: &CFHost,
    has_been_resolved: *mut Boolean,
) -> Option<CFRetained<CFArray>> {
    extern "C-unwind" {
        fn CFHostGetNames(
            the_host: &CFHost,
            has_been_resolved: *mut Boolean,
        ) -> Option<NonNull<CFArray>>;
    }
    let ret = unsafe { CFHostGetNames(the_host, has_been_resolved) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

#[deprecated = "renamed to `CFHost::reachability`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostGetReachability(
    the_host: &CFHost,
    has_been_resolved: *mut Boolean,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn CFHostGetReachability(
            the_host: &CFHost,
            has_been_resolved: *mut Boolean,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { CFHostGetReachability(the_host, has_been_resolved) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

extern "C-unwind" {
    #[deprecated = "renamed to `CFHost::cancel_info_resolution`"]
    pub fn CFHostCancelInfoResolution(the_host: &CFHost, info: CFHostInfoType);
}

#[deprecated = "renamed to `CFHost::set_client`"]
#[inline]
pub unsafe extern "C-unwind" fn CFHostSetClient(
    the_host: &CFHost,
    client_cb: CFHostClientCallBack,
    client_context: *mut CFHostClientContext,
) -> bool {
    extern "C-unwind" {
        fn CFHostSetClient(
            the_host: &CFHost,
            client_cb: CFHostClientCallBack,
            client_context: *mut CFHostClientContext,
        ) -> Boolean;
    }
    let ret = unsafe { CFHostSetClient(the_host, client_cb, client_context) };
    ret != 0
}

extern "C-unwind" {
    #[deprecated = "renamed to `CFHost::schedule_with_run_loop`"]
    pub fn CFHostScheduleWithRunLoop(
        the_host: &CFHost,
        run_loop: &CFRunLoop,
        run_loop_mode: &CFString,
    );
}

extern "C-unwind" {
    #[deprecated = "renamed to `CFHost::unschedule_from_run_loop`"]
    pub fn CFHostUnscheduleFromRunLoop(
        the_host: &CFHost,
        run_loop: &CFRunLoop,
        run_loop_mode: &CFString,
    );
}