[cups.development] How to get printer status via CUPS API?
Michael R Sweet
msweet at apple.com
Tue Jun 17 07:56:24 PDT 2008
Toni Heimala wrote:
> How can I get the current printer status through the CUPS API?
>
> What I would like to achieve is to get printer status messages like "Out
> of paper", "Paper jam", etc.
You can either call cupsGetDests and cupsGetDest to get the current
printer-state and printer-state-reasons attributes (they are provided
as options in the cups_dest_t structure), or send an
IPP_GET_PRINTER_ATTRIBUTES request to get the attributes directly:
const char *name; /* printer name */
http_t *http = httpConnectEncrypt(cupsServer(), ippPort(),
cupsEncryption());
ipp_t *request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
char printer_uri[1024];
ipp_t *response;
ipp_attribute_t *printer_state_message;
ipp_attribute_t *printer_state_reasons;
httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
"ipp", NULL, cupsServer(), ippPort(),
"/printers/%s", name);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, printer_uri);
response = cupsDoRequest(http, request, "/");
printer_state_message = ippFindAttribute(response,
"printer-state-message",
IPP_TAG_TEXT);
printer_state_reasons = ippFindAttribute(response,
"printer-state-reasons",
IPP_TAG_KEYWORD);
/* do something wih message and reasons */
ippDelete(response);
httpClose(http);
--
______________________________________________________________________
Michael R Sweet Senior Printing System Engineer
More information about the cups
mailing list