Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: jingle/glue/utils.cc

Issue 10209008: Roll libjingle 132:133 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/base/ip_endpoint.h" 12 #include "net/base/ip_endpoint.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "third_party/libjingle/overrides/talk/base/byteorder.h" 14 #include "third_party/libjingle/source/talk/base/byteorder.h"
15 #include "third_party/libjingle/source/talk/base/socketaddress.h" 15 #include "third_party/libjingle/source/talk/base/socketaddress.h"
16 #include "third_party/libjingle/source/talk/p2p/base/candidate.h" 16 #include "third_party/libjingle/source/talk/p2p/base/candidate.h"
17 17
18 namespace jingle_glue { 18 namespace jingle_glue {
19 19
20 bool IPEndPointToSocketAddress(const net::IPEndPoint& address_chrome, 20 bool IPEndPointToSocketAddress(const net::IPEndPoint& address_chrome,
21 talk_base::SocketAddress* address_lj) { 21 talk_base::SocketAddress* address_lj) {
22 if (address_chrome.GetFamily() != AF_INET) { 22 if (address_chrome.GetFamily() != AF_INET) {
23 LOG(ERROR) << "Only IPv4 addresses are supported."; 23 LOG(ERROR) << "Only IPv4 addresses are supported.";
24 return false; 24 return false;
(...skipping 10 matching lines...) Expand all
35 net::IPAddressNumber address; 35 net::IPAddressNumber address;
36 address.resize(net::kIPv4AddressSize); 36 address.resize(net::kIPv4AddressSize);
37 memcpy(&address[0], &ip, net::kIPv4AddressSize); 37 memcpy(&address[0], &ip, net::kIPv4AddressSize);
38 *address_chrome = net::IPEndPoint(address, address_lj.port()); 38 *address_chrome = net::IPEndPoint(address, address_lj.port());
39 return true; 39 return true;
40 } 40 }
41 41
42 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { 42 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) {
43 // TODO(sergeyu): Use SDP to format candidates? 43 // TODO(sergeyu): Use SDP to format candidates?
44 DictionaryValue value; 44 DictionaryValue value;
45 value.SetString("name", candidate.name());
46 value.SetString("ip", candidate.address().IPAsString()); 45 value.SetString("ip", candidate.address().IPAsString());
47 value.SetInteger("port", candidate.address().port()); 46 value.SetInteger("port", candidate.address().port());
48 value.SetString("type", candidate.type()); 47 value.SetString("type", candidate.type());
49 value.SetString("protocol", candidate.protocol()); 48 value.SetString("protocol", candidate.protocol());
50 value.SetString("username", candidate.username()); 49 value.SetString("username", candidate.username());
51 value.SetString("password", candidate.password()); 50 value.SetString("password", candidate.password());
52 value.SetDouble("preference", candidate.preference()); 51 value.SetDouble("preference", candidate.preference());
53 value.SetInteger("generation", candidate.generation()); 52 value.SetInteger("generation", candidate.generation());
54 53
55 std::string result; 54 std::string result;
56 base::JSONWriter::Write(&value, &result); 55 base::JSONWriter::Write(&value, &result);
57 return result; 56 return result;
58 } 57 }
59 58
60 bool DeserializeP2PCandidate(const std::string& candidate_str, 59 bool DeserializeP2PCandidate(const std::string& candidate_str,
61 cricket::Candidate* candidate) { 60 cricket::Candidate* candidate) {
62 scoped_ptr<Value> value( 61 scoped_ptr<Value> value(
63 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS)); 62 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS));
64 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { 63 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) {
65 return false; 64 return false;
66 } 65 }
67 66
68 DictionaryValue* dic_value = static_cast<DictionaryValue*>(value.get()); 67 DictionaryValue* dic_value = static_cast<DictionaryValue*>(value.get());
69 68
70 std::string name;
71 std::string ip; 69 std::string ip;
72 int port; 70 int port;
73 std::string type; 71 std::string type;
74 std::string protocol; 72 std::string protocol;
75 std::string username; 73 std::string username;
76 std::string password; 74 std::string password;
77 double preference; 75 double preference;
78 int generation; 76 int generation;
79 77
80 if (!dic_value->GetString("name", &name) || 78 if (!dic_value->GetString("ip", &ip) ||
81 !dic_value->GetString("ip", &ip) ||
82 !dic_value->GetInteger("port", &port) || 79 !dic_value->GetInteger("port", &port) ||
83 !dic_value->GetString("type", &type) || 80 !dic_value->GetString("type", &type) ||
84 !dic_value->GetString("protocol", &protocol) || 81 !dic_value->GetString("protocol", &protocol) ||
85 !dic_value->GetString("username", &username) || 82 !dic_value->GetString("username", &username) ||
86 !dic_value->GetString("password", &password) || 83 !dic_value->GetString("password", &password) ||
87 !dic_value->GetDouble("preference", &preference) || 84 !dic_value->GetDouble("preference", &preference) ||
88 !dic_value->GetInteger("generation", &generation)) { 85 !dic_value->GetInteger("generation", &generation)) {
89 return false; 86 return false;
90 } 87 }
91 88
92 candidate->set_name(name);
93 candidate->set_address(talk_base::SocketAddress(ip, port)); 89 candidate->set_address(talk_base::SocketAddress(ip, port));
94 candidate->set_type(type); 90 candidate->set_type(type);
95 candidate->set_protocol(protocol); 91 candidate->set_protocol(protocol);
96 candidate->set_username(username); 92 candidate->set_username(username);
97 candidate->set_password(password); 93 candidate->set_password(password);
98 candidate->set_preference(static_cast<float>(preference)); 94 candidate->set_preference(static_cast<float>(preference));
99 candidate->set_generation(generation); 95 candidate->set_generation(generation);
100 96
101 return true; 97 return true;
102 } 98 }
103 99
104 } // namespace jingle_glue 100 } // namespace jingle_glue
OLDNEW
« no previous file with comments | « jingle/glue/channel_socket_adapter_unittest.cc ('k') | jingle/notifier/listener/push_notifications_subscribe_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698