A working proxy exists.
This commit is contained in:
@@ -32,14 +32,16 @@ func (h *ippResponseHeader) unmarshal(byteStream io.Reader) {
|
||||
binary.Read(byteStream, binary.BigEndian, &h.requestID)
|
||||
}
|
||||
|
||||
// Response represens a ipp response object
|
||||
type Response struct {
|
||||
a *attributes
|
||||
a *Attributes
|
||||
header ippResponseHeader
|
||||
}
|
||||
|
||||
// NewResponse creates a new ipp response object
|
||||
func NewResponse(code statusCode, requestID uint32) *Response {
|
||||
r := new(Response)
|
||||
r.a = new(attributes)
|
||||
r.a = new(Attributes)
|
||||
r.header.versionNumber = 0x0101
|
||||
r.header.requestID = requestID
|
||||
r.header.statusCode = code
|
||||
@@ -50,6 +52,7 @@ func (r Response) String() string {
|
||||
return r.header.String() + "\n" + r.a.String()
|
||||
}
|
||||
|
||||
// Marshal converts the response object to a wire formatted byte stream.
|
||||
func (r *Response) Marshal() []byte {
|
||||
a := make([]byte, 0, 20)
|
||||
a = append(a, r.header.marshal()...)
|
||||
@@ -75,21 +78,63 @@ func (r *Response) Marshal() []byte {
|
||||
return a
|
||||
}
|
||||
|
||||
// UnMarshal unmarshals a ipp response into a response object
|
||||
func (r *Response) UnMarshal(body io.Reader) {
|
||||
buffbody := bufio.NewReader(body)
|
||||
r.header.unmarshal(buffbody)
|
||||
//log.Printf("Header %v", r.header)
|
||||
r.a = UnMarshalAttributes(buffbody)
|
||||
}
|
||||
|
||||
func (r *Response) AddPrinterAttribute(a Attribute) {
|
||||
r.a.addAttribute(printerAttributes, a)
|
||||
// AddPrinterAttribute adds a printer attribute to the response object
|
||||
func (r *Response) AddPrinterAttribute(a Attribute) error {
|
||||
if a != nil {
|
||||
r.a.addAttribute(printerAttributes, a)
|
||||
return nil
|
||||
}
|
||||
return ErrNilAttribute
|
||||
}
|
||||
|
||||
func (r *Response) AddOperatonAttribute(a Attribute) {
|
||||
r.a.addAttribute(operationAttributes, a)
|
||||
// AddOperatonAttribute adds a printer attribute to the response object
|
||||
func (r *Response) AddOperatonAttribute(a Attribute) error {
|
||||
|
||||
if a != nil {
|
||||
r.a.addAttribute(operationAttributes, a)
|
||||
return nil
|
||||
}
|
||||
return ErrNilAttribute
|
||||
}
|
||||
|
||||
func (r *Response) AddJobAttribute(a Attribute) {
|
||||
r.a.addAttribute(jobAttributes, a)
|
||||
// AddJobAttribute adds a printer attribute to the response object
|
||||
func (r *Response) AddJobAttribute(a Attribute) error {
|
||||
if a != nil {
|
||||
r.a.addAttribute(jobAttributes, a)
|
||||
return nil
|
||||
}
|
||||
return ErrNilAttribute
|
||||
}
|
||||
|
||||
// GetAttribute retreives a attribute by name from the response object
|
||||
// returns nil a atribute with the provided name can be found.
|
||||
func (r *Response) GetAttribute(name string) Attribute {
|
||||
for _, a := range r.a.operation {
|
||||
if a.Name() == name {
|
||||
return a
|
||||
}
|
||||
}
|
||||
for _, a := range r.a.job {
|
||||
if a.Name() == name {
|
||||
return a
|
||||
}
|
||||
}
|
||||
for _, a := range r.a.printer {
|
||||
if a.Name() == name {
|
||||
return a
|
||||
}
|
||||
}
|
||||
for _, a := range r.a.unsupported {
|
||||
if a.Name() == name {
|
||||
return a
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user