]> git.ipfire.org Git - thirdparty/cups.git/blame - doc/help/api-filter.html
Merge changes from CUPS 1.5svn-r9675.
[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
5a738aea
MS
346 Filter and backend programming header for the Common UNIX Printing System
347 (CUPS).
ef416fc2 348
178cb736 349 Copyright 2008-2009 by Apple Inc.
ef416fc2 350
351 These coded instructions, statements, and computer programs are the
bc44d920 352 property of Apple Inc. and are protected by Federal copyright
353 law. Distribution and use rights are outlined in the file "LICENSE.txt"
354 which should have been included with this file. If this file is
355 file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 356-->
357
178cb736
MS
358<h1 class='title'>Filter and Backend Programming</h1>
359
5a738aea
MS
360<div class='summary'><table summary='General Information'>
361<thead>
362<tr>
ac884b6a 363 <th>Headers</th>
5a738aea 364 <th>cups/backend.h<br>
79e1d494 365 cups/sidechannel.h</th>
5a738aea
MS
366</tr>
367</thead>
368<tbody>
369<tr>
370 <th>Library</th>
371 <td>-lcups</td>
372</tr>
373<tr>
374 <th>See Also</th>
375 <td>Programming: <a href='api-overview.html' target='_top'>Introduction to CUPS Programming</a><br>
376 Programming: <a href='api-cups.html' target='_top'>CUPS API</a><br>
377 Programming: <a href='api-ppd.html' target='_top'>PPD API</a><br>
79e1d494 378 Programming: <a href='api-raster.html' target='_top'>Raster API</a><br>
b0f6947b
MS
379 Programming: <a href='postscript-driver.html' target='_top'>Developing PostScript Printer Drivers</a><br>
380 Programming: <a href='raster-driver.html' target='_top'>Developing Raster Printer Drivers</a><br>
10d09e33 381 Specifications: <a href='spec-design.html' target='_top'>CUPS Design Description</a></td>
5a738aea
MS
382</tr>
383</tbody>
384</table></div>
385<h2 class="title">Contents</h2>
386<ul class="contents">
5a738aea 387<li><a href="#OVERVIEW">Overview</a><ul class="subcontents">
0268488e
MS
388 <li><a href="#SECURITY">Security Considerations</a></li>
389 <li><a href="#PERMISSIONS">File Permissions</a></li>
390 <li><a href="#TEMPFILES">Temporary Files</a></li>
391 <li><a href="#COPIES">Copy Generation</a></li>
392 <li><a href="#EXITCODES">Exit Codes</a></li>
393 <li><a href="#ENVIRONMENT">Environment Variables</a></li>
394 <li><a href="#MESSAGES">Communicating with the Scheduler</a></li>
395 <li><a href="#COMMUNICATING_BACKEND">Communicating with the Backend</a></li>
396 <li><a href="#COMMUNICATING_FILTER">Communicating with Filters</a></li>
397 <li><a href="#SNMP">Doing SNMP Queries with Network Printers</a></li>
5a738aea
MS
398</ul></li>
399<li><a href="#FUNCTIONS">Functions</a><ul class="code">
0268488e
MS
400 <li><a href="#cupsBackChannelRead" title="Read data from the backchannel.">cupsBackChannelRead</a></li>
401 <li><a href="#cupsBackChannelWrite" title="Write data to the backchannel.">cupsBackChannelWrite</a></li>
402 <li><a href="#cupsBackendDeviceURI" title="Get the device URI for a backend.">cupsBackendDeviceURI</a></li>
403 <li><a href="#cupsBackendReport" title="Write a device line from a backend.">cupsBackendReport</a></li>
404 <li><a href="#cupsSideChannelDoRequest" title="Send a side-channel command to a backend and wait for a response.">cupsSideChannelDoRequest</a></li>
405 <li><a href="#cupsSideChannelRead" title="Read a side-channel message.">cupsSideChannelRead</a></li>
406 <li><a href="#cupsSideChannelSNMPGet" title="Query a SNMP OID's value.">cupsSideChannelSNMPGet</a></li>
407 <li><a href="#cupsSideChannelSNMPWalk" title="Query multiple SNMP OID values.">cupsSideChannelSNMPWalk</a></li>
408 <li><a href="#cupsSideChannelWrite" title="Write a side-channel message.">cupsSideChannelWrite</a></li>
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>
82f97232 414 <li><a href="#cups_sc_connected_t" title="Connectivity values">cups_sc_connected_t</a></li>
5a738aea
MS
415 <li><a href="#cups_sc_state_t" title="Printer state bits">cups_sc_state_t</a></li>
416 <li><a href="#cups_sc_status_t" title="Response status codes">cups_sc_status_t</a></li>
20fbc903 417 <li><a href="#cups_sc_walk_func_t" title="SNMP walk callback">cups_sc_walk_func_t</a></li>
5a738aea
MS
418</ul></li>
419<li><a href="#ENUMERATIONS">Constants</a><ul class="code">
420 <li><a href="#cups_backend_e" title="Backend exit codes">cups_backend_e</a></li>
79e1d494 421 <li><a href="#cups_sc_bidi_e" title="Bidirectional capability values">cups_sc_bidi_e</a></li>
5a738aea 422 <li><a href="#cups_sc_command_e" title="Request command codes">cups_sc_command_e</a></li>
82f97232 423 <li><a href="#cups_sc_connected_e" title="Connectivity values">cups_sc_connected_e</a></li>
5a738aea
MS
424 <li><a href="#cups_sc_state_e" title="Printer state bits">cups_sc_state_e</a></li>
425 <li><a href="#cups_sc_status_e" title="Response status codes">cups_sc_status_e</a></li>
426</ul></li>
0268488e 427</ul>
5a738aea 428<!--
68b10830 429 "$Id$"
ef416fc2 430
5a738aea
MS
431 Filter and backend programming introduction for the Common UNIX Printing
432 System (CUPS).
ef416fc2 433
178cb736 434 Copyright 2007-2009 by Apple Inc.
5a738aea 435 Copyright 1997-2006 by Easy Software Products, all rights reserved.
ef416fc2 436
5a738aea
MS
437 These coded instructions, statements, and computer programs are the
438 property of Apple Inc. and are protected by Federal copyright
439 law. Distribution and use rights are outlined in the file "LICENSE.txt"
440 which should have been included with this file. If this file is
441 file is missing or damaged, see the license at "http://www.cups.org/".
442-->
f7deaa1a 443
5a738aea 444<h2 class='title'><a name="OVERVIEW">Overview</a></h2>
ef416fc2 445
79e1d494
MS
446<p>Filters (which include printer drivers and port monitors) and backends
447are used to convert job files to a printable format and send that data to the
448printer itself. All of these programs use a common interface for processing
449print jobs and communicating status information to the scheduler. Each is run
450with a standard set of command-line arguments:<p>
ef416fc2 451
5a738aea 452<dl class="code">
f7deaa1a 453
5a738aea
MS
454 <dt>argv[1]</dt>
455 <dd>The job ID</dd>
ef416fc2 456
5a738aea
MS
457 <dt>argv[2]</dt>
458 <dd>The user printing the job</dd>
f7deaa1a 459
5a738aea
MS
460 <dt>argv[3]</dt>
461 <dd>The job name/title</dd>
f7deaa1a 462
5a738aea
MS
463 <dt>argv[4]</dt>
464 <dd>The number of copies to print</dd>
f7deaa1a 465
5a738aea
MS
466 <dt>argv[5]</dt>
467 <dd>The options that were provided when the job was submitted</dd>
f7deaa1a 468
5a738aea 469 <dt>argv[6]</dt>
79e1d494 470 <dd>The file to print (first program only)</dd>
5a738aea 471</dl>
f7deaa1a 472
5a738aea
MS
473<p>The scheduler runs one or more of these programs to print any given job. The
474first filter reads from the print file and writes to the standard output, while
475the remaining filters read from the standard input and write to the standard
476output. The backend is the last filter in the chain and writes to the
477device.</p>
f7deaa1a 478
178cb736
MS
479<p>Filters are always run as a non-privileged user, typically "lp", with no
480connection to the user's desktop. Backends are run either as a non-privileged
481user or as root if the file permissions do not allow user or group execution.
482The <a href="#PERMISSIONS">file permissions</a> section talks about this in
483more detail.</p>
484
ac884b6a
MS
485<h3><a name="SECURITY">Security Considerations</a></h3>
486
487<p>It is always important to use security programming practices. Filters and
488most backends are run as a non-priviledged user, so the major security
489consideration is resource utilization - filters should not depend on unlimited
490amounts of CPU, memory, or disk space, and should protect against conditions
491that could lead to excess usage of any resource like infinite loops and
492unbounded recursion. In addition, filters must <em>never</em> allow the user to
493specify an arbitrary file path to a separator page, template, or other file
494used by the filter since that can lead to an unauthorized disclosure of
495information. <em>Always</em> treat input as suspect and validate it!</p>
496
4d301e69 497<p>If you are developing a backend that runs as root, make sure to check for
ac884b6a
MS
498potential buffer overflows, integer under/overflow conditions, and file
499accesses since these can lead to privilege escalations. When writing files,
500always validate the file path and <em>never</em> allow a user to determine
501where to store a file.</p>
502
503<blockquote><b>Note:</b>
504
505<p><em>Never</em> write files to a user's home directory. Aside from the
506security implications, CUPS is a network print service and as such the network
507user may not be the same as the local user and/or there may not be a local home
508directory to write to.</p>
509
510<p>In addition, some operating systems provide additional security mechanisms
178cb736 511that further limit file system access, even for backends running as root. On
ac884b6a
MS
512Mac OS X, for example, no backend may write to a user's home directory.</p>
513</blockquote>
514
178cb736
MS
515<h3><a name="PERMISSIONS">File Permissions</a></h3>
516
517<p>For security reasons, CUPS will only run filters and backends that are owned
4d301e69
MS
518by root and do not have world or group write permissions. The recommended
519permissions for filters and backends are 0555 - read and execute but no write.
520Backends that must run as root should use permissions of 0500 - read and execute
521by root, no access for other users. Write permissions can be enabled for the
522root user only.</p>
178cb736
MS
523
524<p>To avoid a warning message, the directory containing your filter(s) must also
4d301e69
MS
525be owned by root and have world and group write disabled - permissions of 0755
526or 0555 are strongly encouraged.</p>
178cb736 527
ac884b6a
MS
528<h3><a name="TEMPFILES">Temporary Files</a></h3>
529
530<p>Temporary files should be created in the directory specified by the
531"TMPDIR" environment variable. The
532<a href="#cupsTempFile2"><code>cupsTempFile2</code></a> function can be
533used to safely create temporary files in this directory.</p>
534
535<h3><a name="COPIES">Copy Generation</a></h3>
536
537<p>The <code>argv[4]</code> argument specifies the number of copies to produce
538of the input file. In general, you should only generate copies if the
539<em>filename</em> argument is supplied. The only exception to this are
540filters that produce device-independent PostScript output, since the PostScript
541filter <var>pstops</var> is responsible for generating copies of PostScript
542files.</p>
543
5a738aea 544<h3><a name="EXITCODES">Exit Codes</a></h3>
f7deaa1a 545
5a738aea
MS
546<p>Filters must exit with status 0 when they successfully generate print data
547or 1 when they encounter an error. Backends can return any of the
548<a href="#cups_backend_t"><code>cups_backend_t</code></a> constants.</p>
f7deaa1a 549
5a738aea 550<h3><a name="ENVIRONMENT">Environment Variables</a></h3>
f7deaa1a 551
79e1d494
MS
552<p>The following environment variables are defined by the printing system
553when running print filters and backends:</p>
f7deaa1a 554
5a738aea 555<dl class="code">
f7deaa1a 556
acb056cb 557 <dt>APPLE_LANGUAGE</dt>
5a738aea
MS
558 <dd>The Apple language identifier associated with the job
559 (Mac OS X only).</dd>
f7deaa1a 560
5a738aea
MS
561 <dt>CHARSET</dt>
562 <dd>The job character set, typically "utf-8".</dd>
f7deaa1a 563
5a738aea
MS
564 <dt>CLASS</dt>
565 <dd>When a job is submitted to a printer class, contains the name of
566 the destination printer class. Otherwise this environment
567 variable will not be set.</dd>
f7deaa1a 568
5a738aea
MS
569 <dt>CONTENT_TYPE</dt>
570 <dd>The MIME type associated with the file (e.g.
571 application/postscript).</dd>
f7deaa1a 572
5a738aea 573 <dt>CUPS_CACHEDIR</dt>
79e1d494
MS
574 <dd>The directory where cache files can be stored. Cache files can be
575 used to retain information between jobs or files in a job.</dd>
f7deaa1a 576
5a738aea 577 <dt>CUPS_DATADIR</dt>
79e1d494 578 <dd>The directory where (read-only) CUPS data files can be found.</dd>
f7deaa1a 579
758a062f
MS
580 <dt>CUPS_FILETYPE</dt>
581 <dd>The type of file being printed: "job-sheet" for a banner page and
582 "document" for a regular print file.</dd>
583
5a738aea
MS
584 <dt>CUPS_SERVERROOT</dt>
585 <dd>The root directory of the server.</dd>
f7deaa1a 586
5a738aea
MS
587 <dt>DEVICE_URI</dt>
588 <dd>The device-uri associated with the printer.</dd>
f7deaa1a 589
5a738aea
MS
590 <dt>FINAL_CONTENT_TYPE</dt>
591 <dd>The MIME type associated with the printer (e.g.
592 application/vnd.cups-postscript).</dd>
f7deaa1a 593
5a738aea
MS
594 <dt>LANG</dt>
595 <dd>The language locale associated with the job.</dd>
f7deaa1a 596
5a738aea
MS
597 <dt>PPD</dt>
598 <dd>The full pathname of the PostScript Printer Description (PPD)
599 file for this printer.</dd>
f7deaa1a 600
5a738aea 601 <dt>PRINTER</dt>
79e1d494 602 <dd>The queue name of the class or printer.</dd>
f7deaa1a 603
5a738aea
MS
604 <dt>RIP_CACHE</dt>
605 <dd>The recommended amount of memory to use for Raster Image
606 Processors (RIPs).</dd>
f7deaa1a 607
79e1d494
MS
608 <dt>TMPDIR</dt>
609 <dd>The directory where temporary files should be created.</dd>
610
5a738aea 611</dl>
f7deaa1a 612
5a738aea 613<h3><a name="MESSAGES">Communicating with the Scheduler</a></h3>
f7deaa1a 614
79e1d494
MS
615<p>Filters and backends communicate with the scheduler by writing messages
616to the standard error file. The scheduler reads messages from all filters in
617a job and processes the message based on its prefix. For example, the following
618code sets the current printer state message to "Printing page 5":</p>
f7deaa1a 619
5a738aea
MS
620<pre class="example">
621int page = 5;
f7deaa1a 622
5a738aea 623fprintf(stderr, "INFO: Printing page %d\n", page);
f7deaa1a 624</pre>
625
5a738aea
MS
626<p>Each message is a single line of text starting with one of the following
627prefix strings:</p>
628
629<dl class="code">
630
631 <dt>ALERT: message</dt>
632 <dd>Sets the printer-state-message attribute and adds the specified
633 message to the current error log file using the "alert" log level.</dd>
634
635 <dt>ATTR: attribute=value [attribute=value]</dt>
636 <dd>Sets the named printer or job attribute(s). Typically this is used
637 to set the <code>marker-colors</code>, <code>marker-levels</code>,
75bd9771
MS
638 <code>marker-message</code>, <code>marker-names</code>,
639 <code>marker-types</code>, <code>printer-alert</code>, and
640 <code>printer-alert-description</code> printer attributes. Standard
641 <code>marker-types</code> values are listed in <a href='#TABLE1'>Table
642 1</a>.</dd>
5a738aea
MS
643
644 <dt>CRIT: message</dt>
645 <dd>Sets the printer-state-message attribute and adds the specified
646 message to the current error log file using the "critical" log
647 level.</dd>
648
649 <dt>DEBUG: message</dt>
650 <dd>Sets the printer-state-message attribute and adds the specified
651 message to the current error log file using the "debug" log level.</dd>
652
653 <dt>DEBUG2: message</dt>
654 <dd>Sets the printer-state-message attribute and adds the specified
655 message to the current error log file using the "debug2" log level.</dd>
656
657 <dt>EMERG: message</dt>
658 <dd>Sets the printer-state-message attribute and adds the specified
659 message to the current error log file using the "emergency" log
660 level.</dd>
661
662 <dt>ERROR: message</dt>
663 <dd>Sets the printer-state-message attribute and adds the specified
79e1d494
MS
664 message to the current error log file using the "error" log level.
665 Use "ERROR:" messages for non-persistent processing errors.</dd>
5a738aea
MS
666
667 <dt>INFO: message</dt>
668 <dd>Sets the printer-state-message attribute. If the current log level
669 is set to "debug2", also adds the specified message to the current error
670 log file using the "info" log level.</dd>
671
672 <dt>NOTICE: message</dt>
673 <dd>Sets the printer-state-message attribute and adds the specified
674 message to the current error log file using the "notice" log level.</dd>
675
676 <dt>PAGE: page-number #-copies</dt>
677 <dt>PAGE: total #-pages</dt>
678 <dd>Adds an entry to the current page log file. The first form adds
679 #-copies to the job-media-sheets-completed attribute. The second
680 form sets the job-media-sheets-completed attribute to #-pages.</dd>
681
20fbc903
MS
682 <dt>PPD: keyword=value [keyword=value ...]</dt>
683 <dd>Changes or adds keywords to the printer's PPD file. Typically
684 this is used to update installable options or default media settings
685 based on the printer configuration.</dd>
686
5a738aea
MS
687 <dt>STATE: printer-state-reason [printer-state-reason ...]</dt>
688 <dt>STATE: + printer-state-reason [printer-state-reason ...]</dt>
689 <dt>STATE: - printer-state-reason [printer-state-reason ...]</dt>
690 <dd>Sets, adds, or removes printer-state-reason keywords to the
79e1d494
MS
691 current queue. Typically this is used to indicate persistent media,
692 ink, toner, and configuration conditions or errors on a printer.
693 <a href='#TABLE2'>Table 2</a> lists the standard state keywords -
acb056cb
MS
694 use vendor-prefixed ("com.acme.foo") keywords for custom states.
695
696 <blockquote><b>Note:</b>
697
698 <p>"STATE:" messages often provide visible alerts to the user. For example, on
699 Mac OS X setting a printer-state-reason value with an "-error" or "-warning"
700 suffix will cause the printer's dock item to bounce if the corresponding reason
701 is localized with a cupsIPPReason keyword in the printer's PPD file.</p>
702
703 </blockquote></dd>
5a738aea
MS
704
705 <dt>WARNING: message</dt>
706 <dd>Sets the printer-state-message attribute and adds the specified
707 message to the current error log file using the "warning" log
708 level.</dd>
709
710</dl>
711
712<p>Messages without one of these prefixes are treated as if they began with
713the "DEBUG:" prefix string.</p>
714
79e1d494
MS
715<div class='table'><table width='80%' summary='Table 1: Standard marker-types Values'>
716<caption>Table 1: <a name='TABLE1'>Standard marker-types Values</a></caption>
717<thead>
718<tr>
719 <th>marker-type</th>
720 <th>Description</th>
721</tr>
722</thead>
723<tbody>
724<tr>
725 <td>developer</td>
726 <td>Developer unit</td>
727</tr>
728<tr>
729 <td>fuser</td>
730 <td>Fuser unit</td>
731</tr>
732<tr>
733 <td>fuserCleaningPad</td>
734 <td>Fuser cleaning pad</td>
735</tr>
736<tr>
737 <td>fuserOil</td>
738 <td>Fuser oil</td>
739</tr>
740<tr>
741 <td>ink</td>
742 <td>Ink supply</td>
743</tr>
744<tr>
745 <td>opc</td>
746 <td>Photo conductor</td>
747</tr>
748<tr>
749 <td>solidWax</td>
750 <td>Wax supply</td>
751</tr>
752<tr>
753 <td>staples</td>
754 <td>Staple supply</td>
755</tr>
756<tr>
757 <td>toner</td>
758 <td>Toner supply</td>
759</tr>
760<tr>
761 <td>transferUnit</td>
762 <td>Transfer unit</td>
763</tr>
764<tr>
765 <td>wasteInk</td>
766 <td>Waste ink tank</td>
767</tr>
768<tr>
769 <td>wasteToner</td>
770 <td>Waste toner tank</td>
771</tr>
772<tr>
773 <td>wasteWax</td>
774 <td>Waste wax tank</td>
775</tr>
776</tbody>
777</table></div>
778
779<br>
780
781<div class='table'><table width='80%' summary='Table 2: Standard State Keywords'>
782<caption>Table 2: <a name='TABLE2'>Standard State Keywords</a></caption>
783<thead>
784<tr>
785 <th>Keyword</th>
786 <th>Description</th>
787</tr>
788</thead>
789<tbody>
790<tr>
791 <td>connecting-to-device</td>
792 <td>Connecting to printer but not printing yet</td>
793</tr>
794<tr>
795 <td>cover-open</td>
796 <td>A cover is open on the printer</td>
797</tr>
798<tr>
799 <td>input-tray-missing</td>
800 <td>An input tray is missing from the printer</td>
801</tr>
802<tr>
803 <td>marker-supply-empty</td>
804 <td>Out of ink</td>
805</tr>
806<tr>
807 <td>marker-supply-low</td>
808 <td>Low on ink</td>
809</tr>
810<tr>
811 <td>marker-waste-almost-full</td>
812 <td>Waste tank almost full</td>
813</tr>
814<tr>
815 <td>marker-waste-full</td>
816 <td>Waste tank full</td>
817</tr>
818<tr>
819 <td>media-empty</td>
820 <td>Out of media</td>
821</tr>
822<tr>
823 <td>media-jam</td>
824 <td>Media is jammed in the printer</td>
825</tr>
826<tr>
827 <td>media-low</td>
828 <td>Low on media</td>
829</tr>
830<tr>
831 <td>paused</td>
832 <td>Stop the printer</td>
833</tr>
834<tr>
835 <td>timed-out</td>
836 <td>Unable to connect to printer</td>
837</tr>
838<tr>
839 <td>toner-empty</td>
840 <td>Out of toner</td>
841</tr>
842<tr>
843 <td>toner-low</td>
844 <td>Low on toner</td>
845</tr>
846</tbody>
847</table></div>
848
20fbc903 849<h3><a name="COMMUNICATING_BACKEND">Communicating with the Backend</a></h3>
5a738aea
MS
850
851<p>Filters can communicate with the backend via the
852<a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> and
853<a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
854functions. The
855<a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> function
856reads data that has been sent back from the device and is typically used to
857obtain status and configuration information. For example, the following code
858polls the backend for back-channel data:</p>
859
860<pre class="example">
861#include &lt;cups/cups.h&gt;
862
863char buffer[8192];
864ssize_t bytes;
865
866/* Use a timeout of 0.0 seconds to poll for back-channel data */
867bytes = cupsBackChannelRead(buffer, sizeof(buffer), 0.0);
868</pre>
f7deaa1a 869
79e1d494
MS
870<p>Filters can also use <code>select()</code> or <code>poll()</code> on the
871back-channel file descriptor (3 or <code>CUPS_BC_FD</code>) to read data only
872when it is available.</p>
873
874<p>The
5a738aea
MS
875<a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
876function allows you to get out-of-band status information and do synchronization
877with the device. For example, the following code gets the current IEEE-1284
878device ID string from the backend:</p>
879
880<pre class="example">
f7deaa1a 881#include &lt;cups/sidechannel.h&gt;
882
883char data[2049];
884int datalen;
5a738aea 885<a href="#cups_sc_status_t">cups_sc_status_t</a> status;
f7deaa1a 886
79e1d494
MS
887/* Tell cupsSideChannelDoRequest() how big our buffer is, less 1 byte for
888 nul-termination... */
f7deaa1a 889datalen = sizeof(data) - 1;
890
891/* Get the IEEE-1284 device ID, waiting for up to 1 second */
5a738aea 892status = <a href="#cupsSideChannelDoRequest">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_GET_DEVICE_ID, data, &amp;datalen, 1.0);
f7deaa1a 893
894/* Use the returned value if OK was returned and the length is non-zero */
895if (status == CUPS_SC_STATUS_OK && datalen > 0)
896 data[datalen] = '\0';
897else
898 data[0] = '\0';
899</pre>
900
20fbc903
MS
901<h3><a name="COMMUNICATING_FILTER">Communicating with Filters</a></h3>
902
5a738aea
MS
903<p>Backends communicate with filters using the reciprocal functions
904<a href="#cupsBackChannelWrite"><code>cupsBackChannelWrite</code></a>,
905<a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>, and
906<a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a>. We
907recommend writing back-channel data using a timeout of 1.0 seconds:</p>
f7deaa1a 908
5a738aea
MS
909<pre class="example">
910#include &lt;cups/cups.h&gt;
f7deaa1a 911
5a738aea
MS
912char buffer[8192];
913ssize_t bytes;
f7deaa1a 914
79e1d494
MS
915/* Obtain data from printer/device */
916...
917
5a738aea
MS
918/* Use a timeout of 1.0 seconds to give filters a chance to read */
919cupsBackChannelWrite(buffer, bytes, 1.0);
f7deaa1a 920</pre>
921
5a738aea
MS
922<p>The <a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>
923function reads a side-channel command from a filter, driver, or port monitor.
924Backends can either poll for commands using a <code>timeout</code> of 0.0, wait
925indefinitely for commands using a <code>timeout</code> of -1.0 (probably in a
926separate thread for that purpose), or use <code>select</code> or
927<code>poll</code> on the <code>CUPS_SC_FD</code> file descriptor (4) to handle
20fbc903 928input and output on several file descriptors at the same time.</p>
5a738aea
MS
929
930<p>Once a command is processed, the backend uses the
931<a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a> function
932to send its response. For example, the following code shows how to poll for a
933side-channel command and respond to it:</p>
934
935<pre class="example">
f7deaa1a 936#include &lt;cups/sidechannel.h&gt;
937
5a738aea
MS
938<a href="#cups_sc_command_t">cups_sc_command_t</a> command;
939<a href="#cups_sc_status_t">cups_sc_status_t</a> status;
20fbc903
MS
940char data[2048];
941int datalen = sizeof(data);
f7deaa1a 942
943/* Poll for a command... */
20fbc903 944if (!<a href="#cupsSideChannelRead">cupsSideChannelRead</a>(&amp;command, &amp;status, data, &amp;datalen, 0.0))
f7deaa1a 945{
f7deaa1a 946 switch (command)
947 {
20fbc903 948 /* handle supported commands, fill data/datalen/status with values as needed */
f7deaa1a 949
950 default :
951 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
952 datalen = 0;
953 break;
954 }
955
956 /* Send a response... */
5a738aea 957 <a href="#cupsSideChannelWrite">cupsSideChannelWrite</a>(command, status, data, datalen, 1.0);
f7deaa1a 958}
959</pre>
ac884b6a
MS
960
961<h3><a name="SNMP">Doing SNMP Queries with Network Printers</a></h3>
962
963<p>The Simple Network Management Protocol (SNMP) allows you to get the current
964status, page counter, and supply levels from most network printers. Every
965piece of information is associated with an Object Identifier (OID), and
966every printer has a <em>community</em> name associated with it. OIDs can be
967queried directly or by "walking" over a range of OIDs with a common prefix.</p>
968
20fbc903
MS
969<p>The two CUPS SNMP functions provide a simple API for querying network
970printers through the side-channel interface. Each accepts a string containing
971an OID like ".1.3.6.1.2.1.43.10.2.1.4.1.1" (the standard page counter OID)
972along with a timeout for the query.</p>
ac884b6a 973
20fbc903
MS
974<p>The <a href="#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet</code></a>
975function queries a single OID and returns the value as a string in a buffer
976you supply:</p>
ac884b6a
MS
977
978<pre class="example">
20fbc903 979#include &lt;cups/sidechannel.h&gt;
ac884b6a 980
20fbc903
MS
981char data[512];
982int datalen = sizeof(data);
ac884b6a 983
20fbc903
MS
984if (<a href="#cupsSideChannelSNMPGet">cupsSideChannelSNMPGet</a>(".1.3.6.1.2.1.43.10.2.1.4.1.1", data, &amp;datalen, 5.0)
985 == CUPS_SC_STATUS_OK)
ac884b6a
MS
986{
987 /* Do something with the value */
20fbc903 988 printf("Page counter is: %s\n", data);
ac884b6a
MS
989}
990</pre>
991
20fbc903
MS
992<p>The
993<a href="#cupsSideChannelSNMPWalk"><code>cupsSideChannelSNMPWalk</code></a>
994function allows you to query a whole group of OIDs, calling a function of your
995choice for each OID that is found:</p>
ac884b6a
MS
996
997<pre class="example">
20fbc903 998#include &lt;cups/sidechannel.h&gt;
ac884b6a
MS
999
1000void
20fbc903 1001my_callback(const char *oid, const char *data, int datalen, void *context)
ac884b6a
MS
1002{
1003 /* Do something with the value */
20fbc903 1004 printf("%s=%s\n", oid, data);
ac884b6a
MS
1005}
1006
20fbc903
MS
1007...
1008
ac884b6a
MS
1009void *my_data;
1010
20fbc903 1011<a href="#cupsSideChannelSNMPWalk">cupsSNMPSideChannelWalk</a>(".1.3.6.1.2.1.43", 5.0, my_callback, my_data);
ac884b6a 1012</pre>
20fbc903 1013<h2 class="title"><a name="FUNCTIONS">Functions</a></h2>
426c6a59 1014<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
1015<p class="description">Read data from the backchannel.</p>
1016<p class="code">
1017ssize_t cupsBackChannelRead (<br>
1018&nbsp;&nbsp;&nbsp;&nbsp;char *buffer,<br>
1019&nbsp;&nbsp;&nbsp;&nbsp;size_t bytes,<br>
1020&nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1021);</p>
1022<h4 class="parameters">Parameters</h4>
1023<dl>
1024<dt>buffer</dt>
79e1d494 1025<dd class="description">Buffer to read into</dd>
5a738aea
MS
1026<dt>bytes</dt>
1027<dd class="description">Bytes to read</dd>
1028<dt>timeout</dt>
79e1d494 1029<dd class="description">Timeout in seconds, typically 0.0 to poll</dd>
5a738aea
MS
1030</dl>
1031<h4 class="returnvalue">Return Value</h4>
1032<p class="description">Bytes read or -1 on error</p>
1033<h4 class="discussion">Discussion</h4>
79e1d494
MS
1034<p class="discussion">Reads up to &quot;bytes&quot; bytes from the backchannel/backend. The &quot;timeout&quot;
1035parameter controls how many seconds to wait for the data - use 0.0 to
1036return immediately if there is no data, -1.0 to wait for data indefinitely.
ef416fc2 1037
5a738aea 1038</p>
426c6a59 1039<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
1040<p class="description">Write data to the backchannel.</p>
1041<p class="code">
1042ssize_t cupsBackChannelWrite (<br>
1043&nbsp;&nbsp;&nbsp;&nbsp;const char *buffer,<br>
1044&nbsp;&nbsp;&nbsp;&nbsp;size_t bytes,<br>
1045&nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1046);</p>
1047<h4 class="parameters">Parameters</h4>
1048<dl>
1049<dt>buffer</dt>
1050<dd class="description">Buffer to write</dd>
1051<dt>bytes</dt>
1052<dd class="description">Bytes to write</dd>
1053<dt>timeout</dt>
79e1d494 1054<dd class="description">Timeout in seconds, typically 1.0</dd>
5a738aea
MS
1055</dl>
1056<h4 class="returnvalue">Return Value</h4>
1057<p class="description">Bytes written or -1 on error</p>
1058<h4 class="discussion">Discussion</h4>
79e1d494 1059<p class="discussion">Writes &quot;bytes&quot; bytes to the backchannel/filter. The &quot;timeout&quot; parameter
ef416fc2 1060controls how many seconds to wait for the data to be written - use
10610.0 to return immediately if the data cannot be written, -1.0 to wait
1062indefinitely.
1063
ac884b6a 1064</p>
426c6a59 1065<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
1066<p class="description">Get the device URI for a backend.</p>
1067<p class="code">
1068const char *cupsBackendDeviceURI (<br>
1069&nbsp;&nbsp;&nbsp;&nbsp;char **argv<br>
1070);</p>
1071<h4 class="parameters">Parameters</h4>
1072<dl>
1073<dt>argv</dt>
1074<dd class="description">Command-line arguments</dd>
1075</dl>
1076<h4 class="returnvalue">Return Value</h4>
1077<p class="description">Device URI or <code>NULL</code></p>
1078<h4 class="discussion">Discussion</h4>
1079<p class="discussion">The &quot;argv&quot; argument is the argv argument passed to main(). This
1080function returns the device URI passed in the DEVICE_URI environment
1081variable or the device URI passed in argv[0], whichever is found
426c6a59
MS
1082first.
1083
1084</p>
178cb736 1085<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
1086<p class="description">Write a device line from a backend.</p>
1087<p class="code">
1088void cupsBackendReport (<br>
1089&nbsp;&nbsp;&nbsp;&nbsp;const char *device_scheme,<br>
1090&nbsp;&nbsp;&nbsp;&nbsp;const char *device_uri,<br>
1091&nbsp;&nbsp;&nbsp;&nbsp;const char *device_make_and_model,<br>
1092&nbsp;&nbsp;&nbsp;&nbsp;const char *device_info,<br>
1093&nbsp;&nbsp;&nbsp;&nbsp;const char *device_id,<br>
1094&nbsp;&nbsp;&nbsp;&nbsp;const char *device_location<br>
1095);</p>
1096<h4 class="parameters">Parameters</h4>
1097<dl>
1098<dt>device_scheme</dt>
1099<dd class="description">device-scheme string</dd>
1100<dt>device_uri</dt>
1101<dd class="description">device-uri string</dd>
1102<dt>device_make_and_model</dt>
1103<dd class="description">device-make-and-model string or <code>NULL</code></dd>
1104<dt>device_info</dt>
1105<dd class="description">device-info string or <code>NULL</code></dd>
1106<dt>device_id</dt>
1107<dd class="description">device-id string or <code>NULL</code></dd>
1108<dt>device_location</dt>
1109<dd class="description">device-location string or <code>NULL</code></dd>
1110</dl>
1111<h4 class="discussion">Discussion</h4>
1112<p class="discussion">This function writes a single device line to stdout for a backend.
1113It handles quoting of special characters in the device-make-and-model,
426c6a59
MS
1114device-info, device-id, and device-location strings.
1115
1116</p>
1117<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
1118<p class="description">Send a side-channel command to a backend and wait for a response.</p>
1119<p class="code">
1120<a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelDoRequest (<br>
1121&nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> command,<br>
1122&nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
1123&nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
1124&nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1125);</p>
1126<h4 class="parameters">Parameters</h4>
1127<dl>
1128<dt>command</dt>
1129<dd class="description">Command to send</dd>
1130<dt>data</dt>
1131<dd class="description">Response data buffer pointer</dd>
1132<dt>datalen</dt>
1133<dd class="description">Size of data buffer on entry, number of bytes in buffer on return</dd>
1134<dt>timeout</dt>
1135<dd class="description">Timeout in seconds</dd>
1136</dl>
1137<h4 class="returnvalue">Return Value</h4>
1138<p class="description">Status of command</p>
1139<h4 class="discussion">Discussion</h4>
1140<p class="discussion">This function is normally only called by filters, drivers, or port
f7deaa1a 1141monitors in order to communicate with the backend used by the current
1142printer. Programs must be prepared to handle timeout or &quot;not
1143implemented&quot; status codes, which indicate that the backend or device
5a738aea
MS
1144do not support the specified side-channel command.<br>
1145<br>
1146The &quot;datalen&quot; parameter must be initialized to the size of the buffer
f7deaa1a 1147pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
1148update the value to contain the number of data bytes in the buffer.
1149
5a738aea 1150</p>
426c6a59 1151<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
1152<p class="description">Read a side-channel message.</p>
1153<p class="code">
1154int cupsSideChannelRead (<br>
1155&nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> *command,<br>
1156&nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_status_t">cups_sc_status_t</a> *status,<br>
1157&nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
1158&nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
1159&nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1160);</p>
1161<h4 class="parameters">Parameters</h4>
1162<dl>
1163<dt>command</dt>
1164<dd class="description">Command code</dd>
1165<dt>status</dt>
1166<dd class="description">Status code</dd>
1167<dt>data</dt>
1168<dd class="description">Data buffer pointer</dd>
1169<dt>datalen</dt>
1170<dd class="description">Size of data buffer on entry, number of bytes in buffer on return</dd>
1171<dt>timeout</dt>
1172<dd class="description">Timeout in seconds</dd>
1173</dl>
1174<h4 class="returnvalue">Return Value</h4>
1175<p class="description">0 on success, -1 on error</p>
1176<h4 class="discussion">Discussion</h4>
1177<p class="discussion">This function is normally only called by backend programs to read
f7deaa1a 1178commands from a filter, driver, or port monitor program. The
1179caller must be prepared to handle incomplete or invalid messages
5a738aea
MS
1180and return the corresponding status codes.<br>
1181<br>
1182The &quot;datalen&quot; parameter must be initialized to the size of the buffer
f7deaa1a 1183pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
1184update the value to contain the number of data bytes in the buffer.
1185
20fbc903 1186</p>
178cb736 1187<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
1188<p class="description">Query a SNMP OID's value.</p>
1189<p class="code">
1190<a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelSNMPGet (<br>
1191&nbsp;&nbsp;&nbsp;&nbsp;const char *oid,<br>
1192&nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
1193&nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
1194&nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1195);</p>
1196<h4 class="parameters">Parameters</h4>
1197<dl>
1198<dt>oid</dt>
1199<dd class="description">OID to query</dd>
1200<dt>data</dt>
1201<dd class="description">Buffer for OID value</dd>
1202<dt>datalen</dt>
1203<dd class="description">Size of OID buffer on entry, size of value on return</dd>
1204<dt>timeout</dt>
1205<dd class="description">Timeout in seconds</dd>
1206</dl>
1207<h4 class="returnvalue">Return Value</h4>
1208<p class="description">Query status</p>
1209<h4 class="discussion">Discussion</h4>
1210<p class="discussion">This function asks the backend to do a SNMP OID query on behalf of the
1211filter, port monitor, or backend using the default community name.<br>
1212<br>
1213&quot;oid&quot; contains a numeric OID consisting of integers separated by periods,
1214for example &quot;.1.3.6.1.2.1.43&quot;. Symbolic names from SNMP MIBs are not
1215supported and must be converted to their numeric forms.<br>
1216<br>
1217On input, &quot;data&quot; and &quot;datalen&quot; provide the location and size of the
1218buffer to hold the OID value as a string. HEX-String (binary) values are
1219converted to hexadecimal strings representing the binary data, while
1220NULL-Value and unknown OID types are returned as the empty string.
1221The returned &quot;datalen&quot; does not include the trailing nul.
1222
1223<code>CUPS_SC_STATUS_NOT_IMPLEMENTED</code> is returned by backends that do not
1224support SNMP queries. <code>CUPS_SC_STATUS_NO_RESPONSE</code> is returned when
1225the printer does not respond to the SNMP query.
1226
1227</p>
178cb736 1228<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
1229<p class="description">Query multiple SNMP OID values.</p>
1230<p class="code">
1231<a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelSNMPWalk (<br>
1232&nbsp;&nbsp;&nbsp;&nbsp;const char *oid,<br>
1233&nbsp;&nbsp;&nbsp;&nbsp;double timeout,<br>
1234&nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_walk_func_t">cups_sc_walk_func_t</a> cb,<br>
1235&nbsp;&nbsp;&nbsp;&nbsp;void *context<br>
1236);</p>
1237<h4 class="parameters">Parameters</h4>
1238<dl>
1239<dt>oid</dt>
1240<dd class="description">First numeric OID to query</dd>
1241<dt>timeout</dt>
1242<dd class="description">Timeout for each query in seconds</dd>
1243<dt>cb</dt>
1244<dd class="description">Function to call with each value</dd>
1245<dt>context</dt>
1246<dd class="description">Application-defined pointer to send to callback</dd>
1247</dl>
1248<h4 class="returnvalue">Return Value</h4>
1249<p class="description">Status of first query of <code>CUPS_SC_STATUS_OK</code> on success</p>
1250<h4 class="discussion">Discussion</h4>
1251<p class="discussion">This function asks the backend to do multiple SNMP OID queries on behalf
1252of the filter, port monitor, or backend using the default community name.
1253All OIDs under the &quot;parent&quot; OID are queried and the results are sent to
1254the callback function you provide.<br>
1255<br>
1256&quot;oid&quot; contains a numeric OID consisting of integers separated by periods,
1257for example &quot;.1.3.6.1.2.1.43&quot;. Symbolic names from SNMP MIBs are not
1258supported and must be converted to their numeric forms.<br>
1259<br>
1260&quot;timeout&quot; specifies the timeout for each OID query. The total amount of
1261time will depend on the number of OID values found and the time required
1262for each query.<br>
1263<br>
1264&quot;cb&quot; provides a function to call for every value that is found. &quot;context&quot;
1265is an application-defined pointer that is sent to the callback function
1266along with the OID and current data. The data passed to the callback is the
1267same as returned by <a href="#cupsSideChannelSNMPGet"><code>cupsSideChannelSNMPGet</code></a>.
1268
1269<code>CUPS_SC_STATUS_NOT_IMPLEMENTED</code> is returned by backends that do not
1270support SNMP queries. <code>CUPS_SC_STATUS_NO_RESPONSE</code> is returned when
1271the printer does not respond to the first SNMP query.
1272
5a738aea 1273</p>
426c6a59 1274<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
1275<p class="description">Write a side-channel message.</p>
1276<p class="code">
1277int cupsSideChannelWrite (<br>
1278&nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> command,<br>
1279&nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_status_t">cups_sc_status_t</a> status,<br>
1280&nbsp;&nbsp;&nbsp;&nbsp;const char *data,<br>
1281&nbsp;&nbsp;&nbsp;&nbsp;int datalen,<br>
1282&nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
1283);</p>
1284<h4 class="parameters">Parameters</h4>
1285<dl>
1286<dt>command</dt>
1287<dd class="description">Command code</dd>
1288<dt>status</dt>
1289<dd class="description">Status code</dd>
1290<dt>data</dt>
1291<dd class="description">Data buffer pointer</dd>
1292<dt>datalen</dt>
1293<dd class="description">Number of bytes of data</dd>
1294<dt>timeout</dt>
1295<dd class="description">Timeout in seconds</dd>
1296</dl>
1297<h4 class="returnvalue">Return Value</h4>
1298<p class="description">0 on success, -1 on error</p>
1299<h4 class="discussion">Discussion</h4>
1300<p class="discussion">This function is normally only called by backend programs to send
f7deaa1a 1301responses to a filter, driver, or port monitor program.
1302
5a738aea
MS
1303</p>
1304<h2 class="title"><a name="TYPES">Data Types</a></h2>
1305<h3 class="typedef"><a name="cups_backend_t">cups_backend_t</a></h3>
1306<p class="description">Backend exit codes</p>
1307<p class="code">
1308typedef enum <a href="#cups_backend_e">cups_backend_e</a> cups_backend_t;
1309</p>
1310<h3 class="typedef"><a name="cups_sc_bidi_t">cups_sc_bidi_t</a></h3>
1311<p class="description">Bidirectional capabilities</p>
1312<p class="code">
1313typedef enum <a href="#cups_sc_bidi_e">cups_sc_bidi_e</a> cups_sc_bidi_t;
1314</p>
1315<h3 class="typedef"><a name="cups_sc_command_t">cups_sc_command_t</a></h3>
1316<p class="description">Request command codes</p>
1317<p class="code">
1318typedef enum <a href="#cups_sc_command_e">cups_sc_command_e</a> cups_sc_command_t;
1319</p>
82f97232
MS
1320<h3 class="typedef"><a name="cups_sc_connected_t">cups_sc_connected_t</a></h3>
1321<p class="description">Connectivity values</p>
1322<p class="code">
1323typedef enum <a href="#cups_sc_connected_e">cups_sc_connected_e</a> cups_sc_connected_t;
1324</p>
5a738aea
MS
1325<h3 class="typedef"><a name="cups_sc_state_t">cups_sc_state_t</a></h3>
1326<p class="description">Printer state bits</p>
1327<p class="code">
1328typedef enum <a href="#cups_sc_state_e">cups_sc_state_e</a> cups_sc_state_t;
1329</p>
1330<h3 class="typedef"><a name="cups_sc_status_t">cups_sc_status_t</a></h3>
1331<p class="description">Response status codes</p>
1332<p class="code">
1333typedef enum <a href="#cups_sc_status_e">cups_sc_status_e</a> cups_sc_status_t;
1334</p>
20fbc903
MS
1335<h3 class="typedef"><a name="cups_sc_walk_func_t">cups_sc_walk_func_t</a></h3>
1336<p class="description">SNMP walk callback</p>
1337<p class="code">
1338typedef void (*cups_sc_walk_func_t)(const char *oid, const char *data, int datalen, void *context);
1339</p>
5a738aea
MS
1340<h2 class="title"><a name="ENUMERATIONS">Constants</a></h2>
1341<h3 class="enumeration"><a name="cups_backend_e">cups_backend_e</a></h3>
1342<p class="description">Backend exit codes</p>
1343<h4 class="constants">Constants</h4>
1344<dl>
1345<dt>CUPS_BACKEND_AUTH_REQUIRED </dt>
1346<dd class="description">Job failed, authentication required</dd>
1347<dt>CUPS_BACKEND_CANCEL </dt>
1348<dd class="description">Job failed, cancel job</dd>
1349<dt>CUPS_BACKEND_FAILED </dt>
1350<dd class="description">Job failed, use error-policy</dd>
1351<dt>CUPS_BACKEND_HOLD </dt>
1352<dd class="description">Job failed, hold job</dd>
1353<dt>CUPS_BACKEND_OK </dt>
1354<dd class="description">Job completed successfully</dd>
1355<dt>CUPS_BACKEND_STOP </dt>
1356<dd class="description">Job failed, stop queue</dd>
1357</dl>
1358<h3 class="enumeration"><a name="cups_sc_bidi_e">cups_sc_bidi_e</a></h3>
79e1d494 1359<p class="description">Bidirectional capability values</p>
5a738aea
MS
1360<h4 class="constants">Constants</h4>
1361<dl>
1362<dt>CUPS_SC_BIDI_NOT_SUPPORTED </dt>
1363<dd class="description">Bidirectional I/O is not supported</dd>
1364<dt>CUPS_SC_BIDI_SUPPORTED </dt>
1365<dd class="description">Bidirectional I/O is supported</dd>
1366</dl>
1367<h3 class="enumeration"><a name="cups_sc_command_e">cups_sc_command_e</a></h3>
1368<p class="description">Request command codes</p>
1369<h4 class="constants">Constants</h4>
1370<dl>
1371<dt>CUPS_SC_CMD_DRAIN_OUTPUT </dt>
1372<dd class="description">Drain all pending output</dd>
1373<dt>CUPS_SC_CMD_GET_BIDI </dt>
1374<dd class="description">Return bidirectional capabilities</dd>
82f97232
MS
1375<dt>CUPS_SC_CMD_GET_CONNECTED <span class="info">&nbsp;CUPS 1.5&nbsp;</span></dt>
1376<dd class="description">Return whether the backend is &quot;connected&quot; to the printer </dd>
5a738aea
MS
1377<dt>CUPS_SC_CMD_GET_DEVICE_ID </dt>
1378<dd class="description">Return the IEEE-1284 device ID</dd>
1379<dt>CUPS_SC_CMD_GET_STATE </dt>
1380<dd class="description">Return the device state</dd>
178cb736 1381<dt>CUPS_SC_CMD_SNMP_GET <span class="info">&nbsp;CUPS 1.4/Mac OS X 10.6&nbsp;</span></dt>
20fbc903 1382<dd class="description">Query an SNMP OID </dd>
178cb736 1383<dt>CUPS_SC_CMD_SNMP_GET_NEXT <span class="info">&nbsp;CUPS 1.4/Mac OS X 10.6&nbsp;</span></dt>
20fbc903 1384<dd class="description">Query the next SNMP OID </dd>
5a738aea
MS
1385<dt>CUPS_SC_CMD_SOFT_RESET </dt>
1386<dd class="description">Do a soft reset</dd>
1387</dl>
82f97232
MS
1388<h3 class="enumeration"><a name="cups_sc_connected_e">cups_sc_connected_e</a></h3>
1389<p class="description">Connectivity values</p>
1390<h4 class="constants">Constants</h4>
1391<dl>
1392<dt>CUPS_SC_CONNECTED </dt>
1393<dd class="description">Backend is &quot;connected&quot; to printer</dd>
1394<dt>CUPS_SC_NOT_CONNECTED </dt>
1395<dd class="description">Backend is not &quot;connected&quot; to printer</dd>
1396</dl>
5a738aea
MS
1397<h3 class="enumeration"><a name="cups_sc_state_e">cups_sc_state_e</a></h3>
1398<p class="description">Printer state bits</p>
1399<h4 class="constants">Constants</h4>
1400<dl>
1401<dt>CUPS_SC_STATE_BUSY </dt>
1402<dd class="description">Device is busy</dd>
1403<dt>CUPS_SC_STATE_ERROR </dt>
1404<dd class="description">Other error condition</dd>
1405<dt>CUPS_SC_STATE_MARKER_EMPTY </dt>
1406<dd class="description">Toner/ink out condition</dd>
1407<dt>CUPS_SC_STATE_MARKER_LOW </dt>
1408<dd class="description">Toner/ink low condition</dd>
1409<dt>CUPS_SC_STATE_MEDIA_EMPTY </dt>
1410<dd class="description">Paper out condition</dd>
1411<dt>CUPS_SC_STATE_MEDIA_LOW </dt>
1412<dd class="description">Paper low condition</dd>
1413<dt>CUPS_SC_STATE_OFFLINE </dt>
79e1d494 1414<dd class="description">Device is offline</dd>
5a738aea 1415<dt>CUPS_SC_STATE_ONLINE </dt>
79e1d494 1416<dd class="description">Device is online</dd>
5a738aea
MS
1417</dl>
1418<h3 class="enumeration"><a name="cups_sc_status_e">cups_sc_status_e</a></h3>
1419<p class="description">Response status codes</p>
1420<h4 class="constants">Constants</h4>
1421<dl>
1422<dt>CUPS_SC_STATUS_BAD_MESSAGE </dt>
1423<dd class="description">The command/response message was invalid</dd>
1424<dt>CUPS_SC_STATUS_IO_ERROR </dt>
1425<dd class="description">An I/O error occurred</dd>
1426<dt>CUPS_SC_STATUS_NONE </dt>
1427<dd class="description">No status</dd>
1428<dt>CUPS_SC_STATUS_NOT_IMPLEMENTED </dt>
1429<dd class="description">Command not implemented</dd>
1430<dt>CUPS_SC_STATUS_NO_RESPONSE </dt>
1431<dd class="description">The device did not respond</dd>
1432<dt>CUPS_SC_STATUS_OK </dt>
1433<dd class="description">Operation succeeded</dd>
1434<dt>CUPS_SC_STATUS_TIMEOUT </dt>
1435<dd class="description">The backend did not respond</dd>
1436<dt>CUPS_SC_STATUS_TOO_BIG </dt>
1437<dd class="description">Response too big</dd>
1438</dl>
1439</div>
ef416fc2 1440</body>
1441</html>