Skip to content

Commit

Permalink
Use the full uri for the printer-uri in Get-Printer-Attributes.
Browse files Browse the repository at this point in the history
We've been using the relative path for the printer-uri value in
Get-Printer-Attributes requests.  After further testing, limited
printers support the relative path and require the full uri.

Bug: 753086
Change-Id: I75c6f82b2d62f18a299444d20b13f40d9404b42b
Reviewed-on: https://chromium-review.googlesource.com/613801
Commit-Queue: Sean Kau <skau@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#494532}
  • Loading branch information
Sean Kau authored and Commit Bot committed Aug 15, 2017
1 parent 1d433a4 commit 8d5e7fb
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions printing/backend/cups_jobs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ const char kDeveloperEmpty[] = "developer-empty";
const char kInterpreterResourceUnavailable[] =
"interpreter-resource-unavailable";

constexpr char kIppScheme[] = "ipp";
constexpr char kIppsScheme[] = "ipps";

// Timeout for establishing a HTTP connection in milliseconds. Anecdotally,
// some print servers are slow and can use the extra time.
constexpr int kHttpConnectTimeoutMs = 1000;

constexpr std::array<const char* const, 3> kPrinterAttributes{
{kPrinterState, kPrinterStateReasons, kPrinterStateMessage}};

Expand Down Expand Up @@ -308,7 +315,6 @@ bool ParsePrinterInfo(ipp_t* response, PrinterInfo* printer_info) {
for (ipp_attribute_t* attr = ippFirstAttribute(response); attr != nullptr;
attr = ippNextAttribute(response)) {
base::StringPiece name = ippGetName(attr);

if (name == base::StringPiece(kPrinterMakeAndModel)) {
DCHECK_EQ(IPP_TAG_TEXT, ippGetValueTag(attr));
printer_info->make_and_model = ippGetString(attr, 0, nullptr);
Expand Down Expand Up @@ -388,9 +394,11 @@ ScopedIppPtr GetPrinterAttributes(http_t* http,
: "/" + resource_path;

auto request = WrapIpp(ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES));
// We support IPP up to 2.2 but are compatible down to v1.1.
ippSetVersion(request.get(), 1, 1);

ippAddString(request.get(), IPP_TAG_OPERATION, IPP_TAG_URI, kPrinterUri,
nullptr, printer_uri.data());
nullptr, printer_uri.c_str());

ippAddStrings(request.get(), IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
kRequestedAttributes, num_attributes, nullptr, attributes);
Expand Down Expand Up @@ -434,18 +442,22 @@ bool GetPrinterInfo(const std::string& address,
base::ThreadRestrictions::AssertIOAllowed();

ScopedHttpPtr http = ScopedHttpPtr(httpConnect2(
address.data(), port, nullptr, AF_INET,
address.c_str(), port, nullptr, AF_INET,
encrypted ? HTTP_ENCRYPTION_REQUIRED : HTTP_ENCRYPTION_IF_REQUESTED, 0,
200, nullptr));
kHttpConnectTimeoutMs, nullptr));
if (!http) {
LOG(WARNING) << "Could not connect to host";
return false;
}

std::string printer_uri =
base::StringPrintf("%s://%s:%d/%s", encrypted ? kIppsScheme : kIppScheme,
address.c_str(), port, resource.c_str());

ipp_status_t status;
ScopedIppPtr response =
GetPrinterAttributes(http.get(), resource, resource, kPrinterInfo.size(),
kPrinterInfo.data(), &status);
GetPrinterAttributes(http.get(), printer_uri, resource,
kPrinterInfo.size(), kPrinterInfo.data(), &status);
if (status != IPP_STATUS_OK || response.get() == nullptr) {
LOG(WARNING) << "Get attributes failure: " << status;
return false;
Expand Down Expand Up @@ -485,7 +497,7 @@ bool GetCupsJobs(http_t* http,
auto request = WrapIpp(ippNewRequest(IPP_OP_GET_JOBS));
const std::string printer_uri = PrinterUriFromName(printer_id);
ippAddString(request.get(), IPP_TAG_OPERATION, IPP_TAG_URI, kPrinterUri,
nullptr, printer_uri.data());
nullptr, printer_uri.c_str());
ippAddInteger(request.get(), IPP_TAG_OPERATION, IPP_TAG_INTEGER, kLimit,
limit);

Expand Down

0 comments on commit 8d5e7fb

Please sign in to comment.