2 * Copyright (c) 2000, 2001, 2003-2005, 2007-2009 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@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * November 9, 2000 Allan Nathanson <ajn@apple.com>
34 #include <SystemConfiguration/SystemConfiguration.h>
35 #include <SystemConfiguration/SCPrivate.h>
36 #include "SCPreferencesInternal.h"
41 #include <sys/errno.h>
42 #include <sys/param.h>
44 __private_extern__ CFDataRef
45 __SCPSignatureFromStatbuf(const struct stat
*statBuf
)
47 CFMutableDataRef signature
;
48 SCPSignatureDataRef sig
;
50 signature
= CFDataCreateMutable(NULL
, sizeof(SCPSignatureData
));
51 CFDataSetLength(signature
, sizeof(SCPSignatureData
));
52 sig
= (SCPSignatureDataRef
)CFDataGetBytePtr(signature
);
53 sig
->st_dev
= statBuf
->st_dev
;
54 sig
->st_ino
= statBuf
->st_ino
;
55 sig
->tv_sec
= statBuf
->st_mtimespec
.tv_sec
;
56 sig
->tv_nsec
= statBuf
->st_mtimespec
.tv_nsec
;
57 sig
->st_size
= statBuf
->st_size
;
62 __private_extern__
char *
63 __SCPreferencesPath(CFAllocatorRef allocator
,
67 CFStringRef path
= NULL
;
70 if (prefsID
== NULL
) {
71 /* default preference ID */
72 path
= CFStringCreateWithFormat(allocator
,
75 useNewPrefs
? PREFS_DEFAULT_DIR
: PREFS_DEFAULT_DIR_OLD
,
76 useNewPrefs
? PREFS_DEFAULT_CONFIG
: PREFS_DEFAULT_CONFIG_OLD
);
77 } else if (CFStringHasPrefix(prefsID
, CFSTR("/"))) {
78 /* if absolute path */
79 path
= CFStringCreateCopy(allocator
, prefsID
);
82 path
= CFStringCreateWithFormat(allocator
,
85 useNewPrefs
? PREFS_DEFAULT_DIR
: PREFS_DEFAULT_DIR_OLD
,
87 if (useNewPrefs
&& CFStringHasSuffix(path
, CFSTR(".xml"))) {
88 CFMutableStringRef newPath
;
90 newPath
= CFStringCreateMutableCopy(allocator
, 0, path
);
91 CFStringReplace(newPath
,
92 CFRangeMake(CFStringGetLength(newPath
)-4, 4),
100 * convert CFStringRef path to C-string path
102 pathStr
= _SC_cfstring_to_cstring(path
, NULL
, 0, kCFStringEncodingASCII
);
103 if (pathStr
== NULL
) {
104 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("could not convert path to C string"));
113 SCPreferencesGetSignature(SCPreferencesRef prefs
)
115 SCPreferencesPrivateRef prefsPrivate
= (SCPreferencesPrivateRef
)prefs
;
118 /* sorry, you must provide a session */
119 _SCErrorSet(kSCStatusNoPrefsSession
);
123 __SCPreferencesAccess(prefs
);
125 return prefsPrivate
->signature
;
129 __private_extern__ CFStringRef
130 _SCPNotificationKey(CFAllocatorRef allocator
,
137 CFStringRef storeKey
;
140 case kSCPreferencesKeyLock
:
141 keyStr
= CFSTR("lock");
143 case kSCPreferencesKeyCommit
:
144 keyStr
= CFSTR("commit");
146 case kSCPreferencesKeyApply
:
147 keyStr
= CFSTR("apply");
153 path
= __SCPreferencesPath(allocator
, prefsID
, TRUE
);
158 pathStr
= CFStringCreateWithCStringNoCopy(allocator
,
160 kCFStringEncodingASCII
,
163 storeKey
= CFStringCreateWithFormat(allocator
,
166 kSCDynamicStoreDomainPrefs
,
171 CFAllocatorDeallocate(NULL
, path
);
177 SCDynamicStoreKeyCreatePreferences(CFAllocatorRef allocator
,
179 SCPreferencesKeyType keyType
)
181 return _SCPNotificationKey(allocator
, prefsID
, keyType
);