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

Generated on Mon Dec 7 13:28:19 2009 for gloox by  doxygen 1.6.1