]> git.ipfire.org Git - thirdparty/cups.git/blob - doc/help/api-filter.html
More man page modernization.
[thirdparty/cups.git] / doc / help / api-filter.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- SECTION: Programming -->
4 <head>
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="Mini-XML v2.7">
9 <style type="text/css"><!--
10 BODY {
11 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
12 }
13
14 H1, H2, H3, H4, H5, H6, P, TD, TH {
15 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
16 }
17
18 KBD {
19 font-family: monaco, courier, monospace;
20 font-weight: bold;
21 }
22
23 PRE {
24 font-family: monaco, courier, monospace;
25 }
26
27 PRE.command {
28 border: dotted thin #7f7f7f;
29 margin-left: 36pt;
30 padding: 10px;
31 }
32
33 P.compact {
34 margin: 0;
35 }
36
37 P.example {
38 font-style: italic;
39 margin-left: 36pt;
40 }
41
42 PRE.example {
43 background: #eeeeee;
44 border: dotted thin #999999;
45 margin-left: 36pt;
46 padding: 10pt;
47 }
48
49 PRE.command EM, PRE.example EM {
50 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
51 }
52
53 P.command {
54 font-family: monaco, courier, monospace;
55 margin-left: 36pt;
56 }
57
58 P.formula {
59 font-style: italic;
60 margin-left: 36pt;
61 }
62
63 BLOCKQUOTE {
64 background: #eeeeee;
65 border: solid thin #999999;
66 padding: 10pt;
67 }
68
69 A IMG {
70 border: none;
71 }
72
73 A:link:hover IMG {
74 background: #f0f0f0;
75 border-radius: 10px;
76 -moz-border-radius: 10px;
77 }
78
79 A:link, A:visited {
80 font-weight: inherit;
81 text-decoration: none;
82 }
83
84 A:link:hover, A:visited:hover, A:active {
85 text-decoration: underline;
86 }
87
88 SUB, SUP {
89 font-size: 50%;
90 }
91
92 TR.data, TD.data, TR.data TD {
93 margin-top: 10pt;
94 padding: 5pt;
95 border-bottom: solid 1pt #999999;
96 }
97
98 TR.data TH {
99 border-bottom: solid 1pt #999999;
100 padding-top: 10pt;
101 padding-left: 5pt;
102 text-align: left;
103 }
104
105 DIV.table TABLE {
106 border: solid thin #999999;
107 border-collapse: collapse;
108 border-spacing: 0;
109 margin-left: auto;
110 margin-right: auto;
111 }
112
113 DIV.table CAPTION {
114 caption-side: top;
115 font-size: 120%;
116 font-style: italic;
117 font-weight: bold;
118 margin-left: auto;
119 margin-right: auto;
120 }
121
122 DIV.table TABLE TD {
123 border: solid thin #cccccc;
124 padding-top: 5pt;
125 }
126
127 DIV.table TABLE TH {
128 background: #cccccc;
129 border: none;
130 border-bottom: solid thin #999999;
131 }
132
133 DIV.figure TABLE {
134 margin-left: auto;
135 margin-right: auto;
136 }
137
138 DIV.figure CAPTION {
139 caption-side: bottom;
140 font-size: 120%;
141 font-style: italic;
142 font-weight: bold;
143 margin-left: auto;
144 margin-right: auto;
145 }
146
147 TH.label {
148 text-align: right;
149 vertical-align: top;
150 }
151
152 TH.sublabel {
153 text-align: right;
154 font-weight: normal;
155 }
156
157 HR {
158 border: solid thin;
159 }
160
161 SPAN.info {
162 background: black;
163 border: thin solid black;
164 color: white;
165 font-size: 80%;
166 font-style: italic;
167 font-weight: bold;
168 white-space: nowrap;
169 }
170
171 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
172 float: right;
173 font-size: 100%;
174 }
175
176 H1.title {
177 }
178
179 H2.title, H3.title {
180 border-bottom: solid 2pt #000000;
181 }
182
183 DIV.indent, TABLE.indent {
184 margin-top: 2em;
185 margin-left: auto;
186 margin-right: auto;
187 width: 90%;
188 }
189
190 TABLE.indent {
191 border-collapse: collapse;
192 }
193
194 TABLE.indent TD, TABLE.indent TH {
195 padding: 0;
196 }
197
198 TABLE.list {
199 border-collapse: collapse;
200 margin-left: auto;
201 margin-right: auto;
202 width: 90%;
203 }
204
205 TABLE.list TH {
206 background: white;
207 border-bottom: solid thin #cccccc;
208 color: #444444;
209 padding-top: 10pt;
210 padding-left: 5pt;
211 text-align: left;
212 vertical-align: bottom;
213 white-space: nowrap;
214 }
215
216 TABLE.list TH A {
217 color: #4444cc;
218 }
219
220 TABLE.list TD {
221 border-bottom: solid thin #eeeeee;
222 padding-top: 5pt;
223 padding-left: 5pt;
224 }
225
226 TABLE.list TR:nth-child(even) {
227 background: #f8f8f8;
228 }
229
230 TABLE.list TR:nth-child(odd) {
231 background: #f4f4f4;
232 }
233
234 DT {
235 margin-left: 36pt;
236 margin-top: 12pt;
237 }
238
239 DD {
240 margin-left: 54pt;
241 }
242
243 DL.category DT {
244 font-weight: bold;
245 }
246
247 P.summary {
248 margin-left: 36pt;
249 font-family: monaco, courier, monospace;
250 }
251
252 DIV.summary TABLE {
253 border: solid thin #999999;
254 border-collapse: collapse;
255 border-spacing: 0;
256 margin: 10px;
257 }
258
259 DIV.summary TABLE TD, DIV.summary TABLE TH {
260 border: solid thin #999999;
261 padding: 5px;
262 text-align: left;
263 vertical-align: top;
264 }
265
266 DIV.summary TABLE THEAD TH {
267 background: #eeeeee;
268 }
269
270 /* API documentation styles... */
271 div.body h1 {
272 margin: 0;
273 }
274 div.body h2 {
275 margin-top: 1.5em;
276 }
277 div.body h3, div.body h4, div.body h5 {
278 margin-bottom: 0.5em;
279 margin-top: 1.5em;
280 }
281 .class, .enumeration, .function, .struct, .typedef, .union {
282 border-bottom: solid thin #999999;
283 margin-bottom: 0;
284 margin-top: 2em;
285 }
286 .description {
287 margin-top: 0.5em;
288 }
289 code, p.code, pre, ul.code li {
290 font-family: monaco, courier, monospace;
291 font-size: 90%;
292 }
293 ul.code, ul.contents, ul.subcontents {
294 list-style-type: none;
295 margin: 0;
296 padding-left: 0;
297 }
298 ul.code li {
299 margin: 0;
300 }
301 ul.contents > li {
302 margin-top: 1em;
303 }
304 ul.contents li ul.code, ul.contents li ul.subcontents {
305 padding-left: 2em;
306 }
307 div.body dl {
308 margin-left: 0;
309 margin-top: 0;
310 }
311 div.body dt {
312 font-style: italic;
313 margin-left: 0;
314 margin-top: 0;
315 }
316 div.body dd {
317 margin-bottom: 0.5em;
318 }
319
320 /* This is just for the HTML files generated with the framedhelp target */
321 div.contents {
322 background: #e8e8e8;
323 border: solid thin black;
324 padding: 10px;
325 }
326 div.contents h1 {
327 font-size: 110%;
328 }
329 div.contents h2 {
330 font-size: 100%;
331 }
332 div.contents ul.contents {
333 font-size: 80%;
334 }
335 div.contents ul.subcontents li {
336 margin-left: 1em;
337 text-indent: -1em;
338 }
339 --></style>
340 </head>
341 <body>
342 <div class='body'>
343 <!--
344 "$Id: api-filter.header 7616 2008-05-28 00:34:13Z mike $"
345
346 Filter and backend programming header for CUPS.
347
348 Copyright 2008-2014 by Apple Inc.
349
350 These coded instructions, statements, and computer programs are the
351 property of Apple Inc. and are protected by Federal copyright
352 law. Distribution and use rights are outlined in the file "LICENSE.txt"
353 which should have been included with this file. If this file is
354 file is missing or damaged, see the license at "http://www.cups.org/".
355 -->
356
357 <h1 class='title'>Filter and Backend Programming</h1>
358
359 <div class='summary'><table summary='General Information'>
360 <thead>
361 <tr>
362 <th>Headers</th>
363 <th>cups/backend.h<br>
364 cups/sidechannel.h</th>
365 </tr>
366 </thead>
367 <tbody>
368 <tr>
369 <th>Library</th>
370 <td>-lcups</td>
371 </tr>
372 <tr>
373 <th>See Also</th>
374 <td>Programming: <a href='api-overview.html' target='_top'>Introduction to CUPS Programming</a><br>
375 Programming: <a href='api-cups.html' target='_top'>CUPS API</a><br>
376 Programming: <a href='api-ppd.html' target='_top'>PPD API</a><br>
377 Programming: <a href='api-raster.html' target='_top'>Raster API</a><br>
378 Programming: <a href='postscript-driver.html' target='_top'>Developing PostScript Printer Drivers</a><br>
379 Programming: <a href='raster-driver.html' target='_top'>Developing Raster Printer Drivers</a><br>
380 Specifications: <a href='spec-design.html' target='_top'>CUPS Design Description</a></td>
381 </tr>
382 </tbody>
383 </table></div>
384 <h2 class="title">Contents</h2>
385 <ul class="contents">
386 <li><a href="#OVERVIEW">Overview</a><ul class="subcontents">
387 <li><a href="#SECURITY">Security Considerations</a></li>
388 <li><a href="#SIGNALS">Canceled Jobs and Signal Handling</a></li>
389 <li><a href="#PERMISSIONS">File Permissions</a></li>
390 <li><a href="#TEMPFILES">Temporary Files</a></li>
391 <li><a href="#COPIES">Copy Generation</a></li>
392 <li><a href="#EXITCODES">Exit Codes</a></li>
393 <li><a href="#ENVIRONMENT">Environment Variables</a></li>
394 <li><a href="#MESSAGES">Communicating with the Scheduler</a></li>
395 <li><a href="#COMMUNICATING_BACKEND">Communicating with the Backend</a></li>
396 <li><a href="#COMMUNICATING_FILTER">Communicating with Filters</a></li>
397 <li><a href="#SNMP">Doing SNMP Queries with Network Printers</a></li>
398 </ul></li>
399 <li><a href="#FUNCTIONS">Functions</a><ul class="code">
400 <li><a href="#cupsBackChannelRead" title="Read data from the backchannel.">cupsBackChannelRead</a></li>
401 <li><a href="#cupsBackChannelWrite" title="Write data to the backchannel.">cupsBackChannelWrite</a></li>
402 <li><a href="#cupsBackendDeviceURI" title="Get the device URI for a backend.">cupsBackendDeviceURI</a></li>
403 <li><a href="#cupsBackendReport" title="Write a device line from a backend.">cupsBackendReport</a></li>
404 <li><a href="#cupsSideChannelDoRequest" title="Send a side-channel command to a backend and wait for a response.">cupsSideChannelDoRequest</a></li>
405 <li><a href="#cupsSideChannelRead" title="Read a side-channel message.">cupsSideChannelRead</a></li>
406 <li><a href="#cupsSideChannelSNMPGet" title="Query a SNMP OID's value.">cupsSideChannelSNMPGet</a></li>
407 <li><a href="#cupsSideChannelSNMPWalk" title="Query multiple SNMP OID values.">cupsSideChannelSNMPWalk</a></li>
408 <li><a href="#cupsSideChannelWrite" title="Write a side-channel message.">cupsSideChannelWrite</a></li>
409 </ul></li>
410 <li><a href="#TYPES">Data Types</a><ul class="code">
411 <li><a href="#cups_backend_t" title="Backend exit codes">cups_backend_t</a></li>
412 <li><a href="#cups_sc_bidi_t" title="Bidirectional capabilities">cups_sc_bidi_t</a></li>
413 <li><a href="#cups_sc_command_t" title="Request command codes">cups_sc_command_t</a></li>
414 <li><a href="#cups_sc_connected_t" title="Connectivity values">cups_sc_connected_t</a></li>
415 <li><a href="#cups_sc_state_t" title="Printer state bits">cups_sc_state_t</a></li>
416 <li><a href="#cups_sc_status_t" title="Response status codes">cups_sc_status_t</a></li>
417 <li><a href="#cups_sc_walk_func_t" title="SNMP walk callback">cups_sc_walk_func_t</a></li>
418 </ul></li>
419 <li><a href="#ENUMERATIONS">Constants</a><ul class="code">
420 <li><a href="#cups_backend_e" title="Backend exit codes">cups_backend_e</a></li>
421 <li><a href="#cups_sc_bidi_e" title="Bidirectional capability values">cups_sc_bidi_e</a></li>
422 <li><a href="#cups_sc_command_e" title="Request command codes">cups_sc_command_e</a></li>
423 <li><a href="#cups_sc_connected_e" title="Connectivity values">cups_sc_connected_e</a></li>
424 <li><a href="#cups_sc_state_e" title="Printer state bits">cups_sc_state_e</a></li>
425 <li><a href="#cups_sc_status_e" title="Response status codes">cups_sc_status_e</a></li>
426 </ul></li>
427 </ul>
428 <!--
429 "$Id: api-filter.shtml 7677 2008-06-19 23:22:19Z mike $"
430
431 Filter and backend programming introduction for CUPS.
432
433 Copyright 2007-2013 by Apple Inc.
434 Copyright 1997-2006 by Easy Software Products, all rights reserved.
435
436 These coded instructions, statements, and computer programs are the
437 property of Apple Inc. and are protected by Federal copyright
438 law. Distribution and use rights are outlined in the file "LICENSE.txt"
439 which should have been included with this file. If this file is
440 file is missing or damaged, see the license at "http://www.cups.org/".
441 -->
442
443 <h2 class='title'><a name="OVERVIEW">Overview</a></h2>
444
445 <p>Filters (which include printer drivers and port monitors) and backends
446 are used to convert job files to a printable format and send that data to the
447 printer itself. All of these programs use a common interface for processing
448 print jobs and communicating status information to the scheduler. Each is run
449 with a standard set of command-line arguments:<p>
450
451 <dl class="code">
452
453 <dt>argv[1]</dt>
454 <dd>The job ID</dd>
455
456 <dt>argv[2]</dt>
457 <dd>The user printing the job</dd>
458
459 <dt>argv[3]</dt>
460 <dd>The job name/title</dd>
461
462 <dt>argv[4]</dt>
463 <dd>The number of copies to print</dd>
464
465 <dt>argv[5]</dt>
466 <dd>The options that were provided when the job was submitted</dd>
467
468 <dt>argv[6]</dt>
469 <dd>The file to print (first program only)</dd>
470 </dl>
471
472 <p>The scheduler runs one or more of these programs to print any given job. The
473 first filter reads from the print file and writes to the standard output, while
474 the remaining filters read from the standard input and write to the standard
475 output. The backend is the last filter in the chain and writes to the
476 device.</p>
477
478 <p>Filters are always run as a non-privileged user, typically "lp", with no
479 connection to the user's desktop. Backends are run either as a non-privileged
480 user or as root if the file permissions do not allow user or group execution.
481 The <a href="#PERMISSIONS">file permissions</a> section talks about this in
482 more detail.</p>
483
484 <h3><a name="SECURITY">Security Considerations</a></h3>
485
486 <p>It is always important to use security programming practices. Filters and
487 most backends are run as a non-privileged user, so the major security
488 consideration is resource utilization - filters should not depend on unlimited
489 amounts of CPU, memory, or disk space, and should protect against conditions
490 that could lead to excess usage of any resource like infinite loops and
491 unbounded recursion. In addition, filters must <em>never</em> allow the user to
492 specify an arbitrary file path to a separator page, template, or other file
493 used by the filter since that can lead to an unauthorized disclosure of
494 information. <em>Always</em> treat input as suspect and validate it!</p>
495
496 <p>If you are developing a backend that runs as root, make sure to check for
497 potential buffer overflows, integer under/overflow conditions, and file
498 accesses since these can lead to privilege escalations. When writing files,
499 always validate the file path and <em>never</em> allow a user to determine
500 where to store a file.</p>
501
502 <blockquote><b>Note:</b>
503
504 <p><em>Never</em> write files to a user's home directory. Aside from the
505 security implications, CUPS is a network print service and as such the network
506 user may not be the same as the local user and/or there may not be a local home
507 directory to write to.</p>
508
509 <p>In addition, some operating systems provide additional security mechanisms
510 that further limit file system access, even for backends running as root. On
511 OS X, for example, no backend may write to a user's home directory.</p>
512 </blockquote>
513
514 <h3><a name="SIGNALS">Canceled Jobs and Signal Handling</a></h3>
515
516 <p>The scheduler sends <code>SIGTERM</code> when a printing job is canceled or
517 held. Filters, backends, and port monitors <em>must</em> catch
518 <code>SIGTERM</code> and perform any cleanup necessary to produce a valid output
519 file or return the printer to a known good state. The recommended behavior is to
520 end the output on the current page, preferably on the current line or object
521 being printed.</p>
522
523 <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>
524
525 <pre class="example">
526 #include &lt;signal.h&gt;>
527
528 ...
529
530 int
531 main(int argc, char *argv[])
532 {
533 signal(SIGPIPE, SIG_IGN);
534
535 ...
536 }
537 </pre>
538
539 <h3><a name="PERMISSIONS">File Permissions</a></h3>
540
541 <p>For security reasons, CUPS will only run filters and backends that are owned
542 by root and do not have world or group write permissions. The recommended
543 permissions for filters and backends are 0555 - read and execute but no write.
544 Backends that must run as root should use permissions of 0500 - read and execute
545 by root, no access for other users. Write permissions can be enabled for the
546 root user only.</p>
547
548 <p>To avoid a warning message, the directory containing your filter(s) must also
549 be owned by root and have world and group write disabled - permissions of 0755
550 or 0555 are strongly encouraged.</p>
551
552 <h3><a name="TEMPFILES">Temporary Files</a></h3>
553
554 <p>Temporary files should be created in the directory specified by the
555 "TMPDIR" environment variable. The
556 <a href="#cupsTempFile2"><code>cupsTempFile2</code></a> function can be
557 used to safely create temporary files in this directory.</p>
558
559 <h3><a name="COPIES">Copy Generation</a></h3>
560
561 <p>The <code>argv[4]</code> argument specifies the number of copies to produce
562 of the input file. In general, you should only generate copies if the
563 <em>filename</em> argument is supplied. The only exception to this are
564 filters that produce device-independent PostScript output, since the PostScript
565 filter <var>pstops</var> is responsible for generating copies of PostScript
566 files.</p>
567
568 <h3><a name="EXITCODES">Exit Codes</a></h3>
569
570 <p>Filters must exit with status 0 when they successfully generate print data
571 or 1 when they encounter an error. Backends can return any of the
572 <a href="#cups_backend_t"><code>cups_backend_t</code></a> constants.</p>
573
574 <h3><a name="ENVIRONMENT">Environment Variables</a></h3>
575
576 <p>The following environment variables are defined by the printing system
577 when running print filters and backends:</p>
578
579 <dl class="code">
580
581 <dt>APPLE_LANGUAGE</dt>
582 <dd>The Apple language identifier associated with the job
583 (OS X only).</dd>
584
585 <dt>CHARSET</dt>
586 <dd>The job character set, typically "utf-8".</dd>
587
588 <dt>CLASS</dt>
589 <dd>When a job is submitted to a printer class, contains the name of
590 the destination printer class. Otherwise this environment
591 variable will not be set.</dd>
592
593 <dt>CONTENT_TYPE</dt>
594 <dd>The MIME type associated with the file (e.g.
595 application/postscript).</dd>
596
597 <dt>CUPS_CACHEDIR</dt>
598 <dd>The directory where cache files can be stored. Cache files can be
599 used to retain information between jobs or files in a job.</dd>
600
601 <dt>CUPS_DATADIR</dt>
602 <dd>The directory where (read-only) CUPS data files can be found.</dd>
603
604 <dt>CUPS_FILETYPE</dt>
605 <dd>The type of file being printed: "job-sheet" for a banner page and
606 "document" for a regular print file.</dd>
607
608 <dt>CUPS_SERVERROOT</dt>
609 <dd>The root directory of the server.</dd>
610
611 <dt>DEVICE_URI</dt>
612 <dd>The device-uri associated with the printer.</dd>
613
614 <dt>FINAL_CONTENT_TYPE</dt>
615 <dd>The MIME type associated with the printer (e.g.
616 application/vnd.cups-postscript).</dd>
617
618 <dt>LANG</dt>
619 <dd>The language locale associated with the job.</dd>
620
621 <dt>PPD</dt>
622 <dd>The full pathname of the PostScript Printer Description (PPD)
623 file for this printer.</dd>
624
625 <dt>PRINTER</dt>
626 <dd>The queue name of the class or printer.</dd>
627
628 <dt>RIP_CACHE</dt>
629 <dd>The recommended amount of memory to use for Raster Image
630 Processors (RIPs).</dd>
631
632 <dt>TMPDIR</dt>
633 <dd>The directory where temporary files should be created.</dd>
634
635 </dl>
636
637 <h3><a name="MESSAGES">Communicating with the Scheduler</a></h3>
638
639 <p>Filters and backends communicate with the scheduler by writing messages
640 to the standard error file. The scheduler reads messages from all filters in
641 a job and processes the message based on its prefix. For example, the following
642 code sets the current printer state message to "Printing page 5":</p>
643
644 <pre class="example">
645 int page = 5;
646
647 fprintf(stderr, "INFO: Printing page %d\n", page);
648 </pre>
649
650 <p>Each message is a single line of text starting with one of the following
651 prefix strings:</p>
652
653 <dl class="code">
654
655 <dt>ALERT: message</dt>
656 <dd>Sets the printer-state-message attribute and adds the specified
657 message to the current error log file using the "alert" log level.</dd>
658
659 <dt>ATTR: attribute=value [attribute=value]</dt>
660 <dd>Sets the named printer or job attribute(s). Typically this is used
661 to set the <code>marker-colors</code>, <code>marker-high-levels</code>,
662 <code>marker-levels</code>, <code>marker-low-levels</code>,
663 <code>marker-message</code>, <code>marker-names</code>,
664 <code>marker-types</code>, <code>printer-alert</code>, and
665 <code>printer-alert-description</code> printer attributes. Standard
666 <code>marker-types</code> values are listed in <a href='#TABLE1'>Table
667 1</a>. String values need special handling - see <a href="#ATTR_STRINGS">Reporting Attribute String Values</a> below.</dd>
668
669 <dt>CRIT: message</dt>
670 <dd>Sets the printer-state-message attribute and adds the specified
671 message to the current error log file using the "critical" log
672 level.</dd>
673
674 <dt>DEBUG: message</dt>
675 <dd>Sets the printer-state-message attribute and adds the specified
676 message to the current error log file using the "debug" log level.</dd>
677
678 <dt>DEBUG2: message</dt>
679 <dd>Sets the printer-state-message attribute and adds the specified
680 message to the current error log file using the "debug2" log level.</dd>
681
682 <dt>EMERG: message</dt>
683 <dd>Sets the printer-state-message attribute and adds the specified
684 message to the current error log file using the "emergency" log
685 level.</dd>
686
687 <dt>ERROR: message</dt>
688 <dd>Sets the printer-state-message attribute and adds the specified
689 message to the current error log file using the "error" log level.
690 Use "ERROR:" messages for non-persistent processing errors.</dd>
691
692 <dt>INFO: message</dt>
693 <dd>Sets the printer-state-message attribute. If the current log level
694 is set to "debug2", also adds the specified message to the current error
695 log file using the "info" log level.</dd>
696
697 <dt>NOTICE: message</dt>
698 <dd>Sets the printer-state-message attribute and adds the specified
699 message to the current error log file using the "notice" log level.</dd>
700
701 <dt>PAGE: page-number #-copies</dt>
702 <dt>PAGE: total #-pages</dt>
703 <dd>Adds an entry to the current page log file. The first form adds
704 #-copies to the job-media-sheets-completed attribute. The second
705 form sets the job-media-sheets-completed attribute to #-pages.</dd>
706
707 <dt>PPD: keyword=value [keyword=value ...]</dt>
708 <dd>Changes or adds keywords to the printer's PPD file. Typically
709 this is used to update installable options or default media settings
710 based on the printer configuration.</dd>
711
712 <dt>STATE: + printer-state-reason [printer-state-reason ...]</dt>
713 <dt>STATE: - printer-state-reason [printer-state-reason ...]</dt>
714 <dd>Sets or clears printer-state-reason keywords for the current queue.
715 Typically this is used to indicate persistent media, ink, toner, and
716 configuration conditions or errors on a printer.
717 <a href='#TABLE2'>Table 2</a> lists the standard state keywords -
718 use vendor-prefixed ("com.example.foo") keywords for custom states. See
719 <a href="#MANAGING_STATE">Managing Printer State in a Filter</a> for more
720 information.
721
722 <dt>WARNING: message</dt>
723 <dd>Sets the printer-state-message attribute and adds the specified
724 message to the current error log file using the "warning" log
725 level.</dd>
726
727 </dl>
728
729 <p>Messages without one of these prefixes are treated as if they began with
730 the "DEBUG:" prefix string.</p>
731
732 <div class='table'><table width='80%' summary='Table 1: Standard marker-types Values'>
733 <caption>Table 1: <a name='TABLE1'>Standard marker-types Values</a></caption>
734 <thead>
735 <tr>
736 <th>marker-type</th>
737 <th>Description</th>
738 </tr>
739 </thead>
740 <tbody>
741 <tr>
742 <td>developer</td>
743 <td>Developer unit</td>
744 </tr>
745 <tr>
746 <td>fuser</td>
747 <td>Fuser unit</td>
748 </tr>
749 <tr>
750 <td>fuser-cleaning-pad</td>
751 <td>Fuser cleaning pad</td>
752 </tr>
753 <tr>
754 <td>fuser-oil</td>
755 <td>Fuser oil</td>
756 </tr>
757 <tr>
758 <td>ink</td>
759 <td>Ink supply</td>
760 </tr>
761 <tr>
762 <td>opc</td>
763 <td>Photo conductor</td>
764 </tr>
765 <tr>
766 <td>solid-wax</td>
767 <td>Wax supply</td>
768 </tr>
769 <tr>
770 <td>staples</td>
771 <td>Staple supply</td>
772 </tr>
773 <tr>
774 <td>toner</td>
775 <td>Toner supply</td>
776 </tr>
777 <tr>
778 <td>transfer-unit</td>
779 <td>Transfer unit</td>
780 </tr>
781 <tr>
782 <td>waste-ink</td>
783 <td>Waste ink tank</td>
784 </tr>
785 <tr>
786 <td>waste-toner</td>
787 <td>Waste toner tank</td>
788 </tr>
789 <tr>
790 <td>waste-wax</td>
791 <td>Waste wax tank</td>
792 </tr>
793 </tbody>
794 </table></div>
795
796 <br>
797
798 <div class='table'><table width='80%' summary='Table 2: Standard State Keywords'>
799 <caption>Table 2: <a name='TABLE2'>Standard State Keywords</a></caption>
800 <thead>
801 <tr>
802 <th>Keyword</th>
803 <th>Description</th>
804 </tr>
805 </thead>
806 <tbody>
807 <tr>
808 <td>connecting-to-device</td>
809 <td>Connecting to printer but not printing yet.</td>
810 </tr>
811 <tr>
812 <td>cover-open</td>
813 <td>The printer's cover is open.</td>
814 </tr>
815 <tr>
816 <td>input-tray-missing</td>
817 <td>The paper tray is missing.</td>
818 </tr>
819 <tr>
820 <td>marker-supply-empty</td>
821 <td>The printer is out of ink.</td>
822 </tr>
823 <tr>
824 <td>marker-supply-low</td>
825 <td>The printer is almost out of ink.</td>
826 </tr>
827 <tr>
828 <td>marker-waste-almost-full</td>
829 <td>The printer's waste bin is almost full.</td>
830 </tr>
831 <tr>
832 <td>marker-waste-full</td>
833 <td>The printer's waste bin is full.</td>
834 </tr>
835 <tr>
836 <td>media-empty</td>
837 <td>The paper tray (any paper tray) is empty.</td>
838 </tr>
839 <tr>
840 <td>media-jam</td>
841 <td>There is a paper jam.</td>
842 </tr>
843 <tr>
844 <td>media-low</td>
845 <td>The paper tray (any paper tray) is almost empty.</td>
846 </tr>
847 <tr>
848 <td>media-needed</td>
849 <td>The paper tray needs to be filled (for a job that is printing).</td>
850 </tr>
851 <tr>
852 <td>paused</td>
853 <td>Stop the printer.</td>
854 </tr>
855 <tr>
856 <td>timed-out</td>
857 <td>Unable to connect to printer.</td>
858 </tr>
859 <tr>
860 <td>toner-empty</td>
861 <td>The printer is out of toner.</td>
862 </tr>
863 <tr>
864 <td>toner-low</td>
865 <td>The printer is low on toner.</td>
866 </tr>
867 </tbody>
868 </table></div>
869
870
871 <h4><a name="ATTR_STRINGS">Reporting Attribute String Values</a></h4>
872
873 <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>
874
875 <pre class="example">
876 name=simple
877 name=simple,simple,...
878 name='complex value'
879 name="complex value"
880 name='"complex value"','"complex value"',...
881 </pre>
882
883 <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>
884
885 <pre class="example">
886 int levels[4] = { 40, 50, 60, 70 }; /* CMYK */
887
888 fputs("ATTR: marker-colors=#00FFFF,#FF00FF,#FFFF00,#000000\n", stderr);
889 fputs("ATTR: marker-high-levels=100,100,100,100\n", stderr);
890 fprintf(stderr, "ATTR: marker-levels=%d,%d,%d,%d\n", levels[0], levels[1],
891 levels[2], levels[3], levels[4]);
892 fputs("ATTR: marker-low-levels=5,5,5,5\n", stderr);
893 fputs("ATTR: marker-types=toner,toner,toner,toner\n", stderr);
894 </pre>
895
896 <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>
897
898 <pre class="example">
899 fputs("ATTR: marker-message='Levels shown are approximate.'\n", stderr);
900 </pre>
901
902 <p>When multiple values are reported, each value must be enclosed by a set of single and double quotes:</p>
903
904 <pre class="example">
905 fputs("ATTR: marker-names='\"Cyan Toner\"','\"Magenta Toner\"',"
906 "'\"Yellow Toner\"','\"Black Toner\"'\n", stderr);
907 </pre>
908
909 <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>
910
911 <pre class="example">
912 static const char * /* O - Quoted string */
913 quote_string(const char *s, /* I - String */
914 char *q, /* I - Quoted string buffer */
915 size_t qsize) /* I - Size of quoted string buffer */
916 {
917 char *qptr, /* Pointer into string buffer */
918 *qend; /* End of string buffer */
919
920
921 qptr = q;
922 qend = q + qsize - 5;
923
924 if (qend &lt; q)
925 {
926 *q = '\0';
927 return (q);
928 }
929
930 *qptr++ = '\'';
931 *qptr++ = '\"';
932
933 while (*s && qptr &lt; qend)
934 {
935 if (*s == '\\' || *s == '\"' || *s == '\'')
936 {
937 if (qptr &lt; (qend - 4))
938 {
939 *qptr++ = '\\';
940 *qptr++ = '\\';
941 *qptr++ = '\\';
942 }
943 else
944 break;
945 }
946
947 *qptr++ = *s++;
948 }
949
950 *qptr++ = '\"';
951 *qptr++ = '\'';
952 *qptr = '\0';
953
954 return (q);
955 }
956 </pre>
957
958
959 <h4><a name="MANAGING_STATE">Managing Printer State in a Filter</a></h4>
960
961 <p>Filters are responsible for managing the state keywords they set using
962 "STATE:" messages. Typically you will update <em>all</em> of the keywords that
963 are used by the filter at startup, for example:</p>
964
965 <pre class="example">
966 if (foo_condition != 0)
967 fputs("STATE: +com.example.foo\n", stderr);
968 else
969 fputs("STATE: -com.example.foo\n", stderr);
970
971 if (bar_condition != 0)
972 fputs("STATE: +com.example.bar\n", stderr);
973 else
974 fputs("STATE: -com.example.bar\n", stderr);
975 </pre>
976
977 <p>Then as conditions change, your filter sends "STATE: +keyword" or "STATE:
978 -keyword" messages as necessary to set or clear the corresponding keyword,
979 respectively.</p>
980
981 <p>State keywords are often used to notify the user of issues that span across
982 jobs, for example "media-empty-warning" that indicates one or more paper trays
983 are empty. These keywords should not be cleared unless the corresponding issue
984 no longer exists.</p>
985
986 <p>Filters should clear job-related keywords on startup and exit so that they
987 do not remain set between jobs. For example, "connecting-to-device" is a job
988 sub-state and not an issue that applies when a job is not printing.</p>
989
990 <blockquote><b>Note:</b>
991
992 <p>"STATE:" messages often provide visible alerts to the user. For example,
993 on OS X setting a printer-state-reason value with an "-error" or
994 "-warning" suffix will cause the printer's dock item to bounce if the
995 corresponding reason is localized with a cupsIPPReason keyword in the
996 printer's PPD file.</p>
997
998 <p>When providing a vendor-prefixed keyword, <em>always</em> provide the
999 corresponding standard keyword (if any) to allow clients to respond to the
1000 condition correctly. For example, if you provide a vendor-prefixed keyword
1001 for a low cyan ink condition ("com.example.cyan-ink-low") you must also set the
1002 "marker-supply-low-warning" keyword. In such cases you should also refrain
1003 from localizing the vendor-prefixed keyword in the PPD file - otherwise both
1004 the generic and vendor-specific keyword will be shown in the user
1005 interface.</p>
1006
1007 </blockquote>
1008
1009 <h4><a name="REPORTING_SUPPLIES">Reporting Supply Levels</a></h4>
1010
1011 <p>CUPS tracks several "marker-*" attributes for ink/toner supply level
1012 reporting. These attributes allow applications to display the current supply
1013 levels for a printer without printer-specific software. <a href="#TABLE3">Table 3</a> lists the marker attributes and what they represent.</p>
1014
1015 <p>Filters set marker attributes by sending "ATTR:" messages to stderr. For
1016 example, a filter supporting an inkjet printer with black and tri-color ink
1017 cartridges would use the following to initialize the supply attributes:</p>
1018
1019 <pre class="example">
1020 fputs("ATTR: marker-colors=#000000,#00FFFF#FF00FF#FFFF00\n", stderr);
1021 fputs("ATTR: marker-low-levels=5,10\n", stderr);
1022 fputs("ATTR: marker-names=Black,Tri-Color\n", stderr);
1023 fputs("ATTR: marker-types=ink,ink\n", stderr);
1024 </pre>
1025
1026 <p>Then periodically the filter queries the printer for its current supply
1027 levels and updates them with a separate "ATTR:" message:</p>
1028
1029 <pre class="example">
1030 int black_level, tri_level;
1031 ...
1032 fprintf(stderr, "ATTR: marker-levels=%d,%d\n", black_level, tri_level);
1033 </pre>
1034
1035 <div class='table'><table width='80%' summary='Table 3: Supply Level Attributes'>
1036 <caption>Table 3: <a name='TABLE3'>Supply Level Attributes</a></caption>
1037 <thead>
1038 <tr>
1039 <th>Attribute</th>
1040 <th>Description</th>
1041 </tr>
1042 </thead>
1043 <tbody>
1044 <tr>
1045 <td>marker-colors</td>
1046 <td>A list of comma-separated colors; each color is either "none" or one or
1047 more hex-encoded sRGB colors of the form "#RRGGBB".</td>
1048 </tr>
1049 <tr>
1050 <td>marker-high-levels</td>
1051 <td>A list of comma-separated "almost full" level values from 0 to 100; a
1052 value of 100 should be used for supplies that are consumed/emptied like ink
1053 cartridges.</td>
1054 </tr>
1055 <tr>
1056 <td>marker-levels</td>
1057 <td>A list of comma-separated level values for each supply. A value of -1
1058 indicates the level is unavailable, -2 indicates unknown, and -3 indicates
1059 the level is unknown but has not yet reached capacity. Values from 0 to 100
1060 indicate the corresponding percentage.</td>
1061 </tr>
1062 <tr>
1063 <td>marker-low-levels</td>
1064 <td>A list of comma-separated "almost empty" level values from 0 to 100; a
1065 value of 0 should be used for supplies that are filled like waste ink
1066 tanks.</td>
1067 </tr>
1068 <tr>
1069 <td>marker-message</td>
1070 <td>A human-readable supply status message for the user like "12 pages of
1071 ink remaining."</td>
1072 </tr>
1073 <tr>
1074 <td>marker-names</td>
1075 <td>A list of comma-separated supply names like "Cyan Ink", "Fuser",
1076 etc.</td>
1077 </tr>
1078 <tr>
1079 <td>marker-types</td>
1080 <td>A list of comma-separated supply types; the types are listed in
1081 <a href="#TABLE1">Table 1</a>.</td>
1082 </tr>
1083 </tbody>
1084 </table></div>
1085
1086 <h3><a name="COMMUNICATING_BACKEND">Communicating with the Backend</a></h3>
1087
1088 <p>Filters can communicate with the backend via the
1089 <a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> and
1090 <a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
1091 functions. The
1092 <a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> function
1093 reads data that has been sent back from the device and is typically used to
1094 obtain status and configuration information. For example, the following code
1095 polls the backend for back-channel data:</p>
1096
1097 <pre class="example">
1098 #include &lt;cups/cups.h&gt;
1099
1100 char buffer[8192];
1101 ssize_t bytes;
1102
1103 /* Use a timeout of 0.0 seconds to poll for back-channel data */
1104 bytes = cupsBackChannelRead(buffer, sizeof(buffer), 0.0);
1105 </pre>
1106
1107 <p>Filters can also use <code>select()</code> or <code>poll()</code> on the
1108 back-channel file descriptor (3 or <code>CUPS_BC_FD</code>) to read data only
1109 when it is available.</p>
1110
1111 <p>The
1112 <a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
1113 function allows you to get out-of-band status information and do synchronization
1114 with the device. For example, the following code gets the current IEEE-1284
1115 device ID string from the backend:</p>
1116
1117 <pre class="example">
1118 #include &lt;cups/sidechannel.h&gt;
1119
1120 char data[2049];
1121 int datalen;
1122 <a href="#cups_sc_status_t">cups_sc_status_t</a> status;
1123
1124 /* Tell cupsSideChannelDoRequest() how big our buffer is, less 1 byte for
1125 nul-termination... */
1126 datalen = sizeof(data) - 1;
1127
1128 /* Get the IEEE-1284 device ID, waiting for up to 1 second */
1129 status = <a href="#cupsSideChannelDoRequest">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_GET_DEVICE_ID, data, &amp;datalen, 1.0);
1130
1131 /* Use the returned value if OK was returned and the length is non-zero */
1132 if (status == CUPS_SC_STATUS_OK &amp;&amp; datalen > 0)
1133 data[datalen] = '\0';
1134 else
1135 data[0] = '\0';
1136 </pre>
1137
1138 <h4><a name="DRAIN_OUTPUT">Forcing All Output to a Printer</a></h4>
1139
1140 <p>The
1141 <a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
1142 function allows you to tell the backend to send all pending data to the printer.
1143 This is most often needed when sending query commands to the printer. For example:</p>
1144
1145 <pre class="example">
1146 #include &lt;cups/cups.h&gt;
1147 #include &lt;cups/sidechannel.h&gt;
1148
1149 char data[1024];
1150 int datalen = sizeof(data);
1151 <a href="#cups_sc_status_t">cups_sc_status_t</a> status;
1152
1153 /* Flush pending output to stdout */
1154 fflush(stdout);
1155
1156 /* Drain output to backend, waiting for up to 30 seconds */
1157 status = <a href="#cupsSideChannelDoRequest">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_DRAIN_OUTPUT, data, &amp;datalen, 30.0);
1158
1159 /* Read the response if the output was sent */
1160 if (status == CUPS_SC_STATUS_OK)
1161 {
1162 ssize_t bytes;
1163
1164 /* Wait up to 10.0 seconds for back-channel data */
1165 bytes = cupsBackChannelRead(data, sizeof(data), 10.0);
1166 /* do something with the data from the printer */
1167 }
1168 </pre>
1169
1170 <h3><a name="COMMUNICATING_FILTER">Communicating with Filters</a></h3>
1171
1172 <p>Backends communicate with filters using the reciprocal functions
1173 <a href="#cupsBackChannelWrite"><code>cupsBackChannelWrite</code></a>,
1174 <a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>, and
1175 <a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a>. We
1176 recommend writing back-channel data using a timeout of 1.0 seconds:</p>
1177
1178 <pre class="example">
1179 #include &lt;cups/cups.h&gt;
1180
1181 char buffer[8192];
1182 ssize_t bytes;
1183
1184 /* Obtain data from printer/device */
1185 ...
1186
1187 /* Use a timeout of 1.0 seconds to give filters a chance to read */
1188 cupsBackChannelWrite(buffer, bytes, 1.0);
1189 </pre>
1190
1191 <p>The <a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>
1192 function reads a side-channel command from a filter, driver, or port monitor.
1193 Backends can either poll for commands using a <code>timeout</code> of 0.0, wait
1194 indefinitely for commands using a <code>timeout</code> of -1.0 (probably in a
1195 separate thread for that purpose), or use <code>select</code> or
1196 <code>poll</code> on the <code>CUPS_SC_FD</code> file descriptor (4) to handle
1197 input and output on several file descriptors at the same time.</p>
1198
1199 <p>Once a command is processed, the backend uses the
1200 <a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a> function
1201 to send its response. For example, the following code shows how to poll for a
1202 side-channel command and respond to it:</p>
1203
1204 <pre class="example">
1205 #include &lt;cups/sidechannel.h&gt;
1206
1207 <a href="#cups_sc_command_t">cups_sc_command_t</a> command;
1208 <a href="#cups_sc_status_t">cups_sc_status_t</a> status;
1209 char data[2048];
1210 int datalen = sizeof(data);
1211
1212 /* Poll for a command... */
1213 if (!<a href="#cupsSideChannelRead">cupsSideChannelRead</a>(&amp;command, &amp;status, data, &amp;datalen, 0.0))
1214 {
1215 switch (command)
1216 {
1217 /* handle supported commands, fill data/datalen/status with values as needed */
1218
1219 default :
1220 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
1221 datalen = 0;
1222 break;
1223 }
1224
1225 /* Send a response... */
1226 <a href="#cupsSideChannelWrite">cupsSideChannelWrite</a>(command, status, data, datalen, 1.0);
1227 }
1228 </pre>
1229
1230 <h3><a name="SNMP">Doing SNMP Queries with Network Printers</a></h3>
1231
1232 <p>The Simple Network Management Protocol (SNMP) allows you to get the current
1233 status, page counter, and supply levels from most network printers. Every
1234 piece of information is associated with an Object Identifier (OID), and
1235 every printer has a <em>community</em> name associated with it. OIDs can be
1236 queried directly or by "walking" over a range of OIDs with a common prefix.</p>
1237
1238 <p>The two CUPS SNMP functions provide a simple API for querying network
1239 printers through the side-channel interface. Each accepts a string containing
1240 an OID like ".1.3.6.1.2.1.43.10.2.1.4.1.1" (the standard page counter OID)
1241 along with a timeout for the query.</p>
1242
1243 <p>The <a href="#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet</code></a>
1244 function queries a single OID and returns the value as a string in a buffer
1245 you supply:</p>
1246
1247 <pre class="example">
1248 #include &lt;cups/sidechannel.h&gt;
1249
1250 char data[512];
1251 int datalen = sizeof(data);
1252
1253 if (<a href="#cupsSideChannelSNMPGet">cupsSideChannelSNMPGet</a>(".1.3.6.1.2.1.43.10.2.1.4.1.1", data, &amp;datalen, 5.0)
1254 == CUPS_SC_STATUS_OK)
1255 {
1256 /* Do something with the value */
1257 printf("Page counter is: %s\n", data);
1258 }
1259 </pre>
1260
1261 <p>The
1262 <a href="#cupsSideChannelSNMPWalk"><code>cupsSideChannelSNMPWalk</code></a>
1263 function allows you to query a whole group of OIDs, calling a function of your
1264 choice for each OID that is found:</p>
1265
1266 <pre class="example">
1267 #include &lt;cups/sidechannel.h&gt;
1268
1269 void
1270 my_callback(const char *oid, const char *data, int datalen, void *context)
1271 {
1272 /* Do something with the value */
1273 printf("%s=%s\n", oid, data);
1274 }
1275
1276 ...
1277
1278 void *my_data;
1279
1280 <a href="#cupsSideChannelSNMPWalk">cupsSNMPSideChannelWalk</a>(".1.3.6.1.2.1.43", 5.0, my_callback, my_data);
1281 </pre>
1282 <h2 class="title"><a name="FUNCTIONS">Functions</a></h2>
1283 <h3 class="function"><span class="info">&nbsp;CUPS 1.2/OS X 10.5&nbsp;</span><a name="cupsBackChannelRead">cupsBackChannelRead</a></h3>
1284 <p class="description">Read data from the backchannel.</p>
1285 <p class="code">
1286 ssize_t cupsBackChannelRead (<br>
1287 &nbsp;&nbsp;&nbsp;&nbsp;char *buffer,<br>
1288 &nbsp;&nbsp;&nbsp;&nbsp;size_t bytes,<br>
1289 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1290 );</p>
1291 <h4 class="parameters">Parameters</h4>
1292 <dl>
1293 <dt>buffer</dt>
1294 <dd class="description">Buffer to read into</dd>
1295 <dt>bytes</dt>
1296 <dd class="description">Bytes to read</dd>
1297 <dt>timeout</dt>
1298 <dd class="description">Timeout in seconds, typically 0.0 to poll</dd>
1299 </dl>
1300 <h4 class="returnvalue">Return Value</h4>
1301 <p class="description">Bytes read or -1 on error</p>
1302 <h4 class="discussion">Discussion</h4>
1303 <p class="discussion">Reads up to &quot;bytes&quot; bytes from the backchannel/backend. The &quot;timeout&quot;
1304 parameter controls how many seconds to wait for the data - use 0.0 to
1305 return immediately if there is no data, -1.0 to wait for data indefinitely.
1306
1307 </p>
1308 <h3 class="function"><span class="info">&nbsp;CUPS 1.2/OS X 10.5&nbsp;</span><a name="cupsBackChannelWrite">cupsBackChannelWrite</a></h3>
1309 <p class="description">Write data to the backchannel.</p>
1310 <p class="code">
1311 ssize_t cupsBackChannelWrite (<br>
1312 &nbsp;&nbsp;&nbsp;&nbsp;const char *buffer,<br>
1313 &nbsp;&nbsp;&nbsp;&nbsp;size_t bytes,<br>
1314 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1315 );</p>
1316 <h4 class="parameters">Parameters</h4>
1317 <dl>
1318 <dt>buffer</dt>
1319 <dd class="description">Buffer to write</dd>
1320 <dt>bytes</dt>
1321 <dd class="description">Bytes to write</dd>
1322 <dt>timeout</dt>
1323 <dd class="description">Timeout in seconds, typically 1.0</dd>
1324 </dl>
1325 <h4 class="returnvalue">Return Value</h4>
1326 <p class="description">Bytes written or -1 on error</p>
1327 <h4 class="discussion">Discussion</h4>
1328 <p class="discussion">Writes &quot;bytes&quot; bytes to the backchannel/filter. The &quot;timeout&quot; parameter
1329 controls how many seconds to wait for the data to be written - use
1330 0.0 to return immediately if the data cannot be written, -1.0 to wait
1331 indefinitely.
1332
1333 </p>
1334 <h3 class="function"><span class="info">&nbsp;CUPS 1.2/OS X 10.5&nbsp;</span><a name="cupsBackendDeviceURI">cupsBackendDeviceURI</a></h3>
1335 <p class="description">Get the device URI for a backend.</p>
1336 <p class="code">
1337 const char *cupsBackendDeviceURI (<br>
1338 &nbsp;&nbsp;&nbsp;&nbsp;char **argv<br>
1339 );</p>
1340 <h4 class="parameters">Parameters</h4>
1341 <dl>
1342 <dt>argv</dt>
1343 <dd class="description">Command-line arguments</dd>
1344 </dl>
1345 <h4 class="returnvalue">Return Value</h4>
1346 <p class="description">Device URI or <code>NULL</code></p>
1347 <h4 class="discussion">Discussion</h4>
1348 <p class="discussion">The &quot;argv&quot; argument is the argv argument passed to main(). This
1349 function returns the device URI passed in the DEVICE_URI environment
1350 variable or the device URI passed in argv[0], whichever is found
1351 first.
1352
1353 </p>
1354 <h3 class="function"><span class="info">&nbsp;CUPS 1.4/OS X 10.6&nbsp;</span><a name="cupsBackendReport">cupsBackendReport</a></h3>
1355 <p class="description">Write a device line from a backend.</p>
1356 <p class="code">
1357 void cupsBackendReport (<br>
1358 &nbsp;&nbsp;&nbsp;&nbsp;const char *device_scheme,<br>
1359 &nbsp;&nbsp;&nbsp;&nbsp;const char *device_uri,<br>
1360 &nbsp;&nbsp;&nbsp;&nbsp;const char *device_make_and_model,<br>
1361 &nbsp;&nbsp;&nbsp;&nbsp;const char *device_info,<br>
1362 &nbsp;&nbsp;&nbsp;&nbsp;const char *device_id,<br>
1363 &nbsp;&nbsp;&nbsp;&nbsp;const char *device_location<br>
1364 );</p>
1365 <h4 class="parameters">Parameters</h4>
1366 <dl>
1367 <dt>device_scheme</dt>
1368 <dd class="description">device-scheme string</dd>
1369 <dt>device_uri</dt>
1370 <dd class="description">device-uri string</dd>
1371 <dt>device_make_and_model</dt>
1372 <dd class="description">device-make-and-model string or <code>NULL</code></dd>
1373 <dt>device_info</dt>
1374 <dd class="description">device-info string or <code>NULL</code></dd>
1375 <dt>device_id</dt>
1376 <dd class="description">device-id string or <code>NULL</code></dd>
1377 <dt>device_location</dt>
1378 <dd class="description">device-location string or <code>NULL</code></dd>
1379 </dl>
1380 <h4 class="discussion">Discussion</h4>
1381 <p class="discussion">This function writes a single device line to stdout for a backend.
1382 It handles quoting of special characters in the device-make-and-model,
1383 device-info, device-id, and device-location strings.
1384
1385 </p>
1386 <h3 class="function"><span class="info">&nbsp;CUPS 1.3/OS X 10.5&nbsp;</span><a name="cupsSideChannelDoRequest">cupsSideChannelDoRequest</a></h3>
1387 <p class="description">Send a side-channel command to a backend and wait for a response.</p>
1388 <p class="code">
1389 <a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelDoRequest (<br>
1390 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> command,<br>
1391 &nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
1392 &nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
1393 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1394 );</p>
1395 <h4 class="parameters">Parameters</h4>
1396 <dl>
1397 <dt>command</dt>
1398 <dd class="description">Command to send</dd>
1399 <dt>data</dt>
1400 <dd class="description">Response data buffer pointer</dd>
1401 <dt>datalen</dt>
1402 <dd class="description">Size of data buffer on entry, number of bytes in buffer on return</dd>
1403 <dt>timeout</dt>
1404 <dd class="description">Timeout in seconds</dd>
1405 </dl>
1406 <h4 class="returnvalue">Return Value</h4>
1407 <p class="description">Status of command</p>
1408 <h4 class="discussion">Discussion</h4>
1409 <p class="discussion">This function is normally only called by filters, drivers, or port
1410 monitors in order to communicate with the backend used by the current
1411 printer. Programs must be prepared to handle timeout or &quot;not
1412 implemented&quot; status codes, which indicate that the backend or device
1413 do not support the specified side-channel command.<br>
1414 <br>
1415 The &quot;datalen&quot; parameter must be initialized to the size of the buffer
1416 pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
1417 update the value to contain the number of data bytes in the buffer.
1418
1419 </p>
1420 <h3 class="function"><span class="info">&nbsp;CUPS 1.3/OS X 10.5&nbsp;</span><a name="cupsSideChannelRead">cupsSideChannelRead</a></h3>
1421 <p class="description">Read a side-channel message.</p>
1422 <p class="code">
1423 int cupsSideChannelRead (<br>
1424 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> *command,<br>
1425 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_status_t">cups_sc_status_t</a> *status,<br>
1426 &nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
1427 &nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
1428 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1429 );</p>
1430 <h4 class="parameters">Parameters</h4>
1431 <dl>
1432 <dt>command</dt>
1433 <dd class="description">Command code</dd>
1434 <dt>status</dt>
1435 <dd class="description">Status code</dd>
1436 <dt>data</dt>
1437 <dd class="description">Data buffer pointer</dd>
1438 <dt>datalen</dt>
1439 <dd class="description">Size of data buffer on entry, number of bytes in buffer on return</dd>
1440 <dt>timeout</dt>
1441 <dd class="description">Timeout in seconds</dd>
1442 </dl>
1443 <h4 class="returnvalue">Return Value</h4>
1444 <p class="description">0 on success, -1 on error</p>
1445 <h4 class="discussion">Discussion</h4>
1446 <p class="discussion">This function is normally only called by backend programs to read
1447 commands from a filter, driver, or port monitor program. The
1448 caller must be prepared to handle incomplete or invalid messages
1449 and return the corresponding status codes.<br>
1450 <br>
1451 The &quot;datalen&quot; parameter must be initialized to the size of the buffer
1452 pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
1453 update the value to contain the number of data bytes in the buffer.
1454
1455 </p>
1456 <h3 class="function"><span class="info">&nbsp;CUPS 1.4/OS X 10.6&nbsp;</span><a name="cupsSideChannelSNMPGet">cupsSideChannelSNMPGet</a></h3>
1457 <p class="description">Query a SNMP OID's value.</p>
1458 <p class="code">
1459 <a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelSNMPGet (<br>
1460 &nbsp;&nbsp;&nbsp;&nbsp;const char *oid,<br>
1461 &nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
1462 &nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
1463 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1464 );</p>
1465 <h4 class="parameters">Parameters</h4>
1466 <dl>
1467 <dt>oid</dt>
1468 <dd class="description">OID to query</dd>
1469 <dt>data</dt>
1470 <dd class="description">Buffer for OID value</dd>
1471 <dt>datalen</dt>
1472 <dd class="description">Size of OID buffer on entry, size of value on return</dd>
1473 <dt>timeout</dt>
1474 <dd class="description">Timeout in seconds</dd>
1475 </dl>
1476 <h4 class="returnvalue">Return Value</h4>
1477 <p class="description">Query status</p>
1478 <h4 class="discussion">Discussion</h4>
1479 <p class="discussion">This function asks the backend to do a SNMP OID query on behalf of the
1480 filter, port monitor, or backend using the default community name.<br>
1481 <br>
1482 &quot;oid&quot; contains a numeric OID consisting of integers separated by periods,
1483 for example &quot;.1.3.6.1.2.1.43&quot;. Symbolic names from SNMP MIBs are not
1484 supported and must be converted to their numeric forms.<br>
1485 <br>
1486 On input, &quot;data&quot; and &quot;datalen&quot; provide the location and size of the
1487 buffer to hold the OID value as a string. HEX-String (binary) values are
1488 converted to hexadecimal strings representing the binary data, while
1489 NULL-Value and unknown OID types are returned as the empty string.
1490 The returned &quot;datalen&quot; does not include the trailing nul.
1491
1492 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED</code> is returned by backends that do not
1493 support SNMP queries. <code>CUPS_SC_STATUS_NO_RESPONSE</code> is returned when
1494 the printer does not respond to the SNMP query.
1495
1496 </p>
1497 <h3 class="function"><span class="info">&nbsp;CUPS 1.4/OS X 10.6&nbsp;</span><a name="cupsSideChannelSNMPWalk">cupsSideChannelSNMPWalk</a></h3>
1498 <p class="description">Query multiple SNMP OID values.</p>
1499 <p class="code">
1500 <a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelSNMPWalk (<br>
1501 &nbsp;&nbsp;&nbsp;&nbsp;const char *oid,<br>
1502 &nbsp;&nbsp;&nbsp;&nbsp;double timeout,<br>
1503 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_walk_func_t">cups_sc_walk_func_t</a> cb,<br>
1504 &nbsp;&nbsp;&nbsp;&nbsp;void *context<br>
1505 );</p>
1506 <h4 class="parameters">Parameters</h4>
1507 <dl>
1508 <dt>oid</dt>
1509 <dd class="description">First numeric OID to query</dd>
1510 <dt>timeout</dt>
1511 <dd class="description">Timeout for each query in seconds</dd>
1512 <dt>cb</dt>
1513 <dd class="description">Function to call with each value</dd>
1514 <dt>context</dt>
1515 <dd class="description">Application-defined pointer to send to callback</dd>
1516 </dl>
1517 <h4 class="returnvalue">Return Value</h4>
1518 <p class="description">Status of first query of <code>CUPS_SC_STATUS_OK</code> on success</p>
1519 <h4 class="discussion">Discussion</h4>
1520 <p class="discussion">This function asks the backend to do multiple SNMP OID queries on behalf
1521 of the filter, port monitor, or backend using the default community name.
1522 All OIDs under the &quot;parent&quot; OID are queried and the results are sent to
1523 the callback function you provide.<br>
1524 <br>
1525 &quot;oid&quot; contains a numeric OID consisting of integers separated by periods,
1526 for example &quot;.1.3.6.1.2.1.43&quot;. Symbolic names from SNMP MIBs are not
1527 supported and must be converted to their numeric forms.<br>
1528 <br>
1529 &quot;timeout&quot; specifies the timeout for each OID query. The total amount of
1530 time will depend on the number of OID values found and the time required
1531 for each query.<br>
1532 <br>
1533 &quot;cb&quot; provides a function to call for every value that is found. &quot;context&quot;
1534 is an application-defined pointer that is sent to the callback function
1535 along with the OID and current data. The data passed to the callback is the
1536 same as returned by <a href="#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet</code></a>.
1537
1538 <code>CUPS_SC_STATUS_NOT_IMPLEMENTED</code> is returned by backends that do not
1539 support SNMP queries. <code>CUPS_SC_STATUS_NO_RESPONSE</code> is returned when
1540 the printer does not respond to the first SNMP query.
1541
1542 </p>
1543 <h3 class="function"><span class="info">&nbsp;CUPS 1.3/OS X 10.5&nbsp;</span><a name="cupsSideChannelWrite">cupsSideChannelWrite</a></h3>
1544 <p class="description">Write a side-channel message.</p>
1545 <p class="code">
1546 int cupsSideChannelWrite (<br>
1547 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> command,<br>
1548 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_status_t">cups_sc_status_t</a> status,<br>
1549 &nbsp;&nbsp;&nbsp;&nbsp;const char *data,<br>
1550 &nbsp;&nbsp;&nbsp;&nbsp;int datalen,<br>
1551 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1552 );</p>
1553 <h4 class="parameters">Parameters</h4>
1554 <dl>
1555 <dt>command</dt>
1556 <dd class="description">Command code</dd>
1557 <dt>status</dt>
1558 <dd class="description">Status code</dd>
1559 <dt>data</dt>
1560 <dd class="description">Data buffer pointer</dd>
1561 <dt>datalen</dt>
1562 <dd class="description">Number of bytes of data</dd>
1563 <dt>timeout</dt>
1564 <dd class="description">Timeout in seconds</dd>
1565 </dl>
1566 <h4 class="returnvalue">Return Value</h4>
1567 <p class="description">0 on success, -1 on error</p>
1568 <h4 class="discussion">Discussion</h4>
1569 <p class="discussion">This function is normally only called by backend programs to send
1570 responses to a filter, driver, or port monitor program.
1571
1572 </p>
1573 <h2 class="title"><a name="TYPES">Data Types</a></h2>
1574 <h3 class="typedef"><a name="cups_backend_t">cups_backend_t</a></h3>
1575 <p class="description">Backend exit codes</p>
1576 <p class="code">
1577 typedef enum <a href="#cups_backend_e">cups_backend_e</a> cups_backend_t;
1578 </p>
1579 <h3 class="typedef"><a name="cups_sc_bidi_t">cups_sc_bidi_t</a></h3>
1580 <p class="description">Bidirectional capabilities</p>
1581 <p class="code">
1582 typedef enum <a href="#cups_sc_bidi_e">cups_sc_bidi_e</a> cups_sc_bidi_t;
1583 </p>
1584 <h3 class="typedef"><a name="cups_sc_command_t">cups_sc_command_t</a></h3>
1585 <p class="description">Request command codes</p>
1586 <p class="code">
1587 typedef enum <a href="#cups_sc_command_e">cups_sc_command_e</a> cups_sc_command_t;
1588 </p>
1589 <h3 class="typedef"><a name="cups_sc_connected_t">cups_sc_connected_t</a></h3>
1590 <p class="description">Connectivity values</p>
1591 <p class="code">
1592 typedef enum <a href="#cups_sc_connected_e">cups_sc_connected_e</a> cups_sc_connected_t;
1593 </p>
1594 <h3 class="typedef"><a name="cups_sc_state_t">cups_sc_state_t</a></h3>
1595 <p class="description">Printer state bits</p>
1596 <p class="code">
1597 typedef enum <a href="#cups_sc_state_e">cups_sc_state_e</a> cups_sc_state_t;
1598 </p>
1599 <h3 class="typedef"><a name="cups_sc_status_t">cups_sc_status_t</a></h3>
1600 <p class="description">Response status codes</p>
1601 <p class="code">
1602 typedef enum <a href="#cups_sc_status_e">cups_sc_status_e</a> cups_sc_status_t;
1603 </p>
1604 <h3 class="typedef"><a name="cups_sc_walk_func_t">cups_sc_walk_func_t</a></h3>
1605 <p class="description">SNMP walk callback</p>
1606 <p class="code">
1607 typedef void (*cups_sc_walk_func_t)(const char *oid, const char *data, int datalen, void *context);
1608 </p>
1609 <h2 class="title"><a name="ENUMERATIONS">Constants</a></h2>
1610 <h3 class="enumeration"><a name="cups_backend_e">cups_backend_e</a></h3>
1611 <p class="description">Backend exit codes</p>
1612 <h4 class="constants">Constants</h4>
1613 <dl>
1614 <dt>CUPS_BACKEND_AUTH_REQUIRED </dt>
1615 <dd class="description">Job failed, authentication required</dd>
1616 <dt>CUPS_BACKEND_CANCEL </dt>
1617 <dd class="description">Job failed, cancel job</dd>
1618 <dt>CUPS_BACKEND_FAILED </dt>
1619 <dd class="description">Job failed, use error-policy</dd>
1620 <dt>CUPS_BACKEND_HOLD </dt>
1621 <dd class="description">Job failed, hold job</dd>
1622 <dt>CUPS_BACKEND_OK </dt>
1623 <dd class="description">Job completed successfully</dd>
1624 <dt>CUPS_BACKEND_RETRY </dt>
1625 <dd class="description">Job failed, retry this job later</dd>
1626 <dt>CUPS_BACKEND_RETRY_CURRENT </dt>
1627 <dd class="description">Job failed, retry this job immediately</dd>
1628 <dt>CUPS_BACKEND_STOP </dt>
1629 <dd class="description">Job failed, stop queue</dd>
1630 </dl>
1631 <h3 class="enumeration"><a name="cups_sc_bidi_e">cups_sc_bidi_e</a></h3>
1632 <p class="description">Bidirectional capability values</p>
1633 <h4 class="constants">Constants</h4>
1634 <dl>
1635 <dt>CUPS_SC_BIDI_NOT_SUPPORTED </dt>
1636 <dd class="description">Bidirectional I/O is not supported</dd>
1637 <dt>CUPS_SC_BIDI_SUPPORTED </dt>
1638 <dd class="description">Bidirectional I/O is supported</dd>
1639 </dl>
1640 <h3 class="enumeration"><a name="cups_sc_command_e">cups_sc_command_e</a></h3>
1641 <p class="description">Request command codes</p>
1642 <h4 class="constants">Constants</h4>
1643 <dl>
1644 <dt>CUPS_SC_CMD_DRAIN_OUTPUT </dt>
1645 <dd class="description">Drain all pending output</dd>
1646 <dt>CUPS_SC_CMD_GET_BIDI </dt>
1647 <dd class="description">Return bidirectional capabilities</dd>
1648 <dt>CUPS_SC_CMD_GET_CONNECTED <span class="info">&nbsp;CUPS 1.5/OS X 10.7&nbsp;</span></dt>
1649 <dd class="description">Return whether the backend is &quot;connected&quot; to the printer </dd>
1650 <dt>CUPS_SC_CMD_GET_DEVICE_ID </dt>
1651 <dd class="description">Return the IEEE-1284 device ID</dd>
1652 <dt>CUPS_SC_CMD_GET_STATE </dt>
1653 <dd class="description">Return the device state</dd>
1654 <dt>CUPS_SC_CMD_SNMP_GET <span class="info">&nbsp;CUPS 1.4/OS X 10.6&nbsp;</span></dt>
1655 <dd class="description">Query an SNMP OID </dd>
1656 <dt>CUPS_SC_CMD_SNMP_GET_NEXT <span class="info">&nbsp;CUPS 1.4/OS X 10.6&nbsp;</span></dt>
1657 <dd class="description">Query the next SNMP OID </dd>
1658 <dt>CUPS_SC_CMD_SOFT_RESET </dt>
1659 <dd class="description">Do a soft reset</dd>
1660 </dl>
1661 <h3 class="enumeration"><a name="cups_sc_connected_e">cups_sc_connected_e</a></h3>
1662 <p class="description">Connectivity values</p>
1663 <h4 class="constants">Constants</h4>
1664 <dl>
1665 <dt>CUPS_SC_CONNECTED </dt>
1666 <dd class="description">Backend is &quot;connected&quot; to printer</dd>
1667 <dt>CUPS_SC_NOT_CONNECTED </dt>
1668 <dd class="description">Backend is not &quot;connected&quot; to printer</dd>
1669 </dl>
1670 <h3 class="enumeration"><a name="cups_sc_state_e">cups_sc_state_e</a></h3>
1671 <p class="description">Printer state bits</p>
1672 <h4 class="constants">Constants</h4>
1673 <dl>
1674 <dt>CUPS_SC_STATE_BUSY </dt>
1675 <dd class="description">Device is busy</dd>
1676 <dt>CUPS_SC_STATE_ERROR </dt>
1677 <dd class="description">Other error condition</dd>
1678 <dt>CUPS_SC_STATE_MARKER_EMPTY </dt>
1679 <dd class="description">Toner/ink out condition</dd>
1680 <dt>CUPS_SC_STATE_MARKER_LOW </dt>
1681 <dd class="description">Toner/ink low condition</dd>
1682 <dt>CUPS_SC_STATE_MEDIA_EMPTY </dt>
1683 <dd class="description">Paper out condition</dd>
1684 <dt>CUPS_SC_STATE_MEDIA_LOW </dt>
1685 <dd class="description">Paper low condition</dd>
1686 <dt>CUPS_SC_STATE_OFFLINE </dt>
1687 <dd class="description">Device is offline</dd>
1688 <dt>CUPS_SC_STATE_ONLINE </dt>
1689 <dd class="description">Device is online</dd>
1690 </dl>
1691 <h3 class="enumeration"><a name="cups_sc_status_e">cups_sc_status_e</a></h3>
1692 <p class="description">Response status codes</p>
1693 <h4 class="constants">Constants</h4>
1694 <dl>
1695 <dt>CUPS_SC_STATUS_BAD_MESSAGE </dt>
1696 <dd class="description">The command/response message was invalid</dd>
1697 <dt>CUPS_SC_STATUS_IO_ERROR </dt>
1698 <dd class="description">An I/O error occurred</dd>
1699 <dt>CUPS_SC_STATUS_NONE </dt>
1700 <dd class="description">No status</dd>
1701 <dt>CUPS_SC_STATUS_NOT_IMPLEMENTED </dt>
1702 <dd class="description">Command not implemented</dd>
1703 <dt>CUPS_SC_STATUS_NO_RESPONSE </dt>
1704 <dd class="description">The device did not respond</dd>
1705 <dt>CUPS_SC_STATUS_OK </dt>
1706 <dd class="description">Operation succeeded</dd>
1707 <dt>CUPS_SC_STATUS_TIMEOUT </dt>
1708 <dd class="description">The backend did not respond</dd>
1709 <dt>CUPS_SC_STATUS_TOO_BIG </dt>
1710 <dd class="description">Response too big</dd>
1711 </dl>
1712 </div>
1713 </body>
1714 </html>