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