]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lp.c
Full sweep of all Clang warnings, plus some bug fixes for incorrect memcpy usage.
[thirdparty/cups.git] / systemv / lp.c
index 744a13acff89053f17493edd46e62df3dee5ed09..9e895d4d6400be9518625da5a37027ae1db91ed7 100644 (file)
@@ -1,22 +1,16 @@
 /*
- * "$Id: lp.c 7170 2008-01-04 02:21:30Z mike $"
+ * "$Id$"
  *
- *   "lp" command for CUPS.
+ * "lp" command for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 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 send files for printing.
- *   restart_job()   - Restart a job.
- *   set_job_attrs() - Set job attributes.
+ * 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/".
  */
 
 /*
@@ -46,7 +40,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
   int          i, j;                   /* Looping vars */
   int          job_id;                 /* Job ID */
   char         *printer,               /* Printer name */
-               *instance,              /* Instance name */ 
+               *instance,              /* Instance name */
                *val,                   /* Option value */
                *title;                 /* Job title */
   int          priority;               /* Job priority (1-100) */
@@ -121,7 +115,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
               cupsSetUser(argv[i]);
            }
            break;
-           
+
         case 'c' : /* Copy to spool dir (always enabled) */
            break;
 
@@ -146,7 +140,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
             if ((instance = strrchr(printer, '/')) != NULL)
              *instance++ = '\0';
 
-            if ((dest = cupsGetNamedDest(NULL, printer, instance)) != NULL)
+            if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer,
+                                         instance)) != NULL)
            {
              for (j = 0; j < dest->num_options; j ++)
                if (cupsGetOption(dest->options[j].name, num_options,
@@ -155,6 +150,14 @@ main(int  argc,                            /* I - Number of command-line arguments */
                                              dest->options[j].value,
                                              num_options, &options);
            }
+           else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                    cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+           {
+             _cupsLangPrintf(stderr,
+                             _("%s: Error - add '/version=1.1' to server "
+                               "name."), argv[0]);
+             return (1);
+           }
            break;
 
         case 'f' : /* Form */
@@ -285,7 +288,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              if (i >= argc)
              {
                _cupsLangPrintf(stderr,
-                               _("%s: Error - expected option string after "
+                               _("%s: Error - expected option=value after "
                                  "\"-o\" option."), argv[0]);
                return (1);
               }
@@ -489,6 +492,13 @@ main(int  argc,                            /* I - Number of command-line arguments */
            break;
 
         case '-' : /* Stop processing options */
+            if (argv[i][2])
+            {
+             _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."),
+                             argv[0], argv[i]);
+             return (1);
+           }
+
            end_options = 1;
            break;
 
@@ -560,6 +570,14 @@ main(int  argc,                            /* I - Number of command-line arguments */
                                      dest->options[j].value,
                                      num_options, &options);
     }
+    else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+            cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+    {
+      _cupsLangPrintf(stderr,
+                     _("%s: Error - add '/version=1.1' to server "
+                       "name."), argv[0]);
+      return (1);
+    }
   }
 
   if (printer == NULL)
@@ -605,7 +623,6 @@ main(int  argc,                             /* I - Number of command-line arguments */
     const char         *format;        /* Document format */
     ssize_t            bytes;          /* Bytes read */
 
-
     if (cupsGetOption("raw", num_options, options))
       format = CUPS_FORMAT_RAW;
     else if ((format = cupsGetOption("document-format", num_options,
@@ -617,17 +634,23 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
     while (status == HTTP_CONTINUE &&
            (bytes = read(0, buffer, sizeof(buffer))) > 0)
-      status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, bytes);
+      status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, (size_t)bytes);
 
     if (status != HTTP_CONTINUE)
     {
       _cupsLangPrintf(stderr, _("%s: Error - unable to queue from stdin - %s."),
                      argv[0], httpStatus(status));
+      cupsFinishDocument(CUPS_HTTP_DEFAULT, printer);
+      cupsCancelJob2(CUPS_HTTP_DEFAULT, printer, job_id, 0);
       return (1);
     }
 
     if (cupsFinishDocument(CUPS_HTTP_DEFAULT, printer) != IPP_OK)
-      job_id = 0;
+    {
+      _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
+      cupsCancelJob2(CUPS_HTTP_DEFAULT, printer, job_id, 0);
+      return (1);
+    }
   }
 
   if (job_id < 1)
@@ -667,7 +690,15 @@ restart_job(const char *command,   /* I - Command name */
 
   ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+  {
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server "
+                     "name."), command);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
     return (1);
@@ -708,7 +739,15 @@ set_job_attrs(const char    *command,      /* I - Command name */
 
   ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+  {
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server "
+                     "name."), command);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
     return (1);
@@ -719,5 +758,5 @@ set_job_attrs(const char    *command,       /* I - Command name */
 
 
 /*
- * End of "$Id: lp.c 7170 2008-01-04 02:21:30Z mike $".
+ * End of "$Id$".
  */