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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 scoped_ptr<base::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(base::Value::TYPE_DICTIONARY)) { | 57 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 base::DictionaryValue* dic_value = | 61 base::DictionaryValue* dic_value = |
62 static_cast<base::DictionaryValue*>(value.get()); | 62 static_cast<base::DictionaryValue*>(value.get()); |
63 | 63 |
64 std::string ip; | 64 std::string ip; |
65 int port; | 65 int port = 0; |
66 std::string type; | 66 std::string type; |
67 std::string protocol; | 67 std::string protocol; |
68 std::string username; | 68 std::string username; |
69 std::string password; | 69 std::string password; |
70 double preference; | 70 double preference = 0; |
71 int generation; | 71 int generation = 0; |
72 | 72 |
73 if (!dic_value->GetString("ip", &ip) || | 73 if (!dic_value->GetString("ip", &ip) || |
74 !dic_value->GetInteger("port", &port) || | 74 !dic_value->GetInteger("port", &port) || |
75 !dic_value->GetString("type", &type) || | 75 !dic_value->GetString("type", &type) || |
76 !dic_value->GetString("protocol", &protocol) || | 76 !dic_value->GetString("protocol", &protocol) || |
77 !dic_value->GetString("username", &username) || | 77 !dic_value->GetString("username", &username) || |
78 !dic_value->GetString("password", &password) || | 78 !dic_value->GetString("password", &password) || |
79 !dic_value->GetDouble("preference", &preference) || | 79 !dic_value->GetDouble("preference", &preference) || |
80 !dic_value->GetInteger("generation", &generation)) { | 80 !dic_value->GetInteger("generation", &generation)) { |
81 return false; | 81 return false; |
82 } | 82 } |
83 | 83 |
84 candidate->set_address(talk_base::SocketAddress(ip, port)); | 84 candidate->set_address(talk_base::SocketAddress(ip, port)); |
85 candidate->set_type(type); | 85 candidate->set_type(type); |
86 candidate->set_protocol(protocol); | 86 candidate->set_protocol(protocol); |
87 candidate->set_username(username); | 87 candidate->set_username(username); |
88 candidate->set_password(password); | 88 candidate->set_password(password); |
89 candidate->set_preference(static_cast<float>(preference)); | 89 candidate->set_preference(static_cast<float>(preference)); |
90 candidate->set_generation(generation); | 90 candidate->set_generation(generation); |
91 | 91 |
92 return true; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 } // namespace jingle_glue | 95 } // namespace jingle_glue |
OLD | NEW |