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 */ 90 pub fn CFURLCopyAbsoluteURL(anURL: CFURLRef) -> CFURLRef; 91 pub fn CFURLCreateAbsoluteURLWithBytes(allocator: CFAllocatorRef, relativeURLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef, useCompatibilityMode: Boolean) -> CFURLRef; 92 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 97 pub fn CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef) -> CFURLRef; 98 //fn CFURLCreateFileReferenceURL 99 pub fn CFURLCreateFromFileSystemRepresentation(allocator: CFAllocatorRef, buffer: *const u8, bufLen: CFIndex, isDirectory: Boolean) -> CFURLRef; 100 //fn CFURLCreateFromFileSystemRepresentationRelativeToBase 101 //fn CFURLCreateFromFSRef 102 pub fn CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef) -> CFURLRef; 103 pub fn CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef; 104 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 */ 109 pub fn CFURLCanBeDecomposed(anURL: CFURLRef) -> Boolean; 110 pub fn CFURLCopyFileSystemPath(anURL: CFURLRef, pathStyle: CFURLPathStyle) -> CFStringRef; 111 pub fn CFURLCopyFragment(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef; 112 pub fn CFURLCopyHostName(anURL: CFURLRef) -> CFStringRef; 113 pub fn CFURLCopyLastPathComponent(anURL: CFURLRef) -> CFStringRef; 114 pub fn CFURLCopyNetLocation(anURL: CFURLRef) -> CFStringRef; 115 pub fn CFURLCopyParameterString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef; 116 pub fn CFURLCopyPassword(anURL: CFURLRef) -> CFStringRef; 117 pub fn CFURLCopyPath(anURL: CFURLRef) -> CFStringRef; 118 pub fn CFURLCopyPathExtension(anURL: CFURLRef) -> CFStringRef; 119 pub fn CFURLCopyQueryString(anURL: CFURLRef, charactersToLeaveEscaped: CFStringRef) -> CFStringRef; 120 pub fn CFURLCopyResourceSpecifier(anURL: CFURLRef) -> CFStringRef; 121 pub fn CFURLCopyScheme(anURL: CFURLRef) -> CFStringRef; 122 pub fn CFURLCopyStrictPath(anURL: CFURLRef, isAbsolute: *mut Boolean) -> CFStringRef; 123 pub fn CFURLCopyUserName(anURL: CFURLRef) -> CFStringRef; 124 pub fn CFURLGetPortNumber(anURL: CFURLRef) -> SInt32; 125 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 133 pub fn CFURLGetFileSystemRepresentation(anURL: CFURLRef, resolveAgainstBase: Boolean, buffer: *mut u8, maxBufLen: CFIndex) -> Boolean; 134 135 //fn CFURLGetFSRef 136 pub fn CFURLGetString(anURL: CFURLRef) -> CFStringRef; 137 138 /* Getting URL Properties */ 139 //fn CFURLGetBaseURL(anURL: CFURLRef) -> CFURLRef; 140 pub fn CFURLGetBytes(anURL: CFURLRef, buffer: *mut u8, bufferLength: CFIndex) -> CFIndex; 141 //fn CFURLGetByteRangeForComponent 142 pub fn CFURLGetTypeID() -> CFTypeID; 143 //fn CFURLResourceIsReachable 144 145 /* Getting and Setting File System Resource Properties */ 146 pub fn CFURLClearResourcePropertyCache(url: CFURLRef); 147 //fn CFURLClearResourcePropertyCacheForKey 148 //fn CFURLCopyResourcePropertiesForKeys 149 //fn CFURLCopyResourcePropertyForKey 150 pub fn CFURLCreateResourcePropertiesForKeysFromBookmarkData(allocator: CFAllocatorRef, resourcePropertiesToReturn: CFArrayRef, bookmark: CFDataRef) -> CFDictionaryRef; 151 pub fn CFURLCreateResourcePropertyForKeyFromBookmarkData(allocator: CFAllocatorRef, resourcePropertyKey: CFStringRef, bookmark: CFDataRef) -> CFTypeRef; 152 //fn CFURLSetResourcePropertiesForKeys 153 pub fn CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean; 154 //fn CFURLSetTemporaryResourcePropertyForKey 155 156 /* Working with Bookmark Data */ 157 pub fn CFURLCreateBookmarkData(allocator: CFAllocatorRef, url: CFURLRef, options: CFURLBookmarkCreationOptions, resourcePropertiesToInclude: CFArrayRef, relativeToURL: CFURLRef, error: *mut CFErrorRef) -> CFDataRef; 158 pub fn CFURLCreateBookmarkDataFromAliasRecord(allocator: CFAllocatorRef, aliasRecordDataRef: CFDataRef) -> CFDataRef; 159 pub fn CFURLCreateBookmarkDataFromFile(allocator: CFAllocatorRef, fileURL: CFURLRef, errorRef: *mut CFErrorRef) -> CFDataRef; 160 pub fn CFURLWriteBookmarkDataToFile(bookmarkRef: CFDataRef, fileURL: CFURLRef, options: CFURLBookmarkFileCreationOptions, errorRef: *mut CFErrorRef) -> Boolean; 161 pub fn CFURLStartAccessingSecurityScopedResource(url: CFURLRef) -> Boolean; 162 pub fn CFURLStopAccessingSecurityScopedResource(url: CFURLRef); 163 } 164 165 #[test] 166 #[cfg(feature="mac_os_10_8_features")] 167 fn can_see_excluded_from_backup_key() { 168 let _ = unsafe { kCFURLIsExcludedFromBackupKey }; 169 } 170