gloox 1.0

gpgsigned.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 "gpgsigned.h"
00015 #include "tag.h"
00016 
00017 namespace gloox
00018 {
00019 
00020   GPGSigned::GPGSigned( const std::string& signature )
00021     : StanzaExtension( ExtGPGSigned ),
00022       m_signature( signature ), m_valid( true )
00023   {
00024     if( m_signature.empty() )
00025       m_valid = false;
00026   }
00027 
00028   GPGSigned::GPGSigned( const Tag* tag )
00029     : StanzaExtension( ExtGPGSigned ),
00030       m_valid( false )
00031   {
00032     if( tag && tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_GPGSIGNED ) )
00033     {
00034       m_valid = true;
00035       m_signature = tag->cdata();
00036     }
00037   }
00038 
00039   GPGSigned::~GPGSigned()
00040   {
00041   }
00042 
00043   const std::string& GPGSigned::filterString() const
00044   {
00045     static const std::string filter =
00046            "/presence/x[@xmlns='" + XMLNS_X_GPGSIGNED + "']"
00047            "|/message/x[@xmlns='" + XMLNS_X_GPGSIGNED + "']";
00048     return filter;
00049   }
00050 
00051   Tag* GPGSigned::tag() const
00052   {
00053     if( !m_valid )
00054       return 0;
00055 
00056     Tag* x = new Tag( "x", m_signature );
00057     x->addAttribute( XMLNS, XMLNS_X_GPGSIGNED );
00058 
00059     return x;
00060   }
00061 
00062 }