Skip to content

Commit 2f1b265

Browse files
committed
Added XEP-0357
1 parent 0b373ed commit 2f1b265

File tree

7 files changed

+222
-7
lines changed

7 files changed

+222
-7
lines changed

Extensions/XEP-0357/XMPPIQ+XEP_0357.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// NSXMLElement+NSXMLElement_XEP_0357.h
3+
//
4+
// Created by David Chiles on 2/9/16.
5+
//
6+
//
7+
8+
#import "XMPPIQ.h"
9+
@class XMPPJID;
10+
11+
/**
12+
XMPPIQ (XEP0357) is a class extension on XMPPIQ for creating the elements for XEP-0357 http://xmpp.org/extensions/xep-0357.html
13+
*/
14+
extern NSString * __nonnull const XMPPPushXMLNS;
15+
16+
@interface XMPPIQ (XEP0357)
17+
18+
/**
19+
Creates an IQ stanza for enabling push notificiations. http://xmpp.org/extensions/xep-0357.html#enabling
20+
21+
@param jid The jid of the XMPP Push Service
22+
@param node Optional node of the XMPP Push Service
23+
@param options Optional values to passed to your XMPP service (this is likely some sort of secret or token to validate this user/device with teh app server)
24+
@return An IQ stanza
25+
*/
26+
+ (nonnull instancetype)enableNotificationsElementWithJID:(nonnull XMPPJID *)jid node:(nullable NSString *)node options:(nullable NSDictionary <NSString *,NSString *>*)options;
27+
28+
/**
29+
Creates an IQ stanza for disable push notifications. http://xmpp.org/extensions/xep-0357.html#disabling
30+
31+
@param jid the jid of the XMPP Push Service
32+
@param node the node of the XMPP push Service
33+
@return an IQ Stanza
34+
*/
35+
+ (nonnull instancetype)disableNotificationsElementWithJID:(nonnull XMPPJID *)jid node:(nullable NSString *)node;
36+
37+
@end

Extensions/XEP-0357/XMPPIQ+XEP_0357.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// NSXMLElement+NSXMLElement_XEP_0357.m
3+
// Pods
4+
//
5+
// Created by David Chiles on 2/9/16.
6+
//
7+
//
8+
9+
#import "XMPPIQ+XEP_0357.h"
10+
#import "XMPPJID.h"
11+
12+
NSString *const XMPPPushXMLNS = @"urn:xmpp:push:0";
13+
14+
@implementation XMPPIQ (XEP0357)
15+
16+
+ (instancetype)enableNotificationsElementWithJID:(XMPPJID *)jid node:(NSString *)node options:(nullable NSDictionary<NSString *,NSString *> *)options
17+
{
18+
NSXMLElement *enableElement = [self elementWithName:@"enable" xmlns:XMPPPushXMLNS];
19+
[enableElement addAttributeWithName:@"jid" stringValue:[jid full]];
20+
if ([node length]) {
21+
[enableElement addAttributeWithName:@"node" stringValue:node];
22+
}
23+
24+
if ([options count]) {
25+
NSXMLElement *dataForm = [self elementWithName:@"x" xmlns:@"jabber:x:data"];
26+
NSXMLElement *formTypeField = [NSXMLElement elementWithName:@"field"];
27+
[formTypeField addAttributeWithName:@"var" stringValue:@"FORM_TYPE"];
28+
[formTypeField addChild:[NSXMLElement elementWithName:@"value" stringValue:@"http://jabber.org/protocol/pubsub#publish-options"]];
29+
[dataForm addChild:formTypeField];
30+
31+
[options enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
32+
NSXMLElement *formField = [NSXMLElement elementWithName:@"field"];
33+
[formField addAttributeWithName:@"var" stringValue:key];
34+
[formField addChild:[NSXMLElement elementWithName:@"value" stringValue:obj]];
35+
[dataForm addChild:formField];
36+
}];
37+
[enableElement addChild:dataForm];
38+
}
39+
40+
return [self iqWithType:@"set" child:enableElement];
41+
42+
}
43+
44+
+ (instancetype)disableNotificationsElementWithJID:(XMPPJID *)jid node:(NSString *)node
45+
{
46+
NSXMLElement *disableElement = [self elementWithName:@"disable" xmlns:XMPPPushXMLNS];
47+
[disableElement addAttributeWithName:@"jid" stringValue:[jid full]];
48+
if ([node length]) {
49+
[disableElement addAttributeWithName:@"node" stringValue:node];
50+
}
51+
return [self iqWithType:@"set" child:disableElement];
52+
}
53+
54+
@end

XMPPFramework.podspec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ s.subspec 'XEP-0352' do |ss|
323323
ss.prefix_header_contents = "#define HAVE_XMPP_SUBSPEC_#{name.upcase.sub('-', '_')}"
324324
end
325325

326+
s.subspec 'XEP-0357' do |ss|
327+
ss.source_files = 'Extensions/XEP-0357/*.{h,m}'
328+
ss.dependency 'XMPPFramework/Core'
329+
ss.prefix_header_contents = "#define HAVE_XMPP_SUBSPEC_#{name.upcase.sub('-', '_')}"
330+
end
331+
326332
s.subspec 'All' do |ss|
327333
ss.dependency 'XMPPFramework/Core'
328334
ss.dependency 'XMPPFramework/BandwidthMonitor'
@@ -367,6 +373,7 @@ s.subspec 'All' do |ss|
367373
ss.dependency 'XMPPFramework/XEP-0333'
368374
ss.dependency 'XMPPFramework/XEP-0335'
369375
ss.dependency 'XMPPFramework/XEP-0352'
376+
ss.dependency 'XMPPFramework/XEP-0357'
370377

371378
end
372379
end

Xcode/Testing-pod/Podfile.lock

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
PODS:
22
- CocoaAsyncSocket (7.4.2)
3-
- CocoaLumberjack (1.9.2):
4-
- CocoaLumberjack/Extensions (= 1.9.2)
5-
- CocoaLumberjack/Core (1.9.2)
6-
- CocoaLumberjack/Extensions (1.9.2):
3+
- CocoaLumberjack (2.2.0):
4+
- CocoaLumberjack/Default (= 2.2.0)
5+
- CocoaLumberjack/Extensions (= 2.2.0)
6+
- CocoaLumberjack/Core (2.2.0)
7+
- CocoaLumberjack/Default (2.2.0):
78
- CocoaLumberjack/Core
9+
- CocoaLumberjack/Extensions (2.2.0):
10+
- CocoaLumberjack/Default
811
- KissXML/Core (5.0.3)
912
- KissXML/libxml_module (5.0.3):
1013
- KissXML/Core
@@ -53,11 +56,12 @@ PODS:
5356
- XMPPFramework/XEP-0333
5457
- XMPPFramework/XEP-0335
5558
- XMPPFramework/XEP-0352
59+
- XMPPFramework/XEP-0357
5660
- XMPPFramework/BandwidthMonitor (3.6.7):
5761
- XMPPFramework/Core
5862
- XMPPFramework/Core (3.6.7):
5963
- CocoaAsyncSocket (~> 7.4.1)
60-
- CocoaLumberjack (~> 1.9)
64+
- CocoaLumberjack (~> 2.0)
6165
- KissXML/libxml_module (~> 5.0.3)
6266
- XMPPFramework/CoreDataStorage (3.6.7):
6367
- XMPPFramework/Core
@@ -150,6 +154,8 @@ PODS:
150154
- XMPPFramework/Core
151155
- XMPPFramework/XEP-0352 (3.6.7):
152156
- XMPPFramework/Core
157+
- XMPPFramework/XEP-0357 (3.6.7):
158+
- XMPPFramework/Core
153159

154160
DEPENDENCIES:
155161
- XMPPFramework (from `../../`)
@@ -160,8 +166,8 @@ EXTERNAL SOURCES:
160166

161167
SPEC CHECKSUMS:
162168
CocoaAsyncSocket: f5783bdedd232d91b89769bc4b5a1580aed518ad
163-
CocoaLumberjack: 628fca2e88ef06f7cf6817309aa405f325d9a6fa
169+
CocoaLumberjack: 17fe8581f84914d5d7e6360f7c70022b173c3ae0
164170
KissXML: d19dd6dc65e0dc721ba92b3077b8ebdd240f1c1e
165-
XMPPFramework: b8f741bfd26268113a3f6b39b5c9dbd93a68944a
171+
XMPPFramework: 53da6a70a6aa55aaaa47009b2b11ef975e3a0556
166172

167173
COCOAPODS: 0.39.0

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
637AE2E91C6AC0D50051BF1F /* XMPPPushTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637AE2E81C6AC0D50051BF1F /* XMPPPushTests.swift */; };
1011
63F50D9E1C6020A100CA0201 /* CapabilitiesHashingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F50D9B1C6020A100CA0201 /* CapabilitiesHashingTest.m */; };
1112
63F50D9F1C6020A100CA0201 /* EncodeDecodeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F50D9C1C6020A100CA0201 /* EncodeDecodeTest.m */; };
1213
63F50DA01C6020A100CA0201 /* XMPPURITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F50D9D1C6020A100CA0201 /* XMPPURITests.m */; };
@@ -15,6 +16,7 @@
1516

1617
/* Begin PBXFileReference section */
1718
16B6474F735EF4CB50F33A27 /* Pods-XMPPFrameworkTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMPPFrameworkTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-XMPPFrameworkTests/Pods-XMPPFrameworkTests.debug.xcconfig"; sourceTree = "<group>"; };
19+
637AE2E81C6AC0D50051BF1F /* XMPPPushTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XMPPPushTests.swift; sourceTree = "<group>"; };
1820
63F50D921C60208200CA0201 /* XMPPFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XMPPFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1921
63F50D971C60208200CA0201 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2022
63F50D9B1C6020A100CA0201 /* CapabilitiesHashingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CapabilitiesHashingTest.m; sourceTree = "<group>"; };
@@ -67,6 +69,7 @@
6769
63F50D9B1C6020A100CA0201 /* CapabilitiesHashingTest.m */,
6870
63F50D9C1C6020A100CA0201 /* EncodeDecodeTest.m */,
6971
63F50D9D1C6020A100CA0201 /* XMPPURITests.m */,
72+
637AE2E81C6AC0D50051BF1F /* XMPPPushTests.swift */,
7073
63F50D971C60208200CA0201 /* Info.plist */,
7174
);
7275
path = XMPPFrameworkTests;
@@ -200,6 +203,7 @@
200203
files = (
201204
63F50D9E1C6020A100CA0201 /* CapabilitiesHashingTest.m in Sources */,
202205
63F50D9F1C6020A100CA0201 /* EncodeDecodeTest.m in Sources */,
206+
637AE2E91C6AC0D50051BF1F /* XMPPPushTests.swift in Sources */,
203207
63F50DA01C6020A100CA0201 /* XMPPURITests.m in Sources */,
204208
);
205209
runOnlyForDeploymentPostprocessing = 0;
@@ -252,6 +256,7 @@
252256
PRODUCT_BUNDLE_IDENTIFIER = com.davidchiles.XMPPFrameworkTests;
253257
PRODUCT_NAME = "$(TARGET_NAME)";
254258
SDKROOT = iphoneos;
259+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
255260
};
256261
name = Debug;
257262
};

Xcode/Testing-pod/XMPPFrameworkTests.xcodeproj/xcshareddata/xcschemes/XMPPFrameworkTests.xcscheme

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "NO"
13+
buildForArchiving = "NO"
14+
buildForAnalyzing = "NO">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "63F50D911C60208100CA0201"
18+
BuildableName = "XMPPFrameworkTests.xctest"
19+
BlueprintName = "XMPPFrameworkTests"
20+
ReferencedContainer = "container:XMPPFrameworkTests.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
824
</BuildAction>
925
<TestAction
1026
buildConfiguration = "Debug"
@@ -36,6 +52,15 @@
3652
debugDocumentVersioning = "YES"
3753
debugServiceExtension = "internal"
3854
allowLocationSimulation = "YES">
55+
<MacroExpansion>
56+
<BuildableReference
57+
BuildableIdentifier = "primary"
58+
BlueprintIdentifier = "63F50D911C60208100CA0201"
59+
BuildableName = "XMPPFrameworkTests.xctest"
60+
BlueprintName = "XMPPFrameworkTests"
61+
ReferencedContainer = "container:XMPPFrameworkTests.xcodeproj">
62+
</BuildableReference>
63+
</MacroExpansion>
3964
<AdditionalOptions>
4065
</AdditionalOptions>
4166
</LaunchAction>
@@ -45,6 +70,15 @@
4570
savedToolIdentifier = ""
4671
useCustomWorkingDirectory = "NO"
4772
debugDocumentVersioning = "YES">
73+
<MacroExpansion>
74+
<BuildableReference
75+
BuildableIdentifier = "primary"
76+
BlueprintIdentifier = "63F50D911C60208100CA0201"
77+
BuildableName = "XMPPFrameworkTests.xctest"
78+
BlueprintName = "XMPPFrameworkTests"
79+
ReferencedContainer = "container:XMPPFrameworkTests.xcodeproj">
80+
</BuildableReference>
81+
</MacroExpansion>
4882
</ProfileAction>
4983
<AnalyzeAction
5084
buildConfiguration = "Debug">
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// XMPPPushTests.swift
3+
// XMPPFrameworkTests
4+
//
5+
// Created by David Chiles on 2/9/16.
6+
//
7+
//
8+
import XMPPFramework
9+
10+
import XCTest
11+
12+
class XMPPPushTests: XCTestCase {
13+
14+
override func setUp() {
15+
super.setUp()
16+
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
}
18+
19+
override func tearDown() {
20+
// Put teardown code here. This method is called after the invocation of each test method in the class.
21+
super.tearDown()
22+
}
23+
24+
func testEnableStanzaWithoutOptions() {
25+
26+
let jid = XMPPJID.jidWithString("push-5.client.example")
27+
let node = "yxs32uqsflafdk3iuqo"
28+
let enableStanza = XMPPIQ.enableNotificationsElementWithJID(jid, node: node, options: nil)
29+
XCTAssertNotNil(enableStanza,"No Stanza")
30+
31+
/**
32+
<iq type="set">
33+
<enable xmlns="urn:xmpp:push:0" jid="push-5.client.example" node="yxs32uqsflafdk3iuqo"></enable>
34+
</iq>
35+
*/
36+
XCTAssertTrue(enableStanza.XMLString() == "<iq type=\"set\"><enable xmlns=\"urn:xmpp:push:0\" jid=\"push-5.client.example\" node=\"yxs32uqsflafdk3iuqo\"></enable></iq>","XML does not match \(enableStanza.XMLString())")
37+
}
38+
39+
func testEnableStanzaWithOptions() {
40+
let jid = XMPPJID.jidWithString("push-5.client.example")
41+
let node = "yxs32uqsflafdk3iuqo"
42+
let options = ["secret":"eruio234vzxc2kla-91"]
43+
let enableStanza = XMPPIQ.enableNotificationsElementWithJID(jid, node: node, options: options)
44+
XCTAssertNotNil(enableStanza,"No Stanza")
45+
46+
/**
47+
<iq type="set">
48+
<enable xmlns="urn:xmpp:push:0" jid="push-5.client.example" node="yxs32uqsflafdk3iuqo">
49+
<x xmlns="jabber:x:data">
50+
<field var="FORM_TYPE"><value>http://jabber.org/protocol/pubsub#publish-options</value></field>
51+
<field var="secret"><value>eruio234vzxc2kla-91</value></field>
52+
</x>
53+
</enable>
54+
</iq>
55+
*/
56+
XCTAssertTrue(enableStanza.XMLString() == "<iq type=\"set\"><enable xmlns=\"urn:xmpp:push:0\" jid=\"push-5.client.example\" node=\"yxs32uqsflafdk3iuqo\"><x xmlns=\"jabber:x:data\"><field var=\"FORM_TYPE\"><value>http://jabber.org/protocol/pubsub#publish-options</value></field><field var=\"secret\"><value>eruio234vzxc2kla-91</value></field></x></enable></iq>","XML does not match \(enableStanza.XMLString())")
57+
}
58+
59+
func testDisableStanza() {
60+
let jid = XMPPJID.jidWithString("push-5.client.example")
61+
let node = "yxs32uqsflafdk3iuqo"
62+
let disableStanza = XMPPIQ.disableNotificationsElementWithJID(jid, node: node)
63+
XCTAssertNotNil(disableStanza)
64+
print("\(disableStanza.XMLString())")
65+
/**
66+
<iq type="set">
67+
<disable xmlns="urn:xmpp:push:0" jid="push-5.client.example" node="yxs32uqsflafdk3iuqo"></disable>
68+
</iq>
69+
*/
70+
XCTAssertTrue(disableStanza.XMLString() == "<iq type=\"set\"><disable xmlns=\"urn:xmpp:push:0\" jid=\"push-5.client.example\" node=\"yxs32uqsflafdk3iuqo\"></disable></iq>","XML does not match \(disableStanza.XMLString())")
71+
}
72+
}

0 commit comments

Comments
 (0)