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