ipp

package module
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: Apache-2.0 Imports: 13 Imported by: 1

README

go-ipp

Version Documentation Go Report Card Licence

Go Get

To get the package, execute:

go get -u 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 ipp control files

Example

Print a file with the ipp client

package main

import "github.com/phin1x/go-ipp"

func main() {
    // create a new ipp client
    client := ipp.NewIPPClient("printserver", 631, "user", "password", true)
    // print file
    client.PrintFile("/path/to/file", "my-printer", map[string]interface{}{})
}

Craft and send a custom request


package main

import "github.com/phin1x/go-ipp"

func main() {             
    // define a ipp request
    req := ipp.NewRequest(OperationGetJobs, 1)
    req.OperationAttributes[ipp.AttributeWhichJobs] = "completed"
    req.OperationAttributes[ipp.AttributeMyJobs] = myJobs
    req.OperationAttributes[ipp.AttributeFirstJobID] = 42
    req.OperationAttributes[ipp.AttributeRequestingUserName] = "fabian"
    
    // encode request to bytes
    payload, err := req.Encode()
    if err != nil {
        panic(err)
    }
    
    // send ipp request to remote server via http
    httpReq, err := http.NewRequest("POST", "http://my-print-server:631/printers/my-printer", bytes.NewBuffer(payload))
    if err != nil {
        panic(err)
    }
    
    // set ipp headers
    httpReq.Header.Set("Content-Length", len(payload))
    httpReq.Header.Set("Content-Type", ipp.ContentTypeIPP)
    
    httpClient := &http.Client()
    httpResp, err := httpClient.Do(httpReq)
    if err != nil {
        panic(err)
    }
    defer httpResp.Body.Close()
    
    // response must be 200 for a successful operation
    // other possible http codes are: 
    // - 500 -> server error
    // - 426 -> sever requests a encrypted connection
    // - 401 -> forbidden -> need authorization header or user is not permitted
    if httpResp.StatusCode != 200 {
        panic("non 200 response from server")
    }
    
    // decode ipp response
    resp, err := ipp.NewResponseDecoder(httpResp.Body).Decode(nil)
    if err != nil {
        panic(err)
    }
    
    // check if the response status is "ok"
    if resp.StatusCode == ipp.StatusOk {
        panic(resp.StatusCode)
    }
    
    // do something with the returned data
    for _, job := resp.JobAttributes {
        // ...
    }
}

Licence

Apache Licence Version 2.0

Documentation

Overview

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

** Copyright 2022 Dolysis Consulting Limited ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. ** ** For changes see the git log

Index

Constants

View Source
const (
	StatusCupsInvalid                         int16 = -1
	StatusOk                                  int16 = 0x0000
	StatusOkIgnoredOrSubstituted              int16 = 0x0001
	StatusOkConflicting                       int16 = 0x0002
	StatusOkIgnoredSubscriptions              int16 = 0x0003
	StatusOkIgnoredNotifications              int16 = 0x0004
	StatusOkTooManyEvents                     int16 = 0x0005
	StatusOkButCancelSubscription             int16 = 0x0006
	StatusOkEventsComplete                    int16 = 0x0007
	StatusRedirectionOtherSite                int16 = 0x0200
	StatusCupsSeeOther                        int16 = 0x0280
	StatusErrorBadRequest                     int16 = 0x0400
	StatusErrorForbidden                      int16 = 0x0401
	StatusErrorNotAuthenticated               int16 = 0x0402
	StatusErrorNotAuthorized                  int16 = 0x0403
	StatusErrorNotPossible                    int16 = 0x0404
	StatusErrorTimeout                        int16 = 0x0405
	StatusErrorNotFound                       int16 = 0x0406
	StatusErrorGone                           int16 = 0x0407
	StatusErrorRequestEntity                  int16 = 0x0408
	StatusErrorRequestValue                   int16 = 0x0409
	StatusErrorDocumentFormatNotSupported     int16 = 0x040a
	StatusErrorAttributesOrValues             int16 = 0x040b
	StatusErrorUriScheme                      int16 = 0x040c
	StatusErrorCharset                        int16 = 0x040d
	StatusErrorConflicting                    int16 = 0x040e
	StatusErrorCompressionError               int16 = 0x040f
	StatusErrorDocumentFormatError            int16 = 0x0410
	StatusErrorDocumentAccess                 int16 = 0x0411
	StatusErrorAttributesNotSettable          int16 = 0x0412
	StatusErrorIgnoredAllSubscriptions        int16 = 0x0413
	StatusErrorTooManySubscriptions           int16 = 0x0414
	StatusErrorIgnoredAllNotifications        int16 = 0x0415
	StatusErrorPrintSupportFileNotFound       int16 = 0x0416
	StatusErrorDocumentPassword               int16 = 0x0417
	StatusErrorDocumentPermission             int16 = 0x0418
	StatusErrorDocumentSecurity               int16 = 0x0419
	StatusErrorDocumentUnprintable            int16 = 0x041a
	StatusErrorAccountInfoNeeded              int16 = 0x041b
	StatusErrorAccountClosed                  int16 = 0x041c
	StatusErrorAccountLimitReached            int16 = 0x041d
	StatusErrorAccountAuthorizationFailed     int16 = 0x041e
	StatusErrorNotFetchable                   int16 = 0x041f
	StatusErrorCupsAccountInfoNeeded          int16 = 0x049C
	StatusErrorCupsAccountClosed              int16 = 0x049d
	StatusErrorCupsAccountLimitReached        int16 = 0x049e
	StatusErrorCupsAccountAuthorizationFailed int16 = 0x049f
	StatusErrorInternal                       int16 = 0x0500
	StatusErrorOperationNotSupported          int16 = 0x0501
	StatusErrorServiceUnavailable             int16 = 0x0502
	StatusErrorVersionNotSupported            int16 = 0x0503
	StatusErrorDevice                         int16 = 0x0504
	StatusErrorTemporary                      int16 = 0x0505
	StatusErrorNotAcceptingJobs               int16 = 0x0506
	StatusErrorBusy                           int16 = 0x0507
	StatusErrorJobCanceled                    int16 = 0x0508
	StatusErrorMultipleJobsNotSupported       int16 = 0x0509
	StatusErrorPrinterIsDeactivated           int16 = 0x050a
	StatusErrorTooManyJobs                    int16 = 0x050b
	StatusErrorTooManyDocuments               int16 = 0x050c
	StatusErrorCupsAuthenticationCanceled     int16 = 0x1000
	StatusErrorCupsPki                        int16 = 0x1001
	StatusErrorCupsUpgradeRequired            int16 = 0x1002
)

ipp status codes

View Source
const (
	OperationCupsInvalid                     int16 = -0x0001
	OperationCupsNone                        int16 = 0x0000
	OperationPrintJob                        int16 = 0x0002
	OperationPrintUri                        int16 = 0x0003
	OperationValidateJob                     int16 = 0x0004
	OperationCreateJob                       int16 = 0x0005
	OperationSendDocument                    int16 = 0x0006
	OperationSendUri                         int16 = 0x0007
	OperationCancelJob                       int16 = 0x0008
	OperationGetJobAttributes                int16 = 0x0009
	OperationGetJobs                         int16 = 0x000a
	OperationGetPrinterAttributes            int16 = 0x000b
	OperationHoldJob                         int16 = 0x000c
	OperationReleaseJob                      int16 = 0x000d
	OperationRestartJob                      int16 = 0x000e
	OperationPausePrinter                    int16 = 0x0010
	OperationResumePrinter                   int16 = 0x0011
	OperationPurgeJobs                       int16 = 0x0012
	OperationSetPrinterAttributes            int16 = 0x0013
	OperationSetJobAttributes                int16 = 0x0014
	OperationGetPrinterSupportedValues       int16 = 0x0015
	OperationCreatePrinterSubscriptions      int16 = 0x0016
	OperationCreateJobSubscriptions          int16 = 0x0017
	OperationGetSubscriptionAttributes       int16 = 0x0018
	OperationGetSubscriptions                int16 = 0x0019
	OperationRenewSubscription               int16 = 0x001a
	OperationCancelSubscription              int16 = 0x001b
	OperationGetNotifications                int16 = 0x001c
	OperationSendNotifications               int16 = 0x001d
	OperationGetResourceAttributes           int16 = 0x001e
	OperationGetResourceData                 int16 = 0x001f
	OperationGetResources                    int16 = 0x0020
	OperationGetPrintSupportFiles            int16 = 0x0021
	OperationEnablePrinter                   int16 = 0x0022
	OperationDisablePrinter                  int16 = 0x0023
	OperationPausePrinterAfterCurrentJob     int16 = 0x0024
	OperationHoldNewJobs                     int16 = 0x0025
	OperationReleaseHeldNewJobs              int16 = 0x0026
	OperationDeactivatePrinter               int16 = 0x0027
	OperationActivatePrinter                 int16 = 0x0028
	OperationRestartPrinter                  int16 = 0x0029
	OperationShutdownPrinter                 int16 = 0x002a
	OperationStartupPrinter                  int16 = 0x002b
	OperationReprocessJob                    int16 = 0x002c
	OperationCancelCurrentJob                int16 = 0x002d
	OperationSuspendCurrentJob               int16 = 0x002e
	OperationResumeJob                       int16 = 0x002f
	OperationOperationPromoteJob             int16 = 0x0030
	OperationScheduleJobAfter                int16 = 0x0031
	OperationCancelDocument                  int16 = 0x0033
	OperationGetDocumentAttributes           int16 = 0x0034
	OperationGetDocuments                    int16 = 0x0035
	OperationDeleteDocument                  int16 = 0x0036
	OperationSetDocumentAttributes           int16 = 0x0037
	OperationCancelJobs                      int16 = 0x0038
	OperationCancelMyJobs                    int16 = 0x0039
	OperationResubmitJob                     int16 = 0x003a
	OperationCloseJob                        int16 = 0x003b
	OperationIdentifyPrinter                 int16 = 0x003c
	OperationValidateDocument                int16 = 0x003d
	OperationAddDocumentImages               int16 = 0x003e
	OperationAcknowledgeDocument             int16 = 0x003f
	OperationAcknowledgeIdentifyPrinter      int16 = 0x0040
	OperationAcknowledgeJob                  int16 = 0x0041
	OperationFetchDocument                   int16 = 0x0042
	OperationFetchJob                        int16 = 0x0043
	OperationGetOutputDeviceAttributes       int16 = 0x0044
	OperationUpdateActiveJobs                int16 = 0x0045
	OperationDeregisterOutputDevice          int16 = 0x0046
	OperationUpdateDocumentStatus            int16 = 0x0047
	OperationUpdateJobStatus                 int16 = 0x0048
	OperationUpdateOutputDeviceAttributes    int16 = 0x0049
	OperationGetNextDocumentData             int16 = 0x004a
	OperationAllocatePrinterResources        int16 = 0x004b
	OperationCreatePrinter                   int16 = 0x004c
	OperationDeallocatePrinterResources      int16 = 0x004d
	OperationDeletePrinter                   int16 = 0x004e
	OperationGetPrinters                     int16 = 0x004f
	OperationShutdownOnePrinter              int16 = 0x0050
	OperationStartupOnePrinter               int16 = 0x0051
	OperationCancelResource                  int16 = 0x0052
	OperationCreateResource                  int16 = 0x0053
	OperationInstallResource                 int16 = 0x0054
	OperationSendResourceData                int16 = 0x0055
	OperationSetResourceAttributes           int16 = 0x0056
	OperationCreateResourceSubscriptions     int16 = 0x0057
	OperationCreateSystemSubscriptions       int16 = 0x0058
	OperationDisableAllPrinters              int16 = 0x0059
	OperationEnableAllPrinters               int16 = 0x005a
	OperationGetSystemAttributes             int16 = 0x005b
	OperationGetSystemSupportedValues        int16 = 0x005c
	OperationPauseAllPrinters                int16 = 0x005d
	OperationPauseAllPrintersAfterCurrentJob int16 = 0x005e
	OperationRegisterOutputDevice            int16 = 0x005f
	OperationRestartSystem                   int16 = 0x0060
	OperationResumeAllPrinters               int16 = 0x0061
	OperationSetSystemAttributes             int16 = 0x0062
	OperationShutdownAllPrinter              int16 = 0x0063
	OperationStartupAllPrinters              int16 = 0x0064
	OperationPrivate                         int16 = 0x4000
	OperationCupsGetDefault                  int16 = 0x4001
	OperationCupsGetPrinters                 int16 = 0x4002
	OperationCupsAddModifyPrinter            int16 = 0x4003
	OperationCupsDeletePrinter               int16 = 0x4004
	OperationCupsGetClasses                  int16 = 0x4005
	OperationCupsAddModifyClass              int16 = 0x4006
	OperationCupsDeleteClass                 int16 = 0x4007
	OperationCupsAcceptJobs                  int16 = 0x4008
	OperationCupsRejectJobs                  int16 = 0x4009
	OperationCupsSetDefault                  int16 = 0x400a
	OperationCupsGetDevices                  int16 = 0x400b
	OperationCupsGetPPDs                     int16 = 0x400c
	OperationCupsMoveJob                     int16 = 0x400d
	OperationCupsAuthenticateJob             int16 = 0x400e
	OperationCupsGetPpd                      int16 = 0x400f
	OperationCupsGetDocument                 int16 = 0x4027
	OperationCupsCreateLocalPrinter          int16 = 0x4028
)

ipp operations

View Source
const (
	TagCupsInvalid       int8 = -1
	TagZero              int8 = 0x00
	TagOperation         int8 = 0x01
	TagJob               int8 = 0x02
	TagEnd               int8 = 0x03
	TagPrinter           int8 = 0x04
	TagUnsupportedGroup  int8 = 0x05
	TagSubscription      int8 = 0x06
	TagEventNotification int8 = 0x07
	TagResource          int8 = 0x08
	TagDocument          int8 = 0x09
	TagSystem            int8 = 0x0a
	TagUnsupportedValue  int8 = 0x10
	TagDefault           int8 = 0x11
	TagUnknown           int8 = 0x12
	TagNoValue           int8 = 0x13
	TagNotSettable       int8 = 0x15
	TagDeleteAttr        int8 = 0x16
	TagAdminDefine       int8 = 0x17
	TagInteger           int8 = 0x21
	TagBoolean           int8 = 0x22
	TagEnum              int8 = 0x23
	TagString            int8 = 0x30
	TagDate              int8 = 0x31
	TagResolution        int8 = 0x32
	TagRange             int8 = 0x33
	TagBeginCollection   int8 = 0x34
	TagTextLang          int8 = 0x35
	TagNameLang          int8 = 0x36
	TagEndCollection     int8 = 0x37
	TagText              int8 = 0x41
	TagName              int8 = 0x42
	TagReservedString    int8 = 0x43
	TagKeyword           int8 = 0x44
	TagUri               int8 = 0x45
	TagUriScheme         int8 = 0x46
	TagCharset           int8 = 0x47
	TagLanguage          int8 = 0x48
	TagMimeType          int8 = 0x49
	TagMemberName        int8 = 0x4a
	TagExtension         int8 = 0x7f
)

ipp tags

View Source
const (
	JobStatePending    int8 = 0x03
	JobStateHeld       int8 = 0x04
	JobStateProcessing int8 = 0x05
	JobStateStopped    int8 = 0x06
	JobStateCanceled   int8 = 0x07
	JobStateAborted    int8 = 0x08
	JobStateCompleted  int8 = 0x09
)

job states

View Source
const (
	DocumentStatePending    int8 = 0x03
	DocumentStateProcessing int8 = 0x05
	DocumentStateCanceled   int8 = 0x07
	DocumentStateAborted    int8 = 0x08
	DocumentStateCompleted  int8 = 0x08
)

document states

View Source
const (
	PrinterStateIdle       int8 = 0x0003
	PrinterStateProcessing int8 = 0x0004
	PrinterStateStopped    int8 = 0x0005
)

printer states

View Source
const (
	JobStateFilterNotCompleted = "not-completed"
	JobStateFilterCompleted    = "completed"
	JobStateFilterAll          = "all"
)

job state filter

View Source
const (
	ErrorPolicyRetryJob        = "retry-job"
	ErrorPolicyAbortJob        = "abort-job"
	ErrorPolicyRetryCurrentJob = "retry-current-job"
	ErrorPolicyStopPrinter     = "stop-printer"
)

error policies

View Source
const (
	CharsetLanguage      = "en-US"
	Charset              = "utf-8"
	ProtocolVersionMajor = int8(2)
	ProtocolVersionMinor = int8(0)

	DefaultJobPriority = 50
)

ipp defaults

View Source
const (
	MimeTypePostscript  = "application/postscript"
	MimeTypeOctetStream = "application/octet-stream"
)

useful mime types for ipp

View Source
const (
	AttributeCopies                 = "copies"
	AttributeDocumentFormat         = "document-format"
	AttributeDocumentName           = "document-name"
	AttributeJobID                  = "job-id"
	AttributeJobName                = "job-name"
	AttributeJobPriority            = "job-priority"
	AttributeJobURI                 = "job-uri"
	AttributeLastDocument           = "last-document"
	AttributeMyJobs                 = "my-jobs"
	AttributePPDName                = "ppd-name"
	AttributePPDMakeAndModel        = "ppd-make-and-model"
	AttributePrinterIsShared        = "printer-is-shared"
	AttributePrinterURI             = "printer-uri"
	AttributePurgeJobs              = "purge-jobs"
	AttributeRequestedAttributes    = "requested-attributes"
	AttributeRequestingUserName     = "requesting-user-name"
	AttributeWhichJobs              = "which-jobs"
	AttributeFirstJobID             = "first-job-id"
	AttributeLimit                  = "limit"
	AttributeStatusMessage          = "status-message"
	AttributeCharset                = "attributes-charset"
	AttributeNaturalLanguage        = "attributes-natural-language"
	AttributeDeviceURI              = "device-uri"
	AttributeHoldJobUntil           = "job-hold-until"
	AttributePrinterErrorPolicy     = "printer-error-policy"
	AttributePrinterInfo            = "printer-info"
	AttributePrinterLocation        = "printer-location"
	AttributePrinterName            = "printer-name"
	AttributePrinterStateReasons    = "printer-state-reasons"
	AttributeJobPrinterURI          = "job-printer-uri"
	AttributeMemberURIs             = "member-uris"
	AttributeDocumentNumber         = "document-number"
	AttributeDocumentState          = "document-state"
	AttributeFinishings             = "finishings"
	AttributeJobHoldUntil           = "hold-job-until"
	AttributeJobSheets              = "job-sheets"
	AttributeJobState               = "job-state"
	AttributeJobStateReason         = "job-state-reason"
	AttributeMedia                  = "media"
	AttributeNumberUp               = "number-up"
	AttributeOrientationRequested   = "orientation-requested"
	AttributePrintQuality           = "print-quality"
	AttributePrinterIsAcceptingJobs = "printer-is-accepting-jobs"
	AttributePrinterResolution      = "printer-resolution"
	AttributePrinterState           = "printer-state"
	AttributeMemberNames            = "member-names"
	AttributePrinterType            = "printer-type"
	AttributePrinterMakeAndModel    = "printer-make-and-model"
	AttributePrinterStateMessage    = "printer-state-message"
	AttributePrinterUriSupported    = "printer-uri-supported"
	AttributeJobMediaProgress       = "job-media-progress"
	AttributeJobKilobyteOctets      = "job-k-octets"
	AttributeNumberOfDocuments      = "number-of-documents"
	AttributeJobOriginatingUserName = "job-originating-user-name"
	AttributeOutputOrder            = "outputorder"
	AttributeMediaCol               = "media-col"
)

known ipp attributes

View Source
const (
	ContentTypeIPP = "application/ipp"
)

ipp content types

View Source
const DefaultRequestRetryLimit = 3

Variables

View Source
var (
	DefaultSocketSearchPaths = []string{"/var/run/cupsd", "/var/run/cups/cups.sock", "/run/cups/cups.sock"}
	DefaultCertSearchPaths   = []string{"/etc/cups/certs/0", "/run/cups/certs/0"}
)

Default attributes

View Source
var (
	AttributeTagMapping = map[string]int8{
		AttributeCharset:                TagCharset,
		AttributeNaturalLanguage:        TagLanguage,
		AttributeCopies:                 TagInteger,
		AttributeDeviceURI:              TagUri,
		AttributeDocumentFormat:         TagMimeType,
		AttributeDocumentName:           TagName,
		AttributeDocumentNumber:         TagInteger,
		AttributeDocumentState:          TagEnum,
		AttributeFinishings:             TagEnum,
		AttributeJobHoldUntil:           TagKeyword,
		AttributeHoldJobUntil:           TagKeyword,
		AttributeJobID:                  TagInteger,
		AttributeJobName:                TagName,
		AttributeJobPrinterURI:          TagUri,
		AttributeJobPriority:            TagInteger,
		AttributeJobSheets:              TagName,
		AttributeJobState:               TagEnum,
		AttributeJobStateReason:         TagKeyword,
		AttributeJobURI:                 TagUri,
		AttributeLastDocument:           TagBoolean,
		AttributeMedia:                  TagKeyword,
		AttributeMemberURIs:             TagUri,
		AttributeMyJobs:                 TagBoolean,
		AttributeNumberUp:               TagInteger,
		AttributeOrientationRequested:   TagEnum,
		AttributePPDName:                TagName,
		AttributePPDMakeAndModel:        TagText,
		AttributeNumberOfDocuments:      TagInteger,
		AttributePrintQuality:           TagEnum,
		AttributePrinterErrorPolicy:     TagName,
		AttributePrinterInfo:            TagText,
		AttributePrinterIsAcceptingJobs: TagBoolean,
		AttributePrinterIsShared:        TagBoolean,
		AttributePrinterName:            TagName,
		AttributePrinterLocation:        TagText,
		AttributePrinterResolution:      TagResolution,
		AttributePrinterState:           TagEnum,
		AttributePrinterStateReasons:    TagKeyword,
		AttributePrinterURI:             TagUri,
		AttributePurgeJobs:              TagBoolean,
		AttributeRequestedAttributes:    TagKeyword,
		AttributeRequestingUserName:     TagName,
		AttributeWhichJobs:              TagKeyword,
		AttributeFirstJobID:             TagInteger,
		AttributeStatusMessage:          TagText,
		AttributeLimit:                  TagInteger,
		AttributeOutputOrder:            TagName,
		AttributeMediaCol:               TagBeginCollection,
	}
)

Attribute to tag mapping

View Source
var CertNotFoundError = errors.New("unable to locate CUPS certificate")
View Source
var SocketNotFoundError = errors.New("unable to locate CUPS socket")

Functions

func IsNotExistsError

func IsNotExistsError(err error) bool

IsNotExistsError checks a given error whether a printer or class does not exist

Types

type Adapter

type Adapter interface {
	SendRequest(url string, req *Request, additionalResponseData io.Writer) (*Response, error)
	GetHttpUri(namespace string, object interface{}) string
	TestConnection() error
}

type Attribute

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

Attribute defines an ipp attribute

type AttributeDecoder

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

AttributeDecoder reads and decodes ipp from an input stream

func NewAttributeDecoder

func NewAttributeDecoder(r io.Reader) *AttributeDecoder

NewAttributeDecoder returns a new decoder that reads from r

func (*AttributeDecoder) Decode

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

Decode reads the next ipp attribute into a attribute struct. the type is identified by a tag passed as an argument

type AttributeEncoder

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

AttributeEncoder encodes attribute to a io.Writer

func NewAttributeEncoder

func NewAttributeEncoder(w io.Writer) *AttributeEncoder

NewAttributeEncoder returns a new encoder that writes to w

func (*AttributeEncoder) Encode

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

Encode encodes a attribute and its value to a io.Writer the tag is determined by the AttributeTagMapping map

type Attributes

type Attributes map[string][]Attribute

Attributes is a wrapper for a set of attributes

type CUPSClient

type CUPSClient struct {
	*IPPClient
}

CUPSClient implements a ipp client with specific cups operations

func NewCUPSClient

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

NewCUPSClient creates a new cups ipp client (used HttpAdapter internally)

func NewCUPSClientWithAdapter

func NewCUPSClientWithAdapter(username string, adapter Adapter) *CUPSClient

NewCUPSClient creates a new cups ipp client with given Adapter

func (*CUPSClient) AcceptJobs

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

AcceptJobs lets a printer accept jobs again

func (*CUPSClient) AddPrinterToClass

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

AddPrinterToClass adds a printer to a class, if the class does not exists it will be crated

func (*CUPSClient) CreatePrinter

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

CreatePrinter creates a new printer

func (*CUPSClient) DeleteClass

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

DeleteClass deletes a class

func (*CUPSClient) DeletePrinter

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

DeletePrinter deletes a printer

func (*CUPSClient) DeletePrinterFromClass

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

DeletePrinterFromClass removes a printer from a class, if a class has no more printer it will be deleted

func (*CUPSClient) GetClasses

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

GetClasses returns a map of class names and attributes

func (*CUPSClient) GetDevices

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

GetDevices returns a map of device uris and printer attributes

func (*CUPSClient) GetPPDs

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

GetPPDs returns a map of ppd names and attributes

func (*CUPSClient) GetPrinters

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

GetPrinters returns a map of printer names and attributes

func (*CUPSClient) MoveAllJob

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

MoveAllJob moves all job from a printer to a other printer

func (*CUPSClient) MoveJob

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

MoveJob moves a job to a other printer

func (*CUPSClient) PrintTestPage

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

PrintTestPage prints a test page of type application/vnd.cups-pdf-banner

func (*CUPSClient) RejectJobs

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

RejectJobs does not let a printer accept jobs

func (*CUPSClient) SetPrinterDeviceURI

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

SetPrinterDeviceURI sets the device uri for a printer

func (*CUPSClient) SetPrinterErrorPolicy

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

SetPrinterErrorPolicy sets the error policy for a printer

func (*CUPSClient) SetPrinterInformation

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

SetPrinterInformation sets general printer information

func (*CUPSClient) SetPrinterIsShared

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

SetPrinterIsShared shares or unshares a printer in the network

func (*CUPSClient) SetPrinterLocation

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

SetPrinterLocation sets the printer location

func (*CUPSClient) SetPrinterPPD

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

SetPrinterPPD sets the ppd for a printer

type Document

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

Document wraps an io.Reader with more information, needed for encoding

type HTTPError

type HTTPError struct {
	Code int
}

HTTPError used for non 200 http codes

func (HTTPError) Error

func (e HTTPError) Error() string

type HttpAdapter

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

func NewHttpAdapter

func NewHttpAdapter(host string, port int, username, password string, useTLS bool) *HttpAdapter

func (*HttpAdapter) GetHttpUri

func (h *HttpAdapter) GetHttpUri(namespace string, object interface{}) string

func (*HttpAdapter) SendRequest

func (h *HttpAdapter) SendRequest(url string, req *Request, additionalResponseData io.Writer) (*Response, error)

func (*HttpAdapter) TestConnection

func (h *HttpAdapter) TestConnection() error

type IPPClient

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

IPPClient implements a generic ipp client

func NewIPPClient

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

NewIPPClient creates a new generic ipp client (used HttpAdapter internally)

func NewIPPClientWithAdapter

func NewIPPClientWithAdapter(username string, adapter Adapter) *IPPClient

NewIPPClientWithAdapter creates a new generic ipp client with given Adapter

func (*IPPClient) CancelAllJob

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

CancelAllJob cancels all jobs for a specified printer. if purge is true, the jobs will also be removed

func (*IPPClient) CancelJob

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

CancelJob cancels a job. if purge is true, the job will also be removed

func (*IPPClient) GetJobAttributes

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

GetJobAttributes returns the requested attributes for the specified job, if attributes is nil the default job will be used

func (*IPPClient) GetJobs

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

GetJobs returns jobs from a printer or class

func (*IPPClient) GetPrinterAttributes

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

GetPrinterAttributes returns the requested attributes for the specified printer, if attributes is nil the default attributes will be used

func (*IPPClient) HoldJobUntil

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

HoldJobUntil holds a job

func (*IPPClient) PausePrinter

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

PausePrinter pauses a printer

func (*IPPClient) PrintDocuments

func (c *IPPClient) PrintDocuments(docs []Document, printer string, jobAttributes map[string]interface{}) (int, error)

PrintDocuments prints one or more documents using a Create-Job operation followed by one or more Send-Document operation(s). custom job settings can be specified via the jobAttributes parameter

func (*IPPClient) PrintFile

func (c *IPPClient) PrintFile(filePath, printer string, jobAttributes map[string]interface{}) (int, error)

PrintFile prints a local file on the file system. custom job settings can be specified via the jobAttributes parameter

func (*IPPClient) PrintJob

func (c *IPPClient) PrintJob(doc Document, printer string, jobAttributes map[string]interface{}) (int, error)

PrintJob prints a document using a Print-Job operation. custom job settings can be specified via the jobAttributes parameter

func (*IPPClient) RestartJob

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

RestartJob restarts a job

func (*IPPClient) ResumePrinter

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

ResumePrinter resumes a printer

func (*IPPClient) SendRequest

func (c *IPPClient) SendRequest(url string, req *Request, additionalResponseData io.Writer) (*Response, error)

SendRequest sends a request to a remote uri end returns the response

func (*IPPClient) TestConnection

func (c *IPPClient) TestConnection() error

TestConnection tests if a tcp connection to the remote server is possible

type IPPError

type IPPError struct {
	Status  int16
	Message string
}

IPPError used for non ok ipp status codes

func (IPPError) Error

func (e IPPError) Error() string

type Request

type Request struct {
	ProtocolVersionMajor int8
	ProtocolVersionMinor int8

	Operation int16
	RequestId int32

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

	File     io.Reader
	FileSize int
}

Request defines a ipp request

func NewRequest

func NewRequest(op int16, reqID int32) *Request

NewRequest creates a new ipp request

func (*Request) Encode

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

Encode encodes the request to a byte slice

type RequestDecoder

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

RequestDecoder reads and decodes a request from a stream

func NewRequestDecoder

func NewRequestDecoder(r io.Reader) *RequestDecoder

NewRequestDecoder returns a new decoder that reads from r

func (*RequestDecoder) Decode

func (d *RequestDecoder) Decode(data io.Writer) (*Request, error)

Decode decodes a ipp request into a request struct. additional data will be written to an io.Writer if data is not nil

type Resolution

type Resolution struct {
	Height int32
	Width  int32
	Depth  int8
}

Resolution defines the resolution attribute

type Response

type Response struct {
	ProtocolVersionMajor int8
	ProtocolVersionMinor int8

	StatusCode int16
	RequestId  int32

	OperationAttributes Attributes
	PrinterAttributes   []Attributes
	JobAttributes       []Attributes
}

Response defines a ipp response

func NewResponse

func NewResponse(statusCode int16, reqID int32) *Response

NewResponse creates a new ipp response

func ParseControlFile

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

ParseControlFile reads and decodes a cups control file into a response

func (*Response) CheckForErrors

func (r *Response) CheckForErrors() error

CheckForErrors checks the status code and returns a error if it is not zero. it also returns the status message if provided by the server

func (*Response) Encode

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

Encode encodes the response to a byte slice

type ResponseDecoder

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

ResponseDecoder reads and decodes a response from a stream

func NewResponseDecoder

func NewResponseDecoder(r io.Reader) *ResponseDecoder

NewResponseDecoder returns a new decoder that reads from r

func (*ResponseDecoder) Decode

func (d *ResponseDecoder) Decode(data io.Writer) (*Response, error)

Decode decodes a ipp response into a response struct. additional data will be written to an io.Writer if data is not nil

type SocketAdapter

type SocketAdapter struct {
	SocketSearchPaths []string
	CertSearchPaths   []string
	//RequestRetryLimit is the number of times a request will be retried when receiving an authorized status. This usually happens when a CUPs cert is expired, and a retry will use the newly generated cert. Default 3.
	RequestRetryLimit int
	// contains filtered or unexported fields
}

func NewSocketAdapter

func NewSocketAdapter(host string, useTLS bool) *SocketAdapter

func (*SocketAdapter) GetCert

func (h *SocketAdapter) GetCert() (string, error)

GetCert returns the current CUPs authentication certificate by searching CertSearchPaths

func (*SocketAdapter) GetHttpUri

func (h *SocketAdapter) GetHttpUri(namespace string, object interface{}) string

func (*SocketAdapter) GetSocket

func (h *SocketAdapter) GetSocket() (string, error)

GetSocket returns the path to the cupsd socket by searching SocketSearchPaths

func (*SocketAdapter) SendRequest

func (h *SocketAdapter) SendRequest(url string, r *Request, additionalData io.Writer) (*Response, error)

DoRequest performs the given IPP request to the given URL, returning the IPP response or an error if one occurred. Additional data will be written to an io.Writer if additionalData is not nil

func (*SocketAdapter) TestConnection

func (h *SocketAdapter) TestConnection() error

Jump to

Keyboard shortcuts

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