Skip to content

Commit

Permalink
Merge pull request #1532 from meganz/release/v3.6.0
Browse files Browse the repository at this point in the history
Release/v3.6.0
  • Loading branch information
sergiohs84 authored Jul 8, 2019
2 parents 17a9d23 + 2ec96da commit f293e3a
Show file tree
Hide file tree
Showing 85 changed files with 7,088 additions and 5,182 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ megaclient_statecache*
*.db-journal

/third_party/Makefile
/third_party/3rdparty
138 changes: 138 additions & 0 deletions bindings/ios/MEGABackgroundMediaUpload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* @file MEGABackgroundMediaUpload.h
* @brief Background media upload
*
* (c) 2018 - by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class MEGASdk;

@interface MEGABackgroundMediaUpload : NSObject

/**
* @brief Initial step to upload a photo/video via iOS low-power background upload feature.
*
* Creates an object which can be used to encrypt a media file, and upload it outside of the SDK,
* eg. in order to take advantage of a particular platform's low power background upload functionality.
*
* @param sdk The MEGASdk instance the new object will be used with. It must live longer than the new object.
* @return A pointer to an object that keeps some needed state through the process of
* uploading a media file via iOS low power background uploads (or similar).
*/
- (instancetype)initWithMEGASdk:(MEGASdk *)sdk;

/**
* @brief Extract mediainfo information about the photo or video.
*
* Call this function once with the file to be uploaded. It uses mediainfo to extract information that will
* help other clients to show or to play the files. The information is stored in this object until the whole
* operation completes.
*
* Call ensureMediaInfo in MEGASdk first in order prepare the library to attach file attributes
* that enable videos to be identified and played in the web browser.
*
* @param inputFilepath The file to analyse with MediaInfo.
* @return YES if analysis was performed (and any relevant attributes stored ready for upload), NO if mediainfo was not ready yet.
*/
- (BOOL)analyseMediaInfoForFileAtPath:(NSString *)inputFilepath;

/**
* @brief Encrypt the file or a portion of it.
*
* Call this function once with the file to be uploaded. It uses mediainfo to extract information that will
* help the webclient show or play the file in various browsers. The information is stored in this object
* until the whole operation completes. The encrypted data is stored in a new file.
*
* In order to save space on mobile devices, this function can be called in such a way that the last portion
* of the file is encrypted (to a new file), and then that last portion of the file is removed by file truncation.
* That operation can be repeated until the file is completely encrypted, and only the encrypted version remains,
* and takes up the same amount of space on the device. The size of the portions must first be calculated by using
* the 'adjustsSizeOnly' parameter, and iterating from the start of the file, specifying the approximate sizes of the portions.
*
* Encryption is done by reading small pieces of the file, encrypting them, and outputting to the new file,
* so that RAM usage is not excessive.
*
* @param inputFilePath The file to encrypt a portion of (and the one that is ultimately being uploaded).
* @param start The index of the first byte of the file to encrypt.
* @param length The number of bytes of the file to encrypt. The function will round this value up by up to 1MB to fit the
* MEGA internal chunking algorithm. The number of bytes actually encrypted and stored in the new file is the updated number.
* You can supply -1 as input to request the remainder file (from start) be encrypted.
* @param outputFilePath The name of the new file to create, and store the encrypted data in.
* @param adjustsSizeOnly If this is set YES, then encryption is not performed, and only the length parameter is adjusted.
* This feature is to enable precalculating the exact sizes of the file portions for upload.
* @return If the function tries to encrypt and succeeds, the return value is the suffix to append to the URL when uploading this enrypted chunk.
* If adjustsizeonly was set, and the function succeeds, the return value will be a nonempty string.
* If the function fails, the return value is an empty string, and an error will have been logged.
*/
- (nullable NSString *)encryptFileAtPath:(NSString *)inputFilePath startPosition:(int64_t)start length:(int64_t *)length outputFilePath:(nullable NSString *)outputFilePath adjustsSizeOnly:(BOOL)adjustsSizeOnly;

/**
* @brief Retrieves the value of the uploadURL once it has been successfully requested via requestBackgroundUploadURLWithFileSize:mediaUpload:delegate: in MEGASdk.
*
* @return The URL to upload to (after appending the suffix), if one has been received. Otherwise the string will be empty.
*/
- (nullable NSString *)uploadURLString;

/**
* @brief Sets the GPS coordinates for the node
*
* The node created via completeBackgroundMediaUpload:fileName:parentNode:fingerprint:originalFingerprint:binaryUploadToken:delegate: in MEGASdk
* will gain these coordinates as part of the
* node creation. If the unshareable flag is set, the coodinates are encrypted in a way that even if the
* node is later shared, the GPS coordinates cannot be decrypted by a different account.
*
* @param latitude The GPS latitude
* @param longitude The GPS longitude
* @param unshareable Set this true to prevent the coordinates being readable by other accounts.
*/
- (void)setCoordinatesWithLatitude:(double)latitude longitude:(double)longitude isUnshareable:(BOOL)unshareable;

/**
* @brief Turns the data stored in this object into a base 64 encoded binary data.
*
* The object can then be recreated via unserialize method in MEGABackgroundMediaUpload and supplying the returned binary data.
*
* You take ownership of the returned value.
*
* @return serialized version of this object (including URL, mediainfo attributes, and internal data suitable to resume uploading with in future).
*/
- (nullable NSData *)serialize;

/**
* @brief Get back the needed MEGABackgroundMediaUpload after the iOS app exited and restarted.
*
* In case the iOS app exits while a background upload is going on, and the app is started again
* to complete the operation, call this function to recreate the MEGABackgroundMediaUpload object
* needed for a call to completeBackgroundMediaUpload:fileName:parentNode:fingerprint:originalFingerprint:binaryUploadToken:delegate: in MEGASdk.
* The object must have been serialised before the app was unloaded by using serialize method in MEGABackgroundMediaUpload.
*
* You take ownership of the returned value.
*
* @param data The binary the object was serialized to previously.
* @param sdk The MEGASdk this object will be used with. It must live longer than this object.
* @return A new MEGABackgroundMediaUpload instance with all fields set to the data that was
* stored in the serialized binary data.
*/
+ (instancetype)unserializByData:(NSData *)data MEGASdk:(MEGASdk *)sdk;

@end

NS_ASSUME_NONNULL_END
84 changes: 84 additions & 0 deletions bindings/ios/MEGABackgroundMediaUpload.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @file MEGABackgroundMediaUpload.mm
* @brief Background media upload
*
* (c) 2018 - by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/

#import "MEGABackgroundMediaUpload.h"
#import "megaapi.h"
#import "MEGABackgroundMediaUpload+init.h"
#import "MEGASdk+init.h"

@interface MEGABackgroundMediaUpload ()

@property (nonatomic) mega::MegaBackgroundMediaUpload *mediaUpload;

@end

@implementation MEGABackgroundMediaUpload

- (instancetype)initWithBackgroundMediaUpload:(mega::MegaBackgroundMediaUpload *)mediaUpload {
self = [super init];
if (self) {
_mediaUpload = mediaUpload;
}

return self;
}

- (instancetype)initWithMEGASdk:(MEGASdk *)sdk {
return [self initWithBackgroundMediaUpload:mega::MegaBackgroundMediaUpload::createInstance(sdk.getCPtr)];
}

- (void)dealloc {
delete _mediaUpload;
}

- (mega::MegaBackgroundMediaUpload *)getCPtr {
return self.mediaUpload;
}

- (BOOL)analyseMediaInfoForFileAtPath:(NSString *)inputFilepath {
return self.mediaUpload->analyseMediaInfo(inputFilepath.UTF8String);
}

- (NSString *)encryptFileAtPath:(NSString *)inputFilePath startPosition:(int64_t)start length:(int64_t *)length outputFilePath:(NSString *)outputFilePath adjustsSizeOnly:(BOOL)adjustsSizeOnly {
const char *suffix = self.mediaUpload->encryptFile(inputFilePath.UTF8String, start, length, outputFilePath.UTF8String, adjustsSizeOnly);
return suffix == NULL ? nil : @(suffix);
}

- (NSString *)uploadURLString {
const char *urlString = self.mediaUpload->getUploadURL();
return urlString == NULL ? nil : @(urlString);
}

- (void)setCoordinatesWithLatitude:(double)latitude longitude:(double)longitude isUnshareable:(BOOL)unshareable {
self.mediaUpload->setCoordinates(latitude, longitude, unshareable);
}

- (NSData *)serialize {
const char *binary = self.mediaUpload->serialize();
return binary == NULL ? nil : [NSData dataWithBytes:binary length:strlen(binary)];
}

+ (instancetype)unserializByData:(NSData *)data MEGASdk:(MEGASdk *)sdk {
mega::MegaBackgroundMediaUpload *mediaUpload = mega::MegaBackgroundMediaUpload::unserialize((const char *)data.bytes, sdk.getCPtr);
return [[self alloc] initWithBackgroundMediaUpload:mediaUpload];
}

@end
3 changes: 2 additions & 1 deletion bindings/ios/MEGAEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typedef NS_ENUM(NSUInteger, Event) {
EventDisconnect = 3,
EventAccountBlocked = 4,
EventStorage = 5,
EventNodesCurrent = 6
EventNodesCurrent = 6,
EventMediaInfoReady = 7
};

/**
Expand Down
2 changes: 2 additions & 0 deletions bindings/ios/MEGAGlobalDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
*
* - EventNodesCurrent: when all external changes have been received
*
* - EventMediaInfoReady: when codec-mappings have been received
*
* You can check the type of event by calling [MEGAEvent type]
*
* @param api MEGASdk object connected to the account
Expand Down
11 changes: 10 additions & 1 deletion bindings/ios/MEGARequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,17 @@ typedef NS_ENUM (NSInteger, MEGARequestType) {
MEGARequestTypeRemoveBackup,
MEGARequestTypeTimer,
MEGARequestTypeAbortCurrentBackup,
MEGARequestTypeFetchTimeZone,
MEGARequestTypeGetPSA,
MEGARequestTypeFetchTimeZone,
MEGARequestTypeUseralertAcknowledge,
MEGARequestTypeChatLinkHandle,
MEGARequestTypeChatLinkUrl,
MEGARequestTypeSetPrivateMode,
MEGARequestTypeAutojoinPublicChat,
MEGARequestTypeCatchup,
MEGARequestTypePublicLinkInformation,
MEGARequestTypeGetBackgroundUploadURL,
MEGARequestTypeCompleteBackgroundUpload,
TotalOfRequestTypes
};

Expand Down
27 changes: 21 additions & 6 deletions bindings/ios/MEGASDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
4148209A1C561CB500552E76 /* mega_http_parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 414820991C561CB500552E76 /* mega_http_parser.cpp */; };
418412731BA1A06600D94E72 /* MEGAInputStream.mm in Sources */ = {isa = PBXBuildFile; fileRef = 418412721BA1A06600D94E72 /* MEGAInputStream.mm */; };
418412731BA1A06600D94E72 /* MEGADataInputStream.mm in Sources */ = {isa = PBXBuildFile; fileRef = 418412721BA1A06600D94E72 /* MEGADataInputStream.mm */; };
41A990731A5D305700B2094A /* mega_utf8proc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41A990721A5D305700B2094A /* mega_utf8proc.cpp */; };
41AB68F21A094194003FE608 /* GfxProcCG.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41AB68F11A094194003FE608 /* GfxProcCG.mm */; };
41AD7A7E1A1E10F900D66856 /* DelegateMEGALoggerListener.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41AD7A7C1A1E10F900D66856 /* DelegateMEGALoggerListener.mm */; };
Expand Down Expand Up @@ -91,6 +91,8 @@
A8A86BD51F559EDA00C214DA /* mega_zxcvbn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A86BD41F559EDA00C214DA /* mega_zxcvbn.cpp */; };
A8FD7B641E93B40E0031FC50 /* osxutils.mm in Sources */ = {isa = PBXBuildFile; fileRef = A8FD7B631E93B40E0031FC50 /* osxutils.mm */; };
B6657E9C225C2B6200EF8D91 /* raid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6657E9B225C2B6200EF8D91 /* raid.cpp */; };
B698890D2198CCE300D0EE89 /* MEGAFileInputStream.mm in Sources */ = {isa = PBXBuildFile; fileRef = B698890B2198CCE300D0EE89 /* MEGAFileInputStream.mm */; };
B6A6CB662170125A009032C9 /* MEGABackgroundMediaUpload.mm in Sources */ = {isa = PBXBuildFile; fileRef = B6A6CB652170125A009032C9 /* MEGABackgroundMediaUpload.mm */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -109,8 +111,8 @@
414820951C523B2D00552E76 /* mega_http_parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mega_http_parser.h; sourceTree = "<group>"; };
414820961C523B2D00552E76 /* pendingcontactrequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pendingcontactrequest.h; sourceTree = "<group>"; };
414820991C561CB500552E76 /* mega_http_parser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mega_http_parser.cpp; path = ../../src/mega_http_parser.cpp; sourceTree = "<group>"; };
418412711BA1A06600D94E72 /* MEGAInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MEGAInputStream.h; sourceTree = "<group>"; };
418412721BA1A06600D94E72 /* MEGAInputStream.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MEGAInputStream.mm; sourceTree = "<group>"; };
418412711BA1A06600D94E72 /* MEGADataInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MEGADataInputStream.h; sourceTree = "<group>"; };
418412721BA1A06600D94E72 /* MEGADataInputStream.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MEGADataInputStream.mm; sourceTree = "<group>"; };
41A990721A5D305700B2094A /* mega_utf8proc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mega_utf8proc.cpp; path = ../../src/mega_utf8proc.cpp; sourceTree = "<group>"; };
41AA739B1A56B246008601DD /* MEGAAccountDetails+init.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MEGAAccountDetails+init.h"; sourceTree = "<group>"; };
41AB68ED1A093C3D003FE608 /* MEGASdk+init.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MEGASdk+init.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -306,8 +308,13 @@
A8EBFDD21EFAE14C00DF89DA /* MEGAEvent+init.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MEGAEvent+init.h"; sourceTree = "<group>"; };
A8FD7B611E93B3ED0031FC50 /* osxutils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = osxutils.h; path = osx/osxutils.h; sourceTree = "<group>"; };
A8FD7B631E93B40E0031FC50 /* osxutils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = osxutils.mm; path = ../../src/osx/osxutils.mm; sourceTree = "<group>"; };
B622FC762174261F00CF707C /* MEGABackgroundMediaUpload+init.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MEGABackgroundMediaUpload+init.h"; sourceTree = "<group>"; };
B6657E9B225C2B6200EF8D91 /* raid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = raid.cpp; path = ../../src/raid.cpp; sourceTree = "<group>"; };
B6657E9D225C2BE600EF8D91 /* raid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = raid.h; sourceTree = "<group>"; };
B698890B2198CCE300D0EE89 /* MEGAFileInputStream.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MEGAFileInputStream.mm; sourceTree = "<group>"; };
B698890C2198CCE300D0EE89 /* MEGAFileInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MEGAFileInputStream.h; sourceTree = "<group>"; };
B6A6CB642170125A009032C9 /* MEGABackgroundMediaUpload.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MEGABackgroundMediaUpload.h; sourceTree = "<group>"; };
B6A6CB652170125A009032C9 /* MEGABackgroundMediaUpload.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MEGABackgroundMediaUpload.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -486,6 +493,8 @@
A820A3092155111C00C8B6A5 /* MEGATimeZoneDetails.mm */,
5B1D7CDD21F1E01E00B0215E /* MEGARecentActionBucket.h */,
5B1D7CE121F1E07200B0215E /* MEGARecentActionBucket.mm */,
B6A6CB642170125A009032C9 /* MEGABackgroundMediaUpload.h */,
B6A6CB652170125A009032C9 /* MEGABackgroundMediaUpload.mm */,
);
name = bindings;
sourceTree = "<group>";
Expand Down Expand Up @@ -630,8 +639,10 @@
41B0CE781A038EB9008D6044 /* MEGAPricing+init.h */,
41AB68ED1A093C3D003FE608 /* MEGASdk+init.h */,
41AA739B1A56B246008601DD /* MEGAAccountDetails+init.h */,
418412711BA1A06600D94E72 /* MEGAInputStream.h */,
418412721BA1A06600D94E72 /* MEGAInputStream.mm */,
418412711BA1A06600D94E72 /* MEGADataInputStream.h */,
418412721BA1A06600D94E72 /* MEGADataInputStream.mm */,
B698890C2198CCE300D0EE89 /* MEGAFileInputStream.h */,
B698890B2198CCE300D0EE89 /* MEGAFileInputStream.mm */,
41D98D021BD5504700764370 /* MEGAContactRequest+init.h */,
41D98D081BD5679C00764370 /* MEGAContactRequestList+init.h */,
A81790121EFAD24F00110E91 /* MEGAHandleList+init.h */,
Expand All @@ -642,6 +653,7 @@
A827F4DE204D450E006A1962 /* MEGAFolderInfo+init.h */,
A808E4862158DAC400BDCE82 /* MEGATimeZoneDetails+init.h */,
5B0670CD21F5BABD00AD9F99 /* MEGARecentActionBucket+init.h */,
B622FC762174261F00CF707C /* MEGABackgroundMediaUpload+init.h */,
);
path = Private;
sourceTree = "<group>";
Expand Down Expand Up @@ -726,6 +738,7 @@
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 9472043A19ED916F00F6805F;
productRefGroup = 9472044419ED916F00F6805F /* Products */;
Expand Down Expand Up @@ -756,7 +769,7 @@
940BF01419ED97B9007E7FA2 /* MEGAShare.mm in Sources */,
41D143DA1B5FC053000CA86F /* pendingcontactrequest.cpp in Sources */,
940BF01219ED97B9007E7FA2 /* MEGANodeList.mm in Sources */,
418412731BA1A06600D94E72 /* MEGAInputStream.mm in Sources */,
418412731BA1A06600D94E72 /* MEGADataInputStream.mm in Sources */,
940BEFC419ED92C2007E7FA2 /* logging.cpp in Sources */,
940BEFF519ED9351007E7FA2 /* waiter.cpp in Sources */,
A81790151EFADDDE00110E91 /* MEGAEvent.mm in Sources */,
Expand Down Expand Up @@ -801,9 +814,11 @@
41B538CC1A0284CB00EABDC9 /* MEGAPricing.mm in Sources */,
940BEFD419ED92C2007E7FA2 /* utils.cpp in Sources */,
A87843F5215D078700E809EB /* useralerts.cpp in Sources */,
B698890D2198CCE300D0EE89 /* MEGAFileInputStream.mm in Sources */,
940BEFF319ED9351007E7FA2 /* fs.cpp in Sources */,
A88722DC1FFE6A8B00E3F443 /* mediafileattribute.cpp in Sources */,
A827F4DD204D3D14006A1962 /* MEGAFolderInfo.mm in Sources */,
B6A6CB662170125A009032C9 /* MEGABackgroundMediaUpload.mm in Sources */,
940BEFC719ED92C2007E7FA2 /* megaclient.cpp in Sources */,
940BEFEB19ED9351007E7FA2 /* sodium.cpp in Sources */,
41B2AEDB1A0A859C006C40FB /* DelegateMEGARequestListener.mm in Sources */,
Expand Down
Loading

0 comments on commit f293e3a

Please sign in to comment.