A working proxy exists.
This commit is contained in:
@@ -1,67 +1,95 @@
|
||||
package ipp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type resolution struct {
|
||||
name string
|
||||
crossFeedResolution int32
|
||||
feedResolution int32
|
||||
units int8
|
||||
// Resolution represents a ipp resolution attribute
|
||||
type Resolution struct {
|
||||
CrossFeedResolution int32
|
||||
FeedResolution int32
|
||||
Unit int8 // 3 seems to mean dpi (rfc3805)
|
||||
}
|
||||
|
||||
func NewResolution(name string, xfres int32, fres int32) *resolution {
|
||||
r := new(resolution)
|
||||
// SetOfResolutions represents a set ipp resolution attributes
|
||||
type SetOfResolutions struct {
|
||||
name string
|
||||
sor []Resolution
|
||||
}
|
||||
|
||||
// NewSetOfResolution creats a new set of ipp resolution attributes
|
||||
func NewSetOfResolution(name string, resSet ...Resolution) *SetOfResolutions {
|
||||
r := new(SetOfResolutions)
|
||||
r.name = name
|
||||
r.crossFeedResolution = xfres
|
||||
r.feedResolution = fres
|
||||
r.units = 3 // 3 seems to mean dpi (rfc3805)
|
||||
r.sor = resSet
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resolution) unmarshal(byteStream io.Reader) {
|
||||
func (r *SetOfResolutions) unmarshal(byteStream *bufio.Reader) {
|
||||
var length uint16
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
attributeName := make([]byte, length)
|
||||
if length > 0 {
|
||||
binary.Read(byteStream, binary.BigEndian, attributeName)
|
||||
var res Resolution
|
||||
for {
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
attributeName := make([]byte, length)
|
||||
if length > 0 {
|
||||
binary.Read(byteStream, binary.BigEndian, attributeName)
|
||||
r.name = string(attributeName)
|
||||
}
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
if length != 9 {
|
||||
panic("Wrong length in resolution")
|
||||
}
|
||||
binary.Read(byteStream, binary.BigEndian, &res.CrossFeedResolution)
|
||||
binary.Read(byteStream, binary.BigEndian, &res.FeedResolution)
|
||||
binary.Read(byteStream, binary.BigEndian, &res.Unit)
|
||||
r.sor = append(r.sor, res)
|
||||
var t tag
|
||||
err := binary.Read(byteStream, binary.BigEndian, &t)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
if t != resolutionValueTag {
|
||||
byteStream.UnreadByte()
|
||||
return
|
||||
}
|
||||
}
|
||||
r.name = string(attributeName)
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
if length != 9 {
|
||||
panic("Wrong length in resolution")
|
||||
}
|
||||
binary.Read(byteStream, binary.BigEndian, &r.crossFeedResolution)
|
||||
binary.Read(byteStream, binary.BigEndian, &r.feedResolution)
|
||||
binary.Read(byteStream, binary.BigEndian, &r.units)
|
||||
}
|
||||
|
||||
func (r resolution) Name() string {
|
||||
// Name returns the name of the attribute
|
||||
func (r SetOfResolutions) Name() string {
|
||||
return r.name
|
||||
}
|
||||
|
||||
func (r resolution) String() string {
|
||||
return fmt.Sprintf("%v:%v,%v,%v", r.name, r.crossFeedResolution, r.feedResolution, r.units)
|
||||
func (r SetOfResolutions) String() string {
|
||||
return fmt.Sprintf("%v:%v", r.name, r.sor)
|
||||
}
|
||||
|
||||
func (r *resolution) marshal() []byte {
|
||||
func (r *SetOfResolutions) marshal() []byte {
|
||||
|
||||
b := make([]byte, 0, 14+len(r.name))
|
||||
b := make([]byte, 0, 14+len(r.name)+14*(len(r.sor)-1))
|
||||
buf := bytes.NewBuffer(b)
|
||||
buf.WriteByte(byte(resolutionValueTag))
|
||||
binary.Write(buf, binary.BigEndian, uint16(len(r.name)))
|
||||
buf.WriteString(r.name)
|
||||
binary.Write(buf, binary.BigEndian, uint16(9))
|
||||
binary.Write(buf, binary.BigEndian, int32(r.crossFeedResolution))
|
||||
binary.Write(buf, binary.BigEndian, int32(r.feedResolution))
|
||||
buf.WriteByte(byte(r.units))
|
||||
|
||||
for i, res := range r.sor {
|
||||
buf.WriteByte(byte(resolutionValueTag))
|
||||
if i == 0 {
|
||||
binary.Write(buf, binary.BigEndian, uint16(len(r.name)))
|
||||
buf.WriteString(r.name)
|
||||
} else {
|
||||
binary.Write(buf, binary.BigEndian, uint16(0))
|
||||
}
|
||||
binary.Write(buf, binary.BigEndian, uint16(9))
|
||||
binary.Write(buf, binary.BigEndian, int32(res.CrossFeedResolution))
|
||||
binary.Write(buf, binary.BigEndian, int32(res.FeedResolution))
|
||||
buf.WriteByte(byte(res.Unit))
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func (r *resolution) valueTag() tag {
|
||||
func (r *SetOfResolutions) valueTag() tag {
|
||||
return resolutionValueTag
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user