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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 bool SocketAddressToIPEndPoint(const talk_base::SocketAddress& address, | 28 bool SocketAddressToIPEndPoint(const talk_base::SocketAddress& address, |
29 net::IPEndPoint* ip_endpoint) { | 29 net::IPEndPoint* ip_endpoint) { |
30 sockaddr_storage addr; | 30 sockaddr_storage addr; |
31 int size = address.ToSockAddrStorage(&addr); | 31 int size = address.ToSockAddrStorage(&addr); |
32 return (size > 0) && | 32 return (size > 0) && |
33 ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size); | 33 ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size); |
34 } | 34 } |
35 | 35 |
36 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { | 36 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { |
37 // TODO(sergeyu): Use SDP to format candidates? | 37 // TODO(sergeyu): Use SDP to format candidates? |
38 DictionaryValue value; | 38 base::DictionaryValue value; |
39 value.SetString("ip", candidate.address().ipaddr().ToString()); | 39 value.SetString("ip", candidate.address().ipaddr().ToString()); |
40 value.SetInteger("port", candidate.address().port()); | 40 value.SetInteger("port", candidate.address().port()); |
41 value.SetString("type", candidate.type()); | 41 value.SetString("type", candidate.type()); |
42 value.SetString("protocol", candidate.protocol()); | 42 value.SetString("protocol", candidate.protocol()); |
43 value.SetString("username", candidate.username()); | 43 value.SetString("username", candidate.username()); |
44 value.SetString("password", candidate.password()); | 44 value.SetString("password", candidate.password()); |
45 value.SetDouble("preference", candidate.preference()); | 45 value.SetDouble("preference", candidate.preference()); |
46 value.SetInteger("generation", candidate.generation()); | 46 value.SetInteger("generation", candidate.generation()); |
47 | 47 |
48 std::string result; | 48 std::string result; |
49 base::JSONWriter::Write(&value, &result); | 49 base::JSONWriter::Write(&value, &result); |
50 return result; | 50 return result; |
51 } | 51 } |
52 | 52 |
53 bool DeserializeP2PCandidate(const std::string& candidate_str, | 53 bool DeserializeP2PCandidate(const std::string& candidate_str, |
54 cricket::Candidate* candidate) { | 54 cricket::Candidate* candidate) { |
55 scoped_ptr<Value> value( | 55 scoped_ptr<base::Value> value( |
56 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS)); | 56 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS)); |
57 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { | 57 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 DictionaryValue* dic_value = static_cast<DictionaryValue*>(value.get()); | 61 base::DictionaryValue* dic_value = |
| 62 static_cast<base::DictionaryValue*>(value.get()); |
62 | 63 |
63 std::string ip; | 64 std::string ip; |
64 int port; | 65 int port; |
65 std::string type; | 66 std::string type; |
66 std::string protocol; | 67 std::string protocol; |
67 std::string username; | 68 std::string username; |
68 std::string password; | 69 std::string password; |
69 double preference; | 70 double preference; |
70 int generation; | 71 int generation; |
71 | 72 |
(...skipping 13 matching lines...) Expand all Loading... |
85 candidate->set_protocol(protocol); | 86 candidate->set_protocol(protocol); |
86 candidate->set_username(username); | 87 candidate->set_username(username); |
87 candidate->set_password(password); | 88 candidate->set_password(password); |
88 candidate->set_preference(static_cast<float>(preference)); | 89 candidate->set_preference(static_cast<float>(preference)); |
89 candidate->set_generation(generation); | 90 candidate->set_generation(generation); |
90 | 91 |
91 return true; | 92 return true; |
92 } | 93 } |
93 | 94 |
94 } // namespace jingle_glue | 95 } // namespace jingle_glue |
OLD | NEW |