1 // Copyright 2013 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.
5 #include "cloud_print/gcp20/prototype/command_line_reader.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "cloud_print/gcp20/prototype/gcp20_switches.h"
12 namespace command_line_reader {
14 uint16 ReadHttpPort(uint16 default_value) {
17 std::string http_port_string =
18 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
21 if (!base::StringToUint(http_port_string, &http_port))
22 http_port = default_value;
24 if (http_port > kuint16max) {
25 LOG(ERROR) << "HTTP Port is too large";
26 http_port = default_value;
29 VLOG(1) << "HTTP port for responses: " << http_port;
30 return static_cast<uint16>(http_port);
33 uint32 ReadTtl(uint32 default_value) {
36 if (!base::StringToUint(
37 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kTtl),
42 VLOG(1) << "TTL for announcements: " << ttl;
46 std::string ReadServiceNamePrefix(const std::string& default_value) {
47 std::string service_name =
48 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
49 switches::kServiceName);
51 return service_name.empty() ? default_value : service_name;
54 std::string ReadDomainName(const std::string& default_value) {
55 std::string domain_name =
56 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
57 switches::kDomainName);
59 if (domain_name.empty())
62 std::string suffix = ".local";
63 if (domain_name == suffix) {
64 LOG(ERROR) << "Domain name cannot be only \"" << suffix << "\"";
68 if (domain_name.size() < suffix.size() ||
69 domain_name.substr(domain_name.size() - suffix.size()) != suffix) {
70 LOG(ERROR) << "Domain name should end with \"" << suffix << "\"";
77 std::string ReadStatePath(const std::string& default_value) {
78 std::string filename = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
79 switches::kStatePath);
86 } // namespace command_line_reader