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 MUCROOMCONFIGHANDLER_H__
16 #define MUCROOMCONFIGHANDLER_H__
17 
18 #include "gloox.h"
19 #include "jid.h"
20 
21 #include <string>
22 #include <list>
23 
24 namespace gloox
25 {
26 
27   class MUCRoom;
28   class DataForm;
29 
30   /**
31    * An item in a list of MUC room users. Lists of these items are
32    * used when manipulating the lists of members, admins, owners, etc.
33    * of a room.
34    *
35    * @author Jakob Schröter <js@camaya.net>
36    * @since 1.0
37    */
38   class MUCListItem
39   {
40     public:
41       /**
42        * Constructs a new object using the given JID.
43        * @param jid The item's JID.
44        */
MUCListItem(const JID & jid)45       MUCListItem( const JID& jid )
46         : m_jid( jid ), m_affiliation( AffiliationInvalid ), m_role( RoleInvalid )
47       {}
48 
49       /**
50        * Creates a new object, setting JID, affiliation, role, and nick.
51        * @param jid The item's JID.
52        * @param role The item's role.
53        * @param affiliation The item's affiliation.
54        * @param nick The item's nick.
55        */
MUCListItem(const JID & jid,MUCRoomRole role,MUCRoomAffiliation affiliation,const std::string & nick)56       MUCListItem( const JID& jid, MUCRoomRole role, MUCRoomAffiliation affiliation,
57                    const std::string& nick )
58         : m_jid( jid ), m_nick( nick ), m_affiliation( affiliation ), m_role( role )
59       {}
60 
61       /**
62        * Creates a new object, using nick, affiliation and a reason.
63        * @param nick The item's nick.
64        * @param affiliation The item's affiliation.
65        * @param reason A reason.
66        */
MUCListItem(const std::string & nick,MUCRoomAffiliation affiliation,const std::string & reason)67       MUCListItem( const std::string& nick, MUCRoomAffiliation affiliation, const std::string& reason )
68         : m_nick( nick ), m_affiliation( affiliation ), m_role( RoleInvalid ),
69           m_reason( reason )
70       {}
71 
72       /**
73        * Creates a new object, using nick, role and a reason.
74        * @param nick The item's nick.
75        * @param role The item's role.
76        * @param reason A reason.
77        */
MUCListItem(const std::string & nick,MUCRoomRole role,const std::string & reason)78       MUCListItem( const std::string& nick, MUCRoomRole role, const std::string& reason )
79         : m_nick( nick ), m_affiliation( AffiliationInvalid ), m_role( role ),
80           m_reason( reason )
81       {}
82 
83       /**
84        * Destructor. Deletes the @c jid member.
85        */
~MUCListItem()86       ~MUCListItem() {}
87 
88       /**
89        * Returns the item's JID.
90        * @return The item's JID.
91        */
jid()92       const JID& jid() const { return m_jid; }
93 
94       /**
95        * Returns the item's nick.
96        * @return The item's nick.
97        */
nick()98       const std::string& nick() const { return m_nick; }
99 
100       /**
101        * Returns the item's affiliation.
102        * @return The item's affiliation.
103        */
affiliation()104       MUCRoomAffiliation affiliation() const { return m_affiliation; }
105 
106       /**
107        * Returns the item's role.
108        * @return The item's role.
109        */
role()110       MUCRoomRole role() const { return m_role; }
111 
112       /**
113        * Returns the reason.
114        * @return The reason.
115        */
reason()116       const std::string& reason() const { return m_reason; }
117 
118     private:
119       JID m_jid;                   /**< Pointer to the occupant's JID if available, 0 otherwise. */
120       std::string m_nick;           /**< The occupant's nick in the room. */
121       MUCRoomAffiliation m_affiliation; /**< The occupant's affiliation. */
122       MUCRoomRole m_role;           /**< The occupant's role. */
123       std::string m_reason;         /**< Use this only when **setting** the item's role/affiliation to
124                                      * specify a reason for the role/affiliation change. This field is
125                                      * empty in items fetched from the MUC service. */
126   };
127 
128   /**
129    * A list of MUCListItems.
130    */
131   typedef std::list<MUCListItem> MUCListItemList;
132 
133   /**
134    * Available operations on a room.
135    */
136   enum MUCOperation
137   {
138     RequestUniqueName,              /**< Request a unique room name. */
139     CreateInstantRoom,              /**< Create an instant room. */
140     CancelRoomCreation,             /**< Cancel room creation process. */
141     RequestRoomConfig,              /**< Request room configuration form. */
142     SendRoomConfig,                 /**< Send room configuration */
143     DestroyRoom,                    /**< Destroy room. */
144     GetRoomInfo,                    /**< Fetch room info. */
145     GetRoomItems,                   /**< Fetch room items (e.g., current occupants). */
146     SetRNone,                       /**< Set a user's role to None. */
147     SetVisitor,                     /**< Set a user's role to Visitor. */
148     SetParticipant,                 /**< Set a user's role to Participant. */
149     SetModerator,                   /**< Set a user's role to Moderator. */
150     SetANone,                       /**< Set a user's affiliation to None. */
151     SetOutcast,                     /**< Set a user's affiliation to Outcast. */
152     SetMember,                      /**< Set a user's affiliation to Member. */
153     SetAdmin,                       /**< Set a user's affiliation to Admin. */
154     SetOwner,                       /**< Set a user's affiliation to Owner. */
155     RequestVoiceList,               /**< Request the room's Voice List. */
156     StoreVoiceList,                 /**< Store the room's Voice List. */
157     RequestBanList,                 /**< Request the room's Ban List. */
158     StoreBanList,                   /**< Store the room's Ban List. */
159     RequestMemberList,              /**< Request the room's Member List. */
160     StoreMemberList,                /**< Store the room's Member List. */
161     RequestModeratorList,           /**< Request the room's Moderator List. */
162     StoreModeratorList,             /**< Store the room's Moderator List. */
163     RequestOwnerList,               /**< Request the room's Owner List. */
164     StoreOwnerList,                 /**< Store the room's Owner List. */
165     RequestAdminList,               /**< Request the room's Admin List. */
166     StoreAdminList,                 /**< Store the room's Admin List. */
167     InvalidOperation                /**< Invalid operation. */
168   };
169 
170   /**
171    * @brief An abstract interface that can be implemented for MUC room configuration.
172    *
173    * @author Jakob Schröter <js@camaya.net>
174    * @since 0.9
175    */
176   class GLOOX_API MUCRoomConfigHandler
177   {
178     public:
179       /**
180        * Virtual Destructor.
181        */
~MUCRoomConfigHandler()182       virtual ~MUCRoomConfigHandler() {}
183 
184       /**
185        * This function is called in response to MUCRoom::requestList() if the list was
186        * fetched successfully.
187        * @param room The room for which the list arrived.
188        * @param items The requestd list's items.
189        * @param operation The type of the list.
190        */
191       virtual void handleMUCConfigList( MUCRoom* room, const MUCListItemList& items,
192                                         MUCOperation operation ) = 0;
193 
194       /**
195        * This function is called when the room's configuration form arrives. This usually happens
196        * after a call to MUCRoom::requestRoomConfig(). Use
197        * MUCRoom::setRoomConfig() to send the configuration back to the
198        * room.
199        * @param room The room for which the config form arrived.
200        * @param form The configuration form.
201        */
202       virtual void handleMUCConfigForm( MUCRoom* room, const DataForm& form ) = 0;
203 
204       /**
205        * This function is called in response to MUCRoom::kick(), MUCRoom::storeList(),
206        * MUCRoom::ban(), and others, to indcate the end of the operation.
207        * @param room The room for which the operation ended.
208        * @param success Whether or not the operation was successful.
209        * @param operation The finished operation.
210        */
211       virtual void handleMUCConfigResult( MUCRoom* room, bool success, MUCOperation operation ) = 0;
212 
213       /**
214        * This function is called when a Voice request or a Registration request arrive through
215        * the room that need to be approved/rejected by the room admin. Use MUCRoom::createDataForm()
216        * to have a Tag created that answers the request.
217        * @param room The room the request arrived from.
218        * @param form A DataForm containing the request.
219        */
220       virtual void handleMUCRequest( MUCRoom* room, const DataForm& form ) = 0;
221 
222   };
223 
224 }
225 
226 #endif // MUCROOMCONFIGHANDLER_H__
227