]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge changes from CUPS 1.5svn-r9041.
[thirdparty/cups.git] / scheduler / ipp.c
index 668da3ee197f1cf8e8049451ba832a7f9603b60a..c4604fc61e8e1a82399b497f52760f94e8fea1fa 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
- *   Copyright 2007-2009 by Apple Inc.
+ *   Copyright 2007-2010 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   This file contains Kerberos support code, copyright 2006 by
 #include "cupsd.h"
 #include <cups/ppd-private.h>
 
-#ifdef HAVE_LIBPAPER
-#  include <paper.h>
-#endif /* HAVE_LIBPAPER */
-
 #ifdef __APPLE__
 #  include <ApplicationServices/ApplicationServices.h>
 #  include <CoreFoundation/CoreFoundation.h>
@@ -295,17 +291,31 @@ cupsdProcessIPPRequest(
                  con->request->request.any.version[1]);
 
     send_ipp_status(con, IPP_VERSION_NOT_SUPPORTED,
-                    _("Bad request version number %d.%d!"),
+                    _("Bad request version number %d.%d"),
                    con->request->request.any.version[0],
                    con->request->request.any.version[1]);
   }
+  else if (con->request->request.any.request_id < 1)
+  {
+   /*
+    * Return an error, since request IDs must be between 1 and 2^31-1
+    */
+
+    cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
+                  "%04X %s Bad request ID %d",
+                 IPP_BAD_REQUEST, con->http.hostname,
+                  con->request->request.any.request_id);
+
+    send_ipp_status(con, IPP_BAD_REQUEST, _("Bad request ID %d"),
+                   con->request->request.any.request_id);
+  }
   else if (!con->request->attrs)
   {
     cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
                   "%04X %s No attributes in request",
                  IPP_BAD_REQUEST, con->http.hostname);
 
-    send_ipp_status(con, IPP_BAD_REQUEST, _("No attributes in request!"));
+    send_ipp_status(con, IPP_BAD_REQUEST, _("No attributes in request"));
   }
   else
   {
@@ -328,7 +338,7 @@ cupsdProcessIPPRequest(
                      IPP_BAD_REQUEST, con->http.hostname);
 
        send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("Attribute groups are out of order (%x < %x)!"),
+                       _("Attribute groups are out of order (%x < %x)"),
                        attr->group_tag, group);
        break;
       }
@@ -346,7 +356,8 @@ cupsdProcessIPPRequest(
       */
 
       attr = con->request->attrs;
-      if (attr && !strcmp(attr->name, "attributes-charset") &&
+      if (attr && attr->name &&
+          !strcmp(attr->name, "attributes-charset") &&
          (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET)
        charset = attr;
       else
@@ -355,7 +366,8 @@ cupsdProcessIPPRequest(
       if (attr)
         attr = attr->next;
 
-      if (attr && !strcmp(attr->name, "attributes-natural-language") &&
+      if (attr && attr->name &&
+          !strcmp(attr->name, "attributes-natural-language") &&
          (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE)
        language = attr;
       else
@@ -378,7 +390,7 @@ cupsdProcessIPPRequest(
                     charset->values[0].string.text);
       else
        ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                    "attributes-charset", NULL, DefaultCharset);
+                    "attributes-charset", NULL, "utf-8");
 
       if (language)
        ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
@@ -396,14 +408,14 @@ cupsdProcessIPPRequest(
         * Bad character set...
        */
 
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Unsupported character set \"%s\"!",
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Unsupported character set \"%s\"",
                        charset->values[0].string.text);
        cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
                      "%04X %s Unsupported attributes-charset value \"%s\"",
                      IPP_CHARSET, con->http.hostname,
                      charset->values[0].string.text);
        send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("Unsupported character set \"%s\"!"),
+                       _("Unsupported character set \"%s\""),
                        charset->values[0].string.text);
       }
       else if (!charset || !language ||
@@ -423,7 +435,7 @@ cupsdProcessIPPRequest(
         if (!charset)
        {
          cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Missing attributes-charset attribute!");
+                         "Missing attributes-charset attribute");
 
          cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
                        "%04X %s Missing attributes-charset attribute",
@@ -433,7 +445,7 @@ cupsdProcessIPPRequest(
         if (!language)
        {
          cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Missing attributes-natural-language attribute!");
+                         "Missing attributes-natural-language attribute");
 
          cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
                        "%04X %s Missing attributes-natural-language attribute",
@@ -444,7 +456,7 @@ cupsdProcessIPPRequest(
        {
          cupsdLogMessage(CUPSD_LOG_ERROR,
                          "Missing printer-uri, job-uri, or ppd-name "
-                         "attribute!");
+                         "attribute");
 
          cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
                        "%04X %s Missing printer-uri, job-uri, or ppd-name "
@@ -462,7 +474,7 @@ cupsdProcessIPPRequest(
        cupsdLogMessage(CUPSD_LOG_DEBUG, "End of attributes...");
 
        send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("Missing required attributes!"));
+                       _("Missing required attributes"));
       }
       else
       {
@@ -686,7 +698,7 @@ cupsdProcessIPPRequest(
                            ippOpString(con->request->request.op.operation_id));
 
               send_ipp_status(con, IPP_OPERATION_NOT_SUPPORTED,
-                             _("%s not supported!"),
+                             _("%s not supported"),
                              ippOpString(
                                  con->request->request.op.operation_id));
              break;
@@ -711,6 +723,11 @@ cupsdProcessIPPRequest(
                    uri ? uri->values[0].string.text : "no URI",
                    con->http.hostname);
 
+    if (LogLevel == CUPSD_LOG_DEBUG2)
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                     "cupsdProcessIPPRequest: ippLength(response)=%ld",
+                     (long)ippLength(con->response));
+
     if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
     {
 #ifdef CUPSD_USE_CHUNKING
@@ -887,6 +904,9 @@ accept_jobs(cupsd_client_t  *con,   /* I - Client connection */
 
   cupsdAddPrinterHistory(printer);
 
+  cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
+                "Now accepting jobs.");
+
   if (dtype & CUPS_PRINTER_CLASS)
   {
     cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
@@ -993,7 +1013,7 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("A printer named \"%s\" already exists!"),
+                      _("A printer named \"%s\" already exists"),
                      resource + 9);
       return;
     }
@@ -1085,7 +1105,8 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
     cupsdSetString(&pclass->info, attr->values[0].string.text);
 
   if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
-                               IPP_TAG_BOOLEAN)) != NULL)
+                               IPP_TAG_BOOLEAN)) != NULL &&
+      attr->values[0].boolean != pclass->accepting)
   {
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s printer-is-accepting-jobs to %d (was %d.)",
@@ -1093,6 +1114,9 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
 
     pclass->accepting = attr->values[0].boolean;
     cupsdAddPrinterHistory(pclass);
+
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, pclass, NULL, "%s accepting jobs.",
+                 pclass->accepting ? "Now" : "No longer");
   }
 
   if ((attr = ippFindAttribute(con->request, "printer-is-shared",
@@ -1115,7 +1139,7 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
         attr->values[0].integer != IPP_PRINTER_STOPPED)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Attempt to set %s printer-state to bad value %d!"),
+                      _("Attempt to set %s printer-state to bad value %d"),
                       pclass->name, attr->values[0].integer);
       return;
     }
@@ -1137,6 +1161,9 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
     strlcpy(pclass->state_message, attr->values[0].string.text,
             sizeof(pclass->state_message));
     cupsdAddPrinterHistory(pclass);
+
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, pclass, NULL, "%s",
+                  pclass->state_message);
   }
   if ((attr = ippFindAttribute(con->request, "member-uris",
                                IPP_TAG_URI)) != NULL)
@@ -1173,6 +1200,12 @@ add_class(cupsd_client_t  *con,          /* I - Client connection */
                        _("The printer or class was not found."));
        return;
       }
+      else if (dtype & CUPS_PRINTER_CLASS)
+      {
+        send_ipp_status(con, IPP_BAD_REQUEST,
+                       _("Nested classes are not allowed"));
+        return;
+      }
 
      /*
       * Add it to the class...
@@ -1197,30 +1230,21 @@ add_class(cupsd_client_t  *con,         /* I - Client connection */
 
   if (need_restart_job && pclass->job)
   {
-    cupsd_job_t *job;
-
    /*
-    * Stop the current job and then restart it below...
+    * Reset the current job to a "pending" status...
     */
 
-    job = (cupsd_job_t *)pclass->job;
-
-    cupsdStopJob(job, 1);
-
-    job->state->values[0].integer = IPP_JOB_PENDING;
-    job->state_value              = IPP_JOB_PENDING;
+    cupsdSetJobState(pclass->job, IPP_JOB_PENDING, CUPSD_JOB_FORCE,
+                     "Job restarted because the class was modified.");
   }
 
-  if (need_restart_job)
-    cupsdCheckJobs();
-
   cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
 
   if (modify)
   {
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, pclass, NULL,
-                  "Class \"%s\" modified by \"%s\".", pclass->name,
-                 get_username(con));
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED | CUPSD_EVENT_PRINTER_CONFIG,
+                 pclass, NULL, "Class \"%s\" modified by \"%s\".",
+                 pclass->name, get_username(con));
 
     cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" modified by \"%s\".",
                     pclass->name, get_username(con));
@@ -1229,9 +1253,9 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
   {
     cupsdAddPrinterHistory(pclass);
 
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, pclass, NULL,
-                  "New class \"%s\" added by \"%s\".", pclass->name,
-                 get_username(con));
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED | CUPSD_EVENT_PRINTER_CONFIG,
+                 pclass, NULL, "New class \"%s\" added by \"%s\".",
+                 pclass->name, get_username(con));
 
     cupsdLogMessage(CUPSD_LOG_INFO, "New class \"%s\" added by \"%s\".",
                     pclass->name, get_username(con));
@@ -1280,11 +1304,12 @@ add_file(cupsd_client_t *con,           /* I - Connection to client */
 
   if (!compressions || !filetypes)
   {
-    cupsdCancelJob(job, 1, IPP_JOB_ABORTED);
+    cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_PURGE,
+                     "Job aborted because the scheduler ran out of memory.");
 
     if (con)
       send_ipp_status(con, IPP_INTERNAL_ERROR,
-                     _("Unable to allocate memory for file types!"));
+                     _("Unable to allocate memory for file types"));
 
     return (-1);
   }
@@ -1317,12 +1342,16 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
                *auth_info;             /* auth-info attribute */
   const char   *val;                   /* Default option value */
   int          priority;               /* Job priority */
-  char         *title;                 /* Job name/title */
   cupsd_job_t  *job;                   /* Current job */
   char         job_uri[HTTP_MAX_URI];  /* Job URI */
   int          kbytes;                 /* Size of print file */
   int          i;                      /* Looping var */
   int          lowerpagerange;         /* Page range bound */
+  const char   *ppd;                   /* PPD keyword for media selection */
+  int          exact;                  /* Did we have an exact match? */
+  ipp_attribute_t *media_col,          /* media-col attribute */
+               *media_margin;          /* media-*-margin attribute */
+  ipp_t                *unsup_col;             /* media-col in unsupported response */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
@@ -1339,7 +1368,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
       strcasecmp(con->http.hostname, ServerName))
   {
     send_ipp_status(con, IPP_NOT_AUTHORIZED,
-                    _("The printer or class is not shared!"));
+                    _("The printer or class is not shared"));
     return (NULL);
   }
 
@@ -1354,9 +1383,9 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
     send_http_error(con, status, printer);
     return (NULL);
   }
-  else if (printer->num_auth_info_required > 0 &&
-           strcmp(printer->auth_info_required[0], "none") &&
-           !con->username[0] && !auth_info)
+  else if (printer->num_auth_info_required == 1 &&
+           !strcmp(printer->auth_info_required[0], "negotiate") &&
+           !con->username[0])
   {
     send_http_error(con, HTTP_UNAUTHORIZED, printer);
     return (NULL);
@@ -1402,7 +1431,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
              filetype->type);
 
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
-                    _("Unsupported format \'%s\'!"), mimetype);
+                    _("Unsupported format \'%s\'"), mimetype);
 
     ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
                  "document-format", NULL, mimetype);
@@ -1429,14 +1458,14 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
     if (attr->value_tag != IPP_TAG_KEYWORD &&
         attr->value_tag != IPP_TAG_NAME)
     {
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-sheets value type!"));
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-sheets value type"));
       return (NULL);
     }
 
     if (attr->num_values > 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Too many job-sheets values (%d > 2)!"),
+                      _("Too many job-sheets values (%d > 2)"),
                      attr->num_values);
       return (NULL);
     }
@@ -1445,7 +1474,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
       if (strcmp(attr->values[i].string.text, "none") &&
           !cupsdFindBanner(attr->values[i].string.text))
       {
-       send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-sheets value \"%s\"!"),
+       send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-sheets value \"%s\""),
                        attr->values[i].string.text);
        return (NULL);
       }
@@ -1488,6 +1517,62 @@ add_job(cupsd_client_t  *con,            /* I - Client connection */
     }
   }
 
+ /*
+  * Do media selection as needed...
+  */
+
+  if (!ippFindAttribute(con->request, "InputSlot", IPP_TAG_ZERO) &&
+      (ppd = _pwgGetInputSlot(printer->pwg, con->request, NULL)) != NULL)
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "InputSlot", NULL,
+                 ppd);
+
+  if (!ippFindAttribute(con->request, "MediaType", IPP_TAG_ZERO) &&
+      (ppd = _pwgGetMediaType(printer->pwg, con->request, NULL)) != NULL)
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "MediaType", NULL,
+                 ppd);
+
+  if (!ippFindAttribute(con->request, "PageSize", IPP_TAG_ZERO) &&
+      (ppd = _pwgGetPageSize(printer->pwg, con->request, NULL, &exact)) != NULL)
+  {
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "PageSize", NULL,
+                 ppd);
+
+    if (!exact &&
+        (media_col = ippFindAttribute(con->request, "media-col",
+                                     IPP_TAG_BEGIN_COLLECTION)) != NULL)
+    {
+      send_ipp_status(con, IPP_OK_SUBST, _("Unsupported margins."));
+
+      unsup_col = ippNew();
+      ippAddCollection(con->response, IPP_TAG_UNSUPPORTED_GROUP, "media-col",
+                       unsup_col);
+
+      if ((media_margin = ippFindAttribute(media_col->values[0].collection,
+                                           "media-bottom-margin",
+                                          IPP_TAG_INTEGER)) != NULL)
+        ippAddInteger(unsup_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
+                     "media-bottom-margin", media_margin->values[0].integer);
+
+      if ((media_margin = ippFindAttribute(media_col->values[0].collection,
+                                           "media-left-margin",
+                                          IPP_TAG_INTEGER)) != NULL)
+        ippAddInteger(unsup_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
+                     "media-left-margin", media_margin->values[0].integer);
+
+      if ((media_margin = ippFindAttribute(media_col->values[0].collection,
+                                           "media-right-margin",
+                                          IPP_TAG_INTEGER)) != NULL)
+        ippAddInteger(unsup_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
+                     "media-right-margin", media_margin->values[0].integer);
+
+      if ((media_margin = ippFindAttribute(media_col->values[0].collection,
+                                           "media-top-margin",
+                                          IPP_TAG_INTEGER)) != NULL)
+        ippAddInteger(unsup_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
+                     "media-top-margin", media_margin->values[0].integer);
+    }
+  }
+
  /*
   * Make sure we aren't over our limit...
   */
@@ -1532,17 +1617,14 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
                   priority);
   }
 
-  if ((attr = ippFindAttribute(con->request, "job-name",
-                               IPP_TAG_NAME)) != NULL)
-    title = attr->values[0].string.text;
-  else
+  if (!ippFindAttribute(con->request, "job-name", IPP_TAG_NAME))
     ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
-                 title = "Untitled");
+                 "Untitled");
 
   if ((job = cupsdAddJob(priority, printer->name)) == NULL)
   {
     send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("Unable to add job for destination \"%s\"!"),
+                    _("Unable to add job for destination \"%s\""),
                    printer->name);
     return (NULL);
   }
@@ -1691,8 +1773,6 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
                               "job-media-sheets-completed", 0);
   ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL,
                printer->uri);
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
-               title);
 
   if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
                                IPP_TAG_INTEGER)) != NULL)
@@ -1712,21 +1792,20 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
     attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
                         "job-hold-until", NULL, val);
   }
-  if (attr && strcmp(attr->values[0].string.text, "no-hold") &&
-      !(printer->type & CUPS_PRINTER_REMOTE))
+  if (attr && strcmp(attr->values[0].string.text, "no-hold"))
   {
    /*
     * Hold job until specified time...
     */
 
-    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+    cupsdSetJobHoldUntil(job, attr->values[0].string.text, 0);
 
     job->state->values[0].integer = IPP_JOB_HELD;
     job->state_value              = IPP_JOB_HELD;
   }
   else if (job->attrs->request.op.operation_id == IPP_CREATE_JOB)
   {
-    job->hold_until               = time(NULL) + 60;
+    job->hold_until               = time(NULL) + MultipleOperationTimeout;
     job->state->values[0].integer = IPP_JOB_HELD;
     job->state_value              = IPP_JOB_HELD;
   }
@@ -1877,7 +1956,9 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
 
       if ((kbytes = copy_banner(con, job, attr->values[0].string.text)) < 0)
       {
-        cupsdDeleteJob(job);
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_PURGE,
+                        "Aborting job because the start banner could not be "
+                        "copied.");
         return (NULL);
       }
 
@@ -2073,7 +2154,7 @@ add_job_subscriptions(
                            resource, sizeof(resource)) < HTTP_URI_OK)
         {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("Bad notify-recipient-uri URI \"%s\"!"), recipient);
+                         _("Bad notify-recipient-uri URI \"%s\""), recipient);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_URI_SCHEME);
          return;
@@ -2085,7 +2166,7 @@ add_job_subscriptions(
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
                          _("notify-recipient-uri URI \"%s\" uses unknown "
-                           "scheme!"), recipient);
+                           "scheme"), recipient);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_URI_SCHEME);
          return;
@@ -2094,7 +2175,7 @@ add_job_subscriptions(
         if (!strcmp(scheme, "rss") && !check_rss_recipient(recipient))
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("notify-recipient-uri URI \"%s\" is already used!"),
+                         _("notify-recipient-uri URI \"%s\" is already used"),
                          recipient);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_ATTRIBUTES);
@@ -2109,7 +2190,7 @@ add_job_subscriptions(
         if (strcmp(pullmethod, "ippget"))
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("Bad notify-pull-method \"%s\"!"), pullmethod);
+                         _("Bad notify-pull-method \"%s\""), pullmethod);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_ATTRIBUTES);
          return;
@@ -2121,7 +2202,7 @@ add_job_subscriptions(
               strcmp(attr->values[0].string.text, "utf-8"))
       {
         send_ipp_status(con, IPP_CHARSET,
-                       _("Character set \"%s\" not supported!"),
+                       _("Character set \"%s\" not supported"),
                        attr->values[0].string.text);
        return;
       }
@@ -2130,7 +2211,7 @@ add_job_subscriptions(
                strcmp(attr->values[0].string.text, DefaultLanguage)))
       {
         send_ipp_status(con, IPP_CHARSET,
-                       _("Language \"%s\" not supported!"),
+                       _("Language \"%s\" not supported"),
                        attr->values[0].string.text);
        return;
       }
@@ -2141,7 +2222,7 @@ add_job_subscriptions(
        {
           send_ipp_status(con, IPP_REQUEST_VALUE,
                          _("The notify-user-data value is too large "
-                           "(%d > 63 octets)!"),
+                           "(%d > 63 octets)"),
                          attr->values[0].unknown.length);
          return;
        }
@@ -2191,6 +2272,9 @@ add_job_subscriptions(
       ippAddSeparator(con->response);
       ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
                    "notify-subscription-id", sub->id);
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Added subscription %d for job %d",
+                      sub->id, job->id);
     }
 
     if (attr)
@@ -2308,8 +2392,9 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
                dstfile[1024];          /* Destination Script/PPD file */
   int          modify;                 /* Non-zero if we are modifying */
   char         newname[IPP_MAX_NAME];  /* New printer name */
-  int          need_restart_job;       /* Need to restart job? */
-  int          set_device_uri,         /* Did we set the device URI? */
+  int          changed_driver,         /* Changed the PPD/interface script? */
+               need_restart_job,       /* Need to restart job? */
+               set_device_uri,         /* Did we set the device URI? */
                set_port_monitor;       /* Did we set the port monitor? */
 
 
@@ -2370,7 +2455,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("A class named \"%s\" already exists!"),
+                      _("A class named \"%s\" already exists"),
                      resource + 10);
       return;
     }
@@ -2453,6 +2538,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   * Look for attributes and copy them over as needed...
   */
 
+  changed_driver   = 0;
   need_restart_job = 0;
 
   if ((attr = ippFindAttribute(con->request, "printer-location",
@@ -2488,7 +2574,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
 
     if (uri_status < HTTP_URI_OK)
     {
-      send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
+      send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\""),
                      attr->values[0].string.text);
       cupsdLogMessage(CUPSD_LOG_DEBUG,
                       "add_printer: httpSeparateURI returned %d", uri_status);
@@ -2528,7 +2614,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
         * Could not find device in list!
        */
 
-       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri scheme \"%s\"!"),
+       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri scheme \"%s\""),
                        scheme);
        return;
       }
@@ -2572,7 +2658,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
 
     if (!supported || i >= supported->num_values)
     {
-      send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
+      send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\""),
                      attr->values[0].string.text);
       return;
     }
@@ -2591,7 +2677,8 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   }
 
   if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
-                               IPP_TAG_BOOLEAN)) != NULL)
+                               IPP_TAG_BOOLEAN)) != NULL &&
+      attr->values[0].boolean != printer->accepting)
   {
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s printer-is-accepting-jobs to %d (was %d.)",
@@ -2599,6 +2686,10 @@ add_printer(cupsd_client_t  *con,        /* I - Client connection */
 
     printer->accepting = attr->values[0].boolean;
     cupsdAddPrinterHistory(printer);
+
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
+                  "%s accepting jobs.",
+                 printer->accepting ? "Now" : "No longer");
   }
 
   if ((attr = ippFindAttribute(con->request, "printer-is-shared",
@@ -2620,7 +2711,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
     if (attr->values[0].integer != IPP_PRINTER_IDLE &&
         attr->values[0].integer != IPP_PRINTER_STOPPED)
     {
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad printer-state value %d!"),
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad printer-state value %d"),
                       attr->values[0].integer);
       return;
     }
@@ -2636,12 +2727,16 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
       cupsdSetPrinterState(printer, (ipp_pstate_t)(attr->values[0].integer), 0);
     }
   }
+
   if ((attr = ippFindAttribute(con->request, "printer-state-message",
                                IPP_TAG_TEXT)) != NULL)
   {
     strlcpy(printer->state_message, attr->values[0].string.text,
             sizeof(printer->state_message));
     cupsdAddPrinterHistory(printer);
+
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL, "%s",
+                  printer->state_message);
   }
 
   if ((attr = ippFindAttribute(con->request, "printer-state-reasons",
@@ -2651,7 +2746,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
             (int)(sizeof(printer->reasons) / sizeof(printer->reasons[0])))
     {
       send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("Too many printer-state-reasons values (%d > %d)!"),
+                      _("Too many printer-state-reasons values (%d > %d)"),
                      attr->num_values,
                      (int)(sizeof(printer->reasons) /
                            sizeof(printer->reasons[0])));
@@ -2669,8 +2764,9 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
 
       printer->reasons[printer->num_reasons] =
           _cupsStrRetain(attr->values[i].string.text);
+      printer->num_reasons ++;
 
-      if (!strcmp(printer->reasons[printer->num_reasons], "paused") &&
+      if (!strcmp(attr->values[i].string.text, "paused") &&
           printer->state != IPP_PRINTER_STOPPED)
       {
        cupsdLogMessage(CUPSD_LOG_INFO,
@@ -2678,12 +2774,13 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
                        printer->name, IPP_PRINTER_STOPPED, printer->state);
        cupsdStopPrinter(printer, 0);
       }
-
-      printer->num_reasons ++;
     }
 
     if (PrintcapFormat == PRINTCAP_PLIST)
       cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
+                  "Printer \"%s\" state changed.", printer->name);
   }
 
   set_printer_defaults(con, printer);
@@ -2706,6 +2803,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   if (con->filename)
   {
     need_restart_job = 1;
+    changed_driver   = 1;
 
     strlcpy(srcfile, con->filename, sizeof(srcfile));
 
@@ -2745,13 +2843,13 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
        if (copy_file(srcfile, dstfile))
        {
           send_ipp_status(con, IPP_INTERNAL_ERROR,
-                         _("Unable to copy interface script - %s!"),
+                         _("Unable to copy interface script - %s"),
                          strerror(errno));
          return;
        }
 
        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                       "Copied interface script successfully!");
+                       "Copied interface script successfully");
        chmod(dstfile, 0755);
       }
 
@@ -2768,26 +2866,14 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
        if (copy_file(srcfile, dstfile))
        {
           send_ipp_status(con, IPP_INTERNAL_ERROR,
-                         _("Unable to copy PPD file - %s!"),
+                         _("Unable to copy PPD file - %s"),
                          strerror(errno));
          return;
        }
 
        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                       "Copied PPD file successfully!");
+                       "Copied PPD file successfully");
        chmod(dstfile, 0644);
-
-#ifdef __APPLE__
-       /*
-        * (Re)register color profiles...
-       */
-
-        if (!RunUser)
-       {
-         apple_unregister_profiles(printer);
-         apple_register_profiles(printer);
-        }
-#endif /* __APPLE__ */
       }
       else
       {
@@ -2804,6 +2890,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
                                     IPP_TAG_NAME)) != NULL)
   {
     need_restart_job = 1;
+    changed_driver   = 1;
 
     if (!strcmp(attr->values[0].string.text, "raw"))
     {
@@ -2834,26 +2921,44 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
 
       if (copy_model(con, attr->values[0].string.text, dstfile))
       {
-        send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file!"));
+        send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file"));
        return;
       }
 
       cupsdLogMessage(CUPSD_LOG_DEBUG,
-                     "Copied PPD file successfully!");
+                     "Copied PPD file successfully");
       chmod(dstfile, 0644);
+    }
+  }
+
+  if (changed_driver)
+  {
+   /*
+    * If we changed the PPD/interface script, then remove the printer's cache
+    * file...
+    */
+
+    char cache_name[1024];             /* Cache filename for printer attrs */
+
+    snprintf(cache_name, sizeof(cache_name), "%s/%s.ipp2", CacheDir,
+             printer->name);
+    unlink(cache_name);
+
+    snprintf(cache_name, sizeof(cache_name), "%s/%s.pwg", CacheDir,
+             printer->name);
+    unlink(cache_name);
 
 #ifdef __APPLE__
-     /*
-      * (Re)register color profiles...
-      */
+   /*
+    * (Re)register color profiles...
+    */
 
-      if (!RunUser)
-      {
-       apple_unregister_profiles(printer);
-       apple_register_profiles(printer);
-      }
-#endif /* __APPLE__ */
+    if (!RunUser)
+    {
+      apple_unregister_profiles(printer);
+      apple_register_profiles(printer);
     }
+#endif /* __APPLE__ */
   }
 
  /*
@@ -2907,30 +3012,21 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
 
   if (need_restart_job && printer->job)
   {
-    cupsd_job_t *job;
-
    /*
-    * Stop the current job and then restart it below...
+    * Restart the current job...
     */
 
-    job = (cupsd_job_t *)printer->job;
-
-    cupsdStopJob(job, 1);
-
-    job->state->values[0].integer = IPP_JOB_PENDING;
-    job->state_value              = IPP_JOB_PENDING;
+    cupsdSetJobState(printer->job, IPP_JOB_PENDING, CUPSD_JOB_FORCE,
+                     "Job restarted because the printer was modified.");
   }
 
-  if (need_restart_job)
-    cupsdCheckJobs();
-
   cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
 
   if (modify)
   {
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Printer \"%s\" modified by \"%s\".", printer->name,
-                 get_username(con));
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED | CUPSD_EVENT_PRINTER_CONFIG,
+                  printer, NULL, "Printer \"%s\" modified by \"%s\".",
+                 printer->name, get_username(con));
 
     cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".",
                     printer->name, get_username(con));
@@ -2939,9 +3035,9 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   {
     cupsdAddPrinterHistory(printer);
 
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, printer, NULL,
-                  "New printer \"%s\" added by \"%s\".", printer->name,
-                 get_username(con));
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED | CUPSD_EVENT_PRINTER_CONFIG,
+                  printer, NULL, "New printer \"%s\" added by \"%s\".",
+                 printer->name, get_username(con));
 
     cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".",
                     printer->name, get_username(con));
@@ -2967,8 +3063,7 @@ add_printer_state_reasons(
 
   if (p->num_reasons == 0)
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                 "printer-state-reasons", NULL,
-                p->state == IPP_PRINTER_STOPPED ? "paused" : "none");
+                 "printer-state-reasons", NULL, "none");
   else
     ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                   "printer-state-reasons", p->num_reasons, NULL,
@@ -3187,7 +3282,7 @@ apple_register_profiles(
       num_profiles ++;
     }
 
-  
+
  /*
   * If we have profiles, add them...
   */
@@ -3233,7 +3328,7 @@ apple_register_profiles(
        snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value);
        q2_attr = ppdFindAttr(ppd, q_keyword, NULL);
       }
-      else 
+      else
        q2_attr = ppdFindAttr(ppd, "DefaultMediaType", NULL);
 
       if (q2_attr && q2_attr->value && q2_attr->value[0])
@@ -3247,7 +3342,7 @@ apple_register_profiles(
        snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value);
        q3_attr = ppdFindAttr(ppd, q_keyword, NULL);
       }
-      else 
+      else
        q3_attr = ppdFindAttr(ppd, "DefaultResolution", NULL);
 
       if (q3_attr && q3_attr->value && q3_attr->value[0])
@@ -3265,7 +3360,7 @@ apple_register_profiles(
     if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for %d profiles!",
+                      "Unable to allocate memory for %d profiles",
                      num_profiles);
       ppdClose(ppd);
       return;
@@ -3372,7 +3467,7 @@ apple_register_profiles(
     if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for %d profiles!",
+                      "Unable to allocate memory for %d profiles",
                      num_profiles);
       ppdClose(ppd);
       return;
@@ -3413,12 +3508,14 @@ apple_register_profiles(
     * Use the default colorspace...
     */
 
-    num_profiles = 1 + ppd->colorspace != PPD_CS_GRAY;
-    
+    attr = ppdFindAttr(ppd, "DefaultColorSpace", NULL);
+
+    num_profiles = (attr && ppd->colorspace == PPD_CS_GRAY) ? 1 : 2;
+
     if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for %d profiles!",
+                      "Unable to allocate memory for %d profiles",
                      num_profiles);
       ppdClose(ppd);
       return;
@@ -3442,14 +3539,15 @@ apple_register_profiles(
                             _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL);
           break;
 
+      case PPD_CS_GRAY :
+          if (attr)
+           break;
+
       case PPD_CS_N :
           apple_init_profile(ppd, NULL, profiles->profiles + 1,
                             _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
                             NULL);
           break;
-
-      default :
-         break;
     }
   }
 
@@ -3628,7 +3726,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -3650,7 +3748,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
       * Not a valid URI!
       */
 
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-uri attribute \"%s\"!"),
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -3669,7 +3767,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
     */
 
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("Job #%d does not exist!"), jobid);
+                    _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -3684,7 +3782,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
     */
 
     send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Job #%d is not held for authentication!"),
+                    _("Job #%d is not held for authentication"),
                    jobid);
     return;
   }
@@ -3712,7 +3810,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
       send_http_error(con, HTTP_UNAUTHORIZED, printer);
     else
       send_ipp_status(con, IPP_NOT_AUTHORIZED,
-                     _("No authentication information provided!"));
+                     _("No authentication information provided"));
     return;
   }
 
@@ -3722,7 +3820,8 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                    cupsdFindDest(job->dest));
     return;
   }
 
@@ -3773,7 +3872,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
   int          port;                   /* Port portion of URI */
   ipp_attribute_t *attr;               /* Attribute in request */
   const char   *username;              /* Username */
-  int          purge;                  /* Purge? */
+  cupsd_jobaction_t purge;             /* Purge? */
   cupsd_printer_t *printer;            /* Printer */
 
 
@@ -3787,7 +3886,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
   if (strcmp(uri->name, "printer-uri"))
   {
     send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("The printer-uri attribute is required!"));
+                    _("The printer-uri attribute is required"));
     return;
   }
 
@@ -3806,7 +3905,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
     else
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Missing requesting-user-name attribute!"));
+                      _("Missing requesting-user-name attribute"));
       return;
     }
   }
@@ -3819,9 +3918,9 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
 
   if ((attr = ippFindAttribute(con->request, "purge-jobs",
                                IPP_TAG_BOOLEAN)) != NULL)
-    purge = attr->values[0].boolean;
+    purge = attr->values[0].boolean ? CUPSD_JOB_PURGE : CUPSD_JOB_DEFAULT;
   else
-    purge = 1;
+    purge = CUPSD_JOB_PURGE;
 
  /*
   * And if the destination is valid...
@@ -3863,7 +3962,8 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
     cupsdCancelJobs(NULL, username, purge);
 
     cupsdLogMessage(CUPSD_LOG_INFO, "All jobs were %s by \"%s\".",
-                    purge ? "purged" : "canceled", get_username(con));
+                    purge == CUPSD_JOB_PURGE ? "purged" : "canceled",
+                   get_username(con));
   }
   else
   {
@@ -3885,7 +3985,8 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
     cupsdCancelJobs(printer->name, username, purge);
 
     cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
-                    printer->name, purge ? "purged" : "canceled",
+                    printer->name,
+                   purge == CUPSD_JOB_PURGE ? "purged" : "canceled",
                    get_username(con));
   }
 
@@ -3911,7 +4012,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
   cupsd_job_t  *job;                   /* Job information */
   cups_ptype_t dtype;                  /* Destination type (printer/class) */
   cupsd_printer_t *printer;            /* Printer data */
-  int          purge;                  /* Purge the job? */
+  cupsd_jobaction_t purge;             /* Purge the job? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con,
@@ -3931,7 +4032,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -3953,21 +4054,28 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
       }
 
      /*
-      * See if the printer is currently printing a job...
+      * See if there are any pending jobs...
       */
 
-      if (printer->job)
-        jobid = ((cupsd_job_t *)printer->job)->id;
+      for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
+          job;
+          job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
+       if (job->state_value <= IPP_JOB_PROCESSING &&
+           !strcasecmp(job->dest, printer->name))
+         break;
+
+      if (job)
+       jobid = job->id;
       else
       {
        /*
-        * No, see if there are any pending jobs...
+        * No, try stopped jobs...
        */
 
-        for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
+       for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
             job;
             job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
-         if (job->state_value <= IPP_JOB_PROCESSING &&
+         if (job->state_value == IPP_JOB_STOPPED &&
              !strcasecmp(job->dest, printer->name))
            break;
 
@@ -3975,21 +4083,9 @@ cancel_job(cupsd_client_t  *con, /* I - Client connection */
          jobid = job->id;
        else
        {
-         for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
-              job;
-              job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
-           if (job->state_value == IPP_JOB_STOPPED &&
-               !strcasecmp(job->dest, printer->name))
-             break;
-
-          if (job)
-           jobid = job->id;
-         else
-         {
-           send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s!"),
-                           printer->name);
-           return;
-         }
+         send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s"),
+                         printer->name);
+         return;
        }
       }
     }
@@ -4011,7 +4107,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -4025,9 +4121,9 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
 
   if ((attr = ippFindAttribute(con->request, "purge-job",
                                IPP_TAG_BOOLEAN)) != NULL)
-    purge = attr->values[0].boolean;
+    purge = attr->values[0].boolean ? CUPSD_JOB_PURGE : CUPSD_JOB_DEFAULT;
   else
-    purge = 0;
+    purge = CUPSD_JOB_DEFAULT;
 
  /*
   * See if the job exists...
@@ -4039,7 +4135,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -4049,7 +4145,8 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                    cupsdFindDest(job->dest));
     return;
   }
 
@@ -4058,7 +4155,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
   * we can't cancel...
   */
 
-  if (job->state_value >= IPP_JOB_CANCELED && !purge)
+  if (job->state_value >= IPP_JOB_CANCELED && purge != CUPSD_JOB_PURGE)
   {
     switch (job->state_value)
     {
@@ -4088,10 +4185,13 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
   * Cancel the job and return...
   */
 
-  cupsdCancelJob(job, purge, IPP_JOB_CANCELED);
+  cupsdSetJobState(job, IPP_JOB_CANCELED, purge,
+                   purge == CUPSD_JOB_PURGE ? "Job purged by \"%s\"" :
+                                             "Job canceled by \"%s\"",
+                  username);
   cupsdCheckJobs();
 
-  if (purge)
+  if (purge == CUPSD_JOB_PURGE)
     cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Purged by \"%s\".", jobid,
                    username);
   else
@@ -4130,7 +4230,7 @@ cancel_subscription(
     */
 
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("notify-subscription-id %d no good!"), sub_id);
+                    _("notify-subscription-id %d no good"), sub_id);
     return;
   }
 
@@ -4378,16 +4478,7 @@ check_quotas(cupsd_client_t  *con,       /* I - Client connection */
                          "entry ignored", p->users[i]);
        }
 
-       if ((mbr_err = mbr_check_membership(usr_uuid, usr2_uuid,
-                                           &is_member)) != 0)
-       {
-         cupsdLogMessage(CUPSD_LOG_DEBUG,
-                         "check_quotas: User \"%s\" identity check failed "
-                         "(err=%d)", p->users[i], mbr_err);
-         is_member = 0;
-       }
-
-       if (is_member)
+       if (!uuid_compare(usr_uuid, usr2_uuid))
          break;
       }
 #else
@@ -4408,72 +4499,12 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
   * Check quotas...
   */
 
-#ifdef __APPLE__
-  if (AppleQuotas && (q = cupsdFindQuota(p, username)) != NULL)
-  {
-   /*
-    * TODO: Define these special page count values as constants!
-    */
-
-    if (q->page_count == -4) /* special case: unlimited user */
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "User \"%s\" request approved for printer %s (%s): " 
-                     "unlimited quota.",
-                     username, p->name, p->info);
-      q->page_count = 0; /* allow user to print */
-      return (1);
-    }
-    else if (q->page_count == -3) /* quota exceeded */
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "User \"%s\" request denied for printer %s (%s): "
-                     "quota limit exceeded.",
-                     username, p->name, p->info);
-      q->page_count = 2; /* force quota exceeded failure */
-      return (-1);
-    }
-    else if (q->page_count == -2) /* quota disabled for user */
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "User \"%s\" request denied for printer %s (%s): "
-                     "printing disabled for user.",
-                     username, p->name, p->info);
-      q->page_count = 2; /* force quota exceeded failure */
-      return (-1);
-    }
-    else if (q->page_count == -1) /* quota access error */
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "User \"%s\" request denied for printer %s (%s): "
-                     "unable to determine quota limit.",
-                     username, p->name, p->info);
-      q->page_count = 2; /* force quota exceeded failure */
-      return (-1);
-    }
-    else if (q->page_count < 0) /* user not found or other error */
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "User \"%s\" request denied for printer %s (%s): "
-                     "user disabled / missing quota.",
-                     username, p->name, p->info);
-      q->page_count = 2; /* force quota exceeded failure */
-      return (-1);
-    }
-    else /* page within user limits */
-    {
-      q->page_count = 0; /* allow user to print */
-      return (1);
-    }
-  }
-  else
-#endif /* __APPLE__ */
   if (p->k_limit || p->page_limit)
   {
     if ((q = cupsdUpdateQuota(p, username, 0, 0)) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate quota data for user \"%s\"!",
+                      "Unable to allocate quota data for user \"%s\"",
                       username);
       return (-1);
     }
@@ -4651,8 +4682,9 @@ copy_attribute(
         for (i = 0; i < attr->num_values; i ++)
        {
          toattr->values[i].collection = ippNew();
+         toattr->values[i].collection->request.status.version[0] = 2;
          copy_attrs(toattr->values[i].collection, attr->values[i].collection,
-                    NULL, IPP_TAG_ZERO, 0);
+                    NULL, IPP_TAG_ZERO, quickcopy);
        }
         break;
 
@@ -4714,7 +4746,21 @@ copy_attrs(ipp_t        *to,             /* I - Destination request */
       continue;
 
     if (!ra || cupsArrayFind(ra, fromattr->name))
+    {
+     /*
+      * Don't send collection attributes by default to IPP/1.x clients
+      * since many do not support collections.  Also don't send
+      * media-col-database unless specifically requested by the client.
+      */
+
+      if (fromattr->value_tag == IPP_TAG_BEGIN_COLLECTION &&
+          !ra &&
+         (to->request.status.version[0] == 1 ||
+          !strcmp(fromattr->name, "media-col-database")))
+       continue;
+
       copy_attribute(to, fromattr, quickcopy);
+    }
   }
 }
 
@@ -4905,7 +4951,10 @@ copy_banner(cupsd_client_t *con, /* I - Client connection */
          case IPP_TAG_INTEGER :
          case IPP_TAG_ENUM :
              if (!strncmp(s, "time-at-", 8))
-               cupsFilePuts(out, cupsdGetDateTime(attr->values[i].integer));
+             {
+               struct timeval tv = { attr->values[i].integer, 0 };
+               cupsFilePuts(out, cupsdGetDateTime(&tv, CUPSD_TIME_STANDARD));
+             }
              else
                cupsFilePrintf(out, "%d", attr->values[i].integer);
              break;
@@ -5072,6 +5121,7 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
   int          i;                      /* Looping var */
   char         option[PPD_MAX_NAME],   /* Option name */
                choice[PPD_MAX_NAME];   /* Choice name */
+  ppd_size_t   *size;                  /* Default size */
   int          num_defaults;           /* Number of default options */
   cups_option_t        *defaults;              /* Default options */
   char         cups_protocol[PPD_MAX_LINE];
@@ -5105,7 +5155,7 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
                   "copy_model: Running \"cups-driverd cat %s\"...", from);
 
   if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
-                         -1, -1, 0, DefaultProfile, &temppid))
+                         -1, -1, 0, DefaultProfile, NULL, &temppid))
   {
     close(tempfd);
     unlink(tempfile);
@@ -5185,7 +5235,7 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
     * No data from cups-deviced...
     */
 
-    cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file!");
+    cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file");
     unlink(tempfile);
     return (-1);
   }
@@ -5244,19 +5294,19 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
 
     cupsFileClose(dst);
   }
-  else if (ppdPageSize(ppd, DefaultPaperSize))
+  else if ((size = ppdPageSize(ppd, DefaultPaperSize)) != NULL)
   {
    /*
     * Add the default media sizes...
     */
 
-    num_defaults = cupsAddOption("PageSize", DefaultPaperSize,
+    num_defaults = cupsAddOption("PageSize", size->name,
                                  num_defaults, &defaults);
-    num_defaults = cupsAddOption("PageRegion", DefaultPaperSize,
+    num_defaults = cupsAddOption("PageRegion", size->name,
                                  num_defaults, &defaults);
-    num_defaults = cupsAddOption("PaperDimension", DefaultPaperSize,
+    num_defaults = cupsAddOption("PaperDimension", size->name,
                                  num_defaults, &defaults);
-    num_defaults = cupsAddOption("ImageableArea", DefaultPaperSize,
+    num_defaults = cupsAddOption("ImageableArea", size->name,
                                  num_defaults, &defaults);
   }
 
@@ -5410,14 +5460,6 @@ copy_printer_attrs(
 
   curtime = time(NULL);
 
-#ifdef __APPLE__
-  if ((!ra || cupsArrayFind(ra, "com.apple.print.recoverable-message")) &&
-      printer->recoverable)
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
-                 "com.apple.print.recoverable-message", NULL,
-                printer->recoverable);
-#endif /* __APPLE__ */
-
   if (!ra || cupsArrayFind(ra, "marker-change-time"))
     ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                   "marker-change-time", printer->marker_time);
@@ -5486,6 +5528,25 @@ copy_printer_attrs(
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
                 "printer-error-policy", NULL, printer->error_policy);
 
+  if (!ra || cupsArrayFind(ra, "printer-error-policy-supported"))
+  {
+    static const char * const errors[] =/* printer-error-policy-supported values */
+                 {
+                   "abort-job",
+                   "retry-current-job",
+                   "retry-job",
+                   "stop-printer"
+                 };
+
+    if (printer->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_CLASS))
+      ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
+                   "printer-error-policy-supported", NULL, "retry-current-job");
+    else
+      ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
+                   "printer-error-policy-supported",
+                   sizeof(errors) / sizeof(errors[0]), NULL, errors);
+  }
+
   if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs"))
     ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
                   printer->accepting);
@@ -6064,7 +6125,7 @@ create_subscription(
   if (!attr)
   {
     send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("No subscription attributes in request!"));
+                    _("No subscription attributes in request"));
     return;
   }
 
@@ -6122,7 +6183,7 @@ create_subscription(
                            resource, sizeof(resource)) < HTTP_URI_OK)
         {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("Bad notify-recipient-uri URI \"%s\"!"), recipient);
+                         _("Bad notify-recipient-uri URI \"%s\""), recipient);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_URI_SCHEME);
          return;
@@ -6134,7 +6195,7 @@ create_subscription(
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
                          _("notify-recipient-uri URI \"%s\" uses unknown "
-                           "scheme!"), recipient);
+                           "scheme"), recipient);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_URI_SCHEME);
          return;
@@ -6143,7 +6204,7 @@ create_subscription(
         if (!strcmp(scheme, "rss") && !check_rss_recipient(recipient))
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("notify-recipient-uri URI \"%s\" is already used!"),
+                         _("notify-recipient-uri URI \"%s\" is already used"),
                          recipient);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_ATTRIBUTES);
@@ -6158,7 +6219,7 @@ create_subscription(
         if (strcmp(pullmethod, "ippget"))
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("Bad notify-pull-method \"%s\"!"), pullmethod);
+                         _("Bad notify-pull-method \"%s\""), pullmethod);
          ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
                        "notify-status-code", IPP_ATTRIBUTES);
          return;
@@ -6170,7 +6231,7 @@ create_subscription(
               strcmp(attr->values[0].string.text, "utf-8"))
       {
         send_ipp_status(con, IPP_CHARSET,
-                       _("Character set \"%s\" not supported!"),
+                       _("Character set \"%s\" not supported"),
                        attr->values[0].string.text);
        return;
       }
@@ -6179,7 +6240,7 @@ create_subscription(
                strcmp(attr->values[0].string.text, DefaultLanguage)))
       {
         send_ipp_status(con, IPP_CHARSET,
-                       _("Language \"%s\" not supported!"),
+                       _("Language \"%s\" not supported"),
                        attr->values[0].string.text);
        return;
       }
@@ -6190,7 +6251,7 @@ create_subscription(
        {
           send_ipp_status(con, IPP_REQUEST_VALUE,
                          _("The notify-user-data value is too large "
-                           "(%d > 63 octets)!"),
+                           "(%d > 63 octets)"),
                          attr->values[0].unknown.length);
          return;
        }
@@ -6238,7 +6299,7 @@ create_subscription(
       else
       {
         send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("notify-events not specified!"));
+                       _("notify-events not specified"));
        return;
       }
     }
@@ -6256,7 +6317,7 @@ create_subscription(
     {
       if ((job = cupsdFindJob(jobid)) == NULL)
       {
-       send_ipp_status(con, IPP_NOT_FOUND, _("Job %d not found!"), jobid);
+       send_ipp_status(con, IPP_NOT_FOUND, _("Job %d not found"), jobid);
        return;
       }
     }
@@ -6379,7 +6440,10 @@ delete_printer(cupsd_client_t  *con,     /* I - Client connection */
            printer->name);
   unlink(filename);
 
-  snprintf(filename, sizeof(filename), "%s/%s.ipp", CacheDir, printer->name);
+  snprintf(filename, sizeof(filename), "%s/%s.ipp2", CacheDir, printer->name);
+  unlink(filename);
+
+  snprintf(filename, sizeof(filename), "%s/%s.pwg", CacheDir, printer->name);
   unlink(filename);
 
 #ifdef __APPLE__
@@ -6403,7 +6467,9 @@ delete_printer(cupsd_client_t  *con,      /* I - Client connection */
     cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".",
                     printer->name, get_username(con));
 
-    cupsdDeletePrinter(printer, 0);
+    if (cupsdDeletePrinter(printer, 0))
+      cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
+
     cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
   }
 
@@ -6521,7 +6587,7 @@ get_devices(cupsd_client_t *con)  /* I - Client connection */
            "%d+%d+%d+%d+%s%s%s%s%s",
            con->request->request.op.request_id,
            limit ? limit->values[0].integer : 0,
-          timeout ? timeout->values[0].integer : 10,
+          timeout ? timeout->values[0].integer : 15,
           (int)User,
           requested_str,
           exclude_str[0] ? "%20" : "", exclude_str,
@@ -6588,7 +6654,7 @@ get_document(cupsd_client_t  *con,        /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -6611,7 +6677,7 @@ get_document(cupsd_client_t  *con,        /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -6629,7 +6695,7 @@ get_document(cupsd_client_t  *con,        /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -6651,7 +6717,7 @@ get_document(cupsd_client_t  *con,        /* I - Client connection */
                                IPP_TAG_INTEGER)) == NULL)
   {
     send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("Missing document-number attribute!"));
+                    _("Missing document-number attribute"));
     return;
   }
 
@@ -6671,7 +6737,7 @@ get_document(cupsd_client_t  *con,        /* I - Client connection */
                     "Unable to open document %d in job %d - %s", docnum, jobid,
                    strerror(errno));
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("Unable to open document %d in job %d!"), docnum, jobid);
+                    _("Unable to open document %d in job %d"), docnum, jobid);
     return;
   }
 
@@ -6705,6 +6771,7 @@ get_job_attrs(cupsd_client_t  *con,       /* I - Client connection */
   ipp_attribute_t *attr;               /* Current attribute */
   int          jobid;                  /* Job ID */
   cupsd_job_t  *job;                   /* Current job */
+  cupsd_printer_t *printer;            /* Current printer */
   char         scheme[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
@@ -6730,7 +6797,7 @@ get_job_attrs(cupsd_client_t  *con,       /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -6753,7 +6820,7 @@ get_job_attrs(cupsd_client_t  *con,       /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -6771,7 +6838,7 @@ get_job_attrs(cupsd_client_t  *con,       /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -6779,7 +6846,19 @@ get_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+  if ((printer = job->printer) == NULL)
+    printer = cupsdFindDest(job->dest);
+
+  if (printer)
+  {
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
+                                   NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, printer);
+      return;
+    }
+  }
+  else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
     send_http_error(con, status, NULL);
     return;
@@ -6836,7 +6915,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
 
   if (strcmp(uri->name, "printer-uri"))
   {
-    send_ipp_status(con, IPP_BAD_REQUEST, _("No printer-uri in request!"));
+    send_ipp_status(con, IPP_BAD_REQUEST, _("No printer-uri in request"));
     return;
   }
 
@@ -6844,7 +6923,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
                   sizeof(scheme), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
-  if (!strcmp(resource, "/"))
+  if (!strcmp(resource, "/") || !strcmp(resource, "/jobs"))
   {
     dest    = NULL;
     dtype   = (cups_ptype_t)0;
@@ -6917,7 +6996,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
     completed = 0;
     list      = Jobs;
   }
-  else if (attr && !strcmp(attr->values[0].string.text, "printing"))
+  else if (attr && !strcmp(attr->values[0].string.text, "processing"))
   {
     completed = 0;
     list      = PrintingJobs;
@@ -6955,7 +7034,18 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
   else
     username[0] = '\0';
 
-  ra = create_requested_array(con->request);
+  if ((ra = create_requested_array(con->request)) == NULL &&
+      !ippFindAttribute(con->request, "requested-attributes", IPP_TAG_KEYWORD))
+  {
+   /*
+    * IPP conformance - Get-Jobs has a default requested-attributes value of
+    * "job-id" and "job-uri".
+    */
+
+    ra = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+    cupsArrayAdd(ra, "job-id");
+    cupsArrayAdd(ra, "job-uri");
+  }
 
  /*
   * OK, build a list of jobs for this printer...
@@ -6969,7 +7059,10 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
     * Filter out jobs that don't match...
     */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: job->id = %d", job->id);
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
+                   "state_value=%d, attrs=%p", job->id, job->dest,
+                   job->username, job->state_value, job->attrs);
 
     if (!job->dest || !job->username)
       cupsdLoadJob(job);
@@ -6992,7 +7085,11 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
     cupsdLoadJob(job);
 
     if (!job->attrs)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: No attributes for job %d",
+                      job->id);
       continue;
+    }
 
     if (username[0] && strcasecmp(username, job->username))
       continue;
@@ -7002,11 +7099,11 @@ get_jobs(cupsd_client_t  *con,          /* I - Client connection */
 
     count ++;
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count = %d", count);
-
     copy_job_attrs(con, job, ra);
   }
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count=%d", count);
+
   cupsArrayDelete(ra);
 
   con->response->request.status.status_code = IPP_OK;
@@ -7044,7 +7141,7 @@ get_notifications(cupsd_client_t *con)    /* I - Client connection */
   if (!ids)
   {
     send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("Missing notify-subscription-ids attribute!"));
+                    _("Missing notify-subscription-ids attribute"));
     return;
   }
 
@@ -7061,7 +7158,7 @@ get_notifications(cupsd_client_t *con)    /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_NOT_FOUND,
-                      _("notify-subscription-id %d no good!"),
+                      _("notify-subscription-id %d no good"),
                      ids->values[i].integer);
       return;
     }
@@ -7598,6 +7695,7 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
   const char   *username;              /* Current user */
   char         *first_printer_name;    /* first-printer-name attribute */
   cups_array_t *ra;                    /* Requested attributes array */
+  int          local;                  /* Local connection? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printers(%p[%d], %x)", con,
@@ -7655,6 +7753,8 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
   else
     printer_mask = 0;
 
+  local = httpAddrLocalhost(&(con->clientaddr));
+
   if ((attr = ippFindAttribute(con->request, "printer-location",
                                IPP_TAG_TEXT)) != NULL)
     location = attr->values[0].string.text;
@@ -7687,6 +7787,9 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
        count < limit && printer;
        printer = (cupsd_printer_t *)cupsArrayNext(Printers))
   {
+    if (!local && !printer->shared)
+      continue;
+
     if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
         (printer->type & printer_mask) == printer_type &&
        (!location ||
@@ -7706,8 +7809,7 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
       * access...
       */
 
-      if (!(printer->type & CUPS_PRINTER_AUTHENTICATED) &&
-          printer->num_users && username && !user_allowed(printer, username))
+      if (printer->num_users && username && !user_allowed(printer, username))
         continue;
 
      /*
@@ -7762,7 +7864,7 @@ get_subscription_attrs(
     */
 
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("notify-subscription-id %d no good!"), sub_id);
+                    _("notify-subscription-id %d no good"), sub_id);
     return;
   }
 
@@ -7848,7 +7950,7 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
 
     if (!job)
     {
-      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%s does not exist!"),
+      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%s does not exist"),
                       resource + 6);
       return;
     }
@@ -7870,7 +7972,7 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
 
     if (!job)
     {
-      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"),
+      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"),
                       attr->values[0].integer);
       return;
     }
@@ -7965,8 +8067,8 @@ static void
 hold_job(cupsd_client_t  *con,         /* I - Client connection */
          ipp_attribute_t *uri)         /* I - Job or Printer URI */
 {
-  ipp_attribute_t *attr,               /* Current job-hold-until */
-               *newattr;               /* New job-hold-until */
+  ipp_attribute_t *attr;               /* Current job-hold-until */
+  const char   *when;                  /* New value */
   int          jobid;                  /* Job ID */
   char         scheme[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
@@ -7993,7 +8095,7 @@ hold_job(cupsd_client_t  *con,            /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -8016,7 +8118,7 @@ hold_job(cupsd_client_t  *con,            /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -8034,7 +8136,7 @@ hold_job(cupsd_client_t  *con,            /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -8044,7 +8146,8 @@ hold_job(cupsd_client_t  *con,            /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                   cupsdFindDest(job->dest));
     return;
   }
 
@@ -8052,50 +8155,23 @@ hold_job(cupsd_client_t  *con,          /* I - Client connection */
   * Hold the job and return...
   */
 
-  cupsdHoldJob(job);
-
-  cupsdAddEvent(CUPSD_EVENT_JOB_STATE, cupsdFindDest(job->dest), job,
-                "Job held by user.");
-
-  if ((newattr = ippFindAttribute(con->request, "job-hold-until",
-                                  IPP_TAG_KEYWORD)) == NULL)
-    newattr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME);
-
-  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
-                               IPP_TAG_KEYWORD)) == NULL)
-    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+  if ((attr = ippFindAttribute(con->request, "job-hold-until",
+                              IPP_TAG_KEYWORD)) == NULL)
+    attr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME);
 
   if (attr)
   {
-   /*
-    * Free the old hold value and copy the new one over...
-    */
-
-    _cupsStrFree(attr->values[0].string.text);
-
-    if (newattr)
-    {
-      attr->value_tag = newattr->value_tag;
-      attr->values[0].string.text =
-          _cupsStrRetain(newattr->values[0].string.text);
-    }
-    else
-    {
-      attr->value_tag = IPP_TAG_KEYWORD;
-      attr->values[0].string.text = _cupsStrAlloc("indefinite");
-    }
-
-   /*
-    * Hold job until specified time...
-    */
-
-    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+    when = attr->values[0].string.text;
 
     cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
-                  "Job job-hold-until value changed by user.");
+                 "Job job-hold-until value changed by user.");
   }
+  else
+    when = "indefinite";
 
-  cupsdLogJob(job, CUPSD_LOG_INFO, "Held by \"%s\".", username);
+  cupsdSetJobHoldUntil(job, when, 1);
+  cupsdSetJobState(job, IPP_JOB_HELD, CUPSD_JOB_DEFAULT, "Job held by \"%s\".",
+                   username);
 
   con->response->request.status.status_code = IPP_OK;
 }
@@ -8207,7 +8283,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
     */
 
     send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("job-printer-uri attribute missing!"));
+                    _("job-printer-uri attribute missing"));
     return;
   }
 
@@ -8270,7 +8346,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
        */
 
        send_ipp_status(con, IPP_NOT_FOUND,
-                       _("Job #%d does not exist!"), attr->values[0].integer);
+                       _("Job #%d does not exist"), attr->values[0].integer);
        return;
       }
       else
@@ -8297,7 +8373,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -8315,7 +8391,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_NOT_FOUND,
-                      _("Job #%d does not exist!"), jobid);
+                      _("Job #%d does not exist"), jobid);
       return;
     }
     else
@@ -8357,7 +8433,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("Job #%d is finished and cannot be altered!"),
+                      _("Job #%d is finished and cannot be altered"),
                      job->id);
       return;
     }
@@ -8368,7 +8444,8 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
 
     if (!validate_user(job, con, job->username, username, sizeof(username)))
     {
-      send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+      send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                      cupsdFindDest(job->dest));
       return;
     }
 
@@ -8448,7 +8525,9 @@ ppd_parse_line(const char *line,  /* I - Line */
   * Read the option name...
   */
 
-  for (line += 8, olen --; isalnum(*line & 255); line ++)
+  for (line += 8, olen --;
+       *line > ' ' && *line < 0x7f && *line != ':' && *line != '/';
+       line ++)
     if (olen > 0)
     {
       *option++ = *line;
@@ -8476,7 +8555,9 @@ ppd_parse_line(const char *line,  /* I - Line */
   while (isspace(*line & 255))
     line ++;
 
-  for (clen --; isalnum(*line & 255); line ++)
+  for (clen --;
+       *line > ' ' && *line < 0x7f && *line != ':' && *line != '/';
+       line ++)
     if (clen > 0)
     {
       *choice++ = *line;
@@ -8537,7 +8618,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
       )
     {
       send_ipp_status(con, IPP_ATTRIBUTES,
-                      _("Unsupported compression \"%s\"!"),
+                      _("Unsupported compression \"%s\""),
                      attr->values[0].string.text);
       ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD,
                   "compression", NULL, attr->values[0].string.text);
@@ -8556,7 +8637,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
 
   if (!con->filename)
   {
-    send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!"));
+    send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?"));
     return;
   }
 
@@ -8590,7 +8671,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
                type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Could not scan type \"%s\"!"),
+                      _("Could not scan type \"%s\""),
                      format->values[0].string.text);
       return;
     }
@@ -8606,7 +8687,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
     if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Could not scan type \"%s\"!"),
+                      _("Could not scan type \"%s\""),
                      default_format);
       return;
     }
@@ -8671,7 +8752,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
   else if (!filetype)
   {
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
-                    _("Unsupported format \'%s/%s\'!"), super, type);
+                    _("Unsupported format \'%s/%s\'"), super, type);
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Hint: Do you have the raw file printing rules enabled?");
 
@@ -8991,6 +9072,9 @@ reject_jobs(cupsd_client_t  *con, /* I - Client connection */
 
   cupsdAddPrinterHistory(printer);
 
+  cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
+                "No longer accepting jobs.");
+
   if (dtype & CUPS_PRINTER_CLASS)
   {
     cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
@@ -9117,7 +9201,7 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -9140,7 +9224,7 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -9158,7 +9242,7 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -9172,7 +9256,7 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
     * Nope - return a "not possible" error...
     */
 
-    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Job #%d is not held!"), jobid);
+    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Job #%d is not held"), jobid);
     return;
   }
 
@@ -9182,7 +9266,8 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                    cupsdFindDest(job->dest));
     return;
   }
 
@@ -9251,7 +9336,7 @@ renew_subscription(
     */
 
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("notify-subscription-id %d no good!"), sub_id);
+                    _("notify-subscription-id %d no good"), sub_id);
     return;
   }
 
@@ -9262,7 +9347,7 @@ renew_subscription(
     */
 
     send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Job subscriptions cannot be renewed!"));
+                    _("Job subscriptions cannot be renewed"));
     return;
   }
 
@@ -9317,12 +9402,12 @@ restart_job(cupsd_client_t  *con,       /* I - Client connection */
 {
   ipp_attribute_t *attr;               /* Current attribute */
   int          jobid;                  /* Job ID */
+  cupsd_job_t  *job;                   /* Job information */
   char         scheme[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
-  cupsd_job_t  *job;                   /* Job information */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "restart_job(%p[%d], %s)", con,
@@ -9342,7 +9427,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -9365,7 +9450,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -9383,7 +9468,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -9397,7 +9482,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
     * Nope - return a "not possible" error...
     */
 
-    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Job #%d is not complete!"),
+    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Job #%d is not complete"),
                     jobid);
     return;
   }
@@ -9415,7 +9500,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
     */
 
     send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Job #%d cannot be restarted - no files!"), jobid);
+                    _("Job #%d cannot be restarted - no files"), jobid);
     return;
   }
 
@@ -9425,15 +9510,43 @@ restart_job(cupsd_client_t  *con,       /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                    cupsdFindDest(job->dest));
     return;
   }
 
  /*
-  * Restart the job and return...
+  * See if the job-hold-until attribute is specified...
   */
 
-  cupsdRestartJob(job);
+  if ((attr = ippFindAttribute(con->request, "job-hold-until",
+                               IPP_TAG_KEYWORD)) == NULL)
+    attr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME);
+
+  if (attr && strcmp(attr->values[0].string.text, "no-hold"))
+  {
+   /*
+    * Return the job to a held state...
+    */
+
+    cupsdLogJob(job, CUPSD_LOG_DEBUG,
+               "Restarted by \"%s\" with job-hold-until=%s.",
+                username, attr->values[0].string.text);
+    cupsdSetJobHoldUntil(job, attr->values[0].string.text, 0);
+
+    cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE,
+                  NULL, job, "Job restarted by user with job-hold-until=%s",
+                 attr->values[0].string.text);
+  }
+  else
+  {
+   /*
+    * Restart the job...
+    */
+
+    cupsdRestartJob(job);
+    cupsdCheckJobs();
+  }
 
   cupsdLogJob(job, CUPSD_LOG_INFO, "Restarted by \"%s\".", username);
 
@@ -9556,7 +9669,7 @@ save_auth_info(
   * Write a random number of newlines to the end of the file...
   */
 
-  for (i = (rand() % 1024); i >= 0; i --)
+  for (i = (CUPS_RAND() % 1024); i >= 0; i --)
     cupsFilePutChar(fp, '\n');
 
  /*
@@ -9566,7 +9679,12 @@ save_auth_info(
   cupsFileClose(fp);
 
 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
-  if (con->gss_have_creds)
+#  ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
+  if (con->have_gss &&
+      (con->http.hostaddr->addr.sa_family == AF_LOCAL || con->gss_creds))
+#  else
+  if (con->have_gss && con->gss_creds)
+#  endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
     save_krb5_creds(con, job);
   else if (job->ccname)
     cupsdClearString(&(job->ccname));
@@ -9583,121 +9701,26 @@ static void
 save_krb5_creds(cupsd_client_t *con,   /* I - Client connection */
                 cupsd_job_t    *job)   /* I - Job */
 {
-#  if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
-  cupsdLogMessage(CUPSD_LOG_INFO,
-                  "Sorry, your version of Kerberos does not support delegated "
-                 "credentials!");
-  return;
-
-#  else
-  krb5_error_code      error;          /* Kerberos error code */
-  OM_uint32            major_status,   /* Major status code */
-                       minor_status;   /* Minor status code */
-  krb5_principal       principal;      /* Kerberos principal */
-
-
-#   ifdef __APPLE__
  /*
-  * If the weak-linked GSSAPI/Kerberos library is not present, don't try
-  * to use it...
+  * Get the credentials...
   */
 
-  if (krb5_init_context == NULL)
-    return;
-#    endif /* __APPLE__ */
-
-  if (!KerberosInitialized)
-  {
-   /*
-    * Setup a Kerberos context for the scheduler to use...
-    */
-
-    KerberosInitialized = 1;
-
-    if (krb5_init_context(&KerberosContext))
-    {
-      KerberosContext = NULL;
-
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to initialize Kerberos context");
-      return;
-    }
-  }
-
- /*
-  * We MUST create a file-based cache because memory-based caches are
-  * only valid for the current process/address space.
-  *
-  * Due to various bugs/features in different versions of Kerberos, we
-  * need either the krb5_cc_new_unique() function or Heimdal's version
-  * of krb5_cc_gen_new() to create a new FILE: credential cache that
-  * can be passed to the backend.  These functions create a temporary
-  * file (typically in /tmp) containing the cached credentials, which
-  * are removed when we have successfully printed a job.
-  */
-
-#    ifdef HAVE_KRB5_CC_NEW_UNIQUE
-  if ((error = krb5_cc_new_unique(KerberosContext, "FILE", NULL,
-                                  &(job->ccache))) != 0)
-#    else /* HAVE_HEIMDAL */
-  if ((error = krb5_cc_gen_new(KerberosContext, &krb5_fcc_ops,
-                               &(job->ccache))) != 0)
-#    endif /* HAVE_KRB5_CC_NEW_UNIQUE */
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to create new credentials cache (%d/%s)",
-                    error, strerror(errno));
-    job->ccache = NULL;
-    return;
-  }
-
-  if ((error = krb5_parse_name(KerberosContext, con->username, &principal)) != 0)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to parse kerberos username (%d/%s)",
-                    error, strerror(errno));
-    krb5_cc_destroy(KerberosContext, job->ccache);
-    job->ccache = NULL;
-    return;
-  }
-
-  if ((error = krb5_cc_initialize(KerberosContext, job->ccache, principal)))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to initialize credentials cache (%d/%s)", error,
-                   strerror(errno));
-    krb5_cc_destroy(KerberosContext, job->ccache);
-    krb5_free_principal(KerberosContext, principal);
-    job->ccache = NULL;
-    return;
-  }
-
-  krb5_free_principal(KerberosContext, principal);
-
- /*
-  * Copy the user's credentials to the new cache file...
-  */
-
-  major_status = gss_krb5_copy_ccache(&minor_status, con->gss_delegated_cred,
-                                     job->ccache);
-
-  if (GSS_ERROR(major_status))
-  {
-    cupsdLogGSSMessage(CUPSD_LOG_ERROR, major_status, minor_status,
-                       "Unable to import client credentials cache");
-    krb5_cc_destroy(KerberosContext, job->ccache);
-    job->ccache = NULL;
-    return;
-  }
+  job->ccache = cupsdCopyKrb5Creds(con);
 
  /*
   * Add the KRB5CCNAME environment variable to the job so that the
   * backend can use the credentials when printing.
   */
 
-  cupsdSetStringf(&(job->ccname), "KRB5CCNAME=FILE:%s",
-                  krb5_cc_get_name(KerberosContext, job->ccache));
+  if (job->ccache)
+  {
+    cupsdSetStringf(&(job->ccname), "KRB5CCNAME=FILE:%s",
+                   krb5_cc_get_name(KerberosContext, job->ccache));
 
-  cupsdLogJob(job, CUPSD_LOG_DEBUG2, "save_krb5_creds: %s", job->ccname);
-#  endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
+    cupsdLogJob(job, CUPSD_LOG_DEBUG2, "save_krb5_creds: %s", job->ccname);
+  }
+  else
+    cupsdClearString(&(job->ccname));
 }
 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
 
@@ -9759,7 +9782,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -9782,7 +9805,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -9800,7 +9823,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -9812,7 +9835,8 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                    cupsdFindDest(job->dest));
     return;
   }
 
@@ -9832,7 +9856,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
 #endif /* HAVE_LIBZ */
       )
     {
-      send_ipp_status(con, IPP_ATTRIBUTES, _("Unsupported compression \"%s\"!"),
+      send_ipp_status(con, IPP_ATTRIBUTES, _("Unsupported compression \"%s\""),
                      attr->values[0].string.text);
       ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD,
                   "compression", NULL, attr->values[0].string.text);
@@ -9851,7 +9875,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
 
   if (!con->filename)
   {
-    send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!"));
+    send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?"));
     return;
   }
 
@@ -9869,7 +9893,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
     if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]",
                super, type) != 2)
     {
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\"!"),
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\""),
                      format->values[0].string.text);
       return;
     }
@@ -9885,7 +9909,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
     if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Could not scan type \"%s\"!"),
+                      _("Could not scan type \"%s\""),
                      default_format);
       return;
     }
@@ -9949,7 +9973,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
   else if (!filetype)
   {
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
-                    _("Unsupported format \'%s/%s\'!"), super, type);
+                    _("Unsupported format \'%s/%s\'"), super, type);
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Hint: Do you have the raw file printing rules enabled?");
 
@@ -9966,7 +9990,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
              filetype->type);
 
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
-                    _("Unsupported format \'%s\'!"), mimetype);
+                    _("Unsupported format \'%s\'"), mimetype);
 
     ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
                  "document-format", NULL, mimetype);
@@ -10051,7 +10075,7 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
     {
       job->state->values[0].integer = IPP_JOB_HELD;
       job->state_value              = IPP_JOB_HELD;
-      job->hold_until               = time(NULL) + 60;
+      job->hold_until               = time(NULL) + MultipleOperationTimeout;
       job->dirty                    = 1;
 
       cupsdMarkDirty(CUPSD_DIRTY_JOBS);
@@ -10203,7 +10227,7 @@ send_ipp_status(cupsd_client_t *con,    /* I - Client connection */
   if (ippFindAttribute(con->response, "attributes-charset",
                        IPP_TAG_ZERO) == NULL)
     ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                 "attributes-charset", NULL, DefaultCharset);
+                 "attributes-charset", NULL, "utf-8");
 
   if (ippFindAttribute(con->response, "attributes-natural-language",
                        IPP_TAG_ZERO) == NULL)
@@ -10334,7 +10358,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
                                  IPP_TAG_INTEGER)) == NULL)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
+                      _("Got a printer-uri attribute but no job-id"));
       return;
     }
 
@@ -10357,7 +10381,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
       */
 
       send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
+                      _("Bad job-uri attribute \"%s\""),
                       uri->values[0].string.text);
       return;
     }
@@ -10375,7 +10399,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
     * Nope - return a "not found" error...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist"), jobid);
     return;
   }
 
@@ -10390,7 +10414,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
     */
 
     send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Job #%d is finished and cannot be altered!"), jobid);
+                    _("Job #%d is finished and cannot be altered"), jobid);
     return;
   }
 
@@ -10400,7 +10424,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
+    send_http_error(con, con->username[0] ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED,
+                    cupsdFindDest(job->dest));
     return;
   }
 
@@ -10464,7 +10489,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 
       if (attr->value_tag != IPP_TAG_INTEGER)
       {
-       send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-priority value!"));
+       send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-priority value"));
 
        if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL)
           attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
@@ -10494,7 +10519,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 
       if (attr->value_tag != IPP_TAG_ENUM)
       {
-       send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-state value!"));
+       send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-state value"));
 
        if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL)
           attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
@@ -10515,11 +10540,9 @@ set_job_attrs(cupsd_client_t  *con,    /* I - Client connection */
              {
                cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-state to %d",
                            attr->values[0].integer);
-
-               job->state->values[0].integer = attr->values[0].integer;
-               job->state_value = (ipp_jstate_t)attr->values[0].integer;
-
-                event |= CUPSD_EVENT_JOB_STATE;
+                cupsdSetJobState(job, attr->values[0].integer,
+                                CUPSD_JOB_DEFAULT,
+                                "Job state changed by \"%s\"", username);
                check_jobs = 1;
              }
              break;
@@ -10547,8 +10570,9 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
              {
                cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-state to %d",
                            attr->values[0].integer);
-                cupsdCancelJob(job, 0, (ipp_jstate_t)attr->values[0].integer);
-
+                cupsdSetJobState(job, (ipp_jstate_t)attr->values[0].integer,
+                                CUPSD_JOB_DEFAULT,
+                                "Job state changed by \"%s\"", username);
                 check_jobs = 1;
              }
              break;
@@ -10588,15 +10612,18 @@ set_job_attrs(cupsd_client_t  *con,   /* I - Client connection */
       {
         cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-hold-until to %s",
                    attr->values[0].string.text);
-        cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+        cupsdSetJobHoldUntil(job, attr->values[0].string.text, 0);
 
        if (!strcmp(attr->values[0].string.text, "no-hold"))
+       {
          cupsdReleaseJob(job);
+          check_jobs = 1;
+       }
        else
-         cupsdHoldJob(job);
+         cupsdSetJobState(job, IPP_JOB_HELD, CUPSD_JOB_DEFAULT,
+                          "Job held by \"%s\".", username);
 
-        check_jobs = 1;
-        event      |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
+        event |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
       }
     }
     else if (attr->value_tag == IPP_TAG_DELETEATTR)
@@ -10679,7 +10706,7 @@ set_printer_attrs(cupsd_client_t  *con, /* I - Client connection */
   cups_ptype_t         dtype;          /* Destination type (printer/class) */
   cupsd_printer_t      *printer;       /* Printer/class */
   ipp_attribute_t      *attr;          /* Printer attribute */
-  int                  changed;        /* Was anything changed? */
+  int                  changed = 0;    /* Was anything changed? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_printer_attrs(%p[%d], %s)", con,
@@ -10891,10 +10918,11 @@ set_printer_defaults(
       if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD)
         continue;
 
-      if (strcmp(attr->values[0].string.text, "abort-job") &&
-          strcmp(attr->values[0].string.text, "retry-current-job") &&
-          strcmp(attr->values[0].string.text, "retry-job") &&
-          strcmp(attr->values[0].string.text, "stop-printer"))
+      if (strcmp(attr->values[0].string.text, "retry-current-job") &&
+          ((printer->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_CLASS)) ||
+          (strcmp(attr->values[0].string.text, "abort-job") &&
+           strcmp(attr->values[0].string.text, "retry-job") &&
+           strcmp(attr->values[0].string.text, "stop-printer"))))
       {
        send_ipp_status(con, IPP_NOT_POSSIBLE,
                        _("Unknown printer-error-policy \"%s\"."),
@@ -11201,7 +11229,7 @@ url_encode_string(const char *s,        /* I - String */
 
   while (*s && bufptr < bufend)
   {
-    if (*s == ' ' || *s == '%')
+    if (*s == ' ' || *s == '%' || *s == '+')
     {
       if (bufptr >= (bufend - 2))
        break;
@@ -11327,7 +11355,7 @@ validate_job(cupsd_client_t  *con,      /* I - Client connection */
       !strcmp(attr->values[0].string.text, "none"))
   {
     send_ipp_status(con, IPP_ATTRIBUTES,
-                    _("Unsupported compression attribute %s!"),
+                    _("Unsupported compression attribute %s"),
                     attr->values[0].string.text);
     ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD,
                 "compression", NULL, attr->values[0].string.text);
@@ -11344,7 +11372,7 @@ validate_job(cupsd_client_t  *con,      /* I - Client connection */
     if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]",
                super, type) != 2)
     {
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\"!"),
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\""),
                      format->values[0].string.text);
       return;
     }
@@ -11355,7 +11383,7 @@ validate_job(cupsd_client_t  *con,      /* I - Client connection */
       cupsdLogMessage(CUPSD_LOG_INFO,
                       "Hint: Do you have the raw file printing rules enabled?");
       send_ipp_status(con, IPP_DOCUMENT_FORMAT,
-                      _("Unsupported format \"%s\"!"),
+                      _("Unsupported format \"%s\""),
                      format->values[0].string.text);
       ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
                    "document-format", NULL, format->values[0].string.text);