Commit 419f2d3d authored by stevenjb's avatar stevenjb Committed by Commit bot

Format ONC translation files

BUG=None

Review URL: https://codereview.chromium.org/1031253002

Cr-Commit-Position: refs/heads/master@{#322338}
parent 1eeacc84
This diff is collapsed.
...@@ -31,9 +31,8 @@ CHROMEOS_EXPORT const OncFieldSignature* GetFieldSignature( ...@@ -31,9 +31,8 @@ CHROMEOS_EXPORT const OncFieldSignature* GetFieldSignature(
const OncValueSignature& signature, const OncValueSignature& signature,
const std::string& onc_field_name); const std::string& onc_field_name);
CHROMEOS_EXPORT bool FieldIsCredential( CHROMEOS_EXPORT bool FieldIsCredential(const OncValueSignature& signature,
const OncValueSignature& signature, const std::string& onc_field_name);
const std::string& onc_field_name);
CHROMEOS_EXPORT extern const OncValueSignature kRecommendedSignature; CHROMEOS_EXPORT extern const OncValueSignature kRecommendedSignature;
CHROMEOS_EXPORT extern const OncValueSignature kEAPSignature; CHROMEOS_EXPORT extern const OncValueSignature kEAPSignature;
......
...@@ -126,7 +126,6 @@ void LocalTranslator::TranslateEthernet() { ...@@ -126,7 +126,6 @@ void LocalTranslator::TranslateEthernet() {
CopyFieldsAccordingToSignature(); CopyFieldsAccordingToSignature();
} }
void LocalTranslator::TranslateOpenVPN() { void LocalTranslator::TranslateOpenVPN() {
// SaveCredentials needs special handling when translating from Shill -> ONC // SaveCredentials needs special handling when translating from Shill -> ONC
// so handle it explicitly here. // so handle it explicitly here.
...@@ -216,8 +215,8 @@ void LocalTranslator::TranslateVPN() { ...@@ -216,8 +215,8 @@ void LocalTranslator::TranslateVPN() {
void LocalTranslator::TranslateWiFi() { void LocalTranslator::TranslateWiFi() {
std::string security; std::string security;
if (onc_object_->GetStringWithoutPathExpansion( if (onc_object_->GetStringWithoutPathExpansion(::onc::wifi::kSecurity,
::onc::wifi::kSecurity, &security)) { &security)) {
TranslateWithTableAndSet(security, kWiFiSecurityTable, TranslateWithTableAndSet(security, kWiFiSecurityTable,
shill::kSecurityClassProperty); shill::kSecurityClassProperty);
} }
...@@ -249,9 +248,9 @@ void LocalTranslator::TranslateEAP() { ...@@ -249,9 +248,9 @@ void LocalTranslator::TranslateEAP() {
// Shill. // Shill.
onc_object_->GetStringWithoutPathExpansion(::onc::eap::kInner, &inner); onc_object_->GetStringWithoutPathExpansion(::onc::eap::kInner, &inner);
if (inner != ::onc::eap::kAutomatic) { if (inner != ::onc::eap::kAutomatic) {
const StringTranslationEntry* table = const StringTranslationEntry* table = outer == ::onc::eap::kPEAP
outer == ::onc::eap::kPEAP ? kEAP_PEAP_InnerTable : ? kEAP_PEAP_InnerTable
kEAP_TTLS_InnerTable; : kEAP_TTLS_InnerTable;
TranslateWithTableAndSet(inner, table, shill::kEapPhase2AuthProperty); TranslateWithTableAndSet(inner, table, shill::kEapPhase2AuthProperty);
} }
} }
...@@ -328,8 +327,8 @@ void LocalTranslator::AddValueAccordingToSignature( ...@@ -328,8 +327,8 @@ void LocalTranslator::AddValueAccordingToSignature(
if (!value || !field_translation_table_) if (!value || !field_translation_table_)
return; return;
std::string shill_property_name; std::string shill_property_name;
if (!GetShillPropertyName( if (!GetShillPropertyName(onc_name, field_translation_table_,
onc_name, field_translation_table_, &shill_property_name)) { &shill_property_name)) {
return; return;
} }
...@@ -366,8 +365,7 @@ void TranslateONCHierarchy(const OncValueSignature& signature, ...@@ -366,8 +365,7 @@ void TranslateONCHierarchy(const OncValueSignature& signature,
GetPathToNestedShillDictionary(signature); GetPathToNestedShillDictionary(signature);
for (std::vector<std::string>::const_iterator it = for (std::vector<std::string>::const_iterator it =
path_to_shill_dictionary.begin(); path_to_shill_dictionary.begin();
it != path_to_shill_dictionary.end(); it != path_to_shill_dictionary.end(); ++it) {
++it) {
base::DictionaryValue* nested_shill_dict = NULL; base::DictionaryValue* nested_shill_dict = NULL;
target_shill_dictionary->GetDictionaryWithoutPathExpansion( target_shill_dictionary->GetDictionaryWithoutPathExpansion(
*it, &nested_shill_dict); *it, &nested_shill_dict);
......
...@@ -66,8 +66,7 @@ class ShillToONCTranslator { ...@@ -66,8 +66,7 @@ class ShillToONCTranslator {
: shill_dictionary_(&shill_dictionary), : shill_dictionary_(&shill_dictionary),
onc_source_(onc_source), onc_source_(onc_source),
onc_signature_(&onc_signature), onc_signature_(&onc_signature),
field_translation_table_(field_translation_table) { field_translation_table_(field_translation_table) {}
}
// Translates the associated Shill dictionary and creates an ONC object of the // Translates the associated Shill dictionary and creates an ONC object of the
// given signature. // given signature.
...@@ -222,8 +221,7 @@ void ShillToONCTranslator::TranslateOpenVPN() { ...@@ -222,8 +221,7 @@ void ShillToONCTranslator::TranslateOpenVPN() {
const base::Value* shill_value = NULL; const base::Value* shill_value = NULL;
if (!field_translation_table_ || if (!field_translation_table_ ||
!GetShillPropertyName(field_signature->onc_field_name, !GetShillPropertyName(field_signature->onc_field_name,
field_translation_table_, field_translation_table_, &shill_property_name) ||
&shill_property_name) ||
!shill_dictionary_->GetWithoutPathExpansion(shill_property_name, !shill_dictionary_->GetWithoutPathExpansion(shill_property_name,
&shill_value)) { &shill_value)) {
continue; continue;
...@@ -235,23 +233,21 @@ void ShillToONCTranslator::TranslateOpenVPN() { ...@@ -235,23 +233,21 @@ void ShillToONCTranslator::TranslateOpenVPN() {
// Shill wants all Provider/VPN fields to be strings. Translates these // Shill wants all Provider/VPN fields to be strings. Translates these
// strings back to the correct ONC type. // strings back to the correct ONC type.
translated = ConvertStringToValue( translated = ConvertStringToValue(
shill_str, shill_str, field_signature->value_signature->onc_type);
field_signature->value_signature->onc_type);
if (translated.get() == NULL) { if (translated.get() == NULL) {
LOG(ERROR) << "Shill property '" << shill_property_name LOG(ERROR) << "Shill property '" << shill_property_name
<< "' with value " << *shill_value << "' with value " << *shill_value
<< " couldn't be converted to base::Value::Type " << " couldn't be converted to base::Value::Type "
<< field_signature->value_signature->onc_type << field_signature->value_signature->onc_type << ": "
<< ": " << GetName(); << GetName();
} else { } else {
onc_object_->SetWithoutPathExpansion(onc_field_name, onc_object_->SetWithoutPathExpansion(onc_field_name,
translated.release()); translated.release());
} }
} else { } else {
LOG(ERROR) << "Shill property '" << shill_property_name LOG(ERROR) << "Shill property '" << shill_property_name << "' has value "
<< "' has value " << *shill_value << *shill_value << ", but expected a string: " << GetName();
<< ", but expected a string: " << GetName();
} }
} }
} }
...@@ -294,8 +290,8 @@ void ShillToONCTranslator::TranslateVPN() { ...@@ -294,8 +290,8 @@ void ShillToONCTranslator::TranslateVPN() {
std::string shill_provider_type, onc_provider_type; std::string shill_provider_type, onc_provider_type;
provider->GetStringWithoutPathExpansion(shill::kTypeProperty, provider->GetStringWithoutPathExpansion(shill::kTypeProperty,
&shill_provider_type); &shill_provider_type);
if (!TranslateStringToONC( if (!TranslateStringToONC(kVPNTypeTable, shill_provider_type,
kVPNTypeTable, shill_provider_type, &onc_provider_type)) { &onc_provider_type)) {
return; return;
} }
onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kType, onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kType,
...@@ -323,15 +319,13 @@ void ShillToONCTranslator::TranslateVPN() { ...@@ -323,15 +319,13 @@ void ShillToONCTranslator::TranslateVPN() {
if (onc_provider_type != ::onc::vpn::kThirdPartyVpn && if (onc_provider_type != ::onc::vpn::kThirdPartyVpn &&
shill_dictionary_->GetBooleanWithoutPathExpansion( shill_dictionary_->GetBooleanWithoutPathExpansion(
shill::kSaveCredentialsProperty, &save_credentials)) { shill::kSaveCredentialsProperty, &save_credentials)) {
SetNestedOncValue(provider_type_dictionary, SetNestedOncValue(provider_type_dictionary, ::onc::vpn::kSaveCredentials,
::onc::vpn::kSaveCredentials,
base::FundamentalValue(save_credentials)); base::FundamentalValue(save_credentials));
} }
} }
void ShillToONCTranslator::TranslateWiFiWithState() { void ShillToONCTranslator::TranslateWiFiWithState() {
TranslateWithTableAndSet(shill::kSecurityClassProperty, TranslateWithTableAndSet(shill::kSecurityClassProperty, kWiFiSecurityTable,
kWiFiSecurityTable,
::onc::wifi::kSecurity); ::onc::wifi::kSecurity);
bool unknown_encoding = true; bool unknown_encoding = true;
std::string ssid = shill_property_util::GetSSIDFromProperties( std::string ssid = shill_property_util::GetSSIDFromProperties(
...@@ -362,15 +356,15 @@ void ShillToONCTranslator::TranslateCellularWithState() { ...@@ -362,15 +356,15 @@ void ShillToONCTranslator::TranslateCellularWithState() {
::onc::cellular::kActivationState); ::onc::cellular::kActivationState);
const base::DictionaryValue* dictionary = NULL; const base::DictionaryValue* dictionary = NULL;
if (shill_dictionary_->GetDictionaryWithoutPathExpansion( if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
shill::kServingOperatorProperty, &dictionary)) { shill::kServingOperatorProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary); TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary);
} }
if (shill_dictionary_->GetDictionaryWithoutPathExpansion( if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
shill::kCellularApnProperty, &dictionary)) { shill::kCellularApnProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
} }
if (shill_dictionary_->GetDictionaryWithoutPathExpansion( if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
shill::kCellularLastGoodApnProperty, &dictionary)) { shill::kCellularLastGoodApnProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kLastGoodAPN, *dictionary); TranslateAndAddNestedObject(::onc::cellular::kLastGoodAPN, *dictionary);
} }
const base::DictionaryValue* device_dictionary = NULL; const base::DictionaryValue* device_dictionary = NULL;
...@@ -436,8 +430,8 @@ void ShillToONCTranslator::TranslateNetworkWithState() { ...@@ -436,8 +430,8 @@ void ShillToONCTranslator::TranslateNetworkWithState() {
std::string onc_network_type = ::onc::network_type::kEthernet; std::string onc_network_type = ::onc::network_type::kEthernet;
if (shill_network_type != shill::kTypeEthernet && if (shill_network_type != shill::kTypeEthernet &&
shill_network_type != shill::kTypeEthernetEap) { shill_network_type != shill::kTypeEthernetEap) {
TranslateStringToONC( TranslateStringToONC(kNetworkTypeTable, shill_network_type,
kNetworkTypeTable, shill_network_type, &onc_network_type); &onc_network_type);
} }
// Translate nested Cellular, WiFi, etc. properties. // Translate nested Cellular, WiFi, etc. properties.
if (!onc_network_type.empty()) { if (!onc_network_type.empty()) {
...@@ -487,8 +481,8 @@ void ShillToONCTranslator::TranslateNetworkWithState() { ...@@ -487,8 +481,8 @@ void ShillToONCTranslator::TranslateNetworkWithState() {
source = ::onc::network_config::kSourceUser; source = ::onc::network_config::kSourceUser;
else else
source = ::onc::network_config::kSourceNone; source = ::onc::network_config::kSourceNone;
onc_object_->SetStringWithoutPathExpansion( onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kSource,
::onc::network_config::kSource, source); source);
} }
// Use a human-readable aa:bb format for any hardware MAC address. Note: // Use a human-readable aa:bb format for any hardware MAC address. Note:
...@@ -514,7 +508,7 @@ void ShillToONCTranslator::TranslateNetworkWithState() { ...@@ -514,7 +508,7 @@ void ShillToONCTranslator::TranslateNetworkWithState() {
const base::DictionaryValue* saved_ipconfig = nullptr; const base::DictionaryValue* saved_ipconfig = nullptr;
if (shill_dictionary_->GetDictionaryWithoutPathExpansion( if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
shill::kSavedIPConfigProperty, &saved_ipconfig)) { shill::kSavedIPConfigProperty, &saved_ipconfig)) {
TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig, TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig,
*saved_ipconfig); *saved_ipconfig);
} }
...@@ -598,8 +592,8 @@ void ShillToONCTranslator::TranslateAndAddNestedObject( ...@@ -598,8 +592,8 @@ void ShillToONCTranslator::TranslateAndAddNestedObject(
NOTREACHED() << "Unable to find signature for field: " << onc_field_name; NOTREACHED() << "Unable to find signature for field: " << onc_field_name;
return; return;
} }
ShillToONCTranslator nested_translator( ShillToONCTranslator nested_translator(dictionary, onc_source_,
dictionary, onc_source_, *field_signature->value_signature); *field_signature->value_signature);
scoped_ptr<base::DictionaryValue> nested_object = scoped_ptr<base::DictionaryValue> nested_object =
nested_translator.CreateTranslatedONCObject(); nested_translator.CreateTranslatedONCObject();
if (nested_object->empty()) if (nested_object->empty())
...@@ -612,8 +606,8 @@ void ShillToONCTranslator::SetNestedOncValue( ...@@ -612,8 +606,8 @@ void ShillToONCTranslator::SetNestedOncValue(
const std::string& onc_field_name, const std::string& onc_field_name,
const base::Value& value) { const base::Value& value) {
base::DictionaryValue* nested; base::DictionaryValue* nested;
if (!onc_object_->GetDictionaryWithoutPathExpansion( if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name,
onc_dictionary_name, &nested)) { &nested)) {
nested = new base::DictionaryValue; nested = new base::DictionaryValue;
onc_object_->SetWithoutPathExpansion(onc_dictionary_name, nested); onc_object_->SetWithoutPathExpansion(onc_dictionary_name, nested);
} }
...@@ -633,14 +627,13 @@ void ShillToONCTranslator::TranslateAndAddListOfObjects( ...@@ -633,14 +627,13 @@ void ShillToONCTranslator::TranslateAndAddListOfObjects(
} }
DCHECK(field_signature->value_signature->onc_array_entry_signature); DCHECK(field_signature->value_signature->onc_array_entry_signature);
scoped_ptr<base::ListValue> result(new base::ListValue()); scoped_ptr<base::ListValue> result(new base::ListValue());
for (base::ListValue::const_iterator it = list.begin(); for (base::ListValue::const_iterator it = list.begin(); it != list.end();
it != list.end(); ++it) { ++it) {
const base::DictionaryValue* shill_value = NULL; const base::DictionaryValue* shill_value = NULL;
if (!(*it)->GetAsDictionary(&shill_value)) if (!(*it)->GetAsDictionary(&shill_value))
continue; continue;
ShillToONCTranslator nested_translator( ShillToONCTranslator nested_translator(
*shill_value, *shill_value, onc_source_,
onc_source_,
*field_signature->value_signature->onc_array_entry_signature); *field_signature->value_signature->onc_array_entry_signature);
scoped_ptr<base::DictionaryValue> nested_object = scoped_ptr<base::DictionaryValue> nested_object =
nested_translator.CreateTranslatedONCObject(); nested_translator.CreateTranslatedONCObject();
...@@ -677,21 +670,19 @@ void ShillToONCTranslator::CopyProperty( ...@@ -677,21 +670,19 @@ void ShillToONCTranslator::CopyProperty(
const base::Value* shill_value = NULL; const base::Value* shill_value = NULL;
if (!field_translation_table_ || if (!field_translation_table_ ||
!GetShillPropertyName(field_signature->onc_field_name, !GetShillPropertyName(field_signature->onc_field_name,
field_translation_table_, field_translation_table_, &shill_property_name) ||
&shill_property_name) ||
!shill_dictionary_->GetWithoutPathExpansion(shill_property_name, !shill_dictionary_->GetWithoutPathExpansion(shill_property_name,
&shill_value)) { &shill_value)) {
return; return;
} }
if (shill_value->GetType() != field_signature->value_signature->onc_type) { if (shill_value->GetType() != field_signature->value_signature->onc_type) {
LOG(ERROR) << "Shill property '" << shill_property_name LOG(ERROR) << "Shill property '" << shill_property_name << "' with value "
<< "' with value " << *shill_value << *shill_value << " has base::Value::Type "
<< " has base::Value::Type " << shill_value->GetType() << shill_value->GetType() << " but ONC field '"
<< " but ONC field '" << field_signature->onc_field_name << field_signature->onc_field_name << "' requires type "
<< "' requires type " << field_signature->value_signature->onc_type << ": "
<< field_signature->value_signature->onc_type << GetName();
<< ": " << GetName();
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment