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 string::{CFStringRef, CFStringEncoding};
14 use error::CFErrorRef;
15 
16 #[repr(C)]
17 pub struct __CFURL(c_void);
18 
19 pub type CFURLRef = *const __CFURL;
20 
21 pub type CFURLBookmarkCreationOptions = CFOptionFlags;
22 
23 pub type CFURLPathStyle = CFIndex;
24 
25 /* typedef CF_ENUM(CFIndex, CFURLPathStyle) */
26 pub const kCFURLPOSIXPathStyle: CFURLPathStyle   = 0;
27 pub const kCFURLHFSPathStyle: CFURLPathStyle     = 1;
28 pub const kCFURLWindowsPathStyle: CFURLPathStyle = 2;
29 
30 // static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions =
31 //     (1 << 8) as u32;
32 // static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions =
33 //     (1 << 9) as u32;
34 // static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions =
35 //     (1 << 10) as u32;
36 // static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions =
37 //     (1 << 11) as u32;
38 // static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions =
39 //     (1 << 12) as u32;
40 
41 // TODO: there are a lot of missing keys and constants. Add if you are bored or need them.
42 
43 extern {
44     /*
45      * CFURL.h
46      */
47 
48     /* Common File System Resource Keys */
49     pub static kCFURLAttributeModificationDateKey: CFStringRef;
50     pub static kCFURLContentAccessDateKey: CFStringRef;
51     pub static kCFURLContentModificationDateKey: CFStringRef;
52     pub static kCFURLCreationDateKey: CFStringRef;
53     pub static kCFURLFileResourceIdentifierKey: CFStringRef;
54     pub static kCFURLFileSecurityKey: CFStringRef;
55     pub static kCFURLHasHiddenExtensionKey: CFStringRef;
56     pub static kCFURLIsDirectoryKey: CFStringRef;
57     pub static kCFURLIsExecutableKey: CFStringRef;
58     pub static kCFURLIsHiddenKey: CFStringRef;
59     pub static kCFURLIsPackageKey: CFStringRef;
60     pub static kCFURLIsReadableKey: CFStringRef;
61     pub static kCFURLIsRegularFileKey: CFStringRef;
62     pub static kCFURLIsSymbolicLinkKey: CFStringRef;
63     pub static kCFURLIsSystemImmutableKey: CFStringRef;
64     pub static kCFURLIsUserImmutableKey: CFStringRef;
65     pub static kCFURLIsVolumeKey: CFStringRef;
66     pub static kCFURLIsWritableKey: CFStringRef;
67     pub static kCFURLLabelNumberKey: CFStringRef;
68     pub static kCFURLLinkCountKey: CFStringRef;
69     pub static kCFURLLocalizedLabelKey: CFStringRef;
70     pub static kCFURLLocalizedNameKey: CFStringRef;
71     pub static kCFURLLocalizedTypeDescriptionKey: CFStringRef;
72     pub static kCFURLNameKey: CFStringRef;
73     pub static kCFURLParentDirectoryURLKey: CFStringRef;
74     pub static kCFURLPreferredIOBlockSizeKey: CFStringRef;
75     pub static kCFURLTypeIdentifierKey: CFStringRef;
76     pub static kCFURLVolumeIdentifierKey: CFStringRef;
77     pub static kCFURLVolumeURLKey: CFStringRef;
78 
79     #[cfg(feature="mac_os_10_8_features")]
80     #[cfg_attr(feature = "mac_os_10_7_support", linkage = "extern_weak")]
81     pub static kCFURLIsExcludedFromBackupKey: CFStringRef;
82     pub static kCFURLFileResourceTypeKey: CFStringRef;
83 
84     /* Creating a CFURL */
CFURLCopyAbsoluteURL(anURL: CFURLRef) -> CFURLRef85     pub fn CFURLCopyAbsoluteURL(anURL: CFURLRef) -> CFURLRef;
86     //fn CFURLCreateAbsoluteURLWithBytes
87     //fn CFURLCreateByResolvingBookmarkData
88     //fn CFURLCreateCopyAppendingPathComponent
89     //fn CFURLCreateCopyAppendingPathExtension
90     //fn CFURLCreateCopyDeletingLastPathComponent
91     //fn CFURLCreateCopyDeletingPathExtension
CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef) -> CFURLRef92     pub fn CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef) -> CFURLRef;
93     //fn CFURLCreateFileReferenceURL
CFURLCreateFromFileSystemRepresentation(allocator: CFAllocatorRef, buffer: *const u8, bufLen: CFIndex, isDirectory: Boolean) -> CFURLRef94     pub fn CFURLCreateFromFileSystemRepresentation(allocator: CFAllocatorRef, buffer: *const u8, bufLen: CFIndex, isDirectory: Boolean) -> CFURLRef;
95     //fn CFURLCreateFromFileSystemRepresentationRelativeToBase
96     //fn CFURLCreateFromFSRef
CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef) -> CFURLRef97     pub fn CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef) -> CFURLRef;
CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef98     pub fn CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef;
CFURLCreateWithFileSystemPathRelativeToBase(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean, baseURL: CFURLRef) -> CFURLRef99     pub fn CFURLCreateWithFileSystemPathRelativeToBase(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean, baseURL: CFURLRef) -> CFURLRef;
100     //fn CFURLCreateWithString(allocator: CFAllocatorRef, urlString: CFStringRef,
101     //                         baseURL: CFURLRef) -> CFURLRef;
102 
103     /* Accessing the Parts of a URL */
CFURLCanBeDecomposed(anURL: CFURLRef) -> Boolean104     pub fn CFURLCanBeDecomposed(anURL: CFURLRef) -> Boolean;
CFURLCopyFileSystemPath(anURL: CFURLRef, pathStyle: CFURLPathStyle) -> CFStringRef105     pub fn CFURLCopyFileSystemPath(anURL: CFURLRef, pathStyle: CFURLPathStyle) -> CFStringRef;
CFURLCopyFragment(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef106     pub fn CFURLCopyFragment(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef;
CFURLCopyHostName(anURL: CFURLRef) -> CFStringRef107     pub fn CFURLCopyHostName(anURL: CFURLRef) -> CFStringRef;
CFURLCopyLastPathComponent(anURL: CFURLRef) -> CFStringRef108     pub fn CFURLCopyLastPathComponent(anURL: CFURLRef) -> CFStringRef;
CFURLCopyNetLocation(anURL: CFURLRef) -> CFStringRef109     pub fn CFURLCopyNetLocation(anURL: CFURLRef) -> CFStringRef;
CFURLCopyParameterString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef110     pub fn CFURLCopyParameterString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef;
CFURLCopyPassword(anURL: CFURLRef) -> CFStringRef111     pub fn CFURLCopyPassword(anURL: CFURLRef) -> CFStringRef;
CFURLCopyPath(anURL: CFURLRef) -> CFStringRef112     pub fn CFURLCopyPath(anURL: CFURLRef) -> CFStringRef;
CFURLCopyPathExtension(anURL: CFURLRef) -> CFStringRef113     pub fn CFURLCopyPathExtension(anURL: CFURLRef) -> CFStringRef;
CFURLCopyQueryString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef114     pub fn CFURLCopyQueryString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef;
CFURLCopyResourceSpecifier(anURL: CFURLRef) -> CFStringRef115     pub fn CFURLCopyResourceSpecifier(anURL: CFURLRef) -> CFStringRef;
CFURLCopyScheme(anURL: CFURLRef) -> CFStringRef116     pub fn CFURLCopyScheme(anURL: CFURLRef) -> CFStringRef;
CFURLCopyStrictPath(anURL: CFURLRef, isAbsolute: *mut Boolean) -> CFStringRef117     pub fn CFURLCopyStrictPath(anURL: CFURLRef, isAbsolute: *mut Boolean) -> CFStringRef;
CFURLCopyUserName(anURL: CFURLRef) -> CFStringRef118     pub fn CFURLCopyUserName(anURL: CFURLRef) -> CFStringRef;
CFURLGetPortNumber(anURL: CFURLRef) -> SInt32119     pub fn CFURLGetPortNumber(anURL: CFURLRef) -> SInt32;
CFURLHasDirectoryPath(anURL: CFURLRef) -> Boolean120     pub fn CFURLHasDirectoryPath(anURL: CFURLRef) -> Boolean;
121 
122     /* Converting URLs to Other Representations */
123     //fn CFURLCreateData(allocator: CFAllocatorRef, url: CFURLRef,
124     //                   encoding: CFStringEncoding, escapeWhitespace: bool) -> CFDataRef;
125     //fn CFURLCreateStringByAddingPercentEscapes
126     //fn CFURLCreateStringByReplacingPercentEscapes
127     //fn CFURLCreateStringByReplacingPercentEscapesUsingEncoding
CFURLGetFileSystemRepresentation(anURL: CFURLRef, resolveAgainstBase: Boolean, buffer: *mut u8, maxBufLen: CFIndex) -> Boolean128     pub fn CFURLGetFileSystemRepresentation(anURL: CFURLRef, resolveAgainstBase: Boolean, buffer: *mut u8, maxBufLen: CFIndex) -> Boolean;
129 
130     //fn CFURLGetFSRef
CFURLGetString(anURL: CFURLRef) -> CFStringRef131     pub fn CFURLGetString(anURL: CFURLRef) -> CFStringRef;
132 
133     /* Getting URL Properties */
134     //fn CFURLGetBaseURL(anURL: CFURLRef) -> CFURLRef;
CFURLGetBytes(anURL: CFURLRef, buffer: *mut u8, bufferLength: CFIndex) -> CFIndex135     pub fn CFURLGetBytes(anURL: CFURLRef, buffer: *mut u8, bufferLength: CFIndex) -> CFIndex;
136     //fn CFURLGetByteRangeForComponent
CFURLGetTypeID() -> CFTypeID137     pub fn CFURLGetTypeID() -> CFTypeID;
138     //fn CFURLResourceIsReachable
139 
140     /* Getting and Setting File System Resource Properties */
CFURLClearResourcePropertyCache(url: CFURLRef)141     pub fn CFURLClearResourcePropertyCache(url: CFURLRef);
142     //fn CFURLClearResourcePropertyCacheForKey
143     //fn CFURLCopyResourcePropertiesForKeys
144     //fn CFURLCopyResourcePropertyForKey
145     //fn CFURLCreateResourcePropertiesForKeysFromBookmarkData
146     //fn CFURLCreateResourcePropertyForKeyFromBookmarkData
147     //fn CFURLSetResourcePropertiesForKeys
CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean148     pub fn CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean;
149     //fn CFURLSetTemporaryResourcePropertyForKey
150 
151     /* Working with Bookmark Data */
152     //fn CFURLCreateBookmarkData
153     //fn CFURLCreateBookmarkDataFromAliasRecord
154     //fn CFURLCreateBookmarkDataFromFile
155     //fn CFURLWriteBookmarkDataToFile
156     //fn CFURLStartAccessingSecurityScopedResource
157     //fn CFURLStopAccessingSecurityScopedResource
158 }
159 
160 #[test]
161 #[cfg(feature="mac_os_10_8_features")]
can_see_excluded_from_backup_key()162 fn can_see_excluded_from_backup_key() {
163     let _ = unsafe { kCFURLIsExcludedFromBackupKey };
164 }
165