]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge changes from CUPS 1.7svn-r10578.
[thirdparty/cups.git] / scheduler / ipp.c
index d0011c03a7fd199f47aa5e3a59a04fd07dde56e3..4da385b4194083ed9ee2962338f3f6689ae50fde 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   IPP routines for the CUPS scheduler.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   This file contains Kerberos support code, copyright 2006 by
@@ -23,8 +23,6 @@
  *   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 subscriptions for a job.
  *   add_job_uuid()              - Add job-uuid attribute to a job.
  *   add_printer()               - Add a printer to the system.
  *                                 based upon the printer state...
  *   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 or selected print jobs.
@@ -45,7 +39,6 @@
  *                                 feed URI.
  *   check_quotas()              - Check quotas for a printer and user.
  *   close_job()                 - Close a multi-file job.
- *   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
  *                                 for the specified job.
 #include <cups/ppd-private.h>
 
 #ifdef __APPLE__
-#  include <ApplicationServices/ApplicationServices.h>
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+/*#  include <ApplicationServices/ApplicationServices.h>
 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-#  include <CoreFoundation/CoreFoundation.h>
+#  include <CoreFoundation/CoreFoundation.h>*/
 #  ifdef HAVE_MEMBERSHIP_H
 #    include <membership.h>
 #  endif /* HAVE_MEMBERSHIP_H */
@@ -142,25 +133,12 @@ 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, 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);
-static void    add_job_uuid(cupsd_client_t *con, cupsd_job_t *job);
+static void    add_job_uuid(cupsd_job_t *job);
 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,
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-                                   CFMutableDictionaryRef profile,
-#  else
-                                  CMDeviceProfileInfo *profile,
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-                                  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);
@@ -169,8 +147,6 @@ 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);
 static void    close_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    copy_attrs(ipp_t *to, ipp_t *from, cups_array_t *ra,
                           ipp_tag_t group, int quickcopy,
@@ -228,10 +204,7 @@ 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__
-__attribute__ ((__format__ (__printf__, 3, 4)))
-#    endif /* __GNUC__ */
-;
+               __attribute__((__format__(__printf__, 3, 4)));
 static void    set_default(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    set_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    set_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
@@ -412,8 +385,8 @@ cupsdProcessIPPRequest(
                      "attributes-natural-language", NULL, DefaultLanguage);
 
       if (charset &&
-          strcasecmp(charset->values[0].string.text, "us-ascii") &&
-          strcasecmp(charset->values[0].string.text, "utf-8"))
+          _cups_strcasecmp(charset->values[0].string.text, "us-ascii") &&
+          _cups_strcasecmp(charset->values[0].string.text, "utf-8"))
       {
        /*
         * Bad character set...
@@ -502,7 +475,7 @@ cupsdProcessIPPRequest(
          */
 
          if (!strcmp(username->values[0].string.text, "root") &&
-             strcasecmp(con->http.hostname, "localhost") &&
+             _cups_strcasecmp(con->http.hostname, "localhost") &&
              strcmp(con->username, "root"))
          {
           /*
@@ -853,8 +826,7 @@ cupsdTimeoutJob(cupsd_job_t *job)   /* I - Job to timeout */
   printer = cupsdFindDest(job->dest);
   attr    = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME);
 
-  if (printer &&
-      !(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
+  if (printer && !(printer->type & CUPS_PRINTER_REMOTE) &&
       attr && attr->num_values > 1)
   {
    /*
@@ -969,7 +941,6 @@ add_class(cupsd_client_t  *con,             /* I - Client connection */
   cups_ptype_t dtype;                  /* Destination type */
   ipp_attribute_t *attr;               /* Printer attribute */
   int          modify;                 /* Non-zero if we just modified */
-  char         newname[IPP_MAX_NAME];  /* New class name */
   int          need_restart_job;       /* Need to restart job? */
 
 
@@ -1023,8 +994,7 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
     * Class doesn't exist; see if we have a printer of the same name...
     */
 
-    if ((pclass = cupsdFindPrinter(resource + 9)) != NULL &&
-        !(pclass->type & CUPS_PRINTER_DISCOVERED))
+    if ((pclass = cupsdFindPrinter(resource + 9)) != NULL)
     {
      /*
       * Yes, return an error...
@@ -1049,56 +1019,6 @@ add_class(cupsd_client_t  *con,          /* I - Client connection */
     pclass = cupsdAddClass(resource + 9);
     modify = 0;
   }
-  else if (pclass->type & CUPS_PRINTER_IMPLICIT)
-  {
-   /*
-    * 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);
-      cupsdRenamePrinter(pclass, newname);
-    }
-    else
-      cupsdDeletePrinter(pclass, 1);
-
-   /*
-    * Add the class as a new local class...
-    */
-
-    pclass = cupsdAddClass(resource + 9);
-    modify = 0;
-  }
-  else if (pclass->type & CUPS_PRINTER_DISCOVERED)
-  {
-   /*
-    * 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);
-
-   /*
-    * Add the class as a new local class...
-    */
-
-    pclass = cupsdAddClass(resource + 9);
-    modify = 0;
-  }
   else if ((status = cupsdCheckPolicy(pclass->op_policy_ptr, con,
                                       NULL)) != HTTP_OK)
   {
@@ -1377,8 +1297,8 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
   */
 
   if (!printer->shared &&
-      strcasecmp(con->http.hostname, "localhost") &&
-      strcasecmp(con->http.hostname, ServerName))
+      _cups_strcasecmp(con->http.hostname, "localhost") &&
+      _cups_strcasecmp(con->http.hostname, ServerName))
   {
     send_ipp_status(con, IPP_NOT_AUTHORIZED,
                     _("The printer or class is not shared."));
@@ -1630,15 +1550,14 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
     return (NULL);
   }
 
-  job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
-                                  CUPS_PRINTER_REMOTE);
+  job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE);
   job->attrs   = con->request;
   job->dirty   = 1;
   con->request = ippNewRequest(job->attrs->request.op.operation_id);
 
   cupsdMarkDirty(CUPSD_DIRTY_JOBS);
 
-  add_job_uuid(con, job);
+  add_job_uuid(job);
   apply_printer_defaults(printer, job);
 
   attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
@@ -1720,10 +1639,10 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
            {
              _cupsStrFree(attr->values[i].string.text);
              attr->values[i].string.text = NULL;
-             if (attr->values[i].string.charset)
+             if (attr->values[i].string.language)
              {
-               _cupsStrFree(attr->values[i].string.charset);
-               attr->values[i].string.charset = NULL;
+               _cupsStrFree(attr->values[i].string.language);
+               attr->values[i].string.language = NULL;
              }
             }
 
@@ -1770,6 +1689,8 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
   job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
                              "job-state", IPP_JOB_STOPPED);
   job->state_value = (ipp_jstate_t)job->state->values[0].integer;
+  job->reasons = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                              "job-state-reasons", NULL, "job-incoming");
   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,
@@ -1803,6 +1724,8 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
 
     job->state->values[0].integer = IPP_JOB_HELD;
     job->state_value              = IPP_JOB_HELD;
+
+    ippSetString(job->attrs, &job->reasons, 0, "job-hold-until-specified");
   }
   else if (job->attrs->request.op.operation_id == IPP_CREATE_JOB)
   {
@@ -1814,10 +1737,11 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   {
     job->state->values[0].integer = IPP_JOB_PENDING;
     job->state_value              = IPP_JOB_PENDING;
+
+    ippSetString(job->attrs, &job->reasons, 0, "none");
   }
 
-  if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
-      Classification)
+  if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification)
   {
    /*
     * Add job sheets options...
@@ -1950,7 +1874,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
     * See if we need to add the starting sheet...
     */
 
-    if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
+    if (!(printer->type & CUPS_PRINTER_REMOTE))
     {
       cupsdLogJob(job, CUPSD_LOG_INFO, "Adding start banner page \"%s\".",
                  attr->values[0].string.text);
@@ -1974,9 +1898,8 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
   * Fill in the response info...
   */
 
-  snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
-          LocalPort, job->id);
-
+  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                   con->servername, con->serverport, "/jobs/%d", job->id);
   ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
                job_uri);
 
@@ -1984,7 +1907,8 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
 
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
                 job->state_value);
-  add_job_state_reasons(con, job);
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons",
+               NULL, job->reasons->values[0].string.text);
 
   con->response->request.status.status_code = IPP_OK;
 
@@ -2015,75 +1939,6 @@ add_job(cupsd_client_t  *con,            /* I - Client connection */
 }
 
 
-/*
- * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
- *                             upon the job and printer state...
- */
-
-static void
-add_job_state_reasons(
-    cupsd_client_t *con,               /* I - Client connection */
-    cupsd_job_t    *job)               /* I - Job info */
-{
-  cupsd_printer_t      *dest;          /* Destination printer */
-
-
-  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_CANCELED)
-  {
-    case IPP_JOB_PENDING :
-       dest = cupsdFindDest(job->dest);
-
-        if (dest && dest->state == IPP_PRINTER_STOPPED)
-          ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                      "job-state-reasons", NULL, "printer-stopped");
-        else
-          ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                      "job-state-reasons", NULL, "none");
-        break;
-
-    case IPP_JOB_HELD :
-        if (ippFindAttribute(job->attrs, "job-hold-until",
-                            IPP_TAG_KEYWORD) != NULL ||
-           ippFindAttribute(job->attrs, "job-hold-until",
-                            IPP_TAG_NAME) != NULL)
-          ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                      "job-state-reasons", NULL, "job-hold-until-specified");
-        else
-          ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                      "job-state-reasons", NULL, "job-incoming");
-        break;
-
-    case IPP_JOB_PROCESSING :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-printing");
-        break;
-
-    case IPP_JOB_STOPPED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-stopped");
-        break;
-
-    case IPP_JOB_CANCELED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-canceled-by-user");
-        break;
-
-    case IPP_JOB_ABORTED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "aborted-by-system");
-        break;
-
-    case IPP_JOB_COMPLETED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-completed-successfully");
-        break;
-  }
-}
-
-
 /*
  * 'add_job_subscriptions()' - Add any subscriptions for a job.
  */
@@ -2302,7 +2157,7 @@ add_job_subscriptions(
       * Free and remove this attribute...
       */
 
-      _ippFreeAttr(attr);
+      ippDeleteAttribute(NULL, attr);
 
       if (prev)
         prev->next = next;
@@ -2325,8 +2180,7 @@ add_job_subscriptions(
  */
 
 static void
-add_job_uuid(cupsd_client_t *con,      /* I - Client connection */
-             cupsd_job_t    *job)      /* I - Job */
+add_job_uuid(cupsd_job_t *job)         /* I - Job */
 {
   char                 uuid[64];       /* job-uuid string */
 
@@ -2364,7 +2218,6 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
   char         srcfile[1024],          /* Source Script/PPD file */
                dstfile[1024];          /* Destination Script/PPD file */
   int          modify;                 /* Non-zero if we are modifying */
-  char         newname[IPP_MAX_NAME];  /* New printer name */
   int          changed_driver,         /* Changed the PPD/interface script? */
                need_restart_job,       /* Need to restart job? */
                set_device_uri,         /* Did we set the device URI? */
@@ -2420,8 +2273,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
     * Printer doesn't exist; see if we have a class of the same name...
     */
 
-    if ((printer = cupsdFindClass(resource + 10)) != NULL &&
-        !(printer->type & CUPS_PRINTER_DISCOVERED))
+    if ((printer = cupsdFindClass(resource + 10)) != NULL)
     {
      /*
       * Yes, return an error...
@@ -2446,58 +2298,6 @@ add_printer(cupsd_client_t  *con,        /* I - Client connection */
     printer = cupsdAddPrinter(resource + 10);
     modify  = 0;
   }
-  else if (printer->type & CUPS_PRINTER_IMPLICIT)
-  {
-   /*
-    * 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);
-      cupsdRenamePrinter(printer, newname);
-    }
-    else
-      cupsdDeletePrinter(printer, 1);
-
-   /*
-    * Add the printer as a new local printer...
-    */
-
-    printer = cupsdAddPrinter(resource + 10);
-    modify  = 0;
-  }
-  else if (printer->type & CUPS_PRINTER_DISCOVERED)
-  {
-   /*
-    * Check the default policy, then rename the remote printer to
-    * "Printer@server"...
-    */
-
-    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);
-
-   /*
-    * Add the printer as a new local printer...
-    */
-
-    printer = cupsdAddPrinter(resource + 10);
-    modify  = 0;
-  }
   else if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
                                       NULL)) != HTTP_OK)
   {
@@ -2926,17 +2726,11 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
 
     cupsdSetPrinterReasons(printer, "none");
 
-#ifdef __APPLE__
    /*
     * (Re)register color profiles...
     */
 
-    if (!RunUser)
-    {
-      apple_unregister_profiles(printer);
-      apple_register_profiles(printer);
-    }
-#endif /* __APPLE__ */
+    cupsdRegisterColor(printer);
   }
 
  /*
@@ -2956,7 +2750,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
 
     snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot,
             printer->name);
-    if ((ppd = ppdOpenFile(srcfile)) != NULL)
+    if ((ppd = _ppdOpenFile(srcfile, _PPD_LOCALIZATION_NONE)) != NULL)
     {
       for (ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
           ppdattr;
@@ -3003,936 +2797,71 @@ add_printer(cupsd_client_t  *con,      /* I - Client connection */
   if (modify)
   {
     cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED,
-                  printer, NULL, "Printer \"%s\" modified by \"%s\".",
-                 printer->name, get_username(con));
-
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".",
-                    printer->name, get_username(con));
-  }
-  else
-  {
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED,
-                  printer, NULL, "New printer \"%s\" added by \"%s\".",
-                 printer->name, get_username(con));
-
-    cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".",
-                    printer->name, get_username(con));
-  }
-
-  con->response->request.status.status_code = IPP_OK;
-}
-
-
-/*
- * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
- *                                 based upon the printer state...
- */
-
-static void
-add_printer_state_reasons(
-    cupsd_client_t  *con,              /* I - Client connection */
-    cupsd_printer_t *p)                        /* I - Printer info */
-{
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "add_printer_state_reasons(%p[%d], %p[%s])",
-                  con, con->http.fd, p, p->name);
-
-  if (p->num_reasons == 0)
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                 "printer-state-reasons", NULL, "none");
-  else
-    ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                  "printer-state-reasons", p->num_reasons, NULL,
-                 (const char * const *)p->reasons);
-}
-
-
-/*
- * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
- *                            the specified printer or class.
- */
-
-static void
-add_queued_job_count(
-    cupsd_client_t  *con,              /* I - Client connection */
-    cupsd_printer_t *p)                        /* I - Printer or class */
-{
-  int          count;                  /* Number of jobs on destination */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])",
-                  con, con->http.fd, p, p->name);
-
-  count = cupsdGetPrinterJobCount(p->name);
-
-  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                "queued-job-count", 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 */
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-    CFMutableDictionaryRef profile,    /* I - Profile dictionary */
-#  else
-    CMDeviceProfileInfo    *profile,   /* I - Profile record */
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-    unsigned               id,         /* I - Profile ID */
-    const char             *name,      /* I - Profile name */
-    const char             *text,      /* I - Profile UI text */
-    const char             *iccfile)   /* I - ICC filename */
-{
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-  CFURLRef             url;            /* URL for profile filename */
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-  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_US"), 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...
-  */
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
- if (iccfile)
- {
-    url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
-                                                 (const UInt8 *)iccfile,
-                                                  strlen(iccfile), false);
-
-    if (url)
-    {
-      CFDictionarySetValue(profile, kColorSyncDeviceProfileURL, url);
-      CFRelease(url);
-    }
-  }
-
-  CFDictionarySetValue(profile, kColorSyncDeviceModeDescriptions, dict);
-  CFRelease(dict);
-
-#  else
-  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));
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-}
-
-
-/*
- * '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 */
-  OSStatus             error = 0;      /* 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 */
-  cups_array_t         *languages;     /* Languages array */
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-  CFMutableDictionaryRef profiles,     /* Dictionary of profiles */
-                       profile;        /* Current profile info dictionary */
-  CFStringRef          dict_key;       /* Key in factory profile dictionary */
-#  else
-  CMDeviceScope                scope =         /* Scope of the registration */
-                       {
-                         kCFPreferencesAnyUser,
-                         kCFPreferencesCurrentHost
-                       };
-  CMDeviceProfileArrayPtr profiles;    /* Profiles */
-  CMDeviceProfileInfo  *profile;       /* Current profile */
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
-
- /*
-  * Make sure ColorSync is available...
-  */
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-  if (ColorSyncRegisterDevice == NULL)
-    return;
-
-#  else
-  if (CMRegisterColorDevice == NULL)
-    return;
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
- /*
-  * 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 ++;
-    }
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
- /*
-  * Create a dictionary for the factory profiles...
-  */
-
-  profiles = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
-                                      &kCFTypeDictionaryKeyCallBacks,
-                                      &kCFTypeDictionaryValueCallBacks);
-  if (!profiles)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                   "Unable to allocate memory for factory profiles.");
-    ppdClose(ppd);
-    return;
-  }
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
- /*
-  * 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;
-    }
-
-#  ifndef HAVE_COLORSYNCREGISTERDEVICE
-   /*
-    * 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 factory profiles.");
-      ppdClose(ppd);
-      return;
-    }
-
-    profiles->profileCount = num_profiles;
-    profile = profiles->profiles;
-#  endif /* !HAVE_COLORSYNCREGISTERDEVICE */
-
-   /*
-    * Loop through the profiles listed in the PPD...
-    */
-
-    languages = _ppdGetLanguages(ppd);
-
-    for (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);
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-       profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
-                                           &kCFTypeDictionaryKeyCallBacks,
-                                           &kCFTypeDictionaryValueCallBacks);
-       if (!profile)
-       {
-         cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Unable to allocate memory for color profile.");
-         CFRelease(profiles);
-         ppdClose(ppd);
-         return;
-       }
-
-       apple_init_profile(ppd, languages, profile, profile_id, attr->spec,
-                          attr->text[0] ? attr->text : attr->spec, iccfile);
-
-       dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
-                                           CFSTR("%u"), profile_id);
-       if (dict_key)
-       {
-         CFDictionarySetValue(profiles, dict_key, profile);
-         CFRelease(dict_key);
-       }
-
-       CFRelease(profile);
-
-#  else
-        apple_init_profile(ppd, languages, profile, profile_id, attr->spec,
-                          attr->text[0] ? attr->text : attr->spec, iccfile);
-
-       profile ++;
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
-       /*
-        * See if this is the default profile...
-       */
-
-        if (!default_profile_id && q1_choice && q2_choice && 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 && q1_choice && q2_choice)
-       {
-         snprintf(selector, sizeof(selector), "%s.%s.", q1_choice, q2_choice);
-         if (!strcmp(selector, attr->spec))
-           default_profile_id = profile_id;
-       }
-
-        if (!default_profile_id && q1_choice && 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 && q1_choice)
-       {
-         snprintf(selector, sizeof(selector), "%s..", q1_choice);
-         if (!strcmp(selector, attr->spec))
-           default_profile_id = profile_id;
-       }
-
-        if (!default_profile_id && q2_choice && q3_choice)
-       {
-         snprintf(selector, sizeof(selector), ".%s.%s", q2_choice, q3_choice);
-         if (!strcmp(selector, attr->spec))
-           default_profile_id = profile_id;
-       }
-
-        if (!default_profile_id && q2_choice)
-       {
-         snprintf(selector, sizeof(selector), ".%s.", q2_choice);
-         if (!strcmp(selector, attr->spec))
-           default_profile_id = profile_id;
-       }
-
-        if (!default_profile_id && q3_choice)
-       {
-         snprintf(selector, sizeof(selector), "..%s", q3_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;
-
-#  ifndef HAVE_COLORSYNCREGISTERDEVICE
-   /*
-    * Create an array for the factory profiles...
-    */
-
-    if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for factory profiles.");
-      ppdClose(ppd);
-      return;
-    }
-
-    profiles->profileCount = num_profiles;
-    profile = profiles->profiles;
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
-    for (i = cm_option->num_choices, cm_choice = cm_option->choices;
-         i > 0;
-        i --, cm_choice ++)
-    {
-      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);
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-      profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
-                                         &kCFTypeDictionaryKeyCallBacks,
-                                         &kCFTypeDictionaryValueCallBacks);
-      if (!profile)
-      {
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to allocate memory for color profile.");
-       CFRelease(profiles);
-       ppdClose(ppd);
-       return;
-      }
-
-      apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice,
-                         cm_choice->text, NULL);
-
-      dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
-                                          CFSTR("%u"), profile_id);
-      if (dict_key)
-      {
-       CFDictionarySetValue(profiles, dict_key, profile);
-       CFRelease(dict_key);
-      }
-
-      CFRelease(profile);
-
-#  else
-      apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice,
-                         cm_choice->text, NULL);
-      profile ++;
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
-      if (cm_choice->marked)
-        default_profile_id = profile_id;
-    }
-  }
-  else
-  {
-   /*
-    * Use the default colorspace...
-    */
-
-    attr = ppdFindAttr(ppd, "DefaultColorSpace", NULL);
-
-    num_profiles = (attr && ppd->colorspace == PPD_CS_GRAY) ? 1 : 2;
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-   /*
-    * Add the grayscale profile first.  We always have a grayscale profile.
-    */
-
-    profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
-                                       &kCFTypeDictionaryKeyCallBacks,
-                                       &kCFTypeDictionaryValueCallBacks);
-
-    if (!profile)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for color profile.");
-      CFRelease(profiles);
-      ppdClose(ppd);
-      return;
-    }
-
-    profile_id = _ppdHashName("Gray..");
-    apple_init_profile(ppd, NULL, profile, profile_id, "Gray", "Gray", NULL);
-
-    dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"),
-                                        profile_id);
-    if (dict_key)
-    {
-      CFDictionarySetValue(profiles, dict_key, profile);
-      CFRelease(dict_key);
-    }
-
-    CFRelease(profile);
-
-   /*
-    * Then add the RGB/CMYK/DeviceN color profile...
-    */
-
-    profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
-                                       &kCFTypeDictionaryKeyCallBacks,
-                                       &kCFTypeDictionaryValueCallBacks);
-
-    if (!profile)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for color profile.");
-      CFRelease(profiles);
-      ppdClose(ppd);
-      return;
-    }
-
-    switch (ppd->colorspace)
-    {
-      case PPD_CS_RGB :
-      case PPD_CS_CMY :
-          profile_id = _ppdHashName("RGB..");
-          apple_init_profile(ppd, NULL, profile, profile_id, "RGB", "RGB",
-                            NULL);
-          break;
-      case PPD_CS_RGBK :
-      case PPD_CS_CMYK :
-          profile_id = _ppdHashName("CMYK..");
-          apple_init_profile(ppd, NULL, profile, profile_id, "CMYK", "CMYK",
-                            NULL);
-          break;
-
-      case PPD_CS_GRAY :
-          if (attr)
-            break;
-
-      case PPD_CS_N :
-          profile_id = _ppdHashName("DeviceN..");
-          apple_init_profile(ppd, NULL, profile, profile_id, "DeviceN",
-                            "DeviceN", NULL);
-          break;
-    }
-
-    if (CFDictionaryGetCount(profile) > 0)
-    {
-      dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
-                                          CFSTR("%u"), profile_id);
-      if (dict_key)
-      {
-        CFDictionarySetValue(profiles, dict_key, profile);
-        CFRelease(dict_key);
-      }
-    }
-
-    CFRelease(profile);
-
-#  else
-   /*
-    * Create an array for the factory profiles...
-    */
-
-    if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for factory profiles.");
-      ppdClose(ppd);
-      return;
-    }
-
-    profiles->profileCount = num_profiles;
-
-   /*
-    * Add the grayscale profile first.  We always have a grayscale profile.
-    */
-
-    profile_id = _ppdHashName("Gray..");
-    apple_init_profile(ppd, NULL, profiles->profiles, profile_id, "Gray",
-                       "Gray", NULL);
-
-   /*
-    * Then add the RGB/CMYK/DeviceN color profile...
-    */
-
-    switch (ppd->colorspace)
-    {
-      case PPD_CS_RGB :
-      case PPD_CS_CMY :
-          profile_id = _ppdHashName("RGB..");
-          apple_init_profile(ppd, NULL, profiles->profiles + 1, profile_id,
-                            "RGB", "RGB", NULL);
-          break;
-      case PPD_CS_RGBK :
-      case PPD_CS_CMYK :
-          profile_id = _ppdHashName("CMYK..");
-          apple_init_profile(ppd, NULL, profiles->profiles + 1, profile_id,
-                            "CMYK", "CMYK", NULL);
-          break;
-
-      case PPD_CS_GRAY :
-          if (attr)
-           break;
-
-      case PPD_CS_N :
-          profile_id = _ppdHashName("DeviceN..");
-          apple_init_profile(ppd, NULL, profiles->profiles + 1, profile_id,
-                            "DeviceN", "DeviceN", NULL);
-          break;
-    }
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-  }
-
-  if (num_profiles > 0)
-  {
-   /*
-    * Make sure we have a default profile ID...
-    */
-
-    if (!default_profile_id)
-      default_profile_id = profile_id; /* Last profile */
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-    dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"),
-                                        default_profile_id);
-    if (dict_key)
-    {
-      CFDictionarySetValue(profiles, kColorSyncDeviceDefaultProfileID,
-                           dict_key);
-      CFRelease(dict_key);
-    }
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-
-   /*
-    * 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_US"), printer_name);
-
-     /*
-      * Register the device with ColorSync...
-      */
-
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-      CFTypeRef                deviceDictKeys[] =
-      {                                        /* Device keys */
-        kColorSyncDeviceDescriptions,
-       kColorSyncFactoryProfiles,
-       kColorSyncDeviceUserScope,
-       kColorSyncDeviceHostScope
-      };
-      CFTypeRef        deviceDictVals[] =
-      {                                        /* Device values */
-        device_name,
-       profiles,
-       kCFPreferencesAnyUser,
-       kCFPreferencesCurrentHost
-      };
-      CFDictionaryRef  deviceDict;     /* Device dictionary */
-      CFUUIDRef                deviceUUID;     /* Device UUID */
-
-      deviceDict = CFDictionaryCreate(kCFAllocatorDefault,
-                                     (const void **)deviceDictKeys,
-                                     (const void **)deviceDictVals,
-                                     sizeof(deviceDictKeys) /
-                                         sizeof(deviceDictKeys[0]),
-                                     &kCFTypeDictionaryKeyCallBacks,
-                                     &kCFTypeDictionaryValueCallBacks);
-      deviceUUID = ColorSyncCreateUUIDFromUInt32(device_id);
-
-      if (!deviceDict || !deviceUUID ||
-         !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass, deviceUUID,
-                                  deviceDict))
-       error = 1001;
-
-      if (deviceUUID)
-        CFRelease(deviceUUID);
-
-      if (deviceDict)
-        CFRelease(deviceDict);
-
-#  else
-      error = CMRegisterColorDevice(cmPrinterDeviceClass, device_id,
-                                    device_name, &scope);
-
-     /*
-      * Register the profiles...
-      */
-
-      if (error == noErr)
-       error = CMSetDeviceFactoryProfiles(cmPrinterDeviceClass, device_id,
-                                          default_profile_id, profiles);
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
-    }
-    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);
+                  printer, NULL, "Printer \"%s\" modified by \"%s\".",
+                 printer->name, get_username(con));
 
-    if (printer_name)
-      CFRelease(printer_name);
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".",
+                    printer->name, get_username(con));
+  }
+  else
+  {
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED,
+                  printer, NULL, "New printer \"%s\" added by \"%s\".",
+                 printer->name, get_username(con));
 
-    if (device_name)
-      CFRelease(device_name);
+    cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".",
+                    printer->name, get_username(con));
   }
 
- /*
-  * Free any memory we used...
-  */
+  con->response->request.status.status_code = IPP_OK;
+}
 
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-  CFRelease(profiles);
 
-#  else
-  if (num_profiles > 0)
-  {
-    for (profile = profiles->profiles;
-        num_profiles > 0;
-        profile ++, num_profiles --)
-      CFRelease(profile->profileName);
+/*
+ * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
+ *                                 based upon the printer state...
+ */
 
-    free(profiles);
-  }
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
+static void
+add_printer_state_reasons(
+    cupsd_client_t  *con,              /* I - Client connection */
+    cupsd_printer_t *p)                        /* I - Printer info */
+{
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "add_printer_state_reasons(%p[%d], %p[%s])",
+                  con, con->http.fd, p, p->name);
 
-  ppdClose(ppd);
+  if (p->num_reasons == 0)
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                 "printer-state-reasons", NULL, "none");
+  else
+    ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                  "printer-state-reasons", p->num_reasons, NULL,
+                 (const char * const *)p->reasons);
 }
 
 
 /*
- * 'apple_unregister_profiles()' - Remove color profiles for the specified
- *                                 printer.
+ * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
+ *                            the specified printer or class.
  */
 
 static void
-apple_unregister_profiles(
-    cupsd_printer_t *p)                        /* I - Printer */
+add_queued_job_count(
+    cupsd_client_t  *con,              /* I - Client connection */
+    cupsd_printer_t *p)                        /* I - Printer or class */
 {
- /*
-  * Make sure ColorSync is available...
-  */
+  int          count;                  /* Number of jobs on destination */
 
-#  ifdef HAVE_COLORSYNCREGISTERDEVICE
-  if (ColorSyncUnregisterDevice != NULL)
-  {
-   /*
-    * Because we may have registered the printer profiles using a prior device
-    * ID-based UUID, remove both the old style UUID and current UUID for the
-    * printer.
-    */
 
-    CFUUIDRef deviceUUID;              /* Device UUID */
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])",
+                  con, con->http.fd, p, p->name);
 
-    deviceUUID = ColorSyncCreateUUIDFromUInt32(_ppdHashName(p->name));
-    if (deviceUUID)
-    {
-      ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass, deviceUUID);
-      CFRelease(deviceUUID);
-    }
-  }
+  count = cupsdGetPrinterJobCount(p->name);
 
-#  else
-  if (CMUnregisterColorDevice != NULL)
-    CMUnregisterColorDevice(cmPrinterDeviceClass, _ppdHashName(p->name));
-#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
+  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+                "queued-job-count", count);
 }
-#endif /* __APPLE__ */
 
 
 /*
@@ -4090,7 +3019,6 @@ authenticate_job(cupsd_client_t  *con,    /* I - Client connection */
   {
     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...
@@ -4340,7 +3268,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
       for (i = 0; i < job_ids->num_values; i ++)
       {
        if ((job = cupsdFindJob(job_ids->values[i].integer)) == NULL ||
-           strcasecmp(job->dest, printer->name))
+           _cups_strcasecmp(job->dest, printer->name))
          break;
       }
 
@@ -4450,7 +3378,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
           job;
           job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
        if (job->state_value <= IPP_JOB_PROCESSING &&
-           !strcasecmp(job->dest, printer->name))
+           !_cups_strcasecmp(job->dest, printer->name))
          break;
 
       if (job)
@@ -4465,7 +3393,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
             job;
             job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
          if (job->state_value == IPP_JOB_STOPPED &&
-             !strcasecmp(job->dest, printer->name))
+             !_cups_strcasecmp(job->dest, printer->name))
            break;
 
        if (job)
@@ -4719,6 +3647,9 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
 
   strlcpy(username, get_username(con), sizeof(username));
 
+  if ((name = strchr(username, '@')) != NULL)
+    *name = '\0';                      /* Strip @REALM */
+
  /*
   * Check global active job limits for printers and users...
   */
@@ -4871,7 +3802,7 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
          break;
       }
 #else
-      else if (!strcasecmp(username, name))
+      else if (!_cups_strcasecmp(username, name))
        break;
 #endif /* HAVE_MBR_UID_TO_UUID */
 
@@ -5014,8 +3945,8 @@ close_job(cupsd_client_t  *con,           /* I - Client connection */
   * Fill in the response info...
   */
 
-  snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
-          LocalPort, job->id);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                   con->servername, con->serverport, "/jobs/%d", job->id);
   ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
                job_uri);
 
@@ -5024,8 +3955,6 @@ close_job(cupsd_client_t  *con,           /* I - Client connection */
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
                 job->state_value);
 
-  add_job_state_reasons(con, job);
-
   con->response->request.status.status_code = IPP_OK;
 
  /*
@@ -5036,192 +3965,6 @@ close_job(cupsd_client_t  *con,         /* I - Client connection */
 }
 
 
-/*
- * 'copy_attribute()' - Copy a single attribute.
- */
-
-static ipp_attribute_t *               /* O - New attribute */
-copy_attribute(
-    ipp_t           *to,               /* O - Destination request/response */
-    ipp_attribute_t *attr,             /* I - Attribute to copy */
-    int             quickcopy)         /* I - Do a quick copy? */
-{
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *toattr;        /* Destination attribute */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "copy_attribute(%p, %p[%s,%x,%x])", to, attr,
-                 attr->name ? attr->name : "(null)", attr->group_tag,
-                 attr->value_tag);
-
-  switch (attr->value_tag & ~IPP_TAG_COPY)
-  {
-    case IPP_TAG_ZERO :
-        toattr = ippAddSeparator(to);
-       break;
-
-    case IPP_TAG_INTEGER :
-    case IPP_TAG_ENUM :
-        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,
-                               attr->name, attr->num_values, NULL);
-
-        for (i = 0; i < attr->num_values; i ++)
-         toattr->values[i].integer = attr->values[i].integer;
-        break;
-
-    case IPP_TAG_BOOLEAN :
-        toattr = ippAddBooleans(to, attr->group_tag, attr->name,
-                               attr->num_values, NULL);
-
-        for (i = 0; i < attr->num_values; i ++)
-         toattr->values[i].boolean = attr->values[i].boolean;
-        break;
-
-    case IPP_TAG_STRING :
-    case IPP_TAG_TEXT :
-    case IPP_TAG_NAME :
-    case IPP_TAG_KEYWORD :
-    case IPP_TAG_URI :
-    case IPP_TAG_URISCHEME :
-    case IPP_TAG_CHARSET :
-    case IPP_TAG_LANGUAGE :
-    case IPP_TAG_MIMETYPE :
-        toattr = ippAddStrings(to, attr->group_tag,
-                              (ipp_tag_t)(attr->value_tag | quickcopy),
-                              attr->name, attr->num_values, NULL, NULL);
-
-        if (quickcopy)
-       {
-          for (i = 0; i < attr->num_values; i ++)
-           toattr->values[i].string.text = attr->values[i].string.text;
-        }
-       else if (attr->value_tag & IPP_TAG_COPY)
-       {
-          for (i = 0; i < attr->num_values; i ++)
-           toattr->values[i].string.text =
-               _cupsStrAlloc(attr->values[i].string.text);
-       }
-       else
-       {
-          for (i = 0; i < attr->num_values; i ++)
-           toattr->values[i].string.text =
-               _cupsStrRetain(attr->values[i].string.text);
-       }
-        break;
-
-    case IPP_TAG_DATE :
-        toattr = ippAddDate(to, attr->group_tag, attr->name,
-                           attr->values[0].date);
-        break;
-
-    case IPP_TAG_RESOLUTION :
-        toattr = ippAddResolutions(to, attr->group_tag, attr->name,
-                                  attr->num_values, IPP_RES_PER_INCH,
-                                  NULL, NULL);
-
-        for (i = 0; i < attr->num_values; i ++)
-       {
-         toattr->values[i].resolution.xres  = attr->values[i].resolution.xres;
-         toattr->values[i].resolution.yres  = attr->values[i].resolution.yres;
-         toattr->values[i].resolution.units = attr->values[i].resolution.units;
-       }
-        break;
-
-    case IPP_TAG_RANGE :
-        toattr = ippAddRanges(to, attr->group_tag, attr->name,
-                             attr->num_values, NULL, NULL);
-
-        for (i = 0; i < attr->num_values; i ++)
-       {
-         toattr->values[i].range.lower = attr->values[i].range.lower;
-         toattr->values[i].range.upper = attr->values[i].range.upper;
-       }
-        break;
-
-    case IPP_TAG_TEXTLANG :
-    case IPP_TAG_NAMELANG :
-        toattr = ippAddStrings(to, attr->group_tag,
-                              (ipp_tag_t)(attr->value_tag | quickcopy),
-                              attr->name, attr->num_values, NULL, NULL);
-
-        if (quickcopy)
-       {
-          for (i = 0; i < attr->num_values; i ++)
-         {
-            toattr->values[i].string.charset = attr->values[i].string.charset;
-           toattr->values[i].string.text    = attr->values[i].string.text;
-          }
-        }
-       else if (attr->value_tag & IPP_TAG_COPY)
-       {
-          for (i = 0; i < attr->num_values; i ++)
-         {
-           if (!i)
-              toattr->values[i].string.charset =
-                 _cupsStrAlloc(attr->values[i].string.charset);
-           else
-              toattr->values[i].string.charset =
-                 toattr->values[0].string.charset;
-
-           toattr->values[i].string.text =
-               _cupsStrAlloc(attr->values[i].string.text);
-          }
-        }
-       else
-       {
-          for (i = 0; i < attr->num_values; i ++)
-         {
-           if (!i)
-              toattr->values[i].string.charset =
-                 _cupsStrRetain(attr->values[i].string.charset);
-           else
-              toattr->values[i].string.charset =
-                 toattr->values[0].string.charset;
-
-           toattr->values[i].string.text =
-               _cupsStrRetain(attr->values[i].string.text);
-          }
-        }
-        break;
-
-    case IPP_TAG_BEGIN_COLLECTION :
-        toattr = ippAddCollections(to, attr->group_tag, attr->name,
-                                  attr->num_values, NULL);
-
-        for (i = 0; i < attr->num_values; i ++)
-       {
-         toattr->values[i].collection = attr->values[i].collection;
-         attr->values[i].collection->use ++;
-       }
-        break;
-
-    default :
-        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,
-                               attr->name, attr->num_values, NULL);
-
-        for (i = 0; i < attr->num_values; i ++)
-       {
-         toattr->values[i].unknown.length = attr->values[i].unknown.length;
-
-         if (toattr->values[i].unknown.length > 0)
-         {
-           if ((toattr->values[i].unknown.data =
-                    malloc(toattr->values[i].unknown.length)) == NULL)
-             toattr->values[i].unknown.length = 0;
-           else
-             memcpy(toattr->values[i].unknown.data,
-                    attr->values[i].unknown.data,
-                    toattr->values[i].unknown.length);
-         }
-       }
-        break; /* anti-compiler-warning-code */
-  }
-
-  return (toattr);
-}
-
-
 /*
  * 'copy_attrs()' - Copy attributes from one request to another.
  */
@@ -5254,20 +3997,24 @@ copy_attrs(ipp_t        *to,            /* I - Destination request */
          fromattr->group_tag != IPP_TAG_ZERO) || !fromattr->name)
       continue;
 
+    if (!strcmp(fromattr->name, "job-printer-uri"))
+      continue;
+
     if (exclude &&
         (cupsArrayFind(exclude, fromattr->name) ||
         cupsArrayFind(exclude, "all")))
     {
      /*
       * We need to exclude this attribute for security reasons; we require the
-      * job-id and job-printer-uri attributes regardless of the security
-      * settings for IPP conformance.
+      * job-id attribute regardless of the security settings for IPP
+      * conformance.
+      *
+      * The job-printer-uri attribute is handled by copy_job_attrs().
       *
       * Subscription attribute security is handled by copy_subscription_attrs().
       */
 
-      if (strcmp(fromattr->name, "job-id") &&
-         strcmp(fromattr->name, "job-printer-uri"))
+      if (strcmp(fromattr->name, "job-id"))
         continue;
     }
 
@@ -5285,7 +4032,7 @@ copy_attrs(ipp_t        *to,              /* I - Destination request */
           !strcmp(fromattr->name, "media-col-database")))
        continue;
 
-      copy_attribute(to, fromattr, quickcopy);
+      ippCopyAttribute(to, fromattr, quickcopy);
     }
   }
 }
@@ -5506,7 +4253,7 @@ copy_banner(cupsd_client_t *con,  /* I - Client connection */
              cupsFilePrintf(out, "%dx%d%s", attr->values[i].resolution.xres,
                      attr->values[i].resolution.yres,
                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
-                         "dpi" : "dpc");
+                         "dpi" : "dpcm");
              break;
 
          case IPP_TAG_URI :
@@ -5516,7 +4263,7 @@ copy_banner(cupsd_client_t *con,  /* I - Client connection */
          case IPP_TAG_KEYWORD :
          case IPP_TAG_CHARSET :
          case IPP_TAG_LANGUAGE :
-             if (!strcasecmp(banner->filetype->type, "postscript"))
+             if (!_cups_strcasecmp(banner->filetype->type, "postscript"))
              {
               /*
                * Need to quote strings for PS banners...
@@ -5676,11 +4423,9 @@ copy_model(cupsd_client_t *con,          /* I - Client connection */
   snprintf(buffer, sizeof(buffer), "%s/daemon/cups-driverd", ServerBin);
   snprintf(tempfile, sizeof(tempfile), "%s/%d.ppd", TempDir, con->http.fd);
   tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600);
-  if (tempfd < 0)
+  if (tempfd < 0 || cupsdOpenPipe(temppipe))
     return (-1);
 
-  cupsdOpenPipe(temppipe);
-
   cupsdLogMessage(CUPSD_LOG_DEBUG,
                   "copy_model: Running \"cups-driverd cat %s\"...", from);
 
@@ -5770,12 +4515,23 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
     return (-1);
   }
 
+ /*
+  * Open the source file for a copy...
+  */
+
+  if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
+  {
+    unlink(tempfile);
+    return (-1);
+  }
+
  /*
   * Read the source file and see what page sizes are supported...
   */
 
-  if ((ppd = ppdOpenFile(tempfile)) == NULL)
+  if ((ppd = _ppdOpen(src, _PPD_LOCALIZATION_NONE)) == NULL)
   {
+    cupsFileClose(src);
     unlink(tempfile);
     return (-1);
   }
@@ -5842,17 +4598,6 @@ copy_model(cupsd_client_t *con,          /* I - Client connection */
 
   ppdClose(ppd);
 
- /*
-  * Open the source file for a copy...
-  */
-
-  if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
-  {
-    cupsFreeOptions(num_defaults, defaults);
-    unlink(tempfile);
-    return (-1);
-  }
-
  /*
   * Open the destination file for a copy...
   */
@@ -5869,6 +4614,8 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
   * Copy the source file to the destination...
   */
 
+  cupsFileRewind(src);
+
   while (cupsFileGets(src, buffer, sizeof(buffer)))
   {
     if (!strncmp(buffer, "*Default", 8))
@@ -5931,16 +4678,12 @@ copy_job_attrs(cupsd_client_t *con,     /* I - Client connection */
   * Send the requested attributes for each job...
   */
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
-                   con->servername, con->serverport, "/jobs/%d",
-                  job->id);
-
   if (!cupsArrayFind(exclude, "all"))
   {
-    if ((!exclude || !cupsArrayFind(exclude, "document-count")) &&
-        (!ra || cupsArrayFind(ra, "document-count")))
+    if ((!exclude || !cupsArrayFind(exclude, "number-of-documents")) &&
+        (!ra || cupsArrayFind(ra, "number-of-documents")))
       ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                   "document-count", job->num_files);
+                   "number-of-documents", job->num_files);
 
     if ((!exclude || !cupsArrayFind(exclude, "job-media-progress")) &&
         (!ra || cupsArrayFind(ra, "job-media-progress")))
@@ -5949,8 +4692,13 @@ copy_job_attrs(cupsd_client_t *con,      /* I - Client connection */
 
     if ((!exclude || !cupsArrayFind(exclude, "job-more-info")) &&
         (!ra || cupsArrayFind(ra, "job-more-info")))
+    {
+      httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "http",
+                       NULL, con->servername, con->serverport, "/jobs/%d",
+                      job->id);
       ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
                   "job-more-info", NULL, job_uri);
+    }
 
     if (job->state_value > IPP_JOB_PROCESSING &&
        (!exclude || !cupsArrayFind(exclude, "job-preserved")) &&
@@ -5964,12 +4712,25 @@ copy_job_attrs(cupsd_client_t *con,     /* I - Client connection */
                    "job-printer-up-time", time(NULL));
   }
 
-  if (!ra || cupsArrayFind(ra, "job-state-reasons"))
-    add_job_state_reasons(con, job);
+  if (!ra || cupsArrayFind(ra, "job-printer-uri"))
+  {
+    httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                    con->servername, con->serverport,
+                    (job->dtype & CUPS_PRINTER_CLASS) ? "/classes/%s" :
+                                                        "/printers/%s",
+                    job->dest);
+    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
+                "job-printer-uri", NULL, job_uri);
+  }
 
   if (!ra || cupsArrayFind(ra, "job-uri"))
+  {
+    httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                    con->servername, con->serverport, "/jobs/%d",
+                    job->id);
     ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
                 "job-uri", NULL, job_uri);
+  }
 
   copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0, exclude);
 }
@@ -6052,7 +4813,7 @@ copy_printer_attrs(
     ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
                ippTimeToDate(curtime));
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
   {
     if (printer->reg_name)
@@ -6062,7 +4823,7 @@ copy_printer_attrs(
       ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
                    "printer-dns-sd-name", 0);
   }
-#endif /* HAVE_DNSSD */
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
 
   if (!ra || cupsArrayFind(ra, "printer-error-policy"))
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
@@ -6078,7 +4839,7 @@ copy_printer_attrs(
                    "stop-printer"
                  };
 
-    if (printer->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_CLASS))
+    if (printer->type & CUPS_PRINTER_CLASS)
       ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
                    "printer-error-policy-supported", NULL, "retry-current-job");
     else
@@ -6105,8 +4866,7 @@ copy_printer_attrs(
     ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
                   printer->shared);
 
-  if ((!ra || cupsArrayFind(ra, "printer-more-info")) &&
-      !(printer->type & CUPS_PRINTER_DISCOVERED))
+  if (!ra || cupsArrayFind(ra, "printer-more-info"))
   {
     httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
                      "http", NULL, con->servername, con->serverport,
@@ -6162,8 +4922,7 @@ copy_printer_attrs(
     ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                   "printer-up-time", curtime);
 
-  if ((!ra || cupsArrayFind(ra, "printer-uri-supported")) &&
-      !(printer->type & CUPS_PRINTER_DISCOVERED))
+  if (!ra || cupsArrayFind(ra, "printer-uri-supported"))
   {
     httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
                      "ipp", NULL, con->servername, con->serverport,
@@ -6313,8 +5072,16 @@ static void
 create_job(cupsd_client_t  *con,       /* I - Client connection */
           ipp_attribute_t *uri)        /* I - Printer URI */
 {
+  int                  i;              /* Looping var */
   cupsd_printer_t      *printer;       /* Printer */
   cupsd_job_t          *job;           /* New job */
+  static const char * const forbidden_attrs[] =
+  {                                    /* List of forbidden attributes */
+    "compression",
+    "document-format",
+    "document-name",
+    "document-natural-language"
+  };
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
@@ -6335,6 +5102,29 @@ create_job(cupsd_client_t  *con, /* I - Client connection */
     return;
   }
 
+ /*
+  * Check for invalid Create-Job attributes and log a warning or error depending
+  * on whether cupsd is running in "strict conformance" mode...
+  */
+
+  for (i = 0;
+       i < (int)(sizeof(forbidden_attrs) / sizeof(forbidden_attrs[0]));
+       i ++)
+    if (ippFindAttribute(con->request, forbidden_attrs[i], IPP_TAG_ZERO))
+    {
+      if (StrictConformance)
+      {
+       send_ipp_status(con, IPP_BAD_REQUEST,
+                       _("The '%s' operation attribute cannot be supplied in a "
+                         "Create-Job request."), forbidden_attrs[i]);
+       return;
+      }
+
+      cupsdLogMessage(CUPSD_LOG_WARN,
+                      "Unexpected '%s' operation attribute in a Create-Job "
+                      "request.", forbidden_attrs[i]);
+    }
+
  /*
   * Create the job object...
   */
@@ -6395,6 +5185,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
 
     if (!strcmp(value, "job-template"))
     {
+      /* Only includes the set of Job Template attributes supported by CUPS */
       cupsArrayAdd(ra, "copies");
       cupsArrayAdd(ra, "copies-default");
       cupsArrayAdd(ra, "copies-supported");
@@ -6411,6 +5202,8 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "job-sheets-default");
       cupsArrayAdd(ra, "job-sheets-supported");
       cupsArrayAdd(ra, "media");
+      cupsArrayAdd(ra, "media-col");
+      cupsArrayAdd(ra, "media-col-default");
       cupsArrayAdd(ra, "media-default");
       cupsArrayAdd(ra, "media-supported");
       cupsArrayAdd(ra, "multiple-document-handling");
@@ -6418,24 +5211,49 @@ create_requested_array(ipp_t *request)  /* I - IPP request */
       cupsArrayAdd(ra, "multiple-document-handling-supported");
       cupsArrayAdd(ra, "number-up");
       cupsArrayAdd(ra, "number-up-default");
+      cupsArrayAdd(ra, "number-up-layout");
+      cupsArrayAdd(ra, "number-up-layout-default");
+      cupsArrayAdd(ra, "number-up-layout-supported");
       cupsArrayAdd(ra, "number-up-supported");
       cupsArrayAdd(ra, "orientation-requested");
       cupsArrayAdd(ra, "orientation-requested-default");
       cupsArrayAdd(ra, "orientation-requested-supported");
+      cupsArrayAdd(ra, "output-bin");
+      cupsArrayAdd(ra, "output-bin-default");
+      cupsArrayAdd(ra, "output-bin-supported");
+      cupsArrayAdd(ra, "page-delivery");
+      cupsArrayAdd(ra, "page-delivery-default");
+      cupsArrayAdd(ra, "page-delivery-supported");
+      cupsArrayAdd(ra, "page-order-received");
+      cupsArrayAdd(ra, "page-order-received-default");
+      cupsArrayAdd(ra, "page-order-received-supported");
       cupsArrayAdd(ra, "page-ranges");
       cupsArrayAdd(ra, "page-ranges-supported");
-      cupsArrayAdd(ra, "printer-resolution");
-      cupsArrayAdd(ra, "printer-resolution-default");
-      cupsArrayAdd(ra, "printer-resolution-supported");
+      cupsArrayAdd(ra, "presentation-direction-number-up");
+      cupsArrayAdd(ra, "presentation-direction-number-up-default");
+      cupsArrayAdd(ra, "presentation-direction-number-up-supported");
+      cupsArrayAdd(ra, "print-color-mode");
+      cupsArrayAdd(ra, "print-color-mode-default");
+      cupsArrayAdd(ra, "print-color-mode-supported");
+      cupsArrayAdd(ra, "print-content-optimize");
+      cupsArrayAdd(ra, "print-content-optimize-default");
+      cupsArrayAdd(ra, "print-content-optimize-supported");
       cupsArrayAdd(ra, "print-quality");
       cupsArrayAdd(ra, "print-quality-default");
       cupsArrayAdd(ra, "print-quality-supported");
+      cupsArrayAdd(ra, "printer-resolution");
+      cupsArrayAdd(ra, "printer-resolution-default");
+      cupsArrayAdd(ra, "printer-resolution-supported");
+      cupsArrayAdd(ra, "sheet-collate");
+      cupsArrayAdd(ra, "sheet-collate-default");
+      cupsArrayAdd(ra, "sheet-collate-supported");
       cupsArrayAdd(ra, "sides");
       cupsArrayAdd(ra, "sides-default");
       cupsArrayAdd(ra, "sides-supported");
     }
     else if (!strcmp(value, "job-description"))
     {
+      /* Only includes the set of Job Description attributes supported by CUPS */
       cupsArrayAdd(ra, "date-time-at-completed");
       cupsArrayAdd(ra, "date-time-at-creation");
       cupsArrayAdd(ra, "date-time-at-processing");
@@ -6446,6 +5264,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-mandatory-attributes");
       cupsArrayAdd(ra, "job-media-progress");
       cupsArrayAdd(ra, "job-media-sheets");
       cupsArrayAdd(ra, "job-media-sheets-completed");
@@ -6468,6 +5287,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
     }
     else if (!strcmp(value, "printer-description"))
     {
+      /* Only includes the set of Printer Description attributes supported by CUPS */
       cupsArrayAdd(ra, "charset-configured");
       cupsArrayAdd(ra, "charset-supported");
       cupsArrayAdd(ra, "color-supported");
@@ -6476,43 +5296,54 @@ create_requested_array(ipp_t *request)  /* I - IPP request */
       cupsArrayAdd(ra, "document-format-supported");
       cupsArrayAdd(ra, "generated-natural-language-supported");
       cupsArrayAdd(ra, "ipp-versions-supported");
+      cupsArrayAdd(ra, "job-creation-attributes-supported");
+      cupsArrayAdd(ra, "job-ids-supported");
       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, "jpeg-k-octets-supported");
+      cupsArrayAdd(ra, "jpeg-x-dimension-supported");
+      cupsArrayAdd(ra, "jpeg-y-dimension-supported");
+      cupsArrayAdd(ra, "media-bottom-margin-supported");
+      cupsArrayAdd(ra, "media-col-supported");
+      cupsArrayAdd(ra, "media-key-supported");
+      cupsArrayAdd(ra, "media-left-margin-supported");
+      cupsArrayAdd(ra, "media-right-margin-supported");
+      cupsArrayAdd(ra, "media-size-supported");
+      cupsArrayAdd(ra, "media-source-supported");
+      cupsArrayAdd(ra, "media-top-margin-supported");
+      cupsArrayAdd(ra, "media-type-supported");
       cupsArrayAdd(ra, "multiple-document-jobs-supported");
       cupsArrayAdd(ra, "multiple-operation-time-out");
       cupsArrayAdd(ra, "natural-language-configured");
-      cupsArrayAdd(ra, "notify-attributes-supported");
-      cupsArrayAdd(ra, "notify-lease-duration-default");
-      cupsArrayAdd(ra, "notify-lease-duration-supported");
       cupsArrayAdd(ra, "notify-max-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, "pdf-k-octets-supported");
       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-is-shared");
       cupsArrayAdd(ra, "printer-location");
       cupsArrayAdd(ra, "printer-make-and-model");
       cupsArrayAdd(ra, "printer-message-from-operator");
       cupsArrayAdd(ra, "printer-more-info");
       cupsArrayAdd(ra, "printer-more-info-manufacturer");
       cupsArrayAdd(ra, "printer-name");
+      cupsArrayAdd(ra, "printer-settable-attributes-supported");
       cupsArrayAdd(ra, "printer-state");
+      cupsArrayAdd(ra, "printer-state-change-date-time");
+      cupsArrayAdd(ra, "printer-state-change-time");
       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");
@@ -6520,6 +5351,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "reference-uri-schemes-supported");
       cupsArrayAdd(ra, "uri-authentication-supported");
       cupsArrayAdd(ra, "uri-security-supported");
+      cupsArrayAdd(ra, "which-jobs-supported");
     }
     else if (!strcmp(value, "printer-defaults"))
     {
@@ -6531,14 +5363,32 @@ create_requested_array(ipp_t *request)  /* I - IPP request */
           name = (char *)cupsArrayNext(CommonDefaults))
         cupsArrayAdd(ra, name);
     }
+    else if (!strcmp(value, "subscription-description"))
+    {
+      /* Only includes the set of Subscription Description attributes supported by CUPS */
+      cupsArrayAdd(ra, "notify-job-id");
+      cupsArrayAdd(ra, "notify-lease-expiration-time");
+      cupsArrayAdd(ra, "notify-printer-up-time");
+      cupsArrayAdd(ra, "notify-printer-uri");
+      cupsArrayAdd(ra, "notify-sequence-number");
+      cupsArrayAdd(ra, "notify-subscriber-user-name");
+      cupsArrayAdd(ra, "notify-subscription-id");
+    }
     else if (!strcmp(value, "subscription-template"))
     {
+      /* Only includes the set of Subscription Template attributes supported by CUPS */
       cupsArrayAdd(ra, "notify-attributes");
+      cupsArrayAdd(ra, "notify-attributes-supported");
       cupsArrayAdd(ra, "notify-charset");
       cupsArrayAdd(ra, "notify-events");
+      cupsArrayAdd(ra, "notify-events-default");
+      cupsArrayAdd(ra, "notify-events-supported");
       cupsArrayAdd(ra, "notify-lease-duration");
+      cupsArrayAdd(ra, "notify-lease-duration-default");
+      cupsArrayAdd(ra, "notify-lease-duration-supported");
       cupsArrayAdd(ra, "notify-natural-language");
       cupsArrayAdd(ra, "notify-pull-method");
+      cupsArrayAdd(ra, "notify-pull-method-supported");
       cupsArrayAdd(ra, "notify-recipient-uri");
       cupsArrayAdd(ra, "notify-time-interval");
       cupsArrayAdd(ra, "notify-user-data");
@@ -6997,13 +5847,11 @@ delete_printer(cupsd_client_t  *con,    /* I - Client connection */
   snprintf(filename, sizeof(filename), "%s/%s.data", CacheDir, printer->name);
   unlink(filename);
 
-#ifdef __APPLE__
  /*
   * Unregister color profiles...
   */
 
-  apple_unregister_profiles(printer);
-#endif /* __APPLE__ */
+  cupsdUnregisterColor(printer);
 
   if (dtype & CUPS_PRINTER_CLASS)
   {
@@ -7766,7 +6614,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
        continue;
       }
 
-      if (username[0] && strcasecmp(username, job->username))
+      if (username[0] && _cups_strcasecmp(username, job->username))
        continue;
 
       if (count > 0)
@@ -8025,11 +6873,10 @@ get_ppd(cupsd_client_t  *con,           /* I - Client connection */
                    "printer-uri", NULL, dest->uri);
       return;
     }
-    else if (dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
+    else if (dtype & CUPS_PRINTER_CLASS)
     {
       for (i = 0; i < dest->num_printers; i ++)
-        if (!(dest->printers[i]->type &
-             (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)))
+        if (!(dest->printers[i]->type & CUPS_PRINTER_CLASS))
        {
          snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
                   dest->printers[i]->name);
@@ -8474,17 +7321,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))))
+        (printer->location && !_cups_strcasecmp(printer->location, location))))
     {
-     /*
-      * If HideImplicitMembers is enabled, see if this printer or class
-      * is a member of an implicit class...
-      */
-
-      if (ImplicitClasses && HideImplicitMembers &&
-          printer->in_implicit_class)
-        continue;
-
      /*
       * If a username is specified, see if it is allowed or denied
       * access...
@@ -8714,7 +7552,7 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
        sub;
        sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
     if ((!printer || sub->dest == printer) && (!job || sub->job == job) &&
-        (!username[0] || !strcasecmp(username, sub->owner)))
+        (!username[0] || !_cups_strcasecmp(username, sub->owner)))
     {
       ippAddSeparator(con->response);
 
@@ -8850,6 +7688,22 @@ hold_job(cupsd_client_t  *con,           /* I - Client connection */
     return;
   }
 
+ /*
+  * See if the job is in a state that allows holding...
+  */
+
+  if (job->state_value > IPP_JOB_STOPPED)
+  {
+   /*
+    * Return a "not-possible" error...
+    */
+
+    send_ipp_status(con, IPP_NOT_POSSIBLE,
+                   _("Job #%d is finished and cannot be altered."),
+                   job->id);
+    return;
+  }
+
  /*
   * Hold the job and return...
   */
@@ -9166,7 +8020,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
       * completed...
       */
 
-      if (strcasecmp(job->dest, src) ||
+      if (_cups_strcasecmp(job->dest, src) ||
           job->state_value > IPP_JOB_STOPPED)
        continue;
 
@@ -9465,9 +8319,9 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
   * Read any embedded job ticket info from PS files...
   */
 
-  if (!strcasecmp(filetype->super, "application") &&
-      (!strcasecmp(filetype->type, "postscript") ||
-       !strcasecmp(filetype->type, "pdf")))
+  if (!_cups_strcasecmp(filetype->super, "application") &&
+      (!_cups_strcasecmp(filetype->type, "postscript") ||
+       !_cups_strcasecmp(filetype->type, "pdf")))
     read_job_ticket(con);
 
  /*
@@ -9694,14 +8548,14 @@ read_job_ticket(cupsd_client_t *con)    /* I - Client connection */
       if (con->request->last == attr2)
         con->request->last = prev2;
 
-      _ippFreeAttr(attr2);
+      ippDeleteAttribute(NULL, attr2);
     }
 
    /*
     * Add new option by copying it...
     */
 
-    copy_attribute(con->request, attr, 0);
+    ippCopyAttribute(con->request, attr, 0);
   }
 
  /*
@@ -9982,6 +8836,7 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
 
     cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
                   "Job job-hold-until value changed by user.");
+    ippSetString(job->attrs, &job->reasons, 0, "none");
   }
 
  /*
@@ -10260,7 +9115,7 @@ save_auth_info(
   int                  i;              /* Looping var */
   char                 filename[1024]; /* Job authentication filename */
   cups_file_t          *fp;            /* Job authentication file */
-  char                 line[2048];     /* Line for file */
+  char                 line[65536];    /* Line for file */
   cupsd_printer_t      *dest;          /* Destination printer/class */
 
 
@@ -10309,33 +9164,66 @@ save_auth_info(
   fchown(cupsFileNumber(fp), 0, 0);
   fchmod(cupsFileNumber(fp), 0400);
 
+  cupsFilePuts(fp, "CUPSD-AUTH-V2\n");
+
+  for (i = 0;
+       i < (int)(sizeof(job->auth_env) / sizeof(job->auth_env[0]));
+       i ++)
+    cupsdClearString(job->auth_env + i);
+
   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 ++)
+    for (i = 0;
+         i < auth_info->num_values &&
+            i < (int)(sizeof(job->auth_env) / sizeof(job->auth_env[0]));
+        i ++)
     {
       httpEncode64_2(line, sizeof(line), auth_info->values[i].string.text,
                      strlen(auth_info->values[i].string.text));
-      cupsFilePrintf(fp, "%s\n", line);
+      cupsFilePutConf(fp, dest->auth_info_required[i], line);
 
       if (!strcmp(dest->auth_info_required[i], "username"))
-        cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s",
+        cupsdSetStringf(job->auth_env + i, "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",
+        cupsdSetStringf(job->auth_env + i, "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",
+        cupsdSetStringf(job->auth_env + i, "AUTH_PASSWORD=%s",
                        auth_info->values[i].string.text);
+      else if (!strcmp(dest->auth_info_required[i], "negotiate"))
+        cupsdSetStringf(job->auth_env + i, "AUTH_NEGOTIATE=%s",
+                       auth_info->values[i].string.text);
+      else
+        i --;
     }
   }
+  else if (auth_info && auth_info->num_values == 2 &&
+           dest->num_auth_info_required == 1 &&
+           !strcmp(dest->auth_info_required[0], "negotiate"))
+  {
+   /*
+    * Allow fallback to username+password for Kerberized queues...
+    */
+
+    httpEncode64_2(line, sizeof(line), auth_info->values[0].string.text,
+                   strlen(auth_info->values[0].string.text));
+    cupsFilePutConf(fp, "username", line);
+
+    cupsdSetStringf(job->auth_env + 0, "AUTH_USERNAME=%s",
+                    auth_info->values[0].string.text);
+
+    httpEncode64_2(line, sizeof(line), auth_info->values[1].string.text,
+                   strlen(auth_info->values[1].string.text));
+    cupsFilePutConf(fp, "password", line);
+
+    cupsdSetStringf(job->auth_env + 1, "AUTH_PASSWORD=%s",
+                    auth_info->values[1].string.text);
+  }
   else if (con->username[0])
   {
    /*
@@ -10343,25 +9231,24 @@ save_auth_info(
     */
 
     httpEncode64_2(line, sizeof(line), con->username, strlen(con->username));
-    cupsFilePrintf(fp, "%s\n", line);
+    cupsFilePutConf(fp, "username", line);
 
-    cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s", con->username);
-    cupsdClearString(&job->auth_domain);
+    cupsdSetStringf(job->auth_env + 0, "AUTH_USERNAME=%s", con->username);
 
    /*
     * Write the authenticated password...
     */
 
     httpEncode64_2(line, sizeof(line), con->password, strlen(con->password));
-    cupsFilePrintf(fp, "%s\n", line);
+    cupsFilePutConf(fp, "password", line);
 
-    cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s", con->password);
+    cupsdSetStringf(job->auth_env + 1, "AUTH_PASSWORD=%s", con->password);
   }
 
 #ifdef HAVE_GSSAPI
-  if (con->have_gss && con->gss_uid > 0)
+  if (con->gss_uid > 0)
   {
-    cupsFilePrintf(fp, "%d\n", (int)con->gss_uid);
+    cupsFilePrintf(fp, "uid %d\n", (int)con->gss_uid);
     cupsdSetStringf(&job->auth_uid, "AUTH_UID=%d", (int)con->gss_uid);
   }
 #endif /* HAVE_GSSAPI */
@@ -10528,6 +9415,14 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
   * Do we have a file to print?
   */
 
+  if ((attr = ippFindAttribute(con->request, "last-document",
+                              IPP_TAG_BOOLEAN)) == NULL)
+  {
+    send_ipp_status(con, IPP_BAD_REQUEST,
+                    _("Missing last-document attribute in request."));
+    return;
+  }
+
   if (!con->filename)
   {
    /*
@@ -10535,10 +9430,7 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
     * used to close an "open" job by RFC 2911, section 3.3.2.
     */
 
-    if (job->num_files > 0 &&
-        (attr = ippFindAttribute(con->request, "last-document",
-                                IPP_TAG_BOOLEAN)) != NULL &&
-        attr->values[0].boolean)
+    if (job->num_files > 0 && attr->values[0].boolean)
       goto last_document;
 
     send_ipp_status(con, IPP_BAD_REQUEST, _("No file in print request."));
@@ -10714,6 +9606,8 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
     {
       job->state->values[0].integer = IPP_JOB_PENDING;
       job->state_value              = IPP_JOB_PENDING;
+
+      ippSetString(job->attrs, &job->reasons, 0, "none");
     }
     else if (job->state_value == IPP_JOB_HELD)
     {
@@ -10725,7 +9619,11 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
       {
        job->state->values[0].integer = IPP_JOB_PENDING;
        job->state_value              = IPP_JOB_PENDING;
+
+       ippSetString(job->attrs, &job->reasons, 0, "none");
       }
+      else
+       ippSetString(job->attrs, &job->reasons, 0, "job-hold-until-specified");
     }
 
     job->dirty = 1;
@@ -10744,8 +9642,10 @@ 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) + MultipleOperationTimeout;
-      job->dirty                    = 1;
 
+      ippSetString(job->attrs, &job->reasons, 0, "job-incoming");
+
+      job->dirty = 1;
       cupsdMarkDirty(CUPSD_DIRTY_JOBS);
     }
 
@@ -10756,9 +9656,8 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
   * Fill in the response info...
   */
 
-  snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
-          LocalPort, jobid);
-
+  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                   con->servername, con->serverport, "/jobs/%d", jobid);
   ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
                job_uri);
 
@@ -10766,7 +9665,8 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
 
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
                 job->state_value);
-  add_job_state_reasons(con, job);
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons",
+               NULL, job->reasons->values[0].string.text);
 
   con->response->request.status.status_code = IPP_OK;
 
@@ -10799,7 +9699,9 @@ send_http_error(
   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),
+                 con->request ?
+                     ippOpString(con->request->request.op.operation_id) :
+                     "no operation-id",
                  uri ? uri->values[0].string.text : "no URI",
                  con->http.hostname);
 
@@ -10849,7 +9751,7 @@ send_http_error(
       if (auth)
       {
         if (auth->type == CUPSD_AUTH_DEFAULT)
-         auth_type = DefaultAuthType;
+         auth_type = cupsdDefaultAuthType();
        else
          auth_type = auth->type;
       }
@@ -10964,7 +9866,7 @@ set_default(cupsd_client_t  *con,        /* I - Client connection */
                "%s is now the default printer.", printer->name);
 
   cupsdMarkDirty(CUPSD_DIRTY_PRINTERS | CUPSD_DIRTY_CLASSES |
-                 CUPSD_DIRTY_REMOTE | CUPSD_DIRTY_PRINTCAP);
+                 CUPSD_DIRTY_PRINTCAP);
 
   cupsdLogMessage(CUPSD_LOG_INFO,
                   "Default destination set to \"%s\" by \"%s\".",
@@ -11142,9 +10044,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
       send_ipp_status(con, IPP_ATTRIBUTES_NOT_SETTABLE,
                       _("%s cannot be changed."), attr->name);
 
-      if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL)
-        attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
-
+      attr2 = ippCopyAttribute(con->response, attr, 0);
+      ippSetGroupTag(con->response, &attr2, IPP_TAG_UNSUPPORTED_GROUP);
       continue;
     }
 
@@ -11158,8 +10059,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
       {
        send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-priority value."));
 
-       if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL)
-          attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
+       attr2 = ippCopyAttribute(con->response, attr, 0);
+       ippSetGroupTag(con->response, &attr2, IPP_TAG_UNSUPPORTED_GROUP);
       }
       else if (job->state_value >= IPP_JOB_PROCESSING)
       {
@@ -11188,8 +10089,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
       {
        send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-state value."));
 
-       if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL)
-          attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
+       attr2 = ippCopyAttribute(con->response, attr, 0);
+       ippSetGroupTag(con->response, &attr2, IPP_TAG_UNSUPPORTED_GROUP);
       }
       else
       {
@@ -11263,13 +10164,13 @@ set_job_attrs(cupsd_client_t  *con,   /* I - Client connection */
       if (job->attrs->last == attr2)
         job->attrs->last = job->attrs->prev;
 
-      _ippFreeAttr(attr2);
+      ippDeleteAttribute(NULL, attr2);
 
      /*
       * Then copy the attribute...
       */
 
-      copy_attribute(job->attrs, attr, 0);
+      ippCopyAttribute(job->attrs, attr, 0);
 
      /*
       * See if the job-name or job-hold-until is being changed.
@@ -11310,7 +10211,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
         if (attr2 == job->attrs->last)
          job->attrs->last = job->attrs->prev;
 
-        _ippFreeAttr(attr2);
+        ippDeleteAttribute(NULL, attr2);
 
         event |= CUPSD_EVENT_JOB_CONFIG_CHANGED;
       }
@@ -11321,7 +10222,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
       * Add new option by copying it...
       */
 
-      copy_attribute(job->attrs, attr, 0);
+      ippCopyAttribute(job->attrs, attr, 0);
 
       event |= CUPSD_EVENT_JOB_CONFIG_CHANGED;
     }
@@ -11586,7 +10487,7 @@ set_printer_defaults(
         continue;
 
       if (strcmp(attr->values[0].string.text, "retry-current-job") &&
-          ((printer->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_CLASS)) ||
+          ((printer->type & CUPS_PRINTER_CLASS) ||
           (strcmp(attr->values[0].string.text, "abort-job") &&
            strcmp(attr->values[0].string.text, "retry-job") &&
            strcmp(attr->values[0].string.text, "stop-printer"))))
@@ -11676,7 +10577,7 @@ set_printer_defaults(
           sprintf(value, "%dx%d%s", attr->values[0].resolution.xres,
                  attr->values[0].resolution.yres,
                  attr->values[0].resolution.units == IPP_RES_PER_INCH ?
-                     "dpi" : "dpc");
+                     "dpi" : "dpcm");
           printer->num_options = cupsAddOption(name, value,
                                               printer->num_options,
                                               &(printer->options));
@@ -12000,7 +10901,7 @@ user_allowed(cupsd_printer_t *p,        /* I - Printer or class */
       if (cupsdCheckGroup(username, pw, name))
         break;
     }
-    else if (!strcasecmp(username, name))
+    else if (!_cups_strcasecmp(username, name))
       break;
   }