CUPS Bypass Interface

I have a server on which I have several serial printers configured as raw queues in cups. On each of them I installed interface scripts to perform some simple manipulations with the outputs and to handle IPC with an application that runs on the server, and he likes to apply directly to printers and write to them, which doesn’t work well with cups that think that It exclusively controls printer devices. Everything works there.

Enter another application on the server that, although it goes through the cups (after buffering through its own print queue manager), it seems to enter the printer emission codes into the files that it prints. In other words, the print created by this application is not just a stream of text characters, but contains binary control codes that the printer must interpret.

The problem I am facing is that the cups seem to bypass my interfaces when they get such files from this second application. I checked this by installing two almost identical print files. The first contains the simple text "Hello world!". followed by a newline; the second contains some escape codes for one of the printers, followed by "Hello world!" and a new line. Then I added the line "sleep 5" to my printer interface so that there was a noticeable delay in printing.

When I printed the first file using lp, nothing happened for five seconds, after which the printer came to life and wrote "Hello, world!". However, when I printed the second file using the same lp , it immediately printed "Hello, world!" without sleep. I also noted that I can use the -o raw option in lp to force the same behavior with the first file (immediately print it without a five second delay).

My guess is that the cups look at the actual data that is printed and try to determine its type, and when he sees the printer exit codes in the data, he decides that this is a raw print and bypasses the interface. This is not the behavior that I expected, since I put the printer as a “raw” queue in the first place and suggested that this means that the cups simply transmit everything that was sent to him through the interface; However, this is the behavior that I see.

My question is: Is there a way to send the option to cups (except for -o raw , which also bypasses the interface) by telling it not to detect the type of print data received and go and send it to the script interface? . Alternatively, is there a way to specify the format of the incoming data (for example, tell the watch that what it receives is “plain text”, although it contains escape codes), so that cups will not look at it and simply pass it to the interface?

+3
source share
1 answer

You have unloaded pages!

At first , you don't seem to know which raw print queue is in the CUPS language: the raw queue is one that is not related to ...

  • ... no script interface (a script with the same name as the queue itself, located in /etc/cups/interfaces/ ),

  • ... nor a PostScript printer description file (PPD file) with the same name as the queue itself with the additional suffix * .ppd located in /etc/cups/ppd/ ).

Since you are saying that you have installed the script interface for printer queues, by definition these are NOT raw queues!

To send jobs as raw (i.e., unfiltered) to non-raw CUPS queues, there is no other way than using -o raw on the lp command line. You can also use (alternatively) the option -o document-format=application/vnd.cups-raw ... but it has exactly the same meaning: it forces CUPS to use the same work processing and only 7 times as many keyboard keys for punching.

Both methods force CUPS to skip the step of automatically entering the incoming job file and pass it through the filter without filtering into the queue.

The automatic input step and its result can be observed in the log file /var/log/cups/error_log , looking for the Auto-typing keyword when your cupsd.conf has LogLevel debug enabled: the line indicating Request file type is ... tells you which MIME type of CUPS classifies your incoming job as.)

How to force CUPS to process incoming print data as text

Use -o document-format=text/plain on the lp command line.

How to configure "raw" CUPS queues

If you want to turn (any) an existing print queue into the original one, simply delete the associated PPD file ( /etc/cups/ppd/myprinter.ppd ) or its associated script interfaces ( /etc/cups/interfaces/myprinter ).

If you want to set the print queue to act as a source from the very beginning, just use printername and an internal URI, but do not specify any PPD or any script interface with it:

An example of a command to set a raw print queue:

  sudo lpadmin -p my_raw_printer -E -v socket://192.168.177.188:9100 

( -p - specify the name of the print queue, -E - enable the print queue from the beginning.)

Speculation: why the 2nd application can bypass your script interface

Without seeing your complete system setup and looking at the second application (the print of which seems to be different from your first) or without access to the debug level CUPS file error_log , you can only assume:

  • I assume that your 2nd application uses some tough print command, which implicitly uses the -o raw print command option.
+3
source

Source: https://habr.com/ru/post/1204524/


All Articles