1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_ 6#define CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_ 7 8#include <string> 9 10#include "base/memory/scoped_ptr.h" 11#include "chromeos/chromeos_export.h" 12 13namespace base { 14class DictionaryValue; 15class Value; 16} 17 18namespace chromeos { 19 20class NetworkUIData; 21 22namespace shill_property_util { 23 24// Sets the |ssid| in |properties|. 25CHROMEOS_EXPORT void SetSSID(const std::string ssid, 26 base::DictionaryValue* properties); 27 28// Returns the SSID from |properties| in UTF-8 encoding. If |unknown_encoding| 29// is not NULL, it is set to whether the SSID is of unknown encoding. 30CHROMEOS_EXPORT std::string GetSSIDFromProperties( 31 const base::DictionaryValue& properties, 32 bool* unknown_encoding); 33 34// Returns the GUID (if available), SSID, or Name from |properties|. Only used 35// for logging and debugging. 36CHROMEOS_EXPORT std::string GetNetworkIdFromProperties( 37 const base::DictionaryValue& properties); 38 39 // Returns the name for the network represented by the Shill |properties|. For 40// WiFi it refers to the HexSSID. 41CHROMEOS_EXPORT std::string GetNameFromProperties( 42 const std::string& service_path, 43 const base::DictionaryValue& properties); 44 45// Returns the UIData specified by |value|. Returns NULL if the value cannot be 46// parsed. 47scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value); 48 49// Returns the NetworkUIData parsed from the UIData property of 50// |shill_dictionary|. If parsing fails or the field doesn't exist, returns 51// NULL. 52scoped_ptr<NetworkUIData> GetUIDataFromProperties( 53 const base::DictionaryValue& shill_dictionary); 54 55// Sets the UIData property in |shill_dictionary| to the serialization of 56// |ui_data|. 57void SetUIData(const NetworkUIData& ui_data, 58 base::DictionaryValue* shill_dictionary); 59 60// Copy configuration properties required by Shill to identify a network in the 61// format that Shill expects on writes. 62// Only WiFi, VPN, Ethernet and EthernetEAP are supported. Wimax and Cellular 63// are not supported. 64// If |properties_read_from_shill| is true, it is assumed that 65// |service_properties| has the format that Shill exposes on reads, as opposed 66// to property dictionaries which are sent to Shill. Returns true only if all 67// required properties could be copied. 68bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, 69 const bool properties_read_from_shill, 70 base::DictionaryValue* dest); 71 72// Compares the identifying configuration properties of |new_properties| and 73// |old_properties|, returns true if they are identical. |new_properties| must 74// have the form that Shill expects on writes. |old_properties| must have the 75// form that Shill exposes on reads. See also CopyIdentifyingProperties. Only 76// WiFi, VPN, Ethernet and EthernetEAP are supported. Wimax and Cellular are not 77// supported. 78bool DoIdentifyingPropertiesMatch( 79 const base::DictionaryValue& new_properties, 80 const base::DictionaryValue& old_properties); 81 82// Returns true if |key| corresponds to a passphrase property. 83bool IsPassphraseKey(const std::string& key); 84 85// Parses |value| (which should be a Dictionary). Returns true and sets 86// |home_provider_id| if |value| was succesfully parsed. 87bool GetHomeProviderFromProperty(const base::Value& value, 88 std::string* home_provider_id); 89 90} // namespace shill_property_util 91 92} // namespace chromeos 93 94#endif // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_ 95