]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/cupsaccept.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / systemv / cupsaccept.c
index 3c4f838cb1562bb104037dede1633105808a823f..7d597b386dba1688f09aab69253610c5bba37021 100644 (file)
@@ -1,33 +1,18 @@
 /*
- * "$Id$"
+ * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
+ * CUPS.
  *
- *   "accept", "disable", "enable", and "reject" commands for the Common
- *   UNIX Printing System (CUPS).
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2008 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
- *
- *   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/".
- *
- * Contents:
- *
- *   main() - Parse options and accept/reject jobs or disable/enable printers.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
+#include <cups/cups-private.h>
 
 
 /*
@@ -38,13 +23,12 @@ int                                 /* O - Exit status */
 main(int  argc,                                /* I - Number of command-line arguments */
      char *argv[])                     /* I - Command-line arguments */
 {
-  http_t       *http;                  /* HTTP connection to server */
   int          i;                      /* Looping var */
   char         *command,               /* Command to do */
+               *opt,                   /* Option pointer */
                uri[1024],              /* Printer URI */
                *reason;                /* Reason for reject/disable */
   ipp_t                *request;               /* IPP request */
-  ipp_t                *response;              /* IPP response */
   ipp_op_t     op;                     /* Operation */
   int          cancel;                 /* Cancel jobs? */
 
@@ -72,12 +56,10 @@ main(int  argc,                             /* I - Number of command-line arguments */
     op = IPP_RESUME_PRINTER;
   else
   {
-    _cupsLangPrintf(stderr, _("%s: Don't know what to do!\n"),
-                    command);
+    _cupsLangPrintf(stderr, _("%s: Don't know what to do."), command);
     return (1);
   }
 
-  http   = NULL;
   reason = NULL;
 
  /*
@@ -85,121 +67,98 @@ main(int  argc,                            /* I - Number of command-line arguments */
   */
 
   for (i = 1; i < argc; i ++)
-    if (argv[i][0] == '-')
-      switch (argv[i][1])
+  {
+    if (!strcmp(argv[i], "--hold"))
+      op = IPP_HOLD_NEW_JOBS;
+    else if (!strcmp(argv[i], "--release"))
+      op = IPP_RELEASE_HELD_NEW_JOBS;
+    else if (argv[i][0] == '-')
+    {
+      for (opt = argv[i] + 1; *opt; opt ++)
       {
-        case 'E' : /* Encrypt */
+       switch (*opt)
+       {
+         case 'E' : /* Encrypt */
 #ifdef HAVE_SSL
-           cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
-
-           if (http)
-             httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+             cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr,
-                           _("%s: Sorry, no encryption support compiled in!\n"),
-                           command);
+             _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), command);
 #endif /* HAVE_SSL */
-           break;
-
-        case 'U' : /* Username */
-           if (argv[i][2] != '\0')
-             cupsSetUser(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+             break;
+
+         case 'U' : /* Username */
+             if (opt[1] != '\0')
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected username after "
-                                 "\'-U\' option!\n"),
-                               command);
-               return (1);
+               cupsSetUser(opt + 1);
+               opt += strlen(opt) - 1;
              }
-
-              cupsSetUser(argv[i]);
-           }
-           break;
-           
-        case 'c' : /* Cancel jobs */
-           cancel = 1;
-           break;
-
-        case 'h' : /* Connect to host */
-           if (http)
-           {
-             httpClose(http);
-             http = NULL;
-           }
-
-           if (argv[i][2] != '\0')
-             cupsSetServer(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+             else
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected hostname after "
-                                 "\'-h\' option!\n"),
-                               command);
-               return (1);
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), command);
+                 return (1);
+               }
+
+               cupsSetUser(argv[i]);
              }
+             break;
 
-              cupsSetServer(argv[i]);
-           }
-           break;
-
-        case 'r' : /* Reason for cancellation */
-           if (argv[i][2] != '\0')
-             reason = argv[i] + 2;
-           else
-           {
-             i ++;
-             if (i >= argc)
+         case 'c' : /* Cancel jobs */
+             cancel = 1;
+             break;
+
+         case 'h' : /* Connect to host */
+             if (opt[1] != '\0')
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected reason text after "
-                                 "\'-r\' option!\n"),
-                               command);
-               return (1);
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), command);
+                 return (1);
+               }
+
+               cupsSetServer(argv[i]);
+             }
+             break;
 
-             reason = argv[i];
-           }
-           break;
+         case 'r' : /* Reason for cancellation */
+             if (opt[1] != '\0')
+             {
+               reason = opt + 1;
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected reason text after \"-r\" option."), command);
+                 return (1);
+               }
+
+               reason = argv[i];
+             }
+             break;
 
-       default :
-           _cupsLangPrintf(stderr, _("%s: Error - unknown option \'%c\'!\n"),
-                           command, argv[i][1]);
-           return (1);
+         default :
+             _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), command, *opt);
+             return (1);
+       }
       }
+    }
     else
     {
      /*
       * Accept/disable/enable/reject a destination...
       */
 
-      if (http == NULL)
-        http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
-
-      if (http == NULL)
-      {
-       _cupsLangPrintf(stderr,
-                       _("%s: Unable to connect to server: %s\n"),
-                       command, strerror(errno));
-       return (1);
-      }
-
-     /*
-      * Build an IPP request, which requires the following
-      * attributes:
-      *
-      *    attributes-charset
-      *    attributes-natural-language
-      *    printer-uri
-      *    printer-state-message [optional]
-      */
-
       request = ippNewRequest(op);
 
       httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
@@ -218,21 +177,13 @@ main(int  argc,                           /* I - Number of command-line arguments */
       * Do the request and get back a response...
       */
 
-      if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
-      {
-        if (response->request.status.status_code > IPP_OK_CONFLICT)
-       {
-          _cupsLangPrintf(stderr,
-                         _("%s: Operation failed: %s\n"),
-                         command, ippErrorString(cupsLastError()));
-         return (1);
-       }
-       
-        ippDelete(response);
-      }
-      else
+      ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/"));
+
+      if (cupsLastError() > IPP_OK_CONFLICT)
       {
-        _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
+       _cupsLangPrintf(stderr,
+                       _("%s: Operation failed: %s"),
+                       command, ippErrorString(cupsLastError()));
        return (1);
       }
 
@@ -256,31 +207,16 @@ main(int  argc,                           /* I - Number of command-line arguments */
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                      "printer-uri", NULL, uri);
 
-       if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
-       {
-          if (response->request.status.status_code > IPP_OK_CONFLICT)
-         {
-            _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
-           return (1);
-         }
+       ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/"));
 
-          ippDelete(response);
-       }
-       else
+        if (cupsLastError() > IPP_OK_CONFLICT)
        {
-          _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
+         _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
          return (1);
        }
       }
     }
-
-  if (http != NULL)
-    httpClose(http);
+  }
 
   return (0);
 }
-
-
-/*
- * End of "$Id$".
- */