Merge pull request 'Add flags to proxy and add license headers.' (#19) from add-flags-and-license-headers into master
Reviewed-on: #19
This commit was merged in pull request #19.
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -100,7 +102,7 @@ func printFile(fname string) {
|
|||||||
fmt.Print(rb)
|
fmt.Print(rb)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
requesting-user-name:chronos (nameWithoutLanguagageValueTag)
|
requesting-user-name:chronos (nameWithoutLanguagageValueTag)
|
||||||
job-name:2 - Untitled (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
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
type charsetAttribute struct {
|
type charsetAttribute struct {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
type KeyWord struct {
|
type KeyWord struct {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
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
|
//Package ipp provides functonality to handle ipp messages
|
||||||
//go:generate stringer -type jobState -type printerState
|
//go:generate stringer -type jobState -type printerState
|
||||||
package ipp
|
package ipp
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
type MimeMediaType struct {
|
type MimeMediaType struct {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import "io"
|
import "io"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import "encoding/binary"
|
import "encoding/binary"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import "io"
|
import "io"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package mdnsserver
|
package mdnsserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@@ -9,40 +12,40 @@ import (
|
|||||||
"github.com/holoplot/go-avahi"
|
"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()
|
conn, err := dbus.SystemBus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
a, err := avahi.ServerNew(conn)
|
a, err := avahi.ServerNew(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Avahi new failed: %v", err)
|
log.Fatalf("Failed to connect to avahi: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
eg, err := a.EntryGroupNew()
|
eg, err := a.EntryGroupNew()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("EntryGroupNew() failed: %v", err)
|
log.Fatalf("Failed to create entry group: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fqdn, err := a.GetHostNameFqdn()
|
fqdn, err := a.GetHostNameFqdn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("GetHostNameFqdn() failed: %v", err)
|
log.Fatalf("failed to get hostname: %v", err)
|
||||||
}
|
}
|
||||||
var txt [][]byte
|
var txt [][]byte
|
||||||
|
notestring := fmt.Sprintf("note=%v", location)
|
||||||
txt = append(txt, []byte("note=burken"))
|
txt = append(txt, []byte(notestring))
|
||||||
txt = append(txt, []byte("product=ChroBroPrint V1"))
|
txt = append(txt, []byte("product=ChroBroPrint V1"))
|
||||||
txt = append(txt, []byte("Color=T"))
|
txt = append(txt, []byte("Color=T"))
|
||||||
txt = append(txt, []byte("rp=ipp/print"))
|
txt = append(txt, []byte("rp=ipp/print"))
|
||||||
txt = append(txt, []byte("ty=ChroBroPrint"))
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("AddService() failed: %v", err)
|
log.Fatalf("Failed to add service to avahi: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = eg.Commit()
|
err = eg.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Commit() failed: %v", err)
|
log.Fatalf("Failed to commit avahi changes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "ippserver/packages/ipp"
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -13,7 +15,7 @@ func handleGetJobAttributes(r *ipp.Request, requestID uint32) (*ipp.Response, er
|
|||||||
request := ipp.NewRequest(ipp.GetJobAttributes, requestID)
|
request := ipp.NewRequest(ipp.GetJobAttributes, requestID)
|
||||||
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
|
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
|
||||||
request.AddOperatonAttribute(ipp.NewNaturalLanguage("attributes-natural-language", "en"))
|
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("job-id"))
|
||||||
request.AddOperatonAttribute(r.GetAttribute("requesting-user-name"))
|
request.AddOperatonAttribute(r.GetAttribute("requesting-user-name"))
|
||||||
request.AddOperatonAttribute(r.GetAttribute("requested-attributes"))
|
request.AddOperatonAttribute(r.GetAttribute("requested-attributes"))
|
||||||
@@ -23,7 +25,7 @@ func handleGetJobAttributes(r *ipp.Request, requestID uint32) (*ipp.Response, er
|
|||||||
downStreamRequest := request.Marshal()
|
downStreamRequest := request.Marshal()
|
||||||
b := bytes.NewBuffer(downStreamRequest)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -13,7 +15,7 @@ func handleGetJobs(r *ipp.Request, requestID uint32) (*ipp.Response, error) {
|
|||||||
request := ipp.NewRequest(ipp.GetJobs, requestID)
|
request := ipp.NewRequest(ipp.GetJobs, requestID)
|
||||||
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
|
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
|
||||||
request.AddOperatonAttribute(ipp.NewNaturalLanguage("attributes-natural-language", "en"))
|
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("requesting-user-name"))
|
||||||
request.AddOperatonAttribute(r.GetAttribute("requested-attributes"))
|
request.AddOperatonAttribute(r.GetAttribute("requested-attributes"))
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ func handleGetJobs(r *ipp.Request, requestID uint32) (*ipp.Response, error) {
|
|||||||
downStreamRequest := request.Marshal()
|
downStreamRequest := request.Marshal()
|
||||||
b := bytes.NewBuffer(downStreamRequest)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "ippserver/packages/ipp"
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -11,15 +13,15 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
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) {
|
func handlePrintJob(r *ipp.Request, byteStream io.Reader, requestID uint32) (*ipp.Response, error) {
|
||||||
|
|
||||||
// This request is what will be sent to the real printer
|
// This request is what will be sent to the real printer
|
||||||
request := ipp.NewRequest(ipp.PrintJob, requestID)
|
request := ipp.NewRequest(ipp.PrintJob, requestID)
|
||||||
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
|
request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8"))
|
||||||
request.AddOperatonAttribute(ipp.NewNaturalLanguage("attributes-natural-language", "en"))
|
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("requesting-user-name"))
|
||||||
request.AddOperatonAttribute(r.GetAttribute("job-name"))
|
request.AddOperatonAttribute(r.GetAttribute("job-name"))
|
||||||
request.AddOperatonAttribute(ipp.NewMimeMediaType("document-format", "image/pwg-raster"))
|
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)
|
b := bytes.NewBuffer(downStreamRequest)
|
||||||
|
|
||||||
mr := io.MultiReader(b, byteStream)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,62 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"ippserver/packages/ipp"
|
"ippserver/packages/ipp"
|
||||||
"ippserver/packages/mdnsserver"
|
"ippserver/packages/mdnsserver"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
loglevel string
|
loglevel string
|
||||||
location string
|
location string
|
||||||
|
port uint
|
||||||
|
printerURI string
|
||||||
|
printerName string
|
||||||
|
ippurl, httpurl *url.URL
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&loglevel, "loglevel", "info", "The wanted loglevel error/info/debug")
|
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() {
|
func main() {
|
||||||
|
var err error
|
||||||
|
flag.Parse()
|
||||||
customFormatter := new(log.TextFormatter)
|
customFormatter := new(log.TextFormatter)
|
||||||
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
|
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
|
||||||
log.SetFormatter(customFormatter)
|
log.SetFormatter(customFormatter)
|
||||||
customFormatter.FullTimestamp = true
|
customFormatter.FullTimestamp = true
|
||||||
log.SetLevel(log.InfoLevel)
|
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())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
go mdnsserver.Run(ctx)
|
go mdnsserver.Run(ctx, location, uint16(port), printerName)
|
||||||
|
|
||||||
http.HandleFunc("/ipp/print", handle)
|
http.HandleFunc("/ipp/print", handle)
|
||||||
|
|
||||||
log.Info("http server started on :1234")
|
log.Infof("http server starting on :%v", port)
|
||||||
err := http.ListenAndServe(":1234", nil)
|
err = http.ListenAndServe(fmt.Sprintf(":%v", port), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("ListenAndServe: " + err.Error())
|
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
|
package main
|
||||||
|
|
||||||
import "ippserver/packages/ipp"
|
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
|
package main
|
||||||
|
|
||||||
import "ippserver/packages/ipp"
|
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
|
package main
|
||||||
|
|
||||||
import "ippserver/packages/ipp"
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -18,7 +20,7 @@ func main() {
|
|||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
go mdnsserver.Run(ctx)
|
go mdnsserver.Run(ctx, "some location", 1234, "ChroBroPrint")
|
||||||
|
|
||||||
http.HandleFunc("/ipp/print", handle)
|
http.HandleFunc("/ipp/print", handle)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user