]> git.saurik.com Git - apple/cf.git/blame - CFURL.h
CF-550.43.tar.gz
[apple/cf.git] / CFURL.h
CommitLineData
9ce05555 1/*
e588f561 2 * Copyright (c) 2010 Apple Inc. All rights reserved.
9ce05555
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
9ce05555
A
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 */
f64f9b69 23
9ce05555 24/* CFURL.h
cf7d2af9 25 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
9ce05555
A
26*/
27
28#if !defined(__COREFOUNDATION_CFURL__)
29#define __COREFOUNDATION_CFURL__ 1
30
31#include <CoreFoundation/CFBase.h>
32#include <CoreFoundation/CFData.h>
cf7d2af9 33#include <CoreFoundation/CFError.h>
9ce05555
A
34#include <CoreFoundation/CFString.h>
35
bd5b749c 36CF_EXTERN_C_BEGIN
9ce05555 37
bd5b749c 38enum {
9ce05555
A
39 kCFURLPOSIXPathStyle = 0,
40 kCFURLHFSPathStyle,
41 kCFURLWindowsPathStyle
bd5b749c
A
42};
43typedef CFIndex CFURLPathStyle;
9ce05555
A
44
45typedef const struct __CFURL * CFURLRef;
46
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. */
60
61CF_EXPORT
62CFTypeID CFURLGetTypeID(void);
63
64/* encoding will be used both to interpret the bytes of URLBytes, and to */
65/* interpret any percent-escapes within the bytes. */
66CF_EXPORT
67CFURLRef CFURLCreateWithBytes(CFAllocatorRef allocator, const UInt8 *URLBytes, CFIndex length, CFStringEncoding encoding, CFURLRef baseURL);
68
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) */
73CF_EXPORT
74CFDataRef CFURLCreateData(CFAllocatorRef allocator, CFURLRef url, CFStringEncoding encoding, Boolean escapeWhitespace);
75
76/* Any escape sequences in URLString will be interpreted via UTF-8. */
77CF_EXPORT
78CFURLRef CFURLCreateWithString(CFAllocatorRef allocator, CFStringRef URLString, CFURLRef baseURL);
79
80#if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED
81
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 */
d8925383 93CF_EXPORT
9ce05555
A
94CFURLRef CFURLCreateAbsoluteURLWithBytes(CFAllocatorRef alloc, const UInt8 *relativeURLBytes, CFIndex length, CFStringEncoding encoding, CFURLRef baseURL, Boolean useCompatibilityMode) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
95#endif
96
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 */
102/* components */
103CF_EXPORT
104CFURLRef CFURLCreateWithFileSystemPath(CFAllocatorRef allocator, CFStringRef filePath, CFURLPathStyle pathStyle, Boolean isDirectory);
105
106CF_EXPORT
107CFURLRef CFURLCreateFromFileSystemRepresentation(CFAllocatorRef allocator, const UInt8 *buffer, CFIndex bufLen, Boolean isDirectory);
108
cf7d2af9
A
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 */
114/* is ignored. */
9ce05555
A
115CF_EXPORT
116CFURLRef CFURLCreateWithFileSystemPathRelativeToBase(CFAllocatorRef allocator, CFStringRef filePath, CFURLPathStyle pathStyle, Boolean isDirectory, CFURLRef baseURL);
117
118CF_EXPORT
119CFURLRef CFURLCreateFromFileSystemRepresentationRelativeToBase(CFAllocatorRef allocator, const UInt8 *buffer, CFIndex bufLen, Boolean isDirectory, CFURLRef baseURL);
120
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. */
128CF_EXPORT
129Boolean CFURLGetFileSystemRepresentation(CFURLRef url, Boolean resolveAgainstBase, UInt8 *buffer, CFIndex maxBufLen);
130
131/* Creates a new URL by resolving the relative portion of relativeURL against its base. */
132CF_EXPORT
133CFURLRef CFURLCopyAbsoluteURL(CFURLRef relativeURL);
134
135/* Returns the URL's string. */
136CF_EXPORT
137CFStringRef CFURLGetString(CFURLRef anURL);
138
139/* Returns the base URL if it exists */
140CF_EXPORT
141CFURLRef CFURLGetBaseURL(CFURLRef anURL);
142
143/*
144All URLs can be broken into two pieces - the scheme (preceding the
145first colon) and the resource specifier (following the first colon).
146Most URLs are also "standard" URLs conforming to RFC 1808 (available
147from www.w3c.org). This category includes URLs of the file, http,
148https, and ftp schemes, to name a few. Standard URLs start the
149resource specifier with two slashes ("//"), and can be broken into
150four distinct pieces - the scheme, the net location, the path, and
151further resource specifiers (typically an optional parameter, query,
152and/or fragment). The net location appears immediately following
153the two slashes and goes up to the next slash; it's format is
154scheme-specific, but is usually composed of some or all of a username,
155password, host name, and port. The path is a series of path components
156separated by slashes; if the net location is present, the path always
157begins with a slash. Standard URLs can be relative to another URL,
158in which case at least the scheme and possibly other pieces as well
159come from the base URL (see RFC 1808 for precise details when resolving
160a relative URL against its base). The full URL is therefore
161
162<scheme> "://" <net location> <path, always starting with slash> <add'l resource specifiers>
163
164If a given CFURL can be decomposed (that is, conforms to RFC 1808), you
165can ask for each of the four basic pieces (scheme, net location, path,
166and resource specifer) separately, as well as for its base URL. The
167basic pieces are returned with any percent escape sequences still in
168place (although note that the scheme may not legally include any
169percent escapes); this is to allow the caller to distinguish between
170percent sequences that may have syntactic meaning if replaced by the
171character being escaped (for instance, a '/' in a path component).
172Since only the individual schemes know which characters are
173syntactically significant, CFURL cannot safely replace any percent
174escape sequences. However, you can use
175CFURLCreateStringByReplacingPercentEscapes() to create a new string with
176the percent escapes removed; see below.
177
178If a given CFURL can not be decomposed, you can ask for its scheme and its
179resource specifier; asking it for its net location or path will return NULL.
180
181To get more refined information about the components of a decomposable
182CFURL, you may ask for more specific pieces of the URL, expressed with
183the percent escapes removed. The available functions are CFURLCopyHostName(),
184CFURLGetPortNumber() (returns an Int32), CFURLCopyUserName(),
185CFURLCopyPassword(), CFURLCopyQuery(), CFURLCopyParameters(), and
186CFURLCopyFragment(). Because the parameters, query, and fragment of an
187URL may contain scheme-specific syntaxes, these methods take a second
188argument, giving a list of characters which should NOT be replaced if
189percent escaped. For instance, the ftp parameter syntax gives simple
190key-value pairs as "<key>=<value>;" Clearly if a key or value includes
191either '=' or ';', it must be escaped to avoid corrupting the meaning of
192the parameters, so the caller may request the parameter string as
193
194CFStringRef myParams = CFURLCopyParameters(ftpURL, CFSTR("=;%"));
195
196requesting that all percent escape sequences be replaced by the represented
197characters, except for escaped '=', '%' or ';' characters. Pass the empty
198string (CFSTR("")) to request that all percent escapes be replaced, or NULL
199to request that none be.
200*/
201
202/* Returns true if anURL conforms to RFC 1808 */
203CF_EXPORT
204Boolean CFURLCanBeDecomposed(CFURLRef anURL);
205
206/* The next several methods leave any percent escape sequences intact */
207
208CF_EXPORT
209CFStringRef CFURLCopyScheme(CFURLRef anURL);
210
211/* NULL if CFURLCanBeDecomposed(anURL) is false */
212CF_EXPORT
213CFStringRef CFURLCopyNetLocation(CFURLRef anURL);
214
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. */
222
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. */
226CF_EXPORT
227CFStringRef CFURLCopyPath(CFURLRef anURL);
228
229CF_EXPORT
230CFStringRef CFURLCopyStrictPath(CFURLRef anURL, Boolean *isAbsolute);
231
232CF_EXPORT
233CFStringRef CFURLCopyFileSystemPath(CFURLRef anURL, CFURLPathStyle pathStyle);
234
235/* Returns whether anURL's path represents a directory */
236/* (true returned) or a simple file (false returned) */
237CF_EXPORT
238Boolean CFURLHasDirectoryPath(CFURLRef anURL);
239
240/* Any additional resource specifiers after the path. For URLs */
241/* that cannot be decomposed, this is everything except the scheme itself. */
242CF_EXPORT
243CFStringRef CFURLCopyResourceSpecifier(CFURLRef anURL);
244
245CF_EXPORT
246CFStringRef CFURLCopyHostName(CFURLRef anURL);
247
248CF_EXPORT
249SInt32 CFURLGetPortNumber(CFURLRef anURL); /* Returns -1 if no port number is specified */
250
251CF_EXPORT
252CFStringRef CFURLCopyUserName(CFURLRef anURL);
253
254CF_EXPORT
255CFStringRef CFURLCopyPassword(CFURLRef anURL);
256
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 */
262CF_EXPORT
263CFStringRef CFURLCopyParameterString(CFURLRef anURL, CFStringRef charactersToLeaveEscaped);
264
265CF_EXPORT
266CFStringRef CFURLCopyQueryString(CFURLRef anURL, CFStringRef charactersToLeaveEscaped);
267
268CF_EXPORT
269CFStringRef CFURLCopyFragment(CFURLRef anURL, CFStringRef charactersToLeaveEscaped);
270
271CF_EXPORT
272CFStringRef CFURLCopyLastPathComponent(CFURLRef url);
273
274CF_EXPORT
275CFStringRef CFURLCopyPathExtension(CFURLRef url);
276
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. */
280
281CF_EXPORT
282CFURLRef CFURLCreateCopyAppendingPathComponent(CFAllocatorRef allocator, CFURLRef url, CFStringRef pathComponent, Boolean isDirectory);
283
284CF_EXPORT
285CFURLRef CFURLCreateCopyDeletingLastPathComponent(CFAllocatorRef allocator, CFURLRef url);
286
287CF_EXPORT
288CFURLRef CFURLCreateCopyAppendingPathExtension(CFAllocatorRef allocator, CFURLRef url, CFStringRef extension);
289
290CF_EXPORT
291CFURLRef CFURLCreateCopyDeletingPathExtension(CFAllocatorRef allocator, CFURLRef url);
292
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 */
d8925383 300CF_EXPORT
9ce05555
A
301CFIndex CFURLGetBytes(CFURLRef url, UInt8 *buffer, CFIndex bufferLength) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
302
bd5b749c 303enum {
9ce05555
A
304 kCFURLComponentScheme = 1,
305 kCFURLComponentNetLocation = 2,
306 kCFURLComponentPath = 3,
307 kCFURLComponentResourceSpecifier = 4,
308
309 kCFURLComponentUser = 5,
310 kCFURLComponentPassword = 6,
311 kCFURLComponentUserInfo = 7,
312 kCFURLComponentHost = 8,
313 kCFURLComponentPort = 9,
314 kCFURLComponentParameterString = 10,
315 kCFURLComponentQuery = 11,
316 kCFURLComponentFragment = 12
bd5b749c
A
317};
318typedef CFIndex CFURLComponentType;
9ce05555
A
319
320/*
321Gets the range of the requested component in the bytes of url, as
322returned by CFURLGetBytes(). This range is only good for use in the
323bytes returned by CFURLGetBytes!
324
325If non-NULL, rangeIncludingSeparators gives the range of component
326including the sequences that separate component from the previous and
327next components. If there is no previous or next component, that end of
328rangeIncludingSeparators will match the range of the component itself.
329If url does not contain the given component type, (kCFNotFound, 0) is
330returned, and rangeIncludingSeparators is set to the location where the
331component would be inserted. Some examples -
332
333For the URL http://www.apple.com/hotnews/
334
335Component returned range rangeIncludingSeparators
336scheme (0, 4) (0, 7)
337net location (7, 13) (4, 16)
338path (20, 9) (20, 9)
339resource specifier (kCFNotFound, 0) (29, 0)
340user (kCFNotFound, 0) (7, 0)
341password (kCFNotFound, 0) (7, 0)
342user info (kCFNotFound, 0) (7, 0)
343host (7, 13) (4, 16)
344port (kCFNotFound, 0) (20, 0)
345parameter (kCFNotFound, 0) (29, 0)
346query (kCFNotFound, 0) (29, 0)
347fragment (kCFNotFound, 0) (29, 0)
348
349
350For the URL ./relPath/file.html#fragment
351
352Component returned range rangeIncludingSeparators
353scheme (kCFNotFound, 0) (0, 0)
354net location (kCFNotFound, 0) (0, 0)
355path (0, 19) (0, 20)
356resource specifier (20, 8) (19, 9)
357user (kCFNotFound, 0) (0, 0)
358password (kCFNotFound, 0) (0, 0)
359user info (kCFNotFound, 0) (0, 0)
360host (kCFNotFound, 0) (0, 0)
361port (kCFNotFound, 0) (0, 0)
362parameter (kCFNotFound, 0) (19, 0)
363query (kCFNotFound, 0) (19, 0)
364fragment (20, 8) (19, 9)
365
366
367For the URL scheme://user:pass@host:1/path/path2/file.html;params?query#fragment
368
369Component returned range rangeIncludingSeparators
370scheme (0, 6) (0, 9)
371net location (9, 16) (6, 19)
372path (25, 21) (25, 22)
373resource specifier (47, 21) (46, 22)
374user (9, 4) (6, 8)
375password (14, 4) (13, 6)
376user info (9, 9) (6, 13)
377host (19, 4) (18, 6)
378port (24, 1) (23, 2)
379parameter (47, 6) (46, 8)
380query (54, 5) (53, 7)
381fragment (60, 8) (59, 9)
382*/
d8925383 383CF_EXPORT
9ce05555
A
384CFRange CFURLGetByteRangeForComponent(CFURLRef url, CFURLComponentType component, CFRange *rangeIncludingSeparators) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
385#endif
386
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. */
394CF_EXPORT
395CFStringRef CFURLCreateStringByReplacingPercentEscapes(CFAllocatorRef allocator, CFStringRef originalString, CFStringRef charactersToLeaveEscaped);
396
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 */
399CF_EXPORT
400CFStringRef CFURLCreateStringByReplacingPercentEscapesUsingEncoding(CFAllocatorRef allocator, CFStringRef origString, CFStringRef charsToLeaveEscaped, CFStringEncoding encoding) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
401#endif
402
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: */
414
bd5b749c 415/* newString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, origString, NULL, NULL, kCFStringEncodingUTF8); */
9ce05555
A
416CF_EXPORT
417CFStringRef CFURLCreateStringByAddingPercentEscapes(CFAllocatorRef allocator, CFStringRef originalString, CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding);
418
419
cf7d2af9
A
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. */
425CF_EXPORT
426CFURLRef CFURLCreateFileReferenceURL(CFAllocatorRef allocator, CFURLRef url, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
427
428
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. */
434CF_EXPORT
435CFURLRef CFURLCreateFilePathURL(CFAllocatorRef allocator, CFURLRef url, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
436
437
438
439
440#if TARGET_OS_MAC
441
442/* The following APIs provide efficient access to resource properties. Properties
443are identified by keys, and values are represented as Core Foundation objects. The
444type of each value is fixed for each property, e.g. the modification date is a CFDateRef,
445the file size is a CFNumberRef.
446
447Values are fetched on-demand, synchronously, from the resource's backing store. They
448are cached and reused when fetched again through the same URL instance, until the
449client clears the value. The client has complete control over the cache lifetime.
450
451Some resource property values can be changed, given sufficient access permission to the resource.
452When a resource property value is set, the change is written to backing store synchronously.
453*/
454
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. */
462CF_EXPORT
463Boolean CFURLCopyResourcePropertyForKey(CFURLRef url, CFStringRef key, void *propertyValueTypeRefPtr, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
464
465
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. */
473CF_EXPORT
474CFDictionaryRef CFURLCopyResourcePropertiesForKeys(CFURLRef url, CFArrayRef keys, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
475
476
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. */
484CF_EXPORT
485Boolean CFURLSetResourcePropertyForKey(CFURLRef url, CFStringRef key, CFTypeRef propertValue, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
486
487
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. */
496CF_EXPORT
497Boolean CFURLSetResourcePropertiesForKeys(CFURLRef url, CFDictionaryRef keyedPropertyValues, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
498
499
500/* Discards a cached property value for a specific key */
501CF_EXPORT
502void CFURLClearResourcePropertyCacheForKey(CFURLRef url, CFStringRef key) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
503
504
505/* Discards all cached property values */
506CF_EXPORT
507void CFURLClearResourcePropertyCache(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
508
509
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. */
515CF_EXPORT
516void CFURLSetTemporaryResourcePropertyForKey(CFURLRef url, CFStringRef key, CFTypeRef propertyValue) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
517
518
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. */
528CF_EXPORT
529Boolean CFURLResourceIsReachable(CFURLRef url, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
530
531
532/* Properties of File System Resources */
533
534CF_EXPORT
535const CFStringRef kCFURLNameKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
536 /* The resource name provided by the file system (value type CFString) */
537
538CF_EXPORT
539const 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) */
541
542CF_EXPORT
543const CFStringRef kCFURLIsRegularFileKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
544 /* True for regular files (Read-only, value type CFBoolean) */
545
546CF_EXPORT
547const CFStringRef kCFURLIsDirectoryKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
548 /* True for directories (Read-only, CFBoolean) */
549
550CF_EXPORT
551const CFStringRef kCFURLIsSymbolicLinkKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
552 /* True for symlinks (Read-only, value type CFBoolean) */
553
554CF_EXPORT
555const 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) */
557
558CF_EXPORT
559const CFStringRef kCFURLIsPackageKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
560 /* True for packaged directories (value type CFBoolean) */
561
562CF_EXPORT
563const CFStringRef kCFURLIsSystemImmutableKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
564 /* True for system-immutable resources (value type CFBoolean) */
565
566CF_EXPORT
567const CFStringRef kCFURLIsUserImmutableKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
568 /* True for user-immutable resources (value type CFBoolean) */
569
570CF_EXPORT
571const CFStringRef kCFURLIsHiddenKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
572 /* True for resources normally hidden from users (value type CFBoolean) */
573
574CF_EXPORT
575const CFStringRef kCFURLHasHiddenExtensionKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
576 /* True for resources whose filename extension is hiden (value type CFBoolean) */
577
578CF_EXPORT
579const CFStringRef kCFURLCreationDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
580 /* Value type CFDate */
581
582CF_EXPORT
583const CFStringRef kCFURLContentAccessDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
584 /* Value type CFDate */
585
586CF_EXPORT
587const CFStringRef kCFURLContentModificationDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
588 /* Value type CFDate */
589
590CF_EXPORT
591const CFStringRef kCFURLAttributeModificationDateKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
592 /* Value type CFDate */
593
594CF_EXPORT
595const CFStringRef kCFURLLinkCountKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
596 /* Number of hard links to the resource (Read-only, CFNumber) */
597
598CF_EXPORT
599const CFStringRef kCFURLParentDirectoryURLKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
600 /* URL of the parent directory, if any (Read-only, value type CFURL) */
601
602CF_EXPORT
603const 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) */
605
606CF_EXPORT
607const CFStringRef kCFURLTypeIdentifierKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
608 /* Uniform type identifier for the resource (Read-only, value type CFString) */
609
610CF_EXPORT
611const CFStringRef kCFURLLocalizedTypeDescriptionKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
612 /* User-visible type or "kind" descriptiopn (Read-only, value type CFString) */
613
614CF_EXPORT
615const CFStringRef kCFURLLabelNumberKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
616 /* The label number assigned to the resource (value type CFNumber) */
617
618CF_EXPORT
619const 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) */
621
622CF_EXPORT
623const CFStringRef kCFURLLocalizedLabelKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
624 /* The user-visible label text (Read-only, value type CFString) */
625
626CF_EXPORT
627const 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) */
629
630CF_EXPORT
631const 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) */
633
634
635/* File Properties */
636
637CF_EXPORT
638const CFStringRef kCFURLFileSizeKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
639 /* Total file size, in bytes (Read-only, value type CFNumber) */
640
641CF_EXPORT
642const CFStringRef kCFURLFileAllocatedSizeKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
643 /* Total size of blocks allocated (Read-only, value type CFNumber) */
644
645CF_EXPORT
646const 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) */
648
649
650/* Volume Properties */
651
652/* For convenience, volume properties may be requested from any resource on a volume. */
653
654CF_EXPORT
655const CFStringRef kCFURLVolumeLocalizedFormatDescriptionKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
656 /* The user-visible volume format (Read-only, value type CFString) */
657
658CF_EXPORT
659const CFStringRef kCFURLVolumeTotalCapacityKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
660 /* Total volume capacity in bytes (Read-only, value type CFNumber) */
661
662CF_EXPORT
663const CFStringRef kCFURLVolumeAvailableCapacityKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
664 /* Total free space, in bytes (Read-only, value type CFNumber) */
665
666CF_EXPORT
667const CFStringRef kCFURLVolumeResourceCountKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
668 /* Total number of resources on the volume (Read-only, value type CFNumber) */
669
670CF_EXPORT
671const CFStringRef kCFURLVolumeSupportsPersistentIDsKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
672 /* Read-only, value type CFBoolean */
673
674CF_EXPORT
675const CFStringRef kCFURLVolumeSupportsSymbolicLinksKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
676 /* Read-only, value type CFBoolean */
677
678CF_EXPORT
679const CFStringRef kCFURLVolumeSupportsHardLinksKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
680 /* Read-only, value type CFBoolean */
681
682CF_EXPORT
683const CFStringRef kCFURLVolumeSupportsJournalingKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
684 /* Read-only, value type CFBoolean */
685
686CF_EXPORT
687const CFStringRef kCFURLVolumeIsJournalingKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
688 /* Read-only, value type CFBoolean */
689
690CF_EXPORT
691const CFStringRef kCFURLVolumeSupportsSparseFilesKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
692 /* Read-only, value type CFBoolean */
693
694CF_EXPORT
695const CFStringRef kCFURLVolumeSupportsZeroRunsKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
696 /* Read-only, value type CFBoolean */
697
698CF_EXPORT
699const CFStringRef kCFURLVolumeSupportsCaseSensitiveNamesKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
700 /* Read-only, value type CFBoolean */
701
702CF_EXPORT
703const CFStringRef kCFURLVolumeSupportsCasePreservedNamesKey AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
704 /* Read-only, value type CFBoolean */
705
706enum {
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
710};
711typedef CFOptionFlags CFURLBookmarkCreationOptions;
712
713enum {
714 kCFBookmarkResolutionWithoutUIMask = ( 1UL << 8 ), // don't perform any UI during bookmark resolution
715 kCFBookmarkResolutionWithoutMountingMask = ( 1UL << 9 ), // don't mount a volume during bookmark resolution
716};
717typedef CFOptionFlags CFURLBookmarkResolutionOptions;
718
719typedef CFOptionFlags CFURLBookmarkFileCreationOptions;
720
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() */
731CFDataRef CFURLCreateBookmarkData ( CFAllocatorRef allocator, CFURLRef url, CFURLBookmarkCreationOptions options, CFArrayRef resourcePropertiesToInclude, CFURLRef relativeToURL, CFErrorRef* error ) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
732
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 */
749CFURLRef CFURLCreateByResolvingBookmarkData ( CFAllocatorRef allocator, CFDataRef bookmark, CFURLBookmarkResolutionOptions options, CFURLRef relativeToURL, CFArrayRef resourcePropertiesToInclude, Boolean* isStale, CFErrorRef* error ) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
750
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 ) */
758CFDictionaryRef CFURLCreateResourcePropertiesForKeysFromBookmarkData ( CFAllocatorRef allocator, CFArrayRef resourcePropertiesToReturn, CFDataRef bookmark ) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
759
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 ) */
767CFTypeRef CFURLCreateResourcePropertyForKeyFromBookmarkData( CFAllocatorRef allocator, CFStringRef resourcePropertyKey, CFDataRef bookmark ) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
768
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.
778 */
779CFDataRef CFURLCreateBookmarkDataFromFile(CFAllocatorRef allocator, CFURLRef fileURL, CFErrorRef *errorRef );
780
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
791 */
792Boolean CFURLWriteBookmarkDataToFile( CFDataRef bookmarkRef, CFURLRef fileURL, CFURLBookmarkFileCreationOptions options, CFErrorRef *errorRef );
793
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()
801 */
802CFDataRef CFURLCreateBookmarkDataFromAliasRecord ( CFAllocatorRef allocatorRef, CFDataRef aliasRecordDataRef );
803
804#endif /* TARGET_OS_MAC */
805
bd5b749c 806CF_EXTERN_C_END
9ce05555 807
bd5b749c 808#endif /* ! __COREFOUNDATION_CFURL__ */
9ce05555 809