-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for XEP-0030 with tests #736
Open
andresinaka
wants to merge
2
commits into
robbiehanson:master
Choose a base branch
from
esl:andres.XEP-0030ServiceDiscovery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// 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 XMPPIQ *) discoverInfoAssociatedWithJID:(nonnull XMPPJID *)jid; | ||
+ (nullable NSArray <NSXMLElement *> *)parseDiscoveredItemsFromIQ:(nonnull XMPPIQ *)iq; | ||
+ (nullable NSArray <NSXMLElement *> *)parseDiscoveredInfoFromIQ:(nonnull XMPPIQ *)iq; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// 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" | ||
#import "XMPPConstants.h" | ||
|
||
@implementation XMPPIQ (XEP_0060) | ||
|
||
+ (nonnull XMPPIQ *) discoverItemsAssociatedWithJID:(nonnull XMPPJID *)jid { | ||
|
||
// <iq type='get' | ||
// from='romeo@montague.net/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: XMPPDiscoItemsNamespace]; | ||
return [XMPPIQ iqWithType:@"get" to:jid elementID:iqID child:query]; | ||
|
||
} | ||
|
||
+ (nonnull XMPPIQ *) discoverInfoAssociatedWithJID:(nonnull XMPPJID *)jid { | ||
|
||
// <iq type='get' | ||
// from='romeo@montague.net/orchard' | ||
// to='shakespeare.lit' | ||
// id='items1'> | ||
// <query xmlns='http://jabber.org/protocol/disco#info'/> // disco#info | ||
// </iq> | ||
|
||
NSString *iqID = [XMPPStream generateUUID]; | ||
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns: XMPPDiscoInfoNamespace]; | ||
return [XMPPIQ iqWithType:@"get" to:jid elementID:iqID child:query]; | ||
|
||
} | ||
|
||
+ (nullable NSArray <NSXMLElement *> *)parseDiscoveredItemsFromIQ:(nonnull XMPPIQ *)iq { | ||
// <iq xmlns='jabber:client' from='shakespeare.lit' | ||
// to='test@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: XMPPDiscoItemsNamespace]; | ||
if(query) { | ||
return [query elementsForName:@"item"]; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
+ (nullable NSArray <NSXMLElement *> *)parseDiscoveredInfoFromIQ:(nonnull XMPPIQ *)iq { | ||
// <iq xmlns='jabber:client' from='shakespeare.lit' | ||
// to='test@shakespeare.lit' | ||
// id='items1' type='result'> | ||
// <query xmlns='http://jabber.org/protocol/disco#info'> | ||
// <identity category='pubsub' type='pep'/> | ||
// <identity category='server' type='im' name='ejabberd'/> | ||
// <feature var='erlang-solutions.com:xmpp:token-auth:0'/> | ||
// <feature var='http://jabber.org/protocol/disco#info'/> | ||
// <feature var='http://jabber.org/protocol/disco#items'/> | ||
// <feature var='http://jabber.org/protocol/pubsub'/> | ||
// <feature var='urn:xmpp:mam:0'/> | ||
// <feature var='urn:xmpp:mam:1'/> | ||
// </query> | ||
// </iq> | ||
|
||
NSXMLElement *query = [iq elementForName:@"query" xmlns: XMPPDiscoInfoNamespace]; | ||
if(query) { | ||
return [query children] ? [query children] : ((NSArray <NSXMLElement *> *)[[NSArray alloc] init]); | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// XMPPServiceDiscovery.h | ||
// Mangosta | ||
// | ||
// Created by Andres Canal on 4/27/16. | ||
// Copyright © 2016 Inaka. All rights reserved. | ||
// | ||
|
||
#import <XMPPFramework/XMPPFramework.h> | ||
|
||
@class XMPPIDTracker; | ||
|
||
@interface XMPPServiceDiscovery : XMPPModule { | ||
XMPPIDTracker *xmppIDTracker; | ||
} | ||
|
||
- (void)discoverInformationAboutJID:(nonnull XMPPJID *)jid; | ||
- (void)discoverItemsAssociatedWithJID:(nonnull XMPPJID *)jid; | ||
|
||
@end | ||
|
||
@protocol XMPPServiceDiscoveryDelegate | ||
|
||
@optional | ||
|
||
- (void)xmppServiceDiscovery:(nonnull XMPPServiceDiscovery *)sender didDiscoverInformation:(nonnull NSArray<NSXMLElement *> *)items; | ||
- (void)xmppServiceDiscovery:(nonnull XMPPServiceDiscovery *)sender didDiscoverItems:(nonnull NSArray <NSXMLElement *>*)items; | ||
|
||
- (void)xmppServiceDiscovery:(nonnull XMPPServiceDiscovery *)sender didFailToDiscover:(nonnull XMPPIQ *)iq; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// XMPPServiceDiscovery.m | ||
// Mangosta | ||
// | ||
// Created by Andres Canal on 4/27/16. | ||
// Copyright © 2016 Inaka. All rights reserved. | ||
// | ||
|
||
#import "XMPPServiceDiscovery.h" | ||
#import "XMPPIQ+XEP_0030.h" | ||
#import "XMPPIDTracker.h" | ||
#import "XMPPConstants.h" | ||
|
||
@implementation XMPPServiceDiscovery | ||
|
||
- (BOOL)activate:(XMPPStream *)aXmppStream { | ||
|
||
if ([super activate:aXmppStream]) { | ||
xmppIDTracker = [[XMPPIDTracker alloc] initWithDispatchQueue:moduleQueue]; | ||
|
||
return YES; | ||
} | ||
|
||
return NO; | ||
} | ||
|
||
- (void)deactivate { | ||
dispatch_block_t block = ^{ @autoreleasepool { | ||
|
||
[xmppIDTracker removeAllIDs]; | ||
xmppIDTracker = nil; | ||
|
||
}}; | ||
|
||
if (dispatch_get_specific(moduleQueueTag)) | ||
block(); | ||
else | ||
dispatch_sync(moduleQueue, block); | ||
|
||
[super deactivate]; | ||
} | ||
|
||
- (void) discoverWithIQ:(XMPPIQ *) infoOrItem { | ||
|
||
dispatch_block_t block = ^{ @autoreleasepool { | ||
|
||
NSString *iqID = [infoOrItem elementID]; | ||
[xmppIDTracker addID:iqID | ||
target:self | ||
selector:@selector(handleDiscovery:withInfo:) | ||
timeout:60.0]; | ||
|
||
[xmppStream sendElement:infoOrItem]; | ||
}}; | ||
|
||
if (dispatch_get_specific(moduleQueueTag)) | ||
block(); | ||
else | ||
dispatch_async(moduleQueue, block); | ||
} | ||
|
||
- (void)discoverInformationAboutJID:(XMPPJID *)jid{ | ||
[self discoverWithIQ:[XMPPIQ discoverInfoAssociatedWithJID:jid]]; | ||
} | ||
|
||
|
||
- (void)discoverItemsAssociatedWithJID:(XMPPJID *)jid{ | ||
[self discoverWithIQ:[XMPPIQ discoverItemsAssociatedWithJID:jid]]; | ||
} | ||
|
||
- (void)handleDiscovery:(XMPPIQ *)iq withInfo:(id <XMPPTrackingInfo>)info{ | ||
|
||
if ([[iq type] isEqualToString:@"result"]){ | ||
NSXMLElement *query = [iq elementForName:@"query"]; | ||
NSArray *items = [query children]; | ||
|
||
if ([query.xmlns isEqualToString:XMPPDiscoInfoNamespace]) { | ||
[multicastDelegate xmppServiceDiscovery:self didDiscoverInformation:items]; | ||
} else { | ||
[multicastDelegate xmppServiceDiscovery:self didDiscoverItems:items]; | ||
} | ||
|
||
} else { | ||
[multicastDelegate xmppServiceDiscovery:self didFailToDiscover:iq]; | ||
} | ||
} | ||
|
||
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq { | ||
|
||
NSString *type = [iq type]; | ||
|
||
if ([type isEqualToString:@"result"] || [type isEqualToString:@"error"]){ | ||
return [xmppIDTracker invokeForID:[iq elementID] withObject:iq]; | ||
} | ||
|
||
return NO; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if !query? Also violates nonnull