Jump to content

CUPS

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Ta bu shi da yu (talk | contribs) at 12:00, 1 January 2005 (Filter system: added info on the filtering process). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The Common Unix Printing System (CUPS) is modularised printing system for Unix-like operating systems. It consists of a Unix print spooler and scheduler, a filter system (which converts from a uniform rasterized data format to a printer output format) and a backend system that sends the data to the print device. CUPS uses the Internet Printing Protocol as the basis for managing print jobs and queues. CUPS also provides the traditional System V and Berkeley command line interfaces, along with limited support for the server message block protocol (SMB). The device drivers CUPS supplies are based on the PostScript Printer Description.

Overview

CUPS provides a standard API to allow print jobs to be sent to printers. The API sends the data to a scheduler which then sends jobs to a filter system that converts the print job into a format the printer will understand. The filter system then passes the data onto a backend—a special filter that sends print data to a device or network connection.

Scheduler

The CUPS scheduler implements Internet Printing Protocol (IPP) printing, which is a printing protocol that utilises the HTTP protocol to manage print jobs and print queues. The scheduler accepts HTTP/1.1 requests, and provides a web-based interface for managing print jobs, the configuration of the server and also for maintaining documentation about CUPS itself.

The scheduler has an authorization module which controls what IPP and HTTP messages can pass through the system. Once the IPP/HTTP packets are authorized they are sent to the client module, which listens for and processes incoming connections. The client module is also responsible for executing the external CGI programs as needed to support web-based printers, classes, and job status monitoring and administration. Once the client module has processed the requests, it sends them to the IPP module to process these requests further. This module does URI validation to prevent a client from sidestepping any access controls or authentication on the HTTP server.

The scheduler allows for classes of printers. This is a method of grouping printers together to allow applications to send jobs to the class, which then means the scheduler will pick the first available printer in the class and send the job to that printer. A jobs module then manages print jobs and sends them to the filter and backend processes so the jobs can be printed. it also monitors status messages from those filters and backends.

The scheduler has a configuration module that it uses to access CUPS configuration files. It parses configuration files an initiates data structures and the CUPS program state. The configuration module will stop the CUPS services while it processes the configuration files and then restarts the service when it has finished processing the files.

A logging module handles logging scheduler events for access, error, and page log files, whilst the main module handles timeouts and the dispatching of I/O requests for client connections; watches for SIGHUP and SIGCHLD signals and reloads the server configuration files as needed and handles child process errors and exits.

Other modules used by the scheduler are: the MIME module, which handles a Multipurpose Internet Mail Extensions (MIME) type and conversion database that is used in the filtering process of converting print data to a format that the the print device will understand; a PPD module that handles a list of Postscript Printer Description (PPD) files; a devices module that manages a list of devices that are available in the system; and a printers module that handles printers and PPDs within CUPS.

Filter system

MIME databases

After the print job has been given to the scheduler, it is then passed to the CUPS filter system. This processes the print data and coverts it to a format that the printer will understand. When the CUPS daemon starts, it loads to MIME databases: mime.types and mime.convs. mime.types defines the known file types that CUPS can accept data for, and mime.convs defines the program that processes that particular MIME type.

The mime.types file has the syntax:

mimetype      { [file-extensions] | [pattern-match] }

For example, to detect an HTML file, you could use:

text/html       html htm \
     printable(0,1024) + (string(0,"<HTML>") string(0,"<!DOCTYPE"))

The second line matches the file contents to a MIME type by determining that the first kilobyte of text in the file holds printable characters and that those characters include html markup. If it determines that this matches it marks the file as of the MIME type text/html.

The mime.convs file has the syntax:

source destination cost program

The source field is the MIME type that is determined by looking up the mime.types file, while the destination field determines what output is requested and determines what program should be used. This is also looked up in mime.types. The cost field helps determine between different sets of filters when converting a file. The last field, program determines what filter program to use to do the data conversion.

Some examples follow:

text/plain application/postscript 50 texttops
application/vnd.cups-postscript application/vnd.cups-raster 50 pstoraster
image/* application/vnd.cups-postscript 50 imagetops
image/* application/vnd.cups-raster 50 imagetoraster

Further information on these databases can be found at http://www.cups.org/sam.html#FILE_TYPING_FILTERING

Filtering process

The filtering process works by taking input data preformatted with six arguments: the name of the printer queue or print filter, the job ID of the print job, the user-name, the job-name, the number of copies to print, any print options, and the filename (though unnecessary if it is coming from standard input). It then determines the type of data that is being input and the filter to be used through the use of the MIME databases, for instance image data will be detected and processed through a particular filter and html data detected and processed through another filter. This data can then be either converted into PostScript data or directly into raster data. If it is converted into postscript data an addition filter is applied called a prefilter, which basically runs the PostScript data through another PostScript converter so that it can add printer specific options like selecting page ranges to print, setting n-up mode and other device specific things.

After the pre-filtering is done, the data is sent to directly to a CUPS backend (if using a PostScript printer), is passed to another filter (like Foo-matic by linuxprint.org), or is passed to Ghostscript, which coverts the postscript into an intermediary CUPS-raster format (the MIME type is application/vnd.cups-raster). The intermediary raster format is then passed onto a final filter which coverts the raster data to a printer specific format. The default filters that are included with CUPS are: raster to PCL; raster to ESC/P or ESC/P2 (an Epson printer language, now largely superceded by their new ESC/P-Raster format) and raster to Dymo (another printer company). However, there are several other alternatives that can be used with CUPS. Easy Software Printing (ESP) Solutions, the creators of CUPS, have released their own CUPS filters; Gimp-Print is a range of high-quality printer drivers for (mostly) inkjet printers; and Turbo-Print for Linux has another range of quality printer drivers for a wide range of printers.

Category:Open device driver