Skip to content

Commit

Permalink
Added publish function to PubSub XEP-0060
Browse files Browse the repository at this point in the history
  • Loading branch information
bnadim committed Mar 19, 2012
1 parent 4421f3a commit 0c88f07
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Extensions/XEP-0060/XMPPPubSub.h
Expand Up @@ -2,15 +2,21 @@
// XMPPPubSub.h
//
// Created by Duncan Robertson [duncan@whomwah.com]
// Updated by Nadim for Novedia Group - Hubiquitus project[hubiquitus.com]
//

#import <Foundation/Foundation.h>
#import "XMPPModule.h"

#if TARGET_OS_IPHONE
#import "DDXML.h"
#endif

@class XMPPStream;
@class XMPPJID;
@class XMPPIQ;
@class XMPPMessage;
@class XMPPItem;

@interface XMPPPubSub : XMPPModule
{
Expand All @@ -28,6 +34,8 @@
- (NSString *)deleteNode:(NSString *)node;
- (NSString *)configureNode:(NSString *)node;
- (NSString *)allItemsForNode:(NSString *)node;
- (NSString *)publishToNode:(NSString*)node entry:(NSXMLElement*)entry;


@end

Expand All @@ -39,5 +47,6 @@
- (void)xmppPubSub:(XMPPPubSub *)sender didReceiveMessage:(XMPPMessage *)message;
- (void)xmppPubSub:(XMPPPubSub *)sender didReceiveError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didReceiveResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didPublish:(XMPPIQ *)iq;

@end
51 changes: 50 additions & 1 deletion Extensions/XEP-0060/XMPPPubSub.m
Expand Up @@ -102,7 +102,17 @@ - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
return YES;
}
}
}
} else {
//Check if it was a publish
NSString *elementID = [iq attributeStringValueForName:@"id"];
if (elementID) {
NSArray * elementIDComp = [elementID componentsSeparatedByString:@":"];
if (elementIDComp > 0 && [[elementIDComp objectAtIndex:1] isEqualToString:@"publish_node"]) {
[multicastDelegate xmppPubSub:self didPublish:iq];
return YES;
}
}
}

[multicastDelegate xmppPubSub:self didReceiveResult:iq];
return YES;
Expand Down Expand Up @@ -365,4 +375,43 @@ - (NSString*)configureNode:(NSString*)node
return sid;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - publication methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (NSString *)publishToNode:(NSString *)node entry:(NSXMLElement *)entry {
//<iq type='set' from='hamlet@denmark.lit/blogbot' to='pubsub.shakespeare.lit' id='publish1'>
// <pubsub xmlns='http://jabber.org/protocol/pubsub'>
// <publish node='princely_musings'>
// <item id='bnd81g37d61f49fgn581'>
// Some content
// </item>
// </publish>
// </pubsub>
//</iq>

NSString *sid = [NSString stringWithFormat:@"%@:publish_node", xmppStream.generateUUID];

//create iq message
XMPPIQ *iq = [XMPPIQ iqWithType:@"set" to:serviceJID elementID:sid];

//create child nodes
NSXMLElement * pubsub = [NSXMLElement elementWithName:@"pubsub" xmlns:NS_PUBSUB];

NSXMLElement * publish = [NSXMLElement elementWithName:@"publish"];
[publish addAttributeWithName:@"node" stringValue:node];

NSXMLElement * item = [NSXMLElement elementWithName:@"item"];

//create node hierarchy
[item addChild:entry];
[publish addChild:item];
[pubsub addChild:publish];
[iq addChild:pubsub];

[xmppStream sendElement:iq];

return sid;
}

@end

0 comments on commit 0c88f07

Please sign in to comment.