Add XMPPRoster class.
This commit is contained in:
parent
3e97096129
commit
915d5b5cab
9 changed files with 239 additions and 34 deletions
|
@ -29,6 +29,7 @@
|
|||
@class XMPPMessage;
|
||||
@class XMPPPresence;
|
||||
@class XMPPAuthenticator;
|
||||
@class XMPPRoster;
|
||||
|
||||
@protocol XMPPConnectionDelegate
|
||||
@optional
|
||||
|
@ -64,7 +65,7 @@
|
|||
BOOL needsSession;
|
||||
unsigned int lastID;
|
||||
OFString *bindID, *sessionID, *rosterID;
|
||||
OFMutableDictionary *roster;
|
||||
XMPPRoster *roster;
|
||||
}
|
||||
|
||||
@property (copy) OFString *username, *password, *server, *resource;
|
||||
|
@ -72,7 +73,7 @@
|
|||
@property (assign) uint16_t port;
|
||||
@property (assign) BOOL useTLS;
|
||||
@property (retain) id <XMPPConnectionDelegate> delegate;
|
||||
@property (copy, readonly) OFDictionary *roster;
|
||||
@property (readonly, retain) XMPPRoster *roster;
|
||||
|
||||
/**
|
||||
* Connects to the XMPP service.
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#import "XMPPIQ.h"
|
||||
#import "XMPPMessage.h"
|
||||
#import "XMPPPresence.h"
|
||||
#import "XMPPRoster.h"
|
||||
#import "XMPPRosterItem.h"
|
||||
#import "XMPPExceptions.h"
|
||||
|
||||
|
@ -81,7 +82,7 @@
|
|||
parser.delegate = self;
|
||||
elementBuilder.delegate = self;
|
||||
|
||||
roster = [[OFMutableDictionary alloc] init];
|
||||
roster = [[XMPPRoster alloc] initWithConnection: self];
|
||||
} @catch (id e) {
|
||||
[self release];
|
||||
@throw e;
|
||||
|
@ -489,7 +490,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
if ([mechs count] > 0) {
|
||||
if (mechs.count > 0) {
|
||||
for (OFXMLElement *mech in [mechs.firstObject children])
|
||||
[mechanisms addObject:
|
||||
[mech.children.firstObject stringValue]];
|
||||
|
@ -654,41 +655,21 @@
|
|||
|
||||
rosterItem = [XMPPRosterItem rosterItem];
|
||||
rosterItem.JID = [XMPPJID JIDWithString:
|
||||
[rosterElem attributeForName: @"jid"].stringValue];
|
||||
rosterItem.name =
|
||||
[rosterElem attributeForName: @"name"].stringValue;
|
||||
[elem attributeForName: @"jid"].stringValue];
|
||||
rosterItem.name = [elem attributeForName: @"name"].stringValue;
|
||||
rosterItem.subscription =
|
||||
[rosterElem attributeForName: @"subscription"].stringValue;
|
||||
[elem attributeForName: @"subscription"].stringValue;
|
||||
|
||||
for (OFXMLElement *groupElem in
|
||||
[elem elementsForName: @"group"
|
||||
namespace: NS_ROSTER]) {
|
||||
OFMutableArray *rosterGroup =
|
||||
[roster objectForKey: rosterElem.stringValue];
|
||||
namespace: NS_ROSTER])
|
||||
[groups addObject:
|
||||
[groupElem.children.firstObject stringValue]];
|
||||
|
||||
if (rosterGroup == nil) {
|
||||
rosterGroup = [OFMutableArray array];
|
||||
[roster setObject: rosterGroup
|
||||
forKey: rosterElem.stringValue];
|
||||
}
|
||||
if (groups.count > 0)
|
||||
rosterItem.groups = groups;
|
||||
|
||||
[rosterGroup addObject: rosterItem];
|
||||
}
|
||||
|
||||
rosterItem.groups = groups;
|
||||
|
||||
if (groups.count == 0) {
|
||||
OFMutableArray *rosterGroup =
|
||||
[roster objectForKey: @""];
|
||||
|
||||
if (rosterGroup == nil) {
|
||||
rosterGroup = [OFMutableArray array];
|
||||
[roster setObject: rosterGroup
|
||||
forKey: @""];
|
||||
}
|
||||
|
||||
[rosterGroup addObject: rosterItem];
|
||||
}
|
||||
[roster XMPP_addRosterItem: rosterItem];
|
||||
}
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
|
|
|
@ -201,4 +201,9 @@
|
|||
return [OFString stringWithFormat: @"%@/%@",
|
||||
domain, resource];
|
||||
}
|
||||
|
||||
- (OFString*)description
|
||||
{
|
||||
return [self fullJID];
|
||||
}
|
||||
@end
|
||||
|
|
38
src/XMPPRoster.h
Normal file
38
src/XMPPRoster.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org>
|
||||
*
|
||||
* https://webkeks.org/hg/objxmpp/
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice is present in all copies.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
@class XMPPConnection;
|
||||
@class XMPPRosterItem;
|
||||
|
||||
@interface XMPPRoster: OFObject
|
||||
{
|
||||
XMPPConnection *connection;
|
||||
OFMutableDictionary *groups;
|
||||
}
|
||||
|
||||
- initWithConnection: (XMPPConnection*)conn;
|
||||
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem;
|
||||
- (OFArray*)groups;
|
||||
- (OFArray*)rosterItemsInGroup: (OFString*)group;
|
||||
@end
|
95
src/XMPPRoster.m
Normal file
95
src/XMPPRoster.m
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org>
|
||||
*
|
||||
* https://webkeks.org/hg/objxmpp/
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice is present in all copies.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import "XMPPRoster.h"
|
||||
#import "XMPPRosterItem.h"
|
||||
|
||||
@implementation XMPPRoster
|
||||
- initWithConnection: (XMPPConnection*)conn
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
@try {
|
||||
connection = [conn retain];
|
||||
groups = [[OFMutableDictionary alloc] init];
|
||||
} @catch (id e) {
|
||||
[self release];
|
||||
@throw e;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[connection release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
|
||||
{
|
||||
if (rosterItem.groups.count > 0) {
|
||||
for (OFString *group in rosterItem.groups) {
|
||||
OFMutableArray *rosterGroup =
|
||||
[groups objectForKey: group];
|
||||
|
||||
if (rosterGroup == nil) {
|
||||
rosterGroup = [OFMutableArray array];
|
||||
[groups setObject: rosterGroup
|
||||
forKey: group];
|
||||
}
|
||||
|
||||
[rosterGroup addObject: rosterItem];
|
||||
}
|
||||
} else {
|
||||
OFMutableArray *rosterGroup = [groups objectForKey: @""];
|
||||
|
||||
if (rosterGroup == nil) {
|
||||
rosterGroup = [OFMutableArray array];
|
||||
[groups setObject: rosterGroup
|
||||
forKey: @""];
|
||||
}
|
||||
|
||||
[rosterGroup addObject: rosterItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (OFArray*)groups
|
||||
{
|
||||
OFMutableArray *ret = [OFMutableArray array];
|
||||
|
||||
for (OFString *group in groups)
|
||||
[ret addObject: group];
|
||||
|
||||
ret->isa = [OFArray class];
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (OFArray*)rosterItemsInGroup: (OFString*)group
|
||||
{
|
||||
if (group == nil)
|
||||
group = @"";
|
||||
|
||||
return [[[groups objectForKey: group] copy] autorelease];
|
||||
}
|
||||
@end
|
34
src/XMPPRosterItem.h
Normal file
34
src/XMPPRosterItem.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org>
|
||||
*
|
||||
* https://webkeks.org/hg/objxmpp/
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice is present in all copies.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
@class XMPPJID;
|
||||
|
||||
@interface XMPPRosterItem: OFObject
|
||||
@property (copy) XMPPJID *JID;
|
||||
@property (copy) OFString *name;
|
||||
@property (copy) OFString *subscription;
|
||||
@property (copy) OFArray *groups;
|
||||
|
||||
+ rosterItem;
|
||||
@end
|
39
src/XMPPRosterItem.m
Normal file
39
src/XMPPRosterItem.m
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org>
|
||||
*
|
||||
* https://webkeks.org/hg/objxmpp/
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice is present in all copies.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import "XMPPRosterItem.h"
|
||||
|
||||
@implementation XMPPRosterItem
|
||||
@synthesize JID, name, subscription, groups;
|
||||
|
||||
+ rosterItem
|
||||
{
|
||||
return [[[self alloc] init] autorelease];
|
||||
}
|
||||
|
||||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat: @"<XMPPRosterItem, JID=%@, name=%@, "
|
||||
@"subscription=%@, groups=%@>",
|
||||
JID, name, subscription, groups];
|
||||
}
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue