jingleiceudp.cpp
/*
Copyright (c) 2013-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "jingleiceudp.h"
#include "tag.h"
#include "gloox.h"
namespace gloox
{
namespace Jingle
{
static const char* typeValues [] = {
"host",
"prflx",
"relay",
"srflx"
};
ICEUDP::ICEUDP( const std::string& pwd, const std::string& ufrag, CandidateList& candidates )
: Plugin( PluginICEUDP ), m_pwd( pwd ), m_ufrag( ufrag), m_candidates( candidates )
{
}
ICEUDP::ICEUDP( const Tag* tag )
: Plugin( PluginICEUDP )
{
if( !tag || tag->name() != "transport" || tag->xmlns() != XMLNS_JINGLE_ICE_UDP )
return;
m_pwd = tag->findAttribute( "pwd" );
m_ufrag = tag->findAttribute( "ufrag" );
const TagList candidates = tag->findChildren( "candidate" );
TagList::const_iterator it = candidates.begin();
for( ; it != candidates.end(); ++it )
{
Candidate c;
c.component = (*it)->findAttribute( "component" );
c.foundation = (*it)->findAttribute( "foundation" );
c.generation = (*it)->findAttribute( "generation" );
c.id = (*it)->findAttribute( "id" );
c.ip = (*it)->findAttribute( "ip" );
c.network = (*it)->findAttribute( "network" );
c.port = atoi( (*it)->findAttribute( "port" ).c_str() );
c.priority = atoi( (*it)->findAttribute( "priority" ).c_str() );
c.protocol = (*it)->findAttribute( "protocol" );
c.rel_addr = (*it)->findAttribute( "rel-addr" );
c.rel_port = atoi( (*it)->findAttribute( "rel-port" ).c_str() );
c.type = static_cast<Type>( util::lookup( (*it)->findAttribute( "type" ), typeValues ) );
m_candidates.push_back( c );
}
}
const StringList ICEUDP::features() const
{
StringList sl;
sl.push_back( XMLNS_JINGLE_ICE_UDP );
return sl;
}
const std::string& ICEUDP::filterString() const
{
static const std::string filter = "content/transport[@xmlns='" + XMLNS_JINGLE_ICE_UDP + "']";
return filter;
}
Plugin* ICEUDP::newInstance( const Tag* tag ) const
{
return new ICEUDP( tag );
}
Tag* ICEUDP::tag() const
{
Tag* t = new Tag( "transport", XMLNS, XMLNS_JINGLE_ICE_UDP );
t->addAttribute( "pwd", m_pwd );
t->addAttribute( "ufrag", m_ufrag );
CandidateList::const_iterator it = m_candidates.begin();
for( ; it != m_candidates.end(); ++it )
{
Tag* c = new Tag( t, "candidate" );
c->addAttribute( "component", (*it).component );
c->addAttribute( "foundation", (*it).foundation );
c->addAttribute( "generation", (*it).generation );
c->addAttribute( "id", (*it).id );
c->addAttribute( "ip", (*it).ip );
c->addAttribute( "network", (*it).network );
c->addAttribute( "port", (*it).port );
c->addAttribute( "priority", (*it).priority );
c->addAttribute( "protocol", (*it).protocol );
c->addAttribute( "rel-addr", (*it).rel_addr );
c->addAttribute( "rel-port", (*it).rel_port );
c->addAttribute( "type", util::lookup( (*it).type, typeValues ) );
}
return t;
}
}
}
gloox::Jingle::ICEUDP::pwd
const std::string & pwd() const
Definition jingleiceudp.h:98
gloox::Jingle::ICEUDP::ufrag
const std::string & ufrag() const
Definition jingleiceudp.h:104
gloox::Jingle::ICEUDP::ICEUDP
ICEUDP(const std::string &pwd, const std::string &ufrag, CandidateList &candidates)
Definition jingleiceudp.cpp:32
gloox::Jingle::ICEUDP::newInstance
virtual Plugin * newInstance(const Tag *tag) const
Definition jingleiceudp.cpp:79
gloox::Jingle::ICEUDP::candidates
const CandidateList & candidates() const
Definition jingleiceudp.h:110
gloox::Jingle::ICEUDP::features
virtual const StringList features() const
Definition jingleiceudp.cpp:66
gloox::Jingle::ICEUDP::filterString
virtual const std::string & filterString() const
Definition jingleiceudp.cpp:73
gloox::Jingle::ICEUDP::CandidateList
std::list< Candidate > CandidateList
Definition jingleiceudp.h:73
gloox::Jingle::ICEUDP::tag
virtual Tag * tag() const
Definition jingleiceudp.cpp:84
gloox::Jingle::Plugin::Plugin
Plugin(JinglePluginType type)
Definition jingleplugin.h:76
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
gloox::Jingle
The namespace containing Jingle-related (XEP-0166 et. al.) classes.
Definition jinglecontent.cpp:22
gloox::Jingle::PluginICEUDP
@ PluginICEUDP
Definition jingleplugin.h:42
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::TagList
std::list< Tag * > TagList
Definition tag.h:31
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::XMLNS_JINGLE_ICE_UDP
const std::string XMLNS_JINGLE_ICE_UDP
Definition gloox.cpp:103