Permalink
Browse files

Merge branch 'URLProtocol' of github.com:artifacts/AFCache into URLPr…

…otocol
  • Loading branch information...
2 parents 7ef8983 + 72b3925 commit 132efb71c4eb9aa412d7aa70d74b0889688601a4 @artifacts committed Aug 5, 2013
Showing with 163 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. +134 −0 AFCache-iOS.xcodeproj/project.pbxproj
  3. +26 −6 src/shared/AFCache.m
  4. +1 −1 src/shared/AFCache_Logging.h
  5. +1 −1 src/shared/AFCacheableItem.m
View
@@ -20,3 +20,4 @@ release/AFCacheLib.h
# vi noise
.*.swp
.idea
+Headers
@@ -6,6 +6,22 @@
objectVersion = 46;
objects = {
+/* Begin PBXAggregateTarget section */
+ 379B6926177CAEA8001174E8 /* AFCache_universal */ = {
+ isa = PBXAggregateTarget;
+ buildConfigurationList = 379B692A177CAEA8001174E8 /* Build configuration list for PBXAggregateTarget "AFCache_universal" */;
+ buildPhases = (
+ 379B692D177CAFF9001174E8 /* ShellScript */,
+ 379B692E177CB01B001174E8 /* CopyFiles */,
+ );
+ dependencies = (
+ 379B692C177CAFCA001174E8 /* PBXTargetDependency */,
+ );
+ name = AFCache_universal;
+ productName = AFCache;
+ };
+/* End PBXAggregateTarget section */
+
/* Begin PBXBuildFile section */
051B38711328AACA0057F2F5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051B38701328AACA0057F2F5 /* Foundation.framework */; };
051B387C1328AACA0057F2F5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051B387B1328AACA0057F2F5 /* UIKit.framework */; };
@@ -87,6 +103,26 @@
0569DECC1328AD9C00B3D016 /* DateParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 0569DE931328AD9C00B3D016 /* DateParser.m */; };
058339CD150CB747005A6D55 /* AFHTTPURLProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 058339CB150CB747005A6D55 /* AFHTTPURLProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
058339CE150CB747005A6D55 /* AFHTTPURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 058339CC150CB747005A6D55 /* AFHTTPURLProtocol.m */; };
+ 379B6930177CBC38001174E8 /* crypt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE6B1328AD9C00B3D016 /* crypt.h */; };
+ 379B6931177CBC38001174E8 /* ioapi.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE6D1328AD9C00B3D016 /* ioapi.h */; };
+ 379B6932177CBC38001174E8 /* mztools.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE701328AD9C00B3D016 /* mztools.h */; };
+ 379B6933177CBC38001174E8 /* unzip.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE721328AD9C00B3D016 /* unzip.h */; };
+ 379B6934177CBC38001174E8 /* zip.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE741328AD9C00B3D016 /* zip.h */; };
+ 379B6935177CBC38001174E8 /* ZipArchive.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE751328AD9C00B3D016 /* ZipArchive.h */; };
+ 379B6936177CBC38001174E8 /* AFMediaTypeParser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0544C86E150F57980057EC39 /* AFMediaTypeParser.h */; };
+ 379B6937177CBC38001174E8 /* AFCache+Mimetypes.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE7F1328AD9C00B3D016 /* AFCache+Mimetypes.h */; };
+ 379B6938177CBC38001174E8 /* AFCache+Packaging.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE811328AD9C00B3D016 /* AFCache+Packaging.h */; };
+ 379B6939177CBC38001174E8 /* AFCache+PrivateAPI.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE831328AD9C00B3D016 /* AFCache+PrivateAPI.h */; };
+ 379B693A177CBC38001174E8 /* AFCache.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE841328AD9C00B3D016 /* AFCache.h */; };
+ 379B693B177CBC38001174E8 /* AFCache_Logging.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE861328AD9C00B3D016 /* AFCache_Logging.h */; };
+ 379B693C177CBC38001174E8 /* AFCacheableItem+Packaging.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE871328AD9C00B3D016 /* AFCacheableItem+Packaging.h */; };
+ 379B693D177CBC38001174E8 /* AFCacheableItem.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE891328AD9C00B3D016 /* AFCacheableItem.h */; };
+ 379B693E177CBC38001174E8 /* AFCacheableItemInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE8B1328AD9C00B3D016 /* AFCacheableItemInfo.h */; };
+ 379B693F177CBC38001174E8 /* AFPackageInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE8D1328AD9C00B3D016 /* AFPackageInfo.h */; };
+ 379B6940177CBC38001174E8 /* AFURLCache.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE8F1328AD9C00B3D016 /* AFURLCache.h */; };
+ 379B6941177CBC38001174E8 /* Constants.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE911328AD9C00B3D016 /* Constants.h */; };
+ 379B6942177CBC38001174E8 /* DateParser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0569DE921328AD9C00B3D016 /* DateParser.h */; };
+ 379B6943177CBC38001174E8 /* AFHTTPURLProtocol.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 058339CB150CB747005A6D55 /* AFHTTPURLProtocol.h */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -104,8 +140,47 @@
remoteGlobalIDString = 051B386C1328AACA0057F2F5;
remoteInfo = "AFCache-iOS";
};
+ 379B692B177CAFCA001174E8 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 051B38641328AACA0057F2F5 /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 051B386C1328AACA0057F2F5;
+ remoteInfo = "AFCache-iOS";
+ };
/* End PBXContainerItemProxy section */
+/* Begin PBXCopyFilesBuildPhase section */
+ 379B692E177CB01B001174E8 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = "${SRCROOT}/$DEPLOYMENT_TARGET/$LIB_BASE_NAME";
+ dstSubfolderSpec = 0;
+ files = (
+ 379B6930177CBC38001174E8 /* crypt.h in CopyFiles */,
+ 379B6931177CBC38001174E8 /* ioapi.h in CopyFiles */,
+ 379B6932177CBC38001174E8 /* mztools.h in CopyFiles */,
+ 379B6933177CBC38001174E8 /* unzip.h in CopyFiles */,
+ 379B6934177CBC38001174E8 /* zip.h in CopyFiles */,
+ 379B6935177CBC38001174E8 /* ZipArchive.h in CopyFiles */,
+ 379B6936177CBC38001174E8 /* AFMediaTypeParser.h in CopyFiles */,
+ 379B6937177CBC38001174E8 /* AFCache+Mimetypes.h in CopyFiles */,
+ 379B6938177CBC38001174E8 /* AFCache+Packaging.h in CopyFiles */,
+ 379B6939177CBC38001174E8 /* AFCache+PrivateAPI.h in CopyFiles */,
+ 379B693A177CBC38001174E8 /* AFCache.h in CopyFiles */,
+ 379B693B177CBC38001174E8 /* AFCache_Logging.h in CopyFiles */,
+ 379B693C177CBC38001174E8 /* AFCacheableItem+Packaging.h in CopyFiles */,
+ 379B693D177CBC38001174E8 /* AFCacheableItem.h in CopyFiles */,
+ 379B693E177CBC38001174E8 /* AFCacheableItemInfo.h in CopyFiles */,
+ 379B693F177CBC38001174E8 /* AFPackageInfo.h in CopyFiles */,
+ 379B6940177CBC38001174E8 /* AFURLCache.h in CopyFiles */,
+ 379B6941177CBC38001174E8 /* Constants.h in CopyFiles */,
+ 379B6942177CBC38001174E8 /* DateParser.h in CopyFiles */,
+ 379B6943177CBC38001174E8 /* AFHTTPURLProtocol.h in CopyFiles */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
/* Begin PBXFileReference section */
051B386D1328AACA0057F2F5 /* libAFCache-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libAFCache-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
051B38701328AACA0057F2F5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -516,6 +591,7 @@
051B386C1328AACA0057F2F5 /* AFCache-iOS */,
051B38791328AACA0057F2F5 /* AFCache-iOSTests */,
0566ADFF1332D6B500583E6A /* AFCacheDemo */,
+ 379B6926177CAEA8001174E8 /* AFCache_universal */,
);
};
/* End PBXProject section */
@@ -560,6 +636,19 @@
shellPath = /bin/sh;
shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
};
+ 379B692D177CAFF9001174E8 /* ShellScript */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "deploymentTarget=$DEPLOYMENT_TARGET\n\nif [ ! -d \"$deploymentTarget\" ]; then\nmkdir \"$deploymentTarget\"\nfi\n\nsh ../buildUniversalLib.sh AFCache-iOS $LIB_BASE_NAME \"$deploymentTarget\" AFCache-iOS.xcodeproj";
+ };
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -635,6 +724,11 @@
target = 051B386C1328AACA0057F2F5 /* AFCache-iOS */;
targetProxy = 0566AE371332D79C00583E6A /* PBXContainerItemProxy */;
};
+ 379B692C177CAFCA001174E8 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 051B386C1328AACA0057F2F5 /* AFCache-iOS */;
+ targetProxy = 379B692B177CAFCA001174E8 /* PBXContainerItemProxy */;
+ };
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
@@ -727,6 +821,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ DEPLOYMENT_TARGET = ../sharedLib/;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
@@ -735,6 +830,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
+ LIB_BASE_NAME = ERBeans;
SDKROOT = iphoneos;
};
name = Debug;
@@ -743,11 +839,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ DEPLOYMENT_TARGET = ../sharedLib/;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
+ LIB_BASE_NAME = ERBeans;
SDKROOT = iphoneos;
};
name = Release;
@@ -873,6 +971,33 @@
};
name = Release;
};
+ 379B6927177CAEA8001174E8 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DEPLOYMENT_TARGET = ../sharedLib;
+ LIB_BASE_NAME = AFCache;
+ PRODUCT_NAME = "AFCache-iOS";
+ };
+ name = Debug;
+ };
+ 379B6928177CAEA8001174E8 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DEPLOYMENT_TARGET = ../sharedLib;
+ LIB_BASE_NAME = AFCache;
+ PRODUCT_NAME = "AFCache-iOS";
+ };
+ name = Release;
+ };
+ 379B6929177CAEA8001174E8 /* Adhoc */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DEPLOYMENT_TARGET = ../sharedLib;
+ LIB_BASE_NAME = AFCache;
+ PRODUCT_NAME = "AFCache-iOS";
+ };
+ name = Adhoc;
+ };
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@@ -916,6 +1041,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ 379B692A177CAEA8001174E8 /* Build configuration list for PBXAggregateTarget "AFCache_universal" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 379B6927177CAEA8001174E8 /* Debug */,
+ 379B6928177CAEA8001174E8 /* Release */,
+ 379B6929177CAEA8001174E8 /* Adhoc */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
/* End XCConfigurationList section */
};
rootObject = 051B38641328AACA0057F2F5 /* Project object */;
View
@@ -293,7 +293,7 @@ - (void)reinitialize {
AFLog(@ "Failed to create cache directory at path %@: %@", dataPath, [error description]);
}
}
-
+
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1 || TARGET_OS_MAC && MAC_OS_X_VERSION_MIN_ALLOWED < MAC_OS_X_VERSION_10_8
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:dataPath]];
#endif
@@ -312,15 +312,15 @@ - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
NSError *error = nil;
-
+
BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES] forKey: NSURLIsExcludedFromBackupKey error:&error];
if (!success) {
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success;
}
-#endif
+#endif
// remove all expired cache entries
// TODO: exchange with a better displacement strategy
@@ -561,7 +561,7 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
if (!internalURL.isFileURL && [self isOffline] && !item) {
- // check if there is a cached redirect for this URL, but ONLY if we're offline
+ // check if there is a cached redirect for this URL, but ONLY if we're offline
// AFAIU redirects of type 302 MUST NOT be cached
// since we do not distinguish between 301 and 302 or other types of redirects, nor save the status code anywhere
// we simply only check the cached redirects if we're offline
@@ -586,7 +586,14 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
if (!item) {
// we're offline and did not have a cached version, so return nil
- if (!internalURL.isFileURL && [self isOffline]) return nil;
+ if (!internalURL.isFileURL && [self isOffline])
+ {
+ if(aFailBlock != nil)
+ {
+ ((AFCacheableItemBlock)aFailBlock)(nil);
+ }
+ return nil;
+ }
// we're online - create a new item, since we had a cache miss
item = [[[AFCacheableItem alloc] init] autorelease];
@@ -1202,9 +1209,12 @@ - (void)cancelConnectionsForURL: (NSURL *) url
{
if (nil != url)
{
-// NSURLConnection *connection = [pendingConnections objectForKey: url];
AFCacheableItem *pendingItem = [pendingConnections objectForKey: url];
AFLog(@"Cancelling connection for URL: %@", [url absoluteString]);
+ pendingItem.delegate = nil;
+ pendingItem.completionBlock = nil;
+ pendingItem.failBlock = nil;
+ pendingItem.progressBlock = nil;
[pendingItem.connection cancel];
[pendingConnections removeObjectForKey: url];
}
@@ -1554,6 +1564,16 @@ - (void)downloadItem:(AFCacheableItem*)item
// Do not start any connection right now, because AFCache is paused
return;
}
+ //check if we can download
+ if (![item.url isFileURL] && [self isOffline]) {
+ //we can not download this item at the moment
+ if(item.failBlock != nil)
+ {
+ item.failBlock(item);
+ }
+ return;
+ }
+
AFLog(@"downloading %@",item.url);
// Remove the item from the queue, becaue we are going to download the item now
[downloadQueue removeObject:item];
@@ -6,7 +6,7 @@
* Copyright 2011 Artifacts - Fine Software Development. All rights reserved.
*
*/
-#define AFCACHE_LOGGING_ENABLED 1
+
#ifdef AFCACHE_LOGGING_ENABLED
#define AFLog(fmt, ...) NSLog((fmt), ## __VA_ARGS__)
@@ -604,6 +604,7 @@ - (void)signalItemsDidFinish:(NSArray*)items
{
for (AFCacheableItem* item in items)
{
+
if (nil == item.data) {
// item may not have loaded its data, share self.data with all items
item.data = self.data;
@@ -623,7 +624,6 @@ - (void)signalItemsDidFinish:(NSArray*)items
}
-
- (void)signalItemsDidFail:(NSArray*)items
{
for (AFCacheableItem* item in items)

0 comments on commit 132efb7

Please sign in to comment.