Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 21.4 Printer Spooling 793


The following is a sample HTTP header for a print request submitted to the
author ’s Xerox Phaser 8560 printer:

POST /ipp HTTP/1.1ˆM
Content-Length: 21931ˆM
Content-Type: application/ippˆM
Host: phaser8560:631ˆM
ˆM

TheContent-Lengthline specifies the size in bytes of the amount of data in the HTTP
message. This excludes the size of the HTTP header,but includes the size of the IPP
header.TheHostline specifies the host name and port number of the server to which
the message is being sent.
TheˆMat the end of the each line is the carriage return that precedes the line feed.
The line feed doesn’t show up as a printable character.Note that the last line of the
header is empty,except for the carriage return and line feed.
The start line in an HTTP response message contains a version string followed by a
numeric status code and a status message, terminated by a carriage return and a line
feed. Theremainder of the HTTP response message has the same format as the request
message: headers followed by a blank line and an optional entity body.
In response to a print request, the printer might send us the following message:

HTTP/1.1 200 OKˆM
Content-Type: application/ippˆM
Cache-Control: no-cache, no-store, must-revalidateˆM
Expires: THU, 26 OCT 1995 00:00:00 GMTˆM
Content-Length: 215ˆM
Server: Allegro-Software-RomPager/4.34ˆM
ˆM

As far as our print spooler is concerned, all we careabout in this message is the first
line: it tells us whether the request succeeded or failed using a numeric error code and a
short string. The remainder of the message contains additional information to control
caching by nodes that might sit in between the client and the server and to indicate the
softwareversion running on the server.

21.4 Printer Spooling


The programs that we develop in this chapter form the basis of a simple printer spooler.
Asimple user command sends a file to the printer spooler; the spooler saves it to disk,
queues the request, and ultimately sends the file to the printer.
All UNIX Systems provide at least one print spooling system. FreeBSD ships LPD,
the BSD print spooling system (seelpd( 8 )and Chapter 13 of Stevens[ 1990 ]). Linux and
Mac OS X include CUPS, the Common UNIX Printing System (seecupsd( 8 )). Solaris
ships with the standardSystem V printer spooler (seelp( 1 )andlpsched(1M)). In this
Free download pdf