]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpinfo.c
Import CUPS 1.4svn-r7464.
[thirdparty/cups.git] / systemv / lpinfo.c
index b8697c2c8c95f572074b65a0b70f969e9bf3e826..137304994c7009b4ebe32486fb3aa35f008a84e7 100644 (file)
@@ -15,6 +15,7 @@
  * 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);
 
@@ -158,134 +163,53 @@ main(int  argc,                          /* I - Number of command-line arguments */
 
 
 /*
- * '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);