ippsrv

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package ippsrv implements an IPP server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDriver is returned when the printer does not have a driver set.
	ErrNoDriver = errors.New("no driver set for printer")
	// ErrEmptyData is returned when the data to print is empty.
	ErrEmptyData = errors.New("data cannot be empty")
	// ErrNoImages is returned when the data could not be converted to any
	// images.
	ErrNoImages = errors.New("no images were converted from the data")
	// ErrPrintOptionsUnsupported is returned when a printer cannot honor
	// options attached to an IPP print job.
	ErrPrintOptionsUnsupported = errors.New("printer does not support print job options")
)
View Source
var MaxDocumentSize int64 = 104857600

Functions

This section is empty.

Types

type Driver

type Driver interface {
	// SetOptions should set the options for the driver. Options can include
	// thermal printing options such as energy level, print delay, etc.
	// It should return an error if the options are invalid or cannot be set.
	SetOptions(opt ...thermoprint.Option) error
	// PrintImage should print the given image to the printer. The image can be
	// in any format and size, driver should handle the resizing and dithering.
	PrintImage(ctx context.Context, img image.Image) error
	// DPI should return the printer's DPI (dots per inch) setting, which is
	// used to determine the resolution of the printed output.
	DPI() float64
	// Width should return the width of the printer in pixels. This is used to
	// determine the width of the printed output.
	Width() int
}

type Filter

type Filter interface {
	// ToRaster converts the postscript data to a printable format.
	// It returns a slice of images, each representing a page.
	ToRaster(ctx context.Context, dpi int, data []byte) ([]image.Image, error)
	// Type returns the type of the filter, e.g. "ImageMagick", "Ghostscript",
	// etc.
	Type() string
}

type IPPHandler

type IPPHandler interface {
	ServeIPP(ctx context.Context, req *goipp.Message, body []byte) (resp *goipp.Message, err error)
}

type IPPHandlerFunc

type IPPHandlerFunc func(ctx context.Context, req *goipp.Message, body []byte) (resp *goipp.Message, err error)

func (IPPHandlerFunc) ServeIPP

func (f IPPHandlerFunc) ServeIPP(ctx context.Context, req *goipp.Message, body []byte) (resp *goipp.Message, err error)

type Job

type Job struct {
	ID           JobID
	Printer      Printer // Printer that this job is associated with
	State        JobState
	StateReasons []JobStateReason // Reasons for the current job state
	Name         string
	Created      time.Time
	Processing   time.Time
	Completed    time.Time
	Username     string // Username of the user who created the job
	JobURI       string // URL to access the job, e.g., "/printers/default/123"
	PrinterURI   string // URI of the printer, e.g., "/printers/default"
	Format       string // document-format of the job data, if provided by the client
	// contains filtered or unexported fields
}

func (*Job) IsActive

func (j *Job) IsActive() bool

func (*Job) IsCompleted

func (j *Job) IsCompleted() bool

func (*Job) Snapshot added in v0.3.0

func (j *Job) Snapshot() JobSnapshot

Snapshot returns a stable copy of the job without exposing mutable slices.

type JobID

type JobID int32

type JobSnapshot added in v0.3.0

type JobSnapshot struct {
	ID           JobID
	PrinterName  string
	State        JobState
	StateReasons []JobStateReason
	Name         string
	Created      time.Time
	Processing   time.Time
	Completed    time.Time
	Username     string
	JobURI       string
	PrinterURI   string
	Format       string
}

JobSnapshot is a stable copy of a spooled job.

type JobState

type JobState int32

JobState represents the state of a job. https://datatracker.ietf.org/doc/html/rfc2911#section-4.3.7

const (
	JobPending JobState = iota + 3
	JobPendingHeld
	JobProcessing
	JobProcessingStopped
	JobCancelled
	JobAborted
	JobCompleted
)

func (JobState) String

func (i JobState) String() string

type JobStateReason

type JobStateReason string

JobStateReason represents the reason for the current job state. https://datatracker.ietf.org/doc/html/rfc2911#section-4.3.8 RFC2911 obsoleted by RFC8011.

const (
	JSRNone                      JobStateReason = "none"
	JSRJobIncoming               JobStateReason = "job-incoming"
	JSRJobDataInsufficient       JobStateReason = "job-data-insufficient"
	JSRDocumentAccessError       JobStateReason = "document-access-error"
	JSRSubmissionInterrupted     JobStateReason = "submission-interrupted"
	JSRJobOutgoing               JobStateReason = "job-outgoing"
	JSRJobHeldUntilSpecified     JobStateReason = "job-held-until-specified"
	JSRResourcesAreNotReady      JobStateReason = "resources-are-not-ready"
	JSRJobQueued                 JobStateReason = "job-queued"
	JSRJobTransforming           JobStateReason = "job-transforming"
	JSRJobPrinting               JobStateReason = "job-printing"
	JSRJobCancelledByUser        JobStateReason = "job-cancelled-by-user"
	JSRJobCancelledByOperator    JobStateReason = "job-cancelled-by-operator"
	JSRJobCancelledAtDevice      JobStateReason = "job-cancelled-at-device"
	JSRAbortedBySystem           JobStateReason = "aborted-by-system"
	JSRUnsupportedCompression    JobStateReason = "unsupported-compression"
	JSRUnsupportedDocumentFormat JobStateReason = "unsupported-document-format"
	JSRDocumentFormatError       JobStateReason = "document-format-error"
	JSRProcessingToStopPoint     JobStateReason = "processing-to-stop-point"
	JSRServiceOffline            JobStateReason = "service-offline"
	JSRJobCompletedSuccessfully  JobStateReason = "job-completed-successfully"
	JSRJobCompletedWithWarnings  JobStateReason = "job-completed-with-warnings"
	JSRJobCompletedWithErrors    JobStateReason = "job-completed-with-errors"
	JSRJobRestartable            JobStateReason = "job-restartable"
	JSRQueuedInDevice            JobStateReason = "queued-in-device"
	JSROther                     JobStateReason = "other"
)

type Option

type Option func(*Server)

Option is the server option.

func WithAdditionalPrinters

func WithAdditionalPrinters(pp ...Printer) Option

func WithBonjour added in v0.1.0

func WithBonjour() Option

WithBonjour enables Bonjour/DNS-SD advertisement of the printers when the server starts listening.

func WithDebug

func WithDebug(b bool) Option

func WithDumpDir

func WithDumpDir(dir string) Option

WithDumpDir allows to set the directory for protocol dumps. If not specified, a temporary directory will be used.

type OptionPrinter added in v0.1.2

type OptionPrinter interface {
	PrintWithOptions(ctx context.Context, data []byte, opts PrintOptions) error
}

OptionPrinter is implemented by printers that can honor per-job print options supplied by the IPP server.

type PrintOptions added in v0.1.2

type PrintOptions struct {
	// TrimTrailingBlank removes trailing blank rows for variable-height roll
	// jobs so the printer stops after the visible content.
	TrimTrailingBlank bool
}

PrintOptions are optional behaviors requested for a single IPP print job.

type Printer

type Printer interface {
	PrinterInformer

	// Print should print the given data to the printer.  Data can be in any
	// format, such as PostScript, PDF, or image. The method should handle
	// conversion to the printer's native format if necessary.
	Print(ctx context.Context, data []byte) error
	// Driver should return the driver used to print the data. The driver
	// should implement the [Driver] interface and handle the actual printing.
	Driver() Driver
}

func WrapDriver

func WrapDriver(drv Driver, id, fullname string, opt ...PrinterOption) (Printer, error)

type PrinterInformer

type PrinterInformer interface {
	// Name should return a url-safe name for the printer (printer-name
	// attribute).
	// Example: "default" or "my-thermal-printer".
	Name() string
	// MakeAndModel should return the full name of the printer, including make
	// and model (printer-make-and-model attribute).
	// Example: "LX-D02 Thermal Printer".
	MakeAndModel() string
	// Info should return a human-readable description of the printer
	// (printer-info attribute).
	// Example: "LX-D02 Thermal Printer with USB and Bluetooth connectivity".
	Info() string
	// State should return the current state of the printer (printer-state
	// attribute), it can be one of the [PrinterState] constants.
	State() PrinterState
	// Ready should return true if the printer is ready to accept jobs. This is
	// used to determine if the printer is ready to print
	// (printer-is-accepting-jobs attribute).
	Ready() bool
	// UpTime should return the number of seconds since the printer was started.
	// This is used to report the printer uptime (printer-up-time attribute).
	UpTime() int
	// Media should return the media type used by the printer
	// (media-supported attribute).
	MediaSupported() []string
	// MediaDefault should return the default media type used by the printer
	// (media-default attribute).
	MediaDefault() string
	// SetState should set the printer state that is returned by the [State]
	// method.
	SetState(state PrinterState) // Set the printer state
	// UUID should return a unique identifier for the printer, used to identify
	// the printer in the system (printer-uuid attribute).
	UUID() string
}

type PrinterOption

type PrinterOption func(*basePrinter) error

func WithFilter

func WithFilter(f Filter) PrinterOption

type PrinterSnapshot added in v0.3.0

type PrinterSnapshot struct {
	Name         string
	MakeAndModel string
	Info         string
	State        PrinterState
	Ready        bool
	UpTime       int
	MediaDefault string
	UUID         string
}

PrinterSnapshot is a stable copy of an IPP printer's public state.

type PrinterState

type PrinterState uint16
const (
	PSIdle PrinterState = iota + 3 // 3 is the value for idle in RFC 2911
	PSProcessing
	PSStopped
)

func (PrinterState) String added in v0.3.0

func (i PrinterState) String() string

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(p Printer, opts ...Option) (*Server, error)

New returns a new IPP server.

func (*Server) DebugServer

func (s *Server) DebugServer(ctx context.Context, addr string) error

func (*Server) Info

func (s *Server) Info(w io.Writer)

Info is the SIGINFO response for the server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Snapshot added in v0.3.0

func (s *Server) Snapshot() ServerSnapshot

Snapshot returns a stable copy of the server state.

type ServerSnapshot added in v0.3.0

type ServerSnapshot struct {
	BaseURL         string
	ListenAddr      string
	Uptime          time.Duration
	Debug           bool
	DumpDir         string
	BonjourEnabled  bool
	MaxDocumentSize int64
	Printers        []PrinterSnapshot
	Jobs            []JobSnapshot
}

ServerSnapshot is a stable, read-only copy of server, printer, and spool state for observers such as terminal dashboards.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL