]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/ipp.c
Merge pull request #5621 from zdohnal/cgigetarray-sigsegv
[thirdparty/cups.git] / backend / ipp.c
index dbbb029f189020d5dfff2878ae4694d46246a3b2..b2b22065ef4ab9e5e964f1c36d482c9eff4eee8d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * IPP backend for CUPS.
  *
- * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 2007-2019 by Apple Inc.
  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  *
  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
 #  define kPMPrintUIToolAgent  "com.apple.printuitool.agent"
 #  define kPMStartJob          100
 #  define kPMWaitForJob                101
-#  ifdef HAVE_XPC_PRIVATE_H
-#    include <xpc/private.h>
-#  else
 extern void    xpc_connection_set_target_uid(xpc_connection_t connection,
                                              uid_t uid);
-#  endif /* HAVE_XPC_PRIVATE_H */
 #endif /* HAVE_GSSAPI && HAVE_XPC */
 
 
@@ -389,7 +385,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
 #  else /* No XPC, just try to run as the user ID */
     if (uid > 0)
-      seteuid(uid);
+      setuid(uid);
 #  endif /* HAVE_XPC */
   }
 #endif /* HAVE_GSSAPI */
@@ -421,9 +417,9 @@ main(int  argc,                             /* I - Number of command-line args */
     port = IPP_PORT;                   /* Default to port 631 */
 
   if (!strcmp(scheme, "https") || !strcmp(scheme, "ipps"))
-    cupsSetEncryption(HTTP_ENCRYPT_ALWAYS);
+    cupsSetEncryption(HTTP_ENCRYPTION_ALWAYS);
   else
-    cupsSetEncryption(HTTP_ENCRYPT_IF_REQUESTED);
+    cupsSetEncryption(HTTP_ENCRYPTION_IF_REQUESTED);
 
  /*
   * See if there are any options...
@@ -510,13 +506,13 @@ main(int  argc,                           /* I - Number of command-line args */
        */
 
         if (!_cups_strcasecmp(value, "always"))
-         cupsSetEncryption(HTTP_ENCRYPT_ALWAYS);
+         cupsSetEncryption(HTTP_ENCRYPTION_ALWAYS);
         else if (!_cups_strcasecmp(value, "required"))
-         cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
+         cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);
         else if (!_cups_strcasecmp(value, "never"))
-         cupsSetEncryption(HTTP_ENCRYPT_NEVER);
+         cupsSetEncryption(HTTP_ENCRYPTION_NEVER);
         else if (!_cups_strcasecmp(value, "ifrequested"))
-         cupsSetEncryption(HTTP_ENCRYPT_IF_REQUESTED);
+         cupsSetEncryption(HTTP_ENCRYPTION_IF_REQUESTED);
        else
        {
          _cupsLangPrintFilter(stderr, "ERROR",
@@ -704,11 +700,11 @@ main(int  argc,                           /* I - Number of command-line args */
     fprintf(stderr, "DEBUG: Connecting to %s:%d\n", hostname, port);
     _cupsLangPrintFilter(stderr, "INFO", _("Connecting to printer."));
 
-    if (httpReconnect(http))
+    if (httpReconnect2(http, 30000, NULL))
     {
       int error = errno;               /* Connection error */
 
-      if (http->status == HTTP_PKI_ERROR)
+      if (http->status == HTTP_STATUS_CUPS_PKI_ERROR)
        update_reasons(NULL, "+cups-certificate-error");
 
       if (job_canceled)
@@ -911,7 +907,7 @@ main(int  argc,                             /* I - Number of command-line args */
     * Build the IPP request...
     */
 
-    request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+    request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
     ippSetVersion(request, version / 10, version % 10);
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                 NULL, uri);
@@ -926,7 +922,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
     fputs("DEBUG: Getting supported attributes...\n", stderr);
 
-    if (http->version < HTTP_1_1)
+    if (http->version < HTTP_VERSION_1_1)
     {
       fprintf(stderr, "DEBUG: Printer responded with HTTP version %d.%d.\n",
               http->version / 100, http->version % 100);
@@ -940,15 +936,15 @@ main(int  argc,                           /* I - Number of command-line args */
     fprintf(stderr, "DEBUG: Get-Printer-Attributes: %s (%s)\n",
             ippErrorString(ipp_status), cupsLastErrorString());
 
-    if (ipp_status <= IPP_OK_CONFLICT)
+    if (ipp_status <= IPP_STATUS_OK_CONFLICTING)
       password_tries = 0;
     else
     {
       fprintf(stderr, "DEBUG: Get-Printer-Attributes returned %s.\n",
               ippErrorString(ipp_status));
 
-      if (ipp_status == IPP_PRINTER_BUSY ||
-         ipp_status == IPP_SERVICE_UNAVAILABLE)
+      if (ipp_status == IPP_STATUS_ERROR_BUSY ||
+         ipp_status == IPP_STATUS_ERROR_SERVICE_UNAVAILABLE)
       {
         if (contimeout && (time(NULL) - start_time) > contimeout)
        {
@@ -965,8 +961,8 @@ main(int  argc,                             /* I - Number of command-line args */
 
         delay = _cupsNextDelay(delay, &prev_delay);
       }
-      else if ((ipp_status == IPP_BAD_REQUEST ||
-               ipp_status == IPP_VERSION_NOT_SUPPORTED) && version > 10)
+      else if ((ipp_status == IPP_STATUS_ERROR_BAD_REQUEST ||
+               ipp_status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) && version > 10)
       {
        /*
        * Switch to IPP/1.1 or IPP/1.0...
@@ -989,9 +985,9 @@ main(int  argc,                             /* I - Number of command-line args */
          version = 10;
         }
 
-       httpReconnect(http);
+       httpReconnect2(http, 30000, NULL);
       }
-      else if (ipp_status == IPP_NOT_FOUND)
+      else if (ipp_status == IPP_STATUS_ERROR_NOT_FOUND)
       {
         _cupsLangPrintFilter(stderr, "ERROR",
                             _("The printer configuration is incorrect or the "
@@ -1001,8 +997,8 @@ main(int  argc,                            /* I - Number of command-line args */
 
        return (CUPS_BACKEND_STOP);
       }
-      else if (ipp_status == IPP_FORBIDDEN ||
-               ipp_status == IPP_AUTHENTICATION_CANCELED)
+      else if (ipp_status == IPP_STATUS_ERROR_FORBIDDEN ||
+               ipp_status == IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED)
       {
         const char *www_auth = httpGetField(http, HTTP_FIELD_WWW_AUTHENTICATE);
                                        /* WWW-Authenticate field value */
@@ -1015,13 +1011,13 @@ main(int  argc,                         /* I - Number of command-line args */
        fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required);
        return (CUPS_BACKEND_AUTH_REQUIRED);
       }
-      else if (ipp_status != IPP_NOT_AUTHORIZED)
+      else if (ipp_status != IPP_STATUS_ERROR_NOT_AUTHORIZED)
       {
        _cupsLangPrintFilter(stderr, "ERROR",
                             _("Unable to get printer status."));
         sleep(10);
 
-       httpReconnect(http);
+       httpReconnect2(http, 30000, NULL);
       }
 
       ippDelete(supported);
@@ -1135,7 +1131,14 @@ main(int  argc,                          /* I - Number of command-line args */
        copies_sup = NULL; /* No */
     }
 
-    cups_version = ippFindAttribute(supported, "cups-version", IPP_TAG_TEXT);
+    if ((cups_version = ippFindAttribute(supported, "cups-version", IPP_TAG_TEXT)) != NULL)
+    {
+      const char *val = ippGetString(cups_version, 0, NULL);
+
+      fprintf(stderr, "DEBUG: cups-version = \"%s\"\n", val);
+      if (!strcmp(val, "cups-version"))
+        cups_version = NULL;           /* Bogus cups-version value returned by buggy printers! */
+    }
 
     encryption_sup = ippFindAttribute(supported, "job-password-encryption-supported", IPP_TAG_KEYWORD);
 
@@ -1171,7 +1174,7 @@ main(int  argc,                           /* I - Number of command-line args */
                 ippOpString(operations_sup->values[i].integer));
 
       for (i = 0; i < operations_sup->num_values; i ++)
-        if (operations_sup->values[i].integer == IPP_PRINT_JOB)
+        if (operations_sup->values[i].integer == IPP_OP_PRINT_JOB)
          break;
 
       if (i >= operations_sup->num_values)
@@ -1179,7 +1182,7 @@ main(int  argc,                           /* I - Number of command-line args */
                             "cups-ipp-missing-print-job");
 
       for (i = 0; i < operations_sup->num_values; i ++)
-        if (operations_sup->values[i].integer == IPP_CANCEL_JOB)
+        if (operations_sup->values[i].integer == IPP_OP_CANCEL_JOB)
          break;
 
       if (i >= operations_sup->num_values)
@@ -1187,7 +1190,7 @@ main(int  argc,                           /* I - Number of command-line args */
                             "cups-ipp-missing-cancel-job");
 
       for (i = 0; i < operations_sup->num_values; i ++)
-        if (operations_sup->values[i].integer == IPP_GET_JOB_ATTRIBUTES)
+        if (operations_sup->values[i].integer == IPP_OP_GET_JOB_ATTRIBUTES)
          break;
 
       if (i >= operations_sup->num_values)
@@ -1195,7 +1198,7 @@ main(int  argc,                           /* I - Number of command-line args */
                              "cups-ipp-missing-get-job-attributes");
 
       for (i = 0; i < operations_sup->num_values; i ++)
-        if (operations_sup->values[i].integer == IPP_GET_PRINTER_ATTRIBUTES)
+        if (operations_sup->values[i].integer == IPP_OP_GET_PRINTER_ATTRIBUTES)
          break;
 
       if (i >= operations_sup->num_values)
@@ -1204,13 +1207,13 @@ main(int  argc,                         /* I - Number of command-line args */
 
       for (i = 0; i < operations_sup->num_values; i ++)
       {
-        if (operations_sup->values[i].integer == IPP_VALIDATE_JOB)
+        if (operations_sup->values[i].integer == IPP_OP_VALIDATE_JOB)
          validate_job = 1;
-        else if (operations_sup->values[i].integer == IPP_CREATE_JOB)
+        else if (operations_sup->values[i].integer == IPP_OP_CREATE_JOB)
          create_job = 1;
-        else if (operations_sup->values[i].integer == IPP_SEND_DOCUMENT)
+        else if (operations_sup->values[i].integer == IPP_OP_SEND_DOCUMENT)
          send_document = 1;
-        else if (operations_sup->values[i].integer == IPP_GET_JOB_ATTRIBUTES)
+        else if (operations_sup->values[i].integer == IPP_OP_GET_JOB_ATTRIBUTES)
          get_job_attrs = 1;
       }
 
@@ -1238,7 +1241,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
     report_printer_state(supported);
   }
-  while (!job_canceled && ipp_status > IPP_OK_CONFLICT);
+  while (!job_canceled && ipp_status > IPP_STATUS_OK_CONFLICTING);
 
   if (job_canceled)
     return (CUPS_BACKEND_OK);
@@ -1256,7 +1259,7 @@ main(int  argc,                           /* I - Number of command-line args */
                                         IPP_TAG_BOOLEAN);
 
     if (printer_state == NULL ||
-       (printer_state->values[0].integer > IPP_PRINTER_PROCESSING &&
+       (printer_state->values[0].integer > IPP_PSTATE_PROCESSING &&
         waitprinter) ||
        printer_accepting == NULL ||
        !printer_accepting->values[0].boolean)
@@ -1382,7 +1385,7 @@ main(int  argc,                           /* I - Number of command-line args */
   * (I hate compatibility hacks!)
   */
 
-  if (http->version < HTTP_1_1 && num_files == 0)
+  if (http->version < HTTP_VERSION_1_1 && num_files == 0)
   {
     if ((fd = cupsTempFd(tmpfilename, sizeof(tmpfilename))) < 0)
     {
@@ -1410,7 +1413,7 @@ main(int  argc,                           /* I - Number of command-line args */
     files      = &compatfile;
     num_files  = 1;
   }
-  else if (http->version < HTTP_1_1 && num_files == 1)
+  else if (http->version < HTTP_VERSION_1_1 && num_files == 1)
   {
     struct stat        fileinfo;               /* File information */
 
@@ -1443,10 +1446,12 @@ main(int  argc,                         /* I - Number of command-line args */
   monitor.create_job    = create_job;
   monitor.get_job_attrs = get_job_attrs;
   monitor.encryption    = cupsEncryption();
-  monitor.job_state     = IPP_JOB_PENDING;
-  monitor.printer_state = IPP_PRINTER_IDLE;
+  monitor.job_state     = IPP_JSTATE_PENDING;
+  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];
@@ -1485,6 +1490,30 @@ main(int  argc,                          /* I - Number of command-line args */
                                   ippGetString(job_auth, 0, NULL), num_options,
                                   &options);
 
+    if (ipp_status == IPP_STATUS_OK_IGNORED_OR_SUBSTITUTED || ipp_status == IPP_STATUS_OK_CONFLICTING)
+    {
+     /*
+      * One or more options are not supported...
+      */
+
+      ipp_attribute_t  *attr;          /* Unsupported attribute */
+
+      if ((attr = ippFindAttribute(response, "sides", IPP_TAG_ZERO)) != NULL)
+      {
+       /*
+        * The sides value is not supported, revert to one-sided as needed...
+        */
+
+        const char *sides = cupsGetOption("sides", num_options, options);
+
+        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);
+        }
+      }
+    }
+
     ippDelete(response);
 
     if (job_canceled)
@@ -1527,10 +1556,10 @@ main(int  argc,                         /* I - Number of command-line args */
                           "cups-ipp-missing-validate-job");
       break;
     }
-    else if (ipp_status < IPP_REDIRECTION_OTHER_SITE ||
-             ipp_status == IPP_BAD_REQUEST)
+    else if (ipp_status < IPP_STATUS_REDIRECTION_OTHER_SITE ||
+             ipp_status == IPP_STATUS_ERROR_BAD_REQUEST)
       break;
-    else if (job_auth == NULL && ipp_status > IPP_BAD_REQUEST)
+    else if (job_auth == NULL && ipp_status > IPP_STATUS_ERROR_BAD_REQUEST)
       goto cleanup;
   }
 
@@ -1555,8 +1584,8 @@ main(int  argc,                           /* I - Number of command-line args */
     if (job_canceled)
       break;
 
-    request = new_request((num_files > 1 || create_job) ? IPP_CREATE_JOB :
-                                                          IPP_PRINT_JOB,
+    request = new_request((num_files > 1 || create_job) ? IPP_OP_CREATE_JOB :
+                                                          IPP_OP_PRINT_JOB,
                          version, uri, argv[2], monitor.job_name, num_options,
                          options, compression, copies_sup ? copies : 1,
                          document_format, pc, ppd, media_col_sup,
@@ -1581,7 +1610,7 @@ main(int  argc,                           /* I - Number of command-line args */
         fputs("DEBUG: Sending file using HTTP/1.1 chunking...\n", stderr);
 
       http_status = cupsSendRequest(http, request, resource, length);
-      if (http_status == HTTP_CONTINUE && request->state == IPP_DATA)
+      if (http_status == HTTP_STATUS_CONTINUE && request->state == IPP_STATE_DATA)
       {
        if (compression && strcmp(compression, "none"))
          httpSetField(http, HTTP_FIELD_CONTENT_ENCODING, compression);
@@ -1600,7 +1629,7 @@ main(int  argc,                           /* I - Number of command-line args */
          http_status = cupsWriteRequestData(http, buffer, (size_t)bytes);
         }
 
-        while (http_status == HTTP_CONTINUE &&
+        while (http_status == HTTP_STATUS_CONTINUE &&
                (!job_canceled || compatsize > 0))
        {
         /*
@@ -1625,7 +1654,7 @@ main(int  argc,                           /* I - Number of command-line args */
              fprintf(stderr, "DEBUG: Read %d bytes...\n", (int)bytes);
 
              if ((http_status = cupsWriteRequestData(http, buffer, (size_t)bytes))
-                     != HTTP_CONTINUE)
+                     != HTTP_STATUS_CONTINUE)
                break;
            }
            else if (bytes == 0 || (errno != EINTR && errno != EAGAIN))
@@ -1633,7 +1662,7 @@ main(int  argc,                           /* I - Number of command-line args */
          }
        }
 
-       if (http_status == HTTP_ERROR)
+       if (http_status == HTTP_STATUS_ERROR)
          fprintf(stderr, "DEBUG: Error writing document data for "
                          "Print-Job: %s\n", strerror(httpError(http)));
 
@@ -1652,7 +1681,7 @@ main(int  argc,                           /* I - Number of command-line args */
             ippErrorString(ipp_status), cupsLastErrorString());
     debug_attributes(response);
 
-    if (ipp_status > IPP_OK_CONFLICT)
+    if (ipp_status > IPP_STATUS_OK_CONFLICTING)
     {
       job_id = 0;
 
@@ -1704,7 +1733,7 @@ main(int  argc,                           /* I - Number of command-line args */
          else if (www_auth[0])
            auth_info_required = "username,password";
        }
-       else if (ipp_status == IPP_REQUEST_VALUE)
+       else if (ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE)
        {
         /*
          * Print file is too large, abort this job...
@@ -1760,7 +1789,7 @@ main(int  argc,                           /* I - Number of command-line args */
         * Send the next file in the job...
        */
 
-       request = ippNewRequest(IPP_SEND_DOCUMENT);
+       request = ippNewRequest(IPP_OP_SEND_DOCUMENT);
        ippSetVersion(request, version / 10, version % 10);
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
@@ -1789,7 +1818,7 @@ main(int  argc,                           /* I - Number of command-line args */
        debug_attributes(request);
 
        http_status = cupsSendRequest(http, request, resource, 0);
-       if (http_status == HTTP_CONTINUE && request->state == IPP_DATA)
+       if (http_status == HTTP_STATUS_CONTINUE && request->state == IPP_STATE_DATA)
        {
          if (compression && strcmp(compression, "none"))
            httpSetField(http, HTTP_FIELD_CONTENT_ENCODING, compression);
@@ -1813,11 +1842,11 @@ main(int  argc,                         /* I - Number of command-line args */
 
        if (fd >= 0)
        {
-         while (!job_canceled && http_status == HTTP_CONTINUE &&
+         while (!job_canceled && http_status == HTTP_STATUS_CONTINUE &&
                 (bytes = read(fd, buffer, sizeof(buffer))) > 0)
          {
            if ((http_status = cupsWriteRequestData(http, buffer, (size_t)bytes))
-                   != HTTP_CONTINUE)
+                   != HTTP_STATUS_CONTINUE)
              break;
            else
            {
@@ -1833,28 +1862,36 @@ main(int  argc,                         /* I - Number of command-line args */
            close(fd);
        }
 
-        if (http_status == HTTP_ERROR)
+        if (http_status == HTTP_STATUS_ERROR)
           fprintf(stderr, "DEBUG: Error writing document data for "
                           "Send-Document: %s\n", strerror(httpError(http)));
 
        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_OK_CONFLICT && !job_canceled)
+       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)
@@ -1866,12 +1903,12 @@ main(int  argc,                         /* I - Number of command-line args */
     if (job_canceled)
       break;
 
-    if (ipp_status <= IPP_OK_CONFLICT && argc > 6)
+    if (ipp_status <= IPP_STATUS_OK_CONFLICTING && argc > 6)
     {
       fprintf(stderr, "PAGE: 1 %d\n", copies_sup ? atoi(argv[4]) : 1);
       copies_remaining --;
     }
-    else if ((ipp_status == IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR || 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"))
     {
@@ -1885,9 +1922,9 @@ main(int  argc,                           /* I - Number of command-line args */
 
       goto cleanup;
     }
-    else if (ipp_status == IPP_SERVICE_UNAVAILABLE ||
-             ipp_status == IPP_NOT_POSSIBLE ||
-            ipp_status == IPP_PRINTER_BUSY)
+    else if (ipp_status == IPP_STATUS_ERROR_SERVICE_UNAVAILABLE ||
+             ipp_status == IPP_STATUS_ERROR_NOT_POSSIBLE ||
+            ipp_status == IPP_STATUS_ERROR_BUSY)
     {
       if (argc == 6)
       {
@@ -1903,14 +1940,14 @@ main(int  argc,                         /* I - Number of command-line args */
       }
       continue;
     }
-    else if (ipp_status == IPP_REQUEST_VALUE ||
-             ipp_status == IPP_ERROR_JOB_CANCELED ||
-             ipp_status == IPP_NOT_AUTHORIZED ||
+    else if (ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE ||
+             ipp_status == IPP_STATUS_ERROR_JOB_CANCELED ||
+             ipp_status == IPP_STATUS_ERROR_NOT_AUTHORIZED ||
              ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_INFO_NEEDED ||
              ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_CLOSED ||
              ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_LIMIT_REACHED ||
              ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_AUTHORIZATION_FAILED ||
-             ipp_status == IPP_INTERNAL_ERROR)
+             ipp_status == IPP_STATUS_ERROR_INTERNAL)
     {
      /*
       * Print file is too large, job was canceled, we need new
@@ -1940,7 +1977,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
       goto cleanup;
     }
-    else if (ipp_status == IPP_NOT_FOUND)
+    else if (ipp_status == IPP_STATUS_ERROR_NOT_FOUND)
     {
      /*
       * Printer does not actually implement support for Create-Job/
@@ -1954,7 +1991,7 @@ main(int  argc,                           /* I - Number of command-line args */
       update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
                           "cups-ipp-missing-send-document");
 
-      ipp_status = IPP_INTERNAL_ERROR; /* Force queue to stop */
+      ipp_status = IPP_STATUS_ERROR_INTERNAL;  /* Force queue to stop */
 
       goto cleanup;
     }
@@ -1986,14 +2023,14 @@ main(int  argc,                         /* I - Number of command-line args */
 
       check_printer_state(http, uri, resource, argv[2], version);
 
-      if (cupsLastError() <= IPP_OK_CONFLICT)
+      if (cupsLastError() <= IPP_STATUS_OK_CONFLICTING)
         password_tries = 0;
 
      /*
-      * Build an IPP_GET_JOB_ATTRIBUTES request...
+      * Build an IPP_OP_GET_JOB_ATTRIBUTES request...
       */
 
-      request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
+      request = ippNewRequest(IPP_OP_GET_JOB_ATTRIBUTES);
       ippSetVersion(request, version / 10, version % 10);
 
       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
@@ -2017,11 +2054,11 @@ main(int  argc,                         /* I - Number of command-line args */
       * Do the request...
       */
 
-      httpReconnect(http);
+      httpReconnect2(http, 30000, NULL);
       response   = cupsDoRequest(http, request, resource);
       ipp_status = cupsLastError();
 
-      if (ipp_status == IPP_NOT_FOUND || ipp_status == IPP_NOT_POSSIBLE)
+      if (ipp_status == IPP_STATUS_ERROR_NOT_FOUND || ipp_status == IPP_STATUS_ERROR_NOT_POSSIBLE)
       {
        /*
         * Job has gone away and/or the server has no job history...
@@ -2031,7 +2068,7 @@ main(int  argc,                           /* I - Number of command-line args */
                             "cups-ipp-missing-job-history");
         ippDelete(response);
 
-       ipp_status = IPP_OK;
+       ipp_status = IPP_STATUS_OK;
         break;
       }
 
@@ -2039,25 +2076,25 @@ main(int  argc,                         /* I - Number of command-line args */
              ippErrorString(ipp_status), cupsLastErrorString());
       debug_attributes(response);
 
-      if (ipp_status <= IPP_OK_CONFLICT)
+      if (ipp_status <= IPP_STATUS_OK_CONFLICTING)
        password_tries = 0;
       else
       {
-       if (ipp_status != IPP_SERVICE_UNAVAILABLE &&
-           ipp_status != IPP_PRINTER_BUSY)
+       if (ipp_status != IPP_STATUS_ERROR_SERVICE_UNAVAILABLE &&
+           ipp_status != IPP_STATUS_ERROR_BUSY)
        {
          ippDelete(response);
-          ipp_status = IPP_OK;
+          ipp_status = IPP_STATUS_OK;
           break;
        }
-       else if (ipp_status == IPP_INTERNAL_ERROR)
+       else if (ipp_status == IPP_STATUS_ERROR_INTERNAL)
        {
          waitjob_tries ++;
 
          if (waitjob_tries > 4)
          {
            ippDelete(response);
-           ipp_status = IPP_OK;
+           ipp_status = IPP_STATUS_OK;
            break;
          }
        }
@@ -2073,11 +2110,11 @@ main(int  argc,                         /* I - Number of command-line args */
          */
 
          if (cups_version &&
-             job_state->values[0].integer >= IPP_JOB_PENDING &&
-             job_state->values[0].integer <= IPP_JOB_COMPLETED)
+             job_state->values[0].integer >= IPP_JSTATE_PENDING &&
+             job_state->values[0].integer <= IPP_JSTATE_COMPLETED)
            update_reasons(NULL,
                           remote_job_states[job_state->values[0].integer -
-                                            IPP_JOB_PENDING]);
+                                            IPP_JSTATE_PENDING]);
 
          if ((job_sheets = ippFindAttribute(response, "job-impressions-completed", IPP_TAG_INTEGER)) == NULL)
            job_sheets = ippFindAttribute(response, "job-media-sheets-completed", IPP_TAG_INTEGER);
@@ -2097,9 +2134,9 @@ main(int  argc,                           /* I - Number of command-line args */
            break;
          }
        }
-       else if (ipp_status != IPP_SERVICE_UNAVAILABLE &&
-                ipp_status != IPP_NOT_POSSIBLE &&
-                ipp_status != IPP_PRINTER_BUSY)
+       else if (ipp_status != IPP_STATUS_ERROR_SERVICE_UNAVAILABLE &&
+                ipp_status != IPP_STATUS_ERROR_NOT_POSSIBLE &&
+                ipp_status != IPP_STATUS_ERROR_BUSY)
        {
         /*
          * If the printer does not return a job-state attribute, it does not
@@ -2109,7 +2146,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
          update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
                               "cups-ipp-missing-job-state");
-         ipp_status = IPP_INTERNAL_ERROR;
+         ipp_status = IPP_STATUS_ERROR_INTERNAL;
          break;
        }
       }
@@ -2134,7 +2171,7 @@ main(int  argc,                           /* I - Number of command-line args */
   {
     cancel_job(http, uri, job_id, resource, argv[2], version);
 
-    if (cupsLastError() > IPP_OK_CONFLICT)
+    if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
       _cupsLangPrintFilter(stderr, "ERROR", _("Unable to cancel print job."));
   }
 
@@ -2144,7 +2181,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
   check_printer_state(http, uri, resource, argv[2], version);
 
-  if (cupsLastError() <= IPP_OK_CONFLICT)
+  if (cupsLastError() <= IPP_STATUS_OK_CONFLICTING)
     password_tries = 0;
 
  /*
@@ -2191,9 +2228,9 @@ main(int  argc,                           /* I - Number of command-line args */
   * Return the queue status...
   */
 
-  if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN ||
-      ipp_status == IPP_AUTHENTICATION_CANCELED ||
-      ipp_status <= IPP_OK_CONFLICT)
+  if (ipp_status == IPP_STATUS_ERROR_NOT_AUTHORIZED || ipp_status == IPP_STATUS_ERROR_FORBIDDEN ||
+      ipp_status == IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED ||
+      ipp_status <= IPP_STATUS_OK_CONFLICTING)
     fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required);
 
   if (ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_INFO_NEEDED)
@@ -2205,25 +2242,26 @@ main(int  argc,                         /* I - Number of command-line args */
   else if (ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_AUTHORIZATION_FAILED)
     fputs("JOBSTATE: account-authorization-failed\n", stderr);
 
-  if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN ||
-      ipp_status == IPP_AUTHENTICATION_CANCELED)
+  if (job_canceled)
+    return (CUPS_BACKEND_OK);
+  else if (ipp_status == IPP_STATUS_ERROR_NOT_AUTHORIZED || ipp_status == IPP_STATUS_ERROR_FORBIDDEN || ipp_status == IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED)
     return (CUPS_BACKEND_AUTH_REQUIRED);
   else if (ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_LIMIT_REACHED ||
           ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_INFO_NEEDED ||
           ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_CLOSED ||
           ipp_status == IPP_STATUS_ERROR_CUPS_ACCOUNT_AUTHORIZATION_FAILED)
     return (CUPS_BACKEND_HOLD);
-  else if (ipp_status == IPP_INTERNAL_ERROR)
+  else if (ipp_status == IPP_STATUS_ERROR_INTERNAL)
     return (CUPS_BACKEND_STOP);
-  else if (ipp_status == IPP_CONFLICT || ipp_status == IPP_STATUS_ERROR_REQUEST_ENTITY || ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE)
+  else if (ipp_status == IPP_STATUS_ERROR_CONFLICTING || ipp_status == IPP_STATUS_ERROR_REQUEST_ENTITY || ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE)
     return (CUPS_BACKEND_FAILED);
-  else if (ipp_status == IPP_REQUEST_VALUE ||
+  else if (ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE ||
           ipp_status == IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES ||
-           ipp_status == IPP_DOCUMENT_FORMAT || job_canceled < 0)
+           ipp_status == IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED || job_canceled < 0)
   {
-    if (ipp_status == IPP_REQUEST_VALUE)
+    if (ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE)
       _cupsLangPrintFilter(stderr, "ERROR", _("Print job too large."));
-    else if (ipp_status == IPP_DOCUMENT_FORMAT)
+    else if (ipp_status == IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED)
       _cupsLangPrintFilter(stderr, "ERROR",
                            _("Printer cannot print supplied content."));
     else if (ipp_status == IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES)
@@ -2234,7 +2272,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
     return (CUPS_BACKEND_CANCEL);
   }
-  else if (ipp_status > IPP_OK_CONFLICT && ipp_status != IPP_ERROR_JOB_CANCELED)
+  else if (ipp_status > IPP_STATUS_OK_CONFLICTING && ipp_status != IPP_STATUS_ERROR_JOB_CANCELED)
     return (CUPS_BACKEND_RETRY_CURRENT);
   else
     return (CUPS_BACKEND_OK);
@@ -2258,7 +2296,7 @@ cancel_job(http_t     *http,              /* I - HTTP connection */
 
   _cupsLangPrintFilter(stderr, "INFO", _("Canceling print job."));
 
-  request = ippNewRequest(IPP_CANCEL_JOB);
+  request = ippNewRequest(IPP_OP_CANCEL_JOB);
   ippSetVersion(request, version / 10, version % 10);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
@@ -2292,7 +2330,7 @@ check_printer_state(
   ipp_t                *request,               /* IPP request */
                *response;              /* IPP response */
   ipp_attribute_t *attr;               /* Attribute in response */
-  ipp_pstate_t printer_state = IPP_PRINTER_STOPPED;
+  ipp_pstate_t printer_state = IPP_PSTATE_STOPPED;
                                        /* Current printer-state */
 
 
@@ -2300,7 +2338,7 @@ check_printer_state(
   * Send a Get-Printer-Attributes request and log the results...
   */
 
-  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+  request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
   ippSetVersion(request, version / 10, version % 10);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
@@ -2426,14 +2464,14 @@ monitor_printer(
 
   monitor->job_reasons = 0;
 
-  while (monitor->job_state < IPP_JOB_CANCELED && !job_canceled)
+  while (monitor->job_state < IPP_JSTATE_CANCELED && !job_canceled)
   {
    /*
     * Reconnect to the printer as needed...
     */
 
     if (httpGetFd(http) < 0)
-      httpReconnect(http);
+      httpReconnect2(http, 30000, NULL);
 
     if (httpGetFd(http) >= 0)
     {
@@ -2445,7 +2483,7 @@ monitor_printer(
                                                    monitor->resource,
                                                   monitor->user,
                                                   monitor->version);
-      if (cupsLastError() <= IPP_OK_CONFLICT)
+      if (cupsLastError() <= IPP_STATUS_OK_CONFLICTING)
         password_tries = 0;
 
       if (monitor->job_id == 0 && monitor->create_job)
@@ -2462,13 +2500,13 @@ monitor_printer(
       */
 
       job_op  = (monitor->job_id > 0 && monitor->get_job_attrs) ?
-                    IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS;
+                    IPP_OP_GET_JOB_ATTRIBUTES : IPP_OP_GET_JOBS;
       request = ippNewRequest(job_op);
       ippSetVersion(request, monitor->version / 10, monitor->version % 10);
 
       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                   NULL, monitor->uri);
-      if (job_op == IPP_GET_JOB_ATTRIBUTES)
+      if (job_op == IPP_OP_GET_JOB_ATTRIBUTES)
        ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
                      monitor->job_id);
 
@@ -2489,16 +2527,16 @@ monitor_printer(
       fprintf(stderr, "DEBUG: (monitor) %s: %s (%s)\n", ippOpString(job_op),
              ippErrorString(cupsLastError()), cupsLastErrorString());
 
-      if (cupsLastError() <= IPP_OK_CONFLICT)
+      if (cupsLastError() <= IPP_STATUS_OK_CONFLICTING)
         password_tries = 0;
 
-      if (job_op == IPP_GET_JOB_ATTRIBUTES)
+      if (job_op == IPP_OP_GET_JOB_ATTRIBUTES)
       {
        if ((attr = ippFindAttribute(response, "job-state",
                                     IPP_TAG_ENUM)) != NULL)
          monitor->job_state = (ipp_jstate_t)attr->values[0].integer;
        else
-         monitor->job_state = IPP_JOB_COMPLETED;
+         monitor->job_state = IPP_JSTATE_COMPLETED;
       }
       else if (response)
       {
@@ -2506,7 +2544,7 @@ monitor_printer(
         {
           job_id    = 0;
           job_name  = NULL;
-          job_state = IPP_JOB_PENDING;
+          job_state = IPP_JSTATE_PENDING;
           job_user  = NULL;
 
           while (attr && attr->group_tag != IPP_TAG_JOB)
@@ -2548,12 +2586,11 @@ monitor_printer(
         }
       }
 
-      fprintf(stderr, "DEBUG: (monitor) job-state = %s\n",
-              ippEnumString("job-state", monitor->job_state));
+      fprintf(stderr, "DEBUG: (monitor) job-state = %s\n", ippEnumString("job-state", (int)monitor->job_state));
 
       if (!job_canceled &&
-          (monitor->job_state == IPP_JOB_CANCELED ||
-          monitor->job_state == IPP_JOB_ABORTED))
+          (monitor->job_state == IPP_JSTATE_CANCELED ||
+          monitor->job_state == IPP_JSTATE_ABORTED))
       {
        job_canceled = -1;
        fprintf(stderr, "DEBUG: (monitor) job_canceled = -1\n");
@@ -2630,12 +2667,11 @@ monitor_printer(
 
       ippDelete(response);
 
-      fprintf(stderr, "DEBUG: (monitor) job-state = %s\n",
-              ippEnumString("job-state", monitor->job_state));
+      fprintf(stderr, "DEBUG: (monitor) job-state = %s\n", ippEnumString("job-state", (int)monitor->job_state));
 
       if (!job_canceled &&
-          (monitor->job_state == IPP_JOB_CANCELED ||
-          monitor->job_state == IPP_JOB_ABORTED))
+          (monitor->job_state == IPP_JSTATE_CANCELED ||
+          monitor->job_state == IPP_JSTATE_ABORTED))
        job_canceled = -1;
     }
 
@@ -2657,14 +2693,14 @@ monitor_printer(
   if (job_canceled > 0 && monitor->job_id > 0)
   {
     if (httpGetFd(http) < 0)
-      httpReconnect(http);
+      httpReconnect2(http, 30000, NULL);
 
     if (httpGetFd(http) >= 0)
     {
       cancel_job(http, monitor->uri, monitor->job_id, monitor->resource,
                  monitor->user, monitor->version);
 
-      if (cupsLastError() > IPP_OK_CONFLICT)
+      if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
       {
        fprintf(stderr, "DEBUG: (monitor) cancel_job() = %s\n", cupsLastErrorString());
        _cupsLangPrintFilter(stderr, "ERROR", _("Unable to cancel print job."));
@@ -2740,7 +2776,7 @@ new_request(
     fprintf(stderr, "DEBUG: job-name=\"%s\"\n", title);
   }
 
-  if (format && op != IPP_CREATE_JOB)
+  if (format && op != IPP_OP_CREATE_JOB)
   {
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, format);
     fprintf(stderr, "DEBUG: document-format=\"%s\"\n", format);
@@ -2780,7 +2816,7 @@ new_request(
        char    phone[1024],            /* Phone number string */
                *ptr,                   /* Pointer into string */
                tel_uri[1024];          /* tel: URI */
-        static const char * const allowed = "0123456789#*-+.()";
+        static const char * const allowed = "0123456789#*-+.()pw";
                                        /* Allowed characters */
 
         destination = ippNew();
@@ -2793,7 +2829,9 @@ new_request(
         _httpDecodeURI(phone, keyword, sizeof(phone));
         for (ptr = phone; *ptr;)
        {
-         if (!strchr(allowed, *ptr))
+         if (*ptr == ',')
+           *ptr = 'p';
+         else if (!strchr(allowed, *ptr))
            _cups_strcpy(ptr, ptr + 1);
          else
            ptr ++;
@@ -3579,6 +3617,8 @@ update_reasons(ipp_attribute_t *attr,     /* I - printer-state-reasons or NULL */
     }
   }
 
+  cupsArrayDelete(new_reasons);
+
   _cupsMutexUnlock(&report_mutex);
 
  /*