PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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