2 * Copyright (c) 2010 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 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFURL__)
29 #define __COREFOUNDATION_CFURL__ 1
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFData.h>
33 #include <CoreFoundation/CFError.h>
34 #include <CoreFoundation/CFString.h>
39 kCFURLPOSIXPathStyle
= 0,
41 kCFURLWindowsPathStyle
43 typedef CFIndex CFURLPathStyle
;
45 typedef const struct __CFURL
* CFURLRef
;
47 /* CFURLs are composed of two fundamental pieces - their string, and a */
48 /* (possibly NULL) base URL. A relative URL is one in which the string */
49 /* by itself does not fully specify the URL (for instance "myDir/image.tiff"); */
50 /* an absolute URL is one in which the string does fully specify the URL */
51 /* ("file://localhost/myDir/image.tiff"). Absolute URLs always have NULL */
52 /* base URLs; however, it is possible for a URL to have a NULL base, and still */
53 /* not be absolute. Such a URL has only a relative string, and cannot be */
54 /* resolved. Two CFURLs are considered equal if and only if their strings */
55 /* are equal and their bases are equal. In other words, */
56 /* "file://localhost/myDir/image.tiff" is NOT equal to the URL with relative */
57 /* string "myDir/image.tiff" and base URL "file://localhost/". Clients that */
58 /* need these less strict form of equality should convert all URLs to their */
59 /* absolute form via CFURLCopyAbsoluteURL(), then compare the absolute forms. */
62 CFTypeID
CFURLGetTypeID(void);
64 /* encoding will be used both to interpret the bytes of URLBytes, and to */
65 /* interpret any percent-escapes within the bytes. */
67 CFURLRef
CFURLCreateWithBytes(CFAllocatorRef allocator
, const UInt8
*URLBytes
, CFIndex length
, CFStringEncoding encoding
, CFURLRef baseURL
);
69 /* Escapes any character that is not 7-bit ASCII with the byte-code */
70 /* for the given encoding. If escapeWhitespace is true, whitespace */
71 /* characters (' ', '\t', '\r', '\n') will be escaped also (desirable */
72 /* if embedding the URL into a larger text stream like HTML) */
74 CFDataRef
CFURLCreateData(CFAllocatorRef allocator
, CFURLRef url
, CFStringEncoding encoding
, Boolean escapeWhitespace
);
76 /* Any escape sequences in URLString will be interpreted via UTF-8. */
78 CFURLRef
CFURLCreateWithString(CFAllocatorRef allocator
, CFStringRef URLString
, CFURLRef baseURL
);
80 #if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED
82 /* Create an absolute URL directly, without requiring the extra step */
83 /* of calling CFURLCopyAbsoluteURL(). If useCompatibilityMode is */
84 /* true, the rules historically used on the web are used to resolve */
85 /* relativeString against baseURL - these rules are generally listed */
86 /* in the RFC as optional or alternate interpretations. Otherwise, */
87 /* the strict rules from the RFC are used. The major differences are */
88 /* that in compatibility mode, we are lenient of the scheme appearing */
89 /* in relative portion, leading "../" components are removed from the */
90 /* final URL's path, and if the relative portion contains only */
91 /* resource specifier pieces (query, parameters, and fragment), then */
92 /* the last path component of the base URL will not be deleted */
94 CFURLRef
CFURLCreateAbsoluteURLWithBytes(CFAllocatorRef alloc
, const UInt8
*relativeURLBytes
, CFIndex length
, CFStringEncoding encoding
, CFURLRef baseURL
, Boolean useCompatibilityMode
) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
;
97 /* filePath should be the URL's path expressed as a path of the type */
98 /* fsType. If filePath is not absolute, the resulting URL will be */
99 /* considered relative to the current working directory (evaluated */
100 /* at creation time). isDirectory determines whether filePath is */
101 /* treated as a directory path when resolving against relative path */
104 CFURLRef
CFURLCreateWithFileSystemPath(CFAllocatorRef allocator
, CFStringRef filePath
, CFURLPathStyle pathStyle
, Boolean isDirectory
);
107 CFURLRef
CFURLCreateFromFileSystemRepresentation(CFAllocatorRef allocator
, const UInt8
*buffer
, CFIndex bufLen
, Boolean isDirectory
);
109 /* The path style of the baseURL must match the path style of the relative */
110 /* url or the results are undefined. If the provided filePath looks like an */
111 /* absolute path ( starting with '/' if pathStyle is kCFURLPosixPathStyle, */
112 /* not starting with ':' for kCFURLHFSPathStyle, or starting with what looks */
113 /* like a drive letter and colon for kCFURLWindowsPathStyle ) then the baseURL */
116 CFURLRef
CFURLCreateWithFileSystemPathRelativeToBase(CFAllocatorRef allocator
, CFStringRef filePath
, CFURLPathStyle pathStyle
, Boolean isDirectory
, CFURLRef baseURL
);
119 CFURLRef
CFURLCreateFromFileSystemRepresentationRelativeToBase(CFAllocatorRef allocator
, const UInt8
*buffer
, CFIndex bufLen
, Boolean isDirectory
, CFURLRef baseURL
);
121 /* Fills buffer with the file system's native representation of */
122 /* url's path. No more than maxBufLen bytes are written to buffer. */
123 /* The buffer should be at least the maximum path length for */
124 /* the file system in question to avoid failures for insufficiently */
125 /* large buffers. If resolveAgainstBase is true, the url's relative */
126 /* portion is resolved against its base before the path is computed. */
127 /* Returns success or failure. */
129 Boolean
CFURLGetFileSystemRepresentation(CFURLRef url
, Boolean resolveAgainstBase
, UInt8
*buffer
, CFIndex maxBufLen
);
131 /* Creates a new URL by resolving the relative portion of relativeURL against its base. */
133 CFURLRef
CFURLCopyAbsoluteURL(CFURLRef relativeURL
);
135 /* Returns the URL's string. */
137 CFStringRef
CFURLGetString(CFURLRef anURL
);
139 /* Returns the base URL if it exists */
141 CFURLRef
CFURLGetBaseURL(CFURLRef anURL
);
144 All URLs can be broken into two pieces - the scheme (preceding the
145 first colon) and the resource specifier (following the first colon).
146 Most URLs are also "standard" URLs conforming to RFC 1808 (available
147 from www.w3c.org). This category includes URLs of the file, http,
148 https, and ftp schemes, to name a few. Standard URLs start the
149 resource specifier with two slashes ("//"), and can be broken into
150 four distinct pieces - the scheme, the net location, the path, and
151 further resource specifiers (typically an optional parameter, query,
152 and/or fragment). The net location appears immediately following
153 the two slashes and goes up to the next slash; it's format is
154 scheme-specific, but is usually composed of some or all of a username,
155 password, host name, and port. The path is a series of path components
156 separated by slashes; if the net location is present, the path always
157 begins with a slash. Standard URLs can be relative to another URL,
158 in which case at least the scheme and possibly other pieces as well
159 come from the base URL (see RFC 1808 for precise details when resolving
160 a relative URL against its base). The full URL is therefore
162 <scheme> "://" <net location> <path, always starting with slash> <add'l resource specifiers>
164 If a given CFURL can be decomposed (that is, conforms to RFC 1808), you
165 can ask for each of the four basic pieces (scheme, net location, path,
166 and resource specifer) separately, as well as for its base URL. The
167 basic pieces are returned with any percent escape sequences still in
168 place (although note that the scheme may not legally include any
169 percent escapes); this is to allow the caller to distinguish between
170 percent sequences that may have syntactic meaning if replaced by the
171 character being escaped (for instance, a '/' in a path component).
172 Since only the individual schemes know which characters are
173 syntactically significant, CFURL cannot safely replace any percent
174 escape sequences. However, you can use
175 CFURLCreateStringByReplacingPercentEscapes() to create a new string with
176 the percent escapes removed; see below.
178 If a given CFURL can not be decomposed, you can ask for its scheme and its
179 resource specifier; asking it for its net location or path will return NULL.
181 To get more refined information about the components of a decomposable
182 CFURL, you may ask for more specific pieces of the URL, expressed with
183 the percent escapes removed. The available functions are CFURLCopyHostName(),
184 CFURLGetPortNumber() (returns an Int32), CFURLCopyUserName(),
185 CFURLCopyPassword(), CFURLCopyQuery(), CFURLCopyParameters(), and
186 CFURLCopyFragment(). Because the parameters, query, and fragment of an
187 URL may contain scheme-specific syntaxes, these methods take a second
188 argument, giving a list of characters which should NOT be replaced if
189 percent escaped. For instance, the ftp parameter syntax gives simple
190 key-value pairs as "<key>=<value>;" Clearly if a key or value includes
191 either '=' or ';', it must be escaped to avoid corrupting the meaning of
192 the parameters, so the caller may request the parameter string as
194 CFStringRef myParams = CFURLCopyParameters(ftpURL, CFSTR("=;%"));
196 requesting that all percent escape sequences be replaced by the represented
197 characters, except for escaped '=', '%' or ';' characters. Pass the empty
198 string (CFSTR("")) to request that all percent escapes be replaced, or NULL
199 to request that none be.
202 /* Returns true if anURL conforms to RFC 1808 */
204 Boolean
CFURLCanBeDecomposed(CFURLRef anURL
);
206 /* The next several methods leave any percent escape sequences intact */
209 CFStringRef
CFURLCopyScheme(CFURLRef anURL
);
211 /* NULL if CFURLCanBeDecomposed(anURL) is false */
213 CFStringRef
CFURLCopyNetLocation(CFURLRef anURL
);
215 /* NULL if CFURLCanBeDecomposed(anURL) is false; also does not resolve the URL */
216 /* against its base. See also CFURLCopyAbsoluteURL(). Note that, strictly */
217 /* speaking, any leading '/' is not considered part of the URL's path, although */
218 /* its presence or absence determines whether the path is absolute. */
219 /* CFURLCopyPath()'s return value includes any leading slash (giving the path */
220 /* the normal POSIX appearance); CFURLCopyStrictPath()'s return value omits any */
221 /* leading slash, and uses isAbsolute to report whether the URL's path is absolute. */
223 /* CFURLCopyFileSystemPath() returns the URL's path as a file system path for the */
224 /* given path style. All percent escape sequences are replaced. The URL is not */
225 /* resolved against its base before computing the path. */
227 CFStringRef
CFURLCopyPath(CFURLRef anURL
);
230 CFStringRef
CFURLCopyStrictPath(CFURLRef anURL
, Boolean
*isAbsolute
);
233 CFStringRef
CFURLCopyFileSystemPath(CFURLRef anURL
, CFURLPathStyle pathStyle
);
235 /* Returns whether anURL's path represents a directory */
236 /* (true returned) or a simple file (false returned) */
238 Boolean
CFURLHasDirectoryPath(CFURLRef anURL
);
240 /* Any additional resource specifiers after the path. For URLs */
241 /* that cannot be decomposed, this is everything except the scheme itself. */
243 CFStringRef
CFURLCopyResourceSpecifier(CFURLRef anURL
);
246 CFStringRef
CFURLCopyHostName(CFURLRef anURL
);
249 SInt32
CFURLGetPortNumber(CFURLRef anURL
); /* Returns -1 if no port number is specified */
252 CFStringRef
CFURLCopyUserName(CFURLRef anURL
);
255 CFStringRef
CFURLCopyPassword(CFURLRef anURL
);
257 /* These remove all percent escape sequences except those for */
258 /* characters in charactersToLeaveEscaped. If charactersToLeaveEscaped */
259 /* is empty (""), all percent escape sequences are replaced by their */
260 /* corresponding characters. If charactersToLeaveEscaped is NULL, */
261 /* then no escape sequences are removed at all */
263 CFStringRef
CFURLCopyParameterString(CFURLRef anURL
, CFStringRef charactersToLeaveEscaped
);
266 CFStringRef
CFURLCopyQueryString(CFURLRef anURL
, CFStringRef charactersToLeaveEscaped
);
269 CFStringRef
CFURLCopyFragment(CFURLRef anURL
, CFStringRef charactersToLeaveEscaped
);
272 CFStringRef
CFURLCopyLastPathComponent(CFURLRef url
);
275 CFStringRef
CFURLCopyPathExtension(CFURLRef url
);
277 /* These functions all treat the base URL of the supplied url as */
278 /* invariant. In other words, the URL returned will always have */
279 /* the same base as the URL supplied as an argument. */
282 CFURLRef
CFURLCreateCopyAppendingPathComponent(CFAllocatorRef allocator
, CFURLRef url
, CFStringRef pathComponent
, Boolean isDirectory
);
285 CFURLRef
CFURLCreateCopyDeletingLastPathComponent(CFAllocatorRef allocator
, CFURLRef url
);
288 CFURLRef
CFURLCreateCopyAppendingPathExtension(CFAllocatorRef allocator
, CFURLRef url
, CFStringRef extension
);
291 CFURLRef
CFURLCreateCopyDeletingPathExtension(CFAllocatorRef allocator
, CFURLRef url
);
293 #if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED
294 /* Fills buffer with the bytes for url, returning the number of bytes */
295 /* filled. If buffer is of insufficient size, returns -1 and no bytes */
296 /* are placed in buffer. If buffer is NULL, the needed length is */
297 /* computed and returned. The returned bytes are the original bytes */
298 /* from which the URL was created; if the URL was created from a */
299 /* string, the bytes will be the bytes of the string encoded via UTF-8 */
301 CFIndex
CFURLGetBytes(CFURLRef url
, UInt8
*buffer
, CFIndex bufferLength
) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
;
304 kCFURLComponentScheme
= 1,
305 kCFURLComponentNetLocation
= 2,
306 kCFURLComponentPath
= 3,
307 kCFURLComponentResourceSpecifier
= 4,
309 kCFURLComponentUser
= 5,
310 kCFURLComponentPassword
= 6,
311 kCFURLComponentUserInfo
= 7,
312 kCFURLComponentHost
= 8,
313 kCFURLComponentPort
= 9,
314 kCFURLComponentParameterString
= 10,
315 kCFURLComponentQuery
= 11,
316 kCFURLComponentFragment
= 12
318 typedef CFIndex CFURLComponentType
;
321 Gets the range of the requested component in the bytes of url, as
322 returned by CFURLGetBytes(). This range is only good for use in the
323 bytes returned by CFURLGetBytes!
325 If non-NULL, rangeIncludingSeparators gives the range of component
326 including the sequences that separate component from the previous and
327 next components. If there is no previous or next component, that end of
328 rangeIncludingSeparators will match the range of the component itself.
329 If url does not contain the given component type, (kCFNotFound, 0) is
330 returned, and rangeIncludingSeparators is set to the location where the
331 component would be inserted. Some examples -
333 For the URL http://www.apple.com/hotnews/
335 Component returned range rangeIncludingSeparators
337 net location (7, 13) (4, 16)
339 resource specifier (kCFNotFound, 0) (29, 0)
340 user (kCFNotFound, 0) (7, 0)
341 password (kCFNotFound, 0) (7, 0)
342 user info (kCFNotFound, 0) (7, 0)
344 port (kCFNotFound, 0) (20, 0)
345 parameter (kCFNotFound, 0) (29, 0)
346 query (kCFNotFound, 0) (29, 0)
347 fragment (kCFNotFound, 0) (29, 0)
350 For the URL ./relPath/file.html#fragment
352 Component returned range rangeIncludingSeparators
353 scheme (kCFNotFound, 0) (0, 0)
354 net location (kCFNotFound, 0) (0, 0)
356 resource specifier (20, 8) (19, 9)
357 user (kCFNotFound, 0) (0, 0)
358 password (kCFNotFound, 0) (0, 0)
359 user info (kCFNotFound, 0) (0, 0)
360 host (kCFNotFound, 0) (0, 0)
361 port (kCFNotFound, 0) (0, 0)
362 parameter (kCFNotFound, 0) (19, 0)
363 query (kCFNotFound, 0) (19, 0)
364 fragment (20, 8) (19, 9)
367 For the URL scheme://user:pass@host:1/path/path2/file.html;params?query#fragment
369 Component returned range rangeIncludingSeparators
371 net location (9, 16) (6, 19)
372 path (25, 21) (25, 22)
373 resource specifier (47, 21) (46, 22)
375 password (14, 4) (13, 6)
376 user info (9, 9) (6, 13)
379 parameter (47, 6) (46, 8)
380 query (54, 5) (53, 7)
381 fragment (60, 8) (59, 9)
384 CFRange
CFURLGetByteRangeForComponent(CFURLRef url
, CFURLComponentType component
, CFRange
*rangeIncludingSeparators
) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
;
387 /* Returns a string with any percent escape sequences that do NOT */
388 /* correspond to characters in charactersToLeaveEscaped with their */
389 /* equivalent. Returns NULL on failure (if an invalid percent sequence */
390 /* is encountered), or the original string (retained) if no characters */
391 /* need to be replaced. Pass NULL to request that no percent escapes be */
392 /* replaced, or the empty string (CFSTR("")) to request that all percent */
393 /* escapes be replaced. Uses UTF8 to interpret percent escapes. */
395 CFStringRef
CFURLCreateStringByReplacingPercentEscapes(CFAllocatorRef allocator
, CFStringRef originalString
, CFStringRef charactersToLeaveEscaped
);
397 #if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED
398 /* As above, but allows you to specify the encoding to use when interpreting percent escapes */
400 CFStringRef
CFURLCreateStringByReplacingPercentEscapesUsingEncoding(CFAllocatorRef allocator
, CFStringRef origString
, CFStringRef charsToLeaveEscaped
, CFStringEncoding encoding
) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
;
403 /* Creates a copy or originalString, replacing certain characters with */
404 /* the equivalent percent escape sequence based on the encoding specified. */
405 /* If the originalString does not need to be modified (no percent escape */
406 /* sequences are missing), may retain and return originalString. */
407 /* If you are uncertain of the correct encoding, you should use UTF-8, */
408 /* which is the encoding designated by RFC 2396 as the correct encoding */
409 /* for use in URLs. The characters so escaped are all characters that */
410 /* are not legal URL characters (based on RFC 2396), plus any characters */
411 /* in legalURLCharactersToBeEscaped, less any characters in */
412 /* charactersToLeaveUnescaped. To simply correct any non-URL characters */
413 /* in an otherwise correct URL string, do: */
415 /* newString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, origString, NULL, NULL, kCFStringEncodingUTF8); */
417 CFStringRef
CFURLCreateStringByAddingPercentEscapes(CFAllocatorRef allocator
, CFStringRef originalString
, CFStringRef charactersToLeaveUnescaped
, CFStringRef legalURLCharactersToBeEscaped
, CFStringEncoding encoding
);
420 /* Returns a file reference URL, a path-idependent form of file URL. */
421 /* Converts a file path URL if necessary. For non-file URLs, returns NULL. */
422 /* Also returns NULL when the conversion fails because the target resource doesn't exist. */
423 /* Optional output error: The error is set to a valid CFErrorRef when the function */
424 /* result is NULL. A valid output error must be released by the caller. */
426 CFURLRef
CFURLCreateFileReferenceURL(CFAllocatorRef allocator
, CFURLRef url
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
429 /* Returns a file path URL, converting a file reference URL if necessary. */
430 /* For non-file URLs, returns NULL. Also returns NULL when the conversion fails */
431 /* because the target resource doesn't exist. */
432 /* Optional output error: The error is set to a valid CFErrorRef when the function */
433 /* result is NULL. A valid output error must be released by the caller. */
435 CFURLRef
CFURLCreateFilePathURL(CFAllocatorRef allocator
, CFURLRef url
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
442 /* The following APIs provide efficient access to resource properties. Properties
443 are identified by keys, and values are represented as Core Foundation objects. The
444 type of each value is fixed for each property, e.g. the modification date is a CFDateRef,
445 the file size is a CFNumberRef.
447 Values are fetched on-demand, synchronously, from the resource's backing store. They
448 are cached and reused when fetched again through the same URL instance, until the
449 client clears the value. The client has complete control over the cache lifetime.
451 Some resource property values can be changed, given sufficient access permission to the resource.
452 When a resource property value is set, the change is written to backing store synchronously.
455 /* Assigns the requested resource property value to the typeRefValuePtr output */
456 /* argument. Returns true if the output value was set. Note that NULL is a valid output value. */
457 /* The value is fetched synchronously from the resource backing store only if a value is not */
458 /* already cached. The type of the output value type varies by property (see property key */
459 /* definitions). Returns false if an error occurs. Optional output error: the error is set to */
460 /* a valid CFErrorRef when the function returns false. A valid output error must be */
461 /* released by the caller. */
463 Boolean
CFURLCopyResourcePropertyForKey(CFURLRef url
, CFStringRef key
, void *propertyValueTypeRefPtr
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
466 /* Returns any number of resource property values as a dictionary of keyed values. */
467 /* The requested values are specified as an array of keys to appear in */
468 /* the result dictionary. Values are fetched synchronously from the resource backing store unless */
469 /* already cached. The type of each value type varies (see key definitions, below). */
470 /* Returns an empty dictionary if no values are found. Returns NULL when an error occurs. */
471 /* Optional output error: the error is set to a valid CFErrorRef when the */
472 /* function returns NULL. A valid output error must be released by the caller. */
474 CFDictionaryRef
CFURLCopyResourcePropertiesForKeys(CFURLRef url
, CFArrayRef keys
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
477 /* Changes a resource property value. Synchronously writes the value to the resource backing */
478 /* store. The input value type must be a valid CFTypeRef, of the type required for the specified */
479 /* key (see key definitions). Returns true upon success, false when an error occurs. */
480 /* Optional output error: the error is set to a valid CFErrorRef when the function */
481 /* returns false. A valid output error must be released by the caller. */
482 /* Note that some values are read-only. Attempting to set a read-only property */
483 /* results in an error. */
485 Boolean
CFURLSetResourcePropertyForKey(CFURLRef url
, CFStringRef key
, CFTypeRef propertValue
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
488 /* Changes any number of resource property values, specified as a dictionary of keyed values. */
489 /* Synchronously writes values to the resource backing store. The input dictionary's value types must conform */
490 /* to the type required for its key (see key definitions). Returns true when all values are set successfully, */
491 /* and false if an error occurs. Optional output error: the error is set to a valid CFErrorRef when the function returns */
492 /* false. A valid output error must be released by the caller. When an error occurs after some properties have been */
493 /* successfully changed, the user dictionary in the error contains an array of keys that */
494 /* were not set. Note that some values are read-only. Attempting to set a read-only value */
495 /* results in an error. */
497 Boolean
CFURLSetResourcePropertiesForKeys(CFURLRef url
, CFDictionaryRef keyedPropertyValues
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
500 /* Discards a cached property value for a specific key */
502 void CFURLClearResourcePropertyCacheForKey(CFURLRef url
, CFStringRef key
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
505 /* Discards all cached property values */
507 void CFURLClearResourcePropertyCache(CFURLRef url
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
510 /* Sets a temporary property value. Temporary properties exist only in memory and are never */
511 /* written to resource backing store. Once set, a temporary property value can be fetched */
512 /* with CFURLCopyResourcePropertyForKey and CFURLCopyResourcePropertiesForKeys. Temporary property */
513 /* values are for client use. Values must be valid Core Foundation types, and will be retained. */
514 /* To remove a temporary property value, use CFURLClearResourcePropertyCacheForKey. */
516 void CFURLSetTemporaryResourcePropertyForKey(CFURLRef url
, CFStringRef key
, CFTypeRef propertyValue
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
519 /* Synchronously checks if the resource's backing store is reachable and the resource exists, */
520 /* returning true if so. The optional output error can be used to determine the type of reachability */
521 /* failure (e.g., file not found, network error, etc.). The error is set to a valid CFErrorRef if */
522 /* and only if the function returns false. A valid output error must be released by */
523 /* the caller. Checking for resource existence and reachability is appropriate when making decisions */
524 /* that do not require other immediate operations on the resource. An example would be */
525 /* periodic maintenance of UI state that depends on the existence of a particular document. */
526 /* When performing an operation such as opening a file, it is more efficient to */
527 /* simply try the operation and handle failures than to check first for reachability. */
529 Boolean
CFURLResourceIsReachable(CFURLRef url
, CFErrorRef
*error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
532 /* Properties of File System Resources */
535 const CFStringRef kCFURLNameKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
536 /* The resource name provided by the file system (value type CFString) */
539 const CFStringRef kCFURLLocalizedNameKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
540 /* Localized or extension-hidden name as displayed to users (Read-only, value type CFString) */
543 const CFStringRef kCFURLIsRegularFileKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
544 /* True for regular files (Read-only, value type CFBoolean) */
547 const CFStringRef kCFURLIsDirectoryKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
548 /* True for directories (Read-only, CFBoolean) */
551 const CFStringRef kCFURLIsSymbolicLinkKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
552 /* True for symlinks (Read-only, value type CFBoolean) */
555 const CFStringRef kCFURLIsVolumeKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
556 /* True for the root directory of a volume (Read-only, value type CFBoolean) */
559 const CFStringRef kCFURLIsPackageKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
560 /* True for packaged directories (value type CFBoolean) */
563 const CFStringRef kCFURLIsSystemImmutableKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
564 /* True for system-immutable resources (value type CFBoolean) */
567 const CFStringRef kCFURLIsUserImmutableKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
568 /* True for user-immutable resources (value type CFBoolean) */
571 const CFStringRef kCFURLIsHiddenKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
572 /* True for resources normally hidden from users (value type CFBoolean) */
575 const CFStringRef kCFURLHasHiddenExtensionKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
576 /* True for resources whose filename extension is hiden (value type CFBoolean) */
579 const CFStringRef kCFURLCreationDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
580 /* Value type CFDate */
583 const CFStringRef kCFURLContentAccessDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
584 /* Value type CFDate */
587 const CFStringRef kCFURLContentModificationDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
588 /* Value type CFDate */
591 const CFStringRef kCFURLAttributeModificationDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
592 /* Value type CFDate */
595 const CFStringRef kCFURLLinkCountKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
596 /* Number of hard links to the resource (Read-only, CFNumber) */
599 const CFStringRef kCFURLParentDirectoryURLKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
600 /* URL of the parent directory, if any (Read-only, value type CFURL) */
603 const CFStringRef kCFURLVolumeURLKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
604 /* URL of the volume on which the resource is stored (Read-only, value type CFURL) */
607 const CFStringRef kCFURLTypeIdentifierKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
608 /* Uniform type identifier for the resource (Read-only, value type CFString) */
611 const CFStringRef kCFURLLocalizedTypeDescriptionKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
612 /* User-visible type or "kind" descriptiopn (Read-only, value type CFString) */
615 const CFStringRef kCFURLLabelNumberKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
616 /* The label number assigned to the resource (value type CFNumber) */
619 const CFStringRef kCFURLLabelColorKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
620 /* The color of the assigned label (Read-only, value type CGColorRef, must link with Application Services) */
623 const CFStringRef kCFURLLocalizedLabelKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
624 /* The user-visible label text (Read-only, value type CFString) */
627 const CFStringRef kCFURLEffectiveIconKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
628 /* The icon normally displayed for the resource (Read-only, value type CGImageRef, must link with Application Services) */
631 const CFStringRef kCFURLCustomIconKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
632 /* The custom icon assigned to the resource, if any (value type CGImageRef, must link with Application Services) */
635 /* File Properties */
638 const CFStringRef kCFURLFileSizeKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
639 /* Total file size, in bytes (Read-only, value type CFNumber) */
642 const CFStringRef kCFURLFileAllocatedSizeKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
643 /* Total size of blocks allocated (Read-only, value type CFNumber) */
646 const CFStringRef kCFURLIsAliasFileKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
647 /* true if the url is a Finder alias file, false otherwise ( Read-only, value type CFBooleanRef) */
650 /* Volume Properties */
652 /* For convenience, volume properties may be requested from any resource on a volume. */
655 const CFStringRef kCFURLVolumeLocalizedFormatDescriptionKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
656 /* The user-visible volume format (Read-only, value type CFString) */
659 const CFStringRef kCFURLVolumeTotalCapacityKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
660 /* Total volume capacity in bytes (Read-only, value type CFNumber) */
663 const CFStringRef kCFURLVolumeAvailableCapacityKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
664 /* Total free space, in bytes (Read-only, value type CFNumber) */
667 const CFStringRef kCFURLVolumeResourceCountKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
668 /* Total number of resources on the volume (Read-only, value type CFNumber) */
671 const CFStringRef kCFURLVolumeSupportsPersistentIDsKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
672 /* Read-only, value type CFBoolean */
675 const CFStringRef kCFURLVolumeSupportsSymbolicLinksKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
676 /* Read-only, value type CFBoolean */
679 const CFStringRef kCFURLVolumeSupportsHardLinksKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
680 /* Read-only, value type CFBoolean */
683 const CFStringRef kCFURLVolumeSupportsJournalingKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
684 /* Read-only, value type CFBoolean */
687 const CFStringRef kCFURLVolumeIsJournalingKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
688 /* Read-only, value type CFBoolean */
691 const CFStringRef kCFURLVolumeSupportsSparseFilesKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
692 /* Read-only, value type CFBoolean */
695 const CFStringRef kCFURLVolumeSupportsZeroRunsKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
696 /* Read-only, value type CFBoolean */
699 const CFStringRef kCFURLVolumeSupportsCaseSensitiveNamesKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
700 /* Read-only, value type CFBoolean */
703 const CFStringRef kCFURLVolumeSupportsCasePreservedNamesKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
704 /* Read-only, value type CFBoolean */
707 kCFURLBookmarkCreationPreferFileIDResolutionMask
= ( 1UL << 8 ), // At resolution time, this alias will prefer resolving by the embedded fileID to the path
708 kCFURLBookmarkCreationMinimalBookmarkMask
= ( 1UL << 9 ), // Creates a bookmark with "less" information, which may be smaller but still be able to resolve in certain ways
709 kCFURLBookmarkCreationSuitableForBookmarkFile
= ( 1UL << 10 ), // includes in the created bookmark those properties which are needed for a bookmark/alias file
711 typedef CFOptionFlags CFURLBookmarkCreationOptions
;
714 kCFBookmarkResolutionWithoutUIMask
= ( 1UL << 8 ), // don't perform any UI during bookmark resolution
715 kCFBookmarkResolutionWithoutMountingMask
= ( 1UL << 9 ), // don't mount a volume during bookmark resolution
717 typedef CFOptionFlags CFURLBookmarkResolutionOptions
;
719 typedef CFOptionFlags CFURLBookmarkFileCreationOptions
;
721 /* @function CFURLCreateBookmarkData
722 @discussion Create a CFDataRef containing an externalizable representation from a CFURLRef, modified with the given options, including ( at the minimum ) any
723 properties in the propertiesToInclude array which are retrievable from the given url.
724 @param allocator the CFAllocator to use to create this object
725 @param url the CFURLRef to create a bookmark data from.
726 @param options a set of options which control creation of the bookmark data
727 @param resourcePropertiesToInclude If non-NULL, an CFArrayRef of additional properties copied from the url to include in the created bookmark data.
728 @param relativeToURL If non-NULL, the created bookmark will be relative to the given url
729 @param error If non-NULL, on exit will be filled in with a CFErrorRef representing any error which occured during creation of the bookmark data
730 @result A CFDataRef containing an data, which can be later be passed to CFURLCreateByResolvingBookmarkData() or to CFURLCopyPropertiesForKeysFromBookmarkData() / CFURLCopyPropertyForKeyFromBookmarkData() */
731 CFDataRef
CFURLCreateBookmarkData ( CFAllocatorRef allocator
, CFURLRef url
, CFURLBookmarkCreationOptions options
, CFArrayRef resourcePropertiesToInclude
, CFURLRef relativeToURL
, CFErrorRef
* error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
733 /* @function CFURLCreateByResolvingBookmarkData
734 @discussion Given a CFDataRef created with CFURLCreateBookmarkRepresentation(), return a CFURLRef of the item it was a bookmark to, and
735 attempt to pre-cache those properties in propertiesToInclude in the resulting url. If in the process of resolving the bookmark into the CFURLRef
736 it points to this determines that some properties in the bookmark are out of date or not correct for the item it resolves to, set *isStale to YES,
737 which the client may want to use to decide to make a new bookmark from the returned item and replace the saved bookmark it has. If the bookmarked
738 item cannot be found, return NULL. If an error ( other than "original item can not be found" ) occurs during the process, return NULL and fill in error )
739 @param allocator the CFAllocator to use to create this object
740 @param bookmark a CFDataRef containing a bookmark data, created with CFURLCreateBookmarkData
741 @param options options which affect the resolution
742 @param relativeToURL If non-NULL, and if the bookmark was created relative to another url, then resolve it relative to this url
743 @param resourcePropertiesToInclude If non-NULL, a CFArray containing those properties which the caller would like to already be cached on the given url
744 @param isStale If non-NULL, on exit will be set to true if during resolution any of the properties in the bookmark no longer seemed to match the
745 corresponding properties on the returned file. Clients, upon seeing a stale representation, may want to replace whatever stored bookmark data they
746 have saved and create a new one.
747 @param error If non-NULL, on exit will be filled in with a CFErrorRef representing any error which occured during resolution of the bookmark data
748 @result A CFURLRef of a file which is the closest match to the file the bookmark data */
749 CFURLRef
CFURLCreateByResolvingBookmarkData ( CFAllocatorRef allocator
, CFDataRef bookmark
, CFURLBookmarkResolutionOptions options
, CFURLRef relativeToURL
, CFArrayRef resourcePropertiesToInclude
, Boolean
* isStale
, CFErrorRef
* error
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
751 /* @function CFURLCreatePropertiesForKeysFromBookmarkData
752 @discussion Given a bookmark, return a dictionary of properties ( all properties if propertiesToReturn == NULL ).
753 This returns only the properties stored within the bookmark and will not attempt to resolve the bookmark or do i/o.
754 @param allocator the CFAllocator to use to create this object
755 @param bookmark a CFDataRef containing a bookmark data, created with CFURLCreateBookmarkData
756 @param propertiesToReturn a CFArrayRef of the properties of the bookmark data which the client would like returned.
757 @result a CFDictionaryRef containing the values for the properties passed in obtained from the bookmark data ( not by attempting to resolve it or do i/o in any way ) */
758 CFDictionaryRef
CFURLCreateResourcePropertiesForKeysFromBookmarkData ( CFAllocatorRef allocator
, CFArrayRef resourcePropertiesToReturn
, CFDataRef bookmark
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
760 /* @function CFURLCreatePropertyForKeyFromBookmarkData
761 @discussion Given a bookmark, return the value for a given property from the bookmark data
762 This returns only the properties stored within the bookmark and will not attempt to resolve the bookmark or do i/o.
763 @param allocator the CFAllocator to use to create this object
764 @param bookmark a CFDataRef containing a bookmark data, created with CFURLCreateBookmarkData
765 @param propertyKey the property key to return.
766 @result a CFTypeRef value for the property passed in obtained from the bookmark data ( not by attempting to resolve it or do i/o in any way ) */
767 CFTypeRef
CFURLCreateResourcePropertyForKeyFromBookmarkData( CFAllocatorRef allocator
, CFStringRef resourcePropertyKey
, CFDataRef bookmark
) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
;
769 /*! @function CFURLCreateBookmarkDataFromFile
770 @description Given a fileURL of a file which is a Finder "alias" file, return a CFDataRef with the bookmark data from the file. If urlRef points to an alias file
771 created before SnowLeopard which contains Alias Manager information and no bookmark data, then a CFDataRef will be synthesized which contains
772 a approximation of the alias information in a format which can be used to resolve the bookmark. If an error prevents reading the data or
773 if it is corrupt, NULL will be returned and error will be filled in if errorRef is non-NULL.
774 @param allocator the CFAllocator to use to create this object
775 @param fileURL a CFURLRef to to the alias file to create the bookmark data from
776 @param errorRef if non-NULL, on exit will be filled in with a CFErrorRef representing any error which occurred during the creation of the bookmark data from the file
777 @result A CFDataRef containing bookmark data, or NULL if there was an error creating bookmark data from the file, such as if the file is not an alias file.
779 CFDataRef
CFURLCreateBookmarkDataFromFile(CFAllocatorRef allocator
, CFURLRef fileURL
, CFErrorRef
*errorRef
);
781 /*! @function CFURLWriteBookmarkDataToFile
782 @description Given a created bookmarkData object, create a new Finder "alias" file at fileURL which contains the bookmark data. If fileURL is a url to a directory, an alias file
783 will be created with the same name as the bookmarked item and a ".alias" extension. If fileURL is a url for a file and it exists it will be overwritten. If a
784 .alias extension is not present it will be added. In addition to the bookmark data, sufficient pre-SnowLeopard alias data will added to the file to allow
785 systems running something before SnowLeopard to resolve this file using Alias Manager routines and get back the same file as the bookmark routines.
786 The bookmark data must have been created with the kCFURLBookmarkCreationSuitableForBookmarkFile option and an error will be returned if not.
787 @param allocator the CFAllocator to use to create this object
788 @param bookmark a CFDataRef containing a bookmark data, created with CFURLCreateBookmarkData
789 @param options options flags
790 @param errorRef if non-NULL, on exit will be filled in with a CFErrorRef representing any error which occurred during the creation of the alias file
792 Boolean
CFURLWriteBookmarkDataToFile( CFDataRef bookmarkRef
, CFURLRef fileURL
, CFURLBookmarkFileCreationOptions options
, CFErrorRef
*errorRef
);
794 /*! @function CFURLCreateBookmarkDataFromAliasRecord
795 @discussion Create a CFDataRef containing bookmarkdata by converting the alias data in aliasRecordDataRef, which should be the contents of an AliasRecord copied into a CFDataRef object.
796 The created bookmarkdata can be passed into CFURLCreateByResolvingBookmarkData() to resolve the item into a CFURLRef, or a small set of information can be returned from
797 CFURLCreateResourcePropertiesForKeysFromBookmarkData() / CFURLCreateResourcePropertyForKeyFromBookmarkData().
798 @param allocator the CFAllocator to use to create this object
799 @param aliasRecordDataRef the contents of an AliasRecord to create bookmark data for
800 @result A CFDataRef containing an data, which can be later be passed to CFURLCreateByResolvingBookmarkData() or to CFURLCopyPropertiesForKeysFromBookmarkData() / CFURLCopyPropertyForKeyFromBookmarkData()
802 CFDataRef
CFURLCreateBookmarkDataFromAliasRecord ( CFAllocatorRef allocatorRef
, CFDataRef aliasRecordDataRef
);
804 #endif /* TARGET_OS_MAC */
808 #endif /* ! __COREFOUNDATION_CFURL__ */