]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge changes from CUPS 1.4svn-r7994.
[thirdparty/cups.git] / scheduler / ipp.c
index e94c7310ac271efbd8b48d5564bb5d3057b6cf6b..016a1b1af619972480604078d57598929ab90b34 100644 (file)
@@ -1,47 +1,49 @@
 /*
- * "$Id: ipp.c 5383 2006-04-07 15:36:10Z mike $"
+ * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
+ *   This file contains Kerberos support code, copyright 2006 by
+ *   Jelmer Vernooij.
  *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
- *   cupsdProcessIPPRequest()    - Process an incoming IPP request...
+ *   cupsdProcessIPPRequest()    - Process an incoming IPP request.
+ *   cupsdTimeoutJob()           - Timeout a job waiting on job files.
  *   accept_jobs()               - Accept print jobs to a printer.
  *   add_class()                 - Add a class to the system.
  *   add_file()                  - Add a file to a job.
  *   add_job()                   - Add a job to a print queue.
  *   add_job_state_reasons()     - Add the "job-state-reasons" attribute based
  *                                 upon the job and printer state...
- *   add_job_subscriptions()     - Add any subcriptions for a job.
+ *   add_job_subscriptions()     - Add any subscriptions for a job.
  *   add_job_uuid()              - Add job-uuid attribute to a job.
  *   add_printer()               - Add a printer to the system.
  *   add_printer_state_reasons() - Add the "printer-state-reasons" attribute
  *                                 based upon the printer state...
- *   add_queued_job_count()      - Add the "queued-job-count" attribute for
+ *   add_queued_job_count()      - Add the "queued-job-count" attribute for the
+ *                                 specified printer or class.
+ *   apple_init_profile()        - Initialize a color profile.
+ *   apple_register_profiles()   - Register color profiles for a printer.
+ *   apple_unregister_profiles() - Remove color profiles for the specified
+ *                                 printer.
  *   apply_printer_defaults()    - Apply printer default options to a job.
  *   authenticate_job()          - Set job authentication info.
  *   cancel_all_jobs()           - Cancel all print jobs.
  *   cancel_job()                - Cancel a print job.
  *   cancel_subscription()       - Cancel a subscription.
  *   check_quotas()              - Check quotas for a printer and user.
+ *   check_rss_recipient()       - Check that we do not have a duplicate RSS
+ *                                 feed URI.
  *   copy_attribute()            - Copy a single attribute.
  *   copy_attrs()                - Copy attributes from one request to another.
  *   copy_banner()               - Copy a banner file to the requests directory
  *   get_default()               - Get the default destination.
  *   get_devices()               - Get the list of available devices on the
  *                                 local system.
+ *   get_document()              - Get a copy of a job file.
  *   get_job_attrs()             - Get job attributes.
  *   get_jobs()                  - Get a list of jobs for the specified printer.
  *   get_notifications()         - Get events for a subscription.
+ *   get_ppd()                   - Get a named PPD from the local system.
  *   get_ppds()                  - Get the list of PPD files on the local
  *                                 system.
  *   get_printer_attrs()         - Get printer attributes.
- *   get_printers()              - Get a list of printers.
+ *   get_printers()              - Get a list of printers or classes.
  *   get_subscription_attrs()    - Get subscription attributes.
  *   get_subscriptions()         - Get subscriptions.
  *   get_username()              - Get the username associated with a request.
  *   hold_job()                  - Hold a print job.
  *   move_job()                  - Move a job to a new destination.
- *   ppd_add_default()           - Add a PPD default choice.
  *   ppd_parse_line()            - Parse a PPD default line.
  *   print_job()                 - Print a file to a printer or class.
- *   read_ps_line()              - Read a line from a PS file...
- *   read_ps_job_ticket()        - Reads a job ticket embedded in a PS file.
+ *   read_job_ticket()           - Read a job ticket embedded in a print file.
  *   reject_jobs()               - Reject print jobs to a printer.
  *   release_job()               - Release a held print job.
+ *   renew_subscription()        - Renew an existing subscription...
  *   restart_job()               - Restart an old print job.
  *   save_auth_info()            - Save authentication information for a job.
+ *   save_krb5_creds()           - Save Kerberos credentials for the job.
  *   send_document()             - Send a file to a printer or class.
  *   send_http_error()           - Send a HTTP error back to the IPP client.
  *   send_ipp_status()           - Send a status back to the IPP client.
@@ -88,6 +92,8 @@
  *   set_printer_defaults()      - Set printer default options from a request.
  *   start_printer()             - Start a printer.
  *   stop_printer()              - Stop a printer.
+ *   url_encode_attr()           - URL-encode a string attribute.
+ *   url_encode_string()         - URL-encode a string.
  *   user_allowed()              - See if a user is allowed to print to a queue.
  *   validate_job()              - Validate printer options and destination.
  *   validate_name()             - Make sure the printer name only contains
  */
 
 #include "cupsd.h"
+#include <cups/ppd-private.h>
 
 #ifdef HAVE_LIBPAPER
 #  include <paper.h>
 #endif /* HAVE_LIBPAPER */
 
-
-/*
- * PPD default choice structure...
- */
-
-typedef struct
-{
-  char option[PPD_MAX_NAME];           /* Main keyword (option name) */
-  char choice[PPD_MAX_NAME];           /* Option keyword (choice name) */
-} ppd_default_t;
+#ifdef __APPLE__
+#  include <ApplicationServices/ApplicationServices.h>
+#  include <CoreFoundation/CoreFoundation.h>
+#  ifdef HAVE_MEMBERSHIP_H
+#    include <membership.h>
+#  endif /* HAVE_MEMBERSHIP_H */
+#  ifdef HAVE_MEMBERSHIPPRIV_H
+#    include <membershipPriv.h>
+#  else
+extern int mbr_user_name_to_uuid(const char* name, uuid_t uu);
+extern int mbr_group_name_to_uuid(const char* name, uuid_t uu);
+extern int mbr_check_membership_by_id(uuid_t user, gid_t group, int* ismember);
+#  endif /* HAVE_MEMBERSHIPPRIV_H */
+#endif /* __APPLE__ */
 
 
 /*
@@ -125,8 +136,7 @@ static void accept_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    add_class(cupsd_client_t *con, ipp_attribute_t *uri);
 static int     add_file(cupsd_client_t *con, cupsd_job_t *job,
                         mime_type_t *filetype, int compression);
-static cupsd_job_t *add_job(cupsd_client_t *con, ipp_attribute_t *uri,
-                           cupsd_printer_t **dprinter,
+static cupsd_job_t *add_job(cupsd_client_t *con, cupsd_printer_t *printer,
                            mime_type_t *filetype);
 static void    add_job_state_reasons(cupsd_client_t *con, cupsd_job_t *job);
 static void    add_job_subscriptions(cupsd_client_t *con, cupsd_job_t *job);
@@ -135,12 +145,21 @@ static void       add_printer(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    add_printer_state_reasons(cupsd_client_t *con,
                                          cupsd_printer_t *p);
 static void    add_queued_job_count(cupsd_client_t *con, cupsd_printer_t *p);
+#ifdef __APPLE__
+static void    apple_init_profile(ppd_file_t *ppd, cups_array_t *languages,
+                                  CMDeviceProfileInfo *profile, unsigned id,
+                                  const char *name, const char *text,
+                                  const char *iccfile);
+static void    apple_register_profiles(cupsd_printer_t *p);
+static void    apple_unregister_profiles(cupsd_printer_t *p);
+#endif /* __APPLE__ */
 static void    apply_printer_defaults(cupsd_printer_t *printer,
                                       cupsd_job_t *job);
 static void    authenticate_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    cancel_all_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    cancel_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    cancel_subscription(cupsd_client_t *con, int id);
+static int     check_rss_recipient(const char *recipient);
 static int     check_quotas(cupsd_client_t *con, cupsd_printer_t *p);
 static ipp_attribute_t *copy_attribute(ipp_t *to, ipp_attribute_t *attr,
                                        int quickcopy);
@@ -166,9 +185,11 @@ static void        create_subscription(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    delete_printer(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    get_default(cupsd_client_t *con);
 static void    get_devices(cupsd_client_t *con);
+static void    get_document(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    get_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    get_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    get_notifications(cupsd_client_t *con);
+static void    get_ppd(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    get_ppds(cupsd_client_t *con);
 static void    get_printers(cupsd_client_t *con, int type);
 static void    get_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
@@ -177,19 +198,22 @@ static void       get_subscriptions(cupsd_client_t *con, ipp_attribute_t *uri);
 static const char *get_username(cupsd_client_t *con);
 static void    hold_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    move_job(cupsd_client_t *con, ipp_attribute_t *uri);
-static int     ppd_add_default(const char *option, const char *choice,
-                               int num_defaults, ppd_default_t **defaults);
 static int     ppd_parse_line(const char *line, char *option, int olen,
                               char *choice, int clen);
 static void    print_job(cupsd_client_t *con, ipp_attribute_t *uri);
-static void    read_ps_job_ticket(cupsd_client_t *con);
+static void    read_job_ticket(cupsd_client_t *con);
 static void    reject_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    release_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    renew_subscription(cupsd_client_t *con, int sub_id);
 static void    restart_job(cupsd_client_t *con, ipp_attribute_t *uri);
-static void    save_auth_info(cupsd_client_t *con, cupsd_job_t *job);
+static void    save_auth_info(cupsd_client_t *con, cupsd_job_t *job,
+                              ipp_attribute_t *auth_info);
+#if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
+static void    save_krb5_creds(cupsd_client_t *con, cupsd_job_t *job);
+#endif /* HAVE_GSSAPI && HAVE_KRB5_H */
 static void    send_document(cupsd_client_t *con, ipp_attribute_t *uri);
-static void    send_http_error(cupsd_client_t *con, http_status_t status);
+static void    send_http_error(cupsd_client_t *con, http_status_t status,
+                               cupsd_printer_t *printer);
 static void    send_ipp_status(cupsd_client_t *con, ipp_status_t status,
                                const char *message, ...)
 #    ifdef __GNUC__
@@ -202,6 +226,9 @@ static void set_printer_defaults(cupsd_client_t *con,
                                     cupsd_printer_t *printer);
 static void    start_printer(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    stop_printer(cupsd_client_t *con, ipp_attribute_t *uri);
+static void    url_encode_attr(ipp_attribute_t *attr, char *buffer,
+                               int bufsize);
+static char    *url_encode_string(const char *s, char *buffer, int bufsize);
 static int     user_allowed(cupsd_printer_t *p, const char *username);
 static void    validate_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static int     validate_name(const char *name);
@@ -211,7 +238,7 @@ static int  validate_user(cupsd_job_t *job, cupsd_client_t *con,
 
 
 /*
- * 'cupsdProcessIPPRequest()' - Process an incoming IPP request...
+ * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -222,7 +249,7 @@ cupsdProcessIPPRequest(
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_attribute_t      *charset;       /* Character set attribute */
   ipp_attribute_t      *language;      /* Language attribute */
-  ipp_attribute_t      *uri;           /* Printer URI attribute */
+  ipp_attribute_t      *uri = NULL;    /* Printer or job URI attribute */
   ipp_attribute_t      *username;      /* requesting-user-name attr */
   int                  sub_id;         /* Subscription ID */
 
@@ -237,14 +264,17 @@ cupsdProcessIPPRequest(
 
   con->response = ippNew();
 
-  con->response->request.status.version[0] = con->request->request.op.version[0];
-  con->response->request.status.version[1] = con->request->request.op.version[1];
-  con->response->request.status.request_id = con->request->request.op.request_id;
+  con->response->request.status.version[0] =
+      con->request->request.op.version[0];
+  con->response->request.status.version[1] =
+      con->request->request.op.version[1];
+  con->response->request.status.request_id =
+      con->request->request.op.request_id;
 
  /*
   * Then validate the request header and required attributes...
   */
-  
+
   if (con->request->request.any.version[0] != 1)
   {
    /*
@@ -261,7 +291,7 @@ cupsdProcessIPPRequest(
                     _("Bad request version number %d.%d!"),
                    con->request->request.any.version[0],
                    con->request->request.any.version[1]);
-  }  
+  }
   else if (!con->request->attrs)
   {
     cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
@@ -330,12 +360,15 @@ cupsdProcessIPPRequest(
       else if ((attr = ippFindAttribute(con->request, "job-uri",
                                         IPP_TAG_URI)) != NULL)
        uri = attr;
+      else if (con->request->request.op.operation_id == CUPS_GET_PPD)
+        uri = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME);
       else
        uri = NULL;
 
       if (charset)
        ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                    "attributes-charset", NULL, charset->values[0].string.text);
+                    "attributes-charset", NULL,
+                    charset->values[0].string.text);
       else
        ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
                     "attributes-charset", NULL, DefaultCharset);
@@ -348,13 +381,31 @@ cupsdProcessIPPRequest(
        ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                      "attributes-natural-language", NULL, DefaultLanguage);
 
-      if (!charset || !language ||
-         (!uri &&
-          con->request->request.op.operation_id != CUPS_GET_DEFAULT &&
-          con->request->request.op.operation_id != CUPS_GET_PRINTERS &&
-          con->request->request.op.operation_id != CUPS_GET_CLASSES &&
-          con->request->request.op.operation_id != CUPS_GET_DEVICES &&
-          con->request->request.op.operation_id != CUPS_GET_PPDS))
+      if (charset &&
+          strcasecmp(charset->values[0].string.text, "us-ascii") &&
+          strcasecmp(charset->values[0].string.text, "utf-8"))
+      {
+       /*
+        * Bad character set...
+       */
+
+        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\"!"),
+                       charset->values[0].string.text);
+      }
+      else if (!charset || !language ||
+              (!uri &&
+               con->request->request.op.operation_id != CUPS_GET_DEFAULT &&
+               con->request->request.op.operation_id != CUPS_GET_PRINTERS &&
+               con->request->request.op.operation_id != CUPS_GET_CLASSES &&
+               con->request->request.op.operation_id != CUPS_GET_DEVICES &&
+               con->request->request.op.operation_id != CUPS_GET_PPDS))
       {
        /*
        * Return an error, since attributes-charset,
@@ -385,17 +436,18 @@ cupsdProcessIPPRequest(
         if (!uri)
        {
          cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Missing printer-uri or job-uri attribute!");
+                         "Missing printer-uri, job-uri, or ppd-name "
+                         "attribute!");
 
          cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
-                       "%04X %s Missing printer-uri or job-uri attribute",
-                       IPP_BAD_REQUEST, con->http.hostname);
+                       "%04X %s Missing printer-uri, job-uri, or ppd-name "
+                       "attribute", IPP_BAD_REQUEST, con->http.hostname);
         }
 
        cupsdLogMessage(CUPSD_LOG_DEBUG, "Request attributes follow...");
 
        for (attr = con->request->attrs; attr; attr = attr->next)
-         cupsdLogMessage(CUPSD_LOG_DEBUG, 
+         cupsdLogMessage(CUPSD_LOG_DEBUG,
                          "attr \"%s\": group_tag = %x, value_tag = %x",
                          attr->name ? attr->name : "(null)", attr->group_tag,
                          attr->value_tag);
@@ -558,6 +610,14 @@ cupsdProcessIPPRequest(
               get_devices(con);
               break;
 
+          case CUPS_GET_DOCUMENT :
+             get_document(con, uri);
+             break;
+
+         case CUPS_GET_PPD :
+              get_ppd(con, uri);
+              break;
+
          case CUPS_GET_PPDS :
               get_ppds(con);
               break;
@@ -604,7 +664,8 @@ cupsdProcessIPPRequest(
 
               send_ipp_status(con, IPP_OPERATION_NOT_SUPPORTED,
                              _("%s not supported!"),
-                             ippOpString(con->request->request.op.operation_id));
+                             ippOpString(
+                                 con->request->request.op.operation_id));
              break;
        }
       }
@@ -617,38 +678,72 @@ cupsdProcessIPPRequest(
     * Sending data from the scheduler...
     */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "cupsdProcessIPPRequest: %d status_code=%x (%s)",
-                    con->http.fd, con->response->request.status.status_code,
-                   ippErrorString(con->response->request.status.status_code));
+    cupsdLogMessage(con->response->request.status.status_code
+                        >= IPP_BAD_REQUEST &&
+                    con->response->request.status.status_code
+                       != IPP_NOT_FOUND ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG,
+                    "Returning IPP %s for %s (%s) from %s",
+                   ippErrorString(con->response->request.status.status_code),
+                   ippOpString(con->request->request.op.operation_id),
+                   uri ? uri->values[0].string.text : "no URI",
+                   con->http.hostname);
 
-    if (cupsdSendHeader(con, HTTP_OK, "application/ipp"))
+    if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
     {
+#ifdef CUPSD_USE_CHUNKING
+     /*
+      * Because older versions of CUPS (1.1.17 and older) and some IPP
+      * clients do not implement chunking properly, we cannot use
+      * chunking by default.  This may become the default in future
+      * CUPS releases, or we might add a configuration directive for
+      * it.
+      */
+
       if (con->http.version == HTTP_1_1)
       {
-       con->http.data_encoding = HTTP_ENCODE_CHUNKED;
+       if (httpPrintf(HTTP(con), "Transfer-Encoding: chunked\r\n\r\n") < 0)
+         return (0);
+
+       if (cupsdFlushHeader(con) < 0)
+         return (0);
 
-       httpPrintf(HTTP(con), "Transfer-Encoding: chunked\r\n\r\n");
+       con->http.data_encoding = HTTP_ENCODE_CHUNKED;
       }
       else
+#endif /* CUPSD_USE_CHUNKING */
       {
+        size_t length;                 /* Length of response */
+
+
+       length = ippLength(con->response);
+
+       if (con->file >= 0 && !con->pipe_pid)
+       {
+         struct stat   fileinfo;       /* File information */
+
+
+          if (!fstat(con->file, &fileinfo))
+           length += fileinfo.st_size;
+       }
+
+       if (httpPrintf(HTTP(con), "Content-Length: " CUPS_LLFMT "\r\n\r\n",
+                      CUPS_LLCAST length) < 0)
+         return (0);
+
+       if (cupsdFlushHeader(con) < 0)
+         return (0);
+
        con->http.data_encoding  = HTTP_ENCODE_LENGTH;
-       con->http.data_remaining = ippLength(con->response);
+       con->http.data_remaining = length;
 
-        if (con->http.data_remaining < INT_MAX)
+       if (con->http.data_remaining <= INT_MAX)
          con->http._data_remaining = con->http.data_remaining;
        else
          con->http._data_remaining = INT_MAX;
-
-       httpPrintf(HTTP(con), "Content-Length: " CUPS_LLFMT "\r\n\r\n",
-                  CUPS_LLCAST con->http.data_remaining);
       }
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdProcessIPPRequest: Adding fd %d to OutputSet...",
-                     con->http.fd);
-
-      FD_SET(con->http.fd, OutputSet);
+      cupsdAddSelect(con->http.fd, (cupsd_selfunc_t)cupsdReadClient,
+                     (cupsd_selfunc_t)cupsdWriteClient, con);
 
      /*
       * Tell the caller the response header was sent successfully...
@@ -677,6 +772,48 @@ cupsdProcessIPPRequest(
 }
 
 
+/*
+ * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsdTimeoutJob(cupsd_job_t *job)      /* I - Job to timeout */
+{
+  cupsd_printer_t      *printer;       /* Destination printer or class */
+  ipp_attribute_t      *attr;          /* job-sheets attribute */
+  int                  kbytes;         /* Kilobytes in banner */
+
+
+  job->pending_timeout = 0;
+
+ /*
+  * See if we need to add the ending sheet...
+  */
+
+  printer = cupsdFindDest(job->dest);
+  attr    = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME);
+
+  if (printer &&
+      !(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
+      attr && attr->num_values > 1)
+  {
+   /*
+    * Yes...
+    */
+
+    cupsdLogJob(job, CUPSD_LOG_INFO, "Adding end banner page \"%s\".",
+                attr->values[1].string.text);
+
+    if ((kbytes = copy_banner(NULL, job, attr->values[1].string.text)) < 0)
+      return (-1);
+
+    cupsdUpdateQuota(printer, job->username, 0, kbytes);
+  }
+
+  return (0);
+}
+
+
 /*
  * 'accept_jobs()' - Accept print jobs to a printer.
  */
@@ -686,13 +823,7 @@ accept_jobs(cupsd_client_t  *con,  /* I - Client connection */
             ipp_attribute_t *uri)      /* I - Printer or class URI */
 {
   http_status_t        status;                 /* Policy status */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
-  char         method[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 */
-  const char   *name;                  /* Printer name */
+  cups_ptype_t dtype;                  /* Destination type (printer/class) */
   cupsd_printer_t *printer;            /* Printer data */
 
 
@@ -703,11 +834,7 @@ accept_jobs(cupsd_client_t  *con,  /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -724,7 +851,7 @@ accept_jobs(cupsd_client_t  *con,   /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -738,12 +865,20 @@ accept_jobs(cupsd_client_t  *con, /* I - Client connection */
   cupsdAddPrinterHistory(printer);
 
   if (dtype & CUPS_PRINTER_CLASS)
-    cupsdSaveAllClasses();
+  {
+    cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
+
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" now accepting jobs (\"%s\").",
+                    printer->name, get_username(con));
+  }
   else
-    cupsdSaveAllPrinters();
+  {
+    cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" now accepting jobs (\"%s\").", name,
-                  get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Printer \"%s\" now accepting jobs (\"%s\").",
+                    printer->name, get_username(con));
+  }
 
  /*
   * Everything was ok, so return OK status...
@@ -771,7 +906,6 @@ add_class(cupsd_client_t  *con,             /* I - Client connection */
   cupsd_printer_t *pclass,             /* Class */
                *member;                /* Member printer/class */
   cups_ptype_t dtype;                  /* Destination type */
-  const char   *dest;                  /* Printer or class name */
   ipp_attribute_t *attr;               /* Printer attribute */
   int          modify;                 /* Non-zero if we just modified */
   char         newname[IPP_MAX_NAME];  /* New class name */
@@ -818,16 +952,6 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
     return;
   }
 
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-
  /*
   * See if the class already exists; if not, create a new class...
   */
@@ -839,7 +963,7 @@ add_class(cupsd_client_t  *con,             /* I - Client connection */
     */
 
     if ((pclass = cupsdFindPrinter(resource + 9)) != NULL &&
-        !(pclass->type & CUPS_PRINTER_REMOTE))
+        !(pclass->type & CUPS_PRINTER_DISCOVERED))
     {
      /*
       * Yes, return an error...
@@ -852,18 +976,31 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
     }
 
    /*
-    * No, add the pclass...
+    * No, check the default policy and then add the class...
     */
 
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
     pclass = cupsdAddClass(resource + 9);
     modify = 0;
   }
   else if (pclass->type & CUPS_PRINTER_IMPLICIT)
   {
    /*
-    * Rename the implicit class to "AnyClass" or remove it...
+    * Check the default policy, then rename the implicit class to "AnyClass"
+    * or remove it...
     */
 
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
     if (ImplicitAnyClasses)
     {
       snprintf(newname, sizeof(newname), "Any%s", resource + 9);
@@ -879,12 +1016,18 @@ add_class(cupsd_client_t  *con,          /* I - Client connection */
     pclass = cupsdAddClass(resource + 9);
     modify = 0;
   }
-  else if (pclass->type & CUPS_PRINTER_REMOTE)
+  else if (pclass->type & CUPS_PRINTER_DISCOVERED)
   {
    /*
-    * Rename the remote class to "Class"...
+    * Check the default policy, then rename the remote class to "Class"...
     */
 
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
     snprintf(newname, sizeof(newname), "%s@%s", resource + 9, pclass->hostname);
     cupsdRenamePrinter(pclass, newname);
 
@@ -895,6 +1038,12 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
     pclass = cupsdAddClass(resource + 9);
     modify = 0;
   }
+  else if ((status = cupsdCheckPolicy(pclass->op_policy_ptr, con,
+                                      NULL)) != HTTP_OK)
+  {
+    send_http_error(con, status, pclass);
+    return;
+  }
   else
     modify = 1;
 
@@ -915,8 +1064,9 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
   if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
                                IPP_TAG_BOOLEAN)) != NULL)
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-is-accepting-jobs to %d (was %d.)",
-               pclass->name, attr->values[0].boolean, pclass->accepting);
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Setting %s printer-is-accepting-jobs to %d (was %d.)",
+                    pclass->name, attr->values[0].boolean, pclass->accepting);
 
     pclass->accepting = attr->values[0].boolean;
     cupsdAddPrinterHistory(pclass);
@@ -926,7 +1076,7 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
                                IPP_TAG_BOOLEAN)) != NULL)
   {
     if (pclass->shared && !attr->values[0].boolean)
-      cupsdSendBrowseDelete(pclass);
+      cupsdDeregisterPrinter(pclass, 1);
 
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s printer-is-shared to %d (was %d.)",
@@ -947,8 +1097,8 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
       return;
     }
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)", pclass->name,
-                    attr->values[0].integer, pclass->state);
+    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)",
+                    pclass->name, attr->values[0].integer, pclass->state);
 
     if (attr->values[0].integer == IPP_PRINTER_STOPPED)
       cupsdStopPrinter(pclass, 0);
@@ -990,11 +1140,7 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
       * Search for the printer or class URI...
       */
 
-      httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[i].string.text, method,
-                      sizeof(method), username, sizeof(username), host,
-                     sizeof(host), &port, resource, sizeof(resource));
-
-      if ((dest = cupsdValidateDest(host, resource, &dtype, &member)) == NULL)
+      if (!cupsdValidateDest(attr->values[i].string.text, &dtype, &member))
       {
        /*
        * Bad URI...
@@ -1015,12 +1161,16 @@ add_class(cupsd_client_t  *con,         /* I - Client connection */
 
   set_printer_defaults(con, pclass);
 
+  if ((attr = ippFindAttribute(con->request, "auth-info-required",
+                               IPP_TAG_KEYWORD)) != NULL)
+    cupsdSetAuthInfoRequired(pclass, NULL, attr);
+
  /*
   * Update the printer class attributes and return...
   */
 
   cupsdSetPrinterAttrs(pclass);
-  cupsdSaveAllClasses();
+  cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
 
   if (need_restart_job && pclass->job)
   {
@@ -1041,7 +1191,7 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
   if (need_restart_job)
     cupsdCheckJobs();
 
-  cupsdWritePrintcap();
+  cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
 
   if (modify)
   {
@@ -1083,9 +1233,9 @@ add_file(cupsd_client_t *con,             /* I - Connection to client */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                 "add_file(con=%p[%d], job=%d, filetype=%s/%s, compression=%d)",
-                 con, con->http.fd, job->id, filetype->super, filetype->type,
-                 compression);
+                 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
+                 "compression=%d)", con, con ? con->http.fd : -1, job->id,
+                 filetype->super, filetype->type, compression);
 
  /*
   * Add the file to the job...
@@ -1107,10 +1257,12 @@ add_file(cupsd_client_t *con,           /* I - Connection to client */
 
   if (!compressions || !filetypes)
   {
-    cupsdCancelJob(job, 1);
+    cupsdCancelJob(job, 1, IPP_JOB_ABORTED);
+
+    if (con)
+      send_ipp_status(con, IPP_INTERNAL_ERROR,
+                     _("Unable to allocate memory for file types!"));
 
-    send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("Unable to allocate memory for file types!"));
     return (-1);
   }
 
@@ -1121,6 +1273,9 @@ add_file(cupsd_client_t *con,             /* I - Connection to client */
 
   job->num_files ++;
 
+  job->dirty = 1;
+  cupsdMarkDirty(CUPSD_DIRTY_JOBS);
+
   return (0);
 }
 
@@ -1131,54 +1286,26 @@ add_file(cupsd_client_t *con,           /* I - Connection to client */
 
 static cupsd_job_t *                   /* O - Job object */
 add_job(cupsd_client_t  *con,          /* I - Client connection */
-        ipp_attribute_t *uri,          /* I - printer-uri */
-       cupsd_printer_t **dprinter,     /* I - Destination printer */
+       cupsd_printer_t *printer,       /* I - Destination printer */
        mime_type_t     *filetype)      /* I - First print file type, if any */
 {
   http_status_t        status;                 /* Policy status */
-  ipp_attribute_t *attr;               /* Current attribute */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  ipp_attribute_t *attr,               /* Current attribute */
+               *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 */
-               method[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_printer_t *printer;            /* Printer data */
+  char         job_uri[HTTP_MAX_URI];  /* Job URI */
   int          kbytes;                 /* Size of print file */
   int          i;                      /* Looping var */
   int          lowerpagerange;         /* Page range bound */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %s)", con,
-                  con->http.fd, uri->values[0].string.text);
-
- /*
-  * Is the destination valid?
-  */
-
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
-  {
-   /*
-    * Bad URI...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return (NULL);
-  }
-
-  if (dprinter)
-    *dprinter = printer;
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
+                  con, con->http.fd, printer, printer->name,
+                 filetype, filetype ? filetype->super : "none",
+                 filetype ? filetype->type : "none");
 
  /*
   * Check remote printing to non-shared printer...
@@ -1197,16 +1324,32 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   * Check policy...
   */
 
+  auth_info = ippFindAttribute(con->request, "auth-info", IPP_TAG_TEXT);
+
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    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)
+  {
+    send_http_error(con, HTTP_UNAUTHORIZED, printer);
     return (NULL);
   }
-  else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
+#ifdef HAVE_SSL
+  else if (auth_info && !con->http.tls &&
+           !httpAddrLocalhost(con->http.hostaddr))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED);
+   /*
+    * Require encryption of auth-info over non-local connections...
+    */
+
+    send_http_error(con, HTTP_UPGRADE_REQUIRED, printer);
     return (NULL);
   }
+#endif /* HAVE_SSL */
 
  /*
   * See if the printer is accepting jobs...
@@ -1216,13 +1359,13 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   {
     send_ipp_status(con, IPP_NOT_ACCEPTING,
                     _("Destination \"%s\" is not accepting jobs."),
-                    dest);
+                    printer->name);
     return (NULL);
   }
 
  /*
   * Validate job template attributes; for now just document-format,
-  * copies, and page-ranges...
+  * copies, number-up, and page-ranges...
   */
 
   if (filetype && printer->filetypes &&
@@ -1257,12 +1400,58 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
     }
   }
 
+  if ((attr = ippFindAttribute(con->request, "job-sheets",
+                               IPP_TAG_ZERO)) != NULL)
+  {
+    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!"));
+      return (NULL);
+    }
+
+    if (attr->num_values > 2)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Too many job-sheets values (%d > 2)!"),
+                     attr->num_values);
+      return (NULL);
+    }
+
+    for (i = 0; i < attr->num_values; i ++)
+      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\"!"),
+                       attr->values[i].string.text);
+       return (NULL);
+      }
+  }
+
+  if ((attr = ippFindAttribute(con->request, "number-up",
+                               IPP_TAG_INTEGER)) != NULL)
+  {
+    if (attr->values[0].integer != 1 &&
+        attr->values[0].integer != 2 &&
+        attr->values[0].integer != 4 &&
+        attr->values[0].integer != 6 &&
+        attr->values[0].integer != 9 &&
+        attr->values[0].integer != 16)
+    {
+      send_ipp_status(con, IPP_ATTRIBUTES, _("Bad number-up value %d."),
+                      attr->values[0].integer);
+      ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
+                   "number-up", attr->values[0].integer);
+      return (NULL);
+    }
+  }
+
   if ((attr = ippFindAttribute(con->request, "page-ranges",
                                IPP_TAG_RANGE)) != NULL)
   {
     for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
     {
-      if (attr->values[i].range.lower < lowerpagerange || 
+      if (attr->values[i].range.lower < lowerpagerange ||
          attr->values[i].range.lower > attr->values[i].range.upper)
       {
        send_ipp_status(con, IPP_BAD_REQUEST,
@@ -1283,18 +1472,23 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
     cupsdCleanJobs();
 
-  if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
+  if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
   {
     send_ipp_status(con, IPP_NOT_POSSIBLE,
                     _("Too many active jobs."));
     return (NULL);
   }
 
-  if (!check_quotas(con, printer))
+  if ((i = check_quotas(con, printer)) < 0)
   {
     send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
     return (NULL);
   }
+  else if (i == 0)
+  {
+    send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Not allowed to print."));
+    return (NULL);
+  }
 
  /*
   * Create the job and set things up...
@@ -1325,13 +1519,18 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   if ((job = cupsdAddJob(priority, printer->name)) == NULL)
   {
     send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("Unable to add job for destination \"%s\"!"), dest);
+                    _("Unable to add job for destination \"%s\"!"),
+                   printer->name);
     return (NULL);
   }
 
-  job->dtype   = dtype;
+  job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
+                                  CUPS_PRINTER_REMOTE);
   job->attrs   = con->request;
-  con->request = NULL;
+  job->dirty   = 1;
+  con->request = ippNewRequest(job->attrs->request.op.operation_id);
+
+  cupsdMarkDirty(CUPSD_DIRTY_JOBS);
 
   add_job_uuid(con, job);
   apply_printer_defaults(printer, job);
@@ -1344,8 +1543,6 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
 
     if (attr)
       cupsdSetString(&attr->values[0].string.text, con->username);
-
-    save_auth_info(con, job);
   }
   else if (attr)
   {
@@ -1368,6 +1565,18 @@ add_job(cupsd_client_t  *con,            /* I - Client connection */
     attr->name = _cupsStrAlloc("job-originating-user-name");
   }
 
+  if (con->username[0] || auth_info)
+  {
+    save_auth_info(con, job, auth_info);
+
+   /*
+    * Remove the auth-info attribute from the attribute data...
+    */
+
+    if (auth_info)
+      ippDeleteAttribute(job->attrs, auth_info);
+  }
+
   if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
                                IPP_TAG_ZERO)) != NULL)
   {
@@ -1434,7 +1643,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
     * the connection...
     */
 
-    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
+    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
                 "job-originating-host-name", NULL, con->http.hostname);
   }
 
@@ -1454,7 +1663,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
   ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
   job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
                              "job-state", IPP_JOB_STOPPED);
-  job->state_value = job->state->values[0].integer;
+  job->state_value = (ipp_jstate_t)job->state->values[0].integer;
   job->sheets = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
                               "job-media-sheets-completed", 0);
   ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL,
@@ -1466,8 +1675,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
                                IPP_TAG_INTEGER)) != NULL)
     attr->values[0].integer = 0;
   else
-    attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                         "job-k-octets", 0);
+    ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-k-octets", 0);
 
   if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
                                IPP_TAG_KEYWORD)) == NULL)
@@ -1550,10 +1758,10 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
 
           cupsdSetString(&attr->values[0].string.text, Classification);
 
-         cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
-                                           "job-sheets=\"%s,none\", "
-                                           "job-originating-user-name=\"%s\"",
-                        job->id, Classification, job->username);
+         cupsdLogJob(job, CUPSD_LOG_NOTICE, "CLASSIFICATION FORCED "
+                                            "job-sheets=\"%s,none\", "
+                                            "job-originating-user-name=\"%s\"",
+                     Classification, job->username);
        }
        else if (attr->num_values == 2 &&
                 strcmp(attr->values[0].string.text,
@@ -1567,11 +1775,11 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
 
           cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
 
-         cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
-                                           "job-sheets=\"%s,%s\", "
-                                           "job-originating-user-name=\"%s\"",
-                        job->id, attr->values[0].string.text,
-                        attr->values[1].string.text, job->username);
+         cupsdLogJob(job, CUPSD_LOG_NOTICE, "CLASSIFICATION FORCED "
+                                            "job-sheets=\"%s,%s\", "
+                                            "job-originating-user-name=\"%s\"",
+                     attr->values[0].string.text,
+                     attr->values[1].string.text, job->username);
        }
        else if (strcmp(attr->values[0].string.text, Classification) &&
                 strcmp(attr->values[0].string.text, "none") &&
@@ -1580,18 +1788,18 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
                   strcmp(attr->values[1].string.text, "none"))))
         {
          if (attr->num_values == 1)
-            cupsdLogMessage(CUPSD_LOG_NOTICE,
-                           "[Job %d] CLASSIFICATION OVERRIDDEN "
-                           "job-sheets=\"%s\", "
-                           "job-originating-user-name=\"%s\"",
-                      job->id, attr->values[0].string.text, job->username);
+            cupsdLogJob(job, CUPSD_LOG_NOTICE,
+                       "CLASSIFICATION OVERRIDDEN "
+                       "job-sheets=\"%s\", "
+                       "job-originating-user-name=\"%s\"",
+                       attr->values[0].string.text, job->username);
           else
-            cupsdLogMessage(CUPSD_LOG_NOTICE,
-                           "[Job %d] CLASSIFICATION OVERRIDDEN "
-                           "job-sheets=\"%s,%s\",fffff "
-                           "job-originating-user-name=\"%s\"",
-                           job->id, attr->values[0].string.text,
-                           attr->values[1].string.text, job->username);
+            cupsdLogJob(job, CUPSD_LOG_NOTICE,
+                       "CLASSIFICATION OVERRIDDEN "
+                       "job-sheets=\"%s,%s\",fffff "
+                       "job-originating-user-name=\"%s\"",
+                       attr->values[0].string.text,
+                       attr->values[1].string.text, job->username);
         }
       }
       else if (strcmp(attr->values[0].string.text, Classification) &&
@@ -1620,18 +1828,18 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
         }
 
         if (attr->num_values > 1)
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s,%s\", "
-                         "job-originating-user-name=\"%s\"",
-                         job->id, attr->values[0].string.text,
-                         attr->values[1].string.text, job->username);
+         cupsdLogJob(job, CUPSD_LOG_NOTICE,
+                     "CLASSIFICATION FORCED "
+                     "job-sheets=\"%s,%s\", "
+                     "job-originating-user-name=\"%s\"",
+                     attr->values[0].string.text,
+                     attr->values[1].string.text, job->username);
         else
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s\", "
-                         "job-originating-user-name=\"%s\"",
-                        job->id, Classification, job->username);
+         cupsdLogJob(job, CUPSD_LOG_NOTICE,
+                     "CLASSIFICATION FORCED "
+                     "job-sheets=\"%s\", "
+                     "job-originating-user-name=\"%s\"",
+                     Classification, job->username);
       }
     }
 
@@ -1641,11 +1849,14 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
 
     if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
     {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Adding start banner page \"%s\" to job %d.",
-                      attr->values[0].string.text, job->id);
+      cupsdLogJob(job, CUPSD_LOG_INFO, "Adding start banner page \"%s\".",
+                 attr->values[0].string.text);
 
-      kbytes = copy_banner(con, job, attr->values[0].string.text);
+      if ((kbytes = copy_banner(con, job, attr->values[0].string.text)) < 0)
+      {
+        cupsdDeleteJob(job);
+        return (NULL);
+      }
 
       cupsdUpdateQuota(printer, job->username, 0, kbytes);
     }
@@ -1715,7 +1926,7 @@ add_job_state_reasons(
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job_state_reasons(%p[%d], %d)",
                   con, con->http.fd, job ? job->id : 0);
 
-  switch (job ? job->state_value : IPP_JOB_CANCELLED)
+  switch (job ? job->state_value : IPP_JOB_CANCELED)
   {
     case IPP_JOB_PENDING :
        dest = cupsdFindDest(job->dest);
@@ -1750,7 +1961,7 @@ add_job_state_reasons(
                     "job-state-reasons", NULL, "job-stopped");
         break;
 
-    case IPP_JOB_CANCELLED :
+    case IPP_JOB_CANCELED :
         ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
                     "job-state-reasons", NULL, "job-canceled-by-user");
         break;
@@ -1769,7 +1980,7 @@ add_job_state_reasons(
 
 
 /*
- * 'add_job_subscriptions()' - Add any subcriptions for a job.
+ * 'add_job_subscriptions()' - Add any subscriptions for a job.
  */
 
 static void
@@ -1794,9 +2005,7 @@ add_job_subscriptions(
   * none...
   */
 
-  for (attr = job->attrs->attrs, prev = NULL;
-       attr;
-       prev = attr, attr = attr->next)
+  for (attr = job->attrs->attrs; attr; attr = attr->next)
     if (attr->group_tag == IPP_TAG_SUBSCRIPTION)
       break;
 
@@ -1817,12 +2026,72 @@ add_job_subscriptions(
 
     while (attr && attr->group_tag != IPP_TAG_ZERO)
     {
-      if (!strcmp(attr->name, "notify-recipient") &&
+      if (!strcmp(attr->name, "notify-recipient-uri") &&
           attr->value_tag == IPP_TAG_URI)
+      {
+       /*
+        * Validate the recipient scheme against the ServerBin/notifier
+       * directory...
+       */
+
+       char    notifier[1024],         /* Notifier filename */
+               scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
+               userpass[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 */
+
+
         recipient = attr->values[0].string.text;
+
+       if (httpSeparateURI(HTTP_URI_CODING_ALL, recipient,
+                           scheme, sizeof(scheme), userpass, sizeof(userpass),
+                           host, sizeof(host), &port,
+                           resource, sizeof(resource)) < HTTP_URI_OK)
+        {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("Bad notify-recipient-uri URI \"%s\"!"), recipient);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_URI_SCHEME);
+         return;
+       }
+
+        snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin,
+                scheme);
+        if (access(notifier, X_OK))
+       {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("notify-recipient-uri URI \"%s\" uses unknown "
+                           "scheme!"), recipient);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_URI_SCHEME);
+         return;
+       }
+
+        if (!strcmp(scheme, "rss") && !check_rss_recipient(recipient))
+       {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("notify-recipient-uri URI \"%s\" is already used!"),
+                         recipient);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_ATTRIBUTES);
+         return;
+       }
+      }
       else if (!strcmp(attr->name, "notify-pull-method") &&
                attr->value_tag == IPP_TAG_KEYWORD)
+      {
         pullmethod = attr->values[0].string.text;
+
+        if (strcmp(pullmethod, "ippget"))
+       {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("Bad notify-pull-method \"%s\"!"), pullmethod);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_ATTRIBUTES);
+         return;
+       }
+      }
       else if (!strcmp(attr->name, "notify-charset") &&
                attr->value_tag == IPP_TAG_CHARSET &&
               strcmp(attr->values[0].string.text, "us-ascii") &&
@@ -1904,10 +2173,13 @@ add_job_subscriptions(
       attr = attr->next;
   }
 
-  cupsdSaveAllSubscriptions();
+  cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
 
  /*
   * Remove all of the subscription attributes from the job request...
+  *
+  * TODO: Optimize this since subscription groups have to come at the
+  * end of the request...
   */
 
   for (attr = job->attrs->attrs, prev = NULL; attr; attr = next)
@@ -1948,7 +2220,6 @@ add_job_uuid(cupsd_client_t *con, /* I - Client connection */
              cupsd_job_t    *job)      /* I - Job */
 {
   char                 uuid[1024];     /* job-uuid string */
-  ipp_attribute_t      *attr;          /* job-uuid attribute */
   _cups_md5_state_t    md5state;       /* MD5 state */
   unsigned char                md5sum[16];     /* MD5 digest/sum */
 
@@ -1957,7 +2228,7 @@ add_job_uuid(cupsd_client_t *con, /* I - Client connection */
   * First see if the job already has a job-uuid attribute; if so, return...
   */
 
-  if ((attr = ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI)) != NULL)
+  if (ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI))
     return;
 
  /*
@@ -2000,7 +2271,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
 {
   http_status_t        status;                 /* Policy status */
   int          i;                      /* Looping var */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+  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 */
@@ -2014,6 +2285,8 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   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? */
+               set_port_monitor;       /* Did we set the port monitor? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con,
@@ -2023,8 +2296,8 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   * Do we have a valid URI?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
+                  sizeof(scheme), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (strncmp(resource, "/printers/", 10) || strlen(resource) == 10)
@@ -2055,16 +2328,6 @@ add_printer(cupsd_client_t  *con,        /* I - Client connection */
     return;
   }
 
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-
  /*
   * See if the printer already exists; if not, create a new printer...
   */
@@ -2076,7 +2339,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
     */
 
     if ((printer = cupsdFindClass(resource + 10)) != NULL &&
-        !(printer->type & CUPS_PRINTER_REMOTE))
+        !(printer->type & CUPS_PRINTER_DISCOVERED))
     {
      /*
       * Yes, return an error...
@@ -2089,18 +2352,31 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
     }
 
    /*
-    * No, add the printer...
+    * No, check the default policy then add the printer...
     */
 
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
     printer = cupsdAddPrinter(resource + 10);
     modify  = 0;
   }
   else if (printer->type & CUPS_PRINTER_IMPLICIT)
   {
    /*
-    * Rename the implicit printer to "AnyPrinter" or delete it...
+    * Check the default policy, then rename the implicit printer to
+    * "AnyPrinter" or delete it...
     */
 
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
     if (ImplicitAnyClasses)
     {
       snprintf(newname, sizeof(newname), "Any%s", resource + 10);
@@ -2116,13 +2392,20 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
     printer = cupsdAddPrinter(resource + 10);
     modify  = 0;
   }
-  else if (printer->type & CUPS_PRINTER_REMOTE)
+  else if (printer->type & CUPS_PRINTER_DISCOVERED)
   {
    /*
-    * Rename the remote printer to "Printer@server"...
+    * Check the default policy, then rename the remote printer to
+    * "Printer@server"...
     */
 
-    snprintf(newname, sizeof(newname), "%s@%s", resource + 10,
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
+    snprintf(newname, sizeof(newname), "%s@%s", resource + 10,
              printer->hostname);
     cupsdRenamePrinter(printer, newname);
 
@@ -2133,6 +2416,12 @@ add_printer(cupsd_client_t  *con,        /* I - Client connection */
     printer = cupsdAddPrinter(resource + 10);
     modify  = 0;
   }
+  else if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
+                                      NULL)) != HTTP_OK)
+  {
+    send_http_error(con, status, printer);
+    return;
+  }
   else
     modify = 1;
 
@@ -2150,6 +2439,8 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
                                IPP_TAG_TEXT)) != NULL)
     cupsdSetString(&printer->info, attr->values[0].string.text);
 
+  set_device_uri = 0;
+
   if ((attr = ippFindAttribute(con->request, "device-uri",
                                IPP_TAG_URI)) != NULL)
   {
@@ -2157,13 +2448,30 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
     * Do we have a valid device URI?
     */
 
+    http_uri_status_t  uri_status;     /* URI separation status */
+    char               old_device_uri[1024];
+                                       /* Old device URI */
+
+
     need_restart_job = 1;
 
-    httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
-                    sizeof(method), username, sizeof(username), host,
-                   sizeof(host), &port, resource, sizeof(resource));
+    uri_status = httpSeparateURI(HTTP_URI_CODING_ALL,
+                                attr->values[0].string.text,
+                                scheme, sizeof(scheme),
+                                username, sizeof(username),
+                                host, sizeof(host), &port,
+                                resource, sizeof(resource));
 
-    if (!strcmp(method, "file"))
+    if (uri_status < HTTP_URI_OK)
+    {
+      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);
+      return;
+    }
+
+    if (!strcmp(scheme, "file"))
     {
      /*
       * See if the administrator has enabled file devices...
@@ -2189,32 +2497,39 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
       * See if the backend exists and is executable...
       */
 
-      snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, method);
+      snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, scheme);
       if (access(srcfile, X_OK))
       {
        /*
         * Could not find device in list!
        */
 
-       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
-                       attr->values[0].string.text);
+       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri scheme \"%s\"!"),
+                       scheme);
        return;
       }
     }
 
+    if (printer->sanitized_device_uri)
+      strlcpy(old_device_uri, printer->sanitized_device_uri,
+              sizeof(old_device_uri));
+    else
+      old_device_uri[0] = '\0';
+
+    cupsdSetDeviceURI(printer, attr->values[0].string.text);
+
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s device-uri to \"%s\" (was \"%s\".)",
-                   printer->name,
-                   cupsdSanitizeURI(attr->values[0].string.text, line,
-                                    sizeof(line)),
-                   cupsdSanitizeURI(printer->device_uri, resource,
-                                    sizeof(resource)));
+                   printer->name, printer->sanitized_device_uri,
+                   old_device_uri);
 
-    cupsdSetString(&printer->device_uri, attr->values[0].string.text);
+    set_device_uri = 1;
   }
 
+  set_port_monitor = 0;
+
   if ((attr = ippFindAttribute(con->request, "port-monitor",
-                               IPP_TAG_KEYWORD)) != NULL)
+                               IPP_TAG_NAME)) != NULL)
   {
     ipp_attribute_t    *supported;     /* port-monitor-supported attribute */
 
@@ -2222,13 +2537,16 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
     need_restart_job = 1;
 
     supported = ippFindAttribute(printer->attrs, "port-monitor-supported",
-                                 IPP_TAG_KEYWORD);
-    for (i = 0; i < supported->num_values; i ++)
-      if (!strcmp(supported->values[i].string.text,
-                  attr->values[0].string.text))
-        break;
+                                 IPP_TAG_NAME);
+    if (supported)
+    {
+      for (i = 0; i < supported->num_values; i ++)
+        if (!strcmp(supported->values[i].string.text,
+                    attr->values[0].string.text))
+          break;
+    }
 
-    if (i >= supported->num_values)
+    if (!supported || i >= supported->num_values)
     {
       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
                      attr->values[0].string.text);
@@ -2238,12 +2556,14 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s port-monitor to \"%s\" (was \"%s\".)",
                     printer->name, attr->values[0].string.text,
-                   printer->port_monitor);
+                   printer->port_monitor ? printer->port_monitor : "none");
 
     if (strcmp(attr->values[0].string.text, "none"))
       cupsdSetString(&printer->port_monitor, attr->values[0].string.text);
     else
       cupsdClearString(&printer->port_monitor);
+
+    set_port_monitor = 1;
   }
 
   if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
@@ -2261,7 +2581,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
                                IPP_TAG_BOOLEAN)) != NULL)
   {
     if (printer->shared && !attr->values[0].boolean)
-      cupsdSendBrowseDelete(printer);
+      cupsdDeregisterPrinter(printer, 1);
 
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s printer-is-shared to %d (was %d.)",
@@ -2281,8 +2601,8 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
       return;
     }
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)", printer->name,
-               attr->values[0].integer, printer->state);
+    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)",
+                    printer->name, attr->values[0].integer, printer->state);
 
     if (attr->values[0].integer == IPP_PRINTER_STOPPED)
       cupsdStopPrinter(printer, 0);
@@ -2300,8 +2620,54 @@ add_printer(cupsd_client_t  *con,        /* I - Client connection */
     cupsdAddPrinterHistory(printer);
   }
 
+  if ((attr = ippFindAttribute(con->request, "printer-state-reasons",
+                               IPP_TAG_KEYWORD)) != NULL)
+  {
+    if (attr->num_values >
+            (int)(sizeof(printer->reasons) / sizeof(printer->reasons[0])))
+    {
+      send_ipp_status(con, IPP_NOT_POSSIBLE,
+                      _("Too many printer-state-reasons values (%d > %d)!"),
+                     attr->num_values,
+                     (int)(sizeof(printer->reasons) /
+                           sizeof(printer->reasons[0])));
+      return;
+    }
+
+    for (i = 0; i < printer->num_reasons; i ++)
+      _cupsStrFree(printer->reasons[i]);
+
+    printer->num_reasons = 0;
+    for (i = 0; i < attr->num_values; i ++)
+    {
+      if (!strcmp(attr->values[i].string.text, "none"))
+        continue;
+
+      printer->reasons[printer->num_reasons] =
+          _cupsStrAlloc(attr->values[i].string.text);
+
+      if (!strcmp(printer->reasons[printer->num_reasons], "paused") &&
+          printer->state != IPP_PRINTER_STOPPED)
+      {
+       cupsdLogMessage(CUPSD_LOG_INFO,
+                       "Setting %s printer-state to %d (was %d.)",
+                       printer->name, IPP_PRINTER_STOPPED, printer->state);
+       cupsdStopPrinter(printer, 0);
+      }
+
+      printer->num_reasons ++;
+    }
+
+    if (PrintcapFormat == PRINTCAP_PLIST)
+      cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+  }
+
   set_printer_defaults(con, printer);
 
+  if ((attr = ippFindAttribute(con->request, "auth-info-required",
+                               IPP_TAG_KEYWORD)) != NULL)
+    cupsdSetAuthInfoRequired(printer, NULL, attr);
+
  /*
   * See if we have all required attributes...
   */
@@ -2359,12 +2725,10 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
                          strerror(errno));
          return;
        }
-       else
-       {
-          cupsdLogMessage(CUPSD_LOG_DEBUG,
-                         "Copied interface script successfully!");
-          chmod(dstfile, 0755);
-       }
+
+       cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "Copied interface script successfully!");
+       chmod(dstfile, 0755);
       }
 
       snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
@@ -2384,12 +2748,19 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
                          strerror(errno));
          return;
        }
-       else
-       {
-          cupsdLogMessage(CUPSD_LOG_DEBUG,
-                         "Copied PPD file successfully!");
-          chmod(dstfile, 0644);
-       }
+
+       cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "Copied PPD file successfully!");
+       chmod(dstfile, 0644);
+
+#ifdef __APPLE__
+       /*
+        * (Re)register color profiles...
+       */
+
+        apple_unregister_profiles(printer);
+       apple_register_profiles(printer);
+#endif /* __APPLE__ */
       }
       else
       {
@@ -2439,12 +2810,61 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
         send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file!"));
        return;
       }
-      else
-      {
-        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                       "Copied PPD file successfully!");
-        chmod(dstfile, 0644);
-      }
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                     "Copied PPD file successfully!");
+      chmod(dstfile, 0644);
+
+#ifdef __APPLE__
+     /*
+      * (Re)register color profiles...
+      */
+
+      apple_unregister_profiles(printer);
+      apple_register_profiles(printer);
+#endif /* __APPLE__ */
+    }
+  }
+
+ /*
+  * If we set the device URI but not the port monitor, check which port
+  * monitor to use by default...
+  */
+
+  if (set_device_uri && !set_port_monitor)
+  {
+    ppd_file_t *ppd;                   /* PPD file */
+    ppd_attr_t *ppdattr;               /* cupsPortMonitor attribute */
+
+
+    httpSeparateURI(HTTP_URI_CODING_ALL, printer->device_uri, scheme,
+                    sizeof(scheme), username, sizeof(username), host,
+                   sizeof(host), &port, resource, sizeof(resource));
+
+    snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot,
+            printer->name);
+    if ((ppd = ppdOpenFile(srcfile)) != NULL)
+    {
+      for (ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
+          ppdattr;
+          ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
+        if (!strcmp(scheme, ppdattr->spec))
+       {
+         cupsdLogMessage(CUPSD_LOG_INFO,
+                         "Setting %s port-monitor to \"%s\" (was \"%s\".)",
+                         printer->name, ppdattr->value,
+                         printer->port_monitor ? printer->port_monitor
+                                               : "none");
+
+         if (strcmp(ppdattr->value, "none"))
+           cupsdSetString(&printer->port_monitor, ppdattr->value);
+         else
+           cupsdClearString(&printer->port_monitor);
+
+         break;
+       }
+
+      ppdClose(ppd);
     }
   }
 
@@ -2453,7 +2873,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   */
 
   cupsdSetPrinterAttrs(printer);
-  cupsdSaveAllPrinters();
+  cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
 
   if (need_restart_job && printer->job)
   {
@@ -2474,7 +2894,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   if (need_restart_job)
     cupsdCheckJobs();
 
-  cupsdWritePrintcap();
+  cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
 
   if (modify)
   {
@@ -2549,6 +2969,550 @@ add_queued_job_count(
 }
 
 
+#ifdef __APPLE__
+/*
+ * 'apple_init_profile()' - Initialize a color profile.
+ */
+
+static void
+apple_init_profile(
+    ppd_file_t          *ppd,          /* I - PPD file */
+    cups_array_t       *languages,     /* I - Languages in the PPD file */
+    CMDeviceProfileInfo *profile,      /* I - Profile record */
+    unsigned            id,            /* I - Profile ID */
+    const char          *name,         /* I - Profile name */
+    const char          *text,         /* I - Profile UI text */
+    const char          *iccfile)      /* I - ICC filename */
+{
+  char                 url[1024];      /* URL for profile filename */
+  CFMutableDictionaryRef dict;         /* Dictionary for name */
+  char                 *language;      /* Current language */
+  ppd_attr_t           *attr;          /* Profile attribute */
+  CFStringRef          cflang,         /* Language string */
+                       cftext;         /* Localized text */
+
+
+ /*
+  * Build the profile name dictionary...
+  */
+
+  dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                  &kCFTypeDictionaryKeyCallBacks,
+                                  &kCFTypeDictionaryValueCallBacks);
+
+  cftext = CFStringCreateWithCString(kCFAllocatorDefault, text,
+                                    kCFStringEncodingUTF8);
+
+  if (cftext)
+  {
+    CFDictionarySetValue(dict, CFSTR("en"), cftext);
+    CFRelease(cftext);
+  }
+
+  if (languages)
+  {
+   /*
+    * Find localized names for the color profiles...
+    */
+
+    cupsArraySave(ppd->sorted_attrs);
+
+    for (language = (char *)cupsArrayFirst(languages);
+        language;
+        language = (char *)cupsArrayNext(languages))
+    {
+      if (iccfile)
+      {
+        if ((attr = _ppdLocalizedAttr(ppd, "cupsICCProfile", name,
+                                     language)) == NULL)
+         attr = _ppdLocalizedAttr(ppd, "APTiogaProfile", name, language);
+      }
+      else
+        attr = _ppdLocalizedAttr(ppd, "ColorModel", name, language);
+
+      if (attr && attr->text[0])
+      {
+       cflang = CFStringCreateWithCString(kCFAllocatorDefault, language,
+                                          kCFStringEncodingUTF8);
+       cftext = CFStringCreateWithCString(kCFAllocatorDefault, attr->text,
+                                          kCFStringEncodingUTF8);
+
+        if (cflang && cftext)
+         CFDictionarySetValue(dict, cflang, cftext);
+
+        if (cflang)
+         CFRelease(cflang);
+
+        if (cftext)
+         CFRelease(cftext);
+      }
+    }
+
+    cupsArrayRestore(ppd->sorted_attrs);
+  }
+
+ /*
+  * Fill in the profile data...
+  */
+
+  if (iccfile)
+    httpAssembleURI(HTTP_URI_CODING_ALL, url, sizeof(url), "file", NULL, "", 0,
+                   iccfile);
+
+  profile->dataVersion        = cmDeviceProfileInfoVersion1;
+  profile->profileID          = id;
+  profile->profileLoc.locType = iccfile ? cmPathBasedProfile : cmNoProfileBase;
+  profile->profileName        = dict;
+
+  if (iccfile)
+    strlcpy(profile->profileLoc.u.pathLoc.path, iccfile,
+           sizeof(profile->profileLoc.u.pathLoc.path));
+}
+
+
+/*
+ * 'apple_register_profiles()' - Register color profiles for a printer.
+ */
+
+static void
+apple_register_profiles(
+    cupsd_printer_t *p)                        /* I - Printer */
+{
+  int                  i;              /* Looping var */
+  char                 ppdfile[1024],  /* PPD filename */
+                       iccfile[1024],  /* ICC filename */
+                       selector[PPD_MAX_NAME];
+                                       /* Profile selection string */
+  ppd_file_t           *ppd;           /* PPD file */
+  ppd_attr_t           *attr,          /* Profile attributes */
+                       *profileid_attr,/* cupsProfileID attribute */
+                       *q1_attr,       /* ColorModel (or other) qualifier */
+                       *q2_attr,       /* MediaType (or other) qualifier */
+                       *q3_attr;       /* Resolution (or other) qualifier */
+  char                 q_keyword[PPD_MAX_NAME];
+                                       /* Qualifier keyword */
+  const char           *q1_choice,     /* ColorModel (or other) choice */
+                       *q2_choice,     /* MediaType (or other) choice */
+                       *q3_choice;     /* Resolution (or other) choice */
+  const char           *profile_key;   /* Profile keyword */
+  ppd_option_t         *cm_option;     /* Color model option */
+  ppd_choice_t         *cm_choice;     /* Color model choice */
+  int                  num_profiles;   /* Number of profiles */
+  CMError              error;          /* Last error */
+  unsigned             device_id,      /* Printer device ID */
+                       profile_id,     /* Profile ID */
+                       default_profile_id = 0;
+                                       /* Default profile ID */
+  CFMutableDictionaryRef device_name;  /* Printer device name dictionary */
+  CFStringRef          printer_name;   /* Printer name string */
+  CMDeviceScope                scope =         /* Scope of the registration */
+                       {
+                         kCFPreferencesAnyUser,
+                         kCFPreferencesCurrentHost
+                       };
+  CMDeviceProfileArrayPtr profiles;    /* Profiles */
+  CMDeviceProfileInfo  *profile;       /* Current profile */
+  cups_array_t         *languages;     /* Languages array */
+
+
+ /*
+  * Make sure ColorSync is available...
+  */
+
+  if (CMRegisterColorDevice == NULL)
+    return;
+
+ /*
+  * Try opening the PPD file for this printer...
+  */
+
+  snprintf(ppdfile, sizeof(ppdfile), "%s/ppd/%s.ppd", ServerRoot, p->name);
+  if ((ppd = ppdOpenFile(ppdfile)) == NULL)
+    return;
+
+ /*
+  * See if we have any profiles...
+  */
+
+  if ((attr = ppdFindAttr(ppd, "APTiogaProfile", NULL)) != NULL)
+    profile_key = "APTiogaProfile";
+  else
+  {
+    attr = ppdFindAttr(ppd, "cupsICCProfile", NULL);
+    profile_key = "cupsICCProfile";
+  }
+
+  for (num_profiles = 0; attr; attr = ppdFindNextAttr(ppd, profile_key, NULL))
+    if (attr->spec[0] && attr->value && attr->value[0])
+    {
+      if (attr->value[0] != '/')
+       snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir,
+                attr->value);
+      else
+       strlcpy(iccfile, attr->value, sizeof(iccfile));
+
+      if (access(iccfile, 0))
+       continue;
+
+      num_profiles ++;
+    }
+
+  
+ /*
+  * If we have profiles, add them...
+  */
+
+  if (num_profiles > 0)
+  {
+    if (profile_key[0] == 'A')
+    {
+     /*
+      * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
+      * attribute...
+      */
+
+      if ((attr = ppdFindAttr(ppd, "DefaultAPTiogaProfile", NULL)) != NULL &&
+         attr->value)
+        default_profile_id = atoi(attr->value);
+
+      q1_choice = q2_choice = q3_choice = NULL;
+    }
+    else
+    {
+     /*
+      * For CUPS PPDs, figure out the default profile selector values...
+      */
+
+      if ((attr = ppdFindAttr(ppd, "cupsICCQualifier1", NULL)) != NULL &&
+         attr->value && attr->value[0])
+      {
+       snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value);
+       q1_attr = ppdFindAttr(ppd, q_keyword, NULL);
+      }
+      else if ((q1_attr = ppdFindAttr(ppd, "DefaultColorModel", NULL)) == NULL)
+       q1_attr = ppdFindAttr(ppd, "DefaultColorSpace", NULL);
+
+      if (q1_attr && q1_attr->value && q1_attr->value[0])
+       q1_choice = q1_attr->value;
+      else
+       q1_choice = "";
+
+      if ((attr = ppdFindAttr(ppd, "cupsICCQualifier2", NULL)) != NULL &&
+         attr->value && attr->value[0])
+      {
+       snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value);
+       q2_attr = ppdFindAttr(ppd, q_keyword, NULL);
+      }
+      else 
+       q2_attr = ppdFindAttr(ppd, "DefaultMediaType", NULL);
+
+      if (q2_attr && q2_attr->value && q2_attr->value[0])
+       q2_choice = q2_attr->value;
+      else
+       q2_choice = NULL;
+
+      if ((attr = ppdFindAttr(ppd, "cupsICCQualifier3", NULL)) != NULL &&
+         attr->value && attr->value[0])
+      {
+       snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value);
+       q3_attr = ppdFindAttr(ppd, q_keyword, NULL);
+      }
+      else 
+       q3_attr = ppdFindAttr(ppd, "DefaultResolution", NULL);
+
+      if (q3_attr && q3_attr->value && q3_attr->value[0])
+       q3_choice = q3_attr->value;
+      else
+       q3_choice = NULL;
+    }
+
+   /*
+    * Build the array of profiles...
+    *
+    * Note: This calloc actually requests slightly more memory than needed.
+    */
+
+    if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate memory for %d profiles!",
+                     num_profiles);
+      ppdClose(ppd);
+      return;
+    }
+
+    profiles->profileCount = num_profiles;
+    languages              = _ppdGetLanguages(ppd);
+
+    for (profile = profiles->profiles,
+             attr = ppdFindAttr(ppd, profile_key, NULL);
+        attr;
+        attr = ppdFindNextAttr(ppd, profile_key, NULL))
+      if (attr->spec[0] && attr->value && attr->value[0])
+      {
+       /*
+        * Add this profile...
+       */
+
+        if (attr->value[0] != '/')
+         snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir,
+                  attr->value);
+        else
+         strlcpy(iccfile, attr->value, sizeof(iccfile));
+
+        if (access(iccfile, 0))
+         continue;
+
+        if (profile_key[0] == 'c')
+       {
+         cupsArraySave(ppd->sorted_attrs);
+
+         if ((profileid_attr = ppdFindAttr(ppd, "cupsProfileID",
+                                           attr->spec)) != NULL &&
+             profileid_attr->value && isdigit(profileid_attr->value[0] & 255))
+           profile_id = (unsigned)strtoul(profileid_attr->value, NULL, 10);
+         else
+           profile_id = _ppdHashName(attr->spec);
+
+         cupsArrayRestore(ppd->sorted_attrs);
+        }
+       else
+         profile_id = atoi(attr->spec);
+
+        apple_init_profile(ppd, languages, profile, profile_id, attr->spec,
+                          attr->text[0] ? attr->text : attr->spec, iccfile);
+
+       profile ++;
+
+       /*
+        * See if this is the default profile...
+       */
+
+        if (!default_profile_id)
+       {
+         if (q2_choice)
+         {
+           if (q3_choice)
+           {
+             snprintf(selector, sizeof(selector), "%s.%s.%s",
+                      q1_choice, q2_choice, q3_choice);
+              if (!strcmp(selector, attr->spec))
+               default_profile_id = profile_id;
+            }
+
+            if (!default_profile_id)
+           {
+             snprintf(selector, sizeof(selector), "%s.%s.", q1_choice,
+                      q2_choice);
+              if (!strcmp(selector, attr->spec))
+               default_profile_id = profile_id;
+           }
+          }
+
+          if (!default_profile_id && q3_choice)
+         {
+           snprintf(selector, sizeof(selector), "%s..%s", q1_choice,
+                    q3_choice);
+           if (!strcmp(selector, attr->spec))
+             default_profile_id = profile_id;
+         }
+
+          if (!default_profile_id)
+         {
+           snprintf(selector, sizeof(selector), "%s..", q1_choice);
+           if (!strcmp(selector, attr->spec))
+             default_profile_id = profile_id;
+         }
+       }
+      }
+
+    _ppdFreeLanguages(languages);
+  }
+  else if ((cm_option = ppdFindOption(ppd, "ColorModel")) != NULL)
+  {
+   /*
+    * Extract profiles from ColorModel option...
+    */
+
+    const char *profile_name;          /* Name of generic profile */
+
+
+    num_profiles = cm_option->num_choices;
+
+    if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate memory for %d profiles!",
+                     num_profiles);
+      ppdClose(ppd);
+      return;
+    }
+
+    profiles->profileCount = num_profiles;
+
+    for (profile = profiles->profiles, i = cm_option->num_choices,
+             cm_choice = cm_option->choices;
+         i > 0;
+        i --, cm_choice ++, profile ++)
+    {
+      if (!strcmp(cm_choice->choice, "Gray") ||
+          !strcmp(cm_choice->choice, "Black"))
+        profile_name = "Gray";
+      else if (!strcmp(cm_choice->choice, "RGB") ||
+               !strcmp(cm_choice->choice, "CMY"))
+        profile_name = "RGB";
+      else if (!strcmp(cm_choice->choice, "CMYK") ||
+               !strcmp(cm_choice->choice, "KCMY"))
+        profile_name = "CMYK";
+      else
+        profile_name = "DeviceN";
+
+      snprintf(selector, sizeof(selector), "%s..", profile_name);
+      profile_id = _ppdHashName(selector);
+
+      apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice,
+                         cm_choice->text, NULL);
+
+      if (cm_choice->marked)
+        default_profile_id = profile_id;
+    }
+  }
+  else
+  {
+   /*
+    * Use the default colorspace...
+    */
+
+    num_profiles = 1 + ppd->colorspace != PPD_CS_GRAY;
+    
+    if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate memory for %d profiles!",
+                     num_profiles);
+      ppdClose(ppd);
+      return;
+    }
+
+    profiles->profileCount = num_profiles;
+
+    apple_init_profile(ppd, NULL, profiles->profiles, _ppdHashName("Gray.."),
+                       "Gray", "Gray", NULL);
+
+    switch (ppd->colorspace)
+    {
+      case PPD_CS_RGB :
+      case PPD_CS_CMY :
+          apple_init_profile(ppd, NULL, profiles->profiles + 1,
+                            _ppdHashName("RGB.."), "RGB", "RGB", NULL);
+          break;
+      case PPD_CS_RGBK :
+      case PPD_CS_CMYK :
+          apple_init_profile(ppd, NULL, profiles->profiles + 1,
+                            _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL);
+          break;
+
+      case PPD_CS_N :
+          apple_init_profile(ppd, NULL, profiles->profiles + 1,
+                            _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
+                            NULL);
+          break;
+
+      default :
+         break;
+    }
+  }
+
+  if (num_profiles > 0)
+  {
+   /*
+    * Make sure we have a default profile ID...
+    */
+
+    if (!default_profile_id)
+      default_profile_id = profiles->profiles[num_profiles - 1].profileID;
+
+   /*
+    * Get the device ID hash and pathelogical name dictionary.
+    */
+
+    cupsdLogMessage(CUPSD_LOG_INFO, "Registering ICC color profiles for \"%s\"",
+                   p->name);
+
+    device_id    = _ppdHashName(p->name);
+    device_name  = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                            &kCFTypeDictionaryKeyCallBacks,
+                                            &kCFTypeDictionaryValueCallBacks);
+    printer_name = CFStringCreateWithCString(kCFAllocatorDefault,
+                                             p->name, kCFStringEncodingUTF8);
+
+    if (device_name && printer_name)
+    {
+      CFDictionarySetValue(device_name, CFSTR("en"), printer_name);
+
+     /*
+      * Register the device with ColorSync...
+      */
+
+      error = CMRegisterColorDevice(cmPrinterDeviceClass, device_id,
+                                    device_name, &scope);
+
+     /*
+      * Register the profiles...
+      */
+
+      if (error == noErr)
+       error = CMSetDeviceFactoryProfiles(cmPrinterDeviceClass, device_id,
+                                          default_profile_id, profiles);
+    }
+    else
+      error = 1000;
+
+   /*
+    * Clean up...
+    */
+
+    if (error != noErr)
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Unable to register ICC color profiles for \"%s\" - %d",
+                     p->name, (int)error);
+
+    for (profile = profiles->profiles;
+        num_profiles > 0;
+        profile ++, num_profiles --)
+      CFRelease(profile->profileName);
+
+    free(profiles);
+
+    if (printer_name)
+      CFRelease(printer_name);
+
+    if (device_name)
+      CFRelease(device_name);
+  }
+
+  ppdClose(ppd);
+}
+
+
+/*
+ * 'apple_unregister_profiles()' - Remove color profiles for the specified
+ *                                 printer.
+ */
+
+static void
+apple_unregister_profiles(
+    cupsd_printer_t *p)                        /* I - Printer */
+{
+ /*
+  * Make sure ColorSync is available...
+  */
+
+  if (CMUnregisterColorDevice != NULL)
+    CMUnregisterColorDevice(cmPrinterDeviceClass, _ppdHashName(p->name));
+}
+#endif /* __APPLE__ */
+
 /*
  * 'apply_printer_defaults()' - Apply printer default options to a job.
  */
@@ -2561,7 +3525,7 @@ apply_printer_defaults(
   int          i,                      /* Looping var */
                num_options;            /* Number of default options */
   cups_option_t        *options,               /* Default options */
-               *option;                /* Current option */    
+               *option;                /* Current option */
 
 
  /*
@@ -2569,7 +3533,8 @@ apply_printer_defaults(
   * job object...
   */
 
-  for (i = printer->num_options, num_options = 0, option = printer->options;
+  for (i = printer->num_options, num_options = 0, options = NULL,
+           option = printer->options;
        i > 0;
        i --, option ++)
     if (!ippFindAttribute(job->attrs, option->name, IPP_TAG_ZERO))
@@ -2595,7 +3560,8 @@ static void
 authenticate_job(cupsd_client_t  *con, /* I - Client connection */
                 ipp_attribute_t *uri)  /* I - Job URI */
 {
-  ipp_attribute_t      *attr;          /* Job-id attribute */
+  ipp_attribute_t      *attr,          /* job-id attribute */
+                       *auth_info;     /* auth-info attribute */
   int                  jobid;          /* Job ID */
   cupsd_job_t          *job;           /* Current job */
   char                 method[HTTP_MAX_URI],
@@ -2647,7 +3613,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
     httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
                     sizeof(method), username, sizeof(username), host,
                    sizeof(host), &port, resource, sizeof(resource));
+
     if (strncmp(resource, "/jobs/", 6))
     {
      /*
@@ -2697,10 +3663,26 @@ authenticate_job(cupsd_client_t  *con,  /* I - Client connection */
   * See if we have already authenticated...
   */
 
-  if (!con->username[0])
+  auth_info = ippFindAttribute(con->request, "auth-info", IPP_TAG_TEXT);
+
+  if (!con->username[0] && !auth_info)
   {
-    send_ipp_status(con, IPP_NOT_AUTHORIZED,
-                    _("No authentication information provided!"));
+    cupsd_printer_t    *printer;       /* Job destination */
+
+
+   /*
+    * No auth data.  If we need to authenticate via Kerberos, send a
+    * HTTP auth challenge, otherwise just return an IPP error...
+    */
+
+    printer = cupsdFindDest(job->dest);
+
+    if (printer && printer->num_auth_info_required > 0 &&
+        !strcmp(printer->auth_info_required[0], "negotiate"))
+      send_http_error(con, HTTP_UNAUTHORIZED, printer);
+    else
+      send_ipp_status(con, IPP_NOT_AUTHORIZED,
+                     _("No authentication information provided!"));
     return;
   }
 
@@ -2710,7 +3692,7 @@ 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);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
@@ -2718,7 +3700,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
   * Save the authentication information for this job...
   */
 
-  save_auth_info(con, job);
+  save_auth_info(con, job, auth_info);
 
  /*
   * Reset the job-hold-until value to "no-hold"...
@@ -2740,8 +3722,7 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
 
   cupsdReleaseJob(job);
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was authenticated by \"%s\".", jobid,
-                  con->username);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Authenticated by \"%s\".", con->username);
 }
 
 
@@ -2754,11 +3735,10 @@ cancel_all_jobs(cupsd_client_t  *con,   /* I - Client connection */
                ipp_attribute_t *uri)   /* I - Job or Printer URI */
 {
   http_status_t        status;                 /* Policy status */
-  const char   *dest;                  /* Destination */
   cups_ptype_t dtype;                  /* Destination type */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+  char         scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
                userpass[HTTP_MAX_URI], /* Username portion of URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
+               hostname[HTTP_MAX_URI], /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
   ipp_attribute_t *attr;               /* Attribute in request */
@@ -2817,16 +3797,17 @@ cancel_all_jobs(cupsd_client_t  *con,   /* I - Client connection */
   * And if the destination is valid...
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), userpass, sizeof(userpass), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI?
     */
 
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text,
+                    scheme, sizeof(scheme), userpass, sizeof(userpass),
+                   hostname, sizeof(hostname), &port,
+                   resource, sizeof(resource));
+
     if ((!strncmp(resource, "/printers/", 10) && resource[10]) ||
         (!strncmp(resource, "/classes/", 9) && resource[9]))
     {
@@ -2834,13 +3815,6 @@ cancel_all_jobs(cupsd_client_t  *con,    /* I - Client connection */
                       _("The printer or class was not found."));
       return;
     }
-    else if (strcmp(resource, "/printers/"))
-    {
-      send_ipp_status(con, IPP_NOT_FOUND,
-                      _("The printer-uri \"%s\" is not valid."),
-                     uri->values[0].string.text);
-      return;
-    }
 
    /*
     * Check policy...
@@ -2848,7 +3822,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
 
     if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
     {
-      send_http_error(con, status);
+      send_http_error(con, status, NULL);
       return;
     }
 
@@ -2859,7 +3833,7 @@ 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" : "cancelled", get_username(con));
+                    purge ? "purged" : "canceled", get_username(con));
   }
   else
   {
@@ -2867,9 +3841,10 @@ cancel_all_jobs(cupsd_client_t  *con,    /* I - Client connection */
     * Check policy...
     */
 
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
+                                   NULL)) != HTTP_OK)
     {
-      send_http_error(con, status);
+      send_http_error(con, status, printer);
       return;
     }
 
@@ -2877,10 +3852,11 @@ cancel_all_jobs(cupsd_client_t  *con,   /* I - Client connection */
     * Cancel all of the jobs on the named printer...
     */
 
-    cupsdCancelJobs(dest, username, purge);
+    cupsdCancelJobs(printer->name, username, purge);
 
     cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
-                    dest, purge ? "purged" : "cancelled", get_username(con));
+                    printer->name, purge ? "purged" : "canceled",
+                   get_username(con));
   }
 
   con->response->request.status.status_code = IPP_OK;
@@ -2897,15 +3873,15 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
 {
   ipp_attribute_t *attr;               /* Current attribute */
   int          jobid;                  /* Job ID */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+  char         scheme[HTTP_MAX_URI],   /* Scheme 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 */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  cups_ptype_t dtype;                  /* Destination type (printer/class) */
   cupsd_printer_t *printer;            /* Printer data */
+  int          purge;                  /* Purge the job? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con,
@@ -2935,11 +3911,7 @@ cancel_job(cupsd_client_t  *con, /* I - Client connection */
       * Find the current job on the specified printer...
       */
 
-      httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                      sizeof(method), username, sizeof(username), host,
-                     sizeof(host), &port, resource, sizeof(resource));
-
-      if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+      if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
       {
        /*
        * Bad URI...
@@ -2961,21 +3933,33 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
        /*
         * No, see if there are any pending jobs...
        */
-        
+
         for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
             job;
             job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
          if (job->state_value <= IPP_JOB_PROCESSING &&
-             !strcasecmp(job->dest, dest))
+             !strcasecmp(job->dest, printer->name))
            break;
 
        if (job)
          jobid = job->id;
        else
        {
-         send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s!"),
-                         dest);
-         return;
+         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;
+         }
        }
       }
     }
@@ -2986,10 +3970,10 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
     * Got a job URI; parse it to get the job ID...
     */
 
-    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                    sizeof(method), username, sizeof(username), host,
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
+                    sizeof(scheme), username, sizeof(username), host,
                    sizeof(host), &port, resource, sizeof(resource));
+
     if (strncmp(resource, "/jobs/", 6))
     {
      /*
@@ -3005,6 +3989,16 @@ cancel_job(cupsd_client_t  *con, /* I - Client connection */
     jobid = atoi(resource + 6);
   }
 
+ /*
+  * Look for the "purge-job" attribute...
+  */
+
+  if ((attr = ippFindAttribute(con->request, "purge-job",
+                               IPP_TAG_BOOLEAN)) != NULL)
+    purge = attr->values[0].boolean;
+  else
+    purge = 0;
+
  /*
   * See if the job exists...
   */
@@ -3025,22 +4019,22 @@ 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);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
  /*
-  * See if the job is already completed, cancelled, or aborted; if so,
+  * See if the job is already completed, canceled, or aborted; if so,
   * we can't cancel...
   */
 
-  if (job->state_value >= IPP_JOB_CANCELLED)
+  if (job->state_value >= IPP_JOB_CANCELED && !purge)
   {
     switch (job->state_value)
     {
-      case IPP_JOB_CANCELLED :
+      case IPP_JOB_CANCELED :
          send_ipp_status(con, IPP_NOT_POSSIBLE,
-                         _("Job #%d is already cancelled - can\'t cancel."),
+                         _("Job #%d is already canceled - can\'t cancel."),
                          jobid);
           break;
 
@@ -3064,14 +4058,15 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
   * Cancel the job and return...
   */
 
-  cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                "Job cancelled by \"%s\".", username);
-
-  cupsdCancelJob(job, 0);
+  cupsdCancelJob(job, purge, IPP_JOB_CANCELED);
   cupsdCheckJobs();
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was cancelled by \"%s\".", jobid,
-                  username);
+  if (purge)
+    cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Purged by \"%s\".", jobid,
+                   username);
+  else
+    cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Canceled by \"%s\".", jobid,
+                   username);
 
   con->response->request.status.status_code = IPP_OK;
 }
@@ -3117,7 +4112,7 @@ cancel_subscription(
                                              DefaultPolicyPtr,
                                  con, sub->owner)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, sub->dest);
     return;
   }
 
@@ -3131,6 +4126,40 @@ cancel_subscription(
 }
 
 
+/*
+ * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
+ */
+
+static int                             /* O - 1 if OK, 0 if not */
+check_rss_recipient(
+    const char *recipient)             /* I - Recipient URI */
+{
+  cupsd_subscription_t *sub;           /* Current subscription */
+
+
+  for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
+       sub;
+       sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
+    if (sub->recipient)
+    {
+     /*
+      * Compare the URIs up to the first ?...
+      */
+
+      const char *r1, *r2;
+
+      for (r1 = recipient, r2 = sub->recipient;
+           *r1 == *r2 && *r1 && *r1 != '?' && *r2 && *r2 != '?';
+          r1 ++, r2 ++);
+
+      if (*r1 == *r2)
+        return (0);
+    }
+
+  return (1);
+}
+
+
 /*
  * 'check_quotas()' - Check quotas for a printer and user.
  */
@@ -3142,19 +4171,29 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
   int          i;                      /* Looping var */
   char         username[33];           /* Username */
   cupsd_quota_t        *q;                     /* Quota data */
+#ifdef HAVE_MBR_UID_TO_UUID
+ /*
+  * Use Apple membership APIs which require that all names represent
+  * valid user account or group records accessible by the server.
+  */
+
+  uuid_t       usr_uuid;               /* UUID for job requesting user  */
+  uuid_t       usr2_uuid;              /* UUID for ACL user name entry  */
+  uuid_t       grp_uuid;               /* UUID for ACL group name entry */
+  int          mbr_err;                /* Error from membership function */
+  int          is_member;              /* Is this user a member? */
+#else
+ /*
+  * Use standard POSIX APIs for checking users and groups...
+  */
+
   struct passwd        *pw;                    /* User password data */
+#endif /* HAVE_MBR_UID_TO_UUID */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "check_quotas(%p[%d], %p[%s])",
                   con, con->http.fd, p, p->name);
 
- /*
-  * Check input...
-  */
-
-  if (!con || !p)
-    return (0);
-
  /*
   * Figure out who is printing...
   */
@@ -3200,10 +4239,36 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
   if (p->num_users == 0 && p->k_limit == 0 && p->page_limit == 0)
     return (1);
 
-  if (p->num_users)
-  {
+  if (p->num_users)
+  {
+#ifdef HAVE_MBR_UID_TO_UUID
+   /*
+    * Get UUID for job requesting user...
+    */
+
+    if (mbr_user_name_to_uuid((char *)username, usr_uuid))
+    {
+     /*
+      * Unknown user...
+      */
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                     "check_quotas: UUID lookup failed for user \"%s\"",
+                     username);
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                     "Denying user \"%s\" access to printer \"%s\" "
+                     "(unknown user)...",
+                     username, p->name);
+      return (0);
+    }
+#else
+   /*
+    * Get UID and GID of requesting user...
+    */
+
     pw = getpwnam(username);
     endpwent();
+#endif /* HAVE_MBR_UID_TO_UUID */
 
     for (i = 0; i < p->num_users; i ++)
       if (p->users[i][0] == '@')
@@ -3212,11 +4277,93 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
         * Check group membership...
        */
 
+#ifdef HAVE_MBR_UID_TO_UUID
+        if (p->users[i][1] == '#')
+       {
+         if (uuid_parse((char *)p->users[i] + 2, grp_uuid))
+           uuid_clear(grp_uuid);
+       }
+       else if ((mbr_err = mbr_group_name_to_uuid((char *)p->users[i] + 1,
+                                                  grp_uuid)) != 0)
+       {
+        /*
+         * Invalid ACL entries are ignored for matching; just record a
+         * warning in the log...
+         */
+
+         cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "check_quotas: UUID lookup failed for ACL entry "
+                         "\"%s\" (err=%d)", p->users[i], mbr_err);
+         cupsdLogMessage(CUPSD_LOG_WARN,
+                         "Access control entry \"%s\" not a valid group name; "
+                         "entry ignored", p->users[i]);
+       }
+
+       if ((mbr_err = mbr_check_membership(usr_uuid, grp_uuid,
+                                           &is_member)) != 0)
+       {
+        /*
+         * At this point, there should be no errors, but check anyways...
+         */
+
+         cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "check_quotas: group \"%s\" membership check "
+                         "failed (err=%d)", p->users[i] + 1, mbr_err);
+         is_member = 0;
+       }
+
+       /*
+       * Stop if we found a match...
+       */
+
+       if (is_member)
+         break;
+
+#else
         if (cupsdCheckGroup(username, pw, p->users[i] + 1))
          break;
+#endif /* HAVE_MBR_UID_TO_UUID */
+      }
+#ifdef HAVE_MBR_UID_TO_UUID
+      else
+      {
+        if (p->users[i][0] == '#')
+       {
+         if (uuid_parse((char *)p->users[i] + 1, usr2_uuid))
+           uuid_clear(usr2_uuid);
+        }
+        else if ((mbr_err = mbr_user_name_to_uuid((char *)p->users[i],
+                                                 usr2_uuid)) != 0)
+       {
+        /*
+         * Invalid ACL entries are ignored for matching; just record a
+         * warning in the log...
+         */
+
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "check_quotas: UUID lookup failed for ACL entry "
+                         "\"%s\" (err=%d)", p->users[i], mbr_err);
+          cupsdLogMessage(CUPSD_LOG_WARN,
+                         "Access control entry \"%s\" not a valid user name; "
+                         "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)
+         break;
       }
+#else
       else if (!strcasecmp(username, p->users[i]))
        break;
+#endif /* HAVE_MBR_UID_TO_UUID */
 
     if ((i < p->num_users) == p->deny_users)
     {
@@ -3231,6 +4378,66 @@ 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)
@@ -3238,7 +4445,7 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Unable to allocate quota data for user \"%s\"!",
                       username);
-      return (0);
+      return (-1);
     }
 
     if ((q->k_count >= p->k_limit && p->k_limit) ||
@@ -3246,7 +4453,7 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
     {
       cupsdLogMessage(CUPSD_LOG_INFO, "User \"%s\" is over the quota limit...",
                       username);
-      return (0);
+      return (-1);
     }
   }
 
@@ -3321,7 +4528,8 @@ copy_attribute(
        else
        {
           for (i = 0; i < attr->num_values; i ++)
-           toattr->values[i].string.text = _cupsStrAlloc(attr->values[i].string.text);
+           toattr->values[i].string.text =
+               _cupsStrAlloc(attr->values[i].string.text);
        }
         break;
 
@@ -3379,7 +4587,8 @@ copy_attribute(
               toattr->values[i].string.charset =
                  toattr->values[0].string.charset;
 
-           toattr->values[i].string.text = _cupsStrAlloc(attr->values[i].string.text);
+           toattr->values[i].string.text =
+               _cupsStrAlloc(attr->values[i].string.text);
           }
         }
         break;
@@ -3449,8 +4658,8 @@ copy_attrs(ipp_t        *to,              /* I - Destination request */
     * Filter attributes as needed...
     */
 
-    if (group != IPP_TAG_ZERO && fromattr->group_tag != group &&
-        fromattr->group_tag != IPP_TAG_ZERO && !fromattr->name)
+    if ((group != IPP_TAG_ZERO && fromattr->group_tag != group &&
+         fromattr->group_tag != IPP_TAG_ZERO) || !fromattr->name)
       continue;
 
     if (!ra || cupsArrayFind(ra, fromattr->name))
@@ -3481,8 +4690,10 @@ copy_banner(cupsd_client_t *con, /* I - Client connection */
   ipp_attribute_t *attr;               /* Attribute */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner(%p[%d], %p[%d], %s)",
-                  con, con->http.fd, job, job->id, name ? name : "(null)");
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
+                  con, con ? con->http.fd : -1, job, job->id,
+                 name ? name : "(null)");
 
  /*
   * Find the banner; return if not found or "none"...
@@ -3497,14 +4708,14 @@ copy_banner(cupsd_client_t *con,        /* I - Client connection */
   */
 
   if (add_file(con, job, banner->filetype, 0))
-    return (0);
+    return (-1);
 
   snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
            job->num_files);
   if ((out = cupsFileOpen(filename, "w")) == NULL)
   {
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "copy_banner: Unable to create banner job file %s - %s",
+                    "Unable to create banner job file %s - %s",
                     filename, strerror(errno));
     job->num_files --;
     return (0);
@@ -3560,7 +4771,7 @@ copy_banner(cupsd_client_t *con,  /* I - Client connection */
     cupsFileClose(out);
     unlink(filename);
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "copy_banner: Unable to open banner template file %s - %s",
+                    "Unable to open banner template file %s - %s",
                     filename, strerror(errno));
     job->num_files --;
     return (0);
@@ -3792,9 +5003,9 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
            const char     *from,       /* I - Source file */
            const char     *to)         /* I - Destination file */
 {
-  fd_set       *input;                 /* select() input set */
+  fd_set       input;                  /* select() input set */
   struct timeval timeout;              /* select() timeout */
-  int          maxfd;                  /* Maximum file descriptor for select() */
+  int          maxfd;                  /* Max file descriptor for select() */
   char         tempfile[1024];         /* Temporary PPD file */
   int          tempfd;                 /* Temporary PPD file descriptor */
   int          temppid;                /* Process ID of cups-driverd */
@@ -3803,23 +5014,17 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
                *envp[MAX_ENV];         /* Environment */
   cups_file_t  *src,                   /* Source file */
                *dst;                   /* Destination file */
+  ppd_file_t   *ppd;                   /* PPD file */
   int          bytes,                  /* Bytes from pipe */
                total;                  /* Total bytes from pipe */
-  char         buffer[2048],           /* Copy buffer */
-               *ptr;                   /* Pointer into buffer */
+  char         buffer[2048];           /* Copy buffer */
   int          i;                      /* Looping var */
   char         option[PPD_MAX_NAME],   /* Option name */
                choice[PPD_MAX_NAME];   /* Choice name */
   int          num_defaults;           /* Number of default options */
-  ppd_default_t        *defaults;              /* Default options */
+  cups_option_t        *defaults;              /* Default options */
   char         cups_protocol[PPD_MAX_LINE];
                                        /* cupsProtocol attribute */
-  int          have_letter,            /* Have Letter size */
-               have_a4;                /* Have A4 size */
-#ifdef HAVE_LIBPAPER
-  char         *paper_result;          /* Paper size name from libpaper */
-  char         system_paper[64];       /* Paper size name buffer */
-#endif /* HAVE_LIBPAPER */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
@@ -3845,26 +5050,15 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
 
   cupsdOpenPipe(temppipe);
 
-  if ((input = calloc(1, SetSize)) == NULL)
-  {
-    close(tempfd);
-    unlink(tempfile);
-
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "copy_model: Unable to allocate %d bytes for select()...",
-                    SetSize);
-    return (-1);
-  }
-
   cupsdLogMessage(CUPSD_LOG_DEBUG,
                   "copy_model: Running \"cups-driverd cat %s\"...", from);
 
   if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
-                         -1, 0, &temppid))
+                         -1, -1, 0, DefaultProfile, &temppid))
   {
-    free(input);
     close(tempfd);
     unlink(tempfile);
+
     return (-1);
   }
 
@@ -3887,15 +5081,14 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
     * See if we have data ready...
     */
 
-    bytes = 0;
-
-    FD_SET(temppipe[0], input);
-    FD_SET(CGIPipes[0], input);
+    FD_ZERO(&input);
+    FD_SET(temppipe[0], &input);
+    FD_SET(CGIPipes[0], &input);
 
     timeout.tv_sec  = 30;
     timeout.tv_usec = 0;
 
-    if ((i = select(maxfd, input, NULL, NULL, &timeout)) < 0)
+    if ((i = select(maxfd, &input, NULL, NULL, &timeout)) < 0)
     {
       if (errno == EINTR)
         continue;
@@ -3911,7 +5104,7 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
       break;
     }
 
-    if (FD_ISSET(temppipe[0], input))
+    if (FD_ISSET(temppipe[0], &input))
     {
      /*
       * Read the PPD file from the pipe, and write it to the PPD file.
@@ -3928,15 +5121,13 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
        break;
     }
 
-    if (FD_ISSET(CGIPipes[0], input))
+    if (FD_ISSET(CGIPipes[0], &input))
       cupsdUpdateCGI();
   }
 
   close(temppipe[0]);
   close(tempfd);
 
-  free(input);
-
   if (!total)
   {
    /*
@@ -3952,42 +5143,12 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
   * Read the source file and see what page sizes are supported...
   */
 
-  if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
+  if ((ppd = ppdOpenFile(tempfile)) == NULL)
   {
     unlink(tempfile);
     return (-1);
   }
 
-  have_letter = 0;
-  have_a4     = 0;
-
-  while (cupsFileGets(src, buffer, sizeof(buffer)))
-    if (!strncmp(buffer, "*PageSize ", 10))
-    {
-     /*
-      * Strip UI text and command data from the end of the line...
-      */
-
-      if ((ptr = strchr(buffer + 10, '/')) != NULL)
-        *ptr = '\0';
-      if ((ptr = strchr(buffer + 10, ':')) != NULL)
-        *ptr = '\0';
-
-      for (ptr = buffer + 10; isspace(*ptr); ptr ++);
-
-     /*
-      * Look for Letter and A4 page sizes...
-      */
-
-      if (!strcmp(ptr, "Letter"))
-       have_letter = 1;
-
-      if (!strcmp(ptr, "A4"))
-       have_a4 = 1;
-    }
-
-  cupsFileRewind(src);
-
  /*
   * Open the destination (if possible) and set the default options...
   */
@@ -4011,88 +5172,54 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
 
         if (!ppd_parse_line(buffer, option, sizeof(option),
                            choice, sizeof(choice)))
-          num_defaults = ppd_add_default(option, choice, num_defaults,
+        {
+         ppd_option_t  *ppdo;          /* PPD option */
+
+
+         /*
+         * Only add the default if the default hasn't already been
+         * set and the choice exists in the new PPD...
+         */
+
+         if (!cupsGetOption(option, num_defaults, defaults) &&
+             (ppdo = ppdFindOption(ppd, option)) != NULL &&
+             ppdFindChoice(ppdo, choice))
+            num_defaults = cupsAddOption(option, choice, num_defaults,
                                         &defaults);
+        }
       }
       else if (!strncmp(buffer, "*cupsProtocol:", 14))
         strlcpy(cups_protocol, buffer, sizeof(cups_protocol));
 
     cupsFileClose(dst);
   }
-#ifdef HAVE_LIBPAPER
-  else if ((paper_result = systempapername()) != NULL)
+  else if (ppdPageSize(ppd, DefaultPaperSize))
   {
    /*
-    * Set the default media sizes from the systemwide default...
+    * Add the default media sizes...
     */
 
-    strlcpy(system_paper, paper_result, sizeof(system_paper));
-    system_paper[0] = toupper(system_paper[0] & 255);
-
-    if ((!strcmp(system_paper, "Letter") && have_letter) ||
-        (!strcmp(system_paper, "A4") && have_a4))
-    {
-      num_defaults = ppd_add_default("PageSize", system_paper, 
-                                    num_defaults, &defaults);
-      num_defaults = ppd_add_default("PageRegion", system_paper, 
-                                    num_defaults, &defaults);
-      num_defaults = ppd_add_default("PaperDimension", system_paper, 
-                                    num_defaults, &defaults);
-      num_defaults = ppd_add_default("ImageableArea", system_paper, 
-                                    num_defaults, &defaults);
-    }
+    num_defaults = cupsAddOption("PageSize", DefaultPaperSize,
+                                 num_defaults, &defaults);
+    num_defaults = cupsAddOption("PageRegion", DefaultPaperSize,
+                                 num_defaults, &defaults);
+    num_defaults = cupsAddOption("PaperDimension", DefaultPaperSize,
+                                 num_defaults, &defaults);
+    num_defaults = cupsAddOption("ImageableArea", DefaultPaperSize,
+                                 num_defaults, &defaults);
   }
-#endif /* HAVE_LIBPAPER */
-  else
-  {
-   /*
-    * Add the default media sizes...
-    *
-    * Note: These values are generally not valid for large-format devices
-    *       like plotters, however it is probably safe to say that those
-    *       users will configure the media size after initially adding
-    *       the device anyways...
-    */
 
-    if (!DefaultLanguage ||
-        !strcasecmp(DefaultLanguage, "C") ||
-        !strcasecmp(DefaultLanguage, "POSIX") ||
-       !strcasecmp(DefaultLanguage, "en") ||
-       !strncasecmp(DefaultLanguage, "en_US", 5) ||
-       !strncasecmp(DefaultLanguage, "en_CA", 5) ||
-       !strncasecmp(DefaultLanguage, "fr_CA", 5))
-    {
-     /*
-      * These are the only locales that will default to "letter" size...
-      */
+  ppdClose(ppd);
 
-      if (have_letter)
-      {
-       num_defaults = ppd_add_default("PageSize", "Letter", num_defaults,
-                                       &defaults);
-       num_defaults = ppd_add_default("PageRegion", "Letter", num_defaults,
-                                       &defaults);
-       num_defaults = ppd_add_default("PaperDimension", "Letter", num_defaults,
-                                       &defaults);
-       num_defaults = ppd_add_default("ImageableArea", "Letter", num_defaults,
-                                       &defaults);
-      }
-    }
-    else if (have_a4)
-    {
-     /*
-      * The rest default to "a4" size...
-      */
+ /*
+  * Open the source file for a copy...
+  */
 
-      num_defaults = ppd_add_default("PageSize", "A4", num_defaults,
-                                     &defaults);
-      num_defaults = ppd_add_default("PageRegion", "A4", num_defaults,
-                                     &defaults);
-      num_defaults = ppd_add_default("PaperDimension", "A4", num_defaults,
-                                     &defaults);
-      num_defaults = ppd_add_default("ImageableArea", "A4", num_defaults,
-                                     &defaults);
-    }
+  if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
+  {
+    cupsFreeOptions(num_defaults, defaults);
+    unlink(tempfile);
+    return (-1);
   }
 
  /*
@@ -4101,9 +5228,7 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
 
   if ((dst = cupsFileOpen(to, "wb")) == NULL)
   {
-    if (num_defaults > 0)
-      free(defaults);
-
+    cupsFreeOptions(num_defaults, defaults);
     cupsFileClose(src);
     unlink(tempfile);
     return (-1);
@@ -4124,17 +5249,17 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
       if (!ppd_parse_line(buffer, option, sizeof(option),
                          choice, sizeof(choice)))
       {
-        for (i = 0; i < num_defaults; i ++)
-         if (!strcmp(option, defaults[i].option))
-         {
-          /*
-           * Substitute the previous choice...
-           */
+        const char     *val;           /* Default option value */
 
-           snprintf(buffer, sizeof(buffer), "*Default%s: %s", option,
-                    defaults[i].choice);
-           break;
-         }
+
+        if ((val = cupsGetOption(option, num_defaults, defaults)) != NULL)
+       {
+        /*
+         * Substitute the previous choice...
+         */
+
+         snprintf(buffer, sizeof(buffer), "*Default%s: %s", option, val);
+       }
       }
     }
 
@@ -4144,8 +5269,7 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
   if (cups_protocol[0])
     cupsFilePrintf(dst, "%s\n", cups_protocol);
 
-  if (num_defaults > 0)
-    free(defaults);
+  cupsFreeOptions(num_defaults, defaults);
 
  /*
   * Close both files and return...
@@ -4179,6 +5303,14 @@ copy_job_attrs(cupsd_client_t *con,      /* I - Client connection */
                    con->servername, con->serverport, "/jobs/%d",
                   job->id);
 
+  if (!ra || cupsArrayFind(ra, "document-count"))
+    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                 "document-count", job->num_files);
+
+  if (!ra || cupsArrayFind(ra, "job-media-progress"))
+    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                 "job-media-progress", job->progress);
+
   if (!ra || cupsArrayFind(ra, "job-more-info"))
     ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
                 "job-more-info", NULL, job_uri);
@@ -4235,10 +5367,70 @@ copy_printer_attrs(
                 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);
+
+  if (printer->num_printers > 0 &&
+      (!ra || cupsArrayFind(ra, "member-uris")))
+  {
+    ipp_attribute_t    *member_uris;   /* member-uris attribute */
+    cupsd_printer_t    *p2;            /* Printer in class */
+    ipp_attribute_t    *p2_uri;        /* printer-uri-supported for class printer */
+
+
+    if ((member_uris = ippAddStrings(con->response, IPP_TAG_PRINTER,
+                                     IPP_TAG_URI, "member-uris",
+                                    printer->num_printers, NULL,
+                                    NULL)) != NULL)
+    {
+      for (i = 0; i < printer->num_printers; i ++)
+      {
+        p2 = printer->printers[i];
+
+        if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported",
+                                      IPP_TAG_URI)) != NULL)
+          member_uris->values[i].string.text =
+             _cupsStrAlloc(p2_uri->values[0].string.text);
+        else
+       {
+         httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri,
+                          sizeof(printer_uri), "ipp", NULL, con->servername,
+                          con->serverport,
+                          (p2->type & CUPS_PRINTER_CLASS) ?
+                              "/classes/%s" : "/printers/%s", p2->name);
+         member_uris->values[i].string.text = _cupsStrAlloc(printer_uri);
+        }
+      }
+    }
+  }
+
+  if (printer->alert && (!ra || cupsArrayFind(ra, "printer-alert")))
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING,
+                 "printer-alert", NULL, printer->alert);
+
+  if (printer->alert_description &&
+      (!ra || cupsArrayFind(ra, "printer-alert-description")))
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+                 "printer-alert-description", NULL,
+                printer->alert_description);
+
   if (!ra || cupsArrayFind(ra, "printer-current-time"))
     ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
                ippTimeToDate(curtime));
 
+#ifdef HAVE_DNSSD
+  if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
+  {
+    if (printer->reg_name)
+      ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
+                   "printer-dns-sd-name", NULL, printer->reg_name);
+    else
+      ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
+                   "printer-dns-sd-name", 0);
+  }
+#endif /* HAVE_DNSSD */
+
   if (!ra || cupsArrayFind(ra, "printer-error-policy"))
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
                 "printer-error-policy", NULL, printer->error_policy);
@@ -4262,7 +5454,7 @@ copy_printer_attrs(
   if (!ra || cupsArrayFind(ra, "printer-state-change-time"))
     ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                   "printer-state-change-time", printer->state_time);
-                
+
   if (MaxPrinterHistory > 0 && printer->num_history > 0 &&
       cupsArrayFind(ra, "printer-state-history"))
   {
@@ -4321,7 +5513,8 @@ copy_printer_attrs(
   {
     httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
                      "ipp", NULL, con->servername, con->serverport,
-                    "/printers/%s", printer->name);
+                    (printer->type & CUPS_PRINTER_CLASS) ?
+                        "/classes/%s" : "/printers/%s", printer->name);
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
                 "printer-uri-supported", NULL, printer_uri);
     cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"",
@@ -4368,7 +5561,7 @@ copy_subscription_attrs(
       */
 
       ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
-                   IPP_TAG_KEYWORD | IPP_TAG_COPY,
+                   (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
                    "notify-events", NULL, name);
     }
     else
@@ -4382,7 +5575,7 @@ copy_subscription_attrs(
           count ++;
 
       attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
-                           IPP_TAG_KEYWORD | IPP_TAG_COPY,
+                           (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
                            "notify-events", count, NULL, NULL);
 
       for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
@@ -4446,27 +5639,43 @@ static void
 create_job(cupsd_client_t  *con,       /* I - Client connection */
           ipp_attribute_t *uri)        /* I - Printer URI */
 {
-  cupsd_job_t  *job;                   /* New job */
+  cupsd_printer_t      *printer;       /* Printer */
+  cupsd_job_t          *job;           /* New job */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
                   con->http.fd, uri->values[0].string.text);
 
+ /*
+  * Is the destination valid?
+  */
+
+  if (!cupsdValidateDest(uri->values[0].string.text, NULL, &printer))
+  {
+   /*
+    * Bad URI...
+    */
+
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The printer or class was not found."));
+    return;
+  }
+
  /*
   * Create the job object...
   */
 
-  if ((job = add_job(con, uri, NULL, NULL)) == NULL)
+  if ((job = add_job(con, printer, NULL)) == NULL)
     return;
 
+  job->pending_timeout = 1;
+
  /*
   * Save and log the job...
   */
-   
-  cupsdSaveJob(job);
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d created on \"%s\" by \"%s\".",
-                  job->id, job->dest, job->username);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Queued on \"%s\" by \"%s\".",
+             job->dest, job->username);
 }
 
 
@@ -4563,6 +5772,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "job-impressions-completed");
       cupsArrayAdd(ra, "job-k-octets");
       cupsArrayAdd(ra, "job-k-octets-processed");
+      cupsArrayAdd(ra, "job-media-progress");
       cupsArrayAdd(ra, "job-media-sheets");
       cupsArrayAdd(ra, "job-media-sheets-completed");
       cupsArrayAdd(ra, "job-message-from-operator");
@@ -4595,6 +5805,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "job-impressions-supported");
       cupsArrayAdd(ra, "job-k-octets-supported");
       cupsArrayAdd(ra, "job-media-sheets-supported");
+      cupsArrayAdd(ra, "job-settable-attributes-supported");
       cupsArrayAdd(ra, "multiple-document-jobs-supported");
       cupsArrayAdd(ra, "multiple-operation-time-out");
       cupsArrayAdd(ra, "natural-language-configured");
@@ -4602,16 +5813,20 @@ create_requested_array(ipp_t *request)  /* I - IPP request */
       cupsArrayAdd(ra, "notify-lease-duration-default");
       cupsArrayAdd(ra, "notify-lease-duration-supported");
       cupsArrayAdd(ra, "notify-max-events-supported");
-      cupsArrayAdd(ra, "notify-notify-events-default");
-      cupsArrayAdd(ra, "notify-notify-events-supported");
+      cupsArrayAdd(ra, "notify-events-default");
+      cupsArrayAdd(ra, "notify-events-supported");
       cupsArrayAdd(ra, "notify-pull-method-supported");
       cupsArrayAdd(ra, "notify-schemes-supported");
       cupsArrayAdd(ra, "operations-supported");
       cupsArrayAdd(ra, "pages-per-minute");
       cupsArrayAdd(ra, "pages-per-minute-color");
       cupsArrayAdd(ra, "pdl-override-supported");
+      cupsArrayAdd(ra, "printer-alert");
+      cupsArrayAdd(ra, "printer-alert-description");
+      cupsArrayAdd(ra, "printer-commands");
       cupsArrayAdd(ra, "printer-current-time");
       cupsArrayAdd(ra, "printer-driver-installer");
+      cupsArrayAdd(ra, "printer-dns-sd-name");
       cupsArrayAdd(ra, "printer-info");
       cupsArrayAdd(ra, "printer-is-accepting-jobs");
       cupsArrayAdd(ra, "printer-location");
@@ -4623,6 +5838,8 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "printer-state");
       cupsArrayAdd(ra, "printer-state-message");
       cupsArrayAdd(ra, "printer-state-reasons");
+      cupsArrayAdd(ra, "printer-settable-attributes-supported");
+      cupsArrayAdd(ra, "printer-type");
       cupsArrayAdd(ra, "printer-up-time");
       cupsArrayAdd(ra, "printer-uri-supported");
       cupsArrayAdd(ra, "queued-job-count");
@@ -4630,6 +5847,16 @@ create_requested_array(ipp_t *request)   /* I - IPP request */
       cupsArrayAdd(ra, "uri-authentication-supported");
       cupsArrayAdd(ra, "uri-security-supported");
     }
+    else if (!strcmp(value, "printer-defaults"))
+    {
+      char     *name;                  /* Option name */
+
+
+      for (name = (char *)cupsArrayFirst(CommonDefaults);
+           name;
+          name = (char *)cupsArrayNext(CommonDefaults))
+        cupsArrayAdd(ra, name);
+    }
     else if (!strcmp(value, "subscription-template"))
     {
       cupsArrayAdd(ra, "notify-attributes");
@@ -4662,10 +5889,9 @@ create_subscription(
   http_status_t        status;                 /* Policy status */
   int                  i;              /* Looping var */
   ipp_attribute_t      *attr;          /* Current attribute */
-  const char           *dest;          /* Destination */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[HTTP_MAX_URI],
-                                       /* Method portion of URI */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
+  char                 scheme[HTTP_MAX_URI],
+                                       /* Scheme portion of URI */
                        userpass[HTTP_MAX_URI],
                                        /* Username portion of URI */
                        host[HTTP_MAX_URI],
@@ -4677,23 +5903,26 @@ create_subscription(
   cupsd_job_t          *job;           /* Job */
   int                  jobid;          /* Job ID */
   cupsd_subscription_t *sub;           /* Subscription object */
-  const char           *username,      /* requesting-user-name or authenticated username */
+  const char           *username,      /* requesting-user-name or
+                                          authenticated username */
                        *recipient,     /* notify-recipient-uri */
                        *pullmethod;    /* notify-pull-method */
   ipp_attribute_t      *user_data;     /* notify-user-data */
   int                  interval,       /* notify-time-interval */
                        lease;          /* notify-lease-duration */
   unsigned             mask;           /* notify-events */
+  ipp_attribute_t      *notify_events,/* notify-events(-default) */
+                       *notify_lease;  /* notify-lease-duration(-default) */
 
 
 #ifdef DEBUG
   for (attr = con->request->attrs; attr; attr = attr->next)
   {
     if (attr->group_tag != IPP_TAG_ZERO)
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "g%04x v%04x %s", attr->group_tag,
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "g%04x v%04x %s", attr->group_tag,
                       attr->value_tag, attr->name);
     else
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "----SEP----");
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "----SEP----");
   }
 #endif /* DEBUG */
 
@@ -4705,29 +5934,26 @@ create_subscription(
                   "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
                   con, con->http.fd, uri->values[0].string.text);
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), userpass, sizeof(userpass), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
+                  sizeof(scheme), userpass, sizeof(userpass), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(resource, "/"))
   {
-    dest    = NULL;
     dtype   = (cups_ptype_t)0;
     printer = NULL;
   }
   else if (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10)
   {
-    dest    = NULL;
     dtype   = (cups_ptype_t)0;
     printer = NULL;
   }
   else if (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9)
   {
-    dest    = NULL;
     dtype   = CUPS_PRINTER_CLASS;
     printer = NULL;
   }
-  else if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  else if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -4744,15 +5970,16 @@ create_subscription(
 
   if (printer)
   {
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
+                                   NULL)) != HTTP_OK)
     {
-      send_http_error(con, status);
+      send_http_error(con, status, printer);
       return;
     }
   }
   else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -4794,14 +6021,86 @@ create_subscription(
     jobid      = 0;
     mask       = CUPSD_EVENT_NONE;
 
+    if (printer)
+    {
+      notify_events = ippFindAttribute(printer->attrs, "notify-events-default",
+                                       IPP_TAG_KEYWORD);
+      notify_lease  = ippFindAttribute(printer->attrs,
+                                       "notify-lease-duration-default",
+                                       IPP_TAG_INTEGER);
+
+      if (notify_lease)
+        lease = notify_lease->values[0].integer;
+    }
+    else
+    {
+      notify_events = NULL;
+      notify_lease  = NULL;
+    }
+
     while (attr && attr->group_tag != IPP_TAG_ZERO)
     {
-      if (!strcmp(attr->name, "notify-recipient") &&
+      if (!strcmp(attr->name, "notify-recipient-uri") &&
           attr->value_tag == IPP_TAG_URI)
+      {
+       /*
+        * Validate the recipient scheme against the ServerBin/notifier
+       * directory...
+       */
+
+       char    notifier[1024];         /* Notifier filename */
+
+
         recipient = attr->values[0].string.text;
+
+       if (httpSeparateURI(HTTP_URI_CODING_ALL, recipient,
+                           scheme, sizeof(scheme), userpass, sizeof(userpass),
+                           host, sizeof(host), &port,
+                           resource, sizeof(resource)) < HTTP_URI_OK)
+        {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("Bad notify-recipient-uri URI \"%s\"!"), recipient);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_URI_SCHEME);
+         return;
+       }
+
+        snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin,
+                scheme);
+        if (access(notifier, X_OK))
+       {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("notify-recipient-uri URI \"%s\" uses unknown "
+                           "scheme!"), recipient);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_URI_SCHEME);
+         return;
+       }
+
+        if (!strcmp(scheme, "rss") && !check_rss_recipient(recipient))
+       {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("notify-recipient-uri URI \"%s\" is already used!"),
+                         recipient);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_ATTRIBUTES);
+         return;
+       }
+      }
       else if (!strcmp(attr->name, "notify-pull-method") &&
                attr->value_tag == IPP_TAG_KEYWORD)
+      {
         pullmethod = attr->values[0].string.text;
+
+        if (strcmp(pullmethod, "ippget"))
+       {
+          send_ipp_status(con, IPP_NOT_POSSIBLE,
+                         _("Bad notify-pull-method \"%s\"!"), pullmethod);
+         ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM,
+                       "notify-status-code", IPP_ATTRIBUTES);
+         return;
+       }
+      }
       else if (!strcmp(attr->name, "notify-charset") &&
                attr->value_tag == IPP_TAG_CHARSET &&
               strcmp(attr->values[0].string.text, "us-ascii") &&
@@ -4837,10 +6136,7 @@ create_subscription(
       }
       else if (!strcmp(attr->name, "notify-events") &&
                attr->value_tag == IPP_TAG_KEYWORD)
-      {
-        for (i = 0; i < attr->num_values; i ++)
-         mask |= cupsdEventValue(attr->values[i].string.text);
-      }
+        notify_events = attr;
       else if (!strcmp(attr->name, "notify-lease-duration") &&
                attr->value_tag == IPP_TAG_INTEGER)
         lease = attr->values[0].integer;
@@ -4854,6 +6150,12 @@ create_subscription(
       attr = attr->next;
     }
 
+    if (notify_events)
+    {
+      for (i = 0; i < notify_events->num_values; i ++)
+       mask |= cupsdEventValue(notify_events->values[i].string.text);
+    }
+
     if (recipient)
       cupsdLogMessage(CUPSD_LOG_DEBUG, "recipient=\"%s\"", recipient);
     if (pullmethod)
@@ -4934,8 +6236,7 @@ create_subscription(
       attr = attr->next;
   }
 
-  cupsdSaveAllSubscriptions();
-
+  cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
 }
 
 
@@ -4943,18 +6244,12 @@ create_subscription(
  * 'delete_printer()' - Remove a printer or class from the system.
  */
 
-static void
-delete_printer(cupsd_client_t  *con,   /* I - Client connection */
-               ipp_attribute_t *uri)   /* I - URI of printer or class */
-{
-  http_status_t        status;                 /* Policy status */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
-  char         method[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 */
+static void
+delete_printer(cupsd_client_t  *con,   /* I - Client connection */
+               ipp_attribute_t *uri)   /* I - URI of printer or class */
+{
+  http_status_t        status;                 /* Policy status */
+  cups_ptype_t dtype;                  /* Destination type (printer/class) */
   cupsd_printer_t *printer;            /* Printer/class */
   char         filename[1024];         /* Script/PPD filename */
 
@@ -4966,11 +6261,7 @@ delete_printer(cupsd_client_t  *con,     /* I - Client connection */
   * Do we have a valid URI?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -4987,7 +6278,7 @@ delete_printer(cupsd_client_t  *con,      /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -4995,7 +6286,7 @@ delete_printer(cupsd_client_t  *con,      /* I - Client connection */
   * Remove old jobs...
   */
 
-  cupsdCancelJobs(dest, NULL, 1);
+  cupsdCancelJobs(printer->name, NULL, 1);
 
  /*
   * Remove old subscriptions and send a "deleted printer" event...
@@ -5004,38 +6295,48 @@ delete_printer(cupsd_client_t  *con,    /* I - Client connection */
   cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, printer, NULL,
                 "%s \"%s\" deleted by \"%s\".",
                (dtype & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
-               dest, get_username(con));
+               printer->name, get_username(con));
 
   cupsdExpireSubscriptions(printer, NULL);
+
  /*
   * Remove any old PPD or script files...
   */
 
-  snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot, dest);
+  snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
+           printer->name);
   unlink(filename);
 
-  snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, dest);
+  snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
+           printer->name);
   unlink(filename);
 
+#ifdef __APPLE__
+ /*
+  * Unregister color profiles...
+  */
+
+  apple_unregister_profiles(printer);
+#endif /* __APPLE__ */
+
   if (dtype & CUPS_PRINTER_CLASS)
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".", dest,
-                    get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".",
+                    printer->name, get_username(con));
 
     cupsdDeletePrinter(printer, 0);
-    cupsdSaveAllClasses();
+    cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
   }
   else
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".", dest,
-                    get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".",
+                    printer->name, get_username(con));
 
     cupsdDeletePrinter(printer, 0);
-    cupsdSaveAllPrinters();
+    cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
   }
 
-  cupsdWritePrintcap();
+  cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
 
  /*
   * Return with no errors...
@@ -5064,7 +6365,7 @@ get_default(cupsd_client_t *con)  /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -5091,14 +6392,16 @@ static void
 get_devices(cupsd_client_t *con)       /* I - Client connection */
 {
   http_status_t                status;         /* Policy status */
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *limit,         /* Limit attribute */
-                       *requested;     /* requested-attributes attribute */
+  ipp_attribute_t      *limit,         /* limit attribute */
+                       *timeout,       /* timeout attribute */
+                       *requested,     /* requested-attributes attribute */
+                       *exclude;       /* exclude-schemes attribute */
   char                 command[1024],  /* cups-deviced command */
                        options[1024],  /* Options to pass to command */
-                       attrs[1024],    /* String for requested attributes */
-                       *aptr;          /* Pointer into string */
-  int                  alen;           /* Length of attribute value */
+                       requested_str[256],
+                                       /* String for requested attributes */
+                       exclude_str[512];
+                                       /* String for excluded attributes */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_devices(%p[%d])", con, con->http.fd);
@@ -5109,7 +6412,7 @@ get_devices(cupsd_client_t *con)  /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -5117,53 +6420,31 @@ get_devices(cupsd_client_t *con)        /* I - Client connection */
   * Run cups-deviced command with the given options...
   */
 
-  limit = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
+  limit     = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
+  timeout   = ippFindAttribute(con->request, "timeout", IPP_TAG_INTEGER);
   requested = ippFindAttribute(con->request, "requested-attributes",
                                IPP_TAG_KEYWORD);
+  exclude   = ippFindAttribute(con->request, "exclude-schemes", IPP_TAG_NAME);
 
   if (requested)
-  {
-    for (i = 0, aptr = attrs; i < requested->num_values; i ++)
-    {
-     /*
-      * Check that we have enough room...
-      */
-
-      alen = strlen(requested->values[i].string.text);
-      if (alen > (sizeof(attrs) - (aptr - attrs) - 2))
-        break;
-
-     /*
-      * Put commas between values...
-      */
-
-      if (i)
-        *aptr++ = ',';
-
-     /*
-      * Add the value to the end of the string...
-      */
-
-      strcpy(aptr, requested->values[i].string.text);
-      aptr += alen;
-    }
-
-   /*
-    * If we have more attribute names than will fit, default to "all"...
-    */
+    url_encode_attr(requested, requested_str, sizeof(requested_str));
+  else
+    strlcpy(requested_str, "requested-attributes=all", sizeof(requested_str));
 
-    if (i < requested->num_values)
-      strcpy(attrs, "all");
-  }
+  if (exclude)
+    url_encode_attr(exclude, exclude_str, sizeof(exclude_str));
   else
-    strcpy(attrs, "all");
+    exclude_str[0] = '\0';
 
   snprintf(command, sizeof(command), "%s/daemon/cups-deviced", ServerBin);
   snprintf(options, sizeof(options),
-           "%d+%d+%d+requested-attributes=%s",
+           "%d+%d+%d+%d+%s%s%s",
            con->request->request.op.request_id,
-           limit ? limit->values[0].integer : 0, (int)User,
-          attrs);
+           limit ? limit->values[0].integer : 0,
+          timeout ? timeout->values[0].integer : 10,
+          (int)User,
+          requested_str,
+          exclude_str[0] ? "%20" : "", exclude_str);
 
   if (cupsdSendCommand(con, command, options, 1))
   {
@@ -5187,6 +6468,150 @@ get_devices(cupsd_client_t *con)        /* I - Client connection */
 }
 
 
+/*
+ * 'get_document()' - Get a copy of a job file.
+ */
+
+static void
+get_document(cupsd_client_t  *con,     /* I - Client connection */
+             ipp_attribute_t *uri)     /* I - Job URI */
+{
+  http_status_t        status;                 /* Policy status */
+  ipp_attribute_t *attr;               /* Current attribute */
+  int          jobid;                  /* Job ID */
+  int          docnum;                 /* Document number */
+  cupsd_job_t  *job;                   /* Current job */
+  char         method[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 */
+  char         filename[1024],         /* Filename for document */
+               format[1024];           /* Format for document */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_document(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
+
+ /*
+  * See if we have a job URI or a printer URI...
+  */
+
+  if (!strcmp(uri->name, "printer-uri"))
+  {
+   /*
+    * Got a printer URI; see if we also have a job-id attribute...
+    */
+
+    if ((attr = ippFindAttribute(con->request, "job-id",
+                                 IPP_TAG_INTEGER)) == NULL)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Got a printer-uri attribute but no job-id!"));
+      return;
+    }
+
+    jobid = attr->values[0].integer;
+  }
+  else
+  {
+   /*
+    * Got a job URI; parse it to get the job ID...
+    */
+
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                    sizeof(method), username, sizeof(username), host,
+                   sizeof(host), &port, resource, sizeof(resource));
+
+    if (strncmp(resource, "/jobs/", 6))
+    {
+     /*
+      * Not a valid URI!
+      */
+
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Bad job-uri attribute \"%s\"!"),
+                      uri->values[0].string.text);
+      return;
+    }
+
+    jobid = atoi(resource + 6);
+  }
+
+ /*
+  * See if the job exists...
+  */
+
+  if ((job = cupsdFindJob(jobid)) == NULL)
+  {
+   /*
+    * Nope - return a "not found" error...
+    */
+
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    return;
+  }
+
+ /*
+  * Check policy...
+  */
+
+  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+  {
+    send_http_error(con, status, NULL);
+    return;
+  }
+
+ /*
+  * Get the document number...
+  */
+
+  if ((attr = ippFindAttribute(con->request, "document-number",
+                               IPP_TAG_INTEGER)) == NULL)
+  {
+    send_ipp_status(con, IPP_BAD_REQUEST,
+                    _("Missing document-number attribute!"));
+    return;
+  }
+
+  if ((docnum = attr->values[0].integer) < 1 || docnum > job->num_files ||
+      attr->num_values > 1)
+  {
+    send_ipp_status(con, IPP_NOT_FOUND, _("Document %d not found in job %d."),
+                    docnum, jobid);
+    return;
+  }
+
+  snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, jobid,
+           docnum);
+  if ((con->file = open(filename, O_RDONLY)) == -1)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "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);
+    return;
+  }
+
+  fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
+
+  cupsdLoadJob(job);
+
+  snprintf(format, sizeof(format), "%s/%s", job->filetypes[docnum - 1]->super,
+           job->filetypes[docnum - 1]->type);
+
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format",
+               NULL, format);
+  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "document-number",
+                docnum);
+  if ((attr = ippFindAttribute(job->attrs, "document-name",
+                               IPP_TAG_NAME)) != NULL)
+    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_NAME, "document-name",
+                 NULL, attr->values[0].string.text);
+}
+
+
 /*
  * 'get_job_attrs()' - Get job attributes.
  */
@@ -5275,7 +6700,7 @@ get_job_attrs(cupsd_client_t  *con,       /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -5304,9 +6729,9 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   http_status_t        status;                 /* Policy status */
   ipp_attribute_t *attr;               /* Current attribute */
   const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  cups_ptype_t dtype;                  /* Destination type (printer/class) */
   cups_ptype_t dmask;                  /* Destination type mask */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+  char         scheme[HTTP_MAX_URI],   /* Scheme 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 */
@@ -5328,8 +6753,8 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
+                  sizeof(scheme), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(resource, "/") ||
@@ -5354,7 +6779,8 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
     dmask   = CUPS_PRINTER_CLASS;
     printer = NULL;
   }
-  else if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  else if ((dest = cupsdValidateDest(uri->values[0].string.text, &dtype,
+                                     &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -5365,7 +6791,10 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
     return;
   }
   else
+  {
+    dtype &= CUPS_PRINTER_CLASS;
     dmask = CUPS_PRINTER_CLASS;
+  }
 
  /*
   * Check policy...
@@ -5373,15 +6802,16 @@ get_jobs(cupsd_client_t  *con,          /* I - Client connection */
 
   if (printer)
   {
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
+                                   NULL)) != HTTP_OK)
     {
-      send_http_error(con, status);
+      send_http_error(con, status, printer);
       return;
     }
   }
   else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -5401,6 +6831,11 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
     completed = 0;
     list      = Jobs;
   }
+  else if (attr && !strcmp(attr->values[0].string.text, "printing"))
+  {
+    completed = 0;
+    list      = PrintingJobs;
+  }
   else
   {
     completed = 0;
@@ -5415,7 +6850,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
                                IPP_TAG_INTEGER)) != NULL)
     limit = attr->values[0].integer;
   else
-    limit = 1000000;
+    limit = 0;
 
   if ((attr = ippFindAttribute(con->request, "first-job-id",
                                IPP_TAG_INTEGER)) != NULL)
@@ -5441,7 +6876,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   */
 
   for (count = 0, job = (cupsd_job_t *)cupsArrayFirst(list);
-       count < limit && job;
+       (limit <= 0 || count < limit) && job;
        job = (cupsd_job_t *)cupsArrayNext(list))
   {
    /*
@@ -5450,15 +6885,18 @@ get_jobs(cupsd_client_t  *con,          /* I - Client connection */
 
     cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: job->id = %d", job->id);
 
+    if (!job->dest || !job->username)
+      cupsdLoadJob(job);
+
+    if (!job->dest || !job->username)
+      continue;
+
     if ((dest && strcmp(job->dest, dest)) &&
         (!job->printer || !dest || strcmp(job->printer->name, dest)))
       continue;
     if ((job->dtype & dmask) != dtype &&
         (!job->printer || (job->printer->type & dmask) != dtype))
       continue;
-    if (username[0] && strcasecmp(username, job->username))
-      continue;
-
     if (completed && job->state_value <= IPP_JOB_STOPPED)
       continue;
 
@@ -5470,6 +6908,9 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
     if (!job->attrs)
       continue;
 
+    if (username[0] && strcasecmp(username, job->username))
+      continue;
+
     if (count > 0)
       ippAddSeparator(con->response);
 
@@ -5502,7 +6943,7 @@ get_notifications(cupsd_client_t *con)    /* I - Client connection */
   int                  interval;       /* Poll interval */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_subscription_attrs(con=%p[%d])",
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_notifications(con=%p[%d])",
                   con, con->http.fd);
 
  /*
@@ -5547,7 +6988,7 @@ get_notifications(cupsd_client_t *con)    /* I - Client connection */
                                                DefaultPolicyPtr,
                                    con, sub->owner)) != HTTP_OK)
     {
-      send_http_error(con, status);
+      send_http_error(con, status, sub->dest);
       return;
     }
 
@@ -5623,6 +7064,152 @@ get_notifications(cupsd_client_t *con)  /* I - Client connection */
 }
 
 
+/*
+ * 'get_ppd()' - Get a named PPD from the local system.
+ */
+
+static void
+get_ppd(cupsd_client_t  *con,          /* I - Client connection */
+        ipp_attribute_t *uri)          /* I - Printer URI or PPD name */
+{
+  http_status_t                status;         /* Policy status */
+  cupsd_printer_t      *dest;          /* Destination */
+  cups_ptype_t         dtype;          /* Destination type */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppd(%p[%d], %p[%s=%s])", con,
+                  con->http.fd, uri, uri->name, uri->values[0].string.text);
+
+  if (!strcmp(uri->name, "ppd-name"))
+  {
+   /*
+    * Return a PPD file from cups-driverd...
+    */
+
+    char       command[1024],  /* cups-driverd command */
+               options[1024],  /* Options to pass to command */
+               ppd_name[1024]; /* ppd-name */
+
+
+   /*
+    * Check policy...
+    */
+
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, NULL);
+      return;
+    }
+
+   /*
+    * Run cups-driverd command with the given options...
+    */
+
+    snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
+    url_encode_string(uri->values[0].string.text, ppd_name, sizeof(ppd_name));
+    snprintf(options, sizeof(options), "get+%d+%s",
+             con->request->request.op.request_id, ppd_name);
+
+    if (cupsdSendCommand(con, command, options, 0))
+    {
+     /*
+      * Command started successfully, don't send an IPP response here...
+      */
+
+      ippDelete(con->response);
+      con->response = NULL;
+    }
+    else
+    {
+     /*
+      * Command failed, return "internal error" so the user knows something
+      * went wrong...
+      */
+
+      send_ipp_status(con, IPP_INTERNAL_ERROR,
+                     _("cups-driverd failed to execute."));
+    }
+  }
+  else if (!strcmp(uri->name, "printer-uri") &&
+           cupsdValidateDest(uri->values[0].string.text, &dtype, &dest))
+  {
+    int        i;                      /* Looping var */
+    char       filename[1024];         /* PPD filename */
+
+
+   /*
+    * Check policy...
+    */
+
+    if ((status = cupsdCheckPolicy(dest->op_policy_ptr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status, dest);
+      return;
+    }
+
+   /*
+    * See if we need the PPD for a class or remote printer...
+    */
+
+    snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
+             dest->name);
+
+    if ((dtype & CUPS_PRINTER_REMOTE) && access(filename, 0))
+    {
+      con->response->request.status.status_code = CUPS_SEE_OTHER;
+      ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI,
+                   "printer-uri", NULL, dest->uri);
+      return;
+    }
+    else if (dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
+    {
+      for (i = 0; i < dest->num_printers; i ++)
+        if (!(dest->printers[i]->type &
+             (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)))
+       {
+         snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
+                  dest->printers[i]->name);
+
+          if (!access(filename, 0))
+           break;
+        }
+
+      if (i < dest->num_printers)
+        dest = dest->printers[i];
+      else
+      {
+        con->response->request.status.status_code = CUPS_SEE_OTHER;
+       ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI,
+                    "printer-uri", NULL, dest->printers[0]->uri);
+        return;
+      }
+    }
+
+   /*
+    * Found the printer with the PPD file, now see if there is one...
+    */
+
+    if ((con->file = open(filename, O_RDONLY)) < 0)
+    {
+      send_ipp_status(con, IPP_NOT_FOUND,
+                      _("The PPD file \"%s\" could not be opened: %s"),
+                     uri->values[0].string.text, strerror(errno));
+      return;
+    }
+
+    fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
+
+    con->pipe_pid = 0;
+
+    con->response->request.status.status_code = IPP_OK;
+  }
+  else
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The PPD file \"%s\" could not be found."),
+                    uri->values[0].string.text);
+}
+
+
 /*
  * 'get_ppds()' - Get the list of PPD files on the local system.
  */
@@ -5631,15 +7218,32 @@ static void
 get_ppds(cupsd_client_t *con)          /* I - Client connection */
 {
   http_status_t                status;         /* Policy status */
-  int                  i;              /* Looping var */
   ipp_attribute_t      *limit,         /* Limit attribute */
+                       *device,        /* ppd-device-id attribute */
+                       *language,      /* ppd-natural-language attribute */
                        *make,          /* ppd-make attribute */
+                       *model,         /* ppd-make-and-model attribute */
+                       *model_number,  /* ppd-model-number attribute */
+                       *product,       /* ppd-product attribute */
+                       *psversion,     /* ppd-psverion attribute */
+                       *type,          /* ppd-type attribute */
                        *requested;     /* requested-attributes attribute */
-  char                 command[1024],  /* cups-deviced command */
+  char                 command[1024],  /* cups-driverd command */
                        options[1024],  /* Options to pass to command */
-                       attrs[1024],    /* String for requested attributes */
-                       *aptr;          /* Pointer into string */
-  int                  alen;           /* Length of attribute value */
+                       device_str[256],/* Escaped ppd-device-id string */
+                       language_str[256],
+                                       /* Escaped ppd-natural-language */
+                       make_str[256],  /* Escaped ppd-make string */
+                       model_str[256], /* Escaped ppd-make-and-model string */
+                       model_number_str[256],
+                                       /* ppd-model-number string */
+                       product_str[256],
+                                       /* Escaped ppd-product string */
+                       psversion_str[256],
+                                       /* Escaped ppd-psversion string */
+                       type_str[256],  /* Escaped ppd-type string */
+                       requested_str[256];
+                                       /* String for requested attributes */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppds(%p[%d])", con, con->http.fd);
@@ -5650,7 +7254,7 @@ get_ppds(cupsd_client_t *con)             /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -5658,56 +7262,81 @@ get_ppds(cupsd_client_t *con)           /* I - Client connection */
   * Run cups-driverd command with the given options...
   */
 
-  limit     = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
-  make      = ippFindAttribute(con->request, "ppd-make", IPP_TAG_TEXT);
-  requested = ippFindAttribute(con->request, "requested-attributes",
-                               IPP_TAG_KEYWORD);
+  limit        = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
+  device       = ippFindAttribute(con->request, "ppd-device-id", IPP_TAG_TEXT);
+  language     = ippFindAttribute(con->request, "ppd-natural-language",
+                                  IPP_TAG_LANGUAGE);
+  make         = ippFindAttribute(con->request, "ppd-make", IPP_TAG_TEXT);
+  model        = ippFindAttribute(con->request, "ppd-make-and-model",
+                                  IPP_TAG_TEXT);
+  model_number = ippFindAttribute(con->request, "ppd-model-number",
+                                  IPP_TAG_INTEGER);
+  product      = ippFindAttribute(con->request, "ppd-product", IPP_TAG_TEXT);
+  psversion    = ippFindAttribute(con->request, "ppd-psversion", IPP_TAG_TEXT);
+  type         = ippFindAttribute(con->request, "ppd-type", IPP_TAG_KEYWORD);
+  requested    = ippFindAttribute(con->request, "requested-attributes",
+                                  IPP_TAG_KEYWORD);
 
   if (requested)
-  {
-    for (i = 0, aptr = attrs; i < requested->num_values; i ++)
-    {
-     /*
-      * Check that we have enough room...
-      */
+    url_encode_attr(requested, requested_str, sizeof(requested_str));
+  else
+    strlcpy(requested_str, "requested-attributes=all", sizeof(requested_str));
 
-      alen = strlen(requested->values[i].string.text);
-      if (alen > (sizeof(attrs) - (aptr - attrs) - 2))
-        break;
+  if (device)
+    url_encode_attr(device, device_str, sizeof(device_str));
+  else
+    device_str[0] = '\0';
 
-     /*
-      * Put commas between values...
-      */
+  if (language)
+    url_encode_attr(language, language_str, sizeof(language_str));
+  else
+    language_str[0] = '\0';
 
-      if (i)
-        *aptr++ = ',';
+  if (make)
+    url_encode_attr(make, make_str, sizeof(make_str));
+  else
+    make_str[0] = '\0';
 
-     /*
-      * Add the value to the end of the string...
-      */
+  if (model)
+    url_encode_attr(model, model_str, sizeof(model_str));
+  else
+    model_str[0] = '\0';
 
-      strcpy(aptr, requested->values[i].string.text);
-      aptr += alen;
-    }
+  if (model_number)
+    snprintf(model_number_str, sizeof(model_number_str), "ppd-model-number=%d",
+             model_number->values[0].integer);
+  else
+    model_number_str[0] = '\0';
 
-   /*
-    * If we have more attribute names than will fit, default to "all"...
-    */
+  if (product)
+    url_encode_attr(product, product_str, sizeof(product_str));
+  else
+    product_str[0] = '\0';
 
-    if (i < requested->num_values)
-      strcpy(attrs, "all");
-  }
+  if (psversion)
+    url_encode_attr(psversion, psversion_str, sizeof(psversion_str));
+  else
+    psversion_str[0] = '\0';
+
+  if (type)
+    url_encode_attr(type, type_str, sizeof(type_str));
   else
-    strcpy(attrs, "all");
+    type_str[0] = '\0';
 
   snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
   snprintf(options, sizeof(options),
-           "list+%d+%d+requested-attributes=%s%s%s",
+           "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
            con->request->request.op.request_id,
            limit ? limit->values[0].integer : 0,
-          attrs,
-          make ? "%20ppd-make=" : "",
-          make ? make->values[0].string.text : "");
+          requested_str,
+          device ? "%20" : "", device_str,
+          language ? "%20" : "", language_str,
+          make ? "%20" : "", make_str,
+          model ? "%20" : "", model_str,
+          model_number ? "%20" : "", model_number_str,
+          product ? "%20" : "", product_str,
+          psversion ? "%20" : "", psversion_str,
+          type ? "%20" : "", type_str);
 
   if (cupsdSendCommand(con, command, options, 0))
   {
@@ -5740,17 +7369,7 @@ get_printer_attrs(cupsd_client_t  *con,  /* I - Client connection */
                  ipp_attribute_t *uri) /* I - Printer URI */
 {
   http_status_t                status;         /* Policy status */
-  const char           *dest;          /* Destination */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[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 */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
   cupsd_printer_t      *printer;       /* Printer/class */
   cups_array_t         *ra;            /* Requested attributes array */
 
@@ -5762,11 +7381,7 @@ get_printer_attrs(cupsd_client_t  *con,  /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -5783,7 +7398,7 @@ get_printer_attrs(cupsd_client_t  *con,   /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -5811,7 +7426,7 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
 {
   http_status_t        status;                 /* Policy status */
   ipp_attribute_t *attr;               /* Current attribute */
-  int          limit;                  /* Maximum number of printers to return */
+  int          limit;                  /* Max number of printers to return */
   int          count;                  /* Number of printers that match */
   cupsd_printer_t *printer;            /* Current printer pointer */
   int          printer_type,           /* printer-type attribute */
@@ -5831,7 +7446,7 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -5911,8 +7526,8 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
   {
     if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
         (printer->type & printer_mask) == printer_type &&
-       (!location || !printer->location ||
-        !strcasecmp(printer->location, location)))
+       (!location ||
+        (printer->location && !strcasecmp(printer->location, location))))
     {
      /*
       * If HideImplicitMembers is enabled, see if this printer or class
@@ -5928,7 +7543,8 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
       * access...
       */
 
-      if (printer->num_users && username && !user_allowed(printer, username))
+      if (!(printer->type & CUPS_PRINTER_AUTHENTICATED) &&
+          printer->num_users && username && !user_allowed(printer, username))
         continue;
 
      /*
@@ -5995,7 +7611,7 @@ get_subscription_attrs(
                                              DefaultPolicyPtr,
                                  con, sub->owner)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, sub->dest);
     return;
   }
 
@@ -6028,9 +7644,9 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
   cupsd_subscription_t *sub;           /* Subscription */
   cups_array_t         *ra;            /* Requested attributes array */
   ipp_attribute_t      *attr;          /* Attribute */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[HTTP_MAX_URI],
-                                       /* Method portion of URI */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
+  char                 scheme[HTTP_MAX_URI],
+                                       /* Scheme portion of URI */
                        username[HTTP_MAX_URI],
                                        /* Username portion of URI */
                        host[HTTP_MAX_URI],
@@ -6050,8 +7666,8 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
+                  sizeof(scheme), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(resource, "/") ||
@@ -6074,7 +7690,7 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
       return;
     }
   }
-  else if (!cupsdValidateDest(host, resource, &dtype, &printer))
+  else if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -6107,7 +7723,7 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
                                            DefaultPolicyPtr,
                                  con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -6265,7 +7881,7 @@ 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);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
@@ -6275,6 +7891,9 @@ hold_job(cupsd_client_t  *con,            /* I - Client connection */
 
   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);
@@ -6308,10 +7927,12 @@ hold_job(cupsd_client_t  *con,          /* I - Client connection */
     */
 
     cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+
+    cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
+                  "Job job-hold-until value changed by user.");
   }
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid,
-                  username);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Held by \"%s\".", username);
 
   con->response->request.status.status_code = IPP_OK;
 }
@@ -6329,11 +7950,10 @@ move_job(cupsd_client_t  *con,          /* I - Client connection */
   ipp_attribute_t *attr;               /* Current attribute */
   int          jobid;                  /* Job ID */
   cupsd_job_t  *job;                   /* Current job */
-  const char   *src,                   /* Source printer/class */
-               *dest;                  /* Destination */
+  const char   *src;                   /* Source printer/class */
   cups_ptype_t stype,                  /* Source type (printer or class) */
-               dtype;                  /* Destination type (printer or class) */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               dtype;                  /* Destination type (printer/class) */
+  char         scheme[HTTP_MAX_URI],   /* Scheme 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 */
@@ -6360,12 +7980,8 @@ move_job(cupsd_client_t  *con,           /* I - Client connection */
                     _("job-printer-uri attribute missing!"));
     return;
   }
-    
-  httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
 
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &dprinter)) == NULL)
+  if (!cupsdValidateDest(attr->values[0].string.text, &dtype, &dprinter))
   {
    /*
     * Bad URI...
@@ -6376,22 +7992,12 @@ move_job(cupsd_client_t  *con,          /* I - Client connection */
     return;
   }
 
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-
  /*
   * See if we have a job URI or a printer URI...
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
+                  sizeof(scheme), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(uri->name, "printer-uri"))
@@ -6407,7 +8013,8 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
       * Move all jobs...
       */
 
-      if ((src = cupsdValidateDest(host, resource, &stype, &sprinter)) == NULL)
+      if ((src = cupsdValidateDest(uri->values[0].string.text, &stype,
+                                   &sprinter)) == NULL)
       {
        /*
        * Bad URI...
@@ -6492,6 +8099,17 @@ move_job(cupsd_client_t  *con,           /* I - Client connection */
     }
   }
 
+ /*
+  * Check the policy of the destination printer...
+  */
+
+  if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con,
+                                 job ? job->username : NULL)) != HTTP_OK)
+  {
+    send_http_error(con, status, dprinter);
+    return;
+  }
+
  /*
   * Now move the job or jobs...
   */
@@ -6520,7 +8138,7 @@ 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);
+      send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
       return;
     }
 
@@ -6578,56 +8196,6 @@ move_job(cupsd_client_t  *con,           /* I - Client connection */
 }
 
 
-/*
- * 'ppd_add_default()' - Add a PPD default choice.
- */
-
-static int                             /* O  - Number of defaults */
-ppd_add_default(
-    const char    *option,             /* I  - Option name */
-    const char    *choice,             /* I  - Choice name */
-    int           num_defaults,                /* I  - Number of defaults */
-    ppd_default_t **defaults)          /* IO - Defaults */
-{
-  int          i;                      /* Looping var */
-  ppd_default_t        *temp;                  /* Temporary defaults array */
-
-
- /*
-  * First check if the option already has a default value; the PPD spec
-  * says that the first one is used...
-  */
-
-  for (i = 0, temp = *defaults; i < num_defaults; i ++)
-    if (!strcmp(option, temp[i].option))
-      return (num_defaults);
-
- /*
-  * Now add the option...
-  */
-
-  if (num_defaults == 0)
-    temp = malloc(sizeof(ppd_default_t));
-  else
-    temp = realloc(*defaults, (num_defaults + 1) * sizeof(ppd_default_t));
-
-  if (!temp)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "ppd_add_default: Unable to add default value for \"%s\" - %s",
-               option, strerror(errno));
-    return (num_defaults);
-  }
-
-  *defaults = temp;
-  temp      += num_defaults;
-
-  strlcpy(temp->option, option, sizeof(temp->option));
-  strlcpy(temp->choice, choice, sizeof(temp->choice));
-
-  return (num_defaults + 1);
-}
-
-
 /*
  * 'ppd_parse_line()' - Parse a PPD default line.
  */
@@ -6705,6 +8273,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
 {
   ipp_attribute_t *attr;               /* Current attribute */
   ipp_attribute_t *format;             /* Document-format attribute */
+  const char   *default_format;        /* document-format-default value */
   cupsd_job_t  *job;                   /* New job */
   char         filename[1024];         /* Job filename */
   mime_type_t  *filetype;              /* Type of file */
@@ -6761,6 +8330,21 @@ print_job(cupsd_client_t  *con,          /* I - Client connection */
     return;
   }
 
+ /*
+  * Is the destination valid?
+  */
+
+  if (!cupsdValidateDest(uri->values[0].string.text, NULL, &printer))
+  {
+   /*
+    * Bad URI...
+    */
+
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The printer or class was not found."));
+    return;
+  }
+
  /*
   * Is it a format we support?
   */
@@ -6772,7 +8356,8 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
     * Grab format from client...
     */
 
-    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
+    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super,
+               type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
                       _("Could not scan type \"%s\"!"),
@@ -6780,10 +8365,26 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
       return;
     }
   }
+  else if ((default_format = cupsGetOption("document-format",
+                                           printer->num_options,
+                                          printer->options)) != NULL)
+  {
+   /*
+    * Use default document format...
+    */
+
+    if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Could not scan type \"%s\"!"),
+                     default_format);
+      return;
+    }
+  }
   else
   {
    /*
-    * No document format attribute?  Auto-type it!
+    * Auto-type it!
     */
 
     strcpy(super, "application");
@@ -6799,39 +8400,45 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
     ipp_attribute_t    *doc_name;      /* document-name attribute */
 
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: auto-typing file...");
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job ???] Auto-typing file...");
 
     doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
     filetype = mimeFileType(MimeDatabase, con->filename,
                             doc_name ? doc_name->values[0].string.text : NULL,
                            &compression);
 
-    if (filetype)
-    {
-     /*
-      * Replace the document-format attribute value with the auto-typed one.
-      */
+    if (!filetype)
+      filetype = mimeType(MimeDatabase, super, type);
 
-      snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
-               filetype->type);
+    cupsdLogMessage(CUPSD_LOG_INFO, "[Job ???] Request file type is %s/%s.",
+                   filetype->super, filetype->type);
+  }
+  else
+    filetype = mimeType(MimeDatabase, super, type);
 
-      if (format)
-      {
-         _cupsStrFree(format->values[0].string.text);
+  if (filetype &&
+      (!format ||
+       (!strcmp(super, "application") && !strcmp(type, "octet-stream"))))
+  {
+   /*
+    * Replace the document-format attribute value with the auto-typed or
+    * default one.
+    */
 
-       format->values[0].string.text = _cupsStrAlloc(mimetype);
-      }
-      else
-        ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
-                    "document-format", NULL, mimetype);
+    snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
+             filetype->type);
+
+    if (format)
+    {
+      _cupsStrFree(format->values[0].string.text);
+
+      format->values[0].string.text = _cupsStrAlloc(mimetype);
     }
     else
-      filetype = mimeType(MimeDatabase, super, type);
+      ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+                  "document-format", NULL, mimetype);
   }
-  else
-    filetype = mimeType(MimeDatabase, super, type);
-
-  if (!filetype)
+  else if (!filetype)
   {
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
                     _("Unsupported format \'%s/%s\'!"), super, type);
@@ -6845,22 +8452,20 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
     return;
   }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: request file type is %s/%s.",
-                 filetype->super, filetype->type);
-
  /*
   * Read any embedded job ticket info from PS files...
   */
 
   if (!strcasecmp(filetype->super, "application") &&
-      !strcasecmp(filetype->type, "postscript"))
-    read_ps_job_ticket(con);
+      (!strcasecmp(filetype->type, "postscript") ||
+       !strcasecmp(filetype->type, "pdf")))
+    read_job_ticket(con);
 
  /*
   * Create the job object...
   */
 
-  if ((job = add_job(con, uri, &printer, filetype)) == NULL)
+  if ((job = add_job(con, printer, filetype)) == NULL)
     return;
 
  /*
@@ -6894,31 +8499,19 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
   * See if we need to add the ending sheet...
   */
 
-  if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
-      attr->num_values > 1)
-  {
-   /*
-    * Yes...
-    */
-
-    cupsdLogMessage(CUPSD_LOG_INFO, "Adding end banner page \"%s\" to job %d.",
-                    attr->values[1].string.text, job->id);
-
-    kbytes = copy_banner(con, job, attr->values[1].string.text);
-
-    cupsdUpdateQuota(printer, job->username, 0, kbytes);
-  }
+  if (cupsdTimeoutJob(job))
+    return;
 
  /*
   * Log and save the job...
   */
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d queued on \"%s\" by \"%s\".", job->id,
-                  job->dest, job->username);
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "Job %d hold_until = %d", job->id,
-                  (int)job->hold_until);
-
-  cupsdSaveJob(job);
+  cupsdLogJob(job, CUPSD_LOG_INFO,
+             "File of type %s/%s queued by \"%s\".",
+             filetype->super, filetype->type, job->username);
+  cupsdLogJob(job, CUPSD_LOG_DEBUG, "hold_until=%d", (int)job->hold_until);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Queued on \"%s\" by \"%s\".",
+             job->dest, job->username);
 
  /*
   * Start the job if possible...
@@ -6929,16 +8522,16 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
 
 
 /*
- * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
+ * 'read_job_ticket()' - Read a job ticket embedded in a print file.
  *
- * This function only gets called when printing a single PostScript
+ * This function only gets called when printing a single PDF or PostScript
  * file using the Print-Job operation.  It doesn't work for Create-Job +
  * Send-File, since the job attributes need to be set at job creation
- * time for banners to work.  The embedded PS job ticket stuff is here
- * only to allow the Windows printer driver for CUPS to pass in JCL
+ * time for banners to work.  The embedded job ticket stuff is here
+ * primarily to allow the Windows printer driver for CUPS to pass in JCL
  * options and IPP attributes which otherwise would be lost.
  *
- * The format of a PS job ticket is simple:
+ * The format of a job ticket is simple:
  *
  *     %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
  *
@@ -6948,8 +8541,8 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
  *     %cupsJobTicket: attrN=valueN
  *
  * Job ticket lines must appear immediately after the first line that
- * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
- * looking for job ticket info when it finds a line that does not begin
+ * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
+ * stops looking for job ticket info when it finds a line that does not begin
  * with "%cupsJobTicket:".
  *
  * The maximum length of a job ticket line, including the prefix, is
@@ -6962,7 +8555,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
  */
 
 static void
-read_ps_job_ticket(cupsd_client_t *con)        /* I - Client connection */
+read_job_ticket(cupsd_client_t *con)   /* I - Client connection */
 {
   cups_file_t          *fp;            /* File to read from */
   char                 line[256];      /* Line data */
@@ -6981,8 +8574,7 @@ read_ps_job_ticket(cupsd_client_t *con)   /* I - Client connection */
   if ((fp = cupsFileOpen(con->filename, "rb")) == NULL)
   {
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "read_ps_job_ticket: Unable to open PostScript print file "
-                   "- %s",
+                    "Unable to open print file for job ticket - %s",
                     strerror(errno));
     return;
   }
@@ -6994,14 +8586,13 @@ read_ps_job_ticket(cupsd_client_t *con) /* I - Client connection */
   if (cupsFileGets(fp, line, sizeof(line)) == NULL)
   {
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "read_ps_job_ticket: Unable to read from PostScript print "
-                   "file - %s",
+                    "Unable to read from print file for job ticket - %s",
                     strerror(errno));
     cupsFileClose(fp);
     return;
   }
 
-  if (strncmp(line, "%!PS-Adobe-", 11))
+  if (strncmp(line, "%!PS-Adobe-", 11) && strncmp(line, "%PDF-", 5))
   {
    /*
     * Not a DSC-compliant file, so no job ticket info will be available...
@@ -7122,13 +8713,7 @@ reject_jobs(cupsd_client_t  *con,        /* I - Client connection */
             ipp_attribute_t *uri)      /* I - Printer or class URI */
 {
   http_status_t        status;                 /* Policy status */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
-  char         method[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 */
-  const char   *name;                  /* Printer name */
+  cups_ptype_t dtype;                  /* Destination type (printer/class) */
   cupsd_printer_t *printer;            /* Printer data */
   ipp_attribute_t *attr;               /* printer-state-message text */
 
@@ -7140,11 +8725,7 @@ reject_jobs(cupsd_client_t  *con,        /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -7161,7 +8742,7 @@ reject_jobs(cupsd_client_t  *con, /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -7182,17 +8763,17 @@ reject_jobs(cupsd_client_t  *con,       /* I - Client connection */
 
   if (dtype & CUPS_PRINTER_CLASS)
   {
-    cupsdSaveAllClasses();
+    cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
 
     cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" rejecting jobs (\"%s\").",
-                    name, get_username(con));
+                    printer->name, get_username(con));
   }
   else
   {
-    cupsdSaveAllPrinters();
+    cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
 
     cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" rejecting jobs (\"%s\").",
-                    name, get_username(con));
+                    printer->name, get_username(con));
   }
 
  /*
@@ -7303,7 +8884,7 @@ 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);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
@@ -7321,6 +8902,9 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
 
     attr->value_tag = IPP_TAG_KEYWORD;
     attr->values[0].string.text = _cupsStrAlloc("no-hold");
+
+    cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
+                  "Job job-hold-until value changed by user.");
   }
 
  /*
@@ -7329,10 +8913,14 @@ release_job(cupsd_client_t  *con,       /* I - Client connection */
 
   cupsdReleaseJob(job);
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was released by \"%s\".", jobid,
-                  username);
+  cupsdAddEvent(CUPSD_EVENT_JOB_STATE, cupsdFindDest(job->dest), job,
+                "Job released by user.");
+
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Released by \"%s\".", username);
 
   con->response->request.status.status_code = IPP_OK;
+
+  cupsdCheckJobs();
 }
 
 
@@ -7388,7 +8976,7 @@ renew_subscription(
                                              DefaultPolicyPtr,
                                  con, sub->owner)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, sub->dest);
     return;
   }
 
@@ -7412,9 +9000,12 @@ renew_subscription(
 
   sub->expire = sub->lease ? time(NULL) + sub->lease : 0;
 
-  cupsdSaveAllSubscriptions();
+  cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
 
   con->response->request.status.status_code = IPP_OK;
+
+  ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                "notify-lease-duration", sub->lease);
 }
 
 
@@ -7519,7 +9110,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
 
   cupsdLoadJob(job);
 
-  if (!job->attrs ||job->num_files == 0)
+  if (!job->attrs || job->num_files == 0)
   {
    /*
     * Nope - return a "not possible" error...
@@ -7536,7 +9127,7 @@ 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);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
@@ -7546,8 +9137,7 @@ restart_job(cupsd_client_t  *con, /* I - Client connection */
 
   cupsdRestartJob(job);
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was restarted by \"%s\".", jobid,
-                  username);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Restarted by \"%s\".", username);
 
   con->response->request.status.status_code = IPP_OK;
 }
@@ -7558,22 +9148,25 @@ restart_job(cupsd_client_t  *con,       /* I - Client connection */
  */
 
 static void
-save_auth_info(cupsd_client_t *con,    /* I - Client connection */
-               cupsd_job_t    *job)    /* I - Job */
+save_auth_info(
+    cupsd_client_t  *con,              /* I - Client connection */
+    cupsd_job_t     *job,              /* I - Job */
+    ipp_attribute_t *auth_info)                /* I - auth-info attribute, if any */
 {
-  int          i;                      /* Looping var */
-  char         filename[1024];         /* Job authentication filename */
-  cups_file_t  *fp;                    /* Job authentication file */
-  char         line[1024];             /* Line for file */
+  int                  i;              /* Looping var */
+  char                 filename[1024]; /* Job authentication filename */
+  cups_file_t          *fp;            /* Job authentication file */
+  char                 line[2048];     /* Line for file */
+  cupsd_printer_t      *dest;          /* Destination printer/class */
 
 
  /*
   * This function saves the in-memory authentication information for
   * a job so that it can be used to authenticate with a remote host.
   * The information is stored in a file that is readable only by the
-  * root user.  The username and password are Base-64 encoded, each
-  * on a separate line, followed by random number (up to 1024) of
-  * newlines to limit the amount of information that is exposed.
+  * root user.  The fields are Base-64 encoded, each on a separate line,
+  * followed by random number (up to 1024) of newlines to limit the
+  * amount of information that is exposed.
   *
   * Because of the potential for exposing of authentication information,
   * this functionality is only enabled when running cupsd as root.
@@ -7593,6 +9186,9 @@ save_auth_info(cupsd_client_t *con,       /* I - Client connection */
   if (RunUser)
     return;
 
+  if ((dest = cupsdFindDest(job->dest)) == NULL)
+    return;
+
  /*
   * Create the authentication file and change permissions...
   */
@@ -7609,33 +9205,203 @@ save_auth_info(cupsd_client_t *con,    /* I - Client connection */
   fchown(cupsFileNumber(fp), 0, 0);
   fchmod(cupsFileNumber(fp), 0400);
 
+  if (auth_info && auth_info->num_values == dest->num_auth_info_required)
+  {
+   /*
+    * Write 1 to 3 auth values...
+    */
+
+    cupsdClearString(&job->auth_username);
+    cupsdClearString(&job->auth_domain);
+    cupsdClearString(&job->auth_password);
+
+    for (i = 0; i < auth_info->num_values; i ++)
+    {
+      httpEncode64_2(line, sizeof(line), auth_info->values[i].string.text,
+                     strlen(auth_info->values[i].string.text));
+      cupsFilePrintf(fp, "%s\n", line);
+
+      if (!strcmp(dest->auth_info_required[i], "username"))
+        cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s",
+                       auth_info->values[i].string.text);
+      else if (!strcmp(dest->auth_info_required[i], "domain"))
+        cupsdSetStringf(&job->auth_domain, "AUTH_DOMAIN=%s",
+                       auth_info->values[i].string.text);
+      else if (!strcmp(dest->auth_info_required[i], "password"))
+        cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s",
+                       auth_info->values[i].string.text);
+    }
+  }
+  else if (con->username[0])
+  {
+   /*
+    * Write the authenticated username...
+    */
+
+    httpEncode64_2(line, sizeof(line), con->username, strlen(con->username));
+    cupsFilePrintf(fp, "%s\n", line);
+
+    cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s", con->username);
+    cupsdClearString(&job->auth_domain);
+
+   /*
+    * Write the authenticated password...
+    */
+
+    httpEncode64_2(line, sizeof(line), con->password, strlen(con->password));
+    cupsFilePrintf(fp, "%s\n", line);
+
+    cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s", con->password);
+  }
+
  /*
-  * Write the authenticated username...
+  * Write a random number of newlines to the end of the file...
   */
 
-  httpEncode64_2(line, sizeof(line), con->username, strlen(con->username));
-  cupsFilePrintf(fp, "%s\n", line);
+  for (i = (rand() % 1024); i >= 0; i --)
+    cupsFilePutChar(fp, '\n');
 
  /*
-  * Write the authenticated password...
+  * Close the file and return...
   */
 
-  httpEncode64_2(line, sizeof(line), con->password, strlen(con->password));
-  cupsFilePrintf(fp, "%s\n", line);
+  cupsFileClose(fp);
+
+#if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
+  if (con->gss_have_creds)
+    save_krb5_creds(con, job);
+  else if (job->ccname)
+    cupsdClearString(&(job->ccname));
+#endif /* HAVE_GSSAPI && HAVE_KRB5_H */
+}
+
+
+#if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
+/*
+ * 'save_krb5_creds()' - Save Kerberos credentials for the job.
+ */
+
+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__
  /*
-  * Write a random number of newlines to the end of the file...
+  * If the weak-linked GSSAPI/Kerberos library is not present, don't try
+  * to use it...
   */
 
-  for (i = (rand() % 1024); i >= 0; i --)
-    cupsFilePutChar(fp, '\n');
+  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;
+  }
 
  /*
-  * Close the file and return...
+  * Add the KRB5CCNAME environment variable to the job so that the
+  * backend can use the credentials when printing.
   */
 
-  cupsFileClose(fp);
+  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 */
 }
+#endif /* HAVE_GSSAPI && HAVE_KRB5_H */
 
 
 /*
@@ -7647,7 +9413,9 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
              ipp_attribute_t *uri)     /* I - Printer URI */
 {
   ipp_attribute_t      *attr;          /* Current attribute */
-  ipp_attribute_t      *format;        /* Document-format attribute */
+  ipp_attribute_t      *format;        /* Request's document-format attribute */
+  ipp_attribute_t      *jformat;       /* Job's document-format attribute */
+  const char           *default_format;/* document-format-default value */
   int                  jobid;          /* Job ID number */
   cupsd_job_t          *job;           /* Current job */
   char                 job_uri[HTTP_MAX_URI],
@@ -7673,6 +9441,7 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
   struct stat          fileinfo;       /* File information */
   int                  kbytes;         /* Size of file */
   int                  compression;    /* Type of compression */
+  int                  start_job;      /* Start the job? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_document(%p[%d], %s)", con,
@@ -7737,13 +9506,15 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
     return;
   }
 
+  printer = cupsdFindDest(job->dest);
+
  /*
   * See if the job is owned by the requesting user...
   */
 
   if (!validate_user(job, con, job->username, username, sizeof(username)))
   {
-    send_http_error(con, HTTP_UNAUTHORIZED);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
@@ -7797,13 +9568,30 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
     * Grab format from client...
     */
 
-    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
+    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]",
+               super, type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\"!"),
                      format->values[0].string.text);
       return;
     }
   }
+  else if ((default_format = cupsGetOption("document-format",
+                                           printer->num_options,
+                                          printer->options)) != NULL)
+  {
+   /*
+    * Use default document format...
+    */
+
+    if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Could not scan type \"%s\"!"),
+                     default_format);
+      return;
+    }
+  }
   else
   {
    /*
@@ -7823,38 +9611,44 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
     ipp_attribute_t    *doc_name;      /* document-name attribute */
 
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "send_document: auto-typing file...");
+    cupsdLogJob(job, CUPSD_LOG_DEBUG, "Auto-typing file...");
 
     doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
     filetype = mimeFileType(MimeDatabase, con->filename,
                             doc_name ? doc_name->values[0].string.text : NULL,
                            &compression);
 
-    if (filetype)
-    {
-     /*
-      * Replace the document-format attribute value with the auto-typed one.
-      */
-
-      snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
-               filetype->type);
-
-      if (format)
-      {
-       _cupsStrFree(format->values[0].string.text);
-       format->values[0].string.text = _cupsStrAlloc(mimetype);
-      }
-      else
-        ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
-                    "document-format", NULL, mimetype);
-    }
-    else
+    if (!filetype)
       filetype = mimeType(MimeDatabase, super, type);
+
+    cupsdLogJob(job, CUPSD_LOG_DEBUG, "Request file type is %s/%s.",
+               filetype->super, filetype->type);
   }
   else
     filetype = mimeType(MimeDatabase, super, type);
 
-  if (!filetype)
+  if (filetype)
+  {
+   /*
+    * Replace the document-format attribute value with the auto-typed or
+    * default one.
+    */
+
+    snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
+             filetype->type);
+
+    if ((jformat = ippFindAttribute(job->attrs, "document-format",
+                                    IPP_TAG_MIMETYPE)) != NULL)
+    {
+      _cupsStrFree(jformat->values[0].string.text);
+
+      jformat->values[0].string.text = _cupsStrAlloc(mimetype);
+    }
+    else
+      ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+                  "document-format", NULL, mimetype);
+  }
+  else if (!filetype)
   {
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
                     _("Unsupported format \'%s/%s\'!"), super, type);
@@ -7868,8 +9662,6 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
     return;
   }
 
-  printer = cupsdFindDest(job->dest);
-
   if (printer->filetypes && !cupsArrayFind(printer->filetypes, filetype))
   {
     snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
@@ -7884,10 +9676,6 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
     return;
   }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG,
-                  "send_document: request file type is %s/%s.",
-                 filetype->super, filetype->type);
-
  /*
   * Add the file to the job...
   */
@@ -7914,9 +9702,8 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
 
   cupsdClearString(&con->filename);
 
-  cupsdLogMessage(CUPSD_LOG_INFO,
-                  "File of type %s/%s queued in job #%d by \"%s\".",
-                  filetype->super, filetype->type, job->id, job->username);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "File of type %s/%s queued by \"%s\".",
+             filetype->super, filetype->type, job->username);
 
  /*
   * Start the job if this is the last document...
@@ -7930,24 +9717,8 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
     * See if we need to add the ending sheet...
     */
 
-    if (printer &&
-        !(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
-        (attr = ippFindAttribute(job->attrs, "job-sheets",
-                                IPP_TAG_ZERO)) != NULL &&
-        attr->num_values > 1)
-    {
-     /*
-      * Yes...
-      */
-
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Adding end banner page \"%s\" to job %d.",
-                     attr->values[1].string.text, job->id);
-
-      kbytes = copy_banner(con, job, attr->values[1].string.text);
-
-      cupsdUpdateQuota(printer, job->username, 0, kbytes);
-    }
+    if (cupsdTimeoutJob(job))
+      return;
 
     if (job->state_value == IPP_JOB_STOPPED)
     {
@@ -7967,18 +9738,10 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
       }
     }
 
-    cupsdSaveJob(job);
-
-   /*
-    * Start the job if possible...  Since cupsdCheckJobs() can cancel a
-    * job if it doesn't print, we need to re-find the job afterwards...
-    */
-
-    jobid = job->id;
-
-    cupsdCheckJobs();
+    job->dirty = 1;
+    cupsdMarkDirty(CUPSD_DIRTY_JOBS);
 
-    job = cupsdFindJob(jobid);
+    start_job = 1;
   }
   else
   {
@@ -7991,8 +9754,12 @@ 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;
-      cupsdSaveJob(job);
+      job->dirty                    = 1;
+
+      cupsdMarkDirty(CUPSD_DIRTY_JOBS);
     }
+
+    start_job = 0;
   }
 
  /*
@@ -8008,10 +9775,17 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", jobid);
 
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
-                job ? job->state_value : IPP_JOB_CANCELLED);
+                job->state_value);
   add_job_state_reasons(con, job);
 
   con->response->request.status.status_code = IPP_OK;
+
+ /*
+  * Start the job if necessary...
+  */
+
+  if (start_job)
+    cupsdCheckJobs();
 }
 
 
@@ -8020,14 +9794,81 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
  */
 
 static void
-send_http_error(cupsd_client_t *con,   /* I - Client connection */
-                http_status_t  status) /* I - HTTP status code */
+send_http_error(
+    cupsd_client_t  *con,              /* I - Client connection */
+    http_status_t   status,            /* I - HTTP status code */
+    cupsd_printer_t *printer)          /* I - Printer, if any */
 {
-  cupsdLogMessage(CUPSD_LOG_ERROR, "%s: %s",
-                  ippOpString(con->request->request.op.operation_id),
-                 httpStatus(status));
+  ipp_attribute_t      *uri;           /* Request URI, if any */
+
+
+  if ((uri = ippFindAttribute(con->request, "printer-uri",
+                              IPP_TAG_URI)) == NULL)
+    uri = ippFindAttribute(con->request, "job-uri", IPP_TAG_URI);
+
+  cupsdLogMessage(status == HTTP_FORBIDDEN ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG,
+                  "Returning HTTP %s for %s (%s) from %s",
+                  httpStatus(status),
+                 ippOpString(con->request->request.op.operation_id),
+                 uri ? uri->values[0].string.text : "no URI",
+                 con->http.hostname);
+
+  if (printer)
+  {
+    int                auth_type;              /* Type of authentication required */
+
+
+    auth_type = CUPSD_AUTH_NONE;
+
+    if (status == HTTP_UNAUTHORIZED &&
+        printer->num_auth_info_required > 0 &&
+        !strcmp(printer->auth_info_required[0], "negotiate") &&
+       con->request &&
+       (con->request->request.op.operation_id == IPP_PRINT_JOB ||
+        con->request->request.op.operation_id == IPP_CREATE_JOB ||
+        con->request->request.op.operation_id == CUPS_AUTHENTICATE_JOB))
+    {
+     /*
+      * Creating and authenticating jobs requires Kerberos...
+      */
+
+      auth_type = CUPSD_AUTH_NEGOTIATE;
+    }
+    else
+    {
+     /*
+      * Use policy/location-defined authentication requirements...
+      */
+
+      char     resource[HTTP_MAX_URI]; /* Resource portion of URI */
+      cupsd_location_t *auth;          /* Pointer to authentication element */
+
+
+      if (printer->type & CUPS_PRINTER_CLASS)
+       snprintf(resource, sizeof(resource), "/classes/%s", printer->name);
+      else
+       snprintf(resource, sizeof(resource), "/printers/%s", printer->name);
+
+      if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
+         auth->type == CUPSD_AUTH_NONE)
+       auth = cupsdFindPolicyOp(printer->op_policy_ptr,
+                                con->request ?
+                                    con->request->request.op.operation_id :
+                                    IPP_PRINT_JOB);
+
+      if (auth)
+      {
+        if (auth->type == CUPSD_AUTH_DEFAULT)
+         auth_type = DefaultAuthType;
+       else
+         auth_type = auth->type;
+      }
+    }
 
-  cupsdSendError(con, status);
+    cupsdSendError(con, status, auth_type);
+  }
+  else
+    cupsdSendError(con, status, CUPSD_AUTH_NONE);
 
   ippDelete(con->response);
   con->response = NULL;
@@ -8042,31 +9883,22 @@ send_http_error(cupsd_client_t *con,    /* I - Client connection */
 
 static void
 send_ipp_status(cupsd_client_t *con,   /* I - Client connection */
-               ipp_status_t   status,  /* I - IPP status code */
-              const char     *message, /* I - Status message */
-              ...)                     /* I - Additional args as needed */
+                ipp_status_t   status, /* I - IPP status code */
+               const char     *message,/* I - Status message */
+               ...)                    /* I - Additional args as needed */
 {
   va_list      ap;                     /* Pointer to additional args */
   char         formatted[1024];        /* Formatted errror message */
 
 
-  if (message)
-  {
-    va_start(ap, message);
-    vsnprintf(formatted, sizeof(formatted),
-              _cupsLangString(con->language, message), ap);
-    va_end(ap);
+  va_start(ap, message);
+  vsnprintf(formatted, sizeof(formatted),
+            _cupsLangString(con->language, message), ap);
+  va_end(ap);
 
-    cupsdLogMessage(status >= IPP_BAD_REQUEST ? CUPSD_LOG_ERROR : CUPSD_LOG_INFO,
-                    "%s %s: %s",
-                   ippOpString(con->request->request.op.operation_id),
-                   ippErrorString(status), formatted);
-  }
-  else
-    cupsdLogMessage(status >= IPP_BAD_REQUEST ? CUPSD_LOG_ERROR : CUPSD_LOG_INFO,
-                    "%s %s",
-                   ippOpString(con->request->request.op.operation_id),
-                   ippErrorString(status));
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "%s %s: %s",
+                 ippOpString(con->request->request.op.operation_id),
+                 ippErrorString(status), formatted);
 
   con->response->request.status.status_code = status;
 
@@ -8080,9 +9912,8 @@ send_ipp_status(cupsd_client_t *con,      /* I - Client connection */
     ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                  "attributes-natural-language", NULL, DefaultLanguage);
 
-  if (message)
-    ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_TEXT,
-                "status-message", NULL, formatted);
+  ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_TEXT,
+               "status-message", NULL, formatted);
 }
 
 
@@ -8095,18 +9926,9 @@ set_default(cupsd_client_t  *con,        /* I - Client connection */
             ipp_attribute_t *uri)      /* I - Printer URI */
 {
   http_status_t                status;         /* Policy status */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[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 */
-  const char           *name;          /* Printer name */
-  cupsd_printer_t      *printer;       /* Printer */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
+  cupsd_printer_t      *printer,       /* Printer */
+                       *oldprinter;    /* Old default printer */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_default(%p[%d], %s)", con,
@@ -8116,11 +9938,7 @@ set_default(cupsd_client_t  *con,        /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -8137,7 +9955,7 @@ set_default(cupsd_client_t  *con, /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, NULL);
     return;
   }
 
@@ -8145,16 +9963,22 @@ set_default(cupsd_client_t  *con,       /* I - Client connection */
   * Set it as the default...
   */
 
+  oldprinter     = DefaultPrinter;
   DefaultPrinter = printer;
 
-  cupsdSaveAllPrinters();
-  cupsdSaveAllClasses();
+  if (oldprinter)
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, oldprinter, NULL,
+                  "%s is no longer the default printer.", oldprinter->name);
 
-  cupsdWritePrintcap();
+  cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
+               "%s is now the default printer.", printer->name);
+
+  cupsdMarkDirty(CUPSD_DIRTY_PRINTERS | CUPSD_DIRTY_CLASSES |
+                 CUPSD_DIRTY_REMOTE | CUPSD_DIRTY_PRINTCAP);
 
   cupsdLogMessage(CUPSD_LOG_INFO,
-                  "Default destination set to \"%s\" by \"%s\".", name,
-                  get_username(con));
+                  "Default destination set to \"%s\" by \"%s\".",
+                 printer->name, get_username(con));
 
  /*
   * Everything was ok, so return OK status...
@@ -8185,6 +10009,8 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
                        resource[HTTP_MAX_URI];
                                        /* Resource portion of URI */
   int                  port;           /* Port portion of URI */
+  int                  event;          /* Events? */
+  int                  check_jobs;     /* Check jobs? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_job_attrs(%p[%d], %s)", con,
@@ -8276,7 +10102,7 @@ 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);
+    send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest));
     return;
   }
 
@@ -8286,6 +10112,9 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
 
   cupsdLoadJob(job);
 
+  check_jobs = 0;
+  event      = 0;
+
   for (attr = con->request->attrs; attr; attr = attr->next)
   {
     if (attr->group_tag != IPP_TAG_JOB || !attr->name)
@@ -8298,6 +10127,7 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
        !strcmp(attr->name, "job-detailed-status-messages") ||
        !strcmp(attr->name, "job-document-access-errors") ||
        !strcmp(attr->name, "job-id") ||
+       !strcmp(attr->name, "job-impressions-completed") ||
        !strcmp(attr->name, "job-k-octets") ||
         !strcmp(attr->name, "job-originating-host-name") ||
         !strcmp(attr->name, "job-originating-user-name") ||
@@ -8311,7 +10141,6 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
        !strcmp(attr->name, "number-of-intervening-jobs") ||
        !strcmp(attr->name, "output-device-assigned") ||
        !strncmp(attr->name, "date-time-at-", 13) ||
-       !strncmp(attr->name, "job-impressions", 15) ||
        !strncmp(attr->name, "job-k-octets", 12) ||
        !strncmp(attr->name, "job-media-sheets", 16) ||
        !strncmp(attr->name, "time-at-", 8))
@@ -8349,7 +10178,15 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
        return;
       }
       else if (con->response->request.status.status_code == IPP_OK)
+      {
+        cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-priority to %d",
+                   attr->values[0].integer);
         cupsdSetJobPriority(job, attr->values[0].integer);
+
+       check_jobs = 1;
+        event      |= CUPSD_EVENT_JOB_CONFIG_CHANGED |
+                     CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED;
+      }
     }
     else if (!strcmp(attr->name, "job-state"))
     {
@@ -8378,8 +10215,14 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
              }
               else if (con->response->request.status.status_code == IPP_OK)
              {
+               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              = attr->values[0].integer;
+               job->state_value = (ipp_jstate_t)attr->values[0].integer;
+
+                event |= CUPSD_EVENT_JOB_STATE;
+               check_jobs = 1;
              }
              break;
 
@@ -8393,7 +10236,7 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
              }
              break;
 
-         case IPP_JOB_CANCELLED :
+         case IPP_JOB_CANCELED :
          case IPP_JOB_ABORTED :
          case IPP_JOB_COMPLETED :
              if (job->state_value > IPP_JOB_PROCESSING)
@@ -8404,14 +10247,11 @@ set_job_attrs(cupsd_client_t  *con,    /* I - Client connection */
              }
               else if (con->response->request.status.status_code == IPP_OK)
              {
-                cupsdCancelJob(job, 0);
+               cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-state to %d",
+                           attr->values[0].integer);
+                cupsdCancelJob(job, 0, (ipp_jstate_t)attr->values[0].integer);
 
-               if (JobHistory)
-               {
-                  job->state->values[0].integer = attr->values[0].integer;
-                  job->state_value              = attr->values[0].integer;
-                 cupsdSaveJob(job);
-               }
+                check_jobs = 1;
              }
              break;
        }
@@ -8448,12 +10288,17 @@ set_job_attrs(cupsd_client_t  *con,    /* I - Client connection */
 
       if (!strcmp(attr->name, "job-hold-until"))
       {
+        cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-hold-until to %s",
+                   attr->values[0].string.text);
         cupsdSetJobHoldUntil(job, attr->values[0].string.text);
 
        if (!strcmp(attr->values[0].string.text, "no-hold"))
          cupsdReleaseJob(job);
        else
          cupsdHoldJob(job);
+
+        check_jobs = 1;
+        event      |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
       }
     }
     else if (attr->value_tag == IPP_TAG_DELETEATTR)
@@ -8474,6 +10319,8 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
          job->attrs->last = job->attrs->prev;
 
         _ippFreeAttr(attr2);
+
+        event |= CUPSD_EVENT_JOB_CONFIG_CHANGED;
       }
     }
     else
@@ -8483,6 +10330,8 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
       */
 
       copy_attribute(job->attrs, attr, 0);
+
+      event |= CUPSD_EVENT_JOB_CONFIG_CHANGED;
     }
   }
 
@@ -8490,13 +10339,33 @@ set_job_attrs(cupsd_client_t  *con,    /* I - Client connection */
   * Save the job...
   */
 
-  cupsdSaveJob(job);
+  job->dirty = 1;
+  cupsdMarkDirty(CUPSD_DIRTY_JOBS);
+
+ /*
+  * Send events as needed...
+  */
+
+  if (event & CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED)
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED,
+                  cupsdFindDest(job->dest), job,
+                  "Job priority changed by user.");
+
+  if (event & CUPSD_EVENT_JOB_STATE)
+    cupsdAddEvent(CUPSD_EVENT_JOB_STATE, cupsdFindDest(job->dest), job,
+                  job->state_value == IPP_JOB_HELD ?
+                     "Job held by user." : "Job restarted by user.");
+
+  if (event & CUPSD_EVENT_JOB_CONFIG_CHANGED)
+    cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
+                  "Job options changed by user.");
 
  /*
   * Start jobs if possible...
   */
 
-  cupsdCheckJobs();
+  if (check_jobs)
+    cupsdCheckJobs();
 }
 
 
@@ -8642,6 +10511,7 @@ set_printer_defaults(
         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"))
       {
@@ -8656,10 +10526,6 @@ set_printer_defaults(
                       attr->values[0].string.text);
       cupsdSetString(&printer->error_policy, attr->values[0].string.text);
     }
-    else if (!strcmp(attr->name, "document-format-default") ||
-             !strcmp(attr->name, "notify-lease-duration-default") ||
-             !strcmp(attr->name, "notify-notify-events-default"))
-      continue;
 
    /*
     * Skip any other non-default attributes...
@@ -8759,17 +10625,7 @@ start_printer(cupsd_client_t  *con,     /* I - Client connection */
               ipp_attribute_t *uri)    /* I - Printer URI */
 {
   http_status_t                status;         /* Policy status */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[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 */
-  const char           *name;          /* Printer name */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
   cupsd_printer_t      *printer;       /* Printer data */
 
 
@@ -8780,11 +10636,7 @@ start_printer(cupsd_client_t  *con,     /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -8801,7 +10653,7 @@ start_printer(cupsd_client_t  *con,      /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -8814,19 +10666,11 @@ start_printer(cupsd_client_t  *con,    /* I - Client connection */
   cupsdStartPrinter(printer, 1);
 
   if (dtype & CUPS_PRINTER_CLASS)
-  {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" started by \"%s\".", name,
-                    get_username(con));
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Class \"%s\" started by \"%s\".", name, get_username(con));
-  }
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" started by \"%s\".",
+                    printer->name, get_username(con));
   else
-  {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" started by \"%s\".", name,
-                    get_username(con));
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Printer \"%s\" started by \"%s\".", name, get_username(con));
-  }
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" started by \"%s\".",
+                    printer->name, get_username(con));
 
   cupsdCheckJobs();
 
@@ -8847,17 +10691,7 @@ stop_printer(cupsd_client_t  *con,      /* I - Client connection */
              ipp_attribute_t *uri)     /* I - Printer URI */
 {
   http_status_t                status;         /* Policy status */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[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 */
-  const char           *name;          /* Printer name */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
   cupsd_printer_t      *printer;       /* Printer data */
   ipp_attribute_t      *attr;          /* printer-state-message attribute */
 
@@ -8869,11 +10703,7 @@ stop_printer(cupsd_client_t  *con,      /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -8890,7 +10720,7 @@ stop_printer(cupsd_client_t  *con,       /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -8910,19 +10740,11 @@ stop_printer(cupsd_client_t  *con,     /* I - Client connection */
   cupsdStopPrinter(printer, 1);
 
   if (dtype & CUPS_PRINTER_CLASS)
-  {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" stopped by \"%s\".", name,
-                    get_username(con));
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Class \"%s\" stopped by \"%s\".", name, get_username(con));
-  }
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" stopped by \"%s\".",
+                    printer->name, get_username(con));
   else
-  {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" stopped by \"%s\".", name,
-                    get_username(con));
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Printer \"%s\" stopped by \"%s\".", name, get_username(con));
-  }
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" stopped by \"%s\".",
+                    printer->name, get_username(con));
 
  /*
   * Everything was ok, so return OK status...
@@ -8932,6 +10754,101 @@ stop_printer(cupsd_client_t  *con,     /* I - Client connection */
 }
 
 
+/*
+ * 'url_encode_attr()' - URL-encode a string attribute.
+ */
+
+static void
+url_encode_attr(ipp_attribute_t *attr, /* I - Attribute */
+                char            *buffer,/* I - String buffer */
+               int             bufsize)/* I - Size of buffer */
+{
+  int  i;                              /* Looping var */
+  char *bufptr,                        /* Pointer into buffer */
+       *bufend;                        /* End of buffer */
+
+
+  strlcpy(buffer, attr->name, bufsize);
+  bufptr = buffer + strlen(buffer);
+  bufend = buffer + bufsize - 1;
+
+  for (i = 0; i < attr->num_values; i ++)
+  {
+    if (bufptr >= bufend)
+      break;
+
+    if (i)
+      *bufptr++ = ',';
+    else
+      *bufptr++ = '=';
+
+    if (bufptr >= bufend)
+      break;
+
+    *bufptr++ = '\'';
+
+    bufptr = url_encode_string(attr->values[i].string.text,
+                               bufptr, bufend - bufptr + 1);
+
+    if (bufptr >= bufend)
+      break;
+
+    *bufptr++ = '\'';
+  }
+
+  *bufptr = '\0';
+}
+
+
+/*
+ * 'url_encode_string()' - URL-encode a string.
+ */
+
+static char *                          /* O - End of string */
+url_encode_string(const char *s,       /* I - String */
+                  char       *buffer,  /* I - String buffer */
+                 int        bufsize)   /* I - Size of buffer */
+{
+  char *bufptr,                        /* Pointer into buffer */
+       *bufend;                        /* End of buffer */
+  static const char *hex = "0123456789ABCDEF";
+                                       /* Hex digits */
+
+
+  bufptr = buffer;
+  bufend = buffer + bufsize - 1;
+
+  while (*s && bufptr < bufend)
+  {
+    if (*s == ' ' || *s == '%')
+    {
+      if (bufptr >= (bufend - 2))
+       break;
+
+      *bufptr++ = '%';
+      *bufptr++ = hex[(*s >> 4) & 15];
+      *bufptr++ = hex[*s & 15];
+
+      s ++;
+    }
+    else if (*s == '\'' || *s == '\\')
+    {
+      if (bufptr >= (bufend - 1))
+       break;
+
+      *bufptr++ = '\\';
+      *bufptr++ = *s++;
+    }
+    else
+      *bufptr++ = *s++;
+  }
+
+  *bufptr = '\0';
+
+  return (bufptr);
+}
+
+
 /*
  * 'user_allowed()' - See if a user is allowed to print to a queue.
  */
@@ -8942,6 +10859,8 @@ user_allowed(cupsd_printer_t *p, /* I - Printer or class */
 {
   int          i;                      /* Looping var */
   struct passwd        *pw;                    /* User password data */
+  char         baseuser[256],          /* Base username */
+               *baseptr;               /* Pointer to "@" in base username */
 
 
   if (p->num_users == 0)
@@ -8950,6 +10869,20 @@ user_allowed(cupsd_printer_t *p,        /* I - Printer or class */
   if (!strcmp(username, "root"))
     return (1);
 
+  if (strchr(username, '@'))
+  {
+   /*
+    * Strip @REALM for username check...
+    */
+
+    strlcpy(baseuser, username, sizeof(baseuser));
+
+    if ((baseptr = strchr(baseuser, '@')) != NULL)
+      *baseptr = '\0';
+
+    username = baseuser;
+  }
+
   pw = getpwnam(username);
   endpwent();
 
@@ -8964,6 +10897,15 @@ user_allowed(cupsd_printer_t *p,        /* I - Printer or class */
       if (cupsdCheckGroup(username, pw, p->users[i] + 1))
         break;
     }
+    else if (p->users[i][0] == '#')
+    {
+     /*
+      * Check UUID...
+      */
+
+      if (cupsdCheckGroup(username, pw, p->users[i]))
+        break;
+    }
     else if (!strcasecmp(username, p->users[i]))
       break;
   }
@@ -8983,16 +10925,7 @@ validate_job(cupsd_client_t  *con,      /* I - Client connection */
   http_status_t                status;         /* Policy status */
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_attribute_t      *format;        /* Document-format attribute */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[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 */
+  cups_ptype_t         dtype;          /* Destination type (printer/class) */
   char                 super[MIME_MAX_SUPER],
                                        /* Supertype of file */
                        type[MIME_MAX_TYPE];
@@ -9027,7 +10960,8 @@ validate_job(cupsd_client_t  *con,       /* I - Client connection */
   if ((format = ippFindAttribute(con->request, "document-format",
                                  IPP_TAG_MIMETYPE)) != NULL)
   {
-    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
+    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]",
+               super, type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\"!"),
                      format->values[0].string.text);
@@ -9052,11 +10986,7 @@ validate_job(cupsd_client_t  *con,      /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if (cupsdValidateDest(host, resource, &dtype, &printer) == NULL)
+  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -9073,7 +11003,7 @@ validate_job(cupsd_client_t  *con,       /* I - Client connection */
 
   if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_http_error(con, status);
+    send_http_error(con, status, printer);
     return;
   }
 
@@ -9089,7 +11019,7 @@ validate_job(cupsd_client_t  *con,       /* I - Client connection */
  * 'validate_name()' - Make sure the printer name only contains valid chars.
  */
 
-static int                     /* O - 0 if name is no good, 1 if name is good */
+static int                     /* O - 0 if name is no good, 1 if good */
 validate_name(const char *name)        /* I - Name to check */
 {
   const char   *ptr;           /* Pointer into name */
@@ -9100,7 +11030,7 @@ validate_name(const char *name)  /* I - Name to check */
   */
 
   for (ptr = name; *ptr; ptr ++)
-    if ((*ptr >= 0 && *ptr <= ' ') || *ptr == 127 || *ptr == '/' || *ptr == '#')
+    if ((*ptr > 0 && *ptr <= ' ') || *ptr == 127 || *ptr == '/' || *ptr == '#')
       return (0);
 
  /*
@@ -9128,8 +11058,8 @@ validate_user(cupsd_job_t    *job,       /* I - Job */
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
                   "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
                  "userlen=%d)",
-                 job ? job->id : 0, con->http.fd, owner ? owner : "(null)",
-                 username, userlen);
+                 job->id, con ? con->http.fd : 0,
+                 owner ? owner : "(null)", username, userlen);
 
  /*
   * Validate input...
@@ -9156,5 +11086,5 @@ validate_user(cupsd_job_t    *job,       /* I - Job */
 
 
 /*
- * End of "$Id: ipp.c 5383 2006-04-07 15:36:10Z mike $".
+ * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".
  */