1*5e7646d2SAndroid Build Coastguard Worker<!-- 2*5e7646d2SAndroid Build Coastguard Worker Administrative API documentation for CUPS. 3*5e7646d2SAndroid Build Coastguard Worker 4*5e7646d2SAndroid Build Coastguard Worker Copyright © 2016 by Apple Inc. 5*5e7646d2SAndroid Build Coastguard Worker 6*5e7646d2SAndroid Build Coastguard Worker Licensed under Apache License v2.0. See the file "LICENSE" for more 7*5e7646d2SAndroid Build Coastguard Worker information. 8*5e7646d2SAndroid Build Coastguard Worker--> 9*5e7646d2SAndroid Build Coastguard Worker 10*5e7646d2SAndroid Build Coastguard Worker<h2 class="title"><a name="OVERVIEW">Overview</a></h2> 11*5e7646d2SAndroid Build Coastguard Worker 12*5e7646d2SAndroid Build Coastguard Worker<p>The administrative APIs provide convenience functions to perform certain administrative functions with the CUPS scheduler.</p> 13*5e7646d2SAndroid Build Coastguard Worker 14*5e7646d2SAndroid Build Coastguard Worker<blockquote><b>Note:</b> 15*5e7646d2SAndroid Build Coastguard Worker <p>Administrative functions normally require administrative privileges to execute and must not be used in ordinary user applications!</p> 16*5e7646d2SAndroid Build Coastguard Worker</blockquote> 17*5e7646d2SAndroid Build Coastguard Worker 18*5e7646d2SAndroid Build Coastguard Worker<h3><a name="SETTINGS">Scheduler Settings</a></h3> 19*5e7646d2SAndroid Build Coastguard Worker 20*5e7646d2SAndroid Build Coastguard Worker<p>The <a href="#cupsAdminGetServerSettings"><code>cupsAdminGetServerSettings</code></a> and <a href="#cupsAdminSetServerSettings"><code>cupsAdminSetServerSettings</code></a> functions allow you to get and set simple directives and their values, respectively, in the <var>cupsd.conf</var> file for the CUPS scheduler. Settings are stored in CUPS option arrays which provide a simple list of string name/value pairs. While any simple <var>cupsd.conf</var> directive name can be specified, the following convenience names are also defined to control common complex directives:</p> 21*5e7646d2SAndroid Build Coastguard Worker 22*5e7646d2SAndroid Build Coastguard Worker<ul> 23*5e7646d2SAndroid Build Coastguard Worker <li><code>CUPS_SERVER_DEBUG_LOGGING</code></li>: For <code>cupsAdminGetServerSettings</code>, a value of "1" means that the <code>LogLevel</code> directive is set to <code>debug</code> or <code>debug2</code> while a value of "0" means it is set to any other value. For <code>cupsAdminSetServerSettings</code> a value of "1" sets the <code>LogLeveL</code> to <code>debug</code> while a value of "0" sets it to <code>warn</code>.</li> 24*5e7646d2SAndroid Build Coastguard Worker <li><code>CUPS_SERVER_REMOTE_ADMIN</code></li>: A value of "1" specifies that administrative requests are accepted from remote addresses while "0" specifies that requests are only accepted from local addresses (loopback interface and domain sockets).</li> 25*5e7646d2SAndroid Build Coastguard Worker <li><code>CUPS_SERVER_REMOTE_ANY</code></li>: A value of "1" specifies that requests are accepts from any address while "0" specifies that requests are only accepted from the local subnet (when sharing is enabled) or local addresses (loopback interface and domain sockets).</li> 26*5e7646d2SAndroid Build Coastguard Worker <li><code>CUPS_SERVER_SHARE_PRINTERS</code></li>: A value of "1" specifies that printer sharing is enabled for selected printers and remote requests are accepted while a value of "0" specifies that printer sharing is disables and remote requests are not accepted.</li> 27*5e7646d2SAndroid Build Coastguard Worker <li><code>CUPS_SERVER_USER_CANCEL_ANY</code></li>: A value of "1" specifies that the default security policy allows any user to cancel any print job, regardless of the owner. A value of "0" specifies that only administrative users can cancel other user's jobs.</li> 28*5e7646d2SAndroid Build Coastguard Worker</ul> 29*5e7646d2SAndroid Build Coastguard Worker 30*5e7646d2SAndroid Build Coastguard Worker<blockquote><b>Note:</b> 31*5e7646d2SAndroid Build Coastguard Worker <p>Changing settings will restart the CUPS scheduler.</p> 32*5e7646d2SAndroid Build Coastguard Worker <p>When printer sharing or the web interface are enabled, the scheduler's launch-on-demand functionality is effectively disabled. This can affect power usage, system performance, and the security profile of a system.</p> 33*5e7646d2SAndroid Build Coastguard Worker</blockquote> 34*5e7646d2SAndroid Build Coastguard Worker 35*5e7646d2SAndroid Build Coastguard Worker<p>The recommended way to make changes to the <var>cupsd.conf</var> is to first call <a href="#cupsAdminGetServerSettings"><code>cupsAdminGetServerSettings</code></a>, make any changes to the returned option array, and then call <a href="#cupsAdminSetServerSettings"><code>cupsAdminSetServerSettings</code></a> to save those settings. For example, to enable the web interface:</p> 36*5e7646d2SAndroid Build Coastguard Worker 37*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 38*5e7646d2SAndroid Build Coastguard Worker#include <cups/cups.h> 39*5e7646d2SAndroid Build Coastguard Worker#include <cups/adminutil.h> 40*5e7646d2SAndroid Build Coastguard Worker 41*5e7646d2SAndroid Build Coastguard Workervoid 42*5e7646d2SAndroid Build Coastguard Workerenable_web_interface(void) 43*5e7646d2SAndroid Build Coastguard Worker{ 44*5e7646d2SAndroid Build Coastguard Worker int num_settings = 0; /* Number of settings */ 45*5e7646d2SAndroid Build Coastguard Worker cups_option_t *settings = NULL; /* Settings */ 46*5e7646d2SAndroid Build Coastguard Worker 47*5e7646d2SAndroid Build Coastguard Worker 48*5e7646d2SAndroid Build Coastguard Worker if (!<a href="#cupsAdminGetServerSettings">cupsAdminGetServerSettings</a>(CUPS_HTTP_DEFAULT, &num_settings, &settings)) 49*5e7646d2SAndroid Build Coastguard Worker { 50*5e7646d2SAndroid Build Coastguard Worker fprintf(stderr, "ERROR: Unable to get server settings: %s\n", cupsLastErrorString()); 51*5e7646d2SAndroid Build Coastguard Worker return; 52*5e7646d2SAndroid Build Coastguard Worker } 53*5e7646d2SAndroid Build Coastguard Worker 54*5e7646d2SAndroid Build Coastguard Worker num_settings = <a href="api-cups.html#cupsAddOption">cupsAddOption</a>("WebInterface", "Yes", num_settings, &settings); 55*5e7646d2SAndroid Build Coastguard Worker 56*5e7646d2SAndroid Build Coastguard Worker if (!<a href="#cupsAdminSetServerSettings">cupsAdminSetServerSettings</a>(CUPS_HTTP_DEFAULT, num_settings, settings)) 57*5e7646d2SAndroid Build Coastguard Worker { 58*5e7646d2SAndroid Build Coastguard Worker fprintf(stderr, "ERROR: Unable to set server settings: %s\n", cupsLastErrorString()); 59*5e7646d2SAndroid Build Coastguard Worker } 60*5e7646d2SAndroid Build Coastguard Worker 61*5e7646d2SAndroid Build Coastguard Worker <a href="api-cups.html#cupsFreeOptions">cupsFreeOptions</a>(num_settings, settings); 62*5e7646d2SAndroid Build Coastguard Worker} 63*5e7646d2SAndroid Build Coastguard Worker</pre> 64*5e7646d2SAndroid Build Coastguard Worker 65*5e7646d2SAndroid Build Coastguard Worker<h3><a name="DEVICES">Devices</a></h3> 66*5e7646d2SAndroid Build Coastguard Worker 67*5e7646d2SAndroid Build Coastguard Worker<p>Printers can be discovered through the CUPS scheduler using the <a href="#cupsGetDevices"><code>cupsGetDevices</code></a> API. Typically this API is used to locate printers to add the the system. Each device that is found will cause a supplied callback function to be executed. For example, to list the available printer devices that can be found within 30 seconds:</p> 68*5e7646d2SAndroid Build Coastguard Worker 69*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 70*5e7646d2SAndroid Build Coastguard Worker#include <cups/cups.h> 71*5e7646d2SAndroid Build Coastguard Worker#include <cups/adminutil.h> 72*5e7646d2SAndroid Build Coastguard Worker 73*5e7646d2SAndroid Build Coastguard Worker 74*5e7646d2SAndroid Build Coastguard Workervoid 75*5e7646d2SAndroid Build Coastguard Workerget_devices_cb( 76*5e7646d2SAndroid Build Coastguard Worker const char *device_class, /* I - Class */ 77*5e7646d2SAndroid Build Coastguard Worker const char *device_id, /* I - 1284 device ID */ 78*5e7646d2SAndroid Build Coastguard Worker const char *device_info, /* I - Description */ 79*5e7646d2SAndroid Build Coastguard Worker const char *device_make_and_model, /* I - Make and model */ 80*5e7646d2SAndroid Build Coastguard Worker const char *device_uri, /* I - Device URI */ 81*5e7646d2SAndroid Build Coastguard Worker const char *device_location, /* I - Location */ 82*5e7646d2SAndroid Build Coastguard Worker void *user_data) /* I - User data */ 83*5e7646d2SAndroid Build Coastguard Worker{ 84*5e7646d2SAndroid Build Coastguard Worker puts(device_uri); 85*5e7646d2SAndroid Build Coastguard Worker} 86*5e7646d2SAndroid Build Coastguard Worker 87*5e7646d2SAndroid Build Coastguard Worker 88*5e7646d2SAndroid Build Coastguard Workervoid 89*5e7646d2SAndroid Build Coastguard Workershow_devices(void) 90*5e7646d2SAndroid Build Coastguard Worker{ 91*5e7646d2SAndroid Build Coastguard Worker <a href="#cupsGetDevices">cupsGetDevices</a>(CUPS_HTTP_DEFAULT, 30, NULL, NULL, get_devices_cb, NULL); 92*5e7646d2SAndroid Build Coastguard Worker} 93*5e7646d2SAndroid Build Coastguard Worker</pre> 94