ipp

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ipp is the slice of the Internet Printing Protocol (RFC 8010 and 8011) the print dialog needs from CUPS: list the printers (CUPS-Get-Printers) and send a job (Print-Job), over the CUPS domain socket or CUPS_SERVER. Pure Go; no libcups.

Index

Constants

View Source
const (
	StateIdle       int32 = 3
	StateProcessing int32 = 4
	StateStopped    int32 = 5
)

The printer-state values.

View Source
const (
	OpPrintJob        uint16 = 0x0002
	OpCUPSGetPrinters uint16 = 0x4002
)

Operations.

View Source
const (
	TagInteger   byte = 0x21
	TagBoolean   byte = 0x22
	TagEnum      byte = 0x23
	TagRange     byte = 0x33
	TagText      byte = 0x41
	TagName      byte = 0x42
	TagKeyword   byte = 0x44
	TagURI       byte = 0x45
	TagCharset   byte = 0x47
	TagLanguage  byte = 0x48
	TagMimeMedia byte = 0x49
)

Value tags.

Variables

This section is empty.

Functions

func DefaultServer

func DefaultServer() string

DefaultServer is libcups' server choice: $CUPS_SERVER (a socket path or host[:port]), else the scheduler's domain socket, else localhost:631.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports client-error-not-found (no such printer, or no printers at all for CUPS-Get-Printers).

func PrinterURI

func PrinterURI(name string) string

PrinterURI is the queue's URI as CUPS names it.

func StatusOK

func StatusOK(code uint16) bool

StatusOK reports a successful status (successful-ok and its "ignored or substituted" variants).

Types

type Attr

type Attr struct {
	Name   string
	Values []Value
}

Attr is one named attribute with its values.

func Enum

func Enum(name string, v int32) Attr

Enum is an enum attribute.

func Int

func Int(name string, v int32) Attr

Int is an integer attribute.

func Ranges

func Ranges(name string, rs [][2]int32) Attr

Ranges is a 1-based rangeOfInteger attribute.

func String

func String(tag byte, name string, vs ...string) Attr

String is a text-kind attribute (name, keyword, uri, ...).

type Client

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

Client talks IPP to one CUPS server.

func NewClient

func NewClient(server string) *Client

NewClient addresses server: an absolute socket path or host[:port].

func (*Client) Print

func (c *Client) Print(ctx context.Context, j Job) (int32, error)

Print sends a job (Print-Job) and returns its id.

func (*Client) Printers

func (c *Client) Printers(ctx context.Context) ([]Printer, error)

Printers lists the queues (CUPS-Get-Printers).

type Group

type Group struct {
	Tag   byte
	Attrs []Attr
}

Group is one attribute group.

func (Group) Get

func (g Group) Get(name string) (Attr, bool)

Get is the group's attribute name, false when absent.

func (Group) Int

func (g Group) Int(name string) (int32, bool)

Int is the first value of name as an integer, false when absent.

func (Group) Ints

func (g Group) Ints(name string) []int32

Ints is every value of name as an integer, none when absent.

func (Group) Text

func (g Group) Text(name string) string

Text is the first value of name as text, "" when absent.

func (Group) Texts

func (g Group) Texts(name string) []string

Texts is every value of name as text, none when absent.

type Job

type Job struct {
	Printer, Title, User string
	// Format is the document's MIME type.
	Format string
	// Attrs are the job template attributes (copies, sides, media...).
	Attrs    []Attr
	Document io.Reader
}

Job is one document to spool.

type Message

type Message struct {
	Code      uint16
	RequestID uint32
	Groups    []Group
}

Message is a request (Code is the operation) or a response (Code is the status).

func Decode

func Decode(data []byte) (Message, error)

Decode parses a message; trailing data after the end tag (a job's document) is ignored.

func (Message) Encode

func (m Message) Encode() []byte

Encode writes the message: version 2.0, the code, the request id, the groups, the end tag. It panics on a name or value longer than 65535 bytes.

type Printer

type Printer struct {
	Name, Location, StateMessage string
	// State is printer-state: 3 idle, 4 processing, 5 stopped.
	State     int32
	Accepting bool
	// Media are its PWG media names, Sides its sides keywords,
	// ColorModes its print-color-mode keywords, Qualities its
	// print-quality enums; each with its default.
	Media, Sides, ColorModes   []string
	MediaDefault, SidesDefault string
	ColorModeDefault           string
	Qualities                  []int32
	QualityDefault             int32
}

Printer is one queue as the dialog lists it, with what it supports (empty when it does not say).

type StatusError

type StatusError struct {
	Code    uint16
	Message string
}

StatusError is an unsuccessful IPP status.

func (*StatusError) Error

func (e *StatusError) Error() string

type Value

type Value struct {
	Tag  byte
	Int  int32
	Low  int32 // range lower bound; Int is the upper
	Text string
}

Value is one attribute value: an int for integer, enum and boolean (0 or 1), a [2]int32 for a range, a string for the text kinds.

Jump to

Keyboard shortcuts

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