diff --git a/generate_bindings.sh b/generate_bindings.sh index 76b8b85..c158e03 100755 --- a/generate_bindings.sh +++ b/generate_bindings.sh @@ -2,14 +2,21 @@ # Always have the latest version of bindgen and rustfmt installed before using this script +set -eu + export DYLD_LIBRARY_PATH=$(rustc +stable --print sysroot)/lib SDK_VERSION=`xcodebuild -sdk macosx -version SDKVersion` SDK_PATH=`xcodebuild -sdk macosx -version Path` FRAMEWORK_PATH="$SDK_PATH/System/Library/Frameworks/" -HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCDynamicStore.h" -BINDING_PATH="./system-configuration-sys/src/dynamic_store.rs" +PREFERENCES_HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCPreferences.h" +DYNAMIC_STORE_HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCDynamicStore.h" +NETWORK_CONFIGURATION_HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h" + +PREFERENCES_BINDING_PATH="./system-configuration-sys/src/preferences.rs" +DYNAMIC_STORE_BINDING_PATH="./system-configuration-sys/src/dynamic_store.rs" +NETWORK_CONFIGURATION_BINDING_PATH="./system-configuration-sys/src/network_configuration.rs" BINDGEN_VERSION=`bindgen --version` @@ -17,8 +24,44 @@ echo "Using macOS SDK at: $SDK_PATH" echo "Using $BINDGEN_VERSION" echo "" -echo "Generating bindings for $HEADER_PATH" +echo "Generating bindings for $PREFERENCES_HEADER_PATH" +bindgen \ + --no-doc-comments \ + --whitelist-function "SCPreferences.*" \ + --blacklist-type "(__)?CF.*" \ + --blacklist-type "Boolean" \ + --blacklist-type "dispatch_queue_[ts]" \ + --blacklist-type "(AuthorizationOpaqueRef|__SCPreferences)" \ + --raw-line "// Generated using:" \ + --raw-line "// $BINDGEN_VERSION" \ + --raw-line "// macOS SDK $SDK_VERSION." \ + --raw-line "" \ + --raw-line "use core_foundation_sys::array::CFArrayRef;" \ + --raw-line "use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};" \ + --raw-line "use core_foundation_sys::data::CFDataRef;" \ + --raw-line "use core_foundation_sys::string::CFStringRef;" \ + --raw-line "use core_foundation_sys::propertylist::CFPropertyListRef;" \ + --raw-line "use core_foundation_sys::runloop::CFRunLoopRef;" \ + --raw-line "" \ + --raw-line "use dispatch_queue_t;" \ + --raw-line "use libc::c_void;" \ + --raw-line "" \ + --raw-line "pub type AuthorizationOpaqueRef = c_void;" \ + --raw-line "pub type __SCPreferences = c_void;" \ + -o $PREFERENCES_BINDING_PATH \ + $PREFERENCES_HEADER_PATH -- \ + -I$SDK_PATH/usr/include \ + -F$FRAMEWORK_PATH + +rustfmt $PREFERENCES_BINDING_PATH + +echo "" +echo "" +echo "Generating bindings for $DYNAMIC_STORE_HEADER_PATH" +sleep 2 + bindgen \ + --no-doc-comments \ --whitelist-function "SCDynamicStore.*" \ --whitelist-var "kSCDynamicStore.*" \ --blacklist-type "(__)?CF.*" \ @@ -35,11 +78,54 @@ bindgen \ --raw-line "use core_foundation_sys::propertylist::CFPropertyListRef;" \ --raw-line "use core_foundation_sys::runloop::CFRunLoopSourceRef;" \ --raw-line "" \ - --raw-line "/// This is a temporary solution." \ - --raw-line "pub type dispatch_queue_t = *mut ::std::os::raw::c_void;" \ - -o $BINDING_PATH \ - $HEADER_PATH -- \ + --raw-line "use dispatch_queue_t;" \ + -o $DYNAMIC_STORE_BINDING_PATH \ + $DYNAMIC_STORE_HEADER_PATH -- \ + -I$SDK_PATH/usr/include \ + -F$FRAMEWORK_PATH + +rustfmt $DYNAMIC_STORE_BINDING_PATH + +echo "" +echo "" +echo "Generating bindings for $NETWORK_CONFIGURATION_HEADER_PATH" +sleep 2 + +bindgen \ + --no-doc-comments \ + --whitelist-function "SCNetwork.*" \ + --whitelist-function "SCBondInterface.*" \ + --whitelist-var "kSC(NetworkInterface|BondStatus).*" \ + --blacklist-type "dispatch_queue_[ts]" \ + --blacklist-type "(__)?CF.*" \ + --blacklist-type "__SC.*" \ + --blacklist-type "Boolean" \ + --blacklist-type "(sockaddr|socklen_t|sa_family_t|__darwin_socklen_t|__uint.*_t)" \ + --blacklist-type "(__)?SCPreferences.*" \ + --raw-line "// Generated using:" \ + --raw-line "// $BINDGEN_VERSION" \ + --raw-line "// macOS SDK $SDK_VERSION." \ + --raw-line "" \ + --raw-line "use core_foundation_sys::array::CFArrayRef;" \ + --raw-line "use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};" \ + --raw-line "use core_foundation_sys::string::CFStringRef;" \ + --raw-line "use core_foundation_sys::dictionary::CFDictionaryRef;" \ + --raw-line "use core_foundation_sys::runloop::CFRunLoopRef;" \ + --raw-line "" \ + --raw-line "use dispatch_queue_t;" \ + --raw-line "use libc::{c_void, c_char, c_int, sockaddr};" \ + --raw-line "use preferences::SCPreferencesRef;" \ + --raw-line "" \ + --raw-line "pub type __SCNetworkReachability = c_void;" \ + --raw-line "pub type __SCNetworkConnection = c_void;" \ + --raw-line "pub type __SCNetworkInterface = c_void;" \ + --raw-line "pub type __SCBondStatus = c_void;" \ + --raw-line "pub type __SCNetworkProtocol = c_void;" \ + --raw-line "pub type __SCNetworkService = c_void;" \ + --raw-line "pub type __SCNetworkSet = c_void;" \ + -o $NETWORK_CONFIGURATION_BINDING_PATH \ + $NETWORK_CONFIGURATION_HEADER_PATH -- \ -I$SDK_PATH/usr/include \ -F$FRAMEWORK_PATH -rustfmt $BINDING_PATH +rustfmt $NETWORK_CONFIGURATION_BINDING_PATH diff --git a/system-configuration-sys/Cargo.toml b/system-configuration-sys/Cargo.toml index 2730f5b..96a8020 100644 --- a/system-configuration-sys/Cargo.toml +++ b/system-configuration-sys/Cargo.toml @@ -10,3 +10,4 @@ license = "MIT/Apache-2.0" [dependencies] core-foundation-sys = "0.5" +libc = "0.2" diff --git a/system-configuration-sys/src/dynamic_store.rs b/system-configuration-sys/src/dynamic_store.rs index f077026..d1a0831 100644 --- a/system-configuration-sys/src/dynamic_store.rs +++ b/system-configuration-sys/src/dynamic_store.rs @@ -11,204 +11,38 @@ use core_foundation_sys::propertylist::CFPropertyListRef; use core_foundation_sys::runloop::CFRunLoopSourceRef; use core_foundation_sys::string::CFStringRef; -/// This is a temporary solution. -pub type dispatch_queue_t = *mut ::std::os::raw::c_void; +use dispatch_queue_t; +use libc::c_void; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __SCDynamicStore { - _unused: [u8; 0], -} -/// @typedef SCDynamicStoreRef -/// @discussion This is the handle to an open a dynamic store session -/// with the system configuration daemon. +pub type __SCDynamicStore = c_void; pub type SCDynamicStoreRef = *const __SCDynamicStore; -/// @typedef SCDynamicStoreContext -/// Structure containing user-specified data and callbacks for an -/// SCDynamicStore session. -/// @field version The version number of the structure type being passed -/// in as a parameter to the SCDynamicStore creation function. -/// This structure is version 0. -/// @field info A C pointer to a user-specified block of data. -/// @field retain The callback used to add a retain for the info field. -/// If this parameter is not a pointer to a function of the correct -/// prototype, the behavior is undefined. The value may be NULL. -/// @field release The calllback used to remove a retain previously added -/// for the info field. If this parameter is not a pointer to a -/// function of the correct prototype, the behavior is undefined. -/// The value may be NULL. -/// @field copyDescription The callback used to provide a description of -/// the info field. + #[repr(C)] pub struct SCDynamicStoreContext { pub version: CFIndex, - pub info: *mut ::std::os::raw::c_void, - pub retain: ::std::option::Option< - unsafe extern "C" fn(info: *const ::std::os::raw::c_void) -> *const ::std::os::raw::c_void, - >, - pub release: ::std::option::Option, - pub copyDescription: ::std::option::Option< - unsafe extern "C" fn(info: *const ::std::os::raw::c_void) -> CFStringRef, - >, -} -#[test] -fn bindgen_test_layout_SCDynamicStoreContext() { - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(SCDynamicStoreContext)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(SCDynamicStoreContext)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).version as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SCDynamicStoreContext), - "::", - stringify!(version) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).info as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(SCDynamicStoreContext), - "::", - stringify!(info) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).retain as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(SCDynamicStoreContext), - "::", - stringify!(retain) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).release as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(SCDynamicStoreContext), - "::", - stringify!(release) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).copyDescription as *const _ as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(SCDynamicStoreContext), - "::", - stringify!(copyDescription) - ) - ); + pub info: *mut c_void, + pub retain: Option *const c_void>, + pub release: Option, + pub copyDescription: Option CFStringRef>, } -/// @typedef SCDynamicStoreCallBack -/// @discussion Type of callback function used when notification of -/// changes to the dynamic store is delivered. -/// @param store The dynamic store session. -/// @param changedKeys The list of changed keys. -/// -/// The list includes any specific SCDynamicStore keys that -/// changed (add, update, remove, notify) since the last call -/// to SCDynamicStoreSetNotificationKeys or since the last -/// notification callback. The list also includes any specific -/// keys matching one of the pattern string(s) that changed. -/// -/// An empty list indicates that the SCDynamicStore server -/// restarted and that any assumptions based on prior content -/// of the SCDynamicStore should be disgarded. -/// -/// @param info A C pointer to a user-specified block of data. -pub type SCDynamicStoreCallBack = ::std::option::Option< - unsafe extern "C" fn( - store: SCDynamicStoreRef, - changedKeys: CFArrayRef, - info: *mut ::std::os::raw::c_void, - ), + +pub type SCDynamicStoreCallBack = Option< + unsafe extern "C" fn(store: SCDynamicStoreRef, changedKeys: CFArrayRef, info: *mut c_void), >; + +#[link(name = "SystemConfiguration", kind = "framework")] extern "C" { - /// @function SCDynamicStoreGetTypeID - /// @discussion Returns the type identifier of all SCDynamicStore instances. - #[link_name = "\u{1}_SCDynamicStoreGetTypeID"] + pub static mut kSCDynamicStoreUseSessionKeys: CFStringRef; + pub fn SCDynamicStoreGetTypeID() -> CFTypeID; -} -extern "C" { - /// @function SCDynamicStoreCreate - /// @discussion Creates a new session used to interact with the dynamic - /// store maintained by the System Configuration server. - /// @param allocator The CFAllocator that should be used to allocate - /// memory for the local dynamic store object. - /// This parameter may be NULL in which case the current - /// default CFAllocator is used. If this reference is not - /// a valid CFAllocator, the behavior is undefined. - /// @param name A string that describes the name of the calling - /// process or plug-in of the caller. - /// @param callout The function to be called when a watched value - /// in the dynamic store is changed. - /// A NULL value can be specified if no callouts are - /// desired. - /// @param context The SCDynamicStoreContext associated with the callout. - /// @result Returns a reference to the new SCDynamicStore session. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCreate"] + pub fn SCDynamicStoreCreate( allocator: CFAllocatorRef, name: CFStringRef, callout: SCDynamicStoreCallBack, context: *mut SCDynamicStoreContext, ) -> SCDynamicStoreRef; -} -extern "C" { - /// @function SCDynamicStoreCreateWithOptions - /// @discussion Creates a new session used to interact with the dynamic - /// store maintained by the System Configuration server. - /// @param allocator The CFAllocator that should be used to allocate - /// memory for the local dynamic store object. - /// This parameter may be NULL in which case the current - /// default CFAllocator is used. If this reference is not - /// a valid CFAllocator, the behavior is undefined. - /// @param name A string that describes the name of the calling - /// process or plug-in of the caller. - /// @param storeOptions A CFDictionary containing options for the - /// dynamic store session (such as whether all keys added or set - /// into the dynamic store should be per-session keys). - /// - /// Currently available options include: - /// - /// - /// - /// - /// - /// - /// - /// - ///
key - /// value - ///
kSCDynamicStoreUseSessionKeysCFBooleanRef
- /// - /// A NULL value can be specified if no options are desired. - /// @param callout The function to be called when a watched value - /// in the dynamic store is changed. - /// A NULL value can be specified if no callouts are - /// desired. - /// @param context The SCDynamicStoreContext associated with the callout. - /// @result Returns a reference to the new SCDynamicStore session. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCreateWithOptions"] + pub fn SCDynamicStoreCreateWithOptions( allocator: CFAllocatorRef, name: CFStringRef, @@ -216,215 +50,63 @@ extern "C" { callout: SCDynamicStoreCallBack, context: *mut SCDynamicStoreContext, ) -> SCDynamicStoreRef; -} -extern "C" { - #[link_name = "\u{1}_kSCDynamicStoreUseSessionKeys"] - pub static mut kSCDynamicStoreUseSessionKeys: CFStringRef; -} -extern "C" { - /// @function SCDynamicStoreCreateRunLoopSource - /// @discussion Creates a CFRunLoopSource object that can be added to the - /// application's run loop. All dynamic store notifications are - /// delivered using this run loop source. - /// @param allocator The CFAllocator that should be used to allocate - /// memory for this run loop source. - /// This parameter may be NULL in which case the current - /// default CFAllocator is used. If this reference is not - /// a valid CFAllocator, the behavior is undefined. - /// @param store A reference to the dynamic store session. - /// @param order On platforms which support it, for source versions - /// which support it, this parameter determines the order in - /// which the sources which are ready to be processed are - /// handled. A lower order number causes processing before - /// higher order number sources. It is inadvisable to depend - /// on the order number for any architectural or design aspect - /// of code. In the absence of any reason to do otherwise, - /// zero should be used. - /// @result A reference to the new CFRunLoopSource. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCreateRunLoopSource"] + pub fn SCDynamicStoreCreateRunLoopSource( allocator: CFAllocatorRef, store: SCDynamicStoreRef, order: CFIndex, ) -> CFRunLoopSourceRef; -} -extern "C" { - /// @function SCDynamicStoreSetDispatchQueue - /// @discussion Initiates notifications for the Notification - /// Keys in store to the callback contained in store. - /// @param store A reference to the dynamic store session. - /// @param queue The dispatch queue to run the callback function on. - /// Pass NULL to disable notifications, and release the queue. - /// @result Returns TRUE on success, FALSE on failure. - #[link_name = "\u{1}_SCDynamicStoreSetDispatchQueue"] + pub fn SCDynamicStoreSetDispatchQueue( store: SCDynamicStoreRef, queue: dispatch_queue_t, ) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreCopyKeyList - /// @discussion Returns an array of CFString keys representing the - /// current dynamic store entries that match a specified pattern. - /// @param store The dynamic store session. - /// @param pattern A regex(3) regular expression pattern - /// used to match the dynamic store keys. - /// @result Returns the list of matching keys; NULL if an error was - /// encountered. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCopyKeyList"] + pub fn SCDynamicStoreCopyKeyList(store: SCDynamicStoreRef, pattern: CFStringRef) -> CFArrayRef; -} -extern "C" { - /// @function SCDynamicStoreAddValue - /// @discussion Adds the key-value pair to the dynamic store if no - /// such key already exists. - /// @param store The dynamic store session. - /// @param key The key of the value to add to the dynamic store. - /// @param value The value to add to the dynamic store. - /// @result Returns TRUE if the key was added; FALSE if the key was already - /// present in the dynamic store or if an error was encountered. - #[link_name = "\u{1}_SCDynamicStoreAddValue"] + pub fn SCDynamicStoreAddValue( store: SCDynamicStoreRef, key: CFStringRef, value: CFPropertyListRef, ) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreAddTemporaryValue - /// @discussion Temporarily adds the key-value pair to the dynamic store - /// if no such key already exists. Unless the key is updated by another - /// session, the key-value pair will be removed automatically when the - /// session is closed. - /// @param store The dynamic store session. - /// @param key The key of the value to add to the dynamic store. - /// @param value The value to add to the dynamic store. - /// @result Returns TRUE if the key was added; FALSE if the key was already - /// present in the dynamic store or if an error was encountered. - #[link_name = "\u{1}_SCDynamicStoreAddTemporaryValue"] + pub fn SCDynamicStoreAddTemporaryValue( store: SCDynamicStoreRef, key: CFStringRef, value: CFPropertyListRef, ) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreCopyValue - /// @discussion Gets the value of the specified key from the dynamic store. - /// @param store The dynamic store session. - /// @param key The key associated with the value you want to get. - /// @result Returns the value from the dynamic store that is associated with the given - /// key; NULL if no value was located or an error was encountered. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCopyValue"] + pub fn SCDynamicStoreCopyValue(store: SCDynamicStoreRef, key: CFStringRef) -> CFPropertyListRef; -} -extern "C" { - /// @function SCDynamicStoreCopyMultiple - /// @discussion Gets the values of multiple keys in the dynamic store. - /// @param store The dynamic store session. - /// @param keys The keys associated with the values you want to get; NULL if no specific - /// keys are requested. - /// @param patterns An array of regex(3) pattern strings used to match the keys; NULL - /// if no key patterns are requested. - /// @result Returns a dictionary containing the key-value pairs of specific keys and the - /// key-value pairs of keys that matched the specified patterns; - /// NULL if an error was encountered. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCopyMultiple"] + pub fn SCDynamicStoreCopyMultiple( store: SCDynamicStoreRef, keys: CFArrayRef, patterns: CFArrayRef, ) -> CFDictionaryRef; -} -extern "C" { - /// @function SCDynamicStoreSetValue - /// @discussion Adds or replaces a value in the dynamic store for - /// the specified key. - /// @param store The dynamic store session. - /// @param key The key you want to set. - /// @param value The value to add to or replace in the dynamic store. - /// @result Returns TRUE if the key was updated; FALSE if an error was encountered. - #[link_name = "\u{1}_SCDynamicStoreSetValue"] + pub fn SCDynamicStoreSetValue( store: SCDynamicStoreRef, key: CFStringRef, value: CFPropertyListRef, ) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreSetMultiple - /// @discussion Updates multiple values in the dynamic store. - /// @param store The dynamic store session. - /// @param keysToSet A dictionary of key-value pairs you want to set into the dynamic store. - /// @param keysToRemove An array of keys you want to remove from the dynamic store. - /// @param keysToNotify An array of keys to flag as changed (without changing their values). - /// @result Returns TRUE if the dynamic store updates were successful; FALSE if an error was - /// encountered. - #[link_name = "\u{1}_SCDynamicStoreSetMultiple"] + pub fn SCDynamicStoreSetMultiple( store: SCDynamicStoreRef, keysToSet: CFDictionaryRef, keysToRemove: CFArrayRef, keysToNotify: CFArrayRef, ) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreRemoveValue - /// @discussion Removes the value of the specified key from the - /// dynamic store. - /// @param store The dynamic store session. - /// @param key The key of the value you want to remove. - /// @result Returns TRUE if the key was removed; FALSE if no value was - /// located or an error was encountered. - #[link_name = "\u{1}_SCDynamicStoreRemoveValue"] + pub fn SCDynamicStoreRemoveValue(store: SCDynamicStoreRef, key: CFStringRef) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreNotifyValue - /// @discussion Triggers a notification to be delivered for the - /// specified key in the dynamic store. - /// @param store The dynamic store session. - /// @param key The key that should be flagged as changed. Any dynamic store sessions - /// that are monitoring this key will received a notification. Note that the - /// key's value is not updated. - /// @result Returns TRUE if the notification was processed; FALSE if an error was encountered. - #[link_name = "\u{1}_SCDynamicStoreNotifyValue"] + pub fn SCDynamicStoreNotifyValue(store: SCDynamicStoreRef, key: CFStringRef) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreSetNotificationKeys - /// @discussion Specifies a set of specific keys and key patterns - /// that should be monitored for changes. - /// @param store The dynamic store session being watched. - /// @param keys An array of keys to be monitored; NULL if no specific keys - /// are to be monitored. - /// @param patterns An array of regex(3) pattern strings used to match keys to be monitored; - /// NULL if no key patterns are to be monitored. - /// @result Returns TRUE if the set of notification keys and patterns was successfully - /// updated; FALSE if an error was encountered. - #[link_name = "\u{1}_SCDynamicStoreSetNotificationKeys"] + pub fn SCDynamicStoreSetNotificationKeys( store: SCDynamicStoreRef, keys: CFArrayRef, patterns: CFArrayRef, ) -> Boolean; -} -extern "C" { - /// @function SCDynamicStoreCopyNotifiedKeys - /// @discussion Returns an array of CFString keys representing the - /// dynamic store entries that have changed since this - /// function was last called. If possible, your application should - /// use the notification functions instead of polling for the list - /// of changed keys returned by this function. - /// @param store The dynamic store session. - /// @result Returns the list of changed keys; - /// NULL if an error was encountered. - /// You must release the returned value. - #[link_name = "\u{1}_SCDynamicStoreCopyNotifiedKeys"] + pub fn SCDynamicStoreCopyNotifiedKeys(store: SCDynamicStoreRef) -> CFArrayRef; } diff --git a/system-configuration-sys/src/lib.rs b/system-configuration-sys/src/lib.rs index a9ccd3a..f50a6ba 100644 --- a/system-configuration-sys/src/lib.rs +++ b/system-configuration-sys/src/lib.rs @@ -12,10 +12,17 @@ //! [SystemConfiguration]: https://developer.apple.com/documentation/systemconfiguration?language=objc //! [`system-configuration`]: https://crates.io/crates/system-configuration +#![no_std] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] #![allow(non_snake_case)] -extern crate core_foundation_sys; +pub extern crate core_foundation_sys; +pub extern crate libc; + +/// This is a temporary solution. +pub type dispatch_queue_t = *mut libc::c_void; pub mod dynamic_store; +pub mod network_configuration; +pub mod preferences; diff --git a/system-configuration-sys/src/network_configuration.rs b/system-configuration-sys/src/network_configuration.rs new file mode 100644 index 0000000..8aa0191 --- /dev/null +++ b/system-configuration-sys/src/network_configuration.rs @@ -0,0 +1,421 @@ +// automatically generated by rust-bindgen + +// Generated using: +// bindgen 0.32.3 +// macOS SDK 10.13. + +use core_foundation_sys::array::CFArrayRef; +use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID}; +use core_foundation_sys::dictionary::CFDictionaryRef; +use core_foundation_sys::runloop::CFRunLoopRef; +use core_foundation_sys::string::CFStringRef; + +use dispatch_queue_t; +use libc::{c_char, c_int, c_void, sockaddr}; +use preferences::SCPreferencesRef; + +pub type __SCNetworkReachability = c_void; +pub type SCNetworkReachabilityRef = *const __SCNetworkReachability; + +pub type __SCNetworkConnection = c_void; +pub type SCNetworkConnectionRef = *const __SCNetworkConnection; + +pub type __SCNetworkInterface = c_void; +pub type SCNetworkInterfaceRef = *const __SCNetworkInterface; + +pub type SCBondInterfaceRef = SCNetworkInterfaceRef; +pub type __SCBondStatus = c_void; +pub type SCBondStatusRef = *const __SCBondStatus; + +pub type __SCNetworkProtocol = c_void; +pub type SCNetworkProtocolRef = *const __SCNetworkProtocol; + +pub type __SCNetworkService = c_void; +pub type SCNetworkServiceRef = *const __SCNetworkService; + +pub type __SCNetworkSet = c_void; +pub type SCNetworkSetRef = *const __SCNetworkSet; + +#[repr(C)] +pub struct SCNetworkReachabilityContext { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: Option *const c_void>, + pub release: Option, + pub copyDescription: Option CFStringRef>, +} + +pub type SCNetworkReachabilityFlags = u32; +pub type SCNetworkReachabilityCallBack = Option< + unsafe extern "C" fn( + target: SCNetworkReachabilityRef, + flags: SCNetworkReachabilityFlags, + info: *mut c_void, + ), +>; + +#[repr(C)] +pub struct SCNetworkConnectionContext { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: Option *const c_void>, + pub release: Option, + pub copyDescription: Option CFStringRef>, +} + +pub type SCNetworkConnectionStatus = i32; +pub type SCNetworkConnectionCallBack = Option< + unsafe extern "C" fn( + connection: SCNetworkConnectionRef, + status: SCNetworkConnectionStatus, + info: *mut c_void, + ), +>; + +pub const kSCBondStatusOK: u32 = 0; +pub const kSCBondStatusLinkInvalid: u32 = 1; +pub const kSCBondStatusNoPartner: u32 = 2; +pub const kSCBondStatusNotInActiveGroup: u32 = 3; +pub const kSCBondStatusUnknown: u32 = 999; + +#[link(name = "SystemConfiguration", kind = "framework")] +extern "C" { + pub static mut kSCNetworkInterfaceType6to4: CFStringRef; + pub static mut kSCNetworkInterfaceTypeBluetooth: CFStringRef; + pub static mut kSCNetworkInterfaceTypeBond: CFStringRef; + pub static mut kSCNetworkInterfaceTypeEthernet: CFStringRef; + pub static mut kSCNetworkInterfaceTypeFireWire: CFStringRef; + pub static mut kSCNetworkInterfaceTypeIEEE80211: CFStringRef; + pub static mut kSCNetworkInterfaceTypeIPSec: CFStringRef; + pub static mut kSCNetworkInterfaceTypeIrDA: CFStringRef; + pub static mut kSCNetworkInterfaceTypeL2TP: CFStringRef; + pub static mut kSCNetworkInterfaceTypeModem: CFStringRef; + pub static mut kSCNetworkInterfaceTypePPP: CFStringRef; + pub static mut kSCNetworkInterfaceTypePPTP: CFStringRef; + pub static mut kSCNetworkInterfaceTypeSerial: CFStringRef; + pub static mut kSCNetworkInterfaceTypeVLAN: CFStringRef; + pub static mut kSCNetworkInterfaceTypeWWAN: CFStringRef; + pub static mut kSCNetworkInterfaceTypeIPv4: CFStringRef; + pub static mut kSCNetworkInterfaceIPv4: SCNetworkInterfaceRef; + + pub static mut kSCBondStatusDeviceAggregationStatus: CFStringRef; + pub static mut kSCBondStatusDeviceCollecting: CFStringRef; + pub static mut kSCBondStatusDeviceDistributing: CFStringRef; + + pub fn SCNetworkReachabilityCreateWithAddress( + allocator: CFAllocatorRef, + address: *const sockaddr, + ) -> SCNetworkReachabilityRef; + + pub fn SCNetworkReachabilityCreateWithAddressPair( + allocator: CFAllocatorRef, + localAddress: *const sockaddr, + remoteAddress: *const sockaddr, + ) -> SCNetworkReachabilityRef; + + pub fn SCNetworkReachabilityCreateWithName( + allocator: CFAllocatorRef, + nodename: *const c_char, + ) -> SCNetworkReachabilityRef; + + pub fn SCNetworkReachabilityGetTypeID() -> CFTypeID; + + pub fn SCNetworkReachabilityGetFlags( + target: SCNetworkReachabilityRef, + flags: *mut SCNetworkReachabilityFlags, + ) -> Boolean; + + pub fn SCNetworkReachabilitySetCallback( + target: SCNetworkReachabilityRef, + callout: SCNetworkReachabilityCallBack, + context: *mut SCNetworkReachabilityContext, + ) -> Boolean; + + pub fn SCNetworkReachabilityScheduleWithRunLoop( + target: SCNetworkReachabilityRef, + runLoop: CFRunLoopRef, + runLoopMode: CFStringRef, + ) -> Boolean; + + pub fn SCNetworkReachabilityUnscheduleFromRunLoop( + target: SCNetworkReachabilityRef, + runLoop: CFRunLoopRef, + runLoopMode: CFStringRef, + ) -> Boolean; + + pub fn SCNetworkReachabilitySetDispatchQueue( + target: SCNetworkReachabilityRef, + queue: dispatch_queue_t, + ) -> Boolean; + + pub fn SCNetworkConnectionGetTypeID() -> CFTypeID; + + pub fn SCNetworkConnectionCopyUserPreferences( + selectionOptions: CFDictionaryRef, + serviceID: *mut CFStringRef, + userOptions: *mut CFDictionaryRef, + ) -> Boolean; + + pub fn SCNetworkConnectionCreateWithServiceID( + allocator: CFAllocatorRef, + serviceID: CFStringRef, + callout: SCNetworkConnectionCallBack, + context: *mut SCNetworkConnectionContext, + ) -> SCNetworkConnectionRef; + + pub fn SCNetworkConnectionCopyServiceID(connection: SCNetworkConnectionRef) -> CFStringRef; + + pub fn SCNetworkConnectionGetStatus( + connection: SCNetworkConnectionRef, + ) -> SCNetworkConnectionStatus; + + pub fn SCNetworkConnectionCopyExtendedStatus( + connection: SCNetworkConnectionRef, + ) -> CFDictionaryRef; + + pub fn SCNetworkConnectionCopyStatistics(connection: SCNetworkConnectionRef) + -> CFDictionaryRef; + + pub fn SCNetworkConnectionStart( + connection: SCNetworkConnectionRef, + userOptions: CFDictionaryRef, + linger: Boolean, + ) -> Boolean; + + pub fn SCNetworkConnectionStop( + connection: SCNetworkConnectionRef, + forceDisconnect: Boolean, + ) -> Boolean; + + pub fn SCNetworkConnectionCopyUserOptions( + connection: SCNetworkConnectionRef, + ) -> CFDictionaryRef; + + pub fn SCNetworkConnectionScheduleWithRunLoop( + connection: SCNetworkConnectionRef, + runLoop: CFRunLoopRef, + runLoopMode: CFStringRef, + ) -> Boolean; + + pub fn SCNetworkConnectionUnscheduleFromRunLoop( + connection: SCNetworkConnectionRef, + runLoop: CFRunLoopRef, + runLoopMode: CFStringRef, + ) -> Boolean; + + pub fn SCNetworkConnectionSetDispatchQueue( + connection: SCNetworkConnectionRef, + queue: dispatch_queue_t, + ) -> Boolean; + + pub fn SCNetworkInterfaceGetTypeID() -> CFTypeID; + + pub fn SCNetworkInterfaceCopyAll() -> CFArrayRef; + + pub fn SCNetworkInterfaceGetSupportedInterfaceTypes( + interface: SCNetworkInterfaceRef, + ) -> CFArrayRef; + + pub fn SCNetworkInterfaceGetSupportedProtocolTypes( + interface: SCNetworkInterfaceRef, + ) -> CFArrayRef; + + pub fn SCNetworkInterfaceCreateWithInterface( + interface: SCNetworkInterfaceRef, + interfaceType: CFStringRef, + ) -> SCNetworkInterfaceRef; + + pub fn SCNetworkInterfaceGetBSDName(interface: SCNetworkInterfaceRef) -> CFStringRef; + + pub fn SCNetworkInterfaceGetConfiguration(interface: SCNetworkInterfaceRef) -> CFDictionaryRef; + + pub fn SCNetworkInterfaceGetExtendedConfiguration( + interface: SCNetworkInterfaceRef, + extendedType: CFStringRef, + ) -> CFDictionaryRef; + + pub fn SCNetworkInterfaceGetHardwareAddressString( + interface: SCNetworkInterfaceRef, + ) -> CFStringRef; + + pub fn SCNetworkInterfaceGetInterface( + interface: SCNetworkInterfaceRef, + ) -> SCNetworkInterfaceRef; + + pub fn SCNetworkInterfaceGetInterfaceType(interface: SCNetworkInterfaceRef) -> CFStringRef; + + pub fn SCNetworkInterfaceGetLocalizedDisplayName( + interface: SCNetworkInterfaceRef, + ) -> CFStringRef; + + pub fn SCNetworkInterfaceSetConfiguration( + interface: SCNetworkInterfaceRef, + config: CFDictionaryRef, + ) -> Boolean; + + pub fn SCNetworkInterfaceSetExtendedConfiguration( + interface: SCNetworkInterfaceRef, + extendedType: CFStringRef, + config: CFDictionaryRef, + ) -> Boolean; + + pub fn SCNetworkInterfaceCopyMediaOptions( + interface: SCNetworkInterfaceRef, + current: *mut CFDictionaryRef, + active: *mut CFDictionaryRef, + available: *mut CFArrayRef, + filter: Boolean, + ) -> Boolean; + + pub fn SCNetworkInterfaceCopyMediaSubTypes(available: CFArrayRef) -> CFArrayRef; + + pub fn SCNetworkInterfaceCopyMediaSubTypeOptions( + available: CFArrayRef, + subType: CFStringRef, + ) -> CFArrayRef; + + pub fn SCNetworkInterfaceCopyMTU( + interface: SCNetworkInterfaceRef, + mtu_cur: *mut c_int, + mtu_min: *mut c_int, + mtu_max: *mut c_int, + ) -> Boolean; + + pub fn SCNetworkInterfaceSetMediaOptions( + interface: SCNetworkInterfaceRef, + subtype: CFStringRef, + options: CFArrayRef, + ) -> Boolean; + + pub fn SCNetworkInterfaceSetMTU(interface: SCNetworkInterfaceRef, mtu: c_int) -> Boolean; + + pub fn SCNetworkInterfaceForceConfigurationRefresh(interface: SCNetworkInterfaceRef) + -> Boolean; + + pub fn SCBondInterfaceCopyAll(prefs: SCPreferencesRef) -> CFArrayRef; + + pub fn SCBondInterfaceCopyAvailableMemberInterfaces(prefs: SCPreferencesRef) -> CFArrayRef; + + pub fn SCBondInterfaceCreate(prefs: SCPreferencesRef) -> SCBondInterfaceRef; + + pub fn SCBondInterfaceRemove(bond: SCBondInterfaceRef) -> Boolean; + + pub fn SCBondInterfaceGetMemberInterfaces(bond: SCBondInterfaceRef) -> CFArrayRef; + + pub fn SCBondInterfaceGetOptions(bond: SCBondInterfaceRef) -> CFDictionaryRef; + + pub fn SCBondInterfaceSetMemberInterfaces( + bond: SCBondInterfaceRef, + members: CFArrayRef, + ) -> Boolean; + + pub fn SCBondInterfaceSetLocalizedDisplayName( + bond: SCBondInterfaceRef, + newName: CFStringRef, + ) -> Boolean; + + pub fn SCBondInterfaceSetOptions( + bond: SCBondInterfaceRef, + newOptions: CFDictionaryRef, + ) -> Boolean; + + pub fn SCBondInterfaceCopyStatus(bond: SCBondInterfaceRef) -> SCBondStatusRef; + + pub fn SCNetworkProtocolGetTypeID() -> CFTypeID; + + pub fn SCNetworkProtocolGetConfiguration(protocol: SCNetworkProtocolRef) -> CFDictionaryRef; + + pub fn SCNetworkProtocolGetEnabled(protocol: SCNetworkProtocolRef) -> Boolean; + + pub fn SCNetworkProtocolGetProtocolType(protocol: SCNetworkProtocolRef) -> CFStringRef; + + pub fn SCNetworkProtocolSetConfiguration( + protocol: SCNetworkProtocolRef, + config: CFDictionaryRef, + ) -> Boolean; + + pub fn SCNetworkProtocolSetEnabled(protocol: SCNetworkProtocolRef, enabled: Boolean) + -> Boolean; + + pub fn SCNetworkServiceGetTypeID() -> CFTypeID; + + pub fn SCNetworkServiceAddProtocolType( + service: SCNetworkServiceRef, + protocolType: CFStringRef, + ) -> Boolean; + pub fn SCNetworkServiceCopyAll(prefs: SCPreferencesRef) -> CFArrayRef; + + pub fn SCNetworkServiceCopyProtocols(service: SCNetworkServiceRef) -> CFArrayRef; + + pub fn SCNetworkServiceCreate( + prefs: SCPreferencesRef, + interface: SCNetworkInterfaceRef, + ) -> SCNetworkServiceRef; + + pub fn SCNetworkServiceCopy( + prefs: SCPreferencesRef, + serviceID: CFStringRef, + ) -> SCNetworkServiceRef; + + pub fn SCNetworkServiceEstablishDefaultConfiguration(service: SCNetworkServiceRef) -> Boolean; + + pub fn SCNetworkServiceGetEnabled(service: SCNetworkServiceRef) -> Boolean; + + pub fn SCNetworkServiceGetInterface(service: SCNetworkServiceRef) -> SCNetworkInterfaceRef; + + pub fn SCNetworkServiceGetName(service: SCNetworkServiceRef) -> CFStringRef; + + pub fn SCNetworkServiceCopyProtocol( + service: SCNetworkServiceRef, + protocolType: CFStringRef, + ) -> SCNetworkProtocolRef; + + pub fn SCNetworkServiceGetServiceID(service: SCNetworkServiceRef) -> CFStringRef; + + pub fn SCNetworkServiceRemove(service: SCNetworkServiceRef) -> Boolean; + + pub fn SCNetworkServiceRemoveProtocolType( + service: SCNetworkServiceRef, + protocolType: CFStringRef, + ) -> Boolean; + + pub fn SCNetworkServiceSetEnabled(service: SCNetworkServiceRef, enabled: Boolean) -> Boolean; + + pub fn SCNetworkServiceSetName(service: SCNetworkServiceRef, name: CFStringRef) -> Boolean; + + pub fn SCNetworkSetGetTypeID() -> CFTypeID; + + pub fn SCNetworkSetAddService(set: SCNetworkSetRef, service: SCNetworkServiceRef) -> Boolean; + + pub fn SCNetworkSetContainsInterface( + set: SCNetworkSetRef, + interface: SCNetworkInterfaceRef, + ) -> Boolean; + + pub fn SCNetworkSetCopyAll(prefs: SCPreferencesRef) -> CFArrayRef; + + pub fn SCNetworkSetCopyCurrent(prefs: SCPreferencesRef) -> SCNetworkSetRef; + + pub fn SCNetworkSetCopyServices(set: SCNetworkSetRef) -> CFArrayRef; + + pub fn SCNetworkSetCreate(prefs: SCPreferencesRef) -> SCNetworkSetRef; + + pub fn SCNetworkSetCopy(prefs: SCPreferencesRef, setID: CFStringRef) -> SCNetworkSetRef; + + pub fn SCNetworkSetGetName(set: SCNetworkSetRef) -> CFStringRef; + + pub fn SCNetworkSetGetSetID(set: SCNetworkSetRef) -> CFStringRef; + + pub fn SCNetworkSetGetServiceOrder(set: SCNetworkSetRef) -> CFArrayRef; + + pub fn SCNetworkSetRemove(set: SCNetworkSetRef) -> Boolean; + + pub fn SCNetworkSetRemoveService(set: SCNetworkSetRef, service: SCNetworkServiceRef) + -> Boolean; + + pub fn SCNetworkSetSetCurrent(set: SCNetworkSetRef) -> Boolean; + + pub fn SCNetworkSetSetName(set: SCNetworkSetRef, name: CFStringRef) -> Boolean; + + pub fn SCNetworkSetSetServiceOrder(set: SCNetworkSetRef, newOrder: CFArrayRef) -> Boolean; +} diff --git a/system-configuration-sys/src/preferences.rs b/system-configuration-sys/src/preferences.rs new file mode 100644 index 0000000..20823d8 --- /dev/null +++ b/system-configuration-sys/src/preferences.rs @@ -0,0 +1,111 @@ +// automatically generated by rust-bindgen + +// Generated using: +// bindgen 0.32.3 +// macOS SDK 10.13. + +use core_foundation_sys::array::CFArrayRef; +use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID}; +use core_foundation_sys::data::CFDataRef; +use core_foundation_sys::propertylist::CFPropertyListRef; +use core_foundation_sys::runloop::CFRunLoopRef; +use core_foundation_sys::string::CFStringRef; + +use dispatch_queue_t; +use libc::c_void; + +pub type AuthorizationOpaqueRef = c_void; +pub type AuthorizationRef = *const AuthorizationOpaqueRef; + +pub type __SCPreferences = c_void; +pub type SCPreferencesRef = *const __SCPreferences; + +pub type SCPreferencesNotification = u32; + +#[repr(C)] +pub struct SCPreferencesContext { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: Option *const c_void>, + pub release: Option, + pub copyDescription: Option CFStringRef>, +} + +pub type SCPreferencesCallBack = Option< + unsafe extern "C" fn( + prefs: SCPreferencesRef, + notificationType: SCPreferencesNotification, + info: *mut c_void, + ), +>; + +#[link(name = "SystemConfiguration", kind = "framework")] +extern "C" { + pub fn SCPreferencesGetTypeID() -> CFTypeID; + + pub fn SCPreferencesCreate( + allocator: CFAllocatorRef, + name: CFStringRef, + prefsID: CFStringRef, + ) -> SCPreferencesRef; + + pub fn SCPreferencesCreateWithAuthorization( + allocator: CFAllocatorRef, + name: CFStringRef, + prefsID: CFStringRef, + authorization: AuthorizationRef, + ) -> SCPreferencesRef; + + pub fn SCPreferencesLock(prefs: SCPreferencesRef, wait: Boolean) -> Boolean; + + pub fn SCPreferencesCommitChanges(prefs: SCPreferencesRef) -> Boolean; + + pub fn SCPreferencesApplyChanges(prefs: SCPreferencesRef) -> Boolean; + + pub fn SCPreferencesUnlock(prefs: SCPreferencesRef) -> Boolean; + + pub fn SCPreferencesGetSignature(prefs: SCPreferencesRef) -> CFDataRef; + + pub fn SCPreferencesCopyKeyList(prefs: SCPreferencesRef) -> CFArrayRef; + + pub fn SCPreferencesGetValue(prefs: SCPreferencesRef, key: CFStringRef) -> CFPropertyListRef; + + pub fn SCPreferencesAddValue( + prefs: SCPreferencesRef, + key: CFStringRef, + value: CFPropertyListRef, + ) -> Boolean; + + pub fn SCPreferencesSetValue( + prefs: SCPreferencesRef, + key: CFStringRef, + value: CFPropertyListRef, + ) -> Boolean; + + pub fn SCPreferencesRemoveValue(prefs: SCPreferencesRef, key: CFStringRef) -> Boolean; + + pub fn SCPreferencesSetCallback( + prefs: SCPreferencesRef, + callout: SCPreferencesCallBack, + context: *mut SCPreferencesContext, + ) -> Boolean; + + pub fn SCPreferencesScheduleWithRunLoop( + prefs: SCPreferencesRef, + runLoop: CFRunLoopRef, + runLoopMode: CFStringRef, + ) -> Boolean; + + pub fn SCPreferencesUnscheduleFromRunLoop( + prefs: SCPreferencesRef, + runLoop: CFRunLoopRef, + runLoopMode: CFStringRef, + ) -> Boolean; + + pub fn SCPreferencesSetDispatchQueue( + prefs: SCPreferencesRef, + queue: dispatch_queue_t, + ) -> Boolean; + + pub fn SCPreferencesSynchronize(prefs: SCPreferencesRef); +} diff --git a/system-configuration/src/dynamic_store.rs b/system-configuration/src/dynamic_store.rs index a1e626d..c5e87c6 100644 --- a/system-configuration/src/dynamic_store.rs +++ b/system-configuration/src/dynamic_store.rs @@ -21,8 +21,8 @@ use core_foundation::runloop::CFRunLoopSource; use core_foundation::string::CFString; pub use system_configuration_sys::dynamic_store::*; +use system_configuration_sys::libc::c_void; -use std::os::raw::c_void; use std::ptr; /// Struct describing the callback happening when a watched value in the dynamic store is changed.