uniquemucroom.cpp
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "uniquemucroom.h"
#include "clientbase.h"
#include "jid.h"
#include "sha.h"
namespace gloox
{
// ---- UniqueMUCRoom::Unique ----
UniqueMUCRoom::Unique::Unique( const Tag* tag )
: StanzaExtension( ExtMUCUnique )
{
if( !tag || tag->name() != "unique" || tag->xmlns() != XMLNS_MUC_UNIQUE )
return;
m_name = tag->cdata();
}
const std::string& UniqueMUCRoom::Unique::filterString() const
{
static const std::string filter = "/iq/unique[@xmlns='" + XMLNS_MUC_UNIQUE + "']";
return filter;
}
Tag* UniqueMUCRoom::Unique::tag() const
{
Tag* t = new Tag( "unique" );
t->setXmlns( XMLNS_MUC_UNIQUE );
if( !m_name.empty() )
t->setCData( m_name );
return t;
}
// ---- ~UniqueMUCRoom::Unique ----
// ---- UniqueMUCRoom ----
UniqueMUCRoom::UniqueMUCRoom( ClientBase* parent, const JID& nick, MUCRoomHandler* mrh )
: InstantMUCRoom( parent, nick, mrh )
{
if( m_parent )
{
m_parent->registerStanzaExtension( new Unique() );
}
}
UniqueMUCRoom::~UniqueMUCRoom()
{
if( m_parent )
{
m_parent->removeIDHandler( this );
// m_parent->removeStanzaExtension( ExtMUCUnique ); // don't remove, other rooms might need it
}
}
void UniqueMUCRoom::join()
{
if( !m_parent || m_joined )
return;
IQ iq( IQ::Get, m_nick.server() );
iq.addExtension( new Unique() );
m_parent->send( iq, this, RequestUniqueName );
}
void UniqueMUCRoom::handleIqID( const IQ& iq, int context )
{
switch( iq.subtype() )
{
case IQ::Result:
if( context == RequestUniqueName )
{
const Unique* u = iq.findExtension<Unique>( ExtMUCUnique );
if( u )
{
if( !u->name().empty() )
setName( u->name() );
}
}
break;
case IQ::Error:
if( context == RequestUniqueName )
{
SHA s;
s.feed( m_parent->jid().full() );
s.feed( m_parent->getID() );
setName( s.hex() );
}
break;
default:
break;
}
MUCRoom::join();
}
}
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::ClientBase::send
void send(Tag *tag)
Definition clientbase.cpp:1004
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::IQ::Error
@ Error
Definition iq.h:49
gloox::IQ::Result
@ Result
Definition iq.h:48
gloox::IQ::Get
@ Get
Definition iq.h:45
gloox::InstantMUCRoom::InstantMUCRoom
InstantMUCRoom(ClientBase *parent, const JID &nick, MUCRoomHandler *mrh)
Definition instantmucroom.cpp:22
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::JID::server
const std::string & server() const
Definition jid.h:104
gloox::MUCRoomHandler
This interface enables inheriting classes to be notified about certain events in a MUC room.
Definition mucroomhandler.h:91
gloox::MUCRoom::join
virtual void join(Presence::PresenceType type=Presence::Available, const std::string &status=EmptyString, int priority=0)
Definition mucroom.cpp:655
gloox::MUCRoom::setName
void setName(const std::string &name)
Definition mucroom.h:780
gloox::MUCRoom::nick
const std::string nick() const
Definition mucroom.h:389
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition stanzaextension.h:204
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::UniqueMUCRoom::UniqueMUCRoom
UniqueMUCRoom(ClientBase *parent, const JID &nick, MUCRoomHandler *mrh)
Definition uniquemucroom.cpp:50
gloox::UniqueMUCRoom::~UniqueMUCRoom
virtual ~UniqueMUCRoom()
Definition uniquemucroom.cpp:59
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::XMLNS_MUC_UNIQUE
const std::string XMLNS_MUC_UNIQUE
Definition gloox.cpp:71
gloox::RequestUniqueName
@ RequestUniqueName
Definition mucroomconfighandler.h:138
gloox::ExtMUCUnique
@ ExtMUCUnique
Definition stanzaextension.h:73