2 * Copyright (c) 2008 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 Copyright (c) 1998-2007, Apple Inc. All rights reserved.
28 APPLE SPI: NOT TO BE USED OUTSIDE APPLE!
31 #if !defined(__COREFOUNDATION_CFPRIV__)
32 #define __COREFOUNDATION_CFPRIV__ 1
35 #include <CoreFoundation/CFBase.h>
36 #include <CoreFoundation/CFArray.h>
37 #include <CoreFoundation/CFString.h>
38 #include <CoreFoundation/CFURL.h>
39 #include <CoreFoundation/CFBundlePriv.h>
43 #include <CoreFoundation/CFMachPort.h>
46 #if defined(__MACH__) || defined(__WIN32__)
47 #include <CoreFoundation/CFRunLoop.h>
48 #include <CoreFoundation/CFSocket.h>
52 #include <CoreFoundation/CFMachPort.h>
61 CF_EXPORT
intptr_t _CFDoOperation(intptr_t code
, intptr_t subcode1
, intptr_t subcode2
);
63 CF_EXPORT
void _CFRuntimeSetCFMPresent(void *a
);
65 CF_EXPORT
const char *_CFProcessPath(void);
66 CF_EXPORT
const char **_CFGetProcessPath(void);
67 CF_EXPORT
const char **_CFGetProgname(void);
71 CF_EXPORT CFRunLoopRef
CFRunLoopGetMain(void);
72 CF_EXPORT SInt32
CFRunLoopRunSpecific(CFRunLoopRef rl
, CFStringRef modeName
, CFTimeInterval seconds
, Boolean returnAfterSourceHandled
);
74 CF_EXPORT
void _CFRunLoopSetCurrent(CFRunLoopRef rl
);
76 CF_EXPORT Boolean
_CFRunLoopModeContainsMode(CFRunLoopRef rl
, CFStringRef modeName
, CFStringRef candidateContainedName
);
77 CF_EXPORT
void _CFRunLoopAddModeToMode(CFRunLoopRef rl
, CFStringRef modeName
, CFStringRef toModeName
);
78 CF_EXPORT
void _CFRunLoopRemoveModeFromMode(CFRunLoopRef rl
, CFStringRef modeName
, CFStringRef fromModeName
);
79 CF_EXPORT
void _CFRunLoopStopMode(CFRunLoopRef rl
, CFStringRef modeName
);
82 CF_EXPORT CFIndex
CFMachPortGetQueuedMessageCount(CFMachPortRef mp
);
85 CF_EXPORT CFPropertyListRef
_CFURLCopyPropertyListRepresentation(CFURLRef url
);
86 CF_EXPORT CFURLRef
_CFURLCreateFromPropertyListRepresentation(CFAllocatorRef alloc
, CFPropertyListRef pListRepresentation
);
88 CF_EXPORT CFPropertyListRef
_CFURLCopyPropertyListRepresentation(CFURLRef url
);
89 CF_EXPORT CFURLRef
_CFURLCreateFromPropertyListRepresentation(CFAllocatorRef alloc
, CFPropertyListRef pListRepresentation
);
91 CF_EXPORT
void CFPreferencesFlushCaches(void);
94 #if !defined(__WIN32__)
97 Boolean
_CFGetFSSpecFromURL(CFAllocatorRef alloc
, CFURLRef url
, struct FSSpec
*spec
);
100 CFURLRef
_CFCreateURLFromFSSpec(CFAllocatorRef alloc
, const struct FSSpec
*voidspec
, Boolean isDirectory
);
104 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
106 kCFURLComponentDecompositionNonHierarchical
,
107 kCFURLComponentDecompositionRFC1808
, /* use this for RFC 1738 decompositions as well */
108 kCFURLComponentDecompositionRFC2396
110 typedef CFIndex CFURLComponentDecomposition
;
114 CFStringRef schemeSpecific
;
115 } CFURLComponentsNonHierarchical
;
120 CFStringRef password
;
122 CFIndex port
; /* kCFNotFound means ignore/omit */
123 CFArrayRef pathComponents
;
124 CFStringRef parameterString
;
126 CFStringRef fragment
;
128 } CFURLComponentsRFC1808
;
133 /* if the registered name form of the net location is used, userinfo is NULL, port is kCFNotFound, and host is the entire registered name. */
134 CFStringRef userinfo
;
138 CFArrayRef pathComponents
;
140 CFStringRef fragment
;
142 } CFURLComponentsRFC2396
;
144 /* Fills components and returns TRUE if the URL can be decomposed according to decompositionType; FALSE (leaving components unchanged) otherwise. components should be a pointer to the CFURLComponents struct defined above that matches decompositionStyle */
146 Boolean
_CFURLCopyComponents(CFURLRef url
, CFURLComponentDecomposition decompositionType
, void *components
);
148 /* Creates and returns the URL described by components; components should point to the CFURLComponents struct defined above that matches decompositionType. */
150 CFURLRef
_CFURLCreateFromComponents(CFAllocatorRef alloc
, CFURLComponentDecomposition decompositionType
, const void *components
);
151 #define CFURLCopyComponents _CFURLCopyComponents
152 #define CFURLCreateFromComponents _CFURLCreateFromComponents
156 CF_EXPORT Boolean
_CFStringGetFileSystemRepresentation(CFStringRef string
, UInt8
*buffer
, CFIndex maxBufLen
);
158 /* If this is publicized, we might need to create a GetBytesPtr type function as well. */
159 CF_EXPORT CFStringRef
_CFStringCreateWithBytesNoCopy(CFAllocatorRef alloc
, const UInt8
*bytes
, CFIndex numBytes
, CFStringEncoding encoding
, Boolean externalFormat
, CFAllocatorRef contentsDeallocator
);
161 /* These return NULL on MacOS 8 */
163 CFStringRef
CFGetUserName(void);
166 CFURLRef
CFCopyHomeDirectoryURLForUser(CFStringRef uName
); /* Pass NULL for the current user's home directory */
169 /* Extra user notification key for iPhone */
171 const CFStringRef kCFUserNotificationKeyboardTypesKey AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
;
175 CFCopySearchPathForDirectoriesInDomains returns the various
176 standard system directories where apps, resources, etc get
177 installed. Because queries can return multiple directories,
178 you get back a CFArray (which you should free when done) of
179 CFStrings. The directories are returned in search path order;
180 that is, the first place to look is returned first. This API
181 may return directories that do not exist yet. If NSUserDomain
182 is included in a query, then the results will contain "~" to
183 refer to the user's directory. Specify expandTilde to expand
184 this to the current user's home. Some calls might return no
186 ??? On MacOS 8 this function currently returns an empty array.
189 kCFApplicationDirectory
= 1, /* supported applications (Applications) */
190 kCFDemoApplicationDirectory
, /* unsupported applications, demonstration versions (Demos) */
191 kCFDeveloperApplicationDirectory
, /* developer applications (Developer/Applications) */
192 kCFAdminApplicationDirectory
, /* system and network administration applications (Administration) */
193 kCFLibraryDirectory
, /* various user-visible documentation, support, and configuration files, resources (Library) */
194 kCFDeveloperDirectory
, /* developer resources (Developer) */
195 kCFUserDirectory
, /* user home directories (Users) */
196 kCFDocumentationDirectory
, /* documentation (Documentation) */
197 kCFDocumentDirectory
, /* documents (Library/Documents) */
198 kCFAllApplicationsDirectory
= 100, /* all directories where applications can occur (ie Applications, Demos, Administration, Developer/Applications) */
199 kCFAllLibrariesDirectory
= 101 /* all directories where resources can occur (Library, Developer) */
201 typedef CFIndex CFSearchPathDirectory
;
204 kCFUserDomainMask
= 1, /* user's home directory --- place to install user's personal items (~) */
205 kCFLocalDomainMask
= 2, /* local to the current machine --- place to install items available to everyone on this machine (/Local) */
206 kCFNetworkDomainMask
= 4, /* publically available location in the local area network --- place to install items available on the network (/Network) */
207 kCFSystemDomainMask
= 8, /* provided by Apple, unmodifiable (/System) */
208 kCFAllDomainsMask
= 0x0ffff /* all domains: all of the above and more, future items */
210 typedef CFOptionFlags CFSearchPathDomainMask
;
213 CFArrayRef
CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory
, CFSearchPathDomainMask domainMask
, Boolean expandTilde
);
216 CF_EXPORT
const CFStringRef kCFFileURLExists
;
217 CF_EXPORT
const CFStringRef kCFFileURLPOSIXMode
;
218 CF_EXPORT
const CFStringRef kCFFileURLSize
;
219 CF_EXPORT
const CFStringRef kCFFileURLDirectoryContents
;
220 CF_EXPORT
const CFStringRef kCFFileURLLastModificationTime
;
221 CF_EXPORT
const CFStringRef kCFHTTPURLStatusCode
;
222 CF_EXPORT
const CFStringRef kCFHTTPURLStatusLine
;
225 /* System Version file access */
226 CF_EXPORT CFStringRef
CFCopySystemVersionString(void); // Human-readable string containing both marketing and build version, should be API'd
227 CF_EXPORT CFDictionaryRef
_CFCopySystemVersionDictionary(void);
228 CF_EXPORT CFDictionaryRef
_CFCopyServerVersionDictionary(void);
229 CF_EXPORT
const CFStringRef _kCFSystemVersionProductNameKey
;
230 CF_EXPORT
const CFStringRef _kCFSystemVersionProductCopyrightKey
;
231 CF_EXPORT
const CFStringRef _kCFSystemVersionProductVersionKey
;
232 CF_EXPORT
const CFStringRef _kCFSystemVersionProductVersionExtraKey
;
233 CF_EXPORT
const CFStringRef _kCFSystemVersionProductUserVisibleVersionKey
; // For loginwindow; see 2987512
234 CF_EXPORT
const CFStringRef _kCFSystemVersionBuildVersionKey
;
235 CF_EXPORT
const CFStringRef _kCFSystemVersionProductVersionStringKey
; // Localized string for the string "Version"
236 CF_EXPORT
const CFStringRef _kCFSystemVersionBuildStringKey
; // Localized string for the string "Build"
239 CF_EXPORT
void CFMergeSortArray(void *list
, CFIndex count
, CFIndex elementSize
, CFComparatorFunction comparator
, void *context
);
240 CF_EXPORT
void CFQSortArray(void *list
, CFIndex count
, CFIndex elementSize
, CFComparatorFunction comparator
, void *context
);
242 /* _CFExecutableLinkedOnOrAfter(releaseVersionName) will return YES if the current executable seems to be linked on or after the specified release. Example: If you specify CFSystemVersionPuma (10.1), you will get back true for executables linked on Puma or Jaguar(10.2), but false for those linked on Cheetah (10.0) or any of its software updates (10.0.x). You will also get back false for any app whose version info could not be figured out.
243 This function caches its results, so no need to cache at call sites.
245 Note that for non-MACH this function always returns true.
248 CFSystemVersionCheetah
= 0, /* 10.0 */
249 CFSystemVersionPuma
= 1, /* 10.1 */
250 CFSystemVersionJaguar
= 2, /* 10.2 */
251 CFSystemVersionPanther
= 3, /* 10.3 */
252 CFSystemVersionPinot
= 3, /* Deprecated name for Panther */
253 CFSystemVersionTiger
= 4, /* 10.4 */
254 CFSystemVersionMerlot
= 4, /* Deprecated name for Tiger */
255 CFSystemVersionLeopard
= 5, /* Post-Tiger */
256 CFSystemVersionChablis
= 5, /* Deprecated name for Leopard */
257 CFSystemVersionMax
/* This should bump up when new entries are added */
259 typedef CFIndex CFSystemVersion
;
261 CF_EXPORT Boolean
_CFExecutableLinkedOnOrAfter(CFSystemVersion version
);
265 kCFStringGraphemeCluster
= 1, /* Unicode Grapheme Cluster */
266 kCFStringComposedCharacterCluster
= 2, /* Compose all non-base (including spacing marks) */
267 kCFStringCursorMovementCluster
= 3, /* Cluster suitable for cursor movements */
268 kCFStringBackwardDeletionCluster
= 4 /* Cluster suitable for backward deletion */
270 typedef CFIndex CFStringCharacterClusterType
;
272 CF_EXPORT CFRange
CFStringGetRangeOfCharacterClusterAtIndex(CFStringRef string
, CFIndex charIndex
, CFStringCharacterClusterType type
);
274 // Compatibility kCFCompare flags. Use the new public kCFCompareDiacriticInsensitive
276 kCFCompareDiacriticsInsensitive
= 128, /* kCFCompareDiacriticInsensitive */
277 kCFCompareDiacriticsInsensitiveCompatibilityMask
= ((1 << 28)|kCFCompareDiacriticsInsensitive
),
280 /* CFStringEncoding SPI */
281 /* When set, CF encoding conversion engine keeps ASCII compatibility. (i.e. ASCII backslash <-> Unicode backslash in MacJapanese */
282 CF_EXPORT
void _CFStringEncodingSetForceASCIICompatibility(Boolean flag
);
284 #if defined(CF_INLINE)
285 CF_INLINE
const UniChar
*CFStringGetCharactersPtrFromInlineBuffer(CFStringInlineBuffer
*buf
, CFRange desiredRange
) {
286 if ((desiredRange
.location
< 0) || ((desiredRange
.location
+ desiredRange
.length
) > buf
->rangeToBuffer
.length
)) return NULL
;
288 if (buf
->directBuffer
) {
289 return buf
->directBuffer
+ buf
->rangeToBuffer
.location
+ desiredRange
.location
;
291 if (desiredRange
.length
> __kCFStringInlineBufferLength
) return NULL
;
293 if (((desiredRange
.location
+ desiredRange
.length
) > buf
->bufferedRangeEnd
) || (desiredRange
.location
< buf
->bufferedRangeStart
)) {
294 buf
->bufferedRangeStart
= desiredRange
.location
;
295 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
296 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
297 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
300 return buf
->buffer
+ (desiredRange
.location
- buf
->bufferedRangeStart
);
304 CF_INLINE
void CFStringGetCharactersFromInlineBuffer(CFStringInlineBuffer
*buf
, CFRange desiredRange
, UniChar
*outBuf
) {
305 if (buf
->directBuffer
) {
306 memmove(outBuf
, buf
->directBuffer
+ buf
->rangeToBuffer
.location
+ desiredRange
.location
, desiredRange
.length
* sizeof(UniChar
));
308 if ((desiredRange
.location
>= buf
->bufferedRangeStart
) && (desiredRange
.location
< buf
->bufferedRangeEnd
)) {
309 CFIndex bufLen
= desiredRange
.length
;
311 if (bufLen
> (buf
->bufferedRangeEnd
- desiredRange
.location
)) bufLen
= (buf
->bufferedRangeEnd
- desiredRange
.location
);
313 memmove(outBuf
, buf
->buffer
+ (desiredRange
.location
- buf
->bufferedRangeStart
), bufLen
* sizeof(UniChar
));
314 outBuf
+= bufLen
; desiredRange
.location
+= bufLen
; desiredRange
.length
-= bufLen
;
316 CFIndex desiredRangeMax
= (desiredRange
.location
+ desiredRange
.length
);
318 if ((desiredRangeMax
> buf
->bufferedRangeStart
) && (desiredRangeMax
< buf
->bufferedRangeEnd
)) {
319 desiredRange
.length
= (buf
->bufferedRangeStart
- desiredRange
.location
);
320 memmove(outBuf
+ desiredRange
.length
, buf
->buffer
, (desiredRangeMax
- buf
->bufferedRangeStart
) * sizeof(UniChar
));
324 if (desiredRange
.length
> 0) CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ desiredRange
.location
, desiredRange
.length
), outBuf
);
329 #define CFStringGetCharactersPtrFromInlineBuffer(buf, desiredRange) ((buf)->directBuffer ? (buf)->directBuffer + (buf)->rangeToBuffer.location + desiredRange.location : NULL)
331 #define CFStringGetCharactersFromInlineBuffer(buf, desiredRange, outBuf) \
332 if (buf->directBuffer) memmove(outBuf, (buf)->directBuffer + (buf)->rangeToBuffer.location + desiredRange.location, desiredRange.length * sizeof(UniChar)); \
333 else CFStringGetCharacters((buf)->theString, CFRangeMake((buf)->rangeToBuffer.location + desiredRange.location, desiredRange.length), outBuf);
335 #endif /* CF_INLINE */
338 CFCharacterSetInlineBuffer related declarations
341 @typedef CFCharacterSetInlineBuffer
342 @field cset The character set this inline buffer is initialized with.
343 The object is not retained by the structure.
344 @field flags The field is a bit mask that carries various settings.
345 @field rangeStart The beginning of the character range that contains all members.
346 It is guaranteed that there is no member below this value.
347 @field rangeLimit The end of the character range that contains all members.
348 It is guaranteed that there is no member above and equal to this value.
349 @field bitmap The bitmap data representing the membership of the Basic Multilingual Plane characters.
350 If NULL, all BMP characters inside the range are members of the character set.
353 CFCharacterSetRef cset
;
357 const uint8_t *bitmap
;
358 } CFCharacterSetInlineBuffer
;
360 // Bits for flags field
362 kCFCharacterSetIsCompactBitmap
= (1 << 0),
363 kCFCharacterSetNoBitmapAvailable
= (1 << 1),
364 kCFCharacterSetIsInverted
= (1 << 2)
368 @function CFCharacterSetInitInlineBuffer
369 Initializes buffer with cset.
370 @param cset The character set used to initialized the buffer.
371 If this parameter is not a valid CFCharacterSet, the behavior is undefined.
372 @param buffer The reference to the inline buffer to be initialized.
375 void CFCharacterSetInitInlineBuffer(CFCharacterSetRef cset
, CFCharacterSetInlineBuffer
*buffer
);
378 @function CFCharacterSetInlineBufferIsLongCharacterMember
379 Reports whether or not the UTF-32 character is in the character set.
380 @param buffer The reference to the inline buffer to be searched.
381 @param character The UTF-32 character for which to test against the
383 @result true, if the value is in the character set, otherwise false.
385 #if defined(CF_INLINE)
386 CF_INLINE
bool CFCharacterSetInlineBufferIsLongCharacterMember(CFCharacterSetInlineBuffer
*buffer
, UTF32Char character
) {
387 bool isInverted
= ((0 == (buffer
->flags
& kCFCharacterSetIsInverted
)) ? false : true);
389 if ((character
>= buffer
->rangeStart
) && (character
< buffer
->rangeLimit
)) {
390 if ((character
> 0xFFFF) || (0 != (buffer
->flags
& kCFCharacterSetNoBitmapAvailable
))) return (CFCharacterSetIsLongCharacterMember(buffer
->cset
, character
) != 0);
391 if (NULL
== buffer
->bitmap
) {
392 if (0 == (buffer
->flags
& kCFCharacterSetIsCompactBitmap
)) isInverted
= !isInverted
;
393 } else if (0 == (buffer
->flags
& kCFCharacterSetIsCompactBitmap
)) {
394 if (buffer
->bitmap
[character
>> 3] & (1 << (character
& 7))) isInverted
= !isInverted
;
396 uint8_t value
= buffer
->bitmap
[character
>> 8];
399 isInverted
= !isInverted
;
400 } else if (value
> 0) {
401 const uint8_t *segment
= buffer
->bitmap
+ (256 + (32 * (value
- 1)));
403 if (segment
[character
>> 3] & (1 << (character
% 8))) isInverted
= !isInverted
;
409 #else /* CF_INLINE */
410 #define CFCharacterSetInlineBufferIsLongCharacterMember(buffer, character) (CFCharacterSetIsLongCharacterMember(buffer->cset, character))
411 #endif /* CF_INLINE */
414 #if defined(__MACH__)
415 #include <CoreFoundation/CFMessagePort.h>
417 CFMessagePortRef
CFMessagePortCreatePerProcessLocal(CFAllocatorRef allocator
, CFStringRef name
, CFMessagePortCallBack callout
, CFMessagePortContext
*context
, Boolean
*shouldFreeInfo
);
418 CFMessagePortRef
CFMessagePortCreatePerProcessRemote(CFAllocatorRef allocator
, CFStringRef name
, CFIndex pid
);
424 #endif /* ! __COREFOUNDATION_CFPRIV__ */