Documentation
¶
Overview ¶
Package goipp implements IPP core protocol, as defined by RFC 8010
It doesn't implement high-level operations, such as "print a document", "cancel print job" and so on. It's scope is limited to proper generation and parsing of IPP requests and responses.
IPP protocol uses the following simple model: 1. Send a request 2. Receive a response
Request and response both has a similar format, represented here by type Message, with the only difference, that Code field of that Message is the Operation code in request and Status code in response. So most of operations are common for request and response messages
Example:
package main
import (
"bytes"
"net/http"
"os"
"github.com/OpenPrinting/goipp"
)
const uri = "http://192.168.1.102:631"
// Build IPP OpGetPrinterAttributes request
func makeRequest() ([]byte, error) {
m := goipp.NewRequest(goipp.DefaultVersion, goipp.OpGetPrinterAttributes, 1)
m.Operation.Add(goipp.MakeAttribute("attributes-charset",
goipp.TagCharset, goipp.String("utf-8")))
m.Operation.Add(goipp.MakeAttribute("attributes-natural-language",
goipp.TagLanguage, goipp.String("en-US")))
m.Operation.Add(goipp.MakeAttribute("printer-uri",
goipp.TagURI, goipp.String(uri)))
m.Operation.Add(goipp.MakeAttribute("requested-attributes",
goipp.TagKeyword, goipp.String("all")))
return m.EncodeBytes()
}
// Check that there is no error
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
request, err := makeRequest()
check(err)
resp, err := http.Post(uri, goipp.ContentType, bytes.NewBuffer(request))
check(err)
var respMsg goipp.Message
err = respMsg.Decode(resp.Body)
check(err)
respMsg.Print(os.Stdout, false)
}
Index ¶
- Constants
- func ValueEqual(v1, v2 Value) bool
- type Attribute
- type Attributes
- type Binary
- type Boolean
- type Code
- type Collection
- type Integer
- type Message
- func (m *Message) Decode(in io.Reader) error
- func (m *Message) DecodeBytes(data []byte) error
- func (m *Message) Encode(out io.Writer) error
- func (m *Message) EncodeBytes() ([]byte, error)
- func (m Message) Equal(m2 Message) bool
- func (m *Message) Print(out io.Writer, request bool)
- func (m *Message) Reset()
- type Op
- type Range
- type Resolution
- type Status
- type String
- type Tag
- type TextWithLang
- type Time
- type Type
- type Units
- type Value
- type Values
- type Version
- type Void
Constants ¶
const (
// ContentType is the HTTP content type for IPP messages
ContentType = "application/ipp"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attribute ¶
Attribute represents a single attribute
func MakeAttribute ¶
MakeAttribute makes Attribute with single value
type Attributes ¶
type Attributes []Attribute
Attributes represents a slice of attributes
func (Attributes) Equal ¶
func (attrs Attributes) Equal(attrs2 Attributes) bool
Equal checks that attrs and attrs2 are equal
type Collection ¶
type Collection Attributes
Collection represents a collection of attributes
Use with: TagBeginCollection
func (*Collection) Add ¶
func (collection *Collection) Add(attr Attribute)
Add Attribute to Attributes
func (Collection) Equal ¶
func (c1 Collection) Equal(c2 Attributes) bool
Equal checks that two collections are equal
func (Collection) String ¶
func (v Collection) String() string
String() converts Collection to string
type Message ¶
type Message struct {
// Common header
Version Version // Protocol version
Code Code // Operation for request, status for response
RequestID uint32 // Set in request, returned in response
// Attributes, by group
Operation Attributes // Operation attributes
Job Attributes // Job attributes
Printer Attributes // Printer attributes
Unsupported Attributes // Unsupported attributes
Subscription Attributes // Subscription attributes
EventNotification Attributes // Event Notification attributes
Resource Attributes // Resource attributes
Document Attributes // Document attributes
System Attributes // System attributes
Future11 Attributes // \
Future12 Attributes // \
Future13 Attributes // | Reserved for future extensions
Future14 Attributes // /
Future15 Attributes // /
}
Message represents a single IPP message, which may be either client request or server response
func NewRequest ¶
NewRequest creates a new request message
Use DefaultVersion as a first argument, if you don't have any specific needs
func NewResponse ¶
NewResponse creates a new response message
Use DefaultVersion as a first argument, if you don't
func (*Message) DecodeBytes ¶
DecodeBytes decodes message from byte slice
func (*Message) EncodeBytes ¶
EncodeBytes encodes message to byte slice
type Op ¶
type Op Code
Op represents an IPP Operation Code
const ( OpPrintJob Op = 0x0002 // Print-Job: Print a single file OpPrintURI Op = 0x0003 // Print-URI: Print a single URL OpValidateJob Op = 0x0004 // Validate-Job: Validate job values prior to submission OpCreateJob Op = 0x0005 // Create-Job: Create an empty print job OpSendDocument Op = 0x0006 // Send-Document: Add a file to a job OpSendURI Op = 0x0007 // Send-URI: Add a URL to a job OpCancelJob Op = 0x0008 // Cancel-Job: Cancel a job OpGetJobAttributes Op = 0x0009 // Get-Job-Attribute: Get information about a job OpGetJobs Op = 0x000a // Get-Jobs: Get a list of jobs OpGetPrinterAttributes Op = 0x000b // Get-Printer-Attributes: Get information about a printer OpHoldJob Op = 0x000c // Hold-Job: Hold a job for printing OpReleaseJob Op = 0x000d // Release-Job: Release a job for printing OpRestartJob Op = 0x000e // Restart-Job: Reprint a job OpPausePrinter Op = 0x0010 // Pause-Printer: Stop a printer OpResumePrinter Op = 0x0011 // Resume-Printer: Start a printer OpPurgeJobs Op = 0x0012 // Purge-Jobs: Delete all jobs OpSetPrinterAttributes Op = 0x0013 // Set-Printer-Attributes: Set printer values OpSetJobAttributes Op = 0x0014 // Set-Job-Attributes: Set job values OpGetPrinterSupportedValues Op = 0x0015 // Get-Printer-Supported-Values: Get supported values OpCreatePrinterSubscriptions Op = 0x0016 // Create-Printer-Subscriptions: Create one or more printer subscriptions OpCreateJobSubscriptions Op = 0x0017 // Create-Job-Subscriptions: Create one of more job subscriptions OpGetSubscriptionAttributes Op = 0x0018 // Get-Subscription-Attributes: Get subscription information OpGetSubscriptions Op = 0x0019 // Get-Subscriptions: Get list of subscriptions OpRenewSubscription Op = 0x001a // Renew-Subscription: Renew a printer subscription OpCancelSubscription Op = 0x001b // Cancel-Subscription: Cancel a subscription OpGetNotifications Op = 0x001c // Get-Notifications: Get notification events OpSendNotifications Op = 0x001d // Send-Notifications: Send notification events OpGetResourceAttributes Op = 0x001e // Get-Resource-Attributes: Get resource information OpGetResourceData Op = 0x001f // Get-Resource-Data: Get resource data OpGetResources Op = 0x0020 // Get-Resources: Get list of resources OpGetPrintSupportFiles Op = 0x0021 // Get-Printer-Support-Files: Get printer support files OpEnablePrinter Op = 0x0022 // Enable-Printer: Accept new jobs for a printer OpDisablePrinter Op = 0x0023 // Disable-Printer: Reject new jobs for a printer OpPausePrinterAfterCurrentJob Op = 0x0024 // Pause-Printer-After-Current-Job: Stop printer after the current job OpHoldNewJobs Op = 0x0025 // Hold-New-Jobs: Hold new jobs OpReleaseHeldNewJobs Op = 0x0026 // Release-Held-New-Jobs: Release new jobs that were previously held OpDeactivatePrinter Op = 0x0027 // Deactivate-Printer: Stop a printer and do not accept jobs OpActivatePrinter Op = 0x0028 // Activate-Printer: Start a printer and accept jobs OpRestartPrinter Op = 0x0029 // Restart-Printer: Restart a printer OpShutdownPrinter Op = 0x002a // Shutdown-Printer: Turn a printer off OpStartupPrinter Op = 0x002b // Startup-Printer: Turn a printer on OpReprocessJob Op = 0x002c // Reprocess-Job: Reprint a job OpCancelCurrentJob Op = 0x002d // Cancel-Current-Job: Cancel the current job OpSuspendCurrentJob Op = 0x002e // Suspend-Current-Job: Suspend the current job OpResumeJob Op = 0x002f // Resume-Job: Resume the current job OpPromoteJob Op = 0x0030 // Promote-Job: Promote a job to print sooner OpScheduleJobAfter Op = 0x0031 // Schedule-Job-After: Schedule a job to print after another OpCancelDocument Op = 0x0033 // Cancel-Document: Cancel a document OpGetDocumentAttributes Op = 0x0034 // Get-Document-Attributes: Get document information OpGetDocuments Op = 0x0035 // Get-Documents: Get a list of documents in a job OpDeleteDocument Op = 0x0036 // Delete-Document: Delete a document OpSetDocumentAttributes Op = 0x0037 // Set-Document-Attributes: Set document values OpCancelJobs Op = 0x0038 // Cancel-Jobs: Cancel all jobs (administrative) OpCancelMyJobs Op = 0x0039 // Cancel-My-Jobs: Cancel a user's jobs OpResubmitJob Op = 0x003a // Resubmit-Job: Copy and reprint a job OpCloseJob Op = 0x003b // Close-Job: Close a job and start printing OpIdentifyPrinter Op = 0x003c // Identify-Printer: Make the printer beep, flash, or display a message for identification OpValidateDocument Op = 0x003d // Validate-Document: Validate document values prior to submission OpAddDocumentImages Op = 0x003e // Add-Document-Images: Add image(s) from the specified scanner source OpAcknowledgeDocument Op = 0x003f // Acknowledge-Document: Acknowledge processing of a document OpAcknowledgeIdentifyPrinter Op = 0x0040 // Acknowledge-Identify-Printer: Acknowledge action on an Identify-Printer request OpAcknowledgeJob Op = 0x0041 // Acknowledge-Job: Acknowledge processing of a job OpFetchDocument Op = 0x0042 // Fetch-Document: Fetch a document for processing OpFetchJob Op = 0x0043 // Fetch-Job: Fetch a job for processing OpGetOutputDeviceAttributes Op = 0x0044 // Get-Output-Device-Attributes: Get printer information for a specific output device OpUpdateActiveJobs Op = 0x0045 // Update-Active-Jobs: Update the list of active jobs that a proxy has processed OpDeregisterOutputDevice Op = 0x0046 // Deregister-Output-Device: Remove an output device OpUpdateDocumentStatus Op = 0x0047 // Update-Document-Status: Update document values OpUpdateJobStatus Op = 0x0048 // Update-Job-Status: Update job values OpupdateOutputDeviceAttributes Op = 0x0049 // Update-Output-Device-Attributes: Update output device values OpGetNextDocumentData Op = 0x004a // Get-Next-Document-Data: Scan more document data OpAllocatePrinterResources Op = 0x004b // Allocate-Printer-Resources: Use resources for a printer OpCreatePrinter Op = 0x004c // Create-Printer: Create a new service OpDeallocatePrinterResources Op = 0x004d // Deallocate-Printer-Resources: Stop using resources for a printer OpDeletePrinter Op = 0x004e // Delete-Printer: Delete an existing service OpGetPrinters Op = 0x004f // Get-Printers: Get a list of services OpShutdownOnePrinter Op = 0x0050 // Shutdown-One-Printer: Shutdown a service OpStartupOnePrinter Op = 0x0051 // Startup-One-Printer: Start a service OpCancelResource Op = 0x0052 // Cancel-Resource: Uninstall a resource OpCreateResource Op = 0x0053 // Create-Resource: Create a new (empty) resource OpInstallResource Op = 0x0054 // Install-Resource: Install a resource OpSendResourceData Op = 0x0055 // Send-Resource-Data: Upload the data for a resource OpSetResourceAttributes Op = 0x0056 // Set-Resource-Attributes: Set resource object attributes OpCreateResourceSubscriptions Op = 0x0057 // Create-Resource-Subscriptions: Create event subscriptions for a resource OpCreateSystemSubscriptions Op = 0x0058 // Create-System-Subscriptions: Create event subscriptions for a system OpDisableAllPrinters Op = 0x0059 // Disable-All-Printers: Stop accepting new jobs on all services OpEnableAllPrinters Op = 0x005a // Enable-All-Printers: Start accepting new jobs on all services OpGetSystemAttributes Op = 0x005b // Get-System-Attributes: Get system object attributes OpGetSystemSupportedValues Op = 0x005c // Get-System-Supported-Values: Get supported values for system object attributes OpPauseAllPrinters Op = 0x005d // Pause-All-Printers: Stop all services immediately OpPauseAllPrintersAfterCurrentJob Op = 0x005e // Pause-All-Printers-After-Current-Job: Stop all services after processing the current jobs OpRegisterOutputDevice Op = 0x005f // Register-Output-Device: Register a remote service OpRestartSystem Op = 0x0060 // Restart-System: Restart all services OpResumeAllPrinters Op = 0x0061 // Resume-All-Printers: Start job processing on all services OpSetSystemAttributes Op = 0x0062 // Set-System-Attributes: Set system object attributes OpShutdownAllPrinters Op = 0x0063 // Shutdown-All-Printers: Shutdown all services OpStartupAllPrinters Op = 0x0064 // Startup-All-Printers: Startup all services OpCupsGetDefault Op = 0x4001 // CUPS-Get-Default: Get the default printer OpCupsGetPrinters Op = 0x4002 // CUPS-Get-Printers: Get a list of printers and/or classes OpCupsAddModifyPrinter Op = 0x4003 // CUPS-Add-Modify-Printer: Add or modify a printer OpCupsDeletePrinter Op = 0x4004 // CUPS-Delete-Printer: Delete a printer OpCupsGetClasses Op = 0x4005 // CUPS-Get-Classes: Get a list of classes OpCupsAddModifyClass Op = 0x4006 // CUPS-Add-Modify-Class: Add or modify a class OpCupsDeleteClass Op = 0x4007 // CUPS-Delete-Class: Delete a class OpCupsAcceptJobs Op = 0x4008 // CUPS-Accept-Jobs: Accept new jobs on a printer OpCupsRejectJobs Op = 0x4009 // CUPS-Reject-Jobs: Reject new jobs on a printer OpCupsSetDefault Op = 0x400a // CUPS-Set-Default: Set the default printer OpCupsGetDevices Op = 0x400b // CUPS-Get-Devices: Get a list of supported devices OpCupsGetPpds Op = 0x400c // CUPS-Get-PPDs: Get a list of supported drivers OpCupsMoveJob Op = 0x400d // CUPS-Move-Job: Move a job to a different printer OpCupsAuthenticateJob Op = 0x400e // CUPS-Authenticate-Job: Authenticate a job OpCupsGetPpd Op = 0x400f // CUPS-Get-PPD: Get a PPD file OpCupsGetDocument Op = 0x4027 // CUPS-Get-Document: Get a document file OpCupsCreateLocalPrinter Op = 0x4028 // CUPS-Create-Local-Printer: Create a local (temporary) printer )
type Range ¶
type Range struct {
Lower, Upper int // Lower/upper bounds
}
Range represents a range of integers Value
Use with: TagRange
type Resolution ¶
Resolution represents a resolution Value
Use with: TagResolution
func (Resolution) String ¶
func (v Resolution) String() string
String() converts Resolution value to string
type Status ¶
type Status Code
Status represents an IPP Status Code
const ( StatusOk Status = 0x0000 // successful-ok StatusOkIgnoredOrSubstituted Status = 0x0001 // successful-ok-ignored-or-substituted-attributes StatusOkConflicting Status = 0x0002 // successful-ok-conflicting-attributes StatusOkIgnoredSubscriptions Status = 0x0003 // successful-ok-ignored-subscriptions StatusOkIgnoredNotifications Status = 0x0004 // successful-ok-ignored-notifications StatusOkTooManyEvents Status = 0x0005 // successful-ok-too-many-events StatusOkButCancelSubscription Status = 0x0006 // successful-ok-but-cancel-subscription StatusOkEventsComplete Status = 0x0007 // successful-ok-events-complete StatusRedirectionOtherSite Status = 0x0200 // redirection-other-site StatusCupsSeeOther Status = 0x0280 // cups-see-other StatusErrorBadRequest Status = 0x0400 // client-error-bad-request StatusErrorForbidden Status = 0x0401 // client-error-forbidden StatusErrorNotAuthenticated Status = 0x0402 // client-error-not-authenticated StatusErrorNotAuthorized Status = 0x0403 // client-error-not-authorized StatusErrorNotPossible Status = 0x0404 // client-error-not-possible StatusErrorTimeout Status = 0x0405 // client-error-timeout StatusErrorNotFound Status = 0x0406 // client-error-not-found StatusErrorGone Status = 0x0407 // client-error-gone StatusErrorRequestEntity Status = 0x0408 // client-error-request-entity-too-large StatusErrorRequestValue Status = 0x0409 // client-error-request-value-too-long StatusErrorDocumentFormatNotSupported Status = 0x040a // client-error-document-format-not-supported StatusErrorAttributesOrValues Status = 0x040b // client-error-attributes-or-values-not-supported StatusErrorURIScheme Status = 0x040c // client-error-uri-scheme-not-supported StatusErrorCharset Status = 0x040d // client-error-charset-not-supported StatusErrorConflicting Status = 0x040e // client-error-conflicting-attributes StatusErrorCompressionNotSupported Status = 0x040f // client-error-compression-not-supported StatusErrorCompressionError Status = 0x0410 // client-error-compression-error StatusErrorDocumentFormatError Status = 0x0411 // client-error-document-format-error StatusErrorDocumentAccess Status = 0x0412 // client-error-document-access-error StatusErrorAttributesNotSettable Status = 0x0413 // client-error-attributes-not-settable StatusErrorIgnoredAllSubscriptions Status = 0x0414 // client-error-ignored-all-subscriptions StatusErrorTooManySubscriptions Status = 0x0415 // client-error-too-many-subscriptions StatusErrorIgnoredAllNotifications Status = 0x0416 // client-error-ignored-all-notifications StatusErrorPrintSupportFileNotFound Status = 0x0417 // client-error-print-support-file-not-found StatusErrorDocumentPassword Status = 0x0418 // client-error-document-password-error StatusErrorDocumentPermission Status = 0x0419 // client-error-document-permission-error StatusErrorDocumentSecurity Status = 0x041a // client-error-document-security-error StatusErrorDocumentUnprintable Status = 0x041b // client-error-document-unprintable-error StatusErrorAccountInfoNeeded Status = 0x041c // client-error-account-info-needed StatusErrorAccountClosed Status = 0x041d // client-error-account-closed StatusErrorAccountLimitReached Status = 0x041e // client-error-account-limit-reached StatusErrorAccountAuthorizationFailed Status = 0x041f // client-error-account-authorization-failed StatusErrorNotFetchable Status = 0x0420 // client-error-not-fetchable StatusErrorInternal Status = 0x0500 // server-error-internal-error StatusErrorOperationNotSupported Status = 0x0501 // server-error-operation-not-supported StatusErrorVersionNotSupported Status = 0x0503 // server-error-version-not-supported StatusErrorDevice Status = 0x0504 // server-error-device-error StatusErrorTemporary Status = 0x0505 // server-error-temporary-error StatusErrorNotAcceptingJobs Status = 0x0506 // server-error-not-accepting-jobs StatusErrorBusy Status = 0x0507 // server-error-busy StatusErrorJobCanceled Status = 0x0508 // server-error-job-canceled StatusErrorMultipleJobsNotSupported Status = 0x0509 // server-error-multiple-document-jobs-not-supported StatusErrorPrinterIsDeactivated Status = 0x050a // server-error-printer-is-deactivated StatusErrorTooManyJobs Status = 0x050b // server-error-too-many-jobs StatusErrorTooManyDocuments Status = 0x050c // server-error-too-many-documents )
type String ¶
type String string
String represents a string Value
Use with: TagText, TagName, TagReservedString, TagKeyword, TagURI, TagURIScheme, TagCharset, TagLanguage, TagMimeType, TagMemberName
type Tag ¶
type Tag int
Tag represents a tag used in a binary representation of the IPP message
const ( // Delimiter tags TagZero Tag = 0x00 // Zero tag - used for separators TagOperationGroup Tag = 0x01 // Operation group TagJobGroup Tag = 0x02 // Job group TagEnd Tag = 0x03 // End-of-attributes TagPrinterGroup Tag = 0x04 // Printer group TagUnsupportedGroup Tag = 0x05 // Unsupported attributes group TagSubscriptionGroup Tag = 0x06 // Subscription group TagEventNotificationGroup Tag = 0x07 // Event group TagResourceGroup Tag = 0x08 // Resource group TagDocumentGroup Tag = 0x09 // Document group TagSystemGroup Tag = 0x0a // System group TagFuture11Group Tag = 0x0b // Future group 11 TagFuture12Group Tag = 0x0c // Future group 11 TagFuture13Group Tag = 0x0d // Future group 11 TagFuture14Group Tag = 0x0e // Future group 11 TagFuture15Group Tag = 0x0f // Future group 11 // Value tags TagUnsupportedValue Tag = 0x10 // Unsupported value TagDefault Tag = 0x11 // Default value TagUnknown Tag = 0x12 // Unknown value TagNoValue Tag = 0x13 // No-value value TagNotSettable Tag = 0x15 // Not-settable value TagDeleteAttr Tag = 0x16 // Delete-attribute value TagAdminDefine Tag = 0x17 // Admin-defined value TagInteger Tag = 0x21 // Integer value TagBoolean Tag = 0x22 // Boolean value TagEnum Tag = 0x23 // Enumeration value TagString Tag = 0x30 // Octet string value TagDateTime Tag = 0x31 // Date/time value TagResolution Tag = 0x32 // Resolution value TagRange Tag = 0x33 // Range value TagBeginCollection Tag = 0x34 // Beginning of collection value TagTextLang Tag = 0x35 // Text-with-language value TagNameLang Tag = 0x36 // Name-with-language value TagEndCollection Tag = 0x37 // End of collection value TagText Tag = 0x41 // Text value TagName Tag = 0x42 // Name value TagReservedString Tag = 0x43 // Reserved for future string value TagKeyword Tag = 0x44 // Keyword value TagURI Tag = 0x45 // URI value TagURIScheme Tag = 0x46 // URI scheme value TagCharset Tag = 0x47 // Character set value TagLanguage Tag = 0x48 // Language value TagMimeType Tag = 0x49 // MIME media type value TagMemberName Tag = 0x4a // Collection member name value TagExtension Tag = 0x7f // Extension point for 32-bit tags )
func (Tag) IsDelimiter ¶
IsDelimiter returns true for delimiter tags
type TextWithLang ¶
type TextWithLang struct {
Lang, Text string // Language and text
}
TextWithLang represents a combination of two strings: one is a name of natural language and second is a text on this language
Use with: TagTextLang, TagNameLang
func (TextWithLang) String ¶
func (v TextWithLang) String() string
String() converts TextWithLang value to string
type Values ¶
Values represents a slice of Attribute values with tags
type Version ¶
type Version uint16
Version represents a protocol version. It consist of Major and Minor version codes, packed into a single 16-bit word
const DefaultVersion Version = 0x0200
DefaultVersion is the default IPP version
func MakeVersion ¶
MakeVersion makes version from major and minor parts