Skip to content

Commit

Permalink
Merge pull request #28 from mipstian/sandbox_helper
Browse files Browse the repository at this point in the history
Sandbox feed checker helper
  • Loading branch information
Giorgio Calderolla committed Jun 23, 2014
2 parents fe640c7 + f3aec8a commit 106e078
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
17 changes: 16 additions & 1 deletion CTCScheduler.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,25 @@ - (void)callFeedCheckerWithReplyHandler:(CTCFeedCheckCompletionHandler)replyHand
// Extract URLs from history
NSArray *previouslyDownloadedURLs = [history valueForKey:@"url"];

// Create a bookmark so we can transfer access to the downloads path
// to the feed checker service
NSURL *downloadFolderURL = [NSURL fileURLWithPath:downloadPath];
NSError *error = nil;
NSData *downloadFolderBookmark = [downloadFolderURL bookmarkDataWithOptions:NSURLBookmarkCreationMinimalBookmark
includingResourceValuesForKeys:@[]
relativeToURL:nil
error:&error];
if (!downloadFolderBookmark || error) {
NSLog(@"Couldn't create bookmark for downloads folder: %@", error);

// Not really handling this error
return;
}

// Call feed checker service
CTCFeedChecker *feedChecker = [self.feedCheckerConnection remoteObjectProxy];
[feedChecker checkShowRSSFeed:feedURL
downloadingToPath:downloadPath
downloadingToBookmark:downloadFolderBookmark
organizingByFolder:organizeByFolder
skippingURLs:previouslyDownloadedURLs
withReply:^(NSArray *downloadedFeedFiles, NSError *error) {
Expand Down
13 changes: 13 additions & 0 deletions Catch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
4401571C1957A3150041D148 /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/UI.strings; sourceTree = "<group>"; };
4401571D1957A3150041D148 /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
4403ACF31914041C002F286C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4412E8161957F09200701124 /* com.giorgiocalderolla.Catch.CatchFeedHelper.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = com.giorgiocalderolla.Catch.CatchFeedHelper.entitlements; sourceTree = "<group>"; };
4419CF37180627A900C77432 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
4456EE5F1916D20000B3FF1A /* NSDate+TimeOfDayMath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+TimeOfDayMath.h"; sourceTree = "<group>"; };
4456EE601916D20000B3FF1A /* NSDate+TimeOfDayMath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+TimeOfDayMath.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -319,6 +320,7 @@
44717AC61913A08700580054 /* CatchFeedHelper */ = {
isa = PBXGroup;
children = (
4412E8161957F09200701124 /* com.giorgiocalderolla.Catch.CatchFeedHelper.entitlements */,
44717AD71913A1C900580054 /* CTCFeedChecker.h */,
44717AD81913A1C900580054 /* CTCFeedChecker.m */,
44717AAB19131BC700580054 /* CTCFeedParser.h */,
Expand Down Expand Up @@ -418,6 +420,13 @@
446D8B551918D146007AB22D = {
TestTargetID = 8D1107260486CEB800E47090;
};
44717AC31913A08700580054 = {
SystemCapabilities = {
com.apple.Sandbox = {
enabled = 1;
};
};
};
};
};
buildConfigurationList = 26FC0A880875C7B200E6366F /* Build configuration list for PBXProject "Catch" */;
Expand Down Expand Up @@ -762,6 +771,8 @@
44717ACF1913A08700580054 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = CatchFeedHelper/com.giorgiocalderolla.Catch.CatchFeedHelper.entitlements;
CODE_SIGN_IDENTITY = "-";
GCC_PREFIX_HEADER = "CatchFeedHelper/CatchFeedHelper-Prefix.pch";
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
INFOPLIST_FILE = "CatchFeedHelper/CatchFeedHelper-Info.plist";
Expand All @@ -774,6 +785,8 @@
44717AD01913A08700580054 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = CatchFeedHelper/com.giorgiocalderolla.Catch.CatchFeedHelper.entitlements;
CODE_SIGN_IDENTITY = "-";
GCC_PREFIX_HEADER = "CatchFeedHelper/CatchFeedHelper-Prefix.pch";
INFOPLIST_FILE = "CatchFeedHelper/CatchFeedHelper-Info.plist";
MACH_O_TYPE = mh_execute;
Expand Down
2 changes: 1 addition & 1 deletion CatchFeedHelper/CTCFeedChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef void (^CTCFeedCheckCompletionHandler)(NSArray *downloadedFeedFiles,
@protocol CTCFeedCheck

- (void)checkShowRSSFeed:(NSURL *)feedURL
downloadingToPath:(NSString *)downloadFolderPath
downloadingToBookmark:(NSData *)downloadFolderBookmark
organizingByFolder:(BOOL)shouldOrganizeByFolder
skippingURLs:(NSArray *)previouslyDownloadedURLs
withReply:(CTCFeedCheckCompletionHandler)reply;
Expand Down
31 changes: 30 additions & 1 deletion CatchFeedHelper/CTCFeedChecker.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConne
}

- (void)checkShowRSSFeed:(NSURL *)feedURL
downloadingToPath:(NSString *)downloadFolderPath
downloadingToBookmark:(NSData *)downloadFolderBookmark
organizingByFolder:(BOOL)shouldOrganizeByFolder
skippingURLs:(NSArray *)previouslyDownloadedURLs
withReply:(CTCFeedCheckCompletionHandler)reply {
NSLog(@"Checking feed");

// Resolve the bookmark (that the main app gives us to transfer access to
// the download folder) to a URL
NSURL *downloadFolderURL = [self URLFromBookmark:downloadFolderBookmark];
if (!downloadFolderURL) {
reply(@[], [NSError errorWithDomain:kCTCFeedCheckerErrorDomain
code:-4
userInfo:nil]);
return;
}

NSString *downloadFolderPath = downloadFolderURL.path;

// Flush the cache, we want fresh results
[NSURLCache.sharedURLCache removeAllCachedResponses];

Expand Down Expand Up @@ -85,6 +97,23 @@ - (NSXMLDocument*)downloadFeed:(NSURL*)feedURL {
return document;
}

- (NSURL *)URLFromBookmark:(NSData *)bookmark {
NSError *error = nil;
BOOL isStale = NO;
NSURL *URL = [NSURL URLByResolvingBookmarkData:bookmark
options:kNilOptions
relativeToURL:nil
bookmarkDataIsStale:&isStale
error:&error];

if (!URL || error) {
NSLog(@"Could not get URL from bookmark: %@", error);
return nil;
}

return URL;
}

- (NSArray *)downloadFiles:(NSArray *)feedFiles
toPath:(NSString *)downloadPath
organizingByFolder:(BOOL)shouldOrganizeByFolder
Expand Down
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 106e078

Please sign in to comment.