Browse Source

getMiddlewarePing

Marino Faggiana 7 years ago
parent
commit
32ea20b804
3 changed files with 40 additions and 0 deletions
  1. 1 0
      iOSClient/Brand/NCBrand.swift
  2. 1 0
      iOSClient/CCGlobal.h
  3. 38 0
      iOSClient/Networking/OCNetworking.m

+ 1 - 0
iOSClient/Brand/NCBrand.swift

@@ -71,6 +71,7 @@ class NCBrandOptions: NSObject {
     public let loginBaseUrlMultiDomains:        [String] = ["domain.com", "domain.it"]
     public let pushNotificationServer:          String = "https://push-notifications.nextcloud.com"
     public let loginButtonLabelLink:            String = "https://nextcloud.com/providers"
+    public let middlewarePingUrl:               String = ""
     public let webLoginAutenticationProtocol:   String = ""
     public let folderBrandAutoUpload:           String = ""
 

+ 1 - 0
iOSClient/CCGlobal.h

@@ -202,6 +202,7 @@ extern NSString *const urlBaseUploadDB;
 #define actionGetNotificationServer                     @"getNotificationServer"
 #define actionSetNotificationServer                     @"setNotificationServer"
 #define actionGetExternalSitesServer                    @"getExternalSitesServer"
+#define actionGetMiddlewarePing                         @"getMiddlewarePing"
 #define actionListingFavorites                          @"listingFavorites"
 #define actionMoveFileOrFolder                          @"moveFileOrFolder"
 #define actionReadFile                                  @"readFile"

+ 38 - 0
iOSClient/Networking/OCNetworking.m

@@ -1311,6 +1311,44 @@
         [self complete];
     }];
 
+}
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Middleware Ping =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)getMiddlewarePing
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    
+    [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+    
+    [communication getMiddlewarePing:_metadataNet.serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *listOfExternalSites, NSString *redirectedServer) {
+        
+        [self complete];
+        
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0)
+            errorCode = error.code;
+        
+        // Error
+        if ([self.delegate respondsToSelector:@selector(getExternalSitesServerFailure:message:errorCode:)]) {
+            
+            if (errorCode == 503)
+                [self.delegate getExternalSitesServerFailure:_metadataNet message:NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil) errorCode:errorCode];
+            else
+                [self.delegate getExternalSitesServerFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+        }
+        
+        // Request trusted certificated
+        if ([error code] == NSURLErrorServerCertificateUntrusted)
+            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
+        
+        [self complete];
+    }];
+    
 }
 
 #pragma --------------------------------------------------------------------------------------------