]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/job.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / job.c
index 3fbc59f92b77e83e09cf862000e4ca3dc877ac6b..4860b1326ee4190d2828610f3be56788ab4116a5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: job.c 5196 2006-02-27 21:23:00Z mike $"
+ * "$Id: job.c 5305 2006-03-18 03:05:12Z mike $"
  *
  *   Job management routines for the Common UNIX Printing System (CUPS).
  *
  *   cupsdSetJobHoldUntil()     - Set the hold time for a job...
  *   cupsdSetJobPriority()      - Set the priority of a job, moving it
  *                                up/down in the list as needed.
- *   cupsdStartJob()            - Start a print job.
  *   cupsdStopAllJobs()         - Stop all print jobs.
  *   cupsdStopJob()             - Stop a print job.
  *   cupsdUnloadCompletedJobs() - Flush completed job history from memory.
- *   cupsdUnloadJob()           - Unload a job from memory.
  *   cupsdUpdateJob()           - Read a status update from a jobs filters.
  *   compare_active_jobs()      - Compare the job IDs and priorities of two
  *                                jobs.
@@ -66,6 +64,8 @@
  *   set_time()                 - Set one of the "time-at-xyz" attributes...
  *   set_hold_until()           - Set the hold time and update job-hold-until
  *                                attribute...
+ *   start_job()                - Start a print job.
+ *   unload_job()               - Unload a job from memory.
  */
 
 /*
@@ -104,6 +104,8 @@ static void load_next_job_id(const char *filename);
 static void    load_request_root(void);
 static void    set_time(cupsd_job_t *job, const char *name);
 static void    set_hold_until(cupsd_job_t *job, time_t holdtime);
+static void    start_job(cupsd_job_t *job, cupsd_printer_t *printer);
+static void    unload_job(cupsd_job_t *job);
 
 
 /*
@@ -387,7 +389,7 @@ cupsdCheckJobs(void)
         if (printer->state == IPP_PRINTER_IDLE ||      /* Printer is idle */
            ((printer->type & CUPS_PRINTER_REMOTE) &&   /* Printer is remote */
             !printer->job))                            /* and not printing */
-         cupsdStartJob(job, printer);
+         start_job(job, printer);
       }
     }
   }
@@ -593,7 +595,7 @@ cupsdFinishJob(cupsd_job_t *job)    /* I - Job */
       */
 
       FilterLevel -= job->cost;
-      cupsdStartJob(job, printer);
+      start_job(job, printer);
     }
     else
     {
@@ -1431,1998 +1433,1945 @@ cupsdSetJobPriority(
 
 
 /*
- * 'cupsdStartJob()' - Start a print job.
+ * 'cupsdStopAllJobs()' - Stop all print jobs.
  */
 
 void
-cupsdStartJob(cupsd_job_t     *job,    /* I - Job ID */
-              cupsd_printer_t *printer)        /* I - Printer to print job */
+cupsdStopAllJobs(void)
 {
-  int                  i;              /* Looping var */
-  int                  slot;           /* Pipe slot */
-  cups_array_t         *filters;       /* Filters for job */
-  mime_filter_t                *filter,        /* Current filter */
-                       port_monitor;   /* Port monitor filter */
-  char                 method[255],    /* Method for output */
-                       *optptr,        /* Pointer to options */
-                       *valptr;        /* Pointer in value string */
-  ipp_attribute_t      *attr;          /* Current attribute */
-  struct stat          backinfo;       /* Backend file information */
-  int                  backroot;       /* Run backend as root? */
-  int                  pid;            /* Process ID of new filter process */
-  int                  banner_page;    /* 1 if banner page, 0 otherwise */
-  int                  statusfds[2],   /* Pipes used with the scheduler */
-                       filterfds[2][2];/* Pipes used between filters */
-  int                  envc;           /* Number of environment variables */
-  char                 **argv,         /* Filter command-line arguments */
-                       sani_uri[1024], /* Sanitized DEVICE_URI env var */
-                       filename[1024], /* Job filename */
-                       command[1024],  /* Full path to command */
-                       jobid[255],     /* Job ID string */
-                       title[IPP_MAX_NAME],
-                                       /* Job title string */
-                       copies[255],    /* # copies string */
-                       *envp[MAX_ENV + 11],
-                                       /* Environment variables */
-                       charset[255],   /* CHARSET env variable */
-                       class_name[255],/* CLASS env variable */
-                       classification[1024],
-                                       /* CLASSIFICATION env variable */
-                       content_type[1024],
-                                       /* CONTENT_TYPE env variable */
-                       device_uri[1024],
-                                       /* DEVICE_URI env variable */
-                       final_content_type[1024],
-                                       /* FINAL_CONTENT_TYPE env variable */
-                       lang[255],      /* LANG env variable */
-                       ppd[1024],      /* PPD env variable */
-                       printer_name[255],
-                                       /* PRINTER env variable */
-                       rip_max_cache[255];
-                                       /* RIP_MAX_CACHE env variable */
-  int                  remote_job;     /* Remote print job? */
-  static char          *options = NULL;/* Full list of options */
-  static int           optlength = 0;  /* Length of option buffer */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartJob: id = %d, file = %d/%d",
-                  job->id, job->current_file, job->num_files);
-
-  if (job->num_files == 0)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Job ID %d has no files!  Cancelling it!",
-                    job->id);
-
-    cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                  "Job canceled because it has no files.");
-
-    cupsdCancelJob(job, 0);
-    return;
-  }
+  cupsd_job_t  *job;                   /* Current job */
 
- /*
-  * Figure out what filters are required to convert from
-  * the source to the destination type...
-  */
 
-  filters   = NULL;
-  job->cost = 0;
+  DEBUG_puts("cupsdStopAllJobs()");
 
-  if (printer->raw)
-  {
-   /*
-    * Remote jobs and raw queues go directly to the printer without
-    * filtering...
-    */
+  for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
+       job;
+       job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
+    if (job->state_value == IPP_JOB_PROCESSING)
+    {
+      cupsdStopJob(job, 1);
+      job->state->values[0].integer = IPP_JOB_PENDING;
+      job->state_value              = IPP_JOB_PENDING;
+    }
+}
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "[Job %d] Sending job to queue tagged as raw...", job->id);
 
-    filters = NULL;
-  }
-  else
-  {
-   /*
-    * Local jobs get filtered...
-    */
+/*
+ * 'cupsdStopJob()' - Stop a print job.
+ */
 
-    filters = mimeFilter(MimeDatabase, job->filetypes[job->current_file],
-                         printer->filetype, &(job->cost));
+void
+cupsdStopJob(cupsd_job_t *job,         /* I - Job */
+             int         force)                /* I - 1 = Force all filters to stop */
+{
+  int  i;                              /* Looping var */
 
-    if (!filters)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to convert file %d to printable format for "
-                     "job %d!",
-                     job->current_file, job->id);
-      cupsdLogMessage(CUPSD_LOG_INFO,
-                      "Hint: Do you have ESP Ghostscript installed?");
 
-      if (LogLevel < CUPSD_LOG_DEBUG)
-        cupsdLogMessage(CUPSD_LOG_INFO,
-                       "Hint: Try setting the LogLevel to \"debug\".");
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStopJob: id = %d, force = %d",
+                  job->id, force);
 
-      job->current_file ++;
+  if (job->state_value != IPP_JOB_PROCESSING)
+    return;
 
-      if (job->current_file == job->num_files)
-      {
-       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                      "Job canceled because it has no files that can be "
-                     "printed.");
+  FilterLevel -= job->cost;
 
-        cupsdCancelJob(job, 0);
-      }
+  if (job->status < 0 &&
+      !(job->dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)) &&
+      !(job->printer->type & CUPS_PRINTER_FAX) &&
+      !strcmp(job->printer->error_policy, "stop-printer"))
+    cupsdSetPrinterState(job->printer, IPP_PRINTER_STOPPED, 1);
+  else if (job->printer->state != IPP_PRINTER_STOPPED)
+    cupsdSetPrinterState(job->printer, IPP_PRINTER_IDLE, 0);
 
-      return;
-    }
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStopJob: printer state is %d",
+                  job->printer->state);
 
-   /*
-    * Remove NULL ("-") filters...
-    */
+  job->state->values[0].integer = IPP_JOB_STOPPED;
+  job->state_value              = IPP_JOB_STOPPED;
+  job->printer->job = NULL;
+  job->printer      = NULL;
 
-    for (filter = (mime_filter_t *)cupsArrayFirst(filters);
-         filter;
-        filter = (mime_filter_t *)cupsArrayNext(filters))
-      if (!strcmp(filter->filter, "-"))
-        cupsArrayRemove(filters, filter);
+  job->current_file --;
 
-    if (cupsArrayCount(filters) == 0)
+  for (i = 0; job->filters[i]; i ++)
+    if (job->filters[i] > 0)
     {
-      cupsArrayDelete(filters);
-      filters = NULL;
+      cupsdEndProcess(job->filters[i], force);
+      job->filters[i] = 0;
     }
-  }
-
- /*
-  * See if the filter cost is too high...
-  */
 
-  if ((FilterLevel + job->cost) > FilterLimit && FilterLevel > 0 &&
-      FilterLimit > 0)
+  if (job->backend > 0)
   {
-   /*
-    * Don't print this job quite yet...
-    */
-
-    cupsArrayDelete(filters);
-
-    cupsdLogMessage(CUPSD_LOG_INFO,
-                    "Holding job %d because filter limit has been reached.",
-                    job->id);
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStartJob: id=%d, file=%d, cost=%d, level=%d, "
-                   "limit=%d",
-                    job->id, job->current_file, job->cost, FilterLevel,
-                   FilterLimit);
-    return;
+    cupsdEndProcess(job->backend, force);
+    job->backend = 0;
   }
 
-  FilterLevel += job->cost;
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "cupsdStopJob: Closing print pipes [ %d %d ]...",
+                  job->print_pipes[0], job->print_pipes[1]);
 
- /*
-  * Determine if we are printing to a remote printer...
-  */
+  cupsdClosePipe(job->print_pipes);
 
-  remote_job = printer->raw && job->num_files > 1 &&
-               !strncmp(printer->device_uri, "ipp://", 6);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "cupsdStopJob: Closing back pipes [ %d %d ]...",
+                  job->back_pipes[0], job->back_pipes[1]);
 
- /*
-  * Add decompression filters, if any...
-  */
+  cupsdClosePipe(job->back_pipes);
 
-  if (!remote_job && job->compressions[job->current_file])
+  if (job->status_buffer)
   {
    /*
-    * Add gziptoany filter to the front of the list...
+    * Close the pipe and clear the input bit.
     */
 
-    if (!cupsArrayInsert(filters, &gziptoany_filter))
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to add decompression filter - %s",
-                     strerror(errno));
-
-      cupsArrayDelete(filters);
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "cupsdStopJob: Removing fd %d from InputSet...",
+                   job->status_buffer->fd);
 
-      job->current_file ++;
+    FD_CLR(job->status_buffer->fd, InputSet);
 
-      if (job->current_file == job->num_files)
-      {
-       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                      "Job canceled because the print file could not be "
-                     "decompressed.");
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "cupsdStopJob: Closing status input pipe %d...",
+                    job->status_buffer->fd);
 
-        cupsdCancelJob(job, 0);
-      }
+    cupsdStatBufDelete(job->status_buffer);
 
-      return;
-    }
+    job->status_buffer = NULL;
   }
+}
 
- /*
-  * Add port monitor, if any...
-  */
 
-  if (printer->port_monitor)
-  {
-   /*
-    * Add port monitor to the end of the list...
-    */
+/*
+ * 'cupsdUnloadCompletedJobs()' - Flush completed job history from memory.
+ */
 
-    if (!cupsArrayAdd(filters, &port_monitor))
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to add port monitor - %s",
-                      strerror(errno));
+void
+cupsdUnloadCompletedJobs(void)
+{
+  cupsd_job_t  *job;                   /* Current job */
+  time_t       expire;                 /* Expiration time */
 
-      cupsArrayDelete(filters);
 
-      job->current_file ++;
+  expire = time(NULL) - 60;
 
-      if (job->current_file == job->num_files)
-      {
-       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                      "Job canceled because the port monitor could not be "
-                     "added.");
-
-        cupsdCancelJob(job, 0);
-      }
-
-      return;
-    }
-
-    snprintf(port_monitor.filter, sizeof(port_monitor.filter),
-             "%s/monitor/%s", ServerBin, printer->port_monitor);
-  }
+  for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
+       job;
+       job = (cupsd_job_t *)cupsArrayNext(Jobs))
+    if (job->attrs && job->state_value >= IPP_JOB_STOPPED &&
+        job->access_time < expire)
+      unload_job(job);
+}
 
- /*
-  * Update the printer and job state to "processing"...
-  */
 
-  job->state->values[0].integer = IPP_JOB_PROCESSING;
-  job->state_value              = IPP_JOB_PROCESSING;
-  job->status  = 0;
-  job->printer = printer;
-  printer->job = job;
-  cupsdSetPrinterState(printer, IPP_PRINTER_PROCESSING, 0);
+/*
+ * 'cupsdUpdateJob()' - Read a status update from a job's filters.
+ */
 
-  if (job->current_file == 0)
-  {
-    set_time(job, "time-at-processing");
-    cupsdOpenPipe(job->back_pipes);
-  }
+void
+cupsdUpdateJob(cupsd_job_t *job)       /* I - Job to check */
+{
+  int          i;                      /* Looping var */
+  int          copies;                 /* Number of copies printed */
+  char         message[1024],          /* Message text */
+               *ptr;                   /* Pointer update... */
+  int          loglevel;               /* Log level for message */
 
- /*
-  * Determine if we are printing a banner page or not...
-  */
 
-  if (job->job_sheets == NULL)
+  while ((ptr = cupsdStatBufUpdate(job->status_buffer, &loglevel,
+                                   message, sizeof(message))) != NULL)
   {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "No job-sheets attribute.");
-    if ((job->job_sheets =
-         ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) != NULL)
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
-                      "... but someone added one without setting job_sheets!");
-  }
-  else if (job->job_sheets->num_values == 1)
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "job-sheets=%s",
-               job->job_sheets->values[0].string.text);
-  else
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "job-sheets=%s,%s",
-               job->job_sheets->values[0].string.text,
-               job->job_sheets->values[1].string.text);
+   /*
+    * Process page and printer state messages as needed...
+    */
 
-  if (printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
-    banner_page = 0;
-  else if (job->job_sheets == NULL)
-    banner_page = 0;
-  else if (strcasecmp(job->job_sheets->values[0].string.text, "none") != 0 &&
-          job->current_file == 0)
-    banner_page = 1;
-  else if (job->job_sheets->num_values > 1 &&
-          strcasecmp(job->job_sheets->values[1].string.text, "none") != 0 &&
-          job->current_file == (job->num_files - 1))
-    banner_page = 1;
-  else
-    banner_page = 0;
+    if (loglevel == CUPSD_LOG_PAGE)
+    {
+     /*
+      * Page message; send the message to the page_log file and update the
+      * job sheet count...
+      */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "banner_page = %d", banner_page);
+      if (job->sheets != NULL)
+      {
+        if (!strncasecmp(message, "total ", 6))
+       {
+        /*
+         * Got a total count of pages from a backend or filter...
+         */
 
- /*
-  * Building the options string is harder than it needs to be, but
-  * for the moment we need to pass strings for command-line args and
-  * not IPP attribute pointers... :)
-  *
-  * First allocate/reallocate the option buffer as needed...
-  */
+         copies = atoi(message + 6);
+         copies -= job->sheets->values[0].integer; /* Just track the delta */
+       }
+       else if (!sscanf(message, "%*d%d", &copies))
+         copies = 1;
+         
+        job->sheets->values[0].integer += copies;
 
-  i = ipp_length(job->attrs);
+       if (job->printer->page_limit)
+         cupsdUpdateQuota(job->printer, job->username, copies, 0);
+      }
 
-  if (i > optlength)
-  {
-    if (optlength == 0)
-      optptr = malloc(i);
-    else
-      optptr = realloc(options, i);
+      cupsdLogPage(job, message);
 
-    if (optptr == NULL)
+      cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, job->printer, job,
+                    "Printed %d page(s).", job->sheets->values[0].integer);
+    }
+    else if (loglevel == CUPSD_LOG_STATE)
     {
-      cupsdLogMessage(CUPSD_LOG_CRIT,
-                      "Unable to allocate %d bytes for option buffer for "
-                     "job %d!", i, job->id);
-
-      cupsArrayDelete(filters);
-
-      FilterLevel -= job->cost;
-
-      cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                    "Job canceled because the server ran out of memory.");
-
-      cupsdCancelJob(job, 0);
-      return;
+      cupsdSetPrinterReasons(job->printer, message);
+      cupsdAddPrinterHistory(job->printer);
     }
+    else if (loglevel == CUPSD_LOG_ATTR)
+    {
+     /*
+      * Set attribute(s)...
+      */
 
-    options   = optptr;
-    optlength = i;
-  }
+      /**** TODO ****/
+    }
+#ifdef __APPLE__
+    else if (!strncmp(message, "recoverable:", 12))
+    {
+      cupsdSetPrinterReasons(job->printer,
+                             "+com.apple.print.recoverable-warning");
 
- /*
-  * Now loop through the attributes and convert them to the textual
-  * representation used by the filters...
-  */
+      ptr = message + 12;
+      while (isspace(*ptr & 255))
+        ptr ++;
 
-  optptr  = options;
-  *optptr = '\0';
+      cupsdSetString(&job->printer->recoverable, ptr);
+      cupsdAddPrinterHistory(job->printer);
+    }
+    else if (!strncmp(message, "recovered:", 10))
+    {
+      cupsdSetPrinterReasons(job->printer,
+                             "-com.apple.print.recoverable-warning");
 
-  snprintf(title, sizeof(title), "%s-%d", printer->name, job->id);
-  strcpy(copies, "1");
+      ptr = message + 10;
+      while (isspace(*ptr & 255))
+        ptr ++;
 
-  for (attr = job->attrs->attrs; attr != NULL; attr = attr->next)
-  {
-    if (!strcmp(attr->name, "copies") &&
-       attr->value_tag == IPP_TAG_INTEGER)
+      cupsdSetString(&job->printer->recoverable, ptr);
+      cupsdAddPrinterHistory(job->printer);
+    }
+#endif /* __APPLE__ */
+    else if (loglevel <= CUPSD_LOG_INFO)
     {
      /*
-      * Don't use the # copies attribute if we are printing the job sheets...
+      * Some message to show in the printer-state-message attribute...
       */
 
-      if (!banner_page)
-        sprintf(copies, "%d", attr->values[0].integer);
+      strlcpy(job->printer->state_message, message,
+              sizeof(job->printer->state_message));
+      cupsdAddPrinterHistory(job->printer);
     }
-    else if (!strcmp(attr->name, "job-name") &&
-            (attr->value_tag == IPP_TAG_NAME ||
-             attr->value_tag == IPP_TAG_NAMELANG))
-      strlcpy(title, attr->values[0].string.text, sizeof(title));
-    else if (attr->group_tag == IPP_TAG_JOB)
-    {
-     /*
-      * Filter out other unwanted attributes...
-      */
 
-      if (attr->value_tag == IPP_TAG_MIMETYPE ||
-         attr->value_tag == IPP_TAG_NAMELANG ||
-         attr->value_tag == IPP_TAG_TEXTLANG ||
-         (attr->value_tag == IPP_TAG_URI && strcmp(attr->name, "job-uuid")) ||
-         attr->value_tag == IPP_TAG_URISCHEME ||
-         attr->value_tag == IPP_TAG_BEGIN_COLLECTION) /* Not yet supported */
-       continue;
+    if (!strchr(job->status_buffer->buffer, '\n'))
+      break;
+  }
 
-      if (!strncmp(attr->name, "time-", 5))
-       continue;
+  if (ptr == NULL)
+  {
+   /*
+    * See if all of the filters and the backend have returned their
+    * exit statuses.
+    */
 
-      if (!strncmp(attr->name, "job-", 4) && strcmp(attr->name, "job-uuid") &&
-          !(printer->type & CUPS_PRINTER_REMOTE))
-       continue;
+    for (i = 0; job->filters[i] < 0; i ++);
 
-      if (!strncmp(attr->name, "job-", 4) &&
-          strcmp(attr->name, "job-uuid") &&
-          strcmp(attr->name, "job-billing") &&
-          strcmp(attr->name, "job-sheets") &&
-          strcmp(attr->name, "job-hold-until") &&
-         strcmp(attr->name, "job-priority"))
-       continue;
+    if (job->filters[i])
+      return;
 
-      if ((!strcmp(attr->name, "page-label") ||
-           !strcmp(attr->name, "page-border") ||
-           !strncmp(attr->name, "number-up", 9) ||
-          !strcmp(attr->name, "page-set") ||
-          !strcasecmp(attr->name, "AP_FIRSTPAGE_InputSlot") ||
-          !strcasecmp(attr->name, "AP_FIRSTPAGE_ManualFeed")) &&
-         banner_page)
-        continue;
+    if (job->current_file >= job->num_files && job->backend > 0)
+      return;
 
-     /*
-      * Otherwise add them to the list...
-      */
+   /*
+    * Handle the end of job stuff...
+    */
 
-      if (optptr > options)
-       strlcat(optptr, " ", optlength - (optptr - options));
+    cupsdFinishJob(job);
+  }
+}
 
-      if (attr->value_tag != IPP_TAG_BOOLEAN)
-      {
-       strlcat(optptr, attr->name, optlength - (optptr - options));
-       strlcat(optptr, "=", optlength - (optptr - options));
-      }
 
-      for (i = 0; i < attr->num_values; i ++)
-      {
-       if (i)
-         strlcat(optptr, ",", optlength - (optptr - options));
+/*
+ * 'compare_active_jobs()' - Compare the job IDs and priorities of two jobs.
+ */
 
-       optptr += strlen(optptr);
+static int                             /* O - Difference */
+compare_active_jobs(void *first,       /* I - First job */
+                    void *second,      /* I - Second job */
+                   void *data)         /* I - App data (not used) */
+{
+  int  diff;                           /* Difference */
 
-       switch (attr->value_tag)
-       {
-         case IPP_TAG_INTEGER :
-         case IPP_TAG_ENUM :
-             snprintf(optptr, optlength - (optptr - options),
-                      "%d", attr->values[i].integer);
-             break;
 
-         case IPP_TAG_BOOLEAN :
-             if (!attr->values[i].boolean)
-               strlcat(optptr, "no", optlength - (optptr - options));
+  if ((diff = ((cupsd_job_t *)first)->priority -
+              ((cupsd_job_t *)second)->priority) != 0)
+    return (diff);
+  else
+    return (((cupsd_job_t *)first)->id - ((cupsd_job_t *)second)->id);
+}
 
-         case IPP_TAG_NOVALUE :
-             strlcat(optptr, attr->name,
-                     optlength - (optptr - options));
-             break;
 
-         case IPP_TAG_RANGE :
-             if (attr->values[i].range.lower == attr->values[i].range.upper)
-               snprintf(optptr, optlength - (optptr - options) - 1,
-                        "%d", attr->values[i].range.lower);
-              else
-               snprintf(optptr, optlength - (optptr - options) - 1,
-                        "%d-%d", attr->values[i].range.lower,
-                        attr->values[i].range.upper);
-             break;
+/*
+ * 'compare_jobs()' - Compare the job IDs of two jobs.
+ */
 
-         case IPP_TAG_RESOLUTION :
-             snprintf(optptr, optlength - (optptr - options) - 1,
-                      "%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;
+static int                             /* O - Difference */
+compare_jobs(void *first,              /* I - First job */
+             void *second,             /* I - Second job */
+            void *data)                /* I - App data (not used) */
+{
+  return (((cupsd_job_t *)first)->id - ((cupsd_job_t *)second)->id);
+}
 
-          case IPP_TAG_STRING :
-         case IPP_TAG_TEXT :
-         case IPP_TAG_NAME :
-         case IPP_TAG_KEYWORD :
-         case IPP_TAG_CHARSET :
-         case IPP_TAG_LANGUAGE :
-         case IPP_TAG_URI :
-             for (valptr = attr->values[i].string.text; *valptr;)
-             {
-               if (strchr(" \t\n\\\'\"", *valptr))
-                 *optptr++ = '\\';
-               *optptr++ = *valptr++;
-             }
 
-             *optptr = '\0';
-             break;
+/*
+ * 'free_job()' - Free all memory used by a job.
+ */
 
-          default :
-             break; /* anti-compiler-warning-code */
-       }
-      }
+static void
+free_job(cupsd_job_t *job)             /* I - Job */
+{
+  cupsdClearString(&job->username);
+  cupsdClearString(&job->dest);
 
-      optptr += strlen(optptr);
-    }
+  if (job->num_files > 0)
+  {
+    free(job->compressions);
+    free(job->filetypes);
   }
 
- /*
-  * Build the command-line arguments for the filters.  Each filter
-  * has 6 or 7 arguments:
-  *
-  *     argv[0] = printer
-  *     argv[1] = job ID
-  *     argv[2] = username
-  *     argv[3] = title
-  *     argv[4] = # copies
-  *     argv[5] = options
-  *     argv[6] = filename (optional; normally stdin)
-  *
-  * This allows legacy printer drivers that use the old System V
-  * printing interface to be used by CUPS.
-  *
-  * For remote jobs, we send all of the files in the argument list.
-  */
+  ippDelete(job->attrs);
 
-  if (remote_job)
-    argv = calloc(7 + job->num_files, sizeof(char *));
-  else
-    argv = calloc(8, sizeof(char *));
+  free(job);
+}
 
-  sprintf(jobid, "%d", job->id);
 
-  argv[0] = printer->name;
-  argv[1] = jobid;
-  argv[2] = job->username;
-  argv[3] = title;
-  argv[4] = copies;
-  argv[5] = options;
+/*
+ * 'ipp_length()' - Compute the size of the buffer needed to hold 
+ *                 the textual IPP attributes.
+ */
 
-  if (remote_job)
-  {
-    for (i = 0; i < job->num_files; i ++)
-    {
-      snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
-               job->id, i + 1);
-      argv[6 + i] = strdup(filename);
-    }
-  }
-  else
-  {
-    snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
-             job->id, job->current_file + 1);
-    argv[6] = filename;
-  }
+static int                             /* O - Size of attribute buffer */
+ipp_length(ipp_t *ipp)                 /* I - IPP request */
+{
+  int                  bytes;          /* Number of bytes */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* Current attribute */
 
-  for (i = 0; argv[i]; i ++)
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "[Job %d] argv[%d]=\"%s\"", job->id, i, argv[i]);
 
  /*
-  * Create environment variable strings for the filters...
+  * Loop through all attributes...
   */
 
-  attr = ippFindAttribute(job->attrs, "attributes-natural-language",
-                          IPP_TAG_LANGUAGE);
+  bytes = 0;
 
-  switch (strlen(attr->values[0].string.text))
+  for (attr = ipp->attrs; attr != NULL; attr = attr->next)
   {
-    default :
-       /*
-        * This is an unknown or badly formatted language code; use
-       * the POSIX locale...
-       */
+   /*
+    * Skip attributes that won't be sent to filters...
+    */
 
-       strcpy(lang, "LANG=C");
-       break;
+    if (attr->value_tag == IPP_TAG_MIMETYPE ||
+       attr->value_tag == IPP_TAG_NAMELANG ||
+       attr->value_tag == IPP_TAG_TEXTLANG ||
+       attr->value_tag == IPP_TAG_URI ||
+       attr->value_tag == IPP_TAG_URISCHEME)
+      continue;
 
-    case 2 :
-       /*
-        * Just the language code (ll)...
-       */
+    if (strncmp(attr->name, "time-", 5) == 0)
+      continue;
 
-        snprintf(lang, sizeof(lang), "LANG=%s",
-                attr->values[0].string.text);
-        break;
+   /*
+    * Add space for a leading space and commas between each value.
+    * For the first attribute, the leading space isn't used, so the
+    * extra byte can be used as the nul terminator...
+    */
 
-    case 5 :
-       /*
-        * Language and country code (ll-cc)...
-       */
+    bytes ++;                          /* " " separator */
+    bytes += attr->num_values;         /* "," separators */
 
-        snprintf(lang, sizeof(lang), "LANG=%c%c_%c%c",
-                attr->values[0].string.text[0],
-                attr->values[0].string.text[1],
-                toupper(attr->values[0].string.text[3] & 255),
-                toupper(attr->values[0].string.text[4] & 255));
-        break;
-  }
+   /*
+    * Boolean attributes appear as "foo,nofoo,foo,nofoo", while
+    * other attributes appear as "foo=value1,value2,...,valueN".
+    */
 
-  attr = ippFindAttribute(job->attrs, "document-format",
-                          IPP_TAG_MIMETYPE);
-  if (attr != NULL &&
-      (optptr = strstr(attr->values[0].string.text, "charset=")) != NULL)
-    snprintf(charset, sizeof(charset), "CHARSET=%s", optptr + 8);
-  else
-  {
-    attr = ippFindAttribute(job->attrs, "attributes-charset",
-                           IPP_TAG_CHARSET);
-    snprintf(charset, sizeof(charset), "CHARSET=%s",
-             attr->values[0].string.text);
-  }
+    if (attr->value_tag != IPP_TAG_BOOLEAN)
+      bytes += strlen(attr->name);
+    else
+      bytes += attr->num_values * strlen(attr->name);
 
-  snprintf(content_type, sizeof(content_type), "CONTENT_TYPE=%s/%s",
-           job->filetypes[job->current_file]->super,
-           job->filetypes[job->current_file]->type);
-  snprintf(device_uri, sizeof(device_uri), "DEVICE_URI=%s",
-           printer->device_uri);
-  cupsdSanitizeURI(printer->device_uri, sani_uri, sizeof(sani_uri));
-  snprintf(ppd, sizeof(ppd), "PPD=%s/ppd/%s.ppd", ServerRoot, printer->name);
-  snprintf(printer_name, sizeof(printer_name), "PRINTER=%s", printer->name);
-  snprintf(rip_max_cache, sizeof(rip_max_cache), "RIP_MAX_CACHE=%s", RIPCache);
+   /*
+    * Now add the size required for each value in the attribute...
+    */
 
-  envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+    switch (attr->value_tag)
+    {
+      case IPP_TAG_INTEGER :
+      case IPP_TAG_ENUM :
+         /*
+         * Minimum value of a signed integer is -2147483647, or 11 digits.
+         */
 
-  envp[envc ++] = charset;
-  envp[envc ++] = lang;
-  envp[envc ++] = ppd;
-  envp[envc ++] = rip_max_cache;
-  envp[envc ++] = content_type;
-  envp[envc ++] = device_uri;
-  envp[envc ++] = printer_name;
+         bytes += attr->num_values * 11;
+         break;
 
-  if ((filter = (mime_filter_t *)cupsArrayLast(filters)) != NULL)
-  {
-    snprintf(final_content_type, sizeof(final_content_type),
-             "FINAL_CONTENT_TYPE=%s/%s",
-            filter->dst->super, filter->dst->type);
-    envp[envc ++] = final_content_type;
-  }
-
-  if (Classification && !banner_page)
-  {
-    if ((attr = ippFindAttribute(job->attrs, "job-sheets",
-                                 IPP_TAG_NAME)) == NULL)
-      snprintf(classification, sizeof(classification), "CLASSIFICATION=%s",
-               Classification);
-    else if (attr->num_values > 1 &&
-             strcmp(attr->values[1].string.text, "none") != 0)
-      snprintf(classification, sizeof(classification), "CLASSIFICATION=%s",
-               attr->values[1].string.text);
-    else
-      snprintf(classification, sizeof(classification), "CLASSIFICATION=%s",
-               attr->values[0].string.text);
-
-    envp[envc ++] = classification;
-  }
-
-  if (job->dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
-  {
-    snprintf(class_name, sizeof(class_name), "CLASS=%s", job->dest);
-    envp[envc ++] = class_name;
-  }
-
-  envp[envc] = NULL;
+      case IPP_TAG_BOOLEAN :
+         /*
+         * Add two bytes for each false ("no") value...
+         */
 
-  for (i = 0; i < envc; i ++)
-    if (strncmp(envp[i], "DEVICE_URI=", 11))
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] envp[%d]=\"%s\"",
-                      job->id, i, envp[i]);
-    else
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] envp[%d]=\"DEVICE_URI=%s\"",
-                      job->id, i, sani_uri);
+          for (i = 0; i < attr->num_values; i ++)
+           if (!attr->values[i].boolean)
+             bytes += 2;
+         break;
 
-  if (remote_job)
-    job->current_file = job->num_files;
-  else
-    job->current_file ++;
+      case IPP_TAG_RANGE :
+         /*
+         * A range is two signed integers separated by a hyphen, or
+         * 23 characters max.
+         */
 
- /*
-  * Now create processes for all of the filters...
-  */
+         bytes += attr->num_values * 23;
+         break;
 
-  if (cupsdOpenPipe(statusfds))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create job status pipes - %s.",
-                   strerror(errno));
-    snprintf(printer->state_message, sizeof(printer->state_message),
-             "Unable to create status pipes - %s.", strerror(errno));
+      case IPP_TAG_RESOLUTION :
+         /*
+         * A resolution is two signed integers separated by an "x" and
+         * suffixed by the units, or 26 characters max.
+         */
 
-    cupsdAddPrinterHistory(printer);
+         bytes += attr->num_values * 26;
+         break;
 
-    cupsArrayDelete(filters);
+      case IPP_TAG_STRING :
+      case IPP_TAG_TEXT :
+      case IPP_TAG_NAME :
+      case IPP_TAG_KEYWORD :
+      case IPP_TAG_CHARSET :
+      case IPP_TAG_LANGUAGE :
+      case IPP_TAG_URI :
+         /*
+         * Strings can contain characters that need quoting.  We need
+         * at least 2 * len + 2 characters to cover the quotes and
+         * any backslashes in the string.
+         */
 
-    cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                  "Job canceled because the server could not create the job "
-                 "status pipes.");
+          for (i = 0; i < attr->num_values; i ++)
+           bytes += 2 * strlen(attr->values[i].string.text) + 2;
+         break;
 
-    if (remote_job)
-    {
-      for (i = 0; i < job->num_files; i ++)
-        free(argv[i + 6]);
+       default :
+         break; /* anti-compiler-warning-code */
     }
-
-    free(argv);
-
-    cupsdCancelJob(job, 0);
-    return;
   }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartJob: statusfds = [ %d %d ]",
-                  statusfds[0], statusfds[1]);
-
-#ifdef FD_CLOEXEC
-  fcntl(statusfds[0], F_SETFD, FD_CLOEXEC);
-  fcntl(statusfds[1], F_SETFD, FD_CLOEXEC);
-#endif /* FD_CLOEXEC */
-
-  job->status_buffer = cupsdStatBufNew(statusfds[0], "[Job %d]",
-                                           job->id);
-  job->status        = 0;
-  memset(job->filters, 0, sizeof(job->filters));
+  return (bytes);
+}
 
-  filterfds[1][0] = open("/dev/null", O_RDONLY);
-  filterfds[1][1] = -1;
 
-  if (filterfds[1][0] < 0)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"/dev/null\" - %s.",
-                    strerror(errno));
-    snprintf(printer->state_message, sizeof(printer->state_message),
-             "Unable to open \"/dev/null\" - %s.", strerror(errno));
+/*
+ * 'load_job_cache()' - Load jobs from the job.cache file.
+ */
 
-    cupsdAddPrinterHistory(printer);
+static void
+load_job_cache(const char *filename)   /* I - job.cache filename */
+{
+  cups_file_t  *fp;                    /* job.cache file */
+  char         line[1024],             /* Line buffer */
+               *value;                 /* Value on line */
+  int          linenum;                /* Line number in file */
+  cupsd_job_t  *job;                   /* Current job */
+  int          jobid;                  /* Job ID */
+  char         jobfile[1024];          /* Job filename */
 
-    cupsArrayDelete(filters);
 
-    cupsdClosePipe(statusfds);
+ /*
+  * Open the job.cache file...
+  */
 
-    if (remote_job)
-    {
-      for (i = 0; i < job->num_files; i ++)
-        free(argv[i + 6]);
-    }
+  if ((fp = cupsFileOpen(filename, "r")) == NULL)
+  {
+    if (errno != ENOENT)
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to open job cache file \"%s\": %s",
+                      filename, strerror(errno));
 
-    free(argv);
+    load_request_root();
 
-    cupsdCancelJob(job, 0);
     return;
   }
 
-  fcntl(filterfds[1][0], F_SETFD, fcntl(filterfds[1][0], F_GETFD) | FD_CLOEXEC);
+ /*
+  * Read entries from the job cache file and create jobs as needed.
+  */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartJob: filterfds[%d] = [ %d %d ]",
-                  1, filterfds[1][0], filterfds[1][1]);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Loading job cache file \"%s\"...",
+                  filename);
 
-  for (i = 0, slot = 0, filter = (mime_filter_t *)cupsArrayFirst(filters);
-       filter;
-       i ++, filter = (mime_filter_t *)cupsArrayNext(filters))
-  {
-    if (filter->filter[0] != '/')
-      snprintf(command, sizeof(command), "%s/filter/%s", ServerBin,
-               filter->filter);
-    else
-      strlcpy(command, filter->filter, sizeof(command));
+  linenum = 0;
+  job     = NULL;
 
-    if (i < (cupsArrayCount(filters) - 1))
+  while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
+  {
+    if (!strcasecmp(line, "NextJobId"))
     {
-      if (cupsdOpenPipe(filterfds[slot]))
+      if (value)
+        NextJobId = atoi(value);
+    }
+    else if (!strcasecmp(line, "<Job"))
+    {
+      if (job)
       {
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to create job filter pipes - %s.",
-                       strerror(errno));
-       snprintf(printer->state_message, sizeof(printer->state_message),
-               "Unable to create filter pipes - %s.", strerror(errno));
-       cupsdAddPrinterHistory(printer);
-
-       cupsArrayDelete(filters);
-
-       cupsdClosePipe(statusfds);
-       cupsdClosePipe(filterfds[!slot]);
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Missing </Job> directive on line %d!",
+                       linenum);
+        continue;
+      }
 
-       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                      "Job canceled because the server could not create the "
-                     "filter pipes.");
+      if (!value)
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Missing job ID on line %d!", linenum);
+       continue;
+      }
 
-        if (remote_job)
-       {
-         for (i = 0; i < job->num_files; i ++)
-            free(argv[i + 6]);
-       }
+      jobid = atoi(value);
 
-       free(argv);
+      if (jobid < 1)
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Bad job ID %d on line %d!", jobid,
+                       linenum);
+        continue;
+      }
 
-       cupsdCancelJob(job, 0);
-       return;
+      snprintf(jobfile, sizeof(jobfile), "%s/c%05d", RequestRoot, jobid);
+      if (access(jobfile, 0))
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Job %d files have gone away!", jobid);
+        continue;
       }
-    }
-    else
-    {
-      if (job->current_file == 1)
+
+      job = calloc(1, sizeof(cupsd_job_t));
+      if (!job)
       {
-       if (strncmp(printer->device_uri, "file:", 5) != 0)
-       {
-         if (cupsdOpenPipe(job->print_pipes))
-         {
-           cupsdLogMessage(CUPSD_LOG_ERROR,
-                           "Unable to create job backend pipes - %s.",
-                           strerror(errno));
-           snprintf(printer->state_message, sizeof(printer->state_message),
-                   "Unable to create backend pipes - %s.", strerror(errno));
-           cupsdAddPrinterHistory(printer);
+        cupsdLogMessage(CUPSD_LOG_EMERG,
+                       "Unable to allocate memory for job %d!", jobid);
+        break;
+      }
 
-           cupsArrayDelete(filters);
+      job->id             = jobid;
+      job->back_pipes[0]  = -1;
+      job->back_pipes[1]  = -1;
+      job->print_pipes[0] = -1;
+      job->print_pipes[1] = -1;
 
-           cupsdClosePipe(statusfds);
-           cupsdClosePipe(filterfds[!slot]);
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading job %d from cache...", job->id);
+    }
+    else if (!job)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Missing <Job #> directive on line %d!", linenum);
+      continue;
+    }
+    else if (!strcasecmp(line, "</Job>"))
+    {
+      cupsArrayAdd(Jobs, job);
 
-           cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                         "Job canceled because the server could not create "
-                         "the backend pipes.");
+      if (job->state_value < IPP_JOB_STOPPED)
+      {
+        cupsArrayAdd(ActiveJobs, job);
+       cupsdLoadJob(job);
+      }
 
-            if (remote_job)
-           {
-             for (i = 0; i < job->num_files; i ++)
-               free(argv[i + 6]);
-           }
+      job = NULL;
+    }
+    else if (!value)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d!", linenum);
+      continue;
+    }
+    else if (!strcasecmp(line, "State"))
+    {
+      job->state_value = atoi(value);
+
+      if (job->state_value < IPP_JOB_PENDING)
+        job->state_value = IPP_JOB_PENDING;
+      else if (job->state_value > IPP_JOB_COMPLETED)
+        job->state_value = IPP_JOB_COMPLETED;
+    }
+    else if (!strcasecmp(line, "Priority"))
+    {
+      job->priority = atoi(value);
+    }
+    else if (!strcasecmp(line, "Username"))
+    {
+      cupsdSetString(&job->username, value);
+    }
+    else if (!strcasecmp(line, "Destination"))
+    {
+      cupsdSetString(&job->dest, value);
+    }
+    else if (!strcasecmp(line, "DestType"))
+    {
+      job->dtype = (cups_ptype_t)atoi(value);
+    }
+    else if (!strcasecmp(line, "NumFiles"))
+    {
+      job->num_files = atoi(value);
 
-           free(argv);
+      if (job->num_files < 0)
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR, "Bad NumFiles value %d on line %d!",
+                       job->num_files, linenum);
+        job->num_files = 0;
+       continue;
+      }
 
-           cupsdCancelJob(job, 0);
-           return;
-         }
+      if (job->num_files > 0)
+      {
+        snprintf(jobfile, sizeof(jobfile), "%s/d%05d-001", RequestRoot,
+                job->id);
+        if (access(jobfile, 0))
+       {
+         cupsdLogMessage(CUPSD_LOG_INFO,
+                         "Data files for job %d have gone away!", job->id);
+          job->num_files = 0;
+         continue;
        }
-       else
+
+        job->filetypes    = calloc(job->num_files, sizeof(mime_type_t *));
+       job->compressions = calloc(job->num_files, sizeof(int));
+
+        if (!job->filetypes || !job->compressions)
        {
-         job->print_pipes[0] = -1;
-         if (!strncmp(printer->device_uri, "file:/dev/", 10) &&
-             strcmp(printer->device_uri, "file:/dev/null"))
-           job->print_pipes[1] = open(printer->device_uri + 5,
-                                      O_WRONLY | O_EXCL);
-         else if (!strncmp(printer->device_uri, "file:///dev/", 12) &&
-                  strcmp(printer->device_uri, "file:///dev/null"))
-           job->print_pipes[1] = open(printer->device_uri + 7,
-                                      O_WRONLY | O_EXCL);
-         else
-           job->print_pipes[1] = open(printer->device_uri + 5,
-                                      O_WRONLY | O_CREAT | O_TRUNC, 0600);
+         cupsdLogMessage(CUPSD_LOG_EMERG,
+                         "Unable to allocate memory for %d files!",
+                         job->num_files);
+          break;
+       }
+      }
+    }
+    else if (!strcasecmp(line, "File"))
+    {
+      int      number,                 /* File number */
+               compression;            /* Compression value */
+      char     super[MIME_MAX_SUPER],  /* MIME super type */
+               type[MIME_MAX_TYPE];    /* MIME type */
 
-         if (job->print_pipes[1] < 0)
-         {
-            cupsdLogMessage(CUPSD_LOG_ERROR,
-                           "Unable to open output file \"%s\" - %s.",
-                           printer->device_uri, strerror(errno));
-            snprintf(printer->state_message, sizeof(printer->state_message),
-                    "Unable to open output file \"%s\" - %s.",
-                    printer->device_uri, strerror(errno));
 
-           cupsdAddPrinterHistory(printer);
+      if (sscanf(value, "%d%*[ \t]%15[^/]/%255s%d", &number, super, type,
+                 &compression) != 4)
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Bad File on line %d!", linenum);
+       continue;
+      }
 
-           cupsArrayDelete(filters);
+      if (number < 1 || number > job->num_files)
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Bad File number %d on line %d!",
+                       number, linenum);
+        continue;
+      }
 
-           cupsdClosePipe(statusfds);
-           cupsdClosePipe(filterfds[!slot]);
+      number --;
 
-           cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                         "Job canceled because the server could not open the "
-                         "output file.");
+      job->compressions[number] = compression;
+      job->filetypes[number]    = mimeType(MimeDatabase, super, type);
 
-            if (remote_job)
-           {
-             for (i = 0; i < job->num_files; i ++)
-               free(argv[i + 6]);
-           }
+      if (!job->filetypes[number])
+      {
+       /*
+        * If the original MIME type is unknown, auto-type it!
+       */
 
-           free(argv);
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unknown MIME type %s/%s for file %d of job %d!",
+                       super, type, number + 1, job->id);
 
-           cupsdCancelJob(job, 0);
-           return;
-         }
+        snprintf(jobfile, sizeof(jobfile), "%s/d%05d-%03d", RequestRoot,
+                job->id, number + 1);
+        job->filetypes[number] = mimeFileType(MimeDatabase, jobfile, NULL,
+                                             job->compressions + number);
 
-         fcntl(job->print_pipes[1], F_SETFD,
-               fcntl(job->print_pipes[1], F_GETFD) | FD_CLOEXEC);
-       }
+       /*
+        * If that didn't work, assume it is raw...
+       */
 
-       cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                       "cupsdStartJob: print_pipes = [ %d %d ]",
-                        job->print_pipes[0], job->print_pipes[1]);
+        if (!job->filetypes[number])
+         job->filetypes[number] = mimeType(MimeDatabase, "application",
+                                           "vnd.cups-raw");
       }
-
-      filterfds[slot][0] = job->print_pipes[0];
-      filterfds[slot][1] = job->print_pipes[1];
     }
+    else
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown %s directive on line %d!",
+                      line, linenum);
+  }
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartJob: filter=\"%s\"",
-                    command);
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStartJob: filterfds[%d]=[ %d %d ]",
-                    slot, filterfds[slot][0], filterfds[slot][1]);
+  cupsFileClose(fp);
+}
 
-    pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
-                            filterfds[slot][1], statusfds[1],
-                           job->back_pipes[0], 0, job->filters + i);
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStartJob: Closing filter pipes for slot %d "
-                   "[ %d %d ]...",
-                    !slot, filterfds[!slot][0], filterfds[!slot][1]);
+/*
+ * 'load_next_job_id()' - Load the NextJobId value from the job.cache file.
+ */
 
-    cupsdClosePipe(filterfds[!slot]);
+static void
+load_next_job_id(const char *filename) /* I - job.cache filename */
+{
+  cups_file_t  *fp;                    /* job.cache file */
+  char         line[1024],             /* Line buffer */
+               *value;                 /* Value on line */
+  int          linenum;                /* Line number in file */
 
-    if (pid == 0)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to start filter \"%s\" - %s.",
-                      filter->filter, strerror(errno));
-      snprintf(printer->state_message, sizeof(printer->state_message),
-               "Unable to start filter \"%s\" - %s.",
-               filter->filter, strerror(errno));
 
-      cupsdAddPrinterHistory(printer);
+ /*
+  * Read the NextJobId directive from the job.cache file and use
+  * the value (if any).
+  */
 
-      cupsArrayDelete(filters);
+  if ((fp = cupsFileOpen(filename, "r")) == NULL)
+  {
+    if (errno != ENOENT)
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to open job cache file \"%s\": %s",
+                      filename, strerror(errno));
 
-      cupsdAddPrinterHistory(printer);
+    return;
+  }
 
-      cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                    "Job canceled because the server could not execute a "
-                   "filter.");
+  cupsdLogMessage(CUPSD_LOG_INFO,
+                  "Loading NextJobId from job cache file \"%s\"...", filename);
 
-      if (remote_job)
-      {
-       for (i = 0; i < job->num_files; i ++)
-          free(argv[i + 6]);
-      }
+  linenum = 0;
 
-      free(argv);
+  while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
+  {
+    if (!strcasecmp(line, "NextJobId"))
+    {
+      if (value)
+        NextJobId = atoi(value);
 
-      cupsdCancelJob(job, 0);
-      return;
+      break;
     }
+  }
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "Started filter %s (PID %d) for job %d.",
-                    command, pid, job->id);
+  cupsFileClose(fp);
+}
 
-    argv[6] = NULL;
-    slot    = !slot;
-  }
 
-  cupsArrayDelete(filters);
+/*
+ * 'load_request_root()' - Load jobs from the RequestRoot directory.
+ */
+
+static void
+load_request_root(void)
+{
+  cups_dir_t           *dir;           /* Directory */
+  cups_dentry_t                *dent;          /* Directory entry */
+  cupsd_job_t          *job;           /* New job */
+
 
  /*
-  * Finally, pipe the final output into a backend process if needed...
+  * Open the requests directory...
   */
 
-  if (strncmp(printer->device_uri, "file:", 5) != 0)
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "Scanning %s for jobs...", RequestRoot);
+
+  if ((dir = cupsDirOpen(RequestRoot)) == NULL)
   {
-    if (job->current_file == 1)
-    {
-      sscanf(printer->device_uri, "%254[^:]", method);
-      snprintf(command, sizeof(command), "%s/backend/%s", ServerBin, method);
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "Unable to open spool directory \"%s\": %s",
+                    RequestRoot, strerror(errno));
+    return;
+  }
+
+ /*
+  * Read all the c##### files...
+  */
 
+  while ((dent = cupsDirRead(dir)) != NULL)
+    if (strlen(dent->filename) >= 6 && dent->filename[0] == 'c')
+    {
      /*
-      * See if the backend needs to run as root...
+      * Allocate memory for the job...
       */
 
-      if (RunUser)
-        backroot = 0;
-      else if (lstat(command, &backinfo))
-       backroot = 0;
-      else
-        backroot = !(backinfo.st_mode & (S_IRWXG | S_IRWXO));
-
-      argv[0] = sani_uri;
-
-      filterfds[slot][0] = -1;
-      filterfds[slot][1] = open("/dev/null", O_WRONLY);
-
-      if (filterfds[slot][1] < 0)
+      if ((job = calloc(sizeof(cupsd_job_t), 1)) == NULL)
       {
-       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"/dev/null\" - %s.",
-                       strerror(errno));
-       snprintf(printer->state_message, sizeof(printer->state_message),
-                "Unable to open \"/dev/null\" - %s.", strerror(errno));
-
-       cupsdAddPrinterHistory(printer);
-
-       cupsdClosePipe(statusfds);
-
-       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                      "Job canceled because the server could not open a file.");
-
-        if (remote_job)
-       {
-         for (i = 0; i < job->num_files; i ++)
-            free(argv[i + 6]);
-       }
-
-       free(argv);
-
-       cupsdCancelJob(job, 0);
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Ran out of memory for jobs!");
+       cupsDirClose(dir);
        return;
       }
 
-      fcntl(filterfds[slot][1], F_SETFD,
-            fcntl(filterfds[slot][1], F_GETFD) | FD_CLOEXEC);
-
-      cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartJob: backend=\"%s\"",
-                      command);
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdStartJob: filterfds[%d] = [ %d %d ]",
-                     slot, filterfds[slot][0], filterfds[slot][1]);
-
-      pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
-                             filterfds[slot][1], statusfds[1],
-                             job->back_pipes[1], backroot,
-                             &(job->backend));
-
-      if (pid == 0)
-      {
-       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to start backend \"%s\" - %s.",
-                        method, strerror(errno));
-       snprintf(printer->state_message, sizeof(printer->state_message),
-                "Unable to start backend \"%s\" - %s.", method,
-                strerror(errno));
-
-       cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                       "cupsdStartJob: Closing print pipes [ %d %d ]...",
-                       job->print_pipes[0], job->print_pipes[1]);
+     /*
+      * Assign the job ID...
+      */
 
-        cupsdClosePipe(job->print_pipes);
+      job->id             = atoi(dent->filename + 1);
+      job->back_pipes[0]  = -1;
+      job->back_pipes[1]  = -1;
+      job->print_pipes[0] = -1;
+      job->print_pipes[1] = -1;
 
-       cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                       "cupsdStartJob: Closing back pipes [ %d %d ]...",
-                       job->back_pipes[0], job->back_pipes[1]);
+      if (job->id >= NextJobId)
+        NextJobId = job->id + 1;
 
-        cupsdClosePipe(job->back_pipes);
+     /*
+      * Load the job...
+      */
 
-       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
-                      "Job canceled because the server could not execute "
-                     "the backend.");
+      cupsdLoadJob(job);
 
-        if (remote_job)
-       {
-         for (i = 0; i < job->num_files; i ++)
-            free(argv[i + 6]);
-       }
+     /*
+      * Insert the job into the array, sorting by job priority and ID...
+      */
 
-       free(argv);
+      cupsArrayAdd(Jobs, job);
 
-        cupsdCancelJob(job, 0);
-       return;
-      }
+      if (job->state_value < IPP_JOB_STOPPED)
+        cupsArrayAdd(ActiveJobs,job);
       else
-      {
-       cupsdLogMessage(CUPSD_LOG_INFO,
-                       "Started backend %s (PID %d) for job %d.",
-                       command, pid, job->id);
-      }
+        unload_job(job);
     }
 
-    if (job->current_file == job->num_files)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdStartJob: Closing print pipes [ %d %d ]...",
-                     job->print_pipes[0], job->print_pipes[1]);
-
-      cupsdClosePipe(job->print_pipes);
+  cupsDirClose(dir);
+}
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdStartJob: Closing back pipes [ %d %d ]...",
-                     job->back_pipes[0], job->back_pipes[1]);
 
-      cupsdClosePipe(job->back_pipes);
-    }
-  }
-  else
-  {
-    filterfds[slot][0] = -1;
-    filterfds[slot][1] = -1;
+/*
+ * 'set_time()' - Set one of the "time-at-xyz" attributes...
+ */
 
-    if (job->current_file == job->num_files)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdStartJob: Closing print pipes [ %d %d ]...",
-                     job->print_pipes[0], job->print_pipes[1]);
+static void
+set_time(cupsd_job_t *job,             /* I - Job to update */
+         const char  *name)            /* I - Name of attribute */
+{
+  ipp_attribute_t      *attr;          /* Time attribute */
 
-      cupsdClosePipe(job->print_pipes);
-    }
-  }
 
-  if (remote_job)
+  if ((attr = ippFindAttribute(job->attrs, name, IPP_TAG_ZERO)) != NULL)
   {
-    for (i = 0; i < job->num_files; i ++)
-      free(argv[i + 6]);
+    attr->value_tag         = IPP_TAG_INTEGER;
+    attr->values[0].integer = time(NULL);
   }
+}
 
-  free(argv);
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStartJob: Closing filter pipes for slot %d "
-                 "[ %d %d ]...",
-                  slot, filterfds[slot][0], filterfds[slot][1]);
 
-  cupsdClosePipe(filterfds[slot]);
+/*
+ * 'set_hold_until()' - Set the hold time and update job-hold-until attribute...
+ */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStartJob: Closing status output pipe %d...",
-                  statusfds[1]);
+static void 
+set_hold_until(cupsd_job_t *job,       /* I - Job to update */
+              time_t      holdtime)    /* I - Hold until time */
+{
+  ipp_attribute_t      *attr;          /* job-hold-until attribute */
+  struct tm            *holddate;      /* Hold date */
+  char                 holdstr[64];    /* Hold time */
 
-  close(statusfds[1]);
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStartJob: Adding fd %d to InputSet...",
-                  job->status_buffer->fd);
+ /*
+  * Set the hold_until value and hold the job...
+  */
 
-  FD_SET(job->status_buffer->fd, InputSet);
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "set_hold_until: hold_until = %d",
+                  (int)holdtime);
 
-  cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, "Job #%d started.",
-                job->id);
-}
+  job->state->values[0].integer = IPP_JOB_HELD;
+  job->state_value              = IPP_JOB_HELD;
+  job->hold_until               = holdtime;
 
+ /*
+  * Update the job-hold-until attribute with a string representing GMT
+  * time (HH:MM:SS)...
+  */
 
-/*
- * 'cupsdStopAllJobs()' - Stop all print jobs.
- */
+  holddate = gmtime(&holdtime);
+  snprintf(holdstr, sizeof(holdstr), "%d:%d:%d", holddate->tm_hour, 
+          holddate->tm_min, holddate->tm_sec);
 
-void
-cupsdStopAllJobs(void)
-{
-  cupsd_job_t  *job;                   /* Current job */
+  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+                               IPP_TAG_KEYWORD)) == NULL)
+    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
 
+ /*
+  * Either add the attribute or update the value of the existing one
+  */
 
-  DEBUG_puts("cupsdStopAllJobs()");
+  if (attr == NULL)
+    attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+                        "job-hold-until", NULL, holdstr);
+  else
+    cupsdSetString(&attr->values[0].string.text, holdstr);
 
-  for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
-       job;
-       job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
-    if (job->state_value == IPP_JOB_PROCESSING)
-    {
-      cupsdStopJob(job, 1);
-      job->state->values[0].integer = IPP_JOB_PENDING;
-      job->state_value              = IPP_JOB_PENDING;
-    }
+  cupsdSaveJob(job);
 }
 
 
 /*
- * 'cupsdStopJob()' - Stop a print job.
+ * 'start_job()' - Start a print job.
  */
 
-void
-cupsdStopJob(cupsd_job_t *job,         /* I - Job */
-             int         force)                /* I - 1 = Force all filters to stop */
+static void
+start_job(cupsd_job_t     *job,                /* I - Job ID */
+          cupsd_printer_t *printer)    /* I - Printer to print job */
 {
-  int  i;                              /* Looping var */
+  int                  i;              /* Looping var */
+  int                  slot;           /* Pipe slot */
+  cups_array_t         *filters;       /* Filters for job */
+  mime_filter_t                *filter,        /* Current filter */
+                       port_monitor;   /* Port monitor filter */
+  char                 method[255],    /* Method for output */
+                       *optptr,        /* Pointer to options */
+                       *valptr;        /* Pointer in value string */
+  ipp_attribute_t      *attr;          /* Current attribute */
+  struct stat          backinfo;       /* Backend file information */
+  int                  backroot;       /* Run backend as root? */
+  int                  pid;            /* Process ID of new filter process */
+  int                  banner_page;    /* 1 if banner page, 0 otherwise */
+  int                  statusfds[2],   /* Pipes used with the scheduler */
+                       filterfds[2][2];/* Pipes used between filters */
+  int                  envc;           /* Number of environment variables */
+  char                 **argv,         /* Filter command-line arguments */
+                       sani_uri[1024], /* Sanitized DEVICE_URI env var */
+                       filename[1024], /* Job filename */
+                       command[1024],  /* Full path to command */
+                       jobid[255],     /* Job ID string */
+                       title[IPP_MAX_NAME],
+                                       /* Job title string */
+                       copies[255],    /* # copies string */
+                       *envp[MAX_ENV + 11],
+                                       /* Environment variables */
+                       charset[255],   /* CHARSET env variable */
+                       class_name[255],/* CLASS env variable */
+                       classification[1024],
+                                       /* CLASSIFICATION env variable */
+                       content_type[1024],
+                                       /* CONTENT_TYPE env variable */
+                       device_uri[1024],
+                                       /* DEVICE_URI env variable */
+                       final_content_type[1024],
+                                       /* FINAL_CONTENT_TYPE env variable */
+                       lang[255],      /* LANG env variable */
+                       ppd[1024],      /* PPD env variable */
+                       printer_name[255],
+                                       /* PRINTER env variable */
+                       rip_max_cache[255];
+                                       /* RIP_MAX_CACHE env variable */
+  int                  remote_job;     /* Remote print job? */
+  static char          *options = NULL;/* Full list of options */
+  static int           optlength = 0;  /* Length of option buffer */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStopJob: id = %d, force = %d",
-                  job->id, force);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: id = %d, file = %d/%d",
+                  job->id, job->current_file, job->num_files);
 
-  if (job->state_value != IPP_JOB_PROCESSING)
+  if (job->num_files == 0)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Job ID %d has no files!  Cancelling it!",
+                    job->id);
+
+    cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                  "Job canceled because it has no files.");
+
+    cupsdCancelJob(job, 0);
     return;
+  }
 
-  FilterLevel -= job->cost;
+ /*
+  * Figure out what filters are required to convert from
+  * the source to the destination type...
+  */
 
-  if (job->status < 0 &&
-      !(job->dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)) &&
-      !(job->printer->type & CUPS_PRINTER_FAX) &&
-      !strcmp(job->printer->error_policy, "stop-printer"))
-    cupsdSetPrinterState(job->printer, IPP_PRINTER_STOPPED, 1);
-  else if (job->printer->state != IPP_PRINTER_STOPPED)
-    cupsdSetPrinterState(job->printer, IPP_PRINTER_IDLE, 0);
+  filters   = NULL;
+  job->cost = 0;
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStopJob: printer state is %d",
-                  job->printer->state);
+  if (printer->raw)
+  {
+   /*
+    * Remote jobs and raw queues go directly to the printer without
+    * filtering...
+    */
 
-  job->state->values[0].integer = IPP_JOB_STOPPED;
-  job->state_value              = IPP_JOB_STOPPED;
-  job->printer->job = NULL;
-  job->printer      = NULL;
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                    "[Job %d] Sending job to queue tagged as raw...", job->id);
 
-  job->current_file --;
+    filters = NULL;
+  }
+  else
+  {
+   /*
+    * Local jobs get filtered...
+    */
 
-  for (i = 0; job->filters[i]; i ++)
-    if (job->filters[i] > 0)
+    filters = mimeFilter(MimeDatabase, job->filetypes[job->current_file],
+                         printer->filetype, &(job->cost));
+
+    if (!filters)
     {
-      cupsdEndProcess(job->filters[i], force);
-      job->filters[i] = 0;
-    }
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to convert file %d to printable format for "
+                     "job %d!",
+                     job->current_file, job->id);
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "Hint: Do you have ESP Ghostscript installed?");
 
-  if (job->backend > 0)
-  {
-    cupsdEndProcess(job->backend, force);
-    job->backend = 0;
-  }
+      if (LogLevel < CUPSD_LOG_DEBUG)
+        cupsdLogMessage(CUPSD_LOG_INFO,
+                       "Hint: Try setting the LogLevel to \"debug\".");
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStopJob: Closing print pipes [ %d %d ]...",
-                  job->print_pipes[0], job->print_pipes[1]);
+      job->current_file ++;
 
-  cupsdClosePipe(job->print_pipes);
+      if (job->current_file == job->num_files)
+      {
+       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                      "Job canceled because it has no files that can be "
+                     "printed.");
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStopJob: Closing back pipes [ %d %d ]...",
-                  job->back_pipes[0], job->back_pipes[1]);
+        cupsdCancelJob(job, 0);
+      }
 
-  cupsdClosePipe(job->back_pipes);
+      return;
+    }
 
-  if (job->status_buffer)
-  {
    /*
-    * Close the pipe and clear the input bit.
+    * Remove NULL ("-") filters...
     */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStopJob: Removing fd %d from InputSet...",
-                   job->status_buffer->fd);
-
-    FD_CLR(job->status_buffer->fd, InputSet);
+    for (filter = (mime_filter_t *)cupsArrayFirst(filters);
+         filter;
+        filter = (mime_filter_t *)cupsArrayNext(filters))
+      if (!strcmp(filter->filter, "-"))
+        cupsArrayRemove(filters, filter);
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStopJob: Closing status input pipe %d...",
-                    job->status_buffer->fd);
+    if (cupsArrayCount(filters) == 0)
+    {
+      cupsArrayDelete(filters);
+      filters = NULL;
+    }
+  }
 
-    cupsdStatBufDelete(job->status_buffer);
+ /*
+  * Set a minimum cost of 100 for all jobs so that FilterLimit
+  * works with raw queues and other low-cost paths.
+  */
 
-    job->status_buffer = NULL;
-  }
-}
+  if (job->cost < 100)
+    job->cost = 100;
 
+ /*
+  * See if the filter cost is too high...
+  */
 
-/*
- * 'cupsdUnloadCompletedJobs()' - Flush completed job history from memory.
- */
+  if ((FilterLevel + job->cost) > FilterLimit && FilterLevel > 0 &&
+      FilterLimit > 0)
+  {
+   /*
+    * Don't print this job quite yet...
+    */
 
-void
-cupsdUnloadCompletedJobs(void)
-{
-  cupsd_job_t  *job;                   /* Current job */
-  time_t       expire;                 /* Expiration time */
+    cupsArrayDelete(filters);
 
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "Holding job %d because filter limit has been reached.",
+                    job->id);
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "start_job: id=%d, file=%d, cost=%d, level=%d, "
+                   "limit=%d",
+                    job->id, job->current_file, job->cost, FilterLevel,
+                   FilterLimit);
+    return;
+  }
 
-  expire = time(NULL) - 60;
+  FilterLevel += job->cost;
 
-  for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
-       job;
-       job = (cupsd_job_t *)cupsArrayNext(Jobs))
-    if (job->attrs && job->state_value >= IPP_JOB_STOPPED &&
-        job->access_time < expire)
-      cupsdUnloadJob(job);
-}
+ /*
+  * Determine if we are printing to a remote printer...
+  */
 
+  remote_job = printer->raw && job->num_files > 1 &&
+               !strncmp(printer->device_uri, "ipp://", 6);
 
-/*
* 'cupsdUnloadJob()' - Unload a job from memory.
- */
+ /*
 * Add decompression filters, if any...
 */
 
-void
-cupsdUnloadJob(cupsd_job_t *job)       /* I - Job */
-{
-  if (!job->attrs)
-    return;
+  if (!remote_job && job->compressions[job->current_file])
+  {
+   /*
+    * Add gziptoany filter to the front of the list...
+    */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "Unloading job %d...", job->id);
+    if (!cupsArrayInsert(filters, &gziptoany_filter))
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to add decompression filter - %s",
+                     strerror(errno));
 
-  ippDelete(job->attrs);
+      cupsArrayDelete(filters);
 
-  job->attrs      = NULL;
-  job->state      = NULL;
-  job->sheets     = NULL;
-  job->job_sheets = NULL;
-}
+      job->current_file ++;
 
+      if (job->current_file == job->num_files)
+      {
+       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                      "Job canceled because the print file could not be "
+                     "decompressed.");
 
-/*
- * 'cupsdUpdateJob()' - Read a status update from a job's filters.
- */
+        cupsdCancelJob(job, 0);
+      }
 
-void
-cupsdUpdateJob(cupsd_job_t *job)       /* I - Job to check */
-{
-  int          i;                      /* Looping var */
-  int          copies;                 /* Number of copies printed */
-  char         message[1024],          /* Message text */
-               *ptr;                   /* Pointer update... */
-  int          loglevel;               /* Log level for message */
+      return;
+    }
+  }
 
+ /*
+  * Add port monitor, if any...
+  */
 
-  while ((ptr = cupsdStatBufUpdate(job->status_buffer, &loglevel,
-                                   message, sizeof(message))) != NULL)
+  if (printer->port_monitor)
   {
    /*
-    * Process page and printer state messages as needed...
+    * Add port monitor to the end of the list...
     */
 
-    if (loglevel == CUPSD_LOG_PAGE)
+    if (!cupsArrayAdd(filters, &port_monitor))
     {
-     /*
-      * Page message; send the message to the page_log file and update the
-      * job sheet count...
-      */
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to add port monitor - %s",
+                      strerror(errno));
 
-      if (job->sheets != NULL)
-      {
-        if (!strncasecmp(message, "total ", 6))
-       {
-        /*
-         * Got a total count of pages from a backend or filter...
-         */
+      cupsArrayDelete(filters);
 
-         copies = atoi(message + 6);
-         copies -= job->sheets->values[0].integer; /* Just track the delta */
-       }
-       else if (!sscanf(message, "%*d%d", &copies))
-         copies = 1;
-         
-        job->sheets->values[0].integer += copies;
+      job->current_file ++;
 
-       if (job->printer->page_limit)
-         cupsdUpdateQuota(job->printer, job->username, copies, 0);
-      }
+      if (job->current_file == job->num_files)
+      {
+       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                      "Job canceled because the port monitor could not be "
+                     "added.");
 
-      cupsdLogPage(job, message);
+        cupsdCancelJob(job, 0);
+      }
 
-      cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, job->printer, job,
-                    "Printed %d page(s).", job->sheets->values[0].integer);
-    }
-    else if (loglevel == CUPSD_LOG_STATE)
-    {
-      cupsdSetPrinterReasons(job->printer, message);
-      cupsdAddPrinterHistory(job->printer);
+      return;
     }
-    else if (loglevel == CUPSD_LOG_ATTR)
-    {
-     /*
-      * Set attribute(s)...
-      */
 
-      /**** TODO ****/
-    }
-#ifdef __APPLE__
-    else if (!strncmp(message, "recoverable:", 12))
-    {
-      cupsdSetPrinterReasons(job->printer,
-                             "+com.apple.print.recoverable-warning");
+    snprintf(port_monitor.filter, sizeof(port_monitor.filter),
+             "%s/monitor/%s", ServerBin, printer->port_monitor);
+  }
 
-      ptr = message + 12;
-      while (isspace(*ptr & 255))
-        ptr ++;
-
-      cupsdSetString(&job->printer->recoverable, ptr);
-      cupsdAddPrinterHistory(job->printer);
-    }
-    else if (!strncmp(message, "recovered:", 10))
-    {
-      cupsdSetPrinterReasons(job->printer,
-                             "-com.apple.print.recoverable-warning");
-
-      ptr = message + 10;
-      while (isspace(*ptr & 255))
-        ptr ++;
-
-      cupsdSetString(&job->printer->recoverable, ptr);
-      cupsdAddPrinterHistory(job->printer);
-    }
-#endif /* __APPLE__ */
-    else if (loglevel <= CUPSD_LOG_INFO)
-    {
-     /*
-      * Some message to show in the printer-state-message attribute...
-      */
-
-      strlcpy(job->printer->state_message, message,
-              sizeof(job->printer->state_message));
-      cupsdAddPrinterHistory(job->printer);
-    }
+ /*
+  * Update the printer and job state to "processing"...
+  */
 
-    if (!strchr(job->status_buffer->buffer, '\n'))
-      break;
-  }
+  job->state->values[0].integer = IPP_JOB_PROCESSING;
+  job->state_value              = IPP_JOB_PROCESSING;
+  job->status  = 0;
+  job->printer = printer;
+  printer->job = job;
+  cupsdSetPrinterState(printer, IPP_PRINTER_PROCESSING, 0);
 
-  if (ptr == NULL)
+  if (job->current_file == 0)
   {
-   /*
-    * See if all of the filters and the backend have returned their
-    * exit statuses.
-    */
+    set_time(job, "time-at-processing");
+    cupsdOpenPipe(job->back_pipes);
+  }
 
-    for (i = 0; job->filters[i] < 0; i ++);
+ /*
+  * Determine if we are printing a banner page or not...
+  */
 
-    if (job->filters[i])
-      return;
+  if (job->job_sheets == NULL)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "No job-sheets attribute.");
+    if ((job->job_sheets =
+         ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) != NULL)
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                      "... but someone added one without setting job_sheets!");
+  }
+  else if (job->job_sheets->num_values == 1)
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "job-sheets=%s",
+               job->job_sheets->values[0].string.text);
+  else
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "job-sheets=%s,%s",
+               job->job_sheets->values[0].string.text,
+               job->job_sheets->values[1].string.text);
 
-    if (job->current_file >= job->num_files && job->backend > 0)
-      return;
+  if (printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
+    banner_page = 0;
+  else if (job->job_sheets == NULL)
+    banner_page = 0;
+  else if (strcasecmp(job->job_sheets->values[0].string.text, "none") != 0 &&
+          job->current_file == 0)
+    banner_page = 1;
+  else if (job->job_sheets->num_values > 1 &&
+          strcasecmp(job->job_sheets->values[1].string.text, "none") != 0 &&
+          job->current_file == (job->num_files - 1))
+    banner_page = 1;
+  else
+    banner_page = 0;
 
-   /*
-    * Handle the end of job stuff...
-    */
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "banner_page = %d", banner_page);
 
-    cupsdFinishJob(job);
-  }
-}
+ /*
+  * Building the options string is harder than it needs to be, but
+  * for the moment we need to pass strings for command-line args and
+  * not IPP attribute pointers... :)
+  *
+  * First allocate/reallocate the option buffer as needed...
+  */
 
+  i = ipp_length(job->attrs);
 
-/*
- * 'compare_active_jobs()' - Compare the job IDs and priorities of two jobs.
- */
+  if (i > optlength)
+  {
+    if (optlength == 0)
+      optptr = malloc(i);
+    else
+      optptr = realloc(options, i);
 
-static int                             /* O - Difference */
-compare_active_jobs(void *first,       /* I - First job */
-                    void *second,      /* I - Second job */
-                   void *data)         /* I - App data (not used) */
-{
-  int  diff;                           /* Difference */
+    if (optptr == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_CRIT,
+                      "Unable to allocate %d bytes for option buffer for "
+                     "job %d!", i, job->id);
 
+      cupsArrayDelete(filters);
 
-  if ((diff = ((cupsd_job_t *)first)->priority -
-              ((cupsd_job_t *)second)->priority) != 0)
-    return (diff);
-  else
-    return (((cupsd_job_t *)first)->id - ((cupsd_job_t *)second)->id);
-}
+      FilterLevel -= job->cost;
 
+      cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                    "Job canceled because the server ran out of memory.");
 
-/*
- * 'compare_jobs()' - Compare the job IDs of two jobs.
- */
+      cupsdCancelJob(job, 0);
+      return;
+    }
 
-static int                             /* O - Difference */
-compare_jobs(void *first,              /* I - First job */
-             void *second,             /* I - Second job */
-            void *data)                /* I - App data (not used) */
-{
-  return (((cupsd_job_t *)first)->id - ((cupsd_job_t *)second)->id);
-}
+    options   = optptr;
+    optlength = i;
+  }
 
+ /*
+  * Now loop through the attributes and convert them to the textual
+  * representation used by the filters...
+  */
 
-/*
- * 'free_job()' - Free all memory used by a job.
- */
+  optptr  = options;
+  *optptr = '\0';
 
-static void
-free_job(cupsd_job_t *job)             /* I - Job */
-{
-  cupsdClearString(&job->username);
-  cupsdClearString(&job->dest);
+  snprintf(title, sizeof(title), "%s-%d", printer->name, job->id);
+  strcpy(copies, "1");
 
-  if (job->num_files > 0)
+  for (attr = job->attrs->attrs; attr != NULL; attr = attr->next)
   {
-    free(job->compressions);
-    free(job->filetypes);
-  }
+    if (!strcmp(attr->name, "copies") &&
+       attr->value_tag == IPP_TAG_INTEGER)
+    {
+     /*
+      * Don't use the # copies attribute if we are printing the job sheets...
+      */
 
-  ippDelete(job->attrs);
+      if (!banner_page)
+        sprintf(copies, "%d", attr->values[0].integer);
+    }
+    else if (!strcmp(attr->name, "job-name") &&
+            (attr->value_tag == IPP_TAG_NAME ||
+             attr->value_tag == IPP_TAG_NAMELANG))
+      strlcpy(title, attr->values[0].string.text, sizeof(title));
+    else if (attr->group_tag == IPP_TAG_JOB)
+    {
+     /*
+      * Filter out other unwanted attributes...
+      */
 
-  free(job);
-}
+      if (attr->value_tag == IPP_TAG_MIMETYPE ||
+         attr->value_tag == IPP_TAG_NAMELANG ||
+         attr->value_tag == IPP_TAG_TEXTLANG ||
+         (attr->value_tag == IPP_TAG_URI && strcmp(attr->name, "job-uuid")) ||
+         attr->value_tag == IPP_TAG_URISCHEME ||
+         attr->value_tag == IPP_TAG_BEGIN_COLLECTION) /* Not yet supported */
+       continue;
 
+      if (!strncmp(attr->name, "time-", 5))
+       continue;
 
-/*
- * 'ipp_length()' - Compute the size of the buffer needed to hold 
- *                 the textual IPP attributes.
- */
+      if (!strncmp(attr->name, "job-", 4) && strcmp(attr->name, "job-uuid") &&
+          !(printer->type & CUPS_PRINTER_REMOTE))
+       continue;
 
-static int                             /* O - Size of attribute buffer */
-ipp_length(ipp_t *ipp)                 /* I - IPP request */
-{
-  int                  bytes;          /* Number of bytes */
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *attr;          /* Current attribute */
+      if (!strncmp(attr->name, "job-", 4) &&
+          strcmp(attr->name, "job-uuid") &&
+          strcmp(attr->name, "job-billing") &&
+          strcmp(attr->name, "job-sheets") &&
+          strcmp(attr->name, "job-hold-until") &&
+         strcmp(attr->name, "job-priority"))
+       continue;
 
+      if ((!strcmp(attr->name, "page-label") ||
+           !strcmp(attr->name, "page-border") ||
+           !strncmp(attr->name, "number-up", 9) ||
+          !strcmp(attr->name, "page-set") ||
+          !strcasecmp(attr->name, "AP_FIRSTPAGE_InputSlot") ||
+          !strcasecmp(attr->name, "AP_FIRSTPAGE_ManualFeed")) &&
+         banner_page)
+        continue;
 
- /*
-  * Loop through all attributes...
-  */
    /*
+      * Otherwise add them to the list...
+      */
 
-  bytes = 0;
+      if (optptr > options)
+       strlcat(optptr, " ", optlength - (optptr - options));
 
-  for (attr = ipp->attrs; attr != NULL; attr = attr->next)
-  {
-   /*
-    * Skip attributes that won't be sent to filters...
-    */
+      if (attr->value_tag != IPP_TAG_BOOLEAN)
+      {
+       strlcat(optptr, attr->name, optlength - (optptr - options));
+       strlcat(optptr, "=", optlength - (optptr - options));
+      }
 
-    if (attr->value_tag == IPP_TAG_MIMETYPE ||
-       attr->value_tag == IPP_TAG_NAMELANG ||
-       attr->value_tag == IPP_TAG_TEXTLANG ||
-       attr->value_tag == IPP_TAG_URI ||
-       attr->value_tag == IPP_TAG_URISCHEME)
-      continue;
+      for (i = 0; i < attr->num_values; i ++)
+      {
+       if (i)
+         strlcat(optptr, ",", optlength - (optptr - options));
 
-    if (strncmp(attr->name, "time-", 5) == 0)
-      continue;
+       optptr += strlen(optptr);
 
-   /*
-    * Add space for a leading space and commas between each value.
-    * For the first attribute, the leading space isn't used, so the
-    * extra byte can be used as the nul terminator...
-    */
+       switch (attr->value_tag)
+       {
+         case IPP_TAG_INTEGER :
+         case IPP_TAG_ENUM :
+             snprintf(optptr, optlength - (optptr - options),
+                      "%d", attr->values[i].integer);
+             break;
 
-    bytes ++;                          /* " " separator */
-    bytes += attr->num_values;         /* "," separators */
+         case IPP_TAG_BOOLEAN :
+             if (!attr->values[i].boolean)
+               strlcat(optptr, "no", optlength - (optptr - options));
 
-   /*
-    * Boolean attributes appear as "foo,nofoo,foo,nofoo", while
-    * other attributes appear as "foo=value1,value2,...,valueN".
-    */
+         case IPP_TAG_NOVALUE :
+             strlcat(optptr, attr->name,
+                     optlength - (optptr - options));
+             break;
 
-    if (attr->value_tag != IPP_TAG_BOOLEAN)
-      bytes += strlen(attr->name);
-    else
-      bytes += attr->num_values * strlen(attr->name);
+         case IPP_TAG_RANGE :
+             if (attr->values[i].range.lower == attr->values[i].range.upper)
+               snprintf(optptr, optlength - (optptr - options) - 1,
+                        "%d", attr->values[i].range.lower);
+              else
+               snprintf(optptr, optlength - (optptr - options) - 1,
+                        "%d-%d", attr->values[i].range.lower,
+                        attr->values[i].range.upper);
+             break;
 
-   /*
-    * Now add the size required for each value in the attribute...
-    */
+         case IPP_TAG_RESOLUTION :
+             snprintf(optptr, optlength - (optptr - options) - 1,
+                      "%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;
 
-    switch (attr->value_tag)
+          case IPP_TAG_STRING :
+         case IPP_TAG_TEXT :
+         case IPP_TAG_NAME :
+         case IPP_TAG_KEYWORD :
+         case IPP_TAG_CHARSET :
+         case IPP_TAG_LANGUAGE :
+         case IPP_TAG_URI :
+             for (valptr = attr->values[i].string.text; *valptr;)
+             {
+               if (strchr(" \t\n\\\'\"", *valptr))
+                 *optptr++ = '\\';
+               *optptr++ = *valptr++;
+             }
+
+             *optptr = '\0';
+             break;
+
+          default :
+             break; /* anti-compiler-warning-code */
+       }
+      }
+
+      optptr += strlen(optptr);
+    }
+  }
+
+ /*
+  * Build the command-line arguments for the filters.  Each filter
+  * has 6 or 7 arguments:
+  *
+  *     argv[0] = printer
+  *     argv[1] = job ID
+  *     argv[2] = username
+  *     argv[3] = title
+  *     argv[4] = # copies
+  *     argv[5] = options
+  *     argv[6] = filename (optional; normally stdin)
+  *
+  * This allows legacy printer drivers that use the old System V
+  * printing interface to be used by CUPS.
+  *
+  * For remote jobs, we send all of the files in the argument list.
+  */
+
+  if (remote_job)
+    argv = calloc(7 + job->num_files, sizeof(char *));
+  else
+    argv = calloc(8, sizeof(char *));
+
+  sprintf(jobid, "%d", job->id);
+
+  argv[0] = printer->name;
+  argv[1] = jobid;
+  argv[2] = job->username;
+  argv[3] = title;
+  argv[4] = copies;
+  argv[5] = options;
+
+  if (remote_job)
+  {
+    for (i = 0; i < job->num_files; i ++)
     {
-      case IPP_TAG_INTEGER :
-      case IPP_TAG_ENUM :
-         /*
-         * Minimum value of a signed integer is -2147483647, or 11 digits.
-         */
+      snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
+               job->id, i + 1);
+      argv[6 + i] = strdup(filename);
+    }
+  }
+  else
+  {
+    snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
+             job->id, job->current_file + 1);
+    argv[6] = filename;
+  }
 
-         bytes += attr->num_values * 11;
-         break;
+  for (i = 0; argv[i]; i ++)
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                    "[Job %d] argv[%d]=\"%s\"", job->id, i, argv[i]);
 
-      case IPP_TAG_BOOLEAN :
-         /*
-         * Add two bytes for each false ("no") value...
-         */
+ /*
+  * Create environment variable strings for the filters...
+  */
 
-          for (i = 0; i < attr->num_values; i ++)
-           if (!attr->values[i].boolean)
-             bytes += 2;
-         break;
+  attr = ippFindAttribute(job->attrs, "attributes-natural-language",
+                          IPP_TAG_LANGUAGE);
 
-      case IPP_TAG_RANGE :
-         /*
-         * A range is two signed integers separated by a hyphen, or
-         * 23 characters max.
-         */
+  switch (strlen(attr->values[0].string.text))
+  {
+    default :
+       /*
+        * This is an unknown or badly formatted language code; use
+       * the POSIX locale...
+       */
 
-         bytes += attr->num_values * 23;
-         break;
+       strcpy(lang, "LANG=C");
+       break;
 
-      case IPP_TAG_RESOLUTION :
-         /*
-         * A resolution is two signed integers separated by an "x" and
-         * suffixed by the units, or 26 characters max.
-         */
+    case 2 :
+       /*
+        * Just the language code (ll)...
+       */
 
-         bytes += attr->num_values * 26;
-         break;
+        snprintf(lang, sizeof(lang), "LANG=%s",
+                attr->values[0].string.text);
+        break;
 
-      case IPP_TAG_STRING :
-      case IPP_TAG_TEXT :
-      case IPP_TAG_NAME :
-      case IPP_TAG_KEYWORD :
-      case IPP_TAG_CHARSET :
-      case IPP_TAG_LANGUAGE :
-      case IPP_TAG_URI :
-         /*
-         * Strings can contain characters that need quoting.  We need
-         * at least 2 * len + 2 characters to cover the quotes and
-         * any backslashes in the string.
-         */
+    case 5 :
+       /*
+        * Language and country code (ll-cc)...
+       */
 
-          for (i = 0; i < attr->num_values; i ++)
-           bytes += 2 * strlen(attr->values[i].string.text) + 2;
-         break;
+        snprintf(lang, sizeof(lang), "LANG=%c%c_%c%c",
+                attr->values[0].string.text[0],
+                attr->values[0].string.text[1],
+                toupper(attr->values[0].string.text[3] & 255),
+                toupper(attr->values[0].string.text[4] & 255));
+        break;
+  }
 
-       default :
-         break; /* anti-compiler-warning-code */
-    }
+  attr = ippFindAttribute(job->attrs, "document-format",
+                          IPP_TAG_MIMETYPE);
+  if (attr != NULL &&
+      (optptr = strstr(attr->values[0].string.text, "charset=")) != NULL)
+    snprintf(charset, sizeof(charset), "CHARSET=%s", optptr + 8);
+  else
+  {
+    attr = ippFindAttribute(job->attrs, "attributes-charset",
+                           IPP_TAG_CHARSET);
+    snprintf(charset, sizeof(charset), "CHARSET=%s",
+             attr->values[0].string.text);
   }
 
-  return (bytes);
-}
+  snprintf(content_type, sizeof(content_type), "CONTENT_TYPE=%s/%s",
+           job->filetypes[job->current_file]->super,
+           job->filetypes[job->current_file]->type);
+  snprintf(device_uri, sizeof(device_uri), "DEVICE_URI=%s",
+           printer->device_uri);
+  cupsdSanitizeURI(printer->device_uri, sani_uri, sizeof(sani_uri));
+  snprintf(ppd, sizeof(ppd), "PPD=%s/ppd/%s.ppd", ServerRoot, printer->name);
+  snprintf(printer_name, sizeof(printer_name), "PRINTER=%s", printer->name);
+  snprintf(rip_max_cache, sizeof(rip_max_cache), "RIP_MAX_CACHE=%s", RIPCache);
 
+  envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
 
-/*
- * 'load_job_cache()' - Load jobs from the job.cache file.
- */
+  envp[envc ++] = charset;
+  envp[envc ++] = lang;
+  envp[envc ++] = ppd;
+  envp[envc ++] = rip_max_cache;
+  envp[envc ++] = content_type;
+  envp[envc ++] = device_uri;
+  envp[envc ++] = printer_name;
 
-static void
-load_job_cache(const char *filename)   /* I - job.cache filename */
-{
-  cups_file_t  *fp;                    /* job.cache file */
-  char         line[1024],             /* Line buffer */
-               *value;                 /* Value on line */
-  int          linenum;                /* Line number in file */
-  cupsd_job_t  *job;                   /* Current job */
-  int          jobid;                  /* Job ID */
-  char         jobfile[1024];          /* Job filename */
+  if ((filter = (mime_filter_t *)cupsArrayLast(filters)) != NULL)
+  {
+    snprintf(final_content_type, sizeof(final_content_type),
+             "FINAL_CONTENT_TYPE=%s/%s",
+            filter->dst->super, filter->dst->type);
+    envp[envc ++] = final_content_type;
+  }
 
+  if (Classification && !banner_page)
+  {
+    if ((attr = ippFindAttribute(job->attrs, "job-sheets",
+                                 IPP_TAG_NAME)) == NULL)
+      snprintf(classification, sizeof(classification), "CLASSIFICATION=%s",
+               Classification);
+    else if (attr->num_values > 1 &&
+             strcmp(attr->values[1].string.text, "none") != 0)
+      snprintf(classification, sizeof(classification), "CLASSIFICATION=%s",
+               attr->values[1].string.text);
+    else
+      snprintf(classification, sizeof(classification), "CLASSIFICATION=%s",
+               attr->values[0].string.text);
 
- /*
-  * Open the job.cache file...
-  */
+    envp[envc ++] = classification;
+  }
 
-  if ((fp = cupsFileOpen(filename, "r")) == NULL)
+  if (job->dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
   {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to open job cache file \"%s\": %s",
-                      filename, strerror(errno));
+    snprintf(class_name, sizeof(class_name), "CLASS=%s", job->dest);
+    envp[envc ++] = class_name;
+  }
 
-    load_request_root();
+  envp[envc] = NULL;
 
-    return;
-  }
+  for (i = 0; i < envc; i ++)
+    if (strncmp(envp[i], "DEVICE_URI=", 11))
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] envp[%d]=\"%s\"",
+                      job->id, i, envp[i]);
+    else
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] envp[%d]=\"DEVICE_URI=%s\"",
+                      job->id, i, sani_uri);
+
+  if (remote_job)
+    job->current_file = job->num_files;
+  else
+    job->current_file ++;
 
  /*
-  * Read entries from the job cache file and create jobs as needed.
+  * Now create processes for all of the filters...
   */
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Loading job cache file \"%s\"...",
-                  filename);
-
-  linenum = 0;
-  job     = NULL;
+  filterfds[0][0] = -1;
+  filterfds[0][1] = -1;
+  filterfds[1][0] = -1;
+  filterfds[1][1] = -1;
 
-  while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
+  if (cupsdOpenPipe(statusfds))
   {
-    if (!strcasecmp(line, "NextJobId"))
-    {
-      if (value)
-        NextJobId = atoi(value);
-    }
-    else if (!strcasecmp(line, "<Job"))
-    {
-      if (job)
-      {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Missing </Job> directive on line %d!",
-                       linenum);
-        continue;
-      }
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create job status pipes - %s.",
+                   strerror(errno));
+    snprintf(printer->state_message, sizeof(printer->state_message),
+             "Unable to create status pipes - %s.", strerror(errno));
 
-      if (!value)
-      {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Missing job ID on line %d!", linenum);
-       continue;
-      }
+    cupsdAddPrinterHistory(printer);
 
-      jobid = atoi(value);
+    cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                  "Job canceled because the server could not create the job "
+                 "status pipes.");
 
-      if (jobid < 1)
-      {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Bad job ID %d on line %d!", jobid,
-                       linenum);
-        continue;
-      }
+    goto abort_job;
+  }
 
-      snprintf(jobfile, sizeof(jobfile), "%s/c%05d", RequestRoot, jobid);
-      if (access(jobfile, 0))
-      {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Job %d files have gone away!", jobid);
-        continue;
-      }
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: statusfds = [ %d %d ]",
+                  statusfds[0], statusfds[1]);
 
-      job = calloc(1, sizeof(cupsd_job_t));
-      if (!job)
-      {
-        cupsdLogMessage(CUPSD_LOG_EMERG,
-                       "Unable to allocate memory for job %d!", jobid);
-        break;
-      }
+#ifdef FD_CLOEXEC
+  fcntl(statusfds[0], F_SETFD, FD_CLOEXEC);
+  fcntl(statusfds[1], F_SETFD, FD_CLOEXEC);
+#endif /* FD_CLOEXEC */
+
+  job->status_buffer = cupsdStatBufNew(statusfds[0], "[Job %d]",
+                                           job->id);
+  job->status        = 0;
+  memset(job->filters, 0, sizeof(job->filters));
 
-      job->id             = jobid;
-      job->back_pipes[0]  = -1;
-      job->back_pipes[1]  = -1;
-      job->print_pipes[0] = -1;
-      job->print_pipes[1] = -1;
+  filterfds[1][0] = open("/dev/null", O_RDONLY);
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading job %d from cache...", job->id);
-    }
-    else if (!job)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                     "Missing <Job #> directive on line %d!", linenum);
-      continue;
-    }
-    else if (!strcasecmp(line, "</Job>"))
-    {
-      cupsArrayAdd(Jobs, job);
+  if (filterfds[1][0] < 0)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"/dev/null\" - %s.",
+                    strerror(errno));
+    snprintf(printer->state_message, sizeof(printer->state_message),
+             "Unable to open \"/dev/null\" - %s.", strerror(errno));
 
-      if (job->state_value < IPP_JOB_STOPPED)
-      {
-        cupsArrayAdd(ActiveJobs, job);
-       cupsdLoadJob(job);
-      }
+    cupsdAddPrinterHistory(printer);
 
-      job = NULL;
-    }
-    else if (!value)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d!", linenum);
-      continue;
-    }
-    else if (!strcasecmp(line, "State"))
-    {
-      job->state_value = atoi(value);
+    cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                  "Job canceled because the server could not open /dev/null.");
 
-      if (job->state_value < IPP_JOB_PENDING)
-        job->state_value = IPP_JOB_PENDING;
-      else if (job->state_value > IPP_JOB_COMPLETED)
-        job->state_value = IPP_JOB_COMPLETED;
-    }
-    else if (!strcasecmp(line, "Priority"))
-    {
-      job->priority = atoi(value);
-    }
-    else if (!strcasecmp(line, "Username"))
-    {
-      cupsdSetString(&job->username, value);
-    }
-    else if (!strcasecmp(line, "Destination"))
-    {
-      cupsdSetString(&job->dest, value);
-    }
-    else if (!strcasecmp(line, "DestType"))
-    {
-      job->dtype = (cups_ptype_t)atoi(value);
-    }
-    else if (!strcasecmp(line, "NumFiles"))
-    {
-      job->num_files = atoi(value);
+    goto abort_job;
+  }
 
-      if (job->num_files < 0)
-      {
-       cupsdLogMessage(CUPSD_LOG_ERROR, "Bad NumFiles value %d on line %d!",
-                       job->num_files, linenum);
-        job->num_files = 0;
-       continue;
-      }
+  fcntl(filterfds[1][0], F_SETFD, fcntl(filterfds[1][0], F_GETFD) | FD_CLOEXEC);
 
-      if (job->num_files > 0)
-      {
-        snprintf(jobfile, sizeof(jobfile), "%s/d%05d-001", RequestRoot,
-                job->id);
-        if (access(jobfile, 0))
-       {
-         cupsdLogMessage(CUPSD_LOG_INFO,
-                         "Data files for job %d have gone away!", job->id);
-          job->num_files = 0;
-         continue;
-       }
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: filterfds[%d] = [ %d %d ]",
+                  1, filterfds[1][0], filterfds[1][1]);
 
-        job->filetypes    = calloc(job->num_files, sizeof(mime_type_t *));
-       job->compressions = calloc(job->num_files, sizeof(int));
+  for (i = 0, slot = 0, filter = (mime_filter_t *)cupsArrayFirst(filters);
+       filter;
+       i ++, filter = (mime_filter_t *)cupsArrayNext(filters))
+  {
+    if (filter->filter[0] != '/')
+      snprintf(command, sizeof(command), "%s/filter/%s", ServerBin,
+               filter->filter);
+    else
+      strlcpy(command, filter->filter, sizeof(command));
 
-        if (!job->filetypes || !job->compressions)
-       {
-         cupsdLogMessage(CUPSD_LOG_EMERG,
-                         "Unable to allocate memory for %d files!",
-                         job->num_files);
-          break;
-       }
-      }
-    }
-    else if (!strcasecmp(line, "File"))
+    if (i < (cupsArrayCount(filters) - 1))
     {
-      int      number,                 /* File number */
-               compression;            /* Compression value */
-      char     super[MIME_MAX_SUPER],  /* MIME super type */
-               type[MIME_MAX_TYPE];    /* MIME type */
+      if (cupsdOpenPipe(filterfds[slot]))
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to create job filter pipes - %s.",
+                       strerror(errno));
+       snprintf(printer->state_message, sizeof(printer->state_message),
+               "Unable to create filter pipes - %s.", strerror(errno));
+       cupsdAddPrinterHistory(printer);
 
+       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                      "Job canceled because the server could not create the "
+                     "filter pipes.");
 
-      if (sscanf(value, "%d%*[ \t]%15[^/]/%255s%d", &number, super, type,
-                 &compression) != 4)
-      {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Bad File on line %d!", linenum);
-       continue;
+        goto abort_job;
       }
-
-      if (number < 1 || number > job->num_files)
+    }
+    else
+    {
+      if (job->current_file == 1)
       {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Bad File number %d on line %d!",
-                       number, linenum);
-        continue;
-      }
+       if (strncmp(printer->device_uri, "file:", 5) != 0)
+       {
+         if (cupsdOpenPipe(job->print_pipes))
+         {
+           cupsdLogMessage(CUPSD_LOG_ERROR,
+                           "Unable to create job backend pipes - %s.",
+                           strerror(errno));
+           snprintf(printer->state_message, sizeof(printer->state_message),
+                   "Unable to create backend pipes - %s.", strerror(errno));
+           cupsdAddPrinterHistory(printer);
 
-      number --;
+           cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                         "Job canceled because the server could not create "
+                         "the backend pipes.");
 
-      job->compressions[number] = compression;
-      job->filetypes[number]    = mimeType(MimeDatabase, super, type);
+            goto abort_job;
+         }
+       }
+       else
+       {
+         job->print_pipes[0] = -1;
+         if (!strncmp(printer->device_uri, "file:/dev/", 10) &&
+             strcmp(printer->device_uri, "file:/dev/null"))
+           job->print_pipes[1] = open(printer->device_uri + 5,
+                                      O_WRONLY | O_EXCL);
+         else if (!strncmp(printer->device_uri, "file:///dev/", 12) &&
+                  strcmp(printer->device_uri, "file:///dev/null"))
+           job->print_pipes[1] = open(printer->device_uri + 7,
+                                      O_WRONLY | O_EXCL);
+         else
+           job->print_pipes[1] = open(printer->device_uri + 5,
+                                      O_WRONLY | O_CREAT | O_TRUNC, 0600);
 
-      if (!job->filetypes[number])
-      {
-       /*
-        * If the original MIME type is unknown, auto-type it!
-       */
+         if (job->print_pipes[1] < 0)
+         {
+            cupsdLogMessage(CUPSD_LOG_ERROR,
+                           "Unable to open output file \"%s\" - %s.",
+                           printer->device_uri, strerror(errno));
+            snprintf(printer->state_message, sizeof(printer->state_message),
+                    "Unable to open output file \"%s\" - %s.",
+                    printer->device_uri, strerror(errno));
 
-        cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unknown MIME type %s/%s for file %d of job %d!",
-                       super, type, number + 1, job->id);
+           cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                         "Job canceled because the server could not open the "
+                         "output file.");
 
-        snprintf(jobfile, sizeof(jobfile), "%s/d%05d-%03d", RequestRoot,
-                job->id, number + 1);
-        job->filetypes[number] = mimeFileType(MimeDatabase, jobfile, NULL,
-                                             job->compressions + number);
+            goto abort_job;
+         }
 
-       /*
-        * If that didn't work, assume it is raw...
-       */
+         fcntl(job->print_pipes[1], F_SETFD,
+               fcntl(job->print_pipes[1], F_GETFD) | FD_CLOEXEC);
+       }
 
-        if (!job->filetypes[number])
-         job->filetypes[number] = mimeType(MimeDatabase, "application",
-                                           "vnd.cups-raw");
+       cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                       "start_job: print_pipes = [ %d %d ]",
+                        job->print_pipes[0], job->print_pipes[1]);
       }
+
+      filterfds[slot][0] = job->print_pipes[0];
+      filterfds[slot][1] = job->print_pipes[1];
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown %s directive on line %d!",
-                      line, linenum);
-  }
 
-  cupsFileClose(fp);
-}
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: filter=\"%s\"",
+                    command);
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "start_job: filterfds[%d]=[ %d %d ]",
+                    slot, filterfds[slot][0], filterfds[slot][1]);
 
+    pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
+                            filterfds[slot][1], statusfds[1],
+                           job->back_pipes[0], 0, job->filters + i);
 
-/*
- * 'load_next_job_id()' - Load the NextJobId value from the job.cache file.
- */
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "start_job: Closing filter pipes for slot %d "
+                   "[ %d %d ]...",
+                    !slot, filterfds[!slot][0], filterfds[!slot][1]);
 
-static void
-load_next_job_id(const char *filename) /* I - job.cache filename */
-{
-  cups_file_t  *fp;                    /* job.cache file */
-  char         line[1024],             /* Line buffer */
-               *value;                 /* Value on line */
-  int          linenum;                /* Line number in file */
+    cupsdClosePipe(filterfds[!slot]);
 
+    if (pid == 0)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to start filter \"%s\" - %s.",
+                      filter->filter, strerror(errno));
+      snprintf(printer->state_message, sizeof(printer->state_message),
+               "Unable to start filter \"%s\" - %s.",
+               filter->filter, strerror(errno));
 
- /*
-  * Read the NextJobId directive from the job.cache file and use
-  * the value (if any).
-  */
+      cupsdAddPrinterHistory(printer);
 
-  if ((fp = cupsFileOpen(filename, "r")) == NULL)
-  {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to open job cache file \"%s\": %s",
-                      filename, strerror(errno));
+      cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                    "Job canceled because the server could not execute a "
+                   "filter.");
 
-    return;
+      goto abort_job;
+    }
+
+    cupsdLogMessage(CUPSD_LOG_INFO, "Started filter %s (PID %d) for job %d.",
+                    command, pid, job->id);
+
+    argv[6] = NULL;
+    slot    = !slot;
   }
 
-  cupsdLogMessage(CUPSD_LOG_INFO,
-                  "Loading NextJobId from job cache file \"%s\"...", filename);
+  cupsArrayDelete(filters);
 
-  linenum = 0;
+ /*
+  * Finally, pipe the final output into a backend process if needed...
+  */
 
-  while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
+  if (strncmp(printer->device_uri, "file:", 5) != 0)
   {
-    if (!strcasecmp(line, "NextJobId"))
+    if (job->current_file == 1)
     {
-      if (value)
-        NextJobId = atoi(value);
+      sscanf(printer->device_uri, "%254[^:]", method);
+      snprintf(command, sizeof(command), "%s/backend/%s", ServerBin, method);
 
-      break;
-    }
-  }
+     /*
+      * See if the backend needs to run as root...
+      */
 
-  cupsFileClose(fp);
-}
+      if (RunUser)
+        backroot = 0;
+      else if (stat(command, &backinfo))
+       backroot = 0;
+      else
+        backroot = !(backinfo.st_mode & (S_IRWXG | S_IRWXO));
 
+      argv[0] = sani_uri;
 
-/*
- * 'load_request_root()' - Load jobs from the RequestRoot directory.
- */
+      filterfds[slot][0] = -1;
+      filterfds[slot][1] = open("/dev/null", O_WRONLY);
 
-static void
-load_request_root(void)
-{
-  cups_dir_t           *dir;           /* Directory */
-  cups_dentry_t                *dent;          /* Directory entry */
-  cupsd_job_t          *job;           /* New job */
+      if (filterfds[slot][1] < 0)
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"/dev/null\" - %s.",
+                       strerror(errno));
+       snprintf(printer->state_message, sizeof(printer->state_message),
+                "Unable to open \"/dev/null\" - %s.", strerror(errno));
 
+       cupsdAddPrinterHistory(printer);
 
- /*
-  * Open the requests directory...
-  */
+       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                      "Job canceled because the server could not open a file.");
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "Scanning %s for jobs...", RequestRoot);
+        goto abort_job;
+      }
 
-  if ((dir = cupsDirOpen(RequestRoot)) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to open spool directory \"%s\": %s",
-                    RequestRoot, strerror(errno));
-    return;
-  }
+      fcntl(filterfds[slot][1], F_SETFD,
+            fcntl(filterfds[slot][1], F_GETFD) | FD_CLOEXEC);
 
- /*
-  * Read all the c##### files...
-  */
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: backend=\"%s\"",
+                      command);
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "start_job: filterfds[%d] = [ %d %d ]",
+                     slot, filterfds[slot][0], filterfds[slot][1]);
 
-  while ((dent = cupsDirRead(dir)) != NULL)
-    if (strlen(dent->filename) >= 6 && dent->filename[0] == 'c')
-    {
-     /*
-      * Allocate memory for the job...
-      */
+      pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
+                             filterfds[slot][1], statusfds[1],
+                             job->back_pipes[1], backroot,
+                             &(job->backend));
 
-      if ((job = calloc(sizeof(cupsd_job_t), 1)) == NULL)
+      if (pid == 0)
       {
-        cupsdLogMessage(CUPSD_LOG_ERROR, "Ran out of memory for jobs!");
-       cupsDirClose(dir);
-       return;
+       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to start backend \"%s\" - %s.",
+                        method, strerror(errno));
+       snprintf(printer->state_message, sizeof(printer->state_message),
+                "Unable to start backend \"%s\" - %s.", method,
+                strerror(errno));
+
+       cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+                      "Job canceled because the server could not execute "
+                     "the backend.");
+
+        goto abort_job;
+      }
+      else
+      {
+       cupsdLogMessage(CUPSD_LOG_INFO,
+                       "Started backend %s (PID %d) for job %d.",
+                       command, pid, job->id);
       }
+    }
 
-     /*
-      * Assign the job ID...
-      */
+    if (job->current_file == job->num_files)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "start_job: Closing print pipes [ %d %d ]...",
+                     job->print_pipes[0], job->print_pipes[1]);
 
-      job->id             = atoi(dent->filename + 1);
-      job->back_pipes[0]  = -1;
-      job->back_pipes[1]  = -1;
-      job->print_pipes[0] = -1;
-      job->print_pipes[1] = -1;
+      cupsdClosePipe(job->print_pipes);
 
-      if (job->id >= NextJobId)
-        NextJobId = job->id + 1;
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "start_job: Closing back pipes [ %d %d ]...",
+                     job->back_pipes[0], job->back_pipes[1]);
 
-     /*
-      * Load the job...
-      */
+      cupsdClosePipe(job->back_pipes);
+    }
+  }
+  else
+  {
+    filterfds[slot][0] = -1;
+    filterfds[slot][1] = -1;
 
-      cupsdLoadJob(job);
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "start_job: Closing filter pipes for slot %d "
+                   "[ %d %d ]...",
+                    !slot, filterfds[!slot][0], filterfds[!slot][1]);
 
-     /*
-      * Insert the job into the array, sorting by job priority and ID...
-      */
+    cupsdClosePipe(filterfds[!slot]);
 
-      cupsArrayAdd(Jobs, job);
+    if (job->current_file == job->num_files)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "start_job: Closing print pipes [ %d %d ]...",
+                     job->print_pipes[0], job->print_pipes[1]);
 
-      if (job->state_value < IPP_JOB_STOPPED)
-        cupsArrayAdd(ActiveJobs,job);
-      else
-        cupsdUnloadJob(job);
+      cupsdClosePipe(job->print_pipes);
     }
+  }
 
-  cupsDirClose(dir);
-}
+  for (slot = 0; slot < 2; slot ++)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "start_job: Closing filter pipes for slot %d "
+                   "[ %d %d ]...",
+                    slot, filterfds[slot][0], filterfds[slot][1]);
+    cupsdClosePipe(filterfds[slot]);
+  }
 
+  if (remote_job)
+  {
+    for (i = 0; i < job->num_files; i ++)
+      free(argv[i + 6]);
+  }
 
-/*
- * 'set_time()' - Set one of the "time-at-xyz" attributes...
- */
+  free(argv);
 
-static void
-set_time(cupsd_job_t *job,             /* I - Job to update */
-         const char  *name)            /* I - Name of attribute */
-{
-  ipp_attribute_t      *attr;          /* Time attribute */
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "start_job: Closing status output pipe %d...",
+                  statusfds[1]);
 
+  close(statusfds[1]);
 
-  if ((attr = ippFindAttribute(job->attrs, name, IPP_TAG_ZERO)) != NULL)
-  {
-    attr->value_tag         = IPP_TAG_INTEGER;
-    attr->values[0].integer = time(NULL);
-  }
-}
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "start_job: Adding fd %d to InputSet...",
+                  job->status_buffer->fd);
 
+  FD_SET(job->status_buffer->fd, InputSet);
 
-/*
- * 'set_hold_until()' - Set the hold time and update job-hold-until attribute...
- */
+  cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, "Job #%d started.",
+                job->id);
 
-static void 
-set_hold_until(cupsd_job_t *job,       /* I - Job to update */
-              time_t      holdtime)    /* I - Hold until time */
-{
-  ipp_attribute_t      *attr;          /* job-hold-until attribute */
-  struct tm            *holddate;      /* Hold date */
-  char                 holdstr[64];    /* Hold time */
+  return;
 
 
  /*
-  * Set the hold_until value and hold the job...
+  * If we get here, we need to abort the current job and close out all
+  * files and pipes...
   */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "set_hold_until: hold_until = %d",
-                  (int)holdtime);
+  abort_job:
 
-  job->state->values[0].integer = IPP_JOB_HELD;
-  job->state_value              = IPP_JOB_HELD;
-  job->hold_until               = holdtime;
+  for (slot = 0; slot < 2; slot ++)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "start_job: Closing filter pipes for slot %d "
+                   "[ %d %d ]...",
+                    slot, filterfds[slot][0], filterfds[slot][1]);
+    cupsdClosePipe(filterfds[slot]);
+  }
 
- /*
-  * Update the job-hold-until attribute with a string representing GMT
-  * time (HH:MM:SS)...
-  */
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "start_job: Closing status pipes [ %d %d ]...",
+                  statusfds[0], statusfds[1]);
+  cupsdClosePipe(statusfds);
 
-  holddate = gmtime(&holdtime);
-  snprintf(holdstr, sizeof(holdstr), "%d:%d:%d", holddate->tm_hour, 
-          holddate->tm_min, holddate->tm_sec);
+  cupsArrayDelete(filters);
 
-  if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
-                               IPP_TAG_KEYWORD)) == NULL)
-    attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+  if (remote_job)
+  {
+    for (i = 0; i < job->num_files; i ++)
+      free(argv[i + 6]);
+  }
 
- /*
-  * Either add the attribute or update the value of the existing one
-  */
+  free(argv);
 
-  if (attr == NULL)
-    attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
-                        "job-hold-until", NULL, holdstr);
-  else
-    cupsdSetString(&attr->values[0].string.text, holdstr);
+  cupsdStopJob(job, 0);
+}
 
-  cupsdSaveJob(job);
+
+/*
+ * 'unload_job()' - Unload a job from memory.
+ */
+
+static void
+unload_job(cupsd_job_t *job)           /* I - Job */
+{
+  if (!job->attrs)
+    return;
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "Unloading job %d...", job->id);
+
+  ippDelete(job->attrs);
+
+  job->attrs      = NULL;
+  job->state      = NULL;
+  job->sheets     = NULL;
+  job->job_sheets = NULL;
 }
 
 
 /*
- * End of "$Id: job.c 5196 2006-02-27 21:23:00Z mike $".
+ * End of "$Id: job.c 5305 2006-03-18 03:05:12Z mike $".
  */