uniquemucroom.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "uniquemucroom.h"
00016 #include "clientbase.h"
00017 #include "jid.h"
00018 #include "sha.h"
00019
00020 namespace gloox
00021 {
00022
00023 UniqueMUCRoom::UniqueMUCRoom( ClientBase *parent, const JID& nick, MUCRoomHandler *mrh )
00024 : InstantMUCRoom( parent, nick, mrh )
00025 {
00026 }
00027
00028 UniqueMUCRoom::~UniqueMUCRoom()
00029 {
00030 m_parent->removeIDHandler( this );
00031 }
00032
00033 void UniqueMUCRoom::join()
00034 {
00035 if( !m_parent || m_joined )
00036 return;
00037
00038 const std::string& id = m_parent->getID();
00039 Tag *iq = new Tag( "iq" );
00040 iq->addAttribute( "id", id );
00041 iq->addAttribute( "to", m_nick.server() );
00042 iq->addAttribute( "type", "get" );
00043 Tag *u = new Tag( iq, "unique" );
00044 u->addAttribute( "xmlns", XMLNS_MUC_UNIQUE );
00045
00046 m_parent->trackID( this, id, RequestUniqueName );
00047 m_parent->send( iq );
00048 }
00049
00050 bool UniqueMUCRoom::handleIqID( Stanza *stanza, int context )
00051 {
00052 switch( stanza->subtype() )
00053 {
00054 case StanzaIqResult:
00055 if( context == RequestUniqueName )
00056 {
00057 Tag *u = stanza->findChild( "unique", "xmlns", XMLNS_MUC_UNIQUE );
00058 if( u )
00059 {
00060 const std::string& name = u->cdata();
00061 if( !name.empty() )
00062 setName( name );
00063 }
00064 }
00065 break;
00066 case StanzaIqError:
00067 if( context == RequestUniqueName )
00068 {
00069 SHA s;
00070 s.feed( m_parent->jid().full() );
00071 s.feed( m_parent->getID() );
00072 setName( s.hex() );
00073 }
00074 break;
00075 default:
00076 break;
00077 }
00078
00079 MUCRoom::join();
00080
00081 return false;
00082 }
00083
00084 }