A working proxy exists.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
//Package ipp provides functonality to handle ipp messages
|
||||
//go:generate stringer -type jobState -type printerState
|
||||
package ipp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
@@ -14,6 +16,9 @@ import (
|
||||
// https://tools.ietf.org/html/rfc8010
|
||||
// https://tools.ietf.org/html/rfc8011
|
||||
|
||||
// ErrNilAttribute is returned when an attempt to use nil as a attribute
|
||||
var ErrNilAttribute = errors.New("can not add use nil as attribute")
|
||||
|
||||
// Defined value tags
|
||||
// from rfc8010
|
||||
type tag uint8
|
||||
@@ -89,12 +94,27 @@ const (
|
||||
Stopped printerState = 5
|
||||
)
|
||||
|
||||
// jobstate defined in rfc8011 ch 5.3.7
|
||||
type jobState uint16
|
||||
|
||||
const (
|
||||
pending jobState = 3
|
||||
pendingHeld jobState = 4
|
||||
processing jobState = 5
|
||||
processingStoppped jobState = 6
|
||||
cancelled jobState = 7
|
||||
aborted jobState = 8
|
||||
completed jobState = 9
|
||||
)
|
||||
|
||||
type statusCode uint16
|
||||
|
||||
// status code defenitions
|
||||
const (
|
||||
SuccessfulOk statusCode = 0x0000
|
||||
ClientErrorBadRequest statusCode = 0x0400
|
||||
SuccessfulOk statusCode = 0x0000
|
||||
SuccessfulOkIgnoredOrSubstitutedAttributes statusCode = 0x0001
|
||||
SuccessfulOkConflictingAttributes statusCode = 0x0002
|
||||
ClientErrorBadRequest statusCode = 0x0400
|
||||
)
|
||||
|
||||
type versionNumber uint16
|
||||
@@ -148,13 +168,14 @@ type Attribute interface {
|
||||
//size() int
|
||||
}
|
||||
|
||||
type attributes struct {
|
||||
operation []Attribute
|
||||
printer []Attribute
|
||||
job []Attribute
|
||||
type Attributes struct {
|
||||
operation []Attribute
|
||||
printer []Attribute
|
||||
job []Attribute
|
||||
unsupported []Attribute
|
||||
}
|
||||
|
||||
func (a *attributes) String() string {
|
||||
func (a *Attributes) String() string {
|
||||
s := " OperationAttributes" + "\n"
|
||||
for _, a := range a.operation {
|
||||
s = s + fmt.Sprintf(" %v (%v)\n", a, a.valueTag())
|
||||
@@ -167,10 +188,15 @@ func (a *attributes) String() string {
|
||||
for _, a := range a.job {
|
||||
s = s + fmt.Sprintf(" %v (%v)\n", a, a.valueTag())
|
||||
}
|
||||
s = s + " Unsupported" + "\n"
|
||||
for _, a := range a.unsupported {
|
||||
s = s + fmt.Sprintf(" %v (%v)\n", a, a.valueTag())
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (a *attributes) addAttribute(group tag, attr Attribute) {
|
||||
func (a *Attributes) addAttribute(group tag, attr Attribute) {
|
||||
switch group {
|
||||
case operationAttributes:
|
||||
a.operation = append(a.operation, attr)
|
||||
@@ -178,13 +204,15 @@ func (a *attributes) addAttribute(group tag, attr Attribute) {
|
||||
a.job = append(a.job, attr)
|
||||
case printerAttributes:
|
||||
a.printer = append(a.printer, attr)
|
||||
case unsupportedAttributes:
|
||||
a.unsupported = append(a.unsupported, attr)
|
||||
default:
|
||||
log.Error("Unknown attribute group")
|
||||
log.Errorf("Unknown attribute group %v", group)
|
||||
}
|
||||
}
|
||||
|
||||
func UnMarshalAttributes(bytestream *bufio.Reader) *attributes {
|
||||
a := new(attributes)
|
||||
func UnMarshalAttributes(bytestream *bufio.Reader) *Attributes {
|
||||
a := new(Attributes)
|
||||
|
||||
var t tag
|
||||
err := binary.Read(bytestream, binary.BigEndian, &t)
|
||||
@@ -290,6 +318,11 @@ func UnMarshalAttributes(bytestream *bufio.Reader) *attributes {
|
||||
case begCollectionValueTag:
|
||||
// For now just consume the collection
|
||||
consumeCollection(bytestream)
|
||||
case unsupportedValueTag:
|
||||
attr := NewUnsupportedValue()
|
||||
attr.unmarshal(bytestream)
|
||||
a.addAttribute(currentAttributeGroup, attr)
|
||||
|
||||
case jobAttributes:
|
||||
log.Debug("Start job attributes")
|
||||
currentAttributeGroup = jobAttributes
|
||||
@@ -299,8 +332,11 @@ func UnMarshalAttributes(bytestream *bufio.Reader) *attributes {
|
||||
case operationAttributes:
|
||||
log.Debug("Start operation attributes")
|
||||
currentAttributeGroup = operationAttributes
|
||||
case unsupportedAttributes:
|
||||
log.Debug("Start unsupported attributes")
|
||||
currentAttributeGroup = unsupportedAttributes
|
||||
case resolutionValueTag:
|
||||
res := NewResolution("", 0, 0)
|
||||
res := NewSetOfResolution("")
|
||||
res.unmarshal(bytestream)
|
||||
a.addAttribute(currentAttributeGroup, res)
|
||||
log.Debugf("Resolution %v", res)
|
||||
|
||||
Reference in New Issue
Block a user