delayeddelivery.cpp

00001 /*
00002   Copyright (c) 2006-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 #include "delayeddelivery.h"
00015 
00016 #include "tag.h"
00017 
00018 namespace gloox
00019 {
00020 
00021   DelayedDelivery::DelayedDelivery( const JID& from, const std::string stamp, const std::string& reason )
00022     : StanzaExtension( ExtDelay ), m_from( from ), m_stamp( stamp ), m_reason( reason ), m_valid( false )
00023   {
00024     if( !m_stamp.empty() )
00025       m_valid = true;
00026   }
00027 
00028 
00029   DelayedDelivery::DelayedDelivery( Tag *tag )
00030     : StanzaExtension( ExtDelay ), m_valid( false )
00031   {
00032     if( !tag || tag->name() != "delay" || !tag->hasAttribute( "xmlns", XMLNS_DELAY )
00033          || !tag->hasAttribute( "stamp" ) )
00034       return;
00035 
00036     m_reason = tag->cdata();
00037     m_stamp = tag->findAttribute( "stamp" );
00038     m_from = tag->findAttribute( "from" );
00039     m_valid = true;
00040   }
00041 
00042   DelayedDelivery::~DelayedDelivery()
00043   {
00044   }
00045 
00046   Tag* DelayedDelivery::tag() const
00047   {
00048     if( !m_valid )
00049       return 0;
00050 
00051     Tag *t = new Tag( "delay" );
00052     t->addAttribute( "xmlns", XMLNS_DELAY );
00053     if( m_from )
00054       t->addAttribute( "from", m_from.full() );
00055     if( !m_stamp.empty() )
00056       t->addAttribute( "stamp", m_stamp );
00057     if( !m_reason.empty() )
00058       t->setCData( m_reason );
00059     return t;
00060   }
00061 
00062 }

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