Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/talk/p2p/base/rawtransport.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 5.0 KB
Line 
1/*
2 * libjingle
3 * Copyright 2004--2005, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 *  1. Redistributions of source code must retain the above copyright notice,
9 *     this list of conditions and the following disclaimer.
10 *  2. Redistributions in binary form must reproduce the above copyright notice,
11 *     this list of conditions and the following disclaimer in the documentation
12 *     and/or other materials provided with the distribution.
13 *  3. The name of the author may not be used to endorse or promote products
14 *     derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <string>
29#include <vector>
30#include "talk/p2p/base/rawtransport.h"
31#include "talk/base/common.h"
32#include "talk/p2p/base/constants.h"
33#include "talk/p2p/base/parsing.h"
34#include "talk/p2p/base/sessionmanager.h"
35#include "talk/p2p/base/rawtransportchannel.h"
36#include "talk/xmllite/qname.h"
37#include "talk/xmllite/xmlelement.h"
38#include "talk/xmpp/constants.h"
39
40#if defined(FEATURE_ENABLE_PSTN)
41namespace cricket {
42
43RawTransport::RawTransport(talk_base::Thread* signaling_thread,
44                           talk_base::Thread* worker_thread,
45                           const std::string& content_name,
46                           PortAllocator* allocator)
47    : Transport(signaling_thread, worker_thread,
48                content_name, NS_GINGLE_RAW, allocator) {
49}
50
51RawTransport::~RawTransport() {
52  DestroyAllChannels();
53}
54
55bool RawTransport::ParseCandidates(SignalingProtocol protocol,
56                                   const buzz::XmlElement* elem,
57                                   const CandidateTranslator* translator,
58                                   Candidates* candidates,
59                                   ParseError* error) {
60  for (const buzz::XmlElement* cand_elem = elem->FirstElement();
61       cand_elem != NULL;
62       cand_elem = cand_elem->NextElement()) {
63    if (cand_elem->Name() == QN_GINGLE_RAW_CHANNEL) {
64      if (!cand_elem->HasAttr(buzz::QN_NAME)) {
65        return BadParse("no channel name given", error);
66      }
67      if (type() != cand_elem->Attr(buzz::QN_NAME)) {
68        return BadParse("channel named does not exist", error);
69      }
70      talk_base::SocketAddress addr;
71      if (!ParseRawAddress(cand_elem, &addr, error))
72        return false;
73
74      Candidate candidate;
75      candidate.set_component(1);
76      candidate.set_address(addr);
77      candidates->push_back(candidate);
78    }
79  }
80  return true;
81}
82
83bool RawTransport::WriteCandidates(SignalingProtocol protocol,
84                                   const Candidates& candidates,
85                                   const CandidateTranslator* translator,
86                                   XmlElements* candidate_elems,
87                                   WriteError* error) {
88  for (std::vector<Candidate>::const_iterator
89       cand = candidates.begin();
90       cand != candidates.end();
91       ++cand) {
92    ASSERT(cand->component() == 1);
93    ASSERT(cand->protocol() == "udp");
94    talk_base::SocketAddress addr = cand->address();
95
96    buzz::XmlElement* elem = new buzz::XmlElement(QN_GINGLE_RAW_CHANNEL);
97    elem->SetAttr(buzz::QN_NAME, type());
98    elem->SetAttr(QN_ADDRESS, addr.ipaddr().ToString());
99    elem->SetAttr(QN_PORT, addr.PortAsString());
100    candidate_elems->push_back(elem);
101  }
102  return true;
103}
104
105bool RawTransport::ParseRawAddress(const buzz::XmlElement* elem,
106                                   talk_base::SocketAddress* addr,
107                                   ParseError* error) {
108  // Make sure the required attributes exist
109  if (!elem->HasAttr(QN_ADDRESS) ||
110      !elem->HasAttr(QN_PORT)) {
111    return BadParse("channel missing required attribute", error);
112  }
113
114  // Parse the address.
115  if (!ParseAddress(elem, QN_ADDRESS, QN_PORT, addr, error))
116    return false;
117
118  return true;
119}
120
121TransportChannelImpl* RawTransport::CreateTransportChannel(int component) {
122  return new RawTransportChannel(content_name(), component, this,
123                                 worker_thread(),
124                                 port_allocator());
125}
126
127void RawTransport::DestroyTransportChannel(TransportChannelImpl* channel) {
128  delete channel;
129}
130
131}  // namespace cricket
132#endif  // defined(FEATURE_ENABLE_PSTN)
Note: See TracBrowser for help on using the repository browser.