/packages/univint/src/CFURLAccess.pas

https://github.com/slibre/freepascal · Pascal · 274 lines · 28 code · 25 blank · 221 comment · 0 complexity · ad3320c47323a367c807d77260b4fb1a MD5 · raw file

  1. { CFURLAccess.h
  2. Copyright (c) 1998-2012, Apple Inc. All rights reserved.
  3. }
  4. { Pascal Translation Updated: Peter N Lewis, <peter@stairways.com.au>, November 2005 }
  5. { Pascal Translation Updated: Gorazd Krosl, <gorazd_1957@yahoo.ca>, October 2009 }
  6. { Pascal Translation Updated: Jonas Maebe, <jonas@freepascal.org>, October 2009 }
  7. { Pascal Translation Updated: Jonas Maebe <jonas@freepascal.org>, September 2012 }
  8. {
  9. Modified for use with Free Pascal
  10. Version 308
  11. Please report any bugs to <gpc@microbizz.nl>
  12. }
  13. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  14. {$mode macpas}
  15. {$packenum 1}
  16. {$macro on}
  17. {$inline on}
  18. {$calling mwpascal}
  19. unit CFURLAccess;
  20. interface
  21. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  22. {$setc GAP_INTERFACES_VERSION := $0308}
  23. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  24. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  25. {$endc}
  26. {$ifc defined CPUPOWERPC and defined CPUI386}
  27. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  28. {$endc}
  29. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  30. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  31. {$endc}
  32. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  33. {$setc __ppc__ := 1}
  34. {$elsec}
  35. {$setc __ppc__ := 0}
  36. {$endc}
  37. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  38. {$setc __ppc64__ := 1}
  39. {$elsec}
  40. {$setc __ppc64__ := 0}
  41. {$endc}
  42. {$ifc not defined __i386__ and defined CPUI386}
  43. {$setc __i386__ := 1}
  44. {$elsec}
  45. {$setc __i386__ := 0}
  46. {$endc}
  47. {$ifc not defined __x86_64__ and defined CPUX86_64}
  48. {$setc __x86_64__ := 1}
  49. {$elsec}
  50. {$setc __x86_64__ := 0}
  51. {$endc}
  52. {$ifc not defined __arm__ and defined CPUARM}
  53. {$setc __arm__ := 1}
  54. {$elsec}
  55. {$setc __arm__ := 0}
  56. {$endc}
  57. {$ifc defined cpu64}
  58. {$setc __LP64__ := 1}
  59. {$elsec}
  60. {$setc __LP64__ := 0}
  61. {$endc}
  62. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  63. {$error Conflicting definitions for __ppc__ and __i386__}
  64. {$endc}
  65. {$ifc defined __ppc__ and __ppc__}
  66. {$setc TARGET_CPU_PPC := TRUE}
  67. {$setc TARGET_CPU_PPC64 := FALSE}
  68. {$setc TARGET_CPU_X86 := FALSE}
  69. {$setc TARGET_CPU_X86_64 := FALSE}
  70. {$setc TARGET_CPU_ARM := FALSE}
  71. {$setc TARGET_OS_MAC := TRUE}
  72. {$setc TARGET_OS_IPHONE := FALSE}
  73. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  74. {$setc TARGET_OS_EMBEDDED := FALSE}
  75. {$elifc defined __ppc64__ and __ppc64__}
  76. {$setc TARGET_CPU_PPC := FALSE}
  77. {$setc TARGET_CPU_PPC64 := TRUE}
  78. {$setc TARGET_CPU_X86 := FALSE}
  79. {$setc TARGET_CPU_X86_64 := FALSE}
  80. {$setc TARGET_CPU_ARM := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_IPHONE := FALSE}
  83. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  84. {$setc TARGET_OS_EMBEDDED := FALSE}
  85. {$elifc defined __i386__ and __i386__}
  86. {$setc TARGET_CPU_PPC := FALSE}
  87. {$setc TARGET_CPU_PPC64 := FALSE}
  88. {$setc TARGET_CPU_X86 := TRUE}
  89. {$setc TARGET_CPU_X86_64 := FALSE}
  90. {$setc TARGET_CPU_ARM := FALSE}
  91. {$ifc defined(iphonesim)}
  92. {$setc TARGET_OS_MAC := FALSE}
  93. {$setc TARGET_OS_IPHONE := TRUE}
  94. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  95. {$elsec}
  96. {$setc TARGET_OS_MAC := TRUE}
  97. {$setc TARGET_OS_IPHONE := FALSE}
  98. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  99. {$endc}
  100. {$setc TARGET_OS_EMBEDDED := FALSE}
  101. {$elifc defined __x86_64__ and __x86_64__}
  102. {$setc TARGET_CPU_PPC := FALSE}
  103. {$setc TARGET_CPU_PPC64 := FALSE}
  104. {$setc TARGET_CPU_X86 := FALSE}
  105. {$setc TARGET_CPU_X86_64 := TRUE}
  106. {$setc TARGET_CPU_ARM := FALSE}
  107. {$setc TARGET_OS_MAC := TRUE}
  108. {$setc TARGET_OS_IPHONE := FALSE}
  109. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  110. {$setc TARGET_OS_EMBEDDED := FALSE}
  111. {$elifc defined __arm__ and __arm__}
  112. {$setc TARGET_CPU_PPC := FALSE}
  113. {$setc TARGET_CPU_PPC64 := FALSE}
  114. {$setc TARGET_CPU_X86 := FALSE}
  115. {$setc TARGET_CPU_X86_64 := FALSE}
  116. {$setc TARGET_CPU_ARM := TRUE}
  117. { will require compiler define when/if other Apple devices with ARM cpus ship }
  118. {$setc TARGET_OS_MAC := FALSE}
  119. {$setc TARGET_OS_IPHONE := TRUE}
  120. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  121. {$setc TARGET_OS_EMBEDDED := TRUE}
  122. {$elsec}
  123. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  124. {$endc}
  125. {$ifc defined __LP64__ and __LP64__ }
  126. {$setc TARGET_CPU_64 := TRUE}
  127. {$elsec}
  128. {$setc TARGET_CPU_64 := FALSE}
  129. {$endc}
  130. {$ifc defined FPC_BIG_ENDIAN}
  131. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  132. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  133. {$elifc defined FPC_LITTLE_ENDIAN}
  134. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  135. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  136. {$elsec}
  137. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  138. {$endc}
  139. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  140. {$setc CALL_NOT_IN_CARBON := FALSE}
  141. {$setc OLDROUTINENAMES := FALSE}
  142. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  143. {$setc OPAQUE_UPP_TYPES := TRUE}
  144. {$setc OTCARBONAPPLICATION := TRUE}
  145. {$setc OTKERNEL := FALSE}
  146. {$setc PM_USE_SESSION_APIS := TRUE}
  147. {$setc TARGET_API_MAC_CARBON := TRUE}
  148. {$setc TARGET_API_MAC_OS8 := FALSE}
  149. {$setc TARGET_API_MAC_OSX := TRUE}
  150. {$setc TARGET_CARBON := TRUE}
  151. {$setc TARGET_CPU_68K := FALSE}
  152. {$setc TARGET_CPU_MIPS := FALSE}
  153. {$setc TARGET_CPU_SPARC := FALSE}
  154. {$setc TARGET_OS_UNIX := FALSE}
  155. {$setc TARGET_OS_WIN32 := FALSE}
  156. {$setc TARGET_RT_MAC_68881 := FALSE}
  157. {$setc TARGET_RT_MAC_CFM := FALSE}
  158. {$setc TARGET_RT_MAC_MACHO := TRUE}
  159. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  160. {$setc TYPE_BOOL := FALSE}
  161. {$setc TYPE_EXTENDED := FALSE}
  162. {$setc TYPE_LONGLONG := TRUE}
  163. uses MacTypes,CFBase,CFArray,CFData,CFDictionary,CFString,CFURL;
  164. {$endc} {not MACOSALLINCLUDE}
  165. {$ALIGN POWER}
  166. { Attempts to read the data and properties for the given URL. If
  167. only interested in one of the resourceData and properties, pass NULL
  168. for the other. If properties is non-NULL and desiredProperties is
  169. NULL, then all properties are fetched. Returns success or failure;
  170. note that as much work as possible is done even if false is returned.
  171. So for instance if one property is not available, the others are
  172. fetched anyway. errorCode is set to 0 on success, and some other
  173. value on failure. If non-NULL, it is the caller 's responsibility
  174. to release resourceData and properties.
  175. Apple reserves for its use all negative error code values; these
  176. values represent errors common to any scheme. Scheme-specific error
  177. codes should be positive, non-zero, and should be used only if one of
  178. the predefined Apple error codes does not apply. Error codes should
  179. be publicized and documented with the scheme-specific properties.
  180. NOTE: When asking for the resource data, this call will allocate the entire
  181. resource in memory. This can be very expensive, depending on the size of the
  182. resource (file). Please use CFStream or other techniques if you are downloading
  183. large files.
  184. }
  185. function CFURLCreateDataAndPropertiesFromResource( alloc: CFAllocatorRef; url: CFURLRef; resourceData: CFDataRefPtr; properties: CFDictionaryRefPtr; desiredProperties: CFArrayRef; var errorCode: SInt32 ): Boolean; external name '_CFURLCreateDataAndPropertiesFromResource';
  186. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  187. { Attempts to write the given data and properties to the given URL.
  188. If dataToWrite is NULL, only properties are written out (use
  189. CFURLDestroyResource() to delete a resource). Properties not present
  190. in propertiesToWrite are left unchanged, hence if propertiesToWrite
  191. is NULL or empty, the URL's properties are not changed at all.
  192. Returns success or failure; errorCode is set as for
  193. CFURLCreateDataAndPropertiesFromResource(), above.
  194. }
  195. function CFURLWriteDataAndPropertiesToResource( url: CFURLRef; dataToWrite: CFDataRef; propertiesToWrite: CFDictionaryRef; var errorCode: SInt32 ): Boolean; external name '_CFURLWriteDataAndPropertiesToResource';
  196. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  197. { Destroys the resource indicated by url. }
  198. { Returns success or failure; errorCode set as above. }
  199. function CFURLDestroyResource( url: CFURLRef; var errorCode: SInt32 ): Boolean; external name '_CFURLDestroyResource';
  200. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  201. { Convenience method which calls through to CFURLCreateDataAndPropertiesFromResource(). }
  202. { Returns NULL on error and sets errorCode accordingly. }
  203. function CFURLCreatePropertyFromResource( alloc: CFAllocatorRef; url: CFURLRef; proprty: CFStringRef; var errorCode: SInt32 ): CFTypeRef; external name '_CFURLCreatePropertyFromResource';
  204. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  205. { Common error codes (returned only by the older APIs that predate CFError) }
  206. type
  207. CFURLError = CFIndex;
  208. const
  209. kCFURLUnknownError = -10;
  210. kCFURLUnknownSchemeError = -11;
  211. kCFURLResourceNotFoundError = -12;
  212. kCFURLResourceAccessViolationError = -13;
  213. kCFURLRemoteHostUnavailableError = -14;
  214. kCFURLImproperArgumentsError = -15;
  215. kCFURLUnknownPropertyKeyError = -16;
  216. kCFURLPropertyKeyUnavailableError = -17;
  217. kCFURLTimeoutError = -18;
  218. { Older property keys }
  219. var kCFURLFileExists: CFStringRef; external name '_kCFURLFileExists'; (* attribute const *)
  220. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  221. var kCFURLFileDirectoryContents: CFStringRef; external name '_kCFURLFileDirectoryContents'; (* attribute const *)
  222. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  223. var kCFURLFileLength: CFStringRef; external name '_kCFURLFileLength'; (* attribute const *)
  224. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  225. var kCFURLFileLastModificationTime: CFStringRef; external name '_kCFURLFileLastModificationTime'; (* attribute const *)
  226. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  227. var kCFURLFilePOSIXMode: CFStringRef; external name '_kCFURLFilePOSIXMode'; (* attribute const *)
  228. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  229. var kCFURLFileOwnerID: CFStringRef; external name '_kCFURLFileOwnerID'; (* attribute const *)
  230. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  231. var kCFURLHTTPStatusCode: CFStringRef; external name '_kCFURLHTTPStatusCode'; (* attribute const *)
  232. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  233. var kCFURLHTTPStatusLine: CFStringRef; external name '_kCFURLHTTPStatusLine'; (* attribute const *)
  234. (* CF_AVAILABLE_STARTING(10_0, 2_0) *)
  235. { The value of kCFURLFileExists is a CFBoolean }
  236. { The value of kCFURLFileDirectoryContents is a CFArray containing CFURLs. An empty array means the directory exists, but is empty }
  237. { The value of kCFURLFileLength is a CFNumber giving the file's length in bytes }
  238. { The value of kCFURLFileLastModificationTime is a CFDate }
  239. { The value of kCFURLFilePOSIXMode is a CFNumber as given in stat.h }
  240. { The value of kCFURLFileOwnerID is a CFNumber representing the owner's uid }
  241. { Properties for the http: scheme. Except for the common error codes, above, errorCode will be set to the HTTP response status code upon failure. Any HTTP header name can also be used as a property }
  242. { The value of kCFURLHTTPStatusCode is a CFNumber }
  243. { The value of kCFURLHTTPStatusLine is a CFString }
  244. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  245. end.
  246. {$endc} {not MACOSALLINCLUDE}