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