gloox  0.9.9.12
mucroom.h
1 /*
2  Copyright (c) 2006-2008 by Jakob Schroeter <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 "presencehandler.h"
21 #include "iqhandler.h"
22 #include "messagehandler.h"
23 #include "mucroomhandler.h"
24 #include "mucroomconfighandler.h"
25 #include "jid.h"
26 
27 #include <string>
28 
29 namespace gloox
30 {
31 
32  class ClientBase;
33  class MUCMessageSession;
34  class Stanza;
35 
83  class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler,
84  public IqHandler, private MessageHandler, private DiscoNodeHandler
85  {
86  public:
92  {
93  HistoryUnknown,
95  HistoryMaxChars,
100  HistorySince
103  };
104 
117  MUCRoom( ClientBase *parent, const JID& nick, MUCRoomHandler *mrh, MUCRoomConfigHandler *mrch = 0 );
118 
122  virtual ~MUCRoom();
123 
130  void setPassword( const std::string& password ) { m_password = password; }
131 
136  const std::string name() const { return m_nick.username(); }
137 
143  const std::string service() const { return m_nick.server(); }
144 
149  const std::string nick() const { return m_nick.resource(); }
150 
154  virtual void join();
155 
160  void leave( const std::string& msg = "" );
161 
166  void send( const std::string& message );
167 
174  void setSubject( const std::string& subject );
175 
180  MUCRoomAffiliation affiliation() const { return m_affiliation; }
181 
186  MUCRoomRole role() const { return m_role; }
187 
194  void setNick( const std::string& nick );
195 
202  void setPresence( Presence presence, const std::string& msg = "" );
203 
211  void invite( const JID& invitee, const std::string& reason, bool cont = false );
212 
217  void getRoomInfo();
218 
225  void getRoomItems();
226 
236  void setPublish( bool publish, bool publishNick );
237 
243  void registerMUCRoomHandler( MUCRoomHandler *mrl ) { m_roomHandler = mrl; }
244 
248  void removeMUCRoomHandler() { m_roomHandler = 0; }
249 
255  void registerMUCRoomConfigHandler( MUCRoomConfigHandler *mrch ) { m_roomConfigHandler = mrch; }
256 
260  void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; }
261 
272  void addHistory( const std::string& message, const JID& from, const std::string& stamp );
273 
284  void setRequestHistory( int value, HistoryRequestType type );
285 
294  void setRequestHistory( const std::string& since );
295 
303  static Stanza* declineInvitation( const JID& room, const JID& invitor,
304  const std::string& reason = "");
305 
310  void requestVoice();
311 
320  void kick( const std::string& nick, const std::string& reason = "" );
321 
331  void ban( const std::string& nick, const std::string& reason );
332 
342  void grantVoice( const std::string& nick, const std::string& reason );
343 
352  static Stanza* createDataForm( const JID& room, const DataForm& df );
353 
363  void revokeVoice( const std::string& nick, const std::string& reason );
364 
372  void setRole( const std::string& nick, MUCRoomRole role, const std::string& reason = "" );
373 
381  void setAffiliation( const std::string& nick, MUCRoomAffiliation affiliation,
382  const std::string& reason );
383 
391  void requestRoomConfig();
392 
400  void setRoomConfig( DataForm* form );
401 
407  void acknowledgeInstantRoom();
408 
413  void cancelRoomCreation();
414 
424  void destroy( const std::string& reason = "",
425  const JID* alternate = 0, const std::string& password = "" );
426 
440  void requestList( MUCOperation operation );
441 
466  void storeList( const MUCListItemList items, MUCOperation operation );
467 
472  int flags() const { return m_flags; }
473 
474  // reimplemented from DiscoHandler
475  virtual void handleDiscoInfoResult( Stanza *stanza, int context );
476 
477  // reimplemented from DiscoHandler
478  virtual void handleDiscoItemsResult( Stanza *stanza, int context );
479 
480  // reimplemented from DiscoHandler
481  virtual void handleDiscoError( Stanza *stanza, int context );
482 
483  // reimplemented from PresenceHandler
484  virtual void handlePresence( Stanza *stanza );
485 
486  // reimplemented from MessageHandler
487  virtual void handleMessage( Stanza *stanza, MessageSession *session = 0 );
488 
489  // reimplemented from IqHandler
490  virtual bool handleIq( Stanza* /*stanza*/ ) { return false; }
491 
492  // reimplemented from IqHandler
493  virtual bool handleIqID( Stanza *stanza, int context );
494 
495  // reimplemented from DiscoNodeHandler
496  virtual StringList handleDiscoNodeFeatures( const std::string& node );
497 
498  // reimplemented from DiscoNodeHandler
499  virtual StringMap handleDiscoNodeIdentities( const std::string& node, std::string& name );
500 
501  // reimplemented from DiscoNodeHandler
502  virtual DiscoNodeItemList handleDiscoNodeItems( const std::string& node = "" );
503 
504  protected:
505  void setName( const std::string& name ) { m_nick.setUsername( name ); }
506  virtual bool instantRoomHook() const { return false; }
507 
508  ClientBase *m_parent;
509  JID m_nick;
510 
511  bool m_joined;
512 
513  private:
514  bool handleIqResult( Stanza *stanza, int context );
515  bool handleIqError( Stanza *stanza, int context );
516  void setNonAnonymous();
517  void setSemiAnonymous();
518  void setFullyAnonymous();
519  void modifyOccupant( const std::string& nick, int state, const std::string roa,
520  const std::string& reason );
521  void acknowledgeRoomCreation();
522  MUCRoomAffiliation getEnumAffiliation( const std::string& affiliation );
523  MUCRoomRole getEnumRole( const std::string& role );
524 
525  MUCRoomHandler *m_roomHandler;
526  MUCRoomConfigHandler *m_roomConfigHandler;
527  MUCMessageSession *m_session;
528 
529  typedef std::list<MUCRoomParticipant> ParticipantList;
530  ParticipantList m_participants;
531 
532  std::string m_password;
533  std::string m_newNick;
534 
535  MUCRoomAffiliation m_affiliation;
536  MUCRoomRole m_role;
537 
538  HistoryRequestType m_historyType;
539 
540  std::string m_historySince;
541  int m_historyValue;
542  int m_flags;
543  bool m_creationInProgress;
544  bool m_configChanged;
545  bool m_publishNick;
546  bool m_publish;
547  bool m_unique;
548 
549  };
550 
551 }
552 
553 #endif // MUCROOM_H__