1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/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.6">
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;
41 border: dotted thin #999999;
46 PRE.command EM, PRE.example EM {
47 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
51 font-family: monaco, courier, monospace;
62 border: solid thin #999999;
73 -moz-border-radius: 10px;
78 text-decoration: none;
81 A:link:hover, A:visited:hover, A:active {
82 text-decoration: underline;
89 TR.data, TD.data, TR.data TD {
92 border-bottom: solid 1pt #999999;
96 border-bottom: solid 1pt #999999;
103 border: solid thin #999999;
104 border-collapse: collapse;
120 border: solid thin #cccccc;
127 border-bottom: solid thin #999999;
136 caption-side: bottom;
160 border: thin solid black;
168 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
174 border-bottom: solid 2pt #000000;
177 DIV.indent, TABLE.indent {
185 border-collapse: collapse;
188 TABLE.indent TD, TABLE.indent TH {
193 border-collapse: collapse;
201 border-bottom: solid thin #cccccc;
206 vertical-align: bottom;
215 border-bottom: solid thin #eeeeee;
220 TABLE.list TR:nth-child(even) {
224 TABLE.list TR:nth-child(odd) {
243 font-family: monaco, courier, monospace;
247 border: solid thin #999999;
248 border-collapse: collapse;
253 DIV.summary TABLE TD, DIV.summary TABLE TH {
254 border: solid thin #999999;
260 DIV.summary TABLE THEAD TH {
264 /* API documentation styles... */
271 div.body h3, div.body h4, div.body h5 {
272 margin-bottom: 0.5em;
275 .class, .enumeration, .function, .struct, .typedef, .union {
276 border-bottom: solid thin #999999;
283 code, p.code, pre, ul.code li {
284 font-family: monaco, courier, monospace;
287 ul.code, ul.contents, ul.subcontents {
288 list-style-type: none;
298 ul.contents li ul.code, ul.contents li ul.subcontents {
311 margin-bottom: 0.5em;
314 /* This is just for the HTML files generated with the framedhelp target */
317 border: solid thin black;
326 div.contents ul.contents {
329 div.contents ul.subcontents li {
338 "$Id: api-filter.header 8087 2008-10-27 21:37:05Z mike $"
340 Filter and backend programming header for the Common UNIX Printing System
343 Copyright 2008 by Apple Inc.
345 These coded instructions, statements, and computer programs are the
346 property of Apple Inc. and are protected by Federal copyright
347 law. Distribution and use rights are outlined in the file "LICENSE.txt"
348 which should have been included with this file. If this file is
349 file is missing or damaged, see the license at "http://www.cups.org/".
352 <div class='summary'
><table summary='General Information'
>
356 <th>cups/backend.h
<br>
357 cups/sidechannel.h
</th>
367 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a><br>
368 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
369 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
370 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
371 Specifications:
<a href='spec-design' target='_top'
>CUPS Design Description
</a></td>
375 <h2 class=
"title">Contents
</h2>
376 <ul class=
"contents">
377 <ul class=
"subcontents">
378 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
379 <li><a href=
"#SECURITY">Security Considerations
</a></li>
380 <li><a href=
"#TEMPFILES">Temporary Files
</a></li>
381 <li><a href=
"#COPIES">Copy Generation
</a></li>
382 <li><a href=
"#EXITCODES">Exit Codes
</a></li>
383 <li><a href=
"#ENVIRONMENT">Environment Variables
</a></li>
384 <li><a href=
"#MESSAGES">Communicating with the Scheduler
</a></li>
385 <li><a href=
"#COMMUNICATING_BACKEND">Communicating with the Backend
</a></li>
386 <li><a href=
"#COMMUNICATING_FILTER">Communicating with Filters
</a></li>
387 <li><a href=
"#SNMP">Doing SNMP Queries with Network Printers
</a></li>
389 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
390 <li><a href=
"#cupsBackChannelRead" title=
"Read data from the backchannel.">cupsBackChannelRead
</a></li>
391 <li><a href=
"#cupsBackChannelWrite" title=
"Write data to the backchannel.">cupsBackChannelWrite
</a></li>
392 <li><a href=
"#cupsBackendDeviceURI" title=
"Get the device URI for a backend.">cupsBackendDeviceURI
</a></li>
393 <li><a href=
"#cupsBackendReport" title=
"Write a device line from a backend.">cupsBackendReport
</a></li>
394 <li><a href=
"#cupsSideChannelDoRequest" title=
"Send a side-channel command to a backend and wait for a response.">cupsSideChannelDoRequest
</a></li>
395 <li><a href=
"#cupsSideChannelRead" title=
"Read a side-channel message.">cupsSideChannelRead
</a></li>
396 <li><a href=
"#cupsSideChannelSNMPGet" title=
"Query a SNMP OID's value.">cupsSideChannelSNMPGet
</a></li>
397 <li><a href=
"#cupsSideChannelSNMPWalk" title=
"Query multiple SNMP OID values.">cupsSideChannelSNMPWalk
</a></li>
398 <li><a href=
"#cupsSideChannelWrite" title=
"Write a side-channel message.">cupsSideChannelWrite
</a></li>
400 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
401 <li><a href=
"#cups_backend_t" title=
"Backend exit codes">cups_backend_t
</a></li>
402 <li><a href=
"#cups_sc_bidi_t" title=
"Bidirectional capabilities">cups_sc_bidi_t
</a></li>
403 <li><a href=
"#cups_sc_command_t" title=
"Request command codes">cups_sc_command_t
</a></li>
404 <li><a href=
"#cups_sc_state_t" title=
"Printer state bits">cups_sc_state_t
</a></li>
405 <li><a href=
"#cups_sc_status_t" title=
"Response status codes">cups_sc_status_t
</a></li>
406 <li><a href=
"#cups_sc_walk_func_t" title=
"SNMP walk callback">cups_sc_walk_func_t
</a></li>
408 <li><a href=
"#ENUMERATIONS">Constants
</a><ul class=
"code">
409 <li><a href=
"#cups_backend_e" title=
"Backend exit codes">cups_backend_e
</a></li>
410 <li><a href=
"#cups_sc_bidi_e" title=
"Bidirectional capability values">cups_sc_bidi_e
</a></li>
411 <li><a href=
"#cups_sc_command_e" title=
"Request command codes">cups_sc_command_e
</a></li>
412 <li><a href=
"#cups_sc_state_e" title=
"Printer state bits">cups_sc_state_e
</a></li>
413 <li><a href=
"#cups_sc_status_e" title=
"Response status codes">cups_sc_status_e
</a></li>
416 "$Id: api-filter.shtml 7962 2008-09-18 17:31:33Z mike $"
418 Filter and backend programming introduction for the Common UNIX Printing
421 Copyright 2007-2008 by Apple Inc.
422 Copyright 1997-2006 by Easy Software Products, all rights reserved.
424 These coded instructions, statements, and computer programs are the
425 property of Apple Inc. and are protected by Federal copyright
426 law. Distribution and use rights are outlined in the file "LICENSE.txt"
427 which should have been included with this file. If this file is
428 file is missing or damaged, see the license at "http://www.cups.org/".
431 <h2 class='title'
><a name=
"OVERVIEW">Overview
</a></h2>
433 <p>Filters (which include printer drivers and port monitors) and backends
434 are used to convert job files to a printable format and send that data to the
435 printer itself. All of these programs use a common interface for processing
436 print jobs and communicating status information to the scheduler. Each is run
437 with a standard set of command-line arguments:
<p>
445 <dd>The user printing the job
</dd>
448 <dd>The job name/title
</dd>
451 <dd>The number of copies to print
</dd>
454 <dd>The options that were provided when the job was submitted
</dd>
457 <dd>The file to print (first program only)
</dd>
460 <p>The scheduler runs one or more of these programs to print any given job. The
461 first filter reads from the print file and writes to the standard output, while
462 the remaining filters read from the standard input and write to the standard
463 output. The backend is the last filter in the chain and writes to the
466 <h3><a name=
"SECURITY">Security Considerations
</a></h3>
468 <p>It is always important to use security programming practices. Filters and
469 most backends are run as a non-priviledged user, so the major security
470 consideration is resource utilization - filters should not depend on unlimited
471 amounts of CPU, memory, or disk space, and should protect against conditions
472 that could lead to excess usage of any resource like infinite loops and
473 unbounded recursion. In addition, filters must
<em>never
</em> allow the user to
474 specify an arbitrary file path to a separator page, template, or other file
475 used by the filter since that can lead to an unauthorized disclosure of
476 information.
<em>Always
</em> treat input as suspect and validate it!
</p>
478 <p>If you are developing a backend that runs as root, make sure to check for
479 potential buffer overflows, integer under/overflow conditions, and file
480 accesses since these can lead to privilege escalations. When writing files,
481 always validate the file path and
<em>never
</em> allow a user to determine
482 where to store a file.
</p>
484 <blockquote><b>Note:
</b>
486 <p><em>Never
</em> write files to a user's home directory. Aside from the
487 security implications, CUPS is a network print service and as such the network
488 user may not be the same as the local user and/or there may not be a local home
489 directory to write to.
</p>
491 <p>In addition, some operating systems provide additional security mechanisms
492 that further limit file system access, even for backends running as root. On
493 Mac OS X, for example, no backend may write to a user's home directory.
</p>
496 <h3><a name=
"TEMPFILES">Temporary Files
</a></h3>
498 <p>Temporary files should be created in the directory specified by the
499 "TMPDIR" environment variable. The
500 <a href=
"#cupsTempFile2"><code>cupsTempFile2
</code></a> function can be
501 used to safely create temporary files in this directory.
</p>
503 <h3><a name=
"COPIES">Copy Generation
</a></h3>
505 <p>The
<code>argv[
4]
</code> argument specifies the number of copies to produce
506 of the input file. In general, you should only generate copies if the
507 <em>filename
</em> argument is supplied. The only exception to this are
508 filters that produce device-independent PostScript output, since the PostScript
509 filter
<var>pstops
</var> is responsible for generating copies of PostScript
512 <h3><a name=
"EXITCODES">Exit Codes
</a></h3>
514 <p>Filters must exit with status
0 when they successfully generate print data
515 or
1 when they encounter an error. Backends can return any of the
516 <a href=
"#cups_backend_t"><code>cups_backend_t
</code></a> constants.
</p>
518 <h3><a name=
"ENVIRONMENT">Environment Variables
</a></h3>
520 <p>The following environment variables are defined by the printing system
521 when running print filters and backends:
</p>
525 <dt>APPLE_LANGUAGES
</dt>
526 <dd>The Apple language identifier associated with the job
527 (Mac OS X only).
</dd>
530 <dd>The job character set, typically
"utf-8".
</dd>
533 <dd>When a job is submitted to a printer class, contains the name of
534 the destination printer class. Otherwise this environment
535 variable will not be set.
</dd>
537 <dt>CONTENT_TYPE
</dt>
538 <dd>The MIME type associated with the file (e.g.
539 application/postscript).
</dd>
541 <dt>CUPS_CACHEDIR
</dt>
542 <dd>The directory where cache files can be stored. Cache files can be
543 used to retain information between jobs or files in a job.
</dd>
545 <dt>CUPS_DATADIR
</dt>
546 <dd>The directory where (read-only) CUPS data files can be found.
</dd>
548 <dt>CUPS_FILETYPE
</dt>
549 <dd>The type of file being printed:
"job-sheet" for a banner page and
550 "document" for a regular print file.
</dd>
552 <dt>CUPS_SERVERROOT
</dt>
553 <dd>The root directory of the server.
</dd>
556 <dd>The device-uri associated with the printer.
</dd>
558 <dt>FINAL_CONTENT_TYPE
</dt>
559 <dd>The MIME type associated with the printer (e.g.
560 application/vnd.cups-postscript).
</dd>
563 <dd>The language locale associated with the job.
</dd>
566 <dd>The full pathname of the PostScript Printer Description (PPD)
567 file for this printer.
</dd>
570 <dd>The queue name of the class or printer.
</dd>
573 <dd>The recommended amount of memory to use for Raster Image
574 Processors (RIPs).
</dd>
577 <dd>The directory where temporary files should be created.
</dd>
581 <h3><a name=
"MESSAGES">Communicating with the Scheduler
</a></h3>
583 <p>Filters and backends communicate with the scheduler by writing messages
584 to the standard error file. The scheduler reads messages from all filters in
585 a job and processes the message based on its prefix. For example, the following
586 code sets the current printer state message to
"Printing page 5":
</p>
588 <pre class=
"example">
591 fprintf(stderr,
"INFO: Printing page %d\n", page);
594 <p>Each message is a single line of text starting with one of the following
599 <dt>ALERT: message
</dt>
600 <dd>Sets the printer-state-message attribute and adds the specified
601 message to the current error log file using the
"alert" log level.
</dd>
603 <dt>ATTR: attribute=value [attribute=value]
</dt>
604 <dd>Sets the named printer or job attribute(s). Typically this is used
605 to set the
<code>marker-colors
</code>,
<code>marker-levels
</code>,
606 <code>marker-message
</code>,
<code>marker-names
</code>,
607 <code>marker-types
</code>,
<code>printer-alert
</code>, and
608 <code>printer-alert-description
</code> printer attributes. Standard
609 <code>marker-types
</code> values are listed in
<a href='#TABLE1'
>Table
612 <dt>CRIT: message
</dt>
613 <dd>Sets the printer-state-message attribute and adds the specified
614 message to the current error log file using the
"critical" log
617 <dt>DEBUG: message
</dt>
618 <dd>Sets the printer-state-message attribute and adds the specified
619 message to the current error log file using the
"debug" log level.
</dd>
621 <dt>DEBUG2: message
</dt>
622 <dd>Sets the printer-state-message attribute and adds the specified
623 message to the current error log file using the
"debug2" log level.
</dd>
625 <dt>EMERG: message
</dt>
626 <dd>Sets the printer-state-message attribute and adds the specified
627 message to the current error log file using the
"emergency" log
630 <dt>ERROR: message
</dt>
631 <dd>Sets the printer-state-message attribute and adds the specified
632 message to the current error log file using the
"error" log level.
633 Use
"ERROR:" messages for non-persistent processing errors.
</dd>
635 <dt>INFO: message
</dt>
636 <dd>Sets the printer-state-message attribute. If the current log level
637 is set to
"debug2", also adds the specified message to the current error
638 log file using the
"info" log level.
</dd>
640 <dt>NOTICE: message
</dt>
641 <dd>Sets the printer-state-message attribute and adds the specified
642 message to the current error log file using the
"notice" log level.
</dd>
644 <dt>PAGE: page-number #-copies
</dt>
645 <dt>PAGE: total #-pages
</dt>
646 <dd>Adds an entry to the current page log file. The first form adds
647 #-copies to the job-media-sheets-completed attribute. The second
648 form sets the job-media-sheets-completed attribute to #-pages.
</dd>
650 <dt>PPD: keyword=value [keyword=value ...]
</dt>
651 <dd>Changes or adds keywords to the printer's PPD file. Typically
652 this is used to update installable options or default media settings
653 based on the printer configuration.
</dd>
655 <dt>STATE: printer-state-reason [printer-state-reason ...]
</dt>
656 <dt>STATE: + printer-state-reason [printer-state-reason ...]
</dt>
657 <dt>STATE: - printer-state-reason [printer-state-reason ...]
</dt>
658 <dd>Sets, adds, or removes printer-state-reason keywords to the
659 current queue. Typically this is used to indicate persistent media,
660 ink, toner, and configuration conditions or errors on a printer.
661 <a href='#TABLE2'
>Table
2</a> lists the standard state keywords -
662 use vendor-prefixed (
"com.acme.foo") keywords for custom states.
</dd>
664 <dt>WARNING: message
</dt>
665 <dd>Sets the printer-state-message attribute and adds the specified
666 message to the current error log file using the
"warning" log
671 <p>Messages without one of these prefixes are treated as if they began with
672 the
"DEBUG:" prefix string.
</p>
675 <div class='table'
><table width='
80%' summary='Table
1: Standard marker-types Values'
>
676 <caption>Table
1:
<a name='TABLE1'
>Standard marker-types Values
</a></caption>
686 <td>Developer unit
</td>
693 <td>fuserCleaningPad
</td>
694 <td>Fuser cleaning pad
</td>
706 <td>Photo conductor
</td>
714 <td>Staple supply
</td>
718 <td>Toner supply
</td>
721 <td>transferUnit
</td>
722 <td>Transfer unit
</td>
726 <td>Waste ink tank
</td>
730 <td>Waste toner tank
</td>
734 <td>Waste wax tank
</td>
741 <div class='table'
><table width='
80%' summary='Table
2: Standard State Keywords'
>
742 <caption>Table
2:
<a name='TABLE2'
>Standard State Keywords
</a></caption>
751 <td>connecting-to-device
</td>
752 <td>Connecting to printer but not printing yet
</td>
756 <td>A cover is open on the printer
</td>
759 <td>input-tray-missing
</td>
760 <td>An input tray is missing from the printer
</td>
763 <td>marker-supply-empty
</td>
767 <td>marker-supply-low
</td>
771 <td>marker-waste-almost-full
</td>
772 <td>Waste tank almost full
</td>
775 <td>marker-waste-full
</td>
776 <td>Waste tank full
</td>
780 <td>Out of media
</td>
784 <td>Media is jammed in the printer
</td>
788 <td>Low on media
</td>
792 <td>Stop the printer
</td>
796 <td>Unable to connect to printer
</td>
800 <td>Out of toner
</td>
804 <td>Low on toner
</td>
809 <h3><a name=
"COMMUNICATING_BACKEND">Communicating with the Backend
</a></h3>
811 <p>Filters can communicate with the backend via the
812 <a href=
"#cupsBackChannelRead"><code>cupsBackChannelRead
</code></a> and
813 <a href=
"#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest
</code></a>
815 <a href=
"#cupsBackChannelRead"><code>cupsBackChannelRead
</code></a> function
816 reads data that has been sent back from the device and is typically used to
817 obtain status and configuration information. For example, the following code
818 polls the backend for back-channel data:
</p>
820 <pre class=
"example">
821 #include
<cups/cups.h
>
826 /* Use a timeout of
0.0 seconds to poll for back-channel data */
827 bytes = cupsBackChannelRead(buffer, sizeof(buffer),
0.0);
830 <p>Filters can also use
<code>select()
</code> or
<code>poll()
</code> on the
831 back-channel file descriptor (
3 or
<code>CUPS_BC_FD
</code>) to read data only
832 when it is available.
</p>
835 <a href=
"#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest
</code></a>
836 function allows you to get out-of-band status information and do synchronization
837 with the device. For example, the following code gets the current IEEE-
1284
838 device ID string from the backend:
</p>
840 <pre class=
"example">
841 #include
<cups/sidechannel.h
>
845 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> status;
847 /* Tell cupsSideChannelDoRequest() how big our buffer is, less
1 byte for
848 nul-termination... */
849 datalen = sizeof(data) -
1;
851 /* Get the IEEE-
1284 device ID, waiting for up to
1 second */
852 status =
<a href=
"#cupsSideChannelDoRequest">cupsSideChannelDoRequest
</a>(CUPS_SC_CMD_GET_DEVICE_ID, data,
&datalen,
1.0);
854 /* Use the returned value if OK was returned and the length is non-zero */
855 if (status == CUPS_SC_STATUS_OK && datalen
> 0)
856 data[datalen] = '\
0';
861 <h3><a name=
"COMMUNICATING_FILTER">Communicating with Filters
</a></h3>
863 <p>Backends communicate with filters using the reciprocal functions
864 <a href=
"#cupsBackChannelWrite"><code>cupsBackChannelWrite
</code></a>,
865 <a href=
"#cupsSideChannelRead"><code>cupsSideChannelRead
</code></a>, and
866 <a href=
"#cupsSideChannelWrite"><code>cupsSideChannelWrite
</code></a>. We
867 recommend writing back-channel data using a timeout of
1.0 seconds:
</p>
869 <pre class=
"example">
870 #include
<cups/cups.h
>
875 /* Obtain data from printer/device */
878 /* Use a timeout of
1.0 seconds to give filters a chance to read */
879 cupsBackChannelWrite(buffer, bytes,
1.0);
882 <p>The
<a href=
"#cupsSideChannelRead"><code>cupsSideChannelRead
</code></a>
883 function reads a side-channel command from a filter, driver, or port monitor.
884 Backends can either poll for commands using a
<code>timeout
</code> of
0.0, wait
885 indefinitely for commands using a
<code>timeout
</code> of -
1.0 (probably in a
886 separate thread for that purpose), or use
<code>select
</code> or
887 <code>poll
</code> on the
<code>CUPS_SC_FD
</code> file descriptor (
4) to handle
888 input and output on several file descriptors at the same time.
</p>
890 <p>Once a command is processed, the backend uses the
891 <a href=
"#cupsSideChannelWrite"><code>cupsSideChannelWrite
</code></a> function
892 to send its response. For example, the following code shows how to poll for a
893 side-channel command and respond to it:
</p>
895 <pre class=
"example">
896 #include
<cups/sidechannel.h
>
898 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> command;
899 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> status;
901 int datalen = sizeof(data);
903 /* Poll for a command... */
904 if (!
<a href=
"#cupsSideChannelRead">cupsSideChannelRead
</a>(
&command,
&status, data,
&datalen,
0.0))
908 /* handle supported commands, fill data/datalen/status with values as needed */
911 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
916 /* Send a response... */
917 <a href=
"#cupsSideChannelWrite">cupsSideChannelWrite
</a>(command, status, data, datalen,
1.0);
921 <h3><a name=
"SNMP">Doing SNMP Queries with Network Printers
</a></h3>
923 <p>The Simple Network Management Protocol (SNMP) allows you to get the current
924 status, page counter, and supply levels from most network printers. Every
925 piece of information is associated with an Object Identifier (OID), and
926 every printer has a
<em>community
</em> name associated with it. OIDs can be
927 queried directly or by
"walking" over a range of OIDs with a common prefix.
</p>
929 <p>The two CUPS SNMP functions provide a simple API for querying network
930 printers through the side-channel interface. Each accepts a string containing
931 an OID like
".1.3.6.1.2.1.43.10.2.1.4.1.1" (the standard page counter OID)
932 along with a timeout for the query.
</p>
934 <p>The
<a href=
"#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet
</code></a>
935 function queries a single OID and returns the value as a string in a buffer
938 <pre class=
"example">
939 #include
<cups/sidechannel.h
>
942 int datalen = sizeof(data);
944 if (
<a href=
"#cupsSideChannelSNMPGet">cupsSideChannelSNMPGet
</a>(
".1.3.6.1.2.1.43.10.2.1.4.1.1", data,
&datalen,
5.0)
945 == CUPS_SC_STATUS_OK)
947 /* Do something with the value */
948 printf(
"Page counter is: %s\n", data);
953 <a href=
"#cupsSideChannelSNMPWalk"><code>cupsSideChannelSNMPWalk
</code></a>
954 function allows you to query a whole group of OIDs, calling a function of your
955 choice for each OID that is found:
</p>
957 <pre class=
"example">
958 #include
<cups/sidechannel.h
>
961 my_callback(const char *oid, const char *data, int datalen, void *context)
963 /* Do something with the value */
964 printf(
"%s=%s\n", oid, data);
971 <a href=
"#cupsSideChannelSNMPWalk">cupsSNMPSideChannelWalk
</a>(
".1.3.6.1.2.1.43",
5.0, my_callback, my_data);
973 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
974 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsBackChannelRead">cupsBackChannelRead
</a></h3>
975 <p class=
"description">Read data from the backchannel.
</p>
977 ssize_t cupsBackChannelRead (
<br>
978 char *buffer,
<br>
979 size_t bytes,
<br>
980 double timeout
<br>
982 <h4 class=
"parameters">Parameters
</h4>
985 <dd class=
"description">Buffer to read into
</dd>
987 <dd class=
"description">Bytes to read
</dd>
989 <dd class=
"description">Timeout in seconds, typically
0.0 to poll
</dd>
991 <h4 class=
"returnvalue">Return Value
</h4>
992 <p class=
"description">Bytes read or -
1 on error
</p>
993 <h4 class=
"discussion">Discussion
</h4>
994 <p class=
"discussion">Reads up to
"bytes
" bytes from the backchannel/backend. The
"timeout
"
995 parameter controls how many seconds to wait for the data - use
0.0 to
996 return immediately if there is no data, -
1.0 to wait for data indefinitely.
999 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsBackChannelWrite">cupsBackChannelWrite
</a></h3>
1000 <p class=
"description">Write data to the backchannel.
</p>
1002 ssize_t cupsBackChannelWrite (
<br>
1003 const char *buffer,
<br>
1004 size_t bytes,
<br>
1005 double timeout
<br>
1007 <h4 class=
"parameters">Parameters
</h4>
1010 <dd class=
"description">Buffer to write
</dd>
1012 <dd class=
"description">Bytes to write
</dd>
1014 <dd class=
"description">Timeout in seconds, typically
1.0</dd>
1016 <h4 class=
"returnvalue">Return Value
</h4>
1017 <p class=
"description">Bytes written or -
1 on error
</p>
1018 <h4 class=
"discussion">Discussion
</h4>
1019 <p class=
"discussion">Writes
"bytes
" bytes to the backchannel/filter. The
"timeout
" parameter
1020 controls how many seconds to wait for the data to be written - use
1021 0.0 to return immediately if the data cannot be written, -
1.0 to wait
1025 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsBackendDeviceURI">cupsBackendDeviceURI
</a></h3>
1026 <p class=
"description">Get the device URI for a backend.
</p>
1028 const char *cupsBackendDeviceURI (
<br>
1029 char **argv
<br>
1031 <h4 class=
"parameters">Parameters
</h4>
1034 <dd class=
"description">Command-line arguments
</dd>
1036 <h4 class=
"returnvalue">Return Value
</h4>
1037 <p class=
"description">Device URI or
<code>NULL
</code></p>
1038 <h4 class=
"discussion">Discussion
</h4>
1039 <p class=
"discussion">The
"argv
" argument is the argv argument passed to main(). This
1040 function returns the device URI passed in the DEVICE_URI environment
1041 variable or the device URI passed in argv[
0], whichever is found
1045 <h3 class=
"function"><span class=
"info"> CUPS
1.4 </span><a name=
"cupsBackendReport">cupsBackendReport
</a></h3>
1046 <p class=
"description">Write a device line from a backend.
</p>
1048 void cupsBackendReport (
<br>
1049 const char *device_scheme,
<br>
1050 const char *device_uri,
<br>
1051 const char *device_make_and_model,
<br>
1052 const char *device_info,
<br>
1053 const char *device_id,
<br>
1054 const char *device_location
<br>
1056 <h4 class=
"parameters">Parameters
</h4>
1058 <dt>device_scheme
</dt>
1059 <dd class=
"description">device-scheme string
</dd>
1061 <dd class=
"description">device-uri string
</dd>
1062 <dt>device_make_and_model
</dt>
1063 <dd class=
"description">device-make-and-model string or
<code>NULL
</code></dd>
1064 <dt>device_info
</dt>
1065 <dd class=
"description">device-info string or
<code>NULL
</code></dd>
1067 <dd class=
"description">device-id string or
<code>NULL
</code></dd>
1068 <dt>device_location
</dt>
1069 <dd class=
"description">device-location string or
<code>NULL
</code></dd>
1071 <h4 class=
"discussion">Discussion
</h4>
1072 <p class=
"discussion">This function writes a single device line to stdout for a backend.
1073 It handles quoting of special characters in the device-make-and-model,
1074 device-info, device-id, and device-location strings.
1077 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsSideChannelDoRequest">cupsSideChannelDoRequest
</a></h3>
1078 <p class=
"description">Send a side-channel command to a backend and wait for a response.
</p>
1080 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> cupsSideChannelDoRequest (
<br>
1081 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> command,
<br>
1082 char *data,
<br>
1083 int *datalen,
<br>
1084 double timeout
<br>
1086 <h4 class=
"parameters">Parameters
</h4>
1089 <dd class=
"description">Command to send
</dd>
1091 <dd class=
"description">Response data buffer pointer
</dd>
1093 <dd class=
"description">Size of data buffer on entry, number of bytes in buffer on return
</dd>
1095 <dd class=
"description">Timeout in seconds
</dd>
1097 <h4 class=
"returnvalue">Return Value
</h4>
1098 <p class=
"description">Status of command
</p>
1099 <h4 class=
"discussion">Discussion
</h4>
1100 <p class=
"discussion">This function is normally only called by filters, drivers, or port
1101 monitors in order to communicate with the backend used by the current
1102 printer. Programs must be prepared to handle timeout or
"not
1103 implemented
" status codes, which indicate that the backend or device
1104 do not support the specified side-channel command.
<br>
1106 The
"datalen
" parameter must be initialized to the size of the buffer
1107 pointed to by the
"data
" parameter. cupsSideChannelDoRequest() will
1108 update the value to contain the number of data bytes in the buffer.
1111 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsSideChannelRead">cupsSideChannelRead
</a></h3>
1112 <p class=
"description">Read a side-channel message.
</p>
1114 int cupsSideChannelRead (
<br>
1115 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> *command,
<br>
1116 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> *status,
<br>
1117 char *data,
<br>
1118 int *datalen,
<br>
1119 double timeout
<br>
1121 <h4 class=
"parameters">Parameters
</h4>
1124 <dd class=
"description">Command code
</dd>
1126 <dd class=
"description">Status code
</dd>
1128 <dd class=
"description">Data buffer pointer
</dd>
1130 <dd class=
"description">Size of data buffer on entry, number of bytes in buffer on return
</dd>
1132 <dd class=
"description">Timeout in seconds
</dd>
1134 <h4 class=
"returnvalue">Return Value
</h4>
1135 <p class=
"description">0 on success, -
1 on error
</p>
1136 <h4 class=
"discussion">Discussion
</h4>
1137 <p class=
"discussion">This function is normally only called by backend programs to read
1138 commands from a filter, driver, or port monitor program. The
1139 caller must be prepared to handle incomplete or invalid messages
1140 and return the corresponding status codes.
<br>
1142 The
"datalen
" parameter must be initialized to the size of the buffer
1143 pointed to by the
"data
" parameter. cupsSideChannelDoRequest() will
1144 update the value to contain the number of data bytes in the buffer.
1147 <h3 class=
"function"><span class=
"info"> CUPS
1.4 </span><a name=
"cupsSideChannelSNMPGet">cupsSideChannelSNMPGet
</a></h3>
1148 <p class=
"description">Query a SNMP OID's value.
</p>
1150 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> cupsSideChannelSNMPGet (
<br>
1151 const char *oid,
<br>
1152 char *data,
<br>
1153 int *datalen,
<br>
1154 double timeout
<br>
1156 <h4 class=
"parameters">Parameters
</h4>
1159 <dd class=
"description">OID to query
</dd>
1161 <dd class=
"description">Buffer for OID value
</dd>
1163 <dd class=
"description">Size of OID buffer on entry, size of value on return
</dd>
1165 <dd class=
"description">Timeout in seconds
</dd>
1167 <h4 class=
"returnvalue">Return Value
</h4>
1168 <p class=
"description">Query status
</p>
1169 <h4 class=
"discussion">Discussion
</h4>
1170 <p class=
"discussion">This function asks the backend to do a SNMP OID query on behalf of the
1171 filter, port monitor, or backend using the default community name.
<br>
1173 "oid
" contains a numeric OID consisting of integers separated by periods,
1174 for example
".1.3.6.1.2.1.43". Symbolic names from SNMP MIBs are not
1175 supported and must be converted to their numeric forms.
<br>
1177 On input,
"data
" and
"datalen
" provide the location and size of the
1178 buffer to hold the OID value as a string. HEX-String (binary) values are
1179 converted to hexadecimal strings representing the binary data, while
1180 NULL-Value and unknown OID types are returned as the empty string.
1181 The returned
"datalen
" does not include the trailing nul.
1183 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED
</code> is returned by backends that do not
1184 support SNMP queries.
<code>CUPS_SC_STATUS_NO_RESPONSE
</code> is returned when
1185 the printer does not respond to the SNMP query.
1188 <h3 class=
"function"><span class=
"info"> CUPS
1.4 </span><a name=
"cupsSideChannelSNMPWalk">cupsSideChannelSNMPWalk
</a></h3>
1189 <p class=
"description">Query multiple SNMP OID values.
</p>
1191 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> cupsSideChannelSNMPWalk (
<br>
1192 const char *oid,
<br>
1193 double timeout,
<br>
1194 <a href=
"#cups_sc_walk_func_t">cups_sc_walk_func_t
</a> cb,
<br>
1195 void *context
<br>
1197 <h4 class=
"parameters">Parameters
</h4>
1200 <dd class=
"description">First numeric OID to query
</dd>
1202 <dd class=
"description">Timeout for each query in seconds
</dd>
1204 <dd class=
"description">Function to call with each value
</dd>
1206 <dd class=
"description">Application-defined pointer to send to callback
</dd>
1208 <h4 class=
"returnvalue">Return Value
</h4>
1209 <p class=
"description">Status of first query of
<code>CUPS_SC_STATUS_OK
</code> on success
</p>
1210 <h4 class=
"discussion">Discussion
</h4>
1211 <p class=
"discussion">This function asks the backend to do multiple SNMP OID queries on behalf
1212 of the filter, port monitor, or backend using the default community name.
1213 All OIDs under the
"parent
" OID are queried and the results are sent to
1214 the callback function you provide.
<br>
1216 "oid
" contains a numeric OID consisting of integers separated by periods,
1217 for example
".1.3.6.1.2.1.43". Symbolic names from SNMP MIBs are not
1218 supported and must be converted to their numeric forms.
<br>
1220 "timeout
" specifies the timeout for each OID query. The total amount of
1221 time will depend on the number of OID values found and the time required
1224 "cb
" provides a function to call for every value that is found.
"context
"
1225 is an application-defined pointer that is sent to the callback function
1226 along with the OID and current data. The data passed to the callback is the
1227 same as returned by
<a href=
"#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet
</code></a>.
1229 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED
</code> is returned by backends that do not
1230 support SNMP queries.
<code>CUPS_SC_STATUS_NO_RESPONSE
</code> is returned when
1231 the printer does not respond to the first SNMP query.
1234 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsSideChannelWrite">cupsSideChannelWrite
</a></h3>
1235 <p class=
"description">Write a side-channel message.
</p>
1237 int cupsSideChannelWrite (
<br>
1238 <a href=
"#cups_sc_command_t">cups_sc_command_t
</a> command,
<br>
1239 <a href=
"#cups_sc_status_t">cups_sc_status_t
</a> status,
<br>
1240 const char *data,
<br>
1241 int datalen,
<br>
1242 double timeout
<br>
1244 <h4 class=
"parameters">Parameters
</h4>
1247 <dd class=
"description">Command code
</dd>
1249 <dd class=
"description">Status code
</dd>
1251 <dd class=
"description">Data buffer pointer
</dd>
1253 <dd class=
"description">Number of bytes of data
</dd>
1255 <dd class=
"description">Timeout in seconds
</dd>
1257 <h4 class=
"returnvalue">Return Value
</h4>
1258 <p class=
"description">0 on success, -
1 on error
</p>
1259 <h4 class=
"discussion">Discussion
</h4>
1260 <p class=
"discussion">This function is normally only called by backend programs to send
1261 responses to a filter, driver, or port monitor program.
1264 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
1265 <h3 class=
"typedef"><a name=
"cups_backend_t">cups_backend_t
</a></h3>
1266 <p class=
"description">Backend exit codes
</p>
1268 typedef enum
<a href=
"#cups_backend_e">cups_backend_e
</a> cups_backend_t;
1270 <h3 class=
"typedef"><a name=
"cups_sc_bidi_t">cups_sc_bidi_t
</a></h3>
1271 <p class=
"description">Bidirectional capabilities
</p>
1273 typedef enum
<a href=
"#cups_sc_bidi_e">cups_sc_bidi_e
</a> cups_sc_bidi_t;
1275 <h3 class=
"typedef"><a name=
"cups_sc_command_t">cups_sc_command_t
</a></h3>
1276 <p class=
"description">Request command codes
</p>
1278 typedef enum
<a href=
"#cups_sc_command_e">cups_sc_command_e
</a> cups_sc_command_t;
1280 <h3 class=
"typedef"><a name=
"cups_sc_state_t">cups_sc_state_t
</a></h3>
1281 <p class=
"description">Printer state bits
</p>
1283 typedef enum
<a href=
"#cups_sc_state_e">cups_sc_state_e
</a> cups_sc_state_t;
1285 <h3 class=
"typedef"><a name=
"cups_sc_status_t">cups_sc_status_t
</a></h3>
1286 <p class=
"description">Response status codes
</p>
1288 typedef enum
<a href=
"#cups_sc_status_e">cups_sc_status_e
</a> cups_sc_status_t;
1290 <h3 class=
"typedef"><a name=
"cups_sc_walk_func_t">cups_sc_walk_func_t
</a></h3>
1291 <p class=
"description">SNMP walk callback
</p>
1293 typedef void (*cups_sc_walk_func_t)(const char *oid, const char *data, int datalen, void *context);
1295 <h2 class=
"title"><a name=
"ENUMERATIONS">Constants
</a></h2>
1296 <h3 class=
"enumeration"><a name=
"cups_backend_e">cups_backend_e
</a></h3>
1297 <p class=
"description">Backend exit codes
</p>
1298 <h4 class=
"constants">Constants
</h4>
1300 <dt>CUPS_BACKEND_AUTH_REQUIRED
</dt>
1301 <dd class=
"description">Job failed, authentication required
</dd>
1302 <dt>CUPS_BACKEND_CANCEL
</dt>
1303 <dd class=
"description">Job failed, cancel job
</dd>
1304 <dt>CUPS_BACKEND_FAILED
</dt>
1305 <dd class=
"description">Job failed, use error-policy
</dd>
1306 <dt>CUPS_BACKEND_HOLD
</dt>
1307 <dd class=
"description">Job failed, hold job
</dd>
1308 <dt>CUPS_BACKEND_OK
</dt>
1309 <dd class=
"description">Job completed successfully
</dd>
1310 <dt>CUPS_BACKEND_STOP
</dt>
1311 <dd class=
"description">Job failed, stop queue
</dd>
1313 <h3 class=
"enumeration"><a name=
"cups_sc_bidi_e">cups_sc_bidi_e
</a></h3>
1314 <p class=
"description">Bidirectional capability values
</p>
1315 <h4 class=
"constants">Constants
</h4>
1317 <dt>CUPS_SC_BIDI_NOT_SUPPORTED
</dt>
1318 <dd class=
"description">Bidirectional I/O is not supported
</dd>
1319 <dt>CUPS_SC_BIDI_SUPPORTED
</dt>
1320 <dd class=
"description">Bidirectional I/O is supported
</dd>
1322 <h3 class=
"enumeration"><a name=
"cups_sc_command_e">cups_sc_command_e
</a></h3>
1323 <p class=
"description">Request command codes
</p>
1324 <h4 class=
"constants">Constants
</h4>
1326 <dt>CUPS_SC_CMD_DRAIN_OUTPUT
</dt>
1327 <dd class=
"description">Drain all pending output
</dd>
1328 <dt>CUPS_SC_CMD_GET_BIDI
</dt>
1329 <dd class=
"description">Return bidirectional capabilities
</dd>
1330 <dt>CUPS_SC_CMD_GET_DEVICE_ID
</dt>
1331 <dd class=
"description">Return the IEEE-
1284 device ID
</dd>
1332 <dt>CUPS_SC_CMD_GET_STATE
</dt>
1333 <dd class=
"description">Return the device state
</dd>
1334 <dt>CUPS_SC_CMD_SNMP_GET
<span class=
"info"> CUPS
1.4 </span></dt>
1335 <dd class=
"description">Query an SNMP OID
</dd>
1336 <dt>CUPS_SC_CMD_SNMP_GET_NEXT
<span class=
"info"> CUPS
1.4 </span></dt>
1337 <dd class=
"description">Query the next SNMP OID
</dd>
1338 <dt>CUPS_SC_CMD_SOFT_RESET
</dt>
1339 <dd class=
"description">Do a soft reset
</dd>
1341 <h3 class=
"enumeration"><a name=
"cups_sc_state_e">cups_sc_state_e
</a></h3>
1342 <p class=
"description">Printer state bits
</p>
1343 <h4 class=
"constants">Constants
</h4>
1345 <dt>CUPS_SC_STATE_BUSY
</dt>
1346 <dd class=
"description">Device is busy
</dd>
1347 <dt>CUPS_SC_STATE_ERROR
</dt>
1348 <dd class=
"description">Other error condition
</dd>
1349 <dt>CUPS_SC_STATE_MARKER_EMPTY
</dt>
1350 <dd class=
"description">Toner/ink out condition
</dd>
1351 <dt>CUPS_SC_STATE_MARKER_LOW
</dt>
1352 <dd class=
"description">Toner/ink low condition
</dd>
1353 <dt>CUPS_SC_STATE_MEDIA_EMPTY
</dt>
1354 <dd class=
"description">Paper out condition
</dd>
1355 <dt>CUPS_SC_STATE_MEDIA_LOW
</dt>
1356 <dd class=
"description">Paper low condition
</dd>
1357 <dt>CUPS_SC_STATE_OFFLINE
</dt>
1358 <dd class=
"description">Device is offline
</dd>
1359 <dt>CUPS_SC_STATE_ONLINE
</dt>
1360 <dd class=
"description">Device is online
</dd>
1362 <h3 class=
"enumeration"><a name=
"cups_sc_status_e">cups_sc_status_e
</a></h3>
1363 <p class=
"description">Response status codes
</p>
1364 <h4 class=
"constants">Constants
</h4>
1366 <dt>CUPS_SC_STATUS_BAD_MESSAGE
</dt>
1367 <dd class=
"description">The command/response message was invalid
</dd>
1368 <dt>CUPS_SC_STATUS_IO_ERROR
</dt>
1369 <dd class=
"description">An I/O error occurred
</dd>
1370 <dt>CUPS_SC_STATUS_NONE
</dt>
1371 <dd class=
"description">No status
</dd>
1372 <dt>CUPS_SC_STATUS_NOT_IMPLEMENTED
</dt>
1373 <dd class=
"description">Command not implemented
</dd>
1374 <dt>CUPS_SC_STATUS_NO_RESPONSE
</dt>
1375 <dd class=
"description">The device did not respond
</dd>
1376 <dt>CUPS_SC_STATUS_OK
</dt>
1377 <dd class=
"description">Operation succeeded
</dd>
1378 <dt>CUPS_SC_STATUS_TIMEOUT
</dt>
1379 <dd class=
"description">The backend did not respond
</dd>
1380 <dt>CUPS_SC_STATUS_TOO_BIG
</dt>
1381 <dd class=
"description">Response too big
</dd>