Skip to content

Commit

Permalink
instead of implementing the whole module just one category to provide…
Browse files Browse the repository at this point in the history
… the iq and the parsing
  • Loading branch information
Andres Canal committed Jul 7, 2016
1 parent e0fe0e4 commit bd99f21
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 355 deletions.
17 changes: 17 additions & 0 deletions Extensions/XEP-0030/XMPPIQ+XEP_0030.h
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
49 changes: 49 additions & 0 deletions Extensions/XEP-0030/XMPPIQ+XEP_0030.m
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='[email protected]/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
31 changes: 0 additions & 31 deletions Extensions/XEP-0030/XMPPServiceDiscovery.h

This file was deleted.

115 changes: 0 additions & 115 deletions Extensions/XEP-0030/XMPPServiceDiscovery.m

This file was deleted.

2 changes: 1 addition & 1 deletion Xcode/Testing-pod/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ SPEC CHECKSUMS:
CocoaAsyncSocket: a18c75dca4b08723628a0bacca6e94803d90be91
CocoaLumberjack: 97fab7ee5f507fe54445cca7ea80f926729cfd15
KissXML: d19dd6dc65e0dc721ba92b3077b8ebdd240f1c1e
XMPPFramework: 2e6b563c554f3a4c6565b33981c5b527b9c474c4
XMPPFramework: 7fb5899e41c47a75cdf16be39b7079591738b14f

COCOAPODS: 0.39.0
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
63F50DA01C6020A100CA0201 /* XMPPURITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F50D9D1C6020A100CA0201 /* XMPPURITests.m */; };
C11ABAB91D2C4035003F9FBF /* XMPPTBReconnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C11ABAB81D2C4035003F9FBF /* XMPPTBReconnectionTests.m */; };
C12017BC1D2D72700054B254 /* XMPPTBRAuthenticationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C12017BB1D2D72700054B254 /* XMPPTBRAuthenticationTests.m */; };
C12017BE1D2EC89A0054B254 /* XMPP0030Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = C12017BD1D2EC89A0054B254 /* XMPP0030Tests.m */; };
C141EB1A1CF76CE900513A66 /* XMPPMockStream.m in Sources */ = {isa = PBXBuildFile; fileRef = C141EB191CF76CE900513A66 /* XMPPMockStream.m */; };
C1EA90581CFDC2F50019BC16 /* XMPPRoomLightTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1EA90571CFDC2F50019BC16 /* XMPPRoomLightTests.m */; };
C1FF91F61CF8906000C88DEA /* XMPPServiceDiscoveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1FF91F51CF8906000C88DEA /* XMPPServiceDiscoveryTests.m */; };
D92C57A41CC2E0820032DE59 /* XMPPStorageHintTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D92C57A31CC2E0820032DE59 /* XMPPStorageHintTests.m */; };
D9BA12A31D1B55C70095CFE4 /* XMPPvCardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D9BA12A21D1B55C70095CFE4 /* XMPPvCardTests.m */; };
E09D4B441CFCC4A000D37596 /* XMPPMUCLightTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E09D4B431CFCC4A000D37596 /* XMPPMUCLightTests.m */; };
Expand All @@ -36,10 +36,10 @@
B02E767684F690CBF1C43DDA /* Pods_XMPPFrameworkTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMPPFrameworkTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C11ABAB81D2C4035003F9FBF /* XMPPTBReconnectionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPTBReconnectionTests.m; sourceTree = "<group>"; };
C12017BB1D2D72700054B254 /* XMPPTBRAuthenticationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPTBRAuthenticationTests.m; sourceTree = "<group>"; };
C12017BD1D2EC89A0054B254 /* XMPP0030Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPP0030Tests.m; sourceTree = "<group>"; };
C141EB181CF76CE900513A66 /* XMPPMockStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPMockStream.h; sourceTree = "<group>"; };
C141EB191CF76CE900513A66 /* XMPPMockStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPMockStream.m; sourceTree = "<group>"; };
C1EA90571CFDC2F50019BC16 /* XMPPRoomLightTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPRoomLightTests.m; sourceTree = "<group>"; };
C1FF91F51CF8906000C88DEA /* XMPPServiceDiscoveryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPServiceDiscoveryTests.m; sourceTree = "<group>"; };
D92C57A31CC2E0820032DE59 /* XMPPStorageHintTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPStorageHintTests.m; sourceTree = "<group>"; };
D9BA12A21D1B55C70095CFE4 /* XMPPvCardTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPvCardTests.m; sourceTree = "<group>"; };
E09D4B431CFCC4A000D37596 /* XMPPMUCLightTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPMUCLightTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -101,7 +101,7 @@
E0AD9A5A1D09BF0B0067F707 /* XMPPRoomLightCoreDataStorageTests.m */,
C11ABAB81D2C4035003F9FBF /* XMPPTBReconnectionTests.m */,
C12017BB1D2D72700054B254 /* XMPPTBRAuthenticationTests.m */,
C1FF91F51CF8906000C88DEA /* XMPPServiceDiscoveryTests.m */,
C12017BD1D2EC89A0054B254 /* XMPP0030Tests.m */,
637AE2E81C6AC0D50051BF1F /* XMPPPushTests.swift */,
63F50D971C60208200CA0201 /* Info.plist */,
C141EB181CF76CE900513A66 /* XMPPMockStream.h */,
Expand Down Expand Up @@ -236,10 +236,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C12017BE1D2EC89A0054B254 /* XMPP0030Tests.m in Sources */,
63F50D9E1C6020A100CA0201 /* CapabilitiesHashingTest.m in Sources */,
E09D4B441CFCC4A000D37596 /* XMPPMUCLightTests.m in Sources */,
63F50D9F1C6020A100CA0201 /* EncodeDecodeTest.m in Sources */,
C1FF91F61CF8906000C88DEA /* XMPPServiceDiscoveryTests.m in Sources */,
E0ED56D11CF34D28004C726B /* XMPPHTTPFileUploadTests.m in Sources */,
E0ED56D61CF4D333004C726B /* XMPPMessageArchiveManagementTests.m in Sources */,
C11ABAB91D2C4035003F9FBF /* XMPPTBReconnectionTests.m in Sources */,
Expand Down
66 changes: 66 additions & 0 deletions Xcode/Testing-pod/XMPPFrameworkTests/XMPP0030Tests.m
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:@"[email protected]"];
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
Loading

0 comments on commit bd99f21

Please sign in to comment.