Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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 NET_BASE_IP_PATTERN_H_ | |
| 6 #define NET_BASE_IP_PATTERN_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/strings/string_piece.h" | |
| 13 #include "net/base/address_list.h" | |
|
wtc
2014/02/11 23:52:30
Include "net/base/net_util.h" instead. You just ne
jar (doing other things)
2014/02/15 21:14:56
Done.
| |
| 14 #include "net/base/net_export.h" | |
| 15 | |
| 16 namespace net { | |
| 17 | |
| 18 // IPPatterns are used to match IP address resolutions for possible augmentation | |
| 19 // by a MappedIPResolver, which uses IPMappingRules. | |
| 20 class NET_EXPORT IPPattern { | |
| 21 public: | |
| 22 IPPattern(); | |
| 23 ~IPPattern(); | |
| 24 | |
| 25 bool ParsePattern(const std::string& ip_pattern); | |
| 26 bool Match(const IPAddressNumber& address) const; | |
|
wtc
2014/02/11 23:52:30
Nit: document these two methods.
jar (doing other things)
2014/02/15 21:14:56
Done.
| |
| 27 | |
| 28 bool is_ipv4() const { return is_ipv4_; } | |
| 29 | |
| 30 private: | |
| 31 class ComponentPattern; | |
| 32 typedef std::vector<std::string> Strings; | |
| 33 // IPv6 addresses have 8 components, while IPv4 addresses have 4 components. | |
| 34 // ComponentPattern is used to define patterns to match individual components. | |
| 35 bool ParseComponentPattern(const std::string& text, | |
| 36 ComponentPattern* pattern) const; | |
| 37 // Convert IP component to an int. Assume hex vs decimal for IPV6 vs V4. | |
| 38 bool ValueTextToInt(const base::StringPiece& input, uint32* output) const; | |
|
wtc
2014/02/11 23:52:30
All uses of uint32 in this class probably should b
jar (doing other things)
2014/02/15 21:14:56
It was a mistake... but uint32 is more convenient
| |
| 39 | |
| 40 bool is_ipv4_; | |
| 41 // The |ip_mask_| indicates,for each component, if this pattern requires an | |
|
wtc
2014/02/11 23:52:30
Nit: add a space before "for".
jar (doing other things)
2014/02/15 21:14:56
Done.
| |
| 42 // exact match (OCTET in IPv4, or 4 hex digits in IPv6). | |
| 43 // For each true element there is an entry in |component_values_|, and false | |
| 44 // means that an entry from our list of ComponentPattern instances must be | |
| 45 // applied. | |
| 46 std::vector<bool> ip_mask_; | |
| 47 // The vector of fixed values that are requried. | |
| 48 // Other values may be restricted by the component_patterns_; | |
| 49 // The class invariant is: | |
| 50 // ip_mask_.size() == component_patterns_.size() | |
| 51 // + size(our ComponentPattern list) | |
| 52 std::vector<uint32> component_values_; | |
| 53 // The head of our linked list of ComponentPatterns. | |
| 54 // If only one component position was specified using a range, then this | |
| 55 // list will only have 1 element (i.e., we only have patterns for each element | |
| 56 // of ip_mask_ that is false.) | |
| 57 // We own these elements, and need to destroy them all when we are destroyed. | |
| 58 ComponentPattern* first_component_pattern_; | |
|
Ryan Hamilton
2014/02/12 00:44:03
Ditto here. Instead of implementing the list trav
jar (doing other things)
2014/02/15 21:14:56
Done.
| |
| 59 DISALLOW_COPY_AND_ASSIGN(IPPattern); | |
|
wtc
2014/02/11 23:52:30
Nit: I suggest adding a blank line to separate the
jar (doing other things)
2014/02/15 21:14:56
Done.
| |
| 60 }; | |
| 61 | |
| 62 | |
|
wtc
2014/02/11 23:52:30
Nit: delete one blank line.
jar (doing other things)
2014/02/15 21:14:56
Done.
| |
| 63 } // namespace net | |
| 64 | |
| 65 #endif // NET_BASE_IP_PATTERN_H_ | |
| OLD | NEW |