A working proxy exists.
This commit is contained in:
@@ -3,12 +3,16 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"ippserver/packages/ipp"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const printerURI = "brn30055cb5e3ae.local:631/ipp/print"
|
||||
|
||||
//application/ipp
|
||||
// brn30055cb5e3ae.local:631/ipp/print
|
||||
func main() {
|
||||
@@ -17,14 +21,12 @@ func main() {
|
||||
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
|
||||
log.SetFormatter(customFormatter)
|
||||
customFormatter.FullTimestamp = true
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
const printerUri = "brn30055cb5e3ae.local:631/ipp/print"
|
||||
log.SetLevel(log.InfoLevel)
|
||||
|
||||
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)
|
||||
@@ -34,6 +36,88 @@ func main() {
|
||||
}
|
||||
rb := ipp.NewResponse(0, 0)
|
||||
rb.UnMarshal(httpResponse.Body)
|
||||
fmt.Print(r)
|
||||
fmt.Print(rb)
|
||||
|
||||
fmt.Print("\n-------------\n")
|
||||
printFile("4-untitled")
|
||||
|
||||
}
|
||||
|
||||
func printFile(fname string) {
|
||||
|
||||
f, err := os.Open(fname)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to open file %v", fname)
|
||||
return
|
||||
}
|
||||
// fileContents, err := ioutil.ReadAll(f)
|
||||
// if err != nil {
|
||||
// log.Errorf("Failed to read file %v", fname)
|
||||
// return
|
||||
|
||||
// }
|
||||
|
||||
request := ipp.NewRequest(ipp.PrintJob, 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.NewNameWithoutLanguage("requesting-user-name", "chronos"))
|
||||
request.AddOperatonAttribute(ipp.NewNameWithoutLanguage("job-name", "foobar"))
|
||||
request.AddOperatonAttribute(ipp.NewMimeMediaType("document-format", "image/pwg-raster"))
|
||||
|
||||
//request.AddJobAttribute(ipp.NewNameWithoutLanguage("ColorModel", "Gray"))
|
||||
//request.AddJobAttribute(ipp.NewNameWithoutLanguage("cupsPrintQuality", "Normal"))
|
||||
//request.AddJobAttribute(ipp.NewNameWithoutLanguage("Duplex", "DuplexNoTumble"))
|
||||
//request.AddJobAttribute(ipp.NewNameWithoutLanguage("job-originating-host-name", "localhost"))
|
||||
//request.AddJobAttribute(ipp.NewURIValue("name string", value string)
|
||||
request.AddJobAttribute(ipp.NewKeyWord("media", "iso_a4_210x297mm"))
|
||||
//request.AddJobAttribute(ipp.NewKeyWord("multiple-document-handling", "separate-documents-collated-copies"))
|
||||
request.AddJobAttribute(ipp.NewKeyWord("output-bin", "face-down"))
|
||||
//request.AddJobAttribute(ipp.NewNameWithoutLanguage("PageSize", "A4"))
|
||||
request.AddJobAttribute(ipp.NewKeyWord("print-color-mode", "monochrome"))
|
||||
request.AddJobAttribute(ipp.NewSetOfResolution("printer-resolution", ipp.Resolution{CrossFeedResolution: 600, FeedResolution: 600, Unit: 3}))
|
||||
request.AddJobAttribute(ipp.NewKeyWord("sides", "two-sided-long-edge"))
|
||||
fmt.Print(request)
|
||||
r := request.Marshal()
|
||||
b := bytes.NewBuffer(r)
|
||||
|
||||
mr := io.MultiReader(b, f)
|
||||
httpResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", mr)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
return
|
||||
}
|
||||
fmt.Print("\n---response------\n")
|
||||
log.Printf("HTTP status: %v %v", httpResponse.StatusCode, httpResponse.Status)
|
||||
// resp, err := io.ReadAll(httpResponse.Body)
|
||||
// if err != nil {
|
||||
// log.Error("could not read response")
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("% x", resp)
|
||||
rb := ipp.NewResponse(0, 0)
|
||||
rb.UnMarshal(httpResponse.Body)
|
||||
fmt.Print(rb)
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
requesting-user-name:chronos (nameWithoutLanguagageValueTag)
|
||||
job-name:2 - Untitled (nameWithoutLanguagageValueTag)
|
||||
document-format : image/pwg-raster (mimeMediaTypeValueTag)
|
||||
document-format : application/octet-stream (mimeMediaTypeValueTag)
|
||||
PrinterAttributes
|
||||
JobAttributes
|
||||
ColorModel:Gray (nameWithoutLanguagageValueTag)
|
||||
cupsPrintQuality:Normal (nameWithoutLanguagageValueTag)
|
||||
Duplex:DuplexNoTumble (nameWithoutLanguagageValueTag)
|
||||
job-originating-host-name:localhost (nameWithoutLanguagageValueTag)
|
||||
job-uuid:urn:uuid:67a09d25-5df8-3026-6e9c-b55f7afee4ca (uriValueTag)
|
||||
media : iso_a4_210x297mm (keywordValueTag)
|
||||
multiple-document-handling : separate-documents-collated-copies (keywordValueTag)
|
||||
output-bin : face-down (keywordValueTag)
|
||||
PageSize:A4 (nameWithoutLanguagageValueTag)
|
||||
print-color-mode : monochrome (keywordValueTag)
|
||||
printer-resolution:[{600 600 3}] (resolutionValueTag)
|
||||
sides : two-sided-long-edge (keywordValueTag)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user