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

Side by Side Diff: chromeos/network/onc/onc_utils.cc

Issue 11664005: Extending the translation from ONC to Shill. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initial patch. Created 8 years 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
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 "chromeos/network/onc/onc_utils.h" 5 #include "chromeos/network/onc/onc_utils.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chromeos/network/network_event_log.h" 12 #include "chromeos/network/network_event_log.h"
12 #include "chromeos/network/onc/onc_constants.h"
13 #include "crypto/encryptor.h" 13 #include "crypto/encryptor.h"
14 #include "crypto/hmac.h" 14 #include "crypto/hmac.h"
15 #include "crypto/symmetric_key.h" 15 #include "crypto/symmetric_key.h"
16 #include "googleurl/src/gurl.h"
16 17
17 #define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message) 18 #define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message)
18 #define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message) 19 #define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message)
19 20
20 namespace chromeos { 21 namespace chromeos {
21 namespace onc { 22 namespace onc {
22 23
23 namespace { 24 namespace {
24 25
25 const char kUnableToDecrypt[] = "Unable to decrypt encrypted ONC"; 26 const char kUnableToDecrypt[] = "Unable to decrypt encrypted ONC";
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return "user policy"; 158 return "user policy";
158 case ONC_SOURCE_NONE: 159 case ONC_SOURCE_NONE:
159 return "none"; 160 return "none";
160 case ONC_SOURCE_USER_IMPORT: 161 case ONC_SOURCE_USER_IMPORT:
161 return "user import"; 162 return "user import";
162 } 163 }
163 NOTREACHED() << "unknown ONC source " << source; 164 NOTREACHED() << "unknown ONC source " << source;
164 return "unknown"; 165 return "unknown";
165 } 166 }
166 167
168 void ExpandField(const std::string fieldname,
169 StringSubstitution* substitution,
170 base::DictionaryValue* onc_object) {
171 std::string user_string;
172 if (!onc_object->GetStringWithoutPathExpansion(fieldname, &user_string))
173 return;
174
175 std::string login_id;
176 if (substitution->GetSubstitute(substitutes::kLoginIDField, &login_id)) {
177 ReplaceSubstringsAfterOffset(&user_string, 0,
178 onc::substitutes::kLoginIDField,
179 login_id);
180 }
181
182 std::string email;
183 if (substitution->GetSubstitute(substitutes::kEmailField, &email)) {
184 ReplaceSubstringsAfterOffset(&user_string, 0,
185 onc::substitutes::kEmailField,
186 email);
187 }
188
189 onc_object->SetStringWithoutPathExpansion(fieldname, user_string);
190 }
191
192 void ExpandStringsInOncObject(
193 const OncValueSignature& signature,
194 StringSubstitution* substitution,
195 base::DictionaryValue* onc_object) {
196 if (&signature == &kEAPSignature) {
197 ExpandField(eap::kAnonymousIdentity, substitution, onc_object);
198 ExpandField(eap::kIdentity, substitution, onc_object);
199 } else if (&signature == &kL2TPSignature ||
200 &signature == &kOpenVPNSignature) {
201 ExpandField(vpn::kUsername, substitution, onc_object);
202 }
203
204 // Recurse into nested objects.
205 for (base::DictionaryValue::key_iterator it = onc_object->begin_keys();
206 it != onc_object->end_keys(); ++it) {
207 base::DictionaryValue* inner_object;
208 if (!onc_object->GetDictionaryWithoutPathExpansion(*it, &inner_object))
209 continue;
210
211 const OncFieldSignature* field_signature =
212 GetFieldSignature(signature, *it);
213
214 ExpandStringsInOncObject(*field_signature->value_signature,
215 substitution, inner_object);
216 }
217 }
218
219 } // onc
167 } // chromeos 220 } // chromeos
168 } // onc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698