2  * Copyright (c) 2000, 2001, 2004, 2005, 2007-2010, 2015 Apple Inc. All rights reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  24 #ifndef _SCPREFERENCES_H 
  25 #ifdef  USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS 
  26 #include <SystemConfiguration/_SCPreferences.h> 
  27 #else   /* USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS */ 
  28 #define _SCPREFERENCES_H 
  30 #include <Availability.h> 
  31 #include <TargetConditionals.h> 
  32 #include <sys/cdefs.h> 
  33 #include <dispatch/dispatch.h> 
  34 #include <CoreFoundation/CoreFoundation.h> 
  35 #include <SystemConfiguration/SCDynamicStore.h> 
  38 #include <Security/Security.h> 
  39 #else   // !TARGET_OS_IPHONE 
  40 typedef const struct AuthorizationOpaqueRef 
*   AuthorizationRef
; 
  41 #endif  // !TARGET_OS_IPHONE 
  43 CF_IMPLICIT_BRIDGING_ENABLED
 
  44 CF_ASSUME_NONNULL_BEGIN
 
  48         @discussion The SCPreferences API allows an application to load and 
  49                 store XML configuration data in a controlled manner and provide 
  50                 the necessary notifications to other applications that need to 
  51                 be aware of configuration changes. 
  53                 To access configuration preferences, you must first establish a 
  54                 preferences session using the SCPreferencesCreate function. 
  55                 To identify a specific set of preferences to access, you pass a 
  56                 value in the prefsID parameter. 
  57                 A NULL value indicates that the default system preferences are 
  59                 A string that starts with a leading "/" character specifies 
  60                 the absolute path to the file containing the preferences to 
  62                 A string that does not start with a leading "/" character 
  63                 specifies a file relative to the default system preferences 
  66                 When you are finished with the preferences session, use 
  67                 CFRelease to close it. 
  72         @typedef SCPreferencesRef 
  73         @discussion This is the handle to an open preferences session for 
  74                 accessing system configuration preferences. 
  76 typedef const struct CF_BRIDGED_TYPE(id
) __SCPreferences 
*      SCPreferencesRef
; 
  79         @enum SCPreferencesNotification 
  80         @discussion Used with the SCPreferencesCallBack callback 
  81                 to describe the type of notification. 
  82         @constant kSCPreferencesNotificationCommit Indicates when new 
  83                 preferences have been saved. 
  84         @constant kSCPreferencesNotificationApply Key Indicates when a 
  85                 request has been made to apply the currently saved 
  86                 preferences to the active system configuration. 
  88 typedef CF_OPTIONS(uint32_t, SCPreferencesNotification
) { 
  89         kSCPreferencesNotificationCommit        
= 1<<0, // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_2_0/*SPI*/) 
  90         kSCPreferencesNotificationApply         
= 1<<1  // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_2_0/*SPI*/) 
  94         @typedef SCPreferencesContext 
  95         Structure containing user-specified data and callbacks for SCPreferences. 
  96         @field version The version number of the structure type being passed 
  97                 in as a parameter to the SCPreferencesSetCallback function. 
  98                 This structure is version 0. 
  99         @field info A C pointer to a user-specified block of data. 
 100         @field retain The callback used to add a retain for the info field. 
 101                 If this parameter is not a pointer to a function of the correct 
 102                 prototype, the behavior is undefined. 
 103                 The value may be NULL. 
 104         @field release The calllback used to remove a retain previously added 
 106                 If this parameter is not a pointer to a function of the 
 107                 correct prototype, the behavior is undefined. 
 108                 The value may be NULL. 
 109         @field copyDescription The callback used to provide a description of 
 114         void *          __nullable info
; 
 115         const void      * __nonnull (* __nullable retain
)(const void *info
); 
 116         void            (* __nullable release
)(const void *info
); 
 117         CFStringRef     
__nonnull (* __nullable copyDescription
)(const void *info
); 
 118 } SCPreferencesContext
; 
 121         @typedef SCPreferencesCallBack 
 122         @discussion Type of the callback function used when the 
 123                 preferences have been updated and/or applied. 
 124         @param prefs The preferences session. 
 125         @param notificationType The type of notification, such as changes 
 126                 committed, changes applied, etc. 
 127         @param info A C pointer to a user-specified block of data. 
 129 typedef void (*SCPreferencesCallBack
)   ( 
 130                                         SCPreferencesRef                                prefs
, 
 131                                         SCPreferencesNotification                       notificationType
, 
 132                                         void                         *  __nullable      info
 
 139         @function SCPreferencesGetTypeID 
 140         @discussion Returns the type identifier of all SCPreferences instances. 
 143 SCPreferencesGetTypeID                  (void)                  __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 146         @function SCPreferencesCreate 
 147         @discussion Initiates access to the per-system set of configuration 
 149         @param allocator The CFAllocator that should be used to allocate 
 150                 memory for this preferences session. 
 151                 This parameter may be NULL in which case the current 
 152                 default CFAllocator is used. 
 153                 If this reference is not a valid CFAllocator, the behavior 
 155         @param name A string that describes the name of the calling 
 157         @param prefsID A string that identifies the name of the 
 158                 group of preferences to be accessed or updated. 
 159         @result Returns a reference to the new SCPreferences. 
 160                 You must release the returned value. 
 162 SCPreferencesRef __nullable
 
 163 SCPreferencesCreate                     ( 
 164                                         CFAllocatorRef          __nullable      allocator
, 
 166                                         CFStringRef             __nullable      prefsID
 
 167                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 171         @function SCPreferencesCreateWithAuthorization 
 172         @discussion Initiates access to the per-system set of configuration 
 174         @param allocator The CFAllocator that should be used to allocate 
 175                 memory for this preferences session. 
 176                 This parameter may be NULL in which case the current 
 177                 default CFAllocator is used. 
 178                 If this reference is not a valid CFAllocator, the behavior 
 180         @param name A string that describes the name of the calling 
 182         @param prefsID A string that identifies the name of the 
 183                 group of preferences to be accessed or updated. 
 184         @param authorization An authorization reference that is used to 
 185                 authorize any access to the enhanced privileges needed 
 186                 to manage the preferences session. 
 187         @result Returns a reference to the new SCPreferences. 
 188                 You must release the returned value. 
 190 SCPreferencesRef __nullable
 
 191 SCPreferencesCreateWithAuthorization    ( 
 192                                         CFAllocatorRef          __nullable      allocator
, 
 194                                         CFStringRef             __nullable      prefsID
, 
 195                                         AuthorizationRef        __nullable      authorization
 
 196                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_5
,__IPHONE_2_0
/*SPI*/); 
 199         @function SCPreferencesLock 
 200         @discussion Locks access to the configuration preferences. 
 202                 This function obtains exclusive access to the configuration 
 203                 preferences.  Clients attempting to obtain exclusive access 
 204                 to the preferences will either receive a kSCStatusPrefsBusy 
 205                 error or block waiting for the lock to be released. 
 206         @param prefs The preferences session. 
 207         @param wait A boolean flag indicating whether the calling process 
 208                 should block waiting for another process to complete its update 
 209                 operation and release its lock. 
 210         @result Returns TRUE if the lock was obtained; 
 211                 FALSE if an error occurred. 
 215                                         SCPreferencesRef        prefs
, 
 217                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 220         @function SCPreferencesCommitChanges 
 221         @discussion Commits changes made to the configuration preferences to 
 224                 This function commits any changes to permanent storage. 
 225                 Implicit calls to the SCPreferencesLock and SCPreferencesUnlock 
 226                 functions will be made if exclusive access has not already been 
 229                 Note: This routine commits changes to persistent storage. 
 230                 Call the SCPreferencesApplyChanges function to apply the 
 231                 changes to the running system. 
 232         @param prefs The preferences session. 
 233         @result Returns TRUE if the lock was obtained; 
 234                 FALSE if an error occurred. 
 237 SCPreferencesCommitChanges              ( 
 238                                         SCPreferencesRef        prefs
 
 239                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 242         @function SCPreferencesApplyChanges 
 243         @discussion Requests that the currently stored configuration 
 244                 preferences be applied to the active configuration. 
 245         @param prefs The preferences session. 
 246         @result Returns TRUE if the lock was obtained; 
 247                 FALSE if an error occurred. 
 250 SCPreferencesApplyChanges               ( 
 251                                         SCPreferencesRef        prefs
 
 252                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 255         @function SCPreferencesUnlock 
 256         @discussion Releases exclusive access to the configuration preferences. 
 258                 This function releases the exclusive access lock to the 
 259                 preferences.  Other clients will be now be able to establish 
 260                 exclusive access to the preferences. 
 261         @param prefs The preferences session. 
 262         @result Returns TRUE if the lock was obtained; 
 263                 FALSE if an error occurred. 
 266 SCPreferencesUnlock                     ( 
 267                                         SCPreferencesRef        prefs
 
 268                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 271         @function SCPreferencesGetSignature 
 272         @discussion Returns a sequence of bytes that can be used to determine 
 273                 if the saved configuration preferences have changed. 
 274         @param prefs The preferences session. 
 275         @result Returns a CFDataRef that reflects the signature of the configuration 
 276                 preferences at the time of the call to the SCPreferencesCreate function. 
 279 SCPreferencesGetSignature               ( 
 280                                         SCPreferencesRef        prefs
 
 281                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 284         @function SCPreferencesCopyKeyList 
 285         @discussion Returns an array of currently defined preference keys. 
 286         @param prefs The preferences session. 
 287         @result Returns the list of keys. 
 288                 You must release the returned value. 
 290 CFArrayRef __nullable
 
 291 SCPreferencesCopyKeyList                ( 
 292                                         SCPreferencesRef        prefs
 
 293                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 296         @function SCPreferencesGetValue 
 297         @discussion Returns the data associated with a preference key. 
 299                 This function retrieves data associated with the specified 
 302                 Note: To avoid inadvertantly reading stale data, first call 
 303                 the SCPreferencesLock function. 
 304         @param prefs The preferences session. 
 305         @param key The preference key to be returned. 
 306         @result Returns the value associated with the specified preference key; 
 307                 NULL if no value was located. 
 309 CFPropertyListRef __nullable
 
 310 SCPreferencesGetValue                   ( 
 311                                         SCPreferencesRef        prefs
, 
 313                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 316         @function SCPreferencesAddValue 
 317         @discussion Adds data for a preference key. 
 319                 This function associates new data with the specified key. 
 320                 To commit these changes to permanent storage, a call must 
 321                 be made to the SCPreferencesCommitChanges function. 
 322         @param prefs The preferences session. 
 323         @param key The preference key to be updated. 
 324         @param value The CFPropertyListRef object containing the 
 325                 value to be associated with the specified preference key. 
 326         @result Returns TRUE if the value was added; 
 327                 FALSE if the key already exists or 
 328                 if an error occurred. 
 331 SCPreferencesAddValue                   ( 
 332                                         SCPreferencesRef        prefs
, 
 334                                         CFPropertyListRef       value
 
 335                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 338         @function SCPreferencesSetValue 
 339         @discussion Updates the data associated with a preference key. 
 341                 This function adds or replaces the value associated with the 
 342                 specified key.  To commit these changes to permanent storage 
 343                 a call must be made to the SCPreferencesCommitChanges function. 
 344         @param prefs The preferences session. 
 345         @param key The preference key to be updated. 
 346         @param value The CFPropertyListRef object containing the 
 347                 data to be associated with the specified preference key. 
 348         @result Returns TRUE if the value was set; 
 349                 FALSE if an error occurred. 
 352 SCPreferencesSetValue                   ( 
 353                                         SCPreferencesRef        prefs
, 
 355                                         CFPropertyListRef       value
 
 356                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 359         @function SCPreferencesRemoveValue 
 360         @discussion Removes the data associated with a preference key. 
 362                 This function removes the data associated with the specified 
 363                 key.  To commit these changes to permanent storage a call must 
 364                 be made to the SCPreferencesCommitChanges function. 
 365         @param prefs The preferences session. 
 366         @param key The preference key to be removed. 
 367         @result Returns TRUE if the value was removed; 
 368                 FALSE if the key did not exist or if an error occurred. 
 371 SCPreferencesRemoveValue                ( 
 372                                         SCPreferencesRef        prefs
, 
 374                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_1
,__IPHONE_2_0
/*SPI*/); 
 377         @function SCPreferencesSetCallback 
 378         @discussion Assigns a callback to a preferences session.  The function 
 379                 is called when the changes to the preferences have been 
 380                 committed or applied. 
 381         @param prefs The preferences session. 
 382         @param callout The function to be called when the preferences have 
 383                 been changed or applied. 
 384                 If NULL, the current callback is removed. 
 385         @param context The SCPreferencesContext associated with 
 387         @result Returns TRUE if the notification client was successfully set. 
 390 SCPreferencesSetCallback                ( 
 391                                         SCPreferencesRef                        prefs
, 
 392                                         SCPreferencesCallBack   __nullable      callout
, 
 393                                         SCPreferencesContext    
* __nullable    context
 
 394                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_4
,__IPHONE_2_0
/*SPI*/); 
 397         @function SCPreferencesScheduleWithRunLoop 
 398         @discussion Schedule commit and apply notifications for the specified 
 399                 preferences session using the specified run loop and mode. 
 400         @param prefs The preferences session. 
 401         @param runLoop A reference to a run loop on which the notification 
 404         @param runLoopMode The mode on which to schedule the notification. 
 406         @result Returns TRUE if the notifications are successfully scheduled; 
 410 SCPreferencesScheduleWithRunLoop        ( 
 411                                         SCPreferencesRef        prefs
, 
 412                                         CFRunLoopRef            runLoop
, 
 413                                         CFStringRef             runLoopMode
 
 414                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_4
,__IPHONE_2_0
/*SPI*/); 
 417         @function SCPreferencesUnscheduleFromRunLoop 
 418         @discussion Unschedule commit and apply notifications for the specified 
 419                 preferences session from the specified run loop and mode. 
 420         @param prefs The preferences session. 
 421         @param runLoop A reference to a run loop from which the notification 
 422                 should be unscheduled. 
 424         @param runLoopMode The mode on which to unschedule the notification. 
 426         @result Returns TRUE if the notifications are successfully unscheduled; 
 430 SCPreferencesUnscheduleFromRunLoop      ( 
 431                                         SCPreferencesRef        prefs
, 
 432                                         CFRunLoopRef            runLoop
, 
 433                                         CFStringRef             runLoopMode
 
 434                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_4
,__IPHONE_2_0
/*SPI*/); 
 437         @function SCPreferencesSetDispatchQueue 
 438         @discussion Schedule commit and apply notifications for the specified 
 440         @param prefs The preferences session. 
 441         @param queue The dispatch queue to run the callback function on. 
 442         @result Returns TRUE if the notifications are successfully scheduled; 
 446 SCPreferencesSetDispatchQueue           ( 
 447                                          SCPreferencesRef                       prefs
, 
 448                                          dispatch_queue_t       __nullable      queue
 
 449                                          )                      __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
/*SPI*/); 
 452         @function SCPreferencesSynchronize 
 453         @discussion Synchronizes accessed preferences with committed changes. 
 455                 Any references to preference values returned by calls to the 
 456                 SCPreferencesGetValue function are no longer valid unless they 
 457                 were explicitly retained or copied.  Any preference values 
 458                 that were updated (add, set, remove) but not committed will 
 460         @param prefs The preferences session. 
 463 SCPreferencesSynchronize                ( 
 464                                         SCPreferencesRef        prefs
 
 465                                         )                       __OSX_AVAILABLE_STARTING(__MAC_10_4
,__IPHONE_2_0
/*SPI*/); 
 469 CF_ASSUME_NONNULL_END
 
 470 CF_IMPLICIT_BRIDGING_DISABLED
 
 472 #endif  /* USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS */ 
 473 #endif /* _SCPREFERENCES_H */