Limit public API to the LicenseManager singleton

This commit is contained in:
Allan Odgaard
2016-10-15 14:19:01 +02:00
parent 5443b1b48f
commit 34db8d64ff
5 changed files with 26 additions and 20 deletions

View File

@@ -3,7 +3,6 @@
#import <OakFoundation/OakFoundation.h>
#import <OakFoundation/NSString Additions.h>
#import <BundlesManager/BundlesManager.h>
#import <license/license.h>
#import <license/LicenseManager.h>
#import <ns/ns.h>
@@ -48,18 +47,7 @@ static NSData* Digest (NSString* someString)
- (NSString*)licensees
{
if(!licensees)
{
for(auto owner : license::find_all())
{
if(license::is_valid(license::decode(license::find(owner)), owner))
{
licensees = [NSString stringWithCxxString:owner];
break;
}
}
}
return licensees;
return LicenseManager.sharedInstance.owner;
}
- (void)addLicense

View File

@@ -26,7 +26,6 @@
#import <regexp/glob.h>
#import <network/tbz.h>
#import <ns/ns.h>
#import <license/license.h>
#import <license/LicenseManager.h>
#import <settings/settings.h>
#import <oak/debug.h>
@@ -164,11 +163,8 @@ BOOL HasDocumentWindow (NSArray* windows)
if([currentDate laterDate:warningDate] == warningDate)
return (void)[NSTimer scheduledTimerWithTimeInterval:7 * kSecondsPerDay target:self selector:@selector(checkExpirationDate:) userInfo:nil repeats:NO];
for(auto owner : license::find_all())
{
if(license::is_valid(license::decode(license::find(owner)), owner))
return;
}
if(LicenseManager.sharedInstance.owner != nil)
return;
if([currentDate laterDate:expirationDate] == currentDate)
{

View File

@@ -3,4 +3,5 @@
PUBLIC @interface LicenseManager : NSObject
+ (instancetype)sharedInstance;
- (void)showAddLicenseWindow:(id)sender;
@property (nonatomic, readonly) NSString* owner;
@end

View File

@@ -12,6 +12,9 @@
@end
@interface LicenseManager ()
{
id _owner;
}
- (BOOL)addLicense:(License*)license;
@end
@@ -214,6 +217,23 @@ static NSTextField* OakCreateTextField ()
return self;
}
- (NSString*)owner
{
if(_owner == nil)
{
_owner = [NSNull null];
for(auto owner : license::find_all())
{
if(license::is_valid(license::decode(license::find(owner)), owner))
{
_owner = to_ns(owner);
break;
}
}
}
return _owner != [NSNull null] ? _owner : nil;
}
- (BOOL)addLicense:(License*)info
{
if(info.isValid == NO)
@@ -222,6 +242,7 @@ static NSTextField* OakCreateTextField ()
std::string error = "Unknown error.";
if(license::add(to_s([info.owner stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]), to_s(info.licenseAsBase32), &error))
{
_owner = info.owner;
[self removeAllRegisterButtons:self];
NSRunAlertPanel(@"License Added to Keychain", @"Thanks for your support!", @"Continue", nil, nil);
}

View File

@@ -1,5 +1,5 @@
SOURCES = src/*.{cc,mm}
EXPORT = src/{license,keychain,LicenseManager}.h
EXPORT = src/LicenseManager.h
LINK += crash text cf ns OakAppKit OakFoundation
CXX_FLAGS += -I"$libressl_prefix/include"
LN_FLAGS += -Wl,-U,__Z15revoked_serialsv