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

Unified 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: Rebased. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/onc/onc_utils.h ('k') | chromeos/network/onc/onc_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/onc/onc_utils.cc
diff --git a/chromeos/network/onc/onc_utils.cc b/chromeos/network/onc/onc_utils.cc
index 85cfe640d90e068d5fc9e790ba03631b2cce55d7..c66d1e843fb4993b7e39b538c6a3c35931f4372f 100644
--- a/chromeos/network/onc/onc_utils.cc
+++ b/chromeos/network/onc/onc_utils.cc
@@ -7,9 +7,9 @@
#include "base/base64.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
+#include "base/string_util.h"
#include "base/values.h"
#include "chromeos/network/network_event_log.h"
-#include "chromeos/network/onc/onc_constants.h"
#include "crypto/encryptor.h"
#include "crypto/hmac.h"
#include "crypto/symmetric_key.h"
@@ -164,5 +164,56 @@ std::string GetSourceAsString(ONCSource source) {
return "unknown";
}
-} // chromeos
-} // onc
+void ExpandField(const std::string fieldname,
+ const StringSubstitution& substitution,
+ base::DictionaryValue* onc_object) {
+ std::string user_string;
+ if (!onc_object->GetStringWithoutPathExpansion(fieldname, &user_string))
+ return;
+
+ std::string login_id;
+ if (substitution.GetSubstitute(substitutes::kLoginIDField, &login_id)) {
+ ReplaceSubstringsAfterOffset(&user_string, 0,
+ onc::substitutes::kLoginIDField,
+ login_id);
+ }
+
+ std::string email;
+ if (substitution.GetSubstitute(substitutes::kEmailField, &email)) {
+ ReplaceSubstringsAfterOffset(&user_string, 0,
+ onc::substitutes::kEmailField,
+ email);
+ }
+
+ onc_object->SetStringWithoutPathExpansion(fieldname, user_string);
+}
+
+void ExpandStringsInOncObject(
+ const OncValueSignature& signature,
+ const StringSubstitution& substitution,
+ base::DictionaryValue* onc_object) {
+ if (&signature == &kEAPSignature) {
+ ExpandField(eap::kAnonymousIdentity, substitution, onc_object);
+ ExpandField(eap::kIdentity, substitution, onc_object);
+ } else if (&signature == &kL2TPSignature ||
+ &signature == &kOpenVPNSignature) {
+ ExpandField(vpn::kUsername, substitution, onc_object);
+ }
+
+ // Recurse into nested objects.
+ for (base::DictionaryValue::key_iterator it = onc_object->begin_keys();
+ it != onc_object->end_keys(); ++it) {
+ base::DictionaryValue* inner_object;
+ if (!onc_object->GetDictionaryWithoutPathExpansion(*it, &inner_object))
+ continue;
+
+ const OncFieldSignature* field_signature =
+ GetFieldSignature(signature, *it);
+
+ ExpandStringsInOncObject(*field_signature->value_signature,
+ substitution, inner_object);
+ }
+}
+
+} // namespace onc
+} // namespace chromeos
« no previous file with comments | « chromeos/network/onc/onc_utils.h ('k') | chromeos/network/onc/onc_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698