00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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 #include "stanzaextension.h"
00027
00028 #include <string>
00029
00030 namespace gloox
00031 {
00032
00033 class ClientBase;
00034 class MUCMessageSession;
00035 class Message;
00036 class DataForm;
00037
00085 class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler,
00086 public IqHandler, private MessageHandler, private DiscoNodeHandler
00087 {
00088 public:
00093 enum HistoryRequestType
00094 {
00095 HistoryMaxChars,
00098 HistoryMaxStanzas,
00099 HistorySeconds,
00100 HistorySince,
00103 HistoryUnknown
00105 };
00106
00119 MUCRoom( ClientBase* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* mrch = 0 );
00120
00124 virtual ~MUCRoom();
00125
00132 void setPassword( const std::string& password ) { m_password = password; }
00133
00138 const std::string name() const { return m_nick.username(); }
00139
00145 const std::string service() const { return m_nick.server(); }
00146
00151 const std::string nick() const { return m_nick.resource(); }
00152
00156 virtual void join();
00157
00162 void leave( const std::string& msg = EmptyString );
00163
00168 void send( const std::string& message );
00169
00176 void setSubject( const std::string& subject );
00177
00182 MUCRoomAffiliation affiliation() const { return m_affiliation; }
00183
00188 MUCRoomRole role() const { return m_role; }
00189
00196 void setNick( const std::string& nick );
00197
00204 void setPresence( Presence::PresenceType presence, const std::string& msg = EmptyString );
00205
00214 void invite( const JID& invitee, const std::string& reason, const std::string& thread = EmptyString );
00215
00220 void getRoomInfo();
00221
00228 void getRoomItems();
00229
00239 void setPublish( bool publish, bool publishNick );
00240
00246 void registerMUCRoomHandler( MUCRoomHandler* mrl ) { m_roomHandler = mrl; }
00247
00251 void removeMUCRoomHandler() { m_roomHandler = 0; }
00252
00258 void registerMUCRoomConfigHandler( MUCRoomConfigHandler* mrch ) { m_roomConfigHandler = mrch; }
00259
00263 void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; }
00264
00275 void addHistory( const std::string& message, const JID& from, const std::string& stamp );
00276
00287 void setRequestHistory( int value, HistoryRequestType type );
00288
00297 void setRequestHistory( const std::string& since );
00298
00307 static Message* declineInvitation( const JID& room, const JID& invitor,
00308 const std::string& reason = EmptyString);
00309
00314 void requestVoice();
00315
00324 void kick( const std::string& nick, const std::string& reason = EmptyString )
00325 { setRole( nick, RoleNone, reason ); }
00326
00336 void ban( const std::string& nick, const std::string& reason )
00337 { setAffiliation( nick, AffiliationOutcast, reason ); }
00338
00348 void grantVoice( const std::string& nick, const std::string& reason )
00349 { setRole( nick, RoleParticipant, reason ); }
00350
00360 static Message* createDataForm( const JID& room, const DataForm* df );
00361
00371 void revokeVoice( const std::string& nick, const std::string& reason )
00372 { setRole( nick, RoleVisitor, reason ); }
00373
00381 void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = EmptyString );
00382
00390 void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation,
00391 const std::string& reason );
00392
00400 void requestRoomConfig();
00401
00407 void acknowledgeInstantRoom()
00408 { instantRoom( CreateInstantRoom ); }
00409
00414 void cancelRoomCreation()
00415 { instantRoom( CancelRoomCreation ); }
00416
00426 void destroy( const std::string& reason = EmptyString,
00427 const JID& alternate = JID(), const std::string& password = EmptyString );
00428
00442 void requestList( MUCOperation operation );
00443
00468 void storeList( const MUCListItemList items, MUCOperation operation );
00469
00474 int flags() const { return m_flags; }
00475
00476
00477 virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
00478
00479
00480
00481 virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
00482
00483
00484 virtual void handleDiscoError( const JID& from, const Error* error, int context );
00485
00486
00487 virtual void handlePresence( const Presence& presence );
00488
00489
00490 virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
00491
00492
00493 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
00494
00495
00496 virtual void handleIqID( const IQ& iq, int context );
00497
00498
00499 virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node );
00500
00501
00502 virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from,
00503 const std::string& node );
00504
00505
00506 virtual Disco::ItemList handleDiscoNodeItems( const JID& from,
00507 const std::string& node = EmptyString );
00508
00509 protected:
00510 void setName( const std::string& name ) { m_nick.setUsername( name ); }
00511 virtual bool instantRoomHook() const { return false; }
00512
00513 ClientBase* m_parent;
00514 JID m_nick;
00515
00516 bool m_joined;
00517
00518 private:
00519 #ifdef MUCROOM_TEST
00520 public:
00521 #endif
00522
00528 class MUCOwner : public StanzaExtension
00529 {
00530 public:
00531
00535 enum QueryType
00536 {
00537 TypeCreate,
00538 TypeRequestConfig,
00539 TypeSendConfig,
00540 TypeCancelConfig,
00541 TypeInstantRoom,
00542 TypeDestroy,
00543 TypeIncomingTag
00544 };
00545
00552 MUCOwner( QueryType type, DataForm* form = 0 );
00553
00560 MUCOwner( const JID& alternate, const std::string& reason, const std::string& password );
00561
00566 MUCOwner( const Tag* tag = 0 );
00567
00571 virtual ~MUCOwner();
00572
00577 const DataForm* form() const { return m_form; }
00578
00579
00580 const std::string& filterString() const;
00581
00582
00583 StanzaExtension* newInstance( const Tag* tag ) const
00584 {
00585 return new MUCOwner( tag );
00586 }
00587
00588
00589 Tag* tag() const;
00590
00591 private:
00592 QueryType m_type;
00593 JID m_jid;
00594 std::string m_reason;
00595 std::string m_pwd;
00596 DataForm* m_form;
00597 };
00598
00605 class MUCAdmin : public StanzaExtension
00606 {
00607 public:
00614 MUCAdmin( MUCRoomRole role, const std::string& nick,
00615 const std::string& reason = EmptyString );
00616
00623 MUCAdmin( MUCRoomAffiliation affiliation, const std::string& nick,
00624 const std::string& reason = EmptyString );
00625
00635 MUCAdmin( MUCOperation operation, const MUCListItemList& jids = MUCListItemList() );
00636
00641 MUCAdmin( const Tag* tag = 0 );
00642
00646 virtual ~MUCAdmin();
00647
00652 const MUCListItemList& list() const { return m_list; }
00653
00654
00655 const std::string& filterString() const;
00656
00657
00658 StanzaExtension* newInstance( const Tag* tag ) const
00659 {
00660 return new MUCAdmin( tag );
00661 }
00662
00663
00664 Tag* tag() const;
00665
00666 private:
00667 MUCListItemList m_list;
00668 MUCRoomAffiliation m_affiliation;
00669 MUCRoomRole m_role;
00670 };
00671
00678 class MUCUser : public StanzaExtension
00679 {
00680 public:
00681
00685 enum MUCUserOperation
00686 {
00687 OpNone,
00688 OpInvite,
00689 OpDecline
00690 };
00691
00695 MUCUser( const std::string& password, HistoryRequestType historyType = HistoryUnknown,
00696 const std::string& historySince = EmptyString, int historyValue = 0 );
00697
00701 MUCUser( MUCUserOperation operation, const std::string& to, const std::string& reason,
00702 const std::string& thread = EmptyString );
00703
00708 MUCUser( const Tag* tag = 0 );
00709
00713 virtual ~MUCUser();
00714
00718 int flags() const { return m_flags; }
00719
00723 static MUCRoomAffiliation getEnumAffiliation( const std::string& affiliation );
00724
00728 static MUCRoomRole getEnumRole( const std::string& role );
00729
00733 MUCRoomAffiliation affiliation() const { return m_affiliation; }
00734
00738 MUCRoomRole role() const { return m_role; }
00739
00743 const std::string* jid() const { return m_jid; }
00744
00748 const std::string* actor() const { return m_actor; }
00749
00753 const std::string* thread() const { return m_thread; }
00754
00758 const std::string* reason() const { return m_reason; }
00759
00763 const std::string* newNick() const { return m_newNick; }
00764
00768 const std::string* password() const { return m_password; }
00769
00773 const std::string* alternate() const { return m_alternate; }
00774
00778 const std::string* historySince() const { return m_historySince; }
00779
00783 MUCUserOperation operation() const { return m_operation; }
00784
00785
00786 const std::string& filterString() const;
00787
00788
00789 StanzaExtension* newInstance( const Tag* tag ) const
00790 {
00791 return new MUCUser( tag );
00792 }
00793
00794
00795 Tag* tag() const;
00796
00797 private:
00798 MUCRoomAffiliation m_affiliation;
00799 MUCRoomRole m_role;
00800 std::string* m_jid;
00801 std::string* m_actor;
00802 std::string* m_thread;
00803 std::string* m_reason;
00804 std::string* m_newNick;
00805 std::string* m_password;
00806 std::string* m_alternate;
00807 std::string* m_historySince;
00808 MUCUserOperation m_operation;
00809 HistoryRequestType m_historyType;
00810 int m_historyValue;
00811 int m_flags;
00812 bool m_del;
00813 };
00814
00815 void handleIqResult( const IQ& iq, int context );
00816 void handleIqError( const IQ& iq, int context );
00817 void setNonAnonymous();
00818 void setSemiAnonymous();
00819 void setFullyAnonymous();
00820 void acknowledgeRoomCreation();
00821 void instantRoom( int context );
00822
00823 MUCRoomHandler* m_roomHandler;
00824 MUCRoomConfigHandler* m_roomConfigHandler;
00825 MUCMessageSession* m_session;
00826
00827 typedef std::list<MUCRoomParticipant> ParticipantList;
00828 ParticipantList m_participants;
00829
00830 std::string m_password;
00831 std::string m_newNick;
00832
00833 MUCRoomAffiliation m_affiliation;
00834 MUCRoomRole m_role;
00835
00836 HistoryRequestType m_historyType;
00837
00838 std::string m_historySince;
00839 int m_historyValue;
00840 int m_flags;
00841 bool m_creationInProgress;
00842 bool m_configChanged;
00843 bool m_publishNick;
00844 bool m_publish;
00845 bool m_unique;
00846
00847 };
00848
00849 }
00850
00851 #endif // MUCROOM_H__