Header | cups/adminutil.h |
---|---|
Library | -lcups |
See Also | Programming: Introduction to CUPS Programming Programming: CUPS API Programming: HTTP and IPP APIs |
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!
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
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
CUPS_SERVER_REMOTE_ANY
CUPS_SERVER_SHARE_PRINTERS
CUPS_SERVER_USER_CANCEL_ANY
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); }
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); }
Create the Windows PPD file for a printer.
char *cupsAdminCreateWindowsPPD(http_t *http, const char *dest, char *buffer, int bufsize);
http | Connection to server or CUPS_HTTP_DEFAULT |
---|---|
dest | Printer or class |
buffer | Filename buffer |
bufsize | Size of filename buffer |
PPD file or NULL
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);
dest | Destination to export |
---|---|
ppd | PPD file |
samba_server | Samba server |
samba_user | Samba username |
samba_password | Samba password |
logfile | Log file, if any |
1 on success, 0 on failure
Get settings from the server.
int cupsAdminGetServerSettings(http_t *http, int *num_settings, cups_option_t **settings);
http | Connection to server or CUPS_HTTP_DEFAULT |
---|---|
num_settings | Number of settings |
settings | Settings |
1 on success, 0 on failure
The returned settings should be freed with cupsFreeOptions() when you are done with them.
Set settings on the server.
int cupsAdminSetServerSettings(http_t *http, int num_settings, cups_option_t *settings);
http | Connection to server or CUPS_HTTP_DEFAULT |
---|---|
num_settings | Number of settings |
settings | Settings |
1 on success, 0 on failure
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);
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 |
Request status - IPP_OK
on success.
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.
This function is deprecated with the IPP printer discovery functionality
being provided by the cupsEnumDests
and @cupsGetDests@ functions.
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);