/*
- * Copyright (c) 2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2009 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* @APPLE_LICENSE_HEADER_END@
*/
/* CFURLAccess.c
- Copyright 1999-2002, Apple, Inc. All rights reserved.
- Responsibility: Becky Willrich
+ Copyright (c) 1999-2009, Apple Inc. All rights reserved.
+ Responsibility: Chris Linn
*/
/*------
#include <CoreFoundation/CFDate.h>
#include <CoreFoundation/CFNumber.h>
#include <string.h>
-#if DEPLOYMENT_TARGET_MACOSX
+#include <ctype.h>
+#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <pwd.h>
#include <fcntl.h>
#include <dlfcn.h>
+#elif DEPLOYMENT_TARGET_WINDOWS
+//#include <winsock2.h>
+#include <io.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <ctype.h>
+#else
+#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
-#if DEPLOYMENT_TARGET_MACOSX
+#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
+
-DEFINE_WEAK_CFNETWORK_FUNC(Boolean, _CFURLCreateDataAndPropertiesFromResource, (CFAllocatorRef A, CFURLRef B, CFDataRef *C, CFDictionaryRef *D, CFArrayRef E, SInt32 *F), (A, B, C, D, E, F), false)
-DEFINE_WEAK_CFNETWORK_FUNC(Boolean, _CFURLWriteDataAndPropertiesToResource, (CFURLRef A, CFDataRef B, CFDictionaryRef C, SInt32 *D), (A, B, C, D), false)
-DEFINE_WEAK_CFNETWORK_FUNC(Boolean, _CFURLDestroyResource, (CFURLRef A, SInt32 *B), (A, B), false)
+DEFINE_WEAK_CFNETWORK_FUNC_FAIL(Boolean, _CFURLCreateDataAndPropertiesFromResource, (CFAllocatorRef A, CFURLRef B, CFDataRef *C, CFDictionaryRef *D, CFArrayRef E, SInt32 *F), (A, B, C, D, E, F), { if(C) *C=NULL; if (D) *D=NULL; if(F) *F=kCFURLImproperArgumentsError; }, false)
+DEFINE_WEAK_CFNETWORK_FUNC_FAIL(Boolean, _CFURLWriteDataAndPropertiesToResource, (CFURLRef A, CFDataRef B, CFDictionaryRef C, SInt32 *D), (A, B, C, D), if (D) *D = kCFURLImproperArgumentsError, false)
+DEFINE_WEAK_CFNETWORK_FUNC_FAIL(Boolean, _CFURLDestroyResource, (CFURLRef A, SInt32 *B), (A, B), if(B) *B = kCFURLImproperArgumentsError, false)
+
+#elif DEPLOYMENT_TARGET_WINDOWS
+#else
+#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
+typedef struct __NSString__ *NSString;
+
+/*
+ Pre-10.6 property keys
+*/
CONST_STRING_DECL(kCFURLFileExists, "kCFURLFileExists")
CONST_STRING_DECL(kCFURLFilePOSIXMode, "kCFURLFilePOSIXMode")
}
if (_CFGetFileProperties(alloc, url, &exists, &posixMode, &size, modTimePtr, &ownerID, contentsPtr) != 0) {
- if (errorCode) {
+
+ // If all they've asked for is whether this file exists, then any error will just make
+ // this return kCFURLFileExists = kCFBooleanFalse, which handles the case where the filename is invalid or too long or something.
+ if ( arrayRange.length == 1 && CFArrayContainsValue( desiredProperties, arrayRange, kCFURLFileExists ) ) {
+ CFDictionarySetValue(propertyDict, kCFURLFileExists, kCFBooleanFalse);
+ }
+ else if (errorCode) {
*errorCode = kCFURLUnknownError;
}
return propertyDict;
CFNumberRef modeNum = (CFNumberRef)value;
CFNumberGetValue(modeNum, kCFNumberSInt32Type, &mode);
} else {
-#if DEPLOYMENT_TARGET_MACOSX
+#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
#define MODE_TYPE mode_t
+#elif DEPLOYMENT_TARGET_WINDOWS
+#define MODE_TYPE uint16_t
+#else
+#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
const MODE_TYPE *modePtr = (const MODE_TYPE *)CFDataGetBytePtr((CFDataRef)value);
mode = *modePtr;
if (fetchedProperties) {
*fetchedProperties = _CFFileURLCreatePropertiesFromResource(alloc, url, desiredProperties, errorCode);
- if (!*fetchedProperties) success = false;
+ if (!*fetchedProperties)
+ success = false;
}
+ if ( ! success && fetchedData && *fetchedData ) {
+ CFRelease( *fetchedData );
+ *fetchedData = NULL;
+ }
+
return success;
}
static inline CFStringRef percentExpandAndTrimContentType(CFAllocatorRef alloc, CFStringRef str, CFRange range)
{
- CFStringRef contentTypeUnexpanded = CFStringCreateWithSubstring(alloc, str, range);
- CFStringRef contentTypeExpanded = CFURLCreateStringByReplacingPercentEscapes(alloc, contentTypeUnexpanded, CFSTR(""));
- CFRelease(contentTypeUnexpanded);
-
- CFMutableStringRef contentTypeHeader = CFStringCreateMutableCopy(alloc, 0, contentTypeExpanded);
+ CFMutableStringRef contentTypeHeader = NULL;
+ CFStringRef contentTypeUnexpanded = CFStringCreateWithSubstring(alloc, str, range);
+ CFStringRef contentTypeExpanded = CFURLCreateStringByReplacingPercentEscapes(alloc, contentTypeUnexpanded, CFSTR(""));
+
+ if (NULL == contentTypeExpanded) {
+ contentTypeHeader = CFStringCreateMutableCopy(alloc, 0, contentTypeUnexpanded);
+ } else {
+ contentTypeHeader = CFStringCreateMutableCopy(alloc, 0, contentTypeExpanded);
CFRelease(contentTypeExpanded);
- CFStringTrimWhitespace(contentTypeHeader);
-
- return contentTypeHeader;
+ }
+ CFRelease(contentTypeUnexpanded);
+ CFStringTrimWhitespace(contentTypeHeader);
+
+ return contentTypeHeader;
}
static Boolean parseDataRequestURL(CFURLRef url, CFDataRef* outData, CFStringRef* outMimeType, CFStringRef* outTextEncodingName)
mimeType = (CFStringRef) CFRetain(CFSTR("text/plain"));
}
- if (textEncodingName == NULL) {
- textEncodingName = (CFStringRef) CFRetain(CFSTR("us-ascii"));
- }
-
CFIndex bufferSize = CFURLGetBytes(url, NULL, 0);
UInt8* srcBuffer = (UInt8*) malloc(bufferSize);
CFURLGetBytes(url, srcBuffer, bufferSize);
if (CFStringCompare(scheme, CFSTR("file"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
result = _CFFileURLCreateDataAndPropertiesFromResource(alloc, url, fetchedData, desiredProperties, fetchedProperties, errorCode);
} else if (CFStringCompare(scheme, CFSTR("data"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
- result = _CFDataURLCreateDataAndPropertiesFromResource(alloc, url, fetchedData, desiredProperties, fetchedProperties, errorCode);
- } else {
-#if DEPLOYMENT_TARGET_MACOSX
+ result = _CFDataURLCreateDataAndPropertiesFromResource(alloc, url, fetchedData, desiredProperties, fetchedProperties, errorCode);
+ } else {
+#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
result = __CFNetwork__CFURLCreateDataAndPropertiesFromResource(alloc, url, fetchedData, fetchedProperties, desiredProperties, errorCode);
- if (!result) {
- if (fetchedData) *fetchedData = NULL;
- if (fetchedProperties) *fetchedProperties = NULL;
- if (errorCode) *errorCode = kCFURLUnknownSchemeError;
- }
+#elif DEPLOYMENT_TARGET_WINDOWS
+ if (fetchedData) *fetchedData = NULL;
+ if (fetchedProperties) *fetchedProperties = NULL;
+ if (errorCode) *errorCode = kCFURLUnknownSchemeError;
+ result = false;
+#else
+#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
}
CFRelease(scheme);
if (data) {
if (CFURLHasDirectoryPath(url)) {
// Create a directory
+#if DEPLOYMENT_TARGET_WINDOWS
+ wchar_t cPath[CFMaxPathSize];
+ if (!_CFURLGetWideFileSystemRepresentation(url, true, cPath, CFMaxPathSize))
+#else
char cPath[CFMaxPathSize];
- if (!CFURLGetFileSystemRepresentation(url, true, (unsigned char *)cPath, CFMaxPathSize)) {
+ if (!CFURLGetFileSystemRepresentation(url, true, (unsigned char *)cPath, CFMaxPathSize))
+#endif
+ {
if (errorCode) *errorCode = kCFURLImproperArgumentsError;
success = false;
} else {
+#if DEPLOYMENT_TARGET_WINDOWS
+ success = _CFCreateDirectoryWide(cPath);
+#else
success = _CFCreateDirectory(cPath);
+#endif
if (!success && errorCode) *errorCode = kCFURLUnknownError;
}
} else {
return success;
} else {
CFRelease(scheme);
-#if DEPLOYMENT_TARGET_MACOSX
+#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
Boolean result = __CFNetwork__CFURLWriteDataAndPropertiesToResource(url, data, propertyDict, errorCode);
if (!result) {
if (errorCode) *errorCode = kCFURLUnknownSchemeError;
}
return result;
+#elif DEPLOYMENT_TARGET_WINDOWS
+ if (errorCode) *errorCode = kCFURLUnknownSchemeError;
+ return false;
+#else
+#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
}
}
}
} else {
CFRelease(scheme);
-#if DEPLOYMENT_TARGET_MACOSX
+#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
Boolean result = __CFNetwork__CFURLDestroyResource(url, errorCode);
if (!result) {
if (errorCode) *errorCode = kCFURLUnknownSchemeError;
}
return result;
+#elif DEPLOYMENT_TARGET_WINDOWS
+ if (errorCode) *errorCode = kCFURLUnknownSchemeError;
+ return false;
+#else
+#error Unknown or unspecified DEPLOYMENT_TARGET
#endif
}
}
+