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 }
00031
00032 void UniqueMUCRoom::join()
00033 {
00034 if( !m_parent || m_joined )
00035 return;
00036
00037 const std::string& id = m_parent->getID();
00038 Tag *iq = new Tag( "iq" );
00039 iq->addAttribute( "id", id );
00040 iq->addAttribute( "to", m_nick.server() );
00041 iq->addAttribute( "type", "get" );
00042 Tag *u = new Tag( iq, "unique" );
00043 u->addAttribute( "xmlns", XMLNS_MUC_UNIQUE );
00044
00045 m_parent->trackID( this, id, RequestUniqueName );
00046 m_parent->send( iq );
00047 }
00048
00049 bool UniqueMUCRoom::handleIqID( Stanza *stanza, int context )
00050 {
00051 switch( stanza->subtype() )
00052 {
00053 case StanzaIqResult:
00054 if( context == RequestUniqueName )
00055 {
00056 Tag *u = stanza->findChild( "unique", "xmlns", XMLNS_MUC_UNIQUE );
00057 if( u )
00058 {
00059 const std::string& name = u->cdata();
00060 if( !name.empty() )
00061 setName( name );
00062 }
00063 }
00064 break;
00065 case StanzaIqError:
00066 if( context == RequestUniqueName )
00067 {
00068 SHA s;
00069 s.feed( m_parent->jid().full() );
00070 s.feed( m_parent->getID() );
00071 setName( s.hex() );
00072 }
00073 break;
00074 default:
00075 break;
00076 }
00077
00078 MUCRoom::join();
00079
00080 return false;
00081 }
00082
00083 }