initial parsing of requests
This commit is contained in:
69
main.go
69
main.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"ippserver/packages/mdnsserver"
|
||||
"net/http"
|
||||
|
||||
@@ -25,12 +26,74 @@ func main() {
|
||||
|
||||
func handle(w http.ResponseWriter, r *http.Request) {
|
||||
log.Infoln("handle")
|
||||
if r.Method != "POST" {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Unsupported method", http.StatusMethodNotAllowed)
|
||||
|
||||
}
|
||||
// Disable caching of this page
|
||||
var request ippRequest
|
||||
request.operationAttributes = make(map[string]string)
|
||||
request.requestedAttributes = make([]string, 0)
|
||||
log.Info(r.Header)
|
||||
log.Info(r.ContentLength)
|
||||
//body := make([]byte, r.ContentLength)
|
||||
//r.Body.Read(body)
|
||||
binary.Read(r.Body, binary.BigEndian, &request.header.versionNumber)
|
||||
binary.Read(r.Body, binary.BigEndian, &request.header.operationId)
|
||||
binary.Read(r.Body, binary.BigEndian, &request.header.requestId)
|
||||
var tag uint8
|
||||
binary.Read(r.Body, binary.BigEndian, &tag)
|
||||
if tag == operationAttributesTag {
|
||||
var length uint16
|
||||
binary.Read(r.Body, binary.BigEndian, &tag)
|
||||
for tag != endOfAttributesTag {
|
||||
log.Infof("Value tag %x", tag)
|
||||
switch tag {
|
||||
case charsetValueTag, uriValueTag, naturalLanguagageValueTag:
|
||||
binary.Read(r.Body, binary.BigEndian, &length)
|
||||
attributeName := make([]byte, length)
|
||||
binary.Read(r.Body, binary.BigEndian, attributeName)
|
||||
binary.Read(r.Body, binary.BigEndian, &length)
|
||||
attributeValue := make([]byte, length)
|
||||
binary.Read(r.Body, binary.BigEndian, attributeValue)
|
||||
request.operationAttributes[string(attributeName)] = string(attributeValue)
|
||||
log.Infof("%v %v", string(attributeName), string(attributeValue))
|
||||
binary.Read(r.Body, binary.BigEndian, &tag)
|
||||
case keywordValueTag:
|
||||
binary.Read(r.Body, binary.BigEndian, &length)
|
||||
attributeName := make([]byte, length)
|
||||
set := make([]string, 0)
|
||||
binary.Read(r.Body, binary.BigEndian, &attributeName)
|
||||
binary.Read(r.Body, binary.BigEndian, &length)
|
||||
value := make([]byte, length)
|
||||
binary.Read(r.Body, binary.BigEndian, &value)
|
||||
set = append(set, string(value))
|
||||
binary.Read(r.Body, binary.BigEndian, &tag)
|
||||
for tag == keywordValueTag {
|
||||
var additionalValue uint16
|
||||
binary.Read(r.Body, binary.BigEndian, &additionalValue)
|
||||
binary.Read(r.Body, binary.BigEndian, &length)
|
||||
value = make([]byte, length)
|
||||
binary.Read(r.Body, binary.BigEndian, &value)
|
||||
set = append(set, string(value))
|
||||
binary.Read(r.Body, binary.BigEndian, &tag)
|
||||
}
|
||||
if string(attributeName) == "requested-attributes" {
|
||||
request.requestedAttributes = set
|
||||
}
|
||||
log.Infof("%v %v", string(attributeName), set)
|
||||
default:
|
||||
log.Error("Unsupported tag")
|
||||
|
||||
// Check if user is logged in, if not redirect to login page
|
||||
}
|
||||
}
|
||||
log.Infof("Value tag %x", tag)
|
||||
} else {
|
||||
log.Error("unexpected tag")
|
||||
// TODO Return something sensible here
|
||||
|
||||
}
|
||||
|
||||
log.Infof("request %+v", request)
|
||||
//log.Infof("Body %v", string(body))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user