]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/api-filter.shtml
Merge changes from CUPS 1.5svn-r9763.
[thirdparty/cups.git] / cups / api-filter.shtml
index 2be3b2bf6529466c1f30dd89a677e3468a9e03f2..2e149f11fb29df66f091d3a9731a0077b6c7b465 100644 (file)
@@ -1,10 +1,9 @@
 <!--
-  "$Id: api-filter.shtml 6649 2007-07-11 21:46:42Z mike $"
+  "$Id: api-filter.shtml 7677 2008-06-19 23:22:19Z mike $"
 
-  Filter and backend programming introduction for the Common UNIX Printing
-  System (CUPS).
+  Filter and backend programming introduction for CUPS.
 
-  Copyright 2007-2008 by Apple Inc.
+  Copyright 2007-2011 by Apple Inc.
   Copyright 1997-2006 by Easy Software Products, all rights reserved.
 
   These coded instructions, statements, and computer programs are the
@@ -49,10 +48,16 @@ the remaining filters read from the standard input and write to the standard
 output. The backend is the last filter in the chain and writes to the
 device.</p>
 
+<p>Filters are always run as a non-privileged user, typically "lp", with no
+connection to the user's desktop. Backends are run either as a non-privileged
+user or as root if the file permissions do not allow user or group execution.
+The <a href="#PERMISSIONS">file permissions</a> section talks about this in
+more detail.</p>
+
 <h3><a name="SECURITY">Security Considerations</a></h3>
 
 <p>It is always important to use security programming practices. Filters and
-most backends are run as a non-priviledged user, so the major security
+most backends are run as a non-privileged user, so the major security
 consideration is resource utilization - filters should not depend on unlimited
 amounts of CPU, memory, or disk space, and should protect against conditions
 that could lead to excess usage of any resource like infinite loops and
@@ -75,10 +80,47 @@ user may not be the same as the local user and/or there may not be a local home
 directory to write to.</p>
 
 <p>In addition, some operating systems provide additional security mechanisms
-that further limit file system access, even for backends running as root.  On
+that further limit file system access, even for backends running as root. On
 Mac OS X, for example, no backend may write to a user's home directory.</p>
 </blockquote>
 
+<h3><a name="SIGNALS">Signal Handling</a><h3>
+
+<p>The scheduler sends <code>SIGTERM</code> when a printing job is canceled or
+held. Filters, backends, and port monitors <em>must</em> catch
+<code>SIGTERM</code> and perform any cleanup necessary to produce a valid output
+file or return the printer to a known good state. The recommended behavior is to
+end the output on the current page.</p>
+
+<p>Filters and backends may also receive <code>SIGPIPE</code> when an upstream or downstream filter/backend exits with a non-zero status. Developers should generally <code>ignore SIGPIPE</code> at the beginning of <code>main()</code> with the following function call:</p>
+
+<pre class="example">
+#include &lt;signal.h&gt;>
+
+...
+
+int
+main(int argc, char *argv[])
+{
+  signal(SIGPIPE, SIG_IGN);
+
+  ...
+}
+</pre>
+
+<h3><a name="PERMISSIONS">File Permissions</a></h3>
+
+<p>For security reasons, CUPS will only run filters and backends that are owned
+by root and do not have world or group write permissions. The recommended
+permissions for filters and backends are 0555 - read and execute but no write.
+Backends that must run as root should use permissions of 0500 - read and execute
+by root, no access for other users. Write permissions can be enabled for the
+root user only.</p>
+
+<p>To avoid a warning message, the directory containing your filter(s) must also
+be owned by root and have world and group write disabled - permissions of 0755
+or 0555 are strongly encouraged.</p>
+
 <h3><a name="TEMPFILES">Temporary Files</a></h3>
 
 <p>Temporary files should be created in the directory specified by the
@@ -108,7 +150,7 @@ when running print filters and backends:</p>
 
 <dl class="code">
 
-       <dt>APPLE_LANGUAGES</dt>
+       <dt>APPLE_LANGUAGE</dt>
        <dd>The Apple language identifier associated with the job
        (Mac OS X only).</dd>
 
@@ -131,6 +173,10 @@ when running print filters and backends:</p>
        <dt>CUPS_DATADIR</dt>
        <dd>The directory where (read-only) CUPS data files can be found.</dd>
 
+       <dt>CUPS_FILETYPE</dt>
+       <dd>The type of file being printed: "job-sheet" for a banner page and
+       "document" for a regular print file.</dd>
+
        <dt>CUPS_SERVERROOT</dt>
        <dd>The root directory of the server.</dd>
 
@@ -185,10 +231,11 @@ prefix strings:</p>
        <dt>ATTR: attribute=value [attribute=value]</dt>
        <dd>Sets the named printer or job attribute(s). Typically this is used
        to set the <code>marker-colors</code>, <code>marker-levels</code>,
-       <code>marker-names</code>, <code>marker-types</code>,
-       <code>printer-alert</code>, and <code>printer-alert-description</code>
-       printer attributes. Standard <code>marker-types</code> values are
-       listed in <a href='#TABLE1'>Table 1</a>.</dd>
+       <code>marker-message</code>, <code>marker-names</code>,
+       <code>marker-types</code>, <code>printer-alert</code>, and
+       <code>printer-alert-description</code> printer attributes. Standard
+       <code>marker-types</code> values are listed in <a href='#TABLE1'>Table
+       1</a>.</dd>
 
        <dt>CRIT: message</dt>
        <dd>Sets the printer-state-message attribute and adds the specified
@@ -240,7 +287,16 @@ prefix strings:</p>
        current queue. Typically this is used to indicate persistent media,
        ink, toner, and configuration conditions or errors on a printer.
        <a href='#TABLE2'>Table 2</a> lists the standard state keywords -
-       use vendor-prefixed ("com.acme.foo") keywords for custom states.</dd>
+       use vendor-prefixed ("com.acme.foo") keywords for custom states.
+
+       <blockquote><b>Note:</b>
+
+       <p>"STATE:" messages often provide visible alerts to the user. For example, on
+       Mac OS X setting a printer-state-reason value with an "-error" or "-warning"
+       suffix will cause the printer's dock item to bounce if the corresponding reason
+       is localized with a cupsIPPReason keyword in the printer's PPD file.</p>
+
+       </blockquote></dd>
 
        <dt>WARNING: message</dt>
        <dd>Sets the printer-state-message attribute and adds the specified
@@ -252,7 +308,6 @@ prefix strings:</p>
 <p>Messages without one of these prefixes are treated as if they began with
 the "DEBUG:" prefix string.</p>
 
-
 <div class='table'><table width='80%' summary='Table 1: Standard marker-types Values'>
 <caption>Table 1: <a name='TABLE1'>Standard marker-types Values</a></caption>
 <thead>
@@ -392,7 +447,7 @@ the "DEBUG:" prefix string.</p>
 <p>Filters can communicate with the backend via the
 <a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> and
 <a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
-functions. The 
+functions. The
 <a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> function
 reads data that has been sent back from the device and is typically used to
 obtain status and configuration information. For example, the following code