Added AutotypeHelper to encasulate format checks

This commit is contained in:
michael starke
2014-08-10 19:11:43 +02:00
parent 4802b7ddf6
commit b2adf2b78e
5 changed files with 72 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
//
// MPAutotypeHelper.h
// MacPass
//
// Created by Michael Starke on 10/08/14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MPAutotypeHelper : NSObject
/**
* Tests the given item for a possible wrong autotype format
* MacPass 0.4 and 0.4.1 did store wrong Autotype sequences and thus mangled database files
*
* @param item Item to test for malformation. Allowed Items are KPKNode, KPKEntry, KPKGroup and KPKAutotype
*
* @return YES if the given item is considered a possible candiate. NO in all other cases
*/
+ (BOOL)isCandidateForMalformedAutotype:(id)item;
@end

View File

@@ -0,0 +1,35 @@
//
// MPAutotypeHelper.m
// MacPass
//
// Created by Michael Starke on 10/08/14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import "MPAutotypeHelper.h"
#import "KPKGroup.h"
#import "KPKEntry.h"
#import "KPKAutotype.h"
#import "KPKWindowAssociation.h"
@implementation MPAutotypeHelper
+ (BOOL)isCandidateForMalformedAutotype:(id)item {
NSString *keystrokeSequence;
if([item isKindOfClass:[KPKEntry class]] && ![((KPKEntry *)item).autotype hasDefaultKeystrokeSequence]) {
keystrokeSequence = ((KPKEntry *)item).autotype.defaultKeystrokeSequence;
}
else if( [item isKindOfClass:[KPKGroup class]] && ![item hasDefaultAutotypeSequence]) {
keystrokeSequence = ((KPKGroup *)item).defaultAutoTypeSequence;
}
else if( [item isKindOfClass:[KPKWindowAssociation class]] && ![item hasDefaultKeystrokeSequence]){
keystrokeSequence = ((KPKWindowAssociation *)item).keystrokeSequence;
}
/* if nothing is true, keystrokeSequence is nil an hence return is NO */
return (NSOrderedSame == [@"{TAB}{USERNAME}{TAB}{PASSWORD}{ENTER}" compare:keystrokeSequence options:NSCaseInsensitiveSearch]);
}
@end

View File

@@ -12,6 +12,8 @@
@interface MPIntegrationSettingsController ()
@property (copy) NSData *globalAutotypeKeyData;
@end
@implementation MPIntegrationSettingsController
@@ -38,10 +40,12 @@
NSString *serverKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableHttpServer];
NSString *globalAutotypeKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype];
NSString *quicklookKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableQuicklookPreview];
NSString *globalAutotypeDataKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey];
[self.enableServerCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:serverKeyPath options:nil];
[self.enableServerCheckbutton setEnabled:NO];
[self.enableGlobalAutotypeCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeKeyPath options:nil];
[self.enableQuicklookCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:quicklookKeyPath options:nil];
[self.globalAutotypeKeyData bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeDataKeyPath options:nil];
}

View File

@@ -47,10 +47,10 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases;
APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases;
/* Autotype */
APPKIT_EXTERN NSString *const kMPSettingsKeySendCommandForControlKey;
APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype;
APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey;
APPKIT_EXTERN NSString *const kMPSettingsKeyDocumentsAutotypeFixNoteWasShown;
APPKIT_EXTERN NSString *const kMPSettingsKeySendCommandForControlKey; // Should MacPass swap control for command. This is usefull in a cross plattform environment
APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; // Is Global Autotype enabled?
APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey; // The stored Data for the useder defined global autotype key
APPKIT_EXTERN NSString *const kMPSettingsKeyDocumentsAutotypeFixNoteWasShown; //
/* Search */
APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterMode;