1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
#define CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
#include <string>
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
namespace base {
class DictionaryValue;
class Value;
}
namespace chromeos {
class NetworkUIData;
namespace shill_property_util {
// Sets the |ssid| in |properties|.
CHROMEOS_EXPORT void SetSSID(const std::string ssid,
base::DictionaryValue* properties);
// Returns the SSID from |properties| in UTF-8 encoding. If |unknown_encoding|
// is not NULL, it is set to whether the SSID is of unknown encoding.
CHROMEOS_EXPORT std::string GetSSIDFromProperties(
const base::DictionaryValue& properties,
bool* unknown_encoding);
// Returns the GUID (if available), SSID, or Name from |properties|. Only used
// for logging and debugging.
CHROMEOS_EXPORT std::string GetNetworkIdFromProperties(
const base::DictionaryValue& properties);
// Returns the name for the network represented by the Shill |properties|. For
// WiFi it refers to the HexSSID.
CHROMEOS_EXPORT std::string GetNameFromProperties(
const std::string& service_path,
const base::DictionaryValue& properties);
// Returns the UIData specified by |value|. Returns NULL if the value cannot be
// parsed.
scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value);
// Returns the NetworkUIData parsed from the UIData property of
// |shill_dictionary|. If parsing fails or the field doesn't exist, returns
// NULL.
scoped_ptr<NetworkUIData> GetUIDataFromProperties(
const base::DictionaryValue& shill_dictionary);
// Sets the UIData property in |shill_dictionary| to the serialization of
// |ui_data|.
void SetUIData(const NetworkUIData& ui_data,
base::DictionaryValue* shill_dictionary);
// Copy configuration properties required by Shill to identify a network.
// Only WiFi, VPN, Ethernet and EthernetEAP are supported. WiMax and Cellular
// are not supported. Returns true only if all required properties could be
// copied.
bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
base::DictionaryValue* dest);
// Compares the identifying configuration properties of |properties_a| and
// |properties_b|, returns true if they are identical. See also
// CopyIdentifyingProperties. Only WiFi, VPN, Ethernet and EthernetEAP are
// supported. WiMax and Cellular are not supported.
bool DoIdentifyingPropertiesMatch(const base::DictionaryValue& properties_a,
const base::DictionaryValue& properties_b);
// Returns true if |key| corresponds to a passphrase property.
bool IsPassphraseKey(const std::string& key);
} // namespace shill_property_util
class CHROMEOS_EXPORT NetworkTypePattern {
public:
// Matches any network.
static NetworkTypePattern Default();
// Matches wireless networks
static NetworkTypePattern Wireless();
// Matches cellular or wimax networks.
static NetworkTypePattern Mobile();
// Matches non virtual networks.
static NetworkTypePattern NonVirtual();
// Matches ethernet networks (with or without EAP).
static NetworkTypePattern Ethernet();
static NetworkTypePattern WiFi();
static NetworkTypePattern Cellular();
static NetworkTypePattern VPN();
static NetworkTypePattern Wimax();
// Matches only networks of exactly the type |shill_network_type|, which must
// be one of the types defined in service_constants.h (e.g.
// shill::kTypeWifi).
// Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
// unsure, better use one of the matchers above.
static NetworkTypePattern Primitive(const std::string& shill_network_type);
bool Equals(const NetworkTypePattern& other) const;
bool MatchesType(const std::string& shill_network_type) const;
// Returns true if this pattern matches at least one network type that
// |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
// symmetric and reflexive but not transitive.
// See the unit test for examples.
bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
std::string ToDebugString() const;
private:
explicit NetworkTypePattern(int pattern);
// The bit array of the matching network types.
int pattern_;
DISALLOW_ASSIGN(NetworkTypePattern);
};
} // namespace chromeos
#endif // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
|