Permalink
Browse files

Added backend code for custom strings. Issue #82 and #84

  • Loading branch information...
1 parent 1d01b3c commit 4923cf70495e5e7d70908f5001912cba8995c586 Jason Rush committed May 18, 2012
Showing with 29 additions and 5 deletions.
  1. +2 −0 KeePassLib/Kdb4Node.h
  2. +2 −0 KeePassLib/Kdb4Node.m
  3. +13 −5 KeePassLib/Kdb4Parser.m
  4. +2 −0 KeePassLib/Kdb4Persist.m
  5. +10 −0 MiniKeePass/EntryViewController.m
@@ -52,9 +52,11 @@
@interface Kdb4Entry : KdbEntry {
DDXMLElement *element;
+ NSMutableDictionary *stringFields;
}
@property(nonatomic, retain) DDXMLElement *element;
+@property(nonatomic, retain) NSMutableDictionary *stringFields;
- (id)initWithElement:(DDXMLElement*)e;
@@ -68,11 +68,13 @@ - (void)removeEntry:(KdbEntry*)entry {
@implementation Kdb4Entry
@synthesize element;
+@synthesize stringFields;
- (id)initWithElement:(DDXMLElement*)e {
self = [super init];
if(self) {
self.element = e;
+ self.stringFields = [[NSMutableDictionary alloc] init];
}
return self;
}
@@ -19,6 +19,12 @@
#import "Kdb4Node.h"
#import "Base64.h"
+#define FIELD_TITLE @"Title"
+#define FIELD_USER_NAME @"UserName"
+#define FIELD_PASSWORD @"Password"
+#define FIELD_URL @"URL"
+#define FIELD_NOTES @"Notes"
+
@implementation DDXMLDocument (MKPDDXMLDocument_Additions)
- (id)initWithReadIO:(xmlInputReadCallback)ioread closeIO:(xmlInputCloseCallback)ioclose context:(void*)ioctx options:(NSUInteger)mask error:(NSError **)error {
@@ -198,16 +204,18 @@ - (Kdb4Entry*)parseEntry:(DDXMLElement*)root {
DDXMLElement *valueElement = [element elementForName:@"Value"];
NSString *value = [valueElement stringValue];
- if ([key isEqualToString:@"Title"]) {
+ if ([key isEqualToString:FIELD_TITLE]) {
entry.title = value;
- } else if ([key isEqualToString:@"UserName"]) {
+ } else if ([key isEqualToString:FIELD_USER_NAME]) {
entry.username = value;
- } else if ([key isEqualToString:@"Password"]) {
+ } else if ([key isEqualToString:FIELD_PASSWORD]) {
entry.password = value;
- } else if ([key isEqualToString:@"URL"]) {
+ } else if ([key isEqualToString:FIELD_URL]) {
entry.url = value;
- } else if ([key isEqualToString:@"Notes"]) {
+ } else if ([key isEqualToString:FIELD_NOTES]) {
entry.notes = value;
+ } else {
+ [entry.stringFields setValue:value forKey:key];
}
}
@@ -126,6 +126,8 @@ - (void)updateEntry:(Kdb4Entry*)entry {
valueElement.stringValue = entry.url;
} else if ([key isEqualToString:@"Notes"]) {
valueElement.stringValue = entry.notes;
+ } else {
+ valueElement.stringValue = [entry.stringFields valueForKey:key];
}
}
}
@@ -16,6 +16,7 @@
*/
#import "EntryViewController.h"
+#import "Kdb4Node.h"
@implementation EntryViewController
@@ -133,6 +134,15 @@ - (void)setEntry:(KdbEntry *)e {
passwordCell.textField.text = entry.password;
urlCell.textField.text = entry.url;
commentsCell.textView.text = entry.notes;
+
+ // FIXME Example code for looping through string fields
+ if ([entry isKindOfClass:[Kdb4Entry class]]) {
+ Kdb4Entry *kdb4Entry = (Kdb4Entry*)entry;
+ for (NSString *key in kdb4Entry.stringFields) {
+ NSString *value = [kdb4Entry.stringFields valueForKey:key];
+ NSLog(@"%@ = %@\n", key, value);
+ }
+ }
}
- (KdbEntry *)entry {

0 comments on commit 4923cf7

Please sign in to comment.