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