* Contents:
*
* main() - Parse options and show information.
+ * device_cb - Device callback.
* show_devices() - Show available devices.
* show_models() - Show available PPDs.
*/
* Local functions...
*/
+static void device_cb(const char *device_clas, const char *device_id,
+ const char *device_info,
+ const char *device_make_and_model,
+ const char *device_uri, void *user_data);
static int show_devices(http_t *, int);
static int show_models(http_t *, int);
/*
- * 'show_devices()' - Show available devices.
+ * 'device_cb()' - Device callback.
*/
-static int /* O - 0 on success, 1 on failure */
-show_devices(http_t *http, /* I - HTTP connection to server */
- int long_status) /* I - Long status report? */
+static void
+device_cb(
+ const char *device_class, /* I - device-class string */
+ const char *device_id, /* I - device-id string */
+ const char *device_info, /* I - device-info string */
+ const char *device_make_and_model, /* I - device-make-and-model string */
+ const char *device_uri, /* I - device-uri string */
+ void *user_data) /* I - User data */
{
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- ipp_attribute_t *attr; /* Current attribute */
- const char *device_class, /* Pointer to device-class */
- *device_id, /* Pointer to device-id */
- *device_info, /* Pointer to device-info */
- *device_make, /* Pointer to device-make-and-model */
- *device_uri; /* Pointer to device-uri */
-
+ int *long_status; /* Show verbose info? */
- if (http == NULL)
- return (1);
/*
- * Build a CUPS_GET_DEVICES request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
+ * Display the device...
*/
- request = ippNewRequest(CUPS_GET_DEVICES);
-
- /*
- * Do the request and get back a response...
- */
+ long_status = (int *)user_data;
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ if (*long_status)
{
- /*
- * Loop through the device list and display them...
- */
-
- if (response->request.status.status_code > IPP_OK_CONFLICT)
- {
- _cupsLangPrintf(stderr, "lpinfo: %s\n", cupsLastErrorString());
- ippDelete(response);
- return (1);
- }
-
- for (attr = response->attrs; attr != NULL; attr = attr->next)
- {
- /*
- * Skip leading attributes until we hit a device...
- */
-
- while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
- attr = attr->next;
-
- if (attr == NULL)
- break;
-
- /*
- * Pull the needed attributes from this device...
- */
-
- device_class = NULL;
- device_info = NULL;
- device_make = NULL;
- device_uri = NULL;
- device_id = "NONE";
-
- while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
- {
- if (!strcmp(attr->name, "device-class") &&
- attr->value_tag == IPP_TAG_KEYWORD)
- device_class = attr->values[0].string.text;
- else if (!strcmp(attr->name, "device-info") &&
- attr->value_tag == IPP_TAG_TEXT)
- device_info = attr->values[0].string.text;
- else if (!strcmp(attr->name, "device-make-and-model") &&
- attr->value_tag == IPP_TAG_TEXT)
- device_make = attr->values[0].string.text;
- else if (!strcmp(attr->name, "device-uri") &&
- attr->value_tag == IPP_TAG_URI)
- device_uri = attr->values[0].string.text;
- else if (!strcmp(attr->name, "device-id") &&
- attr->value_tag == IPP_TAG_TEXT)
- device_id = attr->values[0].string.text;
-
- attr = attr->next;
- }
-
- /*
- * See if we have everything needed...
- */
-
- if (device_class == NULL || device_info == NULL ||
- device_make == NULL || device_uri == NULL)
- {
- if (attr == NULL)
- break;
- else
- continue;
- }
-
- /*
- * Display the device...
- */
+ _cupsLangPrintf(stdout,
+ _("Device: uri = %s\n"
+ " class = %s\n"
+ " info = %s\n"
+ " make-and-model = %s\n"
+ " device-id = %s\n"),
+ device_uri, device_class, device_info,
+ device_make_and_model, device_id);
+ }
+ else
+ _cupsLangPrintf(stdout, "%s %s\n", device_class, device_uri);
+}
- if (long_status)
- {
- _cupsLangPrintf(stdout,
- _("Device: uri = %s\n"
- " class = %s\n"
- " info = %s\n"
- " make-and-model = %s\n"
- " device-id = %s\n"),
- device_uri, device_class, device_info, device_make,
- device_id);
- }
- else
- _cupsLangPrintf(stdout, "%s %s\n", device_class, device_uri);
- if (attr == NULL)
- break;
- }
+/*
+ * 'show_devices()' - Show available devices.
+ */
- ippDelete(response);
- }
- else
+static int /* O - 0 on success, 1 on failure */
+show_devices(http_t *http, /* I - HTTP connection to server */
+ int long_status) /* I - Long status report? */
+{
+ if (cupsGetDevices(http, CUPS_TIMEOUT_DEFAULT, CUPS_EXCLUDE_NONE, device_cb,
+ &long_status) != IPP_OK)
{
_cupsLangPrintf(stderr, "lpinfo: %s\n", cupsLastErrorString());
return (1);