|
@@ -34,7 +34,7 @@ import Queuer
|
|
|
@objc optional func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, errorCode: Int, errorDescription: String)
|
|
|
}
|
|
|
|
|
|
-@objc class NCNetworking: NSObject, NCCommunicationCommonDelegate, NCCommunicationBackgroundDelegate {
|
|
|
+@objc class NCNetworking: NSObject, NCCommunicationCommonDelegate {
|
|
|
@objc public static let shared: NCNetworking = {
|
|
|
let instance = NCNetworking()
|
|
|
return instance
|
|
@@ -75,10 +75,8 @@ import Queuer
|
|
|
|
|
|
func authenticationChallenge(_ challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
|
|
|
if NCNetworking.shared.checkTrustedChallenge(challenge: challenge, directoryCertificate: CCUtility.getDirectoryCerificates()) {
|
|
|
- NCCommunicationCommon.shared.writeLog("[LOG] Authentication challenge server trust")
|
|
|
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential.init(trust: challenge.protectionSpace.serverTrust!))
|
|
|
} else {
|
|
|
- NCCommunicationCommon.shared.writeLog("[LOG] Authentication challenge default handling")
|
|
|
completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
|
|
|
}
|
|
|
}
|
|
@@ -138,7 +136,7 @@ import Queuer
|
|
|
|
|
|
BIO_free(mem)
|
|
|
if x509cert == nil {
|
|
|
- NCCommunicationCommon.shared.writeLog("[LOG] OpenSSL couldn't parse X509 Certificate")
|
|
|
+ print("[LOG] OpenSSL couldn't parse X509 Certificate")
|
|
|
} else {
|
|
|
if FileManager.default.fileExists(atPath: certNamePath) {
|
|
|
do {
|
|
@@ -352,10 +350,10 @@ import Queuer
|
|
|
let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
|
|
|
let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
|
|
|
|
|
|
- if metadata.session == NCCommunicationBackground.shared.sessionIdentifierBackground || metadata.session == NCCommunicationBackground.shared.sessionIdentifierBackgroundExtension {
|
|
|
- session = NCCommunicationBackground.sessionManagerBackground
|
|
|
- } else if metadata.session == NCCommunicationBackground.shared.sessionIdentifierBackgroundWWan {
|
|
|
- session = NCCommunicationBackground.sessionManagerBackgroundWWan
|
|
|
+ if metadata.session == NCCommunicationCommon.shared.sessionIdentifierBackground || metadata.session == NCCommunicationCommon.shared.sessionIdentifierExtension {
|
|
|
+ session = NCCommunicationBackground.shared.sessionManagerTransfer
|
|
|
+ } else if metadata.session == NCCommunicationCommon.shared.sessionIdentifierBackgroundWWan {
|
|
|
+ session = NCCommunicationBackground.shared.sessionManagerTransferWWan
|
|
|
}
|
|
|
|
|
|
if let task = NCCommunicationBackground.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: metadata.creationDate as Date, dateModificationFile: metadata.date as Date, description: "", session: session!) {
|
|
@@ -448,7 +446,7 @@ import Queuer
|
|
|
|
|
|
if metadata.status == k_metadataStatusUploadForcedStart {
|
|
|
|
|
|
- NCManageDatabase.sharedInstance.setMetadataSession(ocId: ocId!, session: NCCommunicationBackground.shared.sessionIdentifierBackground, sessionError: "", sessionTaskIdentifier: 0, status: Int(k_metadataStatusInUpload))
|
|
|
+ NCManageDatabase.sharedInstance.setMetadataSession(ocId: ocId!, session: NCCommunicationCommon.shared.sessionIdentifierBackground, sessionError: "", sessionTaskIdentifier: 0, status: Int(k_metadataStatusInUpload))
|
|
|
|
|
|
NCNetworking.shared.upload(metadata: metadata) { (_, _) in }
|
|
|
|
|
@@ -491,9 +489,9 @@ import Queuer
|
|
|
@objc func verifyUploadZombie() {
|
|
|
|
|
|
var session: URLSession?
|
|
|
- let sessionBackground = NCCommunicationBackground.shared.sessionIdentifierBackground
|
|
|
- let sessionBackgroundWWan = NCCommunicationBackground.shared.sessionIdentifierBackgroundWWan
|
|
|
- let sessionBackgroundExtension = NCCommunicationBackground.shared.sessionIdentifierBackgroundExtension
|
|
|
+ let sessionBackground = NCCommunicationCommon.shared.sessionIdentifierBackground
|
|
|
+ let sessionBackgroundWWan = NCCommunicationCommon.shared.sessionIdentifierBackgroundWWan
|
|
|
+ let sessionBackgroundExtension = NCCommunicationCommon.shared.sessionIdentifierExtension
|
|
|
|
|
|
// verify k_metadataStatusInUpload (BACKGROUND)
|
|
|
let metadatasInUpload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "(session == %@ OR session == %@ OR session == %@) AND status == %d AND sessionTaskIdentifier == 0", sessionBackground, sessionBackgroundWWan, sessionBackgroundExtension, k_metadataStatusInUpload))
|
|
@@ -501,7 +499,7 @@ import Queuer
|
|
|
for metadata in metadatasInUpload {
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
|
|
|
if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@ AND status == %d AND sessionTaskIdentifier == 0", metadata.ocId, k_metadataStatusInUpload)) {
|
|
|
- NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: NCCommunicationBackground.shared.sessionIdentifierBackground, sessionError: "", sessionSelector: nil, sessionTaskIdentifier: 0, status: Int(k_metadataStatusWaitUpload))
|
|
|
+ NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: NCCommunicationCommon.shared.sessionIdentifierBackground, sessionError: "", sessionSelector: nil, sessionTaskIdentifier: 0, status: Int(k_metadataStatusWaitUpload))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -511,12 +509,12 @@ import Queuer
|
|
|
|
|
|
for metadata in metadatasUploading {
|
|
|
|
|
|
- if metadata.session == NCCommunicationBackground.shared.sessionIdentifierBackground {
|
|
|
- session = NCCommunicationBackground.sessionManagerBackground
|
|
|
- } else if metadata.session == NCCommunicationBackground.shared.sessionIdentifierBackgroundWWan {
|
|
|
- session = NCCommunicationBackground.sessionManagerBackgroundWWan
|
|
|
- } else if metadata.session == NCCommunicationBackground.shared.sessionIdentifierBackgroundExtension {
|
|
|
- session = NCCommunicationBackground.sessionManagerBackgroundExtension
|
|
|
+ if metadata.session == NCCommunicationCommon.shared.sessionIdentifierBackground {
|
|
|
+ session = NCCommunicationBackground.shared.sessionManagerTransfer
|
|
|
+ } else if metadata.session == NCCommunicationCommon.shared.sessionIdentifierBackgroundWWan {
|
|
|
+ session = NCCommunicationBackground.shared.sessionManagerTransferWWan
|
|
|
+ } else if metadata.session == NCCommunicationCommon.shared.sessionIdentifierExtension {
|
|
|
+ session = NCCommunicationBackground.shared.sessionManagerTransferExtension
|
|
|
}
|
|
|
|
|
|
var taskUpload: URLSessionTask?
|
|
@@ -530,7 +528,7 @@ import Queuer
|
|
|
|
|
|
if taskUpload == nil {
|
|
|
if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@ AND status == %d", metadata.ocId, k_metadataStatusUploading)) {
|
|
|
- NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: NCCommunicationBackground.shared.sessionIdentifierBackground, sessionError: "", sessionSelector: nil, sessionTaskIdentifier: 0, status: Int(k_metadataStatusWaitUpload))
|
|
|
+ NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: NCCommunicationCommon.shared.sessionIdentifierBackground, sessionError: "", sessionSelector: nil, sessionTaskIdentifier: 0, status: Int(k_metadataStatusWaitUpload))
|
|
|
}
|
|
|
}
|
|
|
})
|