uniquemucroom.cpp

00001 /*
00002   Copyright (c) 2007-2008 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 #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 }

Generated on Fri Oct 10 15:26:12 2008 for gloox by  doxygen 1.5.6