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:

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