]> git.saurik.com Git - apple/cf.git/blob - CFPriv.h
CF-476.10.tar.gz
[apple/cf.git] / CFPriv.h
1 /*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* CFPriv.h
24 Copyright (c) 1998-2007, Apple Inc. All rights reserved.
25 */
26
27 /*
28 APPLE SPI: NOT TO BE USED OUTSIDE APPLE!
29 */
30
31 #if !defined(__COREFOUNDATION_CFPRIV__)
32 #define __COREFOUNDATION_CFPRIV__ 1
33
34 #include <string.h>
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>
40
41
42 #if defined(__MACH__)
43 #include <CoreFoundation/CFMachPort.h>
44 #endif
45
46 #if defined(__MACH__) || defined(__WIN32__)
47 #include <CoreFoundation/CFRunLoop.h>
48 #include <CoreFoundation/CFSocket.h>
49 #endif
50
51 #if defined(__MACH__)
52 #include <CoreFoundation/CFMachPort.h>
53 #endif
54
55 #if 0
56 #include <shlobj.h>
57 #endif
58
59 CF_EXTERN_C_BEGIN
60
61 CF_EXPORT intptr_t _CFDoOperation(intptr_t code, intptr_t subcode1, intptr_t subcode2);
62
63 CF_EXPORT void _CFRuntimeSetCFMPresent(void *a);
64
65 CF_EXPORT const char *_CFProcessPath(void);
66 CF_EXPORT const char **_CFGetProcessPath(void);
67 CF_EXPORT const char **_CFGetProgname(void);
68
69
70 #if defined(__MACH__)
71 CF_EXPORT CFRunLoopRef CFRunLoopGetMain(void);
72 CF_EXPORT SInt32 CFRunLoopRunSpecific(CFRunLoopRef rl, CFStringRef modeName, CFTimeInterval seconds, Boolean returnAfterSourceHandled);
73
74 CF_EXPORT void _CFRunLoopSetCurrent(CFRunLoopRef rl);
75
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);
80
81 #if defined(__MACH__)
82 CF_EXPORT CFIndex CFMachPortGetQueuedMessageCount(CFMachPortRef mp);
83 #endif
84
85 CF_EXPORT CFPropertyListRef _CFURLCopyPropertyListRepresentation(CFURLRef url);
86 CF_EXPORT CFURLRef _CFURLCreateFromPropertyListRepresentation(CFAllocatorRef alloc, CFPropertyListRef pListRepresentation);
87 #endif
88 CF_EXPORT CFPropertyListRef _CFURLCopyPropertyListRepresentation(CFURLRef url);
89 CF_EXPORT CFURLRef _CFURLCreateFromPropertyListRepresentation(CFAllocatorRef alloc, CFPropertyListRef pListRepresentation);
90
91 CF_EXPORT void CFPreferencesFlushCaches(void);
92
93 #if !__LP64__
94 #if !defined(__WIN32__)
95 struct FSSpec;
96 CF_EXPORT
97 Boolean _CFGetFSSpecFromURL(CFAllocatorRef alloc, CFURLRef url, struct FSSpec *spec);
98
99 CF_EXPORT
100 CFURLRef _CFCreateURLFromFSSpec(CFAllocatorRef alloc, const struct FSSpec *voidspec, Boolean isDirectory);
101 #endif
102 #endif
103
104 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
105 enum {
106 kCFURLComponentDecompositionNonHierarchical,
107 kCFURLComponentDecompositionRFC1808, /* use this for RFC 1738 decompositions as well */
108 kCFURLComponentDecompositionRFC2396
109 };
110 typedef CFIndex CFURLComponentDecomposition;
111
112 typedef struct {
113 CFStringRef scheme;
114 CFStringRef schemeSpecific;
115 } CFURLComponentsNonHierarchical;
116
117 typedef struct {
118 CFStringRef scheme;
119 CFStringRef user;
120 CFStringRef password;
121 CFStringRef host;
122 CFIndex port; /* kCFNotFound means ignore/omit */
123 CFArrayRef pathComponents;
124 CFStringRef parameterString;
125 CFStringRef query;
126 CFStringRef fragment;
127 CFURLRef baseURL;
128 } CFURLComponentsRFC1808;
129
130 typedef struct {
131 CFStringRef scheme;
132
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;
135 CFStringRef host;
136 CFIndex port;
137
138 CFArrayRef pathComponents;
139 CFStringRef query;
140 CFStringRef fragment;
141 CFURLRef baseURL;
142 } CFURLComponentsRFC2396;
143
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 */
145 CF_EXPORT
146 Boolean _CFURLCopyComponents(CFURLRef url, CFURLComponentDecomposition decompositionType, void *components);
147
148 /* Creates and returns the URL described by components; components should point to the CFURLComponents struct defined above that matches decompositionType. */
149 CF_EXPORT
150 CFURLRef _CFURLCreateFromComponents(CFAllocatorRef alloc, CFURLComponentDecomposition decompositionType, const void *components);
151 #define CFURLCopyComponents _CFURLCopyComponents
152 #define CFURLCreateFromComponents _CFURLCreateFromComponents
153 #endif
154
155
156 CF_EXPORT Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8 *buffer, CFIndex maxBufLen);
157
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);
160
161 /* These return NULL on MacOS 8 */
162 CF_EXPORT
163 CFStringRef CFGetUserName(void);
164
165 CF_EXPORT
166 CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName); /* Pass NULL for the current user's home directory */
167
168
169 /* Extra user notification key for iPhone */
170 CF_EXPORT
171 const CFStringRef kCFUserNotificationKeyboardTypesKey AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
172
173
174 /*
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
185 directories!
186 ??? On MacOS 8 this function currently returns an empty array.
187 */
188 enum {
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) */
200 };
201 typedef CFIndex CFSearchPathDirectory;
202
203 enum {
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 */
209 };
210 typedef CFOptionFlags CFSearchPathDomainMask;
211
212 CF_EXPORT
213 CFArrayRef CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory, CFSearchPathDomainMask domainMask, Boolean expandTilde);
214
215 /* Obsolete keys */
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;
223
224
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"
237
238
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);
241
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.
244
245 Note that for non-MACH this function always returns true.
246 */
247 enum {
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 */
258 };
259 typedef CFIndex CFSystemVersion;
260
261 CF_EXPORT Boolean _CFExecutableLinkedOnOrAfter(CFSystemVersion version);
262
263
264 enum {
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 */
269 };
270 typedef CFIndex CFStringCharacterClusterType;
271
272 CF_EXPORT CFRange CFStringGetRangeOfCharacterClusterAtIndex(CFStringRef string, CFIndex charIndex, CFStringCharacterClusterType type);
273
274 // Compatibility kCFCompare flags. Use the new public kCFCompareDiacriticInsensitive
275 enum {
276 kCFCompareDiacriticsInsensitive = 128, /* kCFCompareDiacriticInsensitive */
277 kCFCompareDiacriticsInsensitiveCompatibilityMask = ((1 << 28)|kCFCompareDiacriticsInsensitive),
278 };
279
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);
283
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;
287
288 if (buf->directBuffer) {
289 return buf->directBuffer + buf->rangeToBuffer.location + desiredRange.location;
290 } else {
291 if (desiredRange.length > __kCFStringInlineBufferLength) return NULL;
292
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);
298 }
299
300 return buf->buffer + (desiredRange.location - buf->bufferedRangeStart);
301 }
302 }
303
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));
307 } else {
308 if ((desiredRange.location >= buf->bufferedRangeStart) && (desiredRange.location < buf->bufferedRangeEnd)) {
309 CFIndex bufLen = desiredRange.length;
310
311 if (bufLen > (buf->bufferedRangeEnd - desiredRange.location)) bufLen = (buf->bufferedRangeEnd - desiredRange.location);
312
313 memmove(outBuf, buf->buffer + (desiredRange.location - buf->bufferedRangeStart), bufLen * sizeof(UniChar));
314 outBuf += bufLen; desiredRange.location += bufLen; desiredRange.length -= bufLen;
315 } else {
316 CFIndex desiredRangeMax = (desiredRange.location + desiredRange.length);
317
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));
321 }
322 }
323
324 if (desiredRange.length > 0) CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + desiredRange.location, desiredRange.length), outBuf);
325 }
326 }
327
328 #else
329 #define CFStringGetCharactersPtrFromInlineBuffer(buf, desiredRange) ((buf)->directBuffer ? (buf)->directBuffer + (buf)->rangeToBuffer.location + desiredRange.location : NULL)
330
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);
334
335 #endif /* CF_INLINE */
336
337 /*
338 CFCharacterSetInlineBuffer related declarations
339 */
340 /*!
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.
351 */
352 typedef struct {
353 CFCharacterSetRef cset;
354 uint32_t flags;
355 uint32_t rangeStart;
356 uint32_t rangeLimit;
357 const uint8_t *bitmap;
358 } CFCharacterSetInlineBuffer;
359
360 // Bits for flags field
361 enum {
362 kCFCharacterSetIsCompactBitmap = (1 << 0),
363 kCFCharacterSetNoBitmapAvailable = (1 << 1),
364 kCFCharacterSetIsInverted = (1 << 2)
365 };
366
367 /*!
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.
373 */
374 CF_EXPORT
375 void CFCharacterSetInitInlineBuffer(CFCharacterSetRef cset, CFCharacterSetInlineBuffer *buffer);
376
377 /*!
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
382 character set.
383 @result true, if the value is in the character set, otherwise false.
384 */
385 #if defined(CF_INLINE)
386 CF_INLINE bool CFCharacterSetInlineBufferIsLongCharacterMember(CFCharacterSetInlineBuffer *buffer, UTF32Char character) {
387 bool isInverted = ((0 == (buffer->flags & kCFCharacterSetIsInverted)) ? false : true);
388
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;
395 } else {
396 uint8_t value = buffer->bitmap[character >> 8];
397
398 if (value == 0xFF) {
399 isInverted = !isInverted;
400 } else if (value > 0) {
401 const uint8_t *segment = buffer->bitmap + (256 + (32 * (value - 1)));
402 character &= 0xFF;
403 if (segment[character >> 3] & (1 << (character % 8))) isInverted = !isInverted;
404 }
405 }
406 }
407 return isInverted;
408 }
409 #else /* CF_INLINE */
410 #define CFCharacterSetInlineBufferIsLongCharacterMember(buffer, character) (CFCharacterSetIsLongCharacterMember(buffer->cset, character))
411 #endif /* CF_INLINE */
412
413
414 #if defined(__MACH__)
415 #include <CoreFoundation/CFMessagePort.h>
416
417 CFMessagePortRef CFMessagePortCreatePerProcessLocal(CFAllocatorRef allocator, CFStringRef name, CFMessagePortCallBack callout, CFMessagePortContext *context, Boolean *shouldFreeInfo);
418 CFMessagePortRef CFMessagePortCreatePerProcessRemote(CFAllocatorRef allocator, CFStringRef name, CFIndex pid);
419 #endif
420
421
422 CF_EXTERN_C_END
423
424 #endif /* ! __COREFOUNDATION_CFPRIV__ */
425