]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / ipp.c
index 7053ad0a8541a5a033815e5be98bb17ee0a5310e..3c50525df7c0537d12a0f77043687bc02c4963d6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c 5131 2006-02-18 05:31:36Z mike $"
+ * "$Id: ipp.c 5164 2006-02-24 20:40:00Z mike $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -27,6 +27,7 @@
  *   accept_jobs()               - Accept print jobs to a printer.
  *   add_class()                 - Add a class to the system.
  *   add_file()                  - Add a file to a job.
+ *   add_job()                   - Add a job to a print queue.
  *   add_job_state_reasons()     - Add the "job-state-reasons" attribute based
  *                                 upon the job and printer state...
  *   add_job_subscriptions()     - Add any subcriptions for a job.
@@ -35,6 +36,7 @@
  *   add_printer_state_reasons() - Add the "printer-state-reasons" attribute
  *                                 based upon the printer state...
  *   add_queued_job_count()      - Add the "queued-job-count" attribute for
+ *   apply_printer_defaults()    - Apply printer default options to a job.
  *   authenticate_job()          - Set job authentication info.
  *   cancel_all_jobs()           - Cancel all print jobs.
  *   cancel_job()                - Cancel a print job.
@@ -83,6 +85,7 @@
  *   send_ipp_status()           - Send a status back to the IPP client.
  *   set_default()               - Set the default destination...
  *   set_job_attrs()             - Set job attributes.
+ *   set_printer_defaults()      - Set printer default options from a request.
  *   start_printer()             - Start a printer.
  *   stop_printer()              - Stop a printer.
  *   user_allowed()              - See if a user is allowed to print to a queue.
@@ -120,14 +123,19 @@ typedef struct
 
 static void    accept_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    add_class(cupsd_client_t *con, ipp_attribute_t *uri);
-static int     add_file(cupsd_client_t *con, cupsd_job_t *job, mime_type_t *filetype,
-                        int compression);
+static int     add_file(cupsd_client_t *con, cupsd_job_t *job,
+                        mime_type_t *filetype, int compression);
+static cupsd_job_t *add_job(cupsd_client_t *con, ipp_attribute_t *uri,
+                           cupsd_printer_t **dprinter);
 static 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_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_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);
+static void    apply_printer_defaults(cupsd_printer_t *printer,
+                                      cupsd_job_t *job);
 static void    authenticate_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    cancel_all_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    cancel_job(cupsd_client_t *con, ipp_attribute_t *uri);
@@ -137,9 +145,11 @@ static ipp_attribute_t     *copy_attribute(ipp_t *to, ipp_attribute_t *attr,
                                        int quickcopy);
 static void    copy_attrs(ipp_t *to, ipp_t *from, cups_array_t *ra,
                           ipp_tag_t group, int quickcopy);
-static int     copy_banner(cupsd_client_t *con, cupsd_job_t *job, const char *name);
+static int     copy_banner(cupsd_client_t *con, cupsd_job_t *job,
+                           const char *name);
 static int     copy_file(const char *from, const char *to);
-static int     copy_model(cupsd_client_t *con, const char *from, const char *to);
+static int     copy_model(cupsd_client_t *con, const char *from,
+                          const char *to);
 static void    copy_job_attrs(cupsd_client_t *con,
                               cupsd_job_t *job,
                               cups_array_t *ra);
@@ -187,6 +197,8 @@ __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_defaults(cupsd_client_t *con,
+                                    cupsd_printer_t *printer);
 static void    start_printer(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    stop_printer(cupsd_client_t *con, ipp_attribute_t *uri);
 static int     user_allowed(cupsd_printer_t *p, const char *username);
@@ -761,6 +773,7 @@ add_class(cupsd_client_t  *con,             /* I - Client connection */
   const char   *dest;                  /* Printer or class name */
   ipp_attribute_t *attr;               /* Printer attribute */
   int          modify;                 /* Non-zero if we just modified */
+  char         newname[IPP_MAX_NAME];  /* New class name */
   int          need_restart_job;       /* Need to restart job? */
 
 
@@ -852,9 +865,8 @@ add_class(cupsd_client_t  *con,             /* I - Client connection */
 
     if (ImplicitAnyClasses)
     {
-      cupsArrayRemove(Printers, pclass);
-      cupsdSetStringf(&pclass->name, "Any%s", resource + 9);
-      cupsArrayAdd(Printers, pclass);
+      snprintf(newname, sizeof(newname), "Any%s", resource + 9);
+      cupsdRenamePrinter(pclass, newname);
     }
     else
       cupsdDeletePrinter(pclass, 1);
@@ -872,11 +884,8 @@ add_class(cupsd_client_t  *con,            /* I - Client connection */
     * Rename the remote class to "Class"...
     */
 
-    cupsdDeletePrinterFilters(pclass);
-    cupsArrayRemove(Printers, pclass);
-    cupsdSetStringf(&pclass->name, "%s@%s", resource + 9, pclass->hostname);
-    cupsdSetPrinterAttrs(pclass);
-    cupsArrayAdd(Printers, pclass);
+    snprintf(newname, sizeof(newname), "%s@%s", resource + 9, pclass->hostname);
+    cupsdRenamePrinter(pclass, newname);
 
    /*
     * Add the class as a new local class...
@@ -955,107 +964,6 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
             sizeof(pclass->state_message));
     cupsdAddPrinterHistory(pclass);
   }
-  if ((attr = ippFindAttribute(con->request, "job-sheets-default",
-                               IPP_TAG_ZERO)) != NULL &&
-      !Classification)
-  {
-    cupsdSetString(&pclass->job_sheets[0], attr->values[0].string.text);
-    if (attr->num_values > 1)
-      cupsdSetString(&pclass->job_sheets[1], attr->values[1].string.text);
-    else
-      cupsdSetString(&pclass->job_sheets[1], "none");
-  }
-  if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
-                               IPP_TAG_ZERO)) != NULL)
-  {
-    cupsdFreePrinterUsers(pclass);
-
-    pclass->deny_users = 0;
-    if (attr->value_tag == IPP_TAG_NAME &&
-        (attr->num_values > 1 ||
-        strcmp(attr->values[0].string.text, "all")))
-      for (i = 0; i < attr->num_values; i ++)
-       cupsdAddPrinterUser(pclass, attr->values[i].string.text);
-  }
-  else if ((attr = ippFindAttribute(con->request, "requesting-user-name-denied",
-                                    IPP_TAG_ZERO)) != NULL)
-  {
-    cupsdFreePrinterUsers(pclass);
-
-    pclass->deny_users = 1;
-    if (attr->value_tag == IPP_TAG_NAME &&
-        (attr->num_values > 1 ||
-        strcmp(attr->values[0].string.text, "none")))
-      for (i = 0; i < attr->num_values; i ++)
-       cupsdAddPrinterUser(pclass, attr->values[i].string.text);
-  }
-  if ((attr = ippFindAttribute(con->request, "job-quota-period",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "add_class: Setting job-quota-period to %d...",
-                    attr->values[0].integer);
-    cupsdFreeQuotas(pclass);
-    pclass->quota_period = attr->values[0].integer;
-  }
-  if ((attr = ippFindAttribute(con->request, "job-k-limit",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "add_class: Setting job-k-limit to %d...",
-                    attr->values[0].integer);
-    cupsdFreeQuotas(pclass);
-    pclass->k_limit = attr->values[0].integer;
-  }
-  if ((attr = ippFindAttribute(con->request, "job-page-limit",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "add_class: Setting job-page-limit to %d...",
-                    attr->values[0].integer);
-    cupsdFreeQuotas(pclass);
-    pclass->page_limit = attr->values[0].integer;
-  }
-  if ((attr = ippFindAttribute(con->request, "printer-op-policy",
-                               IPP_TAG_NAME)) != NULL)
-  {
-    cupsd_policy_t *p;                 /* Policy */
-
-
-    if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
-                      "add_class: Setting printer-op-policy to \"%s\"...",
-                      attr->values[0].string.text);
-      cupsdSetString(&pclass->op_policy, attr->values[0].string.text);
-      pclass->op_policy_ptr = p;
-    }
-    else
-    {
-      send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("add_class: Unknown printer-op-policy \"%s\"."),
-                      attr->values[0].string.text);
-      return;
-    }
-  }
-  if ((attr = ippFindAttribute(con->request, "printer-error-policy",
-                               IPP_TAG_NAME)) != NULL)
-  {
-    if (strcmp(attr->values[0].string.text, "abort-job") &&
-        strcmp(attr->values[0].string.text, "retry-job") &&
-        strcmp(attr->values[0].string.text, "stop-printer"))
-    {
-      send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("add_class: Unknown printer-error-policy \"%s\"."),
-                      attr->values[0].string.text);
-      return;
-    }
-
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "add_class: Setting printer-error-policy to \"%s\"...",
-                    attr->values[0].string.text);
-    cupsdSetString(&pclass->error_policy, attr->values[0].string.text);
-  }
   if ((attr = ippFindAttribute(con->request, "member-uris",
                                IPP_TAG_URI)) != NULL)
   {
@@ -1104,6 +1012,8 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
     }
   }
 
+  set_printer_defaults(con, pclass);
+
  /*
   * Update the printer class attributes and return...
   */
@@ -1215,3297 +1125,3301 @@ add_file(cupsd_client_t *con,               /* I - Connection to client */
 
 
 /*
- * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
- *                             upon the job and printer state...
+ * 'add_job()' - Add a job to a print queue.
  */
 
-static void
-add_job_state_reasons(
-    cupsd_client_t *con,               /* I - Client connection */
-    cupsd_job_t    *job)               /* I - Job info */
+static cupsd_job_t *                   /* O - Job object */
+add_job(cupsd_client_t  *con,          /* I - Client connection */
+        ipp_attribute_t *uri,          /* I - printer-uri */
+       cupsd_printer_t **dprinter)     /* I - Destination printer */
 {
-  cupsd_printer_t      *dest;          /* Destination printer */
+  http_status_t        status;                 /* Policy status */
+  ipp_attribute_t *attr;               /* Current attribute */
+  const char   *dest;                  /* Destination */
+  cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  const char   *val;                   /* Default option value */
+  int          priority;               /* Job priority */
+  char         *title;                 /* Job name/title */
+  cupsd_job_t  *job;                   /* Current job */
+  char         job_uri[HTTP_MAX_URI],  /* Job URI */
+               method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  cupsd_printer_t *printer;            /* Printer data */
+  int          kbytes;                 /* Size of print file */
+  int          i;                      /* Looping var */
+  int          lowerpagerange;         /* Page range bound */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job_state_reasons(%p[%d], %d)",
-                  con, con->http.fd, job ? job->id : 0);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
 
-  switch (job ? job->state_value : IPP_JOB_CANCELLED)
+ /*
+  * Is the destination valid?
+  */
+
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
-    case IPP_JOB_PENDING :
-        if (job->dtype & CUPS_PRINTER_CLASS)
-         dest = cupsdFindClass(job->dest);
-       else
-         dest = cupsdFindPrinter(job->dest);
+   /*
+    * Bad URI...
+    */
 
-        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;
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The printer or class was not found."));
+    return (NULL);
+  }
 
-    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;
+  if (dprinter)
+    *dprinter = printer;
 
-    case IPP_JOB_PROCESSING :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-printing");
-        break;
+ /*
+  * Check remote printing to non-shared printer...
+  */
 
-    case IPP_JOB_STOPPED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-stopped");
-        break;
+  if (!printer->shared &&
+      strcasecmp(con->http.hostname, "localhost") &&
+      strcasecmp(con->http.hostname, ServerName))
+  {
+    send_ipp_status(con, IPP_NOT_AUTHORIZED,
+                    _("The printer or class is not shared!"));
+    return (NULL);
+  }
 
-    case IPP_JOB_CANCELLED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-canceled-by-user");
-        break;
+ /*
+  * Check policy...
+  */
 
-    case IPP_JOB_ABORTED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "aborted-by-system");
-        break;
+  if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+  {
+    send_http_error(con, status);
+    return (NULL);
+  }
+  else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
+  {
+    send_http_error(con, HTTP_UNAUTHORIZED);
+    return (NULL);
+  }
 
-    case IPP_JOB_COMPLETED :
-        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                    "job-state-reasons", NULL, "job-completed-successfully");
-        break;
+ /*
+  * See if the printer is accepting jobs...
+  */
+
+  if (!printer->accepting)
+  {
+    send_ipp_status(con, IPP_NOT_ACCEPTING,
+                    _("Destination \"%s\" is not accepting jobs."),
+                    dest);
+    return (NULL);
   }
-}
 
+ /*
+  * Validate job template attributes; for now just copies and page-ranges...
+  */
 
-/*
- * 'add_job_subscriptions()' - Add any subcriptions for a job.
- */
+  if ((attr = ippFindAttribute(con->request, "copies",
+                               IPP_TAG_INTEGER)) != NULL)
+  {
+    if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies)
+    {
+      send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."),
+                      attr->values[0].integer);
+      ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
+                   "copies", attr->values[0].integer);
+      return (NULL);
+    }
+  }
 
-static void
-add_job_subscriptions(
-    cupsd_client_t *con,               /* I - Client connection */
-    cupsd_job_t    *job)               /* I - Newly created job */
-{
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *prev,          /* Previous attribute */
-                       *next,          /* Next attribute */
-                       *attr;          /* Current attribute */
-  cupsd_subscription_t *sub;           /* Subscription object */
-  const char           *recipient,     /* notify-recipient-uri */
-                       *pullmethod;    /* notify-pull-method */
-  ipp_attribute_t      *user_data;     /* notify-user-data */
-  int                  interval;       /* notify-time-interval */
-  unsigned             mask;           /* notify-events */
+  if ((attr = ippFindAttribute(con->request, "page-ranges",
+                               IPP_TAG_RANGE)) != NULL)
+  {
+    for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
+    {
+      if (attr->values[i].range.lower < lowerpagerange || 
+         attr->values[i].range.lower > attr->values[i].range.upper)
+      {
+       send_ipp_status(con, IPP_BAD_REQUEST,
+                       _("Bad page-ranges values %d-%d."),
+                       attr->values[i].range.lower,
+                       attr->values[i].range.upper);
+       return (NULL);
+      }
 
+      lowerpagerange = attr->values[i].range.upper + 1;
+    }
+  }
 
  /*
-  * Find the first subscription group attribute; return if we have
-  * none...
+  * Make sure we aren't over our limit...
   */
 
-  for (attr = job->attrs->attrs, prev = NULL;
-       attr;
-       prev = attr, attr = attr->next)
-    if (attr->group_tag == IPP_TAG_SUBSCRIPTION)
-      break;
+  if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
+    cupsdCleanJobs();
 
-  if (!attr)
-    return;
+  if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
+  {
+    send_ipp_status(con, IPP_NOT_POSSIBLE,
+                    _("Too many active jobs."));
+    return (NULL);
+  }
+
+  if (!check_quotas(con, printer))
+  {
+    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
+    return (NULL);
+  }
 
  /*
-  * Process the subscription attributes in the request...
+  * Create the job and set things up...
   */
 
-  while (attr)
+  if ((attr = ippFindAttribute(con->request, "job-priority",
+                               IPP_TAG_INTEGER)) != NULL)
+    priority = attr->values[0].integer;
+  else
   {
-    recipient = NULL;
-    pullmethod = NULL;
-    user_data  = NULL;
-    interval   = 0;
-    mask       = CUPSD_EVENT_NONE;
-
-    while (attr && attr->group_tag != IPP_TAG_ZERO)
-    {
-      if (!strcmp(attr->name, "notify-recipient") &&
-          attr->value_tag == IPP_TAG_URI)
-        recipient = attr->values[0].string.text;
-      else if (!strcmp(attr->name, "notify-pull-method") &&
-               attr->value_tag == IPP_TAG_KEYWORD)
-        pullmethod = attr->values[0].string.text;
-      else if (!strcmp(attr->name, "notify-charset") &&
-               attr->value_tag == IPP_TAG_CHARSET &&
-              strcmp(attr->values[0].string.text, "us-ascii") &&
-              strcmp(attr->values[0].string.text, "utf-8"))
-      {
-        send_ipp_status(con, IPP_CHARSET,
-                       _("Character set \"%s\" not supported!"),
-                       attr->values[0].string.text);
-       return;
-      }
-      else if (!strcmp(attr->name, "notify-natural-language") &&
-               (attr->value_tag != IPP_TAG_LANGUAGE ||
-               strcmp(attr->values[0].string.text, DefaultLanguage)))
-      {
-        send_ipp_status(con, IPP_CHARSET,
-                       _("Language \"%s\" not supported!"),
-                       attr->values[0].string.text);
-       return;
-      }
-      else if (!strcmp(attr->name, "notify-user-data") &&
-               attr->value_tag == IPP_TAG_STRING)
-      {
-        if (attr->num_values > 1 || attr->values[0].unknown.length > 63)
-       {
-          send_ipp_status(con, IPP_REQUEST_VALUE,
-                         _("The notify-user-data value is too large "
-                           "(%d > 63 octets)!"),
-                         attr->values[0].unknown.length);
-         return;
-       }
-
-        user_data = attr;
-      }
-      else if (!strcmp(attr->name, "notify-events") &&
-               attr->value_tag == IPP_TAG_KEYWORD)
-      {
-        for (i = 0; i < attr->num_values; i ++)
-         mask |= cupsdEventValue(attr->values[i].string.text);
-      }
-      else if (!strcmp(attr->name, "notify-lease-duration"))
-      {
-        send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("The notify-lease-duration attribute cannot be "
-                         "used with job subscriptions."));
-       return;
-      }
-      else if (!strcmp(attr->name, "notify-time-interval") &&
-               attr->value_tag == IPP_TAG_INTEGER)
-        interval = attr->values[0].integer;
-
-      attr = attr->next;
-    }
+    if ((val = cupsGetOption("job-priority", printer->num_options,
+                             printer->options)) != NULL)
+      priority = atoi(val);
+    else
+      priority = 50;
 
-    if (!recipient && !pullmethod)
-      break;
+    ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority",
+                  priority);
+  }
 
-    if (mask == CUPSD_EVENT_NONE)
-      mask = CUPSD_EVENT_JOB_COMPLETED;
+  if ((attr = ippFindAttribute(con->request, "job-name",
+                               IPP_TAG_NAME)) != NULL)
+    title = attr->values[0].string.text;
+  else
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
+                 title = "Untitled");
 
-    sub = cupsdAddSubscription(mask, cupsdFindDest(job->dest), job, recipient,
-                               0);
+  if ((job = cupsdAddJob(priority, printer->name)) == NULL)
+  {
+    send_ipp_status(con, IPP_INTERNAL_ERROR,
+                    _("Unable to add job for destination \"%s\"!"), dest);
+    return (NULL);
+  }
 
-    sub->interval = interval;
+  job->dtype   = dtype;
+  job->attrs   = con->request;
+  con->request = NULL;
 
-    cupsdSetString(&sub->owner, job->username);
+  add_job_uuid(con, job);
+  apply_printer_defaults(printer, job);
 
-    if (user_data)
-    {
-      sub->user_data_len = user_data->values[0].unknown.length;
-      memcpy(sub->user_data, user_data->values[0].unknown.data,
-             sub->user_data_len);
-    }
+  attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
 
-    ippAddSeparator(con->response);
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-subscription-id", sub->id);
+  if (con->username[0])
+  {
+    cupsdSetString(&job->username, con->username);
 
     if (attr)
-      attr = attr->next;
+      cupsdSetString(&attr->values[0].string.text, con->username);
+
+    save_auth_info(con, job);
   }
+  else if (attr)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                    "add_job: requesting-user-name=\"%s\"",
+                    attr->values[0].string.text);
 
-  cupsdSaveAllSubscriptions();
+    cupsdSetString(&job->username, attr->values[0].string.text);
+  }
+  else
+    cupsdSetString(&job->username, "anonymous");
 
- /*
-  * Remove all of the subscription attributes from the job request...
-  */
+  if (!attr)
+    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
+                 "job-originating-user-name", NULL, job->username);
+  else
+  {
+    attr->group_tag = IPP_TAG_JOB;
+    _cups_sp_free(attr->name);
+    attr->name = _cups_sp_alloc("job-originating-user-name");
+  }
 
-  for (attr = job->attrs->attrs, prev = NULL; attr; attr = next)
+  if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
+                               IPP_TAG_ZERO)) != NULL)
   {
-    next = attr->next;
+   /*
+    * Request contains a job-originating-host-name attribute; validate it...
+    */
 
-    if (attr->group_tag == IPP_TAG_SUBSCRIPTION ||
-        attr->group_tag == IPP_TAG_ZERO)
+    if (attr->value_tag != IPP_TAG_NAME ||
+        attr->num_values != 1 ||
+        strcmp(con->http.hostname, "localhost"))
     {
      /*
-      * Free and remove this attribute...
+      * Can't override the value if we aren't connected via localhost.
+      * Also, we can only have 1 value and it must be a name value.
       */
 
-      _ipp_free_attr(attr);
-
-      if (prev)
-        prev->next = next;
-      else
-        job->attrs->attrs = next;
-    }
-    else
-      prev = attr;
-  }
+      switch (attr->value_tag)
+      {
+        case IPP_TAG_STRING :
+       case IPP_TAG_TEXTLANG :
+       case IPP_TAG_NAMELANG :
+       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 :
+          /*
+           * Free old strings...
+           */
 
-  job->attrs->last    = prev;
-  job->attrs->current = prev;
-}
+           for (i = 0; i < attr->num_values; i ++)
+           {
+             _cups_sp_free(attr->values[i].string.text);
+             attr->values[i].string.text = NULL;
+             if (attr->values[i].string.charset)
+             {
+               _cups_sp_free(attr->values[i].string.charset);
+               attr->values[i].string.charset = NULL;
+             }
+            }
 
+       default :
+            break;
+      }
 
-/*
- * 'add_job_uuid()' - Add job-uuid attribute to a job.
- *
- * See RFC 4122 for the definition of UUIDs and the format.
- */
+     /*
+      * Use the default connection hostname instead...
+      */
 
-static void
-add_job_uuid(cupsd_client_t *con,      /* I - Client connection */
-             cupsd_job_t    *job)      /* I - Job */
-{
-  char                 uuid[1024];     /* job-uuid string */
-  ipp_attribute_t      *attr;          /* job-uuid attribute */
-  _cups_md5_state_t    md5state;       /* MD5 state */
-  unsigned char                md5sum[16];     /* MD5 digest/sum */
+      attr->value_tag             = IPP_TAG_NAME;
+      attr->num_values            = 1;
+      attr->values[0].string.text = _cups_sp_alloc(con->http.hostname);
+    }
 
+    attr->group_tag = IPP_TAG_JOB;
+  }
+  else
+  {
+   /*
+    * No job-originating-host-name attribute, so use the hostname from
+    * the connection...
+    */
 
- /*
-  * First see if the job already has a job-uuid attribute; if so, return...
-  */
+    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
+                "job-originating-host-name", NULL, con->http.hostname);
+  }
 
-  if ((attr = ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI)) != NULL)
-    return;
+  ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation",
+                time(NULL));
+  attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                       "time-at-processing", 0);
+  attr->value_tag = IPP_TAG_NOVALUE;
+  attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                       "time-at-completed", 0);
+  attr->value_tag = IPP_TAG_NOVALUE;
 
  /*
-  * No job-uuid attribute, so build a version 3 UUID with the local job
-  * ID at the end; see RFC 4122 for details.  Start with the MD5 sum of
-  * the ServerName, server name and port that the client connected to,
-  * and local job ID...
+  * Add remaining job attributes...
   */
 
-  snprintf(uuid, sizeof(uuid), "%s:%s:%d:%d", ServerName, con->servername,
-          con->serverport, job->id);
+  ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
+  job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
+                             "job-state", IPP_JOB_STOPPED);
+  job->state_value = job->state->values[0].integer;
+  job->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,
+               printer->uri);
+  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
+               title);
 
-  _cups_md5_init(&md5state);
-  _cups_md5_append(&md5state, (unsigned char *)uuid, strlen(uuid));
-  _cups_md5_finish(&md5state, md5sum);
+  if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
+                               IPP_TAG_INTEGER)) != NULL)
+    attr->values[0].integer = 0;
+  else
+    attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                         "job-k-octets", 0);
 
- /*
-  * Format the UUID URI using the MD5 sum and job ID.
-  */
-
-  snprintf(uuid, sizeof(uuid),
-           "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
-          "%02x%02x%02x%02x%02x%02x",
-          md5sum[0], md5sum[1], md5sum[2], md5sum[3], md5sum[4], md5sum[5],
-          (md5sum[6] & 15) | 0x30, md5sum[7], (md5sum[8] & 0x3f) | 0x40,
-          md5sum[9], md5sum[10], md5sum[11], md5sum[12], md5sum[13],
-          md5sum[14], md5sum[15]);
-
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uuid", NULL, uuid);
-}
-
-
-/*
- * 'add_printer()' - Add a printer to the system.
- */
-
-static void
-add_printer(cupsd_client_t  *con,      /* I - Client connection */
-            ipp_attribute_t *uri)      /* I - URI of printer */
-{
-  http_status_t        status;                 /* Policy status */
-  int          i;                      /* Looping var */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
-               username[HTTP_MAX_URI], /* Username portion of URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI]; /* Resource portion of URI */
-  int          port;                   /* Port portion of URI */
-  cupsd_printer_t *printer;            /* Printer/class */
-  ipp_attribute_t *attr;               /* Printer attribute */
-  cups_file_t  *fp;                    /* Script/PPD file */
-  char         line[1024];             /* Line from file... */
-  char         srcfile[1024],          /* Source Script/PPD file */
-               dstfile[1024];          /* Destination Script/PPD file */
-  int          modify;                 /* Non-zero if we are modifying */
-  int          need_restart_job;       /* Need to restart job? */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con,
-                  con->http.fd, uri->values[0].string.text);
-
- /*
-  * Do we have a valid URI?
-  */
-
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if (strncmp(resource, "/printers/", 10) || strlen(resource) == 10)
+  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+                               IPP_TAG_KEYWORD)) == NULL)
+    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+  if (!attr)
   {
-   /*
-    * No, return an error...
-    */
+    if ((val = cupsGetOption("job-hold-until", printer->num_options,
+                             printer->options)) == NULL)
+      val = "no-hold";
 
-    send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("The printer-uri must be of the form "
-                     "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
-    return;
+    attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                        "job-hold-until", NULL, val);
   }
-
- /*
-  * Do we have a valid printer name?
-  */
-
-  if (!validate_name(resource + 10))
+  if (attr && strcmp(attr->values[0].string.text, "no-hold") &&
+      !(printer->type & CUPS_PRINTER_REMOTE))
   {
    /*
-    * No, return an error...
+    * Hold job until specified time...
     */
 
-    send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("The printer-uri \"%s\" contains invalid characters."),
-                   uri->values[0].string.text);
-    return;
+    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
   }
-
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+  else if (job->attrs->request.op.operation_id == IPP_CREATE_JOB)
   {
-    send_http_error(con, status);
-    return;
+    job->hold_until = time(NULL) + 60;
+    job->state->values[0].integer = IPP_JOB_HELD;
+    job->state_value              = IPP_JOB_HELD;
+  }
+  else
+  {
+    job->state->values[0].integer = IPP_JOB_PENDING;
+    job->state_value              = IPP_JOB_PENDING;
   }
 
- /*
-  * See if the printer already exists; if not, create a new printer...
-  */
-
-  if ((printer = cupsdFindPrinter(resource + 10)) == NULL)
+  if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
+      Classification)
   {
    /*
-    * Printer doesn't exist; see if we have a class of the same name...
+    * Add job sheets options...
     */
 
-    if ((printer = cupsdFindClass(resource + 10)) != NULL &&
-        !(printer->type & CUPS_PRINTER_REMOTE))
+    if ((attr = ippFindAttribute(job->attrs, "job-sheets",
+                                 IPP_TAG_ZERO)) == NULL)
     {
-     /*
-      * Yes, return an error...
-      */
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                      "Adding default job-sheets values \"%s,%s\"...",
+                      printer->job_sheets[0], printer->job_sheets[1]);
 
-      send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("A class named \"%s\" already exists!"),
-                     resource + 10);
-      return;
+      attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
+                           2, NULL, NULL);
+      attr->values[0].string.text = _cups_sp_alloc(printer->job_sheets[0]);
+      attr->values[1].string.text = _cups_sp_alloc(printer->job_sheets[1]);
     }
 
-   /*
-    * No, add the printer...
-    */
+    job->job_sheets = attr;
 
-    printer = cupsdAddPrinter(resource + 10);
-    modify  = 0;
-  }
-  else if (printer->type & CUPS_PRINTER_IMPLICIT)
-  {
    /*
-    * Rename the implicit printer to "AnyPrinter" or delete it...
+    * Enforce classification level if set...
     */
 
-    if (ImplicitAnyClasses)
+    if (Classification)
     {
-      cupsArrayRemove(Printers, printer);
-      cupsdSetStringf(&printer->name, "Any%s", resource + 10);
-      cupsArrayAdd(Printers, printer);
-    }
-    else
-      cupsdDeletePrinter(printer, 1);
-
-   /*
-    * Add the printer as a new local printer...
-    */
-
-    printer = cupsdAddPrinter(resource + 10);
-    modify  = 0;
-  }
-  else if (printer->type & CUPS_PRINTER_REMOTE)
-  {
-   /*
-    * Rename the remote printer to "Printer@server"...
-    */
-
-    cupsdDeletePrinterFilters(printer);
-    cupsArrayRemove(Printers, printer);
-    cupsdSetStringf(&printer->name, "%s@%s", resource + 10, printer->hostname);
-    cupsdSetPrinterAttrs(printer);
-    cupsArrayAdd(Printers, printer);
-
-   /*
-    * Add the printer as a new local printer...
-    */
-
-    printer = cupsdAddPrinter(resource + 10);
-    modify  = 0;
-  }
-  else
-    modify = 1;
-
- /*
-  * Look for attributes and copy them over as needed...
-  */
-
-  need_restart_job = 0;
-
-  if ((attr = ippFindAttribute(con->request, "printer-location",
-                               IPP_TAG_TEXT)) != NULL)
-    cupsdSetString(&printer->location, attr->values[0].string.text);
-
-  if ((attr = ippFindAttribute(con->request, "printer-info",
-                               IPP_TAG_TEXT)) != NULL)
-    cupsdSetString(&printer->info, attr->values[0].string.text);
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "Classification=\"%s\", ClassifyOverride=%d",
+                      Classification ? Classification : "(null)",
+                     ClassifyOverride);
 
-  if ((attr = ippFindAttribute(con->request, "device-uri",
-                               IPP_TAG_URI)) != NULL)
-  {
-   /*
-    * Do we have a valid device URI?
-    */
+      if (ClassifyOverride)
+      {
+        if (!strcmp(attr->values[0].string.text, "none") &&
+           (attr->num_values == 1 ||
+            !strcmp(attr->values[1].string.text, "none")))
+        {
+        /*
+          * Force the leading banner to have the classification on it...
+         */
 
-    need_restart_job = 1;
+          cupsdSetString(&attr->values[0].string.text, Classification);
 
-    httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
-                    sizeof(method), username, sizeof(username), host,
-                   sizeof(host), &port, resource, sizeof(resource));
+         cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
+                                           "job-sheets=\"%s,none\", "
+                                           "job-originating-user-name=\"%s\"",
+                        job->id, Classification, job->username);
+       }
+       else if (attr->num_values == 2 &&
+                strcmp(attr->values[0].string.text,
+                       attr->values[1].string.text) &&
+                strcmp(attr->values[0].string.text, "none") &&
+                strcmp(attr->values[1].string.text, "none"))
+        {
+        /*
+         * Can't put two different security markings on the same document!
+         */
 
-    if (!strcmp(method, "file"))
-    {
-     /*
-      * See if the administrator has enabled file devices...
-      */
+          cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
 
-      if (!FileDevice && strcmp(resource, "/dev/null"))
+         cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
+                                           "job-sheets=\"%s,%s\", "
+                                           "job-originating-user-name=\"%s\"",
+                        job->id, attr->values[0].string.text,
+                        attr->values[1].string.text, job->username);
+       }
+       else if (strcmp(attr->values[0].string.text, Classification) &&
+                strcmp(attr->values[0].string.text, "none") &&
+                (attr->num_values == 1 ||
+                 (strcmp(attr->values[1].string.text, Classification) &&
+                  strcmp(attr->values[1].string.text, "none"))))
+        {
+         if (attr->num_values == 1)
+            cupsdLogMessage(CUPSD_LOG_NOTICE,
+                           "[Job %d] CLASSIFICATION OVERRIDDEN "
+                           "job-sheets=\"%s\", "
+                           "job-originating-user-name=\"%s\"",
+                      job->id, attr->values[0].string.text, job->username);
+          else
+            cupsdLogMessage(CUPSD_LOG_NOTICE,
+                           "[Job %d] CLASSIFICATION OVERRIDDEN "
+                           "job-sheets=\"%s,%s\",fffff "
+                           "job-originating-user-name=\"%s\"",
+                           job->id, attr->values[0].string.text,
+                           attr->values[1].string.text, job->username);
+        }
+      }
+      else if (strcmp(attr->values[0].string.text, Classification) &&
+               (attr->num_values == 1 ||
+              strcmp(attr->values[1].string.text, Classification)))
       {
        /*
-        * File devices are disabled and the URL is not file:/dev/null...
+        * Force the banner to have the classification on it...
        */
 
-       send_ipp_status(con, IPP_NOT_POSSIBLE,
-                       _("File device URIs have been disabled! "
-                         "To enable, see the FileDevice directive in "
-                         "\"%s/cupsd.conf\"."),
-                       ServerRoot);
-       return;
-      }
-    }
-    else
-    {
-     /*
-      * See if the backend exists and is executable...
-      */
+        if (attr->num_values > 1 &&
+           !strcmp(attr->values[0].string.text, attr->values[1].string.text))
+       {
+          cupsdSetString(&(attr->values[0].string.text), Classification);
+          cupsdSetString(&(attr->values[1].string.text), Classification);
+       }
+        else
+       {
+          if (attr->num_values == 1 ||
+             strcmp(attr->values[0].string.text, "none"))
+            cupsdSetString(&(attr->values[0].string.text), Classification);
 
-      snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, method);
-      if (access(srcfile, X_OK))
-      {
-       /*
-        * Could not find device in list!
-       */
+          if (attr->num_values > 1 &&
+             strcmp(attr->values[1].string.text, "none"))
+            cupsdSetString(&(attr->values[1].string.text), Classification);
+        }
 
-       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
-                       attr->values[0].string.text);
-       return;
+        if (attr->num_values > 1)
+         cupsdLogMessage(CUPSD_LOG_NOTICE,
+                         "[Job %d] CLASSIFICATION FORCED "
+                         "job-sheets=\"%s,%s\", "
+                         "job-originating-user-name=\"%s\"",
+                         job->id, attr->values[0].string.text,
+                         attr->values[1].string.text, job->username);
+        else
+         cupsdLogMessage(CUPSD_LOG_NOTICE,
+                         "[Job %d] CLASSIFICATION FORCED "
+                         "job-sheets=\"%s\", "
+                         "job-originating-user-name=\"%s\"",
+                        job->id, Classification, job->username);
       }
     }
 
-    cupsdLogMessage(CUPSD_LOG_INFO,
-                    "Setting %s device-uri to \"%s\" (was \"%s\".)",
-                   printer->name,
-                   cupsdSanitizeURI(attr->values[0].string.text, line,
-                                    sizeof(line)),
-                   cupsdSanitizeURI(printer->device_uri, resource,
-                                    sizeof(resource)));
-
-    cupsdSetString(&printer->device_uri, attr->values[0].string.text);
-  }
-
-  if ((attr = ippFindAttribute(con->request, "port-monitor",
-                               IPP_TAG_KEYWORD)) != NULL)
-  {
-    ipp_attribute_t    *supported;     /* port-monitor-supported attribute */
-
-
-    need_restart_job = 1;
-
-    supported = ippFindAttribute(printer->attrs, "port-monitor-supported",
-                                 IPP_TAG_KEYWORD);
-    for (i = 0; i < supported->num_values; i ++)
-      if (!strcmp(supported->values[i].string.text,
-                  attr->values[0].string.text))
-        break;
+   /*
+    * See if we need to add the starting sheet...
+    */
 
-    if (i >= supported->num_values)
+    if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
     {
-      send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
-                     attr->values[0].string.text);
-      return;
-    }
-
-    cupsdLogMessage(CUPSD_LOG_INFO,
-                    "Setting %s port-monitor to \"%s\" (was \"%s\".)",
-                    printer->name, attr->values[0].string.text,
-                   printer->port_monitor);
-
-    if (strcmp(attr->values[0].string.text, "none"))
-      cupsdSetString(&printer->port_monitor, attr->values[0].string.text);
-    else
-      cupsdClearString(&printer->port_monitor);
-  }
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "Adding start banner page \"%s\" to job %d.",
+                      attr->values[0].string.text, job->id);
 
-  if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
-                               IPP_TAG_BOOLEAN)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_INFO,
-                    "Setting %s printer-is-accepting-jobs to %d (was %d.)",
-                    printer->name, attr->values[0].boolean, printer->accepting);
+      kbytes = copy_banner(con, job, attr->values[0].string.text);
 
-    printer->accepting = attr->values[0].boolean;
-    cupsdAddPrinterHistory(printer);
+      cupsdUpdateQuota(printer, job->username, 0, kbytes);
+    }
   }
+  else if ((attr = ippFindAttribute(job->attrs, "job-sheets",
+                                    IPP_TAG_ZERO)) != NULL)
+    job->sheets = attr;
 
-  if ((attr = ippFindAttribute(con->request, "printer-is-shared",
-                               IPP_TAG_BOOLEAN)) != NULL)
-  {
-    if (printer->shared && !attr->values[0].boolean)
-      cupsdSendBrowseDelete(printer);
-
-    cupsdLogMessage(CUPSD_LOG_INFO,
-                    "Setting %s printer-is-shared to %d (was %d.)",
-                    printer->name, attr->values[0].boolean, printer->shared);
+ /*
+  * Fill in the response info...
+  */
 
-    printer->shared = attr->values[0].boolean;
-  }
+  snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
+          LocalPort, job->id);
 
-  if ((attr = ippFindAttribute(con->request, "printer-state",
-                               IPP_TAG_ENUM)) != NULL)
-  {
-    if (attr->values[0].integer != IPP_PRINTER_IDLE &&
-        attr->values[0].integer != IPP_PRINTER_STOPPED)
-    {
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad printer-state value %d!"),
-                      attr->values[0].integer);
-      return;
-    }
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
+               job_uri);
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)", printer->name,
-               attr->values[0].integer, printer->state);
+  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
 
-    if (attr->values[0].integer == IPP_PRINTER_STOPPED)
-      cupsdStopPrinter(printer, 0);
-    else
-    {
-      need_restart_job = 1;
-      cupsdSetPrinterState(printer, (ipp_pstate_t)(attr->values[0].integer), 0);
-    }
-  }
-  if ((attr = ippFindAttribute(con->request, "printer-state-message",
-                               IPP_TAG_TEXT)) != NULL)
-  {
-    strlcpy(printer->state_message, attr->values[0].string.text,
-            sizeof(printer->state_message));
-    cupsdAddPrinterHistory(printer);
-  }
-  if ((attr = ippFindAttribute(con->request, "job-sheets-default",
-                               IPP_TAG_ZERO)) != NULL &&
-      !Classification)
-  {
-    cupsdSetString(&printer->job_sheets[0], attr->values[0].string.text);
-    if (attr->num_values > 1)
-      cupsdSetString(&printer->job_sheets[1], attr->values[1].string.text);
-    else
-      cupsdSetString(&printer->job_sheets[1], "none");
-  }
-  if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
-                               IPP_TAG_ZERO)) != NULL)
-  {
-    cupsdFreePrinterUsers(printer);
+  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
+                job->state_value);
+  add_job_state_reasons(con, job);
 
-    printer->deny_users = 0;
-    if (attr->value_tag == IPP_TAG_NAME &&
-        (attr->num_values > 1 ||
-        strcmp(attr->values[0].string.text, "all")))
-      for (i = 0; i < attr->num_values; i ++)
-       cupsdAddPrinterUser(printer, attr->values[i].string.text);
-  }
-  else if ((attr = ippFindAttribute(con->request, "requesting-user-name-denied",
-                                    IPP_TAG_ZERO)) != NULL)
-  {
-    cupsdFreePrinterUsers(printer);
+  con->response->request.status.status_code = IPP_OK;
 
-    printer->deny_users = 1;
-    if (attr->value_tag == IPP_TAG_NAME &&
-        (attr->num_values > 1 ||
-        strcmp(attr->values[0].string.text, "none")))
-      for (i = 0; i < attr->num_values; i ++)
-       cupsdAddPrinterUser(printer, attr->values[i].string.text);
-  }
-  if ((attr = ippFindAttribute(con->request, "job-quota-period",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-quota-period to %d...",
-               attr->values[0].integer);
-    cupsdFreeQuotas(printer);
-    printer->quota_period = attr->values[0].integer;
-  }
-  if ((attr = ippFindAttribute(con->request, "job-k-limit",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-k-limit to %d...",
-               attr->values[0].integer);
-    cupsdFreeQuotas(printer);
-    printer->k_limit = attr->values[0].integer;
-  }
-  if ((attr = ippFindAttribute(con->request, "job-page-limit",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-page-limit to %d...",
-               attr->values[0].integer);
-    cupsdFreeQuotas(printer);
-    printer->page_limit = attr->values[0].integer;
-  }
-  if ((attr = ippFindAttribute(con->request, "printer-op-policy",
-                               IPP_TAG_NAME)) != NULL)
-  {
-    cupsd_policy_t *p;                 /* Policy */
+ /*
+  * Add any job subscriptions...
+  */
 
+  add_job_subscriptions(con, job);
 
-    if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
-                      "Setting printer-op-policy to \"%s\"...",
-                      attr->values[0].string.text);
-      cupsdSetString(&printer->op_policy, attr->values[0].string.text);
-      printer->op_policy_ptr = p;
-    }
-    else
-    {
-      send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("Unknown printer-op-policy \"%s\"."),
-                      attr->values[0].string.text);
-      return;
-    }
-  }
-  if ((attr = ippFindAttribute(con->request, "printer-error-policy",
-                               IPP_TAG_NAME)) != NULL)
-  {
-    if (strcmp(attr->values[0].string.text, "abort-job") &&
-        strcmp(attr->values[0].string.text, "retry-job") &&
-        strcmp(attr->values[0].string.text, "stop-printer"))
-    {
-      send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("Unknown printer-error-policy \"%s\"."),
-                      attr->values[0].string.text);
-      return;
-    }
+ /*
+  * Set all but the first two attributes to the job attributes group...
+  */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "Setting printer-error-policy to \"%s\"...",
-                    attr->values[0].string.text);
-    cupsdSetString(&printer->error_policy, attr->values[0].string.text);
-  }
+  for (attr = job->attrs->attrs->next->next; attr; attr = attr->next)
+    attr->group_tag = IPP_TAG_JOB;
 
  /*
-  * See if we have all required attributes...
+  * Fire the "job created" event...
   */
 
-  if (!printer->device_uri)
-    cupsdSetString(&printer->device_uri, "file:///dev/null");
+  cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created.");
 
  /*
-  * See if we have an interface script or PPD file attached to the request...
+  * Return the new job...
   */
 
-  if (con->filename)
-  {
-    need_restart_job = 1;
-
-    strlcpy(srcfile, con->filename, sizeof(srcfile));
+  return (job);
+}
 
-    if ((fp = cupsFileOpen(srcfile, "rb")))
-    {
-     /*
-      * Yes; get the first line from it...
-      */
 
-      line[0] = '\0';
-      cupsFileGets(fp, line, sizeof(line));
-      cupsFileClose(fp);
+/*
+ * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
+ *                             upon the job and printer state...
+ */
 
-     /*
-      * Then see what kind of file it is...
-      */
+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 */
 
-      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
-               printer->name);
 
-      if (!strncmp(line, "*PPD-Adobe", 10))
-      {
-       /*
-       * The new file is a PPD file, so remove any old interface script
-       * that might be lying around...
-       */
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job_state_reasons(%p[%d], %d)",
+                  con, con->http.fd, job ? job->id : 0);
 
-       unlink(dstfile);
-      }
-      else
-      {
-       /*
-       * This must be an interface script, so move the file over to the
-       * interfaces directory and make it executable...
-       */
-
-       if (copy_file(srcfile, dstfile))
-       {
-          send_ipp_status(con, IPP_INTERNAL_ERROR,
-                         _("Unable to copy interface script - %s!"),
-                         strerror(errno));
-         return;
-       }
-       else
-       {
-          cupsdLogMessage(CUPSD_LOG_DEBUG,
-                         "Copied interface script successfully!");
-          chmod(dstfile, 0755);
-       }
-      }
-
-      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
-               printer->name);
-
-      if (!strncmp(line, "*PPD-Adobe", 10))
-      {
-       /*
-       * The new file is a PPD file, so move the file over to the
-       * ppd directory and make it readable by all...
-       */
-
-       if (copy_file(srcfile, dstfile))
-       {
-          send_ipp_status(con, IPP_INTERNAL_ERROR,
-                         _("Unable to copy PPD file - %s!"),
-                         strerror(errno));
-         return;
-       }
-       else
-       {
-          cupsdLogMessage(CUPSD_LOG_DEBUG,
-                         "Copied PPD file successfully!");
-          chmod(dstfile, 0644);
-       }
-      }
-      else
-      {
-       /*
-       * This must be an interface script, so remove any old PPD file that
-       * may be lying around...
-       */
-
-       unlink(dstfile);
-      }
-    }
-  }
-  else if ((attr = ippFindAttribute(con->request, "ppd-name",
-                                    IPP_TAG_NAME)) != NULL)
-  {
-    need_restart_job = 1;
-
-    if (!strcmp(attr->values[0].string.text, "raw"))
-    {
-     /*
-      * Raw driver, remove any existing PPD or interface script files.
-      */
-
-      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
-               printer->name);
-      unlink(dstfile);
-
-      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
-               printer->name);
-      unlink(dstfile);
-    }
-    else
-    {
-     /*
-      * PPD model file...
-      */
-
-      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
-               printer->name);
-      unlink(dstfile);
-
-      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
-               printer->name);
-
-      if (copy_model(con, attr->values[0].string.text, dstfile))
-      {
-        send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file!"));
-       return;
-      }
-      else
-      {
-        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                       "Copied PPD file successfully!");
-        chmod(dstfile, 0644);
-      }
-    }
-  }
-
- /*
-  * Update the printer attributes and return...
-  */
-
-  cupsdSetPrinterAttrs(printer);
-  cupsdSaveAllPrinters();
-
-  if (need_restart_job && printer->job)
+  switch (job ? job->state_value : IPP_JOB_CANCELLED)
   {
-    cupsd_job_t *job;
-
-   /*
-    * Stop the current job and then restart it below...
-    */
-
-    job = (cupsd_job_t *)printer->job;
-
-    cupsdStopJob(job, 1);
+    case IPP_JOB_PENDING :
+        if (job->dtype & CUPS_PRINTER_CLASS)
+         dest = cupsdFindClass(job->dest);
+       else
+         dest = cupsdFindPrinter(job->dest);
 
-    job->state->values[0].integer = IPP_JOB_PENDING;
-    job->state_value              = IPP_JOB_PENDING;
-  }
+        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;
 
-  if (need_restart_job)
-    cupsdCheckJobs();
+    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;
 
-  cupsdWritePrintcap();
+    case IPP_JOB_PROCESSING :
+        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                    "job-state-reasons", NULL, "job-printing");
+        break;
 
-  if (modify)
-  {
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Printer \"%s\" modified by \"%s\".", printer->name,
-                 get_username(con));
+    case IPP_JOB_STOPPED :
+        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                    "job-state-reasons", NULL, "job-stopped");
+        break;
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".",
-                    printer->name, get_username(con));
-  }
-  else
-  {
-    cupsdAddPrinterHistory(printer);
+    case IPP_JOB_CANCELLED :
+        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                    "job-state-reasons", NULL, "job-canceled-by-user");
+        break;
 
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, printer, NULL,
-                  "New printer \"%s\" added by \"%s\".", printer->name,
-                 get_username(con));
+    case IPP_JOB_ABORTED :
+        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                    "job-state-reasons", NULL, "aborted-by-system");
+        break;
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".",
-                    printer->name, get_username(con));
+    case IPP_JOB_COMPLETED :
+        ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                    "job-state-reasons", NULL, "job-completed-successfully");
+        break;
   }
-
-  con->response->request.status.status_code = IPP_OK;
 }
 
 
 /*
- * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
- *                                 based upon the printer state...
+ * 'add_job_subscriptions()' - Add any subcriptions for a job.
  */
 
 static void
-add_printer_state_reasons(
-    cupsd_client_t  *con,              /* I - Client connection */
-    cupsd_printer_t *p)                        /* I - Printer info */
+add_job_subscriptions(
+    cupsd_client_t *con,               /* I - Client connection */
+    cupsd_job_t    *job)               /* I - Newly created job */
 {
-  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,
-                p->state == IPP_PRINTER_STOPPED ? "paused" : "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.
- */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *prev,          /* Previous attribute */
+                       *next,          /* Next attribute */
+                       *attr;          /* Current attribute */
+  cupsd_subscription_t *sub;           /* Subscription object */
+  const char           *recipient,     /* notify-recipient-uri */
+                       *pullmethod;    /* notify-pull-method */
+  ipp_attribute_t      *user_data;     /* notify-user-data */
+  int                  interval;       /* notify-time-interval */
+  unsigned             mask;           /* notify-events */
 
-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 */
 
+ /*
+  * Find the first subscription group attribute; return if we have
+  * none...
+  */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])",
-                  con, con->http.fd, p, p->name);
+  for (attr = job->attrs->attrs, prev = NULL;
+       attr;
+       prev = attr, attr = attr->next)
+    if (attr->group_tag == IPP_TAG_SUBSCRIPTION)
+      break;
 
-  count = cupsdGetPrinterJobCount(p->name);
+  if (!attr)
+    return;
 
-  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                "queued-job-count", count);
-}
+ /*
+  * Process the subscription attributes in the request...
+  */
 
+  while (attr)
+  {
+    recipient = NULL;
+    pullmethod = NULL;
+    user_data  = NULL;
+    interval   = 0;
+    mask       = CUPSD_EVENT_NONE;
 
-/*
- * 'authenticate_job()' - Set job authentication info.
- */
+    while (attr && attr->group_tag != IPP_TAG_ZERO)
+    {
+      if (!strcmp(attr->name, "notify-recipient") &&
+          attr->value_tag == IPP_TAG_URI)
+        recipient = attr->values[0].string.text;
+      else if (!strcmp(attr->name, "notify-pull-method") &&
+               attr->value_tag == IPP_TAG_KEYWORD)
+        pullmethod = attr->values[0].string.text;
+      else if (!strcmp(attr->name, "notify-charset") &&
+               attr->value_tag == IPP_TAG_CHARSET &&
+              strcmp(attr->values[0].string.text, "us-ascii") &&
+              strcmp(attr->values[0].string.text, "utf-8"))
+      {
+        send_ipp_status(con, IPP_CHARSET,
+                       _("Character set \"%s\" not supported!"),
+                       attr->values[0].string.text);
+       return;
+      }
+      else if (!strcmp(attr->name, "notify-natural-language") &&
+               (attr->value_tag != IPP_TAG_LANGUAGE ||
+               strcmp(attr->values[0].string.text, DefaultLanguage)))
+      {
+        send_ipp_status(con, IPP_CHARSET,
+                       _("Language \"%s\" not supported!"),
+                       attr->values[0].string.text);
+       return;
+      }
+      else if (!strcmp(attr->name, "notify-user-data") &&
+               attr->value_tag == IPP_TAG_STRING)
+      {
+        if (attr->num_values > 1 || attr->values[0].unknown.length > 63)
+       {
+          send_ipp_status(con, IPP_REQUEST_VALUE,
+                         _("The notify-user-data value is too large "
+                           "(%d > 63 octets)!"),
+                         attr->values[0].unknown.length);
+         return;
+       }
 
-static void
-authenticate_job(cupsd_client_t  *con, /* I - Client connection */
-                ipp_attribute_t *uri)  /* I - Job URI */
-{
-  ipp_attribute_t      *attr;          /* Job-id attribute */
-  int                  jobid;          /* Job ID */
-  cupsd_job_t          *job;           /* Current job */
-  char                 method[HTTP_MAX_URI],
-                                       /* Method portion of URI */
-                       username[HTTP_MAX_URI],
-                                       /* Username portion of URI */
-                       host[HTTP_MAX_URI],
-                                       /* Host portion of URI */
-                       resource[HTTP_MAX_URI];
-                                       /* Resource portion of URI */
-  int                  port;           /* Port portion of URI */
+        user_data = attr;
+      }
+      else if (!strcmp(attr->name, "notify-events") &&
+               attr->value_tag == IPP_TAG_KEYWORD)
+      {
+        for (i = 0; i < attr->num_values; i ++)
+         mask |= cupsdEventValue(attr->values[i].string.text);
+      }
+      else if (!strcmp(attr->name, "notify-lease-duration"))
+      {
+        send_ipp_status(con, IPP_BAD_REQUEST,
+                       _("The notify-lease-duration attribute cannot be "
+                         "used with job subscriptions."));
+       return;
+      }
+      else if (!strcmp(attr->name, "notify-time-interval") &&
+               attr->value_tag == IPP_TAG_INTEGER)
+        interval = attr->values[0].integer;
 
+      attr = attr->next;
+    }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "authenticate_job(%p[%d], %s)",
-                  con, con->http.fd, uri->values[0].string.text);
+    if (!recipient && !pullmethod)
+      break;
 
- /*
-  * Start with "everything is OK" status...
-  */
+    if (mask == CUPSD_EVENT_NONE)
+      mask = CUPSD_EVENT_JOB_COMPLETED;
 
-  con->response->request.status.status_code = IPP_OK;
+    sub = cupsdAddSubscription(mask, cupsdFindDest(job->dest), job, recipient,
+                               0);
 
- /*
-  * See if we have a job URI or a printer URI...
-  */
+    sub->interval = interval;
 
-  if (!strcmp(uri->name, "printer-uri"))
-  {
-   /*
-    * Got a printer URI; see if we also have a job-id attribute...
-    */
+    cupsdSetString(&sub->owner, job->username);
 
-    if ((attr = ippFindAttribute(con->request, "job-id",
-                                 IPP_TAG_INTEGER)) == NULL)
+    if (user_data)
     {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
-      return;
+      sub->user_data_len = user_data->values[0].unknown.length;
+      memcpy(sub->user_data, user_data->values[0].unknown.data,
+             sub->user_data_len);
     }
 
-    jobid = attr->values[0].integer;
-  }
-  else
-  {
-   /*
-    * Got a job URI; parse it to get the job ID...
-    */
-
-    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                    sizeof(method), username, sizeof(username), host,
-                   sizeof(host), &port, resource, sizeof(resource));
-    if (strncmp(resource, "/jobs/", 6))
-    {
-     /*
-      * Not a valid URI!
-      */
-
-      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-uri attribute \"%s\"!"),
-                      uri->values[0].string.text);
-      return;
-    }
+    ippAddSeparator(con->response);
+    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                  "notify-subscription-id", sub->id);
 
-    jobid = atoi(resource + 6);
+    if (attr)
+      attr = attr->next;
   }
 
+  cupsdSaveAllSubscriptions();
+
  /*
-  * See if the job exists...
+  * Remove all of the subscription attributes from the job request...
   */
 
-  if ((job = cupsdFindJob(jobid)) == NULL)
+  for (attr = job->attrs->attrs, prev = NULL; attr; attr = next)
   {
-   /*
-    * Nope - return a "not found" error...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("Job #%d does not exist!"), jobid);
-    return;
-  }
+    next = attr->next;
 
- /*
-  * See if the job has been completed...
-  */
+    if (attr->group_tag == IPP_TAG_SUBSCRIPTION ||
+        attr->group_tag == IPP_TAG_ZERO)
+    {
+     /*
+      * Free and remove this attribute...
+      */
 
-  if (job->state_value != IPP_JOB_HELD)
-  {
-   /*
-    * Return a "not-possible" error...
-    */
+      _ipp_free_attr(attr);
 
-    send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Job #%d is not held for authentication!"),
-                   jobid);
-    return;
+      if (prev)
+        prev->next = next;
+      else
+        job->attrs->attrs = next;
+    }
+    else
+      prev = attr;
   }
 
- /*
-  * See if we have already authenticated...
-  */
+  job->attrs->last    = prev;
+  job->attrs->current = prev;
+}
 
-  if (!con->username[0])
-  {
-    send_ipp_status(con, IPP_NOT_AUTHORIZED,
-                    _("No authentication information provided!"));
-    return;
-  }
 
- /*
-  * See if the job is owned by the requesting user...
-  */
+/*
+ * 'add_job_uuid()' - Add job-uuid attribute to a job.
+ *
+ * See RFC 4122 for the definition of UUIDs and the format.
+ */
+
+static void
+add_job_uuid(cupsd_client_t *con,      /* I - Client connection */
+             cupsd_job_t    *job)      /* I - Job */
+{
+  char                 uuid[1024];     /* job-uuid string */
+  ipp_attribute_t      *attr;          /* job-uuid attribute */
+  _cups_md5_state_t    md5state;       /* MD5 state */
+  unsigned char                md5sum[16];     /* MD5 digest/sum */
 
-  if (!validate_user(job, con, job->username, username, sizeof(username)))
-  {
-    send_http_error(con, HTTP_UNAUTHORIZED);
-    return;
-  }
 
  /*
-  * Save the authentication information for this job...
+  * First see if the job already has a job-uuid attribute; if so, return...
   */
 
-  save_auth_info(con, job);
+  if ((attr = ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI)) != NULL)
+    return;
 
  /*
-  * Reset the job-hold-until value to "no-hold"...
+  * No job-uuid attribute, so build a version 3 UUID with the local job
+  * ID at the end; see RFC 4122 for details.  Start with the MD5 sum of
+  * the ServerName, server name and port that the client connected to,
+  * and local job ID...
   */
 
-  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
-                               IPP_TAG_KEYWORD)) == NULL)
-    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+  snprintf(uuid, sizeof(uuid), "%s:%s:%d:%d", ServerName, con->servername,
+          con->serverport, job->id);
 
-  if (attr)
-  {
-    attr->value_tag = IPP_TAG_KEYWORD;
-    cupsdSetString(&(attr->values[0].string.text), "no-hold");
-  }
+  _cups_md5_init(&md5state);
+  _cups_md5_append(&md5state, (unsigned char *)uuid, strlen(uuid));
+  _cups_md5_finish(&md5state, md5sum);
 
  /*
-  * Release the job and return...
+  * Format the UUID URI using the MD5 sum and job ID.
   */
 
-  cupsdReleaseJob(job);
+  snprintf(uuid, sizeof(uuid),
+           "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
+          "%02x%02x%02x%02x%02x%02x",
+          md5sum[0], md5sum[1], md5sum[2], md5sum[3], md5sum[4], md5sum[5],
+          (md5sum[6] & 15) | 0x30, md5sum[7], (md5sum[8] & 0x3f) | 0x40,
+          md5sum[9], md5sum[10], md5sum[11], md5sum[12], md5sum[13],
+          md5sum[14], md5sum[15]);
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was authenticated by \"%s\".", jobid,
-                  con->username);
+  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uuid", NULL, uuid);
 }
 
 
 /*
- * 'cancel_all_jobs()' - Cancel all print jobs.
+ * 'add_printer()' - Add a printer to the system.
  */
 
 static void
-cancel_all_jobs(cupsd_client_t  *con,  /* I - Client connection */
-               ipp_attribute_t *uri)   /* I - Job or Printer URI */
+add_printer(cupsd_client_t  *con,      /* I - Client connection */
+            ipp_attribute_t *uri)      /* I - URI of printer */
 {
   http_status_t        status;                 /* Policy status */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type */
+  int          i;                      /* Looping var */
   char         method[HTTP_MAX_URI],   /* Method portion of URI */
-               userpass[HTTP_MAX_URI], /* Username portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
-  ipp_attribute_t *attr;               /* Attribute in request */
-  const char   *username;              /* Username */
-  int          purge;                  /* Purge? */
-  cupsd_printer_t *printer;            /* Printer */
+  cupsd_printer_t *printer;            /* Printer/class */
+  ipp_attribute_t *attr;               /* Printer attribute */
+  cups_file_t  *fp;                    /* Script/PPD file */
+  char         line[1024];             /* Line from file... */
+  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          need_restart_job;       /* Need to restart job? */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_all_jobs(%p[%d], %s)", con,
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con,
                   con->http.fd, uri->values[0].string.text);
 
  /*
-  * See if we have a printer URI...
+  * Do we have a valid URI?
   */
 
-  if (strcmp(uri->name, "printer-uri"))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if (strncmp(resource, "/printers/", 10) || strlen(resource) == 10)
   {
+   /*
+    * No, return an error...
+    */
+
     send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("The printer-uri attribute is required!"));
+                    _("The printer-uri must be of the form "
+                     "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
     return;
   }
 
  /*
-  * Get the username (if any) for the jobs we want to cancel (only if
-  * "my-jobs" is specified...
+  * Do we have a valid printer name?
   */
 
-  if ((attr = ippFindAttribute(con->request, "my-jobs",
-                               IPP_TAG_BOOLEAN)) != NULL &&
-      attr->values[0].boolean)
+  if (!validate_name(resource + 10))
   {
-    if ((attr = ippFindAttribute(con->request, "requesting-user-name",
-                                 IPP_TAG_NAME)) != NULL)
-      username = attr->values[0].string.text;
-    else
-    {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Missing requesting-user-name attribute!"));
-      return;
-    }
+   /*
+    * No, return an error...
+    */
+
+    send_ipp_status(con, IPP_BAD_REQUEST,
+                    _("The printer-uri \"%s\" contains invalid characters."),
+                   uri->values[0].string.text);
+    return;
   }
-  else
-    username = NULL;
 
  /*
-  * Look for the "purge-jobs" attribute...
+  * Check policy...
   */
 
-  if ((attr = ippFindAttribute(con->request, "purge-jobs",
-                               IPP_TAG_BOOLEAN)) != NULL)
-    purge = attr->values[0].boolean;
-  else
-    purge = 1;
+  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+  {
+    send_http_error(con, status);
+    return;
+  }
 
  /*
-  * And if the destination is valid...
-  */
-
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), userpass, sizeof(userpass), host,
-                 sizeof(host), &port, resource, sizeof(resource));
+  * See if the printer already exists; if not, create a new printer...
+  */
 
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if ((printer = cupsdFindPrinter(resource + 10)) == NULL)
   {
    /*
-    * Bad URI?
+    * Printer doesn't exist; see if we have a class of the same name...
     */
 
-    if ((!strncmp(resource, "/printers/", 10) && resource[10]) ||
-        (!strncmp(resource, "/classes/", 9) && resource[9]))
-    {
-      send_ipp_status(con, IPP_NOT_FOUND,
-                      _("The printer or class was not found."));
-      return;
-    }
-    else if (strcmp(resource, "/printers/"))
+    if ((printer = cupsdFindClass(resource + 10)) != NULL &&
+        !(printer->type & CUPS_PRINTER_REMOTE))
     {
-      send_ipp_status(con, IPP_NOT_FOUND,
-                      _("The printer-uri \"%s\" is not valid."),
-                     uri->values[0].string.text);
-      return;
-    }
-
-   /*
-    * Check policy...
-    */
+     /*
+      * Yes, return an error...
+      */
 
-    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
-    {
-      send_http_error(con, status);
+      send_ipp_status(con, IPP_NOT_POSSIBLE,
+                      _("A class named \"%s\" already exists!"),
+                     resource + 10);
       return;
     }
 
    /*
-    * Cancel all jobs on all printers...
+    * No, add the printer...
     */
 
-    cupsdCancelJobs(NULL, username, purge);
-
-    cupsdLogMessage(CUPSD_LOG_INFO, "All jobs were %s by \"%s\".",
-                    purge ? "purged" : "cancelled", get_username(con));
+    printer = cupsdAddPrinter(resource + 10);
+    modify  = 0;
   }
-  else
+  else if (printer->type & CUPS_PRINTER_IMPLICIT)
   {
    /*
-    * Check policy...
+    * Rename the implicit printer to "AnyPrinter" or delete it...
     */
 
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+    if (ImplicitAnyClasses)
     {
-      send_http_error(con, status);
-      return;
+      snprintf(newname, sizeof(newname), "Any%s", resource + 10);
+      cupsdRenamePrinter(printer, newname);
     }
+    else
+      cupsdDeletePrinter(printer, 1);
 
    /*
-    * Cancel all of the jobs on the named printer...
+    * Add the printer as a new local printer...
     */
 
-    cupsdCancelJobs(dest, username, purge);
-
-    cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
-                    dest, purge ? "purged" : "cancelled", get_username(con));
+    printer = cupsdAddPrinter(resource + 10);
+    modify  = 0;
   }
+  else if (printer->type & CUPS_PRINTER_REMOTE)
+  {
+   /*
+    * Rename the remote printer to "Printer@server"...
+    */
 
-  con->response->request.status.status_code = IPP_OK;
-}
+    snprintf(newname, sizeof(newname), "%s@%s", resource + 10,
+             printer->hostname);
+    cupsdRenamePrinter(printer, newname);
 
+   /*
+    * Add the printer as a new local printer...
+    */
 
-/*
- * 'cancel_job()' - Cancel a print job.
- */
+    printer = cupsdAddPrinter(resource + 10);
+    modify  = 0;
+  }
+  else
+    modify = 1;
 
-static void
-cancel_job(cupsd_client_t  *con,       /* I - Client connection */
-          ipp_attribute_t *uri)        /* I - Job or Printer URI */
-{
-  ipp_attribute_t *attr;               /* Current attribute */
-  int          jobid;                  /* Job ID */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
-               username[HTTP_MAX_URI], /* Username portion of URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI]; /* Resource portion of URI */
-  int          port;                   /* Port portion of URI */
-  cupsd_job_t  *job;                   /* Job information */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
-  cupsd_printer_t *printer;            /* Printer data */
+ /*
+  * Look for attributes and copy them over as needed...
+  */
 
+  need_restart_job = 0;
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con,
-                  con->http.fd, uri->values[0].string.text);
+  if ((attr = ippFindAttribute(con->request, "printer-location",
+                               IPP_TAG_TEXT)) != NULL)
+    cupsdSetString(&printer->location, attr->values[0].string.text);
 
- /*
-  * See if we have a job URI or a printer URI...
-  */
+  if ((attr = ippFindAttribute(con->request, "printer-info",
+                               IPP_TAG_TEXT)) != NULL)
+    cupsdSetString(&printer->info, attr->values[0].string.text);
 
-  if (!strcmp(uri->name, "printer-uri"))
+  if ((attr = ippFindAttribute(con->request, "device-uri",
+                               IPP_TAG_URI)) != NULL)
   {
    /*
-    * Got a printer URI; see if we also have a job-id attribute...
+    * Do we have a valid device URI?
     */
 
-    if ((attr = ippFindAttribute(con->request, "job-id",
-                                 IPP_TAG_INTEGER)) == NULL)
-    {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
-      return;
-    }
+    need_restart_job = 1;
 
-    if ((jobid = attr->values[0].integer) == 0)
+    httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
+                    sizeof(method), username, sizeof(username), host,
+                   sizeof(host), &port, resource, sizeof(resource));
+
+    if (!strcmp(method, "file"))
     {
      /*
-      * Find the current job on the specified printer...
+      * See if the administrator has enabled file devices...
       */
 
-      httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                      sizeof(method), username, sizeof(username), host,
-                     sizeof(host), &port, resource, sizeof(resource));
-
-      if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+      if (!FileDevice && strcmp(resource, "/dev/null"))
       {
        /*
-       * Bad URI...
+        * File devices are disabled and the URL is not file:/dev/null...
        */
 
-       send_ipp_status(con, IPP_NOT_FOUND,
-                       _("The printer or class was not found."));
+       send_ipp_status(con, IPP_NOT_POSSIBLE,
+                       _("File device URIs have been disabled! "
+                         "To enable, see the FileDevice directive in "
+                         "\"%s/cupsd.conf\"."),
+                       ServerRoot);
        return;
       }
-
+    }
+    else
+    {
      /*
-      * See if the printer is currently printing a job...
+      * See if the backend exists and is executable...
       */
 
-      if (printer->job)
-        jobid = ((cupsd_job_t *)printer->job)->id;
-      else
+      snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, method);
+      if (access(srcfile, X_OK))
       {
        /*
-        * No, see if there are any pending jobs...
+        * Could not find device in list!
        */
-        
-        for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
-            job;
-            job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
-         if (job->state_value <= IPP_JOB_PROCESSING &&
-             !strcasecmp(job->dest, dest))
-           break;
 
-       if (job)
-         jobid = job->id;
-       else
-       {
-         send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s!"),
-                         dest);
-         return;
-       }
+       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
+                       attr->values[0].string.text);
+       return;
       }
     }
-  }
-  else
-  {
-   /*
-    * Got a job URI; parse it to get the job ID...
-    */
-
-    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                    sizeof(method), username, sizeof(username), host,
-                   sizeof(host), &port, resource, sizeof(resource));
-    if (strncmp(resource, "/jobs/", 6))
-    {
-     /*
-      * Not a valid URI!
-      */
-
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
-                      uri->values[0].string.text);
-      return;
-    }
-
-    jobid = atoi(resource + 6);
-  }
-
- /*
-  * See if the job exists...
-  */
-
-  if ((job = cupsdFindJob(jobid)) == NULL)
-  {
-   /*
-    * Nope - return a "not found" error...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
-    return;
-  }
 
- /*
-  * See if the job is owned by the requesting user...
-  */
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Setting %s device-uri to \"%s\" (was \"%s\".)",
+                   printer->name,
+                   cupsdSanitizeURI(attr->values[0].string.text, line,
+                                    sizeof(line)),
+                   cupsdSanitizeURI(printer->device_uri, resource,
+                                    sizeof(resource)));
 
-  if (!validate_user(job, con, job->username, username, sizeof(username)))
-  {
-    send_http_error(con, HTTP_UNAUTHORIZED);
-    return;
+    cupsdSetString(&printer->device_uri, attr->values[0].string.text);
   }
 
- /*
-  * See if the job is already completed, cancelled, or aborted; if so,
-  * we can't cancel...
-  */
-
-  if (job->state_value >= IPP_JOB_CANCELLED)
+  if ((attr = ippFindAttribute(con->request, "port-monitor",
+                               IPP_TAG_KEYWORD)) != NULL)
   {
-    send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Job #%d is already %s - can\'t cancel."), jobid,
-                   job->state_value == IPP_JOB_CANCELLED ? "cancelled" :
-                   job->state_value == IPP_JOB_ABORTED ? "aborted" :
-                   "completed");
-    return;
-  }
+    ipp_attribute_t    *supported;     /* port-monitor-supported attribute */
 
- /*
-  * Cancel the job and return...
-  */
 
-  cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                "Job cancelled by \"%s\".", username);
+    need_restart_job = 1;
 
-  cupsdCancelJob(job, 0);
-  cupsdCheckJobs();
+    supported = ippFindAttribute(printer->attrs, "port-monitor-supported",
+                                 IPP_TAG_KEYWORD);
+    for (i = 0; i < supported->num_values; i ++)
+      if (!strcmp(supported->values[i].string.text,
+                  attr->values[0].string.text))
+        break;
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was cancelled by \"%s\".", jobid,
-                  username);
+    if (i >= supported->num_values)
+    {
+      send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
+                     attr->values[0].string.text);
+      return;
+    }
 
-  con->response->request.status.status_code = IPP_OK;
-}
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Setting %s port-monitor to \"%s\" (was \"%s\".)",
+                    printer->name, attr->values[0].string.text,
+                   printer->port_monitor);
 
+    if (strcmp(attr->values[0].string.text, "none"))
+      cupsdSetString(&printer->port_monitor, attr->values[0].string.text);
+    else
+      cupsdClearString(&printer->port_monitor);
+  }
 
-/*
- * 'cancel_subscription()' - Cancel a subscription.
- */
+  if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
+                               IPP_TAG_BOOLEAN)) != NULL)
+  {
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Setting %s printer-is-accepting-jobs to %d (was %d.)",
+                    printer->name, attr->values[0].boolean, printer->accepting);
 
-static void
-cancel_subscription(
-    cupsd_client_t *con,               /* I - Client connection */
-    int            sub_id)             /* I - Subscription ID */
-{
-  http_status_t                status;         /* Policy status */
-  cupsd_subscription_t *sub;           /* Subscription */
+    printer->accepting = attr->values[0].boolean;
+    cupsdAddPrinterHistory(printer);
+  }
 
+  if ((attr = ippFindAttribute(con->request, "printer-is-shared",
+                               IPP_TAG_BOOLEAN)) != NULL)
+  {
+    if (printer->shared && !attr->values[0].boolean)
+      cupsdSendBrowseDelete(printer);
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cancel_subscription(con=%p[%d], sub_id=%d)",
-                  con, con->http.fd, sub_id);
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Setting %s printer-is-shared to %d (was %d.)",
+                    printer->name, attr->values[0].boolean, printer->shared);
 
- /*
-  * Is the subscription ID valid?
-  */
+    printer->shared = attr->values[0].boolean;
+  }
 
-  if ((sub = cupsdFindSubscription(sub_id)) == NULL)
+  if ((attr = ippFindAttribute(con->request, "printer-state",
+                               IPP_TAG_ENUM)) != NULL)
   {
-   /*
-    * Bad subscription ID...
-    */
+    if (attr->values[0].integer != IPP_PRINTER_IDLE &&
+        attr->values[0].integer != IPP_PRINTER_STOPPED)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad printer-state value %d!"),
+                      attr->values[0].integer);
+      return;
+    }
 
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("notify-subscription-id %d no good!"), sub_id);
-    return;
+    cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)", printer->name,
+               attr->values[0].integer, printer->state);
+
+    if (attr->values[0].integer == IPP_PRINTER_STOPPED)
+      cupsdStopPrinter(printer, 0);
+    else
+    {
+      need_restart_job = 1;
+      cupsdSetPrinterState(printer, (ipp_pstate_t)(attr->values[0].integer), 0);
+    }
+  }
+  if ((attr = ippFindAttribute(con->request, "printer-state-message",
+                               IPP_TAG_TEXT)) != NULL)
+  {
+    strlcpy(printer->state_message, attr->values[0].string.text,
+            sizeof(printer->state_message));
+    cupsdAddPrinterHistory(printer);
   }
 
+  set_printer_defaults(con, printer);
+
  /*
-  * Check policy...
+  * See if we have all required attributes...
   */
 
-  if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
-                                             DefaultPolicyPtr,
-                                 con, sub->owner)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
+  if (!printer->device_uri)
+    cupsdSetString(&printer->device_uri, "file:///dev/null");
 
  /*
-  * Cancel the subscription...
+  * See if we have an interface script or PPD file attached to the request...
   */
 
-  cupsdDeleteSubscription(sub, 1);
+  if (con->filename)
+  {
+    need_restart_job = 1;
 
-  con->response->request.status.status_code = IPP_OK;
-}
+    strlcpy(srcfile, con->filename, sizeof(srcfile));
 
+    if ((fp = cupsFileOpen(srcfile, "rb")))
+    {
+     /*
+      * Yes; get the first line from it...
+      */
 
-/*
- * 'check_quotas()' - Check quotas for a printer and user.
- */
+      line[0] = '\0';
+      cupsFileGets(fp, line, sizeof(line));
+      cupsFileClose(fp);
 
-static int                             /* O - 1 if OK, 0 if not */
-check_quotas(cupsd_client_t  *con,     /* I - Client connection */
-             cupsd_printer_t *p)       /* I - Printer or class */
-{
-  int          i;                      /* Looping var */
-  char         username[33];           /* Username */
-  cupsd_quota_t        *q;                     /* Quota data */
-  struct passwd        *pw;                    /* User password data */
+     /*
+      * Then see what kind of file it is...
+      */
 
+      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
+               printer->name);
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "check_quotas(%p[%d], %p[%s])",
-                  con, con->http.fd, p, p->name);
+      if (!strncmp(line, "*PPD-Adobe", 10))
+      {
+       /*
+       * The new file is a PPD file, so remove any old interface script
+       * that might be lying around...
+       */
 
- /*
-  * Check input...
-  */
+       unlink(dstfile);
+      }
+      else
+      {
+       /*
+       * This must be an interface script, so move the file over to the
+       * interfaces directory and make it executable...
+       */
 
-  if (!con || !p)
-    return (0);
+       if (copy_file(srcfile, dstfile))
+       {
+          send_ipp_status(con, IPP_INTERNAL_ERROR,
+                         _("Unable to copy interface script - %s!"),
+                         strerror(errno));
+         return;
+       }
+       else
+       {
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Copied interface script successfully!");
+          chmod(dstfile, 0755);
+       }
+      }
 
- /*
-  * Figure out who is printing...
-  */
+      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
+               printer->name);
 
-  strlcpy(username, get_username(con), sizeof(username));
+      if (!strncmp(line, "*PPD-Adobe", 10))
+      {
+       /*
+       * The new file is a PPD file, so move the file over to the
+       * ppd directory and make it readable by all...
+       */
 
- /*
-  * Check global active job limits for printers and users...
-  */
+       if (copy_file(srcfile, dstfile))
+       {
+          send_ipp_status(con, IPP_INTERNAL_ERROR,
+                         _("Unable to copy PPD file - %s!"),
+                         strerror(errno));
+         return;
+       }
+       else
+       {
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Copied PPD file successfully!");
+          chmod(dstfile, 0644);
+       }
+      }
+      else
+      {
+       /*
+       * This must be an interface script, so remove any old PPD file that
+       * may be lying around...
+       */
 
-  if (MaxJobsPerPrinter)
+       unlink(dstfile);
+      }
+    }
+  }
+  else if ((attr = ippFindAttribute(con->request, "ppd-name",
+                                    IPP_TAG_NAME)) != NULL)
   {
-   /*
-    * Check if there are too many pending jobs on this printer...
-    */
+    need_restart_job = 1;
 
-    if (cupsdGetPrinterJobCount(p->name) >= MaxJobsPerPrinter)
+    if (!strcmp(attr->values[0].string.text, "raw"))
     {
-      cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for printer \"%s\"...",
-                      p->name);
-      return (0);
-    }
-  }
+     /*
+      * Raw driver, remove any existing PPD or interface script files.
+      */
 
-  if (MaxJobsPerUser)
-  {
-   /*
-    * Check if there are too many pending jobs for this user...
-    */
+      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
+               printer->name);
+      unlink(dstfile);
 
-    if (cupsdGetUserJobCount(username) >= MaxJobsPerUser)
+      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
+               printer->name);
+      unlink(dstfile);
+    }
+    else
     {
-      cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for user \"%s\"...",
-                      username);
-      return (0);
+     /*
+      * PPD model file...
+      */
+
+      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
+               printer->name);
+      unlink(dstfile);
+
+      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
+               printer->name);
+
+      if (copy_model(con, attr->values[0].string.text, dstfile))
+      {
+        send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file!"));
+       return;
+      }
+      else
+      {
+        cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "Copied PPD file successfully!");
+        chmod(dstfile, 0644);
+      }
     }
   }
 
  /*
-  * Check against users...
+  * Update the printer attributes and return...
   */
 
-  if (p->num_users == 0 && p->k_limit == 0 && p->page_limit == 0)
-    return (1);
+  cupsdSetPrinterAttrs(printer);
+  cupsdSaveAllPrinters();
 
-  if (p->num_users)
+  if (need_restart_job && printer->job)
   {
-    pw = getpwnam(username);
-    endpwent();
+    cupsd_job_t *job;
 
-    for (i = 0; i < p->num_users; i ++)
-      if (p->users[i][0] == '@')
-      {
-       /*
-        * Check group membership...
-       */
+   /*
+    * Stop the current job and then restart it below...
+    */
 
-        if (cupsdCheckGroup(username, pw, p->users[i] + 1))
-         break;
-      }
-      else if (!strcasecmp(username, p->users[i]))
-       break;
+    job = (cupsd_job_t *)printer->job;
 
-    if ((i < p->num_users) == p->deny_users)
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Denying user \"%s\" access to printer \"%s\"...",
-                     username, p->name);
-      return (0);
-    }
+    cupsdStopJob(job, 1);
+
+    job->state->values[0].integer = IPP_JOB_PENDING;
+    job->state_value              = IPP_JOB_PENDING;
   }
 
- /*
-  * Check quotas...
-  */
+  if (need_restart_job)
+    cupsdCheckJobs();
 
-  if (p->k_limit || p->page_limit)
+  cupsdWritePrintcap();
+
+  if (modify)
   {
-    if ((q = cupsdUpdateQuota(p, username, 0, 0)) == NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate quota data for user \"%s\"!",
-                      username);
-      return (0);
-    }
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
+                  "Printer \"%s\" modified by \"%s\".", printer->name,
+                 get_username(con));
 
-    if ((q->k_count >= p->k_limit && p->k_limit) ||
-        (q->page_count >= p->page_limit && p->page_limit))
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO, "User \"%s\" is over the quota limit...",
-                      username);
-      return (0);
-    }
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".",
+                    printer->name, get_username(con));
   }
+  else
+  {
+    cupsdAddPrinterHistory(printer);
 
- /*
-  * If we have gotten this far, we're done!
-  */
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, printer, NULL,
+                  "New printer \"%s\" added by \"%s\".", printer->name,
+                 get_username(con));
 
-  return (1);
+    cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".",
+                    printer->name, get_username(con));
+  }
+
+  con->response->request.status.status_code = IPP_OK;
 }
 
 
 /*
- * 'copy_attribute()' - Copy a single attribute.
+ * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
+ *                                 based upon the printer state...
  */
 
-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? */
+static void
+add_printer_state_reasons(
+    cupsd_client_t  *con,              /* I - Client connection */
+    cupsd_printer_t *p)                        /* I - Printer info */
 {
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *toattr;        /* Destination attribute */
+  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,
+                p->state == IPP_PRINTER_STOPPED ? "paused" : "none");
+  else
+    ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                  "printer-state-reasons", p->num_reasons, NULL,
+                 (const char * const *)p->reasons);
+}
 
-  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;
+/*
+ * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
+ *                            the specified printer or class.
+ */
 
-    case IPP_TAG_INTEGER :
-    case IPP_TAG_ENUM :
-        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,
-                               attr->name, attr->num_values, NULL);
+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 */
 
-        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);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])",
+                  con, con->http.fd, p, p->name);
 
-        for (i = 0; i < attr->num_values; i ++)
-         toattr->values[i].boolean = attr->values[i].boolean;
-        break;
+  count = cupsdGetPrinterJobCount(p->name);
 
-    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);
+  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+                "queued-job-count", count);
+}
 
-        if (quickcopy)
-       {
-          for (i = 0; i < attr->num_values; i ++)
-           toattr->values[i].string.text = attr->values[i].string.text;
-        }
-       else
-       {
-          for (i = 0; i < attr->num_values; i ++)
-           toattr->values[i].string.text = _cups_sp_alloc(attr->values[i].string.text);
-       }
-        break;
 
-    case IPP_TAG_DATE :
-        toattr = ippAddDate(to, attr->group_tag, attr->name,
-                           attr->values[0].date);
-        break;
+/*
+ * 'apply_printer_defaults()' - Apply printer default options to a job.
+ */
 
-    case IPP_TAG_RESOLUTION :
-        toattr = ippAddResolutions(to, attr->group_tag, attr->name,
-                                  attr->num_values, IPP_RES_PER_INCH,
-                                  NULL, NULL);
+static void
+apply_printer_defaults(
+    cupsd_printer_t *printer,          /* I - Printer */
+    cupsd_job_t     *job)              /* I - Job */
+{
+  int          i,                      /* Looping var */
+               num_options;            /* Number of default options */
+  cups_option_t        *options,               /* Default options */
+               *option;                /* Current option */    
 
-        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);
+ /*
+  * Collect all of the default options and add the missing ones to the
+  * job object...
+  */
 
-        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;
+  for (i = printer->num_options, num_options = 0, option = printer->options;
+       i > 0;
+       i --, option ++)
+    if (!ippFindAttribute(job->attrs, option->name, IPP_TAG_ZERO))
+    {
+      num_options = cupsAddOption(option->name, option->value, num_options,
+                                  &options);
+    }
 
-    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);
+ /*
+  * Encode these options as attributes in the job object...
+  */
 
-        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
-       {
-          for (i = 0; i < attr->num_values; i ++)
-         {
-           if (!i)
-              toattr->values[i].string.charset =
-                 _cups_sp_alloc(attr->values[i].string.charset);
-           else
-              toattr->values[i].string.charset =
-                 toattr->values[0].string.charset;
+  cupsEncodeOptions2(job->attrs, num_options, options, IPP_TAG_JOB);
+  cupsFreeOptions(num_options, options);
+}
+
+
+/*
+ * 'authenticate_job()' - Set job authentication info.
+ */
+
+static void
+authenticate_job(cupsd_client_t  *con, /* I - Client connection */
+                ipp_attribute_t *uri)  /* I - Job URI */
+{
+  ipp_attribute_t      *attr;          /* Job-id attribute */
+  int                  jobid;          /* Job ID */
+  cupsd_job_t          *job;           /* Current job */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
 
-           toattr->values[i].string.text = _cups_sp_alloc(attr->values[i].string.text);
-          }
-        }
-        break;
 
-    case IPP_TAG_BEGIN_COLLECTION :
-        toattr = ippAddCollections(to, attr->group_tag, attr->name,
-                                  attr->num_values, NULL);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "authenticate_job(%p[%d], %s)",
+                  con, con->http.fd, uri->values[0].string.text);
 
-        for (i = 0; i < attr->num_values; i ++)
-       {
-         toattr->values[i].collection = ippNew();
-         copy_attrs(toattr->values[i].collection, attr->values[i].collection,
-                    NULL, IPP_TAG_ZERO, 0);
-       }
-        break;
+ /*
+  * Start with "everything is OK" status...
+  */
 
-    default :
-        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,
-                               attr->name, attr->num_values, NULL);
+  con->response->request.status.status_code = IPP_OK;
 
-        for (i = 0; i < attr->num_values; i ++)
-       {
-         toattr->values[i].unknown.length = attr->values[i].unknown.length;
+ /*
+  * See if we have a job URI or a printer URI...
+  */
 
-         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 */
-  }
+  if (!strcmp(uri->name, "printer-uri"))
+  {
+   /*
+    * Got a printer URI; see if we also have a job-id attribute...
+    */
 
-  return (toattr);
-}
+    if ((attr = ippFindAttribute(con->request, "job-id",
+                                 IPP_TAG_INTEGER)) == NULL)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Got a printer-uri attribute but no job-id!"));
+      return;
+    }
+
+    jobid = attr->values[0].integer;
+  }
+  else
+  {
+   /*
+    * Got a job URI; parse it to get the job ID...
+    */
 
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                    sizeof(method), username, sizeof(username), host,
+                   sizeof(host), &port, resource, sizeof(resource));
+    if (strncmp(resource, "/jobs/", 6))
+    {
+     /*
+      * Not a valid URI!
+      */
 
-/*
- * 'copy_attrs()' - Copy attributes from one request to another.
- */
+      send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-uri attribute \"%s\"!"),
+                      uri->values[0].string.text);
+      return;
+    }
 
-static void
-copy_attrs(ipp_t        *to,           /* I - Destination request */
-           ipp_t        *from,         /* I - Source request */
-           cups_array_t *ra,           /* I - Requested attributes */
-          ipp_tag_t    group,          /* I - Group to copy */
-          int          quickcopy)      /* I - Do a quick copy? */
-{
-  ipp_attribute_t      *fromattr;      /* Source attribute */
+    jobid = atoi(resource + 6);
+  }
 
+ /*
+  * See if the job exists...
+  */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
-                 to, from, ra, group, quickcopy);
+  if ((job = cupsdFindJob(jobid)) == NULL)
+  {
+   /*
+    * Nope - return a "not found" error...
+    */
 
-  if (!to || !from)
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("Job #%d does not exist!"), jobid);
     return;
+  }
 
-  for (fromattr = from->attrs; fromattr; fromattr = fromattr->next)
+ /*
+  * See if the job has been completed...
+  */
+
+  if (job->state_value != IPP_JOB_HELD)
   {
    /*
-    * Filter attributes as needed...
+    * Return a "not-possible" error...
     */
 
-    if (group != IPP_TAG_ZERO && fromattr->group_tag != group &&
-        fromattr->group_tag != IPP_TAG_ZERO && !fromattr->name)
-      continue;
+    send_ipp_status(con, IPP_NOT_POSSIBLE,
+                    _("Job #%d is not held for authentication!"),
+                   jobid);
+    return;
+  }
 
-    if (!ra || cupsArrayFind(ra, fromattr->name))
-      copy_attribute(to, fromattr, quickcopy);
+ /*
+  * See if we have already authenticated...
+  */
+
+  if (!con->username[0])
+  {
+    send_ipp_status(con, IPP_NOT_AUTHORIZED,
+                    _("No authentication information provided!"));
+    return;
+  }
+
+ /*
+  * See if the job is owned by the requesting user...
+  */
+
+  if (!validate_user(job, con, job->username, username, sizeof(username)))
+  {
+    send_http_error(con, HTTP_UNAUTHORIZED);
+    return;
+  }
+
+ /*
+  * Save the authentication information for this job...
+  */
+
+  save_auth_info(con, job);
+
+ /*
+  * Reset the job-hold-until value to "no-hold"...
+  */
+
+  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+                               IPP_TAG_KEYWORD)) == NULL)
+    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+
+  if (attr)
+  {
+    attr->value_tag = IPP_TAG_KEYWORD;
+    cupsdSetString(&(attr->values[0].string.text), "no-hold");
   }
+
+ /*
+  * Release the job and return...
+  */
+
+  cupsdReleaseJob(job);
+
+  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was authenticated by \"%s\".", jobid,
+                  con->username);
 }
 
 
 /*
- * 'copy_banner()' - Copy a banner file to the requests directory for the
- *                   specified job.
+ * 'cancel_all_jobs()' - Cancel all print jobs.
  */
 
-static int                             /* O - Size of banner file in kbytes */
-copy_banner(cupsd_client_t *con,       /* I - Client connection */
-            cupsd_job_t    *job,       /* I - Job information */
-            const char     *name)      /* I - Name of banner */
+static void
+cancel_all_jobs(cupsd_client_t  *con,  /* I - Client connection */
+               ipp_attribute_t *uri)   /* I - Job or Printer URI */
 {
-  int          i;                      /* Looping var */
-  int          kbytes;                 /* Size of banner file in kbytes */
-  char         filename[1024];         /* Job filename */
-  cupsd_banner_t *banner;              /* Pointer to banner */
-  cups_file_t  *in;                    /* Input file */
-  cups_file_t  *out;                   /* Output file */
-  int          ch;                     /* Character from file */
-  char         attrname[255],          /* Name of attribute */
-               *s;                     /* Pointer into name */
-  ipp_attribute_t *attr;               /* Attribute */
+  http_status_t        status;                 /* Policy status */
+  const char   *dest;                  /* Destination */
+  cups_ptype_t dtype;                  /* Destination type */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               userpass[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  ipp_attribute_t *attr;               /* Attribute in request */
+  const char   *username;              /* Username */
+  int          purge;                  /* Purge? */
+  cupsd_printer_t *printer;            /* Printer */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner(%p[%d], %p[%d], %s)",
-                  con, con->http.fd, job, job->id, name ? name : "(null)");
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_all_jobs(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
 
  /*
-  * Find the banner; return if not found or "none"...
+  * See if we have a printer URI...
   */
 
-  if (!name || !strcmp(name, "none") ||
-      (banner = cupsdFindBanner(name)) == NULL)
-    return (0);
+  if (strcmp(uri->name, "printer-uri"))
+  {
+    send_ipp_status(con, IPP_BAD_REQUEST,
+                    _("The printer-uri attribute is required!"));
+    return;
+  }
 
  /*
-  * Open the banner and job files...
+  * Get the username (if any) for the jobs we want to cancel (only if
+  * "my-jobs" is specified...
   */
 
-  if (add_file(con, job, banner->filetype, 0))
-    return (0);
-
-  snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
-           job->num_files);
-  if ((out = cupsFileOpen(filename, "w")) == NULL)
+  if ((attr = ippFindAttribute(con->request, "my-jobs",
+                               IPP_TAG_BOOLEAN)) != NULL &&
+      attr->values[0].boolean)
   {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "copy_banner: Unable to create banner job file %s - %s",
-                    filename, strerror(errno));
-    job->num_files --;
-    return (0);
+    if ((attr = ippFindAttribute(con->request, "requesting-user-name",
+                                 IPP_TAG_NAME)) != NULL)
+      username = attr->values[0].string.text;
+    else
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Missing requesting-user-name attribute!"));
+      return;
+    }
   }
+  else
+    username = NULL;
 
-  fchmod(cupsFileNumber(out), 0640);
-  fchown(cupsFileNumber(out), RunUser, Group);
+ /*
+  * Look for the "purge-jobs" attribute...
+  */
+
+  if ((attr = ippFindAttribute(con->request, "purge-jobs",
+                               IPP_TAG_BOOLEAN)) != NULL)
+    purge = attr->values[0].boolean;
+  else
+    purge = 1;
 
  /*
-  * Try the localized banner file under the subdirectory...
+  * And if the destination is valid...
   */
 
-  strlcpy(attrname, con->request->attrs->next->values[0].string.text,
-          sizeof(attrname));
-  if (strlen(attrname) > 2 && attrname[2] == '-')
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), userpass, sizeof(userpass), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
-    * Convert ll-cc to ll_CC...
+    * Bad URI?
     */
 
-    attrname[2] = '_';
-    attrname[3] = toupper(attrname[3] & 255);
-    attrname[4] = toupper(attrname[4] & 255);
-  }
+    if ((!strncmp(resource, "/printers/", 10) && resource[10]) ||
+        (!strncmp(resource, "/classes/", 9) && resource[9]))
+    {
+      send_ipp_status(con, IPP_NOT_FOUND,
+                      _("The printer or class was not found."));
+      return;
+    }
+    else if (strcmp(resource, "/printers/"))
+    {
+      send_ipp_status(con, IPP_NOT_FOUND,
+                      _("The printer-uri \"%s\" is not valid."),
+                     uri->values[0].string.text);
+      return;
+    }
 
-  snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,
-           attrname, name);
+   /*
+    * Check policy...
+    */
+
+    if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status);
+      return;
+    }
 
-  if (access(filename, 0) && strlen(attrname) > 2)
-  {
    /*
-    * Wasn't able to find "ll_CC" locale file; try the non-national
-    * localization banner directory.
+    * Cancel all jobs on all printers...
     */
 
-    attrname[2] = '\0';
+    cupsdCancelJobs(NULL, username, purge);
 
-    snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,
-             attrname, name);
+    cupsdLogMessage(CUPSD_LOG_INFO, "All jobs were %s by \"%s\".",
+                    purge ? "purged" : "cancelled", get_username(con));
   }
-
-  if (access(filename, 0))
+  else
   {
    /*
-    * Use the non-localized banner file.
+    * Check policy...
     */
 
-    snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);
-  }
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+    {
+      send_http_error(con, status);
+      return;
+    }
 
-  if ((in = cupsFileOpen(filename, "r")) == NULL)
-  {
-    cupsFileClose(out);
-    unlink(filename);
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "copy_banner: Unable to open banner template file %s - %s",
-                    filename, strerror(errno));
-    job->num_files --;
-    return (0);
+   /*
+    * Cancel all of the jobs on the named printer...
+    */
+
+    cupsdCancelJobs(dest, username, purge);
+
+    cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
+                    dest, purge ? "purged" : "cancelled", get_username(con));
   }
 
+  con->response->request.status.status_code = IPP_OK;
+}
+
+
+/*
+ * 'cancel_job()' - Cancel a print job.
+ */
+
+static void
+cancel_job(cupsd_client_t  *con,       /* I - Client connection */
+          ipp_attribute_t *uri)        /* I - Job or Printer URI */
+{
+  ipp_attribute_t *attr;               /* Current attribute */
+  int          jobid;                  /* Job ID */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  cupsd_job_t  *job;                   /* Job information */
+  const char   *dest;                  /* Destination */
+  cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  cupsd_printer_t *printer;            /* Printer data */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
+
  /*
-  * Parse the file to the end...
+  * See if we have a job URI or a printer URI...
   */
 
-  while ((ch = cupsFileGetChar(in)) != EOF)
-    if (ch == '{')
+  if (!strcmp(uri->name, "printer-uri"))
+  {
+   /*
+    * Got a printer URI; see if we also have a job-id attribute...
+    */
+
+    if ((attr = ippFindAttribute(con->request, "job-id",
+                                 IPP_TAG_INTEGER)) == NULL)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Got a printer-uri attribute but no job-id!"));
+      return;
+    }
+
+    if ((jobid = attr->values[0].integer) == 0)
     {
      /*
-      * Get an attribute name...
+      * Find the current job on the specified printer...
       */
 
-      for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;)
-        if (!isalpha(ch & 255) && ch != '-' && ch != '?')
-          break;
-       else if (s < (attrname + sizeof(attrname) - 1))
-          *s++ = ch;
-       else
-         break;
-
-      *s = '\0';
+      httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                      sizeof(method), username, sizeof(username), host,
+                     sizeof(host), &port, resource, sizeof(resource));
 
-      if (ch != '}')
+      if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
       {
        /*
-        * Ignore { followed by stuff that is not an attribute name...
+       * Bad URI...
        */
 
-        cupsFilePrintf(out, "{%s%c", attrname, ch);
-       continue;
+       send_ipp_status(con, IPP_NOT_FOUND,
+                       _("The printer or class was not found."));
+       return;
       }
 
      /*
-      * See if it is defined...
+      * See if the printer is currently printing a job...
       */
 
-      if (attrname[0] == '?')
-        s = attrname + 1;
+      if (printer->job)
+        jobid = ((cupsd_job_t *)printer->job)->id;
       else
-        s = attrname;
-
-      if (!strcmp(s, "printer-name"))
-      {
-        cupsFilePuts(out, job->dest);
-       continue;
-      }
-      else if ((attr = ippFindAttribute(job->attrs, s, IPP_TAG_ZERO)) == NULL)
       {
        /*
-        * See if we have a leading question mark...
+        * No, see if there are any pending jobs...
        */
+        
+        for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
+            job;
+            job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
+         if (job->state_value <= IPP_JOB_PROCESSING &&
+             !strcasecmp(job->dest, dest))
+           break;
 
-       if (attrname[0] != '?')
+       if (job)
+         jobid = job->id;
+       else
        {
-        /*
-          * Nope, write to file as-is; probably a PostScript procedure...
-         */
+         send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s!"),
+                         dest);
+         return;
+       }
+      }
+    }
+  }
+  else
+  {
+   /*
+    * Got a job URI; parse it to get the job ID...
+    */
 
-         cupsFilePrintf(out, "{%s}", attrname);
-        }
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                    sizeof(method), username, sizeof(username), host,
+                   sizeof(host), &port, resource, sizeof(resource));
+    if (strncmp(resource, "/jobs/", 6))
+    {
+     /*
+      * Not a valid URI!
+      */
 
-        continue;
-      }
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Bad job-uri attribute \"%s\"!"),
+                      uri->values[0].string.text);
+      return;
+    }
+
+    jobid = atoi(resource + 6);
+  }
+
+ /*
+  * See if the job exists...
+  */
+
+  if ((job = cupsdFindJob(jobid)) == NULL)
+  {
+   /*
+    * Nope - return a "not found" error...
+    */
+
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    return;
+  }
+
+ /*
+  * See if the job is owned by the requesting user...
+  */
+
+  if (!validate_user(job, con, job->username, username, sizeof(username)))
+  {
+    send_http_error(con, HTTP_UNAUTHORIZED);
+    return;
+  }
+
+ /*
+  * See if the job is already completed, cancelled, or aborted; if so,
+  * we can't cancel...
+  */
+
+  if (job->state_value >= IPP_JOB_CANCELLED)
+  {
+    send_ipp_status(con, IPP_NOT_POSSIBLE,
+                    _("Job #%d is already %s - can\'t cancel."), jobid,
+                   job->state_value == IPP_JOB_CANCELLED ? "cancelled" :
+                   job->state_value == IPP_JOB_ABORTED ? "aborted" :
+                   "completed");
+    return;
+  }
 
    /*
-      * Output value(s)...
-      */
+ /*
+  * Cancel the job and return...
+  */
 
-      for (i = 0; i < attr->num_values; i ++)
-      {
-       if (i)
-         cupsFilePutChar(out, ',');
+  cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                "Job cancelled by \"%s\".", username);
 
-       switch (attr->value_tag)
-       {
-         case IPP_TAG_INTEGER :
-         case IPP_TAG_ENUM :
-             if (!strncmp(s, "time-at-", 8))
-               cupsFilePuts(out, cupsdGetDateTime(attr->values[i].integer));
-             else
-               cupsFilePrintf(out, "%d", attr->values[i].integer);
-             break;
+  cupsdCancelJob(job, 0);
+  cupsdCheckJobs();
 
-         case IPP_TAG_BOOLEAN :
-             cupsFilePrintf(out, "%d", attr->values[i].boolean);
-             break;
+  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was cancelled by \"%s\".", jobid,
+                  username);
 
-         case IPP_TAG_NOVALUE :
-             cupsFilePuts(out, "novalue");
-             break;
+  con->response->request.status.status_code = IPP_OK;
+}
 
-         case IPP_TAG_RANGE :
-             cupsFilePrintf(out, "%d-%d", attr->values[i].range.lower,
-                     attr->values[i].range.upper);
-             break;
 
-         case IPP_TAG_RESOLUTION :
-             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");
-             break;
+/*
+ * 'cancel_subscription()' - Cancel a subscription.
+ */
 
-         case IPP_TAG_URI :
-          case IPP_TAG_STRING :
-         case IPP_TAG_TEXT :
-         case IPP_TAG_NAME :
-         case IPP_TAG_KEYWORD :
-         case IPP_TAG_CHARSET :
-         case IPP_TAG_LANGUAGE :
-             if (!strcasecmp(banner->filetype->type, "postscript"))
-             {
-              /*
-               * Need to quote strings for PS banners...
-               */
+static void
+cancel_subscription(
+    cupsd_client_t *con,               /* I - Client connection */
+    int            sub_id)             /* I - Subscription ID */
+{
+  http_status_t                status;         /* Policy status */
+  cupsd_subscription_t *sub;           /* Subscription */
 
-               const char *p;
 
-               for (p = attr->values[i].string.text; *p; p ++)
-               {
-                 if (*p == '(' || *p == ')' || *p == '\\')
-                 {
-                   cupsFilePutChar(out, '\\');
-                   cupsFilePutChar(out, *p);
-                 }
-                 else if (*p < 32 || *p > 126)
-                   cupsFilePrintf(out, "\\%03o", *p & 255);
-                 else
-                   cupsFilePutChar(out, *p);
-               }
-             }
-             else
-               cupsFilePuts(out, attr->values[i].string.text);
-             break;
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "cancel_subscription(con=%p[%d], sub_id=%d)",
+                  con, con->http.fd, sub_id);
 
-          default :
-             break; /* anti-compiler-warning-code */
-       }
-      }
-    }
-    else if (ch == '\\')       /* Quoted char */
-    {
-      ch = cupsFileGetChar(in);
+ /*
+  * Is the subscription ID valid?
+  */
 
-      if (ch != '{')           /* Only do special handling for \{ */
-        cupsFilePutChar(out, '\\');
+  if ((sub = cupsdFindSubscription(sub_id)) == NULL)
+  {
+   /*
+    * Bad subscription ID...
+    */
 
-      cupsFilePutChar(out, ch);
-    }
-    else
-      cupsFilePutChar(out, ch);
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("notify-subscription-id %d no good!"), sub_id);
+    return;
+  }
 
-  cupsFileClose(in);
+ /*
+  * Check policy...
+  */
 
-  kbytes = (cupsFileTell(out) + 1023) / 1024;
+  if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
+                                             DefaultPolicyPtr,
+                                 con, sub->owner)) != HTTP_OK)
+  {
+    send_http_error(con, status);
+    return;
+  }
 
-  if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
-                               IPP_TAG_INTEGER)) != NULL)
-    attr->values[0].integer += kbytes;
+ /*
+  * Cancel the subscription...
+  */
 
-  cupsFileClose(out);
+  cupsdDeleteSubscription(sub, 1);
 
-  return (kbytes);
+  con->response->request.status.status_code = IPP_OK;
 }
 
 
 /*
- * 'copy_file()' - Copy a PPD file or interface script...
+ * 'check_quotas()' - Check quotas for a printer and user.
  */
 
-static int                             /* O - 0 = success, -1 = error */
-copy_file(const char *from,            /* I - Source file */
-          const char *to)              /* I - Destination file */
+static int                             /* O - 1 if OK, 0 if not */
+check_quotas(cupsd_client_t  *con,     /* I - Client connection */
+             cupsd_printer_t *p)       /* I - Printer or class */
 {
-  cups_file_t  *src,                   /* Source file */
-               *dst;                   /* Destination file */
-  int          bytes;                  /* Bytes to read/write */
-  char         buffer[2048];           /* Copy buffer */
+  int          i;                      /* Looping var */
+  char         username[33];           /* Username */
+  cupsd_quota_t        *q;                     /* Quota data */
+  struct passwd        *pw;                    /* User password data */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_file(\"%s\", \"%s\")", from, to);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "check_quotas(%p[%d], %p[%s])",
+                  con, con->http.fd, p, p->name);
 
  /*
-  * Open the source and destination file for a copy...
+  * Check input...
   */
 
-  if ((src = cupsFileOpen(from, "rb")) == NULL)
-    return (-1);
+  if (!con || !p)
+    return (0);
 
-  if ((dst = cupsFileOpen(to, "wb")) == NULL)
+ /*
+  * Figure out who is printing...
+  */
+
+  strlcpy(username, get_username(con), sizeof(username));
+
+ /*
+  * Check global active job limits for printers and users...
+  */
+
+  if (MaxJobsPerPrinter)
   {
-    cupsFileClose(src);
-    return (-1);
+   /*
+    * Check if there are too many pending jobs on this printer...
+    */
+
+    if (cupsdGetPrinterJobCount(p->name) >= MaxJobsPerPrinter)
+    {
+      cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for printer \"%s\"...",
+                      p->name);
+      return (0);
+    }
+  }
+
+  if (MaxJobsPerUser)
+  {
+   /*
+    * Check if there are too many pending jobs for this user...
+    */
+
+    if (cupsdGetUserJobCount(username) >= MaxJobsPerUser)
+    {
+      cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for user \"%s\"...",
+                      username);
+      return (0);
+    }
   }
 
  /*
-  * Copy the source file to the destination...
+  * Check against users...
   */
 
-  while ((bytes = cupsFileRead(src, buffer, sizeof(buffer))) > 0)
-    if (cupsFileWrite(dst, buffer, bytes) < bytes)
+  if (p->num_users == 0 && p->k_limit == 0 && p->page_limit == 0)
+    return (1);
+
+  if (p->num_users)
+  {
+    pw = getpwnam(username);
+    endpwent();
+
+    for (i = 0; i < p->num_users; i ++)
+      if (p->users[i][0] == '@')
+      {
+       /*
+        * Check group membership...
+       */
+
+        if (cupsdCheckGroup(username, pw, p->users[i] + 1))
+         break;
+      }
+      else if (!strcasecmp(username, p->users[i]))
+       break;
+
+    if ((i < p->num_users) == p->deny_users)
     {
-      cupsFileClose(src);
-      cupsFileClose(dst);
-      return (-1);
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "Denying user \"%s\" access to printer \"%s\"...",
+                     username, p->name);
+      return (0);
     }
+  }
 
  /*
-  * Close both files and return...
+  * Check quotas...
   */
 
-  cupsFileClose(src);
+  if (p->k_limit || p->page_limit)
+  {
+    if ((q = cupsdUpdateQuota(p, username, 0, 0)) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate quota data for user \"%s\"!",
+                      username);
+      return (0);
+    }
 
-  return (cupsFileClose(dst));
+    if ((q->k_count >= p->k_limit && p->k_limit) ||
+        (q->page_count >= p->page_limit && p->page_limit))
+    {
+      cupsdLogMessage(CUPSD_LOG_INFO, "User \"%s\" is over the quota limit...",
+                      username);
+      return (0);
+    }
+  }
+
+ /*
+  * If we have gotten this far, we're done!
+  */
+
+  return (1);
 }
 
 
 /*
- * 'copy_model()' - Copy a PPD model file, substituting default values
- *                  as needed...
+ * 'copy_attribute()' - Copy a single attribute.
  */
 
-static int                             /* O - 0 = success, -1 = error */
-copy_model(cupsd_client_t *con,                /* I - Client connection */
-           const char     *from,       /* I - Source file */
-           const char     *to)         /* I - Destination file */
+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? */
 {
-  fd_set       *input;                 /* select() input set */
-  struct timeval timeout;              /* select() timeout */
-  int          maxfd;                  /* Maximum file descriptor for select() */
-  char         tempfile[1024];         /* Temporary PPD file */
-  int          tempfd;                 /* Temporary PPD file descriptor */
-  int          temppid;                /* Process ID of cups-driverd */
-  int          temppipe[2];            /* Temporary pipes */
-  char         *argv[4],               /* Command-line arguments */
-               *envp[MAX_ENV];         /* Environment */
-  cups_file_t  *src,                   /* Source file */
-               *dst;                   /* Destination file */
-  int          bytes,                  /* Bytes from pipe */
-               total;                  /* Total bytes from pipe */
-  char         buffer[2048],           /* Copy buffer */
-               *ptr;                   /* Pointer into buffer */
-  int          i;                      /* Looping var */
-  char         option[PPD_MAX_NAME],   /* Option name */
-               choice[PPD_MAX_NAME];   /* Choice name */
-  int          num_defaults;           /* Number of default options */
-  ppd_default_t        *defaults;              /* Default options */
-  char         cups_protocol[PPD_MAX_LINE];
-                                       /* cupsProtocol attribute */
-  int          have_letter,            /* Have Letter size */
-               have_a4;                /* Have A4 size */
-#ifdef HAVE_LIBPAPER
-  char         *paper_result;          /* Paper size name from libpaper */
-  char         system_paper[64];       /* Paper size name buffer */
-#endif /* HAVE_LIBPAPER */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *toattr;        /* Destination attribute */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
-                 con, from, to);
-
- /*
-  * Run cups-driverd to get the PPD file...
-  */
+                  "copy_attribute(%p, %p[%s,%x,%x])", to, attr,
+                 attr->name ? attr->name : "(null)", attr->group_tag,
+                 attr->value_tag);
 
-  argv[0] = "cups-driverd";
-  argv[1] = "cat";
-  argv[2] = (char *)from;
-  argv[3] = NULL;
+  switch (attr->value_tag & ~IPP_TAG_COPY)
+  {
+    case IPP_TAG_ZERO :
+        toattr = ippAddSeparator(to);
+       break;
 
-  cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+    case IPP_TAG_INTEGER :
+    case IPP_TAG_ENUM :
+        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,
+                               attr->name, attr->num_values, NULL);
 
-  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)
-    return (-1);
+        for (i = 0; i < attr->num_values; i ++)
+         toattr->values[i].integer = attr->values[i].integer;
+        break;
 
-  cupsdOpenPipe(temppipe);
+    case IPP_TAG_BOOLEAN :
+        toattr = ippAddBooleans(to, attr->group_tag, attr->name,
+                               attr->num_values, NULL);
 
-  if ((input = calloc(1, SetSize)) == NULL)
-  {
-    close(tempfd);
-    unlink(tempfile);
+        for (i = 0; i < attr->num_values; i ++)
+         toattr->values[i].boolean = attr->values[i].boolean;
+        break;
 
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "copy_model: Unable to allocate %d bytes for select()...",
-                    SetSize);
-    return (-1);
-  }
+    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);
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG,
-                  "copy_model: Running \"cups-driverd cat %s\"...", from);
+        if (quickcopy)
+       {
+          for (i = 0; i < attr->num_values; i ++)
+           toattr->values[i].string.text = attr->values[i].string.text;
+        }
+       else
+       {
+          for (i = 0; i < attr->num_values; i ++)
+           toattr->values[i].string.text = _cups_sp_alloc(attr->values[i].string.text);
+       }
+        break;
 
-  if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
-                         -1, 0, &temppid))
-  {
-    free(input);
-    close(tempfd);
-    unlink(tempfile);
-    return (-1);
-  }
+    case IPP_TAG_DATE :
+        toattr = ippAddDate(to, attr->group_tag, attr->name,
+                           attr->values[0].date);
+        break;
 
-  close(temppipe[1]);
+    case IPP_TAG_RESOLUTION :
+        toattr = ippAddResolutions(to, attr->group_tag, attr->name,
+                                  attr->num_values, IPP_RES_PER_INCH,
+                                  NULL, NULL);
 
- /*
-  * Wait up to 30 seconds for the PPD file to be copied...
-  */
+        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;
 
-  total = 0;
+    case IPP_TAG_RANGE :
+        toattr = ippAddRanges(to, attr->group_tag, attr->name,
+                             attr->num_values, NULL, NULL);
 
-  if (temppipe[0] > CGIPipes[0])
-    maxfd = temppipe[0] + 1;
-  else
-    maxfd = CGIPipes[0] + 1;
+        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;
 
-  for (;;)
-  {
-   /*
-    * See if we have data ready...
-    */
+    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);
 
-    bytes = 0;
+        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
+       {
+          for (i = 0; i < attr->num_values; i ++)
+         {
+           if (!i)
+              toattr->values[i].string.charset =
+                 _cups_sp_alloc(attr->values[i].string.charset);
+           else
+              toattr->values[i].string.charset =
+                 toattr->values[0].string.charset;
 
-    FD_SET(temppipe[0], input);
-    FD_SET(CGIPipes[0], input);
+           toattr->values[i].string.text = _cups_sp_alloc(attr->values[i].string.text);
+          }
+        }
+        break;
 
-    timeout.tv_sec  = 30;
-    timeout.tv_usec = 0;
+    case IPP_TAG_BEGIN_COLLECTION :
+        toattr = ippAddCollections(to, attr->group_tag, attr->name,
+                                  attr->num_values, NULL);
 
-    if ((i = select(maxfd, input, NULL, NULL, &timeout)) < 0)
-    {
-      if (errno == EINTR)
-        continue;
-      else
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         toattr->values[i].collection = ippNew();
+         copy_attrs(toattr->values[i].collection, attr->values[i].collection,
+                    NULL, IPP_TAG_ZERO, 0);
+       }
         break;
-    }
-    else if (i == 0)
-    {
-     /*
-      * We have timed out...
-      */
 
-      break;
-    }
+    default :
+        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,
+                               attr->name, attr->num_values, NULL);
 
-    if (FD_ISSET(temppipe[0], input))
-    {
-     /*
-      * Read the PPD file from the pipe, and write it to the PPD file.
-      */
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         toattr->values[i].unknown.length = attr->values[i].unknown.length;
 
-      if ((bytes = read(temppipe[0], buffer, sizeof(buffer))) > 0)
-      {
-       if (write(tempfd, buffer, bytes) < bytes)
-          break;
+         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 */
+  }
 
-       total += bytes;
-      }
-      else
-       break;
-    }
+  return (toattr);
+}
+
+
+/*
+ * 'copy_attrs()' - Copy attributes from one request to another.
+ */
+
+static void
+copy_attrs(ipp_t        *to,           /* I - Destination request */
+           ipp_t        *from,         /* I - Source request */
+           cups_array_t *ra,           /* I - Requested attributes */
+          ipp_tag_t    group,          /* I - Group to copy */
+          int          quickcopy)      /* I - Do a quick copy? */
+{
+  ipp_attribute_t      *fromattr;      /* Source attribute */
 
-    if (FD_ISSET(CGIPipes[0], input))
-      cupsdUpdateCGI();
-  }
 
-  close(temppipe[0]);
-  close(tempfd);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
+                 to, from, ra, group, quickcopy);
 
-  free(input);
+  if (!to || !from)
+    return;
 
-  if (!total)
+  for (fromattr = from->attrs; fromattr; fromattr = fromattr->next)
   {
    /*
-    * No data from cups-deviced...
+    * Filter attributes as needed...
     */
 
-    cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file!");
-    unlink(tempfile);
-    return (-1);
+    if (group != IPP_TAG_ZERO && fromattr->group_tag != group &&
+        fromattr->group_tag != IPP_TAG_ZERO && !fromattr->name)
+      continue;
+
+    if (!ra || cupsArrayFind(ra, fromattr->name))
+      copy_attribute(to, fromattr, quickcopy);
   }
+}
 
- /*
-  * Read the source file and see what page sizes are supported...
-  */
 
-  if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
-  {
-    unlink(tempfile);
-    return (-1);
-  }
+/*
+ * 'copy_banner()' - Copy a banner file to the requests directory for the
+ *                   specified job.
+ */
 
-  have_letter = 0;
-  have_a4     = 0;
+static int                             /* O - Size of banner file in kbytes */
+copy_banner(cupsd_client_t *con,       /* I - Client connection */
+            cupsd_job_t    *job,       /* I - Job information */
+            const char     *name)      /* I - Name of banner */
+{
+  int          i;                      /* Looping var */
+  int          kbytes;                 /* Size of banner file in kbytes */
+  char         filename[1024];         /* Job filename */
+  cupsd_banner_t *banner;              /* Pointer to banner */
+  cups_file_t  *in;                    /* Input file */
+  cups_file_t  *out;                   /* Output file */
+  int          ch;                     /* Character from file */
+  char         attrname[255],          /* Name of attribute */
+               *s;                     /* Pointer into name */
+  ipp_attribute_t *attr;               /* Attribute */
 
-  while (cupsFileGets(src, buffer, sizeof(buffer)))
-    if (!strncmp(buffer, "*PageSize ", 10))
-    {
-     /*
-      * Strip UI text and command data from the end of the line...
-      */
 
-      if ((ptr = strchr(buffer + 10, '/')) != NULL)
-        *ptr = '\0';
-      if ((ptr = strchr(buffer + 10, ':')) != NULL)
-        *ptr = '\0';
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner(%p[%d], %p[%d], %s)",
+                  con, con->http.fd, job, job->id, name ? name : "(null)");
 
-      for (ptr = buffer + 10; isspace(*ptr); ptr ++);
+ /*
+  * Find the banner; return if not found or "none"...
+  */
 
-     /*
-      * Look for Letter and A4 page sizes...
-      */
+  if (!name || !strcmp(name, "none") ||
+      (banner = cupsdFindBanner(name)) == NULL)
+    return (0);
 
-      if (!strcmp(ptr, "Letter"))
-       have_letter = 1;
+ /*
+  * Open the banner and job files...
+  */
 
-      if (!strcmp(ptr, "A4"))
-       have_a4 = 1;
-    }
+  if (add_file(con, job, banner->filetype, 0))
+    return (0);
 
-  cupsFileRewind(src);
+  snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
+           job->num_files);
+  if ((out = cupsFileOpen(filename, "w")) == NULL)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "copy_banner: Unable to create banner job file %s - %s",
+                    filename, strerror(errno));
+    job->num_files --;
+    return (0);
+  }
+
+  fchmod(cupsFileNumber(out), 0640);
+  fchown(cupsFileNumber(out), RunUser, Group);
 
  /*
-  * Open the destination (if possible) and set the default options...
+  * Try the localized banner file under the subdirectory...
   */
 
-  num_defaults     = 0;
-  defaults         = NULL;
-  cups_protocol[0] = '\0';
-
-  if ((dst = cupsFileOpen(to, "rb")) != NULL)
+  strlcpy(attrname, con->request->attrs->next->values[0].string.text,
+          sizeof(attrname));
+  if (strlen(attrname) > 2 && attrname[2] == '-')
   {
    /*
-    * Read all of the default lines from the old PPD...
+    * Convert ll-cc to ll_CC...
     */
 
-    while (cupsFileGets(dst, buffer, sizeof(buffer)))
-      if (!strncmp(buffer, "*Default", 8))
-      {
-       /*
-       * Add the default option...
-       */
+    attrname[2] = '_';
+    attrname[3] = toupper(attrname[3] & 255);
+    attrname[4] = toupper(attrname[4] & 255);
+  }
 
-        if (!ppd_parse_line(buffer, option, sizeof(option),
-                           choice, sizeof(choice)))
-          num_defaults = ppd_add_default(option, choice, num_defaults,
-                                        &defaults);
-      }
-      else if (!strncmp(buffer, "*cupsProtocol:", 14))
-        strlcpy(cups_protocol, buffer, sizeof(cups_protocol));
+  snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,
+           attrname, name);
 
-    cupsFileClose(dst);
-  }
-#ifdef HAVE_LIBPAPER
-  else if ((paper_result = systempapername()) != NULL)
+  if (access(filename, 0) && strlen(attrname) > 2)
   {
    /*
-    * Set the default media sizes from the systemwide default...
+    * Wasn't able to find "ll_CC" locale file; try the non-national
+    * localization banner directory.
     */
 
-    strlcpy(system_paper, paper_result, sizeof(system_paper));
-    system_paper[0] = toupper(system_paper[0] & 255);
+    attrname[2] = '\0';
 
-    if ((!strcmp(system_paper, "Letter") && have_letter) ||
-        (!strcmp(system_paper, "A4") && have_a4))
-    {
-      num_defaults = ppd_add_default("PageSize", system_paper, 
-                                    num_defaults, &defaults);
-      num_defaults = ppd_add_default("PageRegion", system_paper, 
-                                    num_defaults, &defaults);
-      num_defaults = ppd_add_default("PaperDimension", system_paper, 
-                                    num_defaults, &defaults);
-      num_defaults = ppd_add_default("ImageableArea", system_paper, 
-                                    num_defaults, &defaults);
-    }
+    snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,
+             attrname, name);
   }
-#endif /* HAVE_LIBPAPER */
-  else
+
+  if (access(filename, 0))
   {
    /*
-    * Add the default media sizes...
-    *
-    * Note: These values are generally not valid for large-format devices
-    *       like plotters, however it is probably safe to say that those
-    *       users will configure the media size after initially adding
-    *       the device anyways...
+    * Use the non-localized banner file.
     */
 
-    if (!DefaultLanguage ||
-        !strcasecmp(DefaultLanguage, "C") ||
-        !strcasecmp(DefaultLanguage, "POSIX") ||
-       !strcasecmp(DefaultLanguage, "en") ||
-       !strncasecmp(DefaultLanguage, "en_US", 5) ||
-       !strncasecmp(DefaultLanguage, "en_CA", 5) ||
-       !strncasecmp(DefaultLanguage, "fr_CA", 5))
-    {
-     /*
-      * These are the only locales that will default to "letter" size...
-      */
-
-      if (have_letter)
-      {
-       num_defaults = ppd_add_default("PageSize", "Letter", num_defaults,
-                                       &defaults);
-       num_defaults = ppd_add_default("PageRegion", "Letter", num_defaults,
-                                       &defaults);
-       num_defaults = ppd_add_default("PaperDimension", "Letter", num_defaults,
-                                       &defaults);
-       num_defaults = ppd_add_default("ImageableArea", "Letter", num_defaults,
-                                       &defaults);
-      }
-    }
-    else if (have_a4)
-    {
-     /*
-      * The rest default to "a4" size...
-      */
+    snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);
+  }
 
-      num_defaults = ppd_add_default("PageSize", "A4", num_defaults,
-                                     &defaults);
-      num_defaults = ppd_add_default("PageRegion", "A4", num_defaults,
-                                     &defaults);
-      num_defaults = ppd_add_default("PaperDimension", "A4", num_defaults,
-                                     &defaults);
-      num_defaults = ppd_add_default("ImageableArea", "A4", num_defaults,
-                                     &defaults);
-    }
+  if ((in = cupsFileOpen(filename, "r")) == NULL)
+  {
+    cupsFileClose(out);
+    unlink(filename);
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "copy_banner: Unable to open banner template file %s - %s",
+                    filename, strerror(errno));
+    job->num_files --;
+    return (0);
   }
 
  /*
-  * Open the destination file for a copy...
+  * Parse the file to the end...
   */
 
-  if ((dst = cupsFileOpen(to, "wb")) == NULL)
-  {
-    if (num_defaults > 0)
-      free(defaults);
+  while ((ch = cupsFileGetChar(in)) != EOF)
+    if (ch == '{')
+    {
+     /*
+      * Get an attribute name...
+      */
 
-    cupsFileClose(src);
-    unlink(tempfile);
-    return (-1);
-  }
+      for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;)
+        if (!isalpha(ch & 255) && ch != '-' && ch != '?')
+          break;
+       else if (s < (attrname + sizeof(attrname) - 1))
+          *s++ = ch;
+       else
+         break;
 
- /*
-  * Copy the source file to the destination...
-  */
+      *s = '\0';
+
+      if (ch != '}')
+      {
+       /*
+        * Ignore { followed by stuff that is not an attribute name...
+       */
+
+        cupsFilePrintf(out, "{%s%c", attrname, ch);
+       continue;
+      }
 
-  while (cupsFileGets(src, buffer, sizeof(buffer)))
-  {
-    if (!strncmp(buffer, "*Default", 8))
-    {
      /*
-      * Check for an previous default option choice...
+      * See if it is defined...
       */
 
-      if (!ppd_parse_line(buffer, option, sizeof(option),
-                         choice, sizeof(choice)))
-      {
-        for (i = 0; i < num_defaults; i ++)
-         if (!strcmp(option, defaults[i].option))
-         {
-          /*
-           * Substitute the previous choice...
-           */
+      if (attrname[0] == '?')
+        s = attrname + 1;
+      else
+        s = attrname;
 
-           snprintf(buffer, sizeof(buffer), "*Default%s: %s", option,
-                    defaults[i].choice);
-           break;
-         }
+      if (!strcmp(s, "printer-name"))
+      {
+        cupsFilePuts(out, job->dest);
+       continue;
       }
-    }
+      else if ((attr = ippFindAttribute(job->attrs, s, IPP_TAG_ZERO)) == NULL)
+      {
+       /*
+        * See if we have a leading question mark...
+       */
 
-    cupsFilePrintf(dst, "%s\n", buffer);
-  }
+       if (attrname[0] != '?')
+       {
+        /*
+          * Nope, write to file as-is; probably a PostScript procedure...
+         */
 
-  if (cups_protocol[0])
-    cupsFilePrintf(dst, "%s\n", cups_protocol);
+         cupsFilePrintf(out, "{%s}", attrname);
+        }
 
-  if (num_defaults > 0)
-    free(defaults);
+        continue;
+      }
 
- /*
-  * Close both files and return...
-  */
    /*
+      * Output value(s)...
+      */
 
-  cupsFileClose(src);
+      for (i = 0; i < attr->num_values; i ++)
+      {
+       if (i)
+         cupsFilePutChar(out, ',');
 
-  unlink(tempfile);
+       switch (attr->value_tag)
+       {
+         case IPP_TAG_INTEGER :
+         case IPP_TAG_ENUM :
+             if (!strncmp(s, "time-at-", 8))
+               cupsFilePuts(out, cupsdGetDateTime(attr->values[i].integer));
+             else
+               cupsFilePrintf(out, "%d", attr->values[i].integer);
+             break;
 
-  return (cupsFileClose(dst));
-}
+         case IPP_TAG_BOOLEAN :
+             cupsFilePrintf(out, "%d", attr->values[i].boolean);
+             break;
 
+         case IPP_TAG_NOVALUE :
+             cupsFilePuts(out, "novalue");
+             break;
 
-/*
- * 'copy_job_attrs()' - Copy job attributes.
- */
+         case IPP_TAG_RANGE :
+             cupsFilePrintf(out, "%d-%d", attr->values[i].range.lower,
+                     attr->values[i].range.upper);
+             break;
 
-static void
-copy_job_attrs(cupsd_client_t *con,    /* I - Client connection */
-              cupsd_job_t    *job,     /* I - Job */
-              cups_array_t   *ra)      /* I - Requested attributes array */
-{
-  char job_uri[HTTP_MAX_URI];          /* Job URI */
+         case IPP_TAG_RESOLUTION :
+             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");
+             break;
 
+         case IPP_TAG_URI :
+          case IPP_TAG_STRING :
+         case IPP_TAG_TEXT :
+         case IPP_TAG_NAME :
+         case IPP_TAG_KEYWORD :
+         case IPP_TAG_CHARSET :
+         case IPP_TAG_LANGUAGE :
+             if (!strcasecmp(banner->filetype->type, "postscript"))
+             {
+              /*
+               * Need to quote strings for PS banners...
+               */
 
- /*
-  * Send the requested attributes for each job...
-  */
+               const char *p;
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
-                   con->servername, con->serverport, "/jobs/%d",
-                  job->id);
+               for (p = attr->values[i].string.text; *p; p ++)
+               {
+                 if (*p == '(' || *p == ')' || *p == '\\')
+                 {
+                   cupsFilePutChar(out, '\\');
+                   cupsFilePutChar(out, *p);
+                 }
+                 else if (*p < 32 || *p > 126)
+                   cupsFilePrintf(out, "\\%03o", *p & 255);
+                 else
+                   cupsFilePutChar(out, *p);
+               }
+             }
+             else
+               cupsFilePuts(out, attr->values[i].string.text);
+             break;
 
-  if (!ra || cupsArrayFind(ra, "job-more-info"))
-    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
-                "job-more-info", NULL, job_uri);
+          default :
+             break; /* anti-compiler-warning-code */
+       }
+      }
+    }
+    else if (ch == '\\')       /* Quoted char */
+    {
+      ch = cupsFileGetChar(in);
 
-  if (job->state_value > IPP_JOB_PROCESSING &&
-      (!ra || cupsArrayFind(ra, "job-preserved")))
-    ippAddBoolean(con->response, IPP_TAG_JOB, "job-preserved",
-                  job->num_files > 0);
+      if (ch != '{')           /* Only do special handling for \{ */
+        cupsFilePutChar(out, '\\');
 
-  if (!ra || cupsArrayFind(ra, "job-printer-up-time"))
-    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                  "job-printer-up-time", time(NULL));
+      cupsFilePutChar(out, ch);
+    }
+    else
+      cupsFilePutChar(out, ch);
 
-  if (!ra || cupsArrayFind(ra, "job-state-reasons"))
-    add_job_state_reasons(con, job);
+  cupsFileClose(in);
 
-  if (!ra || cupsArrayFind(ra, "job-uri"))
-    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
-                "job-uri", NULL, job_uri);
+  kbytes = (cupsFileTell(out) + 1023) / 1024;
 
-  copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0);
+  if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
+                               IPP_TAG_INTEGER)) != NULL)
+    attr->values[0].integer += kbytes;
+
+  cupsFileClose(out);
+
+  return (kbytes);
 }
 
 
 /*
- * 'copy_printer_attrs()' - Copy printer attributes.
+ * 'copy_file()' - Copy a PPD file or interface script...
  */
 
-static void
-copy_printer_attrs(
-    cupsd_client_t  *con,              /* I - Client connection */
-    cupsd_printer_t *printer,          /* I - Printer */
-    cups_array_t    *ra)               /* I - Requested attributes array */
+static int                             /* O - 0 = success, -1 = error */
+copy_file(const char *from,            /* I - Source file */
+          const char *to)              /* I - Destination file */
 {
-  char                 printer_uri[HTTP_MAX_URI];
-                                       /* Printer URI */
-  time_t               curtime;        /* Current time */
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *history;       /* History collection */
+  cups_file_t  *src,                   /* Source file */
+               *dst;                   /* Destination file */
+  int          bytes;                  /* Bytes to read/write */
+  char         buffer[2048];           /* Copy buffer */
 
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_file(\"%s\", \"%s\")", from, to);
+
  /*
-  * Copy the printer attributes to the response using requested-attributes
-  * and document-format attributes that may be provided by the client.
+  * Open the source and destination file for a copy...
   */
 
-  curtime = time(NULL);
-
-#ifdef __APPLE__
-  if ((!ra || cupsArrayFind(ra, "com.apple.print.recoverable-message")) &&
-      printer->recoverable)
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
-                 "com.apple.print.recoverable-message", NULL,
-                printer->recoverable);
-#endif /* __APPLE__ */
-
-  if (!ra || cupsArrayFind(ra, "printer-current-time"))
-    ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
-               ippTimeToDate(curtime));
-
-  if (!ra || cupsArrayFind(ra, "printer-error-policy"))
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
-                "printer-error-policy", NULL, printer->error_policy);
-
-  if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs"))
-    ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
-                  printer->accepting);
-
-  if (!ra || cupsArrayFind(ra, "printer-is-shared"))
-    ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
-                  printer->shared);
+  if ((src = cupsFileOpen(from, "rb")) == NULL)
+    return (-1);
 
-  if (!ra || cupsArrayFind(ra, "printer-op-policy"))
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
-                "printer-op-policy", NULL, printer->op_policy);
+  if ((dst = cupsFileOpen(to, "wb")) == NULL)
+  {
+    cupsFileClose(src);
+    return (-1);
+  }
 
-  if (!ra || cupsArrayFind(ra, "printer-state"))
-    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
-                  printer->state);
+ /*
+  * Copy the source file to the destination...
+  */
 
-  if (!ra || cupsArrayFind(ra, "printer-state-change-time"))
-    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                  "printer-state-change-time", printer->state_time);
-                
-  if (MaxPrinterHistory > 0 && printer->num_history > 0 &&
-      cupsArrayFind(ra, "printer-state-history"))
-  {
-   /*
-    * Printer history is only sent if specifically requested, so that
-    * older CUPS/IPP clients won't barf on the collection attributes.
-    */
+  while ((bytes = cupsFileRead(src, buffer, sizeof(buffer))) > 0)
+    if (cupsFileWrite(dst, buffer, bytes) < bytes)
+    {
+      cupsFileClose(src);
+      cupsFileClose(dst);
+      return (-1);
+    }
 
-    history = ippAddCollections(con->response, IPP_TAG_PRINTER,
-                                "printer-state-history",
-                                printer->num_history, NULL);
+ /*
+  * Close both files and return...
+  */
 
-    for (i = 0; i < printer->num_history; i ++)
-      copy_attrs(history->values[i].collection = ippNew(), printer->history[i],
-                 NULL, IPP_TAG_ZERO, 0);
-  }
+  cupsFileClose(src);
 
-  if (!ra || cupsArrayFind(ra, "printer-state-message"))
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
-                "printer-state-message", NULL, printer->state_message);
+  return (cupsFileClose(dst));
+}
 
-  if (!ra || cupsArrayFind(ra, "printer-state-reasons"))
-    add_printer_state_reasons(con, printer);
 
-  if (!ra || cupsArrayFind(ra, "printer-type"))
-  {
-    int type;                          /* printer-type value */
+/*
+ * 'copy_model()' - Copy a PPD model file, substituting default values
+ *                  as needed...
+ */
 
+static int                             /* O - 0 = success, -1 = error */
+copy_model(cupsd_client_t *con,                /* I - Client connection */
+           const char     *from,       /* I - Source file */
+           const char     *to)         /* I - Destination file */
+{
+  fd_set       *input;                 /* select() input set */
+  struct timeval timeout;              /* select() timeout */
+  int          maxfd;                  /* Maximum file descriptor for select() */
+  char         tempfile[1024];         /* Temporary PPD file */
+  int          tempfd;                 /* Temporary PPD file descriptor */
+  int          temppid;                /* Process ID of cups-driverd */
+  int          temppipe[2];            /* Temporary pipes */
+  char         *argv[4],               /* Command-line arguments */
+               *envp[MAX_ENV];         /* Environment */
+  cups_file_t  *src,                   /* Source file */
+               *dst;                   /* Destination file */
+  int          bytes,                  /* Bytes from pipe */
+               total;                  /* Total bytes from pipe */
+  char         buffer[2048],           /* Copy buffer */
+               *ptr;                   /* Pointer into buffer */
+  int          i;                      /* Looping var */
+  char         option[PPD_MAX_NAME],   /* Option name */
+               choice[PPD_MAX_NAME];   /* Choice name */
+  int          num_defaults;           /* Number of default options */
+  ppd_default_t        *defaults;              /* Default options */
+  char         cups_protocol[PPD_MAX_LINE];
+                                       /* cupsProtocol attribute */
+  int          have_letter,            /* Have Letter size */
+               have_a4;                /* Have A4 size */
+#ifdef HAVE_LIBPAPER
+  char         *paper_result;          /* Paper size name from libpaper */
+  char         system_paper[64];       /* Paper size name buffer */
+#endif /* HAVE_LIBPAPER */
 
-   /*
-    * Add the CUPS-specific printer-type attribute...
-    */
 
-    type = printer->type;
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
+                 con, from, to);
 
-    if (printer == DefaultPrinter)
-      type |= CUPS_PRINTER_DEFAULT;
+ /*
+  * Run cups-driverd to get the PPD file...
+  */
 
-    if (!printer->accepting)
-      type |= CUPS_PRINTER_REJECTING;
+  argv[0] = "cups-driverd";
+  argv[1] = "cat";
+  argv[2] = (char *)from;
+  argv[3] = NULL;
 
-    if (!printer->shared)
-      type |= CUPS_PRINTER_NOT_SHARED;
+  cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
 
-    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",
-                 type);
+  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)
+    return (-1);
+
+  cupsdOpenPipe(temppipe);
+
+  if ((input = calloc(1, SetSize)) == NULL)
+  {
+    close(tempfd);
+    unlink(tempfile);
+
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "copy_model: Unable to allocate %d bytes for select()...",
+                    SetSize);
+    return (-1);
   }
 
-  if (!ra || cupsArrayFind(ra, "printer-up-time"))
-    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                  "printer-up-time", curtime);
+  cupsdLogMessage(CUPSD_LOG_DEBUG,
+                  "copy_model: Running \"cups-driverd cat %s\"...", from);
 
-  if ((!ra || cupsArrayFind(ra, "printer-uri-supported")) &&
-      !ippFindAttribute(printer->attrs, "printer-uri-supported",
-                        IPP_TAG_URI))
+  if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
+                         -1, 0, &temppid))
   {
-    httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
-                     "ipp", NULL, con->servername, con->serverport,
-                    "/printers/%s", printer->name);
-    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
-                "printer-uri-supported", NULL, printer_uri);
-    cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"",
-                    printer_uri);
+    free(input);
+    close(tempfd);
+    unlink(tempfile);
+    return (-1);
   }
 
-  if (!ra || cupsArrayFind(ra, "queued-job-count"))
-    add_queued_job_count(con, printer);
+  close(temppipe[1]);
 
-  copy_attrs(con->response, printer->attrs, ra, IPP_TAG_ZERO, 0);
-  copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY);
-}
+ /*
+  * Wait up to 30 seconds for the PPD file to be copied...
+  */
 
+  total = 0;
 
-/*
- * 'copy_subscription_attrs()' - Copy subscription attributes.
- */
+  if (temppipe[0] > CGIPipes[0])
+    maxfd = temppipe[0] + 1;
+  else
+    maxfd = CGIPipes[0] + 1;
 
-static void
-copy_subscription_attrs(
-    cupsd_client_t       *con,         /* I - Client connection */
-    cupsd_subscription_t *sub,         /* I - Subscription */
-    cups_array_t         *ra)          /* I - Requested attributes array */
-{
-  ipp_attribute_t      *attr;          /* Current attribute */
-  char                 printer_uri[HTTP_MAX_URI];
-                                       /* Printer URI */
-  int                  count;          /* Number of events */
-  unsigned             mask;           /* Current event mask */
-  const char           *name;          /* Current event name */
+  for (;;)
+  {
+   /*
+    * See if we have data ready...
+    */
 
+    bytes = 0;
 
- /*
-  * Copy the subscription attributes to the response using the
-  * requested-attributes attribute that may be provided by the client.
-  */
+    FD_SET(temppipe[0], input);
+    FD_SET(CGIPipes[0], input);
 
-  if (!ra || cupsArrayFind(ra, "notify-events"))
-  {
-    if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
+    timeout.tv_sec  = 30;
+    timeout.tv_usec = 0;
+
+    if ((i = select(maxfd, input, NULL, NULL, &timeout)) < 0)
+    {
+      if (errno == EINTR)
+        continue;
+      else
+        break;
+    }
+    else if (i == 0)
     {
      /*
-      * Simple event list...
+      * We have timed out...
       */
 
-      ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
-                   IPP_TAG_KEYWORD | IPP_TAG_COPY,
-                   "notify-events", NULL, name);
+      break;
     }
-    else
+
+    if (FD_ISSET(temppipe[0], input))
     {
      /*
-      * Complex event list...
+      * Read the PPD file from the pipe, and write it to the PPD file.
       */
 
-      for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
-       if (sub->mask & mask)
-          count ++;
-
-      attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
-                           IPP_TAG_KEYWORD | IPP_TAG_COPY,
-                           "notify-events", count, NULL, NULL);
-
-      for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
-       if (sub->mask & mask)
-       {
-          attr->values[count].string.text =
-             (char *)cupsdEventName((cupsd_eventmask_t)mask);
+      if ((bytes = read(temppipe[0], buffer, sizeof(buffer))) > 0)
+      {
+       if (write(tempfd, buffer, bytes) < bytes)
+          break;
 
-          count ++;
-       }
+       total += bytes;
+      }
+      else
+       break;
     }
+
+    if (FD_ISSET(CGIPipes[0], input))
+      cupsdUpdateCGI();
   }
 
-  if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id")))
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-job-id", sub->job->id);
+  close(temppipe[0]);
+  close(tempfd);
 
-  if (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration")))
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-lease-duration", sub->lease);
+  free(input);
 
-  if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri")))
+  if (!total)
   {
-    httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
-                     "ipp", NULL, con->servername, con->serverport,
-                    "/printers/%s", sub->dest->name);
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
-                "notify-printer-uri", NULL, printer_uri);
+   /*
+    * No data from cups-deviced...
+    */
+
+    cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file!");
+    unlink(tempfile);
+    return (-1);
   }
 
-  if (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri")))
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
-                "notify-recipient-uri", NULL, sub->recipient);
-  else if (!ra || cupsArrayFind(ra, "notify-pull-method"))
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
-                 "notify-pull-method", NULL, "ippget");
+ /*
+  * Read the source file and see what page sizes are supported...
+  */
 
-  if (!ra || cupsArrayFind(ra, "notify-subscriber-user-name"))
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
-                "notify-subscriber-user-name", NULL, sub->owner);
+  if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
+  {
+    unlink(tempfile);
+    return (-1);
+  }
 
-  if (!ra || cupsArrayFind(ra, "notify-subscription-id"))
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-subscription-id", sub->id);
+  have_letter = 0;
+  have_a4     = 0;
 
-  if (!ra || cupsArrayFind(ra, "notify-time-interval"))
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-time-interval", sub->interval);
+  while (cupsFileGets(src, buffer, sizeof(buffer)))
+    if (!strncmp(buffer, "*PageSize ", 10))
+    {
+     /*
+      * Strip UI text and command data from the end of the line...
+      */
 
-  if (sub->user_data_len > 0 && (!ra || cupsArrayFind(ra, "notify-user-data")))
-    ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
-                      sub->user_data, sub->user_data_len);
-}
+      if ((ptr = strchr(buffer + 10, '/')) != NULL)
+        *ptr = '\0';
+      if ((ptr = strchr(buffer + 10, ':')) != NULL)
+        *ptr = '\0';
 
+      for (ptr = buffer + 10; isspace(*ptr); ptr ++);
 
-/*
* 'create_job()' - Print a file to a printer or class.
- */
+     /*
     * Look for Letter and A4 page sizes...
     */
 
-static void
-create_job(cupsd_client_t  *con,       /* I - Client connection */
-          ipp_attribute_t *uri)        /* I - Printer URI */
-{
-  http_status_t        status;                 /* Policy status */
-  ipp_attribute_t *attr;               /* Current attribute */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
-  int          priority;               /* Job priority */
-  char         *title;                 /* Job name/title */
-  cupsd_job_t  *job;                   /* Current job */
-  char         job_uri[HTTP_MAX_URI],  /* Job URI */
-               method[HTTP_MAX_URI],   /* Method portion of URI */
-               username[HTTP_MAX_URI], /* Username portion of URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI]; /* Resource portion of URI */
-  int          port;                   /* Port portion of URI */
-  cupsd_printer_t *printer;            /* Printer data */
-  int          kbytes;                 /* Size of print file */
-  int          i;                      /* Looping var */
-  int          lowerpagerange;         /* Page range bound */
+      if (!strcmp(ptr, "Letter"))
+       have_letter = 1;
 
+      if (!strcmp(ptr, "A4"))
+       have_a4 = 1;
+    }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
-                  con->http.fd, uri->values[0].string.text);
+  cupsFileRewind(src);
 
  /*
-  * Is the destination valid?
+  * Open the destination (if possible) and set the default options...
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
+  num_defaults     = 0;
+  defaults         = NULL;
+  cups_protocol[0] = '\0';
 
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  if ((dst = cupsFileOpen(to, "rb")) != NULL)
   {
    /*
-    * Bad URI...
+    * Read all of the default lines from the old PPD...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return;
-  }
+    while (cupsFileGets(dst, buffer, sizeof(buffer)))
+      if (!strncmp(buffer, "*Default", 8))
+      {
+       /*
+       * Add the default option...
+       */
 
- /*
-  * Check remote printing to non-shared printer...
-  */
+        if (!ppd_parse_line(buffer, option, sizeof(option),
+                           choice, sizeof(choice)))
+          num_defaults = ppd_add_default(option, choice, num_defaults,
+                                        &defaults);
+      }
+      else if (!strncmp(buffer, "*cupsProtocol:", 14))
+        strlcpy(cups_protocol, buffer, sizeof(cups_protocol));
 
-  if (!printer->shared &&
-      strcasecmp(con->http.hostname, "localhost") &&
-      strcasecmp(con->http.hostname, ServerName))
-  {
-    send_ipp_status(con, IPP_NOT_AUTHORIZED,
-                    _("The printer or class is not shared!"));
-    return;
+    cupsFileClose(dst);
   }
+#ifdef HAVE_LIBPAPER
+  else if ((paper_result = systempapername()) != NULL)
+  {
+   /*
+    * Set the default media sizes from the systemwide default...
+    */
 
- /*
-  * Check policy...
-  */
+    strlcpy(system_paper, paper_result, sizeof(system_paper));
+    system_paper[0] = toupper(system_paper[0] & 255);
 
-  if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
+    if ((!strcmp(system_paper, "Letter") && have_letter) ||
+        (!strcmp(system_paper, "A4") && have_a4))
+    {
+      num_defaults = ppd_add_default("PageSize", system_paper, 
+                                    num_defaults, &defaults);
+      num_defaults = ppd_add_default("PageRegion", system_paper, 
+                                    num_defaults, &defaults);
+      num_defaults = ppd_add_default("PaperDimension", system_paper, 
+                                    num_defaults, &defaults);
+      num_defaults = ppd_add_default("ImageableArea", system_paper, 
+                                    num_defaults, &defaults);
+    }
   }
-  else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
+#endif /* HAVE_LIBPAPER */
+  else
   {
-    send_http_error(con, HTTP_UNAUTHORIZED);
-    return;
+   /*
+    * Add the default media sizes...
+    *
+    * Note: These values are generally not valid for large-format devices
+    *       like plotters, however it is probably safe to say that those
+    *       users will configure the media size after initially adding
+    *       the device anyways...
+    */
+
+    if (!DefaultLanguage ||
+        !strcasecmp(DefaultLanguage, "C") ||
+        !strcasecmp(DefaultLanguage, "POSIX") ||
+       !strcasecmp(DefaultLanguage, "en") ||
+       !strncasecmp(DefaultLanguage, "en_US", 5) ||
+       !strncasecmp(DefaultLanguage, "en_CA", 5) ||
+       !strncasecmp(DefaultLanguage, "fr_CA", 5))
+    {
+     /*
+      * These are the only locales that will default to "letter" size...
+      */
+
+      if (have_letter)
+      {
+       num_defaults = ppd_add_default("PageSize", "Letter", num_defaults,
+                                       &defaults);
+       num_defaults = ppd_add_default("PageRegion", "Letter", num_defaults,
+                                       &defaults);
+       num_defaults = ppd_add_default("PaperDimension", "Letter", num_defaults,
+                                       &defaults);
+       num_defaults = ppd_add_default("ImageableArea", "Letter", num_defaults,
+                                       &defaults);
+      }
+    }
+    else if (have_a4)
+    {
+     /*
+      * The rest default to "a4" size...
+      */
+
+      num_defaults = ppd_add_default("PageSize", "A4", num_defaults,
+                                     &defaults);
+      num_defaults = ppd_add_default("PageRegion", "A4", num_defaults,
+                                     &defaults);
+      num_defaults = ppd_add_default("PaperDimension", "A4", num_defaults,
+                                     &defaults);
+      num_defaults = ppd_add_default("ImageableArea", "A4", num_defaults,
+                                     &defaults);
+    }
   }
 
  /*
-  * See if the printer is accepting jobs...
+  * Open the destination file for a copy...
   */
 
-  if (!printer->accepting)
+  if ((dst = cupsFileOpen(to, "wb")) == NULL)
   {
-    send_ipp_status(con, IPP_NOT_ACCEPTING,
-                    _("Destination \"%s\" is not accepting jobs."),
-                    dest);
-    return;
+    if (num_defaults > 0)
+      free(defaults);
+
+    cupsFileClose(src);
+    unlink(tempfile);
+    return (-1);
   }
 
  /*
-  * Validate job template attributes; for now just copies and page-ranges...
+  * Copy the source file to the destination...
   */
 
-  if ((attr = ippFindAttribute(con->request, "copies",
-                               IPP_TAG_INTEGER)) != NULL)
+  while (cupsFileGets(src, buffer, sizeof(buffer)))
   {
-    if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies)
+    if (!strncmp(buffer, "*Default", 8))
     {
-      send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."),
-                      attr->values[0].integer);
-      ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
-                   "copies", attr->values[0].integer);
-      return;
-    }
-  }
+     /*
+      * Check for an previous default option choice...
+      */
 
-  if ((attr = ippFindAttribute(con->request, "page-ranges",
-                               IPP_TAG_RANGE)) != NULL)
-  {
-    for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
-    {
-      if (attr->values[i].range.lower < lowerpagerange || 
-         attr->values[i].range.lower > attr->values[i].range.upper)
+      if (!ppd_parse_line(buffer, option, sizeof(option),
+                         choice, sizeof(choice)))
       {
-       send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("Bad page-ranges values %d-%d."),
-                       attr->values[i].range.lower,
-                       attr->values[i].range.upper);
-       return;
-      }
+        for (i = 0; i < num_defaults; i ++)
+         if (!strcmp(option, defaults[i].option))
+         {
+          /*
+           * Substitute the previous choice...
+           */
 
-      lowerpagerange = attr->values[i].range.upper + 1;
+           snprintf(buffer, sizeof(buffer), "*Default%s: %s", option,
+                    defaults[i].choice);
+           break;
+         }
+      }
     }
+
+    cupsFilePrintf(dst, "%s\n", buffer);
   }
 
+  if (cups_protocol[0])
+    cupsFilePrintf(dst, "%s\n", cups_protocol);
+
+  if (num_defaults > 0)
+    free(defaults);
+
  /*
-  * Make sure we aren't over our limit...
+  * Close both files and return...
   */
 
-  if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
-    cupsdCleanJobs();
+  cupsFileClose(src);
+
+  unlink(tempfile);
+
+  return (cupsFileClose(dst));
+}
+
+
+/*
+ * 'copy_job_attrs()' - Copy job attributes.
+ */
 
-  if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
-  {
-    send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Too many active jobs."));
-    return;
-  }
+static void
+copy_job_attrs(cupsd_client_t *con,    /* I - Client connection */
+              cupsd_job_t    *job,     /* I - Job */
+              cups_array_t   *ra)      /* I - Requested attributes array */
+{
+  char job_uri[HTTP_MAX_URI];          /* Job URI */
 
-  if (!check_quotas(con, printer))
-  {
-    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
-    return;
-  }
 
  /*
-  * Create the job and set things up...
+  * Send the requested attributes for each job...
   */
 
-  if ((attr = ippFindAttribute(con->request, "job-priority",
-                               IPP_TAG_INTEGER)) != NULL)
-    priority = attr->values[0].integer;
-  else
-    ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority",
-                  priority = 50);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                   con->servername, con->serverport, "/jobs/%d",
+                  job->id);
 
-  if ((attr = ippFindAttribute(con->request, "job-name",
-                               IPP_TAG_NAME)) != NULL)
-    title = attr->values[0].string.text;
-  else
-    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
-                 title = "Untitled");
+  if (!ra || cupsArrayFind(ra, "job-more-info"))
+    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
+                "job-more-info", NULL, job_uri);
 
-  if ((job = cupsdAddJob(priority, printer->name)) == NULL)
-  {
-    send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("Unable to add job for destination \"%s\"!"), dest);
-    return;
-  }
+  if (job->state_value > IPP_JOB_PROCESSING &&
+      (!ra || cupsArrayFind(ra, "job-preserved")))
+    ippAddBoolean(con->response, IPP_TAG_JOB, "job-preserved",
+                  job->num_files > 0);
 
-  job->dtype   = dtype;
-  job->attrs   = con->request;
-  con->request = NULL;
+  if (!ra || cupsArrayFind(ra, "job-printer-up-time"))
+    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                  "job-printer-up-time", time(NULL));
 
-  add_job_uuid(con, job);
+  if (!ra || cupsArrayFind(ra, "job-state-reasons"))
+    add_job_state_reasons(con, job);
 
-  attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
+  if (!ra || cupsArrayFind(ra, "job-uri"))
+    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
+                "job-uri", NULL, job_uri);
 
-  if (con->username[0])
-  {
-    cupsdSetString(&job->username, con->username);
+  copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0);
+}
 
-    if (attr)
-      cupsdSetString(&attr->values[0].string.text, con->username);
 
-    save_auth_info(con, job);
-  }
-  else if (attr)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "create_job: requesting-user-name = \"%s\"",
-                    attr->values[0].string.text);
+/*
+ * 'copy_printer_attrs()' - Copy printer attributes.
+ */
 
-    cupsdSetString(&job->username, attr->values[0].string.text);
-  }
-  else
-    cupsdSetString(&job->username, "anonymous");
+static void
+copy_printer_attrs(
+    cupsd_client_t  *con,              /* I - Client connection */
+    cupsd_printer_t *printer,          /* I - Printer */
+    cups_array_t    *ra)               /* I - Requested attributes array */
+{
+  char                 printer_uri[HTTP_MAX_URI];
+                                       /* Printer URI */
+  time_t               curtime;        /* Current time */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *history;       /* History collection */
 
-  if (!attr)
-    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
-                 "job-originating-user-name", NULL, job->username);
-  else
-  {
-    attr->group_tag = IPP_TAG_JOB;
-    cupsdSetString(&attr->name, "job-originating-user-name");
-  }
 
-  if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
-                               IPP_TAG_ZERO)) != NULL)
-  {
-   /*
-    * Request contains a job-originating-host-name attribute; validate it...
-    */
+ /*
+  * Copy the printer attributes to the response using requested-attributes
+  * and document-format attributes that may be provided by the client.
+  */
 
-    if (attr->value_tag != IPP_TAG_NAME ||
-        attr->num_values != 1 ||
-        strcmp(con->http.hostname, "localhost"))
-    {
-     /*
-      * Can't override the value if we aren't connected via localhost.
-      * Also, we can only have 1 value and it must be a name value.
-      */
+  curtime = time(NULL);
 
-      switch (attr->value_tag)
-      {
-        case IPP_TAG_STRING :
-       case IPP_TAG_TEXTLANG :
-       case IPP_TAG_NAMELANG :
-       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 :
-          /*
-           * Free old strings...
-           */
+#ifdef __APPLE__
+  if ((!ra || cupsArrayFind(ra, "com.apple.print.recoverable-message")) &&
+      printer->recoverable)
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+                 "com.apple.print.recoverable-message", NULL,
+                printer->recoverable);
+#endif /* __APPLE__ */
 
-           for (i = 0; i < attr->num_values; i ++)
-           {
-             _cups_sp_free(attr->values[i].string.text);
-             attr->values[i].string.text = NULL;
-             if (attr->values[i].string.charset)
-             {
-               _cups_sp_free(attr->values[i].string.charset);
-               attr->values[i].string.charset = NULL;
-             }
-            }
+  if (!ra || cupsArrayFind(ra, "printer-current-time"))
+    ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
+               ippTimeToDate(curtime));
 
-       default :
-            break;
-      }
+  if (!ra || cupsArrayFind(ra, "printer-error-policy"))
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
+                "printer-error-policy", NULL, printer->error_policy);
 
-     /*
-      * Use the default connection hostname instead...
-      */
+  if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs"))
+    ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
+                  printer->accepting);
 
-      attr->value_tag             = IPP_TAG_NAME;
-      attr->num_values            = 1;
-      attr->values[0].string.text = _cups_sp_alloc(con->http.hostname);
-    }
+  if (!ra || cupsArrayFind(ra, "printer-is-shared"))
+    ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
+                  printer->shared);
 
-    attr->group_tag = IPP_TAG_JOB;
-  }
-  else
+  if (!ra || cupsArrayFind(ra, "printer-op-policy"))
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
+                "printer-op-policy", NULL, printer->op_policy);
+
+  if (!ra || cupsArrayFind(ra, "printer-state"))
+    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
+                  printer->state);
+
+  if (!ra || cupsArrayFind(ra, "printer-state-change-time"))
+    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+                  "printer-state-change-time", printer->state_time);
+                
+  if (MaxPrinterHistory > 0 && printer->num_history > 0 &&
+      cupsArrayFind(ra, "printer-state-history"))
   {
    /*
-    * No job-originating-host-name attribute, so use the hostname from
-    * the connection...
+    * Printer history is only sent if specifically requested, so that
+    * older CUPS/IPP clients won't barf on the collection attributes.
     */
 
-    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
-                "job-originating-host-name", NULL, con->http.hostname);
+    history = ippAddCollections(con->response, IPP_TAG_PRINTER,
+                                "printer-state-history",
+                                printer->num_history, NULL);
+
+    for (i = 0; i < printer->num_history; i ++)
+      copy_attrs(history->values[i].collection = ippNew(), printer->history[i],
+                 NULL, IPP_TAG_ZERO, 0);
   }
 
-  ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation",
-                time(NULL));
-  attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                       "time-at-processing", 0);
-  attr->value_tag = IPP_TAG_NOVALUE;
-  attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                       "time-at-completed", 0);
-  attr->value_tag = IPP_TAG_NOVALUE;
+  if (!ra || cupsArrayFind(ra, "printer-state-message"))
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+                "printer-state-message", NULL, printer->state_message);
 
- /*
-  * Add remaining job attributes...
-  */
+  if (!ra || cupsArrayFind(ra, "printer-state-reasons"))
+    add_printer_state_reasons(con, printer);
 
-  ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
-  job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
-                             "job-state", IPP_JOB_STOPPED);
-  job->state_value = job->state->values[0].integer;
-  job->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,
-               printer->uri);
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
-               title);
+  if (!ra || cupsArrayFind(ra, "printer-type"))
+  {
+    int type;                          /* printer-type value */
 
-  if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
-                               IPP_TAG_INTEGER)) != NULL)
-    attr->values[0].integer = 0;
-  else
-    attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                         "job-k-octets", 0);
 
-  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
-                               IPP_TAG_KEYWORD)) == NULL)
-    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
-  if (!attr)
-    attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                        "job-hold-until", NULL, "no-hold");
-  if (attr && strcmp(attr->values[0].string.text, "no-hold") &&
-      !(printer->type & CUPS_PRINTER_REMOTE))
-  {
    /*
-    * Hold job until specified time...
+    * Add the CUPS-specific printer-type attribute...
     */
 
-    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+    type = printer->type;
+
+    if (printer == DefaultPrinter)
+      type |= CUPS_PRINTER_DEFAULT;
+
+    if (!printer->accepting)
+      type |= CUPS_PRINTER_REJECTING;
+
+    if (!printer->shared)
+      type |= CUPS_PRINTER_NOT_SHARED;
+
+    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",
+                 type);
   }
-  else
-    job->hold_until = time(NULL) + 60;
 
-  job->state->values[0].integer = IPP_JOB_HELD;
-  job->state_value              = IPP_JOB_HELD;
+  if (!ra || cupsArrayFind(ra, "printer-up-time"))
+    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+                  "printer-up-time", curtime);
 
-  if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
-      Classification)
+  if ((!ra || cupsArrayFind(ra, "printer-uri-supported")) &&
+      !ippFindAttribute(printer->attrs, "printer-uri-supported",
+                        IPP_TAG_URI))
   {
-   /*
-    * Add job sheets options...
-    */
+    httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
+                     "ipp", NULL, con->servername, con->serverport,
+                    "/printers/%s", printer->name);
+    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
+                "printer-uri-supported", NULL, printer_uri);
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"",
+                    printer_uri);
+  }
 
-    if ((attr = ippFindAttribute(job->attrs, "job-sheets",
-                                 IPP_TAG_ZERO)) == NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
-                      "Adding default job-sheets values \"%s,%s\"...",
-                      printer->job_sheets[0], printer->job_sheets[1]);
+  if (!ra || cupsArrayFind(ra, "queued-job-count"))
+    add_queued_job_count(con, printer);
 
-      attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
-                           2, NULL, NULL);
-      attr->values[0].string.text = _cups_sp_alloc(printer->job_sheets[0]);
-      attr->values[1].string.text = _cups_sp_alloc(printer->job_sheets[1]);
-    }
+  copy_attrs(con->response, printer->attrs, ra, IPP_TAG_ZERO, 0);
+  copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY);
+}
 
-    job->job_sheets = attr;
 
-   /*
   * Enforce classification level if set...
   */
+/*
* 'copy_subscription_attrs()' - Copy subscription attributes.
+ */
 
-    if (Classification)
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Classification=\"%s\", ClassifyOverride=%d",
-                      Classification ? Classification : "(null)",
-                     ClassifyOverride);
+static void
+copy_subscription_attrs(
+    cupsd_client_t       *con,         /* I - Client connection */
+    cupsd_subscription_t *sub,         /* I - Subscription */
+    cups_array_t         *ra)          /* I - Requested attributes array */
+{
+  ipp_attribute_t      *attr;          /* Current attribute */
+  char                 printer_uri[HTTP_MAX_URI];
+                                       /* Printer URI */
+  int                  count;          /* Number of events */
+  unsigned             mask;           /* Current event mask */
+  const char           *name;          /* Current event name */
 
-      if (ClassifyOverride)
-      {
-        if (!strcmp(attr->values[0].string.text, "none") &&
-           (attr->num_values == 1 ||
-            !strcmp(attr->values[1].string.text, "none")))
-        {
-        /*
-          * Force the leading banner to have the classification on it...
-         */
 
-          cupsdSetString(&attr->values[0].string.text, Classification);
+ /*
+  * Copy the subscription attributes to the response using the
+  * requested-attributes attribute that may be provided by the client.
+  */
 
-         cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
-                                           "job-sheets=\"%s,none\", "
-                                           "job-originating-user-name=\"%s\"",
-                        job->id, Classification, job->username);
-       }
-       else if (attr->num_values == 2 &&
-                strcmp(attr->values[0].string.text,
-                       attr->values[1].string.text) &&
-                strcmp(attr->values[0].string.text, "none") &&
-                strcmp(attr->values[1].string.text, "none"))
-        {
-        /*
-         * Can't put two different security markings on the same document!
-         */
+  if (!ra || cupsArrayFind(ra, "notify-events"))
+  {
+    if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
+    {
+     /*
+      * Simple event list...
+      */
 
-          cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
+      ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
+                   IPP_TAG_KEYWORD | IPP_TAG_COPY,
+                   "notify-events", NULL, name);
+    }
+    else
+    {
+     /*
+      * Complex event list...
+      */
 
-         cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
-                                           "job-sheets=\"%s,%s\", "
-                                           "job-originating-user-name=\"%s\"",
-                        job->id, attr->values[0].string.text,
-                        attr->values[1].string.text, job->username);
-       }
-       else if (strcmp(attr->values[0].string.text, Classification) &&
-                strcmp(attr->values[0].string.text, "none") &&
-                (attr->num_values == 1 ||
-                 (strcmp(attr->values[1].string.text, Classification) &&
-                  strcmp(attr->values[1].string.text, "none"))))
-        {
-         if (attr->num_values == 1)
-            cupsdLogMessage(CUPSD_LOG_NOTICE,
-                           "[Job %d] CLASSIFICATION OVERRIDDEN "
-                           "job-sheets=\"%s\", "
-                           "job-originating-user-name=\"%s\"",
-                      job->id, attr->values[0].string.text, job->username);
-          else
-            cupsdLogMessage(CUPSD_LOG_NOTICE,
-                           "[Job %d] CLASSIFICATION OVERRIDDEN "
-                           "job-sheets=\"%s,%s\",fffff "
-                           "job-originating-user-name=\"%s\"",
-                           job->id, attr->values[0].string.text,
-                           attr->values[1].string.text, job->username);
-        }
-      }
-      else if (strcmp(attr->values[0].string.text, Classification) &&
-               (attr->num_values == 1 ||
-              strcmp(attr->values[1].string.text, Classification)))
-      {
-       /*
-        * Force the banner to have the classification on it...
-       */
+      for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
+       if (sub->mask & mask)
+          count ++;
 
-        if (attr->num_values > 1 &&
-           !strcmp(attr->values[0].string.text, attr->values[1].string.text))
-       {
-          cupsdSetString(&(attr->values[0].string.text), Classification);
-          cupsdSetString(&(attr->values[1].string.text), Classification);
-       }
-        else
-       {
-          if (attr->num_values == 1 ||
-             strcmp(attr->values[0].string.text, "none"))
-            cupsdSetString(&(attr->values[0].string.text), Classification);
+      attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
+                           IPP_TAG_KEYWORD | IPP_TAG_COPY,
+                           "notify-events", count, NULL, NULL);
 
-          if (attr->num_values > 1 &&
-             strcmp(attr->values[1].string.text, "none"))
-            cupsdSetString(&(attr->values[1].string.text), Classification);
-        }
+      for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
+       if (sub->mask & mask)
+       {
+          attr->values[count].string.text =
+             (char *)cupsdEventName((cupsd_eventmask_t)mask);
 
-        if (attr->num_values > 1)
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s,%s\", "
-                         "job-originating-user-name=\"%s\"",
-                         job->id, attr->values[0].string.text,
-                         attr->values[1].string.text, job->username);
-        else
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s\", "
-                         "job-originating-user-name=\"%s\"",
-                        job->id, Classification, job->username);
-      }
+          count ++;
+       }
     }
+  }
 
-   /*
-    * See if we need to add the starting sheet...
-    */
-
-    if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Adding start banner page \"%s\" to job %d.",
-                      attr->values[0].string.text, job->id);
+  if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id")))
+    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                  "notify-job-id", sub->job->id);
 
-      kbytes = copy_banner(con, job, attr->values[0].string.text);
+  if (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration")))
+    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                  "notify-lease-duration", sub->lease);
 
-      cupsdUpdateQuota(printer, job->username, 0, kbytes);
-    }
+  if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri")))
+  {
+    httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
+                     "ipp", NULL, con->servername, con->serverport,
+                    "/printers/%s", sub->dest->name);
+    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
+                "notify-printer-uri", NULL, printer_uri);
   }
-  else if ((attr = ippFindAttribute(job->attrs, "job-sheets",
-                                    IPP_TAG_ZERO)) != NULL)
-    job->sheets = attr;
 
- /*
-  * Fill in the response info...
-  */
+  if (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri")))
+    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
+                "notify-recipient-uri", NULL, sub->recipient);
+  else if (!ra || cupsArrayFind(ra, "notify-pull-method"))
+    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
+                 "notify-pull-method", NULL, "ippget");
 
-  snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
-          LocalPort, job->id);
+  if (!ra || cupsArrayFind(ra, "notify-subscriber-user-name"))
+    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
+                "notify-subscriber-user-name", NULL, sub->owner);
 
-  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, job_uri);
+  if (!ra || cupsArrayFind(ra, "notify-subscription-id"))
+    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                  "notify-subscription-id", sub->id);
 
-  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
+  if (!ra || cupsArrayFind(ra, "notify-time-interval"))
+    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                  "notify-time-interval", sub->interval);
 
-  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
-                job->state_value);
+  if (sub->user_data_len > 0 && (!ra || cupsArrayFind(ra, "notify-user-data")))
+    ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
+                      sub->user_data, sub->user_data_len);
+}
 
-  con->response->request.status.status_code = IPP_OK;
 
- /*
-  * Add any job subscriptions...
-  */
+/*
+ * 'create_job()' - Print a file to a printer or class.
+ */
+
+static void
+create_job(cupsd_client_t  *con,       /* I - Client connection */
+          ipp_attribute_t *uri)        /* I - Printer URI */
+{
+  cupsd_job_t  *job;                   /* New job */
+
 
-  add_job_subscriptions(con, job);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
 
  /*
-  * Set all but the first two attributes to the job attributes group...
+  * Create the job object...
   */
 
-  for (attr = job->attrs->attrs->next->next; attr; attr = attr->next)
-    attr->group_tag = IPP_TAG_JOB;
+  if ((job = add_job(con, uri, NULL)) == NULL)
+    return;
 
  /*
   * Save and log the job...
@@ -4515,8 +4429,6 @@ create_job(cupsd_client_t  *con,  /* I - Client connection */
 
   cupsdLogMessage(CUPSD_LOG_INFO, "Job %d created on \"%s\" by \"%s\".",
                   job->id, job->dest, job->username);
-
-  cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created.");
 }
 
 
@@ -5210,7 +5122,7 @@ get_devices(cupsd_client_t *con)  /* I - Client connection */
 
   snprintf(command, sizeof(command), "%s/daemon/cups-deviced", ServerBin);
   snprintf(options, sizeof(options),
-           "cups-deviced %d+%d+%d+requested-attributes=%s",
+           "%d+%d+%d+requested-attributes=%s",
            con->request->request.op.request_id,
            limit ? limit->values[0].integer : 0, User,
           attrs);
@@ -5662,378 +5574,168 @@ get_notifications(cupsd_client_t *con)        /* I - Client connection */
     else
       j = min_seq - sub->first_event_id;
 
-    for (; j < sub->num_events; j ++)
-    {
-      ippAddSeparator(con->response);
-
-      copy_attrs(con->response, sub->events[j]->attrs, NULL,
-                IPP_TAG_EVENT_NOTIFICATION, 0);
-    }
-  }
-}
-
-
-/*
- * 'get_ppds()' - Get the list of PPD files on the local system.
- */
-
-static void
-get_ppds(cupsd_client_t *con)          /* I - Client connection */
-{
-  http_status_t                status;         /* Policy status */
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *limit,         /* Limit attribute */
-                       *make,          /* ppd-make attribute */
-                       *requested;     /* requested-attributes attribute */
-  char                 command[1024],  /* cups-deviced command */
-                       options[1024],  /* Options to pass to command */
-                       attrs[1024],    /* String for requested attributes */
-                       *aptr;          /* Pointer into string */
-  int                  alen;           /* Length of attribute value */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppds(%p[%d])", con, con->http.fd);
-
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-
- /*
-  * Run cups-driverd command with the given options...
-  */
-
-  limit     = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
-  make      = ippFindAttribute(con->request, "ppd-make", IPP_TAG_TEXT);
-  requested = ippFindAttribute(con->request, "requested-attributes",
-                               IPP_TAG_KEYWORD);
-
-  if (requested)
-  {
-    for (i = 0, aptr = attrs; i < requested->num_values; i ++)
-    {
-     /*
-      * Check that we have enough room...
-      */
-
-      alen = strlen(requested->values[i].string.text);
-      if (alen > (sizeof(attrs) - (aptr - attrs) - 2))
-        break;
-
-     /*
-      * Put commas between values...
-      */
-
-      if (i)
-        *aptr++ = ',';
-
-     /*
-      * Add the value to the end of the string...
-      */
-
-      strcpy(aptr, requested->values[i].string.text);
-      aptr += alen;
-    }
-
-   /*
-    * If we have more attribute names than will fit, default to "all"...
-    */
-
-    if (i < requested->num_values)
-      strcpy(attrs, "all");
-  }
-  else
-    strcpy(attrs, "all");
-
-  snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
-  snprintf(options, sizeof(options),
-           "cups-driverd list+%d+%d+requested-attributes=%s%s%s",
-           con->request->request.op.request_id,
-           limit ? limit->values[0].integer : 0,
-          attrs,
-          make ? "%20ppd-make=" : "",
-          make ? make->values[0].string.text : "");
-
-  if (cupsdSendCommand(con, command, options, 0))
-  {
-   /*
-    * Command started successfully, don't send an IPP response here...
-    */
-
-    ippDelete(con->response);
-    con->response = NULL;
-  }
-  else
-  {
-   /*
-    * Command failed, return "internal error" so the user knows something
-    * went wrong...
-    */
-
-    send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("cups-driverd failed to execute."));
-  }
-}
-
-
-/*
- * 'get_printer_attrs()' - Get printer attributes.
- */
-
-static void
-get_printer_attrs(cupsd_client_t  *con,        /* I - Client connection */
-                 ipp_attribute_t *uri) /* I - Printer URI */
-{
-  http_status_t                status;         /* Policy status */
-  const char           *dest;          /* Destination */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[HTTP_MAX_URI],
-                                       /* Method portion of URI */
-                       username[HTTP_MAX_URI],
-                                       /* Username portion of URI */
-                       host[HTTP_MAX_URI],
-                                       /* Host portion of URI */
-                       resource[HTTP_MAX_URI];
-                                       /* Resource portion of URI */
-  int                  port;           /* Port portion of URI */
-  cupsd_printer_t      *printer;       /* Printer/class */
-  cups_array_t         *ra;            /* Requested attributes array */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printer_attrs(%p[%d], %s)", con,
-                  con->http.fd, uri->values[0].string.text);
-
- /*
-  * Is the destination valid?
-  */
-
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
-  {
-   /*
-    * Bad URI...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return;
-  }
-
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-
- /*
-  * Send the attributes...
-  */
-
-  ra = create_requested_array(con->request);
-
-  copy_printer_attrs(con, printer, ra);
-
-  cupsArrayDelete(ra);
-
-  con->response->request.status.status_code = IPP_OK;
-}
-
-
-/*
- * 'get_printers()' - Get a list of printers or classes.
- */
-
-static void
-get_printers(cupsd_client_t *con,      /* I - Client connection */
-             int            type)      /* I - 0 or CUPS_PRINTER_CLASS */
-{
-  http_status_t        status;                 /* Policy status */
-  ipp_attribute_t *attr;               /* Current attribute */
-  int          limit;                  /* Maximum number of printers to return */
-  int          count;                  /* Number of printers that match */
-  cupsd_printer_t *printer;            /* Current printer pointer */
-  int          printer_type,           /* printer-type attribute */
-               printer_mask;           /* printer-type-mask attribute */
-  char         *location;              /* Location string */
-  const char   *username;              /* Current user */
-  char         *first_printer_name;    /* first-printer-name attribute */
-  cups_array_t *ra;                    /* Requested attributes array */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printers(%p[%d], %x)", con,
-                  con->http.fd, type);
-
- /*
-  * Check policy...
-  */
-
-  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-
- /*
-  * Check for printers...
-  */
-
-  if (!Printers || !cupsArrayCount(Printers))
-  {
-    send_ipp_status(con, IPP_NOT_FOUND, _("No destinations added."));
-    return;
-  }
-
- /*
-  * See if they want to limit the number of printers reported...
-  */
-
-  if ((attr = ippFindAttribute(con->request, "limit",
-                               IPP_TAG_INTEGER)) != NULL)
-    limit = attr->values[0].integer;
-  else
-    limit = 10000000;
-
-  if ((attr = ippFindAttribute(con->request, "first-printer-name",
-                               IPP_TAG_NAME)) != NULL)
-    first_printer_name = attr->values[0].string.text;
-  else
-    first_printer_name = NULL;
+    for (; j < sub->num_events; j ++)
+    {
+      ippAddSeparator(con->response);
 
- /*
-  * Support filtering...
-  */
+      copy_attrs(con->response, sub->events[j]->attrs, NULL,
+                IPP_TAG_EVENT_NOTIFICATION, 0);
+    }
+  }
+}
 
-  if ((attr = ippFindAttribute(con->request, "printer-type",
-                               IPP_TAG_ENUM)) != NULL)
-    printer_type = attr->values[0].integer;
-  else
-    printer_type = 0;
 
-  if ((attr = ippFindAttribute(con->request, "printer-type-mask",
-                               IPP_TAG_ENUM)) != NULL)
-    printer_mask = attr->values[0].integer;
-  else
-    printer_mask = 0;
+/*
+ * 'get_ppds()' - Get the list of PPD files on the local system.
+ */
 
-  if ((attr = ippFindAttribute(con->request, "printer-location",
-                               IPP_TAG_TEXT)) != NULL)
-    location = attr->values[0].string.text;
-  else
-    location = NULL;
+static void
+get_ppds(cupsd_client_t *con)          /* I - Client connection */
+{
+  http_status_t                status;         /* Policy status */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *limit,         /* Limit attribute */
+                       *make,          /* ppd-make attribute */
+                       *requested;     /* requested-attributes attribute */
+  char                 command[1024],  /* cups-deviced command */
+                       options[1024],  /* Options to pass to command */
+                       attrs[1024],    /* String for requested attributes */
+                       *aptr;          /* Pointer into string */
+  int                  alen;           /* Length of attribute value */
 
-  if (con->username[0])
-    username = con->username;
-  else if ((attr = ippFindAttribute(con->request, "requesting-user-name",
-                                    IPP_TAG_NAME)) != NULL)
-    username = attr->values[0].string.text;
-  else
-    username = NULL;
 
-  ra = create_requested_array(con->request);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppds(%p[%d])", con, con->http.fd);
 
  /*
-  * OK, build a list of printers for this printer...
+  * Check policy...
   */
 
-  if (first_printer_name)
+  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
-    if ((printer = cupsdFindDest(first_printer_name)) == NULL)
-      printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
+    send_http_error(con, status);
+    return;
   }
-  else
-    printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
 
-  for (count = 0;
-       count < limit && printer;
-       printer = (cupsd_printer_t *)cupsArrayNext(Printers))
+ /*
+  * Run cups-driverd command with the given options...
+  */
+
+  limit     = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
+  make      = ippFindAttribute(con->request, "ppd-make", IPP_TAG_TEXT);
+  requested = ippFindAttribute(con->request, "requested-attributes",
+                               IPP_TAG_KEYWORD);
+
+  if (requested)
   {
-    if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
-        (printer->type & printer_mask) == printer_type &&
-       (!location || !printer->location ||
-        !strcasecmp(printer->location, location)))
+    for (i = 0, aptr = attrs; i < requested->num_values; i ++)
     {
      /*
-      * If HideImplicitMembers is enabled, see if this printer or class
-      * is a member of an implicit class...
+      * Check that we have enough room...
       */
 
-      if (ImplicitClasses && HideImplicitMembers &&
-          printer->in_implicit_class)
-        continue;
+      alen = strlen(requested->values[i].string.text);
+      if (alen > (sizeof(attrs) - (aptr - attrs) - 2))
+        break;
 
      /*
-      * If a username is specified, see if it is allowed or denied
-      * access...
+      * Put commas between values...
       */
 
-      if (printer->num_users && username && !user_allowed(printer, username))
-        continue;
+      if (i)
+        *aptr++ = ',';
 
      /*
-      * Add the group separator as needed...
+      * Add the value to the end of the string...
       */
 
-      if (count > 0)
-        ippAddSeparator(con->response);
-
-      count ++;
+      strcpy(aptr, requested->values[i].string.text);
+      aptr += alen;
+    }
 
-     /*
-      * Send the attributes...
-      */
+   /*
+    * If we have more attribute names than will fit, default to "all"...
+    */
 
-      copy_printer_attrs(con, printer, ra);
-    }
+    if (i < requested->num_values)
+      strcpy(attrs, "all");
   }
+  else
+    strcpy(attrs, "all");
 
-  cupsArrayDelete(ra);
+  snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
+  snprintf(options, sizeof(options),
+           "list+%d+%d+requested-attributes=%s%s%s",
+           con->request->request.op.request_id,
+           limit ? limit->values[0].integer : 0,
+          attrs,
+          make ? "%20ppd-make=" : "",
+          make ? make->values[0].string.text : "");
 
-  con->response->request.status.status_code = IPP_OK;
+  if (cupsdSendCommand(con, command, options, 0))
+  {
+   /*
+    * Command started successfully, don't send an IPP response here...
+    */
+
+    ippDelete(con->response);
+    con->response = NULL;
+  }
+  else
+  {
+   /*
+    * Command failed, return "internal error" so the user knows something
+    * went wrong...
+    */
+
+    send_ipp_status(con, IPP_INTERNAL_ERROR,
+                    _("cups-driverd failed to execute."));
+  }
 }
 
 
 /*
- * 'get_subscription_attrs()' - Get subscription attributes.
+ * 'get_printer_attrs()' - Get printer attributes.
  */
 
 static void
-get_subscription_attrs(
-    cupsd_client_t *con,               /* I - Client connection */
-    int            sub_id)             /* I - Subscription ID */
+get_printer_attrs(cupsd_client_t  *con,        /* I - Client connection */
+                 ipp_attribute_t *uri) /* I - Printer URI */
 {
   http_status_t                status;         /* Policy status */
-  cupsd_subscription_t *sub;           /* Subscription */
+  const char           *dest;          /* Destination */
+  cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
+  cupsd_printer_t      *printer;       /* Printer/class */
   cups_array_t         *ra;            /* Requested attributes array */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "get_subscription_attrs(con=%p[%d], sub_id=%d)",
-                  con, con->http.fd, sub_id);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printer_attrs(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
 
  /*
-  * Is the subscription ID valid?
+  * Is the destination valid?
   */
 
-  if ((sub = cupsdFindSubscription(sub_id)) == NULL)
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
-    * Bad subscription ID...
+    * Bad URI...
     */
 
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("notify-subscription-id %d no good!"), sub_id);
+                    _("The printer or class was not found."));
     return;
   }
 
@@ -6041,22 +5743,19 @@ get_subscription_attrs(
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
-                                             DefaultPolicyPtr,
-                                 con, sub->owner)) != HTTP_OK)
+  if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
     send_http_error(con, status);
     return;
   }
 
  /*
-  * Copy the subscription attributes to the response using the
-  * requested-attributes attribute that may be provided by the client.
+  * Send the attributes...
   */
 
   ra = create_requested_array(con->request);
 
-  copy_subscription_attrs(con, sub, ra);
+  copy_printer_attrs(con, printer, ra);
 
   cupsArrayDelete(ra);
 
@@ -6065,364 +5764,188 @@ get_subscription_attrs(
 
 
 /*
- * 'get_subscriptions()' - Get subscriptions.
+ * 'get_printers()' - Get a list of printers or classes.
  */
 
 static void
-get_subscriptions(cupsd_client_t  *con,        /* I - Client connection */
-                  ipp_attribute_t *uri)        /* I - Printer/job URI */
+get_printers(cupsd_client_t *con,      /* I - Client connection */
+             int            type)      /* I - 0 or CUPS_PRINTER_CLASS */
 {
-  http_status_t                status;         /* Policy status */
-  int                  count;          /* Number of subscriptions */
-  int                  limit;          /* Limit */
-  cupsd_subscription_t *sub;           /* Subscription */
-  cups_array_t         *ra;            /* Requested attributes array */
-  ipp_attribute_t      *attr;          /* Attribute */
-  cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 method[HTTP_MAX_URI],
-                                       /* Method portion of URI */
-                       username[HTTP_MAX_URI],
-                                       /* Username portion of URI */
-                       host[HTTP_MAX_URI],
-                                       /* Host portion of URI */
-                       resource[HTTP_MAX_URI];
-                                       /* Resource portion of URI */
-  int                  port;           /* Port portion of URI */
-  cupsd_job_t          *job;           /* Job pointer */
-  cupsd_printer_t      *printer;       /* Printer */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "get_subscriptions(con=%p[%d], uri=%s)",
-                  con, con->http.fd, uri->values[0].string.text);
-
- /*
-  * Is the destination valid?
-  */
-
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if (!strcmp(resource, "/") ||
-      (!strncmp(resource, "/jobs", 5) && strlen(resource) <= 6) ||
-      (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10) ||
-      (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9))
-  {
-    printer = NULL;
-    job     = NULL;
-  }
-  else if (!strncmp(resource, "/jobs/", 6) && resource[6])
-  {
-    printer = NULL;
-    job     = cupsdFindJob(atoi(resource + 6));
-
-    if (!job)
-    {
-      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%s does not exist!"),
-                      resource + 6);
-      return;
-    }
-  }
-  else if (!cupsdValidateDest(host, resource, &dtype, &printer))
-  {
-   /*
-    * Bad URI...
-    */
+  http_status_t        status;                 /* Policy status */
+  ipp_attribute_t *attr;               /* Current attribute */
+  int          limit;                  /* Maximum number of printers to return */
+  int          count;                  /* Number of printers that match */
+  cupsd_printer_t *printer;            /* Current printer pointer */
+  int          printer_type,           /* printer-type attribute */
+               printer_mask;           /* printer-type-mask attribute */
+  char         *location;              /* Location string */
+  const char   *username;              /* Current user */
+  char         *first_printer_name;    /* first-printer-name attribute */
+  cups_array_t *ra;                    /* Requested attributes array */
 
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return;
-  }
-  else if ((attr = ippFindAttribute(con->request, "notify-job-id",
-                                    IPP_TAG_INTEGER)) != NULL)
-  {
-    job = cupsdFindJob(attr->values[0].integer);
 
-    if (!job)
-    {
-      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"),
-                      attr->values[0].integer);
-      return;
-    }
-  }
-  else
-    job = NULL;
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printers(%p[%d], %x)", con,
+                  con->http.fd, type);
 
  /*
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(printer ? printer->op_policy_ptr :
-                                           DefaultPolicyPtr,
-                                 con, NULL)) != HTTP_OK)
+  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
   {
     send_http_error(con, status);
     return;
   }
 
  /*
-  * Copy the subscription attributes to the response using the
-  * requested-attributes attribute that may be provided by the client.
+  * Check for printers...
   */
 
-  ra = create_requested_array(con->request);
+  if (!Printers || !cupsArrayCount(Printers))
+  {
+    send_ipp_status(con, IPP_NOT_FOUND, _("No destinations added."));
+    return;
+  }
+
+ /*
+  * See if they want to limit the number of printers reported...
+  */
 
   if ((attr = ippFindAttribute(con->request, "limit",
                                IPP_TAG_INTEGER)) != NULL)
     limit = attr->values[0].integer;
   else
-    limit = 0;
+    limit = 10000000;
+
+  if ((attr = ippFindAttribute(con->request, "first-printer-name",
+                               IPP_TAG_NAME)) != NULL)
+    first_printer_name = attr->values[0].string.text;
+  else
+    first_printer_name = NULL;
 
  /*
-  * See if we only want to see subscriptions for a specific user...
+  * Support filtering...
   */
 
-  if ((attr = ippFindAttribute(con->request, "my-subscriptions",
-                               IPP_TAG_BOOLEAN)) != NULL &&
-      attr->values[0].boolean)
-    strlcpy(username, get_username(con), sizeof(username));
+  if ((attr = ippFindAttribute(con->request, "printer-type",
+                               IPP_TAG_ENUM)) != NULL)
+    printer_type = attr->values[0].integer;
   else
-    username[0] = '\0';
-
-  for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions), count = 0;
-       sub;
-       sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
-    if ((!printer || sub->dest == printer) && (!job || sub->job == job) &&
-        (!username[0] || !strcasecmp(username, sub->owner)))
-    {
-      ippAddSeparator(con->response);
-      copy_subscription_attrs(con, sub, ra);
-
-      count ++;
-      if (limit && count >= limit)
-        break;
-    }
-
-  cupsArrayDelete(ra);
+    printer_type = 0;
 
-  if (count)
-    con->response->request.status.status_code = IPP_OK;
+  if ((attr = ippFindAttribute(con->request, "printer-type-mask",
+                               IPP_TAG_ENUM)) != NULL)
+    printer_mask = attr->values[0].integer;
   else
-    send_ipp_status(con, IPP_NOT_FOUND, _("No subscriptions found."));
-}
-
-
-/*
- * 'get_username()' - Get the username associated with a request.
- */
-
-static const char *                    /* O - Username */
-get_username(cupsd_client_t *con)      /* I - Connection */
-{
-  ipp_attribute_t      *attr;          /* Attribute */
+    printer_mask = 0;
 
+  if ((attr = ippFindAttribute(con->request, "printer-location",
+                               IPP_TAG_TEXT)) != NULL)
+    location = attr->values[0].string.text;
+  else
+    location = NULL;
 
   if (con->username[0])
-    return (con->username);
+    username = con->username;
   else if ((attr = ippFindAttribute(con->request, "requesting-user-name",
                                     IPP_TAG_NAME)) != NULL)
-    return (attr->values[0].string.text);
+    username = attr->values[0].string.text;
   else
-    return ("anonymous");
-}
-
-
-/*
- * 'hold_job()' - Hold a print job.
- */
-
-static void
-hold_job(cupsd_client_t  *con,         /* I - Client connection */
-         ipp_attribute_t *uri)         /* I - Job or Printer URI */
-{
-  ipp_attribute_t *attr,               /* Current job-hold-until */
-               *newattr;               /* New job-hold-until */
-  int          jobid;                  /* Job ID */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
-               username[HTTP_MAX_URI], /* Username portion of URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI]; /* Resource portion of URI */
-  int          port;                   /* Port portion of URI */
-  cupsd_job_t  *job;                   /* Job information */
-
+    username = NULL;
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "hold_job(%p[%d], %s)", con, con->http.fd,
-                  uri->values[0].string.text);
+  ra = create_requested_array(con->request);
 
  /*
-  * See if we have a job URI or a printer URI...
+  * OK, build a list of printers for this printer...
   */
 
-  if (!strcmp(uri->name, "printer-uri"))
+  if (first_printer_name)
   {
-   /*
-    * Got a printer URI; see if we also have a job-id attribute...
-    */
-
-    if ((attr = ippFindAttribute(con->request, "job-id",
-                                 IPP_TAG_INTEGER)) == NULL)
-    {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Got a printer-uri attribute but no job-id!"));
-      return;
-    }
-
-    jobid = attr->values[0].integer;
+    if ((printer = cupsdFindDest(first_printer_name)) == NULL)
+      printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
   }
   else
-  {
-   /*
-    * Got a job URI; parse it to get the job ID...
-    */
-
-    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                    sizeof(method), username, sizeof(username), host,
-                   sizeof(host), &port, resource, sizeof(resource));
+    printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
 
-    if (strncmp(resource, "/jobs/", 6))
+  for (count = 0;
+       count < limit && printer;
+       printer = (cupsd_printer_t *)cupsArrayNext(Printers))
+  {
+    if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
+        (printer->type & printer_mask) == printer_type &&
+       (!location || !printer->location ||
+        !strcasecmp(printer->location, location)))
     {
      /*
-      * Not a valid URI!
+      * If HideImplicitMembers is enabled, see if this printer or class
+      * is a member of an implicit class...
       */
 
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
-                      uri->values[0].string.text);
-      return;
-    }
-
-    jobid = atoi(resource + 6);
-  }
-
- /*
-  * See if the job exists...
-  */
-
-  if ((job = cupsdFindJob(jobid)) == NULL)
-  {
-   /*
-    * Nope - return a "not found" error...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
-    return;
-  }
-
- /*
-  * See if the job is owned by the requesting user...
-  */
-
-  if (!validate_user(job, con, job->username, username, sizeof(username)))
-  {
-    send_http_error(con, HTTP_UNAUTHORIZED);
-    return;
-  }
-
- /*
-  * Hold the job and return...
-  */
-
-  cupsdHoldJob(job);
+      if (ImplicitClasses && HideImplicitMembers &&
+          printer->in_implicit_class)
+        continue;
 
-  if ((newattr = ippFindAttribute(con->request, "job-hold-until",
-                                  IPP_TAG_KEYWORD)) == NULL)
-    newattr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME);
+     /*
+      * If a username is specified, see if it is allowed or denied
+      * access...
+      */
 
-  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
-                               IPP_TAG_KEYWORD)) == NULL)
-    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+      if (printer->num_users && username && !user_allowed(printer, username))
+        continue;
 
-  if (attr)
-  {
-   /*
-    * Free the old hold value and copy the new one over...
-    */
+     /*
+      * Add the group separator as needed...
+      */
 
-    _cups_sp_free(attr->values[0].string.text);
+      if (count > 0)
+        ippAddSeparator(con->response);
 
-    if (newattr)
-    {
-      attr->value_tag = newattr->value_tag;
-      attr->values[0].string.text =
-          _cups_sp_alloc(newattr->values[0].string.text);
-    }
-    else
-    {
-      attr->value_tag = IPP_TAG_KEYWORD;
-      attr->values[0].string.text = _cups_sp_alloc("indefinite");
-    }
+      count ++;
 
-   /*
-    * Hold job until specified time...
-    */
+     /*
+      * Send the attributes...
+      */
 
-    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+      copy_printer_attrs(con, printer, ra);
+    }
   }
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid,
-                  username);
+  cupsArrayDelete(ra);
 
   con->response->request.status.status_code = IPP_OK;
 }
 
 
 /*
- * 'move_job()' - Move a job to a new destination.
+ * 'get_subscription_attrs()' - Get subscription attributes.
  */
 
 static void
-move_job(cupsd_client_t  *con,         /* I - Client connection */
-        ipp_attribute_t *uri)          /* I - Job URI */
+get_subscription_attrs(
+    cupsd_client_t *con,               /* I - Client connection */
+    int            sub_id)             /* I - Subscription ID */
 {
-  http_status_t        status;                 /* Policy status */
-  ipp_attribute_t *attr;               /* Current attribute */
-  int          jobid;                  /* Job ID */
-  cupsd_job_t  *job;                   /* Current job */
-  const char   *src,                   /* Source printer/class */
-               *dest;                  /* Destination */
-  cups_ptype_t stype,                  /* Source type (printer or class) */
-               dtype;                  /* Destination type (printer or class) */
-  char         method[HTTP_MAX_URI],   /* Method portion of URI */
-               username[HTTP_MAX_URI], /* Username portion of URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI]; /* Resource portion of URI */
-  int          port;                   /* Port portion of URI */
-  cupsd_printer_t *sprinter,           /* Source printer */
-               *dprinter;              /* Destination printer */
+  http_status_t                status;         /* Policy status */
+  cupsd_subscription_t *sub;           /* Subscription */
+  cups_array_t         *ra;            /* Requested attributes array */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "move_job(%p[%d], %s)", con, con->http.fd,
-                  uri->values[0].string.text);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "get_subscription_attrs(con=%p[%d], sub_id=%d)",
+                  con, con->http.fd, sub_id);
 
  /*
-  * Get the new printer or class...
+  * Is the subscription ID valid?
   */
 
-  if ((attr = ippFindAttribute(con->request, "job-printer-uri",
-                               IPP_TAG_URI)) == NULL)
-  {
-   /*
-    * Need job-printer-uri...
-    */
-
-    send_ipp_status(con, IPP_BAD_REQUEST,
-                    _("job-printer-uri attribute missing!"));
-    return;
-  }
-    
-  httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
-
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &dprinter)) == NULL)
+  if ((sub = cupsdFindSubscription(sub_id)) == NULL)
   {
    /*
-    * Bad URI...
+    * Bad subscription ID...
     */
 
     send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
+                    _("notify-subscription-id %d no good!"), sub_id);
     return;
   }
 
@@ -6430,952 +5953,893 @@ move_job(cupsd_client_t  *con,                /* I - Client connection */
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con, NULL)) != HTTP_OK)
+  if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
+                                             DefaultPolicyPtr,
+                                 con, sub->owner)) != HTTP_OK)
   {
     send_http_error(con, status);
     return;
   }
 
  /*
-  * See if we have a job URI or a printer URI...
+  * Copy the subscription attributes to the response using the
+  * requested-attributes attribute that may be provided by the client.
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
+  ra = create_requested_array(con->request);
 
-  if (!strcmp(uri->name, "printer-uri"))
-  {
-   /*
-    * Got a printer URI; see if we also have a job-id attribute...
-    */
+  copy_subscription_attrs(con, sub, ra);
 
-    if ((attr = ippFindAttribute(con->request, "job-id",
-                                 IPP_TAG_INTEGER)) == NULL)
-    {
-     /*
-      * Move all jobs...
-      */
+  cupsArrayDelete(ra);
 
-      if ((src = cupsdValidateDest(host, resource, &stype, &sprinter)) == NULL)
-      {
-       /*
-       * Bad URI...
-       */
+  con->response->request.status.status_code = IPP_OK;
+}
 
-       send_ipp_status(con, IPP_NOT_FOUND,
-                       _("The printer or class was not found."));
-       return;
-      }
 
-      job = NULL;
-    }
-    else
-    {
-     /*
-      * Otherwise, just move a single job...
-      */
+/*
+ * 'get_subscriptions()' - Get subscriptions.
+ */
 
-      if ((job = cupsdFindJob(attr->values[0].integer)) == NULL)
-      {
-       /*
-       * Nope - return a "not found" error...
-       */
+static void
+get_subscriptions(cupsd_client_t  *con,        /* I - Client connection */
+                  ipp_attribute_t *uri)        /* I - Printer/job URI */
+{
+  http_status_t                status;         /* Policy status */
+  int                  count;          /* Number of subscriptions */
+  int                  limit;          /* Limit */
+  cupsd_subscription_t *sub;           /* Subscription */
+  cups_array_t         *ra;            /* Requested attributes array */
+  ipp_attribute_t      *attr;          /* Attribute */
+  cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
+  cupsd_job_t          *job;           /* Job pointer */
+  cupsd_printer_t      *printer;       /* Printer */
 
-       send_ipp_status(con, IPP_NOT_FOUND,
-                       _("Job #%d does not exist!"), attr->values[0].integer);
-       return;
-      }
-      else
-      {
-       /*
-        * Job found, initialize source pointers...
-       */
 
-       src      = NULL;
-       sprinter = NULL;
-      }
-    }
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "get_subscriptions(con=%p[%d], uri=%s)",
+                  con, con->http.fd, uri->values[0].string.text);
+
+ /*
+  * Is the destination valid?
+  */
+
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if (!strcmp(resource, "/") ||
+      (!strncmp(resource, "/jobs", 5) && strlen(resource) <= 6) ||
+      (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10) ||
+      (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9))
+  {
+    printer = NULL;
+    job     = NULL;
   }
-  else
+  else if (!strncmp(resource, "/jobs/", 6) && resource[6])
   {
-   /*
-    * Got a job URI; parse it to get the job ID...
-    */
+    printer = NULL;
+    job     = cupsdFindJob(atoi(resource + 6));
 
-    if (strncmp(resource, "/jobs/", 6))
+    if (!job)
     {
-     /*
-      * Not a valid URI!
-      */
-
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Bad job-uri attribute \"%s\"!"),
-                      uri->values[0].string.text);
+      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%s does not exist!"),
+                      resource + 6);
       return;
     }
-
+  }
+  else if (!cupsdValidateDest(host, resource, &dtype, &printer))
+  {
    /*
-    * See if the job exists...
+    * Bad URI...
     */
 
-    jobid = atoi(resource + 6);
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The printer or class was not found."));
+    return;
+  }
+  else if ((attr = ippFindAttribute(con->request, "notify-job-id",
+                                    IPP_TAG_INTEGER)) != NULL)
+  {
+    job = cupsdFindJob(attr->values[0].integer);
 
-    if ((job = cupsdFindJob(jobid)) == NULL)
+    if (!job)
     {
-     /*
-      * Nope - return a "not found" error...
-      */
-
-      send_ipp_status(con, IPP_NOT_FOUND,
-                      _("Job #%d does not exist!"), jobid);
+      send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"),
+                      attr->values[0].integer);
       return;
     }
-    else
-    {
-     /*
-      * Job found, initialize source pointers...
-      */
-
-      src      = NULL;
-      sprinter = NULL;
-    }
   }
+  else
+    job = NULL;
 
  /*
-  * Now move the job or jobs...
+  * Check policy...
   */
 
-  if (job)
+  if ((status = cupsdCheckPolicy(printer ? printer->op_policy_ptr :
+                                           DefaultPolicyPtr,
+                                 con, NULL)) != HTTP_OK)
   {
-   /*
-    * See if the job has been completed...
-    */
-
-    if (job->state_value > IPP_JOB_STOPPED)
-    {
-     /*
-      * Return a "not-possible" error...
-      */
+    send_http_error(con, status);
+    return;
+  }
 
-      send_ipp_status(con, IPP_NOT_POSSIBLE,
-                      _("Job #%d is finished and cannot be altered!"),
-                     job->id);
-      return;
-    }
+ /*
+  * Copy the subscription attributes to the response using the
+  * requested-attributes attribute that may be provided by the client.
+  */
 
-   /*
-    * See if the job is owned by the requesting user...
-    */
+  ra = create_requested_array(con->request);
 
-    if (!validate_user(job, con, job->username, username, sizeof(username)))
-    {
-      send_http_error(con, HTTP_UNAUTHORIZED);
-      return;
-    }
+  if ((attr = ippFindAttribute(con->request, "limit",
+                               IPP_TAG_INTEGER)) != NULL)
+    limit = attr->values[0].integer;
+  else
+    limit = 0;
 
  /*
-    * Move the job to a different printer or class...
-    */
+ /*
+  * See if we only want to see subscriptions for a specific user...
+  */
 
-    cupsdMoveJob(job, dest);
-  }
+  if ((attr = ippFindAttribute(con->request, "my-subscriptions",
+                               IPP_TAG_BOOLEAN)) != NULL &&
+      attr->values[0].boolean)
+    strlcpy(username, get_username(con), sizeof(username));
   else
-  {
-   /*
-    * Got the source printer, now look through the jobs...
-    */
+    username[0] = '\0';
 
-    for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
-         job;
-        job = (cupsd_job_t *)cupsArrayNext(Jobs))
+  for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions), count = 0;
+       sub;
+       sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
+    if ((!printer || sub->dest == printer) && (!job || sub->job == job) &&
+        (!username[0] || !strcasecmp(username, sub->owner)))
     {
-     /*
-      * See if the job is pointing at the source printer or has not been
-      * completed...
-      */
-
-      if (strcasecmp(job->dest, src) ||
-          job->state_value > IPP_JOB_STOPPED)
-       continue;
+      ippAddSeparator(con->response);
+      copy_subscription_attrs(con, sub, ra);
 
-     /*
-      * See if the job can be moved by the requesting user...
-      */
+      count ++;
+      if (limit && count >= limit)
+        break;
+    }
 
-      if (!validate_user(job, con, job->username, username, sizeof(username)))
-        continue;
+  cupsArrayDelete(ra);
 
-     /*
-      * Move the job to a different printer or class...
-      */
+  if (count)
+    con->response->request.status.status_code = IPP_OK;
+  else
+    send_ipp_status(con, IPP_NOT_FOUND, _("No subscriptions found."));
+}
 
-      cupsdMoveJob(job, dest);
-    }
-  }
 
- /*
 * Start jobs if possible...
 */
+/*
* 'get_username()' - Get the username associated with a request.
+ */
 
-  cupsdCheckJobs();
+static const char *                    /* O - Username */
+get_username(cupsd_client_t *con)      /* I - Connection */
+{
+  ipp_attribute_t      *attr;          /* Attribute */
 
- /*
-  * Return with "everything is OK" status...
-  */
 
-  con->response->request.status.status_code = IPP_OK;
+  if (con->username[0])
+    return (con->username);
+  else if ((attr = ippFindAttribute(con->request, "requesting-user-name",
+                                    IPP_TAG_NAME)) != NULL)
+    return (attr->values[0].string.text);
+  else
+    return ("anonymous");
 }
 
 
 /*
- * 'ppd_add_default()' - Add a PPD default choice.
+ * 'hold_job()' - Hold a print job.
  */
 
-static int                             /* O  - Number of defaults */
-ppd_add_default(
-    const char    *option,             /* I  - Option name */
-    const char    *choice,             /* I  - Choice name */
-    int           num_defaults,                /* I  - Number of defaults */
-    ppd_default_t **defaults)          /* IO - Defaults */
+static void
+hold_job(cupsd_client_t  *con,         /* I - Client connection */
+         ipp_attribute_t *uri)         /* I - Job or Printer URI */
 {
-  int          i;                      /* Looping var */
-  ppd_default_t        *temp;                  /* Temporary defaults array */
+  ipp_attribute_t *attr,               /* Current job-hold-until */
+               *newattr;               /* New job-hold-until */
+  int          jobid;                  /* Job ID */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  cupsd_job_t  *job;                   /* Job information */
+
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "hold_job(%p[%d], %s)", con, con->http.fd,
+                  uri->values[0].string.text);
 
  /*
-  * First check if the option already has a default value; the PPD spec
-  * says that the first one is used...
+  * See if we have a job URI or a printer URI...
   */
 
-  for (i = 0, temp = *defaults; i < num_defaults; i ++)
-    if (!strcmp(option, temp[i].option))
-      return (num_defaults);
+  if (!strcmp(uri->name, "printer-uri"))
+  {
+   /*
+    * Got a printer URI; see if we also have a job-id attribute...
+    */
 
- /*
-  * Now add the option...
-  */
+    if ((attr = ippFindAttribute(con->request, "job-id",
+                                 IPP_TAG_INTEGER)) == NULL)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Got a printer-uri attribute but no job-id!"));
+      return;
+    }
 
-  if (num_defaults == 0)
-    temp = malloc(sizeof(ppd_default_t));
+    jobid = attr->values[0].integer;
+  }
   else
-    temp = realloc(*defaults, (num_defaults + 1) * sizeof(ppd_default_t));
-
-  if (!temp)
   {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "ppd_add_default: Unable to add default value for \"%s\" - %s",
-               option, strerror(errno));
-    return (num_defaults);
-  }
-
-  *defaults = temp;
-  temp      += num_defaults;
+   /*
+    * Got a job URI; parse it to get the job ID...
+    */
 
-  strlcpy(temp->option, option, sizeof(temp->option));
-  strlcpy(temp->choice, choice, sizeof(temp->choice));
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                    sizeof(method), username, sizeof(username), host,
+                   sizeof(host), &port, resource, sizeof(resource));
 
-  return (num_defaults + 1);
-}
+    if (strncmp(resource, "/jobs/", 6))
+    {
+     /*
+      * Not a valid URI!
+      */
 
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Bad job-uri attribute \"%s\"!"),
+                      uri->values[0].string.text);
+      return;
+    }
 
-/*
- * 'ppd_parse_line()' - Parse a PPD default line.
- */
+    jobid = atoi(resource + 6);
+  }
 
-static int                             /* O - 0 on success, -1 on failure */
-ppd_parse_line(const char *line,       /* I - Line */
-               char       *option,     /* O - Option name */
-              int        olen,         /* I - Size of option name */
-               char       *choice,     /* O - Choice name */
-              int        clen)         /* I - Size of choice name */
-{
  /*
-  * Verify this is a default option line...
+  * See if the job exists...
   */
 
-  if (strncmp(line, "*Default", 8))
-    return (-1);
+  if ((job = cupsdFindJob(jobid)) == NULL)
+  {
+   /*
+    * Nope - return a "not found" error...
+    */
+
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+    return;
+  }
 
  /*
-  * Read the option name...
+  * See if the job is owned by the requesting user...
   */
 
-  for (line += 8, olen --; isalnum(*line & 255); line ++)
-    if (olen > 0)
-    {
-      *option++ = *line;
-      olen --;
-    }
-
-  *option = '\0';
+  if (!validate_user(job, con, job->username, username, sizeof(username)))
+  {
+    send_http_error(con, HTTP_UNAUTHORIZED);
+    return;
+  }
 
  /*
-  * Skip everything else up to the colon (:)...
+  * Hold the job and return...
   */
 
-  while (*line && *line != ':')
-    line ++;
+  cupsdHoldJob(job);
 
-  if (!*line)
-    return (-1);
+  if ((newattr = ippFindAttribute(con->request, "job-hold-until",
+                                  IPP_TAG_KEYWORD)) == NULL)
+    newattr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME);
 
-  line ++;
+  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+                               IPP_TAG_KEYWORD)) == NULL)
+    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
 
- /*
-  * Now grab the option choice, skipping leading whitespace...
-  */
+  if (attr)
+  {
+   /*
+    * Free the old hold value and copy the new one over...
+    */
 
-  while (isspace(*line & 255))
-    line ++;
+    _cups_sp_free(attr->values[0].string.text);
 
-  for (clen --; isalnum(*line & 255); line ++)
-    if (clen > 0)
+    if (newattr)
     {
-      *choice++ = *line;
-      clen --;
+      attr->value_tag = newattr->value_tag;
+      attr->values[0].string.text =
+          _cups_sp_alloc(newattr->values[0].string.text);
+    }
+    else
+    {
+      attr->value_tag = IPP_TAG_KEYWORD;
+      attr->values[0].string.text = _cups_sp_alloc("indefinite");
     }
 
-  *choice = '\0';
+   /*
+    * Hold job until specified time...
+    */
 
- /*
-  * Return with no errors...
-  */
+    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+  }
 
-  return (0);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid,
+                  username);
+
+  con->response->request.status.status_code = IPP_OK;
 }
 
 
 /*
- * 'print_job()' - Print a file to a printer or class.
+ * 'move_job()' - Move a job to a new destination.
  */
 
 static void
-print_job(cupsd_client_t  *con,                /* I - Client connection */
-         ipp_attribute_t *uri)         /* I - Printer URI */
+move_job(cupsd_client_t  *con,         /* I - Client connection */
+        ipp_attribute_t *uri)          /* I - Job URI */
 {
   http_status_t        status;                 /* Policy status */
   ipp_attribute_t *attr;               /* Current attribute */
-  ipp_attribute_t *format;             /* Document-format attribute */
-  const char   *dest;                  /* Destination */
-  cups_ptype_t dtype;                  /* Destination type (printer or class) */
-  int          priority;               /* Job priority */
-  char         *title;                 /* Job name/title */
+  int          jobid;                  /* Job ID */
   cupsd_job_t  *job;                   /* Current job */
-  char         job_uri[HTTP_MAX_URI],  /* Job URI */
-               method[HTTP_MAX_URI],   /* Method portion of URI */
+  const char   *src,                   /* Source printer/class */
+               *dest;                  /* Destination */
+  cups_ptype_t stype,                  /* Source type (printer or class) */
+               dtype;                  /* Destination type (printer or class) */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI], /* Resource portion of URI */
-               filename[1024];         /* Job filename */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
-  mime_type_t  *filetype;              /* Type of file */
-  char         super[MIME_MAX_SUPER],  /* Supertype of file */
-               type[MIME_MAX_TYPE],    /* Subtype of file */
-               mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
-                                       /* Textual name of mime type */
-  cupsd_printer_t *printer;            /* Printer data */
-  struct stat  fileinfo;               /* File information */
-  int          kbytes;                 /* Size of file */
-  int          i;                      /* Looping var */
-  int          lowerpagerange;         /* Page range bound */
-  int          compression;            /* Document compression */
+  cupsd_printer_t *sprinter,           /* Source printer */
+               *dprinter;              /* Destination printer */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "print_job(%p[%d], %s)", con, con->http.fd,
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "move_job(%p[%d], %s)", con, con->http.fd,
                   uri->values[0].string.text);
 
  /*
-  * Validate job template attributes; for now just copies and page-ranges...
+  * Get the new printer or class...
   */
 
-  if ((attr = ippFindAttribute(con->request, "copies",
-                               IPP_TAG_INTEGER)) != NULL)
-  {
-    if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies)
-    {
-      send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."),
-                      attr->values[0].integer);
-      ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
-                   "copies", attr->values[0].integer);
-      return;
-    }
-  }
-
-  if ((attr = ippFindAttribute(con->request, "page-ranges",
-                               IPP_TAG_RANGE)) != NULL)
+  if ((attr = ippFindAttribute(con->request, "job-printer-uri",
+                               IPP_TAG_URI)) == NULL)
   {
-    for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
-    {
-      if (attr->values[i].range.lower < lowerpagerange || 
-         attr->values[i].range.lower > attr->values[i].range.upper)
-      {
-       send_ipp_status(con, IPP_BAD_REQUEST,
-                       _("Bad page-ranges values %d-%d."),
-                       attr->values[i].range.lower,
-                       attr->values[i].range.upper);
-       return;
-      }
+   /*
+    * Need job-printer-uri...
+    */
 
-      lowerpagerange = attr->values[i].range.upper + 1;
-    }
+    send_ipp_status(con, IPP_BAD_REQUEST,
+                    _("job-printer-uri attribute missing!"));
+    return;
   }
+    
+  httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
 
- /*
-  * OK, see if the client is sending the document compressed - CUPS
-  * only supports "none" and "gzip".
-  */
-
-  compression = CUPS_FILE_NONE;
-
-  if ((attr = ippFindAttribute(con->request, "compression",
-                               IPP_TAG_KEYWORD)) != NULL)
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &dprinter)) == NULL)
   {
-    if (strcmp(attr->values[0].string.text, "none")
-#ifdef HAVE_LIBZ
-        && strcmp(attr->values[0].string.text, "gzip")
-#endif /* HAVE_LIBZ */
-      )
-    {
-      send_ipp_status(con, IPP_ATTRIBUTES,
-                      _("Unsupported compression \"%s\"!"),
-                     attr->values[0].string.text);
-      ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD,
-                  "compression", NULL, attr->values[0].string.text);
-      return;
-    }
+   /*
+    * Bad URI...
+    */
 
-#ifdef HAVE_LIBZ
-    if (!strcmp(attr->values[0].string.text, "gzip"))
-      compression = CUPS_FILE_GZIP;
-#endif /* HAVE_LIBZ */
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The printer or class was not found."));
+    return;
   }
 
  /*
-  * Do we have a file to print?
+  * Check policy...
   */
 
-  if (!con->filename)
+  if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
-    send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!"));
+    send_http_error(con, status);
     return;
   }
 
  /*
-  * Is it a format we support?
+  * See if we have a job URI or a printer URI...
   */
 
-  if ((format = ippFindAttribute(con->request, "document-format",
-                                 IPP_TAG_MIMETYPE)) != NULL)
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if (!strcmp(uri->name, "printer-uri"))
   {
    /*
-    * Grab format from client...
+    * Got a printer URI; see if we also have a job-id attribute...
     */
 
-    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
+    if ((attr = ippFindAttribute(con->request, "job-id",
+                                 IPP_TAG_INTEGER)) == NULL)
     {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Could not scan type \"%s\"!"),
-                     format->values[0].string.text);
-      return;
+     /*
+      * Move all jobs...
+      */
+
+      if ((src = cupsdValidateDest(host, resource, &stype, &sprinter)) == NULL)
+      {
+       /*
+       * Bad URI...
+       */
+
+       send_ipp_status(con, IPP_NOT_FOUND,
+                       _("The printer or class was not found."));
+       return;
+      }
+
+      job = NULL;
+    }
+    else
+    {
+     /*
+      * Otherwise, just move a single job...
+      */
+
+      if ((job = cupsdFindJob(attr->values[0].integer)) == NULL)
+      {
+       /*
+       * Nope - return a "not found" error...
+       */
+
+       send_ipp_status(con, IPP_NOT_FOUND,
+                       _("Job #%d does not exist!"), attr->values[0].integer);
+       return;
+      }
+      else
+      {
+       /*
+        * Job found, initialize source pointers...
+       */
+
+       src      = NULL;
+       sprinter = NULL;
+      }
     }
   }
   else
   {
    /*
-    * No document format attribute?  Auto-type it!
+    * Got a job URI; parse it to get the job ID...
     */
 
-    strcpy(super, "application");
-    strcpy(type, "octet-stream");
-  }
+    if (strncmp(resource, "/jobs/", 6))
+    {
+     /*
+      * Not a valid URI!
+      */
+
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Bad job-uri attribute \"%s\"!"),
+                      uri->values[0].string.text);
+      return;
+    }
 
-  if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
-  {
    /*
-    * Auto-type the file...
+    * See if the job exists...
     */
 
-    ipp_attribute_t    *doc_name;      /* document-name attribute */
-
-
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: auto-typing file...");
-
-    doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
-    filetype = mimeFileType(MimeDatabase, con->filename,
-                            doc_name ? doc_name->values[0].string.text : NULL,
-                           &compression);
+    jobid = atoi(resource + 6);
 
-    if (filetype)
+    if ((job = cupsdFindJob(jobid)) == NULL)
     {
      /*
-      * Replace the document-format attribute value with the auto-typed one.
+      * Nope - return a "not found" error...
       */
 
-      snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
-               filetype->type);
-
-      if (format)
-      {
-         _cups_sp_free(format->values[0].string.text);
-
-       format->values[0].string.text = _cups_sp_alloc(mimetype);
-      }
-      else
-        ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
-                    "document-format", NULL, mimetype);
+      send_ipp_status(con, IPP_NOT_FOUND,
+                      _("Job #%d does not exist!"), jobid);
+      return;
     }
     else
-      filetype = mimeType(MimeDatabase, super, type);
-  }
-  else
-    filetype = mimeType(MimeDatabase, super, type);
-
-  if (!filetype)
-  {
-    send_ipp_status(con, IPP_DOCUMENT_FORMAT,
-                    _("Unsupported format \'%s/%s\'!"), super, type);
-    cupsdLogMessage(CUPSD_LOG_INFO,
-                    "Hint: Do you have the raw file printing rules enabled?");
-
-    if (format)
-      ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
-                   "document-format", NULL, format->values[0].string.text);
+    {
+     /*
+      * Job found, initialize source pointers...
+      */
 
-    return;
+      src      = NULL;
+      sprinter = NULL;
+    }
   }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: request file type is %s/%s.",
-            filetype->super, filetype->type);
-
  /*
-  * Read any embedded job ticket info from PS files...
+  * Now move the job or jobs...
   */
 
-  if (!strcasecmp(filetype->super, "application") &&
-      !strcasecmp(filetype->type, "postscript"))
-    read_ps_job_ticket(con);
+  if (job)
+  {
+   /*
+    * See if the job has been completed...
+    */
+
+    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;
+    }
 
- /*
-  * Is the destination valid?
-  */
  /*
+    * See if the job is owned by the requesting user...
+    */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
-                  sizeof(method), username, sizeof(username), host,
-                 sizeof(host), &port, resource, sizeof(resource));
+    if (!validate_user(job, con, job->username, username, sizeof(username)))
+    {
+      send_http_error(con, HTTP_UNAUTHORIZED);
+      return;
+    }
 
-  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
-  {
    /*
-    * Bad URI...
+    * Move the job to a different printer or class...
     */
 
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return;
+    cupsdMoveJob(job, dest);
   }
+  else
+  {
+   /*
+    * Got the source printer, now look through the jobs...
+    */
 
- /*
-  * Check remote printing to non-shared printer...
-  */
+    for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
+         job;
+        job = (cupsd_job_t *)cupsArrayNext(Jobs))
+    {
+     /*
+      * See if the job is pointing at the source printer or has not been
+      * completed...
+      */
 
-  if (!printer->shared &&
-      strcasecmp(con->http.hostname, "localhost") &&
-      strcasecmp(con->http.hostname, ServerName))
-  {
-    send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Printer not shared!"));
-    return;
-  }
+      if (strcasecmp(job->dest, src) ||
+          job->state_value > IPP_JOB_STOPPED)
+       continue;
 
- /*
-  * Check policy...
-  */
    /*
+      * See if the job can be moved by the requesting user...
+      */
 
-  if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
-  {
-    send_http_error(con, status);
-    return;
-  }
-  else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
-  {
-    send_http_error(con, status);
-    return;
-  }
+      if (!validate_user(job, con, job->username, username, sizeof(username)))
+        continue;
 
- /*
-  * See if the printer is accepting jobs...
-  */
    /*
+      * Move the job to a different printer or class...
+      */
 
-  if (!printer->accepting)
-  {
-    send_ipp_status(con, IPP_NOT_ACCEPTING,
-                    _("Destination \"%s\" is not accepting jobs."), dest);
-    return;
+      cupsdMoveJob(job, dest);
+    }
   }
 
  /*
-  * Make sure we aren't over our limit...
+  * Start jobs if possible...
   */
 
-  if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
-    cupsdCleanJobs();
-
-  if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
-  {
-    send_ipp_status(con, IPP_NOT_POSSIBLE,
-                    _("Too many jobs - %d jobs, max jobs is %d."),
-                    cupsArrayCount(Jobs), MaxJobs);
-    return;
-  }
-
-  if (!check_quotas(con, printer))
-  {
-    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
-    return;
-  }
+  cupsdCheckJobs();
 
  /*
-  * Create the job and set things up...
+  * Return with "everything is OK" status...
   */
 
-  if ((attr = ippFindAttribute(con->request, "job-priority",
-                               IPP_TAG_INTEGER)) != NULL)
-    priority = attr->values[0].integer;
-  else
-    ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority",
-                  priority = 50);
+  con->response->request.status.status_code = IPP_OK;
+}
 
-  if ((attr = ippFindAttribute(con->request, "job-name",
-                               IPP_TAG_NAME)) != NULL)
-    title = attr->values[0].string.text;
-  else
-    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
-                 title = "Untitled");
 
-  if ((job = cupsdAddJob(priority, printer->name)) == NULL)
-  {
-    send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("Unable to add job for destination \"%s\"!"), dest);
-    return;
-  }
+/*
+ * 'ppd_add_default()' - Add a PPD default choice.
+ */
 
-  job->dtype   = dtype;
-  job->attrs   = con->request;
-  con->request = NULL;
+static int                             /* O  - Number of defaults */
+ppd_add_default(
+    const char    *option,             /* I  - Option name */
+    const char    *choice,             /* I  - Choice name */
+    int           num_defaults,                /* I  - Number of defaults */
+    ppd_default_t **defaults)          /* IO - Defaults */
+{
+  int          i;                      /* Looping var */
+  ppd_default_t        *temp;                  /* Temporary defaults array */
 
-  add_job_uuid(con, job);
 
  /*
-  * Copy the rest of the job info...
+  * First check if the option already has a default value; the PPD spec
+  * says that the first one is used...
   */
 
-  attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
-
-  if (con->username[0])
-  {
-    cupsdSetString(&job->username, con->username);
-
-    if (attr)
-      cupsdSetString(&attr->values[0].string.text, con->username);
+  for (i = 0, temp = *defaults; i < num_defaults; i ++)
+    if (!strcmp(option, temp[i].option))
+      return (num_defaults);
 
-    save_auth_info(con, job);
-  }
-  else if (attr)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: requesting-user-name = \"%s\"",
-               attr->values[0].string.text);
+ /*
+  * Now add the option...
+  */
 
-    cupsdSetString(&job->username, attr->values[0].string.text);
-  }
+  if (num_defaults == 0)
+    temp = malloc(sizeof(ppd_default_t));
   else
-    cupsdSetString(&job->username, "anonymous");
+    temp = realloc(*defaults, (num_defaults + 1) * sizeof(ppd_default_t));
 
-  if (!attr)
-    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
-                 "job-originating-user-name", NULL, job->username);
-  else
+  if (!temp)
   {
-    attr->group_tag = IPP_TAG_JOB;
-    cupsdSetString(&attr->name, "job-originating-user-name");
+    cupsdLogMessage(CUPSD_LOG_ERROR, "ppd_add_default: Unable to add default value for \"%s\" - %s",
+               option, strerror(errno));
+    return (num_defaults);
   }
 
- /*
-  * Add remaining job attributes...
-  */
+  *defaults = temp;
+  temp      += num_defaults;
 
-  if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
-                               IPP_TAG_ZERO)) != NULL)
-  {
-   /*
-    * Request contains a job-originating-host-name attribute; validate it...
-    */
+  strlcpy(temp->option, option, sizeof(temp->option));
+  strlcpy(temp->choice, choice, sizeof(temp->choice));
 
-    if (attr->value_tag != IPP_TAG_NAME ||
-        attr->num_values != 1 ||
-        strcmp(con->http.hostname, "localhost"))
-    {
-     /*
-      * Can't override the value if we aren't connected via localhost.
-      * Also, we can only have 1 value and it must be a name value.
-      */
+  return (num_defaults + 1);
+}
 
-      switch (attr->value_tag)
-      {
-        case IPP_TAG_STRING :
-       case IPP_TAG_TEXTLANG :
-       case IPP_TAG_NAMELANG :
-       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 :
-          /*
-           * Free old strings...
-           */
 
-           for (i = 0; i < attr->num_values; i ++)
-           {
-             _cups_sp_free(attr->values[i].string.text);
-             attr->values[i].string.text = NULL;
-             if (attr->values[i].string.charset)
-             {
-               _cups_sp_free(attr->values[i].string.charset);
-               attr->values[i].string.charset = NULL;
-             }
-            }
+/*
+ * 'ppd_parse_line()' - Parse a PPD default line.
+ */
 
-       default :
-            break;
-      }
+static int                             /* O - 0 on success, -1 on failure */
+ppd_parse_line(const char *line,       /* I - Line */
+               char       *option,     /* O - Option name */
+              int        olen,         /* I - Size of option name */
+               char       *choice,     /* O - Choice name */
+              int        clen)         /* I - Size of choice name */
+{
+ /*
+  * Verify this is a default option line...
+  */
 
-     /*
-      * Use the default connection hostname instead...
-      */
+  if (strncmp(line, "*Default", 8))
+    return (-1);
 
-      attr->value_tag             = IPP_TAG_NAME;
-      attr->num_values            = 1;
-      attr->values[0].string.text = _cups_sp_alloc(con->http.hostname);
+ /*
+  * Read the option name...
+  */
+
+  for (line += 8, olen --; isalnum(*line & 255); line ++)
+    if (olen > 0)
+    {
+      *option++ = *line;
+      olen --;
     }
 
-    attr->group_tag = IPP_TAG_JOB;
-  }
-  else
-  {
-   /*
-    * No job-originating-host-name attribute, so use the hostname from
-    * the connection...
-    */
+  *option = '\0';
 
-    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
-                "job-originating-host-name", NULL, con->http.hostname);
-  }
+ /*
+  * Skip everything else up to the colon (:)...
+  */
 
-  ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
-  job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
-                             "job-state", IPP_JOB_PENDING);
-  job->state_value = job->state->values[0].integer;
-  job->sheets = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                              "job-media-sheets-completed", 0);
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL,
-               printer->uri);
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
-               title);
+  while (*line && *line != ':')
+    line ++;
 
-  if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
-                               IPP_TAG_INTEGER)) == NULL)
-    attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                         "job-k-octets", 0);
+  if (!*line)
+    return (-1);
 
-  if (stat(con->filename, &fileinfo))
-    kbytes = 0;
-  else
-    kbytes = (fileinfo.st_size + 1023) / 1024;
+  line ++;
 
-  cupsdUpdateQuota(printer, job->username, 0, kbytes);
-  attr->values[0].integer += kbytes;
+ /*
+  * Now grab the option choice, skipping leading whitespace...
+  */
 
-  ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation",
-                time(NULL));
-  attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                       "time-at-processing", 0);
-  attr->value_tag = IPP_TAG_NOVALUE;
-  attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                       "time-at-completed", 0);
-  attr->value_tag = IPP_TAG_NOVALUE;
+  while (isspace(*line & 255))
+    line ++;
 
-  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
-                               IPP_TAG_KEYWORD)) == NULL)
-    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
-  if (!attr)
-    attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                        "job-hold-until", NULL, "no-hold");
+  for (clen --; isalnum(*line & 255); line ++)
+    if (clen > 0)
+    {
+      *choice++ = *line;
+      clen --;
+    }
 
-  if (attr && strcmp(attr->values[0].string.text, "no-hold") &&
-      !(printer->type & CUPS_PRINTER_REMOTE))
-  {
-   /*
-    * Hold job until specified time...
-    */
+  *choice = '\0';
 
-    job->state->values[0].integer = IPP_JOB_HELD;
-    job->state_value              = IPP_JOB_HELD;
-    cupsdSetJobHoldUntil(job, attr->values[0].string.text);
-  }
+ /*
+  * Return with no errors...
+  */
 
-  if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
-      Classification)
-  {
-   /*
-    * Add job sheets options...
-    */
+  return (0);
+}
 
-    if ((attr = ippFindAttribute(job->attrs, "job-sheets",
-                                 IPP_TAG_ZERO)) == NULL)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
-                      "Adding default job-sheets values \"%s,%s\"...",
-                      printer->job_sheets[0], printer->job_sheets[1]);
 
-      attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
-                           2, NULL, NULL);
-      attr->values[0].string.text = _cups_sp_alloc(printer->job_sheets[0]);
-      attr->values[1].string.text = _cups_sp_alloc(printer->job_sheets[1]);
-    }
+/*
+ * 'print_job()' - Print a file to a printer or class.
+ */
 
-    job->job_sheets = attr;
+static void
+print_job(cupsd_client_t  *con,                /* I - Client connection */
+         ipp_attribute_t *uri)         /* I - Printer URI */
+{
+  ipp_attribute_t *attr;               /* Current attribute */
+  ipp_attribute_t *format;             /* Document-format attribute */
+  cupsd_job_t  *job;                   /* New job */
+  char         filename[1024];         /* Job filename */
+  mime_type_t  *filetype;              /* Type of file */
+  char         super[MIME_MAX_SUPER],  /* Supertype of file */
+               type[MIME_MAX_TYPE],    /* Subtype of file */
+               mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
+                                       /* Textual name of mime type */
+  cupsd_printer_t *printer;            /* Printer data */
+  struct stat  fileinfo;               /* File information */
+  int          kbytes;                 /* Size of file */
+  int          compression;            /* Document compression */
 
-   /*
-    * Enforce classification level if set...
-    */
 
-    if (Classification)
-    {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Classification=\"%s\", ClassifyOverride=%d",
-                      Classification ? Classification : "(null)",
-                     ClassifyOverride);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "print_job(%p[%d], %s)", con, con->http.fd,
+                  uri->values[0].string.text);
 
-      if (ClassifyOverride)
-      {
-        if (!strcmp(attr->values[0].string.text, "none") &&
-           (attr->num_values == 1 ||
-            !strcmp(attr->values[1].string.text, "none")))
-        {
-        /*
-          * Force the leading banner to have the classification on it...
-         */
+ /*
+  * Validate print file attributes, for now just document-format and
+  * compression (CUPS only supports "none" and "gzip")...
+  */
 
-          cupsdSetString(&attr->values[0].string.text, Classification);
+  compression = CUPS_FILE_NONE;
 
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s,none\", "
-                         "job-originating-user-name=\"%s\"",
-                         job->id, Classification, job->username);
-       }
-       else if (attr->num_values == 2 &&
-                strcmp(attr->values[0].string.text,
-                       attr->values[1].string.text) &&
-                strcmp(attr->values[0].string.text, "none") &&
-                strcmp(attr->values[1].string.text, "none"))
-        {
-        /*
-         * Can't put two different security markings on the same document!
-         */
+  if ((attr = ippFindAttribute(con->request, "compression",
+                               IPP_TAG_KEYWORD)) != NULL)
+  {
+    if (strcmp(attr->values[0].string.text, "none")
+#ifdef HAVE_LIBZ
+        && strcmp(attr->values[0].string.text, "gzip")
+#endif /* HAVE_LIBZ */
+      )
+    {
+      send_ipp_status(con, IPP_ATTRIBUTES,
+                      _("Unsupported compression \"%s\"!"),
+                     attr->values[0].string.text);
+      ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD,
+                  "compression", NULL, attr->values[0].string.text);
+      return;
+    }
 
-          cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
+#ifdef HAVE_LIBZ
+    if (!strcmp(attr->values[0].string.text, "gzip"))
+      compression = CUPS_FILE_GZIP;
+#endif /* HAVE_LIBZ */
+  }
 
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s,%s\", "
-                         "job-originating-user-name=\"%s\"",
-                         job->id, attr->values[0].string.text,
-                         attr->values[1].string.text, job->username);
-       }
-       else if (strcmp(attr->values[0].string.text, Classification) &&
-                strcmp(attr->values[0].string.text, "none") &&
-                (attr->num_values == 1 ||
-                 (strcmp(attr->values[1].string.text, Classification) &&
-                  strcmp(attr->values[1].string.text, "none"))))
-        {
-         if (attr->num_values == 1)
-            cupsdLogMessage(CUPSD_LOG_NOTICE,
-                           "[Job %d] CLASSIFICATION OVERRIDDEN "
-                           "job-sheets=\"%s\", "
-                           "job-originating-user-name=\"%s\"",
-                           job->id, attr->values[0].string.text,
-                           job->username);
-          else
-            cupsdLogMessage(CUPSD_LOG_NOTICE,
-                           "[Job %d] CLASSIFICATION OVERRIDDEN "
-                           "job-sheets=\"%s,%s\", "
-                           "job-originating-user-name=\"%s\"",
-                           job->id, attr->values[0].string.text,
-                           attr->values[1].string.text, job->username);
-        }
-      }
-      else if (strcmp(attr->values[0].string.text, Classification) &&
-               (attr->num_values == 1 ||
-              strcmp(attr->values[1].string.text, Classification)))
-      {
-       /*
-        * Force the banner to have the classification on it...
-       */
+ /*
+  * Do we have a file to print?
+  */
 
-        if (attr->num_values > 1 &&
-           !strcmp(attr->values[0].string.text, attr->values[1].string.text))
-       {
-          cupsdSetString(&(attr->values[0].string.text), Classification);
-          cupsdSetString(&(attr->values[1].string.text), Classification);
-       }
-        else
-       {
-          if (attr->num_values == 1 ||
-             strcmp(attr->values[0].string.text, "none"))
-            cupsdSetString(&(attr->values[0].string.text), Classification);
+  if (!con->filename)
+  {
+    send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!"));
+    return;
+  }
 
-          if (attr->num_values > 1 &&
-             strcmp(attr->values[1].string.text, "none"))
-            cupsdSetString(&(attr->values[1].string.text), Classification);
-        }
+ /*
+  * Is it a format we support?
+  */
 
-        if (attr->num_values > 1)
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s,%s\", "
-                         "job-originating-user-name=\"%s\"",
-                         job->id, attr->values[0].string.text,
-                         attr->values[1].string.text, job->username);
-        else
-         cupsdLogMessage(CUPSD_LOG_NOTICE,
-                         "[Job %d] CLASSIFICATION FORCED "
-                         "job-sheets=\"%s\", "
-                         "job-originating-user-name=\"%s\"",
-                         job->id, Classification, job->username);
-      }
+  if ((format = ippFindAttribute(con->request, "document-format",
+                                 IPP_TAG_MIMETYPE)) != NULL)
+  {
+   /*
+    * Grab format from client...
+    */
+
+    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
+    {
+      send_ipp_status(con, IPP_BAD_REQUEST,
+                      _("Could not scan type \"%s\"!"),
+                     format->values[0].string.text);
+      return;
     }
+  }
+  else
+  {
+   /*
+    * No document format attribute?  Auto-type it!
+    */
+
+    strcpy(super, "application");
+    strcpy(type, "octet-stream");
+  }
 
+  if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
+  {
    /*
-    * Add the starting sheet...
+    * Auto-type the file...
     */
 
-    if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
+    ipp_attribute_t    *doc_name;      /* document-name attribute */
+
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: auto-typing file...");
+
+    doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
+    filetype = mimeFileType(MimeDatabase, con->filename,
+                            doc_name ? doc_name->values[0].string.text : NULL,
+                           &compression);
+
+    if (filetype)
     {
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Adding start banner page \"%s\" to job %d.",
-                     attr->values[0].string.text, job->id);
+     /*
+      * Replace the document-format attribute value with the auto-typed one.
+      */
 
-      kbytes = copy_banner(con, job, attr->values[0].string.text);
+      snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
+               filetype->type);
 
-      cupsdUpdateQuota(printer, job->username, 0, kbytes);
+      if (format)
+      {
+         _cups_sp_free(format->values[0].string.text);
+
+       format->values[0].string.text = _cups_sp_alloc(mimetype);
+      }
+      else
+        ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+                    "document-format", NULL, mimetype);
     }
+    else
+      filetype = mimeType(MimeDatabase, super, type);
   }
-  else if ((attr = ippFindAttribute(job->attrs, "job-sheets",
-                                    IPP_TAG_ZERO)) != NULL)
-    job->sheets = attr;
-   
+  else
+    filetype = mimeType(MimeDatabase, super, type);
+
+  if (!filetype)
+  {
+    send_ipp_status(con, IPP_DOCUMENT_FORMAT,
+                    _("Unsupported format \'%s/%s\'!"), super, type);
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Hint: Do you have the raw file printing rules enabled?");
+
+    if (format)
+      ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
+                   "document-format", NULL, format->values[0].string.text);
+
+    return;
+  }
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: request file type is %s/%s.",
+            filetype->super, filetype->type);
+
+ /*
+  * Read any embedded job ticket info from PS files...
+  */
+
+  if (!strcasecmp(filetype->super, "application") &&
+      !strcasecmp(filetype->type, "postscript"))
+    read_ps_job_ticket(con);
+
+ /*
+  * Create the job object...
+  */
+
+  if ((job = add_job(con, uri, &printer)) == NULL)
+    return;
+
+ /*
+  * Update quota data...
+  */
+
+  if (stat(con->filename, &fileinfo))
+    kbytes = 0;
+  else
+    kbytes = (fileinfo.st_size + 1023) / 1024;
+
+  cupsdUpdateQuota(printer, job->username, 0, kbytes);
+
+  if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
+                               IPP_TAG_INTEGER)) != NULL)
+    attr->values[0].integer += kbytes;
+
  /*
   * Add the job file...
   */
@@ -7407,37 +6871,6 @@ print_job(cupsd_client_t  *con,          /* I - Client connection */
     cupsdUpdateQuota(printer, job->username, 0, kbytes);
   }
 
- /*
-  * Fill in the response info...
-  */
-
-  snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
-          LocalPort, job->id);
-
-  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
-               job_uri);
-
-  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
-
-  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;
-
- /*
-  * Add any job subscriptions...
-  */
-
-  add_job_subscriptions(con, job);
-
- /*
-  * Set all but the first two attributes to the job attributes group...
-  */
-
-  for (attr = job->attrs->attrs->next->next; attr; attr = attr->next)
-    attr->group_tag = IPP_TAG_JOB;
-
  /*
   * Log and save the job...
   */
@@ -7449,8 +6882,6 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
 
   cupsdSaveJob(job);
 
-  cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created.");
-
  /*
   * Start the job if possible...
   */
@@ -9020,6 +8451,256 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 }
 
 
+/*
+ * 'set_printer_defaults()' - Set printer default options from a request.
+ */
+
+static void
+set_printer_defaults(
+    cupsd_client_t  *con,              /* I - Client connection */
+    cupsd_printer_t *printer)          /* I - Printer */
+{
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* Current attribute */
+  int                  namelen;        /* Length of attribute name */
+  char                 name[256],      /* New attribute name */
+                       value[256];     /* String version of integer attrs */
+
+
+  for (attr = con->request->attrs; attr; attr = attr->next)
+  {
+   /*
+    * Skip non-printer attributes...
+    */
+
+    if (attr->group_tag != IPP_TAG_PRINTER || !attr->name)
+      continue;
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_printer_defaults: %s", attr->name);
+
+    if (!strcmp(attr->name, "job-sheets-default"))
+    {
+     /*
+      * Only allow keywords and names...
+      */
+
+      if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD)
+        continue;
+
+     /*
+      * Only allow job-sheets-default to be set when running without a
+      * system high classification level...
+      */
+
+      if (Classification)
+        continue;
+
+      cupsdSetString(&printer->job_sheets[0], attr->values[0].string.text);
+
+      if (attr->num_values > 1)
+       cupsdSetString(&printer->job_sheets[1], attr->values[1].string.text);
+      else
+       cupsdSetString(&printer->job_sheets[1], "none");
+    }
+    else if (!strcmp(attr->name, "requesting-user-name-allowed"))
+    {
+      cupsdFreePrinterUsers(printer);
+
+      printer->deny_users = 0;
+
+      if (attr->value_tag == IPP_TAG_NAME &&
+          (attr->num_values > 1 ||
+          strcmp(attr->values[0].string.text, "all")))
+      {
+       for (i = 0; i < attr->num_values; i ++)
+         cupsdAddPrinterUser(printer, attr->values[i].string.text);
+      }
+    }
+    else if (!strcmp(attr->name, "requesting-user-name-denied"))
+    {
+      cupsdFreePrinterUsers(printer);
+
+      printer->deny_users = 1;
+
+      if (attr->value_tag == IPP_TAG_NAME &&
+          (attr->num_values > 1 ||
+          strcmp(attr->values[0].string.text, "none")))
+      {
+       for (i = 0; i < attr->num_values; i ++)
+         cupsdAddPrinterUser(printer, attr->values[i].string.text);
+      }
+    }
+    else if (!strcmp(attr->name, "job-quota-period"))
+    {
+      if (attr->value_tag != IPP_TAG_INTEGER)
+        continue;
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-quota-period to %d...",
+                     attr->values[0].integer);
+      cupsdFreeQuotas(printer);
+
+      printer->quota_period = attr->values[0].integer;
+    }
+    else if (!strcmp(attr->name, "job-k-limit"))
+    {
+      if (attr->value_tag != IPP_TAG_INTEGER)
+        continue;
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-k-limit to %d...",
+                     attr->values[0].integer);
+      cupsdFreeQuotas(printer);
+
+      printer->k_limit = attr->values[0].integer;
+    }
+    else if (!strcmp(attr->name, "job-page-limit"))
+    {
+      if (attr->value_tag != IPP_TAG_INTEGER)
+        continue;
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-page-limit to %d...",
+                     attr->values[0].integer);
+      cupsdFreeQuotas(printer);
+
+      printer->page_limit = attr->values[0].integer;
+    }
+    else if (!strcmp(attr->name, "printer-op-policy"))
+    {
+      cupsd_policy_t *p;               /* Policy */
+
+
+      if (attr->value_tag != IPP_TAG_NAME)
+        continue;
+
+      if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL)
+      {
+       cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "Setting printer-op-policy to \"%s\"...",
+                       attr->values[0].string.text);
+       cupsdSetString(&printer->op_policy, attr->values[0].string.text);
+       printer->op_policy_ptr = p;
+      }
+      else
+      {
+       send_ipp_status(con, IPP_NOT_POSSIBLE,
+                       _("Unknown printer-op-policy \"%s\"."),
+                       attr->values[0].string.text);
+       return;
+      }
+    }
+    else if (!strcmp(attr->name, "printer-error-policy"))
+    {
+      if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD)
+        continue;
+
+      if (strcmp(attr->values[0].string.text, "abort-job") &&
+          strcmp(attr->values[0].string.text, "retry-job") &&
+          strcmp(attr->values[0].string.text, "stop-printer"))
+      {
+       send_ipp_status(con, IPP_NOT_POSSIBLE,
+                       _("Unknown printer-error-policy \"%s\"."),
+                       attr->values[0].string.text);
+       return;
+      }
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                      "Setting printer-error-policy to \"%s\"...",
+                      attr->values[0].string.text);
+      cupsdSetString(&printer->error_policy, attr->values[0].string.text);
+    }
+    else if (!strcmp(attr->name, "document-format-default") ||
+             !strcmp(attr->name, "notify-lease-duration-default") ||
+             !strcmp(attr->name, "notify-notify-events-default"))
+      continue;
+
+   /*
+    * Skip any other non-default attributes...
+    */
+
+    namelen = strlen(attr->name);
+    if (namelen < 9 || strcmp(attr->name + namelen - 8, "-default") ||
+        namelen > (sizeof(name) - 1) || attr->num_values != 1)
+      continue;
+
+   /*
+    * OK, anything else must be a user-defined default...
+    */
+
+    strlcpy(name, attr->name, sizeof(name));
+    name[namelen - 8] = '\0';          /* Strip "-default" */
+
+    switch (attr->value_tag)
+    {
+      case IPP_TAG_DELETEATTR :
+          printer->num_options = cupsRemoveOption(name,
+                                                 printer->num_options,
+                                                 &(printer->options));
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Deleting %s", attr->name);
+          break;
+
+      case IPP_TAG_NAME :
+      case IPP_TAG_KEYWORD :
+      case IPP_TAG_URI :
+          printer->num_options = cupsAddOption(name,
+                                              attr->values[0].string.text,
+                                              printer->num_options,
+                                              &(printer->options));
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Setting %s to \"%s\"...", attr->name,
+                         attr->values[0].string.text);
+          break;
+
+      case IPP_TAG_BOOLEAN :
+          printer->num_options = cupsAddOption(name,
+                                              attr->values[0].boolean ?
+                                                  "true" : "false",
+                                              printer->num_options,
+                                              &(printer->options));
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Setting %s to %s...", attr->name,
+                         attr->values[0].boolean ? "true" : "false");
+          break;
+
+      case IPP_TAG_INTEGER :
+      case IPP_TAG_ENUM :
+          sprintf(value, "%d", attr->values[0].integer);
+          printer->num_options = cupsAddOption(name, value,
+                                              printer->num_options,
+                                              &(printer->options));
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Setting %s to %s...", attr->name, value);
+          break;
+
+      case IPP_TAG_RANGE :
+          sprintf(value, "%d-%d", attr->values[0].range.lower,
+                 attr->values[0].range.upper);
+          printer->num_options = cupsAddOption(name, value,
+                                              printer->num_options,
+                                              &(printer->options));
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Setting %s to %s...", attr->name, value);
+          break;
+
+      case IPP_TAG_RESOLUTION :
+          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");
+          printer->num_options = cupsAddOption(name, value,
+                                              printer->num_options,
+                                              &(printer->options));
+          cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Setting %s to %s...", attr->name, value);
+          break;
+
+      default :
+          /* Do nothing for other values */
+         break;
+    }
+  }
+}
+
+
 /*
  * 'start_printer()' - Start a printer.
  */
@@ -9413,5 +9094,5 @@ validate_user(cupsd_job_t    *job,        /* I - Job */
 
 
 /*
- * End of "$Id: ipp.c 5131 2006-02-18 05:31:36Z mike $".
+ * End of "$Id: ipp.c 5164 2006-02-24 20:40:00Z mike $".
  */