uniquemucroom.cpp

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

Generated on Sat Nov 10 08:50:27 2007 for gloox by  doxygen 1.5.3-20071008