iOS: Add initial support for upload via browser

This only starts the HTTP server on 127.0.0.1 for now and does nothing
else yet.
This commit is contained in:
Jonathan Schleifer 2018-01-11 23:49:18 +01:00
parent e5b90b856a
commit 02ed98041d
No known key found for this signature in database
GPG key ID: 28D65178B37F33E3
7 changed files with 142 additions and 7 deletions

View file

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BN3-Y7-zvx"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BN3-Y7-zvx">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/> <adaptation id="fullscreen"/>
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/> <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
@ -327,7 +327,14 @@
</connections> </connections>
</tableView> </tableView>
<toolbarItems/> <toolbarItems/>
<navigationItem key="navigationItem" id="bWa-Dd-f4f"/> <navigationItem key="navigationItem" id="bWa-Dd-f4f">
<nil key="title"/>
<barButtonItem key="rightBarButtonItem" title="Upload" id="85s-WF-868">
<connections>
<action selector="upload:" destination="4bs-rP-TxE" id="DnV-UG-h0y"/>
</connections>
</barButtonItem>
</navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/> <simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
</tableViewController> </tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hBM-t2-PD9" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="hBM-t2-PD9" userLabel="First Responder" sceneMemberID="firstResponder"/>

26
iOS/HTTPServerDelegate.h Normal file
View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2016, 2017, Jonathan Schleifer <js@heap.zone>
*
* 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 <ObjFW/ObjFW.h>
@interface HTTPServerDelegate: OFObject <OFHTTPServerDelegate>
@end

32
iOS/HTTPServerDelegate.m Normal file
View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2016, 2017, Jonathan Schleifer <js@heap.zone>
*
* 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

View file

@ -15,11 +15,13 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.1</string> <string>1.2</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>3</string> <string>1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIMainStoryboardFile</key> <key>UIMainStoryboardFile</key>
@ -35,7 +37,5 @@
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>UIFileSharingEnabled</key>
<true/>
</dict> </dict>
</plist> </plist>

View file

@ -21,14 +21,21 @@
*/ */
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <ObjFW/ObjFW.h>
#import "AddSiteController.h" #import "AddSiteController.h"
#import "HTTPServerDelegate.h"
@interface SelectKeyFileController: UITableViewController <UITableViewDelegate, @interface SelectKeyFileController: UITableViewController <UITableViewDelegate,
UITableViewDataSource> UITableViewDataSource>
{ {
NSArray<NSString *> *_keyFiles; NSArray<NSString *> *_keyFiles;
OFHTTPServer *_HTTPServer;
HTTPServerDelegate *_HTTPServerDelegate;
OFThread *_HTTPServerThread;
} }
@property (retain) AddSiteController *addSiteController; @property (retain) AddSiteController *addSiteController;
- (IBAction)upload:(id)sender;
@end @end

View file

@ -20,6 +20,9 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#import <ObjFW_Bridge/ObjFW_Bridge.h>
#import "HTTPServerDelegate.h"
#import "SelectKeyFileController.h" #import "SelectKeyFileController.h"
@implementation SelectKeyFileController @implementation SelectKeyFileController
@ -50,12 +53,31 @@
_keyFiles = [[keyFiles sortedArrayUsingSelector: _keyFiles = [[keyFiles sortedArrayUsingSelector:
@selector(compare:)] retain]; @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 - (void)dealloc
{ {
[_keyFiles release]; [_keyFiles release];
[_HTTPServerThread.runLoop stop];
[_HTTPServerThread join];
[_HTTPServerThread release];
[_HTTPServer release];
[_HTTPServerDelegate release];
[super dealloc]; [super dealloc];
} }
@ -92,4 +114,39 @@
[self.navigationController popViewControllerAnimated: YES]; [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 @end

View file

@ -19,6 +19,7 @@
4B9525261F96BB900095F259 /* ObjFW_Bridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9525241F96BB820095F259 /* ObjFW_Bridge.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, ); }; }; 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, ); }; }; 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"; }; }; 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"; }; }; 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 */; }; 4BA115D61DA94390007ED4EA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BA115D51DA94390007ED4EA /* UIKit.framework */; };
@ -60,6 +61,8 @@
4B82D1141DAAAFCE00F32B2F /* AboutController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutController.m; sourceTree = "<group>"; }; 4B82D1141DAAAFCE00F32B2F /* AboutController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutController.m; sourceTree = "<group>"; };
4B9525231F96BB820095F259 /* ObjFW.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW.framework; path = ObjFW/Frameworks/ObjFW.framework; sourceTree = "<group>"; }; 4B9525231F96BB820095F259 /* ObjFW.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW.framework; path = ObjFW/Frameworks/ObjFW.framework; sourceTree = "<group>"; };
4B9525241F96BB820095F259 /* ObjFW_Bridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW_Bridge.framework; path = ObjFW/Frameworks/ObjFW_Bridge.framework; sourceTree = "<group>"; }; 4B9525241F96BB820095F259 /* ObjFW_Bridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW_Bridge.framework; path = ObjFW/Frameworks/ObjFW_Bridge.framework; sourceTree = "<group>"; };
4B9EB1142008167200EB66F2 /* HTTPServerDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HTTPServerDelegate.m; sourceTree = "<group>"; };
4B9EB1162008168400EB66F2 /* HTTPServerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTTPServerDelegate.h; sourceTree = "<group>"; };
4BA115CD1DA9432D007ED4EA /* LegacyPasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LegacyPasswordGenerator.h; path = ../LegacyPasswordGenerator.h; sourceTree = "<group>"; }; 4BA115CD1DA9432D007ED4EA /* LegacyPasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LegacyPasswordGenerator.h; path = ../LegacyPasswordGenerator.h; sourceTree = "<group>"; };
4BA115CE1DA9432D007ED4EA /* LegacyPasswordGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LegacyPasswordGenerator.m; path = ../LegacyPasswordGenerator.m; sourceTree = "<group>"; }; 4BA115CE1DA9432D007ED4EA /* LegacyPasswordGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LegacyPasswordGenerator.m; path = ../LegacyPasswordGenerator.m; sourceTree = "<group>"; };
4BA115CF1DA9432D007ED4EA /* NewPasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NewPasswordGenerator.h; path = ../NewPasswordGenerator.h; sourceTree = "<group>"; }; 4BA115CF1DA9432D007ED4EA /* NewPasswordGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NewPasswordGenerator.h; path = ../NewPasswordGenerator.h; sourceTree = "<group>"; };
@ -118,6 +121,8 @@
4BB3CDFC1DA9764300FEE5ED /* AddSiteController.m */, 4BB3CDFC1DA9764300FEE5ED /* AddSiteController.m */,
4B2E52E21DA942840040D091 /* AppDelegate.h */, 4B2E52E21DA942840040D091 /* AppDelegate.h */,
4B2E52E31DA942840040D091 /* AppDelegate.m */, 4B2E52E31DA942840040D091 /* AppDelegate.m */,
4B9EB1162008168400EB66F2 /* HTTPServerDelegate.h */,
4B9EB1142008167200EB66F2 /* HTTPServerDelegate.m */,
4B2E52F01DA942840040D091 /* Info.plist */, 4B2E52F01DA942840040D091 /* Info.plist */,
4B2E52ED1DA942840040D091 /* LaunchScreen.storyboard */, 4B2E52ED1DA942840040D091 /* LaunchScreen.storyboard */,
4B2E52E81DA942840040D091 /* Main.storyboard */, 4B2E52E81DA942840040D091 /* Main.storyboard */,
@ -234,6 +239,7 @@
4BC29DD51FCB5FAE00A1E786 /* SelectKeyFileController.m in Sources */, 4BC29DD51FCB5FAE00A1E786 /* SelectKeyFileController.m in Sources */,
4BB3CDFD1DA9764300FEE5ED /* AddSiteController.m in Sources */, 4BB3CDFD1DA9764300FEE5ED /* AddSiteController.m in Sources */,
4B2E52E41DA942840040D091 /* AppDelegate.m in Sources */, 4B2E52E41DA942840040D091 /* AppDelegate.m in Sources */,
4B9EB1152008167200EB66F2 /* HTTPServerDelegate.m in Sources */,
4BA115D21DA9432D007ED4EA /* LegacyPasswordGenerator.m in Sources */, 4BA115D21DA9432D007ED4EA /* LegacyPasswordGenerator.m in Sources */,
4B2E52E71DA942840040D091 /* MainViewController.m in Sources */, 4B2E52E71DA942840040D091 /* MainViewController.m in Sources */,
4BA115D31DA9432D007ED4EA /* NewPasswordGenerator.m in Sources */, 4BA115D31DA9432D007ED4EA /* NewPasswordGenerator.m in Sources */,