From e74a397152eedb7aa1c361315d5da3cc46f0a233 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 1 Apr 2016 22:41:12 -0400 Subject: [PATCH] Add downloader XPC services for sandboxed apps ATS exceptions now need to be included in the appcast & update downloader services - *shrugs*. I've a run script configured to disable ATS for release builds. --- .../AppcastDownloader.entitlements | 10 + AppcastDownloader/Info.plist | 40 +++ AppcastDownloader/SUAppcastDownloader.h | 14 + AppcastDownloader/SUAppcastDownloader.m | 75 +++++ .../SUAppcastDownloaderProtocol.h | 20 ++ AppcastDownloader/main.m | 49 +++ .../ConfigAppcastDownloader.xcconfig | 7 + .../ConfigUpdateDownloader.xcconfig | 7 + Sparkle.xcodeproj/project.pbxproj | 283 +++++++++++++++++- Sparkle/SUAppcast.m | 105 +++---- Sparkle/SUCoreBasedUpdateDriver.m | 2 +- Sparkle/SUDownloadDriver.h | 2 +- Sparkle/SUDownloadDriver.m | 155 +++++----- Sparkle/SUDownloaderDelegate.h | 29 ++ TestApplication/Sparkle-Test-App.entitlements | 4 - UpdateDownloader/Info.plist | 40 +++ UpdateDownloader/SUUpdateDownloader.h | 19 ++ UpdateDownloader/SUUpdateDownloader.m | 128 ++++++++ UpdateDownloader/SUUpdateDownloaderProtocol.h | 20 ++ .../UpdateDownloader.entitlements | 10 + UpdateDownloader/main.m | 53 ++++ 21 files changed, 906 insertions(+), 166 deletions(-) create mode 100644 AppcastDownloader/AppcastDownloader.entitlements create mode 100644 AppcastDownloader/Info.plist create mode 100644 AppcastDownloader/SUAppcastDownloader.h create mode 100644 AppcastDownloader/SUAppcastDownloader.m create mode 100644 AppcastDownloader/SUAppcastDownloaderProtocol.h create mode 100644 AppcastDownloader/main.m create mode 100644 Configurations/ConfigAppcastDownloader.xcconfig create mode 100644 Configurations/ConfigUpdateDownloader.xcconfig create mode 100644 Sparkle/SUDownloaderDelegate.h create mode 100644 UpdateDownloader/Info.plist create mode 100644 UpdateDownloader/SUUpdateDownloader.h create mode 100644 UpdateDownloader/SUUpdateDownloader.m create mode 100644 UpdateDownloader/SUUpdateDownloaderProtocol.h create mode 100644 UpdateDownloader/UpdateDownloader.entitlements create mode 100644 UpdateDownloader/main.m diff --git a/AppcastDownloader/AppcastDownloader.entitlements b/AppcastDownloader/AppcastDownloader.entitlements new file mode 100644 index 00000000..ee95ab7e --- /dev/null +++ b/AppcastDownloader/AppcastDownloader.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/AppcastDownloader/Info.plist b/AppcastDownloader/Info.plist new file mode 100644 index 00000000..4ed4a23c --- /dev/null +++ b/AppcastDownloader/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + AppcastDownloader + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © 2016 Sparkle Project. All rights reserved. + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + XPCService + + RunLoopType + NSRunLoop + ServiceType + Application + + + diff --git a/AppcastDownloader/SUAppcastDownloader.h b/AppcastDownloader/SUAppcastDownloader.h new file mode 100644 index 00000000..5ee8eff3 --- /dev/null +++ b/AppcastDownloader/SUAppcastDownloader.h @@ -0,0 +1,14 @@ +// +// SUAppcastDownloader.h +// AppcastDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUAppcastDownloaderProtocol.h" + +// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection. +@interface SUAppcastDownloader : NSObject +@end diff --git a/AppcastDownloader/SUAppcastDownloader.m b/AppcastDownloader/SUAppcastDownloader.m new file mode 100644 index 00000000..e6aab51a --- /dev/null +++ b/AppcastDownloader/SUAppcastDownloader.m @@ -0,0 +1,75 @@ +// +// SUAppcastDownloader.m +// AppcastDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUAppcastDownloader.h" + +@interface SUAppcastDownloader () + +@property (nonatomic, copy) void (^completionBlock)(NSData * _Nullable appcastData, NSError * _Nullable error); +@property (nonatomic) NSURLDownload *download; +@property (nonatomic, copy) NSString *downloadFilename; + +@end + +@implementation SUAppcastDownloader + +@synthesize completionBlock = _completionBlock; +@synthesize download = _download; +@synthesize downloadFilename = _downloadFilename; + +- (void)startDownloadWithRequest:(NSURLRequest *)request completion:(void (^)(NSData * _Nullable appcastData, NSError * _Nullable error))completionBlock +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.completionBlock = completionBlock; + + self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + }); +} + +- (void)dealloc +{ + [self cleanup]; +} + +- (void)cleanup +{ + if (self.downloadFilename != nil) { + [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil]; + } + self.downloadFilename = nil; +} + +- (void)download:(NSURLDownload *)__unused aDownload decideDestinationWithSuggestedFilename:(NSString *)filename +{ + NSString *destinationFilename = NSTemporaryDirectory(); + if (destinationFilename) + { + destinationFilename = [destinationFilename stringByAppendingPathComponent:filename]; + [self.download setDestination:destinationFilename allowOverwrite:NO]; + } +} + +- (void)download:(NSURLDownload *)__unused aDownload didCreateDestination:(NSString *)path +{ + self.downloadFilename = path; +} + +- (void)downloadDidFinish:(NSURLDownload *)__unused aDownload +{ + self.completionBlock([NSData dataWithContentsOfFile:self.downloadFilename], nil); + self.completionBlock = nil; + [self cleanup]; +} + +- (void)download:(NSURLDownload *)__unused aDownload didFailWithError:(NSError *)error +{ + [self cleanup]; + self.completionBlock(nil, error); +} + +@end diff --git a/AppcastDownloader/SUAppcastDownloaderProtocol.h b/AppcastDownloader/SUAppcastDownloaderProtocol.h new file mode 100644 index 00000000..c64b292a --- /dev/null +++ b/AppcastDownloader/SUAppcastDownloaderProtocol.h @@ -0,0 +1,20 @@ +// +// SUAppcastDownloaderProtocol.h +// AppcastDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service. +@protocol SUAppcastDownloaderProtocol + +- (void)startDownloadWithRequest:(NSURLRequest *)request completion:(void (^)(NSData * _Nullable appcastData, NSError * _Nullable error))completionBlock; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AppcastDownloader/main.m b/AppcastDownloader/main.m new file mode 100644 index 00000000..8e73fa68 --- /dev/null +++ b/AppcastDownloader/main.m @@ -0,0 +1,49 @@ +// +// main.m +// AppcastDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUAppcastDownloader.h" + +@interface ServiceDelegate : NSObject +@end + +@implementation ServiceDelegate + +- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection { + // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection. + + // Configure the connection. + // First, set the interface that the exported object implements. + newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUAppcastDownloaderProtocol)]; + + // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object. + SUAppcastDownloader *exportedObject = [SUAppcastDownloader new]; + newConnection.exportedObject = exportedObject; + + // Resuming the connection allows the system to deliver more incoming messages. + [newConnection resume]; + + // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO. + return YES; +} + +@end + +int main(int __unused argc, const char * __unused argv[]) +{ + // Create the delegate for the service. + ServiceDelegate *delegate = [ServiceDelegate new]; + + // Set up the one NSXPCListener for this service. It will handle all incoming connections. + NSXPCListener *listener = [NSXPCListener serviceListener]; + listener.delegate = delegate; + + // Resuming the serviceListener starts this service. This method does not return. + [listener resume]; + return 0; +} diff --git a/Configurations/ConfigAppcastDownloader.xcconfig b/Configurations/ConfigAppcastDownloader.xcconfig new file mode 100644 index 00000000..e59c7f9c --- /dev/null +++ b/Configurations/ConfigAppcastDownloader.xcconfig @@ -0,0 +1,7 @@ +// AppcastDownloader only + +INFOPLIST_FILE = AppcastDownloader/Info.plist +WRAPPER_EXTENSION = xpc +PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.AppcastDownloader +CODE_SIGN_ENTITLEMENTS = AppcastDownloader/AppcastDownloader.entitlements +CODE_SIGN_IDENTITY = - diff --git a/Configurations/ConfigUpdateDownloader.xcconfig b/Configurations/ConfigUpdateDownloader.xcconfig new file mode 100644 index 00000000..1579c5a1 --- /dev/null +++ b/Configurations/ConfigUpdateDownloader.xcconfig @@ -0,0 +1,7 @@ +// UpdateDownloader only + +INFOPLIST_FILE = UpdateDownloader/Info.plist +WRAPPER_EXTENSION = xpc +PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.UpdateDownloader +CODE_SIGN_ENTITLEMENTS = UpdateDownloader/UpdateDownloader.entitlements +CODE_SIGN_IDENTITY = - diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 40c5cce4..51e0e97b 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -173,9 +173,12 @@ 726E07BE1CAF0C5C001A286B /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; 726E07BF1CAF0C6C001A286B /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; 726E07C01CAF15B7001A286B /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; - 726E07C21CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */; }; 726E07E91CAF30C0001A286B /* SUUpdaterPermission.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E07E71CAF30C0001A286B /* SUUpdaterPermission.h */; }; 726E07EA1CAF30C0001A286B /* SUUpdaterPermission.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07E81CAF30C0001A286B /* SUUpdaterPermission.m */; }; + 726E07F41CAF37BD001A286B /* SUUpdateDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07F31CAF37BD001A286B /* SUUpdateDownloader.m */; }; + 726E07F61CAF37BD001A286B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07F51CAF37BD001A286B /* main.m */; }; + 726E07FA1CAF37BD001A286B /* UpdateDownloader.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 726E07EF1CAF37BD001A286B /* UpdateDownloader.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 726E08011CAF3F70001A286B /* SUDownloaderDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E08001CAF3F70001A286B /* SUDownloaderDelegate.h */; }; 726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E4A1B1C86C88F00C57C6A /* TestAppHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E4A1A1C86C88F00C57C6A /* TestAppHelper.m */; }; @@ -198,6 +201,10 @@ 7275F9C31B5F1F2900B1D19E /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; 728337A61C9E6FF40085AA99 /* SUProbeInstallStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 728337A41C9E6FF40085AA99 /* SUProbeInstallStatus.h */; }; 728337A71C9E6FF40085AA99 /* SUProbeInstallStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 728337A51C9E6FF40085AA99 /* SUProbeInstallStatus.m */; }; + 728638ED1CAF50CE00783084 /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; + 728638F81CAF5A5F00783084 /* SUAppcastDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 728638F71CAF5A5F00783084 /* SUAppcastDownloader.m */; }; + 728638FA1CAF5A5F00783084 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 728638F91CAF5A5F00783084 /* main.m */; }; + 728638FE1CAF5A5F00783084 /* AppcastDownloader.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 728638F31CAF5A5F00783084 /* AppcastDownloader.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 729746201C8E8D9A00FC134E /* TerminationListener.m in Sources */ = {isa = PBXBuildFile; fileRef = 7297461F1C8E8D9A00FC134E /* TerminationListener.m */; }; 729746231C8E8F1100FC134E /* AppInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 729746221C8E8F1100FC134E /* AppInstaller.m */; }; 729746371C8FC04600FC134E /* SUUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A8C09CA790200B7442F /* SUUnarchiver.m */; }; @@ -370,6 +377,13 @@ remoteGlobalIDString = 726E07AC1CAF08D6001A286B; remoteInfo = InstallerLauncher; }; + 726E07F81CAF37BD001A286B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 726E07EE1CAF37BD001A286B; + remoteInfo = UpdateDownloader; + }; 726E4A1F1C86C88F00C57C6A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; @@ -377,6 +391,13 @@ remoteGlobalIDString = 726E4A151C86C88F00C57C6A; remoteInfo = TestAppHelper; }; + 728638FC1CAF5A5F00783084 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 728638F21CAF5A5F00783084; + remoteInfo = AppcastDownloader; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -419,6 +440,8 @@ dstSubfolderSpec = 16; files = ( 726E07B81CAF08D6001A286B /* InstallerLauncher.xpc in Embed XPC Services */, + 726E07FA1CAF37BD001A286B /* UpdateDownloader.xpc in Embed XPC Services */, + 728638FE1CAF5A5F00783084 /* AppcastDownloader.xpc in Embed XPC Services */, ); name = "Embed XPC Services"; runOnlyForDeploymentPostprocessing = 0; @@ -714,6 +737,14 @@ 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigInstallerLauncher.xcconfig; sourceTree = ""; }; 726E07E71CAF30C0001A286B /* SUUpdaterPermission.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterPermission.h; sourceTree = ""; }; 726E07E81CAF30C0001A286B /* SUUpdaterPermission.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterPermission.m; sourceTree = ""; }; + 726E07EF1CAF37BD001A286B /* UpdateDownloader.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = UpdateDownloader.xpc; sourceTree = BUILT_PRODUCTS_DIR; }; + 726E07F11CAF37BD001A286B /* SUUpdateDownloaderProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUUpdateDownloaderProtocol.h; sourceTree = ""; }; + 726E07F21CAF37BD001A286B /* SUUpdateDownloader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUUpdateDownloader.h; sourceTree = ""; }; + 726E07F31CAF37BD001A286B /* SUUpdateDownloader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDownloader.m; sourceTree = ""; }; + 726E07F51CAF37BD001A286B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 726E07F71CAF37BD001A286B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 726E07FF1CAF3801001A286B /* UpdateDownloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = UpdateDownloader.entitlements; sourceTree = ""; }; + 726E08001CAF3F70001A286B /* SUDownloaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUDownloaderDelegate.h; path = ../Sparkle/SUDownloaderDelegate.h; sourceTree = ""; }; 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverUIDelegate.h; sourceTree = ""; }; 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverRemoteDelegate.h; sourceTree = ""; }; 726E4A111C86C44A00C57C6A /* Sparkle-Test-App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Sparkle-Test-App.entitlements"; sourceTree = ""; }; @@ -736,6 +767,15 @@ 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileManager.m; sourceTree = ""; }; 728337A41C9E6FF40085AA99 /* SUProbeInstallStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbeInstallStatus.h; sourceTree = ""; }; 728337A51C9E6FF40085AA99 /* SUProbeInstallStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUProbeInstallStatus.m; sourceTree = ""; }; + 728638EE1CAF589C00783084 /* ConfigUpdateDownloader.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUpdateDownloader.xcconfig; sourceTree = ""; }; + 728638F31CAF5A5F00783084 /* AppcastDownloader.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = AppcastDownloader.xpc; sourceTree = BUILT_PRODUCTS_DIR; }; + 728638F51CAF5A5F00783084 /* SUAppcastDownloaderProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUAppcastDownloaderProtocol.h; sourceTree = ""; }; + 728638F61CAF5A5F00783084 /* SUAppcastDownloader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUAppcastDownloader.h; sourceTree = ""; }; + 728638F71CAF5A5F00783084 /* SUAppcastDownloader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUAppcastDownloader.m; sourceTree = ""; }; + 728638F91CAF5A5F00783084 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 728638FB1CAF5A5F00783084 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 728639031CAF5B3B00783084 /* AppcastDownloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = AppcastDownloader.entitlements; sourceTree = ""; }; + 728639041CAF614000783084 /* ConfigAppcastDownloader.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigAppcastDownloader.xcconfig; sourceTree = ""; }; 7297461E1C8E8D9A00FC134E /* TerminationListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TerminationListener.h; sourceTree = ""; }; 7297461F1C8E8D9A00FC134E /* TerminationListener.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TerminationListener.m; sourceTree = ""; }; 729746211C8E8F1100FC134E /* AppInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppInstaller.h; sourceTree = ""; }; @@ -876,6 +916,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 726E07EC1CAF37BD001A286B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 726E4A131C86C88F00C57C6A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -884,6 +931,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 728638F01CAF5A5F00783084 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DC2EF560486A6940098B216 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -910,6 +964,8 @@ 726B2B5D1C645FC900388755 /* UI Tests.xctest */, 726E4A161C86C88F00C57C6A /* TestAppHelper.xpc */, 726E07AD1CAF08D6001A286B /* InstallerLauncher.xpc */, + 726E07EF1CAF37BD001A286B /* UpdateDownloader.xpc */, + 728638F31CAF5A5F00783084 /* AppcastDownloader.xpc */, ); name = Products; sourceTree = ""; @@ -1029,6 +1085,7 @@ 61B5F8F309C4CE5900B25A18 /* Other Sources */, 61F83F6E0DBFE07A006FDD30 /* Update Control */, 726E07AE1CAF08D6001A286B /* InstallerLauncher */, + 726E07F01CAF37BD001A286B /* UpdateDownloader */, 61299B3A09CB056100B7442F /* User Interface */, ); path = Sparkle; @@ -1125,6 +1182,7 @@ 61299B3909CB055000B7442F /* Appcast Support */ = { isa = PBXGroup; children = ( + 728638F41CAF5A5F00783084 /* AppcastDownloader */, 61B5FB9409C4F04600B25A18 /* SUAppcast.h */, 61B5FB9509C4F04600B25A18 /* SUAppcast.m */, 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */, @@ -1323,6 +1381,21 @@ path = ../InstallerLauncher; sourceTree = ""; }; + 726E07F01CAF37BD001A286B /* UpdateDownloader */ = { + isa = PBXGroup; + children = ( + 726E07F11CAF37BD001A286B /* SUUpdateDownloaderProtocol.h */, + 726E08001CAF3F70001A286B /* SUDownloaderDelegate.h */, + 726E07F21CAF37BD001A286B /* SUUpdateDownloader.h */, + 726E07F31CAF37BD001A286B /* SUUpdateDownloader.m */, + 726E07F51CAF37BD001A286B /* main.m */, + 726E07F71CAF37BD001A286B /* Info.plist */, + 726E07FF1CAF3801001A286B /* UpdateDownloader.entitlements */, + ); + name = UpdateDownloader; + path = ../UpdateDownloader; + sourceTree = ""; + }; 726E4A171C86C88F00C57C6A /* TestAppHelper */ = { isa = PBXGroup; children = ( @@ -1336,6 +1409,20 @@ path = ../TestAppHelper; sourceTree = ""; }; + 728638F41CAF5A5F00783084 /* AppcastDownloader */ = { + isa = PBXGroup; + children = ( + 728638F51CAF5A5F00783084 /* SUAppcastDownloaderProtocol.h */, + 728638F61CAF5A5F00783084 /* SUAppcastDownloader.h */, + 728638F71CAF5A5F00783084 /* SUAppcastDownloader.m */, + 728638F91CAF5A5F00783084 /* main.m */, + 728638FB1CAF5A5F00783084 /* Info.plist */, + 728639031CAF5B3B00783084 /* AppcastDownloader.entitlements */, + ); + name = AppcastDownloader; + path = ../AppcastDownloader; + sourceTree = ""; + }; 729746481C91483B00FC134E /* IPC */ = { isa = PBXGroup; children = ( @@ -1399,6 +1486,8 @@ 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */, 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */, 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */, + 728638EE1CAF589C00783084 /* ConfigUpdateDownloader.xcconfig */, + 728639041CAF614000783084 /* ConfigAppcastDownloader.xcconfig */, 14732BC91960F70A00593899 /* make-release-package.sh */, 14652F7919A93E5F00959E44 /* set-git-version-info.sh */, 146EC84E19A68CF8004A50C5 /* Sparkle.podspec */, @@ -1433,6 +1522,7 @@ 72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, 7246E0A31C83B685003B4E75 /* SUStandardUpdaterController.h in Headers */, + 726E08011CAF3F70001A286B /* SUDownloaderDelegate.h in Headers */, 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, 72B767D61C9C8B5C00A07552 /* SUBasicUpdateDriver.h in Headers */, 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, @@ -1625,6 +1715,24 @@ productReference = 726E07AD1CAF08D6001A286B /* InstallerLauncher.xpc */; productType = "com.apple.product-type.xpc-service"; }; + 726E07EE1CAF37BD001A286B /* UpdateDownloader */ = { + isa = PBXNativeTarget; + buildConfigurationList = 726E07FB1CAF37BD001A286B /* Build configuration list for PBXNativeTarget "UpdateDownloader" */; + buildPhases = ( + 726E07EB1CAF37BD001A286B /* Sources */, + 726E07EC1CAF37BD001A286B /* Frameworks */, + 726E07ED1CAF37BD001A286B /* Resources */, + 728639061CAF651300783084 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = UpdateDownloader; + productName = UpdateDownloader; + productReference = 726E07EF1CAF37BD001A286B /* UpdateDownloader.xpc */; + productType = "com.apple.product-type.xpc-service"; + }; 726E4A151C86C88F00C57C6A /* TestAppHelper */ = { isa = PBXNativeTarget; buildConfigurationList = 726E4A221C86C88F00C57C6A /* Build configuration list for PBXNativeTarget "TestAppHelper" */; @@ -1642,6 +1750,24 @@ productReference = 726E4A161C86C88F00C57C6A /* TestAppHelper.xpc */; productType = "com.apple.product-type.xpc-service"; }; + 728638F21CAF5A5F00783084 /* AppcastDownloader */ = { + isa = PBXNativeTarget; + buildConfigurationList = 728638FF1CAF5A5F00783084 /* Build configuration list for PBXNativeTarget "AppcastDownloader" */; + buildPhases = ( + 728638EF1CAF5A5F00783084 /* Sources */, + 728638F01CAF5A5F00783084 /* Frameworks */, + 728638F11CAF5A5F00783084 /* Resources */, + 728639051CAF64EF00783084 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = AppcastDownloader; + productName = AppcastDownloader; + productReference = 728638F31CAF5A5F00783084 /* AppcastDownloader.xpc */; + productType = "com.apple.product-type.xpc-service"; + }; 8DC2EF4F0486A6940098B216 /* Sparkle */ = { isa = PBXNativeTarget; buildConfigurationList = 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "Sparkle" */; @@ -1661,6 +1787,8 @@ dependencies = ( 55C14F97136F044100649790 /* PBXTargetDependency */, 726E07B71CAF08D6001A286B /* PBXTargetDependency */, + 726E07F91CAF37BD001A286B /* PBXTargetDependency */, + 728638FD1CAF5A5F00783084 /* PBXTargetDependency */, ); name = Sparkle; productInstallPath = "$(HOME)/Library/Frameworks"; @@ -1696,6 +1824,14 @@ 726E07AC1CAF08D6001A286B = { CreatedOnToolsVersion = 7.3; }; + 726E07EE1CAF37BD001A286B = { + CreatedOnToolsVersion = 7.3; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; 726E4A151C86C88F00C57C6A = { CreatedOnToolsVersion = 7.2.1; SystemCapabilities = { @@ -1704,6 +1840,14 @@ }; }; }; + 728638F21CAF5A5F00783084 = { + CreatedOnToolsVersion = 7.3; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; }; }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Sparkle" */; @@ -1765,6 +1909,8 @@ targets = ( 8DC2EF4F0486A6940098B216 /* Sparkle */, 726E07AC1CAF08D6001A286B /* InstallerLauncher */, + 726E07EE1CAF37BD001A286B /* UpdateDownloader */, + 728638F21CAF5A5F00783084 /* AppcastDownloader */, 61B5F90109C4CEE200B25A18 /* Sparkle Test App */, 726E4A151C86C88F00C57C6A /* TestAppHelper */, 612279D80DB5470200AB99EA /* Sparkle Unit Tests */, @@ -1836,6 +1982,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 726E07ED1CAF37BD001A286B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 726E4A141C86C88F00C57C6A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1843,6 +1996,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 728638F11CAF5A5F00783084 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DC2EF520486A6940098B216 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1851,7 +2011,6 @@ 615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */, 55C14BEF136EF21700649790 /* SUStatus.xib in Resources */, 55C14C04136EF26100649790 /* SUUpdateAlert.xib in Resources */, - 726E07C21CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig in Resources */, 55C14C19136EF2C700649790 /* SUUpdatePermissionPrompt.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1923,6 +2082,32 @@ shellScript = "ln -sfh \"pt_BR.lproj\" \"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/pt.lproj\""; showEnvVarsInLog = 0; }; + 728639051CAF64EF00783084 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# http://stackoverflow.com/questions/32390228/is-it-possible-to-disable-ats-in-ios-9-just-for-debug-environment\n#Disables ATS in debug builds.\nINFOPLIST=\"${TARGET_BUILD_DIR}\"/\"${INFOPLIST_PATH}\"\ncase \"${CONFIGURATION}\" in\n\"Release\"|\"Adhoc\")\n/usr/libexec/PlistBuddy -c \"Set :NSAppTransportSecurity:NSAllowsArbitraryLoads NO\" \"${INFOPLIST}\"\n;;\n\"Debug\")\n/usr/libexec/PlistBuddy -c \"Set :NSAppTransportSecurity:NSAllowsArbitraryLoads YES\" \"${INFOPLIST}\"\n;;\nesac"; + }; + 728639061CAF651300783084 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# http://stackoverflow.com/questions/32390228/is-it-possible-to-disable-ats-in-ios-9-just-for-debug-environment\n#Disables ATS in debug builds.\nINFOPLIST=\"${TARGET_BUILD_DIR}\"/\"${INFOPLIST_PATH}\"\ncase \"${CONFIGURATION}\" in\n\"Release\"|\"Adhoc\")\n/usr/libexec/PlistBuddy -c \"Set :NSAppTransportSecurity:NSAllowsArbitraryLoads NO\" \"${INFOPLIST}\"\n;;\n\"Debug\")\n/usr/libexec/PlistBuddy -c \"Set :NSAppTransportSecurity:NSAllowsArbitraryLoads YES\" \"${INFOPLIST}\"\n;;\nesac"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -2045,6 +2230,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 726E07EB1CAF37BD001A286B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 728638ED1CAF50CE00783084 /* SUConstants.m in Sources */, + 726E07F61CAF37BD001A286B /* main.m in Sources */, + 726E07F41CAF37BD001A286B /* SUUpdateDownloader.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 726E4A121C86C88F00C57C6A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2055,6 +2250,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 728638EF1CAF5A5F00783084 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 728638FA1CAF5A5F00783084 /* main.m in Sources */, + 728638F81CAF5A5F00783084 /* SUAppcastDownloader.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DC2EF540486A6940098B216 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2177,11 +2381,21 @@ target = 726E07AC1CAF08D6001A286B /* InstallerLauncher */; targetProxy = 726E07B61CAF08D6001A286B /* PBXContainerItemProxy */; }; + 726E07F91CAF37BD001A286B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 726E07EE1CAF37BD001A286B /* UpdateDownloader */; + targetProxy = 726E07F81CAF37BD001A286B /* PBXContainerItemProxy */; + }; 726E4A201C86C88F00C57C6A /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 726E4A151C86C88F00C57C6A /* TestAppHelper */; targetProxy = 726E4A1F1C86C88F00C57C6A /* PBXContainerItemProxy */; }; + 728638FD1CAF5A5F00783084 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 728638F21CAF5A5F00783084 /* AppcastDownloader */; + targetProxy = 728638FC1CAF5A5F00783084 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -2579,6 +2793,30 @@ }; name = Release; }; + 726E07FC1CAF37BD001A286B /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 728638EE1CAF589C00783084 /* ConfigUpdateDownloader.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + }; + name = Debug; + }; + 726E07FD1CAF37BD001A286B /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 728638EE1CAF589C00783084 /* ConfigUpdateDownloader.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + }; + name = Coverage; + }; + 726E07FE1CAF37BD001A286B /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 728638EE1CAF589C00783084 /* ConfigUpdateDownloader.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + }; + name = Release; + }; 726E4A231C86C88F00C57C6A /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 726E4A271C86CAB500C57C6A /* ConfigTestAppDebugHelper.xcconfig */; @@ -2600,6 +2838,27 @@ }; name = Release; }; + 728639001CAF5A5F00783084 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 728639041CAF614000783084 /* ConfigAppcastDownloader.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + 728639011CAF5A5F00783084 /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 728639041CAF614000783084 /* ConfigAppcastDownloader.xcconfig */; + buildSettings = { + }; + name = Coverage; + }; + 728639021CAF5A5F00783084 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 728639041CAF614000783084 /* ConfigAppcastDownloader.xcconfig */; + buildSettings = { + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -2711,6 +2970,17 @@ 726E07BC1CAF08D6001A286B /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 726E07FB1CAF37BD001A286B /* Build configuration list for PBXNativeTarget "UpdateDownloader" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 726E07FC1CAF37BD001A286B /* Debug */, + 726E07FD1CAF37BD001A286B /* Coverage */, + 726E07FE1CAF37BD001A286B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 726E4A221C86C88F00C57C6A /* Build configuration list for PBXNativeTarget "TestAppHelper" */ = { isa = XCConfigurationList; @@ -2722,6 +2992,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 728638FF1CAF5A5F00783084 /* Build configuration list for PBXNativeTarget "AppcastDownloader" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 728639001CAF5A5F00783084 /* Debug */, + 728639011CAF5A5F00783084 /* Coverage */, + 728639021CAF5A5F00783084 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = 0867D690FE84028FC02AAC07 /* Project object */; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 0ae23554..38f59572 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -14,6 +14,7 @@ #import "SULog.h" #import "SUErrors.h" #import "SULocalizations.h" +#import "SUAppcastDownloaderProtocol.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -45,8 +46,6 @@ @interface SUAppcast () @property (strong) void (^completionBlock)(NSError *); -@property (copy) NSString *downloadFilename; -@property (strong) NSURLDownload *download; @property (copy) NSArray *items; - (void)reportError:(NSError *)error; - (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes; @@ -54,11 +53,9 @@ @implementation SUAppcast -@synthesize downloadFilename; @synthesize completionBlock; @synthesize userAgentString; @synthesize httpHeaders; -@synthesize download; @synthesize items; - (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *))block @@ -79,60 +76,43 @@ [request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"]; - self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + NSXPCConnection *connection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.AppcastDownloader"]; + connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUAppcastDownloaderProtocol)]; + [connection resume]; + + [connection.remoteObjectProxy startDownloadWithRequest:request completion:^(NSData * _Nullable appcastData, NSError * _Nullable error) { + [connection invalidate]; + + dispatch_async(dispatch_get_main_queue(), ^{ + if (appcastData == nil) { + [self reportError:error]; + } else { + NSError *parseError = nil; + NSArray *appcastItems = [self parseAppcastItemsFromXMLData:appcastData error:&parseError]; + + if (appcastItems != nil) { + self.items = appcastItems; + self.completionBlock(nil); + self.completionBlock = nil; + } else { + NSMutableDictionary *userInfo = [NSMutableDictionary + dictionaryWithObject: SULocalizedString(@"An error occurred while parsing the update feed.", nil) + forKey: NSLocalizedDescriptionKey]; + if (parseError != nil) { + [userInfo setObject:parseError forKey:NSUnderlyingErrorKey]; + } + [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain + code:SUAppcastParseError + userInfo:userInfo]]; + } + } + }); + }]; } -- (void)download:(NSURLDownload *)__unused aDownload decideDestinationWithSuggestedFilename:(NSString *)filename -{ - NSString *destinationFilename = NSTemporaryDirectory(); - if (destinationFilename) - { - destinationFilename = [destinationFilename stringByAppendingPathComponent:filename]; - [self.download setDestination:destinationFilename allowOverwrite:NO]; - } -} - -- (void)download:(NSURLDownload *)__unused aDownload didCreateDestination:(NSString *)path -{ - self.downloadFilename = path; -} - -- (void)downloadDidFinish:(NSURLDownload *)__unused aDownload -{ - NSError *error = nil; - NSArray *appcastItems = [self parseAppcastItemsFromXMLFile:[NSURL fileURLWithPath:self.downloadFilename] error:&error]; - - [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil]; - self.downloadFilename = nil; - - if (appcastItems) { - self.items = appcastItems; - self.completionBlock(nil); - self.completionBlock = nil; - } else { - NSMutableDictionary *userInfo = [NSMutableDictionary - dictionaryWithObject: SULocalizedString(@"An error occurred while parsing the update feed.", nil) - forKey: NSLocalizedDescriptionKey]; - if (error) { - [userInfo setObject:error forKey:NSUnderlyingErrorKey]; - } - [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain - code:SUAppcastParseError - userInfo:userInfo]]; - } -} - --(NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp { - if (errorp) { - *errorp = nil; - } - - if (!appcastFile) { - return nil; - } - +-(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData error:(NSError *__autoreleasing*)errorp { NSUInteger options = NSXMLNodeLoadExternalEntitiesNever; // Prevent inclusion from file:// - NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:appcastFile options:options error:errorp]; + NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:appcastData options:options error:errorp]; if (nil == document) { return nil; } @@ -232,21 +212,6 @@ return appcastItems; } -- (void)download:(NSURLDownload *)__unused aDownload didFailWithError:(NSError *)error -{ - if (self.downloadFilename) { - [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil]; - } - self.downloadFilename = nil; - - [self reportError:error]; -} - -- (NSURLRequest *)download:(NSURLDownload *)__unused aDownload willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)__unused redirectResponse -{ - return request; -} - - (void)reportError:(NSError *)error { NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ diff --git a/Sparkle/SUCoreBasedUpdateDriver.m b/Sparkle/SUCoreBasedUpdateDriver.m index d6b9321e..2df12e1b 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.m +++ b/Sparkle/SUCoreBasedUpdateDriver.m @@ -115,7 +115,7 @@ - (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem { - self.downloadDriver = [[SUDownloadDriver alloc] initWithUpdateItem:updateItem host:self.host cachePath:[[self class] sparkleCachePathForHost:self.host] userAgent:self.userAgent delegate:self]; + self.downloadDriver = [[SUDownloadDriver alloc] initWithUpdateItem:updateItem host:self.host userAgent:self.userAgent delegate:self]; if ([self.updaterDelegate respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { [self.updaterDelegate updater:self.updater diff --git a/Sparkle/SUDownloadDriver.h b/Sparkle/SUDownloadDriver.h index 0369761f..a0a7bd1f 100644 --- a/Sparkle/SUDownloadDriver.h +++ b/Sparkle/SUDownloadDriver.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUDownloadDriver : NSObject -- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host cachePath:(NSString *)cachePath userAgent:(NSString *)userAgent delegate:(id)delegate; +- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id)delegate; - (void)downloadUpdate; diff --git a/Sparkle/SUDownloadDriver.m b/Sparkle/SUDownloadDriver.m index 6368d673..e899237d 100644 --- a/Sparkle/SUDownloadDriver.m +++ b/Sparkle/SUDownloadDriver.m @@ -7,6 +7,8 @@ // #import "SUDownloadDriver.h" +#import "SUDownloaderDelegate.h" +#import "SUUpdateDownloaderProtocol.h" #import "SUAppcastItem.h" #import "SUFileManager.h" #import "SULocalizations.h" @@ -17,12 +19,11 @@ #error This is a "core" class and should NOT import AppKit #endif -@interface SUDownloadDriver () +@interface SUDownloadDriver () +@property (nonatomic) NSXPCConnection *connection; @property (nonatomic, readonly) SUAppcastItem *updateItem; @property (nonatomic, readonly) SUHost *host; -@property (nonatomic, readonly, copy) NSString *cachePath; -@property (nonatomic) NSURLDownload *download; @property (nonatomic, copy) NSString *temporaryDirectory; @property (nonatomic, copy) NSString *downloadPath; @property (nonatomic, weak) id delegate; @@ -31,33 +32,41 @@ @implementation SUDownloadDriver +@synthesize connection = _connection; @synthesize updateItem = _updateItem; @synthesize request = _request; @synthesize host = _host; -@synthesize cachePath = _cachePath; -@synthesize download = _download; @synthesize temporaryDirectory = _temporaryDirectory; @synthesize downloadPath = _downloadPath; @synthesize delegate = _delegate; -- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host cachePath:(NSString *)cachePath userAgent:(NSString *)userAgent delegate:(id)delegate +- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id)delegate { self = [super init]; if (self != nil) { _updateItem = updateItem; _host = host; - _cachePath = [cachePath copy]; _delegate = delegate; _request = [NSMutableURLRequest requestWithURL:updateItem.fileURL]; [_request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; + + _connection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.UpdateDownloader"]; + _connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUUpdateDownloaderProtocol)]; + _connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUDownloaderDelegate)]; + _connection.exportedObject = self; } return self; } - (void)downloadUpdate { - self.download = [[NSURLDownload alloc] initWithRequest:self.request delegate:self]; + [self.connection resume]; + + NSString *bundleIdentifier = self.host.bundle.bundleIdentifier; + assert(bundleIdentifier != nil); + + [self.connection.remoteObjectProxy startDownloadWithRequest:self.request bundleIdentifier:bundleIdentifier desiredFilename:[NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]]]; } - (void)dealloc @@ -72,105 +81,75 @@ - (void)cleanup { - NSString *temporaryDirectory = self.temporaryDirectory; - if (temporaryDirectory != nil) // temporaryDirectory contains downloadPath, so we implicitly delete both here. - { - if ([[NSFileManager defaultManager] fileExistsAtPath:temporaryDirectory]) { - BOOL success = [[NSFileManager defaultManager] removeItemAtPath:temporaryDirectory error:NULL]; // Clean up the copied relauncher - if (!success) { - NSURL *tempDirURL = [NSURL fileURLWithPath:temporaryDirectory]; - if (tempDirURL != nil) { - [[SUFileManager fileManagerAllowingAuthorization:NO] moveItemAtURLToTrash:tempDirURL error:NULL]; - } - } - } - } - - if (self.download != nil) { - [self.download cancel]; - self.download = nil; + if (self.connection != nil) { + [self.connection invalidate]; + self.connection = nil; } self.downloadPath = nil; } -- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name +- (void)downloaderDidSetDestination:(NSString *)destinationPath temporaryDirectory:(NSString *)temporaryDirectory { - NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]]; - - NSString *cachePath = self.cachePath; - NSString *tempDir = [cachePath stringByAppendingPathComponent:downloadFileName]; - int count = 1; - while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && count <= 999) - { - tempDir = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, count++]]; - } - - // Create the temporary directory if necessary. - BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL]; - if (!success) - { - // Okay, something's really broken with this user's file structure. - [self.download cancel]; - self.download = nil; - - NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.", tempDir] }]; - + dispatch_async(dispatch_get_main_queue(), ^{ + self.downloadPath = destinationPath; + self.temporaryDirectory = temporaryDirectory; + }); +} + +- (void)downloaderDidFailToCreateTemporaryDirectoryWithError:(NSError *)error +{ + dispatch_async(dispatch_get_main_queue(), ^{ [self cleanup]; [self.delegate downloadDriverDidFailToDownloadUpdateWithError:error]; - } else { - NSString *downloadPath = [tempDir stringByAppendingPathComponent:name]; - self.downloadPath = downloadPath; - [self.download setDestination:downloadPath allowOverwrite:YES]; - } - - self.temporaryDirectory = tempDir; + }); } -- (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response +- (void)downloaderDidReceiveResponse:(NSURLResponse *)response { - [self.delegate downloadDriverDidReceiveResponse:response]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate downloadDriverDidReceiveResponse:response]; + }); } -- (void)download:(NSURLDownload *)__unused download didReceiveDataOfLength:(NSUInteger)length +- (void)downloaderDidReceiveDataOfLength:(NSUInteger)length { - [self.delegate downloadDriverDidReceiveDataOfLength:length]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate downloadDriverDidReceiveDataOfLength:length]; + }); } -- (void)downloadDidFinish:(NSURLDownload *)__unused d +- (void)downloaderDidFinish { - assert(self.updateItem); - - // If this fails, then we must have already cleaned up / cancelled - if (self.download != nil && self.downloadPath != nil) { - self.download = nil; - [self.delegate downloadDriverDidDownloadUpdate]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + // If this fails, then we must have already cleaned up / cancelled + if (self.connection != nil) { + [self.connection invalidate]; + self.connection = nil; + + [self.delegate downloadDriverDidDownloadUpdate]; + } + }); } -- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error +- (void)downloaderDidFailWithError:(NSError *)error { - NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey]; - if (!failingUrl) { - failingUrl = [self.updateItem fileURL]; - } - - NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ - NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), - NSUnderlyingErrorKey: error, - }]; - if (failingUrl) { - userInfo[NSURLErrorFailingURLErrorKey] = failingUrl; - } - - NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]; - [self.delegate downloadDriverDidFailToDownloadUpdateWithError:downloadError]; -} - -- (BOOL)download:(NSURLDownload *)__unused download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType -{ - // We don't want the download system to extract our gzips. - // Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug. - return ([encodingType rangeOfString:@"gzip"].location == NSNotFound); + dispatch_async(dispatch_get_main_queue(), ^{ + NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey]; + if (!failingUrl) { + failingUrl = [self.updateItem fileURL]; + } + + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ + NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), + NSUnderlyingErrorKey: error, + }]; + if (failingUrl) { + userInfo[NSURLErrorFailingURLErrorKey] = failingUrl; + } + + NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]; + [self.delegate downloadDriverDidFailToDownloadUpdateWithError:downloadError]; + }); } @end diff --git a/Sparkle/SUDownloaderDelegate.h b/Sparkle/SUDownloaderDelegate.h new file mode 100644 index 00000000..5ac57c01 --- /dev/null +++ b/Sparkle/SUDownloaderDelegate.h @@ -0,0 +1,29 @@ +// +// SUDownloaderDelegate.h +// Sparkle +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol SUDownloaderDelegate + +- (void)downloaderDidSetDestination:(NSString *)destinationPath temporaryDirectory:(NSString *)temporaryDirectory; + +- (void)downloaderDidFailToCreateTemporaryDirectoryWithError:(NSError *)error; + +- (void)downloaderDidReceiveResponse:(NSURLResponse *)response; + +- (void)downloaderDidReceiveDataOfLength:(NSUInteger)length; + +- (void)downloaderDidFinish; + +- (void)downloaderDidFailWithError:(NSError *)error; + +@end + +NS_ASSUME_NONNULL_END diff --git a/TestApplication/Sparkle-Test-App.entitlements b/TestApplication/Sparkle-Test-App.entitlements index ec177ea6..73b46eaa 100644 --- a/TestApplication/Sparkle-Test-App.entitlements +++ b/TestApplication/Sparkle-Test-App.entitlements @@ -4,16 +4,12 @@ com.apple.security.app-sandbox - com.apple.security.network.server - com.apple.security.network.client - com.apple.security.temporary-exception.mach-lookup.global-name org.sparkle-project.SparkleTestApp-sparkle-installer - com.apple.security.temporary-exception.shared-preference.read-write org.sparkle-project.SparkleTestApp diff --git a/UpdateDownloader/Info.plist b/UpdateDownloader/Info.plist new file mode 100644 index 00000000..537ba7b0 --- /dev/null +++ b/UpdateDownloader/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + UpdateDownloader + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + NSHumanReadableCopyright + Copyright © 2016 Sparkle Project. All rights reserved. + XPCService + + ServiceType + Application + RunLoopType + NSRunLoop + + + diff --git a/UpdateDownloader/SUUpdateDownloader.h b/UpdateDownloader/SUUpdateDownloader.h new file mode 100644 index 00000000..b992f643 --- /dev/null +++ b/UpdateDownloader/SUUpdateDownloader.h @@ -0,0 +1,19 @@ +// +// SUUpdateDownloader.h +// UpdateDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUUpdateDownloaderProtocol.h" + +@protocol SUDownloaderDelegate; + +// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection. +@interface SUUpdateDownloader : NSObject + +- (instancetype)initWithDelegate:(id )delegate; + +@end diff --git a/UpdateDownloader/SUUpdateDownloader.m b/UpdateDownloader/SUUpdateDownloader.m new file mode 100644 index 00000000..9a3212ed --- /dev/null +++ b/UpdateDownloader/SUUpdateDownloader.m @@ -0,0 +1,128 @@ +// +// SUUpdateDownloader.m +// UpdateDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUUpdateDownloader.h" +#import "SUDownloaderDelegate.h" +#import "SUErrors.h" + +@interface SUUpdateDownloader () + +@property (nonatomic) id delegate; +@property (nonatomic) NSURLDownload *download; +@property (nonatomic, copy) NSString *bundleIdentifier; +@property (nonatomic, copy) NSString *desiredFilename; + +@end + +@implementation SUUpdateDownloader + +@synthesize delegate = _delegate; +@synthesize download = _download; +@synthesize bundleIdentifier = _bundleIdentifier; +@synthesize desiredFilename = _desiredFilename; + +- (instancetype)initWithDelegate:(id )delegate +{ + self = [super init]; + if (self != nil) { + _delegate = delegate; + } + return self; +} + +- (void)dealloc +{ + [self.download cancel]; + self.download = nil; +} + +- (void)startDownloadWithRequest:(NSURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + self.desiredFilename = desiredFilename; + self.bundleIdentifier = bundleIdentifier; + + // Remove our old caches path so we don't start accumulating files in there + NSString *cachePath = [[self class] sparkleCachePathForBundleIdentifier:self.bundleIdentifier]; + if ([[NSFileManager defaultManager] fileExistsAtPath:cachePath]) { + [[NSFileManager defaultManager] removeItemAtPath:cachePath error:NULL]; + } + }); +} + +// If we support sandboxing this component in the future, it is important to note this may return a different path +// For this reason, this method should not be a part of SUHost because its behavior depends on what kind of process it's being invoked from ++ (NSString *)sparkleCachePathForBundleIdentifier:(NSString *)bundleIdentifier +{ + NSURL *cacheURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL]; + + assert(cacheURL != nil); + return [[[cacheURL URLByAppendingPathComponent:bundleIdentifier] URLByAppendingPathComponent:@"Sparkle"] path]; +} + +- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name +{ + NSString *downloadFileName = self.desiredFilename; + + NSString *cachePath = [[self class] sparkleCachePathForBundleIdentifier:self.bundleIdentifier]; + + NSString *tempDir = [cachePath stringByAppendingPathComponent:downloadFileName]; + int count = 1; + while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && count <= 999) + { + tempDir = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, count++]]; + } + + // Create the temporary directory if necessary. + BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL]; + if (!success) + { + // Okay, something's really broken with this user's file structure. + [self.download cancel]; + self.download = nil; + + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.", tempDir] }]; + + [self.delegate downloaderDidFailToCreateTemporaryDirectoryWithError:error]; + } else { + NSString *downloadPath = [tempDir stringByAppendingPathComponent:name]; + [self.download setDestination:downloadPath allowOverwrite:YES]; + + [self.delegate downloaderDidSetDestination:downloadPath temporaryDirectory:tempDir]; + } +} + +- (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response +{ + [self.delegate downloaderDidReceiveResponse:response]; +} + +- (void)download:(NSURLDownload *)__unused download didReceiveDataOfLength:(NSUInteger)length +{ + [self.delegate downloaderDidReceiveDataOfLength:length]; +} + +- (void)downloadDidFinish:(NSURLDownload *)__unused d +{ + [self.delegate downloaderDidFinish]; +} + +- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error +{ + [self.delegate downloaderDidFailWithError:error]; +} + +- (BOOL)download:(NSURLDownload *)__unused download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType +{ + // We don't want the download system to extract our gzips. + // Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug. + return ([encodingType rangeOfString:@"gzip"].location == NSNotFound); +} + +@end diff --git a/UpdateDownloader/SUUpdateDownloaderProtocol.h b/UpdateDownloader/SUUpdateDownloaderProtocol.h new file mode 100644 index 00000000..04596f04 --- /dev/null +++ b/UpdateDownloader/SUUpdateDownloaderProtocol.h @@ -0,0 +1,20 @@ +// +// SUUpdateDownloaderProtocol.h +// UpdateDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service. +@protocol SUUpdateDownloaderProtocol + +- (void)startDownloadWithRequest:(NSURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename; + +@end + +NS_ASSUME_NONNULL_END diff --git a/UpdateDownloader/UpdateDownloader.entitlements b/UpdateDownloader/UpdateDownloader.entitlements new file mode 100644 index 00000000..ee95ab7e --- /dev/null +++ b/UpdateDownloader/UpdateDownloader.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/UpdateDownloader/main.m b/UpdateDownloader/main.m new file mode 100644 index 00000000..5d21ab6d --- /dev/null +++ b/UpdateDownloader/main.m @@ -0,0 +1,53 @@ +// +// main.m +// UpdateDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUUpdateDownloader.h" +#import "SUDownloaderDelegate.h" + +@interface ServiceDelegate : NSObject +@end + +@implementation ServiceDelegate + +- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection { + // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection. + + // Configure the connection. + // First, set the interface that the exported object implements. + newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUUpdateDownloaderProtocol)]; + + // Then set remote object interface + newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUDownloaderDelegate)]; + + // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object. + SUUpdateDownloader *exportedObject = [[SUUpdateDownloader alloc] initWithDelegate:newConnection.remoteObjectProxy]; + newConnection.exportedObject = exportedObject; + + // Resuming the connection allows the system to deliver more incoming messages. + [newConnection resume]; + + // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO. + return YES; +} + +@end + +int main(int __unused argc, const char * __unused argv[]) +{ + // Create the delegate for the service. + ServiceDelegate *delegate = [ServiceDelegate new]; + + // Set up the one NSXPCListener for this service. It will handle all incoming connections. + NSXPCListener *listener = [NSXPCListener serviceListener]; + listener.delegate = delegate; + + // Resuming the serviceListener starts this service. This method does not return. + [listener resume]; + return 0; +}