From beeb3e617eca003a1bc43319122527a6d2ae1d05 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sat, 23 Mar 2013 18:50:11 +0100 Subject: [PATCH] Add support for calculating caps hashes --- src/XMPPDiscoEntity.h | 7 +++++++ src/XMPPDiscoEntity.m | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/XMPPDiscoEntity.h b/src/XMPPDiscoEntity.h index 369678b..def24bc 100644 --- a/src/XMPPDiscoEntity.h +++ b/src/XMPPDiscoEntity.h @@ -74,5 +74,12 @@ */ - (void)addDiscoNode: (XMPPDiscoNode*)node; +/** + * \brief Calculates the Entity Capabilities Hash of the entity + * + * \return A OFString containing the capabilities hash + */ +- (OFString*)capsHash; + - (OFDictionary*)discoNodes; @end diff --git a/src/XMPPDiscoEntity.m b/src/XMPPDiscoEntity.m index 0b2d724..0ea7112 100644 --- a/src/XMPPDiscoEntity.m +++ b/src/XMPPDiscoEntity.m @@ -21,6 +21,7 @@ */ #import "XMPPDiscoEntity.h" +#import "XMPPDiscoIdentity.h" #import "XMPPIQ.h" #import "namespaces.h" @@ -67,6 +68,25 @@ forKey: [node node]]; } +- (OFString*)capsHash +{ + OFMutableString *caps = [OFMutableString string]; + OFEnumerator *enumerator; + XMPPDiscoIdentity *identity; + OFString *feature; + + enumerator = [_identities objectEnumerator]; + while ((identity = [enumerator nextObject]) != nil) + [caps appendFormat: @"%@/%@//%@<", [identity category], + [identity type], [identity name]]; + + enumerator = [_features objectEnumerator]; + while ((feature = [enumerator nextObject]) != nil) + [caps appendFormat: @"%@<", feature]; + + return [caps SHA1Hash]; +} + - (BOOL)connection: (XMPPConnection*)connection didReceiveIQ: (XMPPIQ*)IQ {