chromium/printing/backend/cups_jobs.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "printing/backend/cups_jobs.h"

#include <cups/ipp.h>

#include <array>
#include <cstring>
#include <memory>
#include <string>
#include <string_view>

#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/version.h"
#include "printing/backend/cups_deleters.h"
#include "printing/backend/cups_helper.h"
#include "printing/backend/cups_ipp_helper.h"
#include "printing/backend/cups_weak_functions.h"
#include "printing/printer_status.h"

namespace printing {
namespace {

PReason;
PSeverity;

// printer attributes
constexpr char kPrinterUri[] =;
constexpr char kPrinterState[] =;
constexpr char kPrinterStateReasons[] =;
constexpr char kPrinterStateMessage[] =;

constexpr std::string_view kPrinterMakeAndModel =;
constexpr std::string_view kIppVersionsSupported =;
constexpr std::string_view kIppFeaturesSupported =;
constexpr std::string_view kDocumentFormatSupported =;
constexpr std::string_view kOauthAuthorizationServerUri =;
constexpr std::string_view kOauthAuthorizationScope =;

// job attributes
constexpr char kJobUri[] =;
constexpr char kJobId[] =;
constexpr char kJobState[] =;
constexpr char kJobStateReasons[] =;
constexpr char kJobStateMessage[] =;
constexpr char kJobImpressionsCompleted[] =;
constexpr char kTimeAtProcessing[] =;

// request parameters
constexpr char kRequestedAttributes[] =;
constexpr char kWhichJobs[] =;
constexpr char kLimit[] =;

// request values
constexpr char kCompleted[] =;
constexpr char kNotCompleted[] =;

// ipp features
constexpr char kIppEverywhere[] =;

// job state reason values
constexpr char kJobCompletedWithErrors[] =;
constexpr char kCupsHeldForAuthentication[] =;

// printer state severities
constexpr char kSeverityReport[] =;
constexpr char kSeverityWarn[] =;
constexpr char kSeverityError[] =;

// printer state reason values
constexpr char kNone[] =;
constexpr char kMediaNeeded[] =;
constexpr char kMediaJam[] =;
constexpr char kMovingToPaused[] =;
constexpr char kPaused[] =;
constexpr char kShutdown[] =;
constexpr char kConnectingToDevice[] =;
constexpr char kTimedOut[] =;
constexpr char kStopping[] =;
constexpr char kStoppedPartly[] =;
constexpr char kTonerLow[] =;
constexpr char kTonerEmpty[] =;
constexpr char kSpoolAreaFull[] =;
constexpr char kCoverOpen[] =;
constexpr char kInterlockOpen[] =;
constexpr char kDoorOpen[] =;
constexpr char kInputTrayMissing[] =;
constexpr char kMediaLow[] =;
constexpr char kMediaEmpty[] =;
constexpr char kOutputTrayMissing[] =;
constexpr char kOutputAreaAlmostFull[] =;
constexpr char kOutputAreaFull[] =;
constexpr char kMarkerSupplyLow[] =;
constexpr char kMarkerSupplyEmpty[] =;
constexpr char kMarkerWasteAlmostFull[] =;
constexpr char kMarkerWasteFull[] =;
constexpr char kFuserOverTemp[] =;
constexpr char kFuserUnderTemp[] =;
constexpr char kOpcNearEol[] =;
constexpr char kOpcLifeOver[] =;
constexpr char kDeveloperLow[] =;
constexpr char kDeveloperEmpty[] =;
constexpr char kInterpreterResourceUnavailable[] =;
constexpr char kCupsPkiExpired[] =;

constexpr char kIppScheme[] =;
constexpr char kIppsScheme[] =;

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

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

constexpr std::array<const char* const, 9> kPrinterInfoAndStatus{};

// Converts an IPP attribute `attr` to the appropriate JobState enum.
CupsJob::JobState ToJobState(ipp_attribute_t* attr) {}

// Returns the Reason corresponding to the string `reason`.  Returns
// `PReason::kUnknownReason` if the string is not recognized.
PrinterStatus::PrinterReason::Reason ToReason(std::string_view reason) {}

// Returns the Severity corresponding to `severity`.  Returns UNKNOWN_SEVERITY
// if the strin gis not recognized.
PSeverity ToSeverity(std::string_view severity) {}

// Parses the `reason` string into a PrinterReason.  Splits the string based on
// the last '-' to determine severity.  If a recognized severity is not
// included, severity is assumed to be ERROR per RFC2911.
PrinterStatus::PrinterReason ToPrinterReason(std::string_view reason) {}

// Populates `collection` with the collection of strings in `attr`.
void ParseCollection(ipp_attribute_t* attr,
                     std::vector<std::string>* collection) {}

// Parse a field for the CupsJob `job` from IPP attribute `attr` using the
// attribute name `name`.
void ParseField(ipp_attribute_t* attr, std::string_view name, CupsJob* job) {}

// Returns a new CupsJob allocated in `jobs` with `printer_id` populated.
CupsJob* NewJob(const std::string& printer_id, std::vector<CupsJob>* jobs) {}

void ParseJobs(ipp_t* response,
               const std::string& printer_id,
               ipp_attribute_t* starting_attr,
               std::vector<CupsJob>* jobs) {}

// Extracts PrinterInfo fields from `response` and populates `printer_info`.
// Returns true if at least printer-make-and-model and ipp-versions-supported
// were read.
bool ParsePrinterInfo(ipp_t* response, PrinterInfo* printer_info) {}

// Returns true if `status` represents a complete failure in the IPP request.
bool StatusError(ipp_status_e status) {}

}  // namespace

CupsJob::CupsJob() = default;

CupsJob::CupsJob(const CupsJob& other) = default;

CupsJob::~CupsJob() = default;

bool CupsJob::ContainsStateReason(CupsJob::JobStateReason reason) const {}

PrinterInfo::PrinterInfo() = default;

PrinterInfo::~PrinterInfo() = default;

const std::string_view ToJobStateReasonString(
    CupsJob::JobStateReason state_reason) {}

std::string PrinterUriFromName(const std::string& id) {}

void ParseJobsResponse(ipp_t* response,
                       const std::string& printer_id,
                       std::vector<CupsJob>* jobs) {}

// Returns an IPP response for a Get-Printer-Attributes request to `http`.  For
// print servers, `printer_uri` is used as the printer-uri value.
// `resource_path` specifies the path portion of the server URI.
// `num_attributes` is the number of attributes in `attributes` which should be
// a list of IPP attributes.  `status` is updated with status code for the
// request.  A successful request will have the `status` IPP_STATUS_OK.
ScopedIppPtr GetPrinterAttributes(http_t* http,
                                  const std::string& printer_uri,
                                  const std::string& resource_path,
                                  int num_attributes,
                                  const char* const* attributes,
                                  ipp_status_t* status) {}

void ParsePrinterStatus(ipp_t* response, PrinterStatus* printer_status) {}

PrinterQueryResult GetPrinterInfo(const std::string& address,
                                  const int port,
                                  const std::string& resource,
                                  bool encrypted,
                                  PrinterInfo* printer_info,
                                  PrinterStatus* printer_status) {}

bool GetPrinterStatus(http_t* http,
                      const std::string& printer_id,
                      PrinterStatus* printer_status) {}

bool GetCupsJobs(http_t* http,
                 const std::string& printer_id,
                 int limit,
                 JobCompletionState which,
                 std::vector<CupsJob>* jobs) {}

}  // namespace printing