DiscoEntity: Answer to requests send to the caps node
This commit is contained in:
parent
56e3aef482
commit
441a9e4472
3 changed files with 55 additions and 6 deletions
|
@ -35,6 +35,7 @@
|
||||||
{
|
{
|
||||||
OFMutableDictionary *_discoNodes;
|
OFMutableDictionary *_discoNodes;
|
||||||
XMPPConnection *_connection;
|
XMPPConnection *_connection;
|
||||||
|
OFString *_capsNode;
|
||||||
}
|
}
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
#ifdef OF_HAVE_PROPERTIES
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +46,8 @@
|
||||||
* any number of nodes nested more deeply.
|
* any number of nodes nested more deeply.
|
||||||
*/
|
*/
|
||||||
@property (readonly) OFDictionary *discoNodes;
|
@property (readonly) OFDictionary *discoNodes;
|
||||||
|
/// \brief The node advertised for the entity's capabilites
|
||||||
|
@property (readonly) OFString *capsNode;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,6 +60,18 @@
|
||||||
*/
|
*/
|
||||||
+ discoEntityWithConnection: (XMPPConnection*)connection;
|
+ discoEntityWithConnection: (XMPPConnection*)connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Creates a new autoreleased XMPPDiscoEntity with the specified
|
||||||
|
* connection.
|
||||||
|
*
|
||||||
|
* \param connection The XMPPConnection to serve responses on.
|
||||||
|
* This must already be bound to a resource)
|
||||||
|
* \param capsNode The node advertised for the entity's capabilites
|
||||||
|
* \return A new autoreleased XMPPDiscoEntity
|
||||||
|
*/
|
||||||
|
+ discoEntityWithConnection: (XMPPConnection*)connection
|
||||||
|
capsNode: (OFString*)capsNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initializes an already allocated XMPPDiscoEntity with the specified
|
* \brief Initializes an already allocated XMPPDiscoEntity with the specified
|
||||||
* connection.
|
* connection.
|
||||||
|
@ -67,6 +82,18 @@
|
||||||
*/
|
*/
|
||||||
- initWithConnection: (XMPPConnection*)connection;
|
- initWithConnection: (XMPPConnection*)connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Initializes an already allocated XMPPDiscoEntity with the specified
|
||||||
|
* connection.
|
||||||
|
*
|
||||||
|
* \param connection The XMPPConnection to serve responses on.
|
||||||
|
* This must already be bound to a resource)
|
||||||
|
* \param capsNode The node advertised for the entity's capabilites
|
||||||
|
* \return An initialized XMPPDiscoEntity
|
||||||
|
*/
|
||||||
|
- initWithConnection: (XMPPConnection*)connection
|
||||||
|
capsNode: (OFString*)capsNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Adds a XMPPDiscoNode to provide responses for.
|
* \brief Adds a XMPPDiscoNode to provide responses for.
|
||||||
*
|
*
|
||||||
|
@ -82,4 +109,5 @@
|
||||||
- (OFString*)capsHash;
|
- (OFString*)capsHash;
|
||||||
|
|
||||||
- (OFDictionary*)discoNodes;
|
- (OFDictionary*)discoNodes;
|
||||||
|
- (OFString*)capsNode;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -31,7 +31,21 @@
|
||||||
return [[[self alloc] initWithConnection: connection] autorelease];
|
return [[[self alloc] initWithConnection: connection] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ discoEntityWithConnection: (XMPPConnection*)connection
|
||||||
|
capsNode: (OFString*)capsNode
|
||||||
|
{
|
||||||
|
return [[[self alloc] initWithConnection: connection
|
||||||
|
capsNode: capsNode] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
- initWithConnection: (XMPPConnection*)connection
|
- initWithConnection: (XMPPConnection*)connection
|
||||||
|
{
|
||||||
|
return [self initWithConnection: connection
|
||||||
|
capsNode: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- initWithConnection: (XMPPConnection*)connection
|
||||||
|
capsNode: (OFString*)capsNode
|
||||||
{
|
{
|
||||||
self = [super initWithJID: [connection JID]
|
self = [super initWithJID: [connection JID]
|
||||||
node: nil];
|
node: nil];
|
||||||
|
@ -39,6 +53,7 @@
|
||||||
@try {
|
@try {
|
||||||
_discoNodes = [OFMutableDictionary new];
|
_discoNodes = [OFMutableDictionary new];
|
||||||
_connection = connection;
|
_connection = connection;
|
||||||
|
_capsNode = [capsNode copy];
|
||||||
|
|
||||||
[_connection addDelegate: self];
|
[_connection addDelegate: self];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
|
@ -68,6 +83,11 @@
|
||||||
forKey: [node node]];
|
forKey: [node node]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (OFString*)capsNode
|
||||||
|
{
|
||||||
|
OF_GETTER(_capsNode, YES);
|
||||||
|
}
|
||||||
|
|
||||||
- (OFString*)capsHash
|
- (OFString*)capsHash
|
||||||
{
|
{
|
||||||
OFMutableString *caps = [OFMutableString string];
|
OFMutableString *caps = [OFMutableString string];
|
||||||
|
@ -117,10 +137,17 @@
|
||||||
if (query != nil) {
|
if (query != nil) {
|
||||||
OFString *node =
|
OFString *node =
|
||||||
[[query attributeForName: @"node"] stringValue];
|
[[query attributeForName: @"node"] stringValue];
|
||||||
|
|
||||||
if (node == nil)
|
if (node == nil)
|
||||||
return [self XMPP_handleInfoIQ: IQ
|
return [self XMPP_handleInfoIQ: IQ
|
||||||
connection: connection];
|
connection: connection];
|
||||||
|
|
||||||
|
OFString *capsNode = [_capsNode stringByAppendingFormat: @"#%@",
|
||||||
|
[self capsHash]];
|
||||||
|
if ([capsNode isEqual: node])
|
||||||
|
return [self XMPP_handleInfoIQ: IQ
|
||||||
|
connection: connection];
|
||||||
|
|
||||||
XMPPDiscoNode *responder = [_discoNodes objectForKey: node];
|
XMPPDiscoNode *responder = [_discoNodes objectForKey: node];
|
||||||
if (responder != nil)
|
if (responder != nil)
|
||||||
return [responder XMPP_handleInfoIQ: IQ
|
return [responder XMPP_handleInfoIQ: IQ
|
||||||
|
|
|
@ -190,12 +190,6 @@
|
||||||
OFEnumerator *enumerator;
|
OFEnumerator *enumerator;
|
||||||
OFString *feature;
|
OFString *feature;
|
||||||
XMPPDiscoIdentity *identity;
|
XMPPDiscoIdentity *identity;
|
||||||
OFXMLElement *query = [IQ elementForName: @"query"
|
|
||||||
namespace: XMPP_NS_DISCO_INFO];
|
|
||||||
OFString *node = [[query attributeForName: @"node"] stringValue];
|
|
||||||
|
|
||||||
if (!(node == _node) && ![node isEqual: _node])
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
resultIQ = [IQ resultIQ];
|
resultIQ = [IQ resultIQ];
|
||||||
response = [OFXMLElement elementWithName: @"query"
|
response = [OFXMLElement elementWithName: @"query"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue