]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / ipp.c
index 543eb84ec79210261f1c7c407bca3924d4daa6c8..7ed169a449d3d3bc8d09add475f75ef19a4ad45b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c 181 2006-06-22 20:01:18Z jlovell $"
+ * "$Id: ipp.c 5686 2006-06-21 21:02:56Z mike $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -126,7 +126,8 @@ static void accept_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    add_class(cupsd_client_t *con, ipp_attribute_t *uri);
 static int     add_file(cupsd_client_t *con, cupsd_job_t *job,
                         mime_type_t *filetype, int compression);
-static cupsd_job_t *add_job(cupsd_client_t *con, cupsd_printer_t *printer,
+static cupsd_job_t *add_job(cupsd_client_t *con, ipp_attribute_t *uri,
+                           cupsd_printer_t **dprinter,
                            mime_type_t *filetype);
 static void    add_job_state_reasons(cupsd_client_t *con, cupsd_job_t *job);
 static void    add_job_subscriptions(cupsd_client_t *con, cupsd_job_t *job);
@@ -699,6 +700,12 @@ accept_jobs(cupsd_client_t  *con,  /* I - Client connection */
 {
   http_status_t        status;                 /* Policy status */
   cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  const char   *name;                  /* Printer name */
   cupsd_printer_t *printer;            /* Printer data */
 
 
@@ -709,7 +716,11 @@ accept_jobs(cupsd_client_t  *con,  /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -740,19 +751,12 @@ accept_jobs(cupsd_client_t  *con, /* I - Client connection */
   cupsdAddPrinterHistory(printer);
 
   if (dtype & CUPS_PRINTER_CLASS)
-  {
     cupsdSaveAllClasses();
-
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" now accepting jobs (\"%s\").",
-                    printer->name, get_username(con));
-  }
   else
-  {
     cupsdSaveAllPrinters();
 
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" now accepting jobs (\"%s\").",
-                    printer->name, get_username(con));
-  }
+  cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" now accepting jobs (\"%s\").", name,
+                  get_username(con));
 
  /*
   * Everything was ok, so return OK status...
@@ -780,6 +784,7 @@ add_class(cupsd_client_t  *con,             /* I - Client connection */
   cupsd_printer_t *pclass,             /* Class */
                *member;                /* Member printer/class */
   cups_ptype_t dtype;                  /* Destination type */
+  const char   *dest;                  /* Printer or class name */
   ipp_attribute_t *attr;               /* Printer attribute */
   int          modify;                 /* Non-zero if we just modified */
   char         newname[IPP_MAX_NAME];  /* New class name */
@@ -998,7 +1003,11 @@ add_class(cupsd_client_t  *con,           /* I - Client connection */
       * Search for the printer or class URI...
       */
 
-      if (!cupsdValidateDest(attr->values[i].string.text, &dtype, &member))
+      httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[i].string.text, method,
+                      sizeof(method), username, sizeof(username), host,
+                     sizeof(host), &port, resource, sizeof(resource));
+
+      if ((dest = cupsdValidateDest(host, resource, &dtype, &member)) == NULL)
       {
        /*
        * Bad URI...
@@ -1135,24 +1144,54 @@ add_file(cupsd_client_t *con,           /* I - Connection to client */
 
 static cupsd_job_t *                   /* O - Job object */
 add_job(cupsd_client_t  *con,          /* I - Client connection */
-       cupsd_printer_t *printer,       /* I - Destination printer */
+        ipp_attribute_t *uri,          /* I - printer-uri */
+       cupsd_printer_t **dprinter,     /* I - Destination printer */
        mime_type_t     *filetype)      /* I - First print file type, if any */
 {
   http_status_t        status;                 /* Policy status */
   ipp_attribute_t *attr;               /* Current attribute */
+  const char   *dest;                  /* Destination */
+  cups_ptype_t dtype;                  /* Destination type (printer or class) */
   const char   *val;                   /* Default option value */
   int          priority;               /* Job priority */
   char         *title;                 /* Job name/title */
   cupsd_job_t  *job;                   /* Current job */
-  char         job_uri[HTTP_MAX_URI];  /* Job URI */
+  char         job_uri[HTTP_MAX_URI],  /* Job URI */
+               method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  cupsd_printer_t *printer;            /* Printer data */
   int          kbytes;                 /* Size of print file */
   int          i;                      /* Looping var */
   int          lowerpagerange;         /* Page range bound */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
-                  con, con->http.fd, printer, printer->name,
-                 filetype, filetype->super, filetype->type);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %s)", con,
+                  con->http.fd, uri->values[0].string.text);
+
+ /*
+  * Is the destination valid?
+  */
+
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+  {
+   /*
+    * Bad URI...
+    */
+
+    send_ipp_status(con, IPP_NOT_FOUND,
+                    _("The printer or class was not found."));
+    return (NULL);
+  }
+
+  if (dprinter)
+    *dprinter = printer;
 
  /*
   * Check remote printing to non-shared printer...
@@ -1190,7 +1229,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
   {
     send_ipp_status(con, IPP_NOT_ACCEPTING,
                     _("Destination \"%s\" is not accepting jobs."),
-                    printer->name);
+                    dest);
     return (NULL);
   }
 
@@ -1257,7 +1296,7 @@ add_job(cupsd_client_t  *con,             /* I - Client connection */
   if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
     cupsdCleanJobs();
 
-  if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
+  if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
   {
     send_ipp_status(con, IPP_NOT_POSSIBLE,
                     _("Too many active jobs."));
@@ -1299,13 +1338,11 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   if ((job = cupsdAddJob(priority, printer->name)) == NULL)
   {
     send_ipp_status(con, IPP_INTERNAL_ERROR,
-                    _("Unable to add job for destination \"%s\"!"),
-                   printer->name);
+                    _("Unable to add job for destination \"%s\"!"), dest);
     return (NULL);
   }
 
-  job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
-                                  CUPS_PRINTER_REMOTE);
+  job->dtype   = dtype;
   job->attrs   = con->request;
   con->request = NULL;
 
@@ -2730,10 +2767,11 @@ cancel_all_jobs(cupsd_client_t  *con,   /* I - Client connection */
                ipp_attribute_t *uri)   /* I - Job or Printer URI */
 {
   http_status_t        status;                 /* Policy status */
+  const char   *dest;                  /* Destination */
   cups_ptype_t dtype;                  /* Destination type */
-  char         scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
                userpass[HTTP_MAX_URI], /* Username portion of URI */
-               hostname[HTTP_MAX_URI], /* Host portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
   ipp_attribute_t *attr;               /* Attribute in request */
@@ -2792,17 +2830,16 @@ cancel_all_jobs(cupsd_client_t  *con,   /* I - Client connection */
   * And if the destination is valid...
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), userpass, sizeof(userpass), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI?
     */
 
-    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text,
-                    scheme, sizeof(scheme), userpass, sizeof(userpass),
-                   hostname, sizeof(hostname), &port,
-                   resource, sizeof(resource));
-
     if ((!strncmp(resource, "/printers/", 10) && resource[10]) ||
         (!strncmp(resource, "/classes/", 9) && resource[9]))
     {
@@ -2810,6 +2847,13 @@ cancel_all_jobs(cupsd_client_t  *con,    /* I - Client connection */
                       _("The printer or class was not found."));
       return;
     }
+    else if (strcmp(resource, "/printers/"))
+    {
+      send_ipp_status(con, IPP_NOT_FOUND,
+                      _("The printer-uri \"%s\" is not valid."),
+                     uri->values[0].string.text);
+      return;
+    }
 
    /*
     * Check policy...
@@ -2836,8 +2880,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
     * Check policy...
     */
 
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
-                                   NULL)) != HTTP_OK)
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
     {
       send_http_error(con, status);
       return;
@@ -2847,11 +2890,10 @@ cancel_all_jobs(cupsd_client_t  *con,   /* I - Client connection */
     * Cancel all of the jobs on the named printer...
     */
 
-    cupsdCancelJobs(printer->name, username, purge);
+    cupsdCancelJobs(dest, username, purge);
 
     cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
-                    printer->name, purge ? "purged" : "cancelled",
-                   get_username(con));
+                    dest, purge ? "purged" : "cancelled", get_username(con));
   }
 
   con->response->request.status.status_code = IPP_OK;
@@ -2868,12 +2910,13 @@ cancel_job(cupsd_client_t  *con,        /* I - Client connection */
 {
   ipp_attribute_t *attr;               /* Current attribute */
   int          jobid;                  /* Job ID */
-  char         scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
   cupsd_job_t  *job;                   /* Job information */
+  const char   *dest;                  /* Destination */
   cups_ptype_t dtype;                  /* Destination type (printer or class) */
   cupsd_printer_t *printer;            /* Printer data */
 
@@ -2905,7 +2948,11 @@ cancel_job(cupsd_client_t  *con, /* I - Client connection */
       * Find the current job on the specified printer...
       */
 
-      if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+      httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                      sizeof(method), username, sizeof(username), host,
+                     sizeof(host), &port, resource, sizeof(resource));
+
+      if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
       {
        /*
        * Bad URI...
@@ -2932,7 +2979,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
             job;
             job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
          if (job->state_value <= IPP_JOB_PROCESSING &&
-             !strcasecmp(job->dest, printer->name))
+             !strcasecmp(job->dest, dest))
            break;
 
        if (job)
@@ -2940,7 +2987,7 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
        else
        {
          send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s!"),
-                         printer->name);
+                         dest);
          return;
        }
       }
@@ -2952,8 +2999,8 @@ cancel_job(cupsd_client_t  *con,  /* I - Client connection */
     * Got a job URI; parse it to get the job ID...
     */
 
-    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
-                    sizeof(scheme), username, sizeof(username), host,
+    httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                    sizeof(method), username, sizeof(username), host,
                    sizeof(host), &port, resource, sizeof(resource));
  
     if (strncmp(resource, "/jobs/", 6))
@@ -4412,33 +4459,17 @@ static void
 create_job(cupsd_client_t  *con,       /* I - Client connection */
           ipp_attribute_t *uri)        /* I - Printer URI */
 {
-  cupsd_printer_t      *printer;       /* Printer */
-  cupsd_job_t          *job;           /* New job */
+  cupsd_job_t  *job;                   /* New job */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
                   con->http.fd, uri->values[0].string.text);
 
- /*
-  * Is the destination valid?
-  */
-
-  if (!cupsdValidateDest(uri->values[0].string.text, NULL, &printer))
-  {
-   /*
-    * Bad URI...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return;
-  }
-
  /*
   * Create the job object...
   */
 
-  if ((job = add_job(con, printer, NULL)) == NULL)
+  if ((job = add_job(con, uri, NULL, NULL)) == NULL)
     return;
 
  /*
@@ -4709,8 +4740,7 @@ create_subscription(
     dtype   = CUPS_PRINTER_CLASS;
     printer = NULL;
   }
-  else if ((dest = cupsdValidateDest(uri->values[0].string.text, &dtype,
-                                     &printer)) == NULL)
+  else if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -4727,8 +4757,7 @@ create_subscription(
 
   if (printer)
   {
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
-                                   NULL)) != HTTP_OK)
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
     {
       send_http_error(con, status);
       return;
@@ -4976,7 +5005,13 @@ delete_printer(cupsd_client_t  *con,     /* I - Client connection */
                ipp_attribute_t *uri)   /* I - URI of printer or class */
 {
   http_status_t        status;                 /* Policy status */
+  const char   *dest;                  /* Destination */
   cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
   cupsd_printer_t *printer;            /* Printer/class */
   char         filename[1024];         /* Script/PPD filename */
 
@@ -4988,7 +5023,11 @@ delete_printer(cupsd_client_t  *con,     /* I - Client connection */
   * Do we have a valid URI?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -5013,7 +5052,7 @@ delete_printer(cupsd_client_t  *con,      /* I - Client connection */
   * Remove old jobs...
   */
 
-  cupsdCancelJobs(printer->name, NULL, 1);
+  cupsdCancelJobs(dest, NULL, 1);
 
  /*
   * Remove old subscriptions and send a "deleted printer" event...
@@ -5022,7 +5061,7 @@ delete_printer(cupsd_client_t  *con,      /* I - Client connection */
   cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, printer, NULL,
                 "%s \"%s\" deleted by \"%s\".",
                (dtype & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
-               printer->name, get_username(con));
+               dest, get_username(con));
 
   cupsdExpireSubscriptions(printer, NULL);
  
@@ -5030,26 +5069,24 @@ delete_printer(cupsd_client_t  *con,    /* I - Client connection */
   * Remove any old PPD or script files...
   */
 
-  snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
-           printer->name);
+  snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot, dest);
   unlink(filename);
 
-  snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
-           printer->name);
+  snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, dest);
   unlink(filename);
 
   if (dtype & CUPS_PRINTER_CLASS)
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".",
-                    printer->name, get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".", dest,
+                    get_username(con));
 
     cupsdDeletePrinter(printer, 0);
     cupsdSaveAllClasses();
   }
   else
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".",
-                    printer->name, get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".", dest,
+                    get_username(con));
 
     cupsdDeletePrinter(printer, 0);
     cupsdSaveAllPrinters();
@@ -5292,7 +5329,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   const char   *dest;                  /* Destination */
   cups_ptype_t dtype;                  /* Destination type (printer or class) */
   cups_ptype_t dmask;                  /* Destination type mask */
-  char         scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
@@ -5314,8 +5351,8 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
-                  sizeof(scheme), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(resource, "/") ||
@@ -5340,8 +5377,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
     dmask   = CUPS_PRINTER_CLASS;
     printer = NULL;
   }
-  else if ((dest = cupsdValidateDest(uri->values[0].string.text, &dtype,
-                                     &printer)) == NULL)
+  else if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -5360,8 +5396,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
 
   if (printer)
   {
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
-                                   NULL)) != HTTP_OK)
+    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
     {
       send_http_error(con, status);
       return;
@@ -5697,7 +5732,17 @@ get_printer_attrs(cupsd_client_t  *con,  /* I - Client connection */
                  ipp_attribute_t *uri) /* I - Printer URI */
 {
   http_status_t                status;         /* Policy status */
+  const char           *dest;          /* Destination */
   cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
   cupsd_printer_t      *printer;       /* Printer/class */
   cups_array_t         *ra;            /* Requested attributes array */
 
@@ -5709,7 +5754,11 @@ get_printer_attrs(cupsd_client_t  *con,  /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -5972,8 +6021,8 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
   cups_array_t         *ra;            /* Requested attributes array */
   ipp_attribute_t      *attr;          /* Attribute */
   cups_ptype_t         dtype;          /* Destination type (printer or class) */
-  char                 scheme[HTTP_MAX_URI],
-                                       /* Scheme portion of URI */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
                        username[HTTP_MAX_URI],
                                        /* Username portion of URI */
                        host[HTTP_MAX_URI],
@@ -5993,8 +6042,8 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
   * Is the destination valid?
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
-                  sizeof(scheme), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(resource, "/") ||
@@ -6017,7 +6066,7 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
       return;
     }
   }
-  else if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  else if (!cupsdValidateDest(host, resource, &dtype, &printer))
   {
    /*
     * Bad URI...
@@ -6276,7 +6325,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
                *dest;                  /* Destination */
   cups_ptype_t stype,                  /* Source type (printer or class) */
                dtype;                  /* Destination type (printer or class) */
-  char         scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
@@ -6304,8 +6353,11 @@ move_job(cupsd_client_t  *con,           /* I - Client connection */
     return;
   }
     
-  if ((dest = cupsdValidateDest(attr->values[0].string.text, &dtype,
-                                &dprinter)) == NULL)
+  httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((dest = cupsdValidateDest(host, resource, &dtype, &dprinter)) == NULL)
   {
    /*
     * Bad URI...
@@ -6320,8 +6372,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con,
-                                 NULL)) != HTTP_OK)
+  if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con, NULL)) != HTTP_OK)
   {
     send_http_error(con, status);
     return;
@@ -6331,8 +6382,8 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
   * See if we have a job URI or a printer URI...
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
-                  sizeof(scheme), username, sizeof(username), host,
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
                  sizeof(host), &port, resource, sizeof(resource));
 
   if (!strcmp(uri->name, "printer-uri"))
@@ -6348,8 +6399,7 @@ move_job(cupsd_client_t  *con,            /* I - Client connection */
       * Move all jobs...
       */
 
-      if ((src = cupsdValidateDest(uri->values[0].string.text, &stype,
-                                   &sprinter)) == NULL)
+      if ((src = cupsdValidateDest(host, resource, &stype, &sprinter)) == NULL)
       {
        /*
        * Bad URI...
@@ -6647,7 +6697,6 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
 {
   ipp_attribute_t *attr;               /* Current attribute */
   ipp_attribute_t *format;             /* Document-format attribute */
-  const char   *default_format;        /* document-format-default value */
   cupsd_job_t  *job;                   /* New job */
   char         filename[1024];         /* Job filename */
   mime_type_t  *filetype;              /* Type of file */
@@ -6704,21 +6753,6 @@ print_job(cupsd_client_t  *con,          /* I - Client connection */
     return;
   }
 
- /*
-  * Is the destination valid?
-  */
-
-  if (!cupsdValidateDest(uri->values[0].string.text, NULL, &printer))
-  {
-   /*
-    * Bad URI...
-    */
-
-    send_ipp_status(con, IPP_NOT_FOUND,
-                    _("The printer or class was not found."));
-    return;
-  }
-
  /*
   * Is it a format we support?
   */
@@ -6730,8 +6764,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
     * Grab format from client...
     */
 
-    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super,
-               type) != 2)
+    if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
     {
       send_ipp_status(con, IPP_BAD_REQUEST,
                       _("Could not scan type \"%s\"!"),
@@ -6739,26 +6772,10 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
       return;
     }
   }
-  else if ((default_format = cupsGetOption("document-format",
-                                           printer->num_options,
-                                          printer->options)) != NULL)
-  {
-   /*
-    * Use default document format...
-    */
-
-    if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2)
-    {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Could not scan type \"%s\"!"),
-                     default_format);
-      return;
-    }
-  }
   else
   {
    /*
-    * Auto-type it!
+    * No document format attribute?  Auto-type it!
     */
 
     strcpy(super, "application");
@@ -6781,35 +6798,32 @@ print_job(cupsd_client_t  *con,         /* I - Client connection */
                             doc_name ? doc_name->values[0].string.text : NULL,
                            &compression);
 
-    if (!filetype)
-      filetype = mimeType(MimeDatabase, super, type);
-  }
-  else
-    filetype = mimeType(MimeDatabase, super, type);
-
-  if (filetype &&
-      (!format ||
-       (!strcmp(super, "application") && !strcmp(type, "octet-stream"))))
-  {
-   /*
-    * Replace the document-format attribute value with the auto-typed or
-    * default one.
-    */
+    if (filetype)
+    {
+     /*
+      * Replace the document-format attribute value with the auto-typed one.
+      */
 
-    snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
-             filetype->type);
+      snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
+               filetype->type);
 
-    if (format)
-    {
-      _cupsStrFree(format->values[0].string.text);
+      if (format)
+      {
+         _cupsStrFree(format->values[0].string.text);
 
-      format->values[0].string.text = _cupsStrAlloc(mimetype);
+       format->values[0].string.text = _cupsStrAlloc(mimetype);
+      }
+      else
+        ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+                    "document-format", NULL, mimetype);
     }
     else
-      ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
-                  "document-format", NULL, mimetype);
+      filetype = mimeType(MimeDatabase, super, type);
   }
-  else if (!filetype)
+  else
+    filetype = mimeType(MimeDatabase, super, type);
+
+  if (!filetype)
   {
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
                     _("Unsupported format \'%s/%s\'!"), super, type);
@@ -6838,7 +6852,7 @@ print_job(cupsd_client_t  *con,           /* I - Client connection */
   * Create the job object...
   */
 
-  if ((job = add_job(con, printer, filetype)) == NULL)
+  if ((job = add_job(con, uri, &printer, filetype)) == NULL)
     return;
 
  /*
@@ -7103,6 +7117,12 @@ reject_jobs(cupsd_client_t  *con,        /* I - Client connection */
 {
   http_status_t        status;                 /* Policy status */
   cups_ptype_t dtype;                  /* Destination type (printer or class) */
+  char         method[HTTP_MAX_URI],   /* Method portion of URI */
+               username[HTTP_MAX_URI], /* Username portion of URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  int          port;                   /* Port portion of URI */
+  const char   *name;                  /* Printer name */
   cupsd_printer_t *printer;            /* Printer data */
   ipp_attribute_t *attr;               /* printer-state-message text */
 
@@ -7114,7 +7134,11 @@ reject_jobs(cupsd_client_t  *con,        /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -7155,14 +7179,14 @@ reject_jobs(cupsd_client_t  *con,       /* I - Client connection */
     cupsdSaveAllClasses();
 
     cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" rejecting jobs (\"%s\").",
-                    printer->name, get_username(con));
+                    name, get_username(con));
   }
   else
   {
     cupsdSaveAllPrinters();
 
     cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" rejecting jobs (\"%s\").",
-                    printer->name, get_username(con));
+                    name, get_username(con));
   }
 
  /*
@@ -7618,7 +7642,6 @@ send_document(cupsd_client_t  *con,       /* I - Client connection */
 {
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_attribute_t      *format;        /* Document-format attribute */
-  const char           *default_format;/* document-format-default value */
   int                  jobid;          /* Job ID number */
   cupsd_job_t          *job;           /* Current job */
   char                 job_uri[HTTP_MAX_URI],
@@ -7777,22 +7800,6 @@ send_document(cupsd_client_t  *con,      /* I - Client connection */
       return;
     }
   }
-  else if ((default_format = cupsGetOption("document-format",
-                                           printer->num_options,
-                                          printer->options)) != NULL)
-  {
-   /*
-    * Use default document format...
-    */
-
-    if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2)
-    {
-      send_ipp_status(con, IPP_BAD_REQUEST,
-                      _("Could not scan type \"%s\"!"),
-                     default_format);
-      return;
-    }
-  }
   else
   {
    /*
@@ -7819,35 +7826,31 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
                             doc_name ? doc_name->values[0].string.text : NULL,
                            &compression);
 
-    if (!filetype)
-      filetype = mimeType(MimeDatabase, super, type);
-  }
-  else
-    filetype = mimeType(MimeDatabase, super, type);
-
-  if (filetype &&
-      (!format ||
-       (!strcmp(super, "application") && !strcmp(type, "octet-stream"))))
-  {
-   /*
-    * Replace the document-format attribute value with the auto-typed or
-    * default one.
-    */
-
-    snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
-             filetype->type);
-
-    if (format)
+    if (filetype)
     {
-      _cupsStrFree(format->values[0].string.text);
+     /*
+      * Replace the document-format attribute value with the auto-typed one.
+      */
 
-      format->values[0].string.text = _cupsStrAlloc(mimetype);
+      snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
+               filetype->type);
+
+      if (format)
+      {
+       _cupsStrFree(format->values[0].string.text);
+       format->values[0].string.text = _cupsStrAlloc(mimetype);
+      }
+      else
+        ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+                    "document-format", NULL, mimetype);
     }
     else
-      ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
-                  "document-format", NULL, mimetype);
+      filetype = mimeType(MimeDatabase, super, type);
   }
-  else if (!filetype)
+  else
+    filetype = mimeType(MimeDatabase, super, type);
+
+  if (!filetype)
   {
     send_ipp_status(con, IPP_DOCUMENT_FORMAT,
                     _("Unsupported format \'%s/%s\'!"), super, type);
@@ -8087,6 +8090,16 @@ set_default(cupsd_client_t  *con,        /* I - Client connection */
 {
   http_status_t                status;         /* Policy status */
   cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
+  const char           *name;          /* Printer name */
   cupsd_printer_t      *printer;       /* Printer */
 
 
@@ -8097,7 +8110,11 @@ set_default(cupsd_client_t  *con,        /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -8130,8 +8147,8 @@ set_default(cupsd_client_t  *con, /* I - Client connection */
   cupsdWritePrintcap();
 
   cupsdLogMessage(CUPSD_LOG_INFO,
-                  "Default destination set to \"%s\" by \"%s\".",
-                 printer->name, get_username(con));
+                  "Default destination set to \"%s\" by \"%s\".", name,
+                  get_username(con));
 
  /*
   * Everything was ok, so return OK status...
@@ -8633,7 +8650,8 @@ set_printer_defaults(
                       attr->values[0].string.text);
       cupsdSetString(&printer->error_policy, attr->values[0].string.text);
     }
-    else if (!strcmp(attr->name, "notify-lease-duration-default") ||
+    else if (!strcmp(attr->name, "document-format-default") ||
+             !strcmp(attr->name, "notify-lease-duration-default") ||
              !strcmp(attr->name, "notify-events-default"))
       continue;
 
@@ -8736,6 +8754,16 @@ start_printer(cupsd_client_t  *con,      /* I - Client connection */
 {
   http_status_t                status;         /* Policy status */
   cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
+  const char           *name;          /* Printer name */
   cupsd_printer_t      *printer;       /* Printer data */
 
 
@@ -8746,7 +8774,11 @@ start_printer(cupsd_client_t  *con,      /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -8777,19 +8809,17 @@ start_printer(cupsd_client_t  *con,     /* I - Client connection */
 
   if (dtype & CUPS_PRINTER_CLASS)
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" started by \"%s\".",
-                    printer->name, get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" started by \"%s\".", name,
+                    get_username(con));
     cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Class \"%s\" started by \"%s\".", printer->name,
-                 get_username(con));
+                  "Class \"%s\" started by \"%s\".", name, get_username(con));
   }
   else
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" started by \"%s\".",
-                    printer->name, get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" started by \"%s\".", name,
+                    get_username(con));
     cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Printer \"%s\" started by \"%s\".", printer->name,
-                 get_username(con));
+                  "Printer \"%s\" started by \"%s\".", name, get_username(con));
   }
 
   cupsdCheckJobs();
@@ -8812,6 +8842,16 @@ stop_printer(cupsd_client_t  *con,       /* I - Client connection */
 {
   http_status_t                status;         /* Policy status */
   cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
+  const char           *name;          /* Printer name */
   cupsd_printer_t      *printer;       /* Printer data */
   ipp_attribute_t      *attr;          /* printer-state-message attribute */
 
@@ -8823,7 +8863,11 @@ stop_printer(cupsd_client_t  *con,       /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
   {
    /*
     * Bad URI...
@@ -8861,19 +8905,17 @@ stop_printer(cupsd_client_t  *con,      /* I - Client connection */
 
   if (dtype & CUPS_PRINTER_CLASS)
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" stopped by \"%s\".",
-                    printer->name, get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" stopped by \"%s\".", name,
+                    get_username(con));
     cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Class \"%s\" stopped by \"%s\".", printer->name,
-                 get_username(con));
+                  "Class \"%s\" stopped by \"%s\".", name, get_username(con));
   }
   else
   {
-    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" stopped by \"%s\".",
-                    printer->name, get_username(con));
+    cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" stopped by \"%s\".", name,
+                    get_username(con));
     cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
-                  "Printer \"%s\" stopped by \"%s\".", printer->name,
-                 get_username(con));
+                  "Printer \"%s\" stopped by \"%s\".", name, get_username(con));
   }
 
  /*
@@ -9000,6 +9042,15 @@ validate_job(cupsd_client_t  *con,       /* I - Client connection */
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_attribute_t      *format;        /* Document-format attribute */
   cups_ptype_t         dtype;          /* Destination type (printer or class) */
+  char                 method[HTTP_MAX_URI],
+                                       /* Method portion of URI */
+                       username[HTTP_MAX_URI],
+                                       /* Username portion of URI */
+                       host[HTTP_MAX_URI],
+                                       /* Host portion of URI */
+                       resource[HTTP_MAX_URI];
+                                       /* Resource portion of URI */
+  int                  port;           /* Port portion of URI */
   char                 super[MIME_MAX_SUPER],
                                        /* Supertype of file */
                        type[MIME_MAX_TYPE];
@@ -9059,7 +9110,11 @@ validate_job(cupsd_client_t  *con,       /* I - Client connection */
   * Is the destination valid?
   */
 
-  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
+  httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+                  sizeof(method), username, sizeof(username), host,
+                 sizeof(host), &port, resource, sizeof(resource));
+
+  if (cupsdValidateDest(host, resource, &dtype, &printer) == NULL)
   {
    /*
     * Bad URI...
@@ -9159,5 +9214,5 @@ validate_user(cupsd_job_t    *job,        /* I - Job */
 
 
 /*
- * End of "$Id: ipp.c 181 2006-06-22 20:01:18Z jlovell $".
+ * End of "$Id: ipp.c 5686 2006-06-21 21:02:56Z mike $".
  */