From df8aa9c611cdfa72cc71f4d860501f8b37b33ffa Mon Sep 17 00:00:00 2001 From: Alexander Pevzner Date: Thu, 9 Nov 2023 16:31:50 +0300 Subject: [PATCH] Added get-all-printer-attrs to the [logging] section By default, during initialization ipp-usb requests only those IPP printer attributes that it needs by itself. If this option is enabled, it will request **all** printer attributes. Normally, it should affect only logging (as returned attributes are written to log). However, some enterprise-quality HP printers are so slow in returning all attributes, so it can cause initializatio timeouts, so by default this option is disabled. See also #32 for some details on initialization timeout when all printer attributes are requested. --- conf.go | 54 ++++++++++++++++++++++++++++------------------------ ipp-usb.8 | 13 ++++++++++++- ipp-usb.8.md | 11 +++++++++++ ipp-usb.conf | 11 +++++++++++ ipp.go | 36 ++++++++++++++++++++--------------- 5 files changed, 84 insertions(+), 41 deletions(-) diff --git a/conf.go b/conf.go index 76a9fcf..a6a1039 100644 --- a/conf.go +++ b/conf.go @@ -25,35 +25,37 @@ const ( // Configuration represents a program configuration type Configuration struct { - HTTPMinPort int // Starting port number for HTTP to bind to - HTTPMaxPort int // Ending port number for HTTP to bind to - DNSSdEnable bool // Enable DNS-SD advertising - LoopbackOnly bool // Use only loopback interface - IPV6Enable bool // Enable IPv6 advertising - ConfAuthUID []*AuthUIDRule // [auth uid], parsed - LogDevice LogLevel // Per-device LogLevel mask - LogMain LogLevel // Main log LogLevel mask - LogConsole LogLevel // Console LogLevel mask - LogMaxFileSize int64 // Maximum log file size - LogMaxBackupFiles uint // Count of files preserved during rotation - ColorConsole bool // Enable ANSI colors on console - Quirks QuirksSet // Device quirks + HTTPMinPort int // Starting port number for HTTP to bind to + HTTPMaxPort int // Ending port number for HTTP to bind to + DNSSdEnable bool // Enable DNS-SD advertising + LoopbackOnly bool // Use only loopback interface + IPV6Enable bool // Enable IPv6 advertising + ConfAuthUID []*AuthUIDRule // [auth uid], parsed + LogDevice LogLevel // Per-device LogLevel mask + LogMain LogLevel // Main log LogLevel mask + LogConsole LogLevel // Console LogLevel mask + LogMaxFileSize int64 // Maximum log file size + LogMaxBackupFiles uint // Count of files preserved during rotation + LogAllPrinterAttrs bool // Get *all* printer attrs, for logging + ColorConsole bool // Enable ANSI colors on console + Quirks QuirksSet // Device quirks } // Conf contains a global instance of program configuration var Conf = Configuration{ - HTTPMinPort: 60000, - HTTPMaxPort: 65535, - DNSSdEnable: true, - LoopbackOnly: true, - IPV6Enable: true, - ConfAuthUID: nil, - LogDevice: LogDebug, - LogMain: LogDebug, - LogConsole: LogDebug, - LogMaxFileSize: 256 * 1024, - LogMaxBackupFiles: 5, - ColorConsole: true, + HTTPMinPort: 60000, + HTTPMaxPort: 65535, + DNSSdEnable: true, + LoopbackOnly: true, + IPV6Enable: true, + ConfAuthUID: nil, + LogDevice: LogDebug, + LogMain: LogDebug, + LogConsole: LogDebug, + LogMaxFileSize: 256 * 1024, + LogMaxBackupFiles: 5, + LogAllPrinterAttrs: false, + ColorConsole: true, } // ConfLoad loads the program configuration @@ -147,6 +149,8 @@ func confLoadInternal(path string) error { err = rec.LoadSize(&Conf.LogMaxFileSize) case confMatchName(rec.Key, "max-backup-files"): err = rec.LoadUint(&Conf.LogMaxBackupFiles) + case confMatchName(rec.Key, "get-all-printer-attrs"): + err = rec.LoadBool(&Conf.LogAllPrinterAttrs) } } } diff --git a/ipp-usb.8 b/ipp-usb.8 index d85081a..ee9317d 100644 --- a/ipp-usb.8 +++ b/ipp-usb.8 @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "IPP\-USB" "8" "July 2023" "" "ipp-usb.8" +.TH "IPP\-USB" "8" "November 2023" "" "ipp-usb.8" .SH "NAME" \fBipp\-usb\fR \- Daemon for IPP over USB printer support .SH "DESCRIPTION" @@ -203,6 +203,17 @@ Logging parameters are all in the \fB[logging]\fR section: # Enable or disable ANSI colors on console console\-color = enable # enable | disable + + # ipp\-usb queries IPP printer attributes at the initialization time + # for its own purposes and writes received attributes to the log\. + # By default, only necessary attributes are requested from device\. + # + # If this parameter is set to true, all printer attributes will + # be requested\. Normally, it only affects the logging\. However, + # some enterprise\-level HP printers returns such huge amount of + # data and do it so slowly, so it can cause initialization timeout\. + # This is why this feature is not enabled by default + get\-all\-printer\-attrs = false # false | true .fi .IP "" 0 .SS "Quirks" diff --git a/ipp-usb.8.md b/ipp-usb.8.md index cfbeeb8..2f28141 100644 --- a/ipp-usb.8.md +++ b/ipp-usb.8.md @@ -254,6 +254,17 @@ Logging parameters are all in the `[logging]` section: # Enable or disable ANSI colors on console console-color = enable # enable | disable + # ipp-usb queries IPP printer attributes at the initialization time + # for its own purposes and writes received attributes to the log. + # By default, only necessary attributes are requested from device. + # + # If this parameter is set to true, all printer attributes will + # be requested. Normally, it only affects the logging. However, + # some enterprise-level HP printers returns such huge amount of + # data and do it so slowly, so it can cause initialization timeout. + # This is why this feature is not enabled by default + get-all-printer-attrs = false # false | true + ### Quirks Some devices, due to their firmware bugs, require special handling, diff --git a/ipp-usb.conf b/ipp-usb.conf index b2993fa..bf7be1b 100644 --- a/ipp-usb.conf +++ b/ipp-usb.conf @@ -83,4 +83,15 @@ # Enable or disable ANSI colors on console console-color = enable # enable | disable + # ipp-usb queries IPP printer attributes at the initialization time + # for its own purposes and writes received attributes to the log. + # By default, only necessary attributes are requested from device. + # + # If this parameter is set to true, all printer attributes will + # be requested. Normally, it only affects the logging. However, + # some enterprise-level HP printers returns such huge amount of + # data and do it so slowly, so it can cause initialization timeout. + # This is why this feature is not enabled by default + get-all-printer-attrs = false # false | true + # vim:ts=8:sw=2:et diff --git a/ipp.go b/ipp.go index c536572..101b704 100644 --- a/ipp.go +++ b/ipp.go @@ -118,21 +118,27 @@ func ippGetPrinterAttributes(log *LogMessage, c *http.Client, uri string) ( goipp.TagURI, goipp.String(uri))) rq := goipp.Attribute{Name: "requested-attributes"} - rq.Values.Add(goipp.TagKeyword, goipp.String("color-supported")) - rq.Values.Add(goipp.TagKeyword, goipp.String("document-format-supported")) - rq.Values.Add(goipp.TagKeyword, goipp.String("media-size-supported")) - rq.Values.Add(goipp.TagKeyword, goipp.String("mopria-certified")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-device-id")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-dns-sd-name")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-icons")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-info")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-kind")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-location")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-make-and-model")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-more-info")) - rq.Values.Add(goipp.TagKeyword, goipp.String("printer-uuid")) - rq.Values.Add(goipp.TagKeyword, goipp.String("sides-supported")) - rq.Values.Add(goipp.TagKeyword, goipp.String("urf-supported")) + + if Conf.LogAllPrinterAttrs { + rq.Values.Add(goipp.TagKeyword, goipp.String("all")) + } else { + rq.Values.Add(goipp.TagKeyword, goipp.String("color-supported")) + rq.Values.Add(goipp.TagKeyword, goipp.String("document-format-supported")) + rq.Values.Add(goipp.TagKeyword, goipp.String("media-size-supported")) + rq.Values.Add(goipp.TagKeyword, goipp.String("mopria-certified")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-device-id")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-dns-sd-name")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-icons")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-info")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-kind")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-location")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-make-and-model")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-more-info")) + rq.Values.Add(goipp.TagKeyword, goipp.String("printer-uuid")) + rq.Values.Add(goipp.TagKeyword, goipp.String("sides-supported")) + rq.Values.Add(goipp.TagKeyword, goipp.String("urf-supported")) + } + msg.Operation.Add(rq) log.Add(LogTraceIPP, '>', "IPP request:").