Fix lint warnings.

This commit was merged in pull request #11.
This commit is contained in:
2021-01-09 12:10:43 +01:00
parent f449b535db
commit 0805cec129
19 changed files with 85 additions and 84 deletions

View File

@@ -24,7 +24,7 @@ func main() {
request := ipp.NewRequest(ipp.GetPrinterAttributes, 10)
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
request.AddOperatonAttribute(ipp.NewNaturalLanguage("attributes-natural-language", "en"))
request.AddOperatonAttribute(ipp.NewUriValue("printer-uri", "ipp://"+printerUri))
request.AddOperatonAttribute(ipp.NewURIValue("printer-uri", "ipp://"+printerUri))
r := request.Marshal()
b := bytes.NewBuffer(r)
httpResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", b)

View File

@@ -37,15 +37,15 @@ func (b *boolean) unmarshal(byteStream io.Reader) {
log.Warn("Unmarshal of boolean is not implemented yet")
}
func (e *boolean) marshal() []byte {
l := 5 + len(e.name)
b := make([]byte, 0, l)
buf := bytes.NewBuffer(b)
func (b *boolean) marshal() []byte {
l := 5 + len(b.name)
ba := make([]byte, 0, l)
buf := bytes.NewBuffer(ba)
buf.WriteByte(byte(booleanValueTag))
binary.Write(buf, binary.BigEndian, uint16(len(e.name)))
buf.WriteString(e.name)
binary.Write(buf, binary.BigEndian, uint16(len(b.name)))
buf.WriteString(b.name)
binary.Write(buf, binary.BigEndian, uint16(1))
if e.value {
if b.value {
buf.WriteByte(byte(1))
} else {
buf.WriteByte(byte(0))
@@ -53,7 +53,7 @@ func (e *boolean) marshal() []byte {
return buf.Bytes()
}
func (e *boolean) size() int {
l := 5 + len(e.name)
func (b *boolean) size() int {
l := 5 + len(b.name)
return l
}

View File

@@ -34,7 +34,7 @@ func (c *charSetValue) unmarshal(byteStream io.Reader) {
func (c *charSetValue) marshal() []byte {
l := 5 + len(c.name) + len(c.value)
b := make([]byte, l, l)
b := make([]byte, l)
b[0] = byte(charsetValueTag)
marshalNameValue(c.name, c.value, b[1:])
return b

View File

@@ -32,8 +32,8 @@ func (e *enum) size() int {
return 9 + len(e.name)
}
func (i *enum) addValue(v interface{}) {
i.values = append(i.values, v.(int32))
func (e *enum) addValue(v interface{}) {
e.values = append(e.values, v.(int32))
}
func (e *enum) marshal() []byte {

View File

@@ -1,3 +1,4 @@
//Package ipp provides functonality to handle ipp messages
package ipp
import (
@@ -56,26 +57,26 @@ const (
memberAttrNameValueTag tag = 0x4a
)
// Operation-id, defined in rfc8011
type OperationId uint16
// OperationID is defined in rfc8011
type OperationID uint16
const (
PrintJob OperationId = 0x0002
PrintURI OperationId = 0x0003
ValidateJob OperationId = 0x0004
CreateJob OperationId = 0x0005
SendDocument OperationId = 0x0006
SendURI OperationId = 0x0007
CancelJob OperationId = 0x0008
GetJobAttributes OperationId = 0x0009
GetJobs OperationId = 0x000a
GetPrinterAttributes OperationId = 0x000b
HoldJob OperationId = 0x000c
ReleaseJob OperationId = 0x000d
RestartJob OperationId = 0x000e
PausePrinter OperationId = 0x0010
ResumePrinter OperationId = 0x0011
PurgeJobs OperationId = 0x0012
PrintJob OperationID = 0x0002
PrintURI OperationID = 0x0003
ValidateJob OperationID = 0x0004
CreateJob OperationID = 0x0005
SendDocument OperationID = 0x0006
SendURI OperationID = 0x0007
CancelJob OperationID = 0x0008
GetJobAttributes OperationID = 0x0009
GetJobs OperationID = 0x000a
GetPrinterAttributes OperationID = 0x000b
HoldJob OperationID = 0x000c
ReleaseJob OperationID = 0x000d
RestartJob OperationID = 0x000e
PausePrinter OperationID = 0x0010
ResumePrinter OperationID = 0x0011
PurgeJobs OperationID = 0x0012
)
type printerState int32
@@ -166,14 +167,14 @@ func (a *attributes) String() string {
return s
}
func (as *attributes) addAttribute(group tag, a Attribute) {
func (a *attributes) addAttribute(group tag, attr Attribute) {
switch group {
case operationAttributes:
as.operation = append(as.operation, a)
a.operation = append(a.operation, attr)
case jobAttributes:
as.job = append(as.job, a)
a.job = append(a.job, attr)
case printerAttributes:
as.printer = append(as.printer, a)
a.printer = append(a.printer, attr)
default:
log.Error("Unknown attribute group")
}
@@ -210,7 +211,7 @@ func UnMarshalAttributues(body io.Reader) *attributes {
a.addAttribute(currentAttributeGroup, c)
log.Debugf("%v %v", c.name, c.value)
case uriValueTag:
u := NewUriValue("", "")
u := NewURIValue("", "")
u.unmarshal(body)
a.addAttribute(currentAttributeGroup, u)
log.Debugf("%v %v", u.name, u.value)

View File

@@ -14,33 +14,33 @@ func NewNameWithoutLanguage(name, value string) *NameWithoutLanguage {
return c
}
func (c NameWithoutLanguage) Name() string {
return c.name
func (n NameWithoutLanguage) Name() string {
return n.name
}
func (c NameWithoutLanguage) String() string {
return c.name + ":" + c.value
func (n NameWithoutLanguage) String() string {
return n.name + ":" + n.value
}
func (c *NameWithoutLanguage) valueTag() tag {
func (n *NameWithoutLanguage) valueTag() tag {
return nameWithoutLanguageValueTag
}
func (c *NameWithoutLanguage) unmarshal(byteStream io.Reader) {
c.name, c.value = unmarshalSingleValue(byteStream)
func (n *NameWithoutLanguage) unmarshal(byteStream io.Reader) {
n.name, n.value = unmarshalSingleValue(byteStream)
}
func (c *NameWithoutLanguage) marshal() []byte {
l := 5 + len(c.name) + len(c.value)
b := make([]byte, l, l)
func (n *NameWithoutLanguage) marshal() []byte {
l := 5 + len(n.name) + len(n.value)
b := make([]byte, l)
b[0] = byte(nameWithoutLanguageValueTag)
marshalNameValue(c.name, c.value, b[1:])
marshalNameValue(n.name, n.value, b[1:])
return b
}
func (c *NameWithoutLanguage) size() int {
func (n *NameWithoutLanguage) size() int {
l := 1 + 4 // The attribute tag + 2 lengths
l += len(c.name)
l += len(c.value)
l += len(n.name)
l += len(n.value)
return l
}

View File

@@ -34,7 +34,7 @@ func (c *naturalLanguage) unmarshal(byteStream io.Reader) {
func (c *naturalLanguage) marshal() []byte {
l := 5 + len(c.name) + len(c.value)
b := make([]byte, l, l)
b := make([]byte, l)
b[0] = byte(naturalLanguageValueTag)
marshalNameValue(c.name, c.value, b[1:])
return b

View File

@@ -36,7 +36,7 @@ var (
_operationId_index_1 = [...]uint8{0, 12, 25, 34}
)
func (i OperationId) String() string {
func (i OperationID) String() string {
switch {
case 2 <= i && i <= 14:
i -= 2

View File

@@ -9,27 +9,27 @@ import (
type ippMessageHeader struct {
versionNumber versionNumber
operationId OperationId
requestId uint32
operationID OperationID
requestID uint32
}
func (h *ippMessageHeader) unmarshal(byteStream io.Reader) {
binary.Read(byteStream, binary.BigEndian, &h.versionNumber)
binary.Read(byteStream, binary.BigEndian, &h.operationId)
binary.Read(byteStream, binary.BigEndian, &h.requestId)
binary.Read(byteStream, binary.BigEndian, &h.operationID)
binary.Read(byteStream, binary.BigEndian, &h.requestID)
}
func (h *ippMessageHeader) marshal() []byte {
b := make([]byte, 0, 8)
buf := bytes.NewBuffer(b)
binary.Write(buf, binary.BigEndian, h.versionNumber)
binary.Write(buf, binary.BigEndian, h.operationId)
binary.Write(buf, binary.BigEndian, h.requestId)
binary.Write(buf, binary.BigEndian, h.operationID)
binary.Write(buf, binary.BigEndian, h.requestID)
return buf.Bytes()
}
func (h ippMessageHeader) String() string {
return fmt.Sprintf("Version number: %v Operation Id: %v Request Id: %v", h.versionNumber, h.operationId, h.requestId)
return fmt.Sprintf("Version number: %v Operation Id: %v Request Id: %v", h.versionNumber, h.operationID, h.requestID)
}
type AddValuer interface {
@@ -41,10 +41,10 @@ type Request struct {
header ippMessageHeader
}
func NewRequest(op OperationId, requestId uint32) *Request {
func NewRequest(op OperationID, requestID uint32) *Request {
r := new(Request)
r.header.operationId = op
r.header.requestId = requestId
r.header.operationID = op
r.header.requestID = requestID
r.header.versionNumber = 0x0200
r.a = new(attributes)
return r
@@ -60,12 +60,12 @@ func (r *Request) UnMarshal(body io.Reader) {
r.a = UnMarshalAttributues(body)
}
func (r *Request) RequestId() uint32 {
return r.header.requestId
func (r *Request) RequestID() uint32 {
return r.header.requestID
}
func (r *Request) Operation() OperationId {
return r.header.operationId
func (r *Request) Operation() OperationID {
return r.header.operationID
}
func (r *Request) GetAttribute(name string) Attribute {

View File

@@ -64,8 +64,8 @@ func TestUnmarshalRequestPrinterAttributes(T *testing.T) {
req.UnMarshal(buf)
fmt.Print(req)
assert.Equal(T, versionNumber(0x0101), req.header.versionNumber, "Wrong version number")
assert.Equal(T, GetPrinterAttributes, req.header.operationId, "Wrong Operation")
assert.Equal(T, uint32(17), req.header.requestId, "Wrong request id")
assert.Equal(T, GetPrinterAttributes, req.header.operationID, "Wrong Operation")
assert.Equal(T, uint32(17), req.header.requestID, "Wrong request id")
assert.Len(T, req.a.operation, 4)
v := req.GetAttribute("requested-attributes").(*keyWord).sos.values
assert.Len(T, v, 7)

View File

@@ -9,18 +9,18 @@ import (
type ippResponseHeader struct {
versionNumber versionNumber
statusCode statusCode
requestId uint32
requestID uint32
}
func (h ippResponseHeader) String() string {
return fmt.Sprintf("Version number: %v Status code: %v Request Id: %v", h.versionNumber, h.statusCode, h.requestId)
return fmt.Sprintf("Version number: %v Status code: %v Request Id: %v", h.versionNumber, h.statusCode, h.requestID)
}
func (h *ippResponseHeader) marshal() []byte {
a := make([]byte, 8, 8)
a := make([]byte, 8)
binary.BigEndian.PutUint16(a[0:2], uint16(h.versionNumber))
binary.BigEndian.PutUint16(a[2:4], uint16(h.statusCode))
binary.BigEndian.PutUint32(a[4:8], h.requestId)
binary.BigEndian.PutUint32(a[4:8], h.requestID)
return a
}
@@ -28,7 +28,7 @@ func (h *ippResponseHeader) marshal() []byte {
func (h *ippResponseHeader) unmarshal(byteStream io.Reader) {
binary.Read(byteStream, binary.BigEndian, &h.versionNumber)
binary.Read(byteStream, binary.BigEndian, &h.statusCode)
binary.Read(byteStream, binary.BigEndian, &h.requestId)
binary.Read(byteStream, binary.BigEndian, &h.requestID)
}
type Response struct {
@@ -36,11 +36,11 @@ type Response struct {
header ippResponseHeader
}
func NewResponse(code statusCode, requestId uint32) *Response {
func NewResponse(code statusCode, requestID uint32) *Response {
r := new(Response)
r.a = new(attributes)
r.header.versionNumber = 0x0101
r.header.requestId = requestId
r.header.requestID = requestID
r.header.statusCode = code
return r
}

View File

@@ -10,7 +10,7 @@ func TestMarshalResponseHeader(T *testing.T) {
h.versionNumber = 0x0101
h.statusCode = SuccessfulOk
h.requestId = 0xdeadbeef
h.requestID = 0xdeadbeef
b := h.marshal()
fmt.Printf("% x\n", b)

View File

@@ -44,7 +44,7 @@ func (s *setOfStrings) marshal() []byte {
for i := range s.values[1:] {
l += 5 + len(s.values[i+1])
}
res := make([]byte, l, l)
res := make([]byte, l)
p := 0
res[p] = byte(s.vTag)
p += 1

View File

@@ -32,7 +32,7 @@ func (c *textWithoutLanguage) unmarshal(byteStream io.Reader) {
func (c *textWithoutLanguage) marshal() []byte {
l := 5 + len(c.name) + len(c.value)
b := make([]byte, l, l)
b := make([]byte, l)
b[0] = byte(textWithoutLanguageValueTag)
marshalNameValue(c.name, c.value, b[1:])
return b

View File

@@ -9,7 +9,7 @@ type uriValue struct {
value string
}
func NewUriValue(name, value string) *uriValue {
func NewURIValue(name, value string) *uriValue {
u := new(uriValue)
u.name = name
u.value = value

View File

@@ -3,6 +3,6 @@ package main
import "ippserver/packages/ipp"
func handleGetJobs(r *ipp.Request) *ipp.Response {
response := ipp.NewResponse(ipp.SuccessfulOk, r.RequestId())
response := ipp.NewResponse(ipp.SuccessfulOk, r.RequestID())
return response
}

View File

@@ -3,13 +3,13 @@ package main
import "ippserver/packages/ipp"
func handleGetPrinterAttributes(r *ipp.Request) *ipp.Response {
response := ipp.NewResponse(ipp.SuccessfulOk, r.RequestId())
response := ipp.NewResponse(ipp.SuccessfulOk, r.RequestID())
var a ipp.Attribute
a = ipp.NewCharSetValue("attributes-charset", "utf-8")
response.AddOperatonAttribute(a)
a = ipp.NewNaturalLanguage("attributes-natural-language", "en")
response.AddOperatonAttribute(a)
a = ipp.NewUriValue("printer-uri", "ipp://drpork:1234/ipp/print")
a = ipp.NewURIValue("printer-uri", "ipp://drpork:1234/ipp/print")
response.AddOperatonAttribute(a)
a = ipp.NewtextWithoutLanguage("printer-make-and-model", "ChroBro 001")
response.AddOperatonAttribute(a)

View File

@@ -16,7 +16,7 @@ func handlePrintJob(r *ipp.Request, byteStream io.Reader) *ipp.Response {
}
defer f.Close()
io.Copy(f, byteStream)
response := ipp.NewResponse(ipp.SuccessfulOk, r.RequestId())
response := ipp.NewResponse(ipp.SuccessfulOk, r.RequestID())
return response
}

View File

@@ -57,7 +57,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
case ipp.GetJobs:
response = handleGetJobs(request)
default:
response = ipp.NewResponse(ipp.ClientErrorBadRequest, request.RequestId())
response = ipp.NewResponse(ipp.ClientErrorBadRequest, request.RequestID())
}
log.Infof("Response:\n%v\n", response)