1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
3 <!-- SECTION: Programming -->
5 <title>Filter and Backend Programming
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta name=
"creator" content=
"Mini-XML v2.5">
8 <style type=
"text/css"><!--
10 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
13 H1, H2, H3, H4, H5, H6, P, TD, TH {
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
18 font-family: monaco, courier, monospace;
23 font-family: monaco, courier, monospace;
32 border: dotted thin #999999;
37 PRE.command EM, PRE.example EM {
38 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
42 font-family: monaco, courier, monospace;
53 border: solid thin #999999;
59 text-decoration: none;
62 A:link:hover, A:visited:hover, A:active {
63 text-decoration: underline;
71 border: solid thin #999999;
72 border-collapse: collapse;
88 border: solid thin #cccccc;
95 border-bottom: solid thin #999999;
104 caption-side: bottom;
124 border: thin solid #000000;
132 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
138 border-bottom: solid 2pt #000000;
156 font-family: monaco, courier, monospace;
165 border: solid thin #999999;
166 border-collapse: collapse;
171 DIV.summary TABLE TD, DIV.summary TABLE TH {
172 border: solid thin #999999;
178 DIV.summary TABLE THEAD TH {
182 /* API documentation styles... */
189 div.body h3, div.body h4, div.body h5 {
190 margin-bottom: 0.5em;
193 .class, .enumeration, .function, .struct, .typedef, .union {
194 border-bottom: solid thin #999999;
201 code, p.code, pre, ul.code li {
202 font-family: monaco, courier, monospace;
205 ul.code, ul.contents, ul.subcontents {
206 list-style-type: none;
216 ul.contents li ul.code, ul.contents li ul.subcontents {
229 margin-bottom: 0.5em;
232 /* This is just for the HTML files generated with the framedhelp target */
235 border: solid thin black;
244 div.contents ul.contents {
247 div.contents ul.subcontents li {
256 "$Id: api-filter.header 7615 2008-05-25 07:17:07Z mike $"
258 Filter and backend programming header for the Common UNIX Printing System
261 Copyright 2008 by Apple Inc.
263 These coded instructions, statements, and computer programs are the
264 property of Apple Inc. and are protected by Federal copyright
265 law. Distribution and use rights are outlined in the file "LICENSE.txt"
266 which should have been included with this file. If this file is
267 file is missing or damaged, see the license at "http://www.cups.org/".
270 <h1 class=
"title">Filter and Backend Programming
</h1>
272 <div class='summary'
><table summary='General Information'
>
276 <th>cups/backend.h
<br>
277 cups/sidechannel.h
</th>
287 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a><br>
288 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
289 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
290 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
291 Specifications:
<a href='spec-design' target='_top'
>CUPS Design Description
</a></td>
295 <h2 class=
"title">Contents
</h2>
296 <ul class=
"contents">
298 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
299 <li><a href=
"#SECURITY">Security Considerations
</a></li>
300 <li><a href=
"#TEMPFILES">Temporary Files
</a></li>
301 <li><a href=
"#COPIES">Copy Generation
</a></li>
302 <li><a href=
"#EXITCODES">Exit Codes
</a></li>
303 <li><a href=
"#ENVIRONMENT">Environment Variables
</a></li>
304 <li><a href=
"#MESSAGES">Communicating with the Scheduler
</a></li>
305 <li><a href=
"#COMMUNICATING_BACKEND">Communicating with the Backend
</a></li>
306 <li><a href=
"#COMMUNICATING_FILTER">Communicating with Filters
</a></li>
307 <li><a href=
"#SNMP">Doing SNMP Queries with Network Printers
</a></li>
309 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
310 <li><a href=
"#cupsBackChannelRead" title=
"Read data from the backchannel.">cupsBackChannelRead
</a></li>
311 <li><a href=
"#cupsBackChannelWrite" title=
"Write data to the backchannel.">cupsBackChannelWrite
</a></li>
312 <li><a href=
"#cupsBackendDeviceURI" title=
"Get the device URI for a backend.">cupsBackendDeviceURI
</a></li>
313 <li><a href=
"#cupsSideChannelDoRequest" title=
"Send a side-channel command to a backend and wait for a response.">cupsSideChannelDoRequest
</a></li>
314 <li><a href=
"#cupsSideChannelRead" title=
"Read a side-channel message.">cupsSideChannelRead
</a></li>
315 <li><a href=
"#cupsSideChannelSNMPGet" title=
"Query a SNMP OID's value.">cupsSideChannelSNMPGet
</a></li>
316 <li><a href=
"#cupsSideChannelSNMPWalk" title=
"Query multiple SNMP OID values.">cupsSideChannelSNMPWalk
</a></li>
317 <li><a href=
"#cupsSideChannelWrite" title=
"Write a side-channel message.">cupsSideChannelWrite
</a></li>
319 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
320 <li><a href=
"#cups_backend_t" title=
"Backend exit codes">cups_backend_t
</a></li>
321 <li><a href=
"#cups_sc_bidi_t" title=
"Bidirectional capabilities">cups_sc_bidi_t
</a></li>
322 <li><a href=
"#cups_sc_command_t" title=
"Request command codes">cups_sc_command_t
</a></li>
323 <li><a href=
"#cups_sc_state_t" title=
"Printer state bits">cups_sc_state_t
</a></li>
324 <li><a href=
"#cups_sc_status_t" title=
"Response status codes">cups_sc_status_t
</a></li>
325 <li><a href=
"#cups_sc_walk_func_t" title=
"SNMP walk callback">cups_sc_walk_func_t
</a></li>
327 <li><a href=
"#ENUMERATIONS">Constants
</a><ul class=
"code">
328 <li><a href=
"#cups_backend_e" title=
"Backend exit codes">cups_backend_e
</a></li>
329 <li><a href=
"#cups_sc_bidi_e" title=
"Bidirectional capability values">cups_sc_bidi_e
</a></li>
330 <li><a href=
"#cups_sc_command_e" title=
"Request command codes">cups_sc_command_e
</a></li>
331 <li><a href=
"#cups_sc_state_e" title=
"Printer state bits">cups_sc_state_e
</a></li>
332 <li><a href=
"#cups_sc_status_e" title=
"Response status codes">cups_sc_status_e
</a></li>
336 "$Id: api-filter.shtml 7594 2008-05-19 23:16:03Z mike $"
338 Filter and backend programming introduction for the Common UNIX Printing
341 Copyright 2007-2008 by Apple Inc.
342 Copyright 1997-2006 by Easy Software Products, all rights reserved.
344 These coded instructions, statements, and computer programs are the
345 property of Apple Inc. and are protected by Federal copyright
346 law. Distribution and use rights are outlined in the file "LICENSE.txt"
347 which should have been included with this file. If this file is
348 file is missing or damaged, see the license at "http://www.cups.org/".
351 <h2 class='title'
><a name=
"OVERVIEW">Overview
</a></h2>
353 <p>Filters (which include printer drivers and port monitors) and backends
354 are used to convert job files to a printable format and send that data to the
355 printer itself. All of these programs use a common interface for processing
356 print jobs and communicating status information to the scheduler. Each is run
357 with a standard set of command-line arguments:
<p>
365 <dd>The user printing the job
</dd>
368 <dd>The job name/title
</dd>
371 <dd>The number of copies to print
</dd>
374 <dd>The options that were provided when the job was submitted
</dd>
377 <dd>The file to print (first program only)
</dd>
380 <p>The scheduler runs one or more of these programs to print any given job. The
381 first filter reads from the print file and writes to the standard output, while
382 the remaining filters read from the standard input and write to the standard
383 output. The backend is the last filter in the chain and writes to the
386 <h3><a name=
"SECURITY">Security Considerations
</a></h3>
388 <p>It is always important to use security programming practices. Filters and
389 most backends are run as a non-priviledged user, so the major security
390 consideration is resource utilization - filters should not depend on unlimited
391 amounts of CPU, memory, or disk space, and should protect against conditions
392 that could lead to excess usage of any resource like infinite loops and
393 unbounded recursion. In addition, filters must
<em>never
</em> allow the user to
394 specify an arbitrary file path to a separator page, template, or other file
395 used by the filter since that can lead to an unauthorized disclosure of
396 information.
<em>Always
</em> treat input as suspect and validate it!
</p>
398 <p>If you are developing a backend that runs as root, make sure to check for
399 potential buffer overflows, integer under/overflow conditions, and file
400 accesses since these can lead to privilege escalations. When writing files,
401 always validate the file path and
<em>never
</em> allow a user to determine
402 where to store a file.
</p>
404 <blockquote><b>Note:
</b>
406 <p><em>Never
</em> write files to a user's home directory. Aside from the
407 security implications, CUPS is a network print service and as such the network
408 user may not be the same as the local user and/or there may not be a local home
409 directory to write to.
</p>
411 <p>In addition, some operating systems provide additional security mechanisms
412 that further limit file system access, even for backends running as root. On
413 Mac OS X, for example, no backend may write to a user's home directory.
</p>
416 <h3><a name=
"TEMPFILES">Temporary Files
</a></h3>
418 <p>Temporary files should be created in the directory specified by the
419 "TMPDIR" environment variable. The
420 <a href=
"#cupsTempFile2"><code>cupsTempFile2
</code></a> function can be
421 used to safely create temporary files in this directory.
</p>
423 <h3><a name=
"COPIES">Copy Generation
</a></h3>
425 <p>The
<code>argv[
4]
</code> argument specifies the number of copies to produce
426 of the input file. In general, you should only generate copies if the
427 <em>filename
</em> argument is supplied. The only exception to this are
428 filters that produce device-independent PostScript output, since the PostScript
429 filter
<var>pstops
</var> is responsible for generating copies of PostScript
432 <h3><a name=
"EXITCODES">Exit Codes
</a></h3>
434 <p>Filters must exit with status
0 when they successfully generate print data
435 or
1 when they encounter an error. Backends can return any of the
436 <a href=
"#cups_backend_t"><code>cups_backend_t
</code></a> constants.
</p>
438 <h3><a name=
"ENVIRONMENT">Environment Variables
</a></h3>
440 <p>The following environment variables are defined by the printing system
441 when running print filters and backends:
</p>
445 <dt>APPLE_LANGUAGES
</dt>
446 <dd>The Apple language identifier associated with the job
447 (Mac OS X only).
</dd>
450 <dd>The job character set, typically
"utf-8".
</dd>
453 <dd>When a job is submitted to a printer class, contains the name of
454 the destination printer class. Otherwise this environment
455 variable will not be set.
</dd>
457 <dt>CONTENT_TYPE
</dt>
458 <dd>The MIME type associated with the file (e.g.
459 application/postscript).
</dd>
461 <dt>CUPS_CACHEDIR
</dt>
462 <dd>The directory where cache files can be stored. Cache files can be
463 used to retain information between jobs or files in a job.
</dd>
465 <dt>CUPS_DATADIR
</dt>
466 <dd>The directory where (read-only) CUPS data files can be found.
</dd>
468 <dt>CUPS_SERVERROOT
</dt>
469 <dd>The root directory of the server.
</dd>
472 <dd>The device-uri associated with the printer.
</dd>
474 <dt>FINAL_CONTENT_TYPE
</dt>
475 <dd>The MIME type associated with the printer (e.g.
476 application/vnd.cups-postscript).
</dd>
479 <dd>The language locale associated with the job.
</dd>
482 <dd>The full pathname of the PostScript Printer Description (PPD)
483 file for this printer.
</dd>
486 <dd>The queue name of the class or printer.
</dd>
489 <dd>The recommended amount of memory to use for Raster Image
490 Processors (RIPs).
</dd>
493 <dd>The directory where temporary files should be created.
</dd>
497 <h3><a name=
"MESSAGES">Communicating with the Scheduler
</a></h3>
499 <p>Filters and backends communicate with the scheduler by writing messages
500 to the standard error file. The scheduler reads messages from all filters in
501 a job and processes the message based on its prefix. For example, the following
502 code sets the current printer state message to
"Printing page 5":
</p>
504 <pre class=
"example">
507 fprintf(stderr,
"INFO: Printing page %d\n", page);
510 <p>Each message is a single line of text starting with one of the following
515 <dt>ALERT: message
</dt>
516 <dd>Sets the printer-state-message attribute and adds the specified
517 message to the current error log file using the
"alert" log level.
</dd>
519 <dt>ATTR: attribute=value [attribute=value]
</dt>
520 <dd>Sets the named printer or job attribute(s). Typically this is used
521 to set the
<code>marker-colors
</code>,
<code>marker-levels
</code>,
522 <code>marker-names
</code>,
<code>marker-types
</code>,
523 <code>printer-alert
</code>, and
<code>printer-alert-description
</code>
524 printer attributes. Standard
<code>marker-types
</code> values are
525 listed in
<a href='#TABLE1'
>Table
1</a>.
</dd>
527 <dt>CRIT: message
</dt>
528 <dd>Sets the printer-state-message attribute and adds the specified
529 message to the current error log file using the
"critical" log
532 <dt>DEBUG: message
</dt>
533 <dd>Sets the printer-state-message attribute and adds the specified
534 message to the current error log file using the
"debug" log level.
</dd>
536 <dt>DEBUG2: message
</dt>
537 <dd>Sets the printer-state-message attribute and adds the specified
538 message to the current error log file using the
"debug2" log level.
</dd>
540 <dt>EMERG: message
</dt>
541 <dd>Sets the printer-state-message attribute and adds the specified
542 message to the current error log file using the
"emergency" log
545 <dt>ERROR: message
</dt>
546 <dd>Sets the printer-state-message attribute and adds the specified
547 message to the current error log file using the
"error" log level.
548 Use
"ERROR:" messages for non-persistent processing errors.
</dd>
550 <dt>INFO: message
</dt>
551 <dd>Sets the printer-state-message attribute. If the current log level
552 is set to
"debug2", also adds the specified message to the current error
553 log file using the
"info" log level.
</dd>
555 <dt>NOTICE: message
</dt>
556 <dd>Sets the printer-state-message attribute and adds the specified
557 message to the current error log file using the
"notice" log level.
</dd>
559 <dt>PAGE: page-number #-copies
</dt>
560 <dt>PAGE: total #-pages
</dt>
561 <dd>Adds an entry to the current page log file. The first form adds
562 #-copies to the job-media-sheets-completed attribute. The second
563 form sets the job-media-sheets-completed attribute to #-pages.
</dd>
565 <dt>PPD: keyword=value [keyword=value ...]
</dt>
566 <dd>Changes or adds keywords to the printer's PPD file. Typically
567 this is used to update installable options or default media settings
568 based on the printer configuration.
</dd>
570 <dt>STATE: printer-state-reason [printer-state-reason ...]
</dt>
571 <dt>STATE: + printer-state-reason [printer-state-reason ...]
</dt>
572 <dt>STATE: - printer-state-reason [printer-state-reason ...]
</dt>
573 <dd>Sets, adds, or removes printer-state-reason keywords to the
574 current queue. Typically this is used to indicate persistent media,
575 ink, toner, and configuration conditions or errors on a printer.
576 <a href='#TABLE2'
>Table
2</a> lists the standard state keywords -
577 use vendor-prefixed (
"com.acme.foo") keywords for custom states.
</dd>
579 <dt>WARNING: message
</dt>
580 <dd>Sets the printer-state-message attribute and adds the specified
581 message to the current error log file using the
"warning" log
586 <p>Messages without one of these prefixes are treated as if they began with
587 the
"DEBUG:" prefix string.
</p>
590 <div class='table'
><table width='
80%' summary='Table
1: Standard marker-types Values'
>
591 <caption>Table
1:
<a name='TABLE1'
>Standard marker-types Values
</a></caption>
601 <td>Developer unit
</td>
608 <td>fuserCleaningPad
</td>
609 <td>Fuser cleaning pad
</td>
621 <td>Photo conductor
</td>
629 <td>Staple supply
</td>
633 <td>Toner supply
</td>
636 <td>transferUnit
</td>
637 <td>Transfer unit
</td>
641 <td>Waste ink tank
</td>
645 <td>Waste toner tank
</td>
649 <td>Waste wax tank
</td>
656 <div class='table'
><table width='
80%' summary='Table
2: Standard State Keywords'
>
657 <caption>Table
2:
<a name='TABLE2'
>Standard State Keywords
</a></caption>
666 <td>connecting-to-device
</td>
667 <td>Connecting to printer but not printing yet
</td>
671 <td>A cover is open on the printer
</td>
674 <td>input-tray-missing
</td>
675 <td>An input tray is missing from the printer
</td>
678 <td>marker-supply-empty
</td>
682 <td>marker-supply-low
</td>
686 <td>marker-waste-almost-full
</td>
687 <td>Waste tank almost full
</td>
690 <td>marker-waste-full
</td>
691 <td>Waste tank full
</td>
695 <td>Out of media
</td>
699 <td>Media is jammed in the printer
</td>
703 <td>Low on media
</td>
707 <td>Stop the printer
</td>
711 <td>Unable to connect to printer
</td>
715 <td>Out of toner
</td>
719 <td>Low on toner
</td>
724 <h3><a name=
"COMMUNICATING_BACKEND">Communicating with the Backend
</a></h3>
726 <p>Filters can communicate with the backend via the
727 <a href=
"#cupsBackChannelRead"><code>cupsBackChannelRead
</code></a> and
728 <a href=
"#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest
</code></a>
730 <a href=
"#cupsBackChannelRead"><code>cupsBackChannelRead
</code></a> function
731 reads data that has been sent back from the device and is typically used to
732 obtain status and configuration information. For example, the following code
733 polls the backend for back-channel data:
</p>
735 <pre class=
"example">
736 #include
<cups/cups.h
>
741 /* Use a timeout of
0.0 seconds to poll for back-channel data */
742 bytes = cupsBackChannelRead(buffer, sizeof(buffer),
0.0);
745 <p>Filters can also use
<code>select()
</code> or
<code>poll()
</code> on the
746 back-channel file descriptor (
3 or
<code>CUPS_BC_FD
</code>) to read data only
747 when it is available.
</p>
750 <a href=
"#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest
</code></a>
751 function allows you to get out-of-band status information and do synchronization
752 with the device. For example, the following code gets the current IEEE-
1284
753 device ID string from the backend:
</p>
755 <pre class=
"example">
756 #include
<cups/sidechannel.h
>
760 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> status;
762 /* Tell cupsSideChannelDoRequest() how big our buffer is, less
1 byte for
763 nul-termination... */
764 datalen = sizeof(data) -
1;
766 /* Get the IEEE-
1284 device ID, waiting for up to
1 second */
767 status =
<a href=
"#cupsSideChannelDoRequest">cupsSideChannelDoRequest
</a>(CUPS_SC_CMD_GET_DEVICE_ID, data,
&datalen,
1.0);
769 /* Use the returned value if OK was returned and the length is non-zero */
770 if (status == CUPS_SC_STATUS_OK && datalen
> 0)
771 data[datalen] = '\
0';
776 <h3><a name=
"COMMUNICATING_FILTER">Communicating with Filters
</a></h3>
778 <p>Backends communicate with filters using the reciprocal functions
779 <a href=
"#cupsBackChannelWrite"><code>cupsBackChannelWrite
</code></a>,
780 <a href=
"#cupsSideChannelRead"><code>cupsSideChannelRead
</code></a>, and
781 <a href=
"#cupsSideChannelWrite"><code>cupsSideChannelWrite
</code></a>. We
782 recommend writing back-channel data using a timeout of
1.0 seconds:
</p>
784 <pre class=
"example">
785 #include
<cups/cups.h
>
790 /* Obtain data from printer/device */
793 /* Use a timeout of
1.0 seconds to give filters a chance to read */
794 cupsBackChannelWrite(buffer, bytes,
1.0);
797 <p>The
<a href=
"#cupsSideChannelRead"><code>cupsSideChannelRead
</code></a>
798 function reads a side-channel command from a filter, driver, or port monitor.
799 Backends can either poll for commands using a
<code>timeout
</code> of
0.0, wait
800 indefinitely for commands using a
<code>timeout
</code> of -
1.0 (probably in a
801 separate thread for that purpose), or use
<code>select
</code> or
802 <code>poll
</code> on the
<code>CUPS_SC_FD
</code> file descriptor (
4) to handle
803 input and output on several file descriptors at the same time.
</p>
805 <p>Once a command is processed, the backend uses the
806 <a href=
"#cupsSideChannelWrite"><code>cupsSideChannelWrite
</code></a> function
807 to send its response. For example, the following code shows how to poll for a
808 side-channel command and respond to it:
</p>
810 <pre class=
"example">
811 #include
<cups/sidechannel.h
>
813 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> command;
814 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> status;
816 int datalen = sizeof(data);
818 /* Poll for a command... */
819 if (!
<a href=
"#cupsSideChannelRead">cupsSideChannelRead
</a>(
&command,
&status, data,
&datalen,
0.0))
823 /* handle supported commands, fill data/datalen/status with values as needed */
826 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
831 /* Send a response... */
832 <a href=
"#cupsSideChannelWrite">cupsSideChannelWrite
</a>(command, status, data, datalen,
1.0);
836 <h3><a name=
"SNMP">Doing SNMP Queries with Network Printers
</a></h3>
838 <p>The Simple Network Management Protocol (SNMP) allows you to get the current
839 status, page counter, and supply levels from most network printers. Every
840 piece of information is associated with an Object Identifier (OID), and
841 every printer has a
<em>community
</em> name associated with it. OIDs can be
842 queried directly or by
"walking" over a range of OIDs with a common prefix.
</p>
844 <p>The two CUPS SNMP functions provide a simple API for querying network
845 printers through the side-channel interface. Each accepts a string containing
846 an OID like
".1.3.6.1.2.1.43.10.2.1.4.1.1" (the standard page counter OID)
847 along with a timeout for the query.
</p>
849 <p>The
<a href=
"#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet
</code></a>
850 function queries a single OID and returns the value as a string in a buffer
853 <pre class=
"example">
854 #include
<cups/sidechannel.h
>
857 int datalen = sizeof(data);
859 if (
<a href=
"#cupsSideChannelSNMPGet">cupsSideChannelSNMPGet
</a>(
".1.3.6.1.2.1.43.10.2.1.4.1.1", data,
&datalen,
5.0)
860 == CUPS_SC_STATUS_OK)
862 /* Do something with the value */
863 printf(
"Page counter is: %s\n", data);
868 <a href=
"#cupsSideChannelSNMPWalk"><code>cupsSideChannelSNMPWalk
</code></a>
869 function allows you to query a whole group of OIDs, calling a function of your
870 choice for each OID that is found:
</p>
872 <pre class=
"example">
873 #include
<cups/sidechannel.h
>
876 my_callback(const char *oid, const char *data, int datalen, void *context)
878 /* Do something with the value */
879 printf(
"%s=%s\n", oid, data);
886 <a href=
"#cupsSideChannelSNMPWalk">cupsSNMPSideChannelWalk
</a>(
".1.3.6.1.2.1.43",
5.0, my_callback, my_data);
888 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
889 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsBackChannelRead">cupsBackChannelRead
</a></h3>
890 <p class=
"description">Read data from the backchannel.
</p>
892 ssize_t cupsBackChannelRead (
<br>
893 char *buffer,
<br>
894 size_t bytes,
<br>
895 double timeout
<br>
897 <h4 class=
"parameters">Parameters
</h4>
900 <dd class=
"description">Buffer to read into
</dd>
902 <dd class=
"description">Bytes to read
</dd>
904 <dd class=
"description">Timeout in seconds, typically
0.0 to poll
</dd>
906 <h4 class=
"returnvalue">Return Value
</h4>
907 <p class=
"description">Bytes read or -
1 on error
</p>
908 <h4 class=
"discussion">Discussion
</h4>
909 <p class=
"discussion">Reads up to
"bytes
" bytes from the backchannel/backend. The
"timeout
"
910 parameter controls how many seconds to wait for the data - use
0.0 to
911 return immediately if there is no data, -
1.0 to wait for data indefinitely.
914 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsBackChannelWrite">cupsBackChannelWrite
</a></h3>
915 <p class=
"description">Write data to the backchannel.
</p>
917 ssize_t cupsBackChannelWrite (
<br>
918 const char *buffer,
<br>
919 size_t bytes,
<br>
920 double timeout
<br>
922 <h4 class=
"parameters">Parameters
</h4>
925 <dd class=
"description">Buffer to write
</dd>
927 <dd class=
"description">Bytes to write
</dd>
929 <dd class=
"description">Timeout in seconds, typically
1.0</dd>
931 <h4 class=
"returnvalue">Return Value
</h4>
932 <p class=
"description">Bytes written or -
1 on error
</p>
933 <h4 class=
"discussion">Discussion
</h4>
934 <p class=
"discussion">Writes
"bytes
" bytes to the backchannel/filter. The
"timeout
" parameter
935 controls how many seconds to wait for the data to be written - use
936 0.0 to return immediately if the data cannot be written, -
1.0 to wait
940 <h3 class=
"function"><a name=
"cupsBackendDeviceURI">cupsBackendDeviceURI
</a></h3>
941 <p class=
"description">Get the device URI for a backend.
</p>
943 const char *cupsBackendDeviceURI (
<br>
944 char **argv
<br>
946 <h4 class=
"parameters">Parameters
</h4>
949 <dd class=
"description">Command-line arguments
</dd>
951 <h4 class=
"returnvalue">Return Value
</h4>
952 <p class=
"description">Device URI or
<code>NULL
</code></p>
953 <h4 class=
"discussion">Discussion
</h4>
954 <p class=
"discussion">The
"argv
" argument is the argv argument passed to main(). This
955 function returns the device URI passed in the DEVICE_URI environment
956 variable or the device URI passed in argv[
0], whichever is found
958 <h3 class=
"function"><span class=
"info"> CUPS
1.3 </span><a name=
"cupsSideChannelDoRequest">cupsSideChannelDoRequest
</a></h3>
959 <p class=
"description">Send a side-channel command to a backend and wait for a response.
</p>
961 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> cupsSideChannelDoRequest (
<br>
962 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> command,
<br>
963 char *data,
<br>
964 int *datalen,
<br>
965 double timeout
<br>
967 <h4 class=
"parameters">Parameters
</h4>
970 <dd class=
"description">Command to send
</dd>
972 <dd class=
"description">Response data buffer pointer
</dd>
974 <dd class=
"description">Size of data buffer on entry, number of bytes in buffer on return
</dd>
976 <dd class=
"description">Timeout in seconds
</dd>
978 <h4 class=
"returnvalue">Return Value
</h4>
979 <p class=
"description">Status of command
</p>
980 <h4 class=
"discussion">Discussion
</h4>
981 <p class=
"discussion">This function is normally only called by filters, drivers, or port
982 monitors in order to communicate with the backend used by the current
983 printer. Programs must be prepared to handle timeout or
"not
984 implemented
" status codes, which indicate that the backend or device
985 do not support the specified side-channel command.
<br>
987 The
"datalen
" parameter must be initialized to the size of the buffer
988 pointed to by the
"data
" parameter. cupsSideChannelDoRequest() will
989 update the value to contain the number of data bytes in the buffer.
992 <h3 class=
"function"><span class=
"info"> CUPS
1.3 </span><a name=
"cupsSideChannelRead">cupsSideChannelRead
</a></h3>
993 <p class=
"description">Read a side-channel message.
</p>
995 int cupsSideChannelRead (
<br>
996 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> *command,
<br>
997 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> *status,
<br>
998 char *data,
<br>
999 int *datalen,
<br>
1000 double timeout
<br>
1002 <h4 class=
"parameters">Parameters
</h4>
1005 <dd class=
"description">Command code
</dd>
1007 <dd class=
"description">Status code
</dd>
1009 <dd class=
"description">Data buffer pointer
</dd>
1011 <dd class=
"description">Size of data buffer on entry, number of bytes in buffer on return
</dd>
1013 <dd class=
"description">Timeout in seconds
</dd>
1015 <h4 class=
"returnvalue">Return Value
</h4>
1016 <p class=
"description">0 on success, -
1 on error
</p>
1017 <h4 class=
"discussion">Discussion
</h4>
1018 <p class=
"discussion">This function is normally only called by backend programs to read
1019 commands from a filter, driver, or port monitor program. The
1020 caller must be prepared to handle incomplete or invalid messages
1021 and return the corresponding status codes.
<br>
1023 The
"datalen
" parameter must be initialized to the size of the buffer
1024 pointed to by the
"data
" parameter. cupsSideChannelDoRequest() will
1025 update the value to contain the number of data bytes in the buffer.
1028 <h3 class=
"function"><span class=
"info"> CUPS
1.4 </span><a name=
"cupsSideChannelSNMPGet">cupsSideChannelSNMPGet
</a></h3>
1029 <p class=
"description">Query a SNMP OID's value.
</p>
1031 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> cupsSideChannelSNMPGet (
<br>
1032 const char *oid,
<br>
1033 char *data,
<br>
1034 int *datalen,
<br>
1035 double timeout
<br>
1037 <h4 class=
"parameters">Parameters
</h4>
1040 <dd class=
"description">OID to query
</dd>
1042 <dd class=
"description">Buffer for OID value
</dd>
1044 <dd class=
"description">Size of OID buffer on entry, size of value on return
</dd>
1046 <dd class=
"description">Timeout in seconds
</dd>
1048 <h4 class=
"returnvalue">Return Value
</h4>
1049 <p class=
"description">Query status
</p>
1050 <h4 class=
"discussion">Discussion
</h4>
1051 <p class=
"discussion">This function asks the backend to do a SNMP OID query on behalf of the
1052 filter, port monitor, or backend using the default community name.
<br>
1054 "oid
" contains a numeric OID consisting of integers separated by periods,
1055 for example
".1.3.6.1.2.1.43". Symbolic names from SNMP MIBs are not
1056 supported and must be converted to their numeric forms.
<br>
1058 On input,
"data
" and
"datalen
" provide the location and size of the
1059 buffer to hold the OID value as a string. HEX-String (binary) values are
1060 converted to hexadecimal strings representing the binary data, while
1061 NULL-Value and unknown OID types are returned as the empty string.
1062 The returned
"datalen
" does not include the trailing nul.
1064 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED
</code> is returned by backends that do not
1065 support SNMP queries.
<code>CUPS_SC_STATUS_NO_RESPONSE
</code> is returned when
1066 the printer does not respond to the SNMP query.
1069 <h3 class=
"function"><span class=
"info"> CUPS
1.4 </span><a name=
"cupsSideChannelSNMPWalk">cupsSideChannelSNMPWalk
</a></h3>
1070 <p class=
"description">Query multiple SNMP OID values.
</p>
1072 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> cupsSideChannelSNMPWalk (
<br>
1073 const char *oid,
<br>
1074 double timeout,
<br>
1075 <a href=
"#cups_sc_walk_func_t">cups_sc_walk_func_t
</a> cb,
<br>
1076 void *context
<br>
1078 <h4 class=
"parameters">Parameters
</h4>
1081 <dd class=
"description">First numeric OID to query
</dd>
1083 <dd class=
"description">Timeout for each query in seconds
</dd>
1085 <dd class=
"description">Function to call with each value
</dd>
1087 <dd class=
"description">Application-defined pointer to send to callback
</dd>
1089 <h4 class=
"returnvalue">Return Value
</h4>
1090 <p class=
"description">Status of first query of
<code>CUPS_SC_STATUS_OK
</code> on success
</p>
1091 <h4 class=
"discussion">Discussion
</h4>
1092 <p class=
"discussion">This function asks the backend to do multiple SNMP OID queries on behalf
1093 of the filter, port monitor, or backend using the default community name.
1094 All OIDs under the
"parent
" OID are queried and the results are sent to
1095 the callback function you provide.
<br>
1097 "oid
" contains a numeric OID consisting of integers separated by periods,
1098 for example
".1.3.6.1.2.1.43". Symbolic names from SNMP MIBs are not
1099 supported and must be converted to their numeric forms.
<br>
1101 "timeout
" specifies the timeout for each OID query. The total amount of
1102 time will depend on the number of OID values found and the time required
1105 "cb
" provides a function to call for every value that is found.
"context
"
1106 is an application-defined pointer that is sent to the callback function
1107 along with the OID and current data. The data passed to the callback is the
1108 same as returned by
<a href=
"#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet
</code></a>.
1110 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED
</code> is returned by backends that do not
1111 support SNMP queries.
<code>CUPS_SC_STATUS_NO_RESPONSE
</code> is returned when
1112 the printer does not respond to the first SNMP query.
1115 <h3 class=
"function"><span class=
"info"> CUPS
1.3 </span><a name=
"cupsSideChannelWrite">cupsSideChannelWrite
</a></h3>
1116 <p class=
"description">Write a side-channel message.
</p>
1118 int cupsSideChannelWrite (
<br>
1119 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> command,
<br>
1120 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> status,
<br>
1121 const char *data,
<br>
1122 int datalen,
<br>
1123 double timeout
<br>
1125 <h4 class=
"parameters">Parameters
</h4>
1128 <dd class=
"description">Command code
</dd>
1130 <dd class=
"description">Status code
</dd>
1132 <dd class=
"description">Data buffer pointer
</dd>
1134 <dd class=
"description">Number of bytes of data
</dd>
1136 <dd class=
"description">Timeout in seconds
</dd>
1138 <h4 class=
"returnvalue">Return Value
</h4>
1139 <p class=
"description">0 on success, -
1 on error
</p>
1140 <h4 class=
"discussion">Discussion
</h4>
1141 <p class=
"discussion">This function is normally only called by backend programs to send
1142 responses to a filter, driver, or port monitor program.
1145 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
1146 <h3 class=
"typedef"><a name=
"cups_backend_t">cups_backend_t
</a></h3>
1147 <p class=
"description">Backend exit codes
</p>
1149 typedef enum
<a href=
"#cups_backend_e">cups_backend_e
</a> cups_backend_t;
1151 <h3 class=
"typedef"><a name=
"cups_sc_bidi_t">cups_sc_bidi_t
</a></h3>
1152 <p class=
"description">Bidirectional capabilities
</p>
1154 typedef enum
<a href=
"#cups_sc_bidi_e">cups_sc_bidi_e
</a> cups_sc_bidi_t;
1156 <h3 class=
"typedef"><a name=
"cups_sc_command_t">cups_sc_command_t
</a></h3>
1157 <p class=
"description">Request command codes
</p>
1159 typedef enum
<a href=
"#cups_sc_command_e">cups_sc_command_e
</a> cups_sc_command_t;
1161 <h3 class=
"typedef"><a name=
"cups_sc_state_t">cups_sc_state_t
</a></h3>
1162 <p class=
"description">Printer state bits
</p>
1164 typedef enum
<a href=
"#cups_sc_state_e">cups_sc_state_e
</a> cups_sc_state_t;
1166 <h3 class=
"typedef"><a name=
"cups_sc_status_t">cups_sc_status_t
</a></h3>
1167 <p class=
"description">Response status codes
</p>
1169 typedef enum
<a href=
"#cups_sc_status_e">cups_sc_status_e
</a> cups_sc_status_t;
1171 <h3 class=
"typedef"><a name=
"cups_sc_walk_func_t">cups_sc_walk_func_t
</a></h3>
1172 <p class=
"description">SNMP walk callback
</p>
1174 typedef void (*cups_sc_walk_func_t)(const char *oid, const char *data, int datalen, void *context);
1176 <h2 class=
"title"><a name=
"ENUMERATIONS">Constants
</a></h2>
1177 <h3 class=
"enumeration"><a name=
"cups_backend_e">cups_backend_e
</a></h3>
1178 <p class=
"description">Backend exit codes
</p>
1179 <h4 class=
"constants">Constants
</h4>
1181 <dt>CUPS_BACKEND_AUTH_REQUIRED
</dt>
1182 <dd class=
"description">Job failed, authentication required
</dd>
1183 <dt>CUPS_BACKEND_CANCEL
</dt>
1184 <dd class=
"description">Job failed, cancel job
</dd>
1185 <dt>CUPS_BACKEND_FAILED
</dt>
1186 <dd class=
"description">Job failed, use error-policy
</dd>
1187 <dt>CUPS_BACKEND_HOLD
</dt>
1188 <dd class=
"description">Job failed, hold job
</dd>
1189 <dt>CUPS_BACKEND_OK
</dt>
1190 <dd class=
"description">Job completed successfully
</dd>
1191 <dt>CUPS_BACKEND_STOP
</dt>
1192 <dd class=
"description">Job failed, stop queue
</dd>
1194 <h3 class=
"enumeration"><a name=
"cups_sc_bidi_e">cups_sc_bidi_e
</a></h3>
1195 <p class=
"description">Bidirectional capability values
</p>
1196 <h4 class=
"constants">Constants
</h4>
1198 <dt>CUPS_SC_BIDI_NOT_SUPPORTED
</dt>
1199 <dd class=
"description">Bidirectional I/O is not supported
</dd>
1200 <dt>CUPS_SC_BIDI_SUPPORTED
</dt>
1201 <dd class=
"description">Bidirectional I/O is supported
</dd>
1203 <h3 class=
"enumeration"><a name=
"cups_sc_command_e">cups_sc_command_e
</a></h3>
1204 <p class=
"description">Request command codes
</p>
1205 <h4 class=
"constants">Constants
</h4>
1207 <dt>CUPS_SC_CMD_DRAIN_OUTPUT
</dt>
1208 <dd class=
"description">Drain all pending output
</dd>
1209 <dt>CUPS_SC_CMD_GET_BIDI
</dt>
1210 <dd class=
"description">Return bidirectional capabilities
</dd>
1211 <dt>CUPS_SC_CMD_GET_DEVICE_ID
</dt>
1212 <dd class=
"description">Return the IEEE-
1284 device ID
</dd>
1213 <dt>CUPS_SC_CMD_GET_STATE
</dt>
1214 <dd class=
"description">Return the device state
</dd>
1215 <dt>CUPS_SC_CMD_SNMP_GET
<span class=
"info"> CUPS
1.4 </span></dt>
1216 <dd class=
"description">Query an SNMP OID
</dd>
1217 <dt>CUPS_SC_CMD_SNMP_GET_NEXT
<span class=
"info"> CUPS
1.4 </span></dt>
1218 <dd class=
"description">Query the next SNMP OID
</dd>
1219 <dt>CUPS_SC_CMD_SOFT_RESET
</dt>
1220 <dd class=
"description">Do a soft reset
</dd>
1222 <h3 class=
"enumeration"><a name=
"cups_sc_state_e">cups_sc_state_e
</a></h3>
1223 <p class=
"description">Printer state bits
</p>
1224 <h4 class=
"constants">Constants
</h4>
1226 <dt>CUPS_SC_STATE_BUSY
</dt>
1227 <dd class=
"description">Device is busy
</dd>
1228 <dt>CUPS_SC_STATE_ERROR
</dt>
1229 <dd class=
"description">Other error condition
</dd>
1230 <dt>CUPS_SC_STATE_MARKER_EMPTY
</dt>
1231 <dd class=
"description">Toner/ink out condition
</dd>
1232 <dt>CUPS_SC_STATE_MARKER_LOW
</dt>
1233 <dd class=
"description">Toner/ink low condition
</dd>
1234 <dt>CUPS_SC_STATE_MEDIA_EMPTY
</dt>
1235 <dd class=
"description">Paper out condition
</dd>
1236 <dt>CUPS_SC_STATE_MEDIA_LOW
</dt>
1237 <dd class=
"description">Paper low condition
</dd>
1238 <dt>CUPS_SC_STATE_OFFLINE
</dt>
1239 <dd class=
"description">Device is offline
</dd>
1240 <dt>CUPS_SC_STATE_ONLINE
</dt>
1241 <dd class=
"description">Device is online
</dd>
1243 <h3 class=
"enumeration"><a name=
"cups_sc_status_e">cups_sc_status_e
</a></h3>
1244 <p class=
"description">Response status codes
</p>
1245 <h4 class=
"constants">Constants
</h4>
1247 <dt>CUPS_SC_STATUS_BAD_MESSAGE
</dt>
1248 <dd class=
"description">The command/response message was invalid
</dd>
1249 <dt>CUPS_SC_STATUS_IO_ERROR
</dt>
1250 <dd class=
"description">An I/O error occurred
</dd>
1251 <dt>CUPS_SC_STATUS_NONE
</dt>
1252 <dd class=
"description">No status
</dd>
1253 <dt>CUPS_SC_STATUS_NOT_IMPLEMENTED
</dt>
1254 <dd class=
"description">Command not implemented
</dd>
1255 <dt>CUPS_SC_STATUS_NO_RESPONSE
</dt>
1256 <dd class=
"description">The device did not respond
</dd>
1257 <dt>CUPS_SC_STATUS_OK
</dt>
1258 <dd class=
"description">Operation succeeded
</dd>
1259 <dt>CUPS_SC_STATUS_TIMEOUT
</dt>
1260 <dd class=
"description">The backend did not respond
</dd>
1261 <dt>CUPS_SC_STATUS_TOO_BIG
</dt>
1262 <dd class=
"description">Response too big
</dd>