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