-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instead of implementing the whole module just one category to provide…
… the iq and the parsing
- Loading branch information
Andres Canal
committed
Jul 7, 2016
1 parent
492b900
commit ca5f449
Showing
8 changed files
with
137 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// XMPPIQ+XEP_0030.h | ||
// XMPPFramework | ||
// | ||
// Created by Andres on 7/07/16. | ||
// Copyright © 2016 Inaka. All rights reserved. | ||
// | ||
|
||
#import <XMPPFramework/XMPPFramework.h> | ||
#import "XMPPFramework/XMPPJID.h" | ||
|
||
@interface XMPPIQ (XEP_0030) | ||
|
||
+ (nonnull XMPPIQ *) discoverItemsAssociatedWithJID:(nonnull XMPPJID *)jid; | ||
+ (nonnull NSArray <NSXMLElement *> *)parseDiscoveredItemsFromIQ:(nonnull XMPPIQ *)iq; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// XMPPIQ+XEP_0030.m | ||
// XMPPFramework | ||
// | ||
// Created by Andres on 7/07/16. | ||
// Copyright © 2016 Inaka. All rights reserved. | ||
// | ||
|
||
#import "XMPPIQ+XEP_0030.h" | ||
#import "NSXMLElement+XMPP.h" | ||
|
||
#define XMLNS_DISCO_ITEMS @"http://jabber.org/protocol/disco#items" | ||
|
||
@implementation XMPPIQ (XEP_0060) | ||
|
||
+ (nonnull XMPPIQ *) discoverItemsAssociatedWithJID:(nonnull XMPPJID *)jid { | ||
|
||
// <iq type='get' | ||
// from='romeo@montague.net/orchard' | ||
// to='shakespeare.lit' | ||
// id='items1'> | ||
// <query xmlns='http://jabber.org/protocol/disco#items'/> // disco#items | ||
// </iq> | ||
|
||
NSString *iqID = [XMPPStream generateUUID]; | ||
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns: XMLNS_DISCO_ITEMS]; | ||
return [XMPPIQ iqWithType:@"get" to:jid elementID:iqID child:query]; | ||
|
||
} | ||
|
||
+ (nonnull NSArray <NSXMLElement *> *)parseDiscoveredItemsFromIQ:(nonnull XMPPIQ *)iq { | ||
// <iq xmlns='jabber:client' from='shakespeare.lit' | ||
// to='@shakespeare.lit' | ||
// id='items1' type='result'> | ||
// <query xmlns='http://jabber.org/protocol/disco#items'> | ||
// <item jid='muc.erlang-solutions.com'/> | ||
// <item jid='muclight.erlang-solutions.com'/> | ||
// <item jid='pubsub.erlang-solutions.com'/> | ||
// <item jid='vjud.erlang-solutions.com'/> | ||
// </query> | ||
// </iq> | ||
|
||
NSXMLElement *query = [iq elementForName:@"query" xmlns: XMLNS_DISCO_ITEMS]; | ||
if(query) { | ||
return [query elementsForName:@"item"]; | ||
} | ||
} | ||
|
||
@end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// XMPP0030Tests.m | ||
// XMPPFrameworkTests | ||
// | ||
// Created by Andres Canal on 7/7/16. | ||
// | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "XMPPFramework/XMPPIQ+XEP_0030.h" | ||
|
||
@interface XMPP0030Tests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation XMPP0030Tests | ||
|
||
- (void)testIQDiscoItem { | ||
|
||
XMPPJID *jid = [XMPPJID jidWithString:@"test@server.com"]; | ||
XMPPIQ *discoItemsIQ = [XMPPIQ discoverItemsAssociatedWithJID:jid]; | ||
|
||
NSXMLElement *queryElement = [discoItemsIQ elementForName:@"query"]; | ||
XCTAssertEqualObjects(queryElement.xmlns, @"http://jabber.org/protocol/disco#items"); | ||
|
||
XCTAssertEqualObjects(discoItemsIQ.to, jid); | ||
XCTAssertEqualObjects(discoItemsIQ.type, @"get"); | ||
} | ||
|
||
- (void)testParsingDiscoItemsResponse { | ||
|
||
// <iq xmlns='jabber:client' from='shakespeare.lit' | ||
// to='@shakespeare.lit' | ||
// id='items1' type='result'> | ||
// <query xmlns='http://jabber.org/protocol/disco#items'> | ||
// <item jid='muc.erlang-solutions.com'/> | ||
// <item jid='muclight.erlang-solutions.com'/> | ||
// <item jid='pubsub.erlang-solutions.com'/> | ||
// <item jid='vjud.erlang-solutions.com'/> | ||
// </query> | ||
// </iq> | ||
|
||
NSMutableString *s = [NSMutableString string]; | ||
[s appendString: @"<iq xmlns='jabber:client' from='shakespeare.lit'"]; | ||
[s appendString: @" to='@shakespeare.lit'"]; | ||
[s appendString: @" id='items1' type='result'>"]; | ||
[s appendString: @" <query xmlns='http://jabber.org/protocol/disco#items'>"]; | ||
[s appendString: @" <item jid='muc.erlang-solutions.com'/>"]; | ||
[s appendString: @" <item jid='muclight.erlang-solutions.com'/>"]; | ||
[s appendString: @" <item jid='pubsub.erlang-solutions.com'/>"]; | ||
[s appendString: @" <item jid='vjud.erlang-solutions.com'/>"]; | ||
[s appendString: @" </query>"]; | ||
[s appendString: @"</iq>"]; | ||
|
||
NSError *error; | ||
NSXMLDocument *doc = [[NSXMLDocument alloc] initWithXMLString:s options:0 error:&error]; | ||
XMPPIQ *iq = [XMPPIQ iqFromElement:[doc rootElement]]; | ||
|
||
NSArray *parsedItems = [XMPPIQ parseDiscoveredItemsFromIQ:iq]; | ||
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[0]) attributeForName:@"jid"].stringValue, @"muc.erlang-solutions.com"); | ||
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[1]) attributeForName:@"jid"].stringValue, @"muclight.erlang-solutions.com"); | ||
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[2]) attributeForName:@"jid"].stringValue, @"pubsub.erlang-solutions.com"); | ||
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[3]) attributeForName:@"jid"].stringValue, @"vjud.erlang-solutions.com"); | ||
} | ||
|
||
@end |
Oops, something went wrong.