Skip to content

Commit bd99f21

Browse files
author
Andres Canal
committed
instead of implementing the whole module just one category to provide the iq and the parsing
1 parent e0fe0e4 commit bd99f21

File tree

8 files changed

+137
-355
lines changed

8 files changed

+137
-355
lines changed

Extensions/XEP-0030/XMPPIQ+XEP_0030.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// XMPPIQ+XEP_0030.h
3+
// XMPPFramework
4+
//
5+
// Created by Andres on 7/07/16.
6+
// Copyright © 2016 Inaka. All rights reserved.
7+
//
8+
9+
#import <XMPPFramework/XMPPFramework.h>
10+
#import "XMPPFramework/XMPPJID.h"
11+
12+
@interface XMPPIQ (XEP_0030)
13+
14+
+ (nonnull XMPPIQ *) discoverItemsAssociatedWithJID:(nonnull XMPPJID *)jid;
15+
+ (nonnull NSArray <NSXMLElement *> *)parseDiscoveredItemsFromIQ:(nonnull XMPPIQ *)iq;
16+
17+
@end

Extensions/XEP-0030/XMPPIQ+XEP_0030.m

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// XMPPIQ+XEP_0030.m
3+
// XMPPFramework
4+
//
5+
// Created by Andres on 7/07/16.
6+
// Copyright © 2016 Inaka. All rights reserved.
7+
//
8+
9+
#import "XMPPIQ+XEP_0030.h"
10+
#import "NSXMLElement+XMPP.h"
11+
12+
#define XMLNS_DISCO_ITEMS @"http://jabber.org/protocol/disco#items"
13+
14+
@implementation XMPPIQ (XEP_0060)
15+
16+
+ (nonnull XMPPIQ *) discoverItemsAssociatedWithJID:(nonnull XMPPJID *)jid {
17+
18+
// <iq type='get'
19+
// from='romeo@montague.net/orchard'
20+
// to='shakespeare.lit'
21+
// id='items1'>
22+
// <query xmlns='http://jabber.org/protocol/disco#items'/> // disco#items
23+
// </iq>
24+
25+
NSString *iqID = [XMPPStream generateUUID];
26+
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns: XMLNS_DISCO_ITEMS];
27+
return [XMPPIQ iqWithType:@"get" to:jid elementID:iqID child:query];
28+
29+
}
30+
31+
+ (nonnull NSArray <NSXMLElement *> *)parseDiscoveredItemsFromIQ:(nonnull XMPPIQ *)iq {
32+
// <iq xmlns='jabber:client' from='shakespeare.lit'
33+
// to='@shakespeare.lit'
34+
// id='items1' type='result'>
35+
// <query xmlns='http://jabber.org/protocol/disco#items'>
36+
// <item jid='muc.erlang-solutions.com'/>
37+
// <item jid='muclight.erlang-solutions.com'/>
38+
// <item jid='pubsub.erlang-solutions.com'/>
39+
// <item jid='vjud.erlang-solutions.com'/>
40+
// </query>
41+
// </iq>
42+
43+
NSXMLElement *query = [iq elementForName:@"query" xmlns: XMLNS_DISCO_ITEMS];
44+
if(query) {
45+
return [query elementsForName:@"item"];
46+
}
47+
}
48+
49+
@end

Extensions/XEP-0030/XMPPServiceDiscovery.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

Extensions/XEP-0030/XMPPServiceDiscovery.m

Lines changed: 0 additions & 115 deletions
This file was deleted.

Xcode/Testing-pod/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,6 @@ SPEC CHECKSUMS:
192192
CocoaAsyncSocket: a18c75dca4b08723628a0bacca6e94803d90be91
193193
CocoaLumberjack: 97fab7ee5f507fe54445cca7ea80f926729cfd15
194194
KissXML: d19dd6dc65e0dc721ba92b3077b8ebdd240f1c1e
195-
XMPPFramework: 2e6b563c554f3a4c6565b33981c5b527b9c474c4
195+
XMPPFramework: 7fb5899e41c47a75cdf16be39b7079591738b14f
196196

197197
COCOAPODS: 0.39.0

Xcode/Testing-pod/XMPPFrameworkTests.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
63F50DA01C6020A100CA0201 /* XMPPURITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F50D9D1C6020A100CA0201 /* XMPPURITests.m */; };
1414
C11ABAB91D2C4035003F9FBF /* XMPPTBReconnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C11ABAB81D2C4035003F9FBF /* XMPPTBReconnectionTests.m */; };
1515
C12017BC1D2D72700054B254 /* XMPPTBRAuthenticationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C12017BB1D2D72700054B254 /* XMPPTBRAuthenticationTests.m */; };
16+
C12017BE1D2EC89A0054B254 /* XMPP0030Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = C12017BD1D2EC89A0054B254 /* XMPP0030Tests.m */; };
1617
C141EB1A1CF76CE900513A66 /* XMPPMockStream.m in Sources */ = {isa = PBXBuildFile; fileRef = C141EB191CF76CE900513A66 /* XMPPMockStream.m */; };
1718
C1EA90581CFDC2F50019BC16 /* XMPPRoomLightTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1EA90571CFDC2F50019BC16 /* XMPPRoomLightTests.m */; };
18-
C1FF91F61CF8906000C88DEA /* XMPPServiceDiscoveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1FF91F51CF8906000C88DEA /* XMPPServiceDiscoveryTests.m */; };
1919
D92C57A41CC2E0820032DE59 /* XMPPStorageHintTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D92C57A31CC2E0820032DE59 /* XMPPStorageHintTests.m */; };
2020
D9BA12A31D1B55C70095CFE4 /* XMPPvCardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D9BA12A21D1B55C70095CFE4 /* XMPPvCardTests.m */; };
2121
E09D4B441CFCC4A000D37596 /* XMPPMUCLightTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E09D4B431CFCC4A000D37596 /* XMPPMUCLightTests.m */; };
@@ -36,10 +36,10 @@
3636
B02E767684F690CBF1C43DDA /* Pods_XMPPFrameworkTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMPPFrameworkTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3737
C11ABAB81D2C4035003F9FBF /* XMPPTBReconnectionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPTBReconnectionTests.m; sourceTree = "<group>"; };
3838
C12017BB1D2D72700054B254 /* XMPPTBRAuthenticationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPTBRAuthenticationTests.m; sourceTree = "<group>"; };
39+
C12017BD1D2EC89A0054B254 /* XMPP0030Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPP0030Tests.m; sourceTree = "<group>"; };
3940
C141EB181CF76CE900513A66 /* XMPPMockStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPMockStream.h; sourceTree = "<group>"; };
4041
C141EB191CF76CE900513A66 /* XMPPMockStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPMockStream.m; sourceTree = "<group>"; };
4142
C1EA90571CFDC2F50019BC16 /* XMPPRoomLightTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPRoomLightTests.m; sourceTree = "<group>"; };
42-
C1FF91F51CF8906000C88DEA /* XMPPServiceDiscoveryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPServiceDiscoveryTests.m; sourceTree = "<group>"; };
4343
D92C57A31CC2E0820032DE59 /* XMPPStorageHintTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPStorageHintTests.m; sourceTree = "<group>"; };
4444
D9BA12A21D1B55C70095CFE4 /* XMPPvCardTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPvCardTests.m; sourceTree = "<group>"; };
4545
E09D4B431CFCC4A000D37596 /* XMPPMUCLightTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPMUCLightTests.m; sourceTree = "<group>"; };
@@ -101,7 +101,7 @@
101101
E0AD9A5A1D09BF0B0067F707 /* XMPPRoomLightCoreDataStorageTests.m */,
102102
C11ABAB81D2C4035003F9FBF /* XMPPTBReconnectionTests.m */,
103103
C12017BB1D2D72700054B254 /* XMPPTBRAuthenticationTests.m */,
104-
C1FF91F51CF8906000C88DEA /* XMPPServiceDiscoveryTests.m */,
104+
C12017BD1D2EC89A0054B254 /* XMPP0030Tests.m */,
105105
637AE2E81C6AC0D50051BF1F /* XMPPPushTests.swift */,
106106
63F50D971C60208200CA0201 /* Info.plist */,
107107
C141EB181CF76CE900513A66 /* XMPPMockStream.h */,
@@ -236,10 +236,10 @@
236236
isa = PBXSourcesBuildPhase;
237237
buildActionMask = 2147483647;
238238
files = (
239+
C12017BE1D2EC89A0054B254 /* XMPP0030Tests.m in Sources */,
239240
63F50D9E1C6020A100CA0201 /* CapabilitiesHashingTest.m in Sources */,
240241
E09D4B441CFCC4A000D37596 /* XMPPMUCLightTests.m in Sources */,
241242
63F50D9F1C6020A100CA0201 /* EncodeDecodeTest.m in Sources */,
242-
C1FF91F61CF8906000C88DEA /* XMPPServiceDiscoveryTests.m in Sources */,
243243
E0ED56D11CF34D28004C726B /* XMPPHTTPFileUploadTests.m in Sources */,
244244
E0ED56D61CF4D333004C726B /* XMPPMessageArchiveManagementTests.m in Sources */,
245245
C11ABAB91D2C4035003F9FBF /* XMPPTBReconnectionTests.m in Sources */,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// XMPP0030Tests.m
3+
// XMPPFrameworkTests
4+
//
5+
// Created by Andres Canal on 7/7/16.
6+
//
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "XMPPFramework/XMPPIQ+XEP_0030.h"
11+
12+
@interface XMPP0030Tests : XCTestCase
13+
14+
@end
15+
16+
@implementation XMPP0030Tests
17+
18+
- (void)testIQDiscoItem {
19+
20+
XMPPJID *jid = [XMPPJID jidWithString:@"test@server.com"];
21+
XMPPIQ *discoItemsIQ = [XMPPIQ discoverItemsAssociatedWithJID:jid];
22+
23+
NSXMLElement *queryElement = [discoItemsIQ elementForName:@"query"];
24+
XCTAssertEqualObjects(queryElement.xmlns, @"http://jabber.org/protocol/disco#items");
25+
26+
XCTAssertEqualObjects(discoItemsIQ.to, jid);
27+
XCTAssertEqualObjects(discoItemsIQ.type, @"get");
28+
}
29+
30+
- (void)testParsingDiscoItemsResponse {
31+
32+
// <iq xmlns='jabber:client' from='shakespeare.lit'
33+
// to='@shakespeare.lit'
34+
// id='items1' type='result'>
35+
// <query xmlns='http://jabber.org/protocol/disco#items'>
36+
// <item jid='muc.erlang-solutions.com'/>
37+
// <item jid='muclight.erlang-solutions.com'/>
38+
// <item jid='pubsub.erlang-solutions.com'/>
39+
// <item jid='vjud.erlang-solutions.com'/>
40+
// </query>
41+
// </iq>
42+
43+
NSMutableString *s = [NSMutableString string];
44+
[s appendString: @"<iq xmlns='jabber:client' from='shakespeare.lit'"];
45+
[s appendString: @" to='@shakespeare.lit'"];
46+
[s appendString: @" id='items1' type='result'>"];
47+
[s appendString: @" <query xmlns='http://jabber.org/protocol/disco#items'>"];
48+
[s appendString: @" <item jid='muc.erlang-solutions.com'/>"];
49+
[s appendString: @" <item jid='muclight.erlang-solutions.com'/>"];
50+
[s appendString: @" <item jid='pubsub.erlang-solutions.com'/>"];
51+
[s appendString: @" <item jid='vjud.erlang-solutions.com'/>"];
52+
[s appendString: @" </query>"];
53+
[s appendString: @"</iq>"];
54+
55+
NSError *error;
56+
NSXMLDocument *doc = [[NSXMLDocument alloc] initWithXMLString:s options:0 error:&error];
57+
XMPPIQ *iq = [XMPPIQ iqFromElement:[doc rootElement]];
58+
59+
NSArray *parsedItems = [XMPPIQ parseDiscoveredItemsFromIQ:iq];
60+
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[0]) attributeForName:@"jid"].stringValue, @"muc.erlang-solutions.com");
61+
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[1]) attributeForName:@"jid"].stringValue, @"muclight.erlang-solutions.com");
62+
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[2]) attributeForName:@"jid"].stringValue, @"pubsub.erlang-solutions.com");
63+
XCTAssertEqualObjects([((NSXMLElement *)parsedItems[3]) attributeForName:@"jid"].stringValue, @"vjud.erlang-solutions.com");
64+
}
65+
66+
@end

0 commit comments

Comments
 (0)