shill_property_util.h revision f2477e01787aa58f445919b809d89e252beef54f
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 name for the network represented by the Shill |properties|. For
35// WiFi it refers to the HexSSID.
36CHROMEOS_EXPORT std::string GetNameFromProperties(
37    const std::string& service_path,
38    const base::DictionaryValue& properties);
39
40// Returns the UIData specified by |value|. Returns NULL if the value cannot be
41// parsed.
42scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value);
43
44// Returns the NetworkUIData parsed from the UIData property of
45// |shill_dictionary|. If parsing fails or the field doesn't exist, returns
46// NULL.
47scoped_ptr<NetworkUIData> GetUIDataFromProperties(
48    const base::DictionaryValue& shill_dictionary);
49
50// Sets the UIData property in |shill_dictionary| to the serialization of
51// |ui_data|.
52void SetUIData(const NetworkUIData& ui_data,
53               base::DictionaryValue* shill_dictionary);
54
55// Copy configuration properties required by Shill to identify a network.
56// Only WiFi, VPN, Ethernet and EthernetEAP are supported. WiMax and Cellular
57// are not supported. Returns true only if all required properties could be
58// copied.
59bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
60                               base::DictionaryValue* dest);
61
62// Compares the identifying configuration properties of |properties_a| and
63// |properties_b|, returns true if they are identical. See also
64// CopyIdentifyingProperties. Only WiFi, VPN, Ethernet and EthernetEAP are
65// supported. WiMax and Cellular are not supported.
66bool DoIdentifyingPropertiesMatch(const base::DictionaryValue& properties_a,
67                                  const base::DictionaryValue& properties_b);
68
69}  // namespace shill_property_util
70
71class CHROMEOS_EXPORT NetworkTypePattern {
72 public:
73  // Matches any network.
74  static NetworkTypePattern Default();
75
76  // Matches wireless networks
77  static NetworkTypePattern Wireless();
78
79  // Matches cellular or wimax networks.
80  static NetworkTypePattern Mobile();
81
82  // Matches non virtual networks.
83  static NetworkTypePattern NonVirtual();
84
85  // Matches ethernet networks (with or without EAP).
86  static NetworkTypePattern Ethernet();
87
88  static NetworkTypePattern WiFi();
89  static NetworkTypePattern Cellular();
90  static NetworkTypePattern VPN();
91  static NetworkTypePattern Wimax();
92
93  // Matches only networks of exactly the type |shill_network_type|, which must
94  // be one of the types defined in service_constants.h (e.g.
95  // shill::kTypeWifi).
96  // Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
97  // unsure, better use one of the matchers above.
98  static NetworkTypePattern Primitive(const std::string& shill_network_type);
99
100  bool Equals(const NetworkTypePattern& other) const;
101  bool MatchesType(const std::string& shill_network_type) const;
102
103  // Returns true if this pattern matches at least one network type that
104  // |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
105  // symmetric and reflexive but not transitive.
106  // See the unit test for examples.
107  bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
108
109  std::string ToDebugString() const;
110
111 private:
112  explicit NetworkTypePattern(int pattern);
113
114  // The bit array of the matching network types.
115  int pattern_;
116
117  DISALLOW_ASSIGN(NetworkTypePattern);
118};
119
120}  // namespace chromeos
121
122#endif  // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
123