1 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 use std::os::raw::c_void;
11 
12 use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID, CFTypeRef, SInt32};
13 use data::CFDataRef;
14 use array::CFArrayRef;
15 use dictionary::CFDictionaryRef;
16 use string::{CFStringRef, CFStringEncoding};
17 use error::CFErrorRef;
18 
19 #[repr(C)]
20 pub struct __CFURL(c_void);
21 
22 pub type CFURLRef = *const __CFURL;
23 
24 pub type CFURLBookmarkCreationOptions = CFOptionFlags;
25 pub type CFURLBookmarkResolutionOptions = CFOptionFlags;
26 pub type CFURLBookmarkFileCreationOptions = CFOptionFlags;
27 
28 pub type CFURLPathStyle = CFIndex;
29 
30 /* typedef CF_ENUM(CFIndex, CFURLPathStyle) */
31 pub const kCFURLPOSIXPathStyle: CFURLPathStyle   = 0;
32 pub const kCFURLHFSPathStyle: CFURLPathStyle     = 1;
33 pub const kCFURLWindowsPathStyle: CFURLPathStyle = 2;
34 
35 pub static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions =
36     (1u32 << 8) as usize;
37 pub static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions =
38     (1u32 << 9) as usize;
39 pub static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions =
40     (1u32 << 10) as usize;
41 pub static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions =
42     (1u32 << 11) as usize;
43 pub static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions =
44     (1u32 << 12) as usize;
45 
46 // TODO: there are a lot of missing keys and constants. Add if you are bored or need them.
47 
48 extern {
49     /*
50      * CFURL.h
51      */
52 
53     /* Common File System Resource Keys */
54     pub static kCFURLAttributeModificationDateKey: CFStringRef;
55     pub static kCFURLContentAccessDateKey: CFStringRef;
56     pub static kCFURLContentModificationDateKey: CFStringRef;
57     pub static kCFURLCreationDateKey: CFStringRef;
58     pub static kCFURLFileResourceIdentifierKey: CFStringRef;
59     pub static kCFURLFileSecurityKey: CFStringRef;
60     pub static kCFURLHasHiddenExtensionKey: CFStringRef;
61     pub static kCFURLIsDirectoryKey: CFStringRef;
62     pub static kCFURLIsExecutableKey: CFStringRef;
63     pub static kCFURLIsHiddenKey: CFStringRef;
64     pub static kCFURLIsPackageKey: CFStringRef;
65     pub static kCFURLIsReadableKey: CFStringRef;
66     pub static kCFURLIsRegularFileKey: CFStringRef;
67     pub static kCFURLIsSymbolicLinkKey: CFStringRef;
68     pub static kCFURLIsSystemImmutableKey: CFStringRef;
69     pub static kCFURLIsUserImmutableKey: CFStringRef;
70     pub static kCFURLIsVolumeKey: CFStringRef;
71     pub static kCFURLIsWritableKey: CFStringRef;
72     pub static kCFURLLabelNumberKey: CFStringRef;
73     pub static kCFURLLinkCountKey: CFStringRef;
74     pub static kCFURLLocalizedLabelKey: CFStringRef;
75     pub static kCFURLLocalizedNameKey: CFStringRef;
76     pub static kCFURLLocalizedTypeDescriptionKey: CFStringRef;
77     pub static kCFURLNameKey: CFStringRef;
78     pub static kCFURLParentDirectoryURLKey: CFStringRef;
79     pub static kCFURLPreferredIOBlockSizeKey: CFStringRef;
80     pub static kCFURLTypeIdentifierKey: CFStringRef;
81     pub static kCFURLVolumeIdentifierKey: CFStringRef;
82     pub static kCFURLVolumeURLKey: CFStringRef;
83 
84     #[cfg(feature="mac_os_10_8_features")]
85     #[cfg_attr(feature = "mac_os_10_7_support", linkage = "extern_weak")]
86     pub static kCFURLIsExcludedFromBackupKey: CFStringRef;
87     pub static kCFURLFileResourceTypeKey: CFStringRef;
88 
89     /* Creating a CFURL */
CFURLCopyAbsoluteURL(anURL: CFURLRef) -> CFURLRef90     pub fn CFURLCopyAbsoluteURL(anURL: CFURLRef) -> CFURLRef;
CFURLCreateAbsoluteURLWithBytes(allocator: CFAllocatorRef, relativeURLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef, useCompatibilityMode: Boolean) -> CFURLRef91     pub fn CFURLCreateAbsoluteURLWithBytes(allocator: CFAllocatorRef, relativeURLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef, useCompatibilityMode: Boolean) -> CFURLRef;
CFURLCreateByResolvingBookmarkData(allocator: CFAllocatorRef, bookmark: CFDataRef, options: CFURLBookmarkResolutionOptions, relativeToURL: CFURLRef, resourcePropertiesToInclude: CFArrayRef, isStale: *mut Boolean, error: *mut CFErrorRef) -> CFURLRef92     pub fn CFURLCreateByResolvingBookmarkData(allocator: CFAllocatorRef, bookmark: CFDataRef, options: CFURLBookmarkResolutionOptions, relativeToURL: CFURLRef, resourcePropertiesToInclude: CFArrayRef, isStale: *mut Boolean, error: *mut CFErrorRef) -> CFURLRef;
93     //fn CFURLCreateCopyAppendingPathComponent
94     //fn CFURLCreateCopyAppendingPathExtension
95     //fn CFURLCreateCopyDeletingLastPathComponent
96     //fn CFURLCreateCopyDeletingPathExtension
CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef) -> CFURLRef97     pub fn CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef) -> CFURLRef;
98     //fn CFURLCreateFileReferenceURL
CFURLCreateFromFileSystemRepresentation(allocator: CFAllocatorRef, buffer: *const u8, bufLen: CFIndex, isDirectory: Boolean) -> CFURLRef99     pub fn CFURLCreateFromFileSystemRepresentation(allocator: CFAllocatorRef, buffer: *const u8, bufLen: CFIndex, isDirectory: Boolean) -> CFURLRef;
100     //fn CFURLCreateFromFileSystemRepresentationRelativeToBase
101     //fn CFURLCreateFromFSRef
CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef) -> CFURLRef102     pub fn CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef) -> CFURLRef;
CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef103     pub fn CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef;
CFURLCreateWithFileSystemPathRelativeToBase(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean, baseURL: CFURLRef) -> CFURLRef104     pub fn CFURLCreateWithFileSystemPathRelativeToBase(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean, baseURL: CFURLRef) -> CFURLRef;
105     //fn CFURLCreateWithString(allocator: CFAllocatorRef, urlString: CFStringRef,
106     //                         baseURL: CFURLRef) -> CFURLRef;
107 
108     /* Accessing the Parts of a URL */
CFURLCanBeDecomposed(anURL: CFURLRef) -> Boolean109     pub fn CFURLCanBeDecomposed(anURL: CFURLRef) -> Boolean;
CFURLCopyFileSystemPath(anURL: CFURLRef, pathStyle: CFURLPathStyle) -> CFStringRef110     pub fn CFURLCopyFileSystemPath(anURL: CFURLRef, pathStyle: CFURLPathStyle) -> CFStringRef;
CFURLCopyFragment(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef111     pub fn CFURLCopyFragment(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef;
CFURLCopyHostName(anURL: CFURLRef) -> CFStringRef112     pub fn CFURLCopyHostName(anURL: CFURLRef) -> CFStringRef;
CFURLCopyLastPathComponent(anURL: CFURLRef) -> CFStringRef113     pub fn CFURLCopyLastPathComponent(anURL: CFURLRef) -> CFStringRef;
CFURLCopyNetLocation(anURL: CFURLRef) -> CFStringRef114     pub fn CFURLCopyNetLocation(anURL: CFURLRef) -> CFStringRef;
CFURLCopyParameterString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef115     pub fn CFURLCopyParameterString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef;
CFURLCopyPassword(anURL: CFURLRef) -> CFStringRef116     pub fn CFURLCopyPassword(anURL: CFURLRef) -> CFStringRef;
CFURLCopyPath(anURL: CFURLRef) -> CFStringRef117     pub fn CFURLCopyPath(anURL: CFURLRef) -> CFStringRef;
CFURLCopyPathExtension(anURL: CFURLRef) -> CFStringRef118     pub fn CFURLCopyPathExtension(anURL: CFURLRef) -> CFStringRef;
CFURLCopyQueryString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef119     pub fn CFURLCopyQueryString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef;
CFURLCopyResourceSpecifier(anURL: CFURLRef) -> CFStringRef120     pub fn CFURLCopyResourceSpecifier(anURL: CFURLRef) -> CFStringRef;
CFURLCopyScheme(anURL: CFURLRef) -> CFStringRef121     pub fn CFURLCopyScheme(anURL: CFURLRef) -> CFStringRef;
CFURLCopyStrictPath(anURL: CFURLRef, isAbsolute: *mut Boolean) -> CFStringRef122     pub fn CFURLCopyStrictPath(anURL: CFURLRef, isAbsolute: *mut Boolean) -> CFStringRef;
CFURLCopyUserName(anURL: CFURLRef) -> CFStringRef123     pub fn CFURLCopyUserName(anURL: CFURLRef) -> CFStringRef;
CFURLGetPortNumber(anURL: CFURLRef) -> SInt32124     pub fn CFURLGetPortNumber(anURL: CFURLRef) -> SInt32;
CFURLHasDirectoryPath(anURL: CFURLRef) -> Boolean125     pub fn CFURLHasDirectoryPath(anURL: CFURLRef) -> Boolean;
126 
127     /* Converting URLs to Other Representations */
128     //fn CFURLCreateData(allocator: CFAllocatorRef, url: CFURLRef,
129     //                   encoding: CFStringEncoding, escapeWhitespace: bool) -> CFDataRef;
130     //fn CFURLCreateStringByAddingPercentEscapes
131     //fn CFURLCreateStringByReplacingPercentEscapes
132     //fn CFURLCreateStringByReplacingPercentEscapesUsingEncoding
CFURLGetFileSystemRepresentation(anURL: CFURLRef, resolveAgainstBase: Boolean, buffer: *mut u8, maxBufLen: CFIndex) -> Boolean133     pub fn CFURLGetFileSystemRepresentation(anURL: CFURLRef, resolveAgainstBase: Boolean, buffer: *mut u8, maxBufLen: CFIndex) -> Boolean;
134 
135     //fn CFURLGetFSRef
CFURLGetString(anURL: CFURLRef) -> CFStringRef136     pub fn CFURLGetString(anURL: CFURLRef) -> CFStringRef;
137 
138     /* Getting URL Properties */
139     //fn CFURLGetBaseURL(anURL: CFURLRef) -> CFURLRef;
CFURLGetBytes(anURL: CFURLRef, buffer: *mut u8, bufferLength: CFIndex) -> CFIndex140     pub fn CFURLGetBytes(anURL: CFURLRef, buffer: *mut u8, bufferLength: CFIndex) -> CFIndex;
141     //fn CFURLGetByteRangeForComponent
CFURLGetTypeID() -> CFTypeID142     pub fn CFURLGetTypeID() -> CFTypeID;
143     //fn CFURLResourceIsReachable
144 
145     /* Getting and Setting File System Resource Properties */
CFURLClearResourcePropertyCache(url: CFURLRef)146     pub fn CFURLClearResourcePropertyCache(url: CFURLRef);
147     //fn CFURLClearResourcePropertyCacheForKey
148     //fn CFURLCopyResourcePropertiesForKeys
149     //fn CFURLCopyResourcePropertyForKey
CFURLCreateResourcePropertiesForKeysFromBookmarkData(allocator: CFAllocatorRef, resourcePropertiesToReturn: CFArrayRef, bookmark: CFDataRef) -> CFDictionaryRef150     pub fn CFURLCreateResourcePropertiesForKeysFromBookmarkData(allocator: CFAllocatorRef, resourcePropertiesToReturn: CFArrayRef, bookmark: CFDataRef) -> CFDictionaryRef;
CFURLCreateResourcePropertyForKeyFromBookmarkData(allocator: CFAllocatorRef, resourcePropertyKey: CFStringRef, bookmark: CFDataRef) -> CFTypeRef151     pub fn CFURLCreateResourcePropertyForKeyFromBookmarkData(allocator: CFAllocatorRef, resourcePropertyKey: CFStringRef, bookmark: CFDataRef) -> CFTypeRef;
152     //fn CFURLSetResourcePropertiesForKeys
CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean153     pub fn CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean;
154     //fn CFURLSetTemporaryResourcePropertyForKey
155 
156     /* Working with Bookmark Data */
CFURLCreateBookmarkData(allocator: CFAllocatorRef, url: CFURLRef, options: CFURLBookmarkCreationOptions, resourcePropertiesToInclude: CFArrayRef, relativeToURL: CFURLRef, error: *mut CFErrorRef) -> CFDataRef157     pub fn CFURLCreateBookmarkData(allocator: CFAllocatorRef, url: CFURLRef, options: CFURLBookmarkCreationOptions, resourcePropertiesToInclude: CFArrayRef, relativeToURL: CFURLRef, error: *mut CFErrorRef) -> CFDataRef;
CFURLCreateBookmarkDataFromAliasRecord(allocator: CFAllocatorRef, aliasRecordDataRef: CFDataRef) -> CFDataRef158     pub fn CFURLCreateBookmarkDataFromAliasRecord(allocator: CFAllocatorRef, aliasRecordDataRef: CFDataRef) -> CFDataRef;
CFURLCreateBookmarkDataFromFile(allocator: CFAllocatorRef, fileURL: CFURLRef, errorRef: *mut CFErrorRef) -> CFDataRef159     pub fn CFURLCreateBookmarkDataFromFile(allocator: CFAllocatorRef, fileURL: CFURLRef, errorRef: *mut CFErrorRef) -> CFDataRef;
CFURLWriteBookmarkDataToFile(bookmarkRef: CFDataRef, fileURL: CFURLRef, options: CFURLBookmarkFileCreationOptions, errorRef: *mut CFErrorRef) -> Boolean160     pub fn CFURLWriteBookmarkDataToFile(bookmarkRef: CFDataRef, fileURL: CFURLRef, options: CFURLBookmarkFileCreationOptions, errorRef: *mut CFErrorRef) -> Boolean;
CFURLStartAccessingSecurityScopedResource(url: CFURLRef) -> Boolean161     pub fn CFURLStartAccessingSecurityScopedResource(url: CFURLRef) -> Boolean;
CFURLStopAccessingSecurityScopedResource(url: CFURLRef)162     pub fn CFURLStopAccessingSecurityScopedResource(url: CFURLRef);
163 }
164 
165 #[test]
166 #[cfg(feature="mac_os_10_8_features")]
can_see_excluded_from_backup_key()167 fn can_see_excluded_from_backup_key() {
168     let _ = unsafe { kCFURLIsExcludedFromBackupKey };
169 }
170