From eb4e25c0ba59c930a7ed00031fe22cbce872e230 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 11 May 2012 09:05:11 +0200 Subject: [PATCH] Fix importing of sites. [FIXED] Parsing mpsites for import. --- External/iCloudStoreManager | 2 +- MasterPassword-iOS.xcodeproj/project.pbxproj | 3 +- MasterPassword/MPAppDelegate_Store.m | 37 +++++++++++-------- .../MasterPassword.xcdatamodel/contents | 6 +-- Site/1/index.html | 16 +++++++- Site/2/index.html | 14 +++++++ 6 files changed, 55 insertions(+), 23 deletions(-) diff --git a/External/iCloudStoreManager b/External/iCloudStoreManager index 71cfb8f4..01f70ef9 160000 --- a/External/iCloudStoreManager +++ b/External/iCloudStoreManager @@ -1 +1 @@ -Subproject commit 71cfb8f4e21a536f5d88a69401f02eeaf1c0a89f +Subproject commit 01f70ef927d497fb179688b1e2da0b25f80ec425 diff --git a/MasterPassword-iOS.xcodeproj/project.pbxproj b/MasterPassword-iOS.xcodeproj/project.pbxproj index f641b97b..1f03606c 100644 --- a/MasterPassword-iOS.xcodeproj/project.pbxproj +++ b/MasterPassword-iOS.xcodeproj/project.pbxproj @@ -4092,7 +4092,7 @@ CLANG_WARN_OBJCPP_ARC_ABI = YES; CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Maarten Billemont (DWGU95U4ZD)"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -4132,6 +4132,7 @@ ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "${TARGET_NAME}"; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = "8CFABC40-E134-41B3-83D3-DD64DE74903D"; SDKROOT = iphoneos; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/MasterPassword/MPAppDelegate_Store.m b/MasterPassword/MPAppDelegate_Store.m index e4488a40..fe260a2e 100644 --- a/MasterPassword/MPAppDelegate_Store.m +++ b/MasterPassword/MPAppDelegate_Store.m @@ -269,13 +269,13 @@ static NSDateFormatter *rfc3339DateFormatter = nil; } // Header - if ([headerPattern numberOfMatchesInString:importedSiteLine options:0 range:NSRangeFromString(importedSiteLine)] != 2) { + if ([headerPattern numberOfMatchesInString:importedSiteLine options:0 range:NSMakeRange(0, [importedSiteLine length])] != 1) { err(@"Invalid header format in line: %@", importedSiteLine); return MPImportResultMalformedInput; } - NSArray *headerElements = [headerPattern matchesInString:importedSiteLine options:0 range:NSRangeFromString(importedSiteLine)]; - NSString *key = [importedSiteLine substringWithRange:[[headerElements objectAtIndex:0] range]]; - NSString *value = [importedSiteLine substringWithRange:[[headerElements objectAtIndex:1] range]]; + NSTextCheckingResult *headerElements = [[headerPattern matchesInString:importedSiteLine options:0 range:NSMakeRange(0, [importedSiteLine length])] lastObject]; + NSString *key = [importedSiteLine substringWithRange:[headerElements rangeAtIndex:1]]; + NSString *value = [importedSiteLine substringWithRange:[headerElements rangeAtIndex:2]]; if ([key isEqualToString:@"Key ID"]) { if (![(keyID = value) isEqualToString:[keyHashForPassword(password) encodeHex]]) return MPImportResultInvalidPassword; @@ -291,16 +291,16 @@ static NSDateFormatter *rfc3339DateFormatter = nil; continue; // Site - if ([sitePattern numberOfMatchesInString:importedSiteLine options:0 range:NSRangeFromString(importedSiteLine)] != 2) { + if ([sitePattern numberOfMatchesInString:importedSiteLine options:0 range:NSMakeRange(0, [importedSiteLine length])] != 1) { err(@"Invalid site format in line: %@", importedSiteLine); return MPImportResultMalformedInput; } - NSArray *siteElements = [headerPattern matchesInString:importedSiteLine options:0 range:NSRangeFromString(importedSiteLine)]; - NSString *lastUsed = [importedSiteLine substringWithRange:[[siteElements objectAtIndex:0] range]]; - NSString *uses = [importedSiteLine substringWithRange:[[siteElements objectAtIndex:1] range]]; - NSString *type = [importedSiteLine substringWithRange:[[siteElements objectAtIndex:2] range]]; - NSString *name = [importedSiteLine substringWithRange:[[siteElements objectAtIndex:3] range]]; - NSString *exportContent = [importedSiteLine substringWithRange:[[siteElements objectAtIndex:4] range]]; + NSTextCheckingResult *siteElements = [[sitePattern matchesInString:importedSiteLine options:0 range:NSMakeRange(0, [importedSiteLine length])] lastObject]; + NSString *lastUsed = [importedSiteLine substringWithRange:[siteElements rangeAtIndex:1]]; + NSString *uses = [importedSiteLine substringWithRange:[siteElements rangeAtIndex:2]]; + NSString *type = [importedSiteLine substringWithRange:[siteElements rangeAtIndex:3]]; + NSString *name = [importedSiteLine substringWithRange:[siteElements rangeAtIndex:4]]; + NSString *exportContent = [importedSiteLine substringWithRange:[siteElements rangeAtIndex:5]]; // Find existing site. fetchRequest.predicate = [NSPredicate predicateWithFormat:@"name == %@ AND keyID == %@", name, keyID]; @@ -320,9 +320,11 @@ static NSDateFormatter *rfc3339DateFormatter = nil; // Delete existing sites. [elementsToDelete enumerateObjectsUsingBlock:^(id obj, BOOL *stop) { + dbg(@"Deleting: %@", [obj name]); [self.managedObjectContext deleteObject:obj]; }]; - + [self saveContext]; + // Import new sites. for (NSArray *siteElements in importedSiteElements) { NSDate *lastUsed = [rfc3339DateFormatter dateFromString:[siteElements objectAtIndex:0]]; @@ -332,16 +334,19 @@ static NSDateFormatter *rfc3339DateFormatter = nil; NSString *exportContent = [siteElements objectAtIndex:4]; // Create new site. + dbg(@"Creating: name=%@, lastUsed=%@, uses=%d, type=%u, keyID=%@", name, lastUsed, uses, type, keyID); MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:ClassNameFromMPElementType(type) inManagedObjectContext:self.managedObjectContext]; - element.lastUsed = [lastUsed timeIntervalSinceReferenceDate]; - element.uses = uses; - element.type = type; element.name = name; + element.keyID = keyID; + element.type = type; + element.uses = uses; + element.lastUsed = [lastUsed timeIntervalSinceReferenceDate]; if ([exportContent length]) [element importContent:exportContent]; } - + [self saveContext]; + return MPImportResultSuccess; } diff --git a/MasterPassword/MasterPassword.xcdatamodeld/MasterPassword.xcdatamodel/contents b/MasterPassword/MasterPassword.xcdatamodeld/MasterPassword.xcdatamodel/contents index 9bc67eeb..2755e835 100644 --- a/MasterPassword/MasterPassword.xcdatamodeld/MasterPassword.xcdatamodel/contents +++ b/MasterPassword/MasterPassword.xcdatamodeld/MasterPassword.xcdatamodel/contents @@ -1,9 +1,9 @@ - + - + - + diff --git a/Site/1/index.html b/Site/1/index.html index 6e20ccc6..6258cbdd 100644 --- a/Site/1/index.html +++ b/Site/1/index.html @@ -37,8 +37,20 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); - - + +
diff --git a/Site/2/index.html b/Site/2/index.html index f2ba6389..1b7a7c07 100644 --- a/Site/2/index.html +++ b/Site/2/index.html @@ -28,6 +28,20 @@ navigateTo(document.location.hash.substring(1)); }); + ")); + +