Compare commits
2 Commits
21cf29f651
...
61abe8dbd4
| Author | SHA1 | Date | |
|---|---|---|---|
| 61abe8dbd4 | |||
| 2d74da1c91 |
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -100,7 +102,7 @@ func printFile(fname string) {
|
||||
fmt.Print(rb)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
requesting-user-name:chronos (nameWithoutLanguagageValueTag)
|
||||
job-name:2 - Untitled (nameWithoutLanguagageValueTag)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
type charsetAttribute struct {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
type KeyWord struct {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//Package ipp provides functonality to handle ipp messages
|
||||
//go:generate stringer -type jobState -type printerState
|
||||
package ipp
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
type MimeMediaType struct {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import "io"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import "io"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package ipp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package mdnsserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
@@ -9,40 +12,40 @@ import (
|
||||
"github.com/holoplot/go-avahi"
|
||||
)
|
||||
|
||||
func Run(ctx context.Context) {
|
||||
func Run(ctx context.Context, location string, port uint16, name string) {
|
||||
conn, err := dbus.SystemBus()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
a, err := avahi.ServerNew(conn)
|
||||
if err != nil {
|
||||
log.Fatalf("Avahi new failed: %v", err)
|
||||
log.Fatalf("Failed to connect to avahi: %v", err)
|
||||
}
|
||||
|
||||
eg, err := a.EntryGroupNew()
|
||||
if err != nil {
|
||||
log.Fatalf("EntryGroupNew() failed: %v", err)
|
||||
log.Fatalf("Failed to create entry group: %v", err)
|
||||
}
|
||||
|
||||
fqdn, err := a.GetHostNameFqdn()
|
||||
if err != nil {
|
||||
log.Fatalf("GetHostNameFqdn() failed: %v", err)
|
||||
log.Fatalf("failed to get hostname: %v", err)
|
||||
}
|
||||
var txt [][]byte
|
||||
|
||||
txt = append(txt, []byte("note=burken"))
|
||||
notestring := fmt.Sprintf("note=%v", location)
|
||||
txt = append(txt, []byte(notestring))
|
||||
txt = append(txt, []byte("product=ChroBroPrint V1"))
|
||||
txt = append(txt, []byte("Color=T"))
|
||||
txt = append(txt, []byte("rp=ipp/print"))
|
||||
txt = append(txt, []byte("ty=ChroBroPrint"))
|
||||
err = eg.AddService(avahi.InterfaceUnspec, avahi.ProtoUnspec, 0, "ChroBroPrint", "_ipp._tcp", "local", fqdn, 1234, txt)
|
||||
err = eg.AddService(avahi.InterfaceUnspec, avahi.ProtoUnspec, 0, name, "_ipp._tcp", "local", fqdn, port, txt)
|
||||
if err != nil {
|
||||
log.Fatalf("AddService() failed: %v", err)
|
||||
log.Fatalf("Failed to add service to avahi: %v", err)
|
||||
}
|
||||
|
||||
err = eg.Commit()
|
||||
if err != nil {
|
||||
log.Fatalf("Commit() failed: %v", err)
|
||||
log.Fatalf("Failed to commit avahi changes: %v", err)
|
||||
}
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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 "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 "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 (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -18,7 +20,7 @@ func main() {
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go mdnsserver.Run(ctx)
|
||||
go mdnsserver.Run(ctx, "some location", 1234, "ChroBroPrint")
|
||||
|
||||
http.HandleFunc("/ipp/print", handle)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user