gloox  1.0.28
jingleiceudp.cpp
1 /*
2  Copyright (c) 2013-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #include "jingleiceudp.h"
15 
16 #include "tag.h"
17 #include "gloox.h"
18 
19 namespace gloox
20 {
21 
22  namespace Jingle
23  {
24 
25  static const char* typeValues [] = {
26  "host",
27  "prflx",
28  "relay",
29  "srflx"
30  };
31 
32  ICEUDP::ICEUDP( const std::string& pwd, const std::string& ufrag, CandidateList& candidates )
33  : Plugin( PluginICEUDP ), m_pwd( pwd ), m_ufrag( ufrag), m_candidates( candidates )
34  {
35  }
36 
37  ICEUDP::ICEUDP( const Tag* tag )
38  : Plugin( PluginICEUDP )
39  {
40  if( !tag || tag->name() != "transport" || tag->xmlns() != XMLNS_JINGLE_ICE_UDP )
41  return;
42 
43  m_pwd = tag->findAttribute( "pwd" );
44  m_ufrag = tag->findAttribute( "ufrag" );
45  const TagList candidates = tag->findChildren( "candidate" );
46  TagList::const_iterator it = candidates.begin();
47  for( ; it != candidates.end(); ++it )
48  {
49  Candidate c;
50  c.component = (*it)->findAttribute( "component" );
51  c.foundation = (*it)->findAttribute( "foundation" );
52  c.generation = (*it)->findAttribute( "generation" );
53  c.id = (*it)->findAttribute( "id" );
54  c.ip = (*it)->findAttribute( "ip" );
55  c.network = (*it)->findAttribute( "network" );
56  c.port = atoi( (*it)->findAttribute( "port" ).c_str() );
57  c.priority = atoi( (*it)->findAttribute( "priority" ).c_str() );
58  c.protocol = (*it)->findAttribute( "protocol" );
59  c.rel_addr = (*it)->findAttribute( "rel-addr" );
60  c.rel_port = atoi( (*it)->findAttribute( "rel-port" ).c_str() );
61  c.type = static_cast<Type>( util::lookup( (*it)->findAttribute( "type" ), typeValues ) );
62  m_candidates.push_back( c );
63  }
64  }
65 
67  {
68  StringList sl;
69  sl.push_back( XMLNS_JINGLE_ICE_UDP );
70  return sl;
71  }
72 
73  const std::string& ICEUDP::filterString() const
74  {
75  static const std::string filter = "content/transport[@xmlns='" + XMLNS_JINGLE_ICE_UDP + "']";
76  return filter;
77  }
78 
79  Plugin* ICEUDP::newInstance( const Tag* tag ) const
80  {
81  return new ICEUDP( tag );
82  }
83 
84  Tag* ICEUDP::tag() const
85  {
86  Tag* t = new Tag( "transport", XMLNS, XMLNS_JINGLE_ICE_UDP );
87  t->addAttribute( "pwd", m_pwd );
88  t->addAttribute( "ufrag", m_ufrag );
89 
90  CandidateList::const_iterator it = m_candidates.begin();
91  for( ; it != m_candidates.end(); ++it )
92  {
93  Tag* c = new Tag( t, "candidate" );
94  c->addAttribute( "component", (*it).component );
95  c->addAttribute( "foundation", (*it).foundation );
96  c->addAttribute( "generation", (*it).generation );
97  c->addAttribute( "id", (*it).id );
98  c->addAttribute( "ip", (*it).ip );
99  c->addAttribute( "network", (*it).network );
100  c->addAttribute( "port", (*it).port );
101  c->addAttribute( "priority", (*it).priority );
102  c->addAttribute( "protocol", (*it).protocol );
103  c->addAttribute( "rel-addr", (*it).rel_addr );
104  c->addAttribute( "rel-port", (*it).rel_port );
105  c->addAttribute( "type", util::lookup( (*it).type, typeValues ) );
106  }
107 
108  return t;
109  }
110 
111  }
112 
113 }
const CandidateList & candidates() const
Definition: jingleiceudp.h:110
ICEUDP(const std::string &pwd, const std::string &ufrag, CandidateList &candidates)
virtual Plugin * newInstance(const Tag *tag) const
virtual const StringList features() const
virtual const std::string & filterString() const
std::list< Candidate > CandidateList
Definition: jingleiceudp.h:73
virtual Tag * tag() const
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:68
This is an abstraction of an XML element.
Definition: tag.h:47
const std::string xmlns() const
Definition: tag.cpp:543
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
const std::string & findAttribute(const std::string &name) const
Definition: tag.cpp:589
TagList findChildren(const std::string &name, const std::string &xmlns=EmptyString) const
Definition: tag.cpp:714
const std::string & name() const
Definition: tag.h:394
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< Tag * > TagList
Definition: tag.h:26
std::list< std::string > StringList
Definition: gloox.h:1251
const std::string XMLNS
Definition: gloox.cpp:122
const std::string XMLNS_JINGLE_ICE_UDP
Definition: gloox.cpp:103