Skip to content

Commit

Permalink
Merge pull request #171 from mgmart/bug-fix/someBugs
Browse files Browse the repository at this point in the history
Bug fix/some bugs
  • Loading branch information
webframp authored Feb 3, 2017
2 parents f089c1e + 7809994 commit fadb072
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 12 deletions.
3 changes: 0 additions & 3 deletions Classes/Settings/SyncSettingsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ class SyncSettingsController: UITableViewController {

alert.addAction(cancelAction)
self.present(alert, animated: true)

sender.text = ""
sender.placeholder = "Enter valid URL"
}

// The user just changed URLs. Let's see if they had any local changes.
Expand Down
18 changes: 17 additions & 1 deletion Classes/Sync/Dropbox/DropboxTransferManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,23 @@ import SwiftyDropbox
self.requestFinished(self.activeTransfer!)
}
if let error = error {
self.activeTransfer?.errorText = error.description
switch error as CallError {
case .routeError(let boxed, _):
switch boxed.unboxed as Files.DownloadError {
case .path(let lookupError):
switch lookupError {
case .notFound:
self.activeTransfer?.statusCode = 404
self.activeTransfer?.errorText = "The file \(self.activeTransfer?.remoteUrl.lastPathComponent) could not be found"
default:
self.activeTransfer?.errorText = error.description
}
default:
self.activeTransfer?.errorText = error.description
}
default:
self.activeTransfer?.errorText = error.description
}
self.activeTransfer?.success = false
self.requestFinished(self.activeTransfer!)
}
Expand Down
17 changes: 15 additions & 2 deletions Classes/Sync/SyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//

#import "SyncManager.h"
#import "WebDavTransferManager.h"
#import "TransferManager.h"
#import "TransferContext.h"
#import "Settings.h"
#import "DataUtils.h"
Expand Down Expand Up @@ -93,7 +93,7 @@ - (id)init {

- (TransferManager*)transferManager {
if ([[Settings instance] serverMode] == ServerModeWebDav) {
return [WebDavTransferManager instance];
return (TransferManager *)[WebDavTransferManager instance];
} else if ([[Settings instance] serverMode] == ServerModeDropbox) {
return (TransferManager *)[DropboxTransferManager instance];
}
Expand Down Expand Up @@ -753,6 +753,19 @@ - (void)transferComplete:(TransferContext*)context {

- (void)transferFailed:(TransferContext*)context {
//NSLog(@"Failed %@ with code %d", [context remoteUrl], [context statusCode]);

switch ([context statusCode] ) {
case NSURLErrorAppTransportSecurityRequiresSecureConnection:
[self showAlert:@"ATS Error" withText:@"A secure connection could not be established.\nPlease make sure that you're using a secure connection"];
[self abort];
return;
case NSURLErrorSecureConnectionFailed:
[self showAlert:@"ATS Error" withText:@"A secure connection could not be established.\nPlease make sure that you're using a secure connection with valid certificates"];
[self abort];
return;

}

switch (currentState) {
case SyncManagerTransferStateDownloadingEditsFile:
if ([context statusCode] == 404) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Sync/TransferContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ typedef enum {
NSString *errorText;
bool success;
bool abortOnFailure;
UInt32 statusCode;
int statusCode;
bool dummy;
}

@property (nonatomic, copy) NSURL *remoteUrl;
@property (nonatomic, copy) NSString *localFile;
@property (nonatomic) TransferType transferType;
@property (nonatomic, assign) id<TransferManagerDelegate> delegate;
@property (nonatomic) UInt32 statusCode;
@property (nonatomic) int statusCode;
@property (nonatomic, copy) NSString *errorText;
@property (nonatomic) bool abortOnFailure;
@property (nonatomic) bool success;
Expand Down
36 changes: 35 additions & 1 deletion Classes/Sync/WebDav/WebDavTransferManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,40 @@ - (void)connection:(NSURLConnection*)aConnection didReceiveData:(NSData*)someDat
-(void)connection:(NSURLConnection*)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge {
if ([challenge previousFailureCount] == 0) {
if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodServerTrust) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"SSL Handshake" message:@"Server Ceritificate could not be validated.\nWould you like to continiue?" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Yes"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {


[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];

}];

UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];

[alertController addAction:ok];
[alertController addAction:cancel];

id rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController = ((UINavigationController *)rootViewController).viewControllers.firstObject;
}
if([rootViewController isKindOfClass:[UITabBarController class]])
{
rootViewController = ((UITabBarController *)rootViewController).selectedViewController;
}
[rootViewController presentViewController:alertController animated:YES completion:nil];


}
else {
NSURLCredential *newCredential;
Expand All @@ -281,6 +314,7 @@ -(void)connection:(NSURLConnection*)connection didReceiveAuthenticationChallenge
// In simulator on 4.x, the workaround for allowsAnyHTTPSCertificateForHost doesn't work,
// so use this instead (along with the bit in didReceiveAuthenticationChallenge about NSURLAuthenticationMethodServerTrust.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
// return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
return YES;
}

Expand Down
Loading

0 comments on commit fadb072

Please sign in to comment.