]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lpc.c
Merge changes from CUPS 1.4svn-r7874.
[thirdparty/cups.git] / berkeley / lpc.c
index 4b80a618d206cb4e5584a7450e75e9bab0818370..a18eb0e71a38a7fd094ae0e840a2b9956428ea80 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lpc.c 4906 2006-01-10 20:53:28Z mike $"
+ * "$Id: lpc.c 7079 2007-11-30 01:58:31Z mike $"
  *
  *   "lpc" 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:
  *
@@ -65,6 +56,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
                *params;                /* Pointer to parameters */
 
 
+  _cupsSetLocale(argv);
+
  /*
   * Connect to the scheduler...
   */
@@ -85,7 +78,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
     * Do the command prompt thing...
     */
 
-    printf("lpc> ");
+    _cupsLangPuts(stdout, _("lpc> "));
     while (fgets(line, sizeof(line), stdin) != NULL)
     {
      /*
@@ -113,7 +106,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
         * Nothing left, just show a prompt...
        */
 
-        printf("lpc> ");
+       _cupsLangPuts(stdout, _("lpc> "));
        continue;
       }
 
@@ -149,7 +142,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       * Put another prompt out to the user...
       */
 
-      printf("lpc> ");
+      _cupsLangPuts(stdout, _("lpc> "));
     }
   }
 
@@ -197,7 +190,7 @@ do_command(http_t     *http,                /* I - HTTP connection to server */
   else if (!compare_strings(command, "help", 1) || !strcmp(command, "?"))
     show_help(params);
   else
-    _cupsLangPrintf(stdout, cupsLangDefault(),
+    _cupsLangPrintf(stdout,
                     _("%s is not implemented by the CUPS version of lpc.\n"),
                    command);
 }
@@ -212,20 +205,17 @@ show_help(const char *command)            /* I - Command to describe or NULL */
 {
   if (!command)
   {
-    _cupsLangPrintf(stdout, cupsLangDefault(),
+    _cupsLangPrintf(stdout,
                     _("Commands may be abbreviated.  Commands are:\n"
                      "\n"
                      "exit    help    quit    status  ?\n"));
   }
   else if (!compare_strings(command, "help", 1) || !strcmp(command, "?"))
-    _cupsLangPrintf(stdout, cupsLangDefault(),
-                    _("help\t\tget help on commands\n"));
+    _cupsLangPrintf(stdout, _("help\t\tget help on commands\n"));
   else if (!compare_strings(command, "status", 4))
-    _cupsLangPrintf(stdout, cupsLangDefault(),
-                    _("status\t\tshow status of daemon and queue\n"));
+    _cupsLangPrintf(stdout, _("status\t\tshow status of daemon and queue\n"));
   else
-    _cupsLangPrintf(stdout, cupsLangDefault(),
-                    _("?Invalid help command unknown\n"));
+    _cupsLangPrintf(stdout, _("?Invalid help command unknown\n"));
 }
 
 
@@ -238,11 +228,8 @@ show_status(http_t     *http,              /* I - HTTP connection to server */
             const char *dests)         /* I - Destinations */
 {
   ipp_t                *request,               /* IPP Request */
-               *response,              /* IPP Response */
-               *jobs;                  /* IPP Get Jobs response */
-  ipp_attribute_t *attr,               /* Current attribute */
-               *jattr;                 /* Current job attribute */
-  cups_lang_t  *language;              /* Default language */
+               *response;              /* IPP Response */
+  ipp_attribute_t *attr;               /* Current attribute */
   char         *printer,               /* Printer name */
                *device,                /* Device URI */
                 *delimiter;            /* Char search result */
@@ -252,14 +239,13 @@ show_status(http_t     *http,             /* I - HTTP connection to server */
   const char   *dptr,                  /* Pointer into destination list */
                *ptr;                   /* Pointer into printer name */
   int          match;                  /* Non-zero if this job matches */
-  char         printer_uri[HTTP_MAX_URI];
-                                       /* Printer URI */
   static const char *requested[] =     /* Requested attributes */
                {
-                 "printer-name",
                  "device-uri",
+                 "printer-is-accepting-jobs",
+                 "printer-name",
                  "printer-state",
-                 "printer-is-accepting-jobs"
+                 "queued-job-count"
                };
 
 
@@ -276,18 +262,7 @@ show_status(http_t     *http,              /* I - HTTP connection to server */
   *    attributes-natural-language
   */
 
-  request = ippNew();
-
-  request->request.op.operation_id = CUPS_GET_PRINTERS;
-  request->request.op.request_id   = 1;
-
-  language = cupsLangDefault();
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-               "attributes-charset", NULL, cupsLangEncoding(language));
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-               "attributes-natural-language", NULL, language->language);
+  request = ippNewRequest(CUPS_GET_PRINTERS);
 
   ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                 "requested-attributes", sizeof(requested) / sizeof(requested[0]),
@@ -330,21 +305,21 @@ show_status(http_t     *http,             /* I - HTTP connection to server */
 
       while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
       {
-        if (!strcmp(attr->name, "printer-name") &&
-           attr->value_tag == IPP_TAG_NAME)
-         printer = attr->values[0].string.text;
-
         if (!strcmp(attr->name, "device-uri") &&
            attr->value_tag == IPP_TAG_URI)
          device = attr->values[0].string.text;
-
-        if (!strcmp(attr->name, "printer-state") &&
-           attr->value_tag == IPP_TAG_ENUM)
-         pstate = (ipp_pstate_t)attr->values[0].integer;
-
-        if (!strcmp(attr->name, "printer-is-accepting-jobs") &&
-           attr->value_tag == IPP_TAG_BOOLEAN)
+        else if (!strcmp(attr->name, "printer-is-accepting-jobs") &&
+                attr->value_tag == IPP_TAG_BOOLEAN)
          accepting = attr->values[0].boolean;
+        else if (!strcmp(attr->name, "printer-name") &&
+                attr->value_tag == IPP_TAG_NAME)
+         printer = attr->values[0].string.text;
+        else if (!strcmp(attr->name, "printer-state") &&
+                attr->value_tag == IPP_TAG_ENUM)
+         pstate = (ipp_pstate_t)attr->values[0].integer;
+        else if (!strcmp(attr->name, "queued-job-count") &&
+                attr->value_tag == IPP_TAG_INTEGER)
+         jobcount = attr->values[0].integer;
 
         attr = attr->next;
       }
@@ -396,7 +371,8 @@ show_status(http_t     *http,               /* I - HTTP connection to server */
               *ptr != '\0' && *dptr != '\0' && *ptr == *dptr;
               ptr ++, dptr ++);
 
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
+          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' ||
+                              isspace(*dptr & 255)))
          {
            match = 1;
            break;
@@ -422,59 +398,13 @@ show_status(http_t     *http,             /* I - HTTP connection to server */
 
       if (match)
       {
-       /*
-       * Build an IPP_GET_JOBS request, which requires the following
-       * attributes:
-       *
-       *    attributes-charset
-       *    attributes-natural-language
-       *    printer-uri
-       *    limit
-       */
-
-       request = ippNew();
-
-       request->request.op.operation_id = IPP_GET_JOBS;
-       request->request.op.request_id   = 1;
-
-       language = cupsLangDefault();
-
-       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                     "attributes-charset", NULL,
-                    cupsLangEncoding(language));
-
-       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-                     "attributes-natural-language", NULL,
-                    language->language);
-
-        httpAssembleURIf(printer_uri, sizeof(printer_uri), "ipp", NULL,
-                        "localhost", 631, "/printers/%s", printer);
-       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
-                    "printer-uri", NULL, printer_uri);
-
-       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
-                    "requested-attributes", NULL, "job-id");
-
-        if ((jobs = cupsDoRequest(http, request, "/")) != NULL)
-       {
-        /*
-         * Grab the number of jobs for the printer.
-         */
-
-         for (jattr = jobs->attrs; jattr != NULL; jattr = jattr->next)
-           if (jattr->name && !strcmp(jattr->name, "job-id"))
-             jobcount ++;
-
-          ippDelete(jobs);
-       }
-
        /*
         * Display it...
        */
 
         printf("%s:\n", printer);
        if (!strncmp(device, "file:", 5))
-         _cupsLangPrintf(stdout, language,
+         _cupsLangPrintf(stdout,
                          _("\tprinter is on device \'%s\' speed -1\n"),
                          device + 5);
        else
@@ -486,28 +416,28 @@ show_status(http_t     *http,             /* I - HTTP connection to server */
          if ((delimiter = strchr(device, ':')) != NULL )
          {
            *delimiter = '\0';
-           _cupsLangPrintf(stdout, language,
+           _cupsLangPrintf(stdout,
                            _("\tprinter is on device \'%s\' speed -1\n"),
                            device);
          }
        }
 
         if (accepting)
-         _cupsLangPuts(stdout, language, _("\tqueuing is enabled\n"));
+         _cupsLangPuts(stdout, _("\tqueuing is enabled\n"));
        else
-         _cupsLangPuts(stdout, language, _("\tqueuing is disabled\n"));
+         _cupsLangPuts(stdout, _("\tqueuing is disabled\n"));
 
         if (pstate != IPP_PRINTER_STOPPED)
-         _cupsLangPuts(stdout, language, _("\tprinting is enabled\n"));
+         _cupsLangPuts(stdout, _("\tprinting is enabled\n"));
        else
-         _cupsLangPuts(stdout, language, _("\tprinting is disabled\n"));
+         _cupsLangPuts(stdout, _("\tprinting is disabled\n"));
 
        if (jobcount == 0)
-         _cupsLangPuts(stdout, language, _("\tno entries\n"));
+         _cupsLangPuts(stdout, _("\tno entries\n"));
        else
-         _cupsLangPrintf(stdout, language, _("\t%d entries\n"), jobcount);
+         _cupsLangPrintf(stdout, _("\t%d entries\n"), jobcount);
 
-       _cupsLangPuts(stdout, language, _("\tdaemon present\n"));
+       _cupsLangPuts(stdout, _("\tdaemon present\n"));
       }
 
       if (attr == NULL)
@@ -520,5 +450,5 @@ show_status(http_t     *http,               /* I - HTTP connection to server */
 
 
 /*
- * End of "$Id: lpc.c 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: lpc.c 7079 2007-11-30 01:58:31Z mike $".
  */