ipp

package module
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: Apache-2.0 Imports: 13 Imported by: 10

README

go-ipp

Go Get

To get the package, execute:

go get -h github.com/phin1x/go-ipp

Features

  • basic ipp 2.0 compatible Client
  • extended client for cups server
  • create custom ipp requests
  • parse ipp responses and control files

Examples

Print a file

client := ipp.NewIPPClient("printserver", 631, "user", "password", true)
client.PrintFile("/path/to/file", "my-printer", 1, ipp.DefaultJobPriority)

Licence

Apache Licence Version 2.0

Documentation

Index

Constants

View Source
const (
	StatusCupsInvalid            Status = -1
	StatusOk                            = 0x0000
	StatusOkIgnoredOrSubstituted        = 0x0001
	StatusOkConflicting                 = 0x0002

	StatusErrorForbidden                      = 0x0401
	StatusErrorNotAuthenticated               = 0x0402
	StatusErrorNotAuthorized                  = 0x0403
	StatusErrorNotPossible                    = 0x0404
	StatusErrorTimeout                        = 0x0405
	StatusErrorNotFound                       = 0x0406
	StatusErrorGone                           = 0x0407
	StatusErrorRequestEntity                  = 0x0408
	StatusErrorRequestValue                   = 0x0409
	StatusErrorDocumentFormatNotSupported     = 0x040a
	StatusErrorAttributesOrValues             = 0x040b
	StatusErrorUriScheme                      = 0x040c
	StatusErrorCharset                        = 0x040d
	StatusErrorConflicting                    = 0x040e
	StatusErrorCompressionError               = 0x040f
	StatusErrorDocumentFormatError            = 0x0410
	StatusErrorDocumentAccess                 = 0x0411
	StatusErrorAttributesNotSettable          = 0x0412
	StatusErrorIgnoredAllSubscriptions        = 0x0413
	StatusErrorTooManySubscriptions           = 0x0414
	StatusErrorIgnoredAllNotifications        = 0x0415
	StatusErrorPrintSupportFileNotFound       = 0x0416
	StatusErrorDocumentPassword               = 0x0417
	StatusErrorDocumentPermission             = 0x0418
	StatusErrorDocumentSecurity               = 0x0419
	StatusErrorDocumentUnprintable            = 0x041a
	StatusErrorAccountInfoNeeded              = 0x041b
	StatusErrorAccountClosed                  = 0x041c
	StatusErrorAccountLimitReached            = 0x041d
	StatusErrorAccountAuthorizationFailed     = 0x041e
	StatusErrorNotFetchable                   = 0x041f
	StatusErrorCupsAccountInfoNeeded          = 0x049C
	StatusErrorCupsAccountClosed              = 0x049d
	StatusErrorCupsAccountLimitReached        = 0x049e
	StatusErrorCupsAccountAuthorizationFailed = 0x049f
	StatusErrorInternal                       = 0x0500
	StatusErrorOperationNotSupported          = 0x0501
	StatusErrorServiceUnavailable             = 0x0502
	StatusErrorVersionNotSupported            = 0x0503
	StatusErrorDevice                         = 0x0504
	StatusErrorTemporary                      = 0x0505
	StatusErrorNotAcceptingJobs               = 0x0506
	StatusErrorBusy                           = 0x0507
	StatusErrorJobCanceled                    = 0x0508
	StatusErrorMultipleJobsNotSupported       = 0x0509
	StatusErrorPrinterIsDeactivated           = 0x050a
	StatusErrorTooManyJobs                    = 0x050b
	StatusErrorTooManyDocuments               = 0x050c
	StatusErrorCupsAuthenticationCanceled     = 0x1000
	StatusErrorCupsPki                        = 0x1001
	StatusErrorCupsUpgradeRequired            = 0x1002
)
View Source
const (
	OperationCupsInvalid                     Operation = -0x0001
	OperationCupsNone                                  = 0x0000
	OperationPrintJob                                  = 0x0002
	OperationPrintUri                                  = 0x0003
	OperationValidateJob                               = 0x0004
	OperationCreateJob                                 = 0x0005
	OperationSendDocument                              = 0x0006
	OperationSendUri                                   = 0x0007
	OperationCancelJob                                 = 0x0008
	OperationGetJobAttributes                          = 0x0009
	OperationGetJobs                                   = 0x000a
	OperationGetPrinterAttributes                      = 0x000b
	OperationHoldJob                                   = 0x000c
	OperationReleaseJob                                = 0x000d
	OperationRestartJob                                = 0x000e
	OperationPausePrinter                              = 0x0010
	OperationResumePrinter                             = 0x0011
	OperationPurgeJobs                                 = 0x0012
	OperationSetPrinterAttributes                      = 0x0013
	OperationSetJobAttributes                          = 0x0014
	OperationGetPrinterSupportedValues                 = 0x0015
	OperationCreatePrinterSubscriptions                = 0x0016
	OperationCreateJobSubscriptions                    = 0x0017
	OperationGetSubscriptionAttributes                 = 0x0018
	OperationGetSubscriptions                          = 0x0019
	OperationRenewSubscription                         = 0x001a
	OperationCancelSubscription                        = 0x001b
	OperationGetNotifications                          = 0x001c
	OperationSendNotifications                         = 0x001d
	OperationGetResourceAttributes                     = 0x001e
	OperationGetResourceData                           = 0x001f
	OperationGetResources                              = 0x0020
	OperationGetPrintSupportFiles                      = 0x0021
	OperationEnablePrinter                             = 0x0022
	OperationDisablePrinter                            = 0x0023
	OperationPausePrinterAfterCurrentJob               = 0x0024
	OperationHoldNewJobs                               = 0x0025
	OperationReleaseHeldNewJobs                        = 0x0026
	OperationDeactivatePrinter                         = 0x0027
	OperationActivatePrinter                           = 0x0028
	OperationRestartPrinter                            = 0x0029
	OperationShutdownPrinter                           = 0x002a
	OperationStartupPrinter                            = 0x002b
	OperationReprocessJob                              = 0x002c
	OperationCancelCurrentJob                          = 0x002d
	OperationSuspendCurrentJob                         = 0x002e
	OperationResumeJob                                 = 0x002f
	OperationOperationPromoteJob                       = 0x0030
	OperationScheduleJobAfter                          = 0x0031
	OperationCancelDocument                            = 0x0033
	OperationGetDocumentAttributes                     = 0x0034
	OperationGetDocuments                              = 0x0035
	OperationDeleteDocument                            = 0x0036
	OperationSetDocumentAttributes                     = 0x0037
	OperationCancelJobs                                = 0x0038
	OperationCancelMyJobs                              = 0x0039
	OperationResubmitJob                               = 0x003a
	OperationCloseJob                                  = 0x003b
	OperationIdentifyPrinter                           = 0x003c
	OperationValidateDocument                          = 0x003d
	OperationAddDocumentImages                         = 0x003e
	OperationAcknowledgeDocument                       = 0x003f
	OperationAcknowledgeIdentifyPrinter                = 0x0040
	OperationAcknowledgeJob                            = 0x0041
	OperationFetchDocument                             = 0x0042
	OperationFetchJob                                  = 0x0043
	OperationGetOutputDeviceAttributes                 = 0x0044
	OperationUpdateActiveJobs                          = 0x0045
	OperationDeregisterOutputDevice                    = 0x0046
	OperationUpdateDocumentStatus                      = 0x0047
	OperationUpdateJobStatus                           = 0x0048
	OperationUpdateOutputDeviceAttributes              = 0x0049
	OperationGetNextDocumentData                       = 0x004a
	OperationAllocatePrinterResources                  = 0x004b
	OperationCreatePrinter                             = 0x004c
	OperationDeallocatePrinterResources                = 0x004d
	OperationDeletePrinter                             = 0x004e
	OperationGetPrinters                               = 0x004f
	OperationShutdownOnePrinter                        = 0x0050
	OperationStartupOnePrinter                         = 0x0051
	OperationCancelResource                            = 0x0052
	OperationCreateResource                            = 0x0053
	OperationInstallResource                           = 0x0054
	OperationSendResourceData                          = 0x0055
	OperationSetResourceAttributes                     = 0x0056
	OperationCreateResourceSubscriptions               = 0x0057
	OperationCreateSystemSubscriptions                 = 0x0058
	OperationDisableAllPrinters                        = 0x0059
	OperationEnableAllPrinters                         = 0x005a
	OperationGetSystemAttributes                       = 0x005b
	OperationGetSystemSupportedValues                  = 0x005c
	OperationPauseAllPrinters                          = 0x005d
	OperationPauseAllPrintersAfterCurrentJob           = 0x005e
	OperationRegisterOutputDevice                      = 0x005f
	OperationRestartSystem                             = 0x0060
	OperationResumeAllPrinters                         = 0x0061
	OperationSetSystemAttributes                       = 0x0062
	OperationShutdownAllPrinter                        = 0x0063
	OperationStartupAllPrinters                        = 0x0064
	OperationPrivate                                   = 0x4000
	OperationCupsGetDefault                            = 0x4001
	OperationCupsGetPrinters                           = 0x4002
	OperationCupsAddModifyPrinter                      = 0x4003
	OperationCupsDeletePrinter                         = 0x4004
	OperationCupsGetClasses                            = 0x4005
	OperationCupsAddModifyClass                        = 0x4006
	OperationCupsDeleteClass                           = 0x4007
	OperationCupsAcceptJobs                            = 0x4008
	OperationCupsRejectJobs                            = 0x4009
	OperationCupsSetDefault                            = 0x400a
	OperationCupsGetDevices                            = 0x400b
	OperationCupsGetPpds                               = 0x400c
	OperationCupsMoveJob                               = 0x400d
	OperationCupsAuthenticateJob                       = 0x400e
	OperationCupsGetPpd                                = 0x400f
	OperationCupsGetDocument                           = 0x4027
	OperationCupsCreateLocalPrinter                    = 0x4028
)
View Source
const (
	TagCupsInvalid       Tag = -1
	TagZero                  = 0x00
	TagOperation             = 0x01
	TagJob                   = 0x02
	TagEnd                   = 0x03
	TagPrinter               = 0x04
	TagUnsupportedGroup      = 0x05
	TagSubscription          = 0x06
	TagEventNotification     = 0x07
	TagResource              = 0x08
	TagDocument              = 0x09
	TagSystem                = 0x0a
	TagUnsupportedValue      = 0x10
	TagDefault               = 0x11
	TagUnknown               = 0x12
	TagNoValue               = 0x013
	TagNotSettable           = 0x15
	TagDeleteAttr            = 0x16
	TagAdminDefine           = 0x17
	TagInteger               = 0x21
	TagBoolean               = 0x22
	TagEnum                  = 0x23
	TagString                = 0x30
	TagDate                  = 0x31
	TagResolution            = 0x32
	TagRange                 = 0x33
	TagBeginCollection       = 0x34
	TagTextLang              = 0x35
	TagNameLang              = 0x36
	TagEndCollection         = 0x37
	TagText                  = 0x41
	TagName                  = 0x42
	TagReservedString        = 0x43
	TagKeyword               = 0x44
	TagUri                   = 0x45
	TagUriScheme             = 0x46
	TagCharset               = 0x47
	TagLanguage              = 0x48
	TagMimeType              = 0x49
	TagMemberName            = 0x4a
	TagExtension             = 0x7f
	TagCupsMask              = 0x7fffffff
	TagCupsConst             = -0x7fffffff - 1
)
View Source
const (
	JobStatePending    JobState = 0x03
	JobStateHeld                = 0x04
	JobStateProcessing          = 0x05
	JobStateStopped             = 0x06
	JobStateCanceled            = 0x07
	JobStateAborted             = 0x08
	JobStateCompleted           = 0x09
)
View Source
const (
	DocumentStatePending    DocumentState = 0x03
	DocumentStateProcessing               = 0x05
	DocumentStateCanceled                 = 0x07
	DocumentStateAborted                  = 0x08
	DocumentStateCompleted                = 0x08
)
View Source
const (
	PrinterStateIdle       PrinterState = 0x0003
	PrinterStateProcessing              = 0x0004
	PrinterStateStopped                 = 0x0005
)
View Source
const (
	JobStateFilterNotCompleted = "not-completed"
	JobStateFilterCompleted    = "completed"
)
View Source
const (
	ErrorPolicyRetryJob        ErrorPolicy = "retry-job"
	ErrorPolicyAbortJob                    = "abort-job"
	ErrorPolicyRetryCurrentJob             = "retry-current-job"
	ErrorPolicyStopPrinter                 = "stop-printer"
)
View Source
const (
	CharsetLanguage      = "en-US"
	Charset              = "utf-8"
	ProtocolVersionMajor = uint8(2)
	ProtocolVersionMinor = uint8(0)

	DefaultJobPriority = 50

	MimeTypePostscript  = "application/postscript"
	MimeTypeOctetStream = "application/octet-stream"
)

Variables

View Source
var (
	DefaultClassAttributes   = []string{"printer-name", "member-names"}
	DefaultPrinterAttributes = []string{"printer-name", "printer-type", "printer-location", "printer-info",
		"printer-make-and-model", "printer-state", "printer-state-message", "printer-state-reason",
		"printer-uri-supported", "device-uri", "printer-is-shared"}
	DefaultJobAttributes = []string{"job-id", "job-name", "printer-uri", "job-state", "job-state-reasons",
		"job-hold-until", "job-media-progress", "job-k-octets", "number-of-documents", "copies",
		"job-originating-user-name"}

	AttributeTagMapping = map[string]Tag{
		"attributes-charset":          TagCharset,
		"attributes-natural-language": TagLanguage,
		"printer-uri":                 TagUri,
		"requesting-user-name":        TagName,
		"job-id":                      TagInteger,
		"document-name":               TagName,
		"job-name":                    TagName,
		"document-format":             TagMimeType,
		"last-document":               TagBoolean,
		"copies":                      TagInteger,
		"job-hold-until":              TagKeyword,
		"job-priority":                TagInteger,
		"number-up":                   TagInteger,
		"job-sheets":                  TagName,
		"job-uri":                     TagUri,
		"job-state":                   TagEnum,
		"job-state-reason":            TagKeyword,
		"requested-attributes":        TagKeyword,
		"member-uris":                 TagUri,
		"ppd-name":                    TagName,
		"printer-state-reason":        TagKeyword,
		"printer-is-shared":           TagBoolean,
		"printer-error-policy":        TagName,
		"printer-info":                TagText,
		"which-jobs":                  TagKeyword,
		"my-jobs":                     TagBoolean,
		"purge-jobs":                  TagBoolean,
		"hold-job-until":              TagKeyword,
		"job-printer-uri":             TagUri,
		"printer-location":            TagText,
		"document-number":             TagInteger,
		"printer-state":               TagEnum,
		"document-state":              TagEnum,
		"device-uri":                  TagUri,
	}
)

Functions

func IsNotExistsError

func IsNotExistsError(err error) bool

Types

type Attribute

type Attribute struct {
	Tag   Tag
	Name  string
	Value interface{}
}

type AttributeDecoder

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

func NewAttributeDecoder

func NewAttributeDecoder(r io.Reader) *AttributeDecoder

func (*AttributeDecoder) Decode

func (d *AttributeDecoder) Decode(tag Tag) (*Attribute, error)

type AttributeEncoder

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

func NewAttributeEncoder

func NewAttributeEncoder(w io.Writer) *AttributeEncoder

func (*AttributeEncoder) Encode

func (e *AttributeEncoder) Encode(attribute string, value interface{}) error

type Attributes

type Attributes map[string][]Attribute

type CUPSClient

type CUPSClient struct {
	*IPPClient
}

func NewCUPSClient

func NewCUPSClient(host string, port int, username, password string, useTLS bool) *CUPSClient

func (*CUPSClient) AcceptJobs

func (c *CUPSClient) AcceptJobs(printer string) error

func (*CUPSClient) AddPrinterToClass

func (c *CUPSClient) AddPrinterToClass(class, printer string) error

func (*CUPSClient) CreatePrinter

func (c *CUPSClient) CreatePrinter(name, deviceURI, ppd string, shared bool, errorPolicy ErrorPolicy, information, location string) error

func (*CUPSClient) DeleteClass

func (c *CUPSClient) DeleteClass(class string) error

func (*CUPSClient) DeletePrinter

func (c *CUPSClient) DeletePrinter(printer string) error

func (*CUPSClient) DeletePrinterFromClass

func (c *CUPSClient) DeletePrinterFromClass(class, printer string) error

func (*CUPSClient) GetClasses

func (c *CUPSClient) GetClasses(attributes []string) (map[string]Attributes, error)

func (*CUPSClient) GetDevices

func (c *CUPSClient) GetDevices() (map[string]Attributes, error)

func (*CUPSClient) GetPPDs

func (c *CUPSClient) GetPPDs() (map[string]Attributes, error)

func (*CUPSClient) GetPrinters

func (c *CUPSClient) GetPrinters(attributes []string) (map[string]Attributes, error)

func (*CUPSClient) MoveAllJob

func (c *CUPSClient) MoveAllJob(srcPrinter, destPrinter string) error

func (*CUPSClient) MoveJob

func (c *CUPSClient) MoveJob(jobID int, destPrinter string) error

func (*CUPSClient) RejectJobs

func (c *CUPSClient) RejectJobs(printer string) error

func (*CUPSClient) SetPrinterDeviceURI

func (c *CUPSClient) SetPrinterDeviceURI(printer, deviceURI string) error

func (*CUPSClient) SetPrinterErrorPolicy

func (c *CUPSClient) SetPrinterErrorPolicy(printer string, errorPolicy ErrorPolicy) error

func (*CUPSClient) SetPrinterInformation

func (c *CUPSClient) SetPrinterInformation(printer, information string) error

func (*CUPSClient) SetPrinterIsShared

func (c *CUPSClient) SetPrinterIsShared(printer string, shared bool) error

func (*CUPSClient) SetPrinterLocation

func (c *CUPSClient) SetPrinterLocation(printer, location string) error

func (*CUPSClient) SetPrinterPPD

func (c *CUPSClient) SetPrinterPPD(printer, ppd string) error

type Document

type Document struct {
	Document io.Reader
	Size     int
	Name     string
	MimeType string
}

type DocumentState

type DocumentState uint8

type ErrorPolicy

type ErrorPolicy string

type IPPClient

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

func NewIPPClient

func NewIPPClient(host string, port int, username, password string, useTLS bool) *IPPClient

func (*IPPClient) CancelAllJob

func (c *IPPClient) CancelAllJob(printer string, purge bool) error

func (*IPPClient) CancelJob

func (c *IPPClient) CancelJob(jobID int, purge bool) error

func (*IPPClient) GetJobAttributes

func (c *IPPClient) GetJobAttributes(jobID int, attributes []string) (Attributes, error)

func (*IPPClient) GetJobs

func (c *IPPClient) GetJobs(printer string, whichJobs JobStateFilter, myJobs bool, attributes []string) (map[int]Attributes, error)

func (*IPPClient) GetPrinterAttributes

func (c *IPPClient) GetPrinterAttributes(printer string, attributes []string) (Attributes, error)

func (*IPPClient) HoldJobUntil

func (c *IPPClient) HoldJobUntil(jobID int, holdUntil string) error

func (*IPPClient) PausePrinter

func (c *IPPClient) PausePrinter(printer string) error

func (*IPPClient) Print

func (c *IPPClient) Print(docs []Document, printer, jobName string, copies, priority int) (int, error)

func (*IPPClient) PrintFile

func (c *IPPClient) PrintFile(filePath, printer string, copies, priority int) (int, error)

func (*IPPClient) PrintTestPage

func (c *IPPClient) PrintTestPage(printer string) (int, error)

func (*IPPClient) RestartJob

func (c *IPPClient) RestartJob(jobID int) error

func (*IPPClient) ResumePrinter

func (c *IPPClient) ResumePrinter(printer string) error

func (*IPPClient) SendRequest

func (c *IPPClient) SendRequest(url string, req *Request) (*Response, error)

func (*IPPClient) TestConnection

func (c *IPPClient) TestConnection() error

type JobState

type JobState uint8

type JobStateFilter

type JobStateFilter string

type Operation

type Operation int16

type PrinterState

type PrinterState uint8

type Request

type Request struct {
	Operation Operation
	RequestID int

	OperationAttributes map[string]interface{}
	JobAttributes       map[string]interface{}
	PrinterAttributes   map[string]interface{}

	File     io.Reader
	FileSize int
}

func NewRequest

func NewRequest(op Operation, reqID int) *Request

func (*Request) Encode

func (r *Request) Encode() ([]byte, error)

type Resolution

type Resolution struct {
	Height int
	Width  int
	Depth  uint8
}

type Response

type Response struct {
	ProtocolVersionMajor uint8
	ProtocolVersionMinor uint8

	StatusCode uint16
	RequestId  int32

	OperationAttributes Attributes
	Printers            []Attributes
	Jobs                []Attributes

	Data []byte
}

func ParseControlFile

func ParseControlFile(jobID int, spoolDirectory string) (*Response, error)

func (*Response) CheckForErrors

func (r *Response) CheckForErrors() error

type ResponseDecoder

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

func NewResponseDecoder

func NewResponseDecoder(r io.Reader) *ResponseDecoder

func (*ResponseDecoder) Decode

func (d *ResponseDecoder) Decode() (*Response, error)

type Status

type Status int8

type Tag

type Tag int8

Jump to

Keyboard shortcuts

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