diff --git a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m index 24f251f..edf0688 100755 --- a/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m +++ b/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m @@ -428,6 +428,7 @@ NSString const *OCWebDAVModificationDateKey = @"modificationdate"; NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:remoteDestination parameters:nil]; [request setTimeoutInterval:k_timeout_upload]; [request setValue:[NSString stringWithFormat:@"%lld", [UtilsFramework getSizeInBytesByPath:localSource]] forHTTPHeaderField:@"Content-Length"]; + [request setValue:[NSString stringWithFormat:@"SHA1:%@", [UtilsFramework getShasumByPath:localSource]] forHTTPHeaderField:@"OC-Checksum"]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; [request setHTTPBodyStream:[NSInputStream inputStreamWithFileAtPath:localSource]]; //[request setHTTPBody:[NSData dataWithContentsOfFile:localSource]]; @@ -484,6 +485,7 @@ NSString const *OCWebDAVModificationDateKey = @"modificationdate"; NSMutableURLRequest *request = [self requestWithMethod:@"PUT" path:remoteDestination parameters:nil]; [request setTimeoutInterval:k_timeout_upload]; [request setValue:[NSString stringWithFormat:@"%lld", [UtilsFramework getSizeInBytesByPath:localSource]] forHTTPHeaderField:@"Content-Length"]; + [request setValue:[NSString stringWithFormat:@"SHA1:%@", [UtilsFramework getShasumByPath:localSource]] forHTTPHeaderField:@"OC-Checksum"]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; //If is not nil is a redirection so we keep the original url server diff --git a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.h b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.h index 6ebd408..53da6d3 100644 --- a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.h +++ b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.h @@ -24,6 +24,7 @@ // #import +#import @interface UtilsFramework : NSObject @@ -113,6 +114,14 @@ */ + (long long) getSizeInBytesByPath:(NSString *) path; +/** + * Method to return the sha1 sum of a file by a path + * + * @param NSString -> path of the file + * + * @return NSString -> sha1 sum of the file in the path + */ ++ (NSString *) getShasumByPath: (NSString *) path; ///----------------------------------- /// @name isURLWithSamlFragment: diff --git a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m index cd82e78..cf00133 100644 --- a/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m +++ b/OCCommunicationLib/OCCommunicationLib/Utils/UtilsFramework.m @@ -352,9 +352,34 @@ return fileLength; } +///----------------------------------- +/// @ name getShasumByPath +///----------------------------------- - - +/** + * Method to return the sha1 sum of a file by a path + * + * @param NSString -> path of the file + * + * @return NSString -> sha1 sum of the file in the path + */ ++ (NSString *) getShasumByPath:(NSString *)path { + NSFileManager *fileManager = [NSFileManager defaultManager]; + if( [fileManager fileExistsAtPath:path isDirectory:nil] ) { + NSData *data = [NSData dataWithContentsOfFile:path]; + unsigned char digest[CC_SHA1_DIGEST_LENGTH]; + CC_SHA1(data.bytes, (CC_LONG)data.length, digest); + + NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; + + for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { + [output appendFormat:@"%02x", digest[i]]; + } + return output; + } else { + return @""; + } +} ///----------------------------------- /// @name isURLWithSamlFragment: