Skip to content

Commit c90e9b2

Browse files
committed
Several updates to PubSub module
1 parent 4fcc987 commit c90e9b2

File tree

7 files changed

+1214
-319
lines changed

7 files changed

+1214
-319
lines changed

Extensions/XEP-0060/XMPPIQ+XEP_0060.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#import <Foundation/Foundation.h>
2+
#import "XMPPIQ.h"
3+
4+
#define XMLNS_PUBSUB @"http://jabber.org/protocol/pubsub"
5+
#define XMLNS_PUBSUB_OWNER @"http://jabber.org/protocol/pubsub#owner"
6+
#define XMLNS_PUBSUB_EVENT @"http://jabber.org/protocol/pubsub#event"
7+
#define XMLNS_PUBSUB_NODE_CONFIG @"http://jabber.org/protocol/pubsub#node_config"
8+
#define XMLNS_PUBSUB_PUBLISH_OPTIONS @"http://jabber.org/protocol/pubsub#publish-options"
9+
#define XMLNS_PUBSUB_SUBSCRIBE_OPTIONS @"http://jabber.org/protocol/pubsub#subscribe_options"
10+
11+
@interface XMPPIQ (XEP_0060)
12+
13+
/**
14+
* Extracts the 'subid' from a PubSub subscription response.
15+
*
16+
* For example, if we sent a PubSub subscription request for node "princely_musings",
17+
* and the server returned this response:
18+
*
19+
* <iq type='result' from='pubsub.shakespeare.lit' to='francisco@denmark.lit/barracks' id='sub1'>
20+
* <pubsub xmlns='http://jabber.org/protocol/pubsub'>
21+
* <subscription
22+
* node='princely_musings'
23+
* jid='francisco@denmark.lit'
24+
* subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
25+
* subscription='subscribed'/>
26+
* </pubsub>
27+
* </iq>
28+
*
29+
* Then this method would return "ba49252aaa4f5d320c24d3766f0bdcade78c78d3".
30+
*
31+
* It is common to store the subid as it often a required attribute when unsubscribing.
32+
**/
33+
- (NSString *)pubsubid;
34+
35+
@end

Extensions/XEP-0060/XMPPIQ+XEP_0060.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#import "XMPPIQ+XEP_0060.h"
2+
#import "NSXMLElement+XMPP.h"
3+
4+
5+
@implementation XMPPIQ (XEP_0060)
6+
7+
- (NSString *)pubsubid
8+
{
9+
// <iq type='result' from='pubsub.shakespeare.lit' to='francisco@denmark.lit/barracks' id='sub1'>
10+
// <pubsub xmlns='http://jabber.org/protocol/pubsub'>
11+
// <subscription
12+
// node='princely_musings'
13+
// jid='francisco@denmark.lit'
14+
// subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
15+
// subscription='subscribed'/>
16+
// </pubsub>
17+
// </iq>
18+
19+
NSXMLElement *pubsub = [self elementForName:@"pubsub" xmlns:XMLNS_PUBSUB];
20+
NSXMLElement *subscription = [pubsub elementForName:@"subscription"];
21+
22+
return [subscription attributeStringValueForName:@"subid"];
23+
}
24+
25+
@end

0 commit comments

Comments
 (0)