]>
Commit | Line | Data |
---|---|---|
dffa3c74 MS |
1 | <!-- |
2 | Administrative API documentation for CUPS. | |
3 | ||
53f8d64f | 4 | Copyright © 2016 by Apple Inc. |
dffa3c74 | 5 | |
53f8d64f MS |
6 | Licensed under Apache License v2.0. See the file "LICENSE" for more |
7 | information. | |
dffa3c74 MS |
8 | --> |
9 | ||
10 | <h2 class="title"><a name="OVERVIEW">Overview</a></h2> | |
11 | ||
12 | <p>The administrative APIs provide convenience functions to perform certain administrative functions with the CUPS scheduler.</p> | |
13 | ||
73721e3e | 14 | <blockquote><b>Note:</b> |
dffa3c74 MS |
15 | <p>Administrative functions normally require administrative privileges to execute and must not be used in ordinary user applications!</p> |
16 | </blockquote> | |
17 | ||
18 | <h3><a name="SETTINGS">Scheduler Settings</a></h3> | |
19 | ||
20 | <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 | ||
22 | <ul> | |
23 | <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 | <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 | <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 | <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 | <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 | </ul> | |
29 | ||
30 | <blockquote><b>Note:</b> | |
31 | <p>Changing settings will restart the CUPS scheduler.</p> | |
32 | <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 | </blockquote> | |
34 | ||
35 | <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 | ||
37 | <pre class="example"> | |
38 | #include <cups/cups.h> | |
39 | #include <cups/adminutil.h> | |
40 | ||
41 | void | |
42 | enable_web_interface(void) | |
43 | { | |
44 | int num_settings = 0; /* Number of settings */ | |
45 | cups_option_t *settings = NULL; /* Settings */ | |
46 | ||
47 | ||
48 | if (!<a href="#cupsAdminGetServerSettings">cupsAdminGetServerSettings</a>(CUPS_HTTP_DEFAULT, &num_settings, &settings)) | |
49 | { | |
50 | fprintf(stderr, "ERROR: Unable to get server settings: %s\n", cupsLastErrorString()); | |
51 | return; | |
52 | } | |
53 | ||
54 | num_settings = <a href="api-cups.html#cupsAddOption">cupsAddOption</a>("WebInterface", "Yes", num_settings, &settings); | |
55 | ||
56 | if (!<a href="#cupsAdminSetServerSettings">cupsAdminSetServerSettings</a>(CUPS_HTTP_DEFAULT, num_settings, settings)) | |
57 | { | |
58 | fprintf(stderr, "ERROR: Unable to set server settings: %s\n", cupsLastErrorString()); | |
59 | } | |
60 | ||
61 | <a href="api-cups.html#cupsFreeOptions">cupsFreeOptions</a>(num_settings, settings); | |
62 | } | |
63 | </pre> | |
64 | ||
65 | <h3><a name="DEVICES">Devices</a></h3> | |
66 | ||
67 | <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 | ||
69 | <pre class="example"> | |
70 | #include <cups/cups.h> | |
71 | #include <cups/adminutil.h> | |
72 | ||
73 | ||
74 | void | |
75 | get_devices_cb( | |
76 | const char *device_class, /* I - Class */ | |
77 | const char *device_id, /* I - 1284 device ID */ | |
78 | const char *device_info, /* I - Description */ | |
79 | const char *device_make_and_model, /* I - Make and model */ | |
80 | const char *device_uri, /* I - Device URI */ | |
81 | const char *device_location, /* I - Location */ | |
82 | void *user_data) /* I - User data */ | |
83 | { | |
84 | puts(device_uri); | |
85 | } | |
86 | ||
87 | ||
88 | void | |
89 | show_devices(void) | |
90 | { | |
91 | <a href="#cupsGetDevices">cupsGetDevices</a>(CUPS_HTTP_DEFAULT, 30, NULL, NULL, get_devices_cb, NULL); | |
92 | } | |
93 | </pre> |