2 * Copyright (c) 2000, 2001, 2003-2005, 2007 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
->st_mtimespec
= statBuf
->st_mtimespec
;
56 sig
->st_size
= statBuf
->st_size
;
61 __private_extern__
char *
62 __SCPreferencesPath(CFAllocatorRef allocator
,
66 CFStringRef path
= NULL
;
69 if (prefsID
== NULL
) {
70 /* default preference ID */
71 path
= CFStringCreateWithFormat(allocator
,
74 useNewPrefs
? PREFS_DEFAULT_DIR
: PREFS_DEFAULT_DIR_OLD
,
75 useNewPrefs
? PREFS_DEFAULT_CONFIG
: PREFS_DEFAULT_CONFIG_OLD
);
76 } else if (CFStringHasPrefix(prefsID
, CFSTR("/"))) {
77 /* if absolute path */
78 path
= CFStringCreateCopy(allocator
, prefsID
);
81 path
= CFStringCreateWithFormat(allocator
,
84 useNewPrefs
? PREFS_DEFAULT_DIR
: PREFS_DEFAULT_DIR_OLD
,
86 if (useNewPrefs
&& CFStringHasSuffix(path
, CFSTR(".xml"))) {
87 CFMutableStringRef newPath
;
89 newPath
= CFStringCreateMutableCopy(allocator
, 0, path
);
90 CFStringReplace(newPath
,
91 CFRangeMake(CFStringGetLength(newPath
)-4, 4),
99 * convert CFStringRef path to C-string path
101 pathStr
= _SC_cfstring_to_cstring(path
, NULL
, 0, kCFStringEncodingASCII
);
102 if (pathStr
== NULL
) {
103 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("could not convert path to C string"));
112 SCPreferencesGetSignature(SCPreferencesRef prefs
)
114 SCPreferencesPrivateRef prefsPrivate
= (SCPreferencesPrivateRef
)prefs
;
117 /* sorry, you must provide a session */
118 _SCErrorSet(kSCStatusNoPrefsSession
);
122 __SCPreferencesAccess(prefs
);
124 return prefsPrivate
->signature
;
128 __private_extern__ CFStringRef
129 _SCPNotificationKey(CFAllocatorRef allocator
,
136 CFStringRef storeKey
;
139 case kSCPreferencesKeyCommit
:
140 keyStr
= CFSTR("commit");
142 case kSCPreferencesKeyApply
:
143 keyStr
= CFSTR("apply");
149 path
= __SCPreferencesPath(allocator
, prefsID
, TRUE
);
154 pathStr
= CFStringCreateWithCStringNoCopy(allocator
,
156 kCFStringEncodingASCII
,
159 storeKey
= CFStringCreateWithFormat(allocator
,
162 kSCDynamicStoreDomainPrefs
,
167 CFAllocatorDeallocate(NULL
, path
);
173 SCDynamicStoreKeyCreatePreferences(CFAllocatorRef allocator
,
175 SCPreferencesKeyType keyType
)
177 return _SCPNotificationKey(allocator
, prefsID
, keyType
);