gloox 1.0.27
mucroom.h
1/*
2 Copyright (c) 2006-2023 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
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 send( const std::string& message, const std::string& subject, const StanzaExtensionList& sel = StanzaExtensionList() );
422
429 void setSubject( const std::string& subject );
430
435 MUCRoomAffiliation affiliation() const { return m_affiliation; }
436
441 MUCRoomRole role() const { return m_role; }
442
449 void setNick( const std::string& nick );
450
457 void setPresence( Presence::PresenceType presence, const std::string& msg = EmptyString );
458
467 void invite( const JID& invitee, const std::string& reason, const std::string& thread = EmptyString );
468
473 void getRoomInfo();
474
481 void getRoomItems();
482
492 void setPublish( bool publish, bool publishNick );
493
499 void registerMUCRoomHandler( MUCRoomHandler* mrl ) { m_roomHandler = mrl; }
500
504 void removeMUCRoomHandler() { m_roomHandler = 0; }
505
511 void registerMUCRoomConfigHandler( MUCRoomConfigHandler* mrch ) { m_roomConfigHandler = mrch; }
512
516 void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; }
517
528 void addHistory( const std::string& message, const JID& from, const std::string& stamp );
529
540 void setRequestHistory( int value, HistoryRequestType type );
541
550 void setRequestHistory( const std::string& since );
551
561 static Message* declineInvitation( const JID& room, const JID& invitor,
562 const std::string& reason = EmptyString);
563
568 void requestVoice();
569
578 void kick( const std::string& nick, const std::string& reason = EmptyString )
579 { setRole( nick, RoleNone, reason ); }
580
590 void ban( const std::string& nick, const std::string& reason )
591 { setAffiliation( nick, AffiliationOutcast, reason ); }
592
602 void grantVoice( const std::string& nick, const std::string& reason )
603 { setRole( nick, RoleParticipant, reason ); }
604
614 static Message* createDataForm( const JID& room, const DataForm* df );
615
625 void revokeVoice( const std::string& nick, const std::string& reason )
626 { setRole( nick, RoleVisitor, reason ); }
627
635 void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = EmptyString );
636
644 void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation,
645 const std::string& reason );
646
657 void requestRoomConfig();
658
666 void setRoomConfig( DataForm* form );
667
674 { instantRoom( CreateInstantRoom ); }
675
681 { instantRoom( CancelRoomCreation ); }
682
692 void destroy( const std::string& reason = EmptyString,
693 const JID& alternate = JID(), const std::string& password = EmptyString );
694
708 void requestList( MUCOperation operation );
709
734 void storeList( const MUCListItemList items, MUCOperation operation );
735
740 int flags() const { return m_flags; }
741
742 // reimplemented from DiscoHandler
743 virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
744
745 // reimplemented from DiscoHandler
746 // reimplemented from DiscoHandler
747 virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
748
749 // reimplemented from DiscoHandler
750 virtual void handleDiscoError( const JID& from, const Error* error, int context );
751
752 // reimplemented from PresenceHandler
753 virtual void handlePresence( const Presence& presence );
754
755 // reimplemented from MessageHandler
756 virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
757
758 // reimplemented from IqHandler
759 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
760
761 // reimplemented from IqHandler
762 virtual void handleIqID( const IQ& iq, int context );
763
764 // reimplemented from DiscoNodeHandler
765 virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node );
766
767 // reimplemented from DiscoNodeHandler
768 virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from,
769 const std::string& node );
770
771 // reimplemented from DiscoNodeHandler
772 virtual Disco::ItemList handleDiscoNodeItems( const JID& from, const JID& to,
773 const std::string& node = EmptyString );
774
775 protected:
780 void setName( const std::string& name ) { m_nick.setUsername( name ); }
781
786 virtual bool instantRoomHook() const { return false; }
787
788 ClientBase* m_parent;
789 JID m_nick;
790
791 bool m_joined;
792
793 private:
794#ifdef MUCROOM_TEST
795 public:
796#endif
803 class MUCOwner : public StanzaExtension
804 {
805 public:
806
810 enum QueryType
811 {
812 TypeCreate,
813 TypeRequestConfig,
814 TypeSendConfig,
815 TypeCancelConfig,
816 TypeInstantRoom,
817 TypeDestroy,
818 TypeIncomingTag
819 };
820
827 MUCOwner( QueryType type, DataForm* form = 0 );
828
835 MUCOwner( const JID& alternate = JID(), const std::string& reason = EmptyString,
836 const std::string& password = EmptyString);
837
842 MUCOwner( const Tag* tag );
843
847 virtual ~MUCOwner();
848
853 const DataForm* form() const { return m_form; }
854
855 // reimplemented from StanzaExtension
856 const std::string& filterString() const;
857
858 // reimplemented from StanzaExtension
859 StanzaExtension* newInstance( const Tag* tag ) const
860 {
861 return new MUCOwner( tag );
862 }
863
864 // reimplemented from StanzaExtension
865 Tag* tag() const;
866
867 // reimplemented from StanzaExtension
868 virtual StanzaExtension* clone() const
869 {
870 MUCOwner* m = new MUCOwner();
871 m->m_type = m_type;
872 m->m_jid = m_jid;
873 m->m_reason = m_reason;
874 m->m_pwd = m_pwd;
875 m->m_form = m_form ? new DataForm( *m_form ) : 0;
876 return m;
877 }
878
879 private:
880 QueryType m_type;
881 JID m_jid;
882 std::string m_reason;
883 std::string m_pwd;
884 DataForm* m_form;
885 };
886
893 class MUCAdmin : public StanzaExtension
894 {
895 public:
902 MUCAdmin( MUCRoomRole role, const std::string& nick,
903 const std::string& reason = EmptyString );
904
911 MUCAdmin( MUCRoomAffiliation affiliation, const std::string& nick,
912 const std::string& reason = EmptyString );
913
923 MUCAdmin( MUCOperation operation, const MUCListItemList& jids = MUCListItemList() );
924
929 MUCAdmin( const Tag* tag = 0 );
930
934 virtual ~MUCAdmin();
935
940 const MUCListItemList& list() const { return m_list; }
941
942 // reimplemented from StanzaExtension
943 const std::string& filterString() const;
944
945 // reimplemented from StanzaExtension
946 StanzaExtension* newInstance( const Tag* tag ) const
947 {
948 return new MUCAdmin( tag );
949 }
950
951 // reimplemented from StanzaExtension
952 Tag* tag() const;
953
954 // reimplemented from StanzaExtension
955 virtual StanzaExtension* clone() const
956 {
957 return new MUCAdmin( *this );
958 }
959
960 private:
961 MUCListItemList m_list;
962 MUCRoomAffiliation m_affiliation;
963 MUCRoomRole m_role;
964 };
965
966 void handleIqResult( const IQ& iq, int context );
967 void handleIqError( const IQ& iq, int context );
968 void setNonAnonymous();
969 void setSemiAnonymous();
970 void setFullyAnonymous();
971 void acknowledgeRoomCreation();
972 void instantRoom( int context );
973
974 MUCRoomHandler* m_roomHandler;
975 MUCRoomConfigHandler* m_roomConfigHandler;
976 MUCMessageSession* m_session;
977
978 typedef std::list<MUCRoomParticipant> ParticipantList;
979 ParticipantList m_participants;
980
981 std::string m_password;
982 std::string m_newNick;
983
984 MUCRoomAffiliation m_affiliation;
985 MUCRoomRole m_role;
986
987 HistoryRequestType m_historyType;
988
989 std::string m_historySince;
990 int m_historyValue;
991 int m_flags;
992 bool m_creationInProgress;
993 bool m_configChanged;
994 bool m_publishNick;
995 bool m_publish;
996 bool m_unique;
997
998 };
999
1000}
1001
1002#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.
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
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:511
void cancelRoomCreation()
Definition mucroom.h:680
void kick(const std::string &nick, const std::string &reason=EmptyString)
Definition mucroom.h:578
virtual bool handleIq(const IQ &iq)
Definition mucroom.h:759
void revokeVoice(const std::string &nick, const std::string &reason)
Definition mucroom.h:625
MUCRoomAffiliation affiliation() const
Definition mucroom.h:435
virtual bool instantRoomHook() const
Definition mucroom.h:786
@ HistoryMaxStanzas
Definition mucroom.h:98
void ban(const std::string &nick, const std::string &reason)
Definition mucroom.h:590
void acknowledgeInstantRoom()
Definition mucroom.h:673
void setPassword(const std::string &password)
Definition mucroom.h:370
void grantVoice(const std::string &nick, const std::string &reason)
Definition mucroom.h:602
const std::string service() const
Definition mucroom.h:383
void setName(const std::string &name)
Definition mucroom.h:780
int flags() const
Definition mucroom.h:740
void registerMUCRoomHandler(MUCRoomHandler *mrl)
Definition mucroom.h:499
void removeMUCRoomHandler()
Definition mucroom.h:504
MUCRoomRole role() const
Definition mucroom.h:441
void removeMUCRoomConfigHandler()
Definition mucroom.h:516
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
std::list< const StanzaExtension * > StanzaExtensionList
Definition gloox.h:1272
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