Commit 777602be authored by Piotr Pawliczek's avatar Piotr Pawliczek Committed by Commit Bot

External Print Servers: Bugfix for ipp/ipps based URLs without port

When an URL of a print server is specified with ipp/ipps schema and
without a port number, ChromeOS tries to contact the server on port 80.
It is caused by the fact that internally URLs are stored as http/https
based versions (because of GURL limitations). This patch solves the
problem by improving conversion between http(s) and ipp(s).

BUG=none
TEST=tested on nautilus

Change-Id: I19c55ece15a07103556c882caa56ed77b45bac1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1780073
Commit-Queue: Sean Kau <skau@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Auto-Submit: Piotr Pawliczek <pawliczek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694603}
parent bebe5295
......@@ -106,8 +106,10 @@ TaskResults ParseData(int task_id, std::unique_ptr<std::string> data) {
// context of IPP interface. Moreover, the URL must have http/https scheme
// to pass IsStandard() test from GURL library (see "Validation of the URL
// address" below).
bool replaced_ipp_schema = false;
if (gurl.SchemeIs("ipp")) {
gurl = GURL("http" + url->substr(url->find_first_of(':')));
replaced_ipp_schema = true;
} else if (gurl.SchemeIs("ipps")) {
gurl = GURL("https" + url->substr(url->find_first_of(':')));
}
......@@ -117,6 +119,15 @@ TaskResults ParseData(int task_id, std::unique_ptr<std::string> data) {
<< "The following URL is invalid: " << *url;
continue;
}
// The default port for ipp is 631. If the schema ipp is replaced by http
// and the port is not explicitly defined in the url, we have to overwrite
// the default http port with the default ipp port. For ipps we do nothing
// because implementers use the same port for ipps and https.
if (replaced_ipp_schema && gurl.IntPort() == url::PORT_UNSPECIFIED) {
GURL::Replacements replacement;
replacement.SetPortStr("631");
gurl = gurl.ReplaceComponents(replacement);
}
// Checks if a set of URLs contains this URL. If not, the URL is added to
// the set. Otherwise, a warning is emitted and the record is skipped.
if (!print_server_urls.insert(gurl).second) {
......
......@@ -23,7 +23,7 @@ constexpr char kPrintServersPolicyJson1[] = R"json(
"url": "ipp://192.168.1.5"
}, {
"display_name": "Server API",
"url":"ipps://print-server.intra.example.com:443/ipp/cl2k4"
"url":"ipps://print-server.intra.example.com:444/ipp/cl2k4"
}, {
"display_name": "YaLP",
"url": "http://192.168.1.8/bleble/print"
......@@ -32,8 +32,8 @@ constexpr char kPrintServersPolicyJson1[] = R"json(
// Corresponding vector with PrintServers.
const std::vector<PrintServer> kPrintServersPolicyData1 = {
{GURL("http://192.168.1.5"), "MyPrintServer"},
{GURL("https://print-server.intra.example.com:443/ipp/cl2k4"),
{GURL("http://192.168.1.5:631"), "MyPrintServer"},
{GURL("https://print-server.intra.example.com:444/ipp/cl2k4"),
"Server API"},
{GURL("http://192.168.1.8/bleble/print"), "YaLP"}};
......@@ -48,7 +48,7 @@ constexpr char kPrintServersPolicyJson2[] = R"json(
// Corresponding vector with PrintServers.
const std::vector<PrintServer> kPrintServersPolicyData2 = {
{GURL("http://192.168.1.15"), "CUPS"}};
{GURL("http://192.168.1.15:631"), "CUPS"}};
// Another configuration file with print servers, this time with invalid URLs.
constexpr char kPrintServersPolicyJson3[] = R"json(
......@@ -74,12 +74,13 @@ constexpr char kPrintServersPolicyJson3[] = R"json(
}
])json";
// Corresponding vector with PrintServers. Only the first record is included,
// Corresponding vector with PrintServers. Only two records are included,
// because other ones are invalid:
// server_1 - OK
// server_2 - invalid URL - invalid port number
// server_3 - unsupported scheme
// server_4 - duplicate of server_1
// server_5 - leading whitespaces, they should be trimmed
// server_5 - leading whitespaces, but OK
// server_6 - invalid URL - forbidden character
const std::vector<PrintServer> kPrintServersPolicyData3 = {
{GURL("http://aaa.bbb.ccc:666/xx"), "server_1"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment