mucroom.h
/*
Copyright (c) 2006-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.
*/
#ifndef MUCROOM_H__
#define MUCROOM_H__
#include "discohandler.h"
#include "disconodehandler.h"
#include "dataform.h"
#include "presencehandler.h"
#include "iqhandler.h"
#include "messagehandler.h"
#include "mucroomhandler.h"
#include "mucroomconfighandler.h"
#include "jid.h"
#include "stanzaextension.h"
#include <string>
namespace gloox
{
class ClientBase;
class MUCMessageSession;
class Message;
class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler,
public IqHandler, private MessageHandler, private DiscoNodeHandler
{
public:
enum HistoryRequestType
{
HistoryMaxChars,
HistoryMaxStanzas,
HistorySeconds,
HistorySince,
HistoryUnknown
};
enum MUCUserOperation
{
OpNone,
OpInviteTo,
OpInviteFrom,
OpDeclineTo,
OpDeclineFrom
};
class MUC : public StanzaExtension
{
public:
MUC( const std::string& password, HistoryRequestType historyType = HistoryUnknown,
const std::string& historySince = EmptyString, int historyValue = 0 );
MUC( const Tag* tag = 0 );
virtual ~MUC();
const std::string* password() const { return m_password; }
const std::string* historySince() const { return m_historySince; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new MUC( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
MUC* m = new MUC();
m->m_password = m_password ? new std::string( *m_password ) : 0;
m->m_historySince = m_historySince ? new std::string( *m_historySince ) : 0;
m->m_historyType = m_historyType;
m->m_historyValue = m_historyValue;
return m;
}
private:
std::string* m_password;
std::string* m_historySince;
HistoryRequestType m_historyType;
int m_historyValue;
};
class MUCUser : public StanzaExtension
{
public:
MUCUser( MUCUserOperation operation, const std::string& to, const std::string& reason,
const std::string& thread = EmptyString );
MUCUser( const Tag* tag = 0 );
virtual ~MUCUser();
int flags() const { return m_flags; }
MUCRoomAffiliation affiliation() const { return m_affiliation; }
MUCRoomRole role() const { return m_role; }
const std::string* jid() const { return m_jid; }
const std::string* actor() const { return m_actor; }
const std::string* password() const { return m_password; }
const std::string* thread() const { return m_thread; }
const std::string* reason() const { return m_reason; }
const std::string* newNick() const { return m_newNick; }
const std::string* alternate() const { return m_alternate; }
bool continued() const { return m_continue; }
MUCUserOperation operation() const { return m_operation; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new MUCUser( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
MUCUser* m = new MUCUser();
m->m_affiliation = m_affiliation;
m->m_role = m_role;
m->m_jid = m_jid ? new std::string( *m_jid ) : 0;
m->m_actor = m_actor ? new std::string( *m_actor ) : 0;
m->m_thread = m_thread ? new std::string( *m_thread ) : 0;
m->m_reason = m_reason ? new std::string( *m_reason ) : 0;
m->m_newNick = m_newNick ? new std::string( *m_newNick ) : 0;
m->m_password = m_password ? new std::string( *m_password ) : 0;
m->m_alternate = m_alternate ? new std::string( *m_alternate ) : 0;
m->m_operation = m_operation;
m->m_flags = m_flags;
m->m_del = m_del;
m->m_continue = m_continue;
return m;
}
private:
static MUCRoomAffiliation getEnumAffiliation( const std::string& affiliation );
static MUCRoomRole getEnumRole( const std::string& role );
MUCRoomAffiliation m_affiliation;
MUCRoomRole m_role;
std::string* m_jid;
std::string* m_actor;
std::string* m_thread;
std::string* m_reason;
std::string* m_newNick;
std::string* m_password;
std::string* m_alternate;
MUCUserOperation m_operation;
int m_flags;
bool m_del;
bool m_continue;
};
MUCRoom( ClientBase* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* mrch = 0 );
virtual ~MUCRoom();
void setPassword( const std::string& password ) { m_password = password; }
const std::string name() const { return m_nick.username(); }
const std::string service() const { return m_nick.server(); }
const std::string nick() const { return m_nick.resource(); }
virtual void join( Presence::PresenceType type = Presence::Available,
const std::string& status = EmptyString,
int priority = 0 );
void leave( const std::string& msg = EmptyString );
void send( const std::string& message );
void send( const std::string& message, const std::string& subject, const StanzaExtensionList& sel = StanzaExtensionList() );
void setSubject( const std::string& subject );
MUCRoomAffiliation affiliation() const { return m_affiliation; }
MUCRoomRole role() const { return m_role; }
void setNick( const std::string& nick );
void setPresence( Presence::PresenceType presence, const std::string& msg = EmptyString );
void invite( const JID& invitee, const std::string& reason, const std::string& thread = EmptyString );
void getRoomInfo();
void getRoomItems();
void setPublish( bool publish, bool publishNick );
void registerMUCRoomHandler( MUCRoomHandler* mrl ) { m_roomHandler = mrl; }
void removeMUCRoomHandler() { m_roomHandler = 0; }
void registerMUCRoomConfigHandler( MUCRoomConfigHandler* mrch ) { m_roomConfigHandler = mrch; }
void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; }
void addHistory( const std::string& message, const JID& from, const std::string& stamp );
void setRequestHistory( int value, HistoryRequestType type );
void setRequestHistory( const std::string& since );
static Message* declineInvitation( const JID& room, const JID& invitor,
const std::string& reason = EmptyString);
void requestVoice();
void kick( const std::string& nick, const std::string& reason = EmptyString )
{ setRole( nick, RoleNone, reason ); }
void ban( const std::string& nick, const std::string& reason )
{ setAffiliation( nick, AffiliationOutcast, reason ); }
void grantVoice( const std::string& nick, const std::string& reason )
{ setRole( nick, RoleParticipant, reason ); }
static Message* createDataForm( const JID& room, const DataForm* df );
void revokeVoice( const std::string& nick, const std::string& reason )
{ setRole( nick, RoleVisitor, reason ); }
void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = EmptyString );
void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation,
const std::string& reason );
void requestRoomConfig();
void setRoomConfig( DataForm* form );
void acknowledgeInstantRoom()
{ instantRoom( CreateInstantRoom ); }
void cancelRoomCreation()
{ instantRoom( CancelRoomCreation ); }
void destroy( const std::string& reason = EmptyString,
const JID& alternate = JID(), const std::string& password = EmptyString );
void requestList( MUCOperation operation );
void storeList( const MUCListItemList items, MUCOperation operation );
int flags() const { return m_flags; }
// reimplemented from DiscoHandler
virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
// reimplemented from DiscoHandler
// reimplemented from DiscoHandler
virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
// reimplemented from DiscoHandler
virtual void handleDiscoError( const JID& from, const Error* error, int context );
// reimplemented from PresenceHandler
virtual void handlePresence( const Presence& presence );
// reimplemented from MessageHandler
virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
// reimplemented from IqHandler
virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
// reimplemented from IqHandler
virtual void handleIqID( const IQ& iq, int context );
// reimplemented from DiscoNodeHandler
virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node );
// reimplemented from DiscoNodeHandler
virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from,
const std::string& node );
// reimplemented from DiscoNodeHandler
virtual Disco::ItemList handleDiscoNodeItems( const JID& from, const JID& to,
const std::string& node = EmptyString );
protected:
void setName( const std::string& name ) { m_nick.setUsername( name ); }
virtual bool instantRoomHook() const { return false; }
ClientBase* m_parent;
JID m_nick;
bool m_joined;
private:
#ifdef MUCROOM_TEST
public:
#endif
class MUCOwner : public StanzaExtension
{
public:
enum QueryType
{
TypeCreate,
TypeRequestConfig,
TypeSendConfig,
TypeCancelConfig,
TypeInstantRoom,
TypeDestroy,
TypeIncomingTag
};
MUCOwner( QueryType type, DataForm* form = 0 );
MUCOwner( const JID& alternate = JID(), const std::string& reason = EmptyString,
const std::string& password = EmptyString);
MUCOwner( const Tag* tag );
virtual ~MUCOwner();
const DataForm* form() const { return m_form; }
// reimplemented from StanzaExtension
const std::string& filterString() const;
// reimplemented from StanzaExtension
StanzaExtension* newInstance( const Tag* tag ) const
{
return new MUCOwner( tag );
}
// reimplemented from StanzaExtension
Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
MUCOwner* m = new MUCOwner();
m->m_type = m_type;
m->m_jid = m_jid;
m->m_reason = m_reason;
m->m_pwd = m_pwd;
m->m_form = m_form ? new DataForm( *m_form ) : 0;
return m;
}
private:
QueryType m_type;
JID m_jid;
std::string m_reason;
std::string m_pwd;
DataForm* m_form;
};
class MUCAdmin : public StanzaExtension
{
public:
MUCAdmin( MUCRoomRole role, const std::string& nick,
const std::string& reason = EmptyString );
MUCAdmin( MUCRoomAffiliation affiliation, const std::string& nick,
const std::string& reason = EmptyString );
MUCAdmin( MUCOperation operation, const MUCListItemList& jids = MUCListItemList() );
MUCAdmin( const Tag* tag = 0 );
virtual ~MUCAdmin();
const MUCListItemList& list() const { return m_list; }
// reimplemented from StanzaExtension
const std::string& filterString() const;
// reimplemented from StanzaExtension
StanzaExtension* newInstance( const Tag* tag ) const
{
return new MUCAdmin( tag );
}
// reimplemented from StanzaExtension
Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
return new MUCAdmin( *this );
}
private:
MUCListItemList m_list;
MUCRoomAffiliation m_affiliation;
MUCRoomRole m_role;
};
void handleIqResult( const IQ& iq, int context );
void handleIqError( const IQ& iq, int context );
void setNonAnonymous();
void setSemiAnonymous();
void setFullyAnonymous();
void acknowledgeRoomCreation();
void instantRoom( int context );
MUCRoomHandler* m_roomHandler;
MUCRoomConfigHandler* m_roomConfigHandler;
MUCMessageSession* m_session;
typedef std::list<MUCRoomParticipant> ParticipantList;
ParticipantList m_participants;
std::string m_password;
std::string m_newNick;
MUCRoomAffiliation m_affiliation;
MUCRoomRole m_role;
HistoryRequestType m_historyType;
std::string m_historySince;
int m_historyValue;
int m_flags;
bool m_creationInProgress;
bool m_configChanged;
bool m_publishNick;
bool m_publish;
bool m_unique;
};
}
#endif // MUCROOM_H__
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::DataForm
An abstraction of a XEP-0004 Data Form.
Definition dataform.h:57
gloox::DiscoHandler
A virtual interface that enables objects to receive Service Discovery (XEP-0030) events.
Definition discohandler.h:35
gloox::DiscoNodeHandler
Derived classes can be registered as NodeHandlers for certain nodes with the Disco object.
Definition disconodehandler.h:36
gloox::Disco::Info
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
Definition disco.h:66
gloox::Disco::Items
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
Definition disco.h:276
gloox::Disco::IdentityList
std::list< Identity * > IdentityList
Definition disco.h:56
gloox::Disco::ItemList
std::list< Item * > ItemList
Definition disco.h:266
gloox::Error
A stanza error abstraction implemented as a StanzaExtension.
Definition error.h:35
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::IqHandler
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition iqhandler.h:32
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::MUCMessageSession
This is a MessageSession, adapted to be used in a MUC context.
Definition mucmessagesession.h:33
gloox::MUCRoomConfigHandler
An abstract interface that can be implemented for MUC room configuration.
Definition mucroomconfighandler.h:177
gloox::MUCRoomHandler
This interface enables inheriting classes to be notified about certain events in a MUC room.
Definition mucroomhandler.h:91
gloox::MUCRoom::MUCUser::affiliation
MUCRoomAffiliation affiliation() const
Definition mucroom.h:237
gloox::MUCRoom::MUCUser::alternate
const std::string * alternate() const
Definition mucroom.h:279
gloox::MUCRoom::MUCUser::clone
virtual StanzaExtension * clone() const
Definition mucroom.h:306
gloox::MUCRoom::MUCUser::MUCUser
MUCUser(MUCUserOperation operation, const std::string &to, const std::string &reason, const std::string &thread=EmptyString)
Definition mucroom.cpp:298
gloox::MUCRoom::MUCUser::continued
bool continued() const
Definition mucroom.h:285
gloox::MUCRoom::MUCUser::newInstance
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition mucroom.h:297
gloox::MUCRoom::MUCUser::flags
int flags() const
Definition mucroom.h:231
gloox::MUCRoom::MUCUser::operation
MUCUserOperation operation() const
Definition mucroom.h:291
gloox::MUCRoom::MUCUser::role
MUCRoomRole role() const
Definition mucroom.h:243
gloox::MUCRoom::MUCUser::tag
virtual Tag * tag() const
Definition mucroom.cpp:457
gloox::MUCRoom::MUC::clone
virtual StanzaExtension * clone() const
Definition mucroom.h:176
gloox::MUCRoom::MUC::password
const std::string * password() const
Definition mucroom.h:155
gloox::MUCRoom::MUC::newInstance
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition mucroom.h:167
gloox::MUCRoom::MUC::MUC
MUC(const std::string &password, HistoryRequestType historyType=HistoryUnknown, const std::string &historySince=EmptyString, int historyValue=0)
Definition mucroom.cpp:543
gloox::MUCRoom::MUC::historySince
const std::string * historySince() const
Definition mucroom.h:161
gloox::MUCRoom::MUC::tag
virtual Tag * tag() const
Definition mucroom.cpp:596
gloox::MUCRoom
This is an implementation of XEP-0045 (Multi-User Chat).
Definition mucroom.h:87
gloox::MUCRoom::registerMUCRoomConfigHandler
void registerMUCRoomConfigHandler(MUCRoomConfigHandler *mrch)
Definition mucroom.h:511
gloox::MUCRoom::cancelRoomCreation
void cancelRoomCreation()
Definition mucroom.h:680
gloox::MUCRoom::kick
void kick(const std::string &nick, const std::string &reason=EmptyString)
Definition mucroom.h:578
gloox::MUCRoom::handleIq
virtual bool handleIq(const IQ &iq)
Definition mucroom.h:759
gloox::MUCRoom::revokeVoice
void revokeVoice(const std::string &nick, const std::string &reason)
Definition mucroom.h:625
gloox::MUCRoom::affiliation
MUCRoomAffiliation affiliation() const
Definition mucroom.h:435
gloox::MUCRoom::instantRoomHook
virtual bool instantRoomHook() const
Definition mucroom.h:786
gloox::MUCRoom::HistoryRequestType
HistoryRequestType
Definition mucroom.h:94
gloox::MUCRoom::HistoryUnknown
@ HistoryUnknown
Definition mucroom.h:103
gloox::MUCRoom::HistorySeconds
@ HistorySeconds
Definition mucroom.h:99
gloox::MUCRoom::HistoryMaxStanzas
@ HistoryMaxStanzas
Definition mucroom.h:98
gloox::MUCRoom::HistorySince
@ HistorySince
Definition mucroom.h:100
gloox::MUCRoom::HistoryMaxChars
@ HistoryMaxChars
Definition mucroom.h:95
gloox::MUCRoom::ban
void ban(const std::string &nick, const std::string &reason)
Definition mucroom.h:590
gloox::MUCRoom::MUCRoom
MUCRoom(ClientBase *parent, const JID &nick, MUCRoomHandler *mrh, MUCRoomConfigHandler *mrch=0)
Definition mucroom.cpp:619
gloox::MUCRoom::acknowledgeInstantRoom
void acknowledgeInstantRoom()
Definition mucroom.h:673
gloox::MUCRoom::setPassword
void setPassword(const std::string &password)
Definition mucroom.h:370
gloox::MUCRoom::grantVoice
void grantVoice(const std::string &nick, const std::string &reason)
Definition mucroom.h:602
gloox::MUCRoom::service
const std::string service() const
Definition mucroom.h:383
gloox::MUCRoom::setAffiliation
void setAffiliation(const std::string &nick, MUCRoomAffiliation affiliation, const std::string &reason)
Definition mucroom.cpp:859
gloox::MUCRoom::setName
void setName(const std::string &name)
Definition mucroom.h:780
gloox::MUCRoom::flags
int flags() const
Definition mucroom.h:740
gloox::MUCRoom::registerMUCRoomHandler
void registerMUCRoomHandler(MUCRoomHandler *mrl)
Definition mucroom.h:499
gloox::MUCRoom::removeMUCRoomHandler
void removeMUCRoomHandler()
Definition mucroom.h:504
gloox::MUCRoom::role
MUCRoomRole role() const
Definition mucroom.h:441
gloox::MUCRoom::setRole
void setRole(const std::string &nick, MUCRoomRole role, const std::string &reason=EmptyString)
Definition mucroom.cpp:828
gloox::MUCRoom::removeMUCRoomConfigHandler
void removeMUCRoomConfigHandler()
Definition mucroom.h:516
gloox::MUCRoom::name
const std::string name() const
Definition mucroom.h:376
gloox::MUCRoom::nick
const std::string nick() const
Definition mucroom.h:389
gloox::MUCRoom::MUCUserOperation
MUCUserOperation
Definition mucroom.h:111
gloox::MUCRoom::OpDeclineTo
@ OpDeclineTo
Definition mucroom.h:115
gloox::MUCRoom::OpInviteTo
@ OpInviteTo
Definition mucroom.h:113
gloox::MUCRoom::OpDeclineFrom
@ OpDeclineFrom
Definition mucroom.h:116
gloox::MUCRoom::OpInviteFrom
@ OpInviteFrom
Definition mucroom.h:114
gloox::MUCRoom::OpNone
@ OpNone
Definition mucroom.h:112
gloox::MessageHandler
A virtual interface which can be reimplemented to receive incoming message stanzas.
Definition messagehandler.h:37
gloox::MessageSession
An abstraction of a message session between any two entities.
Definition messagesession.h:146
gloox::Message
An abstraction of a message stanza.
Definition message.h:34
gloox::PresenceHandler
A virtual interface which can be reimplemented to receive presence stanzas.
Definition presencehandler.h:31
gloox::Presence
An abstraction of a presence stanza.
Definition presence.h:33
gloox::Presence::PresenceType
PresenceType
Definition presence.h:43
gloox::Presence::Available
@ Available
Definition presence.h:44
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition stanzaextension.h:204
gloox::StanzaExtension::StanzaExtension
StanzaExtension(int type)
Definition stanzaextension.h:211
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StanzaExtensionList
std::list< const StanzaExtension * > StanzaExtensionList
Definition gloox.h:1272
gloox::MUCRoomRole
MUCRoomRole
Definition gloox.h:1164
gloox::RoleParticipant
@ RoleParticipant
Definition gloox.h:1167
gloox::RoleVisitor
@ RoleVisitor
Definition gloox.h:1166
gloox::RoleNone
@ RoleNone
Definition gloox.h:1165
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::MUCListItemList
std::list< MUCListItem > MUCListItemList
Definition mucroomconfighandler.h:131
gloox::MUCOperation
MUCOperation
Definition mucroomconfighandler.h:137
gloox::CreateInstantRoom
@ CreateInstantRoom
Definition mucroomconfighandler.h:139
gloox::CancelRoomCreation
@ CancelRoomCreation
Definition mucroomconfighandler.h:140
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::MUCRoomAffiliation
MUCRoomAffiliation
Definition gloox.h:1151
gloox::AffiliationOutcast
@ AffiliationOutcast
Definition gloox.h:1153