Administrative APIs

Header cups/adminutil.h
Library -lcups
See Also Programming: Introduction to CUPS Programming
Programming: CUPS API
Programming: HTTP and IPP APIs

Contents

Overview

The administrative APIs provide convenience functions to perform certain administrative functions with the CUPS scheduler.

Note:

Administrative functions normally require administrative privileges to execute and must not be used in ordinary user applications!

Scheduler Settings

The cupsAdminGetServerSettings and cupsAdminSetServerSettings functions allow you to get and set simple directives and their values, respectively, in the cupsd.conf 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 cupsd.conf directive name can be specified, the following convenience names are also defined to control common complex directives:

  • CUPS_SERVER_DEBUG_LOGGING
  • : For cupsAdminGetServerSettings, a value of "1" means that the LogLevel directive is set to debug or debug2 while a value of "0" means it is set to any other value. For cupsAdminSetServerSettings a value of "1" sets the LogLeveL to debug while a value of "0" sets it to warn.
  • CUPS_SERVER_REMOTE_ADMIN
  • : 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).
  • CUPS_SERVER_REMOTE_ANY
  • : 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).
  • CUPS_SERVER_SHARE_PRINTERS
  • : 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.
  • CUPS_SERVER_USER_CANCEL_ANY
  • : 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.
Note:

Changing settings will restart the CUPS scheduler.

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.

The recommended way to make changes to the cupsd.conf is to first call cupsAdminGetServerSettings, make any changes to the returned option array, and then call cupsAdminSetServerSettings to save those settings. For example, to enable the web interface:

#include <cups/cups.h>
#include <cups/adminutil.h>

void
enable_web_interface(void)
{
  int num_settings = 0;           /* Number of settings */
  cups_option_t *settings = NULL; /* Settings */


  if (!cupsAdminGetServerSettings(CUPS_HTTP_DEFAULT, &num_settings, &settings))
  {
    fprintf(stderr, "ERROR: Unable to get server settings: %s\n", cupsLastErrorString());
    return;
  }

  num_settings = cupsAddOption("WebInterface", "Yes", num_settings, &settings);

  if (!cupsAdminSetServerSettings(CUPS_HTTP_DEFAULT, num_settings, settings))
  {
    fprintf(stderr, "ERROR: Unable to set server settings: %s\n", cupsLastErrorString());
  }

  cupsFreeOptions(num_settings, settings);
}

Devices

Printers can be discovered through the CUPS scheduler using the cupsGetDevices 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:

#include <cups/cups.h>
#include <cups/adminutil.h>


void
get_devices_cb(
    const char *device_class,           /* I - Class */
    const char *device_id,              /* I - 1284 device ID */
    const char *device_info,            /* I - Description */
    const char *device_make_and_model,  /* I - Make and model */
    const char *device_uri,             /* I - Device URI */
    const char *device_location,        /* I - Location */
    void       *user_data)              /* I - User data */
{
  puts(device_uri);
}


void
show_devices(void)
{
  cupsGetDevices(CUPS_HTTP_DEFAULT, 30, NULL, NULL, get_devices_cb, NULL);
}

Functions

 DEPRECATED cupsAdminCreateWindowsPPD

Create the Windows PPD file for a printer.

char *cupsAdminCreateWindowsPPD (
    http_t *http,
    const char *dest,
    char *buffer,
    int bufsize
);

Parameters

http
Connection to server or CUPS_HTTP_DEFAULT
dest
Printer or class
buffer
Filename buffer
bufsize
Size of filename buffer

Return Value

PPD file or NULL

 DEPRECATED cupsAdminExportSamba

Export a printer to Samba.

int cupsAdminExportSamba (
    const char *dest,
    const char *ppd,
    const char *samba_server,
    const char *samba_user,
    const char *samba_password,
    FILE *logfile
);

Parameters

dest
Destination to export
ppd
PPD file
samba_server
Samba server
samba_user
Samba username
samba_password
Samba password
logfile
Log file, if any

Return Value

1 on success, 0 on failure

 CUPS 1.3/OS X 10.5 cupsAdminGetServerSettings

Get settings from the server.

int cupsAdminGetServerSettings (
    http_t *http,
    int *num_settings,
    cups_option_t **settings
);

Parameters

http
Connection to server or CUPS_HTTP_DEFAULT
num_settings
Number of settings
settings
Settings

Return Value

1 on success, 0 on failure

Discussion

The returned settings should be freed with cupsFreeOptions() when you are done with them.

 CUPS 1.3/OS X 10.5 cupsAdminSetServerSettings

Set settings on the server.

int cupsAdminSetServerSettings (
    http_t *http,
    int num_settings,
    cups_option_t *settings
);

Parameters

http
Connection to server or CUPS_HTTP_DEFAULT
num_settings
Number of settings
settings
Settings

Return Value

1 on success, 0 on failure

 CUPS 1.4/OS X 10.6 cupsGetDevices

Get available printer devices.

ipp_status_t cupsGetDevices (
    http_t *http,
    int timeout,
    const char *include_schemes,
    const char *exclude_schemes,
    cups_device_cb_t callback,
    void *user_data
);

Parameters

http
Connection to server or CUPS_HTTP_DEFAULT
timeout
Timeout in seconds or CUPS_TIMEOUT_DEFAULT
include_schemes
Comma-separated URI schemes to include or CUPS_INCLUDE_ALL
exclude_schemes
Comma-separated URI schemes to exclude or CUPS_EXCLUDE_NONE
callback
Callback function
user_data
User data pointer

Return Value

Request status - IPP_OK on success.

Discussion

This function sends a CUPS-Get-Devices request and streams the discovered devices to the specified callback function. The "timeout" parameter controls how long the request lasts, while the "include_schemes" and "exclude_schemes" parameters provide comma-delimited lists of backends to include or omit from the request respectively.

Data Types

 CUPS 1.4/OS X 10.6 cups_device_cb_t

Device callback

typedef 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);