Software: Apache/2.2.16 (Debian). PHP/5.3.3-7+squeeze19 uname -a: Linux mail.tri-specialutilitydistrict.com 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/cups/doc-root/help/ drwxr-xr-x |
Viewing file: Select action/file-type: CUPS API
Contents
OverviewThe CUPS API provides the convenience functions needed to support applications, filters, printer drivers, and backends that need to interface with the CUPS scheduler. Clients and ServersCUPS is based on the Internet Printing Protocol ("IPP"), which allows
clients (applications) to communicate with a server (the scheduler) to get a
list of printers, send print jobs, and so forth. You identify which server
you want to communicate with using a pointer to the opaque structure
Printers and ClassesPrinters and classes (collections of printers) are accessed through
the #include <cups/cups.h> cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests); /* do something wiith dest */ cupsFreeDests(num_dests, dests); Passing
OptionsOptions are stored in arrays of
#include <cups/cups.h> cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest; int i; const char *value; for (i = num_dests, dest = dests; i > 0; i --, dest ++) if (dest->instance == NULL) { value = cupsGetOption("printer-info", dest->num_options, dest->options); printf("%s (%s)\n", dest->name, value ? value : "no description"); } cupsFreeDests(num_dests, dests); You can create your own option arrays using the
#include <cups/cups.h> int num_options = 0; cups_option_t *options = NULL; /* The returned num_options value is updated as needed */ num_options = cupsAddOption("first", "value", num_options, &options); /* This adds a second option value */ num_options = cupsAddOption("second", "value", num_options, &options); /* This replaces the first option we added */ num_options = cupsAddOption("first", "new value", num_options, &options); Use a #include <cups/cups.h> int i; int num_options = 0; cups_option_t *options = NULL; cups_dest_t *dest; for (i = 0; i < dest->num_options; i ++) num_options = cupsAddOption(dest->options[i].name, dest->options[i].value, num_options, &options); Use the cupsFreeOptions(num_options, options); Print JobsPrint jobs are identified by a locally-unique job ID number from 1 to
231-1 and have options and one or more files for printing to a
single destination. The #include <cups/cups.h> cups_dest_t *dest; int num_options; cups_option_t *options; int job_id; /* Print a single file */ job_id = cupsPrintFile(dest->name, "/usr/share/cups/data/testprint.ps", "Test Print", num_options, options); The #include <cups/cups.h> cups_dest_t *dest; int num_options; cups_option_t *options; int job_id; char *files[3] = { "file1.pdf", "file2.pdf", "file3.pdf" }; /* Print three files */ job_id = cupsPrintFiles(dest->name, 3, files, "Test Print", num_options, options); Finally, the #include <cups/cups.h> cups_dest_t *dest; int num_options; cups_option_t *options; int job_id; int i; char buffer[1024]; /* Create the job */ job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, dest->name, "10 Text Files", num_options, options); /* If the job is created, add 10 files */ if (job_id > 0) { for (i = 1; i <= 10; i ++) { snprintf(buffer, sizeof(buffer), "file%d.txt", i); cupsStartDocument(CUPS_HTTP_DEFAULT, dest->name, job_id, buffer, CUPS_FORMAT_TEXT, i == 10); snprintf(buffer, sizeof(buffer), "File %d\n" "\n" "One fish,\n" "Two fish,\n "Red fish,\n "Blue fish\n", i); /* cupsWriteRequestData can be called as many times as needed */ cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, strlen(buffer)); cupsFinishDocument(CUPS_HTTP_DEFAULT, dest->name); } } Once you have created a job, you can monitor its status using the
#include <cups/cups.h> cups_dest_t *dest; int job_id; int num_jobs; cups_job_t *jobs; int i; ipp_jstate_t job_state = IPP_JOB_PENDING; while (job_state < IPP_JOB_STOPPED) { /* Get my jobs (1) with any state (-1) */ num_jobs = cupsGetJobs(&jobs, dest->name, 1, -1); /* Loop to find my job */ job_state = IPP_JOB_COMPLETED; for (i = 0; i < num_jobs; i ++) if (jobs[i].id == job_id) { job_state = jobs[i].state; break; } /* Free the job array */ cupsFreeJobs(num_jobs, jobs); /* Show the current state */ switch (job_state) { case IPP_JOB_PENDING : printf("Job %d is pending.\n", job_id); break; case IPP_JOB_HELD : printf("Job %d is held.\n", job_id); break; case IPP_JOB_PROCESSING : printf("Job %d is processing.\n", job_id); break; case IPP_JOB_STOPPED : printf("Job %d is stopped.\n", job_id); break; case IPP_JOB_CANCELED : printf("Job %d is canceled.\n", job_id); break; case IPP_JOB_ABORTED : printf("Job %d is aborted.\n", job_id); break; case IPP_JOB_COMPLETED : printf("Job %d is completed.\n", job_id); break; } /* Sleep if the job is not finished */ if (job_state < IPP_JOB_STOPPED) sleep(5); } To cancel a job, use the
#include <cups/cups.h> cups_dest_t *dest; int job_id; cupsCancelJob(dest->name, job_id); Error HandlingIf any of the CUPS API printing functions returns an error, the reason for
that error can be found by calling the
#include <cups/cups.h> int job_id; if (job_id == 0) puts(cupsLastErrorString()); Passwords and AuthenticationCUPS supports authentication of any request, including submission of print jobs. The default mechanism for getting the username and password is to use the login user and a password from the console. To support other types of applications, in particular Graphical User Interfaces ("GUIs"), the CUPS API provides functions to set the default username and to register a callback function that returns a password string. The The The following example shows a simple password callback that gets a username and password from the user: #include <cups/cups.h> const char * my_password_cb(const char *prompt) { char user[65]; puts(prompt); /* Get a username from the user */ printf("Username: "); if (fgets(user, sizeof(user), stdin) == NULL) return (NULL); /* Strip the newline from the string and set the user */ user[strlen(user) - 1] = '\0'; cupsSetUser(user); /* Use getpass() to ask for the password... */ return (getpass("Password: ")); } cupsSetPasswordCB(my_password_cb); Similarly, a GUI could display the prompt string in a window with input
fields for the username and password. The username should default to the
string returned by the FunctionscupsAddDestAdd a destination to the list of destinations.
int cupsAddDest ( Parameters
Return ValueNew number of destinations DiscussionThis function cannot be used to add a new class or printer queue,
it only adds a new container of saved options for the named
destination or instance. cupsAddOptionAdd an option to an option array.
int cupsAddOption ( Parameters
Return ValueNumber of options DiscussionNew option arrays can be initialized simply by passing 0 for the "num_options" parameter. CUPS 1.2/Mac OS X 10.5 cupsAdminCreateWindowsPPDCreate the Windows PPD file for a printer.
char *cupsAdminCreateWindowsPPD ( Parameters
Return ValuePPD file or NULL CUPS 1.2/Mac OS X 10.5 cupsAdminExportSambaExport a printer to Samba.
int cupsAdminExportSamba ( Parameters
Return Value1 on success, 0 on failure CUPS 1.3/Mac OS X 10.5 cupsAdminGetServerSettingsGet settings from the server.
int cupsAdminGetServerSettings ( Parameters
Return Value1 on success, 0 on failure DiscussionThe returned settings should be freed with cupsFreeOptions() when you are done with them. CUPS 1.3/Mac OS X 10.5 cupsAdminSetServerSettingsSet settings on the server.
int cupsAdminSetServerSettings ( Parameters
Return Value1 on success, 0 on failure cupsCancelJobCancel a print job on the default server.
int cupsCancelJob ( Parameters
Return Value1 on success, 0 on failure DiscussionPass CUPS 1.4/Mac OS X 10.6 cupsCancelJob2Cancel or purge a print job.
ipp_status_t cupsCancelJob2 ( Parameters
Return ValueIPP status DiscussionCanceled jobs remain in the job history while purged jobs are removed
from the job history. CUPS 1.4/Mac OS X 10.6 cupsCreateJobCreate an empty job for streaming.
int cupsCreateJob ( Parameters
Return ValueJob ID or 0 on error DiscussionUse this function when you want to stream print data using the
cupsEncryptionGet the current encryption settings. http_encryption_t cupsEncryption (void); Return ValueEncryption settings DiscussionThe default encryption setting comes from the CUPS_ENCRYPTION
environment variable, then the ~/.cups/client.conf file, and finally the
/etc/cups/client.conf file. If not set, the default is
CUPS 1.4/Mac OS X 10.6 cupsFinishDocumentFinish sending a document.
ipp_status_t cupsFinishDocument ( Parameters
Return ValueStatus of document submission DiscussionThe document must have been started using cupsFreeDestsFree the memory used by the list of destinations.
void cupsFreeDests ( Parameters
cupsFreeJobsFree memory used by job data.
void cupsFreeJobs ( Parameters
cupsFreeOptionsFree all memory used by options.
void cupsFreeOptions ( Parameters
DEPRECATED cupsGetClassesGet a list of printer classes from the default server.
int cupsGetClasses ( Parameters
Return ValueNumber of classes DiscussionThis function is deprecated - use cupsGetDefaultGet the default printer or class for the default server. const char *cupsGetDefault (void); Return ValueDefault printer or DiscussionThis function returns the default printer or class as defined by
the LPDEST or PRINTER environment variables. If these environment
variables are not set, the server default destination is returned.
Applications should use the CUPS 1.1.21/Mac OS X 10.4 cupsGetDefault2Get the default printer or class for the specified server.
const char *cupsGetDefault2 ( Parameters
Return ValueDefault printer or DiscussionThis function returns the default printer or class as defined by
the LPDEST or PRINTER environment variables. If these environment
variables are not set, the server default destination is returned.
Applications should use the cupsGetDestGet the named destination from the list.
cups_dest_t *cupsGetDest ( Parameters
Return ValueDestination pointer or DiscussionUse the cupsGetDestsGet the list of destinations from the default server.
int cupsGetDests ( Parameters
Return ValueNumber of destinations DiscussionStarting with CUPS 1.2, the returned list of destinations include the
printer-info, printer-is-accepting-jobs, printer-is-shared,
printer-make-and-model, printer-state, printer-state-change-time,
printer-state-reasons, and printer-type attributes as options. CUPS 1.4
adds the marker-change-time, marker-colors, marker-high-levels,
marker-levels, marker-low-levels, marker-message, marker-names,
marker-types, and printer-commands attributes as well. CUPS 1.1.21/Mac OS X 10.4 cupsGetDests2Get the list of destinations from the specified server.
int cupsGetDests2 ( Parameters
Return ValueNumber of destinations DiscussionStarting with CUPS 1.2, the returned list of destinations include the
printer-info, printer-is-accepting-jobs, printer-is-shared,
printer-make-and-model, printer-state, printer-state-change-time,
printer-state-reasons, and printer-type attributes as options. CUPS 1.4
adds the marker-change-time, marker-colors, marker-high-levels,
marker-levels, marker-low-levels, marker-message, marker-names,
marker-types, and printer-commands attributes as well. cupsGetJobsGet the jobs from the default server.
int cupsGetJobs ( Parameters
Return ValueNumber of jobs DiscussionA "whichjobs" value of CUPS 1.1.21/Mac OS X 10.4 cupsGetJobs2Get the jobs from the specified server.
int cupsGetJobs2 ( Parameters
Return ValueNumber of jobs DiscussionA "whichjobs" value of CUPS 1.4/Mac OS X 10.6 cupsGetNamedDestGet options for the named destination.
cups_dest_t *cupsGetNamedDest ( Parameters
Return ValueDestination or DiscussionThis function is optimized for retrieving a single destination and should
be used instead of cupsGetOptionGet an option value.
const char *cupsGetOption ( Parameters
Return ValueOption value or cupsGetPPDGet the PPD file for a printer on the default server.
const char *cupsGetPPD ( Parameters
Return ValueFilename for PPD file DiscussionFor classes, CUPS 1.1.21/Mac OS X 10.4 cupsGetPPD2Get the PPD file for a printer from the specified server.
const char *cupsGetPPD2 ( Parameters
Return ValueFilename for PPD file DiscussionFor classes, CUPS 1.4/Mac OS X 10.6 cupsGetPPD3Get the PPD file for a printer on the specified server if it has changed.
http_status_t cupsGetPPD3 ( Parameters
Return ValueHTTP status DiscussionThe "modtime" parameter contains the modification time of any
locally-cached content and is updated with the time from the PPD file on
the server. cupsGetPasswordGet a password from the user.
const char *cupsGetPassword ( Parameters
Return ValuePassword DiscussionUses the current password callback function. Returns CUPS 1.4/Mac OS X 10.6 cupsGetPassword2Get a password from the user using the advanced password callback.
const char *cupsGetPassword2 ( Parameters
Return ValuePassword DiscussionUses the current password callback function. Returns DEPRECATED cupsGetPrintersGet a list of printers from the default server.
int cupsGetPrinters ( Parameters
Return ValueNumber of printers DiscussionThis function is deprecated - use CUPS 1.3/Mac OS X 10.5 cupsGetServerPPDGet an available PPD file from the server.
char *cupsGetServerPPD ( Parameters
Return ValueName of PPD file or DiscussionThis function returns the named PPD file from the server. The
list of available PPDs is provided by the IPP cupsLangDefaultReturn the default language. cups_lang_t *cupsLangDefault (void); Return ValueLanguage data cupsLangEncodingReturn the character encoding (us-ascii, etc.) for the given language.
const char *cupsLangEncoding ( Parameters
Return ValueCharacter encoding cupsLangFlushFlush all language data out of the cache. void cupsLangFlush (void); cupsLangFreeFree language data.
void cupsLangFree ( Parameters
DiscussionThis does not actually free anything; use cupsLangGetGet a language.
cups_lang_t *cupsLangGet ( Parameters
Return ValueLanguage data cupsLastErrorReturn the last IPP status code. ipp_status_t cupsLastError (void); Return ValueIPP status code from last request CUPS 1.2/Mac OS X 10.5 cupsLastErrorStringReturn the last IPP status-message. const char *cupsLastErrorString (void); Return Valuestatus-message text from last request CUPS 1.2/Mac OS X 10.5 cupsNotifySubjectReturn the subject for the given notification message.
char *cupsNotifySubject ( Parameters
Return ValueSubject string or DiscussionThe returned string must be freed by the caller using CUPS 1.2/Mac OS X 10.5 cupsNotifyTextReturn the text for the given notification message.
char *cupsNotifyText ( Parameters
Return ValueMessage text or DiscussionThe returned string must be freed by the caller using cupsParseOptionsParse options from a command-line argument.
int cupsParseOptions ( Parameters
Return ValueNumber of options found DiscussionThis function converts space-delimited name/value pairs according
to the PAPI text option ABNF specification. Collection values
("name={a=... b=... c=...}") are stored with the curley brackets
intact - use cupsPrintFilePrint a file to a printer or class on the default server.
int cupsPrintFile ( Parameters
Return ValueJob ID or 0 on error CUPS 1.1.21/Mac OS X 10.4 cupsPrintFile2Print a file to a printer or class on the specified server.
int cupsPrintFile2 ( Parameters
Return ValueJob ID or 0 on error cupsPrintFilesPrint one or more files to a printer or class on the default server.
int cupsPrintFiles ( Parameters
Return ValueJob ID or 0 on error CUPS 1.1.21/Mac OS X 10.4 cupsPrintFiles2Print one or more files to a printer or class on the specified server.
int cupsPrintFiles2 ( Parameters
Return ValueJob ID or 0 on error CUPS 1.3/Mac OS X 10.5 cupsRemoveDestRemove a destination from the destination list.
int cupsRemoveDest ( Parameters
Return ValueNew number of destinations DiscussionRemoving a destination/instance does not delete the class or printer
queue, merely the lpoptions for that destination/instance. Use the
CUPS 1.2/Mac OS X 10.5 cupsRemoveOptionRemove an option from an option array.
int cupsRemoveOption ( Parameters
Return ValueNew number of options cupsServerReturn the hostname/address of the current server. const char *cupsServer (void); Return ValueServer name DiscussionThe default server comes from the CUPS_SERVER environment variable, then the
~/.cups/client.conf file, and finally the /etc/cups/client.conf file. If not
set, the default is the local system - either "localhost" or a domain socket
path. CUPS 1.3/Mac OS X 10.5 cupsSetDefaultDestSet the default destination.
void cupsSetDefaultDest ( Parameters
cupsSetDestsSave the list of destinations for the default server.
void cupsSetDests ( Parameters
DiscussionThis function saves the destinations to /etc/cups/lpoptions when run as root and ~/.cups/lpoptions when run as a normal user. CUPS 1.1.21/Mac OS X 10.4 cupsSetDests2Save the list of destinations for the specified server.
int cupsSetDests2 ( Parameters
Return Value0 on success, -1 on error DiscussionThis function saves the destinations to /etc/cups/lpoptions when run as root and ~/.cups/lpoptions when run as a normal user. cupsSetEncryptionSet the encryption preference.
void cupsSetEncryption ( Parameters
DiscussionThe default encryption setting comes from the CUPS_ENCRYPTION
environment variable, then the ~/.cups/client.conf file, and finally the
/etc/cups/client.conf file. If not set, the default is
cupsSetPasswordCBSet the password callback for CUPS.
void cupsSetPasswordCB ( Parameters
DiscussionPass CUPS 1.4/Mac OS X 10.6 cupsSetPasswordCB2Set the advanced password callback for CUPS.
void cupsSetPasswordCB2 ( Parameters
DiscussionPass cupsSetServerSet the default server name and port.
void cupsSetServer ( Parameters
DiscussionThe "server" string can be a fully-qualified hostname, a numeric
IPv4 or IPv6 address, or a domain socket pathname. Hostnames and numeric IP
addresses can be optionally followed by a colon and port number to override
the default port 631, e.g. "hostname:8631". Pass cupsSetUserSet the default user name.
void cupsSetUser ( Parameters
DiscussionPass CUPS 1.4/Mac OS X 10.6 cupsStartDocumentAdd a document to a job created with cupsCreateJob().
http_status_t cupsStartDocument ( Parameters
Return ValueHTTP status of request DiscussionUse cupsTempFdCreates a temporary file.
int cupsTempFd ( Parameters
Return ValueNew file descriptor or -1 on error DiscussionThe temporary filename is returned in the filename buffer. The temporary file is opened for reading and writing. DEPRECATED cupsTempFileGenerates a temporary filename.
char *cupsTempFile ( Parameters
Return ValueFilename or DiscussionThe temporary filename is returned in the filename buffer.
This function is deprecated - use CUPS 1.2/Mac OS X 10.5 cupsTempFile2Creates a temporary CUPS file.
cups_file_t *cupsTempFile2 ( Parameters
Return ValueCUPS file or DiscussionThe temporary filename is returned in the filename buffer. The temporary file is opened for writing. cupsUserReturn the current user's name. const char *cupsUser (void); Return ValueUser name DiscussionNote: The current user name is tracked separately for each thread in a
program. Multi-threaded programs that override the user name with the
Data Typescups_dest_tDestination typedef struct cups_dest_s cups_dest_t; CUPS 1.4/Mac OS X 10.6 cups_device_cb_tDevice 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); cups_job_tJob typedef struct cups_job_s cups_job_t; cups_option_tPrinter Options typedef struct cups_option_s cups_option_t; CUPS 1.4/Mac OS X 10.6 cups_password_cb2_tNew password callback typedef const char *(*cups_password_cb2_t)(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data); cups_password_cb_tPassword callback typedef const char *(*cups_password_cb_t)(const char *prompt); cups_ptype_tPrinter type/capability bits typedef unsigned cups_ptype_t; Structurescups_dest_sDestination struct cups_dest_s { Members
cups_job_sJob struct cups_job_s { Members
cups_option_sPrinter Options struct cups_option_s { Members
Constantscups_ptype_ePrinter type/capability bit constants Constants
|
:: Command execute :: | |
--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0091 ]-- |