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

Unified Diff: remoting/jingle_glue/network_settings.cc

Issue 209323002: New policies: enable/disable relay; port range (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed android build. Created 6 years, 8 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/jingle_glue/network_settings.h ('k') | remoting/jingle_glue/network_settings_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/jingle_glue/network_settings.cc
diff --git a/remoting/jingle_glue/network_settings.cc b/remoting/jingle_glue/network_settings.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fd5b24d31a77998119ca3068a5dcde87082e7c8b
--- /dev/null
+++ b/remoting/jingle_glue/network_settings.cc
@@ -0,0 +1,45 @@
+// Copyright 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.
+
+#include "remoting/jingle_glue/network_settings.h"
+
+#include <limits.h>
+#include <stdlib.h>
+
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
+
+namespace remoting {
+
+// static
+ bool NetworkSettings::ParsePortRange(const std::string& port_range,
+ int* out_min_port,
+ int* out_max_port) {
+ 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::TrimWhitespaceASCII(port_range.substr(separator_index + 1),
+ base::TRIM_ALL,
+ &max_port_string);
+
+ unsigned min_port, max_port;
+ if (!base::StringToUint(min_port_string, &min_port) ||
+ !base::StringToUint(max_port_string, &max_port)) {
+ return false;
+ }
+
+ if (min_port == 0 || min_port > max_port || max_port > USHRT_MAX)
+ return false;
+
+ *out_min_port = static_cast<int>(min_port);
+ *out_max_port = static_cast<int>(max_port);
+ return true;
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/jingle_glue/network_settings.h ('k') | remoting/jingle_glue/network_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698