| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "jingle/glue/utils.h" | 5 #include "jingle/glue/utils.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "net/base/ip_address.h" |
| 14 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 15 #include "third_party/webrtc/base/byteorder.h" | 16 #include "third_party/webrtc/base/byteorder.h" |
| 16 #include "third_party/webrtc/base/socketaddress.h" | 17 #include "third_party/webrtc/base/socketaddress.h" |
| 17 #include "third_party/webrtc/p2p/base/candidate.h" | 18 #include "third_party/webrtc/p2p/base/candidate.h" |
| 18 | 19 |
| 19 namespace jingle_glue { | 20 namespace jingle_glue { |
| 20 | 21 |
| 21 bool IPEndPointToSocketAddress(const net::IPEndPoint& ip_endpoint, | 22 bool IPEndPointToSocketAddress(const net::IPEndPoint& ip_endpoint, |
| 22 rtc::SocketAddress* address) { | 23 rtc::SocketAddress* address) { |
| 23 sockaddr_storage addr; | 24 sockaddr_storage addr; |
| 24 socklen_t len = sizeof(addr); | 25 socklen_t len = sizeof(addr); |
| 25 return ip_endpoint.ToSockAddr(reinterpret_cast<sockaddr*>(&addr), &len) && | 26 return ip_endpoint.ToSockAddr(reinterpret_cast<sockaddr*>(&addr), &len) && |
| 26 rtc::SocketAddressFromSockAddrStorage(addr, address); | 27 rtc::SocketAddressFromSockAddrStorage(addr, address); |
| 27 } | 28 } |
| 28 | 29 |
| 29 bool SocketAddressToIPEndPoint(const rtc::SocketAddress& address, | 30 bool SocketAddressToIPEndPoint(const rtc::SocketAddress& address, |
| 30 net::IPEndPoint* ip_endpoint) { | 31 net::IPEndPoint* ip_endpoint) { |
| 31 sockaddr_storage addr; | 32 sockaddr_storage addr; |
| 32 int size = address.ToSockAddrStorage(&addr); | 33 int size = address.ToSockAddrStorage(&addr); |
| 33 return (size > 0) && | 34 return (size > 0) && |
| 34 ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size); | 35 ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size); |
| 35 } | 36 } |
| 36 | 37 |
| 37 rtc::IPAddress IPAddressNumberToIPAddress( | 38 rtc::IPAddress NetIPAddressToIPAddress(const net::IPAddress& ip_address) { |
| 38 const net::IPAddressNumber& ip_address_number) { | 39 if (ip_address.IsIPv4()) { |
| 39 if (ip_address_number.size() == net::kIPv4AddressSize) { | |
| 40 uint32_t address; | 40 uint32_t address; |
| 41 memcpy(&address, &ip_address_number[0], sizeof(uint32_t)); | 41 memcpy(&address, ip_address.bytes().data(), sizeof(uint32_t)); |
| 42 address = rtc::NetworkToHost32(address); | 42 address = rtc::NetworkToHost32(address); |
| 43 return rtc::IPAddress(address); | 43 return rtc::IPAddress(address); |
| 44 } | 44 } |
| 45 if (ip_address_number.size() == net::kIPv6AddressSize) { | 45 if (ip_address.IsIPv6()) { |
| 46 in6_addr address; | 46 in6_addr address; |
| 47 memcpy(&address, &ip_address_number[0], sizeof(in6_addr)); | 47 memcpy(&address, ip_address.bytes().data(), sizeof(in6_addr)); |
| 48 return rtc::IPAddress(address); | 48 return rtc::IPAddress(address); |
| 49 } | 49 } |
| 50 return rtc::IPAddress(); | 50 return rtc::IPAddress(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { | 53 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { |
| 54 // TODO(sergeyu): Use SDP to format candidates? | 54 // TODO(sergeyu): Use SDP to format candidates? |
| 55 base::DictionaryValue value; | 55 base::DictionaryValue value; |
| 56 value.SetString("ip", candidate.address().ipaddr().ToString()); | 56 value.SetString("ip", candidate.address().ipaddr().ToString()); |
| 57 value.SetInteger("port", candidate.address().port()); | 57 value.SetInteger("port", candidate.address().port()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 candidate->set_protocol(protocol); | 103 candidate->set_protocol(protocol); |
| 104 candidate->set_username(username); | 104 candidate->set_username(username); |
| 105 candidate->set_password(password); | 105 candidate->set_password(password); |
| 106 candidate->set_preference(static_cast<float>(preference)); | 106 candidate->set_preference(static_cast<float>(preference)); |
| 107 candidate->set_generation(generation); | 107 candidate->set_generation(generation); |
| 108 | 108 |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace jingle_glue | 112 } // namespace jingle_glue |
| OLD | NEW |