OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/api/vpn_provider/vpn_provider_api.h" | 5 #include "extensions/browser/api/vpn_provider/vpn_provider_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const char kCIDRSeperator[] = "/"; | 25 const char kCIDRSeperator[] = "/"; |
26 | 26 |
27 bool CheckIPCIDRSanity(const std::string& value, bool cidr, bool ipv6) { | 27 bool CheckIPCIDRSanity(const std::string& value, bool cidr, bool ipv6) { |
28 int dots = ipv6 ? 0 : 3; | 28 int dots = ipv6 ? 0 : 3; |
29 int sep = cidr ? 1 : 0; | 29 int sep = cidr ? 1 : 0; |
30 int colon = ipv6 ? 7 : 0; | 30 int colon = ipv6 ? 7 : 0; |
31 bool hex_allowed = ipv6; | 31 bool hex_allowed = ipv6; |
32 int counter = 0; | 32 int counter = 0; |
33 | 33 |
34 for (const auto& elem : value) { | 34 for (const auto& elem : value) { |
35 if (IsAsciiDigit(elem)) { | 35 if (base::IsAsciiDigit(elem)) { |
36 counter++; | 36 counter++; |
37 continue; | 37 continue; |
38 } | 38 } |
39 if (elem == '.') { | 39 if (elem == '.') { |
40 if (!dots) | 40 if (!dots) |
41 return false; | 41 return false; |
42 dots--; | 42 dots--; |
43 } else if (elem == kCIDRSeperator[0]) { | 43 } else if (elem == kCIDRSeperator[0]) { |
44 if (!sep || dots || colon == 7 || !counter) | 44 if (!sep || dots || colon == 7 || !counter) |
45 return false; | 45 return false; |
46 // Separator observed, no more dots and colons, only digits are allowed | 46 // Separator observed, no more dots and colons, only digits are allowed |
47 // after observing separator. So setting hex_allowed to false. | 47 // after observing separator. So setting hex_allowed to false. |
48 sep--; | 48 sep--; |
49 counter = 0; | 49 counter = 0; |
50 colon = 0; | 50 colon = 0; |
51 hex_allowed = false; | 51 hex_allowed = false; |
52 } else if (elem == ':') { | 52 } else if (elem == ':') { |
53 if (!colon) | 53 if (!colon) |
54 return false; | 54 return false; |
55 colon--; | 55 colon--; |
56 } else if (!hex_allowed || !IsHexDigit(elem)) { | 56 } else if (!hex_allowed || !base::IsHexDigit(elem)) { |
57 return false; | 57 return false; |
58 } else { | 58 } else { |
59 counter++; | 59 counter++; |
60 } | 60 } |
61 } | 61 } |
62 return !sep && !dots && (colon < 7) && counter; | 62 return !sep && !dots && (colon < 7) && counter; |
63 } | 63 } |
64 | 64 |
65 bool CheckIPCIDRSanityList(const std::vector<std::string>& list, | 65 bool CheckIPCIDRSanityList(const std::vector<std::string>& list, |
66 bool cidr, | 66 bool cidr, |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 SignalCallCompletionSuccess, | 318 SignalCallCompletionSuccess, |
319 this), | 319 this), |
320 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 320 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
321 SignalCallCompletionFailure, | 321 SignalCallCompletionFailure, |
322 this)); | 322 this)); |
323 | 323 |
324 return RespondLater(); | 324 return RespondLater(); |
325 } | 325 } |
326 | 326 |
327 } // namespace extensions | 327 } // namespace extensions |
OLD | NEW |