Index: net/base/ip_pattern.h |
diff --git a/net/base/ip_pattern.h b/net/base/ip_pattern.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..90a72c8f22628baa2280cf2944aa92b5aaf55e69 |
--- /dev/null |
+++ b/net/base/ip_pattern.h |
@@ -0,0 +1,65 @@ |
+// Copyright (c) 2014 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 NET_BASE_IP_PATTERN_H_ |
+#define NET_BASE_IP_PATTERN_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/strings/string_piece.h" |
+#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.
|
+#include "net/base/net_export.h" |
+ |
+namespace net { |
+ |
+// IPPatterns are used to match IP address resolutions for possible augmentation |
+// by a MappedIPResolver, which uses IPMappingRules. |
+class NET_EXPORT IPPattern { |
+ public: |
+ IPPattern(); |
+ ~IPPattern(); |
+ |
+ bool ParsePattern(const std::string& ip_pattern); |
+ 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.
|
+ |
+ bool is_ipv4() const { return is_ipv4_; } |
+ |
+ private: |
+ class ComponentPattern; |
+ typedef std::vector<std::string> Strings; |
+ // IPv6 addresses have 8 components, while IPv4 addresses have 4 components. |
+ // ComponentPattern is used to define patterns to match individual components. |
+ bool ParseComponentPattern(const std::string& text, |
+ ComponentPattern* pattern) const; |
+ // Convert IP component to an int. Assume hex vs decimal for IPV6 vs V4. |
+ 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
|
+ |
+ bool is_ipv4_; |
+ // 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.
|
+ // exact match (OCTET in IPv4, or 4 hex digits in IPv6). |
+ // For each true element there is an entry in |component_values_|, and false |
+ // means that an entry from our list of ComponentPattern instances must be |
+ // applied. |
+ std::vector<bool> ip_mask_; |
+ // The vector of fixed values that are requried. |
+ // Other values may be restricted by the component_patterns_; |
+ // The class invariant is: |
+ // ip_mask_.size() == component_patterns_.size() |
+ // + size(our ComponentPattern list) |
+ std::vector<uint32> component_values_; |
+ // The head of our linked list of ComponentPatterns. |
+ // If only one component position was specified using a range, then this |
+ // list will only have 1 element (i.e., we only have patterns for each element |
+ // of ip_mask_ that is false.) |
+ // We own these elements, and need to destroy them all when we are destroyed. |
+ 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.
|
+ 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.
|
+}; |
+ |
+ |
wtc
2014/02/11 23:52:30
Nit: delete one blank line.
jar (doing other things)
2014/02/15 21:14:56
Done.
|
+} // namespace net |
+ |
+#endif // NET_BASE_IP_PATTERN_H_ |