Skip to content

Commit

Permalink
Merge pull request #48 from readium/feature/xcode10
Browse files Browse the repository at this point in the history
XCode 10 updates (broken build) + API updates (convenient additions, no risk of regression bugs on existing APIs) + debug / logging messages
  • Loading branch information
danielweck authored Nov 7, 2018
2 parents 9a33f28 + 82750a7 commit aa9d8de
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 46 deletions.
18 changes: 17 additions & 1 deletion platform/apple/LCP Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@
5ACE2E031BF21D7900AC0585 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0800;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = Readium;
TargetAttributes = {
5ACE2E1A1BF21D8C00AC0585 = {
Expand Down Expand Up @@ -888,14 +888,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -934,14 +942,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
8 changes: 7 additions & 1 deletion platform/apple/src/LCPLicense.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ namespace lcp {
}
#endif


@interface LCPLicense : NSObject

@property (readonly, nonatomic) NSString *identifier;
@property (readonly, nonatomic) NSString *linkPublication;
@property (readonly, nonatomic) BOOL isDecrypted;

@property (readonly, nonatomic) NSString *username;
@property (readonly, nonatomic) NSString *userHint;

- (NSString *)originalJSON;
- (NSString *)canonicalJSON;

- (NSDate *)rightsStart;
- (NSDate *)rightsEnd;

#ifdef __cplusplus
@property (readonly, nonatomic) lcp::ILicense *nativeLicense;
- (instancetype)initWithLicense:(lcp::ILicense *)nativeLicense NS_DESIGNATED_INITIALIZER;
Expand Down
84 changes: 82 additions & 2 deletions platform/apple/src/LCPLicense.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#import "LCPLicense.h"

#import "ICrypto.h"
#import "ILicense.h"

#import "ILinks.h"
#import "IRights.h"
#import "IUser.h"

@interface LCPLicense ()
@property (nonatomic) lcp::ILicense *nativeLicense;
Expand Down Expand Up @@ -77,9 +77,89 @@ - (BOOL)isDecrypted
return _nativeLicense->Decrypted();
}

- (NSString *)username
{
if (_nativeLicense->User() != NULL) { // _nativeLicense->User()->Name() can be std::string.empty(), but not nil
return [NSString stringWithUTF8String:_nativeLicense->User()->Name().c_str()];
}
return @""; // no nil return to be consistent with the above potential missing Name() JSON value (empty std::string)
}

- (NSString *)userHint
{
return [NSString stringWithUTF8String:_nativeLicense->Crypto()->UserKeyHint().c_str()];
}

- (NSString *)originalJSON
{
return [NSString stringWithUTF8String:_nativeLicense->OriginalContent().c_str()];
}

- (NSString *)canonicalJSON
{
return [NSString stringWithUTF8String:_nativeLicense->CanonicalContent().c_str()];
}

- (NSDate *)rightsStart {
std::string start;
// _nativeLicense->Rights()->HasRightValue(lcp::StartRight)
if (_nativeLicense->Rights() != NULL && _nativeLicense->Rights()->GetRightValue(lcp::StartRight, start)) {
NSString *startDateString = [NSString stringWithUTF8String:start.c_str()];

NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
NSDate *startDate = [dateFormatter dateFromString:startDateString]; // may be nil
return startDate;
}
return nil;

// NSData *data = [[self canonicalJSON] dataUsingEncoding:NSUTF8StringEncoding];
//
// NSError *error;
// NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
// if (!jsonDictionary) {
// NSLog(@"Failed to parse license JSON: %@", error);
// return nil;
// }
//
// NSDictionary *rights = [jsonDictionary objectForKey:@"rights"];
// if (rights == nil) { // no need to check for (id)[NSNull null] here (because source data is LCP license JSON)
// return nil;
// }
// NSString *startDateString = [rights objectForKey:@"start"];
// if (startDateString == nil || [startDateString length] == 0) { // early exit
// return nil;
// }
}

- (NSDate *)rightsEnd {
std::string end;
// _nativeLicense->Rights()->HasRightValue(lcp::StartRight)
if (_nativeLicense->Rights() != NULL && _nativeLicense->Rights()->GetRightValue(lcp::EndRight, end)) {
NSString *endDateString = [NSString stringWithUTF8String:end.c_str()];

NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
NSDate *endDate = [dateFormatter dateFromString:endDateString]; // may be nil
return endDate;
}
return nil;

// NSData *data = [[self canonicalJSON] dataUsingEncoding:NSUTF8StringEncoding];
//
// NSError *error;
// NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
// if (!jsonDictionary) {
// NSLog(@"Failed to parse license JSON: %@", error);
// return nil;
// }
//
// NSDictionary *rights = [jsonDictionary objectForKey:@"rights"];
// if (rights == nil) { // no need to check for (id)[NSNull null] here (because source data is LCP license JSON)
// return nil;
// }
// NSString *endDateString = [rights objectForKey:@"end"];
// if (endDateString == nil || [endDateString length] == 0) { // early exit
// return nil;
// }
}

@end
41 changes: 39 additions & 2 deletions platform/apple/src/LCPStatusDocumentProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@

#import <Foundation/Foundation.h>

@interface StatusDocumentLink : NSObject {
NSString* rel;
NSString* href;
NSString* type;
BOOL templated;
NSString* title;
NSString* profile;
}

- (instancetype)init_:(NSString*) rel href:(NSString*) href type:(NSString*) type templated:(BOOL) templated title:(NSString*) title profile:(NSString*) profile;

@property (nonatomic, readonly) NSString* rel;
@property (nonatomic, readonly) NSString* href;
@property (nonatomic, readonly) NSString* type;
@property (nonatomic, readonly) BOOL templated;
@property (nonatomic, readonly) NSString* title;
@property (nonatomic, readonly) NSString* profile;

@end

@protocol DeviceIdManager

Expand Down Expand Up @@ -61,11 +80,29 @@ typedef void (^DoneCallback)(bool);
-(bool)isInitialized;

-(bool)hasLicenseUpdatePending;

- (NSString *)identifier;
- (NSString *)message;

-(NSString *)status;
-(bool)isActive;
-(bool)hasRenewLink;
-(bool)hasReturnLink;

-(StatusDocumentLink *)licenseLink;

-(bool)hasRegisterLink;
-(StatusDocumentLink *)registerLink;

-(bool)hasRenewLink;
-(StatusDocumentLink *)renewLink;
-(void)doRenew:(DoneCallback)doneCallback_doRenew; //void(^)(bool)

-(bool)hasReturnLink;
-(StatusDocumentLink *)returnLink;
-(void)doReturn:(DoneCallback)doneCallback_doReturn; //void(^)(bool)

-(NSDate *)potentialRightsEndDate;

- (NSDate *)statusUpdated;
- (NSDate *)licenseUpdated;

@end
Loading

0 comments on commit aa9d8de

Please sign in to comment.