1<!DOCTYPE html> 2<html lang="en-US"> 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="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 Administrative API header for CUPS. 251 252 Copyright © 2020-2024 by OpenPrinting. 253 Copyright © 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'>Administrative APIs</h1> 260 261<div class='summary'><table summary='General Information'> 262<thead> 263<tr> 264 <th>Header</th> 265 <th>cups/adminutil.h</th> 266</tr> 267</thead> 268<tbody> 269<tr> 270 <th>Library</th> 271 <td>-lcups</td> 272</tr> 273<tr> 274 <th>See Also</th> 275 <td>Programming: <a href='api-overview.html' target='_top'>Introduction to CUPS Programming</a><br> 276 Programming: <a href='api-cups.html' target='_top'>CUPS API</a><br> 277 Programming: <a href='api-httpipp.html' target='_top'>HTTP and IPP APIs</a></td> 278</tr> 279</tbody> 280</table></div> 281</div> 282<div class="contents"> 283<h2 class="title">Contents</h2> 284<ul class="contents"> 285<li><a href="#OVERVIEW">Overview</a><ul class="subcontents"> 286<li><a href="#SETTINGS">Scheduler Settings</a></li> 287<li><a href="#DEVICES">Devices</a></li> 288</ul></li> 289<li><a href="#FUNCTIONS">Functions</a><ul class="subcontents"> 290<li><a href="#cupsAdminCreateWindowsPPD">cupsAdminCreateWindowsPPD</a></li> 291<li><a href="#cupsAdminExportSamba">cupsAdminExportSamba</a></li> 292<li><a href="#cupsAdminGetServerSettings">cupsAdminGetServerSettings</a></li> 293<li><a href="#cupsAdminSetServerSettings">cupsAdminSetServerSettings</a></li> 294<li><a href="#cupsGetDevices">cupsGetDevices</a></li> 295</ul></li> 296<li><a href="#TYPES">Data Types</a><ul class="subcontents"> 297<li><a href="#cups_device_cb_t">cups_device_cb_t</a></li> 298</ul></li> 299</ul> 300</div> 301<div class="body"> 302<!-- 303 Administrative API documentation for CUPS. 304 305 Copyright © 2016 by Apple Inc. 306 307 Licensed under Apache License v2.0. See the file "LICENSE" for more 308 information. 309--> 310 311<h2 class="title"><a name="OVERVIEW">Overview</a></h2> 312 313<p>The administrative APIs provide convenience functions to perform certain administrative functions with the CUPS scheduler.</p> 314 315<blockquote><b>Note:</b> 316 <p>Administrative functions normally require administrative privileges to execute and must not be used in ordinary user applications!</p> 317</blockquote> 318 319<h3><a name="SETTINGS">Scheduler Settings</a></h3> 320 321<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> 322 323<ul> 324 <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> 325 <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> 326 <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> 327 <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> 328 <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> 329</ul> 330 331<blockquote><b>Note:</b> 332 <p>Changing settings will restart the CUPS scheduler.</p> 333 <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> 334</blockquote> 335 336<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> 337 338<pre class="example"> 339#include <cups/cups.h> 340#include <cups/adminutil.h> 341 342void 343enable_web_interface(void) 344{ 345 int num_settings = 0; /* Number of settings */ 346 cups_option_t *settings = NULL; /* Settings */ 347 348 349 if (!<a href="#cupsAdminGetServerSettings">cupsAdminGetServerSettings</a>(CUPS_HTTP_DEFAULT, &num_settings, &settings)) 350 { 351 fprintf(stderr, "ERROR: Unable to get server settings: %s\n", cupsLastErrorString()); 352 return; 353 } 354 355 num_settings = <a href="api-cups.html#cupsAddOption">cupsAddOption</a>("WebInterface", "Yes", num_settings, &settings); 356 357 if (!<a href="#cupsAdminSetServerSettings">cupsAdminSetServerSettings</a>(CUPS_HTTP_DEFAULT, num_settings, settings)) 358 { 359 fprintf(stderr, "ERROR: Unable to set server settings: %s\n", cupsLastErrorString()); 360 } 361 362 <a href="api-cups.html#cupsFreeOptions">cupsFreeOptions</a>(num_settings, settings); 363} 364</pre> 365 366<h3><a name="DEVICES">Devices</a></h3> 367 368<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 to 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> 369 370<pre class="example"> 371#include <cups/cups.h> 372#include <cups/adminutil.h> 373 374 375void 376get_devices_cb( 377 const char *device_class, /* I - Class */ 378 const char *device_id, /* I - 1284 device ID */ 379 const char *device_info, /* I - Description */ 380 const char *device_make_and_model, /* I - Make and model */ 381 const char *device_uri, /* I - Device URI */ 382 const char *device_location, /* I - Location */ 383 void *user_data) /* I - User data */ 384{ 385 puts(device_uri); 386} 387 388 389void 390show_devices(void) 391{ 392 <a href="#cupsGetDevices">cupsGetDevices</a>(CUPS_HTTP_DEFAULT, 30, NULL, NULL, get_devices_cb, NULL); 393} 394</pre> 395<h2 class="title"><a id="FUNCTIONS">Functions</a></h2> 396<h3 class="function"><span class="info"> DEPRECATED </span><a id="cupsAdminCreateWindowsPPD">cupsAdminCreateWindowsPPD</a></h3> 397<p class="description">Create the Windows PPD file for a printer.</p> 398<p class="code"> 399char *cupsAdminCreateWindowsPPD(http_t *http, const char *dest, char *buffer, int bufsize);</p> 400<h4 class="parameters">Parameters</h4> 401<table class="list"><tbody> 402<tr><th>http</th> 403<td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr> 404<tr><th>dest</th> 405<td class="description">Printer or class</td></tr> 406<tr><th>buffer</th> 407<td class="description">Filename buffer</td></tr> 408<tr><th>bufsize</th> 409<td class="description">Size of filename buffer</td></tr> 410</tbody></table> 411<h4 class="returnvalue">Return Value</h4> 412<p class="description">PPD file or NULL</p> 413<h3 class="function"><span class="info"> DEPRECATED </span><a id="cupsAdminExportSamba">cupsAdminExportSamba</a></h3> 414<p class="description">Export a printer to Samba.</p> 415<p class="code"> 416int cupsAdminExportSamba(const char *dest, const char *ppd, const char *samba_server, const char *samba_user, const char *samba_password, FILE *logfile);</p> 417<h4 class="parameters">Parameters</h4> 418<table class="list"><tbody> 419<tr><th>dest</th> 420<td class="description">Destination to export</td></tr> 421<tr><th>ppd</th> 422<td class="description">PPD file</td></tr> 423<tr><th>samba_server</th> 424<td class="description">Samba server</td></tr> 425<tr><th>samba_user</th> 426<td class="description">Samba username</td></tr> 427<tr><th>samba_password</th> 428<td class="description">Samba password</td></tr> 429<tr><th>logfile</th> 430<td class="description">Log file, if any</td></tr> 431</tbody></table> 432<h4 class="returnvalue">Return Value</h4> 433<p class="description">1 on success, 0 on failure</p> 434<h3 class="function"><span class="info"> CUPS 1.3/macOS 10.5 </span><a id="cupsAdminGetServerSettings">cupsAdminGetServerSettings</a></h3> 435<p class="description">Get settings from the server.</p> 436<p class="code"> 437int cupsAdminGetServerSettings(http_t *http, int *num_settings, cups_option_t **settings);</p> 438<h4 class="parameters">Parameters</h4> 439<table class="list"><tbody> 440<tr><th>http</th> 441<td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr> 442<tr><th>num_settings</th> 443<td class="description">Number of settings</td></tr> 444<tr><th>settings</th> 445<td class="description">Settings</td></tr> 446</tbody></table> 447<h4 class="returnvalue">Return Value</h4> 448<p class="description">1 on success, 0 on failure</p> 449<h4 class="discussion">Discussion</h4> 450<p class="discussion">The returned settings should be freed with cupsFreeOptions() when 451you are done with them. 452 453</p> 454<h3 class="function"><span class="info"> CUPS 1.3/macOS 10.5 </span><a id="cupsAdminSetServerSettings">cupsAdminSetServerSettings</a></h3> 455<p class="description">Set settings on the server.</p> 456<p class="code"> 457int cupsAdminSetServerSettings(http_t *http, int num_settings, cups_option_t *settings);</p> 458<h4 class="parameters">Parameters</h4> 459<table class="list"><tbody> 460<tr><th>http</th> 461<td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr> 462<tr><th>num_settings</th> 463<td class="description">Number of settings</td></tr> 464<tr><th>settings</th> 465<td class="description">Settings</td></tr> 466</tbody></table> 467<h4 class="returnvalue">Return Value</h4> 468<p class="description">1 on success, 0 on failure</p> 469<h3 class="function"><span class="info"> DEPRECATED </span><a id="cupsGetDevices">cupsGetDevices</a></h3> 470<p class="description">Get available printer devices.</p> 471<p class="code"> 472ipp_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> 473<h4 class="parameters">Parameters</h4> 474<table class="list"><tbody> 475<tr><th>http</th> 476<td class="description">Connection to server or <code>CUPS_HTTP_DEFAULT</code></td></tr> 477<tr><th>timeout</th> 478<td class="description">Timeout in seconds or <code>CUPS_TIMEOUT_DEFAULT</code></td></tr> 479<tr><th>include_schemes</th> 480<td class="description">Comma-separated URI schemes to include or <code>CUPS_INCLUDE_ALL</code></td></tr> 481<tr><th>exclude_schemes</th> 482<td class="description">Comma-separated URI schemes to exclude or <code>CUPS_EXCLUDE_NONE</code></td></tr> 483<tr><th>callback</th> 484<td class="description">Callback function</td></tr> 485<tr><th>user_data</th> 486<td class="description">User data pointer</td></tr> 487</tbody></table> 488<h4 class="returnvalue">Return Value</h4> 489<p class="description">Request status - <code>IPP_OK</code> on success.</p> 490<h4 class="discussion">Discussion</h4> 491<p class="discussion">This function sends a CUPS-Get-Devices request and streams the discovered 492devices to the specified callback function. The "timeout" parameter controls 493how long the request lasts, while the "include_schemes" and "exclude_schemes" 494parameters provide comma-delimited lists of backends to include or omit from 495the request respectively.<br> 496<br> 497This function is deprecated with the IPP printer discovery functionality 498being provided by the <a href="#cupsEnumDests"><code>cupsEnumDests</code></a> and @cupsGetDests@ functions. 499 500</p> 501<h2 class="title"><a id="TYPES">Data Types</a></h2> 502<h3 class="typedef"><a id="cups_device_cb_t"><span class="info"> CUPS 1.4/macOS 10.6 </span>cups_device_cb_t</a></h3> 503<p class="description">Device callback 504</p> 505<p class="code"> 506typedef 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); 507</p> 508</div> 509</body> 510</html> 511