gloox  1.0.9
jingleiceudp.cpp
1 /*
2  Copyright (c) 2013 by Jakob Schroeter <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  : m_pwd( pwd ), m_ufrag( ufrag), m_candidates( candidates )
34  {
35  }
36 
37  ICEUDP::ICEUDP( const Tag* tag )
38  {
39  if( !tag || tag->name() != "transport" || tag->xmlns() != XMLNS_JINGLE_ICE_UDP )
40  return;
41 
42  m_pwd = tag->findAttribute( "pwd" );
43  m_ufrag = tag->findAttribute( "ufrag" );
44  const TagList candidates = tag->findChildren( "candidate" );
45  TagList::const_iterator it = candidates.begin();
46  for( ; it != candidates.end(); ++it )
47  {
48  Candidate c;
49  c.component = (*it)->findAttribute( "component" );
50  c.foundation = (*it)->findAttribute( "foundation" );
51  c.generation = (*it)->findAttribute( "generation" );
52  c.id = (*it)->findAttribute( "id" );
53  c.ip = (*it)->findAttribute( "ip" );
54  c.network = (*it)->findAttribute( "network" );
55  c.port = atoi( (*it)->findAttribute( "port" ).c_str() );
56  c.priority = atoi( (*it)->findAttribute( "priority" ).c_str() );
57  c.protocol = (*it)->findAttribute( "protocol" );
58  c.rel_addr = (*it)->findAttribute( "rel-addr" );
59  c.rel_port = atoi( (*it)->findAttribute( "rel-port" ).c_str() );
60  c.type = (Type)util::lookup( (*it)->findAttribute( "type" ), typeValues );
61  }
62  }
63 
65  {
66  StringList sl;
67  sl.push_back( XMLNS_JINGLE_ICE_UDP );
68  return sl;
69  }
70 
71  const std::string& ICEUDP::filterString() const
72  {
73  static const std::string filter = "content/transport[@xmlns='" + XMLNS_JINGLE_ICE_UDP + "']";
74  return filter;
75  }
76 
77  Plugin* ICEUDP::newInstance( const Tag* tag ) const
78  {
79  return new ICEUDP( tag );
80  }
81 
82  Tag* ICEUDP::tag() const
83  {
84  Tag* t = new Tag( "transport", XMLNS, XMLNS_JINGLE_ICE_UDP );
85  t->addAttribute( "pwd", m_pwd );
86  t->addAttribute( "ufrag", m_ufrag );
87 
88  CandidateList::const_iterator it = m_candidates.begin();
89  for( ; it != m_candidates.end(); ++it )
90  {
91  Tag* c = new Tag( t, "candidate" );
92  c->addAttribute( "component", (*it).component );
93  c->addAttribute( "foundation", (*it).foundation );
94  c->addAttribute( "generation", (*it).generation );
95  c->addAttribute( "id", (*it).id );
96  c->addAttribute( "ip", (*it).ip );
97  c->addAttribute( "network", (*it).network );
98  c->addAttribute( "port", (*it).port );
99  c->addAttribute( "priority", (*it).priority );
100  c->addAttribute( "protocol", (*it).protocol );
101  c->addAttribute( "rel-addr", (*it).rel_addr );
102  c->addAttribute( "rel-port", (*it).rel_port );
103  c->addAttribute( "type", util::lookup( (*it).type, typeValues ) );
104  }
105 
106  return t;
107  }
108 
109  }
110 
111 }