photocraft/crates/ipp
Diego Chagas 235e7578f3
Print through CUPS over IPP and the print portal, so File › Print works in the Flatpak (#2728) (#3017)
Main prints through craft-print, which runs `lp`; a Flatpak has no `lp`,
so File › Print fails there. This keeps craft-print as the route wherever
`lp` is on the path (and on Windows) and adds two more behind it:

- `photocraft-ipp`, a pure-Rust IPP client (CUPS-Get-Printers/Classes/
  Default, Print-Job over HTTP/1.1) that talks to CUPS over its socket or
  TCP; the Flatpak manifests grant --socket=cups for it. A `printServer`
  named in the request always takes this route. `file.print.printers`
  lists the queues.
- The XDG Print portal as the app's spooler (`Session::print_spooler`),
  for a sandbox without the CUPS socket or a system without a printer:
  the system print dialog, seeded with copies, paper and orientation.
  PHOTOCRAFT_PRINT_PORTAL=1 prefers it, =0 removes it.

A route that exists but fails (unknown printer, refused job) is an error;
only a missing route moves on. Results gain `backend` (lp, windows, ipp,
portal). docs/printing.md describes the routes.
2026-10-17 15:55:54 -06:00
..
src Print through CUPS over IPP and the print portal, so File › Print works in the Flatpak (#2728) (#3017) 2026-10-17 15:55:54 -06:00
Cargo.toml Print through CUPS over IPP and the print portal, so File › Print works in the Flatpak (#2728) (#3017) 2026-10-17 15:55:54 -06:00
README.md Print through CUPS over IPP and the print portal, so File › Print works in the Flatpak (#2728) (#3017) 2026-10-17 15:55:54 -06:00

photocraft-ipp

A small IPP (Internet Printing Protocol, RFC 8010/8011) client for the local CUPS server, in pure Rust with no dependencies. It does in-process what lp does from the command line, so PhotoCraft can print where there is no lp binary (a Flatpak sandbox with --socket=cups, a minimal container) and can read the printer list and the default printer first instead of handing CUPS's errors to the user.

let ep = photocraft_ipp::Endpoint::detect().ok_or("no CUPS server")?;   // socket, then localhost:631
let printers = photocraft_ipp::printers(&ep)?;                            // name, info, state, default
let id = photocraft_ipp::print_job(&ep, &photocraft_ipp::Job { printer: "Office", title: "photo", user: "me", copies: 2, document: &pdf, format: "application/pdf" })?;

Three operations: CUPS-Get-Printers, CUPS-Get-Default, Print-Job. HTTP/1.1 over the CUPS domain socket (/run/cups/cups.sock, or CUPS_SERVER as a path) or TCP (localhost:631, or CUPS_SERVER as host[:port]), chunked replies included. Replies are capped at 16 MiB and parsed with bounds checks; an IPP error status becomes Error::Status with the server's own message. Tests run against an in-process fake server over TCP and a Unix socket.

Standalone: it depends on no other PhotoCraft crate. Used by photocraft-engine's print commands on Unix; Windows printing lives in photocraft-winprint.