diff options
author | maksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 13:47:28 +0000 |
---|---|---|
committer | maksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 13:47:28 +0000 |
commit | b05a032357bc917a4545777526c84c855d9c5d85 (patch) | |
tree | dcbfb44621c68d468a52550c31a5f7e3e0afe2fe /cloud_print | |
parent | ae46ea6dde058da7b0d9ed5989404b67ccb47776 (diff) | |
download | chromium_src-b05a032357bc917a4545777526c84c855d9c5d85.zip chromium_src-b05a032357bc917a4545777526c84c855d9c5d85.tar.gz chromium_src-b05a032357bc917a4545777526c84c855d9c5d85.tar.bz2 |
GCP2.0 Device: New parameters for command line: domain-name and service-name.
Moved default variables to Printer.
BUG=
Review URL: https://chromiumcodereview.appspot.com/20150004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print')
-rw-r--r-- | cloud_print/gcp20/prototype/command_line_reader.cc | 54 | ||||
-rw-r--r-- | cloud_print/gcp20/prototype/command_line_reader.h | 8 | ||||
-rw-r--r-- | cloud_print/gcp20/prototype/printer.cc | 17 |
3 files changed, 55 insertions, 24 deletions
diff --git a/cloud_print/gcp20/prototype/command_line_reader.cc b/cloud_print/gcp20/prototype/command_line_reader.cc index a5474e6..0ca8a66 100644 --- a/cloud_print/gcp20/prototype/command_line_reader.cc +++ b/cloud_print/gcp20/prototype/command_line_reader.cc @@ -8,46 +8,66 @@ #include "base/logging.h" #include "base/strings/string_number_conversions.h" -namespace { - -const uint16 kDefaultHttpPort = 10101; -const uint32 kDefaultTTL = 60*60; - -} // namespace - namespace command_line_reader { -uint16 ReadHttpPort() { - uint32 http_port = kDefaultHttpPort; +uint16 ReadHttpPort(uint16 default_value) { + uint32 http_port = 0; std::string http_port_string = CommandLine::ForCurrentProcess()->GetSwitchValueASCII("http-port"); if (!base::StringToUint(http_port_string, &http_port)) - http_port = kDefaultHttpPort; + http_port = default_value; if (http_port > kuint16max) { - LOG(ERROR) << "Port " << http_port << " is too large (maximum is " << - kuint16max << "). Using default port: " << kDefaultHttpPort; - - http_port = kDefaultHttpPort; + LOG(ERROR) << "HTTP Port is too large"; + http_port = default_value; } VLOG(1) << "HTTP port for responses: " << http_port; return static_cast<uint16>(http_port); } -uint32 ReadTtl() { - uint32 ttl = kDefaultTTL; +uint32 ReadTtl(uint32 default_value) { + uint32 ttl = 0; if (!base::StringToUint( CommandLine::ForCurrentProcess()->GetSwitchValueASCII("ttl"), &ttl)) { - ttl = kDefaultTTL; + ttl = default_value; } VLOG(1) << "TTL for announcements: " << ttl; return ttl; } +std::string ReadServiceNamePrefix(const std::string& default_value) { + std::string service_name = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII("service-name"); + + return service_name.empty() ? default_value : service_name; +} + +std::string ReadDomainName(const std::string& default_value) { + std::string domain_name = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII("domain-name"); + + if (domain_name.empty()) + return default_value; + + std::string suffix = ".local"; + if (domain_name == suffix) { + LOG(ERROR) << "Domain name cannot be only \"" << suffix << "\""; + return default_value; + } + + if (domain_name.size() < suffix.size() || + domain_name.substr(domain_name.size() - suffix.size()) != suffix) { + LOG(ERROR) << "Domain name should end with \"" << suffix << "\""; + return default_value; + } + + return domain_name; +} + } // namespace command_line_reader diff --git a/cloud_print/gcp20/prototype/command_line_reader.h b/cloud_print/gcp20/prototype/command_line_reader.h index 1043890..cf2ce0c 100644 --- a/cloud_print/gcp20/prototype/command_line_reader.h +++ b/cloud_print/gcp20/prototype/command_line_reader.h @@ -5,12 +5,16 @@ #ifndef CLOUD_PRINT_GCP20_PROTOTYPE_COMMAND_LINE_READER_H_ #define CLOUD_PRINT_GCP20_PROTOTYPE_COMMAND_LINE_READER_H_ +#include <string> + #include "base/basictypes.h" namespace command_line_reader { -uint16 ReadHttpPort(); -uint32 ReadTtl(); +uint16 ReadHttpPort(uint16 default_value); +uint32 ReadTtl(uint32 default_value); +std::string ReadServiceNamePrefix(const std::string& default_value); +std::string ReadDomainName(const std::string& default_value); } // namespace command_line_reader diff --git a/cloud_print/gcp20/prototype/printer.cc b/cloud_print/gcp20/prototype/printer.cc index 56bcad4..1dc1359 100644 --- a/cloud_print/gcp20/prototype/printer.cc +++ b/cloud_print/gcp20/prototype/printer.cc @@ -27,9 +27,12 @@ const base::FilePath::CharType kPrinterStatePath[] = namespace { +const uint16 kHttpPortDefault = 10101; +const uint32 kTtlDefault = 60*60; + const char kServiceType[] = "_privet._tcp.local"; -const char kServiceNamePrefix[] = "first_gcp20_device"; -const char kServiceDomainName[] = "my-privet-device.local"; +const char kServiceNamePrefixDefault[] = "first_gcp20_device"; +const char kServiceDomainNameDefault[] = "my-privet-device.local"; const char kPrinterName[] = "Google GCP2.0 Prototype"; const char kPrinterDescription[] = "Printer emulator"; @@ -126,7 +129,7 @@ bool Printer::Start() { } VLOG(1) << "Local address: " << net::IPAddressToString(ip); - uint16 port = command_line_reader::ReadHttpPort(); + uint16 port = command_line_reader::ReadHttpPort(kHttpPortDefault); // Starting HTTP server. if (!http_server_.Start(port)) @@ -136,10 +139,14 @@ bool Printer::Start() { reg_info_ = RegistrationInfo(); // Starting DNS-SD server. + std::string service_name_prefix = + command_line_reader::ReadServiceNamePrefix(kServiceNamePrefixDefault); + std::string service_domain_name = + command_line_reader::ReadDomainName(kServiceDomainNameDefault); if (!dns_server_.Start( - ServiceParameters(kServiceType, kServiceNamePrefix, kServiceDomainName, + ServiceParameters(kServiceType, service_name_prefix, service_domain_name, ip, port), - command_line_reader::ReadTtl(), + command_line_reader::ReadTtl(kTtlDefault), CreateTxt())) { http_server_.Shutdown(); return false; |