From: Florian Zeitz Date: Wed, 3 Apr 2013 21:37:48 +0000 (+0200) Subject: Add basic Service Discovery support X-Git-Url: https://git.babelmonkeys.de/?a=commitdiff_plain;h=1a38d433f22f577feb4007160d7a591b00518c9f;p=jubjub.git Add basic Service Discovery support --- diff --git a/src/core/JubChatClient.h b/src/core/JubChatClient.h index cacb72d..57cfd0b 100644 --- a/src/core/JubChatClient.h +++ b/src/core/JubChatClient.h @@ -13,12 +13,14 @@ XMPPRoster *_roster; XMPPStreamManagement *_streamManagement; XMPPContactManager *_contactManager; + XMPPDiscoEntity *_discoEntity; XMPPPresence *_presence; id _ui; } @property (readonly) XMPPConnection *connection; @property (readonly) XMPPRoster *roster; @property (readonly) XMPPContactManager *contactManager; +@property (readonly) XMPPDiscoEntity *discoEntity; @property (readonly) XMPPPresence *presence; @property (assign) id ui; diff --git a/src/core/JubChatClient.m b/src/core/JubChatClient.m index eea1b8a..1d7874a 100644 --- a/src/core/JubChatClient.m +++ b/src/core/JubChatClient.m @@ -1,9 +1,13 @@ #import "JubChatClient.h" +#import "ObjXMPP/namespaces.h" + +#define JUB_CLIENT_URI @"http://babelmonkeys.de/jubjub" @implementation JubChatClient @synthesize connection = _connection; @synthesize roster = _roster; @synthesize contactManager = _contactManager; +@synthesize discoEntity = _discoEntity; @synthesize presence = _presence; @synthesize ui = _ui; @@ -47,6 +51,7 @@ [_roster release]; [_contactManager release]; + [_discoEntity release]; [_streamManagement release]; [_connection release]; [_presence release]; @@ -111,6 +116,17 @@ if (text != nil) presence.status = text; + OFXMLElement *caps = [OFXMLElement elementWithName: @"c" + namespace: XMPP_NS_CAPS]; + [caps addAttributeWithName: @"hash" + stringValue: @"sha-1"]; + [caps addAttributeWithName: @"ver" + stringValue: [_discoEntity capsHash]]; + [caps addAttributeWithName: @"node" + stringValue: JUB_CLIENT_URI]; + + [presence addChild: caps]; + [_connection sendStanza: presence]; } @@ -119,6 +135,17 @@ { of_log(@"Bound to JID: %@", [jid fullJID]); + _discoEntity = + [[XMPPDiscoEntity alloc] initWithConnection: connection + capsNode: JUB_CLIENT_URI]; + + XMPPDiscoIdentity *identity = + [XMPPDiscoIdentity identityWithCategory: @"client" + type: @"pc" + name: @"JubJub"]; + [_discoEntity addIdentity: identity]; + [_discoEntity addFeature: XMPP_NS_CAPS]; + [_roster requestRoster]; } @@ -145,8 +172,7 @@ - (void)rosterWasReceived: (XMPPRoster*)roster { - XMPPPresence *pres = [XMPPPresence presence]; - [pres setStatus: @"Hello from JubJub"]; - [_connection sendStanza: pres]; + [self sendPresenceWithStatus: @"available" + text: @"Hello from JubJub"]; } @end