]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/ipp.c
Off by one error in ipp_finishings_vendor
[thirdparty/cups.git] / backend / ipp.c
index 7851956dbadb21669ff25a4275ea62104e4080d1..60a4ef20f6d86ff558d1dfd49709187c2f8c67c6 100644 (file)
@@ -1450,6 +1450,8 @@ main(int  argc,                           /* I - Number of command-line args */
   monitor.printer_state = IPP_PSTATE_IDLE;
   monitor.retryable     = argc == 6 && document_format && strcmp(document_format, "image/pwg-raster") && strcmp(document_format, "image/urf");
 
+  fprintf(stderr, "DEBUG: retryable=%d\n", monitor.retryable);
+
   if (create_job)
   {
     monitor.job_name = argv[3];
@@ -1504,7 +1506,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
         const char *sides = cupsGetOption("sides", num_options, options);
 
-        if (!strncmp(sides, "two-sided-", 10))
+        if (!sides || !strncmp(sides, "two-sided-", 10))
         {
           fputs("DEBUG: Unable to do two-sided printing, setting sides to 'one-sided'.\n", stderr);
           num_options = cupsAddOption("sides", "one-sided", num_options, &options);
@@ -1867,21 +1869,29 @@ main(int  argc,                         /* I - Number of command-line args */
        response = cupsGetResponse(http, resource);
        ippDelete(request);
 
-       fprintf(stderr, "DEBUG: Send-Document: %s (%s)\n",
-               ippErrorString(cupsLastError()), cupsLastErrorString());
+       fprintf(stderr, "DEBUG: Send-Document: %s (%s)\n", ippErrorString(cupsLastError()), cupsLastErrorString());
         debug_attributes(response);
-        ippDelete(response);
 
        if (cupsLastError() > IPP_STATUS_OK_CONFLICTING && !job_canceled)
        {
+         ipp_attribute_t *reasons = ippFindAttribute(response, "job-state-reasons", IPP_TAG_KEYWORD);
+                                       /* job-state-reasons values */
+
          ipp_status = cupsLastError();
 
-         _cupsLangPrintFilter(stderr, "ERROR",
-                              _("Unable to add document to print job."));
+          if (ippContainsString(reasons, "document-format-error"))
+            ipp_status = IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR;
+          else if (ippContainsString(reasons, "document-unprintable"))
+            ipp_status = IPP_STATUS_ERROR_DOCUMENT_UNPRINTABLE;
+
+         ippDelete(response);
+         _cupsLangPrintFilter(stderr, "ERROR", _("Unable to add document to print job."));
          break;
        }
        else
        {
+         ippDelete(response);
+
          password_tries = 0;
 
          if (num_files == 0 || fd < 0)
@@ -1898,7 +1908,7 @@ main(int  argc,                           /* I - Number of command-line args */
       fprintf(stderr, "PAGE: 1 %d\n", copies_sup ? atoi(argv[4]) : 1);
       copies_remaining --;
     }
-    else if ((ipp_status == IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED || ipp_status == IPP_STATUS_ERROR_DOCUMENT_UNPRINTABLE) &&
+    else if ((ipp_status == IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED || ipp_status == IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR || ipp_status == IPP_STATUS_ERROR_DOCUMENT_UNPRINTABLE) &&
              argc == 6 &&
              document_format && strcmp(document_format, "image/pwg-raster") && strcmp(document_format, "image/urf"))
     {
@@ -2114,11 +2124,10 @@ main(int  argc,                         /* I - Number of command-line args */
                    job_sheets->values[0].integer);
 
         /*
-          * Stop polling if the job is finished or pending-held for 30 seconds...
+          * Stop polling if the job is finished or pending-held...
          */
 
-          if (job_state->values[0].integer > IPP_JSTATE_STOPPED ||
-             (job_state->values[0].integer == IPP_JSTATE_HELD && time(NULL) > waittime))
+          if (job_state->values[0].integer > IPP_JSTATE_STOPPED || job_state->values[0].integer == IPP_JSTATE_HELD)
          {
            ippDelete(response);
            break;