chromium/printing/backend/cups_helper.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "printing/backend/cups_helper.h"

#include <cups/ppd.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>

#include <optional>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "printing/backend/cups_deleters.h"
#include "printing/backend/cups_weak_functions.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
#include "printing/mojom/print.mojom.h"
#include "printing/print_job_constants_cups.h"
#include "printing/printing_utils.h"
#include "printing/units.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"

EqualsCaseInsensitiveASCII;

namespace printing {

// This section contains helper code for PPD parsing for semantic capabilities.
namespace {

// Timeout for establishing a CUPS connection.  It is expected that cupsd is
// able to start and respond on all systems within this duration.
constexpr base::TimeDelta kCupsTimeout =;

// CUPS default max copies value (parsed from kCupsMaxCopies PPD attribute).
constexpr int32_t kDefaultMaxCopies =;
constexpr char kCupsMaxCopies[] =;

constexpr char kColorDevice[] =;

constexpr char kDuplex[] =;
constexpr char kDuplexNone[] =;
constexpr char kDuplexNoTumble[] =;
constexpr char kDuplexTumble[] =;
constexpr char kPageSize[] =;

// Brother printer specific options.
constexpr char kBrotherDuplex[] =;

int32_t GetCopiesMax(ppd_file_t* ppd) {}

std::pair<std::vector<mojom::DuplexMode>, mojom::DuplexMode> GetDuplexSettings(
    ppd_file_t* ppd) {}

std::optional<gfx::Size> ParseResolutionString(const char* input) {}

std::pair<std::vector<gfx::Size>, gfx::Size> GetResolutionSettings(
    ppd_file_t* ppd) {}

bool GetBasicColorModelSettings(ppd_file_t* ppd,
                                mojom::ColorModel* color_model_for_black,
                                mojom::ColorModel* color_model_for_color,
                                bool* color_is_default) {}

bool GetPrintOutModeColorSettings(ppd_file_t* ppd,
                                  mojom::ColorModel* color_model_for_black,
                                  mojom::ColorModel* color_model_for_color,
                                  bool* color_is_default) {}

bool GetColorModeSettings(ppd_file_t* ppd,
                          mojom::ColorModel* color_model_for_black,
                          mojom::ColorModel* color_model_for_color,
                          bool* color_is_default) {}

bool GetBrotherColorSettings(ppd_file_t* ppd,
                             mojom::ColorModel* color_model_for_black,
                             mojom::ColorModel* color_model_for_color,
                             bool* color_is_default) {}

bool GetHPColorSettings(ppd_file_t* ppd,
                        mojom::ColorModel* color_model_for_black,
                        mojom::ColorModel* color_model_for_color,
                        bool* color_is_default) {}

bool GetHPColorModeSettings(ppd_file_t* ppd,
                            mojom::ColorModel* color_model_for_black,
                            mojom::ColorModel* color_model_for_color,
                            bool* color_is_default) {}

bool GetHpPjlColorAsGrayModeSettings(ppd_file_t* ppd,
                                     mojom::ColorModel* color_model_for_black,
                                     mojom::ColorModel* color_model_for_color,
                                     bool* color_is_default) {}

bool GetCanonCNColorModeSettings(ppd_file_t* ppd,
                                 mojom::ColorModel* color_model_for_black,
                                 mojom::ColorModel* color_model_for_color,
                                 bool* color_is_default) {}

bool GetCanonCNIJGrayscaleSettings(ppd_file_t* ppd,
                                   mojom::ColorModel* color_model_for_black,
                                   mojom::ColorModel* color_model_for_color,
                                   bool* color_is_default) {}

bool GetEpsonInkSettings(ppd_file_t* ppd,
                         mojom::ColorModel* color_model_for_black,
                         mojom::ColorModel* color_model_for_color,
                         bool* color_is_default) {}

bool GetKonicaMinoltaSelectColorSettings(
    ppd_file_t* ppd,
    mojom::ColorModel* color_model_for_black,
    mojom::ColorModel* color_model_for_color,
    bool* color_is_default) {}

bool GetLexmarkBLWSettings(ppd_file_t* ppd,
                           mojom::ColorModel* color_model_for_black,
                           mojom::ColorModel* color_model_for_color,
                           bool* color_is_default) {}

bool GetOkiSettings(ppd_file_t* ppd,
                    mojom::ColorModel* color_model_for_black,
                    mojom::ColorModel* color_model_for_color,
                    bool* color_is_default) {}

bool GetSharpARCModeSettings(ppd_file_t* ppd,
                             mojom::ColorModel* color_model_for_black,
                             mojom::ColorModel* color_model_for_color,
                             bool* color_is_default) {}

bool GetXeroxColorSettings(ppd_file_t* ppd,
                           mojom::ColorModel* color_model_for_black,
                           mojom::ColorModel* color_model_for_color,
                           bool* color_is_default) {}

bool GetXeroxOutputColorSettings(ppd_file_t* ppd,
                                 mojom::ColorModel* color_model_for_black,
                                 mojom::ColorModel* color_model_for_color,
                                 bool* color_is_default) {}

bool GetProcessColorModelSettings(ppd_file_t* ppd,
                                  mojom::ColorModel* color_model_for_black,
                                  mojom::ColorModel* color_model_for_color,
                                  bool* color_is_default) {}

bool GetColorModelSettings(ppd_file_t* ppd,
                           mojom::ColorModel* cm_black,
                           mojom::ColorModel* cm_color,
                           bool* is_color) {}

// Default port for IPP print servers.
const int kDefaultIPPServerPort =;

}  // namespace

// Helper wrapper around http_t structure, with connection and cleanup
// functionality.
HttpConnectionCUPS::HttpConnectionCUPS(const GURL& print_server_url,
                                       http_encryption_t encryption,
                                       bool blocking) {}

HttpConnectionCUPS::~HttpConnectionCUPS() = default;

http_t* HttpConnectionCUPS::http() {}

bool ParsePpdCapabilities(cups_dest_t* dest,
                          std::string_view locale,
                          std::string_view printer_capabilities,
                          PrinterSemanticCapsAndDefaults* printer_info) {}

ScopedHttpPtr HttpConnect2(const char* host,
                           int port,
                           http_addrlist_t* addrlist,
                           int family,
                           http_encryption_t encryption,
                           int blocking,
                           int msec,
                           int* cancel) {}

}  // namespace printing