#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;
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 = …;
constexpr char kJobUri[] = …;
constexpr char kJobId[] = …;
constexpr char kJobState[] = …;
constexpr char kJobStateReasons[] = …;
constexpr char kJobStateMessage[] = …;
constexpr char kJobImpressionsCompleted[] = …;
constexpr char kTimeAtProcessing[] = …;
constexpr char kRequestedAttributes[] = …;
constexpr char kWhichJobs[] = …;
constexpr char kLimit[] = …;
constexpr char kCompleted[] = …;
constexpr char kNotCompleted[] = …;
constexpr char kIppEverywhere[] = …;
constexpr char kJobCompletedWithErrors[] = …;
constexpr char kCupsHeldForAuthentication[] = …;
constexpr char kSeverityReport[] = …;
constexpr char kSeverityWarn[] = …;
constexpr char kSeverityError[] = …;
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[] = …;
constexpr int kHttpConnectTimeoutMs = …;
constexpr std::array<const char* const, 3> kPrinterAttributes{ … };
constexpr std::array<const char* const, 9> kPrinterInfoAndStatus{ … };
CupsJob::JobState ToJobState(ipp_attribute_t* attr) { … }
PrinterStatus::PrinterReason::Reason ToReason(std::string_view reason) { … }
PSeverity ToSeverity(std::string_view severity) { … }
PrinterStatus::PrinterReason ToPrinterReason(std::string_view reason) { … }
void ParseCollection(ipp_attribute_t* attr,
std::vector<std::string>* collection) { … }
void ParseField(ipp_attribute_t* attr, std::string_view name, CupsJob* job) { … }
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) { … }
bool ParsePrinterInfo(ipp_t* response, PrinterInfo* printer_info) { … }
bool StatusError(ipp_status_e status) { … }
}
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) { … }
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) { … }
}