OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "cloud_print/gcp20/prototype/command_line_reader.h" | 5 #include "cloud_print/gcp20/prototype/command_line_reader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "cloud_print/gcp20/prototype/gcp20_switches.h" | 10 #include "cloud_print/gcp20/prototype/gcp20_switches.h" |
11 | 11 |
12 namespace command_line_reader { | 12 namespace command_line_reader { |
13 | 13 |
14 uint16 ReadHttpPort(uint16 default_value) { | 14 uint16 ReadHttpPort(uint16 default_value) { |
15 uint32 http_port = 0; | 15 uint32 http_port = 0; |
16 | 16 |
17 std::string http_port_string = | 17 std::string http_port_string = |
18 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 18 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
19 switches::kHttpPort); | 19 switches::kHttpPort); |
20 | 20 |
21 if (!base::StringToUint(http_port_string, &http_port)) | 21 if (!base::StringToUint(http_port_string, &http_port)) |
22 http_port = default_value; | 22 http_port = default_value; |
23 | 23 |
24 if (http_port > kuint16max) { | 24 if (http_port > kuint16max) { |
25 LOG(ERROR) << "HTTP Port is too large"; | 25 LOG(ERROR) << "HTTP Port is too large"; |
26 http_port = default_value; | 26 http_port = default_value; |
27 } | 27 } |
28 | 28 |
29 VLOG(1) << "HTTP port for responses: " << http_port; | 29 VLOG(1) << "HTTP port for responses: " << http_port; |
30 return static_cast<uint16>(http_port); | 30 return static_cast<uint16>(http_port); |
31 } | 31 } |
32 | 32 |
33 uint32 ReadTtl(uint32 default_value) { | 33 uint32 ReadTtl(uint32 default_value) { |
34 uint32 ttl = 0; | 34 uint32 ttl = 0; |
| 35 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
35 | 36 |
36 if (!base::StringToUint( | 37 if (!base::StringToUint( |
37 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kTtl), | 38 command_line->GetSwitchValueASCII(switches::kTtl), |
38 &ttl)) { | 39 &ttl)) { |
39 ttl = default_value; | 40 ttl = default_value; |
40 } | 41 } |
41 | 42 |
42 VLOG(1) << "TTL for announcements: " << ttl; | 43 VLOG(1) << "TTL for announcements: " << ttl; |
43 return ttl; | 44 return ttl; |
44 } | 45 } |
45 | 46 |
46 std::string ReadServiceNamePrefix(const std::string& default_value) { | 47 std::string ReadServiceNamePrefix(const std::string& default_value) { |
47 std::string service_name = | 48 std::string service_name = |
48 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 49 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
49 switches::kServiceName); | 50 switches::kServiceName); |
50 | 51 |
51 return service_name.empty() ? default_value : service_name; | 52 return service_name.empty() ? default_value : service_name; |
52 } | 53 } |
53 | 54 |
54 std::string ReadDomainName(const std::string& default_value) { | 55 std::string ReadDomainName(const std::string& default_value) { |
55 std::string domain_name = | 56 std::string domain_name = |
56 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 57 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
57 switches::kDomainName); | 58 switches::kDomainName); |
58 | 59 |
59 if (domain_name.empty()) | 60 if (domain_name.empty()) |
60 return default_value; | 61 return default_value; |
61 | 62 |
62 std::string suffix = ".local"; | 63 std::string suffix = ".local"; |
63 if (domain_name == suffix) { | 64 if (domain_name == suffix) { |
64 LOG(ERROR) << "Domain name cannot be only \"" << suffix << "\""; | 65 LOG(ERROR) << "Domain name cannot be only \"" << suffix << "\""; |
65 return default_value; | 66 return default_value; |
66 } | 67 } |
67 | 68 |
68 if (domain_name.size() < suffix.size() || | 69 if (domain_name.size() < suffix.size() || |
69 domain_name.substr(domain_name.size() - suffix.size()) != suffix) { | 70 domain_name.substr(domain_name.size() - suffix.size()) != suffix) { |
70 LOG(ERROR) << "Domain name should end with \"" << suffix << "\""; | 71 LOG(ERROR) << "Domain name should end with \"" << suffix << "\""; |
71 return default_value; | 72 return default_value; |
72 } | 73 } |
73 | 74 |
74 return domain_name; | 75 return domain_name; |
75 } | 76 } |
76 | 77 |
77 std::string ReadStatePath(const std::string& default_value) { | 78 std::string ReadStatePath(const std::string& default_value) { |
78 std::string filename = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 79 std::string filename = |
79 switches::kStatePath); | 80 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 81 switches::kStatePath); |
80 | 82 |
81 if (filename.empty()) | 83 if (filename.empty()) |
82 return default_value; | 84 return default_value; |
83 return filename; | 85 return filename; |
84 } | 86 } |
85 | 87 |
86 } // namespace command_line_reader | 88 } // namespace command_line_reader |
87 | 89 |
OLD | NEW |