]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpinfo.c
Merge changes from CUPS 1.4svn-r7961.
[thirdparty/cups.git] / systemv / lpinfo.c
index df8bef1aa9df8cd3c29d7414b32aec8c5a96f905..babe6a2ad3f5b21bcfb28511725aee34763b662b 100644 (file)
@@ -1,29 +1,21 @@
 /*
- * "$Id: lpinfo.c 4925 2006-01-13 02:52:47Z mike $"
+ * "$Id: lpinfo.c 7810 2008-07-29 01:11:15Z mike $"
  *
  *   "lpinfo" command for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * 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, const char *device_location,
+                         void *user_data);
 static int     show_devices(http_t *, int);
 static int     show_models(http_t *, int);
 
@@ -62,6 +59,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
   int          long_status;            /* Long listing? */
 
 
+  _cupsSetLocale(argv);
+
   http        = NULL;
   long_status = 0;
 
@@ -165,134 +164,55 @@ 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 */
+    const char *device_location,       /* I - device-location 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"
+                     "        location = %s\n"),
+                   device_uri, device_class, device_info,
+                   device_make_and_model, device_id, device_location);
+  }
+  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);
@@ -434,5 +354,5 @@ show_models(http_t *http,           /* I - HTTP connection to server */
 
 
 /*
- * End of "$Id: lpinfo.c 4925 2006-01-13 02:52:47Z mike $".
+ * End of "$Id: lpinfo.c 7810 2008-07-29 01:11:15Z mike $".
  */