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

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: 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 side-by-side diff with in-line comments
Download patch
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..1e83768931a7140dd2246ec60e9739747db5ee59 100644
--- a/chromeos/network/onc/onc_utils.cc
+++ b/chromeos/network/onc/onc_utils.cc
@@ -7,12 +7,13 @@
#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"
+#include "googleurl/src/gurl.h"
#define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message)
#define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message)
@@ -164,5 +165,56 @@ std::string GetSourceAsString(ONCSource source) {
return "unknown";
}
-} // chromeos
+void ExpandField(const std::string fieldname,
+ 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,
+ 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);
+ }
+}
+
} // onc
+} // chromeos

Powered by Google App Engine
This is Rietveld 408576698