]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/util.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / cups / util.c
index 33ba350537c2b523f2232cf738ccf218a516f637..80f36d153a047cc5c9189233ac879d0a584b91aa 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: util.c 7014 2007-10-10 21:57:43Z mike $"
+ * "$Id: util.c 7850 2008-08-20 00:07:25Z mike $"
  *
- *   Printing utilities for the Common UNIX Printing System (CUPS).
+ *   Printing utilities for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 2007-2010 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -18,7 +18,7 @@
  *
  *   cupsCancelJob()        - Cancel a print job on the default server.
  *   cupsCancelJob2()       - Cancel or purge a print job.
- *   cupsCreateJob()        - Create an empty job.
+ *   cupsCreateJob()        - Create an empty job for streaming.
  *   cupsFinishDocument()   - Finish sending a document.
  *   cupsFreeJobs()         - Free memory used by job data.
  *   cupsGetClasses()       - Get a list of printer classes from the default
@@ -37,8 +37,6 @@
  *                            server if it has changed.
  *   cupsGetPrinters()      - Get a list of printers from the default server.
  *   cupsGetServerPPD()     - Get an available PPD file from the server.
- *   cupsLastError()        - Return the last IPP status code.
- *   cupsLastErrorString()  - Return the last IPP status-message.
  *   cupsPrintFile()        - Print a file to a printer or class on the default
  *                            server.
  *   cupsPrintFile2()       - Print a file to a printer or class on the
@@ -49,7 +47,6 @@
  *                            the specified server.
  *   cupsStartDocument()    - Add a document to a job created with
  *                            cupsCreateJob().
- *   _cupsConnect()         - Get the default server connection...
  *   cups_get_printer_uri() - Get the printer-uri-supported attribute for the
  *                            first printer in a class.
  */
  * Include necessary headers...
  */
 
-#include "globals.h"
-#include "debug.h"
-#include <stdlib.h>
-#include <errno.h>
+#include "cups-private.h"
 #include <fcntl.h>
 #include <sys/stat.h>
 #if defined(WIN32) || defined(__EMX__)
@@ -84,15 +78,18 @@ static int  cups_get_printer_uri(http_t *http, const char *name,
 /*
  * 'cupsCancelJob()' - Cancel a print job on the default server.
  *
- * Use the cupsLastError() and cupsLastErrorString() functions to get
+ * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
+ * to cancel the current job on the named destination.
+ *
+ * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
  * the cause of any failure.
  */
 
 int                                    /* O - 1 on success, 0 on failure */
 cupsCancelJob(const char *name,                /* I - Name of printer or class */
-              int        job_id)       /* I - Job ID */
+              int        job_id)       /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
 {
-  return (cupsCancelJob2(CUPS_HTTP_DEFAULT, job_id, 0)
+  return (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0)
               < IPP_REDIRECTION_OTHER_SITE);
 }
 
@@ -103,18 +100,22 @@ cupsCancelJob(const char *name,           /* I - Name of printer or class */
  * Canceled jobs remain in the job history while purged jobs are removed
  * from the job history.
  *
- * Use the cupsLastError() and cupsLastErrorString() functions to get
+ * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
+ * to cancel the current job on the named destination.
+ *
+ * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
  * the cause of any failure.
  *
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
  */
 
 ipp_status_t                           /* O - IPP status */
-cupsCancelJob2(http_t *http,           /* I - HTTP connection or CUPS_HTTP_DEFAULT */
-               int    job_id,          /* I - Job ID */
-              int    purge)            /* I - 1 to purge, 0 to cancel */
+cupsCancelJob2(http_t     *http,       /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
+               const char *name,       /* I - Name of printer or class */
+               int        job_id,      /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
+              int        purge)        /* I - 1 to purge, 0 to cancel */
 {
-  char         uri[HTTP_MAX_URI];      /* Job URI */
+  char         uri[HTTP_MAX_URI];      /* Job/printer URI */
   ipp_t                *request;               /* IPP request */
 
 
@@ -122,9 +123,9 @@ cupsCancelJob2(http_t *http,                /* I - HTTP connection or CUPS_HTTP_DEFAULT */
   * Range check input...
   */
 
-  if (job_id <= 0)
+  if (job_id < -1 || (!name && job_id == 0))
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL));
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
     return (0);
   }
 
@@ -137,25 +138,42 @@ cupsCancelJob2(http_t *http,              /* I - HTTP connection or CUPS_HTTP_DEFAULT */
       return (IPP_SERVICE_UNAVAILABLE);
 
  /*
-  * Build an IPP_CANCEL_JOB request, which requires the following
+  * Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following
   * attributes:
   *
   *    attributes-charset
   *    attributes-natural-language
-  *    job-uri
+  *    job-uri or printer-uri + job-id
   *    requesting-user-name
-  *    [purge-job]
+  *    [purge-job] or [purge-jobs]
   */
 
-  request = ippNewRequest(IPP_CANCEL_JOB);
+  request = ippNewRequest(job_id < 0 ? IPP_PURGE_JOBS : IPP_CANCEL_JOB);
+
+  if (name)
+  {
+    httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                     "localhost", ippPort(), "/printers/%s", name);
 
-  snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
+                 uri);
+    ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
+                  job_id);
+  }
+  else if (job_id > 0)
+  {
+    snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
+
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
+  }
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
                NULL, cupsUser());
-  if (purge)
+
+  if (purge && job_id >= 0)
     ippAddBoolean(request, IPP_TAG_OPERATION, "purge-job", 1);
+  else if (!purge && job_id < 0)
+    ippAddBoolean(request, IPP_TAG_OPERATION, "purge-jobs", 0);
 
  /*
   * Do the request...
@@ -168,18 +186,21 @@ cupsCancelJob2(http_t *http,              /* I - HTTP connection or CUPS_HTTP_DEFAULT */
 
 
 /*
- * 'cupsCreateJob()' - Create an empty job.
+ * 'cupsCreateJob()' - Create an empty job for streaming.
  *
- * Submit files for printing to the job using the cupsStartDocument(),
- * cupsWriteRequestData(), and cupsFinishDocument() functions.
+ * Use this function when you want to stream print data using the
+ * @link cupsStartDocument@, @link cupsWriteRequestData@, and
+ * @link cupsFinishDocument@ functions.  If you have one or more files to
+ * print, use the @link cupsPrintFile2@ or @link cupsPrintFiles2@ function
+ * instead.
  *
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
  */
 
 int                                    /* O - Job ID or 0 on error */
 cupsCreateJob(
-    http_t        *http,               /* I - HTTP connection or CUPS_HTTP_DEFAULT */
-    const char    *name,               /* I - Printer or class name */
+    http_t        *http,               /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
+    const char    *name,               /* I - Destination name */
     const char    *title,              /* I - Title of job */
     int           num_options,         /* I - Number of options */
     cups_option_t *options)            /* I - Options */
@@ -193,7 +214,7 @@ cupsCreateJob(
 
 
   DEBUG_printf(("cupsCreateJob(http=%p, name=\"%s\", title=\"%s\", "
-                "num_options=%d, options=%p)\n",
+                "num_options=%d, options=%p)",
                 http, name, title, num_options, options));
 
  /*
@@ -202,7 +223,7 @@ cupsCreateJob(
 
   if (!name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
     return (0);
   }
 
@@ -212,7 +233,7 @@ cupsCreateJob(
 
   if ((request = ippNewRequest(IPP_CREATE_JOB)) == NULL)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
     return (0);
   }
 
@@ -251,12 +272,14 @@ cupsCreateJob(
 /*
  * 'cupsFinishDocument()' - Finish sending a document.
  *
- * @since CUPS 1.4@
+ * The document must have been started using @link cupsStartDocument@.
+ *
+ * @since CUPS 1.4/Mac OS X 10.6@
  */
 
 ipp_status_t                           /* O - Status of document submission */
-cupsFinishDocument(http_t     *http,   /* I - HTTP connection or CUPS_HTTP_DEFAULT */
-                   const char *name)   /* I - Printer or class name */
+cupsFinishDocument(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
+                   const char *name)   /* I - Destination name */
 {
   char resource[1024];                 /* Printer resource */
 
@@ -299,7 +322,7 @@ cupsFreeJobs(int        num_jobs,   /* I - Number of jobs */
 /*
  * 'cupsGetClasses()' - Get a list of printer classes from the default server.
  *
- * This function is deprecated - use cupsGetDests() instead.
+ * This function is deprecated - use @link cupsGetDests@ instead.
  *
  * @deprecated@
  */
@@ -317,7 +340,7 @@ cupsGetClasses(char ***classes)             /* O - Classes */
 
   if (!classes)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -394,12 +417,12 @@ cupsGetClasses(char ***classes)           /* O - Classes */
  * This function returns the default printer or class as defined by
  * the LPDEST or PRINTER environment variables. If these environment
  * variables are not set, the server default destination is returned.
- * Applications should use the cupsGetDests() and cupsGetDest() functions
- * to get the user-defined default printer, as this function does not
- * support the lpoptions-defined default printer.
+ * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
+ * functions to get the user-defined default printer, as this function does
+ * not support the lpoptions-defined default printer.
  */
 
-const char *                           /* O - Default printer or NULL */
+const char *                           /* O - Default printer or @code NULL@ */
 cupsGetDefault(void)
 {
  /*
@@ -416,34 +439,28 @@ cupsGetDefault(void)
  * This function returns the default printer or class as defined by
  * the LPDEST or PRINTER environment variables. If these environment
  * variables are not set, the server default destination is returned.
- * Applications should use the cupsGetDests() and cupsGetDest() functions
- * to get the user-defined default printer, as this function does not
- * support the lpoptions-defined default printer.
+ * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
+ * functions to get the user-defined default printer, as this function does
+ * not support the lpoptions-defined default printer.
  *
- * @since CUPS 1.1.21@
+ * @since CUPS 1.1.21/Mac OS X 10.4@
  */
 
-const char *                           /* O - Default printer or NULL */
-cupsGetDefault2(http_t *http)          /* I - HTTP connection */
+const char *                           /* O - Default printer or @code NULL@ */
+cupsGetDefault2(http_t *http)          /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
 {
   ipp_t                *request,               /* IPP Request */
                *response;              /* IPP Response */
   ipp_attribute_t *attr;               /* Current attribute */
-  const char   *var;                   /* Environment variable */
   _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
 
 
  /*
-  * First see if the LPDEST or PRINTER environment variables are
-  * set...  However, if PRINTER is set to "lp", ignore it to work
-  * around a "feature" in most Linux distributions - the default
-  * user login scripts set PRINTER to "lp"...
+  * See if we have a user default printer set...
   */
 
-  if ((var = getenv("LPDEST")) != NULL)
-    return (var);
-  else if ((var = getenv("PRINTER")) != NULL && strcmp(var, "lp") != 0)
-    return (var);
+  if (_cupsUserDefault(cg->def_printer, sizeof(cg->def_printer)))
+    return (cg->def_printer);
 
  /*
   * Connect to the server as needed...
@@ -487,21 +504,24 @@ cupsGetDefault2(http_t *http)             /* I - HTTP connection */
 
 /*
  * 'cupsGetJobs()' - Get the jobs from the default server.
+ *
+ * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
+ * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
+ * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
+ * jobs that are stopped, canceled, aborted, or completed.
  */
 
 int                                    /* O - Number of jobs */
 cupsGetJobs(cups_job_t **jobs,         /* O - Job data */
-            const char *mydest,                /* I - NULL = all destinations,       *
-                                        *     otherwise show jobs for mydest */
+            const char *name,          /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
             int        myjobs,         /* I - 0 = all users, 1 = mine */
-           int        completed)       /* I - -1 = show all, 0 = active, *
-                                        *     1 = completed jobs         */
+           int        whichjobs)       /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
 {
  /*
   * Return the jobs...
   */
 
-  return (cupsGetJobs2(CUPS_HTTP_DEFAULT, jobs, mydest, myjobs, completed));
+  return (cupsGetJobs2(CUPS_HTTP_DEFAULT, jobs, name, myjobs, whichjobs));
 }
 
 
@@ -509,17 +529,20 @@ cupsGetJobs(cups_job_t **jobs,            /* O - Job data */
 /*
  * 'cupsGetJobs2()' - Get the jobs from the specified server.
  *
- * @since CUPS 1.1.21@
+ * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
+ * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
+ * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
+ * jobs that are stopped, canceled, aborted, or completed.
+ *
+ * @since CUPS 1.1.21/Mac OS X 10.4@
  */
 
 int                                    /* O - Number of jobs */
-cupsGetJobs2(http_t     *http,         /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+cupsGetJobs2(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
              cups_job_t **jobs,                /* O - Job data */
-             const char *mydest,       /* I - NULL = all destinations,       *
-                                        *     otherwise show jobs for mydest */
+             const char *name,         /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
              int        myjobs,                /* I - 0 = all users, 1 = mine */
-            int        completed)      /* I - -1 = show all, 0 = active, *
-                                        *     1 = completed jobs         */
+            int        whichjobs)      /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
 {
   int          n;                      /* Number of jobs */
   ipp_t                *request,               /* IPP Request */
@@ -541,17 +564,17 @@ cupsGetJobs2(http_t     *http,            /* I - HTTP connection or CUPS_HTTP_DEFAULT */
   _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
   static const char * const attrs[] =  /* Requested attributes */
                {
+                 "document-format",
                  "job-id",
-                 "job-priority",
                  "job-k-octets",
+                 "job-name",
+                 "job-originating-user-name",
+                 "job-printer-uri",
+                 "job-priority",
                  "job-state",
                  "time-at-completed",
                  "time-at-creation",
-                 "time-at-processing",
-                 "job-printer-uri",
-                 "document-format",
-                 "job-name",
-                 "job-originating-user-name"
+                 "time-at-processing"
                };
 
 
@@ -561,7 +584,7 @@ cupsGetJobs2(http_t     *http,              /* I - HTTP connection or CUPS_HTTP_DEFAULT */
 
   if (!jobs)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     return (-1);
   }
@@ -570,18 +593,18 @@ cupsGetJobs2(http_t     *http,            /* I - HTTP connection or CUPS_HTTP_DEFAULT */
   * Get the right URI...
   */
 
-  if (mydest)
+  if (name)
   {
     if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                         "localhost", 0, "/printers/%s", mydest) != HTTP_URI_OK)
+                         "localhost", 0, "/printers/%s", name) != HTTP_URI_OK)
     {
-      _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+      _cupsSetError(IPP_INTERNAL_ERROR, _("Unable to create printer-uri"), 1);
 
       return (-1);
     }
   }
   else
-    strcpy(uri, "ipp://localhost/jobs");
+    strcpy(uri, "ipp://localhost/");
 
   if (!http)
     if ((http = _cupsConnect()) == NULL)
@@ -611,10 +634,10 @@ cupsGetJobs2(http_t     *http,            /* I - HTTP connection or CUPS_HTTP_DEFAULT */
   if (myjobs)
     ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
 
-  if (completed > 0)
+  if (whichjobs == CUPS_WHICHJOBS_COMPLETED)
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                  "which-jobs", NULL, "completed");
-  else if (completed < 0)
+  else if (whichjobs == CUPS_WHICHJOBS_ALL)
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                  "which-jobs", NULL, "all");
 
@@ -729,7 +752,7 @@ cupsGetJobs2(http_t     *http,              /* I - HTTP connection or CUPS_HTTP_DEFAULT */
         * Ran out of memory!
         */
 
-        _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+        _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
 
        cupsFreeJobs(n, *jobs);
        *jobs = NULL;
@@ -776,12 +799,16 @@ cupsGetJobs2(http_t     *http,            /* I - HTTP connection or CUPS_HTTP_DEFAULT */
 /*
  * 'cupsGetPPD()' - Get the PPD file for a printer on the default server.
  *
- * For classes, cupsGetPPD() returns the PPD file for the first printer
+ * For classes, @code cupsGetPPD@ returns the PPD file for the first printer
  * in the class.
+ *
+ * The returned filename is stored in a static buffer and is overwritten with
+ * each call to @code cupsGetPPD@ or @link cupsGetPPD2@.  The caller "owns" the
+ * file that is created and must @code unlink@ the returned filename.
  */
 
 const char *                           /* O - Filename for PPD file */
-cupsGetPPD(const char *name)           /* I - Printer name */
+cupsGetPPD(const char *name)           /* I - Destination name */
 {
   _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
   time_t       modtime = 0;            /* Modification time */
@@ -804,15 +831,19 @@ cupsGetPPD(const char *name)              /* I - Printer name */
 /*
  * 'cupsGetPPD2()' - Get the PPD file for a printer from the specified server.
  *
- * For classes, cupsGetPPD2() returns the PPD file for the first printer
+ * For classes, @code cupsGetPPD2@ returns the PPD file for the first printer
  * in the class.
  *
- * @since CUPS 1.1.21@
+ * The returned filename is stored in a static buffer and is overwritten with
+ * each call to @link cupsGetPPD@ or @code cupsGetPPD2@.  The caller "owns" the
+ * file that is created and must @code unlink@ the returned filename.
+ *
+ * @since CUPS 1.1.21/Mac OS X 10.4@
  */
 
 const char *                           /* O - Filename for PPD file */
-cupsGetPPD2(http_t     *http,          /* I - HTTP connection or CUPS_HTTP_DEFAULT */
-            const char *name)          /* I - Printer name */
+cupsGetPPD2(http_t     *http,          /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
+            const char *name)          /* I - Destination name */
 {
   _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
   time_t       modtime = 0;            /* Modification time */
@@ -838,15 +869,22 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection or CUPS_HTTP_DEFAULT */
  *
  * The "buffer" parameter contains the local PPD filename.  If it contains
  * the empty string, a new temporary file is created, otherwise the existing
- * file will be overwritten as needed.
+ * file will be overwritten as needed.  The caller "owns" the file that is
+ * created and must @code unlink@ the returned filename.
  *
- * On success, HTTP_OK is returned for a new PPD file and HTTP_NOT_MODIFIED
- * if the existing PPD file is up-to-date.  Any other status is an error.
+ * On success, @code HTTP_OK@ is returned for a new PPD file and
+ * @code HTTP_NOT_MODIFIED@ if the existing PPD file is up-to-date.  Any other
+ * status is an error.
+ *
+ * For classes, @code cupsGetPPD3@ returns the PPD file for the first printer
+ * in the class.
+ *
+ * @since CUPS 1.4/Mac OS X 10.6@
  */
 
 http_status_t                          /* O  - HTTP status */
-cupsGetPPD3(http_t     *http,          /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
-            const char *name,          /* I  - Printer name */
+cupsGetPPD3(http_t     *http,          /* I  - HTTP connection or @code CUPS_HTTP_DEFAULT@ */
+            const char *name,          /* I  - Destination name */
            time_t     *modtime,        /* IO - Modification time */
            char       *buffer,         /* I  - Filename buffer */
            size_t     bufsize)         /* I  - Size of filename buffer */
@@ -869,39 +907,146 @@ cupsGetPPD3(http_t     *http,            /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
   */
 
   DEBUG_printf(("cupsGetPPD3(http=%p, name=\"%s\", modtime=%p(%d), buffer=%p, "
-                "bufsize=%d)\n", http, name ? name : "(null)", modtime,
-               modtime ? *modtime : 0, buffer, (int)bufsize));
+                "bufsize=%d)", http, name, modtime,
+               modtime ? (int)*modtime : 0, buffer, (int)bufsize));
 
   if (!name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, "No printer name!");
+    _cupsSetError(IPP_INTERNAL_ERROR, _("No printer name"), 1);
     return (HTTP_NOT_ACCEPTABLE);
   }
 
   if (!modtime)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, "No modification time!");
+    _cupsSetError(IPP_INTERNAL_ERROR, _("No modification time"), 1);
     return (HTTP_NOT_ACCEPTABLE);
   }
 
   if (!buffer || bufsize <= 1)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, "Bad filename buffer!");
+    _cupsSetError(IPP_INTERNAL_ERROR, _("Bad filename buffer"), 1);
     return (HTTP_NOT_ACCEPTABLE);
   }
 
+#ifndef WIN32
+ /*
+  * See if the PPD file is available locally...
+  */
+
+  if (!cg->servername[0])
+    cupsServer();
+
+  if (!strcasecmp(cg->servername, "localhost"))
+  {
+    char       ppdname[1024];          /* PPD filename */
+    struct stat        ppdinfo;                /* PPD file information */
+
+
+    snprintf(ppdname, sizeof(ppdname), "%s/ppd/%s.ppd", cg->cups_serverroot,
+             name);
+    if (!stat(ppdname, &ppdinfo))
+    {
+     /*
+      * OK, the file exists, use it!
+      */
+
+      if (buffer[0])
+      {
+        unlink(buffer);
+
+       if (symlink(ppdname, buffer) && errno != EEXIST)
+        {
+          _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+
+         return (HTTP_SERVER_ERROR);
+       }
+      }
+      else
+      {
+        int            tries;          /* Number of tries */
+        const char     *tmpdir;        /* TMPDIR environment variable */
+       struct timeval  curtime;        /* Current time */
+
+       /*
+       * Previously we put root temporary files in the default CUPS temporary
+       * directory under /var/spool/cups.  However, since the scheduler cleans
+       * out temporary files there and runs independently of the user apps, we
+       * don't want to use it unless specifically told to by cupsd.
+       */
+
+       if ((tmpdir = getenv("TMPDIR")) == NULL)
+#  ifdef __APPLE__
+         tmpdir = "/private/tmp";      /* /tmp is a symlink to /private/tmp */
+#  else
+          tmpdir = "/tmp";
+#  endif /* __APPLE__ */
+
+       /*
+       * Make the temporary name using the specified directory...
+       */
+
+       tries = 0;
+
+       do
+       {
+        /*
+         * Get the current time of day...
+         */
+
+         gettimeofday(&curtime, NULL);
+
+        /*
+         * Format a string using the hex time values...
+         */
+
+         snprintf(buffer, bufsize, "%s/%08lx%05lx", tmpdir,
+                  (unsigned long)curtime.tv_sec,
+                  (unsigned long)curtime.tv_usec);
+
+        /*
+         * Try to make a symlink...
+         */
+
+         if (!symlink(ppdname, buffer))
+           break;
+
+         tries ++;
+       }
+       while (tries < 1000);
+
+        if (tries >= 1000)
+       {
+          _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+
+         return (HTTP_SERVER_ERROR);
+       }
+      }
+
+      if (*modtime >= ppdinfo.st_mtime)
+        return (HTTP_NOT_MODIFIED);
+      else
+      {
+        *modtime = ppdinfo.st_mtime;
+       return (HTTP_OK);
+      }
+    }
+  }
+#endif /* !WIN32 */
+
  /*
   * Try finding a printer URI for this printer...
   */
 
   if (!http)
-    http = _cupsConnect();
+    if ((http = _cupsConnect()) == NULL)
+      return (HTTP_SERVICE_UNAVAILABLE);
 
   if (!cups_get_printer_uri(http, name, hostname, sizeof(hostname), &port,
                             resource, sizeof(resource), 0))
     return (HTTP_NOT_FOUND);
 
-  DEBUG_printf(("Printer hostname=\"%s\", port=%d\n", hostname, port));
+  DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname,
+                port));
 
  /*
   * Remap local hostname to localhost...
@@ -909,7 +1054,7 @@ cupsGetPPD3(http_t     *http,              /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
 
   httpGetHostname(NULL, localhost, sizeof(localhost));
 
-  DEBUG_printf(("Local hostname=\"%s\"\n", localhost));
+  DEBUG_printf(("2cupsGetPPD3: Local hostname=\"%s\"", localhost));
 
   if (!strcasecmp(localhost, hostname))
     strcpy(hostname, "localhost");
@@ -919,19 +1064,10 @@ cupsGetPPD3(http_t     *http,            /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
   */
 
   httpGetHostname(http, http_hostname, sizeof(http_hostname));
+  http_port = _httpAddrPort(http->hostaddr);
 
-#ifdef AF_INET6
-  if (http->hostaddr->addr.sa_family == AF_INET6)
-    http_port = ntohs(http->hostaddr->ipv6.sin6_port);
-  else
-#endif /* AF_INET6 */
-  if (http->hostaddr->addr.sa_family == AF_INET)
-    http_port = ntohs(http->hostaddr->ipv4.sin_port);
-  else
-    http_port = ippPort(); 
-
-  DEBUG_printf(("Connection hostname=\"%s\", port=%d\n", http_hostname,
-                http_port));
+  DEBUG_printf(("2cupsGetPPD3: Connection hostname=\"%s\", port=%d",
+                http_hostname, http_port));
 
  /*
   * Reconnect to the correct server as needed...
@@ -942,7 +1078,7 @@ cupsGetPPD3(http_t     *http,              /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
   else if ((http2 = httpConnectEncrypt(hostname, port,
                                        cupsEncryption())) == NULL)
   {
-    DEBUG_puts("Unable to connect to server!");
+    DEBUG_puts("1cupsGetPPD3: Unable to connect to server");
 
     return (HTTP_SERVICE_UNAVAILABLE);
   }
@@ -962,7 +1098,7 @@ cupsGetPPD3(http_t     *http,              /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
     * Can't open file; close the server connection and return NULL...
     */
 
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+    _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
 
     if (http2 != http)
       httpClose(http2);
@@ -984,9 +1120,6 @@ cupsGetPPD3(http_t     *http,              /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
 
   close(fd);
 
-  if (http2 != http)
-    httpClose(http2);
-
  /*
   * See if we actually got the file or an error...
   */
@@ -995,30 +1128,20 @@ cupsGetPPD3(http_t     *http,            /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
     *modtime = httpGetDateTime(httpGetField(http2, HTTP_FIELD_DATE));
   else if (status != HTTP_NOT_MODIFIED)
   {
-    switch (status)
-    {
-      case HTTP_NOT_FOUND :
-          _cupsSetError(IPP_NOT_FOUND, httpStatus(status));
-         break;
-
-      case HTTP_UNAUTHORIZED :
-          _cupsSetError(IPP_NOT_AUTHORIZED, httpStatus(status));
-         break;
-
-      default :
-         DEBUG_printf(("HTTP error %d mapped to IPP_SERVICE_UNAVAILABLE!\n",
-                       status));
-         _cupsSetError(IPP_SERVICE_UNAVAILABLE, httpStatus(status));
-         break;
-    }
+    _cupsSetHTTPError(status);
 
     unlink(cg->ppd_filename);
   }
 
+  if (http2 != http)
+    httpClose(http2);
+
  /*
   * Return the PPD file...
   */
 
+  DEBUG_printf(("1cupsGetPPD3: Returning status %d", status));
+
   return (status);
 }
 
@@ -1026,7 +1149,7 @@ cupsGetPPD3(http_t     *http,             /* I  - HTTP connection or CUPS_HTTP_DEFAULT */
 /*
  * 'cupsGetPrinters()' - Get a list of printers from the default server.
  *
- * This function is deprecated - use cupsGetDests() instead.
+ * This function is deprecated - use @link cupsGetDests@ instead.
  *
  * @deprecated@
  */
@@ -1048,7 +1171,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
 
   if (!printers)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -1133,19 +1256,19 @@ cupsGetPrinters(char ***printers)       /* O - Printers */
  * 'cupsGetServerPPD()' - Get an available PPD file from the server.
  *
  * This function returns the named PPD file from the server.  The
- * list of available PPDs is provided by the IPP CUPS_GET_PPDS
+ * list of available PPDs is provided by the IPP @code CUPS_GET_PPDS@
  * operation.
  *
  * You must remove (unlink) the PPD file when you are finished with
  * it. The PPD filename is stored in a static location that will be
- * overwritten on the next call to cupsGetPPD(), cupsGetPPD2(), or
- * cupsGetServerPPD().
+ * overwritten on the next call to @link cupsGetPPD@, @link cupsGetPPD2@,
+ * or @link cupsGetServerPPD@.
  *
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
-char *                                 /* O - Name of PPD file or NULL on error */
-cupsGetServerPPD(http_t     *http,     /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+char *                                 /* O - Name of PPD file or @code NULL@ on error */
+cupsGetServerPPD(http_t     *http,     /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
                  const char *name)     /* I - Name of PPD file ("ppd-name") */
 {
   int                  fd;             /* PPD file descriptor */
@@ -1160,7 +1283,7 @@ cupsGetServerPPD(http_t     *http,        /* I - HTTP connection or CUPS_HTTP_DEFAULT *
 
   if (!name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, "No PPD name!");
+    _cupsSetError(IPP_INTERNAL_ERROR, _("No PPD name"), 1);
 
     return (NULL);
   }
@@ -1179,7 +1302,7 @@ cupsGetServerPPD(http_t     *http,        /* I - HTTP connection or CUPS_HTTP_DEFAULT *
     * Can't open file; close the server connection and return NULL...
     */
 
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+    _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
 
     return (NULL);
   }
@@ -1206,43 +1329,19 @@ cupsGetServerPPD(http_t     *http,      /* I - HTTP connection or CUPS_HTTP_DEFAULT *
 }
 
 
-/*
- * 'cupsLastError()' - Return the last IPP status code.
- */
-
-ipp_status_t                           /* O - IPP status code from last request */
-cupsLastError(void)
-{
-  return (_cupsGlobals()->last_error);
-}
-
-
-/*
- * 'cupsLastErrorString()' - Return the last IPP status-message.
- *
- * @since CUPS 1.2@
- */
-
-const char *                           /* O - status-message text from last request */
-cupsLastErrorString(void)
-{
-  return (_cupsGlobals()->last_status_message);
-}
-
-
 /*
  * 'cupsPrintFile()' - Print a file to a printer or class on the default server.
  */
 
-int                                    /* O - Job ID */
-cupsPrintFile(const char    *name,     /* I - Printer or class name */
+int                                    /* O - Job ID or 0 on error */
+cupsPrintFile(const char    *name,     /* I - Destination name */
               const char    *filename, /* I - File to print */
              const char    *title,     /* I - Title of job */
               int           num_options,/* I - Number of options */
              cups_option_t *options)   /* I - Options */
 {
   DEBUG_printf(("cupsPrintFile(name=\"%s\", filename=\"%s\", "
-                "title=\"%s\", num_options=%d, options=%p)\n",
+                "title=\"%s\", num_options=%d, options=%p)",
                 name, filename, title, num_options, options));
 
   return (cupsPrintFiles2(CUPS_HTTP_DEFAULT, name, 1, &filename, title,
@@ -1251,22 +1350,23 @@ cupsPrintFile(const char    *name,      /* I - Printer or class name */
 
 
 /*
- * 'cupsPrintFile2()' - Print a file to a printer or class on the specified server.
+ * 'cupsPrintFile2()' - Print a file to a printer or class on the specified
+ *                      server.
  *
- * @since CUPS 1.1.21@
+ * @since CUPS 1.1.21/Mac OS X 10.4@
  */
 
-int                                    /* O - Job ID */
+int                                    /* O - Job ID or 0 on error */
 cupsPrintFile2(
-    http_t        *http,               /* I - HTTP connection */
-    const char    *name,               /* I - Printer or class name */
+    http_t        *http,               /* I - Connection to server */
+    const char    *name,               /* I - Destination name */
     const char    *filename,           /* I - File to print */
     const char    *title,              /* I - Title of job */
     int           num_options,         /* I - Number of options */
     cups_option_t *options)            /* I - Options */
 {
   DEBUG_printf(("cupsPrintFile2(http=%p, name=\"%s\", filename=\"%s\", "
-                "title=\"%s\", num_options=%d, options=%p)\n",
+                "title=\"%s\", num_options=%d, options=%p)",
                 http, name, filename, title, num_options, options));
 
   return (cupsPrintFiles2(http, name, 1, &filename, title, num_options,
@@ -1279,9 +1379,9 @@ cupsPrintFile2(
  *                      default server.
  */
 
-int                                    /* O - Job ID */
+int                                    /* O - Job ID or 0 on error */
 cupsPrintFiles(
-    const char    *name,               /* I - Printer or class name */
+    const char    *name,               /* I - Destination name */
     int           num_files,           /* I - Number of files */
     const char    **files,             /* I - File(s) to print */
     const char    *title,              /* I - Title of job */
@@ -1289,10 +1389,9 @@ cupsPrintFiles(
     cups_option_t *options)            /* I - Options */
 {
   DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, "
-                "files=%p, title=\"%s\", num_options=%d, options=%p)\n",
+                "files=%p, title=\"%s\", num_options=%d, options=%p)",
                 name, num_files, files, title, num_options, options));
 
-
  /*
   * Print the file(s)...
   */
@@ -1306,13 +1405,13 @@ cupsPrintFiles(
  * 'cupsPrintFiles2()' - Print one or more files to a printer or class on the
  *                       specified server.
  *
- * @since CUPS 1.1.21@
+ * @since CUPS 1.1.21/Mac OS X 10.4@
  */
 
-int                                    /* O - Job ID */
+int                                    /* O - Job ID or 0 on error */
 cupsPrintFiles2(
-    http_t        *http,               /* I - HTTP connection or CUPS_HTTP_DEFAULT */
-    const char    *name,               /* I - Printer or class name */
+    http_t        *http,               /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
+    const char    *name,               /* I - Destination name */
     int           num_files,           /* I - Number of files */
     const char    **files,             /* I - File(s) to print */
     const char    *title,              /* I - Title of job */
@@ -1327,10 +1426,13 @@ cupsPrintFiles2(
   char         buffer[8192];           /* Copy buffer */
   ssize_t      bytes;                  /* Bytes in buffer */
   http_status_t        status;                 /* Status of write */
+  _cups_globals_t *cg = _cupsGlobals();        /* Global data */
+  ipp_status_t cancel_status;          /* Status code to preserve */
+  char         *cancel_message;        /* Error message to preserve */
 
 
   DEBUG_printf(("cupsPrintFiles2(http=%p, name=\"%s\", num_files=%d, "
-                "files=%p, title=\"%s\", num_options=%d, options=%p)\n",
+                "files=%p, title=\"%s\", num_options=%d, options=%p)",
                 http, name, num_files, files, title, num_options, options));
 
  /*
@@ -1339,7 +1441,7 @@ cupsPrintFiles2(
 
   if (!name || num_files < 1 || !files)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -1378,15 +1480,15 @@ cupsPrintFiles2(
       * Unable to open print file, cancel the job and return...
       */
 
-      cupsCancelJob2(http, job_id, 0);
-      return (0);
+      _cupsSetError(IPP_DOCUMENT_ACCESS_ERROR, NULL, 0);
+      goto cancel_job;
     }
 
     status = cupsStartDocument(http, name, job_id, docname, format,
-                               i == (num_files - 1));
+                              i == (num_files - 1));
 
     while (status == HTTP_CONTINUE &&
-           (bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
+          (bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
       status = cupsWriteRequestData(http, buffer, bytes);
 
     cupsFileClose(fp);
@@ -1397,36 +1499,54 @@ cupsPrintFiles2(
       * Unable to queue, cancel the job and return...
       */
 
-      cupsCancelJob2(http, job_id, 0);
-      return (0);
+      goto cancel_job;
     }
   }
 
   return (job_id);
+
+ /*
+  * If we get here, something happened while sending the print job so we need
+  * to cancel the job without setting the last error (since we need to preserve
+  * the current error...
+  */
+
+  cancel_job:
+
+  cancel_status  = cg->last_error;
+  cancel_message = cg->last_status_message ?
+                       _cupsStrRetain(cg->last_status_message) : NULL;
+
+  cupsCancelJob2(http, name, job_id, 0);
+
+  cg->last_error          = cancel_status;
+  cg->last_status_message = cancel_message;
+
+  return (0);
 }
 
 
 /*
  * 'cupsStartDocument()' - Add a document to a job created with cupsCreateJob().
  *
- * Use cupsWriteRequestData() to write data for the document and
- * cupsFinishDocument() to finish the document and get the submission status.
+ * Use @link cupsWriteRequestData@ to write data for the document and
+ * @link cupsFinishDocument@ to finish the document and get the submission status.
  *
- * The MIME type constants CUPS_FORMAT_AUTO, CUPS_FORMAT_PDF,
- * CUPS_FORMAT_POSTSCRIPT, CUPS_FORMAT_RAW, and CUPS_FORMAT_TEXT are provided
- * for the "format" argument, although any supported MIME type string can be
- * supplied.
+ * The MIME type constants @code CUPS_FORMAT_AUTO@, @code CUPS_FORMAT_PDF@,
+ * @code CUPS_FORMAT_POSTSCRIPT@, @code CUPS_FORMAT_RAW@, and
+ * @code CUPS_FORMAT_TEXT@ are provided for the "format" argument, although
+ * any supported MIME type string can be supplied.
  *
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
  */
 
 http_status_t                          /* O - HTTP status of request */
 cupsStartDocument(
-    http_t     *http,                  /* I - HTTP connection or CUPS_HTTP_DEFAULT */
-    const char *name,                  /* I - Printer or class name */
-    int        job_id,                 /* I - Job ID from cupsCreateJob() */
+    http_t     *http,                  /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
+    const char *name,                  /* I - Destination name */
+    int        job_id,                 /* I - Job ID from @link cupsCreateJob@ */
     const char *docname,               /* I - Name of document */
-    const char *format,                        /* I - MIME type or CUPS_FORMAT_foo */
+    const char *format,                        /* I - MIME type or @code CUPS_FORMAT_foo@ */
     int        last_document)          /* I - 1 for last document in job, 0 otherwise */
 {
   char         resource[1024],         /* Resource for destinatio */
@@ -1441,7 +1561,7 @@ cupsStartDocument(
 
   if ((request = ippNewRequest(IPP_SEND_DOCUMENT)) == NULL)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
     return (0);
   }
 
@@ -1475,84 +1595,13 @@ cupsStartDocument(
 
 
 /*
- * '_cupsConnect()' - Get the default server connection...
- */
-
-http_t *                               /* O - HTTP connection */
-_cupsConnect(void)
-{
-  _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
-
-
- /*
-  * See if we are connected to the same server...
-  */
-
-  if (cg->http)
-  {
-    int        port;                           /* Port for connection */
-
-
-   /*
-    * Get the port associated with the current connection...
-    */
-
-#ifdef AF_INET6
-    if (cg->http->hostaddr->addr.sa_family == AF_INET6)
-      port = ntohs(cg->http->hostaddr->ipv6.sin6_port);
-    else
-#endif /* AF_INET6 */
-    if (cg->http->hostaddr->addr.sa_family == AF_INET)
-      port = ntohs(cg->http->hostaddr->ipv4.sin_port);
-    else
-      port = cg->ipp_port;
-
-   /*
-    * Compare the connection hostname, port, and encryption settings to
-    * the cached defaults; these were initialized the first time we
-    * connected...
-    */
-
-    if (strcmp(cg->http->hostname, cg->server) || cg->ipp_port != port ||
-        (cg->http->encryption != cg->encryption &&
-        cg->http->encryption == HTTP_ENCRYPT_NEVER))
-    {
-     /*
-      * Need to close the current connection because something has changed...
-      */
-
-      httpClose(cg->http);
-      cg->http = NULL;
-    }
-  }
-
- /*
-  * (Re)connect as needed...
-  */
-
-  if (!cg->http)
-  {
-    if ((cg->http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption())) == NULL)
-      _cupsSetError(IPP_SERVICE_UNAVAILABLE,
-                    errno ? strerror(errno) : "Unable to connect to host.");
-  }
-
- /*
-  * Return the cached connection...
-  */
-
-  return (cg->http);
-}
-
-
-/*
- * 'cups_get_printer_uri()' - Get the printer-uri-supported attribute for the first printer in a class.
+ * 'cups_get_printer_uri()' - Get the printer-uri-supported attribute for the
+ *                            first printer in a class.
  */
 
 static int                             /* O - 1 on success, 0 on failure */
 cups_get_printer_uri(
-    http_t     *http,                  /* I - HTTP connection */
+    http_t     *http,                  /* I - Connection to server */
     const char *name,                  /* I - Name of printer or class */
     char       *host,                  /* I - Hostname buffer */
     int        hostsize,               /* I - Size of hostname buffer */
@@ -1575,16 +1624,15 @@ cups_get_printer_uri(
                                        /* Hostname associated with connection */
   static const char * const requested_attrs[] =
                {                       /* Requested attributes */
+                 "member-uris",
                  "printer-uri-supported",
-                 "printer-type",
-                 "member-uris"
+                 "printer-type"
                };
 
 
-  DEBUG_printf(("cups_get_printer_uri(http=%p, name=\"%s\", host=%p, "
-                "hostsize=%d, resource=%p, resourcesize=%d, depth=%d)\n",
-               http, name ? name : "(null)", host, hostsize,
-               resource, resourcesize, depth));
+  DEBUG_printf(("7cups_get_printer_uri(http=%p, name=\"%s\", host=%p, "
+                "hostsize=%d, resource=%p, resourcesize=%d, depth=%d)",
+               http, name, host, hostsize, resource, resourcesize, depth));
 
  /*
   * Setup the printer URI...
@@ -1593,7 +1641,7 @@ cups_get_printer_uri(
   if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
                        "localhost", 0, "/printers/%s", name) != HTTP_URI_OK)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, "Unable to create printer-uri!");
+    _cupsSetError(IPP_INTERNAL_ERROR, _("Unable to create printer-uri"), 1);
 
     *host     = '\0';
     *resource = '\0';
@@ -1601,23 +1649,14 @@ cups_get_printer_uri(
     return (0);
   }
 
-  DEBUG_printf(("cups_get_printer_uri: printer-uri=\"%s\"\n", uri));
+  DEBUG_printf(("9cups_get_printer_uri: printer-uri=\"%s\"", uri));
 
  /*
   * Get the hostname and port number we are connected to...
   */
 
   httpGetHostname(http, http_hostname, sizeof(http_hostname));
-
-#ifdef AF_INET6
-  if (http->hostaddr->addr.sa_family == AF_INET6)
-    http_port = ntohs(http->hostaddr->ipv6.sin6_port);
-  else
-#endif /* AF_INET6 */
-  if (http->hostaddr->addr.sa_family == AF_INET)
-    http_port = ntohs(http->hostaddr->ipv4.sin_port);
-  else
-    http_port = ippPort(); 
+  http_port = _httpAddrPort(http->hostaddr);
 
  /*
   * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
@@ -1691,7 +1730,7 @@ cups_get_printer_uri(
            else if ((http2 = httpConnectEncrypt(host, *port,
                                                 cupsEncryption())) == NULL)
            {
-             DEBUG_puts("Unable to connect to server!");
+             DEBUG_puts("8cups_get_printer_uri: Unable to connect to server");
 
              continue;
            }
@@ -1721,11 +1760,24 @@ cups_get_printer_uri(
     else if ((attr = ippFindAttribute(response, "printer-uri-supported",
                                       IPP_TAG_URI)) != NULL)
     {
-      httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text,
+      httpSeparateURI(HTTP_URI_CODING_ALL,
+                      _httpResolveURI(attr->values[0].string.text, uri,
+                                     sizeof(uri), 0),
                       scheme, sizeof(scheme), username, sizeof(username),
                      host, hostsize, port, resource, resourcesize);
       ippDelete(response);
 
+      if (!strncmp(resource, "/classes/", 9))
+      {
+        _cupsSetError(IPP_INTERNAL_ERROR,
+                     _("No printer-uri found for class"), 1);
+
+       *host     = '\0';
+       *resource = '\0';
+
+       return (0);
+      }
+
       return (1);
     }
 
@@ -1733,7 +1785,7 @@ cups_get_printer_uri(
   }
 
   if (cupsLastError() != IPP_NOT_FOUND)
-    _cupsSetError(IPP_INTERNAL_ERROR, "No printer-uri found!");
+    _cupsSetError(IPP_INTERNAL_ERROR, _("No printer-uri found"), 1);
 
   *host     = '\0';
   *resource = '\0';
@@ -1743,5 +1795,5 @@ cups_get_printer_uri(
 
 
 /*
- * End of "$Id: util.c 7014 2007-10-10 21:57:43Z mike $".
+ * End of "$Id: util.c 7850 2008-08-20 00:07:25Z mike $".
  */