gloox
1.0
|
00001 /* 00002 Copyright (c) 2006-2009 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 "dataform.h" 00021 #include "presencehandler.h" 00022 #include "iqhandler.h" 00023 #include "messagehandler.h" 00024 #include "mucroomhandler.h" 00025 #include "mucroomconfighandler.h" 00026 #include "jid.h" 00027 #include "stanzaextension.h" 00028 00029 #include <string> 00030 00031 namespace gloox 00032 { 00033 00034 class ClientBase; 00035 class MUCMessageSession; 00036 class Message; 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 00110 enum MUCUserOperation 00111 { 00112 OpNone, 00113 OpInviteTo, 00114 OpInviteFrom, 00115 OpDeclineTo, 00116 OpDeclineFrom 00117 }; 00118 00127 class MUC : public StanzaExtension 00128 { 00129 public: 00137 MUC( const std::string& password, HistoryRequestType historyType = HistoryUnknown, 00138 const std::string& historySince = EmptyString, int historyValue = 0 ); 00139 00144 MUC( const Tag* tag = 0 ); 00145 00149 virtual ~MUC(); 00150 00155 const std::string* password() const { return m_password; } 00156 00161 const std::string* historySince() const { return m_historySince; } 00162 00163 // reimplemented from StanzaExtension 00164 virtual const std::string& filterString() const; 00165 00166 // reimplemented from StanzaExtension 00167 virtual StanzaExtension* newInstance( const Tag* tag ) const 00168 { 00169 return new MUC( tag ); 00170 } 00171 00172 // reimplemented from StanzaExtension 00173 virtual Tag* tag() const; 00174 00175 // reimplemented from StanzaExtension 00176 virtual StanzaExtension* clone() const 00177 { 00178 MUC* m = new MUC(); 00179 m->m_password = m_password ? new std::string( *m_password ) : 0; 00180 m->m_historySince = m_historySince ? new std::string( *m_historySince ) : 0; 00181 m->m_historyType = m_historyType; 00182 m->m_historyValue = m_historyValue; 00183 return m; 00184 } 00185 00186 private: 00187 std::string* m_password; 00188 std::string* m_historySince; 00189 HistoryRequestType m_historyType; 00190 int m_historyValue; 00191 }; 00192 00201 class MUCUser : public StanzaExtension 00202 { 00203 public: 00213 MUCUser( MUCUserOperation operation, const std::string& to, const std::string& reason, 00214 const std::string& thread = EmptyString ); 00215 00220 MUCUser( const Tag* tag = 0 ); 00221 00225 virtual ~MUCUser(); 00226 00231 int flags() const { return m_flags; } 00232 00237 MUCRoomAffiliation affiliation() const { return m_affiliation; } 00238 00243 MUCRoomRole role() const { return m_role; } 00244 00248 const std::string* jid() const { return m_jid; } 00249 00253 const std::string* actor() const { return m_actor; } 00254 00258 const std::string* password() const { return m_password; } 00259 00263 const std::string* thread() const { return m_thread; } 00264 00268 const std::string* reason() const { return m_reason; } 00269 00273 const std::string* newNick() const { return m_newNick; } 00274 00279 const std::string* alternate() const { return m_alternate; } 00280 00285 bool continued() const { return m_continue; } 00286 00291 MUCUserOperation operation() const { return m_operation; } 00292 00293 // reimplemented from StanzaExtension 00294 virtual const std::string& filterString() const; 00295 00296 // reimplemented from StanzaExtension 00297 virtual StanzaExtension* newInstance( const Tag* tag ) const 00298 { 00299 return new MUCUser( tag ); 00300 } 00301 00302 // reimplemented from StanzaExtension 00303 virtual Tag* tag() const; 00304 00305 // reimplemented from StanzaExtension 00306 virtual StanzaExtension* clone() const 00307 { 00308 MUCUser* m = new MUCUser(); 00309 m->m_affiliation = m_affiliation; 00310 m->m_role = m_role; 00311 m->m_jid = m_jid ? new std::string( *m_jid ) : 0; 00312 m->m_actor = m_actor ? new std::string( *m_actor ) : 0; 00313 m->m_thread = m_thread ? new std::string( *m_thread ) : 0; 00314 m->m_reason = m_reason ? new std::string( *m_reason ) : 0; 00315 m->m_newNick = m_newNick ? new std::string( *m_newNick ) : 0; 00316 m->m_password = m_password ? new std::string( *m_password ) : 0; 00317 m->m_alternate = m_alternate ? new std::string( *m_alternate ) : 0; 00318 m->m_operation = m_operation; 00319 m->m_flags = m_flags; 00320 m->m_del = m_del; 00321 m->m_continue = m_continue; 00322 return m; 00323 } 00324 00325 private: 00326 static MUCRoomAffiliation getEnumAffiliation( const std::string& affiliation ); 00327 static MUCRoomRole getEnumRole( const std::string& role ); 00328 00329 00330 MUCRoomAffiliation m_affiliation; 00331 MUCRoomRole m_role; 00332 std::string* m_jid; 00333 std::string* m_actor; 00334 std::string* m_thread; 00335 std::string* m_reason; 00336 std::string* m_newNick; 00337 std::string* m_password; 00338 std::string* m_alternate; 00339 MUCUserOperation m_operation; 00340 int m_flags; 00341 bool m_del; 00342 bool m_continue; 00343 }; 00344 00357 MUCRoom( ClientBase* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* mrch = 0 ); 00358 00362 virtual ~MUCRoom(); 00363 00370 void setPassword( const std::string& password ) { m_password = password; } 00371 00376 const std::string name() const { return m_nick.username(); } 00377 00383 const std::string service() const { return m_nick.server(); } 00384 00389 const std::string nick() const { return m_nick.resource(); } 00390 00399 virtual void join( Presence::PresenceType type = Presence::Available, 00400 const std::string& status = EmptyString, 00401 int priority = 0 ); 00402 00407 void leave( const std::string& msg = EmptyString ); 00408 00413 void send( const std::string& message ); 00414 00421 void setSubject( const std::string& subject ); 00422 00427 MUCRoomAffiliation affiliation() const { return m_affiliation; } 00428 00433 MUCRoomRole role() const { return m_role; } 00434 00441 void setNick( const std::string& nick ); 00442 00449 void setPresence( Presence::PresenceType presence, const std::string& msg = EmptyString ); 00450 00459 void invite( const JID& invitee, const std::string& reason, const std::string& thread = EmptyString ); 00460 00465 void getRoomInfo(); 00466 00473 void getRoomItems(); 00474 00484 void setPublish( bool publish, bool publishNick ); 00485 00491 void registerMUCRoomHandler( MUCRoomHandler* mrl ) { m_roomHandler = mrl; } 00492 00496 void removeMUCRoomHandler() { m_roomHandler = 0; } 00497 00503 void registerMUCRoomConfigHandler( MUCRoomConfigHandler* mrch ) { m_roomConfigHandler = mrch; } 00504 00508 void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; } 00509 00520 void addHistory( const std::string& message, const JID& from, const std::string& stamp ); 00521 00532 void setRequestHistory( int value, HistoryRequestType type ); 00533 00542 void setRequestHistory( const std::string& since ); 00543 00553 static Message* declineInvitation( const JID& room, const JID& invitor, 00554 const std::string& reason = EmptyString); 00555 00560 void requestVoice(); 00561 00570 void kick( const std::string& nick, const std::string& reason = EmptyString ) 00571 { setRole( nick, RoleNone, reason ); } 00572 00582 void ban( const std::string& nick, const std::string& reason ) 00583 { setAffiliation( nick, AffiliationOutcast, reason ); } 00584 00594 void grantVoice( const std::string& nick, const std::string& reason ) 00595 { setRole( nick, RoleParticipant, reason ); } 00596 00606 static Message* createDataForm( const JID& room, const DataForm* df ); 00607 00617 void revokeVoice( const std::string& nick, const std::string& reason ) 00618 { setRole( nick, RoleVisitor, reason ); } 00619 00627 void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = EmptyString ); 00628 00636 void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation, 00637 const std::string& reason ); 00638 00649 void requestRoomConfig(); 00650 00658 void setRoomConfig( DataForm* form ); 00659 00665 void acknowledgeInstantRoom() 00666 { instantRoom( CreateInstantRoom ); } 00667 00672 void cancelRoomCreation() 00673 { instantRoom( CancelRoomCreation ); } 00674 00684 void destroy( const std::string& reason = EmptyString, 00685 const JID& alternate = JID(), const std::string& password = EmptyString ); 00686 00700 void requestList( MUCOperation operation ); 00701 00726 void storeList( const MUCListItemList items, MUCOperation operation ); 00727 00732 int flags() const { return m_flags; } 00733 00734 // reimplemented from DiscoHandler 00735 virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context ); 00736 00737 // reimplemented from DiscoHandler 00738 // reimplemented from DiscoHandler 00739 virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context ); 00740 00741 // reimplemented from DiscoHandler 00742 virtual void handleDiscoError( const JID& from, const Error* error, int context ); 00743 00744 // reimplemented from PresenceHandler 00745 virtual void handlePresence( const Presence& presence ); 00746 00747 // reimplemented from MessageHandler 00748 virtual void handleMessage( const Message& msg, MessageSession* session = 0 ); 00749 00750 // reimplemented from IqHandler 00751 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; } 00752 00753 // reimplemented from IqHandler 00754 virtual void handleIqID( const IQ& iq, int context ); 00755 00756 // reimplemented from DiscoNodeHandler 00757 virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node ); 00758 00759 // reimplemented from DiscoNodeHandler 00760 virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from, 00761 const std::string& node ); 00762 00763 // reimplemented from DiscoNodeHandler 00764 virtual Disco::ItemList handleDiscoNodeItems( const JID& from, const JID& to, 00765 const std::string& node = EmptyString ); 00766 00767 protected: 00772 void setName( const std::string& name ) { m_nick.setUsername( name ); } 00773 00778 virtual bool instantRoomHook() const { return false; } 00779 00780 ClientBase* m_parent; 00781 JID m_nick; 00782 00783 bool m_joined; 00784 00785 private: 00786 #ifdef MUCROOM_TEST 00787 public: 00788 #endif 00789 00795 class MUCOwner : public StanzaExtension 00796 { 00797 public: 00798 00802 enum QueryType 00803 { 00804 TypeCreate, 00805 TypeRequestConfig, 00806 TypeSendConfig, 00807 TypeCancelConfig, 00808 TypeInstantRoom, 00809 TypeDestroy, 00810 TypeIncomingTag 00811 }; 00812 00819 MUCOwner( QueryType type, DataForm* form = 0 ); 00820 00827 MUCOwner( const JID& alternate = JID(), const std::string& reason = EmptyString, 00828 const std::string& password = EmptyString); 00829 00834 MUCOwner( const Tag* tag ); 00835 00839 virtual ~MUCOwner(); 00840 00845 const DataForm* form() const { return m_form; } 00846 00847 // reimplemented from StanzaExtension 00848 const std::string& filterString() const; 00849 00850 // reimplemented from StanzaExtension 00851 StanzaExtension* newInstance( const Tag* tag ) const 00852 { 00853 return new MUCOwner( tag ); 00854 } 00855 00856 // reimplemented from StanzaExtension 00857 Tag* tag() const; 00858 00859 // reimplemented from StanzaExtension 00860 virtual StanzaExtension* clone() const 00861 { 00862 MUCOwner* m = new MUCOwner(); 00863 m->m_type = m_type; 00864 m->m_jid = m_jid; 00865 m->m_reason = m_reason; 00866 m->m_pwd = m_pwd; 00867 m->m_form = m_form ? new DataForm( *m_form ) : 0; 00868 return m; 00869 } 00870 00871 private: 00872 QueryType m_type; 00873 JID m_jid; 00874 std::string m_reason; 00875 std::string m_pwd; 00876 DataForm* m_form; 00877 }; 00878 00885 class MUCAdmin : public StanzaExtension 00886 { 00887 public: 00894 MUCAdmin( MUCRoomRole role, const std::string& nick, 00895 const std::string& reason = EmptyString ); 00896 00903 MUCAdmin( MUCRoomAffiliation affiliation, const std::string& nick, 00904 const std::string& reason = EmptyString ); 00905 00915 MUCAdmin( MUCOperation operation, const MUCListItemList& jids = MUCListItemList() ); 00916 00921 MUCAdmin( const Tag* tag = 0 ); 00922 00926 virtual ~MUCAdmin(); 00927 00932 const MUCListItemList& list() const { return m_list; } 00933 00934 // reimplemented from StanzaExtension 00935 const std::string& filterString() const; 00936 00937 // reimplemented from StanzaExtension 00938 StanzaExtension* newInstance( const Tag* tag ) const 00939 { 00940 return new MUCAdmin( tag ); 00941 } 00942 00943 // reimplemented from StanzaExtension 00944 Tag* tag() const; 00945 00946 // reimplemented from StanzaExtension 00947 virtual StanzaExtension* clone() const 00948 { 00949 return new MUCAdmin( *this ); 00950 } 00951 00952 private: 00953 MUCListItemList m_list; 00954 MUCRoomAffiliation m_affiliation; 00955 MUCRoomRole m_role; 00956 }; 00957 00958 void handleIqResult( const IQ& iq, int context ); 00959 void handleIqError( const IQ& iq, int context ); 00960 void setNonAnonymous(); 00961 void setSemiAnonymous(); 00962 void setFullyAnonymous(); 00963 void acknowledgeRoomCreation(); 00964 void instantRoom( int context ); 00965 00966 MUCRoomHandler* m_roomHandler; 00967 MUCRoomConfigHandler* m_roomConfigHandler; 00968 MUCMessageSession* m_session; 00969 00970 typedef std::list<MUCRoomParticipant> ParticipantList; 00971 ParticipantList m_participants; 00972 00973 std::string m_password; 00974 std::string m_newNick; 00975 00976 MUCRoomAffiliation m_affiliation; 00977 MUCRoomRole m_role; 00978 00979 HistoryRequestType m_historyType; 00980 00981 std::string m_historySince; 00982 int m_historyValue; 00983 int m_flags; 00984 bool m_creationInProgress; 00985 bool m_configChanged; 00986 bool m_publishNick; 00987 bool m_publish; 00988 bool m_unique; 00989 00990 }; 00991 00992 } 00993 00994 #endif // MUCROOM_H__