Index: iOS/Base.lproj/Main.storyboard ================================================================== --- iOS/Base.lproj/Main.storyboard +++ iOS/Base.lproj/Main.storyboard @@ -1,13 +1,13 @@ - + - + @@ -325,11 +325,18 @@ - + + + + + + + + ADDED iOS/HTTPServerDelegate.h Index: iOS/HTTPServerDelegate.h ================================================================== --- iOS/HTTPServerDelegate.h +++ iOS/HTTPServerDelegate.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016, 2017, Jonathan Schleifer + * + * https://heap.zone/git/scrypt-pwgen.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import + +@interface HTTPServerDelegate: OFObject +@end ADDED iOS/HTTPServerDelegate.m Index: iOS/HTTPServerDelegate.m ================================================================== --- iOS/HTTPServerDelegate.m +++ iOS/HTTPServerDelegate.m @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016, 2017, Jonathan Schleifer + * + * https://heap.zone/git/scrypt-pwgen.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import "HTTPServerDelegate.h" + +@implementation HTTPServerDelegate +- (void)server: (OFHTTPServer *)server + didReceiveRequest: (OFHTTPRequest *)request + response: (OFHTTPResponse *)response +{ + of_log(@"%@", request); +} +@end Index: iOS/Info.plist ================================================================== --- iOS/Info.plist +++ iOS/Info.plist @@ -13,14 +13,16 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString - 1.1 + 1.2 CFBundleVersion - 3 + 1 LSRequiresIPhoneOS + + UIFileSharingEnabled UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main @@ -33,9 +35,7 @@ UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortraitUpsideDown - UIFileSharingEnabled - Index: iOS/SelectKeyFileController.h ================================================================== --- iOS/SelectKeyFileController.h +++ iOS/SelectKeyFileController.h @@ -19,16 +19,23 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import +#import #import "AddSiteController.h" +#import "HTTPServerDelegate.h" @interface SelectKeyFileController: UITableViewController { NSArray *_keyFiles; + OFHTTPServer *_HTTPServer; + HTTPServerDelegate *_HTTPServerDelegate; + OFThread *_HTTPServerThread; } @property (retain) AddSiteController *addSiteController; + +- (IBAction)upload:(id)sender; @end Index: iOS/SelectKeyFileController.m ================================================================== --- iOS/SelectKeyFileController.m +++ iOS/SelectKeyFileController.m @@ -18,10 +18,13 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#import + +#import "HTTPServerDelegate.h" #import "SelectKeyFileController.h" @implementation SelectKeyFileController - (void)viewDidLoad { @@ -48,15 +51,34 @@ return; } _keyFiles = [[keyFiles sortedArrayUsingSelector: @selector(compare:)] retain]; + + _HTTPServer = [[OFHTTPServer alloc] init]; + @autoreleasepool { + _HTTPServer.host = @"127.0.0.1".OFObject; + } + + _HTTPServerDelegate = [[HTTPServerDelegate alloc] init]; + _HTTPServer.delegate = _HTTPServerDelegate; + + _HTTPServerThread = [[OFThread alloc] init]; + [_HTTPServerThread start]; } - (void)dealloc { [_keyFiles release]; + + [_HTTPServerThread.runLoop stop]; + [_HTTPServerThread join]; + [_HTTPServerThread release]; + + [_HTTPServer release]; + + [_HTTPServerDelegate release]; [super dealloc]; } - (NSInteger)tableView: (UITableView *)tableView @@ -90,6 +112,41 @@ self.addSiteController.keyFileLabel.text = (indexPath.row > 0 ? _keyFiles[indexPath.row - 1] : @"None"); [self.navigationController popViewControllerAnimated: YES]; } + +- (void)upload: (id)sender +{ + [_HTTPServerThread.runLoop addTimer: [OFTimer + scheduledTimerWithTimeInterval: 0 + repeats: false + block: ^ (OFTimer *timer) { + NSString *message; + UIAlertController *alert; + + _HTTPServer.port = 0; + [_HTTPServer start]; + + message = [NSString stringWithFormat: + @"Navigate to http://%@:%u/ with your browser.\n\n" + @"Press OK when done.", + _HTTPServer.host.NSObject, _HTTPServer.port]; + alert = [UIAlertController + alertControllerWithTitle: @"Server Running" + message: message + preferredStyle: UIAlertControllerStyleAlert]; + [alert addAction: + [UIAlertAction actionWithTitle: @"OK" + style: UIAlertActionStyleDefault + handler: nil]]; + + dispatch_sync(dispatch_get_main_queue(), ^ { + [self presentViewController: alert + animated: YES + completion: ^ { + [_HTTPServer stop]; + }]; + }); + }]]; +} @end Index: iOS/scrypt-pwgen.xcodeproj/project.pbxproj ================================================================== --- iOS/scrypt-pwgen.xcodeproj/project.pbxproj +++ iOS/scrypt-pwgen.xcodeproj/project.pbxproj @@ -17,10 +17,11 @@ 4B82D1151DAAAFCE00F32B2F /* AboutController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B82D1141DAAAFCE00F32B2F /* AboutController.m */; }; 4B9525251F96BB900095F259 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9525231F96BB820095F259 /* ObjFW.framework */; }; 4B9525261F96BB900095F259 /* ObjFW_Bridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9525241F96BB820095F259 /* ObjFW_Bridge.framework */; }; 4B9525291F994CD30095F259 /* ObjFW.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9525231F96BB820095F259 /* ObjFW.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4B95252A1F9953350095F259 /* ObjFW_Bridge.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9525241F96BB820095F259 /* ObjFW_Bridge.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 4B9EB1152008167200EB66F2 /* HTTPServerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B9EB1142008167200EB66F2 /* HTTPServerDelegate.m */; settings = {COMPILER_FLAGS = "-fconstant-string-class=OFConstantString -fno-constant-cfstrings"; }; }; 4BA115D21DA9432D007ED4EA /* LegacyPasswordGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BA115CE1DA9432D007ED4EA /* LegacyPasswordGenerator.m */; settings = {COMPILER_FLAGS = "-fconstant-string-class=OFConstantString -fno-constant-cfstrings"; }; }; 4BA115D31DA9432D007ED4EA /* NewPasswordGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BA115D01DA9432D007ED4EA /* NewPasswordGenerator.m */; settings = {COMPILER_FLAGS = "-fconstant-string-class=OFConstantString -fno-constant-cfstrings"; }; }; 4BA115D61DA94390007ED4EA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BA115D51DA94390007ED4EA /* UIKit.framework */; }; 4BB3CDFD1DA9764300FEE5ED /* AddSiteController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB3CDFC1DA9764300FEE5ED /* AddSiteController.m */; }; 4BC29DD51FCB5FAE00A1E786 /* SelectKeyFileController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC29DD41FCB5FAE00A1E786 /* SelectKeyFileController.m */; }; @@ -58,10 +59,12 @@ 4B2E52F01DA942840040D091 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 4B82D1131DAAAFCE00F32B2F /* AboutController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AboutController.h; sourceTree = ""; }; 4B82D1141DAAAFCE00F32B2F /* AboutController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutController.m; sourceTree = ""; }; 4B9525231F96BB820095F259 /* ObjFW.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW.framework; path = ObjFW/Frameworks/ObjFW.framework; sourceTree = ""; }; 4B9525241F96BB820095F259 /* ObjFW_Bridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW_Bridge.framework; path = ObjFW/Frameworks/ObjFW_Bridge.framework; sourceTree = ""; }; + 4B9EB1142008167200EB66F2 /* HTTPServerDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HTTPServerDelegate.m; sourceTree = ""; }; + 4B9EB1162008168400EB66F2 /* HTTPServerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTTPServerDelegate.h; sourceTree = ""; }; 4BA115CD1DA9432D007ED4EA /* LegacyPasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LegacyPasswordGenerator.h; path = ../LegacyPasswordGenerator.h; sourceTree = ""; }; 4BA115CE1DA9432D007ED4EA /* LegacyPasswordGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LegacyPasswordGenerator.m; path = ../LegacyPasswordGenerator.m; sourceTree = ""; }; 4BA115CF1DA9432D007ED4EA /* NewPasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NewPasswordGenerator.h; path = ../NewPasswordGenerator.h; sourceTree = ""; }; 4BA115D01DA9432D007ED4EA /* NewPasswordGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NewPasswordGenerator.m; path = ../NewPasswordGenerator.m; sourceTree = ""; }; 4BA115D11DA9432D007ED4EA /* PasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PasswordGenerator.h; path = ../PasswordGenerator.h; sourceTree = ""; }; @@ -116,10 +119,12 @@ 4B82D1141DAAAFCE00F32B2F /* AboutController.m */, 4BB3CDFB1DA9764300FEE5ED /* AddSiteController.h */, 4BB3CDFC1DA9764300FEE5ED /* AddSiteController.m */, 4B2E52E21DA942840040D091 /* AppDelegate.h */, 4B2E52E31DA942840040D091 /* AppDelegate.m */, + 4B9EB1162008168400EB66F2 /* HTTPServerDelegate.h */, + 4B9EB1142008167200EB66F2 /* HTTPServerDelegate.m */, 4B2E52F01DA942840040D091 /* Info.plist */, 4B2E52ED1DA942840040D091 /* LaunchScreen.storyboard */, 4B2E52E81DA942840040D091 /* Main.storyboard */, 4B2E52E51DA942840040D091 /* MainViewController.h */, 4B2E52E61DA942840040D091 /* MainViewController.m */, @@ -232,10 +237,11 @@ files = ( 4B82D1151DAAAFCE00F32B2F /* AboutController.m in Sources */, 4BC29DD51FCB5FAE00A1E786 /* SelectKeyFileController.m in Sources */, 4BB3CDFD1DA9764300FEE5ED /* AddSiteController.m in Sources */, 4B2E52E41DA942840040D091 /* AppDelegate.m in Sources */, + 4B9EB1152008167200EB66F2 /* HTTPServerDelegate.m in Sources */, 4BA115D21DA9432D007ED4EA /* LegacyPasswordGenerator.m in Sources */, 4B2E52E71DA942840040D091 /* MainViewController.m in Sources */, 4BA115D31DA9432D007ED4EA /* NewPasswordGenerator.m in Sources */, 4B0719251DAA78D80065997A /* ShowDetailsController.m in Sources */, 4BF4ADED1DA9A6B00073B995 /* SiteStorage.m in Sources */,