Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1131)

Unified Diff: remoting/protocol/port_range.cc

Issue 966433002: Malformed PortRange or ThirdPartyAuthConfig trigger OnPolicyError. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing a Windows-specific, pre-processor-related build break. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/port_range.h ('k') | remoting/protocol/port_range_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/port_range.cc
diff --git a/remoting/protocol/network_settings.cc b/remoting/protocol/port_range.cc
similarity index 52%
rename from remoting/protocol/network_settings.cc
rename to remoting/protocol/port_range.cc
index 65068ef951197ce2f76e28c896025f23f6200a0e..ca6408991a6e87bcadc85483dcbe4ebb06188f3a 100644
--- a/remoting/protocol/network_settings.cc
+++ b/remoting/protocol/port_range.cc
@@ -1,8 +1,8 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 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.
-#include "remoting/protocol/network_settings.h"
+#include "remoting/protocol/port_range.h"
#include <limits.h>
#include <stdlib.h>
@@ -11,23 +11,25 @@
#include "base/strings/string_util.h"
namespace remoting {
-namespace protocol {
-// static
- bool NetworkSettings::ParsePortRange(const std::string& port_range,
- uint16* out_min_port,
- uint16* out_max_port) {
+bool PortRange::Parse(const std::string& port_range, PortRange* result) {
+ DCHECK(result);
+
+ if (port_range.empty()) {
+ result->min_port = 0;
+ result->max_port = 0;
+ return true;
+ }
+
size_t separator_index = port_range.find('-');
if (separator_index == std::string::npos)
return false;
std::string min_port_string, max_port_string;
base::TrimWhitespaceASCII(port_range.substr(0, separator_index),
- base::TRIM_ALL,
- &min_port_string);
+ base::TRIM_ALL, &min_port_string);
base::TrimWhitespaceASCII(port_range.substr(separator_index + 1),
- base::TRIM_ALL,
- &max_port_string);
+ base::TRIM_ALL, &max_port_string);
unsigned min_port, max_port;
if (!base::StringToUint(min_port_string, &min_port) ||
@@ -38,10 +40,18 @@ namespace protocol {
if (min_port == 0 || min_port > max_port || max_port > USHRT_MAX)
return false;
- *out_min_port = static_cast<uint16>(min_port);
- *out_max_port = static_cast<uint16>(max_port);
+ result->min_port = static_cast<uint16>(min_port);
+ result->max_port = static_cast<uint16>(max_port);
return true;
}
-} // namespace protocol
+std::ostream& operator<<(std::ostream& os, const PortRange& port_range) {
+ if (port_range.is_null()) {
+ os << "<no port range specified>";
+ } else {
+ os << "[" << port_range.min_port << ", " << port_range.max_port << "]";
+ }
+ return os;
+}
+
} // namespace remoting
« no previous file with comments | « remoting/protocol/port_range.h ('k') | remoting/protocol/port_range_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698