[cups.development] How to get printer status via CUPS API?

Toni Heimala snildspam at gmail.com
Wed Jun 18 03:31:43 PDT 2008


Michael R Sweet wrote:
> 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),

Thanks for the quick response!

It seems that the "printer-state" field from the options has only value 
of 3 or 4 when the printer is out of paper or in a ready state and the 
"printer-state-reasons" value is always "none".

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

Using this approach the "printer_state_message" and 
"printer_state_reasons" pointers point to the NULL pointer and I 
couldn't find a reason why that is.

BTW. httpConnectEncrypt() calls httpInitialize() which calls 
gnutls_global_init() but httpClose() or any other function do not call 
gnutls_global_deinit() which would free the acquired resources. This is 
true for atleast CUPS 1.3.7. See: 
http://linux.die.net/man/3/gnutls_global_init




More information about the cups-devel mailing list