Software: Apache/2.0.54 (Fedora). PHP/5.0.4 uname -a: Linux mina-info.me 2.6.17-1.2142_FC4smp #1 SMP Tue Jul 11 22:57:02 EDT 2006 i686 uid=48(apache) gid=48(apache) groups=48(apache) Safe-mode: OFF (not secure) /usr/share/doc/cups-1.1.23/ drwxr-xr-x |
Viewing file: Select action/file-type: ![]() CUPS Software Programmers ManualCUPS-SPM-1.1.23 Easy Software Products Copyright 1997-2005, All Rights Reserved Table of ContentsPreface 1 - Printing System Overview 2 - The CUPS API 3 - Writing Filters 4 - Writing Printer Drivers 5 - Writing Backends A - Software License Agreement
PrefaceThis software programmers manual provides software programming information for the Common UNIX Printing System ("CUPS") Version 1.1.23. System OverviewCUPS provides a portable printing layer for UNIX®-based operating systems. It has been developed by Easy Software Products to promote a standard printing solution for all UNIX vendors and users. CUPS provides the System V and Berkeley command-line interfaces. CUPS uses the Internet Printing Protocol ("IPP") as the basis for managing print jobs and queues. The Line Printer Daemon ("LPD") Server Message Block ("SMB"), and AppSocket (a.k.a. JetDirect) protocols are also supported with reduced functionality. CUPS adds network printer browsing and PostScript Printer Description ("PPD") based printing options to support real-world printing under UNIX. CUPS includes an image file RIP that supports printing of image files to non-PostScript printers. A customized version of GNU Ghostscript 7.05 for CUPS called ESP Ghostscript is available separately to support printing of PostScript files within the CUPS driver framework. Sample drivers for Dymo, EPSON, HP, and OKIDATA printers are included that use these filters. Drivers for thousands of printers are provided with our ESP Print Pro software, available at: http://www.easysw.com/printpro/ CUPS is licensed under the GNU General Public License and GNU Library General Public License. Please contact Easy Software Products for commercial support and "binary distribution" rights. Document OverviewThis software programmers manual is organized into the following sections:
Notation ConventionsVarious font and syntax conventions are used in this guide. Examples and their meanings and uses are explained below:
AbbreviationsThe following abbreviations are used throughout this manual:
Other References
1 - Printing System OverviewThis chapter provides an overview of how the Common UNIX Printing System works. The Printing ProblemFor years the printing problem has plagued UNIX. Unlike Microsoft® Windows® or Mac OS, UNIX has no standard interface or system in place for supporting printers. Among the solutions currently available, the Berkeley and System V printing systems are the most prevalent. These printing systems support line printers (text only) or PostScript printers (text and graphics), and with some coaxing they can be made to support a full range of printers and file formats. However, because each varient of the UNIX operating system uses a different printing system than the next developing printer drivers for a wide range of printers and operating systems is extremely difficult. That combined with the limited volume of customers for each UNIX varient has forced most printer vendors to give up supporting UNIX entirely. CUPS is designed to eliminate the printing problem. One common printing system can be used by all UNIX varients to support the printing needs of users. Printer vendors can use its modular filter interface to develop a single driver program that supports a wide range of file formats with little or no effort. Since CUPS provides both the System V and Berkeley printing commands, users (and applications) can reap the benefits of this new technology with no changes. The TechnologyCUPS is based upon an emerging Internet standard called the Internet Printing Protocol. IPP has been embraced by dozens of printer and printer server manufacturers and is supported by Microsoft Windows 2000. IPP defines a standard protocol for printing as well as managing print jobs and printer options like media size, resolution, and so forth. Like all IP-based protocols, IPP can be used locally or over the Internet to printers hundreds or thousands of miles away. Unlike other protocols, however, IPP also supports access control, authentication, and encryption, making it a much more capable and secure printing solution than older ones. IPP is layered on top of the Hyper-Text Transport Protocol ("HTTP") which is the basis of web servers on the Internet. This allows users to view documentation, check status information on a printer or server, and manage their printers, classes, and jobs using their web browser. CUPS provides a complete IPP/1.1 based printing system that provides Basic, Digest, and local certificate authentication and user, domain, or IP-based access control. TLS encryption will be available in future versions of CUPS. JobsEach file or set of files that is submitted for printing is called a job. Jobs are identified by a unique number starting at 1 and are assigned to a particular destination, usually a printer. Jobs can also have options associated with them such as media size, number of copies, and priority. ClassesCUPS supports collections of printers known as classes. Jobs sent to a class are forwarded to the first available printer in the class. FiltersFilters allow a user or application to print many types of files without extra effort. Print jobs sent to a CUPS server are filtered before sending them to a printer. Some filters convert job files to different formats that the printer can understand. Others perform page selection and ordering tasks. CUPS provides filters for printing many types of image files, HP-GL/2 files, PDF files, and text files. CUPS also supplies PostScript and image file Raster Image Processor ("RIP") filters that convert PostScript or image files into bitmaps that can be sent to a raster printer. BackendsBackends perform the most important task of all - they send the filtered print data to the printer. CUPS provides backends for printing over parallel, serial, and USB ports, and over the network via the IPP, JetDirect (AppSocket), and Line Printer Daemon ("LPD") protocols. Additional backends are available in network service packages such as the SMB backend included with the popular SAMBA software. Backends are also used to determine the available devices. On startup each backend is asked for a list of devices it supports, and any information that is available. This allows the parallel backend to tell CUPS that an EPSON Stylus Color 600 printer is attached to parallel port 1, for example. Printer DriversPrinter drivers in CUPS consist of one of more filters specific to a printer. CUPS includes sample printer drivers for Hewlett-Packard LaserJet and DeskJet printers and EPSON 9-pin, 24-pin, Stylus Color, and Stylus Photo printers. While these drivers do not generate optimal output for the different printer models, they do provide basic printing and demonstrate how you can write your own printer drivers and incorporate them into CUPS. NetworkingPrinters and classes on the local system are automatically shared with other systems on the network. This allows you to setup one system to print to a printer and use this system as a printer server or spool host for all of the others. Users may then select a local printer by name or a remote printer using "name@server". CUPS also provides implicit classes, which are collections of printers and/or classes with the same name. This allows you to setup multiple servers pointing to the same physical network printer, for example, so that you aren't relying on a single system for printing. Because this also works with printer classes, you can setup multiple servers and printers and never worry about a single point of failure unless all of the printers and servers go down! 2 - The CUPS APIThis chapter describes the CUPS Application Programmers Interface ("API"). The CUPS API LibraryThe CUPS library provides a whole collection of interfaces needed to support the internal needs of the CUPS software as well as the needs of applications, filters, printer drivers, and backends. Unlike the rest of CUPS, the CUPS API library is provided under the GNU Library General Public License. This means that you can use the CUPS API library in both proprietary and open-source programs. Programs that use the CUPS API library typically will include the #include <cups/cups.h> ... jobid = cupsPrintFile("myprinter", "filename.ps", "title", num_options, options); Use the cc -o program program.c -lcups ENTER Additional options and libraries may be required depending on the operating system and the location of the CUPS API library. Detecting the CUPS API Library in GNU AutoconfGNU autoconf is a popular configuration tool used by many programs. Add the following lines to your configure.in file to check for the CUPS API library in your configuration script: AC_CHECK_LIB(socket,socket, if test "$uname" != "IRIX"; then LIBS="-lsocket $LIBS" else echo "Not using -lsocket since you are running IRIX." fi) AC_CHECK_LIB(nsl,gethostbyaddr, if test "$uname" != "IRIX"; then LIBS="-lnsl $LIBS" else echo "Not using -lnsl since you are running IRIX." fi) AC_CHECK_LIB(cups,httpConnect) Printing ServicesThe CUPS API library provides some basic printing services for applications that need to print files. Include FilesThe include file used by all of these functions is #include <cups/cups.h> Printing a FileThe CUPS API provides two functions for printing files. The first is #include <cups/cups.h> ... int jobid; ... jobid = cupsPrintFile("name", "filename", "title", 0, NULL); The The return value is a unique ID number for the print job or 0 if there was an error. Printing Multiple FilesThe second printing function is #include <cups/cups.h> ... int jobid; int num_files; const char *files[100]; ... jobid = cupsPrintFiles("name", num_files, files, "title", 0, NULL); Instead of passing a filename string as with As with Cancelling JobsThe #include <cups/cups.h> ... int jobid; int status; ... status = cupsCancelJob("name", jobid); The
Getting the Available Printers and ClassesThe #include <cups/cups.h> ... int num_dests; cups_dest_t *dests; ... num_dests = cupsGetDests(&dests); Each destination is stored in a typedef struct /**** Destination ****/ { char *name, /* Printer or class name */ *instance; /* Local instance name or NULL */ int is_default; /* Is this printer the default? */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ } cups_dest_t; The destinations are sorted by name and instance for your
convenience. Once you have the list of available destinations, you can
lookup a specific destination using the #include <cups/cups.h> ... int num_dests; cups_dest_t *dests; cups_dest_t *mydest; ... mydest = cupsGetDest("name", "instance", num_dests, dests); The The Printing with OptionsAll of the previous printing examples have passed int cupsPrintFile(const char *name, const char *filename, const char *title, int num_options, cups_option_t *options); int cupsPrintFiles(const char *name, int num_files, const char **files, const char *title, int num_options, cups_option_t *options); The The simplest way of handling options is to use the #include <cups/cups.h> ... int jobid; int num_dests; cups_dest_t *dests; cups_dest_t *mydest; ... mydest = cupsGetDest("name", "instance", num_dests, dests); jobid = cupsPrintFile(mydest->name, "filename", "title", mydest->num_options, mydest->options); This effectively uses the options a user has previous selected without a lot of code. Setting Printer OptionsOptions can also be set by your program using the #include <cups/cups.h> ... int num_options; cups_option_t *options; ... num_options = 0; options = NULL; ... num_options = cupsAddOption("name", "value", num_options, &options); num_options = cupsAddOption("name", "value", num_options, &options); num_options = cupsAddOption("name", "value", num_options, &options); num_options = cupsAddOption("name", "value", num_options, &options); The Each call to Call #include <cups/cups.h> ... int num_options; cups_option_t *options; ... cupsFreeOptions(num_options, options); Getting ErrorsIf any of the CUPS API printing functions returns an error, the
reason for that error can be found by calling #include <cups/cups.h> ... int jobid; ... if (jobid == 0) puts(ippErrorString(cupsLastError())); Passwords and AuthenticationCUPS supports authentication of any request, including submission of print jobs. The default mechanism for getting the username and password is to use the login user and a password from the console. To support other types of applications, in particular Graphical User Interfaces ("GUIs"), the CUPS API provides functions to set the default username and to register a callback function that returns a password string. The The The following example shows a simple password callback that gets a username and password from the user: #include <cups/cups.h> const char * my_password_cb(const char *prompt) { char user[65]; puts(prompt); /* Get a username from the user */ printf("Username: "); if (fgets(user, sizeof(user), stdin) == NULL) return (NULL); /* Strip the newline from the string and set the user */ user[strlen(user) - 1] = '\0'; cupsSetUser(user); /* Use getpass() to ask for the password... */ return (getpass("Password: ")); } ... cupsSetPasswordCB(my_password_cb); Similarly, a GUI interface could display the prompt string in a
window with input fields for the username and password. The username
should probably default to the value of PPD ServicesCUPS includes functions to access and manipulate PostScript Printer Description ("PPD") files that are used with the printer drivers in CUPS. Each PPD file enumerates the available features provided by a printer, including conflict information for specific options (e.g. can't duplex output on envelopes.) Include FilesInclude the #include <cups/ppd.h> This header file is also included by the Getting a PPD File for a PrinterThe #include <cups/cups.h> ... const char *filename; filename = cupsGetPPD("name"); The The return value is a pointer to a filename in static storage; this
value is overwritten with each call to Loading a PPD FileThe #include <cups/ppd.h> ... ppd_file_t *ppd; ppd = ppdOpenFile("filename"); The The return value is a pointer to a structure describing the contents of the PPD file or NULL if the PPD file could not be read. Freeing PPD File InformationOnce you are done using a PPD file, call the #include <cups/ppd.h> ... ppd_file_t *ppd; ... ppdClose(ppd); The PPD File StructureEach PPD file contains a number of capability attributes, printer
options, and conflict definitions. The page size options also include
the physical margins for the printer and the minimum and maximum sizes
for the printer. All of this information is stored in the CapabilitiesEach PPD file contains a number of informational attributes that
describe the capabilities of the printer. These are provided in the
Options and GroupsPPD files support multiple options, which are stored in Each option in turn is associated with a group stored in the Groups can also have sub-groups; CUPS currently limits the depth of sub-groups to 1 level to reduce programming complexity. ConflictsPPD files support specification of conflict conditions between
different options. Conflicts are stored in Page SizesPPD files specify all of the available pages sizes and the physical
margins associated with them. These sizes are stored in #include <cups/ppd.h> ... ppd_file_t *ppd; ppd_size_t *size; float width; float length; ... size = ppdPageSize(ppd, "size"); width = ppdPageWidth(ppd, "size"); length = ppdPageLength(ppd, "size"); The typedef struct /**** Page Sizes ****/ { int marked; /* Page size selected? */ char name[41]; /* Media size option */ float width, /* Width of media in points */ length, /* Length of media in points */ left, /* Left printable margin in points */ bottom, /* Bottom printable margin in points */ right, /* Right printable margin in points */ top; /* Top printable margin in points */ } ppd_size_t; Custom Page SizesBesides the standard page sizes listed in a PPD file, some printers
support variable or custom page sizes. If To get the resulting media size, use a page size string of Custom.612x792 [8.5 inches wide, 11 inches long] Custom.1224x792 [17 inches wide, 11 inches long] Marking OptionsBefore marking any user-defined options, call the #include <cups/ppd.h> ... ppd_file_t *ppd; ... ppdMarkDefaults(ppd); Then call the #include <cups/ppd.h> ... ppd_file_t *ppd; int conflicts; ... conflicts = ppdMarkOption(ppd, "name", "value"); The CUPS also provides a convenience function for marking all options in
the #include <cups/cups.h> ... ppd_file_t *ppd; int num_options; cups_option_t *options; int conflicts; ... conflicts = cupsMarkOptions(ppd, num_options, options); The Checking for ConflictsThe Call the #include <cups/cups.h> ... ppd_file_t *ppd; int conflicts; ... conflicts = ppdConflicts(ppd); The return value is the number of conflicting options, or 0 if there are no conflicts. 3 - Writing FiltersThis chapter describes how to write a file filter for CUPS. OverviewFile filters are programs that convert from one or more MIME types to another type. Filters use a common command-line and environment interface that allows them to be joined as needed to print files to any type of printer. Security ConsiderationsFilters are normally run as a non-priviledged user, so the major security consideration is resource utilization - filters should not depend on unlimited amounts of memory and disk space. Users and GroupsThe default CUPS configuration runs filters as user "lp" and group "other". Temporary FilesTemporary files should be created in the directory specified by the
"TMPDIR" environment variable. The Sending Messages to the UserThe CUPS scheduler collects messages sent to the standard error file
by the filter. These messages are relayed to the user based upon the
scheduler The type of message is determined by an initial prefix sent on each line:
If the line of text does not begin with any of the above prefixes, it
is treated as a debug message. Text following the prefix is copied to
the Page AccountingPage accounting messages are used to inform the server when one or more pages are printed. Each line has the form: PAGE: page-number copy-count The page-number field is the current page number, starting at 1. The copy-count field specifies the number of copies of that page that was produced. Page account messages are added to the page_log file and
cause the Command-Line ArgumentsEvery filter accepts exactly 6 or 7 command-line arguments: printer job user title copies options [filename] printer - The name of the printer queue (normally this
is the name of the program being run)job - The numeric job ID for the job being printeduser - The string from the originating-user-name
attributetitle - The string from the job-name
attributecopies - The numeric value from the number-copies
attributeoptions - String representations of the job template
attributes, separated by spaces. Boolean attributes are provided as
"name" for true values and "noname" for false values. All other
attributes are provided as "name=value" for single-valued attributes
and "name=value1,value2,...,valueN" for set attributesfilename - The request fileThe filename argument is only provided to the first filter in the chain; all filters must be prepared to read the print file from the standard input if the filename argument is omitted. Copy GenerationThe copies argument specifies the number of copies to produce
of the input file. In general, you should only generate copies if the
filename argument is supplied. The only exception to this are
filters that produce device-independent PostScript output (without any
printer commands from the printer's PPD file), since the PostScript
filter Environment VariablesEvery filter receives a fixed set of environment variables that can be used by the filter:
Dissecting the HP-GL/2 FilterThe HP-GL/2 filter ( Initializing the FilterThe first task of any filter is to ensure that the correct number of command-line arguments are present: if (argc < 6 || argc > 7) { fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr); return (1); } After this you open the print file or read from the standard input as needed: FILE *fp; /* * If we have 7 arguments, print the file named on the command-line. * Otherwise, send stdin instead... */ if (argc == 6) fp = stdin; else { /* * Try to open the print file... */ if ((fp = fopen(argv[6], "rb")) == NULL) { perror("ERROR: unable to open print file - "); return (1); } } Once the print file has been opened, options can be processed using
the int num_options; cups_option_t *options; const char *val; /* * Process command-line options and write the prolog... */ options = NULL; num_options = cupsParseOptions(argv[5], 0, &options); if ((val = cupsGetOption("blackplot", num_options, options)) != NULL) shading = 0; if ((val = cupsGetOption("fitplot", num_options, options)) != NULL) FitPlot = 1; if ((val = cupsGetOption("penwidth", num_options, options)) != NULL) PenWidth = (float)atoi(val) * 0.001f; After the options have been processed, the filter writes PostScript code to the standard output based on the print file, closes the print file (as needed), and returns 0 to the scheduler. PostScript OutputFilters that produce PostScript output must generate output conforming to the Adobe Document Structuring Conventions, 3.0. In general this means the beginning of each file must begin with: %!PS-Adobe-3.0 %%BoundingBox: left bottom right top %%Pages: (atend) %%EndComments The left, bottom, right, and top values are integers in points from the lower-lefthand corner of the page. Pages must be surrounded by: %%Page: number number gsave ... grestore showpage And the end of each file must contain: %%Trailer %%Pages: number-pages %%EOF These comments allow the PostScript filter to correctly perform page accounting, copy generation, N-up printing, and so forth. 4 - Writing Printer DriversThis chapter discusses how to write a printer driver, which is a special filter program that converts CUPS raster data into the appropriate commands and data required for a printer. OverviewRaster printers utilitize PPD files that specify one or more device-specific filters that handle converting print files for the printer. The simplest raster printer drivers provide a single filter that converts CUPS raster data to the printer's native format. CUPS Raster DataCUPS raster data ( Each page of data begins with a page dictionary structure called
After the page dictionary comes the page data which is a full-resolution, uncompressed bitmap representing the page in the printer's output colorspace. Page AccountingPrinter drivers must handle all page accounting. This means they must send "PAGE:" messages to the standard error file for each page (and in many cases, copy) sent to the printer. Color ManagementPrinter drivers can implement their color management via the For example, the Device and Bitmap VariablesBesides the standard PostScript page device dictionary variables defined in the Adobe PostScript Level 3 reference manual, the CUPS filters support additional variables that are passed in the page device dictionary header for the page and in some cases control the type of raster data that is generated:
Bitmaps with a colorspace of CUPS_CSPACE_KCMYcm and more than 1 bit per color are transmitted to the raster driver in KCMY colorspace; the driver is responsible for producing the correct separation of normal and light cyan and magenta inks. Dissecting the HP-PCL DriverThe HP-PCL driver provided with CUPS ( PPD FilesPPD files play an important part of all raster printer drivers. Options defined in the PPD file contain PostScript commands that control the raster data that is sent to the printer driver. A typical CUPS printer driver will include *OpenUI *PageSize/Media Size: PickOne *OrderDependency: 10 AnySetup *PageSize *DefaultPageSize: Letter *PageSize Letter/US Letter: "<< /PageSize [612 792] /ImagingBBox null >> setpagedevice" *End *PageSize Legal/US Legal: "<< /PageSize [612 1008] /ImagingBBox null >> setpagedevice" *End *PageSize A4/A4: "<< /PageSize [595 842] /ImagingBBox null >> setpagedevice" *End *CloseUI: *PageSize The Every option must have a default value, specified using the Each option begins with the option name followed by the computer and human-readable values. The PostScript commands follow these inside double quotes. PostScript commands can be provided on a single line: *PageSize A4/A4: "<</PageSize[595 842]/ImagingBBox null>> setpagedevice" or broken down on separate lines using the *PageSize A4/A4: "<< /PageSize [595 842] /ImagingBBox null >> setpagedevice" *End The choice of the two formats is usually esthetic. However, each line in a PPD file must not exceed 255 characters, so if your PostScript commands are long you may need to break them up on separate lines. Reading Raster DataAs with any filter, your printer driver should handle raster data
from a filename specified on the command-line or from the standard
input. The int fd; /* File descriptor */ cups_raster_t *ras; /* Raster stream for printing */ /* * Check for valid arguments... */ if (argc < 6 || argc > 7) { /* * We don't have the correct number of arguments; write an error message * and return. */ fputs("ERROR: rastertopcl job-id user title copies options [file]\n", stderr); return (1); } /* * Open the page stream... */ if (argc == 7) { if ((fd = open(argv[6], O_RDONLY)) == -1) { perror("ERROR: Unable to open raster file - "); sleep(1); return (1); } } else fd = 0; ras = cupsRasterOpen(fd, CUPS_RASTER_READ); Once you have opened the raster stream you just need to read each page and print it: cups_raster_header_t header; int y; unsigned char data[8192]; while (cupsRasterReadHeader(ras, &header)) { ... initialize the printer ... for (y = header.cupsHeight; y > 0; y ++) { cupsRasterReadPixels(ras, data, header.cupsBytesPerLine); ... send raster line to printer ... } } After you have processed all pages, close the raster stream and return: cupsRasterClose(ras); return (0); 5 - Writing BackendsThis chapter describes how to write a backend for CUPS. Backends communicate directly with printers and allow printer drivers and filters to send data using any type of connection transparently. OverviewBackends are special filters that communicate with printers directly. They are treated slightly differently than filters, however, and have some unique requirements. Security ConsiderationsBackends are run as the root user, so special care must be taken to avoid potential security violations. In particular, remember that a backend will be able to manipulate disk files, devices, and other resources that potentially could damage a system or printer. Command-Line ArgumentsBesides the standard filter arguments, backends are also run with no arguments to get a list of available devices. This discovery process is described later in this chapter. Copy GenerationLike filters, backends should send multiple copies of the print file only if a filename is supplied on the command-line. Otherwise the backend should assume that the upstream filter has already added the necessary commands or data to produce the multiple copies. Page AccountingBackend filters generally do not do page accounting, however they should at a minimum produce a single page message for each copy that is produced when a filename is present on the command-line. This is because the user selected "raw" printing and no other accounting information is possible. Exclusive AccessBackends that talk to local character or block devices should open
the device file in exclusive mode ( RetriesAll backends must retry connections to the device. This includes backends that talk to local character or block devices, as the user may define more than one printer queue pointing at the same physical device. To prevent excess CPU utilitization, the backend should go to sleep for an amount of time between retries; the CUPS-supplied backends retry once every 30 seconds. Dissecting the Serial Port BackendThe serial port backend provides support for serial printers. Since it does everything a good backend needs to do, it provides an excellent example of what to do. Supporting Device DiscoveryAs previously noted, backends are special filter programs that talk to printer devices. Another task a backend must perform is to list the available devices it supports. The backend lists the available devices when no additioanl arguments are supplied on the command-line (i.e. just the command name...) The serial backend lists devices by looking at serial port files in the /dev directory, by consulting a hardware inventory (IRIX), and in some cases by trying to open the ports to see if they actually exist. Once it finds a serial port it writes a single line for each port to the standard output file. Each line looks like this: serial serial:/dev/ttyS0?baud=115200 "Unknown" "Serial Port 1" The first word "serial" is the device class; this identifies the class of device which can be used to categorize it in user interfaces. CUPS currently recognizes the following classes:
After the device class is the device URI, in this case "serial:/dev/ttyS0?baud=115200". This is the URI that should be used by the user to select this port. For serial ports, the "baud=115200" specifies the maximum baud rate supported by the port - the actual value will vary based on the speed the user selects for the printer. The last two strings are the model and description for the port. The "Unknown" string means that the printer model is unknown - some devices are able to provide a make and model such as "HP DeskJet" that allows users and software to choose an appropriate printer driver more easily. Both the model and description must be enclosed inside double quotes. Opening the Serial PortAs noted previously, all backends should open device files in
exclusive mode, and retry as needed until the port is available. The
serial port does this using a do { if ((fd = open(resource, O_WRONLY | O_NOCTTY | O_EXCL)) == -1) { if (errno == EBUSY) { fputs("INFO: Serial port busy; will retry in 30 seconds...\n", stderr); sleep(30); } else { perror("ERROR: Unable to open serial port device file"); return (1); } } } while (fd < 0); If the port is busy or in use by another process, the backend will go to sleep for 30 seconds and try again. If another error is detected a message is sent to the user and the backend aborts the print job until the problem can be corrected. Writing Data to the PortNetwork and character devices pose an interesting problem when writing data to the port - they may not be able to write all of the bytes in your buffer before returning. To work around this problem you must loop until all bytes have been written: while (nbytes > 0) { if ((wbytes = write(fd, bufptr, nbytes)) < 0) if (errno == ENOTTY) wbytes = write(fd, bufptr, nbytes); if (wbytes < 0) { perror("ERROR: Unable to send print file to printer"); break; } nbytes -= wbytes; bufptr += wbytes; } The check for the Finishing UpOnce you have sent the print file, return 0 if the file printed successfully or 1 if it did not. This will allow the scheduler to stop the print job if there is a device error, preserving the print job for later printing once the problem has been corrected. A - Software License AgreementCommon UNIX Printing System License AgreementCopyright 1997-2005 by Easy Software Products
IntroductionThe Common UNIX Printing SystemTM, ("CUPSTM"), is provided under the GNU General Public License ("GPL") and GNU Library General Public License ("LGPL"), Version 2, with exceptions for Apple operating systems and the OpenSSL toolkit. A copy of the exceptions and licenses follow this introduction. The GNU LGPL applies to the CUPS API library, located in the "cups" subdirectory of the CUPS source distribution and in the "cups" include directory and library files in the binary distributions. The GNU GPL applies to the remainder of the CUPS distribution, including the "pdftops" filter which is based upon Xpdf and the CUPS imaging library. For those not familiar with the GNU GPL, the license basically allows you to:
What this license does not allow you to do is make changes or add features to CUPS and then sell a binary distribution without source code. You must provide source for any new drivers, changes, or additions to the software, and all code must be provided under the GPL or LGPL as appropriate. The only exceptions to this are the portions of the CUPS software covered by the Apple operating system license exceptions outlined later in this license agreement. The GNU LGPL relaxes the "link-to" restriction, allowing you to develop applications that use the CUPS API library under other licenses and/or conditions as appropriate for your application. License ExceptionsIn addition, as the copyright holder of CUPS, Easy Software Products grants the following special exceptions:
No developer is required to provide these exceptions in a derived work. TrademarksEasy Software Products has trademarked the Common UNIX Printing System, CUPS, and CUPS logo. You may use these names and logos in any direct port or binary distribution of CUPS. Please contact Easy Software Products for written permission to use them in derivative products. Our intention is to protect the value of these trademarks and ensure that any derivative product meets the same high-quality standards as the original. Binary Distribution RightsEasy Software Products also sells rights to the CUPS source code under a binary distribution license for vendors that are unable to release source code for their drivers, additions, and modifications to CUPS under the GNU GPL and LGPL. For information please contact us at the address shown above. The Common UNIX Printing System provides a "pdftops" filter that is based on the Xpdf software. For binary distribution licensing of this software, please contact: Derek B. Noonburg SupportEasy Software Products sells software support for CUPS as well as a commercial printing product based on CUPS called ESP Print Pro. You can find out more at our web site: http://www.easysw.com/ GNU GENERAL PUBLIC LICENSEVersion 2, June 1991 Copyright 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. PreambleThe licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE
|
Member | Type | Description |
---|---|---|
name | char * | The name of the printer or class. |
instance | char * | The instance of the printer or class; NULL for the primary instance. |
is_default | int | 1 if the destination is set as the default, 0 otherwise. |
num_options | int | The number of options associated with this destination. |
options | cups_option_t * | The options associated with this destination. |
The CUPS job structure (cups_job_t
) contains information
on a specific job:
Member | Type | Description |
---|---|---|
id | int | The job ID for this job. |
dest | char * | The destination for this job (printer or class name). |
title | char * | The job-name for this job (title). |
user | char * | The job-originating-user-name for this job (username). |
format | char * | The document-format for this job (MIME type string). |
state | ipp_jstate | The current state of the job. |
size | int | The size of this job in kilobytes. |
priority | int | The priority of this job from 1 to 100 (50 is normal). |
completed_time | time_t | The time the job was completed, or 0 if not yet completed. |
creation_time | time_t | The time the job was queued. |
processing_time | time_t | The time the job started printing. |
The CUPS messages structure (cups_lang_t
) contains the
character set, locale name, and messages array:
Member | Type | Description |
---|---|---|
next | cups_lang_t * | Pointer to the next messages structure in memory. |
used | int | The number of active users of this messages structure. |
encoding | cups_encoding_t | The character encoding of the message strings. |
language | char [16] | The language/locale name. |
messages | char *[] | The array of message strings. |
The CUPS option structure (cups_option_t
) contains the
option name and string value:
Member | Type | Description |
---|---|---|
name | char * | The name of the option. |
value | char * | The string value of the option. |
The HTTP state structure (http_t
) contains the current
state of a HTTP request or response:
Member | Type | Description |
---|---|---|
fd | int | The socket for the HTTP connection. |
blocking | int | 1 if the HTTP functions should block, 0 if not. |
error | int | The last OS error that occurred on the socket. |
activity | time_t | The last time the HTTP connection was used. |
state | http_state_t | The current HTTP request/response state. |
status | int | The last HTTP status seen. |
version | http_version_t | The HTTP protocol version in use. |
keep_alive | http_keep_alive_t | Whether or not to use Keep-Alive |
hostaddr | struct sockaddr_in | The IPv4 address of the HTTP server. |
hostname | char [] | The hostname of the HTTP server. |
fields | char [][] | The string values of all HTTP request/response fields. |
data | char * | Current byte in data buffer. |
data_encoding | http_encoding_t | The transfer encoding for the request/response. |
data_remaining | int | The number of bytes remaining in the current request, response, or chunk. |
used | int | The number of bytes that are used in the buffer. |
buffer | char [] | The read/write buffer. |
auth_type | int | The type of authentication in use. |
md5_state | md5_state_t | The current MD5 digest state. |
nonce | char [] | The nonce value for Digest authentication. |
nonce_count | int | The nonce count value. |
tls | void * | A pointer to private encryption data. |
encryption | http_encryption_t | The current encryption mode. |
The IPP state structure (ipp_t
) contains the current
state of a IPP request or response:
Member | Type | Description |
---|---|---|
TODO
TODO
TODO
TODO
The raster page header (cups_raster_header_t
) consists
of the PostScript page device dictionary for the page:
Member | Type | Description |
---|---|---|
MediaClass | char[64] | The media class name |
MediaColor | char[64] | The media color name |
MediaType | char[64] | The media type name |
OutputType | char[64] | The output type name |
AdvanceDistance | unsigned | The distance to advance the media in points |
AdvanceMedia | cups_adv_t | When to advance the media |
Collate | cups_bool_t | Whether or not to produce collated copies |
CutMedia | cups_cut_t | When to cut the media |
Duplex | cups_bool_t | Whether or not to print on both sides of the paper |
HWResolution | unsigned[2] | The resolution of the page image in pixels per inch; the HWResolution[0] represents the horizontal resolution and HWResolution[1] represents the vertical resolution |
ImagingBoundingBox | unsigned[4] | The bounding box for the page in points; the elements represent the left, bottom, right, and top coordinates of the imaged area (if 0 then the whole page is imaged) |
InsertSheet | cups_bool_t | Whether or not to insert a sheet before this page |
Jog | cups_jog_t | When to jog copies of the page |
LeadingEdge | cups_edge_t | The leading edge of the page |
Margins | unsigned[2] | The lower-lefthand margin of the page in points |
ManualFeed | cups_bool_t | Whether or not to manually feed the page |
MediaPosition | unsigned | The input slot number to use |
MediaWeight | unsigned | The weight of the output media in grams/m2 |
MirrorPrint | cups_bool_t | Whether or not to mirror the print |
NegativePrint | cups_bool_t | Whether or not to invert the print |
NumCopies | unsigned | The number of copies to produce |
Orientation | cups_orient_t | The orientation of the page image |
OutputFaceUp | cups_bool_t | Whether or not to output the page face up |
PageSize | unsigned[2] | The width and height of the page in points |
Separations | cups_bool_t | Whether or not to output separations |
TraySwitch | cups_bool_t | Whether or not to automatically switch trays for the requested media size/type |
Tumble | cups_bool_t | Whether or not to rotate the back side of the page |
cupsWidth | unsigned | The width of the page image in pixels |
cupsHeight | unsigned | The height of the page image in pixels |
cupsMediaType | unsigned | The device-specific media type code |
cupsBitsPerColor | unsigned | The number of bits per color |
cupsBitsPerPixel | unsigned | The number of bits per pixel |
cupsBytesPerLine | unsigned | The number of bytes per line of image data |
cupsColorOrder | cups_order_t | The order of color values |
cupsColorSpace | cups_cspace_t | The type of color values |
cupsCompression | unsigned | The device-specific compression code |
cupsRowCount | unsigned | The device-specific row count |
cupsRowFeed | unsigned | The device-specific row feed |
cupsRowStep | unsigned | The device-specific row step |
This appendix provides a reference for all of the CUPS API functions.
int cupsAddDest(const char *name, const char *instance, int num_dests, cups_dest_t **dests);
Argument | Description |
---|---|
name | The name of the destination. |
instance | The instance of the destination, or NULL for the primary instance. |
num_dests | The number of destinations in the array. |
dest | A pointer to the destination array pointer. |
The new number of destinations in the array.
cupsAddDest()
adds the named destination to the
destination array if it does not already exist.
#include <cups/cups.h> int num_dests; cups_dest_t *dests; num_dests = cupsAddDests("foo", "bar", num_dests, &dests);
cupsFreeDests()
,
cupsGetDest()
,
cupsGetDests()
int cupsAddOption(const char *name, const char *value, int num_options, cups_option_t **options);
Argument | Description |
---|---|
name | The name of the option. |
value | The value of the option. |
num_options | Number of options currently in the array. |
options | Pointer to the options array. |
The new number of options.
cupsAddOption()
adds an option to the specified array.
#include <cups.h> ... /* Declare the options array */ int num_options; cups_option_t *options; /* Initialize the options array */ num_options = 0; options = (cups_option_t *)0; /* Add options using cupsAddOption() */ num_options = cupsAddOption("media", "letter", num_options, &options); num_options = cupsAddOption("resolution", "300dpi", num_options, &options);
cupsEncodeOptions()
,
cupsFreeOptions()
,
cupsGetOption()
,
cupsParseOptions()
int cupsCancelJob(const char *dest, int job);
Argument | Description |
---|---|
dest | Printer or class name |
job | Job ID |
1 on success, 0 on failure. On failure the error can be found by
calling cupsLastError()
.
cupsCancelJob()
cancels the specifies job.
#include <cups.h> cupsCancelJob("LaserJet", 1);
cupsLastError()
,
cupsPrintFile()
,
cupsPrintFiles()
int cupsDoAuthentication(http_t *http, const char *method, const char *resource);
Argument | Description |
---|---|
http | HTTP connection to server. |
method | HTTP method name ("GET", "POST", "PUT", etc.) |
resource | HTTP resource name. |
0 if the authentication string was successfully generated, -1 otherwise.
cupsDoAuthentication()
generates an authentication
string for the given method and request. It supports Basic, Digest, and
CUPS local certificate authentication methods and uses the current user
and password callback to collect authentication information as needed.
Applications using this function should set the
HTTP_FIELD_AUTHORIZATION
field to the authstring
value in the http_t
structure prior to issuing a new
request.
#include <cups.h> http_t *http; char resource[HTTP_MAX_URI]; http_status_t status; ... do { httpClearFields(http); httpSetField(http, HTTP_FIELD_AUTHORIZATION, http->authstring); if (httpGet(http, resource)) { if (httpReconnect(http)) { status = HTTP_ERROR; break; } continue; } while ((status = httpUpdate(http)) == HTTP_CONTINUE); if (status == HTTP_UNAUTHORIZED) { httpFlush(http); if (cupsDoAuthentication(http, "GET", resource)) break; httpReconnect(http); continue; } } while (status == HTTP_UNAUTHORIZED);
cupsDoAuthentication()
, cupsGetPassword()
,
cupsSetPasswordCB()
,
cupsSetUser()
, cupsUser()
ipp_t * cupsDoFileRequest(http_t *http, ipp_t *request, const char *resource, const char *filename);
Argument | Description |
---|---|
http | HTTP connection to server. |
request | IPP request data. |
resource | HTTP resource name for POST. |
filename | File to send with POST request (NULL
pointer if none.) |
IPP response data or NULL
if the request fails. On
failure the error can be found by calling
cupsLastError()
.
cupsDoFileRequest()
does a HTTP POST request and
provides the IPP request and optionally the contents of a file to the
IPP server. It also handles resubmitting the request and performing
password authentication as needed.
#include <cups.h> http_t *http; cups_lang_t *language; ipp_t *request; ipp_t *response; ... /* Get the default language */ language = cupsLangDefault(); /* Create a new IPP request */ request = ippNew(); request->request.op.operation_id = IPP_PRINT_FILE; request->request.op.request_id = 1; /* Add required attributes */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(language)); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language != NULL ? language->language : "C"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://hostname/resource"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); /* Do the request... */ response = cupsDoFileRequest(http, request, "/resource", "filename.txt");
cupsLangDefault()
,
cupsLangEncoding()
,
cupsUser()
, httpConnect()
, ippAddString()
,
ippNew()
ipp_t * cupsDoRequest(http_t *http, ipp_t *request, const char *resource);
Argument | Description |
---|---|
http | HTTP connection to server. |
request | IPP request data. |
resource | HTTP resource name for POST. |
IPP response data or NULL
if the request fails. On
failure the error can be found by calling
cupsLastError()
.
cupsDoRequest()
does a HTTP POST request and provides
the IPP request to the IPP server. It also handles resubmitting the
request and performing password authentication as needed.
#include <cups.h> http_t *http; cups_lang_t *language; ipp_t *request; ipp_t *response; ... /* Get the default language */ language = cupsLangDefault(); /* Create a new IPP request */ request = ippNew(); request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES; request->request.op.request_id = 1; /* Add required attributes */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(language)); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language != NULL ? language->language : "C"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://hostname/resource"); /* Do the request... */ response = cupsDoRequest(http, request, "/resource");
cupsLangDefault()
,
cupsLangEncoding()
,
cupsUser()
, httpConnect()
, ippAddString()
,
ippNew()
void cupsEncodeOptions(ipp_t *ipp, int num_options, cups_option_t *options);
Argument | Description |
---|---|
ipp | The IPP request. |
num_options | The number of options. |
options | The options. |
cupsEncodeOptions()
encodes all of the options in the
specified array as IPP attributes and adds them to the IPP request.
#include <cups/cups.h> ipp_t *ipp; int num_options; cups_option_t *options; cupsEncodeOptions(ipp, num_options, options);
cupsAddOption()
,
cupsParseOptions()
, ippNew()
http_encryption_t cupsEncryption(void);
The current encryption setting.
cupsEncryption()
returns the current encryption setting
for IPP requests such as printing.
#include <cups/cups.h> http_t *http; printf("The current encryption setting is %d.\n", cupsEncryption()); http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
cupsServer()
,
httpConnectEncrypt()
,
ippPort()
void cupsFreeDests(int num_dests, cups_dest_t *dests);
Argument | Description |
---|---|
num_dests | The number of destinations in the array. |
dests | The destination array. |
cupsFreeDests()
frees a destination array that was
created using cupsGetDests()
.
#include <cups/cups.h> int num_dests; cups_dest_t *dests; cups_dest_t *dest; num_dests = cupsGetDests(&dests); dest = cupsGetDest(NULL, NULL, num_dests, dests); if (dest) printf("The default destination is %s\n", dest->name); else puts("No default destination."); cupsFreeDests(num_dests, dests);
void cupsFreeJobs(int num_jobs, cups_job_t *jobs);
Argument | Description |
---|---|
num_jobs | The number of jobs. |
jobs | The job array. |
cupsFreeJobs()
frees an array of print jobs created by
the cupsGetJobs()
function.
#include <cups/cups.h> int i; int num_jobs; cups_job_t *jobs; num_jobs = cupsGetJobs(&jobs, NULL, 0, 0); printf("%d active job(s):\n", num_jobs); for (i = 0; i < num_jobs; i ++) printf("%-16.16s %-6d %-12.12s %s (%s)\n", jobs[i].dest, jobs[i].id, jobs[i].user, jobs[i].title, jobs[i].state != IPP_JOB_PENDING ? "printing" : "pending"); cupsFreeJobs(num_jobs, jobs);
void cupsFreeOptions(int num_options, cups_option_t *options);
Argument | Description |
---|---|
num_options | Number of options in array. |
options | Pointer to options array. |
cupsFreeOptions()
frees all memory associated with the
option array specified.
#include <cups/cups.h> int num_options; cups_option_t *options; ... cupsFreeOptions(num_options, options);
cupsAddOption()
,
cupsEncodeOptions()
,
cupsGetOption()
,
cupsMarkOptions()
,
cupsParseOptions()
int cupsGetClasses(char ***classes);
Argument | Description |
---|---|
classes | Pointer to character pointer array. |
The number of printer classes available.
cupsGetClasses()
gets a list of the available printer
classes. The returned array should be freed using the free()
when it is no longer needed.
#include <cups/cups.h> int i; int num_classes; char **classes; ... num_classes = cupsGetClasses(&classes); ... if (num_classes > 0) { for (i = 0; i < num_classes; i ++) free(classes[i]); free(classes); }
cupsGetDefault()
,
cupsGetPrinters()
const char * cupsGetDefault(void);
A pointer to the default destination.
cupsGetDefault()
gets the default destination printer or
class. The default destination is stored in a static string and will be
overwritten (usually with the same value) after each call.
#include <cups/cups.h> printf("The default destination is %s\n", cupsGetDefault());
cupsGetClasses()
,
cupsGetPrinters()
cups_dest_t * cupsGetDest(const char *name, const char *instance, int num_dests, cups_dest_t *dests);
Argument | Description |
---|---|
name | The name of the destination, or NULL for the default destination. |
instance | The instance of the destination, or NULL for the primary instance. |
num_dests | The number of destinations. |
dests | The destination array. |
A pointer to the specified destination, or NULL if none exists.
cupsGetDest()
finds the specified destination in the
array of destinations created by the cupsGetDests()
function.
#include <cups/cups.h> int num_dests; cups_dest_t *dests; cups_dest_t *dest; num_dests = cupsGetDests(&dests); dest = cupsGetDest(NULL, NULL, num_dests, dests); if (dest) printf("The default destination is %s\n", dest->name); else puts("No default destination."); cupsFreeDests(num_dests, dests);
int cupsGetDests(cups_dest_t **dests);
Argument | Description |
---|---|
dests | A pointer to a destination array pointer. |
The number of available destinations.
cupsGetDests()
creates an array of available
destinations that the user can print to. The array should be freed
using the cupsFreeDests()
function.
#include <cups/cups.h> int num_dests; cups_dest_t *dests; cups_dest_t *dest; num_dests = cupsGetDests(&dests); dest = cupsGetDest(NULL, NULL, num_dests, dests); if (dest) printf("The default destination is %s\n", dest->name); else puts("No default destination."); cupsFreeDests(num_dests, dests);
cupsFreeDests()
,
cupsGetDest()
,
cupsGetJobs()
http_status_t cupsGetFd(http_t *http, const char *resource, int fd);
Argument | Description |
---|---|
http | The HTTP connection to the server. |
resource | The resource name on the server. |
fd | The file descriptor to write to. |
The HTTP status code associated with the request.
cupsGetFd()
gets a file from the given HTTP server and
writes it to the specified file descriptor, performing any
authentication or encryption as required.
#include <cups/cups.h> http_t *http; int fd; char filename[1024]; http_status_t status; ... http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); fd = cupsTempFd(filename, sizeof(filename)); status = cupsGetFd(http, "/admin/cupsd.conf", fd); ... close(fd); unlink(filename); httpClose(http);
cupsGetFile()
,
cupsPutFd()
, cupsPutFile()
http_status_t cupsGetFile(http_t *http, const char *resource, const char *filename);
Argument | Description |
---|---|
http | The HTTP connection to the server. |
resource | The resource name on the server. |
filename | The filename to write to. |
The HTTP status code associated with the request.
cupsGetFile()
gets a file from the given HTTP server and
writes it to the specified filename, performing any authentication or
encryption as required.
#include <cups/cups.h> http_t *http; char filename[1024]; http_status_t status; ... http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); cupsTempFile(filename, sizeof(filename)); status = cupsGetFile(http, "/admin/cupsd.conf", filename); ... unlink(filename); httpClose(http);
cupsGetFd()
,
cupsPutFd()
, cupsPutFile()
int cupsGetJobs(cups_job_t **jobs, const char *dest, int myjobs, int completed);
Argument | Description |
---|---|
jobs | A pointer to the job array pointer. |
dest | The destination name, or NULL if jobs for all destinations are requested. |
myjobs | 1 if only those jobs submitted by the current
cupsUser() should be returned, 0 for jobs submitted by all users. |
completed | 1 if only completed jobs should be returned, 0 if only pending/processing jobs should be returned. |
The number of jobs.
cupsGetJobs()
creates an array of print jobs based on
the arguments supplied in the function call. The returned array should
be freed using the cupsFreeJobs()
function.
#include <cups/cups.h> int i; int num_jobs; cups_job_t *jobs; num_jobs = cupsGetJobs(&jobs, NULL, 0, 0); printf("%d active job(s):\n", num_jobs); for (i = 0; i < num_jobs; i ++) printf("%-16.16s %-6d %-12.12s %s (%s)\n", jobs[i].dest, jobs[i].id, jobs[i].user, jobs[i].title, jobs[i].state != IPP_JOB_PENDING ? "printing" : "pending"); cupsFreeJobs(num_jobs, jobs);
cupsFreeJobs()
,
cupsGetDests()
const char * cupsGetOption(const char *name, int num_options, cups_option_t *options);
Argument | Description |
---|---|
name | The name of the option. |
num_options | The number of options in the array. |
options | The options array. |
A pointer to the option values or NULL
if the option is
not defined.
cupsGetOption()
returns the first occurrence of the
named option. If the option is not included in the options array then a
NULL
pointer is returned.
#include <cups/cups.h> int num_options; cups_option_t *options; const char *media; ... media = cupsGetOption("media", num_options, options);
cupsAddOption()
,
cupsEncodeOptions()
,
cupsFreeOptions()
,
cupsMarkOptions()
,
cupsParseOptions()
const char * cupsGetPassword(const char *prompt);
Argument | Description |
---|---|
prompt | The prompt to display to the user. |
A pointer to the password that was entered or NULL
if no
password was entered.
cupsGetPassword()
displays the prompt string and asks
the user for a password. The password text is not echoed to the user.
#include <cups/cups.h> char *password; ... password = cupsGetPassword("Please enter a password:");
cupsDoAuthentication()
, cupsServer()
,
cupsSetPasswordCB()
,
cupsSetServer()
, cupsSetUser()
, cupsUser()
const char * cupsGetPPD(const char *printer);
Argument | Description |
---|---|
printer | The name of the printer. |
The name of a temporary file containing the PPD file or NULL
if the printer cannot be located or does not have a PPD file.
cupsGetPPD()
gets a copy of the PPD file for the named
printer. The printer name can be of the form "printer" or
"printer@hostname".
You should remove (unlink) the PPD file after you are done using it.
The filename is stored in a static buffer and will be overwritten with
each call to cupsGetPPD()
.
#include <cups/cups.h> char *ppd; ... ppd = cupsGetPPD("printer@hostname"); ... unlink(ppd);
int cupsGetPrinters(char ***printers);
Argument | Description |
---|---|
printers | Pointer to character pointer array. |
The number of printer printers available.
cupsGetPrinters()
gets a list of the available printers.
The returned array should be freed using the free()
when
it is no longer needed.
#include <cups/cups.h> int i; int num_printers; char **printers; ... num_printers = cupsGetPrinters(&printers); ... if (num_printers > 0) { for (i = 0; i < num_printers; i ++) free(printers[i]); free(printers); }
cupsGetClasses()
cupsGetDefault()
const char * cupsLangDefault(void);
A pointer to the default language structure.
cupsLangDefault()
returns a language structure for the
default language. The default language is defined by the LANG
environment variable. If the specified language cannot be located then
the POSIX (English) locale is used.
Call cupsLangFree()
to free any memory associated with
the language structure when you are done.
#include <cups/language.h> cups_lang_t *language; ... language = cupsLangDefault(); ... cupsLangFree(language);
cupsLangEncoding()
,
cupsLangFlush()
,
cupsLangFree()
, cupsLangGet()
, cupsLangString()
char * cupsLangEncoding(cups_lang_t *language);
Argument | Description |
---|---|
language | The language structure. |
A pointer to the encoding string.
cupsLangEncoding()
returns the language encoding used
for the specified language, e.g. "iso-8859-1", "utf-8", etc.
#include <cups/language.h> cups_lang_t *language; char *encoding; ... language = cupsLangDefault(); encoding = cupsLangEncoding(language); ... cupsLangFree(language);
cupsLangDefault()
,
cupsLangFlush()
,
cupsLangFree()
, cupsLangGet()
, cupsLangString()
void cupsLangFlush(void);
cupsLangFlush()
frees all language structures that have
been allocated.
#include <cups/language.h> ... cupsLangFlush();
cupsLangDefault()
,
cupsLangEncoding()
,
cupsLangFree()
, cupsLangGet()
, cupsLangString()
void cupsLangFree(cups_lang_t *language);
Argument | Description |
---|---|
language | The language structure to free. |
cupsLangFree()
frees the specified language structure.
#include <cups/language.h> cups_lang_t *language; ... cupsLangFree(language);
cupsLangDefault()
,
cupsLangEncoding()
,
cupsLangFlush()
, cupsLangGet()
, cupsLangString()
cups_lang_t * cupsLangGet(const char *name);
Argument | Description |
---|---|
name | The name of the locale. |
A pointer to a language structure.
cupsLangGet()
returns a language structure for the
specified locale. If the locale is not defined then the POSIX (English)
locale is substituted.
#include <cups/language.h> cups_lang_t *language; ... language = cupsLangGet("fr"); ... cupsLangFree(language);
cupsLangDefault()
,
cupsLangEncoding()
,
cupsLangFlush()
, cupsLangFree()
, cupsLangString()
char * cupsLangString(cups_lang_t *language, int message);
Argument | Description |
---|---|
language | The language to query. |
message | The message number. |
A pointer to the message string or NULL
if the message
is not defined.
cupsLangString()
returns a pointer to the specified
message string in the specified language.
#include <cups/language.h> cups_lang_t *language; char *s; ... language = cupsLangGet("fr"); s = cupsLangString(language, CUPS_MSG_YES); ... cupsLangFree(language);
cupsLangDefault()
,
cupsLangEncoding()
,
cupsLangFlush()
, cupsLangFree()
, cupsLangGet()
ipp_status_t cupsLastError(void);
An enumeration containing the last IPP error.
cupsLastError()
returns the last IPP error that
occurred. If no error occurred then it will return IPP_OK
or IPP_OK_CONFLICT
.
#include <cups/cups.h> ipp_status_t status; ... status = cupsLastError();
cupsCancelJob()
,
cupsPrintFile()
int cupsMarkOptions(ppd_file_t *ppd, int num_options, cups_option_t *options);
Argument | Description |
---|---|
ppd | The PPD file to mark. |
num_options | The number of options in the options array. |
options | A pointer to the options array. |
The number of conflicts found.
cupsMarkOptions()
marks options in the PPD file. It also
handles mapping of IPP option names and values to PPD option names.
#include <cups/cups.h> int num_options; cups_option_t *options; ppd_file_t *ppd; ... cupsMarkOptions(ppd, num_options, options);
cupsAddOption()
,
cupsFreeOptions()
,
cupsGetOption()
,
cupsParseOptions()
int cupsParseOptions(const char *arg, int num_options, cups_option_t **options);
Argument | Description |
---|---|
arg | The string containing one or more options. |
num_options | The number of options in the options array. |
options | A pointer to the options array pointer. |
The new number of options in the array.
cupsParseOptions()
parses the specifies string for one
or more options of the form "name=value", "name", or "noname". It can
be called multiple times to combine the options from several strings.
#include <cups/cups.h> int num_options; cups_option_t *options; ... num_options = 0; options = (cups_option_t *)0; num_options = cupsParseOptions(argv[5], num_options, &options);
cupsAddOption()
,
cupsFreeOptions()
,
cupsGetOption()
,
cupsMarkOptions()
int cupsPrintFile(const char *printer, const char *filename, const char *title, int num_options, cups_option_t *options);
Argument | Description |
---|---|
printer | The printer or class to print to. |
filename | The file to print. |
title | The job title. |
num_options | The number of options in the options array. |
options | A pointer to the options array. |
The new job ID number or 0 on error.
cupsPrintFile()
sends a file to the specified printer or
class for printing. If the job cannot be printed the error code can be
found by calling cupsLastError()
.
#include <cups/cups.h> int num_options; cups_option_t *options; int jobid; ... jobid = cupsPrintFile("printer@hostname", "filename.ps", "Job Title", num_options, options);
cupsCancelJob()
,
cupsLastError()
,
cupsPrintFiles()
int cupsPrintFiles(const char *printer, int num_files, const char **files, const char *title, int num_options, cups_option_t *options);
Argument | Description |
---|---|
printer | The printer or class to print to. |
num_files | The number of files to print. |
files | The files to print. |
title | The job title. |
num_options | The number of options in the options array. |
options | A pointer to the options array. |
The new job ID number or 0 on error.
cupsPrintFiles()
sends multiple files to the specified
printer or class for printing. If the job cannot be printed the error
code can be found by calling cupsLastError()
.
#include <cups/cups.h> int num_files; const char *files[100]; int num_options; cups_option_t *options; int jobid; ... jobid = cupsPrintFiles("printer@hostname", num_files, files, "Job Title", num_options, options);
cupsCancelJob()
,
cupsLastError()
,
cupsPrintFile()
http_status_t cupsPutFd(http_t *http, const char *resource, int fd);
Argument | Description |
---|---|
http | The HTTP connection to the server. |
resource | The resource name on the server. |
fd | The file descriptor to read from. |
The HTTP status code associated with the request.
cupsPutFd()
puts a file to the given HTTP server,
reading it from the specified file descriptor and performing any
authentication or encryption as required.
#include <cups/cups.h> http_t *http; int fd; http_status_t status; ... http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); status = cupsPutFd(http, "/admin/cupsd.conf", fd); httpClose(http);
cupsGetFd()
,
cupsGetFile()
,
cupsPutFile()
http_status_t cupsPutFile(http_t *http, const char *resource, const char *filename);
Argument | Description |
---|---|
http | The HTTP connection to the server. |
resource | The resource name on the server. |
filename | The filename to read from. |
The HTTP status code associated with the request.
cupsPutFile()
puts a file on the given HTTP server,
reading it from the specified filename and performing any
authentication or encryption as required.
#include <cups/cups.h> http_t *http; char filename[1024]; http_status_t status; ... http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); status = cupsPutFile(http, "/admin/cupsd.conf", filename); httpClose(http);
cupsGetFd()
,
cupsGetFile()
, cupsPutFd()
void cupsRasterClose(cups_raster_t *ras);
Argument | Description |
---|---|
ras | The raster stream to close. |
cupsRasterClose()
closes the specified raster stream.
#include <cups/raster.h> cups_raster_t *ras; ... cupsRasterClose(ras);
cupsRasterOpen()
,
cupsRasterReadHeader()
,
cupsRasterReadPixels()
,
cupsRasterWriteHeader()
,
cupsRasterWritePixels()
cups_raster_t * cupsRasterOpen(int fd, cups_mode_t mode);
Argument | Description |
---|---|
fd | The file descriptor to use. |
mode | The mode to use; CUPS_RASTER_READ or
CUPS_RASTER_WRITE . |
A pointer to a raster stream or NULL
if there was an
error.
cupsRasterOpen()
opens a raster stream for reading or
writing.
#include <cups/raster.h> cups_raster_t *ras; ... ras = cupsRasterOpen(0, CUPS_RASTER_READ);
cupsRasterClose()
,
cupsRasterReadHeader()
,
cupsRasterReadPixels()
,
cupsRasterWriteHeader()
,
cupsRasterWritePixels()
unsigned cupsRasterReadHeader(cups_raster_t *ras, cups_page_header_t *header);
Argument | Description |
---|---|
ras | The raster stream to read from. |
header | A pointer to a page header structure to read into. |
1 on success, 0 on EOF or error.
cupsRasterReadHeader()
reads a page header from the
specified raster stream.
#include <cups/raster.h> int line; cups_raster_t *ras; cups_raster_header_t header; unsigned char pixels[8192]; ... while (cupsRasterReadHeader(ras, &header)) { ... for (line = 0; line < header.cupsHeight; line ++) { cupsRasterReadPixels(ras, pixels, header.cupsBytesPerLine); ... } }
cupsRasterClose()
,
cupsRasterOpen()
,
cupsRasterReadPixels()
,
cupsRasterWriteHeader()
,
cupsRasterWritePixels()
unsigned cupsRasterReadPixels(cups_raster_t *ras, unsigned char *pixels, unsigned length);
Argument | Description |
---|---|
ras | The raster stream to read from. |
pixels | The pointer to a pixel buffer. |
length | The number of bytes of pixel data to read. |
The number of bytes read or 0 on EOF or error.
cupsRasterReadPixels()
reads pixel data from the
specified raster stream.
#include <cups/raster.h> int line; cups_raster_t *ras; cups_raster_header_t header; unsigned char pixels[8192]; ... while (cupsRasterReadHeader(ras, &header)) { ... for (line = 0; line < header.cupsHeight; line ++) { cupsRasterReadPixels(ras, pixels, header.cupsBytesPerLine); ... } }
cupsRasterClose()
,
cupsRasterOpen()
,
cupsRasterReadHeader()
,
cupsRasterWriteHeader()
,
cupsRasterWritePixels()
unsigned cupsRasterWriteHeader(cups_raster_t *ras, cups_page_header_t *header);
Argument | Description |
---|---|
ras | The raster stream to write to. |
header | A pointer to the page header to write. |
1 on success, 0 on error.
cupsRasterWriteHeader()
writes the specified page header
to a raster stream.
#include <cups/raster.h> int line; cups_raster_t *ras; cups_raster_header_t header; unsigned char pixels[8192]; ... cupsRasterWriteHeader(ras, &header); for (line = 0; line < header.cupsHeight; line ++) { ... cupsRasterWritePixels(ras, pixels, header.cupsBytesPerLine); }
cupsRasterClose()
,
cupsRasterOpen()
,
cupsRasterReadHeader()
,
cupsRasterReadPixels()
,
cupsRasterWritePixels()
unsigned cupsRasterWritePixels(cups_raster_t *ras, unsigned char *pixels, unsigned length);
Argument | Description |
---|---|
ras | The raster stream to write to. |
pixels | The pixel data to write. |
length | The number of bytes to write. |
The number of bytes written.
cupsRasterWritePixels()
writes the specified pixel data
to a raster stream.
#include <cups/raster.h> int line; cups_raster_t *ras; cups_raster_header_t header; unsigned char pixels[8192]; ... cupsRasterWriteHeader(ras, &header); for (line = 0; line < header.cupsHeight; line ++) { ... cupsRasterWritePixels(ras, pixels, header.cupsBytesPerLine); }
cupsRasterClose()
,
cupsRasterOpen()
,
cupsRasterReadHeader()
,
cupsRasterReadPixels()
,
cupsRasterWriteHeader()
const char * cupsServer(void);
A pointer to the default server name.
cupsServer()
returns a pointer to the default server
name. The server name is stored in a static location and will be
overwritten with every call to cupsServer()
.
The default server is determined from the following locations:
CUPS_SERVER
environment variable,ServerName
directive in the client.conf
file,#include <cups/cups.h> const char *server; server = cupsServer();
cupsGetPassword()
,
cupsSetPasswordCB()
,
cupsSetServer()
, cupsSetUser()
, cupsUser()
void cupsSetDests(int num_dests, cups_dest_t *dests);
Argument | Description |
---|---|
num_dests | Number of destinations. |
dests | Array of destinations. |
cupsSetDests()
saves the destination array to disk. If
the current UID is 0, the destinations are saved in the
/etc/cups/lpoptions file, otherwise they are saved in the
~/.lpoptions file. This function is typically used to save the
default options and instances that are set by the user.
#include <cups/cups.h> int num_dests; cups_dest_t *dests; ... cupsSetDests(num_dests, dests);
void cupsSetEncryption(http_encryption_t encryption);
Argument | Description |
---|---|
encryption | The type of encryption to use. |
cupsSetEncryption()
sets the default type of encryption
to use when connecting with the print server.
#include <cups/cups.h> cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
void cupsSetPasswordCB(const char *(*cb)(const char *prompt));
Argument | Description |
---|---|
cb | The password callback function. |
cupsSetPasswordCB()
sets the callback function to use
when asking the user for a password. The callback function must accept
a single character string pointer (the prompt string) and return
NULL
if the user did not enter a password string or a pointer to
the password string otherwise.
#include <cups/cups.h> const char * my_password_cb(const char *prompt) { return (getpass(prompt)); } ... char *password; ... cupsSetPasswordCB(my_password_cb); password = cupsGetPassword("Please enter a password:");
cupsDoAuthentication()
, cupsServer()
,
cupsSetServer()
,
cupsSetUser()
, cupsUser()
void cupsSetServer(const char *server);
Argument | Description |
---|---|
server | The default server to use. |
cupsSetServer()
sets the default server to use for the
CUPS API. If the server
argument is NULL
, the
default server is used.
#include <cups/cups.h> cupsSetServer("foo.bar.com");
cupsServer()
,
cupsSetPasswordCB()
,
cupsSetUser()
, cupsUser()
void cupsSetUser(const char *user);
Argument | Description |
---|---|
user | The user name string to use. |
cupsSetUser()
sets the default user name for
authentication. If the user
argument is NULL
then the current login user is used.
#include <cups/cups.h> ... cupsSetUser("root");
cupsDoAuthentication()
, cupsServer()
,
cupsSetPasswordCB()
,
cupsSetServer()
, cupsUser()
int cupsTempFd(char *filename, int length);
Argument | Description |
---|---|
filename | The character string to hold the temporary filename. |
length | The size of the filename string in bytes. |
A file descriptor open for reading and writing.
cupsTempFd()
create a temporary filename in the
/var/tmp directory or the directory specified by the TMPDIR
environment variable.
#include <cups/cups.h> int fd; char filename[256]; fd = cupsTempFd(filename, sizeof(filename));
char * cupsTempFile(char *filename, int length);
Argument | Description |
---|---|
filename | The character string to hold the temporary filename. |
length | The size of the filename string in bytes. |
A pointer to filename
.
cupsTempFile()
creates a temporary filename in the
/var/tmp directory or the directory specified by the TMPDIR
environment variable.
#include <cups/cups.h> char filename[256]; cupsTempFile(filename, sizeof(filename));
const char * cupsUser(void);
A pointer to the current username or NULL
if the user ID
is undefined.
cupsUser()
returns the name associated with the current
user ID as reported by the getuid()
system call.
#include <cups/cups.h> const char *user; user = cupsUser();
cupsDoAuthentication()
, cupsGetPassword()
,
cupsServer()
,
cupsSetServer()
, cupsSetUser()
void httpBlocking(http_t *http, int blocking)
Argument | Description |
---|---|
http | The HTTP connection |
blocking | 0 if the connection should be non-blocking, 1 if it should be blocking |
The httpBlocking()
function sets the blocking mode for
the HTTP connection. By default HTTP connections will block (stop) the
client program until data is available or can be sent to the server.
#include <cups/http.h> http_t *http; http = httpConnect("server", port); httpBlocking(http, 0);
httpCheck()
,
httpConnect()
int httpCheck(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection |
0 if there is no data pending, 1 otherwise.
The httpCheck()
function checks to see if there is any
data pending on an HTTP connection.
#include <cups/http.h> http_t *http; if (httpCheck(http)) { ... do something ... }
httpBlocking()
,
httpConnect()
, httpGets()
, httpRead()
void httpClearFields(http_t *http)
Argument | Description |
---|---|
http | The HTTP connection |
The httpClearFields()
function clears all HTTP request
fields for the HTTP connection.
#include <cups/http.h> http_t *http; httpClearFields(http);
httpConnect()
,
httpGetField()
,
httpSetField()
void httpClose(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection |
The httpClose()
function closes an active HTTP
connection.
#include <cups/http.h> http_t *http; httpClose(http);
httpConnect()
http_t * httpConnect(const char *hostname, int port);
Argument | Description |
---|---|
hostname | The name or IP address of the server to connect to |
port | The port number to use |
A pointer to a HTTP connection structure or NULL if the connection could not be made.
The httpConnect()
function opens a HTTP connection to
the specified server and port.
#include <cups/http.h> http_t *http; http = httpConnect(cupsServer(), ippPort());
httpClose()
,
httpConnectEncrypt()
,
httpGet()
, httpGets()
, httpPost()
,
httpRead()
, httpWrite()
http_t * httpConnectEncrypt(const char *hostname, int port, http_encryption_t encryption);
Argument | Description |
---|---|
hostname | The name or IP address of the server to connect to |
port | The port number to use |
encryption | The level of encryption to use |
A pointer to a HTTP connection structure or NULL if the connection could not be made.
The httpConnectEncrypt()
function opens a HTTP
connection to the specified server, port, and encryption.
#include <cups/http.h> http_t *http; http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
httpClose()
,
httpConnect()
, httpGet()
, httpGets()
,
httpPost()
, httpRead()
, httpWrite()
char * httpDecode64(char *out, const char *in);
Argument | Description |
---|---|
out | The output string |
in | The input string |
A pointer to the decoded string.
The httpDecode64()
function decodes a base-64 encoded
string to the original string.
#include <cups/http.h> char encoded_string[255]; char original_string[255]; httpDecode64(original_string, encoded_string);
httpEncode64()
int httpDelete(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to delete |
0 on success, non-zero on failure.
The httpDelete()
function sends a HTTP DELETE request to
the server.
#include <cups/http.h> http_t *http; httpDelete(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
char * httpEncode64(char *out, const char *in);
Argument | Description |
---|---|
out | The output string |
in | The input string |
A pointer to the encoded string.
The httpEncode64()
function decodes a base-64 encoded
string to the original string.
#include <cups/http.h> char encoded_string[255]; char original_string[255]; httpEncode64(encoded_string, original_string);
httpDecode64()
int httpEncryption(http_t *http, http_encryption_t encryption);
Argument | Description |
---|---|
http | The HTTP connection. |
encryption | The desired level of encryption. |
0 on success, -1 on error.
httpEncryption()
sets the encryption level for the HTTP
connection.
#include <cups/http.h> http_t *http; ... httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
int httpError(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection |
The last error that occurred or 0 if no error has occurred.
The httpError()
function returns the last error that
occurred on the HTTP connection.
#include <cups/http.h> http_t *http; if (httpError(http)) { ... show an error message ... }
httpConnect()
void httpFlush(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection |
The httpFlush()
function flushes any remaining data left
from a GET or POST operation.
#include <cups/http.h> http_t *http; httpFlush(http);
httpConnect()
,
int httpGet(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to get |
0 on success, non-zero on failure.
The httpGet()
function sends a HTTP GET request to the
server.
#include <cups/http.h> http_t *http; httpGet(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
char * httpGets(char *line, int length, http_t *http)
Argument | Description |
---|---|
line | The string to fill with a line from the HTTP connection |
length | The maximum length of the string |
http | The HTTP connection |
A pointer to the string or NULL if no line could be retrieved.
The httpGets()
function is used to read a request line
from the HTTP connection. It is not normally used by a client program.
#include <cups/http.h> http_t *http; char line[1024]; if (httpGets(line, sizeof(line), http)) { ... process the line ... }
httpConnect()
,
httpUpdate()
const char * httpGetDateString(time_t time)
Argument | Description |
---|---|
time | The UNIX date/time value |
A pointer to a static string containing the HTTP date/time string for the specified UNIX time value.
The httpGetDateString()
function generates a date/time
string suitable for HTTP requests from a UNIX time value.
#include <cups/http.h> puts(httpGetDateString(time(NULL)));
httpGetDateTime()
time_t httpGetDateTime(const char *date)
Argument | Description |
---|---|
date | The HTTP date/time string |
A UNIX time value.
The httpGetDateTime()
function converts a HTTP date/time
string to a UNIX time value.
#include <cups/http.h> printf("%d\n", httpGetDateTime("Fri, 30 June 2000 12:34:56 GMT"));
httpGetDateString()
const char * httpGetField(http_t *http, http_field_t field);
Argument | Description |
---|---|
http | The HTTP connection |
field | The HTTP field |
A pointer to the field value string.
The httpGetField()
function returns the current value
for the specified HTTP field.
#include <cups/http.h> http_t *http; httpGet(http, "/some/uri"); while (httpUpdate(http) == HTTP_CONTINUE); puts(httpGetField(http, HTTP_FIELD_CONTENT_TYPE));
httpConnect()
,
httpGetSubField()
,
httpSetField()
struct hostent * httpGetHostByName(const char *name);
Argument | Description |
---|---|
name | Name or IP address to lookup. |
NULL if the host could not be found or a pointer to a host entry containing one or more addresses.
httpGetHostByName()
is a portable wrapper around the
gethostbyname()
function which handles both hostnames and IP
addresses.
#include <cups/http.h> struct hostent *hostaddr; hostaddr = httpGetHostByName("foo.bar.com");
int httpGetLength(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection. |
The content length of the response or MAX_INT if chunking is used.
httpGetLength()
returns the content length of a
response.
#include <cups/http.h> http_t *http; ... printf("The length of the response is %d bytes.\n", httpGetLength(http));
const char * httpGetSubField(http_t *http, http_field_t field, const char *name, char *value);
Argument | Description |
---|---|
http | The HTTP connection. |
field | The HTTP field. |
name | The name of the subfield. |
value | The string to hold the subfield value. |
A pointer to the subfield value string or NULL if it does not exist.
The httpGetSubField()
function returns a subfield value
from the specified HTTP field. The destination string buffer must be at
least HTTP_MAX_VALUE
bytes in length.
#include <cups/http.h> http_t *http; char value[HTTP_MAX_VALUE]; httpGet(http, "/some/uri"); while (httpUpdate(http) == HTTP_CONTINUE); puts(httpGetSubField(http, HTTP_FIELD_CONTENT_TYPE, "charset", value));
httpConnect()
,
httpGetField()
,
httpSetField()
int httpHead(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to head |
0 on success, non-zero on failure.
The httpHead()
function sends a HTTP HEAD request to the
server.
#include <cups/http.h> http_t *http; httpHead(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
void httpInitialize(void);
The httpInitialize()
function initializes the networking
code as needed by the underlying platform. It is called automatically
by the httpConnect()
function.
#include <cups/http.h> httpInitialize();
httpConnect()
char * httpMD5(const char *username, const char *realm, const char *passwd, char md5[33]);
Argument | Description |
---|---|
username | The authenticating user name. |
realm | The authenticating realm name. |
passwd | The authenticating password. |
md5 | The MD5 sum string. |
A pointer to the MD5 sum string.
httpMD5()
computes the MD5 hash of the username, realm,
and password as required by the HTTP Digest specification.
#include <cups/http.h> char md5[33]; ... httpMD5("user", "realm", "password", md5);
httpMD5Final()
,
httpMD5String()
char * httpMD5Final(const char *nonce, const char *method, const char *resource, char md5[33]);
Argument | Description |
---|---|
nonce | The server nonce value. |
method | The HTTP method (GET, POST, etc.) |
resource | The resource path. |
md5 | The MD5 sum string. |
The MD5 sum string.
httpMD5Final()
appends the nonce, method, and resource
to the specified MD5 sum.
#include <cups/http.h> char md5[33]; ... httpMD5Final("nonce", "GET", "/jobs", md5);
char * httpMD5String(const md5_byte_t *sum, char md5[33]);
Argument | Description |
---|---|
sum | The raw MD5 sum data. |
md5 | The MD5 sum string. |
The MD5 sum string.
httpMD5String()
converts the raw MD5 sum value to a
string.
#include <cups/http.h> md5_byte_t sum[16]; char md5[33]; ... httpMD5String(sum, md5);
int httpOptions(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to check for options |
0 on success, non-zero on failure.
The httpOptions()
function sends a HTTP OPTIONS request
to the server.
#include <cups/http.h> http_t *http; httpOptions(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
int httpPost(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to post to |
0 on success, non-zero on failure.
The httpPost()
function sends a HTTP POST request to the
server.
#include <cups/http.h> http_t *http; httpPost(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
int httpPrintf(http_t *http, const char *format, ...);
Argument | Description |
---|---|
http | The HTTP connection |
format | A printf-style format string |
The number of bytes written.
The httpPrintf()
function sends a formatted string to
the HTTP connection. It is normally only used by the CUPS API and
scheduler.
#include <cups/http.h> http_t *http; httpPrintf(http, "GET / HTTP/1.1 \r\n");
httpConnect()
int httpPut(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to put |
0 on success, non-zero on failure.
The httpPut()
function sends a HTTP PUT request to the
server.
#include <cups/http.h> http_t *http; httpDelete(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
int httpRead(http_t *http, char *buffer, int length);
Argument | Description |
---|---|
http | The HTTP connection |
buffer | The buffer to read into |
length | The number of bytes to read |
The number of bytes read or -1 on error.
The httpRead()
function reads data from the HTTP
connection, possibly the result of a GET or POST request.
#include <cups/http.h> http_t *http; char buffer[1024]; int bytes; httpGet(http, "/"); while (httpUpdate(http) != HTTP_CONTINUE); while ((bytes = httpRead(http, buffer, sizeof(buffer) - 1)) > 0) { buffer[bytes] = '\0'; fputs(buffer, stdout); }
httpConnect()
,
httpWrite()
int httpReconnect(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection |
0 on success, non-zero on failure.
The httpReconnect()
function reconnects to the HTTP
server. This is usually done automatically if the HTTP functions detect
that the server connection has terminated.
#include <cups/http.h> http_t *http; httpReconnect(http);
httpConnect()
void httpSeparate(const char *uri, char *method, char *username, char *host, int *port, char *resource);
Argument | Description |
---|---|
uri | The URI to separate |
method | The method (scheme) of the URI |
username | The username (and password) portion of the URI, if any |
host | The hostname portion of the URI, if any |
port | The port number for the URI, either as specified or as default for the method/scheme |
resource | The resource string, usually a filename on the server |
The httpSeparate()
function separates the specified URI
into its component parts. The method, username, hostname, and resource
strings should be at least HTTP_MAX_URI
characters long to
avoid potential buffer overflow problems.
char uri[HTTP_MAX_URI]; char method[HTTP_MAX_URI]; char username[HTTP_MAX_URI]; char host[HTTP_MAX_URI]; char resource[HTTP_MAX_URI]; int port; ... httpSeparate(uri, method, username, host, &port, resource);
httpConnect()
void httpSetField(http_t *http, http_field_t field, const char *value);
Argument | Description |
---|---|
http | The HTTP connection |
field | The HTTP field |
value | The string value for the field |
The httpSetField()
function sets the current value for
the specified HTTP field.
#include <cups/http.h> http_t *http; httpSetField(http, HTTP_FIELD_AUTHORIZATION, "Basic dfdr34453454325")); httpGet(http, "/some/uri"); while (httpUpdate(http) == HTTP_CONTINUE);
httpConnect()
,
httpGetField()
const char * httpStatus(http_status_t status);
Argument | Description |
---|---|
status | The HTTP status code from the server. |
The standard HTTP status text associated with the status code.
httpStatus()
returns the standard HTTP status text
associated with the status code.
#include <cups/http.h> http_t *http; ... puts(httpStatus(http->status));
int httpTrace(http_t *http, const char *uri);
Argument | Description |
---|---|
http | The HTTP connection |
uri | The URI to trace |
0 on success, non-zero on failure.
The httpTrace()
function sends a HTTP TRACE request to
the server.
#include <cups/http.h> http_t *http; httpTrace(http, "/some/uri");
httpConnect()
,
httpSetField()
,
httpUpdate()
http_status_t httpUpdate(http_t *http);
Argument | Description |
---|---|
http | The HTTP connection |
The HTTP status of the current request.
The httpUpdate()
function updates the current request
status. It is used after any DELETE, GET, HEAD, OPTIONS, POST, PUT, or
TRACE request to finalize the HTTP request and retrieve the request
status.
Since proxies and the current blocking mode can cause the request to
take longer, programs should continue calling httpUpdate()
until the return status is not the constant value
HTTP_CONTINUE
.
#include <cups/http.h> http_t *http; http_status_t status; httpGet(http, "/some/uri"); while ((status = httpUpdate(http)) == HTTP_CONTINUE); printf("Request status is %d\n", status);
httpConnect()
,
httpDelete()
, httpGet()
, httpHead()
,
httpOptions()
, httpPost()
, httpPut()
,
httpTrace()
int httpWrite(http_t *http, char *buffer, int length);
Argument | Description |
---|---|
http | The HTTP connection |
buffer | The buffer to read into |
length | The number of bytes to read |
The number of bytes read or -1 on error.
The httpWrite()
function reads data from the HTTP
connection, possibly the result of a GET or POST request.
#include <cups/http.h> http_t *http; FILE *fp; char buffer[1024]; int bytes; httpPost(http, "/"); while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) httpWrite(http, buffer, bytes); while (httpUpdate(http) != HTTP_CONTINUE); while ((bytes = httpRead(http, buffer, sizeof(buffer) - 1)) > 0) { buffer[bytes] = '\0'; fputs(buffer, stdout); }
httpConnect()
,
httpRead()
ipp_attribute_t * ippAddBoolean(ipp_t *ipp, ipp_tag_t group, const char *name, char value);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
value | The boolean value |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddBoolean()
function adds a single boolean
attribute value to the specified IPP request.
#include <cups/ipp.h> ipp_t *ipp; ippAddBoolean(ipp, IPP_TAG_OPERATION, "my-jobs", 1);
ippAddBooleans()
,
ippAddDate()
,
ippAddInteger()
,
ippAddIntegers()
, ippAddRange()
, ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddBooleans(ipp_t *ipp, ipp_tag_t group, const char *name, int num_values, const char *values);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
num_values | The number of values |
values | The boolean values |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddBooleans()
function adds one or more boolean
attribute values to the specified IPP request. If the values
pointer is NULL
then an array of num_values
false values is created.
#include <cups/ipp.h> ipp_t *ipp; char values[10]; ippAddBooleans(ipp, IPP_TAG_OPERATION, "some-attribute", 10, values);
ippAddBoolean()
,
ippAddDate()
,
ippAddInteger()
,
ippAddIntegers()
, ippAddRange()
, ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddDate(ipp_t *ipp, ipp_tag_t group, const char *name, ipp_uchar_t *value);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
value | The date value |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddDate()
function adds a single date-time
attribute value to the specified IPP request.
#include <cups/ipp.h> ipp_t *ipp; ippAddDate(ipp, IPP_TAG_OPERATION, "some-attribute", ippTimeToDate(time(NULL));
ippAddBoolean()
,
ippAddBooleans()
,
ippAddInteger()
,
ippAddIntegers()
, ippAddRange()
, ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
,
ippTimeToDate()
ipp_attribute_t * ippAddInteger(ipp_t *ipp, ipp_tag_t group, ipp_tag_t tag, const char *name, int value);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
tag | The type of integer value (IPP_TAG_INTEGER or IPP_TAG_ENUM) |
name | The name of attribute |
value | The integer value |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddInteger()
function adds a single integer
attribute value to the specified IPP request.
#include <cups/ipp.h> ipp_t *ipp; ippAddInteger(ipp, IPP_TAG_OPERATION, "limit", 100);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
,
ippAddIntegers()
, ippAddRange()
, ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddIntegers(ipp_t *ipp, ipp_tag_t group, ipp_tag_t tag, const char *name, int num_values, const int *values);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
tag | The type of integer value (IPP_TAG_INTEGER or IPP_TAG_ENUM) |
name | The name of attribute |
num_values | The number of values |
values | The integer values |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddIntegers()
function adds one or more integer
attribute values to the specified IPP request. If the values
pointer is NULL
then an array of num_values
0
values is created.
#include <cups/ipp.h> ipp_t *ipp; int values[100]; ippAddIntegers(ipp, IPP_TAG_OPERATION, "some-attribute", 100, values);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddRange()
,
ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddRange(ipp_t *ipp, ipp_tag_t group, const char *name, int low, int high);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
low | The lower value |
high | The higher value |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddRange()
function adds a single range attribute
value to the specified IPP request.
#include <cups/ipp.h> ipp_t *ipp; ippAddRange(ipp, IPP_TAG_OPERATION, "page-ranges", 1, 10);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddRanges(ipp_t *ipp, ipp_tag_t group, const char *name, int num_values, const int *lows, const int *highs);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
num_values | The number of range values |
lows | The lower values |
highs | The higher values |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddRanges()
function adds one or more range
attribute values to the specified IPP request. If the values
pointer is NULL
then an array of num_values
0,0 ranges is created.
#include <cups/ipp.h> ipp_t *ipp; int lows[2]; int highs[2]; ippAddRanges(ipp, IPP_TAG_OPERATION, "page-ranges", 2, lows, highs);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRange()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddResolution(ipp_t *ipp, ipp_tag_t group, const char *name, int xres, int yres, ipp_res_t units);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
xres | The horizontal resolution |
yres | The vertical resolution |
units | The resolution units |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddResolution()
function adds a single resolution
attribute value to the specified IPP request.
#include <cups/ipp.h> ipp_t *ipp; ippAddBoolean(ipp, IPP_TAG_OPERATION, "printer-resolution", 720, 720, IPP_RES_PER_INCH);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRange()
,
ippAddRanges()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddResolutions(ipp_t *ipp, ipp_tag_t group, const char *name, int num_values, const int *xres, const int *yres, const ipp_res_t *units);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
name | The name of attribute |
num_values | The number of resolution values |
xres | The horizontal resolutions |
yres | The vertical resolutions |
units | The resolution units |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddResolutions()
function adds one or more
resolution attribute values to the specified IPP request. If the
values
pointer is NULL
then an array of
num_values
0,0 resolutions is created.
#include <cups/ipp.h> ipp_t *ipp; int xres[5]; int yres[5]; ipp_res_t units[5]; ippAddBoolean(ipp, IPP_TAG_OPERATION, "printer-resolutions-supported", 5, xres, yres, units);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRange()
,
ippAddRanges()
,
ippAddResolution()
,
ippAddSeparator()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddSeparator(ipp_t *ipp);
Argument | Description |
---|---|
ipp | The IPP request |
A pointer to the new separator or NULL if the separator could not be created.
The ippAddSeparator()
function adds a group separator to
the specified IPP request.
#include <cups/ipp.h> ipp_t *ipp; ippAddSeparator(ipp);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRange()
,
ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddString()
,
ippAddStrings()
ipp_attribute_t * ippAddString(ipp_t *ipp, ipp_tag_t group, ipp_tag_t tag, const char *name, const char *charset, const char *value);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
tag | The type of string value |
name | The name of attribute |
charset | The character set for the string |
value | The string value |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddString()
function adds a single string
attribute value to the specified IPP request. For
IPP_TAG_NAMELANG
and IPP_TAG_TEXTLANG
strings, the
charset value is provided with the string to identify the string
encoding used. Otherwise the charset value is ignored.
#include <cups/ipp.h> ipp_t *ipp; ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL, "abc123");
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRange()
,
ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddStrings()
ipp_attribute_t * ippAddStrings(ipp_t *ipp, ipp_tag_t group, ipp_tag_t tag, const char *name, int num_values, const char *charset, const char **values);
Argument | Description |
---|---|
ipp | The IPP request |
group | The IPP group |
tag | The type of string value |
name | The name of attribute |
num_values | The number of strings |
charset | The character set for the strings |
values | The string values |
A pointer to the new attribute or NULL if the attribute could not be created.
The ippAddStrings()
function adds one or more string
attribute values to the specified IPP request. For
IPP_TAG_NAMELANG
and IPP_TAG_TEXTLANG
strings, the
charset value is provided with the strings to identify the string
encoding used. Otherwise the charset value is ignored. If the
values
pointer is NULL
then an array of
num_values
NULL strings is created.
#include <cups/ipp.h> ipp_t *ipp; char *values[2] = { "one", "two" }; ippAddStrings(ipp, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "attr-name", 2, NULL, values);
ippAddBoolean()
,
ippAddBooleans()
,
ippAddDate()
, ippAddInteger()
, ippAddIntegers()
,
ippAddRange()
,
ippAddRanges()
,
ippAddResolution()
,
ippAddResolutions()
,
ippAddSeparator()
,
ippAddString()
time_t ippDateToTime(const ipp_uchar_t date[11]);
Argument | Description |
---|---|
date | The IPP date-time value |
A UNIX time value.
The ippDateToTime()
function converts an IPP date-time
value to a UNIX time value.
#include <cups/ipp.h> ipp_uchar_t date[11]; printf("UNIX time is %d\n", ippDateToTime(date));
ippTimeToDate()
void ippDelete(ipp_t *ipp);
Argument | Description |
---|---|
ipp | The IPP request or response |
The ippDelete()
function deletes all memory used by an
IPP request or response.
#include <cups/ipp.h> ipp_t *ipp; ippDelete(ipp);
ippNew()
const char * ippErrorString(ipp_status_t error);
Argument | Description |
---|---|
error | IPP error code. |
The standard text representation of the IPP error code.
ippErrorString()
returns the standard text
representation of the IPP error code.
#include <cups/ipp.h> puts(ippErrorString(IPP_OK));
ipp_attribute_t * ippFindAttribute(ipp_t *ipp, const char *name, ipp_tag_t tag);
Argument | Description |
---|---|
ipp | The IPP request or response |
name | The name of the attribute |
tag | The required value tag for the attribute or
IPP_TAG_ZERO for any type of value. |
A pointer to the first occurrence of the requested attribute, or
NULL
if it was not found.
ippFindAttribute()
finds the first occurrence of the
named attribute. The tag
parameter restricts the search to
a specific value type - use IPP_TAG_ZERO
to find any value
with the name.
The value tags IPP_TAG_NAME
and IPP_TAG_TEXT
match the name/text values with or without the language code.
ipp_attribute_t *attr; attr = ippFindAttribute(response, "printer-state-message", IPP_TAG_TEXT); while (attr != NULL) { puts(attr->values[0].string.text); attr = ippFindNextAttribute(response, "printer-state-message", IPP_TAG_TEXT); }
cupsDoFileRequest()
,
cupsDoRequest()
, ippDelete()
, ippFindNextAttribute()
, ippNew()
ipp_attribute_t * ippFindNextAttribute(ipp_t *ipp, const char *name, ipp_tag_t tag);
Argument | Description |
---|---|
ipp | The IPP request or response |
name | The name of the attribute |
tag | The required value tag for the attribute or
IPP_TAG_ZERO for any type of value. |
A pointer to the next occurrence of the requested attribute, or
NULL
if it was not found.
ippFindNextAttribute()
finds the next occurrence of the
named attribute. The tag
parameter restricts the search to
a specific value type - use IPP_TAG_ZERO
to find any value
with the name.
The value tags IPP_TAG_NAME
and IPP_TAG_TEXT
match the name/text values with or without the language code.
ipp_attribute_t *attr; attr = ippFindAttribute(response, "printer-state-message", IPP_TAG_TEXT); while (attr != NULL) { puts(attr->values[0].string.text); attr = ippFindNextAttribute(response, "printer-state-message", IPP_TAG_TEXT); }
cupsDoFileRequest()
,
cupsDoRequest()
, ippDelete()
, ippFindNextAttribute()
, ippNew()
int ippLength(ipp_t *ipp);
Argument | Description |
---|---|
ipp | The IPP request or response |
The total encoded length of the IPP request or response in bytes.
ippLength()
returns the length of the IPP request or
response in bytes.
printf("The length of the response is %d bytes.\n", ippLength(response));
ippDelete()
,
ippNew()
ipp_t * ippNew(void);
A pointer to a new IPP request or response.
The ippNew()
function creates a new IPP request or
response.
#include <cups/ipp.h> ipp_t *ipp; ipp = ippNew();
ippDelete()
int ippPort(void);
The default TCP/IP port number for IPP requests.
The ippPort()
function returns the default IPP port
number for requests.
#include <cups/http.h> #include <cups/ipp.h> http_t *http; http = httpConnect(cupsServer(), ippPort());
cupsServer()
,
ippSetPort()
ipp_state_t ippRead(http_t *http, ipp_t *ipp);
Argument | Description |
---|---|
http | The HTTP connection |
ipp | The IPP request or response |
The current read state.
The ippRead()
function reads IPP attributes from the
specified HTTP connection. Programs should continue calling
ippRead()
until IPP_ERROR
or IPP_DATA
is returned.
#include <cups/http.h> #include <cups/ipp.h> http_t *http; ipp_t *ipp; ipp_state_t status; ipp = ippNew(); while ((status = ippRead(http, ipp)) != IPP_ERROR) if (status == IPP_DATA) break; if (status == IPP_DATA) { ... read additional non-IPP data using httpRead() ... }
ippWrite()
void ippSetPort(int port);
Argument | Description |
---|---|
port | The port number to use |
The ippSetPort()
function sets the default IPP port
number for requests.
#include <cups/http.h> #include <cups/ipp.h> ... ippSetPort(8631);
ippPort()
ipp_uchar_t * ippTimeToDate(time_t time);
Argument | Description |
---|---|
time | The UNIX time value |
A static pointer to an IPP date-time value.
The ippTimeToDate()
function converts a UNIX time to an
IPP date-time value.
#include <cups/ipp.h> ipp_uchar_t *date; date = ippTimeToDate(time(NULL));
ippDateToTime()
ipp_state_t ippWrite(http_t *http, ipp_t *ipp);
Argument | Description |
---|---|
http | The HTTP connection |
ipp | The IPP request or response |
The current write state.
The ippWrite()
function writes IPP attributes to the
specified HTTP connection. Programs should continue calling
ippWrite()
until IPP_ERROR
or IPP_DATA
is returned.
#include <cups/http.h> #include <cups/ipp.h> http_t *http; ipp_t *ipp; ipp_state_t status; ipp = ippNew(); ... add attributes ... while ((status = ippWrite(http, ipp)) != IPP_ERROR) if (status == IPP_DATA) break; if (status == IPP_DATA) { ... read additional non-IPP data using httpWrite() ... }
ippRead()
void ppdClose(ppd_file_t *ppd);
Argument | Description |
---|---|
ppd | The PPD file |
The ppdClose()
function frees all memory associated with
the PPD file.
#include <cups/ppd.h> ppd_file_t *ppd; ppdClose(ppd);
ppdOpen()
,
ppdOpenFd()
, ppdOpenFile()
int ppdCollect(ppd_file_t *ppd, ppd_section_t section, ppd_choice_t ***choices);
Argument | Description |
---|---|
ppd | The PPD file. |
section | The document section to collect. |
choices | The array of option choices that are marked. |
The number of options collected.
ppdCollect()
collects all of the marked options in the
specified section, sorts them by their order dependency values, and
returns an array that can be used to emit option commands in the proper
order. It is normally used by the ppdEmit*()
functions.
#include <cups/ppd.h> ppd_file_t *ppd; int num_choices; ppd_choice_t **choices; ... num_choices = ppdCollect(ppd, PPD_ORDER_JCL, &choices);
ppdEmit()
,
ppdEmitFd()
, ppdEmitJCL()
int ppdConflicts(ppd_file_t *ppd);
Argument | Description |
---|---|
ppd | The PPD file |
The number of option conflicts in the file.
The ppdConflicts()
function returns the number of
conflicts with the currently selected options.
#include <cups/ppd.h> ppd_file_t *ppd; printf("%d conflicts\n", ppdConflicts(ppd));
cupsMarkOptions()
,
ppdIsMarked()
,
ppdMarkDefaults()
,
ppdMarkOption()
int ppdEmit(ppd_file_t *ppd, FILE *file, ppd_section_t section);
Argument | Description |
---|---|
ppd | The PPD file |
file | The file to write to |
section | The option section to write |
0 on success, -1 on error.
The ppdEmit()
function sends printer-specific option
commands to the specified file.
#include <cups/ppd.h> ppd_file_t *ppd; ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
ppdEmitFd()
int ppdEmitFd(ppd_file_t *ppd, int fd, ppd_section_t section);
Argument | Description |
---|---|
ppd | The PPD file |
fd | The file descriptor to write to |
section | The option section to write |
0 on success, -1 on error.
The ppdEmitFd()
function sends printer-specific option
commands to the specified file descriptor.
#include <cups/ppd.h> ppd_file_t *ppd; ppdEmitFd(ppd, 1, PPD_ORDER_PAGE);
ppdEmit()
,
ppdEmitJCL()
int ppdEmitJCL(ppd_file_t *ppd, FILE *file, int job_id, const char *user, const char *title);
Argument | Description |
---|---|
ppd | The PPD file |
file | The file to write to |
job_id | The job ID number |
user | The job user |
title | The job name |
0 on success, -1 on error.
The ppdEmitJCL()
function sends printer-specific job
control commands to the specified file. For printers that support the
HP Printer Job Language (PJL) job control language, the output also
contains a display string that usually appears on the printer's LCD.
#include <cups/ppd.h> ppd_file_t *ppd; ppdEmitJCL(ppd, stdout, job_id, user, title);
ppdEmit()
,
ppdEmitFd()
ppd_attr_t * ppdFindAttr(ppd_file_t *ppd, const char *keyword, const char *spec);
Argument | Description |
---|---|
ppd | The PPD file |
keyword | The name of the attribute |
spec | The option keyword associated with the attribute or NULL if you don't care. |
A pointer to the attribute data or NULL if the attribute does not exist.
The ppdFindAttr()
function returns a pointer to the
first occurrence of the attribute in the PPD file.
#include <cups/ppd.h> ppd_file_t *ppd; ppd_attr_t *attr; attr = ppdFindAttr(ppd, "RequiresPageRegion", "Upper");
ppdFindNextAttr()
ppd_choice_t * ppdFindChoice(ppd_option_t *option, const char *choice);
Argument | Description |
---|---|
option | A pointer to the option |
choice | The name of the choice |
A pointer to the choice data or NULL if the choice does not exist.
The ppdFindChoice()
function returns a pointer to the
choice data for the specified option.
#include <cups/ppd.h> ppd_file_t *ppd; ppd_option_t *option; ppd_choice_t *choice; option = ppdFindOption(ppd, "PageSize"); choice = ppdFindChoice(option, "Letter");
ppdFindMarkedChoice()
, ppdFindOption()
ppd_choice_t * ppdFindMarkedChoice(ppd_file_t *ppd, const char *keyword);
Argument | Description |
---|---|
ppd | The PPD file |
keyword | The name of the option |
A pointer to the choice data or NULL if the choice does not exist or is not marked.
The ppdFindMarkedChoice()
function returns a pointer to
the marked choice data for the specified option.
#include <cups/ppd.h> ppd_file_t *ppd; ppd_choice_t *choice; choice = ppdFindMarkedChoice(ppd, "PageSize");
ppdFindChoice()
,
ppdFindOption()
ppd_attr_t * ppdFindNextAttr(ppd_file_t *ppd, const char *keyword, const char *spec);
Argument | Description |
---|---|
ppd | A pointer to the PPD file |
keyword | The name of the attribute |
spec | The option keyword associated with the attribute or NULL if you don't care. |
A pointer to the attribute data or NULL if the attribute does not exist.
The ppdFindNextAttr()
function returns a pointer to the
next occurrence of the attribute in the PPD file.
#include <cups/ppd.h> ppd_file_t *ppd; ppd_attr_t *attr; for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); attr != NULL; attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) { printf("*%s %s/%s: \"%s\"\n", attr->name, attr->spec, attr->text, attr->value ? attr->value : "(none)"); }
ppdFindAttr()
ppd_option_t * ppdFindOption(ppd_file_t *ppd, const char *keyword);
Argument | Description |
---|---|
ppd | The PPD file |
keyword | The name of the option |
A pointer to the option data or NULL if the option does not exist.
The ppdFindOption()
function returns a pointer to the
option data for the specified option.
#include <cups/ppd.h> ppd_file_t *ppd; ppd_option_t *option; option = ppdFindOption(ppd, "PageSize");
ppdFindChoice()
,
ppdFindMarkedChoice()
int ppdIsMarked(ppd_file_t *ppd, const char *keyword, const char *choice);
Argument | Description |
---|---|
ppd | The PPD file |
keyword | The name of the option |
choice | The name of the option choice |
1 if the choice is marked, 0 otherwise.
The ppdIsMarked()
function returns whether or not the
specified option choice is marked.
#include <cups/ppd.h> ppd_file_t *ppd; printf("Letter size %s selected.\n", ppdIsMarked(ppd, "PageSize", "Letter") ? "is" : "is not");
cupsMarkOptions()
,
ppdConflicts()
,
ppdIsMarked()
,
ppdMarkDefaults()
,
ppdMarkOption()
void ppdMarkDefaults(ppd_file_t *ppd);
Argument | Description |
---|---|
ppd | The PPD file |
The ppdMarkDefaults()
function marks all of the default
choices in the PPD file.
#include <cups/ppd.h> ppd_file_t *ppd; ppdMarkDefaults(ppd);
cupsMarkOptions()
,
ppdConflicts()
,
ppdIsMarked()
,
ppdMarkDefaults()
,
ppdMarkOption()
int ppdMarkOption(ppd_file_t *ppd, const char *keyword, const char *choice);
Argument | Description |
---|---|
ppd | The PPD file |
keyword | The name of the option |
choice | The name of the choice |
The number of conflicts in the PPD file.
The ppdMarkOption()
function marks the specified option
choice.
#include <cups/ppd.h> ppd_file_t *ppd; ppdMarkOption(ppd, "PageSize", "Letter");
cupsMarkOptions()
,
ppdConflicts()
,
ppdIsMarked()
,
ppdMarkDefaults()
,
ppdMarkOption()
ppd_file_t * ppdOpen(FILE *file);
Argument | Description |
---|---|
file | The file to read from |
A pointer to a PPD file structure or NULL if the PPD file could not be read.
The ppdOpen()
function reads a PPD file from the
specified file into memory.
#include <cups/ppd.h> ppd_file_t *ppd; FILE *file; file = fopen("filename.ppd", "rb"); ppd = ppdOpen(file); fclose(file);
ppdClose()
,
ppdOpenFd()
, ppdOpenFile()
ppd_file_t * ppdOpenFd(int fd);
Argument | Description |
---|---|
fd | The file descriptor to read from |
A pointer to a PPD file structure or NULL if the PPD file could not be read.
The ppdOpenFd()
function reads a PPD file from the
specified file descriptor into memory.
#include <cups/ppd.h> ppd_file_t *ppd; int fd; fd = open("filename.ppd", O_RDONLY); ppd = ppdOpenFd(fd); close(fd);
ppdClose()
,
ppdOpen()
, ppdOpenFile()
ppd_file_t * ppdOpenFile(const char *filename);
Argument | Description |
---|---|
filename | The name of the file to read from |
A pointer to a PPD file structure or NULL if the PPD file could not be read.
The ppdOpenFile()
function reads a PPD file from the
named file into memory.
#include <cups/ppd.h> ppd_file_t *ppd; ppd = ppdOpenFile("filename.ppd");
ppdClose()
,
ppdOpen()
, ppdOpenFd()
float ppdPageLength(ppd_file_t *ppd, const char *name);
Argument | Description |
---|---|
ppd | The PPD file |
name | The name of the page size |
The length of the specified page size in points or 0 if the page size does not exist.
The ppdPageLength()
function returns the page length of
the specified page size.
#include <cups/ppd.h> ppd_file_t *ppd; printf("Length = %.0f\n", ppdPageLength(ppd, "Letter"));
ppdPageLength()
,
ppdPageSize()
,
ppdPageWidth()
ppd_size_t * ppdPageSize(ppd_file_t *ppd, const char *name);
Argument | Description |
---|---|
ppd | The PPD file |
name | The name of the page size |
A pointer to the page size record of the specified page size in points or NULL if the page size does not exist.
The ppdPageSize()
function returns the page size record
for the specified page size.
#include <cups/ppd.h> ppd_file_t *ppd; ppd_size_t *size; size = ppdPageSize(ppd, "Letter"); if (size != NULL) { printf(" Width = %.0f\n", size->width); printf("Length = %.0f\n", size->length); printf(" Left = %.0f\n", size->left); printf(" Right = %.0f\n", size->right); printf("Bottom = %.0f\n", size->bottom); printf(" Top = %.0f\n", size->top); }
ppdPageLength()
,
ppdPageWidth()
float ppdPageWidth(ppd_file_t *ppd, const char *name);
Argument | Description |
---|---|
ppd | The PPD file |
name | The name of the page size |
The width of the specified page size in points or 0 if the page size does not exist.
The ppdPageWidth()
function returns the page width of
the specified page size.
#include <cups/ppd.h> ppd_file_t *ppd; printf("Width = %.0f\n", ppdPageWidth(ppd, "Letter"));
ppdPageLength()
,
ppdPageSize()
:: Command execute :: | |
--[ c99shell v. 1.0 pre-release build #16 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0034 ]-- |