mucroom.h

00001 /*
00002   Copyright (c) 2006-2007 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 
00015 #ifndef MUCROOM_H__
00016 #define MUCROOM_H__
00017 
00018 #include "discohandler.h"
00019 #include "disconodehandler.h"
00020 #include "presencehandler.h"
00021 #include "iqhandler.h"
00022 #include "messagehandler.h"
00023 #include "mucroomhandler.h"
00024 #include "mucroomconfighandler.h"
00025 #include "jid.h"
00026 
00027 #include <string>
00028 
00029 namespace gloox
00030 {
00031 
00032   class ClientBase;
00033   class MUCMessageSession;
00034   class Stanza;
00035 
00083   class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler,
00084                             public IqHandler, private MessageHandler, private DiscoNodeHandler
00085   {
00086     public:
00091       enum HistoryRequestType
00092       {
00093         HistoryUnknown,             
00095         HistoryMaxChars,            
00098         HistoryMaxStanzas,          
00099         HistorySeconds,             
00100         HistorySince                
00103       };
00104 
00117       MUCRoom( ClientBase *parent, const JID& nick, MUCRoomHandler *mrh, MUCRoomConfigHandler *mrch = 0 );
00118 
00122       virtual ~MUCRoom();
00123 
00130       void setPassword( const std::string& password ) { m_password = password; }
00131 
00136       const std::string name() const { return m_nick.username(); }
00137 
00143       const std::string service() const { return m_nick.server(); }
00144 
00149       const std::string nick() const { return m_nick.resource(); }
00150 
00154       virtual void join();
00155 
00160       void leave( const std::string& msg = "" );
00161 
00166       void send( const std::string& message );
00167 
00174       void setSubject( const std::string& subject );
00175 
00180       MUCRoomAffiliation affiliation() const { return m_affiliation; }
00181 
00186       MUCRoomRole role() const { return m_role; }
00187 
00194       void setNick( const std::string& nick );
00195 
00202       void setPresence( Presence presence, const std::string& msg = "" );
00203 
00211       void invite( const JID& invitee, const std::string& reason, bool cont = false );
00212 
00217       void getRoomInfo();
00218 
00225       void getRoomItems();
00226 
00236       void setPublish( bool publish, bool publishNick );
00237 
00243       void registerMUCRoomHandler( MUCRoomHandler *mrl ) { m_roomHandler = mrl; }
00244 
00248       void removeMUCRoomHandler() { m_roomHandler = 0; }
00249 
00255       void registerMUCRoomConfigHandler( MUCRoomConfigHandler *mrch ) { m_roomConfigHandler = mrch; }
00256 
00260       void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; }
00261 
00272       void addHistory( const std::string& message, const JID& from, const std::string& stamp );
00273 
00284       void setRequestHistory( int value, HistoryRequestType type );
00285 
00294       void setRequestHistory( const std::string& since );
00295 
00303       static Stanza* declineInvitation( const JID& room, const JID& invitor,
00304                                         const std::string& reason = "");
00305 
00310       void requestVoice();
00311 
00320       void kick( const std::string& nick, const std::string& reason = "" );
00321 
00331       void ban( const std::string& nick, const std::string& reason );
00332 
00342       void grantVoice( const std::string& nick, const std::string& reason );
00343 
00352       static Stanza* createDataForm( const JID& room, const DataForm& df );
00353 
00363       void revokeVoice( const std::string& nick, const std::string& reason );
00364 
00372       void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = "" );
00373 
00381       void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation,
00382                            const std::string& reason );
00383 
00391       void requestRoomConfig();
00392 
00398       void acknowledgeInstantRoom();
00399 
00404       void cancelRoomCreation();
00405 
00415       void destroy( const std::string& reason = "",
00416                     const JID* alternate = 0, const std::string& password = "" );
00417 
00431       void requestList( MUCOperation operation );
00432 
00457       void storeList( const MUCListItemList items, MUCOperation operation );
00458 
00463       int flags() const { return m_flags; }
00464 
00465       // reimplemented from DiscoHandler
00466       virtual void handleDiscoInfoResult( Stanza *stanza, int context );
00467 
00468       // reimplemented from DiscoHandler
00469       virtual void handleDiscoItemsResult( Stanza *stanza, int context );
00470 
00471       // reimplemented from DiscoHandler
00472       virtual void handleDiscoError( Stanza *stanza, int context );
00473 
00474       // reimplemented from PresenceHandler
00475       virtual void handlePresence( Stanza *stanza );
00476 
00477       // reimplemented from MessageHandler
00478       virtual void handleMessage( Stanza *stanza, MessageSession *session = 0 );
00479 
00480       // reimplemented from IqHandler
00481       virtual bool handleIq( Stanza* /*stanza*/ ) { return false; }
00482 
00483       // reimplemented from IqHandler
00484       virtual bool handleIqID( Stanza *stanza, int context );
00485 
00486       // reimplemented from DiscoNodeHandler
00487       virtual StringList handleDiscoNodeFeatures( const std::string& node );
00488 
00489       // reimplemented from DiscoNodeHandler
00490       virtual StringMap handleDiscoNodeIdentities( const std::string& node, std::string& name );
00491 
00492       // reimplemented from DiscoNodeHandler
00493       virtual DiscoNodeItemList handleDiscoNodeItems( const std::string& node = "" );
00494 
00495     protected:
00496       void setName( const std::string& name ) { m_nick.setUsername( name ); }
00497       virtual bool instantRoomHook() const { return false; }
00498 
00499       ClientBase *m_parent;
00500       JID m_nick;
00501 
00502       bool m_joined;
00503 
00504     private:
00505       bool handleIqResult( Stanza *stanza, int context );
00506       bool handleIqError( Stanza *stanza, int context );
00507       void setNonAnonymous();
00508       void setSemiAnonymous();
00509       void setFullyAnonymous();
00510       void modifyOccupant( const std::string& nick, int state, const std::string roa,
00511                            const std::string& reason );
00512       void acknowledgeRoomCreation();
00513       MUCRoomAffiliation getEnumAffiliation( const std::string& affiliation );
00514       MUCRoomRole getEnumRole( const std::string& role );
00515 
00516       MUCRoomHandler *m_roomHandler;
00517       MUCRoomConfigHandler *m_roomConfigHandler;
00518       MUCMessageSession *m_session;
00519 
00520       typedef std::list<MUCRoomParticipant> ParticipantList;
00521       ParticipantList m_participants;
00522 
00523       std::string m_password;
00524       std::string m_newNick;
00525 
00526       MUCRoomAffiliation m_affiliation;
00527       MUCRoomRole m_role;
00528 
00529       HistoryRequestType m_historyType;
00530 
00531       std::string m_historySince;
00532       int m_historyValue;
00533       int m_flags;
00534       bool m_creationInProgress;
00535       bool m_configChanged;
00536       bool m_publishNick;
00537       bool m_publish;
00538       bool m_unique;
00539 
00540   };
00541 
00542 }
00543 
00544 #endif // MUCROOM_H__

Generated on Sat Nov 10 08:50:27 2007 for gloox by  doxygen 1.5.3-20071008