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