3 <!-- SECTION: Programming -->
5 <title>Filter and Backend Programming
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8">
8 <meta name=
"creator" content=
"codedoc v3.1">
9 <meta name=
"author" content=
"Unknown">
10 <meta name=
"copyright" content=
"Unknown">
11 <meta name=
"version" content=
"0.0">
12 <style type=
"text/css"><!--
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
17 H1, H2, H3, H4, H5, H6, P, TD, TH {
18 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
21 H1 { font-size: 2em; }
22 H2 { font-size: 1.75em; }
23 H3 { font-size: 1.5em; }
24 H4 { font-size: 1.25em; }
27 font-family: monaco, courier, monospace;
32 font-family: monaco, courier, monospace;
36 border-left: solid 2px #777;
45 PRE.command, PRE.example {
72 PRE.command EM, PRE.example EM {
73 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
77 font-family: monaco, courier, monospace;
93 -moz-border-radius: 10px;
98 text-decoration: none;
101 A:link:hover, A:visited:hover, A:active {
102 text-decoration: underline;
109 TR.data, TD.data, TR.data TD {
112 border-bottom: solid 1pt #999999;
116 border-bottom: solid 1pt #999999;
123 border: solid thin #999999;
124 border-collapse: collapse;
140 border: solid thin #cccccc;
147 border-bottom: solid thin #999999;
156 caption-side: bottom;
180 border: thin solid black;
188 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
197 border-bottom: solid 2pt #000000;
200 DIV.indent, TABLE.indent {
208 border-collapse: collapse;
211 TABLE.indent TD, TABLE.indent TH {
216 border-collapse: collapse;
224 border-bottom: solid thin #cccccc;
229 vertical-align: bottom;
238 border-bottom: solid thin #eeeeee;
243 TABLE.list TR:nth-child(even) {
247 TABLE.list TR:nth-child(odd) {
266 font-family: monaco, courier, monospace;
270 border: solid thin #999999;
271 border-collapse: collapse;
276 DIV.summary TABLE TD, DIV.summary TABLE TH {
277 border: solid thin #999999;
283 DIV.summary TABLE THEAD TH {
287 /* API documentation styles... */
299 margin-bottom: 0.5em;
304 margin-bottom: 0.5em;
309 margin-bottom: 0.5em;
314 border: solid thin black;
323 div.contents ul.contents {
327 border-bottom: solid 2px gray;
337 border-bottom: solid 2px gray;
340 border-bottom: solid 2px gray;
352 border-bottom: solid 2px gray;
355 border-bottom: solid 2px gray;
358 border-bottom: solid 2px gray;
362 h1, h2, h3, h4, h5, h6 {
363 page-break-inside: avoid;
366 border: solid thin gray;
367 box-shadow: 3px 3px 5px rgba(0,0,0,0.5);
368 padding: 10px 10px 0px;
369 page-break-inside: avoid;
371 p code, li code, p.code, pre, ul.code li {
372 background: rgba(127,127,127,0.1);
373 border: thin dotted gray;
374 font-family: monospace;
376 -webkit-hyphens: manual;
377 page-break-inside: avoid;
379 p.code, pre, ul.code li {
386 text-decoration: none;
390 border: solid thin black;
397 h2 span.info, h3 span.info, h4 span.info {
403 h2.title span.info, h3.title span.info, h4.title span.info {
404 border-bottom-left-radius: 0px;
405 border-bottom-right-radius: 0px;
410 ul.code, ul.contents, ul.subcontents {
411 list-style-type: none;
421 ul.contents li ul.code, ul.contents li ul.subcontents {
425 border-collapse: collapse;
428 table.list tr:nth-child(even) {
429 background: rgba(127,127,127,0.1);]n}
431 border-right: 2px solid gray;
432 font-family: monospace;
433 padding: 5px 10px 5px 2px;
438 padding: 5px 2px 5px 10px;
445 border-bottom: solid 2px black;
448 border-bottom: solid 2px black;
454 Filter and backend programming header for CUPS.
456 Copyright © 2008-2016 by Apple Inc.
458 Licensed under Apache License v2.0. See the file "LICENSE" for more
462 <h1 class='title'
>Filter and Backend Programming
</h1>
464 <div class='summary'
><table summary='General Information'
>
468 <th>cups/backend.h
<br>
470 cups/sidechannel.h
</th>
480 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a><br>
481 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
482 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
483 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
484 Programming:
<a href='postscript-driver.html' target='_top'
>Developing PostScript Printer Drivers
</a><br>
485 Programming:
<a href='raster-driver.html' target='_top'
>Developing Raster Printer Drivers
</a><br>
486 Specifications:
<a href='spec-design.html' target='_top'
>CUPS Design Description
</a></td>
490 <div class=
"contents">
491 <h2 class=
"title">Contents
</h2>
492 <ul class=
"contents">
493 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
494 <li><a href=
"#SECURITY">Security Considerations
</a></li>
495 <li><a href=
"#SIGNALS">Canceled Jobs and Signal Handling
</a></li>
496 <li><a href=
"#PERMISSIONS">File Permissions
</a></li>
497 <li><a href=
"#TEMPFILES">Temporary Files
</a></li>
498 <li><a href=
"#COPIES">Copy Generation
</a></li>
499 <li><a href=
"#EXITCODES">Exit Codes
</a></li>
500 <li><a href=
"#ENVIRONMENT">Environment Variables
</a></li>
501 <li><a href=
"#MESSAGES">Communicating with the Scheduler
</a></li>
502 <li><a href=
"#COMMUNICATING_BACKEND">Communicating with the Backend
</a></li>
503 <li><a href=
"#COMMUNICATING_FILTER">Communicating with Filters
</a></li>
504 <li><a href=
"#SNMP">Doing SNMP Queries with Network Printers
</a></li>
506 <li><a href=
"#SANDBOXING">Sandboxing on macOS
</a></li>
507 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"subcontents">
508 <li><a href=
"#cupsBackChannelRead">cupsBackChannelRead
</a></li>
509 <li><a href=
"#cupsBackChannelWrite">cupsBackChannelWrite
</a></li>
510 <li><a href=
"#cupsBackendDeviceURI">cupsBackendDeviceURI
</a></li>
511 <li><a href=
"#cupsBackendReport">cupsBackendReport
</a></li>
512 <li><a href=
"#cupsSideChannelDoRequest">cupsSideChannelDoRequest
</a></li>
513 <li><a href=
"#cupsSideChannelRead">cupsSideChannelRead
</a></li>
514 <li><a href=
"#cupsSideChannelSNMPGet">cupsSideChannelSNMPGet
</a></li>
515 <li><a href=
"#cupsSideChannelSNMPWalk">cupsSideChannelSNMPWalk
</a></li>
516 <li><a href=
"#cupsSideChannelWrite">cupsSideChannelWrite
</a></li>
518 <li><a href=
"#TYPES">Data Types
</a><ul class=
"subcontents">
519 <li><a href=
"#cups_backend_t">cups_backend_t
</a></li>
520 <li><a href=
"#cups_sc_bidi_t">cups_sc_bidi_t
</a></li>
521 <li><a href=
"#cups_sc_command_t">cups_sc_command_t
</a></li>
522 <li><a href=
"#cups_sc_connected_t">cups_sc_connected_t
</a></li>
523 <li><a href=
"#cups_sc_state_t">cups_sc_state_t
</a></li>
524 <li><a href=
"#cups_sc_status_t">cups_sc_status_t
</a></li>
525 <li><a href=
"#cups_sc_walk_func_t">cups_sc_walk_func_t
</a></li>
527 <li><a href=
"#ENUMERATIONS">Enumerations
</a><ul class=
"subcontents">
528 <li><a href=
"#cups_backend_e">cups_backend_e
</a></li>
529 <li><a href=
"#cups_sc_bidi_e">cups_sc_bidi_e
</a></li>
530 <li><a href=
"#cups_sc_command_e">cups_sc_command_e
</a></li>
531 <li><a href=
"#cups_sc_connected_e">cups_sc_connected_e
</a></li>
532 <li><a href=
"#cups_sc_state_e">cups_sc_state_e
</a></li>
533 <li><a href=
"#cups_sc_status_e">cups_sc_status_e
</a></li>
539 Filter and backend programming introduction for CUPS.
541 Copyright © 2007-2016 by Apple Inc.
542 Copyright © 1997-2006 by Easy Software Products, all rights reserved.
544 Licensed under Apache License v2.0. See the file "LICENSE" for more
548 <h2 class='title'
><a name=
"OVERVIEW">Overview
</a></h2>
550 <p>Filters (which include printer drivers and port monitors) and backends
551 are used to convert job files to a printable format and send that data to the
552 printer itself. All of these programs use a common interface for processing
553 print jobs and communicating status information to the scheduler. Each is run
554 with a standard set of command-line arguments:
<p>
562 <dd>The user printing the job
</dd>
565 <dd>The job name/title
</dd>
568 <dd>The number of copies to print
</dd>
571 <dd>The options that were provided when the job was submitted
</dd>
574 <dd>The file to print (first program only)
</dd>
577 <p>The scheduler runs one or more of these programs to print any given job. The
578 first filter reads from the print file and writes to the standard output, while
579 the remaining filters read from the standard input and write to the standard
580 output. The backend is the last filter in the chain and writes to the
583 <p>Filters are always run as a non-privileged user, typically
"lp", with no
584 connection to the user's desktop. Backends are run either as a non-privileged
585 user or as root if the file permissions do not allow user or group execution.
586 The
<a href=
"#PERMISSIONS">file permissions
</a> section talks about this in
589 <h3><a name=
"SECURITY">Security Considerations
</a></h3>
591 <p>It is always important to use security programming practices. Filters and
592 most backends are run as a non-privileged user, so the major security
593 consideration is resource utilization - filters should not depend on unlimited
594 amounts of CPU, memory, or disk space, and should protect against conditions
595 that could lead to excess usage of any resource like infinite loops and
596 unbounded recursion. In addition, filters must
<em>never
</em> allow the user to
597 specify an arbitrary file path to a separator page, template, or other file
598 used by the filter since that can lead to an unauthorized disclosure of
599 information.
<em>Always
</em> treat input as suspect and validate it!
</p>
601 <p>If you are developing a backend that runs as root, make sure to check for
602 potential buffer overflows, integer under/overflow conditions, and file
603 accesses since these can lead to privilege escalations. When writing files,
604 always validate the file path and
<em>never
</em> allow a user to determine
605 where to store a file.
</p>
607 <blockquote><b>Note:
</b>
609 <p><em>Never
</em> write files to a user's home directory. Aside from the
610 security implications, CUPS is a network print service and as such the network
611 user may not be the same as the local user and/or there may not be a local home
612 directory to write to.
</p>
614 <p>In addition, some operating systems provide additional security mechanisms
615 that further limit file system access, even for backends running as root. On
616 macOS, for example, no backend may write to a user's home directory. See the
<a href=
"#SANDBOXING">Sandboxing on macOS
</a> section for more information.
</p>
619 <h3><a name=
"SIGNALS">Canceled Jobs and Signal Handling
</a></h3>
621 <p>The scheduler sends
<code>SIGTERM
</code> when a printing job is canceled or
622 held. Filters, backends, and port monitors
<em>must
</em> catch
623 <code>SIGTERM
</code> and perform any cleanup necessary to produce a valid output
624 file or return the printer to a known good state. The recommended behavior is to
625 end the output on the current page, preferably on the current line or object
628 <p>Filters and backends may also receive
<code>SIGPIPE
</code> when an upstream or downstream filter/backend exits with a non-zero status. Developers should generally ignore
<code>SIGPIPE
</code> at the beginning of
<code>main()
</code> with the following function call:
</p>
630 <pre class=
"example">
631 #include
<signal.h
>
636 main(int argc, char *argv[])
638 signal(SIGPIPE, SIG_IGN);
644 <h3><a name=
"PERMISSIONS">File Permissions
</a></h3>
646 <p>For security reasons, CUPS will only run filters and backends that are owned
647 by root and do not have world or group write permissions. The recommended
648 permissions for filters and backends are
0555 - read and execute but no write.
649 Backends that must run as root should use permissions of
0500 - read and execute
650 by root, no access for other users. Write permissions can be enabled for the
653 <p>To avoid a warning message, the directory containing your filter(s) must also
654 be owned by root and have world and group write disabled - permissions of
0755
655 or
0555 are strongly encouraged.
</p>
657 <h3><a name=
"TEMPFILES">Temporary Files
</a></h3>
659 <p>Temporary files should be created in the directory specified by the
660 "TMPDIR" environment variable. The
661 <a href=
"#cupsTempFile2"><code>cupsTempFile2
</code></a> function can be
662 used to safely create temporary files in this directory.
</p>
664 <h3><a name=
"COPIES">Copy Generation
</a></h3>
666 <p>The
<code>argv[
4]
</code> argument specifies the number of copies to produce
667 of the input file. In general, you should only generate copies if the
668 <em>filename
</em> argument is supplied. The only exception to this are
669 filters that produce device-independent PostScript output, since the PostScript
670 filter
<var>pstops
</var> is responsible for generating copies of PostScript
673 <h3><a name=
"EXITCODES">Exit Codes
</a></h3>
675 <p>Filters must exit with status
0 when they successfully generate print data
676 or
1 when they encounter an error. Backends can return any of the
677 <a href=
"#cups_backend_t"><code>cups_backend_t
</code></a> constants.
</p>
679 <h3><a name=
"ENVIRONMENT">Environment Variables
</a></h3>
681 <p>The following environment variables are defined by the printing system
682 when running print filters and backends:
</p>
686 <dt>APPLE_LANGUAGE
</dt>
687 <dd>The Apple language identifier associated with the job
691 <dd>The job character set, typically
"utf-8".
</dd>
694 <dd>When a job is submitted to a printer class, contains the name of
695 the destination printer class. Otherwise this environment
696 variable will not be set.
</dd>
698 <dt>CONTENT_TYPE
</dt>
699 <dd>The MIME type associated with the file (e.g.
700 application/postscript).
</dd>
702 <dt>CUPS_CACHEDIR
</dt>
703 <dd>The directory where cache files can be stored. Cache files can be
704 used to retain information between jobs or files in a job.
</dd>
706 <dt>CUPS_DATADIR
</dt>
707 <dd>The directory where (read-only) CUPS data files can be found.
</dd>
709 <dt>CUPS_FILETYPE
</dt>
710 <dd>The type of file being printed:
"job-sheet" for a banner page and
711 "document" for a regular print file.
</dd>
713 <dt>CUPS_SERVERROOT
</dt>
714 <dd>The root directory of the server.
</dd>
717 <dd>The device-uri associated with the printer.
</dd>
719 <dt>FINAL_CONTENT_TYPE
</dt>
720 <dd>The MIME type associated with the printer (e.g.
721 application/vnd.cups-postscript).
</dd>
724 <dd>The language locale associated with the job.
</dd>
727 <dd>The full pathname of the PostScript Printer Description (PPD)
728 file for this printer.
</dd>
731 <dd>The queue name of the class or printer.
</dd>
734 <dd>The recommended amount of memory to use for Raster Image
735 Processors (RIPs).
</dd>
738 <dd>The directory where temporary files should be created.
</dd>
742 <h3><a name=
"MESSAGES">Communicating with the Scheduler
</a></h3>
744 <p>Filters and backends communicate with the scheduler by writing messages
745 to the standard error file. The scheduler reads messages from all filters in
746 a job and processes the message based on its prefix. For example, the following
747 code sets the current printer state message to
"Printing page 5":
</p>
749 <pre class=
"example">
752 fprintf(stderr,
"INFO: Printing page %d\n", page);
755 <p>Each message is a single line of text starting with one of the following
760 <dt>ALERT: message
</dt>
761 <dd>Sets the printer-state-message attribute and adds the specified
762 message to the current error log file using the
"alert" log level.
</dd>
764 <dt>ATTR: attribute=value [attribute=value]
</dt>
765 <dd>Sets the named printer or job attribute(s). Typically this is used
766 to set the
<code>marker-colors
</code>,
<code>marker-high-levels
</code>,
767 <code>marker-levels
</code>,
<code>marker-low-levels
</code>,
768 <code>marker-message
</code>,
<code>marker-names
</code>,
769 <code>marker-types
</code>,
<code>printer-alert
</code>, and
770 <code>printer-alert-description
</code> printer attributes. Standard
771 <code>marker-types
</code> values are listed in
<a href='#TABLE1'
>Table
772 1</a>. String values need special handling - see
<a href=
"#ATTR_STRINGS">Reporting Attribute String Values
</a> below.
</dd>
774 <dt>CRIT: message
</dt>
775 <dd>Sets the printer-state-message attribute and adds the specified
776 message to the current error log file using the
"critical" log
779 <dt>DEBUG: message
</dt>
780 <dd>Sets the printer-state-message attribute and adds the specified
781 message to the current error log file using the
"debug" log level.
</dd>
783 <dt>DEBUG2: message
</dt>
784 <dd>Sets the printer-state-message attribute and adds the specified
785 message to the current error log file using the
"debug2" log level.
</dd>
787 <dt>EMERG: message
</dt>
788 <dd>Sets the printer-state-message attribute and adds the specified
789 message to the current error log file using the
"emergency" log
792 <dt>ERROR: message
</dt>
793 <dd>Sets the printer-state-message attribute and adds the specified
794 message to the current error log file using the
"error" log level.
795 Use
"ERROR:" messages for non-persistent processing errors.
</dd>
797 <dt>INFO: message
</dt>
798 <dd>Sets the printer-state-message attribute. If the current log level
799 is set to
"debug2", also adds the specified message to the current error
800 log file using the
"info" log level.
</dd>
802 <dt>NOTICE: message
</dt>
803 <dd>Sets the printer-state-message attribute and adds the specified
804 message to the current error log file using the
"notice" log level.
</dd>
806 <dt>PAGE: page-number #-copies
</dt>
807 <dt>PAGE: total #-pages
</dt>
808 <dd>Adds an entry to the current page log file. The first form adds
809 #-copies to the job-media-sheets-completed attribute. The second
810 form sets the job-media-sheets-completed attribute to #-pages.
</dd>
812 <dt>PPD: keyword=value [keyword=value ...]
</dt>
813 <dd>Changes or adds keywords to the printer's PPD file. Typically
814 this is used to update installable options or default media settings
815 based on the printer configuration.
</dd>
817 <dt>STATE: + printer-state-reason [printer-state-reason ...]
</dt>
818 <dt>STATE: - printer-state-reason [printer-state-reason ...]
</dt>
819 <dd>Sets or clears printer-state-reason keywords for the current queue.
820 Typically this is used to indicate persistent media, ink, toner, and
821 configuration conditions or errors on a printer.
822 <a href='#TABLE2'
>Table
2</a> lists some of the standard
"printer-state-reasons" keywords from the
<a href=
"http://www.iana.org/assignments/ipp-registrations/ipp-registrations.xhtml#ipp-registrations-4">IANA IPP Registry
</a> -
823 use vendor-prefixed (
"com.example.foo") keywords for custom states. See
824 <a href=
"#MANAGING_STATE">Managing Printer State in a Filter
</a> for more
827 <dt>WARNING: message
</dt>
828 <dd>Sets the printer-state-message attribute and adds the specified
829 message to the current error log file using the
"warning" log
834 <p>Messages without one of these prefixes are treated as if they began with
835 the
"DEBUG:" prefix string.
</p>
837 <div class='table'
><table width='
80%' summary='Table
1: Standard marker-types Values'
>
838 <caption>Table
1:
<a name='TABLE1'
>Standard marker-types Values
</a></caption>
848 <td>Developer unit
</td>
855 <td>fuser-cleaning-pad
</td>
856 <td>Fuser cleaning pad
</td>
868 <td>Photo conductor
</td>
876 <td>Staple supply
</td>
880 <td>Toner supply
</td>
883 <td>transfer-unit
</td>
884 <td>Transfer unit
</td>
888 <td>Waste ink tank
</td>
892 <td>Waste toner tank
</td>
896 <td>Waste wax tank
</td>
903 <div class='table'
><table width='
80%' summary='Table
2: Standard State Keywords'
>
904 <caption>Table
2:
<a name='TABLE2'
>Standard State Keywords
</a></caption>
913 <td>connecting-to-device
</td>
914 <td>Connecting to printer but not printing yet.
</td>
918 <td>The printer's cover is open.
</td>
921 <td>input-tray-missing
</td>
922 <td>The paper tray is missing.
</td>
925 <td>marker-supply-empty
</td>
926 <td>The printer is out of ink.
</td>
929 <td>marker-supply-low
</td>
930 <td>The printer is almost out of ink.
</td>
933 <td>marker-waste-almost-full
</td>
934 <td>The printer's waste bin is almost full.
</td>
937 <td>marker-waste-full
</td>
938 <td>The printer's waste bin is full.
</td>
942 <td>The paper tray (any paper tray) is empty.
</td>
946 <td>There is a paper jam.
</td>
950 <td>The paper tray (any paper tray) is almost empty.
</td>
953 <td>media-needed
</td>
954 <td>The paper tray needs to be filled (for a job that is printing).
</td>
958 <td>Stop the printer.
</td>
962 <td>Unable to connect to printer.
</td>
966 <td>The printer is out of toner.
</td>
970 <td>The printer is low on toner.
</td>
976 <h4><a name=
"ATTR_STRINGS">Reporting Attribute String Values
</a></h4>
978 <p>When reporting string values using
"ATTR:" messages, a filter or backend must take special care to appropriately quote those values. The scheduler uses the CUPS option parsing code for attributes, so the general syntax is:
</p>
980 <pre class=
"example">
982 name=simple,simple,...
985 name='
"complex value"','
"complex value"',...
988 <p>Simple values are strings that do not contain spaces, quotes, backslashes, or the comma and can be placed verbatim in the
"ATTR:" message, for example:
</p>
990 <pre class=
"example">
991 int levels[
4] = {
40,
50,
60,
70 }; /* CMYK */
993 fputs(
"ATTR: marker-colors=#00FFFF,#FF00FF,#FFFF00,#000000\n", stderr);
994 fputs(
"ATTR: marker-high-levels=100,100,100,100\n", stderr);
995 fprintf(stderr,
"ATTR: marker-levels=%d,%d,%d,%d\n", levels[
0], levels[
1],
996 levels[
2], levels[
3], levels[
4]);
997 fputs(
"ATTR: marker-low-levels=5,5,5,5\n", stderr);
998 fputs(
"ATTR: marker-types=toner,toner,toner,toner\n", stderr);
1001 <p>Complex values that contains spaces, quotes, backslashes, or the comma must be quoted. For a single value a single set of quotes is sufficient:
</p>
1003 <pre class=
"example">
1004 fputs(
"ATTR: marker-message='Levels shown are approximate.'\n", stderr);
1007 <p>When multiple values are reported, each value must be enclosed by a set of single and double quotes:
</p>
1009 <pre class=
"example">
1010 fputs(
"ATTR: marker-names='\"Cyan Toner\
"','\"Magenta Toner\
"',"
1011 "'\"Yellow Toner\
"','\"Black Toner\
"'\n", stderr);
1014 <p>The IPP backend includes a
<var>quote_string
</var> function that may be used to properly quote a complex value in an
"ATTR:" message:
</p>
1016 <pre class=
"example">
1017 static const char * /* O - Quoted string */
1018 quote_string(const char *s, /* I - String */
1019 char *q, /* I - Quoted string buffer */
1020 size_t qsize) /* I - Size of quoted string buffer */
1022 char *qptr, /* Pointer into string buffer */
1023 *qend; /* End of string buffer */
1027 qend = q + qsize -
5;
1038 while (*s && qptr < qend)
1040 if (*s == '\\' || *s == '\"' || *s == '\'')
1042 if (qptr
< (qend -
4))
1064 <h4><a name="MANAGING_STATE
">Managing Printer State in a Filter</a></h4>
1066 <p>Filters are responsible for managing the state keywords they set using
1067 "STATE:
" messages. Typically you will update <em>all</em> of the keywords that
1068 are used by the filter at startup, for example:</p>
1070 <pre class="example
">
1071 if (foo_condition != 0)
1072 fputs("STATE: +com.example.foo\n
", stderr);
1074 fputs("STATE: -com.example.foo\n
", stderr);
1076 if (bar_condition != 0)
1077 fputs("STATE: +com.example.bar\n
", stderr);
1079 fputs("STATE: -com.example.bar\n
", stderr);
1082 <p>Then as conditions change, your filter sends "STATE: +keyword
" or "STATE:
1083 -keyword
" messages as necessary to set or clear the corresponding keyword,
1086 <p>State keywords are often used to notify the user of issues that span across
1087 jobs, for example "media-empty-warning
" that indicates one or more paper trays
1088 are empty. These keywords should not be cleared unless the corresponding issue
1089 no longer exists.</p>
1091 <p>Filters should clear job-related keywords on startup and exit so that they
1092 do not remain set between jobs. For example, "connecting-to-device
" is a job
1093 sub-state and not an issue that applies when a job is not printing.</p>
1095 <blockquote><b>Note:</b>
1097 <p>"STATE:
" messages often provide visible alerts to the user. For example,
1098 on macOS setting a printer-state-reason value with an "-error
" or
1099 "-warning
" suffix will cause the printer's dock item to bounce if the
1100 corresponding reason is localized with a cupsIPPReason keyword in the
1101 printer's PPD file.</p>
1103 <p>When providing a vendor-prefixed keyword, <em>always</em> provide the
1104 corresponding standard keyword (if any) to allow clients to respond to the
1105 condition correctly. For example, if you provide a vendor-prefixed keyword
1106 for a low cyan ink condition ("com.example.cyan-ink-low
") you must also set the
1107 "marker-supply-low-warning
" keyword. In such cases you should also refrain
1108 from localizing the vendor-prefixed keyword in the PPD file - otherwise both
1109 the generic and vendor-specific keyword will be shown in the user
1114 <h4><a name="REPORTING_SUPPLIES
">Reporting Supply Levels</a></h4>
1116 <p>CUPS tracks several "marker-*
" attributes for ink/toner supply level
1117 reporting. These attributes allow applications to display the current supply
1118 levels for a printer without printer-specific software. <a href="#TABLE3
">Table 3</a> lists the marker attributes and what they represent.</p>
1120 <p>Filters set marker attributes by sending "ATTR:
" messages to stderr. For
1121 example, a filter supporting an inkjet printer with black and tri-color ink
1122 cartridges would use the following to initialize the supply attributes:</p>
1124 <pre class="example
">
1125 fputs("ATTR: marker-colors=#
000000,#
00FFFF#FF00FF#FFFF00\n
", stderr);
1126 fputs("ATTR: marker-low-levels=
5,
10\n
", stderr);
1127 fputs("ATTR: marker-names=Black,Tri-Color\n
", stderr);
1128 fputs("ATTR: marker-types=ink,ink\n
", stderr);
1131 <p>Then periodically the filter queries the printer for its current supply
1132 levels and updates them with a separate "ATTR:
" message:</p>
1134 <pre class="example
">
1135 int black_level, tri_level;
1137 fprintf(stderr, "ATTR: marker-levels=%d,%d\n
", black_level, tri_level);
1140 <div class='table'><table width='80%' summary='Table 3: Supply Level Attributes'>
1141 <caption>Table 3: <a name='TABLE3'>Supply Level Attributes</a></caption>
1145 <th>Description</th>
1150 <td>marker-colors</td>
1151 <td>A list of comma-separated colors; each color is either "none
" or one or
1152 more hex-encoded sRGB colors of the form "#RRGGBB
".</td>
1155 <td>marker-high-levels</td>
1156 <td>A list of comma-separated "almost full
" level values from 0 to 100; a
1157 value of 100 should be used for supplies that are consumed/emptied like ink
1161 <td>marker-levels</td>
1162 <td>A list of comma-separated level values for each supply. A value of -1
1163 indicates the level is unavailable, -2 indicates unknown, and -3 indicates
1164 the level is unknown but has not yet reached capacity. Values from 0 to 100
1165 indicate the corresponding percentage.</td>
1168 <td>marker-low-levels</td>
1169 <td>A list of comma-separated "almost empty
" level values from 0 to 100; a
1170 value of 0 should be used for supplies that are filled like waste ink
1174 <td>marker-message</td>
1175 <td>A human-readable supply status message for the user like "12 pages of
1176 ink remaining.
"</td>
1179 <td>marker-names</td>
1180 <td>A list of comma-separated supply names like "Cyan Ink
", "Fuser
",
1184 <td>marker-types</td>
1185 <td>A list of comma-separated supply types; the types are listed in
1186 <a href="#TABLE1
">Table 1</a>.</td>
1191 <h3><a name="COMMUNICATING_BACKEND
">Communicating with the Backend</a></h3>
1193 <p>Filters can communicate with the backend via the
1194 <a href="#cupsBackChannelRead
"><code>cupsBackChannelRead</code></a> and
1195 <a href="#cupsSideChannelDoRequest
"><code>cupsSideChannelDoRequest</code></a>
1197 <a href="#cupsBackChannelRead
"><code>cupsBackChannelRead</code></a> function
1198 reads data that has been sent back from the device and is typically used to
1199 obtain status and configuration information. For example, the following code
1200 polls the backend for back-channel data:</p>
1202 <pre class="example
">
1203 #include <cups/cups.h>
1208 /* Use a timeout of 0.0 seconds to poll for back-channel data */
1209 bytes = cupsBackChannelRead(buffer, sizeof(buffer), 0.0);
1212 <p>Filters can also use <code>select()</code> or <code>poll()</code> on the
1213 back-channel file descriptor (3 or <code>CUPS_BC_FD</code>) to read data only
1214 when it is available.</p>
1217 <a href="#cupsSideChannelDoRequest
"><code>cupsSideChannelDoRequest</code></a>
1218 function allows you to get out-of-band status information and do synchronization
1219 with the device. For example, the following code gets the current IEEE-1284
1220 device ID string from the backend:</p>
1222 <pre class="example
">
1223 #include <cups/sidechannel.h>
1227 <a href="#cups_sc_status_t
">cups_sc_status_t</a> status;
1229 /* Tell cupsSideChannelDoRequest() how big our buffer is, less 1 byte for
1230 nul-termination... */
1231 datalen = sizeof(data) - 1;
1233 /* Get the IEEE-1284 device ID, waiting for up to 1 second */
1234 status = <a href="#cupsSideChannelDoRequest
">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_GET_DEVICE_ID, data, &datalen, 1.0);
1236 /* Use the returned value if OK was returned and the length is non-zero */
1237 if (status == CUPS_SC_STATUS_OK && datalen > 0)
1238 data[datalen] = '\0';
1243 <h4><a name="DRAIN_OUTPUT
">Forcing All Output to a Printer</a></h4>
1246 <a href="#cupsSideChannelDoRequest
"><code>cupsSideChannelDoRequest</code></a>
1247 function allows you to tell the backend to send all pending data to the printer.
1248 This is most often needed when sending query commands to the printer. For example:</p>
1250 <pre class="example
">
1251 #include <cups/cups.h>
1252 #include <cups/sidechannel.h>
1255 int datalen = sizeof(data);
1256 <a href="#cups_sc_status_t
">cups_sc_status_t</a> status;
1258 /* Flush pending output to stdout */
1261 /* Drain output to backend, waiting for up to 30 seconds */
1262 status = <a href="#cupsSideChannelDoRequest
">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_DRAIN_OUTPUT, data, &datalen, 30.0);
1264 /* Read the response if the output was sent */
1265 if (status == CUPS_SC_STATUS_OK)
1269 /* Wait up to 10.0 seconds for back-channel data */
1270 bytes = cupsBackChannelRead(data, sizeof(data), 10.0);
1271 /* do something with the data from the printer */
1275 <h3><a name="COMMUNICATING_FILTER
">Communicating with Filters</a></h3>
1277 <p>Backends communicate with filters using the reciprocal functions
1278 <a href="#cupsBackChannelWrite
"><code>cupsBackChannelWrite</code></a>,
1279 <a href="#cupsSideChannelRead
"><code>cupsSideChannelRead</code></a>, and
1280 <a href="#cupsSideChannelWrite
"><code>cupsSideChannelWrite</code></a>. We
1281 recommend writing back-channel data using a timeout of 1.0 seconds:</p>
1283 <pre class="example
">
1284 #include <cups/cups.h>
1289 /* Obtain data from printer/device */
1292 /* Use a timeout of 1.0 seconds to give filters a chance to read */
1293 cupsBackChannelWrite(buffer, bytes, 1.0);
1296 <p>The <a href="#cupsSideChannelRead
"><code>cupsSideChannelRead</code></a>
1297 function reads a side-channel command from a filter, driver, or port monitor.
1298 Backends can either poll for commands using a <code>timeout</code> of 0.0, wait
1299 indefinitely for commands using a <code>timeout</code> of -1.0 (probably in a
1300 separate thread for that purpose), or use <code>select</code> or
1301 <code>poll</code> on the <code>CUPS_SC_FD</code> file descriptor (4) to handle
1302 input and output on several file descriptors at the same time.</p>
1304 <p>Once a command is processed, the backend uses the
1305 <a href="#cupsSideChannelWrite
"><code>cupsSideChannelWrite</code></a> function
1306 to send its response. For example, the following code shows how to poll for a
1307 side-channel command and respond to it:</p>
1309 <pre class="example
">
1310 #include <cups/sidechannel.h>
1312 <a href="#cups_sc_command_t
">cups_sc_command_t</a> command;
1313 <a href="#cups_sc_status_t
">cups_sc_status_t</a> status;
1315 int datalen = sizeof(data);
1317 /* Poll for a command... */
1318 if (!<a href="#cupsSideChannelRead
">cupsSideChannelRead</a>(&command, &status, data, &datalen, 0.0))
1322 /* handle supported commands, fill data/datalen/status with values as needed */
1325 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
1330 /* Send a response... */
1331 <a href="#cupsSideChannelWrite
">cupsSideChannelWrite</a>(command, status, data, datalen, 1.0);
1335 <h3><a name="SNMP
">Doing SNMP Queries with Network Printers</a></h3>
1337 <p>The Simple Network Management Protocol (SNMP) allows you to get the current
1338 status, page counter, and supply levels from most network printers. Every
1339 piece of information is associated with an Object Identifier (OID), and
1340 every printer has a <em>community</em> name associated with it. OIDs can be
1341 queried directly or by "walking
" over a range of OIDs with a common prefix.</p>
1343 <p>The two CUPS SNMP functions provide a simple API for querying network
1344 printers through the side-channel interface. Each accepts a string containing
1345 an OID like ".1.3.6.1.2.1.43.10.2.1.4.1.1" (the standard page counter OID)
1346 along with a timeout for the query.</p>
1348 <p>The <a href="#cupsSideChannelSNMPGet
"><code>cupsSideChannelSNMPGet</code></a>
1349 function queries a single OID and returns the value as a string in a buffer
1352 <pre class="example
">
1353 #include <cups/sidechannel.h>
1356 int datalen = sizeof(data);
1358 if (<a href="#cupsSideChannelSNMPGet
">cupsSideChannelSNMPGet</a>(".1.3.6.1.2.1.43.10.2.1.4.1.1", data, &datalen, 5.0)
1359 == CUPS_SC_STATUS_OK)
1361 /* Do something with the value */
1362 printf("Page counter is: %s\n
", data);
1367 <a href="#cupsSideChannelSNMPWalk
"><code>cupsSideChannelSNMPWalk</code></a>
1368 function allows you to query a whole group of OIDs, calling a function of your
1369 choice for each OID that is found:</p>
1371 <pre class="example
">
1372 #include <cups/sidechannel.h>
1375 my_callback(const char *oid, const char *data, int datalen, void *context)
1377 /* Do something with the value */
1378 printf("%s=%s\n
", oid, data);
1385 <a href="#cupsSideChannelSNMPWalk
">cupsSNMPSideChannelWalk</a>(".1.3.6.1.2.1.43", 5.0, my_callback, my_data);
1388 <h2><a name="SANDBOXING
">Sandboxing on macOS</a></h2>
1390 <p>Starting with macOS 10.6, filters and backends are run inside a security "sandbox
" which further limits (beyond the normal UNIX user/group permissions) what a filter or backend can do. This helps to both secure the printing system from malicious software and enforce the functional separation of components in the CUPS filter chain. What follows is a list of actions that are explicitly allowed for all filters and backends:</p>
1394 <li>Reading of files: pursuant to normal UNIX file permissions, filters and backends can read files for the current job from the <var>/private/var/spool/cups</var> directory and other files on mounted filesystems <em>except</em> for user home directories under <var>/Users</var>.</li>
1396 <li>Writing of files: pursuant to normal UNIX file permissions, filters and backends can read/write files to the cache directory specified by the <code>CUPS_CACHEDIR</code> environment variable, to the state directory specified by the <code>CUPS_STATEDIR</code> environment variable, to the temporary directory specified by the <code>TMPDIR</code> environment variable, and under the <var>/private/var/db</var>, <var>/private/var/folders</var>, <var>/private/var/lib</var>, <var>/private/var/mysql</var>, <var>/private/var/run</var>, <var>/private/var/spool</var> (except <var>/private/var/spool/cups</var>), <var>/Library/Application Support</var>, <var>/Library/Caches</var>, <var>/Library/Logs</var>, <var>/Library/Preferences</var>, <var>/Library/WebServer</var>, and <var>/Users/Shared</var> directories.</li>
1398 <li>Execution of programs: pursuant to normal UNIX file permissions, filters and backends can execute any program not located under the <var>/Users</var> directory. Child processes inherit the sandbox and are subject to the same restrictions as the parent.</li>
1400 <li>Bluetooth and USB: backends can access Bluetooth and USB printers through IOKit. <em>Filters cannot access Bluetooth and USB printers directly.</em></li>
1402 <li>Network: filters and backends can access UNIX domain sockets under the <var>/private/tmp</var>, <var>/private/var/run</var>, and <var>/private/var/tmp</var> directories. Backends can also create IPv4 and IPv6 TCP (outgoing) and UDP (incoming and outgoing) socket, and bind to local source ports. <em>Filters cannot directly create IPv4 and IPv6 TCP or UDP sockets.</em></li>
1404 <li>Notifications: filters and backends can send notifications via the Darwin <code>notify_post()</code> API.</li>
1408 <blockquote><b>Note:</b>
1410 <p>The sandbox profile used in CUPS still allows some actions that are not listed above - these privileges will be removed over time until the profile matches the list above.</p>
1412 <h2 class="title
"><a id="FUNCTIONS
">Functions</a></h2>
1413 <h3 class="function
"><span class="info
"> CUPS 1.2/macOS 10.5 </span><a id="cupsBackChannelRead
">cupsBackChannelRead</a></h3>
1414 <p class="description
">Read data from the backchannel.</p>
1416 ssize_t cupsBackChannelRead(char *buffer, size_t bytes, double timeout);</p>
1417 <h4 class="parameters
">Parameters</h4>
1418 <table class="list
"><tbody>
1420 <td class="description
">Buffer to read into</td></tr>
1422 <td class="description
">Bytes to read</td></tr>
1423 <tr><th>timeout</th>
1424 <td class="description
">Timeout in seconds, typically 0.0 to poll</td></tr>
1426 <h4 class="returnvalue
">Return Value</h4>
1427 <p class="description
">Bytes read or -1 on error</p>
1428 <h4 class="discussion
">Discussion</h4>
1429 <p class="discussion
">Reads up to "bytes" bytes from the backchannel/backend. The "timeout"
1430 parameter controls how many seconds to wait for the data - use 0.0 to
1431 return immediately if there is no data, -1.0 to wait for data indefinitely.
1434 <h3 class="function
"><span class="info
"> CUPS 1.2/macOS 10.5 </span><a id="cupsBackChannelWrite
">cupsBackChannelWrite</a></h3>
1435 <p class="description
">Write data to the backchannel.</p>
1437 ssize_t cupsBackChannelWrite(const char *buffer, size_t bytes, double timeout);</p>
1438 <h4 class="parameters
">Parameters</h4>
1439 <table class="list
"><tbody>
1441 <td class="description
">Buffer to write</td></tr>
1443 <td class="description
">Bytes to write</td></tr>
1444 <tr><th>timeout</th>
1445 <td class="description
">Timeout in seconds, typically 1.0</td></tr>
1447 <h4 class="returnvalue
">Return Value</h4>
1448 <p class="description
">Bytes written or -1 on error</p>
1449 <h4 class="discussion
">Discussion</h4>
1450 <p class="discussion
">Writes "bytes" bytes to the backchannel/filter. The "timeout" parameter
1451 controls how many seconds to wait for the data to be written - use
1452 0.0 to return immediately if the data cannot be written, -1.0 to wait
1456 <h3 class="function
"><span class="info
"> CUPS 1.2/macOS 10.5 </span><a id="cupsBackendDeviceURI
">cupsBackendDeviceURI</a></h3>
1457 <p class="description
">Get the device URI for a backend.</p>
1459 const char *cupsBackendDeviceURI(char **argv);</p>
1460 <h4 class="parameters
">Parameters</h4>
1461 <table class="list
"><tbody>
1463 <td class="description
">Command-line arguments</td></tr>
1465 <h4 class="returnvalue
">Return Value</h4>
1466 <p class="description
">Device URI or <code>NULL</code></p>
1467 <h4 class="discussion
">Discussion</h4>
1468 <p class="discussion
">The "argv" argument is the argv argument passed to main(). This
1469 function returns the device URI passed in the DEVICE_URI environment
1470 variable or the device URI passed in argv[0], whichever is found
1474 <h3 class="function
"><span class="info
"> CUPS 1.4/macOS 10.6 </span><a id="cupsBackendReport
">cupsBackendReport</a></h3>
1475 <p class="description
">Write a device line from a backend.</p>
1477 void cupsBackendReport(const char *device_scheme, const char *device_uri, const char *device_make_and_model, const char *device_info, const char *device_id, const char *device_location);</p>
1478 <h4 class="parameters
">Parameters</h4>
1479 <table class="list
"><tbody>
1480 <tr><th>device_scheme</th>
1481 <td class="description
">device-scheme string</td></tr>
1482 <tr><th>device_uri</th>
1483 <td class="description
">device-uri string</td></tr>
1484 <tr><th>device_make_and_model</th>
1485 <td class="description
">device-make-and-model string or <code>NULL</code></td></tr>
1486 <tr><th>device_info</th>
1487 <td class="description
">device-info string or <code>NULL</code></td></tr>
1488 <tr><th>device_id</th>
1489 <td class="description
">device-id string or <code>NULL</code></td></tr>
1490 <tr><th>device_location</th>
1491 <td class="description
">device-location string or <code>NULL</code></td></tr>
1493 <h4 class="discussion
">Discussion</h4>
1494 <p class="discussion
">This function writes a single device line to stdout for a backend.
1495 It handles quoting of special characters in the device-make-and-model,
1496 device-info, device-id, and device-location strings.
1499 <h3 class="function
"><span class="info
"> CUPS 1.3/macOS 10.5 </span><a id="cupsSideChannelDoRequest
">cupsSideChannelDoRequest</a></h3>
1500 <p class="description
">Send a side-channel command to a backend and wait for a response.</p>
1502 <a href="#cups_sc_status_t
">cups_sc_status_t</a> cupsSideChannelDoRequest(<a href="#cups_sc_command_t
">cups_sc_command_t</a> command, char *data, int *datalen, double timeout);</p>
1503 <h4 class="parameters
">Parameters</h4>
1504 <table class="list
"><tbody>
1505 <tr><th>command</th>
1506 <td class="description
">Command to send</td></tr>
1508 <td class="description
">Response data buffer pointer</td></tr>
1509 <tr><th>datalen</th>
1510 <td class="description
">Size of data buffer on entry, number of bytes in buffer on return</td></tr>
1511 <tr><th>timeout</th>
1512 <td class="description
">Timeout in seconds</td></tr>
1514 <h4 class="returnvalue
">Return Value</h4>
1515 <p class="description
">Status of command</p>
1516 <h4 class="discussion
">Discussion</h4>
1517 <p class="discussion
">This function is normally only called by filters, drivers, or port
1518 monitors in order to communicate with the backend used by the current
1519 printer. Programs must be prepared to handle timeout or "not
1520 implemented" status codes, which indicate that the backend or device
1521 do not support the specified side-channel command.<br>
1523 The "datalen" parameter must be initialized to the size of the buffer
1524 pointed to by the "data" parameter. cupsSideChannelDoRequest() will
1525 update the value to contain the number of data bytes in the buffer.
1528 <h3 class="function
"><span class="info
"> CUPS 1.3/macOS 10.5 </span><a id="cupsSideChannelRead
">cupsSideChannelRead</a></h3>
1529 <p class="description
">Read a side-channel message.</p>
1531 int cupsSideChannelRead(<a href="#cups_sc_command_t
">cups_sc_command_t</a> *command, <a href="#cups_sc_status_t
">cups_sc_status_t</a> *status, char *data, int *datalen, double timeout);</p>
1532 <h4 class="parameters
">Parameters</h4>
1533 <table class="list
"><tbody>
1534 <tr><th>command</th>
1535 <td class="description
">Command code</td></tr>
1537 <td class="description
">Status code</td></tr>
1539 <td class="description
">Data buffer pointer</td></tr>
1540 <tr><th>datalen</th>
1541 <td class="description
">Size of data buffer on entry, number of bytes in buffer on return</td></tr>
1542 <tr><th>timeout</th>
1543 <td class="description
">Timeout in seconds</td></tr>
1545 <h4 class="returnvalue
">Return Value</h4>
1546 <p class="description
">0 on success, -1 on error</p>
1547 <h4 class="discussion
">Discussion</h4>
1548 <p class="discussion
">This function is normally only called by backend programs to read
1549 commands from a filter, driver, or port monitor program. The
1550 caller must be prepared to handle incomplete or invalid messages
1551 and return the corresponding status codes.<br>
1553 The "datalen" parameter must be initialized to the size of the buffer
1554 pointed to by the "data" parameter. cupsSideChannelDoRequest() will
1555 update the value to contain the number of data bytes in the buffer.
1558 <h3 class="function
"><span class="info
"> CUPS 1.4/macOS 10.6 </span><a id="cupsSideChannelSNMPGet
">cupsSideChannelSNMPGet</a></h3>
1559 <p class="description
">Query a SNMP OID's value.</p>
1561 <a href="#cups_sc_status_t
">cups_sc_status_t</a> cupsSideChannelSNMPGet(const char *oid, char *data, int *datalen, double timeout);</p>
1562 <h4 class="parameters
">Parameters</h4>
1563 <table class="list
"><tbody>
1565 <td class="description
">OID to query</td></tr>
1567 <td class="description
">Buffer for OID value</td></tr>
1568 <tr><th>datalen</th>
1569 <td class="description
">Size of OID buffer on entry, size of value on return</td></tr>
1570 <tr><th>timeout</th>
1571 <td class="description
">Timeout in seconds</td></tr>
1573 <h4 class="returnvalue
">Return Value</h4>
1574 <p class="description
">Query status</p>
1575 <h4 class="discussion
">Discussion</h4>
1576 <p class="discussion
">This function asks the backend to do a SNMP OID query on behalf of the
1577 filter, port monitor, or backend using the default community name.<br>
1579 "oid" contains a numeric OID consisting of integers separated by periods,
1580 for example ".1.3.6.1.2.1.43". Symbolic names from SNMP MIBs are not
1581 supported and must be converted to their numeric forms.<br>
1583 On input, "data" and "datalen" provide the location and size of the
1584 buffer to hold the OID value as a string. HEX-String (binary) values are
1585 converted to hexadecimal strings representing the binary data, while
1586 NULL-Value and unknown OID types are returned as the empty string.
1587 The returned "datalen" does not include the trailing nul.
1589 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED</code> is returned by backends that do not
1590 support SNMP queries. <code>CUPS_SC_STATUS_NO_RESPONSE</code> is returned when
1591 the printer does not respond to the SNMP query.
1594 <h3 class="function
"><span class="info
"> CUPS 1.4/macOS 10.6 </span><a id="cupsSideChannelSNMPWalk
">cupsSideChannelSNMPWalk</a></h3>
1595 <p class="description
">Query multiple SNMP OID values.</p>
1597 <a href="#cups_sc_status_t
">cups_sc_status_t</a> cupsSideChannelSNMPWalk(const char *oid, double timeout, <a href="#cups_sc_walk_func_t
">cups_sc_walk_func_t</a> cb, void *context);</p>
1598 <h4 class="parameters
">Parameters</h4>
1599 <table class="list
"><tbody>
1601 <td class="description
">First numeric OID to query</td></tr>
1602 <tr><th>timeout</th>
1603 <td class="description
">Timeout for each query in seconds</td></tr>
1605 <td class="description
">Function to call with each value</td></tr>
1606 <tr><th>context</th>
1607 <td class="description
">Application-defined pointer to send to callback</td></tr>
1609 <h4 class="returnvalue
">Return Value</h4>
1610 <p class="description
">Status of first query of <code>CUPS_SC_STATUS_OK</code> on success</p>
1611 <h4 class="discussion
">Discussion</h4>
1612 <p class="discussion
">This function asks the backend to do multiple SNMP OID queries on behalf
1613 of the filter, port monitor, or backend using the default community name.
1614 All OIDs under the "parent" OID are queried and the results are sent to
1615 the callback function you provide.<br>
1617 "oid" contains a numeric OID consisting of integers separated by periods,
1618 for example ".1.3.6.1.2.1.43". Symbolic names from SNMP MIBs are not
1619 supported and must be converted to their numeric forms.<br>
1621 "timeout" specifies the timeout for each OID query. The total amount of
1622 time will depend on the number of OID values found and the time required
1625 "cb" provides a function to call for every value that is found. "context"
1626 is an application-defined pointer that is sent to the callback function
1627 along with the OID and current data. The data passed to the callback is the
1628 same as returned by <a href="#cupsSideChannelSNMPGet
"><code>cupsSideChannelSNMPGet</code></a>.
1630 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED</code> is returned by backends that do not
1631 support SNMP queries. <code>CUPS_SC_STATUS_NO_RESPONSE</code> is returned when
1632 the printer does not respond to the first SNMP query.
1635 <h3 class="function
"><span class="info
"> CUPS 1.3/macOS 10.5 </span><a id="cupsSideChannelWrite
">cupsSideChannelWrite</a></h3>
1636 <p class="description
">Write a side-channel message.</p>
1638 int cupsSideChannelWrite(<a href="#cups_sc_command_t
">cups_sc_command_t</a> command, <a href="#cups_sc_status_t
">cups_sc_status_t</a> status, const char *data, int datalen, double timeout);</p>
1639 <h4 class="parameters
">Parameters</h4>
1640 <table class="list
"><tbody>
1641 <tr><th>command</th>
1642 <td class="description
">Command code</td></tr>
1644 <td class="description
">Status code</td></tr>
1646 <td class="description
">Data buffer pointer</td></tr>
1647 <tr><th>datalen</th>
1648 <td class="description
">Number of bytes of data</td></tr>
1649 <tr><th>timeout</th>
1650 <td class="description
">Timeout in seconds</td></tr>
1652 <h4 class="returnvalue
">Return Value</h4>
1653 <p class="description
">0 on success, -1 on error</p>
1654 <h4 class="discussion
">Discussion</h4>
1655 <p class="discussion
">This function is normally only called by backend programs to send
1656 responses to a filter, driver, or port monitor program.
1659 <h2 class="title
"><a id="TYPES
">Data Types</a></h2>
1660 <h3 class="typedef
"><a id="cups_backend_t
">cups_backend_t</a></h3>
1661 <p class="description
">Backend exit codes</p>
1663 typedef enum <a href="#cups_backend_e
">cups_backend_e</a> cups_backend_t;
1665 <h3 class="typedef
"><a id="cups_sc_bidi_t
">cups_sc_bidi_t</a></h3>
1666 <p class="description
">Bidirectional capabilities</p>
1668 typedef enum <a href="#cups_sc_bidi_e
">cups_sc_bidi_e</a> cups_sc_bidi_t;
1670 <h3 class="typedef
"><a id="cups_sc_command_t
">cups_sc_command_t</a></h3>
1671 <p class="description
">Request command codes</p>
1673 typedef enum <a href="#cups_sc_command_e
">cups_sc_command_e</a> cups_sc_command_t;
1675 <h3 class="typedef
"><a id="cups_sc_connected_t
">cups_sc_connected_t</a></h3>
1676 <p class="description
">Connectivity values</p>
1678 typedef enum <a href="#cups_sc_connected_e
">cups_sc_connected_e</a> cups_sc_connected_t;
1680 <h3 class="typedef
"><a id="cups_sc_state_t
">cups_sc_state_t</a></h3>
1681 <p class="description
">Printer state bits</p>
1683 typedef enum <a href="#cups_sc_state_e
">cups_sc_state_e</a> cups_sc_state_t;
1685 <h3 class="typedef
"><a id="cups_sc_status_t
">cups_sc_status_t</a></h3>
1686 <p class="description
">Response status codes</p>
1688 typedef enum <a href="#cups_sc_status_e
">cups_sc_status_e</a> cups_sc_status_t;
1690 <h3 class="typedef
"><a id="cups_sc_walk_func_t
">cups_sc_walk_func_t</a></h3>
1691 <p class="description
">SNMP walk callback</p>
1693 typedef void (*cups_sc_walk_func_t)(const char *oid, const char *data, int datalen, void *context);
1695 <h2 class="title
"><a id="ENUMERATIONS
">Constants</a></h2>
1696 <h3 class="enumeration
"><a id="cups_backend_e
">cups_backend_e</a></h3>
1697 <p class="description
">Backend exit codes</p>
1698 <h4 class="constants
">Constants</h4>
1699 <table class="list
"><tbody>
1700 <tr><th>CUPS_BACKEND_AUTH_REQUIRED </th> <td class="description
">Job failed, authentication required</td></tr>
1701 <tr><th>CUPS_BACKEND_CANCEL </th> <td class="description
">Job failed, cancel job</td></tr>
1702 <tr><th>CUPS_BACKEND_FAILED </th> <td class="description
">Job failed, use error-policy</td></tr>
1703 <tr><th>CUPS_BACKEND_HOLD </th> <td class="description
">Job failed, hold job</td></tr>
1704 <tr><th>CUPS_BACKEND_OK </th> <td class="description
">Job completed successfully</td></tr>
1705 <tr><th>CUPS_BACKEND_RETRY </th> <td class="description
">Job failed, retry this job later</td></tr>
1706 <tr><th>CUPS_BACKEND_RETRY_CURRENT </th> <td class="description
">Job failed, retry this job immediately</td></tr>
1707 <tr><th>CUPS_BACKEND_STOP </th> <td class="description
">Job failed, stop queue</td></tr>
1709 <h3 class="enumeration
"><a id="cups_sc_bidi_e
">cups_sc_bidi_e</a></h3>
1710 <p class="description
">Bidirectional capability values</p>
1711 <h4 class="constants
">Constants</h4>
1712 <table class="list
"><tbody>
1713 <tr><th>CUPS_SC_BIDI_NOT_SUPPORTED </th> <td class="description
">Bidirectional I/O is not supported</td></tr>
1714 <tr><th>CUPS_SC_BIDI_SUPPORTED </th> <td class="description
">Bidirectional I/O is supported</td></tr>
1716 <h3 class="enumeration
"><a id="cups_sc_command_e
">cups_sc_command_e</a></h3>
1717 <p class="description
">Request command codes</p>
1718 <h4 class="constants
">Constants</h4>
1719 <table class="list
"><tbody>
1720 <tr><th>CUPS_SC_CMD_DRAIN_OUTPUT </th> <td class="description
">Drain all pending output</td></tr>
1721 <tr><th>CUPS_SC_CMD_GET_BIDI </th> <td class="description
">Return bidirectional capabilities</td></tr>
1722 <tr><th>CUPS_SC_CMD_GET_CONNECTED <span class="info
"> CUPS 1.5/macOS 10.7 </span></th> <td class="description
">Return whether the backend is "connected" to the printer </td></tr>
1723 <tr><th>CUPS_SC_CMD_GET_DEVICE_ID </th> <td class="description
">Return the IEEE-1284 device ID</td></tr>
1724 <tr><th>CUPS_SC_CMD_GET_STATE </th> <td class="description
">Return the device state</td></tr>
1725 <tr><th>CUPS_SC_CMD_SNMP_GET <span class="info
"> CUPS 1.4/macOS 10.6 </span></th> <td class="description
">Query an SNMP OID </td></tr>
1726 <tr><th>CUPS_SC_CMD_SNMP_GET_NEXT <span class="info
"> CUPS 1.4/macOS 10.6 </span></th> <td class="description
">Query the next SNMP OID </td></tr>
1727 <tr><th>CUPS_SC_CMD_SOFT_RESET </th> <td class="description
">Do a soft reset</td></tr>
1729 <h3 class="enumeration
"><a id="cups_sc_connected_e
">cups_sc_connected_e</a></h3>
1730 <p class="description
">Connectivity values</p>
1731 <h4 class="constants
">Constants</h4>
1732 <table class="list
"><tbody>
1733 <tr><th>CUPS_SC_CONNECTED </th> <td class="description
">Backend is "connected" to printer</td></tr>
1734 <tr><th>CUPS_SC_NOT_CONNECTED </th> <td class="description
">Backend is not "connected" to printer</td></tr>
1736 <h3 class="enumeration
"><a id="cups_sc_state_e
">cups_sc_state_e</a></h3>
1737 <p class="description
">Printer state bits</p>
1738 <h4 class="constants
">Constants</h4>
1739 <table class="list
"><tbody>
1740 <tr><th>CUPS_SC_STATE_BUSY </th> <td class="description
">Device is busy</td></tr>
1741 <tr><th>CUPS_SC_STATE_ERROR </th> <td class="description
">Other error condition</td></tr>
1742 <tr><th>CUPS_SC_STATE_MARKER_EMPTY </th> <td class="description
">Toner/ink out condition</td></tr>
1743 <tr><th>CUPS_SC_STATE_MARKER_LOW </th> <td class="description
">Toner/ink low condition</td></tr>
1744 <tr><th>CUPS_SC_STATE_MEDIA_EMPTY </th> <td class="description
">Paper out condition</td></tr>
1745 <tr><th>CUPS_SC_STATE_MEDIA_LOW </th> <td class="description
">Paper low condition</td></tr>
1746 <tr><th>CUPS_SC_STATE_OFFLINE </th> <td class="description
">Device is offline</td></tr>
1747 <tr><th>CUPS_SC_STATE_ONLINE </th> <td class="description
">Device is online</td></tr>
1749 <h3 class="enumeration
"><a id="cups_sc_status_e
">cups_sc_status_e</a></h3>
1750 <p class="description
">Response status codes</p>
1751 <h4 class="constants
">Constants</h4>
1752 <table class="list
"><tbody>
1753 <tr><th>CUPS_SC_STATUS_BAD_MESSAGE </th> <td class="description
">The command/response message was invalid</td></tr>
1754 <tr><th>CUPS_SC_STATUS_IO_ERROR </th> <td class="description
">An I/O error occurred</td></tr>
1755 <tr><th>CUPS_SC_STATUS_NONE </th> <td class="description
">No status</td></tr>
1756 <tr><th>CUPS_SC_STATUS_NOT_IMPLEMENTED </th> <td class="description
">Command not implemented</td></tr>
1757 <tr><th>CUPS_SC_STATUS_NO_RESPONSE </th> <td class="description
">The device did not respond</td></tr>
1758 <tr><th>CUPS_SC_STATUS_OK </th> <td class="description
">Operation succeeded</td></tr>
1759 <tr><th>CUPS_SC_STATUS_TIMEOUT </th> <td class="description
">The backend did not respond</td></tr>
1760 <tr><th>CUPS_SC_STATUS_TOO_BIG </th> <td class="description
">Response too big</td></tr>