delayeddelivery.cpp

00001 /*
00002   Copyright (c) 2006-2009 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( const Tag* tag )
00030     : StanzaExtension( ExtDelay ), m_valid( false )
00031   {
00032     if( !tag || !tag->hasAttribute( "stamp" ) )
00033       return;
00034     if( !( tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_DELAY ) ) )
00035       if( !( tag->name() == "delay" && tag->hasAttribute( XMLNS, XMLNS_DELAY ) ) )
00036         return;
00037 
00038     m_reason = tag->cdata();
00039     m_stamp = tag->findAttribute( "stamp" );
00040     m_from = tag->findAttribute( "from" );
00041     m_valid = true;
00042   }
00043 
00044   DelayedDelivery::~DelayedDelivery()
00045   {
00046   }
00047 
00048   const std::string& DelayedDelivery::filterString() const
00049   {
00050     static const std::string filter =
00051            "/presence/delay[@xmlns='" + XMLNS_DELAY + "']"
00052            "|/message/delay[@xmlns='" + XMLNS_DELAY + "']"
00053            "|/presence/x[@xmlns='" + XMLNS_X_DELAY + "']"
00054            "|/message/x[@xmlns='" + XMLNS_X_DELAY + "']";
00055     return filter;
00056   }
00057 
00058   Tag* DelayedDelivery::tag() const
00059   {
00060     if( !m_valid )
00061       return 0;
00062 
00063     Tag* t = new Tag( "delay" );
00064     t->addAttribute( XMLNS, XMLNS_DELAY );
00065     if( m_from )
00066       t->addAttribute( "from", m_from.full() );
00067     if( !m_stamp.empty() )
00068       t->addAttribute( "stamp", m_stamp );
00069     if( !m_reason.empty() )
00070       t->setCData( m_reason );
00071     return t;
00072   }
00073 
00074 }
Generated on Tue Jun 8 23:37:53 2010 for gloox by  doxygen 1.6.3