]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge changes from CUPS 1.4svn-r7994.
[thirdparty/cups.git] / scheduler / ipp.c
index 621663e3a59ff279665c36923bc453809ccfb26a..016a1b1af619972480604078d57598929ab90b34 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c 7682 2008-06-21 00:06:02Z mike $"
+ * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -25,7 +25,7 @@
  *   add_job()                   - Add a job to a print queue.
  *   add_job_state_reasons()     - Add the "job-state-reasons" attribute based
  *                                 upon the job and printer state...
- *   add_job_subscriptions()     - Add any subcriptions for a job.
+ *   add_job_subscriptions()     - Add any subscriptions for a job.
  *   add_job_uuid()              - Add job-uuid attribute to a job.
  *   add_printer()               - Add a printer to the system.
  *   add_printer_state_reasons() - Add the "printer-state-reasons" attribute
@@ -77,7 +77,7 @@
  *   move_job()                  - Move a job to a new destination.
  *   ppd_parse_line()            - Parse a PPD default line.
  *   print_job()                 - Print a file to a printer or class.
- *   read_ps_job_ticket()        - Reads a job ticket embedded in a PS file.
+ *   read_job_ticket()           - Read a job ticket embedded in a print file.
  *   reject_jobs()               - Reject print jobs to a printer.
  *   release_job()               - Release a held print job.
  *   renew_subscription()        - Renew an existing subscription...
@@ -201,7 +201,7 @@ static void move_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static int     ppd_parse_line(const char *line, char *option, int olen,
                               char *choice, int clen);
 static void    print_job(cupsd_client_t *con, ipp_attribute_t *uri);
-static void    read_ps_job_ticket(cupsd_client_t *con);
+static void    read_job_ticket(cupsd_client_t *con);
 static void    reject_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    release_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    renew_subscription(cupsd_client_t *con, int sub_id);
@@ -249,7 +249,7 @@ cupsdProcessIPPRequest(
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_attribute_t      *charset;       /* Character set attribute */
   ipp_attribute_t      *language;      /* Language attribute */
-  ipp_attribute_t      *uri;           /* Printer URI attribute */
+  ipp_attribute_t      *uri = NULL;    /* Printer or job URI attribute */
   ipp_attribute_t      *username;      /* requesting-user-name attr */
   int                  sub_id;         /* Subscription ID */
 
@@ -678,10 +678,15 @@ cupsdProcessIPPRequest(
     * Sending data from the scheduler...
     */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "cupsdProcessIPPRequest: %d status_code=%x (%s)",
-                    con->http.fd, con->response->request.status.status_code,
-                   ippErrorString(con->response->request.status.status_code));
+    cupsdLogMessage(con->response->request.status.status_code
+                        >= IPP_BAD_REQUEST &&
+                    con->response->request.status.status_code
+                       != IPP_NOT_FOUND ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG,
+                    "Returning IPP %s for %s (%s) from %s",
+                   ippErrorString(con->response->request.status.status_code),
+                   ippOpString(con->request->request.op.operation_id),
+                   uri ? uri->values[0].string.text : "no URI",
+                   con->http.hostname);
 
     if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
     {
@@ -1975,7 +1980,7 @@ add_job_state_reasons(
 
 
 /*
- * 'add_job_subscriptions()' - Add any subcriptions for a job.
+ * 'add_job_subscriptions()' - Add any subscriptions for a job.
  */
 
 static void
@@ -2443,7 +2448,9 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
     * Do we have a valid device URI?
     */
 
-    http_uri_status_t uri_status;      /* URI separation status */
+    http_uri_status_t  uri_status;     /* URI separation status */
+    char               old_device_uri[1024];
+                                       /* Old device URI */
 
 
     need_restart_job = 1;
@@ -2497,21 +2504,25 @@ add_printer(cupsd_client_t  *con,       /* I - Client connection */
         * Could not find device in list!
        */
 
-       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
-                       attr->values[0].string.text);
+       send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri scheme \"%s\"!"),
+                       scheme);
        return;
       }
     }
 
+    if (printer->sanitized_device_uri)
+      strlcpy(old_device_uri, printer->sanitized_device_uri,
+              sizeof(old_device_uri));
+    else
+      old_device_uri[0] = '\0';
+
+    cupsdSetDeviceURI(printer, attr->values[0].string.text);
+
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Setting %s device-uri to \"%s\" (was \"%s\".)",
-                   printer->name,
-                   cupsdSanitizeURI(attr->values[0].string.text, line,
-                                    sizeof(line)),
-                   cupsdSanitizeURI(printer->device_uri, resource,
-                                    sizeof(resource)));
+                   printer->name, printer->sanitized_device_uri,
+                   old_device_uri);
 
-    cupsdSetString(&printer->device_uri, attr->values[0].string.text);
     set_device_uri = 1;
   }
 
@@ -2609,6 +2620,48 @@ add_printer(cupsd_client_t  *con,        /* I - Client connection */
     cupsdAddPrinterHistory(printer);
   }
 
+  if ((attr = ippFindAttribute(con->request, "printer-state-reasons",
+                               IPP_TAG_KEYWORD)) != NULL)
+  {
+    if (attr->num_values >
+            (int)(sizeof(printer->reasons) / sizeof(printer->reasons[0])))
+    {
+      send_ipp_status(con, IPP_NOT_POSSIBLE,
+                      _("Too many printer-state-reasons values (%d > %d)!"),
+                     attr->num_values,
+                     (int)(sizeof(printer->reasons) /
+                           sizeof(printer->reasons[0])));
+      return;
+    }
+
+    for (i = 0; i < printer->num_reasons; i ++)
+      _cupsStrFree(printer->reasons[i]);
+
+    printer->num_reasons = 0;
+    for (i = 0; i < attr->num_values; i ++)
+    {
+      if (!strcmp(attr->values[i].string.text, "none"))
+        continue;
+
+      printer->reasons[printer->num_reasons] =
+          _cupsStrAlloc(attr->values[i].string.text);
+
+      if (!strcmp(printer->reasons[printer->num_reasons], "paused") &&
+          printer->state != IPP_PRINTER_STOPPED)
+      {
+       cupsdLogMessage(CUPSD_LOG_INFO,
+                       "Setting %s printer-state to %d (was %d.)",
+                       printer->name, IPP_PRINTER_STOPPED, printer->state);
+       cupsdStopPrinter(printer, 0);
+      }
+
+      printer->num_reasons ++;
+    }
+
+    if (PrintcapFormat == PRINTCAP_PLIST)
+      cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+  }
+
   set_printer_defaults(con, printer);
 
   if ((attr = ippFindAttribute(con->request, "auth-info-required",
@@ -3390,8 +3443,8 @@ apple_register_profiles(
     device_name  = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
                                             &kCFTypeDictionaryKeyCallBacks,
                                             &kCFTypeDictionaryValueCallBacks);
-    printer_name = CFStringCreateWithCString(kCFAllocatorDefault, p->name,
-                                           kCFStringEncodingUTF8);
+    printer_name = CFStringCreateWithCString(kCFAllocatorDefault,
+                                             p->name, kCFStringEncodingUTF8);
 
     if (device_name && printer_name)
     {
@@ -4972,12 +5025,6 @@ copy_model(cupsd_client_t *con,          /* I - Client connection */
   cups_option_t        *defaults;              /* Default options */
   char         cups_protocol[PPD_MAX_LINE];
                                        /* cupsProtocol attribute */
-  int          have_letter,            /* Have Letter size */
-               have_a4;                /* Have A4 size */
-#ifdef HAVE_LIBPAPER
-  char         *paper_result;          /* Paper size name from libpaper */
-  char         system_paper[64];       /* Paper size name buffer */
-#endif /* HAVE_LIBPAPER */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
@@ -5102,9 +5149,6 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
     return (-1);
   }
 
-  have_letter = ppdPageSize(ppd, "Letter") != NULL;
-  have_a4     = ppdPageSize(ppd, "A4") != NULL;
-
  /*
   * Open the destination (if possible) and set the default options...
   */
@@ -5149,81 +5193,20 @@ copy_model(cupsd_client_t *con,         /* I - Client connection */
 
     cupsFileClose(dst);
   }
-#ifdef HAVE_LIBPAPER
-  else if ((paper_result = systempapername()) != NULL)
-  {
-   /*
-    * Set the default media sizes from the systemwide default...
-    */
-
-    strlcpy(system_paper, paper_result, sizeof(system_paper));
-    system_paper[0] = toupper(system_paper[0] & 255);
-
-    if ((!strcmp(system_paper, "Letter") && have_letter) ||
-        (!strcmp(system_paper, "A4") && have_a4))
-    {
-      num_defaults = cupsAddOption("PageSize", system_paper,
-                                  num_defaults, &defaults);
-      num_defaults = cupsAddOption("PageRegion", system_paper,
-                                  num_defaults, &defaults);
-      num_defaults = cupsAddOption("PaperDimension", system_paper,
-                                  num_defaults, &defaults);
-      num_defaults = cupsAddOption("ImageableArea", system_paper,
-                                  num_defaults, &defaults);
-    }
-  }
-#endif /* HAVE_LIBPAPER */
-  else
+  else if (ppdPageSize(ppd, DefaultPaperSize))
   {
    /*
     * Add the default media sizes...
-    *
-    * Note: These values are generally not valid for large-format devices
-    *       like plotters, however it is probably safe to say that those
-    *       users will configure the media size after initially adding
-    *       the device anyways...
     */
 
-    if (!DefaultLanguage ||
-        !strcasecmp(DefaultLanguage, "C") ||
-        !strcasecmp(DefaultLanguage, "POSIX") ||
-       !strcasecmp(DefaultLanguage, "en") ||
-       !strncasecmp(DefaultLanguage, "en.", 3) ||
-       !strncasecmp(DefaultLanguage, "en_US", 5) ||
-       !strncasecmp(DefaultLanguage, "en_CA", 5) ||
-       !strncasecmp(DefaultLanguage, "fr_CA", 5))
-    {
-     /*
-      * These are the only locales that will default to "letter" size...
-      */
-
-      if (have_letter)
-      {
-       num_defaults = cupsAddOption("PageSize", "Letter", num_defaults,
-                                     &defaults);
-       num_defaults = cupsAddOption("PageRegion", "Letter", num_defaults,
-                                     &defaults);
-       num_defaults = cupsAddOption("PaperDimension", "Letter", num_defaults,
-                                     &defaults);
-       num_defaults = cupsAddOption("ImageableArea", "Letter", num_defaults,
-                                     &defaults);
-      }
-    }
-    else if (have_a4)
-    {
-     /*
-      * The rest default to "a4" size...
-      */
-
-      num_defaults = cupsAddOption("PageSize", "A4", num_defaults,
-                                   &defaults);
-      num_defaults = cupsAddOption("PageRegion", "A4", num_defaults,
-                                   &defaults);
-      num_defaults = cupsAddOption("PaperDimension", "A4", num_defaults,
-                                   &defaults);
-      num_defaults = cupsAddOption("ImageableArea", "A4", num_defaults,
-                                   &defaults);
-    }
+    num_defaults = cupsAddOption("PageSize", DefaultPaperSize,
+                                 num_defaults, &defaults);
+    num_defaults = cupsAddOption("PageRegion", DefaultPaperSize,
+                                 num_defaults, &defaults);
+    num_defaults = cupsAddOption("PaperDimension", DefaultPaperSize,
+                                 num_defaults, &defaults);
+    num_defaults = cupsAddOption("ImageableArea", DefaultPaperSize,
+                                 num_defaults, &defaults);
   }
 
   ppdClose(ppd);
@@ -5324,6 +5307,10 @@ copy_job_attrs(cupsd_client_t *con,      /* I - Client connection */
     ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
                  "document-count", job->num_files);
 
+  if (!ra || cupsArrayFind(ra, "job-media-progress"))
+    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                 "job-media-progress", job->progress);
+
   if (!ra || cupsArrayFind(ra, "job-more-info"))
     ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
                 "job-more-info", NULL, job_uri);
@@ -5785,6 +5772,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "job-impressions-completed");
       cupsArrayAdd(ra, "job-k-octets");
       cupsArrayAdd(ra, "job-k-octets-processed");
+      cupsArrayAdd(ra, "job-media-progress");
       cupsArrayAdd(ra, "job-media-sheets");
       cupsArrayAdd(ra, "job-media-sheets-completed");
       cupsArrayAdd(ra, "job-message-from-operator");
@@ -5817,6 +5805,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "job-impressions-supported");
       cupsArrayAdd(ra, "job-k-octets-supported");
       cupsArrayAdd(ra, "job-media-sheets-supported");
+      cupsArrayAdd(ra, "job-settable-attributes-supported");
       cupsArrayAdd(ra, "multiple-document-jobs-supported");
       cupsArrayAdd(ra, "multiple-operation-time-out");
       cupsArrayAdd(ra, "natural-language-configured");
@@ -5849,6 +5838,7 @@ create_requested_array(ipp_t *request)    /* I - IPP request */
       cupsArrayAdd(ra, "printer-state");
       cupsArrayAdd(ra, "printer-state-message");
       cupsArrayAdd(ra, "printer-state-reasons");
+      cupsArrayAdd(ra, "printer-settable-attributes-supported");
       cupsArrayAdd(ra, "printer-type");
       cupsArrayAdd(ra, "printer-up-time");
       cupsArrayAdd(ra, "printer-uri-supported");
@@ -7536,8 +7526,8 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
   {
     if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
         (printer->type & printer_mask) == printer_type &&
-       (!location || !printer->location ||
-        !strcasecmp(printer->location, location)))
+       (!location ||
+        (printer->location && !strcasecmp(printer->location, location))))
     {
      /*
       * If HideImplicitMembers is enabled, see if this printer or class
@@ -8467,8 +8457,9 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
   */
 
   if (!strcasecmp(filetype->super, "application") &&
-      !strcasecmp(filetype->type, "postscript"))
-    read_ps_job_ticket(con);
+      (!strcasecmp(filetype->type, "postscript") ||
+       !strcasecmp(filetype->type, "pdf")))
+    read_job_ticket(con);
 
  /*
   * Create the job object...
@@ -8519,6 +8510,8 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
              "File of type %s/%s queued by \"%s\".",
              filetype->super, filetype->type, job->username);
   cupsdLogJob(job, CUPSD_LOG_DEBUG, "hold_until=%d", (int)job->hold_until);
+  cupsdLogJob(job, CUPSD_LOG_INFO, "Queued on \"%s\" by \"%s\".",
+             job->dest, job->username);
 
  /*
   * Start the job if possible...
@@ -8529,16 +8522,16 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
 
 
 /*
- * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
+ * 'read_job_ticket()' - Read a job ticket embedded in a print file.
  *
- * This function only gets called when printing a single PostScript
+ * This function only gets called when printing a single PDF or PostScript
  * file using the Print-Job operation.  It doesn't work for Create-Job +
  * Send-File, since the job attributes need to be set at job creation
- * time for banners to work.  The embedded PS job ticket stuff is here
- * only to allow the Windows printer driver for CUPS to pass in JCL
+ * time for banners to work.  The embedded job ticket stuff is here
+ * primarily to allow the Windows printer driver for CUPS to pass in JCL
  * options and IPP attributes which otherwise would be lost.
  *
- * The format of a PS job ticket is simple:
+ * The format of a job ticket is simple:
  *
  *     %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
  *
@@ -8548,8 +8541,8 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
  *     %cupsJobTicket: attrN=valueN
  *
  * Job ticket lines must appear immediately after the first line that
- * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
- * looking for job ticket info when it finds a line that does not begin
+ * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
+ * stops looking for job ticket info when it finds a line that does not begin
  * with "%cupsJobTicket:".
  *
  * The maximum length of a job ticket line, including the prefix, is
@@ -8562,7 +8555,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
  */
 
 static void
-read_ps_job_ticket(cupsd_client_t *con)        /* I - Client connection */
+read_job_ticket(cupsd_client_t *con)   /* I - Client connection */
 {
   cups_file_t          *fp;            /* File to read from */
   char                 line[256];      /* Line data */
@@ -8581,8 +8574,7 @@ read_ps_job_ticket(cupsd_client_t *con)   /* I - Client connection */
   if ((fp = cupsFileOpen(con->filename, "rb")) == NULL)
   {
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "read_ps_job_ticket: Unable to open PostScript print file "
-                   "- %s",
+                    "Unable to open print file for job ticket - %s",
                     strerror(errno));
     return;
   }
@@ -8594,14 +8586,13 @@ read_ps_job_ticket(cupsd_client_t *con) /* I - Client connection */
   if (cupsFileGets(fp, line, sizeof(line)) == NULL)
   {
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "read_ps_job_ticket: Unable to read from PostScript print "
-                   "file - %s",
+                    "Unable to read from print file for job ticket - %s",
                     strerror(errno));
     cupsFileClose(fp);
     return;
   }
 
-  if (strncmp(line, "%!PS-Adobe-", 11))
+  if (strncmp(line, "%!PS-Adobe-", 11) && strncmp(line, "%PDF-", 5))
   {
    /*
     * Not a DSC-compliant file, so no job ticket info will be available...
@@ -8928,6 +8919,8 @@ release_job(cupsd_client_t  *con, /* I - Client connection */
   cupsdLogJob(job, CUPSD_LOG_INFO, "Released by \"%s\".", username);
 
   con->response->request.status.status_code = IPP_OK;
+
+  cupsdCheckJobs();
 }
 
 
@@ -9315,6 +9308,23 @@ save_krb5_creds(cupsd_client_t *con,     /* I - Client connection */
     return;
 #    endif /* __APPLE__ */
 
+  if (!KerberosInitialized)
+  {
+   /*
+    * Setup a Kerberos context for the scheduler to use...
+    */
+
+    KerberosInitialized = 1;
+
+    if (krb5_init_context(&KerberosContext))
+    {
+      KerberosContext = NULL;
+
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to initialize Kerberos context");
+      return;
+    }
+  }
+
  /*
   * We MUST create a file-based cache because memory-based caches are
   * only valid for the current process/address space.
@@ -9617,11 +9627,7 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
   else
     filetype = mimeType(MimeDatabase, super, type);
 
-  jformat = ippFindAttribute(job->attrs, "document-format", IPP_TAG_MIMETYPE);
-
-  if (filetype &&
-      (!jformat ||
-       (!strcmp(super, "application") && !strcmp(type, "octet-stream"))))
+  if (filetype)
   {
    /*
     * Replace the document-format attribute value with the auto-typed or
@@ -9631,7 +9637,8 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
     snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
              filetype->type);
 
-    if (jformat)
+    if ((jformat = ippFindAttribute(job->attrs, "document-format",
+                                    IPP_TAG_MIMETYPE)) != NULL)
     {
       _cupsStrFree(jformat->values[0].string.text);
 
@@ -9792,39 +9799,71 @@ send_http_error(
     http_status_t   status,            /* I - HTTP status code */
     cupsd_printer_t *printer)          /* I - Printer, if any */
 {
-  cupsdLogMessage(CUPSD_LOG_ERROR, "%s: %s",
-                  ippOpString(con->request->request.op.operation_id),
-                 httpStatus(status));
-
-  if (status == HTTP_UNAUTHORIZED &&
-      printer && printer->num_auth_info_required > 0 &&
-      !strcmp(printer->auth_info_required[0], "negotiate"))
-    cupsdSendError(con, status, CUPSD_AUTH_NEGOTIATE);
-  else if (printer)
-  {
-    char       resource[HTTP_MAX_URI]; /* Resource portion of URI */
-    cupsd_location_t *auth;            /* Pointer to authentication element */
+  ipp_attribute_t      *uri;           /* Request URI, if any */
+
+
+  if ((uri = ippFindAttribute(con->request, "printer-uri",
+                              IPP_TAG_URI)) == NULL)
+    uri = ippFindAttribute(con->request, "job-uri", IPP_TAG_URI);
+
+  cupsdLogMessage(status == HTTP_FORBIDDEN ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG,
+                  "Returning HTTP %s for %s (%s) from %s",
+                  httpStatus(status),
+                 ippOpString(con->request->request.op.operation_id),
+                 uri ? uri->values[0].string.text : "no URI",
+                 con->http.hostname);
+
+  if (printer)
+  {
     int                auth_type;              /* Type of authentication required */
 
 
-    if (printer->type & CUPS_PRINTER_CLASS)
-      snprintf(resource, sizeof(resource), "/classes/%s", printer->name);
-    else
-      snprintf(resource, sizeof(resource), "/printers/%s", printer->name);
-
-    if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
-        auth->type == CUPSD_AUTH_NONE)
-      auth = cupsdFindPolicyOp(printer->op_policy_ptr,
-                               con->request ?
-                                  con->request->request.op.operation_id :
-                                  IPP_PRINT_JOB);
-
-    if (!auth)
-      auth_type = CUPSD_AUTH_NONE;
-    else if (auth->type == CUPSD_AUTH_DEFAULT)
-      auth_type = DefaultAuthType;
+    auth_type = CUPSD_AUTH_NONE;
+
+    if (status == HTTP_UNAUTHORIZED &&
+        printer->num_auth_info_required > 0 &&
+        !strcmp(printer->auth_info_required[0], "negotiate") &&
+       con->request &&
+       (con->request->request.op.operation_id == IPP_PRINT_JOB ||
+        con->request->request.op.operation_id == IPP_CREATE_JOB ||
+        con->request->request.op.operation_id == CUPS_AUTHENTICATE_JOB))
+    {
+     /*
+      * Creating and authenticating jobs requires Kerberos...
+      */
+
+      auth_type = CUPSD_AUTH_NEGOTIATE;
+    }
     else
-      auth_type = auth->type;
+    {
+     /*
+      * Use policy/location-defined authentication requirements...
+      */
+
+      char     resource[HTTP_MAX_URI]; /* Resource portion of URI */
+      cupsd_location_t *auth;          /* Pointer to authentication element */
+
+
+      if (printer->type & CUPS_PRINTER_CLASS)
+       snprintf(resource, sizeof(resource), "/classes/%s", printer->name);
+      else
+       snprintf(resource, sizeof(resource), "/printers/%s", printer->name);
+
+      if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
+         auth->type == CUPSD_AUTH_NONE)
+       auth = cupsdFindPolicyOp(printer->op_policy_ptr,
+                                con->request ?
+                                    con->request->request.op.operation_id :
+                                    IPP_PRINT_JOB);
+
+      if (auth)
+      {
+        if (auth->type == CUPSD_AUTH_DEFAULT)
+         auth_type = DefaultAuthType;
+       else
+         auth_type = auth->type;
+      }
+    }
 
     cupsdSendError(con, status, auth_type);
   }
@@ -9971,6 +10010,7 @@ set_job_attrs(cupsd_client_t  *con,      /* I - Client connection */
                                        /* Resource portion of URI */
   int                  port;           /* Port portion of URI */
   int                  event;          /* Events? */
+  int                  check_jobs;     /* Check jobs? */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_job_attrs(%p[%d], %s)", con,
@@ -10072,7 +10112,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 
   cupsdLoadJob(job);
 
-  event = 0;
+  check_jobs = 0;
+  event      = 0;
 
   for (attr = con->request->attrs; attr; attr = attr->next)
   {
@@ -10086,6 +10127,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
        !strcmp(attr->name, "job-detailed-status-messages") ||
        !strcmp(attr->name, "job-document-access-errors") ||
        !strcmp(attr->name, "job-id") ||
+       !strcmp(attr->name, "job-impressions-completed") ||
        !strcmp(attr->name, "job-k-octets") ||
         !strcmp(attr->name, "job-originating-host-name") ||
         !strcmp(attr->name, "job-originating-user-name") ||
@@ -10099,7 +10141,6 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
        !strcmp(attr->name, "number-of-intervening-jobs") ||
        !strcmp(attr->name, "output-device-assigned") ||
        !strncmp(attr->name, "date-time-at-", 13) ||
-       !strncmp(attr->name, "job-impressions", 15) ||
        !strncmp(attr->name, "job-k-octets", 12) ||
        !strncmp(attr->name, "job-media-sheets", 16) ||
        !strncmp(attr->name, "time-at-", 8))
@@ -10138,9 +10179,13 @@ set_job_attrs(cupsd_client_t  *con,    /* I - Client connection */
       }
       else if (con->response->request.status.status_code == IPP_OK)
       {
+        cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-priority to %d",
+                   attr->values[0].integer);
         cupsdSetJobPriority(job, attr->values[0].integer);
-        event |= CUPSD_EVENT_JOB_CONFIG_CHANGED |
-                CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED;
+
+       check_jobs = 1;
+        event      |= CUPSD_EVENT_JOB_CONFIG_CHANGED |
+                     CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED;
       }
     }
     else if (!strcmp(attr->name, "job-state"))
@@ -10170,10 +10215,14 @@ set_job_attrs(cupsd_client_t  *con,   /* I - Client connection */
              }
               else if (con->response->request.status.status_code == IPP_OK)
              {
+               cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-state to %d",
+                           attr->values[0].integer);
+
                job->state->values[0].integer = attr->values[0].integer;
                job->state_value = (ipp_jstate_t)attr->values[0].integer;
 
                 event |= CUPSD_EVENT_JOB_STATE;
+               check_jobs = 1;
              }
              break;
 
@@ -10197,7 +10246,13 @@ set_job_attrs(cupsd_client_t  *con,    /* I - Client connection */
                return;
              }
               else if (con->response->request.status.status_code == IPP_OK)
+             {
+               cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-state to %d",
+                           attr->values[0].integer);
                 cupsdCancelJob(job, 0, (ipp_jstate_t)attr->values[0].integer);
+
+                check_jobs = 1;
+             }
              break;
        }
       }
@@ -10233,6 +10288,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 
       if (!strcmp(attr->name, "job-hold-until"))
       {
+        cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-hold-until to %s",
+                   attr->values[0].string.text);
         cupsdSetJobHoldUntil(job, attr->values[0].string.text);
 
        if (!strcmp(attr->values[0].string.text, "no-hold"))
@@ -10240,7 +10297,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
        else
          cupsdHoldJob(job);
 
-        event |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
+        check_jobs = 1;
+        event      |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
       }
     }
     else if (attr->value_tag == IPP_TAG_DELETEATTR)
@@ -10306,7 +10364,8 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
   * Start jobs if possible...
   */
 
-  cupsdCheckJobs();
+  if (check_jobs)
+    cupsdCheckJobs();
 }
 
 
@@ -10452,6 +10511,7 @@ set_printer_defaults(
         continue;
 
       if (strcmp(attr->values[0].string.text, "abort-job") &&
+          strcmp(attr->values[0].string.text, "retry-current-job") &&
           strcmp(attr->values[0].string.text, "retry-job") &&
           strcmp(attr->values[0].string.text, "stop-printer"))
       {
@@ -11026,5 +11086,5 @@ validate_user(cupsd_job_t    *job,      /* I - Job */
 
 
 /*
- * End of "$Id: ipp.c 7682 2008-06-21 00:06:02Z mike $".
+ * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".
  */