]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/cancel.c
Add more targets covering the CGIs and filters.
[thirdparty/cups.git] / systemv / cancel.c
index 63c92fcfacbec27e1bf6ce4128f41ea0ce6e6fdd..7540d0ba8eecac9231377beaea6508a489027e2a 100644 (file)
@@ -1,40 +1,21 @@
 /*
- * "$Id: cancel.c 5091 2006-02-08 18:39:56Z mike $"
+ * "cancel" command for CUPS.
  *
- *   "cancel" command for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2013 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   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
- *
- * Contents:
- *
- *   main() - Parse options and cancel jobs.
+ * These coded instructions, statements, and computer programs are the
+ * 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/".
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
+#include <cups/cups-private.h>
 
 
 /*
@@ -60,13 +41,14 @@ main(int  argc,                             /* I - Number of command-line arguments */
   ipp_op_t     op;                     /* Operation */
 
 
+  _cupsSetLocale(argv);
+
  /*
   * Setup to cancel individual print jobs...
   */
 
   op        = IPP_CANCEL_JOB;
   purge     = 0;
-  job_id    = 0;
   dest      = NULL;
   user      = NULL;
   http      = NULL;
@@ -80,6 +62,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
 
   for (i = 1; i < argc; i ++)
     if (argv[i][0] == '-' && argv[i][1])
+    {
       switch (argv[i][1])
       {
         case 'E' : /* Encrypt */
@@ -90,8 +73,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
              httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
 #else
             _cupsLangPrintf(stderr,
-                           _("%s: Sorry, no encryption support compiled in!\n"),
-                           argv[0]);
+                           _("%s: Sorry, no encryption support."), argv[0]);
 #endif /* HAVE_SSL */
            break;
 
@@ -105,23 +87,24 @@ main(int  argc,                            /* I - Number of command-line arguments */
              {
                _cupsLangPrintf(stderr,
                                _("%s: Error - expected username after "
-                                 "\'-U\' option!\n"),
-                               argv[0]);
+                                 "\"-U\" option."), argv[0]);
                return (1);
              }
 
               cupsSetUser(argv[i]);
            }
            break;
-           
+
         case 'a' : /* Cancel all jobs */
-           purge = 1;
-           op    = IPP_PURGE_JOBS;
+           op = purge ? IPP_PURGE_JOBS : IPP_CANCEL_JOBS;
            break;
 
         case 'h' : /* Connect to host */
            if (http != NULL)
+           {
              httpClose(http);
+             http = NULL;
+           }
 
            if (argv[i][2] != '\0')
               cupsSetServer(argv[i] + 2);
@@ -133,8 +116,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              {
                _cupsLangPrintf(stderr,
                                _("%s: Error - expected hostname after "
-                                 "\'-h\' option!\n"),
-                               argv[0]);
+                                 "\"-h\" option."), argv[0]);
                return (1);
               }
              else
@@ -143,7 +125,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
            break;
 
         case 'u' : /* Username */
-           op = IPP_PURGE_JOBS;
+           op = IPP_CANCEL_MY_JOBS;
 
            if (argv[i][2] != '\0')
              user = argv[i] + 2;
@@ -155,8 +137,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              {
                _cupsLangPrintf(stderr,
                                _("%s: Error - expected username after "
-                                 "\'-u\' option!\n"),
-                               argv[0]);
+                                 "\"-u\" option."), argv[0]);
                return (1);
               }
              else
@@ -164,12 +145,20 @@ main(int  argc,                           /* I - Number of command-line arguments */
            }
            break;
 
+        case 'x' : /* Purge job(s) */
+           purge = 1;
+
+           if (op == IPP_CANCEL_JOBS)
+             op = IPP_PURGE_JOBS;
+           break;
+
        default :
            _cupsLangPrintf(stderr,
-                           _("%s: Error - unknown option \'%c\'!\n"),
+                           _("%s: Error - unknown option \"%c\"."),
                            argv[0], argv[i][1]);
            return (1);
       }
+    }
     else
     {
      /*
@@ -224,7 +213,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
        */
 
         _cupsLangPrintf(stderr,
-                       _("%s: Error - unknown destination \"%s\"!\n"),
+                       _("%s: Error - unknown destination \"%s\"."),
                        argv[0], argv[i]);
        return (1);
       }
@@ -247,8 +236,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                                       cupsEncryption())) == NULL)
        {
          _cupsLangPrintf(stderr,
-                         _("%s: Unable to contact server!\n"),
-                         argv[0]);
+                         _("%s: Unable to connect to server."), argv[0]);
          return (1);
        }
 
@@ -285,19 +273,22 @@ main(int  argc,                           /* I - Number of command-line arguments */
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                      "requesting-user-name", NULL, user);
        ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
+
+        if (op == IPP_CANCEL_JOBS)
+          op = IPP_CANCEL_MY_JOBS;
       }
       else
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                      "requesting-user-name", NULL, cupsUser());
 
-      if (op == IPP_PURGE_JOBS)
-       ippAddBoolean(request, IPP_TAG_OPERATION, "purge-jobs", purge);
+      if (purge)
+       ippAddBoolean(request, IPP_TAG_OPERATION, "purge-jobs", (char)purge);
 
      /*
       * Do the request and get back a response...
       */
 
-      if (op == IPP_PURGE_JOBS && (!user || strcasecmp(user, cupsUser())))
+      if (op == IPP_CANCEL_JOBS && (!user || _cups_strcasecmp(user, cupsUser())))
         response = cupsDoRequest(http, request, "/admin/");
       else
         response = cupsDoRequest(http, request, "/jobs/");
@@ -305,7 +296,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       if (response == NULL ||
           response->request.status.status_code > IPP_OK_CONFLICT)
       {
-       _cupsLangPrintf(stderr, _("%s: %s failed: %s\n"), argv[0],
+       _cupsLangPrintf(stderr, _("%s: %s failed: %s"), argv[0],
                        op == IPP_PURGE_JOBS ? "purge-jobs" : "cancel-job",
                        cupsLastErrorString());
 
@@ -318,7 +309,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       ippDelete(response);
     }
 
-  if (num_dests == 0 && op == IPP_PURGE_JOBS)
+  if (num_dests == 0 && op != IPP_CANCEL_JOB)
   {
    /*
     * Open a connection to the server...
@@ -328,8 +319,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
                                     cupsEncryption())) == NULL)
       {
-       _cupsLangPrintf(stderr, _("%s: Unable to contact server!\n"),
-                       argv[0]);
+       _cupsLangPrintf(stderr, _("%s: Unable to contact server."), argv[0]);
        return (1);
       }
 
@@ -358,7 +348,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                    "requesting-user-name", NULL, cupsUser());
 
-    ippAddBoolean(request, IPP_TAG_OPERATION, "purge-jobs", purge);
+    ippAddBoolean(request, IPP_TAG_OPERATION, "purge-jobs", (char)purge);
 
    /*
     * Do the request and get back a response...
@@ -369,7 +359,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     if (response == NULL ||
         response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, _("%s: %s failed: %s\n"), argv[0],
+      _cupsLangPrintf(stderr, _("%s: %s failed: %s"), argv[0],
                      op == IPP_PURGE_JOBS ? "purge-jobs" : "cancel-job",
                      cupsLastErrorString());
 
@@ -384,8 +374,3 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   return (0);
 }
-
-
-/*
- * End of "$Id: cancel.c 5091 2006-02-08 18:39:56Z mike $".
- */