1<!DOCTYPE html>
2<html>
3<!-- SECTION: Programming -->
4  <head>
5    <title>Administration APIs</title>
6    <meta name="keywords" content="Programming">
7    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
8    <meta name="creator" content="codedoc v3.1">
9    <meta name="author" content="Unknown">
10    <meta name="copyright" content="Unknown">
11    <meta name="version" content="0.0">
12    <style type="text/css"><!--
13BODY {
14  font-family: lucida grande, geneva, helvetica, arial, sans-serif;
15}
16
17H1, H2, H3, H4, H5, H6, P, TD, TH {
18  font-family: lucida grande, geneva, helvetica, arial, sans-serif;
19}
20
21H1 { font-size: 2em; }
22H2 { font-size: 1.75em; }
23H3 { font-size: 1.5em; }
24H4 { font-size: 1.25em; }
25
26KBD {
27  font-family: monaco, courier, monospace;
28  font-weight: bold;
29}
30
31PRE {
32  font-family: monaco, courier, monospace;
33}
34
35BLOCKQUOTE {
36  border-left: solid 2px #777;
37  margin: 1em 0;
38  padding: 10px;
39}
40
41BLOCKQUOTE OL LI {
42  margin-left: -1em;
43}
44
45PRE.command, PRE.example {
46  background: #eee;
47  margin: 0 36pt;
48  padding: 10px;
49}
50
51P.compact {
52  margin: 0;
53}
54
55P.example {
56  font-style: italic;
57  margin-left: 36pt;
58}
59
60DL.man DD {
61  margin-left: 5em;
62}
63
64DL.man DT {
65  margin-left: 0;
66}
67
68PRE.man {
69  margin: 0;
70}
71
72PRE.command EM, PRE.example EM {
73  font-family: lucida grande, geneva, helvetica, arial, sans-serif;
74}
75
76P.command {
77  font-family: monaco, courier, monospace;
78  margin-left: 36pt;
79}
80
81P.formula {
82  font-style: italic;
83  margin-left: 36pt;
84}
85
86A IMG {
87  border: none;
88}
89
90A:link:hover IMG {
91  background: #f0f0f0;
92  border-radius: 10px;
93  -moz-border-radius: 10px;
94}
95
96A:link, A:visited {
97  font-weight: inherit;
98  text-decoration: none;
99}
100
101A:link:hover, A:visited:hover, A:active {
102  text-decoration: underline;
103}
104
105SUB, SUP {
106  font-size: 50%;
107}
108
109TR.data, TD.data, TR.data TD {
110  margin-top: 10pt;
111  padding: 5pt;
112  border-bottom: solid 1pt #999999;
113}
114
115TR.data TH {
116  border-bottom: solid 1pt #999999;
117  padding-top: 10pt;
118  padding-left: 5pt;
119  text-align: left;
120}
121
122DIV.table TABLE {
123  border: solid thin #999999;
124  border-collapse: collapse;
125  border-spacing: 0;
126  margin-left: auto;
127  margin-right: auto;
128}
129
130DIV.table CAPTION {
131  caption-side: top;
132  font-size: 120%;
133  font-style: italic;
134  font-weight: bold;
135  margin-left: auto;
136  margin-right: auto;
137}
138
139DIV.table TABLE TD {
140  border: solid thin #cccccc;
141  padding: 5pt 10pt 0;
142}
143
144DIV.table TABLE TH {
145  background: #cccccc;
146  border: none;
147  border-bottom: solid thin #999999;
148}
149
150DIV.figure TABLE {
151  margin-left: auto;
152  margin-right: auto;
153}
154
155DIV.figure CAPTION {
156  caption-side: bottom;
157  font-size: 120%;
158  font-style: italic;
159  font-weight: bold;
160  margin-left: auto;
161  margin-right: auto;
162}
163
164TH.label {
165  text-align: right;
166  vertical-align: top;
167}
168
169TH.sublabel {
170  text-align: right;
171  font-weight: normal;
172}
173
174HR {
175  border: solid thin;
176}
177
178SPAN.info {
179  background: black;
180  border: thin solid black;
181  color: white;
182  font-size: 80%;
183  font-style: italic;
184  font-weight: bold;
185  white-space: nowrap;
186}
187
188H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
189  float: right;
190  font-size: 100%;
191}
192
193H1.title {
194}
195
196H2.title, H3.title {
197  border-bottom: solid 2pt #000000;
198}
199
200DIV.indent, TABLE.indent {
201  margin-top: 2em;
202  margin-left: auto;
203  margin-right: auto;
204  width: 90%;
205}
206
207TABLE.indent {
208  border-collapse: collapse;
209}
210
211TABLE.indent TD, TABLE.indent TH {
212  padding: 0;
213}
214
215TABLE.list {
216  border-collapse: collapse;
217  margin-left: auto;
218  margin-right: auto;
219  width: 90%;
220}
221
222TABLE.list TH {
223  background: white;
224  border-bottom: solid thin #cccccc;
225  color: #444444;
226  padding-top: 10pt;
227  padding-left: 5pt;
228  text-align: left;
229  vertical-align: bottom;
230  white-space: nowrap;
231}
232
233TABLE.list TH A {
234  color: #4444cc;
235}
236
237TABLE.list TD {
238  border-bottom: solid thin #eeeeee;
239  padding-top: 5pt;
240  padding-left: 5pt;
241}
242
243TABLE.list TR:nth-child(even) {
244  background: #f8f8f8;
245}
246
247TABLE.list TR:nth-child(odd) {
248  background: #f4f4f4;
249}
250
251DT {
252  margin-left: 36pt;
253  margin-top: 12pt;
254}
255
256DD {
257  margin-left: 54pt;
258}
259
260DL.category DT {
261  font-weight: bold;
262}
263
264P.summary {
265  margin-left: 36pt;
266  font-family: monaco, courier, monospace;
267}
268
269DIV.summary TABLE {
270  border: solid thin #999999;
271  border-collapse: collapse;
272  border-spacing: 0;
273  margin: 10px;
274}
275
276DIV.summary TABLE TD, DIV.summary TABLE TH {
277  border: solid thin #999999;
278  padding: 5px;
279  text-align: left;
280  vertical-align: top;
281}
282
283DIV.summary TABLE THEAD TH {
284  background: #eeeeee;
285}
286
287/* API documentation styles... */
288div.body h1 {
289  font-size: 250%;
290  font-weight: bold;
291  margin: 0;
292}
293div.body h2 {
294  font-size: 250%;
295  margin-top: 1.5em;
296}
297div.body h3 {
298  font-size: 150%;
299  margin-bottom: 0.5em;
300  margin-top: 1.5em;
301}
302div.body h4 {
303  font-size: 110%;
304  margin-bottom: 0.5em;
305  margin-top: 1.5em;
306}
307div.body h5 {
308  font-size: 100%;
309  margin-bottom: 0.5em;
310  margin-top: 1.5em;
311}
312div.contents {
313  background: #e8e8e8;
314  border: solid thin black;
315  padding: 10px;
316}
317div.contents h1 {
318  font-size: 110%;
319}
320div.contents h2 {
321  font-size: 100%;
322}
323div.contents ul.contents {
324  font-size: 80%;
325}
326.class {
327  border-bottom: solid 2px gray;
328}
329.constants {
330}
331.description {
332  margin-top: 0.5em;
333}
334.discussion {
335}
336.enumeration {
337  border-bottom: solid 2px gray;
338}
339.function {
340  border-bottom: solid 2px gray;
341  margin-bottom: 0;
342}
343.members {
344}
345.method {
346}
347.parameters {
348}
349.returnvalue {
350}
351.struct {
352  border-bottom: solid 2px gray;
353}
354.typedef {
355  border-bottom: solid 2px gray;
356}
357.union {
358  border-bottom: solid 2px gray;
359}
360.variable {
361}
362h1, h2, h3, h4, h5, h6 {
363  page-break-inside: avoid;
364}
365blockquote {
366  border: solid thin gray;
367  box-shadow: 3px 3px 5px rgba(0,0,0,0.5);
368  padding: 10px 10px 0px;
369  page-break-inside: avoid;
370}
371p code, li code, p.code, pre, ul.code li {
372  background: rgba(127,127,127,0.1);
373  border: thin dotted gray;
374  font-family: monospace;
375  hyphens: manual;
376  -webkit-hyphens: manual;
377  page-break-inside: avoid;
378}
379p.code, pre, ul.code li {
380  padding: 10px;
381}
382p code, li code {
383  padding: 2px 5px;
384}
385a:link, a:visited {
386  text-decoration: none;
387}
388span.info {
389  background: black;
390  border: solid thin black;
391  color: white;
392  font-size: 80%;
393  font-style: italic;
394  font-weight: bold;
395  white-space: nowrap;
396}
397h2 span.info, h3 span.info, h4 span.info {
398  border-radius: 10px;
399  float: right;
400  font-size: 80%;
401  padding: 3px 6px;
402}
403h2.title span.info, h3.title span.info, h4.title span.info {
404  border-bottom-left-radius: 0px;
405  border-bottom-right-radius: 0px;
406}
407h2.title span.info {
408  padding: 4px 6px;
409}
410ul.code, ul.contents, ul.subcontents {
411  list-style-type: none;
412  margin: 0;
413  padding-left: 0;
414}
415ul.code li {
416  margin: 0;
417}
418ul.contents > li {
419  margin-top: 1em;
420}
421ul.contents li ul.code, ul.contents li ul.subcontents {
422  padding-left: 2em;
423}
424table.list {
425  border-collapse: collapse;
426  width: 100%;
427}
428table.list tr:nth-child(even) {
429  background: rgba(127,127,127,0.1);]n}
430table.list th {
431  border-right: 2px solid gray;
432  font-family: monospace;
433  padding: 5px 10px 5px 2px;
434  text-align: right;
435  vertical-align: top;
436}
437table.list td {
438  padding: 5px 2px 5px 10px;
439  text-align: left;
440  vertical-align: top;
441}
442h1.title {
443}
444h2.title {
445  border-bottom: solid 2px black;
446}
447h3.title {
448  border-bottom: solid 2px black;
449}
450--></style>
451  </head>
452  <body>
453<!--
454  Administrative API header for CUPS.
455
456  Copyright © 2016 by Apple Inc.
457
458  Licensed under Apache License v2.0.  See the file "LICENSE" for more
459  information.
460-->
461
462<h1 class='title'>Administrative APIs</h1>
463
464<div class='summary'><table summary='General Information'>
465<thead>
466<tr>
467	<th>Header</th>
468	<th>cups/adminutil.h</th>
469</tr>
470</thead>
471<tbody>
472<tr>
473	<th>Library</th>
474	<td>-lcups</td>
475</tr>
476<tr>
477	<th>See Also</th>
478	<td>Programming: <a href='api-overview.html' target='_top'>Introduction to CUPS Programming</a><br>
479	Programming: <a href='api-cups.html' target='_top'>CUPS API</a><br>
480	Programming: <a href='api-httpipp.html' target='_top'>HTTP and IPP APIs</a></td>
481</tr>
482</tbody>
483</table></div>
484    <div class="contents">
485      <h2 class="title">Contents</h2>
486      <ul class="contents">
487        <li><a href="#OVERVIEW">Overview</a><ul class="subcontents">
488          <li><a href="#SETTINGS">Scheduler Settings</a></li>
489          <li><a href="#DEVICES">Devices</a></li>
490        </ul></li>
491        <li><a href="#FUNCTIONS">Functions</a><ul class="subcontents">
492          <li><a href="#cupsAdminCreateWindowsPPD">cupsAdminCreateWindowsPPD</a></li>
493          <li><a href="#cupsAdminExportSamba">cupsAdminExportSamba</a></li>
494          <li><a href="#cupsAdminGetServerSettings">cupsAdminGetServerSettings</a></li>
495          <li><a href="#cupsAdminSetServerSettings">cupsAdminSetServerSettings</a></li>
496          <li><a href="#cupsGetDevices">cupsGetDevices</a></li>
497        </ul></li>
498        <li><a href="#TYPES">Data Types</a><ul class="subcontents">
499          <li><a href="#cups_device_cb_t">cups_device_cb_t</a></li>
500        </ul></li>
501      </ul>
502    </div>
503    <div class="body">
504<!--
505  Administrative API documentation for CUPS.
506
507  Copyright © 2016 by Apple Inc.
508
509  Licensed under Apache License v2.0.  See the file "LICENSE" for more
510  information.
511-->
512
513<h2 class="title"><a name="OVERVIEW">Overview</a></h2>
514
515<p>The administrative APIs provide convenience functions to perform certain administrative functions with the CUPS scheduler.</p>
516
517<blockquote><b>Note:</b>
518  <p>Administrative functions normally require administrative privileges to execute and must not be used in ordinary user applications!</p>
519</blockquote>
520
521<h3><a name="SETTINGS">Scheduler Settings</a></h3>
522
523<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>
524
525<ul>
526  <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>
527  <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>
528  <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>
529  <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>
530  <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>
531</ul>
532
533<blockquote><b>Note:</b>
534  <p>Changing settings will restart the CUPS scheduler.</p>
535  <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>
536</blockquote>
537
538<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>
539
540<pre class="example">
541#include &lt;cups/cups.h&gt;
542#include &lt;cups/adminutil.h&gt;
543
544void
545enable_web_interface(void)
546{
547  int num_settings = 0;           /* Number of settings */
548  cups_option_t *settings = NULL; /* Settings */
549
550
551  if (!<a href="#cupsAdminGetServerSettings">cupsAdminGetServerSettings</a>(CUPS_HTTP_DEFAULT, &amp;num_settings, &amp;settings))
552  {
553    fprintf(stderr, "ERROR: Unable to get server settings: %s\n", cupsLastErrorString());
554    return;
555  }
556
557  num_settings = <a href="api-cups.html#cupsAddOption">cupsAddOption</a>("WebInterface", "Yes", num_settings, &amp;settings);
558
559  if (!<a href="#cupsAdminSetServerSettings">cupsAdminSetServerSettings</a>(CUPS_HTTP_DEFAULT, num_settings, settings))
560  {
561    fprintf(stderr, "ERROR: Unable to set server settings: %s\n", cupsLastErrorString());
562  }
563
564  <a href="api-cups.html#cupsFreeOptions">cupsFreeOptions</a>(num_settings, settings);
565}
566</pre>
567
568<h3><a name="DEVICES">Devices</a></h3>
569
570<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>
571
572<pre class="example">
573#include &lt;cups/cups.h&gt;
574#include &lt;cups/adminutil.h&gt;
575
576
577void
578get_devices_cb(
579    const char *device_class,           /* I - Class */
580    const char *device_id,              /* I - 1284 device ID */
581    const char *device_info,            /* I - Description */
582    const char *device_make_and_model,  /* I - Make and model */
583    const char *device_uri,             /* I - Device URI */
584    const char *device_location,        /* I - Location */
585    void       *user_data)              /* I - User data */
586{
587  puts(device_uri);
588}
589
590
591void
592show_devices(void)
593{
594  <a href="#cupsGetDevices">cupsGetDevices</a>(CUPS_HTTP_DEFAULT, 30, NULL, NULL, get_devices_cb, NULL);
595}
596</pre>
597      <h2 class="title"><a id="FUNCTIONS">Functions</a></h2>
598<h3 class="function"><span class="info">&#160;DEPRECATED&#160;</span><a id="cupsAdminCreateWindowsPPD">cupsAdminCreateWindowsPPD</a></h3>
599        <p class="description">Create the Windows PPD file for a printer.</p>
600<p class="code">
601char *cupsAdminCreateWindowsPPD(http_t *http, const char *dest, char *buffer, int bufsize);</p>
602<h4 class="parameters">Parameters</h4>
603<table class="list"><tbody>
604<tr><th>http</th>
605        <td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr>
606<tr><th>dest</th>
607        <td class="description">Printer or class</td></tr>
608<tr><th>buffer</th>
609        <td class="description">Filename buffer</td></tr>
610<tr><th>bufsize</th>
611        <td class="description">Size of filename buffer</td></tr>
612</tbody></table>
613<h4 class="returnvalue">Return Value</h4>
614        <p class="description">PPD file or NULL</p>
615<h3 class="function"><span class="info">&#160;DEPRECATED&#160;</span><a id="cupsAdminExportSamba">cupsAdminExportSamba</a></h3>
616        <p class="description">Export a printer to Samba.</p>
617<p class="code">
618int cupsAdminExportSamba(const char *dest, const char *ppd, const char *samba_server, const char *samba_user, const char *samba_password, FILE *logfile);</p>
619<h4 class="parameters">Parameters</h4>
620<table class="list"><tbody>
621<tr><th>dest</th>
622        <td class="description">Destination to export</td></tr>
623<tr><th>ppd</th>
624        <td class="description">PPD file</td></tr>
625<tr><th>samba_server</th>
626        <td class="description">Samba server</td></tr>
627<tr><th>samba_user</th>
628        <td class="description">Samba username</td></tr>
629<tr><th>samba_password</th>
630        <td class="description">Samba password</td></tr>
631<tr><th>logfile</th>
632        <td class="description">Log file, if any</td></tr>
633</tbody></table>
634<h4 class="returnvalue">Return Value</h4>
635        <p class="description">1 on success, 0 on failure</p>
636<h3 class="function"><span class="info">&#160;CUPS 1.3/macOS 10.5&#160;</span><a id="cupsAdminGetServerSettings">cupsAdminGetServerSettings</a></h3>
637        <p class="description">Get settings from the server.</p>
638<p class="code">
639int cupsAdminGetServerSettings(http_t *http, int *num_settings, cups_option_t **settings);</p>
640<h4 class="parameters">Parameters</h4>
641<table class="list"><tbody>
642<tr><th>http</th>
643        <td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr>
644<tr><th>num_settings</th>
645        <td class="description">Number of settings</td></tr>
646<tr><th>settings</th>
647        <td class="description">Settings</td></tr>
648</tbody></table>
649<h4 class="returnvalue">Return Value</h4>
650        <p class="description">1 on success, 0 on failure</p>
651<h4 class="discussion">Discussion</h4>
652        <p class="discussion">The returned settings should be freed with cupsFreeOptions() when
653you are done with them.
654
655</p>
656<h3 class="function"><span class="info">&#160;CUPS 1.3/macOS 10.5&#160;</span><a id="cupsAdminSetServerSettings">cupsAdminSetServerSettings</a></h3>
657        <p class="description">Set settings on the server.</p>
658<p class="code">
659int cupsAdminSetServerSettings(http_t *http, int num_settings, cups_option_t *settings);</p>
660<h4 class="parameters">Parameters</h4>
661<table class="list"><tbody>
662<tr><th>http</th>
663        <td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr>
664<tr><th>num_settings</th>
665        <td class="description">Number of settings</td></tr>
666<tr><th>settings</th>
667        <td class="description">Settings</td></tr>
668</tbody></table>
669<h4 class="returnvalue">Return Value</h4>
670        <p class="description">1 on success, 0 on failure</p>
671<h3 class="function"><span class="info">&#160;DEPRECATED&#160;</span><a id="cupsGetDevices">cupsGetDevices</a></h3>
672        <p class="description">Get available printer devices.</p>
673<p class="code">
674ipp_status_t cupsGetDevices(http_t *http, int timeout, const char *include_schemes, const char *exclude_schemes, <a href="#cups_device_cb_t">cups_device_cb_t</a> callback, void *user_data);</p>
675<h4 class="parameters">Parameters</h4>
676<table class="list"><tbody>
677<tr><th>http</th>
678        <td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr>
679<tr><th>timeout</th>
680        <td class="description">Timeout in seconds or <code>CUPS_TIMEOUT_DEFAULT</code></td></tr>
681<tr><th>include_schemes</th>
682        <td class="description">Comma-separated URI schemes to include or <code>CUPS_INCLUDE_ALL</code></td></tr>
683<tr><th>exclude_schemes</th>
684        <td class="description">Comma-separated URI schemes to exclude or <code>CUPS_EXCLUDE_NONE</code></td></tr>
685<tr><th>callback</th>
686        <td class="description">Callback function</td></tr>
687<tr><th>user_data</th>
688        <td class="description">User data pointer</td></tr>
689</tbody></table>
690<h4 class="returnvalue">Return Value</h4>
691        <p class="description">Request status - <code>IPP_OK</code> on success.</p>
692<h4 class="discussion">Discussion</h4>
693        <p class="discussion">This function sends a CUPS-Get-Devices request and streams the discovered
694devices to the specified callback function. The &quot;timeout&quot; parameter controls
695how long the request lasts, while the &quot;include_schemes&quot; and &quot;exclude_schemes&quot;
696parameters provide comma-delimited lists of backends to include or omit from
697the request respectively.<br>
698<br>
699This function is deprecated with the IPP printer discovery functionality
700being provided by the <a href="#cupsEnumDests"><code>cupsEnumDests</code></a> and @cupsGetDests@ functions.
701
702</p>
703      <h2 class="title"><a id="TYPES">Data Types</a></h2>
704      <h3 class="typedef"><a id="cups_device_cb_t"><span class="info">&#160;CUPS 1.4/macOS 10.6&#160;</span>cups_device_cb_t</a></h3>
705        <p class="description">Device callback
706</p>
707      <p class="code">
708typedef void (*cups_device_cb_t)(const char *device_class, const char *device_id, const char *device_info, const char *device_make_and_model, const char *device_uri, const char *device_location, void *user_data);
709</p>
710    </div>
711  </body>
712</html>
713