lprlib

package module
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 16 Imported by: 0

README

go-lprlib

Test

This repository contains an implementation of the LPR protocol (send & receive) in go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIP

func GetIP(hostname string) (*net.IPAddr, error)

GetIP Resolve the IP Address from the hostname

func GetStatus

func GetStatus(hostname string, port uint16, queue string, long bool, timeout time.Duration) (string, error)

GetStatus Reads the Status from the printer

func Send

func Send(file string, hostname string, port uint16, queue string, username string, timeout time.Duration) (err error)

Send is a convenience function to send the given file to the remote printer

func SetDebugLogger

func SetDebugLogger(logger Logger)

SetDebugLogger sets logger as debug logging function

func SetErrorLogger

func SetErrorLogger(logger Logger)

SetErrorLogger sets logger as error logging function

Types

type ConnectionStatus

type ConnectionStatus int16
const (
	// DaemonCommand means, that the LPR daemon wants to receive a Deamon command (see RFC-1179, chapter 5)
	DaemonCommand ConnectionStatus = 0

	// JobSubCommand means, that the LPR daemon wants to receive a job sub-command (see RFC-1179, chapter 6)
	JobSubCommand ConnectionStatus = 1

	// End end of request processing
	End ConnectionStatus = 4

	// Error Error
	Error ConnectionStatus = 0xff
)

type ConnectionType added in v0.3.0

type ConnectionType int
const (
	ConnectionTypePrintAnyWaitingJobs ConnectionType = 0
	ConnectionTypeReceivePrintJob     ConnectionType = 1
	ConnectionTypeSendQueueStateShort ConnectionType = 2
	ConnectionTypeSendQueueStateLong  ConnectionType = 3
	ConnectionTypeRemoveJobs          ConnectionType = 4
	ConnectionTypeUnknown             ConnectionType = 5
)

type ExternalIDCallbackFunc added in v0.3.0

type ExternalIDCallbackFunc func() uint64

type Logger

type Logger func(...interface{})

type LprConnection

type LprConnection struct {

	// Connection connection
	Connection net.Conn

	// Hostname Hostname
	Hostname string

	// Filename Filename
	Filename string

	// PrqName PRQ - Name
	PrqName string

	// UserIdentification User Identification
	UserIdentification string

	// JobName Job name
	JobName string

	// BufferSize the size of the buffer
	BufferSize int64

	// TitleText Title
	TitleText string

	// ClassName Name of class for banner pages
	ClassName string

	// Filesize Filesize
	Filesize uint64

	// Output output File
	Output *os.File

	// IntentingCount Indenting count
	IntentingCount int64

	// Status Status
	Status ConnectionStatus

	// PrintFileWithPr Print file with pr
	PrintFileWithPr string

	// SaveName The File name of the new file
	SaveName string

	// ExternalID describes a reference of a print job id
	ExternalID uint64
	// contains filtered or unexported fields
}

LprConnection Accepted connection

func (*LprConnection) Init

func (lpr *LprConnection) Init(socket net.Conn, bufferSize int64, daemon *LprDaemon)

Init is the constructor of LprConnection socket is the accepted connection bufferSize is per default 8192

func (*LprConnection) ReadCommand added in v0.3.0

func (lpr *LprConnection) ReadCommand() ([]byte, error)

ReadCommand reads from the socket until the newline character occurs, but only a maximum number of len(buffer) bytes. The command returned does not include the LF character.

func (*LprConnection) RunConnection

func (lpr *LprConnection) RunConnection()

RunConnection This method read the data from the client

type LprDaemon

type LprDaemon struct {

	// GetQueueState will be called if a client requests the queue state.
	// If not set, "Idle" will be returned.
	GetQueueState QueueState

	// InputFileSaveDir is the directory into which received files will be saved.
	// If empty, the default system temp directory will be used.
	// if nil set, a temp file will be used instead of the directory
	InputFileSaveDir string

	// Trace states if the LprDaemon should create a trace file for each connection.
	// The trace file will be saved into the InputFileSaveDir or system temp directory.
	Trace bool

	GetExternalID ExternalIDCallbackFunc
	// contains filtered or unexported fields
}

LprDaemon structure

func (*LprDaemon) Close

func (lpr *LprDaemon) Close()

Close Closes all LprConnections and the listener

func (*LprDaemon) FinishedConnections added in v0.2.0

func (lpr *LprDaemon) FinishedConnections() <-chan *LprConnection

FinishedConnections returns a channel containing the finished connections. The ConnectionStatus may be END or ERROR. Will also contain LPR Queue State requests (check with SaveName != "").

func (*LprDaemon) Init

func (lpr *LprDaemon) Init(port uint16, ipAddress string) error

Init is the constructor port ist the tcp port where the daemon should listen default 515 ipAddress of the daemon default own ip

func (*LprDaemon) Listen

func (lpr *LprDaemon) Listen()

Listen waits for a new connection and accept them

func (*LprDaemon) SetFallbackEncoding added in v0.2.0

func (lpr *LprDaemon) SetFallbackEncoding(encodingName string) error

SetFallbackEncoding sets the given encoding as fallback encoding. Will be used to decode any received non-utf8 string values like Filename, PrqName, UserIdentification, etc. Will not be applied to any received file contents. Defaults to windows-1252.

func (*LprDaemon) SetFileMask

func (lpr *LprDaemon) SetFileMask(fileMask os.FileMode)

SetFileMask can be used to set the file mask which should be applied to the data file which is written by new connections.

type LprError

type LprError struct {
	What string
}

LprError This errordomain contains some errors wich may occur when you work with LprSend or LprDaemon

func (*LprError) Error

func (e *LprError) Error() string

type LprSend

type LprSend struct {

	/**
	 * The max size of one transmit
	 */
	MaxSize uint64

	/**
	 * The configuration for the remote printer
	 */
	Config map[byte]string

	// Timeout is the duration after which each read / write
	// operation will fail.
	Timeout time.Duration
	// contains filtered or unexported fields
}

LprSend This struct includes all methods to read a LprSender It send files to the remote printer

func (*LprSend) Close

func (lpr *LprSend) Close() error

Close Close the connection to the remote printer

func (*LprSend) Init

func (lpr *LprSend) Init(hostname, filePath string, port uint16, queue string, username string, timeout time.Duration) error

Init This Methode initializes the LprSender If lpr.MaxSize isn't set yet then it is 16*1024 The port is per default 515

func (*LprSend) SendConfiguration

func (lpr *LprSend) SendConfiguration() error

SendConfiguration Sends the configuration to the remote printer

func (*LprSend) SendFile

func (lpr *LprSend) SendFile() error

SendFile Sends the file to the remote printer

type QueueState

type QueueState func(queue string, list string, long bool) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL