gloox 1.0.24
mucroom.h
1/*
2 Copyright (c) 2006-2019 by Jakob Schröter <js@camaya.net>
3 This file is part of the gloox library. http://camaya.net/gloox
4
5 This software is distributed under a license. The full license
6 agreement can be found in the file LICENSE in this distribution.
7 This software may not be copied, modified, sold or distributed
8 other than expressed in the named license agreement.
9
10 This software is distributed without any warranty.
11*/
12
13
14
15#ifndef MUCROOM_H__
16#define MUCROOM_H__
17
18#include "discohandler.h"
19#include "disconodehandler.h"
20#include "dataform.h"
21#include "presencehandler.h"
22#include "iqhandler.h"
23#include "messagehandler.h"
24#include "mucroomhandler.h"
25#include "mucroomconfighandler.h"
26#include "jid.h"
27#include "stanzaextension.h"
28
29#include <string>
30
31namespace gloox
32{
33
34 class ClientBase;
35 class MUCMessageSession;
36 class Message;
37
85 class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler,
86 public IqHandler, private MessageHandler, private DiscoNodeHandler
87 {
88 public:
94 {
95 HistoryMaxChars,
100 HistorySince,
103 HistoryUnknown
105 };
106
111 {
116 OpDeclineFrom
117 };
118
127 class MUC : public StanzaExtension
128 {
129 public:
137 MUC( const std::string& password, HistoryRequestType historyType = HistoryUnknown,
138 const std::string& historySince = EmptyString, int historyValue = 0 );
139
144 MUC( const Tag* tag = 0 );
145
149 virtual ~MUC();
150
155 const std::string* password() const { return m_password; }
156
161 const std::string* historySince() const { return m_historySince; }
162
163 // reimplemented from StanzaExtension
164 virtual const std::string& filterString() const;
165
166 // reimplemented from StanzaExtension
167 virtual StanzaExtension* newInstance( const Tag* tag ) const
168 {
169 return new MUC( tag );
170 }
171
172 // reimplemented from StanzaExtension
173 virtual Tag* tag() const;
174
175 // reimplemented from StanzaExtension
176 virtual StanzaExtension* clone() const
177 {
178 MUC* m = new MUC();
179 m->m_password = m_password ? new std::string( *m_password ) : 0;
180 m->m_historySince = m_historySince ? new std::string( *m_historySince ) : 0;
181 m->m_historyType = m_historyType;
182 m->m_historyValue = m_historyValue;
183 return m;
184 }
185
186 private:
187 std::string* m_password;
188 std::string* m_historySince;
189 HistoryRequestType m_historyType;
190 int m_historyValue;
191 };
192
202 {
203 public:
213 MUCUser( MUCUserOperation operation, const std::string& to, const std::string& reason,
214 const std::string& thread = EmptyString );
215
220 MUCUser( const Tag* tag = 0 );
221
225 virtual ~MUCUser();
226
231 int flags() const { return m_flags; }
232
237 MUCRoomAffiliation affiliation() const { return m_affiliation; }
238
243 MUCRoomRole role() const { return m_role; }
244
248 const std::string* jid() const { return m_jid; }
249
253 const std::string* actor() const { return m_actor; }
254
258 const std::string* password() const { return m_password; }
259
263 const std::string* thread() const { return m_thread; }
264
268 const std::string* reason() const { return m_reason; }
269
273 const std::string* newNick() const { return m_newNick; }
274
279 const std::string* alternate() const { return m_alternate; }
280
285 bool continued() const { return m_continue; }
286
291 MUCUserOperation operation() const { return m_operation; }
292
293 // reimplemented from StanzaExtension
294 virtual const std::string& filterString() const;
295
296 // reimplemented from StanzaExtension
297 virtual StanzaExtension* newInstance( const Tag* tag ) const
298 {
299 return new MUCUser( tag );
300 }
301
302 // reimplemented from StanzaExtension
303 virtual Tag* tag() const;
304
305 // reimplemented from StanzaExtension
306 virtual StanzaExtension* clone() const
307 {
308 MUCUser* m = new MUCUser();
309 m->m_affiliation = m_affiliation;
310 m->m_role = m_role;
311 m->m_jid = m_jid ? new std::string( *m_jid ) : 0;
312 m->m_actor = m_actor ? new std::string( *m_actor ) : 0;
313 m->m_thread = m_thread ? new std::string( *m_thread ) : 0;
314 m->m_reason = m_reason ? new std::string( *m_reason ) : 0;
315 m->m_newNick = m_newNick ? new std::string( *m_newNick ) : 0;
316 m->m_password = m_password ? new std::string( *m_password ) : 0;
317 m->m_alternate = m_alternate ? new std::string( *m_alternate ) : 0;
318 m->m_operation = m_operation;
319 m->m_flags = m_flags;
320 m->m_del = m_del;
321 m->m_continue = m_continue;
322 return m;
323 }
324
325 private:
326 static MUCRoomAffiliation getEnumAffiliation( const std::string& affiliation );
327 static MUCRoomRole getEnumRole( const std::string& role );
328
329
330 MUCRoomAffiliation m_affiliation;
331 MUCRoomRole m_role;
332 std::string* m_jid;
333 std::string* m_actor;
334 std::string* m_thread;
335 std::string* m_reason;
336 std::string* m_newNick;
337 std::string* m_password;
338 std::string* m_alternate;
339 MUCUserOperation m_operation;
340 int m_flags;
341 bool m_del;
342 bool m_continue;
343 };
344
357 MUCRoom( ClientBase* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* mrch = 0 );
358
362 virtual ~MUCRoom();
363
370 void setPassword( const std::string& password ) { m_password = password; }
371
376 const std::string name() const { return m_nick.username(); }
377
383 const std::string service() const { return m_nick.server(); }
384
389 const std::string nick() const { return m_nick.resource(); }
390
399 virtual void join( Presence::PresenceType type = Presence::Available,
400 const std::string& status = EmptyString,
401 int priority = 0 );
402
407 void leave( const std::string& msg = EmptyString );
408
413 void send( const std::string& message );
414
421 void setSubject( const std::string& subject );
422
427 MUCRoomAffiliation affiliation() const { return m_affiliation; }
428
433 MUCRoomRole role() const { return m_role; }
434
441 void setNick( const std::string& nick );
442
449 void setPresence( Presence::PresenceType presence, const std::string& msg = EmptyString );
450
459 void invite( const JID& invitee, const std::string& reason, const std::string& thread = EmptyString );
460
465 void getRoomInfo();
466
473 void getRoomItems();
474
484 void setPublish( bool publish, bool publishNick );
485
491 void registerMUCRoomHandler( MUCRoomHandler* mrl ) { m_roomHandler = mrl; }
492
496 void removeMUCRoomHandler() { m_roomHandler = 0; }
497
503 void registerMUCRoomConfigHandler( MUCRoomConfigHandler* mrch ) { m_roomConfigHandler = mrch; }
504
508 void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; }
509
520 void addHistory( const std::string& message, const JID& from, const std::string& stamp );
521
532 void setRequestHistory( int value, HistoryRequestType type );
533
542 void setRequestHistory( const std::string& since );
543
553 static Message* declineInvitation( const JID& room, const JID& invitor,
554 const std::string& reason = EmptyString);
555
560 void requestVoice();
561
570 void kick( const std::string& nick, const std::string& reason = EmptyString )
571 { setRole( nick, RoleNone, reason ); }
572
582 void ban( const std::string& nick, const std::string& reason )
583 { setAffiliation( nick, AffiliationOutcast, reason ); }
584
594 void grantVoice( const std::string& nick, const std::string& reason )
595 { setRole( nick, RoleParticipant, reason ); }
596
606 static Message* createDataForm( const JID& room, const DataForm* df );
607
617 void revokeVoice( const std::string& nick, const std::string& reason )
618 { setRole( nick, RoleVisitor, reason ); }
619
627 void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = EmptyString );
628
636 void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation,
637 const std::string& reason );
638
649 void requestRoomConfig();
650
658 void setRoomConfig( DataForm* form );
659
666 { instantRoom( CreateInstantRoom ); }
667
673 { instantRoom( CancelRoomCreation ); }
674
684 void destroy( const std::string& reason = EmptyString,
685 const JID& alternate = JID(), const std::string& password = EmptyString );
686
700 void requestList( MUCOperation operation );
701
726 void storeList( const MUCListItemList items, MUCOperation operation );
727
732 int flags() const { return m_flags; }
733
734 // reimplemented from DiscoHandler
735 virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
736
737 // reimplemented from DiscoHandler
738 // reimplemented from DiscoHandler
739 virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
740
741 // reimplemented from DiscoHandler
742 virtual void handleDiscoError( const JID& from, const Error* error, int context );
743
744 // reimplemented from PresenceHandler
745 virtual void handlePresence( const Presence& presence );
746
747 // reimplemented from MessageHandler
748 virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
749
750 // reimplemented from IqHandler
751 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
752
753 // reimplemented from IqHandler
754 virtual void handleIqID( const IQ& iq, int context );
755
756 // reimplemented from DiscoNodeHandler
757 virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node );
758
759 // reimplemented from DiscoNodeHandler
760 virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from,
761 const std::string& node );
762
763 // reimplemented from DiscoNodeHandler
764 virtual Disco::ItemList handleDiscoNodeItems( const JID& from, const JID& to,
765 const std::string& node = EmptyString );
766
767 protected:
772 void setName( const std::string& name ) { m_nick.setUsername( name ); }
773
778 virtual bool instantRoomHook() const { return false; }
779
780 ClientBase* m_parent;
781 JID m_nick;
782
783 bool m_joined;
784
785 private:
786#ifdef MUCROOM_TEST
787 public:
788#endif
795 class MUCOwner : public StanzaExtension
796 {
797 public:
798
802 enum QueryType
803 {
804 TypeCreate,
805 TypeRequestConfig,
806 TypeSendConfig,
807 TypeCancelConfig,
808 TypeInstantRoom,
809 TypeDestroy,
810 TypeIncomingTag
811 };
812
819 MUCOwner( QueryType type, DataForm* form = 0 );
820
827 MUCOwner( const JID& alternate = JID(), const std::string& reason = EmptyString,
828 const std::string& password = EmptyString);
829
834 MUCOwner( const Tag* tag );
835
839 virtual ~MUCOwner();
840
845 const DataForm* form() const { return m_form; }
846
847 // reimplemented from StanzaExtension
848 const std::string& filterString() const;
849
850 // reimplemented from StanzaExtension
851 StanzaExtension* newInstance( const Tag* tag ) const
852 {
853 return new MUCOwner( tag );
854 }
855
856 // reimplemented from StanzaExtension
857 Tag* tag() const;
858
859 // reimplemented from StanzaExtension
860 virtual StanzaExtension* clone() const
861 {
862 MUCOwner* m = new MUCOwner();
863 m->m_type = m_type;
864 m->m_jid = m_jid;
865 m->m_reason = m_reason;
866 m->m_pwd = m_pwd;
867 m->m_form = m_form ? new DataForm( *m_form ) : 0;
868 return m;
869 }
870
871 private:
872 QueryType m_type;
873 JID m_jid;
874 std::string m_reason;
875 std::string m_pwd;
876 DataForm* m_form;
877 };
878
885 class MUCAdmin : public StanzaExtension
886 {
887 public:
894 MUCAdmin( MUCRoomRole role, const std::string& nick,
895 const std::string& reason = EmptyString );
896
903 MUCAdmin( MUCRoomAffiliation affiliation, const std::string& nick,
904 const std::string& reason = EmptyString );
905
915 MUCAdmin( MUCOperation operation, const MUCListItemList& jids = MUCListItemList() );
916
921 MUCAdmin( const Tag* tag = 0 );
922
926 virtual ~MUCAdmin();
927
932 const MUCListItemList& list() const { return m_list; }
933
934 // reimplemented from StanzaExtension
935 const std::string& filterString() const;
936
937 // reimplemented from StanzaExtension
938 StanzaExtension* newInstance( const Tag* tag ) const
939 {
940 return new MUCAdmin( tag );
941 }
942
943 // reimplemented from StanzaExtension
944 Tag* tag() const;
945
946 // reimplemented from StanzaExtension
947 virtual StanzaExtension* clone() const
948 {
949 return new MUCAdmin( *this );
950 }
951
952 private:
953 MUCListItemList m_list;
954 MUCRoomAffiliation m_affiliation;
955 MUCRoomRole m_role;
956 };
957
958 void handleIqResult( const IQ& iq, int context );
959 void handleIqError( const IQ& iq, int context );
960 void setNonAnonymous();
961 void setSemiAnonymous();
962 void setFullyAnonymous();
963 void acknowledgeRoomCreation();
964 void instantRoom( int context );
965
966 MUCRoomHandler* m_roomHandler;
967 MUCRoomConfigHandler* m_roomConfigHandler;
968 MUCMessageSession* m_session;
969
970 typedef std::list<MUCRoomParticipant> ParticipantList;
971 ParticipantList m_participants;
972
973 std::string m_password;
974 std::string m_newNick;
975
976 MUCRoomAffiliation m_affiliation;
977 MUCRoomRole m_role;
978
979 HistoryRequestType m_historyType;
980
981 std::string m_historySince;
982 int m_historyValue;
983 int m_flags;
984 bool m_creationInProgress;
985 bool m_configChanged;
986 bool m_publishNick;
987 bool m_publish;
988 bool m_unique;
989
990 };
991
992}
993
994#endif // MUCROOM_H__
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:79
An abstraction of a XEP-0004 Data Form.
Definition: dataform.h:57
A virtual interface that enables objects to receive Service Discovery (XEP-0030) events.
Definition: discohandler.h:35
Derived classes can be registered as NodeHandlers for certain nodes with the Disco object.
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
Definition: disco.h:66
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
Definition: disco.h:276
std::list< Identity * > IdentityList
Definition: disco.h:56
std::list< Item * > ItemList
Definition: disco.h:266
A stanza error abstraction implemented as a StanzaExtension.
Definition: error.h:35
An abstraction of an IQ stanza.
Definition: iq.h:34
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:32
An abstraction of a JID.
Definition: jid.h:31
An abstract interface that can be implemented for MUC room configuration.
This interface enables inheriting classes to be notified about certain events in a MUC room.
An abstraction of a MUC user query.
Definition: mucroom.h:202
MUCRoomAffiliation affiliation() const
Definition: mucroom.h:237
const std::string * alternate() const
Definition: mucroom.h:279
virtual StanzaExtension * clone() const
Definition: mucroom.h:306
bool continued() const
Definition: mucroom.h:285
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: mucroom.h:297
int flags() const
Definition: mucroom.h:231
MUCUserOperation operation() const
Definition: mucroom.h:291
MUCRoomRole role() const
Definition: mucroom.h:243
An abstraction of a MUC query.
Definition: mucroom.h:128
virtual StanzaExtension * clone() const
Definition: mucroom.h:176
const std::string * password() const
Definition: mucroom.h:155
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: mucroom.h:167
const std::string * historySince() const
Definition: mucroom.h:161
This is an implementation of XEP-0045 (Multi-User Chat).
Definition: mucroom.h:87
void registerMUCRoomConfigHandler(MUCRoomConfigHandler *mrch)
Definition: mucroom.h:503
void cancelRoomCreation()
Definition: mucroom.h:672
void kick(const std::string &nick, const std::string &reason=EmptyString)
Definition: mucroom.h:570
virtual bool handleIq(const IQ &iq)
Definition: mucroom.h:751
void revokeVoice(const std::string &nick, const std::string &reason)
Definition: mucroom.h:617
MUCRoomAffiliation affiliation() const
Definition: mucroom.h:427
virtual bool instantRoomHook() const
Definition: mucroom.h:778
@ HistorySeconds
Definition: mucroom.h:99
@ HistoryMaxStanzas
Definition: mucroom.h:98
void ban(const std::string &nick, const std::string &reason)
Definition: mucroom.h:582
void acknowledgeInstantRoom()
Definition: mucroom.h:665
void setPassword(const std::string &password)
Definition: mucroom.h:370
void grantVoice(const std::string &nick, const std::string &reason)
Definition: mucroom.h:594
const std::string service() const
Definition: mucroom.h:383
void setName(const std::string &name)
Definition: mucroom.h:772
int flags() const
Definition: mucroom.h:732
void registerMUCRoomHandler(MUCRoomHandler *mrl)
Definition: mucroom.h:491
void removeMUCRoomHandler()
Definition: mucroom.h:496
MUCRoomRole role() const
Definition: mucroom.h:433
void removeMUCRoomConfigHandler()
Definition: mucroom.h:508
const std::string name() const
Definition: mucroom.h:376
const std::string nick() const
Definition: mucroom.h:389
A virtual interface which can be reimplemented to receive incoming message stanzas.
An abstraction of a message session between any two entities.
An abstraction of a message stanza.
Definition: message.h:34
A virtual interface which can be reimplemented to receive presence stanzas.
An abstraction of a presence stanza.
Definition: presence.h:33
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
The namespace for the gloox library.
Definition: adhoc.cpp:28
MUCRoomRole
Definition: gloox.h:1164
@ RoleParticipant
Definition: gloox.h:1167
@ RoleVisitor
Definition: gloox.h:1166
@ RoleNone
Definition: gloox.h:1165
std::list< std::string > StringList
Definition: gloox.h:1251
std::list< MUCListItem > MUCListItemList
const std::string EmptyString
Definition: gloox.cpp:124
MUCRoomAffiliation
Definition: gloox.h:1151
@ AffiliationOutcast
Definition: gloox.h:1153