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