Repository: servo/core-foundation-rs (language: rust)

Issue:
How to use Bookmark Data functions?
Hey there!

I'm interesting in using these functions (and other security-scoped bookmark functions) from a Rust library of mine. What needs to be done in terms of enabling these in this library?

https://github.com/servo/core-foundation-rs/blob/dc4599d8179c01c4a7e1fbcaf73f9ad39891f6d0/core-foundation-sys/src/url.rs#L149-L155


Discussion / hints:
It should be as simple as filling out the definitions. You should be able to mostly copy the existing style in that file.
As the question was answered and the original poster deleted their account I am assuming it’s fine to close this.

Fix patch:
diff --git a/core-foundation-sys/src/url.rs b/core-foundation-sys/src/url.rs
index 9c4bc3e4b..e5e699d5a 100644
--- a/core-foundation-sys/src/url.rs
+++ b/core-foundation-sys/src/url.rs
@@ -10,6 +10,9 @@
 use std::os::raw::c_void;
 
 use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID, CFTypeRef, SInt32};
+use data::CFDataRef;
+use array::CFArrayRef;
+use dictionary::CFDictionaryRef;
 use string::{CFStringRef, CFStringEncoding};
 use error::CFErrorRef;
 
@@ -19,6 +22,8 @@ pub struct __CFURL(c_void);
 pub type CFURLRef = *const __CFURL;
 
 pub type CFURLBookmarkCreationOptions = CFOptionFlags;
+pub type CFURLBookmarkResolutionOptions = CFOptionFlags;
+pub type CFURLBookmarkFileCreationOptions = CFOptionFlags;
 
 pub type CFURLPathStyle = CFIndex;
 
@@ -27,16 +32,16 @@ pub const kCFURLPOSIXPathStyle: CFURLPathStyle   = 0;
 pub const kCFURLHFSPathStyle: CFURLPathStyle     = 1;
 pub const kCFURLWindowsPathStyle: CFURLPathStyle = 2;
 
-// static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions =
-//     (1 << 8) as u32;
-// static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions =
-//     (1 << 9) as u32;
-// static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions =
-//     (1 << 10) as u32;
-// static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions =
-//     (1 << 11) as u32;
-// static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions =
-//     (1 << 12) as u32;
+pub static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions =
+    (1 << 8) as u32;
+pub static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions =
+    (1 << 9) as u32;
+pub static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions =
+    (1 << 10) as u32;
+pub static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions =
+    (1 << 11) as u32;
+pub static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions =
+    (1 << 12) as u32;
 
 // TODO: there are a lot of missing keys and constants. Add if you are bored or need them.
 
@@ -83,8 +88,8 @@ extern {
 
     /* Creating a CFURL */
     pub fn CFURLCopyAbsoluteURL(anURL: CFURLRef) -> CFURLRef;
-    //fn CFURLCreateAbsoluteURLWithBytes
-    //fn CFURLCreateByResolvingBookmarkData
+    pub fn CFURLCreateAbsoluteURLWithBytes(allocator: CFAllocatorRef, relativeURLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef, useCompatibilityMode: Boolean) -> CFURLRef;
+    pub fn CFURLCreateByResolvingBookmarkData(allocator: CFAllocatorRef, bookmark: CFDataRef, options: CFURLBookmarkResolutionOptions, relativeToURL: CFURLRef, resourcePropertiesToInclude: CFArrayRef, isStale: *mut Boolean, error: *mut CFErrorRef) -> CFURLRef;
     //fn CFURLCreateCopyAppendingPathComponent
     //fn CFURLCreateCopyAppendingPathExtension
     //fn CFURLCreateCopyDeletingLastPathComponent
@@ -142,19 +147,19 @@ extern {
     //fn CFURLClearResourcePropertyCacheForKey
     //fn CFURLCopyResourcePropertiesForKeys
     //fn CFURLCopyResourcePropertyForKey
-    //fn CFURLCreateResourcePropertiesForKeysFromBookmarkData
-    //fn CFURLCreateResourcePropertyForKeyFromBookmarkData
+    pub fn CFURLCreateResourcePropertiesForKeysFromBookmarkData(allocator: CFAllocatorRef, resourcePropertiesToReturn: CFArrayRef, bookmark: CFDataRef) -> CFDictionaryRef;
+    pub fn CFURLCreateResourcePropertyForKeyFromBookmarkData(allocator: CFAllocatorRef, resourcePropertyKey: CFStringRef, bookmark: CFDataRef) -> CFTypeRef;
     //fn CFURLSetResourcePropertiesForKeys
     pub fn CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean;
     //fn CFURLSetTemporaryResourcePropertyForKey
 
     /* Working with Bookmark Data */
-    //fn CFURLCreateBookmarkData
-    //fn CFURLCreateBookmarkDataFromAliasRecord
-    //fn CFURLCreateBookmarkDataFromFile
-    //fn CFURLWriteBookmarkDataToFile
-    //fn CFURLStartAccessingSecurityScopedResource
-    //fn CFURLStopAccessingSecurityScopedResource
+    pub fn CFURLCreateBookmarkData(allocator: CFAllocatorRef, url: CFURLRef, options: CFURLBookmarkCreationOptions, resourcePropertiesToInclude: CFArrayRef, relativeToURL: CFURLRef, error: *mut CFErrorRef) -> CFDataRef;
+    pub fn CFURLCreateBookmarkDataFromAliasRecord(allocator: CFAllocatorRef, aliasRecordDataRef: CFDataRef) -> CFDataRef;
+    pub fn CFURLCreateBookmarkDataFromFile(allocator: CFAllocatorRef, fileURL: CFURLRef, errorRef: *mut CFErrorRef) -> CFDataRef;
+    pub fn CFURLWriteBookmarkDataToFile(bookmarkRef: CFDataRef, fileURL: CFURLRef, options: CFURLBookmarkFileCreationOptions, errorRef: *mut CFErrorRef) -> Boolean;
+    pub fn CFURLStartAccessingSecurityScopedResource(url: CFURLRef) -> Boolean;
+    pub fn CFURLStopAccessingSecurityScopedResource(url: CFURLRef);
 }
 
 #[test]


Test patch: