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.
This commit is contained in:
Zorg committed 2016-04-01 22:41:12 -04:00
1 parent 9525b156a2
commit e74a397152
21 files changed
+906 -166

No files matched your search

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
+40
View File
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>AppcastDownloader</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>XPCService</key>
<dict>
<key>RunLoopType</key>
<string>NSRunLoop</string>
<key>ServiceType</key>
<string>Application</string>
</dict>
</dict>
</plist>
+14
View File
@@ -0,0 +1,14 @@
//
// SUAppcastDownloader.h
// AppcastDownloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#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 <SUAppcastDownloaderProtocol>
@end
+75
View File
@@ -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 () <NSURLDownloadDelegate>
@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
@@ -0,0 +1,20 @@
//
// SUAppcastDownloaderProtocol.h
// AppcastDownloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
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
+49
View File
@@ -0,0 +1,49 @@
//
// main.m
// AppcastDownloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SUAppcastDownloader.h"
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@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;
}
@@ -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 = -
@@ -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 = -
+281 -2
View File
@@ -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 = "<group>"; };
726E07E71CAF30C0001A286B /* SUUpdaterPermission.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterPermission.h; sourceTree = "<group>"; };
726E07E81CAF30C0001A286B /* SUUpdaterPermission.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterPermission.m; sourceTree = "<group>"; };
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 = "<group>"; };
726E07F21CAF37BD001A286B /* SUUpdateDownloader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUUpdateDownloader.h; sourceTree = "<group>"; };
726E07F31CAF37BD001A286B /* SUUpdateDownloader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDownloader.m; sourceTree = "<group>"; };
726E07F51CAF37BD001A286B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
726E07F71CAF37BD001A286B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
726E07FF1CAF3801001A286B /* UpdateDownloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = UpdateDownloader.entitlements; sourceTree = "<group>"; };
726E08001CAF3F70001A286B /* SUDownloaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUDownloaderDelegate.h; path = ../Sparkle/SUDownloaderDelegate.h; sourceTree = "<group>"; };
726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverUIDelegate.h; sourceTree = "<group>"; };
726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverRemoteDelegate.h; sourceTree = "<group>"; };
726E4A111C86C44A00C57C6A /* Sparkle-Test-App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Sparkle-Test-App.entitlements"; sourceTree = "<group>"; };
@@ -736,6 +767,15 @@
7275F9C01B5F1F2900B1D19E /* SUFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileManager.m; sourceTree = "<group>"; };
728337A41C9E6FF40085AA99 /* SUProbeInstallStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbeInstallStatus.h; sourceTree = "<group>"; };
728337A51C9E6FF40085AA99 /* SUProbeInstallStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUProbeInstallStatus.m; sourceTree = "<group>"; };
728638EE1CAF589C00783084 /* ConfigUpdateDownloader.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUpdateDownloader.xcconfig; sourceTree = "<group>"; };
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 = "<group>"; };
728638F61CAF5A5F00783084 /* SUAppcastDownloader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUAppcastDownloader.h; sourceTree = "<group>"; };
728638F71CAF5A5F00783084 /* SUAppcastDownloader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUAppcastDownloader.m; sourceTree = "<group>"; };
728638F91CAF5A5F00783084 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
728638FB1CAF5A5F00783084 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
728639031CAF5B3B00783084 /* AppcastDownloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = AppcastDownloader.entitlements; sourceTree = "<group>"; };
728639041CAF614000783084 /* ConfigAppcastDownloader.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigAppcastDownloader.xcconfig; sourceTree = "<group>"; };
7297461E1C8E8D9A00FC134E /* TerminationListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TerminationListener.h; sourceTree = "<group>"; };
7297461F1C8E8D9A00FC134E /* TerminationListener.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TerminationListener.m; sourceTree = "<group>"; };
729746211C8E8F1100FC134E /* AppInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppInstaller.h; sourceTree = "<group>"; };
@@ -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 = "<group>";
@@ -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 = "<group>";
};
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 = "<group>";
};
726E4A171C86C88F00C57C6A /* TestAppHelper */ = {
isa = PBXGroup;
children = (
@@ -1336,6 +1409,20 @@
path = ../TestAppHelper;
sourceTree = "<group>";
};
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 = "<group>";
};
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 */;
+35 -70
View File
@@ -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 () <NSURLDownloadDelegate>
@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:@{
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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<SUDownloadDriverDelegate>)delegate;
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)delegate;
- (void)downloadUpdate;
+67 -88
View File
@@ -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 () <NSURLDownloadDelegate>
@interface SUDownloadDriver () <SUDownloaderDelegate>
@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<SUDownloadDriverDelegate> 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<SUDownloadDriverDelegate>)delegate
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)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
+29
View File
@@ -0,0 +1,29 @@
//
// SUDownloaderDelegate.h
// Sparkle
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol SUDownloaderDelegate <NSObject>
- (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
@@ -4,16 +4,12 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- server exception is only needed because the test app launches a web server instance -->
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
<array>
<string>org.sparkle-project.SparkleTestApp-sparkle-installer</string>
</array>
<!-- shared preference exception may only needed when the main app and Sparkle are in separate processes -->
<key>com.apple.security.temporary-exception.shared-preference.read-write</key>
<array>
<string>org.sparkle-project.SparkleTestApp</string>
+40
View File
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>UpdateDownloader</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
<key>XPCService</key>
<dict>
<key>ServiceType</key>
<string>Application</string>
<key>RunLoopType</key>
<string>NSRunLoop</string>
</dict>
</dict>
</plist>
+19
View File
@@ -0,0 +1,19 @@
//
// SUUpdateDownloader.h
// UpdateDownloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#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 <SUUpdateDownloaderProtocol>
- (instancetype)initWithDelegate:(id <SUDownloaderDelegate>)delegate;
@end
+128
View File
@@ -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 () <NSURLDownloadDelegate>
@property (nonatomic) id <SUDownloaderDelegate> 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 <SUDownloaderDelegate>)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
@@ -0,0 +1,20 @@
//
// SUUpdateDownloaderProtocol.h
// UpdateDownloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
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
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
+53
View File
@@ -0,0 +1,53 @@
//
// main.m
// UpdateDownloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SUUpdateDownloader.h"
#import "SUDownloaderDelegate.h"
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@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;
}