From 2cae99ef60ebd9578498c7b210f0e87cd9c0d7e4 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Mon, 6 Feb 2012 16:33:50 +0100 Subject: [PATCH] Fix a few bugs in roster versioning. --- src/XMPPJSONFileStorage.m | 10 +++++++--- src/XMPPRoster.m | 5 +++++ tests/test.m | 10 ++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/XMPPJSONFileStorage.m b/src/XMPPJSONFileStorage.m index 3344e37..d6e8e79 100644 --- a/src/XMPPJSONFileStorage.m +++ b/src/XMPPJSONFileStorage.m @@ -39,7 +39,8 @@ { Class c = isa; [self release]; - @throw [OFNotImplementedException exceptionWithClass: c]; + @throw [OFNotImplementedException exceptionWithClass: c + selector: _cmd]; } - initWithFile: (OFString*)file_ @@ -103,8 +104,11 @@ iter = iter2; } - [iter setObject: object - forKey: [pathComponents lastObject]]; + if (object != nil) + [iter setObject: object + forKey: [pathComponents lastObject]]; + else + [iter removeObjectForKey: [pathComponents lastObject]]; } - (id)XMPP_objectForPath: (OFString*)path diff --git a/src/XMPPRoster.m b/src/XMPPRoster.m index 57882b1..8829787 100644 --- a/src/XMPPRoster.m +++ b/src/XMPPRoster.m @@ -133,6 +133,7 @@ [[rosterElement attributeForName: @"ver"] stringValue]; [dataStorage setStringValue: ver forPath: @"roster.ver"]; + [dataStorage save]; } [delegates broadcastSelector: @selector( @@ -228,6 +229,9 @@ OFMutableDictionary *items = [[[dataStorage dictionaryForPath: @"roster.items"] mutableCopy] autorelease]; + if (items == nil) + items = [OFMutableDictionary dictionary]; + if (![[rosterItem subscription] isEqual: @"remove"]) { OFMutableDictionary *item = [OFMutableDictionary dictionaryWithKeysAndObjects: @@ -342,6 +346,7 @@ [[rosterElement attributeForName: @"ver"] stringValue]; [dataStorage setStringValue: ver forPath: @"roster.ver"]; + [dataStorage save]; } [delegates broadcastSelector: @selector(rosterWasReceived:) diff --git a/tests/test.m b/tests/test.m index 9aeabc1..00acd20 100644 --- a/tests/test.m +++ b/tests/test.m @@ -32,6 +32,7 @@ #import "XMPPMessage.h" #import "XMPPPresence.h" #import "XMPPRoster.h" +#import "XMPPJSONFileStorage.h" @interface AppDelegate: OFObject #ifdef OF_HAVE_OPTIONAL_PROTOCOLS @@ -92,10 +93,15 @@ OF_APPLICATION_DELEGATE(AppDelegate) [[stanza from] fullJID], [[stanza to] fullJID], [stanza type], [stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"])); - conn = [[XMPPConnection alloc] init]; - roster = [[XMPPRoster alloc] initWithConnection: conn]; + conn = [[XMPPConnection alloc] init]; [conn addDelegate: self]; + + XMPPJSONFileStorage *storage = + [[XMPPJSONFileStorage alloc] initWithFile: @"storage.json"]; + [conn setDataStorage: storage]; + + roster = [[XMPPRoster alloc] initWithConnection: conn]; [roster addDelegate: self]; if ([arguments count] != 3) {