Add flags to proxy and add license headers.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import "ippserver/packages/ipp"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,7 +15,7 @@ func handleGetJobAttributes(r *ipp.Request, requestID uint32) (*ipp.Response, er
|
||||
request := ipp.NewRequest(ipp.GetJobAttributes, requestID)
|
||||
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", ippurl.String()))
|
||||
request.AddOperatonAttribute(r.GetAttribute("job-id"))
|
||||
request.AddOperatonAttribute(r.GetAttribute("requesting-user-name"))
|
||||
request.AddOperatonAttribute(r.GetAttribute("requested-attributes"))
|
||||
@@ -23,7 +25,7 @@ func handleGetJobAttributes(r *ipp.Request, requestID uint32) (*ipp.Response, er
|
||||
downStreamRequest := request.Marshal()
|
||||
b := bytes.NewBuffer(downStreamRequest)
|
||||
|
||||
downStreamResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", b)
|
||||
downStreamResponse, err := http.Post(httpurl.String(), "application/ipp", b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,7 +15,7 @@ func handleGetJobs(r *ipp.Request, requestID uint32) (*ipp.Response, error) {
|
||||
request := ipp.NewRequest(ipp.GetJobs, requestID)
|
||||
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", ippurl.String()))
|
||||
request.AddOperatonAttribute(r.GetAttribute("requesting-user-name"))
|
||||
request.AddOperatonAttribute(r.GetAttribute("requested-attributes"))
|
||||
|
||||
@@ -22,7 +24,7 @@ func handleGetJobs(r *ipp.Request, requestID uint32) (*ipp.Response, error) {
|
||||
downStreamRequest := request.Marshal()
|
||||
b := bytes.NewBuffer(downStreamRequest)
|
||||
|
||||
downStreamResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", b)
|
||||
downStreamResponse, err := http.Post(httpurl.String(), "application/ipp", b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import "ippserver/packages/ipp"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -11,15 +13,15 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const printerURI = "brn30055cb5e3ae.local:631/ipp/print"
|
||||
//const printerURI = "brn30055cb5e3ae.local:631/ipp/print"
|
||||
|
||||
func handlePrintJob(r *ipp.Request, byteStream io.Reader, requestID uint32) (*ipp.Response, error) {
|
||||
|
||||
// This request is what will be sent to the real printer
|
||||
request := ipp.NewRequest(ipp.PrintJob, requestID)
|
||||
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))
|
||||
request.AddOperatonAttribute(ipp.NewURIValue("printer-uri", ippurl.String()))
|
||||
request.AddOperatonAttribute(r.GetAttribute("requesting-user-name"))
|
||||
request.AddOperatonAttribute(r.GetAttribute("job-name"))
|
||||
request.AddOperatonAttribute(ipp.NewMimeMediaType("document-format", "image/pwg-raster"))
|
||||
@@ -35,7 +37,8 @@ func handlePrintJob(r *ipp.Request, byteStream io.Reader, requestID uint32) (*ip
|
||||
b := bytes.NewBuffer(downStreamRequest)
|
||||
|
||||
mr := io.MultiReader(b, byteStream)
|
||||
downStreamResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", mr)
|
||||
//downStreamResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", mr)
|
||||
downStreamResponse, err := http.Post(httpurl.String(), "application/ipp", mr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,40 +1,62 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"ippserver/packages/ipp"
|
||||
"ippserver/packages/mdnsserver"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
loglevel string
|
||||
location string
|
||||
loglevel string
|
||||
location string
|
||||
port uint
|
||||
printerURI string
|
||||
printerName string
|
||||
ippurl, httpurl *url.URL
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&loglevel, "loglevel", "info", "The wanted loglevel error/info/debug")
|
||||
flag.StringVar(&location, "location", "somewhere", "locaton of the printer as shown in mDNS")
|
||||
flag.UintVar(&port, "port", 1234, "tcp port")
|
||||
flag.StringVar(&printerURI, "printer", "", "URL to the real printer, typical ipp://printername.local:631/ipp/print")
|
||||
flag.StringVar(&printerName, "name", "ChroBroPrint", "Name of the printer advertised with mDNS")
|
||||
}
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
flag.Parse()
|
||||
customFormatter := new(log.TextFormatter)
|
||||
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
|
||||
log.SetFormatter(customFormatter)
|
||||
customFormatter.FullTimestamp = true
|
||||
log.SetLevel(log.InfoLevel)
|
||||
|
||||
ippurl, err = url.Parse(printerURI)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to parse printer URL %v", err.Error())
|
||||
return
|
||||
}
|
||||
httpurl, _ = url.Parse(printerURI)
|
||||
httpurl.Scheme = "http"
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go mdnsserver.Run(ctx)
|
||||
go mdnsserver.Run(ctx, location, uint16(port), printerName)
|
||||
|
||||
http.HandleFunc("/ipp/print", handle)
|
||||
|
||||
log.Info("http server started on :1234")
|
||||
err := http.ListenAndServe(":1234", nil)
|
||||
log.Infof("http server starting on :%v", port)
|
||||
err = http.ListenAndServe(fmt.Sprintf(":%v", port), nil)
|
||||
if err != nil {
|
||||
log.Fatal("ListenAndServe: " + err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user